From 595227c345d0310607c0e7c881e29db4fd319595 Mon Sep 17 00:00:00 2001 From: Theo Heimel Date: Tue, 27 Oct 2026 11:03:06 +0100 Subject: [PATCH] pyamplicol: drop profiling-campaign and report tooling Remove the packaged profiling campaign (`pyamplicol profiling-campaign`), the performance-report and FFT-profiling drivers, the developer gates and benchmarks that only fed them, the UMAMI/MadSpace demo, the nix flake, and their tests and docs. Published reports stay linked from upstream. --- .gitattributes | 15 +- docs/source/conf.py | 8 +- pyamplicol/README.md | 141 +- pyamplicol/build_backend/_pyamplicol_build.py | 212 +- pyamplicol/docs/README.md | 4 +- .../docs/development/PACKAGING_CONTRACT.md | 2 +- pyamplicol/docs/performance_reports/README.md | 93 - .../docs/user/artifacts-and-portability.md | 7 - .../docs/user/command-line-interface.md | 4 - pyamplicol/docs/user/configuration.md | 4 +- .../docs/user/fullcolor-fft-profiling.md | 277 - pyamplicol/docs/user/gentle-walkthrough.md | 5 +- .../docs/user/profiling-and-benchmarking.md | 45 +- .../user/profiling-campaign-walkthrough.md | 715 -- pyamplicol/docs/user/profiling-campaigns.md | 367 - pyamplicol/docs/user/quick-start.md | 1 - pyamplicol/docs/user/release-and-support.md | 8 +- pyamplicol/docs/user/runtime-and-selectors.md | 3 - .../docs/user/symbolica-and-licensing.md | 2 +- pyamplicol/docs/user/troubleshooting.md | 75 +- pyamplicol/docs/user/umami-api.md | 21 +- pyamplicol/flake.lock | 48 - pyamplicol/flake.nix | 134 - pyamplicol/justfile | 23 - pyamplicol/pyproject.toml | 3 - pyamplicol/run_fft_profiling_render.sh | 14 - .../pyamplicol/_profiling_campaign/README.md | 190 - .../_profiling_campaign/TABLE_FILLING.md | 224 - .../_profiling_campaign/build_pdf.py | 112 - .../_profiling_campaign/pyAmpliCol.tex | 537 - .../_profiling_campaign/report-workspace.json | 71 - .../report_environment.json | 1 - .../report_environment.tex | 6 - ...sult_matrix_best_builtin_sm_full_table.tex | 212 - ...result_matrix_best_builtin_sm_lc_table.tex | 296 - ...esult_matrix_best_builtin_sm_nlc_table.tex | 212 - ..._matrix_compiled_builtin_sm_full_table.tex | 208 - ...lt_matrix_compiled_builtin_sm_lc_table.tex | 292 - ...t_matrix_compiled_builtin_sm_nlc_table.tex | 208 - ...compiled_ufo_sm_full_vs_madgraph_table.tex | 208 - ...ult_matrix_eager_builtin_sm_full_table.tex | 208 - ...esult_matrix_eager_builtin_sm_lc_table.tex | 292 - ...sult_matrix_eager_builtin_sm_nlc_table.tex | 208 - ...ix_eager_ufo_sm_full_vs_madgraph_table.tex | 208 - ...atrix_on_the_fly_builtin_sm_full_table.tex | 208 - ..._matrix_on_the_fly_builtin_sm_lc_table.tex | 208 - ...matrix_on_the_fly_builtin_sm_nlc_table.tex | 208 - ..._the_fly_ufo_sm_full_vs_madgraph_table.tex | 208 - ...atrix_recurrence_builtin_sm_full_table.tex | 208 - ..._matrix_recurrence_builtin_sm_lc_table.tex | 292 - ...matrix_recurrence_builtin_sm_nlc_table.tex | 208 - ...lt_matrix_recurrence_ufo_sm_full_table.tex | 208 - ...currence_ufo_sm_full_vs_madgraph_table.tex | 208 - ...sult_matrix_recurrence_ufo_sm_lc_table.tex | 292 - ...ult_matrix_recurrence_ufo_sm_nlc_table.tex | 208 - .../result_scalar_contact_table.tex | 51 - .../result_scalar_gravity_table.tex | 51 - .../_profiling_campaign/result_tables.py | 711 -- .../result_validation_summary.tex | 44 - .../result_z_builtin_sm_table.tex | 205 - .../result_z_external_sm_table.tex | 205 - .../matrix_compiled_builtin_sm_full.json | 1 - .../matrix_compiled_builtin_sm_lc.json | 1 - .../matrix_compiled_builtin_sm_nlc.json | 1 - .../results/matrix_compiled_ufo_sm_full.json | 1 - .../results/matrix_eager_builtin_sm_full.json | 1 - .../results/matrix_eager_builtin_sm_lc.json | 1 - .../results/matrix_eager_builtin_sm_nlc.json | 1 - .../results/matrix_eager_ufo_sm_full.json | 1 - .../matrix_on_the_fly_builtin_sm_full.json | 1 - .../matrix_on_the_fly_builtin_sm_lc.json | 1 - .../matrix_on_the_fly_builtin_sm_nlc.json | 1 - .../matrix_on_the_fly_ufo_sm_full.json | 1 - .../matrix_recurrence_builtin_sm_full.json | 1 - .../matrix_recurrence_builtin_sm_lc.json | 1 - .../matrix_recurrence_builtin_sm_nlc.json | 1 - .../matrix_recurrence_ufo_sm_full.json | 1 - .../results/matrix_recurrence_ufo_sm_lc.json | 1 - .../results/matrix_recurrence_ufo_sm_nlc.json | 1 - .../results/reference_amplicol_full.json | 1 - .../results/reference_amplicol_lc.json | 1 - .../results/reference_amplicol_nlc.json | 1 - .../results/reference_madgraph_full.json | 1 - .../results/report-cache.schema.json | 1 - .../results/scalar_contact.json | 1 - .../results/scalar_gravity.json | 1 - .../results/z_builtin_sm.json | 1 - .../results/z_external_sm.json | 1 - .../section_eager_execution.tex | 97 - .../section_lc_flow_layouts.tex | 148 - .../section_three_mode_performance_tables.tex | 230 - .../section_ufo_support.tex | 163 - .../_profiling_campaign/section_zgg_dag.tex | 83 - .../section_zgg_example.tex | 143 - .../steer_performance_campaign.py | 140 - pyamplicol/src/pyamplicol/cli/parser.py | 5 +- pyamplicol/src/pyamplicol/cli/utilities.py | 431 - .../ufo-sm-seed101-v1.json | 1625 --- .../integration/test_numerical_acceptance.py | 74 - .../test_on_the_fly_artifact_probe.py | 790 -- .../tests/release/test_sdist_manifest.py | 3 - .../unit/test_amplicol_z6g_m0_capture.py | 998 -- .../unit/test_arena_native_x86_acceptance.py | 530 - pyamplicol/tests/unit/test_build_backend.py | 228 +- ...talog_final_source_structural_preflight.py | 75 - .../unit/test_catalog_restart_parity_gate.py | 497 - .../test_catalog_structural_parity_audit.py | 458 - .../test_catalog_structural_scope_registry.py | 37 - pyamplicol/tests/unit/test_cli_utilities.py | 414 +- .../unit/test_compiled_all_jit_arena_gate.py | 412 - .../test_compiled_microkernel_acceptance.py | 1180 -- .../test_conditioned_report_validation.py | 438 - .../tests/unit/test_deployment_harness.py | 44 - .../tests/unit/test_exact_python_bootstrap.py | 763 -- pyamplicol/tests/unit/test_examples.py | 1 - .../test_fft_gluon_performance_acceptance.py | 1603 --- .../test_fft_madgraph_selected_runtime.py | 1728 --- .../unit/test_fft_numerical_acceptance.py | 554 - pyamplicol/tests/unit/test_fft_profiling.py | 3417 ------ .../unit/test_fft_results_summary_pdf.py | 255 - ...st_fft_scaling_final_publication_report.py | 743 -- ...test_fft_scaling_selected_scalar_report.py | 612 - .../tests/unit/test_fft_scaling_study.py | 1889 --- .../unit/test_fft_scaling_study_plots.py | 957 -- .../unit/test_final_source_numerical_truth.py | 327 - .../unit/test_four_quark_compiled_gate.py | 737 -- .../unit/test_legacy_structural_proof.py | 403 - .../unit/test_manual_campaign_audit_polish.py | 412 - .../unit/test_manual_campaign_entrypoint.py | 223 - .../unit/test_manual_campaign_interrupts.py | 491 - .../test_manual_campaign_lightweight_reuse.py | 1718 --- .../test_manual_campaign_observability.py | 332 - .../test_manual_campaign_recycled_exit.py | 115 - ...t_manual_campaign_summary_and_lifecycle.py | 1498 --- .../unit/test_manual_performance_campaign.py | 6415 ---------- .../tests/unit/test_numerical_acceptance.py | 605 - .../test_on_the_fly_artifact_scheduling.py | 246 - .../unit/test_on_the_fly_high_multiplicity.py | 2133 ---- .../tests/unit/test_on_the_fly_lc_gate.py | 2099 ---- .../test_on_the_fly_performance_campaign.py | 645 - ...n_the_fly_recurrence_authority_campaign.py | 1188 -- .../unit/test_on_the_fly_report_render.py | 460 - .../unit/test_otf_contracted_parity_gate.py | 171 - .../tests/unit/test_packaging_hygiene.py | 16 - ...test_performance_report_aggregate_audit.py | 202 - .../test_performance_report_agreements.py | 974 -- .../unit/test_performance_report_artifacts.py | 673 - .../unit/test_performance_report_boundary.py | 164 - ...st_performance_report_campaign_activity.py | 157 - .../test_performance_report_campaign_holds.py | 698 -- ...test_performance_report_campaign_policy.py | 2370 ---- .../test_performance_report_campaign_reset.py | 704 -- .../tests/unit/test_performance_report_cli.py | 839 -- .../test_performance_report_final_audit.py | 4840 -------- .../unit/test_performance_report_madgraph.py | 436 - .../test_performance_report_measurement.py | 1417 --- ..._performance_report_measurement_lineage.py | 466 - ..._report_measurement_lineage_adversarial.py | 1470 --- .../test_performance_report_phase_state.py | 139 - .../test_performance_report_phase_timeline.py | 143 - .../unit/test_performance_report_policy.py | 257 - .../unit/test_performance_report_prepared.py | 179 - .../test_performance_report_publication.py | 685 -- ..._performance_report_publication_lineage.py | 185 - .../unit/test_performance_report_publisher.py | 292 - ...t_performance_report_resource_retention.py | 187 - .../unit/test_performance_report_resources.py | 1976 --- ...est_performance_report_runtime_evidence.py | 274 - ...test_performance_report_source_identity.py | 401 - ...est_performance_report_standalone_build.py | 81 - .../test_performance_report_study_contract.py | 482 - .../unit/test_performance_report_worker.py | 728 -- .../unit/test_performance_report_workspace.py | 891 -- .../test_prepare_class_c_bridge_bootstrap.py | 182 - .../unit/test_profile_warmup_reporting.py | 372 - .../unit/test_qq_z6g_final_comparison.py | 988 -- .../test_recurrence_numerical_ab_parity.py | 1015 -- .../test_recurrence_runtime_ab_analyzer.py | 290 - .../unit/test_recurrence_semantic_census.py | 415 - .../unit/test_structural_work_certificate.py | 591 - ...test_symjit_2_22_generated_fixture_gate.py | 628 - ...st_symjit_2_22_migration_benchmark_gate.py | 2319 ---- .../unit/test_three_mode_report_catalog.py | 1484 --- .../unit/test_three_mode_report_legacy.py | 2141 ---- .../unit/test_three_mode_report_render.py | 4664 ------- .../unit/test_three_mode_report_runner.py | 3034 ----- .../unit/test_three_mode_report_scheduler.py | 3736 ------ .../unit/test_three_mode_report_service.py | 461 - .../unit/test_umami_example_environment.py | 244 - .../tests/unit/test_umami_example_grouping.py | 112 - .../test_x86_performance_runtime_bundle.py | 731 -- ...est_x86_portable_performance_acceptance.py | 430 - .../unit/test_x86_qq_recurrence_acceptance.py | 478 - .../developer/amplicol_z6g_m0_capture.py | 1822 --- .../developer/arena_native_x86_acceptance.py | 1834 --- ...talog_final_source_structural_preflight.py | 477 - .../developer/catalog_restart_parity_gate.py | 665 - .../catalog_structural_parity_audit.py | 1422 --- .../catalog_structural_scope_registry.py | 242 - .../developer/compiled_all_jit_arena_gate.py | 1887 --- .../compiled_microkernel_acceptance.py | 2106 ---- .../emit_candidate_structural_preflight.py | 358 - .../developer/fft_gluon_candidate_probe.cpp | 811 -- .../fft_gluon_performance_acceptance.py | 2687 ---- .../fft_madgraph_selected_runtime.py | 3200 ----- .../developer/fft_numerical_acceptance.py | 2062 ---- .../developer/fft_results_summary_pdf.py | 557 - .../fft_scaling_final_publication_report.py | 1275 -- .../fft_scaling_selected_scalar_report.py | 1341 -- .../tools/developer/fft_scaling_study.py | 3943 ------ .../developer/fft_scaling_study_plots.py | 1701 --- .../developer/final_source_numerical_truth.py | 1315 -- .../developer/four_quark_compiled_gate.py | 2491 ---- .../developer/native_direct_cpp_probe.py | 805 -- .../tools/developer/numerical_acceptance.py | 2005 --- .../developer/on_the_fly_high_multiplicity.py | 2834 ----- .../tools/developer/on_the_fly_lc_gate.py | 3679 ------ .../developer/otf_contracted_parity_gate.py | 812 -- .../developer/otf_wave1_runtime_benchmark.py | 222 - .../prepare_builtin_without_auxiliary_qcd.py | 55 - .../tools/developer/prepare_class_c_bridge.py | 559 - .../developer/qq_z6g_final_comparison.py | 2209 ---- .../tools/developer/rebuild_rusticol.py | 279 - .../recurrence_numerical_ab_parity.py | 2144 ---- .../recurrence_runtime_ab_analyzer.py | 802 -- .../developer/recurrence_semantic_census.py | 1211 -- .../developer/reset_performance_campaign.py | 651 - .../developer/structural_work_certificate.py | 609 - .../symjit_2_22_generated_fixture_gate.py | 1034 -- .../symjit_2_22_migration_benchmark_gate.py | 4140 ------- .../x86_performance_runtime_bundle.py | 1141 -- .../x86_portable_performance_acceptance.py | 645 - .../developer/x86_qq_recurrence_acceptance.py | 767 -- pyamplicol/tools/fft_profiling/__init__.py | 2 - .../tools/fft_profiling/fft_profiling.py | 5274 -------- .../tools/performance_report/__init__.py | 33 - .../tools/performance_report/__main__.py | 9 - .../performance_report/aggregate_audit.py | 259 - .../tools/performance_report/agreements.py | 1135 -- .../tools/performance_report/arena_profile.py | 401 - .../tools/performance_report/artifacts.py | 1686 --- .../tools/performance_report/boundary.py | 169 - pyamplicol/tools/performance_report/cache.py | 1674 --- .../performance_report/campaign_activity.py | 288 - .../performance_report/campaign_holds.py | 464 - .../performance_report/campaign_policy.py | 1505 --- .../performance_report/campaign_reset.py | 1320 -- .../tools/performance_report/catalog.py | 821 -- pyamplicol/tools/performance_report/cli.py | 1609 --- .../performance_report/display_contract.py | 89 - .../tools/performance_report/final_audit.py | 7201 ----------- pyamplicol/tools/performance_report/legacy.py | 2737 ----- .../performance_report/legacy_structure.py | 1106 -- .../tools/performance_report/madgraph.py | 773 -- .../performance_report/manual_campaign.py | 10126 ---------------- .../tools/performance_report/measurement.py | 1911 --- .../performance_report/measurement_lineage.py | 4914 -------- pyamplicol/tools/performance_report/models.py | 227 - .../tools/performance_report/phase_state.py | 630 - .../performance_report/phase_timeline.py | 359 - .../tools/performance_report/prepared.py | 410 - .../tools/performance_report/publication.py | 853 -- .../tools/performance_report/publisher.py | 662 - pyamplicol/tools/performance_report/render.py | 5004 -------- .../tools/performance_report/report_policy.py | 289 - .../tools/performance_report/resources.py | 2068 ---- pyamplicol/tools/performance_report/runner.py | 5499 --------- .../performance_report/runtime_evidence.py | 645 - .../tools/performance_report/scheduler.py | 3870 ------ .../performance_report/selector_policy.py | 116 - .../tools/performance_report/service.py | 560 - .../performance_report/source_identity.py | 527 - .../performance_report/standalone_build.py | 123 - .../performance_report/study_contract.py | 780 -- pyamplicol/tools/performance_report/timing.py | 346 - .../performance_report/validation_summary.py | 550 - pyamplicol/tools/performance_report/worker.py | 689 -- .../performance_report/worker_harness.py | 177 - .../tools/performance_report/workspace.py | 1316 -- pyamplicol/tools/release/test_deployment.py | 59 - pyamplicol/umami_example/README.md | 227 - pyamplicol/umami_example/_metadata.py | 64 - pyamplicol/umami_example/requirements.txt | 6 - pyamplicol/umami_example/run.py | 150 - pyamplicol/umami_example/test_grouping.py | 244 - pyamplicol/umami_example/test_integrate.py | 501 - pyamplicol/umami_example/test_umami.py | 212 - 287 files changed, 34 insertions(+), 229732 deletions(-) delete mode 100644 pyamplicol/docs/performance_reports/README.md delete mode 100644 pyamplicol/docs/user/fullcolor-fft-profiling.md delete mode 100644 pyamplicol/docs/user/profiling-campaign-walkthrough.md delete mode 100644 pyamplicol/docs/user/profiling-campaigns.md delete mode 100644 pyamplicol/flake.lock delete mode 100644 pyamplicol/flake.nix delete mode 100755 pyamplicol/run_fft_profiling_render.sh delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/README.md delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/TABLE_FILLING.md delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/build_pdf.py delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/pyAmpliCol.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/report-workspace.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/report_environment.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/report_environment.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_full_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_lc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_nlc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_full_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_lc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_nlc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_ufo_sm_full_vs_madgraph_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_full_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_lc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_nlc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_ufo_sm_full_vs_madgraph_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_full_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_lc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_nlc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_ufo_sm_full_vs_madgraph_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_full_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_lc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_nlc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_vs_madgraph_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_lc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_nlc_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_contact_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_gravity_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_tables.py delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_validation_summary.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_z_builtin_sm_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/result_z_external_sm_table.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_lc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_nlc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_ufo_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_lc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_nlc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_ufo_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_lc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_nlc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_ufo_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_lc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_nlc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_lc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_nlc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_lc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_nlc.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_madgraph_full.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/report-cache.schema.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_contact.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_gravity.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/z_builtin_sm.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/results/z_external_sm.json delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/section_eager_execution.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/section_lc_flow_layouts.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/section_three_mode_performance_tables.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/section_ufo_support.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_dag.tex delete mode 100644 pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_example.tex delete mode 100755 pyamplicol/src/pyamplicol/_profiling_campaign/steer_performance_campaign.py delete mode 100644 pyamplicol/tests/fixtures/numerical_acceptance/ufo-sm-seed101-v1.json delete mode 100644 pyamplicol/tests/integration/test_numerical_acceptance.py delete mode 100644 pyamplicol/tests/integration/test_on_the_fly_artifact_probe.py delete mode 100644 pyamplicol/tests/unit/test_amplicol_z6g_m0_capture.py delete mode 100644 pyamplicol/tests/unit/test_arena_native_x86_acceptance.py delete mode 100644 pyamplicol/tests/unit/test_catalog_final_source_structural_preflight.py delete mode 100644 pyamplicol/tests/unit/test_catalog_restart_parity_gate.py delete mode 100644 pyamplicol/tests/unit/test_catalog_structural_parity_audit.py delete mode 100644 pyamplicol/tests/unit/test_catalog_structural_scope_registry.py delete mode 100644 pyamplicol/tests/unit/test_compiled_all_jit_arena_gate.py delete mode 100644 pyamplicol/tests/unit/test_compiled_microkernel_acceptance.py delete mode 100644 pyamplicol/tests/unit/test_conditioned_report_validation.py delete mode 100644 pyamplicol/tests/unit/test_exact_python_bootstrap.py delete mode 100644 pyamplicol/tests/unit/test_fft_gluon_performance_acceptance.py delete mode 100644 pyamplicol/tests/unit/test_fft_madgraph_selected_runtime.py delete mode 100644 pyamplicol/tests/unit/test_fft_numerical_acceptance.py delete mode 100644 pyamplicol/tests/unit/test_fft_profiling.py delete mode 100644 pyamplicol/tests/unit/test_fft_results_summary_pdf.py delete mode 100644 pyamplicol/tests/unit/test_fft_scaling_final_publication_report.py delete mode 100644 pyamplicol/tests/unit/test_fft_scaling_selected_scalar_report.py delete mode 100644 pyamplicol/tests/unit/test_fft_scaling_study.py delete mode 100644 pyamplicol/tests/unit/test_fft_scaling_study_plots.py delete mode 100644 pyamplicol/tests/unit/test_final_source_numerical_truth.py delete mode 100644 pyamplicol/tests/unit/test_four_quark_compiled_gate.py delete mode 100644 pyamplicol/tests/unit/test_legacy_structural_proof.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_audit_polish.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_entrypoint.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_interrupts.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_lightweight_reuse.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_observability.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_recycled_exit.py delete mode 100644 pyamplicol/tests/unit/test_manual_campaign_summary_and_lifecycle.py delete mode 100644 pyamplicol/tests/unit/test_manual_performance_campaign.py delete mode 100644 pyamplicol/tests/unit/test_numerical_acceptance.py delete mode 100644 pyamplicol/tests/unit/test_on_the_fly_artifact_scheduling.py delete mode 100644 pyamplicol/tests/unit/test_on_the_fly_high_multiplicity.py delete mode 100644 pyamplicol/tests/unit/test_on_the_fly_lc_gate.py delete mode 100644 pyamplicol/tests/unit/test_on_the_fly_performance_campaign.py delete mode 100644 pyamplicol/tests/unit/test_on_the_fly_recurrence_authority_campaign.py delete mode 100644 pyamplicol/tests/unit/test_on_the_fly_report_render.py delete mode 100644 pyamplicol/tests/unit/test_otf_contracted_parity_gate.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_aggregate_audit.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_agreements.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_artifacts.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_boundary.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_campaign_activity.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_campaign_holds.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_campaign_policy.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_campaign_reset.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_cli.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_final_audit.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_madgraph.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_measurement.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_measurement_lineage.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_measurement_lineage_adversarial.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_phase_state.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_phase_timeline.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_policy.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_prepared.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_publication.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_publication_lineage.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_publisher.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_resource_retention.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_resources.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_runtime_evidence.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_source_identity.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_standalone_build.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_study_contract.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_worker.py delete mode 100644 pyamplicol/tests/unit/test_performance_report_workspace.py delete mode 100644 pyamplicol/tests/unit/test_prepare_class_c_bridge_bootstrap.py delete mode 100644 pyamplicol/tests/unit/test_profile_warmup_reporting.py delete mode 100644 pyamplicol/tests/unit/test_qq_z6g_final_comparison.py delete mode 100644 pyamplicol/tests/unit/test_recurrence_numerical_ab_parity.py delete mode 100644 pyamplicol/tests/unit/test_recurrence_runtime_ab_analyzer.py delete mode 100644 pyamplicol/tests/unit/test_recurrence_semantic_census.py delete mode 100644 pyamplicol/tests/unit/test_structural_work_certificate.py delete mode 100644 pyamplicol/tests/unit/test_symjit_2_22_generated_fixture_gate.py delete mode 100644 pyamplicol/tests/unit/test_symjit_2_22_migration_benchmark_gate.py delete mode 100644 pyamplicol/tests/unit/test_three_mode_report_catalog.py delete mode 100644 pyamplicol/tests/unit/test_three_mode_report_legacy.py delete mode 100644 pyamplicol/tests/unit/test_three_mode_report_render.py delete mode 100644 pyamplicol/tests/unit/test_three_mode_report_runner.py delete mode 100644 pyamplicol/tests/unit/test_three_mode_report_scheduler.py delete mode 100644 pyamplicol/tests/unit/test_three_mode_report_service.py delete mode 100644 pyamplicol/tests/unit/test_umami_example_environment.py delete mode 100644 pyamplicol/tests/unit/test_umami_example_grouping.py delete mode 100644 pyamplicol/tests/unit/test_x86_performance_runtime_bundle.py delete mode 100644 pyamplicol/tests/unit/test_x86_portable_performance_acceptance.py delete mode 100644 pyamplicol/tests/unit/test_x86_qq_recurrence_acceptance.py delete mode 100755 pyamplicol/tools/developer/amplicol_z6g_m0_capture.py delete mode 100644 pyamplicol/tools/developer/arena_native_x86_acceptance.py delete mode 100644 pyamplicol/tools/developer/catalog_final_source_structural_preflight.py delete mode 100644 pyamplicol/tools/developer/catalog_restart_parity_gate.py delete mode 100644 pyamplicol/tools/developer/catalog_structural_parity_audit.py delete mode 100644 pyamplicol/tools/developer/catalog_structural_scope_registry.py delete mode 100644 pyamplicol/tools/developer/compiled_all_jit_arena_gate.py delete mode 100644 pyamplicol/tools/developer/compiled_microkernel_acceptance.py delete mode 100644 pyamplicol/tools/developer/emit_candidate_structural_preflight.py delete mode 100644 pyamplicol/tools/developer/fft_gluon_candidate_probe.cpp delete mode 100644 pyamplicol/tools/developer/fft_gluon_performance_acceptance.py delete mode 100755 pyamplicol/tools/developer/fft_madgraph_selected_runtime.py delete mode 100644 pyamplicol/tools/developer/fft_numerical_acceptance.py delete mode 100644 pyamplicol/tools/developer/fft_results_summary_pdf.py delete mode 100644 pyamplicol/tools/developer/fft_scaling_final_publication_report.py delete mode 100644 pyamplicol/tools/developer/fft_scaling_selected_scalar_report.py delete mode 100644 pyamplicol/tools/developer/fft_scaling_study.py delete mode 100644 pyamplicol/tools/developer/fft_scaling_study_plots.py delete mode 100644 pyamplicol/tools/developer/final_source_numerical_truth.py delete mode 100644 pyamplicol/tools/developer/four_quark_compiled_gate.py delete mode 100644 pyamplicol/tools/developer/native_direct_cpp_probe.py delete mode 100644 pyamplicol/tools/developer/numerical_acceptance.py delete mode 100644 pyamplicol/tools/developer/on_the_fly_high_multiplicity.py delete mode 100644 pyamplicol/tools/developer/on_the_fly_lc_gate.py delete mode 100644 pyamplicol/tools/developer/otf_contracted_parity_gate.py delete mode 100644 pyamplicol/tools/developer/otf_wave1_runtime_benchmark.py delete mode 100644 pyamplicol/tools/developer/prepare_builtin_without_auxiliary_qcd.py delete mode 100644 pyamplicol/tools/developer/prepare_class_c_bridge.py delete mode 100644 pyamplicol/tools/developer/qq_z6g_final_comparison.py delete mode 100644 pyamplicol/tools/developer/rebuild_rusticol.py delete mode 100644 pyamplicol/tools/developer/recurrence_numerical_ab_parity.py delete mode 100644 pyamplicol/tools/developer/recurrence_runtime_ab_analyzer.py delete mode 100644 pyamplicol/tools/developer/recurrence_semantic_census.py delete mode 100644 pyamplicol/tools/developer/reset_performance_campaign.py delete mode 100644 pyamplicol/tools/developer/structural_work_certificate.py delete mode 100644 pyamplicol/tools/developer/symjit_2_22_generated_fixture_gate.py delete mode 100644 pyamplicol/tools/developer/symjit_2_22_migration_benchmark_gate.py delete mode 100644 pyamplicol/tools/developer/x86_performance_runtime_bundle.py delete mode 100644 pyamplicol/tools/developer/x86_portable_performance_acceptance.py delete mode 100644 pyamplicol/tools/developer/x86_qq_recurrence_acceptance.py delete mode 100644 pyamplicol/tools/fft_profiling/__init__.py delete mode 100755 pyamplicol/tools/fft_profiling/fft_profiling.py delete mode 100644 pyamplicol/tools/performance_report/__init__.py delete mode 100644 pyamplicol/tools/performance_report/__main__.py delete mode 100644 pyamplicol/tools/performance_report/aggregate_audit.py delete mode 100644 pyamplicol/tools/performance_report/agreements.py delete mode 100644 pyamplicol/tools/performance_report/arena_profile.py delete mode 100644 pyamplicol/tools/performance_report/artifacts.py delete mode 100644 pyamplicol/tools/performance_report/boundary.py delete mode 100644 pyamplicol/tools/performance_report/cache.py delete mode 100644 pyamplicol/tools/performance_report/campaign_activity.py delete mode 100644 pyamplicol/tools/performance_report/campaign_holds.py delete mode 100644 pyamplicol/tools/performance_report/campaign_policy.py delete mode 100644 pyamplicol/tools/performance_report/campaign_reset.py delete mode 100644 pyamplicol/tools/performance_report/catalog.py delete mode 100644 pyamplicol/tools/performance_report/cli.py delete mode 100644 pyamplicol/tools/performance_report/display_contract.py delete mode 100644 pyamplicol/tools/performance_report/final_audit.py delete mode 100644 pyamplicol/tools/performance_report/legacy.py delete mode 100644 pyamplicol/tools/performance_report/legacy_structure.py delete mode 100644 pyamplicol/tools/performance_report/madgraph.py delete mode 100644 pyamplicol/tools/performance_report/manual_campaign.py delete mode 100644 pyamplicol/tools/performance_report/measurement.py delete mode 100644 pyamplicol/tools/performance_report/measurement_lineage.py delete mode 100644 pyamplicol/tools/performance_report/models.py delete mode 100644 pyamplicol/tools/performance_report/phase_state.py delete mode 100644 pyamplicol/tools/performance_report/phase_timeline.py delete mode 100644 pyamplicol/tools/performance_report/prepared.py delete mode 100644 pyamplicol/tools/performance_report/publication.py delete mode 100644 pyamplicol/tools/performance_report/publisher.py delete mode 100644 pyamplicol/tools/performance_report/render.py delete mode 100644 pyamplicol/tools/performance_report/report_policy.py delete mode 100644 pyamplicol/tools/performance_report/resources.py delete mode 100644 pyamplicol/tools/performance_report/runner.py delete mode 100644 pyamplicol/tools/performance_report/runtime_evidence.py delete mode 100644 pyamplicol/tools/performance_report/scheduler.py delete mode 100644 pyamplicol/tools/performance_report/selector_policy.py delete mode 100644 pyamplicol/tools/performance_report/service.py delete mode 100644 pyamplicol/tools/performance_report/source_identity.py delete mode 100644 pyamplicol/tools/performance_report/standalone_build.py delete mode 100644 pyamplicol/tools/performance_report/study_contract.py delete mode 100644 pyamplicol/tools/performance_report/timing.py delete mode 100644 pyamplicol/tools/performance_report/validation_summary.py delete mode 100644 pyamplicol/tools/performance_report/worker.py delete mode 100644 pyamplicol/tools/performance_report/worker_harness.py delete mode 100644 pyamplicol/tools/performance_report/workspace.py delete mode 100644 pyamplicol/umami_example/README.md delete mode 100644 pyamplicol/umami_example/_metadata.py delete mode 100644 pyamplicol/umami_example/requirements.txt delete mode 100644 pyamplicol/umami_example/run.py delete mode 100644 pyamplicol/umami_example/test_grouping.py delete mode 100644 pyamplicol/umami_example/test_integrate.py delete mode 100644 pyamplicol/umami_example/test_umami.py diff --git a/.gitattributes b/.gitattributes index 7c623641ac..410303ff9d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,24 +6,13 @@ .bzrignore export-ignore # pyamplicol tests and development tooling stay in the repository for its own -# PyPI releases. The MadGraph7 installer builds the wheel without them, except -# for the legacy-oracle modules that the wheel bundles. +# PyPI releases. The MadGraph7 installer builds the wheel without them. pyamplicol/tests/ export-ignore -pyamplicol/tools/developer/** export-ignore -pyamplicol/tools/developer/legacy_amplicol.py -export-ignore -pyamplicol/tools/developer/legacy_oracle -export-ignore -pyamplicol/tools/developer/legacy_oracle/** -export-ignore -pyamplicol/tools/fft_profiling/ export-ignore -pyamplicol/umami_example/ export-ignore -pyamplicol/flake.nix export-ignore -pyamplicol/flake.lock export-ignore -pyamplicol/run_fft_profiling_render.sh export-ignore +pyamplicol/tools/developer/ export-ignore # Generated pyamplicol data: GitHub collapses these in PR diffs. pyamplicol/Cargo.lock linguist-generated -pyamplicol/flake.lock linguist-generated pyamplicol/dependencies/python-runtime-lock.toml linguist-generated pyamplicol/tests/fixtures/** linguist-generated pyamplicol/src/pyamplicol/assets/selftest/** linguist-generated pyamplicol/src/pyamplicol/assets/models/json/** linguist-generated -pyamplicol/src/pyamplicol/_profiling_campaign/results/*.json linguist-generated diff --git a/docs/source/conf.py b/docs/source/conf.py index 164a6dbc0b..e2963634d0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -32,13 +32,7 @@ def _copy_pyamplicol_docs(): "_config.yml", "_includes", "css", "results", "archive", "arxiv", ".*" ) - def ignore(directory, names): - # Only the report index is tracked; campaigns are local output. - if os.path.basename(directory) == "performance_reports": - return {name for name in names if name != "README.md"} - return jekyll_only(directory, names) - - shutil.copytree(source, target, ignore=ignore) + shutil.copytree(source, target, ignore=jekyll_only) _copy_pyamplicol_docs() diff --git a/pyamplicol/README.md b/pyamplicol/README.md index fe501ea5ea..091108d1a3 100644 --- a/pyamplicol/README.md +++ b/pyamplicol/README.md @@ -228,152 +228,15 @@ The public C ABI is version 1. Every generated artifact can include standalone Python, C11, C++17, Fortran 2008, and dependency-free Rust 2021 drivers backed by the wheel-owned static Rusticol SDK. -## Profiling campaigns +## Performance reports -An installed wheel can populate a self-contained campaign workspace: - -```console -pyamplicol profiling-campaign copy ./pyamplicol-profiling-campaign --force -cd ./pyamplicol-profiling-campaign -./steer_performance_campaign.py run \ - --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in -``` - -That deliberately small real campaign measures only the final-state- -multiplicity-one `d d~ > Z` recurrence cell. Broader campaign selections are -intended for dedicated profiling hosts. The -[documentation](https://madgraph.org/pyamplicol/) covers selection, -continuation, optional original-AmpliCol comparisons, artifact retention, and -PDF generation. - -The source checkout also contains a thin orchestrator for the dedicated -FullColor FFT comparison. It delegates generation and timing to the existing -pyAmpliCol profiling commands and schedules independent measurement children: - -```console -just dev-install --with-legacy-amplicol --with-reference-fft -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --multiplicities 2 3 4 5 \ - --lines reference-fft amplicol pyamplicol-recurrence pyamplicol-otf madgraph \ - --cores 8 --candidate-cores 1 \ - --memory-limit-gib 30 --time-limit-seconds 3600 \ - --amplicol-root /path/to/AmpliCol \ - --reference-fft-root /path/to/AllGluonsMultipletFFT \ - --madgraph-root /path/to/MG5_aMC \ - --build-amplicol -``` - -`--multiplicities` adds the selected values to the persistent fill history and -defaults to `2 ... 9`. `--lines` similarly adds any combination of -`reference-fft`, `amplicol`, `pyamplicol-recurrence`, `pyamplicol-otf`, and -`madgraph`; the two pyAmpliCol groups each schedule their direct and FFT -companion curves together so they reuse the same generation lane. Dependencies -are selected automatically. -Repeating a command against the same output unions both selections, resumes -unfinished cells, and skips completed cells; -`--resume` is an explicit alias for that default. `--cores` is the total -scheduler budget, while `--candidate-cores` is one candidate child's core -claim and evaluator setting. The memory and time limits are strict per-child -cutoffs. `--retry` reruns only failed/skipped cells in the active selection. -`--overwrite` reruns every selected cell and replaces each old result only when -that cell's worker is about to launch; queued or blocked cells retain their old -results. Use `--output PATH` for an independent run directory. `--refresh` -removes only that exact recognized output directory and restarts it, so a -custom output also scopes the refresh; a path that does not exist simply starts -cleanly. Without `--output`, fixed and summed -workloads use separate `IMPLEMENTATION_DOCS/RESULTS/fft-profiling/runs/` -directories named `cluster-fullcolor-n2-n9` and -`cluster-fullcolor-helicity-sum-n2-n9`. Refresh also shares the persistent -MadGraph cache-writer lock and refuses to delete a run while a standalone -MadGraph profiler is using that cache. - -Add `--compare-helicity-sums` for the independent complete physical-helicity- -sum workload. The fixed-helicity MadGraph lane selects the shared helicity -through the generated `MATRIX(P,NHEL,IC)` entry point. The summed lane instead -calls the generated `SMATRIX(P,ANS)` with `USERHEL=-1`; MadGraph applies its -native IDEN normalization and may reuse its warmed `GOODHEL` pruning. Fixed- -helicity and summed overlays carry distinct workload identities and cannot be -mixed. `just dev-install` omits the developer-only AmpliCol and Reference FFT -repositories unless they are requested with `--with-legacy-amplicol` and -`--with-reference-fft`; either opt-in also installs the `fft-profiling` Python -extra into `.venv`. Their profiler roots default to -`dependencies/checkouts/legacy-amplicol` and -`dependencies/checkouts/reference-fft`; `--build-amplicol` may build the -AmpliCol probe once. Both paths can be overridden explicitly with -`--amplicol-root` and `--reference-fft-root`. The MadGraph root defaults to -`PYAMPLICOL_MADGRAPH_ROOT` or a recognized developer checkout and may be set -explicitly with `--madgraph-root`. - -The published fixed-helicity MadGraph series currently has measured points -through `n=5` for pure gluons and `n=6` for -`d d~ > d d~ + gluons`. Pure-gluon `n=6` retains its measured resource cutoff; -`n=7..9` are explicit protocol-scope not-applicable cells for both families. -The independent helicity-sum MadGraph series has measured points for both -families at `n=2..5`. Every admitted point passed the same-workload numerical -gate before entering the PDFs. - -The rolling plot frontiers are per process and implementation, rather than a -claim that every curve reaches the same `n`. Both fixed-helicity and helicity- -sum OTF curves are requested only through final-state `n=6`; beyond that the -publication protocol retains recurrence, AmpliCol, and Reference FFT where -applicable. Within that frontier, cutoffs are annotated rather than hidden or -interpolated. Pure-gluon OTF FFT reached the 3,600 s first-use runtime cap at -`n=6` and retains its measured `n=5` point. The helicity-sum comparison extends -the `d d~ > d d~ + gluons` curves through `n=6` using an authenticated isolated -30 GiB extension. At that point every requested curve measured successfully. -For OTF, direct and FFT setup took 1,725.8 s and 1,607.9 s, while warmed runtime -was 5.321 and 3.759 ms/point respectively (a 1.416x FFT speedup). The measured -peak RSS values were 1.17 and 1.22 GiB. - -The plotted *setup time* is deliberately method-specific. pyAmpliCol includes -artifact generation, a fresh load, the first requested evaluation, and OTF -family warm-up where applicable. Reference FFT includes its build, -initialization, and first pass. AmpliCol includes process/color-object -generation for the fixed workload, or process/raw-library generation and build -plus the immutable snapshot for the summed workload. Warmed runtime is measured -separately after those setup boundaries. Resource limits apply individually to -each child. The retained isolated high-frontier extensions use a 30 GiB -process-tree guard. - -After the first snapshot is published, rendering never waits for workers and -uses the latest available data. Concurrent renders and refresh publication are -serialized so an older render cannot replace a newer one: - -```console -python tools/fft_profiling/fft_profiling.py --render -python tools/fft_profiling/fft_profiling.py --render --compare-helicity-sums -python tools/fft_profiling/fft_profiling.py --render --output /path/to/run -``` - -For a custom output, the saved manifest determines whether the workload is -fixed-helicity or helicity-summed, so a render does not need to repeat -`--compare-helicity-sums`. Default outputs still use that flag to select the -helicity-sum workspace. Default outputs also refresh the corresponding -canonical PDF; custom outputs keep their PDF inside the selected run directory. -During a scan, the progress display reports the active cell, total live RSS, -and occupied core slots. - -An older local MadGraph overlay that predates the node-fingerprint field may -appear only in a nonterminal anytime render, only when its system, machine, and -Python version match the current workstation. Such plots carry an explicit -provenance note; the strict terminal publication merger still requires the -complete host identity produced by a fresh profiler run. - -The public performance index retains four selected rendered snapshots. Raw -JSON, generated tables, attempts, and campaign workspaces stay untracked: +Selected manual measurement snapshots are published in the upstream repository: - [MacBook M3 report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/macbook_M3_pyAmpliCol.pdf) - [AMD EPYC report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/EPYC_pyAmpliCol.pdf) - [FullColor FFT selected-helicity snapshot](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/summary_plots_final.pdf) - [FullColor FFT helicity-sum snapshot](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/summary_plots_final_helicity_sum.pdf) -These are manual measurement snapshots rather than release-CI results; raw -campaign data remains local. The general host report format is reproducible -from an installed package, while the FullColor FFT snapshots use the source- -checkout orchestrator above. - ## Documentation Read the complete [pyAmpliCol documentation](https://madgraph.org/pyamplicol/). diff --git a/pyamplicol/build_backend/_pyamplicol_build.py b/pyamplicol/build_backend/_pyamplicol_build.py index 7d0970e3b3..68e269aca1 100644 --- a/pyamplicol/build_backend/_pyamplicol_build.py +++ b/pyamplicol/build_backend/_pyamplicol_build.py @@ -17,7 +17,7 @@ import tomllib from collections.abc import Callable, Iterator, Mapping from contextlib import contextmanager -from pathlib import Path, PurePosixPath +from pathlib import Path from tempfile import TemporaryDirectory from typing import Any, TypeVar @@ -117,30 +117,9 @@ def _runtime_artifact_id(manifest: Mapping[str, object]) -> str: "tools/ci/__init__.py", "tools/ci/memory_watchdog.py", "tools/developer", - "tools/fft_profiling", - "tools/performance_report", "tools/release", "tools/typing", ) -_PROFILING_CAMPAIGN_SOURCE = Path("src/pyamplicol/_profiling_campaign") -_PROFILING_CAMPAIGN_REQUIRED_FILES = ( - Path("README.md"), - Path("TABLE_FILLING.md"), - Path("build_pdf.py"), - Path("pyAmpliCol.tex"), - Path("report-workspace.json"), - Path("report_environment.json"), - Path("report_environment.tex"), - Path("result_tables.py"), - Path("result_validation_summary.tex"), - Path("steer_performance_campaign.py"), -) -_PROFILING_CAMPAIGN_GLOBS = ( - "result_*_table.tex", - "section_*.tex", - "results/*.json", -) -_PROFILING_CAMPAIGN_FILE_COUNT = 69 _RELEASE_BUILD_INFO_FIELDS = { "publishable", "schema_version", @@ -148,18 +127,6 @@ def _runtime_artifact_id(manifest: Mapping[str, object]) -> str: "source_revision", "version", } -_PERFORMANCE_REPORT_REQUIRED_MODULES = { - "__init__.py", - "cli.py", - "manual_campaign.py", - "scheduler.py", -} -_LEGACY_ORACLE_REQUIRED_MODULES = { - "__init__.py", - "checkout.py", - "model.py", - "probe.py", -} IGNORED_NAMES = { "__pycache__", ".agent-work", @@ -186,7 +153,6 @@ def _runtime_artifact_id(manifest: Mapping[str, object]) -> str: Path("docs/.result_outputs"), Path("docs/archive"), Path("outputs"), - _PROFILING_CAMPAIGN_SOURCE / "campaign_artifacts", Path("src/pyamplicol/_sdk/fortran"), Path("src/pyamplicol/_sdk/include"), Path("src/pyamplicol/_sdk/lib"), @@ -523,10 +489,9 @@ def _is_excluded(relative: Path) -> bool: and relative.name.endswith(_NATIVE_EXTENSION_SUFFIXES) ): return True - report_source = relative.is_relative_to(Path("docs")) or relative.is_relative_to( - _PROFILING_CAMPAIGN_SOURCE + return relative.is_relative_to(Path("docs")) and relative.name.endswith( + _TEX_BUILD_SUFFIXES ) - return report_source and relative.name.endswith(_TEX_BUILD_SUFFIXES) def _reject_symlinks(path: Path, relative: Path = Path()) -> None: @@ -721,76 +686,6 @@ def _stage_packaged_examples(overlay: Path) -> None: shutil.copytree(source, target, ignore=_copy_ignore(overlay)) -def _profiling_campaign_inventory(source: Path) -> tuple[Path, ...]: - selected = set(_PROFILING_CAMPAIGN_REQUIRED_FILES) - for pattern in _PROFILING_CAMPAIGN_GLOBS: - selected.update(path.relative_to(source) for path in source.glob(pattern)) - missing = tuple( - relative - for relative in _PROFILING_CAMPAIGN_REQUIRED_FILES - if not (source / relative).is_file() - ) - if missing or len(selected) != _PROFILING_CAMPAIGN_FILE_COUNT: - detail = ", ".join(path.as_posix() for path in missing) - raise RuntimeError( - "wheel profiling campaign has an invalid inventory" - + (f": missing {detail}" if detail else "") - ) - for relative in selected: - path = source / relative - if path.is_symlink() or not path.is_file(): - raise RuntimeError( - f"wheel profiling campaign has an unsafe member: {relative}" - ) - return tuple(sorted(selected, key=lambda path: path.as_posix())) - - -def _stage_packaged_profiling_campaign(overlay: Path) -> None: - source = overlay / _PROFILING_CAMPAIGN_SOURCE - if not source.is_dir(): - raise RuntimeError("wheel build input has no profiling campaign directory") - _profiling_campaign_inventory(source) - - performance_source = overlay / "tools" / "performance_report" - watchdog_source = overlay / "tools" / "ci" / "memory_watchdog.py" - legacy_source = overlay / "tools" / "developer" / "legacy_amplicol.py" - oracle_source = overlay / "tools" / "developer" / "legacy_oracle" - runtime_target = overlay / "src" / "pyamplicol" / "_performance_report" - performance_modules = tuple(sorted(performance_source.glob("*.py"))) - oracle_modules = tuple(sorted(oracle_source.glob("*.py"))) - if ( - not _PERFORMANCE_REPORT_REQUIRED_MODULES.issubset( - {path.name for path in performance_modules} - ) - or not _LEGACY_ORACLE_REQUIRED_MODULES.issubset( - {path.name for path in oracle_modules} - ) - or not watchdog_source.is_file() - or not legacy_source.is_file() - ): - raise RuntimeError("wheel build input has incomplete profiling runtime sources") - for path in (*performance_modules, watchdog_source, legacy_source, *oracle_modules): - if path.is_symlink() or not path.is_file(): - raise RuntimeError(f"wheel profiling runtime has an unsafe member: {path}") - if runtime_target.exists(): - raise RuntimeError("wheel overlay already contains a profiling runtime") - runtime_target.mkdir(parents=True) - for path in performance_modules: - shutil.copy2(path, runtime_target / path.name) - shutil.copy2(watchdog_source, runtime_target / "_memory_watchdog.py") - developer_target = runtime_target / "_developer" - developer_target.mkdir() - (developer_target / "__init__.py").write_text( - "# SPDX-License-Identifier: 0BSD\n", - encoding="utf-8", - ) - shutil.copy2(legacy_source, developer_target / legacy_source.name) - oracle_target = developer_target / "legacy_oracle" - oracle_target.mkdir() - for path in oracle_modules: - shutil.copy2(path, oracle_target / path.name) - - def _stage_python_stub(overlay: Path) -> None: source = ( overlay @@ -1114,7 +1009,7 @@ def _mark_candidate( package = overlay / "src" / "pyamplicol" package.mkdir(parents=True, exist_ok=True) - source_revision = _clean_source_revision(allow_generated_report_outputs=True) + source_revision = _clean_source_revision() (package / "_build_info.json").write_text( json.dumps( { @@ -1229,101 +1124,8 @@ def _stage_release_build_info(overlay: Path, version: str) -> None: raise RuntimeError("release source archive has invalid build provenance") -def _generated_report_status_only(status: bytes) -> bool: - """Recognize only report outputs already excluded by campaign identity.""" - - records = status.split(b"\0") - if ( - not records - or records[-1] - or not all(len(record) >= 4 and record[2:3] == b" " for record in records[:-1]) - ): - return False - entries = tuple( - (record[:2], os.fsdecode(record[3:])) for record in records[:-1] - ) - paths = tuple(path for _state, path in entries) - classifier_path = Path("tools/performance_report/source_identity.py") - if classifier_path.as_posix() in paths: - return False - try: - namespace = runpy.run_path(str(ROOT / classifier_path)) - classifier = namespace.get("_generated_report_path") - except (OSError, RuntimeError, TypeError, ValueError): - return False - if not callable(classifier): - return False - try: - tracked = _git_inventory(build_inputs_only=False) - if tracked is None: - return False - copied_campaign_roots = _untracked_profiling_campaign_roots( - entries, - tracked=tracked, - ) - return all( - classifier(path) is True - or ( - state == b"??" - and any( - len(PurePosixPath(path).parts) > len(root) - and PurePosixPath(path).parts[: len(root)] == root - for root in copied_campaign_roots - ) - ) - for state, path in entries - ) - except (OSError, RuntimeError, TypeError, ValueError): - return False - - -def _untracked_profiling_campaign_roots( - entries: tuple[tuple[bytes, str], ...], - *, - tracked: list[Path], -) -> set[tuple[str, ...]]: - """Recognize roots of user-owned untracked copied report campaigns. - - ``pyamplicol profiling-campaign copy`` is intentionally useful inside a - contributor checkout. Its files are trusted steering inputs and outputs, - but the candidate overlay is built exclusively from Git-tracked inventory, - so they cannot alter its Python or native runtime. This exception is - applied only to ``??`` status records; edits to tracked report sources - remain source dirt. - """ - - markers: dict[tuple[str, ...], set[str]] = {} - for state, value in entries: - path = PurePosixPath(value) - parts = path.parts - if ( - state != b"??" - or path.is_absolute() - or len(parts) < 2 - or any(part in {"", ".", ".."} for part in parts) - or parts[-1] - not in {"report-workspace.json", "steer_performance_campaign.py"} - ): - continue - markers.setdefault(parts[:-1], set()).add(parts[-1]) - required = {"report-workspace.json", "steer_performance_campaign.py"} - tracked_parts = tuple( - PurePosixPath(path.as_posix()).parts for path in tracked - ) - return { - root - for root, names in markers.items() - if required <= names - and not any( - len(parts) >= len(root) and parts[: len(root)] == root - for parts in tracked_parts - ) - } - - def _clean_source_revision( *, - allow_generated_report_outputs: bool = False, allow_dirty: bool = False, ) -> str | None: """Return the exact source revision only for a clean Git checkout. @@ -1367,10 +1169,7 @@ def _clean_source_revision( else record for record in status.split(b"\0") ) - if status and not allow_dirty and ( - not allow_generated_report_outputs - or not _generated_report_status_only(status) - ): + if status and not allow_dirty: return None revision = subprocess.run( ["git", "rev-parse", "HEAD"], @@ -1937,7 +1736,6 @@ def _from_overlay( if with_sdk: _stage_source_hash(overlay) _stage_packaged_examples(overlay) - _stage_packaged_profiling_campaign(overlay) _stage_python_stub(overlay) _stage_runtime_resources(overlay) if prepared_model_recovery: diff --git a/pyamplicol/docs/README.md b/pyamplicol/docs/README.md index 1eff0c1fec..98302b5e38 100644 --- a/pyamplicol/docs/README.md +++ b/pyamplicol/docs/README.md @@ -35,7 +35,7 @@ Python, C11, C++17, Fortran 2008, and Rust 2021 interfaces. | prepare and evaluate tree-level spin and colour correlations | [Born Correlations](correlators.md) and [Correlation Conventions](correlator-conventions.md), LC/NLC/full colour and grouped Python evaluation | | use C, C++, Fortran, Rust, or generated Python drivers | [Native APIs](user/native-apis.md) | | build a UMAMI shared library or integrate with MadSpace | [UMAMI and MadSpace](user/umami-api.md) | -| benchmark, reproduce, or view performance reports | [Profiling and Benchmarking](user/profiling-and-benchmarking.md), [FullColor FFT Profiling](user/fullcolor-fft-profiling.md), and [published performance reports](performance_reports/README.md) | +| benchmark or profile a process | [Profiling and Benchmarking](user/profiling-and-benchmarking.md) | | diagnose an error | [Troubleshooting](user/troubleshooting.md) | ## Install and try it @@ -111,7 +111,7 @@ flows, and resolved metadata; particles never cross the `>` boundary. See - **Using pyAmpliCol:** [Examples Gallery](user/examples-gallery.md), [Command-Line Interface](user/command-line-interface.md), [Runtime and Selectors](user/runtime-and-selectors.md) - **Generation:** [Models and Processes](user/models-and-processes.md), including scalar HEFT, [Generation Modes and Evaluators](user/generation-modes-and-evaluators.md), and [Process Grouping](user/process-grouping.md) of subprocesses with equal matrix elements -- **Guided workflows:** [LC workloads and execution modes](user/lc-workloads-and-execution-modes.md), [Profiling campaign: from measurements to the PDF](user/profiling-campaign-walkthrough.md), [FullColor FFT Profiling](user/fullcolor-fft-profiling.md) +- **Guided workflows:** [LC workloads and execution modes](user/lc-workloads-and-execution-modes.md) - **Deployment:** [Artifacts and Portability](user/artifacts-and-portability.md), [Release and Platform Support](user/release-and-support.md) - **Background:** [Architecture Overview](user/architecture-overview.md), [Symbolica and Licensing](user/symbolica-and-licensing.md) diff --git a/pyamplicol/docs/development/PACKAGING_CONTRACT.md b/pyamplicol/docs/development/PACKAGING_CONTRACT.md index 7896f2c1e2..63a9a243cf 100644 --- a/pyamplicol/docs/development/PACKAGING_CONTRACT.md +++ b/pyamplicol/docs/development/PACKAGING_CONTRACT.md @@ -111,7 +111,7 @@ The wheel contains: - the typed Python package and one native extension; - model assets with their provenance and content manifest; -- packaged examples, an empty profiling-campaign workspace, and +- packaged examples and Python/C11/C++17/Fortran 2008/Rust 2021 API templates; - direct-JIT f64 self-test data; - license and third-party notice files; diff --git a/pyamplicol/docs/performance_reports/README.md b/pyamplicol/docs/performance_reports/README.md deleted file mode 100644 index cb8b9c8453..0000000000 --- a/pyamplicol/docs/performance_reports/README.md +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "Performance Reports" -nav_order: 2 -parent: "Profiling and Benchmarking" ---- - -# Performance Reports - -See [FullColor FFT Profiling](../user/fullcolor-fft-profiling.md) for the -source-checkout driver, cluster resource limits, incremental top-ups, -targeted overwrite, and render-at-any-time workflow that produces the FFT -snapshots below. - -The repository publishes four selected rendered snapshots from manual -measurement campaigns: - -- [MacBook M3 report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/macbook_M3_pyAmpliCol.pdf) -- [AMD EPYC report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/EPYC_pyAmpliCol.pdf) -- [FullColor FFT selected-helicity snapshot](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/summary_plots_final.pdf) -- [FullColor FFT helicity-sum snapshot](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/summary_plots_final_helicity_sum.pdf) - -The first two PDFs are general host reports. The FullColor FFT selected- -helicity snapshot times one shared known-nonzero helicity from helicity-general -artifacts; the helicity-sum snapshot times the complete physical helicity sum. -Both snapshots include genuine same-workload MadGraph standalone series. The -fixed series uses the generated helicity-general standalone and selects the -shared helicity through `MATRIX(P,NHEL,IC)`; it currently measures pure gluons -through `n=5` and `d d~ > d d~ + gluons` through `n=6`. The independent summed -series measures both families at `n=2..5` through MadGraph's generated -`SMATRIX(P,ANS)` entry point with `USERHEL=-1`, native IDEN normalization, and -warmed `GOODHEL` pruning. It does not reuse the fixed-helicity timings. -The FFT PDFs are rolling development snapshots, not claims that every -final-state multiplicity through `n=9` has completed. - -Their frontiers are curve-specific. Both fixed-helicity and helicity-sum OTF -curves are requested only through final-state `n=6`; beyond that the publication -protocol retains recurrence, AmpliCol, and Reference FFT where applicable. -Pure-gluon OTF FFT reached the 3,600 s first-use runtime cap at `n=6` and retains -its measured `n=5` point. The helicity-sum snapshot extends -`d d~ > d d~ + gluons` through `n=6`, where every requested curve measured. -OTF direct and FFT setup took 1,725.8 s and 1,607.9 s; their warmed runtimes were -5.321 and 3.759 ms/point (1.416x faster with FFT), at 1.17 and 1.22 GiB peak -RSS. These isolated measurements used a 10-hour time limit and 30 GiB -process-tree guard and retain their own per-cell provenance. - -The FFT plots use a deliberately method-specific *setup time*. pyAmpliCol -includes artifact generation, a fresh load, the first requested evaluation, -and OTF family warm-up where applicable. Reference FFT includes its build, -initialization, and first pass. AmpliCol includes process/color-object -generation for the fixed workload, or process/raw-library generation and build -plus the immutable snapshot for the summed workload. Warmed runtime remains a -separate measurement after those boundaries. - -These PDFs are measurement-host results, not release-CI results. Raw JSON, -generated TeX, build workspaces, attempts, logs, locks, and coordination state -remain untracked. The blank/reset JSON and TeX resources installed by -pyAmpliCol are campaign templates, not published measurements. - -Create or reset a self-contained campaign from any installed wheel with: - -```console -pyamplicol profiling-campaign copy ./pyamplicol-profiling-campaign --force -./pyamplicol-profiling-campaign/steer_performance_campaign.py run \ - --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in \ - --no-dependencies-added --no-dashboard -./pyamplicol-profiling-campaign/steer_performance_campaign.py refresh-pdf -``` - -The run above is the supported quick installation check: it measures only the -final-state-multiplicity-one `d d~ > Z` recurrence cell. Broader selections -produce the same report format as the two general host PDFs. Re-running -`refresh-pdf` directly reproduces the PDF from the campaign's current results; -no repository report data is required. - -Runtime attempts, artifacts, locks, and coordination state live visibly in -`pyamplicol-profiling-campaign/campaign_artifacts/`. Moving or renaming the -whole campaign directory moves that state with it; campaigns with the same -basename in different parents remain independent. Historical repository-global -`.artifacts` state is intentionally ignored. - -`--force` replaces the managed template files and resets only -`campaign_artifacts/`, the managed PDF and summary IDs, measurement lineage, -and known LaTeX byproducts. It preserves unrelated destination files and the -recorded local-AmpliCol checkout. Stop an active campaign before resetting it; -an active controller makes the command fail without removing state. - -All pyAmpliCol backends use installed resources. Measuring the optional -original-AmpliCol reference additionally requires -`--original-amplicol PATH_TO_COMPLETE_CHECKOUT`; without that checkout only -that backend is reported unavailable. pyAmpliCol and the supported patched -comparison checkout have no LHAPDF dependency. diff --git a/pyamplicol/docs/user/artifacts-and-portability.md b/pyamplicol/docs/user/artifacts-and-portability.md index bb060aba42..765bdbadb3 100644 --- a/pyamplicol/docs/user/artifacts-and-portability.md +++ b/pyamplicol/docs/user/artifacts-and-portability.md @@ -255,13 +255,6 @@ Process artifacts are trusted executable inputs. Direct SymJIT applications are lowered to native code, and C++/ASM artifacts contain native libraries. Generate them yourself or receive them through a channel you trust. -## Campaign artifacts are a separate state layer - -A profiling campaign stores generated process artifacts, attempts, and current -pointers below its own visible `campaign_artifacts/` root. Move the entire -campaign directory to move that state. Do not transplant individual current -pointer files between campaigns. See [Profiling Campaigns](profiling-campaigns.md). - ## Common compatibility failures | Message or symptom | Meaning | Next step | diff --git a/pyamplicol/docs/user/command-line-interface.md b/pyamplicol/docs/user/command-line-interface.md index c536673d71..4c1193950e 100644 --- a/pyamplicol/docs/user/command-line-interface.md +++ b/pyamplicol/docs/user/command-line-interface.md @@ -34,7 +34,6 @@ drives the typed [Python API](python-api.md). | `examples list` | List shipped card names, actions, and descriptions | `pyamplicol examples list` | | `examples copy` | Create an editable, self-contained example workspace | `pyamplicol examples copy ./pyamplicol-examples --force` | | `examples run` | Run one named packaged card in a private cache workspace | `pyamplicol examples run evaluate_total` | -| `profiling-campaign copy` | Create a self-contained performance campaign | See [Profiling Campaigns](profiling-campaigns.md) | | `doctor` | Diagnose the installed runtime and SDK | `pyamplicol doctor` | | `self-test` | Run the installed-package smoke test | `pyamplicol self-test` | @@ -182,9 +181,6 @@ Do not combine `--fft` and `--color-contraction`; use either spelling. Card settings are overridden by dedicated flags, then by ordered `--set` options as usual. -For the dedicated direct/FFT/reference scaling scan, see -[FullColor FFT Profiling](fullcolor-fft-profiling.md). - `--dry-run` performs the operation exposed as `Generator.plan()`. It creates no artifact, output directory, or model-cache entry. A raw UFO or JSON source must already have a reusable compiled-model cache entry, or be compiled explicitly, diff --git a/pyamplicol/docs/user/configuration.md b/pyamplicol/docs/user/configuration.md index 786c117eef..12ade6e57b 100644 --- a/pyamplicol/docs/user/configuration.md +++ b/pyamplicol/docs/user/configuration.md @@ -267,9 +267,7 @@ For the adjoint basis, single-helicity full-colour recurrence benchmarks of `g g > (n-2) g` on one core showed it faster than trace for `n >= 6`: at `n = 10` it evaluated 3.9x faster per sample (57.8 versus 227 ms), generated 4.2x faster and used 2.4x less memory during generation. Below `n = 6` the two -bases are comparable, so compare setup and warmed runtime for other workloads. See -[FullColor FFT Profiling](fullcolor-fft-profiling.md) for the resumable -comparison driver and published snapshots. +bases are comparable, so compare setup and warmed runtime for other workloads. ```toml [color] diff --git a/pyamplicol/docs/user/fullcolor-fft-profiling.md b/pyamplicol/docs/user/fullcolor-fft-profiling.md deleted file mode 100644 index f1ddc34aae..0000000000 --- a/pyamplicol/docs/user/fullcolor-fft-profiling.md +++ /dev/null @@ -1,277 +0,0 @@ ---- -title: "FullColor FFT Profiling" -nav_order: 3 -parent: "Profiling and Benchmarking" ---- - - -# FullColor FFT Profiling - -The source checkout contains a thin, resumable orchestrator for comparing -exact full-colour matrix-element implementations. It delegates physics -generation, profiling, validation, plotting, and PDF assembly to the existing -pyAmpliCol developer tools; the driver owns only selection, scheduling, -per-child resource guards, and persistent progress. - -This workflow is distinct from selecting -`color.contraction = "symmetric-group-fft"` in an ordinary generated artifact: - -- **symmetric-group FFT contraction** is a pyAmpliCol runtime algorithm for - exact NLC/full colour in recurrence and on-the-fly execution; -- **Reference FFT** is the optional external `AllGluonsMultipletFFT` comparison - checkout; -- **the profiling orchestrator** measures those implementations alongside - direct pyAmpliCol, original AmpliCol, and MadGraph where applicable. - -The orchestrator is source-checkout-only. It is intended for a workstation or -cluster node with explicit CPU, memory, and wall-time budgets. - -For ordinary NLC/full recurrence or on-the-fly generation, the defaults -`contraction="auto"` and `fft_basis="adjoint"` try exact FFT, with direct -fallback for unsupported plans. Select `--color-accuracy full` to use this -policy. This adaptively selects certified two-anchor DDM for pure Yang–Mills -trees and single-insertion HEFT (`HIG = 1`), retains fundamental chains for -quarks, and uses exact trace tensors where DDM is unproven. Compare the saved -`fft_basis_selection` as well as the request: requesting adjoint does not imply -that every process used DDM or gained a smaller basis. LC, compiled/eager -execution, and correlators retain direct/trace. Use `--color-contraction direct` -to opt out, or `--fft adjoint` / `--fft trace` to force FFT and retain errors -for unsupported plans. Historical curves retain their saved basis settings -and must not be relabelled. In the benchmarked pure-gluon family the -adjoint basis was faster than trace for six or more external gluons; compare -setup and warmed runtime separately for other workloads. - -## Prepare a profiling checkout - -Enter the repository's Nix environment when available, then request only the -optional references needed by the scan: - -```console -nix develop -just dev-install --with-reference-fft --with-legacy-amplicol -``` - -`--with-reference-fft` clones the public -`rikkert-frederix/AllGluonsMultipletFFT` revision pinned by pyAmpliCol. -`--with-legacy-amplicol` clones the pinned original-AmpliCol comparison. -Both are omitted by a default `just dev-install`; either opt-in also installs -the PDF/plotting dependencies into `.venv`. If a managed Reference FFT checkout -predates the public repository, add `--update` once so its `origin` is migrated. - -MadGraph is not installed by `dev-install`. Pass a complete installation root -containing `bin/mg5_aMC` and `VERSION` with `--madgraph-root`. - -## Select process families and curves - -The scan has two independent process families: - -| Selector | Process family | -| --- | --- | -| `gg` | `g g > g g + gluons` | -| `ddbar` | `d d~ > d d~ + gluons` | - -`--lines` accepts grouped comparison series: - -| Selector | Curves requested | -| --- | --- | -| `reference-fft` | External pure-gluon Reference FFT | -| `amplicol` | Original AmpliCol | -| `pyamplicol-recurrence` | pyAmpliCol recurrence direct and FFT | -| `pyamplicol-otf` | pyAmpliCol on-the-fly direct and FFT | -| `madgraph` | Same-host MadGraph standalone | - -For a targeted top-up, use a concrete pyAmpliCol line: -`recurrence-direct`, `recurrence-fft`, `otf-direct`, or `otf-fft`. -Required authority/baseline shards are added automatically. For example, a -pyAmpliCol pure-gluon comparison may require Reference FFT, while a `ddbar` -comparison may require original AmpliCol. - -## Small Reference FFT example - -This fills only Reference FFT for the pure-gluon family at final-state -multiplicities 2, 3, and 4: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --output /shared/path/fft-reference-gg \ - --families gg --lines reference-fft \ - --multiplicities 2 3 4 \ - --cores 10 \ - --memory-limit-gib 100 --time-limit-seconds 36000 \ - --reference-fft-root "$PWD/dependencies/checkouts/reference-fft" -``` - -Use `--dry-run` first to print the deterministic plan without creating the -output or starting workers. - -## Complete cluster scan - -The following command requests both process families, every grouped series, -ten scheduler cores, a 100 GiB per-child memory guard, and a 10-hour per-cell -time limit in one explicit output directory: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --output /shared/path/pyamplicol-fft-profile \ - --families gg ddbar \ - --lines reference-fft amplicol pyamplicol-recurrence pyamplicol-otf madgraph \ - --multiplicities 2 3 4 5 6 7 8 9 \ - --cores 10 --candidate-cores 1 \ - --memory-limit-gib 100 --time-limit-seconds 36000 \ - --amplicol-root "$PWD/dependencies/checkouts/legacy-amplicol" \ - --reference-fft-root "$PWD/dependencies/checkouts/reference-fft" \ - --madgraph-root /shared/path/MG5_aMC \ - --build-amplicol -``` - -`--build-amplicol` permits the first fixed-helicity AmpliCol shard to build its -probe. It can remain on subsequent resumptions; an already valid probe is -reused. - -Resource options have deliberately narrow meanings: - -- `--cores` is the total scheduler slot budget across active children; -- `--candidate-cores` is one pyAmpliCol child's slot claim and exact - `evaluator.optimization.cores` setting; -- `--memory-limit-gib` and `--time-limit-seconds` are strict per-child/per-cell - limits, not aggregate campaign limits; -- the time limit covers generation/setup and runtime measurement; -- `--target-seconds` controls calibrated runtime sampling after setup and is - not the cell cutoff. - -The progress headline reports the active cell, aggregate live RSS, and occupied -core slots. A child crossing its own guard is terminated and retained as a -cutoff result; other cells continue. - -## Fixed helicity and complete helicity sums - -The default workload evaluates one shared known-nonzero helicity from artifacts -that retain general helicity coverage. Add `--compare-helicity-sums` for the -independent complete physical-helicity sum: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --output /shared/path/pyamplicol-fft-profile-helicity-sum \ - --compare-helicity-sums \ - --families gg ddbar \ - --lines reference-fft amplicol pyamplicol-recurrence pyamplicol-otf madgraph \ - --multiplicities 2 3 4 5 6 \ - --cores 10 --candidate-cores 1 \ - --memory-limit-gib 100 --time-limit-seconds 36000 \ - --amplicol-root "$PWD/dependencies/checkouts/legacy-amplicol" \ - --reference-fft-root "$PWD/dependencies/checkouts/reference-fft" \ - --madgraph-root /shared/path/MG5_aMC -``` - -Fixed-helicity and helicity-sum measurements have different workload -identities and must use separate output directories. MadGraph's summed lane -uses its generated `SMATRIX(P,ANS)` entry point with `USERHEL=-1`; it does not -reuse fixed-helicity measurements. - -## Resume, retry, overwrite, or refresh - -The default behavior is resumable and additive. Repeating a command with the -same `--output`: - -- recovers unfinished prior requests; -- skips completed cells; -- adds newly selected families, lines, and multiplicities to the persistent - history; -- refreshes plots as new completed evidence becomes available. - -`--resume` is an explicit alias for that default. More forceful choices are -scoped to the current `--families`, `--lines`, and `--multiplicities`: - -| Option | Effect | -| --- | --- | -| `--retry` | Rerun selected failed or skipped cells. | -| `--overwrite` | Rerun every selected cell; keep its old result until that worker actually starts. | -| `--refresh` | Delete the exact recognized output workspace and restart it from scratch. | - -Use targeted overwrite to refine a measured subset without discarding the -rest of the campaign: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --output /shared/path/pyamplicol-fft-profile \ - --families ddbar --lines otf-fft \ - --multiplicities 6 --overwrite \ - --cores 10 --memory-limit-gib 100 --time-limit-seconds 36000 -``` - -`--refresh` is intentionally conservative: it refuses an unrecognized path and -will not remove a workspace while a coordinated MadGraph writer is active. - -Inspect machine-readable progress without launching work: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --status --output /shared/path/pyamplicol-fft-profile -``` - -## Render what is currently available - -The driver publishes immutable snapshots during a scan. Rendering freezes the -latest already-published snapshot immediately and never waits for active -workers: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --render --output /shared/path/pyamplicol-fft-profile -``` - -For a custom output, the saved manifest determines whether the workload is -fixed-helicity or helicity-summed; repeating `--compare-helicity-sums` is not -required. The current PDF is written below: - -```text -RUN/render/current/summary_plots_final.pdf -RUN/render/current/summary_plots_final_helicity_sum.pdf -``` - -Only the filename matching the run's workload is produced. The same render -contains six PNGs: setup time, warmed runtime, and peak RSS for each process -family. - -Without a custom output, select the two canonical workspaces explicitly: - -```console -.venv/bin/python tools/fft_profiling/fft_profiling.py --render -.venv/bin/python tools/fft_profiling/fft_profiling.py \ - --render --compare-helicity-sums -``` - -Generation selectors (`--lines`) decide what work enters the campaign. The -render-only `--main-include-lines`, `--main-veto-lines`, -`--ratio-include-lines`, and `--ratio-veto-lines` options only control which -retained series appear in the main and ratio panels. - -## Interpret setup and warmed runtime - -The plotted *setup time* is method-specific: - -- pyAmpliCol includes artifact generation, fresh load, first requested - evaluation, and OTF family construction where applicable; -- Reference FFT includes its build, initialization, and first pass; -- AmpliCol includes its process/colour-object or raw-library preparation for - the selected workload. - -Warmed runtime is measured separately after those setup boundaries. The exact -symmetric-group FFT is not guaranteed to beat direct contraction for every -process: small certified permutation subgroups or large direct residuals can -produce similar scaling. - -Published rolling snapshots: - -- [selected-helicity FullColor FFT PDF](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/summary_plots_final.pdf) -- [complete-helicity-sum FullColor FFT PDF](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/summary_plots_final_helicity_sum.pdf) - -These are measurement-host results rather than release-CI benchmarks. Raw -campaign workspaces remain local. - -## See also - -- [Configuration](configuration.md#color-accuracy-and-lc-layout) — enable exact FFT contraction in a generated artifact. -- [Command-Line Interface](command-line-interface.md#generate) — direct generation example. -- [Performance Reports](../performance_reports/README.md) — published frontiers and measurement boundaries. -- [Installation](installation.md#contributor-installation) — optional profiling references. diff --git a/pyamplicol/docs/user/gentle-walkthrough.md b/pyamplicol/docs/user/gentle-walkthrough.md index a37d422ded..915534e0f0 100644 --- a/pyamplicol/docs/user/gentle-walkthrough.md +++ b/pyamplicol/docs/user/gentle-walkthrough.md @@ -623,9 +623,7 @@ compiled, eager, and OTF are summarized in From here, continue with [Configuration](configuration.md) for all run-card choices, [Models and Processes](models-and-processes.md) for UFO/JSON and multiprocess details, [Runtime and Selectors](runtime-and-selectors.md) for evaluation, and [Native APIs](native-apis.md) for -language integration. To compare many validated process/mode combinations and -turn the measurements into the report, follow the -[profiling-campaign walkthrough](profiling-campaign-walkthrough.md). Every +language integration. Every maintained packaged card and script is indexed in the [examples guide](https://github.com/MadGraphTeam/MadGraph7/blob/main/pyamplicol/examples/README.md). @@ -634,5 +632,4 @@ maintained packaged card and script is indexed in the :hidden: lc-workloads-and-execution-modes -profiling-campaign-walkthrough ``` diff --git a/pyamplicol/docs/user/profiling-and-benchmarking.md b/pyamplicol/docs/user/profiling-and-benchmarking.md index 9d9040a2d5..50552609cf 100644 --- a/pyamplicol/docs/user/profiling-and-benchmarking.md +++ b/pyamplicol/docs/user/profiling-and-benchmarking.md @@ -7,19 +7,8 @@ has_children: true # Profiling and Benchmarking -pyAmpliCol has three intentionally separate performance tools: - -- `pyamplicol profile` measures one generated artifact through the same - optimized total path as `Runtime.evaluate()`; -- a copied [profiling campaign](profiling-campaigns.md) coordinates many model, - process, color, and execution-mode cells and renders comparison PDFs; -- the source-checkout [FullColor FFT profiler](fullcolor-fft-profiling.md) - schedules resumable direct/FFT, reference, AmpliCol, and MadGraph comparison - cells under explicit per-child resource limits. - -Use the direct profiler for a focused runtime question. Use a copied campaign -for a reproducible general matrix. Use the FullColor FFT driver for the -dedicated exact-colour scaling comparison. +`pyamplicol profile` measures one generated artifact through the same +optimized total path as `Runtime.evaluate()`. ## First profile @@ -273,33 +262,14 @@ wall timing rather than the Rusticol f64 breakdown. OTF rejects non-f64 precision altogether. See [Python API](python-api.md) and [Symbolica and Licensing](symbolica-and-licensing.md). -## Reproducible campaign reports - -To create an independent campaign workspace from an installed wheel: - -```console -pyamplicol profiling-campaign copy ./pyamplicol-profiling-campaign --force -cd pyamplicol-profiling-campaign -./steer_performance_campaign.py run \ - --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in -./steer_performance_campaign.py refresh-pdf -``` - -That intentionally small smoke measures only the final-state-multiplicity-one -`d d~ > Z` recurrence cell. Broad campaign matrices belong on dedicated hosts. -See [Profiling Campaigns](profiling-campaigns.md) for continuation, selective -retry, artifact retention, optional original-AmpliCol comparison, and PDF -section controls. +## Published reports -The repository publishes two rendered manual snapshots: +The upstream repository publishes two rendered manual snapshots: - [MacBook M3 report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/macbook_M3_pyAmpliCol.pdf) - [AMD EPYC report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/EPYC_pyAmpliCol.pdf) -They are measurement-host results, not release-CI benchmarks. Raw attempts and -campaign workspaces remain local. +They are measurement-host results, not release-CI benchmarks. ## Comparing results responsibly @@ -318,17 +288,12 @@ campaign workspaces remain local. - [Runtime and Selectors](runtime-and-selectors.md) - [Generation Modes and Evaluators](generation-modes-and-evaluators.md) - [LC workloads and execution modes](lc-workloads-and-execution-modes.md) -- [Profiling Campaigns](profiling-campaigns.md) -- [FullColor FFT Profiling](fullcolor-fft-profiling.md) - [Examples Gallery](examples-gallery.md) ```{toctree} :hidden: -profiling-campaigns -fullcolor-fft-profiling troubleshooting release-and-support -../performance_reports/README ``` diff --git a/pyamplicol/docs/user/profiling-campaign-walkthrough.md b/pyamplicol/docs/user/profiling-campaign-walkthrough.md deleted file mode 100644 index 9c7a9bc995..0000000000 --- a/pyamplicol/docs/user/profiling-campaign-walkthrough.md +++ /dev/null @@ -1,715 +0,0 @@ ---- -title: "Profiling campaign: from measurements to the PDF" -nav_order: 2 -parent: "Get started: a gentle walkthrough" ---- - - -# Profiling campaign: from measurements to the PDF - -The profiling campaign answers a practical physics-computing question: for a -fixed process, multiplicity, colour treatment, and workload, which pyAmpliCol -execution mode is both numerically validated and fastest on *this* machine? -It also records how that result compares with original AmpliCol and, where -appropriate, MadGraph. - -Think of a copied campaign as a self-contained electronic lab notebook. It -contains the catalogue of measurements to make, the report sources, and a -visible `campaign_artifacts/` directory in which every attempt and current -result is recorded, together with bounded diagnostics and any process output -that must be retained. The controller can stop and resume without turning a -long scan into one fragile all-or-nothing job. - -The dashboard and report use a few precise words: - -| Word | Plain-language meaning | -| --- | --- | -| **cell** | One measurement question: one process, multiplicity, model, colour treatment, workload, and execution mode | -| **controller** | The steering script that chooses cells, starts measurements, and records their outcome | -| **worker** | One supervised operating-system process doing one cell at a time; a worker may itself be allowed several CPU cores | -| **dependency** | Another cell whose numerical result is needed to validate the requested cell, such as recurrence or MadGraph | -| **process output** | The generated directory that can later evaluate phase-space points, roughly like a MadGraph standalone-process directory; internal files may call it an `artifact` | -| **current result** | The latest complete record that the next report will use, not a worker that happens to be running now | -| **provenance** | The recorded origin of a number: source revision, settings, machine, phase-space point, and validation link | -| **authenticated record** | A record whose identity and integrity fields the controller has checked; this is a data-integrity term, not a user login | -| **precision lane** | One supported numerical route, such as `p16` (ordinary double precision) or `p200` (about 200 decimal digits); “lane” does not mean another physics approximation | - -A new attempt replaces a cell's current-result pointer only after the complete -record has been written. An interrupted or half-written attempt therefore -cannot silently become the number shown in the PDF. - -The campaign is deliberately broader than the ordinary `pyamplicol profile` -command. `profile` times one process output that you already selected. The -campaign generates many outputs, checks them against independent numerical -references, profiles the accepted results under matched workloads, and fills -the tables in `pyAmpliCol.pdf`. - -## Create an independent campaign workspace - -Start from an installed pyAmpliCol environment and copy the packaged template -into a new or empty directory: - -```console -pyamplicol profiling-campaign copy ./my-profiling-campaign -cd ./my-profiling-campaign -./steer_performance_campaign.py --help -``` - -The copied directory is the unit to archive or move. All measurement state -stays below it; the controller does not consult an old repository-level -`.artifacts` directory. - -Two optional external programs extend the comparisons: - -```console -pyamplicol profiling-campaign copy ./my-full-campaign \ - --local-amplicol /path/to/clean/original-AmpliCol-checkout \ - --local-madgraph /path/to/MG5_aMC -``` - -- Original AmpliCol supplies a legacy numerical diagnostic and the performance - denominator in the “versus AmpliCol” tables. It is not a correctness - authority for pyAmpliCol. The checkout must be clean and complete and expose - the maintained profiling and colour-probe interface from PR #12. -- MadGraph standalone supplies the independent full-colour reference for the - UFO Standard Model comparison views. The path must contain executable - `bin/mg5_aMC` and the standard `models/sm` UFO model. - -The saved paths are defaults for that copy. A later `run --original-amplicol -PATH` or `run --madgraph PATH` overrides one invocation. - -The reset JSON and TeX tables shipped in a fresh copy are **templates**, not -benchmark predictions. Their cells begin unmeasured or `N/A`; they are filled -from results obtained on your machine. In particular, do not expect a reset -copy to contain the example numbers shown later on this page. - -## First preview, then run a small real cell - -Before using substantial CPU time, preview the selected work: - -```console -./steer_performance_campaign.py run \ - --dry-run \ - --table matrix \ - --process-id 1 \ - --multiplicity 1 \ - --color-approximation lc \ - --generation-mode non-union-flow \ - --generation-engine recurrence \ - --model built_in \ - --no-dependencies-added -``` - -The preview separates the cells you requested from any prerequisite or -numerical-reference cells that the controller would add. It also prints the -public pyAmpliCol recipe corresponding to each runnable cell, explicitly -labelling any pre-generation template or report-protocol exception. - -Remove `--dry-run` to perform the deliberately small installation smoke test: - -```console -./steer_performance_campaign.py run \ - --workers 1 \ - --table matrix \ - --process-id 1 \ - --multiplicity 1 \ - --color-approximation lc \ - --generation-mode non-union-flow \ - --generation-engine recurrence \ - --model built_in \ - --no-dependencies-added \ - --no-dashboard -``` - -This measures only the recurrence cell for `d d~ > Z`, at final-state -multiplicity one. It is an installation check, not a representative estimate -of the time needed for a broad high-multiplicity campaign. - -Release wheels omit the optional terminal-dashboard component (implemented -with Ratatui). Their campaigns continue **headlessly**, meaning without the -interactive dashboard, as though `--no-dashboard` had been supplied. A -contributor installation prepared with that optional component can show the -live coloured dashboard. - -## Select the physics question, not individual shell jobs - -The campaign catalogue is a matrix: each axis describes part of the physics or -measurement question, and their allowed combinations define the cells. Useful -selector dimensions include: - -| Selector | What it chooses | Examples | -| --- | --- | --- | -| `--table` | A report surface | `matrix`, `matrix_best`, `z_table`, `reference`, `scalar`, or an exact dataset ID | -| `--process-id` | One of the numbered process families | `1`, or a catalogue key or quoted process | -| `--multiplicity` | Number of final-state particles, `n` | `3 4` | -| `--color-approximation` | Colour treatment | `lc`, `nlc`, `full` | -| `--generation-mode` | Physical workload/layout | `non-union-flow`, `union-flow`, `contracted` | -| `--generation-engine` | Program or execution mode | `amplicol`, `recurrence`, `compiled`, `eager`, `on-the-fly` | -| `--model` | Model preparation used by the cell | `built_in`, `sm_ufo` | -| `--cell-id` / `--cell-id-file` | Exact canonical cells | IDs printed by `inspect` or the summary files | - -Multiple values within one selector are alternatives; different selector -dimensions are combined. For example: - -```console -./steer_performance_campaign.py run \ - --dry-run \ - --table matrix \ - --multiplicity 3 4 \ - --generation-engine recurrence compiled \ - --model built_in sm_ufo -``` - -means “multiplicity 3 **or** 4, recurrence **or** compiled, and built-in -**or** UFO-SM where those catalogue cells exist.” An omitted dimension means -all of its applicable values. Use `--help` to see the exact current choices and -aliases before scripting a large selection. - -The campaign names map to the physical LC calls as follows: - -| Campaign name | Repeated request | Generated layout in recurrence/eager/compiled | -| --- | --- | --- | -| `non-union-flow` | one selected flow, summed over all helicities | `topology-replay` | -| `union-flow` | all flows, one selected helicity | `all-flow-union` | -| `contracted` | the requested axes already summed/contracted | used for NLC and full-colour campaign cells | - -OTF accepts the same two LC requests, but does not write either layout during -generation. Its first selected request constructs the needed family in memory. -This is why “engine” and “generation mode” are separate selectors: the former -chooses *when and how* currents are prepared, while the latter chooses *which -physics workload* is timed. - -By default, the controller also schedules the numerical reference needed to -accept each requested candidate. The dashboard calls such a prerequisite a -dependency. `--no-dependencies-added` suppresses optional independent-reference -cells, but never removes unavoidable model, process, or selector prerequisites. -It is useful for a narrow smoke test; a publication campaign normally keeps -those independent checks. - -### Resource controls - -The safe defaults are one worker, one core per worker, a one-hour -generation/preparation limit, a one-hour whole-worker limit, a decimal 30 GB -RAM cap for each supervised worker process tree, a 64 MiB cap for each watched -attempt-output stream, and a 5 GiB free-disk reserve. The main controls are: - -```text ---workers N ---cores-per-worker N ---amplicol-build-jobs N ---generation-time-limit SECONDS ---worker-wall-limit SECONDS ---ram-limit BYTES ---campaign-ram-limit BYTES ---attempt-output-limit BYTES ---minimum-free-disk BYTES ---target-measurement-duration SECONDS ---minimum-samples N ---warmups N ---batch-size N -``` - -`--cores-per-worker` controls pyAmpliCol generation and runtime construction. -Original AmpliCol compilation has the separate `--amplicol-build-jobs` control, -which defaults to 1 even when pyAmpliCol receives more cores. Keep that serial -default for the maintained legacy checkout: its generator Make target is not -parallel-safe. - -`--ram-limit` is a cap for each worker tree—the worker plus every compiler or -external program it starts. The optional -`--campaign-ram-limit` is an aggregate ceiling: the controller conservatively -divides it by the requested worker count and uses the smaller of that share and -the per-worker cap. For example, ten workers with both limits set to decimal -30 GB receive at most 3 GB each, so they cannot collectively claim ten times -30 GB: - -```console -./steer_performance_campaign.py run \ - --workers 10 --ram-limit 30000000000 \ - --campaign-ram-limit 30000000000 \ - --table matrix --multiplicity 1 2 3 -``` - -The controller measures the worker and all of its descendants as one memory -tree. It guards resident RAM (RSS), and on macOS also checks the operating -system's physical-footprint measure and uses whichever is larger. This RAM -guard does **not** limit bytes written to disk: a runaway external-program log -can fill a volume while the process remains well below its RAM ceiling. -`--attempt-output-limit` therefore stops a worker when any watched attempt log -or output file crosses its per-file limit; the default is 64 MiB (67,108,864 -bytes). `--minimum-free-disk` stops it when free space on the campaign-artifact -volume falls below the reserve; the default is 5 GiB (5,368,709,120 bytes). -Both cases are recorded as explicit errors rather than being mistaken for -physics or timing results. - -Increase parallelism only when the machine has enough RAM for that many -independent worker trees. `--fail-fast` changes validation scheduling into -multiplicity waves and stops after the first final non-success, including a -required mismatch, error, timeout, or supervisor-confirmed resource cap. A -legacy AmpliCol disagreement remains a diagnostic rather than a stopping -condition because original AmpliCol is not a correctness authority. - -## What one campaign cell actually does - -For an ordinary successful cell, the controller: - -1. resolves the catalogue process, model, colour treatment, workload, and - execution mode; -2. prepares reusable model data when needed; -3. generates the process output and records generation time; -4. evaluates a shared deterministic phase-space point; -5. checks the resolved sum and the required cross-mode or MadGraph agreement; -6. profiles the accepted workload in repeated timing chunks; and -7. seals the attempt (marks the record complete and no longer editable) and - makes it the cell's current result in one replacement. - -Independent cells can run in parallel. Dependencies are explicit: for example, -the matching recurrence result checks compiled and eager results, while -MadGraph standalone supplies the independent full-colour reference for UFO-SM -results. For LC OTF cells through `n <= 4`, the matching recurrence cell checks -every resolved helicity/flow component, not only their final sum; no compiled -output is generated merely to perform that check. - -The common deterministic point matters. A timing ratio is published only when -the candidate and denominator are explicitly linked to the same phase-space -point and the required validation has passed. This prevents a visually -plausible ratio from accidentally joining unrelated measurements. - -## Watch, stop, and resume without losing completed work - -In the interactive dashboard, `Ctrl-C` stops the campaign safely. `Esc` first -closes an open command drawer; otherwise it performs the same orderly stop. In -headless mode, use `Ctrl-C`. The controller stops dispatch, terminates each -supervised worker and any child programs with its configured grace period, -preserves completed current results and compact interruption evidence, marks -the campaign as no longer live, writes the summary IDs, and exits with the -conventional interrupted status (code 130). - -There is no supported “hold” or in-memory pause command. To pause a long scan, -stop it orderly and later run the same command again. Compatible successful -results from the same source revision (code version) are reused automatically; -a cell with no compatible successful current is attempted again. If an older -successful current survived the interrupted attempt, the ordinary rerun reuses -that result; add `--force-refresh` only when you intentionally require a fresh -attempt. Historical results from another source revision participate only when -you explicitly pass `--continue-across-revisions`. Use that option only after -checking that the intervening edits cannot change the generated physics, -validation, or measured runtime path—for example, a report-layout-only change. -Each reused result still records its original revision, so the PDF's provenance -remains auditable rather than pretending that every cell came from one commit. -Resume and cross-revision reuse follow the sealed `current.json` and result -records; they do not depend on retaining a compiler or external-program build -workspace. - -With dashboard bindings installed, another terminal can take a read-only -snapshot of the newest live campaign: - -```console -./steer_performance_campaign.py \ - dashboard-snapshot --live --width 160 --height 48 -``` - -This reads a small status record; it cannot pause, resume, or stop the campaign. -Use `--instance ID_OR_PREFIX` when several campaign invocations are active. -Without the optional dashboard bindings, this subcommand explains how to -install them rather than attaching to a wheel-owned headless run. - -### Replay failures or policy caps - -After normal completion or an orderly interrupt, `campaign_summary_ids/` -contains one sorted text file per non-success status. Typical names include -`error.txt`, `blocked_dependency.txt`, `validation_failed.txt`, -`worker_timeout.txt`, `interrupted.txt`, and `unverified.txt`. Replay exact -cells with: - -```console -./steer_performance_campaign.py run \ - --cell-id-file campaign_summary_ids/error.txt \ - campaign_summary_ids/validation_failed.txt \ - --force-refresh -``` - -Replaying a blocked cell includes its required prerequisites. An unverified -timing result is not a successful current; replay `unverified.txt` without -`--force-refresh` once its authority is available. - -Alternatively, keep ordinary table/process selectors and filter them by their -latest state: - -```console -./steer_performance_campaign.py run \ - --table matrix \ - --generation-engine recurrence compiled \ - --rerun-failed --rerun-capped -``` - -`--rerun-failed` selects unsuccessful outcomes that are not authenticated -policy caps. `--rerun-capped` selects resource-policy caps. Together they take -the union. Successful, static, and never-attempted cells are not direct retry -targets. These retry flags cannot be combined with `--force-refresh`; a retry -selection with no matches exits successfully and leaves the existing summary -untouched. - -## What is retained as evidence - -The controller owns `campaign_artifacts/`. Here “artifact” means retained -campaign evidence, not only a generated pyAmpliCol process output. A cell -normally retains a tiny pointer to its current result and one or more uniquely -named attempt directories. Depending on the cell, an attempt can contain: - -- a manifest (an inventory identifying the completed attempt); -- `result.json` and `worker-result.json`; -- a bounded `worker.log`, streamed progress events, and a phase timeline; -- resource measurements and termination diagnostics; and -- when retained, an `artifact/` payload containing the generated process output - or an external-reference workspace used for the measurement. - -Prepared models, reusable model data (“model caches”), live status data, and a -temporary directory used while building the PDF (“publication staging”) also -stay below the campaign directory. Treat their exact subdirectory names as -controller internals; use `inspect`, the summary ID files, and the current -result JSON rather than editing pointers by hand. - -The default is **compact retention**. The controller keeps the result, -provenance, commands, progress and phase records, resource diagnostics, and -bounded final log tails. It keeps a generated pyAmpliCol process output when a -current result still needs it. For original AmpliCol it keeps the small -selected-flow library needed for replay and self-contained structural evidence, -but removes the disposable checkout/build workspace; disposable MadGraph and -other build workspaces are likewise removed after their measurements are -sealed. Heavy payloads from obsolete, failed, or cancelled attempts are also -removed. The old `--cleanup-artifacts` spelling is still accepted, but now -names this default policy rather than enabling a more aggressive one. - -When diagnosing an external generator, opt in to complete workspaces for that -run with: - -```console -./steer_performance_campaign.py run \ - --retain-workspaces \ - --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in \ - --no-dependencies-added --no-dashboard -``` - -`--retain-workspaces` can consume disk quickly and is intended for a bounded -debugging session. It does not disable the attempt-output or minimum-free-disk -guards. Without it, a failed or fail-fast-cancelled attempt still retains the -compact diagnostics needed to understand and replay the cell, but not an -unbounded partial workspace. - -Temporary PDF-building directories and “live” markers are not historical -evidence. They are removed when their operation ends, whether it succeeds or -fails. Do not prune the campaign with broad shell cleanup commands. - -### Reset or branch a campaign safely - -Use another `profiling-campaign copy` for an independent machine, compiler, or -experimental branch. To reset one existing destination intentionally: - -```console -pyamplicol profiling-campaign copy ./my-profiling-campaign --force -``` - -Stop its active controller first. `--force` overwrites the managed template -files and resets only that destination's `campaign_artifacts/`, generated PDF, -summary-ID directory, measurement lineage, and known LaTeX byproducts. It -preserves unrelated files. It also preserves saved AmpliCol and MadGraph paths -unless new `--local-amplicol` or `--local-madgraph` values are supplied. - -This narrow reset is the supported replacement for manually deleting a broad -temporary directory or guessing which attempt files are safe to remove. - -## Turn current results into the report - -When the desired cells have finished, publish one internally consistent report -snapshot: - -```console -./steer_performance_campaign.py refresh-pdf -``` - -The controller first takes a stable snapshot—a read-only list of the complete -current results that belong in this version of the report. It verifies their -recorded origin and validation links, shows coloured progress, renders the JSON -and table TeX in a fresh temporary directory, and runs LaTeX there. Only after -all of that succeeds does it replace the published files and `pyAmpliCol.pdf` -as one unit. A failed render therefore leaves the previous PDF in place. - -Unresolved LaTeX references and compilation errors are fatal. Overfull boxes -are reported by interactive `refresh-pdf` so they can be reviewed. The final -maintainer audit is stricter: it authenticates the current results and physics -links, rebuilds the PDF, extracts its text, renders every page to an image, and -compares both text and pixels. Thus `refresh-pdf` is the normal campaign-owner -command; the release audit is the publication boundary rather than a second -measurement campaign. - -Useful report-only controls are: - -```console -./steer_performance_campaign.py refresh-pdf --list-sections -./steer_performance_campaign.py refresh-pdf \ - --remove-sections worked-zgg shared-current-dag -./steer_performance_campaign.py refresh-pdf --quiet -``` - -Removing sections affects only that staged PDF. It does not remove source, -measurements, result JSON, or table TeX; the next plain `refresh-pdf` restores -the complete report. - -## Find the matrices and their evidence - -Open `pyAmpliCol.pdf` and go to **Standard-Model Process Matrices**. The -“best measured mode versus AmpliCol” tables provide the compact overview. For -each process, multiplicity, and LC workload, the renderer independently chooses -the validated pyAmpliCol mode with the smallest measured wall time. It does not -declare one universally best mode. - -The generated TeX files beside the PDF are useful when a cell is too dense on -screen. For example, the LC overview is -`result_matrix_best_builtin_sm_lc_table.tex`. The corresponding detailed raw -tables are rendered from JSON caches below `results/`, such as -`matrix_compiled_builtin_sm_lc.json` and `reference_amplicol_lc.json`. - -For a human-readable view of current coverage and status, including OTF, use: - -```console -./steer_performance_campaign.py inspect \ - --color-approximation lc \ - --generation-engine recurrence compiled eager on-the-fly -``` - -Add `--json` for stable, uncoloured output suitable for scripts. Exact -cell IDs in `inspect`, the current JSON, and `campaign_summary_ids/` connect a -compact table status back to its retained attempt evidence. The PDF does not -turn every timing into a clickable evidence link; the result record stores the -source/settings (“provenance”), shared point, and validation-reference link. - -### Wall, evaluator, and recurrence clocks - -The report keeps several clocks separate instead of renaming whichever number -is available: - -- **Runtime** is the broad physics task of evaluating already generated output - at phase-space points. The **evaluator** is the loaded numerical calculator - that performs it. -- **Wall time** is elapsed real time observed around the complete timed call. - It is available across implementations and is therefore the primary number - used to choose the fastest validated mode. -- **Evaluator total** is a separately recorded accumulated clock inside the - complete warmed evaluator. Comparing it with wall time helps reveal time - spent in wrappers or in choosing and calling the numerical routine; it is - not copied from wall time. -- **Recurrence core** is the still narrower time spent replaying recurrence - schedules. It is useful for diagnosing recurrence itself, but it is not a - complete evaluator clock and is never relabelled or used as another mode's - denominator. - -The muted bracketed `xS` in a Best-vs-AmpliCol runtime cell first compares -compatible internal clocks that each implementation explicitly assigns to -numerical execution, excluding its documented surrounding work. If those are -unavailable, the table may use its explicitly documented evaluator-total -versus legacy-direct fallback. Either way `xS` is diagnostic. The coloured -outer `xW` is always the wall-time ratio and remains the performance -conclusion. - -`JIT` in row labels means “just-in-time”: numerical machine code is prepared -automatically for the current environment. `O2` and `O3` name compiler -optimization levels; they do not denote perturbative orders. - -### The Z-gluon ladder also includes OTF - -The built-in-SM and UFO-SM Z tables follow - -```text -d d~ -> Z + (n-1)g -``` - -through increasing final-state multiplicity. For each `n`, their setup rows now -include compiled variants, eager, recurrence, **and on-the-fly JIT O2**, beside -the original-AmpliCol reference. The two column groups remain the same physical -workloads used throughout the report: selected flow with a helicity sum, and -all flows at one helicity. - -An OTF generation cell in these detailed Z tables is printed as: - -```text -[G] G+W -``` - -Both numbers are absolute seconds. `G` is generation of the compact process -recipe; `G+W` adds the first cold evaluation of the complete campaign batch for -that workload. The muted brackets separate generation alone without hiding the -construction cost moved to first use. This `W` is not the public -single-point `Runtime.warm_up(...)` call: the campaign deliberately measures -its complete profiling batch. The adjacent `wall` column is the ordinary warm -wall time per point. The `eval` column is shown only when the mode supplied a -separately authenticated warmed evaluator-total clock; `not exposed` does not -mean that wall timing failed. - -## Read one real “Best vs AmpliCol” cell - -The following is the process-ID 1, `n = 2` cell from the current authoritative -campaign rendered for this release. It is a worked notation example, **not** a -performance promise for another machine, compiler, source revision, or model -preparation: - -```text -d d~ -> Z + (n-1)g = d d~ -> Z g -``` - -The LC table contains two aligned workloads in the fixed order -**selected flow, helicity sum | all flows, one helicity**: - -| Table row | Original AmpliCol | Best validated pyAmpliCol mode | -| --- | --- | --- | -| generation `[s]` | `3.66 | 0.000217` | `(o) ([x1.52] x1.52) | [5.57] 5.57 (o)` | -| runtime `[microseconds/point]` | `0.209 | 0.172` | `([x2.46] x2.51) | ([x0.888] x1.04)` | - -Here is every visible entry: - -- `3.66` seconds is original AmpliCol's selected-flow process-library - generation time. -- `0.000217` seconds is original AmpliCol's direct all-flow setup time. This is - a different setup boundary from pyAmpliCol process generation. -- `(o)` says that **on-the-fly JIT O2** had the smallest validated wall time - for that workload. The code is a label, not a ratio. The four possible codes - are `(r)`, `(c)`, `(e)`, and `(o)` for recurrence JIT O2, compiled JIT O3, - eager-DAG JIT O2, and on-the-fly JIT O2. -- In `([x1.52] x1.52)`, the muted bracketed multiplier uses compact OTF - process-output generation `G` alone. The coloured outer multiplier uses - `G+W`, where `W` is construction and first evaluation of the selected family - on the complete campaign batch. Both are divided by the matching 3.66 s - AmpliCol library-generation time. They round to the same value here because - the stored `G` was about 5.565 s and `W` about 0.00362 s. -- `[5.57] 5.57 (o)` is the all-flow OTF generation pair in absolute seconds: - muted `[G]` followed by `G+W`. It is intentionally not divided by - `0.000217`, because AmpliCol direct setup and pyAmpliCol process generation - are different operations. -- `0.209 | 0.172` are original AmpliCol wall times in microseconds per point - for the selected-flow and all-flow workloads, respectively. -- In `([x2.46] x2.51)`, the muted bracketed value compares the OTF - execution-attribution clock with AmpliCol's compatible direct-execution - clock. The coloured outer value independently compares wall time: about - 0.526 microseconds per point divided by 0.209. The outer ratio is the primary - figure used to choose a winner; generation time is not. -- Likewise, `([x0.888] x1.04)` contains the supplementary execution ratio and - the primary wall ratio for all flows at one helicity. The OTF wall time was - about 0.178 microseconds per point, versus about 0.172 for AmpliCol. - -Muted supplementary ratios help diagnose where time is spent, but they never -replace the outer wall ratio. In OTF generation notation, `W` excludes process -output loading and the conventional benchmark warm-up calls. It is also not -the public `Runtime.warm_up(...)` contract, which accepts exactly one -double-precision point for one selected family; the campaign times the first -complete batch required by its profiling protocol. - -## Colours, `N/A`, caps, and failures - -For a candidate/baseline multiplier `x`: - -- green means `x < 1`: the candidate was faster; -- orange means `1 <= x < 2`; -- red means `x >= 2`. - -The colours describe timing ratios, not physics accuracy. Accuracy is a -separate acceptance gate. An orange resource-cap token such as `>5h` or -`>40GB` means a configured policy boundary was reached; a red failure or -validation token means the measurement was not accepted. Muted `N/A` denotes -an unavailable entry, while `not applicable` means the process family itself -is not defined at that multiplicity. `not run` means it exists but was outside -the measured scope. `static N/A` marks a catalogue limitation known without -launching a worker, such as an original-AmpliCol surface outside its supported -open-quark-line scope. - -A compact token such as `N out.[5d35ae]` is a shortened final status, not a -number or speed ratio. Use `inspect` or the relevant file under -`campaign_summary_ids/` to recover the exact cell ID and outcome. `not exposed` -has a different meaning: the wall measurement succeeded, but that mode did not -provide the separately recorded internal clock requested by the detailed -table. It is not a missing or failed wall measurement. - -Unverified, capped, unsupported, and validation-failed candidates do not enter -“best” selection or performance summaries. A successful but unlinked candidate -can still be selected by its absolute wall time; it is displayed absolutely and -is excluded from timing ratios, mode-mix counts, and ratio summaries. - -## Read the summary rows - -Below each multiplicity block, the **mode mix** counts selected-flow wall-time -winners that also have the valid AmpliCol link needed for the generation -summary. The current authoritative `n = 2` LC block shows: - -```text -r:0 | c:2 | e:0 | o:4 -``` - -Among the six eligible process families, no winner was recurrence, two were -compiled, none was eager, and four were OTF. A zero is meaningful—it says that -the mode was measured but did not win this particular group. The order is -always `r | c | e | o`; it matches the four mode labels in the cells. - -Every five-number summary is ordered as: - -```text -minimum | maximum | median | arithmetic mean | weighted mean -``` - -The weighted mean is framed in the PDF. It is the ratio of summed candidate -time to summed baseline time, not the average of the individual ratios: - -```text -weighted mean = sum(candidate times) / sum(baseline times) -``` - -For `n = 2`, the same rendered campaign snapshot displays: - -| Summary row | `min | max | median | mean | weighted` | -| --- | --- | -| generation, selected-flow workload | `x0.801 | x1.52 | x1.34 | x1.24 | x1.23` | -| runtime, selected flow and helicity sum | `x2.00 | x4.12 | x2.46 | x2.89 | x2.65` | -| runtime, all flows and one helicity | `x0.754 | x1.43 | x1.00 | x1.05 | x1.05` | - -The generation summary uses only the comparable selected-flow **primary** -generation ratios; for an OTF winner this is `G+W`, not the muted `G`-only -ratio. Absolute all-flow generation is omitted. Runtime summaries use only the -primary wall ratios, not the muted supplementary ratios, and keep the two LC -workloads on separate lines. Structurally inapplicable, resource-limited, -unsupported, unverified, unlinked, and validation-failed cells are excluded. -This Best-vs summary follows the selected winner's primary token; a fixed-engine -OTF table instead keeps its generation summary as the diagnostic `G`-only -quantity while displaying both `G` and `G+W` in each row. - -The minimum answers “what was the best individual ratio?”, the maximum the -worst, the median the middle process, and the arithmetic mean treats every -included process equally. The framed weighted mean gives processes with larger -baseline times more influence, because it asks what would happen if the -included candidate times and baseline times were each added together. - -## A campaign-owner checklist - -1. Copy a fresh workspace for each machine or measurement environment. -2. Record external AmpliCol or MadGraph paths only when those comparisons are - required. -3. Preview a narrow selector with `run --dry-run`. -4. Confirm worker count, per-worker cores, wall-time limit, per-worker RAM cap, - any aggregate campaign RAM cap, attempt-output cap, and free-disk reserve - before broadening the scan. -5. Stop with `Ctrl-C` or dashboard `Esc`; resume by repeating the command. -6. Use `inspect` and `campaign_summary_ids/` to understand non-successes before - forcing a refresh. -7. Use compact retention by default. Add `--retain-workspaces` only for a - deliberate, disk-bounded debugging run. -8. Run `refresh-pdf` only after the desired current cells are in place. -9. Read ratios together with workload, mode code, validation status, and the - machine/source identity; no timing number is universal. - -For the exact controller contract and all current options, see the packaged -[campaign template README](https://github.com/MadGraphTeam/MadGraph7/blob/main/pyamplicol/src/pyamplicol/_profiling_campaign/README.md) -and [table-filling reference](https://github.com/MadGraphTeam/MadGraph7/blob/main/pyamplicol/src/pyamplicol/_profiling_campaign/TABLE_FILLING.md). -For the physical difference between the two LC workloads and the four -pyAmpliCol execution modes, continue with -[LC workloads and execution modes](lc-workloads-and-execution-modes.md). The -ordinary one-output timing workflow remains documented in -[Profiling and Benchmarking](profiling-and-benchmarking.md#what-is-timed). diff --git a/pyamplicol/docs/user/profiling-campaigns.md b/pyamplicol/docs/user/profiling-campaigns.md deleted file mode 100644 index 6cdd69e5af..0000000000 --- a/pyamplicol/docs/user/profiling-campaigns.md +++ /dev/null @@ -1,367 +0,0 @@ ---- -title: "Profiling Campaigns" -nav_order: 1 -parent: "Profiling and Benchmarking" ---- - -# Profiling Campaigns - -The profiling-campaign command creates a complete, movable measurement -workspace from an installed pyAmpliCol wheel. It is intended for controlled -generation/runtime comparisons and for reproducing the report format used by -the published MacBook M3 and AMD EPYC PDFs. - -For a physicist-oriented end-to-end explanation of steering, interruption, -retained evidence, PDF rendering, and every entry in a concrete “Best vs -AmpliCol” matrix cell, follow -[Profiling campaign: from measurements to the PDF](profiling-campaign-walkthrough.md). - -> A campaign can create very large artifacts and long-running workers. Start -> with the single-cell smoke below. Broader multiplicities belong on a -> dedicated measurement host. - -## Create a fresh campaign - -```console -pyamplicol profiling-campaign copy ./pyamplicol-profiling-campaign --force -cd ./pyamplicol-profiling-campaign -./steer_performance_campaign.py --help -``` - -The copy is self-contained apart from the installed pyAmpliCol runtime. It -contains the controller, report sources, blank/reset data, generated-table -templates, and one visible state root: - -```text -pyamplicol-profiling-campaign/ - steer_performance_campaign.py - README.md - TABLE_FILLING.md - report-workspace.json - campaign_artifacts/ - cells/ - coordination/ - manual-reproductions/ - report-snapshot-builds/ - results/ - result_*.tex - pyAmpliCol.tex -``` - -All attempts, prepared artifacts, current pointers, logs, locks, leases, and -reproduction state live below `campaign_artifacts/`. The controller does not -consult an old checkout-level `.artifacts` directory. - -## A deliberately small real run - -This command measures only the final-state-multiplicity-one `d d~ > Z` -recurrence cell: - -```console -./steer_performance_campaign.py run \ - --workers 1 \ - --table matrix \ - --process-id 1 \ - --multiplicity 1 \ - --color-approximation lc \ - --generation-mode non-union-flow \ - --generation-engine recurrence \ - --model built_in -``` - -It is the recommended installed-wheel campaign smoke. Release wheels omit the -optional Ratatui bindings, so the controller continues headlessly. A -contributor checkout prepared with `just dev-install` can show the interactive -dashboard. - -Preview a broader selection without launching workers: - -```console -./steer_performance_campaign.py run \ - --dry-run \ - --table z_table \ - --multiplicity 3 4 \ - --model built_in sm_ufo -``` - -The dry run separates directly selected cells from dependency work and prints -a public-CLI reproduction recipe for each runnable cell. - -## Selection and numerical-authority closure - -The campaign catalog has stable canonical cell IDs. Ordinary selectors choose -direct work by table, process family, multiplicity, color approximation, -generation mode, engine, model, and variant. - -By default, the controller recursively adds each selected cell's available -active-source numerical-authority chain: - -```text -original AmpliCol → recurrence → compiled / eager -``` - -Added cells are dependency-only work. Independent process/multiplicity cohorts -remain parallel. Hard construction and selector/provider dependencies always -block until available. A terminal optional authority releases its candidate: -the candidate can still run, but a compiled/eager result without independent -authority is retained as an explicit unverified timing diagnostic rather than -published as a successful current. - -Use `--no-dependencies-added` only when you intentionally want to suppress -this optional numerical-authority expansion. It never removes hard -dependencies. - -## Original AmpliCol is optional - -All pyAmpliCol backends work without an original-AmpliCol checkout. The legacy -backend is enabled only when selected as a reference. - -The supported input is a **clean, complete checkout** exposing the profiling -probe sources and Make targets from -[rikkert-frederix/AmpliCol PR #12](https://github.com/rikkert-frederix/AmpliCol/pull/12). -It is not a single Fortran file and is not bundled in pyAmpliCol. - -Record a destination-local default while copying: - -```console -pyamplicol profiling-campaign copy ./campaign \ - --local-amplicol /path/to/clean/complete/AmpliCol-checkout -``` - -Or provide/override it for one run: - -```console -./campaign/steer_performance_campaign.py run \ - --original-amplicol /path/to/clean/complete/AmpliCol-checkout \ - --generation-engine amplicol recurrence \ - --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --model built_in -``` - -The copy stores the chosen path in `.pyamplicol-original-amplicol`. A later -`--force` reset preserves that pointer unless `--local-amplicol` explicitly -replaces it. Without a configured checkout, a selection that does not include -`amplicol` remains fully supported. - -## Reuse and source revisions - -Successful compatible currents are reused by default. The campaign's stored -attempts are not erased merely because pyAmpliCol's source revision changes. - -Without `--continue-across-revisions`, planning and report operations use the -active source cohort. With it, valid historical currents may remain in the -campaign while new cells and dependencies are measured at the active revision: - -```console -./steer_performance_campaign.py run \ - --continue-across-revisions \ - --workers 4 \ - --table matrix \ - --multiplicity 4 5 \ - --generation-engine recurrence compiled eager \ - --model built_in -``` - -This option reconciles compatible prior results; it does not reconstruct a -deleted campaign. Historical numerical authorities needed by current-revision -work are replanned at the active revision rather than silently reused across an -unsafe authority boundary. - -The operations that actually reset managed state are -`pyamplicol profiling-campaign copy DEST --force` and deliberate manual -deletion. Stop every active controller before using `--force`. - -## Move or rename a campaign - -Move the complete directory, not selected result files: - -```console -mv ./campaign-mac ./archive/macbook-M3-2026 -cd ./archive/macbook-M3-2026 -./steer_performance_campaign.py inspect -``` - -Portable current locators are interpreted relative to the campaign's new -`campaign_artifacts/` root. Two campaign directories with the same basename in -different parents do not share state. - -If a directory was renamed while a shell remained inside its old inode, start -a new shell or `cd` through the new absolute path before launching the copied -controller. The launcher checks logical and physical working directories and -fails instead of reading an unintended campaign. - -## Dashboard and progress - -Contributor environments with Ratatui bindings display active worker lanes, -direct/dependency work, completed/capped/error/unverified partitions, elapsed -time, and compact terminal reasons. - -Capture a read-only view from another terminal: - -```console -./steer_performance_campaign.py dashboard-snapshot --live \ - --width 160 --height 48 -``` - -The live snapshot reads only compact coordination leases. Use -`--instance ID_OR_PREFIX` when more than one controller is active. Omit -`--live` for the deterministic layout fixture. - -`Ctrl-C` or `Esc` stops dispatch, terminates supervised process trees, -preserves completed currents, writes the summary-ID files, and restores the -terminal. - -## Retry exactly what needs attention - -Every completed or orderly interrupted run replaces -`campaign_summary_ids/` with one sorted text file per non-success status, for -example: - -```text -campaign_summary_ids/ - blocked_dependency.txt - error.txt - unverified.txt - validation_failed.txt - worker_timeout.txt -``` - -Replay exact IDs: - -```console -./steer_performance_campaign.py run \ - --cell-id-file campaign_summary_ids/error.txt \ - campaign_summary_ids/validation_failed.txt \ - --force-refresh -``` - -Or filter an ordinary selection by structured state: - -```console -./steer_performance_campaign.py run \ - --table z_table \ - --generation-engine recurrence compiled \ - --rerun-failed --rerun-capped \ - --continue-across-revisions -``` - -- `--rerun-failed` selects latest terminal non-successes that are not - authenticated policy caps; unverified diagnostics are retryable here. -- `--rerun-capped` selects authenticated memory/time/generation policy caps. -- Combining them takes the union. -- Successful, structural-static, and never-attempted cells are not direct - retry targets. -- Normal hard and optional dependency closure still applies. -- The selective flags conflict with `--force-refresh`. -- No matches is a successful no-op and preserves the previous summary IDs. - -Replaying `blocked_dependency.txt` includes its prerequisites automatically. -An `unverified.txt` replay does not require `--force-refresh`: unverified is -not an authoritative successful current. - -## Attempt retention and cleanup - -Compact retention is the default. It keeps sealed results and current pointers, -provenance, commands, progress/timeline evidence, bounded log tails, and outputs -needed by currents or dependencies. Disposable copied AmpliCol, MadGraph, and -build workspaces are removed after publication. Cross-revision reuse reads the -sealed results rather than those workspaces. - -Pass `--retain-workspaces` only for a bounded debugging run that needs the full -workspaces: - -```console -./steer_performance_campaign.py run \ - --retain-workspaces \ - --table matrix --process-id 1 --multiplicity 1 \ - --generation-engine recurrence --model built_in -``` - -`--cleanup-artifacts` remains accepted as a compatibility spelling for the -default compact policy. Independently, `--attempt-output-limit` defaults to -67,108,864 bytes (64 MiB) per watched output/log file and -`--minimum-free-disk` reserves 5,368,709,120 bytes (5 GiB) on the artifact -volume. These storage guards complement, but do not replace, process-tree RAM -supervision. - -## Inspect and render - -Inspect coverage and AmpliCol-relative comparisons: - -```console -./steer_performance_campaign.py inspect \ - --color-approximation lc \ - --generation-engine recurrence compiled -``` - -Refresh all tables and atomically replace the PDF from one coherent current -snapshot: - -```console -./steer_performance_campaign.py refresh-pdf -``` - -Interactive refresh displays a colored progress bar while current records are -read and checked. It does not rescan every historical heavy artifact. - -List stable section IDs or omit sections from one PDF build: - -```console -./steer_performance_campaign.py refresh-pdf --list-sections -./steer_performance_campaign.py refresh-pdf \ - --remove-sections worked-zgg shared-current-dag -``` - -Section omission changes only the staged PDF. Measurements, JSON caches, table -TeX, and source remain; the next plain refresh restores the complete report. -`--quiet` suppresses scan progress and live LaTeX output. - -The repository retains only two rendered report snapshots: - -- [MacBook M3 report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/macbook_M3_pyAmpliCol.pdf) -- [AMD EPYC report](https://github.com/MadGraphTeam/pyamplicol/blob/main/docs/performance_reports/EPYC_pyAmpliCol.pdf) - -Raw campaign results are intentionally not published in the repository. A -fresh copied campaign contains everything needed to reproduce the report -format directly. - -## What `--force` resets - -```console -pyamplicol profiling-campaign copy DEST --force -``` - -replaces only managed template files and resets: - -- `DEST/campaign_artifacts/`; -- the managed `pyAmpliCol.pdf`; -- `campaign_summary_ids/`; -- measurement lineage; -- known pyAmpliCol LaTeX build byproducts. - -It preserves unrelated destination files, a legacy `DEST/.artifacts` -directory (which is ignored), and the recorded original-AmpliCol pointer unless -explicitly replaced. An active campaign makes reset fail without removing -state. - -## Recommended operating habits - -1. Use one copied directory per host and campaign policy. -2. Run `--dry-run` before a broad selection. -3. Set worker and RAM limits for the actual host. -4. Use `--continue-across-revisions` when intentionally extending a campaign - across source updates. -5. Prefer selective retry flags over a broad force refresh. -6. Keep compact attempts by default; use `--retain-workspaces` only for a - bounded debugging run. -7. Never commit `campaign_artifacts/`, raw results, logs, locks, attempts, or - LaTeX auxiliary files. - -## Related pages - -- [Examples Gallery](examples-gallery.md) — ordinary generation/runtime examples. -- [Profiling campaign walkthrough](profiling-campaign-walkthrough.md) — the campaign idea, retained evidence, PDF lifecycle, and matrix interpretation. -- [Artifacts and Portability](artifacts-and-portability.md) — process-artifact portability and trust. -- [Troubleshooting](troubleshooting.md) — campaign state, source revision, and dashboard issues. -- [Packaged campaign guide](https://github.com/MadGraphTeam/pyamplicol/blob/main/src/pyamplicol/_profiling_campaign/TABLE_FILLING.md). -- [Published report index](../performance_reports/README.md). diff --git a/pyamplicol/docs/user/quick-start.md b/pyamplicol/docs/user/quick-start.md index 4ffa5afc56..f0f5dc85a2 100644 --- a/pyamplicol/docs/user/quick-start.md +++ b/pyamplicol/docs/user/quick-start.md @@ -210,4 +210,3 @@ SDK discovery. - [Configuration](configuration.md) — adapt a TOML card or use direct CLI overrides. - [Models and Processes](models-and-processes.md) — load your own JSON/UFO model. - [Artifacts and Portability](artifacts-and-portability.md) — understand schema-v3 artifacts, portable compiled JIT O1/O2, and prepared O2 packs. -- [Profiling Campaigns](profiling-campaigns.md) — run reproducible multi-process measurements. diff --git a/pyamplicol/docs/user/release-and-support.md b/pyamplicol/docs/user/release-and-support.md index 5e419d31d2..89d59d3b7b 100644 --- a/pyamplicol/docs/user/release-and-support.md +++ b/pyamplicol/docs/user/release-and-support.md @@ -88,8 +88,7 @@ Version `0.2.0` adds exact symmetric-group FFT full-colour contraction, helicity-parametric recurrence and on-the-fly scheduling, built-in SM+HEFT and trusted UFO HEFT support, and the resumable fixed-helicity/helicity-sum FFT profiling workflow with its final comparison reports. -See the runnable [scalar HEFT workflow](models-and-processes.md#built-in-scalar-heft-model) -and the [FullColor FFT profiling guide](fullcolor-fft-profiling.md). +See the runnable [scalar HEFT workflow](models-and-processes.md#built-in-scalar-heft-model). ## 0.1.4 release @@ -135,7 +134,7 @@ The release set consists of: - one source distribution; - supported-platform `cp311-abi3` wheels; - the Python extension and target-specific static Rusticol SDK in each wheel; -- packaged model resources, examples, profiling-campaign templates, and user +- packaged model resources, examples, and user documentation required by installed workflows. Source installation may work elsewhere, but a platform is not advertised as @@ -190,8 +189,7 @@ hand. - Source contributor builds and release builds have separate dependency boundaries. Contributor candidate wheels are deliberately non-publishable. -See [Symbolica and Licensing](symbolica-and-licensing.md), -[Profiling Campaigns](profiling-campaigns.md), and +See [Symbolica and Licensing](symbolica-and-licensing.md) and [Artifacts and Portability](artifacts-and-portability.md). ## Report a problem diff --git a/pyamplicol/docs/user/runtime-and-selectors.md b/pyamplicol/docs/user/runtime-and-selectors.md index 03a0fffec6..c4c39383af 100644 --- a/pyamplicol/docs/user/runtime-and-selectors.md +++ b/pyamplicol/docs/user/runtime-and-selectors.md @@ -683,9 +683,6 @@ evaluator call. Native component rows describe a separate profiled pass and must not be subtracted from that headline as though they were measured in one identical call. `pyamplicol benchmark` is a compatibility alias for `profile`. -For controlled, multi-process comparisons and report generation, use -[Profiling Campaigns](profiling-campaigns.md) instead. - ## Handle ownership and warnings Parameter and warning state belongs to one runtime handle. Do not invoke the diff --git a/pyamplicol/docs/user/symbolica-and-licensing.md b/pyamplicol/docs/user/symbolica-and-licensing.md index 7b70a189c9..25aea1da93 100644 --- a/pyamplicol/docs/user/symbolica-and-licensing.md +++ b/pyamplicol/docs/user/symbolica-and-licensing.md @@ -285,7 +285,7 @@ Exact dependency versions and notices are included in release metadata and ## Original AmpliCol is not a pyAmpliCol runtime dependency The optional original Fortran AmpliCol checkout is used only as an independent -numerical/performance reference in [Profiling Campaigns](profiling-campaigns.md). It is not shipped +numerical reference for developer validation. It is not shipped in pyAmpliCol wheels or source distributions and is unnecessary for ordinary generation or evaluation. diff --git a/pyamplicol/docs/user/troubleshooting.md b/pyamplicol/docs/user/troubleshooting.md index 8d624f24fb..9e4ebdab7b 100644 --- a/pyamplicol/docs/user/troubleshooting.md +++ b/pyamplicol/docs/user/troubleshooting.md @@ -7,7 +7,7 @@ parent: "Profiling and Benchmarking" # Troubleshooting This page starts with cheap, authoritative checks and then narrows common -generation, runtime, native-SDK, and profiling-campaign failures. Avoid broad +generation, runtime, and native-SDK failures. Avoid broad rebuilds until the failing boundary is known. ## First checks @@ -305,78 +305,6 @@ Python precision other than 16 also loads retained Symbolica state. Native languages are f64-only and never perform a Symbolica license check. See [Symbolica and Licensing](symbolica-and-licensing.md). -## A profiling campaign seems to have lost earlier results - -Running without `--continue-across-revisions` does **not** delete old attempts. -It limits active planning to the current source cohort. To extend a campaign -across source changes: - -```console -./steer_performance_campaign.py run \ - --continue-across-revisions \ - ...ordinary selectors... -``` - -Compatible historical currents can then remain while new work uses the active -revision. Numerical authorities required by new current-revision work are -replanned safely. - -The command that resets state is: - -```console -pyamplicol profiling-campaign copy DEST --force -``` - -It resets only managed state below that destination, and refuses while a -campaign is active. See [Profiling Campaigns](profiling-campaigns.md). - -## The campaign reads the wrong directory after a rename - -All state is local to `DEST/campaign_artifacts/`. If a directory was renamed -while the shell remained inside the old inode, the prompt may show a logical -name that no longer matches the physical directory. - -```console -pwd -pwd -P -``` - -Start a new shell or `cd` through the campaign's current absolute path. Current -launchers reject a stale logical/physical mismatch before opening state. - -Move the whole campaign directory; do not copy individual currents or -coordination files. - -## A campaign reports `unverified` - -`unverified` is intentional for a compiled/eager timing measured without an -independent successful recurrence or original-AmpliCol authority. It is not an -OK current, is excluded from best-mode ratios/summaries, and is automatically -retryable after authority becomes available. - -By default, ordinary selection adds the available authority closure. If you -used `--no-dependencies-added`, rerun without it, or explicitly select the -authority and candidate. Replay exact IDs from: - -```console -./steer_performance_campaign.py run \ - --cell-id-file campaign_summary_ids/unverified.txt -``` - -## A campaign is slow to render its PDF - -`refresh-pdf` scans compact current records and displays a colored progress -bar. It does not need to hash or load every retained heavy attempt. - -```console -./steer_performance_campaign.py refresh-pdf -``` - -Use `--quiet` only when progress and LaTeX output should be suppressed. If the -scan is unexpectedly dominated by old payloads, confirm you are using the -current copied controller and that state is below `campaign_artifacts/`, not a -legacy campaign layout. - ## Memory use while loading a large JIT artifact PACBIN-backed runtimes snapshot the container into anonymous read-only memory. @@ -404,7 +332,6 @@ Also include: - host OS/architecture and Python version; - execution mode, backend, color accuracy, and target; - the complete error, not only its final status code; -- for a campaign, the canonical cell ID and compact worker log/result path; - whether the artifact is reproducible from a public example. Do **not** upload proprietary UFO code, license keys, or an untrusted native diff --git a/pyamplicol/docs/user/umami-api.md b/pyamplicol/docs/user/umami-api.md index bd9297ac3e..1b6811c32a 100644 --- a/pyamplicol/docs/user/umami-api.md +++ b/pyamplicol/docs/user/umami-api.md @@ -300,24 +300,9 @@ flavour classes, the recorded relations and their warnings. ## MadSpace example -The repository's +The upstream pyAmpliCol repository's [`umami_example`](https://github.com/MadGraphTeam/pyamplicol/tree/umami/umami_example) contains close adaptations of AmpliCol's loading and integration examples. They use the real MadSpace matrix-element loader, phase-space mappings and -differential cross section, with VEGAS from MadNIS. The default is a bounded -partonic `g g > g g g` run for LC and full colour, with no PDF downloads: - -```console -python -m pip install -r umami_example/requirements.txt -python umami_example/run.py -``` - -The orchestrator generates both artifacts, compiles the libraries and linked -drivers, checks batched UMAMI/native numerical agreement, and writes integrated -cross sections with statistical uncertainties. It disables numerical -current-relation discovery during generation. Optional PDF and neural-flow -workflows, provider selection, cuts and all commands are explained in the -example README. Those dependencies are not part of pyAmpliCol's core install. -The integration example uses MadSpace's massless two-beam scattering flux and -rejects massive incoming legs; this is a limitation of that example, not of the -UMAMI provider. +differential cross section, with VEGAS from MadNIS. Setup, options and all +commands are explained in its README. diff --git a/pyamplicol/flake.lock b/pyamplicol/flake.lock deleted file mode 100644 index 33a5783d09..0000000000 --- a/pyamplicol/flake.lock +++ /dev/null @@ -1,48 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1784120854, - "narHash": "sha256-KesHgItiZPgGX740axSiQLcIQ8D24MDqNpkKYWIek8k=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "753cc8a3a87467296ddd1fa93f0cc3e81120ee46", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1784216271, - "narHash": "sha256-bvaxxdk7mmMQ88AuXQGTUtk+PcUujHpgxqpryqTWvTU=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "1f69c7203034a4a974d7a4eac0f19b54af30804d", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/pyamplicol/flake.nix b/pyamplicol/flake.nix deleted file mode 100644 index 48494f0259..0000000000 --- a/pyamplicol/flake.nix +++ /dev/null @@ -1,134 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -{ - description = "pyAmpliCol contributor development environment"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = - { nixpkgs, rust-overlay, ... }: - let - systems = [ - "aarch64-darwin" - "aarch64-linux" - "x86_64-linux" - ]; - forAllSystems = nixpkgs.lib.genAttrs systems; - in - { - devShells = forAllSystems ( - system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ (import rust-overlay) ]; - }; - inherit (pkgs) lib stdenv; - - rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - - # Keep the generic PEP 517 frontend for `just wheel`. Project, test, - # and candidate packages belong to the lock-controlled contributor venv. - python = pkgs.python311.withPackages ( - pythonPackages: with pythonPackages; [ - build - pip - setuptools - wheel - ] - ); - - nativeLibraries = with pkgs; [ - gmp - libffi - libmpc - mpfr - openssl - stdenv.cc.cc.lib - zlib - ]; - - platformTools = - lib.optionals stdenv.isLinux [ - pkgs.binutils - pkgs.lsof - pkgs.patchelf - pkgs.procps - ] - ++ lib.optionals stdenv.isDarwin [ - pkgs.darwin.cctools - pkgs.libiconv - ]; - in - { - default = pkgs.mkShell { - packages = - (with pkgs; [ - bash - cacert - cmake - coreutils - curl - diffutils - file - findutils - gh - ghostscript - git - gnumake - gnugrep - gnused - gnutar - gfortran - gzip - just - jq - m4 - ninja - openssh - patch - pkg-config - poppler-utils - python - ripgrep - rustToolchain - stdenv.cc - texliveFull - unzip - which - xz - zip - zstd - ]) - ++ platformTools; - - buildInputs = nativeLibraries; - - PYAMPLICOL_DEV_PYTHON = ".venv/bin/python"; - PIP_DISABLE_PIP_VERSION_CHECK = "1"; - PYTHONNOUSERSITE = "1"; - - # These paths support native wheels and generated SDK consumers in - # a Nix shell without changing release-artifact link metadata. - LD_LIBRARY_PATH = lib.optionalString stdenv.isLinux ( - lib.makeLibraryPath nativeLibraries - ); - NIX_LD_LIBRARY_PATH = lib.optionalString stdenv.isLinux ( - lib.makeLibraryPath nativeLibraries - ); - - shellHook = '' - echo "pyAmpliCol developer shell (Python 3.11, Rust 1.97.1, native SDK, TeX)" - echo "Run 'just dev-install' to create the pinned contributor environment." - ''; - }; - } - ); - }; -} diff --git a/pyamplicol/justfile b/pyamplicol/justfile index 048d34f0c5..3958bae5a5 100644 --- a/pyamplicol/justfile +++ b/pyamplicol/justfile @@ -7,7 +7,6 @@ eager_builtin_pack := env_var_or_default("PYAMPLICOL_EAGER_BUILTIN_PACK", ".arti eager_ufo_pack := env_var_or_default("PYAMPLICOL_EAGER_UFO_SM_PACK", ".artifacts/eager-models/ufo-sm-jit-o3.pyamplicol-model") eager_ufo_source := env_var_or_default("PYAMPLICOL_EAGER_UFO_SM_SOURCE", "src/pyamplicol/assets/models/json/sm/sm.json") dev_cache := ".artifacts/dev-install" -fft_performance_run_id := env_var_or_default("PYAMPLICOL_FFT_PERFORMANCE_RUN_ID", "manual") default: @just --list @@ -53,25 +52,6 @@ symjit-regressions: python-physics: PYTHONPATH="$PWD/src" PYAMPLICOL_REQUIRE_NATIVE_TESTS=1 {{python}} -m pytest tests/integration/test_schema_v3_generation_runtime.py tests/unit/test_reference_fixture_v2.py tests/unit/test_tracked_reference_fixture_v2.py tests/unit/test_color_contraction_safety.py -q -# Explicit, fail-fast numerical authority gate. This is intentionally excluded -# from the default suite because it generates fifteen catalog ProcessSets plus -# four separate full-colour extra artifacts. -numerical-acceptance: _source-checkout - PYTHONPATH="$PWD/src" PYAMPLICOL_RUN_NUMERICAL_ACCEPTANCE=1 PYAMPLICOL_REQUIRE_NATIVE_TESTS=1 {{dev_python}} tools/ci/memory_watchdog.py --limit-gib 30 -- {{dev_python}} -m pytest tests/integration/test_numerical_acceptance.py -q -x - -# Dedicated FFT process-table parity and frozen-MadGraph replay. -# This expensive gate is absent from every default CI and release aggregate. -fft-numerical-acceptance: _source-checkout - mkdir -p .artifacts/fft-acceptance-env/tmp .artifacts/fft-acceptance-env/cargo-home .artifacts/fft-acceptance-env/cargo-target .artifacts/fft-acceptance-env/pip-cache .artifacts/fft-acceptance-env/xdg-cache .artifacts/fft-acceptance-env/python-cache .artifacts/fft-numerical-acceptance - TMPDIR="$PWD/.artifacts/fft-acceptance-env/tmp" CARGO_HOME="$PWD/.artifacts/fft-acceptance-env/cargo-home" CARGO_TARGET_DIR="$PWD/.artifacts/fft-acceptance-env/cargo-target" CARGO_NET_OFFLINE=true PIP_CACHE_DIR="$PWD/.artifacts/fft-acceptance-env/pip-cache" PIP_NO_INDEX=1 XDG_CACHE_HOME="$PWD/.artifacts/fft-acceptance-env/xdg-cache" PYTHONPYCACHEPREFIX="$PWD/.artifacts/fft-acceptance-env/python-cache" PYTHONPATH="$PWD/src" PYAMPLICOL_REQUIRE_NATIVE_TESTS=1 {{dev_python}} tools/ci/memory_watchdog.py --limit-gib 30 -- {{dev_python}} tools/developer/fft_numerical_acceptance.py --output-root "$PWD/.artifacts/fft-numerical-acceptance" - -# Native same-host pure-gluon timing, RSS, and cold-to-ready comparison. Prepare -# its reference with `just dev-install --with-reference-fft`; this gate is -# deliberately excluded from default CI/release runs. -fft-performance-acceptance: _source-checkout - mkdir -p .artifacts/fft-performance/env/tmp .artifacts/fft-performance/env/cargo-home .artifacts/fft-performance/env/cargo-target .artifacts/fft-performance/env/pip-cache .artifacts/fft-performance/env/xdg-cache .artifacts/fft-performance/env/python-cache - TMPDIR="$PWD/.artifacts/fft-performance/env/tmp" CARGO_HOME="$PWD/.artifacts/fft-performance/env/cargo-home" CARGO_TARGET_DIR="$PWD/.artifacts/fft-performance/env/cargo-target" CARGO_NET_OFFLINE=true PIP_CACHE_DIR="$PWD/.artifacts/fft-performance/env/pip-cache" PIP_NO_INDEX=1 XDG_CACHE_HOME="$PWD/.artifacts/fft-performance/env/xdg-cache" PYTHONPYCACHEPREFIX="$PWD/.artifacts/fft-performance/env/python-cache" PYTHONPATH="$PWD/src" PYAMPLICOL_REQUIRE_NATIVE_TESTS=1 {{dev_python}} tools/ci/memory_watchdog.py --limit-gib 30 -- {{dev_python}} tools/developer/fft_gluon_performance_acceptance.py --include-optional --run-id "{{fft_performance_run_id}}" - # Reuse a current staged runtime, or build through the real backend and stage # ignored native runtime/SDK resources for source-tree tests. source-runtime: @@ -151,12 +131,9 @@ dev-install *INSTALLER_ARGS: _source-checkout mkdir -p {{dev_cache}}/tmp {{dev_cache}}/cargo-home {{dev_cache}}/cargo-target {{dev_cache}}/pip-cache {{dev_cache}}/xdg-cache {{dev_cache}}/python-cache TMPDIR="$PWD/{{dev_cache}}/tmp" CARGO_HOME="$PWD/{{dev_cache}}/cargo-home" CARGO_TARGET_DIR="$PWD/{{dev_cache}}/cargo-target" PIP_CACHE_DIR="$PWD/{{dev_cache}}/pip-cache" XDG_CACHE_HOME="$PWD/{{dev_cache}}/xdg-cache" PYTHONPYCACHEPREFIX="$PWD/{{dev_cache}}/python-cache" PYAMPLICOL_CANDIDATE_CACHE_ROOT="$PWD/{{dev_cache}}" {{python}} dependencies/install_dependencies.py {{INSTALLER_ARGS}} -# Report/campaign prerequisite. pyAmpliCol is not released yet, so this keeps -# the explicit build entrypoint tied to the published-dependency environment. dev-build: _source-checkout just dev-install {{dev_python}} -c 'import pyamplicol; import pyamplicol.api' - {{dev_python}} src/pyamplicol/_profiling_campaign/result_tables.py validate dev-test: _source-checkout PYTHON={{dev_python}} PYAMPLICOL_BUILD_MODE={{build_mode}} just source-gate diff --git a/pyamplicol/pyproject.toml b/pyamplicol/pyproject.toml index ee39907fa0..3d98ac590f 100644 --- a/pyamplicol/pyproject.toml +++ b/pyamplicol/pyproject.toml @@ -122,8 +122,6 @@ include = [ { path = "tools/ci/__init__.py", format = ["sdist"] }, { path = "tools/ci/memory_watchdog.py", format = ["sdist"] }, { path = "tools/developer/**/*", format = ["sdist"] }, - { path = "tools/fft_profiling/**/*", format = ["sdist"] }, - { path = "tools/performance_report/**/*", format = ["sdist"] }, { path = "tools/release/**/*", format = ["sdist"] }, { path = "tools/typing/**/*", format = ["sdist"] }, { path = "_sdk/**/*", from = "out-dir", to = "pyamplicol/", crate-name = "rusticol-python" }, @@ -137,7 +135,6 @@ exclude = [ "dependencies/install_dependencies.py", "dependencies/python-runtime-lock.toml", ".pyamplicol-build-dependencies/**", - "flake.nix", "outputs/**", "PYPI_DEPLOYMENT_TEST/**", "release_assets/**", diff --git a/pyamplicol/run_fft_profiling_render.sh b/pyamplicol/run_fft_profiling_render.sh deleted file mode 100755 index 78060834df..0000000000 --- a/pyamplicol/run_fft_profiling_render.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -if [[ -z "${IN_NIX_SHELL:-}" && -z "${PYAMPLICOL_FFT_NO_NIX:-}" ]]; then - exec nix develop --quiet --command "$0" "$@" -fi - -workspace_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" - -exec "$workspace_root/.venv/bin/python" \ - "$workspace_root/tools/fft_profiling/fft_profiling.py" \ - --output "$workspace_root/fft_profiling" \ - --render \ - "$@" diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/README.md b/pyamplicol/src/pyamplicol/_profiling_campaign/README.md deleted file mode 100644 index 63557f2937..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/README.md +++ /dev/null @@ -1,190 +0,0 @@ - -# pyAmpliCol profiling campaign template - -This packaged directory is the authoritative reset template for a -self-contained profiling campaign. Create it in a destination whose name -identifies its measurement environment: - -```console -pyamplicol profiling-campaign copy ./my-profiling-campaign \ - --local-madgraph /path/to/MG5_aMC -cd ./my-profiling-campaign -``` - -The copy contains the report's LaTeX sources, reset raw JSON measurements, and -generated table TeX. Its visible `campaign_artifacts/` directory contains all -evaluator attempts, prepared artifacts, worker logs, locks, leases, and other -runtime state. Moving or renaming the whole campaign therefore moves its state; -no repository-level or legacy `.artifacts` directory is consulted. - -Use the executable manual controller described in `TABLE_FILLING.md`. Its -`--help` output is the authoritative selector, resource-limit, reuse, and -keyboard-control reference: - -```console -./steer_performance_campaign.py --help -``` - -An installed pyAmpliCol wheel can create the portable reset copy without a -source checkout: - -```console -pyamplicol profiling-campaign copy ./pyamplicol-profiling-campaign --force -./pyamplicol-profiling-campaign/steer_performance_campaign.py --help -./pyamplicol-profiling-campaign/steer_performance_campaign.py run \ - --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in \ - --no-dependencies-added --no-dashboard -``` - -The final command is a real, deliberately small installation smoke test. It -measures only `d d~ > Z`; broader multiplicities belong on a dedicated -profiling host. - -`--force` overwrites the managed template files and resets only this copy's -`campaign_artifacts/`, `pyAmpliCol.pdf`, `campaign_summary_ids/`, and known -measurement-lineage/LaTeX build byproducts. It keeps unrelated files and a -previously recorded `.pyamplicol-original-amplicol` default unless a new -`--local-amplicol PATH` is supplied. It likewise preserves the recorded -`.pyamplicol-madgraph` default unless `--local-madgraph PATH` is supplied. -Stop an active campaign before resetting its destination. - -Release wheels do not include the optional `ratatui` and `ratatui_py` -dashboard bindings. Installed campaign runs therefore continue headlessly as -if `--no-dashboard` were supplied. `dashboard-snapshot` is available when -those bindings are present, including in a contributor checkout prepared with -`just dev-install`; otherwise it exits with the corresponding instruction. - -By default, a run adds the available numerical-authority closure for every -selected cell at the active source revision. MadGraph standalone is the -authoritative full-colour boundary for the four UFO-SM comparison views; -recurrence is the independent authority for compiled/eager comparisons on the -other surfaces. Original AmpliCol is retained only as a legacy performance and -numerical diagnostic and never certifies or rejects a candidate. Independent -processes remain parallel, while a terminal required authority releases its -candidate to run unverified. Use -`--no-dependencies-added` to suppress optional authority expansion; hard -construction and selector/provider dependencies are always retained. A -selection that directly or automatically includes `amplicol` requires a clean, -complete checkout exposing the color-probe sources and Make targets from PR -#12. Supply it with `run --original-amplicol PATH`, or add -`--local-amplicol PATH` to the copy command to record that checkout as this -campaign's default; the run option overrides the saved default. A source -checkout can prepare the default path with -`just dev-install --with-legacy-amplicol`. The `amplicol_with_patches` branch -works now; a compatible upstream revision will work unchanged after the PR is -merged. - -The full-colour MadGraph views require an installation with executable -`bin/mg5_aMC` and its standard `models/sm` UFO model. Supply it once with -`profiling-campaign copy --local-madgraph PATH`, or override the saved value -with `run --madgraph PATH`. Each authority cell streams `generate`, `output -standalone`, and `launch -f` through a MadGraph command card, counts the -standalone compilation in generation time, then compiles a small campaign-owned -Fortran driver to evaluate and benchmark the generated matrix element. The -same deterministic point is evaluated by pyAmpliCol at precision 200 for -recurrence, compiled, and eager, and at the supported precision 16 for OTF; all -four candidates must agree within relative tolerance `1e-10`. - -For on-the-fly LC cells in the n<=4 matrix, the matching recurrence cell is the -single numerical correctness authority. No compiled artifact is generated or -loaded for that gate. Original AmpliCol remains the legacy performance -baseline used by the OTF-versus-AmpliCol tables. OTF NLC and full colour use a -selector-free contracted workload and require the authenticated contracted- -colour runtime capability; the UFO-SM full-colour cells compare directly with -MadGraph. This contract is report-cache schema v5. - -With `run --fail-fast`, dispatch proceeds in multiplicity waves (`n=1`, then -`n=2`, and so on) and stops at the first required mismatch. A failed legacy -AmpliCol comparison is deliberately non-terminal: the existing table keeps all -other entries unchanged and renders only the AmpliCol generation time in red. - -Rebuild every table and the PDF from one stable current-result snapshot with: - -```console -./steer_performance_campaign.py refresh-pdf -``` - -The refresh shows a coloured progress bar while it reads and confirms the -campaign's current records. List the stable top-level PDF section IDs, or omit -selected sections from one generated PDF, with: - -```console -./steer_performance_campaign.py refresh-pdf --list-sections -./steer_performance_campaign.py refresh-pdf \ - --remove-sections worked-zgg shared-current-dag -``` - -Section removal changes only that staged PDF build. It does not remove -measurements, result JSON, generated table TeX, or source material; the next -plain `refresh-pdf` restores the complete report. `--quiet` suppresses both the -scan progress display and live LaTeX output. - -Review the deterministic dashboard fixture, or capture the newest running -campaign's read-only informational lease, with: - -```console -./steer_performance_campaign.py dashboard-snapshot -./steer_performance_campaign.py dashboard-snapshot --live -``` - -The live form reads only compact lease JSON in the ignored coordination -directory. Use `--instance ID_OR_PREFIX` to choose among concurrent runs; see -`dashboard-snapshot --help` for staleness and styled-cell capture controls. - -Every completed or orderly interrupted `run` atomically replaces -`campaign_summary_ids/` with one text file per non-success status. Each file -contains exact canonical cell IDs and can be fed straight back to `run` or -`inspect`: - -```console -./steer_performance_campaign.py run \ - --cell-id-file campaign_summary_ids/error.txt \ - campaign_summary_ids/validation_failed.txt \ - --force-refresh -``` - -`campaign_summary_ids/unverified.txt` is directly replayable without -`--force-refresh`: those timing diagnostics are not successful currents, and -they are rerun and validated automatically once the required recurrence or -MadGraph authority is available. - -For state-based retries, keep the ordinary table/process/engine selectors and -add `--rerun-failed`, `--rerun-capped`, or both. The flags filter only that -direct selection: failed means its latest terminal non-success is not an -authenticated policy cap, while capped means an authenticated policy cap. The -combined flags take the union; successful, static, and never-attempted cells -are excluded. Unverified results remain automatically retryable and can be -selected as failed. Normal dependency closure and reuse of successful currents -still apply, and `--continue-across-revisions` controls whether historical -terminal state participates. The retry flags conflict with `--force-refresh`. -A retry filter with no matches exits successfully without replacing the -existing campaign summary. - -The default lifecycle is compact. Each completed attempt retains its sealed -result and current pointer, provenance, commands, progress/timeline evidence, -bounded log tails, and reusable outputs needed by currents or dependencies. -Disposable copied AmpliCol, MadGraph, and build workspaces are removed after -publication; cross-revision reuse relies on the sealed results, not those -workspaces. Pass `run --retain-workspaces` only when full debug workspaces are -needed. `--cleanup-artifacts` remains a compatibility spelling for the default -compact policy. - -Two storage guards apply independently of process-tree memory supervision: -`--attempt-output-limit` defaults to 67,108,864 bytes (64 MiB) per watched -output/log file, and `--minimum-free-disk` defaults to 5,368,709,120 bytes -(5 GiB) on the campaign artifact volume. Both options accept byte counts. - -Create independent campaigns with separate `profiling-campaign copy` commands. -Every result artifact, worker lease, lock, and reproduction file remains below -that copy's `campaign_artifacts/`, even when two destinations share a basename. -A copy made from an installed wheel uses that wheel's recorded source revision -and installed runtime. Never commit `campaign_artifacts/`, evaluator artifacts, -candidate wheels, prepared models, attempts, logs, locks, coordination state, -page images, or LaTeX auxiliary files. - -When the launcher runs from a source checkout, it checks the checkout index -and worktree before measuring. It reads ordinary Git metadata directly and, -if HEAD is packed, uses one read-only `git rev-parse` query for the committed -tree. Installed-wheel campaigns do not need a Git checkout. diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/TABLE_FILLING.md b/pyamplicol/src/pyamplicol/_profiling_campaign/TABLE_FILLING.md deleted file mode 100644 index e165188269..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/TABLE_FILLING.md +++ /dev/null @@ -1,224 +0,0 @@ - -# Profiling campaign table filling - -First create and enter a reset campaign. The executable controller in that -copy is the authoritative campaign interface: - -```console -pyamplicol profiling-campaign copy ./my-profiling-campaign \ - --local-madgraph /path/to/MG5_aMC -cd ./my-profiling-campaign -./steer_performance_campaign.py --help -``` - -For an installed release wheel, first copy the reset campaign into a new or -empty destination and invoke the controller there: - -```console -pyamplicol profiling-campaign copy ./pyamplicol-profiling-campaign --force -./pyamplicol-profiling-campaign/steer_performance_campaign.py \ - run --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in \ - --no-dependencies-added --no-dashboard -``` - -This real smoke campaign selects only the final-state-multiplicity-one -`d d~ > Z` recurrence cell and is suitable for checking an installation. - -Release wheels omit the optional `ratatui` and `ratatui_py` dashboard -bindings. Installed runs automatically continue headlessly as though -`--no-dashboard` had been supplied. `dashboard-snapshot` remains available -when those bindings are present, notably in a contributor checkout prepared -with `just dev-install`; without them it exits with an actionable instruction. - -By default, selected cells gain their available active-source numerical -authority closure. MadGraph standalone is authoritative for the full-colour -UFO-SM views, and recurrence is authoritative for the remaining compiled/eager -cross-mode comparisons. Original AmpliCol is an optional legacy diagnostic and -performance denominator only. Added cells are dependency-only work; -independent processes remain parallel, and a terminal required authority -releases its candidate to run unverified. Pass `--no-dependencies-added` to -suppress optional -authority expansion while retaining every hard construction and -selector/provider dependency. A selection that directly or automatically -includes `amplicol` requires a clean, complete checkout exposing the PR #12 -probe sources and Make targets. Supply it with -`run --original-amplicol PATH`, or pass `--local-amplicol PATH` to the initial -`profiling-campaign copy` command to save it as the campaign default; the run -option overrides the saved default. A source checkout can prepare the default -path with `just dev-install --with-legacy-amplicol`. The -`amplicol_with_patches` branch works now, and a compatible upstream revision -will work unchanged after the PR is merged. - -The MadGraph full-colour cells require an installation containing executable -`bin/mg5_aMC` and the standard `models/sm` UFO model. Record it with the copy -command's `--local-madgraph PATH`, or supply/override it for one invocation via -`run --madgraph PATH`. The campaign times the streamed `generate`, `output -standalone`, `launch -f` sequence, including standalone compilation, and uses a -custom Fortran driver for the reference value and repeated-evaluation timing. -pyAmpliCol evaluates the shared comparison point at precision 200 for -recurrence, compiled, and eager, and at the supported precision 16 for OTF; -the strict relative tolerance is `1e-10` for every candidate. - -Use `run --fail-fast` for multiplicity-wave validation: all selected `n=1` -work completes before `n=2` is released, and the campaign stops at the first -required mismatch. A disagreement with legacy AmpliCol is non-terminal; only -its generation-time token is rendered red, while the rest of the existing -table remains unchanged. OTF NLC and full colour are genuine contracted -workloads with no flow selector and require their accuracy-specific runtime -capability; OTF LC retains the selected-flow and all-flow workloads. - -Inside a contributor checkout it re-executes with the repository `.venv`; an -installed copy uses the wheel's Python runtime. Both modes reuse compatible -same-source currents by default, supervise each process tree, and store campaign -state plus compact retained evidence in this campaign's visible -`campaign_artifacts/` directory. Full workspaces and other heavy debugging -payloads are retained only with `--retain-workspaces`. That state moves with the -entire campaign and never falls back to an old repository-level `.artifacts` -directory. Use separate copied directories for independent campaigns, even when -their basenames happen to match. - -Preview selections before launching workers: - -```console -./steer_performance_campaign.py run \ - --dry-run --table z_table --multiplicity 3 4 \ - --model built_in sm_ufo -``` - -The preview lists direct cells and dependency work separately and prints a -wrapped public-CLI recipe for every selected runnable cell, even for broad -selections. Each recipe uses the repository `.venv/bin/pyamplicol` and states -whether it is exact, a template, or a diagnostic protocol exception. UFO -recurrence/eager recipes include their public `model compile` prerequisite. - -The same small installation campaign, when run from inside its directory, is: - -```console -./steer_performance_campaign.py run \ - --workers 1 --table matrix --process-id 1 --multiplicity 1 \ - --color-approximation lc --generation-mode non-union-flow \ - --generation-engine recurrence --model built_in \ - --no-dependencies-added --no-dashboard -``` - -Broader selections may raise `--workers` and `--cores-per-worker` on a dedicated -profiling host. Original AmpliCol builds use the independent -`--amplicol-build-jobs` setting, which remains 1 by default because the -maintained legacy generator target is not parallel-safe. Defaults are one -worker, one pyAmpliCol core, one AmpliCol build job, a one-hour -generation/preparation limit, and a decimal 30 GB process-tree RAM limit. -`--ram-limit` applies to each worker tree. Add `--campaign-ram-limit` to place -an aggregate ceiling across all workers; it is conservatively divided by the -requested worker count and combined with the per-worker limit. Thus -`--workers 10 --ram-limit 30000000000 --campaign-ram-limit 30000000000` -limits each tree to 3 GB rather than permitting ten independent 30 GB claims. -Press `Ctrl-C` or `Esc` to stop dispatch, terminate supervised process trees, -preserve completed currents, and restore the terminal. - -After normal completion or an orderly interrupt, the controller prints the -absolute path of `campaign_summary_ids/`. It replaces that directory with one -sorted text file per non-success status, for example `error.txt`, -`blocked_dependency.txt`, `validation_failed.txt`, or `worker_timeout.txt`. -Replay any union of those exact IDs while retaining the normal dependency -closure and other selector intersections: - -```console -./steer_performance_campaign.py run \ - --cell-id-file campaign_summary_ids/error.txt \ - campaign_summary_ids/validation_failed.txt \ - --force-refresh -``` - -`--cell-id-file` is also accepted by `inspect`. Blank lines and full-line `#` -comments are ignored. For a structured retry within the ordinary direct -selection, add `--rerun-failed`, `--rerun-capped`, or both: - -```console -./steer_performance_campaign.py run \ - --table z_table --generation-engine recurrence compiled \ - --rerun-failed --rerun-capped -``` - -`--rerun-failed` keeps cells whose latest terminal outcome is unsuccessful but -is not an authenticated policy cap; `--rerun-capped` keeps authenticated policy -caps, and combining them takes the union. Successful, static, and unseen cells -are not direct retry targets. Unverified results are automatically retryable -and may be selected as failed. Dependency closure is still planned normally, -including reuse of successful prerequisite currents. Historical outcomes are -recognized only with `--continue-across-revisions`. These retry flags cannot be -combined with `--force-refresh`; use that option only for an unconditional -refresh. If no selected cell matches the requested retry state, the command is -a successful no-op and preserves the existing campaign summary. - -Replaying `blocked_dependency.txt` automatically includes required -prerequisites. -`unverified.txt` needs no `--force-refresh`: an unverified timing diagnostic is -not a successful current and is automatically rerun against a later available -recurrence or MadGraph authority. - -The default lifecycle is compact. Each completed attempt retains its sealed -result and current pointer, provenance, commands, progress/timeline evidence, -bounded log tails, and reusable outputs needed by currents or dependencies. -Disposable copied AmpliCol, MadGraph, and build workspaces are removed after -publication; cross-revision reuse relies on the sealed results, not those -workspaces. Use `--retain-workspaces` only when full debug workspaces are -needed. `--cleanup-artifacts` remains a compatibility spelling for the default -compact policy. - -Storage safety is separate from the process-tree RAM cap. -`--attempt-output-limit` defaults to 67,108,864 bytes (64 MiB) per watched -output/log file, while `--minimum-free-disk` reserves 5,368,709,120 bytes -(5 GiB) on the campaign artifact volume. Both options accept byte counts. - -Running `pyamplicol profiling-campaign copy DEST --force` again resets only -`DEST/campaign_artifacts`, the managed PDF, the campaign summary-ID directory, -known lineage/LaTeX build byproducts, and the packaged template files. It -preserves unrelated files and the recorded original-AmpliCol and MadGraph -paths unless new `--local-amplicol` or `--local-madgraph` values are supplied. -Stop active campaign processes before resetting their destination. - -Capture a running dashboard from another terminal without attaching to or -changing the campaign: - -```console -./steer_performance_campaign.py \ - dashboard-snapshot --live --width 160 --height 48 -``` - -This reads only the compact non-stale coordination lease. The newest active -invocation is the default; pass `--instance ID_OR_PREFIX` to choose one -concurrent run. Omit `--live` for the deterministic synthetic layout fixture. - -Inspect coverage and AmpliCol-relative statistics: - -```console -./steer_performance_campaign.py inspect \ - --color-approximation lc --generation-engine recurrence compiled -``` - -Rebuild all current JSON/TeX tables and atomically replace the PDF: - -```console -./steer_performance_campaign.py refresh-pdf -``` - -Interactive refreshes show a coloured progress bar while the controller reads -and confirms the complete current-record snapshot. To discover stable -top-level section IDs or build a shorter PDF without changing campaign data: - -```console -./steer_performance_campaign.py refresh-pdf --list-sections -./steer_performance_campaign.py refresh-pdf \ - --remove-sections worked-zgg shared-current-dag -``` - -The omission applies only to that PDF build. Measurements, JSON caches, table -TeX, and the canonical source remain present; a later plain refresh restores -the full report. Use `--quiet` to suppress the scan progress display and live -LaTeX output. - -Human output is coloured by default. Use `--no-color` or `NO_COLOR`; JSON is -always uncoloured. Consult each subcommand’s `--help` for all selectors, -aliases, resource controls, profiling parameters, reuse rules, and examples. diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/build_pdf.py b/pyamplicol/src/pyamplicol/_profiling_campaign/build_pdf.py deleted file mode 100644 index 47b616fc1c..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/build_pdf.py +++ /dev/null @@ -1,112 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Compile and verify an exported pyAmpliCol report using only its TeX folder.""" - -from __future__ import annotations - -import argparse -import re -import subprocess -from collections.abc import Sequence -from pathlib import Path -from shutil import which - - -class StandaloneBuildError(RuntimeError): - """The standalone publication could not be compiled or verified.""" - - -_UNRESOLVED_PATTERNS = ( - re.compile(r"LaTeX Warning: Citation .* undefined"), - re.compile(r"LaTeX Warning: Reference .* undefined"), - re.compile(r"LaTeX Warning: There were undefined references"), - re.compile(r"Package rerunfilecheck Warning:"), -) - - -def validate_latex_log(log: str) -> None: - """Reject layout overflow and unresolved cross-reference diagnostics.""" - - if "Overfull \\hbox" in log or "Overfull \\vbox" in log: - raise StandaloneBuildError("LaTeX output contains an overfull box") - for pattern in _UNRESOLVED_PATTERNS: - if pattern.search(log): - raise StandaloneBuildError( - f"LaTeX output is unresolved: {pattern.pattern}" - ) - - -def compile_report( - report_dir: Path, - *, - engine: str = "pdflatex", - passes: int = 3, -) -> Path: - """Compile ``pyAmpliCol.tex`` and reject unresolved or overflowing output.""" - - root = report_dir.expanduser().resolve(strict=True) - source = root / "pyAmpliCol.tex" - if not source.is_file(): - raise StandaloneBuildError(f"missing report source: {source}") - if passes < 2: - raise StandaloneBuildError("at least two LaTeX passes are required") - executable = which(engine) - if executable is None: - raise StandaloneBuildError(f"LaTeX engine is not available: {engine}") - - command = ( - executable, - "-interaction=nonstopmode", - "-halt-on-error", - "-file-line-error", - source.name, - ) - for _ in range(passes): - completed = subprocess.run( - command, - cwd=root, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - detail = (completed.stdout + completed.stderr)[-4000:] - raise StandaloneBuildError( - f"LaTeX compilation failed with exit {completed.returncode}:\n" - f"{detail}" - ) - - log_path = root / "pyAmpliCol.log" - try: - log = log_path.read_text(encoding="utf-8", errors="replace") - except OSError as error: - raise StandaloneBuildError(f"cannot read LaTeX log: {error}") from error - validate_latex_log(log) - - output = root / "pyAmpliCol.pdf" - if not output.is_file() or output.stat().st_size == 0: - raise StandaloneBuildError(f"LaTeX did not produce {output}") - return output - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description="Compile and verify this standalone pyAmpliCol report", - ) - parser.add_argument("--engine", default="pdflatex") - parser.add_argument("--passes", type=int, default=3) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(argv) - output = compile_report( - Path(__file__).resolve().parent, - engine=arguments.engine, - passes=arguments.passes, - ) - print(output) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/pyAmpliCol.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/pyAmpliCol.tex deleted file mode 100644 index 885d2d8362..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/pyAmpliCol.tex +++ /dev/null @@ -1,537 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\documentclass[10pt,letterpaper]{article} - -\usepackage[T1]{fontenc} -\usepackage[utf8]{inputenc} -\usepackage[letterpaper,margin=0.75in,headheight=21pt]{geometry} -\usepackage{amsmath,amssymb} -\usepackage{array} -\usepackage{booktabs} -\usepackage{eso-pic} -\usepackage{fancyhdr} -\usepackage{hyperref} -\usepackage{listings} -\usepackage{longtable} -\usepackage{pdflscape} -\usepackage{siunitx} -\usepackage[table]{xcolor} - -\DeclareMathSizes{5}{5}{5}{5} -\DeclareMathSizes{6.8}{6.8}{5}{5} - -\definecolor{ReportInk}{HTML}{17212B} -\definecolor{ReportBlue}{HTML}{145A86} -\definecolor{ReportGreen}{HTML}{287A58} -\definecolor{ReportOrange}{HTML}{B76E00} -\definecolor{ReportRed}{HTML}{B33A3A} -\definecolor{ReportRule}{HTML}{CBD3DA} -\definecolor{ReportMuted}{HTML}{66717C} -\definecolor{refblue}{HTML}{DCEBFF} -\definecolor{bestgreen}{HTML}{DFF5E4} -\definecolor{speedgreen}{HTML}{1A7F37} -\definecolor{speedorange}{HTML}{BF8700} -\definecolor{speedred}{HTML}{CF222E} - -\hypersetup{ - colorlinks=true, - linkcolor=ReportBlue, - urlcolor=ReportBlue, - pdftitle={pyAmpliCol 1.0.1 Methodology and Performance Report}, - pdfauthor={Rikkert Frederix, Valentin Hirschi, and Timea Vitos} -} -\sisetup{detect-all,scientific-notation=true,round-mode=figures,round-precision=3} -\setlength{\parindent}{0pt} -\setlength{\parskip}{0.55em} -\setcounter{secnumdepth}{2} -\setcounter{tocdepth}{1} - -\pagestyle{fancy} -\fancyhf{} -\fancyhead[L]{\textcolor{ReportInk}{pyAmpliCol 1.0.1}} -\fancyhead[R]{\textcolor{ReportMuted}{Methodology and performance}} -\fancyfoot[C]{\thepage} -\renewcommand{\headrulewidth}{0.4pt} -\renewcommand{\headrule}{\hbox to\headwidth{\color{ReportRule}\leaders\hrule height \headrulewidth\hfill}} - -\newif\ifReportLandscapePage -\ReportLandscapePagefalse -\AddToShipoutPictureFG{% - \ifReportLandscapePage - \AtPageLowerLeft{% - \put(\LenToUnit{\dimexpr\paperwidth-0.35in\relax}, - \LenToUnit{0.5\paperheight}){% - \rotatebox{90}{\makebox[0pt][c]{% - \textcolor{ReportMuted}{\thepage}}}}}% - \fi -} - -\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} -\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}} -\newcommand{\PAC}{\texttt{pyAmpliCol}} -\newcommand{\AC}{\texttt{AmpliCol}} -\newcommand{\ReportNA}{\textcolor{ReportMuted}{\textsc{n/a}}} -\newcommand{\ReportStatus}[1]{\textcolor{ReportMuted}{\textsc{#1}}} -\newcommand{\ReportMetricCell}[2]{\shortstack{\textcolor{ReportGreen}{G #1}\\\textcolor{ReportBlue}{R #2}}} -\newcommand{\ReportTableNote}[1]{\par\smallskip\noindent\footnotesize\textcolor{ReportMuted}{#1}\par} -\newcommand{\ReportMatrixLegend}{\ReportTableNote{The table heading names the baseline and candidate. LC reports the selected-flow, summed-helicity workload and the all-flow, selected-helicity workload separately. NLC and full colour report one contracted workload. Parenthesized values are candidate-to-baseline ratios; an execution attribution is shown only when both measurements expose it.}} -\newcommand{\ReportLadderLegend}{\ReportTableNote{Each LC workload reports process-generation time in seconds and native wall time in microseconds per phase-space point, together with a separately measured execution attribution when exposed. Compiled rows use the labelled JIT, ASM, or C++ backend; eager and recurrence rows use portable JIT O2 prepared models. Parenthesized wall-time and selected-flow generation values compare each pyAmpliCol row with the corresponding AmpliCol workload. For compiled and eager rows, wall time is the authenticated warmed total-evaluator boundary; not exposed refers only to a narrower execution attribution. All-flow generation is shown absolutely without a ratio because its setup boundary differs from the reference.}} -\newcommand{\ReportLandscapeFooter}{} -\newcommand{\ReportProfileName}{unpopulated} -\newcommand{\ReportPlatformSummary}{specified by the architecture profile} -\newcommand{\ReportToolchainSummary}{specified by the architecture profile} -\newcommand{\ReportEditionStatement}{This source is the unpopulated - documentation template. Architecture-specific copies contain their recorded - environment and measured results.} -\InputIfFileExists{report_environment.tex}{}{} - -\lstset{ - basicstyle=\ttfamily\small, - columns=fullflexible, - frame=single, - rulecolor=\color{ReportRule}, - breaklines=true, - showstringspaces=false, - xleftmargin=0.5em, - xrightmargin=0.5em -} - -\title{\vspace{-1.4cm}\textbf{pyAmpliCol 1.0.1}\\[0.35em] - \Large Methodology and Performance Report} -\author{Rikkert Frederix \and Valentin Hirschi \and Timea Vitos} -\date{Release 1.0.1\\[0.25em]\small Measurement profile: - \texttt{\ReportProfileName}} - -\begin{document} -\maketitle - -\begin{abstract} -This report presents the physics coverage, numerical validation, and -performance of \PAC{} 1.0.1. We compare compiled, eager, recurrence, and -on-the-fly evaluation across the report's stated built-in Standard Model and -UFO or serialized-JSON scopes, together with scalar-contact and scalar-gravity -benchmarks. Every reported -timing is associated with a documented software revision, hardware profile, -numerical configuration, and validation reference appropriate to the -corresponding data set. -\end{abstract} - -\begingroup -\small -\setlength{\parskip}{0pt} -\tableofcontents -\endgroup -\clearpage - -% pyamplicol-report-section-begin: scope -\section{Scope} - -\PAC{} generates and evaluates tree-level scattering amplitudes. Compiled mode -specializes a shared-current directed acyclic graph (DAG) to a process. Eager -mode evaluates the same graph with reusable model kernels. Recurrence mode -constructs a compact current schedule directly. On-the-fly mode stores a -compact source-oriented process seed and constructs selector-family schedules -lazily; this report covers its built-in-SM leading-colour and selector-free -contracted NLC/full lanes through four final-state particles. Within their -declared scopes, the modes implement the -same physics normalization, colour treatment, helicity sums, and resolved -observables. The original \AC{} program and its use in event generation are -described in Ref.~\cite{FrederixVitos2026}. - -The report has three purposes: -\begin{enumerate} - \item define the observables and conditions required for a reproducible - benchmark; - \item preserve a stable matrix of representative process families and colour - approximations; and - \item present performance only after numerical agreement has been verified. -\end{enumerate} - -In each architecture-specific report, an \ReportNA{} entry denotes a -process/multiplicity combination outside the declared scope or an observable -that does not apply. Every applicable cell across the complete declared -multiplicity range must instead contain a validated measurement or an -documented resource-limit status. A measurement that does not pass -numerical validation is labelled explicitly and never replaced by a timing -value. No value is copied, interpolated, or estimated from a neighbouring -cell. -% pyamplicol-report-section-end: scope - -% pyamplicol-report-section-begin: recursion -\section{Current Recursion and Model Lowering} - -\subsection{Shared-current DAG} - -For an external subset $I$, particle state $t$, and local spin or flow label -$\chi$, an off-shell current has the schematic recursion -\begin{equation} - J^{\alpha}_{t,\chi}(I) - = P^{\alpha}{}_{\beta}(t,p_I) - \sum_{I=A\mathbin{\dot\cup}B} - V^{\beta}{}_{\gamma\delta}(t_A,t_B\!\to t) - J^{\gamma}_{t_A,\chi_A}(A) - J^{\delta}_{t_B,\chi_B}(B), - \qquad p_I=\sum_{i\in I}p_i . - \label{eq:recursion} -\end{equation} -Current identity includes the particle, external labels, helicity ancestry, -chirality or spin state, flavour and charge flow, colour state, momentum mask, -and any auxiliary-current kind. Contributions with the same complete identity -share one node. A topological sweep therefore evaluates each retained current -once per phase-space point and reuses it in all dependent amplitudes. -This is a Berends--Giele-type construction~\cite{BerendsGiele1988}. - -The Universal Feynman Output format (UFO; originally Universal FeynRules -Output) describes particles, parameters, interactions, Lorentz tensors, -colour tensors, and propagators in a model-independent -form~\cite{UFO2012,UFO2023}. \PAC{} normalizes a trusted UFO Python module, or -its own serialized JSON representation of that model, to the same canonical -representation used by process generation. The UFO module is executable -Python; the corresponding serialized JSON form is data-only. - -Optimizations of imported models are based on exact colour, Lorentz, -propagator, and coupling identities rather than particle names or numerical -codes. For Standard-Model validation processes, the built-in and imported -routes must produce equivalent current, interaction, amplitude, and colour -content. Algebraic reuse is allowed only when the relevant identity has been -established exactly. - -\subsection{Contact terms and spin two} - -A supported vertex with valence above three is lowered to a deterministic tree -of non-propagating auxiliary currents. The construction inserts the original -coupling once and introduces no pole. Direct contraction of the original -contact tensor is the validation reference for the scalar-contact ladder. - -The scalar-gravity ladder exercises rank-two external states and -momentum-dependent interactions. For a massless graviton, the helicity-two -polarization tensor is represented as -\begin{equation} - \epsilon^{\mu\nu}_{\pm 2} - = \epsilon^{\mu}_{\pm}\epsilon^{\nu}_{\pm} . -\end{equation} -Validation checks symmetry, transversality, tracelessness, normalization, and -agreement between ordinary and higher-precision evaluation. -% pyamplicol-report-section-end: recursion - -% pyamplicol-report-section-begin: colour-runtime -\section{Colour and Runtime Semantics} - -The process matrices use three colour contracts: -\begin{center} -\begin{tabular}{@{}L{0.45in}L{5.85in}@{}} -\textbf{LC} & Leading-colour ordered amplitudes with physical colour-flow selectors~\cite{Maltoni2002}. \\ -\textbf{NLC} & Every colour-metric entry whose leading power is at most two below the leading power of the complete basis. \\ -\textbf{Full} & The complete supported sparse colour metric for the generated amplitude basis. \\ -\end{tabular} -\end{center} - -For NLC, ``retained'' applies to a colour-matrix \emph{entry}, not to a -truncated numerical coefficient. Write the exact overlap of two colour-flow -tensors as -\begin{equation} - C_{ab}(N_c)=\sum_p c^{(ab)}_p N_c^p, - \qquad - p_{ab}=\max\{p:c^{(ab)}_p\ne0\}, - \label{eq:nlc-entry-gate} -\end{equation} -and let \(P\) be the leading power of the complete colour basis. The sparse -NLC metric is -\begin{equation} - C^{\mathrm{NLC}}_{ab}= - \begin{cases} - C_{ab}(3), & p_{ab}\ge P-2,\\ - 0, & p_{ab}\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\providecommand{\bestmodecode}[1]{\textcolor{ReportMuted}{\texttt{(#1)}}} -\providecommand{\bestmodecodeprefix}[1]{\bestmodecode{#1}\hspace{0.025in}} -\providecommand{\bestmodeabsolutechoice}[2]{#1\hspace{0.025in}\bestmodecode{#2}} -\providecommand{\bestmodemix}[1]{\textcolor{ReportBlue}{\texttt{[#1]}}} -\clearpage -\subsection{Built-in SM best measured mode versus AmpliCol: full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. OTF \texttt{([xG]x(G+W))} follows the enclosing contracted cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. OTF \texttt{([xG]x(G+W))} follows the enclosing contracted cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_lc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_lc_table.tex deleted file mode 100644 index da9fedbcb0..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_lc_table.tex +++ /dev/null @@ -1,296 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\providecommand{\bestmodecode}[1]{\textcolor{ReportMuted}{\texttt{(#1)}}} -\providecommand{\bestmodecodeprefix}[1]{\bestmodecode{#1}\hspace{0.025in}} -\providecommand{\bestmodeabsolutechoice}[2]{#1\hspace{0.025in}\bestmodecode{#2}} -\providecommand{\bestmodemix}[1]{\textcolor{ReportBlue}{\texttt{[#1]}}} -\clearpage -\subsection{Built-in SM best measured mode versus AmpliCol: LC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol LC (block 1 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. For the LC all-flow workload, AmpliCol direct-evaluation setup and pyAmpliCol process generation have different boundaries, so the candidate generation value is shown absolutely; no misleading multiplier is formed. OTF \texttt{([xG]x(G+W)) | [G]G+W} follows the enclosing cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol LC (block 2 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. For the LC all-flow workload, AmpliCol direct-evaluation setup and pyAmpliCol process generation have different boundaries, so the candidate generation value is shown absolutely; no misleading multiplier is formed. OTF \texttt{([xG]x(G+W)) | [G]G+W} follows the enclosing cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol LC (block 3 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\textbf{n=9}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=9}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. For the LC all-flow workload, AmpliCol direct-evaluation setup and pyAmpliCol process generation have different boundaries, so the candidate generation value is shown absolutely; no misleading multiplier is formed. OTF \texttt{([xG]x(G+W)) | [G]G+W} follows the enclosing cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_nlc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_nlc_table.tex deleted file mode 100644 index 083155fcda..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_best_builtin_sm_nlc_table.tex +++ /dev/null @@ -1,212 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\providecommand{\bestmodecode}[1]{\textcolor{ReportMuted}{\texttt{(#1)}}} -\providecommand{\bestmodecodeprefix}[1]{\bestmodecode{#1}\hspace{0.025in}} -\providecommand{\bestmodeabsolutechoice}[2]{#1\hspace{0.025in}\bestmodecode{#2}} -\providecommand{\bestmodemix}[1]{\textcolor{ReportBlue}{\texttt{[#1]}}} -\clearpage -\subsection{Built-in SM best measured mode versus AmpliCol: NLC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol NLC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. OTF \texttt{([xG]x(G+W))} follows the enclosing contracted cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM best measured mode versus AmpliCol NLC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize The candidate is selected independently in each cell and workload by the smallest validated wall time. The upper row is generation in seconds and the lower row is runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each pair is non-union-flow \texttt{|} union-flow. Generation multipliers are coloured directly. Each runtime workload uses \texttt{([xS]xW)}. The muted supplementary xS first compares compatible exposed execution attributions; otherwise it uses authenticated evaluator totals. Because original AmpliCol exposes no evaluator-total clock, a candidate total then uses the AmpliCol direct execution clock, or its wall clock when direct execution is absent, as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; execution/execution remains the compatible supplementary attribution. The coloured xW is always the candidate/AmpliCol wall-time multiplier used for selection and as the primary figure of merit. If no compatible supplementary clock exists, only \texttt{(xW)} is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original-AmpliCol rows beyond its three-open-quark-line scope are catalog static N/A entries; their candidates are shown absolutely and excluded from ratio summaries. Unavailable baselines keep their status; candidates remain absolute. Unverified compiled, eager, or on-the-fly diagnostics are never eligible for best-mode selection or summaries and remain visibly marked unverified. OTF \texttt{([xG]x(G+W))} follows the enclosing contracted cold-start contract. Only exact stored same-point links enter ratios. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation is non-union only; LC runtime retains separate non-union and union wall-only lines. Muted generation-row codes (r)|(c)|(e)|(o) identify recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and on-the-fly JIT O2 wall-time winners; runtime rows omit them. Summary mode counts use r|c|e|o in the same order.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_full_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_full_table.tex deleted file mode 100644 index d16f732d53..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_full_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM compiled JIT O3 versus recurrence JIT O2 full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_lc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_lc_table.tex deleted file mode 100644 index 732e4545c7..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_lc_table.tex +++ /dev/null @@ -1,292 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM compiled JIT O3 versus recurrence JIT O2 LC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 LC (block 1 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the topology-replay/all-flow-union baseline generation times and wall times, followed by layout-matched candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 LC (block 2 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the topology-replay/all-flow-union baseline generation times and wall times, followed by layout-matched candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 LC (block 3 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\textbf{n=9}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=9}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the topology-replay/all-flow-union baseline generation times and wall times, followed by layout-matched candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_nlc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_nlc_table.tex deleted file mode 100644 index c08b9b2b41..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_builtin_sm_nlc_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM compiled JIT O3 versus recurrence JIT O2 NLC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 NLC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM compiled JIT O3 versus recurrence JIT O2 NLC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: compiled JIT O3. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_ufo_sm_full_vs_madgraph_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_ufo_sm_full_vs_madgraph_table.tex deleted file mode 100644 index fd504db4b3..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_compiled_ufo_sm_full_vs_madgraph_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM compiled JIT O3 versus MadGraph full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM compiled JIT O3 versus MadGraph full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: compiled JIT O3. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM compiled JIT O3 versus MadGraph full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: compiled JIT O3. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_full_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_full_table.tex deleted file mode 100644 index a8494ee036..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_full_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_lc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_lc_table.tex deleted file mode 100644 index 2002ea40d2..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_lc_table.tex +++ /dev/null @@ -1,292 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 LC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 LC (block 1 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the topology-replay/all-flow-union baseline generation times and wall times, followed by layout-matched candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 LC (block 2 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the topology-replay/all-flow-union baseline generation times and wall times, followed by layout-matched candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 LC (block 3 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\textbf{n=9}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=9}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the topology-replay/all-flow-union baseline generation times and wall times, followed by layout-matched candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_nlc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_nlc_table.tex deleted file mode 100644 index 1e0fd55100..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_builtin_sm_nlc_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 NLC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 NLC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM eager-DAG JIT O2 versus recurrence JIT O2 NLC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: recurrence JIT O2; candidate: eager-DAG JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_ufo_sm_full_vs_madgraph_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_ufo_sm_full_vs_madgraph_table.tex deleted file mode 100644 index 3fcb7c1aca..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_eager_ufo_sm_full_vs_madgraph_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM eager-DAG JIT O2 versus MadGraph full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM eager-DAG JIT O2 versus MadGraph full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: eager-DAG JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM eager-DAG JIT O2 versus MadGraph full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: eager-DAG JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Unverified compiled or eager diagnostics show absolute generation and runtime values with a yellow unverified marker, but never enter ratios or summaries. In their runtime token the muted bracketed value is evaluator-total and the following value is outer wall time. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_full_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_full_table.tex deleted file mode 100644 index d7752ffdf6..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_full_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM on-the-fly JIT O2 versus AmpliCol full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM on-the-fly JIT O2 versus AmpliCol full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: on-the-fly JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM on-the-fly JIT O2 versus AmpliCol full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: on-the-fly JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_lc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_lc_table.tex deleted file mode 100644 index 5c2aa0a1bd..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_lc_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM on-the-fly JIT O2 versus AmpliCol LC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM on-the-fly JIT O2 versus AmpliCol LC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: on-the-fly JIT O2. Each cell shows non-union-flow and union-flow quantities. For non-union flow, generation is ([xG] x(G+W)): the muted inner multiplier is artifact generation G alone and the normally coloured outer multiplier adds exactly the first cold on-the-fly evaluation W, both relative to AmpliCol selected-flow generation. For union flow, generation is the absolute [G] G+W pair, with G muted and G+W in normal black. W excludes artifact loading and conventional benchmark warm-ups. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM on-the-fly JIT O2 versus AmpliCol LC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.00} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=3}} & \multicolumn{8}{c}{\textbf{n=4}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=3}} & \multicolumn{8}{c}{\textbf{n=4}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: on-the-fly JIT O2. Each cell shows non-union-flow and union-flow quantities. For non-union flow, generation is ([xG] x(G+W)): the muted inner multiplier is artifact generation G alone and the normally coloured outer multiplier adds exactly the first cold on-the-fly evaluation W, both relative to AmpliCol selected-flow generation. For union flow, generation is the absolute [G] G+W pair, with G muted and G+W in normal black. W excludes artifact loading and conventional benchmark warm-ups. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_nlc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_nlc_table.tex deleted file mode 100644 index 8daf768bf4..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_builtin_sm_nlc_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM on-the-fly JIT O2 versus AmpliCol NLC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM on-the-fly JIT O2 versus AmpliCol NLC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: on-the-fly JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM on-the-fly JIT O2 versus AmpliCol NLC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: on-the-fly JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_ufo_sm_full_vs_madgraph_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_ufo_sm_full_vs_madgraph_table.tex deleted file mode 100644 index ba6f691dd1..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_on_the_fly_ufo_sm_full_vs_madgraph_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM on-the-fly JIT O2 versus MadGraph full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM on-the-fly JIT O2 versus MadGraph full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: on-the-fly JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM on-the-fly JIT O2 versus MadGraph full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: on-the-fly JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_full_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_full_table.tex deleted file mode 100644 index 14e6163be3..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_full_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM recurrence versus AmpliCol full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_lc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_lc_table.tex deleted file mode 100644 index 5be1fb8d19..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_lc_table.tex +++ /dev/null @@ -1,292 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM recurrence versus AmpliCol LC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol LC (block 1 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the selected-flow library-generation and all-flow direct-setup baseline quantities. The selected-flow entry carries a generation ratio; the all-flow entry carries the absolute pyAmpliCol process-generation time. Its setup boundary differs from the reference, so no generation ratio is formed. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol LC (block 2 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the selected-flow library-generation and all-flow direct-setup baseline quantities. The selected-flow entry carries a generation ratio; the all-flow entry carries the absolute pyAmpliCol process-generation time. Its setup boundary differs from the reference, so no generation ratio is formed. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol LC (block 3 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\textbf{n=9}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=9}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the selected-flow library-generation and all-flow direct-setup baseline quantities. The selected-flow entry carries a generation ratio; the all-flow entry carries the absolute pyAmpliCol process-generation time. Its setup boundary differs from the reference, so no generation ratio is formed. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_nlc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_nlc_table.tex deleted file mode 100644 index edd2ff8e12..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_builtin_sm_nlc_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{Built-in SM recurrence versus AmpliCol NLC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol NLC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM recurrence versus AmpliCol NLC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_table.tex deleted file mode 100644 index 2a5ddbcb6a..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM recurrence versus AmpliCol full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_vs_madgraph_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_vs_madgraph_table.tex deleted file mode 100644 index af6e00faf9..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_full_vs_madgraph_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM recurrence JIT O2 versus MadGraph full-colour} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence JIT O2 versus MadGraph full-colour (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence JIT O2 versus MadGraph full-colour (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: MadGraph standalone; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. MadGraph standalone is the authoritative full-colour numerical reference; its generation and repeated-evaluation measurements are shared by all four UFO-SM comparison views. Recurrence, compiled, and eager candidates use p200 at the comparison point; the on-the-fly candidate uses its supported p16 lane. Ratios and summaries require exact stored linkage to the current denominator. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_lc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_lc_table.tex deleted file mode 100644 index 13ea78895d..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_lc_table.tex +++ /dev/null @@ -1,292 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM recurrence versus AmpliCol LC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol LC (block 1 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{8}{c}{\textbf{n=2}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the selected-flow library-generation and all-flow direct-setup baseline quantities. The selected-flow entry carries a generation ratio; the all-flow entry carries the absolute pyAmpliCol process-generation time. Its setup boundary differs from the reference, so no generation ratio is formed. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol LC (block 2 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{8}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{8}{c}{} & \multicolumn{8}{c}{} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{8}{c}{\textbf{n=5}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the selected-flow library-generation and all-flow direct-setup baseline quantities. The selected-flow entry carries a generation ratio; the all-flow entry carries the absolute pyAmpliCol process-generation time. Its setup boundary differs from the reference, so no generation ratio is formed. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol LC (block 3 of 3)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}l>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l>{\matrixentryfontlc}c>{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{8}{c}{\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\textbf{n=9}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstaticna{ReportMuted} & \matrixpunct{|} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixpunct{|} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=7}} & \multicolumn{8}{c}{\textbf{n=8}} & \multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=9}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{8}{c}{\matrixna{ReportMuted}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\matrixsummaryworkloads{\textbf{summary: run single-flow, hel. sum}}{\textbf{summary: run all-flows, single hel.}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} & \multicolumn{8}{c}{\cellcolor{refblue}\matrixsummaryworkloads{\matrixna{ReportMuted}}{\matrixna{ReportMuted}}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the selected-flow library-generation and all-flow direct-setup baseline quantities. The selected-flow entry carries a generation ratio; the all-flow entry carries the absolute pyAmpliCol process-generation time. Its setup boundary differs from the reference, so no generation ratio is formed. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums and is the framed bold entry. LC generation uses selected flow only, while LC runtime shows separate selected-flow and all-flow wall-only lines. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_nlc_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_nlc_table.tex deleted file mode 100644 index 59add0555e..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_matrix_recurrence_ufo_sm_nlc_table.tex +++ /dev/null @@ -1,208 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\providecommand{\matrixpair}[2]{\begin{tabular}[t]{@{}r@{\hspace{0.025in}\matrixpunct{|}\hspace{0.025in}}r@{}}#1\end{tabular}} -\providecommand{\bestmoderatio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\bestmodecompactratio}[3]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}\textcolor{#2}{\texttt{x#3}}\matrixpunct{)}} -\providecommand{\bestmodewallratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodecompactprefix}[1]{\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}\hspace{0.04in}} -\providecommand{\bestmodeopenprefix}{\matrixpunct{(}\hspace{0.04in}} -\providecommand{\bestmodeprimaryratio}[2]{\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\bestmodeabsoluteprefix}[1]{#1\hspace{0.04in}} -\providecommand{\bestmodecompactabsolute}[2]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}\textcolor{black}{\texttt{#2}}} -\providecommand{\bestmodecompactabsoluteprefix}[1]{\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}} -\providecommand{\bestmodeabsoluteprimary}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\bestmodeunverifiedclockprefix}[2]{\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}\hspace{0.04in}#2\hspace{0.04in}} -\clearpage -\subsection{UFO-SM recurrence versus AmpliCol NLC} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol NLC (block 1 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\textbf{n=3}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=1}} & \multicolumn{3}{c}{\textbf{n=2}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=3}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM recurrence versus AmpliCol NLC (block 2 of 2)} -\begingroup -\centering -\footnotesize -\setlength{\tabcolsep}{2.1pt} -\renewcommand{\arraystretch}{1.04} -\matrixfitwidth{% -\begin{tabular}{@{}rL{1.45in}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l>{\matrixentryfont}l>{\matrixentryfont}r@{}>{\matrixentryfont}l@{}} -\toprule -\textbf{ID} & \textbf{base process} & \textbf{metric} & \multicolumn{3}{c}{\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\textbf{n=6}} \\ -\specialrule{0.85pt}{0pt}{0pt} -\rowcolor{refblue} -\texttt{1} & $d\bar d\to Z+(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{2} & $u\bar d\to W^++(n-1)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{3} & $d\bar d\to e^+e^-+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{4} & $u\bar d\to e^+\nu_e+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{5} & $d\bar d\to ZZ+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{6} & $gg\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{7} & $d\bar d\to t\bar t+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{8} & $gg\to gg+(n-2)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{9} & $d\bar d\to ZZZ+(n-3)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{10} & $d\bar d\to e^+e^-ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{11} & $d\bar d\to t\bar t ZH+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\texttt{12} & $d\bar d\to e^+e^-e^+e^-+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{\matrixstatus{ReportMuted}{not run}} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \multicolumn{3}{c}{} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{13} & $d\bar d\to u\bar u\,s\bar s+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\texttt{14} & $d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \multicolumn{3}{c}{\matrixnotapplicable{ReportMuted}} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \multicolumn{3}{c}{} & \multicolumn{3}{c}{} & \matrixstaticna{ReportMuted} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\rowcolor{refblue} -\texttt{15} & $d\bar d\to u\bar u\,u\bar u+(n-4)g$ & \textcolor{ReportMuted}{\scriptsize gen. [s]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} - & & \textcolor{ReportMuted}{\scriptsize run [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & & \matrixstatus{ReportMuted}{N/A} \\ -\addlinespace[0.05em] -\specialrule{1.05pt}{0.22em}{0.18em} -\multicolumn{3}{@{}l}{} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=4}} & \multicolumn{3}{c}{\textbf{n=5}} & \multicolumn{3}{c}{\cellcolor{refblue}\textbf{n=6}} \\ -\multicolumn{3}{@{}l}{\textbf{summary: generation}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\[0.08em] -\multicolumn{3}{@{}l}{\textbf{summary: wall}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} & \multicolumn{3}{c}{\matrixna{ReportMuted}} & \multicolumn{3}{c}{\cellcolor{refblue}\matrixna{ReportMuted}} \\ -\bottomrule -\end{tabular} -} -\endgroup -\ReportTableNote{{\scriptsize Baseline: original AmpliCol; candidate: recurrence JIT O2. Each cell shows the baseline generation and wall time, followed by candidate/baseline generation and wall-time ratios. Runtime comparisons use ([xS]xW). The muted supplementary xS first compares compatible exposed execution attributions; otherwise it compares authenticated evaluator totals. Only when original AmpliCol has no evaluator-total clock may a candidate evaluator total use the legacy direct execution clock (or its wall clock when direct execution is absent) as denominator. An evaluator total is never divided by a recurrence core. This evaluator-total fallback is diagnostic only; the execution/execution ratio remains the compatible supplementary attribution. The coloured xW is always the candidate/baseline wall multiplier and remains the primary figure of merit. When no compatible supplementary clock exists, only (xW) is shown. No clock is fabricated from another. Every displayed number uses exactly three significant digits. Original AmpliCol is static N/A beyond three open quark lines; unavailable, terminal, or unlinked baselines keep their status while successful candidate timings remain absolute and leave summaries. Summary rows contain multipliers only in min, max, median, average, and weighted-average order; the weighted average is the ratio of timing sums, is the framed bold entry, and runtime statistics use wall time only. Not applicable marks a multiplicity for which the process family does not exist. Not run marks an otherwise defined process that was intentionally excluded from the declared measurement scope. Fixed-engine tables intentionally omit mode letters because the selected engine is named in the table heading.}} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_contact_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_contact_table.tex deleted file mode 100644 index f50d770db7..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_contact_table.tex +++ /dev/null @@ -1,51 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\subsection{Scalar-contact ladder} -\begingroup -\scriptsize -\setlength{\tabcolsep}{2.2pt} -\renewcommand{\arraystretch}{1.10} -\begin{center} -\begin{tabular}{@{}L{1.00in}L{0.72in}L{0.72in}L{0.72in}L{0.72in}L{0.72in}L{0.72in}L{0.72in}@{}} -\toprule -\multicolumn{8}{c}{\texttt{scalar\_0 scalar\_0 > n*scalar\_0}} \\ -\textbf{metric} & \textbf{\texttt{n=2}} & \textbf{\texttt{n=3}} & \textbf{\texttt{n=4}} & \textbf{\texttt{n=5}} & \textbf{\texttt{n=6}} & \textbf{\texttt{n=7}} & \textbf{\texttt{n=8}} \\ -\midrule -\rowcolor{refblue} -generation [s] & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -wall [\(\mu\mathrm{s}/\mathrm{pt}\)] & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} -{\fontsize{6.4pt}{7.4pt}\selectfont\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -matrix element & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportOrange!8} -relative diff. vs hp & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\end{center} -\endgroup -\ReportTableNote{Wall time is the common runtime observable. Evaluator total is the independently measured accumulated warmed evaluator clock from its dedicated authenticated record; it is never copied from or derived from wall time. Unverified diagnostics retain absolute generation, wall, and evaluator clocks with a yellow marker; they are not successes. \textsc{not exposed} denotes a successful wall measurement, and older entries without dedicated evaluator-total evidence remain valid; it does not denote a missing result.} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_gravity_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_gravity_table.tex deleted file mode 100644 index a47239c5af..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_scalar_gravity_table.tex +++ /dev/null @@ -1,51 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\subsection{Scalar-gravity ladder} -\begingroup -\scriptsize -\setlength{\tabcolsep}{3.2pt} -\renewcommand{\arraystretch}{1.10} -\begin{center} -\begin{tabular}{@{}L{1.08in}L{0.82in}L{0.82in}L{0.82in}@{}} -\toprule -\multicolumn{4}{c}{\texttt{scalar\_0 scalar\_0 > n*graviton}} \\ -\textbf{metric} & \textbf{\texttt{n=2}} & \textbf{\texttt{n=3}} & \textbf{\texttt{n=4}} \\ -\midrule -\rowcolor{refblue} -generation [s] & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -wall [\(\mu\mathrm{s}/\mathrm{pt}\)] & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{refblue} -{\fontsize{6.4pt}{7.4pt}\selectfont\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -matrix element & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportOrange!8} -relative diff. vs hp & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\end{center} -\endgroup -\ReportTableNote{Wall time is the common runtime observable. Evaluator total is the independently measured accumulated warmed evaluator clock from its dedicated authenticated record; it is never copied from or derived from wall time. Unverified diagnostics retain absolute generation, wall, and evaluator clocks with a yellow marker; they are not successes. \textsc{not exposed} denotes a successful wall measurement, and older entries without dedicated evaluator-total evidence remain valid; it does not denote a missing result.} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_tables.py b/pyamplicol/src/pyamplicol/_profiling_campaign/result_tables.py deleted file mode 100644 index b8e6c811a0..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_tables.py +++ /dev/null @@ -1,711 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Compatibility entry point for the performance-report service.""" - -from __future__ import annotations - -import importlib.machinery -import json -import os -import subprocess -import sys -import sysconfig -import tempfile -import uuid -from pathlib import Path - -_EXACT_REEXEC_MARKER = "PYAMPLICOL_EXACT_PYTHON_REEXEC" -_EXACT_IMPORT_PATHS = "PYAMPLICOL_EXACT_IMPORT_PATHS" -_PUBLICATION_ONLY_COMMANDS = { - "init-profile", - "export-profile", - "validate", - "audit", - "audit-source-bridge", - "reset", - "render", - "recover", - "publish-snapshot", - "validate-snapshot", - "snapshot-cell-boundary", - "accept-cell-boundary", -} -_GLOBAL_OPTIONS_WITH_VALUE = { - "--repo-root", - "--report-profile", - "--docs-dir", - "--artifact-root", - "--coordination-root", - "--class-c-ancestor-runtime-root", - "--measurement-source-root", - "--expected-measurement-source-revision", - "--expected-measurement-source-tree", - "--expected-policy-wrapper-revision", - "--expected-policy-wrapper-tree", - "--expected-policy-entrypoint-sha256", - "--expected-legacy-adapter-sha256", - "--study-contract-sha256", -} - - -def _repository_root(entrypoint: Path) -> Path: - for candidate in entrypoint.parents: - if ( - (candidate / "tools/performance_report").is_dir() - and (candidate / "src/pyamplicol").is_dir() - ): - return candidate - raise RuntimeError( - "result_tables.py must run from a pyAmpliCol source checkout" - ) - - -def _embedded_profile(entrypoint: Path, repo_root: Path) -> str | None: - profile_parent = repo_root / "docs/performance_reports" - try: - relative = entrypoint.parent.relative_to(profile_parent) - except ValueError: - return None - return relative.parts[0] if len(relative.parts) == 1 else None - - -def _has_option(arguments: list[str], option: str) -> bool: - return any( - argument == option or argument.startswith(f"{option}=") - for argument in arguments - ) - - -def _subcommand(arguments: list[str]) -> str | None: - offset = 0 - while offset < len(arguments): - argument = arguments[offset] - if argument in _GLOBAL_OPTIONS_WITH_VALUE: - offset += 2 - continue - if any( - argument.startswith(f"{option}=") - for option in _GLOBAL_OPTIONS_WITH_VALUE - ): - offset += 1 - continue - if argument.startswith("-"): - offset += 1 - continue - return argument - return None - - -def _option_path(arguments: list[str], option: str) -> Path | None: - """Read one early bootstrap path option without importing the CLI.""" - - values: list[str] = [] - offset = 0 - while offset < len(arguments): - argument = arguments[offset] - if argument == option: - if offset + 1 >= len(arguments): - raise RuntimeError(f"{option} requires one absolute path") - values.append(arguments[offset + 1]) - offset += 2 - continue - prefix = f"{option}=" - if argument.startswith(prefix): - values.append(argument[len(prefix) :]) - offset += 1 - if not values: - return None - if len(values) != 1: - raise RuntimeError(f"{option} must be specified exactly once") - path = Path(values[0]) - if not path.is_absolute(): - raise RuntimeError(f"{option} must be an absolute path") - try: - root = path.resolve(strict=True) - except OSError as error: - raise RuntimeError(f"{option} is unavailable") from error - if not (root / "src/pyamplicol").is_dir(): - raise RuntimeError(f"{option} has no pyamplicol source package") - return root - - -def _option_value(arguments: list[str], option: str) -> str | None: - """Read one exact early-bootstrap value without importing the CLI.""" - - values: list[str] = [] - offset = 0 - while offset < len(arguments): - argument = arguments[offset] - if argument == option: - if offset + 1 >= len(arguments): - raise RuntimeError(f"{option} requires one value") - values.append(arguments[offset + 1]) - offset += 2 - continue - prefix = f"{option}=" - if argument.startswith(prefix): - values.append(argument[len(prefix) :]) - offset += 1 - if not values: - return None - if len(values) != 1 or not values[0]: - raise RuntimeError(f"{option} must be specified exactly once") - return values[0] - - -def _git_value(root: Path, expression: str) -> str: - completed = subprocess.run( - ("git", "-C", str(root), "rev-parse", expression), - check=False, - capture_output=True, - text=True, - ) - value = completed.stdout.strip() - if ( - completed.returncode != 0 - or len(value) != 40 - or any(character not in "0123456789abcdef" for character in value) - ): - raise RuntimeError( - f"cannot authenticate worker checkout identity {expression!r}" - ) - return value - - -def _require_git_identity( - root: Path, - *, - revision: str, - tree: str, - require_clean: bool, - require_tracked_clean: bool = False, - untracked_source_paths: tuple[str, ...] = (), -) -> None: - if ( - _git_value(root, "HEAD^{commit}") != revision - or _git_value(root, "HEAD^{tree}") != tree - ): - raise RuntimeError("worker checkout Git identity differs") - if require_clean: - completed = subprocess.run( - ( - "git", - "-C", - str(root), - "status", - "--porcelain=v1", - "--untracked-files=all", - ), - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0 or completed.stdout: - raise RuntimeError("policy-wrapper checkout is not clean") - if require_tracked_clean: - completed = subprocess.run( - ( - "git", - "-C", - str(root), - "diff", - "--quiet", - "--no-ext-diff", - "HEAD", - "--", - ), - check=False, - capture_output=True, - text=True, - ) - if completed.returncode == 1: - raise RuntimeError( - "measured-source checkout has tracked changes" - ) - if completed.returncode != 0: - raise RuntimeError( - "cannot inspect measured-source tracked cleanliness" - ) - if untracked_source_paths: - completed = subprocess.run( - ( - "git", - "-C", - str(root), - "ls-files", - "--others", - "--exclude-standard", - "-z", - "--", - *untracked_source_paths, - ), - check=False, - capture_output=True, - ) - if completed.returncode != 0: - raise RuntimeError( - "cannot inspect measured-source untracked files" - ) - if completed.stdout: - raise RuntimeError( - "measured-source checkout has untracked files in " - "imported source roots" - ) - - -def _sha256_file(path: Path) -> str: - import hashlib - - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _measured_venv_site_paths(measured_root: Path) -> tuple[Path, ...]: - """Recover the measured checkout's venv even under ``-I -S``.""" - - expected_venv = measured_root / ".venv" - if expected_venv.is_symlink() or not expected_venv.is_dir(): - raise RuntimeError( - "split worker requires a regular measured .venv directory" - ) - venv_root = expected_venv.resolve(strict=True) - executable = Path(os.path.abspath(sys.executable)) - if executable.parent.parent.resolve(strict=True) != venv_root: - raise RuntimeError( - "split worker interpreter is not the measured .venv interpreter" - ) - configuration = expected_venv / "pyvenv.cfg" - if configuration.is_symlink() or not configuration.is_file(): - raise RuntimeError("measured .venv has no regular pyvenv.cfg") - fields: dict[str, str] = {} - for line in configuration.read_text( - encoding="utf-8", - errors="strict", - ).splitlines(): - key, separator, value = line.partition("=") - if separator: - fields[key.strip().lower()] = value.strip() - if fields.get("include-system-site-packages", "").lower() != "false": - raise RuntimeError( - "measured .venv must exclude system site-packages" - ) - - variables = dict(sysconfig.get_config_vars()) - variables.update( - { - "base": str(venv_root), - "platbase": str(venv_root), - "installed_base": str(venv_root), - "installed_platbase": str(venv_root), - } - ) - paths: list[Path] = [] - for name in ("purelib", "platlib"): - value = sysconfig.get_path(name, vars=variables) - if not isinstance(value, str): - raise RuntimeError(f"measured .venv has no {name} path") - candidate = Path(value) - try: - resolved = candidate.resolve(strict=True) - resolved.relative_to(venv_root) - except (OSError, ValueError) as error: - raise RuntimeError( - f"measured .venv {name} path is unavailable" - ) from error - if resolved not in paths: - paths.append(resolved) - if not paths: - raise RuntimeError("measured .venv has no site-packages path") - return tuple(paths) - - -def _native_extensions(package_dir: Path) -> tuple[Path, ...]: - try: - candidates = tuple( - sorted( - ( - path - for path in package_dir.iterdir() - if path.name.startswith("_rusticol") - and path.name.endswith( - tuple(importlib.machinery.EXTENSION_SUFFIXES) - ) - ), - key=lambda path: path.name, - ) - ) - except OSError: - return () - if any(path.is_symlink() or not path.is_file() for path in candidates): - raise RuntimeError( - "measured native extension must be a regular file" - ) - return candidates - - -def _measured_split_runtime( - measured_root: Path, -) -> tuple[tuple[Path, ...], Path]: - """Return exact venv import roots and one canonical measured native root.""" - - site_paths = _measured_venv_site_paths(measured_root) - source_package = (measured_root / "src/pyamplicol").resolve(strict=True) - package_dirs = ( - source_package, - *( - site_path / "pyamplicol" - for site_path in site_paths - if (site_path / "pyamplicol").is_dir() - ), - ) - candidates: list[tuple[Path, Path, str]] = [] - for package_dir in package_dirs: - extensions = _native_extensions(package_dir) - if len(extensions) > 1: - raise RuntimeError( - "measured package has multiple native extension candidates" - ) - if extensions: - extension = extensions[0] - candidates.append( - (package_dir, extension, _sha256_file(extension)) - ) - if not candidates: - raise RuntimeError( - "split worker found no native extension in measured source/venv" - ) - if len({digest for _package, _path, digest in candidates}) != 1: - raise RuntimeError( - "measured source and venv native extensions differ" - ) - canonical_package = next( - ( - package - for package, _path, _digest in candidates - if package == source_package - ), - candidates[0][0], - ) - return site_paths, canonical_package - - -ENTRYPOINT = Path(__file__).resolve() -REPOSITORY_ROOT = _repository_root(ENTRYPOINT) -EMBEDDED_PROFILE = _embedded_profile(ENTRYPOINT, REPOSITORY_ROOT) -ARGUMENTS = list(sys.argv[1:]) -if ( - EMBEDDED_PROFILE is not None - and not _has_option(ARGUMENTS, "--report-profile") - and not _has_option(ARGUMENTS, "--docs-dir") -): - ARGUMENTS[:0] = ("--report-profile", EMBEDDED_PROFILE) -COMMAND = _subcommand(ARGUMENTS) -CLASS_C_ANCESTOR_RUNTIME_ROOT = _option_path( - ARGUMENTS, - "--class-c-ancestor-runtime-root", -) -MEASUREMENT_SOURCE_ROOT = _option_path( - ARGUMENTS, - "--measurement-source-root", -) -_SPLIT_WORKER_OPTIONS = { - "measured_revision": _option_value( - ARGUMENTS, - "--expected-measurement-source-revision", - ), - "measured_tree": _option_value( - ARGUMENTS, - "--expected-measurement-source-tree", - ), - "wrapper_revision": _option_value( - ARGUMENTS, - "--expected-policy-wrapper-revision", - ), - "wrapper_tree": _option_value( - ARGUMENTS, - "--expected-policy-wrapper-tree", - ), - "entrypoint_sha256": _option_value( - ARGUMENTS, - "--expected-policy-entrypoint-sha256", - ), - "legacy_adapter_sha256": _option_value( - ARGUMENTS, - "--expected-legacy-adapter-sha256", - ), - "study_contract_sha256": _option_value( - ARGUMENTS, - "--study-contract-sha256", - ), -} -_SPLIT_WORKER_SPECIFIED = ( - MEASUREMENT_SOURCE_ROOT is not None - or any(value is not None for value in _SPLIT_WORKER_OPTIONS.values()) -) -if _SPLIT_WORKER_SPECIFIED: - if MEASUREMENT_SOURCE_ROOT is None or any( - value is None for value in _SPLIT_WORKER_OPTIONS.values() - ): - raise RuntimeError( - "split worker wrapper/source options must be specified together" - ) - if COMMAND not in {"_prepare", "_worker"}: - raise RuntimeError( - "split worker wrapper/source options are restricted to workers" - ) - requested_repo_root = _option_path(ARGUMENTS, "--repo-root") - if requested_repo_root != MEASUREMENT_SOURCE_ROOT: - raise RuntimeError( - "worker --repo-root must equal --measurement-source-root" - ) - measured_revision = str(_SPLIT_WORKER_OPTIONS["measured_revision"]) - measured_tree = str(_SPLIT_WORKER_OPTIONS["measured_tree"]) - wrapper_revision = str(_SPLIT_WORKER_OPTIONS["wrapper_revision"]) - wrapper_tree = str(_SPLIT_WORKER_OPTIONS["wrapper_tree"]) - _require_git_identity( - MEASUREMENT_SOURCE_ROOT, - revision=measured_revision, - tree=measured_tree, - require_clean=False, - require_tracked_clean=True, - # ``src`` is the measured checkout's only Python import root. - untracked_source_paths=("src",), - ) - _require_git_identity( - REPOSITORY_ROOT, - revision=wrapper_revision, - tree=wrapper_tree, - require_clean=True, - ) - if _sha256_file(ENTRYPOINT) != _SPLIT_WORKER_OPTIONS[ - "entrypoint_sha256" - ]: - raise RuntimeError("policy-wrapper entrypoint digest differs") - if _sha256_file( - REPOSITORY_ROOT / "tools/performance_report/legacy.py" - ) != _SPLIT_WORKER_OPTIONS["legacy_adapter_sha256"]: - raise RuntimeError("policy-wrapper legacy adapter digest differs") -if ( - CLASS_C_ANCESTOR_RUNTIME_ROOT is not None - and COMMAND != "prepare-class-c-bridge" -): - raise RuntimeError( - "--class-c-ancestor-runtime-root is restricted to " - "prepare-class-c-bridge" - ) -RUNTIME_REQUIRED = COMMAND not in _PUBLICATION_ONLY_COMMANDS - - -def _native_package_dir(search_path: object = sys.path) -> Path | None: - if not isinstance(search_path, (list, tuple)): - raise RuntimeError("Python import path is invalid") - for entry in search_path: - if not isinstance(entry, str): - continue - package_dir = Path(entry) / "pyamplicol" - try: - native = any( - path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in package_dir.iterdir() - ) - except OSError: - continue - if native: - return package_dir - return None - - -def _bootstrap_exact_python(arguments: list[str]) -> None: - """Re-exec before importing any repository or candidate module.""" - - if os.environ.get(_EXACT_REEXEC_MARKER) == "1": - if ( - sys.flags.isolated != 1 - or sys.flags.no_site != 1 - or sys.flags.ignore_environment != 1 - or sys.flags.dont_write_bytecode != 1 - or not sys.dont_write_bytecode - ): - raise RuntimeError("exact Python re-exec flags are incomplete") - raw_paths = json.loads(os.environ[_EXACT_IMPORT_PATHS]) - if not isinstance(raw_paths, list) or not all( - isinstance(path, str) and Path(path).is_absolute() for path in raw_paths - ): - raise RuntimeError("exact Python import paths are invalid") - if MEASUREMENT_SOURCE_ROOT is not None: - measured_paths, _native_package = _measured_split_runtime( - MEASUREMENT_SOURCE_ROOT - ) - if raw_paths != [str(path) for path in measured_paths]: - raise RuntimeError( - "exact Python import paths differ from measured .venv" - ) - cache_prefix = os.environ.get("PYTHONPYCACHEPREFIX") - if ( - not isinstance(cache_prefix, str) - or not Path(cache_prefix).is_absolute() - or Path(cache_prefix).exists() - ): - raise RuntimeError("exact Python cache prefix is not absent") - for import_path in reversed(raw_paths): - if import_path not in sys.path: - sys.path.insert(0, import_path) - # ``-I`` ignores PYTHON* variables. Install the authenticated absent - # namespace explicitly before any repository or candidate import. - sys.pycache_prefix = cache_prefix - return - - prefix = Path(tempfile.gettempdir()) / ( - f".pyamplicol-no-bytecode-{os.getpid()}-{uuid.uuid4().hex}" - ) - if prefix.exists(): - raise RuntimeError( - f"isolated Python cache prefix unexpectedly exists: {prefix}" - ) - if MEASUREMENT_SOURCE_ROOT is not None: - measured_paths, _native_package = _measured_split_runtime( - MEASUREMENT_SOURCE_ROOT - ) - import_paths = [str(path) for path in measured_paths] - elif COMMAND in {"_prepare", "_worker"}: - # The scheduler deliberately starts workers with ``-I -S``. On - # Python 3.12, suppressing ``site`` also prevents pyvenv.cfg from - # changing ``sys.prefix``, so generic sysconfig discovery below would - # resolve the base interpreter's site-packages instead of this - # checkout's venv. Workers always use the repository venv; recover - # and authenticate its paths explicitly just as split workers do. - import_paths = [ - str(path) for path in _measured_venv_site_paths(REPOSITORY_ROOT) - ] - else: - import_paths = [] - native_package = _native_package_dir() - if native_package is not None: - import_paths.append( - str(native_package.parent.resolve(strict=True)) - ) - for scheme_name in ("purelib", "platlib"): - scheme_path = sysconfig.get_path(scheme_name) - if not isinstance(scheme_path, str): - continue - try: - resolved = str(Path(scheme_path).resolve(strict=True)) - except OSError: - continue - if resolved not in import_paths: - import_paths.append(resolved) - environment = os.environ.copy() - environment["PYTHONDONTWRITEBYTECODE"] = "1" - environment["PYTHONPYCACHEPREFIX"] = str(prefix) - environment[_EXACT_REEXEC_MARKER] = "1" - environment[_EXACT_IMPORT_PATHS] = json.dumps(import_paths) - os.execve( - sys.executable, - ( - sys.executable, - "-I", - "-S", - "-B", - str(ENTRYPOINT.resolve(strict=True)), - *arguments, - ), - environment, - ) - raise RuntimeError("exact Python re-exec returned unexpectedly") - - -if __name__ == "__main__": - _bootstrap_exact_python(ARGUMENTS) - -_PACKAGE_SOURCE_ROOT = ( - CLASS_C_ANCESTOR_RUNTIME_ROOT - if CLASS_C_ANCESTOR_RUNTIME_ROOT is not None - else ( - REPOSITORY_ROOT - if MEASUREMENT_SOURCE_ROOT is None - else MEASUREMENT_SOURCE_ROOT - ) -) -_IMPORT_ROOTS = ( - REPOSITORY_ROOT, - _PACKAGE_SOURCE_ROOT / "src", -) -for source_root in reversed(_IMPORT_ROOTS): - if str(source_root) not in sys.path: - sys.path.insert(0, str(source_root)) -NATIVE_PACKAGE_DIR = ( - _native_package_dir() - if MEASUREMENT_SOURCE_ROOT is None - else _measured_split_runtime(MEASUREMENT_SOURCE_ROOT)[1] -) - -if __name__ == "__main__": - from tools.performance_report.runtime_evidence import ( - RuntimeEvidenceError, - source_only_bytecode_policy, - ) - - try: - source_only_bytecode_policy() - except RuntimeEvidenceError as error: - raise RuntimeError( - "could not establish source-only Python bytecode isolation" - ) from error - -if __name__ == "__main__" and RUNTIME_REQUIRED: - from tools.performance_report.runtime_evidence import ( - native_extension_in_package, - preimport_python_runtime_identity, - ) - - if NATIVE_PACKAGE_DIR is not None: - _EXACT_SOURCE_PACKAGE = _PACKAGE_SOURCE_ROOT / "src" / "pyamplicol" - _EXACT_PACKAGE_ROOTS = ( - (_EXACT_SOURCE_PACKAGE,) - if NATIVE_PACKAGE_DIR == _EXACT_SOURCE_PACKAGE - else (_EXACT_SOURCE_PACKAGE, NATIVE_PACKAGE_DIR) - ) - _EXACT_NATIVE_EXTENSION = native_extension_in_package(NATIVE_PACKAGE_DIR) - preimport_python_runtime_identity( - _EXACT_PACKAGE_ROOTS, - native_extension=_EXACT_NATIVE_EXTENSION, - ) - - import pyamplicol - - if ( - NATIVE_PACKAGE_DIR is not None - and str(NATIVE_PACKAGE_DIR) not in pyamplicol.__path__ - ): - # Match normal Python import precedence exactly. Additional native-bearing - # installations remain ineligible rather than expanding this namespace. - pyamplicol.__path__.append(str(NATIVE_PACKAGE_DIR)) - if MEASUREMENT_SOURCE_ROOT is not None: - expected_package_roots = { - path.resolve(strict=True) - for path in _EXACT_PACKAGE_ROOTS - } - observed_package_roots = { - Path(path).resolve(strict=True) - for path in pyamplicol.__path__ - } - if ( - observed_package_roots - - expected_package_roots - or _EXACT_SOURCE_PACKAGE.resolve(strict=True) - not in observed_package_roots - ): - raise RuntimeError( - "pyamplicol namespace escaped measured source/venv roots" - ) - -from tools.performance_report.cli import main # noqa: E402, I001 - - -if __name__ == "__main__": - raise SystemExit(main(ARGUMENTS)) diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_validation_summary.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_validation_summary.tex deleted file mode 100644 index 445174f8f5..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_validation_summary.tex +++ /dev/null @@ -1,44 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/validation_summary.py; do not edit. -\begin{samepage} -\subsection*{Numerical validation summary} -Only measurements whose numerical checks pass are counted below. The scope comprises every applicable report cell across the complete declared multiplicity range. -\begin{center} -\small -\begin{tabular}{@{}l r r r l@{}} -\toprule -\textbf{final-state multiplicity} & \textbf{declared} & \textbf{static N/A} & \textbf{verified} & \textbf{measurable coverage} \\ -\midrule -1 & 84 & 0 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 84 open)} \\ -2 & 254 & 0 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 254 open)} \\ -3 & 282 & 0 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 282 open)} \\ -4 & 422 & 0 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 422 open)} \\ -5 & 393 & 0 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 393 open)} \\ -6 & 227 & 4 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 223 open)} \\ -7 & 179 & 10 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 169 open)} \\ -8 & 179 & 10 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 169 open)} \\ -9 & 178 & 10 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 168 open)} \\ -\midrule -\textbf{total} & 2198 & 34 & 0 & \textcolor{ReportOrange}{incomplete (0 censored, 2164 open)} \\ -\bottomrule -\end{tabular} -\end{center} -\end{samepage} -\ReportTableNote{Full-catalog display accounting through \(n=9\): 2198 declared cells, comprising 2164 measurable cells and 34 catalog-authenticated static N/A rows; 659 matrix process/multiplicity positions marked either \textsc{not applicable} or \textsc{not run}; and 36 reference execution fields marked \textsc{not exposed}. The latter two categories are intentional table structure, not unfilled measurements.} -\begin{center} -\small -\begin{tabular}{@{}l r r@{}} -\toprule -\textbf{validation evidence} & \textbf{records} & \textbf{max. relative difference} \\ -\midrule -MadGraph standalone tree-level reference records & 0 & \textcolor{ReportMuted}{reference} \\ -\PAC{} versus MadGraph binary64 (p200; OTF p16) & 0 & \textcolor{ReportMuted}{---} \\ -original-\AC{} legacy diagnostic records & 0 & \textcolor{ReportMuted}{diagnostic} \\ -\PAC{} versus original-\AC{} legacy diagnostic & 0 pass, 0 mismatch & \textcolor{ReportMuted}{---} \\ -compiled/eager/OTF versus recurrence & 0 & \textcolor{ReportMuted}{---} \\ -optimized result versus resolved sum & 0 & \textcolor{ReportMuted}{---} \\ -binary64 result versus p32 & 0 & \textcolor{ReportMuted}{---} \\ -\bottomrule -\end{tabular} -\end{center} -\ReportTableNote{Profile: \texttt{\ReportProfileName}. Measured source: \textcolor{ReportOrange}{source identity is incomplete or mixed}. The authoritative \PAC{} versus MadGraph binary64 full-colour comparison uses p200 for recurrence, compiled, and eager candidates and the supported p16 lane for OTF; all use a relative tolerance of \(10^{-10}\). Original-\AC{} comparisons are retained non-authoritative legacy diagnostics at \(10^{-8}\); a legacy mismatch does not invalidate a candidate; cross-mode (including OTF/recurrence), resolved-sum, and p32 comparisons use \(10^{-12}\).} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_z_builtin_sm_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_z_builtin_sm_table.tex deleted file mode 100644 index 37c64a6a68..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_z_builtin_sm_table.tex +++ /dev/null @@ -1,205 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\clearpage -\subsection{Built-in SM dedicated \(d\bar d\to Z+\) gluon performance} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM \(d\bar d\to Z+\) gluon ladder (block 1 of 3)} -\begingroup -\centering -\scriptsize -\setlength{\tabcolsep}{1.4pt} -\renewcommand{\arraystretch}{1.05} -\begin{tabular}{@{}r L{1.50in} R{1.26in} R{1.26in} R{1.26in} @{\hspace{0.08in}}R{1.26in} R{1.26in} R{1.26in}@{}} -\toprule -\textbf{n} & \textbf{setup} & \multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & \multicolumn{3}{c}{\textbf{all flows, single helicity}} \\ -& & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\ -\midrule -\rowcolor{refblue} -1 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -1 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -1 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -1 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -2 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -2 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -2 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -2 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -3 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -3 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -3 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -3 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\endgroup -\ReportTableNote{Original AmpliCol is the denominator only when successful and exactly linked by stored same-point evidence, directly or through current recurrence. Otherwise its status remains visible and successful pyAmpliCol values are absolute. Unverified diagnostics retain absolute clocks with a yellow marker, but never enter ratios or summaries. Compiled, eager, and recurrence rows report separate topology-replay and all-flow-union generation and runtime measurements. On-the-fly uses one compact query-local process seed for both physical workloads. Its generation entry is the absolute \texttt{[G] G+W} pair: muted G is process-seed generation and G+W adds the first cold on-the-fly evaluation. Parenthesized values are candidate/reference ratios. All-flow generation shows the absolute pyAmpliCol value without a ratio because its setup boundary differs from the reference. The wall time is the common runtime observable. Not exposed means that a successful wall measurement has no dedicated authenticated evaluator-total timing. Authenticated accumulated warmed evaluator totals appear in the eval column with enough precision to remain distinct from wall time. Its parenthesized multiplier uses the original-AmpliCol wall measurement as denominator because the legacy reference has no separate evaluator-total clock. Recurrence rows retain the independently measured narrower recurrence core in detailed evidence; it is not relabeled as evaluator total. Neither evaluator total nor recurrence core is derived from wall time or from the other. Older entries without authenticated total evidence remain marked not exposed; it is not a missing measurement. user cap: native C++/ASM generation is not attempted above n=6 (native-backend-generation-cap-n6-v1).} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM \(d\bar d\to Z+\) gluon ladder (block 2 of 3)} -\begingroup -\centering -\scriptsize -\setlength{\tabcolsep}{1.4pt} -\renewcommand{\arraystretch}{1.05} -\begin{tabular}{@{}r L{1.50in} R{1.26in} R{1.26in} R{1.26in} @{\hspace{0.08in}}R{1.26in} R{1.26in} R{1.26in}@{}} -\toprule -\textbf{n} & \textbf{setup} & \multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & \multicolumn{3}{c}{\textbf{all flows, single helicity}} \\ -& & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\ -\midrule -\rowcolor{refblue} -4 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -4 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -4 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -4 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -5 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -5 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -5 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -5 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -6 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -6 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -6 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -6 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\endgroup -\ReportTableNote{Original AmpliCol is the denominator only when successful and exactly linked by stored same-point evidence, directly or through current recurrence. Otherwise its status remains visible and successful pyAmpliCol values are absolute. Unverified diagnostics retain absolute clocks with a yellow marker, but never enter ratios or summaries. Compiled, eager, and recurrence rows report separate topology-replay and all-flow-union generation and runtime measurements. On-the-fly uses one compact query-local process seed for both physical workloads. Its generation entry is the absolute \texttt{[G] G+W} pair: muted G is process-seed generation and G+W adds the first cold on-the-fly evaluation. Parenthesized values are candidate/reference ratios. All-flow generation shows the absolute pyAmpliCol value without a ratio because its setup boundary differs from the reference. The wall time is the common runtime observable. Not exposed means that a successful wall measurement has no dedicated authenticated evaluator-total timing. Authenticated accumulated warmed evaluator totals appear in the eval column with enough precision to remain distinct from wall time. Its parenthesized multiplier uses the original-AmpliCol wall measurement as denominator because the legacy reference has no separate evaluator-total clock. Recurrence rows retain the independently measured narrower recurrence core in detailed evidence; it is not relabeled as evaluator total. Neither evaluator total nor recurrence core is derived from wall time or from the other. Older entries without authenticated total evidence remain marked not exposed; it is not a missing measurement. user cap: native C++/ASM generation is not attempted above n=6 (native-backend-generation-cap-n6-v1).} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{Built-in SM \(d\bar d\to Z+\) gluon ladder (block 3 of 3)} -\begingroup -\centering -\scriptsize -\setlength{\tabcolsep}{1.4pt} -\renewcommand{\arraystretch}{1.05} -\begin{tabular}{@{}r L{1.50in} R{1.26in} R{1.26in} R{1.26in} @{\hspace{0.08in}}R{1.26in} R{1.26in} R{1.26in}@{}} -\toprule -\textbf{n} & \textbf{setup} & \multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & \multicolumn{3}{c}{\textbf{all flows, single helicity}} \\ -& & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\ -\midrule -\rowcolor{refblue} -7 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -7 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -7 & compiled ASM O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -7 & compiled C++ O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -\rowcolor{ReportGreen!12} -7 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -7 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -7 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -7 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -8 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -8 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -8 & compiled ASM O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -8 & compiled C++ O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -\rowcolor{ReportGreen!12} -8 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -8 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -8 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -8 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -9 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -9 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -9 & compiled ASM O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -9 & compiled C++ O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -\rowcolor{ReportGreen!12} -9 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -9 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -9 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -9 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\endgroup -\ReportTableNote{Original AmpliCol is the denominator only when successful and exactly linked by stored same-point evidence, directly or through current recurrence. Otherwise its status remains visible and successful pyAmpliCol values are absolute. Unverified diagnostics retain absolute clocks with a yellow marker, but never enter ratios or summaries. Compiled, eager, and recurrence rows report separate topology-replay and all-flow-union generation and runtime measurements. On-the-fly uses one compact query-local process seed for both physical workloads. Its generation entry is the absolute \texttt{[G] G+W} pair: muted G is process-seed generation and G+W adds the first cold on-the-fly evaluation. Parenthesized values are candidate/reference ratios. All-flow generation shows the absolute pyAmpliCol value without a ratio because its setup boundary differs from the reference. The wall time is the common runtime observable. Not exposed means that a successful wall measurement has no dedicated authenticated evaluator-total timing. Authenticated accumulated warmed evaluator totals appear in the eval column with enough precision to remain distinct from wall time. Its parenthesized multiplier uses the original-AmpliCol wall measurement as denominator because the legacy reference has no separate evaluator-total clock. Recurrence rows retain the independently measured narrower recurrence core in detailed evidence; it is not relabeled as evaluator total. Neither evaluator total nor recurrence core is derived from wall time or from the other. Older entries without authenticated total evidence remain marked not exposed; it is not a missing measurement. user cap: native C++/ASM generation is not attempted above n=6 (native-backend-generation-cap-n6-v1).} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/result_z_external_sm_table.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/result_z_external_sm_table.tex deleted file mode 100644 index 949cde29e6..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/result_z_external_sm_table.tex +++ /dev/null @@ -1,205 +0,0 @@ -% SPDX-License-Identifier: 0BSD -% Generated by tools/performance_report/render.py; do not edit. -\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont} -\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont} -\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont} -\providecommand{\matrixfitwidth}[1]{\begingroup\sbox0{#1}\ifdim\wd0>\linewidth\resizebox{\linewidth}{!}{\usebox0}\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup} -\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}} -\providecommand{\matrixratio}[2]{\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}} -\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}} -\providecommand{\matrixnotapplicable}[1]{\textcolor{#1}{\textsc{not applicable}}} -\providecommand{\matrixnotexposed}[1]{\textcolor{#1}{\textsc{not exposed}}} -\providecommand{\matrixstaticna}[1]{\textcolor{#1}{\textsc{static N/A}}} -\providecommand{\matrixtotalevaluator}[1]{\textcolor{ReportBlue}{\texttt{T }}#1} -\providecommand{\matrixrecurrencecore}[1]{\textcolor{ReportOrange}{\texttt{C }}#1} -\providecommand{\matrixzrecurrenceclocks}[2]{\shortstack[r]{#1\\#2}} -\providecommand{\matrixwallclock}[2]{\textcolor{#1}{\texttt{W #2}}} -\providecommand{\matrixwallabsolute}[1]{\textcolor{ReportBlue}{\texttt{W }}#1} -\providecommand{\matrixruntimepair}[2]{\shortstack[l]{#1\\#2}} -\providecommand{\matrixruntimetriple}[3]{\shortstack[l]{#1\\#2\matrixpunct{ | }#3}} -\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}} -\providecommand{\matrixnaratio}[1]{\matrixpunct{(}\matrixna{#1}\matrixpunct{)}} -\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}} -\providecommand{\matrixncabsolute}[1]{#1} -\providecommand{\matrixsummaryratio}[2]{\textcolor{#1}{\texttt{x#2}}} -\providecommand{\matrixsummaryratiohighlight}[2]{\begingroup\setlength{\fboxsep}{0.9pt}\setlength{\fboxrule}{0.35pt}\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}\endgroup} -\providecommand{\matrixsummarystats}[5]{\begingroup\matrixsummaryfont\begin{tabular}[t]{@{}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}\makebox[3.6em][l]{#1}&\makebox[4.6em][l]{#2}&\makebox[3.6em][l]{#3}&\makebox[3.6em][l]{#4}&\makebox[4.2em][l]{#5}\end{tabular}\endgroup} -\providecommand{\matrixsummaryworkloads}[2]{\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}} -\clearpage -\subsection{UFO-SM dedicated \(d\bar d\to Z+\) gluon performance} -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM \(d\bar d\to Z+\) gluon ladder (block 1 of 3)} -\begingroup -\centering -\scriptsize -\setlength{\tabcolsep}{1.4pt} -\renewcommand{\arraystretch}{1.05} -\begin{tabular}{@{}r L{1.50in} R{1.26in} R{1.26in} R{1.26in} @{\hspace{0.08in}}R{1.26in} R{1.26in} R{1.26in}@{}} -\toprule -\textbf{n} & \textbf{setup} & \multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & \multicolumn{3}{c}{\textbf{all flows, single helicity}} \\ -& & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\ -\midrule -\rowcolor{refblue} -1 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -1 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -1 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -1 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -1 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -2 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -2 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -2 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -2 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -2 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -3 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -3 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -3 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -3 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -3 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\endgroup -\ReportTableNote{Original AmpliCol is the denominator only when successful and exactly linked by stored same-point evidence, directly or through current recurrence. Otherwise its status remains visible and successful pyAmpliCol values are absolute. Unverified diagnostics retain absolute clocks with a yellow marker, but never enter ratios or summaries. Compiled, eager, and recurrence rows report separate topology-replay and all-flow-union generation and runtime measurements. On-the-fly uses one compact query-local process seed for both physical workloads. Its generation entry is the absolute \texttt{[G] G+W} pair: muted G is process-seed generation and G+W adds the first cold on-the-fly evaluation. Parenthesized values are candidate/reference ratios. All-flow generation shows the absolute pyAmpliCol value without a ratio because its setup boundary differs from the reference. The wall time is the common runtime observable. Not exposed means that a successful wall measurement has no dedicated authenticated evaluator-total timing. Authenticated accumulated warmed evaluator totals appear in the eval column with enough precision to remain distinct from wall time. Its parenthesized multiplier uses the original-AmpliCol wall measurement as denominator because the legacy reference has no separate evaluator-total clock. Recurrence rows retain the independently measured narrower recurrence core in detailed evidence; it is not relabeled as evaluator total. Neither evaluator total nor recurrence core is derived from wall time or from the other. Older entries without authenticated total evidence remain marked not exposed; it is not a missing measurement. user cap: native C++/ASM generation is not attempted above n=6 (native-backend-generation-cap-n6-v1).} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM \(d\bar d\to Z+\) gluon ladder (block 2 of 3)} -\begingroup -\centering -\scriptsize -\setlength{\tabcolsep}{1.4pt} -\renewcommand{\arraystretch}{1.05} -\begin{tabular}{@{}r L{1.50in} R{1.26in} R{1.26in} R{1.26in} @{\hspace{0.08in}}R{1.26in} R{1.26in} R{1.26in}@{}} -\toprule -\textbf{n} & \textbf{setup} & \multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & \multicolumn{3}{c}{\textbf{all flows, single helicity}} \\ -& & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\ -\midrule -\rowcolor{refblue} -4 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -4 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -4 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -4 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -4 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -5 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -5 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -5 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -5 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -5 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -6 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -6 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -6 & compiled ASM O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -6 & compiled C++ O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -6 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\endgroup -\ReportTableNote{Original AmpliCol is the denominator only when successful and exactly linked by stored same-point evidence, directly or through current recurrence. Otherwise its status remains visible and successful pyAmpliCol values are absolute. Unverified diagnostics retain absolute clocks with a yellow marker, but never enter ratios or summaries. Compiled, eager, and recurrence rows report separate topology-replay and all-flow-union generation and runtime measurements. On-the-fly uses one compact query-local process seed for both physical workloads. Its generation entry is the absolute \texttt{[G] G+W} pair: muted G is process-seed generation and G+W adds the first cold on-the-fly evaluation. Parenthesized values are candidate/reference ratios. All-flow generation shows the absolute pyAmpliCol value without a ratio because its setup boundary differs from the reference. The wall time is the common runtime observable. Not exposed means that a successful wall measurement has no dedicated authenticated evaluator-total timing. Authenticated accumulated warmed evaluator totals appear in the eval column with enough precision to remain distinct from wall time. Its parenthesized multiplier uses the original-AmpliCol wall measurement as denominator because the legacy reference has no separate evaluator-total clock. Recurrence rows retain the independently measured narrower recurrence core in detailed evidence; it is not relabeled as evaluator total. Neither evaluator total nor recurrence core is derived from wall time or from the other. Older entries without authenticated total evidence remain marked not exposed; it is not a missing measurement. user cap: native C++/ASM generation is not attempted above n=6 (native-backend-generation-cap-n6-v1).} -\end{minipage} -\clearpage -\noindent\begin{minipage}{\linewidth} -\subsubsection*{UFO-SM \(d\bar d\to Z+\) gluon ladder (block 3 of 3)} -\begingroup -\centering -\scriptsize -\setlength{\tabcolsep}{1.4pt} -\renewcommand{\arraystretch}{1.05} -\begin{tabular}{@{}r L{1.50in} R{1.26in} R{1.26in} R{1.26in} @{\hspace{0.08in}}R{1.26in} R{1.26in} R{1.26in}@{}} -\toprule -\textbf{n} & \textbf{setup} & \multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & \multicolumn{3}{c}{\textbf{all flows, single helicity}} \\ -& & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{gen [s]} & \textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & \textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\ -\midrule -\rowcolor{refblue} -7 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -7 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -7 & compiled ASM O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -7 & compiled C++ O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -\rowcolor{ReportGreen!12} -7 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -7 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -7 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -7 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -8 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -8 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -8 & compiled ASM O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -8 & compiled C++ O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -\rowcolor{ReportGreen!12} -8 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -8 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -8 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -8 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\midrule[0.45pt] -\rowcolor{refblue} -9 & \AC{} reference & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixnotexposed{ReportMuted} \\ -9 & compiled JIT O1 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -9 & compiled ASM O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -9 & compiled C++ O3 & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} & \matrixstaticna{ReportMuted} \\ -\rowcolor{ReportGreen!12} -9 & compiled JIT O3 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -9 & eager-DAG JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -9 & recurrence JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\rowcolor{ReportGreen!12} -9 & on-the-fly JIT O2 & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} & \matrixstatus{ReportMuted}{N/A} \\ -\bottomrule -\end{tabular} -\endgroup -\ReportTableNote{Original AmpliCol is the denominator only when successful and exactly linked by stored same-point evidence, directly or through current recurrence. Otherwise its status remains visible and successful pyAmpliCol values are absolute. Unverified diagnostics retain absolute clocks with a yellow marker, but never enter ratios or summaries. Compiled, eager, and recurrence rows report separate topology-replay and all-flow-union generation and runtime measurements. On-the-fly uses one compact query-local process seed for both physical workloads. Its generation entry is the absolute \texttt{[G] G+W} pair: muted G is process-seed generation and G+W adds the first cold on-the-fly evaluation. Parenthesized values are candidate/reference ratios. All-flow generation shows the absolute pyAmpliCol value without a ratio because its setup boundary differs from the reference. The wall time is the common runtime observable. Not exposed means that a successful wall measurement has no dedicated authenticated evaluator-total timing. Authenticated accumulated warmed evaluator totals appear in the eval column with enough precision to remain distinct from wall time. Its parenthesized multiplier uses the original-AmpliCol wall measurement as denominator because the legacy reference has no separate evaluator-total clock. Recurrence rows retain the independently measured narrower recurrence core in detailed evidence; it is not relabeled as evaluator total. Neither evaluator total nor recurrence core is derived from wall time or from the other. Older entries without authenticated total evidence remain marked not exposed; it is not a missing measurement. user cap: native C++/ASM generation is not attempted above n=6 (native-backend-generation-cap-n6-v1).} -\end{minipage} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_full.json deleted file mode 100644 index 6ef9d5f8d1..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_compiled_builtin_sm_full","entries":[{"cell_id":"matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_lc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_lc.json deleted file mode 100644 index e2aa032bfc..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_lc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_compiled_builtin_sm_lc","entries":[{"cell_id":"matrix-compiled-builtin-sm-lc-n1-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n1-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n1-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n1-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n2-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n3-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n4-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n5-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n6-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n7-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n8-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-compiled-builtin-sm-lc-n9-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_nlc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_nlc.json deleted file mode 100644 index a7d6505199..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_builtin_sm_nlc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_compiled_builtin_sm_nlc","entries":[{"cell_id":"matrix-compiled-builtin-sm-nlc-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-builtin-sm-nlc-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"nlc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_ufo_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_ufo_sm_full.json deleted file mode 100644 index 28ac310734..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_compiled_ufo_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_compiled_ufo_sm_full","entries":[{"cell_id":"matrix-compiled-ufo-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-compiled-ufo-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_full.json deleted file mode 100644 index c0482dc1b3..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_eager_builtin_sm_full","entries":[{"cell_id":"matrix-eager-builtin-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_lc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_lc.json deleted file mode 100644 index 300584c62f..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_lc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_eager_builtin_sm_lc","entries":[{"cell_id":"matrix-eager-builtin-sm-lc-n1-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n1-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n1-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n1-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n2-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n3-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n4-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n5-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n6-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n7-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n8-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-eager-builtin-sm-lc-n9-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_nlc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_nlc.json deleted file mode 100644 index 6669da05d5..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_builtin_sm_nlc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_eager_builtin_sm_nlc","entries":[{"cell_id":"matrix-eager-builtin-sm-nlc-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-builtin-sm-nlc-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"nlc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_ufo_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_ufo_sm_full.json deleted file mode 100644 index 9398809b07..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_eager_ufo_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_eager_ufo_sm_full","entries":[{"cell_id":"matrix-eager-ufo-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-eager-ufo-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_full.json deleted file mode 100644 index eff1e7a3b2..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_on_the_fly_builtin_sm_full","entries":[{"cell_id":"matrix-on-the-fly-builtin-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_lc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_lc.json deleted file mode 100644 index 10352c3c4d..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_lc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_on_the_fly_builtin_sm_lc","entries":[{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n1-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n1-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n1-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n1-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n2-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n3-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-on-the-fly-builtin-sm-lc-n4-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_nlc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_nlc.json deleted file mode 100644 index c1d6d121b2..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_builtin_sm_nlc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_on_the_fly_builtin_sm_nlc","entries":[{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-builtin-sm-nlc-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"nlc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_ufo_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_ufo_sm_full.json deleted file mode 100644 index 48e2c99a45..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_on_the_fly_ufo_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_on_the_fly_ufo_sm_full","entries":[{"cell_id":"matrix-on-the-fly-ufo-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-on-the-fly-ufo-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_full.json deleted file mode 100644 index bc5aceec31..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_recurrence_builtin_sm_full","entries":[{"cell_id":"matrix-recurrence-builtin-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_lc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_lc.json deleted file mode 100644 index 7fc6491610..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_lc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_recurrence_builtin_sm_lc","entries":[{"cell_id":"matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n1-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n1-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n2-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n3-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n4-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n5-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n6-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n7-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n8-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-builtin-sm-lc-n9-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_nlc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_nlc.json deleted file mode 100644 index c89f92b4d3..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_builtin_sm_nlc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_recurrence_builtin_sm_nlc","entries":[{"cell_id":"matrix-recurrence-builtin-sm-nlc-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-builtin-sm-nlc-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_full.json deleted file mode 100644 index 2c9182fb76..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_recurrence_ufo_sm_full","entries":[{"cell_id":"matrix-recurrence-ufo-sm-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_lc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_lc.json deleted file mode 100644 index de72771e12..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_lc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_recurrence_ufo_sm_lc","entries":[{"cell_id":"matrix-recurrence-ufo-sm-lc-n1-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n1-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n1-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n1-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n2-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n3-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n4-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n5-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n6-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n7-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n8-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"matrix-recurrence-ufo-sm-lc-n9-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_nlc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_nlc.json deleted file mode 100644 index b7faa8ce38..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/matrix_recurrence_ufo_sm_nlc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"matrix_recurrence_ufo_sm_nlc","entries":[{"cell_id":"matrix-recurrence-ufo-sm-nlc-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"matrix-recurrence-ufo-sm-nlc-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"nlc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_full.json deleted file mode 100644 index bec9e43703..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"reference_amplicol_full","entries":[{"cell_id":"reference-amplicol-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_lc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_lc.json deleted file mode 100644 index e281c6abd1..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_lc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"reference_amplicol_lc","entries":[{"cell_id":"reference-amplicol-lc-n1-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n1-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n1-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n1-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n2-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n2-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n3-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n3-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n4-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n4-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n5-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n5-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > e+ e- e+ e- g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > e+ e- g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > e+ e- z h g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > t t~ g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > t t~ z h g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > z z g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > z z z g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"g g > g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"g g > t t~ g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"u d~ > e+ ve g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n6-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n6-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"u d~ > w+ g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > u u~ u u~ g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > u u~ s s~ g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > e+ e- e+ e- g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > u u~ s s~ c c~ g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > e+ e- g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > e+ e- z h g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > t t~ g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > t t~ z h g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > z z g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"d d~ > z z z g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"g g > g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"g g > t t~ g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"u d~ > e+ ve g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n7-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n7-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":7,"process":"u d~ > w+ g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > u u~ u u~ g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > u u~ s s~ g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > e+ e- e+ e- g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > u u~ s s~ c c~ g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > e+ e- g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > e+ e- z h g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > t t~ g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > t t~ z h g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > z z g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"d d~ > z z z g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"g g > g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"g g > t t~ g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"u d~ > e+ ve g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n8-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n8-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":8,"process":"u d~ > w+ g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-3q-identical-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-3q-identical-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > u u~ u u~ g g g g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-3q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-3q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > u u~ s s~ g g g g g","process_key":"dd_3q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-4l-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-4l-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > e+ e- e+ e- g g g g g","process_key":"dd_4l_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-4q-lines-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-4q-lines-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > u u~ s s~ c c~ g g g","process_key":"dd_4q_lines","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-epem-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-epem-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > e+ e- g g g g g g g","process_key":"dd_epem_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-epemzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-epemzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > e+ e- z h g g g g g","process_key":"dd_epemzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > t t~ g g g g g g g","process_key":"dd_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-ttzh-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-ttzh-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > t t~ z h g g g g g","process_key":"dd_ttzh_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-z-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-z-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-zz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-zz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > z z g g g g g g g","process_key":"dd_zz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-zzz-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-dd-zzz-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"d d~ > z z z g g g g g g","process_key":"dd_zzz_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-gg-gluons-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-gg-gluons-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"g g > g g g g g g g g g","process_key":"gg_gluons","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-gg-tt-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-gg-tt-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"g g > t t~ g g g g g g g","process_key":"gg_tt_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-ud-epve-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-ud-epve-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"u d~ > e+ ve g g g g g g g","process_key":"ud_epve_jets","variant":null,"workload":"selected-flow"},{"cell_id":"reference-amplicol-lc-n9-ud-w-jets-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"all-flow"},{"cell_id":"reference-amplicol-lc-n9-ud-w-jets-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":9,"process":"u d~ > w+ g g g g g g g g","process_key":"ud_w_jets","variant":null,"workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_nlc.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_nlc.json deleted file mode 100644 index 82c28e8fcf..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_amplicol_nlc.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"reference_amplicol_nlc","entries":[{"cell_id":"reference-amplicol-nlc-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-amplicol-nlc-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"nlc","backend":"fortran","execution_mode":"amplicol","jit_optimization_level":null,"model":null}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_madgraph_full.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_madgraph_full.json deleted file mode 100644 index b5b1a59584..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/reference_madgraph_full.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"reference_madgraph_full","entries":[{"cell_id":"reference-madgraph-full-n1-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n1-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":1,"process":"u d~ > w+","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > e+ e-","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > t t~","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z z","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"g g > g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"g g > t t~","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"u d~ > e+ ve","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n2-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"u d~ > w+ g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > e+ e- g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > t t~ g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z z z","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"g g > g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"g g > t t~ g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"u d~ > e+ ve g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n3-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"u d~ > w+ g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ u u~","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > u u~ s s~","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- e+ e-","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > e+ e- z h","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > t t~ z h","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z z z g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"g g > g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"g g > t t~ g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"u d~ > e+ ve g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n4-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"u d~ > w+ g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ u u~ g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > u u~ s s~ g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-4l-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- e+ e- g","process_key":"dd_4l_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-epem-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- g g g","process_key":"dd_epem_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-epemzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > e+ e- z h g","process_key":"dd_epemzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ g g g","process_key":"dd_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-ttzh-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > t t~ z h g","process_key":"dd_ttzh_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-z-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-zz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z g g g","process_key":"dd_zz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-dd-zzz-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z z z g g","process_key":"dd_zzz_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-gg-gluons-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"g g > g g g g g","process_key":"gg_gluons","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-gg-tt-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"g g > t t~ g g g","process_key":"gg_tt_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-ud-epve-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"u d~ > e+ ve g g g","process_key":"ud_epve_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n5-ud-w-jets-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"u d~ > w+ g g g g","process_key":"ud_w_jets","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n6-dd-3q-identical-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ u u~ g g","process_key":"dd_3q_identical_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n6-dd-3q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ g g","process_key":"dd_3q_lines","variant":null,"workload":"contracted"},{"cell_id":"reference-madgraph-full-n6-dd-4q-lines-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > u u~ s s~ c c~","process_key":"dd_4q_lines","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"fortran","execution_mode":"madgraph","jit_optimization_level":null,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/report-cache.schema.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/report-cache.schema.json deleted file mode 100644 index 8d0b133880..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/report-cache.schema.json +++ /dev/null @@ -1 +0,0 @@ -{"$id":"https://pyamplicol.dev/schema/report-cache-v5.json","$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{"$schema":{"const":"./report-cache.schema.json"},"dataset_id":{"minLength":1,"type":"string"},"entries":{"items":{"additionalProperties":false,"properties":{"cell_id":{"minLength":1,"type":"string"},"measurement":{"additionalProperties":false,"allOf":[{"if":{"properties":{"status":{"const":"ok"}},"required":["status"]},"then":{"properties":{"validation":{"properties":{"direct_agreements":{"items":{"oneOf":[{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-direct-agreement-v1"},"absolute_difference":{"minimum":0,"type":"number"},"absolute_tolerance":{"minimum":0,"type":"number"},"baseline":{"type":"number"},"baseline_cell_id":{"minLength":1,"type":"string"},"candidate":{"type":"number"},"candidate_cell_id":{"minLength":1,"type":"string"},"edge_kind":{"enum":["builtin-ufo-recurrence","z-recurrence-cross-mode","lc-cross-layout-component","lc-legacy-pyamplicol-component","madgraph-full-colour"]},"relative_difference":{"minimum":0,"type":"number"},"relative_tolerance":{"minimum":0,"type":"number"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"value_kind":{"enum":["matrix_element","lc_common_component"]}},"required":["abi","edge_kind","value_kind","baseline_cell_id","candidate_cell_id","status","candidate","baseline","absolute_difference","relative_difference","relative_tolerance","absolute_tolerance"],"type":"object"},{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-direct-agreement-v2"},"absolute_difference":{"minimum":0,"type":"number"},"baseline":{"type":"number"},"baseline_cell_id":{"minLength":1,"type":"string"},"baseline_scale":{"minimum":0,"type":"number"},"baseline_scale_source":{"minLength":1,"type":"string"},"candidate":{"type":"number"},"candidate_cell_id":{"minLength":1,"type":"string"},"candidate_scale":{"minimum":0,"type":"number"},"candidate_scale_source":{"minLength":1,"type":"string"},"comparison_binding":{"minProperties":1,"type":"object"},"comparison_scale":{"minimum":0,"type":"number"},"conditioned_residual":{"minimum":0,"type":"number"},"edge_kind":{"enum":["builtin-ufo-recurrence","z-recurrence-cross-mode","lc-cross-layout-component","lc-legacy-pyamplicol-component","madgraph-full-colour"]},"error_bound":{"minimum":0,"type":"number"},"relative_difference":{"minimum":0,"type":"number"},"relative_tolerance":{"minimum":0,"type":"number"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"value_kind":{"enum":["matrix_element","lc_common_component"]}},"required":["abi","edge_kind","value_kind","baseline_cell_id","candidate_cell_id","status","candidate","baseline","candidate_scale","baseline_scale","candidate_scale_source","baseline_scale_source","comparison_scale","absolute_difference","relative_difference","conditioned_residual","error_bound","relative_tolerance","comparison_binding"],"type":"object"}]},"type":"array"},"independent_authority":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-independent-authority-v1"},"expected_cell_ids":{"items":{"minLength":1,"type":"string"},"type":"array","uniqueItems":true},"reason":{"minLength":1,"type":"string"},"same_artifact_diagnostics_are_authority":{"const":false},"selected_cell_id":{"type":["string","null"]},"status":{"enum":["unavailable","verified","mismatch","incompatible"]}},"required":["abi","expected_cell_ids","selected_cell_id","status","reason","same_artifact_diagnostics_are_authority"],"type":"object"},"lc_common_component":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-lc-common-component-v1"},"cell_id":{"minLength":1,"type":"string"},"color_flow_ids":{"items":{"minLength":1,"type":"string"},"minItems":1,"type":"array","uniqueItems":true},"helicity_ids":{"items":{"minLength":1,"type":"string"},"minItems":1,"type":"array","uniqueItems":true},"point_digest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"value":{"type":"number"}},"required":["abi","cell_id","value","point_digest","helicity_ids","color_flow_ids"],"type":"object"},"madgraph_comparison":{"type":"object"},"on_the_fly_recurrence_authority":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-on-the-fly-recurrence-authority-validation-v1"},"after_clear":{"additionalProperties":false,"properties":{"candidate_resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"candidate_resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"comparison":{"additionalProperties":false,"properties":{"authority_cell_id":{"minLength":1,"type":"string"},"resolved_components":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"component_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","component_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"total":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"}},"required":["authority_cell_id","total","resolved_components"],"type":"object"}},"required":["candidate_total_source_sha256","candidate_resolved_total_source_sha256","candidate_resolved_ordering_sha256","candidate_resolved_source_sha256","candidate_resolved_sum","comparison"],"type":"object"},"authority":{"additionalProperties":false,"properties":{"artifact_id":{"pattern":"^[0-9a-f]{64}$","type":"string"},"cell_id":{"minLength":1,"type":"string"},"resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"}},"required":["cell_id","artifact_id","total_source_sha256","resolved_total_source_sha256","resolved_ordering_sha256","resolved_source_sha256","resolved_sum"],"type":"object"},"before_clear":{"additionalProperties":false,"properties":{"candidate_resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"candidate_resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"comparison":{"additionalProperties":false,"properties":{"authority_cell_id":{"minLength":1,"type":"string"},"resolved_components":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"component_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","component_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"total":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"}},"required":["authority_cell_id","total","resolved_components"],"type":"object"}},"required":["candidate_total_source_sha256","candidate_resolved_total_source_sha256","candidate_resolved_ordering_sha256","candidate_resolved_source_sha256","candidate_resolved_sum","comparison"],"type":"object"},"candidate_artifact_id":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_cell_id":{"minLength":1,"type":"string"},"lifecycle":{"additionalProperties":false,"properties":{"authority_artifact_loaded_only":{"const":true},"candidate_loaded_before_validation":{"const":true},"clear_call_count":{"const":2},"final_clear_before_profile":{"const":true},"validated_after_clear":{"const":true},"validated_before_clear":{"const":true}},"required":["authority_artifact_loaded_only","candidate_loaded_before_validation","validated_before_clear","validated_after_clear","clear_call_count","final_clear_before_profile"],"type":"object"},"point_count":{"minimum":1,"type":"integer"},"point_digest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"precision_digits":{"const":16},"relative_tolerance":{"const":1e-12},"resolved_check_count":{"minimum":1,"type":"integer"},"resolved_component_count":{"minimum":1,"type":"integer"},"selector_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"status":{"const":"ok"},"workload":{"enum":["selected-flow","all-flow"]}},"required":["abi","status","candidate_cell_id","candidate_artifact_id","workload","precision_digits","relative_tolerance","point_digest","selector_sha256","point_count","resolved_component_count","resolved_check_count","authority","before_clear","after_clear","lifecycle"],"type":"object"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]}},"required":["direct_agreements"],"type":"object"}}}},{"if":{"properties":{"status":{"const":"unverified"}},"required":["status"]},"then":{"properties":{"failure":{"type":"object"},"validation":{"properties":{"direct_agreements":{"items":{"oneOf":[{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-direct-agreement-v1"},"absolute_difference":{"minimum":0,"type":"number"},"absolute_tolerance":{"minimum":0,"type":"number"},"baseline":{"type":"number"},"baseline_cell_id":{"minLength":1,"type":"string"},"candidate":{"type":"number"},"candidate_cell_id":{"minLength":1,"type":"string"},"edge_kind":{"enum":["builtin-ufo-recurrence","z-recurrence-cross-mode","lc-cross-layout-component","lc-legacy-pyamplicol-component","madgraph-full-colour"]},"relative_difference":{"minimum":0,"type":"number"},"relative_tolerance":{"minimum":0,"type":"number"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"value_kind":{"enum":["matrix_element","lc_common_component"]}},"required":["abi","edge_kind","value_kind","baseline_cell_id","candidate_cell_id","status","candidate","baseline","absolute_difference","relative_difference","relative_tolerance","absolute_tolerance"],"type":"object"},{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-direct-agreement-v2"},"absolute_difference":{"minimum":0,"type":"number"},"baseline":{"type":"number"},"baseline_cell_id":{"minLength":1,"type":"string"},"baseline_scale":{"minimum":0,"type":"number"},"baseline_scale_source":{"minLength":1,"type":"string"},"candidate":{"type":"number"},"candidate_cell_id":{"minLength":1,"type":"string"},"candidate_scale":{"minimum":0,"type":"number"},"candidate_scale_source":{"minLength":1,"type":"string"},"comparison_binding":{"minProperties":1,"type":"object"},"comparison_scale":{"minimum":0,"type":"number"},"conditioned_residual":{"minimum":0,"type":"number"},"edge_kind":{"enum":["builtin-ufo-recurrence","z-recurrence-cross-mode","lc-cross-layout-component","lc-legacy-pyamplicol-component","madgraph-full-colour"]},"error_bound":{"minimum":0,"type":"number"},"relative_difference":{"minimum":0,"type":"number"},"relative_tolerance":{"minimum":0,"type":"number"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"value_kind":{"enum":["matrix_element","lc_common_component"]}},"required":["abi","edge_kind","value_kind","baseline_cell_id","candidate_cell_id","status","candidate","baseline","candidate_scale","baseline_scale","candidate_scale_source","baseline_scale_source","comparison_scale","absolute_difference","relative_difference","conditioned_residual","error_bound","relative_tolerance","comparison_binding"],"type":"object"}]},"type":"array"},"independent_authority":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-independent-authority-v1"},"expected_cell_ids":{"items":{"minLength":1,"type":"string"},"type":"array","uniqueItems":true},"reason":{"minLength":1,"type":"string"},"same_artifact_diagnostics_are_authority":{"const":false},"selected_cell_id":{"type":["string","null"]},"status":{"enum":["unavailable","verified","mismatch","incompatible"]}},"required":["abi","expected_cell_ids","selected_cell_id","status","reason","same_artifact_diagnostics_are_authority"],"type":"object"},"lc_common_component":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-lc-common-component-v1"},"cell_id":{"minLength":1,"type":"string"},"color_flow_ids":{"items":{"minLength":1,"type":"string"},"minItems":1,"type":"array","uniqueItems":true},"helicity_ids":{"items":{"minLength":1,"type":"string"},"minItems":1,"type":"array","uniqueItems":true},"point_digest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"value":{"type":"number"}},"required":["abi","cell_id","value","point_digest","helicity_ids","color_flow_ids"],"type":"object"},"madgraph_comparison":{"type":"object"},"on_the_fly_recurrence_authority":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-on-the-fly-recurrence-authority-validation-v1"},"after_clear":{"additionalProperties":false,"properties":{"candidate_resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"candidate_resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"comparison":{"additionalProperties":false,"properties":{"authority_cell_id":{"minLength":1,"type":"string"},"resolved_components":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"component_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","component_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"total":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"}},"required":["authority_cell_id","total","resolved_components"],"type":"object"}},"required":["candidate_total_source_sha256","candidate_resolved_total_source_sha256","candidate_resolved_ordering_sha256","candidate_resolved_source_sha256","candidate_resolved_sum","comparison"],"type":"object"},"authority":{"additionalProperties":false,"properties":{"artifact_id":{"pattern":"^[0-9a-f]{64}$","type":"string"},"cell_id":{"minLength":1,"type":"string"},"resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"}},"required":["cell_id","artifact_id","total_source_sha256","resolved_total_source_sha256","resolved_ordering_sha256","resolved_source_sha256","resolved_sum"],"type":"object"},"before_clear":{"additionalProperties":false,"properties":{"candidate_resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"candidate_resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"comparison":{"additionalProperties":false,"properties":{"authority_cell_id":{"minLength":1,"type":"string"},"resolved_components":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"component_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","component_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"total":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"}},"required":["authority_cell_id","total","resolved_components"],"type":"object"}},"required":["candidate_total_source_sha256","candidate_resolved_total_source_sha256","candidate_resolved_ordering_sha256","candidate_resolved_source_sha256","candidate_resolved_sum","comparison"],"type":"object"},"candidate_artifact_id":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_cell_id":{"minLength":1,"type":"string"},"lifecycle":{"additionalProperties":false,"properties":{"authority_artifact_loaded_only":{"const":true},"candidate_loaded_before_validation":{"const":true},"clear_call_count":{"const":2},"final_clear_before_profile":{"const":true},"validated_after_clear":{"const":true},"validated_before_clear":{"const":true}},"required":["authority_artifact_loaded_only","candidate_loaded_before_validation","validated_before_clear","validated_after_clear","clear_call_count","final_clear_before_profile"],"type":"object"},"point_count":{"minimum":1,"type":"integer"},"point_digest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"precision_digits":{"const":16},"relative_tolerance":{"const":1e-12},"resolved_check_count":{"minimum":1,"type":"integer"},"resolved_component_count":{"minimum":1,"type":"integer"},"selector_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"status":{"const":"ok"},"workload":{"enum":["selected-flow","all-flow"]}},"required":["abi","status","candidate_cell_id","candidate_artifact_id","workload","precision_digits","relative_tolerance","point_digest","selector_sha256","point_count","resolved_component_count","resolved_check_count","authority","before_clear","after_clear","lifecycle"],"type":"object"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]}},"required":["status","direct_agreements","independent_authority","resolved_sum","high_precision_resolved_sum","high_precision","precision_diagnostic"],"type":"object"}}}}],"properties":{"artifact":{"type":["object","null"]},"execution_seconds_per_point":{"minimum":0,"type":["number","null"]},"failure":{"type":["object","null"]},"generation_seconds":{"minimum":0,"type":["number","null"]},"matrix_element":{"type":["number","string","null"]},"provenance":{"oneOf":[{"type":"null"},{"properties":{"generation_timer_excludes_model_preparation":{"const":true},"runtime_load_included_in_cold_warmup":{"const":false},"runtime_profile":{"dependentRequired":{"cold_warmup_acceptance_eligible":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_batch_size":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_elapsed_seconds":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_point_count":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_ratio_eligible":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_run_count":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_cold_before_first_evaluation":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_freshness":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_retained_after_first_evaluation":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_retained_before_first_evaluation":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_state_after":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_state_before":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_runtime_state_evidence":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_timer_source":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"],"cold_warmup_timing_scope":["cold_warmup_acceptance_eligible","cold_warmup_batch_size","cold_warmup_elapsed_seconds","cold_warmup_point_count","cold_warmup_ratio_eligible","cold_warmup_run_count","cold_warmup_runtime_cold_before_first_evaluation","cold_warmup_runtime_freshness","cold_warmup_runtime_retained_after_first_evaluation","cold_warmup_runtime_retained_before_first_evaluation","cold_warmup_runtime_state_after","cold_warmup_runtime_state_before","cold_warmup_runtime_state_evidence","cold_warmup_timer_source","cold_warmup_timing_scope","first_warmup_run_outer_wall_seconds","warmup_batch_size","warmup_configured_run_count","warmup_elapsed_seconds","warmup_point_count","warmup_run_outer_wall_seconds","warmup_timer_source","warmup_timing_scope"]},"properties":{"cold_warmup_acceptance_eligible":{"const":false},"cold_warmup_batch_size":{"minimum":1,"type":"integer"},"cold_warmup_elapsed_seconds":{"exclusiveMinimum":0,"type":"number"},"cold_warmup_point_count":{"minimum":1,"type":"integer"},"cold_warmup_ratio_eligible":{"const":false},"cold_warmup_run_count":{"const":1},"cold_warmup_runtime_cold_before_first_evaluation":{"type":"boolean"},"cold_warmup_runtime_freshness":{"enum":["authenticated-already-retained","authenticated-cold"]},"cold_warmup_runtime_retained_after_first_evaluation":{"const":true},"cold_warmup_runtime_retained_before_first_evaluation":{"type":"boolean"},"cold_warmup_runtime_state_after":{"additionalProperties":false,"properties":{"active_family_union_census":{"oneOf":[{"type":"null"},{"additionalProperties":false,"properties":{"basis":{"const":"shared-query-family-union-v1"},"query_count":{"minimum":0,"type":"integer"},"scope":{"const":"active-family-union"},"union_amplitude_destination_count":{"minimum":0,"type":"integer"},"union_closure_executor_call_groups":{"minimum":0,"type":"integer"},"union_closure_rows":{"minimum":0,"type":"integer"},"union_contribution_executor_call_groups":{"minimum":0,"type":"integer"},"union_contribution_rows":{"minimum":0,"type":"integer"},"union_finalization_executor_call_groups":{"minimum":0,"type":"integer"},"union_finalization_rows":{"minimum":0,"type":"integer"},"union_source_executor_call_groups":{"minimum":0,"type":"integer"},"union_source_rows":{"minimum":0,"type":"integer"},"union_unique_current_component_count":{"minimum":0,"type":"integer"},"union_unique_current_count":{"minimum":0,"type":"integer"}},"required":["basis","query_count","scope","union_amplitude_destination_count","union_closure_executor_call_groups","union_closure_rows","union_contribution_executor_call_groups","union_contribution_rows","union_finalization_executor_call_groups","union_finalization_rows","union_source_executor_call_groups","union_source_rows","union_unique_current_component_count","union_unique_current_count"],"type":"object"}]},"family_cache_limit":{"const":1},"family_cache_policy":{"const":"last-family-only"},"kind":{"const":"rusticol-on-the-fly-runtime-state-census-v1"},"pending_family_count":{"minimum":0,"type":"integer"},"process_id":{"minLength":1,"type":"string"},"process_preparation_count":{"minimum":0,"type":"integer"},"retained_amplitude_destination_count":{"minimum":0,"type":"integer"},"retained_embedded_lookup_key_count":{"minimum":0,"type":"integer"},"retained_executor_handle_count":{"minimum":0,"type":"integer"},"retained_family_count":{"maximum":1,"minimum":0,"type":"integer"},"retained_query_local_trace_count":{"minimum":0,"type":"integer"},"retained_request_count":{"minimum":0,"type":"integer"},"retained_selection_count":{"minimum":0,"type":"integer"},"semantic_executor_binding_count":{"minimum":0,"type":"integer"}},"required":["active_family_union_census","family_cache_limit","family_cache_policy","kind","pending_family_count","process_id","process_preparation_count","retained_amplitude_destination_count","retained_embedded_lookup_key_count","retained_executor_handle_count","retained_family_count","retained_query_local_trace_count","retained_request_count","retained_selection_count","semantic_executor_binding_count"],"type":"object"},"cold_warmup_runtime_state_before":{"additionalProperties":false,"properties":{"active_family_union_census":{"oneOf":[{"type":"null"},{"additionalProperties":false,"properties":{"basis":{"const":"shared-query-family-union-v1"},"query_count":{"minimum":0,"type":"integer"},"scope":{"const":"active-family-union"},"union_amplitude_destination_count":{"minimum":0,"type":"integer"},"union_closure_executor_call_groups":{"minimum":0,"type":"integer"},"union_closure_rows":{"minimum":0,"type":"integer"},"union_contribution_executor_call_groups":{"minimum":0,"type":"integer"},"union_contribution_rows":{"minimum":0,"type":"integer"},"union_finalization_executor_call_groups":{"minimum":0,"type":"integer"},"union_finalization_rows":{"minimum":0,"type":"integer"},"union_source_executor_call_groups":{"minimum":0,"type":"integer"},"union_source_rows":{"minimum":0,"type":"integer"},"union_unique_current_component_count":{"minimum":0,"type":"integer"},"union_unique_current_count":{"minimum":0,"type":"integer"}},"required":["basis","query_count","scope","union_amplitude_destination_count","union_closure_executor_call_groups","union_closure_rows","union_contribution_executor_call_groups","union_contribution_rows","union_finalization_executor_call_groups","union_finalization_rows","union_source_executor_call_groups","union_source_rows","union_unique_current_component_count","union_unique_current_count"],"type":"object"}]},"family_cache_limit":{"const":1},"family_cache_policy":{"const":"last-family-only"},"kind":{"const":"rusticol-on-the-fly-runtime-state-census-v1"},"pending_family_count":{"minimum":0,"type":"integer"},"process_id":{"minLength":1,"type":"string"},"process_preparation_count":{"minimum":0,"type":"integer"},"retained_amplitude_destination_count":{"minimum":0,"type":"integer"},"retained_embedded_lookup_key_count":{"minimum":0,"type":"integer"},"retained_executor_handle_count":{"minimum":0,"type":"integer"},"retained_family_count":{"maximum":1,"minimum":0,"type":"integer"},"retained_query_local_trace_count":{"minimum":0,"type":"integer"},"retained_request_count":{"minimum":0,"type":"integer"},"retained_selection_count":{"minimum":0,"type":"integer"},"semantic_executor_binding_count":{"minimum":0,"type":"integer"}},"required":["active_family_union_census","family_cache_limit","family_cache_policy","kind","pending_family_count","process_id","process_preparation_count","retained_amplitude_destination_count","retained_embedded_lookup_key_count","retained_executor_handle_count","retained_family_count","retained_query_local_trace_count","retained_request_count","retained_selection_count","semantic_executor_binding_count"],"type":"object"},"cold_warmup_runtime_state_evidence":{"const":"authenticated-native-otf-census-v1"},"cold_warmup_timer_source":{"const":"python_outer_time.perf_counter"},"cold_warmup_timing_scope":{"const":"one initial requested-selector Runtime evaluation on the full benchmark batch; artifact generation and Runtime/artifact load are excluded"},"first_warmup_run_outer_wall_seconds":{"minimum":0,"type":["number","null"]},"warmup_batch_size":{"minimum":1,"type":"integer"},"warmup_configured_run_count":{"minimum":0,"type":"integer"},"warmup_elapsed_seconds":{"minimum":0,"type":"number"},"warmup_point_count":{"minimum":0,"type":"integer"},"warmup_run_outer_wall_seconds":{"items":{"minimum":0,"type":"number"},"type":"array"},"warmup_timer_source":{"const":"python_outer_time.perf_counter"},"warmup_timing_scope":{"const":"configured benchmark warm-up iteration outer wall; includes the headline evaluation and optional native-profile warm-up; artifact generation and Runtime/artifact load are excluded"}},"type":"object"}},"type":"object"}]},"relative_standard_error":{"minimum":0,"type":["number","null"]},"resources":{"type":["object","null"]},"sample_count":{"minimum":1,"type":["integer","null"]},"selector_contract":{"type":["object","null"]},"standard_error_seconds_per_point":{"minimum":0,"type":["number","null"]},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"validation":{"oneOf":[{"type":"null"},{"properties":{"direct_agreements":{"items":{"oneOf":[{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-direct-agreement-v1"},"absolute_difference":{"minimum":0,"type":"number"},"absolute_tolerance":{"minimum":0,"type":"number"},"baseline":{"type":"number"},"baseline_cell_id":{"minLength":1,"type":"string"},"candidate":{"type":"number"},"candidate_cell_id":{"minLength":1,"type":"string"},"edge_kind":{"enum":["builtin-ufo-recurrence","z-recurrence-cross-mode","lc-cross-layout-component","lc-legacy-pyamplicol-component","madgraph-full-colour"]},"relative_difference":{"minimum":0,"type":"number"},"relative_tolerance":{"minimum":0,"type":"number"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"value_kind":{"enum":["matrix_element","lc_common_component"]}},"required":["abi","edge_kind","value_kind","baseline_cell_id","candidate_cell_id","status","candidate","baseline","absolute_difference","relative_difference","relative_tolerance","absolute_tolerance"],"type":"object"},{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-direct-agreement-v2"},"absolute_difference":{"minimum":0,"type":"number"},"baseline":{"type":"number"},"baseline_cell_id":{"minLength":1,"type":"string"},"baseline_scale":{"minimum":0,"type":"number"},"baseline_scale_source":{"minLength":1,"type":"string"},"candidate":{"type":"number"},"candidate_cell_id":{"minLength":1,"type":"string"},"candidate_scale":{"minimum":0,"type":"number"},"candidate_scale_source":{"minLength":1,"type":"string"},"comparison_binding":{"minProperties":1,"type":"object"},"comparison_scale":{"minimum":0,"type":"number"},"conditioned_residual":{"minimum":0,"type":"number"},"edge_kind":{"enum":["builtin-ufo-recurrence","z-recurrence-cross-mode","lc-cross-layout-component","lc-legacy-pyamplicol-component","madgraph-full-colour"]},"error_bound":{"minimum":0,"type":"number"},"relative_difference":{"minimum":0,"type":"number"},"relative_tolerance":{"minimum":0,"type":"number"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]},"value_kind":{"enum":["matrix_element","lc_common_component"]}},"required":["abi","edge_kind","value_kind","baseline_cell_id","candidate_cell_id","status","candidate","baseline","candidate_scale","baseline_scale","candidate_scale_source","baseline_scale_source","comparison_scale","absolute_difference","relative_difference","conditioned_residual","error_bound","relative_tolerance","comparison_binding"],"type":"object"}]},"type":"array"},"independent_authority":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-independent-authority-v1"},"expected_cell_ids":{"items":{"minLength":1,"type":"string"},"type":"array","uniqueItems":true},"reason":{"minLength":1,"type":"string"},"same_artifact_diagnostics_are_authority":{"const":false},"selected_cell_id":{"type":["string","null"]},"status":{"enum":["unavailable","verified","mismatch","incompatible"]}},"required":["abi","expected_cell_ids","selected_cell_id","status","reason","same_artifact_diagnostics_are_authority"],"type":"object"},"lc_common_component":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-lc-common-component-v1"},"cell_id":{"minLength":1,"type":"string"},"color_flow_ids":{"items":{"minLength":1,"type":"string"},"minItems":1,"type":"array","uniqueItems":true},"helicity_ids":{"items":{"minLength":1,"type":"string"},"minItems":1,"type":"array","uniqueItems":true},"point_digest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"value":{"type":"number"}},"required":["abi","cell_id","value","point_digest","helicity_ids","color_flow_ids"],"type":"object"},"madgraph_comparison":{"type":"object"},"on_the_fly_recurrence_authority":{"additionalProperties":false,"properties":{"abi":{"const":"pyamplicol-report-on-the-fly-recurrence-authority-validation-v1"},"after_clear":{"additionalProperties":false,"properties":{"candidate_resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"candidate_resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"comparison":{"additionalProperties":false,"properties":{"authority_cell_id":{"minLength":1,"type":"string"},"resolved_components":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"component_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","component_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"total":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"}},"required":["authority_cell_id","total","resolved_components"],"type":"object"}},"required":["candidate_total_source_sha256","candidate_resolved_total_source_sha256","candidate_resolved_ordering_sha256","candidate_resolved_source_sha256","candidate_resolved_sum","comparison"],"type":"object"},"authority":{"additionalProperties":false,"properties":{"artifact_id":{"pattern":"^[0-9a-f]{64}$","type":"string"},"cell_id":{"minLength":1,"type":"string"},"resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"}},"required":["cell_id","artifact_id","total_source_sha256","resolved_total_source_sha256","resolved_ordering_sha256","resolved_source_sha256","resolved_sum"],"type":"object"},"before_clear":{"additionalProperties":false,"properties":{"candidate_resolved_ordering_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_resolved_sum":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"candidate_resolved_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_total_source_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"comparison":{"additionalProperties":false,"properties":{"authority_cell_id":{"minLength":1,"type":"string"},"resolved_components":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"component_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","component_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"},"total":{"additionalProperties":false,"properties":{"check_count":{"minimum":1,"type":"integer"},"maximum_absolute_delta":{"minimum":0,"type":"number"},"maximum_conditioned_residual":{"minimum":0,"type":"number"}},"required":["check_count","maximum_conditioned_residual","maximum_absolute_delta"],"type":"object"}},"required":["authority_cell_id","total","resolved_components"],"type":"object"}},"required":["candidate_total_source_sha256","candidate_resolved_total_source_sha256","candidate_resolved_ordering_sha256","candidate_resolved_source_sha256","candidate_resolved_sum","comparison"],"type":"object"},"candidate_artifact_id":{"pattern":"^[0-9a-f]{64}$","type":"string"},"candidate_cell_id":{"minLength":1,"type":"string"},"lifecycle":{"additionalProperties":false,"properties":{"authority_artifact_loaded_only":{"const":true},"candidate_loaded_before_validation":{"const":true},"clear_call_count":{"const":2},"final_clear_before_profile":{"const":true},"validated_after_clear":{"const":true},"validated_before_clear":{"const":true}},"required":["authority_artifact_loaded_only","candidate_loaded_before_validation","validated_before_clear","validated_after_clear","clear_call_count","final_clear_before_profile"],"type":"object"},"point_count":{"minimum":1,"type":"integer"},"point_digest":{"pattern":"^[0-9a-f]{64}$","type":"string"},"precision_digits":{"const":16},"relative_tolerance":{"const":1e-12},"resolved_check_count":{"minimum":1,"type":"integer"},"resolved_component_count":{"minimum":1,"type":"integer"},"selector_sha256":{"pattern":"^[0-9a-f]{64}$","type":"string"},"status":{"const":"ok"},"workload":{"enum":["selected-flow","all-flow"]}},"required":["abi","status","candidate_cell_id","candidate_artifact_id","workload","precision_digits","relative_tolerance","point_digest","selector_sha256","point_count","resolved_component_count","resolved_check_count","authority","before_clear","after_clear","lifecycle"],"type":"object"},"status":{"enum":["not_available","ok","failed","timeout","memory_limit","skip","validation_failed","unverified","error","unsupported"]}},"type":"object"}]},"wall_seconds_per_point":{"minimum":0,"type":["number","null"]}},"required":["status","generation_seconds","wall_seconds_per_point","execution_seconds_per_point","matrix_element","sample_count","standard_error_seconds_per_point","relative_standard_error","artifact","selector_contract","validation","resources","provenance","failure"],"type":"object"},"measurement_spec":{"type":"object"},"n_final":{"minimum":1,"type":"integer"},"process":{"minLength":1,"type":"string"},"process_key":{"type":["string","null"]},"variant":{"type":["string","null"]},"workload":{"enum":["selected-flow","all-flow","contracted"]}},"required":["cell_id","process_key","process","n_final","variant","workload","measurement_spec","measurement"],"type":"object"},"type":"array"},"kind":{"const":"performance_measurements"},"measurement_specs":{"items":{"type":"object"},"type":"array"},"report_version":{"const":"0.3.0"},"schema_version":{"const":5}},"required":["$schema","schema_version","report_version","kind","dataset_id","measurement_specs","entries"],"title":"pyAmpliCol performance cache","type":"object"} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_contact.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_contact.json deleted file mode 100644 index 4fccc05d98..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_contact.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"scalar_contact","entries":[{"cell_id":"scalar-contact-n2-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":2,"process":"scalar_0 scalar_0 > scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"},{"cell_id":"scalar-contact-n3-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":3,"process":"scalar_0 scalar_0 > scalar_0 scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"},{"cell_id":"scalar-contact-n4-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":4,"process":"scalar_0 scalar_0 > scalar_0 scalar_0 scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"},{"cell_id":"scalar-contact-n5-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":5,"process":"scalar_0 scalar_0 > scalar_0 scalar_0 scalar_0 scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"},{"cell_id":"scalar-contact-n6-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":6,"process":"scalar_0 scalar_0 > scalar_0 scalar_0 scalar_0 scalar_0 scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"},{"cell_id":"scalar-contact-n7-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":7,"process":"scalar_0 scalar_0 > scalar_0 scalar_0 scalar_0 scalar_0 scalar_0 scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"},{"cell_id":"scalar-contact-n8-scalar-contact-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"},"n_final":8,"process":"scalar_0 scalar_0 > scalar_0 scalar_0 scalar_0 scalar_0 scalar_0 scalar_0 scalar_0 scalar_0","process_key":"scalar_contact","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_contact"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_gravity.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_gravity.json deleted file mode 100644 index f4ea7c5afd..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/scalar_gravity.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"scalar_gravity","entries":[{"cell_id":"scalar-gravity-n2-scalar-gravity-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_gravity"},"n_final":2,"process":"scalar_0 scalar_0 > graviton graviton","process_key":"scalar_gravity","variant":null,"workload":"contracted"},{"cell_id":"scalar-gravity-n3-scalar-gravity-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_gravity"},"n_final":3,"process":"scalar_0 scalar_0 > graviton graviton graviton","process_key":"scalar_gravity","variant":null,"workload":"contracted"},{"cell_id":"scalar-gravity-n4-scalar-gravity-contracted","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_gravity"},"n_final":4,"process":"scalar_0 scalar_0 > graviton graviton graviton graviton","process_key":"scalar_gravity","variant":null,"workload":"contracted"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"full","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"scalar_gravity"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/z_builtin_sm.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/z_builtin_sm.json deleted file mode 100644 index 12340896f4..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/z_builtin_sm.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"z_builtin_sm","entries":[{"cell_id":"z-builtin-sm-n1-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n1-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n2-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n3-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n4-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n5-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n6-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n7-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n8-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-builtin-sm-n9-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"builtin_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"builtin_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"builtin_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"builtin_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"builtin_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"builtin_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/results/z_external_sm.json b/pyamplicol/src/pyamplicol/_profiling_campaign/results/z_external_sm.json deleted file mode 100644 index d55bbd3db6..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/results/z_external_sm.json +++ /dev/null @@ -1 +0,0 @@ -{"$schema":"./report-cache.schema.json","dataset_id":"z_external_sm","entries":[{"cell_id":"z-external-sm-n1-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n1-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":1,"process":"d d~ > z","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n2-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":2,"process":"d d~ > z g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n3-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":3,"process":"d d~ > z g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n4-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":4,"process":"d d~ > z g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n5-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":5,"process":"d d~ > z g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n6-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":6,"process":"d d~ > z g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n7-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":7,"process":"d d~ > z g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n8-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":8,"process":"d d~ > z g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-asm-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-asm-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"asm_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-cpp-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-cpp-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"cpp_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-eager-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-eager-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"eager_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-jit-o1-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-jit-o1-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o1","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-jit-o3-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-jit-o3-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"jit_o3","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-on-the-fly-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-on-the-fly-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"on_the_fly_jit_o2","workload":"selected-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-recurrence-jit-o2-all-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"all-flow"},{"cell_id":"z-external-sm-n9-dd-z-jets-recurrence-jit-o2-selected-flow","measurement":{"artifact":null,"execution_seconds_per_point":null,"failure":null,"generation_seconds":null,"matrix_element":null,"provenance":null,"relative_standard_error":null,"resources":null,"sample_count":null,"selector_contract":null,"standard_error_seconds_per_point":null,"status":"not_available","validation":null,"wall_seconds_per_point":null},"measurement_spec":{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"},"n_final":9,"process":"d d~ > z g g g g g g g g","process_key":"dd_z_jets","variant":"recurrence_jit_o2","workload":"selected-flow"}],"kind":"performance_measurements","measurement_specs":[{"accuracy":"lc","backend":"asm","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},{"accuracy":"lc","backend":"cpp","execution_mode":"compiled","jit_optimization_level":null,"model":"ufo_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":1,"model":"ufo_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"compiled","jit_optimization_level":3,"model":"ufo_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"eager","jit_optimization_level":2,"model":"ufo_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"on-the-fly","jit_optimization_level":2,"model":"ufo_sm"},{"accuracy":"lc","backend":"jit","execution_mode":"recurrence","jit_optimization_level":2,"model":"ufo_sm"}],"report_version":"0.3.0","schema_version":5} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/section_eager_execution.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/section_eager_execution.tex deleted file mode 100644 index cb9ca80b1e..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/section_eager_execution.tex +++ /dev/null @@ -1,97 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\section{Compiled, Eager, and Recurrence Execution} -\label{sec:eager-execution} - -The three execution modes differ in how they turn the same current recursion -into numerical work. Compiled mode specializes groups of current relations to -one process. Eager mode applies reusable model kernels according to a -process-specific schedule. Recurrence mode constructs a compact schedule of -currents, contributions, and closures directly. These choices change the -balance between process-generation cost and runtime work, but not the -observable being evaluated. - -Recurrence JIT O2 is the default execution mode. - -\begin{center} -\small -\begin{tabular}{@{}L{0.72in}L{1.85in}L{2.00in}L{1.40in}@{}} -\toprule -\textbf{mode} & \textbf{process preparation} & \textbf{evaluation} & - \textbf{characteristic balance} \\ -\midrule -Compiled - & Builds process-specific stage evaluators - & Evaluates a small number of process-wide, multi-output stages - & More preparation; greater fusion across a process \\ -Eager - & Maps the process graph to reusable prepared-model kernels - & Applies those kernels according to the process dependencies - & Reuses model work across processes \\ -Recurrence - & Builds a compact schedule directly from the current recursion - & Evaluates scheduled currents, contributions, and closures - & Avoids construction of a generic process DAG \\ -\bottomrule -\end{tabular} -\end{center} - -\subsection{Common physics contract} - -All three modes retain the same external states, perturbative orders, -helicities, colour components, coherent amplitude groups, symmetry factors, -and initial-state averages. In a contracted colour basis their common -observable has the schematic form -\begin{equation} - \mathcal M_p - =\mathcal N\sum_h\sum_{a,b} - A_{ha}(p)^{*}\,C_{ab}\,A_{hb}(p), - \label{eq:three-mode-common-observable} -\end{equation} -with the corresponding resolved form retained when helicity or leading-colour -flow components are requested. Each mode must reproduce both the directly -evaluated total and the sum of those resolved components. - -Current contributions are accumulated coherently before a propagator or other -current transformation is applied. Final closures then form the amplitude -components entering Eq.~\eqref{eq:three-mode-common-observable}. This ordering -is common to the three modes and prevents execution strategy from changing the -normalization. - -\subsection{Prepared-model boundary} - -A prepared model contains reusable numerical information derived from the -model's particles, parameters, propagators, and interaction tensors. Eager and -recurrence JIT O2 measurements reuse this model-level preparation and add only -the process-dependent schedule. Compiled JIT O3 measurements instead include -construction and compilation of their process-specific evaluators. - -Prepared-model creation occurs outside the process-generation timer. The -reported eager and recurrence generation times therefore describe adding a -process to an already prepared model, not importing and compiling the model -itself. - -\subsection{Batches, selectors, and portability} - -Evaluation is batched over phase-space points, allowing the JIT backend to use -the point dimension for vectorization. Partitioning a large input batch changes -neither the process representation nor the numerical result. - -Helicity and colour-flow selectors refer to physical resolved components. A -complete leading-colour calculation retains every declared helicity and flow, -so selecting one flow with summed helicities or one helicity with all flows -does not alter the underlying physics coverage. The selected-flow and all-flow -layouts used for these workloads retain that same physical coverage. - -Portable JIT state is compiled for the receiving processor when loaded. -Target-native ASM and C++ payloads remain architecture-specific, and the exact -symbolic representation is retained where higher-precision evaluation is -supported. - -\subsection{Interpretation} - -Compiled mode may benefit most when process-wide fusion outweighs its -additional preparation cost. Eager mode can reduce repeated preparation when -many processes share a model, while recurrence provides a compact direct -representation of the current construction. The tables compare these -trade-offs under identical physics, selector, precision, and validation -conditions; no mode is assumed to be universally fastest. diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/section_lc_flow_layouts.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/section_lc_flow_layouts.tex deleted file mode 100644 index 9a5e688c83..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/section_lc_flow_layouts.tex +++ /dev/null @@ -1,148 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\section{Reusable Leading-Colour Execution Layouts} -\label{sec:lc-flow-layouts} - -Leading-colour coverage and its numerical layout are separate concepts. Let -\(\mathcal H\) be the retained helicities and \(\mathcal F\) the retained -physical colour flows. Complete leading-colour coverage represents -\begin{equation} - \mathcal C_{\mathrm{LC}}=\mathcal H\times\mathcal F - \label{eq:lc-complete-coverage} -\end{equation} -and can expose every resolved amplitude \(\mathcal A_{hf}\). For selected -subsets \(S_H\subseteq\mathcal H\) and \(S_F\subseteq\mathcal F\), the -observable is -\begin{equation} - \mathcal W(S_H,S_F) - =\mathcal N\sum_{h\in S_H}\sum_{f\in S_F}w_{hf} - \left|\sum_{r\in G(h,f)}\mathcal A^{(r)}_{hf}\right|^2 . - \label{eq:lc-runtime-selection} -\end{equation} -Here \(G(h,f)\) is a coherent contribution group, \(w_{hf}\) contains exact -symmetry and leading-colour weights, and \(\mathcal N\) is the process -normalization. The layout changes how this sum is scheduled, not its -components or normalization. - -\subsection{Two complete-coverage layouts} - -The report measures two layouts because selected-flow and all-flow workloads -offer different opportunities for sharing: - -\begin{center} -\small -\begin{tabular}{@{}L{1.32in}L{2.40in}L{2.40in}@{}} -\toprule -\textbf{property} & \textbf{topology replay} & - \textbf{all-flow union} \\ -\midrule -Measured workload & one selected flow, summed helicities & - all flows, one selected helicity \\ -Retained physics & every flow and helicity & - every flow and helicity \\ -Main reuse & equivalent flow topologies related by exact permutations and - factors & currents and closures shared directly across all flows \\ -Availability & compiled, eager, recurrence, and on-the-fly to - \(n_{\mathrm{final}}=4\) & - compiled, eager, and recurrence \\ -\bottomrule -\end{tabular} -\end{center} - -On-the-fly execution does not materialize a separate all-flow-union artifact. -Within its LC scope, one compact process-seed artifact serves both measured -workloads: one selected flow with helicities summed, and all physical flows -with one helicity selected. Thus the all-flow observable remains the same, but -its on-the-fly execution is reconstructed lazily from the shared compact -artifact rather than from \(D_{\mathrm{union}}\). - -In topology replay, exact relations partition physical flows into equivalence -classes. If \(\rho(f)\) represents the class containing \(f\), the calculation -records a permutation \(\pi_f\), an exact factor \(s_f\), and the corresponding -weight: -\begin{equation} - \mathcal A_{h f}(p) - =s_f\,\mathcal A_{\pi_f(h),\rho(f)}\!\left(\pi_f(p)\right). - \label{eq:lc-topology-replay} -\end{equation} -This avoids constructing an independent current graph for every physical -ordering and is suited to selected-flow, helicity-summed evaluation. - -The all-flow union instead merges the dependency graphs of all resolved -components: -\begin{equation} - D_{\mathrm{union}} - =\left(\bigcup_{h\in\mathcal H,\,f\in\mathcal F}D_{hf}\right) - \big/\!\sim , - \label{eq:lc-all-flow-union} -\end{equation} -where \(\sim\) identifies currents, kernel values, and closures that are -algebraically equal up to retained exact factors. For a selected helicity, -one graph traversal then reuses intermediate currents across all flows. - -Compiled mode specializes the chosen layout to process-wide stage evaluators. -Eager mode applies prepared-model kernels to the same dependency structure, -recurrence mode constructs a compact current schedule directly, and on-the-fly -mode reconstructs query-local traces from its compact process seed. These -execution choices do not change \(\mathcal H\), \(\mathcal F\), or -Eq.~\eqref{eq:lc-runtime-selection}. - -\subsection{Runtime selection} - -Flow and helicity selections refer to physical components. A selection may be -applied to a complete batch or specified independently for each point; omitting -an axis sums all retained entries on that axis. Rows with equal selections can -be grouped into contiguous numerical batches. This grouping changes neither -the generated coverage nor the resolved result. - -\subsection{Generation and reference boundaries} - -The two layouts build different graphs and numerical schedules, so their -process-generation times are distinct observables: -\begin{equation} - T_{\mathrm{gen}}^{\mathrm{replay}} - \quad\hbox{and}\quad - T_{\mathrm{gen}}^{\mathrm{union}}. - \label{eq:lc-two-generation-times} -\end{equation} -Cross-mode comparisons use the same layout on both sides. Preparation of -reusable model-level kernels occurs before the process-generation timer and is -not included in these table values. - -The on-the-fly exception has one process-generation quantity \(G\), because -the selected-flow and all-flow workloads share one compact artifact. Its first -full-batch evaluation \(W\) constructs the initially requested selector-family -state. Artifact loading and the conventional benchmark warmup calls are timed -separately and are excluded from \(W\). Calling \texttt{Runtime.clear()} drops -the lazy on-the-fly state without replacing the process artifact. - -The original-\AC{} reference uses two different routes. For the selected-flow -workload, its generation value measures creation of the process library. For -the all-flow workload, the reported setup value measures preparation of direct -all-flow evaluation. The corresponding runtime measurements implement the -same physical workloads as \PAC{}, but the all-flow setup quantities do not -define a like-for-like process-generation speedup. The table therefore reports -both quantities absolutely and marks their generation comparison as not -comparable. - -Before timing an on-the-fly cell, the complete resolved components for both -workloads are compared with a separately generated recurrence authority. The -same componentwise comparison is repeated after -\texttt{Runtime.clear()} to check the cold reconstruction path. - -\subsection{NLC and full colour} - -The alternative layouts apply only at leading colour. NLC and full-colour -evaluation construct an amplitude basis and contract it with the appropriate -colour metric: -\begin{equation} - \mathcal W_{\mathrm{contracted}} - =\mathcal N\sum_h\sum_{a,b} - \mathcal A_{ha}^{*}\,C_{ab}\,\mathcal A_{hb}. - \label{eq:contracted-colour-layout} -\end{equation} -These treatments do not expose the physical leading-colour flow axis, so there -is no topology-replay or all-flow-union distinction. On-the-fly NLC and -full-colour entries are selector-free contracted evaluations: their cold stage -builds the requested helicity family and evaluates the authenticated sparse-NLC -or complete-colour contraction payload. They expose helicity selection but no -leading-colour flow selector. diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/section_three_mode_performance_tables.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/section_three_mode_performance_tables.tex deleted file mode 100644 index 0d5369dd35..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/section_three_mode_performance_tables.tex +++ /dev/null @@ -1,230 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\section{Standard-Model Process Matrices} -\label{sec:three-mode-performance-tables} - -The process matrices use recurrence as the primary \PAC{} execution mode. -Built-in-SM and UFO-SM recurrence JIT O2 retain comparisons with legacy -original-\AC{} results. Separate built-in-SM matrices compare compiled JIT O3 -and eager JIT O2 with recurrence JIT O2 for the same process, colour treatment, -and observable. A built-in-SM on-the-fly JIT O2 matrix compares directly with -original-\AC{} for LC at \(n_{\mathrm{final}}\leq4\). Four additional -full-colour UFO-SM views compare recurrence, compiled, eager, and on-the-fly -with one shared authoritative MadGraph standalone reference. - -The canonical matrix spans electroweak vector production, charged-current and -leptonic channels, heavy-quark production, pure gluons, multi-boson final -states, Higgs-associated final states, and three- and four-quark-line cases. -Here \(n\) is the number of final-state particles. LC coverage retains every -declared family through \(n=9\), except that on-the-fly LC coverage currently -ends at \(n_{\mathrm{final}}=4\). NLC and full-colour grids display -\(n=1,\ldots,6\), including genuine on-the-fly contracted cells. A multiplicity -for which a process family does not yet exist -is marked \textsc{not applicable}; an otherwise defined process intentionally -excluded from the declared measurement scope is marked \textsc{not run}. -These are table structure, not unfilled measurements. A complete edition -accounts for every scheduled cell across the full declared range. -Resource-limited cells carry a documented status; every successful cell is -numerical and validated. An in-scope result that does not pass required -numerical validation is identified by a status and does not carry a timing -ratio. Original-\AC{} disagreement is the deliberate exception: it is a legacy -diagnostic, not a required validation failure. -Best-mode cells select the fastest successful candidate, including on-the-fly -where it is in scope and marking that winner with \texttt{(o)}. If none -succeeds, the recurrence attempt is shown with \texttt{(r)} and its terminal -status. - -The UFO-SM recurrence matrices use the same process definitions, colour -contracts, numerical parameters, selectors, and validation points as the -built-in-SM recurrence matrices. Their source is the packaged Standard Model -loaded through the serialized-JSON interface. This comparison verifies that the -imported and built-in model routes implement the same requested physics. -Outside the four MadGraph-reference full-colour views, compiled, eager, and -on-the-fly process matrices remain built-in-only, isolating differences between -execution modes from differences in model loading. - -\input{result_validation_summary.tex} - -\subsection*{Workloads and denominators} - -For a reported timing quantity \(T\), each multiplier is -\begin{equation} - r_{\mathrm{candidate/baseline}} - = \frac{T_{\mathrm{candidate}}}{T_{\mathrm{baseline}}}. - \label{eq:three-mode-matrix-time-ratio} -\end{equation} -Green, orange, and red denote respectively \(r<1\), \(1\leq r<2\), and -\(r\geq2\). Green therefore means that the candidate is faster than the -baseline named in the table heading. The recurrence matrices use original -\AC{} as the baseline, as does the detailed on-the-fly LC matrix. The compiled -and eager matrices use built-in-SM recurrence JIT O2 as the baseline. - -Every LC comparison contains two complete-coverage layouts: -\begin{itemize} - \item topology replay, measured with one physical colour flow selected and - all retained helicities summed; and - \item the all-flow union, measured with one physical helicity selected and - all retained colour flows summed. -\end{itemize} -Neither selection is fixed during generation. Each LC cell reports the two -baseline generation quantities and wall times, followed by candidate -generation entries and runtime ratios. The muted supplementary ratio first -compares separately measured execution attributions when both sides expose -compatible boundaries; otherwise it compares authenticated evaluator totals. -Only against original \AC{}, which has no evaluator-total clock, may a candidate -evaluator total use the legacy direct execution clock (or wall when direct -execution is absent) as denominator. An evaluator total is never divided by a -recurrence core. This evaluator-total fallback is diagnostic only; -execution/execution remains the compatible supplementary attribution. If no -compatible supplementary clock exists, only the wall ratio is shown. Compiled -and eager generation are compared with recurrence using the same layout. - -On-the-fly is the scoped LC exception to the two-artifact layout. One compact -process-seed artifact serves both the selected-flow, helicity-summed -workload and the all-flow, single-helicity workload. Its process-generation -time is \(G\). For selected flow, \texttt{([xG] x(G+W))} shows the muted -generation-only multiplier and the normally coloured multiplier after adding -the first full-batch evaluation \(W\), both relative to the matching \AC{} -library-generation time. For all flow, \texttt{[G] G+W} shows the two absolute -times, with \(G\) muted and \(G+W\) in normal black. In this generation-only -notation, \(W\) excludes artifact loading and the conventional benchmark -warmup calls. - -The two original-\AC{} reference workloads have different setup boundaries. -For the selected-flow workload, the reported generation quantity is creation -of the process library. For the all-flow workload, it is preparation of direct -all-flow evaluation. Runtime ratios compare the same physical observable. The -all-flow setup quantities are not like-for-like, so the table shows the -candidate process-generation time as an absolute value and forms no ratio. -For on-the-fly this is the absolute \texttt{[G] G+W} pair above. - -NLC and full colour use one helicity-summed, colour-contracted calculation per -mode. Their cells report the absolute baseline generation and wall time, -followed by the candidate generation and runtime ratios. No per-flow scalar or -flow selector is defined for these contracted colour accuracies. On-the-fly -uses the same public contracted result shape and authenticates its expanded -colour-contraction payload. - -The wall quantity is the repeated native evaluation time after caller-language -input conversion and is the primary runtime observable. Independent accumulated -evaluator-total and narrower recurrence-core clocks remain in the detailed -measurement evidence; neither is copied from wall time or from the other. The -compact runtime notation \texttt{([xS]xW)} shows a compatible supplementary -clock multiplier \texttt{xS} in muted brackets and the primary wall multiplier -\texttt{xW} in its performance colour. The hierarchy above determines whether -\texttt{xS} is execution attribution or a diagnostic evaluator-total fallback. -If no supplementary ratio is eligible, the cell shows only \texttt{(xW)}. - -Preparation of reusable model-level kernels is excluded from -process-generation time. Compiled generation still includes process-specific -evaluator construction and backend compilation. On-the-fly \(W\) starts only -after the compact artifact has been loaded and stops after its first complete -batch evaluation; later benchmark warmups are separate. - -A timing is shown only after the candidate passes its required internal and -cross-mode checks. Compiled and eager results agree with recurrence at the -strict cross-mode tolerance, and built-in and UFO-SM recurrence results are -compared directly. Each result must reproduce its resolved sum. The four new -full-colour UFO-SM views instead use the shared MadGraph standalone value as -the authoritative physics boundary: \PAC{} is evaluated at precision 200 at -the same point and must agree within relative tolerance \(10^{-10}\). For LC, -the common flow--helicity component is compared directly between topology -replay and all-flow union. On-the-fly adds a recurrence-authority gate: for -both workloads, its complete resolved-component array must agree with the -separately generated recurrence result before timing. After -\texttt{Runtime.clear()}, the full component comparison and the resolved-sum -identity are repeated before the cell is accepted. - -Original \AC{} remains visible as a performance baseline and numerical -diagnostic, but is not authoritative. A mismatch with it does not suppress the -candidate timing, ratio, or summary contribution; only the corresponding -\AC{} generation-time token is coloured red. This rule applies equally to LC, -NLC, and full-colour legacy comparisons. - -\subsection*{Cell and summary layout} - -\begin{center} -\small -\begin{tabular}{@{}L{0.95in}L{2.45in}L{5.75in}@{}} -\toprule -\textbf{contract} & \textbf{baseline entry} & \textbf{candidate entries} \\ -\midrule -LC, upper - & topology replay \texttt{|} all-flow generation quantities in seconds - & layout-matched ratios, except that the all-flow candidate against original - \AC{} is shown absolutely without a ratio; on-the-fly uses selected - \texttt{([xG] x(G+W))} \texttt{|} all-flow \texttt{[G] G+W} \\ -LC, lower - & selected-flow \texttt{|} all-flow wall times in - \(\mu\mathrm{s}/\mathrm{pt}\) - & compact \texttt{([xS]xW)} comparisons, or \texttt{(xW)} when only wall is - comparable \\ -NLC and full-colour, upper - & contracted generation time in seconds - & candidate generation ratio \\ -NLC and full-colour, lower - & contracted wall time in \(\mu\mathrm{s}/\mathrm{pt}\) - & compact \texttt{([xS]xW)} comparison, or \texttt{(xW)} when only wall is - comparable \\ -\bottomrule -\end{tabular} -\end{center} - -Summary rows contain multipliers only, ordered as minimum, maximum, median, -arithmetic mean, and weighted mean. The arithmetic mean averages the -individual candidate/baseline multipliers; the weighted mean is the ratio of -sums -\(\sum_i T_{\mathrm{candidate},i}/\sum_i T_{\mathrm{baseline},i}\). -Generation summaries use topology replay for LC and the contracted workload -for NLC and full colour; the non-comparable LC all-flow generation quantity is -omitted. In the best-mode overview, an on-the-fly winner contributes its -displayed primary \(G+W\) quantity, not the muted generation-only \(G\) -diagnostic. Fixed-engine on-the-fly summaries retain their generation-only -comparison. Runtime summaries use wall time only, with -separate aligned LC topology-replay and all-flow lines. Structurally inapplicable, -resource-limited, unsupported, and validation-failed cells do not contribute. - -The first three matrices provide a built-in-SM overview against original -\AC{}. For each process, multiplicity, colour treatment, and LC workload, -they select the validated pyAmpliCol mode with the smallest wall time. -Selection is independent in every cell: the overview records the measured -winner rather than prescribing one mode for all processes. Its upper row -reports generation and its lower row reports runtime. LC pairs use -non-union-flow \texttt{|} union-flow ordering. Since original-\AC{} all-flow -setup and \PAC{} process generation have different boundaries, the latter is -shown absolutely rather than as a misleading ratio. When on-the-fly is the -winner, the same \texttt{([xG] x(G+W))} and \texttt{[G] G+W} generation -notation applies beside its \texttt{(o)} marker. - -\input{result_matrix_best_builtin_sm_lc_table.tex} -\input{result_matrix_best_builtin_sm_nlc_table.tex} -\input{result_matrix_best_builtin_sm_full_table.tex} - -The detailed tables are grouped by execution mode, model source, and colour -treatment. - -\input{result_matrix_recurrence_builtin_sm_lc_table.tex} -\input{result_matrix_recurrence_builtin_sm_nlc_table.tex} -\input{result_matrix_recurrence_builtin_sm_full_table.tex} -\input{result_matrix_recurrence_ufo_sm_lc_table.tex} -\input{result_matrix_recurrence_ufo_sm_nlc_table.tex} -\input{result_matrix_recurrence_ufo_sm_full_table.tex} -\input{result_matrix_compiled_builtin_sm_lc_table.tex} -\input{result_matrix_compiled_builtin_sm_nlc_table.tex} -\input{result_matrix_compiled_builtin_sm_full_table.tex} -\input{result_matrix_eager_builtin_sm_lc_table.tex} -\input{result_matrix_eager_builtin_sm_nlc_table.tex} -\input{result_matrix_eager_builtin_sm_full_table.tex} -\input{result_matrix_on_the_fly_builtin_sm_lc_table.tex} -\input{result_matrix_on_the_fly_builtin_sm_nlc_table.tex} -\input{result_matrix_on_the_fly_builtin_sm_full_table.tex} - -The following four views reuse the candidate measurements above and one shared -MadGraph full-colour reference cache; they do not create duplicate campaign -measurements. The recurrence, compiled, and eager comparisons use p200 -candidate values, while the genuine on-the-fly contracted comparison uses its -supported p16 lane. - -\input{result_matrix_recurrence_ufo_sm_full_vs_madgraph_table.tex} -\input{result_matrix_compiled_ufo_sm_full_vs_madgraph_table.tex} -\input{result_matrix_eager_ufo_sm_full_vs_madgraph_table.tex} -\input{result_matrix_on_the_fly_ufo_sm_full_vs_madgraph_table.tex} diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/section_ufo_support.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/section_ufo_support.tex deleted file mode 100644 index 3f01e3d9d2..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/section_ufo_support.tex +++ /dev/null @@ -1,163 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\section{Supported UFO and Serialized-JSON Models} -\label{sec:ufo-support} - -\PAC{} accepts a documented subset of the Universal FeynRules Output (UFO) -format and an equivalent serialized-JSON representation. Both sources are -normalized before process generation and then use the same current recursion, -colour treatment, and numerical interfaces as the built-in models. Unsupported -structures are rejected explicitly rather than interpreted approximately. - -\subsection{Sources and normalization} - -The two input routes are -\begin{equation} - \{\text{trusted UFO module},\text{ serialized JSON}\} - \longrightarrow - \text{normalized model} - \longrightarrow - \text{numerical kernels}. - \label{eq:ufo-loading-route} -\end{equation} -A UFO module is executable Python and must therefore come from a trusted -source. The serialized JSON form is data-only and is preferable for portable -exchange and archival. After loading, both forms describe the same particles, -parameters, propagators, interactions, coupling orders, Lorentz tensors, and -colour tensors. - -Model symbols remain in a model-local namespace, so equally named parameters -from different models are not identified accidentally. Normalization also -makes component orderings and particle conjugation explicit. A model is -accepted for ordinary process generation only when the normalized model -satisfies the support boundary below; an unrepresentable requested interaction -is rejected explicitly. - -\subsection{Interactions and exact verification} - -A UFO vertex is a sum over colour and Lorentz structures, -\begin{equation} - \mathcal V(1,\ldots,n) - =\sum_{a,b}g_{ab}\, - C_a(c_1,\ldots,c_n)\, - L_b(s_1,p_1;\ldots;s_n,p_n). - \label{eq:ufo-vertex-matrix} -\end{equation} -Each term retains its coupling-order assignment. The supported Lorentz basis -includes scalars, momenta, metrics, Dirac identity and gamma matrices, -\(\gamma_5\), chiral projectors, slashed momenta, and sigma tensors. The -supported SU(3) representations are the singlet, fundamental, -antifundamental, and adjoint. - -Colour projection and symmetry reuse are based on exact normalized -expressions. Numerical agreement at a sample point is not used to establish an -algebraic identity. When an identity needed only for reuse cannot be proved, -the corresponding contributions are evaluated separately. When an identity -is required to represent an interaction at all, failure to establish it causes -the model or process to be rejected. - -Leading-colour singlet subtraction, for example, follows from the fundamental -Fierz identity -\begin{equation} - (T^a)_i{}^{\bar\jmath}(T^a)_k{}^{\bar l} - =T_R\left( - \delta_i{}^{\bar l}\delta_k{}^{\bar\jmath} - -\frac{1}{N_c} - \delta_i{}^{\bar\jmath}\delta_k{}^{\bar l} - \right). - \label{eq:fierz} -\end{equation} -It is used only when the colour representation, Lorentz interaction, and -vector propagator satisfy the corresponding exact conditions. The same -principle applies to vectorlike parity, Yang--Mills relations, and current -reflection. - -\subsection{Contact interactions and propagators} - -Supported contact interactions are rewritten with non-propagating auxiliary -currents only when the original tensor can be reconstructed exactly. The -physical coupling appears once, and the rewriting introduces no artificial -pole. Colour-singlet scalar contacts provide the validation ladder for this -construction. Higher-valence singlet interactions are accepted when their -normalized tensor admits the same exact reconstruction. - -A coloured four-vector gauge contact is accepted only for the two-\(f\) -structure -\begin{equation} - C^{a_1a_2a_3a_4} - =c\,f^{a_i a_j b}f^{b a_k a_r}, - \label{eq:two-f-color} -\end{equation} -up to exact permutations, with one shared adjoint index and a matching Lorentz -factorization. Other coloured contact tensors require a separately supported -intermediate colour channel. - -Standard scalar, Dirac, vector, and spin-two propagators use the mass, width, -gauge, and component ordering declared by the normalized model. A custom UFO -propagator is accepted only when its numerator and denominator can be lowered -exactly; optimizations that assume a standard propagator are then disabled. -Massless spin two is validated by the scalar-gravity model. Massive spin-two -support remains experimental because it has not yet been tested across a -comparably broad set of models. - -\subsection{Support boundary} - -In the table, \emph{conditional} means that the stated exact algebraic -condition must be established for the particular model expression. It does not -imply acceptance of every algebraically equivalent UFO spelling. - -\begingroup -\small -\setlength{\LTpre}{0.3em} -\setlength{\LTpost}{0.3em} -\begin{longtable}{@{}L{0.83in}L{1.47in}L{0.93in}L{3.15in}@{}} -\toprule -\textbf{area} & \textbf{class} & \textbf{status} & \textbf{boundary} \\ -\midrule -\endfirsthead -\toprule -\textbf{area} & \textbf{class} & \textbf{status} & \textbf{boundary} \\ -\midrule -\endhead -source & UFO directory / JSON & supported & UFO Python must be trusted; JSON - is data-only and both use the same normalized model \\ -spin & scalar, Dirac, vector & supported & standard wavefunctions, - propagators, component orderings, and closures \\ -spin & massless spin two & supported & tensor path validated by the - scalar-gravity model \\ -spin & massive spin two & experimental & Fierz--Pauli path is available, but - broad model validation is incomplete \\ -spin & UFO ghosts & partial & propagating ghosts require an exactly - representable custom propagator and are not broadly qualified \\ -spin & Majorana/FNV, spin \(3/2\) & unsupported & no - fermion-number-violating-flow or Rarita--Schwinger current prescription \\ -colour & \(1,3,\bar3,8\) of SU(3) & supported & LC, NLC, and full-colour - treatments described in this report \\ -colour & \(6,\bar6\), extra groups & unsupported & no sextet or - multiple-group flow and contraction representation \\ -arity 3 & \(1,\delta,T,f\) colour & supported & exact colour projection and - representable Lorentz components \\ -arity 3 & \(d^{abc}\), \(\epsilon\), \(K_6\), \(T_6\) & unsupported & no - supported colour-flow and contraction prescription \\ -arity 4 & colour singlet & conditional & exact tensor reconstruction by - non-propagating auxiliary currents \\ -arity 4 & two-\(f\) gauge colour & conditional & one shared adjoint index, - trivalent topology, and exact Lorentz reconstruction \\ -arity 4 & other coloured tensors & unsupported & no supported auxiliary colour - channel \\ -arity \(>4\) & colour-singlet contact & conditional & exact no-pole - reconstruction with the original coupling inserted once \\ -arity \(>4\) & coloured contact & unsupported & no general - irreducible-channel factorization \\ -Lorentz & normalized tensor basis & supported & every tensor function must - normalize with explicit component axes \\ -Lorentz & form factors / unknown functions & unsupported & no portable - numerical prescription \\ -propagator & standard \(0,\frac12,1,2\) & supported & model mass and width, - with explicit component ordering and closure \\ -propagator & custom UFO tensor & conditional & exact component lowering; - standard-propagator optimizations are disabled \\ -symmetry & vectorlike/Yang--Mills/reflection & conditional & exact normalized - identities over the complete interaction sector used by the process \\ -\bottomrule -\end{longtable} -\endgroup diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_dag.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_dag.tex deleted file mode 100644 index 2a78286be4..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_dag.tex +++ /dev/null @@ -1,83 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\section{\texorpdfstring{Shared-Current DAG and Numerical Execution}{Shared-Current DAG and Numerical Execution}} -\label{sec:zgg-dag} - -The current recursion becomes a directed acyclic graph (DAG) when physically -identical intermediate currents are shared. This section summarizes the -identity and ordering needed for that reuse and relates them to the three -execution modes. - -\subsection{Current identity and reuse} - -Two contributions share a current only when every physics-relevant label -agrees. Schematically, -\begin{equation} - \Omega(J)= - \bigl(t,I,H,s,F,Q,C,O,a,\pi_I\bigr), - \label{eq:zgg-current-key} -\end{equation} -where the entries identify the particle species, external subset, helicity and -spin ancestry, flavour and additive charges, colour state, perturbative order, -auxiliary-current type, and colour-sensitive ordering. The subset determines -the current momentum \(q_I=\sum_{i\in I}q_i\), while the ordered labels prevent -distinct colour traversals from being merged. - -Exact identity permits one stored current to serve every amplitude contribution -that needs it. A second kind of reuse applies when different currents require -the same numerical kernel value up to a known exact factor. Neither form of -reuse merges distinct physical helicity or colour-flow components. - -\subsection{Topological ordering} - -The graph is evaluated in increasing external-subset size. Every input is -therefore available before the current that consumes it. For the representative -\(d\bar d\to Zgg\) process, the ordering is schematically -\begin{equation} - \boxed{\text{sources}} - \longrightarrow - \boxed{|I|=2} - \longrightarrow - \boxed{|I|=3} - \longrightarrow - \boxed{|I|=4} - \longrightarrow - \boxed{\text{amplitude closures}} . - \label{eq:zgg-stage-chain} -\end{equation} -At each stage, all admissible partitions contributing to the same current are -summed coherently before propagation. The final closures join the largest -retained currents to the remaining external states. This ordering makes the -dependency structure explicit without assigning physical meaning to a -particular storage layout. - -\subsection{Numerical realization} - -Compiled mode combines many relations in a stage into process-specific -multi-output evaluators. Eager mode follows the same process graph using -reusable prepared-model kernels. Recurrence mode represents the current and -closure sequence directly. All three preserve the same coherent sums, colour -contraction, helicity treatment, symmetry weights, and normalization. - -For resolved leading-colour evaluation, the public result has the form -\begin{equation} - R_{p,h,f}=\left|\mathcal M_{h,f}(p)\right|^2, - \qquad - \operatorname{shape}(R)= - (N_{\rm point},N_{\rm helicity},N_{\rm flow}) . - \label{eq:zgg-resolved-shape} -\end{equation} -Structural zeros remain explicit, and summing the non-point axes must reproduce -the directly evaluated total within the stated numerical tolerance. - -\subsection{Timing boundary} - -The primary runtime quantity is the complete native wall time after -caller-language array conversion. It includes source and momentum preparation, -the mode-specific numerical evaluation, selectors, closures, and final -reduction. Packing performed by the caller is outside this boundary. - -Some backends additionally expose a narrower execution attribution. Because -its precise boundary is mode-specific, it is reported only as a supplementary -quantity and only when measured directly. The complete wall time remains the -common observable used for comparisons; an unavailable attribution is marked -explicitly rather than inferred. diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_example.tex b/pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_example.tex deleted file mode 100644 index 86f7892480..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/section_zgg_example.tex +++ /dev/null @@ -1,143 +0,0 @@ -% SPDX-License-Identifier: 0BSD -\section{\texorpdfstring{Worked \(d\bar d\to Zgg\) Example}{Worked d dbar -> Z g g Example}} -\label{sec:zgg-example} - -This example illustrates how a familiar tree-level process is represented by -reusable off-shell currents. It also fixes the momentum, helicity, and colour -conventions used in the performance tables. - -\subsection{External legs and conventions} - -The physical process is -\begin{equation} - d(p_1)\,\bar d(p_2) \longrightarrow Z(p_3)\,g(p_4)\,g(p_5), - \qquad p_1+p_2=p_3+p_4+p_5 . - \label{eq:zgg-physical-process} -\end{equation} -The current recursion uses the all-outgoing convention -\begin{equation} - q_1=-p_1,\quad q_2=-p_2,\quad q_i=p_i\ (i=3,4,5), - \qquad \sum_{i=1}^{5}q_i=0 . - \label{eq:zgg-all-outgoing} -\end{equation} -External momenta are supplied in the physical convention of -Eq.~\eqref{eq:zgg-physical-process} and crossed to the all-outgoing convention -before the recursion is evaluated. - -\begin{center} -\small -\begin{tabular}{@{}cL{0.90in}L{1.05in}L{1.00in}cL{1.35in}@{}} -\toprule -\textbf{label} & \textbf{physical leg} & \textbf{outgoing state} & -\textbf{momentum} & \textbf{states} & \textbf{colour role} \\ -\midrule -$1$ & incoming $d$ & outgoing $\bar d$ & $q_1=-p_1$ & $2$ & - $\overline{\mathbf 3}$, line end \\ -$2$ & incoming $\bar d$ & outgoing $d$ & $q_2=-p_2$ & $2$ & - $\mathbf 3$, line start \\ -$3$ & outgoing $Z$ & outgoing $Z$ & $q_3=p_3$ & $3$ & singlet \\ -$4$ & outgoing $g$ & outgoing $g$ & $q_4=p_4$ & $2$ & adjoint insertion \\ -$5$ & outgoing $g$ & outgoing $g$ & $q_5=p_5$ & $2$ & adjoint insertion \\ -\bottomrule -\end{tabular} -\end{center} - -There are \(2\times2\times3\times2\times2=48\) physical helicity -configurations. Twenty-four vanish identically because the massless quark line -permits only chirality-compatible initial-state helicities; they remain -explicit zero entries in resolved results. - -At leading colour the \(Z\) is absent from the colour word. Complete coverage -contains the two orderings -\begin{equation} - c_0=(2,4,5,1),\qquad c_1=(2,5,4,1). - \label{eq:zgg-physical-flows} -\end{equation} -Both are retained during generation, so either flow can be selected at -evaluation time. - -\subsection{Reusable current recursion} - -For a nonempty source subset \(I\), define its momentum by -\begin{equation} - q_I=\sum_{i\in I}q_i . - \label{eq:zgg-subset-mask} -\end{equation} -A one-leg current is the appropriate external spinor, polarization vector, or -scalar wavefunction. Composite currents obey the binary recursion -\begin{equation} - J_{t,\Omega}^{a}(I) - =P_t{}^{a}{}_{b}(q_I) - \sum_{\substack{I=A\mathbin{\dot\cup}B\\ - A,B\ne\varnothing}} - \sum_{v\,:\,t_A t_B\to t} - \kappa_v\, - V_v{}^{b}{}_{cd}(q_A,q_B) - J_{t_A,\Omega_A}^{c}(A) - J_{t_B,\Omega_B}^{d}(B). - \label{eq:zgg-current-recursion} -\end{equation} -Here \(t\) is the particle state, \(P_t\) is its propagator, \(V_v\) is an -allowed interaction, and \(\Omega\) collects the quantum numbers required to -identify the current. Only combinations consistent with the model, -perturbative order, and colour ordering enter the sum. - -Representative terms along the quark line are -\begin{align} - J_d(2,5) &={P}_d\,V_{dgd}\bigl[J_d(2),J_g(5)\bigr], - \label{eq:zgg-j25}\\ - J_g(4,5) &={P}_g\,V_{ggg}\bigl[J_g(4),J_g(5)\bigr], - \label{eq:zgg-j45}\\ - J_d(2,4,5) &={P}_d\Bigl( - V_{dgd}\bigl[J_d(2,5),J_g(4)\bigr] - +V_{dgd}\bigl[J_d(2,4),J_g(5)\bigr] - +V_{dgd}\bigl[J_d(2),J_g(4,5)\bigr] - \Bigr), - \label{eq:zgg-j245}\\ - J_d(2,3,4,5) &={P}_d\!\sum_{A\dot\cup B=\{2,3,4,5\}} - V\bigl[J(A),J(B)\bigr]. - \label{eq:zgg-j2345} -\end{align} -Equation~\eqref{eq:zgg-j2345} includes every admissible placement of the -\(Z\) emission and both gluon insertions. Ordered currents such as -\(J_d(2,5,4)\) and \(J_d(2,4,5)\) remain distinct even though their momentum -subset is the same. - -The final closure joins the endpoint current to source label \(1\): -\begin{equation} - {\cal A}_{h,c}^{(r)} - =C^{(r)}_{\dot a a}\, - J_{\bar d}^{\dot a}(1)\, - J_d^a(2,3,4,5), - \qquad - {\cal A}_{h,c}=\sum_{r\in G(h,c)}{\cal A}_{h,c}^{(r)} . - \label{eq:zgg-amplitude-root} -\end{equation} -The set \(G(h,c)\) contains contributions that must be summed coherently. -Identical subcurrents are evaluated once and reused wherever their complete -quantum-number and ordering labels agree. This sharing is the essential -difference between the current DAG and an independent evaluation of every -Feynman diagram. - -\subsection{Resolved observable and normalization} - -The two leading-colour execution layouts evaluate the same complete set of -helicity and flow components. One is optimized for a selected flow with summed helicities; -the other shares work across all flows for a selected helicity. Their resolved -components and their summed matrix element are numerically identical. - -For the built-in Standard Model, the normalization used in this example is -\begin{equation} - |{\cal M}|^2 - ={\cal N}\sum_{h,c}w_{h,c}\, - \left|\sum_{r\in G(h,c)}{\cal A}_{h,c}^{(r)}\right|^2, - \qquad - {\cal N}=\frac{27\,(4\pi\alpha_s)^2(8\pi\alpha_{\rm EW})} - {36\times2}. - \label{eq:zgg-normalization} -\end{equation} -The denominator averages over the incoming colour and spin states, while the -factor \(2=2!\) accounts for the identical final-state gluons. Coupling -powers, colour weights, coherent groups, and symmetry factors are retained -separately so that changing numerical model parameters does not alter the -process definition. diff --git a/pyamplicol/src/pyamplicol/_profiling_campaign/steer_performance_campaign.py b/pyamplicol/src/pyamplicol/_profiling_campaign/steer_performance_campaign.py deleted file mode 100755 index 071a694a63..0000000000 --- a/pyamplicol/src/pyamplicol/_profiling_campaign/steer_performance_campaign.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Steer a copied pyAmpliCol profiling campaign.""" - -from __future__ import annotations - -import os -import sys -from importlib import import_module -from pathlib import Path - - -def _entrypoint_from_invocation(raw_entrypoint: str) -> Path: - """Preserve a trustworthy lexical campaign path for relative launchers.""" - - entrypoint = Path(raw_entrypoint) - if entrypoint.is_absolute(): - return Path(os.path.abspath(os.fspath(entrypoint))) - - logical_text = os.environ.get("PWD") - logical_cwd = Path(logical_text) if logical_text else None - try: - physical_cwd = Path.cwd() - same_directory = ( - logical_cwd is not None - and logical_cwd.is_absolute() - and logical_cwd.samefile(physical_cwd) - ) - except OSError: - same_directory = False - if not same_directory: - raise RuntimeError( - "campaign launcher cannot identify its working directory: " - "the shell PWD is missing or no longer names the physical directory. " - "Run `cd ..` and re-enter the intended campaign directory, then retry " - "(or invoke its absolute path from another working directory)." - ) - return Path(os.path.abspath(os.fspath(logical_cwd / entrypoint))) - - -def _repository_root(entrypoint: Path) -> Path: - for candidate in entrypoint.parents: - if (candidate / "tools/performance_report").is_dir() and ( - candidate / "src/pyamplicol" - ).is_dir(): - return candidate - raise RuntimeError("campaign entrypoint is not inside a pyAmpliCol checkout") - - -def _embedded_profile(entrypoint: Path, repo_root: Path) -> str: - """Derive the campaign identity from its directory under report profiles.""" - - profile_parent = repo_root / "docs/performance_reports" - try: - relative = entrypoint.parent.relative_to(profile_parent) - except ValueError as error: - raise RuntimeError( - "campaign entrypoint must be directly inside " - "docs/performance_reports/" - ) from error - if len(relative.parts) != 1: - raise RuntimeError( - "campaign entrypoint must be directly inside " - "docs/performance_reports/" - ) - return relative.parts[0] - - -def _reexecute_with_repository_python(repo_root: Path, entrypoint: Path) -> None: - expected = repo_root / ".venv/bin/python" - if not expected.is_file(): - raise RuntimeError( - f"repository Python is unavailable at {expected}; run `just dev-install`" - ) - try: - current_environment = Path(sys.prefix).resolve(strict=True) - expected_environment = (repo_root / ".venv").resolve(strict=True) - except OSError as error: - raise RuntimeError(f"cannot resolve repository Python: {error}") from error - if current_environment == expected_environment: - return - environment = dict(os.environ) - # macOS framework Python leaves this launcher hint behind when a shebang - # process execs a virtual-environment interpreter. Keeping it can make - # the new interpreter ignore the repository venv's site-packages. - environment.pop("__PYVENV_LAUNCHER__", None) - environment.pop("PYTHONHOME", None) - os.execve( - os.fspath(expected), - (os.fspath(expected), os.fspath(entrypoint), *sys.argv[1:]), - environment, - ) - - -def main() -> int: - # Keep the lexical path until the controller has rejected symlinked - # campaign directories and ancestors. Resolving here would erase the - # exact path that must be validated before campaign state is opened. - try: - entrypoint = _entrypoint_from_invocation(sys.argv[0]) - except RuntimeError as error: - sys.stderr.write(f"error: {error}\n") - return 2 - profile = entrypoint.parent.name - try: - repo_root = _repository_root(entrypoint) - source_profile = _embedded_profile(entrypoint, repo_root) - except RuntimeError: - installed = import_module( - "pyamplicol._performance_report.manual_campaign" - ) - return installed.main( - sys.argv[1:], - repo_root=entrypoint.parent, - profile=profile, - docs_dir=entrypoint.parent, - installed=True, - launcher_path_checked=True, - ) - - _reexecute_with_repository_python(repo_root, entrypoint) - sys.path.insert(0, os.fspath(repo_root)) - sys.path.insert(0, os.fspath(repo_root / "src")) - from tools.performance_report.manual_campaign import main as campaign_main - - return campaign_main( - sys.argv[1:], - repo_root=repo_root, - profile=source_profile, - docs_dir=entrypoint.parent, - launcher_path_checked=True, - ) - - -if __name__ == "__main__": - try: - raise SystemExit(main()) - except KeyboardInterrupt: - sys.stderr.write("Interrupted; workers were asked to stop cleanly.\n") - raise SystemExit(130) from None diff --git a/pyamplicol/src/pyamplicol/cli/parser.py b/pyamplicol/src/pyamplicol/cli/parser.py index f6699b0868..7727e07801 100644 --- a/pyamplicol/src/pyamplicol/cli/parser.py +++ b/pyamplicol/src/pyamplicol/cli/parser.py @@ -34,9 +34,7 @@ "compile": Action.MODEL_COMPILE, "processes": Action.MODEL_PROCESSES, } -_UTILITY_COMMANDS = frozenset( - {"config", "examples", "profiling-campaign", "doctor", "self-test"} -) +_UTILITY_COMMANDS = frozenset({"config", "examples", "doctor", "self-test"}) _DIRECT_COMMANDS = frozenset( { *(action.value for action in ACTIONS if not action.value.startswith("model-")), @@ -826,7 +824,6 @@ def build_parser() -> argparse.ArgumentParser: for name, help_text in ( ("config", "Create or resolve run configuration."), ("examples", "List, copy, or run packaged examples."), - ("profiling-campaign", "Copy the packaged profiling campaign."), ("doctor", "Diagnose the installed pyAmpliCol environment."), ("self-test", "Run the installed-package self-test."), ): diff --git a/pyamplicol/src/pyamplicol/cli/utilities.py b/pyamplicol/src/pyamplicol/cli/utilities.py index 3fc3a588bd..f5b16f81e0 100644 --- a/pyamplicol/src/pyamplicol/cli/utilities.py +++ b/pyamplicol/src/pyamplicol/cli/utilities.py @@ -4,11 +4,8 @@ from __future__ import annotations import argparse -import errno import os import shutil -import stat -import sys from collections.abc import Sequence from dataclasses import dataclass from importlib import resources @@ -26,49 +23,10 @@ "examples-list", "examples-copy", "examples-run", - "profiling-campaign-copy", "doctor", "self-test", ] -_PROFILING_CAMPAIGN_REQUIRED_FILES = ( - Path("README.md"), - Path("TABLE_FILLING.md"), - Path("build_pdf.py"), - Path("pyAmpliCol.tex"), - Path("report-workspace.json"), - Path("report_environment.json"), - Path("report_environment.tex"), - Path("result_tables.py"), - Path("result_validation_summary.tex"), - Path("steer_performance_campaign.py"), -) -_PROFILING_CAMPAIGN_GLOBS = ( - "result_*_table.tex", - "section_*.tex", - "results/*.json", -) -_PROFILING_CAMPAIGN_FILE_COUNT = 69 -_PROFILING_CAMPAIGN_LOCAL_AMPLICOL = ".pyamplicol-original-amplicol" -_PROFILING_CAMPAIGN_LOCAL_MADGRAPH = ".pyamplicol-madgraph" -_PROFILING_CAMPAIGN_STATE = "campaign_artifacts" -_PROFILING_CAMPAIGN_SUMMARY = "campaign_summary_ids" -_PROFILING_CAMPAIGN_PDF = "pyAmpliCol.pdf" -_PROFILING_CAMPAIGN_GENERATED_FILES = ( - "measurement_lineage.json", - "pyAmpliCol.aux", - "pyAmpliCol.bbl", - "pyAmpliCol.bcf", - "pyAmpliCol.blg", - "pyAmpliCol.fdb_latexmk", - "pyAmpliCol.fls", - "pyAmpliCol.log", - "pyAmpliCol.out", - "pyAmpliCol.run.xml", - "pyAmpliCol.synctex.gz", - "pyAmpliCol.toc", -) - @dataclass(frozen=True, slots=True) class UtilityInvocation: @@ -79,8 +37,6 @@ class UtilityInvocation: name: str | None = None force: bool = False overrides: tuple[str, ...] = () - local_amplicol: Path | None = None - local_madgraph: Path | None = None @dataclass(frozen=True, slots=True) @@ -153,49 +109,6 @@ def _utility_parser() -> argparse.ArgumentParser: run.add_argument("--set", dest="overrides", action="append", default=[]) _add_output_options(run) - profiling_campaign = commands.add_parser("profiling-campaign") - profiling_commands = profiling_campaign.add_subparsers( - dest="profiling_campaign_command", required=True - ) - campaign_copy = profiling_commands.add_parser( - "copy", - description=( - "Create a self-contained profiling campaign. Runtime state is stored " - "in the visible DEST/campaign_artifacts directory and moves with DEST." - ), - ) - campaign_copy.add_argument("destination", type=Path) - campaign_copy.add_argument( - "--force", - action="store_true", - help=( - "overwrite the managed template files and reset only " - "DEST/campaign_artifacts, DEST/pyAmpliCol.pdf, and " - "DEST/campaign_summary_ids, plus known lineage/LaTeX byproducts; " - "unrelated files and recorded local AmpliCol/MadGraph installations " - "are preserved (stop an active campaign first)" - ), - ) - campaign_copy.add_argument( - "--local-amplicol", - type=Path, - metavar="PATH_TO_COMPLETE_CHECKOUT", - help=( - "Record a clean, complete original-AmpliCol checkout as the " - "default for this copied campaign." - ), - ) - campaign_copy.add_argument( - "--local-madgraph", - type=Path, - metavar="PATH_TO_INSTALLATION", - help=( - "Record a complete MadGraph installation as the default for this " - "copied campaign." - ), - ) - _add_output_options(campaign_copy) - for name in ("doctor", "self-test"): command = commands.add_parser(name) _add_output_options(command) @@ -242,16 +155,6 @@ def parse_utility(argv: Sequence[str]) -> UtilityInvocation: name=namespace.name, overrides=tuple(namespace.overrides), ) - if namespace.utility == "profiling-campaign": - return UtilityInvocation( - "profiling-campaign-copy", - output_format=namespace.output_format, - output_color=namespace.output_color, - path=namespace.destination, - force=bool(namespace.force), - local_amplicol=namespace.local_amplicol, - local_madgraph=namespace.local_madgraph, - ) return UtilityInvocation( namespace.utility, output_format=namespace.output_format, @@ -285,39 +188,6 @@ def _runnable_example_names() -> tuple[str, ...]: ) -def _profiling_campaign_inventory(source: Path) -> tuple[Path, ...]: - selected = set(_PROFILING_CAMPAIGN_REQUIRED_FILES) - for pattern in _PROFILING_CAMPAIGN_GLOBS: - selected.update(path.relative_to(source) for path in source.glob(pattern)) - missing = tuple( - relative - for relative in _PROFILING_CAMPAIGN_REQUIRED_FILES - if not (source / relative).is_file() - ) - if missing or len(selected) != _PROFILING_CAMPAIGN_FILE_COUNT: - detail = ", ".join(path.as_posix() for path in missing) - raise ConfigurationError( - "packaged profiling campaign has an invalid inventory" - + (f": missing {detail}" if detail else "") - ) - for relative in selected: - path = source / relative - if path.is_symlink() or not path.is_file(): - raise ConfigurationError( - f"packaged profiling campaign has an unsafe member: {relative}" - ) - return tuple(sorted(selected, key=lambda path: path.as_posix())) - - -def profiling_campaign_root() -> Path: - packaged = resources.files("pyamplicol").joinpath("_profiling_campaign") - if not isinstance(packaged, os.PathLike): - raise ConfigurationError("packaged profiling campaign is unavailable") - path = Path(os.fspath(packaged)) - _profiling_campaign_inventory(path) - return path.resolve() - - def _copy_tree(source: Path, destination: Path, *, force: bool) -> Path: target = destination.expanduser().resolve(strict=False) if target.exists(): @@ -332,297 +202,6 @@ def _copy_tree(source: Path, destination: Path, *, force: bool) -> Path: return target -def _resolved_original_amplicol_checkout(path: Path) -> Path: - try: - repository = path.expanduser().resolve(strict=True) - except OSError as error: - raise ConfigurationError( - f"--local-amplicol checkout is unavailable: {path}" - ) from error - if not repository.is_dir(): - raise ConfigurationError(f"--local-amplicol is not a directory: {repository}") - return repository - - -def _resolved_madgraph_installation(path: Path) -> Path: - try: - installation = path.expanduser().resolve(strict=True) - except OSError as error: - raise ConfigurationError( - f"--local-madgraph installation is unavailable: {path}" - ) from error - if not installation.is_dir(): - raise ConfigurationError( - f"--local-madgraph is not a directory: {installation}" - ) - launcher = installation / "bin" / "mg5_aMC" - try: - launcher_mode = launcher.stat(follow_symlinks=False).st_mode - except OSError as error: - raise ConfigurationError( - "--local-madgraph must contain a regular executable bin/mg5_aMC" - ) from error - if not stat.S_ISREG(launcher_mode) or not os.access(launcher, os.X_OK): - raise ConfigurationError( - "--local-madgraph must contain a regular executable bin/mg5_aMC" - ) - return installation - - -def _literal_campaign_destination(destination: Path) -> Path: - """Return an absolute destination without accepting symlink traversal.""" - - target = Path(os.path.abspath(os.fspath(destination.expanduser()))) - try: - canonical = target.resolve(strict=False) - except OSError as error: - raise ConfigurationError( - f"profiling campaign destination is unavailable: {target}" - ) from error - if canonical != target: - raise ConfigurationError( - "profiling campaign destination must not traverse a symlink: " - f"{target}" - ) - if os.path.lexists(target): - try: - mode = target.lstat().st_mode - except OSError as error: - raise ConfigurationError( - f"cannot inspect profiling campaign destination: {target}" - ) from error - if stat.S_ISLNK(mode) or not stat.S_ISDIR(mode): - raise ConfigurationError(f"destination is not a real directory: {target}") - return target - - -def _acquire_campaign_reset_lock(target: Path) -> int: - """Exclusively claim one real campaign directory without creating state.""" - - import fcntl - - flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) - try: - descriptor = os.open(target, flags) - except OSError as error: - raise ConfigurationError( - f"cannot open profiling campaign destination: {target}" - ) from error - try: - fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB) - except OSError as error: - os.close(descriptor) - if error.errno in {errno.EACCES, errno.EAGAIN}: - raise ConfigurationError( - "profiling campaign is active; stop it before using --force: " - f"{target}" - ) from None - raise ConfigurationError( - f"cannot lock profiling campaign destination: {target}" - ) from error - return descriptor - - -def _release_campaign_reset_lock(descriptor: int) -> None: - import fcntl - - try: - fcntl.flock(descriptor, fcntl.LOCK_UN) - finally: - os.close(descriptor) - - -def _require_campaign_member(target: Path, relative: Path) -> Path: - """Prove that a literal managed member remains beneath ``target``.""" - - if relative.is_absolute() or not relative.parts or any( - part in {"", ".", ".."} for part in relative.parts - ): - raise ConfigurationError(f"invalid profiling campaign member: {relative}") - member = target.joinpath(*relative.parts) - try: - member.relative_to(target) - canonical_target = target.resolve(strict=False) - member.resolve(strict=False).relative_to(canonical_target) - except (OSError, ValueError) as error: - raise ConfigurationError( - f"profiling campaign member escapes its destination: {relative}" - ) from error - return member - - -def _preflight_managed_file(target: Path, relative: Path) -> Path: - """Reject links or non-files along one managed template output path.""" - - output = _require_campaign_member(target, relative) - cursor = target - for part in relative.parts[:-1]: - cursor /= part - if not os.path.lexists(cursor): - continue - mode = cursor.lstat().st_mode - if stat.S_ISLNK(mode) or not stat.S_ISDIR(mode): - raise ConfigurationError( - f"unsafe profiling campaign output ancestor: {cursor}" - ) - if os.path.lexists(output): - mode = output.lstat().st_mode - if stat.S_ISLNK(mode) or not stat.S_ISREG(mode): - raise ConfigurationError(f"unsafe profiling campaign output: {output}") - return output - - -def _preflight_removable_tree(path: Path) -> None: - """Validate one exact campaign-managed directory before its removal.""" - - if not os.path.lexists(path): - return - mode = path.lstat().st_mode - if stat.S_ISLNK(mode) or not stat.S_ISDIR(mode) or os.path.ismount(path): - raise ConfigurationError(f"unsafe campaign reset directory: {path}") - pending = [path] - while pending: - directory = pending.pop() - try: - entries = tuple(os.scandir(directory)) - except OSError as error: - raise ConfigurationError( - f"cannot inspect campaign reset directory: {directory}" - ) from error - for entry in entries: - child = Path(entry.path) - try: - child_mode = entry.stat(follow_symlinks=False).st_mode - except OSError as error: - raise ConfigurationError( - f"cannot inspect campaign reset member: {child}" - ) from error - if stat.S_ISLNK(child_mode): - raise ConfigurationError( - f"campaign reset directory contains a symlink: {child}" - ) - if stat.S_ISDIR(child_mode): - if os.path.ismount(child): - raise ConfigurationError( - f"campaign reset directory contains a mount: {child}" - ) - pending.append(child) - elif not stat.S_ISREG(child_mode): - raise ConfigurationError( - f"campaign reset directory contains a special file: {child}" - ) - - -def _preflight_removable_file(path: Path) -> None: - if not os.path.lexists(path): - return - mode = path.lstat().st_mode - if stat.S_ISLNK(mode) or not stat.S_ISREG(mode): - raise ConfigurationError(f"unsafe campaign reset file: {path}") - - -def _reset_profiling_campaign_outputs(target: Path) -> None: - """Remove only the exact campaign-managed runtime publications.""" - - state = _require_campaign_member(target, Path(_PROFILING_CAMPAIGN_STATE)) - summary = _require_campaign_member(target, Path(_PROFILING_CAMPAIGN_SUMMARY)) - pdf = _require_campaign_member(target, Path(_PROFILING_CAMPAIGN_PDF)) - generated = tuple( - _require_campaign_member(target, Path(name)) - for name in _PROFILING_CAMPAIGN_GENERATED_FILES - ) - _preflight_removable_tree(state) - _preflight_removable_tree(summary) - _preflight_removable_file(pdf) - for path in generated: - _preflight_removable_file(path) - if state.exists(): - shutil.rmtree(state) - if summary.exists(): - shutil.rmtree(summary) - if pdf.exists(): - pdf.unlink() - for path in generated: - if path.exists(): - path.unlink() - - -def _copy_profiling_campaign( - destination: Path, - *, - force: bool, - local_amplicol: Path | None = None, - local_madgraph: Path | None = None, -) -> Path: - validated_amplicol = ( - None - if local_amplicol is None - else _resolved_original_amplicol_checkout(local_amplicol) - ) - validated_madgraph = ( - None - if local_madgraph is None - else _resolved_madgraph_installation(local_madgraph) - ) - source = profiling_campaign_root() - target = _literal_campaign_destination(destination) - if target.exists() and any(target.iterdir()) and not force: - raise ConfigurationError( - f"destination is not empty: {target}; pass --force to reset" - ) - target.mkdir(parents=True, exist_ok=True) - if target.is_symlink() or not target.is_dir(): - raise ConfigurationError(f"destination is not a real directory: {target}") - reset_lock = _acquire_campaign_reset_lock(target) - try: - inventory = _profiling_campaign_inventory(source) - for relative in inventory: - _preflight_managed_file(target, relative) - if validated_amplicol is not None: - _preflight_managed_file( - target, - Path(_PROFILING_CAMPAIGN_LOCAL_AMPLICOL), - ) - if validated_madgraph is not None: - _preflight_managed_file( - target, - Path(_PROFILING_CAMPAIGN_LOCAL_MADGRAPH), - ) - if force: - _reset_profiling_campaign_outputs(target) - for relative in inventory: - output = target / relative - output.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(source / relative, output) - launcher = target / "steer_performance_campaign.py" - launcher_lines = launcher.read_bytes().splitlines(keepends=True) - if not launcher_lines or not launcher_lines[0].startswith(b"#!"): - raise ConfigurationError("profiling campaign launcher has no shebang") - launcher.write_bytes( - f"#!{sys.executable}\n".encode() + b"".join(launcher_lines[1:]) - ) - launcher.chmod( - launcher.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH - ) - local_amplicol_path = target / _PROFILING_CAMPAIGN_LOCAL_AMPLICOL - if validated_amplicol is not None: - local_amplicol_path.write_text( - f"{validated_amplicol}\n", - encoding="utf-8", - ) - local_madgraph_path = target / _PROFILING_CAMPAIGN_LOCAL_MADGRAPH - if validated_madgraph is not None: - local_madgraph_path.write_text( - f"{validated_madgraph}\n", - encoding="utf-8", - ) - state_root = target / _PROFILING_CAMPAIGN_STATE - state_root.mkdir() - finally: - _release_campaign_reset_lock(reset_lock) - return target - - def _copy_resource_tree(source: Traversable, destination: Path) -> None: destination.mkdir(parents=True, exist_ok=True) for child in source.iterdir(): @@ -719,15 +298,6 @@ def execute_utility(invocation: UtilityInvocation) -> object: ) _copy_packaged_models(destination / "models") return UtilityResult("examples copy", "complete", destination) - if invocation.kind == "profiling-campaign-copy": - assert invocation.path is not None - destination = _copy_profiling_campaign( - invocation.path, - force=invocation.force, - local_amplicol=invocation.local_amplicol, - local_madgraph=invocation.local_madgraph, - ) - return UtilityResult("profiling campaign copy", "complete", destination) if invocation.kind == "doctor": return run_doctor() if invocation.kind == "self-test": @@ -744,5 +314,4 @@ def execute_utility(invocation: UtilityInvocation) -> object: "execute_utility", "list_examples", "parse_utility", - "profiling_campaign_root", ] diff --git a/pyamplicol/tests/fixtures/numerical_acceptance/ufo-sm-seed101-v1.json b/pyamplicol/tests/fixtures/numerical_acceptance/ufo-sm-seed101-v1.json deleted file mode 100644 index 654386450c..0000000000 --- a/pyamplicol/tests/fixtures/numerical_acceptance/ufo-sm-seed101-v1.json +++ /dev/null @@ -1,1625 +0,0 @@ -{ - "kind": "pyamplicol-ufo-sm-numerical-acceptance", - "schema_version": 1, - "model": { - "kind": "ufo-sm-json-default-restriction", - "source_sha256": "c1222e3b70b71804e5212e994a3b76e2f098f7fc3ba1693c9f9c65578d7e3e00", - "restriction_sha256": "8fdd48a3624620c1a15bab602f43a41519038cf69d8fef6aeaaaf13a3f1846c1", - "external_parameters_sha256": "d6b5072d4bfc1d6e9660a3c6349f069fb3c4a4aaafea9a8633b948ab7aafff01" - }, - "point_policy": { - "generator": "generic_validation_point", - "seed": 101, - "stored_components": "canonical-binary64-decimal" - }, - "comparison": { - "relative_tolerance": "0.0000000001", - "absolute_tolerance": null, - "full_candidate_precision_digits": 200, - "native_precision": "binary64" - }, - "references": { - "full": { - "kind": "madgraph-standalone-ufo-sm", - "precision": "binary64", - "command_protocol": "generate-output-standalone-launch-force", - "madgraph_version": "version = 3.7.2\ndate = 2026-07-07", - "model_source_sha256": "f5a639915654d05a96bd3bea9bea0a21ab43f225684cf1988f8159345bd40dbf", - "driver_sha256": "9c243fd026ddfd624fa3a2e6dbd0a2ff34a7753a19896a879f47a134b5b12110", - "external_parameters_sha256": "d6b5072d4bfc1d6e9660a3c6349f069fb3c4a4aaafea9a8633b948ab7aafff01" - }, - "lc": { - "kind": "pyamplicol-recurrence-regression", - "precision_digits": 200, - "captured_source_revision": "546f16657f5038d3a4757780d251a9caf2a0ecca" - }, - "nlc": { - "kind": "pyamplicol-recurrence-regression", - "precision_digits": 200, - "captured_source_revision": "546f16657f5038d3a4757780d251a9caf2a0ecca" - } - }, - "catalog_max_n_final": 4, - "catalog_cases": [ - { - "id": "catalog:dd_z_jets:n1", - "family_id": 1, - "family_key": "dd_z_jets", - "n_final": 1, - "process": "d d~ > z", - "momenta": [ - [ - "45.594000000000001", - "0", - "0", - "45.594000000000001" - ], - [ - "45.594000000000001", - "0", - "0", - "-45.594000000000001" - ], - [ - "91.188000000000002", - "0", - "0", - "0" - ] - ], - "expected": { - "full": "142.10653372833232", - "lc": "142.1065337283316771630720519281830618215656701467945093745489031400198352158371309439349700067578697338864141170719902307518465149412502975033209900016614416142741044808017738627093943395178947669060418", - "nlc": "142.1065337283316737525152424482226734855640446719854922169078006245909239210193549663024730339556879741472550427958462279115447341677246458469334004706282352790667631995989217118372355521612360269942278" - } - }, - { - "id": "catalog:ud_w_jets:n1", - "family_id": 2, - "family_key": "ud_w_jets", - "n_final": 1, - "process": "u d~ > w+", - "momenta": [ - [ - "40.209501222878082", - "0", - "0", - "40.209501222878082" - ], - [ - "40.209501222878082", - "0", - "0", - "-40.209501222878082" - ], - [ - "80.419002445756163", - "0", - "0", - "0" - ] - ], - "expected": { - "full": "229.97056761327616", - "lc": "229.97056761327635753098110523948539254482256522483025375679394580267863704974167984386500379266665540344181452454355935540433709017743888286755792393967055394090096118467927443150248243098196751834485", - "nlc": "229.97056761327635201168748252085259102953113073186877206939500068829327939072917600416340823836618556261790132852503603984426066039108173076041056822685128083361655811981505555850329140411062624231763" - } - }, - { - "id": "catalog:dd_z_jets:n2", - "family_id": 1, - "family_key": "dd_z_jets", - "n_final": 2, - "process": "d d~ > z g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "504.15762567199999", - "-304.10842628649999", - "208.76026523528103", - "331.35611794513767" - ], - [ - "495.84237432800001", - "304.10842628649999", - "-208.76026523528103", - "-331.35611794513767" - ] - ], - "expected": { - "full": "0.36154106787235846", - "lc": "0.406733701356400980477344819798281964547132485640488237589799387080592726894664150379425887837651519884288598614624522573841816532322005277139137654826698129107951277968093762360293553604493833678076069826524", - "nlc": "0.361541067872356403952344829323217079108501349822615561398506938746084907686669668641325659181463018312028246226601999981663560174535609378900337409971875904180570105830589777290143789907993815661589896399039" - } - }, - { - "id": "catalog:ud_w_jets:n2", - "family_id": 2, - "family_key": "ud_w_jets", - "n_final": 2, - "process": "u d~ > w+ g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "503.23360797718527", - "-304.67514180251823", - "209.14929648601478", - "331.97361038249016" - ], - [ - "496.76639202281473", - "304.67514180251823", - "-209.14929648601478", - "-331.97361038249016" - ] - ], - "expected": { - "full": "0.74840094538556268", - "lc": "0.8419510635587580185294296462853350134567455501314195817442538681159914477786403588061823936361260769040911250746729316880543740079632357044117157747537175158282410835270734567234320207181417160317133472737", - "nlc": "0.7484009453855626352396102920220638467317761669955366404555899197379006365745713772290930984916827673852603843223146754010865504256849845946060260134281177186474946660348021721920023777648359873173902451978" - } - }, - { - "id": "catalog:dd_epem_jets:n2", - "family_id": 3, - "family_key": "dd_epem_jets", - "n_final": 2, - "process": "d d~ > e+ e-", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "499.99999999999994", - "-306.65836769058797", - "210.51071473894038", - "334.13453054936508" - ], - [ - "499.99999999999994", - "306.65836769058797", - "-210.51071473894038", - "-334.13453054936508" - ] - ], - "expected": { - "full": "0.00029643287701939142", - "lc": "0.000296432877019388357696549282918537768933406423293542123764771988433219534529326956012307564740668975770611723619347473495181260687648913436184893085265198380502835228731564754571905708622664671181641158", - "nlc": "0.000296432877019388350582160234453216899640661694635800897653228683078559519713067019428638143386424568128453315673515749314163575990040582311127248677358030909759624866080104792775445713006712089597504326" - } - }, - { - "id": "catalog:ud_epve_jets:n2", - "family_id": 4, - "family_key": "ud_epve_jets", - "n_final": 2, - "process": "u d~ > e+ ve", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "499.99999999999994", - "-306.65836769058797", - "210.51071473894038", - "334.13453054936508" - ], - [ - "499.99999999999994", - "306.65836769058797", - "-210.51071473894038", - "-334.13453054936508" - ] - ], - "expected": { - "full": "0.00042290087317927035", - "lc": "0.00042290087317927101667680485117210900708566461543135076562362064944785883078365193194497691987108553413800835685965744053997011788171359700776878346158600283900787979490723528363853135464143412179878595", - "nlc": "0.00042290087317927100652718389486960420085750993520054234644148266986310368853123716180615929096684836190585712378411773194172023022834668011849044816578299908142366488472301684408081986949904973216557403" - } - }, - { - "id": "catalog:dd_zz_jets:n2", - "family_id": 5, - "family_key": "dd_zz_jets", - "n_final": 2, - "process": "d d~ > z z", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "500.00000000000006", - "-301.515357817672", - "206.98021044385018", - "328.53071415120502" - ], - [ - "500.00000000000006", - "301.515357817672", - "-206.98021044385018", - "-328.53071415120502" - ] - ], - "expected": { - "full": "0.0090424170370014562", - "lc": "0.0090424170370013648845279919840604864829391659358048692463947855749456672962148595430803427854517900098592902941101001848666259886778203333078068868738995891075173352708083538172104162137425432736579449505317", - "nlc": "0.0090424170370013648845279919840604864829391659358048692463947855749456672962148595430803427854517900098592902941101001848666259886778203333078068868738995891075173352708083538172104162137425432736579449505317" - } - }, - { - "id": "catalog:gg_tt_jets:n2", - "family_id": 6, - "family_key": "gg_tt_jets", - "n_final": 2, - "process": "g g > t t~", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "500.00000000000006", - "-287.71746404131949", - "197.50841776906941", - "313.49654829996268" - ], - [ - "500.00000000000006", - "287.71746404131949", - "-197.50841776906941", - "-313.49654829996268" - ] - ], - "expected": { - "full": "1.2610084500232903", - "lc": "1.6878740643879328250280033384515409661517475904750590138577663633669181966161042477988263203321837149785427042672253033492835720424525254871719536852878152133513739250681130658663008879735867482594106209936418", - "nlc": "1.26100845002328709396113227586451050337149832360108834320173270021687758321679415237080902723157117758909670503034917661514817267890778244486154273809695951448244927757661746744731218630968331082720920966212" - } - }, - { - "id": "catalog:dd_tt_jets:n2", - "family_id": 7, - "family_key": "dd_tt_jets", - "n_final": 2, - "process": "d d~ > t t~", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "500.00000000000006", - "-287.71746404131949", - "197.50841776906941", - "313.49654829996268" - ], - [ - "500.00000000000006", - "287.71746404131949", - "-197.50841776906941", - "-313.49654829996268" - ] - ], - "expected": { - "full": "0.73920207615248823", - "lc": "0.924002595190608125103802206134566346136990859129272389616301871381931679869555297954080981962509123346720614981687643693018139715654310155871375684678354704978407418966766502445392626632623578986130943", - "nlc": "0.7392020761524864643802649432526023840665888019351189535728266553999803444316071007207571098670967720644692806134794243269686877006555114179154441267934558670200616003901330338951385202584503174225044276" - } - }, - { - "id": "catalog:gg_gluons:n2", - "family_id": 8, - "family_key": "gg_gluons", - "n_final": 2, - "process": "g g > g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "499.99999999999994", - "-306.65836769058797", - "210.51071473894038", - "334.13453054936508" - ], - [ - "499.99999999999994", - "306.65836769058797", - "-210.51071473894038", - "-334.13453054936508" - ] - ], - "expected": { - "full": "165.3364278744663", - "lc": "186.00348135877425216846523106011254900394998008176597202719652802042954685464434667511827369662439335588850389246630513367989312057055392948447348769645380752332242558464170604198515478397123250262088579304", - "nlc": "165.33642787446599699940513832406534195305107497723107694158970675653463381946014449050068848912474809470540644129286839214416641411534939123876870232330423464310169892634437331991273249990348265252061551" - } - }, - { - "id": "catalog:dd_z_jets:n3", - "family_id": 1, - "family_key": "dd_z_jets", - "n_final": 3, - "process": "d d~ > z g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "312.48956564409934", - "-193.66118273046334", - "121.57983298112629", - "192.47900614913141" - ], - [ - "487.79620348021274", - "250.47715399872871", - "-206.71282928308619", - "-363.97271554910253" - ], - [ - "199.71423087568797", - "-56.81597126826545", - "85.132996301959906", - "171.49370939997104" - ] - ], - "expected": { - "full": "0.00017631238848843083", - "lc": "0.00022866903494322777184789097865160576625012684154671490824158388339590189548398253482192251668524571600856818684485074738589444776380122275411388018886878734376854000482302357886069556880559639010461955138435905", - "nlc": "0.000176312388488430309991648207894224321123263898940162375052410862306334784514692159689558997784847564392535584833873113167504696026177391654637809783418664241495889520626711846495166510779996545718826107815627" - } - }, - { - "id": "catalog:ud_w_jets:n3", - "family_id": 2, - "family_key": "ud_w_jets", - "n_final": 3, - "process": "u d~ > w+ g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "310.39704012395219", - "-194.25061519123031", - "121.94987667869806", - "193.06484050499387" - ], - [ - "489.28087331707053", - "251.23951310015411", - "-207.34198609147984", - "-365.0805128389535" - ], - [ - "200.32208655897728", - "-56.988897908923896", - "85.392109412781764", - "172.01567233395957" - ] - ], - "expected": { - "full": "0.00036371847402838503", - "lc": "0.000471802455887629381751012889850229888032057171583165492366500234992781591587899976039282633880020820894197294586755868847973943089271659093712502754705677157184063491263792917257584986048424882556926450601877", - "nlc": "0.00036371847402838502469903577196089132768455237765431682839738136773674757167847031249069141480400207711127675112267240318340066086493292821067928823856229364459017572541706785313721388000256441899530004011129" - } - }, - { - "id": "catalog:dd_epem_jets:n3", - "family_id": 3, - "family_key": "dd_epem_jets", - "n_final": 3, - "process": "d d~ > e+ e- g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "303.00992326176095", - "-196.331453120389", - "123.25621966556298", - "195.13297626103395" - ], - [ - "494.52211385681227", - "253.93082353769123", - "-209.56306049343993", - "-368.99130291580417" - ], - [ - "202.46796288142687", - "-57.59937041730231", - "86.306840827876954", - "173.85832665477017" - ] - ], - "expected": { - "full": "0.00000023666323813983404", - "lc": "0.000000266246142907310901325355677018696429262566038402124896647571207992471742911774178426532602105924836073319636326230387585553669388994611922772295906761290474934178482353991228883532360108864299509867621", - "nlc": "0.0000002366632381398318971427578052895988839464912970716030434163064446724252066375261039185253828910021482446516458195918923494195062313331612865221822320943354822286581774501340738632084350697116897455969543" - } - }, - { - "id": "catalog:ud_epve_jets:n3", - "family_id": 4, - "family_key": "ud_epve_jets", - "n_final": 3, - "process": "u d~ > e+ ve g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "303.00992326176095", - "-196.331453120389", - "123.25621966556298", - "195.13297626103395" - ], - [ - "494.52211385681227", - "253.93082353769123", - "-209.56306049343993", - "-368.99130291580417" - ], - [ - "202.46796288142687", - "-57.59937041730231", - "86.306840827876954", - "173.85832665477017" - ] - ], - "expected": { - "full": "0.00000026222888441700588", - "lc": "0.00000029500749496913309995141368236988967401699007480994826335657432170761032857377380640398814595055344089461821197133139341979477350447304533882423604706380193187700297882778710336474192790983575707412822", - "nlc": "0.00000026222888441700718317416355941810780189023502501067477890596403010748575444712641521504632642580429425722388545414326770153707319045677019729665045403457799744524085932841196732137891816129879264946207" - } - }, - { - "id": "catalog:dd_zz_jets:n3", - "family_id": 5, - "family_key": "dd_zz_jets", - "n_final": 3, - "process": "d d~ > z z g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "309.98693239254516", - "-191.96520759226249", - "120.51510554770157", - "190.79338384500207" - ], - [ - "492.04782104310141", - "248.2836167091192", - "-204.90255520405609", - "-360.78524830423976" - ], - [ - "197.96524656435344", - "-56.318409116856806", - "84.387449656354519", - "169.99186445923763" - ] - ], - "expected": { - "full": "0.000011028108806289972", - "lc": "0.00001240662240707612813324703832178871836279742434792171652467086755723448166029895112872581788260756289707390947803090730806359497520688232506770408844106084876428211533265727176290482021957131949080965007215953", - "nlc": "0.00001102810880628989096819840379459246029776619711417221449389840825799522140565637996952799255419972502988583554768611724029634522775894631910900060017830403949441818231534484519897727904844971259102324984327627" - } - }, - { - "id": "catalog:gg_tt_jets:n3", - "family_id": 6, - "family_key": "gg_tt_jets", - "n_final": 3, - "process": "g g > t t~ g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "327.78016913065488", - "-180.39074377820512", - "113.24869646396822", - "179.28957466534038" - ], - [ - "486.19081801910795", - "233.31345741167567", - "-192.5480392979517", - "-339.03184906320229" - ], - [ - "186.02901285023736", - "-52.922713633470622", - "79.299342833983488", - "159.74227439786188" - ] - ], - "expected": { - "full": "0.0041234764122830402", - "lc": "0.005498647106423893281886883039692273222330614852654020152618248181068760112272295505879887872542713611472137213742699115336550927319641880063792317510519764567992737663647635861239848036129544386653854204580388", - "nlc": "0.004099225748770255672098790545878946580118185128069156274600967727592194049528969226888012825288930608379385616765966572671115456573788536907570925765360749829487479650246440574331402245208776105600804582681" - } - }, - { - "id": "catalog:dd_tt_jets:n3", - "family_id": 7, - "family_key": "dd_tt_jets", - "n_final": 3, - "process": "d d~ > t t~ g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "327.78016913065488", - "-180.39074377820512", - "113.24869646396822", - "179.28957466534038" - ], - [ - "486.19081801910795", - "233.31345741167567", - "-192.5480392979517", - "-339.03184906320229" - ], - [ - "186.02901285023736", - "-52.922713633470622", - "79.299342833983488", - "159.74227439786188" - ] - ], - "expected": { - "full": "0.001055791108500876", - "lc": "0.0015530561536812689777429967533121489028956234696374552770061036600912134736319241268311463390973016613278224707334797345134084692937023716543246453183954922956587807720588433077307834853154662989113147736725", - "nlc": "0.001055791108500874142191908091927224326704140141033006344076728055738504904440144845187070652745087767144598827170004048179928827015155779166913689196724562680181397369201884355946448806444377881546896516" - } - }, - { - "id": "catalog:gg_gluons:n3", - "family_id": 8, - "family_key": "gg_gluons", - "n_final": 3, - "process": "g g > g g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "303.00992326176095", - "-196.331453120389", - "123.25621966556298", - "195.13297626103395" - ], - [ - "494.52211385681227", - "253.93082353769123", - "-209.56306049343993", - "-368.99130291580417" - ], - [ - "202.46796288142687", - "-57.59937041730231", - "86.306840827876954", - "173.85832665477017" - ] - ], - "expected": { - "full": "0.54499571545662018", - "lc": "0.61312017988870141895096325191023036099439898686616580975870190773457471390422531338691835062271078019080994903818393502895975306455156810460532373714066429789120043177101961353963551830888929457599376923382768636", - "nlc": "0.5449957154566211248154238647597053100201890766933366783706880608633809734786336718337661801790197758782318923155091175027700354117565032127253120264264397403244966153999193220740606516995663454023019245418086" - } - }, - { - "id": "catalog:dd_zzz_jets:n3", - "family_id": 9, - "family_key": "dd_zzz_jets", - "n_final": 3, - "process": "d d~ > z z z", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "303.95306247003941", - "-187.87079311487679", - "117.94464604054834", - "186.72396312651625" - ], - [ - "481.91719597099183", - "242.9879902385625", - "-200.53220081013504", - "-353.0900812351025" - ], - [ - "214.12974155896882", - "-55.117197123685791", - "82.587554769586717", - "166.36611810858622" - ] - ], - "expected": { - "full": "0.00000014647132653168889", - "lc": "0.0000001464713265316869800520794730160284038912011013474592914108157089879994148610025965262600019017665935142850477191789064192163726931671793693925359681393606315889711586608630709341781712646919340816652020040544", - "nlc": "0.0000001464713265316869695061439627345651652016063861797669351102746412386196300476432134299959038545791254626626357719862180868585722919538639149144763824502569487305679685242618935904505789400754768222709547204631" - } - }, - { - "id": "catalog:dd_z_jets:n4", - "family_id": 1, - "family_key": "dd_z_jets", - "n_final": 4, - "process": "d d~ > z g g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "300.37140982458777", - "-210.34453868661902", - "87.704153573306712", - "173.12102410369954" - ], - [ - "357.12242829640621", - "151.57318148300286", - "-187.59017005274106", - "-263.38551127012698" - ], - [ - "183.94449464488207", - "-81.602974117292263", - "61.235780320717993", - "153.05786792545604" - ], - [ - "158.56166723412403", - "140.37433132090848", - "38.650236158716361", - "-62.793380759028615" - ] - ], - "expected": { - "full": "0.000000035538847721871692", - "lc": "0.000000049469038090473216897119401175245771989229362094959206211600461468034063798042438035492000663386626460798687901683737336969157021524824204717047392232921150285466902836283518258784151085644291659508822676562877", - "nlc": "0.0000000352987950682156084272081702316323349546137541356434040376852518162253925256156621119958656138451168394069208619763546355501783263005970319279807616363248888375758173373192599426939178509051012552325106043889" - } - }, - { - "id": "catalog:ud_w_jets:n4", - "family_id": 2, - "family_key": "ud_w_jets", - "n_final": 4, - "process": "u d~ > w+ g g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "298.15299166642154", - "-211.01150992056549", - "87.982250394342643", - "173.66996511157876" - ], - [ - "358.25481037848004", - "152.05379748814443", - "-188.18499056948721", - "-264.22066753590093" - ], - [ - "184.52775526736841", - "-81.861725006098553", - "61.429949868533221", - "153.54319165039263" - ], - [ - "159.06444268773024", - "140.81943743851966", - "38.772790306611334", - "-62.992489226070475" - ] - ], - "expected": { - "full": "0.000000072771501409999417", - "lc": "0.0000001012865746931596959737069594481164851504853132405366604633596987513113640512925333512065965311658608749387891401852021396150083736264094237118726586295399437105564561613237941811054373292676792917342655823384", - "nlc": "0.00000007227651332284122746120624693324600837730958861140072390895612022021277734414569417527733145489021162371322115203343951429515837312734989248553011741549488185062564090212158329371329927644192459470193839715" - } - }, - { - "id": "catalog:dd_epem_jets:n4", - "family_id": 3, - "family_key": "dd_epem_jets", - "n_final": 4, - "process": "d d~ > e+ e- g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.31075577423769", - "-213.36929162671257", - "88.965338665326172", - "175.61050317417747" - ], - [ - "362.257846224096", - "153.7528027329422", - "-190.28771533698082", - "-267.17299301111615" - ], - [ - "186.58961514320916", - "-82.776424293003245", - "62.11635039741472", - "155.25883895566528" - ], - [ - "160.84178285845738", - "142.39291318677365", - "39.206026274239925", - "-63.696349118726602" - ] - ], - "expected": { - "full": "0.0000000000424909519514746", - "lc": "0.0000000000549885088289780349922545138477977432927959222290641543247394546139877459565655642153323014279909197140689352625730696639505052819892166629902021865997241109272876458274806001181288687572126976061436472881", - "nlc": "0.00000000004249095195147435805387504941647082381613178399812038666733776066691496014658832123105355569082911555090487099048064660566041552442424657371474351516261809903924053349115554357162718153345538292564774273" - } - }, - { - "id": "catalog:ud_epve_jets:n4", - "family_id": 4, - "family_key": "ud_epve_jets", - "n_final": 4, - "process": "u d~ > e+ ve g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.31075577423769", - "-213.36929162671257", - "88.965338665326172", - "175.61050317417747" - ], - [ - "362.257846224096", - "153.7528027329422", - "-190.28771533698082", - "-267.17299301111615" - ], - [ - "186.58961514320916", - "-82.776424293003245", - "62.11635039741472", - "155.25883895566528" - ], - [ - "160.84178285845738", - "142.39291318677365", - "39.206026274239925", - "-63.696349118726602" - ] - ], - "expected": { - "full": "0.000000000054487229301925616", - "lc": "0.00000000007017853150693386643654001957586773028803096037819722996102943421982911863918202893331036561208870428944241045324899471938430159163110108821248113763427344472397277261249364116133030588885929134350095455", - "nlc": "0.0000000000544872293019260846175862629691090291655941645115128444748867052082733465665899390106555853574283860728388266819286277664181624350717564898970317074202166338696898268940600142211231147593248278115444604" - } - }, - { - "id": "catalog:dd_zz_jets:n4", - "family_id": 5, - "family_key": "dd_zz_jets", - "n_final": 4, - "process": "d d~ > z z g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "297.12168084047005", - "-207.836389371785", - "86.65836881432746", - "171.05672816000515" - ], - [ - "364.45620244094101", - "149.76582212079853", - "-185.35334394151809", - "-260.24490113708436" - ], - [ - "181.75113958517022", - "-80.6299398521829", - "60.505604574707498", - "151.23280515480278" - ], - [ - "156.67097713341875", - "138.7005071031694", - "38.189370552483133", - "-62.044632177723578" - ] - ], - "expected": { - "full": "0.0000000019082866212806233", - "lc": "0.0000000025000011917449759563437217295467915519479084735477322001190128799067088278692472627765955019375097174945804832544211822019734974727372993141968157120071495837450570537587135395878106465727188218406854091083988", - "nlc": "0.000000001908286621280602063295305263807535577621112708881647296934790346905622034020400826223262743154586420687347018265070862631190187245853054381204054169616850130215886433551713335402914496871740914218663758068726" - } - }, - { - "id": "catalog:gg_tt_jets:n4", - "family_id": 6, - "family_key": "gg_tt_jets", - "n_final": 4, - "process": "g g > t t~ g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "314.65690620656977", - "-193.17230180786569", - "80.544107917663595", - "158.98766341288447" - ], - [ - "370.7986607092069", - "139.19895682690071", - "-172.2755683217658", - "-241.88308283436604" - ], - [ - "168.92752080611501", - "-74.941020304264356", - "56.236576007221046", - "140.56243552400588" - ], - [ - "145.61691227810837", - "128.91436528522939", - "35.494884396881169", - "-57.667016102524293" - ] - ], - "expected": { - "full": "0.0000013297504115314729", - "lc": "0.00000181314005319235749767037933567868945319675161558162928086809010060093169432965963992437853938552399976018847351715669551012699682956593917457750915770953667340503045479298179995272883209767825246667733361421801", - "nlc": "0.000001334994216442333805199546027503433542754776795537867615016444753042864780469996339784970768811052860055090830239907368865695958272876617426706472888276494781559661443454136988905904271189224290715804796378" - } - }, - { - "id": "catalog:dd_tt_jets:n4", - "family_id": 7, - "family_key": "dd_tt_jets", - "n_final": 4, - "process": "d d~ > t t~ g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "314.65690620656977", - "-193.17230180786569", - "80.544107917663595", - "158.98766341288447" - ], - [ - "370.7986607092069", - "139.19895682690071", - "-172.2755683217658", - "-241.88308283436604" - ], - [ - "168.92752080611501", - "-74.941020304264356", - "56.236576007221046", - "140.56243552400588" - ], - [ - "145.61691227810837", - "128.91436528522939", - "35.494884396881169", - "-57.667016102524293" - ] - ], - "expected": { - "full": "0.00000010521886363225839", - "lc": "0.00000019228625624912442915499464622016179123007555406846728804028872165990037494616304694310225413403320094528634900774236211375564218411731444412732629246610880693104945861113034797817808899117896958242354616424327", - "nlc": "0.00000010434231717649263869987084847320844023376768057959947054959384226612882985836410423843222776622915858660412871758739753336556553197701007970419742095222358116316635619457501344974341714306337233946800361" - } - }, - { - "id": "catalog:gg_gluons:n4", - "family_id": 8, - "family_key": "gg_gluons", - "n_final": 4, - "process": "g g > g g g g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.31075577423769", - "-213.36929162671257", - "88.965338665326172", - "175.61050317417747" - ], - [ - "362.257846224096", - "153.7528027329422", - "-190.28771533698082", - "-267.17299301111615" - ], - [ - "186.58961514320916", - "-82.776424293003245", - "62.11635039741472", - "155.25883895566528" - ], - [ - "160.84178285845738", - "142.39291318677365", - "39.206026274239925", - "-63.696349118726602" - ] - ], - "expected": { - "full": "0.0001887433739424267", - "lc": "0.0002119883742276068760685181223298585009934290154199226320684050844344779661540786287621514339243264245279803304297811418804253432454641678472946805675739226064420416160768293803958518966703805218536945408263739153316", - "nlc": "0.00018878203188216711218589720227208194236963802768492492668688663228704060626610087489080961066176703351380077689983669556237395452840315867517940414747595664053636712232809681527251400252116941751028160741435924" - } - }, - { - "id": "catalog:dd_zzz_jets:n4", - "family_id": 9, - "family_key": "dd_zzz_jets", - "n_final": 4, - "process": "d d~ > z z z g", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.87287037663418", - "-203.00542771759544", - "84.644076427791873", - "167.08067518424895" - ], - [ - "356.5209915182034", - "146.28465625778162", - "-181.04497956045921", - "-254.1957528532262" - ], - [ - "199.57683067714848", - "-78.755772634483975", - "59.099208628129098", - "147.7175406490696" - ], - [ - "153.02930742801391", - "135.47654409429785", - "37.30169450453824", - "-60.602462980092348" - ] - ], - "expected": { - "full": "0.000000000070486729249754583", - "lc": "0.0000000000792975704059726863009193253330169756829588739865624487291534027778342400965232808525390864110591632851058177142186077385020044795565601145983676791563999543773796882798976779102182971479024683712925189107533", - "nlc": "0.0000000000704867292497534938591060054248739525453893504774918569909153555420043700245032018590196222649986677237358834578457573983061371650848358723267860849532508235804208352387228270016718473509882815128685472167471" - } - }, - { - "id": "catalog:dd_epemzh_jets:n4", - "family_id": 10, - "family_key": "dd_epemzh_jets", - "n_final": 4, - "process": "d d~ > e+ e- z h", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "270.65098032849863", - "-198.91997386302734", - "82.940627056037428", - "163.71820159854309" - ], - [ - "337.72583089717784", - "143.34069944100176", - "-177.40147643883617", - "-249.08010136555396" - ], - [ - "196.40565064490178", - "-77.170824495429102", - "57.909845898243887", - "144.74474724833556" - ], - [ - "195.21753812942174", - "132.75009891745472", - "36.55100348455484", - "-59.382847481324681" - ] - ], - "expected": { - "full": "0.0000000000000043627308885228678", - "lc": "0.000000000000004362730888522779072181106118527979331096051610683739284691232996668770982424442693294285674542813097096973749513339824565679084099720079317258544372383540180400304894396455282998004642813545488467335710735", - "nlc": "0.000000000000004362730888522778967475564793981277410527851784144158515658001278675797388505582053524838339601762867256224162843816300608325628998623331446822321935231721748746342471118753687232190246190554865882648448146" - } - }, - { - "id": "catalog:dd_ttzh_jets:n4", - "family_id": 11, - "family_key": "dd_ttzh_jets", - "n_final": 4, - "process": "d d~ > t t~ z h", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "294.88538952715049", - "-175.51504741897966", - "73.181831909570974", - "144.45511608957261" - ], - [ - "344.56704357168957", - "126.47523107348077", - "-156.52841665261553", - "-219.77333373471285" - ], - [ - "178.53102628594573", - "-68.090904385517319", - "51.096172754651874", - "127.71407859943305" - ], - [ - "182.01654061521435", - "117.13072073101625", - "32.250411988392671", - "-52.395860954292807" - ] - ], - "expected": { - "full": "0.00000000066920840275964804", - "lc": "0.000000000836510503449559851231072110446059165679624184606167947324941649438676205388408515025078530230101842862573043985948169817605821133314054636541145505709018902564926992659009099785013224981663562131059233319", - "nlc": "0.0000000006692084027596478486627105763467572270169985285290438615541721825402623496199058885534520776862455924655100353867931630868468777689742879470828351881296528187778230391297169032684081325840854619654244388" - } - }, - { - "id": "catalog:dd_4l_jets:n4", - "family_id": 12, - "family_key": "dd_4l_jets", - "n_final": 4, - "process": "d d~ > e+ e- e+ e-", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.31075577423769", - "-213.36929162671257", - "88.965338665326172", - "175.61050317417747" - ], - [ - "362.257846224096", - "153.7528027329422", - "-190.28771533698082", - "-267.17299301111615" - ], - [ - "186.58961514320916", - "-82.776424293003245", - "62.11635039741472", - "155.25883895566528" - ], - [ - "160.84178285845738", - "142.39291318677365", - "39.206026274239925", - "-63.696349118726602" - ] - ], - "expected": { - "full": "0.00000000000000026694593189474546", - "lc": "0.00000000000000026694593189473874253916983328023425774528222221014053107751535791050521507933373350232615233072827840317446331944606579594368356248648123582511027011970744907852086694298147900451276132048726150008344053", - "nlc": "0.00000000000000026694593189473874253916983328023425774528222221014053107751535791050521507933373350232615233072827840317446331944606579594368356248648123582511027011970744907852086694298147900451276132048726150008344053" - } - }, - { - "id": "catalog:dd_3q_lines:n4", - "family_id": 13, - "family_key": "dd_3q_lines", - "n_final": 4, - "process": "d d~ > u u~ s s~", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.31075577423769", - "-213.36929162671257", - "88.965338665326172", - "175.61050317417747" - ], - [ - "362.257846224096", - "153.7528027329422", - "-190.28771533698082", - "-267.17299301111615" - ], - [ - "186.58961514320916", - "-82.776424293003245", - "62.11635039741472", - "155.25883895566528" - ], - [ - "160.84178285845738", - "142.39291318677365", - "39.206026274239925", - "-63.696349118726602" - ] - ], - "expected": { - "full": "0.00000000060125965786352068", - "lc": "0.00000000118174717425276052809465310358387087946882347197109385153479972473173004546288743505638610950692102578502600956002570114131165271095415507413627619033616360590755346679234681796423919330077105808874998647", - "nlc": "0.000000000601259657863520599963576540455578253157343523051020036267855165091993041637388361616115301427905380829814161343354563516388998585894742581019697713014219020282493573017608746400843850662614031646325418" - } - }, - { - "id": "catalog:dd_3q_identical_lines:n4", - "family_id": 15, - "family_key": "dd_3q_identical_lines", - "n_final": 4, - "process": "d d~ > u u~ u u~", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "290.31075577423769", - "-213.36929162671257", - "88.965338665326172", - "175.61050317417747" - ], - [ - "362.257846224096", - "153.7528027329422", - "-190.28771533698082", - "-267.17299301111615" - ], - [ - "186.58961514320916", - "-82.776424293003245", - "62.11635039741472", - "155.25883895566528" - ], - [ - "160.84178285845738", - "142.39291318677365", - "39.206026274239925", - "-63.696349118726602" - ] - ], - "expected": { - "full": "0.00000000037697272019965055", - "lc": "0.00000000087519841416157061042890812509782050284145301184555807810099927371832930855029765098227958923557633835345622285110757763154209767677161365114426989947253923992595442785129840537386733128249876128990748363", - "nlc": "0.000000000376972720199650165192493512405126655433720902066270040431048396855514706382122571138601419955898074209827531747111343906360180628989470751322287030514523880061331437479675271500889757029984635975516199" - } - } - ], - "extra_full_colour_cases": [ - { - "id": "extra:identical-u-four-lines", - "process": "u u~ > u u~ u u~ u u~", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "87.426649869533108", - "-1.7683549991323071", - "-13.872238563808319", - "86.300944521110353" - ], - [ - "271.51948426401049", - "188.89524479352281", - "-179.52309551815529", - "-76.242212749687639" - ], - [ - "79.098818575548165", - "28.124777996640972", - "-16.760518635882654", - "72.004895512342586" - ], - [ - "127.91723131205379", - "120.71852712172512", - "-40.699253856211726", - "-11.551017775521951" - ], - [ - "114.48696971232674", - "-72.435438812038697", - "70.964759342285447", - "-53.144862117707397" - ], - [ - "319.55084626652774", - "-263.53475610071791", - "179.89034723177252", - "-17.367747390535968" - ] - ], - "expected": { - "full": "0.000000000000016966596563230786" - } - }, - { - "id": "extra:identical-electron-three-pair", - "process": "e+ e- > e+ e- e+ e- e+ e-", - "momenta": [ - [ - "500", - "0", - "0", - "500" - ], - [ - "500", - "0", - "0", - "-500" - ], - [ - "87.426649869533108", - "-1.7683549991323071", - "-13.872238563808319", - "86.300944521110353" - ], - [ - "271.51948426401049", - "188.89524479352281", - "-179.52309551815529", - "-76.242212749687639" - ], - [ - "79.098818575548165", - "28.124777996640972", - "-16.760518635882654", - "72.004895512342586" - ], - [ - "127.91723131205379", - "120.71852712172512", - "-40.699253856211726", - "-11.551017775521951" - ], - [ - "114.48696971232674", - "-72.435438812038697", - "70.964759342285447", - "-53.144862117707397" - ], - [ - "319.55084626652774", - "-263.53475610071791", - "179.89034723177252", - "-17.367747390535968" - ] - ], - "expected": { - "full": "0.000000000000000000003588368997450193" - } - } - ] -} diff --git a/pyamplicol/tests/integration/test_numerical_acceptance.py b/pyamplicol/tests/integration/test_numerical_acceptance.py deleted file mode 100644 index 5d3062d65c..0000000000 --- a/pyamplicol/tests/integration/test_numerical_acceptance.py +++ /dev/null @@ -1,74 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Environment-gated real numerical acceptance across all fifteen UFO-SM lanes.""" - -from __future__ import annotations - -import importlib.util -import os - -import pytest - -from tools.developer.numerical_acceptance import ( - DEFAULT_FIXTURE, - EXTRA_FULL_COLOUR_CASES, - NumericalAcceptanceHarness, - catalog_cases, -) - -pytestmark = pytest.mark.skipif( - os.environ.get("PYAMPLICOL_RUN_NUMERICAL_ACCEPTANCE") != "1", - reason=( - "set PYAMPLICOL_RUN_NUMERICAL_ACCEPTANCE=1 to run the full numerical " - "acceptance matrix" - ), -) - - -def _unavailable(reason: str) -> None: - if os.environ.get("PYAMPLICOL_REQUIRE_NATIVE_TESTS") == "1": - pytest.fail(reason) - pytest.skip(reason) - - -def _require_native_dependencies() -> None: - if importlib.util.find_spec("pyamplicol._rusticol") is None: - _unavailable("the Rusticol extension has not been built") - if importlib.util.find_spec("symbolica") is None: - _unavailable("Symbolica is unavailable") - - -@pytest.fixture(scope="module") -def acceptance( - tmp_path_factory: pytest.TempPathFactory, -) -> NumericalAcceptanceHarness: - _require_native_dependencies() - if not DEFAULT_FIXTURE.is_file(): - pytest.fail( - f"the numerical acceptance fixture has not been captured: {DEFAULT_FIXTURE}" - ) - return NumericalAcceptanceHarness.prepare( - DEFAULT_FIXTURE, - work_root=tmp_path_factory.mktemp("numerical-acceptance"), - ) - - -@pytest.mark.parametrize( - "case_id", - tuple(case.case_id for case in catalog_cases()), -) -def test_catalog_numerical_acceptance_case( - acceptance: NumericalAcceptanceHarness, - case_id: str, -) -> None: - acceptance.assert_catalog_case(case_id) - - -@pytest.mark.parametrize( - "case_id", - tuple(case.case_id for case in EXTRA_FULL_COLOUR_CASES), -) -def test_non_catalog_full_colour_madgraph_benchmark( - acceptance: NumericalAcceptanceHarness, - case_id: str, -) -> None: - acceptance.assert_full_extra(case_id) diff --git a/pyamplicol/tests/integration/test_on_the_fly_artifact_probe.py b/pyamplicol/tests/integration/test_on_the_fly_artifact_probe.py deleted file mode 100644 index f25c8cdecf..0000000000 --- a/pyamplicol/tests/integration/test_on_the_fly_artifact_probe.py +++ /dev/null @@ -1,790 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Genuine-artifact canary for the hidden on-the-fly execution probe.""" - -from __future__ import annotations - -import importlib -import importlib.util -import json -import math -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -import pytest - -import pyamplicol.generation.service as generation_service -from pyamplicol import Generator, ModelSource, ProcessRequest, Runtime -from pyamplicol.config import ( - ColorConfig, - EvaluatorConfig, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationRelationDiscoveryConfig, - GenerationValidationConfig, - JITConfig, - ProcessConfig, - RunConfig, -) -from tools.developer import on_the_fly_lc_gate as lc_gate - -_MODEL = ( - Path(__file__).resolve().parents[2] - / "src" - / "pyamplicol" - / "assets" - / "models" - / "json" - / "scalars" - / "scalars.json" -) -_HELICITIES = (0, 0, 0, 0) -_SM_SEEDS = (101, 211) -_IDENTICAL_SIX_FERMION_HELICITIES = ( - "h:-1,+1,-1,+1,-1,+1", - "h:-1,+1,+1,-1,+1,-1", - "h:+1,-1,-1,+1,-1,+1", - "h:+1,-1,+1,-1,+1,-1", -) -_S = 1_000_000.0 -_FINAL_ONE_ENERGY = (_S + 1.0 - 4.0) / 2_000.0 -_FINAL_TWO_ENERGY = (_S + 4.0 - 1.0) / 2_000.0 -_FINAL_MOMENTUM = math.sqrt(_FINAL_ONE_ENERGY * _FINAL_ONE_ENERGY - 1.0) -_POINT_0012 = ( - (500.0, 0.0, 0.0, 500.0), - (500.0, 0.0, 0.0, -500.0), - (_FINAL_ONE_ENERGY, 0.0, 0.0, _FINAL_MOMENTUM), - (_FINAL_TWO_ENERGY, 0.0, 0.0, -_FINAL_MOMENTUM), -) -_POINT_0000 = ( - (500.0, 0.0, 0.0, 500.0), - (500.0, 0.0, 0.0, -500.0), - (500.0, 0.0, 0.0, 500.0), - (500.0, 0.0, 0.0, -500.0), -) - - -def _hidden_artifact_probe() -> Any: - """Return the optional development probe or skip its private canaries. - - ``PYAMPLICOL_REQUIRE_NATIVE_TESTS`` requires the production native runtime; - it does not make test-only Cargo features part of candidate or release - wheels. Keep every canary in this file behind the same feature check. - """ - - if importlib.util.find_spec("pyamplicol._rusticol") is None: - pytest.skip("the Rusticol extension has not been built") - rusticol = importlib.import_module("pyamplicol._rusticol") - probe = getattr(rusticol, "_on_the_fly_artifact_probe_v1", None) - if not callable(probe): - pytest.skip("the native extension lacks on-the-fly test support") - return probe - - -@dataclass(frozen=True) -class _ScalarContactCase: - process: str - process_id: str - vertex: str - point: tuple[tuple[float, ...], ...] - normalization_factor: float - - -_CASES = ( - _ScalarContactCase( - process="scalar_0 scalar_0 > scalar_0 scalar_0", - process_id="scalars_0000", - vertex="V_4_SCALAR_0000", - point=_POINT_0000, - normalization_factor=0.5, - ), - _ScalarContactCase( - process="scalar_0 scalar_0 > scalar_1 scalar_2", - process_id="scalars_0012", - vertex="V_4_SCALAR_0012", - point=_POINT_0012, - normalization_factor=1.0, - ), -) - - -def _analytic_scalar_contact(case: _ScalarContactCase, coupling: float) -> float: - # Both selected V4 vertices have color 1, Lorentz structure 1, and raw - # amplitude i*lam. The only normalization difference is the factor 1/2 - # for the two identical scalar_0 particles in the 0000 final state. - return case.normalization_factor * coupling * coupling - - -def _config() -> RunConfig: - return RunConfig( - action="generate", - color=ColorConfig(accuracy="lc", lc_flow_layout="topology-replay"), - process=ProcessConfig( - coupling_order_policy="explicit", - max_coupling_orders={"QCD": 1, "QED": 0}, - ), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - relation_discovery=GenerationRelationDiscoveryConfig(mode="off"), - validation=GenerationValidationConfig( - enabled=False, - post_build_validation=False, - ), - ), - evaluator=EvaluatorConfig( - execution_mode="recurrence", - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=2), - ), - ) - - -def _flatten(points: tuple[tuple[tuple[float, ...], ...], ...]) -> list[float]: - return [ - component for point in points for momentum in point for component in momentum - ] - - -def _transverse(point: tuple[tuple[float, ...], ...]) -> tuple[tuple[float, ...], ...]: - outgoing_one = point[2] - outgoing_two = point[3] - return ( - point[0], - point[1], - (outgoing_one[0], outgoing_one[3], 0.0, 0.0), - (outgoing_two[0], outgoing_two[3], 0.0, 0.0), - ) - - -def _established_resolved_totals( - runtime: Runtime, points: tuple[Any, ...] -) -> tuple[float, ...]: - resolved = runtime.evaluate_resolved(points) - assert resolved.helicity_ids == ("h:+0,+0,+0,+0",) - assert resolved.color_ids == ("flow:singlet",) - values = tuple(complex(value) for value in resolved.total()) - assert all(value.imag == pytest.approx(0.0, abs=1.0e-15) for value in values) - return tuple(value.real for value in values) - - -def _canonical_direct_catalog_json(retained: dict[str, object]) -> bytes: - direct_json = retained["direct_template_catalog_json"] - assert isinstance(direct_json, bytes) - assert direct_json == json.dumps( - retained["direct_template_catalog"].to_dict(), # type: ignore[union-attr] - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return direct_json - - -def _invoke_probe( - probe: Any, - artifact: Path, - case: _ScalarContactCase, - retained: dict[str, object], - direct_json: bytes, - points: tuple[tuple[tuple[float, ...], ...], ...], - *, - overrides: dict[str, list[float]] | None = None, - pack_digest: str | None = None, - tamper: bool = False, - benchmark: bool = False, - benchmark_warmup_repetitions: int = 0, - benchmark_repetitions: int = 0, - collect_current_diagnostics: bool = True, - enable_color_projection: bool = True, -) -> dict[str, Any]: - return probe( - str(artifact), - case.process_id, - retained["builder_input"], - retained["prepared_template_input"], - direct_json, - pack_digest or retained["prepared_kernel_pack_digest"], - 0, - list(_HELICITIES), - _flatten(points), - len(points), - parameter_overrides=overrides, - tamper_executor_key=tamper, - benchmark=benchmark, - benchmark_warmup_repetitions=benchmark_warmup_repetitions, - benchmark_repetitions=benchmark_repetitions, - collect_current_diagnostics=collect_current_diagnostics, - enable_color_projection=enable_color_projection, - ) - - -def _assert_zero_poison_counts(report: dict[str, Any]) -> None: - assert report["direct_plan_load_attempts"] == 0 - assert report["direct_plan_decode_attempts"] == 0 - assert report["direct_plan_materialization_attempts"] == 0 - assert report["established_builder_attempts"] == 0 - - -def _assert_raw_i_lambda(report: dict[str, Any], coupling: float) -> None: - for raw in report["raw_amplitudes"]: - assert raw[0] == pytest.approx(0.0, abs=1.0e-14) - assert raw[1] == pytest.approx(coupling) - - -_WORK_CENSUS_FIELDS = ( - "work_census_basis", - "logical_current_count", - "resident_current_count", - "resident_current_component_count", - "source_operation_count", - "contribution_operation_count", - "finalization_operation_count", - "closure_operation_count", - "total_kernel_application_count", - "semantic_executor_binding_count", - "distinct_prepared_executor_count", -) - - -def _work_census(report: dict[str, Any]) -> tuple[object, ...]: - assert report["work_census_basis"] == "fully-resident-query-local-trace-v1" - assert report["logical_current_count"] == report["resident_current_count"] - resident_components = report["resident_current_component_count"] - assert resident_components >= report["resident_current_count"] - assert report["source_operation_count"] == 4 - assert report["closure_operation_count"] >= 1 - assert report["total_kernel_application_count"] == sum( - report[name] - for name in ( - "source_operation_count", - "contribution_operation_count", - "finalization_operation_count", - "closure_operation_count", - ) - ) - assert ( - 0 - < report["distinct_prepared_executor_count"] - <= report["semantic_executor_binding_count"] - <= report["total_kernel_application_count"] - ) - return tuple(report[name] for name in _WORK_CENSUS_FIELDS) - - -def _assert_hidden_probe_matches_sm_process( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - process: str, - process_id: str, - *, - selected_helicity_ids: tuple[str, ...] | None = None, - expected_flow_count: int | None = None, - expected_query_count: int | None = None, -) -> None: - probe = _hidden_artifact_probe() - monkeypatch.setattr(lc_gate, "PROCESS", process) - monkeypatch.setattr(lc_gate, "PROCESS_ID", process_id) - monkeypatch.setattr(lc_gate, "SEEDS", _SM_SEEDS) - config = lc_gate._on_the_fly_config() - prepared = ModelSource.built_in_sm().compile( - cache_dir=tmp_path / "fresh-built-in-sm-cache", - use_cache=False, - prepared_output=( - tmp_path / f"fresh-{process_id}-built-in-sm-jit-o2.pyamplicol-model" - ), - evaluator=config.evaluator, - ) - on_the_fly_artifact = tmp_path / f"fresh-{process_id}-on-the-fly-artifact" - lc_gate._generate_on_the_fly(on_the_fly_artifact, prepared) - recurrence_artifact = tmp_path / f"fresh-{process_id}-recurrence-probe" - retained = lc_gate._generate_probe_carrier( - recurrence_artifact, - prepared, - ) - runtime = Runtime.load(recurrence_artifact, process=process_id) - on_the_fly_runtime = Runtime.load(on_the_fly_artifact, process=process_id) - points = lc_gate._points() - resolved = runtime.evaluate_resolved(points) - on_the_fly_resolved = on_the_fly_runtime.evaluate_resolved(points) - helicity_axis, color_axis = lc_gate._axes(resolved) - on_the_fly_helicity_axis, on_the_fly_color_axis = lc_gate._axes(on_the_fly_resolved) - assert on_the_fly_helicity_axis == helicity_axis - assert on_the_fly_color_axis == color_axis - flows = tuple(runtime.physics.color_flows) - helicities = tuple( - helicity - for helicity in runtime.physics.helicities - if not helicity.structural_zero - ) - assert flows - assert helicities - if expected_flow_count is not None: - assert len(flows) == expected_flow_count - if selected_helicity_ids is not None: - selected = frozenset(selected_helicity_ids) - helicities = tuple( - helicity for helicity in helicities if helicity.id in selected - ) - assert len(helicities) == len(selected_helicity_ids) - assert {helicity.id for helicity in helicities} == selected - census: list[tuple[str, dict[str, object], bool]] = [] - for flow in flows: - for helicity in helicities: - selector = f"{flow.id}|{helicity.id}" - expected = tuple( - point[helicity_axis[helicity.id]][color_axis[flow.id]] - for point in resolved.values - ) - public_on_the_fly = tuple( - point[on_the_fly_helicity_axis[helicity.id]][ - on_the_fly_color_axis[flow.id] - ] - for point in on_the_fly_resolved.values - ) - lc_gate._series(public_on_the_fly, expected, f"{selector} public") - query = lc_gate._query(flow, helicity) - projected_report = lc_gate._invoke( - probe, - recurrence_artifact, - retained, - query, - points, - enable_color_projection=True, - ) - bypass_report = lc_gate._invoke( - probe, - recurrence_artifact, - retained, - query, - points, - enable_color_projection=False, - ) - projected = lc_gate._probe_values(projected_report, len(points)) - bypass = lc_gate._probe_values(bypass_report, len(points)) - try: - lc_gate._series(projected, expected, selector) - except lc_gate.GateError as error: - try: - lc_gate._series(bypass, expected, f"{selector} bypass") - except lc_gate.GateError: - localization = "pre-projection or shared execution" - else: - localization = "late color projection" - pytest.fail(f"{error}; localized to {localization}") - try: - lc_gate._series(bypass, expected, f"{selector} bypass") - except lc_gate.GateError: - bypass_matches = False - else: - bypass_matches = True - census.append( - ( - selector, - lc_gate._work_census(projected_report), - bypass_matches, - ) - ) - - if expected_query_count is not None: - assert len(census) == expected_query_count - - print( - f"genuine on-the-fly {process} component census:", - f"flows={len(flows)} helicities={len(helicities)} " - f"components={len(census)} point-checks={len(census) * len(points)} ", - census, - ) - - -def test_hidden_on_the_fly_probe_matches_every_physical_sm_n3_component( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _assert_hidden_probe_matches_sm_process( - tmp_path, - monkeypatch, - "d d~ > t t~ g", - "otf_dd_tt_g", - ) - - -def test_hidden_on_the_fly_probe_matches_every_physical_sm_n2_component( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _assert_hidden_probe_matches_sm_process( - tmp_path, - monkeypatch, - "d d~ > t t~", - "otf_dd_tt", - ) - - -def test_hidden_on_the_fly_probe_matches_every_physical_sm_n3_z_component( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _assert_hidden_probe_matches_sm_process( - tmp_path, - monkeypatch, - "d d~ > t t~ z", - "otf_dd_tt_z", - ) - - -def test_hidden_on_the_fly_probe_matches_identical_six_fermion_wick_lineages( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _assert_hidden_probe_matches_sm_process( - tmp_path, - monkeypatch, - "d d~ > u u~ u u~", - "otf_dd_uu_uu", - selected_helicity_ids=_IDENTICAL_SIX_FERMION_HELICITIES, - expected_flow_count=6, - expected_query_count=24, - ) - - -def test_hidden_on_the_fly_probe_matches_identical_leptonic_wick_lineages( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _assert_hidden_probe_matches_sm_process( - tmp_path, - monkeypatch, - "d d~ > e+ e- e+ e-", - "otf_dd_epem_epem", - selected_helicity_ids=_IDENTICAL_SIX_FERMION_HELICITIES, - expected_flow_count=1, - expected_query_count=4, - ) - - -@pytest.mark.parametrize( - ("process", "process_id"), - ( - ("g g > t t~", "otf_gg_tt"), - ("d d~ > e+ e- g", "otf_dd_epem_g"), - ("d d~ > u u~ g", "otf_dd_uu_g"), - ), - ids=("three-gluon-binding", "single-wick-line", "two-open-color-lines"), -) -def test_hidden_on_the_fly_probe_sm_low_multiplicity_discriminators( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - process: str, - process_id: str, -) -> None: - _assert_hidden_probe_matches_sm_process( - tmp_path, - monkeypatch, - process, - process_id, - ) - - -def test_hidden_on_the_fly_probe_executes_genuine_scalar_artifact( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - probe = _hidden_artifact_probe() - rusticol = importlib.import_module("pyamplicol._rusticol") - if importlib.util.find_spec("symbolica") is None: - pytest.skip("Symbolica is unavailable") - - config = _config() - prepared_output = tmp_path / "fresh-scalar-jit-o2.pyamplicol-model" - assert not prepared_output.exists() - prepared = ModelSource.from_path(_MODEL).compile( - cache_dir=tmp_path / "fresh-model-cache", - use_cache=False, - prepared_output=prepared_output, - evaluator=config.evaluator, - ) - assert prepared_output.is_file() - captured: list[dict[str, object]] = [] - original = generation_service._invoke_rust_recurrence_lowering_v2 - - def capture_lowering(*args: object, **kwargs: object) -> object: - captured.append( - { - "builder_input": args[0], - "prepared_template_input": args[1], - "direct_template_catalog": args[2], - "prepared_kernel_pack_digest": args[3], - "direct_template_catalog_json": kwargs.get( - "direct_template_catalog_json" - ), - } - ) - return original(*args, **kwargs) - - monkeypatch.setattr( - generation_service, - "_invoke_rust_recurrence_lowering_v2", - capture_lowering, - ) - generated: dict[str, tuple[_ScalarContactCase, Path, dict[str, object], bytes]] = {} - for case in _CASES: - artifact = tmp_path / f"fresh-{case.process_id}-artifact" - assert not artifact.exists() - Generator(config).generate( - ProcessRequest.parse(case.process, name=case.process_id), - artifact, - model=prepared, - ) - assert artifact.exists() - assert len(captured) == len(generated) + 1 - retained = captured[-1] - # These are the exact canonical bytes supplied to genuine lowering, - # not a reconstruction from the completed artifact. - direct_json = _canonical_direct_catalog_json(retained) - generated[case.process_id] = (case, artifact, retained, direct_json) - - diagnostics: dict[str, object] = {} - for case, artifact, retained, direct_json in generated.values(): - runtime = Runtime.load(artifact, process=case.process_id) - transverse = _transverse(case.point) - single_points = ((case.point,), (transverse,)) - established_default = _established_resolved_totals( - runtime, (case.point, transverse) - ) - expected_default = _analytic_scalar_contact(case, 1.0) - assert established_default == pytest.approx( - (expected_default, expected_default) - ) - - singles = tuple( - _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - points, - ) - for points in single_points - ) - bypass = _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - single_points[0], - enable_color_projection=False, - ) - assert singles[0]["projection_enabled"] is True - assert bypass["projection_enabled"] is False - assert bypass["projection_applied"] is False - for name in ("current_count", "contribution_count", "closure_count"): - assert ( - bypass[f"pre_projection_{name}"] == singles[0][f"pre_projection_{name}"] - ) - assert bypass["raw_amplitudes"] == singles[0]["raw_amplitudes"] - batch_order = (0, 1, 1, 0, 1, 0, 0) - batch_points = tuple(single_points[index][0] for index in batch_order) - many = _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - batch_points, - ) - one = singles[0] - assert one["process_id"] == case.process_id - assert one["point_count"] == 1 - assert many["point_count"] == len(batch_order) - assert one["artifact_id"] == many["artifact_id"] - assert all( - report["seed_digest"] == one["seed_digest"] - and report["query_digest"] == one["query_digest"] - and report["trace_digest"] == one["trace_digest"] - for report in (*singles, many) - ) - assert one["normalization_factor"] == pytest.approx(case.normalization_factor) - work_census = _work_census(one) - assert one["normalized_values"] == pytest.approx((expected_default,)) - assert many["normalized_values"] == pytest.approx( - (expected_default,) * len(batch_order) - ) - for report in (*singles, many): - assert _work_census(report) == work_census - _assert_zero_poison_counts(report) - assert report["trace_build_count"] == 1 - assert report["trace_cache_hit_count"] == 0 - assert report["momentum_fill_count"] == 1 - assert report["benchmark_warmup_repetitions"] == 0 - assert report["benchmark_repetitions"] == 0 - assert report["benchmark_elapsed_seconds"] is None - assert report["benchmark_seconds_per_point"] is None - _assert_raw_i_lambda(report, 1.0) - for raw, normalized in zip( - report["raw_amplitudes"], - report["normalized_values"], - strict=True, - ): - assert normalized == pytest.approx( - (raw[0] * raw[0] + raw[1] * raw[1]) * report["normalization_factor"] - ) - - assert one["currents"] - one_digests = [current["semantic_digest"] for current in one["currents"]] - assert all( - [current["semantic_digest"] for current in report["currents"]] - == one_digests - for report in (*singles, many) - ) - for current_index, many_current in enumerate(many["currents"]): - width = many_current["component_count"] - assert len(many_current["values"]) == len(batch_order) * width - for point_index, single_index in enumerate(batch_order): - single_current = singles[single_index]["currents"][current_index] - assert single_current["component_count"] == width - assert len(single_current["values"]) == width - start = point_index * width - assert ( - many_current["values"][start : start + width] - == single_current["values"] - ) - assert ( - many["raw_amplitudes"][point_index] - == singles[single_index]["raw_amplitudes"][0] - ) - - runtime.set_model_parameters({"lam": 3.0}) - established_mutated = _established_resolved_totals(runtime, (case.point,))[0] - expected_mutated = _analytic_scalar_contact(case, 3.0) - assert established_mutated == pytest.approx(expected_mutated) - mutated = _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - (case.point,), - overrides={"lam": [3.0, 0.0]}, - ) - assert _work_census(mutated) == work_census - _assert_zero_poison_counts(mutated) - _assert_raw_i_lambda(mutated, 3.0) - assert mutated["trace_digest"] == one["trace_digest"] - assert mutated["normalized_values"] == pytest.approx((expected_mutated,)) - assert mutated["normalized_values"] == pytest.approx((established_mutated,)) - # `lam` is a runtime input while SCALAR_COUPLING is the prepared - # derived slot consumed by the executor. This exact factor-three raw - # scaling exercises the authenticated runtime-to-prepared projection. - assert mutated["raw_amplitudes"][0][0] == pytest.approx( - 3.0 * one["raw_amplitudes"][0][0] - ) - assert mutated["raw_amplitudes"][0][1] == pytest.approx( - 3.0 * one["raw_amplitudes"][0][1] - ) - - benchmark = _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - (case.point,), - benchmark=True, - benchmark_warmup_repetitions=2, - benchmark_repetitions=5, - collect_current_diagnostics=False, - ) - assert _work_census(benchmark) == work_census - _assert_zero_poison_counts(benchmark) - _assert_raw_i_lambda(benchmark, 1.0) - assert benchmark["normalized_values"] == pytest.approx((expected_default,)) - assert benchmark["currents"] == [] - assert benchmark["trace_build_count"] == 1 - assert benchmark["trace_cache_hit_count"] == 7 - assert benchmark["momentum_fill_count"] == 7 - assert benchmark["benchmark_warmup_repetitions"] == 2 - assert benchmark["benchmark_repetitions"] == 5 - assert math.isfinite(benchmark["benchmark_elapsed_seconds"]) - assert benchmark["benchmark_elapsed_seconds"] >= 0.0 - assert benchmark["benchmark_seconds_per_point"] == pytest.approx( - benchmark["benchmark_elapsed_seconds"] / 5.0 - ) - - with pytest.raises(ValueError, match="at least one timed repetition"): - _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - (case.point,), - benchmark=True, - ) - - with pytest.raises(ValueError, match="not used by the process"): - _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - (case.point,), - overrides={"unknown_parameter": [1.0, 0.0]}, - ) - with pytest.raises(rusticol.ArtifactError, match="prepared-kernel pack digest"): - _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - (case.point,), - pack_digest="1" * 64, - ) - with pytest.raises(rusticol.ArtifactError, match=r"executor|semantic|mapping"): - _invoke_probe( - probe, - artifact, - case, - retained, - direct_json, - (case.point,), - tamper=True, - ) - - diagnostics[case.process_id] = { - "vertex": case.vertex, - "established_default": established_default, - "probe_default_raw": one["raw_amplitudes"], - "probe_default_normalized": one["normalized_values"], - "probe_batch_normalized": many["normalized_values"], - "normalization_factor": one["normalization_factor"], - "poison_counts": ( - one["direct_plan_load_attempts"], - one["direct_plan_decode_attempts"], - one["direct_plan_materialization_attempts"], - one["established_builder_attempts"], - ), - "established_lam3": established_mutated, - "probe_lam3_raw": mutated["raw_amplitudes"], - "probe_lam3_normalized": mutated["normalized_values"], - } - - case_0000, artifact_0000, _, _ = generated["scalars_0000"] - _, _, retained_0012, direct_json_0012 = generated["scalars_0012"] - with pytest.raises( - rusticol.ArtifactError, match=r"do not belong|selected artifact" - ): - _invoke_probe( - probe, - artifact_0000, - case_0000, - retained_0012, - direct_json_0012, - (case_0000.point,), - ) - - print("genuine on-the-fly scalar contact diagnostics:", diagnostics) diff --git a/pyamplicol/tests/release/test_sdist_manifest.py b/pyamplicol/tests/release/test_sdist_manifest.py index c799acdc70..849d1eaada 100644 --- a/pyamplicol/tests/release/test_sdist_manifest.py +++ b/pyamplicol/tests/release/test_sdist_manifest.py @@ -27,8 +27,6 @@ def test_maturin_includes_required_sdist_source_trees() -> None: "schemas/**/*", "tests/**/*", "tools/developer/**/*", - "tools/fft_profiling/**/*", - "tools/performance_report/**/*", "tools/release/**/*", "tools/typing/**/*", } <= includes @@ -43,7 +41,6 @@ def test_maturin_includes_required_sdist_source_trees() -> None: "dependencies/contributor-lock.toml", "dependencies/install_dependencies.py", "dependencies/python-runtime-lock.toml", - "flake.nix", "release_assets/**", } <= excludes diff --git a/pyamplicol/tests/unit/test_amplicol_z6g_m0_capture.py b/pyamplicol/tests/unit/test_amplicol_z6g_m0_capture.py deleted file mode 100644 index de63dc4c3a..0000000000 --- a/pyamplicol/tests/unit/test_amplicol_z6g_m0_capture.py +++ /dev/null @@ -1,998 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import importlib.util -import json -import os -import subprocess -import sys -from dataclasses import replace -from pathlib import Path -from types import ModuleType, SimpleNamespace -from typing import Any - -import pytest - -ROOT = Path(__file__).resolve().parents[2] -CAPTURE_SCRIPT = ROOT / "tools" / "developer" / "amplicol_z6g_m0_capture.py" -M0_SCRIPT = ROOT / "tools" / "developer" / "eager_compiled_arena_m0.py" - - -def _load(name: str, path: Path) -> ModuleType: - spec = importlib.util.spec_from_file_location(name, path) - assert spec is not None and spec.loader is not None - module = importlib.util.module_from_spec(spec) - sys.modules[name] = module - spec.loader.exec_module(module) - return module - - -capture = _load("_test_amplicol_z6g_m0_capture", CAPTURE_SCRIPT) -m0 = _load("_test_amplicol_z6g_m0_capture_m0", M0_SCRIPT) - -REVISION = "b" * 40 -PYAMPLICOL_REVISION = "a" * 40 -POINTS_SHA256 = "1" * 64 -NORMALIZATION_SHA256 = "2" * 64 -FLOW_ID = "flow:2,4,5,6,7,8,9,1" -FLOW_WORD = [2, 4, 5, 6, 7, 8, 9, 1] -HELICITY_ID = "h:-1,+1,-1,+1,-1,+1,-1,+1,-1" -HELICITY_VALUES = [-1, 1, -1, 1, -1, 1, -1, 1, -1] -HOST = { - "platform": "Darwin-test", - "system": "Darwin", - "release": "24.0.0", - "version": "test", - "machine": "arm64", - "processor": "arm", - "cpu_model": "test-cpu", - "logical_cpu_count": 8, -} - - -def _write(path: Path, raw: bytes, *, executable: bool = False) -> dict[str, Any]: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_bytes(raw) - if executable: - path.chmod(0o755) - return capture._file_ref(path) - - -def _git_repository(path: Path) -> tuple[Path, str]: - path.mkdir() - subprocess.run(("git", "init", "-q"), cwd=path, check=True) - tracked = path / "tracked.txt" - tracked.write_text("tracked\n", encoding="utf-8") - subprocess.run(("git", "add", "tracked.txt"), cwd=path, check=True) - subprocess.run( - ( - "git", - "-c", - "user.name=Capture Test", - "-c", - "user.email=capture@example.invalid", - "commit", - "-qm", - "initial", - ), - cwd=path, - check=True, - ) - revision = subprocess.run( - ("git", "rev-parse", "--verify", "HEAD"), - cwd=path, - capture_output=True, - text=True, - check=True, - ).stdout.strip() - return path, revision - - -def _write_generated_library(repository: Path) -> tuple[Path, Path]: - amplitudes = repository / "Library" / "amplitudes.bin" - data = repository / "Library" / "nested" / "amp_1_lib.data" - amplitudes.parent.mkdir(parents=True) - data.parent.mkdir(parents=True) - amplitudes.write_bytes(b"amplitudes\n") - data.write_bytes(b"library-data\n") - return amplitudes, data - - -def _contract(tmp_path: Path) -> capture.CaptureContract: - fixture = _write(tmp_path / "validation-momenta.json", b"fixture\n") - return capture.CaptureContract( - expected={ - "pyamplicol_source_revision": PYAMPLICOL_REVISION, - "amplicol_source_revision": REVISION, - "momenta_points_sha256": POINTS_SHA256, - "normalization_sha256": NORMALIZATION_SHA256, - "host_sha256": capture._canonical_sha256(HOST), - "color_flow": {"id": FLOW_ID, "word": FLOW_WORD}, - "helicity": {"id": HELICITY_ID, "values": HELICITY_VALUES}, - "external_leg_permutation": list(capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION), - }, - input_files=(), - host=HOST, - fixture={ - "path": Path(fixture["path"]), - "file": fixture, - "point_count": 2, - "points_sha256": POINTS_SHA256, - }, - color_axis={ - "count": 720, - "ordered_ids_sha256": "3" * 64, - }, - helicity_axis={ - "count": 768, - "ordered_ids_sha256": "4" * 64, - }, - color_flow_request="1", - helicity_request="1", - selected_values=(complex(1.25, 0.0), complex(2.5, 0.0)), - union_values=(complex(3.75, 0.0), complex(5.0, 0.0)), - ) - - -def _context(tmp_path: Path) -> capture.ProbeContext: - runtime = tmp_path / "runtime" - runtime.mkdir() - process_file = runtime / "processes.txt" - process_file.write_text("process\n", encoding="utf-8") - selected = runtime / "amplicol_library_benchmark" - union = runtime / "amplicol_color_probe" - selected.write_bytes(b"selected") - union.write_bytes(b"union") - worker = runtime / "amplicol_z6g_m0_sample" - worker.write_bytes(b"worker") - selected.chmod(0o755) - union.chmod(0o755) - worker.chmod(0o755) - return capture.ProbeContext( - runtime=runtime, - worker_executable=worker, - process_file=process_file, - selected_binary=selected, - union_binary=union, - linked_files=(selected, union, process_file), - group=11, - integral=7, - source_pdgs=(2, -2, 23, 21, 21, 21, 21, 21, 21), - generated_pdgs=(2, -2, 21, 21, 21, 21, 21, 21, 23), - generated_color_order=(2, 3, 4, 5, 6, 7, 8, 1, 9), - permutation=capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION, - ) - - -def _source(tmp_path: Path) -> capture.SourceEvidence: - identity = _write(tmp_path / "amplicol-source.f90", b"program probe\n") - return capture.SourceEvidence( - source={ - "revision": REVISION, - "dirty": False, - "compiler": { - "id": "gfortran", - "version": "GNU Fortran 14.2", - "target": "arm64-apple-darwin", - "flags_sha256": capture._canonical_sha256(["-O3"]), - }, - "source_tree_sha256": capture._source_tree_sha256([identity]), - }, - source_files=(identity,), - ) - - -def _role_samples( - tmp_path: Path, - *, - role: str, - executable: dict[str, Any], - fixture: dict[str, Any], - values: list[list[float]], -) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]: - samples: list[dict[str, Any]] = [] - projections: list[dict[str, Any]] = [] - offset = 0 if role == capture.SELECTED_ROLE else 1 - for index in range(capture.MIN_SAMPLES): - evaluated = 1000 - seconds_per_point = 4.0e-5 * (1.0 + index * 0.01) - elapsed = evaluated * seconds_per_point - selector = ( - f"--color-flow-id={FLOW_ID}" - if role == capture.SELECTED_ROLE - else f"--helicity-id={HELICITY_ID}" - ) - command = [ - executable["path"], - "_sample", - f"--workload={role}", - f"--round={index}", - f"--momenta={fixture['path']}", - f"--source-revision={REVISION}", - selector, - ] - command_sha256 = capture._canonical_sha256(command) - stdout_payload = { - "kind": "amplicol-m0-probe-result", - "schema_version": 1, - "role": role, - "sample_index": index, - "evaluated_point_count": evaluated, - "elapsed_seconds": elapsed, - "seconds_per_point": seconds_per_point, - "selected_totals": values, - "resolved_sums": values, - } - stdout = capture._canonical_bytes(stdout_payload).decode() + "\n" - raw = capture._raw_sample( - role=role, - sample_index=index, - command_sha256=command_sha256, - stdout=stdout, - parsed=stdout_payload, - ) - raw_ref = capture._write_json( - tmp_path / "raw" / f"{2 * index + offset:02d}-{role}.json", - raw, - ) - start = 4 * index + 2 * offset - started = f"2026-07-26T01:00:{start:02d}+00:00" - finished = f"2026-07-26T01:00:{start + 1:02d}+00:00" - sample = { - "sample_index": index, - "interleave_round": index, - "interleave_position": 2 * index + offset, - "started_at_utc": started, - "finished_at_utc": finished, - "subprocess": True, - "command": command, - "command_sha256": command_sha256, - "evaluated_point_count": evaluated, - "elapsed_seconds": elapsed, - "seconds_per_point": seconds_per_point, - "interrupted": False, - "raw_output_file": raw_ref, - } - samples.append(sample) - projections.append( - { - "role": role, - "round": index, - "position": 2 * index + offset, - "started_at_utc": started, - "finished_at_utc": finished, - "command_sha256": command_sha256, - } - ) - return samples, projections - - -def test_generated_manifests_pass_the_real_m0_amplicol_validator( - tmp_path: Path, -) -> None: - contract = _contract(tmp_path) - repository = tmp_path / "repository" - repository.mkdir() - for name, raw in ( - ("amplicol_library_benchmark", b"selected"), - ("amplicol_color_probe", b"union"), - ("libamp_1.so", b"library"), - ): - path = repository / name - path.write_bytes(raw) - path.chmod(0o755) - _write_generated_library(repository) - process_file = tmp_path / "processes.txt" - process_file.write_text("process\n", encoding="utf-8") - context = replace( - capture._copy_runtime(repository, tmp_path / "capture", process_file), - group=11, - integral=7, - source_pdgs=(2, -2, 23, 21, 21, 21, 21, 21, 21), - generated_pdgs=(2, -2, 21, 21, 21, 21, 21, 21, 23), - generated_color_order=(2, 3, 4, 5, 6, 7, 8, 1, 9), - permutation=capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION, - ) - source = _source(tmp_path) - executable = capture._file_ref(context.worker_executable) - linked = [capture._file_ref(path) for path in context.linked_files] - binary_evidence = { - "executable": executable, - "linked_libraries": linked, - "source_files": list(source.source_files), - } - selected_values = capture._complex_pairs(contract.selected_values) - union_values = capture._complex_pairs(contract.union_values) - selected_samples, selected_projection = _role_samples( - tmp_path, - role=capture.SELECTED_ROLE, - executable=executable, - fixture=contract.fixture["file"], - values=selected_values, - ) - union_samples, union_projection = _role_samples( - tmp_path, - role=capture.UNION_ROLE, - executable=executable, - fixture=contract.fixture["file"], - values=union_values, - ) - evidence_paths = [ - executable["path"], - *(row["path"] for row in linked), - *(row["path"] for row in source.source_files), - ] - assert len(evidence_paths) == len(set(evidence_paths)) - assert capture._file_ref(context.process_file) in linked - combined = sorted( - [*selected_projection, *union_projection], - key=lambda row: row["position"], - ) - interleave_sha256 = capture._interleave_group_sha256(combined) - assert interleave_sha256 == m0._amplicol_interleave_group_sha256(combined) - - validated = {} - for role, samples, values in ( - (capture.SELECTED_ROLE, selected_samples, contract.selected_values), - (capture.UNION_ROLE, union_samples, contract.union_values), - ): - manifest = capture._manifest( - role=role, - contract=contract, - context=context, - source=source, - binary_evidence=binary_evidence, - samples=samples, - interleave_group_sha256=interleave_sha256, - selected=values, - resolved=values, - ) - path = tmp_path / f"{role}.json" - ref = capture._write_json(path, manifest) - m0_ref = m0._file_ref(ref, base=tmp_path, label=role) - loaded = m0._load_json_ref(m0_ref, role) - validated[role] = m0._validate_amplicol( - loaded, - role=role, - expected=contract.expected, - ) - - assert validated[capture.SELECTED_ROLE].timing["timing_boundary"] == ( - "amplitude-evaluation" - ) - assert validated[capture.UNION_ROLE].timing["timing_boundary"] == ( - "direct-library-total" - ) - assert ( - validated[capture.SELECTED_ROLE].interleave_group_sha256 - == validated[capture.UNION_ROLE].interleave_group_sha256 - == interleave_sha256 - ) - - -def test_capture_orchestrates_exactly_seven_selected_union_pairs( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - request = _write(tmp_path / "request-template.json", b"request\n") - contract = replace( - _contract(tmp_path), - input_files=(request,), - ) - context = _context(tmp_path) - source = _source(tmp_path) - calls: list[tuple[str, int]] = [] - - monkeypatch.setattr(capture, "_contract_from_request", lambda _path: contract) - monkeypatch.setattr(capture, "_host_identity", lambda: HOST) - monkeypatch.setattr( - capture, - "_require_clean_revision", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr(capture, "_prepare_probes", lambda **_kwargs: context) - monkeypatch.setattr(capture, "_source_evidence", lambda _repository: source) - monkeypatch.setattr( - capture.legacy_amplicol, - "validate_checkout", - lambda _repository: None, - ) - - def fake_run_sample( - _command: list[str], - *, - role: str, - round_index: int, - points: int, - ) -> tuple[str, dict[str, Any], str, str]: - calls.append((role, round_index)) - position = len(calls) - 1 - values = ( - contract.selected_values - if role == capture.SELECTED_ROLE - else contract.union_values - ) - elapsed = points * 4.0e-5 * (1.0 + round_index * 0.01) - payload = { - "kind": "amplicol-m0-probe-result", - "schema_version": 1, - "role": role, - "sample_index": round_index, - "evaluated_point_count": points, - "elapsed_seconds": elapsed, - "seconds_per_point": elapsed / points, - "selected_totals": capture._complex_pairs(values), - "resolved_sums": capture._complex_pairs(values), - } - stdout = capture._canonical_bytes(payload).decode() + "\n" - started = f"2026-07-26T02:00:{2 * position:02d}+00:00" - finished = f"2026-07-26T02:00:{2 * position + 1:02d}+00:00" - return stdout, payload, started, finished - - monkeypatch.setattr(capture, "_run_sample_command", fake_run_sample) - output = tmp_path / "output" - arguments = SimpleNamespace( - request_template=Path(request["path"]), - repository=tmp_path / "repository", - output_directory=output, - jobs=1, - selected_points=1000, - union_points=2000, - warmup_points=100, - target_seconds=5.0, - minimum_points=100, - maximum_points=100_000, - ) - - index = capture._capture(arguments) - - assert calls == [ - (role, round_index) - for round_index in range(capture.MIN_SAMPLES) - for role in capture.ROLES - ] - assert index["complete"] is True - assert index["paired_round_count"] == capture.MIN_SAMPLES - assert index["evaluated_points"] == { - capture.SELECTED_ROLE: 1000, - capture.UNION_ROLE: 2000, - } - for role in capture.ROLES: - ref = index["amplicol_evidence"][role] - m0_ref = m0._file_ref(ref, base=output, label=role) - loaded = m0._load_json_ref(m0_ref, role) - evidence = m0._validate_amplicol( - loaded, - role=role, - expected=contract.expected, - ) - assert evidence.interleave_group_sha256 == (index["interleave_group_sha256"]) - - -def test_sample_command_binds_all_required_physical_inputs(tmp_path: Path) -> None: - contract = _contract(tmp_path) - context = _context(tmp_path) - - selected = capture._sample_command( - role=capture.SELECTED_ROLE, - round_index=3, - points=1234, - contract=contract, - context=context, - ) - union = capture._sample_command( - role=capture.UNION_ROLE, - round_index=3, - points=4321, - contract=contract, - context=context, - ) - - for command, role in ( - (selected, capture.SELECTED_ROLE), - (union, capture.UNION_ROLE), - ): - assert command[0] == str(context.worker_executable) - assert f"--workload={role}" in command - assert "--round=3" in command - assert f"--momenta={contract.fixture['path']}" in command - assert f"--source-revision={REVISION}" in command - assert f"--color-flow-word={','.join(map(str, FLOW_WORD))}" in command - assert f"--helicity-values={','.join(map(str, HELICITY_VALUES))}" in command - assert "--source-to-generated-permutation=0,1,3,4,5,6,7,8,2" in command - assert f"--color-flow-id={FLOW_ID}" in selected - assert f"--helicity-id={HELICITY_ID}" in union - assert capture._canonical_sha256(selected) != capture._canonical_sha256(union) - - -def test_runtime_launcher_pins_interpreter_producer_and_probe_inputs( - tmp_path: Path, -) -> None: - repository = tmp_path / "repository" - repository.mkdir() - for name, raw in ( - ("amplicol_library_benchmark", b"selected"), - ("amplicol_color_probe", b"union"), - ("libamp_1.so", b"library"), - ): - path = repository / name - path.write_bytes(raw) - path.chmod(0o755) - source_amplitudes, source_data = _write_generated_library(repository) - process_file = tmp_path / "processes.txt" - process_file.write_text("process\n", encoding="utf-8") - - context = capture._copy_runtime( - repository, - tmp_path / "capture", - process_file, - ) - - launcher = context.worker_executable.read_text(encoding="utf-8") - bundled_producer = ( - context.runtime - / "python-src" - / "tools" - / "developer" - / "amplicol_z6g_m0_capture.py" - ).resolve() - assert launcher.startswith("#!/bin/sh\nexec ") - assert str(Path(sys.executable).resolve()) in launcher - assert " -I -S -B " in launcher - assert str(bundled_producer) in launcher - assert str(CAPTURE_SCRIPT) not in launcher - assert context.worker_executable.stat().st_mode & 0o111 - assert Path(sys.executable).resolve() in context.linked_files - assert CAPTURE_SCRIPT not in context.linked_files - for relative in capture._SAMPLE_RUNTIME_RELATIVE_FILES: - copied = (context.runtime / "python-src" / relative).resolve() - assert copied.is_file() - assert copied in context.linked_files - assert context.process_file in context.linked_files - assert context.selected_binary in context.linked_files - assert context.union_binary in context.linked_files - for source in (source_amplitudes, source_data): - copied = (context.runtime / source.relative_to(repository)).resolve() - assert copied.read_bytes() == source.read_bytes() - assert copied in context.linked_files - assert len(context.linked_files) == len(set(context.linked_files)) - - completed = subprocess.run( - (str(context.worker_executable), "_sample", "--help"), - cwd=tmp_path, - env={**os.environ, "PYTHONPATH": ""}, - capture_output=True, - text=True, - check=False, - ) - assert completed.returncode == 0, completed.stderr - assert "usage:" in completed.stdout - - -def test_selected_launcher_uses_snapshotted_generated_library_tree( - tmp_path: Path, -) -> None: - repository = tmp_path / "repository" - repository.mkdir() - selected = repository / "amplicol_library_benchmark" - selected.write_text( - """#!/bin/sh -set -eu -test "$(cat Library/amplitudes.bin)" = amplitudes -test "$(cat Library/nested/amp_1_lib.data)" = library-data -cat <<'EOF' -AMPICOL_SELECTED_FLOW_PROBE_VALUE 3 1 1.2500000000000000E+00 -AMPICOL_SELECTED_FLOW_PROBE_PDGS 9 2 -2 21 21 21 21 21 21 23 -AMPICOL_SELECTED_FLOW_PROBE_COLOR_ORDER 9 2 3 4 5 6 7 8 9 1 -AMPICOL_SELECTED_FLOW_PROBE_AMPLITUDES 4 -AMPICOL_SELECTED_FLOW_PROBE_COLOR_FACTOR 27 -AMPICOL_SELECTED_FLOW_PROBE_IDENTICAL_FACTOR 36 -AMPICOL_SELECTED_FLOW_PROBE_SINGLET_VERTICES 0 -AMPICOL_SELECTED_FLOW_PROBE_NORMALIZATION 1.0000000000000000E+00 -Timing summary -amplitude evaluation 0.25 -EOF -""", - encoding="utf-8", - ) - selected.chmod(0o755) - union = repository / "amplicol_color_probe" - union.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8") - union.chmod(0o755) - (repository / "libamp_1.so").write_bytes(b"library") - _write_generated_library(repository) - process_file = tmp_path / "processes.txt" - process_file.write_text("process\n", encoding="utf-8") - - source_pdgs = (2, -2, 23, 21, 21, 21, 21, 21, 21) - generated_pdgs = (2, -2, 21, 21, 21, 21, 21, 21, 23) - generated_color_order = (2, 3, 4, 5, 6, 7, 8, 9, 1) - context = replace( - capture._copy_runtime(repository, tmp_path / "capture", process_file), - group=3, - integral=1, - source_pdgs=source_pdgs, - generated_pdgs=generated_pdgs, - generated_color_order=generated_color_order, - permutation=capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION, - ) - fixture_path = tmp_path / "momenta.json" - fixture_path.write_text( - json.dumps( - { - "kind": "pyamplicol-rusticol-validation-momenta", - "schema_version": 1, - "process": capture.NORMALIZED_PROCESS, - "points": [ - [ - { - "pdg": pdg, - "momentum": [float(index + 1), 0.0, 0.0, 0.0], - } - for index, pdg in enumerate(source_pdgs) - ] - ], - } - ), - encoding="utf-8", - ) - parsed_pdgs, points = capture._fixture_points(fixture_path) - assert parsed_pdgs == source_pdgs - fixture_ref = capture._file_ref(fixture_path) - base_contract = _contract(tmp_path / "contract") - expected = dict(base_contract.expected) - expected["amplicol_source_revision"] = capture.legacy_amplicol.expected_revision() - expected["momenta_points_sha256"] = capture._canonical_sha256(points) - contract = replace( - base_contract, - expected=expected, - fixture={ - "path": fixture_path, - "file": fixture_ref, - "point_count": 1, - "points_sha256": expected["momenta_points_sha256"], - }, - ) - - completed = subprocess.run( - capture._sample_command( - role=capture.SELECTED_ROLE, - round_index=0, - points=5, - contract=contract, - context=context, - ), - cwd=tmp_path, - env={**os.environ, "PYTHONPATH": ""}, - capture_output=True, - text=True, - check=False, - ) - - assert completed.returncode == 0, completed.stderr - payload = json.loads(completed.stdout) - assert payload["selected_totals"] == [[1.25, 0.0]] - assert payload["resolved_sums"] == [[1.25, 0.0]] - - -def test_executable_row_authentication_accepts_serialized_color_reorder() -> None: - source_pdgs = (2, -2, 23, 21, 21, 21, 21, 21, 21) - generated_pdgs = (2, -2, 21, 21, 21, 21, 21, 21, 23) - requested = capture.legacy_amplicol.ProcessEntry( - group=3, - integral=1, - process_pdgs=generated_pdgs, - color_order=(2, 3, 4, 5, 6, 7, 8, 1, 9), - ) - emitted = SimpleNamespace( - group=3, - integral=1, - process_pdgs=generated_pdgs, - color_order=(2, 3, 4, 5, 6, 7, 8, 9, 1), - ) - - executable, permutation = capture._validated_executable_row( - requested_entry=requested, - emitted_probe=emitted, - source_pdgs=source_pdgs, - expected_flow_word=FLOW_WORD, - expected_permutation=capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION, - ) - - assert executable.color_order == emitted.color_order - assert executable.color_order != requested.color_order - assert permutation == capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION - - -def test_sample_runtime_inventory_covers_every_imported_legacy_oracle_module() -> None: - expected = { - path.relative_to(ROOT) - for path in (ROOT / "tools" / "developer" / "legacy_oracle").glob("*.py") - } - assert expected <= set(capture._SAMPLE_RUNTIME_RELATIVE_FILES) - - -def test_copied_helper_tampering_is_detected(tmp_path: Path) -> None: - repository = tmp_path / "repository" - repository.mkdir() - for name in ( - "amplicol_library_benchmark", - "amplicol_color_probe", - "libamp_1.so", - ): - path = repository / name - path.write_bytes(name.encode()) - path.chmod(0o755) - _write_generated_library(repository) - process_file = tmp_path / "processes.txt" - process_file.write_text("process\n", encoding="utf-8") - context = capture._copy_runtime(repository, tmp_path / "capture", process_file) - identities = tuple(capture._file_ref(path) for path in context.linked_files) - helper = ( - context.runtime / "python-src" / "tools" / "developer" / "legacy_amplicol.py" - ) - helper.write_text( - helper.read_text(encoding="utf-8") + "\n# adversarial drift\n", - encoding="utf-8", - ) - - with pytest.raises(capture.CaptureError, match="capture input drifted"): - capture._verify_immutable_files(identities) - - -def test_clean_revision_gate_rejects_revision_and_untracked_drift( - tmp_path: Path, -) -> None: - repository, revision = _git_repository(tmp_path / "repository") - - capture._require_clean_revision( - repository, - expected_revision=revision, - label="test checkout", - ) - with pytest.raises(capture.CaptureError, match="revision differs"): - capture._require_clean_revision( - repository, - expected_revision="0" * 40, - label="test checkout", - ) - - (repository / "untracked.txt").write_text("drift\n", encoding="utf-8") - with pytest.raises(capture.CaptureError, match="tracked or untracked"): - capture._require_clean_revision( - repository, - expected_revision=revision, - label="test checkout", - ) - - -def test_prepare_probes_rejects_untracked_checkout_before_build( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repository, revision = _git_repository(tmp_path / "amplicol") - (repository / "untracked-before-build.txt").write_text( - "drift\n", - encoding="utf-8", - ) - monkeypatch.setattr( - capture.legacy_amplicol, - "prepare_checkout", - lambda _repository: None, - ) - monkeypatch.setattr( - capture.legacy_amplicol, - "expected_revision", - lambda: revision, - ) - - with pytest.raises(capture.CaptureError, match="tracked or untracked"): - capture._prepare_probes( - repository=repository, - output=tmp_path / "output", - fixture_path=tmp_path / "not-read-before-cleanliness.json", - expected_flow_word=FLOW_WORD, - expected_permutation=capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION, - jobs=1, - ) - - -def test_capture_rejects_current_source_revision_and_cleanliness_drift( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repository, revision = _git_repository(tmp_path / "pyamplicol") - request = tmp_path / "request.json" - request.write_text("{}\n", encoding="utf-8") - base_contract = _contract(tmp_path) - monkeypatch.setattr(capture, "ROOT", repository) - prepared = False - - def unexpected_prepare(**_kwargs: Any) -> None: - nonlocal prepared - prepared = True - raise AssertionError("probe preparation must not run") - - monkeypatch.setattr(capture, "_prepare_probes", unexpected_prepare) - - def arguments(output: str) -> SimpleNamespace: - return SimpleNamespace( - request_template=request, - repository=tmp_path / "amplicol", - output_directory=tmp_path / output, - ) - - wrong_expected = dict(base_contract.expected) - wrong_expected["pyamplicol_source_revision"] = "0" * 40 - monkeypatch.setattr( - capture, - "_contract_from_request", - lambda _path: replace(base_contract, expected=wrong_expected), - ) - with pytest.raises(capture.CaptureError, match="revision differs"): - capture._capture(arguments("wrong-revision")) - assert prepared is False - - clean_expected = dict(base_contract.expected) - clean_expected["pyamplicol_source_revision"] = revision - monkeypatch.setattr( - capture, - "_contract_from_request", - lambda _path: replace(base_contract, expected=clean_expected), - ) - (repository / "untracked-current-source.txt").write_text( - "drift\n", - encoding="utf-8", - ) - with pytest.raises(capture.CaptureError, match="tracked or untracked"): - capture._capture(arguments("dirty-source")) - assert prepared is False - - -def test_process_generation_subprocess_receives_lowercase_z( - tmp_path: Path, -) -> None: - process_payload = ( - "9 1\n" - "2 -2 21 21 21 21 21 21 23\n" - "\n" - "\n" - "1\n" - "\n" - "1 1 1 1 9 2 3 4 5 6 7 8\n" - "1 1 2 -2 21 21 21 21 21 21 23 " - "2 3 4 5 6 7 8 1 9 720.0\n" - "\n" - "\n" - ) - repository = tmp_path / "case-sensitive-amplicol" - repository.mkdir() - process_list = repository / "process_list.py" - process_list.write_text( - "\n".join( - ( - "import json", - "import sys", - "from pathlib import Path", - "arguments = sys.argv[1:]", - "Path('received.json').write_text(json.dumps(arguments))", - (f"if arguments != ['--serial', {capture.NORMALIZED_PROCESS!r}]:"), - " raise SystemExit(19)", - f"Path('processes.txt').write_text({process_payload!r})", - ) - ) - + "\n", - encoding="utf-8", - ) - setup = tmp_path / "setup" - setup.mkdir() - - generated = capture._generate_process_file( - repository=repository, - setup=setup, - log_path=setup / "generation.log", - ) - - assert generated == setup / "processes.txt" - assert generated.read_text(encoding="utf-8") == process_payload - assert json.loads((setup / "received.json").read_text(encoding="utf-8")) == [ - "--serial", - "u u~ > z g g g g g g", - ] - assert " Z " in f" {capture.PROCESS_EXPRESSION} " - source_pdgs = capture.legacy_amplicol.process_pdgs(capture.NORMALIZED_PROCESS) - entry, matches = capture.legacy_amplicol.select_generated_process_entry( - capture.legacy_amplicol.parse_process_file(generated), - generated_process=capture.NORMALIZED_PROCESS, - wanted_pdgs=source_pdgs, - ) - assert len(matches) == 1 - assert ( - capture.legacy_amplicol._permutation( - source_pdgs, - entry.process_pdgs, - ) - == capture.AMPLICOL_EXTERNAL_LEG_PERMUTATION - ) - mapped = capture.legacy_amplicol.source_mapped_color_order( - entry, - source_pdgs=source_pdgs, - ) - colored_labels = { - index - for index, pdg in enumerate(source_pdgs, start=1) - if abs(pdg) == 21 or 1 <= abs(pdg) <= 6 - } - assert [label for label in mapped if label in colored_labels] == FLOW_WORD - - -def test_probe_stdout_is_strict_and_identity_bound() -> None: - payload = { - "kind": "amplicol-m0-probe-result", - "schema_version": 1, - "role": capture.SELECTED_ROLE, - "sample_index": 2, - "evaluated_point_count": 100, - "elapsed_seconds": 0.5, - "seconds_per_point": 0.005, - "selected_totals": [[1.0, 0.0]], - "resolved_sums": [[1.0, 0.0]], - } - stdout = capture._canonical_bytes(payload).decode() + "\n" - assert ( - capture._parse_probe_stdout( - stdout, - role=capture.SELECTED_ROLE, - sample_index=2, - evaluated_points=100, - ) - == payload - ) - - payload["unexpected"] = True - with pytest.raises(capture.CaptureError, match="unknown or missing"): - capture._parse_probe_stdout( - json.dumps(payload), - role=capture.SELECTED_ROLE, - sample_index=2, - evaluated_points=100, - ) - with pytest.raises(capture.CaptureError, match="duplicate JSON key"): - capture._parse_probe_stdout( - '{"kind":"x","kind":"y"}', - role=capture.SELECTED_ROLE, - sample_index=2, - evaluated_points=100, - ) - - -def test_timing_boundaries_and_adaptive_count_fail_closed() -> None: - output = """\ -Timing summary -generation setup 1.25 -amplitude evaluation 0.5 -total 2.0 -""" - assert capture._timing_value(output, "amplitude evaluation") == 0.5 - assert capture._timing_value(output, "total") == 2.0 - assert ( - capture._adaptive_points( - 0.5, - warmup_points=100, - target_seconds=5.0, - minimum_points=100, - maximum_points=10_000, - ) - == 1000 - ) - with pytest.raises(capture.CaptureError, match="positive finite"): - capture._adaptive_points( - 0.0, - warmup_points=100, - target_seconds=5.0, - minimum_points=100, - maximum_points=10_000, - ) - with pytest.raises(capture.CaptureError, match="no unique"): - capture._timing_value("Timing summary\nother 1.0\n", "total") diff --git a/pyamplicol/tests/unit/test_arena_native_x86_acceptance.py b/pyamplicol/tests/unit/test_arena_native_x86_acceptance.py deleted file mode 100644 index e0bc6bf86f..0000000000 --- a/pyamplicol/tests/unit/test_arena_native_x86_acceptance.py +++ /dev/null @@ -1,530 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import copy -from pathlib import Path -from typing import Any - -import pytest - -from tools.developer import arena_native_x86_acceptance as acceptance - -REVISION = "1" * 40 -WORKSPACE = acceptance.ROOT -SHA256 = "2" * 64 - - -def _source() -> dict[str, object]: - return { - "checkout": str(WORKSPACE), - "revision": REVISION, - "dirty": False, - "untracked_files_checked": True, - } - - -def _runtime() -> dict[str, object]: - build_info = {"source_revision": REVISION} - return { - "interpreter": { - "path": "/python", - "size_bytes": 10, - "sha256": "3" * 64, - "python_version": "3.11.9", - "implementation": "CPython", - }, - "package": {"version": "0.1.0"}, - "python_package_tree": { - "kind": "pyamplicol-python-package-tree-v2", - "sha256": "4" * 64, - }, - "native_extension": { - "path": "/pyamplicol/_rusticol.so", - "size_bytes": 20, - "sha256": "5" * 64, - "build_inputs_sha256": "6" * 64, - }, - "active_build_info": { - "payload": build_info, - "canonical_sha256": acceptance._canonical_sha256(build_info), - }, - "loaded_module_origin_policy": { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "observed_module_count": 1, - "observations": [{"module": "pyamplicol"}], - "observations_sha256": SHA256, - }, - } - - -def _gate_common(kind: str) -> dict[str, Any]: - source = _source() - runtime = _runtime() - script = {"path": "/gate.py", "size_bytes": 1, "sha256": SHA256} - return { - "kind": kind, - "schema_version": 1, - "status": "ok", - "passes": True, - "source_identity": source, - "source_identity_postflight": copy.deepcopy(source), - "source_identity_match": True, - "runtime_identity": runtime, - "runtime_identity_postflight": copy.deepcopy(runtime), - "runtime_identity_match": True, - "gate_script_identity": script, - "gate_script_identity_postflight": copy.deepcopy(script), - "gate_script_identity_match": True, - "failures": [], - } - - -def _comparison() -> dict[str, object]: - return { - "value_count": 2, - "failing_value_count": 0, - "passes": True, - } - - -def _comparison_mapping(names: set[str]) -> dict[str, object]: - return {name: _comparison() for name in names} - - -def _all_jit_payload() -> dict[str, Any]: - payload = _gate_common(acceptance.ALL_JIT_KIND) - payload["request"] = { - "process": "g g > g g", - "jit_optimization_levels": [0, 1, 2, 3], - "point_count": 3, - "point_seeds": list(acceptance._ALL_JIT_POINT_SEEDS), - "momenta_identity": { - "algorithm": "sha256-float-hex-momenta-v1", - "sha256": SHA256, - "point_count": 3, - "external_particle_count": 4, - }, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - "mandatory_watchdog_command": "memory-watchdog -- gate", - "memory_limit_gib": 30, - } - levels = {} - for name, level in acceptance._ALL_JIT_LEVELS.items(): - levels[name] = { - "configuration": { - "process": "g g > g g", - "color_accuracy": "lc", - "lc_flow_layout": "topology-replay", - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": level, - }, - "generation": { - "worker_provenance": { - "source_revision": REVISION, - "postflight_identity_match": True, - } - }, - "artifact_identity": { - "payload_count": 1, - "direct_arena_audit": {"passes": True}, - }, - "numerical_validation": { - "execution_mode": "compiled", - "point_count": 3, - "point_seeds": list(acceptance._ALL_JIT_POINT_SEEDS), - "comparisons": _comparison_mapping(acceptance._ALL_JIT_COMPARISONS), - "native_profile": { - "passes": True, - "execution_mode": "compiled", - "direct_arena_engine_counter": {"value": 1}, - "direct_arena_call_counter": {"value": 2}, - }, - "passes": True, - }, - "passes": True, - } - payload["levels"] = levels - payload["cross_level_numerical_parity"] = { - "baseline_optimization_level": 3, - "comparisons": { - name: _comparison_mapping(acceptance._CROSS_LEVEL_COMPARISONS) - for name in ("o0_vs_o3", "o1_vs_o3", "o2_vs_o3") - }, - "passes": True, - } - return acceptance._attach_content_identity(payload) - - -def _four_quark_payload() -> dict[str, Any]: - payload = _gate_common(acceptance.FOUR_QUARK_KIND) - payload["request"] = { - "process": "d d~ > u u~ s s~ c c~", - "independent_quark_line_count": 4, - "expected_external_pdgs": [-4, -3, -2, -1, 1, 2, 3, 4], - "max_quark_lines": 4, - "point_count": 3, - "point_seeds": list(acceptance._FOUR_QUARK_POINT_SEEDS), - "momenta_identity": { - "algorithm": "sha256-float-hex-momenta-v1", - "sha256": SHA256, - "point_count": 3, - "external_particle_count": 8, - }, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "mandatory_watchdog_command": "memory-watchdog -- gate", - "memory_limit_gib": 30, - } - payload["invalid_union_configurations"] = [ - { - "color_accuracy": color, - "lc_flow_layout": "all-flow-union", - "rejected": True, - "error_type": "ConfigurationError", - "message": f"all-flow-union requires LC, not {color}", - } - for color in ("nlc", "full") - ] - lanes = {} - for name, (color, layout, contracted) in acceptance._FOUR_QUARK_LANES.items(): - comparisons = set(acceptance._FOUR_QUARK_BASE_COMPARISONS) - profiles = {"complete", "helicity_selector"} - if not contracted: - comparisons.add("color_selector_evaluate_vs_resolved_total") - profiles.update({"color_selector", "combined_selector"}) - lanes[name] = { - "configuration": { - "process": "d d~ > u u~ s s~ c c~", - "max_quark_lines": 4, - "color_accuracy": color, - "lc_flow_layout": layout, - "contracted_color": contracted, - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": 3, - }, - "generation": { - "worker_provenance": { - "source_revision": REVISION, - "postflight_identity_match": True, - } - }, - "artifact_identity": { - "payload_count": 1, - "direct_arena_audit": {"passes": True}, - }, - "numerical_validation": { - "point_count": 3, - "point_seeds": list(acceptance._FOUR_QUARK_POINT_SEEDS), - "comparisons": _comparison_mapping(comparisons), - "runtime_execution": { - "execution_mode": "compiled", - "direct_arena_profiles": { - profile: { - "compiled_direct_arena_engine_count": 1, - "compiled_direct_arena_call_count": 2, - "legacy_boundary_component_total": 0, - "passes": True, - } - for profile in profiles - }, - }, - "passes": True, - }, - "passes": True, - } - payload["lanes"] = lanes - payload["lc_cross_layout_parity"] = { - "physical_axes_match": True, - "comparisons": _comparison_mapping(acceptance._CROSS_LC_COMPARISONS), - "passes": True, - } - return acceptance._attach_content_identity(payload) - - -def _resolved() -> dict[str, object]: - return { - "helicity_ids_match": True, - "color_ids_match": True, - "shape_matches": True, - "point_count": 2, - "component_count": 4, - "passes": True, - } - - -def _correctness(*, specialized: bool) -> dict[str, Any]: - result = { - "total": [{"passes": True}], - "resolved_f64": _resolved(), - "resolved_precision32": _resolved(), - "eager_resolved_sum": [{"passes": True}], - "compiled_resolved_sum": [{"passes": True}], - "passes": True, - } - if specialized: - result["specialized_compiled"] = _correctness(specialized=False) - return result - - -def _color_matrix_payload() -> dict[str, Any]: - records = [] - for case_key, (process, n_final) in acceptance._SMOKE_CASES.items(): - for color in acceptance._COLORS: - lc = color == "lc" - workload_names = ( - ("single-flow-helicity-sum", "all-flow-single-helicity") - if lc - else ("summed",) - ) - workloads = [] - for name in workload_names: - modes = {"compiled_complete", "eager_complete"} - if lc: - modes.add("compiled_specialized") - workloads.append( - { - "name": name, - "correctness": _correctness(specialized=lc), - "profiles": [ - { - "batch_size": batch_size, - **{ - mode: { - "result": { - "sample_count": 5, - "wall_time_per_point": 1.0e-6, - "interrupted": False, - "effective_config": { - "batch_size": batch_size - }, - } - } - for mode in modes - }, - } - for batch_size in (128, 1024) - ], - } - ) - records.append( - { - "case": { - "key": case_key, - "process": process, - "n_final": n_final, - "smoke": True, - }, - "model": "built-in", - "color": color, - "process_id": f"{case_key}-{color}", - "compiled_generation_under_hard_limit": True, - "generation": { - mode: {"core_phase_seconds": 1.0} - for mode in ("compiled", "eager") - }, - "workloads": workloads, - "selector_pattern_profiles": ( - { - mode: {"result": {"passes": True}} - for mode in ("compiled", "eager") - } - if lc - else None - ), - } - ) - return { - "kind": acceptance.COLOR_MATRIX_KIND, - "schema_version": acceptance.COLOR_MATRIX_SCHEMA_VERSION, - "complete": True, - "source_revision": REVISION, - "suite": "smoke", - "configuration": { - "batch_sizes": [128, 1024], - "colors": ["lc", "nlc", "full"], - "generation_timeout": 300.0, - "memory_limit_gib": 30.0, - "minimum_samples": 5, - "target_runtime": 5.0, - "selector_target_runtime": 1.0, - "selector_seed": 0xC0FFEE, - }, - "gates": {name: True for name in acceptance._COLOR_MATRIX_GATES}, - "passes": True, - "records": records, - } - - -def _reattach(payload: dict[str, Any]) -> dict[str, Any]: - body = copy.deepcopy(payload) - body.pop("content_identity", None) - return acceptance._attach_content_identity(body) - - -def test_acceptance_validators_accept_complete_synthetic_evidence() -> None: - assert acceptance._validate_all_jit( - _all_jit_payload(), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - )["numerical_validation"] - assert acceptance._validate_four_quark( - _four_quark_payload(), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - )["numerical_validation"] - color = acceptance._validate_color_matrix( - _color_matrix_payload(), - expected_revision=REVISION, - ) - assert color["cell_count"] == 6 - assert color["workload_count"] == 8 - - -def test_all_jit_rejects_tampering_and_vacuous_numerical_comparisons() -> None: - tampered = _all_jit_payload() - tampered["status"] = "validation_failed" - with pytest.raises(acceptance.AcceptanceError, match="content identity"): - acceptance._validate_all_jit( - tampered, - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - ) - - empty = _all_jit_payload() - comparison = empty["levels"]["jit-o2"]["numerical_validation"]["comparisons"][ - "f64_vs_precision32_total" - ] - comparison["value_count"] = 0 - with pytest.raises(acceptance.AcceptanceError, match="comparison is empty"): - acceptance._validate_all_jit( - _reattach(empty), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - ) - - -def test_gate_runtime_must_match_the_preflight_candidate_bytes() -> None: - expected_runtime = _runtime() - package_tree = expected_runtime.pop("python_package_tree") - expected_runtime["preimport_runtime_identity"] = { - "python_package_tree": package_tree - } - acceptance._validate_all_jit( - _all_jit_payload(), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - expected_runtime=expected_runtime, - ) - - expected_runtime["native_extension"]["sha256"] = "7" * 64 - with pytest.raises(acceptance.AcceptanceError, match="preflight candidate runtime"): - acceptance._validate_all_jit( - _all_jit_payload(), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - expected_runtime=expected_runtime, - ) - - -def test_four_quark_rejects_missing_lane_and_invalid_union_coverage() -> None: - missing_lane = _four_quark_payload() - del missing_lane["lanes"]["lc-all-flow-union"] - with pytest.raises(acceptance.AcceptanceError, match="lane coverage"): - acceptance._validate_four_quark( - _reattach(missing_lane), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - ) - - missing_rejection = _four_quark_payload() - missing_rejection["invalid_union_configurations"].pop() - with pytest.raises(acceptance.AcceptanceError, match="reject both"): - acceptance._validate_four_quark( - _reattach(missing_rejection), - expected_revision=REVISION, - expected_workspace=WORKSPACE, - point_count=3, - ) - - -def test_color_matrix_rejects_partial_scope_and_precision32_failure() -> None: - partial = _color_matrix_payload() - partial["records"].pop() - with pytest.raises(acceptance.AcceptanceError, match="cell scope"): - acceptance._validate_color_matrix(partial, expected_revision=REVISION) - - failed = _color_matrix_payload() - failed["records"][0]["workloads"][0]["correctness"]["resolved_precision32"][ - "passes" - ] = False - with pytest.raises(acceptance.AcceptanceError, match="resolved_precision32"): - acceptance._validate_color_matrix(failed, expected_revision=REVISION) - - -def test_color_matrix_rejects_vacuous_reduction_and_false_hard_gate() -> None: - vacuous = _color_matrix_payload() - vacuous["records"][0]["workloads"][0]["correctness"]["eager_resolved_sum"] = [] - with pytest.raises(acceptance.AcceptanceError, match="must not be empty"): - acceptance._validate_color_matrix(vacuous, expected_revision=REVISION) - - failed_gate = _color_matrix_payload() - failed_gate["gates"]["correctness"] = False - with pytest.raises(acceptance.AcceptanceError, match=r"gates\.correctness"): - acceptance._validate_color_matrix(failed_gate, expected_revision=REVISION) - - -def test_checked_json_binds_exact_bytes_and_rejects_symlink( - tmp_path: Path, -) -> None: - evidence = tmp_path / "evidence.json" - evidence.write_text('{"passes":true}\n', encoding="utf-8") - payload, identity = acceptance._checked_json(evidence, label="fixture") - assert payload == {"passes": True} - assert ( - identity["sha256"] - == acceptance.hashlib.sha256(evidence.read_bytes()).hexdigest() - ) - - link = tmp_path / "link.json" - link.symlink_to(evidence) - with pytest.raises(acceptance.AcceptanceError, match="regular file"): - acceptance._checked_json(link, label="fixture link") - - -def test_content_identity_covers_the_entire_manifest_body() -> None: - payload = acceptance._attach_content_identity( - { - "kind": acceptance.ACCEPTANCE_KIND, - "schema_version": 1, - "evidence": { - "all_jit": {"file_identity": {"sha256": SHA256}}, - "four_quark": {"file_identity": {"sha256": "3" * 64}}, - "color_matrix": {"file_identity": {"sha256": "4" * 64}}, - "preflight": {"file_identity": {"sha256": "5" * 64}}, - }, - "passes": True, - } - ) - acceptance._require_content_identity(payload, label="manifest") - payload["evidence"]["all_jit"]["file_identity"]["sha256"] = "6" * 64 - with pytest.raises(acceptance.AcceptanceError, match="content identity"): - acceptance._require_content_identity(payload, label="manifest") - - -def test_strict_json_rejects_duplicate_keys(tmp_path: Path) -> None: - path = tmp_path / "duplicates.json" - path.write_text('{"passes":true,"passes":true}\n', encoding="utf-8") - with pytest.raises(acceptance.AcceptanceError, match="duplicate key"): - acceptance._checked_json(path, label="duplicate fixture") diff --git a/pyamplicol/tests/unit/test_build_backend.py b/pyamplicol/tests/unit/test_build_backend.py index 42ce5cd548..c2ddabf261 100644 --- a/pyamplicol/tests/unit/test_build_backend.py +++ b/pyamplicol/tests/unit/test_build_backend.py @@ -31,30 +31,6 @@ def _git(repo: Path, *arguments: str) -> str: return completed.stdout.strip() -def _source_identity_checkout(tmp_path: Path) -> Path: - repo = tmp_path / "source-identity-checkout" - repo.mkdir() - _git(repo, "init", "-q") - _git(repo, "config", "user.email", "build@example.invalid") - _git(repo, "config", "user.name", "Build Test") - classifier = repo / "tools/performance_report/source_identity.py" - classifier.parent.mkdir(parents=True) - shutil.copy2(ROOT / "tools/performance_report/source_identity.py", classifier) - profile = repo / "docs/performance_reports/manual" - (profile / "results").mkdir(parents=True) - (profile / "results/cache.json").write_text("{}\n", encoding="utf-8") - (profile / "result_sample_table.tex").write_text("% table\n", encoding="utf-8") - (profile / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n") - (profile / "pyAmpliCol.tex").write_text("% report source\n", encoding="utf-8") - source = repo / "src/runtime.py" - source.parent.mkdir() - source.write_text("VALUE = 1\n", encoding="utf-8") - (repo / "pyproject.toml").write_text("[project]\nname='test'\n", encoding="utf-8") - _git(repo, "add", ".") - _git(repo, "commit", "-qm", "fixture") - return repo - - def test_prepared_model_bootstrap_is_candidate_only( monkeypatch: pytest.MonkeyPatch, ) -> None: @@ -441,9 +417,6 @@ def delegated(*_args, **_kwargs) -> str: monkeypatch.setattr(backend, "_check_dependencies", lambda _mode: None) monkeypatch.setattr(backend, "_rust_remap_flags", lambda *_args: "") monkeypatch.setattr(backend, "_stage_packaged_examples", lambda _path: None) - monkeypatch.setattr( - backend, "_stage_packaged_profiling_campaign", lambda _path: None - ) monkeypatch.setattr(backend, "_stage_python_stub", lambda _path: None) monkeypatch.setattr(backend, "_stage_runtime_resources", lambda _path: None) monkeypatch.setattr( @@ -532,9 +505,6 @@ def fake_overlay( lambda _path: "0.1.0", ) monkeypatch.setattr(backend, "_stage_packaged_examples", lambda _path: None) - monkeypatch.setattr( - backend, "_stage_packaged_profiling_campaign", lambda _path: None - ) monkeypatch.setattr(backend, "_stage_python_stub", lambda _path: None) monkeypatch.setattr(backend, "_stage_runtime_resources", lambda _path: None) monkeypatch.setattr( @@ -957,123 +927,6 @@ def unexpected_revision() -> None: assert build_info["native_build_inputs_sha256"] == "c" * 64 -def test_candidate_source_revision_ignores_only_generated_report_outputs( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - checkout = _source_identity_checkout(tmp_path) - profile = checkout / "docs/performance_reports/manual" - (profile / "results/cache.json").write_text('{"updated":true}\n', encoding="utf-8") - (profile / "result_sample_table.tex").write_text("% updated\n", encoding="utf-8") - (profile / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.7\n") - summary = profile / "campaign_summary_ids" - summary.mkdir() - (summary / "error.txt").write_text("cell-a\n", encoding="utf-8") - monkeypatch.setattr(backend, "ROOT", checkout) - - assert backend._clean_source_revision() is None - assert backend._clean_source_revision(allow_generated_report_outputs=True) == _git( - checkout, "rev-parse", "HEAD" - ) - - -@pytest.mark.parametrize( - "destination", - (Path("x86_epyc_manual"), Path("scratch/campaigns/x86_epyc_manual")), -) -def test_candidate_source_revision_ignores_untracked_copied_campaign_anywhere( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - destination: Path, -) -> None: - checkout = _source_identity_checkout(tmp_path) - copied = checkout / destination - (copied / "results").mkdir(parents=True) - (copied / "README.md").write_text("# copied campaign\n", encoding="utf-8") - (copied / "steer_performance_campaign.py").write_text( - "#!/usr/bin/env python3\n", - encoding="utf-8", - ) - (copied / "report-workspace.json").write_text("{}\n", encoding="utf-8") - (copied / "pyAmpliCol.tex").write_text("% copied template\n", encoding="utf-8") - (copied / "results/cache.json").write_text("{}\n", encoding="utf-8") - monkeypatch.setattr(backend, "ROOT", checkout) - - assert backend._clean_source_revision() is None - assert backend._clean_source_revision(allow_generated_report_outputs=True) == _git( - checkout, "rev-parse", "HEAD" - ) - assert not any( - path == destination or destination in path.parents - for path in backend._git_inventory() or () - ) - - tracked = checkout / "src/runtime.py" - tracked.write_text("VALUE = 2\n", encoding="utf-8") - assert ( - backend._clean_source_revision(allow_generated_report_outputs=True) is None - ) - - -def test_candidate_source_revision_rejects_incomplete_untracked_campaign( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - checkout = _source_identity_checkout(tmp_path) - copied = checkout / "scratch/incomplete" - copied.mkdir(parents=True) - (copied / "report-workspace.json").write_text("{}\n", encoding="utf-8") - (copied / "README.md").write_text("# incomplete\n", encoding="utf-8") - monkeypatch.setattr(backend, "ROOT", checkout) - - assert backend._clean_source_revision(allow_generated_report_outputs=True) is None - - -def test_candidate_source_revision_rejects_campaign_markers_in_tracked_tree( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - checkout = _source_identity_checkout(tmp_path) - tracked_tree = checkout / "src" - (tracked_tree / "report-workspace.json").write_text("{}\n", encoding="utf-8") - (tracked_tree / "steer_performance_campaign.py").write_text( - "#!/usr/bin/env python3\n", - encoding="utf-8", - ) - (tracked_tree / "rogue_runtime.py").write_text( - "VALUE = 'untracked'\n", - encoding="utf-8", - ) - monkeypatch.setattr(backend, "ROOT", checkout) - - assert backend._clean_source_revision(allow_generated_report_outputs=True) is None - - -@pytest.mark.parametrize( - "relative", - ( - "src/runtime.py", - "docs/performance_reports/manual/pyAmpliCol.tex", - "pyproject.toml", - "docs/performance_reports/manual/unexpected.json", - ), -) -def test_candidate_source_revision_rejects_non_generated_dirt( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - relative: str, -) -> None: - checkout = _source_identity_checkout(tmp_path) - profile = checkout / "docs/performance_reports/manual" - (profile / "results/cache.json").write_text('{"updated":true}\n', encoding="utf-8") - changed = checkout / relative - changed.parent.mkdir(parents=True, exist_ok=True) - changed.write_text("changed\n", encoding="utf-8") - monkeypatch.setattr(backend, "ROOT", checkout) - - assert backend._clean_source_revision(allow_generated_report_outputs=True) is None - - def test_release_build_info_is_minimal_and_retained_from_sdist( monkeypatch: pytest.MonkeyPatch, tmp_path: Path, @@ -1238,15 +1091,6 @@ def test_overlay_excludes_managed_dependencies_and_includes_licenses() -> None: assert not (overlay / "build_backend" / "python_lock.py").exists() -def test_fft_profiling_tool_is_retained_by_source_release_manifests() -> None: - pyproject = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8")) - includes = {entry["path"] for entry in pyproject["tool"]["maturin"]["include"]} - - assert "tools/fft_profiling" in backend.ALLOWLIST - assert "tools/fft_profiling/**/*" in includes - assert (ROOT / "tools/fft_profiling/fft_profiling.py").is_file() - - def test_wheel_examples_are_staged_from_the_single_canonical_tree() -> None: with backend._overlay("release") as (overlay, _target): packaged = overlay / "src" / "pyamplicol" / "_examples" @@ -1267,61 +1111,6 @@ def test_wheel_examples_are_staged_from_the_single_canonical_tree() -> None: backend._stage_packaged_examples(overlay) -def test_wheel_profiling_campaign_is_a_bounded_reset_template() -> None: - with backend._overlay("release") as (overlay, _target): - source = overlay / backend._PROFILING_CAMPAIGN_SOURCE - packaged = overlay / "src/pyamplicol/_profiling_campaign" - assert packaged == source - before = { - path.relative_to(packaged): path.read_bytes() - for path in packaged.rglob("*") - if path.is_file() - } - backend._stage_packaged_profiling_campaign(overlay) - copied = { - path.relative_to(packaged) for path in packaged.rglob("*") if path.is_file() - } - assert copied == set(backend._profiling_campaign_inventory(source)) - assert len(copied) == 69 - assert { - Path("result_matrix_on_the_fly_builtin_sm_full_table.tex"), - Path("result_matrix_on_the_fly_builtin_sm_lc_table.tex"), - Path("result_matrix_on_the_fly_builtin_sm_nlc_table.tex"), - Path("results/matrix_on_the_fly_builtin_sm_full.json"), - Path("results/matrix_on_the_fly_builtin_sm_lc.json"), - Path("results/matrix_on_the_fly_builtin_sm_nlc.json"), - } <= copied - assert { - path.relative_to(packaged): path.read_bytes() - for path in packaged.rglob("*") - if path.is_file() - } == before - assert Path("steer_performance_campaign.py") in copied - assert Path("results/report-cache.schema.json") in copied - runtime = overlay / "src/pyamplicol/_performance_report" - assert {path.name for path in runtime.glob("*.py")} == { - path.name for path in (overlay / "tools/performance_report").glob("*.py") - } | {"_memory_watchdog.py"} - assert (runtime / "manual_campaign.py").read_bytes() == ( - overlay / "tools/performance_report/manual_campaign.py" - ).read_bytes() - assert (runtime / "_memory_watchdog.py").read_bytes() == ( - overlay / "tools/ci/memory_watchdog.py" - ).read_bytes() - assert (runtime / "_developer/__init__.py").is_file() - assert (runtime / "_developer/legacy_amplicol.py").read_bytes() == ( - overlay / "tools/developer/legacy_amplicol.py" - ).read_bytes() - oracle = runtime / "_developer/legacy_oracle" - assert {path.name for path in oracle.glob("*.py")} == { - path.name - for path in (overlay / "tools/developer/legacy_oracle").glob("*.py") - } - assert (oracle / "__init__.py").is_file() - with pytest.raises(RuntimeError, match="already contains"): - backend._stage_packaged_profiling_campaign(overlay) - - def test_wheel_stages_the_single_maintained_rusticol_stub() -> None: with backend._overlay("release") as (overlay, _target): source = ( @@ -1430,9 +1219,7 @@ def test_archive_overlay_without_git_history_uses_pruned_allowlist( source = tmp_path / "archive" retained = { Path("build_backend/backend.py"): "archive = True\n", - Path("src/pyamplicol/_profiling_campaign/pyAmpliCol.tex"): ( - "maintained TeX\n" - ), + Path("docs/user/report.tex"): "maintained TeX\n", Path("release_assets/prepared_models/README.md"): "release store\n", Path("src/pyamplicol/_sdk/config.py"): "maintained SDK config\n", Path("src/rusticol_config/__init__.py"): "standalone SDK config\n", @@ -1449,13 +1236,9 @@ def test_archive_overlay_without_git_history_uses_pruned_allowlist( Path("build_backend/python_lock.py"), Path("docs/.result_outputs/cache.json"), Path("docs/archive/retired.md"), - Path("src/pyamplicol/_profiling_campaign/pyAmpliCol.aux"), - Path("src/pyamplicol/_profiling_campaign/pyAmpliCol.synctex.gz"), - Path("docs/performance_reports/macbook_M3/pyAmpliCol.toc"), - Path( - "src/pyamplicol/_profiling_campaign/campaign_artifacts/" - "private-attempt.bin" - ), + Path("docs/user/report.aux"), + Path("docs/user/report.synctex.gz"), + Path("docs/user/report.toc"), Path("src/pyamplicol.egg-info/PKG-INFO"), Path("src/pyamplicol/_rusticol.abi3.so"), Path("src/pyamplicol/_rusticol.dylib"), @@ -1659,9 +1442,6 @@ def delegated(*_args, **_kwargs): lambda _path: "0.1.0", ) monkeypatch.setattr(backend, "_stage_packaged_examples", lambda path: None) - monkeypatch.setattr( - backend, "_stage_packaged_profiling_campaign", lambda path: None - ) monkeypatch.setattr(backend, "_stage_python_stub", lambda path: None) monkeypatch.setattr(backend, "_stage_runtime_resources", lambda path: None) monkeypatch.setattr( diff --git a/pyamplicol/tests/unit/test_catalog_final_source_structural_preflight.py b/pyamplicol/tests/unit/test_catalog_final_source_structural_preflight.py deleted file mode 100644 index 8dd53ef68f..0000000000 --- a/pyamplicol/tests/unit/test_catalog_final_source_structural_preflight.py +++ /dev/null @@ -1,75 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.developer.catalog_final_source_structural_preflight import ( - FinalSourceProducerError, - _counts, - _legacy_record, -) -from tools.developer.emit_candidate_structural_preflight import _numerical_proof -from tools.performance_report.catalog import REPORT_CATALOG - - -def test_structural_counts_do_not_accept_summary_placeholders() -> None: - with pytest.raises(FinalSourceProducerError, match="non-negative integer"): - _counts( - { - "source_current_count": 1, - "produced_current_count": 2, - "kernel_evaluation_count": None, - "attachment_count": 4, - "amplitude_destination_count": 1, - }, - "candidate.active", - ) - - -def test_opaque_precision50_digest_is_not_accepted_as_truth(tmp_path: Path) -> None: - revision = "a" * 40 - path = tmp_path / "precision50.json" - path.write_text( - json.dumps( - { - "status": "ok", - "source_revision": revision, - "precision_decimal_digits": 50, - "comparison_sha256": "b" * 64, - } - ) - ) - with pytest.raises( - FinalSourceProducerError, - match="recomputable independent precision>=50 witness", - ): - _numerical_proof(path, revision) - - -def test_legacy_proof_is_bound_to_exact_reference_cell(tmp_path: Path) -> None: - reference = next( - cell - for cell in REPORT_CATALOG.reference_cells() - if REPORT_CATALOG.legacy_reference_available(cell) - ) - (tmp_path / "legacy-structural-proof.json").write_text( - json.dumps( - { - "schema": "pyamplicol-legacy-final-structural-proof-v1", - "cell_id": f"{reference.cell_id}-wrong", - "accuracy": reference.measurement.accuracy.value, - "workload": reference.workload.value, - "source_revision": "a" * 40, - } - ) - ) - result = { - "status": "ok", - "artifact": {"path": str(tmp_path)}, - "provenance": {"revision": "a" * 40}, - } - with pytest.raises(FinalSourceProducerError, match="wrong identity"): - _legacy_record(reference, result) diff --git a/pyamplicol/tests/unit/test_catalog_restart_parity_gate.py b/pyamplicol/tests/unit/test_catalog_restart_parity_gate.py deleted file mode 100644 index e331414501..0000000000 --- a/pyamplicol/tests/unit/test_catalog_restart_parity_gate.py +++ /dev/null @@ -1,497 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -from copy import deepcopy -from decimal import Decimal -from pathlib import Path - -from pyamplicol.artifacts import ArtifactBuilder, load_manifest -from pyamplicol.generation.structural_source_proof import ( - ROLE as STRUCTURAL_SOURCE_PROOF_ROLE, -) -from pyamplicol.generation.structural_source_proof import ( - SEMANTIC_MAP_DOMAINS, - build_generation_structural_proof, -) -from tools.developer.catalog_restart_parity_gate import ( - SCHEMA, - validate_manifest, -) -from tools.developer.final_source_numerical_truth import ( - REFERENCE_SCHEMA, - _agreement, - _value_record, - canonical_sha256, - comparison_sha256, -) -from tools.developer.final_source_numerical_truth import ( - SCHEMA as TRUTH_SCHEMA, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ExecutionMode - -REVISION = "1" * 40 -DIGEST = "2" * 64 - - -def _counts(value: int = 10) -> dict[str, int]: - return { - "source_current_count": 2, - "produced_current_count": value - 2, - "kernel_evaluation_count": value, - "attachment_count": value, - "amplitude_destination_count": 2, - } - - -def _truth( - cell: object, - *, - candidate_id: str, - structural_path: str, - structural_sha256: str, -) -> dict[str, object]: - reference_id = hashlib.sha256(f"reference:{cell.cell_id}".encode()).hexdigest() - contract: dict[str, object] = { - "schema": REFERENCE_SCHEMA, - "status": "materialized", - "semantics": "pre-optimization-reference", - "source_revision": REVISION, - "artifact_id": reference_id, - "process_id": "process", - "contract_sha256": hashlib.sha256( - f"contract:{cell.cell_id}".encode() - ).hexdigest(), - "semantic_payloads": [ - { - "path": "reference.json", - "sha256": hashlib.sha256( - f"reference-payload:{cell.cell_id}".encode() - ).hexdigest(), - } - ], - } - contract["semantic_identity_sha256"] = canonical_sha256( - "independent-reference-semantics-v1", - contract, - ) - momenta: dict[str, object] = { - "candidate_payload_sha256": hashlib.sha256(b"candidate-points").hexdigest(), - "reference_payload_sha256": hashlib.sha256(b"reference-points").hexdigest(), - "points": [ - [ - {"pdg": 1, "momentum": ["5", "0", "0", "5"]}, - {"pdg": -1, "momentum": ["5", "0", "0", "-5"]}, - ] - ], - } - momenta["validation_momenta_sha256"] = canonical_sha256( - "final-source-validation-momenta-v1", - momenta, - ) - selected = cell.workload.value == "selected-flow" - selectors: dict[str, object] = { - "workload": cell.workload.value, - "helicity_ids": ["h:0"] if selected else [], - "color_ids": ["c:0"] if selected else [], - } - selectors["selector_sha256"] = canonical_sha256( - "final-source-selectors-v1", - selectors, - ) - axes: dict[str, object] = { - "color_accuracy": cell.measurement.accuracy.value, - "helicity_ids": ["h:0"], - "color_ids": ["c:0"], - } - axes["resolved_axes_sha256"] = canonical_sha256( - "final-source-resolved-axes-v1", - axes, - ) - exact_values = [[["1"]]] - native_values = [[[["1", "0"]]]] - agreement = _agreement( - exact_values, - native_values, - exact_values, - precision=80, - exact_agreement_digits=50, - native_relative_tolerance=Decimal("1e-10"), - native_absolute_tolerance=Decimal("1e-14"), - ) - truth: dict[str, object] = { - "schema": TRUTH_SCHEMA, - "status": "ok", - "cell_id": cell.cell_id, - "source_revision": REVISION, - "mode": cell.measurement.execution_mode.value, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "precision_decimal_digits": 80, - "validation_momenta": momenta, - "selectors": selectors, - "resolved_axes": axes, - "candidate_artifact": { - "artifact_id": candidate_id, - "source_revision": REVISION, - "structural_proof_path": structural_path, - "structural_proof_sha256": structural_sha256, - }, - "reference_artifact": { - "artifact_id": reference_id, - "source_revision": REVISION, - "semantics_contract": contract, - }, - "candidate_native": _value_record( - precision=16, - executor="native", - values=native_values, - domain="final-source-candidate-native-values-v1", - ), - "candidate_exact": _value_record( - precision=80, - executor="exact", - values=exact_values, - domain="final-source-candidate-exact-values-v1", - ), - "reference_exact": _value_record( - precision=80, - executor="reference", - values=exact_values, - domain="final-source-reference-exact-values-v1", - ), - "agreement": agreement, - } - truth["comparison_sha256"] = comparison_sha256(truth) - return truth - - -def _candidate( - cell: object, - evidence_root: Path, - *, - artifact_id: str, - structural_path: str, - structural_sha256: str, - generation_proof: dict[str, object], -) -> dict[str, object]: - maps = generation_proof["semantic_maps"] - witnesses = {name: maps[name]["rows"] for name in SEMANTIC_MAP_DOMAINS} - return { - "source_revision": REVISION, - "evidence_root": str(evidence_root), - "artifact_identity": { - "artifact_id": artifact_id, - "process_id": "process", - "structural_proof_path": structural_path, - "structural_proof_sha256": structural_sha256, - }, - "active": _counts(), - "final_materialized": _counts(), - "peak_materialized": _counts(), - "semantic_proof": { - "status": "proven", - "strength": "exact-symbolic", - "source_revision": REVISION, - "current_member_map_sha256": maps["current_member_map"]["sha256"], - "interaction_row_map_sha256": maps["interaction_row_map"]["sha256"], - "closure_map_sha256": maps["closure_map"]["sha256"], - "source_contract_sha256": maps["source_contract"]["sha256"], - "witnesses": witnesses, - }, - "numerical_validation": _truth( - cell, - candidate_id=artifact_id, - structural_path=structural_path, - structural_sha256=structural_sha256, - ), - "generation_structural_proof": generation_proof, - "persisted_lane_inventory": generation_proof["physical_lane_inventory"], - } - - -def _legacy(cell: object) -> dict[str, object]: - if not REPORT_CATALOG.legacy_reference_available(cell): - return { - "scope": "unavailable", - "reason": "original-amplicol-open-quark-line-limit", - } - return { - "scope": "available", - "active": _counts(), - "static": _counts(), - "object_mapping": { - "status": "exact", - "current_object_map_sha256": DIGEST, - "kernel_term_map_sha256": DIGEST, - "combine_route_map_sha256": DIGEST, - }, - "row_multiplicity": { - "status": "exact", - "histogram_sha256": DIGEST, - "call_count": 1, - }, - } - - -def _artifact_fixture( - tmp_path: Path, -) -> tuple[Path, str, str, str, dict[str, object]]: - artifact = tmp_path / "artifact" - execution_path = "processes/process/execution.json" - structural_path = "processes/process/structural-source-proof.json" - execution: dict[str, object] = { - "schema_version": 3, - "kind": "pyamplicol-runtime-recurrence-execution", - "key": "process", - "process": "d d~ > z", - "color_accuracy": "lc", - "external_pdg_order": [1, -1, 23], - "source_count": 2, - "current_count": 10, - "interaction_count": 10, - "amplitude_root_count": 2, - } - producer = { - "distribution": "pyamplicol", - "version": "0.1.0", - "versions": { - "python_api": 1, - "toml": 1, - "compiled_model": 1, - "process_artifact": 3, - "runtime_physics": 1, - "symbolica_serialization": "test", - "c_abi": 1, - }, - "target": {"triple": "test", "cpu_features": []}, - "git_revision": REVISION, - "native_build_inputs_sha256": DIGEST, - } - with ArtifactBuilder(artifact) as builder: - execution_record = builder.add_json( - execution_path, - execution, - role="evaluator-manifest", - process_id="process", - compact=True, - ) - generation_proof = build_generation_structural_proof( - artifact_root=builder.root, - process_id="process", - source_revision=REVISION, - native_build_inputs_sha256=DIGEST, - execution_path=execution_path, - execution_sha256=execution_record.sha256, - execution=execution, - evaluator_container_path=None, - evaluator_container_index_sha256=None, - ) - structural_record = builder.add_json( - structural_path, - generation_proof, - role=STRUCTURAL_SOURCE_PROOF_ROLE, - process_id="process", - compact=True, - ) - builder.finalize( - kind="pyamplicol-process", - producer=producer, - model={ - "name": "built-in-sm", - "source_kind": "built-in-sm", - "content_sha256": DIGEST, - "compiled_schema_version": 1, - }, - configuration={ - "toml_schema_version": 1, - "requested_path": "processes/process/execution.json", - "effective_path": "processes/process/execution.json", - "adjustments": [], - }, - processes=[ - { - "id": "process", - "expression": "d d~ > z", - "color_accuracy": "lc", - "external_pdgs": [1, -1, 23], - "physics_path": execution_path, - "required_runtime_capabilities": [ - "rusticol.recurrence-direct-arena.complex-f64.v1" - ], - "aliases": [], - } - ], - default_process_id="process", - runtime={ - "engine": "rusticol", - "engine_version": "0.1.0", - "evaluator_manifest_path": execution_path, - "api_bundle_path": None, - "required_runtime_capabilities": [ - "rusticol.recurrence-direct-arena.complex-f64.v1" - ], - }, - ) - manifest = load_manifest(artifact) - return ( - artifact, - manifest.artifact_id, - structural_path, - structural_record.sha256, - generation_proof, - ) - - -def _manifest(tmp_path: Path) -> dict[str, object]: - ( - artifact, - artifact_id, - structural_path, - structural_sha, - generation_proof, - ) = _artifact_fixture(tmp_path) - cells = [] - for cell in REPORT_CATALOG.matrix_cells(): - if cell.measurement.execution_mode not in { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - }: - continue - comparable = REPORT_CATALOG.legacy_reference_available(cell) - cells.append( - { - "cell_id": cell.cell_id, - "process_key": cell.process_key, - "n_final": cell.n_final, - "mode": cell.measurement.execution_mode.value, - "model": cell.measurement.model.value, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "classification": ( - "certified-parity" if comparable else "legacy-scope-unavailable" - ), - "candidate": _candidate( - cell, - artifact, - artifact_id=artifact_id, - structural_path=structural_path, - structural_sha256=structural_sha, - generation_proof=generation_proof, - ), - "legacy": _legacy(cell), - } - ) - return {"schema": SCHEMA, "source_revision": REVISION, "cells": cells} - - -def test_complete_exact_manifest_passes_every_catalog_row(tmp_path: Path) -> None: - result = validate_manifest(_manifest(tmp_path), expected_revision=REVISION) - assert result["summary"]["expected_cell_count"] == 1356 - assert result["summary"]["failed_row_count"] == 0 - assert result["summary"]["classification_counts"] == { - "certified-parity": 1314, - "legacy-scope-unavailable": 42, - } - assert result["summary"]["restart_ready"] is True - assert len(result["rows"]) == 1356 - - -def test_summary_boolean_cannot_replace_per_row_evidence() -> None: - result = validate_manifest( - { - "schema": SCHEMA, - "source_revision": REVISION, - "fully_certified_catalog_parity": True, - "cells": [], - }, - expected_revision=REVISION, - ) - assert result["summary"]["restart_ready"] is False - assert result["summary"]["failure_reason_counts"] == {"missing-record": 1356} - - -def test_missing_and_unexpected_rows_are_listed_with_reasons( - tmp_path: Path, -) -> None: - manifest = _manifest(tmp_path) - cells = manifest["cells"] - assert isinstance(cells, list) - cells.pop() - cells.append( - { - "cell_id": "not-in-the-report-catalog", - "classification": "certified-parity", - } - ) - result = validate_manifest(manifest, expected_revision=REVISION) - assert result["summary"]["failure_reason_counts"] == { - "missing-record": 1, - "unexpected-record": 1, - } - - -def test_numerical_only_generation_relation_fails_closed(tmp_path: Path) -> None: - manifest = _manifest(tmp_path) - cells = manifest["cells"] - assert isinstance(cells, list) - candidate = cells[0]["candidate"] - candidate["numerical_relation_discovery"] = { - "used_for_generation": True, - "reconstructed_exact": False, - } - result = validate_manifest(manifest, expected_revision=REVISION) - assert result["summary"]["failure_reason_counts"] == { - "numerical-only-relation-used-for-generation": 1 - } - - -def test_counts_only_certificate_and_stale_source_are_rejected( - tmp_path: Path, -) -> None: - manifest = _manifest(tmp_path) - cells = manifest["cells"] - assert isinstance(cells, list) - candidate = cells[0]["candidate"] - candidate["source_revision"] = "3" * 40 - candidate["semantic_proof"] = {"status": "proven"} - result = validate_manifest(manifest, expected_revision=REVISION) - assert result["summary"]["failure_reason_counts"] == { - "candidate-source-revision-mismatch": 1, - "semantic-proof-incomplete": 1, - "semantic-proof-not-exact": 1, - "semantic-proof-source-revision-mismatch": 1, - } - - -def test_static_inventory_and_ratio_are_recomputed_not_trusted( - tmp_path: Path, -) -> None: - manifest = _manifest(tmp_path) - cells = manifest["cells"] - assert isinstance(cells, list) - record = cells[0] - record["producer_ratio"] = 0.01 - candidate = record["candidate"] - candidate["final_materialized"] = _counts(20) - result = validate_manifest(manifest, expected_revision=REVISION) - reasons = result["rows"][0]["reason_codes"] - assert "final_materialized-logical_current-exceeds-1.05" in reasons - assert "final_materialized-kernel_evaluation-exceeds-1.05" in reasons - assert "final_materialized-attachment-exceeds-1.05" in reasons - - -def test_legacy_scope_unavailable_still_requires_candidate_self_proof( - tmp_path: Path, -) -> None: - manifest = _manifest(tmp_path) - cells = manifest["cells"] - assert isinstance(cells, list) - target = next(cell for cell in cells if cell["process_key"] == "dd_4q_lines") - target["candidate"] = deepcopy(target["candidate"]) - del target["candidate"]["numerical_validation"] - result = validate_manifest(manifest, expected_revision=REVISION) - row = next(row for row in result["rows"] if row["cell_id"] == target["cell_id"]) - assert row["reason_codes"] == ["numerical-validation-incomplete"] diff --git a/pyamplicol/tests/unit/test_catalog_structural_parity_audit.py b/pyamplicol/tests/unit/test_catalog_structural_parity_audit.py deleted file mode 100644 index 6f0614dd41..0000000000 --- a/pyamplicol/tests/unit/test_catalog_structural_parity_audit.py +++ /dev/null @@ -1,458 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.developer.catalog_structural_parity_audit import ( - CatalogParityError, - WorkCounts, - _candidate_counts, - _legacy_counts, - _parity_exit_code, - audit_source_manifest, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ExecutionMode, Workload - - -def _module(path: Path, currents: int, interactions: int) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - source_calls = "\n".join( - f"call ext_scalar(p,val_c(1,{current}))" - for current in range(1, currents) - ) - interaction_ids = ",".join(str(value) for value in range(1, interactions + 1)) - path.write_text( - "subroutine evaluate(p,val_c,int_c)\n" - f"complex(kind=8),dimension(1:6,{currents}) :: val_c\n" - f"complex(kind=8),dimension(1:6,{interactions}) :: int_c\n" - "end subroutine evaluate\n" - "subroutine compute_external_currents(p,val_c)\n" - f"{source_calls}\n" - "end subroutine compute_external_currents\n" - "subroutine vertex_type_fixture(p,val_c,int_c)\n" - f"integer,parameter,dimension({interactions}) :: int1=[{interaction_ids}]\n" - "end subroutine vertex_type_fixture\n" - "subroutine combine_currents_fixture(p,val_c,int_c)\n" - f"integer,parameter,dimension(0:{interactions},1) :: int1=" - f"reshape([{currents},{interaction_ids}]," - f"shape=[{interactions + 1},1])\n" - "end subroutine combine_currents_fixture\n" - ) - - -def test_selected_flow_uses_exact_process_row_module(tmp_path: Path) -> None: - artifact = tmp_path / "artifact" - _module( - artifact / "selected-flow-generated-library/Library/amp1_1_lib.f03", - 31, - 37, - ) - _module( - artifact / "selected-flow-generated-library/Library/amp2_1_lib.f03", - 41, - 47, - ) - counts = _legacy_counts( - { - "artifact": { - "path": str(artifact), - "process_row": "group:2:integral:1", - } - }, - workload=Workload.SELECTED_FLOW, - ) - assert counts.active is not None - assert counts.active.current_count == 41 - assert counts.active.evaluation_count == 47 - assert counts.active.attachment_count == 47 - assert counts.static.current_count == 31 + 41 - assert counts.static.evaluation_count == 37 + 47 - assert counts.static.attachment_count == 37 + 47 - assert counts.selected_module == "amp2_1_lib.f03" - assert counts.selected_module_object_mapping is not None - assert counts.selected_module_object_mapping.current_ids_complete is True - assert counts.selected_module_object_mapping.interaction_ids_complete is True - - -def test_contracted_without_call_histogram_keeps_active_work_unresolved( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - for index in range(1, 7): - _module( - artifact / f"contracted-generated-library/Library/amp{index}_1_lib.f03", - 406, - 2440, - ) - probe = ( - artifact - / "contracted-generated-library" - / "amplicol_color_library_probe.output" - ) - probe.write_text( - "Total number of currents, vertices and amplitudes after filter " - f"{720 * 406} {720 * 2440} 720\n" - ) - counts = _legacy_counts( - { - "artifact": { - "path": str(artifact), - "process_row": "group:1:integral:1", - } - }, - workload=Workload.CONTRACTED, - ) - assert counts.static.current_count == 6 * 406 - assert counts.static.evaluation_count == 6 * 2440 - assert counts.static.attachment_count == 6 * 2440 - assert counts.active is None - assert counts.limitation is not None - - -def test_contracted_uses_exact_call_histogram_for_nonuniform_modules( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - _module( - artifact / "contracted-generated-library/Library/amp1_1_lib.f03", - 10, - 20, - ) - _module( - artifact / "contracted-generated-library/Library/amp2_1_lib.f03", - 30, - 40, - ) - probe = ( - artifact - / "contracted-generated-library" - / "amplicol_color_library_probe.output" - ) - probe.write_text( - "Total number of currents, vertices and amplitudes after filter 123 456 7\n" - "AMPICOL_COLOR_PROBE_LIBRARY_CALLS 1 1 2\n" - "AMPICOL_COLOR_PROBE_LIBRARY_CALLS 2 1 5\n" - ) - counts = _legacy_counts( - { - "artifact": { - "path": str(artifact), - "process_row": "group:2:integral:1", - } - }, - workload=Workload.CONTRACTED, - ) - assert counts.active == WorkCounts( - 2 * 10 + 5 * 30, - 2 * 20 + 5 * 40, - 2 * 20 + 5 * 40, - ) - assert counts.static == WorkCounts(40, 60, 60) - assert counts.limitation is None - - -def test_recurrence_selector_certificate_separates_active_from_persisted( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - process = artifact / "processes/p/execution.json" - process.parent.mkdir(parents=True) - process.write_text( - json.dumps( - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 100, - "contribution_count": 200, - }, - "construction": { - "peak_current_count": 120, - "peak_contribution_count": 240, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - "selector_work_certificate": { - "representatives": [ - { - "current_count": 30, - "contribution_count": 40, - }, - { - "current_count": 35, - "contribution_count": 45, - }, - ] - }, - } - }, - } - ) - ) - counts = _candidate_counts( - { - "artifact": {"path": str(artifact)}, - "provenance": {"report_measured_source_revision": "abc"}, - }, - workload=Workload.SELECTED_FLOW, - ) - assert counts.active.current_count == 35 - assert counts.active.evaluation_count == 45 - assert counts.active.attachment_count == 45 - assert counts.final_materialized.current_count == 100 - assert counts.peak_materialized.evaluation_count == 240 - assert counts.peak_materialized.attachment_count == 240 - assert counts.selector_certificate_available is True - - -def test_recurrence_peak_requires_resident_semantics_marker( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - process = artifact / "processes/p/execution.json" - process.parent.mkdir(parents=True) - process.write_text( - json.dumps( - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 100, - "contribution_count": 200, - }, - "construction": { - "peak_current_count": 120, - "peak_contribution_count": 240, - }, - } - }, - } - ) - ) - - with pytest.raises( - CatalogParityError, - match="authenticated resident peak-contribution semantics", - ): - _candidate_counts( - { - "artifact": {"path": str(artifact)}, - "provenance": {"report_measured_source_revision": "abc"}, - }, - workload=Workload.CONTRACTED, - ) - - -def test_compiled_all_flow_uses_primary_fixed_helicity_dag( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - process = artifact / "processes/p/execution.json" - process.parent.mkdir(parents=True) - process.write_text( - json.dumps( - { - "kind": "pyamplicol-runtime-execution", - "dag_summary": { - "current_count": 31, - "interaction_count": 47, - "interaction_evaluation_count": 29, - }, - "helicity_selector_executions": [ - { - "execution": { - "dag_summary": { - "current_count": 19, - "interaction_count": 23, - "interaction_evaluation_count": 17, - } - } - } - ], - } - ) - ) - counts = _candidate_counts( - {"artifact": {"path": str(artifact)}}, - workload=Workload.ALL_FLOW, - ) - assert counts.active.current_count == 19 - assert counts.active.evaluation_count == 17 - assert counts.active.attachment_count == 23 - assert counts.final_materialized == WorkCounts(50, 46, 70) - assert counts.active_evidence_kind == ("compiled-fixed-helicity-worst-class") - assert counts.selector_certificate_available is True - - -def test_compiled_selected_flow_uses_worst_color_sector( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - process = artifact / "processes/p/execution.json" - process.parent.mkdir(parents=True) - process.write_text( - json.dumps( - { - "kind": "pyamplicol-runtime-execution", - "dag_summary": { - "current_count": 11, - "interaction_count": 13, - "interaction_evaluation_count": 7, - }, - "helicity_sum_execution": { - "dag_summary": { - "current_count": 101, - "interaction_count": 211, - "interaction_evaluation_count": 151, - }, - "color_selector_executions": [ - { - "execution": { - "dag_summary": { - "current_count": 31, - "interaction_count": 41, - "interaction_evaluation_count": 29, - } - } - }, - { - "execution": { - "dag_summary": { - "current_count": 37, - "interaction_count": 43, - "interaction_evaluation_count": 31, - } - } - }, - ], - }, - } - ) - ) - counts = _candidate_counts( - {"artifact": {"path": str(artifact)}}, - workload=Workload.SELECTED_FLOW, - ) - assert counts.active == WorkCounts(37, 31, 43) - assert counts.final_materialized == WorkCounts(180, 218, 308) - assert counts.active_evidence_kind == ("compiled-selected-color-worst-sector") - assert counts.selector_certificate_available is True - - -def test_eager_selector_census_separates_active_from_materialized( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - process = artifact / "processes/p/execution.json" - process.parent.mkdir(parents=True) - process.write_text( - json.dumps( - { - "kind": "pyamplicol-runtime-eager-execution", - "plan": { - "inspection_summary": { - "current_count": 101, - "invocation_count": 151, - "attachment_count": 211, - "selector_work": { - "abi": "pyamplicol-eager-selector-work-v1", - "selected_flow_current_count": 37, - "selected_flow_evaluation_count": 31, - "selected_flow_attachment_count": 43, - "all_flow_current_count": 41, - "all_flow_evaluation_count": 35, - "all_flow_attachment_count": 47, - "contracted_current_count": 101, - "contracted_evaluation_count": 151, - "contracted_attachment_count": 211, - }, - } - }, - } - ) - ) - counts = _candidate_counts( - {"artifact": {"path": str(artifact)}}, - workload=Workload.SELECTED_FLOW, - ) - assert counts.active == WorkCounts(37, 31, 43) - assert counts.final_materialized == WorkCounts(101, 151, 211) - assert counts.active_evidence_kind == "eager-selected-flow-selector-census" - assert counts.selector_certificate_available is True - - -def test_complete_parity_gate_fails_closed() -> None: - passing = {"summary": {"fully_certified_catalog_parity": True}} - failing = {"summary": {"fully_certified_catalog_parity": False}} - assert _parity_exit_code(passing, required=False) == 0 - assert _parity_exit_code(failing, required=False) == 0 - assert _parity_exit_code(passing, required=True) == 0 - assert _parity_exit_code(failing, required=True) == 2 - assert _parity_exit_code({}, required=True) == 2 - - -def test_source_preflight_requires_exact_all_catalog_coverage() -> None: - revision = "a" * 40 - cells = tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode - in {ExecutionMode.RECURRENCE, ExecutionMode.COMPILED, ExecutionMode.EAGER} - ) - assert len(cells) == 1356 - counts = { - "current_count": 100, - "evaluation_count": 200, - "attachment_count": 300, - } - rows = [] - for cell in cells: - candidate = { - "active": counts, - "final_materialized": counts, - "peak_materialized": counts, - "active_closure_count": 4, - "final_closure_count": 4, - "peak_closure_count": 4, - "dynamic_color_projection_applied": False, - "dynamic_color_projection": None, - } - row = { - "cell_id": cell.cell_id, - "source_revision": revision, - "proof_strength": "exact-source-construction", - "candidate": candidate, - } - if REPORT_CATALOG.legacy_reference_available(cell): - row |= { - "status": "ok", - "legacy": { - "active": counts, - "static": counts, - }, - } - else: - row |= { - "status": "legacy-scope-unavailable", - "scope_reason": "original AmpliCol supports at most three quark lines", - "legacy": None, - } - rows.append(row) - payload = audit_source_manifest( - { - "schema": "pyamplicol-catalog-source-structural-evidence-v1", - "source_revision": revision, - "cells": rows, - } - ) - - assert payload["summary"]["catalog_candidate_cell_count"] == 1356 - assert payload["summary"]["complete_catalog_coverage"] is True - assert payload["summary"]["fully_certified_catalog_parity"] is True diff --git a/pyamplicol/tests/unit/test_catalog_structural_scope_registry.py b/pyamplicol/tests/unit/test_catalog_structural_scope_registry.py deleted file mode 100644 index d4c1c36b56..0000000000 --- a/pyamplicol/tests/unit/test_catalog_structural_scope_registry.py +++ /dev/null @@ -1,37 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json - -from tools.developer.catalog_structural_scope_registry import ( - SCHEMA, - validate_reviewed_matrix_scope, -) - - -def test_reviewed_out_of_catalog_scope_is_exact_and_machine_readable() -> None: - scope = validate_reviewed_matrix_scope() - assert scope["schema"] == SCHEMA - assert scope["review"]["status"] == "reviewed" - assert { - item["scope_id"] for item in scope["intentionally_out_of_catalog"] - } == {"ufo-compiled-and-eager-lc-nlc"} - requirements = { - item["scope_id"]: item for item in scope["candidate_only_requirements"] - } - assert requirements[ - "four-open-quark-lines-lc-candidate-proof" - ]["catalog_cell_count"] == 32 - contracted = requirements[ - "four-open-quark-lines-contracted-candidate-proof" - ] - assert contracted["catalog_cell_count"] == 10 - assert contracted["mode_model_workload_plane_count_by_accuracy"] == { - "nlc": 4, - "full": 6, - } - assert contracted["legacy_comparison"] == { - "status": "unavailable", - "reason": "original-amplicol-open-quark-line-limit", - } - json.dumps(scope, sort_keys=True) diff --git a/pyamplicol/tests/unit/test_cli_utilities.py b/pyamplicol/tests/unit/test_cli_utilities.py index 1fc5795c9f..37f22227c8 100644 --- a/pyamplicol/tests/unit/test_cli_utilities.py +++ b/pyamplicol/tests/unit/test_cli_utilities.py @@ -3,16 +3,12 @@ import io import json -import os -import subprocess -import sys from pathlib import Path import pytest from pyamplicol.cli import UtilityInvocation, parse_cli, run_cli -from pyamplicol.cli.utilities import list_examples, profiling_campaign_root -from tools.performance_report.catalog import REPORT_CATALOG +from pyamplicol.cli.utilities import list_examples class _TTYStringIO(io.StringIO): @@ -143,414 +139,6 @@ def test_examples_copy_requires_force_for_nonempty_destination( assert run_cli(("examples", "copy", str(destination), "--force")) == 0 -def test_profiling_campaign_copy_is_reset_and_requires_force( - tmp_path: Path, -) -> None: - destination = tmp_path / "profiling-campaign" - invocation = parse_cli(("profiling-campaign", "copy", str(destination))) - assert isinstance(invocation, UtilityInvocation) - assert invocation.kind == "profiling-campaign-copy" - assert invocation.path == destination - assert invocation.force is False - - assert run_cli(("profiling-campaign", "copy", str(destination))) == 0 - copied = tuple(path for path in destination.rglob("*") if path.is_file()) - assert len(copied) == 69 - expected_cache_names = { - f"{cell.dataset_id}.json" for cell in REPORT_CATALOG.measurement_cells() - } | {"report-cache.schema.json"} - assert { - path.name for path in (destination / "results").glob("*.json") - } == expected_cache_names - assert (destination / "steer_performance_campaign.py").is_file() - assert os.access(destination / "steer_performance_campaign.py", os.X_OK) - launcher = destination / "steer_performance_campaign.py" - assert launcher.read_text(encoding="utf-8").splitlines()[0] == ( - f"#!{sys.executable}" - ) - environment = os.environ.copy() - environment.pop("PYTHONPATH", None) - environment["PATH"] = "/usr/bin:/bin" - direct = subprocess.run( - (str(launcher), "--help"), - check=False, - capture_output=True, - env=environment, - text=True, - ) - assert direct.returncode == 0, direct.stderr - table_filling = (destination / "TABLE_FILLING.md").read_text(encoding="utf-8") - assert "compact retained evidence" in table_filling - assert "keep attempts and large artifacts" not in table_filling - assert (destination / "results/report-cache.schema.json").is_file() - assert not (destination / "pyAmpliCol.pdf").exists() - assert not (destination / ".artifacts").exists() - assert (destination / "campaign_artifacts").is_dir() - assert not tuple((destination / "campaign_artifacts").iterdir()) - assert not (profiling_campaign_root() / "campaign_artifacts").exists() - copied_readme = (destination / "README.md").read_text(encoding="utf-8") - assert "moves its state" in copied_readme - assert "legacy `.artifacts`" in copied_readme - workspace = json.loads( - (destination / "report-workspace.json").read_text(encoding="utf-8") - ) - assert workspace["measurement_state"] == "reset" - assert workspace["initialized_from"] == "src/pyamplicol/_profiling_campaign" - assert workspace["report_source_revision"] == "unknown" - assert workspace["report_source_tree"] == "unknown" - assert workspace["initialized_source_identity"] == { - "clean": False, - "dirty_paths": [], - "revision": "unknown", - "schema": "pyamplicol-report-source-v1", - "tree": "unknown", - } - for path in sorted((destination / "results").glob("*.json")): - payload = json.loads(path.read_text(encoding="utf-8")) - for entry in payload.get("entries", ()): - assert entry["measurement"]["status"] == "not_available" - - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination)), - stderr=stderr, - ) - == 2 - ) - assert "not empty" in stderr.getvalue() - (destination / "campaign_artifacts/attempts/cell-a").mkdir(parents=True) - (destination / "campaign_artifacts/attempts/cell-a/payload.bin").write_bytes( - b"attempt" - ) - (destination / "campaign_summary_ids").mkdir() - (destination / "campaign_summary_ids/error.txt").write_text( - "cell-a\n", encoding="utf-8" - ) - (destination / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n") - (destination / "measurement_lineage.json").write_text( - "stale lineage\n", - encoding="utf-8", - ) - (destination / "pyAmpliCol.aux").write_text("stale aux\n", encoding="utf-8") - (destination / "pyAmpliCol.log").write_text("stale log\n", encoding="utf-8") - (destination / "notes.aux").write_text("unrelated\n", encoding="utf-8") - (destination / ".artifacts").mkdir() - (destination / ".artifacts/legacy.bin").write_bytes(b"legacy") - (destination / "unrelated.txt").write_text("keep\n", encoding="utf-8") - madgraph_cache = destination / "results/reference_madgraph_full.json" - madgraph_cache.write_text('{"stale":true}\n', encoding="ascii") - assert run_cli(("profiling-campaign", "copy", str(destination), "--force")) == 0 - assert (destination / "campaign_artifacts").is_dir() - assert not tuple((destination / "campaign_artifacts").iterdir()) - assert not (destination / "campaign_summary_ids").exists() - assert not (destination / "pyAmpliCol.pdf").exists() - assert not (destination / "measurement_lineage.json").exists() - assert not (destination / "pyAmpliCol.aux").exists() - assert not (destination / "pyAmpliCol.log").exists() - assert (destination / "notes.aux").read_text(encoding="utf-8") == "unrelated\n" - assert (destination / ".artifacts/legacy.bin").read_bytes() == b"legacy" - assert (destination / "unrelated.txt").read_text(encoding="utf-8") == "keep\n" - reset_madgraph_cache = json.loads(madgraph_cache.read_text(encoding="ascii")) - assert reset_madgraph_cache["dataset_id"] == "reference_madgraph_full" - assert { - entry["measurement"]["status"] for entry in reset_madgraph_cache["entries"] - } == {"not_available"} - - -def test_profiling_campaign_force_refuses_an_active_directory_lock( - tmp_path: Path, -) -> None: - import fcntl - - destination = tmp_path / "active-campaign" - assert run_cli(("profiling-campaign", "copy", str(destination))) == 0 - sentinel = destination / "campaign_artifacts/active-attempt.bin" - sentinel.write_bytes(b"active") - descriptor = os.open( - destination, - os.O_RDONLY | getattr(os, "O_DIRECTORY", 0), - ) - try: - fcntl.flock(descriptor, fcntl.LOCK_SH) - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination), "--force"), - stderr=stderr, - ) - == 2 - ) - assert "campaign is active" in stderr.getvalue() - assert sentinel.read_bytes() == b"active" - finally: - fcntl.flock(descriptor, fcntl.LOCK_UN) - os.close(descriptor) - - -def test_profiling_campaign_copy_records_local_amplicol_default( - tmp_path: Path, -) -> None: - checkout = tmp_path / "original-amplicol" - checkout.mkdir() - checkout = checkout.resolve() - destination = tmp_path / "profiling-campaign" - invocation = parse_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--local-amplicol", - str(checkout), - ) - ) - assert isinstance(invocation, UtilityInvocation) - assert invocation.local_amplicol == checkout - - assert ( - run_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--local-amplicol", - str(checkout), - ) - ) - == 0 - ) - configured = destination / ".pyamplicol-original-amplicol" - assert configured.read_text(encoding="utf-8") == f"{checkout}\n" - - assert run_cli(("profiling-campaign", "copy", str(destination), "--force")) == 0 - assert configured.read_text(encoding="utf-8") == f"{checkout}\n" - - replacement = tmp_path / "replacement-amplicol" - replacement.mkdir() - assert ( - run_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--force", - "--local-amplicol", - str(replacement), - ) - ) - == 0 - ) - assert configured.read_text(encoding="utf-8") == f"{replacement.resolve()}\n" - - -def test_profiling_campaign_copy_records_local_madgraph_default( - tmp_path: Path, -) -> None: - installation = tmp_path / "madgraph" - (installation / "bin").mkdir(parents=True) - (installation / "bin/mg5_aMC").write_text("#!/bin/sh\n", encoding="utf-8") - (installation / "bin/mg5_aMC").chmod(0o755) - installation = installation.resolve() - destination = tmp_path / "profiling-campaign" - invocation = parse_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--local-madgraph", - str(installation), - ) - ) - assert isinstance(invocation, UtilityInvocation) - assert invocation.local_madgraph == installation - - assert ( - run_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--local-madgraph", - str(installation), - ) - ) - == 0 - ) - configured = destination / ".pyamplicol-madgraph" - assert configured.read_text(encoding="utf-8") == f"{installation}\n" - - assert run_cli(("profiling-campaign", "copy", str(destination), "--force")) == 0 - assert configured.read_text(encoding="utf-8") == f"{installation}\n" - - replacement = tmp_path / "replacement-madgraph" - (replacement / "bin").mkdir(parents=True) - (replacement / "bin/mg5_aMC").write_text("#!/bin/sh\n", encoding="utf-8") - (replacement / "bin/mg5_aMC").chmod(0o755) - assert ( - run_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--force", - "--local-madgraph", - str(replacement), - ) - ) - == 0 - ) - assert configured.read_text(encoding="utf-8") == f"{replacement.resolve()}\n" - - -def test_profiling_campaign_copy_rejects_unsafe_local_madgraph_replacement( - tmp_path: Path, -) -> None: - destination = tmp_path / "profiling-campaign" - assert run_cli(("profiling-campaign", "copy", str(destination))) == 0 - sentinel = tmp_path / "external-madgraph-config" - sentinel.write_text("keep\n", encoding="utf-8") - (destination / ".pyamplicol-madgraph").symlink_to(sentinel) - replacement = tmp_path / "replacement-madgraph" - (replacement / "bin").mkdir(parents=True) - (replacement / "bin/mg5_aMC").write_text("#!/bin/sh\n", encoding="utf-8") - (replacement / "bin/mg5_aMC").chmod(0o755) - stderr = io.StringIO() - - assert ( - run_cli( - ( - "profiling-campaign", - "copy", - str(destination), - "--force", - "--local-madgraph", - str(replacement), - ), - stderr=stderr, - ) - == 2 - ) - assert ( - "unsafe profiling campaign output" in stderr.getvalue() - or "escapes its destination" in stderr.getvalue() - ) - assert sentinel.read_text(encoding="utf-8") == "keep\n" - - -def test_profiling_campaign_force_rejects_unsafe_exact_reset_targets( - tmp_path: Path, -) -> None: - external = tmp_path / "external" - external.mkdir() - sentinel = external / "sentinel" - sentinel.write_text("keep\n", encoding="utf-8") - - for name in ("campaign_artifacts", "campaign_summary_ids"): - destination = tmp_path / f"campaign-{name}" - destination.mkdir() - (destination / name).symlink_to(external, target_is_directory=True) - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination), "--force"), - stderr=stderr, - ) - == 2 - ) - assert "unsafe" in stderr.getvalue() or "escapes" in stderr.getvalue() - assert sentinel.read_text(encoding="utf-8") == "keep\n" - - destination = tmp_path / "campaign-pdf" - destination.mkdir() - (destination / "pyAmpliCol.pdf").symlink_to(sentinel) - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination), "--force"), - stderr=stderr, - ) - == 2 - ) - assert "unsafe" in stderr.getvalue() or "escapes" in stderr.getvalue() - assert sentinel.read_text(encoding="utf-8") == "keep\n" - - -def test_profiling_campaign_force_rejects_unsafe_managed_output( - tmp_path: Path, -) -> None: - external = tmp_path / "external-readme" - external.write_text("keep\n", encoding="utf-8") - destination = tmp_path / "campaign" - destination.mkdir() - (destination / "README.md").symlink_to(external) - - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination), "--force"), - stderr=stderr, - ) - == 2 - ) - assert "unsafe" in stderr.getvalue() or "escapes" in stderr.getvalue() - assert external.read_text(encoding="utf-8") == "keep\n" - - -def test_profiling_campaign_force_rejects_symlinked_destination( - tmp_path: Path, -) -> None: - real = tmp_path / "real" - real.mkdir() - destination = tmp_path / "campaign" - destination.symlink_to(real, target_is_directory=True) - - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination), "--force"), - stderr=stderr, - ) - == 2 - ) - assert "must not traverse a symlink" in stderr.getvalue() - assert not tuple(real.iterdir()) - - -def test_profiling_campaign_force_rejects_special_state_members( - tmp_path: Path, -) -> None: - destination = tmp_path / "campaign" - state = destination / "campaign_artifacts" - state.mkdir(parents=True) - os.mkfifo(state / "active.pipe") - - stderr = io.StringIO() - assert ( - run_cli( - ("profiling-campaign", "copy", str(destination), "--force"), - stderr=stderr, - ) - == 2 - ) - assert "contains a special file" in stderr.getvalue() - assert (state / "active.pipe").exists() - - -def test_profiling_campaign_copy_help_describes_local_reset( - capsys: pytest.CaptureFixture[str], -) -> None: - with pytest.raises(SystemExit) as stopped: - parse_cli(("profiling-campaign", "copy", "--help")) - - assert stopped.value.code == 0 - rendered = capsys.readouterr().out - assert "DEST/campaign_artifacts" in rendered - assert "moves with DEST" in rendered - assert "unrelated files" in rendered - assert "--local-madgraph" in rendered - assert "MadGraph installation" in rendered - - def test_config_template_and_resolve(tmp_path: Path) -> None: target = tmp_path / "all.toml" assert run_cli(("config", "template", str(target))) == 0 diff --git a/pyamplicol/tests/unit/test_compiled_all_jit_arena_gate.py b/pyamplicol/tests/unit/test_compiled_all_jit_arena_gate.py deleted file mode 100644 index 05b138652b..0000000000 --- a/pyamplicol/tests/unit/test_compiled_all_jit_arena_gate.py +++ /dev/null @@ -1,412 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import argparse -import os -from collections.abc import Callable -from copy import deepcopy -from pathlib import Path - -import pytest - -from tools.developer import compiled_all_jit_arena_gate as gate - - -def test_checked_file_identity_rejects_a_symlink(tmp_path: Path) -> None: - if not hasattr(os, "O_NOFOLLOW"): - pytest.skip("O_NOFOLLOW is unavailable") - target = tmp_path / "target.bin" - target.write_bytes(b"authenticated") - link = tmp_path / "link.bin" - link.symlink_to(target) - with pytest.raises(gate.GateError, match="checked fd"): - gate._regular_file_identity(link) - - -def _source_leaf( - optimization_level: int, - *, - include_plane: bool = True, -) -> dict[str, object]: - leaf: dict[str, object] = { - "kind": "symjit-application-evaluator", - "backend": "jit", - "runtime_capability": gate.SYMJIT_RUNTIME_CAPABILITY, - "input_len": 1, - "output_len": 1, - "application_path": f"evaluators/stage-o{optimization_level}.symjit", - "application_abi": gate.SYMJIT_APPLICATION_ABI, - "optimization_level": optimization_level, - } - if include_plane: - leaf["plane_application"] = { - "application_path": ( - f"evaluators/stage-o{optimization_level}.plane.symjit" - ), - "application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "storage_abi": gate.SYMJIT_APPLICATION_ABI, - "translation_mode": "symbolica-structured-instructions", - "optimization_level": optimization_level, - "direct_arena": True, - "source_digest": f"{optimization_level}" * 64, - } - return leaf - - -def _stage(optimization_level: int) -> dict[str, object]: - path = f"evaluators/stage-o{optimization_level}.plane.symjit" - return { - "stage_kind": "amplitude-roots", - "output_length": 1, - "evaluator": _source_leaf(optimization_level), - "compiled_plane_arena": { - "kind": "compiled-plane-arena-stage", - "schema_version": 1, - "application_abi": gate.COMPILED_PLANE_DIRECT_APPLICATION_ABI, - "source_application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "element_layout": "split-complex-component-major", - "input_output_aliasing": "forbidden", - "output_output_aliasing": "forbidden", - "output_operation": "overwrite", - "output_factor": "identity", - "input_bindings": [ - { - "kind": "value", - "parameter_index": 0, - "source_id": 0, - "component": 0, - } - ], - "output_bindings": [ - {"arena": "amplitude", "component": 0, "output_index": 0} - ], - "leaves": [ - { - "application_path": path, - "source_application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "optimization_level": optimization_level, - "direct_codegen_optimization_level": optimization_level, - "input_indices": [0], - "input_len": 1, - "output_len": 1, - "output_start": 0, - "output_stop": 1, - } - ], - }, - } - - -def _stage_set(optimization_level: int) -> dict[str, object]: - return { - "kind": "generic-dag-stage-evaluator-artifacts", - "runtime_available": True, - "required_runtime_capabilities": [ - gate.COMPILED_PLANE_ARENA_CAPABILITY, - gate.SYMJIT_RUNTIME_CAPABILITY, - ], - "stage_count": 1, - "stages": [], - "amplitude_stage": _stage(optimization_level), - } - - -def _execution_payload(optimization_level: int) -> dict[str, object]: - return { - "required_runtime_capabilities": [ - gate.COMPILED_PLANE_ARENA_CAPABILITY, - gate.SYMJIT_RUNTIME_CAPABILITY, - ], - "compiled": { - "model_parameter_evaluator": { - "kind": "model-parameter-evaluator", - "evaluator": _source_leaf( - optimization_level, - include_plane=False, - ), - }, - "stage_evaluators": _stage_set(optimization_level), - }, - "helicity_sum_execution": { - "required_runtime_capabilities": [ - gate.COMPILED_PLANE_ARENA_CAPABILITY, - ], - "runtime_schema": { - "model_parameter_evaluator": None, - "stage_evaluators": _stage_set(optimization_level), - }, - }, - } - - -def _profile() -> dict[str, object]: - result: dict[str, object] = { - "execution_mode": "compiled", - "evaluator_backend_call_count": 7, - "compiled_direct_arena_engine_count": 2, - "compiled_direct_arena_call_count": 7, - } - result.update(dict.fromkeys(gate._ZERO_PROFILE_COUNTERS, 0)) - result.update(dict.fromkeys(gate._ZERO_PROFILE_TIMES, 0.0)) - return result - - -def _capture(offset: float = 0.0) -> gate.EvaluationCapture: - values = (complex(1.0 + offset), complex(2.0 + offset)) - components = (complex(0.25 + offset), complex(0.75)) - return gate.EvaluationCapture( - physics_axes={ - "process": gate.PROCESS, - "helicities": ["h:one"], - "color_flows": ["flow:one"], - }, - f64_total=values, - precision32_total=values, - f64_components=components, - precision32_components=components, - ) - - -@pytest.mark.parametrize("optimization_level", gate.JIT_LEVELS) -def test_recursive_audit_accepts_every_jit_level( - optimization_level: int, -) -> None: - result = gate._audit_execution_payload( - _execution_payload(optimization_level), - optimization_level, - ) - - assert result["source_optimization_level"] == optimization_level - assert result["stage_set_count"] == 2 - assert result["descriptor_count"] == 2 - assert result["leaf_count"] == 2 - assert result["model_parameter_direct_application_count"] == 0 - assert result["passes"] is True - - -@pytest.mark.parametrize( - "mutation, message", - [ - ( - lambda payload: payload["compiled"]["stage_evaluators"][ - "amplitude_stage" - ].pop("compiled_plane_arena"), - "compiled_plane_arena", - ), - ( - lambda payload: payload["compiled"]["stage_evaluators"]["amplitude_stage"][ - "compiled_plane_arena" - ]["leaves"][0].update({"optimization_level": 3}), - "does not retain JIT O1", - ), - ( - lambda payload: payload["compiled"]["stage_evaluators"]["amplitude_stage"][ - "compiled_plane_arena" - ]["leaves"][0].update({"direct_codegen_optimization_level": 2}), - "does not match.*plane", - ), - ( - lambda payload: payload["helicity_sum_execution"]["runtime_schema"][ - "stage_evaluators" - ]["amplitude_stage"]["evaluator"].update({"optimization_level": 2}), - "does not retain JIT O1", - ), - ( - lambda payload: payload["compiled"]["model_parameter_evaluator"].update( - {"compiled_plane_arena": {"kind": "compiled-plane-arena-stage"}} - ), - "model_parameter_evaluator illegally", - ), - ( - lambda payload: payload["compiled"]["model_parameter_evaluator"].update( - { - "nested": { - "application_abi": (gate.NATIVE_COMPILED_DIRECT_APPLICATION_ABI) - } - } - ), - "direct application ABI", - ), - ], -) -def test_recursive_audit_rejects_level_or_direct_application_drift( - mutation: Callable[[dict[str, object]], object], - message: str, -) -> None: - payload = deepcopy(_execution_payload(1)) - mutation(payload) - - with pytest.raises(gate.GateError, match=message): - gate._audit_execution_payload(payload, 1) - - -def test_profile_audit_requires_direct_calls_and_zero_legacy_traffic() -> None: - result = gate._audit_profile(_profile()) - - assert result["direct_arena_engine_counter"] == { - "name": "compiled_direct_arena_engine_count", - "value": 2, - } - assert result["direct_arena_call_counter"] == { - "name": "compiled_direct_arena_call_count", - "value": 7, - } - assert result["passes"] is True - - traffic = _profile() - traffic["amplitude_output_remap_component_count"] = 1 - with pytest.raises(gate.GateError, match=r"output_remap.*=1"): - gate._audit_profile(traffic) - - no_calls = _profile() - no_calls["compiled_direct_arena_call_count"] = 0 - with pytest.raises(gate.GateError, match="no compiled Direct-Arena calls"): - gate._audit_profile(no_calls) - - incomplete_calls = _profile() - incomplete_calls["compiled_direct_arena_call_count"] = 6 - with pytest.raises(gate.GateError, match="every evaluator backend call"): - gate._audit_profile(incomplete_calls) - - -def test_profile_audit_requires_explicit_direct_engine_counter() -> None: - profile = _profile() - - result = gate._audit_profile(profile) - - assert result["direct_arena_engine_counter"] == { - "name": "compiled_direct_arena_engine_count", - "value": 2, - } - - profile["compiled_direct_arena_engine_count"] = 0 - with pytest.raises(gate.GateError, match="no compiled Direct-Arena engines"): - gate._audit_profile(profile) - - -def test_runtime_profile_fails_closed_when_api_has_no_profiler() -> None: - class RuntimeWithoutProfile: - pass - - with pytest.raises(gate.GateError, match="activity cannot be proven"): - gate._profile_runtime(RuntimeWithoutProfile(), (((),),)) - - -def test_cross_level_parity_covers_totals_and_resolved_components() -> None: - captures = {level: _capture() for level in gate.JIT_LEVELS} - - result = gate._cross_level_parity(captures) - - assert set(result["comparisons"]) == {"o0_vs_o3", "o1_vs_o3", "o2_vs_o3"} - assert all( - set(comparisons) - == { - "f64_totals", - "precision32_totals", - "f64_resolved_components", - "precision32_resolved_components", - } - for comparisons in result["comparisons"].values() - ) - - captures[1] = _capture(offset=1.0e-3) - with pytest.raises(gate.GateError, match="O1/O3 f64 totals"): - gate._cross_level_parity(captures) - - -def test_orchestrator_generates_and_checks_exactly_o0_through_o3( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - generated: list[int] = [] - source = {"revision": "a" * 40} - runtime = {"identity": "candidate"} - runtime_sha = gate._canonical_sha256(runtime) - monkeypatch.setattr(gate, "_source_identity", lambda: source) - monkeypatch.setattr(gate, "_runtime_identity", lambda observed: runtime) - monkeypatch.setattr( - gate, - "_file_identity", - lambda path: {"path": str(path), "sha256": "c" * 64}, - ) - monkeypatch.setattr( - gate, - "_prepare_output_root", - lambda output_root, replace: tmp_path, - ) - monkeypatch.setattr(gate, "_deterministic_points", lambda count: (((),),) * count) - monkeypatch.setattr( - gate, - "_points_identity", - lambda points: {"sha256": "b" * 64, "point_count": len(points)}, - ) - - def generate( - artifact: Path, - optimization_level: int, - expected_revision: str, - expected_script_sha256: str, - *, - timeout: float, - ) -> dict[str, object]: - generated.append(optimization_level) - return { - "optimization_level": optimization_level, - "artifact": str(artifact), - "timeout": timeout, - "worker_provenance": { - "source_revision": expected_revision, - "runtime_identity_sha256": runtime_sha, - "gate_script_sha256": expected_script_sha256, - "postflight_identity_match": True, - }, - } - - monkeypatch.setattr(gate, "_invoke_generation_worker", generate) - monkeypatch.setattr( - gate, - "_artifact_identity_and_audit", - lambda artifact, level: ({"artifact_id": f"o{level}"}, "process"), - ) - monkeypatch.setattr( - gate, - "_evaluate_artifact", - lambda artifact, process_id, optimization_level, points: ( - {"passes": True}, - _capture(), - ), - ) - monkeypatch.setattr(gate, "_peak_rss_gib", lambda: 1.0) - arguments = argparse.Namespace( - output_root=tmp_path, - replace=False, - points=2, - generation_timeout=123.0, - ) - - result = gate.run_gate(arguments) - - assert generated == [0, 1, 2, 3] - assert set(result["levels"]) == {"jit-o0", "jit-o1", "jit-o2", "jit-o3"} - assert result["passes"] is True - assert result["status"] == "ok" - assert result["source_identity_match"] is True - assert result["runtime_identity_match"] is True - assert result["gate_script_identity_match"] is True - assert result["content_identity"]["sha256"] == gate._canonical_sha256( - {key: value for key, value in result.items() if key != "content_identity"} - ) - - -def test_parser_documents_mandatory_watchdog_and_defaults() -> None: - parsed = gate.parser().parse_args(["--output-root", "out"]) - - assert parsed.points == 2 - assert parsed.generation_timeout == 3_600.0 - assert "--limit-gib 30" in gate.WATCHDOG_INVOCATION - assert "compiled_all_jit_arena_gate.py" in gate.WATCHDOG_INVOCATION - - -def test_output_root_must_not_dirty_the_authenticated_checkout() -> None: - with pytest.raises(gate.GateError, match="outside the source checkout"): - gate._prepare_output_root(gate.ROOT / "generated-gate", replace=False) diff --git a/pyamplicol/tests/unit/test_compiled_microkernel_acceptance.py b/pyamplicol/tests/unit/test_compiled_microkernel_acceptance.py deleted file mode 100644 index ec076fe4df..0000000000 --- a/pyamplicol/tests/unit/test_compiled_microkernel_acceptance.py +++ /dev/null @@ -1,1180 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -import json -import tomllib -from collections.abc import Callable -from pathlib import Path - -import pytest - -from tools.developer import compiled_microkernel_acceptance as acceptance - - -def test_dependency_identity_is_read_from_the_release_lock() -> None: - root = Path(__file__).resolve().parents[2] - with (root / "dependencies" / "release-lock.toml").open("rb") as stream: - symjit = tomllib.load(stream)["symjit"] - - assert acceptance.DEPENDENCY_SOURCE == "registry+https://github.com/rust-lang/crates.io-index" - assert symjit["version"] == acceptance.DEPENDENCY_VERSION - - -def _digest(character: str) -> str: - return character * 64 - - -def _certificate(kind: str, rows: list[dict[str, object]]) -> dict[str, object]: - payload: dict[str, object] = {"kind": kind, "rows": rows} - return {**payload, "sha256": acceptance.canonical_sha256(payload)} - - -def _diagnostics( - *, - islands: int = 1, - kernels: int = 1, - invocations: int = 2, - attachments: int = 2, - table_code: int = 100, - residual_code: int = 50, - semantic_bytes: int = 32, - arena_bytes: int = 64, - allocations: int = 0, -) -> dict[str, int]: - return { - "island_count": islands, - "kernel_count": kernels, - "invocation_count": invocations, - "attachment_count": attachments, - "table_machine_code_bytes": table_code, - "residual_machine_code_bytes": residual_code, - "semantic_row_bytes": semantic_bytes, - "arena_bytes": arena_bytes, - "warmed_allocation_count": allocations, - } - - -def _stage_plan() -> dict[str, object]: - return { - "kind": acceptance.STAGE_PLAN_KIND, - "schema_version": acceptance.STAGE_PLAN_SCHEMA_VERSION, - "stage_id": "stage-0", - "direct_application_abi": acceptance.DIRECT_APPLICATION_ABI, - "direct_table_binding_abi": acceptance.DIRECT_TABLE_BINDING_ABI, - "direct_table_descriptor_abi": acceptance.DIRECT_TABLE_DESCRIPTOR_ABI, - "output_current_ids": [10, 11], - "table_current_ids": [10], - "residual_current_ids": [11], - "residual_leaves": [ - { - "leaf_id": 0, - "current_ids": [11], - "source_sha256": _digest("1"), - "source_abi": acceptance.DIRECT_APPLICATION_ABI, - "source_bytes": 120, - "machine_code_bytes": 50, - "optimization_level": 3, - } - ], - "kernels": [ - { - "kernel_id": 0, - "kernel_family": acceptance.VECTOR_WEYL_KERNEL_FAMILY, - "motif_sha256": _digest("2"), - "source_sha256": _digest("3"), - "descriptor_sha256": _digest("4"), - "source_abi": acceptance.DIRECT_APPLICATION_ABI, - "binding_abi": acceptance.DIRECT_TABLE_BINDING_ABI, - "descriptor_abi": acceptance.DIRECT_TABLE_DESCRIPTOR_ABI, - "canonical_input_order": ["left-current", "momentum"], - "input_permutation": [0, 1], - "result_signature": "vector-weyl:2", - "mutable_parameter_sha256": _digest("5"), - "coupling_provenance_sha256": _digest("6"), - "selector_domain_sha256": _digest("7"), - "finalizer_sha256": _digest("8"), - "input_complex_count": 2, - "output_complex_count": 2, - "source_bytes": 4096, - "machine_code_bytes": 100, - "optimization_level": 3, - } - ], - "islands": [ - { - "island_id": 0, - "kernel_id": 0, - "current_ids": [10], - "selector_partition_sha256": _digest("9"), - "invocations": [ - { - "invocation_id": 0, - "evaluation_group_id": 7, - "attachment_start": 0, - "attachment_count": 1, - }, - { - "invocation_id": 1, - "evaluation_group_id": 8, - "attachment_start": 1, - "attachment_count": 1, - }, - ], - "attachments": [ - { - "attachment_id": 0, - "invocation_id": 0, - "current_id": 10, - "evaluation_group_id": 7, - "operation": "overwrite", - "destination_complex_count": 2, - "factor_id": 0, - }, - { - "attachment_id": 1, - "invocation_id": 1, - "current_id": 10, - "evaluation_group_id": 8, - "operation": "accumulate", - "destination_complex_count": 2, - "factor_id": 0, - }, - ], - "factor_catalog": [{"factor_id": 0, "factor_sha256": _digest("a")}], - "plane_bindings": [ - { - "plane_id": index, - "role": role, - "canonical_index": index, - "permutation_index": index, - } - for index, role in enumerate( - ("current", "momentum", "parameter", "factor") - ) - ], - "dependency_certificate": _certificate( - "complete-current-independence-v1", - [{"current_id": 10, "predecessor_current_ids": [1, 2]}], - ), - "order_certificate": _certificate( - "evaluation-group-order-v1", - [{"current_id": 10, "evaluation_group_ids": [7, 8]}], - ), - "semantic_row_bytes": 32, - "arena_bytes": 64, - } - ], - "finalizers": [ - { - "current_id": 10, - "island_id": 0, - "identity_sha256": _digest("8"), - } - ], - "diagnostics": _diagnostics(), - } - - -def _residual_only_stage() -> dict[str, object]: - stage = _stage_plan() - stage["table_current_ids"] = [] - stage["residual_current_ids"] = [10, 11] - stage["residual_leaves"] = [ - { - "leaf_id": 0, - "current_ids": [10, 11], - "source_sha256": _digest("1"), - "source_abi": acceptance.DIRECT_APPLICATION_ABI, - "source_bytes": 240, - "machine_code_bytes": 75, - "optimization_level": 3, - } - ] - stage["kernels"] = [] - stage["islands"] = [] - stage["finalizers"] = [] - stage["diagnostics"] = _diagnostics( - islands=0, - kernels=0, - invocations=0, - attachments=0, - table_code=0, - residual_code=75, - semantic_bytes=0, - arena_bytes=0, - ) - return stage - - -def _table_only_stage() -> dict[str, object]: - stage = _stage_plan() - stage["output_current_ids"] = [10] - stage["residual_current_ids"] = [] - stage["residual_leaves"] = [] - diagnostics = stage["diagnostics"] - assert isinstance(diagnostics, dict) - diagnostics["residual_machine_code_bytes"] = 0 - return stage - - -def _authorized_extended_stage_plan() -> dict[str, object]: - vector_current_ids = list(range(26)) - three_vector_current_ids = list(range(26, 31)) - residual_current_ids = list(range(31, 55)) - contribution_counts = [width for width in range(1, 7) for _ in range(4)] - contribution_counts.extend((7, 7)) - assert len(contribution_counts) == 26 - assert sum(contribution_counts) == 98 - - vector_invocations: list[dict[str, object]] = [] - vector_attachments: list[dict[str, object]] = [] - vector_order_rows: list[dict[str, object]] = [] - group_id = 0 - for current_id, contribution_count in zip( - vector_current_ids, - contribution_counts, - strict=True, - ): - current_groups: list[int] = [] - for contribution_index in range(contribution_count): - invocation_id = len(vector_invocations) - vector_invocations.append( - { - "invocation_id": invocation_id, - "evaluation_group_id": group_id, - "attachment_start": invocation_id, - "attachment_count": 1, - } - ) - vector_attachments.append( - { - "attachment_id": invocation_id, - "invocation_id": invocation_id, - "current_id": current_id, - "evaluation_group_id": group_id, - "operation": ( - "overwrite" if contribution_index == 0 else "accumulate" - ), - "destination_complex_count": 2, - "factor_id": 0, - } - ) - current_groups.append(group_id) - group_id += 1 - vector_order_rows.append( - { - "current_id": current_id, - "evaluation_group_ids": current_groups, - } - ) - assert group_id == 98 - - three_vector_invocations = [ - { - "invocation_id": index, - "evaluation_group_id": 98 + index, - "attachment_start": index, - "attachment_count": 1, - } - for index in range(5) - ] - three_vector_attachments = [ - { - "attachment_id": index, - "invocation_id": index, - "current_id": current_id, - "evaluation_group_id": 98 + index, - "operation": "overwrite", - "destination_complex_count": 4, - "factor_id": 0, - } - for index, current_id in enumerate(three_vector_current_ids) - ] - - def bindings() -> list[dict[str, object]]: - return [ - { - "plane_id": index, - "role": role, - "canonical_index": index, - "permutation_index": index, - } - for index, role in enumerate(("current", "momentum", "parameter", "factor")) - ] - - vector_finalizer = _digest("8") - three_vector_finalizer = _digest("d") - return { - "kind": acceptance.STAGE_PLAN_KIND, - "schema_version": acceptance.STAGE_PLAN_SCHEMA_VERSION, - "stage_id": "stage-0", - "direct_application_abi": acceptance.DIRECT_APPLICATION_ABI, - "direct_table_binding_abi": acceptance.DIRECT_TABLE_BINDING_ABI, - "direct_table_descriptor_abi": acceptance.DIRECT_TABLE_DESCRIPTOR_ABI, - "output_current_ids": list(range(55)), - "table_current_ids": vector_current_ids + three_vector_current_ids, - "residual_current_ids": residual_current_ids, - "residual_leaves": [ - { - "leaf_id": 0, - "current_ids": residual_current_ids, - "source_sha256": _digest("1"), - "source_abi": acceptance.DIRECT_APPLICATION_ABI, - "source_bytes": 120, - "machine_code_bytes": 50, - "optimization_level": 3, - } - ], - "kernels": [ - { - "kernel_id": 0, - "kernel_family": acceptance.VECTOR_WEYL_KERNEL_FAMILY, - "motif_sha256": _digest("2"), - "source_sha256": _digest("3"), - "descriptor_sha256": _digest("4"), - "source_abi": acceptance.DIRECT_APPLICATION_ABI, - "binding_abi": acceptance.DIRECT_TABLE_BINDING_ABI, - "descriptor_abi": acceptance.DIRECT_TABLE_DESCRIPTOR_ABI, - "canonical_input_order": [f"input-{index}" for index in range(6)], - "input_permutation": list(range(6)), - "result_signature": "vector-weyl:2", - "mutable_parameter_sha256": _digest("5"), - "coupling_provenance_sha256": _digest("6"), - "selector_domain_sha256": _digest("7"), - "finalizer_sha256": vector_finalizer, - "input_complex_count": 6, - "output_complex_count": 2, - "source_bytes": 4096, - "machine_code_bytes": 100, - "optimization_level": 3, - }, - { - "kernel_id": 1, - "kernel_family": (acceptance.THREE_VECTOR_SINGLETON_KERNEL_FAMILY), - "motif_sha256": _digest("9"), - "source_sha256": _digest("a"), - "descriptor_sha256": _digest("b"), - "source_abi": acceptance.DIRECT_APPLICATION_ABI, - "binding_abi": acceptance.DIRECT_TABLE_BINDING_ABI, - "descriptor_abi": acceptance.DIRECT_TABLE_DESCRIPTOR_ABI, - "canonical_input_order": [f"input-{index}" for index in range(16)], - "input_permutation": list(range(16)), - "result_signature": "three-vector:4", - "mutable_parameter_sha256": _digest("c"), - "coupling_provenance_sha256": _digest("d"), - "selector_domain_sha256": _digest("e"), - "finalizer_sha256": three_vector_finalizer, - "input_complex_count": 16, - "output_complex_count": 4, - "source_bytes": 8192, - "machine_code_bytes": 120, - "optimization_level": 3, - }, - ], - "islands": [ - { - "island_id": 0, - "kernel_id": 0, - "current_ids": vector_current_ids, - "selector_partition_sha256": _digest("9"), - "invocations": vector_invocations, - "attachments": vector_attachments, - "factor_catalog": [{"factor_id": 0, "factor_sha256": _digest("a")}], - "plane_bindings": bindings(), - "dependency_certificate": _certificate( - "complete-current-independence-v1", - [ - { - "current_id": current_id, - "predecessor_current_ids": [100 + current_id], - } - for current_id in vector_current_ids - ], - ), - "order_certificate": _certificate( - "evaluation-group-order-v1", - vector_order_rows, - ), - "semantic_row_bytes": 3136, - "arena_bytes": 1664, - }, - { - "island_id": 1, - "kernel_id": 1, - "current_ids": three_vector_current_ids, - "selector_partition_sha256": _digest("e"), - "invocations": three_vector_invocations, - "attachments": three_vector_attachments, - "factor_catalog": [{"factor_id": 0, "factor_sha256": _digest("f")}], - "plane_bindings": bindings(), - "dependency_certificate": _certificate( - "complete-current-independence-v1", - [ - { - "current_id": current_id, - "predecessor_current_ids": [200 + current_id], - } - for current_id in three_vector_current_ids - ], - ), - "order_certificate": _certificate( - "evaluation-group-order-v1", - [ - { - "current_id": current_id, - "evaluation_group_ids": [98 + index], - } - for index, current_id in enumerate(three_vector_current_ids) - ], - ), - "semantic_row_bytes": 160, - "arena_bytes": 320, - }, - ], - "finalizers": [ - { - "current_id": current_id, - "island_id": 0 if current_id in vector_current_ids else 1, - "identity_sha256": ( - vector_finalizer - if current_id in vector_current_ids - else three_vector_finalizer - ), - } - for current_id in vector_current_ids + three_vector_current_ids - ], - "diagnostics": _diagnostics( - islands=2, - kernels=2, - invocations=103, - attachments=103, - table_code=220, - residual_code=50, - semantic_bytes=3296, - arena_bytes=1984, - ), - } - - -def _active_prepared_kernel_occurrences() -> list[dict[str, object]]: - prepared_kernel_ids = ( - [7] * 49 + [24] * 49 + [4] * 5 + [4] * 30 + [36] * 40 + [41] * 30 - ) - assert len(prepared_kernel_ids) == acceptance.TARGET_MATERIALIZED_INTERACTIONS - return [ - { - "occurrence_id": f"stage-0:{index}", - "prepared_kernel_id": prepared_kernel_id, - } - for index, prepared_kernel_id in enumerate(prepared_kernel_ids) - ] - - -def _complex_values(batch: int, value: float = 1.0) -> list[list[float]]: - return [[value, 0.0] for _ in range(batch)] - - -def _resolved_values(batch: int, value: float = 1.0) -> list[list[list[float]]]: - return [[[value, 0.0]] for _ in range(batch)] - - -def _correctness(batch: int) -> dict[str, object]: - return { - lane: { - "evaluate": _complex_values(batch), - "resolved_total": _complex_values(batch), - "resolved_contributions": _resolved_values(batch), - } - for lane in ("baseline", "candidate") - } - - -def _measurements( - *, - candidate_ratio: float, - allocations: int = 0, -) -> list[dict[str, object]]: - rows: list[dict[str, object]] = [] - for pair_index in range(acceptance.MIN_SAMPLE_PAIRS): - order = ( - ("baseline", "candidate") - if pair_index % 2 == 0 - else ("candidate", "baseline") - ) - baseline = 1.0 + 0.001 * (pair_index % 3) - for lane in order: - rows.append( - { - "pair_index": pair_index, - "sequence_index": len(rows), - "lane": lane, - "duration_seconds": 5.25, - "seconds_per_point": ( - baseline if lane == "baseline" else baseline * candidate_ratio - ), - "warmed_allocation_count": ( - allocations if lane == "candidate" else 0 - ), - } - ) - return rows - - -def _artifact_metrics( - *, - generation_seconds: float, - artifact_bytes: int, - load_seconds: float, - peak_rss_bytes: int, - machine_code_bytes: int, - digest_character: str, - code_size_metric_available: bool = True, -) -> dict[str, object]: - return { - "artifact_sha256": _digest(digest_character), - "build_identity_sha256": _digest(digest_character), - "generation_seconds": generation_seconds, - "artifact_bytes": artifact_bytes, - "load_seconds": load_seconds, - "peak_rss_bytes": peak_rss_bytes, - "code_size_metric_available": code_size_metric_available, - "code_size_metric_kind": ( - acceptance.EXACT_CODE_SIZE_METRIC if code_size_metric_available else None - ), - "selected_machine_code_bytes": ( - machine_code_bytes if code_size_metric_available else None - ), - "portable_source_applications": [ - { - "source_application_sha256": _digest(digest_character), - "source_application_bytes": 4096, - "source_application_abi": acceptance.SOURCE_APPLICATION_ABI, - } - ], - } - - -def _campaign() -> dict[str, object]: - point_digest = _digest("b") - stage = _authorized_extended_stage_plan() - stage_diagnostics = copy.deepcopy(stage["diagnostics"]) - campaign: dict[str, object] = { - "kind": acceptance.CAMPAIGN_KIND, - "schema_version": acceptance.CAMPAIGN_SCHEMA_VERSION, - "dependency": { - "source": acceptance.DEPENDENCY_SOURCE, - "version": acceptance.DEPENDENCY_VERSION, - "local_patch_count": 0, - "direct_application_abi": acceptance.DIRECT_APPLICATION_ABI, - "direct_table_binding_abi": acceptance.DIRECT_TABLE_BINDING_ABI, - "direct_table_descriptor_abi": acceptance.DIRECT_TABLE_DESCRIPTOR_ABI, - }, - "workload": { - "process": acceptance.TARGET_PROCESS, - "color_accuracy": acceptance.TARGET_COLOR_ACCURACY, - "lc_flow_layout": acceptance.TARGET_LAYOUT, - "selected_flow": acceptance.TARGET_FLOW, - "helicity_mode": acceptance.TARGET_HELICITY_MODE, - "source_sha256": _digest("c"), - "model_sha256": _digest("d"), - "point_set_sha256": point_digest, - "runtime_target_sha256": _digest("e"), - "host_sha256": _digest("f"), - }, - "baseline": _artifact_metrics( - generation_seconds=100.0, - artifact_bytes=1000, - load_seconds=10.0, - peak_rss_bytes=10_000, - machine_code_bytes=1000, - digest_character="1", - ), - "candidate": { - "metrics": _artifact_metrics( - generation_seconds=105.0, - artifact_bytes=1050, - load_seconds=10.5, - peak_rss_bytes=10_500, - machine_code_bytes=700, - digest_character="2", - ), - "stage_plans": [stage], - "diagnostics": stage_diagnostics, - "census": { - "denominator_contract": acceptance.CENSUS_DENOMINATOR_CONTRACT, - "active_non_source_current_slots": ( - acceptance.TARGET_ACTIVE_NON_SOURCE_CURRENT_SLOTS - ), - "materialized_interaction_count": ( - acceptance.TARGET_MATERIALIZED_INTERACTIONS - ), - "two_component_current_slots": ( - acceptance.TARGET_TWO_COMPONENT_CURRENT_SLOTS - ), - "four_component_three_vector_singleton_slots": ( - acceptance.TARGET_THREE_VECTOR_SINGLETON_CURRENT_SLOTS - ), - "active_prepared_kernel_occurrences": ( - _active_prepared_kernel_occurrences() - ), - "eligible_prepared_kernel_occurrence_ids": [ - f"stage-0:{index}" - for index in range( - acceptance.TARGET_ELIGIBLE_PREPARED_KERNEL_OCCURRENCES - ) - ], - "proof_dag_non_source_current_slots": ( - acceptance.TARGET_PROOF_DAG_NON_SOURCE_CURRENT_SLOTS - ), - "proof_dag_interaction_count": ( - acceptance.TARGET_PROOF_DAG_INTERACTIONS - ), - "projected_generated_text_bytes": 12_000, - "projected_replaced_text_bytes": 100_000, - }, - }, - "batches": { - str(batch): { - "point_set_sha256": point_digest, - "correctness": _correctness(batch), - "measurements": _measurements( - candidate_ratio=( - 0.85 - if batch in acceptance.PRIMARY_BATCHES - else 1.04 - if batch == 1 - else 0.95 - ) - ), - } - for batch in acceptance.REQUIRED_BATCHES - }, - "regression_cases": [ - { - "name": name, - "passed": True, - "evidence_sha256": _digest("a"), - } - for name in sorted(acceptance.REQUIRED_REGRESSION_CASES) - ], - "non_target_performance": [ - { - "name": name, - "baseline_seconds_per_point": [1.0] * 7, - "candidate_seconds_per_point": [1.01] * 7, - } - for name in sorted(acceptance.REQUIRED_NON_TARGET_PERFORMANCE) - ], - } - return _seal(campaign) - - -def _seal(campaign: dict[str, object]) -> dict[str, object]: - campaign.pop("content_sha256", None) - campaign["content_sha256"] = acceptance.canonical_sha256(campaign) - return campaign - - -def _candidate(campaign: dict[str, object]) -> dict[str, object]: - value = campaign["candidate"] - assert isinstance(value, dict) - return value - - -def _batches(campaign: dict[str, object]) -> dict[str, object]: - value = campaign["batches"] - assert isinstance(value, dict) - return value - - -def test_valid_campaign_recomputes_every_landing_gate() -> None: - result = acceptance.audit_campaign(_campaign()) - - assert result["passes"] is True - assert set(result["batches"]) == { - str(batch) for batch in acceptance.REQUIRED_BATCHES - } - gates = result["gates"] - assert isinstance(gates, dict) - assert gates["primary_gain:batch_128"]["passes"] is True - assert gates["primary_gain:batch_1024"]["passes"] is True - assert gates["selected_machine_code_reduction"]["passes"] is True - assert gates["zero_warmed_allocations"]["passes"] is True - - -def test_residual_only_and_table_only_v2_stages_are_valid() -> None: - residual = acceptance.audit_stage_plan_v2(_residual_only_stage()) - table = acceptance.audit_stage_plan_v2(_table_only_stage()) - - assert residual["residual_only"] is True - assert residual["table_only"] is False - assert table["residual_only"] is False - assert table["table_only"] is True - - -@pytest.mark.parametrize( - "field,value", - [ - ("schema_version", 1), - ("direct_application_abi", "symjit-direct-application-storage-v0"), - ("direct_table_binding_abi", "symjit-direct-table-binding-v0"), - ("direct_table_descriptor_abi", "symjit-direct-table-descriptor-v0"), - ], -) -def test_v1_and_incompatible_abis_fail_closed(field: str, value: object) -> None: - stage = _stage_plan() - stage[field] = value - - with pytest.raises(acceptance.AcceptanceError, match="regenerate"): - acceptance.audit_stage_plan_v2(stage) - - -def test_unknown_fields_and_split_destinations_fail_closed() -> None: - stage = _stage_plan() - stage["silent_fallback"] = True - with pytest.raises(acceptance.AcceptanceError, match="field mismatch"): - acceptance.audit_stage_plan_v2(stage) - - stage = _stage_plan() - stage["residual_current_ids"] = [10, 11] - with pytest.raises(acceptance.AcceptanceError, match="may not be split"): - acceptance.audit_stage_plan_v2(stage) - - -def test_order_certificate_is_authenticated_and_matches_attachments() -> None: - stage = _stage_plan() - island = stage["islands"][0] # type: ignore[index] - assert isinstance(island, dict) - island["order_certificate"] = _certificate( - "evaluation-group-order-v1", - [{"current_id": 10, "evaluation_group_ids": [8, 7]}], - ) - - with pytest.raises(acceptance.AcceptanceError, match="attachment order differs"): - acceptance.audit_stage_plan_v2(stage) - - stage = _stage_plan() - island = stage["islands"][0] # type: ignore[index] - assert isinstance(island, dict) - certificate = island["order_certificate"] - assert isinstance(certificate, dict) - certificate["sha256"] = _digest("0") - with pytest.raises(acceptance.AcceptanceError, match="SHA-256 mismatch"): - acceptance.audit_stage_plan_v2(stage) - - -def test_noncontiguous_ranges_and_partial_destination_writes_fail_closed() -> None: - stage = _stage_plan() - island = stage["islands"][0] # type: ignore[index] - assert isinstance(island, dict) - invocation = island["invocations"][1] # type: ignore[index] - assert isinstance(invocation, dict) - invocation["attachment_start"] = 0 - with pytest.raises(acceptance.AcceptanceError, match="outside its invocation"): - acceptance.audit_stage_plan_v2(stage) - - stage = _stage_plan() - island = stage["islands"][0] # type: ignore[index] - assert isinstance(island, dict) - attachment = island["attachments"][0] # type: ignore[index] - assert isinstance(attachment, dict) - attachment["destination_complex_count"] = 1 - with pytest.raises(acceptance.AcceptanceError, match="complete"): - acceptance.audit_stage_plan_v2(stage) - - -def test_dependency_certificate_rejects_grouped_dependent_currents() -> None: - stage = _stage_plan() - stage["output_current_ids"] = [10, 11, 12] - stage["table_current_ids"] = [10, 12] - island = stage["islands"][0] # type: ignore[index] - assert isinstance(island, dict) - island["current_ids"] = [10, 12] - island["invocations"] = [ - { - "invocation_id": 0, - "evaluation_group_id": 7, - "attachment_start": 0, - "attachment_count": 2, - }, - { - "invocation_id": 1, - "evaluation_group_id": 8, - "attachment_start": 2, - "attachment_count": 2, - }, - ] - island["attachments"] = [ - { - "attachment_id": index, - "invocation_id": index // 2, - "current_id": 10 if index % 2 == 0 else 12, - "evaluation_group_id": 7 if index < 2 else 8, - "operation": "overwrite" if index < 2 else "accumulate", - "destination_complex_count": 2, - "factor_id": 0, - } - for index in range(4) - ] - island["dependency_certificate"] = _certificate( - "complete-current-independence-v1", - [ - {"current_id": 10, "predecessor_current_ids": [12]}, - {"current_id": 12, "predecessor_current_ids": []}, - ], - ) - island["order_certificate"] = _certificate( - "evaluation-group-order-v1", - [ - {"current_id": 10, "evaluation_group_ids": [7, 8]}, - {"current_id": 12, "evaluation_group_ids": [7, 8]}, - ], - ) - stage["finalizers"] = [ - { - "current_id": current_id, - "island_id": 0, - "identity_sha256": _digest("8"), - } - for current_id in (10, 12) - ] - diagnostics = stage["diagnostics"] - assert isinstance(diagnostics, dict) - diagnostics["attachment_count"] = 4 - - with pytest.raises(acceptance.AcceptanceError, match="dependent destinations"): - acceptance.audit_stage_plan_v2(stage) - - -def test_declared_diagnostics_and_hard_bounds_are_recomputed() -> None: - stage = _stage_plan() - diagnostics = stage["diagnostics"] - assert isinstance(diagnostics, dict) - diagnostics["attachment_count"] = 3 - with pytest.raises(acceptance.AcceptanceError, match="recomputed"): - acceptance.audit_stage_plan_v2(stage) - - stage = _stage_plan() - kernel = stage["kernels"][0] # type: ignore[index] - assert isinstance(kernel, dict) - kernel["source_bytes"] = acceptance.MAX_KERNEL_SOURCE_BYTES + 1 - with pytest.raises(acceptance.AcceptanceError, match="64 KiB"): - acceptance.audit_stage_plan_v2(stage) - - -def test_census_rejects_proof_dag_substitution_and_incomplete_occurrences() -> None: - campaign = _campaign() - census = _candidate(campaign)["census"] - assert isinstance(census, dict) - census["active_non_source_current_slots"] = ( - acceptance.TARGET_PROOF_DAG_NON_SOURCE_CURRENT_SLOTS - ) - _seal(campaign) - with pytest.raises(acceptance.AcceptanceError, match="frozen target census"): - acceptance.audit_campaign(campaign) - - campaign = _campaign() - census = _candidate(campaign)["census"] - assert isinstance(census, dict) - active = census["active_prepared_kernel_occurrences"] - assert isinstance(active, list) - active.pop() - _seal(campaign) - with pytest.raises(acceptance.AcceptanceError, match="enumerate all 203"): - acceptance.audit_campaign(campaign) - - campaign = _campaign() - census = _candidate(campaign)["census"] - assert isinstance(census, dict) - eligible = census["eligible_prepared_kernel_occurrence_ids"] - assert isinstance(eligible, list) - eligible.pop() - _seal(campaign) - with pytest.raises(acceptance.AcceptanceError, match="exactly match"): - acceptance.audit_campaign(campaign) - - -def test_authorized_kernel_families_enforce_family_specific_output_caps() -> None: - summary = acceptance.audit_stage_plan_v2(_authorized_extended_stage_plan()) - counts = summary["table_destination_family_counts"] - assert counts == { - acceptance.VECTOR_WEYL_KERNEL_FAMILY: 26, - acceptance.THREE_VECTOR_SINGLETON_KERNEL_FAMILY: 5, - } - - stage = _stage_plan() - kernel = stage["kernels"][0] # type: ignore[index] - assert isinstance(kernel, dict) - kernel["output_complex_count"] = 4 - kernel["result_signature"] = "three-vector:4" - with pytest.raises(acceptance.AcceptanceError, match="vector-weyl"): - acceptance.audit_stage_plan_v2(stage) - - stage = _authorized_extended_stage_plan() - kernel = stage["kernels"][1] # type: ignore[index] - assert isinstance(kernel, dict) - kernel["input_complex_count"] = 15 - kernel["canonical_input_order"] = [f"input-{index}" for index in range(15)] - kernel["input_permutation"] = list(range(15)) - with pytest.raises(acceptance.AcceptanceError, match="exactly 16 inputs"): - acceptance.audit_stage_plan_v2(stage) - - -def test_three_vector_family_rejects_non_singleton_currents() -> None: - stage = _authorized_extended_stage_plan() - island = stage["islands"][1] # type: ignore[index] - assert isinstance(island, dict) - attachments = island["attachments"] - invocations = island["invocations"] - assert isinstance(attachments, list) - assert isinstance(invocations, list) - invocations.append( - { - "invocation_id": 5, - "evaluation_group_id": 103, - "attachment_start": 5, - "attachment_count": 1, - } - ) - attachments.append( - { - "attachment_id": 5, - "invocation_id": 5, - "current_id": 26, - "evaluation_group_id": 103, - "operation": "accumulate", - "destination_complex_count": 4, - "factor_id": 0, - } - ) - island["order_certificate"] = _certificate( - "evaluation-group-order-v1", - [ - { - "current_id": current_id, - "evaluation_group_ids": ( - [98, 103] if current_id == 26 else [98 + index] - ), - } - for index, current_id in enumerate(range(26, 31)) - ], - ) - with pytest.raises(acceptance.AcceptanceError, match="singleton"): - acceptance.audit_stage_plan_v2(stage) - - -def test_odd_tail_batch_or_numerical_mismatch_is_not_accepted() -> None: - campaign = _campaign() - _batches(campaign).pop("129") - _seal(campaign) - with pytest.raises(acceptance.AcceptanceError, match="exactly batches"): - acceptance.audit_campaign(campaign) - - campaign = _campaign() - batch = _batches(campaign)["127"] - assert isinstance(batch, dict) - correctness = batch["correctness"] - assert isinstance(correctness, dict) - candidate = correctness["candidate"] - assert isinstance(candidate, dict) - for field in ("evaluate", "resolved_total", "resolved_contributions"): - values = candidate[field] - assert isinstance(values, list) - if field == "resolved_contributions": - values[0][0][0] += 1.0e-6 - else: - values[0][0] += 1.0e-6 - _seal(campaign) - with pytest.raises(acceptance.AcceptanceError, match="candidate_vs_baseline"): - acceptance.audit_campaign(campaign) - - -def test_resolved_contributions_must_sum_to_the_declared_total() -> None: - campaign = _campaign() - batch = _batches(campaign)["1"] - assert isinstance(batch, dict) - correctness = batch["correctness"] - assert isinstance(correctness, dict) - candidate = correctness["candidate"] - assert isinstance(candidate, dict) - resolved = candidate["resolved_contributions"] - assert isinstance(resolved, list) - resolved[0][0][0] += 1.0e-6 - _seal(campaign) - - with pytest.raises( - acceptance.AcceptanceError, - match="resolved_contributions_vs_total", - ): - acceptance.audit_campaign(campaign) - - -def test_alternating_samples_may_start_with_either_lane() -> None: - campaign = _campaign() - for batch in _batches(campaign).values(): - assert isinstance(batch, dict) - rows = batch["measurements"] - assert isinstance(rows, list) - for pair_index in range(acceptance.MIN_SAMPLE_PAIRS): - start = 2 * pair_index - rows[start], rows[start + 1] = rows[start + 1], rows[start] - rows[start]["sequence_index"] = start - rows[start + 1]["sequence_index"] = start + 1 - _seal(campaign) - - assert acceptance.audit_campaign(campaign)["passes"] is True - - -def _set_candidate_ratio( - campaign: dict[str, object], - batch: int, - ratio: float, -) -> None: - batch_value = _batches(campaign)[str(batch)] - assert isinstance(batch_value, dict) - rows = batch_value["measurements"] - assert isinstance(rows, list) - for row in rows: - assert isinstance(row, dict) - if row["lane"] == "candidate": - pair_index = int(row["pair_index"]) - row["seconds_per_point"] = (1.0 + 0.001 * (pair_index % 3)) * ratio - - -def _miss_primary_gain(campaign: dict[str, object]) -> str: - _set_candidate_ratio(campaign, 128, 0.95) - return "primary_gain:batch_128" - - -def _regress_batch_one(campaign: dict[str, object]) -> str: - _set_candidate_ratio(campaign, 1, 1.06) - return "batch_1_regression" - - -def _miss_code_size(campaign: dict[str, object]) -> str: - metrics = _candidate(campaign)["metrics"] - assert isinstance(metrics, dict) - metrics["selected_machine_code_bytes"] = 800 - return "selected_machine_code_reduction" - - -def _regress_generation(campaign: dict[str, object]) -> str: - metrics = _candidate(campaign)["metrics"] - assert isinstance(metrics, dict) - metrics["generation_seconds"] = 111.0 - return "resource:generation_seconds" - - -def _allocate_when_warmed(campaign: dict[str, object]) -> str: - candidate = _candidate(campaign) - diagnostics = candidate["diagnostics"] - assert isinstance(diagnostics, dict) - diagnostics["warmed_allocation_count"] = 1 - stage_plans = candidate["stage_plans"] - assert isinstance(stage_plans, list) - stage = stage_plans[0] - assert isinstance(stage, dict) - stage_diagnostics = stage["diagnostics"] - assert isinstance(stage_diagnostics, dict) - stage_diagnostics["warmed_allocation_count"] = 1 - for batch in _batches(campaign).values(): - assert isinstance(batch, dict) - rows = batch["measurements"] - assert isinstance(rows, list) - for row in rows: - assert isinstance(row, dict) - if row["lane"] == "candidate": - row["warmed_allocation_count"] = 1 - return "zero_warmed_allocations" - - -def _regress_eager(campaign: dict[str, object]) -> str: - rows = campaign["non_target_performance"] - assert isinstance(rows, list) - eager = next(row for row in rows if row["name"] == "eager") - eager["candidate_seconds_per_point"] = [1.03] * 7 - return "non_target_performance:eager" - - -@pytest.mark.parametrize( - "mutation", - [ - _miss_primary_gain, - _regress_batch_one, - _miss_code_size, - _regress_generation, - _allocate_when_warmed, - _regress_eager, - ], -) -def test_well_formed_threshold_misses_return_failed_gates( - mutation: Callable[[dict[str, object]], str], -) -> None: - campaign = _campaign() - expected_gate = mutation(campaign) - _seal(campaign) - - result = acceptance.audit_campaign(campaign) - - assert result["passes"] is False - gates = result["gates"] - assert isinstance(gates, dict) - assert gates[expected_gate]["passes"] is False - - -def test_unavailable_exact_code_size_fails_closed_without_using_source_bytes() -> None: - campaign = _campaign() - baseline = campaign["baseline"] - assert isinstance(baseline, dict) - baseline["code_size_metric_available"] = False - baseline["code_size_metric_kind"] = None - baseline["selected_machine_code_bytes"] = None - metrics = _candidate(campaign)["metrics"] - assert isinstance(metrics, dict) - metrics["code_size_metric_available"] = False - metrics["code_size_metric_kind"] = None - metrics["selected_machine_code_bytes"] = None - _seal(campaign) - - result = acceptance.audit_campaign(campaign) - - assert result["passes"] is False - gate = result["gates"]["selected_machine_code_reduction"] - assert gate["passes"] is False - assert gate["metric_available"] is False - diagnostics = result["code_size_diagnostics"] - assert diagnostics["portable_source_metric_is_machine_code"] is False - assert diagnostics["baseline_portable_source_application_bytes"] == 4096 - - -def test_code_size_metric_must_be_exact_executed_machine_code() -> None: - campaign = _campaign() - metrics = _candidate(campaign)["metrics"] - assert isinstance(metrics, dict) - metrics["code_size_metric_kind"] = "portable-source-application-bytes-v1" - _seal(campaign) - - with pytest.raises(acceptance.AcceptanceError, match="exact executed code"): - acceptance.audit_campaign(campaign) - - -def test_content_digest_duplicate_keys_and_cli_exit_status( - tmp_path: Path, - capsys: pytest.CaptureFixture[str], -) -> None: - campaign = _campaign() - campaign["content_sha256"] = _digest("0") - with pytest.raises(acceptance.AcceptanceError, match="computed"): - acceptance.audit_campaign(campaign) - - duplicate_path = tmp_path / "duplicate.json" - duplicate_path.write_text('{"kind": 1, "kind": 2}', encoding="utf-8") - with pytest.raises(acceptance.AcceptanceError, match="duplicate"): - acceptance.load_campaign(duplicate_path) - - valid_path = tmp_path / "valid.json" - valid_path.write_text(json.dumps(_campaign()), encoding="utf-8") - assert acceptance.main([str(valid_path)]) == 0 - captured = capsys.readouterr() - assert acceptance.RESULT_KIND in captured.out diff --git a/pyamplicol/tests/unit/test_conditioned_report_validation.py b/pyamplicol/tests/unit/test_conditioned_report_validation.py deleted file mode 100644 index 246d6bee8a..0000000000 --- a/pyamplicol/tests/unit/test_conditioned_report_validation.py +++ /dev/null @@ -1,438 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -from copy import deepcopy -from types import SimpleNamespace - -import pytest - -from tools.performance_report.agreements import ( - BUILTIN_UFO_RECURRENCE, - DIRECT_AGREEMENT_V2_ABI, - INDEPENDENT_AUTHORITY_ABI, - INDEPENDENT_AUTHORITY_FIELD, - independent_numerical_authorities, - validate_direct_agreement_records, -) -from tools.performance_report.cache import _validate_conditioned_measurement_bindings -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.final_audit import ( - _stored_independent_pointwise_matches_baseline, -) -from tools.performance_report.measurement import ( - conditioned_measurement_comparison, - reconcile_independent_authority, -) -from tools.performance_report.models import ( - Accuracy, - CellSpec, - ExecutionMode, - MeasurementSpec, - ModelKey, - ResultStatus, - Workload, -) -from tools.performance_report.runner import ( - SelectorContract, - pointwise_validation, - resolved_sum_validation, - validate_conditioned_comparison_record, - validate_resolved_sum_validation_record, -) - - -def _source_binding( - *, - point_identity: str = "a" * 64, - selector_identity: dict[str, object] | None = None, -) -> dict[str, object]: - identity = selector_identity or {"cell_id": "candidate", "value_kind": "total"} - digest = hashlib.sha256( - json.dumps( - identity, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - return { - "point_digest": point_identity, - "selector_component_identity": identity, - "selector_component_sha256": digest, - "candidate_source_sha256": "b" * 64, - "baseline_source_sha256": "c" * 64, - } - - -def _cell() -> CellSpec: - return CellSpec( - dataset_id="test", - process_key="test", - process="d d~ > z", - n_final=1, - workload=Workload.CONTRACTED, - measurement=MeasurementSpec( - execution_mode=ExecutionMode.RECURRENCE, - backend="jit", - model=ModelKey.BUILTIN_SM, - accuracy=Accuracy.FULL, - jit_optimization_level=2, - ), - ) - - -def test_conditioned_comparison_has_no_tiny_absolute_escape() -> None: - failed = pointwise_validation( - 1.0e-16, - 0.0, - comparison_binding=_source_binding(), - ) - assert failed["status"] == "validation_failed" - assert failed["comparison_scale"] == 1.0e-16 - assert failed["conditioned_residual"] == 1.0 - - cancelled = pointwise_validation( - 1.0e-16, - 0.0, - candidate_scale=1.0e-3, - baseline_scale=1.0e-3, - comparison_binding=_source_binding(), - ) - assert cancelled["status"] == "ok" - validate_conditioned_comparison_record(cancelled, require_binding=True) - - -def test_conditioned_zero_scale_and_scale_validation_are_fail_closed() -> None: - exact = pointwise_validation( - 0.0, - 0.0, - comparison_binding=_source_binding(), - ) - assert exact["comparison_scale"] == 0.0 - assert exact["conditioned_residual"] == 0.0 - assert exact["error_bound"] == 0.0 - - with pytest.raises(ValueError, match="smaller"): - pointwise_validation(2.0, 2.0, candidate_scale=1.0) - with pytest.raises(ValueError, match="finite"): - pointwise_validation(1.0, 1.0, baseline_scale=float("inf")) - - -def test_legacy_comparison_reuse_rejects_floor_only_acceptance() -> None: - floor_only = { - "status": "ok", - "candidate": 1.0e-16, - "baseline": 0.0, - "absolute_difference": 1.0e-16, - "relative_difference": 1.0e-16 / 1.0e-300, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - } - with pytest.raises(ValueError, match="safely reusable"): - validate_conditioned_comparison_record(floor_only, require_binding=False) - - safely_relative = { - "status": "ok", - "candidate": 1.0 + 1.0e-13, - "baseline": 1.0, - "absolute_difference": abs((1.0 + 1.0e-13) - 1.0), - "relative_difference": abs((1.0 + 1.0e-13) - 1.0), - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - } - validate_conditioned_comparison_record(safely_relative, require_binding=False) - - unbound_resolved = { - "status": "ok", - "maximum_absolute_difference": 1.0e-16, - "maximum_relative_difference": 1.0, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - } - with pytest.raises(ValueError, match="floor-only or unbound"): - validate_resolved_sum_validation_record(unbound_resolved) - - -def test_resolved_l1_scale_is_bound_and_tampering_is_rejected() -> None: - class Runtime: - def evaluate(self, _points, **_kwargs): - return (1.0e-16,) - - def evaluate_resolved(self, _points, **_kwargs): - return SimpleNamespace( - values=(((1.0, -1.0 + 1.0e-16),),), - helicity_ids=("h0",), - color_ids=("c0", "c1"), - total=lambda: (1.0e-16,), - ) - - record = resolved_sum_validation( - Runtime(), - (((1.0, 0.0, 0.0, 1.0),),), - cell=_cell(), - selector_contract=None, - ) - assert record["status"] == "ok" - point = record["points"][0] - assert point["candidate_scale"] >= 1.0 - assert point["baseline_scale"] >= 1.0 - validate_resolved_sum_validation_record(record) - - point["comparison_binding"]["point_index"] = 1 - with pytest.raises(ValueError, match="binding differs"): - validate_resolved_sum_validation_record(record) - - -def test_direct_agreement_v2_authenticates_conditioned_fields() -> None: - comparison = pointwise_validation( - 1.0, - 1.0, - comparison_binding=_source_binding(), - ) - comparison.pop("abi") - record = { - "abi": DIRECT_AGREEMENT_V2_ABI, - "edge_kind": BUILTIN_UFO_RECURRENCE, - "value_kind": "matrix_element", - "baseline_cell_id": "baseline", - "candidate_cell_id": "candidate", - **comparison, - } - validate_direct_agreement_records([record], expected_candidate_id="candidate") - - record["candidate_scale"] = 0.5 - with pytest.raises(ValueError, match="numerical record"): - validate_direct_agreement_records([record], expected_candidate_id="candidate") - - legacy_floor = { - "abi": "pyamplicol-report-direct-agreement-v1", - "edge_kind": BUILTIN_UFO_RECURRENCE, - "value_kind": "matrix_element", - "baseline_cell_id": "baseline", - "candidate_cell_id": "candidate", - "status": "ok", - "candidate": 1.0e-16, - "baseline": 0.0, - "absolute_difference": 1.0e-16, - "relative_difference": 1.0e-16 / 1.0e-300, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - } - with pytest.raises(ValueError, match="numerical record"): - validate_direct_agreement_records([legacy_floor]) - - -def test_completed_unverified_candidate_can_be_compared_to_late_authority() -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted" - ) - candidate_value = 1.0 + 1.0e-13 - resolved_point = pointwise_validation( - candidate_value, - candidate_value, - candidate_scale=candidate_value, - baseline_scale=candidate_value, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": "a" * 64, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "c" * 64, - "resolved_source_sha256": "b" * 64, - "point_index": 0, - }, - ) - resolved = { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": "ok", - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": "a" * 64, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "c" * 64, - "resolved_source_sha256": "b" * 64, - "scale_source": "resolved-component-l1", - "precision_digits": 16, - "points": [resolved_point], - } - candidate = { - "status": "unverified", - "matrix_element": candidate_value, - "selector_contract": None, - "validation": {"resolved_sum": resolved}, - "provenance": {"report_momenta": [[[1.0, 0.0, 0.0, 1.0]]]}, - } - authority = { - "status": "ok", - "matrix_element": 1.0, - "selector_contract": None, - "validation": {"point_digest": "a" * 64}, - "provenance": {"report_momenta": [[[1.0, 0.0, 0.0, 1.0]]]}, - } - comparison = conditioned_measurement_comparison(cell, candidate, authority) - assert comparison["status"] == "ok" - assert comparison["candidate_scale_source"] == "resolved-component-l1" - validate_conditioned_comparison_record(comparison, require_binding=True) - candidate["validation"]["pointwise"] = comparison # type: ignore[index] - authority_cell = independent_numerical_authorities(cell)[0] - assert _stored_independent_pointwise_matches_baseline( - cell, - candidate, - authority_cell, - authority, - ) - comparison["comparison_binding"]["baseline_source_sha256"] = "f" * 64 - assert not _stored_independent_pointwise_matches_baseline( - cell, - candidate, - authority_cell, - authority, - ) - candidate["validation"]["resolved_sum"]["point_digest"] = comparison[ # type: ignore[index] - "comparison_binding" - ]["point_digest"] - candidate["validation"]["pointwise"] = comparison # type: ignore[index] - _validate_conditioned_measurement_bindings( - candidate["validation"], # type: ignore[arg-type] - expected_cell=cell, - selector_contract=None, - ) - comparison["comparison_binding"]["candidate_source_sha256"] = "d" * 64 # type: ignore[index] - with pytest.raises(ValueError, match="candidate scale source"): - _validate_conditioned_measurement_bindings( - candidate["validation"], # type: ignore[arg-type] - expected_cell=cell, - selector_contract=None, - ) - - candidate["matrix_element"] = 0.5 - with pytest.raises(RuntimeError, match="differs from resolved-sum"): - conditioned_measurement_comparison(cell, candidate, authority) - - -@pytest.mark.parametrize("authority_value", (1.0, 2.0)) -def test_late_authority_reconciliation_promotes_or_fails( - authority_value: float, -) -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted" - ) - candidate = deepcopy( - # Reuse the authenticated resolved-scale fixture built by the adjacent - # test without relying on any campaign artifact. - { - "status": ResultStatus.UNVERIFIED.value, - "matrix_element": 1.0, - "selector_contract": None, - "validation": { - "point_digest": "a" * 64, - INDEPENDENT_AUTHORITY_FIELD: { - "abi": INDEPENDENT_AUTHORITY_ABI, - "expected_cell_ids": [ - item.cell_id - for item in independent_numerical_authorities(cell) - ], - "selected_cell_id": None, - "status": "unavailable", - "reason": "no-successful-independent-authority", - "same_artifact_diagnostics_are_authority": False, - }, - }, - "failure": { - "kind": "IndependentAuthorityUnavailable", - "message": "no authority", - }, - } - ) - authority = { - "status": ResultStatus.OK.value, - "matrix_element": authority_value, - "selector_contract": None, - "validation": {"point_digest": "a" * 64}, - "provenance": {}, - } - authority_id = independent_numerical_authorities(cell)[0].cell_id - - reconciled = reconcile_independent_authority( - cell, - candidate, - authority, - authority_cell_id=authority_id, - ) - - expected = ( - ResultStatus.OK.value - if authority_value == 1.0 - else ResultStatus.VALIDATION_FAILED.value - ) - assert reconciled["status"] == expected - record = reconciled["validation"][INDEPENDENT_AUTHORITY_FIELD] - assert record["selected_cell_id"] == authority_id - assert record["status"] == ( - "verified" if authority_value == 1.0 else "mismatch" - ) - - -def test_late_lc_all_flow_authority_compares_only_common_component() -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-lc-n4-dd-tt-jets-all-flow" - ) - contract = SelectorContract( - selected_color_flow_ids=("flow:1,2,3",), - selected_color_words=((1, 2, 3),), - all_flow_helicity_ids=("h:-1,+1,-1",), - all_flow_source_helicities=((1, -1), (2, 1), (3, -1)), - point_digest="a" * 64, - ).as_dict() - - def component(cell_id: str, value: float) -> dict[str, object]: - return { - "abi": "pyamplicol-report-lc-common-component-v1", - "cell_id": cell_id, - "value": value, - "point_digest": contract["point_digest"], - "helicity_ids": contract["all_flow_helicity_ids"], - "color_flow_ids": contract["selected_color_flow_ids"], - } - - candidate = { - "status": "unverified", - "matrix_element": 99.0, - "selector_contract": contract, - "validation": { - "lc_common_component": component(cell.cell_id, 2.0), - }, - } - authority_id = "reference-amplicol-lc-n4-dd-tt-jets-all-flow" - authority = { - "status": "ok", - "matrix_element": 1.0, - "selector_contract": contract, - "validation": { - "legacy_numerical_authority": { - "abi": "pyamplicol-report-legacy-numerical-authority-v1", - "source": "all-flow-selected-provider-replay", - }, - "lc_common_component": component(authority_id, 2.0), - }, - } - comparison = conditioned_measurement_comparison(cell, candidate, authority) - assert comparison["status"] == "ok" - assert comparison["candidate"] == 2.0 - assert comparison["baseline"] == 2.0 - assert ( - comparison["comparison_binding"]["selector_component_identity"][ # type: ignore[index] - "value_kind" - ] - == "lc_common_component" - ) - - authority["validation"]["lc_common_component"]["value"] = 3.0 # type: ignore[index] - mismatch = conditioned_measurement_comparison(cell, candidate, authority) - assert mismatch["status"] == "validation_failed" diff --git a/pyamplicol/tests/unit/test_deployment_harness.py b/pyamplicol/tests/unit/test_deployment_harness.py index 4384787ded..1aab25c801 100644 --- a/pyamplicol/tests/unit/test_deployment_harness.py +++ b/pyamplicol/tests/unit/test_deployment_harness.py @@ -29,50 +29,6 @@ def test_installed_smoke_uses_the_v1_builtin_model_name() -> None: assert 'build_info["source_revision"]' in deployment._INSTALLED_SMOKE -def test_installed_smoke_copies_and_dry_runs_the_profiling_campaign() -> None: - smoke = deployment._INSTALLED_SMOKE - assert 'campaign = Path(raw).resolve() / "campaign"' in smoke - assert 'campaign = Path(raw) / "campaign"' not in smoke - assert '"profiling-campaign"' in smoke - assert 'campaign / "steer_performance_campaign.py"' in smoke - assert 'campaign / "pyAmpliCol.pdf"' in smoke - assert '"scalar_contact"' in smoke - assert '"--generation-engine"' in smoke - assert '"compiled"' in smoke - assert '"compact retention (default)"' in smoke - assert '"--retain-workspaces"' in smoke - assert '"full debug workspaces (--retain-workspaces)"' in smoke - - -def test_installed_smoke_finishes_cli_children_before_native_imports() -> None: - tree = ast.parse(deployment._INSTALLED_SMOKE) - native_imports = [ - node.lineno - for node in ast.walk(tree) - if ( - isinstance(node, ast.Import) - and any( - name.name.split(".")[0] in {"pyamplicol", "symbolica"} - for name in node.names - ) - ) - or ( - isinstance(node, ast.ImportFrom) - and (node.module or "").split(".")[0] in {"pyamplicol", "symbolica"} - ) - ] - child_calls = [ - node.lineno - for node in ast.walk(tree) - if isinstance(node, ast.Call) - and isinstance(node.func, ast.Attribute) - and isinstance(node.func.value, ast.Name) - and node.func.value.id == "subprocess" - ] - assert native_imports and child_calls - assert max(child_calls) < min(native_imports) - - def test_f64_deployment_smoke_hard_blocks_symbolica() -> None: smoke = deployment._SYMBOLICA_FREE_F64_SMOKE assert 'os.environ.pop("SYMBOLICA_LICENSE", None)' in smoke diff --git a/pyamplicol/tests/unit/test_exact_python_bootstrap.py b/pyamplicol/tests/unit/test_exact_python_bootstrap.py deleted file mode 100644 index 0a15e51e23..0000000000 --- a/pyamplicol/tests/unit/test_exact_python_bootstrap.py +++ /dev/null @@ -1,763 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import os -import runpy -import shutil -import subprocess -import sys -import sysconfig -from importlib.machinery import EXTENSION_SUFFIXES -from pathlib import Path - -import pytest - -REPORT_ENTRYPOINT = Path("src/pyamplicol/_profiling_campaign/result_tables.py") - - -def test_report_worker_bootstrap_recovers_repository_venv_under_no_site( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - script = Path(__file__).resolve().parents[2] / REPORT_ENTRYPOINT - repository = tmp_path / "repository" - venv = repository / ".venv" - executable = venv / "bin/python" - executable.parent.mkdir(parents=True) - # execve is intercepted below; only the measured venv's layout is needed. - executable.touch() - (venv / "pyvenv.cfg").write_text( - "include-system-site-packages = false\n", encoding="ascii" - ) - variables = dict(sysconfig.get_config_vars()) - for name in ("base", "platbase", "installed_base", "installed_platbase"): - variables[name] = str(venv) - for name in ("purelib", "platlib"): - (Path(sysconfig.get_path(name, vars=variables)) / "symbolica").mkdir( - parents=True, exist_ok=True - ) - monkeypatch.setattr(sys, "executable", str(executable)) - namespace = runpy.run_path( - str(script), - run_name="result_tables_worker_bootstrap_test", - ) - bootstrap = namespace["_bootstrap_exact_python"] - globals_ = bootstrap.__globals__ - globals_["COMMAND"] = "_prepare" - globals_["MEASUREMENT_SOURCE_ROOT"] = None - globals_["REPOSITORY_ROOT"] = repository - globals_["ENTRYPOINT"] = script - for name in ( - "PYAMPLICOL_EXACT_PYTHON_REEXEC", - "PYAMPLICOL_EXACT_IMPORT_PATHS", - "PYTHONPYCACHEPREFIX", - "PYTHONDONTWRITEBYTECODE", - ): - monkeypatch.delenv(name, raising=False) - - observed: dict[str, object] = {} - - def capture_execve( - executable: str, - arguments: tuple[str, ...], - environment: dict[str, str], - ) -> None: - observed.update( - { - "executable": executable, - "arguments": arguments, - "environment": environment, - } - ) - raise RuntimeError("captured exact worker re-exec") - - monkeypatch.setattr(os, "execve", capture_execve) - with pytest.raises(RuntimeError, match="captured exact worker re-exec"): - bootstrap(["_prepare"]) - - environment = observed["environment"] - assert isinstance(environment, dict) - import_paths = json.loads(environment["PYAMPLICOL_EXACT_IMPORT_PATHS"]) - assert import_paths - assert all(Path(path).is_relative_to(repository / ".venv") for path in import_paths) - assert any((Path(path) / "symbolica").is_dir() for path in import_paths) - assert observed["arguments"][:4] == ( - sys.executable, - "-I", - "-S", - "-B", - ) - - -@pytest.mark.parametrize( - "script_relative", - ( - REPORT_ENTRYPOINT, - Path("tools/developer/compiled_all_jit_arena_gate.py"), - Path("tools/developer/four_quark_compiled_gate.py"), - ), -) -def test_direct_entrypoint_imports_repo_code_only_after_isolated_reexec( - tmp_path: Path, - script_relative: Path, -) -> None: - repository = Path(__file__).resolve().parents[2] - script = tmp_path / script_relative - script.parent.mkdir(parents=True) - shutil.copy2(repository / script_relative, script) - - package = tmp_path / "tools" / "performance_report" - package.mkdir(parents=True, exist_ok=True) - if script_relative == REPORT_ENTRYPOINT: - (tmp_path / "src/pyamplicol").mkdir(parents=True, exist_ok=True) - sentinel = tmp_path / "repo-imports.txt" - (package / "runtime_evidence.py").write_text( - "\n".join( - ( - "import os", - "import sys", - "from pathlib import Path", - "sentinel = Path(os.environ['PYAMPLICOL_BOOTSTRAP_SENTINEL'])", - "prefix = Path(sys.pycache_prefix or '.')", - "with sentinel.open('a', encoding='ascii') as stream:", - " stream.write(", - " f'{sys.flags.isolated},{sys.flags.no_site},'", - " f'{sys.flags.ignore_environment},'", - " f'{sys.flags.dont_write_bytecode},'", - " f'{int(prefix.exists())}\\n'", - " )", - "class RuntimeEvidenceError(RuntimeError):", - " pass", - "def source_only_bytecode_policy():", - " raise RuntimeEvidenceError('stop after authenticated import')", - "def established_preimport_runtime_identity():", - " return {}", - "def loaded_pyamplicol_origin_policy(*args, **kwargs):", - " return {}", - "def native_extension_in_package(*args, **kwargs):", - " return Path('/missing-native')", - "def preimport_python_runtime_identity(*args, **kwargs):", - " return {}", - "def python_package_tree_identity(*args, **kwargs):", - " return {}", - "", - ) - ), - encoding="ascii", - ) - - environment = os.environ.copy() - environment["PYAMPLICOL_BOOTSTRAP_SENTINEL"] = str(sentinel) - for name in ( - "PYAMPLICOL_EXACT_PYTHON_REEXEC", - "PYAMPLICOL_EXACT_IMPORT_PATHS", - "PYTHONPYCACHEPREFIX", - "PYTHONDONTWRITEBYTECODE", - ): - environment.pop(name, None) - completed = subprocess.run( - (sys.executable, str(script), "--help"), - cwd=tmp_path, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=30, - ) - - assert completed.returncode != 0 - assert sentinel.read_text(encoding="ascii").splitlines() == ["1,1,1,1,0"] - - -def test_result_tables_preauthenticates_staged_source_native( - tmp_path: Path, -) -> None: - repository = Path(__file__).resolve().parents[2] - script = tmp_path / REPORT_ENTRYPOINT - script.parent.mkdir(parents=True) - shutil.copy2(repository / REPORT_ENTRYPOINT, script) - - source_package = tmp_path / "src/pyamplicol" - source_package.mkdir(parents=True, exist_ok=True) - native_name = f"_rusticol{EXTENSION_SUFFIXES[0]}" - (source_package / native_name).write_bytes(b"source native") - installed_site = tmp_path / "installed" - installed_package = installed_site / "pyamplicol" - installed_package.mkdir(parents=True) - (installed_package / native_name).write_bytes(b"installed native") - - package = tmp_path / "tools/performance_report" - package.mkdir(parents=True) - sentinel = tmp_path / "preimport.json" - (package / "runtime_evidence.py").write_text( - "\n".join( - ( - "import json", - "import os", - "from pathlib import Path", - "class RuntimeEvidenceError(RuntimeError):", - " pass", - "def source_only_bytecode_policy():", - " return {}", - "def native_extension_in_package(package):", - f" return Path(package) / {native_name!r}", - "def preimport_python_runtime_identity(roots, *, native_extension):", - " payload = {", - " 'roots': [str(Path(root)) for root in roots],", - " 'native_extension': str(Path(native_extension)),", - " }", - " Path(os.environ['PYAMPLICOL_PREIMPORT_SENTINEL']).write_text(", - " json.dumps(payload), encoding='ascii'", - " )", - " raise RuntimeError('stop after preimport capture')", - "", - ) - ), - encoding="ascii", - ) - - environment = os.environ.copy() - environment["PYTHONPATH"] = str(installed_site) - environment["PYAMPLICOL_PREIMPORT_SENTINEL"] = str(sentinel) - for name in ( - "PYAMPLICOL_EXACT_PYTHON_REEXEC", - "PYAMPLICOL_EXACT_IMPORT_PATHS", - "PYTHONPYCACHEPREFIX", - "PYTHONDONTWRITEBYTECODE", - ): - environment.pop(name, None) - completed = subprocess.run( - (sys.executable, str(script), "--help"), - cwd=tmp_path, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=30, - ) - - assert completed.returncode != 0 - assert json.loads(sentinel.read_text(encoding="ascii")) == { - "roots": [str(source_package)], - "native_extension": str(source_package / native_name), - } - - -def test_class_c_prepare_uses_ancestor_package_with_descendant_tools( - tmp_path: Path, -) -> None: - repository = Path(__file__).resolve().parents[2] - script_relative = REPORT_ENTRYPOINT - script = tmp_path / script_relative - script.parent.mkdir(parents=True) - shutil.copy2(repository / script_relative, script) - - descendant_package = tmp_path / "src/pyamplicol" - descendant_package.mkdir(parents=True, exist_ok=True) - (descendant_package / "__init__.py").write_text( - "raise RuntimeError('descendant package was imported')\n", - encoding="ascii", - ) - ancestor = tmp_path / "ancestor-runtime" - ancestor_package = ancestor / "src/pyamplicol" - ancestor_package.mkdir(parents=True) - package_sentinel = tmp_path / "ancestor-package.txt" - (ancestor_package / "__init__.py").write_text( - "\n".join( - ( - "import os", - "from pathlib import Path", - "Path(os.environ['PYAMPLICOL_ANCESTOR_PACKAGE_SENTINEL']).write_text(", - " __file__, encoding='ascii'", - ")", - "", - ) - ), - encoding="ascii", - ) - native_name = f"_rusticol{EXTENSION_SUFFIXES[0]}" - (ancestor_package / native_name).write_bytes(b"ancestor native") - - tools_package = tmp_path / "tools/performance_report" - tools_package.mkdir(parents=True) - (tools_package / "__init__.py").write_text("", encoding="ascii") - preimport_sentinel = tmp_path / "preimport.json" - (tools_package / "runtime_evidence.py").write_text( - "\n".join( - ( - "import json", - "import os", - "from pathlib import Path", - "class RuntimeEvidenceError(RuntimeError):", - " pass", - "def source_only_bytecode_policy():", - " return {}", - "def native_extension_in_package(package):", - f" return Path(package) / {native_name!r}", - "def preimport_python_runtime_identity(roots, *, native_extension):", - " payload = {", - " 'roots': [str(Path(root)) for root in roots],", - " 'native_extension': str(Path(native_extension)),", - " }", - " Path(os.environ['PYAMPLICOL_PREIMPORT_SENTINEL']).write_text(", - " json.dumps(payload), encoding='ascii'", - " )", - " return payload", - "", - ) - ), - encoding="ascii", - ) - cli_sentinel = tmp_path / "descendant-cli.json" - (tools_package / "cli.py").write_text( - "\n".join( - ( - "import json", - "import os", - "from pathlib import Path", - "def main(arguments):", - " sentinel = os.environ['PYAMPLICOL_DESCENDANT_CLI_SENTINEL']", - " Path(sentinel).write_text(", - " json.dumps({'arguments': arguments, 'origin': __file__}),", - " encoding='ascii',", - " )", - " return 0", - "", - ) - ), - encoding="ascii", - ) - - environment = os.environ.copy() - environment.update( - { - "PYAMPLICOL_ANCESTOR_PACKAGE_SENTINEL": str(package_sentinel), - "PYAMPLICOL_DESCENDANT_CLI_SENTINEL": str(cli_sentinel), - "PYAMPLICOL_PREIMPORT_SENTINEL": str(preimport_sentinel), - } - ) - for name in ( - "PYAMPLICOL_EXACT_PYTHON_REEXEC", - "PYAMPLICOL_EXACT_IMPORT_PATHS", - "PYTHONPYCACHEPREFIX", - "PYTHONDONTWRITEBYTECODE", - ): - environment.pop(name, None) - completed = subprocess.run( - ( - sys.executable, - str(script), - "--class-c-ancestor-runtime-root", - str(ancestor), - "prepare-class-c-bridge", - "--ancestor-revision", - "a" * 40, - "--descendant-revision", - "d" * 40, - "--impact", - "hzz-orientation-v1", - ), - cwd=tmp_path, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=30, - ) - - assert completed.returncode == 0, completed.stderr - assert Path(package_sentinel.read_text(encoding="ascii")).parent == ancestor_package - assert json.loads(preimport_sentinel.read_text(encoding="ascii")) == { - "roots": [str(ancestor_package)], - "native_extension": str(ancestor_package / native_name), - } - cli = json.loads(cli_sentinel.read_text(encoding="ascii")) - assert Path(cli["origin"]).parent == tools_package - assert "--class-c-ancestor-runtime-root" in cli["arguments"] - - -def test_class_c_ancestor_runtime_option_is_prepare_only(tmp_path: Path) -> None: - repository = Path(__file__).resolve().parents[2] - script = tmp_path / REPORT_ENTRYPOINT - script.parent.mkdir(parents=True) - shutil.copy2(repository / REPORT_ENTRYPOINT, script) - (tmp_path / "tools/performance_report").mkdir(parents=True) - (tmp_path / "src/pyamplicol").mkdir(parents=True, exist_ok=True) - ancestor = tmp_path / "ancestor-runtime" - (ancestor / "src/pyamplicol").mkdir(parents=True) - - completed = subprocess.run( - ( - sys.executable, - str(script), - "--class-c-ancestor-runtime-root", - str(ancestor), - "audit", - ), - cwd=tmp_path, - check=False, - capture_output=True, - text=True, - timeout=30, - ) - - assert completed.returncode != 0 - assert "restricted to prepare-class-c-bridge" in completed.stderr - - -def test_split_worker_uses_wrapper_tools_and_measured_source_venv( - tmp_path: Path, -) -> None: - repository = Path(__file__).resolve().parents[2] - wrapper = tmp_path / "wrapper" - measured = tmp_path / "measured" - output = tmp_path / "output" - output.mkdir() - - def initialize_git(root: Path) -> None: - subprocess.run(("git", "init", "-q"), cwd=root, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=root, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=root, - check=True, - ) - - wrapper_entrypoint = wrapper / REPORT_ENTRYPOINT - wrapper_entrypoint.parent.mkdir(parents=True) - shutil.copy2( - repository / REPORT_ENTRYPOINT, - wrapper_entrypoint, - ) - wrapper_source = wrapper / "src/pyamplicol" - wrapper_source.mkdir(parents=True, exist_ok=True) - (wrapper_source / "__init__.py").write_text( - "raise RuntimeError('wrapper pyamplicol escaped split routing')\n", - encoding="ascii", - ) - wrapper_tools = wrapper / "tools/performance_report" - wrapper_tools.mkdir(parents=True) - (wrapper / "tools/__init__.py").write_text("", encoding="ascii") - (wrapper_tools / "__init__.py").write_text( - "ORIGIN = 'wrapper-tools'\n", - encoding="ascii", - ) - native_name = f"_rusticol{EXTENSION_SUFFIXES[0]}" - preimport_sentinel = output / "preimport.json" - (wrapper_tools / "runtime_evidence.py").write_text( - "\n".join( - ( - "import json", - "import os", - "from pathlib import Path", - "class RuntimeEvidenceError(RuntimeError):", - " pass", - "def source_only_bytecode_policy():", - " return {}", - "def native_extension_in_package(package):", - f" return Path(package) / {native_name!r}", - "def preimport_python_runtime_identity(roots, *, native_extension):", - " payload = {", - " 'roots': [str(Path(root)) for root in roots],", - " 'native_extension': str(Path(native_extension)),", - " }", - " Path(os.environ['SPLIT_PREIMPORT_SENTINEL']).write_text(", - " json.dumps(payload), encoding='ascii'", - " )", - " return payload", - "", - ) - ), - encoding="ascii", - ) - wrapper_legacy = wrapper_tools / "legacy.py" - wrapper_legacy.write_text( - "ORIGIN = 'wrapper-legacy-bootstrap-exclusion'\n", - encoding="ascii", - ) - (wrapper_tools / "cli.py").write_text( - "\n".join( - ( - "import json", - "import os", - "import sys", - "from pathlib import Path", - "import pyamplicol", - "import tools.performance_report as report_package", - "from tools.performance_report import legacy", - "def main(arguments):", - " command = next(", - " value for value in arguments", - " if value in {'_prepare', '_worker'}", - " )", - " result_path = Path(", - " arguments[arguments.index('--result-json') + 1]", - " )", - " if command == '_prepare':", - " prepared = result_path.parent / 'prepared-model'", - " prepared.mkdir(exist_ok=True)", - " result_path.write_text(", - " json.dumps({'path': str(prepared), 'reused': False}),", - " encoding='ascii',", - " )", - " else:", - " result_path.write_text(", - " json.dumps({'status': 'ok'}), encoding='ascii'", - " )", - " payload = {", - " 'arguments': arguments,", - " 'cli_origin': __file__,", - " 'tools_origin': report_package.__file__,", - " 'legacy_origin': legacy.__file__,", - " 'legacy_marker': legacy.ORIGIN,", - " 'pyamplicol_origin': pyamplicol.__file__,", - " 'pyamplicol_path': list(pyamplicol.__path__),", - " 'sys_path': list(sys.path),", - " }", - " sentinel = Path(os.environ['SPLIT_CLI_SENTINEL_ROOT'])", - " (sentinel / f'{command}.json').write_text(", - " json.dumps(payload), encoding='ascii'", - " )", - " return 0", - "", - ) - ), - encoding="ascii", - ) - initialize_git(wrapper) - subprocess.run(("git", "add", "."), cwd=wrapper, check=True) - subprocess.run( - ("git", "commit", "-qm", "authenticated wrapper"), - cwd=wrapper, - check=True, - ) - - measured_package = measured / "src/pyamplicol" - measured_package.mkdir(parents=True) - (measured / ".gitignore").write_text(".venv/\n", encoding="ascii") - (measured_package / "__init__.py").write_text( - "ORIGIN = 'measured-pyamplicol'\n", - encoding="ascii", - ) - native_payload = b"authenticated measured native fixture" - (measured_package / native_name).write_bytes(native_payload) - measured_decoy = measured / "src/tools/performance_report" - measured_decoy.mkdir(parents=True) - (measured / "src/tools/__init__.py").write_text("", encoding="ascii") - (measured_decoy / "__init__.py").write_text( - "raise RuntimeError('measured tools escaped wrapper routing')\n", - encoding="ascii", - ) - (measured_decoy / "legacy.py").write_text( - "ORIGIN = 'measured-legacy-without-bootstrap-fix'\n", - encoding="ascii", - ) - initialize_git(measured) - subprocess.run(("git", "add", "."), cwd=measured, check=True) - subprocess.run( - ("git", "commit", "-qm", "measured source"), - cwd=measured, - check=True, - ) - subprocess.run( - (sys.executable, "-m", "venv", "--without-pip", measured / ".venv"), - check=True, - timeout=30, - ) - site_paths = tuple( - (measured / ".venv").glob("lib/python*/site-packages") - ) - assert len(site_paths) == 1 - installed_package = site_paths[0] / "pyamplicol" - installed_package.mkdir() - (installed_package / "__init__.py").write_text( - "ORIGIN = 'measured-venv-pyamplicol'\n", - encoding="ascii", - ) - (installed_package / native_name).write_bytes(native_payload) - - attacker = tmp_path / "attacker" - attacker_package = attacker / "tools/performance_report" - attacker_package.mkdir(parents=True) - (attacker / "tools/__init__.py").write_text("", encoding="ascii") - (attacker_package / "__init__.py").write_text( - "raise RuntimeError('attacker PYTHONPATH was imported')\n", - encoding="ascii", - ) - (attacker / "pyamplicol").mkdir() - (attacker / "pyamplicol/__init__.py").write_text( - "raise RuntimeError('attacker pyamplicol was imported')\n", - encoding="ascii", - ) - - def git_value(root: Path, expression: str) -> str: - return subprocess.run( - ("git", "rev-parse", expression), - cwd=root, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - def digest(path: Path) -> str: - return hashlib.sha256(path.read_bytes()).hexdigest() - - common_arguments = ( - "--repo-root", - str(measured), - "--measurement-source-root", - str(measured), - "--expected-measurement-source-revision", - git_value(measured, "HEAD^{commit}"), - "--expected-measurement-source-tree", - git_value(measured, "HEAD^{tree}"), - "--expected-policy-wrapper-revision", - git_value(wrapper, "HEAD^{commit}"), - "--expected-policy-wrapper-tree", - git_value(wrapper, "HEAD^{tree}"), - "--expected-policy-entrypoint-sha256", - digest(wrapper_entrypoint), - "--expected-legacy-adapter-sha256", - digest(wrapper_legacy), - "--study-contract-sha256", - "a" * 64, - ) - environment = os.environ.copy() - environment.update( - { - "PYTHONPATH": str(attacker), - "PYTHONHOME": str(attacker), - "PYTHONSTARTUP": str(attacker / "startup.py"), - "PYTHONUSERBASE": str(attacker), - "SPLIT_CLI_SENTINEL_ROOT": str(output), - "SPLIT_PREIMPORT_SENTINEL": str(preimport_sentinel), - } - ) - for command in ("_prepare", "_worker"): - result_path = output / f"{command}-result.json" - completed = subprocess.run( - ( - measured / ".venv/bin/python", - "-I", - "-S", - "-B", - wrapper_entrypoint, - *common_arguments, - command, - "--result-json", - result_path, - ), - cwd=measured, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=30, - ) - assert completed.returncode == 0, completed.stderr - captured = json.loads( - (output / f"{command}.json").read_text(encoding="ascii") - ) - assert Path(captured["cli_origin"]).is_relative_to(wrapper_tools) - assert Path(captured["tools_origin"]).is_relative_to(wrapper_tools) - assert Path(captured["legacy_origin"]) == wrapper_legacy - assert captured["legacy_marker"] == ( - "wrapper-legacy-bootstrap-exclusion" - ) - assert Path(captured["pyamplicol_origin"]).is_relative_to( - measured_package - ) - assert { - Path(path).resolve() - for path in captured["pyamplicol_path"] - } == {measured_package.resolve()} - assert str(attacker) not in captured["sys_path"] - assert str(wrapper / "src") not in captured["sys_path"] - assert { - Path(path).resolve() - for path in captured["sys_path"] - if "site-packages" in path - } == {site_paths[0].resolve()} - assert result_path.is_file() - - assert json.loads(preimport_sentinel.read_text(encoding="ascii")) == { - "roots": [str(measured_package)], - "native_extension": str(measured_package / native_name), - } - - preimport_sentinel.unlink() - (output / "_worker.json").unlink() - (measured_package / "__init__.py").write_text( - "ORIGIN = 'dirty-measured-pyamplicol'\n", - encoding="ascii", - ) - dirty_result = subprocess.run( - ( - measured / ".venv/bin/python", - "-I", - "-S", - "-B", - wrapper_entrypoint, - *common_arguments, - "_worker", - "--result-json", - output / "dirty-result.json", - ), - cwd=measured, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=30, - ) - - assert dirty_result.returncode != 0 - assert ( - "measured-source checkout has tracked changes" - in dirty_result.stderr - ) - assert not preimport_sentinel.exists() - assert not (output / "_worker.json").exists() - - (measured_package / "__init__.py").write_text( - "ORIGIN = 'measured-pyamplicol'\n", - encoding="ascii", - ) - (measured_package / "injected.py").write_text( - "raise RuntimeError('untracked measured source was imported')\n", - encoding="ascii", - ) - untracked_result = subprocess.run( - ( - measured / ".venv/bin/python", - "-I", - "-S", - "-B", - wrapper_entrypoint, - *common_arguments, - "_worker", - "--result-json", - output / "untracked-result.json", - ), - cwd=measured, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=30, - ) - - assert untracked_result.returncode != 0 - assert ( - "measured-source checkout has untracked files in imported " - "source roots" - in untracked_result.stderr - ) - assert not preimport_sentinel.exists() - assert not (output / "_worker.json").exists() diff --git a/pyamplicol/tests/unit/test_examples.py b/pyamplicol/tests/unit/test_examples.py index 8d2f95ee98..a6606442e9 100644 --- a/pyamplicol/tests/unit/test_examples.py +++ b/pyamplicol/tests/unit/test_examples.py @@ -441,7 +441,6 @@ def test_readme_states_current_release_boundary_and_public_surfaces() -> None: assert "p p > Z j j" in readme assert "Runtime.load" in readme assert "pyamplicol examples copy" in readme - assert "pyamplicol profiling-campaign copy" in readme for interface in ("Python", "C11", "C++17", "Fortran 2008", "Rust 2021"): assert interface in readme assert "one source distribution and three `cp311-abi3` wheels" in status diff --git a/pyamplicol/tests/unit/test_fft_gluon_performance_acceptance.py b/pyamplicol/tests/unit/test_fft_gluon_performance_acceptance.py deleted file mode 100644 index 5e52245c79..0000000000 --- a/pyamplicol/tests/unit/test_fft_gluon_performance_acceptance.py +++ /dev/null @@ -1,1603 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import os -import shutil -import subprocess -import sys -import uuid -from dataclasses import replace -from pathlib import Path - -import pytest - -from tools.developer import fft_gluon_performance_acceptance as acceptance - - -def _probe( - *, - lane: str, - warm: float, - rss_kib: int = 1024, - point_values: tuple[float, ...] = (1.0,) * 10, - load: float = 0.2, - first_warm: float = 0.3, -) -> acceptance.CandidateProbeMetrics: - samples = tuple(warm * (1.0 + 0.001 * index) for index in range(10)) - warm_cells = tuple((sample,) for sample in samples) - return acceptance.CandidateProbeMetrics( - process="gg_N4", - execution_mode=lane, - helicity_coverage_count=1 if lane == "recurrence" else 16, - selected_helicity_id="h:-1,-1,+1,+1", - point_count=10, - point_values=point_values, - load_seconds=load, - first_warm_seconds=first_warm, - warm_up_api_seconds=0.0 if lane == "recurrence" else 0.25, - calibration_calls=(100,), - calibration_seconds=(0.26,), - warm_cell_seconds=warm_cells, - warm_samples_seconds=samples, - warm_median_seconds=acceptance.statistics.median(samples), - minimum_absolute_value=1.0, - max_rss_kib=rss_kib, - ) - - -def _candidate( - lane: str, - total_gluons: int, - warm: float, - *, - generation: float = 1.0, - rss_kib: int = 1024, - numerical_passes: bool = True, - load: float = 0.2, - first_warm: float = 0.3, -) -> acceptance.CandidateMetrics: - scale_factor = acceptance.candidate_reference_scale_factor(total_gluons) - point_values = [1.0 / scale_factor] * 10 - if not numerical_passes: - point_values[4] *= 1.0 + 1.0e-8 - numerical_parity = acceptance.compare_candidate_to_reference( - total_gluons=total_gluons, - candidate_values=point_values, - reference_values=(1.0,) * 10, - ) - return acceptance.CandidateMetrics( - lane=lane, - total_gluons=total_gluons, - generator_seed=acceptance.generator_seed(total_gluons), - generation_seconds=generation, - load_seconds=load, - first_warm_seconds=first_warm, - max_rss_kib=rss_kib, - probe=_probe( - lane=lane, - warm=warm, - rss_kib=rss_kib, - point_values=tuple(point_values), - load=load, - first_warm=first_warm, - ), - numerical_parity=numerical_parity, - ) - - -def _reference( - total_gluons: int, - *, - warm: float = 1.0, - rss_kib: int = 1024, - build: float = 1.0, - setup: float | None = None, -) -> acceptance.ReferenceMetrics: - return acceptance.ReferenceMetrics( - total_gluons=total_gluons, - generator_seed=acceptance.generator_seed(total_gluons), - backend=acceptance.REFERENCE_BACKEND, - clean_build_scope=acceptance.REFERENCE_CLEAN_BUILD_SCOPE, - clean_build_command_count=11, - clean_build_seconds=build, - setup_to_driver_seconds=build if setup is None else setup, - initialization_seconds=0.2, - first_pass_seconds=0.3, - warm_samples_seconds=(warm,) * 10, - warm_median_seconds=warm, - max_rss_kib=rss_kib, - selected_helicity=(-1, -1, 1, 1), - selected_path="mhv", - event_paths=tuple(f"point-{index}.event" for index in range(10)), - matrix_elements=(1.0,) * 10, - ) - - -def test_reference_formal_cold_and_scaling_setup_metrics_remain_distinct() -> None: - reference = _reference(4, build=1.0, setup=2.0) - - assert reference.cold_to_ready_seconds == pytest.approx(1.5) - assert reference.setup_to_ready_seconds == pytest.approx(2.5) - payload = acceptance._plain_reference(reference) - assert payload["cold_to_ready_seconds"] == pytest.approx(1.5) - assert payload["setup_to_ready_seconds"] == pytest.approx(2.5) - assert payload["clean_build_scope"] == "ampligluon-trace-backend-only" - - -def test_reference_clean_build_boundary_excludes_support_tools(tmp_path: Path) -> None: - build_dir = tmp_path / "reference" / "N4" / "build" - backend_dir = build_dir / acceptance.REFERENCE_BUILD_PROGRAM - backend_compile = ( - "gfortran", - f"-J{backend_dir / 'modules'}", - "-c", - "trace_colour_matrix.f90", - "-o", - str(backend_dir / "05_trace_colour_matrix.o"), - ) - rambo_compile = ( - "gfortran", - "-c", - "find_zero.f90", - "-o", - str(build_dir / "generate_ampligluon_events" / "00_find_zero.o"), - ) - proxy_link = ( - "gfortran", - "benchmark_helicity_proxy.f90", - "-o", - str(build_dir / "benchmark_helicity_proxy" / "benchmark_helicity_proxy"), - ) - - assert acceptance._is_reference_backend_build_command( - backend_compile, build_dir=build_dir, build_phase_active=True - ) - assert not acceptance._is_reference_backend_build_command( - rambo_compile, build_dir=build_dir, build_phase_active=True - ) - assert not acceptance._is_reference_backend_build_command( - proxy_link, build_dir=build_dir, build_phase_active=True - ) - assert not acceptance._is_reference_backend_build_command( - (str(backend_dir / acceptance.REFERENCE_BUILD_PROGRAM),), - build_dir=build_dir, - build_phase_active=False, - ) - - -def test_reference_cold_timeout_remains_live_for_the_driver( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(acceptance.time, "perf_counter", lambda: 105.0) - - assert acceptance._bounded_reference_cold_timeout(30.0, 10.0, 100.0) == 5.0 - with pytest.raises( - acceptance.ReferenceColdLimitError, match="aggregate cold deadline" - ): - acceptance._bounded_reference_cold_timeout(30.0, 5.0, 100.0) - source = Path(acceptance.__file__).read_text(encoding="utf-8") - assert "cold_setup_active" not in source - - -def _probe_output( - *, - calibration: float = 0.26, - lane: str = "recurrence", -) -> str: - rows = [ - "FFT_CANDIDATE_PROBE_V4", - "PROCESS gg_N4", - f"EXECUTION_MODE {lane}", - "TIMER_SOURCE process-cpu-time", - "HELICITY_COVERAGE_COUNT 1", - "SELECTED_HELICITY_ID h:-1,-1,+1,+1", - "POINT_COUNT 10", - "LOAD_SECONDS 2.0e-1", - "FIRST_WARM_SECONDS 3.0e-1", - f"WARM_UP_API_SECONDS {0.0 if lane == 'recurrence' else 0.25}", - *(f"POINT_VALUE {point} {1.0 / 512.0}" for point in range(1, 11)), - f"CALIBRATION_CELL 1 101 {calibration}", - *(f"WARM_CELL_SECONDS {batch} 1 {batch * 1.0e-6}" for batch in range(1, 11)), - "MIN_ABSOLUTE_VALUE 1.0e-20", - "MAX_RSS_KIB 4096", - ] - return "\n".join(rows) + "\n" - - -def _first_ready_output(*, lane: str = "recurrence", rss_kib: int = 4096) -> str: - return ( - "\n".join( - ( - "FFT_CANDIDATE_FIRST_READY_V1", - "PROCESS gg_N4", - f"EXECUTION_MODE {lane}", - "TIMER_SOURCE process-cpu-time", - "HELICITY_COVERAGE_COUNT 1", - "SELECTED_HELICITY_ID h:-1,-1,+1,+1", - "POINT_COUNT 10", - "LOAD_SECONDS 0.2", - "FIRST_WARM_SECONDS 0.3", - f"WARM_UP_API_SECONDS {0.0 if lane == 'recurrence' else 0.25}", - "MIN_ABSOLUTE_VALUE 1e-20", - f"MAX_RSS_KIB {rss_kib}", - ) - ) - + "\n" - ) - - -def _without_warm_cell(output: str, batch: int, point: int) -> str: - prefix = f"WARM_CELL_SECONDS {batch} {point} " - return ( - "\n".join(line for line in output.splitlines() if not line.startswith(prefix)) - + "\n" - ) - - -def _without_point_value(output: str, point: int) -> str: - prefix = f"POINT_VALUE {point} " - return ( - "\n".join(line for line in output.splitlines() if not line.startswith(prefix)) - + "\n" - ) - - -def _duplicate_warm_cell( - output: str, - source: tuple[int, int], - destination: tuple[int, int], -) -> str: - prefix = f"WARM_CELL_SECONDS {source[0]} {source[1]} " - return ( - "\n".join( - ( - f"WARM_CELL_SECONDS {destination[0]} {destination[1]} {line.split()[3]}" - if line.startswith(prefix) - else line - ) - for line in output.splitlines() - ) - + "\n" - ) - - -def test_candidate_probe_parser_requires_canonical_ten_sample_evidence() -> None: - parsed = acceptance.parse_candidate_probe_output(_probe_output()) - - assert parsed.execution_mode == "recurrence" - assert parsed.point_count == 10 - assert parsed.point_values == pytest.approx((1.0 / 512.0,) * 10) - assert parsed.warm_up_api_seconds == 0.0 - assert parsed.calibration_calls == (101,) - assert parsed.calibration_seconds == pytest.approx((0.26,)) - assert len(parsed.warm_cell_seconds) == 10 - assert all(len(row) == 1 for row in parsed.warm_cell_seconds) - assert parsed.warm_samples_seconds == pytest.approx( - tuple(batch * 1.0e-6 for batch in range(1, 11)) - ) - assert parsed.warm_median_seconds == pytest.approx(5.5e-6) - assert parsed.max_rss_kib == 4096 - - -@pytest.mark.parametrize( - ("payload", "message"), - ( - (_probe_output(calibration=0.249), "0.25 seconds"), - (_without_point_value(_probe_output(), 10), "all 10 point values"), - (_without_warm_cell(_probe_output(), 10, 1), "point-1 cell"), - ( - _probe_output().replace( - "CALIBRATION_CELL 1 101 0.26", - "CALIBRATION_CELL 1 101 0.26\nCALIBRATION_CELL 2 102 0.26", - ), - "calibrate only representative point 1", - ), - ( - _duplicate_warm_cell(_probe_output(), (10, 1), (9, 1)), - "duplicated", - ), - ), -) -def test_candidate_probe_parser_rejects_incomplete_policy_evidence( - payload: str, - message: str, -) -> None: - with pytest.raises(acceptance.AcceptanceError, match=message): - acceptance.parse_candidate_probe_output(payload) - - -def test_candidate_probe_parser_enforces_lane_specific_warm_up_contract() -> None: - otf = acceptance.parse_candidate_probe_output(_probe_output(lane="on-the-fly")) - assert otf.warm_up_api_seconds == pytest.approx(0.25) - - bad_recurrence = _probe_output().replace( - "WARM_UP_API_SECONDS 0.0", "WARM_UP_API_SECONDS 0.25" - ) - with pytest.raises(acceptance.AcceptanceError, match="OTF-only"): - acceptance.parse_candidate_probe_output(bad_recurrence) - - -@pytest.mark.parametrize("lane", acceptance.LANES) -def test_candidate_identity_requires_lane_coverage_and_the_paired_helicity( - lane: str, -) -> None: - metrics = _probe(lane=lane, warm=1.0) - expected = (-1, -1, 1, 1) - - acceptance._validate_candidate_probe_identity( - metrics, - lane=lane, - total_gluons=4, - expected_helicities=expected, - ) - invalid_coverage = 2 if lane == "recurrence" else 1 - with pytest.raises(acceptance.AcceptanceError, match=r"coverage|specialization"): - acceptance._validate_candidate_probe_identity( - replace(metrics, helicity_coverage_count=invalid_coverage), - lane=lane, - total_gluons=4, - expected_helicities=expected, - ) - with pytest.raises(acceptance.AcceptanceError, match="known-nonzero helicity"): - acceptance._validate_candidate_probe_identity( - replace(metrics, selected_helicity_id="h:-1,+1,-1,+1"), - lane=lane, - total_gluons=4, - expected_helicities=expected, - ) - - -def test_observed_default_bg_n4_protocol_times_one_cell_but_retains_ten_mes() -> None: - rows = [ - f"BACKEND {acceptance.REFERENCE_BACKEND}", - "DIMENSION 6", - "INITIALIZATION_SECONDS 1.0e-3", - "FIRST_HELICITY_SWEEP_SECONDS 2.0e-3", - "EVALUATIONS_PER_SWEEP 1", - *(f"MATRIX_ELEMENT {point} 1 {point * 1.0e-3}" for point in range(1, 11)), - *( - f"EVALUATION_CELL_SECONDS {batch} 1 1 {batch * 1.0e-6}" - for batch in range(1, 11) - ), - ] - reference = acceptance._load_reference_module() - run = reference.parse_driver_output( - "\n".join(rows) + "\n", - acceptance.REFERENCE_BACKEND, - False, - ) - - samples = acceptance._reference_representative_warm_samples(run.cell_timings) - - assert set(run.matrix_elements) == {(point, 1) for point in range(1, 11)} - assert samples == pytest.approx(tuple(batch * 1.0e-6 for batch in range(1, 11))) - assert acceptance.statistics.median(samples) == pytest.approx(5.5e-6) - - with pytest.raises(acceptance.AcceptanceError, match="one point-1 cell"): - acceptance._reference_representative_warm_samples( - run.cell_timings | {(1, 2, 1): 1.0e-6} - ) - - -@pytest.mark.parametrize("total_gluons", (4, 9, 11)) -def test_numerical_parity_aligns_unit_coupling_and_me_conventions( - total_gluons: int, -) -> None: - reference_values = tuple(float(point * point + 1) for point in range(1, 11)) - scale_factor = 256 * acceptance.math.factorial(total_gluons - 2) - candidate_values = tuple(value / scale_factor for value in reference_values) - - evidence = acceptance.compare_candidate_to_reference( - total_gluons=total_gluons, - candidate_values=candidate_values, - reference_values=reference_values, - ) - - assert evidence.normalization_alpha_s_me_check == pytest.approx( - 1.0 / (4.0 * acceptance.math.pi) - ) - assert evidence.candidate_scale_factor == scale_factor - assert evidence.relative_tolerance == 1.0e-10 - assert evidence.maximum_relative_error <= 1.0e-15 - assert evidence.passes is True - - -@pytest.mark.parametrize("mismatch_multiplier", (1.0 + 2.0e-10, 0.0, -1.0)) -def test_numerical_parity_rejects_a_strict_scale_relative_mismatch( - mismatch_multiplier: float, -) -> None: - reference_values = (1.0,) * 10 - scale_factor = acceptance.candidate_reference_scale_factor(4) - candidate_values = [1.0 / scale_factor] * 10 - candidate_values[6] *= mismatch_multiplier - - evidence = acceptance.compare_candidate_to_reference( - total_gluons=4, - candidate_values=candidate_values, - reference_values=reference_values, - ) - - assert evidence.maximum_relative_error_point == 7 - assert evidence.maximum_relative_error > 1.0e-10 - assert evidence.passes is False - - -def test_candidate_first_ready_parser_uses_the_same_lane_contract() -> None: - parsed = acceptance.parse_candidate_first_ready_output(_first_ready_output()) - assert parsed.execution_mode == "recurrence" - assert parsed.warm_up_api_seconds == 0.0 - zero_candidate = acceptance.parse_candidate_first_ready_output( - _first_ready_output().replace( - "MIN_ABSOLUTE_VALUE 1e-20", "MIN_ABSOLUTE_VALUE 0" - ) - ) - assert zero_candidate.minimum_absolute_value == 0.0 - - -def test_darwin_reference_command_uses_getrusage_for_gnu_and_direct_wrappers() -> None: - wrapped = ( - "/usr/bin/timeout", - "--signal=TERM", - "--kill-after=5s", - "600s", - "/usr/bin/time", - "--format=BENCHMARK_MAX_RSS_KIB %M", - "/usr/bin/prlimit", - "--as=32212254720", - "--", - "/workspace/reference-driver", - "default-bg", - "fft", - ) - - translated, measured = acceptance._translate_darwin_reference_command( - wrapped, python="/venv/python" - ) - - assert measured is True - assert translated == ( - "/venv/python", - str(acceptance.SCALING_STUDY_DRIVER), - "_time-rss", - "/workspace/reference-driver", - "default-bg", - "fft", - ) - direct, measured = acceptance._translate_darwin_reference_command( - ("/usr/bin/time", "-l", "/workspace/reference-driver"), - python="/venv/python", - ) - assert measured is True - assert direct == ( - "/venv/python", - str(acceptance.SCALING_STUDY_DRIVER), - "_time-rss", - "/workspace/reference-driver", - ) - compiler = ("gfortran", "--version") - assert acceptance._translate_darwin_reference_command(compiler) == ( - compiler, - False, - ) - - -def test_gnu_reference_command_uses_getrusage_and_resolves_wrappers_from_path( - monkeypatch: pytest.MonkeyPatch, -) -> None: - tools = { - "timeout": "/nix/bin/timeout", - "prlimit": "/nix/bin/prlimit", - } - monkeypatch.setattr(acceptance.shutil, "which", tools.__getitem__) - wrapped = ( - "/usr/bin/timeout", - "--signal=TERM", - "--kill-after=5s", - "600s", - "/usr/bin/time", - "--format=BENCHMARK_MAX_RSS_KIB %M", - "/usr/bin/prlimit", - "--as=32212254720", - "--", - "/workspace/reference-driver", - "default-bg", - "fft", - ) - - translated, measured = acceptance._translate_gnu_reference_command( - wrapped, - python="/venv/python", - ) - - assert measured is True - assert translated == ( - "/venv/python", - str(acceptance.SCALING_STUDY_DRIVER), - "_time-rss", - "/nix/bin/timeout", - "--signal=TERM", - "--kill-after=5s", - "600s", - "/nix/bin/prlimit", - "--as=32212254720", - "--", - "/workspace/reference-driver", - "default-bg", - "fft", - ) - - -def test_darwin_getrusage_rss_is_adapted_to_the_reference_protocol() -> None: - getrusage = subprocess.CompletedProcess( - args=("_time-rss", "reference-driver"), - returncode=0, - stdout="BACKEND AmpliGluonTraceDefaultBG\n", - stderr="FFT_MAX_RSS_KIB 125\n", - ) - normalized = acceptance._synthesize_reference_rss_marker(getrusage) - assert normalized.stderr == ("FFT_MAX_RSS_KIB 125\nBENCHMARK_MAX_RSS_KIB 125\n") - assert ( - acceptance._parse_translated_reference_child_rss_kib(normalized.stderr) == 125 - ) - with pytest.raises(acceptance.AcceptanceError, match="matching exact child"): - acceptance._parse_translated_reference_child_rss_kib( - "FFT_MAX_RSS_KIB 125\nBENCHMARK_MAX_RSS_KIB 999\n" - ) - compiler_watchdog_rss_kib = 200 - wrapper_watchdog_rss_kib = 4096 - formal_evaluator_rss_kib = acceptance._formal_reference_evaluator_rss_kib( - 125, - compiler_watchdog_rss_kib, - 125, - ) - assert formal_evaluator_rss_kib == 125 - assert formal_evaluator_rss_kib != compiler_watchdog_rss_kib - assert formal_evaluator_rss_kib != wrapper_watchdog_rss_kib - - -def test_global_lane_is_selected_once_from_both_valid_lane_workloads() -> None: - references = { - total: _reference(total) for total in acceptance.MANDATORY_MULTIPLICITIES - } - candidates = { - "on-the-fly": { - total: _candidate("on-the-fly", total, 0.1) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - "recurrence": { - total: _candidate("recurrence", total, 1.0) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - } - - winner = acceptance.select_global_lane(references, candidates) - eligibility = acceptance.lane_eligibility(candidates) - - assert winner == "on-the-fly" - assert eligibility["on-the-fly"]["eligible"] is True - assert eligibility["on-the-fly"]["generation_specialized"] is False - assert eligibility["on-the-fly"]["complete_helicity_coverage"] is True - assert eligibility["recurrence"]["eligible"] is True - assert eligibility["recurrence"]["generation_specialized"] is True - assert eligibility["recurrence"]["complete_helicity_coverage"] is False - assert all( - candidates["on-the-fly"][total].probe.warm_median_seconds - < candidates["recurrence"][total].probe.warm_median_seconds - for total in acceptance.MANDATORY_MULTIPLICITIES - ) - - -def test_otf_without_complete_selector_coverage_is_ineligible() -> None: - candidates = { - "on-the-fly": { - total: _candidate("on-the-fly", total, 0.1) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - "recurrence": { - total: _candidate("recurrence", total, 1.0) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - } - - for total, candidate in tuple(candidates["on-the-fly"].items()): - candidates["on-the-fly"][total] = replace( - candidate, - probe=replace(candidate.probe, helicity_coverage_count=1), - ) - - assert acceptance.lane_eligibility(candidates)["on-the-fly"]["eligible"] is False - with pytest.raises(acceptance.AcceptanceError, match="workload contract"): - acceptance.evaluate_gates("on-the-fly", {}, candidates) - - -def test_slower_passing_lane_wins_when_faster_lane_fails_rss() -> None: - references = { - total: _reference(total, rss_kib=1000) - for total in acceptance.MANDATORY_MULTIPLICITIES - } - candidates = { - "recurrence": { - total: _candidate("recurrence", total, 0.1, rss_kib=2001) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - "on-the-fly": { - total: _candidate("on-the-fly", total, 1.0, rss_kib=1000) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - } - - assert acceptance.select_global_lane(references, candidates) == "on-the-fly" - - -def test_incremental_viability_keeps_otf_when_recurrence_fails() -> None: - references = {4: _reference(4)} - candidates = { - "recurrence": {4: _candidate("recurrence", 4, 2.0)}, - "on-the-fly": {4: _candidate("on-the-fly", 4, 0.1)}, - } - - viability = acceptance._observed_mandatory_gate_viability( - references, candidates, multiplicities=(4,) - ) - - assert viability["viable_lanes"] == ["on-the-fly"] - assert viability["lanes"]["recurrence"]["viable"] is False - assert viability["lanes"]["on-the-fly"]["eligible"] is True - assert viability["lanes"]["on-the-fly"]["viable"] is True - - -def test_gate_ratios_use_only_the_global_winner_and_include_thresholds() -> None: - references = { - total: _reference( - total, - warm=1.0, - rss_kib=1000, - build=1.0, - setup=100.0, - ) - for total in acceptance.MANDATORY_MULTIPLICITIES - } - candidates = { - "on-the-fly": { - total: _candidate("on-the-fly", total, 100.0, rss_kib=100_000) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - "recurrence": { - total: _candidate( - "recurrence", - total, - 1.25 / 1.0045, - generation=7.0, - rss_kib=2000, - ) - for total in acceptance.MANDATORY_MULTIPLICITIES - }, - } - - gates = acceptance.evaluate_gates("recurrence", references, candidates) - - assert {gate.lane for gate in gates} == {"recurrence"} - assert len(gates) == 6 - assert all(gate.warm_ratio == pytest.approx(1.25) for gate in gates) - assert all(gate.rss_ratio == pytest.approx(2.0) for gate in gates) - assert all(gate.cold_ratio == pytest.approx(5.0) for gate in gates) - assert all(gate.passes for gate in gates) - - -def test_numerical_mismatch_fails_an_otherwise_passing_gate() -> None: - references = { - total: _reference(total) for total in acceptance.MANDATORY_MULTIPLICITIES - } - candidates = { - lane: { - total: _candidate( - lane, - total, - 1.0 / 1.0045, - numerical_passes=(lane != "recurrence" or total != 7), - ) - for total in acceptance.MANDATORY_MULTIPLICITIES - } - for lane in acceptance.LANES - } - - gates = acceptance.evaluate_gates("recurrence", references, candidates) - - failed = next(gate for gate in gates if gate.total_gluons == 7) - assert failed.warm_passes is True - assert failed.rss_passes is True - assert failed.cold_passes is True - assert failed.numerical_passes is False - assert failed.passes is False - assert acceptance._gate_report(gates)["passes"] is False - - -def _gate(total_gluons: int, *, passes: bool) -> acceptance.GateResult: - return acceptance.GateResult( - total_gluons=total_gluons, - lane="recurrence", - warm_ratio=1.0 if passes else 1.26, - rss_ratio=1.0, - cold_ratio=1.0, - warm_passes=passes, - rss_passes=True, - cold_passes=True, - numerical_passes=True, - ) - - -@pytest.mark.parametrize( - ("optional_gates", "expected"), - ( - ((_gate(10, passes=False),), False), - ((_gate(10, passes=True), _gate(11, passes=True)), True), - ((), True), - ), - ids=("measured-fail", "measured-pass", "skipped"), -) -def test_gate_report_includes_every_measured_optional_row( - monkeypatch: pytest.MonkeyPatch, - optional_gates: tuple[acceptance.GateResult, ...], - expected: bool, -) -> None: - mandatory = tuple( - _gate(total_gluons, passes=True) - for total_gluons in acceptance.MANDATORY_MULTIPLICITIES - ) - - report = acceptance._gate_report((*mandatory, *optional_gates)) - - assert report["passes"] is expected - serialized = report["gates"] - assert isinstance(serialized, list) - assert [gate["total_gluons"] for gate in serialized] == [ - *acceptance.MANDATORY_MULTIPLICITIES, - *(gate.total_gluons for gate in optional_gates), - ] - assert all(gate["passes"] for gate in serialized[:6]) - assert [gate["passes"] for gate in serialized[6:]] == [ - gate.passes for gate in optional_gates - ] - monkeypatch.setattr(acceptance, "_campaign", lambda _arguments: report) - assert acceptance.main(("--run-id", "pytest-optional-gate-report")) == ( - 0 if expected else 1 - ) - - -def test_optional_numerical_mismatch_is_fatal_and_persisted_not_skipped( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - performance_root = tmp_path / "performance" - monkeypatch.setattr(acceptance, "PERFORMANCE_ROOT", performance_root) - source_identity = acceptance.ReportSourceIdentity("a" * 40, "b" * 40, ()) - monkeypatch.setattr( - acceptance, - "_require_campaign_source_identity", - lambda _expected=None: source_identity, - ) - reference_source_identity = acceptance.ReferenceSourceIdentity( - acceptance.REFERENCE_REVISION, "c" * 64, 4 - ) - monkeypatch.setattr( - acceptance, - "_require_reference_source_identity", - lambda _expected=None: reference_source_identity, - ) - monkeypatch.setattr(acceptance, "_workspace_environment", lambda _python: {}) - monkeypatch.setattr( - acceptance, - "_enforce_one_core", - lambda _platform: {"requested_cpu_cores": 1}, - ) - monkeypatch.setattr( - acceptance, - "_build_probe", - lambda **_kwargs: ( - tmp_path / "probe", - {"target": "test-target", "package_version": "test-version"}, - ), - ) - monkeypatch.setattr(acceptance, "_load_reference_module", object) - - def fake_reference(**kwargs: object) -> acceptance._ReferenceRun: - total_gluons = int(kwargs["total_gluons"]) - return acceptance._ReferenceRun( - metrics=_reference(total_gluons), - event_paths=tuple( - tmp_path / f"N{total_gluons}-point-{point}.event" for point in range(10) - ), - ) - - def fake_candidate(**kwargs: object) -> acceptance.CandidateMetrics: - total_gluons = int(kwargs["total_gluons"]) - return _candidate( - str(kwargs["lane"]), - total_gluons, - 0.5 if kwargs["lane"] == "recurrence" else 1.0, - numerical_passes=total_gluons != 10, - ) - - monkeypatch.setattr(acceptance, "_run_reference", fake_reference) - monkeypatch.setattr(acceptance, "_run_candidate", fake_candidate) - arguments = acceptance._parser().parse_args( - ("--include-optional", "--run-id", "optional-numerical-mismatch") - ) - - with pytest.raises(acceptance.NumericalParityError, match="N=10"): - acceptance._campaign(arguments) - - report = json.loads( - ( - performance_root / "runs" / "optional-numerical-mismatch" / "report.json" - ).read_text(encoding="utf-8") - ) - assert report["status"] == "failed-numerical-parity" - assert report["optional"]["10"]["status"] == "failed-numerical-parity" - optional_lanes = [ - lane for lane, records in report["candidates"].items() if "10" in records - ] - assert optional_lanes == ["recurrence"] - evidence = report["candidates"][optional_lanes[0]]["10"] - assert len(evidence["probe"]["point_values"]) == 10 - assert evidence["numerical_parity"]["passes"] is False - assert evidence["numerical_parity"]["maximum_relative_error"] > 1.0e-10 - assert len(report["reference"]["10"]["matrix_elements"]) == 10 - - -def test_optional_policy_enforces_independent_stage_and_memory_caps() -> None: - accepted = _candidate( - "recurrence", - 10, - 1.0, - generation=899.75, - first_warm=0.5, - ) - slow_generation = _candidate("recurrence", 10, 1.0, generation=900.0) - slow_first_warm = _candidate("recurrence", 10, 1.0, first_warm=900.0) - large = _candidate( - "recurrence", - 10, - 1.0, - rss_kib=(30 * 1024**2) + 1, - ) - - assert accepted.cold_to_ready_seconds > 900.0 - assert acceptance.optional_candidate_is_feasible(accepted) - assert not acceptance.optional_candidate_is_feasible(slow_generation) - assert not acceptance.optional_candidate_is_feasible(slow_first_warm) - assert not acceptance.optional_candidate_is_feasible(large) - - -def test_candidate_generation_commands_lock_paired_helicity_semantics( - tmp_path: Path, -) -> None: - on_the_fly = acceptance.candidate_generation_command( - python="python-test", - lane="on-the-fly", - total_gluons=4, - helicities=(1, 1, 1, 1), - artifact=tmp_path / "artifact", - ) - recurrence = acceptance.candidate_generation_command( - python="python-test", - lane="recurrence", - total_gluons=4, - helicities=(1, 1, 1, 1), - artifact=tmp_path / "recurrence-artifact", - ) - - for command, lane in ((on_the_fly, "on-the-fly"), (recurrence, "recurrence")): - assert command[:4] == ("python-test", "-m", "pyamplicol", "generate") - assert command[command.index("--color-accuracy") + 1] == "full" - assert command[command.index("--color-contraction") + 1] == ( - "symmetric-group-fft" - ) - assert command[command.index("--execution-mode") + 1] == lane - assert "evaluator.batch_size=1" in command - assert "evaluator.optimization.cores=1" in command - assert "model.cache=false" in command - selection = "process.selected_source_helicities={1=1,2=1,3=1,4=1}" - assert selection not in on_the_fly - assert selection in recurrence - - -def test_dry_run_is_nonwriting_and_covers_locked_seeds( - capsys: pytest.CaptureFixture[str], - monkeypatch: pytest.MonkeyPatch, -) -> None: - run_id = "pytest-dry-run-fft-policy" - run_root = acceptance.PERFORMANCE_ROOT / "runs" / run_id - assert not run_root.exists() - - monkeypatch.setattr(acceptance.sys, "platform", "darwin") - result = acceptance.main(("--dry-run", "--include-optional", "--run-id", run_id)) - - assert result == 0 - assert not run_root.exists() - payload = json.loads(capsys.readouterr().out) - assert payload["dry_run"] is True - assert payload["host_platform"] == "darwin" - assert payload["reference"]["process_measurement"] == ( - "darwin-getrusage-child-plus-watchdog" - ) - assert payload["reference"]["rss_marker"] == "FFT_MAX_RSS_KIB" - assert [item["total_gluons"] for item in payload["multiplicities"]] == list( - range(4, 12) - ) - assert [item["generator_seed"] for item in payload["multiplicities"]] == list( - range(1733, 1741) - ) - assert all( - item["candidate_lanes"] == ["recurrence", "on-the-fly"] - for item in payload["multiplicities"][:6] - ) - assert all( - item["candidate_lanes"] == ["global-winner"] - for item in payload["multiplicities"][6:] - ) - assert payload["measurement"] | {"cpu_policy": None} == { - "batch_size": 1, - "calibration_scope": "representative-point-1-only", - "calibration_seconds_minimum": 0.25, - "candidate_timer_source": "process-cpu-time", - "cpu_cores": 1, - "cpu_policy": None, - "fresh_process_same_os_rss": True, - "mandatory_lane_order": ["recurrence", "on-the-fly"], - "memory_limit_gib": 30.0, - "model_cache": "disabled-per-lane-and-multiplicity", - "optional_cold_and_warm_processes_separate": True, - "timed_event_cells_per_batch": 1, - "warm_batch_reduction": "point-1-cell-direct", - "warm_excludes_first_call": True, - "warm_samples": 10, - } - cpu_policy = payload["measurement"]["cpu_policy"] - assert cpu_policy["method"] == "single-thread-environment" - assert cpu_policy["requested_cpu_cores"] == 1 - assert cpu_policy["affinity_available"] is False - assert cpu_policy["affinity_enforced"] is False - assert cpu_policy["cpu"] is None - assert set(cpu_policy["thread_environment"]) == set( - acceptance.SINGLE_THREAD_ENVIRONMENT - ) - assert set(cpu_policy["thread_environment"].values()) == {"1"} - assert "on-the-fly" in payload["global_lane_policy"] - assert ( - "eligible under their respective helicity workloads" - in payload["global_lane_policy"] - ) - assert "passing every mandatory gate" in payload["global_lane_policy"] - assert payload["helicity_policy"] == { - "on-the-fly": "complete-runtime-selector-fixed-helicity-query", - "recurrence": "generation-specialized-known-nonzero", - } - assert payload["thresholds"] | { - "warm_ratio_maximum": None, - "rss_ratio_maximum": None, - "cold_to_ready_ratio_maximum": None, - } == { - "warm_ratio_maximum": None, - "rss_ratio_maximum": None, - "cold_to_ready_ratio_maximum": None, - "optional_generation_seconds_maximum_exclusive": 900.0, - "optional_first_warm_seconds_maximum_exclusive": 900.0, - "optional_continuation_deadlines_are_independent": True, - } - assert payload["reference"]["formal_cold_to_ready_metric"] == ( - "clean AmpliGluonTrace backend build plus initialization plus first " - "complete pass" - ) - assert payload["reference"]["clean_build_scope"] == ( - "ampligluon-trace-backend-only" - ) - assert payload["reference"]["clean_build_program"] == ("benchmark_ampligluon_trace") - assert ( - "RAMBO and helicity-proxy builds excluded" - in payload["reference"]["clean_build_timing"] - ) - assert payload["reference"]["scaling_setup_to_ready_metric"] == ( - "all setup through driver plus initialization plus first complete pass" - ) - assert payload["schema_version"] == 8 - assert payload["numerical_parity"] == { - "reference_values": "ordered-10-AmpliGluonTrace-matrix-elements", - "candidate_values": ( - "recurrence-first-pass-all-10;" - "otf-first-pass-points-2-10-plus-point-1-calibration" - ), - "candidate_runtime_parameter": "normalization.alpha_s_me_check", - "candidate_runtime_parameter_value": pytest.approx( - 1.0 / (4.0 * acceptance.math.pi) - ), - "candidate_to_reference_scale": "256*factorial(N-2)", - "relative_error_scale": "max(abs(candidate),abs(reference))", - "relative_tolerance": 1.0e-10, - "failure_is_fatal": True, - "extra_evaluations": 0, - } - - -def test_dry_run_rejects_unsafe_run_id_without_writing() -> None: - assert acceptance.main(("--dry-run", "--run-id", "../outside")) == 1 - - -def test_probe_commands_separate_optional_cold_from_warmed_campaign( - tmp_path: Path, -) -> None: - common = { - "probe": tmp_path / "probe", - "artifact": tmp_path / "artifact", - "total_gluons": 4, - "target_seconds": 0.25, - "event_paths": tuple(tmp_path / f"point-{index}.event" for index in range(10)), - } - first_ready = acceptance._candidate_probe_command(**common, first_ready_only=True) - warmed = acceptance._candidate_probe_command(**common, first_ready_only=False) - - assert "--first-ready-only" in first_ready - assert "--first-ready-only" not in warmed - assert first_ready[-10:] == warmed[-10:] - - -def test_optional_candidate_gives_generation_and_first_ready_independent_deadlines( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - calls: list[tuple[tuple[str, ...], float]] = [] - outputs = iter(("", _first_ready_output(), _probe_output())) - - def fake_run_watched( - command: tuple[str, ...], - **kwargs: object, - ) -> acceptance.WatchedCompletedProcess: - calls.append((command, float(kwargs["timeout_seconds"]))) - return acceptance.WatchedCompletedProcess( - command, - 0, - next(outputs), - "", - elapsed_seconds=1.0, - log_write_seconds=0.1, - timed_out=False, - timeout_cleanup="not-required", - ) - - clock = iter((100.0, 105.0, 105.1)) - monkeypatch.setattr(acceptance, "_run_watched", fake_run_watched) - monkeypatch.setattr(acceptance.time, "perf_counter", lambda: next(clock)) - reference = acceptance._ReferenceRun( - metrics=_reference(4), - event_paths=tuple(tmp_path / f"point-{index}.event" for index in range(10)), - ) - - candidate = acceptance._run_candidate( - lane="recurrence", - total_gluons=4, - reference=reference, - probe=tmp_path / "probe", - run_root=tmp_path / "run", - python=sys.executable, - environment={}, - target_seconds=0.25, - timeout_seconds=3600.0, - continuation_stage_limit_seconds=900.0, - ) - - assert candidate.generation_seconds == pytest.approx(4.9) - assert candidate.cold_to_ready_seconds == pytest.approx(5.4) - assert candidate.max_rss_kib == 4096 - assert calls[0][1] == pytest.approx(900.0) - assert "--first-ready-only" in calls[1][0] - assert calls[1][1] == pytest.approx(3600.0) - assert "--first-ready-only" not in calls[2][0] - assert calls[2][1] == pytest.approx(3600.0) - - -def test_native_probe_uses_public_allocation_free_call_and_lane_guard() -> None: - source = acceptance.PROBE_SOURCE.read_text(encoding="utf-8") - - assert "#include " in source - assert "#include " not in source - assert "rusticol_runtime_evaluate_f64" in source - assert "rusticol_runtime_evaluate_selected_f64" in source - assert 'execution_mode == "recurrence" && runtime_helicity_count == 1' in source - assert "arguments.color_id.empty()" in source - assert "if (generation_specialized_total)" in source - assert "&selected_helicity_index" in source - assert 'execution_mode == "compiled" ? nullptr' not in source - assert 'if (execution_mode == "on-the-fly")' in source - assert source.count("rusticol_runtime_warm_up_f64") == 1 - assert "first_evaluated_point" not in source - assert "for (std::size_t point = 0; point < events.size(); ++point)" in source - assert "CLOCK_PROCESS_CPUTIME_ID" in source - assert "rusticol_runtime_set_model_parameter" in source - assert '"normalization.alpha_s_me_check"' in source - assert "kUnitCouplingAlphaS" in source - assert source.count("evaluate_one(") == 4 - assert source.count("evaluate_repeated_batch(") == 2 - assert 'token == "--batch-size"' in source - assert '"BENCHMARK_BATCH_SIZE "' in source - assert "events[point % events.size()]" in source - assert "authenticate_batch_results(" in source - assert "expected[index % expected.size()]" in source - assert '"BATCH_INPUT_PATTERN cyclic-10-events' in source - assert '"BATCH_AUTHENTICATED_POINT_COUNT "' in source - assert '"BATCH_MAX_RELATIVE_ERROR "' in source - assert "CLOCK_MONOTONIC" in source - assert '"START_TO_FIRST_WARM_WALL_SECONDS "' in source - assert "FFT_CANDIDATE_PROBE_V4" in source - assert "point_values[point] = evaluate_one(" in source - assert "point_values[kRepresentativePoint] = last_value" in source - assert "std::array warm_cells" in source - assert "calibration_calls[point]" not in source - assert "warm_cells[sample][point]" not in source - assert "POINT_VALUE" in source - assert "CALIBRATION_CELL" in source - assert "WARM_CELL_SECONDS" in source - - -class _GracefulTimeoutPopen: - def __init__(self) -> None: - self.returncode: int | None = None - self.communicate_timeouts: list[float | None] = [] - self.terminated = False - self.killed = False - - def communicate(self, timeout: float | None = None) -> tuple[str, str]: - self.communicate_timeouts.append(timeout) - if len(self.communicate_timeouts) == 1: - raise subprocess.TimeoutExpired(("watchdog",), timeout) - self.returncode = -15 - return "partial stdout", "watchdog cleaned child tree" - - def terminate(self) -> None: - self.terminated = True - - def kill(self) -> None: - self.killed = True - - -class _FallbackTimeoutPopen(_GracefulTimeoutPopen): - def communicate(self, timeout: float | None = None) -> tuple[str, str]: - self.communicate_timeouts.append(timeout) - if len(self.communicate_timeouts) <= 2: - raise subprocess.TimeoutExpired(("watchdog",), timeout) - self.returncode = -9 - return "partial stdout", "watchdog required fallback kill" - - -def test_watched_timeout_signals_watchdog_and_waits_for_tree_cleanup( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - fake = _GracefulTimeoutPopen() - monkeypatch.setattr(acceptance.subprocess, "Popen", lambda *args, **kwargs: fake) - log_path = tmp_path / "timeout.json" - - with pytest.raises(acceptance.AcceptanceError, match="sigterm-complete"): - acceptance._run_watched( - ("payload",), - python=sys.executable, - environment={}, - timeout_seconds=0.01, - log_path=log_path, - ) - - assert fake.terminated is True - assert fake.killed is False - assert fake.communicate_timeouts[1] > 5.0 - evidence = json.loads(log_path.read_text(encoding="utf-8")) - assert evidence["timed_out"] is True - assert evidence["timeout_cleanup"] == "sigterm-complete" - assert evidence["elapsed_excludes_log_write"] is True - - -def test_watched_timeout_records_fallback_kill( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - fake = _FallbackTimeoutPopen() - monkeypatch.setattr(acceptance.subprocess, "Popen", lambda *args, **kwargs: fake) - log_path = tmp_path / "timeout-fallback.json" - - with pytest.raises(acceptance.AcceptanceError, match="sigkill-fallback"): - acceptance._run_watched( - ("payload",), - python=sys.executable, - environment={}, - timeout_seconds=0.01, - log_path=log_path, - ) - - assert fake.terminated is True - assert fake.killed is True - evidence = json.loads(log_path.read_text(encoding="utf-8")) - assert evidence["timeout_cleanup"] == "sigkill-fallback" - - -def test_watchdog_report_preserves_exact_peak_guard_for_rss_aggregation( - tmp_path: Path, -) -> None: - report_path = tmp_path / "watchdog.json" - report_path.write_text( - json.dumps( - { - "complete": True, - "passes": True, - "enforcement": { - "peak_rss_bytes": 125_953, - "peak_guard_bytes": 126_977, - }, - } - ), - encoding="utf-8", - ) - - assert acceptance._read_watchdog_usage_kib(report_path) == (124, 125) - command = acceptance._watchdog_command( - ("payload",), - python=sys.executable, - memory_limit_gib=20.0, - report_json=report_path, - ) - assert command[-4:] == ("--report-json", str(report_path), "--", "payload") - - -def test_candidate_probe_compiles_and_links_against_public_sdk() -> None: - compiler = acceptance.shlex.split(os.environ.get("CXX", "c++")) - if not compiler or shutil.which(compiler[0]) is None: - pytest.skip("no C++ compiler is available for the public-SDK smoke test") - run_root = ( - acceptance.PERFORMANCE_ROOT - / "test-native-smoke" - / f"pytest-{os.getpid()}-{uuid.uuid4().hex}" - ) - try: - acceptance._create_workspace_directories(run_root) - sdk_root = acceptance.ROOT / "src" / "pyamplicol" / "_sdk" - metadata = json.loads((sdk_root / "metadata.json").read_text(encoding="utf-8")) - link = json.loads((sdk_root / "link.json").read_text(encoding="utf-8")) - probe = run_root / "candidate-probe" / "fft-gluon-candidate-probe" - probe.parent.mkdir(parents=True, exist_ok=True) - acceptance._run_watched( - ( - *compiler, - "-std=c++17", - "-O3", - "-DNDEBUG", - f"-I{sdk_root / 'include'}", - str(acceptance.PROBE_SOURCE), - "-o", - str(probe), - str(sdk_root / str(metadata["archive"])), - *(f"-l{name}" for name in link.get("system_libraries", [])), - *( - token - for name in link.get("frameworks", []) - for token in ("-framework", str(name)) - ), - *acceptance._candidate_probe_executable_link_flags(sys.platform), - ), - python=sys.executable, - environment=acceptance._workspace_environment(sys.executable), - timeout_seconds=600.0, - log_path=run_root / "logs" / "candidate-probe-build.json", - ) - assert probe.is_file() - assert metadata["abi_version"] == 1 - finally: - shutil.rmtree(run_root, ignore_errors=True) - - -@pytest.mark.parametrize( - ("platform_name", "expected"), - ( - ( - "darwin", - ("-Wl,-dead_strip", "-Wl,-no_exported_symbols"), - ), - ("linux", ()), - ("win32", ()), - ), -) -def test_candidate_probe_executable_link_flags_are_darwin_scoped( - platform_name: str, - expected: tuple[str, ...], -) -> None: - assert acceptance._candidate_probe_executable_link_flags(platform_name) == expected - - -def _mock_performance_campaign_dependencies( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - *, - recurrence_warm: float, - otf_warm: float = 0.1, -) -> tuple[Path, list[tuple[str, int]]]: - performance_root = tmp_path / "performance" - source_identity = acceptance.ReportSourceIdentity("a" * 40, "b" * 40, ()) - calls: list[tuple[str, int]] = [] - monkeypatch.setattr(acceptance, "PERFORMANCE_ROOT", performance_root) - monkeypatch.setattr( - acceptance, - "_require_campaign_source_identity", - lambda _expected=None: source_identity, - ) - reference_source_identity = acceptance.ReferenceSourceIdentity( - acceptance.REFERENCE_REVISION, "c" * 64, 4 - ) - monkeypatch.setattr( - acceptance, - "_require_reference_source_identity", - lambda _expected=None: reference_source_identity, - ) - monkeypatch.setattr(acceptance, "_workspace_environment", lambda _python: {}) - monkeypatch.setattr( - acceptance, - "_enforce_one_core", - lambda _platform: {"requested_cpu_cores": 1}, - ) - monkeypatch.setattr( - acceptance, - "_build_probe", - lambda **_kwargs: ( - tmp_path / "probe", - {"target": "test-target", "package_version": "test-version"}, - ), - ) - monkeypatch.setattr(acceptance, "_load_reference_module", object) - - def fake_reference(**kwargs: object) -> acceptance._ReferenceRun: - total_gluons = int(kwargs["total_gluons"]) - calls.append(("reference", total_gluons)) - return acceptance._ReferenceRun( - metrics=_reference(total_gluons), - event_paths=tuple( - tmp_path / f"N{total_gluons}-point-{point}.event" for point in range(10) - ), - ) - - def fake_candidate(**kwargs: object) -> acceptance.CandidateMetrics: - lane = str(kwargs["lane"]) - total_gluons = int(kwargs["total_gluons"]) - calls.append((lane, total_gluons)) - return _candidate( - lane, - total_gluons, - recurrence_warm if lane == "recurrence" else otf_warm, - ) - - monkeypatch.setattr(acceptance, "_run_reference", fake_reference) - monkeypatch.setattr(acceptance, "_run_candidate", fake_candidate) - return performance_root, calls - - -def test_campaign_stops_after_first_dispositive_mandatory_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - performance_root, calls = _mock_performance_campaign_dependencies( - tmp_path, - monkeypatch, - recurrence_warm=2.0, - otf_warm=2.0, - ) - arguments = acceptance._parser().parse_args(("--run-id", "early-mandatory-failure")) - - result = acceptance._campaign(arguments) - - assert calls == [("reference", 4), ("recurrence", 4), ("on-the-fly", 4)] - assert result["status"] == "failed-performance-gates" - assert result["terminal"] is True - assert result["passes"] is False - assert result["dry_run"] is False - assert result["policy"]["dry_run"] is False - assert ( - result["source_identity"] - == acceptance.ReportSourceIdentity("a" * 40, "b" * 40, ()).provenance() - ) - assert ( - result["reference_source_identity"] - == acceptance.ReferenceSourceIdentity( - acceptance.REFERENCE_REVISION, "c" * 64, 4 - ).provenance() - ) - assert result["failure"]["kind"] == "no-global-lane-remains" - viability = result["observed_gate_viability"] - assert viability["completed_multiplicities"] == [4] - assert viability["viable_lanes"] == [] - assert viability["lanes"]["recurrence"]["eligible"] is True - assert viability["lanes"]["recurrence"]["viable"] is False - recurrence_gate = viability["lanes"]["recurrence"]["gates"][0] - assert recurrence_gate["warm_passes"] is False - assert recurrence_gate["rss_passes"] is True - assert recurrence_gate["cold_passes"] is True - report = json.loads( - ( - performance_root / "runs" / "early-mandatory-failure" / "report.json" - ).read_text(encoding="utf-8") - ) - assert report == json.loads(json.dumps(result)) - - -def test_campaign_keeps_running_when_only_otf_remains_viable( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _performance_root, calls = _mock_performance_campaign_dependencies( - tmp_path, - monkeypatch, - recurrence_warm=2.0, - otf_warm=0.1, - ) - arguments = acceptance._parser().parse_args(("--run-id", "otf-survives")) - - result = acceptance._campaign(arguments) - - expected_calls = [ - call - for total in acceptance.MANDATORY_MULTIPLICITIES - for call in ( - ("reference", total), - ("recurrence", total), - ("on-the-fly", total), - ) - ] - assert calls == expected_calls - assert result["status"] == "complete" - assert result["passes"] is True - assert result["global_winning_lane"] == "on-the-fly" - assert {gate["lane"] for gate in result["gates"]} == {"on-the-fly"} - - -def test_campaign_uses_one_stable_winner_for_every_mandatory_row( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - _performance_root, calls = _mock_performance_campaign_dependencies( - tmp_path, - monkeypatch, - recurrence_warm=0.5, - otf_warm=1.0, - ) - arguments = acceptance._parser().parse_args(("--run-id", "stable-winner")) - - result = acceptance._campaign(arguments) - - assert len(calls) == 3 * len(acceptance.MANDATORY_MULTIPLICITIES) - assert result["status"] == "complete" - assert result["passes"] is True - assert result["global_winning_lane"] == "recurrence" - assert [gate["total_gluons"] for gate in result["gates"]] == list( - acceptance.MANDATORY_MULTIPLICITIES - ) - assert {gate["lane"] for gate in result["gates"]} == {"recurrence"} - - -def test_campaign_source_preflight_rejects_dirty_tracked_inputs( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - def reject_source(_root: Path) -> acceptance.ReportSourceIdentity: - raise acceptance.ReportSourceIdentityError( - "dirty source paths: tools/developer/fft_gluon_performance_acceptance.py" - ) - - monkeypatch.setattr(acceptance, "require_eligible_report_source", reject_source) - monkeypatch.setattr(acceptance, "PERFORMANCE_ROOT", tmp_path / "performance") - monkeypatch.setattr( - acceptance, - "_create_workspace_directories", - lambda _root: pytest.fail("dirty source must fail before workspace creation"), - ) - arguments = acceptance._parser().parse_args(("--run-id", "dirty-source")) - - with pytest.raises(acceptance.AcceptanceError, match="dirty source paths"): - acceptance._campaign(arguments) - - -def test_campaign_source_postflight_rejects_head_change( - monkeypatch: pytest.MonkeyPatch, -) -> None: - started = acceptance.ReportSourceIdentity("a" * 40, "b" * 40, ()) - changed = acceptance.ReportSourceIdentity("c" * 40, "d" * 40, ()) - monkeypatch.setattr( - acceptance, - "require_eligible_report_source", - lambda _root: changed, - ) - - with pytest.raises(acceptance.AcceptanceError, match="identity changed"): - acceptance._require_campaign_source_identity(started) - - -def _git(repository: Path, *arguments: str) -> str: - return subprocess.run( - ("git", "-C", str(repository), *arguments), - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - -def test_reference_source_identity_allows_dirty_inputs_and_detects_changes( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repository = tmp_path / "reference" - repository.mkdir() - subprocess.run( - ("git", "init", "--quiet", str(repository)), - check=True, - capture_output=True, - text=True, - ) - (repository / ".gitignore").write_text("ignored.tmp\n", encoding="utf-8") - (repository / "tracked.txt").write_text("committed\n", encoding="utf-8") - _git(repository, "add", ".gitignore", "tracked.txt") - _git( - repository, - "-c", - "user.name=FFT acceptance", - "-c", - "user.email=fft-acceptance@example.invalid", - "commit", - "--quiet", - "-m", - "fixture", - ) - revision = _git(repository, "rev-parse", "HEAD") - monkeypatch.setattr(acceptance, "REFERENCE_ROOT", repository) - monkeypatch.setattr(acceptance, "REFERENCE_REVISION", revision) - - # Intentional tracked and nonignored-untracked patches are authenticated, - # not rejected for making the reference checkout dirty. - (repository / "tracked.txt").write_text("intentional patch\n", encoding="utf-8") - (repository / "extra.txt").write_text("campaign input\n", encoding="utf-8") - started = acceptance._require_reference_source_identity() - assert started.revision == revision - assert started.file_count == 3 - assert acceptance._require_reference_source_identity(started) == started - - # Ignored build products are deliberately outside the source identity. - (repository / "ignored.tmp").write_text("build output\n", encoding="utf-8") - assert acceptance._require_reference_source_identity(started) == started - - (repository / "extra.txt").write_text("changed campaign input\n", encoding="utf-8") - with pytest.raises(acceptance.AcceptanceError, match="identity changed"): - acceptance._require_reference_source_identity(started) - - -def test_reference_source_identity_requires_the_locked_revision( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - assert acceptance.REFERENCE_REVISION == "9c3cb4fb4658200884553bab796e85bd5e7fe7a9" - repository = tmp_path / "reference" - repository.mkdir() - subprocess.run( - ("git", "init", "--quiet", str(repository)), - check=True, - capture_output=True, - text=True, - ) - (repository / "input.txt").write_text("input\n", encoding="utf-8") - _git(repository, "add", "input.txt") - _git( - repository, - "-c", - "user.name=FFT acceptance", - "-c", - "user.email=fft-acceptance@example.invalid", - "commit", - "--quiet", - "-m", - "fixture", - ) - monkeypatch.setattr(acceptance, "REFERENCE_ROOT", repository) - - with pytest.raises(acceptance.AcceptanceError, match="wrong revision"): - acceptance._require_reference_source_identity() diff --git a/pyamplicol/tests/unit/test_fft_madgraph_selected_runtime.py b/pyamplicol/tests/unit/test_fft_madgraph_selected_runtime.py deleted file mode 100644 index e152e23a0b..0000000000 --- a/pyamplicol/tests/unit/test_fft_madgraph_selected_runtime.py +++ /dev/null @@ -1,1728 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import hashlib -import json -import math -import shutil -import subprocess -import sys -from pathlib import Path - -import pytest - -from tools.developer import fft_madgraph_selected_runtime as madgraph - - -def _event_text( - family: str, - n: int, - point: int, - helicity: tuple[int, ...], -) -> str: - header = ( - f"AMPLIGLUON_EVENT_V1\nFINAL_GLUONS {n}\nSTRONG_COUPLING 1.0\n" - if family == "gg" - else "PYAMPLICOL_SCALING_EVENT_V1\n" - ) - momenta = "\n".join( - f"{point + index}.0 {index + 1}.0 0.0 0.0" - for index in range(n + 2) - ) - return ( - f"{header}BEGIN_MOMENTA\n{momenta}\nEND_MOMENTA\n" - "NHELICITIES 1\nBEGIN_HELICITIES\n" - f"{' '.join(str(value) for value in helicity)}\n" - "END_HELICITIES\n" - ) - - -def _source_cell( - *, - family: str, - mode: str, - n: int, - helicity: tuple[int, ...], - event_paths: tuple[Path, ...], -) -> dict[str, object]: - return { - "family": family, - "mode": mode, - "n": n, - "total_external": n + 2, - "process": madgraph.process_expression(family, n), - "status": "measured", - "label": f"test {family} {mode} n={n}", - "helicity_workload": "fixed", - "warm_fixed_helicity": True, - "warm_helicity_sum": False, - "helicity": list(helicity), - "event_paths": [str(path) for path in event_paths], - "point_values": [float(point) for point in range(1, 11)], - } - - -def _make_source_report(root: Path) -> Path: - events_root = root / "events" - cells: dict[str, dict[str, dict[str, dict[str, object]]]] = { - "gg": {"reference-fft": {}, "recurrence-fft": {}}, - "ddbar": {"recurrence-fft": {}}, - } - for family in madgraph.FAMILIES: - modes = tuple(cells[family]) - for n in madgraph.FINAL_MULTIPLICITIES: - helicity = tuple( - 1 if family == "gg" or index % 2 else -1 - for index in range(n + 2) - ) - event_directory = events_root / family / f"n{n}" - event_directory.mkdir(parents=True) - event_paths: list[Path] = [] - for point in range(1, madgraph.POINT_COUNT + 1): - event = event_directory / f"point-{point:02d}.event" - event.write_text( - _event_text(family, n, point, helicity), - encoding="utf-8", - ) - event_paths.append(event) - for mode in modes: - cells[family][mode][str(n)] = _source_cell( - family=family, - mode=mode, - n=n, - helicity=helicity, - event_paths=tuple(event_paths), - ) - report = root / "source-report.json" - report.write_text( - json.dumps( - { - "kind": madgraph.SOURCE_KIND, - "schema_version": 1, - "policy": { - "measurement": { - "alpha_s": 0.118, - "helicity_workload": "fixed", - "warm_fixed_helicity": True, - "warm_helicity_sum": False, - } - }, - "cells": cells, - } - ), - encoding="utf-8", - ) - return report - - -@pytest.fixture(scope="module") -def source_report(tmp_path_factory: pytest.TempPathFactory) -> Path: - return _make_source_report(tmp_path_factory.mktemp("madgraph-source")) - - -@pytest.fixture(scope="module") -def matrix_source(tmp_path_factory: pytest.TempPathFactory) -> Path: - path = tmp_path_factory.mktemp("madgraph-matrix") / "matrix.f" - path.write_text( - """ REAL*8 FUNCTION MATRIX(P,NHEL,IC) - INTEGER NEXTERNAL - PARAMETER (NEXTERNAL=4) - INTEGER NHEL(NEXTERNAL) - INTEGER NGRAPHS - PARAMETER (NGRAPHS=3) - INTEGER NCOLOR - PARAMETER (NCOLOR=2) - MATRIX=1D0 - END - SUBROUTINE SMATRIX(P,ANS) - INTEGER NCOMB - PARAMETER (NCOMB=16) - INTEGER NHEL(NEXTERNAL,NCOMB) - INTEGER IDEN - DATA IDEN/512/ - ANS=1D0 - ANS=ANS/DBLE(IDEN) - END -""", - encoding="utf-8", - ) - return path - - -def test_publication_process_grid_is_final_state_n2_through_n9() -> None: - assert tuple(range(2, 10)) == madgraph.FINAL_MULTIPLICITIES - assert madgraph.process_expression("gg", 2) == "g g > g g" - assert madgraph.process_expression("gg", 9) == "g g > g g g g g g g g g" - assert madgraph.process_expression("ddbar", 2) == "d d~ > d d~" - assert madgraph.process_expression("ddbar", 9) == "d d~ > d d~ g g g g g g g" - with pytest.raises(madgraph.SelectedMadGraphError, match="unsupported"): - madgraph.process_expression("qq", 2) - with pytest.raises(madgraph.SelectedMadGraphError, match="unsupported"): - madgraph.process_expression("gg", 1) - assert madgraph.process_expression("gg", 10).endswith("g g g g g g g g") - - -def test_cli_requires_explicit_source_report_and_madgraph_installation( - tmp_path: Path, -) -> None: - common = ( - "--cache-dir", - str(tmp_path / "cache"), - "--output", - str(tmp_path / "report.json"), - ) - with pytest.raises(SystemExit): - madgraph._parser().parse_args(common) - with pytest.raises(SystemExit): - madgraph._parser().parse_args( - (*common, "--source-report", str(tmp_path / "source.json")) - ) - with pytest.raises(SystemExit): - madgraph._parser().parse_args( - (*common, "--mg5-root", str(tmp_path / "mg5")) - ) - - arguments = madgraph._parser().parse_args( - ( - *common, - "--source-report", - str(tmp_path / "source.json"), - "--mg5-root", - str(tmp_path / "mg5"), - ) - ) - assert arguments.source_report == tmp_path / "source.json" - assert arguments.mg5_root == tmp_path / "mg5" - assert arguments.target_seconds == madgraph.TARGET_SECONDS - - -def test_source_selection_authenticates_both_families_and_all_points( - source_report: Path, -) -> None: - source = madgraph.load_source_selection(source_report) - assert source.alpha_s == 0.118 - assert set(source.cells) == {"gg", "ddbar"} - assert set(source.cells["gg"]) == set(range(2, 10)) - assert set(source.cells["ddbar"]) == set(range(2, 10)) - assert source.unavailable == {"gg": {}, "ddbar": {}} - assert source.cells["gg"][2].source_mode == "reference-fft" - assert source.cells["ddbar"][2].source_mode == "recurrence-fft" - - for family in madgraph.FAMILIES: - for n in madgraph.FINAL_MULTIPLICITIES: - cell = source.cells[family][n] - assert cell.process == madgraph.process_expression(family, n) - assert len(cell.helicity) == n + 2 - assert len(cell.events) == madgraph.POINT_COUNT - assert len(cell.reference_point_values) == madgraph.POINT_COUNT - assert len({event.sha256 for event in cell.events}) == 10 - assert all(event.helicity == cell.helicity for event in cell.events) - - assert source.cells["gg"][2].events[0].strong_coupling == 1.0 - assert source.cells["ddbar"][2].events[0].strong_coupling == pytest.approx( - math.sqrt(4.0 * math.pi * source.alpha_s) - ) - - -def test_source_selection_can_authenticate_one_family( - source_report: Path, -) -> None: - source = madgraph.load_source_selection( - source_report, multiplicities=(2,), families=("gg",) - ) - - assert set(source.cells) == {"gg"} - assert set(source.unavailable) == {"gg"} - assert set(source.cells["gg"]) == {2} - assert source.cells["gg"][2].process == "g g > g g" - - -def test_source_selection_rejects_changed_event_helicity( - tmp_path: Path, - source_report: Path, -) -> None: - payload = json.loads(source_report.read_text(encoding="utf-8")) - payload["cells"]["ddbar"]["recurrence-fft"]["2"]["helicity"][0] *= -1 - report = tmp_path / "source.json" - report.write_text(json.dumps(payload), encoding="utf-8") - with pytest.raises(madgraph.SelectedMadGraphError, match="event helicities"): - madgraph.load_source_selection(report) - - -def test_source_selection_rejects_duplicate_event_payloads(tmp_path: Path) -> None: - report = _make_source_report(tmp_path) - payload = json.loads(report.read_text(encoding="utf-8")) - paths = payload["cells"]["gg"]["reference-fft"]["2"]["event_paths"] - Path(paths[1]).write_bytes(Path(paths[0]).read_bytes()) - with pytest.raises(madgraph.SelectedMadGraphError, match="unique event payloads"): - madgraph.load_source_selection(report, multiplicities=(2,)) - - -def _summed_source_report(tmp_path: Path, source_report: Path) -> Path: - payload = json.loads(source_report.read_text(encoding="utf-8")) - measurement = payload["policy"]["measurement"] - measurement.update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - } - ) - for family in madgraph.FAMILIES: - mode = madgraph.SUM_SOURCE_MODE[family] - for cell in payload["cells"][family][mode].values(): - cell.update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - } - ) - report = tmp_path / "summed-source.json" - report.write_text(json.dumps(payload), encoding="utf-8") - return report - - -def test_summed_source_uses_candidate_convention_and_native_smatrix( - tmp_path: Path, - source_report: Path, -) -> None: - source = madgraph.load_source_selection( - _summed_source_report(tmp_path, source_report), - multiplicities=(2,), - helicity_workload="sum", - ) - assert source.helicity_workload == "sum" - assert source.cells["gg"][2].source_mode == "recurrence-fft" - assert source.cells["ddbar"][2].source_mode == "recurrence-fft" - - body = madgraph.render_check_source( - source.cells["gg"][2], summed_helicity_coverage_count=16 - ) - compact = body.replace(" ", "") - assert body.count("CALL SMATRIX(") == 3 - assert "USERHEL=-1" in compact - assert "MATRIX(P(0,1,E),HEL,IC)" not in body - assert f"ASVALUE={madgraph._fortran_double(source.alpha_s)}" in body - assert "HELICITY_COVERAGE_COUNT" in body - - parsed = madgraph.parse_driver_output( - _driver_output(helicity_workload="sum"), - batches=madgraph.TIMING_DRIVER_BATCH_COUNT, - expected_total_external=4, - expected_events=10, - helicity_workload="sum", - expected_helicity_coverage_count=16, - ) - assert parsed.evaluations_per_sweep == 1 - assert parsed.helicity_coverage_count == 16 - - -def test_rendered_check_fixes_only_timing_helicity_and_calls_direct_matrix( - source_report: Path, -) -> None: - source = madgraph.load_source_selection(source_report) - for family, n in (("gg", 2), ("ddbar", 9)): - cell = source.cells[family][n] - body = madgraph.render_check_source(cell) - assert "SMATRIX" not in body.upper() - assert "MATRIX(P(0,1,E),HEL,IC)" in body - assert "MATRIX(P(0,1,1),HEL,IC)" in body - assert "CALL SETPARA('../../Cards/param_card.dat')" in body - assert "CALL UPDATE_AS_PARAM2(1D0,ASVALUE)" in body - assert "CALL SYSTEM_CLOCK(CLOCK0,CLOCKRATE)" in body - assert "DBLE(CLOCK1-CLOCK0)/DBLE(CLOCKRATE)" in body - assert f"DATA HEL /{','.join(str(value) for value in cell.helicity)}/" in body - assert f"PARAMETER (NSAMPLES={madgraph.TIMING_DRIVER_BATCH_COUNT})" in body - assert max(map(len, body.splitlines())) <= 132 - - -def _driver_output( - *, - total_external: int = 4, - batches: int = madgraph.TIMING_DRIVER_BATCH_COUNT, - point_values: tuple[float, ...] | None = None, - initialization_seconds: float = 1.0e-3, - helicity_workload: str = "fixed", -) -> str: - points = point_values or tuple(float(index) for index in range(1, 11)) - lines = [ - ( - "BACKEND MadGraph5_aMCatNLOHelicitySum" - if helicity_workload == "sum" - else "BACKEND MadGraph5_aMCatNLOFixedHelicity" - ), - ( - "HELICITY_EVALUATOR SMATRIX_GENERATED_COMPLETE_HELICITY_SUM" - if helicity_workload == "sum" - else "HELICITY_EVALUATOR MATRIX_DIRECT_VECTOR" - ), - f"TOTAL_EXTERNAL {total_external}", - f"INITIALIZATION_SECONDS {initialization_seconds:.17e}", - "FIRST_SAMPLE_PASS_SECONDS 2.0D-3", - ] - lines.extend( - f"MATRIX_ELEMENT {index} 1 {value:.17e}" - for index, value in enumerate(points, start=1) - ) - lines.append("EVALUATIONS_PER_SWEEP 1") - lines.append( - "HELICITY_COVERAGE_COUNT " - + (str(2**total_external) if helicity_workload == "sum" else "1") - ) - for batch in range(1, batches + 1): - lines.extend( - ( - f"EVALUATION_SWEEP_SECONDS {batch} {batch}.0D-6", - f"EVALUATION_CELL_SECONDS {batch} 1 1 {batch}.0D-6", - ) - ) - lines.append("CHECKSUM 1.0D+0") - return "\n".join(lines) + "\n" - - -def test_driver_output_requires_ten_points_and_configured_timing_batches() -> None: - parsed = madgraph.parse_driver_output( - _driver_output(), - batches=madgraph.TIMING_DRIVER_BATCH_COUNT, - expected_total_external=4, - expected_events=10, - ) - assert parsed.point_values == tuple(float(index) for index in range(1, 11)) - assert len(parsed.cell_seconds) == madgraph.TIMING_DRIVER_BATCH_COUNT - assert parsed.initialization_seconds == 1.0e-3 - - incomplete = _driver_output().replace( - "EVALUATION_CELL_SECONDS " - f"{madgraph.TIMING_DRIVER_BATCH_COUNT} 1 1 " - f"{madgraph.TIMING_DRIVER_BATCH_COUNT}.0D-6\n", - "", - ) - with pytest.raises(madgraph.SelectedMadGraphError, match="incomplete timing"): - madgraph.parse_driver_output( - incomplete, - batches=madgraph.TIMING_DRIVER_BATCH_COUNT, - expected_total_external=4, - expected_events=10, - ) - - -def test_external_time_command_selects_darwin_and_linux_dialects( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(madgraph.platform, "system", lambda: "Darwin") - monkeypatch.setattr( - madgraph.Path, - "is_file", - lambda path: str(path) == "/usr/bin/time", - ) - assert madgraph._external_time_command(("probe", "argument")) == [ - "/usr/bin/time", - "-l", - "probe", - "argument", - ] - - monkeypatch.setattr(madgraph.platform, "system", lambda: "Linux") - monkeypatch.setattr(madgraph.shutil, "which", lambda name: f"/opt/bin/{name}") - assert madgraph._external_time_command(("probe",)) == [ - "/opt/bin/time", - "-v", - "probe", - ] - - -def test_external_time_command_falls_back_to_watchdog_only( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(madgraph.platform, "system", lambda: "Linux") - monkeypatch.setattr(madgraph.shutil, "which", lambda _name: None) - assert madgraph._external_time_command(("probe", "argument")) == [ - "probe", - "argument", - ] - - monkeypatch.setattr(madgraph.platform, "system", lambda: "FreeBSD") - assert madgraph._external_time_command(("probe",)) == ["probe"] - - -@pytest.mark.parametrize( - ("system", "stderr", "expected_kib"), - ( - ("Darwin", " 1048577 maximum resident set size\n", 1025), - ( - "Linux", - "\tMaximum resident set size (kbytes): 123456\n", - 123456, - ), - ("FreeBSD", "123 maximum resident set size\n", None), - ), -) -def test_external_time_max_rss_parsers( - monkeypatch: pytest.MonkeyPatch, - system: str, - stderr: str, - expected_kib: int | None, -) -> None: - monkeypatch.setattr(madgraph.platform, "system", lambda: system) - assert madgraph._parse_time_max_rss(stderr) == expected_kib - - -def test_generated_matrix_audit_proves_general_helicity_and_direct_vector( - matrix_source: Path, -) -> None: - metadata = madgraph._validate_matrix_source( - matrix_source, family="gg", final_multiplicity=2 - ) - assert metadata["generation_helicity_coverage"] == "all" - assert metadata["generated_helicity_coverage_count"] == 16 - assert metadata["generated_matrix_graphs"] > 0 - assert metadata["colour_flows"] > 0 - assert metadata["smatrix_iden"] == 512 - assert metadata["matrix_sha256"] == hashlib.sha256( - matrix_source.read_bytes() - ).hexdigest() - - -def test_generated_matrix_audit_rejects_missing_duplicate_or_wrong_iden( - tmp_path: Path, - matrix_source: Path, -) -> None: - fixture = matrix_source.read_text(encoding="utf-8") - variants = { - "missing": fixture.replace(" DATA IDEN/512/\n", ""), - "comment-only": fixture.replace( - " DATA IDEN/512/", - "C DATA IDEN/512/", - ), - "duplicate": fixture.replace( - " DATA IDEN/512/\n", - " DATA IDEN/512/\n DATA IDEN/512/\n", - ), - "wrong": fixture.replace(" DATA IDEN/512/", " DATA IDEN/513/"), - } - for name, source in variants.items(): - path = tmp_path / f"{name}.f" - path.write_text(source, encoding="utf-8") - with pytest.raises( - madgraph.SelectedMadGraphError, - match="IDEN denominator", - ): - madgraph._validate_matrix_source(path, family="gg", final_multiplicity=2) - - -@pytest.mark.parametrize( - ("replacement", "message"), - ( - ("PARAMETER (NCOMB=8)", "complete-helicity coverage"), - ("INTEGER NHEL(NEXTERNAL,16)", "NHEL\\(NEXTERNAL,NCOMB\\)"), - ), -) -def test_generated_matrix_audit_requires_exact_ncomb_nhel_coverage( - tmp_path: Path, - matrix_source: Path, - replacement: str, - message: str, -) -> None: - fixture = matrix_source.read_text(encoding="utf-8") - original = ( - "PARAMETER (NCOMB=16)" - if replacement.startswith("PARAMETER") - else "INTEGER NHEL(NEXTERNAL,NCOMB)" - ) - path = tmp_path / "bad-coverage.f" - path.write_text(fixture.replace(original, replacement), encoding="utf-8") - with pytest.raises(madgraph.SelectedMadGraphError, match=message): - madgraph._validate_matrix_source(path, family="gg", final_multiplicity=2) - - -def test_generated_matrix_audit_requires_executable_smatrix_iden_use( - tmp_path: Path, - matrix_source: Path, -) -> None: - fixture = matrix_source.read_text(encoding="utf-8") - statement = " ANS=ANS/DBLE(IDEN)" - variants = { - "missing": fixture.replace(f"{statement}\n", ""), - "commented": fixture.replace(statement, "C ANS=ANS/DBLE(IDEN)"), - "duplicate": fixture.replace( - f"{statement}\n", - f"{statement}\n{statement}\n", - ), - } - for name, source in variants.items(): - path = tmp_path / f"{name}.f" - path.write_text(source, encoding="utf-8") - with pytest.raises( - madgraph.SelectedMadGraphError, - match="does not apply its IDEN denominator exactly once", - ): - madgraph._validate_matrix_source(path, family="gg", final_multiplicity=2) - - -def test_numerical_convention_map_is_fixed_not_fitted() -> None: - assert madgraph._expected_smatrix_iden("gg", 2) == 512 - assert madgraph._expected_smatrix_iden("ddbar", 2) == 36 - assert madgraph._expected_smatrix_iden("ddbar", 4) == 72 - assert madgraph._expected_smatrix_iden("ddbar", 5) == 216 - assert madgraph._numerical_normalization_factor("gg", smatrix_iden=512) == 1.0 - assert ( - madgraph._numerical_normalization_factor("ddbar", smatrix_iden=36) == 1.0 / 36.0 - ) - assert ( - madgraph._numerical_normalization_factor("ddbar", smatrix_iden=72) == 1.0 / 72.0 - ) - with pytest.raises(madgraph.SelectedMadGraphError, match="unsupported"): - madgraph._numerical_normalization_factor("bad", smatrix_iden=1) - with pytest.raises(madgraph.SelectedMadGraphError, match="positive"): - madgraph._numerical_normalization_factor("ddbar", smatrix_iden=0) - - -def test_watchdog_resource_uses_conservative_peak_guard() -> None: - report = { - "passes": True, - "execution": {"elapsed_wall_seconds": 2.5, "outcome": "command-finished"}, - "enforcement": { - "peak_guard_bytes": 2049, - "peak_rss_bytes": 1024, - "peak_physical_footprint_bytes": 2049, - "metric": "max(process-tree-rss,darwin-process-tree-physical-footprint)", - "limit_bytes": 30 * 1024**3, - }, - } - resource = madgraph._watchdog_resource(report) - assert resource["elapsed_wall_seconds"] == 2.5 - assert resource["peak_guard_kib"] == 3 - assert resource["passes"] is True - - -def test_disk_exhaustion_is_infrastructure_not_physics_frontier() -> None: - assert madgraph._is_disk_exhaustion(OSError(28, "No space left on device")) - assert madgraph._is_disk_exhaustion("No space left on device") - assert not madgraph._is_disk_exhaustion("generation reached memory limit") - - -def test_time_and_memory_limits_are_strict_publication_caps() -> None: - assert madgraph.DEFAULT_GENERATION_TIMEOUT_SECONDS < 3600.0 - assert madgraph.MAX_MEMORY_GIB == 30.0 - assert madgraph.TARGET_SECONDS == 180.0 - assert madgraph.WARM_SAMPLE_COUNT == 1 - - -def test_hidden_timeout_worker_propagates_exit_and_terminates_late_child() -> None: - assert ( - madgraph.main( - [ - "_run-with-timeout", - "--timeout-seconds", - "1", - "--", - sys.executable, - "-c", - "raise SystemExit(7)", - ] - ) - == 7 - ) - assert ( - madgraph.main( - [ - "_run-with-timeout", - "--timeout-seconds", - "0.01", - "--", - sys.executable, - "-c", - "import time; time.sleep(10)", - ] - ) - == 124 - ) - - -def test_generation_worker_runs_madgraph_with_current_python( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - fake_bin = tmp_path / "fake-bin" - fake_bin.mkdir() - fake_python = fake_bin / "python3" - fake_python.write_text("#!/bin/sh\nexit 93\n", encoding="ascii") - fake_python.chmod(0o755) - monkeypatch.setenv("PATH", str(fake_bin)) - - mg5_root = tmp_path / "mg5" - (mg5_root / "bin").mkdir(parents=True) - (mg5_root / "VERSION").write_text("test-version\n", encoding="ascii") - mg5 = mg5_root / "bin" / "mg5_aMC" - mg5.write_text( - """#!/usr/bin/env python3 -import sys -from pathlib import Path - -card = Path(sys.argv[1]) -output = None -for line in card.read_text(encoding="utf-8").splitlines(): - if line.startswith("output standalone "): - output = Path(line.removeprefix("output standalone ").rsplit(" -f", 1)[0]) -if output is None: - raise SystemExit(2) -process = output / "SubProcesses" / "P0_test" -process.mkdir(parents=True) -(process / "matrix.f").write_text(" REAL*8 FUNCTION MATRIX()\\n END\\n") -""", - encoding="ascii", - ) - mg5.chmod(0o755) - - cell_dir = tmp_path / "gg" / "n2" - result = cell_dir / "generation-attempts" / "attempt-001" / "result.json" - result.parent.mkdir(parents=True) - arguments = madgraph._worker_parser().parse_args( - [ - "--mg5-root", - str(mg5_root), - "--generated-output", - str(cell_dir / "generated"), - "--worker-result", - str(result), - "--process", - "g g > g g", - "--generation-timeout-seconds", - "10", - ] - ) - - assert madgraph._generation_worker(arguments) == 0 - payload = json.loads(result.read_text(encoding="utf-8")) - - assert payload["status"] == "measured" - assert payload["returncode"] == 0 - assert payload["process_dirs"] == [ - str(cell_dir / "generated" / "SubProcesses" / "P0_test") - ] - - -def test_bounded_command_uses_current_python_for_timeout_wrapper( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - calls: list[list[str]] = [] - - def watchdog( - command: list[str], *, cwd: Path, report: Path, limit_gib: float - ) -> subprocess.CompletedProcess[str]: - del cwd, limit_gib - calls.append(command) - report.write_text(json.dumps(_watchdog_report(elapsed=1.0)), encoding="utf-8") - return subprocess.CompletedProcess(command, 0, "stdout", "stderr") - - monkeypatch.setattr(madgraph, "_run_watchdog", watchdog) - - madgraph._run_bounded_command( - ["probe"], - cwd=tmp_path, - report=tmp_path / "watchdog.json", - limit_gib=1.0, - timeout_seconds=5.0, - ) - - wrapper_index = calls[0].index(sys.executable) - assert calls[0][wrapper_index:] == [ - sys.executable, - str(Path(madgraph.__file__).resolve()), - "_run-with-timeout", - "--timeout-seconds", - "5", - "--", - "probe", - ] - - -def _watchdog_report(*, elapsed: float, peak_kib: int = 1024) -> dict[str, object]: - return { - "passes": True, - "execution": { - "elapsed_wall_seconds": elapsed, - "outcome": "command-finished", - }, - "enforcement": { - "peak_guard_bytes": peak_kib * 1024, - "peak_rss_bytes": peak_kib * 1024, - "peak_physical_footprint_bytes": peak_kib * 1024, - "metric": "process-tree-rss", - "limit_bytes": 30 * 1024**3, - }, - } - - -def test_timeout_frontier_requires_authenticated_wrapper_marker() -> None: - natural_124 = subprocess.CompletedProcess([], 124, "", "child failed") - timed_out = subprocess.CompletedProcess( - [], 124, "", f"prefix\n{madgraph.TIMEOUT_MARKER}\nsuffix" - ) - assert not madgraph._bounded_command_timed_out(natural_124) - assert madgraph._bounded_command_timed_out(timed_out) - - -def test_measurement_runtime_consumes_remaining_cold_budget( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, - matrix_source: Path, -) -> None: - source = madgraph.load_source_selection(source_report) - selected = source.cells["gg"][2] - cell_dir = tmp_path / "gg" / "n2" - process_dir = cell_dir / "generated" / "SubProcesses" / "P1_test" - process_dir.mkdir(parents=True) - shutil.copy2(matrix_source, process_dir / "matrix.f") - (process_dir / "makefile").write_text("check:\n\t@true\n", encoding="ascii") - mg5_root = tmp_path / "mg5" - mg5_root.mkdir() - (mg5_root / "VERSION").write_text("test-version\n", encoding="ascii") - calls: list[tuple[list[str], float | None, Path]] = [] - - def bounded( - command: list[str], - *, - cwd: Path, - report: Path, - limit_gib: float, - timeout_seconds: float | None = None, - ) -> tuple[subprocess.CompletedProcess[str], dict[str, object]]: - del limit_gib - calls.append((list(command), timeout_seconds, report)) - if command[0] == "make": - executable = cwd / "check" - executable.write_bytes(b"test executable") - executable.chmod(0o755) - return ( - subprocess.CompletedProcess(command, 0, "", ""), - _watchdog_report(elapsed=2.0, peak_kib=2000), - ) - return ( - subprocess.CompletedProcess( - command, - 0, - _driver_output( - point_values=selected.reference_point_values, - initialization_seconds=1.0, - ), - "", - ), - _watchdog_report(elapsed=3.0, peak_kib=3000), - ) - - monkeypatch.setattr(madgraph, "_run_bounded_command", bounded) - cell = madgraph._measure_generated_cell( - source=source, - selected=selected, - generation={ - "output": str(cell_dir / "generated"), - "process_dirs": [str(process_dir)], - }, - generation_watchdog=_watchdog_report(elapsed=5.0, peak_kib=1000), - cell_dir=cell_dir, - fc="gfortran", - fflags="-O3", - make="make", - limit_gib=30.0, - mg5_root=mg5_root, - cold_to_ready_limit_seconds=20.0, - ) - assert [call[1] for call in calls] == [15.0, 13.0] - assert all( - call[2].parent == cell_dir / "measurement-attempts" / "attempt-001" - for call in calls - ) - assert cell["metrics"]["generation_seconds"] == 8.0 - assert cell["provenance"]["generation_helicity_coverage"] == "all" - with pytest.raises(madgraph.ResourceFrontierError) as exhausted: - madgraph._remaining_cold_to_ready_budget( - 5.0, madgraph._watchdog_resource(_watchdog_report(elapsed=5.0)) - ) - assert exhausted.value.category == "generation-time-limit" - - -def test_attempt_paths_resume_without_reusing_watchdog_reports(tmp_path: Path) -> None: - cell_dir = tmp_path / "gg" / "n2" - cell_dir.mkdir(parents=True) - first = madgraph._new_attempt_directory(cell_dir, "measurement") - (first / "build-watchdog.json").write_text("{}\n", encoding="ascii") - (first / "runtime-watchdog.json").write_text("{}\n", encoding="ascii") - second = madgraph._new_attempt_directory(cell_dir, "measurement") - assert first.name == "attempt-001" - assert second.name == "attempt-002" - assert (first / "build-watchdog.json").is_file() - assert not (second / "build-watchdog.json").exists() - - -def test_cache_lock_survives_cache_tree_replacement( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - lock_root = tmp_path / "locks" - monkeypatch.setattr(madgraph, "CACHE_LOCK_ROOT", lock_root) - run_directory = tmp_path / "run" - cache = run_directory / "madgraph" / "cache" - first = madgraph._acquire_cache_lock(cache) - try: - cache.mkdir(parents=True) - shutil.rmtree(run_directory) - with pytest.raises( - madgraph.SelectedMadGraphError, - match="another MadGraph profiler holds cache lock", - ): - madgraph._acquire_cache_lock(cache) - finally: - first.close() - - resumed = madgraph._acquire_cache_lock(cache) - resumed.close() - assert madgraph._cache_lock_path(cache).parent == lock_root - - -@pytest.mark.parametrize("keep_generated", [False, True]) -def test_checkpoint_resume_safely_prunes_only_cell_generated( - tmp_path: Path, keep_generated: bool -) -> None: - cell_dir = tmp_path / "gg" / "n2" - generated = cell_dir / "generated" - generated.mkdir(parents=True) - sentinel = generated / "sentinel" - sentinel.write_text("owned\n", encoding="ascii") - checkpoint = cell_dir / "cell.json" - identity = {"producer": "test"} - madgraph._json_atomic( - checkpoint, - {"checkpoint_identity": identity, "cell": {"status": "measured"}}, - ) - cell = madgraph._load_checkpoint_cell( - checkpoint, - identity=identity, - cell_dir=cell_dir, - keep_generated=keep_generated, - ) - assert cell["status"] == "measured" - assert generated.exists() is keep_generated - assert tmp_path.exists() - - -@pytest.mark.parametrize("family", madgraph.FAMILIES) -def test_checkpoint_producer_change_requires_fresh_cache( - tmp_path: Path, family: str -) -> None: - cell_dir = tmp_path / family / "n2" - cell_dir.mkdir(parents=True) - checkpoint = cell_dir / "cell.json" - current = { - "producer_sha256": "current-producer", - "family": family, - "n": 2, - "sentinel": "same", - } - madgraph._json_atomic( - checkpoint, - { - "checkpoint_identity": { - **current, - "producer_sha256": "previous-producer", - }, - "cell": { - "status": "failed", - "failure_category": "generation-time-limit", - }, - }, - ) - with pytest.raises( - madgraph.SelectedMadGraphError, - match="checkpoint identity changed", - ): - madgraph._load_checkpoint_cell( - checkpoint, - identity=current, - cell_dir=cell_dir, - keep_generated=True, - ) - - -def test_checkpoint_reuse_ignores_only_unrelated_source_report_expansion( - tmp_path: Path, -) -> None: - cell_dir = tmp_path / "gg" / "n2" - cell_dir.mkdir(parents=True) - checkpoint = cell_dir / "cell.json" - current = { - "producer_sha256": "same-producer", - "source_report_sha256": "expanded-report", - "source_cell_sha256": "same-cell", - "family": "gg", - "n": 2, - } - madgraph._json_atomic( - checkpoint, - { - "checkpoint_identity": { - **current, - "source_report_sha256": "sparse-report", - }, - "cell": {"status": "measured"}, - }, - ) - - assert ( - madgraph._load_checkpoint_cell( - checkpoint, - identity=current, - cell_dir=cell_dir, - keep_generated=True, - )["status"] - == "measured" - ) - - -def test_measured_checkpoint_reuse_ignores_caps_timing_and_legacy_producer( - tmp_path: Path, -) -> None: - cell_dir = tmp_path / "gg" / "n2" - cell_dir.mkdir(parents=True) - checkpoint = cell_dir / "cell.json" - current = { - "checkpoint_protocol": madgraph.CHECKPOINT_PROTOCOL, - "source_report_sha256": "expanded-report", - "source_cell_sha256": "same-cell", - "family": "gg", - "n": 2, - "generation_timeout_seconds": 36000.0, - "memory_limit_gib": 200.0, - "target_seconds": 180.0, - "warm_sample_count": 1, - } - madgraph._json_atomic( - checkpoint, - { - "checkpoint_identity": { - "producer_sha256": "old-script-hash", - "source_report_sha256": "sparse-report", - "source_cell_sha256": "same-cell", - "family": "gg", - "n": 2, - "generation_timeout_seconds": 3600.0, - "memory_limit_gib": 100.0, - "target_seconds": 0.25, - "warm_sample_count": 10, - }, - "cell": {"status": "measured"}, - }, - ) - - assert ( - madgraph._load_checkpoint_cell( - checkpoint, - identity=current, - cell_dir=cell_dir, - keep_generated=True, - )["status"] - == "measured" - ) - - -def test_failed_checkpoint_cap_or_timing_change_is_not_reused( - tmp_path: Path, -) -> None: - cell_dir = tmp_path / "gg" / "n2" - generated = cell_dir / "generated" - generated.mkdir(parents=True) - checkpoint = cell_dir / "cell.json" - current = { - "checkpoint_protocol": madgraph.CHECKPOINT_PROTOCOL, - "source_report_sha256": "expanded-report", - "source_cell_sha256": "same-cell", - "family": "gg", - "n": 2, - "generation_timeout_seconds": 36000.0, - "memory_limit_gib": 200.0, - "target_seconds": 180.0, - "warm_sample_count": 1, - } - madgraph._json_atomic( - checkpoint, - { - "checkpoint_identity": { - "producer_sha256": "old-script-hash", - "source_report_sha256": "sparse-report", - "source_cell_sha256": "same-cell", - "family": "gg", - "n": 2, - "generation_timeout_seconds": 3600.0, - "memory_limit_gib": 100.0, - "target_seconds": 0.25, - "warm_sample_count": 10, - }, - "cell": { - "status": "failed", - "failure_category": "memory-limit", - }, - }, - ) - - assert ( - madgraph._load_checkpoint_cell( - checkpoint, - identity=current, - cell_dir=cell_dir, - keep_generated=False, - ) - is None - ) - assert not generated.exists() - - -def test_generated_cleanup_refuses_symlink_target(tmp_path: Path) -> None: - cell_dir = tmp_path / "gg" / "n2" - cell_dir.mkdir(parents=True) - outside = tmp_path / "outside" - outside.mkdir() - (outside / "sentinel").write_text("preserve\n", encoding="ascii") - (cell_dir / "generated").symlink_to(outside, target_is_directory=True) - with pytest.raises(madgraph.SelectedMadGraphError, match="symlink"): - madgraph._prune_cell_generated(cell_dir) - assert (outside / "sentinel").read_text(encoding="ascii") == "preserve\n" - - -def _fake_mg5_root(tmp_path: Path) -> Path: - root = tmp_path / "mg5" - (root / "bin").mkdir(parents=True) - (root / "bin" / "mg5_aMC").write_text("#!/bin/sh\n", encoding="ascii") - (root / "VERSION").write_text("test-version\n", encoding="ascii") - return root - - -@pytest.mark.parametrize( - "category", - [ - "generation-error", - "generation-launch-error", - "generation-structure-error", - "generation-watchdog-error", - "infrastructure-disk-exhaustion", - ], -) -def test_generation_diagnostics_abort_without_frontier_checkpoint( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, - category: str, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - monkeypatch.setattr(madgraph, "FINAL_MULTIPLICITIES", (2, 3)) - monkeypatch.setattr( - madgraph, - "_generation_attempt", - lambda **_kwargs: ( - { - "status": "failed", - "failure_category": category, - "failure_reason": "diagnostic", - }, - {}, - ), - ) - cache = tmp_path / "cache" - with pytest.raises(madgraph.SelectedMadGraphError, match="diagnostic"): - madgraph.build_runtime_report( - source_report=source_report, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=_fake_mg5_root(tmp_path), - memory_limit_gib=1.0, - ) - assert not (cache / "gg" / "n2" / "cell.json").exists() - - -@pytest.mark.parametrize( - "message", - [ - "generated standalone build failed", - "MadGraph points disagree with reference", - "MadGraph output has incomplete timing cells", - ], -) -def test_measurement_diagnostics_abort_without_frontier_checkpoint( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, - message: str, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - monkeypatch.setattr(madgraph, "FINAL_MULTIPLICITIES", (2, 3)) - monkeypatch.setattr( - madgraph, - "_generation_attempt", - lambda **_kwargs: ({"status": "measured"}, {}), - ) - - def fail_measurement(**_kwargs: object) -> dict[str, object]: - raise madgraph.SelectedMadGraphError(message) - - monkeypatch.setattr(madgraph, "_measure_generated_cell", fail_measurement) - cache = tmp_path / "cache" - with pytest.raises(madgraph.SelectedMadGraphError, match=message): - madgraph.build_runtime_report( - source_report=source_report, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=_fake_mg5_root(tmp_path), - memory_limit_gib=1.0, - ) - assert not (cache / "gg" / "n2" / "cell.json").exists() - - -@pytest.mark.parametrize("category", ["generation-time-limit", "memory-limit"]) -def test_only_resource_failures_create_and_censor_frontier( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, - category: str, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - monkeypatch.setattr(madgraph, "FINAL_MULTIPLICITIES", (2, 3)) - monkeypatch.setattr( - madgraph, - "_generation_attempt", - lambda **_kwargs: ( - { - "status": "failed", - "failure_category": category, - "failure_reason": "resource cap", - }, - {}, - ), - ) - cache = tmp_path / "cache" - report = madgraph.build_runtime_report( - source_report=source_report, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=_fake_mg5_root(tmp_path), - memory_limit_gib=1.0, - ) - n2 = report["runtime_series"]["gg"][madgraph.MODE]["2"] - n3 = report["runtime_series"]["gg"][madgraph.MODE]["3"] - assert n2["status"] == "failed" - assert n2["failure_category"] == category - assert n3["status"] == "skipped" - assert n3["skipped_after_frontier"] is True - - -def test_diagnostic_family_omission_is_not_an_availability_frontier() -> None: - cell = madgraph._diagnostic_skip_cell("gg", 2, "diagnostic") - assert cell["status"] == "skipped" - assert cell["censors_higher_multiplicities"] is False - assert cell["skipped_after_frontier"] is False - assert "availability_frontier_n" not in cell - - -def _measured_stub(**arguments: object) -> dict[str, object]: - selected = arguments["selected"] - source = arguments["source"] - assert isinstance(selected, madgraph.SelectedCell) - assert isinstance(source, madgraph.SourceSelection) - return { - "status": "measured", - "family": selected.family, - "mode": madgraph.MODE, - "label": madgraph.LABEL, - "n": selected.n, - "total_external": selected.total_external, - "process": selected.process, - "helicity_workload": selected.helicity_workload, - "provenance": { - "source_report": { - "path": madgraph._display_path(source.path), - "sha256": source.sha256, - "cell": ( - f"cells.{selected.family}.{selected.source_mode}.{selected.n}" - ), - } - }, - } - - -def _write_source_payload( - tmp_path: Path, payload: dict[str, object], name: str -) -> Path: - path = tmp_path / name - path.write_text(json.dumps(payload), encoding="utf-8") - return path - - -def test_scaling_source_records_dependency_frontier_without_losing_lower_n( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - payload = json.loads(source_report.read_text(encoding="utf-8")) - payload["kind"] = madgraph.SCALING_STUDY_KIND - failed = payload["cells"]["ddbar"]["recurrence-fft"]["3"] - failed.update( - { - "status": "failed", - "failure_category": "memory-limit", - "failure_reason": "source reached its configured RAM cap", - "censors_higher_multiplicities": True, - } - ) - skipped = payload["cells"]["ddbar"]["recurrence-fft"]["4"] - skipped.update( - { - "status": "skipped", - "failure_reason": "skipped after source frontier", - "censors_higher_multiplicities": True, - } - ) - source_path = _write_source_payload(tmp_path, payload, "source.json") - source = madgraph.load_source_selection( - source_path, multiplicities=(2, 3, 4) - ) - assert set(source.cells["ddbar"]) == {2} - assert set(source.unavailable["ddbar"]) == {3, 4} - - monkeypatch.setattr(madgraph, "FAMILIES", ("ddbar",)) - attempted: list[int] = [] - - def generation_attempt(**arguments: object) -> tuple[dict[str, object], dict]: - selected = arguments["selected"] - assert isinstance(selected, madgraph.SelectedCell) - attempted.append(selected.n) - return {"status": "measured"}, {} - - monkeypatch.setattr(madgraph, "_generation_attempt", generation_attempt) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - progress_path = tmp_path / "overlay.progress.json" - report = madgraph.build_runtime_report( - source_report=source_path, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=7200.0, - mg5_root=_fake_mg5_root(tmp_path), - multiplicities=(2, 3, 4), - memory_limit_gib=64.0, - progress_output=progress_path, - ) - - cells = report["runtime_series"]["ddbar"][madgraph.MODE] - assert attempted == [2] - assert cells["2"]["status"] == "measured" - assert cells["3"]["failure_category"] == "dependency-unavailable" - assert cells["4"]["status"] == "skipped" - assert report["policy"]["final_state_multiplicities"] == [2, 3, 4] - assert report["policy"]["generation_timeout_seconds"] == 7200.0 - assert report["policy"]["outer_memory_watchdog_gib"] == 64.0 - progress = madgraph.load_runtime_progress(progress_path) - assert progress["status"] == "complete-with-failures" - assert progress["summary"]["completed_cell_count"] == 3 - assert progress["pending_cells"] == [] - - -def test_scaling_source_non_frontier_failure_does_not_censor_higher_n( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - payload = json.loads(source_report.read_text(encoding="utf-8")) - payload["kind"] = madgraph.SCALING_STUDY_KIND - failed = payload["cells"]["ddbar"]["recurrence-fft"]["3"] - failed.update( - { - "status": "failed", - "failure_category": "error", - "failure_reason": "source diagnostic failed at this cell", - "censors_higher_multiplicities": False, - } - ) - source_path = _write_source_payload(tmp_path, payload, "source.json") - source = madgraph.load_source_selection( - source_path, multiplicities=(2, 3, 4) - ) - assert set(source.cells["ddbar"]) == {2, 4} - assert set(source.unavailable["ddbar"]) == {3} - assert source.unavailable["ddbar"][3].censors_higher_multiplicities is False - - monkeypatch.setattr(madgraph, "FAMILIES", ("ddbar",)) - attempted: list[int] = [] - - def generation_attempt(**arguments: object) -> tuple[dict[str, object], dict]: - selected = arguments["selected"] - assert isinstance(selected, madgraph.SelectedCell) - attempted.append(selected.n) - return {"status": "measured"}, {} - - monkeypatch.setattr(madgraph, "_generation_attempt", generation_attempt) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - report = madgraph.build_runtime_report( - source_report=source_path, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=7200.0, - mg5_root=_fake_mg5_root(tmp_path), - multiplicities=(2, 3, 4), - memory_limit_gib=64.0, - ) - - cells = report["runtime_series"]["ddbar"][madgraph.MODE] - assert attempted == [2, 4] - assert cells["2"]["status"] == "measured" - assert cells["3"]["failure_category"] == "dependency-unavailable" - assert cells["3"]["censors_higher_multiplicities"] is False - assert "availability_frontier_n" not in cells["3"] - assert cells["4"]["status"] == "measured" - - -def test_progress_is_atomic_sparse_and_names_the_current_cell( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - monkeypatch.setattr( - madgraph, - "_generation_attempt", - lambda **_arguments: ({"status": "measured"}, {}), - ) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - progress_path = tmp_path / "overlay.progress.json" - observed: list[dict[str, object]] = [] - original_atomic = madgraph._json_atomic - - def capture_atomic( - path: Path, payload: dict[str, object], *, replace: bool = True - ) -> None: - original_atomic(path, payload, replace=replace) - if path == progress_path.resolve(strict=False): - observed.append(json.loads(json.dumps(payload))) - - monkeypatch.setattr(madgraph, "_json_atomic", capture_atomic) - report = madgraph.build_runtime_report( - source_report=source_report, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=7201.0, - mg5_root=_fake_mg5_root(tmp_path), - multiplicities=(2, 3), - memory_limit_gib=96.0, - progress_output=progress_path, - ) - - current = [entry["current_cell"] for entry in observed if entry["current_cell"]] - assert [(entry["family"], entry["n"]) for entry in current] == [ - ("gg", 2), - ("gg", 3), - ] - completed = [entry["summary"]["completed_cell_count"] for entry in observed] - assert completed[0] == 0 - assert 1 in completed - assert completed[-1] == 2 - progress = madgraph.load_runtime_progress(progress_path) - assert progress["status"] == "complete" - assert progress["policy"]["final_state_multiplicities"] == [2, 3] - assert progress["policy"]["generation_timeout_seconds"] == 7201.0 - assert progress["policy"]["outer_memory_watchdog_gib"] == 96.0 - assert progress["source_report"]["sha256"] == hashlib.sha256( - source_report.read_bytes() - ).hexdigest() - assert set(progress["runtime_series"]["gg"][madgraph.MODE]) == {"2", "3"} - assert report["status"] == "complete" - - -def test_resumed_progress_prehydrates_compatible_checkpoint_prefix( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - monkeypatch.setattr( - madgraph, - "_generation_attempt", - lambda **_arguments: ({"status": "measured"}, {}), - ) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - cache = tmp_path / "cache" - mg5_root = _fake_mg5_root(tmp_path) - madgraph.build_runtime_report( - source_report=source_report, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=mg5_root, - multiplicities=(2,), - memory_limit_gib=1.0, - ) - - progress_path = tmp_path / "overlay.progress.json" - observed: list[dict[str, object]] = [] - original_atomic = madgraph._json_atomic - - def capture_atomic( - path: Path, payload: dict[str, object], *, replace: bool = True - ) -> None: - original_atomic(path, payload, replace=replace) - if path == progress_path.resolve(strict=False): - observed.append(json.loads(json.dumps(payload))) - - monkeypatch.setattr(madgraph, "_json_atomic", capture_atomic) - - def stop_on_new_cell(**arguments: object) -> dict[str, object]: - selected = arguments["selected"] - assert isinstance(selected, madgraph.SelectedCell) - raise madgraph.SelectedMadGraphError(f"stop at n={selected.n}") - - monkeypatch.setattr(madgraph, "_measure_generated_cell", stop_on_new_cell) - with pytest.raises(madgraph.SelectedMadGraphError, match="stop at n=3"): - madgraph.build_runtime_report( - source_report=source_report, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=mg5_root, - multiplicities=(2, 3), - memory_limit_gib=1.0, - progress_output=progress_path, - ) - - assert observed - first = observed[0] - assert first["summary"]["completed_cell_count"] == 1 - assert set(first["runtime_series"]["gg"][madgraph.MODE]) == {"2"} - assert first["pending_cells"][0]["n"] == 3 - - -def test_final_plot_protocol_skips_pure_gluon_n6( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - attempted: list[int] = [] - - def generation_attempt(**arguments: object) -> tuple[dict[str, object], dict]: - selected = arguments["selected"] - assert isinstance(selected, madgraph.SelectedCell) - attempted.append(selected.n) - return {"status": "measured"}, {} - - monkeypatch.setattr(madgraph, "_generation_attempt", generation_attempt) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - progress_path = tmp_path / "overlay.progress.json" - - report = madgraph.build_runtime_report( - source_report=source_report, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=_fake_mg5_root(tmp_path), - multiplicities=tuple(range(2, 10)), - memory_limit_gib=1.0, - progress_output=progress_path, - ) - - assert attempted == list(range(2, 6)) - cells = report["runtime_series"]["gg"][madgraph.MODE] - assert {cells[str(n)]["status"] for n in range(6, 10)} == { - "not-applicable" - } - assert cells["6"]["failure_category"] == "protocol-scope-pure-gluon-n6" - assert "gfortran -O3 f951 internal compiler error" in cells["6"][ - "failure_reason" - ] - assert report["policy"]["maximum_measured_multiplicity"] == 6 - assert report["policy"]["family_maximum_measured_multiplicity"] == {"gg": 5} - assert report["summary"]["runtime_series_status_counts"] == { - "measured": 4, - "not-applicable": 4, - } - progress = madgraph.load_runtime_progress(progress_path) - assert progress["status"] == "complete" - - -def test_final_plot_protocol_still_launches_ddbar_n6( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("ddbar",)) - attempted: list[int] = [] - - def generation_attempt(**arguments: object) -> tuple[dict[str, object], dict]: - selected = arguments["selected"] - assert isinstance(selected, madgraph.SelectedCell) - attempted.append(selected.n) - return {"status": "measured"}, {} - - monkeypatch.setattr(madgraph, "_generation_attempt", generation_attempt) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - - report = madgraph.build_runtime_report( - source_report=source_report, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=_fake_mg5_root(tmp_path), - multiplicities=(5, 6, 7), - memory_limit_gib=1.0, - ) - - assert attempted == [5, 6] - cells = report["runtime_series"]["ddbar"][madgraph.MODE] - assert cells["6"]["status"] == "measured" - assert cells["7"]["status"] == "not-applicable" - assert report["policy"]["family_maximum_measured_multiplicity"] == { - "ddbar": 6 - } - - -def test_diagnostic_exit_leaves_completed_progress_renderable( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - monkeypatch.setattr( - madgraph, - "_generation_attempt", - lambda **_arguments: ({"status": "measured"}, {}), - ) - - def measure(**arguments: object) -> dict[str, object]: - selected = arguments["selected"] - assert isinstance(selected, madgraph.SelectedCell) - if selected.n == 3: - raise madgraph.SelectedMadGraphError("synthetic diagnostic") - return _measured_stub(**arguments) - - monkeypatch.setattr(madgraph, "_measure_generated_cell", measure) - progress_path = tmp_path / "overlay.progress.json" - with pytest.raises(madgraph.SelectedMadGraphError, match="synthetic diagnostic"): - madgraph.build_runtime_report( - source_report=source_report, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=_fake_mg5_root(tmp_path), - multiplicities=(2, 3), - memory_limit_gib=1.0, - progress_output=progress_path, - ) - progress = madgraph.load_runtime_progress(progress_path) - assert progress["status"] == "running" - assert progress["summary"]["completed_cell_count"] == 1 - assert progress["current_cell"]["n"] == 3 - assert set(progress["runtime_series"]["gg"][madgraph.MODE]) == {"2"} - - -def test_cell_scoped_source_identity_reuses_and_rebinds_checkpoint( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - source_report: Path, -) -> None: - monkeypatch.setattr(madgraph, "FAMILIES", ("gg",)) - payload = json.loads(source_report.read_text(encoding="utf-8")) - payload["kind"] = madgraph.SCALING_STUDY_KIND - first_source = _write_source_payload(tmp_path, payload, "source-1.json") - attempts = 0 - - def generation_attempt(**_arguments: object) -> tuple[dict[str, object], dict]: - nonlocal attempts - attempts += 1 - return {"status": "measured"}, {} - - monkeypatch.setattr(madgraph, "_generation_attempt", generation_attempt) - monkeypatch.setattr(madgraph, "_measure_generated_cell", _measured_stub) - cache = tmp_path / "cache" - mg5_root = _fake_mg5_root(tmp_path) - madgraph.build_runtime_report( - source_report=first_source, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=mg5_root, - multiplicities=(2,), - memory_limit_gib=1.0, - ) - assert attempts == 1 - - payload["cells"]["gg"]["reference-fft"]["3"]["label"] = "unrelated edit" - second_source = _write_source_payload(tmp_path, payload, "source-2.json") - report = madgraph.build_runtime_report( - source_report=second_source, - cache_dir=cache, - fc="gfortran", - fflags="-O3", - timeout_seconds=10.0, - mg5_root=mg5_root, - multiplicities=(2,), - memory_limit_gib=1.0, - ) - assert attempts == 1 - rebound = report["runtime_series"]["gg"][madgraph.MODE]["2"] - assert rebound["provenance"]["source_report"]["path"] == str(second_source) - assert rebound["provenance"]["source_report"]["sha256"] == hashlib.sha256( - second_source.read_bytes() - ).hexdigest() - checkpoint = json.loads((cache / "gg" / "n2" / "cell.json").read_text()) - assert checkpoint["checkpoint_identity"]["source_report_sha256"] == rebound[ - "provenance" - ]["source_report"]["sha256"] - assert len(checkpoint["checkpoint_identity"]["source_cell_sha256"]) == 64 - - -@pytest.mark.parametrize( - ("timeout", "memory", "message"), - ( - (0.0, 1.0, "generation timeout"), - (math.inf, 1.0, "generation timeout"), - (True, 1.0, "generation timeout"), - (1.0, 0.0, "memory limit"), - (1.0, math.nan, "memory limit"), - (1.0, True, "memory limit"), - ), -) -def test_custom_caps_must_only_be_positive_finite_numbers( - tmp_path: Path, - source_report: Path, - timeout: float, - memory: float, - message: str, -) -> None: - with pytest.raises(madgraph.SelectedMadGraphError, match=message): - madgraph.build_runtime_report( - source_report=source_report, - cache_dir=tmp_path / "cache", - fc="gfortran", - fflags="-O3", - timeout_seconds=timeout, - mg5_root=tmp_path / "unused", - multiplicities=(2,), - memory_limit_gib=memory, - ) - - -def test_default_progress_path_stays_beside_overlay(tmp_path: Path) -> None: - output = tmp_path / "overlay.json" - assert madgraph._default_progress_output(output) == ( - tmp_path / "overlay.progress.json" - ) diff --git a/pyamplicol/tests/unit/test_fft_numerical_acceptance.py b/pyamplicol/tests/unit/test_fft_numerical_acceptance.py deleted file mode 100644 index bd0fddc2f1..0000000000 --- a/pyamplicol/tests/unit/test_fft_numerical_acceptance.py +++ /dev/null @@ -1,554 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import sys -from decimal import Decimal -from pathlib import Path -from types import ModuleType, SimpleNamespace - -import pytest - -from tools.developer import fft_numerical_acceptance as gate - - -def test_catalog_and_comparison_matrix_are_derived_at_locked_bounds() -> None: - selected = gate.catalog_cases(gate.SELECTED_MAX_N_FINAL) - totals = gate.catalog_cases(gate.TOTAL_MAX_N_FINAL) - - assert len(selected) == 47 - assert len(totals) == 33 - assert {case.family_id for case in selected}.isdisjoint({14}) - assert all(case.n_final <= 5 for case in selected) - assert all(case.n_final <= 4 for case in totals) - - specs = gate.comparison_specs() - direct_fft = tuple(spec for spec in specs if spec.authority == "direct-vs-fft") - frozen = tuple(spec for spec in specs if spec.authority == "frozen-madgraph") - assert len(direct_fft) == 508 - assert len(frozen) == 66 - assert len(specs) == 574 - assert all(spec.model == "ufo-sm" for spec in frozen) - assert all(spec.accuracy == "full" for spec in frozen) - assert all(spec.helicity_scope == "total" for spec in frozen) - - -def test_dry_run_authenticates_frozen_fixture_and_declares_cache_policy() -> None: - payload = gate.dry_run_payload() - - assert payload["dry_run"] is True - assert payload["point_policy"] == { - "generator": "generic_validation_point", - "seed": 101, - } - assert payload["comparison_counts"] == { - "direct_vs_fft": 508, - "frozen_madgraph": 66, - "total": 574, - } - cache = payload["process_set_cache_policy"] - assert cache["per_process_generation"] is False - assert cache["base_key_axes"] == [ - "method", - "model", - "mode", - "accuracy", - "helicity_scope", - ] - assert cache["selected_execution"] == { - "recurrence": "generation-specialized", - "on-the-fly": "runtime-query-complete-coverage", - } - assert "shared by selected runtime queries" in cache["on_the_fly_complete_coverage"] - assert payload["frozen_authority"]["madgraph_rerun"] is False - - -def test_dry_run_cli_does_not_create_output_root( - tmp_path: Path, - capsys: pytest.CaptureFixture[str], -) -> None: - output_root = tmp_path / "must-not-exist" - assert gate.main(["--dry-run", "--output-root", str(output_root)]) == 0 - - payload = json.loads(capsys.readouterr().out) - assert payload["kind"] == gate.GATE_KIND - assert payload["comparison_counts"]["total"] == 574 - assert not output_root.exists() - - -def test_scale_relative_comparison_has_no_absolute_tolerance_escape() -> None: - assert gate.strict_relative_compare(0, 0).passed - assert gate.strict_relative_compare(Decimal("1.00000000005"), Decimal("1")).passed - assert not gate.strict_relative_compare(Decimal("1e-300"), Decimal("2e-300")).passed - assert not gate.strict_relative_compare(1 + 1e-8j, 1).passed - - -def test_on_the_fly_reflection_census_validator_locks_fold_and_fallback() -> None: - def census( - current_count: int, - contribution_count: int, - finalization_count: int, - query_count: int, - ) -> dict[str, object]: - return { - "basis": "shared-query-family-union-v1", - "scope": "active-family-union", - "query_count": query_count, - "union_unique_current_count": current_count, - "union_contribution_rows": contribution_count, - "union_finalization_rows": finalization_count, - "union_closure_rows": query_count, - } - - pure_direct = census(22, 36, 6, 6) - pure_fft = census(13, 18, 3, 6) - open_line = census(17, 24, 4, 2) - evidence = gate.validate_on_the_fly_reflection_census( - pure_adjoint_direct=pure_direct, - pure_adjoint_fft=pure_fft, - open_line_direct=open_line, - open_line_fft=dict(open_line), - ) - assert evidence["pure_adjoint"] == { - "case_id": "catalog:gg_gluons:n2", - "fields": [ - "union_unique_current_count", - "union_contribution_rows", - "union_finalization_rows", - ], - "direct": [22, 36, 6], - "symmetric_group_fft": [13, 18, 3], - } - assert evidence["open_line"] == { - "case_id": "catalog:gg_tt_jets:n2", - "direct_equals_symmetric_group_fft": True, - "fields": [ - "union_unique_current_count", - "union_contribution_rows", - "union_finalization_rows", - ], - "shared": [17, 24, 4], - } - - with pytest.raises( - gate.FFTAcceptanceError, - match=r"gg_gluons:n2 direct.*expected", - ): - gate.validate_on_the_fly_reflection_census( - pure_adjoint_direct=census(23, 36, 6, 6), - pure_adjoint_fft=pure_fft, - open_line_direct=open_line, - open_line_fft=open_line, - ) - - changed_open_line = dict(open_line) - changed_open_line["union_closure_rows"] = 3 - with pytest.raises( - gate.FFTAcceptanceError, - match=r"gg_tt_jets:n2.*must be identical.*union_closure_rows", - ): - gate.validate_on_the_fly_reflection_census( - pure_adjoint_direct=pure_direct, - pure_adjoint_fft=pure_fft, - open_line_direct=open_line, - open_line_fft=changed_open_line, - ) - - -def test_nonzero_discovery_prefers_structural_selector_then_stable_fallback() -> None: - rows = ( - gate.HelicityObservation("h:-1,-1", (-1, -1), False, 5.0), - gate.HelicityObservation("h:-1,+1", (-1, 1), False, 2.0), - gate.HelicityObservation("h:+1,-1", (1, -1), True, 0.0), - gate.HelicityObservation("h:+1,+1", (1, 1), False, 0.0), - ) - - preferred = gate.choose_nonzero_helicity(rows, preferred=(-1, 1)) - assert preferred.observation.values == (-1, 1) - assert preferred.source == "preferred-structural-selector" - assert preferred.domains == ((-1, 1), (-1, 1)) - - fallback = gate.choose_nonzero_helicity(rows, preferred=(1, 1)) - assert fallback.observation.values == (-1, -1) - assert fallback.source == "largest-nonzero-fallback" - - -def test_nonzero_discovery_rejects_an_all_zero_or_structural_axis() -> None: - with pytest.raises(gate.FFTAcceptanceError, match="no nonzero"): - gate.choose_nonzero_helicity( - ( - gate.HelicityObservation("h:-1", (-1,), False, 0.0), - gate.HelicityObservation("h:+1", (1,), True, 3.0), - ), - preferred=(-1,), - ) - - -def test_selected_groups_include_domain_and_exact_tuple_in_scope() -> None: - cases = gate.catalog_cases(2)[:3] - - def selection( - case: gate.CatalogCase, - values: tuple[int, ...], - domains: tuple[tuple[int, ...], ...], - ) -> gate.SelectionRecord: - return gate.SelectionRecord( - model="built-in-sm", - accuracy="full", - case=case, - helicity_id="h:" + ",".join(f"{value:+d}" for value in values), - values=values, - domains=domains, - source="unit-test", - discovery_value=1.0, - ) - - first_values = (-1, 1, -1) - first_domains = ((-1, 1), (-1, 1), (-1, 0, 1)) - second_domains = ((-1, 1), (-1, 1), (-1, 1)) - selections = { - cases[0].case_id: selection(cases[0], first_values, first_domains), - cases[1].case_id: selection(cases[1], first_values, first_domains), - cases[2].case_id: selection(cases[2], first_values, second_domains), - } - - groups = gate.group_selected_cases(cases, selections) - assert tuple(len(group.cases) for group in groups) == (2, 1) - assert groups[0].scope != groups[1].scope - assert groups[0].source_mapping == ((1, -1), (2, 1), (3, -1)) - - -def test_process_set_cache_builds_once_per_exact_boundary() -> None: - calls: list[gate.GroupRequest] = [] - - def build(request: gate.GroupRequest) -> object: - calls.append(request) - return object() - - cases = gate.catalog_cases(1) - request = gate.GroupRequest( - gate.ArtifactKey( - "direct", - "built-in-sm", - "recurrence", - "full", - "all-helicity-total", - ), - cases, - ) - cache: gate.ProcessSetCache[object] = gate.ProcessSetCache(build) - - first = cache.get(request) - second = cache.get(request) - assert first is second - assert calls == [request] - assert cache.generation_count == 1 - - incompatible = gate.GroupRequest(request.key, cases[:1]) - with pytest.raises(gate.FFTAcceptanceError, match="different case"): - cache.get(incompatible) - - -@pytest.mark.parametrize( - ("request_method", "n_final", "inspection_method", "accepted"), - ( - ("direct", 3, None, True), - ("direct", 3, "symmetric-group-fourier", False), - ("symmetric-group-fft", 1, None, True), - ("symmetric-group-fft", 2, None, True), - ("symmetric-group-fft", 2, "symmetric-group-fourier", False), - ("symmetric-group-fft", 3, None, False), - ("symmetric-group-fft", 3, "symmetric-group-fourier", True), - ), -) -@pytest.mark.parametrize("mode", gate.MODES) -def test_artifact_validation_maps_request_to_canonical_inspection_method( - request_method: gate.MethodName, - n_final: int, - inspection_method: str | None, - accepted: bool, - mode: gate.ModeName, - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - case = next( - case - for case in gate.catalog_cases(n_final) - if case.family_id == 1 and case.n_final == n_final - ) - request = gate.GroupRequest( - gate.ArtifactKey( - request_method, - "built-in-sm", - mode, - "full", - "complete-test", - ), - (case,), - ) - config = tmp_path / "config" - config.mkdir() - (config / "effective.toml").write_text( - "\n".join( - ( - "[color]", - 'accuracy = "full"', - f'contraction = "{request_method}"', - "[evaluator]", - f'execution_mode = "{mode}"', - "", - ) - ), - encoding="utf-8", - ) - inspection = SimpleNamespace( - model_name="built-in-sm", - model_source="compiled-model", - processes=( - SimpleNamespace( - id=case.artifact_name, - expression=case.process, - aliases=(), - color_accuracy="full", - execution_mode=mode, - recurrence_color_contraction_method=inspection_method, - selected_source_helicities=(), - helicity_coverage="complete", - generation_specialized_axes=(), - ), - ), - ) - fake_artifacts = ModuleType("pyamplicol.artifacts") - fake_artifacts.inspect_artifact = lambda _path: inspection # type: ignore[attr-defined] - monkeypatch.setitem(sys.modules, "pyamplicol.artifacts", fake_artifacts) - - if accepted: - gate.NativeArtifactBuilder._validate(tmp_path, request) - else: - with pytest.raises(gate.FFTAcceptanceError, match="expected"): - gate.NativeArtifactBuilder._validate(tmp_path, request) - - -def test_group_request_rejects_selection_outside_recorded_domain() -> None: - case = gate.catalog_cases(1)[0] - with pytest.raises(ValueError, match="outside its domain"): - gate.GroupRequest( - gate.ArtifactKey( - "direct", - "built-in-sm", - "recurrence", - "full", - "selected-invalid", - ), - (case,), - selected_source_helicities=((1, 0),), - external_helicity_domains=((-1, 1),), - ) - - -def test_otf_group_request_is_complete_and_rejects_generation_selection() -> None: - cases = gate.catalog_cases(gate.SELECTED_MAX_N_FINAL) - request = gate.otf_complete_group_request( - method="symmetric-group-fft", - model="ufo-sm", - accuracy="nlc", - cases=cases, - ) - - assert request.key.mode == "on-the-fly" - assert request.key.helicity_scope == "complete-helicity-runtime-query-and-total" - assert request.cases == cases - assert request.selected_source_helicities is None - assert request.external_helicity_domains is None - assert request.as_payload()["helicity_generation_contract"] == "complete-coverage" - - with pytest.raises(ValueError, match="must retain complete helicity coverage"): - gate.GroupRequest( - gate.ArtifactKey( - "direct", - "built-in-sm", - "on-the-fly", - "full", - "invalid-selected-otf", - ), - cases[:1], - selected_source_helicities=((1, -1),), - external_helicity_domains=((-1, 1),), - ) - - -def test_selected_artifact_plan_specializes_recurrence_but_groups_complete_otf( - tmp_path: Path, -) -> None: - cases = gate.catalog_cases(1) - harness = object.__new__(gate.NativeAcceptanceHarness) - harness.selected_cases = cases - harness.total_cases = cases - harness.selections = { - (model, accuracy, case.case_id): gate.SelectionRecord( - model=model, - accuracy=accuracy, - case=case, - helicity_id="h:-1,+1,-1", - values=(-1, 1, -1), - domains=((-1, 1), (-1, 1), (-1, 1)), - source="unit-test", - discovery_value=3.0, - ) - for model in gate.MODELS - for accuracy in gate.ACCURACIES - for case in cases - } - - class RecordingCache: - def __init__(self) -> None: - self.requests: list[gate.GroupRequest] = [] - - def get(self, request: gate.GroupRequest) -> gate.ArtifactRecord: - self.requests.append(request) - return gate.ArtifactRecord(request, tmp_path / request.key.slug) - - cache = RecordingCache() - harness.cache = cache - fallback_scopes = frozenset( - (model, accuracy) for model in gate.MODELS for accuracy in gate.ACCURACIES - ) - records = harness._selected_artifacts({}, fallback_scopes) - - recurrence = tuple( - request for request in cache.requests if request.key.mode == "recurrence" - ) - otf = tuple( - request for request in cache.requests if request.key.mode == "on-the-fly" - ) - assert len(recurrence) == 8 - assert all(request.selected_source_helicities for request in recurrence) - assert len(otf) == 8 - assert all(request.cases == cases for request in otf) - assert all(request.selected_source_helicities is None for request in otf) - for model in gate.MODELS: - for accuracy in gate.ACCURACIES: - for method in gate.METHODS: - lane_paths = { - records[(model, "on-the-fly", accuracy, method, case.case_id)].path - for case in cases - } - assert len(lane_paths) == 1 - - request_count = len(cache.requests) - totals = harness._total_artifacts(records) - assert len(cache.requests) == request_count + 4 - for model in gate.MODELS: - for method in gate.METHODS: - selected_path = records[ - (model, "on-the-fly", "full", method, cases[0].case_id) - ].path - assert totals[(model, "on-the-fly", method)].path == selected_path - - -def test_otf_selected_evaluation_uses_exact_runtime_helicity_query( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - case = gate.catalog_cases(1)[0] - values = (-1, 1, -1) - helicity_id = "h:-1,+1,-1" - selection = gate.SelectionRecord( - model="built-in-sm", - accuracy="full", - case=case, - helicity_id=helicity_id, - values=values, - domains=((-1, 1), (-1, 1), (-1, 1)), - source="unit-test", - discovery_value=3.0, - ) - request = gate.otf_complete_group_request( - method="direct", - model="built-in-sm", - accuracy="full", - cases=(case,), - ) - record = gate.ArtifactRecord(request, tmp_path / "artifact") - calls: list[tuple[str, ...] | None] = [] - - class FakeRuntime: - execution_mode = "on-the-fly" - physics = SimpleNamespace( - color_accuracy="full", - helicity_coverage="complete", - helicities=( - SimpleNamespace(id="h:-1,-1,-1", values=(-1, -1, -1)), - SimpleNamespace(id=helicity_id, values=values), - ), - ) - - def evaluate( - self, - _momenta: object, - *, - helicities: tuple[str, ...] | None = None, - ) -> tuple[complex, ...]: - calls.append(helicities) - return (3.0 + 0.0j,) - - def clear(self) -> None: - pass - - runtime = FakeRuntime() - fake_pyamplicol = ModuleType("pyamplicol") - fake_pyamplicol.Runtime = SimpleNamespace( # type: ignore[attr-defined] - load=lambda _path, *, process: runtime - ) - monkeypatch.setitem(sys.modules, "pyamplicol", fake_pyamplicol) - monkeypatch.setattr( - gate, - "_runtime_points", - lambda _case: (((1.0, 0.0, 0.0, 1.0),),), - ) - - assert gate._evaluate_scalar(record, case, selection=selection) == 3.0 + 0.0j - assert calls == [(helicity_id,)] - - -def test_shared_complete_artifact_caches_selected_and_total_values_separately( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - case = gate.catalog_cases(1)[0] - request = gate.otf_complete_group_request( - method="direct", - model="built-in-sm", - accuracy="full", - cases=(case,), - ) - record = gate.ArtifactRecord(request, tmp_path / "artifact") - selection = gate.SelectionRecord( - model="built-in-sm", - accuracy="full", - case=case, - helicity_id="h:-1,+1,-1", - values=(-1, 1, -1), - domains=((-1, 1), (-1, 1), (-1, 1)), - source="unit-test", - discovery_value=3.0, - ) - calls: list[gate.SelectionRecord | None] = [] - - def evaluate( - _record: gate.ArtifactRecord, - _case: gate.CatalogCase, - *, - selection: gate.SelectionRecord | None, - ) -> float: - calls.append(selection) - return 3.0 if selection is not None else 7.0 - - monkeypatch.setattr(gate, "_evaluate_scalar", evaluate) - harness = object.__new__(gate.NativeAcceptanceHarness) - harness._values = {} - - assert harness._value(record, case, selection=selection) == 3.0 - assert harness._value(record, case, selection=None) == 7.0 - assert harness._value(record, case, selection=selection) == 3.0 - assert calls == [selection, None] diff --git a/pyamplicol/tests/unit/test_fft_profiling.py b/pyamplicol/tests/unit/test_fft_profiling.py deleted file mode 100644 index 9da7210ef9..0000000000 --- a/pyamplicol/tests/unit/test_fft_profiling.py +++ /dev/null @@ -1,3417 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import argparse -import builtins -import io -import json -import os -import sys -import tomllib -from copy import deepcopy -from pathlib import Path - -import pytest - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.developer import fft_scaling_study as study # noqa: E402 -from tools.fft_profiling import fft_profiling as profiling # noqa: E402 - - -def _arguments(*values: str): - return profiling._parser().parse_args(values) - - -@pytest.fixture(autouse=True) -def _redirect_canonical_results( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - monkeypatch.setattr( - profiling, "CANONICAL_RESULTS_ROOT", tmp_path / "canonical-results" - ) - - -def test_dry_run_sparse_custom_caps_is_deterministic_and_write_free( - tmp_path: Path, -) -> None: - output = tmp_path / "cluster run" - arguments = _arguments( - "--dry-run", - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--cores", - "8", - "--candidate-cores", - "2", - "--memory-limit-gib", - "64", - "--time-limit-seconds", - "14400", - "--madgraph-root", - str(tmp_path / "mg5"), - ) - profiling._validate_arguments(arguments) - - first = profiling.dry_run_plan(arguments) - second = profiling.dry_run_plan(arguments) - - assert first == second - assert not output.exists() - assert first["identity"]["scan"]["multiplicity_universe"] == list(range(2, 10)) - assert first["batch_size"] == 128 - assert first["identity"]["scan"]["batch_size"] == 128 - assert first["requested_fill_multiplicities"] == [2, 3] - assert first["identity"]["resources"] == { - "candidate_optimization_cores": 2, - "per_cell_generation_timeout_seconds": 14400.0, - "per_cell_memory_limit_gib": 64.0, - "per_cell_runtime_timeout_seconds": 14400.0, - } - assert set(first["shards"]) == {shard.name for shard in profiling.SHARDS} - for shard in first["shards"].values(): - if shard["argv"] is not None: - batch_index = shard["argv"].index("--batch-size") - assert shard["argv"][batch_index + 1] == "128" - assert first["shards"]["gg-otf"]["owned_modes"] == [ - "otf-direct", - "otf-fft", - ] - mg_argv = first["madgraph"]["argv"] - assert mg_argv is not None - assert mg_argv.count("--multiplicity") == 2 - assert mg_argv[mg_argv.index("--memory-limit-gib") + 1] == "64" - assert mg_argv[mg_argv.index("--generation-timeout-seconds") + 1] == "14400" - - -def test_helicity_sum_dry_run_generates_a_distinct_summed_madgraph_series( - tmp_path: Path, -) -> None: - arguments = _arguments( - "--dry-run", - "--compare-helicity-sums", - "--output", - str(tmp_path / "summed"), - "--multiplicities", - "2", - "3", - "--memory-limit-gib", - "64", - "--time-limit-seconds", - "14400", - "--madgraph-root", - str(tmp_path / "mg5"), - ) - profiling._validate_arguments(arguments) - - plan = profiling.dry_run_plan(arguments) - - assert plan["helicity_workload"] == "sum" - assert plan["batch_size"] == 128 - assert plan["identity"]["scan"]["helicity_workload"] == "sum" - assert plan["identity"]["tools"]["madgraph_root"] == str(tmp_path / "mg5") - assert plan["madgraph"] == { - "phase": 4, - "applicable": True, - "helicity_workload": "sum", - "process_families": ["gg", "ddbar"], - "measurement_multiplicities": [2, 3], - "protocol_scope_multiplicities": [], - "measurement_multiplicities_by_family": { - "gg": [2, 3], - "ddbar": [2, 3], - }, - "protocol_scope_multiplicities_by_family": {"gg": [], "ddbar": []}, - "dependency": ( - "completed pyAmpliCol source cells for the requested MadGraph fill" - ), - "not_applicable_reason": None, - "report": str(tmp_path / "summed" / "madgraph" / "overlay.json"), - "argv": plan["madgraph"]["argv"], - "shell_command": plan["madgraph"]["shell_command"], - } - assert plan["madgraph"]["argv"] is not None - assert "--compare-helicity-sums" in plan["madgraph"]["argv"] - assert plan["madgraph"]["argv"][ - plan["madgraph"]["argv"].index("--target-seconds") + 1 - ] == "180" - assert plan["outputs"]["final_pdf"].endswith( - "/summary_plots_final_helicity_sum.pdf" - ) - for shard in plan["shards"].values(): - if shard["argv"] is not None: - assert "--compare-helicity-sums" in shard["argv"] - master = profiling._master_arguments(arguments, tmp_path / "summed") - assert master.compare_helicity_sums is True - assert study.dry_run_plan(master)["measurement"]["helicity_workload"] == "sum" - - -def test_madgraph_command_protocol_scopes_n_above_six(tmp_path: Path) -> None: - arguments = _arguments( - "--dry-run", - "--output", - str(tmp_path / "fixed"), - "--multiplicities", - "6", - "7", - "8", - "--madgraph-root", - str(tmp_path / "mg5"), - ) - - plan = profiling.dry_run_plan(arguments) - argv = plan["madgraph"]["argv"] - - assert plan["madgraph"]["measurement_multiplicities"] == [6] - assert plan["madgraph"]["protocol_scope_multiplicities"] == [7, 8] - assert plan["madgraph"]["measurement_multiplicities_by_family"] == { - "gg": [], - "ddbar": [6], - } - assert plan["madgraph"]["protocol_scope_multiplicities_by_family"] == { - "gg": [6, 7, 8], - "ddbar": [7, 8], - } - assert argv is not None - assert argv[argv.index("--multiplicity") + 1] == "6" - assert argv[argv.index("--target-seconds") + 1] == "180" - assert [ - argv[index + 1] - for index, value in enumerate(argv) - if value == "--protocol-scope-multiplicity" - ] == ["7", "8"] - - -def test_canonical_authenticated_madgraph_overlay_has_resume_fast_path( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "fixed" - overlay = tmp_path / "overlay.json" - overlay.write_text("{}", encoding="ascii") - arguments = _arguments("--output", str(output)) - calls: list[tuple[Path, Path]] = [] - monkeypatch.setattr(profiling, "_report_publication_profile", lambda _report: True) - monkeypatch.setattr( - profiling, - "_matching_madgraph_overlay", - lambda *_args, **_kwargs: overlay, - ) - monkeypatch.setattr( - profiling.publication, - "build_final_report", - lambda *, campaign_path, madgraph_overlay_path: calls.append( - (campaign_path, madgraph_overlay_path) - ), - ) - - assert profiling._canonical_madgraph_overlay_authenticated( - arguments, output, {"status": "complete"} - ) - assert calls == [(profiling._master_report_path(output), overlay)] - - -def test_workload_defaults_are_separate_and_explicit_output_is_exact( - tmp_path: Path, -) -> None: - fixed = _arguments() - summed = _arguments("--compare-helicity-sums") - explicit_path = tmp_path / "chosen" - explicit = _arguments("--compare-helicity-sums", "--output", str(explicit_path)) - - assert profiling._run_directory(fixed) == profiling.DEFAULT_FIXED_OUTPUT - assert profiling._run_directory(summed) == profiling.DEFAULT_SUM_OUTPUT - assert profiling._run_directory(explicit) == explicit_path - assert fixed.batch_size == 128 - assert summed.batch_size == 128 - assert profiling._pdf_filename(fixed) == "summary_plots_final.pdf" - assert profiling._pdf_filename(summed) == "summary_plots_final_helicity_sum.pdf" - - -def test_dashboard_headline_displays_workload_batch_cores_and_rss( - monkeypatch: pytest.MonkeyPatch, -) -> None: - headlines: list[str] = [] - - class FakeBar: - def start(self) -> None: - pass - - def update(self, _value: int, **values: object) -> None: - headlines.append(str(values["headline"])) - - def finish(self, **_kwargs: object) -> None: - pass - - monkeypatch.setattr( - profiling.progressbar, - "ProgressBar", - lambda **_kwargs: FakeBar(), - ) - monkeypatch.setattr(profiling, "_aggregate_rss", lambda _active: 3 * 1024**3) - - class FakeJob: - claimed_cores = 2 - detail = "gg/recurrence-fft/n4" - - dashboard = profiling.Dashboard( - total=2, - core_budget=4, - helicity_workload="sum", - batch_size=128, - ) - - dashboard.update(1, phase="phase 2", active=(FakeJob(),)) - - assert "1/2 cells | sum batch=128" in headlines[-1] - assert "phase 2: gg/recurrence-fft/n4" in headlines[-1] - assert "cores active=2/4" in headlines[-1] - assert "RSS 3.00 GiB" in headlines[-1] - assert "elapsed " in headlines[-1] - assert "ETA" not in headlines[-1] - - -def test_authoritative_study_supports_isolated_roots_and_custom_caps( - tmp_path: Path, -) -> None: - arguments = study._parser().parse_args( - ( - "--study-root", - str(tmp_path / "one"), - "--run-id", - "cell", - "--multiplicity", - "2", - "--generation-timeout", - "14400", - "--runtime-timeout", - "14400", - "--memory-limit-gib", - "64", - "--optimization-cores", - "3", - ) - ) - study._validate_arguments(arguments) - plan = study.dry_run_plan(arguments) - measurement = plan["measurement"] - assert measurement["requested_memory_ceiling_gib"] == 64.0 - assert measurement["memory_watchdog_gib"] == 64.0 - assert measurement["candidate_optimization_cores"] == 3 - assert measurement["generation_timeout_seconds"] == 14400.0 - - first_root = tmp_path / "lock-one" - second_root = tmp_path / "lock-two" - first_root.mkdir() - second_root.mkdir() - first = study._acquire_campaign_lock(first_root) - second = study._acquire_campaign_lock(second_root) - first.close() - second.close() - - -def test_authoritative_fill_selector_does_not_change_report_policy() -> None: - base = study._parser().parse_args(("--multiplicity", "2", "--multiplicity", "3")) - fill = study._parser().parse_args( - ( - "--multiplicity", - "2", - "--multiplicity", - "3", - "--fill-multiplicity", - "3", - ) - ) - study._validate_arguments(fill) - - assert study.dry_run_plan(fill) == study.dry_run_plan(base) - assert study._fill_multiplicities(fill) == (3,) - - -def test_otf_protocol_scope_keeps_fixed_n6_and_skips_n7_n8_n9() -> None: - arguments = _arguments("--multiplicities", "6", "7", "8", "9") - shard = profiling.SHARD_BY_NAME["gg-otf"] - namespace = profiling._shard_arguments(arguments, Path("/tmp/otf-scope"), shard) - report = study.compose_report(namespace, {}) - - changed = study.apply_protocol_scope_cells( - report, - family="gg", - modes=shard.owned_modes, - multiplicities=(6, 7, 8, 9), - ) - - assert changed is True - for mode in shard.owned_modes: - assert "6" not in report["cells"]["gg"][mode] - assert {report["cells"]["gg"][mode][str(n)]["status"] for n in (7, 8, 9)} == { - "skipped" - } - assert not profiling._selected_shard_complete(arguments, shard, report) - - plan = profiling.dry_run_plan(arguments) - assert plan["shards"]["gg-otf"]["measurement_multiplicities"] == [6] - assert plan["shards"]["gg-otf"]["protocol_skip_multiplicities"] == [7, 8, 9] - assert plan["shards"]["gg-otf"]["argv"] is not None - - -def test_otf_protocol_scope_can_be_extended_for_selective_top_up() -> None: - arguments = _arguments( - "--multiplicities", - "7", - "8", - "--families", - "ddbar", - "--lines", - "pyamplicol-otf", - "--otf-max-multiplicity", - "8", - ) - - plan = profiling.dry_run_plan(arguments) - otf = plan["shards"]["ddbar-otf"] - - assert otf["measurement_multiplicities"] == [7, 8] - assert otf["protocol_skip_multiplicities"] == [] - assert [(job["n"], job["mode"]) for job in otf["jobs"]] == [ - (7, "otf-direct"), - (7, "otf-fft"), - (8, "otf-direct"), - (8, "otf-fft"), - ] - for job in otf["jobs"]: - option = job["argv"].index("--otf-max-multiplicity") - assert job["argv"][option + 1] == "8" - - -def test_candidate_direct_and_fft_modes_are_distinct_work_items(tmp_path: Path) -> None: - output = tmp_path / "split" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "6", - "--families", - "gg", - "--lines", - "pyamplicol-otf", - ) - - works = profiling._phase_work_items(arguments, output, 2) - - assert [ - (work.shard.name, work.final_multiplicity, work.owned_mode) - for work in works - ] == [ - ("gg-otf", 6, "otf-direct"), - ("gg-otf", 6, "otf-fft"), - ] - assert len({profiling._work_report_path(output, work) for work in works}) == 2 - for work in works: - command = profiling._child_command(arguments, output, work) - assert command.count("--fill-mode") == 1 - assert command[command.index("--fill-mode") + 1] == work.owned_mode - - -def test_helicity_sum_amplicol_work_items_do_not_overlap_shared_overlay() -> None: - arguments = _arguments("--compare-helicity-sums") - first = profiling.ShardWork( - profiling.SHARD_BY_NAME["ddbar-amplicol"], 2, "amplicol" - ) - second = profiling.ShardWork( - profiling.SHARD_BY_NAME["gg-amplicol"], 2, "amplicol" - ) - active = [ - profiling.ActiveJob( - shard=first.shard, - final_multiplicity=first.final_multiplicity, - owned_mode=first.owned_mode, - command=(), - process=object(), - stdout=io.BytesIO(), - stderr=io.BytesIO(), - sampler=object(), - claimed_cores=1, - detail="", - ) - ] - - assert profiling._work_launch_conflicts(arguments, second, active) is True - assert profiling._work_launch_conflicts(arguments, first, ()) is False - - -def test_composer_retains_measured_cells_above_out_of_order_frontier() -> None: - arguments = study._parser().parse_args( - ( - "--multiplicity", - "2", - "--multiplicity", - "8", - "--family", - "gg", - "--mode", - "reference-fft", - ) - ) - failed = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 2) | { - "status": "failed", - "censors_higher_multiplicities": True, - } - measured = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 8) | { - "status": "measured" - } - - report = study.compose_report( - arguments, - {"gg": {"reference-fft": {"2": failed, "8": measured}}}, - ) - - assert report["status"] == "complete-with-failures" - assert report["cells"]["gg"]["reference-fft"]["8"] == measured - assert report["resource_frontier_inversions"] == [["gg", "reference-fft", 2, 8]] - - -def test_dry_run_exposes_per_multiplicity_workers(tmp_path: Path) -> None: - arguments = _arguments( - "--dry-run", - "--output", - str(tmp_path / "run"), - "--multiplicities", - "2", - "3", - "4", - "--lines", - "reference-fft", - "--cores", - "3", - ) - - plan = profiling.dry_run_plan(arguments) - reference = plan["shards"]["gg-reference"] - jobs = reference["jobs"] - - assert plan["scheduler"]["parallelism"] == ( - "weighted dependency-aware shard-multiplicity workers" - ) - assert [job["n"] for job in jobs] == [2, 3, 4] - assert len({job["study_root"] for job in jobs}) == 3 - assert reference["argv"] == jobs[0]["argv"] - assert [ - job["argv"][index + 1] - for job in jobs - for index, value in enumerate(job["argv"]) - if value == "--fill-multiplicity" - ] == ["2", "3", "4"] - - -def test_isolated_shard_reports_merge_and_retain_started_higher_measurement( - tmp_path: Path, -) -> None: - output = tmp_path / "run" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--lines", - "reference-fft", - ) - profiling._create_or_resume_manifest(arguments, output) - shard = profiling.SHARD_BY_NAME["gg-reference"] - failed = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 2) | { - "status": "failed", - "failure_category": "memory-limit", - "failure_reason": "memory cap", - "censors_higher_multiplicities": True, - } - measured = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 3) | { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - for final_multiplicity, cell in ((2, failed), (3, measured)): - report = study.compose_report( - profiling._shard_arguments(arguments, output, shard, final_multiplicity), - {"gg": {"reference-fft": {str(final_multiplicity): cell}}}, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard, final_multiplicity), - report, - ) - - report = profiling._load_shard_report(arguments, output, shard, required=True) - - assert report["status"] == "running" - curve = report["cells"]["gg"]["reference-fft"] - assert curve["2"]["status"] == "failed" - assert curve["3"] == measured - assert study.resource_frontier_inversions(report) == ( - ("gg", "reference-fft", 2, 3), - ) - - -def test_isolated_shard_reports_preserve_prior_measurement_over_later_failure( - tmp_path: Path, -) -> None: - output = tmp_path / "run" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "9", - "--lines", - "amplicol", - ) - profiling._create_or_resume_manifest(arguments, output) - shard = profiling.SHARD_BY_NAME["ddbar-amplicol"] - measured = study._cell_base("ddbar", study.MODE_BY_KEY["amplicol"], 9) | { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - failed = study._cell_base("ddbar", study.MODE_BY_KEY["amplicol"], 9) | { - "status": "failed", - "failure_category": "legacy-amplicol-structural-limit", - "failure_reason": "legacy crash", - "censors_higher_multiplicities": True, - } - aggregate = study.compose_report( - profiling._shard_arguments(arguments, output, shard), - {"ddbar": {"amplicol": {"9": measured}}}, - ) - retry = study.compose_report( - profiling._shard_arguments(arguments, output, shard, 9), - {"ddbar": {"amplicol": {"9": failed}}}, - ) - profiling._write_json_atomic(profiling._shard_report_path(output, shard), aggregate) - profiling._write_json_atomic(profiling._shard_report_path(output, shard, 9), retry) - - report = profiling._load_shard_report(arguments, output, shard, required=True) - - assert report["cells"]["ddbar"]["amplicol"]["9"] == measured - - -def test_shard_policy_compatibility_accepts_sampling_policy_updates( - tmp_path: Path, -) -> None: - output = tmp_path / "run" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "5", - "--lines", - "pyamplicol-otf", - "--compare-helicity-sums", - "--memory-limit-gib", - "100", - "--time-limit-seconds", - "3600", - ) - shard = profiling.SHARD_BY_NAME["gg-otf"] - modes = ("reference-fft", "otf-direct") - expected = profiling._expected_shard_policy( - arguments, - output, - shard, - 5, - modes=modes, - ) - stale = deepcopy(expected) - measurement = stale["measurement"] - measurement["calibration_target_seconds"] = 0.25 - measurement["candidate_profile_target_runtime_seconds"] = 0.25 - measurement["candidate_profile_warmup_runs"] = 2 - measurement["candidate_profile_minimum_samples"] = 10 - measurement["warm_samples"] = 10 - measurement["warm_sample_count"] = 10 - measurement["warm_timing_metric"] = {"pyamplicol": "old short sampling"} - measurement["generation_timeout_seconds"] = 60.0 - measurement["runtime_timeout_seconds"] = 60.0 - measurement["requested_memory_ceiling_gib"] = 10.0 - measurement["memory_watchdog_gib"] = 10.0 - measurement["cell_admission_limits"] = {} - - assert profiling._shard_policy_matches_requested_modes( - stale, - expected, - family="gg", - modes=modes, - ) - - measurement["alpha_s"] = 0.2 - assert not profiling._shard_policy_matches_requested_modes( - stale, - expected, - family="gg", - modes=modes, - ) - - -def test_phase_refresh_does_not_queue_higher_work_after_lower_resource_failure( - tmp_path: Path, -) -> None: - output = tmp_path / "run" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "4", - "--lines", - "reference-fft", - ) - profiling._create_or_resume_manifest(arguments, output) - shard = profiling.SHARD_BY_NAME["gg-reference"] - failed = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 2) | { - "status": "failed", - "failure_category": "runtime-time-limit", - "failure_reason": "runtime cap", - "censors_higher_multiplicities": True, - } - report = study.compose_report( - profiling._shard_arguments(arguments, output, shard, 2), - {"gg": {"reference-fft": {"2": failed}}}, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard, 2), - report, - ) - - pending = profiling._refresh_phase_pending( - arguments, - output, - profiling._phase_work_items(arguments, output, 1), - active=(), - ) - merged = profiling._load_shard_report(arguments, output, shard, required=True) - - assert pending == [] - assert { - n: merged["cells"]["gg"]["reference-fft"][str(n)]["status"] for n in (2, 3, 4) - } == {2: "failed", 3: "skipped", 4: "skipped"} - assert profiling._shard_report_path(output, shard).is_file() - - -def test_overwrite_retains_queued_higher_result_after_lower_resource_failure( - tmp_path: Path, -) -> None: - output = tmp_path / "overwrite-frontier" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--lines", - "reference-fft", - "--overwrite", - ) - profiling._create_or_resume_manifest(arguments, output) - shard = profiling.SHARD_BY_NAME["gg-reference"] - failed = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 2) | { - "status": "failed", - "failure_category": "runtime-time-limit", - "failure_reason": "runtime cap", - "censors_higher_multiplicities": True, - } - measured = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 3) | { - "status": "measured", - "generation_seconds": 2.0, - "warm_seconds_per_point": 2.0e-6, - "max_rss_kib": 2048, - } - report = study.compose_report( - profiling._shard_arguments(arguments, output, shard), - {"gg": {"reference-fft": {"2": failed, "3": measured}}}, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard), report - ) - works = profiling._phase_work_items(arguments, output, 1) - overwrite_pending = {profiling._work_identity(work) for work in works} - - pending = profiling._refresh_phase_pending( - arguments, - output, - works, - active=(), - overwrite_pending=overwrite_pending, - ) - - assert [work.final_multiplicity for work in pending] == [2] - assert overwrite_pending == {("gg", "reference-fft", 2)} - retained = profiling._load_shard_report(arguments, output, shard, required=True) - assert retained["cells"]["gg"]["reference-fft"]["3"] == measured - - -def test_phase_launches_independent_multiplicity_workers_when_cores_allow( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "run" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "4", - "--lines", - "reference-fft", - "--cores", - "3", - "--poll-seconds", - "0.001", - ) - profiling._create_or_resume_manifest(arguments, output) - shard = profiling.SHARD_BY_NAME["gg-reference"] - launched: list[int] = [] - active_counts: list[int] = [] - - class FakeProcess: - def __init__(self, work: profiling.ShardWork) -> None: - self.pid = 12345 + work.final_multiplicity - self.returncode: int | None = None - self.work = work - - def poll(self) -> int | None: - if self.returncode is None: - cell = study._cell_base( - self.work.shard.family, - study.MODE_BY_KEY["reference-fft"], - self.work.final_multiplicity, - ) | {"status": "measured"} - report = study.compose_report( - profiling._shard_arguments( - arguments, - output, - self.work.shard, - self.work.final_multiplicity, - ), - { - self.work.shard.family: { - "reference-fft": {str(self.work.final_multiplicity): cell} - } - }, - ) - profiling._write_json_atomic( - profiling._shard_report_path( - output, - self.work.shard, - self.work.final_multiplicity, - ), - report, - ) - self.returncode = 0 - return self.returncode - - class FakeDashboard: - def update(self, _completed, *, phase, active) -> None: - assert phase == "phase 1" - active_counts.append(len(active)) - - def launch(_arguments, _output, work: profiling.ShardWork): - launched.append(work.final_multiplicity) - return profiling.ActiveJob( - shard=work.shard, - final_multiplicity=work.final_multiplicity, - owned_mode=work.owned_mode, - command=(), - process=FakeProcess(work), - stdout=io.BytesIO(), - stderr=io.BytesIO(), - sampler=object(), - claimed_cores=profiling._claimed_cores(arguments, work), - detail="", - ) - - monkeypatch.setattr(profiling, "_launch_shard", launch) - - profiling._phase(arguments, output, 1, FakeDashboard()) - - assert launched[:3] == [2, 3, 4] - assert max(active_counts) == 3 - merged = profiling._load_shard_report(arguments, output, shard, required=True) - assert study.selected_cells_complete( - merged, - family="gg", - modes=("reference-fft",), - multiplicities=(2, 3, 4), - ) - - -def test_phase_accepts_authoritative_failed_cell_from_nonzero_child( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "run" - arguments = _arguments( - "--output", - str(output), - "--families", - "ddbar", - "--multiplicities", - "9", - "--lines", - "amplicol", - "--cores", - "1", - "--poll-seconds", - "0.001", - ) - profiling._create_or_resume_manifest(arguments, output) - - class FakeProcess: - def __init__(self, work: profiling.ShardWork) -> None: - self.pid = 45678 - self.returncode: int | None = None - self.work = work - - def poll(self) -> int | None: - if self.returncode is None: - cell = study._cell_base( - self.work.shard.family, - study.MODE_BY_KEY[self.work.owned_mode], - self.work.final_multiplicity, - ) | { - "status": "failed", - "failure_category": "error", - "failure_reason": "legacy checkout contains tracked edits", - "censors_higher_multiplicities": False, - } - report = study.compose_report( - profiling._work_arguments(arguments, output, self.work), - { - self.work.shard.family: { - self.work.owned_mode: { - str(self.work.final_multiplicity): cell - } - } - }, - ) - report["status"] = "stopped-correctness-failure" - profiling._write_json_atomic( - profiling._work_report_path(output, self.work), - report, - ) - self.returncode = 1 - return self.returncode - - class FakeDashboard: - def update(self, _completed, *, phase, active) -> None: - assert phase == "phase 1" - - def launch(_arguments, _output, work: profiling.ShardWork): - return profiling.ActiveJob( - shard=work.shard, - final_multiplicity=work.final_multiplicity, - owned_mode=work.owned_mode, - command=(), - process=FakeProcess(work), - stdout=io.BytesIO(), - stderr=io.BytesIO(), - sampler=object(), - claimed_cores=1, - detail="", - ) - - monkeypatch.setattr(profiling, "_launch_shard", launch) - - profiling._phase(arguments, output, 1, FakeDashboard()) - report = profiling._publish_master(arguments, output) - - assert profiling._selected_completed_cells( - arguments, report, multiplicities=(9,) - ) == 1 - assert ( - profiling._selected_pending_cells(arguments, report, multiplicities=(9,)) == 0 - ) - assert ( - report["cells"]["ddbar"]["amplicol"]["9"]["failure_category"] == "error" - ) - - -def test_candidate_core_setting_is_passed_to_generation() -> None: - command = study._candidate_generation_command( - python="python", - family="gg", - final_multiplicity=3, - mode=study.MODE_BY_KEY["otf-fft"], - artifact=Path("artifact"), - batch_size=1, - optimization_cores=4, - ) - assert "evaluator.optimization.cores=4" in command - - -def test_matching_manifest_resumes_automatically_and_rejects_identity_change( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "run" - arguments = _arguments("--output", str(output), "--multiplicities", "2", "3") - first = profiling._create_or_resume_manifest(arguments, output) - assert profiling._create_or_resume_manifest(arguments, output) == first - - later = _arguments("--output", str(output), "--multiplicities", "4", "5") - expanded = profiling._create_or_resume_manifest(later, output) - assert expanded["requested_multiplicities"] == [4, 5] - assert expanded["active_multiplicities"] == [4, 5] - assert expanded["fill_history_multiplicities"] == [2, 3, 4, 5] - shard_arguments = profiling._shard_arguments( - later, output, profiling.SHARD_BY_NAME["ddbar-recurrence"] - ) - assert shard_arguments.fill_multiplicities == [4, 5] - - resource_changed = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--memory-limit-gib", - "64", - "--time-limit-seconds", - "7200", - ) - resource_updated = profiling._create_or_resume_manifest(resource_changed, output) - assert resource_updated["identity"]["resources"] == { - "candidate_optimization_cores": 1, - "per_cell_generation_timeout_seconds": 7200.0, - "per_cell_memory_limit_gib": 64.0, - "per_cell_runtime_timeout_seconds": 7200.0, - } - - target_changed = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--memory-limit-gib", - "64", - "--time-limit-seconds", - "7200", - "--target-seconds", - "30", - ) - target_updated = profiling._create_or_resume_manifest(target_changed, output) - assert target_updated["identity"]["scan"]["target_seconds"] == 30.0 - - summed = _arguments( - "--compare-helicity-sums", - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--memory-limit-gib", - "64", - "--time-limit-seconds", - "7200", - ) - with pytest.raises(profiling.ProfilingError, match="helicity_workload"): - profiling._create_or_resume_manifest(summed, output) - - scalar = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--batch-size", - "1", - "--memory-limit-gib", - "64", - "--time-limit-seconds", - "7200", - ) - with pytest.raises(profiling.ProfilingError, match="batch_size"): - profiling._create_or_resume_manifest(scalar, output) - - other_host = dict(first["identity"]["measurement_host"]) - other_host["node_sha256"] = "f" * 64 - monkeypatch.setattr( - profiling.madgraph, "measurement_host_identity", lambda: other_host - ) - with pytest.raises(profiling.ProfilingError, match="measurement_host"): - profiling._create_or_resume_manifest(resource_changed, output) - - -def test_render_arguments_inherit_helicity_workload_from_manifest( - tmp_path: Path, -) -> None: - output = tmp_path / "summed" - profiling._create_or_resume_manifest( - _arguments( - "--output", - str(output), - "--compare-helicity-sums", - "--multiplicities", - "2", - ), - output, - ) - - rendered = profiling._composition_arguments( - _arguments("--render", "--output", str(output)), output - ) - - assert rendered.compare_helicity_sums is True - assert profiling._helicity_workload(rendered) == "sum" - assert profiling._pdf_filename(rendered) == "summary_plots_final_helicity_sum.pdf" - - -def test_resume_manifest_allows_midrun_resource_limit_decreases( - tmp_path: Path, -) -> None: - output = tmp_path / "run" - initial = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--memory-limit-gib", - "800", - "--time-limit-seconds", - "360000", - ) - lowered = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--memory-limit-gib", - "200", - "--time-limit-seconds", - "36000", - ) - status = _arguments( - "--status", - "--output", - str(output), - "--multiplicities", - "2", - "--memory-limit-gib", - "100", - "--time-limit-seconds", - "18000", - ) - - profiling._create_or_resume_manifest(initial, output) - manifest = profiling._create_or_resume_manifest(lowered, output) - - assert manifest["identity"]["resources"] == { - "candidate_optimization_cores": 1, - "per_cell_generation_timeout_seconds": 36000.0, - "per_cell_memory_limit_gib": 200.0, - "per_cell_runtime_timeout_seconds": 36000.0, - } - assert profiling.status_payload(status)["requested_multiplicities"] == [2] - - -def test_existing_manifest_history_does_not_expand_current_multiplicity_request( - tmp_path: Path, -) -> None: - output = tmp_path / "run" - broad = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "--lines", - "reference-fft", - ) - profiling._create_or_resume_manifest(broad, output) - lower = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "3", - "--lines", - "reference-fft", - ) - - manifest = profiling._create_or_resume_manifest(lower, output) - work = profiling._phase_work_items(lower, output, 1) - plan = profiling.dry_run_plan(lower) - - assert manifest["requested_multiplicities"] == [2, 3] - assert manifest["fill_history_multiplicities"] == list(range(2, 10)) - assert [item.final_multiplicity for item in work] == [2, 3] - assert [job["n"] for job in plan["shards"]["gg-reference"]["jobs"]] == [2, 3] - - -def test_line_groups_track_history_but_schedule_only_requested_work( - tmp_path: Path, -) -> None: - output = tmp_path / "line-groups" - common = ("--output", str(output), "--madgraph-root", str(tmp_path / "mg5")) - reference = _arguments( - *common, - "--multiplicities", - "2", - "--lines", - "reference-fft", - ) - first = profiling._create_or_resume_manifest(reference, output) - assert first["requested_line_groups"] == ["reference-fft"] - reference_plan = profiling.dry_run_plan(reference) - assert { - name for name, shard in reference_plan["shards"].items() if shard["scheduled"] - } == {"gg-reference"} - assert reference_plan["madgraph"]["applicable"] is False - - otf = _arguments( - *common, - "--multiplicities", - "3", - "--lines", - "pyamplicol-otf", - ) - expanded = profiling._create_or_resume_manifest(otf, output) - assert expanded["requested_multiplicities"] == [3] - assert expanded["requested_line_groups"] == ["pyamplicol-otf"] - assert expanded["fill_history_multiplicities"] == [2, 3] - assert expanded["line_group_history"] == [ - "reference-fft", - "pyamplicol-otf", - ] - otf_plan = profiling.dry_run_plan(otf) - assert { - name for name, shard in otf_plan["shards"].items() if shard["scheduled"] - } == {"gg-reference", "gg-otf", "ddbar-amplicol", "ddbar-otf"} - assert otf_plan["madgraph"]["applicable"] is False - assert otf_plan["shards"]["gg-recurrence"]["argv"] is None - - with_madgraph = _arguments( - *common, - "--multiplicities", - "4", - "--lines", - "madgraph", - ) - final = profiling._create_or_resume_manifest(with_madgraph, output) - assert final["requested_multiplicities"] == [4] - assert final["requested_line_groups"] == ["madgraph"] - assert final["fill_history_multiplicities"] == [2, 3, 4] - assert final["line_group_history"] == [ - "reference-fft", - "pyamplicol-otf", - "madgraph", - ] - madgraph_plan = profiling.dry_run_plan(with_madgraph) - assert madgraph_plan["madgraph"]["applicable"] is True - assert madgraph_plan["madgraph"]["argv"] is not None - assert madgraph_plan["shards"]["ddbar-recurrence"]["scheduled"] is True - - -def test_concrete_line_selector_schedules_only_requested_fft_variant( - tmp_path: Path, -) -> None: - arguments = _arguments( - "--dry-run", - "--output", - str(tmp_path / "line-mode"), - "--multiplicities", - "2", - "--lines", - "recurrence-fft", - ) - - plan = profiling.dry_run_plan(arguments) - scheduled = {name for name, shard in plan["shards"].items() if shard["scheduled"]} - gg = plan["shards"]["gg-recurrence"] - ddbar = plan["shards"]["ddbar-recurrence"] - - assert plan["requested_line_groups"] == ["recurrence-fft"] - assert scheduled == { - "gg-reference", - "ddbar-amplicol", - "gg-recurrence", - "ddbar-recurrence", - } - assert gg["modes"] == ["reference-fft", "recurrence-fft"] - assert gg["owned_modes"] == ["recurrence-fft"] - assert ddbar["modes"] == ["amplicol", "recurrence-fft"] - assert ddbar["owned_modes"] == ["recurrence-fft"] - assert gg["argv"] is not None - assert "--mode recurrence-fft" in gg["shell_command"] - assert "--mode recurrence-direct" not in gg["shell_command"] - assert plan["shards"]["gg-otf"]["scheduled"] is False - - -def test_process_family_selector_limits_scheduled_shards_and_madgraph( - tmp_path: Path, -) -> None: - arguments = _arguments( - "--dry-run", - "--output", - str(tmp_path / "family-mode"), - "--multiplicities", - "2", - "--families", - "gg", - "--lines", - "recurrence-fft", - "madgraph", - "--madgraph-root", - str(tmp_path / "mg5"), - ) - - plan = profiling.dry_run_plan(arguments) - scheduled = {name for name, shard in plan["shards"].items() if shard["scheduled"]} - madgraph_argv = plan["madgraph"]["argv"] - - assert plan["requested_process_families"] == ["gg"] - assert scheduled == {"gg-reference", "gg-recurrence"} - assert plan["shards"]["ddbar-amplicol"]["scheduled"] is False - assert plan["madgraph"]["process_families"] == ["gg"] - assert madgraph_argv is not None - assert madgraph_argv[madgraph_argv.index("--family") + 1] == "gg" - - -def test_process_family_selector_rejects_inapplicable_line() -> None: - arguments = _arguments( - "--families", - "ddbar", - "--lines", - "reference-fft", - ) - with pytest.raises(profiling.ProfilingError, match="no applicable"): - profiling._validate_arguments(arguments) - - -def test_madgraph_completed_ignores_overlay_when_not_requested(tmp_path: Path) -> None: - output = tmp_path / "reference-only-with-overlay" - overlay = profiling._madgraph_overlay_path(output) - overlay.parent.mkdir(parents=True) - overlay.write_text( - json.dumps( - { - "host": profiling.madgraph.measurement_host_identity(), - "policy": { - "final_state_multiplicities": [2], - "maximum_measured_multiplicity": 6, - "family_maximum_measured_multiplicity": { - "gg": 5, - "ddbar": 6, - }, - "higher_multiplicity_policy": "not-applicable-protocol-scope", - }, - "runtime_series": { - "gg": { - "madgraph-standalone": { - "2": { - "status": "measured", - "warm_seconds_per_point": 1.0e-6, - } - } - } - }, - } - ), - encoding="utf-8", - ) - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--lines", - "reference-fft", - ) - - assert profiling._madgraph_completed(arguments, output) == 0 - - -def test_retry_invalidates_failed_selected_cell_without_dependency_count( - tmp_path: Path, -) -> None: - output = tmp_path / "retry" - initial = _arguments( - "--output", - str(output), - "--multiplicities", - "7", - "--families", - "gg", - "--lines", - "recurrence-direct", - "--memory-limit-gib", - "100", - ) - retry = _arguments( - "--output", - str(output), - "--multiplicities", - "7", - "--families", - "gg", - "--lines", - "recurrence-direct", - "--memory-limit-gib", - "160", - "--retry", - ) - profiling._create_or_resume_manifest(initial, output) - reference = profiling.SHARD_BY_NAME["gg-reference"] - recurrence = profiling.SHARD_BY_NAME["gg-recurrence"] - reference_cell = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 7) | { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - failed_cell = study._cell_base("gg", study.MODE_BY_KEY["recurrence-direct"], 7) | { - "status": "failed", - "failure_category": "memory-limit", - "failure_reason": "memory cap", - "censors_higher_multiplicities": True, - } - reference_report = study.compose_report( - profiling._shard_arguments(initial, output, reference), - {"gg": {"reference-fft": {"7": reference_cell}}}, - ) - recurrence_cells = { - "gg": { - "reference-fft": {"7": reference_cell}, - "recurrence-direct": {"7": failed_cell}, - } - } - recurrence_aggregate = study.compose_report( - profiling._shard_arguments(initial, output, recurrence), - recurrence_cells, - ) - recurrence_cell_report = study.compose_report( - profiling._shard_arguments(initial, output, recurrence, 7), - recurrence_cells, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, reference), - reference_report, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, recurrence), - recurrence_aggregate, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, recurrence, 7), - recurrence_cell_report, - ) - - manifest = profiling._create_or_resume_manifest(retry, output) - removed = profiling._apply_retry_invalidation(retry, output) - master = profiling._publish_master(retry, output) - per_cell = json.loads( - profiling._shard_report_path(output, recurrence, 7).read_text( - encoding="utf-8" - ) - ) - plan = profiling.dry_run_plan(retry) - - assert manifest["identity"]["resources"]["per_cell_memory_limit_gib"] == 160.0 - assert removed == 1 - assert profiling._phase_work_items(retry, output, 1) == () - assert [ - (work.shard.name, work.final_multiplicity) - for work in profiling._phase_work_items(retry, output, 2) - ] == [("gg-recurrence", 7)] - assert profiling._selected_completed_cells(retry, master, multiplicities=(7,)) == 0 - assert profiling._selected_pending_cells(retry, master, multiplicities=(7,)) == 1 - assert ( - per_cell["cells"]["gg"]["reference-fft"]["7"]["status"] == "measured" - ) - assert "7" not in per_cell["cells"]["gg"]["recurrence-direct"] - assert plan["shards"]["gg-reference"]["scheduled"] is False - assert plan["shards"]["gg-reference"]["jobs"] == [] - assert [job["n"] for job in plan["shards"]["gg-recurrence"]["jobs"]] == [7] - - -def test_overwrite_group_replaces_each_mode_only_when_its_worker_launches( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "overwrite" - initial = _arguments( - "--output", - str(output), - "--multiplicities", - "6", - "--families", - "ddbar", - "--lines", - "pyamplicol-recurrence", - ) - overwrite = _arguments( - "--output", - str(output), - "--multiplicities", - "6", - "--families", - "ddbar", - "--lines", - "pyamplicol-recurrence", - "--cores", - "2", - "--poll-seconds", - "0.001", - "--overwrite", - ) - profiling._create_or_resume_manifest(initial, output) - profiling._create_or_resume_manifest(overwrite, output) - dependency = profiling.SHARD_BY_NAME["ddbar-amplicol"] - recurrence = profiling.SHARD_BY_NAME["ddbar-recurrence"] - - def measured(mode: str, generation_seconds: float) -> dict[str, object]: - return study._cell_base("ddbar", study.MODE_BY_KEY[mode], 6) | { - "status": "measured", - "generation_seconds": generation_seconds, - "warm_seconds_per_point": generation_seconds / 1000.0, - "max_rss_kib": 1024, - } - - amplicol = measured("amplicol", 1.0) - old = { - "recurrence-direct": measured("recurrence-direct", 11.0), - "recurrence-fft": measured("recurrence-fft", 12.0), - } - dependency_report = study.compose_report( - profiling._shard_arguments(initial, output, dependency), - {"ddbar": {"amplicol": {"6": amplicol}}}, - ) - aggregate = study.compose_report( - profiling._shard_arguments(initial, output, recurrence), - { - "ddbar": { - "amplicol": {"6": amplicol}, - **{mode: {"6": cell} for mode, cell in old.items()}, - } - }, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, dependency), dependency_report - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, recurrence), aggregate - ) - legacy = study.compose_report( - profiling._shard_arguments(initial, output, recurrence, 6), - { - "ddbar": { - "amplicol": {"6": amplicol}, - **{mode: {"6": cell} for mode, cell in old.items()}, - } - }, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, recurrence, 6), legacy - ) - works = profiling._phase_work_items(overwrite, output, 2) - assert [work.owned_mode for work in works] == [ - "recurrence-direct", - "recurrence-fft", - ] - for work in works: - per_mode = study.compose_report( - profiling._work_arguments(initial, output, work), - { - "ddbar": { - "amplicol": {"6": amplicol}, - work.owned_mode: {"6": old[work.owned_mode]}, - } - }, - ) - profiling._write_json_atomic( - profiling._work_report_path(output, work), per_mode - ) - - overwrite_pending = {profiling._work_identity(work) for work in works} - initial_master = profiling._publish_master(overwrite, output) - assert ( - profiling._selected_completed_cells( - overwrite, - initial_master, - multiplicities=(6,), - ignored_cells=overwrite_pending, - ) - == 0 - ) - assert ( - profiling._selected_pending_cells( - overwrite, - initial_master, - multiplicities=(6,), - ignored_cells=overwrite_pending, - ) - == 2 - ) - assert all(profiling._work_report_path(output, work).is_file() for work in works) - - launched: list[str] = [] - - class FakeProcess: - def __init__(self, work: profiling.ShardWork) -> None: - self.pid = 23456 + len(launched) - self.returncode: int | None = None - self.work = work - - def poll(self) -> int | None: - if self.returncode is None: - replacement = measured( - self.work.owned_mode, - 101.0 if self.work.owned_mode == "recurrence-direct" else 102.0, - ) - report = study.compose_report( - profiling._work_arguments(overwrite, output, self.work), - { - "ddbar": { - "amplicol": {"6": amplicol}, - self.work.owned_mode: {"6": replacement}, - } - }, - ) - profiling._write_json_atomic( - profiling._work_report_path(output, self.work), report - ) - self.returncode = 0 - return self.returncode - - class FakeDashboard: - def update(self, _completed, *, phase, active) -> None: - assert phase == "phase 2" - - def launch(_arguments, _output, work: profiling.ShardWork): - seeded = json.loads( - profiling._work_report_path(output, work).read_text(encoding="utf-8") - ) - assert "6" not in seeded["cells"]["ddbar"][work.owned_mode] - if work.owned_mode == "recurrence-direct": - fft_work = next( - candidate - for candidate in works - if candidate.owned_mode == "recurrence-fft" - ) - fft_report = json.loads( - profiling._work_report_path(output, fft_work).read_text( - encoding="utf-8" - ) - ) - assert ( - fft_report["cells"]["ddbar"]["recurrence-fft"]["6"][ - "generation_seconds" - ] - == 12.0 - ) - legacy_report = json.loads( - profiling._shard_report_path(output, recurrence, 6).read_text( - encoding="utf-8" - ) - ) - assert "6" not in legacy_report["cells"]["ddbar"]["recurrence-direct"] - assert ( - legacy_report["cells"]["ddbar"]["recurrence-fft"]["6"][ - "generation_seconds" - ] - == 12.0 - ) - launched.append(work.owned_mode) - return profiling.ActiveJob( - shard=work.shard, - final_multiplicity=work.final_multiplicity, - owned_mode=work.owned_mode, - command=(), - process=FakeProcess(work), - stdout=io.BytesIO(), - stderr=io.BytesIO(), - sampler=object(), - claimed_cores=profiling._claimed_cores(overwrite, work), - detail="", - ) - - original_prepare = profiling._prepare_overwrite_work - original_seed = profiling._seed_cell_inputs - - def prepare(_arguments, _output, work: profiling.ShardWork): - removed = original_prepare(_arguments, _output, work) - aggregate_report = json.loads( - profiling._shard_report_path(output, recurrence).read_text( - encoding="utf-8" - ) - ) - assert "6" not in aggregate_report["cells"]["ddbar"][work.owned_mode] - legacy_report = json.loads( - profiling._shard_report_path(output, recurrence, 6).read_text( - encoding="utf-8" - ) - ) - assert "6" not in legacy_report["cells"]["ddbar"][work.owned_mode] - assert not profiling._work_cell_root(output, work).exists() - stale_sources = [] - for path in (output / "shards" / recurrence.name).rglob("report.json"): - payload = json.loads(path.read_text(encoding="utf-8")) - cell = payload.get("cells", {}).get("ddbar", {}).get( - work.owned_mode, {} - ).get("6") - if cell is not None: - stale_sources.append((str(path), cell.get("generation_seconds"))) - assert stale_sources == [] - merged_report = profiling._load_shard_report( - overwrite, output, recurrence, required=True - ) - merged_cell = merged_report["cells"]["ddbar"][work.owned_mode].get("6") - assert merged_cell is None, ( - merged_cell.get("status"), - merged_cell.get("generation_seconds"), - merged_cell.get("failure_reason"), - ) - return removed - - def seed(_arguments, _output, work: profiling.ShardWork): - original_seed(_arguments, _output, work) - seeded = json.loads( - profiling._work_report_path(output, work).read_text(encoding="utf-8") - ) - assert "6" not in seeded["cells"]["ddbar"][work.owned_mode] - - monkeypatch.setattr(profiling, "_prepare_overwrite_work", prepare) - monkeypatch.setattr(profiling, "_seed_cell_inputs", seed) - monkeypatch.setattr(profiling, "_launch_shard", launch) - - profiling._phase( - overwrite, - output, - 2, - FakeDashboard(), - overwrite_pending=overwrite_pending, - ) - - assert launched == ["recurrence-direct", "recurrence-fft"] - assert overwrite_pending == set() - merged = profiling._load_shard_report( - overwrite, output, recurrence, required=True - ) - assert ( - merged["cells"]["ddbar"]["recurrence-direct"]["6"][ - "generation_seconds" - ] - == 101.0 - ) - assert ( - merged["cells"]["ddbar"]["recurrence-fft"]["6"][ - "generation_seconds" - ] - == 102.0 - ) - - -def test_overwrite_and_retry_are_mutually_exclusive() -> None: - with pytest.raises(SystemExit): - _arguments("--overwrite", "--retry") - - -def test_narrow_line_selector_reuses_existing_broader_shard_report( - tmp_path: Path, -) -> None: - output = tmp_path / "line-mode-resume" - shard = profiling.SHARD_BY_NAME["gg-recurrence"] - broad = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--lines", - "pyamplicol-recurrence", - ) - narrow = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--lines", - "recurrence-fft", - ) - cells = {"gg": {}} - for mode in ("reference-fft", "recurrence-direct", "recurrence-fft"): - cells["gg"][mode] = { - "2": study._cell_base("gg", study.MODE_BY_KEY[mode], 2) - | { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - } - report = study.compose_report( - profiling._shard_arguments(broad, output, shard, 2), - cells, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard, 2), - report, - ) - - loaded = profiling._load_shard_report(narrow, output, shard, required=True) - family = loaded["cells"]["gg"] - - assert set(family) == {"reference-fft", "recurrence-fft"} - assert family["recurrence-fft"]["2"]["status"] == "measured" - - -def test_broad_line_selector_tops_up_existing_narrow_shard_reports( - tmp_path: Path, -) -> None: - output = tmp_path / "line-mode-top-up" - shard = profiling.SHARD_BY_NAME["gg-recurrence"] - direct = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--families", - "gg", - "--lines", - "recurrence-direct", - ) - fft = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--families", - "gg", - "--lines", - "recurrence-fft", - ) - broad = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--families", - "gg", - "--lines", - "pyamplicol-recurrence", - ) - cells = {"gg": {}} - for mode in ("reference-fft", "recurrence-direct", "recurrence-fft"): - cells["gg"][mode] = { - "2": study._cell_base("gg", study.MODE_BY_KEY[mode], 2) - | { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - } - direct_aggregate = study.compose_report( - profiling._shard_arguments(direct, output, shard), - { - "gg": { - mode: cells["gg"][mode] - for mode in ("reference-fft", "recurrence-direct") - } - }, - ) - fft_per_cell = study.compose_report( - profiling._shard_arguments(fft, output, shard, 2), - { - "gg": { - mode: cells["gg"][mode] - for mode in ("reference-fft", "recurrence-fft") - } - }, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard), - direct_aggregate, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard, 2), - fft_per_cell, - ) - - loaded = profiling._load_shard_report(broad, output, shard, required=True) - family = loaded["cells"]["gg"] - - assert set(family) == {"reference-fft", "recurrence-direct", "recurrence-fft"} - assert family["recurrence-direct"]["2"]["status"] == "measured" - assert family["recurrence-fft"]["2"]["status"] == "measured" - - -def test_mode_cell_report_run_root_does_not_block_shard_merge( - tmp_path: Path, -) -> None: - output = tmp_path / "mode-cell-run-root" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--families", - "ddbar", - "--lines", - "otf-direct", - "--compare-helicity-sums", - ) - shard = profiling.SHARD_BY_NAME["ddbar-otf"] - work = profiling.ShardWork(shard, 2, "otf-direct") - amplicol_cell = study._cell_base( - "ddbar", study.MODE_BY_KEY["amplicol"], 2, sum_helicities=True - ) | { - "status": "measured", - } - otf_cell = study._cell_base( - "ddbar", study.MODE_BY_KEY["otf-direct"], 2, sum_helicities=True - ) | { - "status": "measured", - } - report = study.compose_report( - profiling._work_arguments(arguments, output, work), - {"ddbar": {"amplicol": {"2": amplicol_cell}, "otf-direct": {"2": otf_cell}}}, - ) - profiling._write_json_atomic(profiling._work_report_path(output, work), report) - - loaded = profiling._load_shard_report(arguments, output, shard, required=True) - - assert loaded["cells"]["ddbar"]["otf-direct"]["2"]["status"] == "measured" - - -def test_output_render_rebuilds_master_from_manifest_history( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "render-history" - shard = profiling.SHARD_BY_NAME["gg-recurrence"] - broad = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--families", - "gg", - "--lines", - "pyamplicol-recurrence", - ) - narrow = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--families", - "gg", - "--lines", - "recurrence-direct", - ) - profiling._create_or_resume_manifest(broad, output) - profiling._create_or_resume_manifest(narrow, output) - cells = {"gg": {}} - for mode in ("reference-fft", "recurrence-direct", "recurrence-fft"): - cells["gg"][mode] = { - "2": study._cell_base("gg", study.MODE_BY_KEY[mode], 2) - | { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - } - per_cell = study.compose_report( - profiling._shard_arguments(broad, output, shard, 2), - cells, - ) - partial_aggregate = study.compose_report( - profiling._shard_arguments(narrow, output, shard), - { - "gg": { - mode: cells["gg"][mode] - for mode in ("reference-fft", "recurrence-direct") - } - }, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard, 2), - per_cell, - ) - profiling._write_json_atomic( - profiling._shard_report_path(output, shard), - partial_aggregate, - ) - rendered: dict[str, object] = {} - - def fake_run(command, **_kwargs): - command = tuple(command) - if Path(command[1]) == profiling.PLOT_TOOL: - rendered.update(json.loads(Path(command[2]).read_text(encoding="utf-8"))) - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes( - b"png" - ) - else: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_run_checked", fake_run) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - - profiling.render_snapshot(_arguments("--render", "--output", str(output))) - - assert rendered["cells"]["gg"]["recurrence-direct"]["2"]["status"] == "measured" - assert rendered["cells"]["gg"]["recurrence-fft"]["2"]["status"] == "measured" - - -def test_line_groups_reject_duplicates() -> None: - arguments = _arguments( - "--lines", - "pyamplicol-otf", - "pyamplicol-otf", - ) - with pytest.raises(profiling.ProfilingError, match="--lines"): - profiling._validate_arguments(arguments) - - -def test_reference_fft_root_is_explicit_in_identity_and_child_commands( - tmp_path: Path, -) -> None: - reference_root = tmp_path / "reference-fft" - arguments = _arguments( - "--output", - str(tmp_path / "run"), - "--multiplicities", - "2", - "--lines", - "reference-fft", - "--reference-fft-root", - str(reference_root), - ) - - plan = profiling.dry_run_plan(arguments) - assert plan["identity"]["tools"]["reference_fft_root"] == str(reference_root) - command = plan["shards"]["gg-reference"]["argv"] - assert command is not None - option = command.index("--reference-fft-root") - assert command[option + 1] == str(reference_root) - - -def test_status_rejects_workload_mismatch_with_existing_output(tmp_path: Path) -> None: - output = tmp_path / "fixed-run" - fixed = _arguments("--output", str(output), "--multiplicities", "2") - profiling._create_or_resume_manifest(fixed, output) - summed = _arguments( - "--status", - "--compare-helicity-sums", - "--output", - str(output), - "--multiplicities", - "2", - ) - - with pytest.raises(profiling.ProfilingError, match="identity differs"): - profiling.status_payload(summed) - - -def test_refresh_is_confined_to_recognized_output(tmp_path: Path) -> None: - output = tmp_path / "run" - arguments = _arguments("--output", str(output)) - profiling._create_or_resume_manifest(arguments, output) - retained = output / "owned.txt" - retained.write_text("owned", encoding="ascii") - - profiling._safe_refresh(output) - - assert not output.exists() - with pytest.raises(profiling.ProfilingError, match="ambiguous"): - profiling._safe_refresh(Path.home()) - unrecognized = tmp_path / "not-a-run" - unrecognized.mkdir() - with pytest.raises(profiling.ProfilingError, match="recognized"): - profiling._safe_refresh(unrecognized) - - -def test_first_refresh_of_a_missing_output_starts_cleanly(tmp_path: Path) -> None: - output = tmp_path / "new-run" - - assert profiling._safe_refresh(output) is False - assert not output.exists() - - -def test_refresh_lock_survives_output_deletion(tmp_path: Path) -> None: - output = tmp_path / "run" - arguments = _arguments("--output", str(output)) - profiling._create_or_resume_manifest(arguments, output) - first = profiling._acquire_execution_lock(output) - try: - profiling._safe_refresh(output) - assert not output.exists() - with pytest.raises(profiling.ProfilingError, match="another profiling"): - profiling._acquire_execution_lock(output) - finally: - first.close() - - -def test_refresh_rejects_an_active_madgraph_cache_writer( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "run" - arguments = _arguments("--output", str(output)) - profiling._create_or_resume_manifest(arguments, output) - retained = output / "owned.txt" - retained.write_text("owned", encoding="ascii") - monkeypatch.setattr(profiling.madgraph, "CACHE_LOCK_ROOT", tmp_path / "locks") - - cache_lock = profiling.madgraph._acquire_cache_lock( - profiling._madgraph_cache_path(output) - ) - try: - with pytest.raises( - profiling.ProfilingError, - match="cannot refresh while another MadGraph profiler holds", - ): - profiling._safe_refresh(output) - finally: - cache_lock.close() - - assert retained.read_text(encoding="ascii") == "owned" - - -def test_render_wrapper_holds_generation_lock_until_publication( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "run" - arguments = _arguments("--output", str(output)) - - class Lock: - closed = False - - def close(self) -> None: - self.closed = True - - lock = Lock() - monkeypatch.setattr(profiling, "_acquire_render_lock", lambda _output: lock) - - def render_locked(*_args, **_kwargs): - assert lock.closed is False - return output / "published.pdf" - - monkeypatch.setattr(profiling, "_render_snapshot_locked", render_locked) - - assert profiling.render_snapshot(arguments) == output / "published.pdf" - assert lock.closed is True - - -def test_refresh_rejects_symlinked_output(tmp_path: Path) -> None: - target = tmp_path / "target" - target.mkdir() - link = tmp_path / "linked-run" - link.symlink_to(target, target_is_directory=True) - - with pytest.raises(profiling.ProfilingError, match="symlinked"): - profiling._safe_refresh(link) - - assert target.is_dir() - - -def _partial_report(output: Path, *, summed: bool = False) -> dict[str, object]: - values = ["--output", str(output), "--multiplicities", "2"] - if summed: - values.append("--compare-helicity-sums") - arguments = _arguments(*values) - report = study._empty_report(profiling._master_arguments(arguments, output)) - report["status"] = "running" - return report - - -def _write_fake_pdf_output(command: tuple[str, ...]) -> None: - output = Path(command[command.index("--output") + 1]) - output.write_bytes(b"pdf") - output.with_suffix(".json").write_text("{}\n", encoding="utf-8") - - -def test_render_forwards_recola_results_to_plotter_only( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "render-recola" - source = tmp_path / "live.json" - recola_results = tmp_path / "recola.json" - source.write_text(json.dumps(_partial_report(output)), encoding="utf-8") - recola_results.write_text("{}\n", encoding="utf-8") - calls: list[tuple[str, ...]] = [] - - def fake_run(command, **_kwargs): - command = tuple(command) - calls.append(command) - if Path(command[1]) == profiling.PLOT_TOOL: - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - elif Path(command[1]) == profiling.PDF_TOOL: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_run_checked", fake_run) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_madgraph_render_source", - lambda *_args: pytest.fail("external report must not inherit output MG data"), - ) - - profiling.render_snapshot( - _arguments( - "--render", - "--output", - str(output), - "--campaign-report", - str(source), - "--recola-results", - str(recola_results), - "--main-y-range", - "1e-6", - "1e3", - "--ratio-y-range", - "0", - "5", - "--ratio-y-scale", - "linear", - "--main-include-lines", - "recola", - "madgraph", - "--main-veto-lines", - "pyamplicol-recurrence", - "--ratio-include-lines", - "recola", - "--ratio-veto-lines", - "madgraph", - ) - ) - - plot_command, pdf_command = calls - assert plot_command[plot_command.index("--recola-results") + 1] == str( - recola_results.resolve(strict=False) - ) - assert plot_command[plot_command.index("--main-y-range") + 1 :][0:2] == ( - "1e-06", - "1000.0", - ) - assert plot_command[plot_command.index("--ratio-y-range") + 1 :][0:2] == ( - "0.0", - "5.0", - ) - assert plot_command[plot_command.index("--ratio-y-scale") + 1] == "linear" - assert plot_command[plot_command.index("--main-include-lines") + 1 :][0:2] == ( - "recola", - "madgraph", - ) - assert plot_command[plot_command.index("--main-veto-lines") + 1] == ( - "pyamplicol-recurrence" - ) - assert plot_command[plot_command.index("--ratio-include-lines") + 1] == "recola" - assert plot_command[plot_command.index("--ratio-veto-lines") + 1] == "madgraph" - assert "--recola-results" not in pdf_command - assert "--main-y-range" not in pdf_command - assert "--ratio-y-range" not in pdf_command - assert "--ratio-y-scale" not in pdf_command - assert "--main-include-lines" not in pdf_command - assert "--main-veto-lines" not in pdf_command - assert "--ratio-include-lines" not in pdf_command - assert "--ratio-veto-lines" not in pdf_command - - -def test_render_axis_options_are_validated() -> None: - arguments = _arguments("--render", "--main-y-range", "0", "1") - - with pytest.raises(profiling.ProfilingError, match="logarithmic y-axis"): - profiling._validate_arguments(arguments) - - arguments = _arguments( - "--render", - "--ratio-y-scale", - "linear", - "--ratio-y-range", - "0", - "2", - ) - - profiling._validate_arguments(arguments) - - -def test_render_line_filters_are_render_only_and_deduplicated() -> None: - arguments = _arguments("--main-include-lines", "recola") - with pytest.raises(profiling.ProfilingError, match="valid only with --render"): - profiling._validate_arguments(arguments) - - arguments = _arguments("--render", "--main-include-lines", "recola", "recola") - with pytest.raises(profiling.ProfilingError, match="duplicates"): - profiling._validate_arguments(arguments) - - -def test_render_freezes_once_and_publishes_only_complete_set( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "render-run" - source = tmp_path / "live.json" - source.write_text(json.dumps(_partial_report(output)), encoding="utf-8") - original = source.read_bytes() - calls: list[tuple[str, ...]] = [] - - def fake_run(command, **_kwargs): - command = tuple(command) - calls.append(command) - if Path(command[1]) == profiling.PLOT_TOOL: - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - elif Path(command[1]) == profiling.PDF_TOOL: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_run_checked", fake_run) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_madgraph_render_source", - lambda *_args: pytest.fail("external report must not inherit output MG data"), - ) - arguments = _arguments( - "--render", - "--output", - str(output), - "--campaign-report", - str(source), - ) - - pdf = profiling.render_snapshot(arguments) - - assert source.read_bytes() == original - assert pdf.read_bytes() == b"pdf" - assert not profiling._canonical_pdf_path(arguments).exists() - assert (output / "render" / "current").is_symlink() - assert [Path(command[1]) for command in calls] == [ - profiling.PLOT_TOOL, - profiling.PDF_TOOL, - ] - assert calls[0][2] == calls[1][calls[1].index("--campaign-report") + 1] - - -def test_run_checked_suppresses_success_stdout( - capsys: pytest.CaptureFixture[str], -) -> None: - profiling._run_checked( - ( - sys.executable, - "-c", - "print('generated/path.png')", - ) - ) - - assert capsys.readouterr().out == "" - - -def test_default_campaign_render_atomically_publishes_canonical_pdf( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "default-run" - monkeypatch.setattr(profiling, "DEFAULT_FIXED_OUTPUT", output) - source = profiling._master_report_path(output) - source.parent.mkdir(parents=True) - source.write_text(json.dumps(_partial_report(output)), encoding="utf-8") - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - - def fake_run(command, **_kwargs): - command = tuple(command) - if Path(command[1]) == profiling.PLOT_TOOL: - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - else: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_run_checked", fake_run) - arguments = _arguments("--render") - - profiling.render_snapshot(arguments) - - assert profiling._canonical_pdf_path(arguments).read_bytes() == b"pdf" - assert profiling._canonical_pdf_path(arguments).with_suffix(".json").is_file() - - -def test_bare_render_falls_back_to_richest_compatible_existing_report( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "missing-default-run" - monkeypatch.setattr(profiling, "DEFAULT_FIXED_OUTPUT", output) - report_root = ( - profiling.CANONICAL_RESULTS_ROOT / "fft-scaling-study" / "raw" / "runs" - ) - sparse = report_root / "sparse" / "report.json" - richer = report_root / "richer" / "report.json" - summed = report_root / "summed" / "report.json" - for path, report in ( - (sparse, _partial_report(output)), - (richer, _partial_report(output)), - (summed, _partial_report(output, summed=True)), - ): - path.parent.mkdir(parents=True) - path.write_text(json.dumps(report), encoding="utf-8") - richer_payload = json.loads(richer.read_text(encoding="utf-8")) - richer_payload["cells"]["gg"]["reference-fft"]["2"] = { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - richer.write_text(json.dumps(richer_payload), encoding="utf-8") - - arguments = _arguments("--render") - - assert profiling._render_source(arguments, output) == richer.resolve() - - -def test_bare_render_compares_existing_primary_with_isolated_composite( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "default-run" - monkeypatch.setattr(profiling, "DEFAULT_FIXED_OUTPUT", output) - primary = profiling._master_report_path(output) - primary.parent.mkdir(parents=True) - primary.write_text(json.dumps(_partial_report(output)), encoding="utf-8") - composite = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-profiling" - / "runs" - / "extension" - / "composites" - / "selected" - / "report.json" - ) - richer = _partial_report(output) - richer["cells"]["ddbar"]["recurrence-direct"]["2"] = { - "status": "measured", - "generation_seconds": 1.0, - "warm_seconds_per_point": 1.0e-6, - "max_rss_kib": 1024, - } - composite.parent.mkdir(parents=True) - composite.write_text(json.dumps(richer), encoding="utf-8") - rendered_cell: dict[str, object] = {} - - def fake_run(command, **_kwargs): - command = tuple(command) - if Path(command[1]) == profiling.PLOT_TOOL: - frozen = json.loads(Path(command[2]).read_text(encoding="utf-8")) - rendered_cell.update(frozen["cells"]["ddbar"]["recurrence-direct"]["2"]) - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - else: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_run_checked", fake_run) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - arguments = _arguments("--render") - - assert profiling._render_source(arguments, output) == composite.resolve() - profiling.render_snapshot(arguments) - - assert rendered_cell["status"] == "measured" - assert profiling._canonical_pdf_path(arguments).read_bytes() == b"pdf" - - -def test_implicit_render_selects_only_workload_compatible_global_overlay( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "summed-default" - monkeypatch.setattr(profiling, "DEFAULT_SUM_OUTPUT", output) - primary = profiling._master_report_path(output) - report = _partial_report(output, summed=True) - report["runtime_series"] = {} - primary.parent.mkdir(parents=True) - primary.write_text(json.dumps(report), encoding="utf-8") - fixed_overlay = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-scaling-study" - / "data" - / "selected-scalar-madgraph-runtime-series-overlay.json" - ) - summed_overlay = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-profiling" - / "runs" - / "summed-extension" - / "madgraph" - / "overlay.json" - ) - for path in (fixed_overlay, summed_overlay): - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(json.dumps({"kind": profiling.madgraph.KIND}), encoding="utf-8") - - def attach(report_payload: dict[str, object], path: Path) -> None: - if path == fixed_overlay.resolve(): - raise profiling.ProfilingError("fixed-helicity overlay") - assert path == summed_overlay.resolve() - report_payload["runtime_series"] = { - "gg": { - "madgraph-standalone": { - "2": { - "status": "measured", - "warm_seconds_per_point": 1.0e-6, - } - } - } - } - - monkeypatch.setattr(profiling, "_attach_partial_overlay", attach) - arguments = _arguments("--render", "--compare-helicity-sums") - - selection = profiling._implicit_render_selection(arguments, output) - - assert selection == profiling.RenderSelection( - source=primary, - overlay=summed_overlay.resolve(), - ) - - -def test_summed_bare_render_preserves_n6_extension_and_n2_n5_madgraph( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "summed-default" - monkeypatch.setattr(profiling, "DEFAULT_SUM_OUTPUT", output) - primary = profiling._master_report_path(output) - base = _partial_report(output, summed=True) - for family in ("gg", "ddbar"): - for final_multiplicity in range(2, 6): - base["cells"][family]["recurrence-direct"][str(final_multiplicity)] = { - "status": "measured", - "warm_seconds_per_point": 1.0e-6, - } - primary.parent.mkdir(parents=True) - primary.write_text(json.dumps(base), encoding="utf-8") - composite = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-profiling" - / "runs" - / "summed-ddbar-n6" - / "composites" - / "selected" - / "report.json" - ) - extended = json.loads(json.dumps(base)) - extended["cells"]["ddbar"]["recurrence-direct"]["6"] = { - "status": "measured", - "warm_seconds_per_point": 2.0e-6, - } - composite.parent.mkdir(parents=True) - composite.write_text(json.dumps(extended), encoding="utf-8") - overlay = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-profiling" - / "runs" - / "summed-madgraph-n2-n5" - / "madgraph" - / "overlay.json" - ) - overlay.parent.mkdir(parents=True) - overlay.write_text(json.dumps({"kind": profiling.madgraph.KIND}), encoding="utf-8") - - def attach(report_payload: dict[str, object], path: Path) -> None: - assert path == overlay.resolve() - report_payload["runtime_series"] = { - family: { - "madgraph-standalone": { - str(final_multiplicity): { - "status": "measured", - "warm_seconds_per_point": 3.0e-6, - } - for final_multiplicity in range(2, 6) - } - } - for family in ("gg", "ddbar") - } - - rendered: dict[str, object] = {} - - def fake_run(command, **_kwargs): - command = tuple(command) - if Path(command[1]) == profiling.PLOT_TOOL: - rendered.update(json.loads(Path(command[2]).read_text(encoding="utf-8"))) - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - else: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_attach_partial_overlay", attach) - monkeypatch.setattr(profiling, "_run_checked", fake_run) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - arguments = _arguments("--render", "--compare-helicity-sums") - - assert profiling._implicit_render_selection( - arguments, output - ) == profiling.RenderSelection( - source=composite.resolve(), - overlay=overlay.resolve(), - ) - profiling.render_snapshot(arguments) - - assert rendered["cells"]["ddbar"]["recurrence-direct"]["6"]["status"] == ( - "measured" - ) - assert set(rendered["runtime_series"]["gg"]["madgraph-standalone"]) == { - "2", - "3", - "4", - "5", - } - assert profiling._canonical_pdf_path(arguments).read_bytes() == b"pdf" - - -def test_fixed_bare_render_combines_otf_frontier_with_valid_madgraph_overlay( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "fixed-default" - monkeypatch.setattr(profiling, "DEFAULT_FIXED_OUTPUT", output) - composite_report = _partial_report(output) - for family, modes in profiling.publication.FAMILY_MODES.items(): - for mode in modes: - for final_multiplicity in range(2, 8): - if (family, mode, final_multiplicity) == ("gg", "otf-fft", 7): - continue - composite_report["cells"][family][mode][str(final_multiplicity)] = { - "status": "measured", - "warm_seconds_per_point": 1.0e-6, - } - primary_report = json.loads(json.dumps(composite_report)) - for mode in ("otf-direct", "otf-fft"): - for final_multiplicity in (6, 7): - del primary_report["cells"]["ddbar"][mode][str(final_multiplicity)] - - def runtime_series(*, protocol_scoped: bool) -> dict[str, object]: - series: dict[str, object] = {} - for family in ("gg", "ddbar"): - measured_max = 5 if family == "gg" else 6 - cells: dict[str, object] = {} - for final_multiplicity in range(2, 10): - if final_multiplicity <= measured_max: - status = "measured" - elif protocol_scoped and final_multiplicity > 6: - status = "not-applicable" - elif final_multiplicity == measured_max + 1: - status = "failed" - else: - status = "skipped" - cells[str(final_multiplicity)] = {"status": status} - series[family] = {"madgraph-standalone": cells} - return series - - primary_report["runtime_series"] = runtime_series(protocol_scoped=False) - primary = profiling._master_report_path(output) - primary.parent.mkdir(parents=True) - primary.write_text(json.dumps(primary_report), encoding="utf-8") - composite = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-profiling" - / "runs" - / "fixed-otf-extension" - / "composites" - / "selected" - / "report.json" - ) - composite.parent.mkdir(parents=True) - composite.write_text(json.dumps(composite_report), encoding="utf-8") - overlay_series = runtime_series(protocol_scoped=True) - overlay = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-scaling-study" - / "data" - / "selected-fixed-madgraph-overlay.json" - ) - overlay.parent.mkdir(parents=True) - overlay.write_text( - json.dumps( - { - "kind": profiling.madgraph.KIND, - "policy": { - "final_state_multiplicities": list(range(2, 10)), - "helicity_workload": "fixed", - "warm_fixed_helicity": True, - "warm_helicity_sum": False, - "maximum_measured_multiplicity": 6, - "family_maximum_measured_multiplicity": { - "gg": 5, - "ddbar": 6, - }, - "higher_multiplicity_policy": ("not-applicable-protocol-scope"), - }, - "runtime_series": overlay_series, - } - ), - encoding="utf-8", - ) - - def attach(report_payload: dict[str, object], path: Path) -> None: - assert path == overlay.resolve() - payload = json.loads(path.read_text(encoding="utf-8")) - assert payload["policy"]["helicity_workload"] == "fixed" - for family_cells in payload["runtime_series"].values(): - mode_cells = family_cells["madgraph-standalone"] - assert { - mode_cells[str(final_multiplicity)]["status"] - for final_multiplicity in range(7, 10) - } == {"not-applicable"} - report_payload["runtime_series"] = json.loads( - json.dumps(payload["runtime_series"]) - ) - - rendered: dict[str, object] = {} - - def fake_run(command, **_kwargs): - command = tuple(command) - if Path(command[1]) == profiling.PLOT_TOOL: - rendered.update(json.loads(Path(command[2]).read_text(encoding="utf-8"))) - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - else: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_attach_partial_overlay", attach) - monkeypatch.setattr(profiling, "_run_checked", fake_run) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - arguments = _arguments("--render") - requested = set(profiling._selection(arguments)) - - assert profiling._render_inventory(primary_report, requested=requested)[0] == 70 - assert profiling._render_inventory(composite_report, requested=requested)[0] == 65 - assert profiling._implicit_render_selection( - arguments, output - ) == profiling.RenderSelection( - source=composite.resolve(), - overlay=overlay.resolve(), - ) - profiling.render_snapshot(arguments) - - for mode in ("otf-direct", "otf-fft"): - assert rendered["cells"]["ddbar"][mode]["6"]["status"] == "measured" - measured_madgraph = { - (family, int(final_multiplicity)) - for family, family_cells in rendered["runtime_series"].items() - for final_multiplicity, cell in family_cells["madgraph-standalone"].items() - if cell["status"] == "measured" - } - expected_madgraph = { - ("gg", final_multiplicity) for final_multiplicity in range(2, 6) - } | {("ddbar", final_multiplicity) for final_multiplicity in range(2, 7)} - assert measured_madgraph == expected_madgraph - assert profiling._canonical_pdf_path(arguments).read_bytes() == b"pdf" - - -def test_explicit_existing_output_ignores_richer_implicit_fallback( - tmp_path: Path, -) -> None: - output = tmp_path / "explicit" - primary = profiling._master_report_path(output) - primary.parent.mkdir(parents=True) - primary.write_text(json.dumps(_partial_report(output)), encoding="utf-8") - fallback = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-profiling" - / "runs" - / "extension" - / "composites" - / "selected" - / "report.json" - ) - richer = _partial_report(output) - richer["cells"]["gg"]["reference-fft"]["2"] = {"status": "measured"} - fallback.parent.mkdir(parents=True) - fallback.write_text(json.dumps(richer), encoding="utf-8") - arguments = _arguments("--render", "--output", str(output)) - - assert profiling._render_source(arguments, output) == primary - - -def test_explicit_output_does_not_use_implicit_render_fallback( - tmp_path: Path, -) -> None: - fallback = ( - profiling.CANONICAL_RESULTS_ROOT - / "fft-scaling-study" - / "data" - / "campaign-report-existing.json" - ) - fallback.parent.mkdir(parents=True) - fallback.write_text( - json.dumps(_partial_report(tmp_path / "unrelated")), encoding="utf-8" - ) - output = tmp_path / "explicit-missing" - arguments = _arguments("--render", "--output", str(output)) - - with pytest.raises(profiling.ProfilingError, match="no campaign snapshot yet"): - profiling.render_snapshot(arguments) - - assert not output.exists() - - -def test_missing_render_snapshot_fails_without_waiting_or_writing( - tmp_path: Path, -) -> None: - output = tmp_path / "missing" - arguments = _arguments("--render", "--output", str(output)) - with pytest.raises(profiling.ProfilingError, match="no campaign snapshot yet"): - profiling.render_snapshot(arguments) - assert not output.exists() - - -@pytest.mark.parametrize( - ("report_summed", "argument_summed"), ((False, True), (True, False)) -) -def test_render_rejects_report_workload_filename_mismatch( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - report_summed: bool, - argument_summed: bool, -) -> None: - output = tmp_path / "mismatch" - source = tmp_path / "report.json" - source.write_text( - json.dumps(_partial_report(output, summed=report_summed)), encoding="utf-8" - ) - values = ["--render", "--output", str(output), "--campaign-report", str(source)] - if argument_summed: - values.append("--compare-helicity-sums") - arguments = _arguments(*values) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_run_checked", - lambda *_args, **_kwargs: pytest.fail("mismatched workload must not render"), - ) - - with pytest.raises(profiling.ProfilingError, match="helicity workload"): - profiling.render_snapshot(arguments) - - assert not profiling._canonical_pdf_path(arguments).exists() - - -def test_workload_validation_does_not_import_matplotlib_plotter( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - report = _partial_report(tmp_path / "fixed") - real_import = builtins.__import__ - - def guarded_import(name, *args, **kwargs): - if name.endswith("fft_scaling_study_plots"): - raise AssertionError("workload validation imported the renderer") - return real_import(name, *args, **kwargs) - - monkeypatch.setattr(builtins, "__import__", guarded_import) - - profiling._validate_render_workload(_arguments(), report) - - -def test_render_prefers_matching_running_madgraph_progress( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "render-progress" - source = profiling._master_report_path(output) - source.parent.mkdir(parents=True) - source.write_text(json.dumps(_partial_report(output)), encoding="utf-8") - progress_path = profiling._madgraph_progress_path(output) - progress_path.parent.mkdir(parents=True) - progress_path.write_text("{}", encoding="ascii") - attached: list[Path] = [] - - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_matching_madgraph_progress", - lambda _arguments, _output: {"status": "running"}, - ) - monkeypatch.setattr( - profiling, - "_attach_partial_overlay", - lambda _report, path: attached.append(path), - ) - - def fake_run(command, **_kwargs): - command = tuple(command) - if Path(command[1]) == profiling.PLOT_TOOL: - plot_root = Path(command[3]) - plot_root.mkdir(parents=True) - for family in ("gg", "ddbar"): - for metric in ("generation", "warm-runtime", "rss"): - (plot_root / f"fullcolor-{family}-{metric}.png").write_bytes(b"png") - else: - _write_fake_pdf_output(command) - - monkeypatch.setattr(profiling, "_run_checked", fake_run) - arguments = _arguments("--render", "--output", str(output)) - - profiling.render_snapshot(arguments) - - assert attached == [progress_path] - - -def test_renderer_preflight_has_actionable_direct_requirements( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(profiling, "_command_available", lambda _command: True) - monkeypatch.setattr( - profiling.subprocess, - "run", - lambda *_args, **_kwargs: type("Result", (), {"returncode": 1})(), - ) - with pytest.raises(profiling.ProfilingError) as raised: - profiling._preflight_renderer(_arguments()) - message = str(raised.value) - assert "pip install" in message - assert "-e" not in message - for requirement in profiling.RENDER_REQUIREMENTS: - assert requirement in message - - -def test_renderer_requirements_match_the_project_extra() -> None: - with (ROOT / "pyproject.toml").open("rb") as stream: - project = tomllib.load(stream) - - assert ( - tuple(project["project"]["optional-dependencies"]["fft-profiling"]) - == profiling.RENDER_REQUIREMENTS - ) - - -def test_renderer_preflight_rejects_selected_python_version_mismatch( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(profiling, "_command_available", lambda _command: True) - monkeypatch.setattr( - profiling.subprocess, - "run", - lambda *_args, **_kwargs: type( - "Result", (), {"returncode": 0, "stdout": "0.0-incompatible\n"} - )(), - ) - - with pytest.raises(profiling.ProfilingError, match="profiling driver uses"): - profiling._preflight_renderer(_arguments()) - - -def _available_preflight_status(tmp_path: Path) -> dict[str, object]: - return { - "python": {"available": True, "path": sys.executable}, - "cxx": {"available": True, "path": "c++"}, - "fortran": {"available": True, "path": "gfortran"}, - "amplicol_root": { - "compatible": True, - "path": str(tmp_path / "amplicol"), - "probe_available": True, - "probe": str(tmp_path / "amplicol" / "amplicol_color_probe"), - }, - "reference_fft_root": { - "compatible": True, - "path": str(tmp_path / "reference-fft"), - }, - "madgraph_root": { - "compatible": True, - "path": str(tmp_path / "mg5"), - }, - } - - -def test_preflight_skips_pyamplicol_runtime_for_reference_only( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - arguments = _arguments( - "--output", - str(tmp_path / "run"), - "--lines", - "reference-fft", - ) - monkeypatch.setattr( - profiling, - "_dependency_status", - lambda _arguments: _available_preflight_status(tmp_path), - ) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_preflight_pyamplicol_runtime", - lambda _arguments: pytest.fail( - "reference-only scan should not import pyAmpliCol" - ), - ) - - profiling._preflight(arguments) - - -def test_preflight_checks_pyamplicol_runtime_for_ddbar_work( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - arguments = _arguments( - "--output", - str(tmp_path / "run"), - "--lines", - "amplicol", - ) - calls: list[argparse.Namespace] = [] - monkeypatch.setattr( - profiling, - "_dependency_status", - lambda _arguments: _available_preflight_status(tmp_path), - ) - monkeypatch.setattr(profiling, "_preflight_renderer", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_preflight_pyamplicol_runtime", - lambda runtime_arguments: calls.append(runtime_arguments), - ) - - profiling._preflight(arguments) - - assert calls == [arguments] - - -def test_pyamplicol_preflight_uses_checkout_source_path( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setenv("PYTHONPATH", "/already/configured") - arguments = _arguments() - - environment = profiling._python_source_environment(arguments) - - assert environment["PYTHONPATH"].split(os.pathsep)[:2] == [ - str(ROOT / "src"), - "/already/configured", - ] - - -def test_pyamplicol_preflight_reports_import_failure( - monkeypatch: pytest.MonkeyPatch, -) -> None: - captured_environment: dict[str, str] = {} - - def fake_run(*_args, **kwargs): - captured_environment.update(kwargs["env"]) - return type( - "Result", - (), - { - "returncode": 1, - "stdout": "", - "stderr": "candidate wheel source checkout is unavailable", - }, - )() - - monkeypatch.setattr(profiling.subprocess, "run", fake_run) - - with pytest.raises(profiling.ProfilingError) as raised: - profiling._preflight_pyamplicol_runtime(_arguments()) - - message = str(raised.value) - assert "just dev-install" in message - assert "candidate wheel source checkout is unavailable" in message - assert captured_environment["PYTHONPATH"].split(os.pathsep)[0] == str(ROOT / "src") - - -def test_executable_normalization_preserves_virtualenv_symlink( - tmp_path: Path, -) -> None: - launcher = tmp_path / "venv" / "bin" / "python" - launcher.parent.mkdir(parents=True) - launcher.symlink_to(Path(sys.executable)) - arguments = _arguments("--python", str(launcher)) - - profiling._normalize_executables(arguments) - - assert arguments.python == str(launcher.absolute()) - - -def test_progress_attachment_validates_one_immutable_read( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - live = tmp_path / "progress.json" - current = profiling.madgraph.measurement_host_identity() - payload = { - "kind": profiling.madgraph.PROGRESS_KIND, - "host": {key: current[key] for key in ("system", "machine", "python")}, - } - raw = json.dumps(payload).encode("utf-8") - live.write_bytes(raw) - validated_paths: list[Path] = [] - attached: list[profiling.selected.SourceReport] = [] - - def validate(path: Path): - validated_paths.append(path) - assert path != live - assert path.read_bytes() == raw - return payload - - monkeypatch.setattr(profiling.madgraph, "load_runtime_progress", validate) - monkeypatch.setattr( - profiling.selected, - "apply_runtime_series_source", - lambda _report, source: attached.append(source), - ) - - profiling._attach_partial_overlay({}, live) - - assert len(validated_paths) == 1 - assert attached[0].path == live - assert attached[0].sha256 == profiling.hashlib.sha256(raw).hexdigest() - - -def test_summed_overlay_replaces_stale_madgraph_omission_note( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - overlay = tmp_path / "summed-overlay.json" - current = profiling.madgraph.measurement_host_identity() - overlay.write_text( - json.dumps( - { - "kind": profiling.madgraph.KIND, - "host": {key: current[key] for key in ("system", "machine", "python")}, - "policy": { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - }, - } - ), - encoding="utf-8", - ) - report = { - "policy": { - "plot": { - "notes": [ - "Complete helicity sum; MadGraph is omitted because its " - "available series is fixed-helicity." - ] - } - } - } - monkeypatch.setattr( - profiling.selected, "apply_runtime_series_source", lambda *_args: None - ) - - profiling._attach_partial_overlay(report, overlay) - - notes = report["policy"]["plot"]["notes"] - assert all("omitted" not in note.lower() for note in notes) - assert notes == [ - profiling.LEGACY_MADGRAPH_NOTE, - "MadGraph standalone uses generated SMATRIX with USERHEL=-1; warmed " - "GOODHEL pruning remains enabled.", - ] - - -def test_madgraph_source_freeze_depends_only_on_source_cells(tmp_path: Path) -> None: - output = tmp_path / "mg-source" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--lines", - "madgraph", - ) - gg_source = study._cell_base("gg", study.MODE_BY_KEY["reference-fft"], 2) | { - "status": "measured" - } - ddbar_source = study._cell_base( - "ddbar", study.MODE_BY_KEY["recurrence-fft"], 2 - ) | {"status": "measured"} - unrelated = study._cell_base("gg", study.MODE_BY_KEY["otf-direct"], 2) | { - "status": "measured", - "generation_seconds": 1.0, - } - cells = { - "gg": { - "reference-fft": {"2": gg_source}, - "otf-direct": {"2": unrelated}, - }, - "ddbar": {"recurrence-fft": {"2": ddbar_source}}, - } - master = study.compose_report( - profiling._master_arguments(arguments, output), - cells, - ) - master["measurement_host"] = profiling.madgraph.measurement_host_identity() - profiling._write_json_atomic(profiling._master_report_path(output), master) - - path = profiling._freeze_madgraph_source(arguments, output) - frozen = json.loads(path.read_text(encoding="utf-8")) - - assert frozen["kind"] == profiling.madgraph.SOURCE_KIND - assert set(frozen["cells"]["gg"]) == {"reference-fft"} - assert set(frozen["cells"]["ddbar"]) == {"recurrence-fft"} - - master["cells"]["gg"]["otf-direct"]["2"]["generation_seconds"] = 2.0 - profiling._write_json_atomic(profiling._master_report_path(output), master) - - assert profiling._freeze_madgraph_source(arguments, output) == path - - -def test_helicity_sum_n2_n3_campaign_runs_summed_madgraph_and_renders_sum_pdf( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "sum-run" - arguments = _arguments( - "--compare-helicity-sums", - "--output", - str(output), - "--multiplicities", - "2", - "3", - ) - report = {"status": "running", "cells": {}} - phases: list[int] = [] - steps: list[str] = [] - - class FakeDashboard: - def __init__(self, **_kwargs) -> None: - pass - - def update(self, *_args, **_kwargs) -> None: - pass - - def finish(self) -> None: - pass - - monkeypatch.setattr(profiling, "Dashboard", FakeDashboard) - monkeypatch.setattr(profiling, "_preflight", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_publish_master", - lambda *_args, **_kwargs: report, - ) - def fake_phase(_arguments, _output, phase, _dashboard, **_kwargs): - phases.append(phase) - steps.append(f"phase-{phase}") - - monkeypatch.setattr(profiling, "_phase", fake_phase) - monkeypatch.setattr(profiling, "_completed_cells", lambda _report: 0) - monkeypatch.setattr( - profiling, "_selected_pending_cells", lambda *_args, **_kwargs: 0 - ) - monkeypatch.setattr( - profiling, "_selected_master_complete", lambda *_args, **_kwargs: True - ) - monkeypatch.setattr(profiling, "_madgraph_source_ready", lambda *_args: True) - madgraph_steps: list[str] = [] - - def fake_start_madgraph(*_args): - steps.append("madgraph-start") - madgraph_steps.append("start") - return None - - monkeypatch.setattr( - profiling, - "_start_madgraph_overlay", - fake_start_madgraph, - ) - monkeypatch.setattr( - profiling, - "_run_madgraph", - lambda *_args: pytest.fail("MadGraph should not block the campaign"), - ) - expected = output / "render" / "current" / "summary_plots_final_helicity_sum.pdf" - render_calls: list[bool] = [] - - def fake_render(_arguments, *, renderer_preflight=True): - render_calls.append(renderer_preflight) - return expected - - monkeypatch.setattr(profiling, "render_snapshot", fake_render) - - result = profiling.run_campaign(arguments) - - assert result == expected - assert phases == [1, 2] - assert steps == ["phase-1", "madgraph-start", "phase-2"] - assert madgraph_steps == ["start"] - assert render_calls == [False, False, False] - manifest = json.loads((output / "manifest.json").read_text(encoding="utf-8")) - assert manifest["identity"]["scan"]["helicity_workload"] == "sum" - - -def test_campaign_without_madgraph_line_group_skips_madgraph_phase( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "reference-only" - arguments = _arguments( - "--output", - str(output), - "--multiplicities", - "2", - "--lines", - "reference-fft", - ) - report = {"status": "running", "cells": {}} - monkeypatch.setattr(profiling, "_preflight", lambda _arguments: None) - monkeypatch.setattr( - profiling, - "_publish_master", - lambda *_args, **_kwargs: report, - ) - monkeypatch.setattr(profiling, "_phase", lambda *_args, **_kwargs: None) - monkeypatch.setattr(profiling, "_completed_cells", lambda _report: 0) - monkeypatch.setattr( - profiling, "_selected_pending_cells", lambda *_args, **_kwargs: 0 - ) - monkeypatch.setattr( - profiling, "_selected_master_complete", lambda *_args, **_kwargs: True - ) - monkeypatch.setattr( - profiling, - "_freeze_madgraph_source", - lambda *_args: pytest.fail("MadGraph source should not be frozen"), - ) - monkeypatch.setattr( - profiling, - "_run_madgraph", - lambda *_args: pytest.fail("MadGraph should not run"), - ) - expected = output / "render" / "current" / "summary_plots_final.pdf" - monkeypatch.setattr( - profiling, - "render_snapshot", - lambda *_args, **_kwargs: expected, - ) - - assert profiling.run_campaign(arguments) == expected - - -def test_partial_render_can_reuse_ordered_subset_madgraph_overlay( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "expanded" - overlay = profiling._madgraph_overlay_path(output) - overlay.parent.mkdir(parents=True) - overlay.write_text( - json.dumps( - { - "host": profiling.madgraph.measurement_host_identity(), - "policy": { - "final_state_multiplicities": [2, 3], - "maximum_measured_multiplicity": 6, - "family_maximum_measured_multiplicity": { - "gg": 5, - "ddbar": 6, - }, - "higher_multiplicity_policy": ("not-applicable-protocol-scope"), - }, - "runtime_series": {}, - } - ), - encoding="utf-8", - ) - arguments = _arguments("--output", str(output), "--multiplicities", "4") - monkeypatch.setattr( - profiling, - "_requested_multiplicities", - lambda _arguments, _output: (2, 3, 4), - ) - - assert profiling._matching_madgraph_overlay(arguments, output) is None - assert ( - profiling._matching_madgraph_overlay(arguments, output, require_exact=False) - == overlay - ) - assert profiling._madgraph_render_source(arguments, output) == overlay - - legacy_payload = json.loads(overlay.read_text(encoding="utf-8")) - current = profiling.madgraph.measurement_host_identity() - legacy_payload["host"] = { - key: current[key] for key in ("system", "machine", "python") - } - overlay.write_text(json.dumps(legacy_payload), encoding="utf-8") - assert profiling._matching_madgraph_overlay(arguments, output) is None - assert ( - profiling._matching_madgraph_overlay(arguments, output, require_exact=False) - == overlay - ) - assert profiling._madgraph_render_source(arguments, output) == overlay - - legacy_payload["host"]["machine"] = "foreign-machine" - overlay.write_text(json.dumps(legacy_payload), encoding="utf-8") - assert ( - profiling._matching_madgraph_overlay(arguments, output, require_exact=False) - is None - ) - - legacy_payload["host"] = { - key: current[key] for key in ("system", "machine", "python") - } | {"node_sha256": "malformed-modern-fingerprint"} - overlay.write_text(json.dumps(legacy_payload), encoding="utf-8") - assert ( - profiling._matching_madgraph_overlay(arguments, output, require_exact=False) - is None - ) - - -def test_partial_render_can_reuse_ordered_subset_madgraph_progress( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - output = tmp_path / "expanded-progress" - progress = profiling._madgraph_progress_path(output) - progress.parent.mkdir(parents=True) - progress.write_text("{}", encoding="utf-8") - payload = { - "status": "running", - "host": profiling.madgraph.measurement_host_identity(), - "policy": { - "final_state_multiplicities": [2, 3, 4, 5, 6], - "helicity_workload": "fixed", - "selected_process_families": ["gg", "ddbar"], - "family_maximum_measured_multiplicity": { - "gg": 5, - "ddbar": 6, - }, - }, - "runtime_series": {}, - } - arguments = _arguments("--output", str(output), "--multiplicities", "4") - monkeypatch.setattr( - profiling, - "_requested_multiplicities", - lambda _arguments, _output: (2, 3, 4, 5, 6, 7, 8, 9), - ) - monkeypatch.setattr( - profiling.madgraph, - "load_runtime_progress", - lambda _path: payload, - ) - - assert profiling._matching_madgraph_progress(arguments, output) == payload - assert profiling._madgraph_render_source(arguments, output) == progress - - payload["policy"]["final_state_multiplicities"] = [6, 5, 4] - assert profiling._matching_madgraph_progress(arguments, output) is None diff --git a/pyamplicol/tests/unit/test_fft_results_summary_pdf.py b/pyamplicol/tests/unit/test_fft_results_summary_pdf.py deleted file mode 100644 index 10b3773592..0000000000 --- a/pyamplicol/tests/unit/test_fft_results_summary_pdf.py +++ /dev/null @@ -1,255 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.developer import fft_results_summary_pdf as summary_pdf - - -def test_final_summary_pdf_contains_only_fresh_fixed_helicity_section() -> None: - pages = summary_pdf._plot_pages() - - assert len(pages) == 6 - assert {page.section for page in pages} == { - "Current-host fixed-helicity comparison (n=2..9)" - } - assert {page.path.parent.name for page in pages} == {"scalar-selected-n2-n9-final"} - assert summary_pdf._parser().get_default("output").name == "summary_plots_final.pdf" - assert ( - summary_pdf._parser().get_default("campaign_report") == summary_pdf.FINAL_REPORT - ) - - -def test_pdf_note_requires_and_records_fft_and_helicity_provenance() -> None: - note = summary_pdf._campaign_note( - { - "status": "complete", - "policy": { - "fft_enabled": True, - "selected_pyamplicol_color_contractions": { - "recurrence": ["direct", "symmetric-group-fft"], - "on-the-fly": ["direct", "symmetric-group-fft"], - }, - "measurement": { - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "warm_benchmark_batch_size": 128, - "compiled_fft_enabled": False, - "memory_watchdog_gib": 30.0, - "generation_timeout_seconds": 3600.0, - "runtime_timeout_seconds": 3600.0, - }, - } - } - ) - - assert note.splitlines() == [ - "--fft | recurrence: persisted all-helicity physical schedule | " - "OTF compact artifact: all runtime helicities", - "pyAmpliCol setup: generation + fresh load + first fixed-helicity " - "evaluation; OTF includes family warm-up", - "Reference setup: build/init/first pass | AmpliCol setup: " - "process/color-object generation", - "Warmed runtime measured separately | compiled FFT disabled", - "pyAmpliCol CLI profile: batch 128 (cyclic 10 points) | " - "Reference/AmpliCol: scalar aggregates normalized per point", - ] - assert "compiled FFT disabled" in note - - -def test_pdf_note_and_section_record_helicity_sum() -> None: - note = summary_pdf._campaign_note( - { - "policy": { - "fft_enabled": True, - "helicity_workload": "sum", - "selected_pyamplicol_color_contractions": { - "recurrence": ["direct", "symmetric-group-fft"], - "on-the-fly": ["direct", "symmetric-group-fft"], - }, - "measurement": { - "generation_helicity_coverage": "all", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "warm_benchmark_batch_size": 128, - "compiled_fft_enabled": False, - }, - } - } - ) - - assert "first complete helicity sum" in note - assert "Warmed runtime measured separately" in note - assert "immutable snapshot" in note - assert "create-raw bulk H family" in note - assert "analytic-nonzero H sweep" in note - pages = summary_pdf._plot_pages(helicity_workload="sum") - assert {page.section for page in pages} == { - "Current-host helicity-summed comparison (n=2..9)" - } - assert {page.path.parent.name for page in pages} == { - "scalar-helicity-sum-n2-n9-final" - } - - -def test_pdf_header_reserves_space_for_every_wrapped_note_line() -> None: - note = ( - "IN PROGRESS SNAPSHOT | absent cells are unattempted\n" - "--fft | recurrence: persisted all-helicity physical schedule | " - "OTF compact artifact: all runtime helicities\n" - "pyAmpliCol setup: generation + fresh load + first complete helicity " - "sum; OTF includes family warm-up\n" - "Reference setup: build/init/first pass | AmpliCol setup: process/raw-" - "library generation/build + immutable snapshot\n" - "Warmed runtime measured separately | compiled FFT disabled\n" - "pyAmpliCol CLI profile: batch 128 (cyclic 10 points) | " - "Reference/AmpliCol: scalar aggregates normalized per point\n" - "AmpliCol: create-raw bulk H family + probe-local zero pruning | " - "Reference FFT: analytic-nonzero H sweep" - ) - - lines = summary_pdf._campaign_note_lines(note, available_width=805.0) - - assert len(lines) >= len(note.splitlines()) - assert lines[-1].endswith("Reference FFT: analytic-nonzero H sweep") - header_height = summary_pdf._campaign_header_height(lines) - last_baseline_from_top = 15.5 + 8.0 * (len(lines) - 1) - assert header_height == 15.0 + 8.0 * len(lines) - assert header_height - last_baseline_from_top >= 7.0 - - -def test_pdf_note_rejects_fixed_helicity_cell_in_sum_campaign() -> None: - report = { - "policy": { - "fft_enabled": True, - "helicity_workload": "sum", - "selected_pyamplicol_color_contractions": { - "recurrence": ["direct", "symmetric-group-fft"], - "on-the-fly": ["direct", "symmetric-group-fft"], - }, - "measurement": { - "generation_helicity_coverage": "all", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "warm_benchmark_batch_size": 128, - "compiled_fft_enabled": False, - }, - }, - "runtime_series": { - "gg": { - "madgraph-standalone": { - "2": { - "status": "measured", - "protocol": {"helicity_summed": False}, - } - } - } - }, - } - - with pytest.raises(ValueError, match="not authenticated as helicity-summed"): - summary_pdf._campaign_note(report) - - -def test_pdf_rejects_contradictory_cell_workload_markers() -> None: - with pytest.raises(ValueError, match="markers are contradictory"): - summary_pdf._cell_helicity_workload( - {"helicity_workload": "sum", "warm_fixed_helicity": True} - ) - - -def test_pdf_rejects_disagreeing_policy_and_measurement_workloads() -> None: - with pytest.raises(ValueError, match="declarations disagree"): - summary_pdf._campaign_helicity_workload( - {"helicity_workload": "fixed"}, - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - }, - ) - - -def test_pdf_plot_manifest_rejects_changed_plot(tmp_path: Path) -> None: - campaign_report = tmp_path / "report.json" - campaign_report.write_text("{}\n", encoding="utf-8") - plot_directory = tmp_path / "plots" - plot_directory.mkdir() - hashes: dict[str, str] = {} - for index, filename in enumerate(summary_pdf.PLOT_FILENAMES): - plot_path = plot_directory / filename - plot_path.write_bytes(f"png-{index}".encode()) - hashes[filename] = summary_pdf._sha256(plot_path) - (plot_directory / summary_pdf.PLOT_MANIFEST_NAME).write_text( - json.dumps( - { - "kind": "pyamplicol-fft-scaling-plots", - "schema_version": 1, - "report_sha256": summary_pdf._sha256(campaign_report), - "helicity_workload": "sum", - "plots": hashes, - } - ), - encoding="utf-8", - ) - - summary_pdf._validate_plot_manifest( - plot_directory, campaign_report, "sum" - ) - (plot_directory / summary_pdf.PLOT_FILENAMES[0]).write_bytes(b"changed") - with pytest.raises(ValueError, match="hash does not match"): - summary_pdf._validate_plot_manifest( - plot_directory, campaign_report, "sum" - ) - - -def test_pdf_validates_and_publishes_raw_plot_data_sidecar(tmp_path: Path) -> None: - campaign_report = tmp_path / "report.json" - campaign_report.write_text("{}\n", encoding="utf-8") - plot_directory = tmp_path / "plots" - plot_directory.mkdir() - raw_data = ( - json.dumps( - { - "kind": "pyamplicol-fft-scaling-plot-data", - "schema_version": 1, - "report_sha256": summary_pdf._sha256(campaign_report), - "helicity_workload": "fixed", - "families": {"gg": {}, "ddbar": {}}, - }, - indent=2, - sort_keys=True, - ) - + "\n" - ).encode() - (plot_directory / summary_pdf.PLOT_DATA_NAME).write_bytes(raw_data) - - assert ( - summary_pdf._validated_plot_data_bytes( - plot_directory, campaign_report, "fixed" - ) - == raw_data - ) - destination = summary_pdf._publish_plot_data_sidecar( - raw_data, tmp_path / "summary_plots_final.pdf" - ) - - assert destination == tmp_path / "summary_plots_final.json" - assert destination.read_bytes() == raw_data - - -def test_pdf_note_rejects_missing_otf_comparison() -> None: - report = { - "policy": { - "fft_enabled": True, - "selected_pyamplicol_color_contractions": { - "recurrence": ["direct", "symmetric-group-fft"] - }, - } - } - - with pytest.raises(ValueError, match="for on-the-fly"): - summary_pdf._campaign_note(report) diff --git a/pyamplicol/tests/unit/test_fft_scaling_final_publication_report.py b/pyamplicol/tests/unit/test_fft_scaling_final_publication_report.py deleted file mode 100644 index e27c44bbcc..0000000000 --- a/pyamplicol/tests/unit/test_fft_scaling_final_publication_report.py +++ /dev/null @@ -1,743 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -from copy import deepcopy -from pathlib import Path -from typing import Any - -import pytest - -from tools.developer import ( - fft_scaling_final_publication_report as final_report, -) -from tools.developer import ( - fft_scaling_study_plots as plots, -) - -MEASUREMENT_HOST = { - "schema_version": 1, - "node_sha256": "0" * 64, - "system": "TestOS", - "machine": "test-machine", - "python": "3.test", -} - - -def _write_json(path: Path, payload: object) -> Path: - path.write_text(json.dumps(payload, sort_keys=True), encoding="utf-8") - return path - - -def _sha256(path: Path) -> str: - return hashlib.sha256(path.read_bytes()).hexdigest() - - -def _events(tmp_path: Path, family: str, n: int) -> tuple[list[str], list[str]]: - root = tmp_path / "events" / family / f"n{n}" - root.mkdir(parents=True, exist_ok=True) - paths: list[str] = [] - hashes: list[str] = [] - for index in range(1, 11): - path = root / f"point-{index:02d}.event" - path.write_text(f"{family} n={n} point={index}\n", encoding="utf-8") - paths.append(str(path)) - hashes.append(_sha256(path)) - return paths, hashes - - -def _campaign_cell(tmp_path: Path, family: str, mode: str, n: int) -> dict[str, Any]: - paths, _ = _events(tmp_path, family, n) - points = [float(100 * n + index) for index in range(1, 11)] - cell: dict[str, Any] = { - "status": "measured", - "family": family, - "mode": mode, - "label": mode, - "n": n, - "total_external": n + 2, - "process": final_report._process_expression(family, n), - "color_accuracy": "full", - "helicity": [1 if index % 2 else -1 for index in range(n + 2)], - "event_paths": paths, - "point_values": points[:1] if mode == "amplicol" else points, - "metrics": { - "generation_seconds": float(n), - "warm_seconds_per_point": n / 1_000_000.0, - "max_rss_kib": float(1000 + n), - }, - } - if mode in final_report.CANDIDATE_MODE_CONTRACT: - execution_mode, contraction = final_report.CANDIDATE_MODE_CONTRACT[mode] - cell.update( - { - "execution_mode": execution_mode, - "color_contraction": contraction, - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "numerical": {"available": True, "passes": True}, - } - ) - return cell - - -def _campaign(tmp_path: Path) -> dict[str, Any]: - cells = { - family: { - mode: { - str(n): _campaign_cell(tmp_path, family, mode, n) - for n in final_report.FINAL_MULTIPLICITIES - } - for mode in modes - } - for family, modes in final_report.FAMILY_MODES.items() - } - return { - "kind": final_report.CAMPAIGN_KIND, - "schema_version": 1, - "measurement_host": deepcopy(MEASUREMENT_HOST), - "status": "complete", - "failure_count": 0, - "policy": { - "kind": final_report.CAMPAIGN_KIND, - "schema_version": 1, - "run_root": str(tmp_path), - "fft_enabled": True, - "selected_pyamplicol_color_contractions": { - "recurrence": ["direct", "symmetric-group-fft"], - "on-the-fly": ["direct", "symmetric-group-fft"], - }, - "process_families": { - family: { - "expression": final_report.EXPECTED_EXPRESSIONS[family], - "ratio_reference": final_report.EXPECTED_RATIO_REFERENCES[family], - "modes": list(modes), - } - for family, modes in final_report.FAMILY_MODES.items() - }, - "final_state_multiplicities": list(final_report.FINAL_MULTIPLICITIES), - "total_external_particles": [ - n + 2 for n in final_report.FINAL_MULTIPLICITIES - ], - "measurement": { - "color_accuracy": "full", - "n_definition": "final-state-particle-count", - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "fixed_helicity": True, - "warm_benchmark_batch_size": 128, - "warm_sample_count": final_report.WARM_SAMPLE_COUNT, - "compiled_fft_enabled": False, - "memory_policy": "per-cell-strictly-below-publication-ceiling", - "requested_memory_ceiling_gib": 30.0, - "memory_watchdog_gib": 30.0, - "cell_admission_limits": { - "generation_seconds": {"operator": "<", "limit": 3600.0}, - "runtime_seconds": {"operator": "<", "limit": 3600.0}, - "peak_rss_gib": {"operator": "<", "limit": 30.0}, - }, - }, - }, - "cells": cells, - } - - -def _madgraph_cell( - campaign: dict[str, Any], - source_path: Path, - family: str, - n: int, -) -> dict[str, Any]: - mode = final_report.SOURCE_MODE[family] - source = campaign["cells"][family][mode][str(n)] - factor = final_report._madgraph_normalization_factor(family, n) - points = [float(value) / factor for value in source["point_values"]] - hashes = [_sha256(Path(path)) for path in source["event_paths"]] - warm = n / 10_000.0 - return { - "status": "measured", - "family": family, - "mode": "madgraph-standalone", - "label": "MadGraph standalone (fixed h)", - "n": n, - "total_external": n + 2, - "process": final_report._process_expression(family, n), - "helicity": source["helicity"], - "event_paths": source["event_paths"], - "event_sha256": hashes, - "point_values": points, - "matrix_element": points[0], - "generation_seconds": float(2 * n), - "warm_seconds_per_point": warm, - "max_rss_kib": float(2048 + n), - "warm_samples_seconds": [warm] * 10, - "metrics": { - "generation_seconds": float(2 * n), - "warm_seconds_per_point": warm, - "max_rss_kib": float(2048 + n), - }, - "numerical": { - "reference_mode": mode, - "normalization_factor_reference_per_madgraph": factor, - "passes": True, - }, - "protocol": { - "evaluator": "MATRIX(P,NHEL,IC)-direct", - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "helicity_summed": False, - "color_sum": "full-unaveraged", - "batch_size": 1, - "initialization_included": False, - }, - "runtime_refresh": { - "accepted": True, - "fresh_process": True, - "scope": "generation-resource-and-warm-runtime", - }, - "provenance": { - "smatrix_iden": final_report._expected_madgraph_iden(family, n), - "source_report": { - "path": str(source_path), - "sha256": _sha256(source_path), - "cell": f"cells.{family}.{mode}.{n}", - }, - }, - } - - -def _madgraph_scope_cell(family: str, n: int) -> dict[str, Any]: - measured_limit = final_report.MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY[family] - return { - "status": "not-applicable", - "family": family, - "mode": "madgraph-standalone", - "label": "MadGraph standalone (fixed h)", - "n": n, - "total_external": n + 2, - "process": final_report._process_expression(family, n), - "failure_category": ( - "protocol-scope-pure-gluon-n6" - if (family, n) == ("gg", 6) - else f"protocol-scope-n>{measured_limit}" - ), - "failure_reason": ( - f"final-plot protocol measures {family} MadGraph only through " - f"n={measured_limit}" - ), - "censors_higher_multiplicities": False, - "protocol_scope": { - "maximum_measured_multiplicity": measured_limit, - "disposition": "not-applicable", - }, - } - - -def _overlay(campaign: dict[str, Any], source_path: Path) -> dict[str, Any]: - cells = { - family: { - "madgraph-standalone": { - str(n): ( - _madgraph_cell(campaign, source_path, family, n) - if n - <= final_report.MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY[family] - else _madgraph_scope_cell(family, n) - ) - for n in final_report.FINAL_MULTIPLICITIES - } - } - for family in final_report.FAMILY_MODES - } - return { - "kind": final_report.selected.RUNTIME_SERIES_OVERLAY_KIND, - "schema_version": 1, - "host": deepcopy(MEASUREMENT_HOST), - "status": "complete", - "failure_count": 0, - "policy": { - "final_state_multiplicities": list(final_report.FINAL_MULTIPLICITIES), - "process_families": list(final_report.FAMILY_MODES), - "point_validation_count": 10, - "warm_timed_point_index": 1, - "warm_sample_count": final_report.WARM_SAMPLE_COUNT, - "generation_timeout_seconds": 3595.0, - "outer_memory_watchdog_gib": 30.0, - "watchdog_enforced_per_generation_build_and_runtime": True, - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "maximum_measured_multiplicity": 6, - "family_maximum_measured_multiplicity": ( - final_report.MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY - ), - "higher_multiplicity_policy": "not-applicable-protocol-scope", - "metric_scope": { - "generation_seconds": "cold to ready", - "warm_seconds_per_point": "fixed-helicity warm time", - "max_rss_kib": "conservative process-tree peak", - }, - }, - "summary": { - "runtime_series_status_counts": { - "measured": 9, - "not-applicable": 7, - } - }, - "runtime_series": cells, - } - - -def _inputs(tmp_path: Path) -> tuple[dict[str, Any], Path, dict[str, Any], Path]: - campaign = _campaign(tmp_path) - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay = _overlay(campaign, campaign_path) - overlay_path = _write_json(tmp_path / "madgraph.json", overlay) - return campaign, campaign_path, overlay, overlay_path - - -def test_merge_preserves_fresh_cells_and_policy_and_adds_all_metrics( - tmp_path: Path, -) -> None: - campaign, campaign_path, _, overlay_path = _inputs(tmp_path) - - report = final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - repeated = final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - assert report == repeated - assert report["kind"] == final_report.FINAL_KIND - expected_policy = deepcopy(campaign["policy"]) - expected_policy["measurement"].pop("fixed_helicity") - assert report["policy"] == expected_policy - assert report["policy"]["measurement"]["generation_helicity_coverage"] == "all" - assert report["policy"]["measurement"]["warm_fixed_helicity"] is True - assert report["cells"] == campaign["cells"] - assert report["cells"]["gg"]["otf-fft"]["9"]["execution_mode"] == ( - "on-the-fly" - ) - assert report["cells"]["ddbar"]["otf-direct"]["9"]["color_contraction"] == ( - "direct" - ) - assert report["policy"]["final_state_multiplicities"] == list(range(2, 10)) - assert ( - report["runtime_series"]["ddbar"]["madgraph-standalone"]["9"]["status"] - == "not-applicable" - ) - assert report["summary"] == { - "cell_status_counts": {"measured": 88}, - "runtime_series_status_counts": { - "measured": 9, - "not-applicable": 7, - }, - "total_failure_count": 0, - } - assert report["publication_provenance"]["campaign_report"]["sha256"] == ( - _sha256(campaign_path) - ) - assert report["publication_provenance"]["same_host_authenticated"] is True - - -def test_merge_rejects_cross_host_madgraph_overlay(tmp_path: Path) -> None: - _, campaign_path, overlay, _ = _inputs(tmp_path) - overlay["host"]["node_sha256"] = "1" * 64 - overlay_path = _write_json(tmp_path / "cross-host.json", overlay) - with pytest.raises( - final_report.PublicationMergeError, match="different measurement" - ): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -def test_merge_authenticates_a_native_smatrix_helicity_sum( - tmp_path: Path, -) -> None: - campaign = _campaign(tmp_path) - measurement = campaign["policy"]["measurement"] - measurement.update( - { - "alpha_s": 0.118, - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - } - ) - measurement.pop("fixed_helicity", None) - campaign["policy"]["plot"] = { - "notes": [ - "MadGraph is omitted because its available series is fixed-helicity." - ] - } - for family_modes in campaign["cells"].values(): - for mode, mode_cells in family_modes.items(): - if mode not in final_report.CANDIDATE_MODE_CONTRACT: - continue - for cell in mode_cells.values(): - cell["warm_fixed_helicity"] = False - cell["warm_helicity_sum"] = True - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay = _overlay(campaign, campaign_path) - overlay["policy"].update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - } - ) - for family in final_report.FAMILY_MODES: - source_mode = final_report.SUM_SOURCE_MODE[family] - measured_limit = final_report.MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY[ - family - ] - for n in range(2, measured_limit + 1): - cell = overlay["runtime_series"][family]["madgraph-standalone"][str(n)] - source = campaign["cells"][family][source_mode][str(n)] - cell.update( - { - "label": "MadGraph standalone (helicity sum)", - "alpha_s": 0.118, - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "timed_helicity_count": 2 ** (n + 2), - "helicity": source["helicity"], - "event_paths": source["event_paths"], - "event_sha256": [ - _sha256(Path(path)) for path in source["event_paths"] - ], - "point_values": source["point_values"], - "matrix_element": source["point_values"][0], - } - ) - cell["numerical"].update( - { - "reference_mode": source_mode, - "normalization_factor_reference_per_madgraph": 1.0, - } - ) - cell["protocol"].update( - { - "evaluator": "SMATRIX(P,ANS)-generated-complete-helicity-sum", - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "helicity_summed": True, - "timed_helicity_count": 2 ** (n + 2), - "helicity_sum_implementation": ( - "generated-SMATRIX-with-USERHEL-minus-one" - ), - "warmed_native_call_pruning": ( - "generated GOODHEL cache may skip structurally zero helicities" - ), - "color_sum": "generated-SMATRIX-summed-and-averaged", - } - ) - retained = tmp_path / "retained" / family / f"n{n}" - retained.mkdir(parents=True) - iden = final_report._expected_madgraph_iden(family, n) - matrix = retained / "matrix.f" - matrix.write_text( - " SUBROUTINE SMATRIX(P,ANS)\n" - f" INTEGER NCOMB\n PARAMETER (NCOMB={2 ** (n + 2)})\n" - " INTEGER NEXTERNAL\n" - " INTEGER NHEL(NEXTERNAL,NCOMB)\n" - f" DATA IDEN/{iden}/\n" - " ANS=ANS/DBLE(IDEN)\n" - " END\n", - encoding="utf-8", - ) - check = retained / "check_sa.f" - check.write_text( - " USERHEL=-1\n" - " CALL SMATRIX(P,V)\n" - " CALL SMATRIX(P,V)\n" - " CALL SMATRIX(P,V)\n", - encoding="ascii", - ) - cell["provenance"].update( - { - "source_alpha_s": 0.118, - "runtime_alpha_s": 0.118, - "timed_helicity_count": 2 ** (n + 2), - "matrix_sha256": _sha256(matrix), - "check_source_sha256": _sha256(check), - "retained": { - "matrix_source": str(matrix), - "matrix_sha256": _sha256(matrix), - "check_source": str(check), - "check_source_sha256": _sha256(check), - }, - "source_report": { - "path": str(campaign_path), - "sha256": _sha256(campaign_path), - "cell": f"cells.{family}.{source_mode}.{n}", - }, - } - ) - overlay_path = _write_json(tmp_path / "madgraph-sum.json", overlay) - - report = final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - assert report["status"] == "complete" - assert ( - report["runtime_series"]["gg"]["madgraph-standalone"]["2"][ - "helicity_workload" - ] - == "sum" - ) - assert report["policy"]["measurement"]["warm_fixed_helicity"] is False - assert report["policy"]["measurement"]["warm_helicity_sum"] is True - assert all( - "omitted" not in note.lower() - for note in report["policy"]["plot"]["notes"] - ) - - -def test_protocol_scoped_n2_n9_final_report_renders_all_six_plots( - tmp_path: Path, -) -> None: - _, campaign_path, _, overlay_path = _inputs(tmp_path) - report = final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - output = tmp_path / "plots" - - plots._render(report, output, dpi=72) - - assert {path.name for path in output.glob("*.png")} == { - f"fullcolor-{family}-{metric}.png" - for family in ("gg", "ddbar") - for metric in ("generation", "warm-runtime", "rss") - } - - -def test_merge_accepts_one_amplicol_validation_value_per_measured_cell( - tmp_path: Path, -) -> None: - campaign = _campaign(tmp_path) - for family_cells in campaign["cells"].values(): - for cell in family_cells["amplicol"].values(): - cell["point_values"] = cell["point_values"][:1] - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay_path = _write_json( - tmp_path / "madgraph.json", _overlay(campaign, campaign_path) - ) - - report = final_report.build_final_report( - campaign_path=campaign_path, - madgraph_overlay_path=overlay_path, - ) - - assert report["cells"]["gg"]["amplicol"]["2"]["point_values"] == [201.0] - - -def test_merge_rejects_more_than_one_amplicol_validation_value( - tmp_path: Path, -) -> None: - campaign = _campaign(tmp_path) - campaign["cells"]["gg"]["amplicol"]["2"]["point_values"] = [201.0, 202.0] - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay_path = _write_json( - tmp_path / "madgraph.json", _overlay(campaign, campaign_path) - ) - - with pytest.raises(final_report.PublicationMergeError, match="exactly 1"): - final_report.build_final_report( - campaign_path=campaign_path, - madgraph_overlay_path=overlay_path, - ) - - -@pytest.mark.parametrize( - ("path", "value", "message"), - ( - (("fft_enabled",), False, "record --fft"), - ( - ("measurement", "generation_helicity_coverage"), - "selected", - "generation_helicity_coverage", - ), - ( - ("measurement", "compiled_fft_enabled"), - True, - "compiled_fft_enabled", - ), - ), -) -def test_merge_rejects_incompatible_campaign_protocol( - tmp_path: Path, path: tuple[str, ...], value: object, message: str -) -> None: - campaign = _campaign(tmp_path) - target = campaign["policy"] - for key in path[:-1]: - target = target[key] - target[path[-1]] = value - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay_path = _write_json( - tmp_path / "madgraph.json", _overlay(campaign, campaign_path) - ) - - with pytest.raises(final_report.PublicationMergeError, match=message): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -def test_merge_rejects_measurement_after_a_campaign_frontier(tmp_path: Path) -> None: - campaign = _campaign(tmp_path) - failed = campaign["cells"]["gg"]["recurrence-direct"]["5"] - failed["status"] = "failed" - failed["failure_reason"] = "strict resource frontier" - failed["censors_higher_multiplicities"] = True - failed.pop("metrics") - failed.pop("helicity") - failed.pop("event_paths") - failed.pop("point_values") - campaign["status"] = "complete-with-failures" - campaign["failure_count"] = 1 - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay_path = _write_json( - tmp_path / "madgraph.json", _overlay(campaign, campaign_path) - ) - - with pytest.raises(final_report.PublicationMergeError, match="resumes measurement"): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -@pytest.mark.parametrize( - ("field", "value", "message"), - ( - ("execution_mode", "recurrence", r"execution_mode is wrong"), - ("color_contraction", "direct", r"color_contraction is wrong"), - ( - "generation_helicity_coverage", - "selected", - r"generation_helicity_coverage is wrong", - ), - ("warm_fixed_helicity", False, r"warm_fixed_helicity is wrong"), - ), -) -def test_merge_authenticates_otf_cell_protocol( - tmp_path: Path, field: str, value: object, message: str -) -> None: - campaign = _campaign(tmp_path) - campaign["cells"]["gg"]["otf-fft"]["4"][field] = value - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay_path = _write_json( - tmp_path / "madgraph.json", _overlay(campaign, campaign_path) - ) - - with pytest.raises(final_report.PublicationMergeError, match=message): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -@pytest.mark.parametrize( - ("mutation", "message"), - ( - ("numerical", "failed its numerical comparison"), - ("events", "must contain ten paths"), - ), -) -def test_merge_preserves_otf_numerical_and_event_checks( - tmp_path: Path, mutation: str, message: str -) -> None: - campaign = _campaign(tmp_path) - cell = campaign["cells"]["ddbar"]["otf-direct"]["3"] - if mutation == "numerical": - cell["numerical"]["passes"] = False - else: - cell["event_paths"] = cell["event_paths"][:-1] - campaign_path = _write_json(tmp_path / "report.json", campaign) - overlay_path = _write_json( - tmp_path / "madgraph.json", _overlay(campaign, campaign_path) - ) - - with pytest.raises(final_report.PublicationMergeError, match=message): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -def test_merge_preserves_a_madgraph_failure_frontier(tmp_path: Path) -> None: - _, campaign_path, overlay, _ = _inputs(tmp_path) - curve = overlay["runtime_series"]["gg"]["madgraph-standalone"] - curve["5"] = { - "status": "failed", - "family": "gg", - "mode": "madgraph-standalone", - "label": "MadGraph standalone (fixed h)", - "n": 5, - "total_external": 7, - "process": final_report._process_expression("gg", 5), - "failure_reason": "strict resource frontier", - } - overlay["status"] = "complete-with-failures" - overlay["failure_count"] = 1 - overlay["summary"]["runtime_series_status_counts"] = { - "failed": 1, - "measured": 8, - "not-applicable": 7, - } - overlay_path = _write_json(tmp_path / "madgraph.json", overlay) - - report = final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - assert report["status"] == "complete-with-failures" - assert report["failure_count"] == 1 - assert ( - report["runtime_series"]["gg"]["madgraph-standalone"]["9"]["status"] - == "not-applicable" - ) - - -def test_merge_rejects_madgraph_event_or_source_provenance(tmp_path: Path) -> None: - _, campaign_path, overlay, _ = _inputs(tmp_path) - overlay["runtime_series"]["gg"]["madgraph-standalone"]["2"]["event_sha256"][0] = ( - "0" * 64 - ) - overlay_path = _write_json(tmp_path / "madgraph.json", overlay) - - with pytest.raises(final_report.PublicationMergeError, match="SHA-256 provenance"): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -def test_merge_rejects_old_fixed_ddbar_normalization(tmp_path: Path) -> None: - _, campaign_path, overlay, _ = _inputs(tmp_path) - cell = overlay["runtime_series"]["ddbar"]["madgraph-standalone"]["4"] - cell["numerical"]["normalization_factor_reference_per_madgraph"] = 1.0 / 36.0 - cell["provenance"]["smatrix_iden"] = 36 - overlay_path = _write_json(tmp_path / "madgraph.json", overlay) - - with pytest.raises( - final_report.PublicationMergeError, - match=r"incompatible normalization|wrong generated SMATRIX denominator", - ): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) - - -def test_merge_rejects_non_strict_resource_metrics(tmp_path: Path) -> None: - _, campaign_path, overlay, _ = _inputs(tmp_path) - cell = overlay["runtime_series"]["ddbar"]["madgraph-standalone"]["3"] - cell["generation_seconds"] = 3600.0 - cell["metrics"]["generation_seconds"] = 3600.0 - overlay_path = _write_json(tmp_path / "madgraph.json", overlay) - - with pytest.raises(final_report.PublicationMergeError, match="exceeds one hour"): - final_report.build_final_report( - campaign_path=campaign_path, madgraph_overlay_path=overlay_path - ) diff --git a/pyamplicol/tests/unit/test_fft_scaling_selected_scalar_report.py b/pyamplicol/tests/unit/test_fft_scaling_selected_scalar_report.py deleted file mode 100644 index b44b19693e..0000000000 --- a/pyamplicol/tests/unit/test_fft_scaling_selected_scalar_report.py +++ /dev/null @@ -1,612 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path -from typing import Any - -import pytest - -from tools.developer import fft_scaling_selected_scalar_report as selected - - -def _measured(source: int, family: str, mode: str, n: int) -> dict[str, Any]: - warm = source + n / 100.0 - return { - "family": family, - "mode": mode, - "n": n, - "total_external": n + 2, - "process": selected._process_expression(family, n), - "helicity": [1] * (n + 2), - "event_paths": [ - f"/events/{family}/n{n}/point-{index:02d}.event" for index in range(1, 11) - ], - "label": mode, - "status": "measured", - "metrics": { - "generation_seconds": source * 10 + n, - "warm_seconds_per_point": warm, - "max_rss_kib": source * 100 + n, - }, - "point_values": [float(index) for index in range(1, 11)], - "probe": { - "warm_median_seconds": warm, - "warm_samples_seconds": [warm] * 10, - "point_values": [float(index) for index in range(1, 11)], - }, - } - - -def _report(source: int, *, high: bool, canonical: bool = False) -> dict[str, Any]: - multiplicities = range(7, 11) if high else range(2, 8) - modes = selected.HIGH_MODES if high else selected.FAMILY_MODES - cells: dict[str, dict[str, dict[str, dict[str, Any]]]] = {} - for family, family_modes in modes.items(): - cells[family] = {} - for mode in family_modes: - cells[family][mode] = { - str(n): _measured(source, family, mode, n) for n in multiplicities - } - if high: - for n in (8, 9): - cells["gg"]["amplicol"][str(n)] = { - "status": "skipped", - "failure_reason": "structural or prior resource censor", - } - cells["gg"]["recurrence-fft"]["9"] = { - "status": "failed", - "failure_category": "memory-limit", - } - cells["ddbar"]["amplicol"]["9"] = { - "status": "failed", - "failure_category": "memory-limit", - } - return { - "kind": selected.CANONICAL_KIND if canonical else selected.SCALAR_KIND, - "schema_version": 1, - "status": "complete-with-failures" if high else "complete", - "policy": { - "final_state_multiplicities": list(multiplicities), - "process_families": { - "gg": { - "expression": "g g > g g + (n-2)*g", - "modes": list(modes["gg"]), - "ratio_reference": "reference-fft", - }, - "ddbar": { - "expression": "d d~ > d d~ + (n-2)*g", - "modes": list(modes["ddbar"]), - "ratio_reference": "amplicol", - }, - }, - }, - "cells": cells, - } - - -def _write(path: Path, payload: object) -> Path: - path.write_text(json.dumps(payload), encoding="utf-8") - return path - - -def _sources(tmp_path: Path) -> tuple[Path, Path, Path]: - return ( - _write(tmp_path / "scalar.json", _report(1, high=False)), - _write( - tmp_path / "canonical.json", - _report(2, high=False, canonical=True), - ), - _write(tmp_path / "high.json", _report(3, high=True)), - ) - - -def _clean_runtime_overlay(report: dict[str, Any]) -> dict[str, Any]: - cells: dict[str, dict[str, dict[str, Any]]] = {} - for family, family_modes in selected.RUNTIME_TARGETS.items(): - cells[family] = {} - for mode, multiplicities in family_modes.items(): - cells[family][mode] = {} - for n in multiplicities: - base = report["cells"][family][mode][str(n)] - warm = float(100 + n) - sample_count = 1 if mode == "amplicol" else 10 - cell = { - "status": "measured", - "family": family, - "mode": mode, - "n": n, - "total_external": n + 2, - "process": base["process"], - "helicity": base["helicity"], - "event_paths": base["event_paths"], - "event_sha256": ["a" * 64] * 10, - "warm_seconds_per_point": warm, - "warm_samples_seconds": [warm] * sample_count, - "point_values": base["point_values"], - "runtime_refresh": { - "accepted": True, - "fresh_process": True, - "scope": "warm-runtime-only", - }, - } - if mode == "amplicol": - cell["adaptive_runtime_points"] = 7 - cells[family][mode][str(n)] = cell - censored: dict[str, dict[str, dict[str, Any]]] = {} - for (family, mode, n), status in selected.EXPECTED_CENSORED_CELLS.items(): - censored.setdefault(family, {}).setdefault(mode, {})[str(n)] = { - "status": status - } - return { - "kind": selected.CLEAN_RUNTIME_OVERLAY_KIND, - "schema_version": 1, - "status": "complete", - "cells": cells, - "censored_cells": censored, - } - - -def _madgraph_cell(family: str, n: int, status: str) -> dict[str, Any]: - cell: dict[str, Any] = { - "status": status, - "family": family, - "mode": "madgraph-standalone", - "label": "MadGraph standalone (fixed h)", - "n": n, - "total_external": n + 2, - "process": selected._process_expression(family, n), - } - if status == "measured": - warm = float(n) - cell.update( - { - "helicity": [1] * (n + 2), - "event_paths": [f"/events/mg/{family}/n{n}/{i}" for i in range(10)], - "event_sha256": ["b" * 64] * 10, - "warm_seconds_per_point": warm, - "warm_samples_seconds": [warm] * 10, - "metrics": { - "generation_seconds": warm * 10.0, - "warm_seconds_per_point": warm, - "max_rss_kib": warm * 1024.0, - }, - "matrix_element": 1.0, - "point_values": [1.0] * 10, - "protocol": { - "evaluator": "MATRIX(P,NHEL,IC)-direct", - "helicity_summed": False, - "color_sum": "full-unaveraged", - "batch_size": 1, - "initialization_included": False, - }, - } - ) - elif status == "not-applicable": - measured_limit = selected.MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY[family] - cell.update( - { - "failure_category": ( - "protocol-scope-pure-gluon-n6" - if (family, n) == ("gg", 6) - else f"protocol-scope-n>{measured_limit}" - ), - "failure_reason": ( - f"final-plot protocol measures {family} only through " - f"n={measured_limit}" - ), - "censors_higher_multiplicities": False, - "protocol_scope": { - "maximum_measured_multiplicity": measured_limit, - "disposition": "not-applicable", - }, - } - ) - else: - cell["failure_reason"] = "standalone source frontier" - return cell - - -def _madgraph_overlay() -> dict[str, Any]: - return { - "kind": selected.RUNTIME_SERIES_OVERLAY_KIND, - "schema_version": 1, - "policy": { - "final_state_multiplicities": list(selected.FINAL_MULTIPLICITIES), - "helicity_workload": "fixed", - "warm_fixed_helicity": True, - "warm_helicity_sum": False, - "family_maximum_measured_multiplicity": ( - selected.MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY - ), - }, - "runtime_series": { - "gg": { - "madgraph-standalone": { - str(n): _madgraph_cell( - "gg", - n, - ( - "measured" - if n <= 4 - else "failed" - if n == 5 - else "not-applicable" - ), - ) - for n in range(2, 10) - } - }, - "ddbar": { - "madgraph-standalone": { - str(n): _madgraph_cell( - "ddbar", - n, - ( - "failed" - if n == 2 - else "skipped" - if n <= 6 - else "not-applicable" - ), - ) - for n in range(2, 10) - } - }, - }, - } - - -def test_composite_selects_exact_cells_and_metric_sources(tmp_path: Path) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - ) - - assert report["policy"]["final_state_multiplicities"] == list(range(2, 10)) - assert report["policy"]["process_families"]["gg"]["modes"] == [ - "reference-fft", - "amplicol", - "recurrence-direct", - "recurrence-fft", - ] - assert set(report["cells"]["gg"]["recurrence-direct"]) == { - "2", - "3", - "4", - "5", - "6", - } - assert report["cells"]["gg"]["recurrence-direct"]["6"]["label"] == ( - "pyAmpliCol - recurrence (n≤6)" - ) - assert all( - "10" not in mode_cells - for family_cells in report["cells"].values() - for mode_cells in family_cells.values() - ) - assert report["summary"]["cell_status_counts"] == { - "failed": 2, - "measured": 46, - "skipped": 2, - } - - low_reference = report["cells"]["gg"]["reference-fft"]["6"] - assert low_reference["metrics"] == { - "generation_seconds": 26.0, - "warm_seconds_per_point": 1.06, - "max_rss_kib": 106.0, - } - low_candidate = report["cells"]["gg"]["recurrence-fft"]["6"] - assert low_candidate["metrics"] == { - "generation_seconds": 26.0, - "warm_seconds_per_point": 1.06, - "max_rss_kib": 206.0, - } - assert low_candidate["plot_provenance"]["metrics"] == { - "generation_seconds": "canonical-final:cells.gg.recurrence-fft.6", - "warm_seconds_per_point": "scalar-current:cells.gg.recurrence-fft.6", - "max_rss_kib": "canonical-final:cells.gg.recurrence-fft.6", - } - assert report["cells"]["gg"]["recurrence-fft"]["7"]["metrics"] == { - "generation_seconds": 37.0, - "warm_seconds_per_point": 3.07, - "max_rss_kib": 307.0, - } - - -def test_exact_runtime_overlay_updates_only_accepted_warm_cell( - tmp_path: Path, -) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - overlay = { - "kind": selected.OVERLAY_KIND, - "schema_version": 1, - "cells": { - "8": { - "warm_seconds_per_point": 0.125, - "warm_samples_seconds": [0.125] * 10, - "point_values": [float(index) for index in range(1, 11)], - "runtime_refresh": { - "accepted": True, - "archive_sha256": "a" * 64, - "paired_run_logs": ["p1-B.log", "p2-B.log", "p3-B.log"], - }, - } - }, - } - overlay_path = _write(tmp_path / "overlay.json", overlay) - - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - runtime_overlay_path=overlay_path, - ) - - cell = report["cells"]["gg"]["recurrence-fft"]["8"] - assert cell["metrics"]["warm_seconds_per_point"] == 0.125 - assert cell["probe"]["warm_samples_seconds"] == [0.125] * 10 - assert cell["runtime_refresh"]["accepted"] is True - assert cell["plot_provenance"]["metrics"]["warm_seconds_per_point"] == ( - "runtime-overlay:cells.8" - ) - assert ( - report["cells"]["gg"]["recurrence-fft"]["7"]["metrics"][ - "warm_seconds_per_point" - ] - == 3.07 - ) - - -def test_builder_fails_closed_on_missing_source_cell(tmp_path: Path) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - scalar = json.loads(scalar_path.read_text(encoding="utf-8")) - del scalar["cells"]["ddbar"]["recurrence-direct"]["6"] - _write(scalar_path, scalar) - - with pytest.raises( - selected.CompositeError, match=r"cells\.ddbar\.recurrence-direct\.6" - ): - selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - ) - - -def test_runtime_overlay_rejects_any_target_outside_n7_n8(tmp_path: Path) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - overlay_path = _write( - tmp_path / "overlay.json", - { - "kind": selected.OVERLAY_KIND, - "schema_version": 1, - "cells": {"9": {}}, - }, - ) - - with pytest.raises(selected.CompositeError, match="only gg recurrence-fft"): - selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - runtime_overlay_path=overlay_path, - ) - - -def test_clean_runtime_overlay_refreshes_exactly_all_measured_warm_cells( - tmp_path: Path, -) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - base = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - ) - overlay_path = _write(tmp_path / "clean-overlay.json", _clean_runtime_overlay(base)) - - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - runtime_overlay_path=overlay_path, - ) - - assert report["runtime_refresh"] == { - "scope": "warm-runtime-only", - "coverage": "complete", - "fresh_measured_cell_count": 46, - "preserved_resource_censored_cell_count": 4, - } - assert ( - report["summary"]["cell_status_counts"] == base["summary"]["cell_status_counts"] - ) - assert report["policy"]["measurement"]["warm_samples"] == { - "reference-fft": 10, - "pyamplicol": 10, - "amplicol": 1, - } - assert report["policy"]["plot"]["metric_source_boundaries"] == { - "generation_seconds": { - "source_boundary_after_n": 6, - "source_boundary_label": "n=2..6 / n=7..9 source boundary", - }, - "warm_seconds_per_point": None, - "max_rss_kib": { - "source_boundary_after_n": 6, - "source_boundary_label": "n=2..6 / n=7..9 source boundary", - }, - } - refreshed = report["cells"]["ddbar"]["recurrence-fft"]["9"] - original = base["cells"]["ddbar"]["recurrence-fft"]["9"] - assert refreshed["metrics"]["warm_seconds_per_point"] == 109.0 - assert ( - refreshed["metrics"]["generation_seconds"] - == original["metrics"]["generation_seconds"] - ) - assert refreshed["metrics"]["max_rss_kib"] == original["metrics"]["max_rss_kib"] - assert refreshed["runtime_refresh"]["fresh_process"] is True - assert refreshed["runtime_refresh"]["event_sha256"] == ["a" * 64] * 10 - assert set(report["cells"]["gg"]["recurrence-direct"]) == set("23456") - - -def test_clean_runtime_overlay_fails_closed_when_one_target_is_missing( - tmp_path: Path, -) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - base = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - ) - overlay = _clean_runtime_overlay(base) - del overlay["cells"]["ddbar"]["recurrence-fft"]["9"] - overlay_path = _write(tmp_path / "incomplete.json", overlay) - - with pytest.raises(selected.CompositeError, match="exactly 46 measurable"): - selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - runtime_overlay_path=overlay_path, - ) - - -def test_runtime_series_is_separate_from_the_46_existing_cells( - tmp_path: Path, -) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - overlay_path = _write(tmp_path / "madgraph.json", _madgraph_overlay()) - - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - runtime_series_overlay_path=overlay_path, - ) - - assert report["summary"]["cell_status_counts"] == { - "failed": 2, - "measured": 46, - "skipped": 2, - } - assert report["summary"]["runtime_series_status_counts"] == { - "failed": 2, - "measured": 3, - "not-applicable": 7, - "skipped": 4, - } - assert ( - report["runtime_series"]["gg"]["madgraph-standalone"]["4"][ - "warm_seconds_per_point" - ] - == 4.0 - ) - assert report["runtime_series"]["gg"]["madgraph-standalone"]["4"]["metrics"] == { - "generation_seconds": 40.0, - "warm_seconds_per_point": 4.0, - "max_rss_kib": 4096.0, - } - assert "madgraph-standalone" not in report["cells"]["gg"] - - -def test_runtime_series_uses_policy_warm_sample_count(tmp_path: Path) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - overlay = _madgraph_overlay() - overlay["policy"]["warm_sample_count"] = 1 - for family_series in overlay["runtime_series"].values(): - for cell in family_series["madgraph-standalone"].values(): - if cell["status"] == "measured": - cell["warm_samples_seconds"] = [cell["warm_seconds_per_point"]] - overlay_path = _write(tmp_path / "madgraph.json", overlay) - - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - runtime_series_overlay_path=overlay_path, - ) - - assert ( - report["runtime_series"]["gg"]["madgraph-standalone"]["2"][ - "warm_samples_seconds" - ] - == [2.0] - ) - - -def test_runtime_series_progress_accepts_authenticated_sparse_cells( - tmp_path: Path, -) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - ) - progress = _madgraph_overlay() - progress["kind"] = selected.RUNTIME_SERIES_PROGRESS_KIND - progress["policy"] = {"final_state_multiplicities": list(range(2, 10))} - progress["runtime_series"]["gg"]["madgraph-standalone"] = { - "2": progress["runtime_series"]["gg"]["madgraph-standalone"]["2"] - } - progress["runtime_series"]["ddbar"]["madgraph-standalone"] = {} - path = _write(tmp_path / "progress.json", progress) - - selected.apply_runtime_series_source( - report, - selected.SourceReport( - key="progress", - path=path, - sha256="0" * 64, - payload=progress, - ), - ) - - assert set(report["runtime_series"]["gg"]["madgraph-standalone"]) == {"2"} - assert report["runtime_series"]["ddbar"]["madgraph-standalone"] == {} - assert report["plot_provenance"]["source_reports"]["progress"] == { - "path": str(path), - "sha256": "0" * 64, - } - - -def test_summed_report_rejects_a_fixed_helicity_madgraph_overlay( - tmp_path: Path, -) -> None: - scalar_path, canonical_path, high_path = _sources(tmp_path) - report = selected.build_selected_report( - scalar_path=scalar_path, - canonical_path=canonical_path, - high_path=high_path, - ) - report["policy"]["measurement"].update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - } - ) - overlay = _madgraph_overlay() - overlay["policy"] = { - "final_state_multiplicities": list(range(2, 10)), - "helicity_workload": "fixed", - "warm_fixed_helicity": True, - "warm_helicity_sum": False, - } - path = _write(tmp_path / "fixed-madgraph.json", overlay) - - with pytest.raises(selected.CompositeError, match="differs from the report"): - selected.apply_runtime_series_source( - report, - selected.SourceReport( - key="fixed-madgraph", - path=path, - sha256="0" * 64, - payload=overlay, - ), - ) diff --git a/pyamplicol/tests/unit/test_fft_scaling_study.py b/pyamplicol/tests/unit/test_fft_scaling_study.py deleted file mode 100644 index 82ce9200f3..0000000000 --- a/pyamplicol/tests/unit/test_fft_scaling_study.py +++ /dev/null @@ -1,1889 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import importlib.util -import json -import statistics -import sys -from copy import deepcopy -from pathlib import Path -from types import SimpleNamespace - -import pytest - -ROOT = Path(__file__).resolve().parents[2] -SCRIPT = ROOT / "tools" / "developer" / "fft_scaling_study.py" -SPEC = importlib.util.spec_from_file_location("test_fft_scaling_study_module", SCRIPT) -assert SPEC is not None and SPEC.loader is not None -scaling = importlib.util.module_from_spec(SPEC) -sys.modules[SPEC.name] = scaling -SPEC.loader.exec_module(scaling) - - -def test_watchdog_peak_rss_accepts_a_rounded_zero_for_short_children() -> None: - stderr = ( - "memory-watchdog: command finished exit=0 peak_rss=0.000 GiB " - "peak_physical_footprint=0.001 GiB peak_guard=0.001 GiB" - ) - - assert scaling._parse_watchdog_peak_rss_kib(stderr) == 0 - - -def _pinned_summed_probe_source() -> bytes: - return ( - "program probe\n" - + scaling._SUMMED_AMPLICOL_FERMION_GUARD - + " continue\n" - + scaling._SUMMED_AMPLICOL_FALLBACK_GUARD - + " continue\n" - + scaling._SUMMED_AMPLICOL_HELPER_ANCHOR - + "end program probe\n" - ).encode("utf-8") - - -@pytest.mark.parametrize("body_raises", (False, True)) -def test_summed_amplicol_probe_overlay_restores_clean_pinned_source( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - body_raises: bool, -) -> None: - repository = tmp_path / "amplicol" - repository.mkdir() - source = repository / "amplicol_color_library_probe.f03" - original = _pinned_summed_probe_source() - source.write_bytes(original) - source.chmod(0o640) - original_stat = source.stat() - monkeypatch.setattr( - scaling.legacy_amplicol, - "validate_checkout", - lambda checked: checked.samefile(repository), - ) - monkeypatch.setattr( - scaling.legacy_amplicol, - "expected_revision", - lambda: "pinned-test-revision", - ) - evidence = tmp_path / "evidence" - captured: dict[str, object] = {} - - def exercise() -> None: - with scaling._summed_amplicol_probe_source_overlay( - repository, evidence - ) as record: - captured.update(record) - patched = source.read_bytes() - assert patched != original - assert b"fermion_relabel_is_unique" in patched - snapshot = evidence / "amplicol_color_library_probe.f03" - assert snapshot.read_bytes() == patched - if body_raises: - raise RuntimeError("body failed") - - if body_raises: - with pytest.raises(RuntimeError, match="body failed"): - exercise() - else: - exercise() - - restored_stat = source.stat() - assert source.read_bytes() == original - assert restored_stat.st_mode == original_stat.st_mode - assert restored_stat.st_size == original_stat.st_size - assert restored_stat.st_mtime_ns == original_stat.st_mtime_ns - manifest = json.loads((evidence / "provenance.json").read_text()) - assert manifest["revision"] == "pinned-test-revision" - assert manifest["restoration"]["status"] == "restored" - assert manifest["restoration"]["body_exit"] == ( - "exception" if body_raises else "success" - ) - assert captured["original_sha256"] != captured["patched_sha256"] - - -def test_summed_amplicol_campaign_skips_racy_preflight_checkout_validation( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - study_root = tmp_path / "study" - repository = tmp_path / "amplicol" - repository.mkdir() - monkeypatch.setattr(scaling, "STUDY_ROOT", study_root) - monkeypatch.setattr(scaling, "_study_environment", lambda _python: {}) - monkeypatch.setattr( - scaling, - "_acquire_campaign_lock", - lambda: (tmp_path / "campaign.lock").open("a+", encoding="utf-8"), - ) - monkeypatch.setattr( - scaling.legacy_amplicol, - "validate_checkout", - lambda _repository: pytest.fail( - "summed AmpliCol validation belongs inside the source overlay lock" - ), - ) - - def fake_inputs( - _report: object, _run_root: Path, family: str, final_multiplicity: int - ) -> tuple[tuple[Path, ...], tuple[int, ...]]: - assert family == "ddbar" - return (Path("event"),), scaling.fixed_ddbar_helicity(final_multiplicity) - - def fake_amplicol_cell(**kwargs: object) -> dict[str, object]: - assert kwargs["arguments"].compare_helicity_sums is True - family = str(kwargs["family"]) - final_multiplicity = int(kwargs["final_multiplicity"]) - return scaling._cell_base( - family, - scaling.MODE_BY_KEY["amplicol"], - final_multiplicity, - sum_helicities=True, - ) | {"status": "measured"} - - monkeypatch.setattr(scaling, "_inputs", fake_inputs) - monkeypatch.setattr(scaling, "_amplicol_cell", fake_amplicol_cell) - arguments = scaling._parser().parse_args( - ( - "--run-id", - "summed-amplicol", - "--min-n", - "2", - "--max-n", - "2", - "--family", - "ddbar", - "--mode", - "amplicol", - "--amplicol-repository", - str(repository), - "--compare-helicity-sums", - ) - ) - scaling._validate_arguments(arguments) - - report = scaling._campaign(arguments) - - assert report["cells"]["ddbar"]["amplicol"]["2"]["status"] == "measured" - - -def _amplicol_timing_output(points: int, total_seconds: float) -> str: - return ( - "AmpliCol colour probe\n" - f"points {points}\n" - "generation setup 0.125 50.0% outside-runtime\n" - f"total {total_seconds:.17g} 100.0%\n" - ) - - -def test_amplicol_warm_sampling_grows_and_restarts_one_fixed_aggregate() -> None: - calls: list[tuple[int, int, int]] = [] - - def run_sample(sample_set: int, sample: int, repetitions: int) -> str: - calls.append((sample_set, sample, repetitions)) - total = 0.20 if sample_set == 1 else 0.36 + sample * 0.001 - return _amplicol_timing_output(repetitions, total) - - measured = scaling._collect_amplicol_warm_samples( - seed_points=10, - seed_total_seconds=0.10, - target_seconds=0.25, - run_sample=run_sample, - ) - - assert calls == [(1, 1, 27), (2, 1, 36)] - assert measured.repetitions == 36 - assert measured.sample_set_attempts == 2 - assert len(measured.samples_seconds) == 1 - assert min(measured.sample_totals_seconds) >= 0.25 - assert statistics.median(measured.samples_seconds) == pytest.approx(0.361 / 36) - - -def test_amplicol_timing_parser_retains_the_aggregate_duration() -> None: - output = _amplicol_timing_output(40, 0.4) - - assert scaling._parse_amplicol_timing_aggregate(output) == (0.125, 0.4, 40) - assert scaling._parse_amplicol_timing(output) == (0.125, 0.01, 40) - - -def test_amplicol_cell_uses_fresh_fixed_samples_and_program_rss( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - repository = tmp_path / "amplicol" - repository.mkdir() - event = tmp_path / "event" - event.write_text("mock event\n", encoding="utf-8") - helicity = (-1, 1, -1, 1) - momenta = ( - (500.0, 0.0, 0.0, 500.0), - (500.0, 0.0, 0.0, -500.0), - (500.0, 500.0, 0.0, 0.0), - (500.0, -500.0, 0.0, 0.0), - ) - entry = scaling.legacy_amplicol.ProcessEntry(1, 1, (1, -1, 1, -1), (1, 2, 3, 4)) - monkeypatch.setattr(scaling, "_read_event", lambda _path: (momenta, helicity)) - monkeypatch.setattr( - scaling.legacy_amplicol, "parse_process_file", lambda _path: [entry] - ) - monkeypatch.setattr( - scaling.legacy_amplicol, "process_pdgs", lambda _process: entry.process_pdgs - ) - monkeypatch.setattr( - scaling.legacy_amplicol, - "select_generated_process_entry", - lambda *_args, **_kwargs: (entry, [entry]), - ) - monkeypatch.setattr( - scaling.legacy_amplicol, - "_permutation", - lambda source, _target: tuple(range(len(source))), - ) - monkeypatch.setattr( - scaling.legacy_amplicol, - "_ordered_binary64_momenta", - lambda _source, _target, values: values, - ) - monkeypatch.setattr( - scaling.legacy_amplicol, - "_parse_probe_output", - lambda _output: SimpleNamespace(value=2.0), - ) - - calls: list[dict[str, object]] = [] - - def fake_run_watched( - command: tuple[str, ...], **kwargs: object - ) -> scaling.performance.WatchedCompletedProcess: - log_path = Path(str(kwargs["log_path"])) - environment = dict(kwargs["environment"]) - watchdog_report = Path(str(kwargs["watchdog_report_path"])) - calls.append( - { - "log_path": log_path, - "environment": environment, - "watchdog_report": watchdog_report, - } - ) - if log_path.name == "process-generation.json": - return scaling.performance.WatchedCompletedProcess( - command, - 0, - "", - "memory-watchdog: peak_rss=0.001 GiB peak_guard=0.009 GiB\n", - elapsed_seconds=1.0, - log_write_seconds=0.0, - timed_out=False, - timeout_cleanup="not-required", - peak_rss_kib=1_500, - peak_guard_kib=9_000, - ) - - if log_path.name == "probe.json": - points, total, child_rss = 10, 0.10, 1_100 - elif "warm-sample-set-01" in log_path.name: - sample = int(log_path.stem.rsplit("-", 1)[1]) - points = 27 - total = 0.20 - child_rss = 1_200 + 100 * sample - else: - sample = int(log_path.stem.rsplit("-", 1)[1]) - points = 36 - total = 0.36 + sample * 0.001 - child_rss = 1_500 + 100 * sample - stderr = ( - f"{scaling.RSS_MARKER} {child_rss}\n" - "memory-watchdog: peak_rss=0.008 GiB peak_guard=0.010 GiB\n" - ) - return scaling.performance.WatchedCompletedProcess( - command, - 0, - _amplicol_timing_output(points, total), - stderr, - elapsed_seconds=0.5, - log_write_seconds=0.0, - timed_out=False, - timeout_cleanup="not-required", - peak_rss_kib=8_000, - peak_guard_kib=10_000, - ) - - monkeypatch.setattr(scaling.performance, "_run_watched", fake_run_watched) - arguments = scaling._parser().parse_args( - ( - "--run-id", - "amplicol-protocol", - "--family", - "ddbar", - "--mode", - "amplicol", - "--batch-size", - "1", - "--target-seconds", - "0.25", - "--python", - sys.executable, - "--amplicol-repository", - str(repository), - ) - ) - - cell = scaling._amplicol_cell( - arguments=arguments, - family="ddbar", - final_multiplicity=2, - events=(event,), - helicity=helicity, - baseline=None, - run_root=tmp_path / "run", - environment={}, - ) - - probe_calls = [ - call - for call in calls - if Path(call["log_path"]).name != "process-generation.json" - ] - assert len(calls) == 4 - assert len(probe_calls) == 3 - assert len({Path(call["log_path"]) for call in calls}) == len(calls) - assert len({Path(call["watchdog_report"]) for call in calls}) == len(calls) - assert probe_calls[0]["environment"] == { - "AMPICOL_COLOR_PROBE_TARGET_RUNTIME_S": "0.25" - } - assert all( - "AMPICOL_COLOR_PROBE_TARGET_RUNTIME_S" not in call["environment"] - for call in probe_calls[1:] - ) - assert cell["warm_repetitions"] == [36] - assert cell["warm_sample_set_attempts"] == 2 - assert min(cell["warm_sample_totals_seconds"]) >= 0.25 - assert cell["metrics"]["warm_seconds_per_point"] == pytest.approx(0.361 / 36) - assert cell["metrics"]["max_rss_kib"] == 1_600 - assert cell["resource_peaks_kib"] == { - "generation": 1_500, - "generation_guard": 9_000, - "runtime_self": 1_600, - "runtime_watchdog": 8_000, - "runtime_guard": 10_000, - "runtime_watchdog_included_in_plotted_rss": False, - } - - -def test_publication_defaults_use_strict_one_hour_and_30_gib_frontiers() -> None: - arguments = scaling._parser().parse_args(()) - plan = scaling.dry_run_plan(arguments) - - assert arguments.generation_timeout == 3600.0 - assert arguments.runtime_timeout == 3600.0 - assert arguments.memory_limit_gib == 30.0 - assert arguments.target_seconds == 180.0 - assert ( - "median of 1 independent process-CPU aggregate" - in plan["measurement"]["warm_timing_metric"]["amplicol"] - ) - assert ( - "Fortran runtime child peak RSS" in plan["measurement"]["amplicol_rss_metric"] - ) - assert scaling._require_bounded_rss(30 * 1024**2 - 1, 30.0) > 0 - with pytest.raises(scaling.StudyError, match=r"strict <30 GiB"): - scaling._require_bounded_rss(30 * 1024**2, 30.0) - - -def test_resume_accepts_sampling_and_resource_policy_updates(tmp_path: Path) -> None: - study_root = tmp_path / "study" - arguments = scaling._parser().parse_args( - ( - "--study-root", - str(study_root), - "--run-id", - "campaign", - "--multiplicity", - "5", - "--family", - "gg", - "--mode", - "reference-fft", - "--resume", - ) - ) - report = scaling._empty_report(arguments) - stale_policy = deepcopy(report["policy"]) - measurement = stale_policy["measurement"] - measurement["calibration_target_seconds"] = 0.25 - measurement["candidate_profile_target_runtime_seconds"] = 0.25 - measurement["candidate_profile_warmup_runs"] = 2 - measurement["candidate_profile_minimum_samples"] = 10 - measurement["warm_samples"] = 10 - measurement["warm_sample_count"] = 10 - measurement["warm_timing_metric"] = {"pyamplicol": "old short sampling"} - measurement["generation_timeout_seconds"] = 60.0 - measurement["runtime_timeout_seconds"] = 60.0 - measurement["requested_memory_ceiling_gib"] = 10.0 - measurement["memory_watchdog_gib"] = 10.0 - measurement["cell_admission_limits"] = {} - stale_policy["run_root"] = "/old/shard/layout" - report["policy"] = stale_policy - path = study_root / "runs" / "campaign" / "report.json" - path.parent.mkdir(parents=True) - path.write_text(json.dumps(report), encoding="utf-8") - - loaded = scaling._load_report(path, arguments) - - assert loaded["policy"] == scaling.dry_run_plan(arguments) - - stale_policy["measurement"]["alpha_s"] = 0.2 - report["policy"] = stale_policy - path.write_text(json.dumps(report), encoding="utf-8") - with pytest.raises( - scaling.StudyError, - match="resume arguments differ from the stored study policy", - ): - scaling._load_report(path, arguments) - - -def test_publication_generation_uses_normal_optimized_defaults() -> None: - command = scaling._candidate_generation_command( - python="python-test", - family="ddbar", - final_multiplicity=7, - mode=scaling.MODE_BY_KEY["compiled-direct"], - artifact=Path("artifact"), - batch_size=1, - ) - - assert "--no-numerical-current-reuse" not in command - assert "--no-emit-api-bundle" not in command - assert "--workers" not in command - assert "--progress" not in command - assert "--log-level" not in command - assert "generation.validation.enabled=false" not in command - assert "generation.validation.post_build_validation=false" not in command - assert "model.cache=false" not in command - assert "evaluator.optimization.cores=1" not in command - assert "evaluator.jit.optimization_level=2" not in command - assert not any( - value.startswith("process.selected_source_helicities=") for value in command - ) - assert command[command.index("--set") + 1] == "evaluator.batch_size=1" - - -def test_timed_command_uses_python_getrusage_wrapper_on_linux( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(scaling.sys, "platform", "linux") - - command, normalizer = scaling._timed_command(("payload",), python="python-test") - - assert command == ( - "python-test", - str(scaling.Path(scaling.__file__).resolve()), - "_time-rss", - "payload", - ) - assert normalizer is None - - -def _higher_n_arguments() -> object: - return scaling._parser().parse_args( - ( - "--run-id", - "higher-n-scalar", - "--min-n", - "7", - "--max-n", - "10", - "--family", - "gg", - "--family", - "ddbar", - "--mode", - "reference-fft", - "--mode", - "amplicol", - "--mode", - "recurrence-fft", - "--batch-size", - "1", - "--generation-timeout", - "3600", - "--runtime-timeout", - "3600", - "--memory-limit-gib", - "20", - ) - ) - - -def test_higher_n_scalar_policy_selects_only_requested_curves() -> None: - arguments = _higher_n_arguments() - scaling._validate_arguments(arguments) - - plan = scaling.dry_run_plan(arguments) - assert plan["final_state_multiplicities"] == [7, 8, 9, 10] - assert plan["total_external_particles"] == [9, 10, 11, 12] - assert plan["measurement"]["warm_benchmark_batch_size"] == 1 - assert plan["process_families"]["gg"]["modes"] == [ - "reference-fft", - "amplicol", - "recurrence-fft", - ] - assert plan["process_families"]["ddbar"]["modes"] == [ - "amplicol", - "recurrence-fft", - ] - assert set(scaling._empty_report(arguments)["cells"]) == {"gg", "ddbar"} - - -def test_fft_steering_adds_applicable_pairs_and_records_provenance() -> None: - arguments = scaling._parser().parse_args( - ( - "--family", - "gg", - "--mode", - "reference-fft", - "--mode", - "recurrence-direct", - "--mode", - "compiled-direct", - "--fft", - ) - ) - scaling._validate_arguments(arguments) - - plan = scaling.dry_run_plan(arguments) - assert plan["fft_enabled"] is True - assert plan["process_families"]["gg"]["modes"] == [ - "reference-fft", - "recurrence-direct", - "recurrence-fft", - "compiled-direct", - ] - assert plan["selected_pyamplicol_color_contractions"] == { - "recurrence": ["direct", "symmetric-group-fft"], - "compiled": ["direct"], - } - assert plan["measurement"]["generation_helicity_coverage"] == "all" - assert plan["measurement"]["warm_fixed_helicity"] is True - assert "fixed_helicity" not in plan["measurement"] - assert plan["measurement"]["compiled_fft_enabled"] is False - - -def test_helicity_sum_policy_has_separate_identity_and_count_semantics() -> None: - fixed_arguments = scaling._parser().parse_args(("--multiplicity", "2")) - sum_arguments = scaling._parser().parse_args( - ("--multiplicity", "2", "--compare-helicity-sums") - ) - - fixed = scaling.dry_run_plan(fixed_arguments)["measurement"] - summed = scaling.dry_run_plan(sum_arguments)["measurement"] - - assert fixed["warm_fixed_helicity"] is True - assert "helicity_workload" not in fixed - assert summed["helicity_workload"] == "sum" - assert summed["warm_fixed_helicity"] is False - assert summed["warm_helicity_sum"] is True - assert "candidate_timed_helicity_contract" in summed - semantics = summed["helicity_count_semantics"] - assert "complete physical API axis" in semantics["candidate"] - assert "analytic-nonzero subset" in semantics["reference_fft"] - assert "does not expose that retained count" in semantics["amplicol"] - assert "hel_fac filter" in semantics["amplicol"] - assert "generated-library" in summed["generation_metric"]["amplicol"] - - -def test_compiled_fft_is_explicitly_not_applicable_to_publication() -> None: - cell = scaling._compiled_fft_not_applicable_cell( - family="gg", - mode=scaling.MODE_BY_KEY["compiled-fft"], - final_multiplicity=6, - ) - - assert cell is not None - assert cell["status"] == "not-applicable" - assert cell["censors_higher_multiplicities"] is False - assert cell["applicability"] == { - "compiled_direct": True, - "compiled_fft": False, - "reason_code": "publication-requires-all-runtime-helicities", - } - assert "all runtime helicities" in cell["failure_reason"] - assert "compiled-direct remains supported" in cell["failure_reason"] - - -def test_sum_nonmeasurement_cells_keep_summed_workload_markers() -> None: - compiled = scaling._compiled_fft_not_applicable_cell( - family="gg", - mode=scaling.MODE_BY_KEY["compiled-fft"], - final_multiplicity=6, - sum_helicities=True, - ) - otf = scaling.otf_protocol_scope_cell( - family="gg", - mode=scaling.MODE_BY_KEY["otf-direct"], - final_multiplicity=7, - sum_helicities=True, - ) - - for cell in (compiled, otf): - assert cell is not None - assert cell["helicity_workload"] == "sum" - assert cell["warm_fixed_helicity"] is False - assert cell["warm_helicity_sum"] is True - - -def test_fixed_helicity_otf_frontier_matches_summed_n6_limit() -> None: - mode = scaling.MODE_BY_KEY["otf-direct"] - - for sum_helicities in (False, True): - assert ( - scaling.otf_protocol_scope_cell( - family="gg", - mode=mode, - final_multiplicity=6, - sum_helicities=sum_helicities, - ) - is None - ) - fixed_n7 = scaling.otf_protocol_scope_cell( - family="gg", - mode=mode, - final_multiplicity=7, - ) - assert fixed_n7 is not None - assert fixed_n7["failed_at_n"] == 7 - assert "n<=6" in fixed_n7["failure_reason"] - - assert ( - scaling.otf_protocol_scope_cell( - family="gg", - mode=mode, - final_multiplicity=7, - maximum_multiplicity=8, - ) - is None - ) - extended_n9 = scaling.otf_protocol_scope_cell( - family="gg", - mode=mode, - final_multiplicity=9, - maximum_multiplicity=8, - ) - assert extended_n9 is not None - assert extended_n9["failed_at_n"] == 9 - assert "n<=8" in extended_n9["failure_reason"] - - -def test_publication_artifact_requires_complete_reusable_helicities( - tmp_path: Path, -) -> None: - physics_path = tmp_path / "processes" / "gg_n2" / "physics.json" - physics_path.parent.mkdir(parents=True) - physics = { - "coverage": {"helicities": "complete"}, - "extensions": { - "runtime_selectors": { - "axes": { - "helicity": { - "generation_coverage": "complete", - "generation_selection": {}, - "runtime_contract": "complete-reusable", - } - }, - "generation_specialized_axes": [], - } - }, - "helicities": [{"id": f"h:{index}"} for index in range(16)], - } - physics_path.write_text(json.dumps(physics), encoding="utf-8") - - assert scaling._validate_publication_candidate_artifact(tmp_path, "gg_n2") == 16 - - physics["extensions"]["runtime_selectors"]["axes"]["helicity"] = { - "generation_coverage": "selected", - "generation_selection": {"1": 1}, - "runtime_contract": "generation-specialized", - } - physics_path.write_text(json.dumps(physics), encoding="utf-8") - with pytest.raises(scaling.StudyError, match="not reusable"): - scaling._validate_publication_candidate_artifact(tmp_path, "gg_n2") - - -def _publication_otf_execution() -> dict[str, object]: - return { - "schema_version": 3, - "kind": "pyamplicol-runtime-on-the-fly-execution", - "selector_policy": { - "color_coverage": "contracted", - "selector_census": {"physical_helicity_count": 4}, - }, - "runtime_metadata": { - "process_seed_identity": { - "external_sources": [ - { - "source_slot": 0, - "states": [ - {"state_index": 0, "public_helicity": -1}, - {"state_index": 1, "public_helicity": 1}, - ], - }, - { - "source_slot": 1, - "states": [ - {"state_index": 0, "public_helicity": -1}, - {"state_index": 1, "public_helicity": 1}, - ], - }, - ] - } - }, - } - - -def _write_publication_otf_execution( - root: Path, execution: object, *, raw: str | None = None -) -> None: - path = root / "processes" / "gg_n2" / "execution.json" - path.parent.mkdir(parents=True) - path.write_text(raw if raw is not None else json.dumps(execution), encoding="utf-8") - - -def test_publication_artifact_accepts_otf_seed_helicity_census(tmp_path: Path) -> None: - _write_publication_otf_execution(tmp_path, _publication_otf_execution()) - - assert scaling._validate_publication_candidate_artifact(tmp_path, "gg_n2") == 4 - - -@pytest.mark.parametrize( - "corruption", - ( - "schema", - "kind", - "coverage", - "small-census", - "census-mismatch", - "source-slot", - "state-index", - "public-helicity", - ), -) -def test_publication_artifact_rejects_corrupt_otf_helicity_contract( - tmp_path: Path, corruption: str -) -> None: - execution = deepcopy(_publication_otf_execution()) - selector = execution["selector_policy"] - assert isinstance(selector, dict) - census = selector["selector_census"] - assert isinstance(census, dict) - runtime_metadata = execution["runtime_metadata"] - assert isinstance(runtime_metadata, dict) - identity = runtime_metadata["process_seed_identity"] - assert isinstance(identity, dict) - sources = identity["external_sources"] - assert isinstance(sources, list) - first_source = sources[0] - second_source = sources[1] - assert isinstance(first_source, dict) and isinstance(second_source, dict) - first_states = first_source["states"] - assert isinstance(first_states, list) - - if corruption == "schema": - execution["schema_version"] = 2 - elif corruption == "kind": - execution["kind"] = "pyamplicol-runtime-recurrence-execution" - elif corruption == "coverage": - selector["color_coverage"] = "complete" - elif corruption == "small-census": - census["physical_helicity_count"] = 1 - elif corruption == "census-mismatch": - census["physical_helicity_count"] = 8 - elif corruption == "source-slot": - second_source["source_slot"] = 0 - elif corruption == "state-index": - assert isinstance(first_states[1], dict) - first_states[1]["state_index"] = 0 - elif corruption == "public-helicity": - assert isinstance(first_states[1], dict) - first_states[1]["public_helicity"] = -1 - else: # pragma: no cover - parametrization is exhaustive - raise AssertionError(corruption) - - _write_publication_otf_execution(tmp_path, execution) - with pytest.raises(scaling.StudyError): - scaling._validate_publication_candidate_artifact(tmp_path, "gg_n2") - - -def test_publication_artifact_rejects_malformed_otf_execution(tmp_path: Path) -> None: - _write_publication_otf_execution(tmp_path, {}, raw="{") - - with pytest.raises(scaling.StudyError): - scaling._validate_publication_candidate_artifact(tmp_path, "gg_n2") - - -def test_higher_n_process_and_reference_seed_are_unbounded_above_n7() -> None: - assert scaling.process_expression("gg", 8) == "g g > g g g g g g g g" - assert scaling.process_expression("ddbar", 8) == "d d~ > d d~ g g g g g g" - assert scaling.performance.generator_seed(12) == scaling.performance.BASE_SEED + 12 - with pytest.raises(scaling.performance.AcceptanceError): - scaling.performance.generator_seed(3) - - -def test_only_resource_failures_censor_a_curve(tmp_path: Path) -> None: - base = scaling._cell_base("gg", scaling.MODE_BY_KEY["recurrence-fft"], 8) - resource = scaling._failure_cell( - base, - scaling._CellResourceLimitError( - "candidate artifact generation exhausted the cold cap", - category="generation-time-limit", - ), - tmp_path, - ) - correctness = scaling._failure_cell( - base, - scaling.StudyError("candidate numerical comparison failed"), - tmp_path, - ) - legacy_runtime = scaling._failure_cell( - base, - scaling.legacy_report.ProfilingTimeLimitError( - "legacy profiling stage exhausted its remaining budget" - ), - tmp_path, - ) - - assert resource["failure_category"] == "generation-time-limit" - assert resource["censors_higher_multiplicities"] is True - assert correctness["failure_category"] == "error" - assert correctness["censors_higher_multiplicities"] is False - assert legacy_runtime["failure_category"] == "runtime-time-limit" - assert legacy_runtime["censors_higher_multiplicities"] is True - - -def _write_watched_command_record( - path: Path, - *, - timed_out: bool, - returncode: int, - watchdog_report: Path | None = None, - command: list[str] | None = None, - stdout: str | None = None, - stderr: str | None = None, -) -> None: - command = command or ["amplicol_color_library_probe", "1"] - watchdog_command = [ - sys.executable, - str(scaling.performance.WATCHDOG), - "--limit-gib", - "30", - "--", - *command, - ] - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text( - json.dumps( - { - "command": command, - "watchdog_command": watchdog_command, - "elapsed_seconds": 0.75, - "returncode": returncode, - "stdout": stdout - if stdout is not None - else ( - "Could not map colour row to generated-library integral 2\n" - "row permutation: 3 1 2 4\n" - ), - "stderr": stderr - if stderr is not None - else "timing metadata: runtime was below its deadline", - "timed_out": timed_out, - "timeout_cleanup": "not-required", - "watchdog_report": ( - None if watchdog_report is None else str(watchdog_report) - ), - } - ), - encoding="utf-8", - ) - - -def test_structural_command_failure_is_not_misclassified_as_a_resource_limit( - tmp_path: Path, -) -> None: - command_log = tmp_path / "commands" / "008-amplicol_color_library_probe.json" - _write_watched_command_record( - command_log, - timed_out=False, - returncode=1, - ) - _write_watched_command_record( - tmp_path / "commands" / "stale-timeout.json", - timed_out=True, - returncode=-15, - ) - base = scaling._cell_base("ddbar", scaling.MODE_BY_KEY["amplicol"], 2) - cell = scaling._failure_cell( - base, - scaling._CellCommandError( - "AmpliCol generated-library runtime command failed: " - f"command failed with status 1; see {command_log}", - timeout_category="runtime-time-limit", - ), - tmp_path, - ) - - assert cell["failure_category"] == "error" - assert cell["censors_higher_multiplicities"] is False - - -def test_legacy_amplicol_colour_init_segfault_censors_the_curve( - tmp_path: Path, -) -> None: - command_log = tmp_path / "amplicol" / "ddbar" / "n9" / "probe.json" - _write_watched_command_record( - command_log, - command=["amplicol_color_probe", "1000000000", "2", "1", "full"], - timed_out=False, - returncode=245, - stdout="Initialising amplitude for:\n", - stderr=( - "Program received signal SIGSEGV: Segmentation fault - invalid memory " - "reference.\n" - "#1 0x000000 in __amplitude_qcd_mod_MOD_init_col\n" - ), - ) - base = scaling._cell_base("ddbar", scaling.MODE_BY_KEY["amplicol"], 9) - cell = scaling._failure_cell( - base, - scaling._CellCommandError( - "AmpliCol setup/runtime probe failed: " - f"command failed with status 245; see {command_log}", - timeout_category="setup-or-runtime-time-limit", - ), - tmp_path, - ) - - assert ( - cell["failure_category"] == scaling.LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY - ) - assert ( - cell["failure_reason_short"] - == "legacy AmpliCol structural colour-init limit" - ) - assert cell["censors_higher_multiplicities"] is True - - -def test_loaded_legacy_amplicol_colour_init_segfault_report_is_normalized( - tmp_path: Path, -) -> None: - run_root = tmp_path / "historical-aggregate" - command_log = tmp_path / "isolated" / "cells" / "n9" / "probe.json" - _write_watched_command_record( - command_log, - command=["amplicol_color_probe", "1000000000", "2", "1", "full"], - timed_out=False, - returncode=245, - stdout="Initialising amplitude for:\n", - stderr=( - "Program received signal SIGSEGV: Segmentation fault - invalid memory " - "reference.\n" - "#1 0x000000 in __amplitude_qcd_mod_MOD_init_col\n" - ), - ) - report: dict[str, object] = { - "cells": { - "ddbar": { - "amplicol": { - "9": { - "status": "failed", - "censors_higher_multiplicities": False, - "failure_category": "error", - "failure_reason": ( - "AmpliCol setup/runtime probe failed: " - f"command failed with status 245; see {command_log}" - ), - } - } - } - } - } - - assert scaling.normalize_loaded_failure_cells(report, run_root) is True - - cell = report["cells"]["ddbar"]["amplicol"]["9"] # type: ignore[index] - assert ( - cell["failure_category"] == scaling.LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY - ) - assert cell["censors_higher_multiplicities"] is True - - -def test_typed_watched_command_timeout_censors_the_curve(tmp_path: Path) -> None: - command_log = tmp_path / "commands" / "probe.json" - _write_watched_command_record( - command_log, - timed_out=True, - returncode=-15, - ) - base = scaling._cell_base("ddbar", scaling.MODE_BY_KEY["amplicol"], 2) - cell = scaling._failure_cell( - base, - scaling._CellCommandError( - f"runtime command failed; see {command_log}", - timeout_category="runtime-time-limit", - ), - tmp_path, - ) - - assert cell["failure_category"] == "runtime-time-limit" - assert cell["censors_higher_multiplicities"] is True - - -def test_candidate_generation_retries_symbolica_single_instance_busy( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - arguments = scaling._parser().parse_args( - ("--generation-timeout", "60", "--memory-limit-gib", "100") - ) - mode = scaling.MODE_BY_KEY["recurrence-direct"] - environment = { - scaling.SYMBOLICA_GENERATION_LOCK_ENV: str(tmp_path / "symbolica.lock") - } - calls: list[tuple[str, ...]] = [] - sleeps: list[float] = [] - - def fake_run_watched( - command: tuple[str, ...], **kwargs: object - ) -> scaling.performance.WatchedCompletedProcess: - calls.append(tuple(command)) - log_path = Path(str(kwargs["log_path"])) - log_path.parent.mkdir(parents=True, exist_ok=True) - if len(calls) == 1: - log_path.write_text( - json.dumps( - { - "command": list(command), - "elapsed_seconds": 1.0, - "returncode": 134, - "stdout": scaling.SYMBOLICA_LICENSE_BUSY_FRAGMENT, - "stderr": "", - "timed_out": False, - "timeout_cleanup": "not-required", - } - ) - + "\n", - encoding="utf-8", - ) - raise scaling.performance.AcceptanceError("generation failed") - log_path.write_text( - json.dumps( - { - "command": list(command), - "elapsed_seconds": 1.0, - "returncode": 0, - "stdout": "", - "stderr": "", - "timed_out": False, - "timeout_cleanup": "not-required", - } - ) - + "\n", - encoding="utf-8", - ) - return scaling.performance.WatchedCompletedProcess( - command, - 0, - "", - "", - elapsed_seconds=1.0, - log_write_seconds=0.0, - timed_out=False, - timeout_cleanup="not-required", - ) - - monkeypatch.setattr(scaling.performance, "_run_watched", fake_run_watched) - monkeypatch.setattr(scaling.time, "sleep", lambda seconds: sleeps.append(seconds)) - - result = scaling._run_candidate_generation( - arguments=arguments, - family="ddbar", - final_multiplicity=2, - mode=mode, - artifact=tmp_path / "cell" / "artifact", - cell_root=tmp_path / "cell", - environment=environment, - ) - - assert result.returncode == 0 - assert len(calls) == 2 - assert sleeps == [scaling.SYMBOLICA_BUSY_RETRY_SECONDS] - - -def test_symbolica_generation_lock_is_skipped_for_explicit_license() -> None: - assert ( - scaling._symbolica_generation_lock_path({"SYMBOLICA_LICENSE": "configured"}) - is None - ) - assert ( - scaling._symbolica_generation_lock_path( - {"SYMBOLICA_LICENSE": "configured"}, force=True - ) - is not None - ) - - -@pytest.mark.parametrize("with_report", [False, True]) -def test_watchdog_memory_limit_outcome_censors_the_curve( - tmp_path: Path, with_report: bool -) -> None: - watchdog_report = tmp_path / "commands" / "probe.watchdog.json" - if with_report: - watchdog_report.parent.mkdir(parents=True) - watchdog_report.write_text( - json.dumps( - { - "kind": scaling.memory_watchdog.WATCHDOG_REPORT_KIND, - "schema_version": scaling.memory_watchdog.WATCHDOG_REPORT_SCHEMA, - "complete": True, - "execution": {"outcome": "memory-limit-exceeded"}, - } - ), - encoding="utf-8", - ) - command_log = tmp_path / "commands" / "probe.json" - _write_watched_command_record( - command_log, - timed_out=False, - returncode=scaling.memory_watchdog.MEMORY_LIMIT_EXIT_CODE, - watchdog_report=watchdog_report if with_report else None, - ) - base = scaling._cell_base("gg", scaling.MODE_BY_KEY["recurrence-fft"], 8) - cell = scaling._failure_cell( - base, - scaling.StudyError(f"command failed; see {command_log}"), - tmp_path, - ) - - assert cell["failure_category"] == "memory-limit" - assert cell["censors_higher_multiplicities"] is True - - -def test_selection_validation_requires_oracles_and_supported_scalar_modes() -> None: - missing_oracle = scaling._parser().parse_args( - ("--family", "ddbar", "--mode", "recurrence-fft") - ) - with pytest.raises(scaling.StudyError, match="require --mode amplicol"): - scaling._validate_arguments(missing_oracle) - - compiled_fft_scalar = scaling._parser().parse_args( - ( - "--family", - "gg", - "--mode", - "reference-fft", - "--mode", - "compiled-fft", - "--batch-size", - "1", - ) - ) - scaling._validate_arguments(compiled_fft_scalar) - - compiled_scalar = scaling._parser().parse_args( - ( - "--family", - "gg", - "--mode", - "reference-fft", - "--mode", - "compiled-direct", - "--batch-size", - "1", - ) - ) - with pytest.raises(scaling.StudyError, match="not supported for compiled"): - scaling._validate_arguments(compiled_scalar) - - -def test_correctness_failure_is_recorded_then_retried_on_resume( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - study_root = tmp_path / "study" - monkeypatch.setattr(scaling, "STUDY_ROOT", study_root) - monkeypatch.setattr(scaling, "_study_environment", lambda _python: {}) - monkeypatch.setattr( - scaling, - "_acquire_campaign_lock", - lambda: (tmp_path / "campaign.lock").open("a+", encoding="utf-8"), - ) - monkeypatch.setattr(scaling.performance, "_load_reference_module", lambda: object()) - attempts = 0 - - def fake_reference_cell(**kwargs: object) -> dict[str, object]: - nonlocal attempts - attempts += 1 - if attempts == 1: - raise scaling.StudyError("reference numerical comparison failed") - final_multiplicity = int(kwargs["final_multiplicity"]) - return scaling._cell_base( - "gg", scaling.MODE_BY_KEY["reference-fft"], final_multiplicity - ) | {"status": "measured"} - - monkeypatch.setattr(scaling, "_reference_cell", fake_reference_cell) - common = ( - "--run-id", - "retry-correctness", - "--min-n", - "7", - "--max-n", - "7", - "--family", - "gg", - "--mode", - "reference-fft", - ) - first = scaling._parser().parse_args(common) - scaling._validate_arguments(first) - with pytest.raises(scaling.StudyError, match="repair it, then resume"): - scaling._campaign(first) - - report_path = study_root / "runs" / "retry-correctness" / "report.json" - stopped = json.loads(report_path.read_text(encoding="utf-8")) - failed = stopped["cells"]["gg"]["reference-fft"]["7"] - assert stopped["status"] == "stopped-correctness-failure" - assert failed["status"] == "failed" - assert failed["censors_higher_multiplicities"] is False - - resumed = scaling._parser().parse_args((*common, "--resume")) - scaling._validate_arguments(resumed) - completed = scaling._campaign(resumed) - assert attempts == 2 - assert completed["status"] == "complete" - assert completed["failure_count"] == 0 - assert completed["cells"]["gg"]["reference-fft"]["7"]["status"] == "measured" - - -def test_resume_retries_lower_resource_failure_below_retained_measurement( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - study_root = tmp_path / "study" - monkeypatch.setattr(scaling, "STUDY_ROOT", study_root) - monkeypatch.setattr(scaling, "_study_environment", lambda _python: {}) - monkeypatch.setattr( - scaling, - "_acquire_campaign_lock", - lambda: (tmp_path / "campaign.lock").open("a+", encoding="utf-8"), - ) - monkeypatch.setattr(scaling.performance, "_load_reference_module", lambda: object()) - common = ( - "--run-id", - "retry-lower-frontier", - "--multiplicity", - "2", - "--multiplicity", - "8", - "--fill-multiplicity", - "2", - "--family", - "gg", - "--mode", - "reference-fft", - "--resume", - ) - arguments = scaling._parser().parse_args(common) - scaling._validate_arguments(arguments) - report = scaling._empty_report(arguments) - curve = report["cells"]["gg"]["reference-fft"] - curve["2"] = scaling._cell_base( - "gg", scaling.MODE_BY_KEY["reference-fft"], 2 - ) | { - "status": "failed", - "failure_category": "memory-limit", - "failure_reason": "old lower-n resource observation", - "censors_higher_multiplicities": True, - } - curve["8"] = scaling._cell_base( - "gg", scaling.MODE_BY_KEY["reference-fft"], 8 - ) | {"status": "measured"} - report_path = study_root / "runs" / "retry-lower-frontier" / "report.json" - scaling.performance._write_report(report_path, report) - attempts = 0 - - def fake_reference_cell(**kwargs: object) -> dict[str, object]: - nonlocal attempts - attempts += 1 - final_multiplicity = int(kwargs["final_multiplicity"]) - assert final_multiplicity == 2 - return scaling._cell_base( - "gg", scaling.MODE_BY_KEY["reference-fft"], final_multiplicity - ) | {"status": "measured"} - - monkeypatch.setattr(scaling, "_reference_cell", fake_reference_cell) - completed = scaling._campaign(arguments) - - assert attempts == 1 - assert completed["status"] == "complete" - assert completed["cells"]["gg"]["reference-fft"]["2"]["status"] == "measured" - assert completed["cells"]["gg"]["reference-fft"]["8"]["status"] == "measured" - assert scaling.resource_frontier_inversions(completed) == () - - -def test_candidate_public_cli_commands_and_profile_json_are_authoritative( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - momenta = tmp_path / "momenta.json" - parameters = tmp_path / "parameters.json" - helicity = (-1, -1, 1, 1) - fixed_evaluate = scaling._candidate_evaluate_command( - python="python", - artifact=artifact, - process="gg_n2", - momenta=momenta, - model_parameters=parameters, - helicity=helicity, - sum_helicities=False, - ) - fixed_profile = scaling._candidate_profile_command( - python="python", - artifact=artifact, - process="gg_n2", - momenta=momenta, - helicity=helicity, - sum_helicities=False, - target_seconds=0.25, - batch_size=128, - ) - summed_profile = scaling._candidate_profile_command( - python="python", - artifact=artifact, - process="gg_n2", - momenta=momenta, - helicity=helicity, - sum_helicities=True, - target_seconds=0.25, - batch_size=128, - ) - - assert fixed_evaluate[fixed_evaluate.index("--model-parameters") + 1] == str( - parameters - ) - assert fixed_evaluate[fixed_evaluate.index("--helicity") + 1] == "h:-1,-1,+1,+1" - assert fixed_profile[fixed_profile.index("--helicity") + 1] == "h:-1,-1,+1,+1" - assert "--helicity" not in summed_profile - assert fixed_profile[fixed_profile.index("--target-runtime") + 1] == "0.25" - assert fixed_profile[fixed_profile.index("--batch-size") + 1] == "128" - assert fixed_profile[fixed_profile.index("--warmup-runs") + 1] == "0" - assert fixed_profile[fixed_profile.index("--minimum-samples") + 1] == "1" - assert all("fft_gluon_candidate_probe" not in token for token in fixed_profile) - - values = scaling._parse_candidate_evaluate_json( - json.dumps([{"real": index + 1.0, "imag": 0.0} for index in range(10)]) - ) - assert values == [float(index) for index in range(1, 11)] - - config = { - "batch_size": 128, - "color_flow_ids": [], - "helicity_ids": [], - "minimum_samples": 1, - "precision": 16, - "target_runtime": 0.25, - "warmup_runs": 0, - } - wall = 0.0005343891273355439 - payload = { - "requested_config": config, - "effective_config": config, - "sample_count": 1, - "repetitions_per_sample": 1, - "wall_time_per_point": wall, - "interrupted": False, - "process_id": "gg_n2", - "process_expression": scaling.process_expression("gg", 2), - "environment": { - "target": str(artifact), - "execution_mode": "recurrence", - "color_accuracy": "full", - "batch_size": 128, - "precision": 16, - "selected_color_ids": [], - "selected_helicity_ids": [], - "completed_sample_count": 1, - "measured_point_count": 128, - "interrupted": False, - }, - "retained_full_cli_provenance": {"sentinel": True}, - } - parsed = scaling._parse_candidate_profile_json( - json.dumps(payload), - artifact=artifact, - family="gg", - final_multiplicity=2, - execution_mode="recurrence", - helicity=helicity, - sum_helicities=True, - target_seconds=0.25, - batch_size=128, - ) - - assert parsed["wall_time_per_point"] == wall - assert parsed["retained_full_cli_provenance"] == {"sentinel": True} - - -def test_summed_reference_distinguishes_shared_and_timed_event_paths( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - shared = tuple(tmp_path / f"shared-{index}.event" for index in range(10)) - timed = tuple(tmp_path / f"timed-{index}.event" for index in range(10)) - for path in (*shared, *timed): - path.write_text("event\n", encoding="utf-8") - metrics = scaling.performance.ReferenceMetrics( - total_gluons=4, - generator_seed=scaling.performance.generator_seed(4), - backend=scaling.performance.REFERENCE_BACKEND, - clean_build_scope=scaling.performance.REFERENCE_CLEAN_BUILD_SCOPE, - clean_build_command_count=1, - clean_build_seconds=1.0, - setup_to_driver_seconds=1.0, - initialization_seconds=0.1, - first_pass_seconds=0.1, - warm_samples_seconds=(0.01,) * 10, - warm_median_seconds=0.01, - max_rss_kib=1024, - selected_helicity=(-1, -1, 1, 1), - selected_path="mhv", - event_paths=tuple(str(path) for path in shared), - matrix_elements=(1.0,) * 10, - helicity_workload="sum", - helicity_coverage_count=16, - timed_helicity_count=6, - active_helicity_count=6, - exhaustive_event_paths=tuple(str(path) for path in timed), - ) - monkeypatch.setattr( - scaling.performance, - "_run_reference", - lambda **_kwargs: scaling.performance._ReferenceRun( - metrics=metrics, event_paths=shared - ), - ) - arguments = scaling._parser().parse_args(("--compare-helicity-sums",)) - - cell = scaling._reference_cell( - arguments=arguments, - reference=object(), - run_root=tmp_path, - environment={}, - final_multiplicity=2, - ) - - assert cell["event_paths"] == [str(path) for path in shared] - assert cell["shared_event_paths"] == [str(path) for path in shared] - assert cell["timed_event_paths"] == [str(path) for path in timed] - assert cell["reference"]["exhaustive_event_paths"] == tuple( - str(path) for path in timed - ) - report = {"cells": {"gg": {"reference-fft": {"2": cell}}}} - events, helicity = scaling._inputs(report, tmp_path, "gg", 2) - assert events == shared - assert helicity == metrics.selected_helicity - - -@pytest.mark.parametrize( - ("failed_phase", "expected_generation_calls", "expected_cli_calls"), - (("interruption", 1, 3), ("profile", 1, 4), ("generation", 2, 2)), -) -def test_candidate_resume_reuses_only_a_successful_generation_phase( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - failed_phase: str, - expected_generation_calls: int, - expected_cli_calls: int, -) -> None: - study_root = tmp_path / "study" - final_multiplicity = 8 - run_id = f"resume-{failed_phase}" - monkeypatch.setattr(scaling, "STUDY_ROOT", study_root) - monkeypatch.setattr(scaling, "_study_environment", lambda _python: {}) - monkeypatch.setattr( - scaling, - "_acquire_campaign_lock", - lambda: (tmp_path / "campaign.lock").open("a+", encoding="utf-8"), - ) - monkeypatch.setattr(scaling.performance, "_load_reference_module", lambda: object()) - monkeypatch.setattr( - scaling.performance, - "_build_probe", - lambda **_kwargs: pytest.fail( - "publication candidate cells must not build the custom C++ probe" - ), - ) - monkeypatch.setattr( - scaling, - "_validate_publication_candidate_artifact", - lambda _artifact, _process: 16, - ) - factor = ( - scaling.performance.INITIAL_GLUON_AVERAGE_FACTOR - * scaling.math.factorial(final_multiplicity) - / (4.0 * scaling.math.pi * scaling.DEFAULT_ALPHA_S) ** final_multiplicity - ) - event_paths = tuple(tmp_path / f"event-{index}" for index in range(10)) - for path in event_paths: - path.write_text("mock event\n", encoding="utf-8") - - def fake_reference_cell(**_kwargs: object) -> dict[str, object]: - return scaling._cell_base( - "gg", scaling.MODE_BY_KEY["reference-fft"], final_multiplicity - ) | { - "status": "measured", - "event_paths": [str(path) for path in event_paths], - "helicity": [1] * (final_multiplicity + 2), - "point_values": [factor] * 10, - } - - generation_calls = 0 - cli_calls = 0 - failure_triggered = False - evaluate_timeouts: list[float] = [] - watchdog_stderr = ( - "memory-watchdog: command finished exit=0 peak_rss=0.001 GiB " - "peak_physical_footprint=0.001 GiB peak_guard=0.001 GiB\n" - ) - - def fake_run_watched( - command: tuple[str, ...], **kwargs: object - ) -> scaling.performance.WatchedCompletedProcess: - nonlocal generation_calls, cli_calls, failure_triggered - assert all("fft_gluon_candidate_probe" not in token for token in command) - log_path = Path(str(kwargs["log_path"])) - if log_path.name == "generation.json": - generation_calls += 1 - artifact = log_path.parent / "artifact" - artifact.mkdir(parents=True, exist_ok=True) - (artifact / "artifact.json").write_text("{}\n", encoding="utf-8") - returncode = int(failed_phase == "generation" and not failure_triggered) - failure_triggered = failure_triggered or returncode != 0 - log_path.write_text( - json.dumps( - { - "command": list(command), - "elapsed_seconds": 1.0, - "returncode": returncode, - "stdout": "", - "stderr": watchdog_stderr, - "timed_out": False, - "timeout_cleanup": "not-required", - } - ) - + "\n", - encoding="utf-8", - ) - if returncode != 0: - raise scaling.performance.AcceptanceError("generation failed") - output = "" - elif log_path.name == "evaluate.json": - cli_calls += 1 - evaluate_timeouts.append(float(kwargs["timeout_seconds"])) - if failed_phase == "interruption" and not failure_triggered: - failure_triggered = True - raise KeyboardInterrupt - output = json.dumps([{"real": 1.0, "imag": 0.0}] * 10) - else: - assert log_path.name == "profile.json" - cli_calls += 1 - if failed_phase == "profile" and not failure_triggered: - failure_triggered = True - raise scaling.performance.AcceptanceError("profile failed") - config = { - "batch_size": 1, - "color_flow_ids": [], - "helicity_ids": ["h:" + ",".join(["+1"] * 10)], - "minimum_samples": 1, - "precision": 16, - "target_runtime": scaling.DEFAULT_PROFILE_TARGET_SECONDS, - "warmup_runs": 0, - } - output = json.dumps( - { - "requested_config": config, - "effective_config": config, - "sample_count": 1, - "repetitions_per_sample": 1, - "wall_time_per_point": 0.001, - "interrupted": False, - "process_id": "gg_n8", - "process_expression": scaling.process_expression("gg", 8), - "environment": { - "target": str(log_path.parent / "artifact"), - "execution_mode": "recurrence", - "color_accuracy": "full", - "batch_size": 1, - "precision": 16, - "selected_color_ids": [], - "selected_helicity_ids": config["helicity_ids"], - "completed_sample_count": 1, - "measured_point_count": 1, - "interrupted": False, - }, - } - ) - return scaling.performance.WatchedCompletedProcess( - command, - 0, - output, - watchdog_stderr, - elapsed_seconds=1.0, - log_write_seconds=0.0, - timed_out=False, - timeout_cleanup="not-required", - ) - - monkeypatch.setattr(scaling, "_reference_cell", fake_reference_cell) - monkeypatch.setattr( - scaling, - "_write_candidate_cli_inputs", - lambda *, cell_root, **_kwargs: ( - cell_root / "cli-momenta.json", - cell_root / "cli-model-parameters.json", - ), - ) - monkeypatch.setattr(scaling.performance, "_run_watched", fake_run_watched) - common = ( - "--run-id", - run_id, - "--min-n", - str(final_multiplicity), - "--max-n", - str(final_multiplicity), - "--family", - "gg", - "--mode", - "reference-fft", - "--mode", - "recurrence-fft", - "--batch-size", - "1", - ) - first = scaling._parser().parse_args(common) - scaling._validate_arguments(first) - if failed_phase == "interruption": - with pytest.raises(KeyboardInterrupt): - scaling._campaign(first) - else: - with pytest.raises(scaling.StudyError, match="repair it, then resume"): - scaling._campaign(first) - - resumed = scaling._parser().parse_args((*common, "--resume")) - scaling._validate_arguments(resumed) - report = scaling._campaign(resumed) - - candidate_root = ( - study_root / "runs" / run_id / "candidate" / "recurrence-fft" / "gg" - ) - assert generation_calls == expected_generation_calls - assert cli_calls == expected_cli_calls - assert evaluate_timeouts - assert all(timeout == pytest.approx(3599.0) for timeout in evaluate_timeouts) - assert not (candidate_root / "n8.interrupted-1").exists() - assert not (candidate_root / ".n8.staging").exists() - assert (candidate_root / "n8" / "artifact" / "artifact.json").is_file() - measured = report["cells"]["gg"]["recurrence-fft"]["8"] - assert measured["status"] == "measured" - assert measured["metrics"]["warm_seconds_per_point"] == 0.001 - assert "runtime_profile" in measured - assert "probe" not in measured - - -def test_disk_exhaustion_is_not_misreported_as_an_rss_censor(tmp_path: Path) -> None: - cell = scaling._failure_cell( - scaling._cell_base("gg", scaling.MODE_BY_KEY["recurrence-fft"], 8), - OSError(28, "No space left on device"), - tmp_path, - ) - - assert cell["failure_category"] == "disk-infrastructure-failure" - assert cell["censors_higher_multiplicities"] is False - - -def _prepare_mocked_selected_campaign( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> Path: - study_root = tmp_path / "study" - repository = tmp_path / "amplicol" - repository.mkdir() - (repository / "amplicol_color_probe").write_text("test probe\n", encoding="utf-8") - monkeypatch.setattr(scaling, "STUDY_ROOT", study_root) - monkeypatch.setattr(scaling, "_study_environment", lambda _python: {}) - monkeypatch.setattr( - scaling, - "_acquire_campaign_lock", - lambda: (tmp_path / "campaign.lock").open("a+", encoding="utf-8"), - ) - monkeypatch.setattr(scaling.performance, "_load_reference_module", lambda: object()) - monkeypatch.setattr( - scaling.performance, - "_build_probe", - lambda **_kwargs: pytest.fail( - "publication candidate cells must not build the custom C++ probe" - ), - ) - monkeypatch.setattr( - scaling.legacy_amplicol, "validate_checkout", lambda _repository: None - ) - return repository - - -def test_reference_resource_censor_skips_gg_dependencies_but_runs_ddbar( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - repository = _prepare_mocked_selected_campaign(tmp_path, monkeypatch) - calls = {"reference": 0, "amplicol-ddbar": 0, "candidate-ddbar": 0} - - def fake_reference_cell(**_kwargs: object) -> dict[str, object]: - calls["reference"] += 1 - raise scaling._CellResourceLimitError( - "reference generation reached its cell deadline", - category="generation-time-limit", - ) - - def fake_inputs( - _report: object, _run_root: Path, family: str, final_multiplicity: int - ) -> tuple[tuple[Path, ...], tuple[int, ...]]: - assert family == "ddbar" - return (Path("event"),), scaling.fixed_ddbar_helicity(final_multiplicity) - - def fake_amplicol_cell(**kwargs: object) -> dict[str, object]: - family = str(kwargs["family"]) - assert family == "ddbar" - calls["amplicol-ddbar"] += 1 - final_multiplicity = int(kwargs["final_multiplicity"]) - return scaling._cell_base( - family, scaling.MODE_BY_KEY["amplicol"], final_multiplicity - ) | {"status": "measured"} - - def fake_candidate_cell(**kwargs: object) -> dict[str, object]: - family = str(kwargs["family"]) - assert family == "ddbar" - calls["candidate-ddbar"] += 1 - final_multiplicity = int(kwargs["final_multiplicity"]) - mode = kwargs["mode"] - return scaling._cell_base(family, mode, final_multiplicity) | { - "status": "measured" - } - - monkeypatch.setattr(scaling, "_reference_cell", fake_reference_cell) - monkeypatch.setattr(scaling, "_inputs", fake_inputs) - monkeypatch.setattr(scaling, "_amplicol_cell", fake_amplicol_cell) - monkeypatch.setattr(scaling, "_candidate_cell", fake_candidate_cell) - common = ( - "--run-id", - "dependency-censor", - "--min-n", - "7", - "--max-n", - "8", - "--family", - "gg", - "--family", - "ddbar", - "--mode", - "reference-fft", - "--mode", - "amplicol", - "--mode", - "recurrence-fft", - "--amplicol-repository", - str(repository), - ) - first = scaling._parser().parse_args(common) - scaling._validate_arguments(first) - report = scaling._campaign(first) - - assert calls == {"reference": 1, "amplicol-ddbar": 2, "candidate-ddbar": 2} - for n in ("7", "8"): - for mode in ("amplicol", "recurrence-fft"): - dependency = report["cells"]["gg"][mode][n] - assert dependency["status"] == "skipped" - assert dependency["failure_category"] == "dependency-unavailable" - assert dependency["censors_higher_multiplicities"] is False - assert report["cells"]["ddbar"]["amplicol"][n]["status"] == "measured" - assert report["cells"]["ddbar"]["recurrence-fft"][n]["status"] == "measured" - - resumed = scaling._parser().parse_args((*common, "--resume")) - scaling._validate_arguments(resumed) - scaling._campaign(resumed) - assert calls == {"reference": 1, "amplicol-ddbar": 2, "candidate-ddbar": 2} - - -def test_amplicol_gg_dense_index_preflight_censors_only_that_curve( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - repository = _prepare_mocked_selected_campaign(tmp_path, monkeypatch) - calls = {"reference": 0, "amplicol": 0, "candidate": 0} - - def fake_reference_cell(**kwargs: object) -> dict[str, object]: - calls["reference"] += 1 - final_multiplicity = int(kwargs["final_multiplicity"]) - return scaling._cell_base( - "gg", scaling.MODE_BY_KEY["reference-fft"], final_multiplicity - ) | {"status": "measured"} - - def fake_inputs( - _report: object, _run_root: Path, family: str, final_multiplicity: int - ) -> tuple[tuple[Path, ...], tuple[int, ...]]: - assert family == "gg" - return (Path("event"),), (1,) * (final_multiplicity + 2) - - def fake_amplicol_cell(**_kwargs: object) -> dict[str, object]: - calls["amplicol"] += 1 - raise AssertionError("structurally infeasible AmpliCol cell was launched") - - def fake_candidate_cell(**kwargs: object) -> dict[str, object]: - calls["candidate"] += 1 - final_multiplicity = int(kwargs["final_multiplicity"]) - mode = kwargs["mode"] - return scaling._cell_base("gg", mode, final_multiplicity) | { - "status": "measured" - } - - monkeypatch.setattr(scaling, "_reference_cell", fake_reference_cell) - monkeypatch.setattr(scaling, "_inputs", fake_inputs) - monkeypatch.setattr(scaling, "_amplicol_cell", fake_amplicol_cell) - monkeypatch.setattr(scaling, "_candidate_cell", fake_candidate_cell) - arguments = scaling._parser().parse_args( - ( - "--run-id", - "amplicol-preflight", - "--min-n", - "8", - "--max-n", - "9", - "--family", - "gg", - "--mode", - "reference-fft", - "--mode", - "amplicol", - "--mode", - "recurrence-fft", - "--memory-limit-gib", - "20", - "--amplicol-repository", - str(repository), - ) - ) - scaling._validate_arguments(arguments) - report = scaling._campaign(arguments) - - n7 = scaling._amplicol_gg_dense_index_preflight(7, 20.0) - n8 = scaling._amplicol_gg_dense_index_preflight(8, 20.0) - assert n7["color_orders"] == 40_320 - assert n7["feasible"] is True - assert n8["color_orders"] == 362_880 - assert n8["lower_bound_bytes"] == 263_363_788_800 - assert n8["feasible"] is False - assert calls == {"reference": 2, "amplicol": 0, "candidate": 2} - first_skip = report["cells"]["gg"]["amplicol"]["8"] - assert first_skip["status"] == "skipped" - assert first_skip["failure_category"] == "structural-memory-limit" - assert first_skip["censors_higher_multiplicities"] is True - higher_skip = report["cells"]["gg"]["amplicol"]["9"] - assert higher_skip["status"] == "skipped" - assert higher_skip["failed_at_n"] == 8 - assert report["cells"]["gg"]["recurrence-fft"]["9"]["status"] == "measured" diff --git a/pyamplicol/tests/unit/test_fft_scaling_study_plots.py b/pyamplicol/tests/unit/test_fft_scaling_study_plots.py deleted file mode 100644 index 4f1da1459e..0000000000 --- a/pyamplicol/tests/unit/test_fft_scaling_study_plots.py +++ /dev/null @@ -1,957 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.developer import fft_scaling_study_plots as plots - - -def _report(boundary: object = 6) -> dict[str, object]: - plot_policy = ( - {} - if boundary is None - else { - "source_boundary_after_n": boundary, - "source_boundary_label": "n=2..6 / n=7..9 source boundary", - } - ) - return { - "policy": { - "final_state_multiplicities": list(range(2, 10)), - "plot": plot_policy, - }, - "cells": {}, - } - - -def test_source_boundary_is_drawn_between_n6_and_n7() -> None: - assert plots._source_boundary(_report()) == ( - 6.5, - "n=2..6 / n=7..9 source boundary", - ) - - -def test_source_boundary_is_optional() -> None: - assert plots._source_boundary(_report(None)) is None - - -def test_source_boundary_can_be_disabled_for_only_the_refreshed_metric() -> None: - report = _report() - report["policy"]["plot"]["metric_source_boundaries"] = { - "generation_seconds": { - "source_boundary_after_n": 6, - "source_boundary_label": "generation boundary", - }, - "warm_seconds_per_point": None, - } - - assert plots._source_boundary(report, "warm_seconds_per_point") is None - assert plots._source_boundary(report, "generation_seconds") == ( - 6.5, - "generation boundary", - ) - assert plots._source_boundary(report, "max_rss_kib") == ( - 6.5, - "n=2..6 / n=7..9 source boundary", - ) - - -def test_protocol_summary_records_fft_and_helicity_contract() -> None: - report = _report() - report["policy"].update( - { - "fft_enabled": True, - "measurement": { - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "warm_benchmark_batch_size": 128, - "compiled_fft_enabled": False, - }, - } - ) - - assert plots._protocol_summary(report) == ( - "Campaign --fft enabled | artifacts: all runtime helicities | " - "setup/warm workload: one fixed helicity | pyAmpliCol CLI profile: batch 128 " - "(cyclic 10 points) | Reference/AmpliCol: scalar aggregates normalized " - "per point | compiled FFT disabled | " - "main Y log; ratio Y log" - ) - assert plots.METRICS[0].title == "Setup time" - - -def test_protocol_summary_and_warm_title_record_helicity_sum() -> None: - report = _report() - report["policy"].update( - { - "fft_enabled": True, - "helicity_workload": "sum", - "measurement": { - "generation_helicity_coverage": "all", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "warm_benchmark_batch_size": 128, - "compiled_fft_enabled": False, - }, - } - ) - - assert plots._protocol_summary(report) == ( - "Campaign --fft enabled | artifacts: all runtime helicities | " - "setup/warm workload: complete helicity sum | " - "AmpliCol: create-raw bulk H family | pyAmpliCol CLI profile: batch 128 " - "(cyclic 10 points) | Reference/AmpliCol: scalar aggregates normalized " - "per point | compiled FFT disabled | " - "main Y log; ratio Y log" - ) - assert plots._metric_title(report, plots.METRICS[1]) == ( - "Warmed helicity-summed runtime per point" - ) - assert plots._metric_axis_label(report, plots.METRICS[1]) == ( - "Time per helicity-summed point [s]" - ) - protocol_lines = plots._protocol_summary_lines(report) - assert protocol_lines == ( - "Campaign --fft enabled | artifacts: all runtime helicities | " - "setup/warm workload: complete helicity sum", - "AmpliCol: create-raw bulk H family | pyAmpliCol CLI profile: batch 128 " - "(cyclic 10 points)", - "Reference/AmpliCol: scalar aggregates normalized per point | " - "compiled FFT disabled | main Y log; ratio Y log", - ) - assert max(map(len, protocol_lines)) <= 110 - - -def test_sum_plot_rejects_fixed_helicity_external_series() -> None: - report = _report(None) - report["policy"].update( - { - "fft_enabled": True, - "helicity_workload": "sum", - "process_families": {"gg": {"modes": ["reference-fft"]}}, - "measurement": { - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - }, - } - ) - report["cells"] = { - "gg": { - "reference-fft": { - "2": { - "status": "measured", - "helicity_workload": "sum", - "metrics": {"warm_seconds_per_point": 1.0}, - } - } - } - } - report["runtime_series"] = { - "gg": { - "madgraph-standalone": { - "2": { - "status": "measured", - "protocol": {"helicity_summed": False}, - "metrics": {"warm_seconds_per_point": 2.0}, - } - } - } - } - - with pytest.raises(plots.PlotError, match="not authenticated as a helicity-summed"): - plots._family_cells_for_metric(report, "gg", plots.METRICS[1]) - - -def test_plot_rejects_contradictory_helicity_workload_markers() -> None: - report = _report(None) - report["policy"].update( - { - "fft_enabled": True, - "helicity_workload": "sum", - "measurement": { - "warm_fixed_helicity": True, - "warm_helicity_sum": True, - }, - } - ) - with pytest.raises(plots.PlotError, match="summed policy"): - plots._protocol_summary(report) - - cell = { - "helicity_workload": "sum", - "warm_fixed_helicity": True, - } - with pytest.raises(plots.PlotError, match="markers are contradictory"): - plots._declared_cell_workload(cell) - - -def test_plot_rejects_disagreeing_policy_and_measurement_workloads() -> None: - report = _report(None) - report["policy"].update( - { - "helicity_workload": "fixed", - "measurement": { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - }, - } - ) - - with pytest.raises(plots.PlotError, match="declarations disagree"): - plots._helicity_workload(report) - - -def test_plot_manifest_binds_report_workload_and_exact_pngs(tmp_path: Path) -> None: - report_path = tmp_path / "report.json" - report = _report(None) - report_path.write_text(json.dumps(report), encoding="utf-8") - output_directory = tmp_path / "plots" - output_directory.mkdir() - for index, filename in enumerate(plots.PLOT_FILENAMES): - (output_directory / filename).write_bytes(f"png-{index}".encode()) - - manifest_path = plots._write_plot_manifest( - plots._sha256(report_path), report, output_directory - ) - manifest = json.loads(manifest_path.read_text(encoding="utf-8")) - - assert manifest["report_sha256"] == plots._sha256(report_path) - assert manifest["helicity_workload"] == "fixed" - assert set(manifest["plots"]) == set(plots.PLOT_FILENAMES) - assert manifest["plots"][plots.PLOT_FILENAMES[0]] == plots._sha256( - output_directory / plots.PLOT_FILENAMES[0] - ) - - -def test_plot_data_payload_records_plotted_values_and_ratios(tmp_path: Path) -> None: - report = _report(None) - report["policy"].update( - { - "process_families": { - "gg": {"modes": ["reference-fft", "recurrence-direct"]}, - "ddbar": {"modes": ["amplicol"]}, - }, - "measurement": {"warm_fixed_helicity": True}, - } - ) - measured = { - "status": "measured", - "warm_fixed_helicity": True, - } - report["cells"] = { - "gg": { - "reference-fft": { - "2": measured - | { - "label": "Reference FFT", - "metrics": { - "generation_seconds": 2.0, - "warm_seconds_per_point": 0.2, - "max_rss_kib": 2048.0, - }, - } - }, - "recurrence-direct": { - "2": measured - | { - "metrics": { - "generation_seconds": 4.0, - "warm_seconds_per_point": 0.1, - "max_rss_kib": 4096.0, - }, - } - }, - }, - "ddbar": { - "amplicol": { - "2": measured - | { - "metrics": { - "generation_seconds": 3.0, - "warm_seconds_per_point": 0.3, - "max_rss_kib": 1024.0, - }, - } - } - }, - } - - payload = plots._plot_data_payload("abc123", report) - output_directory = tmp_path / "plots" - output_directory.mkdir() - data_path = plots._write_plot_data("abc123", report, output_directory) - persisted = json.loads(data_path.read_text(encoding="utf-8")) - - generation = payload["families"]["gg"]["metrics"]["generation"] - rss = payload["families"]["gg"]["metrics"]["rss"] - - assert persisted == payload - assert payload["kind"] == "pyamplicol-fft-scaling-plot-data" - assert generation["source_metric_key"] == "generation_seconds" - assert generation["modes"]["reference-fft"]["series"] == [ - {"n": 2, "value": 2.0} - ] - assert generation["modes"]["recurrence-direct"]["ratio_to_baseline"] == [ - {"n": 2, "value": 2.0} - ] - assert rss["axis_label"] == "Peak RSS [MiB]" - assert rss["modes"]["reference-fft"]["series"] == [{"n": 2, "value": 2.0}] - - -def test_plot_data_payload_records_custom_axis_options() -> None: - report = _report(None) - report["policy"].update( - { - "process_families": { - "gg": {"modes": ["reference-fft", "recurrence-direct"]}, - "ddbar": {"modes": ["amplicol"]}, - }, - "measurement": {"warm_fixed_helicity": True}, - } - ) - measured = { - "status": "measured", - "warm_fixed_helicity": True, - } - report["cells"] = { - "gg": { - "reference-fft": { - "2": measured - | {"metrics": {"generation_seconds": 2.0}}, - }, - "recurrence-direct": { - "2": measured - | {"metrics": {"generation_seconds": 4.0}}, - }, - }, - "ddbar": { - "amplicol": { - "2": measured - | {"metrics": {"generation_seconds": 3.0}}, - } - }, - } - axis_options = plots.AxisOptions( - main_y_range=(1.0, 10.0), - ratio_y_range=(0.0, 3.0), - ratio_y_scale="linear", - ) - - payload = plots._plot_data_payload( - "abc123", - report, - axis_options=axis_options, - ) - generation = payload["families"]["gg"]["metrics"]["generation"] - - assert generation["main_axis"] == {"scale": "log", "range": [1.0, 10.0]} - assert generation["ratio_axis"] == { - "scale": "linear", - "range": [0.0, 3.0], - } - - -def test_plot_data_payload_filters_main_and_ratio_lines_independently() -> None: - report = _report(None) - report["policy"].update( - { - "process_families": { - "gg": { - "modes": [ - "reference-fft", - "recurrence-direct", - "madgraph-standalone", - ] - }, - "ddbar": {"modes": ["amplicol"]}, - }, - "measurement": {"warm_fixed_helicity": True}, - } - ) - measured = { - "status": "measured", - "warm_fixed_helicity": True, - } - report["cells"] = { - "gg": { - "reference-fft": { - "2": measured | {"metrics": {"generation_seconds": 2.0}}, - }, - "recurrence-direct": { - "2": measured | {"metrics": {"generation_seconds": 4.0}}, - }, - "madgraph-standalone": { - "2": measured | {"metrics": {"generation_seconds": 6.0}}, - }, - }, - "ddbar": { - "amplicol": { - "2": measured | {"metrics": {"generation_seconds": 3.0}}, - } - }, - } - line_filters = plots.LineFilterOptions( - main_include_lines=("reference-fft",), - main_veto_lines=("reference-fft",), - ratio_veto_lines=("pyamplicol-recurrence",), - ) - - payload = plots._plot_data_payload( - "abc123", - report, - line_filters=line_filters, - ) - generation = payload["families"]["gg"]["metrics"]["generation"] - - assert payload["line_filters"]["main"]["include_lines"] == ["reference-fft"] - assert payload["line_filters"]["main"]["veto_lines"] == ["reference-fft"] - assert generation["main_axis"]["range"] == pytest.approx([1.0, 4.0]) - assert generation["ratio_axis"]["range"] == pytest.approx( - [10**-0.1, 3.0 * 10**0.1] - ) - assert set(generation["modes"]) == {"reference-fft", "madgraph-standalone"} - assert generation["modes"]["reference-fft"]["visible_in_main"] is True - assert generation["modes"]["reference-fft"]["visible_in_ratio"] is True - assert generation["modes"]["reference-fft"]["series"] == [ - {"n": 2, "value": 2.0} - ] - assert generation["modes"]["madgraph-standalone"]["visible_in_main"] is False - assert generation["modes"]["madgraph-standalone"]["visible_in_ratio"] is True - assert generation["modes"]["madgraph-standalone"]["series"] == [] - assert generation["modes"]["madgraph-standalone"]["ratio_to_baseline"] == [ - {"n": 2, "value": 3.0} - ] - - -def test_axis_options_validate_log_positive_ranges() -> None: - linear = plots._parser().parse_args( - [ - "report.json", - "plots", - "--ratio-y-scale", - "linear", - "--ratio-y-range", - "0", - "2", - ] - ) - assert plots._axis_options_from_arguments(linear).ratio_y_range == (0.0, 2.0) - - log = plots._parser().parse_args( - ["report.json", "plots", "--ratio-y-range", "0", "2"] - ) - with pytest.raises(plots.PlotError, match="logarithmic y-axis"): - plots._axis_options_from_arguments(log) - - -def test_recola_results_overlay_is_plotted_and_exported(tmp_path: Path) -> None: - report = _report(None) - report["policy"].update( - { - "process_families": { - "gg": {"modes": ["reference-fft"]}, - "ddbar": {"modes": ["amplicol"]}, - }, - "measurement": {"warm_fixed_helicity": True}, - } - ) - report["status"] = "complete" - measured = { - "status": "measured", - "warm_fixed_helicity": True, - } - report["cells"] = { - "gg": { - "reference-fft": { - "2": measured - | { - "metrics": { - "generation_seconds": 2.0, - "warm_seconds_per_point": 0.2, - "max_rss_kib": 2048.0, - } - } - } - }, - "ddbar": { - "amplicol": { - "2": measured - | { - "metrics": { - "generation_seconds": 4.0, - "warm_seconds_per_point": 0.4, - "max_rss_kib": 4096.0, - } - } - } - }, - } - recola_path = tmp_path / "recola.json" - recola_path.write_text( - json.dumps( - { - "config": {"polarized": True}, - "results": { - "all_gluon": { - "2": { - "family": "all_gluon", - "process": "g g -> g g", - "gen_time_s": 5.0, - "run_time_s": 0.5, - "ram_after_generation_mib": 7.0, - "ram_after_profile_mib": 8.0, - "peak_generation_rss_mib": 6.0, - "polarized": True, - "helicity": [1, 1, 1, 1], - "profiled_call": "get_polarized_squared_amplitude_rcl", - }, - "3": None, - "4": { - "status": "limit_reached", - "error": "all_gluon, n=4: generation time exceeded", - }, - }, - "down_quark_qcd": { - "2": { - "family": "down_quark_qcd", - "process": "d d~ -> d d~", - "gen_time_s": 6.0, - "run_time_s": 0.6, - "peak_generation_rss_mib": 9.0, - "polarized": True, - } - }, - }, - } - ), - encoding="utf-8", - ) - - metadata = plots._attach_recola_results(report, recola_path) - external_sources = {"recola_results": metadata} - payload = plots._plot_data_payload( - "abc123", - report, - external_sources=external_sources, - ) - output_directory = tmp_path / "plots" - output_directory.mkdir() - data_path = plots._write_plot_data( - "abc123", - report, - output_directory, - external_sources=external_sources, - ) - persisted = json.loads(data_path.read_text(encoding="utf-8")) - - generation = payload["families"]["gg"]["metrics"]["generation"] - warm = payload["families"]["gg"]["metrics"]["warm-runtime"] - rss = payload["families"]["gg"]["metrics"]["rss"] - ddbar_generation = payload["families"]["ddbar"]["metrics"]["generation"] - - assert payload["external_sources"]["recola_results"]["sha256"] == plots._sha256( - recola_path - ) - assert persisted == payload - assert generation["modes"]["recola"]["label"] == "Recola" - assert generation["modes"]["recola"]["series"] == [{"n": 2, "value": 5.0}] - assert generation["modes"]["recola"]["ratio_to_baseline"] == [ - {"n": 2, "value": 2.5} - ] - assert warm["modes"]["recola"]["series"] == [{"n": 2, "value": 0.5}] - assert rss["modes"]["recola"]["series"] == [{"n": 2, "value": 8.0}] - assert ddbar_generation["modes"]["recola"]["series"] == [ - {"n": 2, "value": 6.0} - ] - assert plots._status_notes( - report, - "gg", - ("recola",), - family_cells=report["runtime_series"]["gg"], - ) == ["Recola: n=4 failed (configured setup-time limit)."] - - -def test_recola_results_overlay_rejects_workload_mismatch(tmp_path: Path) -> None: - report = _report(None) - report["policy"].update( - { - "process_families": {"gg": {"modes": ["reference-fft"]}}, - "measurement": {"warm_fixed_helicity": True}, - } - ) - report["cells"] = {"gg": {"reference-fft": {}}} - recola_path = tmp_path / "recola-unpolarized.json" - recola_path.write_text( - json.dumps( - { - "config": {"polarized": False}, - "results": { - "all_gluon": { - "2": { - "family": "all_gluon", - "gen_time_s": 1.0, - "run_time_s": 0.1, - } - } - }, - } - ), - encoding="utf-8", - ) - - with pytest.raises(plots.PlotError, match="campaign report is fixed"): - plots._attach_recola_results(report, recola_path) - - -def test_final_series_palette_line_styles_and_legend_grouping() -> None: - assert plots.MODE_STYLES["reference-fft"] == ("#000000", "o", "-") - assert plots.MODE_STYLES["amplicol"] == ("#F0E442", "D", "-") - assert plots.MODE_STYLES["madgraph-standalone"] == ("#CC3311", "*", "-") - assert plots.MODE_STYLES["recurrence-fft"] == ("#009E73", "s", "-") - assert plots.MODE_STYLES["recurrence-direct"] == ("#009E73", "o", "--") - assert plots.MODE_STYLES["otf-fft"] == ("#0072B2", "v", "-") - assert plots.MODE_STYLES["otf-direct"] == ("#0072B2", "^", "--") - assert plots.MODE_STYLES["recola"] == ("#AA4499", "h", "-") - - assert plots.LEGEND_MODE_ORDER["gg"] == ( - "reference-fft", - "amplicol", - "recurrence-fft", - "recurrence-direct", - "otf-fft", - "otf-direct", - "madgraph-standalone", - "recola", - ) - assert plots.LEGEND_MODE_ORDER["ddbar"] == ( - "amplicol", - "madgraph-standalone", - "recurrence-fft", - "recurrence-direct", - "otf-fft", - "otf-direct", - "recola", - ) - - -def test_renderer_includes_measured_otf_cells_beyond_default_frontier() -> None: - family_cells = { - mode: { - str(n): { - "status": "measured", - "label": label, - "metrics": {"warm_seconds_per_point": float(n)}, - } - for n in (6, 7) - } - for mode, label in ( - ("otf-direct", "pyAmpliCol - OTF"), - ("otf-fft", "pyAmpliCol - OTF - FFT"), - ("recurrence-fft", "pyAmpliCol - recurrence - FFT"), - ) - } - - assert plots._series(family_cells, "otf-direct", plots.METRICS[1]) == [ - (6, 6.0), - (7, 7.0), - ] - assert plots._series(family_cells, "otf-fft", plots.METRICS[1]) == [ - (6, 6.0), - (7, 7.0), - ] - assert plots._series(family_cells, "recurrence-fft", plots.METRICS[1]) == [ - (6, 6.0), - (7, 7.0), - ] - assert ( - plots._plot_policy_notes( - _report(None), "ddbar", plots.METRICS[1], family_cells - ) - == [] - ) - - -def test_madgraph_external_series_is_added_to_all_three_metrics() -> None: - report = _report() - report["policy"]["process_families"] = {"gg": {"modes": ["reference-fft"]}} - report["cells"] = { - "gg": { - "reference-fft": { - "2": { - "status": "measured", - "metrics": { - "generation_seconds": 2.0, - "warm_seconds_per_point": 3.0, - }, - } - } - } - } - report["runtime_series"] = { - "gg": { - "madgraph-standalone": { - "2": { - "status": "measured", - "metrics": { - "generation_seconds": 5.0, - "warm_seconds_per_point": 4.0, - "max_rss_kib": 6144.0, - }, - } - } - } - } - - warm_cells, warm_modes = plots._family_cells_for_metric( - report, "gg", plots.METRICS[1] - ) - generation_cells, generation_modes = plots._family_cells_for_metric( - report, "gg", plots.METRICS[0] - ) - rss_cells, rss_modes = plots._family_cells_for_metric( - report, "gg", plots.METRICS[2] - ) - - assert warm_modes == ("reference-fft", "madgraph-standalone") - assert plots._series(warm_cells, "madgraph-standalone", plots.METRICS[1]) == [ - (2, 4.0) - ] - assert generation_modes == ("reference-fft", "madgraph-standalone") - assert plots._series(generation_cells, "madgraph-standalone", plots.METRICS[0]) == [ - (2, 5.0) - ] - assert rss_modes == ("reference-fft", "madgraph-standalone") - assert plots._series(rss_cells, "madgraph-standalone", plots.METRICS[2]) == [ - (2, 6.0) - ] - - -def test_metric_series_exclusion_omits_only_invalid_warm_curve() -> None: - report = _report(None) - report["policy"].update( - { - "process_families": {"gg": {"modes": ["reference-fft", "recurrence-fft"]}}, - "plot": { - "metric_series_exclusions": { - "warm_seconds_per_point": { - "gg": {"recurrence-fft": "driver evaluated all helicities"} - } - } - }, - } - ) - report["cells"] = { - "gg": { - mode: { - "2": { - "status": "measured", - "label": label, - "metrics": { - "generation_seconds": generation, - "warm_seconds_per_point": warm, - }, - } - } - for mode, label, generation, warm in ( - ("reference-fft", "Reference FFT", 1.0, 2.0), - ("recurrence-fft", "pyAmpliCol recurrence FFT", 3.0, 4.0), - ) - } - } - - warm_cells, warm_modes = plots._family_cells_for_metric( - report, "gg", plots.METRICS[1] - ) - generation_cells, generation_modes = plots._family_cells_for_metric( - report, "gg", plots.METRICS[0] - ) - - assert warm_modes == ("reference-fft",) - assert "recurrence-fft" not in warm_cells - assert generation_modes == ("reference-fft", "recurrence-fft") - assert plots._series(generation_cells, "recurrence-fft", plots.METRICS[0]) == [ - (2, 3.0) - ] - assert plots._plot_policy_notes( - report, "gg", plots.METRICS[1], report["cells"]["gg"] - ) == [ - "pyAmpliCol recurrence FFT: warmed runtime per point omitted " - "(driver evaluated all helicities)." - ] - - -def test_stopped_protocol_investigation_is_not_described_as_running() -> None: - report = _report(None) - report.update( - { - "status": "stopped-protocol-investigation", - "status_reason": "selected-output timing mismatch", - } - ) - - assert plots._status_notes(report, "gg", ()) == [ - "Campaign stopped: selected-output timing mismatch. Absent cells are " - "unattempted and omitted." - ] - - -def test_generation_timeout_is_presented_as_setup_time() -> None: - report = _report(None) - report["policy"]["measurement"] = {"generation_timeout_seconds": 300.0} - cell = {"failure_category": "generation-time-limit"} - - assert plots._failure_detail(report, cell) == "5 min setup-time limit" - - -def test_stopped_protocol_investigation_allows_empty_metric_panel(tmp_path) -> None: - report = _report(None) - report.update( - { - "status": "stopped-protocol-investigation", - "status_reason": "all warm measurements are withheld", - "cells": {"ddbar": {"amplicol": {}}}, - } - ) - report["policy"]["process_families"] = {"ddbar": {"modes": ["amplicol"]}} - - output = tmp_path / "empty-warm.png" - plots._plot_metric(report, "ddbar", plots.METRICS[1], output, dpi=72) - - assert output.is_file() - assert output.stat().st_size > 0 - - -def test_complete_report_rejects_empty_metric_panel(tmp_path) -> None: - report = _report(None) - report.update({"status": "complete", "cells": {"ddbar": {"amplicol": {}}}}) - report["policy"]["process_families"] = {"ddbar": {"modes": ["amplicol"]}} - - with pytest.raises(plots.PlotError, match="no measured positive"): - plots._plot_metric( - report, - "ddbar", - plots.METRICS[1], - tmp_path / "must-not-render.png", - dpi=72, - ) - - -def test_legacy_warm_quality_advisory_is_an_ordinary_series_point() -> None: - family_cells = { - "recurrence-fft": { - "3": { - "status": "measured", - "metrics": {"warm_seconds_per_point": 3.0}, - "excluded_metrics": { - "warm_seconds_per_point": { - "status": "excluded-provisional-warm-quality", - "value": 4.0, - } - }, - } - } - } - - assert plots._series( - family_cells, "recurrence-fft", plots.METRICS[1] - ) == [(3, 4.0)] - - -def test_other_metric_exclusion_reasons_remain_invisible() -> None: - family_cells = { - "recurrence-fft": { - "3": { - "status": "measured", - "metrics": {"warm_seconds_per_point": 3.0}, - "excluded_metrics": { - "warm_seconds_per_point": { - "status": "excluded-runtime-selection-semantics", - "value": 4.0, - } - }, - } - } - } - - assert plots._series( - family_cells, "recurrence-fft", plots.METRICS[1] - ) == [] - - -def test_legacy_warm_quality_advisory_does_not_break_curve() -> None: - family_cells = { - "recurrence-fft": { - "2": { - "status": "measured", - "metrics": {"warm_seconds_per_point": 2.0}, - }, - "3": { - "status": "measured", - "metrics": {}, - "excluded_metrics": { - "warm_seconds_per_point": { - "status": "excluded-provisional-warm-quality", - "value": 3.0, - } - }, - }, - "4": { - "status": "measured", - "metrics": {"warm_seconds_per_point": 4.0}, - }, - } - } - - series = plots._series(family_cells, "recurrence-fft", plots.METRICS[1]) - - assert series == [(2, 2.0), (3, 3.0), (4, 4.0)] - assert list(plots._consecutive_runs(series)) == [series] - - -def test_complete_panel_can_render_only_legacy_warm_quality_advisory( - tmp_path, -) -> None: - report = _report(None) - report.update( - { - "status": "complete", - "cells": { - "ddbar": { - "amplicol": { - "2": { - "status": "measured", - "label": "AmpliCol", - "metrics": {}, - "excluded_metrics": { - "warm_seconds_per_point": { - "status": ( - "excluded-provisional-warm-quality" - ), - "value": 2.5, - } - }, - } - } - } - }, - } - ) - report["policy"]["process_families"] = { - "ddbar": {"modes": ["amplicol"]} - } - - output = tmp_path / "legacy-advisory-only-warm.png" - plots._plot_metric(report, "ddbar", plots.METRICS[1], output, dpi=72) - - assert output.is_file() - assert output.stat().st_size > 0 - - -@pytest.mark.parametrize("boundary", (6.0, True, 9)) -def test_source_boundary_rejects_ambiguous_values(boundary: object) -> None: - with pytest.raises(plots.PlotError, match="source_boundary_after_n"): - plots._source_boundary(_report(boundary)) diff --git a/pyamplicol/tests/unit/test_final_source_numerical_truth.py b/pyamplicol/tests/unit/test_final_source_numerical_truth.py deleted file mode 100644 index af10f97180..0000000000 --- a/pyamplicol/tests/unit/test_final_source_numerical_truth.py +++ /dev/null @@ -1,327 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -from dataclasses import dataclass -from decimal import Decimal -from pathlib import Path - -import pytest - -from pyamplicol.generation.structural_source_proof import ( - ROLE as STRUCTURAL_SOURCE_PROOF_ROLE, -) -from pyamplicol.generation.structural_source_proof import ( - build_generation_structural_proof, -) -from tools.developer.final_source_numerical_truth import ( - REFERENCE_SCHEMA, - TruthProducerError, - build_witness, - comparison_sha256, - validate_witness_payload, -) -from tools.performance_report.models import Accuracy, ExecutionMode, Workload - -REVISION = "a" * 40 - - -@dataclass -class _Resolved: - values: tuple[tuple[tuple[complex | Decimal, ...], ...], ...] - helicity_ids: tuple[str, ...] - color_ids: tuple[str, ...] - color_accuracy: str - - -class _Runtime: - def __init__(self, artifact_id: str, mode: str, accuracy: str) -> None: - self.artifact_id = artifact_id - self.execution_mode = mode - self._accuracy = accuracy - - def evaluate_resolved( - self, - _momenta: object, - *, - helicities: object, - color_flows: object, - precision: int, - ) -> _Resolved: - selected_helicities = ("h:0",) if helicities else ("h:0", "h:1") - selected_colors = ("c:0",) - value: complex | Decimal = 1 + 0j if precision == 16 else Decimal("1") - return _Resolved( - values=( - tuple( - tuple(value for _color in selected_colors) - for _helicity in selected_helicities - ), - ), - helicity_ids=selected_helicities, - color_ids=selected_colors, - color_accuracy=self._accuracy, - ) - - -def _write_artifact( - root: Path, - *, - artifact_id: str, - mode: str, - accuracy: str, - reference: bool, -) -> None: - process_id = "process" - execution_path = "processes/process/execution.json" - validation_path = "processes/process/validation-momenta.json" - execution_payload = { - "schema_version": 3, - "kind": mode, - "key": process_id, - "process": "d d~ > z", - "color_accuracy": accuracy, - "external_pdg_order": [1, -1, 23], - "source_count": 3, - "current_count": 5, - "interaction_count": 7, - "amplitude_root_count": 1, - "semantic": "reference" if reference else "candidate", - } - execution = json.dumps(execution_payload, sort_keys=True).encode() - validation = json.dumps( - { - "available": True, - "points": [ - [ - {"pdg": 1, "momentum": ["5", "0", "0", "5"]}, - {"pdg": -1, "momentum": ["5", "0", "0", "-5"]}, - {"pdg": 23, "momentum": ["10", "0", "0", "0"]}, - ] - ], - }, - sort_keys=True, - ).encode() - (root / "processes" / "process").mkdir(parents=True) - (root / execution_path).write_bytes(execution) - (root / validation_path).write_bytes(validation) - payloads: list[dict[str, object]] = [ - { - "path": execution_path, - "role": "evaluator-manifest", - "process_id": process_id, - "sha256": hashlib.sha256(execution).hexdigest(), - }, - { - "path": validation_path, - "role": "validation-momenta", - "process_id": process_id, - "sha256": hashlib.sha256(validation).hexdigest(), - }, - ] - native_inputs = "b" * 64 - structural_path = "processes/process/structural-source-proof.json" - structural = build_generation_structural_proof( - artifact_root=root, - process_id=process_id, - source_revision=REVISION, - native_build_inputs_sha256=native_inputs, - execution_path=execution_path, - execution_sha256=hashlib.sha256(execution).hexdigest(), - execution=execution_payload, - evaluator_container_path=None, - evaluator_container_index_sha256=None, - ) - structural_bytes = json.dumps(structural, sort_keys=True).encode() - (root / structural_path).write_bytes(structural_bytes) - payloads.append( - { - "path": structural_path, - "role": STRUCTURAL_SOURCE_PROOF_ROLE, - "process_id": process_id, - "sha256": hashlib.sha256(structural_bytes).hexdigest(), - } - ) - if reference: - contract_path = "independent-reference-semantics.json" - contract = json.dumps( - { - "schema": REFERENCE_SCHEMA, - "status": "materialized", - "source_revision": REVISION, - "artifact_id": artifact_id, - "process_id": process_id, - "semantics": "pre-optimization-reference", - "semantic_payloads": [ - { - "path": execution_path, - "sha256": hashlib.sha256(execution).hexdigest(), - } - ], - }, - sort_keys=True, - ).encode() - (root / contract_path).write_bytes(contract) - payloads.append( - { - "path": contract_path, - "role": "independent-reference-semantics", - "sha256": hashlib.sha256(contract).hexdigest(), - } - ) - (root / "artifact.json").write_text( - json.dumps( - { - "artifact_id": artifact_id, - "producer": { - "git_revision": REVISION, - "native_build_inputs_sha256": native_inputs, - }, - "default_process_id": process_id, - "processes": [ - { - "id": process_id, - "color_accuracy": accuracy, - } - ], - "payloads": payloads, - } - ) - ) - - -@pytest.mark.parametrize( - ("mode", "accuracy", "workload", "helicities", "colors"), - [ - ( - ExecutionMode.RECURRENCE, - Accuracy.LC, - Workload.SELECTED_FLOW, - ("h:0",), - ("c:0",), - ), - (ExecutionMode.COMPILED, Accuracy.NLC, Workload.CONTRACTED, (), ()), - (ExecutionMode.EAGER, Accuracy.FULL, Workload.CONTRACTED, (), ()), - ], -) -def test_builds_cross_mode_independent_precision80_witness( - tmp_path: Path, - mode: ExecutionMode, - accuracy: Accuracy, - workload: Workload, - helicities: tuple[str, ...], - colors: tuple[str, ...], -) -> None: - candidate = tmp_path / "candidate" - reference = tmp_path / "reference" - candidate_id = hashlib.sha256(f"candidate-{mode.value}".encode()).hexdigest() - reference_id = hashlib.sha256(f"reference-{mode.value}".encode()).hexdigest() - _write_artifact( - candidate, - artifact_id=candidate_id, - mode=mode.value, - accuracy=accuracy.value, - reference=False, - ) - _write_artifact( - reference, - artifact_id=reference_id, - mode=mode.value, - accuracy=accuracy.value, - reference=True, - ) - runtimes = { - candidate.resolve(): _Runtime(candidate_id, mode.value, accuracy.value), - reference.resolve(): _Runtime(reference_id, mode.value, accuracy.value), - } - - witness = build_witness( - candidate, - reference, - reference_contract_path="independent-reference-semantics.json", - cell_id=f"cell-{mode.value}-{accuracy.value}", - source_revision=REVISION, - mode=mode, - accuracy=accuracy, - workload=workload, - helicity_ids=helicities, - color_ids=colors, - runtime_loader=lambda path, **_kwargs: runtimes[Path(path).resolve()], - ) - - assert witness["status"] == "ok" - assert witness["precision_decimal_digits"] == 80 - assert witness["agreement"]["passes"] is True - assert validate_witness_payload(witness) == witness - - -def test_rejects_self_reference_and_digest_tampering(tmp_path: Path) -> None: - artifact = tmp_path / "artifact" - artifact_id = hashlib.sha256(b"same").hexdigest() - _write_artifact( - artifact, - artifact_id=artifact_id, - mode=ExecutionMode.COMPILED.value, - accuracy=Accuracy.LC.value, - reference=True, - ) - runtime = _Runtime(artifact_id, ExecutionMode.COMPILED.value, Accuracy.LC.value) - with pytest.raises(TruthProducerError, match="one content identity"): - build_witness( - artifact, - artifact, - reference_contract_path="independent-reference-semantics.json", - cell_id="cell", - source_revision=REVISION, - mode=ExecutionMode.COMPILED, - accuracy=Accuracy.LC, - workload=Workload.ALL_FLOW, - runtime_loader=lambda _path, **_kwargs: runtime, - ) - - -def test_validator_recomputes_values_and_comparison_sha(tmp_path: Path) -> None: - candidate = tmp_path / "candidate" - reference = tmp_path / "reference" - candidate_id = hashlib.sha256(b"candidate").hexdigest() - reference_id = hashlib.sha256(b"reference").hexdigest() - for root, identifier, is_reference in ( - (candidate, candidate_id, False), - (reference, reference_id, True), - ): - _write_artifact( - root, - artifact_id=identifier, - mode=ExecutionMode.COMPILED.value, - accuracy=Accuracy.LC.value, - reference=is_reference, - ) - runtimes = { - candidate.resolve(): _Runtime( - candidate_id, - ExecutionMode.COMPILED.value, - Accuracy.LC.value, - ), - reference.resolve(): _Runtime( - reference_id, - ExecutionMode.COMPILED.value, - Accuracy.LC.value, - ), - } - witness = build_witness( - candidate, - reference, - reference_contract_path="independent-reference-semantics.json", - cell_id="cell", - source_revision=REVISION, - mode=ExecutionMode.COMPILED, - accuracy=Accuracy.LC, - workload=Workload.ALL_FLOW, - runtime_loader=lambda path, **_kwargs: runtimes[Path(path).resolve()], - ) - witness["reference_exact"]["values"][0][0][0] = "2" - witness["reference_exact"]["values_sha256"] = "0" * 64 - witness["comparison_sha256"] = comparison_sha256(witness) - with pytest.raises(TruthProducerError, match="values digest mismatch"): - validate_witness_payload(witness) diff --git a/pyamplicol/tests/unit/test_four_quark_compiled_gate.py b/pyamplicol/tests/unit/test_four_quark_compiled_gate.py deleted file mode 100644 index 3ace4f6200..0000000000 --- a/pyamplicol/tests/unit/test_four_quark_compiled_gate.py +++ /dev/null @@ -1,737 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import argparse -import os -from collections.abc import Callable -from copy import deepcopy -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.developer import four_quark_compiled_gate as gate - - -def test_checked_file_identity_rejects_a_symlink(tmp_path: Path) -> None: - if not hasattr(os, "O_NOFOLLOW"): - pytest.skip("O_NOFOLLOW is unavailable") - target = tmp_path / "target.bin" - target.write_bytes(b"authenticated") - link = tmp_path / "link.bin" - link.symlink_to(target) - with pytest.raises(gate.GateError, match="checked fd"): - gate._regular_file_identity(link) - - -def _source_leaf( - *, - path: str = "evaluators/stage.symjit", - output_len: int = 1, - include_plane: bool = True, -) -> dict[str, object]: - leaf: dict[str, object] = { - "kind": "symjit-application-evaluator", - "backend": "jit", - "runtime_capability": gate.SYMJIT_RUNTIME_CAPABILITY, - "input_len": 1, - "output_len": output_len, - "application_path": path, - "application_abi": gate.SYMJIT_APPLICATION_ABI, - "optimization_level": 3, - } - if include_plane: - leaf["plane_application"] = { - "application_path": path.replace(".symjit", ".plane.symjit"), - "application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "storage_abi": gate.SYMJIT_APPLICATION_ABI, - "translation_mode": "symbolica-structured-instructions", - "optimization_level": 3, - "direct_arena": True, - "source_digest": "1" * 64, - } - return leaf - - -def _certificate(payload: dict[str, object]) -> dict[str, object]: - return {**payload, "digest": gate._canonical_sha256(payload)} - - -def _direct_policies() -> dict[str, object]: - return { - "kind": gate.COMPILED_STAGE_PLAN_KIND, - "schema_version": gate.COMPILED_STAGE_PLAN_SCHEMA_VERSION, - "application_abi": gate.COMPILED_PLANE_DIRECT_APPLICATION_ABI, - "source_application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "element_layout": "split-complex-component-major", - "input_output_aliasing": "forbidden", - "output_output_aliasing": "forbidden", - "output_operation": "overwrite", - "output_factor": "identity", - "input_bindings": [ - { - "kind": "value", - "parameter_index": 0, - "source_id": 0, - "component": 0, - "global_component": 0, - "real_valued": False, - } - ], - } - - -def _stage() -> dict[str, object]: - stage: dict[str, object] = { - "stage_index": 1, - "stage_kind": "amplitude-roots", - "interaction_ids": [], - "output_length": 1, - "output_slots": [ - { - "current_id": -1, - "component_start": 0, - "component_stop": 1, - "output_start": 0, - "output_stop": 1, - } - ], - "evaluator": _source_leaf(), - } - order = { - "kind": "whole-current-canonical-order-v1", - "current_ids": [], - "source_stage_interaction_ids": [], - "interaction_ids": [], - "evaluation_group_ids": [], - "destinations": [ - { - "destination_id": 0, - "owner_kind": "amplitude", - "owner_id": 0, - "output_start": 0, - "output_stop": 1, - "interaction_ids": [], - "evaluation_group_ids": [], - "ownership": {"kind": "residual"}, - } - ], - } - stage["compiled_plane_arena"] = { - **_direct_policies(), - "output_bindings": [{"arena": "amplitude", "component": 0, "output_index": 0}], - "residual_leaves": [ - { - "kind": gate.COMPILED_RESIDUAL_LEAF_KIND, - "leaf_id": 0, - "application_path": "evaluators/stage.plane.symjit", - "source_application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "optimization_level": 3, - "direct_codegen_optimization_level": 3, - "input_indices": [0], - "input_len": 1, - "output_len": 1, - "output_indices": [0], - "output_ranges": [{"output_start": 0, "output_stop": 1}], - "selector_domain_ids": [], - "color_selector_domain_ids": [], - } - ], - "residual_output_ranges": [{"output_start": 0, "output_stop": 1}], - "kernels": [], - "islands": [], - "order_certificate": _certificate(order), - "census": { - "schema_version": 1, - "stage_kernel_count": 0, - "stage_island_count": 0, - "stage_invocation_count": 0, - "stage_attachment_count": 0, - "stage_residual_leaf_count": 1, - "stage_table_destination_count": 0, - "stage_residual_destination_count": 1, - }, - } - return stage - - -def _mixed_current_stage() -> dict[str, object]: - stage: dict[str, object] = { - "stage_index": 0, - "stage_kind": "current-stage", - "interaction_ids": [], - "output_length": 2, - "output_slots": [ - { - "current_id": 10, - "component_start": 4, - "component_stop": 5, - "output_start": 0, - "output_stop": 1, - }, - { - "current_id": 11, - "component_start": 5, - "component_stop": 6, - "output_start": 1, - "output_stop": 2, - }, - ], - "evaluator": _source_leaf(path="evaluators/residual.symjit"), - } - dependency = { - "kind": "independent-whole-current-group-v1", - "current_ids": [11], - "rows": [ - { - "row_index": 0, - "current_id": 11, - "predecessor_current_ids": [1, 2], - "interaction_ids": [], - "evaluation_group_ids": [], - } - ], - } - order = { - "kind": "whole-current-canonical-order-v1", - "current_ids": [10, 11], - "source_stage_interaction_ids": [], - "interaction_ids": [], - "evaluation_group_ids": [], - "destinations": [ - { - "destination_id": 0, - "owner_kind": "current", - "owner_id": 10, - "output_start": 0, - "output_stop": 1, - "interaction_ids": [], - "evaluation_group_ids": [], - "ownership": {"kind": "residual"}, - }, - { - "destination_id": 1, - "owner_kind": "current", - "owner_id": 11, - "output_start": 1, - "output_stop": 2, - "interaction_ids": [], - "evaluation_group_ids": [], - "ownership": {"kind": "table", "island_id": 0, "row_index": 0}, - }, - ], - } - stage["compiled_plane_arena"] = { - **_direct_policies(), - "output_bindings": [ - {"arena": "current", "component": 4, "output_index": 0}, - {"arena": "current", "component": 5, "output_index": 1}, - ], - "residual_leaves": [ - { - "kind": gate.COMPILED_RESIDUAL_LEAF_KIND, - "leaf_id": 0, - "application_path": "evaluators/residual.plane.symjit", - "source_application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "optimization_level": 3, - "direct_codegen_optimization_level": 3, - "input_indices": [0], - "input_len": 1, - "output_len": 1, - "output_indices": [0], - "output_ranges": [{"output_start": 0, "output_stop": 1}], - "selector_domain_ids": [], - "color_selector_domain_ids": [], - } - ], - "residual_output_ranges": [{"output_start": 0, "output_stop": 1}], - "kernels": [ - { - "kernel_id": 0, - "motif_digest": "1" * 64, - "exact_source_digest": "2" * 64, - "source_application_abi": gate.SYMJIT_PLANE_APPLICATION_ABI, - "application_abi": gate.COMPILED_PLANE_DIRECT_APPLICATION_ABI, - "descriptor_abi": gate.COMPILED_DIRECT_TABLE_DESCRIPTOR_ABI, - "binding_abi": gate.COMPILED_DIRECT_TABLE_BINDING_ABI, - "application_path": "evaluators/kernel.plane.symjit", - "application_sha256": "3" * 64, - "application_size_bytes": 4096, - "descriptor_path": "evaluators/kernel.table", - "descriptor_sha256": "4" * 64, - "descriptor_size_bytes": 256, - "optimization_level": 3, - "input_complex_count": 1, - "output_complex_count": 1, - "input_plane_count": 2, - "scalar_input_count": 0, - "parameter_bindings": [], - } - ], - "islands": [ - { - "island_id": 0, - "kernel_id": 0, - "current_ids": [11], - "selector_domain_ids": [], - "invocation_rows": [ - { - "plane_ids": [0, 1], - "attachment_start": 0, - "attachment_count": 1, - } - ], - "attachment_rows": [ - { - "destination_plane_ids": [2, 3], - "factor_id": 0, - "operation": "overwrite", - } - ], - "factors": [[1.0, 0.0]], - "plane_bindings": [], - "scalar_bindings": [], - "dependency_certificate": _certificate(dependency), - } - ], - "order_certificate": _certificate(order), - "census": { - "schema_version": 1, - "stage_kernel_count": 1, - "stage_island_count": 1, - "stage_invocation_count": 1, - "stage_attachment_count": 1, - "stage_residual_leaf_count": 1, - "stage_table_destination_count": 1, - "stage_residual_destination_count": 1, - }, - } - return stage - - -def _execution_payload() -> dict[str, object]: - return { - "required_runtime_capabilities": [ - gate.COMPILED_PLANE_ARENA_CAPABILITY, - gate.SYMJIT_RUNTIME_CAPABILITY, - ], - "compiled": { - "model_parameter_evaluator": { - "kind": "model-parameter-evaluator", - "evaluator": _source_leaf(include_plane=False), - }, - "stage_evaluators": { - "kind": "generic-dag-stage-evaluator-artifacts", - "runtime_available": True, - "required_runtime_capabilities": [ - gate.COMPILED_PLANE_ARENA_CAPABILITY, - gate.SYMJIT_RUNTIME_CAPABILITY, - ], - "stage_count": 2, - "stages": [_mixed_current_stage()], - "amplitude_stage": _stage(), - }, - }, - } - - -def _capture(offset: float = 0.0) -> gate.EvaluationCapture: - return gate.EvaluationCapture( - physics_axes={ - "process": gate.PROCESS, - "helicities": ["h:one"], - "color_flows": ["flow:one"], - }, - f64_total=(complex(1.0 + offset), complex(2.0 + offset)), - exact_total=(complex(1.0 + offset), complex(2.0 + offset)), - f64_components=(complex(0.25 + offset), complex(0.75)), - exact_components=(complex(0.25 + offset), complex(0.75)), - color_probe=(complex(0.5 + offset), complex(1.0)), - helicity_probe=(complex(0.4 + offset), complex(0.8)), - ) - - -def test_recursive_direct_arena_audit_accepts_complete_o3_stage() -> None: - result = gate._audit_execution_payload(_execution_payload()) - - assert result == { - "capability": gate.COMPILED_PLANE_ARENA_CAPABILITY, - "capability_declaration_count": 2, - "stage_set_count": 1, - "stage_count": 2, - "descriptor_count": 2, - "leaf_count": 2, - "kernel_count": 1, - "island_count": 1, - "invocation_count": 1, - "attachment_count": 1, - "residual_destination_count": 2, - "table_destination_count": 1, - "model_parameter_slot_count": 1, - "model_parameter_evaluator_count": 1, - "model_parameter_direct_application_count": 0, - "passes": True, - } - - -def test_recursive_audit_rejects_v1_and_split_ownership() -> None: - payload = _execution_payload() - amplitude = payload["compiled"]["stage_evaluators"]["amplitude_stage"] - amplitude["compiled_plane_arena"]["schema_version"] = 1 - with pytest.raises(gate.GateError, match="wrong schema"): - gate._audit_execution_payload(payload) - - payload = _execution_payload() - current = payload["compiled"]["stage_evaluators"]["stages"][0] - descriptor = current["compiled_plane_arena"] - order = descriptor["order_certificate"] - order["destinations"][0]["ownership"] = { - "kind": "table", - "island_id": 0, - "row_index": 0, - } - order["digest"] = gate._canonical_sha256( - {name: value for name, value in order.items() if name != "digest"} - ) - with pytest.raises(gate.GateError, match="ownership"): - gate._audit_execution_payload(payload) - - -def test_table_only_stage_may_omit_the_residual_evaluator() -> None: - stage = _mixed_current_stage() - stage["evaluator"] = None - stage["output_length"] = 1 - stage["output_slots"] = [ - { - "current_id": 11, - "component_start": 5, - "component_stop": 6, - "output_start": 0, - "output_stop": 1, - } - ] - descriptor = stage["compiled_plane_arena"] - descriptor["output_bindings"] = [ - {"arena": "current", "component": 5, "output_index": 0} - ] - descriptor["residual_leaves"] = [] - descriptor["residual_output_ranges"] = [] - order_subject = { - "kind": "whole-current-canonical-order-v1", - "current_ids": [11], - "source_stage_interaction_ids": [], - "interaction_ids": [], - "evaluation_group_ids": [], - "destinations": [ - { - "destination_id": 0, - "owner_kind": "current", - "owner_id": 11, - "output_start": 0, - "output_stop": 1, - "interaction_ids": [], - "evaluation_group_ids": [], - "ownership": {"kind": "table", "island_id": 0, "row_index": 0}, - } - ], - } - descriptor["order_certificate"] = _certificate(order_subject) - descriptor["census"].update( - { - "stage_residual_leaf_count": 0, - "stage_residual_destination_count": 0, - } - ) - - result = gate._audit_direct_descriptor( - descriptor, - stage=stage, - label="table-only", - ) - - assert result["leaf_count"] == 0 - assert result["table_destination_count"] == 1 - - -@pytest.mark.parametrize( - "mutation, message", - [ - ( - lambda payload: payload["compiled"]["stage_evaluators"][ - "amplitude_stage" - ].pop("compiled_plane_arena"), - "compiled_plane_arena", - ), - ( - lambda payload: payload["compiled"]["stage_evaluators"]["amplitude_stage"][ - "compiled_plane_arena" - ]["residual_leaves"][0].update({"optimization_level": 2}), - "not JIT O3", - ), - ( - lambda payload: payload["compiled"]["stage_evaluators"]["amplitude_stage"][ - "compiled_plane_arena" - ]["residual_leaves"][0].update({"direct_codegen_optimization_level": 2}), - "does not match.*plane", - ), - ( - lambda payload: payload["compiled"]["stage_evaluators"]["amplitude_stage"][ - "compiled_plane_arena" - ]["residual_leaves"][0]["output_ranges"][0].update({"output_stop": 2}), - "residual", - ), - ( - lambda payload: payload["compiled"]["model_parameter_evaluator"].update( - {"compiled_plane_arena": {"kind": "compiled-plane-arena-stage"}} - ), - "model_parameter_evaluator illegally", - ), - ( - lambda payload: payload["compiled"]["model_parameter_evaluator"].update( - { - "nested": { - "application_abi": (gate.NATIVE_COMPILED_DIRECT_APPLICATION_ABI) - } - } - ), - "direct application ABI", - ), - ], -) -def test_recursive_direct_arena_audit_rejects_descriptor_drift( - mutation: Callable[[dict[str, object]], object], - message: str, -) -> None: - payload = deepcopy(_execution_payload()) - mutation(payload) - - with pytest.raises(gate.GateError, match=message): - gate._audit_execution_payload(payload) - - -def test_lc_cross_layout_audit_requires_exact_axes_and_pointwise_parity() -> None: - result = gate._cross_lc_parity(_capture(), _capture()) - - assert result["passes"] is True - assert result["physical_axes_match"] is True - assert set(result["comparisons"]) == { - "f64_totals", - "precision32_totals", - "f64_resolved_components", - "precision32_resolved_components", - "color_selector", - "helicity_selector", - } - - with pytest.raises(gate.GateError, match="physical axes differ"): - drift = _capture() - drift.physics_axes["color_flows"] = ["flow:other"] - gate._cross_lc_parity(_capture(), drift) - - with pytest.raises(gate.GateError, match="f64 totals failed"): - gate._cross_lc_parity(_capture(), _capture(offset=1.0e-3)) - - -def test_union_rejection_is_checked_through_public_color_config() -> None: - result = gate._assert_union_rejections() - - assert [entry["color_accuracy"] for entry in result] == ["nlc", "full"] - assert all(entry["rejected"] is True for entry in result) - assert all("all-flow-union" in entry["message"] for entry in result) - - -def test_content_identity_addresses_the_complete_evidence_body() -> None: - body = {"kind": gate.RESULT_KIND, "passes": True, "lanes": {"lc": [1, 2]}} - - addressed = gate._attach_content_identity(body) - - assert addressed["content_identity"]["sha256"] == gate._canonical_sha256(body) - assert gate._attach_content_identity(body) == addressed - assert gate._attach_content_identity({**body, "passes": False}) != addressed - - -def test_compiled_profile_requires_direct_calls_and_zero_boundary_traffic() -> None: - profile = { - "execution_mode": "compiled", - "evaluator_backend_call_count": 7, - "compiled_direct_arena_engine_count": 2, - "compiled_direct_arena_call_count": 7, - } - profile.update(dict.fromkeys(gate._ZERO_PROFILE_COUNTERS, 0)) - profile.update(dict.fromkeys(gate._ZERO_PROFILE_TIMES, 0.0)) - - evidence = gate._audit_compiled_direct_profile(profile) - - assert evidence["compiled_direct_arena_call_count"] == 7 - assert evidence["compiled_direct_arena_engine_count"] == 2 - assert evidence["legacy_boundary_component_total"] == 0 - with pytest.raises(gate.GateError, match="no backend calls"): - gate._audit_compiled_direct_profile( - {**profile, "compiled_direct_arena_call_count": 0} - ) - with pytest.raises(gate.GateError, match="legacy boundary traffic"): - gate._audit_compiled_direct_profile( - {**profile, "stage_input_copy_component_count": 1} - ) - with pytest.raises(gate.GateError, match="every evaluator backend call"): - gate._audit_compiled_direct_profile( - {**profile, "compiled_direct_arena_call_count": 6} - ) - - -def test_helicity_probe_is_computed_nonzero_and_self_representing() -> None: - def helicity( - identifier: str, - *, - computed: bool, - structural_zero: bool, - coefficient: float, - representative_id: str, - ) -> SimpleNamespace: - return SimpleNamespace( - id=identifier, - computed=computed, - structural_zero=structural_zero, - coefficient=coefficient, - representative_id=representative_id, - ) - - physics = SimpleNamespace( - helicities=( - helicity( - "zero", - computed=False, - structural_zero=True, - coefficient=0.0, - representative_id="zero", - ), - helicity( - "first", - computed=True, - structural_zero=False, - coefficient=1.0, - representative_id="first", - ), - helicity( - "alias", - computed=False, - structural_zero=False, - coefficient=1.0, - representative_id="first", - ), - helicity( - "second", - computed=True, - structural_zero=False, - coefficient=1.0, - representative_id="second", - ), - ) - ) - - selected, count = gate._select_helicity_probe(physics, lane_name="test") - - assert selected.id == "second" - assert count == 2 - - with pytest.raises(gate.GateError, match="no executable helicity"): - gate._select_helicity_probe( - SimpleNamespace(helicities=(physics.helicities[0],)), - lane_name="test", - ) - - -def test_orchestrator_uses_exactly_four_isolated_generation_lanes( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - generated: list[str] = [] - capture = _capture() - monkeypatch.setattr(gate, "_source_identity", lambda: {"revision": "a" * 40}) - monkeypatch.setattr(gate, "_runtime_identity", lambda source: {"bound": source}) - monkeypatch.setattr( - gate, - "_file_identity", - lambda path: {"path": str(path), "sha256": "c" * 64}, - ) - monkeypatch.setattr( - gate, - "_assert_union_rejections", - lambda: [{"color_accuracy": "nlc"}, {"color_accuracy": "full"}], - ) - monkeypatch.setattr( - gate, - "_prepare_output_root", - lambda output_root, replace: tmp_path, - ) - monkeypatch.setattr(gate, "_deterministic_points", lambda count: (((),),) * count) - monkeypatch.setattr( - gate, - "_points_identity", - lambda points: {"sha256": "b" * 64, "point_count": len(points)}, - ) - - def generate( - artifact: Path, - lane: gate.Lane, - *, - timeout: float, - expected_revision: str, - expected_runtime_sha256: str, - expected_script_sha256: str, - ) -> dict[str, object]: - generated.append(lane.name) - return { - "lane": lane.name, - "timeout": timeout, - "artifact": str(artifact), - "expected_revision": expected_revision, - "expected_runtime_sha256": expected_runtime_sha256, - "expected_script_sha256": expected_script_sha256, - } - - monkeypatch.setattr(gate, "_invoke_generation_worker", generate) - monkeypatch.setattr( - gate, - "_artifact_identity_and_audit", - lambda artifact, lane: ({"artifact_id": lane.name}, "process"), - ) - monkeypatch.setattr( - gate, - "_evaluate_artifact", - lambda artifact, process_id, lane, points: ({"passes": True}, capture), - ) - monkeypatch.setattr( - gate, - "_cross_lc_parity", - lambda topology, union: {"passes": True}, - ) - monkeypatch.setattr(gate, "_peak_rss_gib", lambda: 1.25) - arguments = argparse.Namespace( - output_root=tmp_path, - replace=False, - points=2, - generation_timeout=123.0, - ) - - result = gate.run_gate(arguments) - - assert generated == [lane.name for lane in gate.LANES] - assert set(result["lanes"]) == {lane.name for lane in gate.LANES} - assert result["passes"] is True - assert result["status"] == "ok" - assert result["source_identity_match"] is True - assert result["runtime_identity_match"] is True - assert result["gate_script_identity_match"] is True - assert result["content_identity"]["sha256"] == gate._canonical_sha256( - {key: value for key, value in result.items() if key != "content_identity"} - ) - - -def test_parser_documents_mandatory_watchdog_and_two_point_default() -> None: - parsed = gate.parser().parse_args(["--output-root", "out"]) - - assert parsed.points == 2 - assert parsed.generation_timeout == 10_800.0 - assert "--limit-gib 30" in gate.WATCHDOG_INVOCATION - assert "--output-root" in gate.WATCHDOG_INVOCATION diff --git a/pyamplicol/tests/unit/test_legacy_structural_proof.py b/pyamplicol/tests/unit/test_legacy_structural_proof.py deleted file mode 100644 index 4c600bb289..0000000000 --- a/pyamplicol/tests/unit/test_legacy_structural_proof.py +++ /dev/null @@ -1,403 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import multiprocessing -from pathlib import Path - -import pytest - -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.legacy_structure import ( - LEGACY_PROOF_SCHEMA, - LEGACY_SCOPE_REASON, - InstrumentationRecord, - LegacyStructuralProofError, - _instrument_direct_source, - _instrument_library_source, - _parse_direct, - _parse_module, - emit_legacy_scope_unavailable_proof, - emit_legacy_structural_proof, - instrument_legacy_structural_probes, -) -from tools.performance_report.models import Accuracy, Workload - -_MODULE = """\ -module amp1_1_lib - contains - subroutine evaluate_amp1_1(p,amps) - complex(kind=8),dimension(1),intent(out) :: amps - complex(kind=8),dimension(1:6,3) :: val_c - complex(kind=8),dimension(1:6,2) :: int_c - end subroutine evaluate_amp1_1 - subroutine compute_external_currents(pp,val_c) - call ext_quark(pp(0,1),-1,1,val_c(1,1)) - call ext_gluon(pp(0,2),-1,1,val_c(1,2)) - end subroutine compute_external_currents - subroutine vertex_2(pp,val_c,int_c) - integer,parameter,dimension(2) :: int1=[1,2] - end subroutine vertex_2 - subroutine combine_currents_2(pp,val_c,int_c) - integer,parameter,dimension(0:2,1) :: int1=reshape([3,1,2], shape=[3,1]) - end subroutine combine_currents_2 - subroutine compute_amps(amps,val_c) - complex(kind=8),dimension(1),intent(out) :: amps - amps(1)=sum(val_c(1:2,3)*val_c(1:2,1)) - end subroutine compute_amps -end module amp1_1_lib -""" - - -_DIRECT_OUTPUT = """\ -color_accuracy lc -AMPICOL_COLOR_PROBE_CURRENTS 3 -AMPICOL_COLOR_PROBE_VERTICES 2 -AMPICOL_COLOR_PROBE_AMPLITUDES 1 -AMPICOL_STRUCTURAL_CURRENT 1 1 1 0 1 -AMPICOL_STRUCTURAL_CURRENT 2 1 21 0 2 -AMPICOL_STRUCTURAL_CURRENT 3 0 1 0 3 -AMPICOL_STRUCTURAL_ATTACHMENT 3 1 1 1 -AMPICOL_STRUCTURAL_ATTACHMENT 3 2 2 -1 -AMPICOL_STRUCTURAL_KERNEL 1 2 0 1 2 1.0D+00 0.0D+00 -AMPICOL_STRUCTURAL_KERNEL_SINGLET 1 0 -AMPICOL_STRUCTURAL_KERNEL 2 3 0 2 1 2.0D+00 0.0D+00 -AMPICOL_STRUCTURAL_KERNEL_SINGLET 2 0 -AMPICOL_STRUCTURAL_DESTINATION 1 3 1 -""" - -_DIRECT_SOURCE = """\ - logical :: print_matrix, fixed_helicity - print_matrix = .false. - fixed_helicity = .false. - call get_environment_variable('AMPICOL_COLOR_PROBE_MATRIX',env_value) - if (trim(adjustl(env_value)).eq.'1') print_matrix = .true. - env_value = '' - call print_recursion_counts() - subroutine parse_color_accuracy() -""" - -_LIBRARY_SOURCE = """\ - logical :: print_matrix - print_matrix = .false. - call get_environment_variable('AMPICOL_COLOR_PROBE_MATRIX',env_value) - if (trim(adjustl(env_value)).eq.'1') print_matrix = .true. - - argc = command_argument_count() - call build_row_to_integral() - integer function colour_order_match_sign(jgroup,jint,row,pass,leg_map) -""" - - -def _instrument_probe_sources_in_process( - repository: str, - artifact_path: str, - entered: object, - release: object | None, - outcomes: object, - *, - interrupt: bool, -) -> None: - try: - with instrument_legacy_structural_probes( - Path(repository), - Path(artifact_path), - ): - entered.set() - if release is not None and not release.wait(timeout=5): - raise TimeoutError("test did not release instrumented checkout") - if interrupt: - raise KeyboardInterrupt - except KeyboardInterrupt: - outcomes.put("interrupted") - except BaseException as error: - outcomes.put(f"error:{type(error).__name__}:{error}") - else: - outcomes.put("ok") - - -def _reference(*, workload: Workload, accuracy: Accuracy = Accuracy.LC) -> object: - return next( - cell - for cell in REPORT_CATALOG.reference_cells() - if cell.workload is workload and cell.measurement.accuracy is accuracy - ) - - -def _instrumentation(artifact: Path) -> InstrumentationRecord: - evidence = artifact / "legacy-structural-evidence" - direct = evidence / "instrumented-amplicol_color_probe.f03" - library = evidence / "instrumented-amplicol_color_library_probe.f03" - direct.parent.mkdir(parents=True, exist_ok=True) - direct.write_text("direct diagnostic source\n") - library.write_text("library diagnostic source\n") - return InstrumentationRecord( - abi="pyamplicol-legacy-probe-structural-diagnostics-v1", - sources=( - { - "path": "amplicol_color_probe.f03", - "original_sha256": "1" * 64, - "instrumented_sha256": "2" * 64, - "instrumented_evidence_path": direct.relative_to( - artifact - ).as_posix(), - }, - { - "path": "amplicol_color_library_probe.f03", - "original_sha256": "3" * 64, - "instrumented_sha256": "4" * 64, - "instrumented_evidence_path": library.relative_to( - artifact - ).as_posix(), - }, - ), - evidence_paths=(direct, library), - ) - - -def _base_artifact(root: Path) -> None: - root.mkdir(parents=True) - (root / "processes.txt").write_text("process\n") - (root / "legacy.log").write_text("legacy commands\n") - - -def _assert_evidence_inventory(artifact: Path, proof: dict[str, object]) -> None: - evidence = proof["evidence_files"] - assert isinstance(evidence, list) - assert evidence - for record in evidence: - assert isinstance(record, dict) - path = artifact / str(record["path"]) - assert path.is_file() - assert hashlib.sha256(path.read_bytes()).hexdigest() == record["sha256"] - - -def test_generated_module_preserves_exact_object_maps(tmp_path: Path) -> None: - path = tmp_path / "amp1_1_lib.f03" - path.write_text(_MODULE) - module = _parse_module(path) - assert module.source_current_ids == (1, 2) - assert module.produced_current_ids == (3,) - assert module.kernel_term_ids == (1, 2) - assert module.combine_routes == ((3, (1, 2)),) - assert module.amplitude_destinations == ((1, 3, 1),) - assert module.counts == { - "source_current_count": 2, - "produced_current_count": 1, - "kernel_evaluation_count": 2, - "attachment_count": 2, - "amplitude_destination_count": 1, - } - - -def test_direct_probe_requires_dense_maps_and_exact_accuracy( - tmp_path: Path, -) -> None: - path = tmp_path / "direct.stdout" - path.write_text(_DIRECT_OUTPUT) - structure = _parse_direct(path, "lc") - assert structure.counts == { - "source_current_count": 2, - "produced_current_count": 1, - "kernel_evaluation_count": 2, - "attachment_count": 2, - "amplitude_destination_count": 1, - } - with pytest.raises(LegacyStructuralProofError, match="expected full"): - _parse_direct(path, "full") - - -def test_probe_instrumentation_has_real_histogram_emitter() -> None: - patched_direct = _instrument_direct_source(_DIRECT_SOURCE) - patched_library = _instrument_library_source(_LIBRARY_SOURCE) - assert "AMPICOL_STRUCTURAL_ATTACHMENT" in patched_direct - assert "AMPICOL_STRUCTURAL_DESTINATION" in patched_direct - assert "AMPICOL_COLOR_PROBE_LIBRARY_CALLS" in patched_library - assert ( - "write (99,'(a,3(1x,i0))') 'AMPICOL_COLOR_PROBE_LIBRARY_CALLS'" - in patched_library - ) - assert "AMPICOL_COLOR_PROBE_LIBRARY_ROW" in patched_library - - -def test_probe_instrumentation_serializes_processes_and_restores_after_interrupt( - tmp_path: Path, -) -> None: - repository = tmp_path / "legacy" - repository.mkdir() - direct = repository / "amplicol_color_probe.f03" - library = repository / "amplicol_color_library_probe.f03" - direct.write_text(_DIRECT_SOURCE, encoding="utf-8") - library.write_text(_LIBRARY_SOURCE, encoding="utf-8") - unrelated_repository = tmp_path / "unrelated-legacy" - unrelated_repository.mkdir() - (unrelated_repository / direct.name).write_text(_DIRECT_SOURCE, encoding="utf-8") - (unrelated_repository / library.name).write_text(_LIBRARY_SOURCE, encoding="utf-8") - - context = multiprocessing.get_context("fork") - first_entered = context.Event() - release_first = context.Event() - second_entered = context.Event() - unrelated_entered = context.Event() - outcomes = context.Queue() - first = context.Process( - target=_instrument_probe_sources_in_process, - args=( - str(repository), - str(tmp_path / "first-artifact"), - first_entered, - release_first, - outcomes, - ), - kwargs={"interrupt": True}, - ) - second = context.Process( - target=_instrument_probe_sources_in_process, - args=( - str(repository), - str(tmp_path / "second-artifact"), - second_entered, - None, - outcomes, - ), - kwargs={"interrupt": False}, - ) - unrelated = context.Process( - target=_instrument_probe_sources_in_process, - args=( - str(unrelated_repository), - str(tmp_path / "unrelated-artifact"), - unrelated_entered, - None, - outcomes, - ), - kwargs={"interrupt": False}, - ) - - first.start() - assert first_entered.wait(timeout=3) - unrelated.start() - assert unrelated_entered.wait(timeout=3) - unrelated.join(timeout=3) - assert unrelated.exitcode == 0 - second.start() - assert not second_entered.wait(timeout=0.2) - assert second.is_alive() - release_first.set() - assert second_entered.wait(timeout=3) - first.join(timeout=3) - second.join(timeout=3) - - assert first.exitcode == 0 - assert second.exitcode == 0 - assert sorted(outcomes.get(timeout=1) for _ in range(3)) == [ - "interrupted", - "ok", - "ok", - ] - assert direct.read_text(encoding="utf-8") == _DIRECT_SOURCE - assert library.read_text(encoding="utf-8") == _LIBRARY_SOURCE - assert ( - tmp_path - / "first-artifact" - / "legacy-structural-evidence" - / "instrumented-amplicol_color_probe.f03" - ).is_file() - assert ( - tmp_path - / "second-artifact" - / "legacy-structural-evidence" - / "instrumented-amplicol_color_probe.f03" - ).is_file() - - -def test_selected_flow_sidecar_is_atomic_and_producer_compatible( - tmp_path: Path, -) -> None: - cell = _reference(workload=Workload.SELECTED_FLOW) - artifact = tmp_path / "artifact" - _base_artifact(artifact) - generated = artifact / "selected-flow-generated-library" - library = generated / "Library" - library.mkdir(parents=True) - (library / "amp1_1_lib.f03").write_text(_MODULE) - benchmark = generated / "amplicol_library_benchmark" - benchmark.write_bytes(b"benchmark") - repository = tmp_path / "legacy" - repository.mkdir() - proof_path = emit_legacy_structural_proof( - cell, - artifact_path=artifact, - process_row="group:1:integral:1", - source_revision="a" * 40, - repository=repository, - instrumentation=_instrumentation(artifact), - ) - proof = json.loads(proof_path.read_text()) - assert proof["schema"] == LEGACY_PROOF_SCHEMA - assert proof["scope"] == "available" - assert proof["active"]["source_current_count"] == 2 - assert proof["static"] == proof["active"] - assert proof["object_mapping"]["status"] == "exact" - assert proof["row_multiplicity"]["call_count"] == 1 - _assert_evidence_inventory(artifact, proof) - assert {item["path"] for item in proof["evidence_files"]} >= { - "processes.txt", - "legacy.log", - "selected-flow-generated-library/Library/amp1_1_lib.f03", - "legacy-structural-evidence/legacy-structural-index.json", - "legacy-structural-evidence/source-contract.json", - } - assert not list(artifact.glob(".legacy-structural-proof.json.*")) - - -def test_direct_sidecar_separates_accuracy_and_maps(tmp_path: Path) -> None: - cell = _reference(workload=Workload.ALL_FLOW) - artifact = tmp_path / "artifact" - _base_artifact(artifact) - evidence = artifact / "legacy-structural-evidence" - evidence.mkdir(parents=True) - (evidence / "direct-structural-probe.stdout").write_text(_DIRECT_OUTPUT) - repository = tmp_path / "legacy" - repository.mkdir() - (repository / "amplicol_color_probe").write_bytes(b"probe") - proof_path = emit_legacy_structural_proof( - cell, - artifact_path=artifact, - process_row="group:1:integral:1", - source_revision="b" * 40, - repository=repository, - instrumentation=_instrumentation(artifact), - ) - proof = json.loads(proof_path.read_text()) - assert proof["accuracy"] == "lc" - assert proof["workload"] == Workload.ALL_FLOW.value - assert proof["active"]["kernel_evaluation_count"] == 2 - assert proof["object_mapping"]["combine_route_map_sha256"] - assert proof["object_mapping"]["amplitude_destination_map_sha256"] - _assert_evidence_inventory(artifact, proof) - - -def test_scope_unavailable_has_exact_reason_without_fake_counts( - tmp_path: Path, -) -> None: - cell = next( - cell - for cell in REPORT_CATALOG.reference_cells() - if not REPORT_CATALOG.legacy_reference_available(cell) - ) - path = emit_legacy_scope_unavailable_proof( - cell, - artifact_path=tmp_path, - source_revision="c" * 40, - maximum_open_quark_lines=3, - observed_open_quark_lines=4, - ) - proof = json.loads(path.read_text()) - assert proof["scope"] == "unavailable" - assert proof["reason"] == LEGACY_SCOPE_REASON - assert "active" not in proof - assert "static" not in proof - assert proof["evidence_files"][0]["sha256"] - _assert_evidence_inventory(tmp_path, proof) diff --git a/pyamplicol/tests/unit/test_manual_campaign_audit_polish.py b/pyamplicol/tests/unit/test_manual_campaign_audit_polish.py deleted file mode 100644 index b779857288..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_audit_polish.py +++ /dev/null @@ -1,412 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from pathlib import Path - -import pytest -from colorama import Fore - -import tools.performance_report.manual_campaign as manual_campaign -from pyamplicol.cli import parse_cli -from tools.performance_report.arena_profile import PAIRED_TIMING_SAMPLE_CONTRACT -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.manual_campaign import ( - LightweightCurrent, - ManualCampaignError, - Palette, - build_parser, - reproduction_recipe, - selection_from_arguments, -) -from tools.performance_report.models import ExecutionMode, ModelKey, ResultStatus -from tools.performance_report.timing import ( - MEASURED_EXECUTION_TIMING_ABI, - RECURRENCE_EXECUTION_TIMING_SOURCE, -) - -ROOT = Path(__file__).resolve().parents[2] -CAMPAIGN_ARTIFACT_ROOT = ( - ROOT / "src/pyamplicol/_profiling_campaign/campaign_artifacts" -) - - -def _parse(*arguments: str): - return build_parser().parse_args(arguments) - - -def test_selective_retry_flags_parse_as_a_union_and_request_fresh_attempts() -> None: - arguments = _parse("run", "--rerun-failed", "--rerun-capped") - - assert arguments.rerun_failed - assert arguments.rerun_capped - assert manual_campaign._selective_retry_requested(arguments) - assert manual_campaign._fresh_attempt_requested(arguments) - - -def test_selective_retry_classification_is_structured_and_fail_closed( - tmp_path: Path, -) -> None: - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if manual_campaign._manual_static_na_reason(cell) is None - )[:6] - - def current( - index: int, - *, - status: ResultStatus, - generation_limit: bool = False, - incomplete_worker_timeout: bool = False, - ) -> LightweightCurrent: - result = ( - {"status": ResultStatus.OK.value} - if status is ResultStatus.OK - else manual_campaign.failure_measurement(status, "terminal fixture") - ) - if generation_limit: - result["provenance"] = { - "manual_campaign": {"generation_limit_seconds": 3600.0} - } - if incomplete_worker_timeout: - result["provenance"] = { - "policy_censor": {"kind": "worker_timeout"} - } - return LightweightCurrent( - cell_id=cells[index].cell_id, - attempt_id=f"00000000-0000-4000-8000-00000000000{index}", - result_path=tmp_path / f"result-{index}.json", - result=result, - complete=True, - reusable=True, - reason="terminal fixture", - ) - - def outcome( - index: int, - status: str, - *, - attempt_id: str | None = None, - ) -> manual_campaign.LightweightPresentationOutcome: - return manual_campaign.LightweightPresentationOutcome( - profile="macbook_M3_manual", - cell_id=cells[index].cell_id, - source_revision="a" * 40, - campaign_invocation_id=f"invocation-{index}", - attempt_id=attempt_id, - status=status, - label=status, - completed_at_ns=index + 1, - ) - - ok = current(0, status=ResultStatus.OK) - failed = outcome(1, ResultStatus.FAILED.value) - unverified = outcome(2, ResultStatus.UNVERIFIED.value) - capped = current(3, status=ResultStatus.TIMEOUT, generation_limit=True) - authenticated_cap = outcome( - 3, - "generation_limit", - attempt_id=capped.attempt_id, - ) - incomplete_cap = current( - 4, - status=ResultStatus.TIMEOUT, - incomplete_worker_timeout=True, - ) - incomplete_cap_outcome = outcome( - 4, - "worker_timeout", - attempt_id=incomplete_cap.attempt_id, - ) - unauthenticated_cap_slug = outcome( - 5, - "generation_limit", - attempt_id="00000000-0000-4000-8000-000000000099", - ) - - assert manual_campaign._selective_retry_category(ok, None) is None - assert manual_campaign._selective_retry_category(None, failed) == "failed" - assert manual_campaign._selective_retry_category(None, unverified) == "failed" - assert ( - manual_campaign._selective_retry_category(capped, authenticated_cap) - == "capped" - ) - assert ( - manual_campaign._selective_retry_category( - incomplete_cap, - incomplete_cap_outcome, - ) - == "failed" - ) - assert ( - manual_campaign._selective_retry_category(None, unauthenticated_cap_slug) - == "failed" - ) - assert manual_campaign._selective_retry_category(None, None) is None - - selected = manual_campaign._selective_retry_cells( - cells, - { - ok.cell_id: ok, - capped.cell_id: capped, - incomplete_cap.cell_id: incomplete_cap, - }, - { - failed.cell_id: failed, - unverified.cell_id: unverified, - authenticated_cap.cell_id: authenticated_cap, - incomplete_cap_outcome.cell_id: incomplete_cap_outcome, - unauthenticated_cap_slug.cell_id: unauthenticated_cap_slug, - }, - rerun_failed=True, - rerun_capped=True, - ) - assert tuple(cell.cell_id for cell in selected) == tuple( - cell.cell_id for cell in cells[1:] - ) - - -def test_empty_selector_intersection_shows_canonical_values_and_suggestions() -> None: - arguments = _parse( - "inspect", - "--table", - "scalar_gravity", - "--generation-engine", - "recurrence", - ) - with pytest.raises(ManualCampaignError) as captured: - selection_from_arguments(arguments) - - message = str(captured.value) - assert "contains no catalog entries" in message - assert "Try removing one of --table, --generation-engine" in message - assert "canonical values / useful aliases" in message - assert "scalar_gravity" in message - assert "amplicol, recurrence, compiled, eager" in message - assert "wildcard `*`/`all`" in message - - -@pytest.mark.parametrize( - "arguments", - ( - ("run", "--generation-time-limit", "nan"), - ("run", "--worker-wall-limit", "inf"), - ("run", "--resource-sample-interval", "-inf"), - ("run", "--termination-grace", "nan"), - ("run", "--target-measurement-duration", "inf"), - ("refresh-pdf", "--pdf-timeout", "nan"), - ("dashboard-snapshot", "--stale-after", "inf"), - ), -) -def test_float_options_reject_non_finite_values(arguments: tuple[str, ...]) -> None: - with pytest.raises(SystemExit) as captured: - _parse(*arguments) - assert captured.value.code == 2 - - -def test_generation_recipe_spells_out_measurement_relevant_hyperparameters() -> None: - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - and cell.measurement.backend == "jit" - and REPORT_CATALOG.static_na_reason(cell) is None - ) - recipe = reproduction_recipe( - candidate, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - cores=2, - target_runtime=0.75, - batch_size=32, - warmups=3, - minimum_samples=7, - ) - assert recipe.generate is not None - generate = recipe.generate - expected_pairs = { - "--validation-samples": "1", - "--validation-seed": "12345", - "--relative-tolerance": "1e-12", - "--absolute-tolerance": "1e-300", - "--output-chunk-size": "512", - "--horner-iterations": "10", - "--cpe-iterations": "none", - "--max-horner-variables": "1000", - "--max-common-pair-cache-entries": "5000000", - "--max-common-pair-distance": "1000", - "--cpp-optimization": "O3", - "--cores": "2", - "--batch-size": "32", - } - for option, expected in expected_pairs.items(): - assert generate[generate.index(option) + 1] == expected - assert "--model-cache" in generate - assert "--model-cache-dir" in generate - assert "--numerical-current-reuse" in generate - assert "--no-post-build-validation" in generate - generate_index = generate.index("generate") - assert parse_cli(generate[generate_index:]).resolve().effective.action == "generate" - - assert recipe.profile is not None - profile = recipe.profile - for option, expected in ( - ("--target-runtime", "0.75"), - ("--batch-size", "32"), - ("--warmup-runs", "3"), - ("--minimum-samples", "7"), - ("--precision", "16"), - ): - assert profile[profile.index(option) + 1] == expected - profile_index = profile.index("profile") - assert parse_cli(profile[profile_index:]).resolve().effective.action == "benchmark" - - -def test_dry_run_recipe_blocks_cover_more_than_twenty_direct_cells() -> None: - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - and REPORT_CATALOG.static_na_reason(cell) is None - )[:21] - blocks = tuple( - manual_campaign._dry_run_recipe_blocks( - cells, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - arguments=_parse("run", "--dry-run"), - width=120, - ) - ) - assert len(blocks) == 21 - assert all(f"| recipe | {index}" in block for index, block in enumerate(blocks, 1)) - - -def test_evaluator_total_has_independent_statistics_and_semantic_colors() -> None: - candidate = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n1-dd-z-jets-contracted" - ) - baseline = manual_campaign._manual_baseline(candidate) - assert baseline is not None - - def current( - cell_id: str, - wall: float, - evaluator_total: float, - *, - recurrence_core: float | None = None, - ) -> LightweightCurrent: - sample_count = 5 - repetitions = 2 - batch_size = 1 - measured_points = sample_count * repetitions * batch_size - result = { - "status": ResultStatus.OK.value, - "wall_seconds_per_point": wall, - "execution_seconds_per_point": recurrence_core, - "sample_count": sample_count, - "provenance": { - "evaluator_total_timing": { - "abi": "pyamplicol-report-evaluator-total-timing-v1", - "status": "measured", - "ratio_eligible": False, - "raw_seconds_per_point": evaluator_total, - "source": "runtime.evaluate.accumulated", - "execution_mode": "recurrence", - "sample_contract": ( - "accumulated-repeated-warmed-evaluator-total-v1" - ), - "sample_count": sample_count, - "repetitions_per_sample": repetitions, - "batch_size": batch_size, - "points_per_sample": repetitions * batch_size, - "measured_point_count": measured_points, - "accumulated_seconds": evaluator_total * measured_points, - } - }, - } - if recurrence_core is not None: - result["provenance"]["execution_timing"] = { - "abi": MEASURED_EXECUTION_TIMING_ABI, - "status": "measured", - "ratio_eligible": True, - "raw_seconds_per_point": recurrence_core, - "source": RECURRENCE_EXECUTION_TIMING_SOURCE, - "compiled_direct_arena_active": False, - "sample_count": sample_count, - "native_profile_points_per_sample": repetitions * batch_size, - "sample_contract": PAIRED_TIMING_SAMPLE_CONTRACT, - } - return LightweightCurrent( - cell_id=cell_id, - attempt_id=f"attempt-{cell_id}", - result_path=ROOT / "unused-result.json", - result=result, - complete=True, - reusable=True, - reason="reusable", - ) - - summary, exclusions = manual_campaign._inspect_metric( - (candidate,), - { - candidate.cell_id: current(candidate.cell_id, 2.0, 4.0), - baseline.cell_id: current(baseline.cell_id, 1.0, 2.0), - }, - field=None, - generation=False, - evaluator_total=True, - ) - assert exclusions == {} - assert summary["count"] == 1 - assert summary["median"] == pytest.approx(2.0) - assert summary["weighted_mean"] == pytest.approx(2.0) - - palette = Palette(enabled=True) - assert Fore.GREEN in manual_campaign._paint_multiplier(palette, 0.9) - assert Fore.RED in manual_campaign._paint_multiplier(palette, 1.1) - assert "\x1b[" not in manual_campaign._paint_multiplier(palette, 1.0) - - malformed = current(candidate.cell_id, 2.0, 4.0) - malformed_total = malformed.result["provenance"]["evaluator_total_timing"] - assert isinstance(malformed_total, dict) - malformed_total["accumulated_seconds"] = 99.0 - assert manual_campaign._evaluator_total_number(malformed.result) is None - - other = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.cell_id != candidate.cell_id - ) - core_summary, core_exclusions = manual_campaign._inspect_recurrence_core( - (candidate, other), - { - candidate.cell_id: current( - candidate.cell_id, - 2.0, - 4.0, - recurrence_core=4.0e-6, - ), - other.cell_id: current( - other.cell_id, - 3.0, - 6.0, - recurrence_core=2.0e-6, - ), - }, - ) - assert core_exclusions == {} - assert core_summary["count"] == 2 - assert core_summary["median_seconds_per_point"] == pytest.approx(3.0e-6) - assert core_summary["mean_seconds_per_point"] == pytest.approx(3.0e-6) - fastest = core_summary["fastest"] - slowest = core_summary["slowest"] - assert isinstance(fastest, dict) - assert isinstance(slowest, dict) - assert fastest["cell_id"] == other.cell_id - assert fastest["seconds_per_point"] == pytest.approx(2.0e-6) - assert slowest["cell_id"] == candidate.cell_id - assert slowest["seconds_per_point"] == pytest.approx(4.0e-6) - assert "multiplier" not in fastest diff --git a/pyamplicol/tests/unit/test_manual_campaign_entrypoint.py b/pyamplicol/tests/unit/test_manual_campaign_entrypoint.py deleted file mode 100644 index bb91ce85ca..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_entrypoint.py +++ /dev/null @@ -1,223 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import runpy -import sys -from collections.abc import Callable -from pathlib import Path -from typing import cast - -import pytest - -import tools.performance_report.manual_campaign as manual_campaign - -ROOT = Path(__file__).resolve().parents[2] -ENTRYPOINT = ( - ROOT / "src/pyamplicol/_profiling_campaign/steer_performance_campaign.py" -) - - -def _entrypoint_namespace() -> dict[str, object]: - return runpy.run_path( - str(ENTRYPOINT), - run_name="manual_campaign_entrypoint_test", - ) - - -def test_campaign_profile_is_derived_from_copied_directory_name() -> None: - derive = cast( - Callable[[Path, Path], str], - _entrypoint_namespace()["_embedded_profile"], - ) - copied = ( - ROOT - / "docs/performance_reports/another_macbook_campaign" - / "steer_performance_campaign.py" - ) - - assert derive(copied, ROOT) == "another_macbook_campaign" - - -def test_campaign_entrypoint_rejects_nested_non_profile_directory() -> None: - derive = cast( - Callable[[Path, Path], str], - _entrypoint_namespace()["_embedded_profile"], - ) - nested = ( - ROOT - / "docs/performance_reports/campaign/archive" - / "steer_performance_campaign.py" - ) - - with pytest.raises(RuntimeError, match="directly inside"): - derive(nested, ROOT) - - -def test_campaign_entrypoint_passes_copied_profile_to_controller( - monkeypatch: pytest.MonkeyPatch, -) -> None: - namespace = _entrypoint_namespace() - copied = ( - ROOT - / "docs/performance_reports/independent_campaign" - / "steer_performance_campaign.py" - ) - entrypoint_main = cast(Callable[[], int], namespace["main"]) - entrypoint_main.__globals__["__file__"] = str(copied) - entrypoint_main.__globals__["_reexecute_with_repository_python"] = ( - lambda _root, _entrypoint: None - ) - observed: dict[str, object] = {} - - def fake_campaign_main( - arguments: list[str], - *, - repo_root: Path, - profile: str, - docs_dir: Path, - launcher_path_checked: bool, - ) -> int: - observed.update( - arguments=arguments, - repo_root=repo_root, - profile=profile, - docs_dir=docs_dir, - launcher_path_checked=launcher_path_checked, - ) - return 17 - - monkeypatch.setattr(manual_campaign, "main", fake_campaign_main) - monkeypatch.setattr(sys, "argv", [str(copied), "inspect"]) - - assert entrypoint_main() == 17 - assert observed == { - "arguments": ["inspect"], - "repo_root": ROOT, - "profile": "independent_campaign", - "docs_dir": copied.parent, - "launcher_path_checked": True, - } - - -def test_installed_campaign_entrypoint_passes_its_directory_to_controller( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - namespace = _entrypoint_namespace() - copied = tmp_path / "independent_campaign" / "steer_performance_campaign.py" - copied.parent.mkdir() - entrypoint_main = cast(Callable[[], int], namespace["main"]) - entrypoint_main.__globals__["__file__"] = str(copied) - observed: dict[str, object] = {} - - class InstalledController: - @staticmethod - def main( - arguments: list[str], - *, - repo_root: Path, - profile: str, - docs_dir: Path, - installed: bool, - launcher_path_checked: bool, - ) -> int: - observed.update( - arguments=arguments, - repo_root=repo_root, - profile=profile, - docs_dir=docs_dir, - installed=installed, - launcher_path_checked=launcher_path_checked, - ) - return 19 - - entrypoint_main.__globals__["import_module"] = lambda _name: InstalledController - monkeypatch.setattr(sys, "argv", [str(copied), "inspect"]) - - assert entrypoint_main() == 19 - assert observed == { - "arguments": ["inspect"], - "repo_root": copied.parent, - "profile": "independent_campaign", - "docs_dir": copied.parent, - "installed": True, - "launcher_path_checked": True, - } - - -@pytest.mark.parametrize("pwd_state", ("unset", "renamed-away", "recreated")) -def test_relative_campaign_entrypoint_rejects_stale_pwd_after_move( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], - pwd_state: str, -) -> None: - namespace = _entrypoint_namespace() - original = tmp_path / "campaign" - original.mkdir() - moved = tmp_path / "renamed-campaign" - original.rename(moved) - if pwd_state == "recreated": - original.mkdir() - monkeypatch.chdir(moved) - if pwd_state == "unset": - monkeypatch.delenv("PWD", raising=False) - else: - monkeypatch.setenv("PWD", str(original)) - monkeypatch.setattr(sys, "argv", ["./steer_performance_campaign.py", "inspect"]) - entrypoint_main = cast(Callable[[], int], namespace["main"]) - entrypoint_main.__globals__["__file__"] = str( - moved / "steer_performance_campaign.py" - ) - entrypoint_main.__globals__["import_module"] = lambda _name: pytest.fail( - "stale relative launcher reached the campaign controller" - ) - - assert entrypoint_main() == 2 - assert "cd .." in capsys.readouterr().err - - -def test_source_launcher_preserves_symlinked_campaign_path_for_rejection( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - namespace = _entrypoint_namespace() - fake_repo = tmp_path / "checkout" - (fake_repo / "tools/performance_report").mkdir(parents=True) - (fake_repo / "src/pyamplicol").mkdir(parents=True) - profile_parent = fake_repo / "docs/performance_reports" - profile_parent.mkdir(parents=True) - actual = tmp_path / "actual-campaign" - actual.mkdir() - linked = profile_parent / "linked-campaign" - linked.symlink_to(actual, target_is_directory=True) - monkeypatch.chdir(actual) - monkeypatch.setenv("PWD", str(linked)) - entrypoint_main = cast(Callable[[], int], namespace["main"]) - entrypoint_main.__globals__["__file__"] = "./steer_performance_campaign.py" - entrypoint_main.__globals__["_reexecute_with_repository_python"] = ( - lambda _root, _entrypoint: None - ) - - def rejecting_campaign_main( - _arguments: list[str], - *, - repo_root: Path, - profile: str, - docs_dir: Path, - launcher_path_checked: bool, - ) -> int: - assert profile == "linked-campaign" - assert docs_dir == linked - assert launcher_path_checked is True - with pytest.raises( - manual_campaign.ManualCampaignError, - match="symbolic link", - ): - manual_campaign._campaign_report_paths(repo_root, docs_dir) - return 23 - - monkeypatch.setattr(manual_campaign, "main", rejecting_campaign_main) - monkeypatch.setattr(sys, "argv", ["./steer_performance_campaign.py", "inspect"]) - - assert entrypoint_main() == 23 diff --git a/pyamplicol/tests/unit/test_manual_campaign_interrupts.py b/pyamplicol/tests/unit/test_manual_campaign_interrupts.py deleted file mode 100644 index 35d1c43117..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_interrupts.py +++ /dev/null @@ -1,491 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import io -import json -import threading -from pathlib import Path -from types import SimpleNamespace - -import pytest - -import tools.performance_report.manual_campaign as manual_campaign -from tools.performance_report.agreements import DIRECT_AGREEMENT_FIELD -from tools.performance_report.cache import empty_measurement -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ArtifactPolicy, ResultStatus -from tools.performance_report.resources import ( - GenerationPhaseEvidence, - ResourceUsage, - SupervisedResult, -) -from tools.performance_report.scheduler import ( - CampaignScheduler, - CampaignSettings, - PlannedCell, -) -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity - - -def _service(tmp_path: Path) -> ReportService: - root = tmp_path / "repo" - (root / "docs/arxiv").mkdir(parents=True) - return ReportService( - ReportPaths.from_repo( - root, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - - -def _source() -> ReportSourceIdentity: - return ReportSourceIdentity("a" * 40, "b" * 40, ()) - - -def _cell(): - return REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - - -def _completed_measurement( - source: ReportSourceIdentity, -) -> dict[str, object]: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": {}, - "validation": { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - }, - "resources": {}, - "provenance": source.provenance(), - } - ) - return measurement - - -def _publish_completed_current( - service: ReportService, - source: ReportSourceIdentity, -): - return service.store.new_attempt( - _cell().cell_id, - ArtifactPolicy.REGENERATE, - ).publish(_completed_measurement(source)) - - -def _planned() -> PlannedCell: - return PlannedCell( - _cell(), - dependency=False, - baseline_cell_id=None, - rank=0, - ) - - -def test_queued_cancellation_creates_no_failed_attempt_and_preserves_current( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - source = _source() - current = _publish_completed_current(service, source) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - artifact_policy=ArtifactPolicy.REGENERATE, - source_identity_override=source, - cancellation_requested=lambda: True, - ), - ) - - outcome = scheduler._run_cell(_planned()) - - assert outcome.status == "cancelled" - assert outcome.detail == "not started" - assert service.store.load_current(_cell().cell_id).attempt_id == current.attempt_id - attempts = tuple( - service.store._cell_root(_cell().cell_id).joinpath("attempts").iterdir() - ) - assert tuple(path.name for path in attempts) == (current.attempt_id,) - - -@pytest.mark.parametrize( - ("phase", "final_phase"), - ( - ("generation", "generation"), - ("profiling", "post-generation"), - ), -) -def test_running_cancellation_is_interrupted_history_and_preserves_current( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - phase: str, - final_phase: str, -) -> None: - service = _service(tmp_path) - source = _source() - current = _publish_completed_current(service, source) - cancellation = threading.Event() - - def cancelled_worker( - _command: object, - **arguments: object, - ) -> SupervisedResult: - callback = arguments["cancellation_requested"] - assert callable(callback) - cancellation.set() - assert callback() - return SupervisedResult( - -15, - "cancelled", - ResourceUsage(True, 0, 0, 0, 0.0, 0.1), - GenerationPhaseEvidence( - configured_timeout_seconds=3600.0, - supervisor_reason="cancelled", - authenticated=True, - run_id=f"{phase}-run", - worker_pid=123, - final_sequence=2, - final_phase=final_phase, - generation_started_monotonic_ns=1, - generation_finished_monotonic_ns=2, - generation_elapsed_seconds=1.0, - final_state_sha256="c" * 64, - ), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - cancelled_worker, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - artifact_policy=ArtifactPolicy.REGENERATE, - source_identity_override=source, - cancellation_requested=cancellation.is_set, - generation_time_limit_seconds=3600.0, - ), - ) - - outcome = scheduler._run_cell(_planned()) - - assert outcome.status == "cancelled" - assert outcome.detail == "previous valid current preserved" - assert service.store.load_current(_cell().cell_id).attempt_id == current.attempt_id - attempt_root = service.store._cell_root(_cell().cell_id) / "attempts" - manifests = { - path.parent.name: json.loads(path.read_text(encoding="ascii")) - for path in attempt_root.glob("*/manifest.json") - } - assert manifests[current.attempt_id]["status"] == "ok" - history_root = service.store._attempt_history_cell_root(_cell().cell_id) - archived = { - path.parent.name: json.loads(path.read_text(encoding="ascii")) - for path in history_root.glob("*/manifest.json") - } - assert len(archived) == 1 - manifest = next(iter(archived.values())) - assert manifest["status"] == "interrupted" - assert manifest["result_path"] is None - assert manifest["error"] == "worker terminated by cancellation" - assert manifest["based_on"]["attempt_id"] == current.attempt_id - assert {path.parent.name for path in attempt_root.glob("*/result.json")} == { - current.attempt_id - } - - -def test_manual_legacy_cancellation_discards_isolated_attempt( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - source = _source() - cell = REPORT_CATALOG.cell("reference-amplicol-full-n1-dd-z-jets-contracted") - source_repository = tmp_path / "original-amplicol" - source_repository.mkdir() - workspaces: list[Path] = [] - - def workspace_paths( - _scheduler: CampaignScheduler, - attempt_id: str, - ) -> tuple[Path, Path]: - workspace = tmp_path / "legacy-workspaces" / attempt_id - workspaces.append(workspace) - return source_repository, workspace - - def cancelled_worker( - command: list[str], - **_arguments: object, - ) -> SupervisedResult: - source_option = command.index("--legacy-source-repository") - workspace_option = command.index("--legacy-workspace") - assert Path(command[source_option + 1]) == source_repository - assert Path(command[workspace_option + 1]) == workspaces[0] - assert "--legacy-copy-source" in command - # Workspace preparation has moved into this supervised subprocess; - # the controller must not copy or lock the source before supervision. - assert not workspaces[0].exists() - workspaces[0].mkdir(parents=True) - return SupervisedResult( - -15, - "cancelled", - ResourceUsage(True, 0, 0, 0, 0.0, 0.1), - GenerationPhaseEvidence( - configured_timeout_seconds=3600.0, - supervisor_reason="cancelled", - authenticated=True, - run_id="manual-legacy-run", - worker_pid=123, - final_sequence=1, - final_phase="generation", - generation_started_monotonic_ns=1, - generation_finished_monotonic_ns=None, - generation_elapsed_seconds=0.1, - final_state_sha256="d" * 64, - ), - ) - - monkeypatch.setattr( - CampaignScheduler, - "_legacy_workspace_paths", - workspace_paths, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - cancelled_worker, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - artifact_policy=ArtifactPolicy.REGENERATE, - source_identity_override=source, - generation_time_limit_seconds=3600.0, - manual_terminal_censors=True, - discard_cancelled_attempts=True, - ), - ) - - outcome = scheduler._run_cell( - PlannedCell( - cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - ) - - assert outcome.status == "cancelled" - assert outcome.detail == "incomplete attempt discarded" - assert len(workspaces) == 1 and not workspaces[0].exists() - assert service.store.cell_attempt_ids(cell.cell_id) == () - - -def test_closed_lease_cannot_be_recreated_by_late_worker_event( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - source = _source() - monkeypatch.setattr( - manual_campaign, - "_repo_head", - lambda _repo_root: source.revision, - ) - state = manual_campaign.DashboardState( - instance_id="interrupt-cleanup", - selected_ids=(_cell().cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision=source.revision, - ) - lease = manual_campaign.LeaseManager(service, state) - lease.publish() - assert lease.path.is_file() - - lease.close() - lease.observe( - { - "event": "started", - "cell_id": _cell().cell_id, - } - ) - lease.publish() - - assert not lease.path.exists() - - -def test_repeated_keyboard_interrupt_waits_for_cleanup_before_closing_lease( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - events: list[str] = [] - cancelled_callbacks: list[object] = [] - leases: list[object] = [] - threads: list[object] = [] - - class Tty(io.StringIO): - def isatty(self) -> bool: - return True - - class FakeLease: - def __init__(self, _service: object, _state: object) -> None: - self.closed = False - leases.append(self) - - def publish(self) -> None: - events.append("lease-published") - - def observe(self, _payload: object) -> None: - return None - - def close(self) -> None: - assert threads and not threads[0].is_alive() - self.closed = True - events.append("lease-closed") - - class FakeThread: - def __init__(self, **_arguments: object) -> None: - self.join_timeouts: list[float | None] = [] - self.alive = True - threads.append(self) - - def start(self) -> None: - events.append("worker-started") - - def join(self, timeout: float | None = None) -> None: - self.join_timeouts.append(timeout) - if len(self.join_timeouts) == 1: - events.append("join-interrupted") - raise KeyboardInterrupt - if len(self.join_timeouts) == 2: - events.append("cleanup-delayed") - if len(self.join_timeouts) == 22: - self.alive = False - events.append("cleanup-finished") - - def is_alive(self) -> bool: - return self.alive - - class FakeScheduler: - def __init__(self, _service: object, *, settings: object) -> None: - del settings - - def run(self, _planned: object) -> None: - raise AssertionError("fake controller thread must not execute") - - def settings( - _arguments: object, - _source: object, - *, - original_amplicol_available: bool = False, - observer: object = None, - cancelled: object = None, - campaign_invocation_id: str | None = None, - ) -> object: - del observer, original_amplicol_available - if cancelled is not None: - assert campaign_invocation_id - cancelled_callbacks.append(cancelled) - return SimpleNamespace(effective_cell_rss_limit=lambda: 30_000_000_000) - - def dashboard(*_arguments: object, **_keywords: object) -> None: - del _keywords - try: - raise KeyboardInterrupt - finally: - events.append("terminal-restored") - - monkeypatch.setattr(manual_campaign, "lightweight_currents", lambda *_a, **_k: {}) - monkeypatch.setattr( - manual_campaign, - "plan_campaign", - lambda *_a, **_k: (_planned(),), - ) - monkeypatch.setattr(manual_campaign, "require_measurement_ready", lambda _s: None) - monkeypatch.setattr(manual_campaign, "update_source_marker", lambda *_a: False) - monkeypatch.setattr( - manual_campaign, - "_bind_original_amplicol_if_required", - lambda *_a, **_k: None, - ) - monkeypatch.setattr( - manual_campaign, - "reconcile_attempt_history", - lambda *_a, **_k: (), - ) - monkeypatch.setattr( - manual_campaign, - "_publish_campaign_summary_ids", - lambda *_a, **_k: (tmp_path / "campaign_summary_ids", {}), - ) - monkeypatch.setattr(manual_campaign, "_campaign_settings", settings) - monkeypatch.setattr(manual_campaign, "CampaignScheduler", FakeScheduler) - monkeypatch.setattr(manual_campaign, "LeaseManager", FakeLease) - monkeypatch.setattr(manual_campaign.threading, "Thread", FakeThread) - monkeypatch.setattr(manual_campaign, "_run_live_dashboard", dashboard) - monkeypatch.setattr(manual_campaign.sys, "stdin", Tty()) - monkeypatch.setattr(manual_campaign.sys, "stdout", Tty()) - stderr = Tty() - monkeypatch.setattr(manual_campaign.sys, "stderr", stderr) - arguments = SimpleNamespace( - force_refresh=False, - dry_run=False, - no_dashboard=False, - generation_time_limit=3600.0, - ram_limit=30_000_000_000, - worker_wall_limit=None, - cores_per_worker=1, - target_measurement_duration=0.1, - batch_size=1, - warmups=0, - minimum_samples=5, - termination_grace=0.01, - cleanup_artifacts=False, - original_amplicol=None, - madgraph=None, - ) - service = SimpleNamespace( - store=object(), - paths=SimpleNamespace(docs_dir=tmp_path, artifact_root=tmp_path / "artifacts"), - catalog=REPORT_CATALOG, - ) - - result = manual_campaign._run_campaign( - arguments, - repo_root=tmp_path, - service=service, - source=_source(), - cells=(_cell(),), - palette=manual_campaign.Palette(False), - ) - - assert result == 130 - assert len(cancelled_callbacks) == 1 - callback = cancelled_callbacks[0] - assert callable(callback) and callback() - assert len(threads) == 1 - thread = threads[0] - assert thread.join_timeouts == [0.25] * 22 - assert len(leases) == 1 and leases[0].closed - assert events == [ - "lease-published", - "worker-started", - "terminal-restored", - "join-interrupted", - "cleanup-delayed", - "cleanup-finished", - "lease-closed", - ] - assert "still waiting for supervised worker-tree cleanup" in stderr.getvalue() - assert "no leases or claims will be released early" in stderr.getvalue() diff --git a/pyamplicol/tests/unit/test_manual_campaign_lightweight_reuse.py b/pyamplicol/tests/unit/test_manual_campaign_lightweight_reuse.py deleted file mode 100644 index 48760d0134..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_lightweight_reuse.py +++ /dev/null @@ -1,1718 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import builtins -import hashlib -import json -import os -import struct -import subprocess -import uuid -import zlib -from collections.abc import Mapping -from pathlib import Path - -import pytest - -from tools.performance_report import manual_campaign -from tools.performance_report.agreements import DIRECT_AGREEMENT_FIELD -from tools.performance_report.artifacts import ( - ATTEMPT_SCHEMA, - CURRENT_SCHEMA, - ArtifactStore, - ManifestValidationError, -) -from tools.performance_report.cache import digest_json, empty_measurement -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.manual_campaign import ( - Palette, - _index_metadata_dirty_paths, - _run_campaign, - build_parser, - lightweight_current, -) -from tools.performance_report.measurement import failure_measurement, load_measurement -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ResultStatus, - Workload, -) -from tools.performance_report.runner import pointwise_validation -from tools.performance_report.scheduler import CampaignSettings, plan_campaign -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity -from tools.performance_report.worker import _portable_current_paths - -ROOT = Path(__file__).resolve().parents[2] - - -def _recurrence_validation(cell: CellSpec) -> dict[str, object]: - point_digest = "a" * 64 - ordering = "b" * 64 - - def resolved(precision: int, source: str) -> dict[str, object]: - point = pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": point_digest, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "point_index": 0, - }, - ) - return { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": ResultStatus.OK.value, - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": point_digest, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "scale_source": "resolved-component-l1", - "precision_digits": precision, - "points": [point], - } - - binary64 = resolved(16, "c" * 64) - precision32 = resolved(32, "d" * 64) - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": None, - "value_kind": "matrix-element-p16-versus-p32", - } - return { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - "resolved_sum": binary64, - "high_precision_resolved_sum": precision32, - "high_precision": pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - candidate_scale_source="resolved-component-l1-binary64", - baseline_scale_source="resolved-component-l1-p32", - comparison_binding={ - "point_digest": point_digest, - "selector_component_identity": selector_identity, - "selector_component_sha256": digest_json(selector_identity), - "candidate_source_sha256": "c" * 64, - "baseline_source_sha256": "d" * 64, - }, - ), - } - - -def _cell_identity(cell: CellSpec) -> dict[str, object]: - return { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "workload": cell.workload.value, - "execution_mode": cell.measurement.execution_mode.value, - "model": ( - None if cell.measurement.model is None else cell.measurement.model.value - ), - "accuracy": cell.measurement.accuracy.value, - "backend": cell.measurement.backend, - "variant": cell.variant, - } - - -def _amplicol_leaf_cell() -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.workload is Workload.SELECTED_FLOW - and cell.n_final == 1 - ) - - -def _amplicol_contracted_cell() -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.measurement.accuracy is Accuracy.NLC - and cell.workload is Workload.CONTRACTED - and cell.n_final == 1 - ) - - -def _pyamplicol_leaf_cell() -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.n_final == 1 - ) - - -def _write_lightweight_terminal_current( - service: ReportService, - cell: CellSpec, - *, - revision: str, - extra_provenance: Mapping[str, object] | None = None, -) -> tuple[Path, Path]: - attempt_id = str(uuid.uuid4()) - attempt_root = service.store._cell_root(cell.cell_id) / "attempts" / attempt_id - attempt_root.mkdir(parents=True) - result = failure_measurement(ResultStatus.TIMEOUT, "generation cap") - result["provenance"] = { - "report_source_revision": revision, - "manual_campaign": {"cell_identity": _cell_identity(cell)}, - **({} if extra_provenance is None else dict(extra_provenance)), - } - result_path = attempt_root / "result.json" - result_path.write_text(json.dumps(result), encoding="utf-8") - manifest = { - "schema": ATTEMPT_SCHEMA, - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - "status": "ok", - "artifact_policy": ArtifactPolicy.REUSE.value, - "based_on": None, - "result_path": "result.json", - "artifacts": [ - { - "path": "result.json", - "size": result_path.stat().st_size, - "sha256": "0" * 64, - } - ], - "error": None, - } - manifest_path = attempt_root / "manifest.json" - manifest_path.write_text(json.dumps(manifest), encoding="utf-8") - pointer = { - "schema": CURRENT_SCHEMA, - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - "manifest_path": f"attempts/{attempt_id}/manifest.json", - "manifest_sha256": "1" * 64, - } - pointer_path = service.store._cell_root(cell.cell_id) / "current.json" - pointer_path.write_text(json.dumps(pointer), encoding="utf-8") - return manifest_path, result_path - - -def _write_lightweight_success_current( - service: ReportService, - cell: CellSpec, - *, - revision: str, - numerical_relation_correctness: Mapping[str, object], -) -> tuple[Path, Path]: - attempt_id = str(uuid.uuid4()) - attempt_root = service.store._cell_root(cell.cell_id) / "attempts" / attempt_id - artifact_root = attempt_root / "artifact" - artifact_root.mkdir(parents=True) - (artifact_root / "artifact.json").write_text("{}\n", encoding="ascii") - result = empty_measurement() - result.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": { - "path": str(artifact_root), - "process_id": cell.process, - }, - "validation": ( - _recurrence_validation(cell) - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.accuracy is not Accuracy.LC - else { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - } - ), - "resources": {}, - "provenance": { - "report_source_revision": revision, - "manual_campaign": {"cell_identity": _cell_identity(cell)}, - "numerical_relation_correctness": dict(numerical_relation_correctness), - }, - } - ) - result_path = attempt_root / "result.json" - result_path.write_text(json.dumps(result), encoding="utf-8") - manifest = { - "schema": ATTEMPT_SCHEMA, - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - "status": "ok", - "artifact_policy": ArtifactPolicy.REUSE.value, - "based_on": None, - "result_path": "result.json", - "artifacts": [ - { - "path": "result.json", - "size": result_path.stat().st_size, - "sha256": "0" * 64, - } - ], - "error": None, - } - manifest_path = attempt_root / "manifest.json" - manifest_path.write_text(json.dumps(manifest), encoding="utf-8") - pointer = { - "schema": CURRENT_SCHEMA, - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - "manifest_path": f"attempts/{attempt_id}/manifest.json", - "manifest_sha256": "1" * 64, - } - pointer_path = service.store._cell_root(cell.cell_id) / "current.json" - pointer_path.write_text(json.dumps(pointer), encoding="utf-8") - return manifest_path, result_path - - -def _portable_manual_service(campaign: Path) -> ReportService: - campaign = campaign.expanduser().resolve(strict=False) - state = campaign / "campaign_artifacts" - paths = ReportPaths( - repo_root=ROOT, - docs_dir=campaign, - results_dir=campaign / "results", - artifact_root=state, - coordination_root=state / "coordination", - ) - return ReportService(paths, portable_current_results=True) - - -def _isolated_manual_service(root: Path) -> ReportService: - return ReportService( - ReportPaths( - repo_root=ROOT, - docs_dir=root / "docs", - results_dir=root / "results", - artifact_root=root / "artifacts", - coordination_root=root / "coordination", - ) - ) - - -def _presentation_outcome( - cell: CellSpec, - *, - revision: str, - status: str = ResultStatus.FAILED.value, -) -> manual_campaign.LightweightPresentationOutcome: - return manual_campaign.LightweightPresentationOutcome( - profile="macbook_M3_manual", - cell_id=cell.cell_id, - source_revision=revision, - campaign_invocation_id="selective-retry-fixture", - attempt_id=None, - status=status, - label=status, - completed_at_ns=1, - ) - - -def _publish_success_current( - service: ReportService, - cell: CellSpec, - *, - revision: str, -) -> None: - attempt = service.store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE) - artifact = attempt.path("artifact") - artifact.mkdir() - (artifact / "artifact.json").write_text("{}\n", encoding="ascii") - result = empty_measurement() - result.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": {"path": str(artifact), "process_id": cell.process}, - "validation": ( - _recurrence_validation(cell) - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.accuracy is not Accuracy.LC - else { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - } - ), - "resources": {}, - "provenance": { - "report_source_revision": revision, - "manual_campaign": { - "cell_identity": _cell_identity(cell), - "public_cli_reproduction": manual_campaign.reproduction_recipe( - cell, - repo_root=service.paths.repo_root, - artifact_root=service.paths.artifact_root, - ).as_dict(), - }, - "numerical_relation_correctness": {}, - }, - } - ) - attempt.publish(result, artifact_paths=("artifact/artifact.json",)) - - -def test_manual_current_reuse_survives_whole_campaign_move( - tmp_path: Path, -) -> None: - revision = "b" * 40 - recurrence = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.cell_id - == "matrix-recurrence-builtin-sm-full-n1-dd-z-jets-contracted" - ) - compiled = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.cell_id - == "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted" - ) - campaign_a = tmp_path / "parent-a" / "campaign-a" - service_a = _portable_manual_service(campaign_a) - _publish_success_current(service_a, recurrence, revision=revision) - - campaign_b = tmp_path / "other-parent" / "renamed-campaign" - campaign_b.parent.mkdir() - campaign_a.rename(campaign_b) - service_b = _portable_manual_service(campaign_b) - state_b = campaign_b / "campaign_artifacts" - - full = service_b.store.load_current(recurrence.cell_id) - lightweight = lightweight_current( - service_b.store, - recurrence, - source_revision=revision, - ) - assert full is not None - assert lightweight is not None and lightweight.reusable - assert Path(str(full.result["artifact"]["path"])).is_relative_to(state_b) - assert Path(str(lightweight.result["artifact"]["path"])).is_relative_to(state_b) - portable_recipe = lightweight.result["provenance"]["manual_campaign"][ - "public_cli_reproduction" - ] - assert isinstance(portable_recipe["generate"], list) - assert any(str(state_b) in argument for argument in portable_recipe["generate"]) - assert str(campaign_a) not in json.dumps(portable_recipe, sort_keys=True) - - resolver = manual_campaign._lightweight_current_resolver( - service_b, - source_revision=revision, - initial={recurrence.cell_id: lightweight}, - ) - resolved = resolver(recurrence) - assert resolved is not None - assert Path(str(resolved[0].result["artifact"]["path"])).is_relative_to(state_b) - planned = plan_campaign( - (compiled,), - store=service_b.store, - settings=CampaignSettings(), - expected_revision=revision, - current_resolver=resolver, - ) - assert [item.cell.cell_id for item in planned] == [compiled.cell_id] - assert planned[0].baseline_cell_id is None - assert planned[0].optional_baseline_cell_id == recurrence.cell_id - - worker_attempt = service_b.store.new_attempt( - compiled.cell_id, - ArtifactPolicy.REGENERATE, - ) - worker_paths = _portable_current_paths( - repo_root=ROOT, - attempt_root=worker_attempt.root, - ) - assert worker_paths is not None - worker_loaded = load_measurement( - full.result_path, - publication_paths=worker_paths, - ) - assert Path(str(worker_loaded["artifact"]["path"])).is_relative_to(state_b) - worker_attempt.discard() - - inspect_payload = manual_campaign._inspect_payload( - service_b, - (recurrence,), - source_revision=revision, - renderer_revision=revision, - ) - assert inspect_payload["reusable_count"] == 1 - assert inspect_payload["statuses"] == {ResultStatus.OK.value: 1} - assert str(campaign_a) not in json.dumps(inspect_payload, sort_keys=True) - - merged_payloads, merged_count = manual_campaign._merge_lightweight_snapshot( - service_b, - {recurrence.cell_id: lightweight}, - ) - assert merged_count == 1 - merged_measurement = next( - entry["measurement"] - for payload in merged_payloads.values() - for entry in payload["entries"] - if entry["cell_id"] == recurrence.cell_id - ) - assert Path(str(merged_measurement["artifact"]["path"])).is_relative_to(state_b) - assert str(campaign_a) not in json.dumps(merged_measurement, sort_keys=True) - - recipe = manual_campaign.reproduction_recipe( - recurrence, - repo_root=ROOT, - artifact_root=state_b, - measurement=lightweight.result, - ) - reproduction_root = state_b / "manual-reproductions" / recurrence.cell_id - recipe_commands = tuple( - command - for command in (recipe.prepare, recipe.generate, recipe.profile) - if command is not None - ) - rendered_recipe = "\n".join(" ".join(command) for command in recipe_commands) - assert str(reproduction_root) in rendered_recipe - assert str(campaign_b / ".artifacts") not in rendered_recipe - assert str(campaign_a) not in rendered_recipe - - recycled_workers = manual_campaign._recycled_attention_workers( - (recurrence,), - {recurrence.cell_id: lightweight}, - {recurrence.cell_id}, - repo_root=ROOT, - artifact_root=state_b, - settings=manual_campaign.ReproductionSettings(), - ) - recycled = recycled_workers[recurrence.cell_id] - assert recycled.status == "recycled" - assert recycled.recycled - rendered_worker_commands = "\n".join( - command - for command in ( - recycled.reproduce_prepare, - recycled.reproduce_generate, - recycled.reproduce_profile, - ) - if command is not None - ) - assert str(reproduction_root) in rendered_worker_commands - assert str(campaign_b / ".artifacts") not in rendered_worker_commands - assert str(campaign_a) not in rendered_worker_commands - - -def test_manual_portable_reuse_rejects_old_absolute_current( - tmp_path: Path, -) -> None: - revision = "b" * 40 - cell = _pyamplicol_leaf_cell() - campaign = tmp_path / "manual" - state = campaign / "campaign_artifacts" - ordinary = ReportService( - ReportPaths( - repo_root=ROOT, - docs_dir=campaign, - results_dir=campaign / "results", - artifact_root=state, - coordination_root=state / "coordination", - ) - ) - _publish_success_current(ordinary, cell, revision=revision) - portable = _portable_manual_service(campaign) - - with pytest.raises(ManifestValidationError, match="current pointer schema"): - portable.store.load_current(cell.cell_id) - lightweight = lightweight_current( - portable.store, - cell, - source_revision=revision, - ) - assert lightweight is None - - -def _git_object(git_dir: Path, kind: bytes, body: bytes) -> str: - payload = kind + b" " + str(len(body)).encode("ascii") + b"\0" + body - digest = hashlib.sha1(payload, usedforsecurity=False).hexdigest() - path = git_dir / "objects" / digest[:2] / digest[2:] - path.parent.mkdir(parents=True, exist_ok=True) - path.write_bytes(zlib.compress(payload)) - return digest - - -def _git(repo: Path, *arguments: str) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=repo, - check=True, - capture_output=True, - text=True, - ) - return completed.stdout.strip() - - -def _write_index(repo: Path, relative: str, object_id: str) -> None: - path = repo / relative - observed = path.stat() - encoded = os.fsencode(relative) - fields = struct.pack( - "!10I20sH", - int(observed.st_ctime_ns // 1_000_000_000), - int(observed.st_ctime_ns % 1_000_000_000), - int(observed.st_mtime_ns // 1_000_000_000), - int(observed.st_mtime_ns % 1_000_000_000), - int(observed.st_dev), - int(observed.st_ino), - int(observed.st_mode), - int(observed.st_uid), - int(observed.st_gid), - int(observed.st_size), - bytes.fromhex(object_id), - len(encoded), - ) - entry = fields + encoded + b"\0" - entry += b"\0" * ((8 - len(entry) % 8) % 8) - body = struct.pack("!4sII", b"DIRC", 2, 1) + entry - checksum = hashlib.sha1(body, usedforsecurity=False).digest() - (repo / ".git/index").write_bytes(body + checksum) - - -def test_index_vs_head_detects_staged_content_with_matching_stat_metadata( - tmp_path: Path, -) -> None: - git_dir = tmp_path / ".git" - (git_dir / "refs/heads").mkdir(parents=True) - tracked = tmp_path / "tracked.py" - tracked.write_text("value = 1\n", encoding="utf-8") - - original_blob = _git_object(git_dir, b"blob", tracked.read_bytes()) - tree_body = b"100644 tracked.py\0" + bytes.fromhex(original_blob) - tree = _git_object(git_dir, b"tree", tree_body) - commit = _git_object( - git_dir, - b"commit", - f"tree {tree}\n\nfixture\n".encode("ascii"), - ) - (git_dir / "HEAD").write_text("ref: refs/heads/main\n", encoding="ascii") - (git_dir / "refs/heads/main").write_text(f"{commit}\n", encoding="ascii") - - _write_index(tmp_path, "tracked.py", original_blob) - assert _index_metadata_dirty_paths(tmp_path) == () - - tracked.write_text("value = 2\n", encoding="utf-8") - staged_blob = _git_object(git_dir, b"blob", tracked.read_bytes()) - _write_index(tmp_path, "tracked.py", staged_blob) - - assert _index_metadata_dirty_paths(tmp_path) == ( - "", - ) - - -def test_lightweight_source_identity_accepts_clean_packed_head( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - repo.mkdir() - _git(repo, "init", "-q") - _git(repo, "config", "user.email", "campaign@example.invalid") - _git(repo, "config", "user.name", "Campaign Test") - (repo / "tracked.py").write_text("value = 1\n", encoding="utf-8") - _git(repo, "add", "tracked.py") - _git(repo, "commit", "-q", "-m", "fixture") - revision = _git(repo, "rev-parse", "HEAD") - tree = _git(repo, "rev-parse", "HEAD^{tree}") - - _git(repo, "gc", "--prune=now") - loose_commit = repo / ".git" / "objects" / revision[:2] / revision[2:] - assert not loose_commit.exists() - - identity = manual_campaign.lightweight_source_identity(repo) - - assert identity.revision == revision - assert identity.tree == tree - assert identity.dirty_paths == () - - (repo / "tracked.py").write_text("value = 2\n", encoding="utf-8") - _git(repo, "add", "tracked.py") - - assert manual_campaign.lightweight_source_identity(repo).dirty_paths == ( - "", - ) - - -def test_installed_source_identity_uses_candidate_checkout_only_when_allowed( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - repo.mkdir() - _git(repo, "init", "-q") - _git(repo, "config", "user.email", "campaign@example.invalid") - _git(repo, "config", "user.name", "Campaign Test") - (repo / "tracked.py").write_text("value = 1\n", encoding="utf-8") - _git(repo, "add", "tracked.py") - _git(repo, "commit", "-q", "-m", "fixture") - - from pyamplicol._internal import versions - - monkeypatch.setattr(versions, "active_source_revision", lambda: None) - monkeypatch.setattr(versions, "active_source_checkout", lambda: repo) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match="has no source revision", - ): - manual_campaign.installed_source_identity() - - identity = manual_campaign.installed_source_identity( - allow_candidate_checkout=True, - ) - assert identity.revision == _git(repo, "rev-parse", "HEAD") - assert identity.tree == _git(repo, "rev-parse", "HEAD^{tree}") - assert identity.eligible - - -def test_installed_dry_run_requests_candidate_checkout_identity( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - requested: list[bool] = [] - - class IdentityRequested(RuntimeError): - pass - - def record_request(*, allow_candidate_checkout: bool = False) -> None: - requested.append(allow_candidate_checkout) - raise IdentityRequested - - monkeypatch.setattr( - manual_campaign, - "installed_source_identity", - record_request, - ) - - assert ( - manual_campaign.main( - ( - "run", - "--dry-run", - "--table", - "scalar_contact", - "--multiplicity", - "2", - "--generation-engine", - "compiled", - "--no-color", - ), - repo_root=tmp_path, - docs_dir=tmp_path, - installed=True, - launcher_path_checked=True, - ) - == 2 - ) - - assert requested == [True] - - -def test_measurement_readiness_distinguishes_absent_runtime_revision( - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - monkeypatch.setattr( - manual_campaign, - "_installed_source_revision", - lambda: None, - ) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match="runtime contains no clean source revision", - ): - manual_campaign.require_measurement_ready(source) - - -def test_measurement_readiness_reports_runtime_revision_mismatch( - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - monkeypatch.setattr( - manual_campaign, - "_installed_source_revision", - lambda: "c" * 40, - ) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match=r"checkout=a{40}, installed=c{40}", - ): - manual_campaign.require_measurement_ready(source) - - -def test_installed_source_revision_wraps_package_import_provenance_error( - monkeypatch: pytest.MonkeyPatch, -) -> None: - original_import = builtins.__import__ - - def failing_import(name: str, *args: object, **kwargs: object) -> object: - if name == "pyamplicol._internal.versions": - raise RuntimeError("stale native build inputs") - return original_import(name, *args, **kwargs) - - monkeypatch.setattr(builtins, "__import__", failing_import) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match="runtime provenance cannot be loaded: stale native build inputs", - ): - manual_campaign._installed_source_revision() - - -def test_lightweight_current_rejects_attempt_and_measurement_schema_errors( - tmp_path: Path, -) -> None: - revision = "a" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = _amplicol_leaf_cell() - manifest_path, result_path = _write_lightweight_terminal_current( - service, - cell, - revision=revision, - ) - - current = lightweight_current( - service.store, - cell, - source_revision=revision, - ) - assert current is not None - assert current.complete - assert current.reusable - assert current.record is not None - - manifest = json.loads(manifest_path.read_text(encoding="utf-8")) - manifest["schema"] = "unsupported-attempt-schema" - manifest_path.write_text(json.dumps(manifest), encoding="utf-8") - wrong_attempt_schema = lightweight_current( - service.store, - cell, - source_revision=revision, - ) - assert wrong_attempt_schema is not None - assert not wrong_attempt_schema.complete - assert not wrong_attempt_schema.reusable - assert wrong_attempt_schema.reason == "incomplete metadata" - - manifest["schema"] = ATTEMPT_SCHEMA - manifest_path.write_text(json.dumps(manifest), encoding="utf-8") - result = json.loads(result_path.read_text(encoding="utf-8")) - result.pop("failure") - result_path.write_text(json.dumps(result), encoding="utf-8") - wrong_measurement_schema = lightweight_current( - service.store, - cell, - source_revision=revision, - ) - assert wrong_measurement_schema is not None - assert not wrong_measurement_schema.complete - assert not wrong_measurement_schema.reusable - assert wrong_measurement_schema.reason == "invalid measurement schema" - - -def test_historical_current_reuse_requires_explicit_continuation( - tmp_path: Path, -) -> None: - historical_revision = "a" * 40 - active_revision = "b" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = _amplicol_leaf_cell() - _write_lightweight_terminal_current( - service, - cell, - revision=historical_revision, - ) - - strict = lightweight_current( - service.store, - cell, - source_revision=active_revision, - ) - continued = lightweight_current( - service.store, - cell, - source_revision=active_revision, - accept_historical_source=True, - ) - - assert strict is not None and strict.complete and not strict.reusable - assert strict.reason == "source mismatch" - assert continued is not None and continued.reusable - assert continued.reason == "historical resource-capped terminal" - - inspected = manual_campaign._inspect_payload( - service, - (cell,), - source_revision=active_revision, - renderer_revision=active_revision, - accept_historical_source=True, - ) - assert inspected["source_policy"] == "continue_across_revisions" - assert inspected["source_cohorts"] == {historical_revision: 1} - assert inspected["reusable_count"] == 1 - - -def test_successful_legacy_current_requires_corrected_numerical_authority( - tmp_path: Path, -) -> None: - from tools.performance_report.legacy import ( - LEGACY_NUMERICAL_AUTHORITY_ABI, - LEGACY_NUMERICAL_AUTHORITY_FIELD, - ) - - revision = "a" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = _amplicol_contracted_cell() - _manifest_path, result_path = _write_lightweight_success_current( - service, - cell, - revision=revision, - numerical_relation_correctness={}, - ) - - stale = lightweight_current(service.store, cell, source_revision=revision) - assert stale is not None and stale.complete and not stale.reusable - assert stale.reason == "legacy numerical authority requires refresh" - - result = json.loads(result_path.read_text(encoding="utf-8")) - result["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] = { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": "contracted-generated-library", - } - result_path.write_text(json.dumps(result), encoding="utf-8") - - corrected = lightweight_current(service.store, cell, source_revision=revision) - assert corrected is not None and corrected.complete and corrected.reusable - - -@pytest.mark.parametrize( - ("workload", "generation_source", "expected_compatible"), - ( - (Workload.SELECTED_FLOW, "generated-library-create-mode-1", True), - (Workload.ALL_FLOW, "direct-imode2-generation-setup", False), - (Workload.CONTRACTED, "generated-library-create-raw", False), - ( - Workload.CONTRACTED, - "direct-imode2-three-quark-line-setup", - True, - ), - ), -) -def test_pre_authority_legacy_compatibility_is_narrowly_path_based( - workload: Workload, - generation_source: str, - expected_compatible: bool, -) -> None: - cell = next( - candidate - for candidate in REPORT_CATALOG.measurement_cells() - if candidate.measurement.execution_mode is ExecutionMode.AMPLICOL - and candidate.workload is workload - ) - result = { - "status": ResultStatus.OK.value, - "validation": {}, - "provenance": {"generation_source": generation_source}, - } - - assert ( - manual_campaign._legacy_numerical_authority_compatible(cell, result) - is expected_compatible - ) - - -@pytest.mark.parametrize( - ("extra_provenance", "expected_reusable"), - ( - ( - { - "effective_config": { - "generation": {"relation_discovery": {"mode": "off"}} - } - }, - True, - ), - ( - { - "numerical_relation_correctness": { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - } - }, - True, - ), - ( - { - "numerical_relation_correctness": { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "member-scoped-v1", - "applied_relation_count": 3, - } - }, - True, - ), - ({}, False), - ( - { - "numerical_relation_correctness": { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 1, - } - }, - False, - ), - ( - { - "numerical_relation_correctness": { - "abi": "obsolete", - "state": "member-scoped-v1", - "applied_relation_count": 1, - } - }, - False, - ), - ), -) -def test_historical_pyamplicol_reuse_requires_compact_relation_safety( - tmp_path: Path, - extra_provenance: Mapping[str, object], - expected_reusable: bool, -) -> None: - historical_revision = "a" * 40 - active_revision = "b" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = _pyamplicol_leaf_cell() - _write_lightweight_terminal_current( - service, - cell, - revision=historical_revision, - extra_provenance=extra_provenance, - ) - - current = lightweight_current( - service.store, - cell, - source_revision=active_revision, - accept_historical_source=True, - ) - - assert current is not None - assert current.complete - assert current.reusable is expected_reusable - if not expected_reusable: - assert current.reason == "historical numerical-relation policy is not reusable" - - -def test_successful_historical_pyamplicol_reuse_is_metadata_only_and_planned( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - historical_revision = "a" * 40 - active_revision = "b" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = next( - candidate - for candidate in REPORT_CATALOG.measurement_cells() - if candidate.measurement.execution_mode is ExecutionMode.RECURRENCE - and candidate.measurement.accuracy is not Accuracy.LC - and candidate.n_final == 1 - ) - _manifest_path, result_path = _write_lightweight_success_current( - service, - cell, - revision=historical_revision, - numerical_relation_correctness={ - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - }, - ) - - def forbidden_load_current( - _store: ArtifactStore, - _cell_id: str, - *, - missing_ok: bool = False, - ) -> None: - del missing_ok - raise AssertionError("historical planning inspected authenticated history") - - monkeypatch.setattr(ArtifactStore, "load_current", forbidden_load_current) - requested_batches: list[tuple[str, ...]] = [] - - def observe_plan( - requested: tuple[CellSpec, ...], - **_kwargs: object, - ) -> tuple[object, ...]: - requested_batches.append(tuple(item.cell_id for item in requested)) - return () - - monkeypatch.setattr(manual_campaign, "plan_campaign", observe_plan) - arguments = build_parser().parse_args( - ( - "run", - "--dry-run", - "--no-color", - "--continue-across-revisions", - "--cell-id", - cell.cell_id, - ) - ) - source = ReportSourceIdentity(active_revision, "c" * 40, ()) - - assert ( - _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(cell,), - palette=Palette(False), - ) - == 0 - ) - assert requested_batches == [()] - capsys.readouterr() - - result = json.loads(result_path.read_text(encoding="utf-8")) - result["provenance"]["numerical_relation_correctness"] = { - "abi": "obsolete", - "state": "member-scoped-v1", - "applied_relation_count": 1, - } - result_path.write_text(json.dumps(result), encoding="utf-8") - - assert ( - _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(cell,), - palette=Palette(False), - ) - == 0 - ) - assert requested_batches == [(), (cell.cell_id,)] - - -def test_same_source_pyamplicol_reuse_does_not_require_historical_abi( - tmp_path: Path, -) -> None: - revision = "a" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = _pyamplicol_leaf_cell() - _write_lightweight_terminal_current(service, cell, revision=revision) - - current = lightweight_current( - service.store, - cell, - source_revision=revision, - ) - - assert current is not None and current.reusable - - -def test_continuation_keeps_direct_history_but_not_dependency_resolution( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - historical_revision = "a" * 40 - active_revision = "b" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - historical = _amplicol_leaf_cell() - missing = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.workload is Workload.SELECTED_FLOW - and cell.cell_id != historical.cell_id - ) - _write_lightweight_terminal_current( - service, - historical, - revision=historical_revision, - ) - observed_requested: list[str] = [] - - def observe_plan( - requested: tuple[CellSpec, ...], - **kwargs: object, - ) -> tuple[object, ...]: - observed_requested.extend(cell.cell_id for cell in requested) - resolver = kwargs["current_resolver"] - assert callable(resolver) - assert resolver(historical) is None - return () - - monkeypatch.setattr(manual_campaign, "plan_campaign", observe_plan) - arguments = build_parser().parse_args( - ( - "run", - "--dry-run", - "--no-color", - "--continue-across-revisions", - ) - ) - - result = _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=ReportSourceIdentity(active_revision, "c" * 40, ()), - cells=(historical, missing), - palette=Palette(False), - ) - - assert result == 0 - assert observed_requested == [missing.cell_id] - output = capsys.readouterr().out - assert "Cross-revision continuation is enabled" in output - assert historical_revision in output - - -def test_selective_retry_conflicts_with_force_refresh_before_state_access( - tmp_path: Path, -) -> None: - service = _isolated_manual_service(tmp_path) - arguments = build_parser().parse_args( - ("run", "--force-refresh", "--rerun-failed", "--no-dashboard") - ) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match="--force-refresh cannot be combined with --rerun-failed", - ): - _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=ReportSourceIdentity("a" * 40, "b" * 40, ()), - cells=(), - palette=Palette(False), - ) - - -def test_selective_retry_no_match_preserves_existing_summary( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - service = _isolated_manual_service(tmp_path) - measurable = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is None - )[:2] - static_na = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - ) - ok = manual_campaign.LightweightCurrent( - cell_id=measurable[0].cell_id, - attempt_id="00000000-0000-4000-8000-000000000001", - result_path=tmp_path / "ok.json", - result={"status": ResultStatus.OK.value}, - complete=True, - reusable=True, - reason="reusable", - ) - summary = service.paths.docs_dir / "campaign_summary_ids" - summary.mkdir(parents=True) - sentinel = summary / "error.txt" - sentinel.write_text("existing-cell\n", encoding="utf-8") - - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: {ok.cell_id: ok}, - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcomes", - lambda *_args, **_kwargs: {}, - ) - - def forbidden(*_args: object, **_kwargs: object) -> None: - raise AssertionError("no-match selective retry reached planning/publication") - - monkeypatch.setattr(manual_campaign, "plan_campaign", forbidden) - monkeypatch.setattr(manual_campaign, "_publish_campaign_summary_ids", forbidden) - arguments = build_parser().parse_args( - ("run", "--rerun-failed", "--rerun-capped", "--no-dashboard") - ) - - result = _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=ReportSourceIdentity("a" * 40, "b" * 40, ()), - cells=(*measurable, static_na), - palette=Palette(False), - ) - - assert result == 0 - assert sentinel.read_text(encoding="utf-8") == "existing-cell\n" - assert "No entries among 2 measurable selected cells match" in ( - capsys.readouterr().out - ) - - -def test_selective_retry_historical_state_requires_continuation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - active_revision = "b" * 40 - historical_revision = "a" * 40 - service = _isolated_manual_service(tmp_path) - cell = _pyamplicol_leaf_cell() - historical = _presentation_outcome( - cell, - revision=historical_revision, - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: {}, - ) - - def outcomes( - *_args: object, - accept_historical_source: bool = False, - **_kwargs: object, - ) -> dict[str, manual_campaign.LightweightPresentationOutcome]: - return {cell.cell_id: historical} if accept_historical_source else {} - - planned: list[tuple[str, ...]] = [] - - def observe_plan( - requested: tuple[CellSpec, ...], - **_kwargs: object, - ) -> tuple[object, ...]: - planned.append(tuple(item.cell_id for item in requested)) - return () - - monkeypatch.setattr(manual_campaign, "lightweight_presentation_outcomes", outcomes) - monkeypatch.setattr(manual_campaign, "plan_campaign", observe_plan) - - strict = build_parser().parse_args( - ("run", "--dry-run", "--rerun-failed", "--cell-id", cell.cell_id) - ) - continued = build_parser().parse_args( - ( - "run", - "--dry-run", - "--rerun-failed", - "--continue-across-revisions", - "--cell-id", - cell.cell_id, - ) - ) - source = ReportSourceIdentity(active_revision, "c" * 40, ()) - - assert ( - _run_campaign( - strict, - repo_root=ROOT, - service=service, - source=source, - cells=(cell,), - palette=Palette(False), - ) - == 0 - ) - assert planned == [] - assert ( - _run_campaign( - continued, - repo_root=ROOT, - service=service, - source=source, - cells=(cell,), - palette=Palette(False), - ) - == 0 - ) - assert planned == [(cell.cell_id,)] - - -def test_selective_retry_keeps_dependency_closure_and_reuses_ok_prerequisite( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - revision = "a" * 40 - service = _isolated_manual_service(tmp_path) - target = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-all-flow" - ) - prerequisite = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - failure = _presentation_outcome(target, revision=revision) - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcomes", - lambda *_args, **_kwargs: {target.cell_id: failure}, - ) - success_result = {"status": ResultStatus.OK.value} - success_record = manual_campaign.CurrentRecord( - cell_id=prerequisite.cell_id, - attempt_id="00000000-0000-4000-8000-000000000001", - manifest_path=tmp_path / "manifest.json", - manifest_sha256="0" * 64, - result_path=tmp_path / "result.json", - result=success_result, - artifacts=(), - artifact_policy=ArtifactPolicy.REUSE, - ) - success = manual_campaign.LightweightCurrent( - cell_id=prerequisite.cell_id, - attempt_id=success_record.attempt_id, - result_path=success_record.result_path, - result=success_result, - complete=True, - reusable=True, - reason="reusable", - record=success_record, - ) - recycle_prerequisite = False - - def resolve_lightweight( - _store: ArtifactStore, - cell: CellSpec, - **_kwargs: object, - ) -> manual_campaign.LightweightCurrent | None: - if recycle_prerequisite and cell.cell_id == prerequisite.cell_id: - return success - return None - - monkeypatch.setattr(manual_campaign, "lightweight_current", resolve_lightweight) - planned_batches: list[tuple[object, ...]] = [] - real_dry_run_rows = manual_campaign._dry_run_rows - - def observe_dry_run_rows( - direct: object, - planned: tuple[object, ...], - **kwargs: object, - ) -> tuple[object, ...]: - planned_batches.append(tuple(planned)) - return tuple(real_dry_run_rows(direct, planned, **kwargs)) - - monkeypatch.setattr(manual_campaign, "_dry_run_rows", observe_dry_run_rows) - arguments = build_parser().parse_args( - ( - "run", - "--dry-run", - "--rerun-failed", - "--no-dependencies-added", - "--cell-id", - target.cell_id, - ) - ) - source = ReportSourceIdentity(revision, "b" * 40, ()) - - assert ( - _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(target,), - palette=Palette(False), - ) - == 0 - ) - assert [item.cell.cell_id for item in planned_batches[0]] == [ - prerequisite.cell_id, - target.cell_id, - ] - assert planned_batches[0][0].dependency - - recycle_prerequisite = True - assert ( - _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(target,), - palette=Palette(False), - ) - == 0 - ) - assert [item.cell.cell_id for item in planned_batches[1]] == [target.cell_id] - assert not planned_batches[1][0].dependency - - -def test_selective_retry_injects_authority_chain_unless_explicitly_disabled( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - revision = "a" * 40 - service = _isolated_manual_service(tmp_path) - candidate = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-3q-lines-contracted" - ) - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - failure = _presentation_outcome(candidate, revision=revision) - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcomes", - lambda *_args, **_kwargs: {candidate.cell_id: failure}, - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_current", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - manual_campaign, - "_original_amplicol_available_for_planning", - lambda *_args, **_kwargs: True, - ) - planned_batches: list[tuple[object, ...]] = [] - real_dry_run_rows = manual_campaign._dry_run_rows - - def observe_dry_run_rows( - direct: object, - planned: tuple[object, ...], - **kwargs: object, - ) -> tuple[object, ...]: - planned_batches.append(tuple(planned)) - return tuple(real_dry_run_rows(direct, planned, **kwargs)) - - monkeypatch.setattr(manual_campaign, "_dry_run_rows", observe_dry_run_rows) - arguments = build_parser().parse_args(("run", "--dry-run", "--rerun-failed")) - source = ReportSourceIdentity(revision, "b" * 40, ()) - - assert ( - _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(candidate,), - palette=Palette(False), - ) - == 0 - ) - - assert [item.cell.cell_id for item in planned_batches[0]] == [ - amplicol.cell_id, - recurrence.cell_id, - candidate.cell_id, - ] - assert [item.dependency for item in planned_batches[0]] == [True, True, False] - assert planned_batches[0][1].prerequisite_cell_ids == (amplicol.cell_id,) - assert planned_batches[0][2].prerequisite_cell_ids == (recurrence.cell_id,) - assert planned_batches[0][2].numerical_authority_cell_ids == ( - recurrence.cell_id, - ) - - opt_out = build_parser().parse_args( - ( - "run", - "--dry-run", - "--rerun-failed", - "--no-dependencies-added", - ) - ) - assert ( - _run_campaign( - opt_out, - repo_root=ROOT, - service=service, - source=source, - cells=(candidate,), - palette=Palette(False), - ) - == 0 - ) - assert [item.cell.cell_id for item in planned_batches[1]] == [candidate.cell_id] - assert not planned_batches[1][0].dependency - assert planned_batches[1][0].prerequisite_cell_ids == () - - -def test_manual_dry_run_plans_only_from_lightweight_metadata( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - revision = "b" * 40 - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell = _amplicol_leaf_cell() - _write_lightweight_terminal_current(service, cell, revision=revision) - - def forbidden_load_current( - _store: ArtifactStore, - _cell_id: str, - *, - missing_ok: bool = False, - ) -> None: - del missing_ok - raise AssertionError("manual planning called authenticated artifact loading") - - monkeypatch.setattr(ArtifactStore, "load_current", forbidden_load_current) - arguments = build_parser().parse_args( - ("run", "--dry-run", "--no-color", "--cell-id", cell.cell_id) - ) - result = _run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=ReportSourceIdentity(revision, "c" * 40, ()), - cells=(cell,), - palette=Palette(False), - ) - - assert result == 0 - output = capsys.readouterr().out - assert "recycled" in output - assert "1" in output - assert "planned with dependencies" in output - - -def test_non_manual_planning_keeps_authenticated_store_lookup( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - calls: list[str] = [] - - def observed_load_current( - _store: ArtifactStore, - cell_id: str, - *, - missing_ok: bool = False, - ) -> None: - assert missing_ok - calls.append(cell_id) - return None - - monkeypatch.setattr(ArtifactStore, "load_current", observed_load_current) - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - cell = _amplicol_leaf_cell() - - planned = plan_campaign((cell,), store=store, settings=CampaignSettings()) - - assert planned - assert cell.cell_id in calls - - -@pytest.mark.parametrize( - "setting", - ( - "target_runtime_seconds", - "resource_sample_interval_seconds", - "termination_grace_seconds", - "timeout_seconds", - ), -) -@pytest.mark.parametrize("value", (float("nan"), float("inf"))) -def test_campaign_settings_reject_non_finite_float_controls( - setting: str, - value: float, -) -> None: - with pytest.raises(ValueError): - CampaignSettings(**{setting: value}) diff --git a/pyamplicol/tests/unit/test_manual_campaign_observability.py b/pyamplicol/tests/unit/test_manual_campaign_observability.py deleted file mode 100644 index 6a935c7ab0..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_observability.py +++ /dev/null @@ -1,332 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import os -from pathlib import Path -from typing import Any - -import pytest - -import tools.performance_report.manual_campaign as manual_campaign -from tools.ci.memory_watchdog import ProcessInfo as WatchdogProcessInfo -from tools.performance_report.manual_campaign import ( - DashboardState, - LeaseManager, - render_dashboard_frame, -) -from tools.performance_report.resources import ( - ProcessRecord, - ProcessTreeSampler, - _parse_ps_cpu_time, - process_snapshot, -) -from tools.performance_report.service import ReportPaths, ReportService - -ROOT = Path(__file__).resolve().parents[2] - - -def test_darwin_process_snapshot_reports_native_tree_rss() -> None: - def reject_ps(_command: tuple[str, ...]) -> object: - raise AssertionError("Darwin resource monitoring must not execute ps") - - records = process_snapshot( - "Darwin", - ps_runner=reject_ps, - darwin_snapshotter=lambda: { - 100: WatchdogProcessInfo(100, 1, 100, 1024 * 1024, 1.25), - 101: WatchdogProcessInfo(101, 100, 100, 2048 * 1024, 3_723.5), - }, - ) - sample = ProcessTreeSampler(100).sample(records) - - assert records[100].cpu_seconds == 1.25 - assert records[101].cpu_seconds == 3_723.5 - assert sample.cpu_seconds == 3_724.75 - assert sample.rss_bytes == 3 * 1024 * 1024 - assert _parse_ps_cpu_time("2-03:04:05.50") == 183_845.5 - partial = ProcessTreeSampler(100).sample( - { - 100: ProcessRecord(100, 1, 100, 1.0), - 101: ProcessRecord(101, 100, 100, None), - } - ) - assert partial.cpu_seconds is None - - -def test_dashboard_uses_guard_memory_and_incremental_progress_and_log_tails( - tmp_path: Path, -) -> None: - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - cell_id = "observability-cell" - progress_path = tmp_path / "progress.jsonl" - log_path = tmp_path / "worker.log" - initial_progress = ( - json.dumps( - { - "event": "update", - "completed": 2, - "total": 4, - "message": "building currents", - } - ) - + "\n" - ) - initial_log = "loaded model\n\x1b[31mprofiling batch 2\x1b[0m\n" - progress_path.write_text(initial_progress, encoding="utf-8") - log_path.write_text(initial_log, encoding="utf-8") - state = DashboardState( - instance_id="observability", - selected_ids=(cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - memory_limit_bytes=1_000, - ) - lease = LeaseManager(service, state) - lease.observe( - { - "event": "worker", - "cell_id": cell_id, - "attempt_id": "attempt", - "progress_path": str(progress_path), - "log_path": str(log_path), - } - ) - resource = { - "event": "resource", - "cell_id": cell_id, - "phase": "profiling", - "pid": 100, - "member_pids": [100, 101], - "wall_seconds": 3.5, - "cpu_seconds": 5.25, - "current_rss_bytes": 800, - "peak_rss_bytes": 900, - "current_physical_footprint_bytes": 1_200, - "peak_physical_footprint_bytes": 1_300, - "current_guard_bytes": 1_200, - "peak_guard_bytes": 1_300, - "child_count": 1, - } - lease.observe(resource) - - worker = state.workers[cell_id] - assert worker.cpu_seconds == 5.25 - assert worker.current_rss_bytes == 800 - assert worker.current_physical_footprint_bytes == 1_200 - assert worker.current_guard_bytes == 1_200 - assert worker.log_tail == ["loaded model", "profiling batch 2"] - assert worker._progress_tail_state.last_read_bytes == len(initial_progress.encode()) - assert worker._log_tail_state.last_read_bytes == len(initial_log.encode()) - - appended_progress = ( - json.dumps( - { - "event": "update", - "completed": 3, - "total": 4, - "message": "profiling batch 3", - } - ) - + "\n" - ) - appended_log = "profiling batch 3\n" - with progress_path.open("a", encoding="utf-8") as stream: - stream.write(appended_progress) - with log_path.open("a", encoding="utf-8") as stream: - stream.write(appended_log) - lease.observe(resource) - - assert worker.progress_completed == 3 - assert worker._progress_tail_state.last_read_bytes == len( - appended_progress.encode() - ) - assert worker._log_tail_state.last_read_bytes == len(appended_log.encode()) - assert worker.log_tail[-1] == "profiling batch 3" - assert worker.events.count("resource: profiling") == 1 - lease_payload = json.loads(lease.path.read_text(encoding="utf-8")) - leased_worker = lease_payload["workers"][cell_id] - assert leased_worker["current_rss_bytes"] == 800 - assert leased_worker["current_physical_footprint_bytes"] == 1_200 - assert leased_worker["current_guard_bytes"] == 1_200 - assert "_progress_tail_state" not in leased_worker - - wide = render_dashboard_frame(state, width=160, height=48) - compact = render_dashboard_frame(state, width=80, height=24) - for frame in (wide, compact): - assert "progress" in frame - assert "▰" in frame - assert "Guard current" in frame - assert "1.20 kB" in frame - assert "Recent log" in frame - assert "profiling batch 3" in frame - assert "RSS current" in wide and "800 B" in wide - assert "RSS peak" in wide and "900 B" in wide - assert "Physical current" in wide and "1.20 kB" in wide - assert "RAM cap" in wide and "1.00 kB" in wide - - -@pytest.mark.parametrize( - ("arguments", "environment_color", "expected"), - ( - (("dashboard-snapshot",), None, True), - (("dashboard-snapshot", "--no-color"), None, False), - (("dashboard-snapshot",), "", False), - (("dashboard-snapshot", "--cells-json"), None, True), - (("dashboard-snapshot", "--cells-json", "--no-color"), None, False), - (("dashboard-snapshot", "--cells-json"), "", False), - ), -) -def test_dashboard_cli_propagates_color_policy( - arguments: tuple[str, ...], - environment_color: str | None, - expected: bool, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - if environment_color is None: - monkeypatch.delenv("NO_COLOR", raising=False) - else: - monkeypatch.setenv("NO_COLOR", environment_color) - observed: list[bool] = [] - - def capture(*_args: Any, **kwargs: Any) -> object: - observed.append(bool(kwargs["color"])) - return [] if kwargs["cells"] else "frame" - - monkeypatch.setattr(manual_campaign, "render_dashboard_frame", capture) - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - - assert manual_campaign.main(arguments, repo_root=ROOT, docs_dir=docs_dir) == 0 - capsys.readouterr() - assert observed == [expected] - - -def test_ratatui_style_toggle_removes_all_cell_styles() -> None: - state = manual_campaign._snapshot_fixture(selected=5, recycled=1, completed=1) - - colored = render_dashboard_frame( - state, - width=120, - height=36, - cells=True, - color=True, - ) - plain = render_dashboard_frame( - state, - width=120, - height=36, - cells=True, - color=False, - ) - - assert isinstance(colored, list) - assert isinstance(plain, list) - assert any(cell.get("fg") not in (None, 0) for cell in colored) - assert all(cell.get("fg") in (None, 0) for cell in plain) - assert all(cell.get("bg") in (None, 0) for cell in plain) - assert all(cell.get("mods") in (None, 0) for cell in plain) - - -def test_dashboard_preserves_and_displays_three_independent_recurrence_clocks() -> None: - state = manual_campaign._snapshot_fixture(selected=5, recycled=1, completed=1) - state.show_completed = True - workers = state.visible_workers() - state.selected_index = next( - index - for index, worker in enumerate(workers) - if "matrix-recurrence-" in worker.cell_id - ) - selected = state.selected_worker() - assert selected is not None - - decoded = manual_campaign._worker_from_lease( - selected.cell_id, - selected.as_dict(), - peer_instance=None, - ) - assert decoded.generation_engine == "recurrence" - assert decoded.published_wall_seconds_per_point == pytest.approx(218.105e-6) - assert decoded.published_evaluator_total_seconds_per_point == pytest.approx( - 217.812e-6 - ) - assert decoded.published_recurrence_core_seconds_per_point == pytest.approx( - 205.431e-6 - ) - - frame = render_dashboard_frame(state, width=120, height=36) - assert "Outer wall" in frame - assert "218.105 μs/pt" in frame - assert "Evaluator total" in frame - assert "217.812 μs/pt" in frame - assert "Recurrence core" in frame - assert "205.431 μs/pt" in frame - - state.selected_index = next( - index - for index, worker in enumerate(workers) - if "matrix-compiled-" in worker.cell_id - ) - compiled_frame = render_dashboard_frame(state, width=120, height=36) - assert "Recurrence core" in compiled_frame - assert "not applicable" in compiled_frame - - -def test_ratatui_terminal_session_uses_native_lifecycle_and_restores_environment( - monkeypatch: pytest.MonkeyPatch, -) -> None: - import ratatui_py - - events: list[tuple[str, str | None, str | None]] = [] - - class FakeTerminal: - def __init__(self) -> None: - events.append( - ( - "init", - os.environ.get("RATATUI_FFI_ALTSCR"), - os.environ.get("RATATUI_FFI_NO_RAW"), - ) - ) - - def close(self) -> None: - events.append(("close", None, None)) - - def unsafe_session(**_options: object) -> object: - raise AssertionError("the unsafe ratatui_py.terminal_session was called") - - monkeypatch.setattr(ratatui_py, "Terminal", FakeTerminal) - monkeypatch.setattr(ratatui_py, "terminal_session", unsafe_session) - monkeypatch.setenv("RATATUI_FFI_ALTSCR", "existing-alt") - monkeypatch.setenv("RATATUI_FFI_NO_RAW", "existing-no-raw") - - with ( - pytest.raises(KeyboardInterrupt), - manual_campaign._ratatui_terminal_session(), - ): - events.append( - ( - "body", - os.environ.get("RATATUI_FFI_ALTSCR"), - os.environ.get("RATATUI_FFI_NO_RAW"), - ) - ) - raise KeyboardInterrupt - - assert events == [ - ("init", "1", None), - ("body", "existing-alt", "existing-no-raw"), - ("close", None, None), - ] - assert os.environ["RATATUI_FFI_ALTSCR"] == "existing-alt" - assert os.environ["RATATUI_FFI_NO_RAW"] == "existing-no-raw" diff --git a/pyamplicol/tests/unit/test_manual_campaign_recycled_exit.py b/pyamplicol/tests/unit/test_manual_campaign_recycled_exit.py deleted file mode 100644 index 88ebb83975..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_recycled_exit.py +++ /dev/null @@ -1,115 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from pathlib import Path - -import pytest - -import tools.performance_report.manual_campaign as manual_campaign -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.manual_campaign import LightweightCurrent -from tools.performance_report.models import ExecutionMode -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity - -ROOT = Path(__file__).resolve().parents[2] - - -def test_all_recycled_run_exits_before_lease_scheduler_or_attempt( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - measurable = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and REPORT_CATALOG.static_na_reason(cell) is None - ) - static_na = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - ) - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - service = ReportService( - ReportPaths.from_repo( - ROOT, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - arguments = manual_campaign.build_parser().parse_args( - ( - "run", - "--cell-id", - measurable.cell_id, - static_na.cell_id, - "--no-dashboard", - ) - ) - current = LightweightCurrent( - cell_id=measurable.cell_id, - attempt_id="reusable-attempt", - result_path=tmp_path / "result.json", - result={}, - complete=True, - reusable=True, - reason="reusable", - ) - events: list[str] = [] - - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: {measurable.cell_id: current}, - ) - monkeypatch.setattr( - manual_campaign, - "plan_campaign", - lambda *_args, **_kwargs: (), - ) - monkeypatch.setattr( - manual_campaign, - "require_measurement_ready", - lambda observed: events.append(f"ready:{observed.revision}"), - ) - monkeypatch.setattr( - manual_campaign, - "update_source_marker", - lambda _service, observed: events.append(f"marker:{observed.revision}"), - ) - - def forbidden(*_args: object, **_kwargs: object) -> None: - raise AssertionError("all-recycled run reached worker/attempt setup") - - monkeypatch.setattr(manual_campaign, "LeaseManager", forbidden) - monkeypatch.setattr(manual_campaign, "CampaignScheduler", forbidden) - monkeypatch.setattr(ArtifactStore, "new_attempt", forbidden) - - result = manual_campaign._run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(measurable, static_na), - palette=manual_campaign.Palette(enabled=True), - ) - - assert result == 0 - assert events == [f"ready:{source.revision}", f"marker:{source.revision}"] - output = capsys.readouterr().out - assert "\x1b[" in output - assert "selected entries" in output - assert "measurable entries" in output - assert "recycled measurable entries" in output - assert "static N/A entries" in output - assert "workers created" in output - assert "attempts created" in output - assert "All selected measurable entries were recycled (1 of 1)" in output - assert "no workers or attempts were created" in output - assert "1 selected static N/A entry remains policy unavailable" in output - assert not (tmp_path / "coordination" / "manual-leases").exists() - assert not tuple((tmp_path / "artifacts" / "cells").rglob("attempts")) diff --git a/pyamplicol/tests/unit/test_manual_campaign_summary_and_lifecycle.py b/pyamplicol/tests/unit/test_manual_campaign_summary_and_lifecycle.py deleted file mode 100644 index 3d0f1e2707..0000000000 --- a/pyamplicol/tests/unit/test_manual_campaign_summary_and_lifecycle.py +++ /dev/null @@ -1,1498 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import errno -import json -import threading -from collections.abc import Callable -from concurrent.futures import Future -from pathlib import Path - -import pytest - -import tools.performance_report.artifacts as artifacts_module -import tools.performance_report.manual_campaign as manual_campaign -from tools.performance_report.artifacts import ( - ArtifactStore, - ArtifactStoreError, - DiskFullError, - ManifestValidationError, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.manual_campaign import ( - DashboardState, - LightweightCurrent, - WorkerView, -) -from tools.performance_report.models import ArtifactPolicy -from tools.performance_report.scheduler import ( - CampaignResult, - CampaignScheduler, - CampaignSettings, - CellOutcome, - PlannedCell, - _attempt_files, - archive_cell_attempt_history, - reconcile_attempt_history, -) -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity - - -def _store(tmp_path: Path) -> ArtifactStore: - return ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "coordination", - ) - - -def _service(tmp_path: Path) -> ReportService: - root = tmp_path / "repo" - docs = root / "docs/performance_reports/manual" - docs.mkdir(parents=True) - return ReportService( - ReportPaths.from_repo( - root, - docs_dir=docs, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - - -def _publish_with_payload( - store: ArtifactStore, - cell_id: str, - marker: str, - *, - artifact_path: Path | None = None, -): - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - payload = attempt.path("artifact/payload.bin") - payload.write_bytes(marker.encode("ascii")) - attempt.path("worker.log").write_text(f"{marker}\n", encoding="utf-8") - return attempt.publish( - { - "status": "ok", - "artifact": { - "path": str( - (attempt.root / "artifact") - if artifact_path is None - else artifact_path - ) - }, - }, - artifact_paths=("artifact/payload.bin", "worker.log"), - ) - - -def test_cell_id_files_union_comments_and_intersect(tmp_path: Path) -> None: - first = "scalar-contact-n2-scalar-contact-contracted" - second = "scalar-gravity-n2-scalar-gravity-contracted" - ids = tmp_path / "failed.txt" - ids.write_text(f"# retry set\n{first}\n\n{second}\n{first}\n", encoding="utf-8") - arguments = manual_campaign.build_parser().parse_args( - ( - "inspect", - "--cell-id-file", - str(ids), - "--model", - "scalar_contact", - ) - ) - - _selection, cells = manual_campaign.selection_from_arguments(arguments) - - assert tuple(cell.cell_id for cell in cells) == (first,) - - -def test_fail_fast_parser_help_and_steering_guide_are_explicit( - capsys: pytest.CaptureFixture[str], -) -> None: - parser = manual_campaign.build_parser() - arguments = parser.parse_args(("run", "--fail-fast")) - with pytest.raises(SystemExit) as help_exit: - parser.parse_args(("run", "--help")) - run_help = capsys.readouterr().out - - assert arguments.fail_fast - assert help_exit.value.code == 0 - assert "--fail-fast" in run_help - assert "campaign_summary_ids/fail_fast_failure.log" in run_help - assert "--fail-fast --workers 4 --table matrix" in manual_campaign.STEERING_GUIDE - - -def test_fail_fast_terminal_classification_ignores_stop_cancellation_but_not_recycled( -) -> None: - cancellation = threading.Event() - observed: list[dict[str, object]] = [] - observer = manual_campaign._FailFastObserver( - lambda payload: observed.append(dict(payload)), - cancellation, - ) - - observer.observe( - {"event": "finished", "cell_id": "ok", "status": "skipped-current"} - ) - observer.observe( - {"event": "finished", "cell_id": "stopped", "status": "cancelled"} - ) - assert observer.failure is None - assert not cancellation.is_set() - - observer.observe( - { - "event": "finished", - "cell_id": "unexpected-recycled-terminal", - "status": "recycled", - "detail": "not a scheduler success status", - } - ) - observer.observe( - {"event": "finished", "cell_id": "later", "status": "error"} - ) - - assert cancellation.is_set() - assert observer.failure is not None - assert observer.failure.cell_id == "unexpected-recycled-terminal" - assert len(observed) == 4 - - -def test_fail_fast_all_static_selection_creates_no_failure_report( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - ) - arguments = manual_campaign.build_parser().parse_args( - ("run", "--fail-fast", "--no-dashboard", "--cell-id", cell.cell_id) - ) - - exit_code = manual_campaign._run_campaign( - arguments, - repo_root=tmp_path, - service=service, - source=ReportSourceIdentity("a" * 40, "b" * 40, ()), - cells=(cell,), - palette=manual_campaign.Palette(False), - ) - - summary = service.paths.docs_dir / "campaign_summary_ids" - assert exit_code == 0 - assert (summary / "static_na.txt").read_text(encoding="utf-8") == ( - f"{cell.cell_id}\n" - ) - assert not (summary / manual_campaign.FAIL_FAST_FAILURE_LOG).exists() - - -def test_repeated_cell_id_files_union_with_direct_ids(tmp_path: Path) -> None: - contact = "scalar-contact-n2-scalar-contact-contracted" - gravity = "scalar-gravity-n2-scalar-gravity-contracted" - matrix = "matrix-recurrence-builtin-sm-lc-n2-dd-z-jets-selected-flow" - first = tmp_path / "first.txt" - second = tmp_path / "second.txt" - first.write_text(f"{contact}\n", encoding="utf-8") - second.write_text(f"{gravity}\n", encoding="utf-8") - arguments = manual_campaign.build_parser().parse_args( - ( - "inspect", - "--cell-id-file", - str(first), - "--cell-id-file", - str(second), - "--cell-id", - matrix, - "--multiplicity", - "2", - ) - ) - - _selection, cells = manual_campaign.selection_from_arguments(arguments) - - assert {cell.cell_id for cell in cells} == {contact, gravity, matrix} - - -def test_cell_id_file_reports_path_line_and_rejects_wildcard(tmp_path: Path) -> None: - ids = tmp_path / "failed.txt" - ids.write_text("*\n", encoding="utf-8") - arguments = manual_campaign.build_parser().parse_args( - ("inspect", "--cell-id-file", str(ids)) - ) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match=rf"{ids}:1: wildcards are not allowed", - ): - manual_campaign.selection_from_arguments(arguments) - - -def test_empty_cell_id_file_does_not_expand_to_all_cells(tmp_path: Path) -> None: - ids = tmp_path / "empty.txt" - ids.write_text("# no retries\n\n", encoding="utf-8") - arguments = manual_campaign.build_parser().parse_args( - ("inspect", "--cell-id-file", str(ids)) - ) - - with pytest.raises( - manual_campaign.ManualCampaignError, - match="contain no canonical cell IDs", - ): - manual_campaign.selection_from_arguments(arguments) - - -@pytest.mark.parametrize("wildcard", ("*", "all", "ALL")) -def test_direct_cell_id_wildcard_still_intersects_other_selectors( - wildcard: str, -) -> None: - arguments = manual_campaign.build_parser().parse_args( - ("inspect", "--cell-id", wildcard, "--model", "scalar_contact") - ) - - _selection, cells = manual_campaign.selection_from_arguments(arguments) - - assert cells - assert all(cell.measurement.model is not None for cell in cells) - assert all(cell.measurement.model.value == "scalar_contact" for cell in cells) - - -def test_summary_publication_replaces_stale_files_and_empty_success( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - path, counts = manual_campaign._publish_campaign_summary_ids( - service, - { - "error": ["cell-b", "cell-a", "cell-a"], - "generation_limit": {"cell-c"}, - "ok": {"ignored"}, - }, - ) - - assert counts == {"error": 2, "generation_limit": 1} - assert (path / "error.txt").read_text(encoding="utf-8") == ( - "cell-a\ncell-b\n" - ) - assert (path / "generation_limit.txt").read_text(encoding="utf-8") == ( - "cell-c\n" - ) - assert not (path / manual_campaign.FAIL_FAST_FAILURE_LOG).exists() - (path / ".DS_Store").write_bytes(b"stale Finder metadata") - - replacement, counts = manual_campaign._publish_campaign_summary_ids(service, {}) - assert replacement == path - assert counts == {} - assert tuple(path.iterdir()) == () - publication_root = ( - service.paths.coordination_root / "campaign-summary-publication" - ) - assert publication_root.is_dir() - assert tuple(publication_root.iterdir()) == () - assert not tuple(path.parent.glob(".campaign_summary_ids.*")) - - -def test_fail_fast_report_contains_exact_cell_attempt_and_reproduction_evidence( - tmp_path: Path, - capsys: pytest.CaptureFixture[str], -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n2-dd-z-jets-selected-flow" - ) - attempt = service.store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE) - artifact = attempt.path("artifact") - artifact.mkdir() - attempt.path("artifact/payload.bin").write_bytes(b"retained failure payload") - worker_log = attempt.path("worker.log") - worker_log.write_text("worker failed\n", encoding="utf-8") - worker_progress = attempt.path("worker-progress.jsonl") - worker_progress.write_text('{"phase":"generation"}\n', encoding="utf-8") - attempt.write_json( - "worker-result.json", - { - "status": "error", - "failure": { - "kind": "ExactFailureClass", - "message": "exact failure message", - }, - "artifact": {"path": str(artifact)}, - }, - ) - attempt.mark_failed( - "ExactFailureClass: exact failure message", - artifact_paths=( - "artifact/payload.bin", - "worker-result.json", - "worker.log", - "worker-progress.jsonl", - ), - ) - state = DashboardState( - instance_id="exact-invocation-id", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - ) - state.workers[cell.cell_id] = WorkerView( - cell.cell_id, - status="error", - attempt_id=attempt.attempt_id, - log_path=str(worker_log), - progress_path=str(worker_progress), - reproduce_prepare="pyamplicol model compile --exact", - reproduce_generate="pyamplicol generate --exact", - reproduce_profile="pyamplicol profile --exact", - ) - failure = manual_campaign._FailFastTerminalFailure( - observed_at_utc="2026-08-07T12:34:56Z", - cell_id=cell.cell_id, - status="error", - detail=attempt.attempt_id, - terminal_detail="worker reported an exact terminal detail", - completed_at_ns=1, - ) - stale_summary = service.paths.docs_dir / "campaign_summary_ids" - stale_summary.mkdir() - (stale_summary / "stale.txt").write_text("stale\n", encoding="utf-8") - - summary_path = manual_campaign._publish_completion_summary( - service, - {"error": {cell.cell_id}}, - state=state, - fail_fast_failure=failure, - invocation_command=( - "steer_performance_campaign.py run --fail-fast --cell-id " - f"{cell.cell_id}" - ), - palette=manual_campaign.Palette(False), - ) - - report_path = summary_path / manual_campaign.FAIL_FAST_FAILURE_LOG - report = report_path.read_text(encoding="utf-8") - assert report_path.name == "fail_fast_failure.log" - assert not (summary_path / "stale.txt").exists() - for expected in ( - "timestamp_utc: 2026-08-07T12:34:56Z", - "campaign_invocation_id: exact-invocation-id", - "campaign_invocation: steer_performance_campaign.py run --fail-fast", - f"cell_id: {cell.cell_id}", - "process_family_id: 1", - f"process_key: {cell.process_key}", - f"process: {cell.process}", - f"n_final: {cell.n_final}", - "mode: recurrence", - "workload: selected-flow", - "accuracy: lc", - "terminal_status: error", - f"outcome_detail: {attempt.attempt_id}", - "terminal_detail: worker reported an exact terminal detail", - "failure_class: ExactFailureClass", - "failure_message: exact failure message", - f"attempt_uuid: {attempt.attempt_id}", - f"attempt_root: {attempt.root}", - f"artifact_path: {artifact}", - f"worker_log_path: {worker_log}", - f"worker_progress_path: {worker_progress}", - "reproduce_prepare: pyamplicol model compile --exact", - "reproduce_generate: pyamplicol generate --exact", - "reproduce_profile: pyamplicol profile --exact", - ): - assert expected in report - captured = capsys.readouterr() - assert str(report_path) in captured.err - assert str(artifact) in captured.err - assert str(worker_log) in captured.err - assert (summary_path / "error.txt").read_text(encoding="utf-8") == ( - f"{cell.cell_id}\n" - ) - - -def test_fail_fast_cancels_live_worker_and_never_dispatches_third_cell( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cells = tuple( - REPORT_CATALOG.cell( - f"matrix-recurrence-builtin-sm-lc-n{n_final}-dd-z-jets-selected-flow" - ) - for n_final in (1, 2, 3) - ) - cancellation = threading.Event() - observer = manual_campaign._FailFastObserver(lambda _payload: None, cancellation) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - workers=2, - source_identity_override=ReportSourceIdentity("a" * 40, "b" * 40, ()), - progress_observer=observer.observe, - cancellation_requested=cancellation.is_set, - ), - ) - live_started = threading.Event() - live_saw_cancellation = threading.Event() - launched: list[str] = [] - launched_guard = threading.Lock() - - def run_lane( - _scheduler: CampaignScheduler, - item: PlannedCell, - ) -> CellOutcome: - with launched_guard: - launched.append(item.cell.cell_id) - if item.cell.cell_id == cells[0].cell_id: - assert live_started.wait(timeout=2.0) - return CellOutcome(item.cell.cell_id, "error", "first failure") - if item.cell.cell_id == cells[1].cell_id: - live_started.set() - assert cancellation.wait(timeout=2.0) - live_saw_cancellation.set() - return CellOutcome( - item.cell.cell_id, - "cancelled", - "worker terminated by cancellation", - ) - raise AssertionError("fail-fast dispatched a third cell") - - monkeypatch.setattr(CampaignScheduler, "_run_cell_in_lane", run_lane) - result = scheduler.run( - tuple( - PlannedCell(cell, False, None, index) - for index, cell in enumerate(cells) - ) - ) - - assert set(launched) == {cells[0].cell_id, cells[1].cell_id} - assert live_saw_cancellation.is_set() - assert cells[2].cell_id not in launched - assert observer.failure is not None - assert observer.failure.cell_id == cells[0].cell_id - assert {outcome.status for outcome in result.outcomes} == {"error", "cancelled"} - - -def test_scheduler_rechecks_fail_fast_before_each_multiworker_submission( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cells = tuple( - REPORT_CATALOG.cell( - f"matrix-recurrence-builtin-sm-lc-n{n_final}-dd-z-jets-selected-flow" - ) - for n_final in (1, 2, 3) - ) - cancellation = threading.Event() - observer = manual_campaign._FailFastObserver(lambda _payload: None, cancellation) - submitted: list[str] = [] - - class ImmediateExecutor: - def __init__(self, *_args: object, **_kwargs: object) -> None: - pass - - def __enter__(self) -> ImmediateExecutor: - return self - - def __exit__(self, *_args: object) -> None: - return None - - def submit( - self, - function: Callable[[PlannedCell], CellOutcome], - item: PlannedCell, - ) -> Future[CellOutcome]: - submitted.append(item.cell.cell_id) - future: Future[CellOutcome] = Future() - try: - future.set_result(function(item)) - except BaseException as error: - future.set_exception(error) - return future - - monkeypatch.setattr( - "tools.performance_report.scheduler.ThreadPoolExecutor", - ImmediateExecutor, - ) - monkeypatch.setattr( - CampaignScheduler, - "_run_cell_in_lane", - lambda _scheduler, item: CellOutcome( - item.cell.cell_id, - "error", - "synchronous first failure", - ), - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - workers=3, - source_identity_override=ReportSourceIdentity("a" * 40, "b" * 40, ()), - progress_observer=observer.observe, - cancellation_requested=cancellation.is_set, - ), - ) - - result = scheduler.run( - tuple( - PlannedCell(cell, False, None, index) - for index, cell in enumerate(cells) - ) - ) - - assert submitted == [cells[0].cell_id] - assert tuple(outcome.cell_id for outcome in result.outcomes) == ( - cells[0].cell_id, - ) - - -def test_epyc_n9_codec_limit_summary_round_trips_to_exact_run_selection( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell_id = "matrix-recurrence-builtin-sm-lc-n9-gg-gluons-selected-flow" - summary, _counts = manual_campaign._publish_campaign_summary_ids( - service, - {"error": {cell_id}}, - ) - arguments = manual_campaign.build_parser().parse_args( - ("run", "--dry-run", "--cell-id-file", str(summary / "error.txt")) - ) - - _selection, cells = manual_campaign.selection_from_arguments(arguments) - - assert tuple(cell.cell_id for cell in cells) == (cell_id,) - - -def test_unverified_summary_round_trips_to_exact_retry_selection( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell_id = "matrix-compiled-builtin-sm-lc-n1-dd-z-jets-selected-flow" - result = CampaignResult( - planned=(), - outcomes=( - CellOutcome( - cell_id, - "unverified", - "independent numerical authority unavailable", - ), - ), - ) - categories = manual_campaign._campaign_summary_categories(result=result) - summary, counts = manual_campaign._publish_campaign_summary_ids( - service, - categories, - ) - - assert counts == {"unverified": 1} - selection_file = summary / "unverified.txt" - assert selection_file.read_text(encoding="utf-8") == f"{cell_id}\n" - arguments = manual_campaign.build_parser().parse_args( - ("run", "--dry-run", "--cell-id-file", str(selection_file)) - ) - - _selection, cells = manual_campaign.selection_from_arguments(arguments) - - assert tuple(cell.cell_id for cell in cells) == (cell_id,) - - -def test_interrupted_summary_contains_observed_not_unstarted_cells() -> None: - state = DashboardState( - instance_id="invocation", - selected_ids=("running", "failed", "unstarted"), - recycled_ids=set(), - static_na_ids=set(), - ) - state.workers["running"] = WorkerView("running", status="running") - state.workers["failed"] = WorkerView("failed", status="error") - state.invocation_evidence_ids.update({"running", "failed"}) - - categories = manual_campaign._campaign_summary_categories( - state=state, - interrupted=True, - ) - - assert categories == {"interrupted": {"running"}, "error": {"failed"}} - - -def test_cancelled_outcome_is_omitted_without_started_observation() -> None: - state = DashboardState( - instance_id="invocation", - selected_ids=("started", "unstarted"), - recycled_ids=set(), - static_na_ids=set(), - ) - state.workers["started"] = WorkerView("started", status="cancelled") - state.invocation_evidence_ids.add("started") - result = CampaignResult( - planned=(), - outcomes=( - CellOutcome("started", "cancelled", "worker cancelled"), - CellOutcome("unstarted", "cancelled", "not started"), - ), - ) - - categories = manual_campaign._campaign_summary_categories( - result=result, - state=state, - interrupted=True, - ) - - assert categories == {"interrupted": {"started"}} - - -def test_lease_finished_cancelled_not_started_is_not_interruption_evidence( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - state = DashboardState( - instance_id="invocation", - selected_ids=("queued", "started"), - recycled_ids=set(), - static_na_ids=set(), - ) - lease = manual_campaign.LeaseManager(service, state) - lease.observe( - { - "event": "finished", - "cell_id": "queued", - "status": "cancelled", - "detail": "not started", - } - ) - lease.observe({"event": "started", "cell_id": "started"}) - lease.observe( - { - "event": "finished", - "cell_id": "started", - "status": "cancelled", - "detail": "worker terminated by cancellation", - } - ) - result = CampaignResult( - planned=(), - outcomes=( - CellOutcome("queued", "cancelled", "not started"), - CellOutcome("started", "cancelled", "worker cancelled"), - ), - ) - - categories = manual_campaign._campaign_summary_categories( - result=result, - state=state, - interrupted=True, - ) - lease.close() - - assert state.invocation_evidence_ids == {"started"} - assert categories == {"interrupted": {"started"}} - - -def test_summary_omits_success_and_recycled_cells_but_keeps_future_statuses() -> None: - state = DashboardState( - instance_id="invocation", - selected_ids=("recycled-cap", "ok", "future", "static"), - recycled_ids={"recycled-cap"}, - static_na_ids={"static"}, - ) - state.workers["recycled-cap"] = WorkerView( - "recycled-cap", - status="memory_limit", - recycled=True, - ) - result = CampaignResult( - planned=(), - outcomes=( - CellOutcome("ok", "ok", "complete"), - CellOutcome("future", "Native Crash / Retry", "failed"), - ), - ) - - categories = manual_campaign._campaign_summary_categories( - static_na_ids=state.static_na_ids, - result=result, - state=state, - ) - - assert categories == { - "native_crash_retry": {"future"}, - "static_na": {"static"}, - } - - -def test_cleanup_warning_is_retained_for_dashboard_and_printed_headlessly( - tmp_path: Path, - capsys: pytest.CaptureFixture[str], -) -> None: - service = _service(tmp_path) - state = DashboardState( - instance_id="invocation", - selected_ids=("cell",), - recycled_ids=set(), - static_na_ids=set(), - ) - lease = manual_campaign.LeaseManager(service, state) - - lease.observe( - { - "event": "cleanup-warning", - "cell_id": "cell", - "detail": "DiskFullError: 0 bytes available", - } - ) - manual_campaign._print_cleanup_warnings( - state, - manual_campaign.Palette(False), - ) - lease.close() - - assert state.cleanup_warnings == [ - ("cell", "DiskFullError: 0 bytes available") - ] - assert state.workers["cell"].events[-1] == ( - "cleanup warning: DiskFullError: 0 bytes available" - ) - assert capsys.readouterr().err == ( - "artifact cleanup skipped for cell: " - "DiskFullError: 0 bytes available\n" - ) - - -def test_obsolete_attempt_archives_metadata_but_removes_heavy_payload( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - current = _publish_with_payload(store, "cell", "current") - - archived = store.archive_obsolete_attempts( - "cell", - consumer_cell_ids=("cell",), - ) - - assert archived == (old.attempt_id,) - history = store._attempt_history_cell_root("cell") / old.attempt_id - assert (history / "manifest.json").is_file() - assert (history / "result.json").is_file() - assert (history / "worker.log").read_text(encoding="utf-8") == "old\n" - assert not (history / "artifact").exists() - assert store.load_current("cell").attempt_id == current.attempt_id - assert (current.manifest_path.parent / "artifact/payload.bin").is_file() - - -def test_equivalent_consumer_keeps_superseded_owner_until_reference_moves( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - owner = _publish_with_payload(store, "owner", "owner") - current = _publish_with_payload(store, "owner", "current") - consumer = store.new_attempt("consumer", ArtifactPolicy.REGENERATE) - consumer.publish( - { - "status": "ok", - "artifact": {"path": str(owner.manifest_path.parent / "artifact")}, - } - ) - - assert store.archive_obsolete_attempts( - "owner", - consumer_cell_ids=("owner", "consumer"), - ) == () - assert (owner.manifest_path.parent / "artifact/payload.bin").is_file() - - _publish_with_payload(store, "consumer", "independent") - assert store.archive_obsolete_attempts( - "owner", - consumer_cell_ids=("owner", "consumer"), - ) == (owner.attempt_id,) - assert store.load_current("owner").attempt_id == current.attempt_id - - -def test_active_unsealed_attempt_is_not_archived(tmp_path: Path) -> None: - store = _store(tmp_path) - current = _publish_with_payload(store, "cell", "current") - active = store.new_attempt("cell", ArtifactPolicy.REGENERATE, based_on=current) - active.path("worker.log").write_text("still running\n", encoding="utf-8") - - assert store.archive_obsolete_attempts( - "cell", consumer_cell_ids=("cell",) - ) == () - assert active.root.is_dir() - assert not (active.root / "manifest.json").exists() - - -def test_malformed_current_pointer_prevents_cleanup(tmp_path: Path) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - current = _publish_with_payload(store, "cell", "current") - pointer_path = current.manifest_path.parent.parent.parent / "current.json" - pointer = json.loads(pointer_path.read_text(encoding="utf-8")) - pointer["manifest_path"] = "../unsafe/manifest.json" - pointer_path.write_text(json.dumps(pointer) + "\n", encoding="utf-8") - - with pytest.raises(ManifestValidationError, match="canonical attempt manifest"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert old.manifest_path.is_file() - assert current.manifest_path.is_file() - - -def test_symlinked_cell_root_fails_closed_for_read_and_cleanup(tmp_path: Path) -> None: - store = _store(tmp_path) - external = tmp_path / "escaped-cell" - external.mkdir() - cell_root = store._cell_root("cell") - cell_root.symlink_to(external, target_is_directory=True) - - with pytest.raises(ManifestValidationError, match="cell root is a symbolic link"): - store.load_current("cell", missing_ok=True) - with pytest.raises(ManifestValidationError, match="cell root is a symbolic link"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert tuple(external.iterdir()) == () - - -def test_symlinked_current_pointer_fails_closed_for_read_and_cleanup( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - current = _publish_with_payload(store, "cell", "current") - pointer = store._cell_root("cell") / "current.json" - external = tmp_path / "escaped-current.json" - pointer.replace(external) - pointer.symlink_to(external) - - with pytest.raises(ManifestValidationError, match="pointer is a symbolic link"): - store.load_current("cell") - with pytest.raises(ManifestValidationError, match="pointer is a symbolic link"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert current.manifest_path.is_file() - - -def test_symlinked_current_manifest_fails_closed_for_read_and_cleanup( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - current = _publish_with_payload(store, "cell", "current") - external = tmp_path / "escaped-manifest.json" - current.manifest_path.replace(external) - current.manifest_path.symlink_to(external) - - with pytest.raises(ManifestValidationError, match="manifest_path is not a regular"): - store.load_current("cell") - with pytest.raises(ManifestValidationError, match="manifest_path is not a regular"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert old.manifest_path.is_file() - - -def test_attempt_history_collision_prevents_cleanup(tmp_path: Path) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - _publish_with_payload(store, "cell", "current") - collision = store._attempt_history_cell_root("cell") / old.attempt_id - collision.mkdir(parents=True) - - with pytest.raises(ArtifactStoreError, match="history collision"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert old.manifest_path.is_file() - - -def test_catalog_reconciliation_is_bounded_and_preserves_current( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - old = _publish_with_payload(service.store, cell.cell_id, "old") - current = _publish_with_payload(service.store, cell.cell_id, "current") - - assert reconcile_attempt_history(service, (cell,)) == () - assert service.store.load_current(cell.cell_id).attempt_id == current.attempt_id - assert not old.manifest_path.exists() - assert ( - service.store._attempt_history_cell_root(cell.cell_id) - / old.attempt_id - / "manifest.json" - ).is_file() - - -def test_scheduler_runs_cleanup_after_each_cell( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - old = _publish_with_payload(service.store, cell.cell_id, "old") - current = _publish_with_payload(service.store, cell.cell_id, "current") - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - source_identity_override=ReportSourceIdentity("a" * 40, "b" * 40, ()), - remove_heavy_attempt_artifacts=True, - ), - ) - monkeypatch.setattr( - scheduler, - "_run_cell_in_lane", - lambda _planned: CellOutcome(cell.cell_id, "reused", current.attempt_id), - ) - - outcome = scheduler._run_cell(PlannedCell(cell, False, None, 0)) - - assert outcome.status == "reused" - assert not old.manifest_path.exists() - assert service.store.load_current(cell.cell_id).attempt_id == current.attempt_id - - -@pytest.mark.parametrize( - ("extra_arguments", "cleanup_expected"), - ( - ((), True), - (("--cleanup-artifacts",), True), - (("--retain-workspaces",), False), - ), -) -def test_all_recycled_run_applies_selected_startup_cleanup_policy( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - extra_arguments: tuple[str, ...], - cleanup_expected: bool, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - old = _publish_with_payload(service.store, cell.cell_id, "old") - current = _publish_with_payload(service.store, cell.cell_id, "current") - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - lightweight_result = { - "status": "ok", - "provenance": {"report_source_revision": source.revision}, - } - lightweight = LightweightCurrent( - cell.cell_id, - current.attempt_id, - current.result_path, - lightweight_result, - True, - True, - "reusable", - current, - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: {cell.cell_id: lightweight}, - ) - monkeypatch.setattr(manual_campaign, "plan_campaign", lambda *_a, **_k: ()) - monkeypatch.setattr( - manual_campaign, - "require_measurement_ready", - lambda _source: None, - ) - monkeypatch.setattr( - manual_campaign, - "update_source_marker", - lambda *_args, **_kwargs: False, - ) - arguments = manual_campaign.build_parser().parse_args( - ( - "run", - "--no-dashboard", - "--cell-id", - cell.cell_id, - *extra_arguments, - ) - ) - - exit_code = manual_campaign._run_campaign( - arguments, - repo_root=tmp_path, - service=service, - source=source, - cells=(cell,), - palette=manual_campaign.Palette(False), - ) - - assert exit_code == 0 - assert old.manifest_path.exists() is not cleanup_expected - assert service.store.load_current(cell.cell_id).attempt_id == current.attempt_id - - -def test_immediate_scheduler_preflight_error_preserves_previous_summary( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - summary, _counts = manual_campaign._publish_campaign_summary_ids( - service, - {"error": {"previous-cell"}}, - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: {}, - ) - monkeypatch.setattr( - manual_campaign, - "plan_campaign", - lambda *_args, **_kwargs: (PlannedCell(cell, False, None, 0),), - ) - monkeypatch.setattr( - manual_campaign, - "_bind_original_amplicol_if_required", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr(manual_campaign, "require_measurement_ready", lambda _s: None) - monkeypatch.setattr(manual_campaign, "update_source_marker", lambda *_a: False) - monkeypatch.setattr( - manual_campaign, - "reconcile_attempt_history", - lambda *_args, **_kwargs: (), - ) - - class ImmediateFailureScheduler: - def __init__(self, *_args: object, **_kwargs: object) -> None: - pass - - def run(self, _planned: object) -> CampaignResult: - raise RuntimeError("plan preflight failed before dispatch") - - monkeypatch.setattr( - manual_campaign, - "CampaignScheduler", - ImmediateFailureScheduler, - ) - arguments = manual_campaign.build_parser().parse_args( - ("run", "--no-dashboard", "--cell-id", cell.cell_id) - ) - - with pytest.raises(RuntimeError, match="before dispatch"): - manual_campaign._run_campaign( - arguments, - repo_root=tmp_path, - service=service, - source=source, - cells=(cell,), - palette=manual_campaign.Palette(False), - ) - - assert (summary / "error.txt").read_text(encoding="utf-8") == ( - "previous-cell\n" - ) - assert tuple(path.name for path in summary.iterdir()) == ("error.txt",) - - -def test_fail_fast_first_failure_stops_later_scheduler_dispatch_and_exits_nonzero( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - service = _service(tmp_path) - cells = tuple( - REPORT_CATALOG.cell( - f"matrix-recurrence-builtin-sm-lc-n{n_final}-dd-z-jets-selected-flow" - ) - for n_final in (1, 2, 3) - ) - planned = tuple( - PlannedCell(cell, dependency=False, baseline_cell_id=None, rank=index) - for index, cell in enumerate(cells) - ) - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - dispatched: list[str] = [] - - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: {}, - ) - monkeypatch.setattr( - manual_campaign, - "plan_campaign", - lambda *_args, **_kwargs: planned, - ) - monkeypatch.setattr( - manual_campaign, - "_bind_original_amplicol_if_required", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr(manual_campaign, "require_measurement_ready", lambda _s: None) - monkeypatch.setattr( - manual_campaign, - "update_source_marker", - lambda *_args, **_kwargs: False, - ) - - def terminal_failure( - _scheduler: CampaignScheduler, - item: PlannedCell, - ) -> CellOutcome: - dispatched.append(item.cell.cell_id) - return CellOutcome( - item.cell.cell_id, - "validation_failed", - "first exact failure", - terminal_detail="independent audit mismatch", - ) - - monkeypatch.setattr(CampaignScheduler, "_run_cell_in_lane", terminal_failure) - arguments = manual_campaign.build_parser().parse_args( - ( - "run", - "--fail-fast", - "--no-dashboard", - "--workers", - "1", - "--cell-id", - *(cell.cell_id for cell in cells), - ) - ) - arguments._campaign_invocation_command = ( - "steer_performance_campaign.py run --fail-fast --no-dashboard --workers 1" - ) - - exit_code = manual_campaign._run_campaign( - arguments, - repo_root=tmp_path, - service=service, - source=source, - cells=cells, - palette=manual_campaign.Palette(False), - ) - - assert exit_code == 1 - assert dispatched == [cells[0].cell_id] - summary_path = service.paths.docs_dir / "campaign_summary_ids" - report_path = summary_path / manual_campaign.FAIL_FAST_FAILURE_LOG - assert report_path.is_file() - report = report_path.read_text(encoding="utf-8") - assert f"cell_id: {cells[0].cell_id}" in report - assert "terminal_status: validation_failed" in report - assert "outcome_detail: first exact failure" in report - assert "terminal_detail: independent audit mismatch" in report - assert "attempt_uuid: " in report - assert not any(cell.cell_id in report for cell in cells[1:]) - assert (summary_path / "validation_failed.txt").read_text( - encoding="utf-8" - ) == f"{cells[0].cell_id}\n" - captured = capsys.readouterr() - assert "Fail-fast stopped dispatch" in captured.err - assert str(report_path) in captured.err - - -def test_concurrent_summary_publications_are_each_coherent(tmp_path: Path) -> None: - service = _service(tmp_path) - barrier = threading.Barrier(3) - errors: list[BaseException] = [] - - def publish(status: str, cell_id: str) -> None: - try: - barrier.wait(timeout=5) - manual_campaign._publish_campaign_summary_ids( - service, - {status: {cell_id}}, - ) - except BaseException as error: - errors.append(error) - - threads = ( - threading.Thread(target=publish, args=("error", "cell-error")), - threading.Thread( - target=publish, - args=("memory_limit", "cell-memory"), - ), - ) - for thread in threads: - thread.start() - barrier.wait(timeout=5) - for thread in threads: - thread.join(timeout=5) - - assert not errors - assert all(not thread.is_alive() for thread in threads) - summary = service.paths.docs_dir / "campaign_summary_ids" - files = tuple(summary.iterdir()) - assert len(files) == 1 - assert (files[0].name, files[0].read_text(encoding="utf-8")) in { - ("error.txt", "cell-error\n"), - ("memory_limit.txt", "cell-memory\n"), - } - assert not tuple(summary.parent.glob(".campaign_summary_ids.*")) - - -def test_scheduler_cleanup_flag_defaults_on_and_invocation_is_validated() -> None: - assert CampaignSettings().remove_heavy_attempt_artifacts is True - settings = CampaignSettings(campaign_invocation_id="abc") - assert settings.campaign_invocation_id == "abc" - with pytest.raises(ValueError, match="campaign_invocation_id"): - CampaignSettings(campaign_invocation_id="bad\nvalue") - - -def test_compact_attempt_inventory_excludes_only_heavy_artifact(tmp_path: Path) -> None: - root = tmp_path / "attempt" - (root / "artifact/nested").mkdir(parents=True) - (root / "artifact/nested/data.bin").write_bytes(b"heavy") - (root / "worker.log").write_text("diagnostic\n", encoding="utf-8") - (root / "worker-progress.jsonl").write_text("{}\n", encoding="utf-8") - - assert _attempt_files(root, include_heavy_artifact=False) == ( - "worker-progress.jsonl", - "worker.log", - ) - assert "artifact/nested/data.bin" in _attempt_files(root) - - -def test_manual_campaign_defaults_to_compact_artifacts() -> None: - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - default_arguments = manual_campaign.build_parser().parse_args(("run", "--dry-run")) - cleanup_arguments = manual_campaign.build_parser().parse_args( - ("run", "--dry-run", "--cleanup-artifacts") - ) - fail_fast_cleanup_arguments = manual_campaign.build_parser().parse_args( - ("run", "--dry-run", "--fail-fast", "--cleanup-artifacts") - ) - retained_arguments = manual_campaign.build_parser().parse_args( - ("run", "--dry-run", "--retain-workspaces") - ) - - assert manual_campaign._campaign_settings( - default_arguments, source - ).remove_heavy_attempt_artifacts - assert not manual_campaign._campaign_settings( - default_arguments, source - ).discard_cancelled_attempts - assert manual_campaign._campaign_settings( - cleanup_arguments, source - ).remove_heavy_attempt_artifacts - fail_fast_settings = manual_campaign._campaign_settings( - fail_fast_cleanup_arguments, - source, - ) - assert fail_fast_settings.remove_heavy_attempt_artifacts - assert not fail_fast_settings.discard_cancelled_attempts - retained_settings = manual_campaign._campaign_settings( - retained_arguments, - source, - ) - assert retained_settings.retain_workspaces - assert not retained_settings.remove_heavy_attempt_artifacts - - -@pytest.mark.parametrize( - ("extra_arguments", "expected"), - ( - ((), "compact retention (default)"), - (("--cleanup-artifacts",), "compact retention (default)"), - ( - ("--fail-fast", "--cleanup-artifacts"), - "compact retention (default)", - ), - (("--retain-workspaces",), "full debug workspaces (--retain-workspaces)"), - ), -) -def test_dry_run_prints_effective_artifact_cleanup_policy( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], - extra_arguments: tuple[str, ...], - expected: str, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - source = ReportSourceIdentity("a" * 40, "b" * 40, ()) - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_a, **_k: {}, - ) - monkeypatch.setattr(manual_campaign, "plan_campaign", lambda *_a, **_k: ()) - monkeypatch.setattr( - manual_campaign, - "_dry_run_recipe_blocks", - lambda *_args, **_kwargs: (), - ) - arguments = manual_campaign.build_parser().parse_args( - ( - "run", - "--dry-run", - "--no-color", - "--cell-id", - cell.cell_id, - *extra_arguments, - ) - ) - - assert ( - manual_campaign._run_campaign( - arguments, - repo_root=tmp_path, - service=service, - source=source, - cells=(cell,), - palette=manual_campaign.Palette(False), - ) - == 0 - ) - - assert expected in capsys.readouterr().out - assert not ( - service.paths.docs_dir - / "campaign_summary_ids" - / manual_campaign.FAIL_FAST_FAILURE_LOG - ).exists() - - -def test_cleanup_skips_busy_owner_use_lock(tmp_path: Path) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - _publish_with_payload(store, "cell", "current") - acquired = threading.Event() - release = threading.Event() - - def hold() -> None: - with store.named_lock(f"campaign-artifact-use-{old.attempt_id}"): - acquired.set() - assert release.wait(timeout=5) - - thread = threading.Thread(target=hold) - thread.start() - assert acquired.wait(timeout=5) - try: - assert store.archive_obsolete_attempts( - "cell", consumer_cell_ids=("cell",) - ) == () - assert old.manifest_path.is_file() - finally: - release.set() - thread.join(timeout=5) - assert not thread.is_alive() - - -def test_unsafe_heavy_payload_fails_closed_before_attempt_move(tmp_path: Path) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - _publish_with_payload(store, "cell", "current") - (old.manifest_path.parent / "artifact/unsafe-link").symlink_to(tmp_path) - - with pytest.raises(ArtifactStoreError, match="unsafe member"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert old.manifest_path.is_file() - assert store.load_current("cell") is not None - - -def test_unsafe_root_diagnostic_fails_closed_before_attempt_move( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - _publish_with_payload(store, "cell", "current") - worker_log = old.manifest_path.parent / "worker.log" - worker_log.unlink() - worker_log.symlink_to(tmp_path / "outside.log") - - with pytest.raises(ArtifactStoreError, match="unsafe member"): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert old.manifest_path.is_file() - assert worker_log.is_symlink() - assert store.load_current("cell") is not None - - -def test_atomic_report_write_normalizes_enospc( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - destination = tmp_path / "result.json" - - def no_space(_source: object, _destination: object) -> None: - raise OSError(errno.ENOSPC, "no space left") - - monkeypatch.setattr(artifacts_module.os, "replace", no_space) - with pytest.raises(DiskFullError, match=r"disk full while writing .*result.json"): - artifacts_module._atomic_write_json(destination, {"status": "ok"}) - - -def test_attempt_archive_normalizes_enospc_without_moving_source( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - store = _store(tmp_path) - old = _publish_with_payload(store, "cell", "old") - _publish_with_payload(store, "cell", "current") - - def no_space(_source: object, _destination: object) -> None: - raise OSError(errno.ENOSPC, "no space left") - - monkeypatch.setattr(artifacts_module.os, "replace", no_space) - with pytest.raises( - DiskFullError, - match=r"disk full while writing .*attempt-history", - ): - store.archive_obsolete_attempts("cell", consumer_cell_ids=("cell",)) - - assert old.manifest_path.is_file() - - -def test_summary_publication_normalizes_enospc( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - - def no_space(_source: object, _destination: object) -> None: - raise OSError(errno.ENOSPC, "no space left") - - monkeypatch.setattr(manual_campaign.os, "replace", no_space) - with pytest.raises( - DiskFullError, - match=r"disk full while writing .*campaign_summary_ids", - ): - manual_campaign._publish_campaign_summary_ids( - service, - {"error": {"cell"}}, - ) - - publication_root = ( - service.paths.coordination_root / "campaign-summary-publication" - ) - assert tuple(publication_root.iterdir()) == () - - -def test_controller_atomic_json_normalizes_enospc_with_target_and_free_bytes( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - destination = tmp_path / "worker-result.json" - - def no_space(_source: object, _destination: object) -> None: - raise OSError(errno.ENOSPC, "no space left") - - monkeypatch.setattr(manual_campaign.os, "replace", no_space) - with pytest.raises( - DiskFullError, - match=( - r"disk full while writing .*worker-result\.json; " - r"[0-9]+ bytes available" - ), - ): - manual_campaign._atomic_json(destination, {"status": "error"}) - - assert not destination.exists() - assert not tuple(tmp_path.glob(".worker-result.json.*.tmp")) - - -def test_scheduler_archive_helper_uses_catalog_equivalence(tmp_path: Path) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - old = _publish_with_payload(service.store, cell.cell_id, "old") - _publish_with_payload(service.store, cell.cell_id, "current") - - assert archive_cell_attempt_history(service, cell) == (old.attempt_id,) diff --git a/pyamplicol/tests/unit/test_manual_performance_campaign.py b/pyamplicol/tests/unit/test_manual_performance_campaign.py deleted file mode 100644 index 7c39f999b1..0000000000 --- a/pyamplicol/tests/unit/test_manual_performance_campaign.py +++ /dev/null @@ -1,6415 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import ast -import base64 -import io -import json -import os -import shutil -import struct -import subprocess -import sys -import threading -import time -import tomllib -from pathlib import Path - -import pytest - -import tools.performance_report.manual_campaign as manual_campaign -import tools.performance_report.workspace as workspace_module -from tools.performance_report.artifacts import LockCancelledError -from tools.performance_report.cache import empty_measurement -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.manual_campaign import ( - DEFAULT_MANUAL_EXPECTED_PAGE_COUNT, - MANUAL_STATE_SCHEMA, - Comparison, - DashboardState, - LeaseManager, - LightweightCurrent, - ManualCampaignError, - ReproductionSettings, - WorkerView, - _handle_dashboard_key, - _index_metadata_dirty_paths, - _install_report_snapshot, - _live_dashboard_snapshot, - _manual_static_na_reason, - _merge_lightweight_snapshot, - _progress_detail_summary, - _result_matches_cell, - _snapshot_fixture, - _tail_progress, - build_parser, - comparison_statistics, - render_dashboard_frame, - reproduction_recipe, - selection_from_arguments, -) -from tools.performance_report.manual_campaign import main as campaign_main -from tools.performance_report.models import ( - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from tools.performance_report.publication import ( - PublicationPortabilityError, - portable_publication_value, -) -from tools.performance_report.publisher import _compile_pdf -from tools.performance_report.scheduler import CellOutcome, _CoordinationDeferred -from tools.performance_report.service import ReportPaths, ReportService - -ROOT = Path(__file__).resolve().parents[2] -PROFILE = ROOT / "src/pyamplicol/_profiling_campaign" -CAMPAIGN_ARTIFACT_ROOT = PROFILE / "campaign_artifacts" - - -@pytest.fixture -def repository_with_cli(tmp_path: Path) -> Path: - repository = tmp_path / "repository" - (repository / "src/pyamplicol").mkdir(parents=True) - executable = repository / ".venv/bin/pyamplicol" - executable.parent.mkdir(parents=True) - executable.touch() - return repository - - -def _parse(*arguments: str): - return build_parser().parse_args(arguments) - - -def test_campaign_state_roots_are_local_and_isolated_by_full_destination( - tmp_path: Path, -) -> None: - first_docs = tmp_path / "first" / "same-name" - second_docs = tmp_path / "second" / "same-name" - first_docs.mkdir(parents=True) - second_docs.mkdir(parents=True) - - first = manual_campaign._campaign_report_paths(ROOT, first_docs) - second = manual_campaign._campaign_report_paths(ROOT, second_docs) - - assert first.docs_dir == first_docs.resolve() - assert first.artifact_root == first_docs.resolve() / "campaign_artifacts" - assert first.coordination_root == first.artifact_root / "coordination" - assert second.artifact_root == second_docs.resolve() / "campaign_artifacts" - assert first.artifact_root != second.artifact_root - first_service = ReportService(first, portable_current_results=True) - second_service = ReportService(second, portable_current_results=True) - with ( - first_service.store.named_lock("same-cell", timeout=0.0), - second_service.store.named_lock("same-cell", timeout=0.0), - ): - pass - attempt = first_service.store.new_attempt( - "same-cell", - manual_campaign.ArtifactPolicy.REGENERATE, - ) - attempt.publish({"status": "ok"}) - assert first_service.store.load_current("same-cell") is not None - assert second_service.store.load_current("same-cell", missing_ok=True) is None - assert ( - second_service.store.lightweight_current_payload( - "same-cell", - missing_ok=True, - ) - is None - ) - - legacy_store = manual_campaign.ArtifactStore( - artifact_root=tmp_path / ".artifacts/performance-report/same-name", - lock_root=tmp_path / ".artifacts/performance-report-coordination/same-name", - ) - legacy_attempt = legacy_store.new_attempt( - "legacy-cell", - manual_campaign.ArtifactPolicy.REGENERATE, - ) - legacy_attempt.publish({"status": "ok"}) - assert first_service.store.load_current("legacy-cell", missing_ok=True) is None - assert second_service.store.load_current("legacy-cell", missing_ok=True) is None - assert not (first_docs / ".artifacts").exists() - assert not (second_docs / ".artifacts").exists() - - -def test_campaign_state_root_is_created_fresh_when_absent(tmp_path: Path) -> None: - docs = tmp_path / "campaign" - docs.mkdir() - assert not (docs / "campaign_artifacts").exists() - - paths = manual_campaign._campaign_report_paths(ROOT, docs) - ReportService(paths) - - assert paths.artifact_root == docs / "campaign_artifacts" - assert paths.coordination_root == docs / "campaign_artifacts/coordination" - assert (paths.artifact_root / "cells").is_dir() - assert paths.coordination_root.is_dir() - assert not (docs / ".artifacts").exists() - - -@pytest.mark.parametrize("member", ("campaign_artifacts", "coordination")) -def test_campaign_state_rejects_symlinked_private_directories( - tmp_path: Path, - member: str, -) -> None: - docs = tmp_path / "campaign" - docs.mkdir() - outside = tmp_path / "outside" - outside.mkdir() - if member == "campaign_artifacts": - (docs / member).symlink_to(outside, target_is_directory=True) - else: - state = docs / "campaign_artifacts" - state.mkdir() - (state / member).symlink_to(outside, target_is_directory=True) - - with pytest.raises(ManualCampaignError, match="must not be a symbolic link"): - manual_campaign._campaign_report_paths(ROOT, docs) - - -def test_campaign_state_rejects_special_private_member(tmp_path: Path) -> None: - docs = tmp_path / "campaign" - docs.mkdir() - (docs / "campaign_artifacts").write_text("not a directory\n", encoding="ascii") - - with pytest.raises(ManualCampaignError, match="must be a directory"): - manual_campaign._campaign_report_paths(ROOT, docs) - - -def test_campaign_state_rejects_symlinked_campaign_directory(tmp_path: Path) -> None: - actual = tmp_path / "actual" - actual.mkdir() - linked = tmp_path / "campaign" - linked.symlink_to(actual, target_is_directory=True) - - with pytest.raises(ManualCampaignError, match="must not be a symbolic link"): - manual_campaign._campaign_report_paths(ROOT, linked) - - -@pytest.mark.parametrize("pwd_state", ("unset", "renamed-away", "recreated")) -def test_existing_relative_launcher_rejects_stale_pwd_before_campaign_paths( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], - pwd_state: str, -) -> None: - original = tmp_path / "campaign" - original.mkdir() - moved = tmp_path / "renamed-campaign" - original.rename(moved) - if pwd_state == "recreated": - original.mkdir() - monkeypatch.chdir(moved) - if pwd_state == "unset": - monkeypatch.delenv("PWD", raising=False) - else: - monkeypatch.setenv("PWD", str(original)) - monkeypatch.setattr(sys, "argv", ["./steer_performance_campaign.py"]) - monkeypatch.setattr( - manual_campaign, - "_campaign_report_paths", - lambda *_args, **_kwargs: pytest.fail( - "stale relative launcher opened campaign paths" - ), - ) - - assert ( - campaign_main( - ("dashboard-snapshot", "--width", "80", "--height", "24"), - repo_root=ROOT, - docs_dir=moved, - ) - == 2 - ) - assert "cd .." in capsys.readouterr().err - - -@pytest.mark.parametrize("checked_absolute", (False, True)) -def test_campaign_controller_allows_matching_or_checked_launcher_invocation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - checked_absolute: bool, -) -> None: - docs = tmp_path / "campaign" - docs.mkdir() - monkeypatch.chdir(docs) - monkeypatch.setenv( - "PWD", - str(tmp_path / "different-directory" if checked_absolute else docs), - ) - invocation = ( - docs / "steer_performance_campaign.py" - if checked_absolute - else Path("./steer_performance_campaign.py") - ) - monkeypatch.setattr(sys, "argv", [os.fspath(invocation)]) - - assert ( - campaign_main( - ("dashboard-snapshot", "--width", "80", "--height", "24"), - repo_root=ROOT, - docs_dir=docs, - launcher_path_checked=checked_absolute, - ) - == 0 - ) - - -@pytest.mark.parametrize("replacement", (False, True)) -def test_old_absolute_launcher_reexecution_rejects_stale_pwd_by_default( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], - replacement: bool, -) -> None: - original = tmp_path / "campaign" - original.mkdir() - moved = tmp_path / "renamed-campaign" - original.rename(moved) - if replacement: - original.mkdir() - monkeypatch.chdir(moved) - monkeypatch.setenv("PWD", str(original)) - monkeypatch.setattr( - sys, - "argv", - [os.fspath(moved / "steer_performance_campaign.py")], - ) - monkeypatch.setattr( - manual_campaign, - "_campaign_report_paths", - lambda *_args, **_kwargs: pytest.fail( - "old absolute launcher opened campaign paths after stale re-exec" - ), - ) - - assert ( - campaign_main( - ("dashboard-snapshot", "--width", "80", "--height", "24"), - repo_root=ROOT, - docs_dir=moved, - ) - == 2 - ) - assert "cd .." in capsys.readouterr().err - - -def test_campaign_command_holds_shared_destination_lock( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import fcntl - - docs = tmp_path / "campaign" - docs.mkdir() - original_fixture = manual_campaign._snapshot_fixture - - def assert_locked() -> DashboardState: - descriptor = os.open( - docs, - os.O_RDONLY | getattr(os, "O_DIRECTORY", 0), - ) - try: - with pytest.raises(BlockingIOError): - fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB) - finally: - os.close(descriptor) - return original_fixture() - - monkeypatch.setattr(manual_campaign, "_snapshot_fixture", assert_locked) - - assert ( - campaign_main( - ("dashboard-snapshot", "--width", "80", "--height", "24"), - repo_root=ROOT, - docs_dir=docs, - ) - == 0 - ) - - -def test_catalog_and_fresh_profile_are_complete_but_measurement_empty() -> None: - assert len(REPORT_CATALOG.measurement_cells()) == 2198 - assert PROFILE.is_dir() - assert not (PROFILE / "pyAmpliCol.pdf").exists() - assert not any(PROFILE.rglob("current.json")) - assert not any(PROFILE.rglob("manifest.json")) - assert not any(PROFILE.rglob("*.sha256")) - old_profile = ROOT / "docs/performance_reports/macbook_M3" - assert old_profile.resolve() != PROFILE.resolve() - - -def test_selector_repetition_wildcard_aliases_and_intersection() -> None: - arguments = _parse( - "run", - "--dry-run", - "--multiplicity", - "3", - "--multiplicity", - "4", - "--model", - "built-in", - "sm_ufo", - "--color-approximation", - "LC", - "--generation-mode", - "union-flow", - "--generation-engine", - "recurrence", - ) - _selection, cells = selection_from_arguments(arguments) - assert cells - assert {cell.n_final for cell in cells} == {3, 4} - assert {cell.measurement.model for cell in cells} == { - ModelKey.BUILTIN_SM, - ModelKey.UFO_SM, - } - assert {cell.workload for cell in cells} == {Workload.ALL_FLOW} - assert {cell.measurement.execution_mode for cell in cells} == { - ExecutionMode.RECURRENCE - } - - all_arguments = _parse("inspect", "--table", "*", "--model", "all") - _all_selection, all_cells = selection_from_arguments(all_arguments) - assert len(all_cells) == 2198 - - -def test_variant_filter_keeps_unvaried_matrix_rows_in_a_broad_selection() -> None: - arguments = _parse( - "run", - "--dry-run", - "--multiplicity", - "8", - "9", - "--generation-engine", - "amplicol", - "recurrence", - "compiled", - "--variant", - "recurrence_jit_o2", - "jit_o3", - ) - _selection, cells = selection_from_arguments(arguments) - - assert { - "reference_amplicol_lc", - "matrix_recurrence_builtin_sm_lc", - "matrix_compiled_builtin_sm_lc", - }.issubset({cell.dataset_id for cell in cells}) - assert all(cell.variant in {None, "recurrence_jit_o2", "jit_o3"} for cell in cells) - - -def test_matrix_best_is_all_four_builtin_candidate_modes() -> None: - arguments = _parse("inspect", "--table", "matrix_best") - _selection, cells = selection_from_arguments(arguments) - assert len(cells) == 1108 - assert {cell.measurement.execution_mode for cell in cells} == { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - } - assert {cell.measurement.model for cell in cells} == {ModelKey.BUILTIN_SM} - - -def test_process_id_15_selector_targets_only_identical_quark_line_cells() -> None: - arguments = _parse( - "inspect", - "--process-id", - "15", - "--multiplicity", - "4", - "--generation-engine", - "recurrence", - "--model", - "builtin_sm", - ) - _selection, cells = selection_from_arguments(arguments) - - assert len(cells) == 4 - assert {cell.process_key for cell in cells} == {"dd_3q_identical_lines"} - assert {cell.process for cell in cells} == {"d d~ > u u~ u u~"} - assert {cell.n_final for cell in cells} == {4} - - -def test_builtin_model_and_table_aliases_handle_amplicol_references() -> None: - built_in = _parse( - "inspect", - "--model", - "built_in", - "--generation-engine", - "amplicol", - ) - _selection, cells = selection_from_arguments(built_in) - assert cells - assert all( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL for cell in cells - ) - - z_reference = _parse( - "inspect", - "--table", - "z_table", - "--generation-engine", - "amplicol", - ) - _selection, cells = selection_from_arguments(z_reference) - assert cells - assert {cell.process_key for cell in cells} == {"dd_z_jets"} - assert {cell.workload for cell in cells} == {Workload.SELECTED_FLOW} - - -def test_valid_but_empty_selector_has_concise_error() -> None: - arguments = _parse( - "inspect", - "--color-approximation", - "nlc", - "--generation-mode", - "union-flow", - ) - with pytest.raises(ManualCampaignError, match="selector intersection"): - selection_from_arguments(arguments) - - -def test_invalid_selector_lists_allowed_values_and_suggestion() -> None: - arguments = _parse("inspect", "--generation-engine", "recurrance") - with pytest.raises(ManualCampaignError, match="did you mean recurrence"): - selection_from_arguments(arguments) - - -def test_help_is_exhaustive_and_run_defaults_match_contract() -> None: - parser = build_parser() - help_text = parser.format_help() - for fragment in ( - "Steering model", - "pyamplicol generate", - "pyamplicol profile", - "dashboard-snapshot", - "refresh-pdf", - "matrix_recurrence_ufo_sm_lc", - "Inspect coverage", - "cannot fit the 1-GiB envelope", - "C++/ASM variants above", - "Keyboard controls", - "current/contribution counts", - "process-tree current/peak usage", - "--continue-across-revisions", - "--cell-id-file", - "--cleanup-artifacts", - "--retain-workspaces", - "--attempt-output-limit", - "--minimum-free-disk", - "`unverified.txt` needs no `--force-refresh`", - "bounded log tails", - "sealed with compact diagnostics", - "--no-dependencies-added", - "--list-sections", - "--remove-sections", - "dependency-only work", - "original-AmpliCol diagnostic, recurrence authority", - "quoted `*`", - ): - assert fragment in help_text - run_help = parser._subparsers._group_actions[0].choices["run"].format_help() - assert "Process family number 1..15" in run_help - assert "automatically added diagnostic dependency" in run_help - assert "recurrence remains available" in run_help - assert "Hard construction" in run_help - assert "Omitted or '*' engine" in run_help - assert "--madgraph" in run_help - assert "--campaign-ram-limit" in run_help - assert "Optional decimal RAM ceiling across all concurrent" in run_help - assert "--no-artifacts-removal" not in help_text - arguments = _parse("run", "--dry-run") - assert arguments.workers == 1 - assert arguments.cores_per_worker == 1 - assert arguments.amplicol_build_jobs == 1 - assert arguments.generation_time_limit == 3600.0 - assert arguments.ram_limit == 30_000_000_000 - assert arguments.campaign_ram_limit is None - assert arguments.attempt_output_limit == 64 * 1024 * 1024 - assert arguments.minimum_free_disk == 5 * 1024 * 1024 * 1024 - assert arguments.worker_wall_limit == 3600.0 - assert arguments.no_color is False - assert arguments.force_refresh is False - assert arguments.continue_across_revisions is False - assert arguments.no_dependencies_added is False - assert arguments.cleanup_artifacts is False - assert arguments.retain_workspaces is False - assert arguments.madgraph is None - assert _parse("run", "--no-dependencies-added").no_dependencies_added is True - assert _parse("run", "--cleanup-artifacts").cleanup_artifacts is True - assert manual_campaign._artifact_cleanup_enabled(arguments) is True - retained = _parse("run", "--retain-workspaces") - assert retained.retain_workspaces is True - assert manual_campaign._artifact_cleanup_enabled(retained) is False - assert _parse("run", "--continue-across-revisions").continue_across_revisions - source = manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()) - settings = manual_campaign._campaign_settings( - arguments, - source, - original_amplicol_available=True, - ) - assert settings.amplicol_build_jobs == 1 - parallel_native = _parse( - "run", - "--dry-run", - "--cores-per-worker", - "4", - "--amplicol-build-jobs", - "2", - "--allow-oversubscription", - ) - parallel_settings = manual_campaign._campaign_settings( - parallel_native, - source, - original_amplicol_available=True, - ) - assert parallel_settings.cell_cores == 4 - assert parallel_settings.amplicol_build_jobs == 2 - assert settings.add_optional_dependencies is True - assert settings.original_amplicol_available is True - opt_out_settings = manual_campaign._campaign_settings( - _parse("run", "--dry-run", "--no-dependencies-added"), - source, - original_amplicol_available=True, - ) - assert opt_out_settings.add_optional_dependencies is False - unvalidated_legacy = manual_campaign._campaign_settings( - _parse("run", "--dry-run", "--original-amplicol", "/tmp/legacy"), - source, - original_amplicol_available=True, - ) - assert unvalidated_legacy.original_amplicol_available is True - assert unvalidated_legacy.original_amplicol_repository is None - madgraph = Path("/tmp/madgraph") - madgraph_settings = manual_campaign._campaign_settings( - _parse("run", "--dry-run", "--madgraph", str(madgraph)), - source, - ) - assert madgraph_settings.madgraph_installation == madgraph - refresh = _parse("refresh-pdf") - assert refresh.expected_page_count is None - assert refresh.quiet is False - assert refresh.list_sections is False - assert refresh.remove_sections is None - assert _parse("refresh-pdf", "--quiet").quiet is True - assert _parse("refresh-pdf", "--list-sections").list_sections is True - assert _parse( - "refresh-pdf", - "--remove-sections", - "worked-zgg", - "ufo-support", - ).remove_sections == ["worked-zgg", "ufo-support"] - with pytest.raises(SystemExit): - _parse( - "refresh-pdf", - "--list-sections", - "--remove-sections", - "scope", - ) - assert DEFAULT_MANUAL_EXPECTED_PAGE_COUNT == 73 - underscore = _parse("inspect", "--color_approximation", "lc") - _selection, cells = selection_from_arguments(underscore) - assert cells - assert {cell.measurement.accuracy.value for cell in cells} == {"lc"} - - -@pytest.mark.parametrize("value", ("0", "-1", "1.5")) -def test_campaign_ram_limit_requires_a_positive_integer(value: str) -> None: - with pytest.raises(SystemExit): - _parse("run", "--dry-run", "--campaign-ram-limit", value) - - -def test_campaign_ram_limit_conservatively_caps_ten_workers_and_provenance( - tmp_path: Path, -) -> None: - source = manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()) - arguments = _parse( - "run", - "--dry-run", - "--workers", - "10", - "--ram-limit", - "30000000000", - "--campaign-ram-limit", - "30000000000", - "--allow-oversubscription", - ) - settings = manual_campaign._campaign_settings(arguments, source) - - assert settings.max_rss_bytes == 30_000_000_000 - assert settings.campaign_max_rss_bytes == 30_000_000_000 - assert settings.attempt_output_limit_bytes == 64 * 1024 * 1024 - assert settings.minimum_free_disk_bytes == 5 * 1024 * 1024 * 1024 - assert settings.remove_heavy_attempt_artifacts is True - assert settings.retain_workspaces is False - assert settings.effective_cell_rss_limit() == 3_000_000_000 - assert settings.effective_cell_rss_limit() * settings.workers == ( - settings.campaign_max_rss_bytes - ) - - scheduler = manual_campaign.CampaignScheduler( - _manual_service(tmp_path), - settings=settings, - ) - assert scheduler._effective_cell_rss_limit() == 3_000_000_000 - result: dict[str, object] = {} - scheduler._attach_manual_provenance( - result, - cell=_presentation_test_cell(), - ) - provenance = result["provenance"] - assert isinstance(provenance, dict) - manual = provenance["manual_campaign"] - assert isinstance(manual, dict) - assert manual["memory_limit_bytes"] == 3_000_000_000 - assert manual["campaign_memory_limit_bytes"] == 30_000_000_000 - assert manual["workers"] == 10 - - -def test_colours_are_default_and_only_explicitly_disabled( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.delenv("NO_COLOR", raising=False) - arguments = _parse("inspect") - palette = manual_campaign.Palette( - manual_campaign._color_enabled(arguments), - ) - assert "\x1b[" in palette.key("profile") - assert "\x1b[" in palette.success("ok") - - no_colour = _parse("inspect", "--no-color") - assert not manual_campaign._color_enabled(no_colour) - assert manual_campaign.Palette(False).key("profile") == "profile" - - monkeypatch.setenv("NO_COLOR", "") - assert not manual_campaign._color_enabled(arguments) - monkeypatch.delenv("NO_COLOR") - assert not manual_campaign._color_enabled(arguments, json_output=True) - - -def test_refresh_list_sections_exits_before_campaign_or_source_reads( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - def forbidden(*_args: object, **_kwargs: object) -> object: - raise AssertionError("section listing touched campaign state") - - monkeypatch.setattr(manual_campaign, "_campaign_report_paths", forbidden) - monkeypatch.setattr(manual_campaign, "lightweight_source_identity", forbidden) - - assert ( - campaign_main( - ("refresh-pdf", "--list-sections", "--no-color"), - repo_root=tmp_path, - docs_dir=tmp_path / "campaign", - launcher_path_checked=True, - ) - == 0 - ) - output = capsys.readouterr().out - for section in manual_campaign.REPORT_SECTIONS: - assert section.identifier in output - assert section.title in output - - -def test_report_section_filter_changes_only_the_staged_master(tmp_path: Path) -> None: - source = PROFILE / "pyAmpliCol.tex" - original = source.read_text(encoding="utf-8") - staged = tmp_path / "pyAmpliCol.tex" - staged.write_text(original, encoding="utf-8") - removed = manual_campaign._selected_report_sections( - ("scalar-ladders", "worked-zgg", "scalar-ladders") - ) - - manual_campaign._filter_report_sections(staged, removed) - - filtered = staged.read_text(encoding="utf-8") - assert "\\section{Colour-Singlet Model Ladders}" not in filtered - assert "\\input{section_zgg_example.tex}" not in filtered - assert "\\input{section_three_mode_performance_tables.tex}" in filtered - assert "\\input{section_ufo_support.tex}" in filtered - assert "\\begin{thebibliography}{9}" in filtered - assert source.read_text(encoding="utf-8") == original - assert tuple(section.identifier for section in removed) == ( - "scalar-ladders", - "worked-zgg", - ) - - -def test_report_template_identifies_current_release() -> None: - release = tomllib.loads((ROOT / "Cargo.toml").read_text(encoding="utf-8"))[ - "workspace" - ]["package"]["version"] - source = (PROFILE / "pyAmpliCol.tex").read_text(encoding="utf-8") - - for expected in ( - f"pdftitle={{pyAmpliCol {release} Methodology and Performance Report}}", - f"{{pyAmpliCol {release}}}", - f"Release {release}", - rf"performance of \PAC{{}} {release}.", - ): - assert expected in source - normalized = " ".join(source.split()) - assert ( - "compiled, eager, recurrence, and on-the-fly evaluation across the " - "report's stated built-in Standard Model and UFO or serialized-JSON scopes" - in normalized - ) - assert "leading-colour on-the-fly" not in normalized - assert "the first three modes" not in normalized - - -def test_independently_removable_sections_leave_no_dangling_references() -> None: - assert r"\ref{sec:zgg-example}" not in ( - PROFILE / "section_zgg_dag.tex" - ).read_text(encoding="utf-8") - for source in ( - PROFILE / "section_zgg_example.tex", - PROFILE / "section_eager_execution.tex", - ): - assert r"\ref{sec:lc-flow-layouts}" not in source.read_text( - encoding="utf-8" - ) - - -def test_unknown_report_section_fails_before_pdf_work() -> None: - with pytest.raises(ManualCampaignError, match="--list-sections"): - manual_campaign._selected_report_sections(("not-a-section",)) - - -def test_lightweight_snapshot_reports_four_throttled_scan_stages( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cells = (object(), object()) - - class Catalog: - @staticmethod - def measurement_cells() -> tuple[object, ...]: - return cells - - class Service: - catalog = Catalog() - - class Sink: - def __init__(self) -> None: - self.events: list[tuple[object, ...]] = [] - - def begin( - self, - *, - total: int, - attempt: int, - maximum_attempts: int, - ) -> None: - self.events.append(("begin", total, attempt, maximum_attempts)) - - def update(self, completed: int, total: int, message: str) -> None: - self.events.append(("update", completed, total, message)) - - def end( - self, - *, - success: bool, - message: str, - elapsed_seconds: float, - ) -> None: - self.events.append(("end", success, message, elapsed_seconds)) - - def close(self) -> None: - self.events.append(("close",)) - - def scan( - *_args: object, - progress=None, - **_kwargs: object, - ) -> dict[str, object]: - if progress is not None: - for completed in range(1, len(cells) + 1): - progress(completed, len(cells)) - return {} - - monkeypatch.setattr(manual_campaign, "lightweight_currents", scan) - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcomes", - scan, - ) - sink = Sink() - - assert manual_campaign._capture_lightweight_snapshot( - Service(), # type: ignore[arg-type] - source_revision="a" * 40, - progress=sink, # type: ignore[arg-type] - ) == ({}, {}, ()) - - starts = [event for event in sink.events if event[0] == "begin"] - updates = [event for event in sink.events if event[0] == "update"] - ends = [event for event in sink.events if event[0] == "end"] - assert len(starts) == 1 - assert starts[0][1:] == (4 * len(cells), 1, 3) - assert {event[3] for event in updates} == { - "Reading current records", - "Reading terminal outcomes", - "Confirming current records", - "Confirming terminal outcomes", - } - assert max(int(event[1]) for event in updates) == 4 * len(cells) - assert len(ends) == 1 - assert ends[0][1] is True - assert ends[0][2] == "stable snapshot captured" - - -def test_refresh_scan_progress_is_coloured_and_closes_its_line() -> None: - stream = io.StringIO() - progress = manual_campaign._RefreshScanProgress( - stream, - manual_campaign.Palette(True), - ) - - progress.begin(total=8, attempt=1, maximum_attempts=3) - progress.update(4, 8, "Confirming current records") - progress.end(success=True, message="stable snapshot captured", elapsed_seconds=1.2) - - output = stream.getvalue() - assert "\x1b[" in output - assert "Scanning campaign artifacts" in output - assert "██████████████" in output - assert "4/8 Confirming current records" in output - assert output.endswith("\n") - - -def test_final_unstable_snapshot_reports_failure_instead_of_rescan( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cells = (object(),) - - class Catalog: - @staticmethod - def measurement_cells() -> tuple[object, ...]: - return cells - - class Service: - catalog = Catalog() - - class Current: - reusable = True - - def __init__(self, attempt_id: str) -> None: - self.attempt_id = attempt_id - - class Sink: - def __init__(self) -> None: - self.ends: list[tuple[bool, str]] = [] - - def begin(self, **_kwargs: object) -> None: - pass - - def update(self, *_args: object) -> None: - pass - - def end( - self, - *, - success: bool, - message: str, - elapsed_seconds: float, - ) -> None: - assert elapsed_seconds >= 0.0 - self.ends.append((success, message)) - - def close(self) -> None: - pass - - current_call = 0 - - def changing_currents(*_args: object, **_kwargs: object) -> dict[str, Current]: - nonlocal current_call - current_call += 1 - return {"cell": Current(f"attempt-{current_call}")} - - monkeypatch.setattr(manual_campaign, "lightweight_currents", changing_currents) - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcomes", - lambda *_args, **_kwargs: {}, - ) - sink = Sink() - - with pytest.raises(ManualCampaignError, match="changed during three"): - manual_campaign._capture_lightweight_snapshot( - Service(), # type: ignore[arg-type] - source_revision="a" * 40, - progress=sink, # type: ignore[arg-type] - ) - - assert sink.ends == [ - (True, "campaign state changed; rescanning"), - (True, "campaign state changed; rescanning"), - (False, "campaign state remained unstable after three scans"), - ] - - -def test_reproduction_recipe_uses_public_generate_and_profile( - repository_with_cli: Path, -) -> None: - repository = repository_with_cli - artifact_root = repository / "campaign_artifacts" - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.workload is Workload.ALL_FLOW - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - recipe = reproduction_recipe( - candidate, - repo_root=repository, - artifact_root=artifact_root, - ) - assert recipe.kind == "public-cli-template+model-compile-prerequisite" - assert recipe.prepare is not None - assert recipe.prepare[:5] == ( - "env", - f"PYTHONPATH={os.fspath((repository / 'src').resolve())}", - os.fspath((repository / ".venv/bin/pyamplicol").resolve()), - "model", - "compile", - ) - assert "built-in-sm" in recipe.prepare - assert recipe.generate is not None - assert recipe.generate[:4] == ( - "env", - f"PYTHONPATH={os.fspath((repository / 'src').resolve())}", - os.fspath((repository / ".venv/bin/pyamplicol").resolve()), - "generate", - ) - assert "--lc-flow-layout" in recipe.generate - assert "all-flow-union" in recipe.generate - assert recipe.profile is not None - assert recipe.profile[:4] == ( - "env", - f"PYTHONPATH={os.fspath((repository / 'src').resolve())}", - os.fspath((repository / ".venv/bin/pyamplicol").resolve()), - "profile", - ) - assert recipe.exact is False - assert "<" not in " ".join(recipe.profile) - - legacy = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - legacy_recipe = reproduction_recipe( - legacy, - repo_root=repository, - artifact_root=artifact_root, - ) - assert legacy_recipe.kind == "legacy-report-adapter" - assert legacy_recipe.generate is None - assert legacy_recipe.profile is None - assert legacy_recipe.exact is False - - -def test_reproduction_recipe_exposes_authenticated_reuse_off_fallback() -> None: - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - ) - fallback = { - "abi": "pyamplicol-numerical-current-reuse-fallback-v1", - "requested_mode": "certified-reuse", - "effective_mode": "off", - "effective_reuse_state": "disabled", - "reason": "evidence-envelope-fallback", - "geometry": { - "current_count": 4, - "component_count": 8, - "candidate_probe_count": 2, - "verification_probe_count": 2, - "runtime_parameter_count": 3, - "scalar_count": 76, - "row_count": 11, - }, - "certified_relation_count": 0, - "applied_relation_count": 0, - } - - recipe = reproduction_recipe( - candidate, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - measurement={"provenance": {"numerical_relation_fallback": fallback}}, - ) - - assert recipe.generate is not None - assert "--no-numerical-current-reuse" in recipe.generate - assert "--numerical-current-reuse" not in recipe.generate - assert "effective-reuse-off-fallback" in recipe.kind - assert "evidence-envelope fallback" in recipe.note - assert "effectively disabled" in recipe.note - - malformed = json.loads(json.dumps(fallback)) - malformed["geometry"]["scalar_count"] = 77 - with pytest.raises(ManualCampaignError, match="fallback geometry is inconsistent"): - reproduction_recipe( - candidate, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - measurement={"provenance": {"numerical_relation_fallback": malformed}}, - ) - - -def test_reproduction_cli_prefix_runs_from_an_unrelated_directory( - tmp_path: Path, -) -> None: - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - recipe = reproduction_recipe( - candidate, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - ) - assert recipe.generate is not None - command_prefix = recipe.generate[:3] - completed = subprocess.run( - (*command_prefix, "generate", "--help"), - cwd=tmp_path, - check=False, - capture_output=True, - text=True, - timeout=15, - ) - assert completed.returncode == 0, completed.stderr - assert "usage:" in completed.stdout - - -def test_completed_reproduction_recipe_uses_exact_selectors_and_momenta( - tmp_path: Path, -) -> None: - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.workload is Workload.ALL_FLOW - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - recorded_momenta = [[[101.0, 1.0, 2.0, 3.0]]] - measurement = { - "status": "ok", - "artifact": {"path": "/tmp/example-artifact", "process_id": "stable-process"}, - "selector_contract": { - "selected_color_flow_ids": ["cf:1"], - "selected_color_words": [[1, 2]], - "all_flow_helicity_ids": ["h:+1,-1"], - "all_flow_source_helicities": {"1": 1, "2": -1}, - "point_digest": "1" * 64, - }, - "provenance": { - "requested_config": {"model": {"source": "/tmp/prepared.pyamplicol-model"}}, - "report_momenta": recorded_momenta, - }, - } - recipe = reproduction_recipe( - candidate, - repo_root=tmp_path, - artifact_root=tmp_path / "campaign_artifacts", - measurement=measurement, - ) - assert recipe.exact is True - assert recipe.prepare is not None - assert "built-in-sm" in recipe.prepare - assert recipe.generate is not None - assert recipe.generate[recipe.generate.index("--model") + 1].endswith( - "/prepared-models/built-in-sm-jit-o2.pyamplicol-model" - ) - assert recipe.profile is not None - profile_index = recipe.profile.index("profile") - assert recipe.profile[profile_index + 1].endswith(f"/{candidate.cell_id}/artifact") - assert candidate.process in recipe.profile - assert "--helicity" in recipe.profile - assert "h:+1,-1" in recipe.profile - assert "--momenta" in recipe.profile - momenta_path = Path(recipe.profile[recipe.profile.index("--momenta") + 1]) - assert json.loads(momenta_path.read_text(encoding="ascii")) == recorded_momenta - assert momenta_path.is_relative_to(tmp_path / "campaign_artifacts") - assert all( - ".artifacts" not in argument - for command in (recipe.prepare, recipe.generate, recipe.profile) - for argument in command[1:] - ) - assert "<" not in " ".join((*recipe.generate, *recipe.profile)) - - -def test_ufo_recurrence_recipe_has_public_model_compile_prerequisite( - tmp_path: Path, -) -> None: - from pyamplicol.cli import parse_cli - - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.UFO_SM - ) - recipe = reproduction_recipe( - candidate, - repo_root=tmp_path, - artifact_root=tmp_path / "campaign_artifacts", - ) - - assert recipe.prepare is not None - assert recipe.prepare[:5] == ( - sys.executable, - "-m", - "pyamplicol", - "model", - "compile", - ) - prepare_index = recipe.prepare.index("model") - assert ( - parse_cli(recipe.prepare[prepare_index:]).resolve().effective.action - == "model-compile" - ) - assert recipe.generate is not None - prepared_source = recipe.generate[recipe.generate.index("--model") + 1] - assert prepared_source.endswith(".pyamplicol-model") - generate_index = recipe.generate.index("generate") - assert ( - parse_cli(recipe.generate[generate_index:]).resolve().effective.action - == "generate" - ) - assert "model-compile-prerequisite" in recipe.kind - - -def test_compiled_recipe_labels_both_private_timing_exceptions() -> None: - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.COMPILED - ) - recipe = reproduction_recipe( - candidate, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - ) - - assert recipe.exact is False - assert "precompiled-generation" in recipe.kind - assert "paired-arena" in recipe.kind - assert "outside generation_seconds" in recipe.note - assert "do not reproduce either timing boundary" in recipe.note - - -def test_dry_run_is_compact_and_labels_each_recipe( - tmp_path: Path, - capsys: pytest.CaptureFixture[str], - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setenv("NO_COLOR", "1") - cell_id = "matrix-compiled-builtin-sm-lc-n1-dd-z-jets-selected-flow" - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - - assert ( - campaign_main( - ("run", "--dry-run", "--cell-id", cell_id), - repo_root=ROOT, - docs_dir=docs_dir, - ) - == 0 - ) - output = capsys.readouterr().out - - assert "kind: public-cli+precompiled-generation+paired-arena-exceptions" in output - assert "exact: no" in output - assert "Diagnostic only:" in output - assert "Generate:" in output - assert "Profile template/diagnostic:" in output - assert max(map(len, output.splitlines())) < 300 - - -def test_statistics_use_ratio_of_sums_weighting() -> None: - candidates = [ - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - ][:2] - baselines = [REPORT_CATALOG.validation_baseline_cell(cell) for cell in candidates] - assert all(baseline is not None for baseline in baselines) - comparisons = ( - Comparison(candidates[0], baselines[0], 2.0, 1.0), # type: ignore[arg-type] - Comparison(candidates[1], baselines[1], 9.0, 3.0), # type: ignore[arg-type] - ) - summary = comparison_statistics(comparisons) - assert summary["median"] == 2.5 - assert summary["mean"] == 2.5 - assert summary["weighted_mean"] == 11.0 / 4.0 - assert summary["best"] is comparisons[0] - assert summary["worst"] is comparisons[1] - - -@pytest.mark.parametrize(("width", "height"), ((80, 24), (120, 36), (160, 48))) -def test_ratatui_headless_frames_are_stable_and_informative( - width: int, - height: int, -) -> None: - frame = render_dashboard_frame( - _snapshot_fixture(), - width=width, - height=height, - ) - assert isinstance(frame, str) - assert "pyAmpliCol profiling campaign" in frame - assert "Selected" in frame - assert "Recycled" in frame - assert "Remaining" in frame - assert "Ready 0" in frame - assert "Waiting dependency 0" in frame - assert "Waiting coordination lock 0" in frame - assert "RAM" in frame - assert "Caps Generation 01:00:00" in frame - assert "RAM 30.00 GB" in frame - assert "Total wall 01:00:00" in frame - assert "Ctrl-C" in frame - assert len(frame.splitlines()) == height - - -def test_ratatui_styled_cells_include_color_and_gauge_values() -> None: - from ratatui import Color - - state = _snapshot_fixture() - width = 120 - frame = render_dashboard_frame(state, width=width, height=36) - cells = render_dashboard_frame(state, width=width, height=36, cells=True) - assert isinstance(cells, list) - assert cells - assert any(item.get("fg") not in (None, 0) for item in cells) - assert any(item.get("ch") == ord("8") for item in cells) - header_y, header = next( - (index, line) - for index, line in enumerate(frame.splitlines()) - if "cell" in line and "phase / step" in line - ) - header_cell = cells[header_y * width + header.index("cell")] - assert header_cell["fg"] == int(Color.LightCyan) - assert int(header_cell["mods"]) & 1 - - -def test_dashboard_detail_columns_and_supervision_summary_are_styled() -> None: - from ratatui import Color - - worker = WorkerView( - "completed-demo", - status="ok", - phase="complete", - step="published", - cpu_seconds=1.0, - current_rss_bytes=2_000, - peak_rss_bytes=3_000, - phase_timeline=( - manual_campaign.PhaseTimelineRow( - "Loading and compiling evaluator", - wall_seconds=1.25, - status="measured", - ), - manual_campaign.PhaseTimelineRow( - "Worker supervision", - wall_seconds=2.0, - cpu_seconds=1.0, - peak_memory_bytes=3_000, - status="observed", - detail="overall observed worker wall", - ), - ), - ) - state = DashboardState( - instance_id="aligned-details", - selected_ids=(worker.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - workers={worker.cell_id: worker}, - terminal_outcomes={ - worker.cell_id: manual_campaign._DashboardTerminalOutcome.SUCCESS - }, - show_completed=True, - ) - width = 160 - frame = render_dashboard_frame(state, width=width, height=48) - lines = frame.splitlines() - second_keys = {} - for first_key, key in ( - ("Phase", "Step"), - ("Wall", "CPU"), - ("RSS current", "RSS peak"), - ("Guard current", "Guard peak"), - ("Outer wall", "Evaluator total"), - ("PID tree", "Attempt"), - ): - line = next(value for value in lines if first_key in value and key in value) - second_keys[key] = line.index(key) - assert len(set(second_keys.values())) == 1 - assert "Loading and compiling evaluator" in frame - - cells = render_dashboard_frame(state, width=width, height=48, cells=True) - summary_y, summary_line = next( - (index, line) - for index, line in enumerate(lines) - if "Worker supervision" in line - ) - summary_cell = cells[summary_y * width + summary_line.index("Worker supervision")] - assert summary_cell["fg"] == int(Color.LightCyan) - assert summary_cell["bg"] == int(Color.DarkGray) - assert int(summary_cell["mods"]) & 1 - - -def test_dashboard_retains_and_renders_native_progress_counters( - tmp_path: Path, -) -> None: - progress_path = tmp_path / "progress.jsonl" - progress_path.write_text( - json.dumps( - { - "event": "update", - "task_id": "generation:recurrence:process:rust-builder", - "completed": 8, - "total": 9, - "message": "recurrence stage", - "details": { - "process": "dd_z_7g", - "step": "recurrence stage", - "stage_index": 8, - "stage_total": 9, - "current_count": 38_581, - "contribution_count": 286_294, - "certified_relation_count": 0, - "applied_relation_count": 0, - }, - } - ) - + "\n", - encoding="utf-8", - ) - worker = WorkerView( - "matrix-recurrence-builtin-sm-lc-n8-dd-z-jets-all-flow", - status="running", - phase="generation", - progress_path=str(progress_path), - ) - - _tail_progress(worker) - - assert worker.progress_task_id == ("generation:recurrence:process:rust-builder") - assert worker.progress_completed == 8 - assert worker.progress_total == 9 - assert worker.progress_details["current_count"] == 38_581 - assert worker.progress_details["contribution_count"] == 286_294 - summary = _progress_detail_summary(worker.progress_details) - assert "currents 38,581" in summary - assert "contributions 286,294" in summary - assert "relations certified 0" in summary - state = DashboardState( - instance_id="progress-details", - selected_ids=(worker.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="6" * 40, - workers={worker.cell_id: worker}, - ) - frame = render_dashboard_frame(state, width=160, height=48) - assert "Progress data" in frame - assert "currents 38,581" in frame - assert "contributions 286,294" in frame - - -def test_dashboard_keys_select_scroll_help_and_interrupt() -> None: - from ratatui import KeyCode, KeyMods - - state = _snapshot_fixture() - cancellation = threading.Event() - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Down, "ch": 0, "mods": 0}, - cancellation, - ) - assert state.selected_index == 1 - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.PageDown, "ch": 0, "mods": 0}, - cancellation, - ) - assert state.detail_scroll == 3 - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("?"), "mods": 0}, - cancellation, - ) - assert state.show_help - assert _handle_dashboard_key( - state, - { - "kind": "key", - "code": KeyCode.Char, - "ch": ord("c"), - "mods": int(KeyMods.CTRL), - }, - cancellation, - ) - assert cancellation.is_set() - assert state.interrupted - - -def test_dashboard_command_drawer_scrolls_and_copies_exact_command() -> None: - from ratatui import KeyCode - - command = " ".join( - ["pyamplicol", "generate"] - + [f"--option-{index} 'value {index}'" for index in range(30)] - ) - worker = WorkerView( - "command-demo", - status="running", - phase="generation", - reproduce_prepare="pyamplicol model compile built-in-sm /tmp/model", - reproduce_generate=command, - reproduce_profile="pyamplicol profile /tmp/artifact --process 'd d~ > z'", - ) - state = DashboardState( - instance_id="command-drawer", - selected_ids=(worker.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - workers={worker.cell_id: worker}, - ) - cancellation = threading.Event() - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("2"), "mods": 0}, - cancellation, - ) - assert state.command_stage == "generate" - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Tab, "ch": 0, "mods": 0}, - cancellation, - ) - assert state.command_stage == "profile" - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Left, "ch": 0, "mods": 0}, - cancellation, - ) - assert state.command_stage == "generate" - first = render_dashboard_frame(state, width=80, height=24) - assert "Reproduction command · generate" in first - assert "wrapped lines 1-" in first - assert "--option-29" not in first - - for _ in range(4): - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.PageDown, "ch": 0, "mods": 0}, - cancellation, - ) - last = render_dashboard_frame(state, width=80, height=24) - assert "--option-29" in last - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("y"), "mods": 0}, - cancellation, - ) - assert state.pending_clipboard == ("generate", command) - sequence = manual_campaign._osc52_clipboard_sequence(command) - encoded = sequence.removeprefix("\x1b]52;c;").removesuffix("\x07") - assert base64.b64decode(encoded).decode("utf-8") == command - assert not cancellation.is_set() - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("p"), "mods": 0}, - cancellation, - ) - assert state.pending_print == ("generate", command) - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Esc, "ch": 0, "mods": 0}, - cancellation, - ) - assert state.command_stage is None - assert not cancellation.is_set() - - -def test_dashboard_filters_order_and_keyboard_toggles() -> None: - from ratatui import KeyCode - - workers = { - "done-ok": WorkerView("done-ok", status="ok"), - "done-reused": WorkerView("done-reused", status="reused"), - "attention-error": WorkerView("attention-error", status="error"), - "recycled-cap": WorkerView("recycled-cap", status="memory_limit"), - "active-queued": WorkerView("active-queued", status="queued"), - "active-preparing": WorkerView("active-preparing", status="preparing"), - "active-running": WorkerView("active-running", status="running"), - } - state = DashboardState( - instance_id="filters", - selected_ids=tuple(workers), - recycled_ids={"done-reused", "recycled-cap"}, - static_na_ids=set(), - workers=workers, - terminal_outcomes={ - "done-ok": manual_campaign._DashboardTerminalOutcome.SUCCESS, - "done-reused": manual_campaign._DashboardTerminalOutcome.SUCCESS, - "recycled-cap": manual_campaign._DashboardTerminalOutcome.CAPPED, - "attention-error": manual_campaign._DashboardTerminalOutcome.FAILED, - }, - ) - cancellation = threading.Event() - - assert [worker.cell_id for worker in state.visible_workers()] == [ - "active-running", - "active-preparing", - "active-queued", - "attention-error", - "recycled-cap", - ] - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("d"), "mods": 0}, - cancellation, - ) - assert state.show_completed - assert [worker.cell_id for worker in state.visible_workers()] == [ - "active-running", - "active-preparing", - "active-queued", - "attention-error", - "recycled-cap", - "done-ok", - "done-reused", - ] - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("e"), "mods": 0}, - cancellation, - ) - assert not state.show_errors - assert [worker.cell_id for worker in state.visible_workers()] == [ - "active-running", - "active-preparing", - "active-queued", - "done-ok", - "done-reused", - ] - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("d"), "mods": 0}, - cancellation, - ) - assert not state.show_completed - assert [worker.cell_id for worker in state.visible_workers()] == [ - "active-running", - "active-preparing", - "active-queued", - ] - - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("e"), "mods": 0}, - cancellation, - ) - assert state.show_errors - assert [worker.cell_id for worker in state.visible_workers()] == [ - "active-running", - "active-preparing", - "active-queued", - "attention-error", - "recycled-cap", - ] - - -def test_dashboard_error_total_is_in_primary_overview_summary() -> None: - workers = { - "active": WorkerView("active", status="running"), - "error": WorkerView("error", status="error"), - "unverified": WorkerView("unverified", status="unverified"), - "recycled-cap": WorkerView("recycled-cap", status="memory_limit"), - } - state = DashboardState( - instance_id="error-counter", - selected_ids=tuple(workers), - recycled_ids={"recycled-cap"}, - static_na_ids=set(), - workers=workers, - terminal_outcomes={ - "recycled-cap": manual_campaign._DashboardTerminalOutcome.CAPPED, - "error": manual_campaign._DashboardTerminalOutcome.FAILED, - "unverified": manual_campaign._DashboardTerminalOutcome.UNVERIFIED, - }, - ) - - frame = render_dashboard_frame(state, width=120, height=36) - summary = next(line for line in frame.splitlines() if "Selected " in line) - assert "Errors 1" in summary - assert "Unverified 1" in summary - assert "Remaining 1" in summary - assert "Workers active 1" in frame - assert "Capped 0" in frame - - -def test_finished_unverified_is_not_counted_as_an_error(tmp_path: Path) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="unverified-counter", - selected_ids=("diagnostic",), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - - LeaseManager(service, state).observe( - { - "event": "finished", - "cell_id": "diagnostic", - "status": ResultStatus.UNVERIFIED.value, - "detail": "independent authority unavailable", - } - ) - - assert state.failed_ids == set() - assert state.unverified_ids == {"diagnostic"} - assert state.counters()["failed"] == 0 - assert state.counters()["unverified"] == 1 - assert state.counters()["remaining"] == 0 - - -def test_finished_failure_shows_authenticated_reason_and_keeps_attempt_id( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - result = { - "status": ResultStatus.ERROR.value, - "failure": { - "kind": None, - "message": "worker terminated by phase_state_error", - }, - "resources": { - "supervisor": { - "reason": "phase_state_error", - "phase_state_error": ( - "worker phase-state transition timestamp is outside the " - "supervised process lifetime" - ), - }, - }, - } - with service.store.new_attempt( - cell.cell_id, - manual_campaign.ArtifactPolicy.REGENERATE, - ) as attempt: - attempt.write_json("worker-result.json", result) - attempt.mark_failed( - "phase-state failure", - artifact_paths=("worker-result.json",), - ) - attempt_id = attempt.attempt_id - - state = DashboardState( - instance_id="terminal-reason", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - workers={ - cell.cell_id: WorkerView( - cell.cell_id, - status="running", - phase="terminating", - attempt_id=attempt_id, - ) - }, - ) - monkeypatch.setattr( - service.store, - "load_sealed_unsuccessful_worker_result", - lambda *_args, **_kwargs: pytest.fail( - "terminal dashboard must not hash sealed attempt payloads" - ), - ) - - LeaseManager(service, state).observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": ResultStatus.ERROR.value, - "detail": attempt_id, - "terminal_detail": ( - "worker phase-state transition timestamp is outside the " - "supervised process lifetime" - ), - "completed_at_ns": 7, - } - ) - - worker = state.workers[cell.cell_id] - assert worker.step == ( - "worker phase-state transition timestamp is outside the supervised " - "process lifetime" - ) - assert worker.attempt_id == attempt_id - frame = render_dashboard_frame(state, width=220, height=36) - assert "worker phase-state transition timestamp" in frame - assert "Attempt" in frame - assert attempt_id in frame - - -def test_terminal_result_step_uses_generic_failure_message() -> None: - assert ( - manual_campaign._terminal_result_step( - { - "status": ResultStatus.VALIDATION_FAILED.value, - "failure": { - "kind": "MeasurementValidationError", - "message": "resolved component sum disagrees with total", - }, - } - ) - == "resolved component sum disagrees with total" - ) - assert ( - manual_campaign._terminal_result_step( - { - "status": ResultStatus.MEMORY_LIMIT.value, - "failure": {"kind": "ReportPolicyCensor", "message": "memory cap"}, - "provenance": { - "manual_campaign": {"memory_limit_bytes": 15_000_000_000} - }, - } - ) - == ">15GB" - ) - - -def test_finished_failure_does_not_show_preserved_current_as_failed_attempt( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - result = { - "status": ResultStatus.VALIDATION_FAILED.value, - "failure": { - "kind": "MeasurementValidationError", - "message": "new attempt disagrees with the numerical authority", - }, - } - with service.store.new_attempt( - cell.cell_id, - manual_campaign.ArtifactPolicy.REGENERATE, - ) as attempt: - attempt.write_json("worker-result.json", result) - attempt.mark_failed( - "validation failure", - artifact_paths=("worker-result.json",), - ) - failed_attempt_id = attempt.attempt_id - preserved_attempt_id = "00000000-0000-4000-8000-000000000099" - preserved = LightweightCurrent( - cell_id=cell.cell_id, - attempt_id=preserved_attempt_id, - result_path=tmp_path / "preserved-result.json", - result={ - "status": ResultStatus.OK.value, - "wall_seconds_per_point": 0.25, - }, - complete=True, - reusable=True, - reason="previous valid current", - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_current", - lambda *_args, **_kwargs: preserved, - ) - state = DashboardState( - instance_id="preserved-current", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - workers={ - cell.cell_id: WorkerView( - cell.cell_id, - status="running", - attempt_id=failed_attempt_id, - ) - }, - ) - - LeaseManager(service, state).observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": ResultStatus.VALIDATION_FAILED.value, - "detail": "previous valid current preserved", - "terminal_detail": ( - "new attempt disagrees with the numerical authority" - ), - "completed_at_ns": 8, - } - ) - - worker = state.workers[cell.cell_id] - assert worker.attempt_id == failed_attempt_id - assert worker.step == "new attempt disagrees with the numerical authority" - assert worker.published_wall_seconds_per_point is None - - -def test_recycled_resource_cap_is_available_to_error_filter( - tmp_path: Path, -) -> None: - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - current = LightweightCurrent( - cell_id=cell.cell_id, - attempt_id="recycled-cap-attempt", - result_path=tmp_path / "worker-result.json", - result={ - "status": ResultStatus.TIMEOUT.value, - "resources": { - "wall_seconds": 3601.0, - "peak_rss_bytes": 2_000_000_000, - }, - "provenance": { - "manual_campaign": { - "generation_limit_seconds": 3600.0, - "memory_limit_bytes": 30_000_000_000, - } - }, - }, - complete=True, - reusable=True, - reason="resource-capped terminal", - ) - - workers = manual_campaign._recycled_attention_workers( - (cell,), - {cell.cell_id: current}, - {cell.cell_id}, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - settings=ReproductionSettings(), - ) - - assert set(workers) == {cell.cell_id} - worker = workers[cell.cell_id] - assert worker.status == "generation_limit" - assert worker.attempt_id == "recycled-cap-attempt" - assert worker.wall_seconds == 3601.0 - assert worker.peak_rss_bytes == 2_000_000_000 - assert worker.reproduce_generate is not None - assert worker.recycled - - state = DashboardState( - instance_id="recycled-cap", - selected_ids=(cell.cell_id,), - recycled_ids={cell.cell_id}, - static_na_ids=set(), - workers=workers, - show_completed=True, - ) - assert [row.cell_id for row in state.visible_workers()] == [cell.cell_id] - state.show_errors = False - assert state.visible_workers() == () - - -def test_recycled_legacy_manual_memory_cap_needs_no_new_censor_record( - tmp_path: Path, -) -> None: - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - current = LightweightCurrent( - cell_id=cell.cell_id, - attempt_id="legacy-memory-cap", - result_path=tmp_path / "worker-result.json", - result={ - "status": ResultStatus.MEMORY_LIMIT.value, - "provenance": {"manual_campaign": {"memory_limit_bytes": 30_000_000_000}}, - }, - complete=True, - reusable=True, - reason="resource-capped terminal", - ) - - worker = manual_campaign._recycled_attention_workers( - (cell,), - {cell.cell_id: current}, - {cell.cell_id}, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - settings=ReproductionSettings(), - )[cell.cell_id] - - assert worker.status == "memory_limit" - assert worker.recycled - - -def test_successful_recycled_result_uses_done_filter_and_persisted_timeline( - tmp_path: Path, -) -> None: - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - result = { - "status": ResultStatus.OK.value, - "provenance": { - "report_source_revision": "a" * 40, - "manual_campaign": { - "cell_identity": { - "execution_mode": "recurrence", - "model": "builtin_sm", - }, - "phase_timeline": { - "schema": "pyamplicol-manual-campaign-phase-timeline-v1", - "total_worker_wall_seconds": 12.5, - "peak_rss_bytes": 2_048, - "peak_guard_bytes": 4_096, - "entries": [ - { - "key": "preparation", - "label": "Preparation", - "seconds": 0.125, - "status": "ok", - "detail": "model ready", - }, - { - "key": "generation", - "label": "Generation", - "seconds": 2.5, - "status": "ok", - }, - { - "key": "profiling", - "label": "Profiling", - "start_seconds": 3.0, - "end_seconds": 9.0, - "status": "ok", - }, - ], - }, - }, - }, - } - current = LightweightCurrent( - cell_id=cell.cell_id, - attempt_id="recycled-ok-attempt", - result_path=tmp_path / "worker-result.json", - result=result, - complete=True, - reusable=True, - reason="matching same-source current", - ) - - workers = manual_campaign._recycled_attention_workers( - (cell,), - {cell.cell_id: current}, - {cell.cell_id}, - repo_root=ROOT, - artifact_root=CAMPAIGN_ARTIFACT_ROOT, - settings=ReproductionSettings(), - ) - worker = workers[cell.cell_id] - assert worker.status == "recycled" - assert worker.recycled - assert worker.wall_seconds == 12.5 - assert worker.peak_rss_bytes == 2_048 - assert worker.peak_guard_bytes == 4_096 - assert [row.phase for row in worker.phase_timeline] == [ - "Preparation", - "Generation", - "Profiling", - ] - assert worker.phase_timeline[2].wall_seconds is None - assert worker.provenance_summary == ( - "source aaaaaaaaaaaa · engine recurrence · model builtin_sm" - ) - - state = DashboardState( - instance_id="recycled-ok", - selected_ids=(cell.cell_id,), - recycled_ids={cell.cell_id}, - static_na_ids=set(), - workers=workers, - ) - assert state.visible_workers() == () - state.show_completed = True - assert [row.cell_id for row in state.visible_workers()] == [cell.cell_id] - state.show_errors = False - assert [row.cell_id for row in state.visible_workers()] == [cell.cell_id] - - frame = render_dashboard_frame(state, width=160, height=48) - assert "recycled" in frame - assert "No work executed by this invocation" in frame - assert "Reuse matching same-source current" in frame - assert "Phase timeline" in frame - assert "Preparation" in frame - assert "125.0 ms" in frame - assert "2.50 s" in frame - assert "Generation" in frame - assert "Profiling" in frame - assert "unavailable" in frame - assert "source aaaaaaaaaaaa" in frame - - decoded = manual_campaign._worker_from_lease( - worker.cell_id, - worker.as_dict(), - peer_instance=None, - ) - assert decoded.status == "recycled" - assert decoded.recycled - assert decoded.phase_timeline == worker.phase_timeline - - -def test_completed_legacy_result_marks_missing_timeline_unavailable() -> None: - worker = WorkerView( - "legacy-completed", - status="ok", - phase="completed", - step="measurement published", - ) - state = DashboardState( - instance_id="legacy-completed", - selected_ids=(worker.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - workers={worker.cell_id: worker}, - show_completed=True, - ) - - frame = render_dashboard_frame(state, width=120, height=36) - assert "Provenance unavailable" in frame - assert "Phase timeline unavailable (older result)" in frame - - -def test_selected_worker_preserves_subsecond_wall_and_cpu_durations() -> None: - worker = WorkerView( - "short-worker", - status="running", - phase="profiling", - step="first sample", - wall_seconds=0.125, - cpu_seconds=0.004, - ) - state = DashboardState( - instance_id="short-worker", - selected_ids=(worker.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - workers={worker.cell_id: worker}, - ) - - frame = render_dashboard_frame(state, width=120, height=36) - - assert "Wall 125.0 ms" in frame - assert "CPU 4.0 ms" in frame - assert "Wall 00:00:00" not in frame - - -def test_phase_timeline_uses_only_explicit_legacy_durations() -> None: - rows = manual_campaign._extract_phase_timeline( - { - "generation_seconds": 2.25, - "provenance": { - "runtime_profile": { - "measurement_phase_elapsed_seconds": 1.5, - "started_seconds": 3.0, - "finished_seconds": 99.0, - }, - }, - } - ) - - assert [(row.phase, row.wall_seconds) for row in rows] == [ - ("Generation", 2.25), - ("Timed headline measurement", 1.5), - ] - assert ( - manual_campaign._extract_phase_timeline( - { - "timeline": [{"label": "native core", "duration": 99.0}], - "provenance": { - "manual_campaign": { - "phase_timeline": { - "schema": "unknown-timeline-v0", - "entries": [ - {"label": "untrusted", "seconds": 123.0}, - ], - } - } - }, - } - ) - == () - ) - - -@pytest.mark.parametrize( - ("width", "height", "expected_range"), - ((80, 24, "15-18/18"), (120, 36, "10-18/18")), -) -def test_dashboard_worker_viewport_pans_with_selection( - width: int, - height: int, - expected_range: str, -) -> None: - from ratatui import KeyCode - - workers = { - f"worker-{index:02d}": WorkerView( - f"worker-{index:02d}", - status="running", - step=f"profiling sample {index}", - ) - for index in range(18) - } - state = DashboardState( - instance_id="viewport", - selected_ids=tuple(workers), - recycled_ids=set(), - static_na_ids=set(), - workers=workers, - ) - cancellation = threading.Event() - for _ in range(17): - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Down, "ch": 0, "mods": 0}, - cancellation, - ) - - frame = render_dashboard_frame(state, width=width, height=height) - selected_rows = [line for line in frame.splitlines() if "▶" in line] - assert len(selected_rows) == 1 - assert "worker-17" in selected_rows[0] - assert "worker-00" not in frame - assert expected_range in frame - assert "Cell worker-17" in frame - assert "profiling sample 17" in frame - - -def test_dashboard_key_aliases_clamp_scroll_ignore_noise_and_escape() -> None: - from ratatui import KeyCode - - state = _snapshot_fixture() - cancellation = threading.Event() - assert not _handle_dashboard_key(state, {"kind": "mouse"}, cancellation) - assert state.selected_index == 0 - - state.detail_scroll = 2 - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.PageUp, "ch": 0, "mods": 0}, - cancellation, - ) - assert state.detail_scroll == 0 - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("k"), "mods": 0}, - cancellation, - ) - assert state.selected_index == -1 - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("j"), "mods": 0}, - cancellation, - ) - assert state.selected_index == 0 - assert not _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Char, "ch": ord("c"), "mods": 0}, - cancellation, - ) - assert not cancellation.is_set() - - assert _handle_dashboard_key( - state, - {"kind": "key", "code": KeyCode.Esc, "ch": 0, "mods": 0}, - cancellation, - ) - assert cancellation.is_set() - assert state.interrupted - - -def _manual_service( - tmp_path: Path, - *, - repo_root: Path = ROOT, - initialize_source_marker: bool = True, -) -> ReportService: - service = ReportService( - ReportPaths.from_repo( - repo_root, - profile="macbook_M3_manual", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - if initialize_source_marker: - manual_campaign.update_source_marker( - service, - manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()), - ) - return service - - -def _presentation_test_cell() -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.workload is Workload.CONTRACTED - and REPORT_CATALOG.static_na_reason(cell) is None - ) - - -def _presentation_outcome( - cell_id: str, - *, - status: str, - completed_at_ns: int = 1, - invocation_id: str = "presentation-test", - source_revision: str = "a" * 40, - profile: str = manual_campaign._PRESENTATION_PROFILE, - attempt_id: str | None = None, -) -> manual_campaign.LightweightPresentationOutcome: - return manual_campaign.LightweightPresentationOutcome( - profile=profile, - cell_id=cell_id, - source_revision=source_revision, - campaign_invocation_id=invocation_id, - attempt_id=attempt_id, - status=status, - label=manual_campaign._humanized_outcome_label(status), - completed_at_ns=completed_at_ns, - ) - - -def test_presentation_outcome_survives_campaign_parent_and_basename_move( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()) - campaign_a = tmp_path / "parent-a/original-name" - campaign_a.mkdir(parents=True) - service_a = ReportService( - manual_campaign._campaign_report_paths(ROOT, campaign_a), - portable_current_results=True, - ) - manual_campaign.update_source_marker(service_a, source) - cell = _presentation_test_cell() - monkeypatch.setattr(manual_campaign, "_ACTIVE_PROFILE", "original-name") - expected = _presentation_outcome(cell.cell_id, status="error") - assert manual_campaign._publish_presentation_outcome(service_a, expected) - - campaign_b = tmp_path / "parent-b/renamed-campaign" - campaign_b.parent.mkdir() - campaign_a.rename(campaign_b) - service_b = ReportService( - manual_campaign._campaign_report_paths(ROOT, campaign_b), - portable_current_results=True, - ) - monkeypatch.setattr(manual_campaign, "_ACTIVE_PROFILE", "renamed-campaign") - - moved = manual_campaign.lightweight_presentation_outcome( - service_b, - cell, - source_revision=source.revision, - ) - assert moved == expected - - -def _valid_presentation_current( - cell_id: str, - tmp_path: Path, -) -> LightweightCurrent: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 1.0e-3, - "artifact": {"digest": "presentation-test"}, - "validation": {"status": "ok", "direct_agreements": []}, - "resources": {"peak_rss_bytes": 1}, - "provenance": {"method": "original-amplicol-generated-library"}, - "failure": None, - } - ) - return LightweightCurrent( - cell_id=cell_id, - attempt_id="00000000-0000-4000-8000-000000000001", - result_path=tmp_path / "result.json", - result=measurement, - complete=True, - reusable=True, - reason="reusable", - ) - - -def _capped_presentation_current( - cell_id: str, - tmp_path: Path, -) -> LightweightCurrent: - measurement = manual_campaign.failure_measurement( - ResultStatus.TIMEOUT, - "generation exceeded the configured limit", - ) - measurement["provenance"] = { - "manual_campaign": {"generation_limit_seconds": 3600.0} - } - return LightweightCurrent( - cell_id=cell_id, - attempt_id="00000000-0000-4000-8000-000000000002", - result_path=tmp_path / "capped-result.json", - result=measurement, - complete=True, - reusable=True, - reason="reusable terminal cap", - ) - - -def _cache_measurement( - caches: dict[str, dict[str, object]], - *, - dataset_id: str, - cell_id: str, -) -> dict[str, object]: - entries = caches[f"{dataset_id}.json"]["entries"] - assert isinstance(entries, list) - entry = next(item for item in entries if item["cell_id"] == cell_id) - measurement = entry["measurement"] - assert isinstance(measurement, dict) - return measurement - - -def test_presentation_failure_overlay_never_replaces_a_valid_current( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - failure = _presentation_outcome(cell.cell_id, status="validation_failed") - - failure_caches, merged = _merge_lightweight_snapshot( - service, - {}, - {cell.cell_id: failure}, - ) - assert merged == 1 - failure_measurement = _cache_measurement( - failure_caches, - dataset_id=cell.dataset_id, - cell_id=cell.cell_id, - ) - assert failure_measurement["status"] == ResultStatus.VALIDATION_FAILED.value - assert failure_measurement["failure"] == { - "kind": "ManualCampaignOutcome:validation_failed", - "message": "validation failed", - } - - current = _valid_presentation_current(cell.cell_id, tmp_path) - success_caches, merged = _merge_lightweight_snapshot( - service, - {cell.cell_id: current}, - { - cell.cell_id: _presentation_outcome( - cell.cell_id, - status="error", - completed_at_ns=2, - ) - }, - ) - assert merged == 1 - assert ( - _cache_measurement( - success_caches, - dataset_id=cell.dataset_id, - cell_id=cell.cell_id, - )["status"] - == ResultStatus.OK.value - ) - - -def test_presentation_success_tombstone_suppresses_failure_fallback( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome( - cell.cell_id, - status="error", - completed_at_ns=1, - ), - ) - tombstone = _presentation_outcome( - cell.cell_id, - status="ok", - completed_at_ns=2, - ) - manual_campaign._publish_presentation_outcome(service, tombstone) - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - assert observed == tombstone - - caches, merged = _merge_lightweight_snapshot( - service, - {}, - {cell.cell_id: observed}, - ) - - assert merged == 0 - assert ( - _cache_measurement( - caches, - dataset_id=cell.dataset_id, - cell_id=cell.cell_id, - ) - == empty_measurement() - ) - - -def test_presentation_outcome_publication_has_deterministic_last_writer( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - later_tie_breaker = _presentation_outcome( - cell.cell_id, - status="error", - completed_at_ns=10, - invocation_id="invocation-b", - ) - earlier_tie_breaker = _presentation_outcome( - cell.cell_id, - status="validation_failed", - completed_at_ns=10, - invocation_id="invocation-a", - ) - oldest = _presentation_outcome( - cell.cell_id, - status="blocked_dependency", - completed_at_ns=9, - invocation_id="invocation-z", - ) - - manual_campaign._publish_presentation_outcome(service, later_tie_breaker) - manual_campaign._publish_presentation_outcome(service, oldest) - manual_campaign._publish_presentation_outcome(service, earlier_tie_breaker) - - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - assert observed == later_tie_breaker - - -def test_strict_source_marker_rejects_late_old_revision_writer( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - old = _presentation_outcome( - cell.cell_id, - status="validation_failed", - completed_at_ns=300, - source_revision="a" * 40, - ) - manual_campaign._publish_presentation_outcome(service, old) - manual_campaign.update_source_marker( - service, - manual_campaign.ReportSourceIdentity("b" * 40, "c" * 40, ()), - ) - active = _presentation_outcome( - cell.cell_id, - status="error", - completed_at_ns=200, - source_revision="b" * 40, - ) - - manual_campaign._publish_presentation_outcome(service, active) - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome( - cell.cell_id, - status="validation_failed", - completed_at_ns=400, - source_revision="a" * 40, - ), - ) - - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="b" * 40, - ) - == active - ) - - -def test_cross_revision_marker_retains_global_outcome_ordering( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - manual_campaign.update_source_marker( - service, - manual_campaign.ReportSourceIdentity("b" * 40, "c" * 40, ()), - continue_across_revisions=True, - ) - active = _presentation_outcome( - cell.cell_id, - status="error", - completed_at_ns=200, - source_revision="b" * 40, - ) - historical = _presentation_outcome( - cell.cell_id, - status="validation_failed", - completed_at_ns=300, - source_revision="a" * 40, - ) - - manual_campaign._publish_presentation_outcome(service, active) - manual_campaign._publish_presentation_outcome(service, historical) - - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="b" * 40, - accept_historical_source=True, - ) - == historical - ) - - -def test_presentation_publication_requires_a_readable_source_marker( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path, initialize_source_marker=False) - cell = _presentation_test_cell() - outcome = _presentation_outcome(cell.cell_id, status="error") - - with pytest.raises(ManualCampaignError, match="source marker is unreadable"): - manual_campaign._publish_presentation_outcome(service, outcome) - - marker = service.paths.coordination_root / "manual-source.json" - marker.parent.mkdir(parents=True, exist_ok=True) - marker.write_text("{broken", encoding="utf-8") - with pytest.raises(ManualCampaignError, match="source marker is unreadable"): - manual_campaign._publish_presentation_outcome(service, outcome) - - -def test_presentation_outcome_reader_filters_source_profile_and_malformed_data( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - path = manual_campaign._presentation_outcome_path(service, cell.cell_id) - path.parent.mkdir(parents=True) - historical = _presentation_outcome( - cell.cell_id, - status="error", - source_revision="a" * 40, - ) - path.write_text(json.dumps(historical.as_dict()), encoding="utf-8") - - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="b" * 40, - ) - is None - ) - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="b" * 40, - accept_historical_source=True, - ) - == historical - ) - - wrong_profile = historical.as_dict() - wrong_profile["profile"] = "some_other_profile" - path.write_text(json.dumps(wrong_profile), encoding="utf-8") - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - is None - ) - - path.write_text('{"schema":"truncated"', encoding="utf-8") - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - is None - ) - - -def test_presentation_outcome_reader_rejects_timestamp_above_signed_64_bit( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - path = manual_campaign._presentation_outcome_path(service, cell.cell_id) - path.parent.mkdir(parents=True) - malformed = _presentation_outcome(cell.cell_id, status="error").as_dict() - malformed["completed_at_ns"] = 1 << 63 - path.write_text(json.dumps(malformed), encoding="utf-8") - - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - is None - ) - - -@pytest.mark.parametrize( - ("field", "value"), - ( - ("campaign_invocation_id", "campaign-λ"), - ("label", "error 🚫"), - ), -) -def test_presentation_outcome_parser_rejects_printable_non_ascii_metadata( - field: str, - value: str, -) -> None: - cell = _presentation_test_cell() - malformed = _presentation_outcome(cell.cell_id, status="error").as_dict() - assert value.isprintable() - assert not value.isascii() - malformed[field] = value - - assert ( - manual_campaign._parse_presentation_outcome( - malformed, - expected_profile=manual_campaign._PRESENTATION_PROFILE, - expected_cell_id=cell.cell_id, - source_revision="a" * 40, - accept_historical_source=False, - ) - is None - ) - - -def test_started_event_drops_stale_identity_before_generic_failure_overlay( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _capped_presentation_current(cell.cell_id, tmp_path) - worker = WorkerView( - cell.cell_id, - status="generation_limit", - attempt_id=current.attempt_id, - log_path="stale-worker.log", - progress_path="stale-progress.jsonl", - progress_completed=9, - progress_total=10, - progress_message="stale progress", - progress_task_id="stale-task", - progress_details={"stale": True}, - wall_seconds=12.0, - cpu_seconds=8.0, - current_rss_bytes=99, - peak_rss_bytes=101, - published_wall_seconds_per_point=0.5, - phase_timeline=(manual_campaign.PhaseTimelineRow("stale"),), - blocked_prerequisite_ids=("stale-prerequisite",), - events=["stale event"], - log_tail=["stale cap diagnostics"], - ) - state = DashboardState( - instance_id="new-invocation", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - workers={cell.cell_id: worker}, - ) - lease = LeaseManager(service, state) - monkeypatch.setattr( - manual_campaign, - "lightweight_current", - lambda *_args, **_kwargs: current, - ) - - lease.observe({"event": "started", "cell_id": cell.cell_id}) - - fresh_worker = state.workers[cell.cell_id] - assert fresh_worker is not worker - worker = fresh_worker - assert worker.attempt_id is None - assert worker.log_path is None - assert worker.progress_path is None - assert worker.progress_completed is None - assert worker.progress_total is None - assert worker.progress_message == "" - assert worker.progress_task_id is None - assert worker.progress_details == {} - assert worker.log_tail == [] - assert worker.wall_seconds == 0.0 - assert worker.cpu_seconds is None - assert worker.current_rss_bytes == 0 - assert worker.peak_rss_bytes == 0 - assert worker.published_wall_seconds_per_point is None - assert worker.phase_timeline == () - assert worker.blocked_prerequisite_ids == () - assert worker.events == ["started: dependency preparation"] - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": "error", - "detail": "generic worker crash without attempt records", - "completed_at_ns": 7, - } - ) - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - assert observed is not None - assert observed.status == "error" - assert observed.attempt_id is None - - caches, merged = _merge_lightweight_snapshot( - service, - {cell.cell_id: current}, - {cell.cell_id: observed}, - ) - assert merged == 1 - measurement = _cache_measurement( - caches, - dataset_id=cell.dataset_id, - cell_id=cell.cell_id, - ) - assert measurement["status"] == ResultStatus.ERROR.value - assert measurement["failure"] == { - "kind": "ManualCampaignOutcome:error", - "message": "error", - } - - -@pytest.mark.parametrize("recycle_status", ("reused", "skipped-current")) -def test_non_ok_recycle_does_not_erase_newer_error_outcome( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - recycle_status: str, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _capped_presentation_current(cell.cell_id, tmp_path) - error = _presentation_outcome( - cell.cell_id, status="error", completed_at_ns=2 - ) - manual_campaign._publish_presentation_outcome(service, error) - monkeypatch.setattr( - manual_campaign, - "lightweight_current", - lambda *_args, **_kwargs: current, - ) - lease = LeaseManager( - service, - DashboardState( - instance_id="cap-recycle", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ), - ) - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": recycle_status, - "detail": "ordinary terminal-current recycle", - "completed_at_ns": 3, - } - ) - - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - assert observed == error - - -@pytest.mark.parametrize("existing_success", (False, True)) -def test_front_end_ok_recycle_does_not_write_without_existing_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - existing_success: bool, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _valid_presentation_current(cell.cell_id, tmp_path) - if existing_success: - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome(cell.cell_id, status="reused"), - ) - writes: list[manual_campaign.LightweightPresentationOutcome] = [] - publish = manual_campaign._publish_presentation_outcome - - def capture( - target: ReportService, - outcome: manual_campaign.LightweightPresentationOutcome, - **kwargs: object, - ) -> bool: - written = publish(target, outcome, **kwargs) - if written: - writes.append(outcome) - return written - - monkeypatch.setattr(manual_campaign, "_publish_presentation_outcome", capture) - warnings = manual_campaign._publish_recycled_presentation_outcomes( - service, - {cell.cell_id: current}, - (cell.cell_id,), - source_revision="a" * 40, - campaign_invocation_id="passive-recycle", - ) - - assert warnings == () - assert writes == [] - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - if existing_success: - assert observed is not None - assert observed.status == "reused" - else: - assert observed is None - - -@pytest.mark.parametrize( - ("status", "existing_status", "expected_status", "expected_writes"), - ( - ("ok", None, None, 0), - ("reused", "reused", "reused", 0), - ("skipped-current", "error", "skipped-current", 1), - ), -) -def test_lease_success_with_resolved_ok_only_suppresses_existing_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - status: str, - existing_status: str | None, - expected_status: str | None, - expected_writes: int, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _valid_presentation_current(cell.cell_id, tmp_path) - if existing_status is not None: - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome(cell.cell_id, status=existing_status), - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_current", - lambda *_args, **_kwargs: current, - ) - writes: list[manual_campaign.LightweightPresentationOutcome] = [] - publish = manual_campaign._publish_presentation_outcome - - def capture( - target: ReportService, - outcome: manual_campaign.LightweightPresentationOutcome, - **kwargs: object, - ) -> bool: - written = publish(target, outcome, **kwargs) - if written: - writes.append(outcome) - return written - - monkeypatch.setattr(manual_campaign, "_publish_presentation_outcome", capture) - lease = LeaseManager( - service, - DashboardState( - instance_id="finished-ok", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ), - ) - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": status, - "detail": "resolved reusable OK current", - "completed_at_ns": 2, - } - ) - - assert len(writes) == expected_writes - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - if expected_status is None: - assert observed is None - else: - assert observed is not None - assert observed.status == expected_status - if expected_writes: - assert observed.attempt_id == current.attempt_id - - -@pytest.mark.parametrize("continuation_at_success", (False, True)) -def test_cross_revision_success_tombstones_historical_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - continuation_at_success: bool, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome( - cell.cell_id, - status="error", - completed_at_ns=1, - source_revision="a" * 40, - ), - ) - manual_campaign.update_source_marker( - service, - manual_campaign.ReportSourceIdentity("b" * 40, "c" * 40, ()), - continue_across_revisions=continuation_at_success, - ) - current = _valid_presentation_current(cell.cell_id, tmp_path) - monkeypatch.setattr( - manual_campaign, - "lightweight_current", - lambda *_args, **_kwargs: current, - ) - lease = LeaseManager( - service, - DashboardState( - instance_id="cross-revision-success", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="b" * 40, - ), - ) - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": "ok", - "detail": "new revision succeeded", - "completed_at_ns": 2, - } - ) - - if not continuation_at_success: - manual_campaign.update_source_marker( - service, - manual_campaign.ReportSourceIdentity("b" * 40, "c" * 40, ()), - continue_across_revisions=True, - ) - - tombstone = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="b" * 40, - accept_historical_source=True, - ) - assert tombstone is not None - assert tombstone.successful - assert tombstone.source_revision == "b" * 40 - caches, merged = _merge_lightweight_snapshot( - service, - {}, - {cell.cell_id: tombstone}, - ) - assert merged == 0 - assert ( - _cache_measurement( - caches, - dataset_id=cell.dataset_id, - cell_id=cell.cell_id, - )["status"] - == ResultStatus.NOT_AVAILABLE.value - ) - - -def test_front_end_ok_recycle_skips_immediately_when_cell_lock_is_busy( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _valid_presentation_current(cell.cell_id, tmp_path) - calls: list[tuple[str, float | None]] = [] - writes: list[manual_campaign.LightweightPresentationOutcome] = [] - - class BusyLock: - def __enter__(self) -> None: - raise manual_campaign.LockTimeoutError("busy") - - def __exit__( - self, - _error_type: object, - _error: object, - _traceback: object, - ) -> None: - return None - - def busy_lock(name: str, **kwargs: object) -> BusyLock: - timeout = kwargs.get("timeout") - calls.append((name, timeout if isinstance(timeout, float) else None)) - return BusyLock() - - monkeypatch.setattr(service.store, "named_lock", busy_lock) - monkeypatch.setattr( - manual_campaign, - "_publish_presentation_outcome", - lambda _service, outcome, **_kwargs: writes.append(outcome), - ) - - warnings = manual_campaign._publish_recycled_presentation_outcomes( - service, - {cell.cell_id: current}, - (cell.cell_id,), - source_revision="a" * 40, - campaign_invocation_id="no-ledger", - ) - - assert warnings == () - assert calls == [(f"campaign-cell-{cell.cell_id}", 0.0)] - assert writes == [] - - -def test_front_end_recycle_reconciles_outcome_under_campaign_cell_lock( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _valid_presentation_current(cell.cell_id, tmp_path) - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome(cell.cell_id, status="error"), - ) - campaign_lock = f"campaign-cell-{cell.cell_id}" - held: list[str] = [] - - class TrackingLock: - def __init__(self, name: str) -> None: - self.name = name - - def __enter__(self) -> None: - held.append(self.name) - - def __exit__( - self, - _error_type: object, - _error: object, - _traceback: object, - ) -> None: - assert held.pop() == self.name - - monkeypatch.setattr( - service.store, - "named_lock", - lambda name, **_kwargs: TrackingLock(name), - ) - read = manual_campaign.lightweight_presentation_outcome - publish = manual_campaign._publish_presentation_outcome - operations: list[tuple[str, bool]] = [] - - def tracked_read(*args: object, **kwargs: object): - operations.append(("read", campaign_lock in held)) - return read(*args, **kwargs) - - def tracked_publish(*args: object, **kwargs: object) -> None: - assert campaign_lock in held - operations.append(("write", True)) - publish(*args, **kwargs) - - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcome", - tracked_read, - ) - monkeypatch.setattr( - manual_campaign, - "_publish_presentation_outcome", - tracked_publish, - ) - - warnings = manual_campaign._publish_recycled_presentation_outcomes( - service, - {cell.cell_id: current}, - (cell.cell_id,), - source_revision="a" * 40, - campaign_invocation_id="lock-order", - ) - - assert warnings == () - assert operations == [("read", False), ("write", True)] - assert held == [] - - -def test_front_end_recycle_honours_marker_switch_to_continuation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome( - cell.cell_id, - status="error", - source_revision="a" * 40, - ), - ) - source_b = manual_campaign.ReportSourceIdentity("b" * 40, "c" * 40, ()) - manual_campaign.update_source_marker(service, source_b) - current = _valid_presentation_current(cell.cell_id, tmp_path) - read = manual_campaign.lightweight_presentation_outcome - switched = False - - def read_then_switch(*args: object, **kwargs: object): - nonlocal switched - outcome = read(*args, **kwargs) - if not switched: - switched = True - manual_campaign.update_source_marker( - service, - source_b, - continue_across_revisions=True, - ) - return outcome - - monkeypatch.setattr( - manual_campaign, - "lightweight_presentation_outcome", - read_then_switch, - ) - - warnings = manual_campaign._publish_recycled_presentation_outcomes( - service, - {cell.cell_id: current}, - (cell.cell_id,), - source_revision=source_b.revision, - campaign_invocation_id="marker-switch", - accept_historical_source=False, - ) - - assert warnings == () - outcome = read( - service, - cell, - source_revision=source_b.revision, - accept_historical_source=True, - ) - assert outcome is not None - assert outcome.successful - assert outcome.source_revision == source_b.revision - - -def _stub_run_campaign_boundaries( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - *, - currents: dict[str, LightweightCurrent], - planned: tuple[manual_campaign.PlannedCell, ...], - outcomes: tuple[CellOutcome, ...] = (), -) -> None: - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **_kwargs: dict(currents), - ) - monkeypatch.setattr( - manual_campaign, - "plan_campaign", - lambda *_args, **_kwargs: planned, - ) - monkeypatch.setattr( - manual_campaign, - "_bind_original_amplicol_if_required", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - manual_campaign, - "require_measurement_ready", - lambda _source: None, - ) - monkeypatch.setattr( - manual_campaign, - "_publish_campaign_summary_ids", - lambda *_args, **_kwargs: (tmp_path / "summary", {}), - ) - monkeypatch.setattr( - manual_campaign, - "_print_campaign_summary_ids", - lambda *_args, **_kwargs: None, - ) - - class StubScheduler: - def __init__(self, _service: ReportService, *, settings: object) -> None: - self.settings = settings - - def run( - self, - observed: tuple[manual_campaign.PlannedCell, ...], - ) -> manual_campaign.CampaignResult: - assert tuple(observed) == planned - return manual_campaign.CampaignResult(tuple(observed), outcomes) - - monkeypatch.setattr(manual_campaign, "CampaignScheduler", StubScheduler) - - -@pytest.mark.parametrize("mixed", (False, True)) -def test_run_campaign_recycle_paths_replace_failure_with_known_ok_tombstone( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - mixed: bool, -) -> None: - service = _manual_service(tmp_path) - measurable = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is None - ) - recycled_cell = measurable[0] - work_cell = measurable[1] - current = _valid_presentation_current(recycled_cell.cell_id, tmp_path) - manual_campaign._publish_presentation_outcome( - service, - _presentation_outcome(recycled_cell.cell_id, status="error"), - ) - planned = ( - ( - manual_campaign.PlannedCell( - work_cell, - dependency=False, - baseline_cell_id=None, - rank=1, - ), - ) - if mixed - else () - ) - outcomes = (CellOutcome(work_cell.cell_id, "ok", "completed"),) if mixed else () - _stub_run_campaign_boundaries( - monkeypatch, - tmp_path, - currents={recycled_cell.cell_id: current}, - planned=planned, - outcomes=outcomes, - ) - arguments = _parse("run", "--no-dashboard") - source = manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()) - - return_code = manual_campaign._run_campaign( - arguments, - repo_root=ROOT, - service=service, - source=source, - cells=(recycled_cell, work_cell) if mixed else (recycled_cell,), - palette=manual_campaign.Palette(False), - ) - - assert return_code == 0 - observed = manual_campaign.lightweight_presentation_outcome( - service, - recycled_cell, - source_revision=source.revision, - ) - assert observed is not None - assert observed.status == "reused" - assert observed.attempt_id == current.attempt_id - - -def test_cross_revision_continuation_recycles_ok_and_replans_blocked_cell( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - old_revision = "a" * 40 - active_source = manual_campaign.ReportSourceIdentity("b" * 40, "c" * 40, ()) - ok_cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n3-dd-z-jets-selected-flow" - ) - blocked_cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n4-dd-ttzh-jets-selected-flow" - ) - - def historical( - cell: CellSpec, - *, - status: str, - reusable: bool, - ) -> LightweightCurrent: - return LightweightCurrent( - cell_id=cell.cell_id, - attempt_id=f"historical-{status}", - result_path=tmp_path / f"{cell.cell_id}.json", - result={ - "status": status, - "provenance": {"report_source_revision": old_revision}, - }, - complete=reusable, - reusable=reusable, - reason=("historical source current" if reusable else "incomplete status"), - ) - - currents = { - ok_cell.cell_id: historical(ok_cell, status="ok", reusable=True), - blocked_cell.cell_id: historical( - blocked_cell, - status="skip", - reusable=False, - ), - } - planned = ( - manual_campaign.PlannedCell( - blocked_cell, - dependency=False, - baseline_cell_id=None, - rank=0, - optional_baseline_cell_id=( - "reference-amplicol-lc-n4-dd-ttzh-jets-selected-flow" - ), - ), - ) - _stub_run_campaign_boundaries( - monkeypatch, - tmp_path, - currents=currents, - planned=planned, - outcomes=(CellOutcome(blocked_cell.cell_id, "ok", "completed"),), - ) - monkeypatch.setattr( - manual_campaign, - "lightweight_currents", - lambda *_args, **kwargs: ( - dict(currents) if kwargs.get("accept_historical_source") else {} - ), - ) - requested: list[tuple[str, ...]] = [] - - def capture_plan(cells: tuple[CellSpec, ...], **_kwargs: object): - requested.append(tuple(cell.cell_id for cell in cells)) - return planned - - monkeypatch.setattr(manual_campaign, "plan_campaign", capture_plan) - - return_code = manual_campaign._run_campaign( - _parse("run", "--continue-across-revisions", "--no-dashboard"), - repo_root=ROOT, - service=service, - source=active_source, - cells=(ok_cell, blocked_cell), - palette=manual_campaign.Palette(False), - ) - - assert return_code == 0 - assert requested == [(blocked_cell.cell_id,)] - - -def test_run_campaign_recycled_cap_does_not_erase_newer_error( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - current = _capped_presentation_current(cell.cell_id, tmp_path) - error = _presentation_outcome(cell.cell_id, status="error") - manual_campaign._publish_presentation_outcome(service, error) - _stub_run_campaign_boundaries( - monkeypatch, - tmp_path, - currents={cell.cell_id: current}, - planned=(), - ) - - return_code = manual_campaign._run_campaign( - _parse("run", "--no-dashboard"), - repo_root=ROOT, - service=service, - source=manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()), - cells=(cell,), - palette=manual_campaign.Palette(False), - ) - - assert return_code == 0 - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - == error - ) - - -def test_catalog_static_na_takes_precedence_over_presentation_outcome( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - ) - caches, merged = _merge_lightweight_snapshot( - service, - {}, - {cell.cell_id: _presentation_outcome(cell.cell_id, status="error")}, - ) - - assert merged == 0 - assert ( - _cache_measurement( - caches, - dataset_id=cell.dataset_id, - cell_id=cell.cell_id, - ) - == empty_measurement() - ) - - -@pytest.mark.parametrize( - "status", - ( - "generation_limit", - "memory_limit", - "worker_timeout", - "profiling_timeout", - "validation_timeout", - "dependency", - "resource_frontier", - "error", - "validation_failed", - "blocked_dependency", - "skip", - "preparation_error", - "failed", - "unsupported", - "cancelled", - ), -) -def test_lease_manager_routes_every_started_terminal_status_to_presentation( - tmp_path: Path, - status: str, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - state = DashboardState( - instance_id=f"terminal-{status}", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(service, state) - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": status, - "detail": ( - "worker terminated by cancellation" - if status == "cancelled" - else "terminal outcome" - ), - "completed_at_ns": 123, - } - ) - - observed = manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - assert observed is not None - assert observed.status == status - assert observed.label == manual_campaign._humanized_outcome_label(status) - assert observed.attempt_id is None - assert observed.completed_at_ns == 123 - - -@pytest.mark.parametrize("status", ("ok", "reused", "skipped-current")) -def test_lease_manager_does_not_publish_success_without_reusable_ok_current( - tmp_path: Path, - status: str, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - lease = LeaseManager( - service, - DashboardState( - instance_id=f"terminal-{status}", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ), - ) - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": status, - "detail": "no reusable OK current exists", - "completed_at_ns": 123, - } - ) - - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - is None - ) - - -@pytest.mark.parametrize("raises", (False, True)) -def test_scheduler_finished_event_has_positive_completion_timestamp_after_started( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - raises: bool, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - events: list[dict[str, object]] = [] - campaign_lock = f"campaign-cell-{cell.cell_id}" - held: list[str] = [] - - class TrackingLock: - def __init__(self, name: str) -> None: - self.name = name - - def __enter__(self) -> None: - held.append(self.name) - - def __exit__( - self, - _error_type: object, - _error: object, - _traceback: object, - ) -> None: - assert held.pop() == self.name - - monkeypatch.setattr( - service.store, - "named_lock", - lambda name, **_kwargs: TrackingLock(name), - ) - - def observe(payload: object) -> None: - assert isinstance(payload, dict) - if payload.get("event") == "finished": - assert campaign_lock in held - events.append(dict(payload)) - - scheduler = manual_campaign.CampaignScheduler( - service, - settings=manual_campaign.CampaignSettings( - source_identity_override=manual_campaign.ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - progress_observer=observe, - ), - ) - planned = manual_campaign.PlannedCell( - cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - def run_in_lane(_planned: manual_campaign.PlannedCell) -> CellOutcome: - scheduler._observe("started", cell, dependency=False) - if raises: - raise RuntimeError("synthetic worker failure") - return CellOutcome(cell.cell_id, "ok", "completed") - - monkeypatch.setattr(scheduler, "_run_cell_in_lane", run_in_lane) - before = time.time_ns() - if raises: - with pytest.raises(RuntimeError, match="synthetic worker failure"): - scheduler._run_cell(planned) - else: - assert scheduler._run_cell(planned).status == "ok" - after = time.time_ns() - - assert [event["event"] for event in events] == ["started", "finished"] - finished = events[-1] - assert isinstance(finished["completed_at_ns"], int) - assert before <= finished["completed_at_ns"] <= after - assert finished["status"] == ("error" if raises else "ok") - - -def test_scheduler_finished_event_forwards_terminal_detail( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - events: list[dict[str, object]] = [] - scheduler = manual_campaign.CampaignScheduler( - service, - settings=manual_campaign.CampaignSettings( - source_identity_override=manual_campaign.ReportSourceIdentity( - "a" * 40, "b" * 40, () - ), - progress_observer=lambda payload: events.append(dict(payload)), - ), - ) - monkeypatch.setattr(scheduler, "_coordination_lock_names", lambda _cell: ()) - monkeypatch.setattr( - scheduler, - "_run_cell_in_lane", - lambda _planned: CellOutcome( - cell.cell_id, - ResultStatus.VALIDATION_FAILED.value, - "00000000-0000-4000-8000-000000000088", - terminal_detail="resolved component sum disagrees with total", - ), - ) - - scheduler._run_cell(manual_campaign.PlannedCell(cell, False, None, 0)) - - finished = [event for event in events if event["event"] == "finished"] - assert len(finished) == 1 - assert finished[0]["terminal_detail"] == ( - "resolved component sum disagrees with total" - ) - - -def test_scheduler_inner_coordination_deferred_emits_no_finished_event( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - events: list[dict[str, object]] = [] - scheduler = manual_campaign.CampaignScheduler( - _manual_service(tmp_path), - settings=manual_campaign.CampaignSettings( - source_identity_override=manual_campaign.ReportSourceIdentity( - "a" * 40, "b" * 40, () - ), - progress_observer=lambda payload: events.append(dict(payload)), - ), - ) - planned = manual_campaign.PlannedCell( - _presentation_test_cell(), False, None, 0 - ) - monkeypatch.setattr(scheduler, "_coordination_lock_names", lambda _cell: ()) - monkeypatch.setattr( - scheduler, - "_run_cell_in_lane", - lambda _planned: (_ for _ in ()).throw(_CoordinationDeferred("inner")), - ) - - with pytest.raises(_CoordinationDeferred, match="inner"): - scheduler._run_cell(planned) - - assert [event for event in events if event["event"] == "finished"] == [] - - -def test_scheduler_inner_lock_cancel_emits_one_cancelled_and_no_presentation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - events: list[dict[str, object]] = [] - lease = LeaseManager( - service, - DashboardState( - instance_id="inner-lock-cancel", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ), - ) - - def observe(payload: object) -> None: - assert isinstance(payload, dict) - events.append(dict(payload)) - lease.observe(payload) - - scheduler = manual_campaign.CampaignScheduler( - service, - settings=manual_campaign.CampaignSettings( - source_identity_override=manual_campaign.ReportSourceIdentity( - "a" * 40, "b" * 40, () - ), - progress_observer=observe, - ), - ) - planned = manual_campaign.PlannedCell(cell, False, None, 0) - monkeypatch.setattr(scheduler, "_coordination_lock_names", lambda _cell: ()) - monkeypatch.setattr( - scheduler, - "_run_cell_in_lane", - lambda _planned: (_ for _ in ()).throw(LockCancelledError("cancelled")), - ) - - outcome = scheduler._run_cell(planned) - - finished = [event for event in events if event["event"] == "finished"] - assert [(event["status"], event["detail"]) for event in finished] == [ - ("cancelled", "lock wait cancelled") - ] - assert not any(event.get("status") == "error" for event in events) - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - is None - ) - assert outcome == CellOutcome(cell.cell_id, "cancelled", "lock wait cancelled") - - -@pytest.mark.parametrize( - ("status", "detail"), - ( - (ResultStatus.NOT_AVAILABLE.value, "canonical reset"), - ("cancelled", "not started"), - ("cancelled", "lock wait cancelled"), - ), -) -def test_lease_manager_does_not_publish_non_attempt_outcomes( - tmp_path: Path, - status: str, - detail: str, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - lease = LeaseManager( - service, - DashboardState( - instance_id="non-attempt", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ), - ) - - lease.observe( - { - "event": "finished", - "cell_id": cell.cell_id, - "status": status, - "detail": detail, - "completed_at_ns": 123, - } - ) - - assert ( - manual_campaign.lightweight_presentation_outcome( - service, - cell, - source_revision="a" * 40, - ) - is None - ) - - -def test_lease_publication_uses_runtime_revision_without_checkout_git( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="installed", - selected_ids=(), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - - def forbidden(_repo_root: Path) -> str: - raise AssertionError("installed campaign lease inspected checkout Git") - - monkeypatch.setattr(manual_campaign, "_repo_head", forbidden) - lease = LeaseManager(service, state) - lease.publish() - - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["source_revision"] == "a" * 40 - - -def _environment_witness_current( - tmp_path: Path, - *, - cell_id: str, - source_revision: str, - native_extension_sha256: str = "b" * 64, - numpy_version: str | None = None, -) -> LightweightCurrent: - runtime = { - "source_revision": source_revision, - "package_version": "0.1.4", - "python_package_tree": {"sha256": "a" * 64}, - "candidate_build_identity": { - "candidate_fingerprint": "candidate-test", - "source_revision": source_revision, - "publishable": False, - }, - "candidate_build_identity_sha256": "c" * 64, - "native_build_inputs_sha256": "d" * 64, - "native_extension": { - "sha256": native_extension_sha256, - "package_version": "0.1.4", - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": ["neon"], - }, - } - provenance = { - "report_source_revision": source_revision, - "platform": "MeasuredOS 1.0; witness", - "machine": "measured-machine", - "processor": "measured-processor", - "python": "3.11.9", - "runtime_identity": runtime, - } - if numpy_version is not None: - provenance["numpy"] = numpy_version - return LightweightCurrent( - cell_id=cell_id, - attempt_id=f"attempt-{cell_id}", - result_path=tmp_path / f"{cell_id}.json", - result={ - "status": ResultStatus.OK.value, - "provenance": provenance, - }, - complete=True, - reusable=True, - reason="reusable", - ) - - -def test_environment_witness_is_active_source_and_consistent(tmp_path: Path) -> None: - active_revision = "a" * 40 - assert ( - manual_campaign._active_environment_runtime_witness( - {}, - source_revision=active_revision, - ) - is None - ) - historical = _environment_witness_current( - tmp_path, - cell_id="historical", - source_revision="b" * 40, - ) - first = _environment_witness_current( - tmp_path, - cell_id="first", - source_revision=active_revision, - ) - second = _environment_witness_current( - tmp_path, - cell_id="second", - source_revision=active_revision, - ) - - selected = manual_campaign._active_environment_runtime_witness( - { - historical.cell_id: historical, - first.cell_id: first, - second.cell_id: second, - }, - source_revision=active_revision, - ) - - assert selected is not None - assert selected.active_runtime == first.result["provenance"]["runtime_identity"] - assert selected.host_environment == { - "platform": "MeasuredOS 1.0; witness", - "machine": "measured-machine", - "processor": "measured-processor", - "python": "3.11.9", - "python_implementation": "CPython", - "numpy": manual_campaign._UNRECORDED_MEASUREMENT_NUMPY, - } - legacy_environment = workspace_module._authenticated_environment_payload( - "portable-campaign", - expected_source_revision=active_revision, - active_runtime=selected.active_runtime, - host_environment=selected.host_environment, - ) - assert "NumPy unavailable (not recorded by measurement)" in ( - workspace_module._environment_tex(legacy_environment) - ) - assert ( - manual_campaign._active_environment_runtime_witness( - {historical.cell_id: historical}, - source_revision=active_revision, - ) - is None - ) - - conflicting = _environment_witness_current( - tmp_path, - cell_id="conflicting", - source_revision=active_revision, - native_extension_sha256="e" * 64, - ) - with pytest.raises(ManualCampaignError, match="currents disagree"): - manual_campaign._active_environment_runtime_witness( - { - first.cell_id: first, - conflicting.cell_id: conflicting, - }, - source_revision=active_revision, - ) - - for candidate_revision in (None, "b" * 40): - malformed = _environment_witness_current( - tmp_path, - cell_id=f"malformed-{candidate_revision}", - source_revision=active_revision, - ) - runtime = malformed.result["provenance"]["runtime_identity"] - candidate = runtime["candidate_build_identity"] - if candidate_revision is None: - candidate.pop("source_revision") - else: - candidate["source_revision"] = candidate_revision - with pytest.raises(ManualCampaignError, match="build identity"): - manual_campaign._active_environment_runtime_witness( - {malformed.cell_id: malformed}, - source_revision=active_revision, - ) - - -def test_read_only_views_use_recorded_measurement_source_epoch( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path, initialize_source_marker=False) - checkout_revision = "b" * 40 - measurement_revision = "a" * 40 - assert ( - manual_campaign.recorded_measurement_source_revision( - service, - checkout_revision=checkout_revision, - ) - == checkout_revision - ) - - marker = service.paths.coordination_root / "manual-source.json" - marker.parent.mkdir(parents=True, exist_ok=True) - marker.write_text( - json.dumps( - { - "schema": manual_campaign.SOURCE_MARKER_SCHEMA, - "source_revision": measurement_revision, - } - ), - encoding="utf-8", - ) - assert ( - manual_campaign.recorded_measurement_source_revision( - service, - checkout_revision=checkout_revision, - ) - == measurement_revision - ) - - observed: list[tuple[str, bool]] = [] - - def stop_after_source_selection( - _service: ReportService, - *, - source_revision: str, - accept_historical_source: bool = False, - ) -> object: - observed.append((source_revision, accept_historical_source)) - raise RuntimeError("snapshot stopped after source selection") - - monkeypatch.setattr( - manual_campaign, - "_capture_lightweight_snapshot", - stop_after_source_selection, - ) - source = manual_campaign.ReportSourceIdentity( - checkout_revision, - "c" * 40, - (), - ) - with pytest.raises(RuntimeError, match="snapshot stopped"): - manual_campaign._refresh_pdf( - _parse("refresh-pdf", "--quiet"), - service=service, - source=source, - palette=manual_campaign.Palette(False), - ) - assert observed == [(measurement_revision, False)] - - -def test_cross_revision_policy_persists_for_inspect_and_refresh( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path, initialize_source_marker=False) - source = manual_campaign.ReportSourceIdentity( - "a" * 40, - "c" * 40, - (), - ) - - manual_campaign.update_source_marker( - service, - source, - continue_across_revisions=True, - ) - policy = manual_campaign.recorded_measurement_source_policy( - service, - checkout_revision="b" * 40, - ) - - assert policy.source_revision == source.revision - assert policy.continue_across_revisions - marker = json.loads( - (service.paths.coordination_root / "manual-source.json").read_text( - encoding="utf-8" - ) - ) - assert marker["continue_across_revisions"] is True - - observed: list[tuple[str, bool]] = [] - - def stop_after_source_selection( - _service: ReportService, - *, - source_revision: str, - accept_historical_source: bool = False, - ) -> object: - observed.append((source_revision, accept_historical_source)) - raise RuntimeError("mixed snapshot selected") - - monkeypatch.setattr( - manual_campaign, - "_capture_lightweight_snapshot", - stop_after_source_selection, - ) - with pytest.raises(RuntimeError, match="mixed snapshot selected"): - manual_campaign._refresh_pdf( - _parse("refresh-pdf", "--quiet"), - service=service, - source=manual_campaign.ReportSourceIdentity( - "b" * 40, - "d" * 40, - (), - ), - palette=manual_campaign.Palette(False), - ) - assert observed == [(source.revision, True)] - - -def test_refresh_renders_outcomes_without_serializing_them_as_results( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _manual_service(tmp_path) - cell = _presentation_test_cell() - outcome = _presentation_outcome(cell.cell_id, status="error") - observed: dict[str, str] = {} - original_render = ReportService._render_tables - - monkeypatch.setattr( - manual_campaign, - "_capture_lightweight_snapshot", - lambda *_args, **_kwargs: ({}, {cell.cell_id: outcome}, ()), - ) - monkeypatch.setattr( - manual_campaign, - "_copy_report_sources", - lambda _source, destination: destination.mkdir(parents=True), - ) - monkeypatch.setattr( - manual_campaign, - "_stage_copied_profile_identity", - lambda *_args, **_kwargs: None, - ) - - def capture_render( - staging_service: ReportService, - caches: dict[str, dict[str, object]], - ) -> dict[str, str]: - observed["render_caches"] = json.dumps(caches, sort_keys=True) - tables = original_render(staging_service, caches) - observed["tables"] = "\n".join(tables.values()) - return tables - - def capture_snapshot( - _staging_service: ReportService, - caches: dict[str, dict[str, object]], - tables: dict[str, str], - ) -> tuple[Path, ...]: - observed["snapshot_caches"] = json.dumps(caches, sort_keys=True) - observed["snapshot_tables"] = "\n".join(tables.values()) - return () - - monkeypatch.setattr(ReportService, "_render_tables", capture_render) - monkeypatch.setattr(ReportService, "_snapshot_files", capture_snapshot) - monkeypatch.setattr(manual_campaign, "_compile_pdf", lambda *_a, **_k: 59) - monkeypatch.setattr( - manual_campaign, - "_install_report_snapshot", - lambda *_args, **_kwargs: None, - ) - - assert ( - manual_campaign._refresh_pdf( - _parse("refresh-pdf", "--quiet"), - service=service, - source=manual_campaign.ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - palette=manual_campaign.Palette(False), - ) - == 0 - ) - - failure_kind = "ManualCampaignOutcome:error" - status_tex = r"\matrixstatus{ReportRed}{error}" - assert failure_kind in observed["render_caches"] - assert status_tex in observed["tables"] - assert failure_kind not in observed["snapshot_caches"] - assert status_tex in observed["snapshot_tables"] - - -def test_malformed_measurement_source_marker_is_not_guessed(tmp_path: Path) -> None: - service = _manual_service(tmp_path, initialize_source_marker=False) - marker = service.paths.coordination_root / "manual-source.json" - marker.parent.mkdir(parents=True, exist_ok=True) - marker.write_text( - json.dumps( - { - "schema": manual_campaign.SOURCE_MARKER_SCHEMA, - "source_revision": "short", - } - ), - encoding="utf-8", - ) - with pytest.raises(ManualCampaignError, match="source marker is malformed"): - manual_campaign.recorded_measurement_source_revision( - service, - checkout_revision="b" * 40, - ) - - -def _write_lease( - service: ReportService, - *, - instance_id: str, - source_revision: str, - updated_at: float, - workers: dict[str, dict[str, object]], - counters: dict[str, int] | None = None, - limits: dict[str, object] | None = None, - started_at: float | None = None, - schema: object = MANUAL_STATE_SCHEMA, -) -> None: - path = service.paths.coordination_root / "manual-leases" / f"{instance_id}.json" - path.parent.mkdir(parents=True, exist_ok=True) - if counters is None: - active = sum( - worker.get("status") in {"queued", "preparing", "running"} - for worker in workers.values() - ) - counters = { - "selected": len(workers), - "recycled": 0, - "active": active, - "selected_active": active, - "dependency_active": 0, - "completed": 0, - "remaining": len(workers), - "static_na": 0, - "capped": 0, - "failed": 0, - "unverified": 0, - "dependency_only": 0, - "dependency_completed": 0, - "dependency_issues": 0, - } - path.write_text( - json.dumps( - { - "schema": schema, - "instance_id": instance_id, - "source_revision": source_revision, - "started_at": updated_at if started_at is None else started_at, - "updated_at": updated_at, - "counters": counters, - **({} if limits is None else {"limits": limits}), - "workers": workers, - } - ), - encoding="utf-8", - ) - - -def test_peer_leases_merge_by_sha_without_accumulating_or_double_counting( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="local", - selected_ids=("cell-a", "cell-b"), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - workers={"cell-a": WorkerView("cell-a", status="running")}, - ) - lease = LeaseManager(service, state) - now = time.time() - active_worker = { - "cell_id": "cell-a", - "status": "running", - "phase": "generation", - "step": "generating", - "progress_task_id": "generation:recurrence:rust-builder", - "progress_details": { - "current_count": 38_581, - "contribution_count": 286_294, - }, - "updated_at": now, - } - _write_lease( - service, - instance_id="peer-one", - source_revision=state.source_revision, - updated_at=now, - workers={"cell-a": active_worker}, - ) - _write_lease( - service, - instance_id="peer-two", - source_revision=state.source_revision, - updated_at=now, - workers={"cell-b": active_worker | {"cell_id": "cell-b"}}, - ) - _write_lease( - service, - instance_id="wrong-source", - source_revision="b" * 40, - updated_at=now, - workers={"cell-b": active_worker | {"cell_id": "cell-b"}}, - ) - _write_lease( - service, - instance_id="stale", - source_revision=state.source_revision, - updated_at=0.0, - workers={"cell-b": active_worker | {"cell_id": "cell-b"}}, - ) - - first = lease.dashboard_snapshot() - second = lease.dashboard_snapshot() - - expected_keys = { - "cell-a", - "peer:peer-one:cell-a", - "peer:peer-two:cell-b", - } - assert set(first.workers) == expected_keys - assert set(second.workers) == expected_keys - peer = first.workers["peer:peer-one:cell-a"] - assert peer.progress_task_id == "generation:recurrence:rust-builder" - assert peer.progress_details == { - "current_count": 38_581, - "contribution_count": 286_294, - } - assert first.counters()["active"] == 1 - assert first.counters()["remaining"] == 2 - assert len(first.peer_active) == 2 - assert "Peer active 2" in render_dashboard_frame(first, width=120, height=36) - - lease.publish() - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["counters"]["active"] == 1 - - -def test_lease_manager_publishes_effective_invocation_caps( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="bounded-smoke", - selected_ids=("cell-a",), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - generation_time_limit_seconds=600.0, - memory_limit_bytes=30_000_000_000, - worker_wall_limit_seconds=1200.0, - ) - lease = LeaseManager(service, state) - - lease.publish() - - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["limits"] == { - "generation_time_limit_seconds": 600.0, - "memory_limit_bytes": 30_000_000_000, - "worker_wall_limit_seconds": 1200.0, - } - - -def test_preflight_completion_removes_only_matching_transient_worker( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - state = DashboardState( - instance_id="preflight-lifecycle", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(service, state) - attempt_id = "prepared-model-builtin_sm" - - lease.observe({"event": "started", "cell_id": cell.cell_id}) - lease.observe( - { - "event": "worker", - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - } - ) - - assert state.counters()["active"] == 1 - lease.observe( - { - "event": "preflight-finished", - "cell_id": cell.cell_id, - "attempt_id": "different-attempt", - } - ) - assert cell.cell_id in state.workers - - lease.observe( - { - "event": "preflight-finished", - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - } - ) - - assert cell.cell_id not in state.workers - assert state.completed_ids == set() - assert state.recycled_ids == set() - assert state.failed_ids == set() - assert state.counters()["active"] == 0 - assert state.counters()["completed"] == 0 - assert state.counters()["remaining"] == 1 - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["workers"] == {} - - -def test_scheduler_state_is_visible_and_persisted_without_creating_worker_rows( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="scheduler-state", - selected_ids=("cell-a", "cell-b", "cell-c"), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(service, state) - - lease.observe( - { - "event": "scheduler-state", - "ready": 1, - "waiting_dependency": 1, - "waiting_coordination_lock": 1, - } - ) - - assert state.workers == {} - assert (state.ready_count, state.waiting_dependency_count) == (1, 1) - assert state.waiting_coordination_lock_count == 1 - frame = render_dashboard_frame(state, width=120, height=36) - assert "Ready 1" in frame - assert "Waiting dependency 1" in frame - assert "Waiting coordination lock 1" in frame - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["scheduler"] == { - "ready": 1, - "waiting_dependency": 1, - "waiting_coordination_lock": 1, - } - - -def test_blocked_dependency_dashboard_retains_exact_prerequisite_ids( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell_id = "matrix-compiled-builtin-sm-lc-n1-dd-z-jets-selected-flow" - prerequisite = "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow" - state = DashboardState( - instance_id="blocked-dependency", - selected_ids=(cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(service, state) - - lease.observe( - { - "event": "finished", - "cell_id": cell_id, - "status": "blocked_dependency", - "detail": "blocked by dependency", - "prerequisite_cell_ids": (prerequisite,), - } - ) - - worker = state.workers[cell_id] - assert worker.blocked_prerequisite_ids == (prerequisite,) - assert prerequisite in render_dashboard_frame(state, width=160, height=48) - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["workers"][cell_id]["blocked_prerequisite_ids"] == [prerequisite] - - -def test_active_lease_recipe_uses_effective_invocation_settings( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - defaults = ReproductionSettings() - assert ( - defaults.cores, - defaults.target_runtime, - defaults.batch_size, - defaults.warmups, - defaults.minimum_samples, - ) == (1, 5.0, 128, 2, 5) - state = DashboardState( - instance_id="recipe-settings", - selected_ids=(cell.cell_id,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - reproduction_settings=ReproductionSettings( - cores=3, - target_runtime=0.5, - batch_size=16, - warmups=1, - minimum_samples=7, - ), - ) - lease = LeaseManager(service, state) - - lease.observe({"event": "started", "cell_id": cell.cell_id}) - - worker = lease.dashboard_snapshot().workers[cell.cell_id] - assert worker.reproduce_generate is not None - assert "--workers 3" in worker.reproduce_generate - assert "--cores 3" in worker.reproduce_generate - assert "--batch-size 16" in worker.reproduce_generate - assert worker.reproduce_profile is not None - assert "--target-runtime 0.5" in worker.reproduce_profile - assert "--batch-size 16" in worker.reproduce_profile - assert "--warmup-runs 1" in worker.reproduce_profile - assert "--minimum-samples 7" in worker.reproduce_profile - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert "reproduction_settings" not in payload - assert ( - payload["workers"][cell.cell_id]["reproduce_profile"] - == worker.reproduce_profile - ) - - -def test_live_dashboard_snapshot_selects_instance_and_shows_same_source_peers( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - now = 50_000.0 - source_revision = "a" * 40 - counters = { - "selected": 9, - "recycled": 3, - "active": 2, - "selected_active": 1, - "dependency_active": 1, - "completed": 1, - "remaining": 2, - "static_na": 1, - "capped": 1, - "failed": 0, - "unverified": 0, - "dependency_only": 2, - "dependency_completed": 1, - "dependency_issues": 0, - } - _write_lease( - service, - instance_id="primary-7f91c2", - source_revision=source_revision, - started_at=now - 65.0, - updated_at=now - 1.0, - counters=counters, - workers={ - "matrix-primary": { - "cell_id": "matrix-primary", - "status": "running", - "phase": "profiling", - "step": "sample 4/8", - "pid": 4100, - "member_pids": [4100, 4101], - "wall_seconds": 64.0, - "cpu_seconds": 91.0, - "current_rss_bytes": 2_500_000_000, - "peak_rss_bytes": 3_000_000_000, - "progress_completed": 4, - "progress_total": 8, - "events": ["profiling: sample 4/8"], - } - }, - ) - _write_lease( - service, - instance_id="peer-81ab", - source_revision=source_revision, - updated_at=now - 2.0, - workers={ - "scalar-peer": { - "cell_id": "scalar-peer", - "status": "running", - "phase": "generation", - "step": "gravity model generation", - "pid": 4200, - }, - "finished-peer": { - "cell_id": "finished-peer", - "status": "ok", - "phase": "completed", - "step": "published", - }, - }, - ) - _write_lease( - service, - instance_id="foreign-newer", - source_revision="b" * 40, - updated_at=now - 0.5, - workers={ - "foreign": { - "cell_id": "foreign", - "status": "running", - } - }, - ) - - state = _live_dashboard_snapshot( - service.paths.coordination_root, - instance="primary-7", - stale_after_seconds=15.0, - now=now, - ) - - assert state.live_snapshot - assert state.instance_id == "primary-7f91c2" - assert state.source_revision == source_revision - assert state.started_at == now - 65.0 - assert state.lease_updated_at == now - 1.0 - assert state.counters() == counters - assert set(state.workers) == { - "matrix-primary", - "peer:peer-81ab:scalar-peer", - } - peer = state.workers["peer:peer-81ab:scalar-peer"] - assert peer.peer_instance == "peer-81ab" - frame = render_dashboard_frame(state, width=160, height=48) - assert "LIVE pyAmpliCol profiling campaign" in frame - assert "primary-7f91" in frame - assert "Selected 9" in frame - assert "Recycled 3" in frame - assert "Remaining 2" in frame - assert "matrix-primary" in frame - assert "scalar-peer" in frame - - -@pytest.mark.parametrize(("width", "height"), ((80, 24), (120, 36), (160, 48))) -def test_live_dashboard_snapshot_renders_effective_invocation_caps( - tmp_path: Path, - width: int, - height: int, -) -> None: - service = _manual_service(tmp_path) - now = 60_000.0 - _write_lease( - service, - instance_id="bounded-smoke", - source_revision="b" * 40, - updated_at=now - 1.0, - limits={ - "generation_time_limit_seconds": 600.0, - "memory_limit_bytes": 30_000_000_000, - "worker_wall_limit_seconds": 1200.0, - }, - workers={ - "scalar-gravity": { - "cell_id": "scalar-gravity", - "status": "running", - "phase": "generation", - "step": "building scalar-gravity evaluator", - } - }, - ) - - state = _live_dashboard_snapshot( - service.paths.coordination_root, - instance="bounded", - stale_after_seconds=15.0, - now=now, - ) - - assert state.generation_time_limit_seconds == 600.0 - assert state.memory_limit_bytes == 30_000_000_000 - assert state.worker_wall_limit_seconds == 1200.0 - frame = render_dashboard_frame(state, width=width, height=height) - assert "Caps Generation 00:10:00" in frame - assert "RAM 30.00 GB" in frame - assert "Total wall 00:20:00" in frame - - -def test_live_snapshot_command_is_read_only_and_lease_only( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - docs = tmp_path / "docs/performance_reports/macbook_M3_manual" - docs.mkdir(parents=True) - service = ReportService(manual_campaign._campaign_report_paths(tmp_path, docs)) - now = time.time() - _write_lease( - service, - instance_id="lease-only-instance", - source_revision="c" * 40, - started_at=now - 3.0, - updated_at=now, - counters={ - "selected": 3, - "recycled": 1, - "active": 1, - "selected_active": 1, - "dependency_active": 0, - "completed": 0, - "remaining": 2, - "static_na": 0, - "capped": 0, - "failed": 0, - "unverified": 0, - "dependency_only": 1, - "dependency_completed": 0, - "dependency_issues": 0, - }, - workers={ - "gravity-cell": { - "cell_id": "gravity-cell", - "status": "running", - "phase": "generation", - "step": "building scalar-gravity evaluator", - "pid": 4300, - } - }, - ) - lease_files = tuple( - sorted((service.paths.coordination_root / "manual-leases").glob("*.json")) - ) - before = {path: path.read_bytes() for path in lease_files} - - def forbidden(*_args: object, **_kwargs: object) -> object: - raise AssertionError("live snapshot escaped the lease-only read path") - - monkeypatch.setattr(manual_campaign, "_repo_head", forbidden) - monkeypatch.setattr(manual_campaign, "lightweight_source_identity", forbidden) - monkeypatch.setattr(manual_campaign, "lightweight_currents", forbidden) - monkeypatch.setattr(manual_campaign, "_capture_lightweight_snapshot", forbidden) - - result = campaign_main( - ( - "dashboard-snapshot", - "--live", - "--instance", - "lease-only", - "--width", - "120", - "--height", - "36", - ), - repo_root=tmp_path, - docs_dir=docs, - ) - - assert result == 0 - output = capsys.readouterr().out - assert "LIVE pyAmpliCol profiling campaign" in output - assert "gravity-cell" in output - assert {path: path.read_bytes() for path in lease_files} == before - - -def test_live_snapshot_rejects_stale_malformed_and_ambiguous_leases( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - now = 70_000.0 - worker = {"cell": {"cell_id": "cell", "status": "running"}} - _write_lease( - service, - instance_id="stale", - source_revision="a" * 40, - updated_at=now - 20.0, - workers=worker, - ) - _write_lease( - service, - instance_id="wrong-schema", - source_revision="a" * 40, - updated_at=now, - workers=worker, - schema="unknown-state-v0", - ) - with pytest.raises(ManualCampaignError, match="no active manual-campaign lease"): - _live_dashboard_snapshot( - service.paths.coordination_root, - instance=None, - stale_after_seconds=15.0, - now=now, - ) - - for suffix in ("one", "two"): - _write_lease( - service, - instance_id=f"shared-{suffix}", - source_revision="a" * 40, - updated_at=now, - workers=worker, - ) - with pytest.raises(ManualCampaignError, match="ambiguous"): - _live_dashboard_snapshot( - service.paths.coordination_root, - instance="shared-", - stale_after_seconds=15.0, - now=now, - ) - with pytest.raises(ManualCampaignError, match="positive finite"): - _live_dashboard_snapshot( - service.paths.coordination_root, - instance=None, - stale_after_seconds=0.0, - now=now, - ) - - -def test_dashboard_snapshot_help_explains_synthetic_and_live_modes( - capsys: pytest.CaptureFixture[str], -) -> None: - with pytest.raises(SystemExit) as exit_info: - build_parser().parse_args(("dashboard-snapshot", "--help")) - assert exit_info.value.code == 0 - output = capsys.readouterr().out - for fragment in ( - "deterministic synthetic fixture", - "--live", - "--instance", - "unique prefix", - "--stale-after", - "does not inspect results, artifacts, source identity, or Git", - "never guessed or double-counted", - ): - assert fragment in output - - -def test_dashboard_snapshot_default_does_not_read_live_leases( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - def forbidden(*_args: object, **_kwargs: object) -> DashboardState: - raise AssertionError("deterministic snapshot read a live lease") - - monkeypatch.setattr(manual_campaign, "_live_dashboard_snapshot", forbidden) - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - result = campaign_main( - ("dashboard-snapshot", "--width", "80", "--height", "24"), - repo_root=ROOT, - docs_dir=docs_dir, - ) - assert result == 0 - output = capsys.readouterr().out - assert "pyAmpliCol profiling campaign" in output - assert "LIVE Manual" not in output - - -def test_installed_run_disables_dashboard_when_optional_bindings_are_missing( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr( - manual_campaign, - "_missing_ratatui_bindings", - lambda: ("ratatui", "ratatui_py"), - ) - arguments = _parse("run", "--dry-run") - - changed = manual_campaign._configure_dashboard_capability( - arguments, - installed=True, - ) - - assert changed is True - assert arguments.no_dashboard is True - - -def test_installed_campaign_uses_copied_local_amplicol_and_explicit_override( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - configured = (tmp_path / "configured-amplicol").resolve() - override = (tmp_path / "override-amplicol").resolve() - (docs_dir / ".pyamplicol-original-amplicol").write_text( - f"{configured}\n", - encoding="utf-8", - ) - observed: list[Path] = [] - - def validate(path: Path) -> tuple[Path, str]: - observed.append(path) - return path, "a" * 40 - - monkeypatch.setattr( - manual_campaign, - "_validated_original_amplicol_checkout", - validate, - ) - - legacy = next( - candidate - for candidate in REPORT_CATALOG.measurement_cells() - if candidate.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - planned = (manual_campaign.PlannedCell(legacy, False, None, 0),) - arguments = _parse("run") - manual_campaign._bind_original_amplicol_if_required( - arguments, - planned, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - assert arguments.original_amplicol == configured - assert arguments.original_amplicol_revision == "a" * 40 - - arguments.original_amplicol = override - manual_campaign._bind_original_amplicol_if_required( - arguments, - planned, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - assert arguments.original_amplicol == override - assert arguments.original_amplicol_revision == "a" * 40 - assert observed == [configured, override] - - -def test_installed_campaign_resolves_saved_madgraph_and_explicit_override( - tmp_path: Path, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - configured = tmp_path / "configured-madgraph" - override = tmp_path / "override-madgraph" - for installation in (configured, override): - executable = installation / "bin/mg5_aMC" - executable.parent.mkdir(parents=True) - executable.write_text("#!/bin/sh\n", encoding="ascii") - executable.chmod(0o755) - (docs_dir / ".pyamplicol-madgraph").write_text( - f"{configured.resolve()}\n", - encoding="utf-8", - ) - - arguments = _parse("run") - assert ( - manual_campaign._resolve_madgraph( - arguments, - installed=True, - docs_dir=docs_dir, - ) - == configured.resolve() - ) - assert ( - manual_campaign._resolve_madgraph( - arguments, - installed=False, - docs_dir=docs_dir, - ) - is None - ) - - arguments.madgraph = override - assert ( - manual_campaign._resolve_madgraph( - arguments, - installed=True, - docs_dir=docs_dir, - ) - == override.resolve() - ) - - -def test_madgraph_validation_requires_regular_executable_mg5( - tmp_path: Path, -) -> None: - installation = tmp_path / "madgraph" - executable = installation / "bin/mg5_aMC" - executable.parent.mkdir(parents=True) - - with pytest.raises(ManualCampaignError, match="regular executable bin/mg5_aMC"): - manual_campaign._validated_madgraph_installation(installation) - - executable.write_text("#!/bin/sh\n", encoding="ascii") - executable.chmod(0o644) - with pytest.raises(ManualCampaignError, match="regular executable bin/mg5_aMC"): - manual_campaign._validated_madgraph_installation(installation) - - executable.chmod(0o755) - assert ( - manual_campaign._validated_madgraph_installation(installation) - == installation.resolve() - ) - - executable.unlink() - target = tmp_path / "mg5_aMC-target" - target.write_text("#!/bin/sh\n", encoding="ascii") - target.chmod(0o755) - executable.symlink_to(target) - with pytest.raises(ManualCampaignError, match="regular executable bin/mg5_aMC"): - manual_campaign._validated_madgraph_installation(installation) - - -def test_saved_madgraph_configuration_is_one_absolute_regular_line( - tmp_path: Path, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - config = docs_dir / ".pyamplicol-madgraph" - config.write_text("relative/path\n", encoding="utf-8") - with pytest.raises(ManualCampaignError, match="configuration is invalid"): - manual_campaign._configured_madgraph(docs_dir) - - config.unlink() - target = tmp_path / "madgraph-config" - target.write_text(f"{tmp_path.resolve()}\n", encoding="utf-8") - config.symlink_to(target) - with pytest.raises(ManualCampaignError, match="not a regular file"): - manual_campaign._configured_madgraph(docs_dir) - - -def test_original_amplicol_planning_availability_is_cheap_and_explicit( - tmp_path: Path, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - arguments = _parse("run", "--generation-engine", "compiled") - - assert not manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - - configured = tmp_path / "configured-amplicol" - configured.mkdir() - (docs_dir / ".pyamplicol-original-amplicol").write_text( - f"{configured.resolve()}\n", - encoding="utf-8", - ) - assert manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - - configured.rmdir() - assert not manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - - (docs_dir / ".pyamplicol-original-amplicol").write_text( - "not-an-absolute-path\n", - encoding="utf-8", - ) - assert not manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - arguments.no_dependencies_added = True - assert not manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - arguments.no_dependencies_added = False - - contributor = tmp_path / "dependencies/checkouts/legacy-amplicol" - contributor.mkdir(parents=True) - assert manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=False, - root=tmp_path, - docs_dir=docs_dir, - ) - - arguments.original_amplicol = tmp_path / "explicit-amplicol" - assert manual_campaign._original_amplicol_available_for_planning( - arguments, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - - -@pytest.mark.parametrize( - "cell_id", - ( - "matrix-recurrence-builtin-sm-lc-n4-dd-ttzh-jets-all-flow", - "matrix-compiled-builtin-sm-lc-n4-dd-ttzh-jets-selected-flow", - ), -) -def test_pyamplicol_only_opt_out_plan_and_binding_need_no_original_checkout( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - cell_id: str, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - service = _manual_service(tmp_path) - selected = REPORT_CATALOG.cell(cell_id) - planned = manual_campaign.plan_campaign( - (selected,), - store=service.store, - settings=manual_campaign.CampaignSettings(add_optional_dependencies=False), - ) - - assert planned - assert all( - item.cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - for item in planned - ) - assert any( - item.optional_baseline_cell_id is not None - or item.optional_comparison_peer_ids - for item in planned - ) - monkeypatch.setattr( - manual_campaign, - "_validated_original_amplicol_checkout", - lambda _path: pytest.fail("pyAmpliCol-only plan validated legacy checkout"), - ) - arguments = _parse( - "run", - "--generation-engine", - selected.measurement.execution_mode.value, - "--no-dependencies-added", - ) - - manual_campaign._bind_original_amplicol_if_required( - arguments, - planned, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - - assert arguments.original_amplicol is None - assert arguments.original_amplicol_revision is None - - -def test_direct_or_wildcard_amplicol_selection_still_requires_checkout( - tmp_path: Path, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - legacy = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and REPORT_CATALOG.static_na_reason(cell) is None - ) - planned = (manual_campaign.PlannedCell(legacy, False, None, 0),) - - with pytest.raises( - ManualCampaignError, - match="selection requires original AmpliCol", - ): - manual_campaign._bind_original_amplicol_if_required( - _parse("run"), - planned, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - _selection, wildcard_cells = selection_from_arguments(_parse("run", "--dry-run")) - assert any( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - for cell in wildcard_cells - ) - - -def test_saved_local_amplicol_is_not_validated_for_pyamplicol_only_work( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - docs_dir = tmp_path / "campaign" - docs_dir.mkdir() - missing = (tmp_path / "missing-amplicol").resolve() - (docs_dir / ".pyamplicol-original-amplicol").write_text( - f"{missing}\n", - encoding="utf-8", - ) - cell = next( - candidate - for candidate in REPORT_CATALOG.measurement_cells() - if candidate.measurement.execution_mode is ExecutionMode.RECURRENCE - ) - planned = (manual_campaign.PlannedCell(cell, False, None, 1),) - - monkeypatch.setattr( - manual_campaign, - "_validated_original_amplicol_checkout", - lambda _path: pytest.fail("unused legacy checkout was validated"), - ) - arguments = _parse("run") - - manual_campaign._bind_original_amplicol_if_required( - arguments, - planned, - installed=True, - root=tmp_path, - docs_dir=docs_dir, - ) - - assert arguments.original_amplicol is None - assert arguments.original_amplicol_revision is None - - -def test_source_run_does_not_probe_or_change_dashboard_capability( - monkeypatch: pytest.MonkeyPatch, -) -> None: - def forbidden() -> tuple[str, ...]: - raise AssertionError("source mode probed installed-wheel bindings") - - monkeypatch.setattr(manual_campaign, "_missing_ratatui_bindings", forbidden) - arguments = _parse("run", "--dry-run") - - changed = manual_campaign._configure_dashboard_capability( - arguments, - installed=False, - ) - - assert changed is False - assert arguments.no_dashboard is False - - -def test_installed_dashboard_snapshot_explains_optional_bindings( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - monkeypatch.setattr( - manual_campaign, - "_missing_ratatui_bindings", - lambda: ("ratatui_py",), - ) - (tmp_path / "campaign").mkdir() - - result = campaign_main( - ("dashboard-snapshot", "--no-color"), - repo_root=tmp_path, - docs_dir=tmp_path / "campaign", - installed=True, - ) - - assert result == 2 - error = capsys.readouterr().err - assert "contributor feature" in error - assert "ratatui_py" in error - assert "run --no-dashboard" in error - assert "just dev-install" in error - - -def test_finished_reuse_stays_recycled_while_work_and_caps_complete( - tmp_path: Path, -) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="local", - selected_ids=("reused", "skipped", "fresh", "capped"), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(service, state) - - for cell_id, status in ( - ("reused", "reused"), - ("skipped", "skipped-current"), - ("fresh", "ok"), - ("capped", "generation_limit"), - ): - lease.observe( - { - "event": "finished", - "cell_id": cell_id, - "status": status, - "detail": status, - } - ) - - assert state.completed_ids == {"fresh"} - assert state.capped_ids == {"capped"} - assert state.workers["reused"].status == "recycled" - assert state.workers["reused"].recycled - assert state.workers["skipped"].status == "recycled" - assert state.workers["skipped"].recycled - assert state.counters() == { - "selected": 4, - "recycled": 2, - "active": 0, - "selected_active": 0, - "dependency_active": 0, - "completed": 1, - "remaining": 0, - "static_na": 0, - "capped": 1, - "failed": 0, - "unverified": 0, - "dependency_only": 0, - "dependency_completed": 0, - "dependency_issues": 0, - } - - -def test_active_counter_includes_dependency_work_without_consuming_remaining() -> None: - state = DashboardState( - instance_id="dependency-active", - selected_ids=("direct-cell",), - recycled_ids=set(), - static_na_ids=set(), - dependency_ids={"dependency-cell"}, - workers={ - "dependency-cell": WorkerView( - "dependency-cell", - dependency=True, - status="running", - ) - }, - ) - - counters = state.counters() - - assert counters["active"] == 1 - assert counters["selected_active"] == 0 - assert counters["dependency_active"] == 1 - assert counters["remaining"] == 1 - assert counters["dependency_only"] == 1 - assert "Workers active 1" in render_dashboard_frame(state, width=120, height=36) - - -def test_replanned_selected_dependency_remains_in_selected_counter_scope() -> None: - state = DashboardState( - instance_id="selected-replanned-dependency", - selected_ids=("selected-cell",), - recycled_ids=set(), - static_na_ids=set(), - dependency_ids={"selected-cell"}, - workers={ - "selected-cell": WorkerView( - "selected-cell", - dependency=True, - status="running", - ) - }, - ) - - active = state.counters() - - assert active["active"] == 1 - assert active["selected_active"] == 1 - assert active["dependency_active"] == 0 - assert active["dependency_only"] == 0 - assert active["remaining"] == 1 - - state._reduce_finished("selected-cell", "ok") - finished = state.counters() - - assert finished["completed"] == 1 - assert finished["remaining"] == 0 - assert finished["dependency_completed"] == 0 - assert finished["dependency_issues"] == 0 - - -def test_worker_status_counters_include_dependency_only_rows_and_lease( - tmp_path: Path, -) -> None: - dependency_ids = { - "dependency-ok", - "dependency-cap", - "dependency-error", - "dependency-unverified", - "dependency-running", - } - state = DashboardState( - instance_id="dependency-status-counters", - selected_ids=("direct-cell",), - recycled_ids=set(), - static_na_ids=set(), - dependency_ids=dependency_ids, - source_revision="a" * 40, - ) - lease = LeaseManager(_manual_service(tmp_path), state) - for cell_id, status in ( - ("dependency-ok", "ok"), - ("dependency-cap", "memory_limit"), - ("dependency-error", "error"), - ("dependency-unverified", ResultStatus.UNVERIFIED.value), - ): - lease.observe({"event": "started", "cell_id": cell_id, "dependency": True}) - lease.observe( - { - "event": "finished", - "cell_id": cell_id, - "status": status, - "detail": status, - } - ) - lease.observe( - { - "event": "started", - "cell_id": "dependency-running", - "dependency": True, - } - ) - - counters = state.counters() - - assert counters == { - "selected": 1, - "recycled": 0, - "active": 1, - "selected_active": 0, - "dependency_active": 1, - "completed": 0, - "remaining": 1, - "static_na": 0, - "capped": 0, - "failed": 0, - "unverified": 0, - "dependency_only": 5, - "dependency_completed": 1, - "dependency_issues": 3, - } - frame = render_dashboard_frame(state, width=160, height=40) - assert "Workers active 1" in frame - assert "selected 0" in frame - assert "dependency 1" in frame - assert "Errors 0" in frame - assert "Unverified 0" in frame - assert "Completed 0" in frame - assert "Capped 0" in frame - assert "Dependency done 1" in frame - assert "issues 3" in frame - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["counters"] == counters - - lease.observe({"event": "started", "cell_id": "direct-cell"}) - active = state.counters() - assert active["selected_active"] == 1 - assert active["remaining"] == 1 - lease.observe({"event": "finished", "cell_id": "direct-cell", "status": "ok"}) - finished = state.counters() - assert finished["completed"] == 1 - assert finished["remaining"] == 0 - assert ( - sum( - finished[key] - for key in ( - "recycled", - "completed", - "capped", - "failed", - "unverified", - "static_na", - "remaining", - ) - ) - == finished["selected"] - ) - assert finished["dependency_completed"] == 1 - assert finished["dependency_issues"] == 3 - - -def test_dashboard_reducer_replaces_prior_outcomes_across_retries( - tmp_path: Path, -) -> None: - state = DashboardState( - instance_id="retry-transitions", - selected_ids=("retry-error", "retry-cap", "retry-recycled"), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(_manual_service(tmp_path), state) - - lease.observe( - { - "event": "finished", - "cell_id": "retry-error", - "status": "error", - } - ) - assert state.counters()["failed"] == 1 - assert state.counters()["remaining"] == 2 - lease.observe({"event": "started", "cell_id": "retry-error"}) - assert state.failed_ids == set() - assert state.counters()["active"] == 1 - lease.observe({"event": "finished", "cell_id": "retry-error", "status": "ok"}) - assert state.completed_ids == {"retry-error"} - assert state.failed_ids == set() - - lease.observe( - { - "event": "finished", - "cell_id": "retry-cap", - "status": "memory_limit", - } - ) - assert state.capped_ids == {"retry-cap"} - lease.observe({"event": "started", "cell_id": "retry-cap"}) - lease.observe( - { - "event": "finished", - "cell_id": "retry-cap", - "status": ResultStatus.UNVERIFIED.value, - } - ) - assert state.capped_ids == set() - assert state.completed_ids == {"retry-error"} - assert state.unverified_ids == {"retry-cap"} - - lease.observe( - { - "event": "finished", - "cell_id": "retry-recycled", - "status": "reused", - } - ) - assert state.recycled_ids == {"retry-recycled"} - lease.observe({"event": "started", "cell_id": "retry-recycled"}) - lease.observe( - { - "event": "finished", - "cell_id": "retry-recycled", - "status": "error", - } - ) - assert state.recycled_ids == set() - assert state.failed_ids == {"retry-recycled"} - assert state.counters() == { - "selected": 3, - "recycled": 0, - "active": 0, - "selected_active": 0, - "dependency_active": 0, - "completed": 1, - "remaining": 0, - "static_na": 0, - "capped": 0, - "failed": 1, - "unverified": 1, - "dependency_only": 0, - "dependency_completed": 0, - "dependency_issues": 0, - } - payload = json.loads(lease.path.read_text(encoding="utf-8")) - assert payload["counters"] == state.counters() - - -def test_cancelled_cell_remains_pending_in_dashboard_progress(tmp_path: Path) -> None: - state = DashboardState( - instance_id="cancelled-transition", - selected_ids=("cancelled-cell",), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(_manual_service(tmp_path), state) - lease.observe({"event": "started", "cell_id": "cancelled-cell"}) - lease.observe( - { - "event": "finished", - "cell_id": "cancelled-cell", - "status": "cancelled", - } - ) - - assert state.terminal_outcomes == {} - assert state.counters()["active"] == 0 - assert state.counters()["remaining"] == 1 - - -def test_late_resource_event_cannot_reactivate_terminal_worker(tmp_path: Path) -> None: - state = DashboardState( - instance_id="late-resource", - selected_ids=("cell",), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - lease = LeaseManager(_manual_service(tmp_path), state) - lease.observe({"event": "started", "cell_id": "cell"}) - lease.observe( - { - "event": "worker", - "cell_id": "cell", - "attempt_id": "new-attempt", - } - ) - lease.observe( - { - "event": "resource", - "cell_id": "cell", - "attempt_id": "old-attempt", - "wall_seconds": 50.0, - } - ) - assert state.workers["cell"].wall_seconds == 0.0 - lease.observe( - { - "event": "resource", - "cell_id": "cell", - "attempt_id": "new-attempt", - "wall_seconds": 2.0, - } - ) - lease.observe({"event": "finished", "cell_id": "cell", "status": "ok"}) - lease.observe( - { - "event": "resource", - "cell_id": "cell", - "attempt_id": "new-attempt", - "wall_seconds": 99.0, - } - ) - - assert state.workers["cell"].status == "ok" - assert state.workers["cell"].wall_seconds == 2.0 - assert state.counters()["active"] == 0 - assert state.counters()["completed"] == 1 - - -@pytest.mark.parametrize( - "status", - ("worker_timeout", "profiling_timeout", "validation_timeout"), -) -def test_manual_stage_timeouts_are_addressed_caps_in_dashboard_state( - tmp_path: Path, - status: str, -) -> None: - service = _manual_service(tmp_path) - state = DashboardState( - instance_id="local", - selected_ids=(status,), - recycled_ids=set(), - static_na_ids=set(), - source_revision="a" * 40, - ) - LeaseManager(service, state).observe( - { - "event": "finished", - "cell_id": status, - "status": status, - "detail": status, - } - ) - - assert state.completed_ids == set() - assert state.capped_ids == {status} - assert state.failed_ids == set() - assert state.counters()["remaining"] == 0 - - -def test_n8_all_flow_recurrence_is_runnable_but_native_n7_stays_static_na() -> None: - recurrence = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.workload is Workload.ALL_FLOW - and cell.n_final == 8 - ) - assert _manual_static_na_reason(recurrence) is None - - native = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id.startswith("z_") - and cell.variant in {"cpp_o3", "asm_o3"} - and cell.n_final == 7 - ) - assert _manual_static_na_reason(native) == ("native-backend-generation-cap-n6-v1") - - -def _write_minimal_index(repo: Path, relative: str) -> None: - path = repo / relative - observed = path.stat() - encoded = relative.encode() - fields = struct.pack( - "!10I20sH", - int(observed.st_ctime_ns // 1_000_000_000), - int(observed.st_ctime_ns % 1_000_000_000), - int(observed.st_mtime_ns // 1_000_000_000), - int(observed.st_mtime_ns % 1_000_000_000), - int(observed.st_dev), - int(observed.st_ino), - int(observed.st_mode), - int(observed.st_uid), - int(observed.st_gid), - int(observed.st_size), - b"\0" * 20, - len(encoded), - ) - entry = fields + encoded + b"\0" - entry += b"\0" * ((8 - len(entry) % 8) % 8) - (repo / ".git/index").write_bytes(struct.pack("!4sII", b"DIRC", 2, 1) + entry) - - -def test_source_cleanliness_is_index_metadata_only(tmp_path: Path) -> None: - (tmp_path / ".git/objects").mkdir(parents=True) - source = tmp_path / "tracked.py" - source.write_text("value = 1\n", encoding="utf-8") - _write_minimal_index(tmp_path, "tracked.py") - assert _index_metadata_dirty_paths(tmp_path) == () - source.write_text("value = 200\n", encoding="utf-8") - assert _index_metadata_dirty_paths(tmp_path) == ("tracked.py",) - - -def test_repo_head_resolves_loose_branch_from_linked_worktree_common_dir( - tmp_path: Path, -) -> None: - repo = tmp_path / "linked" - common = tmp_path / "common.git" - worktree_git = common / "worktrees/linked" - reference = "refs/heads/codex/manual-campaign-smoke" - revision = "a" * 40 - repo.mkdir() - worktree_git.mkdir(parents=True) - (repo / ".git").write_text( - f"gitdir: {worktree_git}\n", - encoding="ascii", - ) - (worktree_git / "HEAD").write_text( - f"ref: {reference}\n", - encoding="ascii", - ) - (worktree_git / "commondir").write_text("../..\n", encoding="ascii") - loose = common / reference - loose.parent.mkdir(parents=True) - loose.write_text(f"{revision}\n", encoding="ascii") - - assert manual_campaign._repo_head(repo) == revision - - -def test_lightweight_result_identity_must_match_selected_cell() -> None: - cell = REPORT_CATALOG.measurement_cells()[0] - identity = { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "workload": cell.workload.value, - "execution_mode": cell.measurement.execution_mode.value, - "model": None, - "accuracy": cell.measurement.accuracy.value, - "backend": cell.measurement.backend, - "variant": cell.variant, - } - result = {"provenance": {"manual_campaign": {"cell_identity": identity}}} - assert _result_matches_cell(result, cell) - identity["cell_id"] = "wrong-cell" - assert not _result_matches_cell(result, cell) - - -def test_manual_refresh_projects_artifact_output_and_reproduction_commands( - tmp_path: Path, - repository_with_cli: Path, -) -> None: - service = _manual_service(tmp_path, repo_root=repository_with_cli) - cell = next( - cell - for cell in service.catalog.measurement_cells() - if ( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.UFO_SM - and service.catalog.static_na_reason(cell) is None - ) - ) - artifact = ( - service.paths.artifact_root - / "cells" - / cell.cell_id - / "attempts" - / "attempt-one" - / "artifact" - ) - reproduction = reproduction_recipe( - cell, - repo_root=service.paths.repo_root, - artifact_root=service.paths.artifact_root, - artifact_path=str(artifact), - ).as_dict() - assert all( - isinstance(reproduction[field], list) - for field in ("prepare", "generate", "profile") - ) - - def merged_cache( - output: Path, - recipe: dict[str, object] = reproduction, - ) -> dict[str, dict[str, object]]: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.TIMEOUT.value, - "failure": {"kind": "generation_timeout"}, - "provenance": { - "effective_config": { - "generation": {"output": str(output)}, - }, - "manual_campaign": { - "public_cli_reproduction": recipe, - }, - }, - } - ) - current = LightweightCurrent( - cell_id=cell.cell_id, - attempt_id="attempt-one", - result_path=output.parent / "result.json", - result=measurement, - complete=True, - reusable=True, - reason="reusable", - ) - caches, merged = _merge_lightweight_snapshot( - service, - {cell.cell_id: current}, - ) - assert merged == 1 - return caches - - caches = merged_cache(artifact) - portable = portable_publication_value( - caches[f"{cell.dataset_id}.json"], - service.paths, - ) - assert isinstance(portable, dict) - entries = portable["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if isinstance(item, dict) and item.get("cell_id") == cell.cell_id - ) - output = entry["measurement"]["provenance"]["effective_config"][ # type: ignore[index] - "generation" - ]["output"] - assert output == ( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - f"cells/{cell.cell_id}/attempts/attempt-one/artifact" - ) - provenance = entry["measurement"]["provenance"] # type: ignore[index] - published_recipe = provenance["manual_campaign"][ # type: ignore[index] - "public_cli_reproduction" - ] - for field in ("prepare", "generate", "profile"): - argv = published_recipe[field] # type: ignore[index] - assert isinstance(argv, list) - assert any("${PYAMPLICOL_SOURCE_ROOT}" in argument for argument in argv) - rendered = json.dumps(portable) - assert str(service.paths.artifact_root) not in rendered - assert str(service.paths.repo_root) not in rendered - assert portable_publication_value(portable, service.paths) == portable - - external_recipe = dict(reproduction) - external_trace = ( - service.paths.repo_root.parent / "pyamplicol-external-test" / "trace.json" - ) - external_profile = external_recipe["profile"] - assert isinstance(external_profile, list) - external_recipe["profile"] = [*external_profile, "--trace", str(external_trace)] - external_diagnostic = merged_cache(artifact, external_recipe) - redacted = portable_publication_value( - external_diagnostic[f"{cell.dataset_id}.json"], - service.paths, - ) - redacted_entry = next( - item - for item in redacted["entries"] # type: ignore[index] - if isinstance(item, dict) and item.get("cell_id") == cell.cell_id - ) - redacted_recipe = redacted_entry["measurement"]["provenance"][ # type: ignore[index] - "manual_campaign" - ]["public_cli_reproduction"] - assert redacted_recipe["profile"][-1] == "${LOCAL_PATH_REDACTED}" - assert str(tmp_path) not in json.dumps(redacted) - assert portable_publication_value(redacted, service.paths) == redacted - - with pytest.raises( - PublicationPortabilityError, - match=r"/measurement/provenance/effective_config/generation/output", - ): - external = merged_cache(tmp_path / "external" / "artifact") - portable_publication_value( - external[f"{cell.dataset_id}.json"], - service.paths, - ) - - -def test_copied_campaign_rebinds_private_pdf_build_profile(tmp_path: Path) -> None: - staging = tmp_path / "copied_campaign" - staging.mkdir() - (staging / "report_environment.json").write_text( - json.dumps({"profile": "macbook_M3_manual"}), - encoding="utf-8", - ) - (staging / "report-workspace.json").write_text( - json.dumps( - { - "profile": "macbook_M3_manual", - "artifact_root": ".artifacts/performance-report/macbook_M3_manual", - "coordination_root": ( - ".artifacts/performance-report-coordination/macbook_M3_manual" - ), - "initialized_environment": {"profile": "macbook_M3_manual"}, - } - ), - encoding="utf-8", - ) - (staging / "report_environment.tex").write_text( - "\\renewcommand{\\ReportProfileName}{macbook\\_M3\\_manual}\n", - encoding="utf-8", - ) - - manual_campaign._stage_copied_profile_identity(staging, "independent_run") - - environment = json.loads( - (staging / "report_environment.json").read_text(encoding="utf-8") - ) - workspace = json.loads( - (staging / "report-workspace.json").read_text(encoding="utf-8") - ) - assert environment["profile"] == "independent_run" - assert workspace["profile"] == "independent_run" - assert workspace["initialized_environment"]["profile"] == "independent_run" - assert workspace["artifact_root"] == "campaign_artifacts" - assert workspace["coordination_root"] == "campaign_artifacts/coordination" - assert "{independent\\_run}" in (staging / "report_environment.tex").read_text( - encoding="utf-8" - ) - - -def test_staged_environment_without_witness_is_pending_or_same_source( - tmp_path: Path, -) -> None: - environment_path = tmp_path / "report_environment.json" - profile = "portable-campaign" - active_revision = "a" * 40 - - for status, source_revision in ( - ("pending_exact_runtime", "pending"), - ("authenticated", active_revision), - ): - environment_path.write_text( - json.dumps( - { - "profile": profile, - "status": status, - "source_revision": source_revision, - } - ), - encoding="ascii", - ) - manual_campaign._require_reusable_staged_environment( - tmp_path, - profile, - expected_source_revision=active_revision, - ) - - environment_path.write_text( - json.dumps( - { - "profile": profile, - "status": "authenticated", - "source_revision": "b" * 40, - } - ), - encoding="ascii", - ) - with pytest.raises(ManualCampaignError, match="no active-source runtime witness"): - manual_campaign._require_reusable_staged_environment( - tmp_path, - profile, - expected_source_revision=active_revision, - ) - - -def test_refresh_installs_authenticated_active_source_environment( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - docs = tmp_path / "portable-campaign" - (docs / "results").mkdir(parents=True) - (docs / "pyAmpliCol.tex").write_text("report\n", encoding="ascii") - shutil.copy2(PROFILE / "report_environment.json", docs) - shutil.copy2(PROFILE / "report_environment.tex", docs) - service = ReportService( - manual_campaign._campaign_report_paths(ROOT, docs), - portable_current_results=True, - ) - revision = "a" * 40 - current = _environment_witness_current( - tmp_path, - cell_id="active-current", - source_revision=revision, - numpy_version="1.26.4-measurement", - ) - real_import_module = workspace_module.importlib.import_module - - def reject_renderer_numpy(name: str): - if name == "numpy": - raise AssertionError("portable refresh imported renderer NumPy") - return real_import_module(name) - - monkeypatch.setattr( - workspace_module.importlib, - "import_module", - reject_renderer_numpy, - ) - monkeypatch.setattr( - manual_campaign, - "_capture_lightweight_snapshot", - lambda *_args, **_kwargs: ( - {current.cell_id: current}, - {}, - ((current.cell_id, current.attempt_id),), - ), - ) - monkeypatch.setattr( - manual_campaign, - "_merge_lightweight_snapshot", - lambda *_args, **_kwargs: ({}, 0), - ) - monkeypatch.setattr(ReportService, "_render_tables", lambda *_args: {}) - monkeypatch.setattr(ReportService, "_snapshot_files", lambda *_args: ()) - - def compile_staged(staging_docs: Path, **_kwargs: object) -> int: - environment = json.loads( - (staging_docs / "report_environment.json").read_text(encoding="ascii") - ) - assert environment["status"] == "authenticated" - assert environment["profile"] == "portable-campaign" - assert environment["source_revision"] == revision - assert environment["platform"] == "MeasuredOS 1.0; witness" - assert environment["machine"] == "measured-machine" - assert environment["processor"] == "measured-processor" - assert environment["python"] == "3.11.9" - assert environment["python_implementation"] == "CPython" - assert environment["numpy"] == "1.26.4-measurement" - assert "pending" not in (staging_docs / "report_environment.tex").read_text( - encoding="utf-8" - ) - (staging_docs / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n") - return 1 - - monkeypatch.setattr(manual_campaign, "_compile_pdf", compile_staged) - - assert ( - manual_campaign._refresh_pdf( - _parse("refresh-pdf", "--quiet", "--expected-page-count", "1"), - service=service, - source=manual_campaign.ReportSourceIdentity( - revision, - "b" * 40, - (), - ), - palette=manual_campaign.Palette(False), - ) - == 0 - ) - installed = json.loads( - (docs / "report_environment.json").read_text(encoding="ascii") - ) - assert installed["status"] == "authenticated" - assert installed["platform"] == "MeasuredOS 1.0; witness" - assert "pending" not in (docs / "report_environment.tex").read_text( - encoding="utf-8" - ) - assert (docs / "pyAmpliCol.pdf").read_bytes() == b"%PDF-1.4\n" - - -def test_manual_refresh_source_copy_excludes_only_top_level_campaign_state( - tmp_path: Path, -) -> None: - source = tmp_path / "source" - source.mkdir() - (source / "pyAmpliCol.tex").write_text("report\n", encoding="ascii") - state = source / "campaign_artifacts" - state.mkdir() - (state / "large-sentinel.bin").write_bytes(b"private") - nested = source / "appendix/campaign_artifacts" - nested.mkdir(parents=True) - (nested / "published.txt").write_text("keep\n", encoding="ascii") - destination = tmp_path / "staging" - - manual_campaign._copy_report_sources(source, destination) - - assert not (destination / "campaign_artifacts").exists() - assert (destination / "appendix/campaign_artifacts/published.txt").is_file() - - -def test_refresh_pdf_does_not_stage_local_campaign_state_recursively( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - docs = tmp_path / "portable-campaign" - docs.mkdir() - (docs / "pyAmpliCol.tex").write_text("report\n", encoding="ascii") - service = ReportService( - manual_campaign._campaign_report_paths(ROOT, docs), - portable_current_results=True, - ) - sentinel = service.paths.artifact_root / "large-private-sentinel.bin" - sentinel.write_bytes(b"private-state" * 1024) - manual_campaign.update_source_marker( - service, - manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()), - ) - observed: dict[str, Path] = {} - - monkeypatch.setattr( - manual_campaign, - "_capture_lightweight_snapshot", - lambda *_args, **_kwargs: ({}, {}, ()), - ) - monkeypatch.setattr( - manual_campaign, - "_merge_lightweight_snapshot", - lambda *_args, **_kwargs: ({}, 0), - ) - monkeypatch.setattr(ReportService, "_render_tables", lambda *_args: {}) - monkeypatch.setattr(ReportService, "_snapshot_files", lambda *_args: ()) - - def compile_staged(staging_docs: Path, **_kwargs: object) -> int: - observed["staging_docs"] = staging_docs - assert not (staging_docs / "campaign_artifacts").exists() - assert not any( - path.name == sentinel.name for path in staging_docs.rglob("*") - ) - (staging_docs / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n") - return 1 - - monkeypatch.setattr(manual_campaign, "_compile_pdf", compile_staged) - monkeypatch.setattr( - manual_campaign, - "_install_report_snapshot", - lambda *_args, **_kwargs: None, - ) - - assert ( - manual_campaign._refresh_pdf( - _parse("refresh-pdf", "--quiet", "--expected-page-count", "1"), - service=service, - source=manual_campaign.ReportSourceIdentity("a" * 40, "b" * 40, ()), - palette=manual_campaign.Palette(False), - ) - == 0 - ) - assert "staging_docs" in observed - assert not observed["staging_docs"].exists() - assert sentinel.read_bytes() == b"private-state" * 1024 - build_root = service.paths.artifact_root / "manual-publication-builds" - assert build_root.is_dir() - assert not tuple(build_root.iterdir()) - - -def test_controller_sources_only_use_read_only_git_for_external_checkout() -> None: - source_paths = ( - PROFILE / "steer_performance_campaign.py", - ROOT / "tools/performance_report/manual_campaign.py", - ) - sources = "\n".join(path.read_text(encoding="utf-8") for path in source_paths) - for forbidden in ( - "subprocess.Popen(", - "os.system(", - "shell=True", - "pip install", - "git pull", - "git fetch", - ): - assert forbidden not in sources - commands: list[tuple[str | None, ...]] = [] - for path in source_paths: - tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path)) - for node in ast.walk(tree): - if not ( - isinstance(node, ast.Call) - and isinstance(node.func, ast.Attribute) - and node.func.attr == "run" - and isinstance(node.func.value, ast.Name) - and node.func.value.id == "subprocess" - ): - continue - assert node.args and isinstance(node.args[0], (ast.Tuple, ast.List)) - command = tuple( - element.value if isinstance(element, ast.Constant) else None - for element in node.args[0].elts - ) - assert command[:2] in {("git", "rev-parse"), ("git", "status")} - assert not { - "add", - "apply", - "checkout", - "clean", - "commit", - "fetch", - "merge", - "pull", - "push", - "reset", - "stash", - }.intersection(value for value in command if value is not None) - commands.append(command) - assert ("git", "rev-parse", "HEAD") in commands - assert ( - "git", - "status", - "--porcelain=v1", - "--untracked-files=all", - ) in commands - assert any(command[:3] == ("git", "rev-parse", "--verify") for command in commands) - assert os.access(PROFILE / "steer_performance_campaign.py", os.X_OK) - - -def test_report_snapshot_install_is_atomic_and_rolls_back_on_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - docs = tmp_path / "docs" - staging = tmp_path / "staging" - for root, prefix in ((docs, "old"), (staging, "new")): - (root / "results").mkdir(parents=True) - (root / "results/cache.json").write_text( - f"{prefix}-cache\n", - encoding="ascii", - ) - (root / "result_demo_table.tex").write_text( - f"{prefix}-table\n", - encoding="utf-8", - ) - (root / "report_environment.json").write_text( - f"{prefix}-environment-json\n", - encoding="ascii", - ) - (root / "report_environment.tex").write_text( - f"{prefix}-environment-tex\n", - encoding="utf-8", - ) - (root / "pyAmpliCol.pdf").write_bytes(f"{prefix}-pdf".encode("ascii")) - service = ReportService( - ReportPaths.from_repo( - ROOT, - docs_dir=docs, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - real_replace = os.replace - - def fail_pdf_install( - source: os.PathLike[str], - destination: os.PathLike[str], - ) -> None: - if ( - Path(destination).name == "pyAmpliCol.pdf" - and ".manual-" in Path(source).name - ): - raise OSError("injected PDF install interruption") - return real_replace(source, destination) - - monkeypatch.setattr(os, "replace", fail_pdf_install) - with pytest.raises(OSError, match="injected PDF install"): - _install_report_snapshot( - service, - staging, - ("result_demo_table.tex",), - ) - - assert (docs / "results/cache.json").read_text(encoding="ascii") == "old-cache\n" - assert (docs / "result_demo_table.tex").read_text(encoding="utf-8") == "old-table\n" - assert (docs / "report_environment.json").read_text(encoding="ascii") == ( - "old-environment-json\n" - ) - assert (docs / "report_environment.tex").read_text(encoding="utf-8") == ( - "old-environment-tex\n" - ) - assert (docs / "pyAmpliCol.pdf").read_bytes() == b"old-pdf" - - -@pytest.mark.skipif(shutil.which("latexmk") is None, reason="latexmk is unavailable") -def test_fresh_manual_report_compiles_with_the_manual_page_contract( - tmp_path: Path, -) -> None: - docs = tmp_path / "docs" - shutil.copytree( - PROFILE, - docs, - ignore=shutil.ignore_patterns("pyAmpliCol.pdf", "*.aux", "*.log"), - ) - pages = _compile_pdf( - docs, - expected_page_count=DEFAULT_MANUAL_EXPECTED_PAGE_COUNT, - timeout_seconds=900.0, - ) - assert pages == 73 - assert (docs / "pyAmpliCol.pdf").stat().st_size > 100_000 diff --git a/pyamplicol/tests/unit/test_numerical_acceptance.py b/pyamplicol/tests/unit/test_numerical_acceptance.py deleted file mode 100644 index b31fcfe398..0000000000 --- a/pyamplicol/tests/unit/test_numerical_acceptance.py +++ /dev/null @@ -1,605 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -import hashlib -import json -import sys -from collections import Counter -from decimal import Decimal -from pathlib import Path -from types import ModuleType, SimpleNamespace - -import pytest - -from tools.developer import numerical_acceptance as acceptance_module -from tools.developer.numerical_acceptance import ( - ACCEPTANCE_LANES, - CATALOG_CASE_COUNT, - CATALOG_MAX_N_FINAL, - EXTRA_FULL_COLOUR_CASES, - FULL_CANDIDATE_PRECISION_DIGITS, - NATIVE_PRECISION_DIGITS, - RELATIVE_TOLERANCE, - MadGraphReferenceIdentity, - NumericalAcceptanceError, - NumericalAcceptanceMismatch, - assert_relative_match, - build_fixture_payload, - capture_acceptance_fixture, - catalog_cases, - compare_relative, - current_model_identity, - ingest_authenticated_extra_madgraph_root, - ingest_authenticated_madgraph_wave_root, - lane_case_specs, - load_acceptance_fixture, - parse_acceptance_fixture, - write_acceptance_fixture, -) -from tools.performance_report.madgraph import ( - MADGRAPH_DRIVER_SOURCE_SHA256, - madgraph_command_card, -) -from tools.performance_report.runner import point_digest - - -@pytest.fixture(autouse=True) -def synthetic_validation_points(monkeypatch: pytest.MonkeyPatch) -> None: - """Keep wire-contract unit tests independent of a staged native runtime.""" - - def point(process: str) -> tuple[tuple[Decimal, Decimal, Decimal, Decimal], ...]: - initial, final = process.split(">", maxsplit=1) - width = len(initial.split()) + len(final.split()) - return tuple( - (Decimal(index + 1), Decimal(0), Decimal(0), Decimal(0)) - for index in range(width) - ) - - monkeypatch.setattr(acceptance_module, "validation_momenta", point) - - -@pytest.fixture -def synthetic_payload() -> dict[str, object]: - catalog = catalog_cases() - all_cases = (*catalog, *EXTRA_FULL_COLOUR_CASES) - full = { - case.case_id: Decimal(index + 1) * Decimal("0.000000000000000000000000000001") - for index, case in enumerate(all_cases) - } - lc = { - case.case_id: Decimal(index + 101) * Decimal("0.000000000000000000000000000001") - for index, case in enumerate(catalog) - } - nlc = { - case.case_id: Decimal(index + 201) * Decimal("0.000000000000000000000000000001") - for index, case in enumerate(catalog) - } - model = current_model_identity() - return build_fixture_payload( - full_values=full, - lc_values=lc, - nlc_values=nlc, - full_reference=MadGraphReferenceIdentity( - madgraph_version="synthetic-unit-test", - model_source_sha256="1" * 64, - driver_sha256=MADGRAPH_DRIVER_SOURCE_SHA256, - external_parameters_sha256=model.external_parameters_sha256, - ), - captured_source_revision="a" * 40, - ) - - -def test_catalog_census_extra_cases_and_exact_lane_matrix() -> None: - cases = catalog_cases() - assert len(cases) == CATALOG_CASE_COUNT == 33 - assert Counter(case.n_final for case in cases) == {1: 2, 2: 8, 3: 9, 4: 14} - assert all(case.n_final <= CATALOG_MAX_N_FINAL for case in cases) - assert [case.case_id for case in EXTRA_FULL_COLOUR_CASES] == [ - "extra:identical-u-four-lines", - "extra:identical-electron-three-pair", - ] - assert {case.process for case in cases}.isdisjoint( - case.process for case in EXTRA_FULL_COLOUR_CASES - ) - assert [ - (lane.accuracy, lane.mode, lane.lc_flow_layout) - for lane in ACCEPTANCE_LANES - ] == [ - ("full", "recurrence", "topology-replay"), - ("full", "eager", "topology-replay"), - ("full", "compiled", "topology-replay"), - ("full", "on-the-fly", "topology-replay"), - ("lc", "recurrence", "topology-replay"), - ("lc", "eager", "topology-replay"), - ("lc", "compiled", "topology-replay"), - ("lc", "on-the-fly", "topology-replay"), - ("lc", "recurrence", "all-flow-union"), - ("lc", "eager", "all-flow-union"), - ("lc", "compiled", "all-flow-union"), - ("nlc", "recurrence", "topology-replay"), - ("nlc", "eager", "topology-replay"), - ("nlc", "compiled", "topology-replay"), - ("nlc", "on-the-fly", "topology-replay"), - ] - assert len({lane.lane_id for lane in ACCEPTANCE_LANES}) == 15 - assert { - lane.mode - for lane in ACCEPTANCE_LANES - if lane.lc_flow_layout == "all-flow-union" - } == {"recurrence", "eager", "compiled"} - with pytest.raises(ValueError, match="compact query-local LC artifact"): - acceptance_module.AcceptanceLane( - "lc", "on-the-fly", 2, "all-flow-union" - ) - assert { - lane.accuracy for lane in ACCEPTANCE_LANES if lane.mode == "on-the-fly" - } == {"full", "lc", "nlc"} - - -def test_synthetic_fixture_round_trip_binds_model_points_and_provenance( - tmp_path: Path, - synthetic_payload: dict[str, object], -) -> None: - path = tmp_path / "synthetic-numerical-acceptance.json" - fixture = write_acceptance_fixture(synthetic_payload, path) - loaded = load_acceptance_fixture(path) - - assert loaded == fixture - assert loaded.model == current_model_identity() - assert loaded.full_reference.external_parameters_sha256 == ( - loaded.model.external_parameters_sha256 - ) - assert loaded.captured_source_revision == "a" * 40 - assert len(loaded.catalog) == 33 - assert len(loaded.extra_full_colour) == 2 - for case in (*loaded.catalog, *loaded.extra_full_colour): - assert case.momenta == acceptance_module.validation_momenta(case.spec.process) - - with pytest.raises(NumericalAcceptanceError, match="refusing to overwrite"): - write_acceptance_fixture(synthetic_payload, path) - - -def test_fixture_loader_rejects_changed_points_model_and_wire_contract( - synthetic_payload: dict[str, object], -) -> None: - changed_point = copy.deepcopy(synthetic_payload) - changed_point["catalog_cases"][0]["momenta"][0][0] = "999" # type: ignore[index] - with pytest.raises(NumericalAcceptanceError, match="momenta differ"): - parse_acceptance_fixture(changed_point) - - changed_model = copy.deepcopy(synthetic_payload) - changed_model["model"]["source_sha256"] = "f" * 64 # type: ignore[index] - with pytest.raises(NumericalAcceptanceError, match="model identity differs"): - parse_acceptance_fixture(changed_model) - - changed_comparison = copy.deepcopy(synthetic_payload) - changed_comparison["comparison"]["absolute_tolerance"] = "0" # type: ignore[index] - with pytest.raises(NumericalAcceptanceError, match="relative-only"): - parse_acceptance_fixture(changed_comparison) - - changed_driver = copy.deepcopy(synthetic_payload) - changed_driver["references"]["full"]["driver_sha256"] = "f" * 64 # type: ignore[index] - with pytest.raises(NumericalAcceptanceError, match="canonical adapter driver"): - parse_acceptance_fixture(changed_driver) - - extra_field = copy.deepcopy(synthetic_payload) - extra_field["unreviewed"] = True - with pytest.raises(NumericalAcceptanceError, match="fields differ"): - parse_acceptance_fixture(extra_field) - - -def test_relative_comparator_has_no_absolute_escape_hatch() -> None: - reference = Decimal("0.000000000000000266945931894745456") - inside = reference * (Decimal(1) + RELATIVE_TOLERANCE / 2) - outside = reference * (Decimal(1) + RELATIVE_TOLERANCE * 2) - - assert compare_relative(inside, reference).passed - assert not compare_relative(outside, reference).passed - assert compare_relative(Decimal(0), Decimal(0)).passed - assert not compare_relative(Decimal(0), reference).passed - assert not compare_relative(-reference, reference).passed - assert not compare_relative( - complex(float(reference), float(reference)), reference - ).passed - with pytest.raises(NumericalAcceptanceMismatch, match="strict relative bound"): - assert_relative_match(outside, reference, context="synthetic/sign-gate") - - -def test_lane_helpers_keep_ordered_process_sets_static_and_artifact_safe() -> None: - for lane in ACCEPTANCE_LANES: - specs = lane_case_specs(lane) - assert len(specs) == 33 - assert tuple((spec.n_final, spec.family_id or 1000) for spec in specs) == tuple( - sorted( - ((spec.n_final, spec.family_id or 1000) for spec in specs), - ) - ) - assert all(":" not in spec.artifact_name for spec in specs) - assert all(spec.artifact_name[0].isalpha() for spec in specs) - assert lane.jit_optimization_level == (3 if lane.mode == "compiled" else 2) - config = acceptance_module.lane_run_config(lane) - assert config.color.lc_flow_layout.value == lane.lc_flow_layout - if lane.accuracy == "full": - assert lane_case_specs(lane, group="extra") == EXTRA_FULL_COLOUR_CASES - else: - with pytest.raises(NumericalAcceptanceError, match="no 'extra'"): - lane_case_specs(lane, group="extra") - - assert FULL_CANDIDATE_PRECISION_DIGITS == 200 - assert NATIVE_PRECISION_DIGITS == 16 - - -def test_lane_precision_policy_keeps_on_the_fly_at_p16() -> None: - for lane in ACCEPTANCE_LANES: - expected = (NATIVE_PRECISION_DIGITS,) - if lane.accuracy == "full" and lane.mode != "on-the-fly": - expected += (FULL_CANDIDATE_PRECISION_DIGITS,) - assert lane.evaluation_precisions == expected - assert lane.evaluation_precisions_for("catalog") == expected - assert lane.evaluation_precisions_for("extra") == ( - NATIVE_PRECISION_DIGITS, - ) - - -def test_runtime_lane_validation_binds_mode_and_color_accuracy() -> None: - lane = acceptance_module.AcceptanceLane("lc", "recurrence", 2) - runtime = SimpleNamespace( - execution_mode="recurrence", - physics=SimpleNamespace(color_accuracy="lc"), - ) - acceptance_module._validate_runtime_lane(runtime, lane, context="synthetic") - - runtime.physics.color_accuracy = "full" - with pytest.raises(NumericalAcceptanceError, match="color_accuracy='full'"): - acceptance_module._validate_runtime_lane(runtime, lane, context="synthetic") - runtime.physics.color_accuracy = "lc" - runtime.execution_mode = "eager" - with pytest.raises(NumericalAcceptanceError, match="mode='eager'"): - acceptance_module._validate_runtime_lane(runtime, lane, context="synthetic") - - -def test_artifact_lane_validation_binds_all_flow_union(tmp_path: Path) -> None: - artifact = tmp_path / "union" - (artifact / "config").mkdir(parents=True) - (artifact / "config" / "effective.toml").write_text( - """ -[color] -accuracy = "lc" -lc_flow_layout = "all-flow-union" -[evaluator] -execution_mode = "recurrence" -""".lstrip(), - encoding="utf-8", - ) - union = acceptance_module.AcceptanceLane( - "lc", "recurrence", 2, "all-flow-union" - ) - acceptance_module._validate_artifact_lane(artifact, union) - - topology = acceptance_module.AcceptanceLane("lc", "recurrence", 2) - with pytest.raises(NumericalAcceptanceError, match="effective lane"): - acceptance_module._validate_artifact_lane(artifact, topology) - - -def test_capture_runtime_identity_requires_repo_venv_site_packages( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repository = tmp_path / "repository" - prefix = repository / ".venv" - package_file = ( - prefix / "lib" / f"python{sys.version_info.major}.{sys.version_info.minor}" - / "site-packages/pyamplicol/__init__.py" - ) - package_file.parent.mkdir(parents=True) - package_file.touch() - source_file = repository / "src/pyamplicol/__init__.py" - source_file.parent.mkdir(parents=True) - source_file.touch() - monkeypatch.setattr(acceptance_module, "ROOT", repository) - package = ModuleType("pyamplicol") - package.__file__ = str(package_file) - package.__path__ = [] # type: ignore[attr-defined] - internal = ModuleType("pyamplicol._internal") - internal.__path__ = [] # type: ignore[attr-defined] - versions = ModuleType("pyamplicol._internal.versions") - versions.active_native_source_identity = lambda: ( # type: ignore[attr-defined] - "a" * 40, - "b" * 64, - ) - monkeypatch.setitem(sys.modules, "pyamplicol", package) - monkeypatch.setitem(sys.modules, "pyamplicol._internal", internal) - monkeypatch.setitem(sys.modules, "pyamplicol._internal.versions", versions) - monkeypatch.setattr(acceptance_module.sys, "prefix", str(prefix)) - monkeypatch.setattr( - acceptance_module.importlib.metadata, - "version", - lambda _name: "synthetic", - ) - - identity = acceptance_module._current_runtime_identity() - assert identity.source_revision == "a" * 40 - assert identity.native_build_inputs_sha256 == "b" * 64 - - package.__file__ = str(source_file) - with pytest.raises(NumericalAcceptanceError, match=r"\.venv site-packages"): - acceptance_module._current_runtime_identity() - - -def test_json_loader_rejects_duplicate_fields( - tmp_path: Path, - synthetic_payload: dict[str, object], -) -> None: - path = tmp_path / "duplicates.json" - encoded = json.dumps(synthetic_payload) - path.write_text(encoded[:-1] + ',"kind":"duplicate"}', encoding="ascii") - with pytest.raises(NumericalAcceptanceError, match="duplicate JSON field"): - load_acceptance_fixture(path) - - -def _write_json(path: Path, payload: object) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8") - - -def _point_payload(process: str) -> list[list[str]]: - return [ - [str(component) for component in row] - for row in acceptance_module.validation_momenta(process) - ] - - -def _measurement_payload( - spec: acceptance_module.AcceptanceCaseSpec, - *, - driver_sha256: str = MADGRAPH_DRIVER_SOURCE_SHA256, -) -> dict[str, object]: - point = ( - tuple( - tuple(float(component) for component in row) - for row in acceptance_module.validation_momenta(spec.process) - ), - ) - external_sha = current_model_identity().external_parameters_sha256 - command_card = madgraph_command_card(spec.process) - card = { - "binary64_exact_match": True, - "external_parameter_count": 1, - "external_parameters_sha256": external_sha, - "format": "%.14e", - } - return { - "status": "ok", - "matrix_element": 1.25, - "validation": { - "status": "ok", - "method": "independent-madgraph-tree-level-oracle", - "point_digest": point_digest(point), - }, - "provenance": { - "method": "madgraph-standalone-custom-fortran-driver", - "command_card": command_card, - "command_card_sha256": hashlib.sha256( - command_card.encode("utf-8") - ).hexdigest(), - "report_momenta": point, - "model": {"name": "sm", "source_sha256": "1" * 64}, - "exact_param_card": dict(card), - "default_restriction": dict(card), - "version": "synthetic-madgraph", - "driver_sha256": driver_sha256, - }, - } - - -def test_madgraph_measurement_requires_canonical_driver_without_timing_census() -> None: - spec = catalog_cases()[0] - value, identity = acceptance_module._madgraph_measurement( - _measurement_payload(spec), - spec, - ) - assert value == Decimal("1.25") - assert identity.driver_sha256 == MADGRAPH_DRIVER_SOURCE_SHA256 - - changed = _measurement_payload(spec, driver_sha256="f" * 64) - with pytest.raises(NumericalAcceptanceError, match="authority contract"): - acceptance_module._madgraph_measurement(changed, spec) - - -def _stub_raw_measurements( - monkeypatch: pytest.MonkeyPatch, - values: dict[str, Decimal], -) -> MadGraphReferenceIdentity: - model = current_model_identity() - identity = MadGraphReferenceIdentity( - madgraph_version="synthetic-gate", - model_source_sha256="1" * 64, - driver_sha256=MADGRAPH_DRIVER_SOURCE_SHA256, - external_parameters_sha256=model.external_parameters_sha256, - ) - - def parse( - measurement: object, - spec: acceptance_module.AcceptanceCaseSpec, - ) -> tuple[Decimal, MadGraphReferenceIdentity]: - assert measurement == {"case_id": spec.case_id} - return values[spec.case_id], identity - - monkeypatch.setattr(acceptance_module, "_madgraph_measurement", parse) - return identity - - -def _synthetic_wave_root(root: Path, values: dict[str, Decimal]) -> Path: - specs = catalog_cases() - _write_json( - root / "manifest.json", - { - "kind": "pyamplicol-madgraph-ufo-sm-full-p200-wave-gate-v1", - "status": "running", - "seed": 101, - "max_n": 6, - "ordering": "n-final-then-family-id-then-mode", - "plan": [ - { - "cell_ordinal": ordinal, - "family_id": spec.family_id, - "n_final": spec.n_final, - "process": spec.process, - "process_key": spec.family_key, - } - for ordinal, spec in enumerate(specs) - ], - }, - ) - for spec in specs: - case_root = root / f"n{spec.n_final}" / f"family-{spec.family_id:02d}" - _write_json( - case_root / "point-seed-101.json", - _point_payload(spec.process), - ) - _write_json( - case_root / "madgraph-measurement.json", - {"case_id": spec.case_id}, - ) - _write_json( - case_root / "madgraph-authority.json", - { - "process": spec.process, - "n_final": spec.n_final, - "seed": 101, - "madgraph_value": str(values[spec.case_id]), - }, - ) - return root - - -def _synthetic_stress_root(root: Path, values: dict[str, Decimal]) -> Path: - keys = ("uu_four_identical_lines", "ee_four_identical_lines") - _write_json( - root / "manifest.json", - { - "kind": "pyamplicol-authenticated-noncatalog-n6-madgraph-stress-v1", - "status": "ok", - "stage": "complete", - "seed": 101, - "process_order": [ - {"key": key, "process": spec.process, "n_final": 6} - for key, spec in zip(keys, EXTRA_FULL_COLOUR_CASES, strict=True) - ], - "catalog_policy": "direct synthetic CellSpec; REPORT_CATALOG not modified", - }, - ) - for case_ordinal, (key, spec) in enumerate( - zip(keys, EXTRA_FULL_COLOUR_CASES, strict=True) - ): - case_root = root / f"case-{case_ordinal + 1:02d}-{key}" - point = _point_payload(spec.process) - _write_json(case_root / "point-seed-101.json", point) - _write_json( - case_root / "madgraph-measurement.json", - {"case_id": spec.case_id}, - ) - _write_json( - case_root / "madgraph-authority-verification.json", - { - "process": spec.process, - "seed": 101, - "point": point, - "matrix_element_binary64": str(values[spec.case_id]), - "checks": { - "status": True, - "exact_seed_101_point": True, - "exact_command_card": True, - "custom_fortran_method": True, - "custom_driver_digest": True, - "exact_generated_process": True, - }, - }, - ) - return root - - -def test_wave_ingestion_reuses_only_madgraph_authority( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - values = { - spec.case_id: Decimal(index + 1) for index, spec in enumerate(catalog_cases()) - } - identity = _stub_raw_measurements(monkeypatch, values) - root = _synthetic_wave_root(tmp_path / "wave", values) - - ingested = ingest_authenticated_madgraph_wave_root(root) - assert ingested.values == values - assert ingested.identity == identity - - manifest_path = root / "manifest.json" - manifest = json.loads(manifest_path.read_text(encoding="utf-8")) - for terminal_status in ("validation-failed", "error"): - manifest["status"] = terminal_status - _write_json(manifest_path, manifest) - with pytest.raises(NumericalAcceptanceError, match="cannot supply"): - ingest_authenticated_madgraph_wave_root(root) - manifest["status"] = "running" - _write_json(manifest_path, manifest) - - last = catalog_cases()[-1] - authority_path = ( - root / "n4" / f"family-{last.family_id:02d}" / "madgraph-authority.json" - ) - authority = json.loads(authority_path.read_text(encoding="utf-8")) - authority["madgraph_value"] = "999" - _write_json(authority_path, authority) - with pytest.raises(NumericalAcceptanceError, match="authority"): - ingest_authenticated_madgraph_wave_root(root) - - -def test_stress_ingestion_reuses_only_madgraph_authority( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - values = { - spec.case_id: Decimal(index + 101) - for index, spec in enumerate(EXTRA_FULL_COLOUR_CASES) - } - identity = _stub_raw_measurements(monkeypatch, values) - root = _synthetic_stress_root(tmp_path / "stress", values) - - ingested = ingest_authenticated_extra_madgraph_root(root) - assert ingested.values == values - assert ingested.identity == identity - - authority_path = ( - root - / "case-01-uu_four_identical_lines" - / "madgraph-authority-verification.json" - ) - authority = json.loads(authority_path.read_text(encoding="utf-8")) - authority["checks"]["custom_driver_digest"] = False - _write_json(authority_path, authority) - with pytest.raises(NumericalAcceptanceError, match="authority"): - ingest_authenticated_extra_madgraph_root(root) - - -def test_capture_preflight_rejects_bidirectional_and_input_path_overlap( - tmp_path: Path, -) -> None: - destination = tmp_path / "fixture.json" - with pytest.raises(NumericalAcceptanceError, match=r"outside.*work root"): - capture_acceptance_fixture( - madgraph_wave_root=tmp_path / "wave", - extra_madgraph_root=tmp_path / "stress", - work_root=destination / "work", - output=destination, - ) - - wave_root = tmp_path / "authenticated-wave" - wave_root.mkdir() - with pytest.raises(NumericalAcceptanceError, match="must not overlap"): - capture_acceptance_fixture( - madgraph_wave_root=wave_root, - extra_madgraph_root=tmp_path / "stress", - work_root=tmp_path / "work", - output=wave_root / "fixture.json", - ) diff --git a/pyamplicol/tests/unit/test_on_the_fly_artifact_scheduling.py b/pyamplicol/tests/unit/test_on_the_fly_artifact_scheduling.py deleted file mode 100644 index 65e87aed81..0000000000 --- a/pyamplicol/tests/unit/test_on_the_fly_artifact_scheduling.py +++ /dev/null @@ -1,246 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import subprocess -from collections.abc import Sequence -from pathlib import Path - -import pytest - -from tools.performance_report.artifacts import ArtifactStore, CurrentRecord -from tools.performance_report.cache import empty_measurement -from tools.performance_report.campaign_policy import PolicyMeasurementState -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ResultStatus, - Workload, -) -from tools.performance_report.resources import ResourceUsage, SupervisedResult -from tools.performance_report.scheduler import ( - CampaignScheduler, - CampaignSettings, - PlannedCell, - _artifact_consumer_cell_ids, - plan_campaign, -) -from tools.performance_report.service import ReportPaths, ReportService - -_REVISION = "current-revision" - - -def _otf_pair() -> tuple[CellSpec, CellSpec]: - cells = tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_on_the_fly_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - ) - selected = next( - cell for cell in cells if cell.workload is Workload.SELECTED_FLOW - ) - all_flow = next(cell for cell in cells if cell.workload is Workload.ALL_FLOW) - return selected, all_flow - - -def _measurement(cell: CellSpec) -> dict[str, object]: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": {}, - "selector_contract": None, - "validation": {"status": ResultStatus.OK.value}, - "resources": {}, - "provenance": { - "report_source_revision": _REVISION, - "test_cell_id": cell.cell_id, - }, - } - ) - return measurement - - -def _publish_current( - store: ArtifactStore, - cell: CellSpec, -) -> CurrentRecord: - return store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE).publish( - _measurement(cell) - ) - - -def _service(tmp_path: Path) -> ReportService: - repo_root = tmp_path / "repo" - (repo_root / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo_root, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo_root, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo_root, - check=True, - ) - (repo_root / "README.md").write_text("# report fixture\n", encoding="ascii") - subprocess.run(("git", "add", "README.md"), cwd=repo_root, check=True) - subprocess.run( - ("git", "commit", "-q", "-m", "Initialize fixture"), - cwd=repo_root, - check=True, - ) - return ReportService( - ReportPaths.from_repo( - repo_root, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - - -def test_otf_artifact_reuse_is_directional_and_preserves_owner_consumers() -> None: - selected, all_flow = _otf_pair() - - assert REPORT_CATALOG.equivalent_cells(selected) == () - assert REPORT_CATALOG.equivalent_cells(all_flow) == (selected,) - assert _artifact_consumer_cell_ids( - selected, - catalog=REPORT_CATALOG, - ) == tuple(sorted((selected.cell_id, all_flow.cell_id))) - - -def test_regenerate_all_flow_forces_its_fresh_selected_owner_into_the_plan( - tmp_path: Path, -) -> None: - selected, all_flow = _otf_pair() - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - current = _publish_current(store, selected) - - def resolve( - _cell: CellSpec, - ) -> tuple[CurrentRecord, PolicyMeasurementState]: - return current, PolicyMeasurementState.SUCCESS - - planned = plan_campaign( - (all_flow,), - store=store, - settings=CampaignSettings(artifact_policy=ArtifactPolicy.REGENERATE), - current_resolver=resolve, - ) - otf = tuple( - item - for item in planned - if item.cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - ) - - assert tuple(item.cell for item in otf) == (selected, all_flow) - assert otf[0].dependency is True - assert selected.cell_id in otf[1].prerequisite_cell_ids - assert otf[0].rank < otf[1].rank - - -@pytest.mark.parametrize("force_refresh", [False, True]) -def test_regenerate_and_force_refresh_generate_selected_once_then_reuse_it( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - force_refresh: bool, -) -> None: - selected, all_flow = _otf_pair() - service = _service(tmp_path) - old_selected = _publish_current(service.store, selected) if force_refresh else None - old_all_flow = _publish_current(service.store, all_flow) if force_refresh else None - commands: list[list[str]] = [] - - def fake_supervise( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - captured = list(command) - commands.append(captured) - cell = REPORT_CATALOG.cell(captured[captured.index("--cell-id") + 1]) - result_path = Path(captured[captured.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_measurement(cell), sort_keys=True) + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler._symbolica_generation_lock_path", - lambda *_args, **_kwargs: tmp_path / "generation.lock", - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - artifact_policy=ArtifactPolicy.REGENERATE, - rerun=force_refresh, - target_runtime_seconds=1.0, - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - scheduler.source_revision = _REVISION - - selected_outcome = scheduler._run_cell(PlannedCell(selected, False, None, 0)) - selected_current = service.store.load_current(selected.cell_id) - assert selected_current is not None - all_flow_outcome = scheduler._run_cell(PlannedCell(all_flow, False, None, 1)) - - assert selected_outcome.status == all_flow_outcome.status == "ok" - assert len(commands) == 2 - selected_command, all_flow_command = commands - assert "--reused-measurement-json" not in selected_command - assert "--generation-lock-path" in selected_command - assert "--generation-lock-path" not in all_flow_command - assert all_flow_command[ - all_flow_command.index("--reused-measurement-json") + 1 - ] == str(selected_current.result_path) - if old_selected is not None: - assert selected_current.attempt_id != old_selected.attempt_id - assert str(old_selected.result_path) not in all_flow_command - if old_all_flow is not None: - assert str(old_all_flow.result_path) not in selected_command - assert str(old_all_flow.result_path) not in all_flow_command - - -def test_directional_owner_contract_is_scoped_to_otf_lc() -> None: - selected, _all_flow = _otf_pair() - recurrence = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.accuracy is Accuracy.LC - and cell.process_key == selected.process_key - and cell.n_final == selected.n_final - and cell.workload is Workload.SELECTED_FLOW - ) - - assert REPORT_CATALOG.equivalent_cells(recurrence) diff --git a/pyamplicol/tests/unit/test_on_the_fly_high_multiplicity.py b/pyamplicol/tests/unit/test_on_the_fly_high_multiplicity.py deleted file mode 100644 index 3c1b4c37eb..0000000000 --- a/pyamplicol/tests/unit/test_on_the_fly_high_multiplicity.py +++ /dev/null @@ -1,2133 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Focused contracts for the bounded OTF high-multiplicity driver.""" - -from __future__ import annotations - -import argparse -import copy -import json -import os -import sys -from pathlib import Path -from types import SimpleNamespace -from unittest import mock - -import pytest - -from tools.developer import on_the_fly_high_multiplicity as study -from tools.performance_report.runner import SelectorContract -from tools.performance_report.selector_policy import fixed_selector_helicity - - -def _args( - tmp_path: Path, - n: int, - workload: str, - *, - process_id: int = 7, -) -> argparse.Namespace: - has_amplicol = workload == "selected" and process_id != 14 and n <= 7 - return argparse.Namespace( - output=tmp_path / "out", - process_id=process_id, - multiplicity=n, - workload=workload, - prepared_model=None, - candidate_artifact=None, - selected_report=None, - reference_repo_root=tmp_path if has_amplicol else None, - reference_profile="reference" if has_amplicol else None, - target_runtime=0.1, - worker=False, - ) - - -def test_exact_cases_helicities_and_cli_routes(tmp_path: Path) -> None: - assert study.SUPPORTED_MULTIPLICITIES == (5, 6, 7, 8, 9) - assert study.SUPPORTED_PROCESS_MULTIPLICITIES == { - 7: (5, 6, 7, 8, 9), - 8: (5, 6, 7, 8, 9), - 11: (5, 6, 7), - 13: (5, 6, 7), - 14: (6, 7), - 15: (5, 6, 7), - } - bases = { - 7: (1, -1, 6, -6), - 8: (21, 21, 21, 21), - 11: (1, -1, 6, -6, 23, 25), - 13: (1, -1, 2, -2, 3, -3), - 14: (1, -1, 2, -2, 3, -3, 4, -4), - 15: (1, -1, 2, -2, 2, -2), - } - for process_id, multiplicities in study.SUPPORTED_PROCESS_MULTIPLICITIES.items(): - for n in multiplicities: - case = study._case(process_id, n) - base = bases[process_id] - assert case.pdgs == ( - *base, - *(21 for _ in range(n - (len(base) - 2))), - ) - assert case.process_id == f"otf_p{process_id}_{case.process_key}_n{n}" - assert fixed_selector_helicity(case.pdgs) == tuple( - 0 if abs(pdg) == 25 else (-1 if index % 2 else 1) - for index, pdg in enumerate(case.pdgs, start=1) - ) - assert study._case(7, 5).process == "d d~ > t t~ g g g" - assert study._case(8, 5).process == "g g > g g g g g" - assert study._case(11, 5).process == "d d~ > t t~ z h g" - assert study._case(13, 5).process == "d d~ > u u~ s s~ g" - assert study._case(14, 6).process == "d d~ > u u~ s s~ c c~" - assert study._case(15, 5).process == "d d~ > u u~ u u~ g" - for process_id, n in ((11, 8), (13, 8), (14, 5), (14, 8), (15, 8)): - with pytest.raises(study.StudyError, match="planned high-multiplicity"): - study._case(process_id, n) - assert study._authority_kind(study._case(7, 5), "selected") == "amplicol" - assert study._authority_kind(study._case(14, 6), "selected") == "recurrence" - assert study._authority_kind(study._case(8, 9), "selected") == "otf-only" - assert study._authority_kind(study._case(7, 5), "all-flow") == "otf-only" - assert ( - study._parser() - .parse_args( - [ - "--output", - "x", - "--process-id", - "7", - "--multiplicity", - "5", - "--workload", - "selected", - ] - ) - .target_runtime - == 5.0 - ) - candidate = tmp_path / "candidate" - candidate.mkdir() - prepared = tmp_path / "model" - prepared.touch() - invalid = ( - _args(tmp_path, 5, "selected"), - _args(tmp_path, 8, "all-flow"), - argparse.Namespace( - **{**vars(_args(tmp_path, 5, "all-flow")), "candidate_artifact": candidate} - ), - argparse.Namespace( - **{ - **vars(_args(tmp_path, 8, "all-flow")), - "candidate_artifact": candidate, - "prepared_model": prepared, - } - ), - argparse.Namespace( - **{ - **vars(_args(tmp_path, 8, "selected")), - "prepared_model": prepared, - "reference_repo_root": tmp_path, - "reference_profile": "reference", - } - ), - ) - for args in invalid: - with pytest.raises(study.StudyError): - study._validate_arguments(args) - with pytest.raises(SystemExit): - study._parser().parse_args( - ["--output", "x", "--multiplicity", "5", "--recurrence-artifact", "x"] - ) - - selected = _args(tmp_path, 5, "selected") - selected.prepared_model = prepared - study._validate_arguments(selected) - recurrence = _args(tmp_path, 6, "selected", process_id=14) - recurrence.prepared_model = prepared - study._validate_arguments(recurrence) - otf_only = _args(tmp_path, 8, "selected") - otf_only.prepared_model = prepared - study._validate_arguments(otf_only) - all_flow = _args(tmp_path, 5, "all-flow") - all_flow.candidate_artifact = candidate - all_flow.selected_report = prepared - study._validate_arguments(all_flow) - - -def test_timing_batch_repeats_only_seed101_point() -> None: - assert study.SEEDS == (101, 211, 307, 401, 503, 607, 709, 811) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - timing = study._timing_points(points) - assert len(timing) == 128 - assert all(point == points[0] for point in timing) - assert points[1] not in timing - - -def test_otf_and_recurrence_use_explicit_distinct_thread_budgets() -> None: - otf = study._config("on-the-fly", "topology-replay") - recurrence = study._config("recurrence", "topology-replay") - - assert otf.evaluator.optimization.cores == study.OTF_QUERY_CONSTRUCTION_THREADS == 4 - assert ( - recurrence.evaluator.optimization.cores - == study.RECURRENCE_GENERATION_THREADS - == 1 - ) - - -def test_high_cost_lifecycle_policy_has_an_exhaustive_same_family_baseline() -> None: - expected = { - (7, 5): study.LIFECYCLE_EXHAUSTIVE, - (7, 6): study.LIFECYCLE_EXHAUSTIVE, - (7, 7): study.LIFECYCLE_LEAN, - (8, 5): study.LIFECYCLE_EXHAUSTIVE, - (8, 6): study.LIFECYCLE_LEAN, - (14, 6): study.LIFECYCLE_EXHAUSTIVE, - (14, 7): study.LIFECYCLE_LEAN, - } - for (process_id, multiplicity), mode in expected.items(): - case = study._case(process_id, multiplicity) - policy = study._lifecycle_policy(case, "selected") - assert policy["mode"] == mode - assert policy["retain_requested_family_after_cold_warmup"] is ( - mode == study.LIFECYCLE_LEAN - ) - baseline = policy["expected_prior_campaign_prerequisite"] - if mode == study.LIFECYCLE_LEAN: - assert baseline["evidence_status"] == ( - "expected-not-authenticated-by-this-report" - ) - assert baseline["process_table_id"] == process_id - assert baseline["multiplicity"] < multiplicity - assert baseline["workload"] == "selected" - assert baseline["policy"] == study.LIFECYCLE_EXHAUSTIVE - all_flow_baseline = study._lifecycle_policy(case, "all-flow")[ - "expected_prior_campaign_prerequisite" - ] - assert all_flow_baseline["workload"] == "all-flow" - else: - assert baseline is None - - -def test_selector_derivation_and_compact_path_never_open_physics( - monkeypatch: pytest.MonkeyPatch, -) -> None: - case = study._case(14, 6) - states = fixed_selector_helicity(case.pdgs) - word = study._colored_source_labels(case) - contract = SelectorContract( - ("flow:" + ",".join(map(str, word)),), - (word,), - ("h:" + ",".join(f"{state:+d}" for state in states),), - tuple(enumerate(states, start=1)), - "a" * 64, - ) - validate = mock.Mock() - derive = mock.Mock(return_value=contract) - monkeypatch.setattr(study, "validate_selector_contract", validate) - monkeypatch.setattr(study, "derive_selector_contract", derive) - recurrence = SimpleNamespace(execution_mode="recurrence") - selector, returned, payload = study._recurrence_authority_contract( - case, recurrence, () - ) - assert selector.flow_word == word and selector.helicities == states - assert returned is contract and payload == contract.as_dict() - derive.assert_called_once_with(recurrence, ()) - validate.assert_called_once_with(recurrence, contract, ()) - - case = study._case(8, 8) - flow_id = "flow:1,2,3,4,5,6,7,8,9,10" - points = (((1.0, 0.0, 0.0, 1.0),),) - - class Backend: - @property - def physics(self) -> object: - raise AssertionError("dense physics opened") - - def _on_the_fly_benchmark_context(self, requested: object) -> dict[str, object]: - assert requested == ("1",) - return { - "process_id": case.process_id, - "process_expression": case.process, - "color_accuracy": "lc", - "helicity_count": 1, - "color_count": 1, - "selected_color_ids": [flow_id], - } - - selector, compact_contract, context = study._selector_from_compact_ordinal_one( - SimpleNamespace(_backend=Backend()), case, points - ) - assert selector.flow_word == tuple(range(1, 11)) - assert compact_contract.selected_color_flow_ids == (flow_id,) - assert context["requested_color_ids"] == ["1"] - assert context["selector_source"] == "compact-seed-one-based-color-ordinal-1" - - -@pytest.mark.parametrize( - ("process_id", "word"), - ( - (7, (2, 5, 6, 7, 4, 3, 1)), - (8, (1, 2, 3, 4, 5, 6, 7)), - (11, (2, 7, 4, 3, 1)), - (13, (2, 7, 1, 3, 4, 5, 6)), - (15, (2, 7, 1, 3, 4, 5, 6)), - ), -) -def test_amplicol_current_is_portably_loaded_and_only_digest_rebound( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - process_id: int, - word: tuple[int, ...], -) -> None: - case = study._case(process_id, 5) - states = fixed_selector_helicity(case.pdgs) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - singleton_digest = study.point_digest((points[0],)) - active = study.ReportSourceIdentity("b" * 40, "d" * 40, ()) - stored = SelectorContract( - ("flow:" + ",".join(map(str, word)),), - (word,), - ("h:" + ",".join(f"{state:+d}" for state in states),), - tuple(enumerate(states, start=1)), - singleton_digest, - ) - docs = tmp_path / "docs" / "performance_reports" / "profile" - paths = SimpleNamespace( - repo_root=tmp_path, - docs_dir=docs, - artifact_root=docs / "campaign_artifacts", - coordination_root=docs / "campaign_artifacts" / "coordination", - ) - for path in (paths.docs_dir, paths.artifact_root, paths.coordination_root): - path.mkdir(parents=True, exist_ok=True) - attempt = tmp_path / "attempt" - legacy_artifact = attempt / "artifact" - library = legacy_artifact / "selected-flow-generated-library" - (library / "Library").mkdir(parents=True) - (library / "processes.txt").touch() - (library / "libamp1.so").touch() - executable = library / "amplicol_library_benchmark" - executable.touch() - executable.chmod(0o755) - expected_cell = study._reference_cell(case, "selected") - result = { - "status": "ok", - "selector_contract": stored.as_dict(), - "matrix_element": 7.5, - "generation_seconds": 3.0, - "wall_seconds_per_point": 2.0e-6, - "execution_seconds_per_point": 1.5e-6, - "relative_standard_error": 0.0 if process_id == 8 else 0.01, - "sample_count": 5, - "artifact": { - "path": str(legacy_artifact), - "process_row": "group:1:integral:1", - }, - "provenance": { - "revision": study.PINNED_REFERENCE_REVISION, - "report_source_revision": "b" * 40, - "report_measured_source_revision": "b" * 40, - "report_source_tree": "d" * 40, - "report_measured_source_tree": "d" * 40, - "report_source_clean": True, - "generation_timing_is_workload_specific": True, - "manual_campaign": { - "batch_size": 128, - "warmup_runs": 2, - "minimum_samples": 5, - "target_runtime_seconds": 0.1, - "cell_identity": { - "accuracy": "lc", - "backend": "fortran", - "cell_id": expected_cell.cell_id, - "dataset_id": "reference_amplicol_lc", - "execution_mode": "amplicol", - "model": None, - "n_final": case.multiplicity, - "process": case.process, - "process_key": case.process_key, - "variant": None, - "workload": "selected-flow", - }, - }, - }, - } - current = SimpleNamespace( - cell_id=expected_cell.cell_id, - result=result, - attempt_id="attempt", - manifest_sha256="c" * 64, - result_path=attempt / "result.json", - ) - seen: dict[str, object] = {} - - def artifact_store(**kwargs: object) -> object: - seen.update(kwargs) - return SimpleNamespace(load_current=lambda cell_id: current) - - def report_paths(repo_root: Path, **kwargs: object) -> object: - assert repo_root == tmp_path.resolve() - assert kwargs == { - "docs_dir": docs, - "artifact_root": docs / "campaign_artifacts", - "coordination_root": docs / "campaign_artifacts" / "coordination", - } - return paths - - validate = mock.Mock() - monkeypatch.setattr(study.ReportPaths, "from_repo", report_paths) - monkeypatch.setattr(study, "ArtifactStore", artifact_store) - monkeypatch.setattr(study, "validate_measurement", validate) - reference = study._load_amplicol_reference( - tmp_path, "profile", case, "selected", points, 0.1, active - ) - - assert seen["current_publication_paths"] is paths - validate.assert_called_once_with(result, expected_cell=expected_cell) - assert reference.selector.flow_word == word - assert reference.matrix_element == 7.5 - assert reference.library_path == library.resolve() - assert reference.process_row == (1, 1) - assert reference.lineage["stored_selector_point_digest"] == singleton_digest - assert reference.timing["relative_standard_error"] == ( - 0.0 if process_id == 8 else 0.01 - ) - assert reference.selector_contract == { - **stored.as_dict(), - "point_digest": study.point_digest(points), - } - if process_id == 7: - outside = tmp_path / "outside-current-attempt" - outside.mkdir() - result["artifact"]["path"] = str(outside) - with pytest.raises(study.StudyError, match="outside its current attempt"): - study._load_amplicol_reference( - tmp_path, "profile", case, "selected", points, 0.1, active - ) - - -def test_process7_rejects_process8_amplicol_current( - monkeypatch: pytest.MonkeyPatch, tmp_path: Path -) -> None: - case7 = study._case(7, 5) - case8 = study._case(8, 5) - cell8 = study._reference_cell(case8, "selected") - paths = SimpleNamespace( - repo_root=tmp_path, - docs_dir=tmp_path / "docs", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - for path in (paths.docs_dir, paths.artifact_root, paths.coordination_root): - path.mkdir() - wrong = SimpleNamespace(cell_id=cell8.cell_id, result={"status": "ok"}) - monkeypatch.setattr(study.ReportPaths, "from_repo", lambda *_args, **_kwargs: paths) - monkeypatch.setattr( - study, - "ArtifactStore", - lambda **_kwargs: SimpleNamespace(load_current=lambda _cell_id: wrong), - ) - monkeypatch.setattr(study, "validate_measurement", lambda *_args, **_kwargs: None) - with pytest.raises(study.StudyError, match="workload identity"): - study._load_amplicol_reference( - tmp_path, - "profile", - case7, - "selected", - (((1.0, 0.0, 0.0, 1.0),),), - 0.1, - study.ReportSourceIdentity("a" * 40, "b" * 40, ()), - ) - - -def test_amplicol_matrix_element_is_an_explicit_singleton_authority() -> None: - case = study._case(7, 5) - states = fixed_selector_helicity(case.pdgs) - word = tuple(range(1, len(case.pdgs) + 1)) - selector = study.Selector( - word, - "flow:" + ",".join(map(str, word)), - states, - "h:" + ",".join(f"{state:+d}" for state in states), - ) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - contract = SelectorContract( - (selector.flow_id,), - (selector.flow_word,), - (selector.helicity_id,), - tuple(enumerate(selector.helicities, start=1)), - study.point_digest(points), - ) - reference = study.AmplicolReference( - selector=selector, - contract=contract, - selector_contract=contract.as_dict(), - matrix_element=3.0, - timing={}, - lineage={}, - ) - check = study._amplicol_singleton_check( - study.Evaluation((3.0, *(9.0 for _ in range(7))), None), - reference, - points, - ) - assert check["seed"] == 101 - assert check["point_count"] == 1 - assert check["stored_amplicol_matrix_element"] == 3.0 - assert check["comparison"]["checks"] == 1 - within_amplicol_tolerance = study._amplicol_singleton_check( - study.Evaluation((3.0 * (1.0 + 0.5e-8), *(9.0 for _ in range(7))), None), - reference, - points, - ) - assert within_amplicol_tolerance["comparison"]["checks"] == 1 - with pytest.raises(study.StudyError, match="disagrees"): - study._amplicol_singleton_check( - study.Evaluation((3.0 * (1.0 + 2.0e-8), *(9.0 for _ in range(7))), None), - reference, - points, - ) - - -def test_amplicol_replays_all_eight_points_from_exact_recorded_row( - monkeypatch: pytest.MonkeyPatch, tmp_path: Path -) -> None: - case = study._case(8, 5) - points = tuple( - tuple( - (float(index) + leg / 100.0, 0.0, 0.0, 1.0) for leg in range(len(case.pdgs)) - ) - for index in range(1, 9) - ) - word = study._colored_source_labels(case) - states = fixed_selector_helicity(case.pdgs) - selector = study.Selector( - word, - "flow:" + ",".join(map(str, word)), - states, - "h:" + ",".join(f"{state:+d}" for state in states), - ) - contract = SelectorContract( - (selector.flow_id,), - (selector.flow_word,), - (selector.helicity_id,), - tuple(enumerate(selector.helicities, start=1)), - study.point_digest(points), - ) - library = tmp_path / "selected-flow-generated-library" - library.mkdir() - entry = study.legacy_amplicol.ProcessEntry(3, 7, case.pdgs, word) - reference = study.AmplicolReference( - selector=selector, - contract=contract, - selector_contract=contract.as_dict(), - matrix_element=1.0, - timing={}, - lineage={}, - library_path=library, - process_row=(3, 7), - ) - monkeypatch.setattr( - study.legacy_amplicol, "parse_process_file", lambda _path: (entry,) - ) - monkeypatch.setattr( - study.legacy_amplicol, - "source_mapped_color_order", - lambda entry, **_kwargs: entry.color_order, - ) - monkeypatch.setenv("LD_LIBRARY_PATH", "/prior-ld") - monkeypatch.setenv("DYLD_LIBRARY_PATH", "/prior-dyld") - observed_environments: list[tuple[str | None, str | None]] = [] - - def replay_probe(_library: Path, **kwargs: object) -> object: - observed_environments.append( - (os.environ.get("LD_LIBRARY_PATH"), os.environ.get("DYLD_LIBRARY_PATH")) - ) - return SimpleNamespace( - value=kwargs["momenta"][0][0], - process_pdgs=case.pdgs, - color_order=word, - ) - - probe = mock.Mock(side_effect=replay_probe) - monkeypatch.setattr(study.legacy_amplicol, "run_selected_flow_library_probe", probe) - - values, evidence = study._replay_amplicol(reference, case, points) - - assert values == tuple(float(index) for index in range(1, 9)) - assert evidence["point_count"] == evidence["subprocess_launches"] == 8 - assert evidence["seed101_replay_vs_stored_matrix_element"]["checks"] == 1 - assert probe.call_count == 8 - root = str(library.resolve()) - assert ( - observed_environments - == [(f"{root}{os.pathsep}/prior-ld", f"{root}{os.pathsep}/prior-dyld")] * 8 - ) - assert os.environ["LD_LIBRARY_PATH"] == "/prior-ld" - assert os.environ["DYLD_LIBRARY_PATH"] == "/prior-dyld" - for point, call in zip(points, probe.call_args_list, strict=True): - assert call.args == (library,) - assert call.kwargs["entry"] is entry - assert call.kwargs["source_pdgs"] == case.pdgs - assert call.kwargs["momenta"] == point - assert call.kwargs["helicities"] is None - assert call.kwargs["points"] == 1 - - monkeypatch.setattr( - study.legacy_amplicol, - "run_selected_flow_library_probe", - lambda _library, **kwargs: SimpleNamespace( - value=kwargs["momenta"][0][0], - process_pdgs=case.pdgs, - color_order=tuple(reversed(word)), - ), - ) - with pytest.raises(study.StudyError, match="different semantic selector flow"): - study._replay_amplicol(reference, case, points) - - -def test_process7_compact_context_does_not_equate_backend_local_ordinals() -> None: - case = study._case(7, 5) - word = (2, 5, 6, 7, 4, 3, 1) - flow_id = "flow:" + ",".join(map(str, word)) - selector = study.Selector( - word, - flow_id, - fixed_selector_helicity(case.pdgs), - "h:-1,+1,-1,+1,-1,+1,-1", - ) - - class Backend: - @property - def physics(self) -> object: - raise AssertionError("dense physics opened") - - def _on_the_fly_benchmark_context(self, requested: object) -> dict[str, object]: - assert requested == (flow_id,) - return { - "process_id": case.process_id, - "process_expression": case.process, - "color_accuracy": "lc", - "helicity_count": 2 ** len(case.pdgs), - "color_count": 10, - "selected_color_ids": [flow_id], - } - - context = study._cross_check_compact_selector( - SimpleNamespace(_backend=Backend()), - case, - selector, - require_ordinal_one=False, - ) - assert context["requested_color_ids"] == [flow_id] - assert context["selected_color_ids"] == [flow_id] - assert context["ordinal_one_required"] is False - assert context["ordinal_one_matches_authority"] is None - - -def test_reference_source_must_match_generated_candidate() -> None: - revision = "a" * 40 - active = study.ReportSourceIdentity(revision, "c" * 40, ()) - assert study._candidate_source_binding(active, {"source_revision": revision}) == { - "status": "passed", - "policy": "exact-source-revision", - "source_revision": revision, - "source_tree": "c" * 40, - } - with pytest.raises(study.StudyError, match="active source"): - study._candidate_source_binding(active, {"source_revision": "b" * 40}) - - -def test_stale_reused_candidate_rejects_before_report_or_any_comparator( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - args = _args(tmp_path, 5, "all-flow") - candidate_path = tmp_path / "candidate" - candidate_path.mkdir() - selected_report = tmp_path / "selected-report.json" - selected_report.touch() - args.candidate_artifact = candidate_path - args.selected_report = selected_report - forbidden_recurrence = mock.Mock( - side_effect=AssertionError("recurrence generation must not start") - ) - forbidden_reference = mock.Mock( - side_effect=AssertionError("AmpliCol reference must not load") - ) - forbidden_report = mock.Mock( - side_effect=AssertionError("selected report validation must not start") - ) - monkeypatch.setattr( - study, - "_active_report_source", - lambda: study.ReportSourceIdentity("a" * 40, "c" * 40, ()), - ) - monkeypatch.setattr(study, "_load_amplicol_reference", forbidden_reference) - monkeypatch.setattr(study.Runtime, "load", lambda *_, **__: SimpleNamespace()) - monkeypatch.setattr( - study, - "_artifact_identity", - lambda *_: { - "producer_identity": { - "source_revision": "b" * 40, - "native_build_inputs_sha256": "d" * 64, - }, - "model_identity": {"content_sha256": "e" * 64}, - }, - ) - monkeypatch.setattr(study, "_selected_report_lineage", forbidden_report) - monkeypatch.setattr(study, "_generate_recurrence", forbidden_recurrence) - - with pytest.raises(study.StudyError, match=r"generated candidate.*active source"): - study._run_worker(args) - forbidden_report.assert_not_called() - forbidden_reference.assert_not_called() - forbidden_recurrence.assert_not_called() - - -def test_ineligible_active_source_is_reported(monkeypatch: pytest.MonkeyPatch) -> None: - monkeypatch.setattr( - study, - "require_eligible_report_source", - mock.Mock(side_effect=study.ReportSourceIdentityError("dirty source")), - ) - with pytest.raises(study.StudyError, match=r"active report source.*dirty source"): - study._active_report_source() - - -def _reference_provenance( - case: study.Case, workload: str, target: float = 0.1 -) -> dict[str, object]: - cell = study._reference_cell(case, workload) - workload_id = "selected-flow" if workload == "selected" else "all-flow" - return { - "revision": study.PINNED_REFERENCE_REVISION, - "generation_timing_is_workload_specific": True, - "manual_campaign": { - "batch_size": 128, - "warmup_runs": 2, - "minimum_samples": 5, - "target_runtime_seconds": target, - "cell_identity": { - "accuracy": "lc", - "backend": "fortran", - "cell_id": cell.cell_id, - "dataset_id": "reference_amplicol_lc", - "execution_mode": "amplicol", - "model": None, - "n_final": case.multiplicity, - "process": case.process, - "process_key": case.process_key, - "variant": None, - "workload": workload_id, - }, - }, - } - - -@pytest.mark.parametrize( - ("field", "value", "message"), - ( - ("batch_size", 64, "batch size"), - ("warmup_runs", 1, "warm-up count"), - ("minimum_samples", 4, "sample minimum"), - ("target_runtime_seconds", 0.2, "target runtime"), - ), -) -def test_reference_timing_contract_rejects_wrong_campaign_settings( - field: str, value: object, message: str -) -> None: - case = study._case(7, 5) - provenance = _reference_provenance(case, "selected") - manual = provenance["manual_campaign"] - assert isinstance(manual, dict) - manual[field] = value - with pytest.raises(study.StudyError, match=message): - study._reference_timing_contract(provenance, case, "selected", 0.1) - - -@pytest.mark.parametrize("value", (True, 4, 5.0, None)) -def test_reference_rejects_insufficient_actual_sample_count(value: object) -> None: - with pytest.raises(study.StudyError, match="actual samples"): - study._required_reference_sample_count({"sample_count": value}) - assert study._required_reference_sample_count({"sample_count": 5}) == 5 - - -def test_reference_selector_rejects_non_seed101_digest() -> None: - case = study._case(7, 5) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - states = fixed_selector_helicity(case.pdgs) - wrong = SelectorContract( - ("flow:2,5,6,7,4,3,1",), - ((2, 5, 6, 7, 4, 3, 1),), - ("h:" + ",".join(f"{state:+d}" for state in states),), - tuple(enumerate(states, start=1)), - "a" * 64, - ) - with pytest.raises(study.StudyError, match="seed-101 singleton"): - study._rebind_reference_selector(wrong.as_dict(), case, points) - - -def test_generation_reporting_separates_selected_ratios_from_all_flow_absolute() -> ( - None -): - selected, selected_ratios = study._generation_reporting( - "selected", - generation_seconds=2.0, - warmup_seconds=0.5, - amplicol_generation_seconds=1.0, - source="this-selected-run", - ) - assert selected["notation"] == "([xG] x(G+W))" - assert selected["generation_only_over_amplicol"] == 2.0 - assert selected["generation_plus_warmup_over_amplicol"] == 2.5 - assert selected_ratios == { - "generation_only": 2.0, - "generation_plus_warmup": 2.5, - } - - all_flow, all_flow_ratios = study._generation_reporting( - "all-flow", - generation_seconds=2.0, - warmup_seconds=0.75, - amplicol_generation_seconds=None, - source="reused-selected-artifact-generation", - ) - assert all_flow == { - "notation": "[G] G+W", - "reporting": "absolute-on-the-fly-seconds", - "source": "reused-selected-artifact-generation", - "warmup_source": "this-all-flow-cold-batch128-run", - "on_the_fly_generation_seconds": 2.0, - "on_the_fly_warmup_seconds": 0.75, - "on_the_fly_generation_plus_warmup_seconds": 2.75, - } - assert all_flow_ratios == {} - - -def _active(queries: int, destinations: int) -> dict[str, object]: - result = { - "basis": "shared-query-family-union-v1", - "scope": "active-family-union", - "query_count": queries, - "union_unique_current_count": 2, - "union_unique_current_component_count": 3, - "union_amplitude_destination_count": destinations, - } - for role in study.OPERATION_ROLES: - result[f"union_{role}_rows"] = 2 - result[f"union_{role}_executor_call_groups"] = 1 - return result - - -def _state( - families: int, - active: dict[str, object] | None = None, - *, - semantic_bindings: int | None = None, - process_id: str = "otf-test", -) -> dict[str, object]: - assert families in {0, 1} - warm = families == 1 - requests = int(active["query_count"]) if warm and active is not None else 0 - destinations = ( - int(active["union_amplitude_destination_count"]) - if warm and active is not None - else 0 - ) - return { - "kind": study.STATE_KIND, - "process_id": process_id, - "family_cache_policy": study.STATE_FAMILY_CACHE_POLICY, - "family_cache_limit": study.STATE_FAMILY_CACHE_LIMIT, - "process_preparation_count": int(warm), - "retained_family_count": families, - "pending_family_count": 0, - "retained_selection_count": families, - "retained_request_count": requests, - "retained_amplitude_destination_count": destinations, - "retained_executor_handle_count": families, - "retained_query_local_trace_count": 0, - "retained_embedded_lookup_key_count": 0, - "semantic_executor_binding_count": ( - int(warm) * 3 if semantic_bindings is None else semantic_bindings - ), - "active_family_union_census": active, - } - - -def test_census_uses_public_inspection_and_exact_last_family_contract() -> None: - process_id = "otf_p7_one_quark_line_n5" - retained = _state(1, _active(2, 1), process_id=process_id) - inspect_runtime = mock.Mock( - return_value={study.STATE_INSPECTION_KEY: copy.deepcopy(retained)} - ) - runtime = SimpleNamespace(inspect=inspect_runtime) - - assert study._census(runtime, process_id) == retained - inspect_runtime.assert_called_once_with() - - for field, value in ( - ("family_cache_policy", "all-seen"), - ("family_cache_limit", 2), - ("family_cache_limit", 1.0), - ("family_cache_limit", True), - ("unexpected", 1), - ): - broken = copy.deepcopy(retained) - broken[field] = value - candidate = SimpleNamespace( - inspect=lambda broken=broken: {study.STATE_INSPECTION_KEY: broken} - ) - with pytest.raises(study.StudyError): - study._census(candidate, process_id) - - -@pytest.mark.parametrize( - ("workload", "expected_kwargs"), - ( - ("selected", {"color_flows": ("flow:1",)}), - ("all-flow", {"helicities": ("h:-1",)}), - ), -) -def test_requested_workload_cold_warmup_is_batch128_and_clears( - monkeypatch: pytest.MonkeyPatch, - workload: str, - expected_kwargs: dict[str, tuple[str, ...]], -) -> None: - cold = _state(0) - warm = _state(1, _active(2, 1)) - states = iter((cold, warm, cold)) - monkeypatch.setattr(study, "_census", lambda *_: copy.deepcopy(next(states))) - monkeypatch.setattr( - study.time, - "perf_counter_ns", - mock.Mock(side_effect=(1_000_000, 4_000_000)), - ) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - captured: dict[str, object] = {} - - def evaluate(batch: object, **kwargs: object) -> tuple[complex, ...]: - captured["batch"] = batch - captured["kwargs"] = kwargs - return (1.0 + 0.0j,) * 128 - - runtime = SimpleNamespace(evaluate=evaluate, clear=mock.Mock()) - evidence = study._requested_workload_cold_warmup( - runtime, - study._case(7, 5), - study.Selector((1,), "flow:1", (-1,), "h:-1"), - points, - workload, - ratio_eligible=workload == "selected", - ) - - assert captured["kwargs"] == expected_kwargs - assert captured["batch"] == (points[0],) * 128 - assert evidence["requested_workload"] == workload - assert evidence["batch_size"] == evidence["point_count"] == 128 - assert evidence["seed"] == 101 - assert evidence["singleton_seed_point_digest"] == study.point_digest((points[0],)) - assert evidence["elapsed_nanoseconds"] == 3_000_000 - assert evidence["kind"] == study.REQUESTED_COLD_WARMUP_KIND - assert ( - evidence["query_construction_threads"] - == study.OTF_QUERY_CONSTRUCTION_THREADS - == 4 - ) - assert evidence["clear_restored_cold_state"] is True - assert "Runtime.load" in evidence["excluded_from_elapsed"] - assert "artifact generation" in evidence["excluded_from_elapsed"] - assert evidence["ratio_eligible"] is (workload == "selected") - runtime.clear.assert_called_once_with() - - -def test_lean_cold_warmup_correctness_repeat_and_benchmark_reuse_one_family( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cold = _state(0) - warm = _state(1, _active(2, 1)) - - class Runtime: - def __init__(self) -> None: - self.state = copy.deepcopy(cold) - self.family_builds = 0 - self.clear_calls = 0 - self.point_counts: list[int] = [] - - def evaluate(self, points: object, **_kwargs: object) -> tuple[complex, ...]: - point_count = len(points) # type: ignore[arg-type] - self.point_counts.append(point_count) - if self.state["retained_family_count"] == 0: - self.family_builds += 1 - self.state = copy.deepcopy(warm) - return (1.0 + 0.0j,) * point_count - - def clear(self) -> None: - self.clear_calls += 1 - self.state = copy.deepcopy(cold) - - runtime = Runtime() - monkeypatch.setattr( - study, "_census", lambda candidate, _process: copy.deepcopy(candidate.state) - ) - monkeypatch.setattr( - study.time, - "perf_counter_ns", - mock.Mock(side_effect=(1_000_000, 4_000_000)), - ) - case = study._case(8, 6) - selector = study.Selector((1,), "flow:1", (-1,), "h:-1") - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - - cold_evidence = study._requested_workload_cold_warmup( - runtime, - case, - selector, - points, - "selected", - ratio_eligible=True, - retain_family=True, - ) - before, after, lifecycle = study._lifecycle( - runtime, case, selector, points, "selected", False - ) - runtime.evaluate(study._timing_points(points), color_flows=(selector.flow_id,)) - - assert before is after and len(before.total) == len(study.SEEDS) - assert runtime.family_builds == 1 - assert runtime.clear_calls == 0 - assert runtime.point_counts == [128, 8, 1, 128] - assert cold_evidence["retained_for_followup"] is True - assert cold_evidence["kind"] == study.REQUESTED_COLD_WARMUP_KIND - assert cold_evidence["after_clear"] is None - assert cold_evidence["clear_call_status"] == ("omitted-retained-for-lean-lifecycle") - assert lifecycle["policy"]["mode"] == study.LIFECYCLE_LEAN - assert lifecycle["headline_point_count"] == 8 - assert lifecycle["plateau_repeat_point_count"] == 1 - assert lifecycle["plateau_repeat_self_consistency"]["total"]["checks"] == 1 - assert lifecycle["clear_rebuild"]["status"] == "omitted" - assert lifecycle["final_plateau"] == warm - assert runtime.state == lifecycle["final_plateau"] - - -def test_a_b_repeat_revisit_clear_rebuild_and_census_invariants( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cold, active_a, active_b = _state(0), _active(2, 1), _active(4, 2) - state_a = _state(1, active_a, semantic_bindings=3) - state_b = _state(1, active_b, semantic_bindings=5) - values = iter( - (cold, state_a, state_b, state_b, state_b, state_a, state_a, cold, state_b) - ) - monkeypatch.setattr(study, "_census", lambda *_: copy.deepcopy(next(values))) - monkeypatch.setattr( - study, "_evaluate", lambda *_, **__: study.Evaluation((1.0 + 0.0j,), None) - ) - monkeypatch.setattr(study, "_compare", lambda *_: {}) - - def native_evaluate(points: object, **_kwargs: object) -> tuple[complex, ...]: - if len(points) == 0: # type: ignore[arg-type] - raise study.EvaluationError( - "on-the-fly evaluation requires at least one point" - ) - return (1.0 + 0.0j,) * len(points) # type: ignore[arg-type] - - runtime = SimpleNamespace( - clear=mock.Mock(), evaluate=mock.Mock(side_effect=native_evaluate) - ) - lifecycle = study._lifecycle( - runtime, - study._case(7, 5), - study.Selector((1,), "flow:1", (-1,), "h:-1"), - ((((1.0, 0.0, 0.0, 1.0),),)), - "all-flow", - False, - )[2] - assert lifecycle["sequence"] == "A,B,B,failed-A,B,A,A; clear; A,B" - assert lifecycle["after_rebuild"] == state_b - assert lifecycle["final_plateau"] == state_b - assert lifecycle["selected_a_revisit"] == state_a - assert lifecycle["selected_a_revisit_repeat"] == state_a - assert ( - lifecycle["failed_selected_a_candidate"]["retained_family_after_failure"] - == state_b - ) - assert state_a["semantic_executor_binding_count"] == 3 - assert state_b["semantic_executor_binding_count"] == 5 - for state in (state_a, state_b): - assert state["retained_family_count"] == 1 - assert state["retained_selection_count"] == 1 - assert state["retained_executor_handle_count"] == 1 - assert lifecycle["policy"]["mode"] == study.LIFECYCLE_EXHAUSTIVE - assert lifecycle["clear_rebuild"]["status"] == "performed" - assert "cold_first_evaluation_timing" not in lifecycle - assert runtime.evaluate.call_count == 2 - assert runtime.evaluate.call_args_list[0] == mock.call( - ((((1.0, 0.0, 0.0, 1.0),),)), color_flows=("flow:1",) - ) - assert runtime.evaluate.call_args_list[1] == mock.call((), color_flows=("flow:1",)) - runtime.clear.assert_called_once_with() - for field, value in ( - ("retained_amplitude_destination_count", 0), - ("retained_request_count", 0), - ): - broken = copy.deepcopy(state_a) - broken[field] = value - with pytest.raises(study.StudyError): - study._assert_family_state(broken, "A") - broken = copy.deepcopy(state_a) - broken["active_family_union_census"]["union_source_executor_call_groups"] = 3 - with pytest.raises(study.StudyError): - study._assert_family_state(broken, "A") - - -def test_selected_a_c_repeat_revisit_and_rebuild( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cold, active_a, active_c = _state(0), _active(2, 1), _active(1, 1) - state_a = _state(1, active_a, semantic_bindings=3) - state_c = _state(1, active_c, semantic_bindings=2) - values = iter( - ( - cold, - state_a, - state_c, - state_c, - state_c, - state_a, - state_a, - cold, - state_a, - state_c, - state_a, - state_a, - ) - ) - calls: list[str] = [] - monkeypatch.setattr(study, "_census", lambda *_: copy.deepcopy(next(values))) - - def evaluate( - _runtime: object, - _points: object, - workload: str, - _selector: object, - *, - resolved: bool, - _precomputed_total: tuple[object, ...] | None = None, - ) -> study.Evaluation: - assert resolved is False - if not calls: - assert _precomputed_total == (1.0 + 0.0j,) - calls.append(workload) - return study.Evaluation((1.0 + 0.0j,), None) - - monkeypatch.setattr(study, "_evaluate", evaluate) - monkeypatch.setattr(study, "_compare", lambda *_: {}) - - def native_evaluate(points: object, **_kwargs: object) -> tuple[complex, ...]: - if len(points) == 0: # type: ignore[arg-type] - raise study.EvaluationError( - "on-the-fly evaluation requires at least one point" - ) - return (1.0 + 0.0j,) * len(points) # type: ignore[arg-type] - - runtime = SimpleNamespace( - clear=mock.Mock(), evaluate=mock.Mock(side_effect=native_evaluate) - ) - lifecycle = study._lifecycle( - runtime, - study._case(7, 6), - study.Selector((1,), "flow:1", (-1,), "h:-1"), - ((((1.0, 0.0, 0.0, 1.0),),)), - "selected", - False, - )[2] - - assert calls == [ - "selected", - "exact", - "exact", - "selected", - "selected", - "selected", - "exact", - "selected", - "selected", - ] - assert lifecycle["sequence"] == "A,C,C,failed-A,C,A,A; clear; A,C,A,A" - assert lifecycle["requested_family"] == state_c - assert lifecycle["selected_a_revisit"] == state_a - assert lifecycle["selected_a_revisit_repeat"] == state_a - assert lifecycle["after_rebuild"] == state_a - assert lifecycle["final_plateau"] == state_a - assert ( - lifecycle["failed_selected_a_candidate"]["retained_family_after_failure"] - == state_c - ) - assert state_a["semantic_executor_binding_count"] == 3 - assert state_c["semantic_executor_binding_count"] == 2 - assert lifecycle["policy"]["mode"] == study.LIFECYCLE_EXHAUSTIVE - assert lifecycle["clear_rebuild"]["status"] == "performed" - assert "cold_first_evaluation_timing" not in lifecycle - runtime.clear.assert_called_once_with() - - -def _worker_selector( - case: study.Case, points: tuple[object, ...] -) -> tuple[study.Selector, SelectorContract]: - word = study._colored_source_labels(case) - states = fixed_selector_helicity(case.pdgs) - selector = study.Selector( - word, - "flow:" + ",".join(map(str, word)), - states, - "h:" + ",".join(f"{state:+d}" for state in states), - ) - return selector, SelectorContract( - (selector.flow_id,), - (selector.flow_word,), - (selector.helicity_id,), - tuple(enumerate(selector.helicities, start=1)), - study.point_digest(points), - ) - - -def _patch_selected_worker_basics( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - case: study.Case, - points: tuple[object, ...], - candidate: object, -) -> tuple[study.ReportSourceIdentity, dict[str, object]]: - source = study.ReportSourceIdentity("b" * 40, "e" * 40, ()) - identity = { - "path": str(tmp_path / "out" / "candidate-artifact"), - "artifact_id": "a" * 64, - "producer_identity": { - "source_revision": source.revision, - "native_build_inputs_sha256": "c" * 64, - }, - "model_identity": {"content_sha256": "d" * 64}, - } - monkeypatch.setattr(study, "_points", lambda _case: points) - monkeypatch.setattr(study, "_active_report_source", lambda: source) - monkeypatch.setattr( - study.ModelSource, - "from_path", - lambda _path: SimpleNamespace(compile=lambda: object()), - ) - monkeypatch.setattr( - study.Runtime, - "load", - lambda path, **_kwargs: ( - candidate - if "recurrence-authority" not in str(path) - else SimpleNamespace(execution_mode="recurrence") - ), - ) - monkeypatch.setattr(study, "_artifact_identity", lambda *_args: dict(identity)) - monkeypatch.setattr( - study, - "_requested_workload_cold_warmup", - lambda *_args, **_kwargs: {"seconds": 0.5}, - ) - monkeypatch.setattr(study, "_census", lambda *_args: {}) - return source, identity - - -@pytest.mark.parametrize( - ("process_id", "multiplicity"), - ((7, 5), (8, 5), (11, 5), (13, 5), (15, 5), (7, 7)), -) -def test_amplicol_cells_forbid_recurrence_and_compiled_and_replay_eight_points( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - process_id: int, - multiplicity: int, -) -> None: - args = _args(tmp_path, multiplicity, "selected", process_id=process_id) - args.prepared_model = tmp_path / "model" - args.prepared_model.touch() - case = study._case(process_id, multiplicity) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - selector, contract = _worker_selector(case, points) - candidate = SimpleNamespace() - _patch_selected_worker_basics(monkeypatch, tmp_path, case, points, candidate) - cold_warmup = mock.Mock(return_value={"seconds": 0.5}) - monkeypatch.setattr(study, "_requested_workload_cold_warmup", cold_warmup) - reference = study.AmplicolReference( - selector=selector, - contract=contract, - selector_contract=contract.as_dict(), - matrix_element=3.0, - timing={ - "generation_seconds": 1.0, - "wall_seconds_per_point": 0.5e-6, - "evaluator_seconds_per_point": 0.4e-6, - }, - lineage={"status": "authenticated"}, - ) - monkeypatch.setattr(study, "_load_amplicol_reference", lambda *_args: reference) - monkeypatch.setattr( - study, - "_generate_otf", - lambda *_args: { - "seconds": 2.0, - "seed_binding_calls": 1, - "seed_count": 1, - "materialized_lane_calls": 0, - "query_construction_threads": study.OTF_QUERY_CONSTRUCTION_THREADS, - }, - ) - forbidden_recurrence = mock.Mock( - side_effect=AssertionError("AmpliCol cell entered recurrence") - ) - monkeypatch.setattr(study, "_generate_recurrence", forbidden_recurrence) - compact = mock.Mock( - return_value={ - "selected_color_ids": [selector.flow_id], - "ordinal_one_required": False, - "ordinal_one_matches_authority": None, - } - ) - monkeypatch.setattr(study, "_cross_check_compact_selector", compact) - evaluation = study.Evaluation((3.0, *(4.0 for _ in range(7))), None) - lifecycle_evidence: dict[str, object] = {"final_plateau": {}} - if multiplicity >= 7: - lifecycle_evidence["plateau_repeat_self_consistency"] = {"total": {"checks": 1}} - lifecycle = mock.Mock(return_value=(evaluation, evaluation, lifecycle_evidence)) - monkeypatch.setattr(study, "_lifecycle", lifecycle) - replay = mock.Mock( - return_value=( - evaluation.total, - {"status": "passed", "point_count": 8, "subprocess_launches": 8}, - ) - ) - monkeypatch.setattr(study, "_replay_amplicol", replay) - monkeypatch.setattr(study, "_compare", lambda *_args: {"checks": 8}) - monkeypatch.setattr( - study, - "_benchmark", - lambda *_args: { - "wall_seconds_per_point": 1.0e-6, - "evaluator_seconds_per_point": 0.8e-6, - }, - ) - - result = study._run_worker(args) - - assert set(result["generation"]) == {"on_the_fly"} - assert set(result["artifacts"]) == {"candidate"} - assert set(result["timings"]) == {"on_the_fly", "amplicol"} - assert ( - result["correctness"]["otf_seed101_vs_amplicol_matrix_element"]["status"] - == "passed" - ) - authority_key = ( - "otf_retained_vs_amplicol_replay" - if multiplicity >= 7 - else "otf_before_vs_amplicol_replay" - ) - assert result["correctness"][authority_key]["checks"] == 8 - assert result["correctness"]["claim_scope"]["external_amplicol_point_count"] == 8 - assert result["forbidden_paths"]["compiled_generation"] == "not-called" - assert result["forbidden_paths"]["recurrence_generation"] == "not-called" - compact.assert_called_once_with( - candidate, case, selector, require_ordinal_one=False - ) - replay.assert_called_once_with(reference, case, points) - assert lifecycle.call_args.args[-1] is True - assert cold_warmup.call_args.kwargs["retain_family"] is (multiplicity >= 7) - if multiplicity >= 7: - assert ( - result["correctness"]["retained_family_plateau_self_consistency"]["total"][ - "checks" - ] - == 1 - ) - assert "pre_post_clear_self_consistency" not in result["correctness"] - forbidden_recurrence.assert_not_called() - with pytest.raises(study.StudyError, match="forbids execution mode"): - study._config("compiled", "topology-replay") - - -@pytest.mark.parametrize("multiplicity", (6, 7)) -def test_id14_uses_recurrence_only_and_derives_its_selector( - monkeypatch: pytest.MonkeyPatch, tmp_path: Path, multiplicity: int -) -> None: - args = _args(tmp_path, multiplicity, "selected", process_id=14) - args.prepared_model = tmp_path / "model" - args.prepared_model.touch() - case = study._case(14, multiplicity) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - selector, contract = _worker_selector(case, points) - candidate = SimpleNamespace() - source, identity = _patch_selected_worker_basics( - monkeypatch, tmp_path, case, points, candidate - ) - cold_warmup = mock.Mock(return_value={"seconds": 0.5}) - monkeypatch.setattr(study, "_requested_workload_cold_warmup", cold_warmup) - recurrence = SimpleNamespace(execution_mode="recurrence") - monkeypatch.setattr( - study.Runtime, - "load", - lambda path, **_kwargs: ( - recurrence if "recurrence-authority" in str(path) else candidate - ), - ) - monkeypatch.setattr( - study, - "_artifact_identity", - lambda path, *_args: { - **identity, - "path": str(path), - "producer_identity": { - "source_revision": source.revision, - "native_build_inputs_sha256": "c" * 64, - }, - }, - ) - forbidden_reference = mock.Mock( - side_effect=AssertionError("ID14 must not load AmpliCol") - ) - monkeypatch.setattr(study, "_load_amplicol_reference", forbidden_reference) - monkeypatch.setattr( - study, - "_generate_otf", - lambda *_args: { - "seconds": 2.0, - "seed_binding_calls": 1, - "seed_count": 1, - "materialized_lane_calls": 0, - "query_construction_threads": study.OTF_QUERY_CONSTRUCTION_THREADS, - }, - ) - generate_recurrence = mock.Mock( - return_value={ - "execution_mode": "recurrence", - "layout": "topology-replay", - "seconds": 4.0, - "generation_threads": study.RECURRENCE_GENERATION_THREADS, - } - ) - monkeypatch.setattr(study, "_generate_recurrence", generate_recurrence) - derive = mock.Mock(return_value=contract) - validate = mock.Mock() - monkeypatch.setattr(study, "derive_selector_contract", derive) - monkeypatch.setattr(study, "validate_selector_contract", validate) - compact = mock.Mock( - return_value={ - "selected_color_ids": [selector.flow_id], - "ordinal_one_required": False, - "ordinal_one_matches_authority": None, - } - ) - monkeypatch.setattr(study, "_cross_check_compact_selector", compact) - evaluation = study.Evaluation((3.0,) * 8, None) - lifecycle_evidence: dict[str, object] = {"final_plateau": {}} - if multiplicity >= 7: - lifecycle_evidence["plateau_repeat_self_consistency"] = {"total": {"checks": 1}} - monkeypatch.setattr( - study, - "_lifecycle", - lambda *_args: (evaluation, evaluation, lifecycle_evidence), - ) - evaluate = mock.Mock(return_value=evaluation) - monkeypatch.setattr(study, "_evaluate", evaluate) - monkeypatch.setattr(study, "_compare", lambda *_args: {"total": {"checks": 8}}) - monkeypatch.setattr( - study, - "_benchmark", - lambda _runtime, mode, *_args: { - "wall_seconds_per_point": 1.0e-6 if mode == "on-the-fly" else 0.5e-6, - "evaluator_seconds_per_point": 0.8e-6 if mode == "on-the-fly" else 0.4e-6, - }, - ) - - result = study._run_worker(args) - - assert result["authority"]["kind"] == "recurrence" - assert set(result["generation"]) == {"on_the_fly", "recurrence"} - assert set(result["artifacts"]) == {"candidate", "recurrence_authority"} - assert set(result["timings"]) == {"on_the_fly", "recurrence"} - assert result["generation_comparison"]["recurrence_generation_seconds"] == 4.0 - assert result["generation_comparison"]["generation_only_over_recurrence"] == 0.5 - assert ( - result["generation_comparison"]["generation_plus_warmup_over_recurrence"] - == 0.625 - ) - assert result["descriptive_ratios"]["on_the_fly_over_recurrence"] == { - "wall_seconds_per_point": 2.0, - "evaluator_seconds_per_point": 2.0, - "generation_only": 0.5, - "generation_plus_warmup": 0.625, - } - derive.assert_called_once_with(recurrence, points) - validate.assert_called_once_with(recurrence, contract, points) - compact.assert_called_once_with( - candidate, case, selector, require_ordinal_one=False - ) - assert cold_warmup.call_args.kwargs["ratio_eligible"] is True - assert cold_warmup.call_args.kwargs["retain_family"] is (multiplicity >= 7) - authority_key = ( - "otf_retained_vs_recurrence" - if multiplicity >= 7 - else "otf_before_vs_recurrence" - ) - assert result["correctness"][authority_key]["total"]["checks"] == 8 - if multiplicity >= 7: - assert ( - result["correctness"]["retained_family_plateau_self_consistency"]["total"][ - "checks" - ] - == 1 - ) - assert "pre_post_clear_self_consistency" not in result["correctness"] - evaluate.assert_called_once_with( - recurrence, points, "selected", selector, resolved=True - ) - generate_recurrence.assert_called_once() - forbidden_reference.assert_not_called() - - -def test_n8_selected_is_compact_ordinal_one_and_forbids_comparators( - monkeypatch: pytest.MonkeyPatch, tmp_path: Path -) -> None: - args = _args(tmp_path, 8, "selected", process_id=8) - args.prepared_model = tmp_path / "model" - args.prepared_model.touch() - case = study._case(8, 8) - points = tuple(((float(index), 0.0, 0.0, 1.0),) for index in range(8)) - flow_id = "flow:1,2,3,4,5,6,7,8,9,10" - - class Backend: - @property - def physics(self) -> object: - raise AssertionError("n8 dense physics opened") - - def _on_the_fly_benchmark_context(self, requested: object) -> dict[str, object]: - assert requested == ("1",) - return { - "process_id": case.process_id, - "process_expression": case.process, - "color_accuracy": "lc", - "helicity_count": 1024, - "color_count": 100, - "selected_color_ids": [flow_id], - } - - candidate = SimpleNamespace(_backend=Backend()) - _patch_selected_worker_basics(monkeypatch, tmp_path, case, points, candidate) - forbidden = mock.Mock(side_effect=AssertionError("n8 comparator called")) - monkeypatch.setattr(study, "_load_amplicol_reference", forbidden) - monkeypatch.setattr(study, "_generate_recurrence", forbidden) - monkeypatch.setattr(study, "derive_selector_contract", forbidden) - monkeypatch.setattr( - study, - "_generate_otf", - lambda *_args: { - "seconds": 2.0, - "seed_binding_calls": 1, - "seed_count": 1, - "materialized_lane_calls": 0, - "query_construction_threads": study.OTF_QUERY_CONSTRUCTION_THREADS, - }, - ) - evaluation = study.Evaluation((3.0,) * 8, None) - lifecycle = mock.Mock( - return_value=( - evaluation, - evaluation, - { - "final_plateau": {}, - "plateau_repeat_self_consistency": {"total": {"checks": 1}}, - }, - ) - ) - monkeypatch.setattr(study, "_lifecycle", lifecycle) - monkeypatch.setattr(study, "_compare", lambda *_args: {"checks": 8}) - monkeypatch.setattr( - study, - "_benchmark", - lambda *_args: { - "wall_seconds_per_point": 1.0e-6, - "evaluator_seconds_per_point": 0.8e-6, - }, - ) - - result = study._run_worker(args) - - assert result["authority"]["kind"] == "otf-only" - assert result["selector_contract"]["selected_color_flow_ids"] == [flow_id] - assert result["compact_selector_context"]["requested_color_ids"] == ["1"] - assert result["correctness"]["status"] == "not-claimed" - assert set(result["timings"]) == {"on_the_fly"} - assert result["descriptive_ratios"] == {} - assert lifecycle.call_args.args[-1] is False - assert result["forbidden_paths"]["physics_enumeration"] == "not-called" - assert result["forbidden_paths"]["resolved_output"] == "not-called" - forbidden.assert_not_called() - - -def test_identity_n8_forbidden_route_and_worker_argv( - monkeypatch: pytest.MonkeyPatch, tmp_path: Path -) -> None: - case, artifact_id = study._case(7, 8), "a" * 64 - manifest = SimpleNamespace( - root=tmp_path, - artifact_id=artifact_id, - processes=( - dict( - id=case.process_id, - expression=case.process, - external_pdgs=case.pdgs, - color_accuracy="lc", - ), - ), - producer={"git_revision": "b" * 40, "native_build_inputs_sha256": "c" * 64}, - model={ - "name": "built-in-sm", - "source_kind": "built-in-sm", - "content_sha256": "d" * 64, - "compiled_schema_version": 9, - }, - ) - metadata = dict( - execution_mode="on-the-fly", - process=case.process, - process_key=case.process_id, - representative_process=case.process, - representative_process_key=case.process_id, - color_accuracy="lc", - external_pdg_order=case.pdgs, - external_count=len(case.pdgs), - ) - runtime = SimpleNamespace( - artifact_id=artifact_id, - execution_mode="on-the-fly", - representative_process_key=case.process_id, - _backend=SimpleNamespace( - _runtime=SimpleNamespace(artifact_id=artifact_id), _native_metadata=metadata - ), - ) - monkeypatch.setattr(study, "load_manifest", lambda *_, **__: manifest) - identity = study._artifact_identity(tmp_path, runtime, case, "on-the-fly") - assert identity["producer_identity"]["source_revision"] == "b" * 40 - mismatched = copy.deepcopy(identity) - mismatched["model_identity"]["content_sha256"] = "e" * 64 - with pytest.raises(study.StudyError, match="different models"): - study._common_model_identity({"candidate": identity, "authority": mismatched}) - wrong_report = tmp_path / "wrong-selected.json" - wrong_report.write_text(json.dumps({"kind": "wrong"}), encoding="utf-8") - with pytest.raises(study.StudyError, match="wrong study identity"): - study._selected_report_lineage( - wrong_report, - case, - identity, - study.ReportSourceIdentity("b" * 40, "e" * 40, ()), - ) - - candidate = tmp_path / "candidate with spaces; no shell" - candidate.mkdir() - selected_report = tmp_path / "selected-report.json" - selected_report.touch() - args = _args(tmp_path, 8, "all-flow") - args.candidate_artifact = candidate - args.selected_report = selected_report - command = study._worker_command(args, args.output) - assert isinstance(command, list) and command[0] == sys.executable - assert str(candidate.resolve()) in command - assert command[-1] == str(selected_report.resolve()) - - selector = study.Selector( - tuple(range(1, 11)), - "flow:" + ",".join(map(str, range(1, 11))), - fixed_selector_helicity(case.pdgs), - "h:-1,+1,-1,+1,-1,+1,-1,+1,-1,+1", - ) - contract = SelectorContract( - (selector.flow_id,), - (selector.flow_word,), - (selector.helicity_id,), - tuple(enumerate(selector.helicities, start=1)), - study.point_digest(study._points(case)), - ) - forbidden = mock.Mock(side_effect=AssertionError("forbidden n>=8 route")) - active_source = study.ReportSourceIdentity("b" * 40, "e" * 40, ()) - candidate_identity = { - **identity, - "path": str(candidate.resolve()), - "artifact_id": artifact_id, - } - retained_state = _state( - 1, - _active(2, 1), - process_id=case.process_id, - ) - selected_report.write_text( - json.dumps( - { - "kind": f"{study.KIND}-run", - "schema_version": study.SCHEMA_VERSION, - "status": "passed", - "watchdog": { - "passes": True, - "limit_bytes": study.WATCHDOG_BYTES, - }, - "study": { - "kind": study.KIND, - "schema_version": study.SCHEMA_VERSION, - "status": "passed", - "workload": "selected", - "process": study.dataclass_payload(case), - "authority": {"kind": study.AUTHORITY_OTF_ONLY}, - "correctness": { - "status": "not-claimed", - "retained_family_plateau_self_consistency": { - "total": {"checks": 1} - }, - }, - "lifecycle_policy": study._lifecycle_policy(case, "selected"), - "cache_lifecycle": { - "policy": study._lifecycle_policy(case, "selected"), - "headline_point_count": 8, - "headline_seeds": list(study.SEEDS), - "plateau_repeat_point_count": 1, - "retained_requested_family": retained_state, - "clear_rebuild": study._clear_rebuild_evidence( - study._lifecycle_policy(case, "selected") - ), - "final_plateau": retained_state, - }, - "requested_workload_cold_warmup": { - "kind": study.REQUESTED_COLD_WARMUP_KIND, - "requested_workload": "selected", - "batch_size": 128, - "point_count": 128, - "query_construction_threads": ( - study.OTF_QUERY_CONSTRUCTION_THREADS - ), - "retained_for_followup": True, - "clear_call_status": ("omitted-retained-for-lean-lifecycle"), - "after_clear": None, - "after_first_evaluation": retained_state, - }, - "compact_selector_context": { - "selector_source": "compact-seed-one-based-color-ordinal-1", - "requested_color_ids": ["1"], - "selected_color_ids": [selector.flow_id], - "resolved_semantic_flow_id": selector.flow_id, - }, - "producer_identity": identity["producer_identity"], - "model_identity": identity["model_identity"], - "active_source": active_source.provenance(), - "candidate_source_binding": study._candidate_source_binding( - active_source, identity["producer_identity"] - ), - "generation": { - "on_the_fly": { - "seconds": 1.0, - "seed_binding_calls": 1, - "seed_count": 1, - "materialized_lane_calls": 0, - "query_construction_threads": ( - study.OTF_QUERY_CONSTRUCTION_THREADS - ), - } - }, - "timing_contract": { - "on_the_fly_query_construction_threads": ( - study.OTF_QUERY_CONSTRUCTION_THREADS - ), - "recurrence_generation_threads": ( - study.RECURRENCE_GENERATION_THREADS - ), - }, - "selector_contract": contract.as_dict(), - "artifacts": {"candidate": candidate_identity}, - }, - } - ), - encoding="utf-8", - ) - monkeypatch.setattr(study, "_active_report_source", lambda: active_source) - monkeypatch.setattr(study, "_load_amplicol_reference", forbidden) - loaded: list[tuple[Path, str]] = [] - - def load(path: Path, *, process: str) -> object: - loaded.append((Path(path), process)) - return runtime - - monkeypatch.setattr(study.Runtime, "load", load) - monkeypatch.setattr( - study, - "_artifact_identity", - lambda *_: candidate_identity, - ) - monkeypatch.setattr( - study, - "_cross_check_compact_selector", - lambda *_, **__: {"selected_color_ids": [selector.flow_id]}, - ) - monkeypatch.setattr( - study, - "_requested_workload_cold_warmup", - lambda *_, **__: { - "requested_workload": "all-flow", - "batch_size": 128, - "point_count": 128, - "seconds": 0.5, - }, - ) - monkeypatch.setattr( - study, - "_lifecycle", - lambda *args: ( - study.Evaluation((1j,), None), - study.Evaluation((1j,), None), - { - "final_plateau": {}, - "plateau_repeat_self_consistency": {"total": {"checks": 1}}, - }, - ), - ) - monkeypatch.setattr( - study, - "_benchmark", - lambda *_: { - "wall_seconds_per_point": 1e-6, - "evaluator_seconds_per_point": 0.8e-6, - }, - ) - monkeypatch.setattr(study, "_census", lambda *_: {}) - monkeypatch.setattr(study, "_compare", lambda *_: {}) - monkeypatch.setattr(study, "_generate_recurrence", forbidden) - monkeypatch.setattr(study, "derive_selector_contract", forbidden) - monkeypatch.setattr(study.ModelSource, "from_path", forbidden) - result = study._run_worker(args) - assert loaded == [(candidate.resolve(), case.process_id)] - assert result["candidate_reuse"]["status"] == "actual-reuse" - assert ( - result["generation"] == {} and result["correctness"]["status"] == "not-claimed" - ) - assert result["candidate_source_binding"]["status"] == "passed" - assert result["amplicol_reference"] is None - assert set(result["timings"]) == {"on_the_fly"} - assert result["generation_comparison"] == { - "notation": "[G] G+W", - "reporting": "absolute-on-the-fly-seconds", - "source": "reused-selected-artifact-generation", - "warmup_source": "this-all-flow-cold-batch128-run", - "on_the_fly_generation_seconds": 1.0, - "on_the_fly_warmup_seconds": 0.5, - "on_the_fly_generation_plus_warmup_seconds": 1.5, - } - assert result["descriptive_ratios"] == {} - assert result["forbidden_paths"]["external_comparator"] == "not-created" - assert result["forbidden_paths"]["physics_enumeration"] == "not-called" - valid_selected = json.loads(selected_report.read_text(encoding="utf-8")) - for mutation in ( - "missing-warmup", - "wrong-warmed-census", - "wrong-prerequisite", - "wrong-thread-contract", - ): - invalid = copy.deepcopy(valid_selected) - selected = invalid["study"] - if mutation == "missing-warmup": - del selected["requested_workload_cold_warmup"] - elif mutation == "wrong-warmed-census": - selected["requested_workload_cold_warmup"]["after_first_evaluation"] = { - "retained_family_count": 2 - } - elif mutation == "wrong-prerequisite": - selected["cache_lifecycle"]["clear_rebuild"][ - "expected_prior_campaign_prerequisite" - ]["workload"] = "all-flow" - else: - selected["timing_contract"]["on_the_fly_query_construction_threads"] = 1 - selected_report.write_text(json.dumps(invalid), encoding="utf-8") - with pytest.raises(study.StudyError): - study._selected_report_lineage( - selected_report, case, candidate_identity, active_source - ) - forbidden.assert_not_called() - - -def test_resolved_total_must_match_public_total() -> None: - selector = study.Selector((1,), "flow:1", (-1,), "h:-1") - - class Resolved: - color_ids = ("flow:1",) - - @staticmethod - def total() -> tuple[complex, ...]: - return (2.0 + 0.0j,) - - runtime = SimpleNamespace( - evaluate=lambda *_args, **_kwargs: (1.0 + 0.0j,), - evaluate_resolved=lambda *_args, **_kwargs: Resolved(), - ) - with pytest.raises(study.StudyError): - study._evaluate( - runtime, - ((((1.0, 0.0, 0.0, 1.0),),)), - "selected", - selector, - resolved=True, - ) - - -@pytest.mark.parametrize( - "mutation", - ( - None, - "artifact-id", - "canonical-path", - "authority", - "source-lineage", - "selector-proof", - "contract-flow", - ), -) -def test_selected_report_binds_exact_candidate( - mutation: str | None, tmp_path: Path -) -> None: - case = study._case(7, 5) - candidate_path = tmp_path / "candidate" - candidate_path.mkdir() - canonical = str(candidate_path.resolve()) - artifact_id = "a" * 64 - source = study.ReportSourceIdentity("b" * 40, "e" * 40, ()) - producer = { - "source_revision": source.revision, - "native_build_inputs_sha256": "c" * 64, - } - model = {"content_sha256": "d" * 64} - recorded_path = canonical - recorded_id = artifact_id - if mutation == "artifact-id": - recorded_id = "b" * 64 - elif mutation == "canonical-path": - recorded_path = ( - f"{candidate_path.parent}/../{candidate_path.parent.name}/candidate" - ) - cold_state = _state(0, process_id=case.process_id) - selected_a_state = _state( - 1, - _active(2, 1), - semantic_bindings=3, - process_id=case.process_id, - ) - exact_c_state = _state( - 1, - _active(1, 1), - semantic_bindings=2, - process_id=case.process_id, - ) - payload = { - "kind": f"{study.KIND}-run", - "schema_version": study.SCHEMA_VERSION, - "status": "passed", - "watchdog": {"passes": True, "limit_bytes": study.WATCHDOG_BYTES}, - "study": { - "kind": study.KIND, - "schema_version": study.SCHEMA_VERSION, - "status": "passed", - "workload": "selected", - "process": study.dataclass_payload(case), - "authority": {"kind": study.AUTHORITY_AMPLICOL}, - "correctness": { - "status": "passed", - "otf_before_vs_amplicol_replay": {"checks": 8}, - "otf_after_vs_amplicol_replay": {"checks": 8}, - "pre_post_clear_self_consistency": {"total": {"checks": 8}}, - }, - "lifecycle_policy": study._lifecycle_policy(case, "selected"), - "cache_lifecycle": { - "policy": study._lifecycle_policy(case, "selected"), - "clear_rebuild": study._clear_rebuild_evidence( - study._lifecycle_policy(case, "selected") - ), - "selected_a": selected_a_state, - "requested_family": exact_c_state, - "requested_repeat": exact_c_state, - "failed_selected_a_candidate": { - "status": "passed", - "candidate_workload": "selected", - "point_count": 0, - "failure": "on-the-fly evaluation requires at least one point", - "retained_family_after_failure": exact_c_state, - }, - "selected_a_revisit": selected_a_state, - "selected_a_revisit_repeat": selected_a_state, - "after_clear": cold_state, - "after_rebuild_selected_a": selected_a_state, - "after_rebuild_exact_c": exact_c_state, - "after_rebuild_selected_a_revisit": selected_a_state, - "after_rebuild_selected_a_repeat": selected_a_state, - "after_rebuild": selected_a_state, - "final_plateau": selected_a_state, - "sequence": "A,C,C,failed-A,C,A,A; clear; A,C,A,A", - }, - "requested_workload_cold_warmup": { - "query_construction_threads": study.OTF_QUERY_CONSTRUCTION_THREADS, - }, - "compact_selector_context": { - "ordinal_one_required": False, - "ordinal_one_matches_authority": None, - "requested_color_ids": ["flow:2,5,6,7,4,3,1"], - "selected_color_ids": ["flow:2,5,6,7,4,3,1"], - "semantic_authority_flow_id": "flow:2,5,6,7,4,3,1", - }, - "producer_identity": producer, - "model_identity": model, - "active_source": source.provenance(), - "candidate_source_binding": study._candidate_source_binding( - source, producer - ), - "generation": { - "on_the_fly": { - "seconds": 1.0, - "seed_binding_calls": 1, - "seed_count": 1, - "materialized_lane_calls": 0, - "query_construction_threads": ( - study.OTF_QUERY_CONSTRUCTION_THREADS - ), - } - }, - "timing_contract": { - "on_the_fly_query_construction_threads": ( - study.OTF_QUERY_CONSTRUCTION_THREADS - ), - "recurrence_generation_threads": (study.RECURRENCE_GENERATION_THREADS), - }, - "selector_contract": SelectorContract( - ("flow:2,5,6,7,4,3,1",), - ((2, 5, 6, 7, 4, 3, 1),), - ("h:-1,+1,-1,+1,-1,+1,-1",), - tuple(enumerate(fixed_selector_helicity(case.pdgs), start=1)), - "f" * 64, - ).as_dict(), - "artifacts": { - "candidate": {"path": recorded_path, "artifact_id": recorded_id} - }, - }, - } - if mutation == "authority": - payload["study"]["authority"]["kind"] = study.AUTHORITY_OTF_ONLY - elif mutation == "source-lineage": - payload["study"]["producer_identity"]["source_revision"] = "e" * 40 - elif mutation == "selector-proof": - payload["study"]["compact_selector_context"]["requested_color_ids"] = ["1"] - elif mutation == "contract-flow": - payload["study"]["compact_selector_context"]["semantic_authority_flow_id"] = ( - "flow:1,2,3,4,5,6,7" - ) - report = tmp_path / f"selected-{mutation or 'valid'}.json" - report.write_text(json.dumps(payload), encoding="utf-8") - candidate = { - "path": canonical, - "artifact_id": artifact_id, - "producer_identity": producer, - "model_identity": model, - } - if mutation is None: - lineage = study._selected_report_lineage(report, case, candidate, source) - assert lineage["candidate_path"] == canonical - assert lineage["candidate_artifact_id"] == artifact_id - else: - with pytest.raises(study.StudyError): - study._selected_report_lineage(report, case, candidate, source) - - -@pytest.mark.parametrize( - ("interrupted", "target", "batch", "warmups", "minimum", "samples"), - ( - (True, 0.1, 128, 2, 5, 5), - (False, 0.2, 128, 2, 5, 5), - (False, 0.1, 64, 2, 5, 5), - (False, 0.1, 128, 1, 5, 5), - (False, 0.1, 128, 2, 4, 5), - (False, 0.1, 128, 2, 5, 4), - ), -) -def test_benchmark_rejects_partial_or_wrong_effective_contract( - monkeypatch: pytest.MonkeyPatch, - interrupted: bool, - target: float, - batch: int, - warmups: int, - minimum: int, - samples: int, -) -> None: - result = SimpleNamespace( - interrupted=interrupted, - sample_count=samples, - effective_config=SimpleNamespace( - target_runtime=target, - precision=16, - batch_size=batch, - warmup_runs=warmups, - minimum_samples=minimum, - helicity_ids=(), - color_flow_ids=("flow:1",), - ), - ) - monkeypatch.setattr( - study, - "BenchmarkRunner", - lambda _config: SimpleNamespace(run=lambda *_args, **_kwargs: result), - ) - with pytest.raises(study.StudyError): - study._benchmark( - SimpleNamespace(), - "on-the-fly", - ((((1.0, 0.0, 0.0, 1.0),),)), - "selected", - study.Selector((1,), "flow:1", (-1,), "h:-1"), - 0.1, - ) - - -@pytest.mark.parametrize( - ("field", "value"), - ( - ("precision", 8), - ("helicity_ids", ("h:-1",)), - ("color_flow_ids", ("flow:2",)), - ), -) -def test_benchmark_rejects_wrong_precision_or_selector( - monkeypatch: pytest.MonkeyPatch, field: str, value: object -) -> None: - effective = SimpleNamespace( - target_runtime=0.1, - precision=16, - batch_size=128, - warmup_runs=2, - minimum_samples=5, - helicity_ids=(), - color_flow_ids=("flow:1",), - ) - setattr(effective, field, value) - result = SimpleNamespace( - interrupted=False, - sample_count=5, - effective_config=effective, - ) - monkeypatch.setattr( - study, - "BenchmarkRunner", - lambda _config: SimpleNamespace(run=lambda *_args, **_kwargs: result), - ) - with pytest.raises(study.StudyError, match="effective timing contract"): - study._benchmark( - SimpleNamespace(), - "on-the-fly", - ((((1.0, 0.0, 0.0, 1.0),),)), - "selected", - study.Selector((1,), "flow:1", (-1,), "h:-1"), - 0.1, - ) diff --git a/pyamplicol/tests/unit/test_on_the_fly_lc_gate.py b/pyamplicol/tests/unit/test_on_the_fly_lc_gate.py deleted file mode 100644 index e15fffefb6..0000000000 --- a/pyamplicol/tests/unit/test_on_the_fly_lc_gate.py +++ /dev/null @@ -1,2099 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Gate-level contracts for the developer on-the-fly LC harness.""" - -from __future__ import annotations - -import io -import json -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from pyamplicol.artifacts import ArtifactBuilder, load_manifest -from pyamplicol.generation.evaluator_container import ( - PacbinMemberKind, - PacbinMemberSource, - write_pacbin_atomic, -) -from tools.developer import on_the_fly_lc_gate as gate - - -def _write_execution(root: Path, payload: object) -> None: - process = root / "processes" / gate.PROCESS_ID - process.mkdir(parents=True) - (process / "execution.json").write_text(json.dumps(payload), encoding="utf-8") - - -def _write_on_the_fly_contract_artifact( - root: Path, - *, - execution_field: str | None = None, - extra_seed_member: bool = False, - extra_sidecar: str | None = None, -) -> str: - process_prefix = f"processes/{gate.PROCESS_ID}" - target = {"triple": "portable-64le", "cpu_features": []} - capabilities = list(gate.ON_THE_FLY_CAPABILITIES) - pdgs = (1, -1, 6, -6, 21, 21) - execution: dict[str, object] = { - "schema_version": 3, - "kind": "pyamplicol-runtime-on-the-fly-execution", - "required_runtime_capabilities": capabilities, - "process": gate.PROCESS, - "key": gate.PROCESS_ID, - "color_accuracy": "lc", - "external_pdg_order": list(pdgs), - "kernel_pack": { - "manifest_path": "model/eager-kernel-pack.json", - "payload_root": "model/eager-kernels", - }, - "runtime_options": { - "point_tile_size": 128, - "query_construction_threads": 1, - }, - "selector_policy": { - "color_coverage": "complete", - "reference_color_word": None, - "trace_reflections_folded": False, - "selector_census": { - "physical_helicity_count": 64, - "physical_color_flow_count": 12, - }, - }, - "runtime_metadata": { - "runtime_parameters": [], - "prepared_parameter_defaults": [], - "parameter_projection": [], - "external_legs": [], - "particle_masses": [], - "normalization": {}, - }, - "runtime_container": { - "kind": "pyamplicol-on-the-fly-runtime-container", - "schema_version": 1, - "storage_abi": "pacbin-v1", - "path": "on-the-fly-runtime.pacbin", - "seed_member_path": gate.ON_THE_FLY_SEED_MEMBER_PATH, - }, - } - if execution_field is not None: - execution[execution_field] = {"materialized": True} - - with ArtifactBuilder(root) as builder: - builder.add_bytes( - "config/requested.toml", - b"[evaluator]\nexecution_mode = 'on-the-fly'\n", - role="configuration-requested", - media_type="application/toml", - ) - builder.add_bytes( - "config/effective.toml", - b"[evaluator]\nexecution_mode = 'on-the-fly'\n", - role="configuration-effective", - media_type="application/toml", - ) - builder.add_json( - "model/compiled-model.json", - {"schema_version": 1}, - role="compiled-model", - ) - builder.add_json( - "model/eager-kernel-pack.json", - {"kind": "fixture-prepared-kernel-pack"}, - role="evaluator-manifest", - ) - builder.add_json( - "processes/evaluators.json", - { - "schema_version": 3, - "kind": "pyamplicol-runtime-execution-set", - "required_runtime_capabilities": capabilities, - "processes": [ - { - "process_id": gate.PROCESS_ID, - "manifest_path": f"{gate.PROCESS_ID}/execution.json", - "required_runtime_capabilities": capabilities, - } - ], - }, - role="evaluator-manifest", - ) - builder.add_json( - f"{process_prefix}/execution.json", - execution, - role="evaluator-manifest", - process_id=gate.PROCESS_ID, - compact=True, - ) - builder.add_json( - f"{process_prefix}/physics.json", - { - "schema_version": 1, - "kind": "pyamplicol-on-the-fly-public-metadata", - "process_id": gate.PROCESS_ID, - "process": gate.PROCESS, - "color_accuracy": "lc", - "external_particles": [ - { - "index": index, - "label": index + 1, - "particle": name, - "pdg": pdg, - "role": "initial" if index < 2 else "final", - "momentum_slot": index, - "momentum_components": ["E", "px", "py", "pz"], - } - for index, (name, pdg) in enumerate( - ( - ("d", 1), - ("d~", -1), - ("t", 6), - ("t~", -6), - ("g", 21), - ("g", 21), - ) - ) - ], - "model_parameters": [], - }, - role="runtime-physics", - process_id=gate.PROCESS_ID, - compact=True, - ) - builder.add_json( - f"{process_prefix}/validation-momenta.json", - {"available": False}, - role="validation-momenta", - process_id=gate.PROCESS_ID, - compact=True, - ) - runtime_path = builder.staged_path( - f"{process_prefix}/on-the-fly-runtime.pacbin", - create_parent=True, - ) - members = [ - PacbinMemberSource( - gate.ON_THE_FLY_SEED_MEMBER_PATH, - PacbinMemberKind.ON_THE_FLY_PROCESS_SEED, - io.BytesIO(b"compact-process-seed"), - ) - ] - if extra_seed_member: - members.append( - PacbinMemberSource( - "on-the-fly/materialized-direct-plan-v1.bin", - PacbinMemberKind.ON_THE_FLY_PROCESS_SEED, - io.BytesIO(b"materialized-sidecar"), - ) - ) - write_pacbin_atomic(runtime_path, members) - builder.register_staged_file( - f"{process_prefix}/on-the-fly-runtime.pacbin", - role="evaluator-state", - media_type="application/octet-stream", - executable=False, - target=target, - process_id=gate.PROCESS_ID, - ) - builder.finalize( - kind="pyamplicol-process", - producer={ - "distribution": "pyamplicol", - "version": "0.1.0", - "versions": { - "python_api": 1, - "toml": 1, - "compiled_model": 1, - "process_artifact": 3, - "runtime_physics": 1, - "symbolica_serialization": "fixture", - "c_abi": 1, - }, - "target": target, - }, - model={ - "name": "built-in-sm", - "source_kind": "built-in-sm", - "content_sha256": "1" * 64, - "compiled_schema_version": 1, - }, - configuration={ - "toml_schema_version": 1, - "requested_path": "config/requested.toml", - "effective_path": "config/effective.toml", - "adjustments": [], - }, - processes=[ - { - "id": gate.PROCESS_ID, - "expression": gate.PROCESS, - "color_accuracy": "lc", - "external_pdgs": list(pdgs), - "physics_path": f"{process_prefix}/physics.json", - "required_runtime_capabilities": capabilities, - "aliases": [], - } - ], - default_process_id=gate.PROCESS_ID, - runtime={ - "engine": "rusticol", - "engine_version": "0.1.0", - "evaluator_manifest_path": "processes/evaluators.json", - "api_bundle_path": None, - "required_runtime_capabilities": capabilities, - }, - ) - - if extra_sidecar is not None: - sidecar = root / process_prefix / extra_sidecar - sidecar.parent.mkdir(parents=True, exist_ok=True) - sidecar.write_bytes(b"forbidden materialized sidecar") - return load_manifest(root, verify_payloads=True).artifact_id - - -def _compiled_record( - *, - sources: int, - currents: int, - components: int, - attachments: int, - evaluations: int, - roots: int, -) -> dict[str, object]: - return { - "kind": "pyamplicol-runtime-execution", - "dag_summary": { - "source_count": sources, - "current_count": currents, - "interaction_count": attachments, - "interaction_evaluation_count": evaluations, - "amplitude_root_count": roots, - }, - "runtime_schema": {"current_storage": {"component_count": components}}, - } - - -def _runtime( - mode: str, - *, - flows: tuple[SimpleNamespace, ...] = (), - helicities: tuple[SimpleNamespace, ...] = (), - artifact_id: str = "a" * 64, - process: str = gate.PROCESS, -) -> SimpleNamespace: - return SimpleNamespace( - execution_mode=mode, - artifact_id=artifact_id, - physics=SimpleNamespace( - process_id=gate.PROCESS_ID, - process=process, - color_accuracy="lc", - external_particles=tuple( - SimpleNamespace(pdg_id=pdg) for pdg in gate.EXTERNAL_PDGS - ), - color_flows=flows, - helicities=helicities, - ), - ) - - -def _fixed_authority_physics( - flow: SimpleNamespace, - helicity: SimpleNamespace, - *, - process: str = gate.PROCESS, - color_accuracy: str = "lc", -) -> SimpleNamespace: - return SimpleNamespace( - process_id=gate.PROCESS_ID, - process=process, - color_accuracy=color_accuracy, - external_particles=tuple( - SimpleNamespace(pdg_id=pdg) for pdg in gate.EXTERNAL_PDGS - ), - color_flows=(flow,), - helicities=(helicity,), - ) - - -def _fake_public_phase() -> gate.PublicGatePhase: - resolved = SimpleNamespace( - helicity_ids=(gate.HELICITY_ID,), - color_ids=(gate.FLOW_ID,), - values=(((1.0,),),), - total=lambda: (1.0,), - ) - evaluation = gate.PublicEvaluation(total=(1.0,), resolved=resolved) - correctness = gate.RecurrenceAuthorityCorrectness( - recurrence_selected=evaluation, - recurrence_all_flow=evaluation, - on_the_fly_selected=evaluation, - on_the_fly_all_flow=evaluation, - public_correctness={"public": "green"}, - clear_checks={"clear": "green"}, - ) - candidate = SimpleNamespace( - artifact_id="a" * 64, - execution_mode="on-the-fly", - ) - recurrence_selected = SimpleNamespace( - artifact_id="b" * 64, - execution_mode="recurrence", - ) - recurrence_all = SimpleNamespace( - artifact_id="c" * 64, - execution_mode="recurrence", - ) - timing = {"wall_seconds_per_point": 1.0} - return gate.PublicGatePhase( - runtime=candidate, - selected_recurrence_runtime=recurrence_selected, - all_flow_recurrence_runtime=recurrence_all, - comparator_selectors=(), - points=((((1.0,),),),), - timing_points=((((1.0,),),),), - correctness=correctness, - artifact_contract={"artifact_id": "a" * 64}, - load_seconds=0.01, - public_profiles={ - "selected_flow_helicity_sum": {"status": "profiled"}, - "all_flow_single_helicity": {"status": "profiled"}, - }, - timings={ - lane: { - "selected_flow_helicity_sum": timing, - "all_flow_single_helicity": timing, - } - for lane in ("on_the_fly", "recurrence") - }, - ) - - -def test_real_on_the_fly_candidate_and_private_probe_carrier_are_separate() -> None: - candidate = gate._on_the_fly_config() - assert candidate.color.accuracy == "lc" - assert candidate.color.lc_flow_layout == "topology-replay" - assert candidate.evaluator.execution_mode == "on-the-fly" - assert candidate.evaluator.backend == "jit" - assert candidate.evaluator.jit.optimization_level == 2 - assert candidate.generation.relation_discovery.mode == "off" - assert candidate.generation.validation.enabled is True - assert candidate.generation.validation.post_build_validation is True - - carrier = gate._recurrence_probe_config() - assert carrier.evaluator.execution_mode == "recurrence" - assert carrier.generation.validation.enabled is False - assert carrier.generation.validation.post_build_validation is False - - flow = SimpleNamespace(id=gate.FLOW_ID, word=gate.FLOW_WORD, index=7) - helicity = SimpleNamespace( - id=gate.HELICITY_ID, - values=gate.HELICITY_VALUES, - structural_zero=False, - ) - assert gate._selectors( - SimpleNamespace(color_flows=(flow,), helicities=(helicity,)) - ) == (flow, helicity) - assert gate._query(flow, helicity).flow_index == 7 - - authority = gate._dense_authority( - SimpleNamespace(artifact_id="a" * 64), - SimpleNamespace(artifact_id="b" * 64), - 8, - ) - assert authority["authority_kind"] == "validated_recurrence" - assert authority["authority_execution_mode"] == "recurrence" - assert authority["runtime_api"] == "Runtime.evaluate_resolved" - assert authority["selected_flow_artifact_id"] == "a" * 64 - assert authority["all_flow_artifact_id"] == "b" * 64 - assert authority["certifies"] == ( - "selected_flow_helicity_sum", - "all_flow_single_helicity", - ) - assert gate._sum(((1.0, 2.0), (3.0, 4.0)), 2) == (4.0, 6.0) - assert gate._series((0.0,), (0.0,), "zero")["worst"]["status"] == "ok" - with pytest.raises(gate.GateError, match="disagrees"): - gate._series((1.0e-300,), (0.0,), "no absolute floor") - - -def test_resolved_authority_checks_each_component_not_only_the_total() -> None: - candidate = SimpleNamespace( - helicity_ids=("h:first", "h:second"), - color_ids=("flow:only",), - values=(((2.0,), (0.0,)),), - ) - reference = SimpleNamespace( - helicity_ids=("h:first", "h:second"), - color_ids=("flow:only",), - values=(((1.0,), (1.0,)),), - ) - assert sum(value[0] for value in candidate.values[0]) == sum( - value[0] for value in reference.values[0] - ) - with pytest.raises(gate.GateError, match="disagrees"): - gate._resolved_component_checks(candidate, reference, "canceling components") - - -def test_recurrence_authority_correctness_uses_public_ids_and_clears_in_order() -> None: - events: list[str] = [] - points = tuple((((float(index),),),) for index in range(len(gate.SEEDS))) - - class Resolved: - def __init__( - self, - helicity_ids: tuple[str, ...], - color_ids: tuple[str, ...], - component_rows: tuple[tuple[float, ...], ...], - ) -> None: - self.helicity_ids = helicity_ids - self.color_ids = color_ids - self.values = tuple( - tuple( - tuple( - component_rows[helicity][color] - for color in range(len(color_ids)) - ) - for helicity in range(len(helicity_ids)) - ) - for _point in points - ) - - def total(self) -> tuple[float, ...]: - return tuple( - sum(value for helicity in point for value in helicity) - for point in self.values - ) - - selected_recurrence = Resolved( - ("h:first", "h:second"), (gate.FLOW_ID,), ((1.0,), (2.0,)) - ) - all_flow_recurrence = Resolved( - (gate.HELICITY_ID,), ("flow:first", "flow:second"), ((4.0, 5.0),) - ) - - class Runtime: - def __init__( - self, - label: str, - selected: Resolved, - all_flow: Resolved, - *, - flow_ordinal: int, - ) -> None: - self.label = label - self.selected = selected - self.all_flow = all_flow - self.flow_ordinal = flow_ordinal - - def _resolved(self, selectors: object) -> tuple[str, Resolved]: - if selectors == {"color_flows": (gate.FLOW_ID,)}: - return "selected", self.selected - if selectors == {"helicities": (gate.HELICITY_ID,)}: - return "all-flow", self.all_flow - raise AssertionError( - f"{self.label} received a native ordinal instead of a public ID: " - f"{selectors!r} (ordinal={self.flow_ordinal})" - ) - - def evaluate(self, _points: object, **selectors: object) -> tuple[float, ...]: - workload, resolved = self._resolved(selectors) - events.append(f"{self.label}:{workload}:total") - return resolved.total() - - def evaluate_resolved(self, _points: object, **selectors: object) -> Resolved: - workload, resolved = self._resolved(selectors) - events.append(f"{self.label}:{workload}:resolved") - return resolved - - def clear(self) -> None: - events.append(f"{self.label}:clear") - - recurrence_selected_runtime = Runtime( - "recurrence-selected", - selected_recurrence, - all_flow_recurrence, - flow_ordinal=8, - ) - recurrence_all_flow_runtime = Runtime( - "recurrence-all-flow", - selected_recurrence, - all_flow_recurrence, - flow_ordinal=8, - ) - candidate_runtime = Runtime( - "on-the-fly", - selected_recurrence, - all_flow_recurrence, - flow_ordinal=99, - ) - - result = gate._recurrence_authority_correctness( - candidate_runtime, - recurrence_selected_runtime, - recurrence_all_flow_runtime, - points, - ) - - assert len(points) == 8 - assert events == [ - "recurrence-selected:selected:total", - "recurrence-selected:selected:resolved", - "recurrence-all-flow:all-flow:total", - "recurrence-all-flow:all-flow:resolved", - "on-the-fly:selected:total", - "on-the-fly:selected:resolved", - "on-the-fly:all-flow:total", - "on-the-fly:all-flow:resolved", - "on-the-fly:clear", - "on-the-fly:selected:total", - "on-the-fly:selected:resolved", - "on-the-fly:all-flow:total", - "on-the-fly:all-flow:resolved", - ] - assert ( - result.public_correctness["selected_flow_helicity_sum"]["resolved_authority"][ - "checks" - ] - == 16 - ) - assert ( - result.public_correctness["all_flow_single_helicity"]["resolved_authority"][ - "checks" - ] - == 16 - ) - assert result.clear_checks["selected_resolved"]["checks"] == 16 - assert events.count("on-the-fly:clear") == 1 - - -def test_public_gate_profiles_and_benchmarks_only_after_recurrence_authority( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - events: list[str] = [] - flow = SimpleNamespace(id=gate.FLOW_ID, word=gate.FLOW_WORD, index=0) - helicity = SimpleNamespace( - id=gate.HELICITY_ID, - values=gate.HELICITY_VALUES, - structural_zero=False, - ) - physics = _fixed_authority_physics(flow, helicity) - candidate = SimpleNamespace(execution_mode="on-the-fly", artifact_id="a" * 64) - authorities = { - tmp_path / "recurrence-selected": SimpleNamespace( - execution_mode="recurrence", artifact_id="b" * 64, physics=physics - ), - tmp_path / "recurrence-all": SimpleNamespace( - execution_mode="recurrence", artifact_id="c" * 64, physics=physics - ), - } - artifact = tmp_path / "candidate" - - def load(path: Path, **_kwargs: object) -> object: - return candidate if Path(path) == artifact else authorities[Path(path)] - - def correctness(*_args: object) -> gate.RecurrenceAuthorityCorrectness: - events.append("correctness") - return _fake_public_phase().correctness - - def profile(*_args: object, **_kwargs: object) -> dict[str, object]: - events.append("profile") - return {"status": "profiled"} - - def benchmark(*_args: object, **_kwargs: object) -> dict[str, object]: - events.append("benchmark") - return {"wall_seconds_per_point": 1.0} - - monkeypatch.setattr(gate.Runtime, "load", load) - monkeypatch.setattr(gate, "_on_the_fly_artifact_contract", lambda *_args: {}) - monkeypatch.setattr(gate, "_points", lambda: ((((1.0,),),),)) - monkeypatch.setattr(gate, "_recurrence_authority_correctness", correctness) - monkeypatch.setattr(gate, "_on_the_fly_public_profile", profile) - monkeypatch.setattr(gate, "_benchmark_runtime", benchmark) - - result = gate._run_public_gate_phase( - artifact, - tmp_path / "recurrence-selected", - tmp_path / "recurrence-all", - 0.1, - 1, - ) - - assert result.correctness.public_correctness == {"public": "green"} - assert events == ["correctness", "profile", "profile"] + ["benchmark"] * 4 - - -@pytest.mark.parametrize( - ("defect", "message"), - ( - ("process", "wrong canonical process identity"), - ("color", "not an LC recurrence authority"), - ("pdgs", "wrong external PDG ordering"), - ), -) -def test_public_gate_rejects_wrong_comparator_physics_before_correctness( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - defect: str, - message: str, -) -> None: - flow = SimpleNamespace(id=gate.FLOW_ID, word=gate.FLOW_WORD, index=0) - helicity = SimpleNamespace( - id=gate.HELICITY_ID, - values=gate.HELICITY_VALUES, - structural_zero=False, - ) - physics = _fixed_authority_physics( - flow, - helicity, - process="u u~ > t t~ g g" if defect == "process" else gate.PROCESS, - color_accuracy="full" if defect == "color" else "lc", - ) - if defect == "pdgs": - physics.external_particles = tuple( - SimpleNamespace(pdg_id=pdg) for pdg in (2, -2, 6, -6, 21, 21) - ) - candidate_path = tmp_path / "candidate" - authorities = { - tmp_path / "recurrence-selected": SimpleNamespace( - execution_mode="recurrence", physics=physics - ), - tmp_path / "recurrence-all": SimpleNamespace( - execution_mode="recurrence", physics=physics - ), - } - - def load(path: Path, **_kwargs: object) -> object: - if Path(path) == candidate_path: - return SimpleNamespace(execution_mode="on-the-fly") - return authorities[Path(path)] - - monkeypatch.setattr(gate.Runtime, "load", load) - monkeypatch.setattr(gate, "_on_the_fly_artifact_contract", lambda *_args: {}) - monkeypatch.setattr( - gate, - "_recurrence_authority_correctness", - lambda *_args: (_ for _ in ()).throw( - AssertionError("correctness ran with an invalid authority") - ), - ) - - with pytest.raises(gate.GateError, match=message): - gate._run_public_gate_phase( - candidate_path, - tmp_path / "recurrence-selected", - tmp_path / "recurrence-all", - 0.1, - 1, - ) - - -def test_comparator_physics_accepts_mapping_external_particles() -> None: - flow = SimpleNamespace(id=gate.FLOW_ID, word=gate.FLOW_WORD, index=0) - helicity = SimpleNamespace( - id=gate.HELICITY_ID, - values=gate.HELICITY_VALUES, - structural_zero=False, - ) - physics = _fixed_authority_physics(flow, helicity) - physics.external_particles = tuple({"pdg_id": pdg} for pdg in gate.EXTERNAL_PDGS) - runtime = SimpleNamespace(execution_mode="recurrence", physics=physics) - - assert ( - gate._validate_comparator_physics(runtime, "recurrence", "mapping") is physics - ) - - -@pytest.mark.parametrize( - "particle", ({"pdg_id": "1"}, {"pdg_id": True}, {"pdg": 1}, {}) -) -def test_comparator_physics_rejects_malformed_mapping_pdg( - particle: dict[str, object], -) -> None: - flow = SimpleNamespace(id=gate.FLOW_ID, word=gate.FLOW_WORD, index=0) - helicity = SimpleNamespace( - id=gate.HELICITY_ID, - values=gate.HELICITY_VALUES, - structural_zero=False, - ) - physics = _fixed_authority_physics(flow, helicity) - physics.external_particles = ( - particle, - *({"pdg_id": pdg} for pdg in gate.EXTERNAL_PDGS[1:]), - ) - runtime = SimpleNamespace(execution_mode="recurrence", physics=physics) - - with pytest.raises( - gate.GateError, match="external particle 0 has an invalid PDG ID" - ): - gate._validate_comparator_physics(runtime, "recurrence", "mapping") - - -def test_public_correctness_only_report_skips_every_private_lane( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - candidate = tmp_path / "candidate" - candidate.mkdir() - forbidden = ( - "_generate_candidate_with_prepared_model", - "_generate_probe_carrier", - "_probe", - "_family_probe", - "_hidden_timing", - "_hidden_family_timing", - "_hidden_family_correctness", - "_query_family_census", - ) - - def reject(*_args: object, **_kwargs: object) -> object: - raise AssertionError("provisional public-only mode entered a private lane") - - for symbol in forbidden: - monkeypatch.setattr(gate, symbol, reject) - monkeypatch.setattr( - gate, "_run_public_gate_phase", lambda *_args: _fake_public_phase() - ) - monkeypatch.setattr(gate, "point_digest", lambda *_args: "point-digest") - - result = gate._run_public_correctness_only( - tmp_path, - None, - candidate, - tmp_path / "recurrence-selected", - tmp_path / "recurrence-all", - 0.1, - 1, - ) - - assert result["status"] == "passed" - assert result["correctness_authority_contract"] == "recurrence-only-v1" - assert result["scope"] == "provisional-public-correctness-only" - assert result["provisional"] is True - assert result["public_only"] is True - assert result["full_gate_status"] == "not-run" - assert result["source_bound"] is False - assert result["source_binding"] == "not-asserted" - assert result["candidate_source"] == "reused-existing-artifact" - assert result["private_probe_carrier"]["status"] == "skipped" - assert result["private_census"]["status"] == "unavailable" - assert result["private_timing"]["status"] == "unavailable" - assert set(result["public_timings"]) == { - "selected_flow_helicity_sum", - "all_flow_single_helicity", - } - assert all( - set(workload) == {"on_the_fly", "recurrence"} - for workload in result["public_timings"].values() - ) - outer = gate._driver_report(result, {"passes": True}) - assert outer["source_bound"] is False - assert outer["source_binding"] == "not-asserted" - assert outer["provisional"] is True - - -def test_real_candidate_contract_and_profile_never_open_dense_physics( - tmp_path: Path, -) -> None: - artifact = tmp_path / "artifact" - artifact_id = _write_on_the_fly_contract_artifact(artifact) - - class Backend: - def profile(self, _points: object, **kwargs: object) -> dict[str, object]: - assert kwargs == { - "helicities": None, - "color_flows": (gate.FLOW_ID,), - "precision": 16, - "include_values": True, - } - return { - "execution_mode": "on-the-fly", - "values": [1.0, 2.0], - "wall_time_s": 0.01, - **{ - name: 2 if name.endswith("row_count") else 1 - for name in gate.PUBLIC_PROFILE_WORK_FIELDS - }, - } - - class Candidate: - execution_mode = "on-the-fly" - representative_process_key = gate.PROCESS_ID - _backend = Backend() - - @property - def physics(self) -> object: - raise AssertionError("candidate dense physics was opened") - - candidate = Candidate() - candidate.artifact_id = artifact_id - contract = gate._on_the_fly_artifact_contract(artifact, candidate) - assert contract["execution_mode"] == "on-the-fly" - assert contract["dense_physics_accessed"] is False - assert contract["required_runtime_capabilities"] == gate.ON_THE_FLY_CAPABILITIES - assert contract["selector_census"] == { - "physical_helicity_count": 64, - "physical_color_flow_count": 12, - } - assert contract["process_evaluator_state_payload_count"] == 1 - assert contract["runtime_container_authenticated"] is True - assert contract["runtime_container_member_count"] == 1 - assert contract["seed_member_kind"] == "ON_THE_FLY_PROCESS_SEED" - profile = gate._on_the_fly_public_profile( - candidate, - (((1.0,),), ((2.0,),)), - (1.0, 2.0), - flows=(gate.FLOW_ID,), - ) - assert profile["value_check"]["checks"] == 2 - assert profile["work"]["recurrence_source_call_count"] == 1 - assert profile["work"]["recurrence_source_row_count"] == 2 - - with pytest.raises(gate.GateError, match="disagrees"): - gate._on_the_fly_public_profile( - candidate, - (((1.0,),), ((2.0,),)), - (1.0, 3.0), - flows=(gate.FLOW_ID,), - ) - - -@pytest.mark.parametrize( - "sidecar", - ( - "dag.json", - "color-plan.json", - "eager-runtime.pacbin", - "direct-plan.bin", - "recurrence-runtime.pacbin", - "compiled.so", - "structural-source-proof.json", - ), -) -def test_on_the_fly_contract_rejects_materialized_process_sidecars( - tmp_path: Path, - sidecar: str, -) -> None: - artifact = tmp_path / sidecar.replace(".", "-") - artifact_id = _write_on_the_fly_contract_artifact( - artifact, - extra_sidecar=sidecar, - ) - runtime = SimpleNamespace( - execution_mode="on-the-fly", - representative_process_key=gate.PROCESS_ID, - artifact_id=artifact_id, - ) - with pytest.raises(gate.GateError, match="materialized sidecars"): - gate._on_the_fly_artifact_contract(artifact, runtime) - - -def test_on_the_fly_contract_rejects_extra_pacbin_member(tmp_path: Path) -> None: - artifact = tmp_path / "extra-member" - artifact_id = _write_on_the_fly_contract_artifact( - artifact, - extra_seed_member=True, - ) - runtime = SimpleNamespace( - execution_mode="on-the-fly", - representative_process_key=gate.PROCESS_ID, - artifact_id=artifact_id, - ) - with pytest.raises(gate.GateError, match="exactly one process seed"): - gate._on_the_fly_artifact_contract(artifact, runtime) - - -@pytest.mark.parametrize( - "field", - ( - "dag", - "color_plan", - "eager_plan", - "direct_plan", - "recurrence_runtime", - "compiled_execution", - "structural_proof", - ), -) -def test_on_the_fly_contract_rejects_materialization_fields( - tmp_path: Path, - field: str, -) -> None: - artifact = tmp_path / field - artifact_id = _write_on_the_fly_contract_artifact( - artifact, - execution_field=field, - ) - runtime = SimpleNamespace( - execution_mode="on-the-fly", - representative_process_key=gate.PROCESS_ID, - artifact_id=artifact_id, - ) - with pytest.raises(gate.GateError, match="forbidden materialization field"): - gate._on_the_fly_artifact_contract(artifact, runtime) - - -def test_amplicol_anchor_requires_exact_cell_and_point_digest(tmp_path: Path) -> None: - def write(name: str, cell_id: str) -> Path: - path = tmp_path / name - path.write_text( - json.dumps( - { - "status": "ok", - "matrix_element": 3.0, - "execution_seconds_per_point": 4.0e-6, - "wall_seconds_per_point": 5.0e-6, - "selector_contract": { - "selected_color_flow_ids": [gate.FLOW_ID], - "selected_color_words": [list(gate.FLOW_WORD)], - }, - "validation": { - "lc_common_component": { - "cell_id": cell_id, - "point_digest": "same-point", - "helicity_ids": [gate.HELICITY_ID], - "color_flow_ids": [gate.FLOW_ID], - "value": 2.0, - } - }, - } - ), - encoding="utf-8", - ) - return path - - wrong_cell = gate._anchor(write("wrong-cell.json", "another-cell")) - contextual = gate._anchor_checks( - wrong_cell, - "same-point", - public_component=99.0, - hidden_component=98.0, - public_sum=97.0, - hidden_sum=96.0, - ) - assert contextual["comparison_performed"] is False - assert "cell identity differs" in str(contextual["reason"]) - - exact = gate._anchor(write("exact.json", gate.AMPICOL_CELL_ID)) - different_point = gate._anchor_checks( - exact, - "different-point", - public_component=99.0, - hidden_component=98.0, - public_sum=97.0, - hidden_sum=96.0, - ) - assert different_point["comparison_performed"] is False - assert "point digest differs" in str(different_point["reason"]) - - compared = gate._anchor_checks( - exact, - "same-point", - public_component=2.0, - hidden_component=2.0, - public_sum=3.0, - hidden_sum=3.0, - ) - assert compared["comparison_performed"] is True - assert compared["execution_seconds_per_point"] == 4.0e-6 - assert compared["wall_seconds_per_point"] == 5.0e-6 - assert "independent clocks" in compared["clock_attribution"]["relationship"] - - -def test_hidden_timing_contract_counts_lookup_fill_execute_and_no_poison() -> None: - def report(repetitions: int) -> dict[str, object]: - benchmark = repetitions > 0 - cycles = gate.WARMUPS + repetitions if benchmark else 1 - elapsed = 0.25 if benchmark else None - return { - "process_id": gate.PROCESS_ID, - "point_count": 2, - "work_census_basis": gate.WORK_CENSUS_BASIS, - "logical_current_count": 5, - "resident_current_count": 5, - "resident_current_component_count": 8, - "source_operation_count": 2, - "contribution_operation_count": 3, - "finalization_operation_count": 1, - "closure_operation_count": 1, - "total_kernel_application_count": 7, - "semantic_executor_binding_count": 4, - "distinct_prepared_executor_count": 3, - "trace_build_count": 1, - "trace_cache_hit_count": cycles if benchmark else 0, - "momentum_fill_count": cycles, - "currents": [], - "direct_plan_load_attempts": 0, - "direct_plan_decode_attempts": 0, - "direct_plan_materialization_attempts": 0, - "established_builder_attempts": 0, - "normalized_values": [1.0, 2.0], - "benchmark_elapsed_seconds": elapsed, - "benchmark_seconds_per_point": ( - None if elapsed is None else elapsed / (repetitions * 2) - ), - } - - assert gate._probe_values(report(0), 2) == (1.0, 2.0) - assert gate._probe_values(report(5), 2, 5) == (1.0, 2.0) - assert gate._work_census(report(5)) == { - "work_census_basis": gate.WORK_CENSUS_BASIS, - "logical_current_count": 5, - "resident_current_count": 5, - "resident_current_component_count": 8, - "source_operation_count": 2, - "contribution_operation_count": 3, - "finalization_operation_count": 1, - "closure_operation_count": 1, - "total_kernel_application_count": 7, - "semantic_executor_binding_count": 4, - "distinct_prepared_executor_count": 3, - } - assert gate._calibrate(0.25, 1.0) == 4 - - poisoned = report(0) - poisoned["direct_plan_load_attempts"] = 1 - with pytest.raises(gate.GateError, match="poison"): - gate._probe_values(poisoned, 2) - wrong_fill = report(5) - wrong_fill["momentum_fill_count"] = 6 - with pytest.raises(gate.GateError, match="contract"): - gate._probe_values(wrong_fill, 2, 5) - inconsistent_work = report(0) - inconsistent_work["total_kernel_application_count"] = 8 - with pytest.raises(gate.GateError, match="kernel and operation"): - gate._probe_values(inconsistent_work, 2) - - -def test_workload_census_sums_operations_and_keeps_recurrence_calls_distinct( - monkeypatch: pytest.MonkeyPatch, -) -> None: - first = { - "work_census_basis": gate.WORK_CENSUS_BASIS, - "source_operation_count": 2, - "contribution_operation_count": 3, - "finalization_operation_count": 1, - "closure_operation_count": 1, - "total_kernel_application_count": 7, - } - second = { - "work_census_basis": gate.WORK_CENSUS_BASIS, - "source_operation_count": 2, - "contribution_operation_count": 5, - "finalization_operation_count": 2, - "closure_operation_count": 1, - "total_kernel_application_count": 10, - } - assert gate._workload_operation_census( - ({"work_census": first}, {"work_census": second}) - ) == { - "aggregation_basis": "sum-one-execution-per-serialized-query-v1", - "query_census_basis": gate.WORK_CENSUS_BASIS, - "query_count": 2, - "source_operation_count": 4, - "contribution_operation_count": 8, - "finalization_operation_count": 3, - "closure_operation_count": 2, - "total_kernel_application_count": 17, - } - - counters = SimpleNamespace( - normalization="mean_per_profiled_point_or_runtime_call_v1", - recurrence_source_calls_per_call=2.0, - recurrence_source_rows_per_call=4.0, - recurrence_contribution_calls_per_call=3.0, - recurrence_contribution_rows_per_call=8.0, - recurrence_finalization_calls_per_call=1.0, - recurrence_finalization_rows_per_call=3.0, - recurrence_closure_calls_per_call=1.0, - recurrence_closure_rows_per_call=2.0, - ) - established = gate._public_recurrence_work( - SimpleNamespace(timing_breakdown=SimpleNamespace(counters=counters)) - ) - assert established is not None - assert established["source_calls_per_runtime_call"] == 2.0 - assert established["source_rows_per_runtime_call"] == 4.0 - assert "grouped prepared-backend invocations" in str(established["semantics"]) - assert gate._public_recurrence_work(SimpleNamespace(timing_breakdown=None)) is None - - monkeypatch.setattr(gate.dataclasses, "asdict", lambda _value: {}) - public = gate._public_timing( - SimpleNamespace( - sample_count=3, - repetitions_per_sample=4, - wall_time_per_point=2.0, - evaluator_time_per_point=1.5, - evaluator_total_time_per_point=1.75, - interrupted=False, - effective_config=SimpleNamespace(), - uncertainty=SimpleNamespace(), - timing_breakdown=SimpleNamespace( - counters=counters, execution_mode="recurrence" - ), - ), - "recurrence", - ) - assert public["execution_mode"] == "recurrence" - assert public["evaluator_seconds_per_point"] == 1.5 - assert public["clock_attribution"]["evaluator_seconds_per_point"] == ( - "recurrence core" - ) - assert "clocks are independent" in public["clock_attribution"]["relationship"] - with pytest.raises(gate.GateError, match="matching timing breakdown"): - gate._public_timing( - SimpleNamespace( - timing_breakdown=SimpleNamespace(execution_mode="compiled") - ), - "on-the-fly", - ) - - -def test_query_family_census_matches_query_local_work_and_retains_destinations() -> ( - None -): - observed: dict[str, object] = {} - - def probe(*args: object, **kwargs: object) -> dict[str, int]: - observed["args"] = args - observed["kwargs"] = kwargs - return { - "query_count": 2, - "source_frame_partition_count": 1, - "projection_applied_query_count": 2, - "projection_pre_current_count": 12, - "projection_pre_contribution_count": 10, - "projection_pre_closure_count": 2, - "projection_post_current_count": 10, - "projection_post_contribution_count": 8, - "projection_post_closure_count": 2, - "dynamic_current_occurrence_count": 10, - "dynamic_current_component_occurrence_count": 16, - "dynamic_source_rows": 4, - "dynamic_contribution_rows": 8, - "dynamic_finalization_rows": 3, - "dynamic_closure_rows": 2, - "dynamic_source_calls": 4, - "dynamic_contribution_calls": 8, - "dynamic_finalization_calls": 3, - "dynamic_closure_calls": 2, - "union_unique_current_count": 6, - "union_unique_current_component_count": 10, - "union_source_rows": 2, - "union_contribution_rows": 5, - "union_finalization_rows": 2, - "union_closure_rows": 2, - "union_amplitude_destination_count": 2, - "union_source_executor_call_groups": 2, - "union_contribution_executor_call_groups": 3, - "union_finalization_executor_call_groups": 1, - "union_closure_executor_call_groups": 1, - } - - retained = gate.RetainedInputs("builder", "template", b"{}", "a" * 64) - queries = ( - gate.Query("flow:0", 0, "h:0", (1, -1)), - gate.Query("flow:1", 1, "h:1", (-1, 1)), - ) - hidden = { - "queries": [ - { - "work_census": { - "logical_current_count": 5, - "resident_current_component_count": 8, - } - }, - { - "work_census": { - "logical_current_count": 5, - "resident_current_component_count": 8, - } - }, - ], - "workload_operation_census": { - "source_operation_count": 4, - "contribution_operation_count": 8, - "finalization_operation_count": 3, - "closure_operation_count": 2, - }, - } - result = gate._query_family_census(probe, retained, queries, hidden, True) - assert result["basis"] == "exact-current-core-key-query-family-union-v1" - assert result["union_unique_current_count"] == 6 - assert result["union_amplitude_destination_count"] == 2 - assert observed["args"][4] == [0, 1] - assert observed["args"][5] == [[1, -1], [-1, 1]] - assert observed["kwargs"] == {"enable_color_projection": True} - - def stale(*_args: object, **_kwargs: object) -> dict[str, int]: - value = probe(*_args, **_kwargs) - value["dynamic_contribution_rows"] = 7 - return value - - with pytest.raises(gate.GateError, match="independently timed"): - gate._query_family_census(stale, retained, queries, hidden, True) - - -def test_executable_family_report_has_exact_union_work_and_ordered_outputs() -> None: - queries = ( - gate.Query("flow:0", 0, "h:0", (1, -1)), - gate.Query("flow:1", 1, "h:1", (-1, 1)), - ) - census = { - "query_count": 2, - "source_frame_partition_count": 1, - "projection_applied_query_count": 2, - "projection_pre_current_count": 12, - "projection_pre_contribution_count": 10, - "projection_pre_closure_count": 2, - "projection_post_current_count": 10, - "projection_post_contribution_count": 8, - "projection_post_closure_count": 2, - "dynamic_current_occurrence_count": 10, - "dynamic_current_component_occurrence_count": 16, - "dynamic_source_rows": 4, - "dynamic_contribution_rows": 8, - "dynamic_finalization_rows": 3, - "dynamic_closure_rows": 2, - "dynamic_source_calls": 4, - "dynamic_contribution_calls": 8, - "dynamic_finalization_calls": 3, - "dynamic_closure_calls": 2, - "union_unique_current_count": 6, - "union_unique_current_component_count": 10, - "union_source_rows": 2, - "union_contribution_rows": 5, - "union_finalization_rows": 2, - "union_closure_rows": 2, - "union_amplitude_destination_count": 2, - "union_source_executor_call_groups": 1, - "union_contribution_executor_call_groups": 3, - "union_finalization_executor_call_groups": 1, - "union_closure_executor_call_groups": 1, - } - rows = [ - { - "selected_public_flow_id": query.flow_index, - "public_helicities": list(query.helicities), - "query_digest": str(index) * 64, - "raw_amplitudes": [[1.0 + index, 2.0], [3.0, 4.0 + index]], - "normalized_values": [5.0 + index, 6.0 + index], - } - for index, query in enumerate(queries, start=1) - ] - report = { - "process_id": gate.PROCESS_ID, - "point_count": 2, - "work_census_basis": gate.FAMILY_WORK_CENSUS_BASIS, - "source_operation_count": 2, - "contribution_operation_count": 5, - "finalization_operation_count": 2, - "closure_operation_count": 2, - "total_kernel_application_count": 11, - "trace_build_count": 2, - "trace_cache_hit_count": 0, - "momentum_fill_count": gate.WARMUPS + 3, - "currents": [], - "direct_plan_load_attempts": 0, - "direct_plan_decode_attempts": 0, - "direct_plan_materialization_attempts": 0, - "established_builder_attempts": 0, - "query_family": { - "queries": rows, - "census": census, - "execution_cache_hit": True, - "execution_source_calls": 1, - "execution_source_rows": 2, - "execution_contribution_calls": 3, - "execution_contribution_rows": 5, - "execution_finalization_calls": 1, - "execution_finalization_rows": 2, - "execution_closure_calls": 1, - "execution_closure_rows": 2, - "cold_prepare_seconds": 0.01, - "private_warmed_elapsed_seconds": 0.12, - "private_warmed_seconds_per_point": 0.02, - "private_timing_excludes_source_crossing": True, - }, - } - parsed = gate._family_probe_result(report, queries, 2, 3) - assert parsed["union_total_kernel_application_count"] == 11 - assert parsed["census"] == census - gate._assert_executable_family_matches_structural_census(census, census) - - broken = dict(report) - broken["total_kernel_application_count"] = 16 - with pytest.raises(gate.GateError, match="top-level execution census"): - gate._family_probe_result(broken, queries, 2, 3) - - -def test_separate_recurrence_artifacts_route_exact_selector_certificates( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - selected = tmp_path / "recurrence-selected" - all_flow = tmp_path / "recurrence-all-flow" - whole = { - "source_row_count": 2, - "current_count": 7, - "semantic_component_count": 11, - "contribution_count": 5, - "finalization_count": 3, - "closure_count": 2, - "row_count": 12, - } - - def recurrence(layout: str, representatives: list[object]) -> dict[str, object]: - return { - "kind": "pyamplicol-runtime-recurrence-execution", - "recurrence_summary": { - "current_count": 7, - "contribution_count": 5, - "closure_term_count": 2, - }, - "runtime_metadata": { - "public_color_flows": [ - {"public_id": gate.FLOW_ID, "target_sector_id": 8} - ] - }, - "plan": { - "inspection_summary": { - "lc_flow_layout": layout, - "schedule": { - "source_row_count": 2, - "current_count": 7, - "contribution_count": 5, - "finalization_count": 3, - "closure_term_count": 2, - "amplitude_destination_count": 1, - }, - "direct_arena": {"semantic_component_count": 11}, - "selector_work_certificate": { - "persisted_union": whole, - "representatives": representatives, - }, - } - }, - } - - live = { - "representative_sector_id": 8, - "source_row_count": 1, - "current_count": 4, - "semantic_component_count": 6, - "contribution_count": 2, - "finalization_count": 1, - "closure_count": 1, - "amplitude_destination_count": 1, - "row_count": 5, - } - _write_execution(selected, recurrence("topology-replay", [live])) - _write_execution(all_flow, recurrence("all-flow-union", [])) - flow = SimpleNamespace(id=gate.FLOW_ID, index=8) - helicity = SimpleNamespace(id=gate.HELICITY_ID, index=21) - runtimes = { - selected.resolve(): _runtime("recurrence", flows=(flow,)), - all_flow.resolve(): _runtime("recurrence", helicities=(helicity,)), - } - loads: list[Path] = [] - - def load(path: Path) -> SimpleNamespace: - loads.append(path) - return runtimes[path] - - monkeypatch.setattr(gate.Runtime, "load", load) - selected_result = gate._recurrence_artifact_census( - selected, layout="topology-replay" - ) - all_result = gate._recurrence_artifact_census(all_flow, layout="all-flow-union") - - assert loads == [selected.resolve(), all_flow.resolve()] - assert selected_result["selector_live"]["current_count"] == 4 - assert selected_result["selector_live"]["kernel_row_count"] == 5 - assert selected_result["whole"]["current_count"] == 7 - assert all_result["whole"] == all_result["selector_live"] - assert all_result["selector"]["public_index"] == 21 - - runtimes[selected.resolve()] = _runtime( - "recurrence", flows=(flow,), process="g g > g g g g" - ) - with pytest.raises(gate.GateError, match="wrong canonical process identity"): - gate._recurrence_artifact_census(selected, layout="topology-replay") - - -def test_compiled_census_selects_one_exact_child_without_summing_alternatives( - tmp_path: Path, monkeypatch: pytest.MonkeyPatch -) -> None: - selected = tmp_path / "compiled-selected" - all_flow = tmp_path / "compiled-all-flow" - primary = _compiled_record( - sources=8, - currents=69, - components=258, - attachments=124, - evaluations=112, - roots=12, - ) - program = _compiled_record( - sources=12, - currents=256, - components=984, - attachments=700, - evaluations=650, - roots=192, - ) - chosen_leaf = _compiled_record( - sources=12, - currents=78, - components=296, - attachments=150, - evaluations=150, - roots=32, - ) - alternative = _compiled_record( - sources=99, - currents=999, - components=1999, - attachments=999, - evaluations=999, - roots=999, - ) - program.update( - { - "physics_reduction": {"groups": [{"physical_color_ids": [gate.FLOW_ID]}]}, - "color_selector_executions": [ - {"materialized_sector_id": 8, "execution": chosen_leaf}, - {"materialized_sector_id": 3, "execution": alternative}, - ], - } - ) - selected_payload = dict(primary) - selected_payload.update( - { - "compiled": { - "lc_topology_replay": { - "groups": [ - {"active_sector_ids": [8, 11], "materialized_sector_id": 8}, - {"active_sector_ids": [3], "materialized_sector_id": 3}, - ] - } - }, - "helicity_sum_execution": program, - } - ) - _write_execution(selected, selected_payload) - - all_primary = _compiled_record( - sources=8, - currents=115, - components=440, - attachments=233, - evaluations=189, - roots=24, - ) - middle = dict(all_primary) - middle["helicity_selector_executions"] = [ - {"selector_domain_ids": [21], "execution": dict(all_primary)}, - {"selector_domain_ids": [5], "execution": alternative}, - ] - all_payload = dict(all_primary) - all_payload["helicity_selector_executions"] = [ - {"selector_domain_ids": [21, 22], "execution": middle}, - {"selector_domain_ids": [4], "execution": alternative}, - ] - _write_execution(all_flow, all_payload) - - flow = SimpleNamespace(id=gate.FLOW_ID, index=8) - helicity = SimpleNamespace(id=gate.HELICITY_ID, index=21) - runtimes = { - selected.resolve(): _runtime("compiled", flows=(flow,)), - all_flow.resolve(): _runtime("compiled", helicities=(helicity,)), - } - loads: list[Path] = [] - - def load(path: Path) -> SimpleNamespace: - loads.append(path) - return runtimes[path] - - monkeypatch.setattr(gate.Runtime, "load", load) - selected_result = gate._compiled_artifact_census( - selected, workload="selected_flow_helicity_sum" - ) - all_result = gate._compiled_artifact_census( - all_flow, workload="all_flow_single_helicity" - ) - - assert loads == [selected.resolve(), all_flow.resolve()] - assert selected_result["levels"]["primary"]["current_count"] == 69 - assert selected_result["levels"]["program"]["current_count"] == 256 - assert selected_result["levels"]["executed_leaf"]["current_count"] == 78 - assert selected_result["levels"]["executed_leaf"]["current_component_count"] == 296 - assert all_result["levels"]["primary"]["current_count"] == 115 - assert all_result["levels"]["executed_leaf"]["current_count"] == 115 - assert all_result["selector"]["selector_depth"] == 2 - assert "never summed" in selected_result["semantics"] - assert "999" not in json.dumps(selected_result) - - program["color_selector_executions"].append( - {"materialized_sector_id": 8, "execution": alternative} - ) - execution_path = selected / "processes" / gate.PROCESS_ID / "execution.json" - execution_path.write_text(json.dumps(selected_payload), encoding="utf-8") - with pytest.raises(gate.GateError, match="absent or ambiguous"): - gate._compiled_artifact_census(selected, workload="selected_flow_helicity_sum") - - with pytest.raises(gate.GateError, match="absent or ambiguous"): - gate._exact_public_index((), gate.FLOW_ID, "test") - with pytest.raises(gate.GateError, match="absent or ambiguous"): - gate._exact_public_index((flow, flow), gate.FLOW_ID, "test") - - -def test_hidden_timing_serializes_one_query_census_and_workload_sum() -> None: - def probe(*args: object, **kwargs: object) -> dict[str, object]: - point_count = int(args[9]) - repetitions = int(kwargs["benchmark_repetitions"]) - cycles = gate.WARMUPS + repetitions - elapsed = repetitions * point_count * 0.01 - return { - "process_id": gate.PROCESS_ID, - "point_count": point_count, - "work_census_basis": gate.WORK_CENSUS_BASIS, - "logical_current_count": 5, - "resident_current_count": 5, - "resident_current_component_count": 8, - "source_operation_count": 2, - "contribution_operation_count": 3, - "finalization_operation_count": 1, - "closure_operation_count": 1, - "total_kernel_application_count": 7, - "semantic_executor_binding_count": 4, - "distinct_prepared_executor_count": 3, - "trace_build_count": 1, - "trace_cache_hit_count": cycles, - "momentum_fill_count": cycles, - "currents": [], - "direct_plan_load_attempts": 0, - "direct_plan_decode_attempts": 0, - "direct_plan_materialization_attempts": 0, - "established_builder_attempts": 0, - "normalized_values": [1.0] * point_count, - "benchmark_elapsed_seconds": elapsed, - "benchmark_seconds_per_point": 0.01, - "trace_digest": "a" * 64, - } - - retained = gate.RetainedInputs(object(), object(), b"{}", "a" * 64) - query = gate.Query("flow", 0, "helicity", (1, -1)) - result = gate._hidden_timing( - probe, - Path("artifact"), - retained, - (query,), - (((1.0,),), ((2.0,),)), - target=0.04, - ) - row = result["queries"][0] - assert row["work_census"]["logical_current_count"] == 5 - assert result["workload_operation_census"] == { - "aggregation_basis": "sum-one-execution-per-serialized-query-v1", - "query_census_basis": gate.WORK_CENSUS_BASIS, - "query_count": 1, - "source_operation_count": 2, - "contribution_operation_count": 3, - "finalization_operation_count": 1, - "closure_operation_count": 1, - "total_kernel_application_count": 7, - } - - -def test_cli_launches_one_worker_with_cross_platform_30_gib_guard( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - prepared_model = tmp_path / "built-in-sm.pyamplicol-model" - prepared_model.write_bytes(b"prepared") - arguments = gate._parser().parse_args( - [ - "--output", - "out", - "--prepared-model", - str(prepared_model), - "--amplicol-result", - "legacy.json", - "--recurrence-selected-artifact", - "recurrence-selected", - "--recurrence-all-flow-artifact", - "recurrence-all-flow", - "--target-runtime", - "2", - "--batch-size", - "64", - ] - ) - assert "--worker" not in gate._parser().format_help() - assert "--compiled-selected-artifact" not in gate._parser().format_help() - assert "--compiled-all-flow-artifact" not in gate._parser().format_help() - command = gate._worker_command(arguments, Path("/tmp/gate")) - assert command.count("--worker") == 1 - assert "all-flow-union" not in command - assert command[command.index("--prepared-model") + 1] == str( - prepared_model.resolve() - ) - assert command[command.index("--amplicol-result") + 1] == str( - Path("legacy.json").resolve() - ) - for option, name in ( - ("--recurrence-selected-artifact", "recurrence-selected"), - ("--recurrence-all-flow-artifact", "recurrence-all-flow"), - ): - assert command[command.index(option) + 1] == str(Path(name).resolve()) - assert arguments.bypass_color_projection is False - assert "--bypass-color-projection" not in command - bypass = arguments - bypass.bypass_color_projection = True - assert "--bypass-color-projection" in gate._worker_command( - bypass, Path("/tmp/gate") - ) - assert gate.WATCHDOG_BYTES == 30 * gate.GIB - - summary = gate._watchdog_summary( - { - "passes": True, - "execution": {"outcome": "command-finished", "reason": None}, - "enforcement": { - "limit_bytes": gate.WATCHDOG_BYTES, - "peak_rss_bytes": 10, - "peak_physical_footprint_bytes": 11, - "peak_guard_bytes": 11, - "peak_processes": 2, - }, - } - ) - assert summary["passes"] is True - assert summary["peak_guard_bytes"] == 11 - - def probe(_pids: object) -> dict[int, int]: - return {} - - monkeypatch.setattr(gate.platform, "system", lambda: "Darwin") - monkeypatch.setattr(gate, "DarwinPhysicalFootprintProbe", lambda: probe) - assert gate._physical_footprint_probe() is probe - monkeypatch.setattr(gate.platform, "system", lambda: "Linux") - assert gate._physical_footprint_probe() is None - - -def test_public_correctness_only_cli_reuses_candidate_in_same_guarded_worker( - tmp_path: Path, -) -> None: - candidate = tmp_path / "candidate" - candidate.mkdir() - arguments = gate._parser().parse_args( - [ - "--output", - "out", - "--candidate-artifact", - str(candidate), - "--public-correctness-only", - "--recurrence-selected-artifact", - "recurrence-selected", - "--recurrence-all-flow-artifact", - "recurrence-all-flow", - ] - ) - - command = gate._worker_command(arguments, tmp_path / "guarded-output") - assert command.count("--worker") == 1 - assert command.count("--public-correctness-only") == 1 - assert command[command.index("--candidate-artifact") + 1] == str( - candidate.resolve() - ) - assert "--prepared-model" not in command - assert gate.WATCHDOG_BYTES == 30 * gate.GIB - - arguments.public_correctness_only = False - with pytest.raises(gate.GateError, match="full gate requires"): - gate._worker_command(arguments, tmp_path / "rejected") - - -def test_default_worker_dispatches_full_lane( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "output" - output.mkdir() - prepared = tmp_path / "model.pyamplicol-model" - prepared.write_bytes(b"prepared") - arguments = gate._parser().parse_args( - [ - "--worker", - "--output", - str(output), - "--prepared-model", - str(prepared), - "--recurrence-selected-artifact", - "recurrence-selected", - "--recurrence-all-flow-artifact", - "recurrence-all-flow", - ] - ) - events: list[str] = [] - - def full(*_args: object, **_kwargs: object) -> dict[str, object]: - events.append("full-private-lane") - return {"kind": "pyamplicol-on-the-fly-lc-gate", "status": "passed"} - - monkeypatch.setattr(gate, "_run", full) - monkeypatch.setattr( - gate, - "_run_public_correctness_only", - lambda *_args: (_ for _ in ()).throw( - AssertionError("default worker dispatched provisional lane") - ), - ) - - assert gate._worker_main(arguments) == 0 - assert events == ["full-private-lane"] - assert json.loads((output / "worker.json").read_text())["status"] == "passed" - - -def test_public_only_worker_mismatch_cannot_report_success( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "output" - output.mkdir() - candidate = tmp_path / "candidate" - candidate.mkdir() - arguments = gate._parser().parse_args( - [ - "--worker", - "--output", - str(output), - "--candidate-artifact", - str(candidate), - "--public-correctness-only", - "--recurrence-selected-artifact", - "recurrence-selected", - "--recurrence-all-flow-artifact", - "recurrence-all-flow", - ] - ) - - monkeypatch.setattr( - gate, - "_run_public_gate_phase", - lambda *_args: (_ for _ in ()).throw(gate.GateError("public disagrees")), - ) - monkeypatch.setattr( - gate, - "_on_the_fly_public_profile", - lambda *_args: (_ for _ in ()).throw( - AssertionError("profile ran after public mismatch") - ), - ) - monkeypatch.setattr( - gate, - "_benchmark_runtime", - lambda *_args: (_ for _ in ()).throw( - AssertionError("benchmark ran after public mismatch") - ), - ) - - assert gate._worker_main(arguments) == 1 - worker = json.loads((output / "worker.json").read_text()) - assert worker["status"] == "failed" - assert worker["scope"] == "provisional-public-correctness-only" - assert "disagrees" in worker["error"] - - -def test_prepared_model_load_precedes_candidate_generation_without_carrier( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - path = tmp_path / "built-in-sm.pyamplicol-model" - path.write_bytes(b"prepared") - events: list[object] = [] - compiled = object() - - class Source: - def compile(self) -> object: - events.append("load") - return compiled - - def from_path(candidate: Path) -> Source: - events.append(("path", candidate)) - return Source() - - def generate_candidate( - artifact: Path, model: object - ) -> tuple[float, dict[str, int]]: - events.append(("generate-candidate", artifact, model)) - return 2.5, { - "expanded_process_count": 1, - "on_the_fly_seed_batch_binding_call_count": 1, - "on_the_fly_seed_build_count": 1, - "recurrence_lowering_call_count": 0, - "materialized_process_lane_count": 0, - } - - monkeypatch.setattr(gate.ModelSource, "from_path", from_path) - monkeypatch.setattr(gate, "_generate_on_the_fly", generate_candidate) - monkeypatch.setattr( - gate, - "_generate_probe_carrier", - lambda *_args: (_ for _ in ()).throw( - AssertionError("candidate generation created a private carrier") - ), - ) - - result = gate._generate_candidate_with_prepared_model(tmp_path / "artifact", path) - - assert events == [ - ("path", path.resolve()), - "load", - ("generate-candidate", tmp_path / "artifact", compiled), - ] - assert result[0] == 2.5 - assert result[1]["on_the_fly_seed_batch_binding_call_count"] == 1 - assert result[1]["on_the_fly_seed_build_count"] == 1 - assert result[2:4] == (compiled, path.resolve()) - assert result[4] >= 0.0 - - -def test_candidate_generation_uses_seed_binding_and_never_recurrence_lowering( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - seen_modes: list[str] = [] - seed_inputs: list[tuple[object, ...]] = [] - - def seed_builder(*args: object, **_kwargs: object) -> tuple[bytes, ...]: - seed_inputs.append(args) - return (b"seed",) - - class Generator: - def __init__(self, config: object) -> None: - seen_modes.append(config.evaluator.execution_mode) - - def generate(self, *_args: object, **_kwargs: object) -> None: - gate.generation_service._invoke_rust_on_the_fly_seed_batch_builder_v1( - (b'{"schema_version":1}',), - b"templates", - b"direct", - "a" * 64, - ) - - monkeypatch.setattr( - gate.generation_service, - "_invoke_rust_on_the_fly_seed_batch_builder_v1", - seed_builder, - ) - monkeypatch.setattr(gate, "Generator", Generator) - elapsed, census = gate._generate_on_the_fly(tmp_path / "artifact", object()) - assert elapsed >= 0.0 - assert seen_modes == ["on-the-fly"] - assert len(seed_inputs) == 1 - assert census == { - "expanded_process_count": 1, - "on_the_fly_seed_batch_binding_call_count": 1, - "on_the_fly_seed_build_count": 1, - "recurrence_lowering_call_count": 0, - "materialized_process_lane_count": 0, - } - - -@pytest.mark.parametrize("symbol", gate.MATERIALIZED_PROCESS_LANE_SYMBOLS) -def test_candidate_generation_fails_fast_for_every_materialized_lane_symbol( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - symbol: str, -) -> None: - seen_modes: list[str] = [] - - class Generator: - def __init__(self, config: object) -> None: - seen_modes.append(config.evaluator.execution_mode) - - def generate(self, *_args: object, **_kwargs: object) -> None: - if symbol == "GenerationBackend._prepare_process_construction": - gate.generation_service.GenerationBackend._prepare_process_construction( - object() - ) - else: - getattr(gate.generation_service, symbol)() - raise AssertionError("materialized lane poison returned to Generator") - - monkeypatch.setattr(gate, "Generator", Generator) - with pytest.raises(gate.GateError, match="materialized process lane"): - gate._generate_on_the_fly(tmp_path / symbol.replace(".", "-"), object()) - assert seen_modes == ["on-the-fly"] - - -def test_candidate_generation_rejects_materialized_source_projection_field( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - native_binding_called = False - - def seed_builder(*_args: object, **_kwargs: object) -> tuple[bytes, ...]: - nonlocal native_binding_called - native_binding_called = True - return (b"seed",) - - class Generator: - def __init__(self, _config: object) -> None: - pass - - def generate(self, *_args: object, **_kwargs: object) -> None: - gate.generation_service._invoke_rust_on_the_fly_seed_batch_builder_v1( - (b'{"schema_version":1,"dag":{}}',), - b"templates", - b"direct", - "a" * 64, - ) - - monkeypatch.setattr( - gate.generation_service, - "_invoke_rust_on_the_fly_seed_batch_builder_v1", - seed_builder, - ) - monkeypatch.setattr(gate, "Generator", Generator) - with pytest.raises(gate.GateError, match="forbidden materialization field"): - gate._generate_on_the_fly(tmp_path / "source-projection", object()) - assert native_binding_called is False - - -def test_public_candidate_mismatch_fails_before_any_timing_or_private_probe( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "output" - output.mkdir() - selected = tmp_path / "selected" - all_flow = tmp_path / "all-flow" - flow = SimpleNamespace(id=gate.FLOW_ID, word=gate.FLOW_WORD, index=0) - helicity = SimpleNamespace( - id=gate.HELICITY_ID, - values=gate.HELICITY_VALUES, - index=0, - structural_zero=False, - ) - physics = _fixed_authority_physics(flow, helicity) - - class Resolved: - helicity_ids = (gate.HELICITY_ID,) - color_ids = (gate.FLOW_ID,) - values = (((1.0,),),) - - @staticmethod - def total() -> tuple[float, ...]: - return (1.0,) - - class Authority: - artifact_id = "b" * 64 - - def __init__(self, execution_mode: str) -> None: - self.execution_mode = execution_mode - - @staticmethod - def evaluate_resolved(*_args: object, **_kwargs: object) -> Resolved: - return Resolved() - - @staticmethod - def evaluate(*_args: object, **_kwargs: object) -> tuple[float, ...]: - return (1.0,) - - class Candidate: - execution_mode = "on-the-fly" - artifact_id = "a" * 64 - representative_process_key = gate.PROCESS_ID - - @property - def physics(self) -> object: - raise AssertionError("candidate dense physics was opened") - - @staticmethod - def evaluate(*_args: object, **_kwargs: object) -> tuple[float, ...]: - return (2.0,) - - @staticmethod - def evaluate_resolved(*_args: object, **_kwargs: object) -> Resolved: - return Resolved() - - candidate = Candidate() - recurrence_authority = Authority("recurrence") - recurrence_authority.physics = physics - monkeypatch.setattr( - gate, - "_generate_candidate_with_prepared_model", - lambda *_args: ( - 0.1, - { - "expanded_process_count": 1, - "on_the_fly_seed_batch_binding_call_count": 1, - "on_the_fly_seed_build_count": 1, - "recurrence_lowering_call_count": 0, - "materialized_process_lane_count": 0, - }, - object(), - tmp_path / "model.pyamplicol-model", - 0.01, - ), - ) - monkeypatch.setattr(gate, "_on_the_fly_artifact_contract", lambda *_args: {}) - monkeypatch.setattr(gate, "_points", lambda: ((((1.0,),),))) - - def load(path: Path, **_kwargs: object) -> object: - path = Path(path) - if path == output / "artifact": - return candidate - if path in (selected, all_flow): - return recurrence_authority - raise AssertionError(f"unexpected load before mismatch: {path}") - - monkeypatch.setattr(gate.Runtime, "load", load) - - def forbidden_timing(*_args: object, **_kwargs: object) -> object: - raise AssertionError("timing ran before recurrence-authority correctness") - - for symbol in ( - "_on_the_fly_public_profile", - "_hidden_timing", - "_hidden_family_timing", - "_benchmark_runtime", - ): - monkeypatch.setattr(gate, symbol, forbidden_timing) - monkeypatch.setattr( - gate, - "_generate_probe_carrier", - lambda *_args: (_ for _ in ()).throw( - AssertionError("private carrier ran before public authority check") - ), - ) - with pytest.raises(gate.GateError, match="disagrees"): - gate._run( - output, - tmp_path / "model.pyamplicol-model", - None, - selected, - all_flow, - 0.1, - 1, - ) - - -def test_prepared_model_path_rejects_missing_non_file_and_wrong_suffix( - tmp_path: Path, -) -> None: - with pytest.raises(gate.GateError, match="does not exist"): - gate._prepared_model_path(tmp_path / "missing.pyamplicol-model") - - directory = tmp_path / "directory.pyamplicol-model" - directory.mkdir() - with pytest.raises(gate.GateError, match="not a regular file"): - gate._prepared_model_path(directory) - - wrong_suffix = tmp_path / "prepared.bin" - wrong_suffix.write_bytes(b"prepared") - with pytest.raises(gate.GateError, match="must end"): - gate._prepared_model_path(wrong_suffix) diff --git a/pyamplicol/tests/unit/test_on_the_fly_performance_campaign.py b/pyamplicol/tests/unit/test_on_the_fly_performance_campaign.py deleted file mode 100644 index 9f6b820b64..0000000000 --- a/pyamplicol/tests/unit/test_on_the_fly_performance_campaign.py +++ /dev/null @@ -1,645 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from collections import Counter -from dataclasses import dataclass -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from pyamplicol.config import BenchmarkConfig -from tools.performance_report.agreements import ( - LC_CROSS_LAYOUT_COMPONENT, - incoming_agreement_edges, -) -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.cache import build_reset_caches -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.manual_campaign import reproduction_recipe -from tools.performance_report.models import Accuracy, ExecutionMode, Workload -from tools.performance_report.render import _BEST_MODE_CODES, render_all_matrix_tables -from tools.performance_report.runner import ( - CONVENTIONAL_WARMUP_TIMING_SCOPE, - LOADED_RUNTIME_PROFILE_COMMAND_PATH, - OTF_ACTIVE_FAMILY_COUNT_FIELDS, - OTF_COLD_WARMUP_RUNTIME_FRESHNESS, - OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE, - OTF_COLD_WARMUP_TIMING_SCOPE, - OTF_RUNTIME_STATE_CENSUS_KIND, - OTF_RUNTIME_STATE_COUNT_FIELDS, - OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS, - OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS, - PUBLIC_CLI_COMMAND_PATH, - WARMUP_TIMER_SOURCE, - RunnerError, - RunnerSettings, - SelectorContract, - _benchmark_measurement, - config_values, - point_digest, - profile_runtime, - validate_artifact_contract, - validate_runtime_contract, -) -from tools.performance_report.scheduler import CampaignSettings, plan_campaign - - -def _otf_warmup_runtime_state(*, retained: bool) -> dict[str, object]: - counts = {field: 0 for field in OTF_RUNTIME_STATE_COUNT_FIELDS} - active: dict[str, object] | None = None - if retained: - counts.update( - { - field: 1 - for field in ( - *OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS, - *OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS, - ) - } - ) - active = { - "basis": "shared-query-family-union-v1", - "scope": "active-family-union", - **{field: 1 for field in OTF_ACTIVE_FAMILY_COUNT_FIELDS}, - } - return { - "kind": OTF_RUNTIME_STATE_CENSUS_KIND, - "process_id": "otf_campaign_process", - "family_cache_policy": OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - "family_cache_limit": OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - **counts, - "active_family_union_census": active, - } - - -def _otf_cells(): - return tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - ) - - -def test_otf_matrix_surface_is_measurable_for_every_color_accuracy() -> None: - cells = _otf_cells() - by_accuracy = Counter(cell.measurement.accuracy for cell in cells) - lc = tuple(cell for cell in cells if cell.measurement.accuracy is Accuracy.LC) - - assert by_accuracy == { - Accuracy.LC: 66, - Accuracy.NLC: 50, - Accuracy.FULL: 100, - } - assert len({(cell.process_key, cell.n_final) for cell in lc}) == 33 - assert {cell.n_final for cell in lc} == {1, 2, 3, 4} - assert all(REPORT_CATALOG.static_na_reason(cell) is None for cell in cells) - assert _BEST_MODE_CODES[ExecutionMode.ON_THE_FLY] == "o" - - -def test_otf_uses_amplicol_for_display_and_recurrence_for_correctness() -> None: - all_flow = next( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is Accuracy.LC - and cell.process_key == "dd_tt_jets" - and cell.n_final == 4 - and cell.workload is Workload.ALL_FLOW - ) - display = REPORT_CATALOG.baseline_cell(all_flow) - validation = REPORT_CATALOG.validation_baseline_cell(all_flow) - edges = incoming_agreement_edges(all_flow) - - assert display is not None - assert display.measurement.execution_mode is ExecutionMode.AMPLICOL - assert validation is not None - assert validation.measurement.execution_mode is ExecutionMode.RECURRENCE - assert all( - edge.baseline.measurement.execution_mode is not ExecutionMode.COMPILED - for edge in edges - ) - selected = next( - edge.baseline for edge in edges if edge.kind == LC_CROSS_LAYOUT_COMPONENT - ) - assert selected.measurement.execution_mode is ExecutionMode.ON_THE_FLY - assert REPORT_CATALOG.equivalent_cells(all_flow) == (selected,) - - -def test_otf_plan_orders_lc_and_contracted_authorities( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - selected = next( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is Accuracy.LC - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is Workload.SELECTED_FLOW - ) - planned = plan_campaign( - (selected,), - store=store, - settings=CampaignSettings(), - ) - - assert tuple(item.cell.measurement.execution_mode for item in planned) == ( - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - ) - nlc = next( - cell for cell in _otf_cells() if cell.measurement.accuracy is Accuracy.NLC - ) - assert nlc.workload is Workload.CONTRACTED - assert tuple( - item.cell.measurement.execution_mode - for item in plan_campaign( - (nlc,), - store=store, - settings=CampaignSettings(), - ) - ) == ( - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - ) - - z_cells = tuple( - cell - for cell in REPORT_CATALOG.z_cells() - if cell.dataset_id == "z_builtin_sm" - and cell.n_final == 1 - and cell.variant == "on_the_fly_jit_o2" - ) - assert {cell.workload for cell in z_cells} == { - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - } - assert all(REPORT_CATALOG.static_na_reason(cell) is None for cell in z_cells) - z_selected = next( - cell for cell in z_cells if cell.workload is Workload.SELECTED_FLOW - ) - z_plan = plan_campaign( - (z_selected,), - store=store, - settings=CampaignSettings(), - ) - assert tuple(item.cell.measurement.execution_mode for item in z_plan) == ( - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - ) - assert z_plan[-1].baseline_cell_id == z_plan[0].cell.cell_id - z_all_flow = next( - cell for cell in z_cells if cell.workload is Workload.ALL_FLOW - ) - z_all_plan = plan_campaign( - (z_all_flow,), - store=store, - settings=CampaignSettings(), - ) - assert tuple( - (item.cell.workload, item.cell.measurement.execution_mode) - for item in z_all_plan - ) == ( - (Workload.SELECTED_FLOW, ExecutionMode.RECURRENCE), - (Workload.SELECTED_FLOW, ExecutionMode.ON_THE_FLY), - (Workload.ALL_FLOW, ExecutionMode.RECURRENCE), - (Workload.ALL_FLOW, ExecutionMode.ON_THE_FLY), - ) - assert z_all_plan[-1].baseline_cell_id == z_all_plan[-2].cell.cell_id - assert z_all_plan[-1].comparison_peer_ids == ( - z_all_plan[1].cell.cell_id, - ) - - ufo_full = next( - cell - for cell in _otf_cells() - if cell.dataset_id == "matrix_on_the_fly_ufo_sm_full" - ) - assert tuple( - item.cell.measurement.execution_mode - for item in plan_campaign( - (ufo_full,), - store=store, - settings=CampaignSettings(), - ) - ) == ( - ExecutionMode.MADGRAPH, - ExecutionMode.ON_THE_FLY, - ) - - -def test_otf_config_reuses_one_topology_replay_artifact_for_both_workloads( - tmp_path: Path, -) -> None: - cells = tuple( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is Accuracy.LC - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - ) - - assert {cell.workload for cell in cells} == { - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - } - configurations = tuple( - config_values(cell, RunnerSettings(), repo_root=tmp_path) for cell in cells - ) - assert { - config["color"]["lc_flow_layout"] # type: ignore[index] - for config in configurations - } == {"topology-replay"} - for config in configurations: - assert config["generation"]["relation_discovery"] == { # type: ignore[index] - "mode": "off" - } - assert config["generation"]["validation"]["enabled"] is False # type: ignore[index] - assert ( # type: ignore[index] - config["generation"]["validation"]["post_build_validation"] is False - ) - assert config["evaluator"]["backend"] == "jit" # type: ignore[index] - assert config["evaluator"]["jit"]["optimization_level"] == 2 # type: ignore[index] - - -@pytest.mark.parametrize("workload", [Workload.SELECTED_FLOW, Workload.ALL_FLOW]) -def test_otf_reproduction_recipe_uses_the_compact_public_generation_contract( - tmp_path: Path, - workload: Workload, -) -> None: - cell = next( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is Accuracy.LC - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is workload - ) - - recipe = reproduction_recipe( - cell, - repo_root=tmp_path / "repo", - artifact_root=tmp_path / "artifacts", - ) - - assert recipe.generate is not None - generate = recipe.generate - assert generate[generate.index("--execution-mode") + 1] == "on-the-fly" - assert generate[generate.index("--lc-flow-layout") + 1] == "topology-replay" - assert "--no-emit-api-bundle" in generate - assert "--emit-api-bundle" not in generate - assert "--no-validation" in generate - assert "--validation" not in generate - assert "--no-post-build-validation" in generate - assert "--post-build-validation" not in generate - assert "--no-numerical-current-reuse" in generate - assert "--numerical-current-reuse" not in generate - - -@pytest.mark.parametrize("accuracy", (Accuracy.LC, Accuracy.NLC, Accuracy.FULL)) -def test_otf_artifact_requires_accuracy_specific_compact_runtime_capability( - monkeypatch: pytest.MonkeyPatch, - accuracy: Accuracy, -) -> None: - cell = next( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is accuracy - and cell.workload - is (Workload.SELECTED_FLOW if accuracy is Accuracy.LC else Workload.CONTRACTED) - ) - process = SimpleNamespace( - execution_mode="on-the-fly", - generation_specialized_axes=(), - selected_source_helicities=(), - selected_color_sector_ids=(), - lc_flow_layout="compact/query-local", - recurrence_color_accuracy=accuracy.value, - recurrence_color_storage="expanded", - recurrence_color_component_count=1, - recurrence_color_group_count=2, - recurrence_color_destination_count=2, - ) - color_capability = ( - "rusticol.on-the-fly.lc-color.v1" - if accuracy is Accuracy.LC - else "rusticol.on-the-fly.contracted-color.v1" - ) - inspection = SimpleNamespace( - processes=(process,), - runtime_capabilities=( - "rusticol.on-the-fly.complex-f64.v1", - color_capability, - ), - ) - monkeypatch.setattr( - "pyamplicol.artifacts.inspect_artifact", - lambda _path: inspection, - ) - - validate_artifact_contract(cell, Path("/artifact")) - if accuracy is not Accuracy.LC: - process.recurrence_color_component_count = 2 - with pytest.raises(RunnerError, match="expanded color payload"): - validate_artifact_contract(cell, Path("/artifact")) - process.recurrence_color_component_count = 1 - inspection.runtime_capabilities = ( - "rusticol.on-the-fly.complex-f64.v1", - "rusticol.on-the-fly.lc-color.v1", - ) - with pytest.raises(RunnerError, match="accuracy-specific"): - validate_artifact_contract(cell, Path("/artifact")) - return - process.lc_flow_layout = "topology-replay" - with pytest.raises(RunnerError, match="compact/query-local"): - validate_artifact_contract(cell, Path("/artifact")) - process.lc_flow_layout = "compact/query-local" - inspection.runtime_capabilities += ("unexpected-capability",) - with pytest.raises(RunnerError, match="exactly its two accuracy-specific"): - validate_artifact_contract(cell, Path("/artifact")) - - -@pytest.mark.parametrize("accuracy", (Accuracy.NLC, Accuracy.FULL)) -def test_otf_contracted_runtime_uses_compact_context_without_flow_selectors( - accuracy: Accuracy, -) -> None: - cell = next( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is accuracy - and cell.workload is Workload.CONTRACTED - ) - - process_expression = cell.process.upper() - - class Backend: - @staticmethod - def _on_the_fly_benchmark_context( - requested: tuple[str, ...], - ) -> dict[str, object]: - assert requested == () - return { - "process_id": "contracted-otf", - "process_expression": process_expression, - "color_accuracy": accuracy.value, - "helicity_count": 4, - "color_count": 1, - "selected_color_ids": [], - } - - runtime = SimpleNamespace(execution_mode="on-the-fly", _backend=Backend()) - validate_runtime_contract(cell, runtime) - - process_expression = "g g > g" - with pytest.raises(RunnerError, match="compact selector identity"): - validate_runtime_contract(cell, runtime) - process_expression = cell.process.upper() - - class DensePhysicsTrap: - @property - def physics(self) -> object: - raise AssertionError("contracted OTF validation opened dense physics") - - runtime._backend = DensePhysicsTrap() - with pytest.raises(RunnerError, match="compact selector context"): - validate_runtime_contract(cell, runtime) - - -@pytest.mark.parametrize("workload", (Workload.SELECTED_FLOW, Workload.ALL_FLOW)) -def test_otf_public_profile_owns_first_evaluation_without_dense_physics( - monkeypatch: pytest.MonkeyPatch, - workload: Workload, -) -> None: - import pyamplicol.api - - cell = next( - cell - for cell in _otf_cells() - if cell.measurement.accuracy is Accuracy.LC and cell.workload is workload - ) - points = (((1.0, 0.0, 0.0, 1.0),),) - contract = SelectorContract( - selected_color_flow_ids=("flow:1,2",), - selected_color_words=((1, 2),), - all_flow_helicity_ids=("h:+1,-1",), - all_flow_source_helicities=((1, 1), (2, -1)), - point_digest=point_digest(points), - ) - events: list[str] = [] - selector_calls: list[tuple[str, tuple[str, ...]]] = [] - dense_physics_accesses = 0 - - class Backend: - @staticmethod - def _on_the_fly_benchmark_context( - requested: tuple[str, ...], - ) -> dict[str, object]: - assert requested == () - return { - "process_id": "compact-profile-candidate", - "process_expression": cell.process, - "color_accuracy": "lc", - "helicity_count": 2, - "color_count": 2, - "selected_color_ids": [], - } - - @staticmethod - def _point_selector_indices( - values: tuple[str, ...], - name: str, - ) -> tuple[int, ...]: - selector_calls.append((name, tuple(values))) - return (0,) - - class Runtime: - execution_mode = "on-the-fly" - _backend = Backend() - - @property - def physics(self) -> object: - nonlocal dense_physics_accesses - dense_physics_accesses += 1 - raise AssertionError("OTF profile opened dense physics") - - def evaluate(self, *_args: object, **_kwargs: object) -> list[float]: - events.append("campaign-evaluate") - expected = ( - {"helicities": None, "color_flows": ("flow:1,2",)} - if workload is Workload.SELECTED_FLOW - else {"helicities": ("h:+1,-1",), "color_flows": None} - ) - assert _kwargs == expected - return [2.0] - - @dataclass(frozen=True) - class Result: - environment: dict[str, object] - - class BenchmarkRunner: - def __init__(self, *_args: object, **_kwargs: object) -> None: - pass - - def run(self, runtime: object, *, points: object) -> Result: - events.append("public-profile") - return Result( - environment={ - "execution_mode": "on-the-fly", - "cold_warmup_elapsed_seconds": 0.25, - } - ) - - def benchmark_measurement(benchmark: Result, *, matrix_element: float): - assert matrix_element == 2.0 - assert benchmark.environment["cold_warmup_elapsed_seconds"] == 0.25 - assert benchmark.environment["report_command_path"] == ( - LOADED_RUNTIME_PROFILE_COMMAND_PATH - ) - assert benchmark.environment["report_public_cli_path"] == ( - PUBLIC_CLI_COMMAND_PATH - ) - return {"status": "ok"} - - monkeypatch.setattr(pyamplicol.api, "BenchmarkRunner", BenchmarkRunner) - monkeypatch.setattr( - "tools.performance_report.runner._benchmark_measurement", - benchmark_measurement, - ) - monkeypatch.setattr( - "tools.performance_report.runner.resolved_sum_validation", - lambda *_args, **_kwargs: {"status": "ok"}, - ) - - result = profile_runtime( - Runtime(), - points, - cell=cell, - benchmark_config=BenchmarkConfig(), - selector_contract=contract, - ) - - assert result["status"] == "ok" - assert events == ["public-profile", "campaign-evaluate"] - assert dense_physics_accesses == 0 - assert selector_calls == [ - ("color_flow_by_point", ("flow:1,2",)), - ("helicity_by_point", ("h:+1,-1",)), - ] - - -def test_otf_benchmark_measurement_requires_and_stores_cold_warmup() -> None: - environment = { - "execution_mode": "on-the-fly", - "batch_size": 128, - "evaluator_time_raw_seconds_per_point": 8.0e-7, - "evaluator_time_status": "measured", - "evaluator_time_ratio_eligible": True, - "evaluator_time_source": "runtime_profile_core_recurrence_schedule_time", - "native_profile_points_per_sample": 128, - "native_profile_repetitions_per_sample": 1, - "native_profile_batch_size": 128, - "timing_sample_contract": "paired-native-repeated-profile-v1", - "elapsed_seconds": 1.0, - "measured_point_count": 640, - "evaluator_total_time_raw_seconds_per_point": 9.0e-7, - "evaluator_total_time_status": "measured", - "evaluator_total_time_ratio_eligible": False, - "evaluator_total_time_source": ("runtime._benchmark_f64_wall_time.accumulated"), - "evaluator_total_time_sample_contract": ( - "accumulated-repeated-warmed-evaluator-total-v1" - ), - "evaluator_total_accumulated_seconds": 5.76e-4, - "cold_warmup_elapsed_seconds": 0.25, - "cold_warmup_run_count": 1, - "cold_warmup_batch_size": 128, - "cold_warmup_point_count": 128, - "cold_warmup_timer_source": WARMUP_TIMER_SOURCE, - "cold_warmup_timing_scope": OTF_COLD_WARMUP_TIMING_SCOPE, - "cold_warmup_runtime_freshness": OTF_COLD_WARMUP_RUNTIME_FRESHNESS, - "cold_warmup_runtime_state_evidence": (OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE), - "cold_warmup_runtime_state_before": _otf_warmup_runtime_state(retained=False), - "cold_warmup_runtime_state_after": _otf_warmup_runtime_state(retained=True), - "cold_warmup_runtime_cold_before_first_evaluation": True, - "cold_warmup_runtime_retained_before_first_evaluation": False, - "cold_warmup_runtime_retained_after_first_evaluation": True, - "cold_warmup_ratio_eligible": False, - "cold_warmup_acceptance_eligible": False, - "warmup_elapsed_seconds": 0.2, - "warmup_configured_run_count": 2, - "warmup_batch_size": 128, - "warmup_point_count": 256, - "warmup_run_outer_wall_seconds": (0.1, 0.1), - "first_warmup_run_outer_wall_seconds": 0.1, - "warmup_timer_source": WARMUP_TIMER_SOURCE, - "warmup_timing_scope": CONVENTIONAL_WARMUP_TIMING_SCOPE, - } - benchmark = SimpleNamespace( - uncertainty=SimpleNamespace( - standard_error=1.0e-8, - relative_standard_error=0.01, - ), - environment=environment, - evaluator_time_per_point=8.0e-7, - evaluator_total_time_per_point=9.0e-7, - wall_time_per_point=1.0e-6, - sample_count=5, - effective_config=SimpleNamespace( - target_runtime=1.0, - batch_size=128, - warmup_runs=2, - ), - ) - - measurement = _benchmark_measurement(benchmark, matrix_element=2.0) - assert measurement["benchmark_evidence"]["cold_warmup_elapsed_seconds"] == 0.25 - assert ( - measurement["benchmark_evidence"]["cold_warmup_runtime_state_evidence"] - == OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - ) - assert ( - measurement["benchmark_evidence"]["cold_warmup_runtime_state_before"][ - "retained_family_count" - ] - == 0 - ) - assert ( - measurement["benchmark_evidence"]["cold_warmup_runtime_state_after"][ - "retained_family_count" - ] - == 1 - ) - assert measurement["evaluator_total_timing"] == { - "abi": "pyamplicol-report-evaluator-total-timing-v1", - "status": "measured", - "ratio_eligible": False, - "raw_seconds_per_point": 9.0e-7, - "source": "runtime._benchmark_f64_wall_time.accumulated", - "execution_mode": "on-the-fly", - "sample_contract": "accumulated-repeated-warmed-evaluator-total-v1", - "sample_count": 5, - "repetitions_per_sample": 1, - "batch_size": 128, - "points_per_sample": 128, - "measured_point_count": 640, - "accumulated_seconds": 5.76e-4, - } - - del environment["cold_warmup_elapsed_seconds"] - with pytest.raises(RunnerError, match="incomplete cold warm-up evidence"): - _benchmark_measurement(benchmark, matrix_element=2.0) - - -def test_otf_tables_are_in_the_normal_matrix_render_path() -> None: - tables = render_all_matrix_tables(build_reset_caches()) - - assert { - "result_matrix_on_the_fly_builtin_sm_lc_table.tex", - "result_matrix_on_the_fly_builtin_sm_nlc_table.tex", - "result_matrix_on_the_fly_builtin_sm_full_table.tex", - "result_matrix_on_the_fly_ufo_sm_full_vs_madgraph_table.tex", - } <= tables.keys() diff --git a/pyamplicol/tests/unit/test_on_the_fly_recurrence_authority_campaign.py b/pyamplicol/tests/unit/test_on_the_fly_recurrence_authority_campaign.py deleted file mode 100644 index d076825f5c..0000000000 --- a/pyamplicol/tests/unit/test_on_the_fly_recurrence_authority_campaign.py +++ /dev/null @@ -1,1188 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import gc -from copy import deepcopy -from pathlib import Path -from types import SimpleNamespace -from weakref import ReferenceType, ref - -import pytest -from jsonschema import Draft202012Validator, ValidationError - -from tools.performance_report import cache as report_cache -from tools.performance_report import measurement as report_measurement -from tools.performance_report import runner as report_runner -from tools.performance_report.agreements import DIRECT_AGREEMENT_FIELD -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import Accuracy, CellSpec, ExecutionMode, Workload -from tools.performance_report.runner import ( - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD, - GeneratedArtifact, - RunnerError, - RunnerSettings, - SelectorContract, - config_values, - derive_selector_contract, - on_the_fly_recurrence_authority_validation, - point_digest, - runtime_identity_payload, - validate_runtime_contract, - validate_selector_contract, -) - -POINTS = (((1.0,),), ((2.0,),)) -FLOW_IDS = ("flow:1,2", "flow:2,1") -HELICITY_IDS = ("h:+1,-1", "h:-1,+1") - - -def _otf_cell(workload: Workload): - return next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is workload - ) - - -def _recurrence_authority(cell): - recurrence = REPORT_CATALOG.validation_baseline_cell(cell) - assert recurrence is not None - assert recurrence.measurement.execution_mode is ExecutionMode.RECURRENCE - return recurrence - - -def _contract() -> SelectorContract: - return SelectorContract( - selected_color_flow_ids=(FLOW_IDS[0],), - selected_color_words=((1, 2),), - all_flow_helicity_ids=(HELICITY_IDS[0],), - all_flow_source_helicities=((1, 1), (2, -1)), - point_digest=point_digest(POINTS), - ) - - -class _Runtime: - def __init__( - self, - mode: ExecutionMode, - artifact_character: str, - *, - reverse_resolved_axis: bool = False, - mutate_nonfirst_component: bool = False, - inconsistent_total: bool = False, - structural_zero_residue: float | None = None, - ) -> None: - self.execution_mode = mode.value - self.artifact_id = artifact_character * 64 - self.reverse_resolved_axis = reverse_resolved_axis - self.mutate_nonfirst_component = mutate_nonfirst_component - self.inconsistent_total = inconsistent_total - self.structural_zero_residue = structural_zero_residue - self.events: list[tuple[object, ...]] = [] - self.physics = SimpleNamespace( - color_accuracy="lc", - selector_capabilities=("helicity", "color_flow"), - color_flows=( - SimpleNamespace(id=FLOW_IDS[0], word=(1, 2)), - SimpleNamespace(id=FLOW_IDS[1], word=(2, 1)), - ), - helicities=( - SimpleNamespace(id=HELICITY_IDS[0], values=(1, -1)), - SimpleNamespace(id=HELICITY_IDS[1], values=(-1, 1)), - ), - external_particles=( - SimpleNamespace(label=1), - SimpleNamespace(label=2), - ), - ) - - def _on_the_fly_benchmark_context( - self, - requested: tuple[str, ...], - ) -> dict[str, object]: - assert self.execution_mode == ExecutionMode.ON_THE_FLY.value - return { - "process_id": "compact-candidate", - "process_expression": "d d~ > z", - "color_accuracy": "lc", - "helicity_count": len(HELICITY_IDS), - "color_count": len(FLOW_IDS), - "selected_color_ids": list(requested), - } - - def _point_selector_indices( - self, - values: tuple[str, ...], - name: str, - ) -> tuple[int, ...]: - assert self.execution_mode == ExecutionMode.ON_THE_FLY.value - available = HELICITY_IDS if name == "helicity_by_point" else FLOW_IDS - return tuple(available.index(identifier) for identifier in values) - - def evaluate( - self, - points: object, - *, - helicities: tuple[str, ...] | None = None, - color_flows: tuple[str, ...] | None = None, - precision: int = 16, - ) -> tuple[float, ...]: - assert precision == 16 - self.events.append(("evaluate", helicities, color_flows)) - _selected_helicities, _selected_colors, values = self._resolved_payload( - points, - helicities=helicities, - color_flows=color_flows, - ) - totals = [ - sum(component for row in point for component in row) for point in values - ] - if self.inconsistent_total: - totals[-1] += 1.0 - return tuple(totals) - - def _resolved_payload( - self, - points: object, - *, - helicities: tuple[str, ...] | None, - color_flows: tuple[str, ...] | None, - ) -> tuple[list[str], list[str], list[list[list[float]]]]: - selected_helicities = list(HELICITY_IDS if helicities is None else helicities) - selected_colors = list(FLOW_IDS if color_flows is None else color_flows) - if self.reverse_resolved_axis: - if len(selected_helicities) > 1: - selected_helicities.reverse() - elif len(selected_colors) > 1: - selected_colors.reverse() - first_component = (selected_helicities[0], selected_colors[0]) - last_component = (selected_helicities[-1], selected_colors[-1]) - values: list[list[list[float]]] = [] - for point_index, _point in enumerate(points): # type: ignore[arg-type] - point_rows: list[list[float]] = [] - for helicity_id in selected_helicities: - row: list[float] = [] - for color_id in selected_colors: - value = ( - 1.0 - + 10.0 * point_index - + 2.0 * HELICITY_IDS.index(helicity_id) - + FLOW_IDS.index(color_id) - ) - component = (helicity_id, color_id) - if ( - self.structural_zero_residue is not None - and point_index == 0 - and component == (HELICITY_IDS[0], FLOW_IDS[0]) - ): - value = self.structural_zero_residue - if self.mutate_nonfirst_component and point_index == 1: - if component == first_component: - value -= 1.0 - if component == last_component: - value += 1.0 - row.append(value) - point_rows.append(row) - values.append(point_rows) - return selected_helicities, selected_colors, values - - def evaluate_resolved( - self, - points: object, - *, - helicities: tuple[str, ...] | None = None, - color_flows: tuple[str, ...] | None = None, - precision: int = 16, - ) -> SimpleNamespace: - assert precision == 16 - self.events.append(("resolved", helicities, color_flows)) - selected_helicities, selected_colors, values = self._resolved_payload( - points, - helicities=helicities, - color_flows=color_flows, - ) - frozen_values = tuple( - tuple(tuple(row) for row in point_rows) for point_rows in values - ) - - def total() -> tuple[float, ...]: - self.events.append(("resolved-total", helicities, color_flows)) - return tuple( - sum(component for row in point for component in row) - for point in frozen_values - ) - - return SimpleNamespace( - helicity_ids=tuple(selected_helicities), - color_ids=tuple(selected_colors), - values=frozen_values, - total=total, - ) - - def clear(self) -> None: - self.events.append(("clear",)) - - -class _CompactBackend: - def __init__( - self, - cell: CellSpec, - *, - context_updates: dict[str, object] | None = None, - ordinal_overrides: dict[str, tuple[int, ...]] | None = None, - ) -> None: - self.cell = cell - self.context_updates = context_updates or {} - self.ordinal_overrides = ordinal_overrides or {} - self.context_requests: list[tuple[str, ...]] = [] - self.ordinal_requests: list[tuple[str, tuple[str, ...]]] = [] - - def _on_the_fly_benchmark_context( - self, - requested: tuple[str, ...], - ) -> dict[str, object]: - self.context_requests.append(requested) - value = { - "process_id": "compact-candidate", - "process_expression": self.cell.process, - "color_accuracy": "lc", - "helicity_count": len(HELICITY_IDS), - "color_count": len(FLOW_IDS), - "selected_color_ids": list(requested), - } - value.update(self.context_updates) - return value - - def _point_selector_indices( - self, - values: tuple[str, ...], - name: str, - ) -> tuple[int, ...]: - frozen = tuple(values) - self.ordinal_requests.append((name, frozen)) - override = self.ordinal_overrides.get(name) - if override is not None: - return override - available = HELICITY_IDS if name == "helicity_by_point" else FLOW_IDS - return tuple(available.index(identifier) for identifier in frozen) - - -class _CompactCandidate: - execution_mode = ExecutionMode.ON_THE_FLY.value - artifact_id = "a" * 64 - - def __init__( - self, - cell: CellSpec, - *, - context_updates: dict[str, object] | None = None, - ordinal_overrides: dict[str, tuple[int, ...]] | None = None, - ) -> None: - self._delegate = _Runtime(ExecutionMode.ON_THE_FLY, "a") - self._backend = _CompactBackend( - cell, - context_updates=context_updates, - ordinal_overrides=ordinal_overrides, - ) - self.dense_physics_access_count = 0 - - @property - def physics(self) -> object: - self.dense_physics_access_count += 1 - raise AssertionError("compact candidate opened dense physics") - - @property - def events(self) -> list[tuple[object, ...]]: - return self._delegate.events - - def evaluate(self, *args: object, **kwargs: object) -> tuple[float, ...]: - return self._delegate.evaluate(*args, **kwargs) - - def evaluate_resolved(self, *args: object, **kwargs: object) -> SimpleNamespace: - return self._delegate.evaluate_resolved(*args, **kwargs) - - def clear(self) -> None: - self._delegate.clear() - - -def _valid_gate(workload: Workload): - cell = _otf_cell(workload) - recurrence_cell = _recurrence_authority(cell) - candidate = _Runtime(ExecutionMode.ON_THE_FLY, "a") - recurrence = _Runtime( - ExecutionMode.RECURRENCE, - "b", - reverse_resolved_axis=True, - ) - contract = _contract() - record = on_the_fly_recurrence_authority_validation( - candidate, - POINTS, - cell=cell, - selector_contract=contract, - authority=(recurrence_cell, recurrence), - ) - return cell, contract, record, candidate, recurrence - - -@pytest.mark.parametrize("workload", (Workload.SELECTED_FLOW, Workload.ALL_FLOW)) -def test_recurrence_authority_candidate_uses_only_compact_selector_contract( - workload: Workload, -) -> None: - cell = _otf_cell(workload) - recurrence_cell = _recurrence_authority(cell) - candidate = _CompactCandidate(cell) - - record = on_the_fly_recurrence_authority_validation( - candidate, - POINTS, - cell=cell, - selector_contract=_contract(), - authority=( - recurrence_cell, - _Runtime(ExecutionMode.RECURRENCE, "b"), - ), - ) - - assert record["status"] == "ok" - assert candidate.dense_physics_access_count == 0 - assert candidate._backend.context_requests == [(), ()] - assert candidate._backend.ordinal_requests == [ - ("color_flow_by_point", (FLOW_IDS[0],)), - ("helicity_by_point", (HELICITY_IDS[0],)), - ] - - -@pytest.mark.parametrize( - ("context_updates", "message"), - ( - ({"process_expression": "g g > g"}, "identity differs"), - ({"helicity_count": 0}, "helicity_count is invalid"), - ({"color_count": False}, "color_count is invalid"), - ), -) -def test_compact_runtime_contract_rejects_invalid_identity_or_counts( - context_updates: dict[str, object], - message: str, -) -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - candidate = _CompactCandidate(cell, context_updates=context_updates) - - with pytest.raises(RunnerError, match=message): - validate_runtime_contract(cell, candidate) - - assert candidate.dense_physics_access_count == 0 - - -@pytest.mark.parametrize( - ("name", "count"), - ( - ("color_flow_by_point", len(FLOW_IDS)), - ("helicity_by_point", len(HELICITY_IDS)), - ), -) -def test_compact_selector_contract_rejects_out_of_range_ordinal( - name: str, - count: int, -) -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - candidate = _CompactCandidate( - cell, - ordinal_overrides={name: (count,)}, - ) - - with pytest.raises(RunnerError, match=rf"invalid {name} ordinals"): - validate_selector_contract( - candidate, - _contract(), - POINTS, - cell=cell, - ) - - assert candidate.dense_physics_access_count == 0 - - -def test_selector_derivation_rejects_otf_before_dense_physics_access() -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - candidate = _CompactCandidate(cell) - - with pytest.raises(RunnerError, match="must be inherited from a dense authority"): - derive_selector_contract(candidate, POINTS) - - assert candidate.dense_physics_access_count == 0 - assert candidate._backend.context_requests == [] - - -@pytest.mark.parametrize("validation", ("runtime", "selector")) -def test_compact_runtime_rejects_non_otf_cell_before_dense_physics_access( - validation: str, -) -> None: - otf_cell = _otf_cell(Workload.SELECTED_FLOW) - recurrence_cell = _recurrence_authority(otf_cell) - candidate = _CompactCandidate(otf_cell) - - with pytest.raises(RunnerError, match="wrong execution mode"): - if validation == "runtime": - validate_runtime_contract(recurrence_cell, candidate) - else: - validate_selector_contract( - candidate, - _contract(), - POINTS, - cell=recurrence_cell, - ) - - assert candidate.dense_physics_access_count == 0 - assert candidate._backend.context_requests == [] - assert candidate._backend.ordinal_requests == [] - - -@pytest.mark.parametrize("workload", (Workload.SELECTED_FLOW, Workload.ALL_FLOW)) -def test_recurrence_authority_gate_aligns_semantic_axes_and_resets_before_profile( - workload: Workload, -) -> None: - _cell, _contract_value, record, candidate, recurrence = _valid_gate(workload) - expected_selectors = ( - (None, (FLOW_IDS[0],)) - if workload is Workload.SELECTED_FLOW - else ((HELICITY_IDS[0],), None) - ) - - assert candidate.events == [ - ("evaluate", *expected_selectors), - ("resolved", *expected_selectors), - ("resolved-total", *expected_selectors), - ("clear",), - ("evaluate", *expected_selectors), - ("resolved", *expected_selectors), - ("resolved-total", *expected_selectors), - ("clear",), - ] - assert recurrence.events == [ - ("evaluate", *expected_selectors), - ("resolved", *expected_selectors), - ("resolved-total", *expected_selectors), - ] - assert record["lifecycle"]["clear_call_count"] == 2 - assert record["lifecycle"]["final_clear_before_profile"] is True - assert record["resolved_check_count"] == 4 - assert record["authority"]["resolved_sum"]["maximum_conditioned_residual"] == 0.0 - assert all( - stage["candidate_resolved_sum"]["maximum_conditioned_residual"] == 0.0 - for stage in (record["before_clear"], record["after_clear"]) - ) - assert ( - record["authority"]["resolved_ordering_sha256"] - != record["before_clear"]["candidate_resolved_ordering_sha256"] - ) - assert all( - stage["comparison"]["resolved_components"]["maximum_conditioned_residual"] - == 0.0 - for stage in (record["before_clear"], record["after_clear"]) - ) - - -def test_mutated_nonfirst_component_fails_before_public_profile( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - recurrence_cell = _recurrence_authority(cell) - candidate = _Runtime( - ExecutionMode.ON_THE_FLY, - "a", - mutate_nonfirst_component=True, - ) - recurrence = _Runtime(ExecutionMode.RECURRENCE, "b") - contract = _contract() - generated = GeneratedArtifact( - path=tmp_path / "candidate", - process_id="process", - generation_seconds=1.0, - model_preparation_seconds=0.0, - model_preparation_reused=True, - requested_config={}, - effective_config={}, - ) - profile_calls: list[object] = [] - - monkeypatch.setattr( - report_measurement, "generate_artifact", lambda *_a, **_k: generated - ) - monkeypatch.setattr( - report_measurement, "validate_artifact_contract", lambda *_a, **_k: None - ) - monkeypatch.setattr( - report_measurement, "_load_runtime", lambda *_a, **_k: candidate - ) - monkeypatch.setattr( - report_measurement, - "runtime_identity_payload", - lambda *_a, **_k: {"loaded_module_origin_policy": {"observations": []}}, - ) - monkeypatch.setattr( - report_measurement, "shared_validation_points", lambda _p: POINTS - ) - monkeypatch.setattr( - report_measurement, - "_load_on_the_fly_recurrence_authority", - lambda *_a, **_k: (recurrence_cell, recurrence), - ) - monkeypatch.setattr( - report_measurement, - "profile_runtime", - lambda *_a, **_k: profile_calls.append(object()), - ) - baseline = { - "status": "ok", - "matrix_element": 1.0, - "selector_contract": contract.as_dict(), - } - - with pytest.raises(RunnerError, match="resolved components disagrees"): - report_measurement.measure_pyamplicol_cell( - cell, - artifact_path=tmp_path / "artifact", - settings=RunnerSettings(source_revision_override="d" * 40), - repo_root=tmp_path, - baseline=baseline, - ) - - assert profile_calls == [] - assert ("clear",) not in candidate.events - - -def test_pure_gluon_structural_zero_residue_uses_resolved_slice_scale() -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - recurrence_cell = _recurrence_authority(cell) - record = on_the_fly_recurrence_authority_validation( - _Runtime( - ExecutionMode.ON_THE_FLY, - "a", - structural_zero_residue=1.0e-30, - ), - POINTS, - cell=cell, - selector_contract=_contract(), - authority=( - recurrence_cell, - _Runtime( - ExecutionMode.RECURRENCE, - "b", - reverse_resolved_axis=True, - structural_zero_residue=0.0, - ), - ), - ) - - comparisons = tuple( - stage["comparison"] for stage in (record["before_clear"], record["after_clear"]) - ) - assert all( - comparison["resolved_components"]["maximum_absolute_delta"] - == pytest.approx(1.0e-30) - for comparison in comparisons - ) - assert all( - comparison["resolved_components"]["maximum_conditioned_residual"] - < report_runner.RELATIVE_TOLERANCE - for comparison in comparisons - ) - - -def test_inconsistent_optimized_and_resolved_sum_fails_before_clear() -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - recurrence_cell = _recurrence_authority(cell) - candidate = _Runtime( - ExecutionMode.ON_THE_FLY, - "a", - inconsistent_total=True, - ) - - with pytest.raises(RunnerError, match="optimized/resolved sum disagrees"): - on_the_fly_recurrence_authority_validation( - candidate, - POINTS, - cell=cell, - selector_contract=_contract(), - authority=( - recurrence_cell, - _Runtime(ExecutionMode.RECURRENCE, "b"), - ), - ) - - assert ("resolved-total", None, (FLOW_IDS[0],)) in candidate.events - assert ("clear",) not in candidate.events - - -def test_measurement_releases_recurrence_authority_before_public_profile( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - class _ProfileReached(Exception): - pass - - cell = _otf_cell(Workload.SELECTED_FLOW) - recurrence_cell = _recurrence_authority(cell) - candidate = _Runtime(ExecutionMode.ON_THE_FLY, "a") - contract = _contract() - generated = GeneratedArtifact( - path=tmp_path / "candidate", - process_id="process", - generation_seconds=1.0, - model_preparation_seconds=0.0, - model_preparation_reused=True, - requested_config={}, - effective_config={}, - ) - authority_refs: list[ReferenceType[_Runtime]] = [] - - def load_authority(*_args: object, **_kwargs: object): - recurrence = _Runtime(ExecutionMode.RECURRENCE, "b") - authority_refs.append(ref(recurrence)) - return (recurrence_cell, recurrence) - - def profile(*_args: object, **_kwargs: object): - gc.collect() - assert authority_refs and all(item() is None for item in authority_refs) - raise _ProfileReached - - monkeypatch.setattr( - report_measurement, "generate_artifact", lambda *_a, **_k: generated - ) - monkeypatch.setattr( - report_measurement, "validate_artifact_contract", lambda *_a, **_k: None - ) - monkeypatch.setattr( - report_measurement, "_load_runtime", lambda *_a, **_k: candidate - ) - monkeypatch.setattr( - report_measurement, - "runtime_identity_payload", - lambda *_a, **_k: {"loaded_module_origin_policy": {"observations": []}}, - ) - monkeypatch.setattr( - report_measurement, "shared_validation_points", lambda _process: POINTS - ) - monkeypatch.setattr( - report_measurement, - "_load_on_the_fly_recurrence_authority", - load_authority, - ) - monkeypatch.setattr( - report_measurement, - "_resolution_benchmark_config", - lambda _config: object(), - ) - monkeypatch.setattr(report_measurement, "profile_runtime", profile) - baseline = { - "status": "ok", - "matrix_element": 1.0, - "selector_contract": contract.as_dict(), - } - - with pytest.raises(_ProfileReached): - report_measurement.measure_pyamplicol_cell( - cell, - artifact_path=tmp_path / "artifact", - settings=RunnerSettings(source_revision_override="d" * 40), - repo_root=tmp_path, - baseline=baseline, - ) - - -def test_recurrence_authority_is_loaded_without_generation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - recurrence_cell = _recurrence_authority(cell) - recurrence_path = tmp_path / "recurrence" - recurrence_path.mkdir() - - def measurement(path: Path, process_id: str) -> dict[str, object]: - return { - "status": "ok", - "generation_seconds": 1.0, - "artifact": {"path": str(path), "process_id": process_id}, - "provenance": { - "requested_config": {}, - "effective_config": {}, - "model_preparation_seconds": 0.0, - "model_preparation_reused": True, - }, - } - - baseline = measurement(recurrence_path, "recurrence-process") - loads: list[tuple[Path, str]] = [] - validations: list[tuple[str, Path]] = [] - monkeypatch.setattr( - report_measurement, - "validate_artifact_contract", - lambda authority_cell, path: validations.append((authority_cell.cell_id, path)), - ) - monkeypatch.setattr( - report_measurement, - "_load_runtime", - lambda path, process_id: loads.append((path, process_id)) or object(), - ) - monkeypatch.setattr( - report_measurement, - "generate_artifact", - lambda *_a, **_k: pytest.fail("authority generation must not run"), - ) - - loaded_cell, _loaded_runtime = ( - report_measurement._load_on_the_fly_recurrence_authority( - cell, - baseline=baseline, - catalog=REPORT_CATALOG, - ) - ) - - assert loaded_cell == recurrence_cell - assert loads == [(recurrence_path.resolve(), "recurrence-process")] - assert validations == [(recurrence_cell.cell_id, recurrence_path.resolve())] - - -def test_otf_cache_requires_and_authenticates_compact_gate_record() -> None: - cell, contract, record, *_runtimes = _valid_gate(Workload.SELECTED_FLOW) - measurement = { - "selector_contract": contract.as_dict(), - "provenance": { - "runtime_identity": {"artifact_id": record["candidate_artifact_id"]} - }, - } - validation = {OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD: record} - report_cache._validate_successful_otf_recurrence_authority( - measurement, - validation, - expected_cell=cell, - catalog=REPORT_CATALOG, - ) - - with pytest.raises(ValueError, match="must be an object"): - report_cache._validate_successful_otf_recurrence_authority( - measurement, - {}, - expected_cell=cell, - catalog=REPORT_CATALOG, - ) - - for mutation in ("digest", "count", "resolved_sum", "lifecycle", "authority"): - corrupted = deepcopy(record) - if mutation == "digest": - corrupted["before_clear"]["candidate_resolved_source_sha256"] = "bad" - elif mutation == "count": - corrupted["resolved_check_count"] += 1 - elif mutation == "resolved_sum": - corrupted["before_clear"]["candidate_resolved_sum"][ - "maximum_conditioned_residual" - ] = 1.0e-6 - elif mutation == "lifecycle": - corrupted["lifecycle"]["clear_call_count"] = 1 - else: - corrupted["authority"]["cell_id"] = "wrong-recurrence-cell" - with pytest.raises(ValueError): - report_cache._validate_successful_otf_recurrence_authority( - measurement, - {OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD: corrupted}, - expected_cell=cell, - catalog=REPORT_CATALOG, - ) - - -def _warmup_runtime_state(*, retained: bool) -> dict[str, object]: - counts = {field: 0 for field in report_runner.OTF_RUNTIME_STATE_COUNT_FIELDS} - active: dict[str, object] | None = None - if retained: - counts.update( - { - field: 1 - for field in ( - *report_runner.OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS, - *report_runner.OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS, - ) - } - ) - active = { - "basis": "shared-query-family-union-v1", - "scope": "active-family-union", - **{field: 1 for field in report_runner.OTF_ACTIVE_FAMILY_COUNT_FIELDS}, - } - return { - "kind": report_runner.OTF_RUNTIME_STATE_CENSUS_KIND, - "process_id": "otf_warmup_process", - "family_cache_policy": report_runner.OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - "family_cache_limit": report_runner.OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - **counts, - "active_family_union_census": active, - } - - -def _warmup_evidence() -> dict[str, object]: - return { - "cold_warmup_elapsed_seconds": 4.767252833, - "cold_warmup_run_count": 1, - "cold_warmup_batch_size": 128, - "cold_warmup_point_count": 128, - "cold_warmup_timer_source": report_runner.WARMUP_TIMER_SOURCE, - "cold_warmup_timing_scope": report_runner.OTF_COLD_WARMUP_TIMING_SCOPE, - "cold_warmup_runtime_freshness": ( - report_runner.OTF_COLD_WARMUP_RUNTIME_FRESHNESS - ), - "cold_warmup_runtime_state_evidence": ( - report_runner.OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - ), - "cold_warmup_runtime_state_before": _warmup_runtime_state(retained=False), - "cold_warmup_runtime_state_after": _warmup_runtime_state(retained=True), - "cold_warmup_runtime_cold_before_first_evaluation": True, - "cold_warmup_runtime_retained_before_first_evaluation": False, - "cold_warmup_runtime_retained_after_first_evaluation": True, - "cold_warmup_ratio_eligible": False, - "cold_warmup_acceptance_eligible": False, - "warmup_elapsed_seconds": 0.021, - "warmup_configured_run_count": 2, - "warmup_batch_size": 128, - "warmup_point_count": 256, - "warmup_run_outer_wall_seconds": [0.010, 0.011], - "first_warmup_run_outer_wall_seconds": 0.010, - "warmup_timer_source": report_runner.WARMUP_TIMER_SOURCE, - "warmup_timing_scope": report_runner.CONVENTIONAL_WARMUP_TIMING_SCOPE, - } - - -def test_otf_cache_requires_complete_cold_and_conventional_warmups() -> None: - cell = _otf_cell(Workload.SELECTED_FLOW) - measurement = { - "provenance": { - "runtime_profile": _warmup_evidence(), - "runtime_load_included_in_cold_warmup": False, - "generation_timer_excludes_model_preparation": True, - "effective_config": {"benchmark": {"batch_size": 128, "warmup_runs": 2}}, - } - } - - report_cache._validate_successful_otf_warmup_evidence( - measurement, - expected_cell=cell, - ) - - structural_zero = deepcopy(measurement) - structural_after = structural_zero["provenance"]["runtime_profile"][ - "cold_warmup_runtime_state_after" - ] - for field in report_runner.OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS: - structural_after[field] = 0 - structural_after["active_family_union_census"] = None - report_cache._validate_successful_otf_warmup_evidence( - structural_zero, - expected_cell=cell, - ) - partial_structural_zero = deepcopy(structural_zero) - partial_structural_zero["provenance"]["runtime_profile"][ - "cold_warmup_runtime_state_after" - ]["retained_executor_handle_count"] = 1 - with pytest.raises( - ValueError, - match=r"after the first evaluation.*strictly retained", - ): - report_cache._validate_successful_otf_warmup_evidence( - partial_structural_zero, - expected_cell=cell, - ) - - retained_before = deepcopy(measurement) - retained_profile = retained_before["provenance"]["runtime_profile"] - retained_profile["cold_warmup_runtime_state_before"] = _warmup_runtime_state( - retained=True - ) - retained_profile["cold_warmup_runtime_freshness"] = ( - report_runner.OTF_COLD_WARMUP_RUNTIME_RETAINED_FRESHNESS - ) - retained_profile["cold_warmup_runtime_cold_before_first_evaluation"] = False - retained_profile["cold_warmup_runtime_retained_before_first_evaluation"] = True - report_cache._validate_successful_otf_warmup_evidence( - retained_before, - expected_cell=cell, - ) - - partial_after = deepcopy(measurement) - partial_after_profile = partial_after["provenance"]["runtime_profile"] - partial_after_profile["cold_warmup_runtime_state_after"]["pending_family_count"] = 1 - with pytest.raises( - ValueError, - match=r"after the first evaluation.*strictly retained", - ): - report_cache._validate_successful_otf_warmup_evidence( - partial_after, - expected_cell=cell, - ) - - invalid_limit = deepcopy(measurement) - invalid_limit["provenance"]["runtime_profile"]["cold_warmup_runtime_state_before"][ - "family_cache_limit" - ] = True - with pytest.raises(ValueError, match="family cache limit 1"): - report_cache._validate_successful_otf_warmup_evidence( - invalid_limit, - expected_cell=cell, - ) - - missing = deepcopy(measurement) - del missing["provenance"]["runtime_profile"]["warmup_timer_source"] - with pytest.raises(ValueError, match="incomplete conventional warm-up"): - report_cache._validate_successful_otf_warmup_evidence( - missing, - expected_cell=cell, - ) - - eligible = deepcopy(measurement) - eligible["provenance"]["runtime_profile"]["cold_warmup_ratio_eligible"] = True - with pytest.raises(ValueError, match="ineligible for ratios and acceptance"): - report_cache._validate_successful_otf_warmup_evidence( - eligible, - expected_cell=cell, - ) - - for field, invalid in ( - ("runtime_load_included_in_cold_warmup", True), - ("generation_timer_excludes_model_preparation", False), - ): - contradictory = deepcopy(measurement) - contradictory["provenance"][field] = invalid - with pytest.raises(ValueError, match="exclude"): - report_cache._validate_successful_otf_warmup_evidence( - contradictory, - expected_cell=cell, - ) - - coordinated_batch = deepcopy(measurement) - batch_profile = coordinated_batch["provenance"]["runtime_profile"] - batch_profile["cold_warmup_batch_size"] = 64 - batch_profile["cold_warmup_point_count"] = 64 - batch_profile["warmup_batch_size"] = 64 - batch_profile["warmup_point_count"] = 128 - with pytest.raises(ValueError, match="effective benchmark configuration"): - report_cache._validate_successful_otf_warmup_evidence( - coordinated_batch, - expected_cell=cell, - ) - - coordinated_runs = deepcopy(measurement) - run_profile = coordinated_runs["provenance"]["runtime_profile"] - run_profile["warmup_configured_run_count"] = 1 - run_profile["warmup_point_count"] = 128 - run_profile["warmup_run_outer_wall_seconds"] = [0.010] - run_profile["first_warmup_run_outer_wall_seconds"] = 0.010 - run_profile["warmup_elapsed_seconds"] = 0.010 - with pytest.raises(ValueError, match="effective benchmark configuration"): - report_cache._validate_successful_otf_warmup_evidence( - coordinated_runs, - expected_cell=cell, - ) - - -def test_report_cache_schema_carries_bounded_warmup_field_contracts() -> None: - schema = report_cache.schema_document() - measurement = schema["properties"]["entries"]["items"]["properties"]["measurement"] - provenance = measurement["properties"]["provenance"]["oneOf"][1] - runtime_profile = provenance["properties"]["runtime_profile"] - - assert runtime_profile["properties"]["cold_warmup_run_count"] == {"const": 1} - assert runtime_profile["properties"]["cold_warmup_ratio_eligible"] == { - "const": False - } - assert runtime_profile["properties"]["cold_warmup_runtime_freshness"] == { - "enum": sorted(report_runner.OTF_COLD_WARMUP_RUNTIME_FRESHNESSES) - } - assert runtime_profile["properties"]["cold_warmup_runtime_state_evidence"] == { - "const": report_runner.OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - } - state_schema = runtime_profile["properties"]["cold_warmup_runtime_state_before"] - assert state_schema["properties"]["kind"] == { - "const": report_runner.OTF_RUNTIME_STATE_CENSUS_KIND - } - assert state_schema["properties"]["family_cache_policy"] == { - "const": report_runner.OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY - } - assert state_schema["properties"]["family_cache_limit"] == { - "const": report_runner.OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT - } - assert state_schema["additionalProperties"] is False - assert runtime_profile["properties"][ - "cold_warmup_runtime_retained_after_first_evaluation" - ] == {"const": True} - assert runtime_profile["properties"]["warmup_timer_source"] == { - "const": report_runner.WARMUP_TIMER_SOURCE - } - assert provenance["properties"]["runtime_load_included_in_cold_warmup"] == { - "const": False - } - assert provenance["properties"]["generation_timer_excludes_model_preparation"] == { - "const": True - } - assert set(runtime_profile["dependentRequired"]["cold_warmup_elapsed_seconds"]) == ( - report_runner.OTF_COLD_WARMUP_FIELDS | report_runner.CONVENTIONAL_WARMUP_FIELDS - ) - assert "warmup_elapsed_seconds" not in runtime_profile["dependentRequired"] - - validator = Draft202012Validator(runtime_profile) - validator.validate(_warmup_evidence()) - validator.validate({"warmup_elapsed_seconds": 0.2}) - with pytest.raises(ValidationError): - validator.validate({"cold_warmup_elapsed_seconds": 0.2}) - - recurrence = _recurrence_authority(_otf_cell(Workload.SELECTED_FLOW)) - historical = report_cache.build_reset_cache( - recurrence.dataset_id, - (recurrence,), - ) - historical_measurement = historical["entries"][0]["measurement"] - historical_measurement["status"] = "ok" - historical_measurement["validation"] = {DIRECT_AGREEMENT_FIELD: []} - historical_measurement["provenance"] = { - "runtime_profile": {"warmup_elapsed_seconds": 0.2} - } - Draft202012Validator(schema).validate(historical) - - -@pytest.mark.parametrize("count_field", ("check_count", "component_count")) -def test_otf_compact_summary_rejects_boolean_counts(count_field: str) -> None: - summary = { - "check_count": 1, - "component_count": 1, - "maximum_conditioned_residual": 0.0, - "maximum_absolute_delta": 0.0, - } - summary[count_field] = True - - with pytest.raises(ValueError, match="count"): - report_runner._validate_otf_compact_summary( - summary, - field="test-summary", - expected_checks=1, - expected_components=1, - relative_tolerance=1.0e-12, - ) - - -def test_otf_config_omits_api_bundle_and_materialized_generation_work( - tmp_path: Path, -) -> None: - values = config_values( - _otf_cell(Workload.ALL_FLOW), - RunnerSettings(), - repo_root=tmp_path, - ) - - assert values["generation"]["emit_api_bundle"] is False - assert values["generation"]["relation_discovery"] == {"mode": "off"} - assert values["color"]["lc_flow_layout"] == "topology-replay" - - -@pytest.mark.parametrize("accuracy", (Accuracy.LC, Accuracy.NLC, Accuracy.FULL)) -def test_otf_runtime_identity_uses_the_real_prepared_jit_source_contract( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - accuracy: Accuracy, -) -> None: - import pyamplicol._internal.versions as versions - import pyamplicol.artifacts - - cell = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is accuracy - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload - is (Workload.SELECTED_FLOW if accuracy is Accuracy.LC else Workload.CONTRACTED) - ) - artifact_id = "a" * 64 - revision = "d" * 40 - native_path = tmp_path / "_rusticol.so" - native_path.write_bytes(b"native") - manifest = SimpleNamespace( - artifact_id=artifact_id, - processes=( - { - "id": "process", - "required_runtime_capabilities": [ - "rusticol.on-the-fly.complex-f64.v1", - ( - "rusticol.on-the-fly.lc-color.v1" - if accuracy is Accuracy.LC - else "rusticol.on-the-fly.contracted-color.v1" - ), - ], - }, - ), - runtime={"engine_version": "test"}, - ) - native = SimpleNamespace( - __file__=str(native_path), - native_build_inputs_sha256=lambda: "e" * 64, - target_info=lambda: SimpleNamespace(triple="test", cpu_features=()), - package_version=lambda: "test", - ) - package_tree = {"kind": "tree"} - native_identity = {"kind": "native"} - monkeypatch.setattr( - pyamplicol.artifacts, "load_manifest", lambda *_a, **_k: manifest - ) - monkeypatch.setattr(versions, "verify_native_module", lambda _native: None) - monkeypatch.setattr( - versions, - "_active_build_info", - lambda: { - "schema_version": 1, - "version": "test", - "source_revision": revision, - "publishable": True, - "selftest_fixture_bootstrap": False, - }, - ) - monkeypatch.setattr(report_runner.importlib, "import_module", lambda _name: native) - monkeypatch.setattr( - report_runner, - "established_preimport_runtime_identity", - lambda: { - "kind": "pyamplicol-preimport-runtime-identity-v1", - "python_package_tree": package_tree, - "native_extension": native_identity, - }, - ) - monkeypatch.setattr( - report_runner, - "python_package_tree_identity", - lambda _roots: package_tree, - ) - monkeypatch.setattr( - report_runner, - "loaded_pyamplicol_origin_policy", - lambda *_a, **_k: {"kind": "loaded-origin"}, - ) - - identity = runtime_identity_payload( - cell, - SimpleNamespace(artifact_id=artifact_id, execution_mode="on-the-fly"), - tmp_path, - "process", - expected_source_revision=revision, - ) - - assert identity["expected_evaluator_abi"] == ( - "pyamplicol-runtime-on-the-fly-execution" - ) - assert identity["expected_source_evaluator_abi"] == ( - "pyamplicol-symjit-plane-application-v2" - ) - assert identity["expected_source_evaluator_runtime_capability"] == ( - "symjit.application.complex-f64.v1" - ) diff --git a/pyamplicol/tests/unit/test_on_the_fly_report_render.py b/pyamplicol/tests/unit/test_on_the_fly_report_render.py deleted file mode 100644 index feb733533b..0000000000 --- a/pyamplicol/tests/unit/test_on_the_fly_report_render.py +++ /dev/null @@ -1,460 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -from collections.abc import Mapping - -import pytest - -from tools.performance_report import render as report_render -from tools.performance_report.cache import build_reset_caches -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import Accuracy, ExecutionMode, Workload -from tools.performance_report.render import ( - BaselineCandidateAdapter, - JoinedWorkload, - _fixed_mode_generation_comparison_layout, - _fixed_mode_runtime_comparison_layout, - render_best_mode_table, - render_matrix_table, -) -from tools.performance_report.runner import ( - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD, -) -from tools.performance_report.validation_summary import render_validation_summary - -_POINT_DIGEST = "1" * 64 -_OTF_ARTIFACT_ID = "a" * 64 -_RECURRENCE_ARTIFACT_ID = "b" * 64 -_AMPLICOL_ARTIFACT_ID = "c" * 64 -_SELECTOR_CONTRACT = { - "selected_color_flow_ids": ["flow:2,1"], - "selected_color_words": [[2, 1]], - "all_flow_helicity_ids": ["h:-1,+1,-1"], - "all_flow_source_helicities": {"1": -1, "2": 1, "3": -1}, - "point_digest": _POINT_DIGEST, -} - - -def _cache(caches: dict[str, dict[str, object]], dataset_id: str) -> dict[str, object]: - return next( - payload for payload in caches.values() if payload["dataset_id"] == dataset_id - ) - - -def _set_measurement( - cache: dict[str, object], - *, - process_key: str, - workload: Workload, - generation: float, - wall: float, - cold_warmup: float | None = None, - selector_contract: Mapping[str, object] | None = None, - artifact_id: str = _AMPLICOL_ARTIFACT_ID, - validation: Mapping[str, object] | None = None, -) -> None: - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["process_key"] == process_key - and item["n_final"] == 1 - and item["workload"] == workload.value - and item["variant"] is None - ) - runtime_profile = { - "warmup_elapsed_seconds": 50.0, - } - if cold_warmup is not None: - runtime_profile["cold_warmup_elapsed_seconds"] = cold_warmup - entry["measurement"] = { - "status": "ok", - "generation_seconds": generation, - "wall_seconds_per_point": wall, - "execution_seconds_per_point": wall, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 0.01, - "artifact": {"digest": "test"}, - "selector_contract": copy.deepcopy(selector_contract), - "validation": dict(validation or {"status": "ok"}), - "resources": {"peak_rss_gib": 1.0}, - "provenance": { - "runtime_load_seconds": 100.0, - "runtime_profile": runtime_profile, - "runtime_identity": {"artifact_id": artifact_id}, - }, - "failure": None, - } - - -def _measurement( - cache: dict[str, object], - *, - process_key: str, - workload: Workload, -) -> dict[str, object]: - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["process_key"] == process_key - and item["n_final"] == 1 - and item["workload"] == workload.value - and item["variant"] is None - ) - measurement = entry["measurement"] - assert isinstance(measurement, dict) - return measurement - - -def _pointwise_validation() -> dict[str, object]: - return { - "status": "ok", - "pointwise": { - "status": "ok", - "candidate": 1.0, - "baseline": 1.0, - }, - } - - -@pytest.fixture -def otf_render_caches( - monkeypatch: pytest.MonkeyPatch, -) -> dict[str, dict[str, object]]: - caches = build_reset_caches() - baseline = _cache(caches, "reference_amplicol_lc") - candidate = _cache(caches, "matrix_on_the_fly_builtin_sm_lc") - recurrence = _cache(caches, "matrix_recurrence_builtin_sm_lc") - for workload, baseline_generation, generation, cold_warmup in ( - (Workload.SELECTED_FLOW, 10.0, 4.0, 1.0), - (Workload.ALL_FLOW, 20.0, 6.0, 2.0), - ): - _set_measurement( - baseline, - process_key="dd_z_jets", - workload=workload, - generation=baseline_generation, - wall=10.0e-6, - selector_contract=_SELECTOR_CONTRACT, - ) - _set_measurement( - recurrence, - process_key="dd_z_jets", - workload=workload, - generation=8.0, - wall=2.0e-6, - selector_contract=_SELECTOR_CONTRACT, - artifact_id=_RECURRENCE_ARTIFACT_ID, - ) - _set_measurement( - candidate, - process_key="dd_z_jets", - workload=workload, - generation=generation, - wall=1.0e-6, - cold_warmup=cold_warmup, - selector_contract=_SELECTOR_CONTRACT, - artifact_id=_OTF_ARTIFACT_ID, - validation={ - "status": "ok", - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD: { - "authority": {"artifact_id": _RECURRENCE_ARTIFACT_ID}, - }, - }, - ) - monkeypatch.setattr( - report_render, - "validate_on_the_fly_recurrence_authority_validation_record", - lambda *_args, **_kwargs: None, - ) - return caches - - -def test_otf_fixed_lc_table_pairs_generation_with_only_first_cold_warmup( - otf_render_caches: dict[str, dict[str, object]], -) -> None: - dataset = REPORT_CATALOG.dataset("matrix_on_the_fly_builtin_sm_lc") - tex = render_matrix_table(dataset, otf_render_caches) - row = next(line for line in tex.splitlines() if line.startswith(r"\texttt{1}")) - - assert ( - r"\bestmodecompactprefix{0.400} & " - r"\bestmodeprimaryratio{ReportGreen}{0.500}" - ) in row - assert ( - r"\bestmodecompactabsoluteprefix{6.00} & " - r"\bestmodeabsoluteprimary{8.00}" - ) in row - assert ( - r"\providecommand{\bestmodecompactabsolute}[2]{" - r"\textcolor{ReportMuted}{\texttt{[#1]}}" - r"\hspace{0.04in}\textcolor{black}{\texttt{#2}}}" - ) in tex - assert r"\renewcommand{\arraystretch}{1.00}" in tex - assert "W excludes artifact loading and conventional benchmark warm-ups" in tex - assert "104" not in row - assert "56.0" not in row - - -def test_otf_best_mode_winner_keeps_pair_semantics_and_o_marker( - otf_render_caches: dict[str, dict[str, object]], -) -> None: - tex = render_best_mode_table(Accuracy.LC, otf_render_caches) - row = next(line for line in tex.splitlines() if line.startswith(r"\texttt{1}")) - - assert ( - r"\bestmodecodeprefix{o}\bestmodecompactprefix{0.400} & " - r"\bestmodeprimaryratio{ReportGreen}{0.500}" - ) in row - assert ( - r"\bestmodecompactabsoluteprefix{6.00} & " - r"\bestmodeabsoluteprimary{8.00}" - r"\hspace{0.025in}\bestmodecode{o}" - ) in row - assert "r|c|e|o" in tex - assert "follows the enclosing cold-start contract" in tex - - -@pytest.mark.parametrize("accuracy", (Accuracy.NLC, Accuracy.FULL)) -def test_otf_contracted_best_mode_winner_is_in_row_mix_and_legend( - accuracy: Accuracy, -) -> None: - caches = build_reset_caches() - workload = Workload.CONTRACTED - baseline = _cache(caches, f"reference_amplicol_{accuracy.value}") - recurrence = _cache( - caches, - f"matrix_recurrence_builtin_sm_{accuracy.value}", - ) - candidate = _cache( - caches, - f"matrix_on_the_fly_builtin_sm_{accuracy.value}", - ) - _set_measurement( - baseline, - process_key="dd_z_jets", - workload=workload, - generation=10.0, - wall=10.0e-6, - ) - _set_measurement( - recurrence, - process_key="dd_z_jets", - workload=workload, - generation=8.0, - wall=2.0e-6, - artifact_id=_RECURRENCE_ARTIFACT_ID, - validation=_pointwise_validation(), - ) - _set_measurement( - candidate, - process_key="dd_z_jets", - workload=workload, - generation=4.0, - wall=1.0e-6, - cold_warmup=1.0, - artifact_id=_OTF_ARTIFACT_ID, - validation=_pointwise_validation(), - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - accuracy, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[0].mode is ExecutionMode.ON_THE_FLY - - tex = render_best_mode_table(accuracy, caches) - row = next(line for line in tex.splitlines() if line.startswith(r"\texttt{1}")) - assert ( - r"\bestmodecodeprefix{o}\bestmodecompactprefix{0.400} & " - r"\bestmodeprimaryratio{ReportGreen}{0.500}" - ) in row - assert r"\bestmodemix{r:0|c:0|e:0|o:1}" in tex - assert "Summary mode counts use r|c|e|o" in tex - assert "contracted cold-start contract" in tex - generation_summary = next( - line - for line in tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{\textbf{summary: generation}}") - ) - assert generation_summary.count( - r"\matrixsummaryratio{ReportGreen}{0.500}" - ) == 4 - assert ( - generation_summary.count( - r"\matrixsummaryratiohighlight{ReportGreen}{0.500}" - ) - == 1 - ) - assert "0.400" not in generation_summary - - -def test_otf_amplicol_links_are_metric_and_workload_specific( - otf_render_caches: dict[str, dict[str, object]], -) -> None: - baseline = _cache(otf_render_caches, "reference_amplicol_lc") - for workload in (Workload.SELECTED_FLOW, Workload.ALL_FLOW): - measurement = _measurement( - baseline, - process_key="dd_z_jets", - workload=workload, - ) - selector = measurement["selector_contract"] - assert isinstance(selector, dict) - selector["selected_color_flow_ids"] = ["flow:2,4,3,1"] - selector["selected_color_words"] = [[2, 4, 3, 1]] - - dataset = REPORT_CATALOG.dataset("matrix_on_the_fly_builtin_sm_lc") - family = next( - item for item in REPORT_CATALOG.process_families if item.key == "dd_z_jets" - ) - view = BaselineCandidateAdapter(otf_render_caches).matrix_cell( - dataset, - family, - 1, - ) - selected, all_flow = view.workloads - - assert selected.generation_comparison_linked - assert not selected.comparison_linked - assert all_flow.generation_comparison_linked - assert all_flow.comparison_linked - - selected_generation = _fixed_mode_generation_comparison_layout( - selected, - candidate_mode=ExecutionMode.ON_THE_FLY, - baseline_mode=ExecutionMode.AMPLICOL, - ) - selected_runtime = _fixed_mode_runtime_comparison_layout( - selected, - candidate_mode=ExecutionMode.ON_THE_FLY, - baseline_mode=ExecutionMode.AMPLICOL, - ) - all_flow_runtime = _fixed_mode_runtime_comparison_layout( - all_flow, - candidate_mode=ExecutionMode.ON_THE_FLY, - baseline_mode=ExecutionMode.AMPLICOL, - ) - assert "bestmodecompactratio{0.400}" in selected_generation.inline - assert selected_runtime.inline == r"\texttt{1.00}" - assert "bestmodecompactratio{0.100}" in all_flow_runtime.inline - - fixed_tex = render_matrix_table(dataset, otf_render_caches) - generation_summary = next( - line - for line in fixed_tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{\textbf{summary: generation}}") - ) - assert r"\matrixsummaryratio{ReportGreen}{0.400}" in generation_summary - assert "0.500" not in generation_summary - - best_tex = render_best_mode_table(Accuracy.LC, otf_render_caches) - best_lines = best_tex.splitlines() - generation_index = next( - index - for index, line in enumerate(best_lines) - if line.startswith(r"\texttt{1}") - ) - generation_row = best_lines[generation_index] - runtime_row = best_lines[generation_index + 2] - assert r"\bestmodecodeprefix{o}\bestmodecompactprefix{0.400}" in generation_row - assert r"\bestmodecode{o}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{1.00}}" in runtime_row - assert r"\bestmodecompactprefix{0.100}" in runtime_row - - best_view = BaselineCandidateAdapter(otf_render_caches).best_mode_cell( - Accuracy.LC, - family, - 1, - ) - best_selected, best_all_flow = best_view.workloads - assert best_selected.mode is ExecutionMode.ON_THE_FLY - assert best_selected.generation_comparison_linked - assert not best_selected.comparison_linked - assert best_all_flow.comparison_linked - - best_generation_summary = next( - line - for line in best_lines - if line.startswith(r"\multicolumn{3}{@{}l}{\textbf{summary: generation}}") - ) - assert best_generation_summary.count( - r"\matrixsummaryratio{ReportGreen}{0.500}" - ) == 4 - assert ( - best_generation_summary.count( - r"\matrixsummaryratiohighlight{ReportGreen}{0.500}" - ) - == 1 - ) - assert "0.400" not in best_generation_summary - - -def test_validation_summary_names_otf_recurrence_cross_mode() -> None: - tex = render_validation_summary(build_reset_caches()) - - assert "compiled/eager/OTF versus recurrence" in tex - assert "cross-mode (including OTF/recurrence)" in tex - - -def test_otf_pair_is_provenance_strict_and_never_used_against_recurrence() -> None: - baseline = { - "status": "ok", - "generation_seconds": 10.0, - } - candidate = { - "status": "ok", - "generation_seconds": 4.0, - "provenance": { - "runtime_load_seconds": 100.0, - "runtime_profile": {"cold_warmup_elapsed_seconds": 1.0}, - }, - } - joined = JoinedWorkload( - Workload.SELECTED_FLOW, - baseline, - candidate, - comparison_linked=True, - ) - - recurrence_layout = _fixed_mode_generation_comparison_layout( - joined, - candidate_mode=ExecutionMode.ON_THE_FLY, - baseline_mode=ExecutionMode.RECURRENCE, - ) - assert recurrence_layout.inline == r"\bestmoderatio{ReportGreen}{0.400}" - - missing_cold = copy.deepcopy(candidate) - missing_cold["provenance"]["runtime_profile"].pop( # type: ignore[index] - "cold_warmup_elapsed_seconds" - ) - missing_layout = _fixed_mode_generation_comparison_layout( - JoinedWorkload( - Workload.SELECTED_FLOW, - baseline, - missing_cold, - comparison_linked=True, - ), - candidate_mode=ExecutionMode.ON_THE_FLY, - baseline_mode=ExecutionMode.AMPLICOL, - ) - assert missing_layout.inline == r"\matrixna{ReportMuted}" - - -@pytest.mark.parametrize("accuracy", [Accuracy.NLC, Accuracy.FULL]) -def test_static_otf_color_tables_keep_the_regular_contracted_layout( - accuracy: Accuracy, -) -> None: - caches = build_reset_caches() - dataset = REPORT_CATALOG.dataset(f"matrix_on_the_fly_builtin_sm_{accuracy.value}") - tex = render_matrix_table(dataset, caches) - - assert r"\multicolumn{3}{c}{\textbf{n=1}}" in tex - assert r"\matrixstaticna{ReportMuted}" in tex diff --git a/pyamplicol/tests/unit/test_otf_contracted_parity_gate.py b/pyamplicol/tests/unit/test_otf_contracted_parity_gate.py deleted file mode 100644 index 431d9b2085..0000000000 --- a/pyamplicol/tests/unit/test_otf_contracted_parity_gate.py +++ /dev/null @@ -1,171 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import importlib.util -import json -import sys -from decimal import Decimal -from pathlib import Path -from types import ModuleType - -import pytest - -_GATE_PATH = ( - Path(__file__).resolve().parents[2] - / "tools" - / "developer" - / "otf_contracted_parity_gate.py" -) -_GATE_SPEC = importlib.util.spec_from_file_location( - "test_otf_contracted_parity_gate_module", - _GATE_PATH, -) -if _GATE_SPEC is None or _GATE_SPEC.loader is None: # pragma: no cover - raise RuntimeError("cannot load the OTF contracted parity gate") -gate = importlib.util.module_from_spec(_GATE_SPEC) -_GATE_SPEC.loader.exec_module(gate) - - -def test_authority_and_compact_preflights_precede_evaluation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - events: list[str] = [] - prepared = tmp_path / "prepared-model" - prepared.write_bytes(b"prepared") - point = tmp_path / "point.json" - point.write_text(json.dumps([[1.0, 0.0, 0.0, 1.0]]), encoding="ascii") - recurrence = tmp_path / "recurrence.json" - recurrence.write_text("{}\n", encoding="ascii") - artifact = tmp_path / "artifact" - output = tmp_path / "result.json" - - class FakeCompiledModelSource: - def compile(self) -> object: - events.append("model-compile") - return object() - - class FakeModelSource: - @staticmethod - def from_path(_path: Path) -> FakeCompiledModelSource: - return FakeCompiledModelSource() - - class FakeProcessSet: - @staticmethod - def from_expressions(*_args: object, **_kwargs: object) -> object: - return object() - - class FakeGenerator: - def __init__(self, _config: object) -> None: - pass - - def generate(self, *_args: object, **_kwargs: object) -> None: - events.append("generation") - artifact.mkdir() - - class FakeRuntimeInstance: - execution_mode = "on-the-fly" - - @property - def physics(self) -> object: - raise AssertionError("ordering gate must not materialize dense physics") - - def inspect(self) -> dict[str, object]: - events.append("compact-inspection") - return { - "runtime_metadata": { - "execution_mode": "on-the-fly", - "color_accuracy": "nlc", - } - } - - def evaluate(self, *_args: object, **_kwargs: object) -> tuple[complex, ...]: - events.append("evaluation") - return (1.0 + 0.0j,) - - def clear(self) -> None: - pass - - class FakeRuntime: - @staticmethod - def load(*_args: object, **_kwargs: object) -> FakeRuntimeInstance: - events.append("runtime-load") - return FakeRuntimeInstance() - - package = ModuleType("pyamplicol") - package.__file__ = str(tmp_path / "pyamplicol" / "__init__.py") - package.Generator = FakeGenerator # type: ignore[attr-defined] - package.ModelSource = FakeModelSource # type: ignore[attr-defined] - package.ProcessSet = FakeProcessSet # type: ignore[attr-defined] - package.Runtime = FakeRuntime # type: ignore[attr-defined] - monkeypatch.setitem(sys.modules, "pyamplicol", package) - monkeypatch.setattr(gate.importlib.metadata, "version", lambda _name: "test") - monkeypatch.setattr(gate, "_run_config", lambda *_args: object()) - - def candidate_identity(*_args: object) -> dict[str, object]: - events.append("candidate-authentication") - return { - "version": "test", - "source_revision": None, - "native_build_inputs_sha256": "a" * 64, - } - - def recurrence_target(*_args: object, **_kwargs: object) -> tuple[Decimal, dict]: - events.append("authority-authentication") - return Decimal(1), {"kind": "mock-recurrence-authority"} - - def artifact_preflight(*_args: object, **_kwargs: object) -> dict[str, object]: - events.append("artifact-preflight") - return { - "producer": {"version": "test"}, - "effective_config": {"evaluator_optimization_cores": 4}, - "runtime_options": {"query_construction_threads": 4}, - } - - monkeypatch.setattr(gate, "_candidate_identity", candidate_identity) - monkeypatch.setattr(gate, "_recurrence_target", recurrence_target) - monkeypatch.setattr(gate, "_authenticate_artifact", artifact_preflight) - - assert ( - gate.main( - ( - "--output", - str(output), - "--artifact", - str(artifact), - "--prepared-model", - str(prepared), - "--process", - "g g > g", - "--process-name", - "ordering_gate", - "--n-final", - "1", - "--family-id", - "1", - "--point", - str(point), - "--accuracy", - "nlc", - "--mode", - "on-the-fly", - "--precision", - "16", - "--query-construction-cores", - "4", - "--recurrence-authority", - str(recurrence), - ) - ) - == 0 - ) - assert events == [ - "candidate-authentication", - "authority-authentication", - "model-compile", - "generation", - "artifact-preflight", - "runtime-load", - "compact-inspection", - "evaluation", - ] diff --git a/pyamplicol/tests/unit/test_packaging_hygiene.py b/pyamplicol/tests/unit/test_packaging_hygiene.py index ef7f16a8d2..83a74f57bf 100644 --- a/pyamplicol/tests/unit/test_packaging_hygiene.py +++ b/pyamplicol/tests/unit/test_packaging_hygiene.py @@ -121,22 +121,6 @@ def test_contributor_lock_has_no_local_symjit_source_or_patch_inventory() -> Non assert not tuple((ROOT / "dependencies/patches/symjit").rglob("*.patch")) -def test_nix_shell_provides_python_build_frontend() -> None: - flake = (ROOT / "flake.nix").read_text(encoding="utf-8") - match = re.search( - r"python = pkgs\.python311\.withPackages \(.*?\[(.*?)\]", - flake, - flags=re.DOTALL, - ) - assert match is not None - assert re.search(r"(?m)^\s+build\s*$", match.group(1)) is not None - assert re.search(r"(?m)^\s+m4\s*$", flake) is not None - assert "pkgs.lsof" in flake - assert "pkgs.procps" in flake - assert '"x86_64-darwin"' not in flake - assert re.search(r"(?m)^\s+lhapdf\s*$", flake) is None - - def test_dev_install_keeps_all_build_caches_inside_the_workspace() -> None: justfile = (ROOT / "justfile").read_text(encoding="utf-8") match = re.search( diff --git a/pyamplicol/tests/unit/test_performance_report_aggregate_audit.py b/pyamplicol/tests/unit/test_performance_report_aggregate_audit.py deleted file mode 100644 index d74d6dee6f..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_aggregate_audit.py +++ /dev/null @@ -1,202 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Tests for architecture-report aggregation authentication.""" - -from __future__ import annotations - -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.aggregate_audit import ( - AggregateAuditError, - audit_aggregate_report, -) - - -def _git(repo: Path, *arguments: str) -> str: - return subprocess.run( - ("git", *arguments), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - -def _write(path: Path, value: str) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(value, encoding="utf-8") - - -def _commit(repo: Path, message: str) -> str: - _git(repo, "add", ".") - _git(repo, "commit", "-m", message) - return _git(repo, "rev-parse", "HEAD") - - -def _seed(repo: Path) -> str: - _git(repo, "init") - _git(repo, "config", "user.email", "report@example.invalid") - _git(repo, "config", "user.name", "Report Test") - for profile in ("macbook_M3", "x86_EPYC"): - root = repo / "docs/performance_reports" / profile - _write(root / "README.md", "fixed prose\n") - _write(root / "results/data.json", '{"value":0}\n') - _write(root / "pyAmpliCol.pdf", "reset\n") - _write(repo / "src/runtime.py", "fixed = True\n") - return _commit(repo, "base") - - -def _profile_commit(repo: Path, profile: str, branch: str, value: str) -> str: - _git(repo, "switch", "-c", branch) - root = repo / "docs/performance_reports" / profile - _write(root / "results/data.json", f'{{"value":{value}}}\n') - _write(root / "result_validation_summary.tex", f"summary {value}\n") - _write(root / "pyAmpliCol.pdf", f"pdf {value}\n") - return _commit(repo, profile) - - -def test_accepts_exact_subtrees_from_two_audited_profiles(tmp_path: Path) -> None: - repo = tmp_path / "repo" - repo.mkdir() - base = _seed(repo) - mac = _profile_commit(repo, "macbook_M3", "mac", "1") - _git(repo, "switch", "--detach", base) - x86 = _profile_commit(repo, "x86_EPYC", "x86", "2") - _git(repo, "switch", "-c", "aggregate", mac) - _git(repo, "merge", "--no-ff", "--no-edit", x86) - aggregate = _git(repo, "rev-parse", "HEAD") - - result = audit_aggregate_report( - repo, - base_revision=base, - revision=aggregate, - audited_profiles={"macbook_M3": mac, "x86_EPYC": x86}, - ) - - assert result["status"] == "ok" - assert result["changed_profiles"] == ["macbook_M3", "x86_EPYC"] - - -def test_accepts_audited_profile_after_main_advances_independently( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - repo.mkdir() - measured_source = _seed(repo) - mac = _profile_commit(repo, "macbook_M3", "mac", "1") - _git(repo, "switch", "--detach", measured_source) - _git(repo, "switch", "-c", "advanced-main") - _write(repo / "src/runtime.py", "fixed = 'later-main-change'\n") - landing_base = _commit(repo, "advance main independently") - _git(repo, "merge", "--no-ff", "--no-edit", mac) - aggregate = _git(repo, "rev-parse", "HEAD") - - result = audit_aggregate_report( - repo, - base_revision=landing_base, - revision=aggregate, - audited_profiles={"macbook_M3": mac}, - ) - - assert result["status"] == "ok" - assert result["base_revision"] == landing_base - assert result["changed_profiles"] == ["macbook_M3"] - - -@pytest.mark.parametrize( - ("relative", "mutation"), - ( - ("docs/performance_reports/macbook_M3/README.md", "prose\n"), - ("src/runtime.py", "fixed = False\n"), - ), -) -def test_rejects_non_output_changes( - tmp_path: Path, - relative: str, - mutation: str, -) -> None: - repo = tmp_path / "repo" - repo.mkdir() - base = _seed(repo) - mac = _profile_commit(repo, "macbook_M3", "mac", "1") - _write(repo / relative, mutation) - revision = _commit(repo, "forbidden") - - with pytest.raises( - AggregateAuditError, - match="non-publication output", - ): - audit_aggregate_report( - repo, - base_revision=base, - revision=revision, - audited_profiles={"macbook_M3": mac}, - ) - - -def test_rejects_changed_profile_without_audited_revision(tmp_path: Path) -> None: - repo = tmp_path / "repo" - repo.mkdir() - base = _seed(repo) - mac = _profile_commit(repo, "macbook_M3", "mac", "1") - - with pytest.raises(AggregateAuditError, match="without audited revisions"): - audit_aggregate_report( - repo, - base_revision=base, - revision=mac, - audited_profiles={"x86_EPYC": base}, - ) - - -def test_rejects_profile_subtree_that_differs_from_attestation( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - repo.mkdir() - base = _seed(repo) - mac = _profile_commit(repo, "macbook_M3", "mac", "1") - _write( - repo / "docs/performance_reports/macbook_M3/results/data.json", - '{"value":3}\n', - ) - aggregate = _commit(repo, "tampered") - - with pytest.raises(AggregateAuditError, match="subtree differs"): - audit_aggregate_report( - repo, - base_revision=base, - revision=aggregate, - audited_profiles={"macbook_M3": mac}, - ) - - -def test_rejects_executable_or_deleted_output(tmp_path: Path) -> None: - repo = tmp_path / "repo" - repo.mkdir() - base = _seed(repo) - mac = _profile_commit(repo, "macbook_M3", "mac", "1") - pdf = repo / "docs/performance_reports/macbook_M3/pyAmpliCol.pdf" - pdf.chmod(0o755) - executable = _commit(repo, "executable") - - with pytest.raises(AggregateAuditError, match="non-executable"): - audit_aggregate_report( - repo, - base_revision=base, - revision=executable, - audited_profiles={"macbook_M3": executable}, - ) - - _git(repo, "reset", "--hard", mac) - pdf.unlink() - deleted = _commit(repo, "deleted") - with pytest.raises(AggregateAuditError, match="added or modified"): - audit_aggregate_report( - repo, - base_revision=base, - revision=deleted, - audited_profiles={"macbook_M3": deleted}, - ) diff --git a/pyamplicol/tests/unit/test_performance_report_agreements.py b/pyamplicol/tests/unit/test_performance_report_agreements.py deleted file mode 100644 index 405409baeb..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_agreements.py +++ /dev/null @@ -1,974 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from collections import Counter -from pathlib import Path -from types import SimpleNamespace - -import pytest - -import tools.performance_report.final_audit as final_audit_module -from tools.performance_report.agreements import ( - BUILTIN_UFO_RECURRENCE, - DIRECT_AGREEMENT_FIELD, - DIRECT_AGREEMENT_V2_ABI, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, - LC_CROSS_LAYOUT_COMPONENT, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_COMPARISON_FIELD, - MADGRAPH_FULL_COLOUR, - Z_RECURRENCE_CROSS_MODE, - AgreementError, - agreement_edges, - attach_direct_agreements, - evaluate_lc_common_component, - incoming_agreement_edges, - independent_numerical_authorities, - madgraph_candidate_precision, - madgraph_comparison_record, - requires_independent_numerical_authority, - validation_baseline_is_required, -) -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.cache import ( - build_reset_cache, - empty_measurement, - validate_cache, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.final_audit import ( - FinalAuditError, - _audit_replayed_direct_agreements, - _direct_replay_category, - _ReplayObservation, -) -from tools.performance_report.models import ( - ArtifactPolicy, - ExecutionMode, - ResultStatus, - Workload, -) -from tools.performance_report.runner import ( - SelectorContract, - pointwise_validation, -) -from tools.performance_report.scheduler import CampaignSettings, plan_campaign - - -def _selector() -> dict[str, object]: - return { - "selected_color_flow_ids": ["flow:2,1"], - "selected_color_words": [[2, 1]], - "all_flow_helicity_ids": ["h:-1,+1,-1"], - "all_flow_source_helicities": {"1": -1, "2": 1, "3": -1}, - "point_digest": "a" * 64, - } - - -def _measurement(cell_id: str, value: float, component: float) -> dict[str, object]: - selector = _selector() - return { - "status": ResultStatus.OK.value, - "matrix_element": value, - "selector_contract": selector, - "validation": { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - LC_COMMON_COMPONENT_FIELD: { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell_id, - "value": component, - "point_digest": selector["point_digest"], - "helicity_ids": selector["all_flow_helicity_ids"], - "color_flow_ids": selector["selected_color_flow_ids"], - }, - }, - "failure": None, - } - - -def _cell( - dataset_id: str, - *, - workload: Workload, - variant: str | None = None, -): - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == dataset_id - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is workload - and cell.variant == variant - ) - - -def test_lc_common_component_uses_signed_zero_runtime_alias() -> None: - cell = _cell( - "matrix_recurrence_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - contract = SelectorContract( - selected_color_flow_ids=("flow:2,1",), - selected_color_words=((2, 1),), - all_flow_helicity_ids=("h:-1,+1,-1,+1,-1,0",), - all_flow_source_helicities=( - (1, -1), - (2, 1), - (3, -1), - (4, 1), - (5, -1), - (6, 0), - ), - point_digest="a" * 64, - ) - - class Runtime: - def evaluate_resolved(self, _points: object, **selectors: object) -> object: - assert selectors["helicities"] == ("h:-1,+1,-1,+1,-1,+0",) - return SimpleNamespace( - helicity_ids=("h:-1,+1,-1,+1,-1,+0",), - color_ids=("flow:2,1",), - values=(((1.0 + 0.0j,),),), - ) - - component = evaluate_lc_common_component( - Runtime(), - object(), - cell=cell, - contract=contract, - ) - - assert component["value"] == 1.0 - assert component["helicity_ids"] == ["h:-1,+1,-1,+1,-1,0"] - - -@pytest.mark.parametrize("target_position", (0, 1)) -def test_selected_flow_common_component_selects_full_helicity_axis_by_id( - target_position: int, -) -> None: - cell = _cell("matrix_compiled_builtin_sm_lc", workload=Workload.SELECTED_FLOW) - contract = SelectorContract.from_mapping(_selector()) - helicity_ids = ["h:+1,-1,+1"] - values = [(19.0 + 0.0j,)] - helicity_ids.insert(target_position, contract.runtime_all_flow_helicity_ids[0]) - values.insert(target_position, (7.0 + 0.0j,)) - - class Runtime: - def evaluate_resolved(self, _points: object, **selectors: object) -> object: - assert selectors == { - "precision": 16, - "helicities": None, - "color_flows": contract.selected_color_flow_ids, - } - return SimpleNamespace( - helicity_ids=tuple(helicity_ids), - color_ids=contract.selected_color_flow_ids, - values=(tuple(values),), - ) - - component = evaluate_lc_common_component( - Runtime(), - object(), - cell=cell, - contract=contract, - ) - assert component["value"] == 7.0 - assert component["helicity_ids"] == list(contract.all_flow_helicity_ids) - - -@pytest.mark.parametrize( - ("helicity_ids", "values", "message"), - ( - (("h:+1,-1,+1",), (((1.0,),),), "helicity axis"), - (("h:-1,+1,-1", "h:-1,+1,-1"), (((1.0,), (2.0,)),), "helicity axis"), - (("h:-1,+1,-1", "h:+1,-1,+1"), (((1.0,),),), "not a scalar"), - (("h:-1,+1,-1",), (((1.0, 2.0),),), "not a scalar"), - ), -) -def test_selected_flow_common_component_rejects_invalid_axes_or_shape( - helicity_ids: tuple[str, ...], - values: object, - message: str, -) -> None: - cell = _cell("matrix_compiled_builtin_sm_lc", workload=Workload.SELECTED_FLOW) - contract = SelectorContract.from_mapping(_selector()) - - class Runtime: - def evaluate_resolved(self, _points: object, **_selectors: object) -> object: - return SimpleNamespace( - helicity_ids=helicity_ids, - color_ids=contract.selected_color_flow_ids, - values=values, - ) - - with pytest.raises(AgreementError, match=message): - evaluate_lc_common_component(Runtime(), object(), cell=cell, contract=contract) - - -def test_canonical_n4_direct_agreement_graph_has_exact_locked_counts() -> None: - counts = Counter(edge.kind for edge in agreement_edges(maximum_n_final=4)) - - assert counts == { - BUILTIN_UFO_RECURRENCE: 140, - Z_RECURRENCE_CROSS_MODE: 80, - LC_CROSS_LAYOUT_COMPONENT: 254, - LC_LEGACY_PYAMPLICOL_COMPONENT: 221, - MADGRAPH_FULL_COLOUR: 132, - } - assert Counter( - _direct_replay_category(edge) for edge in agreement_edges(maximum_n_final=4) - ) == { - "fully-replayed-pyamplicol": 441, - "replayed-pyamplicol-vs-authenticated-legacy": 221, - "authenticated-stored-legacy-layout": 33, - "authenticated-stored-madgraph": 132, - } - - -def test_full_direct_agreement_graph_excludes_unavailable_four_line_legacy() -> None: - edges = agreement_edges() - counts = Counter(edge.kind for edge in edges) - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "matrix_recurrence_builtin_sm_lc" - and cell.process_key == "dd_4q_lines" - and cell.n_final == 6 - and cell.workload is Workload.ALL_FLOW - ) - legacy = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "reference_amplicol_lc" - and cell.process_key == "dd_4q_lines" - and cell.n_final == 6 - and cell.workload is Workload.ALL_FLOW - ) - - assert counts == { - BUILTIN_UFO_RECURRENCE: 332, - Z_RECURRENCE_CROSS_MODE: 180, - LC_CROSS_LAYOUT_COMPONENT: 690, - LC_LEGACY_PYAMPLICOL_COMPONENT: 571, - MADGRAPH_FULL_COLOUR: 200, - } - assert {edge.kind for edge in incoming_agreement_edges(candidate)} == { - LC_CROSS_LAYOUT_COMPONENT - } - assert incoming_agreement_edges(legacy) == () - - measurable_ids = { - cell.cell_id - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is None - } - measurable_edges = tuple( - edge - for edge in edges - if edge.candidate.cell_id in measurable_ids - and edge.baseline.cell_id in measurable_ids - ) - assert Counter(edge.kind for edge in measurable_edges) == { - BUILTIN_UFO_RECURRENCE: 332, - Z_RECURRENCE_CROSS_MODE: 156, - LC_CROSS_LAYOUT_COMPONENT: 678, - LC_LEGACY_PYAMPLICOL_COMPONENT: 559, - MADGRAPH_FULL_COLOUR: 200, - } - assert Counter(_direct_replay_category(edge) for edge in measurable_edges) == { - "fully-replayed-pyamplicol": 1063, - "replayed-pyamplicol-vs-authenticated-legacy": 559, - "authenticated-stored-legacy-layout": 103, - "authenticated-stored-madgraph": 200, - } - - -@pytest.mark.parametrize( - "process_key", - ("dd_3q_lines", "dd_3q_identical_lines"), -) -def test_three_line_lc_keeps_optional_legacy_and_required_layout_agreements( - process_key: str, -) -> None: - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "matrix_recurrence_builtin_sm_lc" - and cell.process_key == process_key - and cell.n_final == 4 - and cell.workload is Workload.ALL_FLOW - ) - - edges = incoming_agreement_edges(candidate) - assert {edge.kind for edge in edges} == { - LC_CROSS_LAYOUT_COMPONENT, - LC_LEGACY_PYAMPLICOL_COMPONENT, - } - assert {edge.kind for edge in edges if edge.required} == {LC_CROSS_LAYOUT_COMPONENT} - assert {edge.kind for edge in edges if not edge.required} == { - LC_LEGACY_PYAMPLICOL_COMPONENT - } - - -def test_optional_legacy_agreement_can_be_absent_but_required_layout_cannot() -> None: - candidate = _cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - edges = incoming_agreement_edges(candidate) - layout = next(edge for edge in edges if edge.required) - topology = _measurement(layout.baseline.cell_id, 1.0, 0.25) - union = _measurement(candidate.cell_id, 1.0, 0.25) - - attach_direct_agreements( - candidate, - union, - {layout.baseline.cell_id: topology}, - ) - - assert union["status"] == ResultStatus.OK.value - assert [ - record["edge_kind"] for record in union["validation"][DIRECT_AGREEMENT_FIELD] - ] == [LC_CROSS_LAYOUT_COMPONENT] - - missing_required = _measurement(candidate.cell_id, 1.0, 0.25) - with pytest.raises(RuntimeError, match="direct-agreement peers differ"): - attach_direct_agreements(candidate, missing_required, {}) - - -@pytest.mark.parametrize("mismatch", (False, True)) -def test_unverified_candidate_still_enforces_hard_direct_agreement( - mismatch: bool, -) -> None: - candidate = _cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - edge = next(item for item in incoming_agreement_edges(candidate) if item.required) - component = 0.25 - measurement = _measurement( - candidate.cell_id, - 1.0, - component + (5.0e-9 if mismatch else 0.0), - ) - measurement["status"] = ResultStatus.UNVERIFIED.value - measurement["validation"]["status"] = ResultStatus.UNVERIFIED.value - measurement["failure"] = { - "kind": "IndependentAuthorityUnavailable", - "message": "no successful independent numerical authority", - } - - attach_direct_agreements( - candidate, - measurement, - {edge.baseline.cell_id: _measurement(edge.baseline.cell_id, 1.0, component)}, - ) - - expected = ( - ResultStatus.VALIDATION_FAILED.value - if mismatch - else ResultStatus.UNVERIFIED.value - ) - assert measurement["status"] == expected - assert measurement["validation"]["status"] == expected - if mismatch: - assert measurement["failure"]["kind"] == "MeasurementValidationError" - else: - assert measurement["failure"]["kind"] == "IndependentAuthorityUnavailable" - - -def test_ufo_recurrence_can_pass_independent_oracle_and_fail_direct_edge() -> None: - candidate = _cell( - "matrix_recurrence_ufo_sm_lc", - workload=Workload.SELECTED_FLOW, - ) - edge = incoming_agreement_edges(candidate)[0] - independent = 1.0 - builtin = _measurement(edge.baseline.cell_id, 1.0, 0.25) - ufo = _measurement(candidate.cell_id, 1.0 + 5.0e-9, 0.25) - - assert ( - pointwise_validation( - float(builtin["matrix_element"]), - independent, - relative_tolerance=1.0e-8, - )["status"] - == ResultStatus.OK.value - ) - assert ( - pointwise_validation( - float(ufo["matrix_element"]), - independent, - relative_tolerance=1.0e-8, - )["status"] - == ResultStatus.OK.value - ) - - attach_direct_agreements( - candidate, - ufo, - {edge.baseline.cell_id: builtin}, - ) - - assert ufo["status"] == ResultStatus.VALIDATION_FAILED.value - record = ufo["validation"][DIRECT_AGREEMENT_FIELD][0] - assert record["edge_kind"] == BUILTIN_UFO_RECURRENCE - assert record["abi"] == DIRECT_AGREEMENT_V2_ABI - assert record["relative_tolerance"] == 1.0e-12 - assert record["error_bound"] == pytest.approx(1.0e-12) - assert record["status"] == ResultStatus.VALIDATION_FAILED.value - - -def test_z_timing_baseline_stays_amplicol_but_numerics_consume_recurrence() -> None: - candidate = _cell( - "z_builtin_sm", - workload=Workload.SELECTED_FLOW, - variant="jit_o1", - ) - timing_baseline = REPORT_CATALOG.baseline_cell(candidate) - assert timing_baseline is not None - assert timing_baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - edge = incoming_agreement_edges(candidate)[0] - assert edge.kind == Z_RECURRENCE_CROSS_MODE - assert edge.baseline.variant == "recurrence_jit_o2" - - amplicol_value = 1.0 - recurrence = _measurement(edge.baseline.cell_id, 1.0, 0.25) - compiled = _measurement(candidate.cell_id, 1.0 + 5.0e-9, 0.25) - assert ( - pointwise_validation( - float(compiled["matrix_element"]), - amplicol_value, - relative_tolerance=1.0e-8, - )["status"] - == ResultStatus.OK.value - ) - - attach_direct_agreements( - candidate, - compiled, - {edge.baseline.cell_id: recurrence}, - ) - - assert compiled["status"] == ResultStatus.VALIDATION_FAILED.value - record = compiled["validation"][DIRECT_AGREEMENT_FIELD][0] - assert record["edge_kind"] == Z_RECURRENCE_CROSS_MODE - assert record["baseline_cell_id"] == edge.baseline.cell_id - - -def test_cross_layout_component_failure_is_not_hidden_by_equal_totals() -> None: - candidate = _cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - edges = incoming_agreement_edges(candidate) - edge = next(item for item in edges if item.kind == LC_CROSS_LAYOUT_COMPONENT) - legacy_edge = next( - item for item in edges if item.kind == LC_LEGACY_PYAMPLICOL_COMPONENT - ) - topology = _measurement(edge.baseline.cell_id, 1.0, 0.25) - union = _measurement(candidate.cell_id, 1.0, 0.25 + 5.0e-9) - legacy = _measurement( - legacy_edge.baseline.cell_id, - 1.0, - 0.25 + 5.0e-9, - ) - - attach_direct_agreements( - candidate, - union, - { - edge.baseline.cell_id: topology, - legacy_edge.baseline.cell_id: legacy, - }, - ) - - assert topology["matrix_element"] == union["matrix_element"] - assert union["status"] == ResultStatus.VALIDATION_FAILED.value - assert ( - next( - record - for record in union["validation"][DIRECT_AGREEMENT_FIELD] - if record["edge_kind"] == LC_CROSS_LAYOUT_COMPONENT - )["value_kind"] - == LC_COMMON_COMPONENT_FIELD - ) - - -def test_final_replay_checks_cross_layout_component_not_only_totals() -> None: - candidate = _cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - edge = incoming_agreement_edges(candidate)[0] - topology = _measurement(edge.baseline.cell_id, 1.0, 0.25) - union = _measurement(candidate.cell_id, 1.0, 0.25) - replayed = { - edge.baseline.cell_id: _ReplayObservation(1.0, 0.0, 0.0, 0.25), - candidate.cell_id: _ReplayObservation( - 1.0, - 0.0, - 0.0, - 0.25 + 5.0e-9, - ), - } - - with pytest.raises(FinalAuditError, match="direct-edge replay failed"): - _audit_replayed_direct_agreements( - (edge,), - { - edge.baseline.cell_id: topology, - candidate.cell_id: union, - }, - replayed, - ) - - -def test_legacy_pyamplicol_component_uses_independent_tolerance() -> None: - candidate = _cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - edges = incoming_agreement_edges(candidate) - layout = next(edge for edge in edges if edge.kind == LC_CROSS_LAYOUT_COMPONENT) - legacy = next(edge for edge in edges if edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT) - observed = 1.0 + 5.0e-9 - measurement = _measurement(candidate.cell_id, 1.0, observed) - - attach_direct_agreements( - candidate, - measurement, - { - layout.baseline.cell_id: _measurement( - layout.baseline.cell_id, - 1.0, - observed, - ), - legacy.baseline.cell_id: _measurement( - legacy.baseline.cell_id, - 1.0, - 1.0, - ), - }, - ) - - record = next( - item - for item in measurement["validation"][DIRECT_AGREEMENT_FIELD] - if item["edge_kind"] == LC_LEGACY_PYAMPLICOL_COMPONENT - ) - assert measurement["status"] == ResultStatus.OK.value - assert record["relative_tolerance"] == 1.0e-8 - assert record["abi"] == DIRECT_AGREEMENT_V2_ABI - assert record["error_bound"] == pytest.approx(1.0e-8) - - -def test_legacy_amplicol_mismatch_is_retained_without_failing_candidate() -> None: - candidate = _cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - edges = incoming_agreement_edges(candidate) - layout = next(edge for edge in edges if edge.kind == LC_CROSS_LAYOUT_COMPONENT) - legacy = next(edge for edge in edges if edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT) - observed = 1.0 + 5.0e-7 - measurement = _measurement(candidate.cell_id, 1.0, observed) - - peers = { - layout.baseline.cell_id: _measurement( - layout.baseline.cell_id, - 1.0, - observed, - ), - legacy.baseline.cell_id: _measurement( - legacy.baseline.cell_id, - 1.0, - 1.0, - ), - } - attach_direct_agreements( - candidate, - measurement, - peers, - ) - - record = next( - item - for item in measurement["validation"][DIRECT_AGREEMENT_FIELD] - if item["edge_kind"] == LC_LEGACY_PYAMPLICOL_COMPONENT - ) - assert record["status"] == ResultStatus.VALIDATION_FAILED.value - assert measurement["status"] == ResultStatus.OK.value - assert measurement["validation"]["status"] == ResultStatus.OK.value - - audited, counts = final_audit_module._audit_direct_agreements( - (candidate,), - {candidate.cell_id: measurement, **peers}, - catalog=REPORT_CATALOG, - ) - assert counts[LC_LEGACY_PYAMPLICOL_COMPONENT] == 1 - replayed = { - candidate.cell_id: _ReplayObservation(1.0, 0.0, 0.0, observed), - layout.baseline.cell_id: _ReplayObservation(1.0, 0.0, 0.0, observed), - } - replay_counts = _audit_replayed_direct_agreements( - audited, - {candidate.cell_id: measurement, **peers}, - replayed, - ) - assert replay_counts["replayed-pyamplicol-vs-authenticated-legacy"] == 1 - - replayed[candidate.cell_id] = _ReplayObservation(1.0, 0.0, 0.0, 1.0) - with pytest.raises(FinalAuditError, match="stored candidate"): - _audit_replayed_direct_agreements( - audited, - {candidate.cell_id: measurement, **peers}, - replayed, - ) - - -@pytest.mark.parametrize( - ("dataset_id", "candidate_precision"), - ( - ("matrix_compiled_ufo_sm_full", 200), - ("matrix_on_the_fly_ufo_sm_full", 16), - ), -) -def test_madgraph_candidate_precision_is_authenticated_and_authority_not_replayed( - dataset_id: str, - candidate_precision: int, -) -> None: - candidate = _cell( - dataset_id, - workload=Workload.CONTRACTED, - ) - edge = next( - edge - for edge in incoming_agreement_edges(candidate) - if edge.kind == MADGRAPH_FULL_COLOUR - ) - baseline = _measurement(edge.baseline.cell_id, 1.0, 0.0) - measurement = _measurement(candidate.cell_id, 1.0, 0.0) - for value in (baseline, measurement): - value["selector_contract"] = None - validation = value["validation"] - assert isinstance(validation, dict) - validation.pop(LC_COMMON_COMPONENT_FIELD) - validation["point_digest"] = _selector()["point_digest"] - validation = measurement["validation"] - assert isinstance(validation, dict) - validation[MADGRAPH_COMPARISON_FIELD] = madgraph_comparison_record( - edge, - candidate=1.0 + 5.0e-12, - baseline_measurement=baseline, - point_identity=_selector()["point_digest"], - ) - assert madgraph_candidate_precision(candidate) == candidate_precision - assert ( - validation[MADGRAPH_COMPARISON_FIELD]["candidate_precision"] - == candidate_precision - ) - attach_direct_agreements( - candidate, - measurement, - {edge.baseline.cell_id: baseline}, - ) - - audited, counts = final_audit_module._audit_direct_agreements( - (candidate,), - {candidate.cell_id: measurement, edge.baseline.cell_id: baseline}, - catalog=REPORT_CATALOG, - ) - assert counts[MADGRAPH_FULL_COLOUR] == 1 - replay_counts = _audit_replayed_direct_agreements( - audited, - {candidate.cell_id: measurement, edge.baseline.cell_id: baseline}, - {candidate.cell_id: _ReplayObservation(1.0, 0.0, 0.0, None)}, - ) - assert replay_counts["authenticated-stored-madgraph"] == 1 - - with pytest.raises(FinalAuditError, match=rf"stored p{candidate_precision}"): - _audit_replayed_direct_agreements( - audited, - {candidate.cell_id: measurement, edge.baseline.cell_id: baseline}, - { - candidate.cell_id: _ReplayObservation( - 1.0 + 5.0e-9, - 0.0, - 0.0, - None, - ) - }, - ) - - -def test_replay_categories_are_explicit_and_missing_endpoints_fail_closed() -> None: - edges = agreement_edges(maximum_n_final=1) - pac_pac = next( - edge - for edge in edges - if edge.baseline.measurement.execution_mode is not ExecutionMode.AMPLICOL - and edge.candidate.measurement.execution_mode is not ExecutionMode.AMPLICOL - ) - pac_legacy = next( - edge for edge in edges if edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT - ) - legacy_layout = next( - edge - for edge in edges - if edge.kind == LC_CROSS_LAYOUT_COMPONENT - and edge.candidate.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - selected = (pac_pac, pac_legacy, legacy_layout) - cells = { - endpoint.cell_id: endpoint - for edge in selected - for endpoint in (edge.baseline, edge.candidate) - } - measurements = {cell_id: _measurement(cell_id, 1.0, 1.0) for cell_id in cells} - attach_direct_agreements( - pac_legacy.candidate, - measurements[pac_legacy.candidate.cell_id], - { - pac_pac.baseline.cell_id: measurements[pac_pac.baseline.cell_id], - pac_legacy.baseline.cell_id: measurements[pac_legacy.baseline.cell_id], - }, - ) - attach_direct_agreements( - legacy_layout.candidate, - measurements[legacy_layout.candidate.cell_id], - { - legacy_layout.baseline.cell_id: measurements[ - legacy_layout.baseline.cell_id - ], - }, - ) - replayed = { - cell_id: _ReplayObservation(1.0, 0.0, 0.0, 1.0) - for cell_id, cell in cells.items() - if cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - } - - counts = _audit_replayed_direct_agreements( - selected, - measurements, - replayed, - ) - - assert sorted(counts.values()) == [0, 1, 1, 1] - missing = dict(replayed) - missing.pop(pac_pac.baseline.cell_id) - with pytest.raises(FinalAuditError, match="missing its required pyAmpliCol replay"): - _audit_replayed_direct_agreements( - selected, - measurements, - missing, - ) - - -def _cache_measurement(cell_id: str) -> dict[str, object]: - compact = _measurement(cell_id, 1.0, 1.0) - result = empty_measurement() - result.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": {}, - "selector_contract": compact["selector_contract"], - "validation": compact["validation"], - "resources": {}, - "provenance": {}, - } - ) - return result - - -def test_cache_admission_requires_agreement_and_lc_component_evidence() -> None: - cell = _cell( - "reference_amplicol_lc", - workload=Workload.SELECTED_FLOW, - ) - measurement = _cache_measurement(cell.cell_id) - cache = build_reset_cache(cell.dataset_id, (cell,)) - cache["entries"][0]["measurement"] = measurement - validate_cache(cache, expected_cells=(cell,)) - - validation = measurement["validation"] - assert isinstance(validation, dict) - direct = validation.pop(DIRECT_AGREEMENT_FIELD) - with pytest.raises(ValueError, match=DIRECT_AGREEMENT_FIELD): - validate_cache(cache, expected_cells=(cell,)) - validation[DIRECT_AGREEMENT_FIELD] = direct - validation.pop(LC_COMMON_COMPONENT_FIELD) - with pytest.raises(ValueError, match=LC_COMMON_COMPONENT_FIELD): - validate_cache(cache, expected_cells=(cell,)) - - -def test_campaign_plan_keeps_z_numerical_peers_availability_optional( - tmp_path: Path, -) -> None: - candidate = _cell( - "z_external_sm", - workload=Workload.ALL_FLOW, - variant="jit_o1", - ) - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(artifact_policy=ArtifactPolicy.REGENERATE), - ) - by_id = {item.cell.cell_id: item for item in planned} - target = by_id[candidate.cell_id] - baseline = REPORT_CATALOG.validation_baseline_cell(candidate) - assert baseline is not None - - edges = incoming_agreement_edges(candidate) - assert validation_baseline_is_required(candidate, baseline) is False - authorities = independent_numerical_authorities(candidate) - assert tuple(authority.measurement.execution_mode for authority in authorities) == ( - ExecutionMode.RECURRENCE, - ) - assert target.baseline_cell_id is None - assert target.optional_baseline_cell_id == baseline.cell_id - assert baseline.cell_id not in by_id - assert set(target.comparison_peer_ids) == { - edge.baseline.cell_id for edge in edges if edge.required - } - assert set(target.optional_comparison_peer_ids) == { - edge.baseline.cell_id for edge in edges if not edge.required - } - assert target.numerical_authority_cell_ids == tuple( - authority.cell_id for authority in authorities - ) - assert set(by_id) == {candidate.cell_id, *target.comparison_peer_ids} - assert not {authority.cell_id for authority in authorities}.intersection(by_id) - - -def test_all_z_compiled_and_eager_cells_use_optional_ordered_authorities( - tmp_path: Path, -) -> None: - candidates = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id.startswith("z_") - and cell.measurement.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - ) - - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - static_count = 0 - runnable_count = 0 - assert len(candidates) == 180 - for candidate in candidates: - baseline = REPORT_CATALOG.validation_baseline_cell(candidate) - authorities = independent_numerical_authorities(candidate) - assert baseline is not None - assert baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - assert validation_baseline_is_required(candidate, baseline) is False - assert tuple( - authority.measurement.execution_mode for authority in authorities - ) == (ExecutionMode.RECURRENCE,) - assert any( - edge.kind == Z_RECURRENCE_CROSS_MODE - and not edge.required - and edge.baseline == authorities[0] - for edge in incoming_agreement_edges(candidate) - ) - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(), - ) - if REPORT_CATALOG.static_na_reason(candidate) is not None: - static_count += 1 - assert planned == () - continue - runnable_count += 1 - by_id = {item.cell.cell_id: item for item in planned} - target = by_id[candidate.cell_id] - assert baseline.cell_id not in by_id - assert target.numerical_authority_cell_ids == tuple( - authority.cell_id for authority in authorities - ) - assert set(by_id) == {candidate.cell_id, *target.comparison_peer_ids} - assert not {authority.cell_id for authority in authorities}.intersection(by_id) - - assert (runnable_count, static_count) == (156, 24) - - -def test_catalog_wide_independent_authority_policy_matches_surface_semantics() -> None: - cells = REPORT_CATALOG.measurement_cells() - authority_required = tuple( - cell for cell in cells if requires_independent_numerical_authority(cell) - ) - standalone_compiled = tuple( - cell - for cell in cells - if cell.measurement.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - and not requires_independent_numerical_authority(cell) - ) - - assert len(authority_required) == 808 - assert all( - cell.measurement.execution_mode in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - for cell in authority_required - ) - assert len(standalone_compiled) == 110 - assert {cell.dataset_id for cell in standalone_compiled} == { - "matrix_compiled_ufo_sm_full", - "matrix_eager_ufo_sm_full", - "scalar_contact", - "scalar_gravity", - } - assert all( - not requires_independent_numerical_authority(cell) - for cell in cells - if cell.measurement.execution_mode - not in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - ) - - -def test_canonical_n4_plan_keeps_bounded_acyclic_dependency_depth( - tmp_path: Path, -) -> None: - selected = tuple( - cell for cell in REPORT_CATALOG.measurement_cells() if cell.n_final <= 4 - ) - planned = plan_campaign( - selected, - store=ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ), - settings=CampaignSettings(artifact_policy=ArtifactPolicy.REGENERATE), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert len(planned) == len(by_id) == 1042 - assert max(item.rank for item in planned) == 4 - for item in planned: - dependency_ids = set(item.comparison_peer_ids) - if item.baseline_cell_id is not None: - dependency_ids.add(item.baseline_cell_id) - assert all( - dependency_id in by_id and by_id[dependency_id].rank < item.rank - for dependency_id in dependency_ids - ) diff --git a/pyamplicol/tests/unit/test_performance_report_artifacts.py b/pyamplicol/tests/unit/test_performance_report_artifacts.py deleted file mode 100644 index d19f97bc51..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_artifacts.py +++ /dev/null @@ -1,673 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import multiprocessing -import shutil -from pathlib import Path -from queue import Empty -from typing import Any - -import pytest - -from tools.performance_report.artifacts import ( - ATTEMPT_SCHEMA, - CURRENT_SCHEMA, - PORTABLE_CURRENT_SCHEMA, - ArtifactAction, - ArtifactStore, - ArtifactStoreError, - LockTimeoutError, - ManifestValidationError, -) -from tools.performance_report.models import ArtifactPolicy -from tools.performance_report.service import ReportPaths - - -def _store(tmp_path: Path) -> ArtifactStore: - return ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "coordination", - ) - - -def _portable_store(campaign: Path, *, repo: Path) -> ArtifactStore: - artifact_root = campaign / "campaign_artifacts" - paths = ReportPaths( - repo_root=repo, - docs_dir=campaign, - results_dir=campaign / "results", - artifact_root=artifact_root, - coordination_root=artifact_root / "coordination", - ) - return ArtifactStore( - artifact_root=paths.artifact_root, - lock_root=paths.coordination_root, - current_publication_paths=paths, - ) - - -def _canonical_bytes(payload: dict[str, Any]) -> bytes: - return ( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ).encode() - - -def _rewrite_json(path: Path, payload: dict[str, Any]) -> None: - path.write_bytes(_canonical_bytes(payload)) - - -def _rewrite_pointer_digest(pointer_path: Path, manifest_path: Path) -> None: - pointer = json.loads(pointer_path.read_text(encoding="utf-8")) - pointer["manifest_sha256"] = hashlib.sha256(manifest_path.read_bytes()).hexdigest() - _rewrite_json(pointer_path, pointer) - - -def _try_named_lock( - artifact_root: str, - lock_root: str, - queue: multiprocessing.Queue[str], -) -> None: - store = ArtifactStore( - artifact_root=Path(artifact_root), - lock_root=Path(lock_root), - ) - try: - with store.named_lock("prepared-ufo", timeout=0.1, poll_interval=0.01): - queue.put("acquired") - except LockTimeoutError: - queue.put("timeout") - - -def test_successful_attempt_is_uuid_qualified_and_published_atomically( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("matrix/row:1", ArtifactPolicy.REGENERATE) - artifact = attempt.path("payload/process.bin") - artifact.write_bytes(b"compiled process") - - current = attempt.publish( - {"status": "ok", "wall_seconds": 1.25}, - artifact_paths=("payload/process.bin",), - ) - - assert attempt.root.name == attempt.attempt_id - assert attempt.root.parent.name == "attempts" - assert current.cell_id == "matrix/row:1" - assert current.result == {"status": "ok", "wall_seconds": 1.25} - assert {entry.relative_path for entry in current.artifacts} == { - "payload/process.bin", - "result.json", - } - pointer = json.loads( - (attempt.root.parent.parent / "current.json").read_text(encoding="utf-8") - ) - assert pointer["schema"] == CURRENT_SCHEMA - assert pointer["manifest_path"] == ( - f"attempts/{attempt.attempt_id}/manifest.json" - ) - assert not list(attempt.root.rglob("*.tmp-*")) - - -def test_portable_current_bytes_survive_campaign_move_and_materialize( - tmp_path: Path, -) -> None: - repo = tmp_path / "source" - repo.mkdir() - campaign_a = tmp_path / "parent-a" / "manual-a" - store_a = _portable_store(campaign_a, repo=repo) - attempt = store_a.new_attempt("cell", ArtifactPolicy.REGENERATE) - artifact = attempt.path("artifact") - artifact.mkdir() - (artifact / "payload.bin").write_bytes(b"payload") - identity = {"native_extension": {"path": "/authenticated/runtime.so"}} - current_a = attempt.publish( - { - "status": "ok", - "artifact": {"path": str(artifact)}, - "provenance": { - "worker_log": str(attempt.root / "worker.log"), - "runtime_identity": identity, - "runtime_identity_sha256": hashlib.sha256( - json.dumps( - identity, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest(), - }, - }, - artifact_paths=("artifact/payload.bin",), - ) - stored = json.loads((attempt.root / "result.json").read_text()) - pointer = json.loads( - (attempt.root.parent.parent / "current.json").read_text(encoding="utf-8") - ) - assert pointer["schema"] == PORTABLE_CURRENT_SCHEMA - assert stored["artifact"]["path"].startswith( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - assert stored["provenance"]["worker_log"].startswith( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - assert stored["provenance"]["runtime_identity"] == identity - - campaign_b = tmp_path / "parent-b" / "renamed-campaign" - campaign_b.parent.mkdir() - campaign_a.rename(campaign_b) - store_b = _portable_store(campaign_b, repo=repo) - - current_b = store_b.load_current("cell") - lightweight = store_b.lightweight_current_payload("cell") - assert current_b is not None - assert lightweight is not None - expected_artifact = current_b.result_path.parent / "artifact" - assert current_b.result["artifact"]["path"] == str(expected_artifact) - assert lightweight[1]["artifact"]["path"] == str(expected_artifact) - assert current_b.manifest_sha256 == current_a.manifest_sha256 - - -def test_portable_store_rejects_old_absolute_current_without_migration( - tmp_path: Path, -) -> None: - repo = tmp_path / "source" - repo.mkdir() - campaign = tmp_path / "manual" - artifact_root = campaign / "campaign_artifacts" - ordinary = ArtifactStore( - artifact_root=artifact_root, - lock_root=artifact_root / "coordination", - ) - attempt = ordinary.new_attempt("cell", ArtifactPolicy.REGENERATE) - artifact = attempt.path("artifact") - artifact.mkdir() - attempt.publish({"artifact": {"path": str(artifact)}}) - - portable = _portable_store(campaign, repo=repo) - with pytest.raises(ManifestValidationError, match="current pointer schema"): - portable.load_current("cell") - with pytest.raises(ManifestValidationError, match="unsupported shape"): - portable.lightweight_current_payload("cell") - - -def test_portable_store_rejects_artifactless_legacy_terminal_current( - tmp_path: Path, -) -> None: - repo = tmp_path / "source" - repo.mkdir() - campaign = tmp_path / "manual" - artifact_root = campaign / "campaign_artifacts" - ordinary = ArtifactStore( - artifact_root=artifact_root, - lock_root=artifact_root / "coordination", - ) - attempt = ordinary.new_attempt("cell", ArtifactPolicy.REGENERATE) - attempt.publish({"status": "memory_limit", "artifact": None}) - - portable = _portable_store(campaign, repo=repo) - with pytest.raises(ManifestValidationError, match="current pointer schema"): - portable.load_current("cell") - with pytest.raises(ManifestValidationError, match="unsupported shape"): - portable.lightweight_current_payload("cell") - - -def test_failed_and_interrupted_attempts_cannot_replace_valid_current( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - first = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - original = first.publish({"sequence": 1}) - - failed = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - failed.mark_failed("backend failed") - interrupted = store.new_attempt("cell", ArtifactPolicy.RETIME, based_on=original) - interrupted.mark_interrupted("worker was terminated") - - current = store.load_current("cell") - assert current is not None - assert current.attempt_id == original.attempt_id - assert current.result == {"sequence": 1} - assert json.loads( - (failed.root / "manifest.json").read_text(encoding="utf-8") - )["status"] == "failed" - assert json.loads( - (interrupted.root / "manifest.json").read_text(encoding="utf-8") - )["status"] == "interrupted" - - -def _sealed_failed_worker_result( - store: ArtifactStore, - *, - cell_id: str = "cell", -) -> tuple[str, Path]: - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json( - "worker-result.json", - {"status": "unverified", "marker": "diagnostic"}, - ) - attempt.mark_failed( - "independent authority unavailable", - artifact_paths=("worker-result.json",), - ) - return attempt.attempt_id, attempt.root - - -def test_named_unsuccessful_result_loads_only_authenticated_live_or_archive( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - attempt_id, root = _sealed_failed_worker_result(store) - - assert store.load_sealed_unsuccessful_worker_result("cell", attempt_id) == { - "status": "unverified", - "marker": "diagnostic", - } - - assert store.archive_obsolete_attempts("cell", consumer_cell_ids=()) == ( - attempt_id, - ) - assert not root.exists() - assert store.load_sealed_unsuccessful_worker_result("cell", attempt_id) == { - "status": "unverified", - "marker": "diagnostic", - } - - -def test_archived_unsuccessful_result_ignores_only_pruned_heavy_payload( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - attempt.write_json( - "worker-result.json", - {"status": "unverified", "marker": "retained"}, - ) - attempt.path("artifact/native/payload.bin").write_bytes(b"heavy") - attempt.mark_failed( - "independent authority unavailable", - artifact_paths=("worker-result.json", "artifact/native/payload.bin"), - ) - - assert store.archive_obsolete_attempts("cell", consumer_cell_ids=()) == ( - attempt.attempt_id, - ) - archived = store._attempt_history_cell_root("cell") / attempt.attempt_id - assert not (archived / "artifact").exists() - assert store.load_sealed_unsuccessful_worker_result( - "cell", - attempt.attempt_id, - ) == {"status": "unverified", "marker": "retained"} - -def test_named_unsuccessful_result_rejects_collisions_and_tampering( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - attempt_id, live = _sealed_failed_worker_result(store) - archived = store._attempt_history_cell_root("cell") / attempt_id - archived.parent.mkdir(parents=True) - shutil.copytree(live, archived) - - with pytest.raises(ManifestValidationError, match="colliding locations"): - store.load_sealed_unsuccessful_worker_result("cell", attempt_id) - - shutil.rmtree(archived) - worker_result = live / "worker-result.json" - worker_result.write_text('{"status":"ok"}\n', encoding="utf-8") - with pytest.raises( - ManifestValidationError, - match=r"artifact (size|digest) mismatch", - ): - store.load_sealed_unsuccessful_worker_result("cell", attempt_id) - - -@pytest.mark.parametrize("location", ("live", "archive")) -def test_named_unsuccessful_result_rejects_symlinked_inventory_ancestors( - tmp_path: Path, - location: str, -) -> None: - store = _store(tmp_path) - attempt_id, _root = _sealed_failed_worker_result(store) - if location == "live": - inventory = store._cell_root("cell") / "attempts" - else: - store.archive_obsolete_attempts("cell", consumer_cell_ids=()) - inventory = store._attempt_history_cell_root("cell") - external = tmp_path / f"external-{location}" - inventory.replace(external) - inventory.symlink_to(external, target_is_directory=True) - - with pytest.raises(ManifestValidationError, match="symbolic link"): - store.load_sealed_unsuccessful_worker_result("cell", attempt_id) - - -def test_attempt_context_records_interruption_without_masking_exception( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - with ( - pytest.raises(RuntimeError, match="deliberate"), - store.new_attempt("cell", ArtifactPolicy.REGENERATE) as attempt, - ): - raise RuntimeError("deliberate") - - manifest = json.loads( - (attempt.root / "manifest.json").read_text(encoding="utf-8") - ) - assert manifest["status"] == "interrupted" - assert manifest["error"] == "RuntimeError: deliberate" - assert store.load_current("cell", missing_ok=True) is None - - -def test_unpublished_attempt_can_be_discarded_without_touching_current( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - current = store.new_attempt("cell", ArtifactPolicy.REGENERATE).publish( - {"status": "ok"} - ) - partial = store.new_attempt( - "cell", - ArtifactPolicy.REGENERATE, - based_on=current, - ) - partial.path("worker.log").write_text("partial\n", encoding="ascii") - partial_root = partial.root - - partial.discard() - - assert not partial_root.exists() - assert store.load_current("cell").attempt_id == current.attempt_id - with pytest.raises(ArtifactStoreError, match="already sealed"): - partial.discard() - - -def test_artifact_policy_decisions_are_explicit(tmp_path: Path) -> None: - store = _store(tmp_path) - assert store.decide("cell", ArtifactPolicy.REUSE).action is ArtifactAction.GENERATE - assert ( - store.decide("cell", ArtifactPolicy.RETIME).action - is ArtifactAction.GENERATE - ) - current = store.new_attempt("cell", ArtifactPolicy.REGENERATE).publish( - {"status": "ok"} - ) - - reuse = store.decide("cell", ArtifactPolicy.REUSE) - retime = store.decide("cell", ArtifactPolicy.RETIME) - regenerate = store.decide("cell", ArtifactPolicy.REGENERATE) - assert reuse.action is ArtifactAction.REUSE_CURRENT - assert reuse.current == current - assert not reuse.requires_timing - assert retime.action is ArtifactAction.RETIME_CURRENT - assert retime.current == current - assert retime.requires_timing and not retime.requires_generation - assert regenerate.action is ArtifactAction.GENERATE - assert regenerate.requires_generation - - -def test_recovery_enumerates_only_validated_current_records(tmp_path: Path) -> None: - store = _store(tmp_path) - expected = { - store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - .publish({"cell": cell_id}) - .attempt_id - for cell_id in ("cell-a", "cell-b") - } - store.new_attempt("failed-cell", ArtifactPolicy.REGENERATE).mark_failed( - "not publishable" - ) - - recovered = store.recover_current_records() - assert {record.attempt_id for record in recovered} == expected - assert {record.cell_id for record in recovered} == {"cell-a", "cell-b"} - - -def test_recovery_rejects_manifest_digest_mismatch(tmp_path: Path) -> None: - store = _store(tmp_path) - current = store.new_attempt("cell", ArtifactPolicy.REGENERATE).publish({"ok": 1}) - current.manifest_path.write_text("{}\n", encoding="utf-8") - - with pytest.raises(ManifestValidationError, match="manifest digest mismatch"): - store.recover_current_records() - - -def test_recovery_rejects_pointer_path_traversal(tmp_path: Path) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - attempt.publish({"ok": 1}) - pointer_path = attempt.root.parent.parent / "current.json" - pointer = json.loads(pointer_path.read_text(encoding="utf-8")) - pointer["manifest_path"] = "../manifest.json" - _rewrite_json(pointer_path, pointer) - - with pytest.raises( - ManifestValidationError, - match="canonical attempt manifest", - ): - store.recover_current_records() - - -def test_recovery_rejects_artifact_path_traversal(tmp_path: Path) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - attempt.publish({"ok": 1}) - manifest_path = attempt.root / "manifest.json" - manifest = json.loads(manifest_path.read_text(encoding="utf-8")) - manifest["artifacts"][0]["path"] = "../outside.json" - _rewrite_json(manifest_path, manifest) - pointer_path = attempt.root.parent.parent / "current.json" - _rewrite_pointer_digest(pointer_path, manifest_path) - - with pytest.raises(ManifestValidationError, match="unsafe path"): - store.recover_current_records() - - -@pytest.mark.parametrize( - ("target", "schema"), - ( - ("pointer", "unknown-current-v9"), - ("manifest", "unknown-attempt-v9"), - ), -) -def test_recovery_rejects_schema_mismatch( - tmp_path: Path, - target: str, - schema: str, -) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - attempt.publish({"ok": 1}) - pointer_path = attempt.root.parent.parent / "current.json" - manifest_path = attempt.root / "manifest.json" - path = pointer_path if target == "pointer" else manifest_path - payload = json.loads(path.read_text(encoding="utf-8")) - payload["schema"] = schema - _rewrite_json(path, payload) - if target == "manifest": - _rewrite_pointer_digest(pointer_path, manifest_path) - - with pytest.raises(ManifestValidationError, match=r"unsupported .* schema"): - store.recover_current_records() - - -def test_recovery_rejects_artifact_digest_mismatch(tmp_path: Path) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - payload_path = attempt.path("payload.bin") - payload_path.write_bytes(b"original") - attempt.publish({"ok": 1}, artifact_paths=("payload.bin",)) - payload_path.write_bytes(b"modified") - - with pytest.raises( - ManifestValidationError, - match=r"artifact (size|digest) mismatch", - ): - store.recover_current_records() - - -def test_attempt_paths_cannot_escape_explicit_artifact_root(tmp_path: Path) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - with pytest.raises(ManifestValidationError, match="unsafe path"): - attempt.path("../outside.json") - assert not (tmp_path / "outside.json").exists() - - -def test_based_on_record_must_belong_to_same_cell(tmp_path: Path) -> None: - store = _store(tmp_path) - current = store.new_attempt("first", ArtifactPolicy.REGENERATE).publish({"ok": 1}) - with pytest.raises(ArtifactStoreError, match="different cell"): - store.new_attempt("second", ArtifactPolicy.RETIME, based_on=current) - - -def test_named_filesystem_lock_times_out_across_processes(tmp_path: Path) -> None: - store = _store(tmp_path) - context = multiprocessing.get_context("spawn") - queue: multiprocessing.Queue[str] = context.Queue() - with store.named_lock("prepared-ufo"): - process = context.Process( - target=_try_named_lock, - args=( - str(store.artifact_root), - str(store.lock_root), - queue, - ), - ) - process.start() - process.join(timeout=3) - assert process.exitcode == 0 - try: - outcome = queue.get(timeout=1) - except Empty as error: - raise AssertionError("child did not report its lock outcome") from error - assert outcome == "timeout" - - -def test_named_filesystem_lock_is_reentrant_in_same_thread(tmp_path: Path) -> None: - store = _store(tmp_path) - competing = ArtifactStore( - artifact_root=store.artifact_root, - lock_root=store.lock_root, - ) - - with ( - store.named_lock("measurement-lineage"), - competing.named_lock("measurement-lineage", timeout=0.0), - store.named_lock("measurement-lineage", timeout=0.0), - ): - pass - - with store.named_lock("measurement-lineage", timeout=0.0): - pass - - -def test_cell_and_named_locks_use_separate_explicit_roots(tmp_path: Path) -> None: - store = _store(tmp_path) - with store.cell_lock("cell"), store.named_lock("report-writer"): - assert store.artifact_root == (tmp_path / "artifacts").resolve() - assert store.lock_root == (tmp_path / "coordination").resolve() - assert list((store.lock_root / "cells").glob("*.lock")) - assert list((store.lock_root / "named").glob("*.lock")) - - -def test_manifest_shape_is_stable_and_records_policy_lineage(tmp_path: Path) -> None: - store = _store(tmp_path) - first = store.new_attempt("cell", ArtifactPolicy.REGENERATE).publish({"run": 1}) - second_attempt = store.new_attempt( - "cell", - ArtifactPolicy.RETIME, - based_on=first, - ) - second_attempt.publish({"run": 2}) - manifest = json.loads( - (second_attempt.root / "manifest.json").read_text(encoding="utf-8") - ) - - assert manifest["schema"] == ATTEMPT_SCHEMA - assert manifest["artifact_policy"] == "retime" - assert manifest["based_on"] == { - "attempt_id": first.attempt_id, - "manifest_sha256": first.manifest_sha256, - } - - -def test_seal_existing_worker_result_publishes_same_authenticated_attempt( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REUSE) - attempt.write_json( - "worker-result.json", - {"status": "ok", "validation": {"status": "ok"}}, - ) - attempt.path("worker.log").write_text("completed\n", encoding="utf-8") - worker_result = attempt.root / "worker-result.json" - digest = hashlib.sha256(worker_result.read_bytes()).hexdigest() - - current = store.seal_existing_worker_result( - "cell", - attempt.attempt_id, - worker_result_sha256=digest, - artifact_policy=ArtifactPolicy.REUSE, - validate_result=lambda result, root: ( - None - if result["status"] == "ok" and (root / "worker.log").is_file() - else (_ for _ in ()).throw(ValueError("incomplete evidence")) - ), - ) - - assert current.attempt_id == attempt.attempt_id - assert current.artifact_policy is ArtifactPolicy.REUSE - assert current.result == { - "status": "ok", - "validation": {"status": "ok"}, - } - assert {artifact.relative_path for artifact in current.artifacts} == { - "result.json", - "worker-result.json", - "worker.log", - } - assert json.loads((attempt.root / "result.json").read_text()) == current.result - assert store.load_current("cell") == current - - -@pytest.mark.parametrize("mutation", ("digest", "wrong-cell", "incomplete")) -def test_seal_existing_worker_result_rejects_untrusted_or_incomplete_evidence( - tmp_path: Path, - mutation: str, -) -> None: - store = _store(tmp_path) - attempt = store.new_attempt("cell", ArtifactPolicy.REUSE) - attempt.write_json("worker-result.json", {"status": "ok"}) - worker_result = attempt.root / "worker-result.json" - digest = hashlib.sha256(worker_result.read_bytes()).hexdigest() - - with pytest.raises((ArtifactStoreError, ValueError)): - store.seal_existing_worker_result( - "other-cell" if mutation == "wrong-cell" else "cell", - attempt.attempt_id, - worker_result_sha256=( - "0" * 64 if mutation == "digest" else digest - ), - artifact_policy=ArtifactPolicy.REUSE, - validate_result=( - (lambda _result, _root: (_ for _ in ()).throw( - ValueError("incomplete evidence") - )) - if mutation == "incomplete" - else lambda _result, _root: None - ), - ) - - assert not (attempt.root / "result.json").exists() - assert not (attempt.root / "manifest.json").exists() - assert store.load_current("cell", missing_ok=True) is None diff --git a/pyamplicol/tests/unit/test_performance_report_boundary.py b/pyamplicol/tests/unit/test_performance_report_boundary.py deleted file mode 100644 index 187823a72c..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_boundary.py +++ /dev/null @@ -1,164 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from collections.abc import Mapping -from pathlib import Path -from typing import Any - -import pytest - -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.boundary import ( - CELL_BOUNDARY_SCHEMA, - CellBoundaryError, - authenticate_current_delta, - load_cell_boundary, - snapshot_cell_boundary, -) -from tools.performance_report.cli import _parser -from tools.performance_report.models import ArtifactPolicy - - -def _store(tmp_path: Path) -> ArtifactStore: - return ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "coordination", - ) - - -def _publish_worker_result( - store: ArtifactStore, - cell_id: str, -) -> str: - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - attempt.path("worker-result.json").write_text( - '{"status":"ok"}\n', - encoding="ascii", - ) - return attempt.publish( - {"status": "ok"}, - artifact_paths=("worker-result.json",), - ).attempt_id - - -def test_boundary_accepts_exactly_one_authenticated_current_delta( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - before = snapshot_cell_boundary(store, "cell") - attempt_id = _publish_worker_result(store, "cell") - - accepted = authenticate_current_delta( - store, - cell_id="cell", - expected_attempt_id=attempt_id, - before=before, - ) - - assert accepted["schema"] == CELL_BOUNDARY_SCHEMA - assert accepted["attempt_ids"] == [attempt_id] - current = accepted["current"] - assert isinstance(current, dict) - assert current["attempt_id"] == attempt_id - assert current["status"] == "ok" - assert len(str(current["manifest_sha256"])) == 64 - assert len(str(current["result_sha256"])) == 64 - assert len(str(current["worker_result_sha256"])) == 64 - - -def test_boundary_rejects_an_extra_attempt_even_with_valid_current( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - before = snapshot_cell_boundary(store, "cell") - failed = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - failed.mark_failed("failed") - accepted_id = _publish_worker_result(store, "cell") - - with pytest.raises(CellBoundaryError, match="exactly"): - authenticate_current_delta( - store, - cell_id="cell", - expected_attempt_id=accepted_id, - before=before, - ) - - -def test_boundary_runs_result_validation_before_acceptance( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - before = snapshot_cell_boundary(store, "cell") - attempt_id = _publish_worker_result(store, "cell") - - def reject_result(result: Mapping[str, Any]) -> None: - assert result == {"status": "ok"} - raise ValueError("measurement schema differs") - - with pytest.raises(ValueError, match="measurement schema"): - authenticate_current_delta( - store, - cell_id="cell", - expected_attempt_id=attempt_id, - before=before, - validate_result=reject_result, - ) - - -def test_boundary_rejects_current_without_authenticated_worker_result( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - before = snapshot_cell_boundary(store, "cell") - attempt = store.new_attempt("cell", ArtifactPolicy.REGENERATE) - attempt.publish({"status": "ok"}) - - with pytest.raises( - CellBoundaryError, - match=r"worker-result\.json", - ): - authenticate_current_delta( - store, - cell_id="cell", - expected_attempt_id=attempt.attempt_id, - before=before, - ) - - -def test_boundary_loads_legacy_fast_wrapper_snapshot(tmp_path: Path) -> None: - path = tmp_path / "pre-populate-current.json" - path.write_text( - json.dumps( - { - "attempt_ids": [], - "cell_root": "/legacy/cell", - "current": None, - } - ), - encoding="ascii", - ) - - assert load_cell_boundary(path)["attempt_ids"] == [] - - -def test_boundary_commands_have_explicit_cell_inputs() -> None: - snapshot = _parser().parse_args( - ("snapshot-cell-boundary", "--cell-id", "cell") - ) - assert snapshot.cell_id == "cell" - - accepted = _parser().parse_args( - ( - "accept-cell-boundary", - "--cell-id", - "cell", - "--expected-attempt-id", - "attempt", - "--before-snapshot", - "before.json", - ) - ) - assert accepted.cell_id == "cell" - assert accepted.expected_attempt_id == "attempt" - assert accepted.before_snapshot == Path("before.json") diff --git a/pyamplicol/tests/unit/test_performance_report_campaign_activity.py b/pyamplicol/tests/unit/test_performance_report_campaign_activity.py deleted file mode 100644 index 6c5e44a023..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_campaign_activity.py +++ /dev/null @@ -1,157 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.campaign_activity import ( - CampaignActivityError, - blocking_coordination_files, - blocking_process_lines, - campaign_activity, - require_campaign_idle, -) - - -def test_publisher_render_processes_are_not_campaign_workers(tmp_path: Path) -> None: - entrypoint = tmp_path / "result_tables.py" - process_output = "\n".join( - ( - ( - "94622 Python /usr/bin/python " - f"{entrypoint} publish-snapshot --watch" - ), - "94623 latexmk /usr/bin/latexmk -pdf pyAmpliCol.tex", - f"94624 Python /usr/bin/python {entrypoint} populate --workers 1", - "94625 rustc /usr/bin/rustc --crate-name pyamplicol", - ) - ) - - assert blocking_process_lines( - process_output, - entrypoints=(entrypoint,), - ) == ( - f"94624 Python /usr/bin/python {entrypoint} populate --workers 1", - "94625 rustc /usr/bin/rustc --crate-name pyamplicol", - ) - - -def test_only_regular_publisher_private_coordination_files_are_ignored( - tmp_path: Path, -) -> None: - coordination_root = tmp_path / "coordination" - publication = coordination_root / "publication" - named = coordination_root / "named" - lsof_output = "\n".join( - ( - "p94622", - "cPython", - "f3u", - "tREG", - f"n{publication / 'daemon.guard'}", - "f4r", - "tREG", - f"n{publication / 'daemon.json'}", - "f5r", - "tREG", - f"n{publication / 'snapshot-staging' / 'current.json'}", - "f6r", - "tDIR", - f"n{publication}", - "p94624", - "cPython", - "f3u", - "tREG", - f"n{named / 'report-writer-deadbeef.lock'}", - "f4u", - "tREG", - f"n{named / 'cell-example-deadbeef.lock'}", - ) - ) - - blocked = blocking_coordination_files( - lsof_output, - coordination_root=coordination_root, - ) - - assert [record.path for record in blocked] == [ - publication, - named / "report-writer-deadbeef.lock", - named / "cell-example-deadbeef.lock", - ] - - -def test_idle_census_ignores_publisher_but_rejects_report_writer( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - coordination_root = tmp_path / "coordination" - publication = coordination_root / "publication" - named = coordination_root / "named" - responses = iter( - ( - subprocess.CompletedProcess( - args=("ps",), - returncode=0, - stdout=( - "94622 Python /usr/bin/python result_tables.py " - "publish-snapshot --watch\n" - ), - stderr="", - ), - subprocess.CompletedProcess( - args=("lsof",), - returncode=0, - stdout="\n".join( - ( - "p94622", - "cPython", - "f3u", - "tREG", - f"n{publication / 'daemon.guard'}", - ) - ), - stderr="", - ), - ) - ) - monkeypatch.setattr( - "tools.performance_report.campaign_activity.subprocess.run", - lambda *_args, **_kwargs: next(responses), - ) - - assert campaign_activity(coordination_root=coordination_root).idle - - responses = iter( - ( - subprocess.CompletedProcess( - args=("ps",), - returncode=0, - stdout="", - stderr="", - ), - subprocess.CompletedProcess( - args=("lsof",), - returncode=0, - stdout="\n".join( - ( - "p94624", - "cPython", - "f3u", - "tREG", - f"n{named / 'report-writer-deadbeef.lock'}", - ) - ), - stderr="", - ), - ) - ) - monkeypatch.setattr( - "tools.performance_report.campaign_activity.subprocess.run", - lambda *_args, **_kwargs: next(responses), - ) - - with pytest.raises(CampaignActivityError, match="report-writer"): - require_campaign_idle(coordination_root=coordination_root) diff --git a/pyamplicol/tests/unit/test_performance_report_campaign_holds.py b/pyamplicol/tests/unit/test_performance_report_campaign_holds.py deleted file mode 100644 index b7625d75da..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_campaign_holds.py +++ /dev/null @@ -1,698 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -from pathlib import Path -from typing import Any - -import pytest - -from tools.performance_report.agreements import ( - DIRECT_AGREEMENT_FIELD, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, -) -from tools.performance_report.artifacts import ArtifactStore, CurrentRecord -from tools.performance_report.cache import empty_measurement -from tools.performance_report.campaign_holds import ( - DEPENDENCY_HOLD_REASON, - PriorHeldDisposition, - PriorHeldEligibilityError, - active_prior_held_ids, - catalog_prerequisite_closure, - classify_prior_held_cells, - prior_held_history_record, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.measurement import failure_measurement -from tools.performance_report.measurement_lineage import MeasurementLineage -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ResultStatus, - Workload, -) - -_SOURCE_REVISION = "1" * 40 -_SOURCE_TREE = "2" * 40 - - -def _store(tmp_path: Path) -> ArtifactStore: - return ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "coordination", - ) - - -def _cell(*, workload: Workload = Workload.SELECTED_FLOW) -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "matrix_compiled_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is workload - ) - - -def _hard_dependency_cell() -> CellSpec: - return _cell(workload=Workload.ALL_FLOW) - - -def _ufo_recurrence_cell( - *, workload: Workload = Workload.SELECTED_FLOW -) -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "matrix_recurrence_ufo_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is workload - ) - - -def _ok_measurement( - cell: CellSpec, - *, - source_revision: str | None = _SOURCE_REVISION, - source_tree: str | None = _SOURCE_TREE, -) -> dict[str, object]: - measurement = empty_measurement() - selector = ( - None - if cell.measurement.accuracy is not Accuracy.LC - else { - "selected_color_flow_ids": ["flow:2,1"], - "selected_color_words": [[2, 1]], - "all_flow_helicity_ids": ["h:-1,+1,-1"], - "all_flow_source_helicities": {"1": -1, "2": 1, "3": -1}, - "point_digest": "a" * 64, - } - ) - validation: dict[str, object] = { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - } - if selector is not None: - validation[LC_COMMON_COMPONENT_FIELD] = { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell.cell_id, - "value": 1.0, - "point_digest": selector["point_digest"], - "helicity_ids": selector["all_flow_helicity_ids"], - "color_flow_ids": selector["selected_color_flow_ids"], - } - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": {}, - "selector_contract": selector, - "validation": validation, - "resources": {}, - "provenance": ( - {} - if source_revision is None - else { - "report_measured_source_revision": source_revision, - "report_measured_source_tree": source_tree, - "report_source_revision": source_revision, - "report_source_tree": source_tree, - } - ), - } - ) - return measurement - - -def _publish_ok(store: ArtifactStore, cell: CellSpec) -> None: - store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE).publish( - _ok_measurement(cell) - ) - - -def _publish_prerequisites( - store: ArtifactStore, - target: CellSpec, -) -> tuple[CellSpec, ...]: - prerequisites = catalog_prerequisite_closure(target) - for prerequisite in prerequisites: - _publish_ok(store, prerequisite) - return prerequisites - - -def _hold_observation(index: int, reason: str) -> dict[str, object]: - summary_path = f"/summaries/{index:04d}.json" - return { - "reason": reason, - "summary_path": summary_path, - "summary_sha256": hashlib.sha256(summary_path.encode()).hexdigest(), - } - - -def _prior( - target: CellSpec, - *, - reasons: tuple[str, ...] = (DEPENDENCY_HOLD_REASON,), -) -> dict[str, object]: - return { - target.cell_id: prior_held_history_record( - target.cell_id, - (_hold_observation(index, reason) for index, reason in enumerate(reasons)), - ) - } - - -def _classify( - store: ArtifactStore, - prior_held_records: dict[str, object], - **kwargs: Any, -) -> dict[str, PriorHeldDisposition]: - kwargs.setdefault("expected_source_revision", _SOURCE_REVISION) - kwargs.setdefault("expected_source_tree", _SOURCE_TREE) - return classify_prior_held_cells( - store, - prior_held_records, - **kwargs, - ) - - -def _active_prior_held_ids( - store: ArtifactStore, - prior_held_records: dict[str, object], -) -> frozenset[str]: - return active_prior_held_ids( - store, - prior_held_records, - expected_source_revision=_SOURCE_REVISION, - expected_source_tree=_SOURCE_TREE, - ) - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for chunk in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def test_dependency_hold_becomes_eligible_after_every_prerequisite_is_ok( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - prerequisites = catalog_prerequisite_closure(target) - assert len(prerequisites) == 1 - assert prerequisites[0] == _cell() - - before = _classify(store, _prior(target))[target.cell_id] - assert before.eligible is False - assert {state for _cell_id, state in before.blocking_prerequisites} == {"missing"} - - for prerequisite in prerequisites: - _publish_ok(store, prerequisite) - after = _classify(store, _prior(target))[target.cell_id] - assert after.eligible is True - assert after.reason == "eligible" - assert _active_prior_held_ids(store, _prior(target)) == frozenset() - - -def test_compiled_recurrence_authority_is_not_a_hold_prerequisite( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _cell() - authority = REPORT_CATALOG.validation_baseline_cell(target) - - assert authority is not None - assert authority.measurement.execution_mode.value == "recurrence" - assert catalog_prerequisite_closure(target) == () - assert _classify(store, _prior(target))[target.cell_id].eligible is True - - -@pytest.mark.parametrize( - "reason", - ( - "exact one-cell plan expanded or changed", - "signed-zero LC family awaits scoped continuity bridge", - "future hold reason", - ), -) -def test_non_dependency_historical_hold_is_never_readmitted( - tmp_path: Path, - reason: str, -) -> None: - store = _store(tmp_path) - target = _cell() - _publish_prerequisites(store, target) - - disposition = _classify( - store, - _prior(target, reasons=(reason,)), - )[target.cell_id] - - assert disposition.eligible is False - assert disposition.reason == "historical-hold-not-dependency" - assert _active_prior_held_ids( - store, - _prior(target, reasons=(reason,)), - ) == frozenset((target.cell_id,)) - - -def test_later_non_dependency_reason_overrides_earlier_dependency_hold( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _cell() - _publish_prerequisites(store, target) - reasons = ( - DEPENDENCY_HOLD_REASON, - "exact one-cell plan expanded or changed", - ) - - disposition = _classify( - store, - _prior(target, reasons=reasons), - )[target.cell_id] - - assert disposition.eligible is False - assert disposition.reason == "historical-hold-not-dependency" - assert disposition.historical_reasons == reasons - assert disposition.as_dict()["historical_reasons"] == list(reasons) - assert len(disposition.historical_observations) == 2 - - -@pytest.mark.parametrize( - "record", - ( - None, - {}, - {"reason": None}, - {"reason": ""}, - ), -) -def test_malformed_historical_hold_record_aborts_classification( - tmp_path: Path, - record: object, -) -> None: - store = _store(tmp_path) - target = _cell() - - with pytest.raises(PriorHeldEligibilityError, match="historical hold"): - _classify(store, {target.cell_id: record}) - - -def test_historical_hold_history_rejects_bad_digest_and_reason_tampering( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _cell() - - with pytest.raises(PriorHeldEligibilityError, match="observation"): - prior_held_history_record( - target.cell_id, - ( - { - "reason": DEPENDENCY_HOLD_REASON, - "summary_path": "/summary.json", - "summary_sha256": "bad", - }, - ), - ) - history = _prior(target) - raw_record = history[target.cell_id] - assert isinstance(raw_record, dict) - tampered = {**raw_record, "reasons": ["different"]} - with pytest.raises(PriorHeldEligibilityError, match="inconsistent"): - _classify(store, {target.cell_id: tampered}) - - -def test_optional_amplicol_diagnostic_is_not_a_hold_prerequisite( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _ufo_recurrence_cell() - (direct,) = catalog_prerequisite_closure(target) - optional_diagnostic = REPORT_CATALOG.validation_baseline_cell(target) - assert optional_diagnostic is not None - assert optional_diagnostic.measurement.execution_mode.value == "amplicol" - - disposition = _classify( - store, - _prior(target), - )[target.cell_id] - - assert disposition.eligible is False - assert disposition.prerequisite_ids == (direct.cell_id,) - assert optional_diagnostic.cell_id not in disposition.prerequisite_ids - assert disposition.blocking_prerequisites == ((direct.cell_id, "missing"),) - - -@pytest.mark.parametrize( - "status", - ( - ResultStatus.ERROR, - ResultStatus.SKIP, - ResultStatus.UNSUPPORTED, - ), -) -def test_terminal_prerequisite_status_keeps_historical_hold( - tmp_path: Path, - status: ResultStatus, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - prerequisites = catalog_prerequisite_closure(target) - failed = prerequisites[-1] - for prerequisite in prerequisites: - result = ( - failure_measurement(status, "terminal") - if prerequisite == failed - else _ok_measurement(prerequisite) - ) - store.new_attempt( - prerequisite.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(result) - - disposition = _classify( - store, - _prior(target), - )[target.cell_id] - - assert disposition.eligible is False - assert (failed.cell_id, status.value) in disposition.blocking_prerequisites - - -@pytest.mark.parametrize("with_current", (False, True)) -def test_target_is_never_reselected_after_any_attempt( - tmp_path: Path, - with_current: bool, -) -> None: - store = _store(tmp_path) - target = _cell() - _publish_prerequisites(store, target) - attempt = store.new_attempt(target.cell_id, ArtifactPolicy.REGENERATE) - if with_current: - attempt.publish(_ok_measurement(target)) - else: - attempt.mark_failed("worker failed") - - disposition = _classify( - store, - _prior(target), - )[target.cell_id] - - assert disposition.eligible is False - assert disposition.reason == "target-already-attempted" - assert disposition.target_attempt_ids == (attempt.attempt_id,) - - -def test_active_scoped_hold_blocks_target_and_dependency_descendants( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - prerequisites = _publish_prerequisites(store, target) - active_dependency = prerequisites[0] - - direct = _classify( - store, - _prior(target), - active_scoped_hold_ids=(target.cell_id,), - )[target.cell_id] - descendant = _classify( - store, - _prior(target), - active_scoped_hold_ids=(active_dependency.cell_id,), - )[target.cell_id] - - assert direct.reason == "active-scoped-defect-hold" - assert descendant.blocking_prerequisites == ( - (active_dependency.cell_id, "active-scoped-defect-hold"), - ) - - -def test_agreement_equivalence_peers_are_required_before_readmission( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _cell(workload=Workload.ALL_FLOW) - prerequisites = catalog_prerequisite_closure(target) - selected_peer = _cell() - assert selected_peer.cell_id in { - prerequisite.cell_id for prerequisite in prerequisites - } - for prerequisite in prerequisites: - if prerequisite != selected_peer: - _publish_ok(store, prerequisite) - - blocked = _classify( - store, - _prior(target), - )[target.cell_id] - assert (selected_peer.cell_id, "missing") in blocked.blocking_prerequisites - - _publish_ok(store, selected_peer) - assert _classify( - store, - _prior(target), - )[target.cell_id].eligible - - -def test_unknown_or_invalid_current_fails_closed(tmp_path: Path) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - prerequisite = catalog_prerequisite_closure(target)[0] - store.new_attempt( - prerequisite.cell_id, - ArtifactPolicy.REGENERATE, - ).publish({"status": "future"}) - - with pytest.raises( - PriorHeldEligibilityError, - match="current measurement is invalid", - ): - _classify(store, _prior(target)) - with pytest.raises(PriorHeldEligibilityError, match="unknown catalog cells"): - _classify( - store, - {"unknown-cell": {"reason": DEPENDENCY_HOLD_REASON}}, - ) - with pytest.raises(PriorHeldEligibilityError, match="invalid catalog cell"): - _classify( - store, - {None: {"reason": DEPENDENCY_HOLD_REASON}}, # type: ignore[dict-item] - ) - - -@pytest.mark.parametrize("authenticated", (True, False, None, "yes")) -def test_additional_current_authenticator_is_strictly_boolean( - tmp_path: Path, - authenticated: object, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - _publish_prerequisites(store, target) - - disposition = classify_prior_held_cells( - store, - _prior(target), - authenticate_current=lambda _cell, _current: authenticated, # type: ignore[return-value] - )[target.cell_id] - - assert disposition.eligible is (authenticated is True) - states = {state for _cell_id, state in disposition.blocking_prerequisites} - assert states == (set() if authenticated is True else {"unauthenticated"}) - - -def test_measurement_lineage_authenticates_inherited_prerequisite_source( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - prerequisites = catalog_prerequisite_closure(target) - ancestor = prerequisites[0] - ancestor_revision = "3" * 40 - ancestor_tree = "4" * 40 - for prerequisite in prerequisites: - store.new_attempt( - prerequisite.cell_id, - ArtifactPolicy.REGENERATE, - ).publish( - _ok_measurement( - prerequisite, - source_revision=( - ancestor_revision if prerequisite == ancestor else _SOURCE_REVISION - ), - source_tree=( - ancestor_tree if prerequisite == ancestor else _SOURCE_TREE - ), - ) - ) - ancestor_current = store.load_current(ancestor.cell_id) - assert ancestor_current is not None - ancestor_pin = { - "attempt_id": ancestor_current.attempt_id, - "current_pointer_sha256": _sha256( - ancestor_current.manifest_path.parent.parent.parent / "current.json" - ), - "manifest_sha256": ancestor_current.manifest_sha256, - "result_sha256": _sha256(ancestor_current.result_path), - "source_revision": ancestor_revision, - "source_tree": ancestor_tree, - } - lineage = MeasurementLineage( - payload={}, - retained_by_cell={ancestor.cell_id: ancestor_pin}, - invalidated_cell_ids=frozenset(), - recompare_cell_ids=frozenset(), - required_descendant_cell_ids=frozenset(), - inherited_environments_by_revision={}, - ) - - def authenticate(_cell: CellSpec, current: CurrentRecord) -> bool: - return ( - lineage.source_for_current( - current, - active_revision=_SOURCE_REVISION, - active_tree=_SOURCE_TREE, - ) - is not None - ) - - accepted = classify_prior_held_cells( - store, - _prior(target), - authenticate_current=authenticate, - )[target.cell_id] - rejected_lineage = MeasurementLineage( - payload={}, - retained_by_cell={}, - invalidated_cell_ids=frozenset(), - recompare_cell_ids=frozenset(), - required_descendant_cell_ids=frozenset(), - inherited_environments_by_revision={}, - ) - rejected = classify_prior_held_cells( - store, - _prior(target), - authenticate_current=lambda _cell, current: ( - rejected_lineage.source_for_current( - current, - active_revision=_SOURCE_REVISION, - active_tree=_SOURCE_TREE, - ) - is not None - ), - )[target.cell_id] - - assert accepted.eligible is True - assert rejected.eligible is False - assert (ancestor.cell_id, "unauthenticated") in (rejected.blocking_prerequisites) - - -def test_source_authentication_policy_is_required(tmp_path: Path) -> None: - store = _store(tmp_path) - target = _cell() - - with pytest.raises( - PriorHeldEligibilityError, - match="source authentication policy", - ): - classify_prior_held_cells(store, _prior(target)) - - -@pytest.mark.parametrize( - ("revision", "tree"), - ( - ("", ""), - ("not-a-git-object", "2" * 40), - ("1" * 39, "2" * 40), - ("1" * 40, "z" * 40), - ), -) -def test_single_source_authentication_rejects_malformed_git_identities( - tmp_path: Path, - revision: str, - tree: str, -) -> None: - store = _store(tmp_path) - target = _cell() - _publish_prerequisites(store, target) - - with pytest.raises(PriorHeldEligibilityError, match="Git object identities"): - classify_prior_held_cells( - store, - _prior(target), - expected_source_revision=revision, - expected_source_tree=tree, - ) - - -def test_expected_source_identity_blocks_stale_prerequisites( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - for prerequisite in catalog_prerequisite_closure(target): - store.new_attempt( - prerequisite.cell_id, - ArtifactPolicy.REGENERATE, - ).publish( - _ok_measurement( - prerequisite, - source_revision="5" * 40, - source_tree="6" * 40, - ) - ) - - disposition = classify_prior_held_cells( - store, - _prior(target), - expected_source_revision=_SOURCE_REVISION, - expected_source_tree=_SOURCE_TREE, - )[target.cell_id] - - assert disposition.eligible is False - assert {state for _cell_id, state in disposition.blocking_prerequisites} == { - "source-stale" - } - with pytest.raises(PriorHeldEligibilityError, match="provided together"): - classify_prior_held_cells( - store, - _prior(target), - expected_source_tree=_SOURCE_TREE, - ) - - -def test_single_source_authentication_checks_measured_identity( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - target = _hard_dependency_cell() - stale = catalog_prerequisite_closure(target)[0] - for prerequisite in catalog_prerequisite_closure(target): - measurement = _ok_measurement(prerequisite) - if prerequisite == stale: - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance["report_measured_source_revision"] = "5" * 40 - store.new_attempt( - prerequisite.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(measurement) - - disposition = _classify(store, _prior(target))[target.cell_id] - - assert disposition.eligible is False - assert (stale.cell_id, "source-stale") in (disposition.blocking_prerequisites) diff --git a/pyamplicol/tests/unit/test_performance_report_campaign_policy.py b/pyamplicol/tests/unit/test_performance_report_campaign_policy.py deleted file mode 100644 index 1ca7a8fe03..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_campaign_policy.py +++ /dev/null @@ -1,2370 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import subprocess -from pathlib import Path -from types import SimpleNamespace -from typing import ClassVar - -import pytest - -from tools.ci.memory_watchdog import ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON, - RSS_LIMIT_REASON, -) -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.cache import build_reset_caches, empty_measurement -from tools.performance_report.campaign_policy import ( - MACBOOK_M3_MEMORY_LIMIT_BYTES, - MACBOOK_M3_POLICY, - MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS, - MACBOOK_M3_Z_TABLE_F_POLICY, - STRICT_POLICY, - X86_EPYC_GENERATION_LIMIT_SECONDS, - X86_EPYC_LEGACY_MEMORY_LIMIT_BYTES, - X86_EPYC_LEGACY_WORKERS, - X86_EPYC_MEMORY_LIMIT_BYTES, - X86_EPYC_NATIVE_COMPILER_SLOTS, - X86_EPYC_POLICY, - X86_EPYC_WORKERS, - CampaignPolicyError, - PolicyCensorKind, - PolicyMeasurementState, - _validate_generation_phase, - dependency_reference, - generation_limit_exempt, - generation_limit_for_cell, - policy_censor_measurement, - policy_from_manifest, - policy_status_label, - resource_frontier_reference, - resource_lane_identity, - validate_policy_measurement, -) -from tools.performance_report.catalog import ( - REPORT_CATALOG, - STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT, -) -from tools.performance_report.cli import _gb_bytes, _parser -from tools.performance_report.final_audit import FinalAuditError, audit_final_report -from tools.performance_report.legacy import ( - LegacyMeasurementAdapter, - LegacySettings, -) -from tools.performance_report.models import ArtifactPolicy, Workload -from tools.performance_report.publication import portable_publication_value -from tools.performance_report.render import _status -from tools.performance_report.resources import ( - PROCESS_TREE_MEMORY_METRIC_ABI, - GenerationPhaseEvidence, - ResourceUsage, - SupervisedResult, -) -from tools.performance_report.scheduler import ( - CampaignScheduler, - CampaignSettings, - PlannedCell, - _partition_dependency_records, - _resource_payload, - plan_campaign, - validate_campaign_plan, -) -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity -from tools.performance_report.study_contract import ( - StudyContractError, - bind_z_table_f_attempt, - create_z_table_f_study_contract, -) -from tools.performance_report.worker import _worker_legacy_workspace -from tools.performance_report.worker_harness import ( - attach_worker_harness_identity, - worker_harness_identity, -) -from tools.performance_report.workspace import ( - WORKSPACE_MANIFEST, - WORKSPACE_SCHEMA, - ReportWorkspaceError, - load_profile_campaign_policy, -) - -_REVISION = "1" * 40 -_TREE = "2" * 40 -_IDENTITY = ReportSourceIdentity(_REVISION, _TREE, ()) - - -def _git_repo( - path: Path, - marker: str, - *, - report_wrapper: bool = False, -) -> Path: - path.mkdir() - subprocess.run(("git", "init", "-q"), cwd=path, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=path, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=path, - check=True, - ) - (path / "README.md").write_text(marker + "\n", encoding="ascii") - if report_wrapper: - (path / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - (path / "tools/performance_report").mkdir(parents=True) - (path / "src/pyamplicol/_profiling_campaign/result_tables.py").write_text( - f"# {marker} policy entrypoint\n", - encoding="ascii", - ) - (path / "tools/performance_report/legacy.py").write_text( - f"# {marker} legacy adapter\n", - encoding="ascii", - ) - subprocess.run(("git", "add", "."), cwd=path, check=True) - subprocess.run(("git", "commit", "-qm", "fixture"), cwd=path, check=True) - return path - - -def _resources(peak: int) -> dict[str, object]: - return { - "available": True, - "current_rss_bytes": peak, - "peak_rss_bytes": peak, - "child_count": 1, - "cpu_seconds": 1.0, - "wall_seconds": 2.0, - "probe_error": None, - } - - -def _guard_resources( - *, - limit: int, - rss: int, - physical: int | None, - reason: str | None, -) -> dict[str, object]: - guard = max(rss, physical if physical is not None else rss) - return { - **_resources(rss), - "memory_metric_abi": PROCESS_TREE_MEMORY_METRIC_ABI, - "current_physical_footprint_bytes": physical, - "peak_physical_footprint_bytes": physical, - "current_guard_bytes": guard, - "peak_guard_bytes": guard, - "memory_limit_bytes": limit, - "memory_limit_reason": reason, - "memory_probe_reason": None, - } - - -def _generation_phase( - *, - reason: str, - elapsed: float, -) -> dict[str, object]: - completed = reason == "completed" - return { - "abi": "pyamplicol-report-generation-phase-evidence-v1", - "phase_state_abi": "pyamplicol-report-worker-phase-state-v1", - "configured_timeout_seconds": 3600.0, - "supervisor_reason": reason, - "authenticated": True, - "run_id": "f-worker", - "worker_pid": 123, - "final_sequence": 2 if completed else 1, - "final_phase": "post-generation" if completed else "generation", - "generation_started_monotonic_ns": 1, - "generation_finished_monotonic_ns": 2 if completed else None, - "generation_elapsed_seconds": elapsed, - "final_state_sha256": "3" * 64, - "error": None, - } - - -def _test_worker_harness() -> dict[str, object]: - return worker_harness_identity( - study_contract_sha256="a" * 64, - policy_wrapper_revision="3" * 40, - policy_wrapper_tree="4" * 40, - policy_entrypoint_sha256="5" * 64, - legacy_adapter_sha256="6" * 64, - measured_source_revision=_REVISION, - measured_source_tree=_TREE, - ) - - -def _x86_settings(**changes: object) -> CampaignSettings: - values: dict[str, object] = { - "workers": X86_EPYC_WORKERS, - "cell_cores": 1, - "target_runtime_seconds": 5.0, - "max_rss_bytes": X86_EPYC_MEMORY_LIMIT_BYTES, - "allow_symbolica_parallel": True, - "campaign_policy": X86_EPYC_POLICY, - "report_profile": "x86_EPYC", - } - values.update(changes) - return CampaignSettings(**values) # type: ignore[arg-type] - - -def _mac_settings(**changes: object) -> CampaignSettings: - values: dict[str, object] = { - "workers": 1, - "cell_cores": 1, - "target_runtime_seconds": 5.0, - "max_rss_bytes": MACBOOK_M3_MEMORY_LIMIT_BYTES, - "campaign_policy": MACBOOK_M3_POLICY, - "report_profile": "macbook_M3", - } - values.update(changes) - return CampaignSettings(**values) # type: ignore[arg-type] - - -def _z_table_f_settings(**changes: object) -> CampaignSettings: - values: dict[str, object] = { - "workers": 1, - "cell_cores": 1, - "target_runtime_seconds": 5.0, - "max_rss_bytes": MACBOOK_M3_MEMORY_LIMIT_BYTES, - "campaign_policy": MACBOOK_M3_Z_TABLE_F_POLICY, - "report_profile": "macbook_M3", - "study_contract_sha256": "a" * 64, - } - values.update(changes) - return CampaignSettings(**values) # type: ignore[arg-type] - - -def _memory_censor(cell, *, peak: int) -> dict[str, object]: - return policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=_resources(peak), - observed_rss_bytes=peak, - ) - - -def test_x86_policy_has_the_exact_canonical_n4_split() -> None: - cells = tuple( - cell for cell in REPORT_CATALOG.measurement_cells() if cell.n_final <= 4 - ) - exempt = tuple(cell for cell in cells if generation_limit_exempt(cell)) - - assert len(cells) == 1042 - assert len(exempt) == 271 - assert len(cells) - len(exempt) == 771 - assert all( - cell.measurement.execution_mode.value == "amplicol" - or ( - cell.measurement.execution_mode.value in {"compiled", "recurrence"} - and cell.measurement.accuracy.value == "lc" - and cell.workload is Workload.SELECTED_FLOW - ) - for cell in exempt - ) - full = REPORT_CATALOG.measurement_cells() - assert len(full) == 2198 - assert sum(generation_limit_exempt(cell) for cell in full) == 725 - assert sum(not generation_limit_exempt(cell) for cell in full) == 1473 - - -def test_x86_settings_are_exact_and_use_decimal_80_gb() -> None: - settings = _x86_settings() - - assert settings.workers == 25 - assert settings.cell_cores == 1 - assert settings.max_rss_bytes == 80_000_000_000 - assert settings.timeout_seconds is None - with pytest.raises(CampaignPolicyError, match="max_rss_bytes"): - _x86_settings(max_rss_bytes=80 * 1024**3) - with pytest.raises(CampaignPolicyError, match="workers"): - _x86_settings(workers=9) - with pytest.raises(CampaignPolicyError, match="workers"): - _x86_settings(workers=X86_EPYC_LEGACY_WORKERS) - assert CampaignSettings().campaign_policy is STRICT_POLICY - assert _gb_bytes(80.0) == X86_EPYC_MEMORY_LIMIT_BYTES - assert X86_EPYC_NATIVE_COMPILER_SLOTS == 4 - parsed = _parser().parse_args( - ( - "--report-profile", - "x86_EPYC", - "populate", - "--max-ram-gb", - "80", - ) - ) - assert parsed.max_ram_gb == 80.0 - - -def test_x86_policy_accepts_only_the_pinned_workers10_manifest_for_continuity() -> None: - legacy = X86_EPYC_POLICY.as_manifest() - legacy["workers"] = X86_EPYC_LEGACY_WORKERS - legacy["memory_limit_bytes"] = X86_EPYC_LEGACY_MEMORY_LIMIT_BYTES - - assert policy_from_manifest(legacy, profile="x86_EPYC") is X86_EPYC_POLICY - assert X86_EPYC_POLICY.as_manifest()["workers"] == X86_EPYC_WORKERS - - unsupported = dict(legacy) - unsupported["workers"] = 24 - with pytest.raises(CampaignPolicyError, match="canonical definition"): - policy_from_manifest(unsupported, profile="x86_EPYC") - - unsupported = dict(legacy) - unsupported["memory_limit_bytes"] = X86_EPYC_MEMORY_LIMIT_BYTES - with pytest.raises(CampaignPolicyError, match="canonical definition"): - policy_from_manifest(unsupported, profile="x86_EPYC") - - -def test_macbook_policy_is_exact_memory_only_decimal_30_gb() -> None: - settings = _mac_settings() - - assert settings.workers == 1 - assert settings.cell_cores == 1 - assert settings.target_runtime_seconds == 5.0 - assert settings.max_rss_bytes == 30_000_000_000 - assert settings.generation_time_limit_seconds is None - assert settings.timeout_seconds is None - assert settings.allow_symbolica_parallel is False - with pytest.raises(CampaignPolicyError, match="max_rss_bytes"): - _mac_settings(max_rss_bytes=30 * 1024**3) - with pytest.raises(CampaignPolicyError, match="generation_time_limit"): - _mac_settings(generation_time_limit_seconds=7200.0) - - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - peak = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - result = policy_censor_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=_resources(peak), - observed_rss_bytes=peak, - ) - assert policy_status_label(result) == ">30GB" - assert ( - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.MEMORY_LIMIT - ) - - -def test_z_table_f_policy_caps_every_generation_at_one_hour() -> None: - settings = _z_table_f_settings() - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id in {"z_builtin_sm", "reference_amplicol_lc"} - and cell.process_key == "dd_z_jets" - and cell.n_final in {8, 9} - and cell.workload in { - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - } - ) - - assert settings.max_rss_bytes == 30_000_000_000 - assert settings.generation_time_limit_seconds is None - assert settings.timeout_seconds is None - assert settings.study_contract_sha256 == "a" * 64 - assert ( - MACBOOK_M3_Z_TABLE_F_POLICY.generation_limit_seconds - == MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS - == 3600.0 - ) - assert ( - MACBOOK_M3_Z_TABLE_F_POLICY.as_manifest()[ - "generation_limit_exemptions" - ] - == "none" - ) - assert cells - assert { - cell.workload for cell in cells - } == {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - assert all( - generation_limit_for_cell(MACBOOK_M3_Z_TABLE_F_POLICY, cell) - == 3600.0 - for cell in cells - ) - assert any( - cell.measurement.execution_mode.value == "amplicol" - for cell in cells - ) - assert any( - cell.measurement.execution_mode.value == "recurrence" - and cell.workload is Workload.SELECTED_FLOW - for cell in cells - ) - with pytest.raises(CampaignPolicyError, match="max_rss_bytes"): - _z_table_f_settings(max_rss_bytes=30 * 1024**3) - with pytest.raises( - CampaignPolicyError, - match="generation_time_limit_seconds", - ): - _z_table_f_settings(generation_time_limit_seconds=3600.0) - with pytest.raises(ValueError, match="requires a study contract"): - _z_table_f_settings(study_contract_sha256=None) - with pytest.raises(ValueError, match="SHA-256"): - _z_table_f_settings(study_contract_sha256="not-a-digest") - with pytest.raises(ValueError, match="requires the Z-table F policy"): - CampaignSettings(study_contract_sha256="a" * 64) - - -def test_physical_footprint_censor_is_authenticated_and_tamper_evident() -> None: - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - rss = MACBOOK_M3_MEMORY_LIMIT_BYTES - 1 - physical = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - reason = "darwin-process-tree-physical-footprint-limit" - resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=rss, - physical=physical, - reason=reason, - ) - result = policy_censor_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_rss_bytes=rss, - observed_guard_bytes=physical, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_limit_reason=reason, - ) - - assert policy_status_label(result) == ">30GB" - assert ">30GB" in _status(result) - assert ( - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.MEMORY_LIMIT - ) - - tampered = json.loads(json.dumps(result)) - tampered["resources"]["peak_guard_bytes"] = physical - 2 - with pytest.raises(CampaignPolicyError, match="memory guard"): - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - tampered, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - - unsupported = json.loads(json.dumps(result)) - unsupported["resources"]["memory_metric_abi"] = "unsupported" - with pytest.raises(CampaignPolicyError, match="metric ABI"): - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - unsupported, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - - incomplete = json.loads(json.dumps(result)) - incomplete["resources"]["memory_probe_reason"] = ( - "darwin-process-tree-physical-footprint-probe-unavailable" - ) - with pytest.raises(CampaignPolicyError, match="incomplete memory"): - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - incomplete, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - - missing_field = json.loads(json.dumps(result)) - del missing_field["resources"]["memory_probe_reason"] - with pytest.raises(CampaignPolicyError, match="metric ABI"): - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - missing_field, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - - -def test_z_table_f_rejects_legacy_rss_only_censor_evidence() -> None: - ordinary_cell = REPORT_CATALOG.cell( - "scalar-contact-n2-scalar-contact-contracted" - ) - ordinary = _memory_censor( - ordinary_cell, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - assert ( - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - ordinary_cell, - ordinary, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.MEMORY_LIMIT - ) - - study_cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n8-dd-z-jets-selected-flow" - ) - with pytest.raises(CampaignPolicyError, match="policy-censor v3"): - policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - study_cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=_resources(MACBOOK_M3_MEMORY_LIMIT_BYTES + 1), - observed_rss_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES + 1, - ) - - peak = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - reason = DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON - v3_resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=peak, - physical=peak, - reason=reason, - ) - study_v3 = policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - study_cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=v3_resources, - observed_rss_bytes=peak, - observed_guard_bytes=peak, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_limit_reason=reason, - ) - assert ( - validate_policy_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - study_cell, - study_v3, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.MEMORY_LIMIT - ) - - -@pytest.mark.parametrize( - "field", - ( - "current_physical_footprint_bytes", - "peak_physical_footprint_bytes", - ), -) -@pytest.mark.parametrize( - "state", - ("success", "generation_limit", "memory_limit"), -) -def test_z_table_f_fails_closed_on_null_darwin_footprint( - field: str, - state: str, -) -> None: - cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n8-dd-z-jets-selected-flow" - ) - resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=100, - physical=120, - reason=None, - ) - if state == "success": - phase = _generation_phase(reason="completed", elapsed=1.0) - resources["generation_phase"] = phase - result = empty_measurement() - result.update( - { - "status": "ok", - "generation_seconds": 1.0, - "resources": resources, - "provenance": _IDENTITY.provenance(), - } - ) - attach_worker_harness_identity(result, _test_worker_harness()) - elif state == "generation_limit": - phase = _generation_phase( - reason="generation_timeout", - elapsed=3600.0, - ) - resources["generation_phase"] = phase - result = policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.GENERATION_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_generation_seconds=3600.0, - phase_evidence=phase, - ) - else: - peak = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=peak, - physical=peak - 1, - reason=RSS_LIMIT_REASON, - ) - result = policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_rss_bytes=peak, - observed_guard_bytes=peak, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_limit_reason=RSS_LIMIT_REASON, - ) - - result["resources"][field] = None - result["resources"][ - ( - "current_guard_bytes" - if field.startswith("current_") - else "peak_guard_bytes" - ) - ] = result["resources"][ - ( - "current_rss_bytes" - if field.startswith("current_") - else "peak_rss_bytes" - ) - ] - with pytest.raises( - CampaignPolicyError, - match="non-null authenticated current and peak Darwin", - ): - validate_policy_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - - -def test_ordinary_mac_policy_remains_compatible_with_null_footprint() -> None: - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - peak = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=peak, - physical=None, - reason=RSS_LIMIT_REASON, - ) - result = policy_censor_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_rss_bytes=peak, - observed_guard_bytes=peak, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_limit_reason=RSS_LIMIT_REASON, - ) - - assert ( - validate_policy_measurement( - MACBOOK_M3_POLICY, - "macbook_M3", - cell, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.MEMORY_LIMIT - ) - - -def test_z_table_f_memory_reason_must_match_darwin_guard_tie_break() -> None: - cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n8-dd-z-jets-selected-flow" - ) - peak = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=peak, - physical=peak, - reason=RSS_LIMIT_REASON, - ) - - with pytest.raises( - CampaignPolicyError, - match="reason does not match the authenticated Darwin guard", - ): - policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_rss_bytes=peak, - observed_guard_bytes=peak, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_limit_reason=RSS_LIMIT_REASON, - ) - - -def test_z_table_f_planning_rejects_stale_wrapper_harness_current( - tmp_path: Path, -) -> None: - cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n8-dd-z-jets-selected-flow" - ) - phase = _generation_phase( - reason="generation_timeout", - elapsed=3600.0, - ) - resources = _guard_resources( - limit=MACBOOK_M3_MEMORY_LIMIT_BYTES, - rss=100, - physical=120, - reason=None, - ) - resources["generation_phase"] = phase - result = policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.GENERATION_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_generation_seconds=3600.0, - phase_evidence=phase, - ) - current_harness = _test_worker_harness() - attach_worker_harness_identity(result, current_harness) - bind_z_table_f_attempt(result, "a" * 64) - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - store.new_attempt( - cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(result) - settings = _z_table_f_settings(missing_only=True) - - assert ( - plan_campaign( - (cell,), - store=store, - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - expected_worker_harness=current_harness, - ) - == () - ) - stale_expected = { - **current_harness, - "policy_wrapper_revision": "7" * 40, - } - planned = plan_campaign( - (cell,), - store=store, - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - expected_worker_harness=stale_expected, - ) - - assert tuple(item.cell_id for item in (entry.cell for entry in planned)) == ( - cell.cell_id, - ) - - -def test_z_table_f_plan_rejects_dependency_expansion( - tmp_path: Path, -) -> None: - cell = REPORT_CATALOG.cell( - "z-builtin-sm-n8-dd-z-jets-jit-o3-all-flow" - ) - settings = _z_table_f_settings() - planned = plan_campaign( - (cell,), - store=ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ), - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - ) - - assert len(planned) > 1 - assert any(item.dependency for item in planned) - with pytest.raises( - StudyContractError, - match="dependencies must already have authenticated currents", - ): - validate_campaign_plan(planned, settings) - - -def test_policy_censors_are_canonical_and_tamper_evident() -> None: - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.n_final <= 4 and not generation_limit_exempt(cell) - ) - phase_evidence = { - "abi": "pyamplicol-report-generation-phase-evidence-v1", - "phase_state_abi": "pyamplicol-report-worker-phase-state-v1", - "configured_timeout_seconds": X86_EPYC_GENERATION_LIMIT_SECONDS, - "supervisor_reason": "generation_timeout", - "authenticated": True, - "run_id": "run-1", - "worker_pid": 123, - "final_sequence": 1, - "final_phase": "generation", - "generation_started_monotonic_ns": 1, - "generation_finished_monotonic_ns": None, - "generation_elapsed_seconds": X86_EPYC_GENERATION_LIMIT_SECONDS, - "final_state_sha256": "3" * 64, - "error": None, - } - resources = _resources(1234) - resources["generation_phase"] = phase_evidence - result = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - kind=PolicyCensorKind.GENERATION_LIMIT, - source_identity=_IDENTITY, - resources=resources, - observed_generation_seconds=X86_EPYC_GENERATION_LIMIT_SECONDS, - phase_evidence=phase_evidence, - ) - - assert policy_status_label(result) == ">2h" - assert ( - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.GENERATION_LIMIT - ) - provenance = result["provenance"] - assert isinstance(provenance, dict) - record = provenance["policy_censor"] - assert isinstance(record, dict) - record["observed_generation_seconds"] = 7201.0 - with pytest.raises(CampaignPolicyError, match="sha256"): - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - - -def test_completed_reused_artifact_accepts_zero_work_generation_phase() -> None: - phase_evidence = { - "abi": "pyamplicol-report-generation-phase-evidence-v1", - "phase_state_abi": "pyamplicol-report-worker-phase-state-v1", - "configured_timeout_seconds": X86_EPYC_GENERATION_LIMIT_SECONDS, - "supervisor_reason": "completed", - "authenticated": True, - "run_id": "run-1", - "worker_pid": 123, - "final_sequence": 2, - "final_phase": "post-generation", - "generation_started_monotonic_ns": 10, - "generation_finished_monotonic_ns": 10, - "generation_elapsed_seconds": 0.0, - "final_state_sha256": "3" * 64, - "error": None, - } - - assert ( - _validate_generation_phase( - phase_evidence, - X86_EPYC_POLICY, - expected_reason="completed", - ) - is phase_evidence - ) - - -def test_generation_timeout_accepts_only_authenticated_preparation_boundary() -> None: - phase_evidence = { - **_generation_phase(reason="generation_timeout", elapsed=3600.0), - "final_sequence": 0, - "final_phase": "pre-generation", - "generation_started_monotonic_ns": None, - } - - assert ( - _validate_generation_phase( - phase_evidence, - MACBOOK_M3_Z_TABLE_F_POLICY, - expected_reason="generation_timeout", - ) - is phase_evidence - ) - for field, invalid in ( - ("final_sequence", 2), - ("final_phase", "post-generation"), - ("generation_started_monotonic_ns", 1), - ): - corrupted = {**phase_evidence, field: invalid} - with pytest.raises(CampaignPolicyError, match="inconsistent"): - _validate_generation_phase( - corrupted, - MACBOOK_M3_Z_TABLE_F_POLICY, - expected_reason="generation_timeout", - ) - - -def test_missing_only_reuses_exact_dependency_censor_and_rebinds_changes( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - candidate = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "matrix_compiled_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is Workload.ALL_FLOW - ) - baseline = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == candidate.dataset_id - and cell.process_key == candidate.process_key - and cell.n_final == candidate.n_final - and cell.workload is Workload.SELECTED_FLOW - ) - first = _memory_censor( - baseline, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - store.new_attempt( - baseline.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(first) - dependency = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - candidate, - kind=PolicyCensorKind.DEPENDENCY, - source_identity=_IDENTITY, - resources=None, - dependencies=(dependency_reference(baseline.cell_id, first),), - ) - store.new_attempt( - candidate.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(dependency) - settings = _x86_settings(missing_only=True) - - assert ( - plan_campaign( - (candidate,), - store=store, - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - ) - == () - ) - - second = _memory_censor( - baseline, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 2, - ) - store.new_attempt( - baseline.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(second) - planned = plan_campaign( - (candidate,), - store=store, - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - ) - - assert tuple(item.cell.cell_id for item in planned) == (candidate.cell_id,) - assert planned[0].force_recompare is True - - -def test_rendered_policy_markers_are_explicit() -> None: - cell = next( - cell for cell in REPORT_CATALOG.measurement_cells() if cell.n_final <= 4 - ) - result = _memory_censor( - cell, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - - assert policy_status_label(result) == ">80GB" - assert ">80GB" in _status(result) - - -def test_resource_frontier_is_lane_bound_and_tamper_evident() -> None: - source = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - target = REPORT_CATALOG.cell("scalar-contact-n3-scalar-contact-contracted") - root = _memory_censor( - source, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - frontier = resource_frontier_reference(target, source, root) - result = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - target, - kind=PolicyCensorKind.RESOURCE_FRONTIER, - source_identity=_IDENTITY, - resources=None, - frontier=frontier, - ) - - assert policy_status_label(result) == "dependency >80GB" - assert ( - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - target, - result, - expected_source_revision=_REVISION, - expected_source_tree=_TREE, - ) - is PolicyMeasurementState.RESOURCE_FRONTIER - ) - assert frontier["lane"] == resource_lane_identity(target) - assert frontier["root"] == { - "cell_id": source.cell_id, - "n_final": 2, - "kind": PolicyCensorKind.MEMORY_LIMIT.value, - "status": "memory_limit", - "censor_sha256": root["provenance"]["policy_censor_sha256"], - } - - other_lane = REPORT_CATALOG.cell("scalar-gravity-n3-scalar-gravity-contracted") - with pytest.raises(CampaignPolicyError, match="same lane"): - resource_frontier_reference(other_lane, source, root) - - -def test_full_catalog_resource_lanes_are_unique_and_monotone( - tmp_path: Path, -) -> None: - cells = REPORT_CATALOG.measurement_cells() - identities = tuple( - (tuple(resource_lane_identity(cell).items()), cell.n_final) for cell in cells - ) - assert len(cells) == 2198 - assert len(set(identities)) == len(identities) - assert len({lane for lane, _n_final in identities}) == 448 - - selected = tuple( - REPORT_CATALOG.cell(cell_id) - for cell_id in ( - "scalar-contact-n2-scalar-contact-contracted", - "scalar-contact-n3-scalar-contact-contracted", - "scalar-gravity-n2-scalar-gravity-contracted", - "scalar-gravity-n3-scalar-gravity-contracted", - ) - ) - planned = plan_campaign( - selected, - store=ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ), - settings=_x86_settings(), - expected_revision=_REVISION, - expected_tree=_TREE, - ) - ranks = {item.cell.cell_id: item.rank for item in planned} - assert ( - ranks["scalar-contact-n3-scalar-contact-contracted"] - > ranks["scalar-contact-n2-scalar-contact-contracted"] - ) - assert ( - ranks["scalar-gravity-n3-scalar-gravity-contracted"] - > ranks["scalar-gravity-n2-scalar-gravity-contracted"] - ) - assert ( - ranks["scalar-contact-n2-scalar-contact-contracted"] - == ranks["scalar-gravity-n2-scalar-gravity-contracted"] - ) - - -def test_missing_only_reuses_and_rebinds_resource_frontier( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - source = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - target = REPORT_CATALOG.cell("scalar-contact-n3-scalar-contact-contracted") - first = _memory_censor( - source, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - store.new_attempt( - source.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(first) - frontier = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - target, - kind=PolicyCensorKind.RESOURCE_FRONTIER, - source_identity=_IDENTITY, - resources=None, - frontier=resource_frontier_reference(target, source, first), - ) - store.new_attempt( - target.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(frontier) - settings = _x86_settings(missing_only=True) - - assert ( - plan_campaign( - (target,), - store=store, - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - ) - == () - ) - - second = _memory_censor( - source, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 2, - ) - store.new_attempt( - source.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(second) - planned = plan_campaign( - (target,), - store=store, - settings=settings, - expected_revision=_REVISION, - expected_tree=_TREE, - ) - assert tuple(item.cell.cell_id for item in planned) == (target.cell_id,) - assert planned[0].force_recompare is True - - -def test_workspace_policy_is_bound_to_the_exact_measured_commit( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - profile = repo / "docs" / "performance_reports" / "x86_EPYC" - profile.mkdir(parents=True) - legacy_policy = X86_EPYC_POLICY.as_manifest() - legacy_policy["workers"] = X86_EPYC_LEGACY_WORKERS - legacy_policy["memory_limit_bytes"] = X86_EPYC_LEGACY_MEMORY_LIMIT_BYTES - manifest = { - "schema": WORKSPACE_SCHEMA, - "profile": "x86_EPYC", - "campaign_policy": legacy_policy, - } - (profile / WORKSPACE_MANIFEST).write_text( - json.dumps(manifest), - encoding="ascii", - ) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=repo, - check=True, - ) - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-qm", "profile"), cwd=repo, check=True) - revision = subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - assert ( - load_profile_campaign_policy( - repo, - "x86_EPYC", - expected_source_revision=revision, - ) - is X86_EPYC_POLICY - ) - manifest["campaign_policy"] = STRICT_POLICY.as_manifest() - (profile / WORKSPACE_MANIFEST).write_text( - json.dumps(manifest), - encoding="ascii", - ) - with pytest.raises(ReportWorkspaceError): - load_profile_campaign_policy( - repo, - "x86_EPYC", - expected_source_revision=revision, - ) - - -def test_legacy_workers_receive_distinct_pinned_shared_object_clones( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = tmp_path / "legacy-source" - source.mkdir() - subprocess.run(("git", "init", "-q"), cwd=source, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=source, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=source, - check=True, - ) - (source / "makefile").write_text("all:\n\t@true\n", encoding="ascii") - subprocess.run(("git", "add", "."), cwd=source, check=True) - subprocess.run(("git", "commit", "-qm", "legacy"), cwd=source, check=True) - legacy_revision = subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=source, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - class FakeLegacyApi: - default_repository = source - - def expected_revision(self) -> str: - return legacy_revision - - def validate_checkout(self, repository: Path) -> None: - observed = subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=repository, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - assert observed == legacy_revision - status = subprocess.run( - ("git", "status", "--porcelain=v1", "--untracked-files=no"), - cwd=repository, - check=True, - capture_output=True, - text=True, - ).stdout - assert status == "" - - monkeypatch.setattr( - "tools.performance_report.legacy.MaintainedLegacyApi", - FakeLegacyApi, - ) - repo = tmp_path / "repo" - (repo / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("fixture\n", encoding="ascii") - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-qm", "fixture"), cwd=repo, check=True) - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - - first_source, first_workspace = scheduler._legacy_workspace_paths("first") - second_source, second_workspace = scheduler._legacy_workspace_paths("second") - - assert first_source == second_source == source - assert first_workspace != second_workspace - assert not first_workspace.exists() and not second_workspace.exists() - with ( - _worker_legacy_workspace( - repository=None, - source_repository=first_source, - workspace=first_workspace, - copy_source=False, - ) as first, - _worker_legacy_workspace( - repository=None, - source_repository=second_source, - workspace=second_workspace, - copy_source=False, - ) as second, - ): - assert first is not None and second is not None - assert (first / ".git").is_dir() - assert (second / ".git").is_dir() - (first / "makefile").write_text("changed\n", encoding="ascii") - assert (second / "makefile").read_text(encoding="ascii") == "all:\n\t@true\n" - assert not first_workspace.exists() and not second_workspace.exists() - - -def test_legacy_generator_bootstrap_is_outside_generation_timing( - tmp_path: Path, -) -> None: - adapter = LegacyMeasurementAdapter( - api=SimpleNamespace(), - executor=SimpleNamespace(), - snapshotter=SimpleNamespace(), - structural_proof=False, - ) - commands: list[dict[str, object]] = [] - - def fake_run(args, **_kwargs): - commands.append( - { - "args": list(args), - "elapsed_seconds": 99.0 if not commands else 1.0, - } - ) - return SimpleNamespace() - - adapter._run = fake_run # type: ignore[method-assign] - process_file = tmp_path / "input-processes.txt" - process_file.write_text("process fixture\n", encoding="ascii") - - elapsed = adapter._generate_library( - context=SimpleNamespace( - entries=(), - process_file=process_file, - source_pdgs=(1, -1, 21, 21), - ), - repository=tmp_path / "legacy", - raw_color=False, - n_final=2, - process_key=None, - settings=LegacySettings(jobs=1), - commands=commands, - log_path=tmp_path / "legacy.log", - ) - - assert commands[0]["args"] == ["make", "-j1", "amplicol_generate"] - assert len(commands) == 5 - assert elapsed == 4.0 - - -def test_legacy_n1_library_generation_bypasses_zero_ht_scale( - tmp_path: Path, -) -> None: - adapter = LegacyMeasurementAdapter( - api=SimpleNamespace(), - executor=SimpleNamespace(), - snapshotter=SimpleNamespace(), - structural_proof=False, - ) - commands: list[dict[str, object]] = [] - - def fake_run(args, **_kwargs): - commands.append({"args": list(args), "elapsed_seconds": 1.0}) - return SimpleNamespace() - - adapter._run = fake_run # type: ignore[method-assign] - process_file = tmp_path / "input-processes.txt" - process_file.write_text("process fixture\n", encoding="ascii") - - adapter._generate_library( - context=SimpleNamespace( - entries=(), - process_file=process_file, - source_pdgs=(1, -1, 23), - ), - repository=tmp_path / "legacy", - raw_color=False, - n_final=1, - process_key="dd_z_jets", - settings=LegacySettings(jobs=1), - commands=commands, - log_path=tmp_path / "legacy.log", - ) - - generator = next( - command["args"] - for command in commands - if command["args"] and command["args"][0] == "./amplicol_generate" - ) - assert "--amplicol_momenta_probe=10" in generator - assert "--amplicol_probe_quiet" in generator - assert "--seed=101" not in generator - - -def test_scheduler_publishes_authenticated_generation_censor( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = _git_repo(tmp_path / "repo", "measured") - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - - def fake_supervise(command, **arguments): - channel = arguments["phase_channel"] - assert arguments["generation_timeout_seconds"] == 7200.0 - assert channel is not None - assert "--phase-state-path" in command - return SupervisedResult( - returncode=-15, - reason="generation_timeout", - usage=ResourceUsage(True, 1, 1, 0, 1.0, 7200.0), - generation_phase=GenerationPhaseEvidence( - configured_timeout_seconds=7200.0, - supervisor_reason="generation_timeout", - authenticated=True, - run_id=channel.run_id, - worker_pid=123, - final_sequence=1, - final_phase="generation", - generation_started_monotonic_ns=1, - generation_finished_monotonic_ns=None, - generation_elapsed_seconds=7200.0, - final_state_sha256="4" * 64, - error=None, - ), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler(service, settings=_x86_settings()) - - outcome = scheduler._run_cell( - PlannedCell( - cell=cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - ) - - assert outcome.status == PolicyMeasurementState.GENERATION_LIMIT.value - current = service.store.load_current(cell.cell_id) - assert current is not None - assert policy_status_label(current.result) == ">2h" - assert ( - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - current.result, - expected_source_revision=scheduler.source_revision, - expected_source_tree=scheduler.source_tree, - ) - is PolicyMeasurementState.GENERATION_LIMIT - ) - - -def test_z_table_f_scheduler_publishes_authenticated_one_hour_censor( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = _git_repo(tmp_path / "repo", "measured") - wrapper = _git_repo( - tmp_path / "wrapper", - "policy", - report_wrapper=True, - ) - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n8-dd-z-jets-selected-flow" - ) - - def fake_supervise(command, **arguments): - channel = arguments["phase_channel"] - assert Path(command[4]) == ( - wrapper / "src/pyamplicol/_profiling_campaign/result_tables.py" - ) - assert command[command.index("--repo-root") + 1] == str(repo) - assert command[command.index("--measurement-source-root") + 1] == str( - repo - ) - assert arguments["generation_timeout_seconds"] == 3600.0 - assert arguments["timeout_seconds"] is None - assert arguments["max_rss_bytes"] == 30_000_000_000 - assert arguments["scrub_import_environment"] is True - assert arguments["working_directory"] == repo - assert channel is not None - assert "--phase-state-path" in command - return SupervisedResult( - returncode=-15, - reason="generation_timeout", - usage=ResourceUsage( - available=True, - current_rss_bytes=100, - peak_rss_bytes=100, - child_count=0, - cpu_seconds=1.0, - wall_seconds=3600.0, - current_physical_footprint_bytes=120, - peak_physical_footprint_bytes=120, - current_guard_bytes=120, - peak_guard_bytes=120, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - ), - generation_phase=GenerationPhaseEvidence( - configured_timeout_seconds=3600.0, - supervisor_reason="generation_timeout", - authenticated=True, - run_id=channel.run_id, - worker_pid=123, - final_sequence=1, - final_phase="generation", - generation_started_monotonic_ns=1, - generation_finished_monotonic_ns=None, - generation_elapsed_seconds=3600.0, - final_state_sha256="4" * 64, - error=None, - ), - memory_limit_bytes=30_000_000_000, - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - monkeypatch.setattr( - CampaignScheduler, - "_legacy_workspace_paths", - lambda _self, attempt_id: ( - repo, - tmp_path / "legacy-workspaces" / attempt_id, - ), - ) - contract = create_z_table_f_study_contract( - repo, - wrapper, - prior_store=service.store, - ) - scheduler = CampaignScheduler( - service, - settings=_z_table_f_settings( - study_contract_sha256=str(contract["sha256"]), - ), - study_contract=contract, - study_contract_wrapper_root=wrapper, - ) - outcome = scheduler._run_cell( - PlannedCell( - cell=cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - ) - - assert outcome.status == PolicyMeasurementState.GENERATION_LIMIT.value - current = service.store.load_current(cell.cell_id) - assert current is not None - assert policy_status_label(current.result) == ">1h" - provenance = current.result["provenance"] - assert isinstance(provenance, dict) - assert provenance["study_contract"] == { - "abi": "pyamplicol-z-table-f-attempt-binding-v1", - "study_id": "macbook-m3-z-table-f", - "study_contract_sha256": contract["sha256"], - } - assert provenance["worker_harness"] == scheduler.worker_harness_identity - assert all( - str(repo) not in str(value) and str(wrapper) not in str(value) - for value in provenance["worker_harness"].values() - ) - assert _status(current.result) == r"\matrixstatus{ReportOrange}{>1h}" - assert ( - validate_policy_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - current.result, - expected_source_revision=scheduler.source_revision, - expected_source_tree=scheduler.source_tree, - ) - is PolicyMeasurementState.GENERATION_LIMIT - ) - - -def test_z_table_f_prepare_runs_authenticated_wrapper_and_returns_harness( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - measured = _git_repo(tmp_path / "measured", "measured") - wrapper = _git_repo( - tmp_path / "wrapper", - "policy", - report_wrapper=True, - ) - service = ReportService( - ReportPaths.from_repo( - measured, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - contract = create_z_table_f_study_contract( - measured, - wrapper, - prior_store=service.store, - ) - scheduler = CampaignScheduler( - service, - settings=_z_table_f_settings( - study_contract_sha256=str(contract["sha256"]), - ), - study_contract=contract, - study_contract_wrapper_root=wrapper, - ) - cell = REPORT_CATALOG.cell( - "z-builtin-sm-n8-dd-z-jets-eager-jit-o2-selected-flow" - ) - prepared = tmp_path / "prepared-model" - prepared.mkdir() - - def fake_supervise(command, **arguments): - assert Path(command[4]) == ( - wrapper / "src/pyamplicol/_profiling_campaign/result_tables.py" - ) - assert "_prepare" in command - assert arguments["scrub_import_environment"] is True - assert arguments["working_directory"] == measured - result_path = Path(command[command.index("--result-json") + 1]) - result_path.parent.mkdir(parents=True, exist_ok=True) - result_path.write_text( - json.dumps( - { - "path": str(prepared), - "reused": False, - "worker_harness": scheduler.worker_harness_identity, - } - ), - encoding="ascii", - ) - return SupervisedResult( - returncode=0, - reason="completed", - usage=ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler._ensure_prepared_model( - ( - PlannedCell( - cell=cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ), - ) - ) - - assert scheduler._prepared_model_paths[cell.measurement.model] == prepared - - -def test_z_table_f_scheduler_rejects_scope_and_missing_dependencies_before_attempt( - tmp_path: Path, -) -> None: - repo = _git_repo(tmp_path / "repo", "measured") - wrapper = _git_repo( - tmp_path / "wrapper", - "policy", - report_wrapper=True, - ) - artifact_root = tmp_path / "artifacts" - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=artifact_root, - coordination_root=tmp_path / "locks", - ) - ) - cell = REPORT_CATALOG.cell( - "scalar-contact-n2-scalar-contact-contracted" - ) - contract = create_z_table_f_study_contract( - repo, - wrapper, - prior_store=service.store, - ) - scheduler = CampaignScheduler( - service, - settings=_z_table_f_settings( - study_contract_sha256=str(contract["sha256"]), - ), - study_contract=contract, - study_contract_wrapper_root=wrapper, - ) - - dependent_cell = REPORT_CATALOG.cell( - "z-builtin-sm-n8-dd-z-jets-jit-o3-all-flow" - ) - expanded = plan_campaign( - (dependent_cell,), - store=service.store, - settings=scheduler.settings, - expected_revision=scheduler.source_revision, - expected_tree=scheduler.source_tree, - ) - requested = next(item for item in expanded if not item.dependency) - with pytest.raises( - StudyContractError, - match="unauthenticated comparison dependencies", - ): - scheduler._run_cell(requested) - - with pytest.raises(StudyContractError, match="outside the contracted"): - scheduler._run_cell( - PlannedCell( - cell=cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - ) - - assert service.store.load_current(cell.cell_id, missing_ok=True) is None - assert not tuple(artifact_root.rglob("manifest.json")) - - -def test_z_table_f_scheduler_rejects_bare_forged_sha_before_attempt( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - (repo / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("fixture\n", encoding="ascii") - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-qm", "fixture"), cwd=repo, check=True) - artifact_root = tmp_path / "artifacts" - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=artifact_root, - coordination_root=tmp_path / "locks", - ) - ) - - with pytest.raises( - StudyContractError, - match="not only a SHA-256", - ): - CampaignScheduler(service, settings=_z_table_f_settings()) - - assert not tuple(artifact_root.rglob("manifest.json")) - - -def test_scheduler_uses_mac_memory_limit_without_generation_channel( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - (repo / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("fixture\n", encoding="ascii") - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-qm", "fixture"), cwd=repo, check=True) - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - - def fake_supervise(_command, **arguments): - assert arguments["generation_timeout_seconds"] is None - assert arguments["phase_channel"] is None - assert arguments["max_rss_bytes"] == MACBOOK_M3_MEMORY_LIMIT_BYTES - rss = MACBOOK_M3_MEMORY_LIMIT_BYTES - 1 - physical = MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - return SupervisedResult( - returncode=-15, - reason="memory_limit", - usage=ResourceUsage( - available=True, - current_rss_bytes=rss, - peak_rss_bytes=rss, - child_count=0, - cpu_seconds=1.0, - wall_seconds=2.0, - current_physical_footprint_bytes=physical, - peak_physical_footprint_bytes=physical, - current_guard_bytes=physical, - peak_guard_bytes=physical, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - ), - memory_limit_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, - memory_limit_reason=("darwin-process-tree-physical-footprint-limit"), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler(service, settings=_mac_settings()) - outcome = scheduler._run_cell( - PlannedCell( - cell=cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - ) - - assert outcome.status == PolicyMeasurementState.MEMORY_LIMIT.value - current = service.store.load_current(cell.cell_id) - assert current is not None - assert policy_status_label(current.result) == ">30GB" - assert _status(current.result) == r"\matrixstatus{ReportOrange}{>30GB}" - assert ( - current.result["resources"]["peak_physical_footprint_bytes"] - == MACBOOK_M3_MEMORY_LIMIT_BYTES + 1 - ) - - -def test_scheduler_never_promotes_incomplete_memory_observation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - (repo / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("fixture\n", encoding="ascii") - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-qm", "fixture"), cwd=repo, check=True) - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - probe_reason = "darwin-process-tree-physical-footprint-probe-unavailable" - usage = ResourceUsage( - available=False, - current_rss_bytes=None, - peak_rss_bytes=None, - child_count=None, - cpu_seconds=None, - wall_seconds=2.0, - error="synthetic footprint probe failure", - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_probe_reason=probe_reason, - ) - - def fake_supervise(_command, **_arguments): - return SupervisedResult( - returncode=-15, - reason="memory_probe_error", - usage=usage, - memory_limit_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler(service, settings=_mac_settings()) - outcome = scheduler._run_cell( - PlannedCell( - cell=cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - ) - - assert outcome.status == "error" - assert service.store.load_current(cell.cell_id, missing_ok=True) is None - assert ( - _resource_payload( - usage, - memory_limit_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, - )["memory_probe_reason"] - == probe_reason - ) - - -def test_terminal_comparison_peer_and_terminal_baseline_both_block() -> None: - baseline = SimpleNamespace(result={"status": "ok"}) - selected_peer = SimpleNamespace(result={"status": "ok"}) - terminal_peer_result = _memory_censor( - REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted"), - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - terminal_peer = SimpleNamespace(result=terminal_peer_result) - currents = { - "baseline": (baseline, PolicyMeasurementState.SUCCESS), - "selected": (selected_peer, PolicyMeasurementState.SUCCESS), - "recurrence": (terminal_peer, PolicyMeasurementState.MEMORY_LIMIT), - } - - resolved_baseline, peers, blockers = _partition_dependency_records( - baseline_cell_id="baseline", - comparison_peer_ids=("selected", "recurrence"), - currents=currents, # type: ignore[arg-type] - ) - - assert resolved_baseline is baseline - assert peers == {"selected": selected_peer} - assert len(blockers) == 1 - assert blockers[0]["cell_id"] == "recurrence" - - _baseline, _peers, blockers = _partition_dependency_records( - baseline_cell_id="recurrence", - comparison_peer_ids=("selected",), - currents=currents, # type: ignore[arg-type] - ) - assert len(blockers) == 1 - assert blockers[0]["cell_id"] == "recurrence" - - -def test_scheduler_frontier_censors_dependencies_but_not_explicit_cells( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - (repo / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("fixture\n", encoding="ascii") - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-qm", "fixture"), cwd=repo, check=True) - service = ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - scheduler = CampaignScheduler(service, settings=_x86_settings()) - source = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - target = REPORT_CATALOG.cell("scalar-contact-n3-scalar-contact-contracted") - peak = X86_EPYC_MEMORY_LIMIT_BYTES + 1 - root = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - source, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=scheduler.source_identity, - resources=_resources(peak), - observed_rss_bytes=peak, - ) - service.store.new_attempt( - source.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(root) - - def forbidden_supervisor(*_args, **_kwargs): - raise AssertionError("frontier target must not launch a worker") - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - forbidden_supervisor, - ) - outcome = scheduler._run_cell( - PlannedCell( - cell=target, - dependency=True, - baseline_cell_id=None, - rank=1, - ) - ) - - assert outcome.status == PolicyMeasurementState.RESOURCE_FRONTIER.value - current = service.store.load_current(target.cell_id) - assert current is not None - assert policy_status_label(current.result) == "dependency >80GB" - assert ( - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - target, - current.result, - expected_source_revision=scheduler.source_revision, - expected_source_tree=scheduler.source_tree, - ) - is PolicyMeasurementState.RESOURCE_FRONTIER - ) - - class ExplicitCellLaunched(RuntimeError): - pass - - def launched_supervisor(*_args, **_kwargs): - raise ExplicitCellLaunched - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - launched_supervisor, - ) - with pytest.raises(ExplicitCellLaunched): - scheduler._run_cell( - PlannedCell( - cell=target, - dependency=False, - baseline_cell_id=None, - rank=1, - ) - ) - - -def test_final_audit_counts_policy_terminal_cells_without_claiming_numerics( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = next( - cell for cell in REPORT_CATALOG.measurement_cells() if cell.n_final == 1 - ) - static_cell = REPORT_CATALOG.cell( - "reference-amplicol-full-n6-dd-4q-lines-contracted" - ) - - class OneCellCatalog: - matrix_datasets = () - process_families = () - scalar_datasets = () - z_variants = () - models: ClassVar[dict[object, object]] = {} - - def measurement_cells(self): - return (cell, static_cell) - - def baseline_cell(self, _cell): - return None - - def validation_baseline_cell(self, _cell): - return None - - def static_na_reason(self, candidate): - if candidate == static_cell: - return STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT - return None - - catalog = OneCellCatalog() - paths = ReportPaths.from_repo( - tmp_path, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - service = ReportService(paths, catalog=catalog) # type: ignore[arg-type] - terminal = _memory_censor( - cell, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - service.store.new_attempt( - cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(terminal) - caches = build_reset_caches(catalog) # type: ignore[arg-type] - for payload in caches.values(): - for entry in payload["entries"]: - if entry["cell_id"] == cell.cell_id: - entry["measurement"] = portable_publication_value( - terminal, - paths, - ) - paths.results_dir.mkdir(parents=True) - for name, payload in caches.items(): - (paths.results_dir / name).write_text( - json.dumps(payload), - encoding="ascii", - ) - monkeypatch.setattr( - service, - "audit", - lambda: {"cache_render_match": True}, - ) - - result = audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=6, - expected_cell_count=2, - catalog=catalog, # type: ignore[arg-type] - service=service, - source_auditor=lambda *_args: None, - pdf_auditor=lambda _service: {"status": "ok"}, - campaign_policy=X86_EPYC_POLICY, - ) - - assert result["policy_state_counts"] == {"memory_limit": 1} - assert result["policy_complete_cell_count"] == 1 - assert result["numerically_evidenced_cell_count"] == 0 - assert result["declared_cell_count"] == 2 - assert result["measurable_cell_count"] == 1 - assert result["catalog_static_na_cell_count"] == 1 - assert result["catalog_static_na_reason_counts"] == { - STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT: 1, - } - assert result["authenticated_current_count"] == 1 - visible = result["visible_completeness"] - assert isinstance(visible, dict) - assert visible["status"] == "ok" - assert visible["declared_measurement_cell_count"] == 2 - assert visible["required_measurement_count"] == 1 - assert visible["rendered_required_measurement_count"] == 1 - assert visible["catalog_static_na_cell_count"] == 1 - assert visible["rendered_catalog_static_na_cell_count"] == 1 - - service.store.new_attempt( - static_cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(empty_measurement()) - with pytest.raises( - FinalAuditError, - match="catalog static N/A cell has a published current", - ): - audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=6, - expected_cell_count=2, - catalog=catalog, # type: ignore[arg-type] - service=service, - source_auditor=lambda *_args: None, - verify_pdf=False, - campaign_policy=X86_EPYC_POLICY, - ) - - -def test_final_audit_requires_exact_monotone_resource_frontier( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - target = REPORT_CATALOG.cell("scalar-contact-n3-scalar-contact-contracted") - - class TwoCellCatalog: - matrix_datasets = () - process_families = () - scalar_datasets = () - z_variants = () - models: ClassVar[dict[object, object]] = {} - - def measurement_cells(self): - return (source, target) - - def baseline_cell(self, _cell): - return None - - def validation_baseline_cell(self, _cell): - return None - - def static_na_reason(self, _cell): - return None - - catalog = TwoCellCatalog() - paths = ReportPaths.from_repo( - tmp_path, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - service = ReportService(paths, catalog=catalog) # type: ignore[arg-type] - root = _memory_censor( - source, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 1, - ) - frontier = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - target, - kind=PolicyCensorKind.RESOURCE_FRONTIER, - source_identity=_IDENTITY, - resources=None, - frontier=resource_frontier_reference(target, source, root), - ) - - def publish(measurements: tuple[dict[str, object], ...]) -> None: - for cell, measurement in zip( - (source, target), - measurements, - strict=True, - ): - service.store.new_attempt( - cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(measurement) - caches = build_reset_caches(catalog) # type: ignore[arg-type] - for payload in caches.values(): - entries = payload["entries"] - assert isinstance(entries, list) - for entry in entries: - cell_id = str(entry["cell_id"]) - measurement = measurements[0 if cell_id == source.cell_id else 1] - entry["measurement"] = portable_publication_value( - measurement, - paths, - ) - paths.results_dir.mkdir(parents=True, exist_ok=True) - for name, payload in caches.items(): - (paths.results_dir / name).write_text( - json.dumps(payload), - encoding="ascii", - ) - - publish((root, frontier)) - monkeypatch.setattr( - service, - "audit", - lambda: {"cache_render_match": True}, - ) - result = audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=3, - expected_cell_count=2, - catalog=catalog, # type: ignore[arg-type] - service=service, - source_auditor=lambda *_args: None, - pdf_auditor=lambda _service: {"status": "ok"}, - campaign_policy=X86_EPYC_POLICY, - ) - assert result["hard_resource_censor_count"] == 1 - assert result["resource_frontier_cell_count"] == 1 - - second_root = _memory_censor( - target, - peak=X86_EPYC_MEMORY_LIMIT_BYTES + 2, - ) - publish((root, second_root)) - with pytest.raises( - FinalAuditError, - match="higher multiplicity is not bound to resource frontier", - ): - audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=3, - expected_cell_count=2, - catalog=catalog, # type: ignore[arg-type] - service=service, - source_auditor=lambda *_args: None, - pdf_auditor=lambda _service: {"status": "ok"}, - campaign_policy=X86_EPYC_POLICY, - ) diff --git a/pyamplicol/tests/unit/test_performance_report_campaign_reset.py b/pyamplicol/tests/unit/test_performance_report_campaign_reset.py deleted file mode 100644 index 791251d888..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_campaign_reset.py +++ /dev/null @@ -1,704 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.campaign_policy import MACBOOK_M3_POLICY -from tools.performance_report.campaign_reset import ( - BASELINE_GATE_FILENAME, - CAMPAIGN_MARKER_FILENAME, - EXPECTED_AMPLICOL_CELL_COUNT, - EXPECTED_CATALOG_CELL_COUNT, - EXPECTED_NON_AMPLICOL_CELL_COUNT, - CampaignResetError, - OriginalAmplicolSeed, - ResetTransactionPaths, - _lc_seed_family_rejections, - _legacy_contract, - assert_campaign_marker, - build_seed_manifest, - campaign_marker, - commit_or_recover_reset, - mark_campaign_ready, - sha256_payload, - stage_seed_store, - write_prepared_journal, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - ExecutionMode, - Workload, -) -from tools.performance_report.scheduler import CampaignSettings, plan_campaign -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity - -_REVISION = "1" * 40 -_TREE = "2" * 40 -_SHA = "3" * 64 - - -def _store(tmp_path: Path) -> ArtifactStore: - return ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - - -def _cell(mode: ExecutionMode): - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is mode - and ( - mode is not ExecutionMode.AMPLICOL - or cell.measurement.accuracy is not Accuracy.LC - ) - ) - - -def test_reset_cardinality_matches_the_current_catalog() -> None: - cells = REPORT_CATALOG.measurement_cells() - amplicol = sum( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL for cell in cells - ) - - assert EXPECTED_CATALOG_CELL_COUNT == len(cells) == 2198 - assert EXPECTED_AMPLICOL_CELL_COUNT == amplicol == 314 - assert EXPECTED_NON_AMPLICOL_CELL_COUNT == len(cells) - amplicol == 1884 - assert ( - sum(REPORT_CATALOG.static_na_reason(cell) is not None for cell in cells) == 34 - ) - assert sum(REPORT_CATALOG.static_na_reason(cell) is None for cell in cells) == 2164 - - -def _contract() -> dict[str, object]: - return { - "legacy_revision": "4" * 40, - "report_source_revision": _REVISION, - "report_source_tree": _TREE, - "compiler_sha256": "5" * 64, - "selector_contract_sha256": "6" * 64, - "validation_sha256": "7" * 64, - "resource_evidence_sha256": "8" * 64, - "target_runtime_seconds": 5.0, - "workload_specific_generation": True, - "row_selection_policy": "row-v1", - "selector_color_word_policy": "selector-v1", - } - - -def _publish(store: ArtifactStore, cell_id: str): - return store.new_attempt( - cell_id, - ArtifactPolicy.REGENERATE, - ).publish( - { - "status": "ok", - "provenance": { - "report_source_revision": _REVISION, - "report_source_tree": _TREE, - "report_measured_source_revision": _REVISION, - "report_measured_source_tree": _TREE, - }, - } - ) - - -def _activate_marker( - root: Path, - seed: dict[str, object], - *, - profile: str, - revision: str, - tree: str, -) -> None: - marker = campaign_marker( - campaign_id="campaign-1", - profile=profile, - source_revision=revision, - source_tree=tree, - policy_sha256=_SHA, - seed_manifest_sha256=str(seed["seed_manifest_sha256"]), - archive_manifest_sha256=_SHA, - ) - (root / CAMPAIGN_MARKER_FILENAME).write_text(json.dumps(marker)) - gate: dict[str, object] = { - "campaign_id": "campaign-1", - "profile": profile, - "source_revision": revision, - "source_tree": tree, - "prepared_marker_sha256": marker["marker_sha256"], - } - gate["baseline_gate_sha256"] = sha256_payload(gate) - (root / BASELINE_GATE_FILENAME).write_text(json.dumps(gate)) - mark_campaign_ready( - root, - baseline_gate_sha256=str(gate["baseline_gate_sha256"]), - ) - - -def test_contracted_amplicol_contract_accepts_no_selector() -> None: - record = SimpleNamespace( - cell_id="reference-amplicol-full-example", - result={ - "selector_contract": None, - "resources": {"monitor": "test", "peak_rss_bytes": 1}, - "validation": { - "status": "ok", - "method": "independent-original-amplicol-oracle", - "point_digest": _SHA, - }, - "provenance": { - "method": "original-amplicol-generated-library", - "revision": _REVISION, - "report_source_revision": _REVISION, - "report_source_tree": _TREE, - "report_measured_source_revision": _REVISION, - "report_measured_source_tree": _TREE, - "report_source_clean": True, - "compiler": { - "identity": "gfortran", - "version": "GNU Fortran", - "flags": ["-O3"], - "target": "test-target", - "executable_sha256": _SHA, - }, - "target_runtime_seconds": 5.0, - "runtime_profile": { - "measurement": {"target_runtime_achieved": True} - }, - "generation_timing_is_workload_specific": True, - "row_selection_policy": "row-v1", - "selector_color_word_policy": "selector-v1", - }, - }, - ) - - contract = _legacy_contract( - record, - requires_selector=False, - expected_legacy_revision=_REVISION, - ) - - assert contract["selector_contract_sha256"] is None - - -def _lc_record( - cell_id: str, - *, - point: str = "a" * 64, - common_value: float = 1.0, -) -> SimpleNamespace: - selector = { - "selected_color_flow_ids": ["flow:2,1"], - "selected_color_words": [[2, 1]], - "all_flow_helicity_ids": ["h:-1,+1"], - "all_flow_source_helicities": {"1": -1, "2": 1}, - "point_digest": point, - } - return SimpleNamespace( - cell_id=cell_id, - result={ - "selector_contract": selector, - "resources": {"monitor": "test", "peak_rss_bytes": 1}, - "validation": { - "status": "ok", - "method": "independent-original-amplicol-oracle", - "point_digest": point, - "lc_common_component": { - "abi": "pyamplicol-report-lc-common-component-v1", - "cell_id": cell_id, - "value": common_value, - "point_digest": point, - "helicity_ids": ["h:-1,+1"], - "color_flow_ids": ["flow:2,1"], - }, - }, - "provenance": { - "method": "original-amplicol-generated-library", - "revision": _REVISION, - "report_source_revision": _REVISION, - "report_source_tree": _TREE, - "report_measured_source_revision": _REVISION, - "report_measured_source_tree": _TREE, - "report_source_clean": True, - "compiler": { - "identity": "gfortran", - "version": "GNU Fortran", - "flags": ["-O3"], - "target": "test-target", - "executable_sha256": _SHA, - }, - "target_runtime_seconds": 5.0, - "runtime_profile": { - "measurement": {"target_runtime_achieved": True} - }, - "generation_timing_is_workload_specific": True, - "row_selection_policy": "row-v1", - "selector_color_word_policy": "selector-v1", - }, - }, - ) - - -def test_lc_seed_rejects_stale_point_and_structural_zero() -> None: - record = _lc_record("reference-amplicol-lc-example-selected-flow") - - contract = _legacy_contract( - record, - requires_selector=True, - expected_legacy_revision=_REVISION, - expected_point_digest="a" * 64, - ) - assert contract["selector_contract_sha256"] is not None - - with pytest.raises(CampaignResetError, match="predates"): - _legacy_contract( - record, - requires_selector=True, - expected_legacy_revision=_REVISION, - expected_point_digest="b" * 64, - ) - with pytest.raises(CampaignResetError, match="structural zero"): - _legacy_contract( - _lc_record(record.cell_id, common_value=0.0), - requires_selector=True, - expected_legacy_revision=_REVISION, - expected_point_digest="a" * 64, - ) - - -def test_lc_seed_family_requires_matching_selected_and_all_flow() -> None: - selected = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.measurement.accuracy is Accuracy.LC - and cell.workload is Workload.SELECTED_FLOW - ) - all_flow = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == selected.dataset_id - and cell.process == selected.process - and cell.n_final == selected.n_final - and cell.measurement == selected.measurement - and cell.workload is Workload.ALL_FLOW - ) - cells = { - selected.cell_id: selected, - all_flow.cell_id: all_flow, - } - records = { - selected.cell_id: _lc_record(selected.cell_id), - all_flow.cell_id: _lc_record(all_flow.cell_id), - } - - assert ( - _lc_seed_family_rejections( - cells=cells, - records_by_cell=records, - admitted_cell_ids=set(cells), - ) - == {} - ) - - records[all_flow.cell_id].result["selector_contract"][ - "selected_color_flow_ids" - ] = ["flow:1,2"] - rejected = _lc_seed_family_rejections( - cells=cells, - records_by_cell=records, - admitted_cell_ids=set(cells), - ) - assert set(rejected) == set(cells) - assert all("contracts differ" in reason for reason in rejected.values()) - - incomplete = _lc_seed_family_rejections( - cells=cells, - records_by_cell=records, - admitted_cell_ids={selected.cell_id}, - ) - assert incomplete == { - selected.cell_id: ( - "LC seed family is incomplete; selected/all-flow rows must be " - "remeasured under one selector authority" - ) - } - - -def test_seed_selects_only_ok_original_amplicol_and_preserves_bytes( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = _store(tmp_path / "source") - reference = _cell(ExecutionMode.AMPLICOL) - candidate = _cell(ExecutionMode.RECURRENCE) - original = _publish(source, reference.cell_id) - _publish(source, candidate.cell_id) - monkeypatch.setattr( - "tools.performance_report.campaign_reset.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.campaign_reset.validate_policy_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.campaign_reset._legacy_contract", - lambda _record, **_kwargs: _contract(), - ) - - seed = build_seed_manifest( - profile="macbook_M3", - store=source, - policy=MACBOOK_M3_POLICY, - final_source_revision="9" * 40, - final_source_tree="a" * 40, - expected_legacy_revision="4" * 40, - ) - assert seed["seed_count"] == 1 - assert [pin["cell_id"] for pin in seed["pins"]] == [reference.cell_id] - - destination = stage_seed_store( - source_store=source, - destination_root=tmp_path / "fresh-artifacts", - destination_lock_root=tmp_path / "fresh-locks", - seed_manifest=seed, - ) - inherited = destination.load_current(reference.cell_id) - assert inherited is not None - assert inherited.attempt_id == original.attempt_id - assert destination.load_current(candidate.cell_id, missing_ok=True) is None - assert destination.cell_attempt_ids(reference.cell_id) == ( - original.attempt_id, - ) - loaded = OriginalAmplicolSeed.load( - destination.artifact_root / "original_amplicol_seed.json", - profile="macbook_M3", - store=destination, - ) - assert loaded.source_for_current( - inherited, - active_revision="9" * 40, - active_tree="a" * 40, - ) == (_REVISION, _TREE) - assert ( - loaded.source_for_current( - inherited, - active_revision="b" * 40, - active_tree="c" * 40, - ) - is None - ) - - -def test_seed_rejects_changed_current_pointer( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = _store(tmp_path / "source") - reference = _cell(ExecutionMode.AMPLICOL) - _publish(source, reference.cell_id) - monkeypatch.setattr( - "tools.performance_report.campaign_reset.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.campaign_reset.validate_policy_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.campaign_reset._legacy_contract", - lambda _record, **_kwargs: _contract(), - ) - seed = build_seed_manifest( - profile="macbook_M3", - store=source, - policy=MACBOOK_M3_POLICY, - final_source_revision="9" * 40, - final_source_tree="a" * 40, - expected_legacy_revision="4" * 40, - ) - destination = stage_seed_store( - source_store=source, - destination_root=tmp_path / "fresh-artifacts", - destination_lock_root=tmp_path / "fresh-locks", - seed_manifest=seed, - ) - pointer = next(destination.cells_root.glob("*/current.json")) - payload = json.loads(pointer.read_text()) - payload["manifest_sha256"] = "0" * 64 - pointer.write_text(json.dumps(payload)) - - with pytest.raises(Exception, match="digest"): - OriginalAmplicolSeed.load( - destination.artifact_root / "original_amplicol_seed.json", - profile="macbook_M3", - store=destination, - ) - - -@pytest.mark.parametrize( - ("catalog_count", "amplicol_count"), - ((1646, 284), (1796, 314)), -) -def test_seed_load_accepts_only_supported_historical_catalog_cardinality( - tmp_path: Path, - catalog_count: int, - amplicol_count: int, -) -> None: - store = _store(tmp_path) - seed_path = store.artifact_root / "original_amplicol_seed.json" - seed_path.parent.mkdir(parents=True, exist_ok=True) - payload: dict[str, object] = { - "schema": "pyamplicol-original-amplicol-seed-v1", - "profile": "x86_EPYC", - "final_source_revision": _REVISION, - "final_source_tree": _TREE, - "expected_legacy_revision": "4" * 40, - "catalog_cell_count": catalog_count, - "amplicol_catalog_cell_count": amplicol_count, - "seed_count": 0, - "pins": [], - "rejected": [], - } - payload["seed_manifest_sha256"] = sha256_payload(payload) - seed_path.write_text(json.dumps(payload), encoding="ascii") - - loaded = OriginalAmplicolSeed.load( - seed_path, - profile="x86_EPYC", - store=store, - ) - assert loaded.pins_by_cell == {} - - payload.pop("seed_manifest_sha256") - payload["catalog_cell_count"] = catalog_count - 1 - payload["seed_manifest_sha256"] = sha256_payload(payload) - seed_path.write_text(json.dumps(payload), encoding="ascii") - with pytest.raises(CampaignResetError, match="catalog coverage differs"): - OriginalAmplicolSeed.load( - seed_path, - profile="x86_EPYC", - store=store, - ) - - -def test_reset_transaction_moves_old_roots_and_is_idempotent( - tmp_path: Path, -) -> None: - source_publication = tmp_path / "old-publication" - source_artifacts = tmp_path / "old-artifacts" - source_coordination = tmp_path / "old-coordination" - destination_publication = tmp_path / "new-publication" - destination_artifacts = tmp_path / "new-artifacts" - destination_coordination = tmp_path / "new-coordination" - archive = tmp_path / "archive" - staging = tmp_path / "staging" - for path, name in ( - (source_publication, "old-doc"), - (source_artifacts, "old-artifact"), - (source_coordination, "old-lock"), - (staging / "archive-publication", "archived-doc"), - (staging / "fresh-artifacts", "seed"), - (staging / "fresh-coordination", "fresh-lock"), - (staging / "fresh-publication", "fresh-doc"), - ): - path.mkdir(parents=True) - (path / name).write_text(name) - (staging / "archive-manifest.json").write_text("{}") - paths = ResetTransactionPaths( - source_publication=source_publication, - source_artifact_root=source_artifacts, - source_coordination_root=source_coordination, - destination_publication=destination_publication, - destination_artifact_root=destination_artifacts, - destination_coordination_root=destination_coordination, - archive_root=archive, - staging_root=staging, - guard_path=tmp_path / "reset.guard", - ) - write_prepared_journal( - profile="macbook_M3", - campaign_id="campaign-1", - archive_id="archive-1", - paths=paths, - archive_manifest_sha256=_SHA, - seed_manifest_sha256=_SHA, - marker_sha256=_SHA, - ) - - first = commit_or_recover_reset(paths.journal_path) - second = commit_or_recover_reset(paths.journal_path) - - assert first["state"] == second["state"] == "COMMITTED" - assert (archive / "artifacts" / "old-artifact").is_file() - assert (archive / "coordination" / "old-lock").is_file() - assert (archive / "publication" / "archived-doc").is_file() - assert (destination_artifacts / "seed").is_file() - assert (destination_coordination / "fresh-lock").is_file() - assert (destination_publication / "fresh-doc").is_file() - - -def test_campaign_marker_is_digest_bound(tmp_path: Path) -> None: - marker = campaign_marker( - campaign_id="campaign-1", - profile="x86_EPYC", - source_revision=_REVISION, - source_tree=_TREE, - policy_sha256=_SHA, - seed_manifest_sha256=_SHA, - archive_manifest_sha256=_SHA, - ) - root = tmp_path / "artifacts" - root.mkdir() - (root / CAMPAIGN_MARKER_FILENAME).write_text(json.dumps(marker)) - - with pytest.raises(CampaignResetError, match="not READY"): - assert_campaign_marker( - root, - campaign_id="campaign-1", - profile="x86_EPYC", - source_revision=_REVISION, - source_tree=_TREE, - ) - assert assert_campaign_marker( - root, - campaign_id="campaign-1", - profile="x86_EPYC", - source_revision=_REVISION, - source_tree=_TREE, - require_ready=False, - )["marker_sha256"] == marker["marker_sha256"] - - marker["campaign_id"] = "different" - (root / CAMPAIGN_MARKER_FILENAME).write_text(json.dumps(marker)) - with pytest.raises(CampaignResetError, match="differs"): - assert_campaign_marker( - root, - campaign_id="campaign-1", - profile="x86_EPYC", - source_revision=_REVISION, - source_tree=_TREE, - require_ready=False, - ) - - -def test_seed_is_authorized_by_scheduler_and_report_merge( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = _store(tmp_path / "source") - reference = _cell(ExecutionMode.AMPLICOL) - _publish(source, reference.cell_id) - for target in ( - "tools.performance_report.campaign_reset.validate_measurement", - "tools.performance_report.campaign_reset.validate_policy_measurement", - ): - monkeypatch.setattr(target, lambda *_args, **_kwargs: None) - monkeypatch.setattr( - "tools.performance_report.campaign_reset._legacy_contract", - lambda _record, **_kwargs: _contract(), - ) - seed = build_seed_manifest( - profile="macbook_M3", - store=source, - policy=MACBOOK_M3_POLICY, - final_source_revision="9" * 40, - final_source_tree="a" * 40, - expected_legacy_revision="4" * 40, - ) - artifact_root = ( - tmp_path - / "repo" - / ".artifacts" - / "performance-report" - / "macbook_M3" - ) - coordination_root = ( - tmp_path - / "repo" - / ".artifacts" - / "performance-report-coordination" - / "macbook_M3" - ) - destination = stage_seed_store( - source_store=source, - destination_root=artifact_root, - destination_lock_root=coordination_root, - seed_manifest=seed, - ) - _activate_marker( - artifact_root, - seed, - profile="macbook_M3", - revision="9" * 40, - tree="a" * 40, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.validate_policy_measurement", - lambda *_args, **_kwargs: None, - ) - settings = CampaignSettings( - workers=1, - cell_cores=1, - target_runtime_seconds=5.0, - max_rss_bytes=30_000_000_000, - campaign_policy=MACBOOK_M3_POLICY, - report_profile="macbook_M3", - missing_only=True, - ) - assert plan_campaign( - (reference,), - store=destination, - settings=settings, - expected_revision="9" * 40, - expected_tree="a" * 40, - ) == () - - repo = tmp_path / "repo" - docs = repo / "docs" / "performance_reports" / "macbook_M3" - docs.mkdir(parents=True) - service = ReportService( - ReportPaths( - repo_root=repo, - docs_dir=docs, - results_dir=docs / "results", - artifact_root=artifact_root, - coordination_root=coordination_root, - ) - ) - monkeypatch.setattr( - "tools.performance_report.service.require_eligible_report_source", - lambda _root: ReportSourceIdentity("9" * 40, "a" * 40, ()), - ) - monkeypatch.setattr( - "tools.performance_report.service.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.cache.validate_measurement", - lambda *_args, **_kwargs: None, - ) - caches = service.reset_payloads() - assert service.merge_current(caches) == 1 - measurement = next( - entry["measurement"] - for cache in caches.values() - for entry in cache["entries"] - if entry["cell_id"] == reference.cell_id - ) - assert measurement["status"] == "ok" diff --git a/pyamplicol/tests/unit/test_performance_report_cli.py b/pyamplicol/tests/unit/test_performance_report_cli.py deleted file mode 100644 index 259d2283b6..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_cli.py +++ /dev/null @@ -1,839 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import subprocess -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.performance_report import final_audit -from tools.performance_report.campaign_policy import ( - MACBOOK_M3_POLICY, - MACBOOK_M3_Z_TABLE_F_POLICY_NAME, - X86_EPYC_POLICY, - CampaignPolicyError, - PolicyMeasurementState, - validate_policy_measurement, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.cli import ( - _compile_pdf, - _is_pinned_epyc_orphan_without_rss, - _launch_async_publication, - _parser, - main, -) -from tools.performance_report.service import ReportPaths, ReportService - - -def _initialize_git_repo(repo: Path) -> None: - (repo / "src/pyamplicol/_profiling_campaign/results").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("# report fixture\n", encoding="ascii") - subprocess.run(("git", "add", "README.md"), cwd=repo, check=True) - subprocess.run( - ("git", "commit", "-q", "-m", "Initialize fixture"), - cwd=repo, - check=True, - ) - - -def _fake_latexmk(tmp_path: Path, log: str) -> Path: - executable = tmp_path / "fake-latexmk" - executable.write_text( - "#!/usr/bin/env python3\n" - "from pathlib import Path\n" - "assert not Path('campaign_artifacts').exists()\n" - "Path('pyAmpliCol.pdf').write_bytes(b'%PDF-1.4\\n%%EOF\\n')\n" - f"Path('pyAmpliCol.log').write_text({log!r}, encoding='utf-8')\n", - encoding="utf-8", - ) - executable.chmod(0o755) - return executable - - -def test_table_filler_defaults_to_five_seconds_per_cell() -> None: - populate = _parser().parse_args(("populate",)) - assert populate.target_runtime == 5.0 - assert populate.generation_time_limit_seconds is None - assert populate.fast_lineage is False - assert populate.exclude_cell_id == [] - - publisher = _parser().parse_args(("publish-snapshot",)) - assert publisher.watch is False - assert publisher.interval_seconds == 600.0 - assert publisher.pdf_timeout_seconds == 900.0 - assert publisher.expected_page_count == 73 - - worker = _parser().parse_args( - ( - "_worker", - "--cell-id", - "cell", - "--attempt-root", - "attempt", - "--result-json", - "result.json", - "--memory-limit-bytes", - "15000000000", - "--madgraph", - "/tmp/madgraph", - ) - ) - assert worker.target_runtime == 5.0 - assert worker.memory_limit_bytes == 15_000_000_000 - assert worker.madgraph == Path("/tmp/madgraph") - - limited = _parser().parse_args( - ("populate", "--generation-time-limit-seconds", "7200") - ) - assert limited.generation_time_limit_seconds == 7200.0 - - decimal_limits = _parser().parse_args( - ( - "populate", - "--max-ram-gb", - "30", - "--campaign-max-ram-gb", - "30", - ) - ) - assert decimal_limits.max_ram_gb == 30.0 - assert decimal_limits.campaign_max_ram_gb == 30.0 - - study = _parser().parse_args( - ( - "populate", - "--study-policy", - MACBOOK_M3_Z_TABLE_F_POLICY_NAME, - "--max-ram-gb", - "30", - ) - ) - assert study.study_policy == MACBOOK_M3_Z_TABLE_F_POLICY_NAME - assert study.max_ram_gb == 30.0 - - -def test_worker_cli_threads_madgraph_installation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = REPORT_CATALOG.measurement_cells()[0] - installation = tmp_path / "madgraph" - captured: dict[str, object] = {} - - def write( - cell_id: str, - result_path: Path, - **arguments: object, - ) -> dict[str, object]: - captured["cell_id"] = cell_id - captured["result_path"] = result_path - captured.update(arguments) - return {"status": "ok"} - - monkeypatch.setattr("tools.performance_report.cli.write_cell_result", write) - assert ( - main( - ( - "--repo-root", - str(tmp_path), - "_worker", - "--cell-id", - cell.cell_id, - "--attempt-root", - str(tmp_path / "attempt"), - "--result-json", - str(tmp_path / "result.json"), - "--madgraph", - str(installation), - ) - ) - == 0 - ) - - assert captured["cell_id"] == cell.cell_id - assert captured["madgraph_installation"] == installation - - -def test_async_publication_can_run_the_authenticated_wrapper_entrypoint( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - measured = tmp_path / "measured" - measured.mkdir() - wrapper_entrypoint = ( - tmp_path / "wrapper/src/pyamplicol/_profiling_campaign/result_tables.py" - ) - wrapper_entrypoint.parent.mkdir(parents=True) - wrapper_entrypoint.write_text("# authenticated wrapper\n", encoding="ascii") - service = ReportService( - ReportPaths.from_repo( - measured, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - captured: dict[str, object] = {} - - def popen(command, **arguments): - captured["command"] = tuple(command) - captured.update(arguments) - return SimpleNamespace() - - monkeypatch.setattr("tools.performance_report.cli.subprocess.Popen", popen) - - log_path = _launch_async_publication( - service, - entrypoint=wrapper_entrypoint, - ) - - command = captured["command"] - assert isinstance(command, tuple) - assert Path(command[4]) == wrapper_entrypoint.resolve() - assert command[command.index("--repo-root") + 1] == str( - measured.resolve() - ) - assert command[-1] == "publish-snapshot" - assert log_path == ( - service.paths.artifact_root - / "publication-logs/refresh-pdf-end.log" - ) - - -def test_pinned_epyc_orphan_is_the_only_unavailable_rss_exception() -> None: - cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n8-gg-gluons-selected-flow" - ) - measurement = { - "status": "ok", - "generation_seconds": 1.0, - "resources": { - "monitor": "external-cell-supervisor", - "peak_rss_gib": None, - }, - "provenance": { - "report_source_identity_schema": "pyamplicol-report-source-v1", - "report_source_revision": "1" * 40, - "report_source_tree": "2" * 40, - "report_measured_source_revision": "1" * 40, - "report_measured_source_tree": "2" * 40, - "report_source_clean": True, - }, - } - identity = { - "profile": "x86_EPYC", - "cell_id": cell.cell_id, - "attempt_id": "83e5c9c7-dbf6-4d61-b724-f4580df2cfa3", - "worker_result_sha256": ( - "5f3a42f9e3d034efedd8b670e7acbf2b54a427449106dbabc29050f3d93afbe6" - ), - "result": measurement, - } - - assert _is_pinned_epyc_orphan_without_rss(**identity) - with pytest.raises(CampaignPolicyError, match="resource monitoring"): - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - measurement, - expected_source_revision="1" * 40, - expected_source_tree="2" * 40, - ) - assert ( - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - measurement, - expected_source_revision="1" * 40, - expected_source_tree="2" * 40, - allow_pinned_orphan_unavailable_resources=True, - ) - is PolicyMeasurementState.SUCCESS - ) - - for field, value in ( - ("profile", "macbook_M3"), - ("cell_id", "reference-amplicol-lc-n7-gg-gluons-selected-flow"), - ("attempt_id", "00000000-0000-4000-8000-000000000000"), - ("worker_result_sha256", "0" * 64), - ): - changed = dict(identity) - changed[field] = value - assert not _is_pinned_epyc_orphan_without_rss(**changed) - - resources = measurement["resources"] - assert isinstance(resources, dict) - for tampered in ( - {"monitor": "external-cell-supervisor"}, - {"monitor": "external-cell-supervisor", "peak_rss_gib": 0.0}, - {"monitor": "other", "peak_rss_gib": None}, - { - "monitor": "external-cell-supervisor", - "peak_rss_gib": None, - "peak_rss_bytes": 0, - }, - ): - changed_measurement = dict(measurement) - changed_measurement["resources"] = tampered - changed = dict(identity) - changed["result"] = changed_measurement - assert not _is_pinned_epyc_orphan_without_rss(**changed) - with pytest.raises(CampaignPolicyError, match="resource monitoring"): - validate_policy_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - changed_measurement, - expected_source_revision="1" * 40, - expected_source_tree="2" * 40, - allow_pinned_orphan_unavailable_resources=True, - ) - - -def test_report_profile_is_a_global_architecture_scope() -> None: - parsed = _parser().parse_args(("--report-profile", "macbook_M3", "populate")) - assert parsed.report_profile == "macbook_M3" - - -def test_final_audit_is_routed_through_the_isolated_result_tables_entrypoint() -> None: - arguments = _parser().parse_args( - ( - "--report-profile", - "macbook_M3", - "final-audit", - "--expected-source-revision", - "a" * 40, - "--publication-revision", - "b" * 40, - "--structural-only", - ) - ) - - assert arguments.command == "final-audit" - assert arguments.report_profile == "macbook_M3" - assert arguments.expected_source_revision == "a" * 40 - assert arguments.publication_revision == "b" * 40 - assert arguments.max_n_final == 9 - assert arguments.expected_cell_count == 2198 - assert arguments.structural_only is True - - -def test_final_audit_receives_the_bound_architecture_profile_service( - tmp_path: Path, - monkeypatch, - capsys, -) -> None: - repo = tmp_path / "repo" - profile = "macbook_M3" - expected_paths = ReportPaths.from_repo(repo, profile=profile) - expected_service = ReportService(expected_paths) - observed: dict[str, object] = {} - environment_checks: list[tuple[Path, str, str]] = [] - - def construct_service(paths: ReportPaths) -> ReportService: - assert paths == expected_paths - return expected_service - - def fake_audit( - repo_root: Path, - **arguments: object, - ) -> dict[str, object]: - observed["repo_root"] = repo_root - observed.update(arguments) - return {"final_gate_complete": True} - - monkeypatch.setattr( - "tools.performance_report.cli.ReportService", - construct_service, - ) - monkeypatch.setattr( - "tools.performance_report.cli.require_active_profile_environment", - lambda root, active_profile, *, expected_source_revision: ( - environment_checks.append((root, active_profile, expected_source_revision)) - or {} - ), - ) - monkeypatch.setattr(final_audit, "audit_final_report", fake_audit) - - assert ( - main( - ( - "--repo-root", - str(repo), - "--report-profile", - profile, - "final-audit", - "--expected-source-revision", - "a" * 40, - "--publication-revision", - "b" * 40, - "--structural-only", - ) - ) - == 0 - ) - - assert observed["repo_root"] == repo.resolve() - assert observed["service"] is expected_service - assert expected_service.paths.docs_dir == ( - repo.resolve() / "docs/performance_reports/macbook_M3" - ) - assert expected_service.paths.artifact_root == ( - repo.resolve() / ".artifacts/performance-report/macbook_M3" - ) - assert expected_service.paths.coordination_root == ( - repo.resolve() / ".artifacts/performance-report-coordination/macbook_M3" - ) - assert observed["expected_source_revision"] == "a" * 40 - assert observed["expected_publication_revision"] == "b" * 40 - assert observed["max_n_final"] == 9 - assert observed["expected_cell_count"] == 2198 - assert observed["replay"] is False - assert environment_checks == [(repo.resolve(), profile, "a" * 40)] - assert json.loads(capsys.readouterr().out)["final_gate_complete"] is True - - -def test_refresh_environment_is_routed_to_the_active_profile( - tmp_path: Path, - monkeypatch, - capsys, -) -> None: - repo = tmp_path / "repo" - observed: dict[str, object] = {} - - def fake_refresh( - root: Path, - profile: str, - *, - expected_source_revision: str, - ) -> dict[str, str]: - observed.update( - { - "root": root, - "profile": profile, - "expected_source_revision": expected_source_revision, - } - ) - return { - "status": "authenticated", - "source_revision": expected_source_revision, - } - - monkeypatch.setattr( - "tools.performance_report.cli.refresh_profile_environment", - fake_refresh, - ) - - assert ( - main( - ( - "--repo-root", - str(repo), - "--report-profile", - "macbook_M3", - "refresh-profile-environment", - "--expected-source-revision", - "a" * 40, - ) - ) - == 0 - ) - - assert observed == { - "root": repo.resolve(), - "profile": "macbook_M3", - "expected_source_revision": "a" * 40, - } - assert json.loads(capsys.readouterr().out) == { - "status": "authenticated", - "source_revision": "a" * 40, - } - - -def test_final_audit_requires_an_architecture_profile( - tmp_path: Path, - monkeypatch, -) -> None: - called = False - - def fake_audit(*_args: object, **_kwargs: object) -> dict[str, object]: - nonlocal called - called = True - return {"final_gate_complete": True} - - monkeypatch.setattr(final_audit, "audit_final_report", fake_audit) - - with pytest.raises(SystemExit, match="2"): - main( - ( - "--repo-root", - str(tmp_path / "repo"), - "final-audit", - "--expected-source-revision", - "a" * 40, - ) - ) - - assert called is False - - -def test_refresh_pdf_rejects_successful_latex_with_overfull_box( - tmp_path: Path, - monkeypatch, -) -> None: - repo = tmp_path / "repo" - service = ReportService(ReportPaths.from_repo(repo)) - service.paths.docs_dir.mkdir(parents=True, exist_ok=True) - (service.paths.docs_dir / "campaign_artifacts").mkdir() - (service.paths.docs_dir / "campaign_artifacts/sentinel").write_text( - "private\n", - encoding="ascii", - ) - (service.paths.docs_dir / "pyAmpliCol.tex").write_text( - "\\documentclass{article}\\begin{document}bad\\end{document}\n", - encoding="ascii", - ) - executable = _fake_latexmk( - tmp_path, - "Overfull \\hbox (1.0pt too wide)\n", - ) - monkeypatch.setattr( - "tools.performance_report.cli.shutil.which", - lambda _name: str(executable), - ) - - with pytest.raises(RuntimeError, match="overfull"): - _compile_pdf(service) - - -def test_reset_and_validate_cli_use_new_service(tmp_path: Path, capsys) -> None: - repo = tmp_path / "repo" - _initialize_git_repo(repo) - - assert main(("--repo-root", str(repo), "reset")) == 0 - reset_output = capsys.readouterr().out - assert ( - "src/pyamplicol/_profiling_campaign/" - "result_matrix_recurrence_builtin_sm_lc_table.tex" - in reset_output - ) - - assert main(("--repo-root", str(repo), "validate")) == 0 - payload = json.loads(capsys.readouterr().out) - assert payload["table_count"] == 27 - assert payload["cache_count"] > 12 - - assert main(("--repo-root", str(repo), "audit")) == 0 - payload = json.loads(capsys.readouterr().out) - assert payload["cache_render_match"] - - -def test_populate_dry_run_supports_exact_filters_and_dependencies( - tmp_path: Path, - capsys, -) -> None: - repo = tmp_path / "repo" - _initialize_git_repo(repo) - main(("--repo-root", str(repo), "reset")) - capsys.readouterr() - subprocess.run( - ("git", "add", "src/pyamplicol/_profiling_campaign"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "commit", "-q", "-m", "Track reset profile"), - cwd=repo, - check=True, - ) - - assert ( - main( - ( - "--repo-root", - str(repo), - "populate", - "--dataset", - "matrix_compiled_builtin_sm_lc", - "--process-key", - "dd_z_jets", - "--n-final", - "1", - "--workload", - "selected-flow", - "--dry-run", - ) - ) - == 0 - ) - payload = json.loads(capsys.readouterr().out) - assert payload["requested"] == 1 - assert payload["scheduled"] == 1 - assert [cell["rank"] for cell in payload["cells"]] == [2] - - -def test_epyc_workers25_dry_run_never_creates_an_attempt( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys, -) -> None: - repo = tmp_path / "repo" - _initialize_git_repo(repo) - monkeypatch.setattr( - "tools.performance_report.cli.load_profile_campaign_policy", - lambda *_args, **_kwargs: X86_EPYC_POLICY, - ) - monkeypatch.setattr( - "tools.performance_report.cli.load_and_audit_measurement_lineage", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.artifacts.ArtifactStore.new_attempt", - lambda *_args, **_kwargs: pytest.fail("dry-run created an attempt"), - ) - command = ( - "--repo-root", - str(repo), - "--report-profile", - "x86_EPYC", - "populate", - "--dataset", - "matrix_compiled_builtin_sm_lc", - "--process-key", - "dd_z_jets", - "--n-final", - "1", - "--workload", - "selected-flow", - "--workers", - "25", - "--cell-cores", - "1", - "--target-runtime", - "5", - "--max-ram-gb", - "80", - "--allow-symbolica-parallel", - "--dry-run", - ) - - assert main(command) == 0 - assert json.loads(capsys.readouterr().out)["scheduled"] == 1 - - stale = list(command) - stale[stale.index("25")] = "10" - with pytest.raises(SystemExit): - main(tuple(stale)) - assert "workers=10, expected 25" in capsys.readouterr().err - - stale = list(command) - stale[stale.index("80")] = "100" - with pytest.raises(SystemExit): - main(tuple(stale)) - assert ( - "max_rss_bytes=100000000000, expected 80000000000" - in capsys.readouterr().err - ) - - -def test_profile_population_requires_the_active_authenticated_environment( - tmp_path: Path, - monkeypatch, - capsys, -) -> None: - repo = tmp_path / "repo" - _initialize_git_repo(repo) - expected_revision = subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - checked: list[tuple[Path, str, str]] = [] - scheduler_settings: list[object] = [] - - def require_environment( - root: Path, - profile: str, - *, - expected_source_revision: str, - ) -> dict[str, str]: - checked.append((root, profile, expected_source_revision)) - return {} - - class FakeScheduler: - def __init__(self, _service, *, settings) -> None: - self.settings = settings - scheduler_settings.append(settings) - - def run(self, planned): - return SimpleNamespace( - planned=planned, - outcomes=(), - failed=(), - ) - - monkeypatch.setattr( - "tools.performance_report.cli.require_active_profile_environment", - require_environment, - ) - monkeypatch.setattr( - "tools.performance_report.cli.load_profile_campaign_policy", - lambda *_args, **_kwargs: MACBOOK_M3_POLICY, - ) - monkeypatch.setattr( - "tools.performance_report.cli.CampaignScheduler", - FakeScheduler, - ) - - assert ( - main( - ( - "--repo-root", - str(repo), - "--report-profile", - "macbook_M3", - "populate", - "--dataset", - "matrix_compiled_builtin_sm_lc", - "--process-key", - "dd_z_jets", - "--n-final", - "1", - "--workload", - "selected-flow", - "--max-ram-gb", - "30", - ) - ) - == 0 - ) - - assert checked == [(repo.resolve(), "macbook_M3", expected_revision)] - assert len(scheduler_settings) == 1 - assert scheduler_settings[0].max_rss_bytes == 30_000_000_000 - assert scheduler_settings[0].campaign_max_rss_bytes is None - assert json.loads(capsys.readouterr().out)["planned"] == 1 - - -def test_profile_fast_lineage_skips_historical_replay( - tmp_path: Path, - monkeypatch, - capsys, -) -> None: - repo = tmp_path / "repo" - _initialize_git_repo(repo) - expected_revision = subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - expected_tree = subprocess.run( - ("git", "rev-parse", "HEAD^{tree}"), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - lineage = SimpleNamespace() - loaded: list[tuple[Path, Path, str, str]] = [] - bound: list[object] = [] - - def load_fast( - root: Path, - docs_dir: Path, - *, - expected_active_revision: str, - expected_active_tree: str, - ): - loaded.append( - ( - root, - docs_dir, - expected_active_revision, - expected_active_tree, - ) - ) - return lineage - - class FakeScheduler: - def __init__(self, service, *, settings) -> None: - assert settings.report_profile == "macbook_M3" - bound.append(service._authenticated_measurement_lineage) - - def run(self, planned): - return SimpleNamespace(planned=planned, outcomes=(), failed=()) - - monkeypatch.setattr( - "tools.performance_report.cli.load_measurement_lineage", - load_fast, - ) - monkeypatch.setattr( - "tools.performance_report.cli.load_and_audit_measurement_lineage", - lambda *_args, **_kwargs: pytest.fail("historical replay was called"), - ) - monkeypatch.setattr( - "tools.performance_report.cli.require_active_profile_environment", - lambda *_args, **_kwargs: {}, - ) - monkeypatch.setattr( - "tools.performance_report.cli.load_profile_campaign_policy", - lambda *_args, **_kwargs: MACBOOK_M3_POLICY, - ) - monkeypatch.setattr( - "tools.performance_report.cli.CampaignScheduler", - FakeScheduler, - ) - - assert ( - main( - ( - "--repo-root", - str(repo), - "--report-profile", - "macbook_M3", - "populate", - "--fast-lineage", - "--dataset", - "matrix_compiled_builtin_sm_lc", - "--process-key", - "dd_z_jets", - "--n-final", - "1", - "--workload", - "selected-flow", - "--max-ram-gb", - "30", - ) - ) - == 0 - ) - - assert loaded == [ - ( - repo.resolve(), - repo / "docs/performance_reports/macbook_M3", - expected_revision, - expected_tree, - ) - ] - assert bound == [lineage] - assert json.loads(capsys.readouterr().out)["planned"] == 1 diff --git a/pyamplicol/tests/unit/test_performance_report_final_audit.py b/pyamplicol/tests/unit/test_performance_report_final_audit.py deleted file mode 100644 index 40ea08a6c2..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_final_audit.py +++ /dev/null @@ -1,4840 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import io -import json -import sys -from collections import Counter -from collections.abc import Mapping -from contextlib import contextmanager -from copy import deepcopy -from dataclasses import dataclass, replace -from pathlib import Path -from types import SimpleNamespace - -import pytest - -import tools.performance_report.final_audit as final_audit_module -import tools.performance_report.runner as report_runner -from tools.performance_report.agreements import ( - DIRECT_AGREEMENT_FIELD, - INDEPENDENT_AUTHORITY_ABI, - INDEPENDENT_AUTHORITY_FIELD, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_FULL_COLOUR, - Z_RECURRENCE_CROSS_MODE, - agreement_edges, - attach_direct_agreements, - independent_numerical_authorities, -) -from tools.performance_report.arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - EMPTY_ARENA_PHASE_VECTOR_FIELDS, - ZERO_ARENA_COUNTER_FIELDS, - ZERO_ARENA_PHASE_TIME_FIELDS, - ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS, - build_arena_profile_evidence, - digest_arena_profile_value, -) -from tools.performance_report.cache import ( - build_reset_caches, - digest_json, - empty_measurement, - reset_entry, -) -from tools.performance_report.campaign_policy import PolicyMeasurementState -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.final_audit import ( - ArtifactEvidence, - FinalAuditError, - _active_runtime_snapshot, - _artifact_reference, - _audit_compiled_execution, - _audit_direct_agreements, - _audit_eager_execution, - _audit_effective_config_mapping, - _audit_measurement, - _audit_model_source, - _audit_on_the_fly_execution, - _audit_pdf, - _audit_pointwise, - _audit_recurrence_execution, - _audit_recurrence_source_pack, - _audit_replayed_direct_agreements, - _audit_runtime_identity, - _audit_runtime_profile_warmup_evidence, - _audit_tex_table_reachability, - _audit_unavailable_execution_timing, - _authenticated_effective_config, - _catalog_static_na_projection_errors, - _count_contract_matches_with_optional_categories, - _ensure_exact_cli_python, - _legacy_consumer_coverage, - _python_package_tree_identity, - _real_nonnegative, - _replay_count_contract_matches_direct_edges, - _runtime_for_measurement_source, - _runtime_namespace_paths, - _shared_artifact_contract, - _validation_baseline_for_audit, - audit_artifact, - audit_final_report, -) -from tools.performance_report.madgraph import madgraph_command_card -from tools.performance_report.measurement_lineage import ( - CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, -) -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - MeasurementSpec, - ModelKey, - Workload, -) -from tools.performance_report.publication import portable_publication_value -from tools.performance_report.render import VisibleCompleteness -from tools.performance_report.service import ReportPaths, ReportService - -_REVISION = "a" * 40 -_LEGACY_REVISION = "dcb3efbcbe89c51969818cddf48113fba19ad763" -_ARTIFACT_ID = "b" * 64 -_CAPABILITY = "rusticol.recurrence-direct-arena.complex-f64.v1" -_COLOR_CAPABILITY = "rusticol.recurrence-color.lc.v1" - - -def test_full_final_audit_distinguishes_declared_and_measurable_edge_totals() -> None: - declared_ids = {cell.cell_id for cell in REPORT_CATALOG.measurement_cells()} - measurable_ids = { - cell.cell_id - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is None - } - declared_edges = tuple( - edge - for edge in agreement_edges() - if edge.candidate.cell_id in declared_ids - and edge.baseline.cell_id in declared_ids - ) - measurable_edges = tuple( - edge - for edge in declared_edges - if edge.candidate.cell_id in measurable_ids - and edge.baseline.cell_id in measurable_ids - ) - - assert len(declared_edges) == 1973 - assert ( - len(declared_edges) == final_audit_module._EXPECTED_FULL_DIRECT_AGREEMENT_COUNT - ) - assert len(measurable_edges) == 1925 - assert sum( - final_audit_module._EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS.values() - ) == len(measurable_edges) - assert Counter(edge.kind for edge in measurable_edges) == ( - final_audit_module._EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS - ) - static_reasons = Counter( - REPORT_CATALOG.static_na_reason(cell) - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - ) - assert static_reasons == { - "native-backend-generation-cap-n6-v1": 24, - "original-amplicol-open-quark-line-limit": 10, - } - - n4_cells = tuple( - cell for cell in REPORT_CATALOG.measurement_cells() if cell.n_final <= 4 - ) - n4_ids = {cell.cell_id for cell in n4_cells} - n4_measurable_ids = { - cell.cell_id - for cell in n4_cells - if REPORT_CATALOG.static_na_reason(cell) is None - } - n4_edges = tuple( - edge - for edge in agreement_edges() - if edge.candidate.cell_id in n4_measurable_ids - and edge.baseline.cell_id in n4_measurable_ids - ) - assert len(n4_ids) == final_audit_module._EXPECTED_N4_CELL_COUNT == 1042 - assert Counter(edge.kind for edge in n4_edges) == ( - final_audit_module._EXPECTED_N4_DIRECT_AGREEMENT_COUNTS - ) - _empty_edges, empty_counts = _audit_direct_agreements( - (), - {}, - catalog=REPORT_CATALOG, - ) - assert set(empty_counts) == set( - final_audit_module._EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS - ) - - -@pytest.mark.parametrize( - ("expected_edges", "expected_replays"), - ( - ( - final_audit_module._EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS, - final_audit_module._EXPECTED_FULL_DIRECT_REPLAY_COUNTS, - ), - ( - final_audit_module._EXPECTED_N4_DIRECT_AGREEMENT_COUNTS, - final_audit_module._EXPECTED_N4_DIRECT_REPLAY_COUNTS, - ), - ), -) -def test_final_audit_count_contract_bounds_only_optional_authority_edges( - expected_edges: Mapping[str, int], - expected_replays: Mapping[str, int], -) -> None: - without_optional = dict(expected_edges) - without_optional[Z_RECURRENCE_CROSS_MODE] = 0 - without_optional[LC_LEGACY_PYAMPLICOL_COMPONENT] = 0 - assert _count_contract_matches_with_optional_categories( - without_optional, - expected_edges, - optional_categories={ - Z_RECURRENCE_CROSS_MODE, - LC_LEGACY_PYAMPLICOL_COMPONENT, - }, - ) - expected_without_optional_replays = dict(expected_replays) - expected_without_optional_replays[ - final_audit_module._FULLY_REPLAYED_PYAMPLICOL - ] -= expected_edges[Z_RECURRENCE_CROSS_MODE] - expected_without_optional_replays[ - final_audit_module._REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY - ] = 0 - assert _replay_count_contract_matches_direct_edges( - expected_without_optional_replays, - without_optional, - expected_replays, - ) - - optional_categories = { - Z_RECURRENCE_CROSS_MODE, - LC_LEGACY_PYAMPLICOL_COMPONENT, - } - for required_category in set(expected_edges) - optional_categories: - missing_required = dict(expected_edges) - missing_required[required_category] -= 1 - assert not _count_contract_matches_with_optional_categories( - missing_required, - expected_edges, - optional_categories=optional_categories, - ) - - for optional_category in optional_categories: - too_many_optional = dict(expected_edges) - too_many_optional[optional_category] += 1 - assert not _count_contract_matches_with_optional_categories( - too_many_optional, - expected_edges, - optional_categories=optional_categories, - ) - - missing_required_replay = dict(expected_without_optional_replays) - missing_required_replay[final_audit_module._FULLY_REPLAYED_PYAMPLICOL] -= 1 - assert not _replay_count_contract_matches_direct_edges( - missing_required_replay, - without_optional, - expected_replays, - ) - - missing_available_z_replay = dict(expected_replays) - missing_available_z_replay[final_audit_module._FULLY_REPLAYED_PYAMPLICOL] -= 1 - assert not _replay_count_contract_matches_direct_edges( - missing_available_z_replay, - expected_edges, - expected_replays, - ) - - missing_available_legacy_replay = dict(expected_replays) - missing_available_legacy_replay[ - final_audit_module._REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY - ] -= 1 - assert not _replay_count_contract_matches_direct_edges( - missing_available_legacy_replay, - expected_edges, - expected_replays, - ) - - -def _fake_latexmk(tmp_path: Path, log: str) -> Path: - executable = tmp_path / "fake-latexmk" - executable.write_text( - "#!/usr/bin/env python3\n" - "from pathlib import Path\n" - "assert not Path('campaign_artifacts').exists()\n" - "Path('pyAmpliCol.pdf').write_bytes(b'%PDF-1.4\\n%%EOF\\n')\n" - f"Path('pyAmpliCol.log').write_text({log!r}, encoding='utf-8')\n", - encoding="utf-8", - ) - executable.chmod(0o755) - return executable - - -def _cell( - mode: ExecutionMode, - *, - backend: str = "jit", - optimization_level: int | None = 3, -) -> CellSpec: - return CellSpec( - dataset_id=f"test_{mode.value}", - process="d d~ > z", - n_final=1, - process_key="dd_z", - measurement=MeasurementSpec( - mode, - ModelKey.BUILTIN_SM, - Accuracy.LC, - backend, - optimization_level, - ), - workload=Workload.SELECTED_FLOW, - ) - - -@pytest.mark.parametrize( - "validation", - ( - { - "enabled": True, - "samples": 10, - "seed": 12345, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "post_build_validation": True, - }, - { - "enabled": True, - "samples": 1, - "seed": 12345, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "post_build_validation": False, - }, - ), -) -def test_final_audit_does_not_promote_generation_smoke_policy_to_identity( - validation: dict[str, object], -) -> None: - final_audit_module._audit_effective_config_mapping( - _cell(ExecutionMode.RECURRENCE), - { - "evaluator": { - "execution_mode": "recurrence", - "backend": "jit", - "jit": {"optimization_level": 3}, - }, - "color": { - "accuracy": "lc", - "lc_flow_layout": "topology-replay", - }, - "generation": {"validation": validation}, - }, - context="test effective config", - ) - - -def test_final_pdf_audit_rejects_successful_latex_with_overfull_box( - tmp_path: Path, - monkeypatch, -) -> None: - repo = tmp_path / "repo" - service = ReportService(ReportPaths.from_repo(repo)) - service.paths.docs_dir.mkdir(parents=True, exist_ok=True) - (service.paths.docs_dir / "campaign_artifacts").mkdir() - (service.paths.docs_dir / "campaign_artifacts/sentinel").write_text( - "private\n", - encoding="ascii", - ) - (service.paths.docs_dir / "pyAmpliCol.tex").write_text( - ( - "\\documentclass{article}\\begin{document}" - "\\input{result_test_table.tex}\\end{document}\n" - ), - encoding="ascii", - ) - (service.paths.docs_dir / "result_test_table.tex").write_text( - "bad\n", - encoding="ascii", - ) - (service.paths.docs_dir / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n%%EOF\n") - executable = _fake_latexmk( - tmp_path, - "Overfull \\vbox (1.0pt too high)\n", - ) - monkeypatch.setattr( - "tools.performance_report.final_audit.shutil.which", - lambda _name: str(executable), - ) - monkeypatch.setattr(ReportService, "load_caches", lambda _self: {}) - monkeypatch.setattr( - "tools.performance_report.final_audit.render_all_tables", - lambda *_args, **_kwargs: {"result_test_table.tex": "bad\n"}, - ) - - with pytest.raises(FinalAuditError, match="overfull"): - _audit_pdf(service) - - -def _recurrence_binding_digest(binding: dict[str, object]) -> str: - if binding["kind"] != "rusticol-intrinsic": - payload = dict(binding) - payload.pop("payload_digest", None) - return digest_json(payload) - fields = ( - "abi", - "contribution_parent_permutation", - "kind", - "runtime_template", - ) - return digest_json({field: binding.get(field) for field in fields}) - - -def _refresh_recurrence_source_catalog( - execution: dict[str, object], - pack: dict[str, object], - *, - refresh_binding_digest: bool = True, -) -> None: - catalog = pack["recurrence_direct_template"] - assert isinstance(catalog, dict) - templates = catalog["templates"] - assert isinstance(templates, list) - for template in templates: - assert isinstance(template, dict) - binding = template["payload_binding"] - assert isinstance(binding, dict) - if refresh_binding_digest: - binding["payload_digest"] = _recurrence_binding_digest(binding) - semantic = dict(template) - semantic.pop("semantic_digest", None) - template["semantic_digest"] = digest_json(semantic) - semantic_catalog = dict(catalog) - semantic_catalog.pop("catalog_digest", None) - catalog["catalog_digest"] = digest_json(semantic_catalog) - execution["direct_template_catalog_digest"] = catalog["catalog_digest"] - plan = execution["plan"] - assert isinstance(plan, dict) - plan["direct_template_catalog_digest"] = catalog["catalog_digest"] - - -def _canonical_symjit_evaluator( - application_path: str, - plane_path: str, - *, - optimization_level: int, - input_len: int = 1, - output_len: int = 1, -) -> dict[str, object]: - return { - "kind": "symjit-application-evaluator", - "runtime_capability": "symjit.application.complex-f64.v1", - "input_len": input_len, - "output_len": output_len, - "application_abi": "symjit-application-storage-v3", - "application_path": application_path, - "element_layout": "complex-f64", - "batch_layout": "row-major", - "compiler_type": "native", - "translation_mode": "indirect", - "optimization_level": optimization_level, - "word_bits": 64, - "endianness": "little", - "required_defuns": [], - "evaluator_state_path": f"{application_path}.state", - "evaluator_state_runtime_capability": ( - "symbolica.legacy-jit-container.complex-f64.v1" - ), - "plane_application": { - "application_path": plane_path, - "application_abi": "pyamplicol-symjit-plane-application-v2", - "storage_abi": "symjit-application-storage-v3", - "element_layout": "split-complex-plane-major", - "descriptor_order": "inputs-re-im-then-outputs-re-im", - "input_complex_count": input_len, - "output_complex_count": output_len, - "input_plane_count": 2 * input_len, - "output_plane_count": 2 * output_len, - "compiler_type": "native", - "translation_mode": "symbolica-structured-instructions", - "optimization_level": optimization_level, - "simd": True, - "complex": True, - "fast_math": True, - "fast_complex": False, - "compression": False, - "threading": False, - "direct_arena": True, - "source_digest": "1" * 64, - "target": {"word_bits": 64, "endianness": "little"}, - }, - } - - -def _recurrence_source_fixture( - source_sha256: str, -) -> tuple[dict[str, object], dict[str, object]]: - ordinary_source_path = "kernels/000000/application-0.symjit" - source_path = "kernels/000000/application-0.plane.symjit" - binding: dict[str, object] = { - "abi": "pyamplicol-recurrence-plane-binding-v2", - "contribution_parent_permutation": [0, 1], - "destination_operation": "finalize-in-place", - "direct_application_abi": "pyamplicol-symjit-plane-application-v2", - "exact_factor_scalar_slots": [0, 1], - "input_plane_count": 1, - "input_plane_projections": [{"kind": "destination-current"}], - "intrinsic_contract_digest": None, - "kind": "prepared-direct-call", - "output_alias_inputs": [0], - "parameter_bindings": [{"index": 0, "kind": "plane"}], - "payload_digest": "", - "payload_paths": [source_path], - "prepared_kernel_id": 0, - "prepared_template_semantic_digest": "d" * 64, - "role": "finalization", - "runtime_template": None, - "scalar_input_count": 2, - "scalar_projections": [ - {"imaginary": False, "kind": "exact-factor"}, - {"imaginary": True, "kind": "exact-factor"}, - ], - "source_application_abi": "pyamplicol-symjit-plane-application-v2", - "source_application_path": source_path, - "source_application_sha256": source_sha256, - "state_plane_indices": [], - } - template: dict[str, object] = { - "abi": "pyamplicol-recurrence-direct-template-v1", - "alignment_bytes": 64, - "backend": "jit", - "coupling_slot_count": 0, - "destination_aliasing": True, - "destination_component_count": 1, - "destination_operation": "finalize-in-place", - "direct_executor_id": 0, - "evaluator_binding_id": 0, - "evaluator_resolver_key": "prepared-kernel-0", - "exact_expression_digest": "e" * 64, - "momentum_operand_count": 0, - "optimization_level": 2, - "parameter_slot_count": 0, - "parent_arity": 1, - "parent_component_counts": [1], - "payload_binding": binding, - "portable": True, - "role": "finalization", - "semantic_digest": "", - "semantic_template_ids": ["prepared-finalization"], - "simd_axis": "points-contiguous", - "target_triple": "symjit-storage-v3-portable", - "template_id": "template-0", - } - prepared_digest = "a" * 64 - catalog: dict[str, object] = { - "abi": "pyamplicol-recurrence-direct-template-v1", - "backend": "jit", - "backend_abi": "rusticol.recurrence-direct-backend.v1", - "canonicalization_abi": "pyamplicol-canonical-json-v1", - "catalog_digest": "", - "compiled_model_digest": "b" * 64, - "optimization_level": 2, - "optimization_settings_digest": "c" * 64, - "portable": True, - "prepared_kernel_contract_digest": "4" * 64, - "prepared_kernel_pack_digest": prepared_digest, - "prepared_kernel_payload_digest": "5" * 64, - "recurrence_template_catalog_digest": "6" * 64, - "target_triple": "symjit-storage-v3-portable", - "templates": [template], - } - plan: dict[str, object] = { - "builder_input_abi": "pyamplicol-recurrence-builder-input-v2", - "recurrence_plan_abi": "pyamplicol-recurrence-plan-v2", - "runtime_layout_abi": "pyamplicol-recurrence-runtime-layout-v2", - "direct_template_abi": "pyamplicol-recurrence-direct-template-v1", - "direct_backend_abi": "rusticol.recurrence-direct-backend.v1", - "prepared_kernel_pack_digest": prepared_digest, - "direct_template_catalog_digest": "", - "inspection_summary": { - "direct_arena": { - "packed_input_bytes": 0, - "packed_output_bytes": 0, - "scatter_bytes": 0, - "row_group_count": 4, - } - }, - } - execution: dict[str, object] = { - "kind": "pyamplicol-runtime-recurrence-execution", - "builder_input_abi": "pyamplicol-recurrence-builder-input-v2", - "recurrence_plan_abi": "pyamplicol-recurrence-plan-v2", - "runtime_layout_abi": "pyamplicol-recurrence-runtime-layout-v2", - "direct_template_abi": "pyamplicol-recurrence-direct-template-v1", - "direct_backend_abi": "rusticol.recurrence-direct-backend.v1", - "prepared_kernel_pack_digest": prepared_digest, - "direct_template_catalog_digest": "", - "kernel_pack": { - "manifest_path": "model/eager-kernel-pack.json", - "payload_root": "model/eager-kernels", - }, - "required_runtime_capabilities": [_COLOR_CAPABILITY, _CAPABILITY], - "plan": plan, - } - pack: dict[str, object] = { - "backend": "jit", - "optimization_settings": { - "backend": "jit", - "jit_optimization_level": 2, - }, - "recurrence_direct_template": catalog, - "kernel_variants": [], - "kernels": [ - { - "kernel_id": 0, - "f64_evaluator_manifest": _canonical_symjit_evaluator( - ordinary_source_path, - source_path, - optimization_level=2, - ), - } - ], - } - _refresh_recurrence_source_catalog(execution, pack) - return execution, pack - - -def _legacy_cell() -> CellSpec: - return CellSpec( - dataset_id="reference_amplicol_lc", - process="d d~ > z", - n_final=1, - process_key="dd_z", - measurement=MeasurementSpec( - ExecutionMode.AMPLICOL, - None, - Accuracy.LC, - "fortran", - None, - ), - workload=Workload.SELECTED_FLOW, - ) - - -def test_catalog_static_na_projection_requires_reset_cache_and_no_current() -> None: - cell = replace( - _legacy_cell(), - dataset_id="reference_amplicol_static_na", - process="d d~ > u u~ s s~ c c~", - n_final=6, - process_key="dd_4q_lines", - ) - canonical = reset_entry(cell) - - assert ( - _catalog_static_na_projection_errors( - (cell,), - {cell.cell_id: canonical}, - load_current=lambda _cell_id: None, - ) - == () - ) - - tampered = deepcopy(canonical) - tampered["measurement"] = { - **empty_measurement(), - "status": "unsupported", - } - assert _catalog_static_na_projection_errors( - (cell,), - {cell.cell_id: tampered}, - load_current=lambda _cell_id: None, - ) == ( - f"{cell.cell_id}: catalog static N/A cache entry differs " - "from the canonical reset entry", - ) - assert _catalog_static_na_projection_errors( - (cell,), - {}, - load_current=lambda _cell_id: None, - ) == (f"{cell.cell_id}: cache entry is missing",) - assert _catalog_static_na_projection_errors( - (cell,), - {cell.cell_id: canonical}, - load_current=lambda _cell_id: object(), - ) == (f"{cell.cell_id}: catalog static N/A cell has a published current",) - - -def _compiled_stage( - *, - optimization_level: int = 3, - backend: str = "jit", -) -> dict[str, object]: - source_application_abi = ( - "pyamplicol-symjit-plane-application-v2" - if backend == "jit" - else "pyamplicol-native-compiled-direct-application-v1" - ) - application_abi = ( - "pyamplicol-compiled-plane-kernel-v2" - if backend == "jit" - else "pyamplicol-native-compiled-direct-application-v1" - ) - evaluator = ( - { - "kind": "symjit-application-evaluator", - "runtime_capability": "symjit.application.complex-f64.v1", - "input_len": 1, - "output_len": 1, - "application_abi": "symjit-application-storage-v3", - "application_path": "evaluators/stage.symjit", - "element_layout": "complex-f64", - "batch_layout": "row-major", - "compiler_type": "native", - "translation_mode": "indirect", - "optimization_level": optimization_level, - "word_bits": 64, - "endianness": "little", - "required_defuns": [], - "evaluator_state_path": "evaluators/stage.symjit.state", - "evaluator_state_runtime_capability": ( - "symbolica.legacy-jit-container.complex-f64.v1" - ), - "plane_application": { - "application_path": "evaluators/stage.plane.symjit", - "application_abi": "pyamplicol-symjit-plane-application-v2", - "storage_abi": "symjit-application-storage-v3", - "element_layout": "split-complex-plane-major", - "descriptor_order": "inputs-re-im-then-outputs-re-im", - "input_complex_count": 1, - "output_complex_count": 1, - "input_plane_count": 2, - "output_plane_count": 2, - "compiler_type": "native", - "translation_mode": "symbolica-structured-instructions", - "optimization_level": optimization_level, - "simd": True, - "complex": True, - "fast_math": True, - "fast_complex": False, - "compression": False, - "threading": False, - "direct_arena": True, - "source_digest": "1" * 64, - "target": {"word_bits": 64, "endianness": "little"}, - }, - } - if backend == "jit" - else { - "kind": "compiled-complex-evaluator", - "runtime_capability": (f"symbolica.compiled-{backend}.complex-f64.v1"), - } - ) - return { - "parameter_count": 1, - "output_length": 1, - "evaluator": evaluator, - "compiled_plane_arena": { - "schema_version": 1, - "kind": "compiled-plane-arena-stage", - "application_abi": application_abi, - "source_application_abi": source_application_abi, - "element_layout": "split-complex-component-major", - "output_operation": "overwrite", - "output_factor": "identity", - "input_output_aliasing": "forbidden", - "output_output_aliasing": "forbidden", - "input_bindings": [{"parameter_index": 0}], - "output_bindings": [{"output_index": 0}], - "leaves": [ - { - "application_path": ( - "evaluators/stage.plane.symjit" - if backend == "jit" - else "evaluators/stage.direct" - ), - "source_application_abi": source_application_abi, - "optimization_level": optimization_level, - "direct_codegen_optimization_level": optimization_level, - } - ], - }, - } - - -def test_compiled_arena_audits_fused_stages_and_parameter_exclusion() -> None: - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "stages": [_compiled_stage()], - "amplitude_stage": _compiled_stage(), - }, - "model_parameter_evaluator": { - "evaluator": {"application_abi": "symjit-application-storage-v3"} - }, - }, - } - assert _audit_compiled_execution( - execution, - _cell(ExecutionMode.COMPILED), - ) == (2, 2) - jit_o1 = deepcopy(execution) - for stage in ( - *jit_o1["compiled"]["stage_evaluators"]["stages"], # type: ignore[index] - jit_o1["compiled"]["stage_evaluators"]["amplitude_stage"], # type: ignore[index] - ): - stage["compiled_plane_arena"]["leaves"][0]["optimization_level"] = 1 - stage["compiled_plane_arena"]["leaves"][0][ - "direct_codegen_optimization_level" - ] = 1 - stage["evaluator"]["optimization_level"] = 1 - stage["evaluator"]["plane_application"]["optimization_level"] = 1 - assert _audit_compiled_execution( - jit_o1, - _cell(ExecutionMode.COMPILED, optimization_level=1), - ) == (2, 2) - - invalid_direct_codegen = deepcopy(execution) - invalid_direct_codegen["compiled"]["stage_evaluators"]["stages"][0][ # type: ignore[index] - "compiled_plane_arena" - ]["leaves"][0]["direct_codegen_optimization_level"] = 2 - with pytest.raises( - FinalAuditError, - match=r"leaf\.direct_codegen_optimization_level", - ): - _audit_compiled_execution( - invalid_direct_codegen, - _cell(ExecutionMode.COMPILED), - ) - - execution["compiled"]["model_parameter_evaluator"] = { # type: ignore[index] - "compiled_plane_arena": {} - } - with pytest.raises(FinalAuditError, match="model-parameter"): - _audit_compiled_execution(execution, _cell(ExecutionMode.COMPILED)) - - execution["compiled"]["model_parameter_evaluator"] = { # type: ignore[index] - "nested": {"native_direct_application": {}} - } - with pytest.raises(FinalAuditError, match="DirectApplication metadata"): - _audit_compiled_execution(execution, _cell(ExecutionMode.COMPILED)) - - execution["compiled"]["model_parameter_evaluator"] = { # type: ignore[index] - "nested": { - "application_abi": "pyamplicol-native-compiled-direct-application-v1" - } - } - with pytest.raises(FinalAuditError, match="direct application ABI"): - _audit_compiled_execution(execution, _cell(ExecutionMode.COMPILED)) - - -@pytest.mark.parametrize( - ("backend", "capability"), - [ - ("jit", "symjit.application.complex-f64.v1"), - ("cpp", "symbolica.compiled-cpp.complex-f64.v1"), - ("asm", "symbolica.compiled-asm.complex-f64.v1"), - ], -) -def test_compiled_arena_authenticates_source_runtime_capability( - backend: str, - capability: str, -) -> None: - stage = _compiled_stage(backend=backend) - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "stages": [], - "amplitude_stage": stage, - }, - }, - } - cell = _cell( - ExecutionMode.COMPILED, - backend=backend, - optimization_level=3 if backend == "jit" else None, - ) - assert _audit_compiled_execution(execution, cell) == (1, 1) - assert stage["evaluator"]["runtime_capability"] == capability # type: ignore[index] - - stage["evaluator"]["runtime_capability"] = "wrong.capability" # type: ignore[index] - with pytest.raises(FinalAuditError, match="runtime_capability"): - _audit_compiled_execution(execution, cell) - - -@pytest.mark.parametrize( - ("field", "value"), - ( - ("backend", "native"), - ("backend", None), - ("compiler_type", "interpreter"), - ), -) -def test_compiled_arena_rejects_contradictory_symjit_identity( - field: str, - value: object, -) -> None: - stage = _compiled_stage() - stage["evaluator"][field] = value # type: ignore[index] - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "stages": [], - "amplitude_stage": stage, - }, - }, - } - - with pytest.raises(FinalAuditError, match=field): - _audit_compiled_execution(execution, _cell(ExecutionMode.COMPILED)) - - -def test_compiled_arena_accepts_fallback_free_portable_symjit_leaf() -> None: - stage = _compiled_stage() - evaluator = stage["evaluator"] - assert isinstance(evaluator, dict) - evaluator["evaluator_state_path"] = None - evaluator["evaluator_state_runtime_capability"] = None - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "stages": [], - "amplitude_stage": stage, - }, - }, - } - - assert _audit_compiled_execution( - execution, - _cell(ExecutionMode.COMPILED), - ) == (1, 1) - - -@pytest.mark.parametrize( - ("state_path", "capability"), - ( - (None, "symbolica.legacy-jit-container.complex-f64.v1"), - ("evaluators/stage.symjit.state", None), - ), -) -def test_compiled_arena_rejects_partial_symjit_fallback_pair( - state_path: str | None, - capability: str | None, -) -> None: - stage = _compiled_stage() - evaluator = stage["evaluator"] - assert isinstance(evaluator, dict) - evaluator["evaluator_state_path"] = state_path - evaluator["evaluator_state_runtime_capability"] = capability - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "stages": [], - "amplitude_stage": stage, - }, - }, - } - - with pytest.raises(FinalAuditError, match="evaluator_state_fallback"): - _audit_compiled_execution(execution, _cell(ExecutionMode.COMPILED)) - - -@pytest.mark.parametrize( - "target", - ( - {"word_bits": 64.0, "endianness": "little"}, - { - "word_bits": 64, - "endianness": "little", - "cpu_features": ["z", "a"], - }, - {"word_bits": 64, "endianness": "little", "unknown": True}, - ), -) -def test_compiled_arena_rejects_noncanonical_symjit_target( - target: dict[str, object], -) -> None: - stage = _compiled_stage() - evaluator = stage["evaluator"] - assert isinstance(evaluator, dict) - plane = evaluator["plane_application"] - assert isinstance(plane, dict) - plane["target"] = target - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "stages": [], - "amplitude_stage": stage, - }, - }, - } - - with pytest.raises(FinalAuditError, match=r"plane_application\.target"): - _audit_compiled_execution(execution, _cell(ExecutionMode.COMPILED)) - - -def test_final_replay_matrix_conversion_rejects_sign_and_complex_drift() -> None: - assert _real_nonnegative(2.0 + 0.0j, "matrix") == 2.0 - assert _real_nonnegative(-1.0e-16 + 0.0j, "matrix") == 0.0 - with pytest.raises(FinalAuditError, match="materially negative"): - _real_nonnegative(-1.0e-3 + 0.0j, "matrix") - with pytest.raises(FinalAuditError, match="imaginary part"): - _real_nonnegative(1.0 + 1.0e-3j, "matrix") - - -def test_shared_artifact_contract_binds_the_exact_physics_cell() -> None: - cell = _cell(ExecutionMode.RECURRENCE, optimization_level=2) - dataset_alias = replace(cell, dataset_id="another_dataset") - different_process = replace( - cell, - process="u u~ > z", - process_key="uu_z", - ) - - assert _shared_artifact_contract(dataset_alias) == _shared_artifact_contract(cell) - assert _shared_artifact_contract(different_process) != _shared_artifact_contract( - cell - ) - - on_the_fly = _cell(ExecutionMode.ON_THE_FLY, optimization_level=2) - all_flow = replace(on_the_fly, workload=Workload.ALL_FLOW) - assert _shared_artifact_contract(on_the_fly) == _shared_artifact_contract(all_flow) - - -def test_native_otf_seed_inspector_wraps_native_decode_errors( - monkeypatch: pytest.MonkeyPatch, -) -> None: - class NativeDecodeError(Exception): - pass - - module = SimpleNamespace( - _inspect_on_the_fly_process_seed_v1=lambda _payload: (_ for _ in ()).throw( - NativeDecodeError("malformed native seed") - ) - ) - monkeypatch.setattr( - final_audit_module.importlib, - "import_module", - lambda _name: module, - ) - - with pytest.raises(FinalAuditError, match="cannot be decoded") as error: - final_audit_module._native_on_the_fly_process_seed_identity(b"bad-seed") - assert isinstance(error.value.__cause__, NativeDecodeError) - - -def test_otf_artifact_audit_accepts_only_compact_seed_and_prepared_jit_contract( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import importlib.util - from types import ModuleType - - # Load the pure-Python PACBIN codec without importing the intentionally - # stale shared-tree native runtime used by this publication-only test. - package = ModuleType("pyamplicol") - package.__path__ = [] # type: ignore[attr-defined] - generation = ModuleType("pyamplicol.generation") - generation.__path__ = [] # type: ignore[attr-defined] - codec_name = "pyamplicol.generation.evaluator_container" - codec_path = ( - Path(__file__).resolve().parents[2] - / "src/pyamplicol/generation/evaluator_container.py" - ) - spec = importlib.util.spec_from_file_location(codec_name, codec_path) - assert spec is not None and spec.loader is not None - codec = importlib.util.module_from_spec(spec) - monkeypatch.setitem(sys.modules, "pyamplicol", package) - monkeypatch.setitem(sys.modules, "pyamplicol.generation", generation) - monkeypatch.setitem(sys.modules, codec_name, codec) - spec.loader.exec_module(codec) - PacbinMemberKind = codec.PacbinMemberKind - PacbinMemberSource = codec.PacbinMemberSource - write_pacbin_atomic = codec.write_pacbin_atomic - - process_id = "otf_dd_z" - pack_relative = "model/eager-kernel-pack.json" - runtime_relative = f"processes/{process_id}/on-the-fly-runtime.pacbin" - seed_identity = { - "abi": "pyamplicol-on-the-fly-process-seed-identity-v1", - "process_digest": "1" * 64, - "compiled_model_digest": "2" * 64, - "recurrence_template_catalog_digest": "3" * 64, - "prepared_kernel_pack_digest": "4" * 64, - "recurrence_direct_template_catalog_digest": "5" * 64, - "semantic_digest": "6" * 64, - "external_permutation": [0, 1, 2], - "external_sources": [ - { - "source_slot": 0, - "public_label": 1, - "is_initial": True, - "states": [ - { - "state_index": 0, - "public_helicity": -1, - "prepared_mass_parameter_slot": None, - } - ], - }, - { - "source_slot": 1, - "public_label": 2, - "is_initial": True, - "states": [ - { - "state_index": 0, - "public_helicity": 1, - "prepared_mass_parameter_slot": None, - } - ], - }, - { - "source_slot": 2, - "public_label": 3, - "is_initial": False, - "states": [ - { - "state_index": 0, - "public_helicity": 0, - "prepared_mass_parameter_slot": 6, - } - ], - }, - ], - } - pack = { - "backend": "jit", - "eager_kernel_abi": "pyamplicol-eager-kernel-v1", - "dependency_abis": { - "symjit_application": "symjit-application-storage-v3", - "symjit_plane_application": "pyamplicol-symjit-plane-application-v2", - }, - "recurrence_template": { - "header": { - "compiled_model_digest": "2" * 64, - "catalog_digest": "3" * 64, - "prepared_kernel_pack_digest": "4" * 64, - } - }, - "recurrence_direct_template": { - "catalog_digest": "5" * 64, - "compiled_model_digest": "2" * 64, - "recurrence_template_catalog_digest": "3" * 64, - "prepared_kernel_pack_digest": "4" * 64, - }, - "optimization_settings": { - "backend": "jit", - "jit_optimization_level": 2, - }, - "kernels": [ - { - "contract_kind": "vertex", - "f64_evaluator_manifest": _canonical_symjit_evaluator( - "kernels/000000/application.symjit", - "kernels/000000/application.plane.symjit", - optimization_level=2, - ), - } - ], - "kernel_variants": [], - } - pack_path = tmp_path / pack_relative - pack_path.parent.mkdir(parents=True) - pack_data = json.dumps(pack, sort_keys=True).encode("ascii") - pack_path.write_bytes(pack_data) - runtime_path = tmp_path / runtime_relative - runtime_path.parent.mkdir(parents=True) - write_pacbin_atomic( - runtime_path, - ( - PacbinMemberSource( - "on-the-fly/process-seed-v1.bin", - PacbinMemberKind.ON_THE_FLY_PROCESS_SEED, - io.BytesIO(b"compact-process-seed"), - ), - ), - ) - runtime_data = runtime_path.read_bytes() - prepared_identity = { - "kind": "pyamplicol-prepared-kernel-pack-identity", - "schema_version": 1, - "abi": "pyamplicol-prepared-kernel-pack-identity-v2", - "backend": "jit", - "eager_kernel_abi": "pyamplicol-eager-kernel-v1", - "identity_sha256": "7" * 64, - "kernel_count": 1, - } - - def payload( - relative: str, - data: bytes, - *, - role: str, - media_type: str, - owner: str | None, - ) -> SimpleNamespace: - return SimpleNamespace( - path=relative, - size_bytes=len(data), - sha256=hashlib.sha256(data).hexdigest(), - role=role, - media_type=media_type, - process_id=owner, - executable=False, - ) - - manifest = SimpleNamespace( - payloads=( - payload( - pack_relative, - pack_data, - role="evaluator-manifest", - media_type="application/json", - owner=None, - ), - payload( - runtime_relative, - runtime_data, - role="evaluator-state", - media_type="application/octet-stream", - owner=process_id, - ), - ), - extensions={"eager_prepared_pack": prepared_identity}, - ) - execution = { - "schema_version": 3, - "kind": "pyamplicol-runtime-on-the-fly-execution", - "required_runtime_capabilities": [ - "rusticol.on-the-fly.complex-f64.v1", - "rusticol.on-the-fly.lc-color.v1", - ], - "process": "d d~ > z", - "key": process_id, - "color_accuracy": "lc", - "external_pdg_order": [1, -1, 23], - "kernel_pack": { - "manifest_path": pack_relative, - "payload_root": "model/eager-kernels", - }, - "runtime_options": { - "point_tile_size": 128, - "query_construction_threads": 4, - }, - "selector_policy": { - "color_coverage": "complete", - "reference_color_word": None, - "trace_reflections_folded": False, - "selector_census": { - "physical_helicity_count": 1, - "physical_color_flow_count": 1, - }, - }, - "runtime_metadata": { - "runtime_parameters": [], - "parameter_projection": [ - { - "runtime_name": "particle.23.mass", - "component": 0, - "prepared_parameter_id": 6, - } - ], - "external_legs": [ - { - "source_slot": 0, - "public_label": 1, - "outgoing_pdg": -1, - "is_initial": True, - }, - { - "source_slot": 1, - "public_label": 2, - "outgoing_pdg": 1, - "is_initial": True, - }, - { - "source_slot": 2, - "public_label": 3, - "outgoing_pdg": 23, - "is_initial": False, - }, - ], - "process_seed_identity": deepcopy(seed_identity), - }, - "runtime_container": { - "kind": "pyamplicol-on-the-fly-runtime-container", - "schema_version": 1, - "storage_abi": "pacbin-v1", - "path": "on-the-fly-runtime.pacbin", - "seed_member_path": "on-the-fly/process-seed-v1.bin", - }, - } - cell = _cell(ExecutionMode.ON_THE_FLY, optimization_level=2) - effective_config = {"evaluator": {"optimization": {"cores": 4}}} - monkeypatch.setattr( - final_audit_module, - "_expected_eager_prepared_pack_identity", - lambda _cell: dict(prepared_identity), - ) - monkeypatch.setattr( - final_audit_module, - "_native_on_the_fly_process_seed_identity", - lambda payload: ( - deepcopy(seed_identity) - if payload == b"compact-process-seed" - else (_ for _ in ()).throw(FinalAuditError("undecodable compact seed")) - ), - ) - - assert ( - _audit_on_the_fly_execution( - tmp_path, - manifest, - execution, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - effective_config=effective_config, - ) - == 1 - ) - - color_relative = f"processes/{process_id}/on-the-fly-color.bin" - color_data = b"authenticated-expanded-contracted-color" - color_path = tmp_path / color_relative - color_path.write_bytes(color_data) - color_sha256 = hashlib.sha256(color_data).hexdigest() - contracted_manifest = SimpleNamespace( - payloads=( - *manifest.payloads, - payload( - color_relative, - color_data, - role="evaluator-state", - media_type="application/octet-stream", - owner=process_id, - ), - ), - extensions=manifest.extensions, - ) - contracted_execution = deepcopy(execution) - contracted_execution["required_runtime_capabilities"] = [ - "rusticol.on-the-fly.complex-f64.v1", - "rusticol.on-the-fly.contracted-color.v1", - ] - contracted_execution["color_accuracy"] = "full" - contracted_execution["selector_policy"] = { - "color_coverage": "contracted", - "reference_color_word": None, - "trace_reflections_folded": False, - "selector_census": { - "physical_helicity_count": 1, - "physical_color_flow_count": 1, - }, - } - contracted_execution["runtime_metadata"]["color_contraction"] = { # type: ignore[index] - "abi": "pyamplicol-recurrence-color-contraction-v3", - "color_accuracy": "full", - "storage": "expanded", - "includes_color_factor": True, - "group_count": 2, - "sector_count": 2, - "active_sector_count": 2, - "component_count": 1, - "destination_count": 2, - "entry_count": 2, - "logical_entry_count": 2, - "semantic_digest": color_sha256, - "factorization": None, - "path": "on-the-fly-color.bin", - "size_bytes": len(color_data), - "sha256": color_sha256, - } - contracted_cell = replace( - cell, - measurement=replace(cell.measurement, accuracy=Accuracy.FULL), - workload=Workload.CONTRACTED, - ) - assert ( - _audit_on_the_fly_execution( - tmp_path, - contracted_manifest, - contracted_execution, - contracted_cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - effective_config=effective_config, - ) - == 1 - ) - - selected_contracted = deepcopy(contracted_execution) - selected_contracted["selector_policy"]["reference_color_word"] = [1] # type: ignore[index] - with pytest.raises(FinalAuditError, match="has a flow selector"): - _audit_on_the_fly_execution( - tmp_path, - contracted_manifest, - selected_contracted, - contracted_cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - with pytest.raises(FinalAuditError, match="payload is missing or ambiguous"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - contracted_execution, - contracted_cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - mismatched_threads = deepcopy(execution) - mismatched_threads["runtime_options"]["query_construction_threads"] = 3 # type: ignore[index] - with pytest.raises(FinalAuditError, match="effective evaluator cores"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - mismatched_threads, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - effective_config=effective_config, - ) - - for mutation in ("missing", "zero", "extra", "seed-mismatch"): - changed_execution = deepcopy(execution) - census = changed_execution["selector_policy"]["selector_census"] - assert isinstance(census, dict) - if mutation == "missing": - del census["physical_color_flow_count"] - elif mutation == "zero": - census["physical_helicity_count"] = 0 - elif mutation == "extra": - census["invented"] = 1 - else: - census["physical_helicity_count"] = 2 - with pytest.raises(FinalAuditError, match=r"selector (?:helicity )?census"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - changed_execution, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - for mutation in ("digest", "missing-abi", "wrong-abi", "extra-field"): - changed = dict(prepared_identity) - if mutation == "digest": - changed["identity_sha256"] = "8" * 64 - elif mutation == "missing-abi": - del changed["abi"] - elif mutation == "wrong-abi": - changed["abi"] = "pyamplicol-prepared-kernel-pack-identity-v1" - else: - changed["invented"] = True - changed_manifest = SimpleNamespace( - payloads=manifest.payloads, - extensions={"eager_prepared_pack": changed}, - ) - with pytest.raises(FinalAuditError, match="prepared-pack identity"): - _audit_on_the_fly_execution( - tmp_path, - changed_manifest, - execution, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - for field, replacement in ( - ("process_digest", "7" * 64), - ("semantic_digest", "8" * 64), - ("prepared_kernel_pack_digest", "9" * 64), - ): - changed_native = deepcopy(seed_identity) - changed_native[field] = replacement - monkeypatch.setattr( - final_audit_module, - "_native_on_the_fly_process_seed_identity", - lambda _payload, identity=changed_native: deepcopy(identity), - ) - with pytest.raises(FinalAuditError, match="does not identify"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - execution, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - monkeypatch.setattr( - final_audit_module, - "_native_on_the_fly_process_seed_identity", - lambda _payload: deepcopy(seed_identity), - ) - changed_state = deepcopy(execution) - changed_state["runtime_metadata"]["process_seed_identity"][ # type: ignore[index] - "external_sources" - ][2]["states"][0]["public_helicity"] = 1 - with pytest.raises(FinalAuditError, match="does not identify"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - changed_state, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - changed_anchor = deepcopy(execution) - changed_anchor["runtime_metadata"]["external_legs"][2][ # type: ignore[index] - "public_label" - ] = 9 - with pytest.raises(FinalAuditError, match="source identity disagrees"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - changed_anchor, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - changed_mass_slot = deepcopy(execution) - changed_mass_slot["runtime_metadata"]["parameter_projection"][0][ # type: ignore[index] - "prepared_parameter_id" - ] = 7 - with pytest.raises(FinalAuditError, match="mass slot differs"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - changed_mass_slot, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - monkeypatch.setattr( - final_audit_module, - "_native_on_the_fly_process_seed_identity", - lambda _payload: (_ for _ in ()).throw( - FinalAuditError("undecodable compact seed") - ), - ) - with pytest.raises(FinalAuditError, match="undecodable compact seed"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - execution, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - invented_seed_contract = deepcopy(execution) - invented_seed_contract["runtime_container"]["seed_member_path"] = ( # type: ignore[index] - "pyamplicol-on-the-fly-process-seed-v1" - ) - with pytest.raises(FinalAuditError, match="runtime container contract"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - invented_seed_contract, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - recurrence_plan = deepcopy(execution) - recurrence_plan["plan"] = {"materialized": True} - with pytest.raises(FinalAuditError, match="compact contract"): - _audit_on_the_fly_execution( - tmp_path, - manifest, - recurrence_plan, - cell, - process_id=process_id, - execution_manifest_path=f"processes/{process_id}/execution.json", - ) - - -def test_otf_effective_config_contract() -> None: - cell = replace( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - workload=Workload.ALL_FLOW, - ) - effective = { - "evaluator": { - "execution_mode": "on-the-fly", - "backend": "jit", - "jit": {"optimization_level": 2}, - }, - "color": {"accuracy": "lc", "lc_flow_layout": "topology-replay"}, - "generation": { - "relation_discovery": {"mode": "off"}, - "validation": { - "enabled": False, - "samples": 10, - "seed": 12345, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "post_build_validation": False, - }, - }, - } - - _audit_effective_config_mapping(cell, effective, context="otf") - - wrong_layout = deepcopy(effective) - wrong_layout["color"]["lc_flow_layout"] = "all-flow-union" # type: ignore[index] - with pytest.raises(FinalAuditError, match=r"color\.lc_flow_layout"): - _audit_effective_config_mapping(cell, wrong_layout, context="otf") - - -@pytest.mark.parametrize("workload", (Workload.SELECTED_FLOW, Workload.ALL_FLOW)) -def test_otf_artifact_audit_distinguishes_requested_and_physical_layout( - tmp_path: Path, - monkeypatch, - workload: Workload, -) -> None: - cell = replace( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - workload=workload, - ) - process_id = "d_dbar_to_z" - effective = { - "evaluator": { - "execution_mode": "on-the-fly", - "backend": "jit", - "jit": {"optimization_level": 2}, - }, - "color": {"accuracy": "lc", "lc_flow_layout": "topology-replay"}, - "generation": { - "relation_discovery": {"mode": "off"}, - "validation": { - "enabled": False, - "samples": 10, - "seed": 12345, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "post_build_validation": False, - }, - }, - } - capability = final_audit_module._ARENA_CAPABILITY[ExecutionMode.ON_THE_FLY] - process = { - "id": process_id, - "expression": cell.process, - "color_accuracy": cell.measurement.accuracy.value, - "required_runtime_capabilities": (capability,), - } - manifest = SimpleNamespace( - artifact_id=_ARTIFACT_ID, - producer={ - "version": "0.1.0.dev0+candidate.test", - "git_revision": _REVISION, - "native_build_inputs_sha256": "e" * 64, - }, - processes=(process,), - runtime={"engine_version": "runtime-v1"}, - ) - inspected = SimpleNamespace( - id=process_id, - execution_mode=ExecutionMode.ON_THE_FLY.value, - generation_specialized_axes=(), - selected_source_helicities=(), - selected_color_sector_ids=(), - lc_flow_layout="compact/query-local", - ) - inspection = SimpleNamespace(integrity="verified", processes=(inspected,)) - - monkeypatch.setattr( - "pyamplicol.artifacts.inspect_artifact", lambda _artifact: inspection - ) - monkeypatch.setattr( - "pyamplicol.artifacts.load_manifest", lambda *_args, **_kwargs: manifest - ) - monkeypatch.setattr( - final_audit_module, - "_authenticated_effective_config", - lambda _artifact, _manifest: effective, - ) - monkeypatch.setattr( - final_audit_module, "_audit_model_source", lambda _cell, _effective: None - ) - monkeypatch.setattr( - final_audit_module, - "_find_process_execution", - lambda _artifact, _manifest, _process_id: ( - {}, - f"processes/{process_id}/execution.json", - "1" * 64, - (capability,), - ), - ) - monkeypatch.setattr( - final_audit_module, - "_audit_on_the_fly_execution", - lambda *_args, **_kwargs: 1, - ) - - evidence = audit_artifact(cell, tmp_path, process_id) - assert evidence.execution_mode == ExecutionMode.ON_THE_FLY.value - assert evidence.arena_record_count == 1 - assert evidence.producer_version == "0.1.0.dev0+candidate.test" - assert evidence.producer_git_revision == _REVISION - assert evidence.producer_native_build_inputs_sha256 == "e" * 64 - - inspected.lc_flow_layout = "topology-replay" - with pytest.raises(FinalAuditError, match="physics/execution contract"): - audit_artifact(cell, tmp_path, process_id) - - -def test_effective_toml_is_payload_authenticated_and_model_bound( - tmp_path: Path, -) -> None: - relative = "config/effective.toml" - path = tmp_path / relative - path.parent.mkdir(parents=True) - data = b'[model]\nsource = "built-in-sm"\n' - path.write_bytes(data) - manifest = SimpleNamespace( - configuration={"effective_path": relative}, - model={"source_kind": "built-in-sm"}, - payloads=( - SimpleNamespace( - path=relative, - role="configuration-effective", - media_type="application/toml", - process_id=None, - executable=False, - size_bytes=len(data), - sha256=hashlib.sha256(data).hexdigest(), - ), - ), - ) - effective = _authenticated_effective_config(tmp_path, manifest) - _audit_model_source(_cell(ExecutionMode.COMPILED), effective) - - path.write_bytes(b'[model]\nsource = "built-in-xx"\n') - with pytest.raises(FinalAuditError, match="artifact manifest"): - _authenticated_effective_config(tmp_path, manifest) - - -def test_eager_and_recurrence_arena_abis_are_audited(tmp_path: Path) -> None: - pack_path = tmp_path / "model" / "eager-kernel-pack.json" - pack_path.parent.mkdir(parents=True) - vertex_evaluator = _canonical_symjit_evaluator( - "kernels/000000/application.symjit", - "kernels/000000/application.plane.symjit", - optimization_level=2, - ) - vertex_evaluator["direct_table"] = { - "capability": "eager-direct-arena-v1", - "descriptor_abi": "pyamplicol-eager-plane-table-descriptor-v1", - "binding_abi": "pyamplicol-eager-plane-table-binding-v2", - "source_application_abi": "pyamplicol-symjit-plane-application-v2", - } - pack_payload = { - "backend": "jit", - "optimization_settings": { - "backend": "jit", - "jit_optimization_level": 2, - }, - "recurrence_direct_template": { - "abi": "pyamplicol-recurrence-direct-template-v1", - "backend": "jit", - "optimization_level": 2, - "portable": True, - "templates": [{"backend": "jit", "optimization_level": 2}], - }, - "kernel_variants": [], - "kernels": [ - { - "contract_kind": "vertex", - "f64_evaluator_manifest": vertex_evaluator, - }, - { - "contract_kind": "model-parameter", - "f64_evaluator_manifest": { - "kind": "symjit-application-evaluator", - "runtime_capability": "symjit.application.complex-f64.v1", - "optimization_level": 2, - "application_abi": "symjit-application-storage-v3", - }, - }, - ], - } - payload_record = SimpleNamespace( - path="model/eager-kernel-pack.json", - role="evaluator-manifest", - media_type="application/json", - process_id=None, - executable=False, - size_bytes=0, - sha256="", - ) - - def write_pack(value: object) -> None: - data = json.dumps(value).encode("utf-8") - pack_path.write_bytes(data) - payload_record.size_bytes = len(data) - payload_record.sha256 = hashlib.sha256(data).hexdigest() - - write_pack(pack_payload) - manifest = SimpleNamespace( - payloads=(payload_record,), - extensions={ - "eager_prepared_pack": { - "kind": "pyamplicol-prepared-kernel-pack-identity", - "schema_version": 1, - "backend": "jit", - "eager_kernel_abi": "pyamplicol-eager-kernel-v1", - "identity_sha256": "c" * 64, - "kernel_count": 2, - } - }, - ) - eager = { - "kind": "pyamplicol-runtime-eager-execution", - "eager_plan_abi": "pyamplicol-eager-plan-v3", - "plan": { - "eager_plan_abi": "pyamplicol-eager-plan-v3", - "lowering_input_abi": "pyamplicol-eager-lowering-input-v1", - "runtime_layout_abi": "pyamplicol-eager-runtime-layout-v1", - }, - "kernel_pack": {"manifest_path": "model/eager-kernel-pack.json"}, - } - assert ( - _audit_eager_execution( - tmp_path, - manifest, - eager, - _cell( - ExecutionMode.EAGER, - optimization_level=2, - ), - ) - == 1 - ) - wrong_capability = deepcopy(pack_payload) - wrong_capability["kernels"][0]["f64_evaluator_manifest"][ # type: ignore[index] - "runtime_capability" - ] = "symbolica.compiled-cpp.complex-f64.v1" - write_pack(wrong_capability) - with pytest.raises(FinalAuditError, match="runtime_capability"): - _audit_eager_execution( - tmp_path, - manifest, - eager, - _cell(ExecutionMode.EAGER, optimization_level=2), - ) - for nested_corruption in ( - {"nested": [{"direct_table": None}]}, - {"nested": {"capability": "eager-direct-arena-v1"}}, - {"nested": {"descriptor_abi": "pyamplicol-eager-plane-table-descriptor-v1"}}, - {"nested": {"binding_abi": "pyamplicol-eager-plane-table-binding-v2"}}, - {"nested": {"application_abi": "pyamplicol-eager-native-direct-table-v1"}}, - ): - corrupted = deepcopy(pack_payload) - corrupted["kernels"][1]["f64_evaluator_manifest"].update( # type: ignore[index] - nested_corruption - ) - write_pack(corrupted) - with pytest.raises(FinalAuditError, match="model-parameter"): - _audit_eager_execution( - tmp_path, - manifest, - eager, - _cell(ExecutionMode.EAGER, optimization_level=2), - ) - corrupted = deepcopy(pack_payload) - corrupted["kernels"][1]["nested_kernel_metadata"] = { # type: ignore[index] - "direct_table": {} - } - write_pack(corrupted) - with pytest.raises(FinalAuditError, match="model-parameter"): - _audit_eager_execution( - tmp_path, - manifest, - eager, - _cell(ExecutionMode.EAGER, optimization_level=2), - ) - source_relative = "model/eager-kernels/kernels/000000/application-0.plane.symjit" - source_data = b"authenticated-symjit-application" - source_sha256 = hashlib.sha256(source_data).hexdigest() - recurrence, recurrence_pack = _recurrence_source_fixture(source_sha256) - write_pack(recurrence_pack) - source_path = tmp_path / source_relative - source_path.parent.mkdir(parents=True) - source_path.write_bytes(source_data) - source_record = SimpleNamespace( - path=source_relative, - role="evaluator-state", - media_type="application/octet-stream", - process_id=None, - executable=False, - size_bytes=len(source_data), - sha256=source_sha256, - ) - manifest.payloads = (*manifest.payloads, source_record) - assert ( - _audit_recurrence_execution( - recurrence, - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - ) - == 4 - ) - source_identity = _audit_recurrence_source_pack( - tmp_path, - manifest, - recurrence, - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - execution_manifest_path="processes/d_dbar_to_z/execution.json", - execution_manifest_sha256="1" * 64, - ) - assert source_identity == { - "kind": "authenticated-recurrence-direct-template-source-v1", - "optimization_level": 2, - "direct_template_count": 1, - "prepared_direct_template_count": 1, - "source_evaluator_leaf_count": 1, - "source_application_abi": "pyamplicol-symjit-plane-application-v2", - "direct_application_abi": "pyamplicol-symjit-plane-application-v2", - "prepared_kernel_pack_digest": "a" * 64, - "direct_template_catalog_digest": recurrence["direct_template_catalog_digest"], - "execution_manifest_path": "processes/d_dbar_to_z/execution.json", - "execution_manifest_sha256": "1" * 64, - "kernel_pack_path": "model/eager-kernel-pack.json", - "kernel_pack_sha256": payload_record.sha256, - } - wrong_o2 = deepcopy(recurrence_pack) - wrong_o2["optimization_settings"]["jit_optimization_level"] = 1 # type: ignore[index] - write_pack(wrong_o2) - with pytest.raises(FinalAuditError, match="does not prove JIT O2"): - _audit_recurrence_source_pack( - tmp_path, - manifest, - recurrence, - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - execution_manifest_path="processes/d_dbar_to_z/execution.json", - execution_manifest_sha256="1" * 64, - ) - write_pack(pack_payload) - recurrence["plan"]["inspection_summary"]["direct_arena"][ # type: ignore[index] - "packed_input_bytes" - ] = 8 - with pytest.raises(FinalAuditError, match="packed_input_bytes"): - _audit_recurrence_execution( - recurrence, - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - ) - - -@pytest.mark.parametrize( - ("corruption", "message"), - ( - ("execution_template_abi", "direct_template_abi"), - ("plan_template_abi", "direct_template_abi"), - ("execution_backend_abi", "direct_backend_abi"), - ("plan_backend_abi", "direct_backend_abi"), - ("plan_prepared_digest", "source digests"), - ("plan_catalog_digest", "source digests"), - ("pack_prepared_digest", "execution_digest_links"), - ("execution_catalog_link", "execution_digest_links"), - ("catalog_backend_abi", "does not prove JIT O2"), - ("catalog_canonicalization_abi", "does not prove JIT O2"), - ("catalog_digest", "catalog_digest"), - ("template_portable", "template\\[0\\] contract"), - ("template_abi", "template\\[0\\] contract"), - ("binding_abi", "payload-binding contract"), - ("source_application_abi", "source application"), - ("direct_application_abi", "source application"), - ("payload_digest", "payload-binding contract"), - ("source_leaf_runtime_capability", "runtime_capability"), - ("source_leaf_application_abi", "application_abi"), - ("source_leaf_optimization", "optimization_level"), - ("source_leaf_plane_abi", "plane_application.application_abi"), - ("source_leaf_plane_digest", "plane_application.source_digest"), - ( - "source_leaf_plane_optimization", - "plane_application.optimization_level", - ), - ("source_leaf_path", "payload is missing"), - ("source_payload_digest_link", "not bound to its prepared kernel"), - ), -) -def test_final_audit_recurrence_source_pack_rejects_every_broken_link( - tmp_path: Path, - corruption: str, - message: str, -) -> None: - pack_relative = "model/eager-kernel-pack.json" - source_relative = "model/eager-kernels/kernels/000000/application-0.plane.symjit" - source_data = b"authenticated-symjit-application" - source_sha256 = hashlib.sha256(source_data).hexdigest() - execution, pack = _recurrence_source_fixture(source_sha256) - plan = execution["plan"] - assert isinstance(plan, dict) - catalog = pack["recurrence_direct_template"] - assert isinstance(catalog, dict) - templates = catalog["templates"] - assert isinstance(templates, list) - template = templates[0] - assert isinstance(template, dict) - binding = template["payload_binding"] - assert isinstance(binding, dict) - kernels = pack["kernels"] - assert isinstance(kernels, list) - kernel = kernels[0] - assert isinstance(kernel, dict) - source_leaf = kernel["f64_evaluator_manifest"] - assert isinstance(source_leaf, dict) - refresh_catalog: bool | None = None - - if corruption == "execution_template_abi": - execution["direct_template_abi"] = "wrong" - elif corruption == "plan_template_abi": - plan["direct_template_abi"] = "wrong" - elif corruption == "execution_backend_abi": - execution["direct_backend_abi"] = "wrong" - elif corruption == "plan_backend_abi": - plan["direct_backend_abi"] = "wrong" - elif corruption == "plan_prepared_digest": - plan["prepared_kernel_pack_digest"] = "0" * 64 - elif corruption == "plan_catalog_digest": - plan["direct_template_catalog_digest"] = "0" * 64 - elif corruption == "pack_prepared_digest": - catalog["prepared_kernel_pack_digest"] = "0" * 64 - refresh_catalog = True - elif corruption == "execution_catalog_link": - execution["direct_template_catalog_digest"] = "0" * 64 - plan["direct_template_catalog_digest"] = "0" * 64 - elif corruption == "catalog_backend_abi": - catalog["backend_abi"] = "wrong" - refresh_catalog = True - elif corruption == "catalog_canonicalization_abi": - catalog["canonicalization_abi"] = "wrong" - refresh_catalog = True - elif corruption == "catalog_digest": - catalog["compiled_model_digest"] = "0" * 64 - elif corruption == "template_portable": - template["portable"] = False - refresh_catalog = True - elif corruption == "template_abi": - template["abi"] = "wrong" - refresh_catalog = True - elif corruption == "binding_abi": - binding["abi"] = "wrong" - refresh_catalog = True - elif corruption == "source_application_abi": - binding["source_application_abi"] = "wrong" - refresh_catalog = True - elif corruption == "direct_application_abi": - binding["direct_application_abi"] = "wrong" - refresh_catalog = True - elif corruption == "payload_digest": - binding["payload_digest"] = "0" * 64 - refresh_catalog = False - elif corruption == "source_leaf_runtime_capability": - source_leaf["runtime_capability"] = "wrong" - elif corruption == "source_leaf_application_abi": - source_leaf["application_abi"] = "wrong" - elif corruption == "source_leaf_optimization": - source_leaf["optimization_level"] = 1 - elif corruption == "source_leaf_plane_abi": - source_leaf["plane_application"]["application_abi"] = "wrong" - elif corruption == "source_leaf_plane_digest": - source_leaf["plane_application"]["source_digest"] = "wrong" - elif corruption == "source_leaf_plane_optimization": - source_leaf["plane_application"]["optimization_level"] = 1 - elif corruption == "source_leaf_path": - source_leaf["plane_application"]["application_path"] = ( - "kernels/000000/missing.plane.symjit" - ) - elif corruption == "source_payload_digest_link": - binding["source_application_sha256"] = "0" * 64 - refresh_catalog = True - else: - pytest.fail(f"unknown corruption {corruption}") - - if refresh_catalog is not None: - _refresh_recurrence_source_catalog( - execution, - pack, - refresh_binding_digest=refresh_catalog, - ) - pack_path = tmp_path / pack_relative - pack_path.parent.mkdir(parents=True) - pack_data = json.dumps(pack, sort_keys=True).encode("ascii") - pack_path.write_bytes(pack_data) - source_path = tmp_path / source_relative - source_path.parent.mkdir(parents=True) - source_path.write_bytes(source_data) - manifest = SimpleNamespace( - payloads=( - SimpleNamespace( - path=pack_relative, - role="evaluator-manifest", - media_type="application/json", - process_id=None, - executable=False, - size_bytes=len(pack_data), - sha256=hashlib.sha256(pack_data).hexdigest(), - ), - SimpleNamespace( - path=source_relative, - role="evaluator-state", - media_type="application/octet-stream", - process_id=None, - executable=False, - size_bytes=len(source_data), - sha256=source_sha256, - ), - ), - extensions={}, - ) - with pytest.raises(FinalAuditError, match=message): - _audit_recurrence_source_pack( - tmp_path, - manifest, - execution, - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - execution_manifest_path="processes/d_dbar_to_z/execution.json", - execution_manifest_sha256="1" * 64, - ) - - -def test_pointwise_audit_recomputes_arithmetic_and_status() -> None: - record = { - "status": "ok", - "candidate": 1.0 + 1.0e-13, - "baseline": 1.0, - "absolute_difference": abs((1.0 + 1.0e-13) - 1.0), - "relative_difference": abs((1.0 + 1.0e-13) - 1.0), - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - } - _audit_pointwise( - record, - context="pointwise", - expected_candidate=1.0 + 1.0e-13, - expected_baseline=1.0, - expected_relative_tolerance=1.0e-12, - ) - record["relative_difference"] = 0.0 - with pytest.raises(FinalAuditError, match="relative difference"): - _audit_pointwise( - record, - context="pointwise", - expected_candidate=1.0 + 1.0e-13, - expected_baseline=1.0, - expected_relative_tolerance=1.0e-12, - ) - - -def test_pointwise_audit_authenticates_conditioned_point_binding() -> None: - from tools.performance_report.runner import pointwise_validation - - selector_identity = {"cell_id": "candidate", "value_kind": "total"} - record = pointwise_validation( - 1.0 + 1.0e-13, - 1.0, - comparison_binding={ - "point_digest": "a" * 64, - "selector_component_identity": selector_identity, - "selector_component_sha256": hashlib.sha256( - json.dumps( - selector_identity, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest(), - "candidate_source_sha256": "b" * 64, - "baseline_source_sha256": "c" * 64, - }, - ) - _audit_pointwise( - record, - context="conditioned", - expected_candidate=1.0 + 1.0e-13, - expected_baseline=1.0, - expected_relative_tolerance=1.0e-12, - expected_point_digest="a" * 64, - expected_candidate_source_sha256="b" * 64, - expected_baseline_source_sha256="c" * 64, - expected_selector_identity=selector_identity, - ) - with pytest.raises(FinalAuditError, match="different point"): - _audit_pointwise( - record, - context="conditioned", - expected_candidate=1.0 + 1.0e-13, - expected_baseline=1.0, - expected_relative_tolerance=1.0e-12, - expected_point_digest="b" * 64, - ) - with pytest.raises(FinalAuditError, match="candidate scale source"): - _audit_pointwise( - record, - context="conditioned", - expected_candidate=1.0 + 1.0e-13, - expected_baseline=1.0, - expected_relative_tolerance=1.0e-12, - expected_point_digest="a" * 64, - expected_candidate_source_sha256="d" * 64, - ) - - -def test_python_package_tree_identity_is_canonical_and_ignores_caches( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - from tools.performance_report import runtime_evidence - - cache_prefix = tmp_path / "absent-cache-prefix" - monkeypatch.setattr( - runtime_evidence, - "_isolated_startup_flags", - lambda: (True, True, True), - ) - monkeypatch.setattr(sys, "dont_write_bytecode", True) - monkeypatch.setattr(sys, "pycache_prefix", str(cache_prefix)) - package = tmp_path / "pyamplicol" - (package / "submodule").mkdir(parents=True) - (package / "__pycache__").mkdir() - (package / "api.py").write_text("VALUE = 1\n", encoding="utf-8") - (package / "submodule" / "data.bin").write_bytes(b"\x00\x01") - (package / "__pycache__" / "api.pyc").write_bytes(b"cache one") - - first = _python_package_tree_identity(package) - assert first["kind"] == "pyamplicol-python-package-tree-v2" - assert first["roots"] == [str(package)] - assert first["file_count"] == 2 - assert first["total_bytes"] == 12 - - (package / "__pycache__" / "api.pyc").write_bytes(b"changed cache") - assert _python_package_tree_identity(package) == first - - (package / "api.py").write_text("VALUE = 2\n", encoding="utf-8") - changed = _python_package_tree_identity(package) - assert changed["sha256"] != first["sha256"] - - -def test_runtime_namespace_uses_only_first_native_candidate(tmp_path: Path) -> None: - from importlib.machinery import EXTENSION_SUFFIXES - - checkout = tmp_path / "checkout" - source_package = checkout / "src" / "pyamplicol" - source_package.mkdir(parents=True) - (source_package / "__init__.py").write_bytes(b"") - first_site = tmp_path / "first-site" - second_site = tmp_path / "second-site" - first_package = first_site / "pyamplicol" - second_package = second_site / "pyamplicol" - first_package.mkdir(parents=True) - second_package.mkdir(parents=True) - suffix = EXTENSION_SUFFIXES[0] - first_native = first_package / f"_rusticol{suffix}" - second_native = second_package / f"_rusticol{suffix}" - first_native.write_bytes(b"first") - second_native.write_bytes(b"stale") - - roots, native = _runtime_namespace_paths( - checkout, - search_path=(str(first_site), str(second_site)), - ) - - assert roots == (source_package.resolve(), first_package.resolve()) - assert native == first_native.resolve() - assert second_package.resolve() not in roots - - -def test_runtime_namespace_rejects_ambiguous_first_native_root( - tmp_path: Path, -) -> None: - from importlib.machinery import EXTENSION_SUFFIXES - - checkout = tmp_path / "checkout" - (checkout / "src" / "pyamplicol").mkdir(parents=True) - site = tmp_path / "site" - package = site / "pyamplicol" - package.mkdir(parents=True) - suffix = EXTENSION_SUFFIXES[0] - (package / f"_rusticol{suffix}").write_bytes(b"one") - (package / f"_rusticol_duplicate{suffix}").write_bytes(b"two") - - with pytest.raises(FinalAuditError, match="ambiguous"): - _runtime_namespace_paths(checkout, search_path=(str(site),)) - - -def test_direct_final_audit_cli_fails_closed_when_not_already_isolated( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - from tools.performance_report.runtime_evidence import RuntimeEvidenceError - - checkout = tmp_path / "checkout" - monkeypatch.setattr( - "tools.performance_report.final_audit.source_only_bytecode_policy", - lambda: (_ for _ in ()).throw(RuntimeEvidenceError("not isolated")), - ) - raw = ("--repo-root", str(checkout), "--expected-source-revision", _REVISION) - with pytest.raises( - FinalAuditError, - match=(r"src/pyamplicol/_profiling_campaign/result_tables\.py final-audit"), - ): - _ensure_exact_cli_python(checkout, raw) - - -def test_master_tex_dependency_graph_reaches_every_canonical_table( - tmp_path: Path, -) -> None: - docs = tmp_path / "docs" - sections = docs / "sections" - tables = docs / "tables" - sections.mkdir(parents=True) - tables.mkdir() - master = docs / "pyAmpliCol.tex" - section = sections / "performance.tex" - first = tables / "result_first_table.tex" - second = tables / "result_second_table.tex" - unreachable = tables / "result_unreachable_table.tex" - for table in (first, second, unreachable): - table.write_text(f"% {table.name}\n", encoding="utf-8") - master.write_text( - "\\input{sections/performance}\n" - "% \\\\input{tables/result_unreachable_table.tex}\n", - encoding="utf-8", - ) - section.write_text( - "\\input{../tables/result_first_table.tex}\n" - "\\include{../tables/result_second_table}\n", - encoding="utf-8", - ) - - identity = _audit_tex_table_reachability(master, (first, second)) - assert identity["reachable_table_source_count"] == 2 - assert identity["reachable_tex_source_count"] == 4 - - with pytest.raises(FinalAuditError, match="not reachable"): - _audit_tex_table_reachability(master, (first, second, unreachable)) - - -def test_active_runtime_snapshot_binds_exact_checkout( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - import pyamplicol - from pyamplicol._internal import versions - - native_path = tmp_path / "_rusticol.so" - native_path.write_bytes(b"native") - native_version = pyamplicol.__version__.replace(".dev", "-dev.") - native = SimpleNamespace( - __file__=str(native_path), - package_version=lambda: native_version, - native_build_inputs_sha256=lambda: "e" * 64, - target_info=lambda: SimpleNamespace( - triple="aarch64-apple-darwin", - cpu_features=(), - ), - ) - package_root = Path(str(pyamplicol.__file__)).parent.resolve() - package_tree = { - "kind": "pyamplicol-python-package-tree-v2", - "root": str(package_root), - "roots": [str(package_root)], - "file_count": 1, - "total_bytes": 1, - "sha256": "9" * 64, - "member_set_stable": True, - "namespace_bound_to_root_fd": True, - "bytecode_policy": _bytecode_policy(), - } - native_identity = { - "path": str(native_path), - "size": len(b"native"), - "sha256": hashlib.sha256(b"native").hexdigest(), - } - preimport_identity = { - "kind": "pyamplicol-preimport-runtime-identity-v1", - "python_package_tree": package_tree, - "native_extension": native_identity, - } - monkeypatch.setattr( - "tools.performance_report.final_audit._prepare_exact_pyamplicol_namespace", - lambda _checkout: ( - pyamplicol, - (package_root,), - native_path, - preimport_identity, - ), - ) - monkeypatch.setattr( - "tools.performance_report.final_audit._python_package_tree_identity", - lambda roots: ( - package_tree - if tuple(roots) == (package_root,) - else pytest.fail(f"unexpected package roots: {roots}") - ), - ) - monkeypatch.setattr( - "tools.performance_report.final_audit.loaded_pyamplicol_origin_policy", - lambda roots, **kwargs: ( - _loaded_origin_policy() - if ( - tuple(roots) == (package_root,) - and kwargs["native_extension"] == native_path - and kwargs["expected_package_identity"] == package_tree - and kwargs["expected_native_identity"] == native_identity - ) - else pytest.fail("unexpected loaded-origin evidence request") - ), - ) - monkeypatch.setattr( - "tools.performance_report.final_audit.importlib.import_module", - lambda name: native if name == "pyamplicol._rusticol" else None, - ) - monkeypatch.setattr(versions, "verify_native_module", lambda _native: None) - monkeypatch.setattr( - versions, - "_active_build_info", - lambda: { - "schema_version": 1, - "version": pyamplicol.__version__, - "candidate_fingerprint": "candidate", - "source_revision": _REVISION, - "source_checkout": str(tmp_path), - "native_build_inputs_sha256": "e" * 64, - "publishable": False, - }, - ) - - snapshot = _active_runtime_snapshot( - _REVISION, - expected_checkout=tmp_path, - ) - assert snapshot["native_build_inputs_sha256"] == "e" * 64 - assert snapshot["python_package_tree"]["kind"] == ( # type: ignore[index] - "pyamplicol-python-package-tree-v2" - ) - assert snapshot["native_extension"]["package_version"] == native_version # type: ignore[index] - assert snapshot["loaded_module_origin_policy"] == _loaded_origin_policy() - - other = tmp_path / "other" - other.mkdir() - with pytest.raises(FinalAuditError, match="not bound"): - _active_runtime_snapshot(_REVISION, expected_checkout=other) - - -@dataclass(frozen=True) -class _Flow: - id: str - word: tuple[int, ...] - - -@dataclass(frozen=True) -class _Helicity: - id: str - values: tuple[int, ...] - - -@dataclass(frozen=True) -class _Particle: - label: int - - -class _Resolved: - values = (((1.0 + 0.0j,),),) - helicity_ids = ("h:-1,+1,-1",) - color_ids = ("flow:2,1",) - - def total(self) -> tuple[complex, ...]: - return (1.0 + 0.0j,) - - -class _Runtime: - artifact_id = _ARTIFACT_ID - execution_mode = "recurrence" - - def __init__(self) -> None: - self.physics = SimpleNamespace( - color_accuracy="lc", - selector_capabilities=("helicity", "color_flow"), - external_particles=(_Particle(1), _Particle(2), _Particle(3)), - helicities=(_Helicity("h:-1,+1,-1", (-1, 1, -1)),), - color_flows=(_Flow("flow:2,1", (2, 1)),), - ) - - def evaluate( - self, - _points: object, - **_kwargs: object, - ) -> tuple[complex, ...]: - return (1.0 + 0.0j,) - - def evaluate_resolved( - self, - _points: object, - **_kwargs: object, - ) -> _Resolved: - return _Resolved() - - -class _Catalog: - def __init__(self, baseline: CellSpec, candidate: CellSpec) -> None: - self.baseline = baseline - self.candidate = candidate - - def measurement_cells(self) -> tuple[CellSpec, ...]: - return (self.baseline, self.candidate) - - def baseline_cell(self, cell: CellSpec) -> CellSpec | None: - return self.baseline if cell == self.candidate else None - - def validation_baseline_cell(self, cell: CellSpec) -> CellSpec | None: - return self.baseline_cell(cell) - - def static_na_reason(self, _cell: CellSpec) -> None: - return None - - def legacy_reference_available(self, _cell: CellSpec) -> bool: - return True - - -def _selector() -> dict[str, object]: - return { - "selected_color_flow_ids": ["flow:2,1"], - "selected_color_words": [[2, 1]], - "all_flow_helicity_ids": ["h:-1,+1,-1"], - "all_flow_source_helicities": {"1": -1, "2": 1, "3": -1}, - "point_digest": ( - "20d4353b25501bdf6c980930babe948e7c1d0364a3169d1ef5dc2a9da427e05c" - ), - } - - -def _lc_common_component(cell_id: str) -> dict[str, object]: - selector = _selector() - return { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell_id, - "value": 1.0, - "point_digest": selector["point_digest"], - "helicity_ids": selector["all_flow_helicity_ids"], - "color_flow_ids": selector["selected_color_flow_ids"], - } - - -def test_otf_v2_replay_uses_compact_selector_context_without_dense_physics( - tmp_path: Path, -) -> None: - cell = _cell(ExecutionMode.ON_THE_FLY, optimization_level=2) - points = final_audit_module.shared_validation_points(cell.process) - raw_selector = _selector() - raw_selector["point_digest"] = report_runner.point_digest(points) - contract = report_runner.SelectorContract.from_mapping(raw_selector) - - class Backend: - def __init__(self) -> None: - self.context_requests: list[tuple[str, ...]] = [] - self.selector_requests: list[tuple[str, tuple[str, ...]]] = [] - - def _on_the_fly_benchmark_context( - self, - requested: tuple[str, ...], - ) -> dict[str, object]: - self.context_requests.append(requested) - return { - "process_id": "d_dbar_to_z", - "process_expression": cell.process, - "color_accuracy": "lc", - "helicity_count": 1, - "color_count": 1, - "selected_color_ids": list(requested), - } - - def _point_selector_indices( - self, - values: tuple[str, ...], - name: str, - ) -> tuple[int, ...]: - self.selector_requests.append((name, values)) - return (0,) - - class Runtime: - artifact_id = _ARTIFACT_ID - execution_mode = "on-the-fly" - - def __init__(self) -> None: - self._backend = Backend() - self.dense_physics_access_count = 0 - - @property - def physics(self) -> object: - self.dense_physics_access_count += 1 - raise AssertionError("OTF replay opened dense physics") - - def evaluate(self, _points: object, **_kwargs: object) -> tuple[complex, ...]: - return (1.0 + 0.0j,) - - def evaluate_resolved(self, _points: object, **_kwargs: object) -> _Resolved: - return _Resolved() - - runtime = Runtime() - resolved_sum = report_runner.resolved_sum_validation( - runtime, - points, - cell=cell, - selector_contract=contract, - ) - measurement = { - "matrix_element": 1.0, - "selector_contract": raw_selector, - "validation": { - "resolved_sum": resolved_sum, - LC_COMMON_COMPONENT_FIELD: { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell.cell_id, - "value": 1.0, - "point_digest": contract.point_digest, - "helicity_ids": list(contract.all_flow_helicity_ids), - "color_flow_ids": list(contract.selected_color_flow_ids), - }, - }, - "provenance": {"runtime_identity": {"loaded_execution_mode": "on-the-fly"}}, - } - reference = final_audit_module._ArtifactReference( - cell=cell, - measurement=measurement, - path=tmp_path, - process_id="d_dbar_to_z", - ) - evidence = ArtifactEvidence( - artifact_id=_ARTIFACT_ID, - process_id="d_dbar_to_z", - producer_version="test", - producer_git_revision=_REVISION, - producer_native_build_inputs_sha256="e" * 64, - runtime_version="test", - runtime_capabilities=(), - execution_manifest_path="execution.json", - execution_manifest_sha256="1" * 64, - execution_mode="on-the-fly", - arena_record_count=1, - direct_leaf_count=0, - effective_config={}, - source_jit_identity=None, - ) - - replay = final_audit_module._replay_cell(runtime, reference, evidence) - - assert replay.matrix_element == 1.0 - assert replay.resolved_maximum_absolute == 0.0 - assert replay.resolved_maximum_relative == 0.0 - assert runtime.dense_physics_access_count == 0 - assert runtime._backend.context_requests == [(), ()] - assert runtime._backend.selector_requests == [ - ("color_flow_by_point", ("flow:2,1",)), - ("helicity_by_point", ("h:-1,+1,-1",)), - ] - - -def _source_provenance() -> dict[str, object]: - tree = "c" * 40 - return { - "report_source_identity_schema": "pyamplicol-report-source-v1", - "report_source_revision": _REVISION, - "report_source_tree": tree, - "report_measured_source_revision": _REVISION, - "report_measured_source_tree": tree, - "report_source_clean": True, - } - - -def _baseline_measurement( - cell_id: str = "reference-amplicol-lc-n1-dd-z-selected-flow", -) -> dict[str, object]: - result = empty_measurement() - result.update( - { - "status": "ok", - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 1.0e-6, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 1.0e-3, - "artifact": {"path": "/legacy", "process_row": "row"}, - "selector_contract": _selector(), - "validation": { - "status": "ok", - "method": "independent-original-amplicol-oracle", - "point_digest": _selector()["point_digest"], - DIRECT_AGREEMENT_FIELD: [], - LC_COMMON_COMPONENT_FIELD: _lc_common_component(cell_id), - }, - "resources": {"available": True}, - "provenance": { - **_source_provenance(), - "revision": _LEGACY_REVISION, - "runtime_profile": { - "measurement": { - "target_runtime_seconds": 5.0, - "achieved_runtime_seconds": 5.0, - "target_runtime_achieved": True, - "chunk_count": 5, - "interrupted": False, - } - }, - }, - "failure": None, - } - ) - return result - - -def _bytecode_policy() -> dict[str, object]: - return { - "kind": "pyamplicol-source-only-bytecode-policy-v1", - "dont_write_bytecode": True, - "external_pycache_prefix": True, - "external_pycache_prefix_absent": True, - "package_local_bytecode_eligible": False, - "isolated_startup": True, - "site_initialization": False, - "python_environment_ignored_at_startup": True, - } - - -def _loaded_origin_policy() -> dict[str, object]: - observations = [ - { - "module": "pyamplicol", - "kind": "package-member", - "root_index": 0, - "path": "__init__.py", - "size": 1, - "sha256": "1" * 64, - } - ] - return { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": len(observations), - "observations": observations, - "observations_sha256": digest_json(observations), - } - - -def _runtime_identity_provenance( - identity: Mapping[str, object], - *, - postflight_policy: Mapping[str, object] | None = None, -) -> dict[str, object]: - stable_identity = deepcopy(dict(identity)) - stable_policy = stable_identity.get("loaded_module_origin_policy") - assert isinstance(stable_policy, dict) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - stable_policy.pop(field) - stable_digest = digest_json(stable_identity) - return { - "runtime_identity": dict(identity), - "runtime_identity_sha256": digest_json(identity), - "runtime_identity_stable_sha256": stable_digest, - "runtime_identity_postflight_stable_sha256": stable_digest, - "runtime_identity_postflight_loaded_module_origin_policy": deepcopy( - identity["loaded_module_origin_policy"] - if postflight_policy is None - else postflight_policy - ), - "runtime_identity_postflight_match": True, - } - - -def _active_runtime() -> dict[str, object]: - candidate = { - "schema_version": 1, - "version": "0.1.0.dev0+candidate.test", - "candidate_fingerprint": "test", - "source_revision": _REVISION, - "source_checkout": "/repo", - "native_build_inputs_sha256": "e" * 64, - "publishable": False, - } - return { - "package_version": candidate["version"], - "python_package_tree": { - "kind": "pyamplicol-python-package-tree-v2", - "root": "/runtime/pyamplicol", - "roots": [ - "/runtime/pyamplicol", - "/candidate/site-packages/pyamplicol", - ], - "file_count": 10, - "total_bytes": 1000, - "sha256": "9" * 64, - "member_set_stable": True, - "namespace_bound_to_root_fd": True, - "bytecode_policy": _bytecode_policy(), - }, - "loaded_module_origin_policy": _loaded_origin_policy(), - "candidate_build_identity": candidate, - "candidate_build_identity_sha256": digest_json(candidate), - "native_build_inputs_sha256": "e" * 64, - "native_extension": { - "path": "/runtime/_rusticol.so", - "sha256": "f" * 64, - "package_version": candidate["version"], - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": [], - }, - } - - -def _candidate_measurement(artifact: Path) -> dict[str, object]: - active = _active_runtime() - capabilities = [_COLOR_CAPABILITY, _CAPABILITY] - identity = { - "kind": "pyamplicol-report-runtime-identity-v1", - "artifact_id": _ARTIFACT_ID, - "loaded_artifact_id": _ARTIFACT_ID, - "artifact_identity_match": True, - "process_id": "d_dbar_to_z", - "execution_mode": "recurrence", - "loaded_execution_mode": "recurrence", - "backend": "jit", - "required_arena_capability": _CAPABILITY, - "expected_evaluator_abi": "pyamplicol-recurrence-runtime-layout-v2", - "expected_source_evaluator_abi": ("pyamplicol-symjit-plane-application-v2"), - "expected_source_evaluator_runtime_capability": ( - "symjit.application.complex-f64.v1" - ), - "source_jit_optimization_level": 2, - "source_jit_identity": { - "kind": "authenticated-recurrence-direct-template-source-v1", - "optimization_level": 2, - "direct_template_count": 4, - "prepared_direct_template_count": 3, - "source_evaluator_leaf_count": 5, - "source_application_abi": ("pyamplicol-symjit-plane-application-v2"), - "direct_application_abi": "pyamplicol-symjit-plane-application-v2", - "prepared_kernel_pack_digest": "7" * 64, - "direct_template_catalog_digest": "8" * 64, - "execution_manifest_path": "processes/d_dbar_to_z/execution.json", - "execution_manifest_sha256": "1" * 64, - "kernel_pack_path": "model/eager-kernel-pack.json", - "kernel_pack_sha256": "2" * 64, - }, - "process_required_runtime_capabilities": capabilities, - "package_version": active["package_version"], - "python_package_tree": active["python_package_tree"], - "loaded_module_origin_policy": active["loaded_module_origin_policy"], - "artifact_runtime_version": active["package_version"], - "source_revision": _REVISION, - "candidate_build_identity": active["candidate_build_identity"], - "candidate_build_identity_sha256": active["candidate_build_identity_sha256"], - "native_build_inputs_sha256": active["native_build_inputs_sha256"], - "native_extension": active["native_extension"], - "native_target": active["native_target"], - } - result = empty_measurement() - result.update( - { - "status": "ok", - "generation_seconds": 2.0, - "wall_seconds_per_point": 2.0e-6, - "execution_seconds_per_point": 1.5e-6, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-8, - "relative_standard_error": 0.01, - "artifact": { - "path": str(artifact), - "process_id": "d_dbar_to_z", - "policy": "generated", - }, - "selector_contract": _selector(), - "validation": { - "status": "ok", - DIRECT_AGREEMENT_FIELD: [], - LC_COMMON_COMPONENT_FIELD: _lc_common_component( - "matrix-recurrence-test-n1-dd-z-selected-flow" - ), - "resolved_sum": { - "status": "ok", - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - }, - "pointwise": { - "status": "ok", - "candidate": 1.0, - "baseline": 1.0, - "absolute_difference": 0.0, - "relative_difference": 0.0, - "relative_tolerance": 1.0e-8, - "absolute_tolerance": 1.0e-15, - }, - }, - "resources": {"available": True}, - "provenance": { - **_source_provenance(), - "source_revision": _REVISION, - "runtime_profile": { - "target_runtime_seconds": 5.0, - "achieved_runtime_seconds": 5.0, - "target_runtime_achieved": True, - "completed_sample_count": 5, - "planned_sample_count": 5, - "repetitions_per_sample": 128, - "measured_point_count": 640, - "interrupted": False, - }, - "effective_config": { - "evaluator": { - "execution_mode": "recurrence", - "backend": "jit", - "jit": {"optimization_level": 2}, - }, - "color": { - "accuracy": "lc", - "lc_flow_layout": "topology-replay", - }, - "generation": { - "validation": { - "enabled": True, - "samples": 10, - "seed": 12345, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "post_build_validation": True, - } - }, - }, - **_runtime_identity_provenance(identity), - }, - "failure": None, - } - ) - return result - - -def test_final_audit_authenticates_madgraph_reference_without_pyamplicol_replay( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = REPORT_CATALOG.cell("reference-madgraph-full-n1-dd-z-jets-contracted") - points = (((100.0, 0.0, 0.0, 100.0), (100.0, 0.0, 0.0, -100.0)),) - monkeypatch.setattr( - final_audit_module, - "shared_validation_points", - lambda _process: points, - ) - command_card = madgraph_command_card(cell.process) - parameter_record = { - "external_parameter_count": 26, - "external_parameters_sha256": "1" * 64, - "binary64_exact_match": True, - "format": "%.14e", - } - command = { - "args": ["driver"], - "cwd": "/tmp", - "elapsed_seconds": 0.1, - "returncode": 0, - } - measurement = empty_measurement() - measurement.update( - { - "status": "ok", - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 1.0e-6, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 1.0e-3, - "artifact": {"path": "/tmp/madgraph"}, - "selector_contract": None, - "validation": { - "status": "ok", - "method": "independent-madgraph-tree-level-oracle", - "point_digest": report_runner.point_digest(points), - DIRECT_AGREEMENT_FIELD: [], - }, - "resources": {"available": True}, - "provenance": { - **_source_provenance(), - "method": "madgraph-standalone-custom-fortran-driver", - "command_card": command_card, - "command_card_sha256": hashlib.sha256( - command_card.encode("utf-8") - ).hexdigest(), - "generation_timing_scope": ("generate-output-standalone-launch-force"), - "generation_includes_madgraph_compilation": True, - "driver_compilation_in_generation_seconds": False, - "driver_warmup_calls": 20, - "profile_chunk_count": 5, - "model": { - "name": "sm", - "source_directory": "/tmp/MG/models/sm", - "source_sha256": "2" * 64, - }, - "default_restriction": parameter_record, - "exact_param_card": parameter_record, - "commands": [command] * 7, - }, - "failure": None, - } - ) - - assert ( - _audit_measurement( - cell, - measurement, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=None, - ) - is None - ) - - bad = deepcopy(measurement) - bad["provenance"]["command_card"] = "generate d d~ > z\n" # type: ignore[index] - with pytest.raises(FinalAuditError, match="generation command"): - _audit_measurement( - cell, - bad, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=None, - ) - - -def test_class_c_runtime_projection_authenticates_relinked_endpoint( - tmp_path: Path, -) -> None: - active = _active_runtime() - measurement = _candidate_measurement(tmp_path) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - identity = deepcopy(provenance["runtime_identity"]) - assert isinstance(identity, dict) - ancestor_revision = "b" * 40 - candidate = identity["candidate_build_identity"] - package_tree = identity["python_package_tree"] - native_extension = identity["native_extension"] - assert isinstance(candidate, dict) - assert isinstance(package_tree, dict) - assert isinstance(native_extension, dict) - candidate["source_revision"] = ancestor_revision - candidate["source_checkout"] = "/ancestor/repo" - identity["source_revision"] = ancestor_revision - identity["candidate_build_identity_sha256"] = digest_json(candidate) - package_tree["root"] = "/ancestor/runtime/pyamplicol" - package_tree["roots"] = [ - "/ancestor/runtime/pyamplicol", - "/ancestor/site-packages/pyamplicol", - ] - package_tree["sha256"] = "8" * 64 - native_extension["path"] = "/ancestor/runtime/_rusticol.so" - native_extension["sha256"] = "7" * 64 - ancestor_environment = { - "python_package_tree_sha256": package_tree["sha256"], - "pyamplicol": identity["package_version"], - "candidate_fingerprint": candidate["candidate_fingerprint"], - "native_build_inputs_sha256": identity["native_build_inputs_sha256"], - "native_extension_sha256": native_extension["sha256"], - "native_target": identity["native_target"]["triple"], - "native_cpu_features": "baseline", - } - lineage = SimpleNamespace( - ancestor_revision=ancestor_revision, - descendant_revision=_REVISION, - environment_for_source=lambda revision: ( - ancestor_environment if revision == ancestor_revision else None - ), - ) - retained_provenance = _runtime_identity_provenance(identity) - - projected = _runtime_for_measurement_source( - active, - retained_provenance, - source_revision=ancestor_revision, - measurement_lineage=lineage, - ) - - assert projected["native_extension"] == native_extension - assert projected["native_extension"] != active["native_extension"] - _audit_runtime_identity( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - retained_provenance, - expected_source_revision=ancestor_revision, - active_runtime=projected, - artifact=None, - ) - - tampered_environment = dict(ancestor_environment) - tampered_environment["native_extension_sha256"] = "6" * 64 - tampered_lineage = SimpleNamespace( - ancestor_revision=ancestor_revision, - descendant_revision=_REVISION, - environment_for_source=lambda revision: ( - tampered_environment if revision == ancestor_revision else None - ), - ) - with pytest.raises( - FinalAuditError, - match="retained ancestor runtime identity differs", - ): - _runtime_for_measurement_source( - active, - retained_provenance, - source_revision=ancestor_revision, - measurement_lineage=tampered_lineage, - ) - - -def test_class_c_runtime_projection_allows_only_pinned_summary_native_transition( - tmp_path: Path, -) -> None: - ancestor_revision = "be11d8304fdc04893dc0e23e9619be848126e3bc" - descendant_revision = "2594d8b520b802f71d60bd646f73ebaa5547927a" - ancestor_digest = "23b9637d5d3fba0947d78cf688df18799b0c9ee5b3bcbfa6a2963a1f1a21f870" - descendant_digest = ( - "96e1ff79a007aaf67a0900dd6d67327ee00f6bd2cca002589b879aa3a734de08" - ) - active = _active_runtime() - active["native_build_inputs_sha256"] = descendant_digest - measurement = _candidate_measurement(tmp_path) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - identity = deepcopy(provenance["runtime_identity"]) - assert isinstance(identity, dict) - candidate = identity["candidate_build_identity"] - package_tree = identity["python_package_tree"] - native_extension = identity["native_extension"] - assert isinstance(candidate, dict) - assert isinstance(package_tree, dict) - assert isinstance(native_extension, dict) - candidate["source_revision"] = ancestor_revision - candidate["source_checkout"] = "/ancestor/repo" - candidate["native_build_inputs_sha256"] = ancestor_digest - identity["source_revision"] = ancestor_revision - identity["native_build_inputs_sha256"] = ancestor_digest - identity["candidate_build_identity_sha256"] = digest_json(candidate) - package_tree["sha256"] = "8" * 64 - native_extension["sha256"] = "7" * 64 - ancestor_environment = { - "python_package_tree_sha256": package_tree["sha256"], - "pyamplicol": identity["package_version"], - "candidate_fingerprint": candidate["candidate_fingerprint"], - "native_build_inputs_sha256": ancestor_digest, - "native_extension_sha256": native_extension["sha256"], - "native_target": identity["native_target"]["triple"], - "native_cpu_features": "baseline", - } - lineage = SimpleNamespace( - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ancestor_revision=ancestor_revision, - descendant_revision=descendant_revision, - environment_for_source=lambda revision: ( - ancestor_environment if revision == ancestor_revision else None - ), - ) - retained_provenance = _runtime_identity_provenance(identity) - - projected = _runtime_for_measurement_source( - active, - retained_provenance, - source_revision=ancestor_revision, - measurement_lineage=lineage, - ) - assert projected["native_build_inputs_sha256"] == ancestor_digest - assert projected["candidate_build_identity"] == candidate - _audit_runtime_identity( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - retained_provenance, - expected_source_revision=ancestor_revision, - active_runtime=projected, - artifact=None, - ) - - changed_active = dict(active) - changed_active["native_build_inputs_sha256"] = "0" * 64 - with pytest.raises( - FinalAuditError, - match="Class-C invariant native identity", - ): - _runtime_for_measurement_source( - changed_active, - retained_provenance, - source_revision=ancestor_revision, - measurement_lineage=lineage, - ) - - -def test_portable_artifact_locator_resolves_only_within_profile_root( - tmp_path: Path, -) -> None: - paths = ReportPaths.from_repo( - tmp_path, - artifact_root=tmp_path / "profile-artifacts", - ) - artifact = paths.artifact_root / "cells/example/artifact" - artifact.mkdir(parents=True) - measurement = { - "artifact": { - "path": ("${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/cells/example/artifact"), - "process_id": "d_dbar_to_z", - } - } - - reference = _artifact_reference( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - measurement, - report_paths=paths, - ) - - assert reference.path == artifact - escaped = deepcopy(measurement) - escaped["artifact"]["path"] = ( # type: ignore[index] - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/../outside" - ) - with pytest.raises(FinalAuditError, match="not canonical"): - _artifact_reference( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - escaped, - report_paths=paths, - ) - - -def _otf_warmup_runtime_state(*, retained: bool) -> dict[str, object]: - counts = {field: 0 for field in report_runner.OTF_RUNTIME_STATE_COUNT_FIELDS} - active: dict[str, object] | None = None - if retained: - counts.update( - { - field: 1 - for field in ( - *report_runner.OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS, - *report_runner.OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS, - ) - } - ) - active = { - "basis": "shared-query-family-union-v1", - "scope": "active-family-union", - **{field: 1 for field in report_runner.OTF_ACTIVE_FAMILY_COUNT_FIELDS}, - } - return { - "kind": report_runner.OTF_RUNTIME_STATE_CENSUS_KIND, - "process_id": "otf_warmup_process", - "family_cache_policy": report_runner.OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - "family_cache_limit": report_runner.OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - **counts, - "active_family_union_census": active, - } - - -def _otf_warmup_profile() -> dict[str, object]: - return { - "cold_warmup_elapsed_seconds": 4.767252833, - "cold_warmup_run_count": 1, - "cold_warmup_batch_size": 128, - "cold_warmup_point_count": 128, - "cold_warmup_timer_source": report_runner.WARMUP_TIMER_SOURCE, - "cold_warmup_timing_scope": report_runner.OTF_COLD_WARMUP_TIMING_SCOPE, - "cold_warmup_runtime_freshness": ( - report_runner.OTF_COLD_WARMUP_RUNTIME_FRESHNESS - ), - "cold_warmup_runtime_state_evidence": ( - report_runner.OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - ), - "cold_warmup_runtime_state_before": _otf_warmup_runtime_state(retained=False), - "cold_warmup_runtime_state_after": _otf_warmup_runtime_state(retained=True), - "cold_warmup_runtime_cold_before_first_evaluation": True, - "cold_warmup_runtime_retained_before_first_evaluation": False, - "cold_warmup_runtime_retained_after_first_evaluation": True, - "cold_warmup_ratio_eligible": False, - "cold_warmup_acceptance_eligible": False, - "warmup_elapsed_seconds": 0.021, - "warmup_configured_run_count": 2, - "warmup_batch_size": 128, - "warmup_point_count": 256, - "warmup_run_outer_wall_seconds": [0.010, 0.011], - "first_warmup_run_outer_wall_seconds": 0.010, - "warmup_timer_source": report_runner.WARMUP_TIMER_SOURCE, - "warmup_timing_scope": report_runner.CONVENTIONAL_WARMUP_TIMING_SCOPE, - } - - -def _otf_warmup_provenance( - profile: dict[str, object] | None = None, -) -> dict[str, object]: - return { - "runtime_profile": _otf_warmup_profile() if profile is None else profile, - "runtime_load_included_in_cold_warmup": False, - "generation_timer_excludes_model_preparation": True, - "effective_config": {"benchmark": {"batch_size": 128, "warmup_runs": 2}}, - } - - -def test_final_audit_accepts_bounded_otf_warmup_evidence() -> None: - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - _otf_warmup_provenance(), - context="otf.measurement", - ) - - -@pytest.mark.parametrize( - ("field", "replacement", "message"), - ( - ("cold_warmup_run_count", 2, "exactly one run"), - ("cold_warmup_batch_size", 64, "full benchmark batch"), - ( - "cold_warmup_runtime_freshness", - "fresh", - "authenticated runtime state", - ), - ( - "cold_warmup_runtime_state_evidence", - "self-reported", - "state evidence is unsupported", - ), - ( - "cold_warmup_runtime_cold_before_first_evaluation", - False, - "booleans do not match", - ), - ("cold_warmup_acceptance_eligible", True, "ineligible"), - ("warmup_configured_run_count", 1, "effective benchmark configuration"), - ), -) -def test_final_audit_rejects_invalid_otf_warmup_evidence( - field: str, - replacement: object, - message: str, -) -> None: - profile = _otf_warmup_profile() - profile[field] = replacement - - with pytest.raises(FinalAuditError, match=message): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - _otf_warmup_provenance(profile), - context="otf.measurement", - ) - - -def test_final_audit_rejects_missing_conventional_warmup_evidence() -> None: - profile = _otf_warmup_profile() - del profile["warmup_run_outer_wall_seconds"] - - with pytest.raises(FinalAuditError, match="incomplete conventional warm-up"): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - _otf_warmup_provenance(profile), - context="otf.measurement", - ) - - -@pytest.mark.parametrize( - ("field", "invalid", "message"), - ( - ("runtime_load_included_in_cold_warmup", True, "must be false"), - ( - "generation_timer_excludes_model_preparation", - False, - "must be true", - ), - ), -) -def test_final_audit_rejects_contradictory_otf_phase_scope_flags( - field: str, - invalid: bool, - message: str, -) -> None: - provenance = _otf_warmup_provenance() - provenance[field] = invalid - - with pytest.raises(FinalAuditError, match=message): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - provenance, - context="otf.measurement", - ) - - -def test_final_audit_binds_otf_warmups_to_effective_benchmark_config() -> None: - coordinated_batch = _otf_warmup_profile() - coordinated_batch["cold_warmup_batch_size"] = 64 - coordinated_batch["cold_warmup_point_count"] = 64 - coordinated_batch["warmup_batch_size"] = 64 - coordinated_batch["warmup_point_count"] = 128 - with pytest.raises(FinalAuditError, match="effective benchmark configuration"): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - _otf_warmup_provenance(coordinated_batch), - context="otf.measurement", - ) - - coordinated_runs = _otf_warmup_profile() - coordinated_runs["warmup_configured_run_count"] = 1 - coordinated_runs["warmup_point_count"] = 128 - coordinated_runs["warmup_run_outer_wall_seconds"] = [0.010] - coordinated_runs["first_warmup_run_outer_wall_seconds"] = 0.010 - coordinated_runs["warmup_elapsed_seconds"] = 0.010 - with pytest.raises(FinalAuditError, match="effective benchmark configuration"): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - _otf_warmup_provenance(coordinated_runs), - context="otf.measurement", - ) - - -def test_final_audit_rejects_coordinated_nonpublication_otf_benchmark() -> None: - coordinated_batch = _otf_warmup_profile() - coordinated_batch["cold_warmup_batch_size"] = 64 - coordinated_batch["cold_warmup_point_count"] = 64 - coordinated_batch["warmup_batch_size"] = 64 - coordinated_batch["warmup_point_count"] = 128 - batch_provenance = _otf_warmup_provenance(coordinated_batch) - batch_provenance["effective_config"]["benchmark"]["batch_size"] = 64 - with pytest.raises( - FinalAuditError, - match=r"batch_size must equal the final report contract 128", - ): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - batch_provenance, - context="otf.measurement", - ) - - coordinated_runs = _otf_warmup_profile() - coordinated_runs["warmup_configured_run_count"] = 1 - coordinated_runs["warmup_point_count"] = 128 - coordinated_runs["warmup_run_outer_wall_seconds"] = [0.010] - coordinated_runs["first_warmup_run_outer_wall_seconds"] = 0.010 - coordinated_runs["warmup_elapsed_seconds"] = 0.010 - run_provenance = _otf_warmup_provenance(coordinated_runs) - run_provenance["effective_config"]["benchmark"]["warmup_runs"] = 1 - with pytest.raises( - FinalAuditError, - match=r"warmup_runs must equal the final report contract 2", - ): - _audit_runtime_profile_warmup_evidence( - _cell(ExecutionMode.ON_THE_FLY, optimization_level=2), - run_provenance, - context="otf.measurement", - ) - - -def test_legacy_measurement_requires_pinned_revision_and_physical_point_digest() -> ( - None -): - cell = _legacy_cell() - measurement = _baseline_measurement() - assert ( - _audit_measurement( - cell, - measurement, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=None, - ) - is None - ) - - wrong_revision = deepcopy(measurement) - wrong_revision["provenance"]["revision"] = "d" * 40 # type: ignore[index] - with pytest.raises(FinalAuditError, match="pinned original-AmpliCol revision"): - _audit_measurement( - cell, - wrong_revision, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=None, - ) - - wrong_points = deepcopy(measurement) - wrong_points["validation"]["point_digest"] = "0" * 64 # type: ignore[index] - with pytest.raises(FinalAuditError, match="physical process"): - _audit_measurement( - cell, - wrong_points, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=None, - ) - - -@pytest.mark.parametrize("execution_seconds", [0.0, -1.0, float("inf")]) -def test_candidate_measurement_requires_positive_finite_execution_time( - tmp_path: Path, - execution_seconds: float, -) -> None: - measurement = _candidate_measurement(tmp_path) - measurement["execution_seconds_per_point"] = execution_seconds - with pytest.raises( - FinalAuditError, - match="execution_seconds_per_point", - ): - _audit_measurement( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - measurement, - baseline=_baseline_measurement(), - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=_active_runtime(), - ) - - -def test_recurrence_without_legacy_oracle_requires_high_precision_validation( - tmp_path: Path, -) -> None: - cell = replace( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - dataset_id="matrix_recurrence_builtin_sm_lc", - process="d d~ > u u~ s s~ c c~", - n_final=6, - process_key="dd_4q_lines", - ) - measurement = _candidate_measurement(tmp_path) - validation = measurement["validation"] - assert isinstance(validation, dict) - validation.pop("pointwise") - validation["high_precision"] = { - "status": "ok", - "candidate": 1.0, - "baseline": 1.0, - "absolute_difference": 0.0, - "relative_difference": 0.0, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - } - - reference = _audit_measurement( - cell, - measurement, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=_active_runtime(), - ) - - assert reference is not None - assert reference.cell == cell - - validation.pop("high_precision") - with pytest.raises(FinalAuditError, match="high_precision"): - _audit_measurement( - cell, - measurement, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=_active_runtime(), - ) - - -@pytest.mark.parametrize( - "baseline_state", - tuple( - state - for state in PolicyMeasurementState - if state is not PolicyMeasurementState.SUCCESS - ), -) -def test_final_audit_omits_only_non_successful_optional_legacy_baseline( - tmp_path: Path, - baseline_state: PolicyMeasurementState, -) -> None: - baseline = _legacy_cell() - candidate = replace( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - dataset_id="matrix_recurrence_builtin_sm_lc", - ) - catalog = _Catalog(baseline, candidate) - baseline_measurement = _baseline_measurement() - candidate_measurement = _candidate_measurement(tmp_path) - - assert ( - _validation_baseline_for_audit( - candidate, - { - baseline.cell_id: baseline_measurement, - candidate.cell_id: candidate_measurement, - }, - {baseline.cell_id: baseline_state}, - catalog=catalog, # type: ignore[arg-type] - ) - is None - ) - assert ( - _validation_baseline_for_audit( - candidate, - {candidate.cell_id: candidate_measurement}, - {}, - catalog=catalog, # type: ignore[arg-type] - ) - is None - ) - - -def test_final_audit_never_promotes_successful_optional_legacy_baseline( - tmp_path: Path, -) -> None: - baseline = _legacy_cell() - candidate = replace( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - dataset_id="matrix_recurrence_builtin_sm_lc", - ) - catalog = _Catalog(baseline, candidate) - baseline_measurement = _baseline_measurement() - candidate_measurement = _candidate_measurement(tmp_path) - - assert ( - _validation_baseline_for_audit( - candidate, - { - baseline.cell_id: baseline_measurement, - candidate.cell_id: candidate_measurement, - }, - {baseline.cell_id: PolicyMeasurementState.SUCCESS}, - catalog=catalog, # type: ignore[arg-type] - ) - is None - ) - assert ( - _validation_baseline_for_audit( - candidate, - {candidate.cell_id: candidate_measurement}, - {baseline.cell_id: PolicyMeasurementState.SUCCESS}, - catalog=catalog, # type: ignore[arg-type] - ) - is None - ) - - -def test_optional_legacy_endpoint_requires_high_precision_authority_route( - tmp_path: Path, -) -> None: - baseline = _legacy_cell() - candidate = replace( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - dataset_id="matrix_recurrence_builtin_sm_lc", - ) - catalog = _Catalog(baseline, candidate) - baseline_measurement = _baseline_measurement() - pointwise_measurement = _candidate_measurement(tmp_path) - - assert ( - _validation_baseline_for_audit( - candidate, - { - baseline.cell_id: baseline_measurement, - candidate.cell_id: pointwise_measurement, - }, - {baseline.cell_id: PolicyMeasurementState.GENERATION_LIMIT}, - catalog=catalog, # type: ignore[arg-type] - ) - is None - ) - with pytest.raises(FinalAuditError, match="high_precision"): - _audit_measurement( - candidate, - pointwise_measurement, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=_active_runtime(), - ) - high_precision_measurement = deepcopy(pointwise_measurement) - validation = high_precision_measurement["validation"] - assert isinstance(validation, dict) - pointwise = validation.pop("pointwise") - assert isinstance(pointwise, dict) - pointwise["relative_tolerance"] = final_audit_module.RELATIVE_TOLERANCE - validation["high_precision"] = pointwise - assert ( - _validation_baseline_for_audit( - candidate, - { - baseline.cell_id: baseline_measurement, - candidate.cell_id: high_precision_measurement, - }, - {baseline.cell_id: PolicyMeasurementState.SUCCESS}, - catalog=catalog, # type: ignore[arg-type] - ) - is None - ) - assert ( - _audit_measurement( - candidate, - high_precision_measurement, - baseline=None, - expected_source_revision=_REVISION, - expected_legacy_revision=_LEGACY_REVISION, - active_runtime=_active_runtime(), - ) - is not None - ) - assert ( - _legacy_consumer_coverage( - (baseline, candidate), - { - baseline.cell_id: baseline_measurement, - candidate.cell_id: high_precision_measurement, - }, - { - baseline.cell_id: PolicyMeasurementState.SUCCESS, - candidate.cell_id: PolicyMeasurementState.SUCCESS, - }, - catalog=catalog, # type: ignore[arg-type] - ) - == () - ) - - -def test_stored_optional_legacy_agreement_survives_missing_current_endpoint( - tmp_path: Path, -) -> None: - legacy_selected = _legacy_cell() - baseline = replace(legacy_selected, workload=Workload.ALL_FLOW) - candidate = replace( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - dataset_id="matrix_recurrence_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - selected = replace(candidate, workload=Workload.SELECTED_FLOW) - - class DirectCatalog(_Catalog): - def measurement_cells(self) -> tuple[CellSpec, ...]: - return (legacy_selected, self.baseline, selected, self.candidate) - - catalog = DirectCatalog(baseline, candidate) - baseline_measurement = _baseline_measurement(baseline.cell_id) - selected_measurement = _candidate_measurement(tmp_path / "selected") - selected_validation = selected_measurement["validation"] - assert isinstance(selected_validation, dict) - selected_validation[LC_COMMON_COMPONENT_FIELD] = _lc_common_component( - selected.cell_id - ) - candidate_measurement = _candidate_measurement(tmp_path) - validation = candidate_measurement["validation"] - assert isinstance(validation, dict) - validation[LC_COMMON_COMPONENT_FIELD] = _lc_common_component(candidate.cell_id) - attach_direct_agreements( - candidate, - candidate_measurement, - { - baseline.cell_id: baseline_measurement, - selected.cell_id: selected_measurement, - }, - catalog=catalog, # type: ignore[arg-type] - ) - - edges, counts = _audit_direct_agreements( - (selected, candidate), - { - selected.cell_id: selected_measurement, - candidate.cell_id: candidate_measurement, - }, - catalog=catalog, # type: ignore[arg-type] - ) - - assert len(edges) == 2 - assert counts[LC_LEGACY_PYAMPLICOL_COMPONENT] == 1 - replay_counts = _audit_replayed_direct_agreements( - edges, - { - selected.cell_id: selected_measurement, - candidate.cell_id: candidate_measurement, - }, - { - selected.cell_id: final_audit_module._ReplayObservation( - matrix_element=1.0, - resolved_maximum_absolute=0.0, - resolved_maximum_relative=0.0, - lc_common_component=1.0, - ), - candidate.cell_id: final_audit_module._ReplayObservation( - matrix_element=1.0, - resolved_maximum_absolute=0.0, - resolved_maximum_relative=0.0, - lc_common_component=1.0, - ), - }, - ) - assert ( - replay_counts[final_audit_module._REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY] == 1 - ) - - -@pytest.mark.parametrize( - "execution_mode", - (ExecutionMode.COMPILED, ExecutionMode.EAGER), -) -def test_final_audit_treats_terminal_recurrence_authority_as_unavailable( - tmp_path: Path, - execution_mode: ExecutionMode, -) -> None: - recurrence = _cell(ExecutionMode.RECURRENCE, optimization_level=2) - candidate = _cell(execution_mode, optimization_level=2) - catalog = _Catalog(recurrence, candidate) - candidate_measurement = _candidate_measurement(tmp_path) - - with pytest.raises( - FinalAuditError, - match="no successful authenticated numerical authority", - ): - _validation_baseline_for_audit( - candidate, - { - recurrence.cell_id: {}, - candidate.cell_id: candidate_measurement, - }, - {recurrence.cell_id: PolicyMeasurementState.GENERATION_LIMIT}, - catalog=catalog, # type: ignore[arg-type] - ) - - -@pytest.mark.parametrize( - "execution_mode", - (ExecutionMode.COMPILED, ExecutionMode.EAGER), -) -def test_final_audit_consumes_durable_selected_independent_authority( - tmp_path: Path, - execution_mode: ExecutionMode, -) -> None: - candidate = REPORT_CATALOG.cell( - f"matrix-{execution_mode.value}-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - authorities = independent_numerical_authorities(candidate) - (recurrence,) = authorities - candidate_measurement = _candidate_measurement(tmp_path / "candidate") - validation = candidate_measurement["validation"] - assert isinstance(validation, dict) - pointwise = validation["pointwise"] - assert isinstance(pointwise, dict) - pointwise["relative_tolerance"] = final_audit_module.RELATIVE_TOLERANCE - validation[INDEPENDENT_AUTHORITY_FIELD] = { - "abi": INDEPENDENT_AUTHORITY_ABI, - "expected_cell_ids": [authority.cell_id for authority in authorities], - "selected_cell_id": recurrence.cell_id, - "status": "verified", - "reason": "independent-authority-agreement", - "same_artifact_diagnostics_are_authority": False, - } - recurrence_measurement = _candidate_measurement(tmp_path / "recurrence") - - assert ( - _validation_baseline_for_audit( - candidate, - { - candidate.cell_id: candidate_measurement, - recurrence.cell_id: recurrence_measurement, - }, - { - recurrence.cell_id: PolicyMeasurementState.SUCCESS, - }, - catalog=REPORT_CATALOG, - ) - is recurrence_measurement - ) - - with pytest.raises(FinalAuditError, match="selected independent authority"): - _validation_baseline_for_audit( - candidate, - { - candidate.cell_id: candidate_measurement, - }, - { - recurrence.cell_id: PolicyMeasurementState.GENERATION_LIMIT, - }, - catalog=REPORT_CATALOG, - ) - - -def _arena_profile_evidence( - *, - execution_mode: ExecutionMode = ExecutionMode.COMPILED, -) -> dict[str, object]: - raw_profile = { - "execution_mode": execution_mode.value, - "profile_boundary": ARENA_PROFILE_BOUNDARY, - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "evaluator_timing_available": False, - "points": 128, - "wall_time_s": 128 * 1.1e-6, - "orchestration_time_s": 128 * 1.1e-6, - **{field: 0 for field in ZERO_ARENA_COUNTER_FIELDS}, - **{field: 0.0 for field in ZERO_ARENA_PHASE_TIME_FIELDS}, - **{field: [] for field in EMPTY_ARENA_PHASE_VECTOR_FIELDS}, - **{field: 0 for field in ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS}, - } - if execution_mode is ExecutionMode.COMPILED: - raw_profile.update( - { - "compiled_direct_arena_engine_count": 1, - "compiled_direct_arena_call_count": 128, - "evaluator_backend_call_count": 128, - } - ) - return build_arena_profile_evidence( - [raw_profile] * 5, - execution_mode=execution_mode.value, - repetitions_per_profile=1, - batch_size=128, - ) - - -def _arena_unavailable_execution_timing( - *, - execution_mode: ExecutionMode = ExecutionMode.COMPILED, - arena_evidence: dict[str, object] | None = None, -) -> dict[str, object]: - evidence = ( - _arena_profile_evidence(execution_mode=execution_mode) - if arena_evidence is None - else arena_evidence - ) - return { - "abi": "pyamplicol-report-arena-execution-timing-v2", - "status": "unavailable", - "ratio_eligible": False, - "raw_seconds_per_point": None, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "repetitions_per_sample": 1, - "batch_size": 128, - "sample_contract": "paired_unprofiled_headline_profiled_attribution_v1", - "profile_protocol": "arena", - "profile_sample_pass": "runtime._profile_arena_repeated", - "profile_boundary": ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" - ), - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": "coarse-arena-boundary-only-v1", - "evaluator_timing_available": False, - "paired_with_headline": True, - "identical_batch": True, - "identical_repetitions": True, - "execution_mode": execution_mode.value, - "warmed_boundary_wall_seconds_per_point": 1.1e-6, - "arena_profile_evidence_sha256": digest_arena_profile_value(evidence), - } - - -def _arena_unavailable_provenance( - *, - execution_mode: ExecutionMode = ExecutionMode.COMPILED, -) -> dict[str, object]: - evidence = _arena_profile_evidence(execution_mode=execution_mode) - return { - "arena_profile_evidence": evidence, - "execution_timing": _arena_unavailable_execution_timing( - execution_mode=execution_mode, - arena_evidence=evidence, - ), - } - - -@pytest.mark.parametrize( - "cell", - ( - _cell(ExecutionMode.EAGER, optimization_level=2), - _cell(ExecutionMode.COMPILED, optimization_level=1), - _cell(ExecutionMode.COMPILED, backend="cpp", optimization_level=None), - ), -) -def test_final_audit_accepts_authenticated_arena_unavailable_timing( - cell: CellSpec, -) -> None: - provenance = _arena_unavailable_provenance( - execution_mode=cell.measurement.execution_mode, - ) - _audit_unavailable_execution_timing( - cell, - provenance, - measurement_sample_count=5, - context="candidate", - ) - - -@pytest.mark.parametrize( - ("field", "value"), - ( - ("abi", "wrong"), - ("status", "measured"), - ("ratio_eligible", True), - ("raw_seconds_per_point", 0.0), - ("sample_count", 4), - ("sample_count", True), - ("native_profile_points_per_sample", 0), - ("native_profile_points_per_sample", None), - ("repetitions_per_sample", 2), - ("batch_size", 64), - ("sample_contract", "separate_native_profile_diagnostic_v1"), - ("profile_protocol", "frozen-pre-arena"), - ("profile_sample_pass", "runtime.profile_repeated"), - ("profile_boundary", "materialized-native-profile-v1"), - ("borrowed_flat_input", False), - ("preallocated_output", False), - ("phase_timing_scope", "profiled-evaluator-phases-v1"), - ("evaluator_timing_available", True), - ("paired_with_headline", False), - ("identical_batch", False), - ("identical_repetitions", False), - ("execution_mode", "eager"), - ("warmed_boundary_wall_seconds_per_point", 0.0), - ("warmed_boundary_wall_seconds_per_point", float("nan")), - ("arena_profile_evidence_sha256", "0" * 64), - ), -) -def test_final_audit_rejects_tampered_arena_unavailable_timing( - field: str, - value: object, -) -> None: - provenance = _arena_unavailable_provenance() - timing = provenance["execution_timing"] - assert isinstance(timing, dict) - timing[field] = value - with pytest.raises(FinalAuditError, match="unavailable-attribution record"): - _audit_unavailable_execution_timing( - _cell(ExecutionMode.COMPILED, optimization_level=3), - provenance, - measurement_sample_count=5, - context="candidate", - ) - - -def test_final_audit_binds_arena_unavailable_shape_and_sample_count() -> None: - provenance = _arena_unavailable_provenance() - timing = provenance["execution_timing"] - assert isinstance(timing, dict) - timing["unexpected"] = True - with pytest.raises(FinalAuditError, match="fields do not match"): - _audit_unavailable_execution_timing( - _cell(ExecutionMode.COMPILED, optimization_level=3), - provenance, - measurement_sample_count=5, - context="candidate", - ) - - with pytest.raises(FinalAuditError, match="unavailable-attribution record"): - _audit_unavailable_execution_timing( - _cell(ExecutionMode.COMPILED, optimization_level=3), - _arena_unavailable_provenance(), - measurement_sample_count=6, - context="candidate", - ) - - -def test_runtime_identity_audit_distinguishes_source_and_direct_codegen_levels( - tmp_path: Path, -) -> None: - measurement = _candidate_measurement(tmp_path) - raw_provenance = measurement["provenance"] - assert isinstance(raw_provenance, dict) - raw_identity = raw_provenance["runtime_identity"] - assert isinstance(raw_identity, dict) - - def provenance(identity: dict[str, object]) -> dict[str, object]: - return _runtime_identity_provenance(identity) - - recurrence = _cell(ExecutionMode.RECURRENCE, optimization_level=2) - _audit_runtime_identity( - recurrence, - provenance(raw_identity), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - missing_source = deepcopy(raw_identity) - del missing_source["source_jit_optimization_level"] - with pytest.raises(FinalAuditError, match="source_jit_optimization_level"): - _audit_runtime_identity( - recurrence, - provenance(missing_source), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - missing_source_identity = deepcopy(raw_identity) - del missing_source_identity["source_jit_identity"] - with pytest.raises(FinalAuditError, match="source_jit_identity"): - _audit_runtime_identity( - recurrence, - provenance(missing_source_identity), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - wrong_source_capability = deepcopy(raw_identity) - wrong_source_capability["expected_source_evaluator_runtime_capability"] = ( - "symbolica.compiled-cpp.complex-f64.v1" - ) - with pytest.raises( - FinalAuditError, - match="expected_source_evaluator_runtime_capability", - ): - _audit_runtime_identity( - recurrence, - provenance(wrong_source_capability), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - missing_loaded_mode = deepcopy(raw_identity) - del missing_loaded_mode["loaded_execution_mode"] - with pytest.raises(FinalAuditError, match="loaded_execution_mode"): - _audit_runtime_identity( - recurrence, - provenance(missing_loaded_mode), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - spurious_direct_codegen = deepcopy(raw_identity) - spurious_direct_codegen["direct_codegen_optimization_level"] = 3 - with pytest.raises(FinalAuditError, match="direct_codegen_optimization_level"): - _audit_runtime_identity( - recurrence, - provenance(spurious_direct_codegen), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - compiled_identity = deepcopy(raw_identity) - del compiled_identity["source_jit_identity"] - compiled_identity.update( - { - "execution_mode": "compiled", - "loaded_execution_mode": "compiled", - "required_arena_capability": "compiled-plane-arena-v1", - "expected_evaluator_abi": "pyamplicol-compiled-plane-kernel-v2", - "expected_source_evaluator_abi": ("pyamplicol-symjit-plane-application-v2"), - "source_jit_optimization_level": 1, - "direct_codegen_optimization_level": 1, - "direct_codegen_identity": { - "kind": "authenticated-compiled-plane-arena-direct-codegen-v1", - "optimization_level": 1, - "source_optimization_level": 1, - "leaf_count": 2, - "execution_manifest_path": "execution.json", - "execution_manifest_sha256": "8" * 64, - }, - } - ) - compiled = _cell(ExecutionMode.COMPILED, optimization_level=1) - _audit_runtime_identity( - compiled, - provenance(compiled_identity), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - compiled_effective = {"evaluator": {"execution_mode": "compiled"}} - compiled_evidence = ArtifactEvidence( - artifact_id=_ARTIFACT_ID, - process_id="d_dbar_to_z", - producer_version=str(_active_runtime()["package_version"]), - producer_git_revision=_REVISION, - producer_native_build_inputs_sha256="e" * 64, - runtime_version=str(_active_runtime()["package_version"]), - runtime_capabilities=(_COLOR_CAPABILITY, _CAPABILITY), - execution_manifest_path="execution.json", - execution_manifest_sha256="8" * 64, - execution_mode="compiled", - arena_record_count=2, - direct_leaf_count=2, - effective_config=compiled_effective, - source_jit_identity=None, - ) - compiled_provenance = provenance(compiled_identity) - compiled_provenance["effective_config"] = compiled_effective - _audit_runtime_identity( - compiled, - compiled_provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=compiled_evidence, - ) - - wrong_leaf_count = deepcopy(compiled_identity) - wrong_leaf_count["direct_codegen_identity"]["leaf_count"] = 3 # type: ignore[index] - wrong_leaf_provenance = provenance(wrong_leaf_count) - wrong_leaf_provenance["effective_config"] = compiled_effective - with pytest.raises(FinalAuditError, match=r"direct_codegen_identity\.leaf_count"): - _audit_runtime_identity( - compiled, - wrong_leaf_provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=compiled_evidence, - ) - - wrong_path = deepcopy(compiled_identity) - wrong_path["direct_codegen_identity"]["execution_manifest_path"] = ( # type: ignore[index] - "other.json" - ) - wrong_path_provenance = provenance(wrong_path) - wrong_path_provenance["effective_config"] = compiled_effective - with pytest.raises( - FinalAuditError, - match=r"direct_codegen_identity\.execution_manifest_path", - ): - _audit_runtime_identity( - compiled, - wrong_path_provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=compiled_evidence, - ) - - wrong_effective_provenance = provenance(compiled_identity) - wrong_effective_provenance["effective_config"] = { - "evaluator": {"execution_mode": "eager"} - } - with pytest.raises(FinalAuditError, match="effective_config"): - _audit_runtime_identity( - compiled, - wrong_effective_provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=compiled_evidence, - ) - - missing_direct_codegen = deepcopy(compiled_identity) - del missing_direct_codegen["direct_codegen_optimization_level"] - with pytest.raises(FinalAuditError, match="direct_codegen_optimization_level"): - _audit_runtime_identity( - compiled, - provenance(missing_direct_codegen), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - -def test_artifact_producer_identity_uses_native_digest_for_dirty_candidate() -> None: - active = _active_runtime() - evidence = ArtifactEvidence( - artifact_id=_ARTIFACT_ID, - process_id="d_dbar_to_z", - producer_version=str(active["package_version"]), - producer_git_revision=_REVISION, - producer_native_build_inputs_sha256="e" * 64, - runtime_version=str(active["package_version"]), - runtime_capabilities=(), - execution_manifest_path="execution.json", - execution_manifest_sha256="1" * 64, - execution_mode="compiled", - arena_record_count=1, - direct_leaf_count=1, - effective_config={}, - source_jit_identity=None, - ) - final_audit_module._audit_artifact_producer_identity( - evidence, - expected_source_revision=_REVISION, - active_runtime=active, - ) - - dirty_active = deepcopy(active) - dirty_candidate = dirty_active["candidate_build_identity"] - assert isinstance(dirty_candidate, dict) - dirty_candidate["source_revision"] = None - dirty_active["candidate_build_identity_sha256"] = digest_json(dirty_candidate) - dirty_evidence = replace(evidence, producer_git_revision=None) - final_audit_module._audit_artifact_producer_identity( - dirty_evidence, - expected_source_revision=None, - active_runtime=dirty_active, - ) - - with pytest.raises(FinalAuditError, match="git_revision"): - final_audit_module._audit_artifact_producer_identity( - evidence, - expected_source_revision=None, - active_runtime=dirty_active, - ) - with pytest.raises(FinalAuditError, match="native_build_inputs_sha256"): - final_audit_module._audit_artifact_producer_identity( - replace( - dirty_evidence, - producer_native_build_inputs_sha256="0" * 64, - ), - expected_source_revision=None, - active_runtime=dirty_active, - ) - with pytest.raises(FinalAuditError, match="version"): - final_audit_module._audit_artifact_producer_identity( - replace(dirty_evidence, producer_version="other"), - expected_source_revision=None, - active_runtime=dirty_active, - ) - - -def test_runtime_identity_audit_accepts_real_otf_contract_and_rejects_seed_alias( - tmp_path: Path, -) -> None: - measurement = _candidate_measurement(tmp_path) - raw_provenance = measurement["provenance"] - assert isinstance(raw_provenance, dict) - raw_identity = raw_provenance["runtime_identity"] - assert isinstance(raw_identity, dict) - identity = deepcopy(raw_identity) - identity.pop("source_jit_identity") - identity.update( - { - "execution_mode": "on-the-fly", - "loaded_execution_mode": "on-the-fly", - "required_arena_capability": "rusticol.on-the-fly.complex-f64.v1", - "expected_evaluator_abi": "pyamplicol-runtime-on-the-fly-execution", - "expected_source_evaluator_abi": ("pyamplicol-symjit-plane-application-v2"), - "expected_source_evaluator_runtime_capability": ( - "symjit.application.complex-f64.v1" - ), - "source_jit_optimization_level": 2, - "process_required_runtime_capabilities": [ - "rusticol.on-the-fly.complex-f64.v1", - "rusticol.on-the-fly.lc-color.v1", - ], - } - ) - cell = _cell(ExecutionMode.ON_THE_FLY, optimization_level=2) - - _audit_runtime_identity( - cell, - _runtime_identity_provenance(identity), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - invented_seed_alias = deepcopy(identity) - invented_seed_alias["expected_source_evaluator_abi"] = ( - "pyamplicol-on-the-fly-process-seed-v1" - ) - with pytest.raises(FinalAuditError, match="expected_source_evaluator_abi"): - _audit_runtime_identity( - cell, - _runtime_identity_provenance(invented_seed_alias), - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - -def test_final_audit_rejects_tampered_raw_arena_profile_evidence() -> None: - provenance = _arena_unavailable_provenance() - evidence = provenance["arena_profile_evidence"] - assert isinstance(evidence, dict) - raw_profiles = evidence["raw_profiles"] - assert isinstance(raw_profiles, list) - assert isinstance(raw_profiles[0], dict) - raw_profiles[0]["native_input_pack_bytes"] = 1 - - with pytest.raises( - FinalAuditError, - match="not an authenticated Arena", - ): - _audit_unavailable_execution_timing( - _cell(ExecutionMode.COMPILED, optimization_level=1), - provenance, - measurement_sample_count=5, - context="candidate", - ) - - -@pytest.mark.parametrize( - ("field", "value", "match"), - [ - ( - "runtime_identity_stable_sha256", - "0" * 64, - "runtime_identity_stable_sha256", - ), - ( - "runtime_identity_postflight_stable_sha256", - "0" * 64, - "postflight stable SHA-256", - ), - ( - "runtime_identity_postflight_match", - False, - "runtime_identity_postflight_match", - ), - ( - "runtime_identity_postflight_loaded_module_origin_policy", - {}, - "loaded-origin policy", - ), - ], -) -def test_runtime_identity_audit_requires_per_cell_postflight_evidence( - tmp_path: Path, - field: str, - value: object, - match: str, -) -> None: - measurement = _candidate_measurement(tmp_path) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance[field] = value - with pytest.raises(FinalAuditError, match=match): - _audit_runtime_identity( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - -def test_runtime_identity_audit_accepts_only_monotonic_postflight_origins( - tmp_path: Path, -) -> None: - measurement = _candidate_measurement(tmp_path) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - raw_postflight = provenance[ - "runtime_identity_postflight_loaded_module_origin_policy" - ] - assert isinstance(raw_postflight, dict) - observations = raw_postflight["observations"] - assert isinstance(observations, list) - observations.append( - { - "module": "pyamplicol.runtime", - "kind": "package-member", - "root_index": 0, - "path": "runtime/__init__.py", - "size": 2, - "sha256": "2" * 64, - } - ) - raw_postflight["observed_module_count"] = len(observations) - raw_postflight["observations_sha256"] = digest_json(observations) - _audit_runtime_identity( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - observations[0] = { - "module": "pyamplicol.replaced", - "kind": "package-member", - "root_index": 0, - "path": "replaced.py", - "size": 3, - "sha256": "3" * 64, - } - raw_postflight["observations_sha256"] = digest_json(observations) - with pytest.raises(FinalAuditError, match="lost a loaded-module origin"): - _audit_runtime_identity( - _cell(ExecutionMode.RECURRENCE, optimization_level=2), - provenance, - expected_source_revision=_REVISION, - active_runtime=_active_runtime(), - artifact=None, - ) - - -def test_final_audit_authenticates_cache_store_and_replays_unique_artifact( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - dependencies = tmp_path / "dependencies" - dependencies.mkdir() - (dependencies / "contributor-lock.toml").write_text( - f'[legacy_amplicol]\nrevision = "{_LEGACY_REVISION}"\n', - encoding="utf-8", - ) - baseline = _legacy_cell() - candidate = CellSpec( - dataset_id="matrix_recurrence_test", - process="d d~ > z", - n_final=1, - process_key="dd_z", - measurement=MeasurementSpec( - ExecutionMode.RECURRENCE, - ModelKey.BUILTIN_SM, - Accuracy.LC, - "jit", - 2, - ), - workload=Workload.SELECTED_FLOW, - ) - catalog = _Catalog(baseline, candidate) - paths = ReportPaths.from_repo( - tmp_path, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - service = ReportService(paths, catalog=catalog) # type: ignore[arg-type] - artifact = paths.artifact_root / "synthetic-artifact" - artifact.mkdir() - measurements = { - baseline.cell_id: _baseline_measurement(), - candidate.cell_id: _candidate_measurement(artifact), - } - candidate_validation = measurements[candidate.cell_id]["validation"] - assert isinstance(candidate_validation, dict) - points = final_audit_module.shared_validation_points(candidate.process) - selector_contract = report_runner.SelectorContract.from_mapping(_selector()) - resolved = report_runner.resolved_sum_validation( - _Runtime(), - points, - cell=candidate, - selector_contract=selector_contract, - precision=16, - ) - high_resolved = report_runner.resolved_sum_validation( - _Runtime(), - points, - cell=candidate, - selector_contract=selector_contract, - precision=32, - ) - resolved_point = resolved["points"][0] - high_resolved_point = high_resolved["points"][0] - assert isinstance(resolved_point, dict) - assert isinstance(high_resolved_point, dict) - selector_identity = { - "cell_id": candidate.cell_id, - "accuracy": candidate.measurement.accuracy.value, - "workload": candidate.workload.value, - "selector_contract": selector_contract.as_dict(), - "value_kind": "matrix-element-p16-versus-p32", - } - high_precision = report_runner.pointwise_validation( - 1.0, - 1.0, - candidate_scale=float(resolved_point["candidate_scale"]), - baseline_scale=float(high_resolved_point["candidate_scale"]), - candidate_scale_source="resolved-component-l1-binary64", - baseline_scale_source="resolved-component-l1-p32", - comparison_binding={ - "point_digest": report_runner.point_digest(points), - "selector_component_identity": selector_identity, - "selector_component_sha256": digest_json(selector_identity), - "candidate_source_sha256": resolved["resolved_source_sha256"], - "baseline_source_sha256": high_resolved["resolved_source_sha256"], - }, - ) - candidate_validation.pop("pointwise") - candidate_validation["resolved_sum"] = resolved - candidate_validation["high_precision_resolved_sum"] = high_resolved - candidate_validation["high_precision"] = high_precision - for cell in catalog.measurement_cells(): - service.store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE).publish( - measurements[cell.cell_id] - ) - caches = build_reset_caches(catalog) # type: ignore[arg-type] - for payload in caches.values(): - for entry in payload["entries"]: - entry["measurement"] = portable_publication_value( - measurements[entry["cell_id"]], - paths, - ) - paths.results_dir.mkdir(parents=True) - for name, payload in caches.items(): - (paths.results_dir / name).write_text( - json.dumps(payload, sort_keys=True), - encoding="ascii", - ) - lock_state = {"held": False, "entries": 0} - - @contextmanager - def named_lock(name: str): - assert name == "report-writer" - assert lock_state["held"] is False - lock_state["held"] = True - lock_state["entries"] += 1 - try: - yield - finally: - lock_state["held"] = False - - def assert_locked() -> None: - assert lock_state["held"] is True - - def render_auditor() -> dict[str, object]: - assert_locked() - return {"cache_render_match": True, "table_count": 1} - - monkeypatch.setattr(service.store, "named_lock", named_lock) - monkeypatch.setattr(service, "audit", render_auditor) - - def artifact_auditor( - _cell: CellSpec, - path: Path, - process_id: str, - ) -> ArtifactEvidence: - assert_locked() - assert path == artifact - candidate_provenance = measurements[candidate.cell_id]["provenance"] - assert isinstance(candidate_provenance, dict) - effective_config = candidate_provenance["effective_config"] - assert isinstance(effective_config, dict) - runtime_identity = candidate_provenance["runtime_identity"] - assert isinstance(runtime_identity, dict) - source_jit_identity = runtime_identity["source_jit_identity"] - assert isinstance(source_jit_identity, dict) - return ArtifactEvidence( - artifact_id=_ARTIFACT_ID, - process_id=process_id, - producer_version=str(_active_runtime()["package_version"]), - producer_git_revision=_REVISION, - producer_native_build_inputs_sha256="e" * 64, - runtime_version=str(_active_runtime()["package_version"]), - runtime_capabilities=(_COLOR_CAPABILITY, _CAPABILITY), - execution_manifest_path="processes/d_dbar_to_z/execution.json", - execution_manifest_sha256="1" * 64, - execution_mode="recurrence", - arena_record_count=4, - direct_leaf_count=0, - effective_config=effective_config, - source_jit_identity=source_jit_identity, - ) - - def runtime_loader(_path: Path, _process: str) -> _Runtime: - assert_locked() - return _Runtime() - - def source_auditor(_root: Path, _revision: str) -> None: - assert_locked() - - def runtime_auditor(_revision: str, _root: Path) -> dict[str, object]: - assert_locked() - return _active_runtime() - - def pdf_auditor(_service: ReportService) -> dict[str, object]: - assert_locked() - return { - "status": "ok", - "published_sha256": "2" * 64, - } - - result = audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=1, - expected_cell_count=2, - replay=True, - catalog=catalog, # type: ignore[arg-type] - service=service, - active_runtime=_active_runtime(), - artifact_auditor=artifact_auditor, - runtime_loader=runtime_loader, - source_auditor=source_auditor, - runtime_auditor=runtime_auditor, - pdf_auditor=pdf_auditor, - ) - - assert lock_state == {"held": False, "entries": 1} - assert result["status"] == "incomplete" - assert result["schema_version"] == 5 - assert result["measurement_source_revision"] == _REVISION - assert result["publication_revision"] == _REVISION - assert result["publication_lineage"]["relationship"] == "same-commit" - assert result["authenticated_current_count"] == 2 - assert result["declared_cell_count"] == 2 - assert result["measurable_cell_count"] == 2 - assert result["catalog_static_na_cell_count"] == 0 - assert result["catalog_static_na_reason_counts"] == {} - assert result["portable_publication_projection_count"] == 2 - assert result["publication_cache_role"] == ("portable-projection-of-current-result") - assert result["cryptographic_audit_source"] == "immutable-current-result" - assert result["numerically_evidenced_cell_count"] == 2 - assert result["legacy_fresh_oracle_count"] == 1 - assert result["legacy_oracles_with_inbound_agreement"] == 0 - assert result["legacy_pointwise_agreement_edge_count"] == 0 - assert result["direct_agreement_edge_count"] == 0 - assert result["direct_agreement_edge_counts"] == { - "builtin-ufo-recurrence": 0, - "z-recurrence-cross-mode": 0, - "lc-cross-layout-component": 0, - "lc-legacy-pyamplicol-component": 0, - MADGRAPH_FULL_COLOUR: 0, - } - assert result["replayed_direct_agreement_edge_count"] == 0 - assert set(result["direct_agreement_replay_category_counts"].values()) == {0} - assert result["unique_artifact_count"] == 1 - assert result["canonical_publication_scope"] is False - assert result["final_gate_complete"] is False - assert result["audit_scope"] == "diagnostic-incomplete" - assert result["pyamplicol_replay_count"] == 1 - assert result["replayed_measurement_count"] == 1 - assert result["visible_completeness"] == { - "kind": "pyamplicol-report-visible-completeness", - "schema_version": 2, - "status": "ok", - "maximum_n_final": 1, - "declared_measurement_cell_count": 2, - "required_measurement_count": 2, - "rendered_required_measurement_count": 2, - "structurally_not_applicable_display_slot_count": 0, - "not_exposed_display_slot_count": 0, - "catalog_static_na_cell_count": 0, - "rendered_catalog_static_na_cell_count": 0, - "applicable_na_display_slot_count": 0, - "applicable_na_display_slots": [], - "missing_rendered_cell_count": 0, - "missing_rendered_cell_ids": [], - "contract_errors": [], - } - - def wrong_runtime_loader(_path: Path, _process: str) -> _Runtime: - assert_locked() - runtime = _Runtime() - runtime.execution_mode = "compiled" - return runtime - - with pytest.raises(FinalAuditError, match="loaded execution mode"): - audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=1, - expected_cell_count=2, - replay=True, - catalog=catalog, # type: ignore[arg-type] - service=service, - active_runtime=_active_runtime(), - artifact_auditor=artifact_auditor, - runtime_loader=wrong_runtime_loader, - source_auditor=source_auditor, - runtime_auditor=runtime_auditor, - pdf_auditor=pdf_auditor, - ) - assert lock_state == {"held": False, "entries": 2} - - structural = audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=1, - expected_cell_count=2, - replay=False, - catalog=catalog, # type: ignore[arg-type] - service=service, - active_runtime=_active_runtime(), - artifact_auditor=artifact_auditor, - source_auditor=source_auditor, - runtime_auditor=runtime_auditor, - pdf_auditor=pdf_auditor, - ) - assert structural["status"] == "incomplete" - assert structural["final_gate_complete"] is False - assert structural["audit_scope"] == "diagnostic-incomplete" - assert structural["pyamplicol_replay_count"] == 0 - - no_pdf = audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=1, - expected_cell_count=2, - replay=True, - catalog=catalog, # type: ignore[arg-type] - service=service, - active_runtime=_active_runtime(), - artifact_auditor=artifact_auditor, - runtime_loader=runtime_loader, - source_auditor=source_auditor, - runtime_auditor=runtime_auditor, - verify_pdf=False, - ) - assert no_pdf["status"] == "incomplete" - assert no_pdf["final_gate_complete"] is False - assert no_pdf["pdf_audit"] == {"status": "incomplete", "skipped": True} - assert lock_state == {"held": False, "entries": 4} - - with monkeypatch.context() as local_patch: - local_patch.setattr( - final_audit_module, - "summarize_visible_completeness", - lambda *_args, **_kwargs: VisibleCompleteness( - maximum_n_final=1, - required_measurement_count=2, - rendered_required_measurement_count=2, - structurally_not_applicable_display_slot_count=0, - not_exposed_display_slot_count=0, - applicable_na_display_slots=("synthetic applicable N/A",), - missing_rendered_cell_ids=(), - contract_errors=(), - ), - ) - with pytest.raises( - FinalAuditError, - match=r"visible-completeness.*applicable_NA=1", - ): - audit_final_report( - tmp_path, - expected_source_revision=_REVISION, - max_n_final=1, - expected_cell_count=2, - replay=False, - catalog=catalog, # type: ignore[arg-type] - service=service, - active_runtime=_active_runtime(), - source_auditor=source_auditor, - runtime_auditor=runtime_auditor, - verify_pdf=False, - ) - assert lock_state == {"held": False, "entries": 5} diff --git a/pyamplicol/tests/unit/test_performance_report_madgraph.py b/pyamplicol/tests/unit/test_performance_report_madgraph.py deleted file mode 100644 index 72f3970581..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_madgraph.py +++ /dev/null @@ -1,436 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import os -import shutil -from collections.abc import Sequence -from pathlib import Path - -import pytest - -from tools.developer import madgraph_correctness -from tools.performance_report import madgraph -from tools.performance_report.models import ( - Accuracy, - CellSpec, - ExecutionMode, - MeasurementSpec, - ModelKey, - ResultStatus, - Workload, -) - -_REPOSITORY = Path(__file__).resolve().parents[2] -_UFO_MODEL = _REPOSITORY / "src/pyamplicol/assets/models/ufo/sm" -_JSON_MODEL = _REPOSITORY / "src/pyamplicol/assets/models/json/sm/sm.json" -_JSON_RESTRICTION = ( - _REPOSITORY / "src/pyamplicol/assets/models/json/sm/restrict_default.json" -) - - -def _command_result( - *, - cwd: Path, - stdout: str = "", - stderr: str = "", - returncode: int = 0, -) -> madgraph.CommandResult: - return madgraph.CommandResult( - args=("fake-command",), - cwd=cwd, - elapsed_seconds=0.25, - returncode=returncode, - stdout=stdout, - stderr=stderr, - ) - - -def _madgraph_cell() -> CellSpec: - return CellSpec( - dataset_id="reference_madgraph_full", - process="g g > g g", - n_final=2, - process_key="gg", - measurement=MeasurementSpec( - execution_mode=ExecutionMode.MADGRAPH, - model=ModelKey.UFO_SM, - accuracy=Accuracy.FULL, - backend="fortran", - jit_optimization_level=None, - ), - workload=Workload.CONTRACTED, - ) - - -def _installation(tmp_path: Path) -> Path: - installation = tmp_path / "madgraph" - launcher = installation / "bin/mg5_aMC" - launcher.parent.mkdir(parents=True) - launcher.write_text("#!/bin/sh\nexit 0\n", encoding="ascii") - launcher.chmod(0o755) - shutil.copytree(_UFO_MODEL, installation / "models/sm") - (installation / "VERSION").write_text("test-version\n", encoding="ascii") - return installation - - -class _FakeExecutor: - def __init__(self, *, fail_import: bool = False) -> None: - self.fail_import = fail_import - self.calls: list[tuple[tuple[str, ...], Path]] = [] - - def run( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - ) -> madgraph.CommandResult: - rendered = tuple(os.fspath(item) for item in args) - self.calls.append((rendered, cwd)) - if Path(rendered[0]).name == "mg5_aMC": - if self.fail_import: - return madgraph.CommandResult( - rendered, - cwd, - 1.75, - 0, - "UFOImportError: installed model rejected\n", - "", - ) - self._write_standalone( - cwd, - Path(rendered[0]).parents[1] / "models/sm", - ) - return madgraph.CommandResult(rendered, cwd, 1.75, 0, "", "") - if "-o" in rendered: - output = cwd / rendered[rendered.index("-o") + 1] - output.write_text("fake driver\n", encoding="ascii") - output.chmod(0o755) - return madgraph.CommandResult(rendered, cwd, 0.4, 0, "", "") - points = int(rendered[3]) - value = 2.5 - seconds = points * 0.01 - stdout = "\n".join( - ( - f"PYAMPLICOL_MG_VALUE {value:.17e}", - f"PYAMPLICOL_MG_POINTS {points}", - f"PYAMPLICOL_MG_SECONDS {seconds:.17e}", - f"PYAMPLICOL_MG_CHECKSUM {points * value:.17e}", - "", - ) - ) - return madgraph.CommandResult(rendered, cwd, seconds, 0, stdout, "") - - @staticmethod - def _write_standalone(artifact: Path, model: Path) -> None: - standalone = artifact / "standalone" - cards = standalone / "Cards" - subprocess_dir = standalone / "SubProcesses/P0_gg_gg" - library = standalone / "lib" - source = standalone / "Source" - for directory in (cards, subprocess_dir, library, source): - directory.mkdir(parents=True) - (cards / "proc_card_mg5.dat").write_text( - "import model sm\n", - encoding="utf-8", - ) - (cards / "param_card.dat").write_text( - (model / "restrict_default.dat").read_text(encoding="utf-8"), - encoding="utf-8", - ) - (subprocess_dir / "matrix.f").write_text("C fake matrix\n", encoding="ascii") - (subprocess_dir / "matrix.o").write_bytes(b"fake object") - (library / "libdhelas.a").write_bytes(b"fake library") - (library / "libmodel.a").write_bytes(b"fake library") - (source / "make_opts").write_text( - "DEFAULT_F_COMPILER = fake-fortran\n", encoding="ascii" - ) - - -class _QuantizedTimerExecutor(_FakeExecutor): - def run( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - ) -> madgraph.CommandResult: - result = super().run(args, cwd=cwd) - rendered = tuple(os.fspath(item) for item in args) - if Path(rendered[0]).name == "mg5_aMC" or "-o" in rendered: - return result - points = int(rendered[3]) - seconds = {10: 0.001, 20: 0.0}.get(points, points * 1.0e-5) - value = 2.5 - stdout = "\n".join( - ( - f"PYAMPLICOL_MG_VALUE {value:.17e}", - f"PYAMPLICOL_MG_POINTS {points}", - f"PYAMPLICOL_MG_SECONDS {seconds:.17e}", - f"PYAMPLICOL_MG_CHECKSUM {points * value:.17e}", - "", - ) - ) - return madgraph.CommandResult(rendered, cwd, seconds, 0, stdout, "") - - -def test_command_card_uses_exact_standalone_launch_sequence_and_installed_sm() -> None: - assert madgraph.madgraph_command_card("g g > g g") == ( - "import model sm\n" - "generate g g > g g\n" - "output standalone standalone -f\n" - "launch -f\n" - ) - with pytest.raises(ValueError, match="one non-empty line"): - madgraph.madgraph_command_card("g g > g g\nimport model sm") - driver_source = madgraph_correctness._DRIVER_SOURCE - assert "iso_fortran_env, only: int64" in driver_source - assert "integer(kind=int64) :: clock_start" in driver_source - assert "if (answer /= reference) error stop 16" in driver_source - assert ( - hashlib.sha256(driver_source.encode("utf-8")).hexdigest() - == madgraph.MADGRAPH_DRIVER_SOURCE_SHA256 - ) - - -def test_numerical_acceptance_fixture_tracks_the_canonical_driver() -> None: - fixture = json.loads( - ( - _REPOSITORY / "tests/fixtures/numerical_acceptance/ufo-sm-seed101-v1.json" - ).read_text(encoding="utf-8") - ) - - assert fixture["references"]["full"]["driver_sha256"] == ( - madgraph.MADGRAPH_DRIVER_SOURCE_SHA256 - ) - - -def test_generation_guard_rejects_model_fallback_and_import_failures( - tmp_path: Path, -) -> None: - cards = tmp_path / "standalone/Cards" - cards.mkdir(parents=True) - process_card = cards / "proc_card_mg5.dat" - process_card.write_text("import model fallback\n", encoding="utf-8") - - with pytest.raises(madgraph.MadGraphAdapterError, match="bound exclusively"): - madgraph._reject_failed_generation( - _command_result(cwd=tmp_path), tmp_path / "standalone" - ) - - process_card.write_text("import model sm\n", encoding="utf-8") - madgraph._reject_failed_generation( - _command_result(cwd=tmp_path), tmp_path / "standalone" - ) - with pytest.raises(madgraph.MadGraphAdapterError, match="possible model fallback"): - madgraph._reject_failed_generation( - _command_result(cwd=tmp_path, stderr="UFOImportError: bad model"), - tmp_path / "standalone", - ) - - -def test_exact_parameter_card_matches_json_default_restriction(tmp_path: Path) -> None: - card = tmp_path / "param_card.dat" - - record = madgraph._write_exact_param_card( - card, - parameters_path=_UFO_MODEL / "parameters.py", - model_path=_JSON_MODEL, - restriction_path=_JSON_RESTRICTION, - ) - - expected = madgraph._expected_external_parameters(_JSON_MODEL, _JSON_RESTRICTION) - restriction = json.loads(_JSON_RESTRICTION.read_text(encoding="utf-8")) - rendered = card.read_text(encoding="ascii") - assert record == { - "external_parameter_count": len(expected), - "external_parameters_sha256": record["external_parameters_sha256"], - "binary64_exact_match": True, - "format": "%.14e", - } - assert set(restriction) == {name for name, _value in expected.values()} - for name, value in expected.values(): - assert f"{value:.14e} # {name}" in rendered - assert float(f"{value:.14e}") == float(restriction[name][0]) - assert ( - madgraph._validate_exact_param_card(card, _JSON_MODEL, _JSON_RESTRICTION) - == record - ) - - -def test_driver_output_parser_accepts_fortran_numbers_and_checks_checksum( - tmp_path: Path, -) -> None: - result = _command_result( - cwd=tmp_path, - stdout=( - "PYAMPLICOL_MG_VALUE 1.25D+01\n" - "PYAMPLICOL_MG_POINTS 4\n" - "PYAMPLICOL_MG_SECONDS 2.0D-03\n" - ), - stderr="PYAMPLICOL_MG_CHECKSUM 5.0D+01\n", - ) - - parsed = madgraph_correctness.parse_driver_output(result, 4) - - assert parsed.value == 12.5 - assert parsed.points == 4 - assert parsed.seconds == 0.002 - assert parsed.checksum == 50.0 - with pytest.raises(madgraph.MadGraphAdapterError, match="changed their value"): - madgraph_correctness.parse_driver_output( - _command_result( - cwd=tmp_path, - stdout=result.stdout + "PYAMPLICOL_MG_CHECKSUM 4.9D+01\n", - ), - 4, - ) - - # Sequential floating-point accumulation has an O(points * epsilon) - # forward error even when every evaluated value is identical. This is a - # real n=1 campaign calibration sample whose individual-value guard passed. - repeated_points = 65_790 - repeated = _command_result( - cwd=tmp_path, - stdout=( - "PYAMPLICOL_MG_VALUE 2.29970567613276160E+002\n" - f"PYAMPLICOL_MG_POINTS {repeated_points}\n" - "PYAMPLICOL_MG_SECONDS 6.97789999999999938E-002\n" - "PYAMPLICOL_MG_CHECKSUM 1.51297636432885565E+007\n" - ), - ) - parsed_repeated = madgraph_correctness.parse_driver_output( - repeated, repeated_points - ) - assert parsed_repeated.value == 229.97056761327616 - assert parsed_repeated.points == repeated_points - - -def test_installation_validation_requires_regular_executable_launcher( - tmp_path: Path, -) -> None: - installation = _installation(tmp_path) - launcher = installation / "bin/mg5_aMC" - - assert madgraph._validate_installation(installation) == ( - installation.resolve(), - launcher.resolve(), - (installation / "models/sm").resolve(), - ) - launcher.chmod(0o644) - with pytest.raises(madgraph.MadGraphAdapterError, match="regular executable"): - madgraph._validate_installation(installation) - launcher.unlink() - target = tmp_path / "other-launcher" - target.write_text("#!/bin/sh\n", encoding="ascii") - target.chmod(0o755) - launcher.symlink_to(target) - with pytest.raises(madgraph.MadGraphAdapterError, match="regular executable"): - madgraph._validate_installation(installation) - - -def test_adapter_fake_executor_happy_path_never_invokes_madgraph( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr( - madgraph.shutil, - "which", - lambda compiler: f"/fake/bin/{compiler}", - ) - installation = _installation(tmp_path) - artifact = tmp_path / "artifact" - executor = _FakeExecutor() - settings = madgraph.MadGraphSettings( - installation=installation, - target_runtime_seconds=0.05, - minimum_calls=2, - maximum_calls=2, - minimum_profile_chunks=5, - json_model_path=_JSON_MODEL, - restriction_json_path=_JSON_RESTRICTION, - ) - - measurement = madgraph.MadGraphMeasurementAdapter(executor=executor).measure( - _madgraph_cell(), artifact_path=artifact, settings=settings - ) - - assert measurement["status"] == ResultStatus.OK.value - assert measurement["generation_seconds"] == 1.75 - assert measurement["matrix_element"] == 2.5 - assert measurement["sample_count"] == 10 - assert measurement["wall_seconds_per_point"] == pytest.approx(0.01) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - assert provenance["command_card"] == madgraph.madgraph_command_card( - _madgraph_cell().process - ) - assert provenance["exact_param_card"]["format"] == "%.14e" - assert provenance["generation_includes_madgraph_compilation"] is True - assert provenance["model"]["name"] == "sm" - assert provenance["model"]["source_directory"] == os.fspath( - installation / "models/sm" - ) - assert len(executor.calls) == 8 - assert Path(executor.calls[0][0][0]) == installation / "bin/mg5_aMC" - - -def test_adapter_retries_a_quantized_zero_duration_profile_batch( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr( - madgraph.shutil, - "which", - lambda compiler: f"/fake/bin/{compiler}", - ) - installation = _installation(tmp_path) - executor = _QuantizedTimerExecutor() - settings = madgraph.MadGraphSettings( - installation=installation, - target_runtime_seconds=0.01, - minimum_calls=10, - maximum_calls=2_000, - minimum_profile_chunks=5, - json_model_path=_JSON_MODEL, - restriction_json_path=_JSON_RESTRICTION, - ) - - measurement = madgraph.MadGraphMeasurementAdapter(executor=executor).measure( - _madgraph_cell(), - artifact_path=tmp_path / "artifact", - settings=settings, - ) - - driver_points = [ - int(args[3]) - for args, _cwd in executor.calls - if Path(args[0]).name == "pyamplicol_madgraph_driver" - ] - assert driver_points == [10, 20, 200, 200, 200, 200, 200] - assert measurement["sample_count"] == 1_000 - assert measurement["wall_seconds_per_point"] == pytest.approx(1.0e-5) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - assert provenance["driver_timer"] == "fortran-system-clock-int64" - assert provenance["profile_calls_per_chunk"] == 200 - assert provenance["profile_attempted_chunk_count"] == 6 - assert provenance["profile_discarded_chunk_count"] == 1 - assert provenance["profile_zero_duration_chunk_count"] == 1 - - -def test_adapter_fake_executor_fails_closed_on_import_error(tmp_path: Path) -> None: - executor = _FakeExecutor(fail_import=True) - settings = madgraph.MadGraphSettings( - installation=_installation(tmp_path), - json_model_path=_JSON_MODEL, - restriction_json_path=_JSON_RESTRICTION, - ) - - with pytest.raises(madgraph.MadGraphAdapterError, match="possible model fallback"): - madgraph.MadGraphMeasurementAdapter(executor=executor).measure( - _madgraph_cell(), - artifact_path=tmp_path / "artifact", - settings=settings, - ) - assert len(executor.calls) == 1 diff --git a/pyamplicol/tests/unit/test_performance_report_measurement.py b/pyamplicol/tests/unit/test_performance_report_measurement.py deleted file mode 100644 index 97b847811d..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_measurement.py +++ /dev/null @@ -1,1417 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import subprocess -from copy import deepcopy -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.performance_report.agreements import independent_numerical_authorities -from tools.performance_report.cache import _validate_independent_authority_record -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.measurement import ( - _attach_baseline_validation, - _baseline_matrix_element, - _baseline_selector_contract, - _measurement_selector_contract, - _require_nonzero_lc_all_flow_baseline, - _requires_high_precision_validation, - _reuse_artifact_for_measurement, - _stable_runtime_identity, - _validate_runtime_identity_postflight, - _validation_failure_precision_diagnostic, - attach_validation_failure_precision_diagnostic, - baseline_uses_lc_common_component_authority, - failure_measurement, - generated_artifact_from_measurement, - measure_pyamplicol_cell, - source_revision, -) -from tools.performance_report.models import Accuracy, ExecutionMode, ResultStatus -from tools.performance_report.phase_state import ( - WorkerPhaseChannel, - WorkerPhaseReporter, - read_worker_phase_state, -) -from tools.performance_report.runner import ( - LOADED_RUNTIME_PROFILE_COMMAND_PATH, - PUBLIC_CLI_COMMAND_PATH, - GeneratedArtifact, - RunnerError, - RunnerSettings, - SelectorContract, -) - - -def _contract() -> SelectorContract: - return SelectorContract( - selected_color_flow_ids=("flow:1,2,3",), - selected_color_words=((1, 2, 3),), - all_flow_helicity_ids=("h:-1,+1,-1",), - all_flow_source_helicities=((1, -1), (2, 1), (3, -1)), - point_digest="a" * 64, - ) - - -def _unchanged_diagnostic_projection( - points: object, *, precision: int -) -> tuple[object, dict[str, object]]: - assert precision == 200 - return points, { - "abi": "pyamplicol-diagnostic-onshell-projection-v1", - "kind": "per-leg-onshell-energy-v1", - "precision_digits": precision, - "unchanged": True, - "projected_digest": "b" * 64, - } - - -def test_baseline_contract_and_matrix_element_are_strict() -> None: - baseline = { - "status": "ok", - "matrix_element": 2.0, - "selector_contract": _contract().as_dict(), - } - assert _baseline_selector_contract(baseline) == _contract() - assert _baseline_matrix_element(baseline) == 2.0 - - with pytest.raises(RunnerError, match="not a valid completed"): - _baseline_matrix_element({"status": "error"}) - with pytest.raises(RunnerError, match="no matrix element"): - _baseline_matrix_element({"status": "ok", "matrix_element": None}) - - -def test_lc_selector_uses_baseline_then_selected_flow_provider() -> None: - cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n7-dd-4q-lines-all-flow" - ) - baseline_contract = _contract() - provider_contract = SelectorContract( - selected_color_flow_ids=("flow:3,2,1",), - selected_color_words=((3, 2, 1),), - all_flow_helicity_ids=("h:+1,-1,+1",), - all_flow_source_helicities=((1, 1), (2, -1), (3, 1)), - point_digest="b" * 64, - ) - baseline = {"selector_contract": baseline_contract.as_dict()} - matching_provider = { - "status": ResultStatus.OK.value, - "selector_contract": baseline_contract.as_dict(), - } - provider = { - "status": ResultStatus.OK.value, - "selector_contract": provider_contract.as_dict(), - } - - assert _measurement_selector_contract(cell, baseline, matching_provider) == ( - baseline_contract - ) - assert _measurement_selector_contract(cell, None, provider) == provider_contract - - -@pytest.mark.parametrize( - "provider", - ( - {"status": ResultStatus.ERROR.value}, - {"status": ResultStatus.OK.value}, - { - "status": ResultStatus.OK.value, - "selector_contract": {"selected_color_flow_ids": []}, - }, - ), -) -def test_invalid_lc_selector_provider_fails_before_generation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - provider: dict[str, object], -) -> None: - import tools.performance_report.measurement as report_measurement - - cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n7-dd-4q-lines-all-flow" - ) - generation_called = False - - def unexpected_generation(*_args: object, **_kwargs: object) -> None: - nonlocal generation_called - generation_called = True - - monkeypatch.setattr(report_measurement, "generate_artifact", unexpected_generation) - - with pytest.raises((RunnerError, ValueError)): - measure_pyamplicol_cell( - cell, - artifact_path=tmp_path / "artifact", - settings=RunnerSettings(), - repo_root=tmp_path, - baseline=None, - selector_provider=provider, - ) - - assert not generation_called - - -def test_differing_baseline_and_peer_selectors_fail_before_generation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import tools.performance_report.measurement as report_measurement - - cell = REPORT_CATALOG.cell("matrix-compiled-builtin-sm-lc-n2-ud-epve-jets-all-flow") - provider_contract = SelectorContract( - selected_color_flow_ids=("flow:3,2,1",), - selected_color_words=((3, 2, 1),), - all_flow_helicity_ids=("h:+1,-1,+1",), - all_flow_source_helicities=((1, 1), (2, -1), (3, 1)), - point_digest="b" * 64, - ) - baseline = { - "status": ResultStatus.OK.value, - "selector_contract": _contract().as_dict(), - "validation": {"lc_common_component": {"value": 1.0}}, - } - provider = { - "status": ResultStatus.OK.value, - "selector_contract": provider_contract.as_dict(), - } - generation_called = False - - def unexpected_generation(*_args: object, **_kwargs: object) -> None: - nonlocal generation_called - generation_called = True - - monkeypatch.setattr(report_measurement, "generate_artifact", unexpected_generation) - - with pytest.raises(RunnerError, match=r"baseline and selected-flow.*disagree"): - measure_pyamplicol_cell( - cell, - artifact_path=tmp_path / "artifact", - settings=RunnerSettings(), - repo_root=tmp_path, - baseline=baseline, - expected_authority_cell_ids=tuple( - authority.cell_id - for authority in independent_numerical_authorities(cell) - ), - selected_authority_cell_id=independent_numerical_authorities( - cell - )[0].cell_id, - selector_provider=provider, - ) - - assert not generation_called - - -def test_lc_all_flow_baseline_must_authenticate_nonzero_common_component() -> None: - cell = REPORT_CATALOG.cell("matrix-compiled-builtin-sm-lc-n2-ud-epve-jets-all-flow") - baseline = { - "validation": { - "lc_common_component": { - "value": 1.0, - } - } - } - - _require_nonzero_lc_all_flow_baseline(cell, baseline) - - for value in (0.0, float("nan"), None): - baseline["validation"]["lc_common_component"]["value"] = value - with pytest.raises(RunnerError, match="baseline selector is structural zero"): - _require_nonzero_lc_all_flow_baseline(cell, baseline) - - -def _legacy_lc_component_baseline() -> dict[str, object]: - contract = _contract().as_dict() - return { - "status": ResultStatus.OK.value, - "matrix_element": 3.736057085488201e-8, - "selector_contract": contract, - "validation": { - "legacy_numerical_authority": { - "abi": "pyamplicol-report-legacy-numerical-authority-v1", - "source": "all-flow-selected-provider-replay", - }, - "lc_common_component": { - "abi": "pyamplicol-report-lc-common-component-v1", - "cell_id": "reference-amplicol-lc-n4-dd-tt-jets-all-flow", - "value": 2.0402809302299425e-10, - "point_digest": contract["point_digest"], - "helicity_ids": contract["all_flow_helicity_ids"], - "color_flow_ids": contract["selected_color_flow_ids"], - }, - "legacy_imode2_diagnostic": { - "authoritative_source": "selected-flow-generated-library-component", - "authoritative_value": 2.0402809302299425e-10, - "imode2_value": 2.0400817525978893e-10, - }, - }, - } - - -def test_lc_provider_replay_authenticates_component_not_aggregate() -> None: - cell = REPORT_CATALOG.cell("matrix-recurrence-builtin-sm-lc-n4-dd-tt-jets-all-flow") - baseline = _legacy_lc_component_baseline() - validation: dict[str, object] = {} - - assert baseline_uses_lc_common_component_authority(cell, baseline) - _attach_baseline_validation( - cell, - validation, - candidate_matrix_element=3.736053706261443e-8, - baseline=baseline, - ) - - assert "pointwise" not in validation - - -@pytest.mark.parametrize( - ("cell_id", "candidate_text", "generated_library", "direct_imode2"), - ( - ( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted", - "1.0521884081060938437e-7", - 1.0521886363225842e-7, - 1.0521884081060942e-7, - ), - ( - "matrix-compiled-builtin-sm-nlc-n4-dd-tt-jets-contracted", - "1.0434229425762874817e-7", - 1.0434231717649298e-7, - 1.0434229425762883e-7, - ), - ), -) -def test_n4_precision_diagnostic_retains_point_and_independent_authorities( - cell_id: str, - candidate_text: str, - generated_library: float, - direct_imode2: float, -) -> None: - from decimal import Decimal - - cell = REPORT_CATALOG.cell(cell_id) - candidate = Decimal(candidate_text) - calls: list[int] = [] - - class Resolved: - def total(self) -> tuple[Decimal]: - return (candidate,) - - class Runtime: - _diagnostic_project_onshell = staticmethod(_unchanged_diagnostic_projection) - - def evaluate( - self, _points: object, *, precision: int, **_selectors: object - ) -> tuple[Decimal]: - calls.append(precision) - return (candidate,) - - def evaluate_resolved( - self, _points: object, *, precision: int, **_selectors: object - ) -> Resolved: - assert precision in {32, 200} - return Resolved() - - baseline = { - "status": ResultStatus.OK.value, - "matrix_element": generated_library, - "validation": { - "legacy_numerical_authority": { - "abi": "pyamplicol-report-legacy-numerical-authority-v1", - "source": "contracted-generated-library", - }, - "legacy_imode2_diagnostic": { - "authoritative_source": "dedicated-generated-library-probe", - "authoritative_value": generated_library, - "imode2_value": direct_imode2, - }, - }, - } - points = ((500.0, 0.0, 0.0, 500.0),) - - diagnostic = _validation_failure_precision_diagnostic( - Runtime(), - points, - cell=cell, - contract=None, - baseline=baseline, - measurement_context={ - "wall_seconds_per_point": 1.5e-6, - "provenance": { - "evaluator_total_timing": {"raw_seconds_per_point": 1.4e-6}, - "execution_timing": {"raw_seconds_per_point": 1.3e-6}, - }, - }, - ) - - assert diagnostic["status"] == "diagnostic-only" - assert diagnostic["promotes_measurement"] is False - assert diagnostic["timings_unchanged"] is True - assert diagnostic["execution_identity"] == { - "cell_id": cell_id, - "process": "d d~ > t t~ g g", - "multiplicity": 4, - "workload": "contracted", - "layout": "contracted", - "execution_mode": "compiled", - "backend": "jit", - "model": "builtin_sm", - "accuracy": cell.measurement.accuracy.value, - "variant": None, - } - assert diagnostic["measurement_timing_context"] == { - "source": "copied-from-measurement", - "recomputed": False, - "outer_wall_seconds_per_point": 1.5e-6, - "evaluator_total_timing": {"raw_seconds_per_point": 1.4e-6}, - "recurrence_core_timing": None, - } - assert diagnostic["retained_point"]["momenta"] == [[500.0, 0.0, 0.0, 500.0]] - assert calls == [32, 200] - assert [attempt["precision_digits"] for attempt in diagnostic["attempts"]] == [ - 32, - 200, - ] - comparisons = diagnostic["attempts"][-1]["comparisons"] - generated = [ - item - for item in comparisons - if item["authority"] == "baseline:generated-library" - ] - direct = [ - item for item in comparisons if item["authority"] == "baseline:direct-imode2" - ] - assert {item["candidate_value_kind"] for item in generated} == { - "total", - "resolved_sum", - } - assert {item["status"] for item in generated} == { - ResultStatus.VALIDATION_FAILED.value - } - assert {item["status"] for item in direct} == {ResultStatus.OK.value} - - -def test_lc_precision_diagnostic_compares_shared_component() -> None: - from decimal import Decimal - - cell = REPORT_CATALOG.cell("matrix-recurrence-builtin-sm-lc-n4-dd-tt-jets-all-flow") - contract = _contract() - aggregate = Decimal("3.7360537062614512535e-8") - component = Decimal("2.0402809302299355e-10") - points = ((500.0, 0.0, 0.0, 500.0),) - received: list[object] = [] - projection_calls: list[tuple[object, int]] = [] - - class Resolved: - def __init__(self, component_only: bool) -> None: - self.helicity_ids = ( - contract.runtime_all_flow_helicity_ids if component_only else () - ) - self.color_ids = contract.selected_color_flow_ids if component_only else () - self.values = (((component,),),) if component_only else () - - def total(self) -> tuple[Decimal]: - return (aggregate,) - - class Runtime: - def _diagnostic_project_onshell( - self, raw_points: object, *, precision: int - ) -> tuple[object, dict[str, object]]: - projection_calls.append((raw_points, precision)) - return _unchanged_diagnostic_projection( - raw_points, - precision=precision, - ) - - def evaluate(self, raw_points: object, **_selectors: object): - received.append(raw_points) - return (aggregate,) - - def evaluate_resolved( - self, - raw_points: object, - *, - color_flows: object = None, - **_selectors: object, - ) -> Resolved: - received.append(raw_points) - return Resolved(color_flows is not None) - - diagnostic = _validation_failure_precision_diagnostic( - Runtime(), - points, - cell=cell, - contract=contract, - baseline=_legacy_lc_component_baseline(), - measurement_context={ - "wall_seconds_per_point": 2.5e-6, - "provenance": { - "evaluator_total_timing": {"raw_seconds_per_point": 2.4e-6}, - "execution_timing": {"raw_seconds_per_point": 2.3e-6}, - }, - }, - ) - - final = diagnostic["attempts"][-1] - assert projection_calls == [(points, 200)] - assert len(received) == 6 - assert all(raw_points is points for raw_points in received) - assert diagnostic["measurement_timing_context"] == { - "source": "copied-from-measurement", - "recomputed": False, - "outer_wall_seconds_per_point": 2.5e-6, - "evaluator_total_timing": {"raw_seconds_per_point": 2.4e-6}, - "recurrence_core_timing": {"raw_seconds_per_point": 2.3e-6}, - } - assert final["candidate"]["lc_common_component"]["value"] == str(component) - comparisons = {item["authority"]: item for item in final["comparisons"]} - assert comparisons["baseline:generated-library"]["status"] == ( - ResultStatus.OK.value - ) - assert comparisons["baseline:direct-imode2"]["status"] == ( - ResultStatus.VALIDATION_FAILED.value - ) - - -def test_precision_diagnostic_stops_after_resolved_p32() -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted" - ) - calls: list[int] = [] - - class Resolved: - def total(self) -> tuple[float]: - return (1.0,) - - class Runtime: - _diagnostic_project_onshell = staticmethod(_unchanged_diagnostic_projection) - - def evaluate(self, _points: object, *, precision: int, **_selectors: object): - calls.append(precision) - return (1.0,) - - def evaluate_resolved( - self, _points: object, *, precision: int, **_selectors: object - ) -> Resolved: - return Resolved() - - diagnostic = _validation_failure_precision_diagnostic( - Runtime(), - ((500.0, 0.0, 0.0, 500.0),), - cell=cell, - contract=None, - baseline={"status": ResultStatus.OK.value, "matrix_element": 1.0}, - ) - - assert calls == [32] - assert [attempt["precision_digits"] for attempt in diagnostic["attempts"]] == [32] - - -def test_precision_diagnostic_records_p32_error_then_attempts_p200() -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted" - ) - calls: list[int] = [] - - class Resolved: - def total(self) -> tuple[float]: - return (1.0,) - - class Runtime: - _diagnostic_project_onshell = staticmethod(_unchanged_diagnostic_projection) - - def evaluate(self, _points: object, *, precision: int, **_selectors: object): - calls.append(precision) - if precision == 32: - raise RuntimeError("p32 diagnostic failure") - return (1.0,) - - def evaluate_resolved( - self, _points: object, *, precision: int, **_selectors: object - ) -> Resolved: - return Resolved() - - diagnostic = _validation_failure_precision_diagnostic( - Runtime(), - ((500.0, 0.0, 0.0, 500.0),), - cell=cell, - contract=None, - baseline={"status": ResultStatus.OK.value, "matrix_element": 1.0}, - ) - - assert calls == [32, 200] - assert diagnostic["attempts"][0]["status"] == "unavailable" - assert diagnostic["attempts"][0]["error"]["message"] == ("p32 diagnostic failure") - assert diagnostic["attempts"][1]["status"] == "evaluated" - - -def test_precision_diagnostic_reuses_projection_and_contextualizes_peers() -> None: - from decimal import Decimal - - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted" - ) - original = ((500.0, 0.0, 0.0, 500.0),) - projected = ( - (Decimal("500.0000000000000001"), Decimal(0), Decimal(0), Decimal(500)), - ) - received: list[object] = [] - projection_calls: list[tuple[object, int]] = [] - - class Resolved: - def total(self) -> tuple[Decimal]: - return (Decimal("2"),) - - class Runtime: - def _diagnostic_project_onshell( - self, points: object, *, precision: int - ) -> tuple[object, dict[str, object]]: - projection_calls.append((points, precision)) - return projected, { - "unchanged": False, - "projected_digest": "c" * 64, - } - - def evaluate( - self, points: object, *, precision: int, **_selectors: object - ) -> tuple[Decimal]: - assert precision in {32, 200} - received.append(points) - return (Decimal("2"),) - - def evaluate_resolved( - self, points: object, *, precision: int, **_selectors: object - ) -> Resolved: - assert precision in {32, 200} - received.append(points) - return Resolved() - - diagnostic = _validation_failure_precision_diagnostic( - Runtime(), - original, - cell=cell, - contract=None, - baseline={"status": ResultStatus.OK.value, "matrix_element": 1.0}, - ) - - assert projection_calls == [(original, 200)] - assert len(received) == 4 - assert all(points is projected for points in received) - assert ( - diagnostic["kinematic_projection"]["original_digest"] - == (diagnostic["retained_point"]["digest"]) - ) - assert diagnostic["kinematic_projection"]["projected_digest"] == "c" * 64 - assert [attempt["precision_digits"] for attempt in diagnostic["attempts"]] == [ - 32, - 200, - ] - for attempt in diagnostic["attempts"]: - assert attempt["candidate"]["point_context"] == "projected-onshell-point" - for comparison in attempt["comparisons"]: - assert comparison["authority_point_context"] == "original-retained-point" - assert comparison["same_kinematic_point"] is False - assert comparison["certifying"] is False - assert comparison["context_only"] is True - assert "status" not in comparison - - -def test_precision_diagnostic_is_bounded_and_non_promoting( - monkeypatch: pytest.MonkeyPatch, -) -> None: - outside = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-lc-n5-dd-z-jets-selected-flow" - ) - measurement = { - "status": ResultStatus.VALIDATION_FAILED.value, - "validation": {"status": ResultStatus.VALIDATION_FAILED.value}, - } - attach_validation_failure_precision_diagnostic(outside, measurement, baseline=None) - assert "precision_diagnostic" not in measurement["validation"] - - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted" - ) - monkeypatch.setattr( - "tools.performance_report.measurement.point_digest", - lambda _points: (_ for _ in ()).throw(RuntimeError("diagnostic only")), - ) - diagnostic = _validation_failure_precision_diagnostic( - object(), object(), cell=cell, contract=None, baseline=None - ) - assert diagnostic["status"] == "unavailable" - assert diagnostic["promotes_measurement"] is False - - -def test_failure_measurement_preserves_compact_cache_shape() -> None: - measurement = failure_measurement( - ResultStatus.MEMORY_LIMIT, - RuntimeError("over limit"), - resources={"peak_rss_bytes": 42}, - ) - - assert measurement["status"] == "memory_limit" - assert measurement["generation_seconds"] is None - assert measurement["resources"] == {"peak_rss_bytes": 42} - assert measurement["failure"] == { - "kind": "RuntimeError", - "message": "over limit", - } - - -def test_reused_artifact_closes_current_worker_generation_phase( - tmp_path: Path, -) -> None: - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - ticks = iter((100, 200, 300)) - reporter = WorkerPhaseReporter( - channel, - worker_pid=42, - clock_ns=lambda: next(ticks), - ) - artifact = GeneratedArtifact( - path=tmp_path / "artifact", - process_id="process", - generation_seconds=6.5, - model_preparation_seconds=1.0, - model_preparation_reused=True, - requested_config={}, - effective_config={}, - ) - - assert ( - _reuse_artifact_for_measurement( - artifact, - phase_reporter=reporter, - ) - is artifact - ) - state = read_worker_phase_state(channel, expected_pid=42) - - assert state.phase == "post-generation" - assert state.sequence == 2 - assert state.generation_started_monotonic_ns == 200 - assert state.generation_finished_monotonic_ns == 300 - assert state.generation_elapsed_seconds(now_seconds=1.0) == 1.0e-7 - - -def test_measurement_routes_reused_artifact_through_phase_completion( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import tools.performance_report.measurement as report_measurement - - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - ) - artifact = GeneratedArtifact( - path=tmp_path / "artifact", - process_id="process", - generation_seconds=6.5, - model_preparation_seconds=1.0, - model_preparation_reused=True, - requested_config={}, - effective_config={}, - ) - reporter = object() - observed: list[tuple[GeneratedArtifact, object]] = [] - - def reuse( - value: GeneratedArtifact, - *, - phase_reporter: object, - ) -> GeneratedArtifact: - observed.append((value, phase_reporter)) - return value - - def stop_after_selection(*_args: object, **_kwargs: object) -> None: - raise RuntimeError("selection observed") - - monkeypatch.setattr(report_measurement, "_reuse_artifact_for_measurement", reuse) - monkeypatch.setattr( - report_measurement, - "validate_artifact_contract", - stop_after_selection, - ) - - with pytest.raises(RuntimeError, match="selection observed"): - measure_pyamplicol_cell( - cell, - artifact_path=tmp_path / "unused", - settings=RunnerSettings(), - repo_root=tmp_path, - baseline=None, - reused_artifact=artifact, - phase_reporter=reporter, # type: ignore[arg-type] - ) - - assert observed == [(artifact, reporter)] - - -def test_reusable_artifact_retains_generation_command_path(tmp_path: Path) -> None: - artifact_path = tmp_path / "artifact" - artifact_path.mkdir() - measurement = { - "status": ResultStatus.OK.value, - "generation_seconds": 2.5, - "artifact": {"path": str(artifact_path), "process_id": "process"}, - "provenance": { - "requested_config": {}, - "effective_config": {}, - "model_preparation_seconds": 0.25, - "model_preparation_reused": True, - "generation_command_path": PUBLIC_CLI_COMMAND_PATH, - "numerical_relation_correctness": { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - }, - "numerical_relation_fallback": { - "abi": "pyamplicol-numerical-current-reuse-fallback-v1", - "requested_mode": "certified-reuse", - "effective_mode": "off", - "effective_reuse_state": "disabled", - "reason": "evidence-envelope-fallback", - "geometry": {"current_count": 4}, - "certified_relation_count": 0, - "applied_relation_count": 0, - }, - }, - } - - artifact = generated_artifact_from_measurement(measurement) - - assert artifact.generation_command_path == PUBLIC_CLI_COMMAND_PATH - assert artifact.numerical_relation_correctness == { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - } - assert artifact.numerical_relation_fallback == { - "abi": "pyamplicol-numerical-current-reuse-fallback-v1", - "requested_mode": "certified-reuse", - "effective_mode": "off", - "effective_reuse_state": "disabled", - "reason": "evidence-envelope-fallback", - "geometry": {"current_count": 4}, - "certified_relation_count": 0, - "applied_relation_count": 0, - } - - del measurement["provenance"]["generation_command_path"] - legacy = generated_artifact_from_measurement(measurement) - assert legacy.generation_command_path is None - - measurement["provenance"]["generation_command_path"] = 42 - with pytest.raises(RunnerError, match="reusable artifact metadata is malformed"): - generated_artifact_from_measurement(measurement) - - measurement["provenance"]["generation_command_path"] = PUBLIC_CLI_COMMAND_PATH - measurement["provenance"]["numerical_relation_fallback"] = 42 - with pytest.raises(RunnerError, match="reusable artifact metadata is malformed"): - generated_artifact_from_measurement(measurement) - - -def test_measurement_persists_generation_and_runtime_command_paths( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import tools.performance_report.measurement as report_measurement - - cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.accuracy is Accuracy.NLC - ) - artifact_path = tmp_path / "artifact" - artifact = GeneratedArtifact( - path=artifact_path, - process_id="process", - generation_seconds=2.5, - model_preparation_seconds=0.25, - model_preparation_reused=True, - requested_config={}, - effective_config={}, - generation_command_path=PUBLIC_CLI_COMMAND_PATH, - numerical_relation_correctness={ - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - }, - numerical_relation_fallback={ - "abi": "pyamplicol-numerical-current-reuse-fallback-v1", - "requested_mode": "certified-reuse", - "effective_mode": "off", - "effective_reuse_state": "disabled", - "reason": "evidence-envelope-fallback", - "geometry": {"current_count": 4}, - "certified_relation_count": 0, - "applied_relation_count": 0, - }, - ) - - class Runtime: - def evaluate(self, *_args: object, **_kwargs: object) -> list[float]: - return [1.0] - - identity = { - "loaded_module_origin_policy": { - "observations": [], - } - } - - def resolved_record(precision: int) -> dict[str, object]: - comparison = report_measurement.pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": "f" * 64, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "a" * 64, - "resolved_source_sha256": ("b" if precision == 16 else "c") * 64, - "point_index": 0, - }, - ) - return { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": ResultStatus.OK.value, - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": "f" * 64, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "a" * 64, - "resolved_source_sha256": ("b" if precision == 16 else "c") * 64, - "scale_source": "resolved-component-l1", - "precision_digits": precision, - "points": [comparison], - } - - profile = { - "status": ResultStatus.OK.value, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 0.5e-6, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.1e-6, - "relative_standard_error": 0.1, - "execution_timing": {}, - "arena_profile_evidence": {}, - "benchmark_evidence": { - "report_command_path": LOADED_RUNTIME_PROFILE_COMMAND_PATH, - }, - "resolved_sum_validation": resolved_record(16), - } - monkeypatch.setattr( - report_measurement, - "generate_artifact", - lambda *_args, **_kwargs: artifact, - ) - monkeypatch.setattr( - report_measurement, - "validate_artifact_contract", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - report_measurement, - "_load_runtime", - lambda *_args, **_kwargs: Runtime(), - ) - monkeypatch.setattr( - report_measurement, - "runtime_identity_payload", - lambda *_args, **_kwargs: identity, - ) - monkeypatch.setattr( - report_measurement, - "shared_validation_points", - lambda _process: ((1.0,),), - ) - monkeypatch.setattr( - report_measurement, - "_resolution_benchmark_config", - lambda _config: object(), - ) - monkeypatch.setattr( - report_measurement, - "profile_runtime", - lambda *_args, **_kwargs: deepcopy(profile), - ) - monkeypatch.setattr( - report_measurement, - "resolved_sum_validation", - lambda *_args, precision=16, **_kwargs: resolved_record(precision), - ) - - measurement = measure_pyamplicol_cell( - cell, - artifact_path=artifact_path, - settings=RunnerSettings(source_revision_override="a" * 40), - repo_root=tmp_path, - baseline=None, - ) - - provenance = measurement["provenance"] - assert provenance["generation_command_path"] == PUBLIC_CLI_COMMAND_PATH - assert provenance["numerical_relation_fallback"]["reason"] == ( - "evidence-envelope-fallback" - ) - assert provenance["report_momenta"] == [[1.0]] - assert ( - provenance["runtime_profile"]["report_command_path"] - == LOADED_RUNTIME_PROFILE_COMMAND_PATH - ) - - -@pytest.mark.parametrize( - ( - "cell_id", - "authority_available", - "standalone", - "p32_matches", - "custom_authority", - ), - ( - ( - "matrix-compiled-builtin-sm-nlc-n1-dd-z-jets-contracted", - True, - False, - True, - False, - ), - ( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted", - True, - False, - True, - False, - ), - ( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted", - False, - False, - True, - False, - ), - ( - "scalar-contact-n2-scalar-contact-contracted", - False, - True, - True, - False, - ), - ( - "scalar-gravity-n2-scalar-gravity-contracted", - False, - True, - True, - False, - ), - ( - "scalar-contact-n2-scalar-contact-contracted", - False, - True, - False, - False, - ), - ( - "scalar-contact-n2-scalar-contact-contracted", - True, - False, - True, - True, - ), - ), -) -def test_initial_compiled_authority_uses_nested_resolved_point_identity( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - cell_id: str, - authority_available: bool, - standalone: bool, - p32_matches: bool, - custom_authority: bool, -) -> None: - import tools.performance_report.measurement as report_measurement - - cell = REPORT_CATALOG.cell(cell_id) - - class CustomAuthorityCatalog: - """Make one scalar use the ordinary matrix authority chain.""" - - def measurement_cells(self): - return REPORT_CATALOG.measurement_cells() - - def validation_baseline_cell(self, candidate): - if candidate == cell: - return REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n1-dd-z-jets-contracted" - ) - return REPORT_CATALOG.validation_baseline_cell(candidate) - - catalog = CustomAuthorityCatalog() if custom_authority else REPORT_CATALOG - validation_points = ((1.0,),) - point_identity = report_measurement.point_digest(validation_points) - source = "b" * 64 - resolved_point = report_measurement.pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "a" * 64, - "resolved_source_sha256": source, - "point_index": 0, - }, - ) - resolved = { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": ResultStatus.OK.value, - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "a" * 64, - "resolved_source_sha256": source, - "scale_source": "resolved-component-l1", - "precision_digits": 16, - "points": [resolved_point], - } - p32_resolved = {**deepcopy(resolved), "precision_digits": 32} - if not p32_matches: - p32_resolved["points"] = [ - report_measurement.pointwise_validation( - 2.0, - 2.0, - candidate_scale=2.0, - baseline_scale=2.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": "a" * 64, - "resolved_source_sha256": source, - "point_index": 0, - }, - ) - ] - artifact_path = tmp_path / "artifact" - artifact = GeneratedArtifact( - path=artifact_path, - process_id="process", - generation_seconds=1.0, - model_preparation_seconds=0.0, - model_preparation_reused=True, - requested_config={}, - effective_config={}, - ) - profile = { - "status": ResultStatus.OK.value, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 0.8e-6, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "execution_timing": {}, - "arena_profile_evidence": {}, - "benchmark_evidence": {}, - "resolved_sum_validation": resolved, - } - identity = {"loaded_module_origin_policy": {"observations": []}} - - class Runtime: - def _diagnostic_project_onshell( - self, - points: object, - *, - precision: int, - ) -> tuple[object, dict[str, object]]: - assert precision == 200 - return points, {"unchanged": True, "projected_digest": point_identity} - - def evaluate(self, *_args: object, **_kwargs: object) -> list[float]: - return [1.0] - - def evaluate_resolved( - self, - *_args: object, - **_kwargs: object, - ) -> SimpleNamespace: - return SimpleNamespace( - total=lambda: (1.0,), - values=(((1.0,),),), - helicity_ids=(), - color_ids=(), - ) - monkeypatch.setattr( - report_measurement, - "generate_artifact", - lambda *_args, **_kwargs: artifact, - ) - monkeypatch.setattr( - report_measurement, - "validate_artifact_contract", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - report_measurement, - "_load_runtime", - lambda *_args, **_kwargs: Runtime(), - ) - monkeypatch.setattr( - report_measurement, - "runtime_identity_payload", - lambda *_args, **_kwargs: identity, - ) - monkeypatch.setattr( - report_measurement, - "shared_validation_points", - lambda _process: validation_points, - ) - if standalone or cell.measurement.model in { - report_measurement.ModelKey.SCALAR_CONTACT, - report_measurement.ModelKey.SCALAR_GRAVITY, - }: - monkeypatch.setattr( - report_measurement, - "runtime_validation_points", - lambda _runtime: validation_points, - ) - monkeypatch.setattr( - report_measurement, - "_resolution_benchmark_config", - lambda _config: object(), - ) - monkeypatch.setattr( - report_measurement, - "profile_runtime", - lambda *_args, **_kwargs: deepcopy(profile), - ) - monkeypatch.setattr( - report_measurement, - "resolved_sum_validation", - lambda *_args, **_kwargs: ( - pytest.fail("p32 is diagnostic-only with authority") - if authority_available and not custom_authority - else deepcopy(p32_resolved) - ), - ) - authorities = independent_numerical_authorities(cell, catalog=catalog) # type: ignore[arg-type] - baseline = { - "status": ResultStatus.OK.value, - "matrix_element": 1.0, - "selector_contract": None, - "validation": {"point_digest": point_identity}, - "provenance": {}, - } - - measurement = measure_pyamplicol_cell( - cell, - artifact_path=artifact_path, - settings=RunnerSettings(source_revision_override="a" * 40), - repo_root=tmp_path, - baseline=baseline if authority_available else None, - expected_authority_cell_ids=tuple(item.cell_id for item in authorities), - selected_authority_cell_id=( - authorities[0].cell_id if authority_available else None - ), - catalog=catalog, # type: ignore[arg-type] - ) - - if custom_authority: - validation = measurement["validation"] - assert isinstance(validation, dict) - _validate_independent_authority_record( - validation, - expected_cell=cell, - expected_status="verified", - catalog=catalog, # type: ignore[arg-type] - ) - with pytest.raises(ValueError, match="not applicable"): - _validate_independent_authority_record( - validation, - expected_cell=cell, - expected_status="verified", - catalog=REPORT_CATALOG, - ) - - validation = measurement["validation"] - if authority_available: - assert measurement["status"] == ResultStatus.OK.value - assert validation["pointwise"]["status"] == ResultStatus.OK.value - assert validation["independent_authority"]["selected_cell_id"] == ( - authorities[0].cell_id - ) - elif standalone and p32_matches: - assert authorities == () - assert measurement["status"] == ResultStatus.OK.value - assert measurement["failure"] is None - assert validation["high_precision"]["status"] == ResultStatus.OK.value - assert "independent_authority" not in validation - assert "precision_diagnostic" not in validation - elif standalone: - assert authorities == () - assert measurement["status"] == ResultStatus.VALIDATION_FAILED.value - assert measurement["failure"]["kind"] == "MeasurementValidationError" - assert validation["high_precision"]["status"] == ( - ResultStatus.VALIDATION_FAILED.value - ) - assert "independent_authority" not in validation - else: - assert measurement["status"] == ResultStatus.UNVERIFIED.value - assert measurement["failure"]["kind"] == "IndependentAuthorityUnavailable" - assert validation["independent_authority"]["status"] == "unavailable" - assert [ - attempt["precision_digits"] - for attempt in validation["precision_diagnostic"]["attempts"] - ] == [32, 200] - - -def test_catalog_contains_no_amplicol_candidate_matrix_cell() -> None: - assert all( - cell.measurement.execution_mode.value != "amplicol" - for cell in REPORT_CATALOG.matrix_cells() - ) - - -def test_legacy_amplicol_diagnostic_does_not_replace_p32_certification() -> None: - recurrence = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n1-dd-z-jets-contracted" - ) - legacy = {"status": ResultStatus.OK.value, "matrix_element": 1.0} - - assert _requires_high_precision_validation( - recurrence, - baseline=legacy, - selected_authority_cell_id=None, - catalog=REPORT_CATALOG, - ) == (True, True) - - compiled = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted" - ) - recurrence_authority = {"status": ResultStatus.OK.value, "matrix_element": 1.0} - assert _requires_high_precision_validation( - compiled, - baseline=recurrence_authority, - selected_authority_cell_id=recurrence.cell_id, - catalog=REPORT_CATALOG, - ) == (False, False) - - -def test_source_revision_rejects_source_dirt_but_allows_report_outputs( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - repo.mkdir() - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-test@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Test"), - cwd=repo, - check=True, - ) - source = repo / "source.py" - source.write_text("VALUE = 1\n", encoding="utf-8") - subprocess.run(("git", "add", "source.py"), cwd=repo, check=True) - subprocess.run(("git", "commit", "-q", "-m", "initial"), cwd=repo, check=True) - - revision = source_revision(repo, require_clean=True) - assert len(revision) == 40 - - cache = repo / "docs/arxiv/results/z_builtin_sm.json" - cache.parent.mkdir(parents=True) - cache.write_text("{}\n", encoding="ascii") - table = repo / "docs/arxiv/result_z_builtin_sm_table.tex" - table.write_text("% generated\n", encoding="ascii") - assert source_revision(repo, require_clean=True) == revision - - source.write_text("VALUE = 2\n", encoding="utf-8") - with pytest.raises(RunnerError, match="outside generated report outputs"): - source_revision(repo, require_clean=True) - - -def _runtime_identity() -> dict[str, object]: - observations = [ - { - "module": "pyamplicol", - "kind": "package-member", - "root_index": 0, - "path": "__init__.py", - "size": 10, - "sha256": "1" * 64, - } - ] - return { - "kind": "pyamplicol-report-runtime-identity-v1", - "loaded_module_origin_policy": { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": len(observations), - "observations": observations, - "observations_sha256": "a" * 64, - }, - } - - -def test_runtime_identity_postflight_is_stable_and_monotonic() -> None: - initial = _runtime_identity() - postflight = deepcopy(initial) - policy = postflight["loaded_module_origin_policy"] - assert isinstance(policy, dict) - observations = policy["observations"] - assert isinstance(observations, list) - observations.append( - { - "module": "pyamplicol.runtime", - "kind": "package-member", - "root_index": 0, - "path": "runtime/__init__.py", - "size": 20, - "sha256": "2" * 64, - } - ) - policy["observed_module_count"] = len(observations) - _validate_runtime_identity_postflight(initial, postflight) - assert _stable_runtime_identity(initial) == _stable_runtime_identity(postflight) - - changed = deepcopy(postflight) - changed["native_build_inputs_sha256"] = "3" * 64 - with pytest.raises(RunnerError, match="changed during report measurement"): - _validate_runtime_identity_postflight(initial, changed) - - lost = deepcopy(postflight) - lost_policy = lost["loaded_module_origin_policy"] - assert isinstance(lost_policy, dict) - lost_observations = lost_policy["observations"] - assert isinstance(lost_observations, list) - lost_observations.pop(0) - lost_policy["observed_module_count"] = len(lost_observations) - with pytest.raises(RunnerError, match="lost an authenticated"): - _validate_runtime_identity_postflight(initial, lost) diff --git a/pyamplicol/tests/unit/test_performance_report_measurement_lineage.py b/pyamplicol/tests/unit/test_performance_report_measurement_lineage.py deleted file mode 100644 index 6e5c885f1a..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_measurement_lineage.py +++ /dev/null @@ -1,466 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.measurement_lineage import ( - CLASS_C_HZZ_IMPACT, - MEASUREMENT_LINEAGE_FILENAME, - MEASUREMENT_LINEAGE_SCHEMA, - MeasurementLineageError, - _catalog_digest, - _digest, - _load_envelope, - audit_measurement_lineage, - class_c_pending_path, - finalize_class_c_bridge, - hzz_agreement_closure, - hzz_impacted_cells, - load_measurement_lineage, - prepare_class_c_bridge, -) -from tools.performance_report.models import ArtifactPolicy, ExecutionMode, ModelKey -from tools.performance_report.workspace import ( - _authenticated_environment_payload, - _environment_tex, -) - - -def _git(repo: Path, *arguments: str) -> str: - return subprocess.run( - ("git", *arguments), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - -def _runtime( - package_tree: str, - *, - source_revision: str, - native_build_inputs: str = "a" * 64, - native_extension: str = "b" * 64, -) -> dict[str, object]: - return { - "package_version": "0.1.0", - "native_build_inputs_sha256": native_build_inputs, - "native_extension": {"sha256": native_extension}, - "python_package_tree": {"sha256": package_tree}, - "candidate_build_identity": { - "candidate_fingerprint": "candidate-fixture", - "source_revision": source_revision, - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": ["neon"], - }, - } - - -def _write(repo: Path, relative: str, value: str | bytes) -> None: - path = repo / relative - path.parent.mkdir(parents=True, exist_ok=True) - if isinstance(value, bytes): - path.write_bytes(value) - else: - path.write_text(value, encoding="utf-8") - - -def _repository(tmp_path: Path) -> tuple[Path, Path, ArtifactStore, str]: - repo = tmp_path / "repo" - repo.mkdir() - _git(repo, "init", "-q") - _git(repo, "config", "user.email", "lineage@example.invalid") - _git(repo, "config", "user.name", "Lineage Test") - profile = repo / "docs/performance_reports/macbook_M3" - _write( - repo, - "docs/performance_reports/macbook_M3/report-workspace.json", - json.dumps({"campaign_policy": {"name": "fixture"}}) + "\n", - ) - _write(repo, "src/pyamplicol/models/builtin/lowering.py", "VALUE = 1\n") - for path in ( - "tests/unit/test_model_builtin.py", - "tests/unit/test_packaged_prepared_model.py", - "tests/unit/test_recurrence_catalog_builder.py", - ): - _write(repo, path, "VALUE = 1\n") - for root in ( - "src/pyamplicol/assets/prepared_models", - "release_assets/prepared_models", - ): - for architecture in ("aarch64", "x86_64"): - stem = f"built-in-sm-jit-o2-{architecture}" - _write(repo, f"{root}/{stem}.pyamplicol-model", b"old bundle\n") - _write(repo, f"{root}/{stem}.metadata.json", '{"old":true}\n') - _git(repo, "add", ".") - _git(repo, "commit", "-q", "-m", "ancestor") - ancestor = _git(repo, "rev-parse", "HEAD") - environment = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision=ancestor, - active_runtime=_runtime("c" * 64, source_revision=ancestor), - ) - _write( - repo, - "docs/performance_reports/macbook_M3/report_environment.json", - json.dumps(environment, sort_keys=True) + "\n", - ) - store = ArtifactStore( - artifact_root=repo / ".artifacts/performance-report/macbook_M3", - lock_root=repo - / ".artifacts/performance-report-coordination/macbook_M3", - ) - retained = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - ancestor_tree = _git(repo, "rev-parse", "HEAD^{tree}") - store.new_attempt(retained.cell_id, ArtifactPolicy.REGENERATE).publish( - { - "status": "ok", - "provenance": { - "report_source_revision": ancestor, - "report_source_tree": ancestor_tree, - "report_measured_source_revision": ancestor, - "report_measured_source_tree": ancestor_tree, - }, - } - ) - _write(repo, "src/pyamplicol/models/builtin/lowering.py", "VALUE = 2\n") - for path in ( - "tests/unit/test_model_builtin.py", - "tests/unit/test_packaged_prepared_model.py", - "tests/unit/test_recurrence_catalog_builder.py", - ): - _write(repo, path, "VALUE = 2\n") - for root in ( - "src/pyamplicol/assets/prepared_models", - "release_assets/prepared_models", - ): - for architecture in ("aarch64", "x86_64"): - stem = f"built-in-sm-jit-o2-{architecture}" - _write(repo, f"{root}/{stem}.pyamplicol-model", b"new bundle\n") - _write(repo, f"{root}/{stem}.metadata.json", '{"new":true}\n') - _git(repo, "add", "src/pyamplicol/models/builtin/lowering.py") - _git(repo, "add", "src/pyamplicol/assets/prepared_models") - _git(repo, "add", "release_assets/prepared_models") - _git(repo, "add", "tests/unit/test_model_builtin.py") - _git(repo, "add", "tests/unit/test_packaged_prepared_model.py") - _git(repo, "add", "tests/unit/test_recurrence_catalog_builder.py") - _git(repo, "commit", "-q", "-m", "descendant") - return repo, profile, store, ancestor - - -def test_hzz_impact_and_direct_agreement_closure_are_exact() -> None: - impacted = hzz_impacted_cells() - closure = hzz_agreement_closure() - - assert len(impacted) == 20 - assert len(closure) == 20 - assert all( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - and cell.process_key == "dd_zzz_jets" - and cell.n_final >= 3 - for cell in impacted - ) - assert all( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.UFO_SM - and cell.process_key == "dd_zzz_jets" - and cell.n_final >= 3 - for cell in closure - ) - assert {cell.cell_id for cell in impacted}.isdisjoint( - cell.cell_id for cell in closure - ) - - -def test_lineage_v2_binds_static_na_catalog_semantics() -> None: - class CatalogWithoutStaticNa: - def __getattr__(self, name: str) -> object: - return getattr(REPORT_CATALOG, name) - - def static_na_reason(self, _cell: object) -> None: - return None - - assert MEASUREMENT_LINEAGE_SCHEMA == ( - "pyamplicol-performance-measurement-lineage-v2" - ) - assert _catalog_digest( - CatalogWithoutStaticNa(), # type: ignore[arg-type] - ) != _catalog_digest(REPORT_CATALOG) - - -def test_lineage_v1_envelope_is_rejected_and_requires_reseal( - tmp_path: Path, -) -> None: - repo, profile, store, ancestor = _repository(tmp_path) - descendant = _git(repo, "rev-parse", "HEAD") - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - pending = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - envelope = json.loads(pending.read_text(encoding="ascii")) - envelope["payload"]["schema"] = ( - "pyamplicol-performance-measurement-lineage-v1" - ) - envelope["payload_sha256"] = _digest(envelope["payload"]) - pending.write_text( - json.dumps( - envelope, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n", - encoding="ascii", - ) - - with pytest.raises( - MeasurementLineageError, - match="schema is incompatible", - ): - _load_envelope(pending, expected_state="pending") - - -def test_prepare_finalize_and_audit_class_c_bridge( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor = _repository(tmp_path) - descendant = _git(repo, "rev-parse", "HEAD") - prepared = prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - pending = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - - assert prepared["state"] == "pending" - assert len(prepared["retained_currents"]) == 1 - assert len(prepared["impacted_cells"]) == 20 - assert len(prepared["agreement_closure_cells"]) == 20 - assert len(prepared["no_attempt_cells"]) == len( - REPORT_CATALOG.measurement_cells() - ) - 1 - - relinked_runtime = _runtime( - "d" * 64, - source_revision=descendant, - native_extension="e" * 64, - ) - new_environment = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision=descendant, - active_runtime=relinked_runtime, - ) - - def fake_refresh( - _repo: Path, - _profile: str, - *, - expected_source_revision: str, - runtime_auditor: object, - _skip_workspace_validation: bool, - ) -> dict[str, str]: - assert expected_source_revision == descendant - assert _skip_workspace_validation is True - del runtime_auditor - with store.named_lock("measurement-lineage", timeout=0.0): - pass - (profile / "report_environment.json").write_text( - json.dumps(new_environment, sort_keys=True) + "\n", - encoding="ascii", - ) - (profile / "report_environment.tex").write_text( - _environment_tex(new_environment), - encoding="utf-8", - ) - return new_environment - - monkeypatch.setattr( - "tools.performance_report.workspace.refresh_profile_environment", - fake_refresh, - ) - finalized = finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: relinked_runtime, - ) - - assert finalized["state"] == "finalized" - assert ( - finalized["ancestor_environment"]["native_extension_sha256"] - != finalized["descendant_environment"]["native_extension_sha256"] - ) - assert "native_extension_sha256" not in finalized["runtime_invariant_fields"] - assert (profile / MEASUREMENT_LINEAGE_FILENAME).is_file() - lineage = load_measurement_lineage( - repo, - profile, - expected_active_revision=descendant, - expected_active_tree=_git(repo, "rev-parse", "HEAD^{tree}"), - ) - assert lineage is not None - retained = store.recover_current_records()[0] - assert lineage.source_for_current( - retained, - active_revision=descendant, - active_tree=_git(repo, "rev-parse", "HEAD^{tree}"), - ) == (ancestor, _git(repo, "rev-parse", f"{ancestor}^{{tree}}")) - assert audit_measurement_lineage( - repo, - profile, - store, - expected_active_source_revision=descendant, - )["runtime_invariants_match"] is True - - -def test_class_c_bridge_rejects_changed_native_build_inputs( - tmp_path: Path, -) -> None: - repo, profile, store, ancestor = _repository(tmp_path) - descendant = _git(repo, "rev-parse", "HEAD") - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - pending = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - - with pytest.raises( - MeasurementLineageError, - match="dependency/native/host runtime identity", - ): - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - "d" * 64, - source_revision=_revision, - native_build_inputs="f" * 64, - ), - ) - - -def test_class_c_bridge_rejects_disallowed_source_change(tmp_path: Path) -> None: - repo, profile, store, ancestor = _repository(tmp_path) - _write(repo, "dependencies/lock.toml", "changed = true\n") - _git(repo, "add", "dependencies/lock.toml") - _git(repo, "commit", "-q", "-m", "disallowed") - - with pytest.raises(MeasurementLineageError, match="disallowed path"): - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=_git(repo, "rev-parse", "HEAD"), - impact=CLASS_C_HZZ_IMPACT, - ) - - -def test_lineage_envelope_tampering_fails_closed( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor = _repository(tmp_path) - descendant = _git(repo, "rev-parse", "HEAD") - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - pending = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - new_environment = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision=descendant, - active_runtime=_runtime("d" * 64, source_revision=descendant), - ) - - def fake_refresh(*_args: object, **_kwargs: object) -> dict[str, str]: - (profile / "report_environment.json").write_text( - json.dumps(new_environment, sort_keys=True) + "\n", - encoding="ascii", - ) - (profile / "report_environment.tex").write_text( - _environment_tex(new_environment), - encoding="utf-8", - ) - return new_environment - - monkeypatch.setattr( - "tools.performance_report.workspace.refresh_profile_environment", - fake_refresh, - ) - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - "d" * 64, - source_revision=_revision, - ), - ) - lineage_path = profile / MEASUREMENT_LINEAGE_FILENAME - raw = json.loads(lineage_path.read_text(encoding="ascii")) - raw["payload"]["retained_currents"][0]["manifest_sha256"] = "0" * 64 - lineage_path.write_text(json.dumps(raw) + "\n", encoding="ascii") - - with pytest.raises(MeasurementLineageError, match="canonical digest"): - load_measurement_lineage( - repo, - profile, - expected_active_revision=descendant, - expected_active_tree=_git(repo, "rev-parse", "HEAD^{tree}"), - ) diff --git a/pyamplicol/tests/unit/test_performance_report_measurement_lineage_adversarial.py b/pyamplicol/tests/unit/test_performance_report_measurement_lineage_adversarial.py deleted file mode 100644 index 69a653dfe3..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_measurement_lineage_adversarial.py +++ /dev/null @@ -1,1470 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import subprocess -from pathlib import Path - -import pytest - -import tools.performance_report.measurement_lineage as measurement_lineage -from tools.performance_report.artifacts import ( - ArtifactPolicy, - ArtifactStore, - ArtifactStoreError, -) -from tools.performance_report.cache import digest_json, empty_measurement -from tools.performance_report.campaign_policy import MACBOOK_M3_POLICY -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.measurement_lineage import ( - _RECURRENCE_SUMMARY_CAP_ALLOWED_PATHS, - CLASS_C_HZZ_IMPACT, - CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - MEASUREMENT_LINEAGE_FILENAME, - MeasurementLineageError, - _agreement_graph_digest_matches, - _is_authorized_native_inputs_transition, - _require_environment_transition, - _resolve_recurrence_artifact_owner, - class_c_pending_path, - finalize_class_c_bridge, - hzz_agreement_closure, - hzz_impacted_cells, - load_measurement_lineage, - prepare_class_c_bridge, - recurrence_summary_cap_agreement_closure, - recurrence_summary_cap_impacted_cells, - signed_zero_helicity_agreement_closure, - signed_zero_helicity_impacted_cells, -) -from tools.performance_report.models import ExecutionMode, ModelKey -from tools.performance_report.scheduler import CampaignScheduler, CampaignSettings -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.workspace import ( - ReportWorkspaceError, - _authenticated_environment_payload, - _environment_tex, - initialize_profile, -) - - -def _git(repo: Path, *arguments: str) -> str: - return subprocess.run( - ("git", *arguments), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - -def _write(repo: Path, relative: str, value: str | bytes) -> None: - path = repo / relative - path.parent.mkdir(parents=True, exist_ok=True) - if isinstance(value, bytes): - path.write_bytes(value) - else: - path.write_text(value, encoding="utf-8") - - -def _lineage_digest(value: object) -> str: - encoded = json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - return hashlib.sha256(f"{encoded}\n".encode("ascii")).hexdigest() - - -def _runtime( - package_tree: str, - *, - source_revision: str = "e" * 40, - fingerprint: str = "candidate-fixture", - native_build_inputs: str = "a" * 64, -) -> dict: - return { - "package_version": "0.1.0", - "native_build_inputs_sha256": native_build_inputs, - "native_extension": {"sha256": "b" * 64}, - "python_package_tree": {"sha256": package_tree}, - "candidate_build_identity": { - "candidate_fingerprint": fingerprint, - "source_revision": source_revision, - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": ["neon"], - }, - } - - -def _validation_failed_result( - ancestor: str, - ancestor_tree: str, - artifact_root: Path, - *, - failure_kind: str = "MeasurementValidationError", -) -> dict[str, object]: - observations = [{"module": "fixture", "origin": "authenticated"}] - origin_policy = { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": len(observations), - "observations": observations, - "observations_sha256": digest_json(observations), - } - identity = {"loaded_module_origin_policy": origin_policy} - identity_sha256 = digest_json(identity) - stable_policy = { - key: value - for key, value in origin_policy.items() - if key - not in { - "observed_module_count", - "observations", - "observations_sha256", - } - } - stable_identity_sha256 = digest_json({"loaded_module_origin_policy": stable_policy}) - measurement = empty_measurement() - measurement.update( - { - "status": "validation_failed", - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0, - "execution_seconds_per_point": 1.0, - "matrix_element": 4.0, - "sample_count": 1, - "standard_error_seconds_per_point": 0.1, - "relative_standard_error": 0.1, - "artifact": { - "path": str(artifact_root), - "process_id": "fixture-process", - "policy": "generated", - }, - "validation": { - "status": "validation_failed", - "resolved_sum": { - "status": "ok", - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - }, - "pointwise": { - "status": "validation_failed", - "candidate": 4.0, - "baseline": 1.0, - "absolute_difference": 3.0, - "relative_difference": 3.0, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - }, - "direct_agreements": [], - }, - "provenance": { - "report_source_revision": ancestor, - "report_source_tree": ancestor_tree, - "report_measured_source_revision": ancestor, - "report_measured_source_tree": ancestor_tree, - "runtime_identity": identity, - "runtime_identity_sha256": identity_sha256, - "runtime_identity_stable_sha256": stable_identity_sha256, - "runtime_identity_postflight_stable_sha256": (stable_identity_sha256), - "runtime_identity_postflight_loaded_module_origin_policy": ( - origin_policy - ), - "runtime_identity_postflight_match": True, - }, - "failure": { - "kind": failure_kind, - "message": "candidate or same-artifact numerical validation failed", - }, - } - ) - return measurement - - -_SUMMARY_CAP_FAILURE_BYTES = { - "matrix-recurrence-builtin-sm-lc-n7-gg-gluons-selected-flow": 4_270_140, - "matrix-recurrence-builtin-sm-lc-n8-dd-tt-jets-selected-flow": 1_083_926, - "matrix-recurrence-builtin-sm-lc-n9-dd-z-jets-selected-flow": 4_449_888, - "matrix-recurrence-builtin-sm-lc-n9-ud-w-jets-selected-flow": 4_449_912, -} -_SUMMARY_CAP_DIFF_PATHS = tuple( - sorted(_RECURRENCE_SUMMARY_CAP_ALLOWED_PATHS) -) - - -def _summary_cap_failure(summary_bytes: int) -> dict[str, object]: - measurement = empty_measurement() - measurement.update( - { - "status": "error", - "failure": { - "kind": "GenerationError", - "message": ( - "Rust recurrence execution summary must be smaller than " - f"1 MiB; received {summary_bytes} bytes" - ), - }, - } - ) - return measurement - - -def _summary_cap_repository( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> tuple[Path, Path, ArtifactStore, str, str]: - repo, profile, store, predecessor_ancestor, ancestor = _repository(tmp_path) - monkeypatch.setattr( - "tools.performance_report.measurement_lineage." - "_RECURRENCE_SUMMARY_CAP_PREDECESSOR_REVISION", - predecessor_ancestor, - ) - monkeypatch.setattr( - "tools.performance_report.measurement_lineage." - "_RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION", - ancestor, - ) - monkeypatch.setattr( - "tools.performance_report.measurement_lineage." - "_RECURRENCE_SUMMARY_CAP_PROFILE", - profile.name, - ) - predecessor_pending = _prepare( - repo, - profile, - store, - predecessor_ancestor, - ancestor, - ) - _finalize( - monkeypatch, - repo, - profile, - store, - ancestor, - predecessor_pending, - ) - ancestor_tree = _git(repo, "rev-parse", "HEAD^{tree}") - retained = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and store.load_current(cell.cell_id, missing_ok=True) is None - ) - store.new_attempt(retained.cell_id, ArtifactPolicy.REGENERATE).publish( - { - "status": "ok", - "provenance": { - "report_source_revision": ancestor, - "report_source_tree": ancestor_tree, - "report_measured_source_revision": ancestor, - "report_measured_source_tree": ancestor_tree, - }, - } - ) - closure_current_id = ( - "matrix-recurrence-builtin-sm-lc-n7-gg-gluons-all-flow" - ) - store.new_attempt( - closure_current_id, - ArtifactPolicy.REGENERATE, - ).publish( - { - "status": "ok", - "provenance": { - "report_source_revision": ancestor, - "report_source_tree": ancestor_tree, - "report_measured_source_revision": ancestor, - "report_measured_source_tree": ancestor_tree, - }, - } - ) - for cell_id, summary_bytes in sorted(_SUMMARY_CAP_FAILURE_BYTES.items()): - store.new_attempt(cell_id, ArtifactPolicy.REGENERATE).publish( - _summary_cap_failure(summary_bytes) - ) - excluded = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.cell_id not in _SUMMARY_CAP_FAILURE_BYTES - and cell.cell_id != closure_current_id - ) - store.new_attempt(excluded.cell_id, ArtifactPolicy.REGENERATE).publish( - _summary_cap_failure(99) - ) - for path in _SUMMARY_CAP_DIFF_PATHS: - _write(repo, path, "DESCENDANT = 2\n") - _git(repo, "add", *_SUMMARY_CAP_DIFF_PATHS) - _git(repo, "commit", "-q", "-m", "descendant") - descendant = _git(repo, "rev-parse", "HEAD") - monkeypatch.setattr( - "tools.performance_report.measurement_lineage." - "_RECURRENCE_SUMMARY_CAP_DESCENDANT_REVISION", - descendant, - ) - monkeypatch.setattr( - "tools.performance_report.measurement_lineage." - "_RECURRENCE_SUMMARY_CAP_ANCESTOR_NATIVE_INPUTS_SHA256", - "a" * 64, - ) - monkeypatch.setattr( - "tools.performance_report.measurement_lineage." - "_RECURRENCE_SUMMARY_CAP_DESCENDANT_NATIVE_INPUTS_SHA256", - "d" * 64, - ) - return repo, profile, store, ancestor, descendant - - -def _repository(tmp_path: Path) -> tuple[Path, Path, ArtifactStore, str, str]: - repo = tmp_path / "repo" - repo.mkdir() - _git(repo, "init", "-q") - _git(repo, "config", "user.email", "lineage@example.invalid") - _git(repo, "config", "user.name", "Lineage Test") - profile = repo / "docs/performance_reports/macbook_M3" - _write( - repo, - "docs/performance_reports/macbook_M3/report-workspace.json", - json.dumps({"campaign_policy": {"name": "fixture"}}) + "\n", - ) - _write(repo, "src/pyamplicol/models/builtin/lowering.py", "VALUE = 1\n") - feature_paths = ( - "tests/unit/test_model_builtin.py", - "tests/unit/test_packaged_prepared_model.py", - "tests/unit/test_recurrence_catalog_builder.py", - ) - for path in feature_paths: - _write(repo, path, "VALUE = 1\n") - for root in ( - "src/pyamplicol/assets/prepared_models", - "release_assets/prepared_models", - ): - for architecture in ("aarch64", "x86_64"): - stem = f"built-in-sm-jit-o2-{architecture}" - _write(repo, f"{root}/{stem}.pyamplicol-model", b"old bundle\n") - _write(repo, f"{root}/{stem}.metadata.json", '{"old":true}\n') - _git(repo, "add", ".") - _git(repo, "commit", "-q", "-m", "ancestor") - ancestor = _git(repo, "rev-parse", "HEAD") - environment = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision=ancestor, - active_runtime=_runtime("c" * 64, source_revision=ancestor), - ) - _write( - repo, - "docs/performance_reports/macbook_M3/report_environment.json", - json.dumps(environment, sort_keys=True) + "\n", - ) - store = ArtifactStore( - artifact_root=repo / ".artifacts/performance-report/macbook_M3", - lock_root=repo / ".artifacts/performance-report-coordination/macbook_M3", - ) - retained = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - ancestor_tree = _git(repo, "rev-parse", "HEAD^{tree}") - store.new_attempt(retained.cell_id, ArtifactPolicy.REGENERATE).publish( - { - "status": "ok", - "provenance": { - "report_source_revision": ancestor, - "report_source_tree": ancestor_tree, - "report_measured_source_revision": ancestor, - "report_measured_source_tree": ancestor_tree, - }, - } - ) - _write(repo, "src/pyamplicol/models/builtin/lowering.py", "VALUE = 2\n") - for path in feature_paths: - _write(repo, path, "VALUE = 2\n") - for root in ( - "src/pyamplicol/assets/prepared_models", - "release_assets/prepared_models", - ): - for architecture in ("aarch64", "x86_64"): - stem = f"built-in-sm-jit-o2-{architecture}" - _write(repo, f"{root}/{stem}.pyamplicol-model", b"new bundle\n") - _write(repo, f"{root}/{stem}.metadata.json", '{"new":true}\n') - _git(repo, "add", "src/pyamplicol/models/builtin/lowering.py") - _git(repo, "add", "src/pyamplicol/assets/prepared_models") - _git(repo, "add", "release_assets/prepared_models") - for path in feature_paths: - _git(repo, "add", path) - _git(repo, "commit", "-q", "-m", "descendant") - return repo, profile, store, ancestor, _git(repo, "rev-parse", "HEAD") - - -def _prepare( - repo: Path, - profile: Path, - store: ArtifactStore, - ancestor: str, - descendant: str, -) -> Path: - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - return class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - - -def _finalize( - monkeypatch: pytest.MonkeyPatch, - repo: Path, - profile: Path, - store: ArtifactStore, - descendant: str, - pending: Path, - *, - package_tree: str = "d" * 64, - native_build_inputs: str = "a" * 64, -) -> None: - environment = _authenticated_environment_payload( - profile.name, - expected_source_revision=descendant, - active_runtime=_runtime( - package_tree, - source_revision=descendant, - native_build_inputs=native_build_inputs, - ), - ) - - def fake_refresh(*_args: object, **_kwargs: object) -> dict[str, str]: - (profile / "report_environment.json").write_text( - json.dumps(environment, sort_keys=True) + "\n", - encoding="ascii", - ) - (profile / "report_environment.tex").write_text( - _environment_tex(environment), - encoding="utf-8", - ) - return environment - - monkeypatch.setattr( - "tools.performance_report.workspace.refresh_profile_environment", - fake_refresh, - ) - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - package_tree, - source_revision=_revision, - native_build_inputs=native_build_inputs, - ), - ) - - -def test_recurrence_summary_cap_native_transition_is_exactly_pinned() -> None: - ancestor_revision = "be11d8304fdc04893dc0e23e9619be848126e3bc" - descendant_revision = "2594d8b520b802f71d60bd646f73ebaa5547927a" - ancestor_digest = ( - "23b9637d5d3fba0947d78cf688df18799b0c9ee5b3bcbfa6a2963a1f1a21f870" - ) - descendant_digest = ( - "96e1ff79a007aaf67a0900dd6d67327ee00f6bd2cca002589b879aa3a734de08" - ) - ancestor_environment = _authenticated_environment_payload( - "x86_EPYC", - expected_source_revision=ancestor_revision, - active_runtime=_runtime( - "c" * 64, - source_revision=ancestor_revision, - native_build_inputs=ancestor_digest, - ), - ) - descendant_environment = _authenticated_environment_payload( - "x86_EPYC", - expected_source_revision=descendant_revision, - active_runtime=_runtime( - "d" * 64, - source_revision=descendant_revision, - native_build_inputs=descendant_digest, - ), - ) - - _require_environment_transition( - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ancestor_revision=ancestor_revision, - descendant_revision=descendant_revision, - ancestor_environment=ancestor_environment, - descendant_environment=descendant_environment, - ) - assert _is_authorized_native_inputs_transition( - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ancestor_revision=ancestor_revision, - descendant_revision=descendant_revision, - ancestor_digest=ancestor_digest, - descendant_digest=descendant_digest, - ) - - for ( - changed_ancestor, - changed_descendant, - changed_ancestor_environment, - changed_descendant_environment, - ) in ( - ( - "0" * 40, - descendant_revision, - ancestor_environment, - descendant_environment, - ), - ( - ancestor_revision, - "1" * 40, - ancestor_environment, - descendant_environment, - ), - ( - ancestor_revision, - descendant_revision, - { - **ancestor_environment, - "native_build_inputs_sha256": "2" * 64, - }, - descendant_environment, - ), - ( - ancestor_revision, - descendant_revision, - ancestor_environment, - { - **descendant_environment, - "native_build_inputs_sha256": ancestor_digest, - }, - ), - ( - ancestor_revision, - descendant_revision, - { - **ancestor_environment, - "native_build_inputs_sha256": descendant_digest, - }, - { - **descendant_environment, - "native_build_inputs_sha256": ancestor_digest, - }, - ), - ( - ancestor_revision, - descendant_revision, - ancestor_environment, - { - **descendant_environment, - "candidate_fingerprint": "unreviewed-native-drift", - }, - ), - ): - with pytest.raises( - MeasurementLineageError, - match="exact recurrence-summary-cap transition", - ): - _require_environment_transition( - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ancestor_revision=changed_ancestor, - descendant_revision=changed_descendant, - ancestor_environment=changed_ancestor_environment, - descendant_environment=changed_descendant_environment, - ) - - with pytest.raises( - MeasurementLineageError, - match="dependency/native/host runtime identity", - ): - _require_environment_transition( - impact=CLASS_C_HZZ_IMPACT, - ancestor_revision=ancestor_revision, - descendant_revision=descendant_revision, - ancestor_environment=ancestor_environment, - descendant_environment=descendant_environment, - ) - - -def test_controller_agreement_transition_is_exactly_lineage_scoped( - monkeypatch: pytest.MonkeyPatch, -) -> None: - old_digest = "7" * 64 - new_digest = "4" * 64 - monkeypatch.setattr( - measurement_lineage, - "_PRE_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256", - old_digest, - ) - monkeypatch.setattr( - measurement_lineage, - "_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256", - new_digest, - ) - exact = { - "profile": "x86_EPYC", - "impact": CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - "ancestor_revision": ( - measurement_lineage._RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION - ), - "descendant_revision": ( - measurement_lineage._RECURRENCE_SUMMARY_CAP_DESCENDANT_REVISION - ), - "agreement_graph_sha256": old_digest, - } - - assert _agreement_graph_digest_matches(exact, old_digest) - assert _agreement_graph_digest_matches(exact, new_digest) - for changed in ( - {**exact, "profile": "macbook_M3"}, - {**exact, "impact": CLASS_C_HZZ_IMPACT}, - {**exact, "ancestor_revision": "0" * 40}, - {**exact, "descendant_revision": "1" * 40}, - {**exact, "agreement_graph_sha256": "2" * 64}, - ): - assert not _agreement_graph_digest_matches(changed, new_digest) - assert not _agreement_graph_digest_matches(exact, "3" * 64) - - -def test_recurrence_summary_cap_bridge_has_exact_failure_and_closure_census( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor, descendant = _summary_cap_repository( - tmp_path, - monkeypatch, - ) - prepared = prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ) - - impacted_ids = { - cell.cell_id for cell in recurrence_summary_cap_impacted_cells() - } - closure_ids = { - cell.cell_id for cell in recurrence_summary_cap_agreement_closure() - } - signed_zero_ids = { - cell.cell_id for cell in signed_zero_helicity_impacted_cells() - } - signed_zero_closure_ids = { - cell.cell_id for cell in signed_zero_helicity_agreement_closure() - } - certificate = prepared["reachability_certificate"] - assert isinstance(certificate, dict) - assert impacted_ids == set(_SUMMARY_CAP_FAILURE_BYTES) - assert len(closure_ids) == 12 - assert not impacted_ids & closure_ids - assert len(signed_zero_ids) == 24 - assert len(signed_zero_closure_ids) == 42 - assert not (impacted_ids | closure_ids) & ( - signed_zero_ids | signed_zero_closure_ids - ) - assert { - str(cell["cell_id"]) for cell in prepared["impacted_cells"] - } == impacted_ids | signed_zero_ids - assert { - str(cell["cell_id"]) - for cell in prepared["agreement_closure_cells"] - } == closure_ids | signed_zero_closure_ids - assert certificate["target_summary_bytes"] == _SUMMARY_CAP_FAILURE_BYTES - assert certificate["inspected_current_count"] == 8 - assert certificate["successful_current_count"] == 3 - assert certificate["excluded_non_success_current_count"] == 1 - assert len(certificate["predecessor"]["retained_currents"]) == 1 - assert { - str(record["cell_id"]) for record in certificate["records"] - } == impacted_ids - assert { - str(pin["cell_id"]) for pin in prepared["invalidated_currents"] - } == impacted_ids - assert len(prepared["retained_currents"]) == 2 - assert [ - pin["cell_id"] for pin in prepared["recompare_currents"] - ] == ["matrix-recurrence-builtin-sm-lc-n7-gg-gluons-all-flow"] - - pending = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - historical_graph = measurement_lineage._agreement_digest(REPORT_CATALOG) - current_graph = "4" * 64 - monkeypatch.setattr( - measurement_lineage, - "_PRE_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256", - historical_graph, - ) - monkeypatch.setattr( - measurement_lineage, - "_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256", - current_graph, - ) - monkeypatch.setattr( - measurement_lineage, - "_agreement_digest", - lambda _catalog: current_graph, - ) - _finalize( - monkeypatch, - repo, - profile, - store, - descendant, - pending, - package_tree="e" * 64, - native_build_inputs="d" * 64, - ) - lineage = load_measurement_lineage( - repo, - profile, - expected_active_revision=descendant, - expected_active_tree=_git(repo, "rev-parse", "HEAD^{tree}"), - ) - assert lineage is not None - assert lineage.required_descendant_cell_ids == ( - impacted_ids - | closure_ids - | signed_zero_ids - | signed_zero_closure_ids - ) - - -def test_recurrence_summary_cap_bridge_rejects_wrong_failure_byte_count( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor, descendant = _summary_cap_repository( - tmp_path, - monkeypatch, - ) - cell_id, summary_bytes = next(iter(_SUMMARY_CAP_FAILURE_BYTES.items())) - store.new_attempt(cell_id, ArtifactPolicy.REGENERATE).publish( - _summary_cap_failure(summary_bytes + 1) - ) - - with pytest.raises( - MeasurementLineageError, - match="not the authenticated recurrence summary-cap GenerationError", - ): - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ) - - -def test_recurrence_summary_cap_bridge_rejects_excluded_current_pointer_change( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor, descendant = _summary_cap_repository( - tmp_path, - monkeypatch, - ) - prepared = prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ) - certificate = prepared["reachability_certificate"] - assert isinstance(certificate, dict) - excluded = certificate["excluded_non_success_currents"] - assert isinstance(excluded, list) - assert len(excluded) == 1 - cell_id = str(excluded[0]["cell_id"]) - store.new_attempt(cell_id, ArtifactPolicy.REGENERATE).publish( - _summary_cap_failure(100) - ) - pending = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - with pytest.raises( - MeasurementLineageError, - match="certificate changed", - ): - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - "e" * 64, - source_revision=_revision, - ), - ) - - -def test_required_descendant_closure_is_exact_even_without_currents( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - pending = _prepare(repo, profile, store, ancestor, descendant) - _finalize(monkeypatch, repo, profile, store, descendant, pending) - lineage = load_measurement_lineage( - repo, - profile, - expected_active_revision=descendant, - expected_active_tree=_git(repo, "rev-parse", "HEAD^{tree}"), - ) - - assert lineage is not None - expected = { - cell.cell_id for cell in (*hzz_impacted_cells(), *hzz_agreement_closure()) - } - current_ids = {record.cell_id for record in store.recover_current_records()} - assert len(expected) == 40 - assert lineage.required_descendant_cell_ids == expected - assert not (expected & current_ids) - - -def test_prepare_partitions_exact_epyc_validation_failures_for_replacement( - tmp_path: Path, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - ancestor_tree = _git(repo, "rev-parse", f"{ancestor}^{{tree}}") - failed_ids = { - "matrix-recurrence-builtin-sm-full-n3-dd-zzz-jets-contracted", - "matrix-recurrence-builtin-sm-lc-n3-dd-zzz-jets-selected-flow", - } - for cell_id in sorted(failed_ids): - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json("artifact/execution.json", {"fixture": True}) - attempt.publish( - _validation_failed_result( - ancestor, - ancestor_tree, - attempt.root / "artifact", - ), - artifact_paths=("artifact/execution.json",), - ) - - prepared = prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - - reachability = prepared["reachability_certificate"] - assert isinstance(reachability, dict) - assert set(reachability["invalidated_validation_failed_current_ids"]) == failed_ids - assert failed_ids == { - str(pin["cell_id"]) for pin in prepared["invalidated_currents"] - } - assert not failed_ids & { - str(pin["cell_id"]) for pin in prepared["retained_currents"] - } - - -def test_prepare_rejects_validation_failure_outside_hzz_closure( - tmp_path: Path, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - ancestor_tree = _git(repo, "rev-parse", f"{ancestor}^{{tree}}") - outside = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - and cell.process_key != "dd_zzz_jets" - ) - attempt = store.new_attempt(outside.cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json("artifact/execution.json", {"fixture": True}) - attempt.publish( - _validation_failed_result( - ancestor, - ancestor_tree, - attempt.root / "artifact", - ), - artifact_paths=("artifact/execution.json",), - ) - - with pytest.raises( - MeasurementLineageError, - match="outside the exact HZZ replacement closure", - ): - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - - -def test_prepare_rejects_wrong_failure_class_inside_hzz_closure( - tmp_path: Path, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - ancestor_tree = _git(repo, "rev-parse", f"{ancestor}^{{tree}}") - cell_id = "matrix-recurrence-builtin-sm-full-n3-dd-zzz-jets-contracted" - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json("artifact/execution.json", {"fixture": True}) - attempt.publish( - _validation_failed_result( - ancestor, - ancestor_tree, - attempt.root / "artifact", - failure_kind="UnexpectedFailure", - ), - artifact_paths=("artifact/execution.json",), - ) - - with pytest.raises( - MeasurementLineageError, - match="not an authenticated numerical-validation failure", - ): - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - - -def test_prepare_rejects_in_closure_failure_runtime_digest_tamper( - tmp_path: Path, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - ancestor_tree = _git(repo, "rev-parse", f"{ancestor}^{{tree}}") - cell_id = "matrix-recurrence-builtin-sm-full-n3-dd-zzz-jets-contracted" - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json("artifact/execution.json", {"fixture": True}) - result = _validation_failed_result( - ancestor, - ancestor_tree, - attempt.root / "artifact", - ) - provenance = result["provenance"] - assert isinstance(provenance, dict) - provenance["runtime_identity_sha256"] = "0" * 64 - attempt.publish(result, artifact_paths=("artifact/execution.json",)) - - with pytest.raises( - MeasurementLineageError, - match="runtime identity is invalid", - ): - prepare_class_c_bridge( - repo, - profile, - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - impact=CLASS_C_HZZ_IMPACT, - ) - - -def test_lineage_rejects_failed_pin_moved_into_retained_group( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - ancestor_tree = _git(repo, "rev-parse", f"{ancestor}^{{tree}}") - cell_id = "matrix-recurrence-builtin-sm-full-n3-dd-zzz-jets-contracted" - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json("artifact/execution.json", {"fixture": True}) - attempt.publish( - _validation_failed_result( - ancestor, - ancestor_tree, - attempt.root / "artifact", - ), - artifact_paths=("artifact/execution.json",), - ) - pending = _prepare(repo, profile, store, ancestor, descendant) - _finalize(monkeypatch, repo, profile, store, descendant, pending) - - lineage_path = profile / MEASUREMENT_LINEAGE_FILENAME - raw = json.loads(lineage_path.read_text(encoding="ascii")) - payload = raw["payload"] - failed_pin = next( - pin for pin in payload["invalidated_currents"] if pin["cell_id"] == cell_id - ) - payload["invalidated_currents"].remove(failed_pin) - payload["retained_currents"].append(failed_pin) - payload["retained_currents"].sort(key=lambda pin: pin["cell_id"]) - snapshot = { - field: payload[field] - for field in ( - "retained_currents", - "invalidated_currents", - "recompare_currents", - "attempt_inventory", - "no_attempt_cells", - ) - } - payload["current_snapshot_sha256"] = _lineage_digest(snapshot) - raw["payload_sha256"] = _lineage_digest(payload) - lineage_path.write_text( - json.dumps( - raw, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n", - encoding="ascii", - ) - - with pytest.raises( - MeasurementLineageError, - match="current groups do not match", - ): - load_measurement_lineage( - repo, - profile, - expected_active_revision=descendant, - expected_active_tree=_git(repo, "rev-parse", "HEAD^{tree}"), - ) - - -def test_attempt_artifact_byte_tamper_blocks_finalization(tmp_path: Path) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - pending = _prepare(repo, profile, store, ancestor, descendant) - result_path = store.recover_current_records()[0].result_path - result_path.write_bytes(result_path.read_bytes() + b" ") - - with pytest.raises( - ArtifactStoreError, - match=r"artifact (size|digest) mismatch", - ): - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - "d" * 64, - source_revision=_revision, - ), - ) - assert not (profile / MEASUREMENT_LINEAGE_FILENAME).exists() - - -def test_new_orphan_attempt_blocks_finalization(tmp_path: Path) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - pending = _prepare(repo, profile, store, ancestor, descendant) - no_current = hzz_impacted_cells()[0] - store.new_attempt( - no_current.cell_id, - ArtifactPolicy.REGENERATE, - ).mark_failed("new orphan attempt") - - with pytest.raises( - MeasurementLineageError, - match="current or attempt state changed", - ): - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - "d" * 64, - source_revision=_revision, - ), - ) - assert not (profile / MEASUREMENT_LINEAGE_FILENAME).exists() - - -def test_failed_refresh_rolls_back_environment_and_lineage_bytes( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo, profile, store, ancestor, descendant = _repository(tmp_path) - pending = _prepare(repo, profile, store, ancestor, descendant) - json_path = profile / "report_environment.json" - tex_path = profile / "report_environment.tex" - lineage_path = profile / MEASUREMENT_LINEAGE_FILENAME - tex_path.write_bytes(b"exact ancestor tex bytes\n") - lineage_path.write_bytes(b"exact prior lineage bytes\n") - before = {path: path.read_bytes() for path in (json_path, tex_path, lineage_path)} - expected = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision=descendant, - active_runtime=_runtime("d" * 64, source_revision=descendant), - ) - - def corrupting_refresh(*_args: object, **_kwargs: object) -> dict[str, str]: - json_path.write_bytes(b"corrupt environment\n") - tex_path.write_bytes(b"corrupt tex\n") - lineage_path.write_bytes(b"corrupt lineage\n") - returned = dict(expected) - returned["candidate_fingerprint"] = "mutated-after-authentication" - return returned - - monkeypatch.setattr( - "tools.performance_report.workspace.refresh_profile_environment", - corrupting_refresh, - ) - with pytest.raises( - MeasurementLineageError, - match="written descendant environment differs", - ): - finalize_class_c_bridge( - repo, - profile, - store, - pending_path=pending, - expected_active_source_revision=descendant, - runtime_auditor=lambda _revision, _root: _runtime( - "d" * 64, - source_revision=_revision, - ), - ) - - assert {path: path.read_bytes() for path in before} == before - - -def test_environment_projects_only_candidate_fingerprint() -> None: - first = _runtime("d" * 64) - second = _runtime("d" * 64) - first["candidate_build_identity"]["host_checkout"] = "/private/host/one" - first["candidate_build_identity"]["nested"] = {"digest": "1" * 64} - second["candidate_build_identity"]["host_checkout"] = "/other/host/two" - second["candidate_build_identity"]["nested"] = {"digest": "2" * 64} - - left = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision="e" * 40, - active_runtime=first, - ) - right = _authenticated_environment_payload( - "macbook_M3", - expected_source_revision="e" * 40, - active_runtime=second, - ) - - assert left == right - assert left["candidate_fingerprint"] == "candidate-fixture" - assert "/private/host" not in json.dumps(left) - - -def test_non_reset_profile_clone_rejects_source_lineage(tmp_path: Path) -> None: - repo, profile, _store, _ancestor, _descendant = _repository(tmp_path) - (profile / MEASUREMENT_LINEAGE_FILENAME).write_text("{}\n", encoding="ascii") - - with pytest.raises( - ReportWorkspaceError, - match=r"mixed Class-C source lineage.*reset_measurements=True", - ): - initialize_profile( - repo, - "x86_EPYC", - source_profile="macbook_M3", - reset_measurements=False, - ) - assert not (repo / "docs/performance_reports/x86_EPYC").exists() - - -def test_scheduler_rejects_mixed_source_without_lineage_before_attempt( - tmp_path: Path, -) -> None: - repo, _profile, store, _ancestor, _descendant = _repository(tmp_path) - before = tuple(store.artifact_root.rglob("manifest.json")) - policy = MACBOOK_M3_POLICY - settings = CampaignSettings( - workers=policy.workers or 1, - cell_cores=policy.cell_cores or 1, - target_runtime_seconds=policy.target_runtime_seconds, - max_rss_bytes=policy.memory_limit_bytes, - campaign_policy=policy, - report_profile="macbook_M3", - ) - service = ReportService(ReportPaths.from_repo(repo, profile="macbook_M3")) - - with pytest.raises( - MeasurementLineageError, - match="mixed/ancestor measurements but no authenticated measurement lineage", - ): - CampaignScheduler(service, settings=settings) - - assert tuple(store.artifact_root.rglob("manifest.json")) == before - - -def _runtime_digest(value: object) -> str: - return hashlib.sha256( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _owner_provenance( - *, - observation_path: str, - revision: str = "a" * 40, - tree: str = "b" * 40, -) -> dict[str, object]: - observations = [{"path": observation_path}] - policy = { - "kind": "fixture-loaded-origin-policy", - "authenticated": True, - "observed_module_count": len(observations), - "observations": observations, - "observations_sha256": _runtime_digest(observations), - } - identity = { - "kind": "fixture-runtime-identity", - "artifact_id": "shared-artifact", - "loaded_module_origin_policy": policy, - } - stable_identity = dict(identity) - stable_policy = dict(policy) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - stable_policy.pop(field) - stable_identity["loaded_module_origin_policy"] = stable_policy - stable_digest = _runtime_digest(stable_identity) - return { - "report_source_revision": revision, - "report_source_tree": tree, - "report_measured_source_revision": revision, - "report_measured_source_tree": tree, - "runtime_identity": identity, - "runtime_identity_sha256": _runtime_digest(identity), - "runtime_identity_stable_sha256": stable_digest, - "runtime_identity_postflight_stable_sha256": stable_digest, - "runtime_identity_postflight_match": True, - } - - -def _owner_cells() -> tuple[object, object]: - consumer = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id.startswith("z_") - and cell.n_final == 1 - and cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - ) - owners = tuple( - cell - for cell in REPORT_CATALOG.equivalent_cells(consumer) - if cell.dataset_id.startswith("matrix_") - ) - assert len(owners) == 1 - return consumer, owners[0] - - -def _publish_owned_artifact( - store: ArtifactStore, - cell_id: str, - *, - observation_path: str, - payload: bytes = b"authenticated artifact payload\n", -) -> tuple[object, Path]: - attempt = store.new_attempt(cell_id, ArtifactPolicy.REGENERATE) - artifact_file = attempt.path("artifact/payload.bin") - artifact_file.write_bytes(payload) - artifact_root = artifact_file.parent - record = attempt.publish( - { - "status": "ok", - "artifact": { - "path": str(artifact_root), - "process_id": "fixture-process", - }, - "provenance": _owner_provenance( - observation_path=observation_path, - ), - }, - artifact_paths=("artifact/payload.bin",), - ) - return record, artifact_root.resolve(strict=True) - - -def _publish_artifact_consumer( - store: ArtifactStore, - cell_id: str, - artifact_root: Path, -) -> object: - return store.new_attempt( - cell_id, - ArtifactPolicy.REGENERATE, - ).publish( - { - "status": "ok", - "artifact": { - "path": str(artifact_root), - "process_id": "fixture-process", - }, - "provenance": _owner_provenance( - observation_path="/consumer/runtime.py", - ), - } - ) - - -def test_recurrence_reachability_accepts_exact_matrix_peer_artifact_owner( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "profile/artifacts", - lock_root=tmp_path / "profile/locks", - ) - consumer, owner_cell = _owner_cells() - owner, artifact_root = _publish_owned_artifact( - store, - owner_cell.cell_id, - observation_path="/owner/runtime.py", - ) - consumer_record = _publish_artifact_consumer( - store, - consumer.cell_id, - artifact_root, - ) - - evidence = _resolve_recurrence_artifact_owner( - store, - REPORT_CATALOG, - consumer_record, - consumer, - artifact_root, - "fixture-process", - ) - - assert evidence["relation"] == "equivalent-matrix-peer" - assert evidence["consumer_cell_id"] == consumer.cell_id - assert evidence["owner_cell_id"] == owner_cell.cell_id - assert evidence["owner_attempt_id"] == owner.attempt_id - assert evidence["owner_current_locator"].endswith("/current.json") - assert ( - evidence["consumer_runtime_identity_sha256"] - != (evidence["owner_runtime_identity_sha256"]) - ) - assert ( - evidence["consumer_runtime_identity_stable_sha256"] - == (evidence["owner_runtime_identity_stable_sha256"]) - ) - - -def test_recurrence_reachability_rejects_foreign_artifact_owner( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "profile/artifacts", - lock_root=tmp_path / "profile/locks", - ) - consumer, owner_cell = _owner_cells() - _publish_owned_artifact( - store, - owner_cell.cell_id, - observation_path="/owner/runtime.py", - ) - foreign_cell = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id.startswith("matrix_") - and cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - and cell.process_key != consumer.process_key - ) - _foreign, foreign_root = _publish_owned_artifact( - store, - foreign_cell.cell_id, - observation_path="/foreign/runtime.py", - ) - consumer_record = _publish_artifact_consumer( - store, - consumer.cell_id, - foreign_root, - ) - - with pytest.raises( - MeasurementLineageError, - match="not owned by its matrix peer", - ): - _resolve_recurrence_artifact_owner( - store, - REPORT_CATALOG, - consumer_record, - consumer, - foreign_root, - "fixture-process", - ) - - -def test_recurrence_reachability_rejects_owner_artifact_hash_drift( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "profile/artifacts", - lock_root=tmp_path / "profile/locks", - ) - consumer, owner_cell = _owner_cells() - _owner, artifact_root = _publish_owned_artifact( - store, - owner_cell.cell_id, - observation_path="/owner/runtime.py", - ) - consumer_record = _publish_artifact_consumer( - store, - consumer.cell_id, - artifact_root, - ) - (artifact_root / "payload.bin").write_bytes(b"altered after publication\n") - - with pytest.raises( - MeasurementLineageError, - match="owner current is invalid", - ): - _resolve_recurrence_artifact_owner( - store, - REPORT_CATALOG, - consumer_record, - consumer, - artifact_root, - "fixture-process", - ) diff --git a/pyamplicol/tests/unit/test_performance_report_phase_state.py b/pyamplicol/tests/unit/test_performance_report_phase_state.py deleted file mode 100644 index 3b72286b49..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_phase_state.py +++ /dev/null @@ -1,139 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from contextlib import contextmanager -from pathlib import Path - -import pytest - -from tools.performance_report.phase_state import ( - WorkerPhaseChannel, - WorkerPhaseReporter, - WorkerPhaseStateError, - read_worker_phase_state, -) - - -class NanosecondClock: - def __init__(self) -> None: - self.now = 1_000_000_000 - - def __call__(self) -> int: - return self.now - - -def test_reporter_publishes_authenticated_atomic_phase_boundaries( - tmp_path: Path, -) -> None: - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - clock = NanosecondClock() - reporter = WorkerPhaseReporter( - channel, - worker_pid=42, - clock_ns=clock, - track_post_generation_stages=True, - ) - - pre = read_worker_phase_state(channel, expected_pid=42) - assert (pre.sequence, pre.phase) == (0, "pre-generation") - assert pre.generation_elapsed_seconds(now_seconds=50.0) is None - - phase = reporter.generation() - clock.now = 2_000_000_000 - phase.__enter__() - active = read_worker_phase_state(channel, expected_pid=42) - assert (active.sequence, active.phase) == (1, "generation") - assert active.generation_elapsed_seconds(now_seconds=3.25) == 1.25 - - clock.now = 3_500_000_000 - phase.__exit__(None, None, None) - post = read_worker_phase_state(channel, expected_pid=42) - assert (post.sequence, post.phase) == (2, "post-generation") - assert post.generation_elapsed_seconds(now_seconds=500.0) == 1.5 - assert not list(tmp_path.glob("*.tmp")) - - clock.now = 4_000_000_000 - reporter.profiling_started() - profiling = read_worker_phase_state(channel, expected_pid=42) - assert (profiling.sequence, profiling.phase) == (3, "profiling") - assert profiling.generation_elapsed_seconds(now_seconds=500.0) == 1.5 - assert profiling.stage_elapsed_seconds("profiling", now_seconds=4.25) == 0.25 - assert profiling.stage_elapsed_seconds("validation", now_seconds=4.25) is None - - clock.now = 5_000_000_000 - reporter.validation_started() - validation = read_worker_phase_state(channel, expected_pid=42) - assert (validation.sequence, validation.phase) == (4, "validation") - assert validation.stage_elapsed_seconds("profiling", now_seconds=500.0) == 1.0 - assert validation.stage_elapsed_seconds("validation", now_seconds=5.5) == 0.5 - - clock.now = 6_000_000_000 - reporter.complete() - complete = read_worker_phase_state(channel, expected_pid=42) - assert (complete.sequence, complete.phase) == (5, "complete") - assert complete.stage_elapsed_seconds("profiling", now_seconds=500.0) == 1.0 - assert complete.stage_elapsed_seconds("validation", now_seconds=500.0) == 1.0 - - with ( - pytest.raises(WorkerPhaseStateError, match="exactly one"), - reporter.generation(), - ): - pass - - -def test_phase_state_rejects_tampering_wrong_pid_and_malformed_fields( - tmp_path: Path, -) -> None: - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - WorkerPhaseReporter(channel, worker_pid=42, clock_ns=lambda: 1) - - with pytest.raises(WorkerPhaseStateError, match="PID"): - read_worker_phase_state(channel, expected_pid=41) - - payload = json.loads(channel.path.read_text(encoding="ascii")) - payload["phase"] = "generation" - channel.path.write_text(json.dumps(payload), encoding="ascii") - with pytest.raises(WorkerPhaseStateError, match="authentication"): - read_worker_phase_state(channel, expected_pid=42) - - channel.path.write_text('{"abi":"incomplete"}\n', encoding="ascii") - with pytest.raises(WorkerPhaseStateError, match="fields"): - read_worker_phase_state(channel, expected_pid=42) - - -def test_generation_gate_is_released_before_profiling_and_validation( - tmp_path: Path, -) -> None: - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - events: list[str] = [] - - @contextmanager - def gate(): - events.append("gate-enter") - try: - yield - finally: - state = read_worker_phase_state(channel, expected_pid=42) - events.append(f"gate-exit-{state.phase}") - - reporter = WorkerPhaseReporter( - channel, - worker_pid=42, - clock_ns=lambda: 1, - track_post_generation_stages=True, - generation_gate=gate, - ) - with reporter.generation(): - events.append("generation") - reporter.profiling_started() - events.append("profiling") - reporter.validation_started() - reporter.complete() - - assert events == [ - "gate-enter", - "generation", - "gate-exit-post-generation", - "profiling", - ] diff --git a/pyamplicol/tests/unit/test_performance_report_phase_timeline.py b/pyamplicol/tests/unit/test_performance_report_phase_timeline.py deleted file mode 100644 index fdfc6bb916..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_phase_timeline.py +++ /dev/null @@ -1,143 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Phase-timeline evidence must remain direct, typed, and reusable.""" - -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.performance_report.phase_timeline import ( - PHASE_TIMELINE_SCHEMA, - build_phase_timeline, -) - - -def _rows(timeline: dict[str, object]) -> dict[str, dict[str, object]]: - entries = timeline["entries"] - assert isinstance(entries, list) - return {str(entry["key"]): entry for entry in entries if isinstance(entry, dict)} - - -def test_pyamplicol_timeline_keeps_only_direct_phase_clocks(tmp_path: Path) -> None: - progress = tmp_path / "worker-progress.jsonl" - events = ( - { - "event": "start", - "task_id": "generation:validation", - "parent_task_id": "generation", - "description": "Validating generated artifact", - }, - { - "event": "end", - "task_id": "generation:validation", - "success": True, - "elapsed_seconds": 0.125, - }, - ) - progress.write_text( - "".join(f"{json.dumps(event)}\n" for event in events), - encoding="utf-8", - ) - result = { - "status": "ok", - "generation_seconds": 4.5, - "validation": {"status": "ok"}, - "resources": { - "wall_seconds": 9.0, - "cpu_seconds": 7.0, - "peak_rss_bytes": 123, - "peak_guard_bytes": 456, - }, - "provenance": { - "model_preparation_seconds": 0.25, - "model_preparation_reused": False, - "runtime_profile": { - "warmup_elapsed_seconds": 0.5, - "calibration_outer_elapsed_seconds": 0.75, - "measurement_phase_elapsed_seconds": 2.0, - "achieved_runtime_seconds": 1.8, - "profile_attribution_elapsed_seconds": 1.0, - "profile_total_elapsed_seconds": 4.25, - "completed_sample_count": 12, - "calibration_block_count": 3, - }, - "manual_campaign": { - "cell_identity": {"execution_mode": "recurrence"}, - }, - }, - } - - timeline = build_phase_timeline(result, progress_path=progress) - rows = _rows(timeline) - - assert timeline["schema"] == PHASE_TIMELINE_SCHEMA - assert rows["generation"]["seconds"] == pytest.approx(4.5) - assert rows["generation-step:validation"]["seconds"] == pytest.approx(0.125) - assert rows["generation-step:validation"]["included_in"] == "generation" - assert rows["runtime-warmup"]["seconds"] == pytest.approx(0.5) - assert rows["runtime-calibration"]["detail"] == "3 blocks" - assert rows["runtime-measurement"]["seconds"] == pytest.approx(1.8) - assert rows["runtime-measurement"]["detail"] == "12 samples" - assert rows["runtime-attribution"]["seconds"] == pytest.approx(1.0) - assert rows["runtime-profile-total"]["seconds"] == pytest.approx(4.25) - assert rows["attempt-publication"]["seconds"] is None - assert "not separately timed" in str(rows["attempt-publication"]["detail"]) - assert timeline["total_worker_wall_seconds"] == pytest.approx(9.0) - assert timeline["peak_guard_bytes"] == 456 - - -def test_legacy_timeline_marks_calibration_not_applicable() -> None: - result = { - "status": "ok", - "generation_seconds": 2.0, - "validation": None, - "resources": {}, - "provenance": { - "runtime_profile": { - "warmup": {"elapsed_seconds": 0.2}, - "measurement": { - "achieved_runtime_seconds": 5.1, - "chunk_count": 8, - "chunks": [ - {"elapsed_seconds": 2.6}, - {"elapsed_seconds": 2.7}, - ], - }, - }, - "manual_campaign": { - "cell_identity": {"execution_mode": "amplicol"}, - }, - }, - } - - rows = _rows(build_phase_timeline(result)) - - assert rows["runtime-warmup"]["seconds"] == pytest.approx(0.2) - assert rows["runtime-calibration"]["status"] == "not_applicable" - assert rows["runtime-calibration"]["seconds"] is None - assert rows["runtime-measurement"]["seconds"] == pytest.approx(5.3) - assert rows["runtime-measurement"]["detail"] == "8 chunks" - - -def test_missing_phase_clocks_remain_unavailable() -> None: - result = { - "status": "ok", - "generation_seconds": 1.0, - "resources": {"wall_seconds": 10.0}, - "provenance": { - "runtime_profile": {"achieved_runtime_seconds": 3.0}, - "manual_campaign": { - "cell_identity": {"execution_mode": "compiled"}, - }, - }, - } - - rows = _rows(build_phase_timeline(result)) - - assert rows["runtime-warmup"]["seconds"] is None - assert rows["runtime-calibration"]["seconds"] is None - assert rows["runtime-attribution"]["seconds"] is None - assert rows["runtime-profile-total"]["seconds"] is None - assert rows["runtime-measurement"]["seconds"] == pytest.approx(3.0) diff --git a/pyamplicol/tests/unit/test_performance_report_policy.py b/pyamplicol/tests/unit/test_performance_report_policy.py deleted file mode 100644 index 6823bd7986..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_policy.py +++ /dev/null @@ -1,257 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from copy import deepcopy -from types import SimpleNamespace - -from tools.performance_report.arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - EMPTY_ARENA_PHASE_VECTOR_FIELDS, - ZERO_ARENA_COUNTER_FIELDS, - ZERO_ARENA_PHASE_TIME_FIELDS, - ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS, - build_arena_profile_evidence, - digest_arena_profile_value, -) -from tools.performance_report.cache import empty_measurement -from tools.performance_report.report_policy import ( - publication_measurement_policy_issues, - timing_policy_issues, -) -from tools.performance_report.runner import _benchmark_measurement -from tools.performance_report.source_identity import SOURCE_IDENTITY_SCHEMA - - -def _measurement() -> dict[str, object]: - revision = "a" * 40 - tree = "b" * 40 - measurement = empty_measurement() - measurement.update( - { - "status": "ok", - "generation_seconds": 1.0, - "wall_seconds_per_point": 2.0e-6, - "execution_seconds_per_point": 1.0e-6, - "matrix_element": 3.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 1.0e-3, - "artifact": {}, - "selector_contract": None, - "validation": {"status": "ok"}, - "resources": {}, - "provenance": { - "runtime_profile": { - "target_runtime_seconds": 5.0, - "achieved_runtime_seconds": 5.01, - "target_runtime_achieved": True, - "completed_sample_count": 5, - "planned_sample_count": 5, - "interrupted": False, - }, - "report_source_identity_schema": SOURCE_IDENTITY_SCHEMA, - "report_source_revision": revision, - "report_source_tree": tree, - "report_measured_source_revision": revision, - "report_measured_source_tree": tree, - "report_source_clean": True, - }, - "failure": None, - } - ) - return measurement - - -def test_complete_five_second_timing_and_source_identity_pass() -> None: - assert publication_measurement_policy_issues(_measurement()) == () - - -def test_native_benchmark_duration_is_retained_as_publication_evidence() -> None: - benchmark = SimpleNamespace( - uncertainty=SimpleNamespace( - standard_error=1.0e-9, - relative_standard_error=1.0e-3, - ), - effective_config=SimpleNamespace(target_runtime=5.0), - wall_time_per_point=2.0e-6, - evaluator_time_per_point=1.0e-6, - sample_count=5, - environment={ - "elapsed_seconds": 5.02, - "completed_sample_count": 5, - "planned_sample_count": 5, - "repetitions_per_sample": 100, - "measured_point_count": 64000, - "interrupted": False, - "evaluator_time_raw_seconds_per_point": 1.0e-6, - "evaluator_time_status": "measured", - "evaluator_time_ratio_eligible": True, - "evaluator_time_source": ( - "runtime_profile_core_evaluator_call_time" - ), - "compiled_direct_arena_active": False, - "evaluator_sample_count": 5, - "native_profile_points_per_sample": 128, - "timing_sample_contract": ( - "paired_unprofiled_headline_profiled_attribution_v1" - ), - }, - ) - - result = _benchmark_measurement(benchmark, matrix_element=3.0) - - assert result["benchmark_evidence"] == { - "measurement_phase_elapsed_seconds": 5.02, - "target_runtime_seconds": 5.0, - "achieved_runtime_seconds": 5.02, - "target_runtime_achieved": True, - "completed_sample_count": 5, - "planned_sample_count": 5, - "repetitions_per_sample": 100, - "measured_point_count": 64000, - "interrupted": False, - } - - -def test_requested_and_achieved_runtime_are_both_enforced() -> None: - measurement = _measurement() - runtime = measurement["provenance"]["runtime_profile"] - runtime["target_runtime_seconds"] = 1.0 - runtime["achieved_runtime_seconds"] = 0.2 - runtime["target_runtime_achieved"] = False - - issues = timing_policy_issues(measurement) - fields = {issue.field for issue in issues} - - assert "provenance.runtime_profile.target_runtime_seconds" in fields - assert "provenance.runtime_profile.achieved_runtime_seconds" in fields - assert "provenance.runtime_profile.target_runtime_achieved" in fields - - -def test_five_timed_samples_are_required() -> None: - measurement = _measurement() - measurement["sample_count"] = 4 - runtime = measurement["provenance"]["runtime_profile"] - runtime["completed_sample_count"] = 4 - runtime["planned_sample_count"] = 4 - - fields = {issue.field for issue in timing_policy_issues(measurement)} - - assert "sample_count" in fields - assert "provenance.runtime_profile.completed_sample_count" in fields - - -def test_unavailable_execution_requires_authenticated_arena_boundary() -> None: - measurement = _measurement() - measurement["execution_seconds_per_point"] = None - - assert any( - issue.field == "execution_seconds_per_point" - for issue in timing_policy_issues(measurement) - ) - - provenance = measurement["provenance"] - raw_profile = { - "execution_mode": "compiled", - "profile_boundary": ARENA_PROFILE_BOUNDARY, - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "evaluator_timing_available": False, - "points": 128, - "wall_time_s": 128 * 2.1e-6, - "orchestration_time_s": 128 * 2.1e-6, - **{field: 0 for field in ZERO_ARENA_COUNTER_FIELDS}, - **{field: 0.0 for field in ZERO_ARENA_PHASE_TIME_FIELDS}, - **{field: [] for field in EMPTY_ARENA_PHASE_VECTOR_FIELDS}, - **{ - field: 0 - for field in ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS - }, - "compiled_direct_arena_engine_count": 1, - "compiled_direct_arena_call_count": 128, - "evaluator_backend_call_count": 128, - } - arena_evidence = build_arena_profile_evidence( - [raw_profile] * 5, - execution_mode="compiled", - repetitions_per_profile=1, - batch_size=128, - ) - provenance["arena_profile_evidence"] = arena_evidence - provenance["execution_timing"] = { - "abi": "pyamplicol-report-arena-execution-timing-v2", - "status": "unavailable", - "ratio_eligible": False, - "raw_seconds_per_point": None, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "repetitions_per_sample": 1, - "batch_size": 128, - "sample_contract": ( - "paired_unprofiled_headline_profiled_attribution_v1" - ), - "profile_protocol": "arena", - "profile_sample_pass": "runtime._profile_arena_repeated", - "profile_boundary": ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" - ), - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": "coarse-arena-boundary-only-v1", - "evaluator_timing_available": False, - "paired_with_headline": True, - "identical_batch": True, - "identical_repetitions": True, - "execution_mode": "compiled", - "warmed_boundary_wall_seconds_per_point": 2.1e-6, - "arena_profile_evidence_sha256": digest_arena_profile_value( - arena_evidence - ), - } - assert not any( - issue.field == "execution_seconds_per_point" - for issue in timing_policy_issues(measurement) - ) - - -def test_zero_execution_is_not_treated_as_an_unavailable_attribution() -> None: - measurement = _measurement() - measurement["execution_seconds_per_point"] = 0.0 - - assert any( - issue.field == "execution_seconds_per_point" - for issue in timing_policy_issues(measurement) - ) - - -def test_hardcoded_zero_uncertainty_and_partial_blocks_are_rejected() -> None: - measurement = _measurement() - measurement["standard_error_seconds_per_point"] = 0.0 - measurement["relative_standard_error"] = 0.0 - runtime = measurement["provenance"]["runtime_profile"] - runtime["completed_sample_count"] = 4 - runtime["interrupted"] = True - - fields = {issue.field for issue in timing_policy_issues(measurement)} - - assert "standard_error_seconds_per_point" in fields - assert "relative_standard_error" in fields - assert "provenance.runtime_profile.completed_sample_count" in fields - assert "provenance.runtime_profile.interrupted" in fields - - -def test_missing_or_mismatched_source_tree_is_rejected() -> None: - measurement = deepcopy(_measurement()) - provenance = measurement["provenance"] - provenance.pop("report_measured_source_tree") - provenance["report_source_clean"] = False - - fields = { - issue.field - for issue in publication_measurement_policy_issues(measurement) - } - - assert "provenance.report_measured_source_tree" in fields - assert "provenance.report_source_clean" in fields diff --git a/pyamplicol/tests/unit/test_performance_report_prepared.py b/pyamplicol/tests/unit/test_performance_report_prepared.py deleted file mode 100644 index 750b1d717a..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_prepared.py +++ /dev/null @@ -1,179 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.models import ModelKey -from tools.performance_report.prepared import ( - PUBLIC_MODEL_COMPILE_COMMAND_PATH, - PreparedModelError, - _PublicCliModelCompiler, - ensure_prepared_model, - ensure_report_prepared_model, - prepared_identity, - validate_prepared_record, -) - - -class Source: - def __init__(self) -> None: - self.calls = 0 - - def compile(self, *, prepared_output: Path, **_kwargs: object) -> object: - self.calls += 1 - prepared_output.write_bytes(b"prepared-bundle") - return object() - - -def _identity() -> dict[str, object]: - return prepared_identity( - model=ModelKey.UFO_SM, - backend="jit", - jit_optimization_level=2, - source_digest="a" * 64, - producer_revision="revision", - ) - - -def test_prepared_bundle_is_built_once_and_reused(tmp_path: Path) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - source = Source() - bundle = tmp_path / "prepared" / "ufo.pyamplicol-model" - - with ensure_prepared_model( - store=store, - bundle_path=bundle, - source=source, - evaluator=object(), - identity=_identity(), - model_cache_dir=tmp_path / "model-cache", - ) as (path, reused): - assert path == bundle - assert not reused - - with ensure_prepared_model( - store=store, - bundle_path=bundle, - source=source, - evaluator=object(), - identity=_identity(), - model_cache_dir=tmp_path / "model-cache", - ) as (_path, reused): - assert reused - - assert source.calls == 1 - record = validate_prepared_record(bundle, expected_identity=_identity()) - assert record["bundle_size"] == len(b"prepared-bundle") - - -def test_report_prepared_model_requires_explicit_revision(tmp_path: Path) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - - with pytest.raises(PreparedModelError, match="explicit producer revision"): - ensure_report_prepared_model( - store=store, - repo_root=tmp_path, - worker_cores=1, - model=ModelKey.UFO_SM, - producer_revision=None, - ) - - -def test_prepared_bundle_digest_or_identity_mismatch_fails_closed( - tmp_path: Path, -) -> None: - store = ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - source = Source() - bundle = tmp_path / "prepared" / "ufo.pyamplicol-model" - with ensure_prepared_model( - store=store, - bundle_path=bundle, - source=source, - evaluator=object(), - identity=_identity(), - model_cache_dir=tmp_path / "model-cache", - ): - pass - - bundle.write_bytes(b"tampered") - with pytest.raises(PreparedModelError, match=r"digest|size"): - validate_prepared_record(bundle, expected_identity=_identity()) - - record_path = bundle.with_suffix(bundle.suffix + ".report.json") - record = json.loads(record_path.read_text(encoding="ascii")) - record["identity"]["producer_revision"] = "other" - record_path.write_text(json.dumps(record), encoding="ascii") - with pytest.raises(PreparedModelError, match="identity"): - validate_prepared_record(bundle, expected_identity=_identity()) - - -@pytest.mark.parametrize("mode", ("recurrence", "compiled")) -@pytest.mark.parametrize("compress", ("auto", False, True)) -def test_report_model_compiler_uses_public_parse_resolve_dispatch( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - mode: str, - compress: str | bool, -) -> None: - from dataclasses import replace - - from pyamplicol.config import ( - EvaluatorBackend, - EvaluatorConfig, - EvaluatorOptimizationConfig, - JITConfig, - ) - - output = tmp_path / "prepared.pyamplicol-model" - evaluator = EvaluatorConfig( - backend=EvaluatorBackend.JIT, - execution_mode=mode, - optimization=EvaluatorOptimizationConfig(cores=3), - jit=JITConfig(optimization_level=2, compress=compress), - ) - observed: dict[str, object] = {} - - def fake_dispatch(config, services, progress, *, dry_run): - observed.update( - { - "config": config, - "services": services, - "progress": progress, - "dry_run": dry_run, - } - ) - output.write_bytes(b"prepared") - return {"output": str(output)} - - monkeypatch.setattr("pyamplicol.cli.handlers.dispatch", fake_dispatch) - compiler = _PublicCliModelCompiler("built-in-sm") - compiler.compile( - cache_dir=tmp_path / "cache", - evaluator=evaluator, - prepared_output=output, - ) - - config = observed["config"] - assert config.action == "model-compile" - assert config.model.source == "built-in-sm" - assert config.model.cache_dir == tmp_path / "cache" - expected_compression = mode == "compiled" if compress == "auto" else compress - assert config.evaluator == replace( - evaluator, jit=replace(evaluator.jit, compress=expected_compression) - ) - assert config.evaluator.jit.compress is expected_compression - assert observed["dry_run"] is False - assert compiler.command_path == PUBLIC_MODEL_COMPILE_COMMAND_PATH diff --git a/pyamplicol/tests/unit/test_performance_report_publication.py b/pyamplicol/tests/unit/test_performance_report_publication.py deleted file mode 100644 index 1370007f45..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_publication.py +++ /dev/null @@ -1,685 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import shlex -from copy import deepcopy -from pathlib import Path - -import pytest - -from tools.performance_report.publication import ( - PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI, - PublicationPortabilityError, - materialize_current_value, - portable_current_value, - portable_publication_value, - publication_absolute_paths, - publication_measurement_matches_current, - resolve_publication_path, - resolve_publication_string, -) -from tools.performance_report.service import ReportPaths - - -def _paths(tmp_path: Path, profile: str = "macbook_M3") -> ReportPaths: - repo = tmp_path / "source" - return ReportPaths.from_repo(repo, profile=profile) - - -def _canonical_bytes(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def _digest(value: object) -> str: - return hashlib.sha256(_canonical_bytes(value)).hexdigest() - - -def _identity_payload() -> tuple[dict[str, object], dict[str, object]]: - observations: list[dict[str, object]] = [ - { - "module": "pyamplicol", - "kind": "package-member", - "root_index": 0, - "path": "__init__.py", - "size": 12, - "sha256": "a" * 64, - }, - { - "module": "pyamplicol._rusticol", - "kind": "native-extension", - "path": "_rusticol.cpython.so", - "size": 34, - "sha256": "b" * 64, - }, - ] - origin_policy: dict[str, object] = { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": len(observations), - "observations": observations, - "observations_sha256": _digest(observations), - } - candidate = { - "source_revision": "c" * 40, - "source_checkout": "source-checkout", - "native_build_inputs_sha256": "d" * 64, - } - identity: dict[str, object] = { - "kind": "pyamplicol-report-runtime-identity-v1", - "candidate_build_identity": candidate, - "candidate_build_identity_sha256": _digest(candidate), - "python_package_tree": { - "kind": "pyamplicol-python-package-tree-v2", - "root": "pyamplicol", - "roots": ["pyamplicol"], - "sha256": "e" * 64, - }, - "native_extension": { - "path": "_rusticol.cpython.so", - "sha256": "f" * 64, - }, - "loaded_module_origin_policy": origin_policy, - } - return identity, deepcopy(origin_policy) - - -def test_projection_changes_only_explicit_unhashed_locators_and_preserves_digests( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - runtime_identity, postflight_policy = _identity_payload() - candidate = runtime_identity["candidate_build_identity"] - assert isinstance(candidate, dict) - candidate["source_checkout"] = str(paths.repo_root) - runtime_identity["candidate_build_identity_sha256"] = _digest(candidate) - package_tree = runtime_identity["python_package_tree"] - assert isinstance(package_tree, dict) - package_tree["root"] = str(paths.repo_root / "src/pyamplicol") - package_tree["roots"] = [str(paths.repo_root / "src/pyamplicol")] - native = runtime_identity["native_extension"] - assert isinstance(native, dict) - native["path"] = str(paths.repo_root / "native/_rusticol.so") - initial_policy = runtime_identity["loaded_module_origin_policy"] - assert isinstance(initial_policy, dict) - initial_observations = initial_policy["observations"] - assert isinstance(initial_observations, list) - initial_observations[1]["path"] = str( # type: ignore[index] - paths.repo_root / "native/_rusticol.so" - ) - initial_policy["observations_sha256"] = _digest(initial_observations) - postflight_observations = postflight_policy["observations"] - assert isinstance(postflight_observations, list) - postflight_observations[1]["path"] = str( # type: ignore[index] - paths.repo_root / "native/_rusticol.so" - ) - postflight_policy["observations_sha256"] = _digest(postflight_observations) - runtime_before = _canonical_bytes(runtime_identity) - postflight_before = _canonical_bytes(postflight_policy) - payload = { - "status": "ok", - "artifact": { - "path": str(paths.artifact_root / "cells/a/attempts/b/artifact"), - "log_path": str(paths.artifact_root / "cells/a/attempts/b/legacy.log"), - "standalone": str( - paths.artifact_root / "cells/a/attempts/b/artifact/standalone" - ), - }, - "provenance": { - "installation": "/opt/local/MG5_aMC", - "model": {"source_directory": "/opt/local/MG5_aMC/models/sm"}, - "requested_config": { - "model": { - "source": str(paths.repo_root / "models/sm.json"), - "cache_dir": str(paths.repo_root / ".cache/models"), - } - }, - "effective_config": { - "model": { - "source": str(paths.repo_root / "models/sm.json"), - "cache_dir": str(paths.repo_root / ".cache/models"), - } - }, - "worker_log": str(paths.artifact_root / "cells/a/worker.log"), - "runtime_identity": runtime_identity, - "runtime_identity_sha256": _digest(runtime_identity), - "runtime_identity_stable_sha256": _digest(runtime_identity), - "runtime_identity_postflight_loaded_module_origin_policy": ( - postflight_policy - ), - }, - } - - portable = portable_publication_value(payload, paths) - - assert isinstance(portable, dict) - assert publication_absolute_paths(portable) == () - assert str(portable["artifact"]["path"]).startswith( # type: ignore[index] - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - assert str(portable["artifact"]["standalone"]).startswith( # type: ignore[index] - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - provenance = portable["provenance"] - assert isinstance(provenance, dict) - assert str(provenance["worker_log"]).startswith( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - assert provenance["installation"] == "${LOCAL_PATH_REDACTED}" - assert provenance["model"] == { - "source_directory": "${LOCAL_PATH_REDACTED}" - } - assert _canonical_bytes(provenance["runtime_identity"]) == runtime_before - assert ( - _canonical_bytes( - provenance["runtime_identity_postflight_loaded_module_origin_policy"] - ) - == postflight_before - ) - assert ( - _digest(provenance["runtime_identity"]) == provenance["runtime_identity_sha256"] - ) - retained_identity = provenance["runtime_identity"] - assert isinstance(retained_identity, dict) - candidate = retained_identity["candidate_build_identity"] - assert isinstance(candidate, dict) - assert _digest(candidate) == retained_identity["candidate_build_identity_sha256"] - origin_policy = retained_identity["loaded_module_origin_policy"] - assert isinstance(origin_policy, dict) - assert ( - _digest(origin_policy["observations"]) == origin_policy["observations_sha256"] - ) - - -def test_projection_is_idempotent_for_a_complete_legacy_locator_shape( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - probe_args = [ - str(paths.repo_root / "dependencies/legacy/amplicol_color_probe"), - "100000", - "1", - "1", - "lc", - "/private/tmp/pac-example/processes.txt", - "/private/tmp/pac-example/momenta.dat", - "-1", - ] - command = { - "args": [ - str(paths.repo_root / ".venv/bin/python"), - str(paths.repo_root / "dependencies/legacy/process_list.py"), - ], - "cwd": str(paths.artifact_root / "cells/example/artifact"), - "environment": { - "LD_LIBRARY_PATH": (f"{paths.artifact_root}/lib:/opt/local/lib with spaces") - }, - } - profile_command = { - "args": probe_args, - "cwd": str(paths.artifact_root / "cells/example/artifact"), - "environment": dict(command["environment"]), - } - payload = { - "artifact": { - "path": str(paths.artifact_root / "cells/example/artifact"), - "log_path": str(paths.artifact_root / "cells/example/legacy.log"), - }, - "provenance": { - "repository": str(paths.repo_root / "dependencies/legacy"), - "commands": [command, profile_command], - "runtime_profile": { - "measurement": { - **profile_command, - "chunks": [profile_command], - }, - "warmup": profile_command, - }, - "worker_environment": { - "LD_LIBRARY_PATH": "/opt/local/lib:/private/tmp/lib", - "DYLD_LIBRARY_PATH": None, - }, - "worker_log": str(paths.artifact_root / "cells/example/worker.log"), - }, - } - - once = portable_publication_value(payload, paths) - twice = portable_publication_value(once, paths) - - assert once == twice - assert publication_absolute_paths(once) == () - assert once["provenance"]["worker_environment"]["LD_LIBRARY_PATH"] == ( # type: ignore[index] - "${LOCAL_PATH_REDACTED}" - ) - profile = once["provenance"]["runtime_profile"] # type: ignore[index] - assert profile["measurement"]["args"][5:] == [ # type: ignore[index] - "${LOCAL_PATH_REDACTED}", - "${LOCAL_PATH_REDACTED}", - "-1", - ] - assert profile["measurement"]["chunks"][0]["args"][5:] == [ # type: ignore[index] - "${LOCAL_PATH_REDACTED}", - "${LOCAL_PATH_REDACTED}", - "-1", - ] - - -def test_snapshot_projection_relocates_legacy_structural_proof( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - artifact = paths.artifact_root / "cells/example/attempts/one/artifact" - payload = { - "entries": [ - { - "measurement": { - "artifact": { - "path": str(artifact), - "legacy_structural_proof": str( - artifact / "legacy-structural-proof.json" - ), - } - } - } - ] - } - - portable = portable_publication_value(payload, paths) - - proof = portable["entries"][0]["measurement"]["artifact"][ # type: ignore[index] - "legacy_structural_proof" - ] - assert proof == ( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - "cells/example/attempts/one/artifact/legacy-structural-proof.json" - ) - assert publication_absolute_paths(portable) == () - assert portable_publication_value(portable, paths) == portable - - -def test_unknown_legacy_argument_position_fails_closed(tmp_path: Path) -> None: - paths = _paths(tmp_path) - - with pytest.raises( - PublicationPortabilityError, - match=r"/provenance/commands/0/args/2", - ): - portable_publication_value( - { - "provenance": { - "commands": [ - { - "args": [ - "probe", - "ordinary-operand", - "/private/tmp/not-a-schema-locator", - ] - } - ] - } - }, - paths, - ) - - -@pytest.mark.parametrize( - "value", - ( - "@/private/tmp/secret.bin", - r"\\server\share\private\a.dll", - "//server/share/private/a.dll", - "file:///C:/Users/example/private/a.dll", - "unknown=/Users/Alice Smith/private/file.so", - ), -) -def test_unknown_absolute_path_outside_allowlist_fails_closed( - tmp_path: Path, - value: str, -) -> None: - paths = _paths(tmp_path) - - with pytest.raises( - PublicationPortabilityError, - match=r"/diagnostic", - ): - portable_publication_value({"diagnostic": value}, paths) - - -def test_digest_covered_identity_with_absolute_locator_is_opaque_and_not_mutated( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - identity, postflight = _identity_payload() - native = identity["native_extension"] - assert isinstance(native, dict) - native["path"] = "/private/runtime/_rusticol.so" - payload = { - "provenance": { - "runtime_identity": identity, - "runtime_identity_sha256": _digest(identity), - "runtime_identity_postflight_loaded_module_origin_policy": postflight, - } - } - before = deepcopy(payload) - - portable = portable_publication_value(payload, paths) - - assert payload == before - assert portable == payload - assert _canonical_bytes(portable["provenance"]["runtime_identity"]) == ( # type: ignore[index] - _canonical_bytes(payload["provenance"]["runtime_identity"]) # type: ignore[index] - ) - assert publication_absolute_paths(payload) == () - - -def test_invalid_identity_digest_does_not_hide_an_absolute_path( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - identity, _postflight = _identity_payload() - native = identity["native_extension"] - assert isinstance(native, dict) - native["path"] = "/private/runtime/_rusticol.so" - payload = { - "provenance": { - "runtime_identity": identity, - "runtime_identity_sha256": "0" * 64, - } - } - - with pytest.raises( - PublicationPortabilityError, - match=r"/provenance/runtime_identity/native_extension/path", - ): - portable_publication_value(payload, paths) - - assert publication_absolute_paths(payload) == ("/private/runtime/_rusticol.so",) - - -def test_any_valid_digest_covered_sibling_is_copied_byte_identically( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - evidence = { - "path": "/private/authenticated/evidence.bin", - "size": 123, - "member_sha256": "a" * 64, - } - payload = { - "authenticated_evidence": evidence, - "authenticated_evidence_sha256": _digest(evidence), - } - before = _canonical_bytes(evidence) - - portable = portable_publication_value(payload, paths) - - assert _canonical_bytes(portable["authenticated_evidence"]) == before # type: ignore[index] - assert portable["authenticated_evidence"] is evidence # type: ignore[index] - assert publication_absolute_paths(portable) == () - - -def test_known_root_replacement_observes_path_boundaries(tmp_path: Path) -> None: - paths = _paths(tmp_path) - sibling = f"{paths.repo_root}-sibling/models/sm.json" - embedded_suffix = f"/unrelated{paths.repo_root}/models/sm.json" - payload = { - "provenance": { - "effective_config": { - "model": { - "source": sibling, - "cache_dir": embedded_suffix, - } - } - } - } - - portable = portable_publication_value(payload, paths) - model = portable["provenance"]["effective_config"]["model"] # type: ignore[index] - - assert model["source"] == "${LOCAL_PATH_REDACTED}" - assert model["cache_dir"] == "${LOCAL_PATH_REDACTED}" - assert "${PYAMPLICOL_SOURCE_ROOT}-sibling" not in repr(portable) - - -def test_resolver_relocates_known_root_and_rejects_escape_or_raw_path( - tmp_path: Path, -) -> None: - source_paths = _paths(tmp_path / "machine-a", "macbook_M3") - target_paths = _paths(tmp_path / "machine-b", "cluster_EPYC") - raw = source_paths.artifact_root / "cells/example/artifact" - portable = portable_publication_value( - {"artifact": {"path": str(raw)}}, - source_paths, - ) - locator = portable["artifact"]["path"] # type: ignore[index] - assert isinstance(locator, str) - - assert resolve_publication_string(locator, target_paths) == str( - target_paths.artifact_root / "cells/example/artifact" - ) - assert resolve_publication_path(locator, target_paths) == ( - target_paths.artifact_root / "cells/example/artifact" - ) - with pytest.raises(ValueError, match="not canonical"): - resolve_publication_path( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/../../outside", - target_paths, - ) - with pytest.raises(ValueError, match="recognized root"): - resolve_publication_path("/tmp/untrusted/artifact", target_paths) - with pytest.raises(ValueError, match="cannot be resolved"): - resolve_publication_path( - "${LOCAL_PATH_REDACTED}/libexample.dylib", - target_paths, - ) - - -def test_raw_current_is_audited_before_projection_and_is_never_mutated( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - identity, postflight = _identity_payload() - current = { - "status": "ok", - "artifact": { - "path": str(paths.artifact_root / "cells/example/artifact"), - }, - "provenance": { - "runtime_identity": identity, - "runtime_identity_sha256": _digest(identity), - "runtime_identity_postflight_loaded_module_origin_policy": postflight, - }, - } - before = deepcopy(current) - audit_order: list[str] = [] - - def audit_raw(value: dict[str, object]) -> None: - audit_order.append("raw") - assert value["artifact"]["path"] == str( # type: ignore[index] - paths.artifact_root / "cells/example/artifact" - ) - provenance = value["provenance"] - assert isinstance(provenance, dict) - assert ( - _digest(provenance["runtime_identity"]) - == provenance["runtime_identity_sha256"] - ) - - audit_raw(current) - portable = portable_publication_value(current, paths) - audit_order.append("projected") - - assert publication_measurement_matches_current(portable, current, paths) - changed = dict(portable) - changed["status"] = "failed" - assert not publication_measurement_matches_current(changed, current, paths) - assert audit_order == ["raw", "projected"] - assert current == before - - -def test_portable_current_round_trip_rebases_only_approved_locators( - tmp_path: Path, -) -> None: - source = _paths(tmp_path / "before", "manual") - target = _paths(tmp_path / "after", "renamed") - identity = {"native_extension": {"path": "/authenticated/runtime.so"}} - payload = { - "artifact": { - "path": str(source.artifact_root / "cells/a/attempts/id/artifact"), - "log_path": str(source.artifact_root / "cells/a/attempts/id/worker.log"), - }, - "provenance": { - "worker_log": str( - source.artifact_root / "cells/a/attempts/id/worker.log" - ), - "runtime_identity": identity, - "runtime_identity_sha256": _digest(identity), - }, - } - identity_before = _canonical_bytes(identity) - - portable = portable_current_value(payload, source) - materialized = materialize_current_value(portable, target) - - assert portable["artifact"]["path"] == ( # type: ignore[index] - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/cells/a/attempts/id/artifact" - ) - assert materialized["artifact"]["path"] == str( # type: ignore[index] - target.artifact_root / "cells/a/attempts/id/artifact" - ) - assert _canonical_bytes(portable["provenance"]["runtime_identity"]) == ( # type: ignore[index] - identity_before - ) - - -@pytest.mark.parametrize( - "locator", - ( - "/tmp/old-campaign/artifact", - "relative/artifact", - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}", - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/../escape", - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/artifact\\member", - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}//artifact", - ), -) -def test_portable_current_rejects_legacy_or_noncanonical_artifact_locator( - tmp_path: Path, - locator: str, -) -> None: - paths = _paths(tmp_path) - - with pytest.raises(PublicationPortabilityError): - materialize_current_value({"artifact": {"path": locator}}, paths) - - -def test_portable_current_rejects_artifact_symlink_traversal(tmp_path: Path) -> None: - paths = _paths(tmp_path) - paths.artifact_root.mkdir(parents=True) - outside = tmp_path / "outside" - outside.mkdir() - (paths.artifact_root / "escape").symlink_to(outside, target_is_directory=True) - - with pytest.raises(PublicationPortabilityError, match="invalid rooted path"): - materialize_current_value( - { - "artifact": { - "path": "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/escape/payload" - } - }, - paths, - ) - - -def test_portable_current_rejects_in_root_artifact_symlink_traversal( - tmp_path: Path, -) -> None: - paths = _paths(tmp_path) - target = paths.artifact_root / "real" - target.mkdir(parents=True) - (paths.artifact_root / "alias").symlink_to(target, target_is_directory=True) - - with pytest.raises(PublicationPortabilityError, match="symbolic link"): - materialize_current_value( - { - "artifact": { - "path": "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/alias/payload" - } - }, - paths, - ) - - -def test_portable_current_preserves_external_installed_command_and_moves_state( - tmp_path: Path, -) -> None: - source = _paths(tmp_path / "before", "manual") - target = _paths(tmp_path / "after path's", "renamed") - external_python = "/opt/pyamplicol-venv/bin/python" - profile_argv = ( - external_python, - "-m", - "pyamplicol", - "profile", - str(source.artifact_root / "manual-reproductions/cell/artifact"), - ) - payload = { - "artifact": { - "path": str(source.artifact_root / "cells/a/attempts/id/artifact") - }, - "provenance": { - "manual_campaign": { - "public_cli_reproduction": { - "abi": PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI, - "prepare": None, - "generate": None, - "profile": list(profile_argv), - } - } - }, - } - - portable = portable_current_value(payload, source) - stored_argv = portable["provenance"]["manual_campaign"][ # type: ignore[index] - "public_cli_reproduction" - ]["profile"] - assert external_python in stored_argv - assert stored_argv[-1].startswith( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/manual-reproductions" - ) - assert "${LOCAL_PATH_REDACTED}" not in stored_argv - - materialized = materialize_current_value(portable, target) - moved_argv = materialized["provenance"]["manual_campaign"][ # type: ignore[index] - "public_cli_reproduction" - ]["profile"] - assert external_python in moved_argv - assert moved_argv[-1] == str( - target.artifact_root / "manual-reproductions/cell/artifact" - ) - assert shlex.split(shlex.join(moved_argv)) == moved_argv - - with pytest.raises(PublicationPortabilityError, match="structured ABI"): - materialize_current_value( - { - "provenance": { - "manual_campaign": { - "public_cli_reproduction": { - "prepare": None, - "generate": None, - "profile": "old absolute command", - } - } - } - }, - target, - ) diff --git a/pyamplicol/tests/unit/test_performance_report_publication_lineage.py b/pyamplicol/tests/unit/test_performance_report_publication_lineage.py deleted file mode 100644 index e78782118b..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_publication_lineage.py +++ /dev/null @@ -1,185 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import os -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.final_audit import ( - FinalAuditError, - _report_publication_lineage, -) - - -def _git(repo: Path, *arguments: str) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=repo, - check=True, - capture_output=True, - text=True, - ) - return completed.stdout.strip() - - -def _commit(repo: Path, message: str) -> str: - _git(repo, "add", "--all") - _git(repo, "commit", "-m", message) - return _git(repo, "rev-parse", "HEAD") - - -def _repository(tmp_path: Path) -> tuple[Path, str]: - repo = tmp_path / "repo" - repo.mkdir() - _git(repo, "init") - _git(repo, "config", "user.email", "report@example.invalid") - _git(repo, "config", "user.name", "Report Test") - _git(repo, "config", "core.fileMode", "true") - (repo / "src").mkdir() - (repo / "src/evaluator.py").write_text("VALUE = 1\n", encoding="utf-8") - (repo / "docs/arxiv/results").mkdir(parents=True) - (repo / "docs/arxiv/results/cache.json").write_text( - "{}\n", - encoding="ascii", - ) - (repo / "docs/arxiv/pyAmpliCol.tex").write_text( - "\\documentclass{article}\n", - encoding="ascii", - ) - return repo, _commit(repo, "measurement source") - - -def test_same_commit_publication_lineage_is_authenticated(tmp_path: Path) -> None: - repo, measurement_revision = _repository(tmp_path) - - result = _report_publication_lineage(repo, measurement_revision) - - assert result["measurement_source_revision"] == measurement_revision - assert result["publication_revision"] == measurement_revision - assert result["relationship"] == "same-commit" - assert result["changed_paths"] == [] - assert result["executable_source_unchanged"] is True - - -def test_report_only_descendant_accepts_canonical_and_profile_outputs( - tmp_path: Path, -) -> None: - repo, measurement_revision = _repository(tmp_path) - canonical = repo / "src/pyamplicol/_profiling_campaign" - (canonical / "results").mkdir(parents=True) - (canonical / "results/cache.json").write_text( - '{"measured":true}\n', - encoding="ascii", - ) - profile = repo / "docs/performance_reports/macbook_M3" - (profile / "results").mkdir(parents=True) - publications = { - "README.md": "# M3 report\n", - "architecture-profile.json": "{}\n", - "report-workspace.json": "{}\n", - "result_example_table.tex": "% generated\n", - "section_results.tex": "% prose\n", - } - for name, content in publications.items(): - (profile / name).write_text(content, encoding="ascii") - (profile / "results/cache.json").write_text("{}\n", encoding="ascii") - (profile / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n%%EOF\n") - publication_revision = _commit(repo, "publish report") - - result = _report_publication_lineage(repo, measurement_revision) - - assert result["publication_revision"] == publication_revision - assert result["relationship"] == "report-only-descendant" - changed = result["changed_paths"] - assert isinstance(changed, list) - assert {entry["path"] for entry in changed} == { - "src/pyamplicol/_profiling_campaign/results/cache.json", - "docs/performance_reports/macbook_M3/README.md", - "docs/performance_reports/macbook_M3/architecture-profile.json", - "docs/performance_reports/macbook_M3/pyAmpliCol.pdf", - "docs/performance_reports/macbook_M3/report-workspace.json", - "docs/performance_reports/macbook_M3/result_example_table.tex", - "docs/performance_reports/macbook_M3/results/cache.json", - "docs/performance_reports/macbook_M3/section_results.tex", - } - assert result["changed_path_count"] == len(changed) - - -@pytest.mark.parametrize( - ("relative_path", "content"), - [ - ("src/evaluator.py", "VALUE = 2\n"), - ( - "docs/performance_reports/macbook_M3/result_tables.py", - "raise SystemExit(1)\n", - ), - ( - "docs/performance_reports/macbook_M3/results/worker.log", - "private\n", - ), - ("docs/development/runtime.md", "runtime changed\n"), - ], -) -def test_publication_descendant_rejects_every_nonreport_path( - tmp_path: Path, - relative_path: str, - content: str, -) -> None: - repo, measurement_revision = _repository(tmp_path) - path = repo / relative_path - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(content, encoding="utf-8") - _commit(repo, "forbidden publication") - - with pytest.raises(FinalAuditError, match="outside the explicit"): - _report_publication_lineage(repo, measurement_revision) - - -def test_publication_descendant_rejects_executable_allowed_member( - tmp_path: Path, -) -> None: - repo, measurement_revision = _repository(tmp_path) - readme = repo / "src/pyamplicol/_profiling_campaign/README.md" - readme.parent.mkdir(parents=True) - readme.write_text("# report\n", encoding="utf-8") - readme.chmod(readme.stat().st_mode | 0o111) - _commit(repo, "executable report") - - with pytest.raises(FinalAuditError, match="executable, a symlink"): - _report_publication_lineage(repo, measurement_revision) - - -def test_publication_descendant_rejects_symlink_allowed_member( - tmp_path: Path, -) -> None: - repo, measurement_revision = _repository(tmp_path) - readme = repo / "src/pyamplicol/_profiling_campaign/README.md" - readme.parent.mkdir(parents=True) - os.symlink("../src/evaluator.py", readme) - _commit(repo, "symlink report") - - with pytest.raises(FinalAuditError, match="executable, a symlink"): - _report_publication_lineage(repo, measurement_revision) - - -def test_publication_lineage_rejects_dirty_report_output(tmp_path: Path) -> None: - repo, measurement_revision = _repository(tmp_path) - (repo / "docs/arxiv/results/cache.json").write_text( - '{"uncommitted":true}\n', - encoding="ascii", - ) - - with pytest.raises(FinalAuditError, match="completely clean"): - _report_publication_lineage(repo, measurement_revision) - - -def test_publication_lineage_rejects_non_descendant_commit(tmp_path: Path) -> None: - repo, measurement_revision = _repository(tmp_path) - empty_tree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" - unrelated = _git(repo, "commit-tree", empty_tree, "-m", "unrelated publication") - _git(repo, "checkout", "--detach", unrelated) - - with pytest.raises(FinalAuditError, match="not a descendant"): - _report_publication_lineage(repo, measurement_revision) diff --git a/pyamplicol/tests/unit/test_performance_report_publisher.py b/pyamplicol/tests/unit/test_performance_report_publisher.py deleted file mode 100644 index b3ad4af8a8..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_publisher.py +++ /dev/null @@ -1,292 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import subprocess -import threading -from pathlib import Path - -import pytest - -from tools.performance_report.publisher import ( - PublicationResult, - ReportPublisherError, - _compile_pdf, - _copy_report_source, - publish_once, - run_publisher, - validate_published_snapshot, -) -from tools.performance_report.service import ReportPaths, ReportService - - -def _clean_report_service(tmp_path: Path) -> ReportService: - root = tmp_path / "repo" - (root / "docs/arxiv").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=root, check=True) - subprocess.run( - ("git", "config", "user.email", "publisher-tests@example.invalid"), - cwd=root, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Publisher Tests"), - cwd=root, - check=True, - ) - (root / "README.md").write_text("# publisher fixture\n", encoding="ascii") - service = ReportService(ReportPaths.from_repo(root)) - service.publish(reset=True, merge_artifacts=False) - subprocess.run(("git", "add", "."), cwd=root, check=True) - subprocess.run( - ("git", "commit", "-q", "-m", "Initialize report fixture"), - cwd=root, - check=True, - ) - return service - - -def test_publisher_source_copy_excludes_only_top_level_campaign_state( - tmp_path: Path, -) -> None: - source = tmp_path / "source" - source.mkdir() - (source / "pyAmpliCol.tex").write_text("report\n", encoding="ascii") - (source / "campaign_artifacts").mkdir() - (source / "campaign_artifacts/sentinel").write_text("private\n", encoding="ascii") - nested = source / "appendix/campaign_artifacts" - nested.mkdir(parents=True) - (nested / "published.txt").write_text("keep\n", encoding="ascii") - destination = tmp_path / "staging" - - _copy_report_source(source, destination) - - assert not (destination / "campaign_artifacts").exists() - assert (destination / "appendix/campaign_artifacts/published.txt").is_file() - - -def test_pdf_compiler_can_allow_overfull_boxes_for_interactive_refresh( - tmp_path: Path, - monkeypatch, -) -> None: - docs = tmp_path / "docs" - docs.mkdir() - (docs / "pyAmpliCol.tex").write_text( - "\\documentclass{article}\\begin{document}ok\\end{document}\n", - encoding="ascii", - ) - latexmk = tmp_path / "latexmk" - latexmk.write_text( - "#!/usr/bin/env python3\n" - "from pathlib import Path\n" - "Path('pyAmpliCol.pdf').write_bytes(b'%PDF-1.4\\n%%EOF\\n')\n" - "Path('pyAmpliCol.log').write_text(" - "'Overfull \\\\hbox (1.0pt too wide)\\n" - "Output written on pyAmpliCol.pdf (60 pages, 123 bytes).\\n', " - "encoding='utf-8')\n", - encoding="utf-8", - ) - latexmk.chmod(0o755) - monkeypatch.setattr( - "tools.performance_report.publisher.shutil.which", - lambda _name: str(latexmk), - ) - - assert ( - _compile_pdf( - docs, - expected_page_count=60, - timeout_seconds=10.0, - allow_overfull_boxes=True, - ) - == 60 - ) - - with pytest.raises(ReportPublisherError, match="overfull"): - _compile_pdf( - docs, - expected_page_count=60, - timeout_seconds=10.0, - ) - - -def test_pdf_compiler_streams_only_when_requested( - tmp_path: Path, - monkeypatch, - capfd: pytest.CaptureFixture[str], -) -> None: - docs = tmp_path / "docs" - docs.mkdir() - (docs / "pyAmpliCol.tex").write_text( - "\\documentclass{article}\\begin{document}ok\\end{document}\n", - encoding="ascii", - ) - latexmk = tmp_path / "latexmk" - latexmk.write_text( - "#!/usr/bin/env python3\n" - "import sys\n" - "from pathlib import Path\n" - "print('live latex stdout', flush=True)\n" - "print('live latex stderr', file=sys.stderr, flush=True)\n" - "Path('pyAmpliCol.pdf').write_bytes(b'%PDF-1.4\\n%%EOF\\n')\n" - "Path('pyAmpliCol.log').write_text(" - "'Output written on pyAmpliCol.pdf (3 pages, 123 bytes).\\n', " - "encoding='utf-8')\n", - encoding="utf-8", - ) - latexmk.chmod(0o755) - monkeypatch.setattr( - "tools.performance_report.publisher.shutil.which", - lambda _name: str(latexmk), - ) - - assert ( - _compile_pdf( - docs, - expected_page_count=3, - timeout_seconds=10.0, - ) - == 3 - ) - captured = capfd.readouterr() - assert "live latex stdout" not in captured.out - assert "live latex stderr" not in captured.err - - assert ( - _compile_pdf( - docs, - expected_page_count=3, - timeout_seconds=10.0, - stream_output=True, - ) - == 3 - ) - captured = capfd.readouterr() - assert "live latex stdout" in captured.out - assert "live latex stderr" in captured.err - - -def test_publish_once_installs_one_consistent_snapshot( - tmp_path: Path, - monkeypatch, -) -> None: - service = _clean_report_service(tmp_path) - - def fake_compile( - docs_dir: Path, - *, - expected_page_count: int, - timeout_seconds: float, - ) -> int: - assert expected_page_count == 73 - assert timeout_seconds == 900.0 - (docs_dir / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n%%EOF\n") - return 73 - - monkeypatch.setattr( - "tools.performance_report.publisher._compile_pdf", - fake_compile, - ) - - published = publish_once(service) - validated = validate_published_snapshot(service) - - assert published.current_count == 0 - assert published.page_count == 73 - assert validated["status"] == "ok" - assert validated["snapshot_sha256"] == published.snapshot_sha256 - assert (service.paths.docs_dir / "pyAmpliCol.pdf").is_file() - - -def test_active_publisher_never_holds_the_controller_named_lock( - tmp_path: Path, - monkeypatch, -) -> None: - service = _clean_report_service(tmp_path) - entered = threading.Event() - release = threading.Event() - failure: list[BaseException] = [] - - def fake_publish_once(*_args: object, **_kwargs: object) -> PublicationResult: - entered.set() - assert release.wait(timeout=5.0) - return PublicationResult( - current_count=0, - page_count=59, - snapshot_sha256="a" * 64, - captured_at_utc="2026-01-01T00:00:00Z", - published_at_utc="2026-01-01T00:00:01Z", - ) - - def publisher() -> None: - try: - run_publisher(service, watch=False) - except BaseException as error: - failure.append(error) - - monkeypatch.setattr( - "tools.performance_report.publisher.publish_once", - fake_publish_once, - ) - thread = threading.Thread(target=publisher) - thread.start() - assert entered.wait(timeout=5.0) - assert ( - service.paths.coordination_root / "publication" / "daemon.json" - ).is_file() - - with ( - service.store.named_lock("report-publisher-daemon", timeout=0.0), - service.store.named_lock("campaign-controller-boundary", timeout=0.0), - ): - pass - with pytest.raises(ReportPublisherError, match="already active"): - run_publisher(service, watch=False) - - release.set() - thread.join(timeout=5.0) - assert not thread.is_alive() - assert failure == [] - - -def test_publisher_backs_off_behind_controller_report_install( - tmp_path: Path, - monkeypatch, -) -> None: - service = _clean_report_service(tmp_path) - compiled = threading.Event() - completed: list[PublicationResult] = [] - failure: list[BaseException] = [] - - def fake_compile( - docs_dir: Path, - *, - expected_page_count: int, - timeout_seconds: float, - ) -> int: - assert expected_page_count == 73 - assert timeout_seconds == 900.0 - (docs_dir / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n%%EOF\n") - compiled.set() - return 73 - - def publisher() -> None: - try: - completed.append(publish_once(service)) - except BaseException as error: - failure.append(error) - - monkeypatch.setattr( - "tools.performance_report.publisher._compile_pdf", - fake_compile, - ) - with service.store.named_lock("report-writer"): - thread = threading.Thread(target=publisher) - thread.start() - assert compiled.wait(timeout=30.0) - thread.join(timeout=0.15) - assert thread.is_alive() - - thread.join(timeout=5.0) - assert not thread.is_alive() - assert failure == [] - assert len(completed) == 1 diff --git a/pyamplicol/tests/unit/test_performance_report_resource_retention.py b/pyamplicol/tests/unit/test_performance_report_resource_retention.py deleted file mode 100644 index 44edd1c19f..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_resource_retention.py +++ /dev/null @@ -1,187 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from pathlib import Path - -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ArtifactPolicy, CellSpec, ExecutionMode -from tools.performance_report.publication import ( - portable_publication_value, - publication_absolute_paths, -) -from tools.performance_report.scheduler import CampaignScheduler, CampaignSettings -from tools.performance_report.service import ReportPaths - - -def _scheduler(*, retain_workspaces: bool = False) -> CampaignScheduler: - scheduler = object.__new__(CampaignScheduler) - scheduler.settings = CampaignSettings(retain_workspaces=retain_workspaces) - return scheduler - - -def _cell(mode: ExecutionMode) -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is mode - ) - - -def test_successful_reference_artifacts_are_compacted_by_default( - tmp_path: Path, -) -> None: - scheduler = _scheduler() - legacy = tmp_path / "legacy-artifact" - legacy.mkdir() - (legacy / "legacy.log").write_bytes(b"a" * (128 * 1024)) - for name in ( - "contracted-generated-library", - "legacy-structural-evidence", - "selected-flow-generated-library", - ): - directory = legacy / name - directory.mkdir() - (directory / "evidence").write_text(name, encoding="ascii") - - legacy_result: dict[str, object] = {"artifact": {"path": str(legacy)}} - scheduler._compact_reference_artifact( - _cell(ExecutionMode.AMPLICOL), - legacy, - legacy_result, - ) - - assert (legacy / "legacy.log").stat().st_size <= 64 * 1024 - assert not (legacy / "contracted-generated-library").exists() - # The proof inventories these compact files by digest, so they stay with it. - assert (legacy / "legacy-structural-evidence").is_dir() - # The compact selected-flow provider remains reusable by an all-flow cell. - assert (legacy / "selected-flow-generated-library").is_dir() - - madgraph = tmp_path / "madgraph-artifact" - (madgraph / "standalone").mkdir(parents=True) - (madgraph / "standalone" / "matrix.f").write_text("x", encoding="ascii") - (madgraph / "madgraph.log").write_bytes(b"b" * (128 * 1024)) - - madgraph_result: dict[str, object] = { - "artifact": { - "path": str(madgraph), - "standalone": str(madgraph / "standalone"), - "subprocess": "standalone/SubProcesses/P0_test", - } - } - scheduler._compact_reference_artifact( - _cell(ExecutionMode.MADGRAPH), - madgraph, - madgraph_result, - ) - - assert (madgraph / "madgraph.log").stat().st_size <= 64 * 1024 - assert not (madgraph / "standalone").exists() - retained_artifact = madgraph_result["artifact"] - assert isinstance(retained_artifact, dict) - assert "standalone" not in retained_artifact - assert "subprocess" not in retained_artifact - assert retained_artifact["workspace_retention"] == { - "schema": "pyamplicol-reference-workspace-retention-v1", - "full_workspaces_retained": False, - "removed": ["standalone"], - } - - -def test_failed_reference_keeps_only_bounded_diagnostic_tail( - tmp_path: Path, -) -> None: - scheduler = _scheduler() - artifact = tmp_path / "attempt" / "artifact" - artifact.mkdir(parents=True) - (artifact / "legacy.log").write_bytes(b"prefix\n" + b"z" * (128 * 1024)) - (artifact / "partial-build").mkdir() - - scheduler._discard_terminal_artifact(artifact, artifact.parent) - - diagnostic = artifact.parent / "legacy-artifact-tail.log" - assert not artifact.exists() - assert diagnostic.is_file() - assert diagnostic.stat().st_size <= 64 * 1024 - assert diagnostic.read_bytes().endswith(b"z" * 1024) - - -def test_legacy_workspace_cleanup_is_default_and_debug_retention_is_opt_in( - tmp_path: Path, -) -> None: - workspace = tmp_path / "legacy-workspace" - log = workspace / "Outputs" / "log_file.txt" - log.parent.mkdir(parents=True) - log.write_bytes(b"line\n" * 20_000) - diagnostic = tmp_path / "attempt" / "legacy-generator-tail.log" - - _scheduler()._finalize_legacy_workspace( - workspace, - diagnostic_path=diagnostic, - ) - - assert not workspace.exists() - assert diagnostic.is_file() - assert diagnostic.stat().st_size <= 64 * 1024 - - retained = tmp_path / "retained-workspace" - retained_log = retained / "Outputs" / "log_file.txt" - retained_log.parent.mkdir(parents=True) - retained_log.write_text("debug", encoding="ascii") - retained_diagnostic = tmp_path / "unused-tail.log" - - _scheduler(retain_workspaces=True)._finalize_legacy_workspace( - retained, - diagnostic_path=retained_diagnostic, - ) - - assert retained_log.is_file() - assert not retained_diagnostic.exists() - - -def test_worker_log_compaction_respects_debug_retention(tmp_path: Path) -> None: - compact_log = tmp_path / "compact-worker.log" - compact_log.write_bytes(b"c" * (128 * 1024)) - _scheduler()._finalize_worker_log(compact_log) - assert compact_log.stat().st_size <= 64 * 1024 - - retained_log = tmp_path / "retained-worker.log" - retained_payload = b"d" * (128 * 1024) - retained_log.write_bytes(retained_payload) - _scheduler(retain_workspaces=True)._finalize_worker_log(retained_log) - assert retained_log.read_bytes() == retained_payload - - -def test_compacted_madgraph_current_remains_resumable_and_portable( - tmp_path: Path, -) -> None: - paths = ReportPaths.from_repo(tmp_path / "source", profile="retention-test") - store = ArtifactStore( - artifact_root=paths.artifact_root, - lock_root=paths.coordination_root / "locks", - ) - cell = _cell(ExecutionMode.MADGRAPH) - - with store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE) as attempt: - artifact = attempt.path("artifact/madgraph.log").parent - (artifact / "madgraph.log").write_text("complete", encoding="ascii") - (artifact / "standalone").mkdir() - result: dict[str, object] = { - "artifact": { - "path": str(artifact), - "standalone": str(artifact / "standalone"), - "subprocess": "standalone/SubProcesses/P0_test", - } - } - _scheduler()._compact_reference_artifact(cell, artifact, result) - attempt.publish(result, artifact_paths=("artifact/madgraph.log",)) - - current = store.load_current(cell.cell_id) - assert current is not None - current_artifact = current.result["artifact"] - assert isinstance(current_artifact, dict) - assert "standalone" not in current_artifact - assert "subprocess" not in current_artifact - portable = portable_publication_value(current.result, paths) - assert publication_absolute_paths(portable) == () diff --git a/pyamplicol/tests/unit/test_performance_report_resources.py b/pyamplicol/tests/unit/test_performance_report_resources.py deleted file mode 100644 index f43a809ba3..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_resources.py +++ /dev/null @@ -1,1976 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import ctypes -import io -import os -import signal -import subprocess -import sys -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path - -import pytest - -from tools.ci import memory_watchdog -from tools.ci.memory_watchdog import ( - ProbeError as WatchdogProbeError, -) -from tools.ci.memory_watchdog import ProcessInfo as WatchdogProcessInfo -from tools.performance_report.phase_state import ( - WorkerPhaseChannel, - WorkerPhaseReporter, -) -from tools.performance_report.resources import ( - DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES, - DEFAULT_MINIMUM_FREE_DISK_BYTES, - DEFAULT_SAMPLE_INTERVAL_SECONDS, - PROCESS_TREE_MEMORY_METRIC_ABI, - ProcessRecord, - ProcessTreeSampler, - ResourceMonitor, - ResourceProbeError, - _darwin_process_identity, - _DarwinProcBsdInfo, - _linux_proc_snapshot, - _parse_linux_process_identity, - _parse_proc_stat, - _parse_proc_status_rss, - _parse_ps_output, - _ProcessIdentity, - _signal_process_tree, - process_snapshot, - supervise_worker, -) - - -def test_linux_proc_parsers_and_snapshot_include_cpu_time(tmp_path: Path) -> None: - stat = "42 (worker (phase 2)) S 7 42 42 0 -1 0 0 0 0 0 200 50" - status = "Name:\tworker\nVmPeak:\t9000 kB\nVmRSS:\t1536 kB\n" - - assert _parse_proc_stat(stat, clock_ticks_per_second=100) == (7, 2.5) - assert _parse_proc_status_rss(status) == 1536 * 1024 - - process_dir = tmp_path / "42" - process_dir.mkdir() - (process_dir / "stat").write_text(stat, encoding="ascii") - (process_dir / "status").write_text(status, encoding="ascii") - - assert _linux_proc_snapshot( - tmp_path, - clock_ticks_per_second=100, - ) == { - 42: ProcessRecord( - pid=42, - ppid=7, - rss_bytes=1536 * 1024, - cpu_seconds=2.5, - ) - } - - -def test_linux_process_identity_uses_one_stat_snapshot() -> None: - stat = "42 (worker (phase 2)) S 1 77 77 0 -1 0 0 0 0 0 0 0 0 0 20 0 1 0 12345" - - assert _parse_linux_process_identity(stat) == _ProcessIdentity( - birth_token=12345, - process_group=77, - ) - - with pytest.raises(ValueError, match="process identity"): - _parse_linux_process_identity(stat.replace(" 77 77 ", " 0 77 ", 1)) - - -def test_darwin_process_identity_uses_bsd_birth_and_group( - monkeypatch: pytest.MonkeyPatch, -) -> None: - class FakeProcPidInfo: - argtypes: object = None - restype: object = None - - def __init__(self) -> None: - self.short = False - self.mismatched_pid = False - - def __call__( - self, - pid: int, - flavor: int, - arg: int, - buffer: object, - size: int, - ) -> int: - assert flavor == 3 - assert arg == 0 - assert size == ctypes.sizeof(_DarwinProcBsdInfo) - info = ctypes.cast( - buffer, - ctypes.POINTER(_DarwinProcBsdInfo), - ).contents - info.pbi_pid = pid + int(self.mismatched_pid) - info.pbi_pgid = 81 - info.pbi_start_tvsec = 123 - info.pbi_start_tvusec = 456 - return size - 1 if self.short else size - - fake_proc_pidinfo = FakeProcPidInfo() - - class FakeLibproc: - proc_pidinfo = fake_proc_pidinfo - - monkeypatch.setattr( - "tools.performance_report.resources._darwin_libproc", - lambda: FakeLibproc(), - ) - - assert _darwin_process_identity(42) == _ProcessIdentity( - birth_token=(123, 456), - process_group=81, - ) - fake_proc_pidinfo.short = True - assert _darwin_process_identity(42) is None - fake_proc_pidinfo.short = False - fake_proc_pidinfo.mismatched_pid = True - assert _darwin_process_identity(42) is None - - -def test_ps_parser_and_platform_fallback_are_injectable(tmp_path: Path) -> None: - output = " 12 7 1536\n 13 12 512\n" - assert _parse_ps_output(output) == { - 12: ProcessRecord(12, 7, 1536 * 1024), - 13: ProcessRecord(13, 12, 512 * 1024), - } - - @dataclass - class Completed: - returncode: int = 0 - stdout: str = output - stderr: str = "" - - commands: list[tuple[str, ...]] = [] - - def run_ps(command: Sequence[str]) -> Completed: - commands.append(tuple(command)) - return Completed() - - records = process_snapshot( - "Linux", - proc_root=tmp_path / "missing", - ps_runner=run_ps, - ) - assert records[12].rss_bytes == 1536 * 1024 - assert commands == [("ps", "-axo", "pid=,ppid=,rss=")] - - -def test_darwin_snapshot_uses_native_inventory_and_preserves_tree_rss() -> None: - def reject_ps(_command: Sequence[str]) -> object: - raise AssertionError("Darwin resource monitoring must not execute ps") - - records = process_snapshot( - "Darwin", - ps_runner=reject_ps, - darwin_snapshotter=lambda: { - 10: WatchdogProcessInfo(10, 1, 10, 100, 1.0), - 11: WatchdogProcessInfo(11, 10, 10, 200, 2.0), - 12: WatchdogProcessInfo(12, 11, 12, 300, 3.0), - 20: WatchdogProcessInfo(20, 1, 20, 900, 9.0), - }, - ) - - sample = ProcessTreeSampler(10).sample(records) - - assert sample.rss_bytes == 600 - assert sample.cpu_seconds == 6.0 - assert sample.child_count == 2 - assert sample.member_pids == (10, 11, 12) - assert sample.guard_bytes == 600 - - -def test_darwin_native_snapshot_failures_remain_fail_closed() -> None: - def fail_native() -> dict[int, WatchdogProcessInfo]: - raise WatchdogProbeError("libproc denied") - - with pytest.raises(ResourceProbeError, match="libproc denied"): - process_snapshot("Darwin", darwin_snapshotter=fail_native) - with pytest.raises(ResourceProbeError, match="yielded no records"): - process_snapshot("Darwin", darwin_snapshotter=dict) - - -@pytest.mark.skipif(sys.platform != "darwin", reason="requires Darwin libproc") -def test_darwin_native_snapshot_observes_current_process() -> None: - def reject_ps(_command: Sequence[str]) -> object: - raise AssertionError("Darwin resource monitoring must not execute ps") - - records = process_snapshot("Darwin", ps_runner=reject_ps) - - assert records[os.getpid()].rss_bytes > 0 - assert records[os.getpid()].cpu_seconds is not None - - -@pytest.mark.skipif(sys.platform != "darwin", reason="requires Darwin libproc") -def test_darwin_rss_remains_available_without_cpu_timebase( - monkeypatch: pytest.MonkeyPatch, -) -> None: - def fail_timebase() -> tuple[int, int]: - raise WatchdogProbeError("synthetic timebase failure") - - monkeypatch.setattr(memory_watchdog, "_darwin_mach_timebase", fail_timebase) - - records = process_snapshot("Darwin") - - assert records[os.getpid()].rss_bytes > 0 - assert records[os.getpid()].cpu_seconds is None - - -def test_process_tree_aggregates_descendants_and_tracks_reparenting() -> None: - sampler = ProcessTreeSampler(10) - first = sampler.sample( - { - 10: ProcessRecord(10, 1, 100, 1.0), - 11: ProcessRecord(11, 10, 200, 2.0), - 12: ProcessRecord(12, 11, 300, 3.0), - 20: ProcessRecord(20, 1, 900, 9.0), - } - ) - assert first.rss_bytes == 600 - assert first.child_count == 2 - assert first.cpu_seconds == 6.0 - assert first.member_pids == (10, 11, 12) - assert first.physical_footprint_bytes is None - assert first.guard_bytes == 600 - - second = sampler.sample( - { - 10: ProcessRecord(10, 1, 110, 1.5), - 12: ProcessRecord(12, 1, 310, 3.5), - 20: ProcessRecord(20, 1, 900, 9.5), - } - ) - assert second.rss_bytes == 420 - assert second.child_count == 1 - assert second.member_pids == (10, 12) - assert second.guard_bytes == 420 - - -def test_process_tree_sums_physical_footprint_with_race_fallback() -> None: - sampler = ProcessTreeSampler(10) - records = { - 10: ProcessRecord(10, 1, 100, 1.0), - 11: ProcessRecord(11, 10, 200, 2.0), - 12: ProcessRecord(12, 11, 300, 3.0), - } - - sample = sampler.sample( - records, - physical_footprint_probe=lambda _pids: {10: 80, 11: 400}, - ) - - assert sample.rss_bytes == 600 - assert sample.physical_footprint_bytes == 780 - assert sample.guard_bytes == 780 - - -def test_monitor_tracks_current_peak_cpu_wall_and_probe_failure() -> None: - now = 100.0 - snapshots = iter( - ( - { - 10: ProcessRecord(10, 1, 100, 1.0), - 11: ProcessRecord(11, 10, 50, 0.5), - }, - {10: ProcessRecord(10, 1, 90, 2.0)}, - ) - ) - monitor = ResourceMonitor( - 10, - snapshotter=lambda: next(snapshots), - clock=lambda: now, - ) - - now = 101.0 - first = monitor.sample_once() - assert first.available - assert first.current_rss_bytes == 150 - assert first.peak_rss_bytes == 150 - assert first.child_count == 1 - assert first.cpu_seconds == 1.5 - assert first.wall_seconds == 1.0 - - now = 103.0 - second = monitor.sample_once() - assert second.current_rss_bytes == 90 - assert second.peak_rss_bytes == 150 - assert second.child_count == 0 - assert second.cpu_seconds == 2.0 - assert second.wall_seconds == 3.0 - - failed = ResourceMonitor( - 10, - snapshotter=lambda: (_ for _ in ()).throw(ResourceProbeError("offline")), - clock=lambda: 4.0, - ).sample_once() - assert not failed.available - assert failed.current_rss_bytes is None - assert failed.error == "offline" - assert failed.memory_probe_reason == "process-tree-memory-probe-unavailable" - - -def test_monitor_tracks_physical_footprint_and_conservative_guard() -> None: - snapshots = iter( - ( - {10: ProcessRecord(10, 1, 100)}, - {10: ProcessRecord(10, 1, 140)}, - ) - ) - footprints = iter(({10: 180}, {10: 120})) - monitor = ResourceMonitor( - 10, - snapshotter=lambda: next(snapshots), - physical_footprint_probe=lambda _pids: next(footprints), - clock=lambda: 0.0, - ) - - first = monitor.sample_once() - second = monitor.sample_once() - - assert first.current_physical_footprint_bytes == 180 - assert first.current_guard_bytes == 180 - assert second.current_rss_bytes == 140 - assert second.current_physical_footprint_bytes == 120 - assert second.current_guard_bytes == 140 - assert second.peak_rss_bytes == 140 - assert second.peak_physical_footprint_bytes == 180 - assert second.peak_guard_bytes == 180 - assert second.memory_metric_abi == PROCESS_TREE_MEMORY_METRIC_ABI - - -class FakeClock: - def __init__(self) -> None: - self.now = 0.0 - - def __call__(self) -> float: - return self.now - - def sleep(self, duration: float) -> None: - self.now += duration - - -class FakeProcess: - def __init__(self, pid: int = 100, *, stderr: bytes | None = None) -> None: - self.pid = pid - self.returncode: int | None = None - self.stderr = None if stderr is None else io.BytesIO(stderr) - - def poll(self) -> int | None: - return self.returncode - - def wait(self, timeout: float | None = None) -> int: - if self.returncode is None: - raise subprocess.TimeoutExpired("worker", timeout) - return self.returncode - - -def test_supervisor_enforces_timeout_on_worker_process_group() -> None: - clock = FakeClock() - process = FakeProcess() - popen_calls: list[tuple[tuple[str, ...], bool]] = [] - signals: list[tuple[int, tuple[int, ...], int]] = [] - - def popen( - command: Sequence[str], - *, - start_new_session: bool, - env: Mapping[str, str], - ) -> FakeProcess: - assert env - popen_calls.append((tuple(command), start_new_session)) - return process - - def signal_tree(pgid: int | None, members: object, selected_signal: int) -> None: - member_tuple = tuple(sorted(members)) # type: ignore[arg-type] - signals.append((pgid, member_tuple, selected_signal)) - process.returncode = -selected_signal - - result = supervise_worker( - ("worker", "--cell", "one"), - timeout_seconds=2.0, - interval_seconds=1.0, - snapshotter=lambda: { - 100: ProcessRecord(100, 1, 100), - 101: ProcessRecord(101, 100, 50), - }, - popen_factory=popen, - clock=clock, - sleeper=clock.sleep, - signaler=signal_tree, - ) - - assert popen_calls == [(("worker", "--cell", "one"), True)] - assert result.reason == "worker_timeout" - assert result.returncode == -signal.SIGTERM - assert result.usage.wall_seconds == 2.0 - assert signals == [(100, (), signal.SIGTERM)] - - -def test_process_tree_signaler_broadcasts_once_and_signals_only_outliers( - monkeypatch: pytest.MonkeyPatch, -) -> None: - group_signals: list[tuple[int, int]] = [] - individual_signals: list[tuple[int, int]] = [] - monkeypatch.setattr( - "tools.performance_report.resources.os.killpg", - lambda pgid, selected_signal: group_signals.append((pgid, selected_signal)), - ) - monkeypatch.setattr( - "tools.performance_report.resources.os.kill", - lambda pid, selected_signal: individual_signals.append( - (pid, selected_signal) - ), - ) - - _signal_process_tree(100, (201, 202), signal.SIGTERM) - - assert group_signals == [(100, signal.SIGTERM)] - assert individual_signals == [ - (201, signal.SIGTERM), - (202, signal.SIGTERM), - ] - - -def test_stubborn_memory_capped_tree_keeps_primary_outcome_until_reaped() -> None: - clock = FakeClock() - process = FakeProcess() - child_alive = True - kill_seen = False - post_kill_polls = 0 - signals: list[tuple[int, tuple[int, ...], int]] = [] - observed_phases: list[str | None] = [] - - snapshot_calls = 0 - - def snapshot() -> dict[int, ProcessRecord]: - nonlocal snapshot_calls - snapshot_calls += 1 - if snapshot_calls == 1: - return { - 100: ProcessRecord(100, 1, 60), - 101: ProcessRecord(101, 100, 30), - } - return ( - {} - if process.returncode is not None - else {100: ProcessRecord(100, 1, 110)} - ) - - def identity(pid: int) -> _ProcessIdentity | None: - if pid == process.pid and process.returncode is None: - return _ProcessIdentity(birth_token=1, process_group=process.pid) - if pid == 101 and child_alive: - return _ProcessIdentity(birth_token=2, process_group=process.pid) - return None - - def signal_tree(pgid: int | None, members: object, selected_signal: int) -> None: - nonlocal kill_seen - signals.append( - (pgid, tuple(sorted(members)), selected_signal) # type: ignore[arg-type] - ) - if selected_signal == signal.SIGKILL: - kill_seen = True - - def sleep(duration: float) -> None: - nonlocal child_alive, post_kill_polls - clock.now += duration - if not kill_seen: - return - post_kill_polls += 1 - if post_kill_polls == 12: - process.returncode = -signal.SIGKILL - elif post_kill_polls == 14: - child_alive = False - - result = supervise_worker( - ("worker",), - max_rss_bytes=100, - interval_seconds=0.1, - termination_grace_seconds=0.5, - snapshotter=snapshot, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - process_identity_probe=identity, - observation_callback=lambda observation: observed_phases.append( - observation.phase - ), - ) - - assert result.reason == "memory_limit" - assert result.returncode == -signal.SIGKILL - assert result.signal_name == "SIGKILL" - assert result.teardown_escalated - assert result.teardown_seconds > 0.5 - assert signals == [ - (100, (), signal.SIGTERM), - (100, (), signal.SIGKILL), - ] - assert "terminating" in observed_phases - assert observed_phases.count("waiting-for-reap") >= 12 - assert not child_alive - assert snapshot_calls > 2 - - -def test_stubborn_wall_timeout_keeps_primary_outcome_until_root_is_reaped() -> None: - clock = FakeClock() - process = FakeProcess() - kill_seen = False - post_kill_polls = 0 - signals: list[tuple[int | None, tuple[int, ...], int]] = [] - - def identity(pid: int) -> _ProcessIdentity | None: - return ( - _ProcessIdentity(birth_token=1, process_group=process.pid) - if pid == process.pid and process.returncode is None - else None - ) - - def signal_tree( - pgid: int | None, - members: object, - selected_signal: int, - ) -> None: - nonlocal kill_seen - signals.append( - (pgid, tuple(sorted(members)), selected_signal) # type: ignore[arg-type] - ) - if selected_signal == signal.SIGKILL: - kill_seen = True - - def sleep(duration: float) -> None: - nonlocal post_kill_polls - clock.now += duration - if not kill_seen: - return - post_kill_polls += 1 - if post_kill_polls == 3: - process.returncode = -signal.SIGKILL - - result = supervise_worker( - ("worker",), - timeout_seconds=0.1, - interval_seconds=0.1, - termination_grace_seconds=0.2, - snapshotter=lambda: ( - {} - if process.returncode is not None - else {100: ProcessRecord(100, 1, 10)} - ), - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - process_identity_probe=identity, - ) - - assert result.reason == "worker_timeout" - assert result.returncode == -signal.SIGKILL - assert result.teardown_escalated - assert signals == [ - (100, (), signal.SIGTERM), - (100, (), signal.SIGKILL), - ] - - -def test_descendant_group_change_keeps_birth_identity_until_gone() -> None: - clock = FakeClock() - process = FakeProcess() - child_alive = True - child_process_group = process.pid - kill_seen = False - post_kill_polls = 0 - signals: list[tuple[int | None, tuple[int, ...], int]] = [] - - def identity(pid: int) -> _ProcessIdentity | None: - if pid == process.pid and process.returncode is None: - return _ProcessIdentity(birth_token=1, process_group=process.pid) - if pid == 101 and child_alive: - return _ProcessIdentity( - birth_token=2, - process_group=child_process_group, - ) - return None - - def signal_tree( - pgid: int | None, - members: object, - selected_signal: int, - ) -> None: - nonlocal child_process_group, kill_seen - selected_members = tuple(sorted(members)) # type: ignore[arg-type] - signals.append((pgid, selected_members, selected_signal)) - if selected_signal == signal.SIGTERM: - child_process_group = 101 - else: - assert selected_members == (101,) - kill_seen = True - process.returncode = -signal.SIGKILL - - def sleep(duration: float) -> None: - nonlocal child_alive, post_kill_polls - clock.now += duration - if not kill_seen: - return - post_kill_polls += 1 - if post_kill_polls == 3: - child_alive = False - - result = supervise_worker( - ("worker",), - max_rss_bytes=100, - interval_seconds=0.1, - termination_grace_seconds=0.2, - snapshotter=lambda: { - **( - {100: ProcessRecord(100, 1, 70)} - if process.returncode is None - else {} - ), - **({101: ProcessRecord(101, 100, 40)} if child_alive else {}), - }, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - process_identity_probe=identity, - ) - - assert result.reason == "memory_limit" - assert result.returncode == -signal.SIGKILL - assert result.teardown_escalated - assert not child_alive - assert post_kill_polls == 3 - assert signals == [ - (100, (), signal.SIGTERM), - (100, (101,), signal.SIGKILL), - ] - - -def test_natural_exit_does_not_signal_a_reused_descendant_pid() -> None: - clock = FakeClock() - process = FakeProcess() - child_identity: _ProcessIdentity | None = _ProcessIdentity( - birth_token=2, - process_group=process.pid, - ) - signals: list[tuple[int | None, tuple[int, ...], int]] = [] - - def identity(pid: int) -> _ProcessIdentity | None: - if pid == process.pid and process.returncode is None: - return _ProcessIdentity(birth_token=1, process_group=process.pid) - if pid == 101: - return child_identity - return None - - def sleep(duration: float) -> None: - nonlocal child_identity - clock.now += duration - process.returncode = 0 - child_identity = _ProcessIdentity( - birth_token=3, - process_group=process.pid, - ) - - result = supervise_worker( - ("worker",), - interval_seconds=0.1, - snapshotter=lambda: { - **( - {100: ProcessRecord(100, 1, 10)} - if process.returncode is None - else {} - ), - 101: ProcessRecord( - 101, - 100 if process.returncode is None else 1, - 10, - ), - }, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=lambda pgid, members, selected_signal: signals.append( - (pgid, tuple(sorted(members)), selected_signal) - ), - process_identity_probe=identity, - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert signals == [] - - -def test_completed_root_cannot_leave_a_known_descendant_running() -> None: - clock = FakeClock() - process = FakeProcess() - child_alive = True - signals: list[tuple[int, tuple[int, ...], int]] = [] - - def snapshot() -> dict[int, ProcessRecord]: - records = ( - {} if process.returncode is not None else {100: ProcessRecord(100, 1, 100)} - ) - if child_alive: - records[101] = ProcessRecord( - 101, - 100 if process.returncode is None else 1, - 50, - ) - return records - - def sleep(duration: float) -> None: - clock.now += duration - process.returncode = 0 - - def signal_tree(pgid: int | None, members: object, selected_signal: int) -> None: - nonlocal child_alive - signals.append( - (pgid, tuple(sorted(members)), selected_signal) # type: ignore[arg-type] - ) - if selected_signal == signal.SIGKILL: - child_alive = False - - result = supervise_worker( - ("worker",), - interval_seconds=0.1, - termination_grace_seconds=0.1, - snapshotter=snapshot, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - process_identity_probe=lambda pid: ( - _ProcessIdentity(birth_token=pid, process_group=process.pid) - if ( - (pid == process.pid and process.returncode is None) - or (pid == 101 and child_alive) - ) - else None - ), - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert not child_alive - assert signals == [ - (100, (), signal.SIGTERM), - (100, (), signal.SIGKILL), - ] - assert result.teardown_escalated - assert result.teardown_seconds >= 0.1 - - -def test_completed_root_reports_graceful_descendant_teardown() -> None: - clock = FakeClock() - process = FakeProcess() - child_alive = True - signals: list[tuple[int | None, tuple[int, ...], int]] = [] - - def sleep(duration: float) -> None: - clock.now += duration - process.returncode = 0 - - def signal_tree( - pgid: int | None, - members: object, - selected_signal: int, - ) -> None: - nonlocal child_alive - signals.append( - (pgid, tuple(sorted(members)), selected_signal) # type: ignore[arg-type] - ) - assert selected_signal == signal.SIGTERM - child_alive = False - - result = supervise_worker( - ("worker",), - interval_seconds=0.1, - termination_grace_seconds=0.2, - snapshotter=lambda: { - **( - {100: ProcessRecord(100, 1, 100)} - if process.returncode is None - else {} - ), - **({101: ProcessRecord(101, 100, 50)} if child_alive else {}), - }, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - process_identity_probe=lambda pid: ( - _ProcessIdentity(birth_token=pid, process_group=process.pid) - if ( - (pid == process.pid and process.returncode is None) - or (pid == 101 and child_alive) - ) - else None - ), - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert signals == [(100, (), signal.SIGTERM)] - assert not result.teardown_escalated - assert result.teardown_seconds > 0.0 - - -def test_supervisor_propagates_symbolica_license_to_worker_environment( - monkeypatch: pytest.MonkeyPatch, -) -> None: - license_value = "ordinary-test-license" - monkeypatch.setenv("SYMBOLICA_LICENSE", license_value) - process = FakeProcess() - process.returncode = 0 - observed: dict[str, object] = {} - - def popen( - command: Sequence[str], - *, - start_new_session: bool, - env: Mapping[str, str], - ) -> FakeProcess: - observed["command"] = tuple(command) - observed["start_new_session"] = start_new_session - observed["license"] = env.get("SYMBOLICA_LICENSE") - return process - - result = supervise_worker( - ("worker", "--cell", "one"), - snapshotter=lambda: {}, - popen_factory=popen, - ) - - assert observed == { - "command": ("worker", "--cell", "one"), - "start_new_session": True, - "license": license_value, - } - assert result.returncode == 0 - - -def test_supervisor_merges_explicit_worker_environment_overrides( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setenv("SYMBOLICA_LICENSE", "ordinary-test-license") - process = FakeProcess() - process.returncode = 0 - observed: dict[str, str | None] = {} - - def popen( - _command: Sequence[str], - *, - start_new_session: bool, - env: Mapping[str, str], - ) -> FakeProcess: - assert start_new_session - observed["license"] = env.get("SYMBOLICA_LICENSE") - observed["gate"] = env.get("PYAMPLICOL_NATIVE_COMPILER_GATE_DIR") - observed["slots"] = env.get("PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT") - return process - - result = supervise_worker( - ("worker",), - environment_overrides={ - "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR": "/tmp/compiler-gate", - "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT": "4", - }, - snapshotter=lambda: {}, - popen_factory=popen, - ) - - assert observed == { - "license": "ordinary-test-license", - "gate": "/tmp/compiler-gate", - "slots": "4", - } - assert result.returncode == 0 - - -def test_split_worker_scrubs_import_environment_and_sets_measured_cwd( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import_environment = { - "PYTHONHOME", - "PYTHONINSPECT", - "PYTHONPATH", - "PYTHONPYCACHEPREFIX", - "PYTHONSTARTUP", - "PYTHONUSERBASE", - "PYAMPLICOL_EXACT_IMPORT_PATHS", - "PYAMPLICOL_EXACT_PYTHON_REEXEC", - "PYAMPLICOL_CACHE_DIR", - "PYAMPLICOL_PREPARED_MODEL_BOOTSTRAP", - "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR", - "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT", - "VIRTUAL_ENV", - "_OLD_VIRTUAL_PATH", - "__PYVENV_LAUNCHER__", - } - for name in import_environment: - monkeypatch.setenv(name, f"attacker-{name}") - process = FakeProcess() - process.returncode = 0 - observed: dict[str, object] = {} - - def popen( - command: Sequence[str], - *, - start_new_session: bool, - env: Mapping[str, str], - cwd: str, - ) -> FakeProcess: - observed["command"] = tuple(command) - observed["start_new_session"] = start_new_session - observed["cwd"] = cwd - observed["present"] = import_environment.intersection(env) - return process - - result = supervise_worker( - ("worker",), - scrub_import_environment=True, - environment_overrides={ - "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR": "/authenticated/gate", - "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT": "4", - }, - working_directory=tmp_path, - snapshotter=lambda: {}, - popen_factory=popen, - ) - - assert result.returncode == 0 - assert observed == { - "command": ("worker",), - "start_new_session": True, - "cwd": str(tmp_path.resolve()), - "present": { - "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR", - "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT", - }, - } - with pytest.raises(ValueError, match="environment override"): - supervise_worker( - ("worker",), - scrub_import_environment=True, - environment_overrides={"PYTHONPATH": "/attacker"}, - ) - - -def test_ordinary_worker_environment_remains_compatible( - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setenv("PYTHONPATH", "/ordinary/controller/path") - process = FakeProcess() - process.returncode = 0 - observed: dict[str, object] = {} - - def popen( - _command: Sequence[str], - *, - start_new_session: bool, - env: Mapping[str, str], - ) -> FakeProcess: - assert start_new_session - observed["pythonpath"] = env.get("PYTHONPATH") - return process - - result = supervise_worker( - ("worker",), - snapshotter=lambda: {}, - popen_factory=popen, - ) - - assert result.returncode == 0 - assert observed["pythonpath"] == "/ordinary/controller/path" - - -def test_supervisor_enforces_memory_limit_and_preserves_exit_on_probe_error() -> None: - process = FakeProcess() - - def terminate(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - limited = supervise_worker( - ("worker",), - max_rss_bytes=100, - snapshotter=lambda: { - 100: ProcessRecord(100, 1, 80), - 101: ProcessRecord(101, 100, 30), - }, - popen_factory=lambda *_args, **_kwargs: process, - signaler=terminate, - ) - assert limited.reason == "memory_limit" - assert limited.usage.current_rss_bytes == 110 - assert limited.usage.peak_rss_bytes == 110 - assert limited.memory_limit_reason == "process-tree-rss-limit" - - completed = FakeProcess() - completed.returncode = 7 - unavailable = supervise_worker( - ("worker",), - max_rss_bytes=100, - snapshotter=lambda: (_ for _ in ()).throw(OSError("unavailable")), - popen_factory=lambda *_args, **_kwargs: completed, - ) - assert unavailable.reason == "worker_exit" - assert unavailable.returncode == 7 - assert not unavailable.usage.available - assert unavailable.usage.error == "unavailable" - assert ( - unavailable.usage.memory_probe_reason == "process-tree-memory-probe-unavailable" - ) - - -def test_supervisor_enforces_physical_footprint_over_rss() -> None: - process = FakeProcess() - - def terminate(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - limited = supervise_worker( - ("worker",), - max_rss_bytes=100, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - physical_footprint_probe=lambda _pids: {100: 150}, - popen_factory=lambda *_args, **_kwargs: process, - signaler=terminate, - ) - - assert limited.reason == "memory_limit" - assert limited.memory_limit_bytes == 100 - assert limited.memory_limit_reason == "darwin-process-tree-physical-footprint-limit" - assert limited.usage.peak_rss_bytes == 80 - assert limited.usage.peak_physical_footprint_bytes == 150 - assert limited.usage.peak_guard_bytes == 150 - - -def test_supervisor_fails_closed_when_worker_exits_during_probe_retry() -> None: - process = FakeProcess() - footprint_calls = 0 - - def footprint(_pids: object) -> dict[int, int]: - nonlocal footprint_calls - footprint_calls += 1 - raise ResourceProbeError("synthetic footprint probe failure") - - def exit_during_retry(_duration: float) -> None: - process.returncode = 0 - - result = supervise_worker( - ("worker",), - max_rss_bytes=100, - interval_seconds=0.01, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - physical_footprint_probe=footprint, - popen_factory=lambda *_args, **_kwargs: process, - sleeper=exit_during_retry, - ) - - assert result.reason == "memory_probe_error" - assert result.returncode == 0 - assert footprint_calls == 1 - assert not result.usage.available - assert ( - result.usage.memory_probe_reason - == "darwin-process-tree-physical-footprint-probe-unavailable" - ) - - -def test_supervisor_terminates_after_third_required_probe_failure() -> None: - process = FakeProcess() - footprint_calls = 0 - signals: list[int] = [] - - def footprint(_pids: object) -> dict[int, int]: - nonlocal footprint_calls - footprint_calls += 1 - raise ResourceProbeError("synthetic footprint probe failure") - - def terminate(_pgid: int, _members: object, selected_signal: int) -> None: - signals.append(selected_signal) - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - max_rss_bytes=100, - interval_seconds=0.01, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - physical_footprint_probe=footprint, - popen_factory=lambda *_args, **_kwargs: process, - sleeper=lambda _duration: None, - signaler=terminate, - ) - - assert result.reason == "memory_probe_error" - assert result.returncode == -signal.SIGTERM - assert footprint_calls == 3 - assert signals == [signal.SIGTERM] - assert ( - result.usage.memory_probe_reason - == "darwin-process-tree-physical-footprint-probe-unavailable" - ) - - -def test_supervisor_clears_recovered_probe_failure_while_worker_is_alive() -> None: - process = FakeProcess() - footprint_calls = 0 - sleep_calls = 0 - - def footprint(_pids: object) -> dict[int, int]: - nonlocal footprint_calls - footprint_calls += 1 - if footprint_calls == 1: - raise ResourceProbeError("synthetic footprint probe failure") - return {100: 90} - - def complete_after_recovery(_duration: float) -> None: - nonlocal sleep_calls - sleep_calls += 1 - if sleep_calls == 2: - process.returncode = 0 - - result = supervise_worker( - ("worker",), - max_rss_bytes=100, - interval_seconds=0.01, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - physical_footprint_probe=footprint, - popen_factory=lambda *_args, **_kwargs: process, - sleeper=complete_after_recovery, - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert footprint_calls >= 2 - assert result.usage.available - assert result.usage.memory_probe_reason is None - assert result.usage.peak_guard_bytes == 90 - - -def test_supervisor_enforces_cap_on_first_recovered_probe_sample() -> None: - process = FakeProcess() - footprint_calls = 0 - - def footprint(_pids: object) -> dict[int, int]: - nonlocal footprint_calls - footprint_calls += 1 - if footprint_calls == 1: - raise ResourceProbeError("synthetic footprint probe failure") - return {100: 150} - - def terminate(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - max_rss_bytes=100, - interval_seconds=0.01, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - physical_footprint_probe=footprint, - popen_factory=lambda *_args, **_kwargs: process, - sleeper=lambda _duration: None, - signaler=terminate, - ) - - assert result.reason == "memory_limit" - assert result.memory_limit_reason == ( - "darwin-process-tree-physical-footprint-limit" - ) - assert footprint_calls == 2 - assert result.usage.memory_probe_reason is None - assert result.usage.peak_guard_bytes == 150 - - -def test_defaults_and_invalid_limits() -> None: - assert DEFAULT_SAMPLE_INTERVAL_SECONDS == 1.0 - assert DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES == 64 * 1024 * 1024 - assert DEFAULT_MINIMUM_FREE_DISK_BYTES == 5 * 1024 * 1024 * 1024 - with pytest.raises(ValueError, match="timeout_seconds"): - supervise_worker(("worker",), timeout_seconds=0) - with pytest.raises(ValueError, match="max_rss_bytes"): - supervise_worker(("worker",), max_rss_bytes=0) - with pytest.raises(ValueError, match="generation_timeout_seconds"): - supervise_worker(("worker",), generation_timeout_seconds=0) - with pytest.raises(ValueError, match="authenticated phase_channel"): - supervise_worker(("worker",), generation_timeout_seconds=1) - with pytest.raises(ValueError, match="environment override"): - supervise_worker( - ("worker",), - environment_overrides={"INVALID=NAME": "value"}, - ) - with pytest.raises(ValueError, match="stderr_limit_bytes"): - supervise_worker(("worker",), stderr_limit_bytes=0) - with pytest.raises(ValueError, match="output file limits"): - supervise_worker(("worker",), output_file_limits={Path("log"): 0}) - with pytest.raises(ValueError, match="minimum_free_disk_bytes"): - supervise_worker(("worker",), minimum_free_disk_bytes=0) - - -@pytest.mark.skipif(os.name != "posix", reason="process groups require POSIX") -def test_supervisor_terminates_runaway_append_at_output_cap(tmp_path: Path) -> None: - output = tmp_path / "runaway.log" - script = ( - "import time\n" - "from pathlib import Path\n" - f"stream = Path({str(output)!r}).open('ab', buffering=0)\n" - "block = b'x' * 4096\n" - "while True:\n" - " stream.write(block)\n" - " time.sleep(0.0001)\n" - ) - - result = supervise_worker( - (sys.executable, "-c", script), - output_file_limits={output: 32 * 1024}, - interval_seconds=1.0, - termination_grace_seconds=1.0, - ) - - assert result.reason == "output_limit" - assert result.returncode < 0 - assert result.output_limit_path == str(output.resolve()) - assert result.output_limit_bytes == 32 * 1024 - assert result.observed_output_bytes is not None - assert result.observed_output_bytes > result.output_limit_bytes - # The safety reason bypasses the ordinary one-second teardown grace. - assert result.teardown_seconds < 1.0 - assert output.stat().st_size < 8 * 1024 * 1024 - - -@pytest.mark.parametrize( - ("exit_code", "expected_reason"), - ((0, "output_limit"), (23, "worker_exit")), -) -def test_exit_boundary_probes_output_without_hiding_worker_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - exit_code: int, - expected_reason: str, -) -> None: - output = tmp_path / "fast-writer.log" - output.write_bytes(b"x" * 33) - process = FakeProcess() - process.returncode = exit_code - # Keep the background guard dormant so this exercises the synchronous - # final probe after poll observes that the worker has already exited. - monkeypatch.setattr( - "tools.performance_report.resources.DEFAULT_STORAGE_SAFETY_INTERVAL_SECONDS", - 60.0, - ) - - result = supervise_worker( - ("worker",), - output_file_limits={output: 32}, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - popen_factory=lambda *_args, **_kwargs: process, - ) - - assert result.reason == expected_reason - assert result.returncode == exit_code - assert result.output_limit_path == str(output.resolve()) - assert result.output_limit_bytes == 32 - assert result.observed_output_bytes == 33 - - -def test_storage_safety_precedes_cancellation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - output = tmp_path / "cancel-race.log" - output.write_bytes(b"x" * 33) - process = FakeProcess() - signals: list[int] = [] - monkeypatch.setattr( - "tools.performance_report.resources.DEFAULT_STORAGE_SAFETY_INTERVAL_SECONDS", - 60.0, - ) - - def signal_tree( - _pgid: int | None, - _members: object, - selected_signal: int, - ) -> None: - signals.append(selected_signal) - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - output_file_limits={output: 32}, - cancellation_requested=lambda: True, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - popen_factory=lambda *_args, **_kwargs: process, - signaler=signal_tree, - ) - - assert result.reason == "output_limit" - assert result.returncode == -signal.SIGTERM - assert signals == [signal.SIGTERM] - - -def test_supervisor_terminates_when_free_disk_reserve_is_crossed( - tmp_path: Path, -) -> None: - process = FakeProcess() - signals: list[int] = [] - - def signal_tree( - _pgid: int | None, - _members: object, - selected_signal: int, - ) -> None: - signals.append(selected_signal) - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - minimum_free_disk_bytes=10_000, - disk_probe_path=tmp_path, - disk_free_probe=lambda _path: 9_999, - snapshotter=lambda: {100: ProcessRecord(100, 1, 80)}, - popen_factory=lambda *_args, **_kwargs: process, - sleeper=lambda _duration: None, - signaler=signal_tree, - ) - - assert result.reason == "disk_space_limit" - assert result.minimum_free_disk_bytes == 10_000 - assert result.observed_free_disk_bytes == 9_999 - assert signals == [signal.SIGTERM] - - -def test_supervisor_preserves_nonzero_worker_exit() -> None: - result = supervise_worker( - (sys.executable, "-c", "raise SystemExit(23)"), - interval_seconds=0.01, - capture_stderr=True, - ) - - assert result.reason == "worker_exit" - assert result.returncode == 23 - assert result.signal_name is None - assert result.signal_number is None - assert result.pid is not None - assert result.pid in result.member_pids - assert result.started_at_utc is not None - assert result.finished_at_utc is not None - assert result.supervisor_stderr is None - - -@pytest.mark.parametrize( - ("returncode", "expected_signal"), - ( - (-signal.SIGSEGV, "SIGSEGV"), - (-signal.SIGKILL, "SIGKILL"), - ), -) -def test_supervisor_decodes_worker_signal_exit_without_crashing_a_child( - returncode: int, - expected_signal: str, -) -> None: - process = FakeProcess() - process.returncode = returncode - - result = supervise_worker( - ("worker",), - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - ) - - assert result.reason == "worker_exit" - assert result.returncode == returncode - assert result.signal_name == expected_signal - assert result.signal_number == -returncode - assert result.pid == process.pid - assert result.member_pids == (process.pid,) - - -def test_supervisor_retains_bounded_native_abort_stderr() -> None: - marker = "native evaluator abort: synthetic fault" - process = FakeProcess(stderr=f"{marker}\n".encode()) - process.returncode = -signal.SIGABRT - - result = supervise_worker( - ("worker",), - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - capture_stderr=True, - stderr_limit_bytes=32, - ) - - assert result.reason == "worker_exit" - assert result.returncode == -signal.SIGABRT - assert result.signal_name == "SIGABRT" - assert result.supervisor_stderr is not None - assert result.supervisor_stderr.endswith("synthetic fault\n") - assert result.supervisor_stderr_truncated - assert result.supervisor_stderr_limit_bytes == 32 - - -def test_worker_exit_remains_primary_when_phase_state_also_fails( - tmp_path: Path, -) -> None: - process = FakeProcess() - process.returncode = -signal.SIGSEGV - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - channel.path.write_text("{malformed", encoding="ascii") - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=2.0, - phase_channel=channel, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - ) - - assert result.reason == "worker_exit" - assert result.returncode == -signal.SIGSEGV - assert result.signal_name == "SIGSEGV" - assert result.phase_state_error is not None - assert "valid JSON" in result.phase_state_error - assert result.generation_phase is not None - assert result.generation_phase.supervisor_reason == "worker_exit" - - -def test_generation_limit_excludes_preparation_and_post_generation( - tmp_path: Path, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - ) - generation = reporter.generation() - sleep_count = 0 - signals: list[int] = [] - - def sleep(_duration: float) -> None: - nonlocal sleep_count - sleep_count += 1 - if sleep_count == 1: - clock.now = 50.0 - generation.__enter__() - elif sleep_count == 2: - clock.now = 51.0 - generation.__exit__(None, None, None) - else: - clock.now = 101.0 - process.returncode = 0 - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - signals.append(selected_signal) - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=2.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert signals == [] - assert result.generation_phase is not None - assert result.generation_phase.authenticated - assert result.generation_phase.supervisor_reason == "completed" - assert result.generation_phase.final_phase == "post-generation" - assert result.generation_phase.generation_elapsed_seconds == 1.0 - - -def test_manual_generation_guard_includes_worker_preparation( - tmp_path: Path, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - ) - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=2.0, - generation_guard_includes_preparation=True, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=clock.sleep, - signaler=signal_tree, - ) - - assert result.reason == "generation_timeout" - assert result.usage.wall_seconds == 2.0 - assert result.generation_phase is not None - assert result.generation_phase.final_phase == "pre-generation" - assert result.generation_phase.generation_elapsed_seconds == 2.0 - - -@pytest.mark.parametrize( - ("stage", "expected_reason"), - ( - ("profiling", "profiling_timeout"), - ("validation", "validation_timeout"), - ), -) -def test_supervisor_enforces_authenticated_post_generation_stage_budget( - tmp_path: Path, - stage: str, - expected_reason: str, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / f"{stage}.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - track_post_generation_stages=True, - ) - with reporter.generation(): - pass - reporter.profiling_started() - if stage == "validation": - reporter.validation_started() - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - timeout_seconds=30.0, - generation_timeout_seconds=10.0, - profiling_timeout_seconds=2.0, - validation_timeout_seconds=2.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=clock.sleep, - signaler=signal_tree, - ) - - assert result.reason == expected_reason - assert result.returncode == -signal.SIGTERM - assert result.usage.wall_seconds == 2.0 - - -def test_supervisor_allows_authenticated_stage_budget_without_generation_limit( - tmp_path: Path, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "profiling-only.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - track_post_generation_stages=True, - ) - with reporter.generation(): - pass - reporter.profiling_started() - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - profiling_timeout_seconds=2.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=clock.sleep, - signaler=signal_tree, - ) - - assert result.reason == "profiling_timeout" - assert result.generation_phase is None - - -@pytest.mark.parametrize( - ("last_transition", "expected_phase"), - ( - ("generation", "post-generation"), - ("profiling", "profiling"), - ("validation", "validation"), - ("complete", "complete"), - ), -) -def test_phase_transitions_during_slow_observation_use_fresh_clock( - tmp_path: Path, - last_transition: str, - expected_phase: str, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / f"{last_transition}.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - track_post_generation_stages=True, - ) - transitioned = False - - def observe(_observation: object) -> None: - nonlocal transitioned - if transitioned: - return - transitioned = True - # Longer than the sampling interval: the old supervisor compared the - # resulting authenticated timestamps with its pre-callback clock and - # rejected them as being outside the process lifetime. - clock.now = 5.0 - with reporter.generation(): - pass - if last_transition in {"profiling", "validation", "complete"}: - reporter.profiling_started() - if last_transition in {"validation", "complete"}: - reporter.validation_started() - if last_transition == "complete": - reporter.complete() - - def sleep(duration: float) -> None: - clock.now += duration - process.returncode = 0 - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=60.0, - profiling_timeout_seconds=60.0, - validation_timeout_seconds=60.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - observation_callback=observe, - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert result.phase_state_error is None - assert result.generation_phase is not None - assert result.generation_phase.authenticated - assert result.generation_phase.final_phase == expected_phase - - -def test_phase_monitor_still_rejects_authenticated_future_timestamp( - tmp_path: Path, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "future.json") - WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: 10_000_000_000, - ) - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=60.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=clock.sleep, - signaler=signal_tree, - ) - - assert result.reason == "phase_state_error" - assert result.returncode == -signal.SIGTERM - assert result.phase_state_error == ( - "worker phase-state transition timestamp is outside the supervised " - "process lifetime" - ) - assert result.generation_phase is not None - assert not result.generation_phase.authenticated - - -@pytest.mark.parametrize( - ("boundaries", "expected_reason"), - ( - ((0.0, 3.0, 3.5, 4.0), "generation_timeout"), - ((0.0, 1.0, 4.0, 4.5), "profiling_timeout"), - ((0.0, 1.0, 1.5, 4.0), "validation_timeout"), - # Deterministic timeline precedence chooses the earlier profiling - # overrun when both closed stages crossed their limits between polls. - ((0.0, 1.0, 4.0, 7.0), "profiling_timeout"), - ), -) -def test_supervisor_enforces_closed_stage_boundaries_between_samples( - tmp_path: Path, - boundaries: tuple[float, float, float, float], - expected_reason: str, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / f"{expected_reason}.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - track_post_generation_stages=True, - ) - transitioned = False - - def cross_all_boundaries(_duration: float) -> None: - nonlocal transitioned - if transitioned: - clock.now += 1.0 - return - transitioned = True - generation_start, generation_end, validation_start, complete = boundaries - clock.now = generation_start - generation = reporter.generation() - generation.__enter__() - clock.now = generation_end - generation.__exit__(None, None, None) - reporter.profiling_started() - clock.now = validation_start - reporter.validation_started() - clock.now = complete - reporter.complete() - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - timeout_seconds=30.0, - generation_timeout_seconds=2.0, - profiling_timeout_seconds=2.0, - validation_timeout_seconds=2.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=cross_all_boundaries, - signaler=signal_tree, - ) - - assert result.reason == expected_reason - assert result.returncode == -signal.SIGTERM - - -@pytest.mark.parametrize( - ("phase", "expected_phase"), - ( - ("preparation", "pre-generation"), - ("generation", "generation"), - ("profiling", "post-generation"), - ), -) -def test_cancellation_terminates_the_process_tree_in_every_worker_phase( - tmp_path: Path, - phase: str, - expected_phase: str, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / f"{phase}.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - ) - generation = reporter.generation() - if phase == "generation": - generation.__enter__() - elif phase == "profiling": - with generation: - pass - cancellation = False - signals: list[tuple[int, tuple[int, ...], int]] = [] - - def sleep(duration: float) -> None: - nonlocal cancellation - clock.now += duration - cancellation = True - - def signal_tree(pgid: int | None, members: object, selected_signal: int) -> None: - signals.append( - (pgid, tuple(sorted(members)), selected_signal) # type: ignore[arg-type] - ) - process.returncode = -selected_signal - - try: - result = supervise_worker( - ("worker",), - generation_timeout_seconds=60.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: { - 100: ProcessRecord(100, 1, 100), - 101: ProcessRecord(101, 100, 50), - }, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - cancellation_requested=lambda: cancellation, - ) - finally: - if phase == "generation": - generation.__exit__(None, None, None) - - assert result.reason == "cancelled" - assert result.returncode == -signal.SIGTERM - assert signals == [(100, (), signal.SIGTERM)] - assert result.generation_phase is not None - assert result.generation_phase.authenticated - assert result.generation_phase.final_phase == expected_phase - - -def test_supervisor_accepts_completed_zero_work_generation_phase( - tmp_path: Path, -) -> None: - clock = FakeClock() - clock.now = 10.0 - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - ) - with reporter.generation(): - pass - process.returncode = 0 - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=2.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=clock.sleep, - ) - - assert result.reason == "completed" - assert result.returncode == 0 - assert result.generation_phase is not None - assert result.generation_phase.authenticated - assert result.generation_phase.final_sequence == 2 - assert result.generation_phase.final_phase == "post-generation" - assert result.generation_phase.generation_elapsed_seconds == 0.0 - - -def test_generation_limit_terminates_only_active_generation( - tmp_path: Path, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - reporter = WorkerPhaseReporter( - channel, - worker_pid=process.pid, - clock_ns=lambda: int(clock.now * 1_000_000_000), - ) - generation = reporter.generation() - sleep_count = 0 - - def sleep(_duration: float) -> None: - nonlocal sleep_count - sleep_count += 1 - if sleep_count == 1: - clock.now = 50.0 - generation.__enter__() - else: - clock.now += 1.0 - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=2.0, - phase_channel=channel, - interval_seconds=1.0, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=sleep, - signaler=signal_tree, - ) - - assert result.reason == "generation_timeout" - assert result.returncode == -signal.SIGTERM - assert result.usage.wall_seconds == 52.0 - assert result.generation_phase is not None - assert result.generation_phase.authenticated - assert result.generation_phase.supervisor_reason == "generation_timeout" - assert result.generation_phase.final_phase == "generation" - assert result.generation_phase.generation_elapsed_seconds == 2.0 - - -def test_generation_phase_monitor_fails_closed_on_malformed_state( - tmp_path: Path, -) -> None: - clock = FakeClock() - process = FakeProcess() - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - channel.path.write_text("{malformed", encoding="ascii") - - def signal_tree(_pgid: int, _members: object, selected_signal: int) -> None: - process.returncode = -selected_signal - - result = supervise_worker( - ("worker",), - generation_timeout_seconds=2.0, - phase_channel=channel, - snapshotter=lambda: {100: ProcessRecord(100, 1, 100)}, - popen_factory=lambda *_args, **_kwargs: process, - clock=clock, - sleeper=clock.sleep, - signaler=signal_tree, - ) - - assert result.reason == "phase_state_error" - assert result.returncode == -signal.SIGTERM - assert result.generation_phase is not None - assert not result.generation_phase.authenticated - assert result.generation_phase.supervisor_reason == "phase_state_error" - assert "valid JSON" in str(result.generation_phase.error) diff --git a/pyamplicol/tests/unit/test_performance_report_runtime_evidence.py b/pyamplicol/tests/unit/test_performance_report_runtime_evidence.py deleted file mode 100644 index 605e2e8a4e..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_runtime_evidence.py +++ /dev/null @@ -1,274 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import sys -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.performance_report import runtime_evidence - - -def _isolate_bytecode(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: - prefix = tmp_path / "absent-cache-prefix" - assert not prefix.exists() - monkeypatch.setattr(sys, "dont_write_bytecode", True) - monkeypatch.setattr(sys, "pycache_prefix", str(prefix)) - monkeypatch.setattr( - runtime_evidence, - "_isolated_startup_flags", - lambda: (True, True, True), - ) - - -def test_source_only_bytecode_policy_requires_both_controls( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - monkeypatch.setattr( - runtime_evidence, - "_isolated_startup_flags", - lambda: (True, True, True), - ) - monkeypatch.setattr(sys, "dont_write_bytecode", False) - monkeypatch.setattr(sys, "pycache_prefix", None) - with pytest.raises(runtime_evidence.RuntimeEvidenceError, match="Python -B"): - runtime_evidence.source_only_bytecode_policy() - - monkeypatch.setattr(sys, "dont_write_bytecode", True) - with pytest.raises( - runtime_evidence.RuntimeEvidenceError, - match="PYTHONPYCACHEPREFIX", - ): - runtime_evidence.source_only_bytecode_policy() - - prefix = tmp_path / "populated" - prefix.mkdir() - monkeypatch.setattr(sys, "pycache_prefix", str(prefix)) - with pytest.raises(runtime_evidence.RuntimeEvidenceError, match="remain absent"): - runtime_evidence.source_only_bytecode_policy() - - -def test_package_identity_is_stable_and_ignores_ineligible_cache_namespace( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - _isolate_bytecode(monkeypatch, tmp_path) - package = tmp_path / "pyamplicol" - cache = package / "__pycache__" - submodule = package / "submodule" - cache.mkdir(parents=True) - submodule.mkdir() - (package / "__init__.py").write_text("VALUE = 1\n", encoding="utf-8") - (submodule / "data.bin").write_bytes(b"\x00\x01") - (cache / "__init__.cpython-test.pyc").write_bytes(b"ineligible") - - first = runtime_evidence.python_package_tree_identity(package) - second = runtime_evidence.python_package_tree_identity(package) - - assert first == second - assert first["kind"] == "pyamplicol-python-package-tree-v2" - assert first["file_count"] == 2 - assert first["member_set_stable"] is True - assert first["namespace_bound_to_root_fd"] is True - assert first["bytecode_policy"] == { - "kind": "pyamplicol-source-only-bytecode-policy-v1", - "dont_write_bytecode": True, - "external_pycache_prefix": True, - "external_pycache_prefix_absent": True, - "package_local_bytecode_eligible": False, - "isolated_startup": True, - "site_initialization": False, - "python_environment_ignored_at_startup": True, - } - - (package / "__init__.py").write_text("VALUE = 2\n", encoding="utf-8") - assert runtime_evidence.python_package_tree_identity(package)["sha256"] != first[ - "sha256" - ] - - -def test_package_identity_rejects_sourceless_bytecode_and_symlinks( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - _isolate_bytecode(monkeypatch, tmp_path) - package = tmp_path / "pyamplicol" - package.mkdir() - (package / "__init__.py").write_bytes(b"") - bytecode = package / "injected.pyc" - bytecode.write_bytes(b"eligible sourceless bytecode") - with pytest.raises( - runtime_evidence.RuntimeEvidenceError, - match="sourceless bytecode", - ): - runtime_evidence.python_package_tree_identity(package) - - bytecode.unlink() - target = package / "target.py" - target.write_bytes(b"VALUE = 1\n") - (package / "alias.py").symlink_to(target) - with pytest.raises( - runtime_evidence.RuntimeEvidenceError, - match="not a regular file", - ): - runtime_evidence.python_package_tree_identity(package) - - -def test_package_identity_binds_ordered_shadowing_roots( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - _isolate_bytecode(monkeypatch, tmp_path) - first = tmp_path / "first" / "pyamplicol" - second = tmp_path / "second" / "pyamplicol" - first.mkdir(parents=True) - second.mkdir(parents=True) - (first / "__init__.py").write_text("ORIGIN = 'first'\n", encoding="utf-8") - (second / "__init__.py").write_text("ORIGIN = 'second'\n", encoding="utf-8") - - forward = runtime_evidence.python_package_tree_identity((first, second)) - reverse = runtime_evidence.python_package_tree_identity((second, first)) - - assert forward["roots"] == [str(first.resolve()), str(second.resolve())] - assert reverse["roots"] == [str(second.resolve()), str(first.resolve())] - assert forward["sha256"] != reverse["sha256"] - - -def _module( - origin: Path, - *, - cached: Path | None = None, - namespace: bool = False, -) -> SimpleNamespace: - return SimpleNamespace( - __file__=None if namespace else str(origin), - __cached__=None if cached is None else str(cached), - __spec__=SimpleNamespace( - origin=None if namespace else str(origin), - submodule_search_locations=[str(origin)] if namespace else None, - ), - ) - - -def test_loaded_origins_are_exact_authenticated_members( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - _isolate_bytecode(monkeypatch, tmp_path) - package = tmp_path / "pyamplicol" - package.mkdir() - package_init = package / "__init__.py" - package_init.write_text("VALUE = 1\n", encoding="utf-8") - cache = package / "__pycache__" / "__init__.cpython-test.pyc" - cache.parent.mkdir() - cache.write_bytes(b"ordinary pip-created bytecode cache") - native = package / "_rusticol.so" - native.write_bytes(b"native") - expected_tree = runtime_evidence.python_package_tree_identity(package) - expected_native = runtime_evidence._path_file_identity(native) - fake_sys = SimpleNamespace( - dont_write_bytecode=True, - pycache_prefix=sys.pycache_prefix, - modules={ - "pyamplicol": _module(package_init, cached=cache), - "pyamplicol._rusticol": _module(native), - }, - ) - monkeypatch.setattr(runtime_evidence, "sys", fake_sys) - - policy = runtime_evidence.loaded_pyamplicol_origin_policy( - package, - native_extension=native, - expected_package_identity=expected_tree, - expected_native_identity=expected_native, - ) - - assert policy["observed_module_count"] == 2 - assert len(policy["observations"]) == 2 - assert len(policy["observations_sha256"]) == 64 - - -def test_loaded_origins_reject_actual_sourceless_bytecode( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - _isolate_bytecode(monkeypatch, tmp_path) - package = tmp_path / "pyamplicol" - package.mkdir() - package_init = package / "__init__.py" - package_init.write_text("VALUE = 1\n", encoding="utf-8") - native = package / "_rusticol.so" - native.write_bytes(b"native") - expected_tree = runtime_evidence.python_package_tree_identity(package) - expected_native = runtime_evidence._path_file_identity(native) - bytecode = package / "__pycache__" / "injected.pyc" - bytecode.parent.mkdir() - bytecode.write_bytes(b"sourceless bytecode") - fake_sys = SimpleNamespace( - dont_write_bytecode=True, - pycache_prefix=sys.pycache_prefix, - modules={"pyamplicol.injected": _module(bytecode)}, - ) - monkeypatch.setattr(runtime_evidence, "sys", fake_sys) - - with pytest.raises( - runtime_evidence.RuntimeEvidenceError, - match="used sourceless bytecode", - ): - runtime_evidence.loaded_pyamplicol_origin_policy( - package, - native_extension=native, - expected_package_identity=expected_tree, - expected_native_identity=expected_native, - ) - - -def test_loaded_origins_reject_unrecorded_and_excluded_members( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - _isolate_bytecode(monkeypatch, tmp_path) - package = tmp_path / "pyamplicol" - cache = package / "__pycache__" - cache.mkdir(parents=True) - package_init = package / "__init__.py" - package_init.write_text("VALUE = 1\n", encoding="utf-8") - native = package / "_rusticol.so" - native.write_bytes(b"native") - expected_tree = runtime_evidence.python_package_tree_identity(package) - expected_native = runtime_evidence._path_file_identity(native) - injected = package / "injected.py" - injected.write_text("VALUE = 2\n", encoding="utf-8") - fake_sys = SimpleNamespace( - dont_write_bytecode=True, - pycache_prefix=sys.pycache_prefix, - modules={"pyamplicol": _module(injected)}, - ) - monkeypatch.setattr(runtime_evidence, "sys", fake_sys) - with pytest.raises( - runtime_evidence.RuntimeEvidenceError, - match="preimport identity", - ): - runtime_evidence.loaded_pyamplicol_origin_policy( - package, - native_extension=native, - expected_package_identity=expected_tree, - expected_native_identity=expected_native, - ) - - injected.unlink() - cached_source = cache / "injected.py" - cached_source.write_text("VALUE = 3\n", encoding="utf-8") - fake_sys.modules = {"pyamplicol": _module(cached_source)} - with pytest.raises( - runtime_evidence.RuntimeEvidenceError, - match="excluded cache bytes", - ): - runtime_evidence.loaded_pyamplicol_origin_policy( - package, - native_extension=native, - expected_package_identity=expected_tree, - expected_native_identity=expected_native, - ) diff --git a/pyamplicol/tests/unit/test_performance_report_source_identity.py b/pyamplicol/tests/unit/test_performance_report_source_identity.py deleted file mode 100644 index 4313e16661..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_source_identity.py +++ /dev/null @@ -1,401 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.source_identity import ( - PUBLICATION_SOURCE_IDENTITY_SCHEMA, - SOURCE_IDENTITY_SCHEMA, - ReportSourceIdentityError, - inspect_report_publication, - inspect_report_source, - require_eligible_report_source, - require_report_only_publication, -) - - -def _git(repo: Path, *arguments: str) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=repo, - check=True, - capture_output=True, - text=True, - ) - return completed.stdout.strip() - - -def _repository(tmp_path: Path) -> Path: - repo = tmp_path / "repo" - repo.mkdir() - _git(repo, "init") - _git(repo, "config", "user.email", "report@example.invalid") - _git(repo, "config", "user.name", "Report Test") - (repo / "src").mkdir() - (repo / "src/evaluator.py").write_text("VALUE = 1\n", encoding="utf-8") - (repo / "docs/arxiv/results").mkdir(parents=True) - (repo / "docs/arxiv/results/cache.json").write_text( - "{}\n", - encoding="ascii", - ) - (repo / "docs/arxiv/result_example_table.tex").write_text( - "% generated\n", - encoding="ascii", - ) - profile = repo / "docs/performance_reports/macbook_M3" - (profile / "results").mkdir(parents=True) - (profile / "pyAmpliCol.tex").write_text("% report\n", encoding="ascii") - (profile / "result_tables.py").write_text("# entry point\n", encoding="ascii") - (profile / "results/cache.json").write_text("{}\n", encoding="ascii") - _git(repo, "add", ".") - _git(repo, "commit", "-m", "fixture") - return repo - - -def test_source_identity_records_commit_tree_and_clean_state( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - - identity = require_eligible_report_source(repo) - - assert identity.revision == _git(repo, "rev-parse", "HEAD") - assert identity.tree == _git(repo, "rev-parse", "HEAD^{tree}") - assert identity.dirty_paths == () - assert identity.provenance() == { - "report_source_identity_schema": SOURCE_IDENTITY_SCHEMA, - "report_source_revision": identity.revision, - "report_source_tree": identity.tree, - "report_measured_source_revision": identity.revision, - "report_measured_source_tree": identity.tree, - "report_source_clean": True, - } - - -def test_source_identity_rejects_a_nested_path_inside_an_outer_checkout( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - nested = repo / "scratch/repo" - nested.mkdir(parents=True) - - with pytest.raises(ReportSourceIdentityError, match="not the repository root"): - inspect_report_source(nested) - - -def test_generated_report_outputs_do_not_dirty_measurement_source( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - (repo / "docs/arxiv/results/cache.json").write_text( - '{"measured":true}\n' - ) - (repo / "docs/arxiv/result_example_table.tex").write_text("% refreshed\n") - profile = repo / "docs/performance_reports/macbook_M3" - (profile / "results/cache.json").write_text('{"measured":true}\n') - (profile / "result_example_table.tex").write_text("% generated\n") - (profile / "result_validation_summary.tex").write_text("% summary\n") - (profile / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n") - (profile / "pyAmpliCol.aux").write_text("\\relax\n") - summary = profile / "campaign_summary_ids" - summary.mkdir() - (summary / "error.txt").write_text("cell-a\n", encoding="utf-8") - campaign_artifacts = profile / "campaign_artifacts" - (campaign_artifacts / "attempts/cell-a").mkdir(parents=True) - (campaign_artifacts / "attempts/cell-a/result.json").write_text( - '{"status":"ok"}\n', encoding="utf-8" - ) - (campaign_artifacts / "coordination/locks").mkdir(parents=True) - (campaign_artifacts / "coordination/locks/cell.lock").write_text( - "locked\n", encoding="utf-8" - ) - artifacts = repo / ".artifacts/performance-report/macbook_M3" - artifacts.mkdir(parents=True) - (artifacts / "attempt.bin").write_bytes(b"attempt") - - identity = require_eligible_report_source(repo) - - assert identity.eligible - assert identity.dirty_paths == () - - -@pytest.mark.parametrize( - "path", - ( - "docs/performance_reports/macbook_M3/result_tables.py", - "docs/performance_reports/macbook_M3/pyAmpliCol.tex", - "docs/performance_reports/macbook_M3/section_scope.tex", - "docs/performance_reports/macbook_M3/README.md", - "docs/performance_reports/macbook_M3/report-workspace.json", - "docs/performance_reports/macbook_M3/arbitrary.txt", - "docs/performance_reports/macbook_M3/results/nested/raw.json", - "docs/performance_reports/macbook_M3/campaign_summary_ids/nested/error.txt", - "docs/performance_reports/macbook_M3/campaign_summary_ids/error.json", - "docs/performance_reports/macbook_M3/" - ".campaign_summary_ids.deadbeef.tmp/error.txt", - "docs/performance_reports/macbook_M3/campaign_artifact/attempt.bin", - "docs/performance_reports/campaign_artifacts/attempt.bin", - "scratch/macbook_M3/campaign_artifacts/attempt.bin", - ), -) -def test_profile_scaffold_or_arbitrary_changes_dirty_measurement_source( - tmp_path: Path, - path: str, -) -> None: - repo = _repository(tmp_path) - target = repo / path - target.parent.mkdir(parents=True, exist_ok=True) - target.write_text("changed\n", encoding="utf-8") - - identity = inspect_report_source(repo) - - assert path in identity.dirty_paths - - -def test_tracked_or_untracked_source_changes_are_ineligible( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - (repo / "src/evaluator.py").write_text("VALUE = 2\n", encoding="utf-8") - (repo / "tools").mkdir() - (repo / "tools/untracked.py").write_text("VALUE = 3\n", encoding="utf-8") - - identity = inspect_report_source(repo) - - assert not identity.eligible - assert identity.dirty_paths == ( - "src/evaluator.py", - "tools/untracked.py", - ) - with pytest.raises( - ReportSourceIdentityError, - match=r"dirty source paths: src/evaluator\.py, tools/untracked\.py", - ): - require_eligible_report_source(repo) - - -def test_generated_profile_environment_is_a_report_output( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - profile = repo / "docs/performance_reports/macbook_M3" - (profile / "report_environment.json").write_text( - '{"status":"authenticated"}\n', - encoding="ascii", - ) - (profile / "report_environment.tex").write_text( - "% authenticated environment\n", - encoding="ascii", - ) - - identity = require_eligible_report_source(repo) - - assert identity.eligible - assert identity.dirty_paths == () - - -def _commit_path(repo: Path, path: str, content: str) -> str: - target = repo / path - target.parent.mkdir(parents=True, exist_ok=True) - target.write_text(content, encoding="utf-8") - _git(repo, "add", path) - _git(repo, "commit", "-m", f"update {path}") - return _git(repo, "rev-parse", "HEAD") - - -def test_publication_descendant_authenticates_both_shas_and_report_paths( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - measured = _git(repo, "rev-parse", "HEAD") - profile = "macbook_M3" - _commit_path( - repo, - f"docs/performance_reports/{profile}/result_example_table.tex", - "% measured table\n", - ) - publication = _commit_path( - repo, - f"docs/performance_reports/{profile}/results/raw.json", - '{"status":"ok"}\n', - ) - - identity = require_report_only_publication( - repo, - measured_revision=measured, - profile=profile, - ) - - assert identity.measured_revision == measured - assert identity.publication_revision == publication - assert identity.measured_tree == _git(repo, "rev-parse", f"{measured}^{{tree}}") - assert identity.publication_tree == _git( - repo, - "rev-parse", - f"{publication}^{{tree}}", - ) - assert identity.eligible - assert identity.provenance() == { - "report_publication_source_identity_schema": ( - PUBLICATION_SOURCE_IDENTITY_SCHEMA - ), - "report_profile": profile, - "report_measured_source_revision": measured, - "report_measured_source_tree": identity.measured_tree, - "report_publication_revision": publication, - "report_publication_tree": identity.publication_tree, - "report_publication_report_only": True, - "report_publication_changed_paths": [ - f"docs/performance_reports/{profile}/result_example_table.tex", - f"docs/performance_reports/{profile}/results/raw.json", - ], - } - - -def test_publication_descendant_allows_authenticated_environment_outputs( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - measured = _git(repo, "rev-parse", "HEAD") - profile = "macbook_M3" - _commit_path( - repo, - f"docs/performance_reports/{profile}/report_environment.json", - '{"status":"authenticated"}\n', - ) - publication = _commit_path( - repo, - f"docs/performance_reports/{profile}/report_environment.tex", - "% authenticated environment\n", - ) - - identity = require_report_only_publication( - repo, - measured_revision=measured, - profile=profile, - publication_revision=publication, - ) - - assert identity.eligible - assert identity.changed_paths == ( - f"docs/performance_reports/{profile}/report_environment.json", - f"docs/performance_reports/{profile}/report_environment.tex", - ) - - -@pytest.mark.parametrize( - "path", - ( - "src/evaluator.py", - "rust/runtime.rs", - "dependencies/symbolica/source.rs", - "build_backend/backend.py", - "tools/performance_report/runner.py", - ), -) -def test_publication_rejects_evaluator_or_tool_changes( - tmp_path: Path, - path: str, -) -> None: - repo = _repository(tmp_path) - measured = _git(repo, "rev-parse", "HEAD") - _commit_path(repo, path, "CHANGED = True\n") - - identity = inspect_report_publication( - repo, - measured_revision=measured, - profile="macbook_M3", - ) - - assert identity.disallowed_paths == (path,) - with pytest.raises( - ReportSourceIdentityError, - match="disallowed paths", - ): - require_report_only_publication( - repo, - measured_revision=measured, - profile="macbook_M3", - ) - - -def test_publication_rejects_scaffold_wrong_profile_and_nested_payloads( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - measured = _git(repo, "rev-parse", "HEAD") - paths = ( - "docs/performance_reports/cluster_EPYC/results/raw.json", - "docs/performance_reports/macbook_M3/result_tables.py", - "docs/performance_reports/macbook_M3/results/nested/raw.json", - "docs/performance_reports/macbook_M3/section_scope.tex", - ) - for path in paths: - _commit_path(repo, path, "payload\n") - - identity = inspect_report_publication( - repo, - measured_revision=measured, - profile="macbook_M3", - ) - - assert identity.disallowed_paths == paths - - -def test_publication_rejects_rename_executable_and_symlink_modes( - tmp_path: Path, -) -> None: - repo = _repository(tmp_path) - profile = repo / "docs/performance_reports/macbook_M3" - measured = _git(repo, "rev-parse", "HEAD") - - old_table = profile / "result_old_table.tex" - old_table.write_text("% old\n", encoding="ascii") - _git(repo, "add", old_table.relative_to(repo).as_posix()) - _git(repo, "commit", "-m", "add old table before measurement") - measured = _git(repo, "rev-parse", "HEAD") - - new_table = profile / "result_new_table.tex" - old_table.rename(new_table) - executable = profile / "result_executable_table.tex" - executable.write_text("% executable\n", encoding="ascii") - executable.chmod(0o755) - symlink = profile / "result_symlink_table.tex" - symlink.symlink_to("result_new_table.tex") - _git(repo, "add", "-A") - _git(repo, "commit", "-m", "unsafe publication members") - - identity = inspect_report_publication( - repo, - measured_revision=measured, - profile="macbook_M3", - ) - - assert identity.disallowed_paths == ( - "docs/performance_reports/macbook_M3/result_executable_table.tex", - "docs/performance_reports/macbook_M3/result_new_table.tex", - "docs/performance_reports/macbook_M3/result_old_table.tex", - "docs/performance_reports/macbook_M3/result_symlink_table.tex", - ) - - -def test_publication_must_descend_from_measured_commit(tmp_path: Path) -> None: - repo = _repository(tmp_path) - measured = _git(repo, "rev-parse", "HEAD") - _git(repo, "checkout", "--orphan", "unrelated") - _git(repo, "rm", "-rf", ".") - publication = _commit_path(repo, "README.md", "unrelated\n") - - with pytest.raises( - ReportSourceIdentityError, - match="not a descendant", - ): - inspect_report_publication( - repo, - measured_revision=measured, - publication_revision=publication, - profile="macbook_M3", - ) diff --git a/pyamplicol/tests/unit/test_performance_report_standalone_build.py b/pyamplicol/tests/unit/test_performance_report_standalone_build.py deleted file mode 100644 index b65fad50dc..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_standalone_build.py +++ /dev/null @@ -1,81 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from pathlib import Path - -import pytest - -from tools.performance_report.standalone_build import ( - StandaloneBuildError, - compile_report, - validate_latex_log, -) - - -def _fake_engine(tmp_path: Path, log: str) -> Path: - engine = tmp_path / "fake-pdflatex" - engine.write_text( - "#!/usr/bin/env python3\n" - "from pathlib import Path\n" - "Path('pyAmpliCol.pdf').write_bytes(b'%PDF-1.4\\n%%EOF\\n')\n" - f"Path('pyAmpliCol.log').write_text({log!r}, encoding='utf-8')\n", - encoding="utf-8", - ) - engine.chmod(0o755) - return engine - - -def test_standalone_builder_compiles_relocated_report(tmp_path: Path) -> None: - report = tmp_path / "relocated report" - report.mkdir() - (report / "pyAmpliCol.tex").write_text( - "\\documentclass{article}\\begin{document}ok\\end{document}\n", - encoding="ascii", - ) - - output = compile_report( - report, - engine=str(_fake_engine(tmp_path, "clean publication log\n")), - passes=2, - ) - - assert output == report / "pyAmpliCol.pdf" - assert output.is_file() - - -def test_standalone_builder_rejects_overfull_output(tmp_path: Path) -> None: - report = tmp_path / "report" - report.mkdir() - (report / "pyAmpliCol.tex").write_text( - "\\documentclass{article}\\begin{document}bad\\end{document}\n", - encoding="ascii", - ) - - with pytest.raises(StandaloneBuildError, match="overfull"): - compile_report( - report, - engine=str( - _fake_engine( - tmp_path, - "Overfull \\hbox (1.0pt too wide)\n", - ) - ), - passes=2, - ) - - -def test_latex_log_can_explicitly_allow_overfull_boxes() -> None: - validate_latex_log( - "Overfull \\hbox (1.0pt too wide)\n" - "Overfull \\vbox (2.0pt too high)\n", - allow_overfull_boxes=True, - ) - - -def test_latex_log_still_rejects_unresolved_references_when_overfull_allowed() -> None: - with pytest.raises(StandaloneBuildError, match="unresolved"): - validate_latex_log( - "Overfull \\hbox (1.0pt too wide)\n" - "LaTeX Warning: There were undefined references.\n", - allow_overfull_boxes=True, - ) diff --git a/pyamplicol/tests/unit/test_performance_report_study_contract.py b/pyamplicol/tests/unit/test_performance_report_study_contract.py deleted file mode 100644 index 41e08a0c8e..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_study_contract.py +++ /dev/null @@ -1,482 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import shutil -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.campaign_policy import ( - MACBOOK_M3_POLICY, - MACBOOK_M3_Z_TABLE_F_POLICY, - PolicyCensorKind, - policy_censor_measurement, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ArtifactPolicy -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity -from tools.performance_report.study_contract import ( - Z_TABLE_F_PRIOR_CELL_COUNT, - Z_TABLE_F_PRIOR_EVIDENCE_ABI, - Z_TABLE_F_PRIOR_STATIC_NA_CELL_COUNT, - StudyContractError, - audit_z_table_f_policy_projection, - bind_z_table_f_attempt, - load_z_table_f_study_contract, - require_z_table_f_explicit_cell, - write_z_table_f_study_contract, - z_table_f_cell_ids, - z_table_f_prior_cell_ids, - z_table_f_worker_harness_identity, -) -from tools.performance_report.worker_harness import attach_worker_harness_identity - - -def _git_repo(path: Path, marker: str) -> Path: - path.mkdir() - (path / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - (path / "tools/performance_report").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=path, check=True) - subprocess.run( - ("git", "config", "user.email", "test@example.invalid"), - cwd=path, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Test"), - cwd=path, - check=True, - ) - (path / "README.md").write_text(marker + "\n", encoding="ascii") - (path / "src/pyamplicol/_profiling_campaign/result_tables.py").write_text( - f"# {marker} policy entrypoint\n", - encoding="ascii", - ) - (path / "tools/performance_report/legacy.py").write_text( - f"# {marker} legacy adapter\n", - encoding="ascii", - ) - subprocess.run(("git", "add", "."), cwd=path, check=True) - subprocess.run( - ("git", "commit", "-qm", "fixture"), - cwd=path, - check=True, - ) - return path - - -def test_study_contract_binds_source_wrapper_policy_and_exact_limits( - tmp_path: Path, -) -> None: - source = _git_repo(tmp_path / "source", "measured") - wrapper = _git_repo(tmp_path / "wrapper", "policy") - contract_path = tmp_path / "contract.json" - - created = write_z_table_f_study_contract( - contract_path, - source, - wrapper, - ) - loaded = load_z_table_f_study_contract( - contract_path, - source, - wrapper, - ) - - assert loaded == created - assert loaded["campaign_policy"] == ( - MACBOOK_M3_Z_TABLE_F_POLICY.as_manifest() - ) - assert loaded["campaign_policy"] != MACBOOK_M3_POLICY.as_manifest() - assert loaded["policy_profile"] == "macbook_M3" - assert set(loaded["policy_wrapper"]) == { - "revision", - "tree", - "policy_entrypoint", - "policy_entrypoint_sha256", - "legacy_adapter", - "legacy_adapter_sha256", - } - assert loaded["policy_wrapper"]["policy_entrypoint"] == ( - "src/pyamplicol/_profiling_campaign/result_tables.py" - ) - assert loaded["policy_wrapper"]["legacy_adapter"] == ( - "tools/performance_report/legacy.py" - ) - assert loaded["memory_guard"] == { - "metric_abi": "pyamplicol-process-tree-memory-metric-v1", - "metric": ( - "max(aggregate-process-tree-rss," - "darwin-physical-footprint)" - ), - "limit_bytes": 30_000_000_000, - } - assert loaded["generation_guard"] == { - "evidence_abi": ( - "pyamplicol-report-generation-phase-evidence-v1" - ), - "limit_seconds": 3600.0, - "scope": ( - "every legacy, selected-flow, and all-flow generation" - ), - } - assert loaded["allowed_cell_ids"] == list(z_table_f_cell_ids()) - assert len(loaded["allowed_cell_ids"]) == 32 - retained = loaded["retained_prior_evidence"] - assert isinstance(retained, dict) - assert retained["n_final"] == list(range(1, 8)) - assert retained["treatment"] == ( - "outside this contract; retain each original attempt, " - "provenance record, and resource ABI unchanged" - ) - assert retained["memory_guard_interpretation"] == ( - "legacy RSS-only evidence remains legacy and is not " - "relabeled as Darwin physical-footprint or exact-decimal-" - "30GB evidence" - ) - snapshot = retained["snapshot"] - assert isinstance(snapshot, dict) - prior_cell_ids = z_table_f_prior_cell_ids() - static_na_cell_ids = tuple( - cell_id - for cell_id in prior_cell_ids - if REPORT_CATALOG.static_na_reason( - REPORT_CATALOG.cell(cell_id) - ) - is not None - ) - assert snapshot == { - "abi": Z_TABLE_F_PRIOR_EVIDENCE_ABI, - "maximum_n_final": 7, - "cell_ids": list(prior_cell_ids), - "static_na_cell_ids": list(static_na_cell_ids), - "declared_cell_count": Z_TABLE_F_PRIOR_CELL_COUNT, - "static_na_cell_count": Z_TABLE_F_PRIOR_STATIC_NA_CELL_COUNT, - "current_cell_count": 0, - "snapshot_sha256": snapshot["snapshot_sha256"], - } - assert len(str(snapshot["snapshot_sha256"])) == 64 - - -def test_study_contract_replays_after_wrapper_path_relocation( - tmp_path: Path, -) -> None: - source = _git_repo(tmp_path / "source", "measured") - wrapper = _git_repo(tmp_path / "wrapper", "policy") - contract_path = tmp_path / "contract.json" - created = write_z_table_f_study_contract( - contract_path, - source, - wrapper, - ) - relocated = tmp_path / "relocated-wrapper" - shutil.move(wrapper, relocated) - - loaded = load_z_table_f_study_contract( - contract_path, - source, - relocated, - ) - - assert loaded == created - - -def test_study_contract_rejects_tamper_wrapper_drift_and_broad_cell( - tmp_path: Path, -) -> None: - source = _git_repo(tmp_path / "source", "measured") - wrapper = _git_repo(tmp_path / "wrapper", "policy") - contract_path = tmp_path / "contract.json" - contract = write_z_table_f_study_contract( - contract_path, - source, - wrapper, - ) - allowed = contract["allowed_cell_ids"] - assert isinstance(allowed, list) - require_z_table_f_explicit_cell(contract, str(allowed[0])) - with pytest.raises(StudyContractError, match="outside"): - require_z_table_f_explicit_cell( - contract, - "matrix-compiled-builtin-sm-lc-n1-dd-z-jets-contracted", - ) - - raw = json.loads(contract_path.read_text(encoding="ascii")) - raw["memory_guard"]["limit_bytes"] = 30 * 1024**3 - contract_path.write_text( - json.dumps(raw, sort_keys=True), - encoding="ascii", - ) - with pytest.raises(StudyContractError, match="digest"): - load_z_table_f_study_contract(contract_path, source, wrapper) - - contract_path.unlink() - write_z_table_f_study_contract(contract_path, source, wrapper) - (wrapper / "README.md").write_text("changed\n", encoding="ascii") - with pytest.raises(StudyContractError, match="clean"): - load_z_table_f_study_contract(contract_path, source, wrapper) - - -def test_study_contract_freezes_only_prior_z_table_current_provenance( - tmp_path: Path, -) -> None: - source = _git_repo(tmp_path / "source", "measured") - wrapper = _git_repo(tmp_path / "wrapper", "policy") - service = ReportService( - ReportPaths.from_repo( - source, - docs_dir=tmp_path / "docs", - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - prior_cell = REPORT_CATALOG.cell( - "reference-amplicol-lc-n1-dd-z-jets-selected-flow" - ) - unrelated_cell = REPORT_CATALOG.cell( - "scalar-contact-n2-scalar-contact-contracted" - ) - original = { - "status": "ok", - "provenance": {"origin": "pre-study"}, - } - current = service.store.new_attempt( - prior_cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(original) - unrelated_current = service.store.new_attempt( - unrelated_cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish( - { - "status": "ok", - "provenance": {"origin": "unrelated-pre-study"}, - } - ) - contract_path = tmp_path / "contract.json" - contract = write_z_table_f_study_contract( - contract_path, - source, - wrapper, - prior_store=service.store, - ) - assert ( - load_z_table_f_study_contract( - contract_path, - source, - wrapper, - prior_store=service.store, - ) - == contract - ) - - service.store.new_attempt( - unrelated_cell.cell_id, - ArtifactPolicy.REGENERATE, - based_on=unrelated_current, - ).publish( - { - "status": "ok", - "provenance": {"origin": "unrelated-update"}, - } - ) - assert ( - load_z_table_f_study_contract( - contract_path, - source, - wrapper, - prior_store=service.store, - ) - == contract - ) - - changed_prior = { - "status": "ok", - "provenance": {"origin": "rewritten-during-study"}, - } - service.store.new_attempt( - prior_cell.cell_id, - ArtifactPolicy.REGENERATE, - based_on=current, - ).publish(changed_prior) - - with pytest.raises( - StudyContractError, - match="retained prior evidence differs", - ): - load_z_table_f_study_contract( - contract_path, - source, - wrapper, - prior_store=service.store, - ) - with pytest.raises(StudyContractError, match="snapshot differs"): - audit_z_table_f_policy_projection( - contract, - service, - maximum_n=8, - ) - - -def test_study_audit_replays_f_policy_without_ordinary_mac_policy( - tmp_path: Path, -) -> None: - source = _git_repo(tmp_path / "source", "measured") - wrapper = _git_repo(tmp_path / "wrapper", "policy") - contract_path = tmp_path / "contract.json" - contract = write_z_table_f_study_contract( - contract_path, - source, - wrapper, - ) - source_record = contract["measured_source"] - assert isinstance(source_record, dict) - identity = ReportSourceIdentity( - str(source_record["revision"]), - str(source_record["tree"]), - (), - ) - docs = tmp_path / "docs" - docs.mkdir() - service = ReportService( - ReportPaths.from_repo( - source, - docs_dir=docs, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "coordination", - ) - ) - service.publish(reset=True, merge_artifacts=False) - allowed = frozenset(str(value) for value in contract["allowed_cell_ids"]) - cells = tuple( - cell - for cell in service.catalog.measurement_cells() - if cell.cell_id in allowed and cell.n_final == 8 - ) - assert len(cells) == 16 - measured_cells = tuple( - cell - for cell in cells - if service.catalog.static_na_reason(cell) is None - ) - assert len(measured_cells) == 12 - phase = { - "abi": "pyamplicol-report-generation-phase-evidence-v1", - "phase_state_abi": "pyamplicol-report-worker-phase-state-v1", - "configured_timeout_seconds": 3600.0, - "supervisor_reason": "generation_timeout", - "authenticated": True, - "run_id": "study-run", - "worker_pid": 123, - "final_sequence": 1, - "final_phase": "generation", - "generation_started_monotonic_ns": 1, - "generation_finished_monotonic_ns": None, - "generation_elapsed_seconds": 3600.0, - "final_state_sha256": "4" * 64, - "error": None, - } - resources = { - "available": True, - "current_rss_bytes": 100, - "peak_rss_bytes": 100, - "child_count": 0, - "cpu_seconds": 1.0, - "wall_seconds": 3600.0, - "probe_error": None, - "memory_metric_abi": ( - "pyamplicol-process-tree-memory-metric-v1" - ), - "current_physical_footprint_bytes": 120, - "peak_physical_footprint_bytes": 120, - "current_guard_bytes": 120, - "peak_guard_bytes": 120, - "memory_limit_bytes": 30_000_000_000, - "memory_limit_reason": None, - "memory_probe_reason": None, - "generation_phase": phase, - } - worker_harness = z_table_f_worker_harness_identity(contract) - for cell in measured_cells: - result = policy_censor_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - "macbook_M3", - cell, - kind=PolicyCensorKind.GENERATION_LIMIT, - source_identity=identity, - resources=resources, - observed_generation_seconds=3600.0, - phase_evidence=phase, - ) - attach_worker_harness_identity(result, worker_harness) - bind_z_table_f_attempt(result, str(contract["sha256"])) - service.store.new_attempt( - cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(result) - service.publish() - - audited = audit_z_table_f_policy_projection( - contract, - service, - maximum_n=8, - ) - - assert audited["status"] == "ok" - assert audited["declared_cell_count"] == 16 - assert audited["static_na_cell_count"] == 4 - assert audited["policy_state_counts"] == {"generation_limit": 12} - assert audited["campaign_policy"] == ( - MACBOOK_M3_Z_TABLE_F_POLICY.as_manifest() - ) - assert audited["campaign_policy"] != MACBOOK_M3_POLICY.as_manifest() - - current = service.store.load_current(measured_cells[0].cell_id) - assert current is not None - stale_harness = json.loads( - json.dumps(current.result, allow_nan=False, sort_keys=True) - ) - stale_harness["provenance"]["worker_harness"][ - "policy_wrapper_revision" - ] = "f" * 40 - stale_current = service.store.new_attempt( - measured_cells[0].cell_id, - ArtifactPolicy.REGENERATE, - based_on=current, - ).publish(stale_harness) - service.publish() - with pytest.raises(StudyContractError, match="worker harness differs"): - audit_z_table_f_policy_projection( - contract, - service, - maximum_n=8, - ) - current = service.store.new_attempt( - measured_cells[0].cell_id, - ArtifactPolicy.REGENERATE, - based_on=stale_current, - ).publish(current.result) - service.publish() - - transplanted = json.loads( - json.dumps(current.result, allow_nan=False, sort_keys=True) - ) - transplanted["provenance"]["study_contract"][ - "study_contract_sha256" - ] = "f" * 64 - with service.store.new_attempt( - measured_cells[0].cell_id, - ArtifactPolicy.REGENERATE, - based_on=current, - ) as attempt: - attempt.publish(transplanted) - service.publish() - with pytest.raises(StudyContractError, match="not bound"): - audit_z_table_f_policy_projection( - contract, - service, - maximum_n=8, - ) diff --git a/pyamplicol/tests/unit/test_performance_report_worker.py b/pyamplicol/tests/unit/test_performance_report_worker.py deleted file mode 100644 index 9b344e0d14..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_worker.py +++ /dev/null @@ -1,728 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import errno -import json -from pathlib import Path - -import pytest - -import tools.performance_report.worker as worker_module -from tools.performance_report.agreements import ( - independent_numerical_authorities, -) -from tools.performance_report.artifacts import DiskFullError -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.measurement import load_measurement -from tools.performance_report.phase_state import ( - WorkerPhaseChannel, - WorkerPhaseReporter, - read_worker_phase_state, -) -from tools.performance_report.runner import RunnerSettings -from tools.performance_report.worker import ( - _atomic_json, - _JsonlProgressSink, - _portable_current_paths, - _selector_provider_measurement, - _source_identity, - _worker_legacy_workspace, - measure_cell, - write_cell_result, -) -from tools.performance_report.worker_harness import worker_harness_identity - - -def test_atomic_worker_result_is_canonical_and_complete(tmp_path: Path) -> None: - path = tmp_path / "attempt" / "result.json" - _atomic_json(path, {"status": "ok", "value": 1}) - - assert json.loads(path.read_text(encoding="ascii")) == { - "status": "ok", - "value": 1, - } - assert not list(path.parent.glob("*.tmp")) - - -def test_worker_materializes_portable_peer_from_canonical_current_path( - tmp_path: Path, -) -> None: - campaign = tmp_path / "manual" - state = campaign / "campaign_artifacts" - (state / "coordination").mkdir(parents=True) - worker_attempt = ( - state - / "cells/worker/attempts/11111111-1111-4111-8111-111111111111" - ) - peer_attempt = state / "cells/peer/attempts/22222222-2222-4222-8222-222222222222" - worker_attempt.mkdir(parents=True) - peer_artifact = peer_attempt / "artifact" - peer_artifact.mkdir(parents=True) - result_path = peer_attempt / "result.json" - result_path.write_text( - json.dumps( - { - "status": "ok", - "artifact": { - "path": "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/cells/peer/attempts/" - "22222222-2222-4222-8222-222222222222/artifact" - }, - } - ), - encoding="utf-8", - ) - - paths = _portable_current_paths( - repo_root=tmp_path / "source", - attempt_root=worker_attempt, - ) - - assert paths is not None - loaded = load_measurement(result_path, publication_paths=paths) - assert loaded["artifact"]["path"] == str(peer_artifact) - - -def test_atomic_worker_result_normalizes_enospc_with_target_and_free_bytes( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - path = tmp_path / "attempt" / "worker-result.json" - - def no_space(_source: object, _destination: object) -> None: - raise OSError(errno.ENOSPC, "no space left") - - monkeypatch.setattr(worker_module.os, "replace", no_space) - with pytest.raises( - DiskFullError, - match=( - r"disk full while writing .*worker-result\.json; " - r"[0-9]+ bytes available" - ), - ): - worker_module._atomic_json(path, {"status": "error"}) - - assert not path.exists() - assert not tuple(path.parent.glob(".worker-result.json.*.tmp")) - - -def test_worker_source_identity_uses_controller_values_without_git( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr( - "tools.performance_report.worker.require_eligible_report_source", - lambda _root: pytest.fail("manual source identity must not invoke Git"), - ) - - identity = _source_identity(tmp_path, "A" * 40, "b" * 40) - - assert identity.revision == "a" * 40 - assert identity.tree == "b" * 40 - assert identity.dirty_paths == () - with pytest.raises(ValueError, match="specified together"): - _source_identity(tmp_path, "a" * 40, None) - with pytest.raises(ValueError, match="revision must be"): - _source_identity(tmp_path, "not-a-revision", "b" * 40) - - -def test_jsonl_progress_sink_captures_compact_typed_events(tmp_path: Path) -> None: - from pyamplicol.reporting import ProgressEnd, ProgressStart, ProgressUpdate - - path = tmp_path / "progress.jsonl" - sink = _JsonlProgressSink(path) - sink.emit(ProgressStart("profile", "Profiling", 2, unit="samples")) - sink.emit(ProgressUpdate("profile", 1, 2, "sampled")) - sink.emit(ProgressEnd("profile", elapsed_seconds=0.25)) - - events = [ - json.loads(line) for line in path.read_text(encoding="ascii").splitlines() - ] - assert [event["event"] for event in events] == ["start", "update", "end"] - assert {event["task_id"] for event in events} == {"profile"} - assert events[0]["total"] == 2 - assert events[1]["completed"] == 1 - assert events[2]["elapsed_seconds"] == 0.25 - - -def test_every_catalog_cell_has_unique_worker_identity() -> None: - cells = REPORT_CATALOG.measurement_cells() - assert len({cell.cell_id for cell in cells}) == len(cells) - - -@pytest.mark.parametrize("mutation", ("missing", "extra")) -def test_worker_requires_exact_catalog_numerical_authority_chain( - tmp_path: Path, - mutation: str, -) -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted" - ) - canonical = tuple( - authority.cell_id for authority in independent_numerical_authorities(cell) - ) - assert canonical == ( - "matrix-recurrence-builtin-sm-full-n4-dd-tt-jets-contracted", - ) - observed = { - "missing": canonical[:-1], - "extra": (*canonical, REPORT_CATALOG.measurement_cells()[0].cell_id), - }[mutation] - - with pytest.raises(ValueError, match="canonical catalog chain"): - measure_cell( - cell.cell_id, - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=1, - expected_authority_cell_ids=observed, - ) - - -def test_no_legacy_baseline_lc_all_flow_gets_selected_flow_selector_peer() -> None: - cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-lc-n7-dd-4q-lines-all-flow" - ) - peer_id = "matrix-recurrence-builtin-sm-lc-n7-dd-4q-lines-selected-flow" - provider = { - "status": "ok", - "selector_contract": { - "selected_color_flow_ids": ["flow:1"], - "selected_color_words": [[1]], - "all_flow_helicity_ids": ["h:-1"], - "all_flow_source_helicities": [[1, -1]], - "point_digest": "a" * 64, - }, - } - - assert REPORT_CATALOG.validation_baseline_cell(cell) is None - assert ( - _selector_provider_measurement( - cell.cell_id, - {peer_id: provider}, - catalog=REPORT_CATALOG, - ) - is provider - ) - - -@pytest.mark.parametrize( - ("cell_id", "reason"), - ( - ( - "reference-amplicol-full-n6-dd-4q-lines-contracted", - "original-amplicol-open-quark-line-limit", - ), - ( - "z-builtin-sm-n7-dd-z-jets-asm-o3-selected-flow", - "user cap: native C\\+\\+/ASM generation is not attempted above n=6", - ), - ), -) -def test_worker_rejects_catalog_static_na_before_measurement( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - cell_id: str, - reason: str, -) -> None: - cell = REPORT_CATALOG.cell(cell_id) - monkeypatch.setattr( - "tools.performance_report.worker.require_eligible_report_source", - lambda _root: pytest.fail( - "source authentication must not run for catalog static N/A" - ), - ) - - with pytest.raises( - ValueError, - match=f"catalog static N/A cell.*{reason}", - ): - measure_cell( - cell.cell_id, - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=1, - ) - - -def test_worker_failure_is_structured_and_traceback_stays_in_log( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - def fail(*_args: object, **_kwargs: object) -> dict[str, object]: - raise RuntimeError("deliberate worker failure") - - monkeypatch.setattr("tools.performance_report.worker.measure_cell", fail) - result_path = tmp_path / "result.json" - log_path = tmp_path / "worker.log" - result = write_cell_result( - "cell", - result_path, - log_path=log_path, - ) - - assert result["status"] == "error" - assert result["failure"]["message"] == "deliberate worker failure" - assert json.loads(result_path.read_text(encoding="ascii"))["status"] == "error" - assert "Traceback" in log_path.read_text(encoding="utf-8") - - -def test_worker_success_carries_authenticated_split_harness( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - harness = worker_harness_identity( - study_contract_sha256="1" * 64, - policy_wrapper_revision="2" * 40, - policy_wrapper_tree="3" * 40, - policy_entrypoint_sha256="4" * 64, - legacy_adapter_sha256="5" * 64, - measured_source_revision="6" * 40, - measured_source_tree="7" * 40, - ) - monkeypatch.setattr( - "tools.performance_report.worker.measure_cell", - lambda *_args, **_kwargs: {"status": "ok", "provenance": {}}, - ) - - result = write_cell_result( - "cell", - tmp_path / "result.json", - worker_harness=harness, - ) - - assert result["provenance"]["worker_harness"] == harness - assert ( - json.loads((tmp_path / "result.json").read_text(encoding="ascii"))[ - "provenance" - ]["worker_harness"] - == harness - ) - - -def test_write_cell_result_threads_madgraph_installation_to_measurement( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - installation = tmp_path / "madgraph" - observed: list[Path | None] = [] - - def measure( - _cell_id: str, - *, - madgraph_installation: Path | None, - **_kwargs: object, - ) -> dict[str, object]: - observed.append(madgraph_installation) - return {"status": "ok", "provenance": {}} - - monkeypatch.setattr("tools.performance_report.worker.measure_cell", measure) - result = write_cell_result( - "cell", - tmp_path / "result.json", - madgraph_installation=installation, - ) - - assert result["status"] == "ok" - assert observed == [installation] - - -def test_worker_constructs_and_threads_parent_phase_reporter( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - observed: list[str] = [] - - def measure( - _cell_id: str, - *, - phase_reporter: WorkerPhaseReporter | None, - **_kwargs: object, - ) -> dict[str, object]: - assert phase_reporter is not None - state = read_worker_phase_state( - channel, - expected_pid=phase_reporter.worker_pid, - ) - observed.append(state.phase) - return {"status": "ok", "provenance": {}} - - monkeypatch.setattr("tools.performance_report.worker.measure_cell", measure) - result = write_cell_result( - "cell", - tmp_path / "result.json", - phase_state_path=channel.path, - phase_state_run_id=channel.run_id, - phase_state_authentication_key=channel.authentication_key, - ) - - assert result["status"] == "ok" - assert observed == ["pre-generation"] - - -def test_legacy_workspace_copy_lives_only_inside_supervised_worker_scope( - tmp_path: Path, -) -> None: - source = tmp_path / "original-amplicol" - source.mkdir() - (source / "source.f03").write_text("program fixture\n", encoding="ascii") - destination = tmp_path / "worker" / "legacy-workspace" - - with _worker_legacy_workspace( - repository=None, - source_repository=source, - workspace=destination, - copy_source=True, - ) as prepared: - assert prepared == destination - assert (destination / "source.f03").read_text(encoding="ascii") == ( - "program fixture\n" - ) - - assert not destination.exists() - - -def test_worker_threads_effective_stage_budgets_and_tracks_extended_phases( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - channel = WorkerPhaseChannel.create(tmp_path / "phase.json") - observed: dict[str, object] = {} - - def measure( - _cell_id: str, - *, - phase_reporter: WorkerPhaseReporter | None, - **kwargs: object, - ) -> dict[str, object]: - assert phase_reporter is not None - observed.update(kwargs) - with phase_reporter.generation(): - pass - phase_reporter.profiling_started() - observed["phase"] = read_worker_phase_state( - channel, - expected_pid=phase_reporter.worker_pid, - ).phase - return {"status": "ok", "provenance": {}} - - monkeypatch.setattr("tools.performance_report.worker.measure_cell", measure) - result = write_cell_result( - "cell", - tmp_path / "result.json", - phase_state_path=channel.path, - phase_state_run_id=channel.run_id, - phase_state_authentication_key=channel.authentication_key, - worker_wall_limit_seconds=12.0, - profiling_time_limit_seconds=5.0, - validation_time_limit_seconds=3.0, - ) - - assert result["status"] == "ok" - assert observed == { - "worker_wall_limit_seconds": 12.0, - "profiling_time_limit_seconds": 5.0, - "validation_time_limit_seconds": 3.0, - "madgraph_installation": None, - "phase": "profiling", - } - - -@pytest.mark.parametrize( - "field", - ( - "worker_wall_limit_seconds", - "profiling_time_limit_seconds", - "validation_time_limit_seconds", - ), -) -def test_worker_rejects_invalid_effective_stage_budget( - tmp_path: Path, - field: str, -) -> None: - with pytest.raises(ValueError, match=f"{field} must be finite and positive"): - measure_cell( - "does-not-need-to-exist", - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=1, - **{field: float("inf")}, - ) - - -def test_legacy_worker_threads_generation_phase_reporter_to_adapter( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = REPORT_CATALOG.cell("reference-amplicol-lc-n1-dd-z-jets-selected-flow") - events: list[str] = [] - - class Reporter: - def complete(self) -> None: - events.append("complete") - - reporter = Reporter() - observed: list[tuple[object, object, int]] = [] - - class SourceIdentity: - def provenance(self) -> dict[str, object]: - return {} - - class Adapter: - def measure(self, *_args: object, **kwargs: object) -> dict[str, object]: - events.append("adapter") - observed.append( - ( - kwargs.get("phase_reporter"), - kwargs.get("selector_provider"), - kwargs["settings"].jobs, - ) - ) - return { - "status": "ok", - "validation": {"status": "ok"}, - "provenance": {}, - } - - identity = SourceIdentity() - monkeypatch.setattr( - "tools.performance_report.worker.require_eligible_report_source", - lambda _root: identity, - ) - monkeypatch.setattr( - "tools.performance_report.legacy.LegacyMeasurementAdapter", - Adapter, - ) - monkeypatch.setattr( - "tools.performance_report.worker.attach_direct_agreements", - lambda *_args, **_kwargs: events.append("agreements"), - ) - - result = measure_cell( - cell.cell_id, - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=4, - amplicol_build_jobs=1, - phase_reporter=reporter, # type: ignore[arg-type] - legacy_repository=tmp_path / "legacy", - ) - - assert result["status"] == "ok" - assert observed == [(reporter, None, 1)] - assert events == ["adapter", "agreements", "complete"] - - -def test_legacy_all_flow_worker_passes_selected_flow_provider( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = REPORT_CATALOG.cell("reference-amplicol-lc-n1-dd-z-jets-all-flow") - provider = {"status": "ok", "selector_contract": {"fixture": True}} - observed: list[tuple[object, object]] = [] - - class SourceIdentity: - def provenance(self) -> dict[str, object]: - return {} - - class Adapter: - def measure(self, *_args: object, **kwargs: object) -> dict[str, object]: - observed.append(kwargs.get("selector_provider")) - return { - "status": "ok", - "validation": {"status": "ok"}, - "provenance": {}, - } - - identity = SourceIdentity() - monkeypatch.setattr( - "tools.performance_report.worker.require_eligible_report_source", - lambda _root: identity, - ) - monkeypatch.setattr( - "tools.performance_report.worker._selector_provider_measurement", - lambda *_args, **_kwargs: provider, - ) - monkeypatch.setattr( - "tools.performance_report.legacy.LegacyMeasurementAdapter", - Adapter, - ) - monkeypatch.setattr( - "tools.performance_report.worker.attach_direct_agreements", - lambda *_args, **_kwargs: None, - ) - - result = measure_cell( - cell.cell_id, - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=1, - legacy_repository=tmp_path / "legacy", - ) - - assert result["status"] == "ok" - assert observed == [provider] - - -def test_pyamplicol_worker_passes_all_validation_peers_to_measurement( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted" - ) - baseline = {"status": "ok", "matrix_element": 1.0} - peer = { - "status": "ok", - "matrix_element": 1.0, - "validation": { - "legacy_imode2_diagnostic": { - "authoritative_value": 1.0, - "imode2_value": 1.0, - } - }, - } - baseline_path = tmp_path / "baseline.json" - peer_path = tmp_path / "peer.json" - baseline_path.write_text(json.dumps(baseline), encoding="ascii") - peer_path.write_text(json.dumps(peer), encoding="ascii") - observed: list[object] = [] - - class SourceIdentity: - def provenance(self) -> dict[str, object]: - return {} - - def measure(*_args: object, **kwargs: object) -> dict[str, object]: - settings = kwargs.get("settings") - assert isinstance(settings, RunnerSettings) - observed.append( - ( - kwargs.get("validation_peers"), - kwargs.get("catalog"), - settings.memory_limit_bytes, - ) - ) - return { - "status": "validation_failed", - "validation": {"status": "validation_failed"}, - "provenance": {}, - } - - identity = SourceIdentity() - monkeypatch.setattr( - "tools.performance_report.worker.require_eligible_report_source", - lambda _root: identity, - ) - monkeypatch.setattr( - "tools.performance_report.worker.measure_pyamplicol_cell", - measure, - ) - monkeypatch.setattr( - "tools.performance_report.worker.attach_direct_agreements", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.worker.attach_validation_failure_precision_diagnostic", - lambda *_args, **_kwargs: None, - ) - - result = measure_cell( - cell.cell_id, - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=1, - memory_limit_bytes=15_000_000_000, - expected_authority_cell_ids=tuple( - authority.cell_id - for authority in independent_numerical_authorities(cell) - ), - selected_authority_cell_id=independent_numerical_authorities(cell)[0].cell_id, - baseline_json=baseline_path, - peer_json=(("reference-amplicol-full-n4-dd-tt-jets-contracted", peer_path),), - ) - - assert result["status"] == "validation_failed" - assert observed == [ - ( - {"reference-amplicol-full-n4-dd-tt-jets-contracted": peer}, - REPORT_CATALOG, - 15_000_000_000, - ) - ] - - -def test_z_worker_accepts_recurrence_as_baseline_and_direct_peer( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = REPORT_CATALOG.cell( - "z-builtin-sm-n1-dd-z-jets-jit-o1-selected-flow" - ) - authorities = independent_numerical_authorities(cell) - assert len(authorities) == 1 - recurrence = authorities[0] - measurement = {"status": "ok", "matrix_element": 1.0} - measurement_path = tmp_path / "recurrence.json" - measurement_path.write_text(json.dumps(measurement), encoding="ascii") - observed: list[tuple[object, object]] = [] - - class SourceIdentity: - def provenance(self) -> dict[str, object]: - return {} - - def measure(*_args: object, **kwargs: object) -> dict[str, object]: - observed.append((kwargs.get("baseline"), kwargs.get("validation_peers"))) - return { - "status": "ok", - "validation": {"status": "ok"}, - "provenance": {}, - } - - identity = SourceIdentity() - monkeypatch.setattr( - "tools.performance_report.worker.require_eligible_report_source", - lambda _root: identity, - ) - monkeypatch.setattr( - "tools.performance_report.worker.measure_pyamplicol_cell", - measure, - ) - monkeypatch.setattr( - "tools.performance_report.worker.attach_direct_agreements", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.worker.attach_validation_failure_precision_diagnostic", - lambda *_args, **_kwargs: None, - ) - - result = measure_cell( - cell.cell_id, - repo_root=tmp_path, - attempt_root=tmp_path / "attempt", - target_runtime_seconds=1.0, - batch_size=1, - worker_cores=1, - expected_authority_cell_ids=tuple( - authority.cell_id - for authority in independent_numerical_authorities(cell) - ), - selected_authority_cell_id=recurrence.cell_id, - baseline_json=measurement_path, - peer_json=((recurrence.cell_id, measurement_path),), - ) - - assert result["status"] == "ok" - assert observed == [(measurement, {recurrence.cell_id: measurement})] diff --git a/pyamplicol/tests/unit/test_performance_report_workspace.py b/pyamplicol/tests/unit/test_performance_report_workspace.py deleted file mode 100644 index 7720f9f751..0000000000 --- a/pyamplicol/tests/unit/test_performance_report_workspace.py +++ /dev/null @@ -1,891 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import multiprocessing -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report import workspace as workspace_module -from tools.performance_report.artifacts import LockTimeoutError -from tools.performance_report.campaign_policy import ( - MACBOOK_M3_POLICY, - X86_EPYC_POLICY, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.service import ( - ReportPaths, - ReportService, - validate_profile_name, -) -from tools.performance_report.source_identity import ( - inspect_report_source, - require_report_only_publication, -) -from tools.performance_report.workspace import ( - ENVIRONMENT_JSON, - ENVIRONMENT_SCHEMA, - ENVIRONMENT_TEX, - STANDALONE_BUILDER, - TABLE_FILLING_RUNBOOK, - WORKSPACE_MANIFEST, - ReportWorkspaceError, - export_profile, - initialize_profile, - record_authenticated_profile_environment, - refresh_profile_environment, - require_active_profile_environment, - require_authenticated_profile_environment, -) - - -def _seed_template(repo: Path) -> None: - docs = repo / "src/pyamplicol/_profiling_campaign" - docs.mkdir(parents=True) - (docs / "pyAmpliCol.tex").write_text( - "\\documentclass{article}\\begin{document}report\\end{document}\n", - encoding="ascii", - ) - (docs / "result_tables.py").write_text( - "#!/usr/bin/env python3\n", - encoding="ascii", - ) - ReportService(ReportPaths.from_repo(repo)).publish( - reset=True, - merge_artifacts=False, - ) - (docs / "pyAmpliCol.pdf").write_bytes(b"%PDF-1.4\n%%EOF\n") - - -def _try_report_writer_lock( - repo: str, - profile: str, - outcomes: object, -) -> None: - service = ReportService( - ReportPaths.from_repo(Path(repo), profile=profile), - ) - try: - with service.store.named_lock("report-writer", timeout=0.0): - outcomes.put("acquired") - except LockTimeoutError: - outcomes.put("timeout") - - -def test_profile_names_and_paths_are_safe_and_machine_isolated( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - mac = ReportPaths.from_repo(repo, profile="macbook_M3") - cluster = ReportPaths.from_repo(repo, profile="cluster_EPYC") - - assert mac.docs_dir == repo / "docs/performance_reports/macbook_M3" - assert mac.artifact_root == repo / ".artifacts/performance-report/macbook_M3" - assert mac.coordination_root == ( - repo / ".artifacts/performance-report-coordination/macbook_M3" - ) - assert mac.results_dir == mac.docs_dir / "results" - assert mac.artifact_root != cluster.artifact_root - assert mac.coordination_root != cluster.coordination_root - assert validate_profile_name("cluster_EPYC") == "cluster_EPYC" - - for invalid in ("", "../escape", "a..b", "/absolute", "white space"): - with pytest.raises(ValueError, match="report profile"): - ReportPaths.from_repo(repo, profile=invalid) - - -def test_initialize_profile_copies_publication_data_but_not_local_state( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - template_state = ( - repo / ".artifacts/performance-report/canonical/cells/attempt" - ) - template_state.mkdir(parents=True) - (template_state / "worker.log").write_text("private\n", encoding="ascii") - coordination = ( - repo / ".artifacts/performance-report-coordination/canonical" - ) - coordination.mkdir(parents=True, exist_ok=True) - (coordination / "writer.lock").write_text("", encoding="ascii") - - profile = initialize_profile(repo, "macbook_M3") - - assert (profile / "pyAmpliCol.tex").is_file() - assert not (profile / "pyAmpliCol.pdf").exists() - assert (profile / "result_tables.py").is_file() - assert (profile / STANDALONE_BUILDER).is_file() - environment_tex = (profile / ENVIRONMENT_TEX).read_text() - assert r"\renewcommand{\ReportProfileName}{macbook\_M3}" in environment_tex - assert r"\renewcommand{\ReportPlatformSummary}" in environment_tex - assert r"\renewcommand{\ReportToolchainSummary}" in environment_tex - assert r"\renewcommand{\ReportEditionStatement}" in environment_tex - assert "pending an authenticated post-checkpoint build" in environment_tex - assert "source checkout" not in environment_tex - environment = json.loads((profile / ENVIRONMENT_JSON).read_text()) - assert environment["schema"] == ENVIRONMENT_SCHEMA - assert environment["status"] == "pending_exact_runtime" - assert environment["source_revision"] == "pending" - assert environment["platform"] == "pending measurement-host authentication" - assert environment["machine"] == "pending measurement-host authentication" - assert "source checkout" not in environment["pyamplicol"] - assert (profile / "results/report-cache.schema.json").is_file() - assert not (profile / ".artifacts").exists() - assert not (profile / "results/.coordination").exists() - manifest = json.loads((profile / WORKSPACE_MANIFEST).read_text()) - assert manifest["profile"] == "macbook_M3" - assert manifest["campaign_policy"] == MACBOOK_M3_POLICY.as_manifest() - assert (profile / TABLE_FILLING_RUNBOOK).is_file() - assert manifest["measurement_state"] == "copied" - assert manifest["initialized_environment"]["profile"] == "macbook_M3" - assert ( - manifest["initialized_environment"]["status"] - == "pending_exact_runtime" - ) - assert manifest["environment_json"] == ENVIRONMENT_JSON - assert "result_tables.py" in manifest["tracked_content"] - assert manifest["initialized_source_identity"] == { - "schema": "pyamplicol-report-source-v1", - "revision": "unknown", - "tree": "unknown", - "clean": False, - "dirty_paths": [], - } - assert manifest["artifact_root"] == ( - ".artifacts/performance-report/macbook_M3" - ) - runbook = (profile / TABLE_FILLING_RUNBOOK).read_text(encoding="utf-8") - assert ( - "30 GB authenticated memory guard defined as max(process-tree RSS, " - "Darwin physical footprint)" - ) in runbook - assert "Legacy v2 RSS-only censor evidence remains readable" in runbook - assert "30 GB hard RSS" not in runbook - assert ReportService( - ReportPaths.from_repo(repo, profile="macbook_M3") - ).audit()["cache_render_match"] - - with pytest.raises(ReportWorkspaceError, match="already exists"): - initialize_profile(repo, "macbook_M3") - - -def test_initialize_x86_epyc_profile_binds_parallel_resource_policy( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - - profile = initialize_profile(repo, "x86_EPYC", reset_measurements=True) - manifest = json.loads((profile / WORKSPACE_MANIFEST).read_text()) - readme = (profile / "README.md").read_text(encoding="utf-8") - runbook = (profile / "TABLE_FILLING.md").read_text(encoding="utf-8") - - assert manifest["campaign_policy"] == X86_EPYC_POLICY.as_manifest() - assert manifest["campaign_policy"]["workers"] == 25 - assert manifest["campaign_policy"]["memory_limit_bytes"] == 80_000_000_000 - assert "--workers 25 --cell-cores 1" in runbook - assert "--max-ram-gb 80" in runbook - assert "25 independent workers" in runbook - assert "80 GB authenticated process-tree memory guard per worker" in runbook - assert "Legacy v2 RSS-only censor evidence remains readable" in runbook - assert "80 GB hard RSS" not in runbook - assert "`TABLE_FILLING.md` is the sole authoritative campaign procedure" in ( - readme - ) - assert "populate" not in readme - assert "export-profile x86_EPYC" in readme - - -def test_profile_readme_requires_full_audited_five_second_campaign( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - - profile = initialize_profile(repo, "macbook_M3") - readme = (profile / "README.md").read_text(encoding="utf-8") - - assert "`TABLE_FILLING.md` is the sole authoritative campaign procedure" in ( - readme - ) - assert "populate" not in readme - assert "render --compile" in readme - assert "result_tables.py audit" in readme - assert "export-profile macbook_M3" in readme - - -def test_documentation_index_links_the_four_published_report_pdfs() -> None: - docs = Path(__file__).resolve().parents[2] / "docs" - root_readme = (docs / "README.md").read_text(encoding="utf-8") - report_readme = (docs / "performance_reports/README.md").read_text( - encoding="utf-8" - ) - - assert "performance_reports/README.md" in root_readme - assert "macbook_M3_pyAmpliCol.pdf" in report_readme - assert "EPYC_pyAmpliCol.pdf" in report_readme - assert "summary_plots_final.pdf" in report_readme - assert "summary_plots_final_helicity_sum.pdf" in report_readme - assert "performance_reports/results/" not in report_readme - assert "profiling-campaign copy" in report_readme - assert "refresh-pdf" in report_readme - - -def _commit_all(repo: Path, message: str) -> str: - subprocess.run(("git", "add", "."), cwd=repo, check=True) - subprocess.run(("git", "commit", "-q", "-m", message), cwd=repo, check=True) - return subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=repo, - check=True, - capture_output=True, - text=True, - ).stdout.strip() - - -def _test_environment( - *, - platform_summary: str = "Darwin 24.0.0; arm64; Apple M3 Pro", - machine: str = "arm64", - processor: str = "Apple M3 Pro", -) -> dict[str, str]: - return { - "schema": ENVIRONMENT_SCHEMA, - "profile": "macbook_M3", - "platform": platform_summary, - "machine": machine, - "processor": processor, - "python": "3.12.6", - "python_implementation": "CPython", - "status": "authenticated", - "source_revision": "a" * 40, - "pyamplicol": "0.1.0", - "numpy": "2.1.0", - "native_target": "aarch64-apple-darwin", - "native_cpu_features": "neon", - "native_build_inputs_sha256": "b" * 64, - "native_extension_sha256": "c" * 64, - "python_package_tree_sha256": "d" * 64, - "candidate_fingerprint": "candidate-aarch64", - } - - -def _test_runtime(source_revision: str = "a" * 40) -> dict[str, object]: - return { - "package_version": "0.1.0", - "native_build_inputs_sha256": "a" * 64, - "native_extension": {"sha256": "b" * 64}, - "python_package_tree": {"sha256": "c" * 64}, - "candidate_build_identity": { - "candidate_fingerprint": "candidate-aarch64", - "source_revision": source_revision, - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": ["neon", "fp-armv8"], - }, - } - - -def test_processor_description_uses_sysctl_and_falls_back_when_denied( - monkeypatch: pytest.MonkeyPatch, -) -> None: - class Completed: - def __init__(self, returncode: int, stdout: str) -> None: - self.returncode = returncode - self.stdout = stdout - - with monkeypatch.context() as context: - context.setattr(workspace_module.platform, "system", lambda: "Darwin") - context.setattr(workspace_module.platform, "processor", lambda: "arm") - context.setattr( - workspace_module.subprocess, - "run", - lambda *_args, **_kwargs: Completed(0, "Apple M3 Pro\n"), - ) - assert workspace_module._processor_description() == "Apple M3 Pro" - - attempted: list[tuple[str, ...]] = [] - - def denied(command, **_kwargs): - attempted.append(command) - return Completed(1, "") - - with monkeypatch.context() as context: - context.setattr(workspace_module.platform, "system", lambda: "Darwin") - context.setattr(workspace_module.platform, "processor", lambda: "arm") - context.setattr(workspace_module.subprocess, "run", denied) - assert workspace_module._processor_description() == "arm" - - assert attempted == [ - ("sysctl", "-n", "machdep.cpu.brand_string"), - ("sysctl", "-n", "hw.model"), - ] - - -def test_active_runtime_accepts_only_processor_display_label_drift( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo, - check=True, - ) - initialize_profile(repo, "macbook_M3") - measured = _commit_all(repo, "Initialize measured-source scaffold") - hosts = iter( - ( - { - "schema": ENVIRONMENT_SCHEMA, - "profile": "macbook_M3", - "platform": "Darwin 24.0.0; arm64; Apple M3 Pro", - "machine": "arm64", - "processor": "Apple M3 Pro", - "python": "3.12.6", - "python_implementation": "CPython", - }, - { - "schema": ENVIRONMENT_SCHEMA, - "profile": "macbook_M3", - "platform": "Darwin 24.0.0; arm64; arm", - "machine": "arm64", - "processor": "arm", - "python": "3.12.6", - "python_implementation": "CPython", - }, - ) - ) - monkeypatch.setattr( - workspace_module, - "_host_environment_payload", - lambda _profile: next(hosts), - ) - - recorded = refresh_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - runtime_auditor=lambda _revision, _root: _test_runtime(measured), - ) - - assert recorded["processor"] == "Apple M3 Pro" - assert require_active_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - runtime_auditor=lambda _revision, _root: _test_runtime(measured), - ) == recorded - - -@pytest.mark.parametrize( - "overrides", - ( - {"platform": "Darwin 25.0.0; arm64; arm"}, - { - "platform": "Linux 6.8.0; arm64; arm", - }, - { - "platform": "Darwin 24.0.0; x86_64; arm", - "machine": "x86_64", - }, - {"python": "3.13.1"}, - {"source_revision": "e" * 40}, - {"candidate_fingerprint": "candidate-other"}, - {"native_build_inputs_sha256": "e" * 64}, - {"native_extension_sha256": "e" * 64}, - {"python_package_tree_sha256": "e" * 64}, - {"native_target": "x86_64-apple-darwin"}, - ), -) -def test_stable_environment_identity_retains_strict_runtime_fields( - overrides: dict[str, str], -) -> None: - recorded = _test_environment() - active = { - **recorded, - "platform": "Darwin 24.0.0; arm64; arm", - "processor": "arm", - **overrides, - } - - assert workspace_module._stable_environment_identity( - active - ) != workspace_module._stable_environment_identity(recorded) - - -def test_stable_environment_identity_rejects_noncanonical_processor_suffix() -> None: - environment = _test_environment( - platform_summary="Darwin 24.0.0; arm64; Apple M3 Pro", - processor="arm", - ) - - with pytest.raises( - ReportWorkspaceError, - match="does not match its processor label", - ): - workspace_module._stable_environment_identity(environment) - - -def test_stable_environment_identity_retains_linux_processor_model() -> None: - recorded = _test_environment( - platform_summary="Linux 6.8.0; x86_64; AMD EPYC 7551", - machine="x86_64", - processor="AMD EPYC 7551", - ) - active = _test_environment( - platform_summary="Linux 6.8.0; x86_64; AMD EPYC 7763", - machine="x86_64", - processor="AMD EPYC 7763", - ) - - assert workspace_module._stable_environment_identity( - active - ) != workspace_module._stable_environment_identity(recorded) - - -def test_environment_refresh_authenticates_runtime_without_dirtying_source( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo, - check=True, - ) - profile = initialize_profile(repo, "macbook_M3") - measured = _commit_all(repo, "Initialize measured-source scaffold") - observed: list[tuple[str, Path]] = [] - - def runtime_auditor(revision: str, checkout: Path) -> dict[str, object]: - observed.append((revision, checkout)) - return { - "package_version": "0.1.0", - "native_build_inputs_sha256": "a" * 64, - "native_extension": {"sha256": "b" * 64}, - "python_package_tree": {"sha256": "c" * 64}, - "candidate_build_identity": { - "candidate_fingerprint": "candidate-aarch64", - "source_revision": measured, - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": ["neon", "fp-armv8"], - }, - } - - environment = refresh_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - runtime_auditor=runtime_auditor, - ) - - assert observed == [(measured, repo.resolve())] - assert environment["status"] == "authenticated" - assert environment["source_revision"] == measured - assert environment["pyamplicol"] == "0.1.0" - assert environment["native_target"] == "aarch64-apple-darwin" - assert environment["native_cpu_features"] == "neon, fp-armv8" - assert environment["native_extension_sha256"] == "b" * 64 - assert environment["python_package_tree_sha256"] == "c" * 64 - assert environment["candidate_fingerprint"] == "candidate-aarch64" - assert "source checkout" not in json.dumps(environment) - assert require_authenticated_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - ) == environment - assert require_active_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - runtime_auditor=runtime_auditor, - ) == environment - source = inspect_report_source(repo) - assert source.eligible - assert source.revision == measured - - publication = _commit_all(repo, "Publish authenticated environment") - lineage = require_report_only_publication( - repo, - measured_revision=measured, - profile="macbook_M3", - publication_revision=publication, - ) - assert lineage.eligible - assert lineage.changed_paths == ( - "docs/performance_reports/macbook_M3/report_environment.json", - "docs/performance_reports/macbook_M3/report_environment.tex", - ) - assert (profile / ENVIRONMENT_JSON).is_file() - - -def test_explicit_environment_recorder_supports_portable_release_runtime( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - docs = tmp_path / "copied-campaign" - docs.mkdir() - monkeypatch.setattr( - workspace_module, - "_host_environment_payload", - lambda profile: { - "schema": ENVIRONMENT_SCHEMA, - "profile": profile, - "platform": "Linux 6.8.0; x86_64; AMD EPYC", - "machine": "x86_64", - "processor": "AMD EPYC", - "python": "3.12.6", - "python_implementation": "CPython", - }, - ) - - class Numpy: - __version__ = "2.1.0" - - monkeypatch.setattr( - workspace_module.importlib, - "import_module", - lambda name: Numpy() if name == "numpy" else None, - ) - runtime = _test_runtime() - runtime["candidate_build_identity"] = { - "publishable": True, - "source_revision": "a" * 40, - } - runtime["candidate_build_identity_sha256"] = "d" * 64 - - recorded = record_authenticated_profile_environment( - docs, - "copied-campaign", - expected_source_revision="a" * 40, - active_runtime=runtime, - ) - - assert recorded["status"] == "authenticated" - assert recorded["profile"] == "copied-campaign" - assert recorded["source_revision"] == "a" * 40 - assert recorded["candidate_fingerprint"] == f"release:{'d' * 64}" - assert json.loads((docs / ENVIRONMENT_JSON).read_text()) == recorded - tex = (docs / ENVIRONMENT_TEX).read_text(encoding="utf-8") - assert r"\renewcommand{\ReportProfileName}{copied-campaign}" in tex - assert "pending" not in tex - - invalid = dict(runtime) - invalid["candidate_build_identity_sha256"] = "short" - with pytest.raises(ReportWorkspaceError, match="is not SHA-256"): - record_authenticated_profile_environment( - docs, - "copied-campaign", - expected_source_revision="a" * 40, - active_runtime=invalid, - ) - assert json.loads((docs / ENVIRONMENT_JSON).read_text()) == recorded - - wrong_source = dict(runtime) - wrong_source["candidate_build_identity"] = { - "publishable": True, - "source_revision": "b" * 40, - } - with pytest.raises(ReportWorkspaceError, match="expected source revision"): - record_authenticated_profile_environment( - docs, - "copied-campaign", - expected_source_revision="a" * 40, - active_runtime=wrong_source, - ) - assert json.loads((docs / ENVIRONMENT_JSON).read_text()) == recorded - - missing_source = dict(runtime) - missing_source["candidate_build_identity"] = {"publishable": True} - with pytest.raises(ReportWorkspaceError, match="expected source revision"): - record_authenticated_profile_environment( - docs, - "copied-campaign", - expected_source_revision="a" * 40, - active_runtime=missing_source, - ) - assert json.loads((docs / ENVIRONMENT_JSON).read_text()) == recorded - - -def test_pending_or_wrong_source_environment_fails_closed( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo, - check=True, - ) - initialize_profile(repo, "macbook_M3") - measured = _commit_all(repo, "Initialize measured-source scaffold") - - with pytest.raises( - ReportWorkspaceError, - match="not authenticated for measurement source", - ): - require_authenticated_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - ) - with pytest.raises( - ReportWorkspaceError, - match="clean evaluator source checkout", - ): - refresh_profile_environment( - repo, - "macbook_M3", - expected_source_revision="b" * 40, - runtime_auditor=lambda _revision, _root: {}, - ) - - -def test_active_runtime_must_still_match_recorded_environment( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo, - check=True, - ) - initialize_profile(repo, "macbook_M3") - measured = _commit_all(repo, "Initialize measured-source scaffold") - - def runtime(version: str) -> dict[str, object]: - return { - "package_version": version, - "native_build_inputs_sha256": "a" * 64, - "native_extension": {"sha256": "b" * 64}, - "python_package_tree": {"sha256": "c" * 64}, - "candidate_build_identity": { - "candidate_fingerprint": "candidate-aarch64", - "source_revision": measured, - }, - "native_target": { - "triple": "aarch64-apple-darwin", - "cpu_features": ["neon"], - }, - } - - refresh_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - runtime_auditor=lambda _revision, _root: runtime("0.1.0"), - ) - - with pytest.raises( - ReportWorkspaceError, - match="active measurement runtime differs", - ): - require_active_profile_environment( - repo, - "macbook_M3", - expected_source_revision=measured, - runtime_auditor=lambda _revision, _root: runtime("0.2.0"), - ) - - -def test_new_cluster_profile_resets_measurements_and_drops_source_pdf( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - initialize_profile(repo, "macbook_M3") - - cluster = initialize_profile( - repo, - "cluster_EPYC", - source_profile="macbook_M3", - reset_measurements=True, - ) - result = ReportService( - ReportPaths.from_repo(repo, profile="cluster_EPYC") - ).validate() - - assert result["statuses"] == { - "not_available": len(REPORT_CATALOG.measurement_cells()) - } - assert not (cluster / "pyAmpliCol.pdf").exists() - manifest = json.loads((cluster / WORKSPACE_MANIFEST).read_text()) - assert manifest["initialized_from"].endswith("/macbook_M3") - assert manifest["measurement_state"] == "reset" - - -def test_export_profile_contains_only_fresh_publication_workspace( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - profile = initialize_profile(repo, "macbook_M3") - stale_pdf = b"%PDF-1.4\n% stale source PDF\n%%EOF\n" - fresh_pdf = b"%PDF-1.4\n% fresh exported PDF\n%%EOF\n" - (profile / "pyAmpliCol.pdf").write_bytes(stale_pdf) - local_state = ( - repo - / ".artifacts/performance-report/macbook_M3/cells/private/worker.log" - ) - local_state.parent.mkdir(parents=True) - local_state.write_text("private\n", encoding="ascii") - compiled: list[Path] = [] - - def fake_compile(report_dir: Path) -> Path: - compiled.append(report_dir) - output = report_dir / "pyAmpliCol.pdf" - output.write_bytes(fresh_pdf) - (report_dir / "pyAmpliCol.log").write_text( - "clean\n", - encoding="ascii", - ) - return output - - monkeypatch.setattr( - "tools.performance_report.workspace.compile_report", - fake_compile, - ) - - exported = export_profile( - repo, - "macbook_M3", - tmp_path / "exports/macbook_M3", - ) - - assert (exported / "pyAmpliCol.tex").is_file() - assert (exported / "pyAmpliCol.pdf").is_file() - assert (exported / "pyAmpliCol.pdf").read_bytes() == fresh_pdf - assert (profile / "pyAmpliCol.pdf").read_bytes() == stale_pdf - assert len(compiled) == 1 - assert (exported / STANDALONE_BUILDER).is_file() - assert (exported / TABLE_FILLING_RUNBOOK).is_file() - assert (exported / WORKSPACE_MANIFEST).is_file() - assert (exported / ENVIRONMENT_JSON).is_file() - assert (exported / ENVIRONMENT_TEX).is_file() - assert not (exported / ".artifacts").exists() - assert not tuple(exported.rglob("*.lock")) - assert not tuple(exported.rglob("*.log")) - - -def test_export_profile_can_omit_pdf( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - initialize_profile(repo, "macbook_M3") - - def unexpected_compile(_report_dir: Path) -> Path: - raise AssertionError("PDF compilation must be disabled") - - monkeypatch.setattr( - "tools.performance_report.workspace.compile_report", - unexpected_compile, - ) - exported = export_profile( - repo, - "macbook_M3", - tmp_path / "exports/macbook_M3", - include_pdf=False, - ) - - assert not (exported / "pyAmpliCol.pdf").exists() - - -def test_export_holds_source_writer_lock_while_copying( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - initialize_profile(repo, "macbook_M3") - original_copy = workspace_module._copy_publication_members - observed_lock = False - - def checking_copy(source: Path, destination: Path) -> None: - nonlocal observed_lock - - context = multiprocessing.get_context("fork") - outcomes = context.Queue() - process = context.Process( - target=_try_report_writer_lock, - args=( - str(repo), - "macbook_M3", - outcomes, - ), - ) - process.start() - process.join(timeout=3) - assert process.exitcode == 0 - assert outcomes.get(timeout=1) == "timeout" - observed_lock = True - original_copy(source, destination) - - monkeypatch.setattr( - workspace_module, - "_copy_publication_members", - checking_copy, - ) - export_profile( - repo, - "macbook_M3", - tmp_path / "exports/macbook_M3", - include_pdf=False, - ) - - assert observed_lock - - -def test_reset_profile_rejects_preexisting_local_artifact_state( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - _seed_template(repo) - stale = repo / ".artifacts/performance-report/macbook_M3/cells/stale" - stale.mkdir(parents=True) - (stale / "current.json").write_text("{}\n", encoding="ascii") - - with pytest.raises( - ReportWorkspaceError, - match="artifact root already contains local state", - ): - initialize_profile( - repo, - "macbook_M3", - reset_measurements=True, - ) diff --git a/pyamplicol/tests/unit/test_prepare_class_c_bridge_bootstrap.py b/pyamplicol/tests/unit/test_prepare_class_c_bridge_bootstrap.py deleted file mode 100644 index 06958fbc3e..0000000000 --- a/pyamplicol/tests/unit/test_prepare_class_c_bridge_bootstrap.py +++ /dev/null @@ -1,182 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import os -import shutil -from pathlib import Path - -from tools.developer import prepare_class_c_bridge as bootstrap - - -def _write(path: Path, data: bytes) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_bytes(data) - - -def test_bind_ancestor_runtime_reconstructs_only_staged_runtime( - tmp_path: Path, -) -> None: - live = tmp_path / "live-descendant" - ancestor = tmp_path / "ancestor" - for root in (live, ancestor): - _write(root / "pyproject.toml", b"[project]\nname='pyamplicol'\n") - _write(root / "Cargo.toml", b"[workspace]\n") - _write(root / "dependencies/contributor-lock.toml", b"[dependency]\n") - _write(root / "rust/lib.rs", b"pub fn tracked() {}\n") - _write(root / "src/pyamplicol/__init__.py", b"# tracked package\n") - - live_package = live / "src/pyamplicol" - _write(live_package / "descendant_only.py", b"raise RuntimeError\n") - extension = live_package / "_rusticol.abi3.so" - _write(extension, b"retained native extension") - for relative in ( - "_sdk/fortran/rusticol.f90", - "_sdk/include/rusticol.h", - "_sdk/lib/librusticol_capi.a", - "_sdk/link.json", - ): - _write(live_package / relative, relative.encode("ascii")) - _write( - live_package / "_sdk/metadata.json", - json.dumps({"target": "test-target"}).encode("ascii"), - ) - _write( - live_package / "assets/selftest/test-target/expected.json", - b'{"ok":true}\n', - ) - (live / "dependencies/checkouts").mkdir(parents=True) - for relative in bootstrap._IGNORED_NATIVE_INPUTS: - _write(live / relative, f"{relative}\n".encode("ascii")) - - shadow = tmp_path / "shadow" - shutil.copytree(ancestor, shadow) - for relative in bootstrap._IGNORED_NATIVE_INPUTS: - _write(shadow / relative, (live / relative).read_bytes()) - native_digest = bootstrap._native_build_inputs_digest(shadow) - extension_sha256 = hashlib.sha256(extension.read_bytes()).hexdigest() - _write( - live / ".artifacts/source-runtime/_build_info.json", - ( - json.dumps( - { - "candidate_fingerprint": "candidate-test", - "source_runtime": { - "extension_name": extension.name, - "extension_sha256": extension_sha256, - "native_build_inputs_sha256": native_digest, - }, - "version": "0.1.0.dev0+candidate.test", - }, - sort_keys=True, - ) - + "\n" - ).encode("ascii"), - ) - - identity = bootstrap._bind_ancestor_runtime(live, ancestor) - - ancestor_extension = ancestor / "src/pyamplicol" / extension.name - assert not ancestor_extension.is_symlink() - assert os.stat(ancestor_extension).st_ino == os.stat(extension).st_ino - linked_header = ancestor / "src/pyamplicol/_sdk/include/rusticol.h" - assert os.stat(linked_header).st_ino == os.stat( - live_package / "_sdk/include/rusticol.h" - ).st_ino - assert (ancestor / ".artifacts/source-runtime").is_symlink() - assert (ancestor / "dependencies/checkouts").is_symlink() - assert all( - (ancestor / path).is_symlink() - for path in bootstrap._IGNORED_NATIVE_INPUTS - ) - assert not (ancestor / "src/pyamplicol/descendant_only.py").exists() - assert bootstrap._native_build_inputs_digest(ancestor) == native_digest - assert identity == { - "candidate_fingerprint": "candidate-test", - "extension_name": extension.name, - "extension_sha256": extension_sha256, - "native_build_inputs_sha256": native_digest, - "package_version": "0.1.0.dev0+candidate.test", - "target": "test-target", - } - - -def test_bind_release_runtime_uses_release_projection_without_candidate_inputs( - tmp_path: Path, -) -> None: - live = tmp_path / "live-descendant" - ancestor = tmp_path / "ancestor" - for root in (live, ancestor): - _write(root / "pyproject.toml", b"[project]\nname='pyamplicol'\n") - _write(root / "Cargo.toml", b"[workspace]\n") - _write(root / "src/pyamplicol/__init__.py", b"# tracked package\n") - _write( - ancestor / "build_backend/native_build_identity.py", - ( - b"import hashlib\n" - b"def native_build_inputs_digest(" - b"root, *, normalize_release_cargo_lock=False):\n" - b" if not normalize_release_cargo_lock:\n" - b" raise RuntimeError('release projection required')\n" - b" return hashlib.sha256((root / 'Cargo.toml').read_bytes()).hexdigest()\n" - ), - ) - - live_package = live / "src/pyamplicol" - extension = live_package / "_rusticol.abi3.so" - _write(extension, b"release native extension") - for relative in ( - "_sdk/fortran/rusticol.f90", - "_sdk/include/rusticol.h", - "_sdk/lib/librusticol_capi.a", - "_sdk/link.json", - ): - _write(live_package / relative, relative.encode("ascii")) - _write( - live_package / "_sdk/metadata.json", - json.dumps({"target": "release-target"}).encode("ascii"), - ) - _write( - live_package / "assets/selftest/release-target/expected.json", - b'{"ok":true}\n', - ) - - native_digest = bootstrap._native_build_inputs_digest( - ancestor, - normalize_release_cargo_lock=True, - ) - extension_sha256 = hashlib.sha256(extension.read_bytes()).hexdigest() - _write( - live / ".artifacts/source-runtime/_build_info.json", - ( - json.dumps( - { - "native_build_inputs_sha256": native_digest, - "publishable": True, - "source_runtime": { - "extension_name": extension.name, - "extension_sha256": extension_sha256, - "mode": "release", - "native_build_inputs_sha256": native_digest, - }, - "version": "0.1.0", - }, - sort_keys=True, - ) - + "\n" - ).encode("ascii"), - ) - - identity = bootstrap._bind_ancestor_runtime(live, ancestor) - - assert not (ancestor / "dependencies/checkouts").exists() - assert all(not (ancestor / path).exists() for path in bootstrap._IGNORED_NATIVE_INPUTS) - assert identity == { - "candidate_fingerprint": None, - "extension_name": extension.name, - "extension_sha256": extension_sha256, - "native_build_inputs_sha256": native_digest, - "package_version": "0.1.0", - "target": "release-target", - } diff --git a/pyamplicol/tests/unit/test_profile_warmup_reporting.py b/pyamplicol/tests/unit/test_profile_warmup_reporting.py deleted file mode 100644 index 1efe119547..0000000000 --- a/pyamplicol/tests/unit/test_profile_warmup_reporting.py +++ /dev/null @@ -1,372 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Focused public-profile warm-up timing and presentation contracts.""" - -from __future__ import annotations - -from types import MappingProxyType, SimpleNamespace - -import pytest - -from pyamplicol import benchmarking -from pyamplicol.config import BenchmarkConfig -from pyamplicol.reporting.summary import render_summary -from tools.performance_report.runner import ( - CONVENTIONAL_WARMUP_FIELDS, - CONVENTIONAL_WARMUP_TIMING_SCOPE, - OTF_ACTIVE_FAMILY_COUNT_FIELDS, - OTF_COLD_WARMUP_FIELDS, - OTF_COLD_WARMUP_RUNTIME_FRESHNESS, - OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE, - OTF_COLD_WARMUP_TIMING_SCOPE, - OTF_RUNTIME_STATE_CENSUS_KIND, - OTF_RUNTIME_STATE_COUNT_FIELDS, - OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS, - OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS, - WARMUP_TIMER_SOURCE, - RunnerError, - _benchmark_measurement, -) - - -def _otf_runtime_state(*, retained: bool) -> dict[str, object]: - counts = {field: 0 for field in OTF_RUNTIME_STATE_COUNT_FIELDS} - active: dict[str, object] | None = None - if retained: - counts.update( - { - field: 1 - for field in ( - *OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS, - *OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS, - ) - } - ) - active = { - "basis": "shared-query-family-union-v1", - "scope": "active-family-union", - **{field: 1 for field in OTF_ACTIVE_FAMILY_COUNT_FIELDS}, - } - return { - "kind": OTF_RUNTIME_STATE_CENSUS_KIND, - "process_id": "otf_test", - "family_cache_policy": OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - "family_cache_limit": OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - **counts, - "active_family_union_census": active, - } - - -class _OnTheFlyRuntime: - execution_mode = "on-the-fly" - supports_profiling = False - - def __init__(self) -> None: - self.evaluate_calls: list[tuple[int, object, object, int]] = [] - self.retained = False - - @property - def physics(self) -> object: - return SimpleNamespace() - - def _on_the_fly_benchmark_context( - self, requested: tuple[str, ...] - ) -> dict[str, object]: - assert requested == () - return { - "process_id": "otf_test", - "process_expression": "d d~ > z", - "color_accuracy": "lc", - "helicity_count": 2, - "color_count": 1, - "selected_color_ids": [], - } - - def evaluate( - self, - momenta: object, - *, - helicities: object = None, - color_flows: object = None, - precision: int = 16, - ) -> tuple[complex, ...]: - batch = tuple(momenta) # type: ignore[arg-type] - self.evaluate_calls.append((len(batch), helicities, color_flows, precision)) - self.retained = True - return tuple(1.0 + 0.0j for _ in batch) - - def _on_the_fly_runtime_state_census(self) -> dict[str, object]: - return _otf_runtime_state(retained=self.retained) - - def evaluate_resolved(self, *_args: object, **_kwargs: object) -> object: - raise AssertionError("resolved evaluation is not part of profiling") - - def set_model_parameters(self, _mapping: object) -> None: - return None - - def clear(self) -> None: - return None - - def mute_warnings(self) -> None: - return None - - def unmute_warnings(self) -> None: - return None - - -def test_otf_initial_preparation_and_conventional_warmups_are_separate( - monkeypatch: pytest.MonkeyPatch, -) -> None: - clock = iter( - ( - 0.000, - 0.000, - 0.010, - 0.012, - 0.020, - 0.021, - 0.025, - 0.026, - 0.030, - 0.031, - 0.034, - 0.035, - 0.040, - 0.041, - 0.050, - 0.051, - 0.053, - 0.054, - ) - ) - monkeypatch.setattr(benchmarking.time, "perf_counter", lambda: next(clock)) - monkeypatch.setattr( - benchmarking, - "_calibrate_repetitions", - lambda *_args, **_kwargs: benchmarking._Calibration( - sample_count=1, - repetitions_per_sample=1, - target_sample_seconds=0.001, - probe_seconds=0.004, - block_count=0, - evaluation_count=0, - elapsed_seconds=0.0, - ), - ) - config = BenchmarkConfig( - target_runtime=0.001, - batch_size=3, - precision=16, - warmup_runs=2, - minimum_samples=1, - ) - runtime = _OnTheFlyRuntime() - result = benchmarking.BenchmarkBackend(config, None).run( - runtime, - points=(((1.0, 0.0, 0.0, 1.0),),), - ) - - environment = result.environment - assert environment["cold_warmup_elapsed_seconds"] == pytest.approx(0.012) - assert environment["cold_warmup_run_count"] == 1 - assert environment["cold_warmup_batch_size"] == 3 - assert environment["cold_warmup_point_count"] == 3 - assert environment["cold_warmup_runtime_freshness"] == ( - OTF_COLD_WARMUP_RUNTIME_FRESHNESS - ) - assert environment["cold_warmup_runtime_state_evidence"] == ( - OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - ) - assert environment["cold_warmup_runtime_cold_before_first_evaluation"] is True - assert environment["cold_warmup_runtime_retained_before_first_evaluation"] is False - assert environment["cold_warmup_runtime_retained_after_first_evaluation"] is True - assert environment["cold_warmup_ratio_eligible"] is False - assert environment["cold_warmup_acceptance_eligible"] is False - assert environment["cold_warmup_timer_source"] == WARMUP_TIMER_SOURCE - assert environment["cold_warmup_timing_scope"] == OTF_COLD_WARMUP_TIMING_SCOPE - assert "Runtime/artifact load are excluded" in str( - environment["cold_warmup_timing_scope"] - ) - - assert environment["warmup_elapsed_seconds"] == pytest.approx(0.011) - assert environment["warmup_configured_run_count"] == 2 - assert environment["warmup_batch_size"] == 3 - assert environment["warmup_point_count"] == 6 - assert environment["warmup_run_outer_wall_seconds"] == pytest.approx((0.006, 0.005)) - assert environment["first_warmup_run_outer_wall_seconds"] == pytest.approx(0.006) - assert environment["warmup_timer_source"] == WARMUP_TIMER_SOURCE - assert environment["warmup_timing_scope"] == CONVENTIONAL_WARMUP_TIMING_SCOPE - assert len(runtime.evaluate_calls) == 4 - assert result.wall_time_per_point == pytest.approx(0.004 / 3.0) - assert result.evaluator_total_time_per_point == pytest.approx(0.002 / 3.0) - - rendered = render_summary(result, color=True) - assert rendered is not None - assert "OTF runtime state" in rendered - assert "authenticated native census: cold -> strictly retained" in rendered - assert "OTF family cache" in rendered - assert "last-family-only; limit 1; retained families 0 -> 1" in rendered - assert "OTF initial preparation" in rendered - assert "12 ms" in rendered - assert "runtime freshness not authenticated here" not in rendered - assert "warm-up wall (total)" in rendered - assert "11 ms" in rendered - assert "first warm-up run" in rendered - assert "6 ms" in rendered - assert "\x1b[" in rendered - - -def _complete_otf_profile_environment() -> dict[str, object]: - return { - "execution_mode": "on-the-fly", - "batch_size": 128, - "evaluator_time_raw_seconds_per_point": 8.0e-7, - "evaluator_time_status": "measured", - "evaluator_time_ratio_eligible": True, - "evaluator_time_source": "runtime_profile_core_recurrence_schedule_time", - "native_profile_points_per_sample": 128, - "timing_sample_contract": "paired-native-repeated-profile-v1", - "elapsed_seconds": 1.0, - "cold_warmup_elapsed_seconds": 4.767252833, - "cold_warmup_run_count": 1, - "cold_warmup_batch_size": 128, - "cold_warmup_point_count": 128, - "cold_warmup_timer_source": WARMUP_TIMER_SOURCE, - "cold_warmup_timing_scope": OTF_COLD_WARMUP_TIMING_SCOPE, - "cold_warmup_runtime_freshness": OTF_COLD_WARMUP_RUNTIME_FRESHNESS, - "cold_warmup_runtime_state_evidence": (OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE), - "cold_warmup_runtime_state_before": _otf_runtime_state(retained=False), - "cold_warmup_runtime_state_after": _otf_runtime_state(retained=True), - "cold_warmup_runtime_cold_before_first_evaluation": True, - "cold_warmup_runtime_retained_before_first_evaluation": False, - "cold_warmup_runtime_retained_after_first_evaluation": True, - "cold_warmup_ratio_eligible": False, - "cold_warmup_acceptance_eligible": False, - "warmup_elapsed_seconds": 0.021, - "warmup_configured_run_count": 2, - "warmup_batch_size": 128, - "warmup_point_count": 256, - "warmup_run_outer_wall_seconds": (0.010, 0.011), - "first_warmup_run_outer_wall_seconds": 0.010, - "warmup_timer_source": WARMUP_TIMER_SOURCE, - "warmup_timing_scope": CONVENTIONAL_WARMUP_TIMING_SCOPE, - } - - -def _complete_otf_benchmark() -> SimpleNamespace: - return SimpleNamespace( - uncertainty=SimpleNamespace( - standard_error=1.0e-8, - relative_standard_error=0.01, - ), - environment=_complete_otf_profile_environment(), - evaluator_time_per_point=8.0e-7, - wall_time_per_point=1.0e-6, - sample_count=5, - effective_config=SimpleNamespace( - target_runtime=1.0, - batch_size=128, - warmup_runs=2, - ), - ) - - -def test_campaign_preserves_complete_cold_and_conventional_warmup_evidence() -> None: - measurement = _benchmark_measurement( - _complete_otf_benchmark(), - matrix_element=2.0, - ) - - evidence = measurement["benchmark_evidence"] - expected = OTF_COLD_WARMUP_FIELDS | CONVENTIONAL_WARMUP_FIELDS - assert expected <= evidence.keys() - source = _complete_otf_profile_environment() - assert {field: evidence[field] for field in expected} == { - field: source[field] for field in expected - } - - -def test_campaign_materializes_frozen_runtime_census_snapshots() -> None: - benchmark = _complete_otf_benchmark() - for field in ( - "cold_warmup_runtime_state_before", - "cold_warmup_runtime_state_after", - ): - state = dict(benchmark.environment[field]) - active = state["active_family_union_census"] - if isinstance(active, dict): - state["active_family_union_census"] = MappingProxyType(active) - benchmark.environment[field] = MappingProxyType(state) - - measurement = _benchmark_measurement(benchmark, matrix_element=2.0) - - evidence = measurement["benchmark_evidence"] - assert isinstance(evidence["cold_warmup_runtime_state_before"], dict) - assert isinstance(evidence["cold_warmup_runtime_state_after"], dict) - assert isinstance( - evidence["cold_warmup_runtime_state_after"]["active_family_union_census"], - dict, - ) - - -@pytest.mark.parametrize("execution_mode", ("compiled", "eager")) -def test_private_arena_historical_single_warmup_elapsed_remains_valid( - execution_mode: str, -) -> None: - benchmark = _complete_otf_benchmark() - benchmark.environment["execution_mode"] = execution_mode - for field in OTF_COLD_WARMUP_FIELDS | CONVENTIONAL_WARMUP_FIELDS: - benchmark.environment.pop(field, None) - benchmark.environment["warmup_elapsed_seconds"] = 0.2 - - measurement = _benchmark_measurement(benchmark, matrix_element=2.0) - - evidence = measurement["benchmark_evidence"] - assert evidence["warmup_elapsed_seconds"] == pytest.approx(0.2) - assert ( - not ( - (OTF_COLD_WARMUP_FIELDS | CONVENTIONAL_WARMUP_FIELDS) - - {"warmup_elapsed_seconds"} - ) - & evidence.keys() - ) - - -@pytest.mark.parametrize( - ("field", "replacement", "message"), - ( - ( - "cold_warmup_acceptance_eligible", - True, - "ineligible for ratios and acceptance", - ), - ("cold_warmup_point_count", 127, "full benchmark batch"), - ("warmup_point_count", 255, "configured runs times batch size"), - ("warmup_run_outer_wall_seconds", (0.010,), "configured run count"), - ("warmup_elapsed_seconds", 2.0, "does not equal its per-run"), - ("cold_warmup_timing_scope", "load included", "scope must exclude"), - ), -) -def test_campaign_rejects_semantically_invalid_otf_warmup_evidence( - field: str, - replacement: object, - message: str, -) -> None: - benchmark = _complete_otf_benchmark() - benchmark.environment[field] = replacement - - with pytest.raises(RunnerError, match=message): - _benchmark_measurement(benchmark, matrix_element=2.0) - - -@pytest.mark.parametrize( - "field", - ("cold_warmup_run_count", "warmup_timer_source"), -) -def test_campaign_rejects_incomplete_otf_warmup_evidence(field: str) -> None: - benchmark = _complete_otf_benchmark() - del benchmark.environment[field] - - with pytest.raises(RunnerError, match=r"incomplete .* warm-up evidence"): - _benchmark_measurement(benchmark, matrix_element=2.0) diff --git a/pyamplicol/tests/unit/test_qq_z6g_final_comparison.py b/pyamplicol/tests/unit/test_qq_z6g_final_comparison.py deleted file mode 100644 index 0dabf80a63..0000000000 --- a/pyamplicol/tests/unit/test_qq_z6g_final_comparison.py +++ /dev/null @@ -1,988 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import copy -import hashlib -import importlib.util -import json -import statistics -import sys -from dataclasses import asdict -from pathlib import Path -from types import ModuleType, SimpleNamespace -from typing import Any - -import pytest - -ROOT = Path(__file__).resolve().parents[2] -SCRIPT = ROOT / "tools" / "developer" / "qq_z6g_final_comparison.py" - - -def _load(name: str, path: Path) -> ModuleType: - spec = importlib.util.spec_from_file_location(name, path) - assert spec is not None and spec.loader is not None - module = importlib.util.module_from_spec(spec) - sys.modules[name] = module - spec.loader.exec_module(module) - return module - - -comparison = _load("_test_qq_z6g_final_comparison", SCRIPT) - - -def _raw_sha256(path: Path) -> str: - return hashlib.sha256(path.read_bytes()).hexdigest() - - -def _write_json(path: Path, payload: object) -> dict[str, Any]: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - return { - "path": str(path), - "size_bytes": path.stat().st_size, - "sha256": _raw_sha256(path), - } - - -def _matrix_aggregate_fixture(matrix: ModuleType) -> dict[str, Any]: - baseline = { - "source_revision": matrix.FROZEN_BASELINE_SOURCE_REVISION, - "native_build_inputs_sha256": "1" * 64, - "distribution_content_sha256": "2" * 64, - "native_module_sha256": "3" * 64, - } - current = { - "source_revision": "4" * 40, - "native_build_inputs_sha256": "5" * 64, - "distribution_content_sha256": "6" * 64, - "native_module_sha256": "7" * 64, - } - platform_record = { - "platform": "macOS-test-arm64", - "system": "Darwin", - "machine": "arm64", - "repository": { - "clean": True, - "head_revision": current["source_revision"], - }, - } - cells = [ - { - "cell_id": cell.cell_id, - "configuration": asdict(cell), - "result_content_sha256": "8" * 64, - "errors": [], - "passes": True, - } - for cell in matrix.CANONICAL_CELLS - ] - return { - "kind": matrix.RESULT_KIND, - "schema_version": matrix.SCHEMA_VERSION, - "matrix_contract": matrix.MATRIX_CONTRACT, - "matrix_definition": { - "sha256": matrix._canonical_sha256( - [ - asdict(cell) | {"cell_id": cell.cell_id} - for cell in matrix.CANONICAL_CELLS - ] - ) - }, - "expected_builds": {"baseline": baseline, "current": current}, - "complete": True, - "run_complete": True, - "passes": True, - "coverage": { - "expected": 168, - "observed": 168, - "missing": [], - "unexpected": [], - "passes": True, - }, - "cell_gate": {"passes": True}, - "identity_gate": { - "passes": True, - "distinct_sha256": {"runtime:baseline": ["9" * 64]}, - }, - "gain_gate": {"passes": True}, - "generation_gate": {"passes": True}, - "outer_provenance_gate": {"passes": True}, - "provenance": { - "preflight": platform_record, - "postflight": copy.deepcopy(platform_record), - }, - "cells": cells, - } - - -def _primary_result_fixture( - matrix: ModuleType, - cell: Any, -) -> tuple[dict[str, Any], dict[str, Any], str]: - baseline_runtime = { - "lane": "baseline", - "native_module": {"sha256": "3" * 64}, - } - current_runtime = { - "lane": "current", - "native_module": {"sha256": "7" * 64}, - } - measurements: list[dict[str, Any]] = [] - values: dict[str, list[float]] = {"baseline": [], "current": []} - for pair_index in range(1, 8): - order = ( - ("baseline", "current") - if (pair_index - 1) % 2 == 0 - else ("current", "baseline") - ) - for order_index, lane in enumerate(order, start=1): - wall = ( - 2.0e-6 + pair_index * 1.0e-8 - if lane == "baseline" - else 1.0e-6 + pair_index * 1.0e-8 - ) - values[lane].append(wall) - measurements.append( - { - "pair_index": pair_index, - "measurement_order": order_index, - "lane": lane, - "wall_seconds_per_point": wall, - "runtime_identity": ( - baseline_runtime if lane == "baseline" else current_runtime - ), - } - ) - - def distribution(raw: list[float]) -> dict[str, Any]: - median = statistics.median(raw) - return { - "sample_count": len(raw), - "samples_seconds_per_point": raw, - "median_seconds_per_point": median, - "mad_seconds_per_point": statistics.median( - abs(value - median) for value in raw - ), - "minimum_seconds_per_point": min(raw), - "maximum_seconds_per_point": max(raw), - } - - distributions = {lane: distribution(raw) for lane, raw in values.items()} - paired = matrix.regression._paired_distribution(measurements) - configuration = { - "process": cell.process, - "model_label": cell.model_kind, - "execution_mode": cell.execution_mode, - "workload": cell.workload, - "jit_optimization_level": cell.jit_optimization_level, - "color_accuracy": cell.color_accuracy, - "lc_flow_layout": cell.lc_flow_layout, - "batch_size": cell.batch_size, - "helicities": list(cell.helicities), - "color_flows": list(cell.color_flows), - "native_wall_time_source": matrix.regression.NATIVE_WALL_TIME_SOURCE, - "native_wall_time_sample_pass": ( - matrix.regression.NATIVE_WALL_TIME_SAMPLE_PASS - ), - "timing_sample_contract": matrix.regression.PAIRED_TIMING_SAMPLE_CONTRACT, - "independent_samples_per_lane": 7, - } - correctness = {"passes": True, "fixture": "recomputed"} - result = { - "kind": matrix.regression.RESULT_KIND, - "schema_version": matrix.regression.SCHEMA_VERSION, - "complete": True, - "performance_result_authoritative": True, - "passes": True, - "configuration": configuration, - "gate": {"passes": True}, - "correctness_gate": correctness, - "arena_profile_gate": {"passes": True}, - "resource_gate": {"passes": True}, - "measurements": measurements, - "pair_orders": [ - ["baseline", "current"] if index % 2 == 0 else ["current", "baseline"] - for index in range(7) - ], - "distributions": distributions, - "paired_distribution": paired, - } - baseline_runtime_sha256 = matrix._canonical_sha256( - matrix._stable_runtime_identity_value(baseline_runtime) - ) - audit = { - "configuration": asdict(cell), - "result_content_sha256": matrix._canonical_sha256(result), - "runtime_identity_sha256_by_lane": { - "baseline": baseline_runtime_sha256, - "current": matrix._canonical_sha256( - matrix._stable_runtime_identity_value(current_runtime) - ), - }, - } - return result, audit, baseline_runtime_sha256 - - -def _section_evidence() -> Any: - modes = ("compiled", "eager", "recurrence") - layouts = ("topology-replay", "all-flow-union") - source_revision = "a" * 40 - runtime = { - "interpreter": { - "implementation": "CPython", - "python_version": "3.12.6", - "sha256": "1" * 64, - }, - "native_extension": { - "sha256": "2" * 64, - "build_inputs_sha256": "3" * 64, - }, - "installed_distribution": { - "package_version": "0.1.0", - "distribution_content": { - "file_count": 10, - "size_bytes": 1024, - "sha256": "4" * 64, - }, - }, - "active_build_info": { - "payload": { - "source_revision": source_revision, - "candidate_fingerprint": "candidate-test", - } - }, - } - captures: dict[tuple[str, str], Any] = {} - for layout_index, layout in enumerate(layouts): - profiles: dict[str, Any] = {} - timings: dict[str, Any] = {} - for mode_index, mode in enumerate(modes, start=1): - raw = [ - float(mode_index + layout_index) * 1.0e-6 + index * 1.0e-9 - for index in range(7) - ] - median = statistics.median(raw) - mad = statistics.median(abs(value - median) for value in raw) - profiles[mode] = { - "validation": { - "passes": True, - "maximum_absolute_difference": 1.0e-15, - "maximum_relative_difference": 1.0e-16, - }, - "profiles": [ - { - "batch_size": 1, - "subprocess_samples": [ - { - "round": index, - "wall_seconds_per_point": value, - "interrupted": False, - } - for index, value in enumerate(raw) - ], - } - ], - } - timings[mode] = { - "1": { - "sample_count": 7, - "median_seconds_per_point": median, - "mad_seconds_per_point": mad, - "raw_seconds_per_point": raw, - } - } - comparisons = { - f"{left}__{right}": { - "passes": True, - "maximum_absolute_difference": 1.0e-15, - "maximum_relative_difference": 1.0e-16, - } - for left, right in comparison.RATIO_PAIRS - } - components = { - key: { - "passes": True, - "compared_component_count": 3, - "maximum_absolute_difference": 1.0e-15, - "maximum_relative_difference": 1.0e-16, - } - for key in comparisons - } - generation = { - mode: { - "generation_reused": False, - "generation_wall_seconds": 0.1 + mode_index * 0.01, - "artifact_stats": { - "file_count": 2, - "size_bytes": 2048, - }, - "peak_rss": {"observed_lower_bound_bytes": 4096}, - "phase_timings_seconds": { - "model-loading": 0.01, - "emission": 0.02, - }, - "artifact_semantic_identity_sha256": (str(mode_index + 4) * 64), - } - for mode_index, mode in enumerate(modes) - } - payload = { - "profiles": profiles, - "lane_comparisons": comparisons, - "validation_summary": {"resolved_component_comparisons": components}, - "generation": generation, - } - capture = SimpleNamespace( - loaded=SimpleNamespace(payload=payload), - validation_values=(1.0 + 0.0j, 2.0 + 0.0j), - timings=timings, - runtime_identity=runtime, - host={ - "platform": "macOS-test", - "system": "Darwin", - "release": "test", - "machine": "arm64", - "cpu_model": "test", - "logical_cpu_count": 8, - }, - color_axis={"count": 720}, - helicity_axis={"count": 512}, - ) - captures[("built-in-sm", layout)] = capture - captures[("ufo-sm", layout)] = copy.deepcopy(capture) - - amplicol: dict[str, Any] = {} - for role_index, role in enumerate(("selected-flow", "all-flow"), start=1): - raw = [role_index * 5.0e-6 + index * 1.0e-9 for index in range(7)] - median = statistics.median(raw) - amplicol[role] = SimpleNamespace( - values=(1.0 + 0.0j, 2.0 + 0.0j), - timing={ - "sample_count": 7, - "median_seconds_per_point": median, - "mad_seconds_per_point": statistics.median( - abs(value - median) for value in raw - ), - "raw_seconds_per_point": raw, - "timing_boundary": ( - "amplitude-evaluation" - if role == "selected-flow" - else "direct-library-total" - ), - }, - interleave_records=tuple({"round": index} for index in range(7)), - source_identity={ - "revision": "b" * 40, - "source_tree_sha256": "c" * 64, - "compiler": { - "id": "gfortran", - "version": "14", - "target": "arm64-apple-darwin", - "flags_sha256": "d" * 64, - }, - }, - ) - m0 = SimpleNamespace( - MODELS=("built-in-sm", "ufo-sm"), - LAYOUTS=layouts, - MODES=modes, - BATCHES=(1,), - MIN_SAMPLES=7, - AMPLICOL_SELECTED_ROLE="selected-flow", - AMPLICOL_UNION_ROLE="all-flow", - ATOL=1.0e-15, - RTOL=1.0e-12, - PROCESS="u u~ > z g g g g g g", - ) - return SimpleNamespace( - m0=m0, - captures=captures, - amplicol=amplicol, - expected={ - "pyamplicol_source_revision": source_revision, - "runtime_provenance_sha256": "e" * 64, - }, - ) - - -def test_default_output_and_parser_require_all_evidence_pins() -> None: - assert ( - Path(".artifacts/developer/qq-z6g-arena-comparison.md") - == comparison.DEFAULT_OUTPUT - ) - option_destinations = { - action.dest for action in comparison.parser()._actions if action.required - } - assert { - "request", - "request_sha256", - "acceptance", - "acceptance_sha256", - "expected_source_revision", - "expected_runtime_provenance_sha256", - "pre_arena_manifest", - "pre_arena_manifest_sha256", - "expected_pre_arena_source_revision", - "expected_pre_arena_build_sha256", - "expected_pre_arena_runtime_sha256", - } <= option_destinations - - -def test_decision_semantics_rejects_unknown_and_stale_content() -> None: - recomputed = { - "accepted": True, - "created_at_utc": "2026-01-01T00:00:00+00:00", - "status": "accepted", - } - body = copy.deepcopy(recomputed) - acceptance = body | {"content_sha256": comparison._canonical_sha256(body)} - fake_m0 = SimpleNamespace(_utc=lambda value, label: value) - - assert comparison._decision_semantics( - acceptance=acceptance, - recomputed=recomputed, - m0=fake_m0, - ) == {"accepted": True, "status": "accepted"} - - unknown = acceptance | {"unexpected": True} - with pytest.raises(comparison.ComparisonError, match="unknown or missing"): - comparison._decision_semantics( - acceptance=unknown, - recomputed=recomputed, - m0=fake_m0, - ) - stale = acceptance | {"accepted": False} - with pytest.raises(comparison.ComparisonError, match="digest is stale"): - comparison._decision_semantics( - acceptance=stale, - recomputed=recomputed, - m0=fake_m0, - ) - - -def test_validate_evidence_rejects_wrong_final_source_and_runtime_pins( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - request = { - "kind": "request", - "schema_version": 1, - "expected": { - "pyamplicol_source_revision": "a" * 40, - "runtime_provenance_sha256": "b" * 64, - }, - } - fake_m0 = SimpleNamespace( - _REQUEST_KEYS=set(request), - REQUEST_KIND="request", - REQUEST_SCHEMA=1, - _require_exact_keys=lambda value, keys, label: None, - _validate_expected=lambda value: value, - ) - loaded = SimpleNamespace( - payload=request, - ref=SimpleNamespace(path=tmp_path / "request.json"), - canonical_sha256="c" * 64, - ) - monkeypatch.setattr(comparison, "_load_m0", lambda: fake_m0) - monkeypatch.setattr(comparison, "_load_json_ref", lambda *args, **kwargs: loaded) - common = { - "request_path": tmp_path / "request.json", - "request_sha256": "d" * 64, - "acceptance_path": tmp_path / "acceptance.json", - "acceptance_sha256": "e" * 64, - "expected_source_revision": "a" * 40, - "expected_runtime_provenance_sha256": "b" * 64, - "pre_arena_manifest_path": tmp_path / "pre-arena.json", - "pre_arena_manifest_sha256": "f" * 64, - "expected_pre_arena_source_revision": "1" * 40, - "expected_pre_arena_build_sha256": "2" * 64, - "expected_pre_arena_runtime_sha256": "3" * 64, - } - - with pytest.raises(comparison.ComparisonError, match="final source"): - comparison.validate_evidence( - **(common | {"expected_source_revision": "4" * 40}) - ) - with pytest.raises(comparison.ComparisonError, match="runtime identity"): - comparison.validate_evidence( - **(common | {"expected_runtime_provenance_sha256": "5" * 64}) - ) - - -def test_manifest_reference_is_content_addressed_and_exact(tmp_path: Path) -> None: - target = tmp_path / "target.json" - target.write_text('{"value":1}\n', encoding="utf-8") - m0 = comparison._load_m0() - reference = { - "path": target.name, - "size_bytes": target.stat().st_size, - "sha256": _raw_sha256(target), - } - loaded = comparison._manifest_ref( - m0=m0, - value=reference, - base=tmp_path, - label="fixture", - ) - assert loaded.payload == {"value": 1} - - with pytest.raises(comparison.ComparisonError, match="unknown"): - comparison._manifest_ref( - m0=m0, - value=reference | {"canonical_sha256": "0" * 64}, - base=tmp_path, - label="fixture", - ) - with pytest.raises(comparison.ComparisonError, match="content hash drifted"): - comparison._manifest_ref( - m0=m0, - value=reference | {"sha256": "0" * 64}, - base=tmp_path, - label="fixture", - ) - - -def test_matrix_aggregate_requires_exact_aarch64_identity_pins() -> None: - matrix = comparison._load_matrix() - payload = _matrix_aggregate_fixture(matrix) - baseline = payload["expected_builds"]["baseline"] - assert isinstance(baseline, dict) - build_sha256 = comparison._canonical_sha256(baseline) - loaded = SimpleNamespace(payload=payload) - - audits, observed_baseline, current, platform_record = ( - comparison._validate_matrix_aggregate( - matrix=matrix, - loaded=loaded, - expected_pre_arena_source_revision=(matrix.FROZEN_BASELINE_SOURCE_REVISION), - expected_pre_arena_build_sha256=build_sha256, - expected_pre_arena_runtime_sha256="9" * 64, - ) - ) - assert len(audits) == 168 - assert observed_baseline == baseline - assert current["source_revision"] == "4" * 40 - assert platform_record["machine"] == "arm64" - - tampered = copy.deepcopy(payload) - tampered["provenance"]["postflight"]["machine"] = "x86_64" - with pytest.raises(comparison.ComparisonError, match="changed"): - comparison._validate_matrix_aggregate( - matrix=matrix, - loaded=SimpleNamespace(payload=tampered), - expected_pre_arena_source_revision=(matrix.FROZEN_BASELINE_SOURCE_REVISION), - expected_pre_arena_build_sha256=build_sha256, - expected_pre_arena_runtime_sha256="9" * 64, - ) - for overrides, message in ( - ( - {"expected_pre_arena_source_revision": "a" * 40}, - "frozen pre-Arena source", - ), - ( - {"expected_pre_arena_build_sha256": "a" * 64}, - "build identity", - ), - ( - {"expected_pre_arena_runtime_sha256": "a" * 64}, - "runtime identity", - ), - ): - arguments = { - "matrix": matrix, - "loaded": loaded, - "expected_pre_arena_source_revision": ( - matrix.FROZEN_BASELINE_SOURCE_REVISION - ), - "expected_pre_arena_build_sha256": build_sha256, - "expected_pre_arena_runtime_sha256": "9" * 64, - } - arguments.update(overrides) - with pytest.raises(comparison.ComparisonError, match=message): - comparison._validate_matrix_aggregate(**arguments) - - -def test_matrix_current_build_is_identical_to_final_m0_runtime() -> None: - source_revision = "a" * 40 - current = { - "source_revision": source_revision, - "native_build_inputs_sha256": "1" * 64, - "distribution_content_sha256": "2" * 64, - "native_module_sha256": "3" * 64, - } - pre_arena = SimpleNamespace(current_build=current) - capture = SimpleNamespace( - runtime_identity={ - "native_extension": { - "build_inputs_sha256": "1" * 64, - "sha256": "3" * 64, - }, - "installed_distribution": {"distribution_content": {"sha256": "2" * 64}}, - } - ) - comparison._bind_matrix_current_to_final( - pre_arena=pre_arena, - final_capture=capture, - expected_source_revision=source_revision, - ) - - mismatched = SimpleNamespace(current_build=current | {"source_revision": "b" * 40}) - with pytest.raises(comparison.ComparisonError, match="does not equal"): - comparison._bind_matrix_current_to_final( - pre_arena=mismatched, - final_capture=capture, - expected_source_revision=source_revision, - ) - - -def test_validate_pre_arena_evidence_authenticates_all_24_primary_files( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - matrix = comparison._load_matrix() - monkeypatch.setattr(comparison, "_load_matrix", lambda: matrix) - monkeypatch.setattr( - matrix.regression, - "_correctness_gate", - lambda measurements: {"passes": True, "fixture": "recomputed"}, - ) - aggregate = _matrix_aggregate_fixture(matrix) - primary_cells = { - cell.cell_id: cell - for cell in matrix.CANONICAL_CELLS - if cell.category == "primary" - } - audit_by_id = {record["cell_id"]: record for record in aggregate["cells"]} - refs: list[dict[str, Any]] = [] - runtime_sha256: str | None = None - first_result_path: Path | None = None - for cell_id, cell in sorted(primary_cells.items()): - result, audit, observed_runtime_sha256 = _primary_result_fixture( - matrix, - cell, - ) - if runtime_sha256 is None: - runtime_sha256 = observed_runtime_sha256 - assert runtime_sha256 == observed_runtime_sha256 - audit_by_id[cell_id].update(audit) - path = tmp_path / "primary" / cell_id / "result.json" - identity = _write_json(path, result) - refs.append({"cell_id": cell_id, **identity}) - first_result_path = first_result_path or path - assert runtime_sha256 is not None - aggregate["identity_gate"]["distinct_sha256"]["runtime:baseline"] = [runtime_sha256] - aggregate_identity = _write_json( - tmp_path / "matrix-result.json", - aggregate, - ) - manifest = { - "kind": comparison.PRE_ARENA_REQUEST_KIND, - "schema_version": comparison.PRE_ARENA_REQUEST_SCHEMA, - "matrix_aggregate": aggregate_identity, - "primary_results": refs, - } - manifest_path = tmp_path / "pre-arena-request.json" - manifest_identity = _write_json(manifest_path, manifest) - baseline = aggregate["expected_builds"]["baseline"] - assert isinstance(baseline, dict) - m0 = comparison._load_m0() - - evidence = comparison.validate_pre_arena_evidence( - m0=m0, - manifest_path=manifest_path, - manifest_sha256=manifest_identity["sha256"], - expected_pre_arena_source_revision=(matrix.FROZEN_BASELINE_SOURCE_REVISION), - expected_pre_arena_build_sha256=comparison._canonical_sha256(baseline), - expected_pre_arena_runtime_sha256=runtime_sha256, - ) - assert len(evidence.results) == 24 - assert len(evidence.timings) == 24 - - unknown_manifest = manifest | {"unexpected": True} - unknown_path = tmp_path / "unknown-request.json" - unknown_identity = _write_json(unknown_path, unknown_manifest) - with pytest.raises(comparison.ComparisonError, match="unknown or missing"): - comparison.validate_pre_arena_evidence( - m0=m0, - manifest_path=unknown_path, - manifest_sha256=unknown_identity["sha256"], - expected_pre_arena_source_revision=(matrix.FROZEN_BASELINE_SOURCE_REVISION), - expected_pre_arena_build_sha256=comparison._canonical_sha256(baseline), - expected_pre_arena_runtime_sha256=runtime_sha256, - ) - missing_manifest = { - key: value for key, value in manifest.items() if key != "primary_results" - } - missing_path = tmp_path / "missing-request.json" - missing_identity = _write_json(missing_path, missing_manifest) - with pytest.raises(comparison.ComparisonError, match="unknown or missing"): - comparison.validate_pre_arena_evidence( - m0=m0, - manifest_path=missing_path, - manifest_sha256=missing_identity["sha256"], - expected_pre_arena_source_revision=(matrix.FROZEN_BASELINE_SOURCE_REVISION), - expected_pre_arena_build_sha256=comparison._canonical_sha256(baseline), - expected_pre_arena_runtime_sha256=runtime_sha256, - ) - - assert first_result_path is not None - first_result_path.write_text( - first_result_path.read_text(encoding="utf-8") + " ", - encoding="utf-8", - ) - with pytest.raises(comparison.ComparisonError, match="drifted"): - comparison.validate_pre_arena_evidence( - m0=m0, - manifest_path=manifest_path, - manifest_sha256=manifest_identity["sha256"], - expected_pre_arena_source_revision=(matrix.FROZEN_BASELINE_SOURCE_REVISION), - expected_pre_arena_build_sha256=comparison._canonical_sha256(baseline), - expected_pre_arena_runtime_sha256=runtime_sha256, - ) - - -def test_primary_raw_medians_and_correctness_are_recomputed( - monkeypatch: pytest.MonkeyPatch, -) -> None: - matrix = comparison._load_matrix() - cell = next(cell for cell in matrix.CANONICAL_CELLS if cell.category == "primary") - result, audit, runtime_sha256 = _primary_result_fixture(matrix, cell) - monkeypatch.setattr( - matrix.regression, - "_correctness_gate", - lambda measurements: {"passes": True, "fixture": "recomputed"}, - ) - - distributions = comparison._matrix_result_distributions( - matrix=matrix, - cell=cell, - result=result, - audit=audit, - baseline_runtime_sha256=runtime_sha256, - ) - assert ( - distributions["baseline"]["median_seconds_per_point"] - > (distributions["current"]["median_seconds_per_point"]) - ) - - stale = copy.deepcopy(result) - stale["distributions"]["baseline"]["median_seconds_per_point"] *= 2.0 - stale_audit = copy.deepcopy(audit) - stale_audit["result_content_sha256"] = matrix._canonical_sha256(stale) - with pytest.raises(comparison.ComparisonError, match="distributions are stale"): - comparison._matrix_result_distributions( - matrix=matrix, - cell=cell, - result=stale, - audit=stale_audit, - baseline_runtime_sha256=runtime_sha256, - ) - - -def test_runtime_numerical_generation_and_amplicol_sections_use_strict_shapes() -> None: - evidence = _section_evidence() - - runtime_rows = comparison._runtime_identity_rows(evidence) - numerical = "\n".join(comparison._numerical_sections(evidence)) - generation = "\n".join(comparison._generation_sections(evidence)) - runtime = "\n".join(comparison._runtime_sections(evidence)) - original_rows = comparison._original_identity_rows(evidence) - amplicol = "\n".join(comparison._amplicol_sections(evidence)) - - assert any(row[0] == "Native extension SHA-256" for row in runtime_rows) - assert "Selected-total versus resolved-sum closure" in numerical - assert "Cross-lane resolved-component agreement" in numerical - assert "Generation peak RSS lower bound" in generation - assert "Cold artifact load time | Unavailable" in generation - assert "Same-round runtime ratios" in runtime - assert any(row[0] == "Original AmpliCol revision" for row in original_rows) - assert "Same-round original selected/union ratio" in amplicol - - broken = copy.deepcopy( - evidence.captures[("built-in-sm", "topology-replay")].loaded.payload - ) - broken["generation"]["compiled"]["artifact_stats"]["size_bytes"] = None - evidence.captures[("built-in-sm", "topology-replay")].loaded.payload = broken - with pytest.raises(comparison.ComparisonError, match="artifact size"): - comparison._generation_sections(evidence) - - -def test_generate_is_atomic_and_cli_failure_leaves_no_partial_output( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - capsys: pytest.CaptureFixture[str], -) -> None: - monkeypatch.setattr( - comparison, - "validate_evidence", - lambda **kwargs: SimpleNamespace(), - ) - monkeypatch.setattr( - comparison, - "render_markdown", - lambda evidence: "# deterministic\n", - ) - output = tmp_path / "result.md" - arguments = { - "request_path": tmp_path / "request.json", - "request_sha256": "1" * 64, - "acceptance_path": tmp_path / "acceptance.json", - "acceptance_sha256": "2" * 64, - "expected_source_revision": "3" * 40, - "expected_runtime_provenance_sha256": "4" * 64, - "pre_arena_manifest_path": tmp_path / "pre-arena.json", - "pre_arena_manifest_sha256": "5" * 64, - "expected_pre_arena_source_revision": "6" * 40, - "expected_pre_arena_build_sha256": "7" * 64, - "expected_pre_arena_runtime_sha256": "8" * 64, - "output_path": output, - } - digest = comparison.generate(**arguments) - assert output.read_text(encoding="utf-8") == "# deterministic\n" - assert digest == hashlib.sha256(b"# deterministic\n").hexdigest() - assert not list(tmp_path.glob(".result.md.*.tmp")) - - output.write_text("complete previous output\n", encoding="utf-8") - monkeypatch.setattr( - comparison, - "validate_evidence", - lambda **kwargs: comparison._die("rejected fixture"), - ) - cli = [ - "--request", - str(arguments["request_path"]), - "--request-sha256", - str(arguments["request_sha256"]), - "--acceptance", - str(arguments["acceptance_path"]), - "--acceptance-sha256", - str(arguments["acceptance_sha256"]), - "--expected-source-revision", - str(arguments["expected_source_revision"]), - "--expected-runtime-provenance-sha256", - str(arguments["expected_runtime_provenance_sha256"]), - "--pre-arena-manifest", - str(arguments["pre_arena_manifest_path"]), - "--pre-arena-manifest-sha256", - str(arguments["pre_arena_manifest_sha256"]), - "--expected-pre-arena-source-revision", - str(arguments["expected_pre_arena_source_revision"]), - "--expected-pre-arena-build-sha256", - str(arguments["expected_pre_arena_build_sha256"]), - "--expected-pre-arena-runtime-sha256", - str(arguments["expected_pre_arena_runtime_sha256"]), - "--output", - str(output), - ] - assert comparison.main(cli) == 2 - assert output.read_text(encoding="utf-8") == "complete previous output\n" - assert "qq_Z6g comparison rejected" in capsys.readouterr().err - - -def test_pre_arena_table_and_full_render_are_deterministic( - monkeypatch: pytest.MonkeyPatch, -) -> None: - timing = { - "median_seconds_per_point": 1.0e-6, - "mad_seconds_per_point": 1.0e-8, - "sample_count": 7, - "raw_seconds_per_point": [1.0e-6] * 7, - } - capture = SimpleNamespace( - host={ - "platform": "macOS-test", - "system": "Darwin", - "release": "test", - "machine": "arm64", - "cpu_model": "test", - "logical_cpu_count": 8, - }, - color_axis={"count": 720}, - helicity_axis={"count": 512}, - timings={ - "compiled": {"1": timing}, - "eager": {"1": timing | {"median_seconds_per_point": 2.0e-6}}, - }, - ) - pre_arena_timings = { - ("built-in-sm", "topology-replay", "compiled", 1): { - "baseline": { - "median_seconds_per_point": 2.0e-6, - "mad_seconds_per_point": 2.0e-8, - }, - "current": timing, - }, - ("built-in-sm", "topology-replay", "eager", 1): { - "baseline": { - "median_seconds_per_point": 4.0e-6, - "mad_seconds_per_point": 4.0e-8, - }, - "current": timing | {"median_seconds_per_point": 2.0e-6}, - }, - } - m0 = SimpleNamespace( - MODELS=("built-in-sm",), - LAYOUTS=("topology-replay",), - MODES=("compiled", "eager", "recurrence"), - BATCHES=(1,), - PROCESS="u u~ > z g g g g g g", - RTOL=1.0e-11, - ATOL=1.0e-300, - ) - evidence = SimpleNamespace( - m0=m0, - captures={("built-in-sm", "topology-replay"): capture}, - expected={ - "color_flow": {"id": "flow:test"}, - "helicity": {"id": "h:test"}, - "model_common_physics_identity_sha256": {"built-in-sm": "a" * 64}, - "generation_model_identities_sha256": {"built-in-sm": "b" * 64}, - }, - pre_arena=SimpleNamespace(timings=pre_arena_timings), - ) - baseline_section = comparison._pre_arena_comparison_sections(evidence) - assert "Final Arena / pre-Arena" in "\n".join(baseline_section) - assert "0.5x" in "\n".join(baseline_section) - - monkeypatch.setattr( - comparison, "_capture_input_rows", lambda evidence: [["x", "y", "z"]] - ) - monkeypatch.setattr( - comparison, "_runtime_identity_rows", lambda evidence: [["x", "y"]] - ) - monkeypatch.setattr( - comparison, "_pre_arena_identity_rows", lambda evidence: [["x", "y"]] - ) - monkeypatch.setattr( - comparison, "_original_identity_rows", lambda evidence: [["x", "y"]] - ) - monkeypatch.setattr( - comparison, "_numerical_sections", lambda evidence: ["## Numeric"] - ) - monkeypatch.setattr( - comparison, "_generation_sections", lambda evidence: ["## Generation"] - ) - monkeypatch.setattr( - comparison, "_runtime_sections", lambda evidence: ["## Runtime"] - ) - monkeypatch.setattr( - comparison, - "_pre_arena_comparison_sections", - lambda evidence: baseline_section, - ) - monkeypatch.setattr( - comparison, "_amplicol_sections", lambda evidence: ["## AmpliCol"] - ) - first = comparison.render_markdown(evidence) - second = comparison.render_markdown(evidence) - assert first == second - assert "# Final qq → Z + 6g Arena comparison" in first - assert "**The all-flow union evidence here is LC-only.**" in first - assert ( - hashlib.sha256(first.encode()).digest() - == hashlib.sha256(second.encode()).digest() - ) diff --git a/pyamplicol/tests/unit/test_recurrence_numerical_ab_parity.py b/pyamplicol/tests/unit/test_recurrence_numerical_ab_parity.py deleted file mode 100644 index 6f5a497f07..0000000000 --- a/pyamplicol/tests/unit/test_recurrence_numerical_ab_parity.py +++ /dev/null @@ -1,1015 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -import os -import sys -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.developer import recurrence_numerical_ab_parity as parity - -PROCESS_KEY, PROCESS_EXPRESSION = parity.PROCESS_CASES[0] - - -def test_file_identity_matches_harness_explicit_model_identity( - tmp_path: Path, -) -> None: - prepared_model = tmp_path / "model.pack" - prepared_model.write_bytes(b"prepared-model") - - assert parity._path_identity( - prepared_model.resolve() - ) == parity.harness._path_identity(prepared_model.resolve()) - - -def _selector_contract(layout: str) -> dict[str, object]: - if layout == "topology-replay": - body: dict[str, object] = { - "workload": "single-runtime-selected-flow/helicity-sum", - "physical_color_ids": ["c:1"], - "physical_helicity_ids": ["h:-1,+1", "h:+1,-1"], - "structural_zero_helicity_ids": [], - "selected_color_flow_ids": ["c:1"], - "selected_helicity_ids": [], - } - else: - body = { - "workload": "all-flows/runtime-selected-single-helicity", - "physical_color_ids": ["c:1"], - "physical_helicity_ids": ["h:-1,+1", "h:+1,-1"], - "structural_zero_helicity_ids": [], - "selected_color_flow_ids": [], - "selected_helicity_ids": ["h:-1,+1"], - } - return { - **body, - "contract_sha256": parity._canonical_sha256(body), - } - - -def _capture( - variant: str, - *, - layout: str = "topology-replay", - process_key: str = PROCESS_KEY, - process_expression: str = PROCESS_EXPRESSION, - checkout: str | None = None, - prepared_model_identity: dict[str, object] | None = None, - source_revision: str | None = None, -) -> dict[str, object]: - points = [ - [ - [50.0, 0.0, 0.0, 50.0], - [50.0, 0.0, 0.0, -50.0], - ] - ] - semantic = { - "coverage": { - "color": "complete", - "helicities": "complete", - "complete_physical_axes": True, - }, - "physical_color_flows": { - "count": 1, - "ordered_entries": [{"id": "c:1", "index": 0}], - "ordered_ids": ["c:1"], - }, - "physical_helicities": { - "count": 2, - "ordered_entries": [ - { - "id": "h:-1,+1", - "index": 0, - "structural_zero": False, - }, - { - "id": "h:+1,-1", - "index": 1, - "structural_zero": False, - }, - ], - "ordered_ids": ["h:-1,+1", "h:+1,-1"], - }, - "normalization": {"kind": "squared-matrix-element"}, - "manifest_model_identity": {"name": "built-in-sm", "sha256": "a" * 64}, - "runtime_selector_semantics": { - "color": "sum", - "helicity": "sum", - "generation_specialized_axes": [], - }, - "reduction_ordering": { - "axes": ["helicity", "color"], - "component_order": "helicity-major/color-minor", - }, - "execution_reduction_identity": {"kind": "ordered-complex-sum"}, - "execution_reduction_coverage": { - "complete": True, - "errors": [], - }, - "generation_specialized_axes": [], - } - parameter_payload = {"alpha_s": 0.118, "mu_r": 91.1876} - prepared_model = prepared_model_identity or { - "path": f"/source/{variant}/model.pack", - "size_bytes": 10, - "sha256": "a" * 64, - } - artifact_id = "c" * 64 - source_checkout = checkout or f"/source/{variant}" - revision = source_revision or parity.EXPECTED_SOURCE_REVISIONS[variant] - artifact_root = f"/artifact/{variant}" - native_identity = { - "path": f"/runtime/{variant}/_rusticol.so", - "size_bytes": 100, - "sha256": "d" * 64, - } - build_info_identity = { - "path": f"/runtime/{variant}/_build_info.json", - "size_bytes": 100, - "sha256": "e" * 64, - } - model_manifest = { - "name": "built-in-sm", - "content_sha256": "a" * 64, - } - common_model_identity = { - "name": "built-in-sm", - "content_sha256": "a" * 64, - } - - def loaded_verification(phase: str) -> dict[str, object]: - return { - "kind": "pyamplicol-loaded-runtime-artifact-verification", - "schema_version": 1, - "phase": phase, - "checked_at_utc": "2026-07-31T00:00:00Z", - "expected_artifact_id": artifact_id, - "loaded_artifact_id": artifact_id, - "passes": True, - } - - resolved_helicity_ids = ( - ["h:-1,+1", "h:+1,-1"] if layout == "topology-replay" else ["h:-1,+1"] - ) - resolved_components = ( - [[[1.0, 0.0], [2.0, 0.0]]] if layout == "topology-replay" else [[[3.0, 0.0]]] - ) - validation = { - "fixture": { - "file": { - "path": f"{artifact_root}/processes/process/validation-momenta.json", - "size_bytes": 100, - "sha256": "b" * 64, - }, - "point_count": 1, - "points_sha256": parity._canonical_sha256(points), - "points": points, - }, - "selector_contract": _selector_contract(layout), - "selected_totals": [[3.0, 0.0]], - "resolved_sums": [[3.0, 0.0]], - "resolved_helicity_ids": resolved_helicity_ids, - "resolved_color_ids": ["c:1"], - "resolved_components": resolved_components, - "point_comparisons": [ - { - "point_index": 0, - "selected_total": [3.0, 0.0], - "resolved_sum": [3.0, 0.0], - "absolute_difference": 0.0, - "relative_difference": 0.0, - "passes": True, - } - ], - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "passes": True, - } - return parity._content_address( - { - "kind": parity.CAPTURE_KIND, - "schema_version": parity.CAPTURE_SCHEMA, - "variant": variant, - "process_key": process_key, - "requested_process": process_expression, - "observed_process": process_expression.lower(), - "layout": layout, - "generation_request": parity._generation_request( - validation_samples=1, - point_tile_size=1024, - jit_optimization_level=2, - ), - "source": { - "checkout": source_checkout, - "revision": revision, - "dirty": False, - "untracked_files_checked": True, - }, - "runtime_provenance": { - "interpreter": { - "path": "/runtime/python", - "size_bytes": 100, - "sha256": "2" * 64, - "python_version": "3.12.6", - "implementation": "CPython", - }, - "installed_distribution": { - "package_version": "0.1.0", - "distribution_content": { - "algorithm": "sha256-relative-path-size-content-v1", - "file_count": 2, - "size_bytes": 200, - "sha256": "3" * 64, - }, - "native_modules": [native_identity], - "build_info_files": [build_info_identity], - }, - "active_build_info": { - **build_info_identity, - "payload": { - "source_checkout": source_checkout, - "source_revision": revision, - "native_build_inputs_sha256": "4" * 64, - }, - }, - "native_extension": { - **native_identity, - "package_version": "0.1.0", - "build_inputs_sha256": "4" * 64, - }, - "dependencies": { - "Cargo.lock": { - "present": True, - "path": f"{source_checkout}/Cargo.lock", - "resolved_path": f"{source_checkout}/Cargo.lock", - "size_bytes": 100, - "sha256": "5" * 64, - } - }, - }, - "prepared_model": prepared_model, - "generation": { - "mode": "recurrence", - "generation_reused": False, - "model_source": { - "kind": "explicit-prepared-model", - "file": prepared_model, - "compile_excluded_from_generation": True, - }, - }, - "artifact": { - "path": artifact_root, - "artifact_id": artifact_id, - "manifest": { - "path": f"{artifact_root}/artifact.json", - "size_bytes": 100, - "sha256": "6" * 64, - }, - "tree": { - "algorithm": "sha256-relative-path-size-content-v1", - "file_count": 4, - "size_bytes": 400, - "sha256": "7" * 64, - }, - "payloads": [ - { - "path": "config/effective.toml", - "role": "configuration-effective", - "process_id": None, - "size_bytes": 100, - "sha256": "8" * 64, - }, - { - "path": "model/parameters.json", - "role": "model-parameters", - "process_id": None, - "size_bytes": 100, - "sha256": "9" * 64, - }, - { - "path": "processes/process/validation-momenta.json", - "role": "validation-momenta", - "process_id": "process", - "size_bytes": 100, - "sha256": "b" * 64, - }, - ], - "process_id": "process", - "process_expression": process_expression, - "color_accuracy": "lc", - "producer": {"version": "0.1.0"}, - "model_identity": { - "manifest": model_manifest, - "manifest_sha256": parity._canonical_sha256(model_manifest), - "common_physics_identity": common_model_identity, - "common_physics_identity_sha256": parity._canonical_sha256( - common_model_identity - ), - }, - "semantic_identity": semantic, - "semantic_identity_sha256": parity._canonical_sha256(semantic), - }, - "effective_contract": { - "execution_mode": "recurrence", - "backend": "jit", - "color_accuracy": "lc", - "lc_flow_layout": layout, - "jit_optimization_level": 2, - }, - "parameters": { - "file": { - "path": f"{artifact_root}/model/parameters.json", - "size_bytes": 100, - "sha256": "9" * 64, - }, - "payload": parameter_payload, - "payload_sha256": parity._canonical_sha256(parameter_payload), - }, - "loaded_artifact_verification": { - "before_evaluation": loaded_verification( - "before-numerical-parity-evaluation" - ), - "after_evaluation": loaded_verification( - "after-numerical-parity-evaluation" - ), - }, - "validation": validation, - "tolerances": { - "absolute": parity.ABSOLUTE_TOLERANCE, - "relative": parity.RELATIVE_TOLERANCE, - }, - } - ) - - -def _readdress(capture: dict[str, object]) -> dict[str, object]: - capture.pop("content_sha256", None) - return parity._content_address(capture) - - -def _compare( - baseline: dict[str, object], - candidate: dict[str, object], - *, - layout: str = "topology-replay", -) -> dict[str, object]: - return parity._compare_captures( - baseline, - candidate, - process_key=PROCESS_KEY, - process_expression=PROCESS_EXPRESSION, - layout=layout, - ) - - -def test_acceptance_matrix_and_defaults_are_fixed() -> None: - assert parity.PROCESS_CASES == ( - ("dd_z_4g", "d d~ > Z g g g g"), - ("dd_tt_3g", "d d~ > t t~ g g g"), - ("gg_4g", "g g > g g g g"), - ) - assert parity.LAYOUTS == ("topology-replay", "all-flow-union") - assert parity.EXPECTED_SOURCE_REVISIONS == { - "baseline": "172e58fd33a3c65563866c50cfbb5e1ddcd7b302", - "candidate": "4e2b1e02dddde2d55b7250cbd52a93001f09b2c2", - } - assert parity.WATCHDOG_LIMIT_GIB == 30.0 - assert parity.ABSOLUTE_TOLERANCE == 1.0e-15 - assert parity.RELATIVE_TOLERANCE == 1.0e-12 - assert parity.DEFAULT_VALIDATION_SAMPLES == 10 - assert ( - parity._generation_request( - validation_samples=10, - point_tile_size=1024, - jit_optimization_level=2, - )["specialize_flow_at_generation"] - is False - ) - - -def test_value_comparison_uses_strict_absolute_or_relative_tolerance() -> None: - exact = parity._value_comparison([2.0, -1.0], [2.0, -1.0]) - relative = parity._value_comparison([1.0e6, 0.0], [1.0e6 + 1.0e-7, 0.0]) - failure = parity._value_comparison([1.0, 0.0], [1.0 + 1.0e-8, 0.0]) - - assert exact["passes"] is True - assert relative["absolute_difference"] > parity.ABSOLUTE_TOLERANCE - assert relative["passes"] is True - assert failure["passes"] is False - - -def test_workload_selection_is_deterministic_and_skips_structural_zeros() -> None: - physics = SimpleNamespace( - color_flows=( - SimpleNamespace(id="c:first"), - SimpleNamespace(id="c:second"), - ), - helicities=( - SimpleNamespace(id="h:zero", structural_zero=True), - SimpleNamespace(id="h:first-live", structural_zero=False), - SimpleNamespace(id="h:second-live", structural_zero=False), - ), - ) - - topology_selectors, topology_contract = parity._select_workload( - physics, - layout="topology-replay", - ) - union_selectors, union_contract = parity._select_workload( - physics, - layout="all-flow-union", - ) - - assert topology_selectors == {"color_flows": ("c:first",)} - assert topology_contract["selected_color_flow_ids"] == ["c:first"] - assert union_selectors == {"helicities": ("h:first-live",)} - assert union_contract["selected_helicity_ids"] == ["h:first-live"] - assert union_contract["structural_zero_helicity_ids"] == ["h:zero"] - for contract in (topology_contract, union_contract): - body = { - key: value for key, value in contract.items() if key != "contract_sha256" - } - assert contract["contract_sha256"] == parity._canonical_sha256(body) - - -@pytest.mark.parametrize( - ("layout", "component_count"), - (("topology-replay", 2), ("all-flow-union", 1)), -) -def test_matching_captures_emit_content_addressed_point_component_and_selector_evidence( - layout: str, - component_count: int, -) -> None: - comparison = _compare( - _capture("baseline", layout=layout), - _capture("candidate", layout=layout), - layout=layout, - ) - - assert comparison["passes"] is True - parity._validate_content_address( - comparison, - kind=parity.COMPARISON_KIND, - schema_version=parity.COMPARISON_SCHEMA, - label="comparison", - ) - assert comparison["summary"] == { - "point_count": 1, - "resolved_component_count": component_count, - "maximum_absolute_point_difference": 0.0, - "maximum_relative_point_difference": 0.0, - "maximum_absolute_component_difference": 0.0, - "maximum_relative_component_difference": 0.0, - } - records = [ - comparison["fixture_comparison"], - comparison["selector_comparison"], - comparison["parameter_comparison"], - *comparison["pointwise_comparisons"], - *comparison["resolved_component_comparisons"], - ] - assert all( - record["content_sha256"] - == parity._canonical_sha256( - {key: value for key, value in record.items() if key != "content_sha256"} - ) - for record in records - ) - observed_components = [ - (entry["point_index"], entry["helicity_id"], entry["color_id"]) - for entry in comparison["resolved_component_comparisons"] - ] - expected_components = [(0, "h:-1,+1", "c:1")] - if layout == "topology-replay": - expected_components.append((0, "h:+1,-1", "c:1")) - assert observed_components == expected_components - - -def test_point_and_resolved_component_drift_fail_independently() -> None: - def set_components( - capture: dict[str, object], - components: list[list[float]], - ) -> dict[str, object]: - validation = capture["validation"] - total = sum((complex(*component) for component in components), 0.0j) - total_payload = [total.real, total.imag] - validation["resolved_components"][0] = components - validation["selected_totals"][0] = total_payload - validation["resolved_sums"][0] = total_payload - validation["point_comparisons"][0].update( - { - "selected_total": total_payload, - "resolved_sum": total_payload, - "absolute_difference": 0.0, - "relative_difference": 0.0, - "passes": True, - } - ) - validation["maximum_absolute_difference"] = 0.0 - validation["maximum_relative_difference"] = 0.0 - validation["passes"] = True - return _readdress(capture) - - point_baseline = set_components( - _capture("baseline"), - [[1.0e9, 0.0], [-999_999_997.0, 0.0]], - ) - point_candidate = set_components( - _capture("candidate"), - [[1.0e9 + 5.0e-4, 0.0], [-999_999_997.0 + 5.0e-4, 0.0]], - ) - - point_comparison = _compare(point_baseline, point_candidate) - assert point_comparison["passes"] is False - assert point_comparison["pointwise_comparisons"][0]["passes"] is False - assert all( - entry["passes"] for entry in point_comparison["resolved_component_comparisons"] - ) - - component_baseline = set_components( - _capture("baseline"), - [[1.0e9, 0.0], [2.0, 0.0]], - ) - component_candidate = set_components( - _capture("candidate"), - [[1.0e9 - 1.0e-4, 0.0], [2.0 + 1.0e-4, 0.0]], - ) - component_comparison = _compare(component_baseline, component_candidate) - assert component_comparison["passes"] is False - assert component_comparison["pointwise_comparisons"][0]["passes"] is True - assert [ - entry["passes"] - for entry in component_comparison["resolved_component_comparisons"] - ] == [True, False] - - -def test_fixture_or_selector_drift_prevents_semantically_invalid_pairing() -> None: - baseline = _capture("baseline") - fixture_candidate = copy.deepcopy(_capture("candidate")) - fixture = fixture_candidate["validation"]["fixture"] - fixture["points"][0][0][0] = 51.0 - fixture["points_sha256"] = parity._canonical_sha256(fixture["points"]) - fixture_candidate = _readdress(fixture_candidate) - - fixture_comparison = _compare(baseline, fixture_candidate) - assert fixture_comparison["passes"] is False - assert fixture_comparison["pointwise_comparisons"] == [] - assert fixture_comparison["resolved_component_comparisons"] == [] - assert "deterministic phase-space fixtures differ" in fixture_comparison["errors"] - - selector_candidate = copy.deepcopy(_capture("candidate")) - semantic = selector_candidate["artifact"]["semantic_identity"] - semantic["physical_color_flows"]["ordered_ids"] = ["c:other"] - semantic["physical_color_flows"]["ordered_entries"][0]["id"] = "c:other" - selector_candidate["artifact"]["semantic_identity_sha256"] = ( - parity._canonical_sha256(semantic) - ) - selector = selector_candidate["validation"]["selector_contract"] - selector["physical_color_ids"] = ["c:other"] - selector["selected_color_flow_ids"] = ["c:other"] - selector_candidate["validation"]["resolved_color_ids"] = ["c:other"] - selector["contract_sha256"] = parity._canonical_sha256( - {key: value for key, value in selector.items() if key != "contract_sha256"} - ) - selector_candidate = _readdress(selector_candidate) - selector_comparison = _compare(baseline, selector_candidate) - assert selector_comparison["passes"] is False - assert selector_comparison["pointwise_comparisons"] == [] - assert selector_comparison["resolved_component_comparisons"] == [] - assert selector_comparison["selector_comparison"]["passes"] is False - - -def test_capture_digest_tampering_and_incomplete_semantics_fail_closed() -> None: - tampered = _capture("baseline") - tampered["prepared_model"]["sha256"] = "f" * 64 - with pytest.raises(parity.ParityError, match="content-address"): - parity._validate_capture( - tampered, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - incomplete = copy.deepcopy(_capture("baseline")) - semantic = incomplete["artifact"]["semantic_identity"] - semantic.pop("reduction_ordering") - incomplete["artifact"]["semantic_identity_sha256"] = parity._canonical_sha256( - semantic - ) - incomplete = _readdress(incomplete) - with pytest.raises(parity.ParityError, match="selector semantics"): - parity._validate_capture( - incomplete, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - -def test_capture_distinguishes_generation_validation_from_persisted_fixture() -> None: - capture = _capture("baseline") - capture["generation_request"]["validation_samples"] = 10 - capture = _readdress(capture) - - assert ( - parity._validate_capture( - capture, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - )["generation_request"]["validation_samples"] - == 10 - ) - - -def test_capture_rejects_invalid_generation_request_and_truncated_provenance() -> None: - invalid_request = _capture("baseline") - invalid_request["generation_request"]["validation_samples"] = 0 - invalid_request = _readdress(invalid_request) - with pytest.raises(parity.ParityError, match="capture is inconsistent"): - parity._validate_capture( - invalid_request, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - truncated = _capture("baseline") - truncated["runtime_provenance"].pop("native_extension") - truncated = _readdress(truncated) - with pytest.raises(parity.ParityError, match="runtime provenance"): - parity._validate_capture( - truncated, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - -def test_capture_rejects_flow_specialization_in_request_or_semantics() -> None: - specialized_request = _capture("baseline") - specialized_request["generation_request"]["specialize_flow_at_generation"] = True - specialized_request = _readdress(specialized_request) - with pytest.raises(parity.ParityError, match="capture is inconsistent"): - parity._validate_capture( - specialized_request, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - specialized_semantics = _capture("baseline") - semantic = specialized_semantics["artifact"]["semantic_identity"] - semantic["generation_specialized_axes"] = ["color"] - specialized_semantics["artifact"]["semantic_identity_sha256"] = ( - parity._canonical_sha256(semantic) - ) - specialized_semantics = _readdress(specialized_semantics) - with pytest.raises(parity.ParityError, match="capture is inconsistent"): - parity._validate_capture( - specialized_semantics, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - specialized_nested_semantics = _capture("baseline") - semantic = specialized_nested_semantics["artifact"]["semantic_identity"] - semantic["runtime_selector_semantics"]["generation_specialized_axes"] = ["color"] - specialized_nested_semantics["artifact"]["semantic_identity_sha256"] = ( - parity._canonical_sha256(semantic) - ) - specialized_nested_semantics = _readdress(specialized_nested_semantics) - with pytest.raises(parity.ParityError, match="capture is inconsistent"): - parity._validate_capture( - specialized_nested_semantics, - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - -def test_artifact_manifest_parameter_and_fixture_links_fail_closed() -> None: - invalid_manifest = _capture("baseline") - invalid_manifest["artifact"]["manifest"]["path"] = "/outside/artifact.json" - - invalid_parameters = _capture("baseline") - invalid_parameters["parameters"]["file"]["sha256"] = "f" * 64 - - invalid_fixture = _capture("baseline") - invalid_fixture["validation"]["fixture"]["file"]["path"] = ( - "/outside/validation-momenta.json" - ) - - for capture, message in ( - (invalid_manifest, "manifest path"), - (invalid_parameters, "parameters is not bound"), - (invalid_fixture, "fixture is not bound"), - ): - with pytest.raises(parity.ParityError, match=message): - parity._validate_capture( - _readdress(capture), - expected_variant="baseline", - expected_process_key=PROCESS_KEY, - expected_process=PROCESS_EXPRESSION, - expected_layout="topology-replay", - ) - - -def test_canonical_parameter_identity_rejects_int_float_type_drift() -> None: - baseline = _capture("baseline") - candidate = _capture("candidate") - baseline["parameters"]["payload"] = {"x": 1} - baseline["parameters"]["payload_sha256"] = parity._canonical_sha256({"x": 1}) - candidate["parameters"]["payload"] = {"x": 1.0} - candidate["parameters"]["payload_sha256"] = parity._canonical_sha256({"x": 1.0}) - - comparison = _compare( - _readdress(baseline), - _readdress(candidate), - ) - - assert comparison["passes"] is False - assert comparison["parameter_comparison"]["passes"] is False - assert "default model parameters differ" in comparison["errors"] - - -def test_source_preflight_rejects_any_revision_other_than_the_pinned_commit( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - checkout = tmp_path / "baseline" - checkout.mkdir() - variant = parity.Variant( - name="baseline", - python=tmp_path / "python", - checkout=checkout, - pythonpath=tmp_path / "site-packages", - prepared_model=tmp_path / "model.pack", - ) - - def git_stdout( - _checkout: Path, - *arguments: str, - label: str, - ) -> str: - del label - if arguments == ("rev-parse", "--show-toplevel"): - return str(checkout) - if arguments == ("rev-parse", "--verify", "HEAD"): - return parity.EXPECTED_SOURCE_REVISIONS["candidate"] - if arguments == ("status", "--porcelain=v1", "--untracked-files=all"): - return "" - raise AssertionError(arguments) - - monkeypatch.setattr(parity, "_git_stdout", git_stdout) - with pytest.raises(parity.ParityError, match="expected 172e58f"): - parity._preflight_variant_source(variant) - - -def test_variant_binding_rejects_mixed_runtime_provenance_across_workers() -> None: - capture = _capture("baseline") - variant = parity.Variant( - name="baseline", - python=Path("/runtime/python"), - checkout=Path("/source/baseline"), - pythonpath=Path("/runtime/site-packages"), - prepared_model=Path("/source/baseline/model.pack"), - ) - bindings: dict[str, dict[str, object]] = {} - parity._pin_variant_binding( - bindings, - variant=variant, - capture=capture, - expected_model=capture["prepared_model"], - expected_generation_request=capture["generation_request"], - expected_source=capture["source"], - ) - - drifted = copy.deepcopy(capture) - drifted["runtime_provenance"]["native_extension"]["package_version"] = "0.2.0" - with pytest.raises(parity.ParityError, match="changed during the campaign"): - parity._pin_variant_binding( - bindings, - variant=variant, - capture=drifted, - expected_model=drifted["prepared_model"], - expected_generation_request=drifted["generation_request"], - expected_source=drifted["source"], - ) - - -def test_workspace_python_symlink_is_retained_and_output_scope_is_fail_closed( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(parity, "DRIVER_ROOT", tmp_path.resolve()) - interpreter = tmp_path / "python" - interpreter.symlink_to(Path(sys.executable)) - assert ( - parity._resolve_python_inside_workspace(interpreter, label="test Python") - == interpreter.absolute() - ) - - allowed = tmp_path / "allowed" - allowed.mkdir() - monkeypatch.setattr(parity, "ALLOWED_OUTPUT_PARENT", allowed.resolve()) - requested = allowed / "campaign" - assert parity._resolve_output_root(requested) == requested.resolve() - with pytest.raises(parity.ParityError, match="below"): - parity._resolve_output_root(tmp_path / "escaped") - requested.mkdir() - with pytest.raises(parity.ParityError, match="already exists"): - parity._resolve_output_root(requested) - - -def test_worker_command_and_environment_isolate_all_writes_under_watchdog( - tmp_path: Path, -) -> None: - checkout = tmp_path / "checkout" - pythonpath = tmp_path / "site-packages" - prepared_model = tmp_path / "model.pack" - python = tmp_path / "python" - for directory in (checkout, pythonpath): - directory.mkdir() - for file_path in (prepared_model, python): - file_path.write_bytes(b"x") - variant = parity.Variant( - name="baseline", - python=python, - checkout=checkout, - pythonpath=pythonpath, - prepared_model=prepared_model, - ) - capture_root = tmp_path / "capture" - capture_root.mkdir() - command = parity._worker_command( - variant, - capture_root=capture_root, - process_key=PROCESS_KEY, - process_expression=PROCESS_EXPRESSION, - layout="all-flow-union", - validation_samples=10, - point_tile_size=1024, - jit_optimization_level=2, - ) - assert command[:6] == [ - str(python), - str(parity.WATCHDOG_PATH), - "--limit-gib", - "30", - "--", - str(python), - ] - assert command[command.index("--artifact") + 1] == str(capture_root / "artifact") - assert command[command.index("--capture-json") + 1] == str( - capture_root / "capture.json" - ) - - environment_root = tmp_path / "environment" - environment_root.mkdir() - environment, overrides = parity._worker_environment( - variant, - environment_root, - ) - assert overrides[parity.SOURCE_CHECKOUT_ENV] == str(checkout) - assert overrides["PYTHONPATH"] == str(pythonpath) - for key in ("TMPDIR", "XDG_CACHE_HOME", "PYTHONPYCACHEPREFIX", "MPLCONFIGDIR"): - assert Path(overrides[key]).resolve().is_relative_to(environment_root.resolve()) - assert environment[key] == overrides[key] - assert os.environ.get(parity.SOURCE_CHECKOUT_ENV) != str(checkout) - - -def test_orchestrator_runs_the_complete_matrix_with_balanced_pair_order( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - monkeypatch.setattr(parity, "ALLOWED_OUTPUT_PARENT", tmp_path.resolve()) - shared_python = tmp_path / "python" - shared_python.write_bytes(b"python") - variants: dict[str, parity.Variant] = {} - for name in ("baseline", "candidate"): - checkout = tmp_path / name / "checkout" - pythonpath = tmp_path / name / "site-packages" - prepared_model = tmp_path / name / "model.pack" - checkout.mkdir(parents=True) - pythonpath.mkdir(parents=True) - prepared_model.write_bytes(b"identical-model") - variants[name] = parity.Variant( - name=name, - python=shared_python, - checkout=checkout, - pythonpath=pythonpath, - prepared_model=prepared_model, - ) - - monkeypatch.setattr( - parity, - "_variant", - lambda name, **_values: variants[name], - ) - preflight_calls: list[str] = [] - - def preflight_source(variant: parity.Variant) -> dict[str, object]: - preflight_calls.append(variant.name) - return { - "checkout": str(variant.checkout.resolve()), - "revision": parity.EXPECTED_SOURCE_REVISIONS[variant.name], - "dirty": False, - "untracked_files_checked": True, - } - - monkeypatch.setattr(parity, "_preflight_variant_source", preflight_source) - calls: list[tuple[str, str, str]] = [] - - def capture_variant( - variant: parity.Variant, - *, - process_key: str, - process_expression: str, - layout: str, - **_values: object, - ) -> tuple[dict[str, object], dict[str, object]]: - assert preflight_calls[:2] == ["baseline", "candidate"] - calls.append((variant.name, process_key, layout)) - capture = _capture( - variant.name, - layout=layout, - process_key=process_key, - process_expression=process_expression, - checkout=str(variant.checkout.resolve()), - prepared_model_identity=parity._path_identity(variant.prepared_model), - ) - invocation = parity._content_address( - { - "kind": "test-invocation", - "schema_version": 1, - "variant": variant.name, - "process_key": process_key, - "layout": layout, - } - ) - return capture, invocation - - monkeypatch.setattr(parity, "_capture_variant", capture_variant) - arguments = SimpleNamespace( - baseline_python=shared_python, - candidate_python=shared_python, - baseline_checkout=variants["baseline"].checkout, - candidate_checkout=variants["candidate"].checkout, - baseline_pythonpath=variants["baseline"].pythonpath, - candidate_pythonpath=variants["candidate"].pythonpath, - baseline_prepared_model=variants["baseline"].prepared_model, - candidate_prepared_model=variants["candidate"].prepared_model, - output_root=tmp_path / "campaign", - validation_samples=1, - point_tile_size=1024, - jit_optimization_level=2, - worker_timeout=60.0, - ) - - result = parity.run(arguments) - - assert result["passes"] is True - assert result["comparison_count"] == 6 - assert result["passing_comparison_count"] == 6 - assert len(calls) == 12 - assert preflight_calls == ["baseline", "candidate", "baseline", "candidate"] - assert [name for name, _process, _layout in calls] == [ - "baseline", - "candidate", - "candidate", - "baseline", - "candidate", - "baseline", - "baseline", - "candidate", - "baseline", - "candidate", - "candidate", - "baseline", - ] - assert {(process_key, layout) for _name, process_key, layout in calls} == { - (process_key, layout) - for process_key, _expression in parity.PROCESS_CASES - for layout in parity.LAYOUTS - } - result_path = arguments.output_root / "result.json" - assert result_path.is_file() - parity._validate_content_address( - parity._json_object(result_path, label="result"), - kind=parity.RESULT_KIND, - schema_version=parity.RESULT_SCHEMA, - label="result", - ) diff --git a/pyamplicol/tests/unit/test_recurrence_runtime_ab_analyzer.py b/pyamplicol/tests/unit/test_recurrence_runtime_ab_analyzer.py deleted file mode 100644 index 0bde9abfc8..0000000000 --- a/pyamplicol/tests/unit/test_recurrence_runtime_ab_analyzer.py +++ /dev/null @@ -1,290 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -from collections.abc import Callable, Sequence -from typing import Any - -import pytest - -from tools.developer import recurrence_generation_ab_ladder as ladder -from tools.developer import recurrence_runtime_ab_analyzer as analyzer -from tools.developer import recurrence_z6g_benchmark as harness - - -def _runtime_peak(value: int) -> dict[str, object]: - return { - "source": "resource.getrusage", - "self_peak_bytes": value, - "maximum_child_peak_bytes": 0, - "observed_lower_bound_bytes": value, - "semantics": harness._RESOURCE_PEAK_SEMANTICS, - } - - -def _outer_sample( - *, - pair_index: int, - variant: str, - order_in_pair: int, - timing_ratios: Sequence[float], - include_runtime_rss: bool, - rss_ratio: float, -) -> dict[str, object]: - workers = [] - for round_index, ratio in enumerate(timing_ratios): - baseline_timing = 1.0e-6 * (1.0 + round_index / 100.0) - timing = baseline_timing if variant == "baseline" else baseline_timing * ratio - baseline_rss = 1_000_000_000 + round_index * 1_000_000 - rss = baseline_rss if variant == "baseline" else round(baseline_rss * rss_ratio) - worker: dict[str, object] = { - "schedule_index": round_index, - "round": round_index, - "wall_seconds_per_point": timing, - "internal_sample_count": 7, - "repetitions_per_sample": 3, - "evaluation_count": 21, - "evaluated_point_count": 21, - "interrupted": False, - "worker_wall_seconds": 5.1, - } - if include_runtime_rss: - worker["peak_rss_after_profile"] = _runtime_peak(rss) - workers.append(worker) - return { - "sample_id": f"pair-{pair_index}-{variant}", - "pair_index": pair_index, - "order_in_pair": order_in_pair, - "variant": variant, - "multiplicity": 6, - "layout": "topology-replay", - "runtime_enabled": True, - "status": "passed", - # These records must never be accepted as runtime-only memory evidence. - "watchdog": {"peak_rss": {"bytes_rounded_from_watchdog": 123}}, - "telemetry": { - "generation_peak_rss": {"observed_lower_bound_bytes": 456}, - "runtime_profile": { - "measurements": [ - { - "batch_size": 1, - "sample_count": len(workers), - "wall_seconds_per_point": 1.0e-6, - "wall_seconds_per_point_median": 1.0e-6, - "wall_seconds_per_point_mad": 0.0, - "interrupted": False, - "subprocess_samples": workers, - } - ] - }, - }, - } - - -def _campaign( - *, - pair_count: int = 1, - ratio_for_observation: Callable[[int], float] = lambda _index: 0.98, - include_runtime_rss: bool = True, - rss_ratio: float = 1.0, -) -> dict[str, object]: - samples = [] - observation_index = 0 - for pair_index in range(pair_count): - ratios = [] - for _round_index in range(7): - ratios.append(ratio_for_observation(observation_index)) - observation_index += 1 - order = ( - ("baseline", "candidate") - if pair_index % 2 == 0 - else ("candidate", "baseline") - ) - for order_in_pair, variant in enumerate(order): - samples.append( - _outer_sample( - pair_index=pair_index, - variant=variant, - order_in_pair=order_in_pair, - timing_ratios=ratios, - include_runtime_rss=include_runtime_rss, - rss_ratio=rss_ratio, - ) - ) - return { - "kind": analyzer.CAMPAIGN_KIND, - "schema_version": analyzer.CAMPAIGN_SCHEMA_VERSION, - "campaign_id": "runtime-test", - "configuration": { - "multiplicities": [6], - "layouts": ["topology-replay"], - "runtime_multiplicities": [6], - "batch_sizes": [1], - "warmup_runs": 2, - "target_runtime_seconds": 5.0, - "minimum_samples": 7, - "subprocess_samples": 7, - "ordering_policy": "alternating-baseline-candidate-pairs-v1", - "cold_cache_policy": "unique-roots-per-outer-sample-v1", - }, - "samples": samples, - } - - -def _analyze(campaign: dict[str, Any]) -> dict[str, object]: - return analyzer.analyze_campaign( - campaign, - multiplicities=(6,), - layouts=("topology-replay",), - batch_sizes=(1,), - ) - - -def test_paired_log_interval_and_seven_sample_pass_are_deterministic() -> None: - interval = analyzer.paired_log_ratio_interval([1.0] * 7, [0.98] * 7) - assert interval["sample_count"] == 7 - assert interval["candidate_over_baseline_geometric_mean"] == pytest.approx(0.98) - assert interval["candidate_over_baseline_upper_confidence_bound"] == pytest.approx( - 0.98 - ) - - result = _analyze(_campaign()) - assert result["status"] == "passed" - assert result["passes"] is True - cell = result["cells"][0] - assert cell["paired_sample_count"] == 7 - assert cell["timing"]["gate"]["status"] == "passed" - assert cell["runtime_rss"]["gate"]["status"] == "passed" - - -def test_inconclusive_seven_samples_requests_expansion_to_twenty_one() -> None: - result = _analyze( - _campaign(ratio_for_observation=lambda index: 0.99 if index % 2 == 0 else 1.01) - ) - cell = result["cells"][0] - assert result["status"] == "needs-more-samples" - assert cell["timing"]["gate"]["status"] == "needs-more-samples" - assert cell["timing"]["gate"]["additional_paired_samples_allowed"] == 14 - - -def test_inconclusive_twenty_one_samples_rejects_runtime_change() -> None: - result = _analyze( - _campaign( - pair_count=3, - ratio_for_observation=lambda index: 0.99 if index % 2 == 0 else 1.01, - ) - ) - cell = result["cells"][0] - assert result["status"] == "rejected" - assert cell["paired_sample_count"] == 21 - assert cell["timing"]["gate"]["status"] == "rejected-inconclusive" - assert cell["timing"]["gate"]["additional_paired_samples_allowed"] == 0 - - -def test_statistically_supported_slowdown_rejects_immediately() -> None: - result = _analyze(_campaign(ratio_for_observation=lambda _index: 1.02)) - cell = result["cells"][0] - assert result["status"] == "rejected" - assert cell["timing"]["gate"]["status"] == "rejected-supported-slowdown" - - -def test_runtime_rss_gate_ignores_generation_and_outer_watchdog_memory() -> None: - result = _analyze(_campaign(include_runtime_rss=False)) - cell = result["cells"][0] - assert result["status"] == "incomplete-runtime-rss" - assert cell["runtime_rss"]["interval"] is None - assert cell["runtime_rss"]["gate"]["status"] == "missing-runtime-only-rss" - - -def test_supported_material_runtime_rss_increase_rejects() -> None: - result = _analyze(_campaign(rss_ratio=1.20)) - cell = result["cells"][0] - assert result["status"] == "rejected" - assert ( - cell["runtime_rss"]["gate"]["status"] - == "rejected-supported-material-rss-increase" - ) - - -def test_outer_pair_order_must_alternate() -> None: - campaign = _campaign(pair_count=3) - samples = campaign["samples"] - assert isinstance(samples, list) - pair_one = [ - sample - for sample in samples - if isinstance(sample, dict) and sample["pair_index"] == 1 - ] - for sample in pair_one: - sample["order_in_pair"] = 0 if sample["variant"] == "baseline" else 1 - with pytest.raises(analyzer.RuntimeABError, match="did not alternate"): - _analyze(campaign) - - -def test_runtime_rss_survives_harness_aggregation_and_campaign_compaction( - monkeypatch: pytest.MonkeyPatch, -) -> None: - schedule = harness._build_profile_schedule( - ("recurrence",), - (1,), - subprocess_samples=1, - ) - semantic_identity: dict[str, object] = {"test": "identity"} - semantic_sha256 = harness._canonical_sha256(semantic_identity) - peak = _runtime_peak(1_234_567_890) - worker: dict[str, object] = { - "mode": "recurrence", - "schedule_index": 0, - "schedule_round": 0, - "process_id": "process", - "process_expression": "d d~ > Z g g g g g", - "selector_contract": {}, - "validation": {}, - "pre_timing_verification": { - "artifact_semantic_identity": semantic_identity, - "artifact_semantic_identity_sha256": semantic_sha256, - }, - "post_timing_loaded_runtime_artifact": {}, - "worker_command": {}, - "worker_invocation": {}, - "worker_process_record": {}, - "worker_result_record": {}, - "cold_load_seconds": 0.01, - "peak_rss_after_cold_load": _runtime_peak(1_000_000_000), - "peak_rss_after_profile": peak, - "timing_configuration": {}, - "profiles": [ - { - "batch_size": 1, - "sample_count": 7, - "repetitions_per_sample": 1, - "evaluation_count": 7, - "evaluated_point_count": 7, - "wall_seconds_per_point": 1.0e-6, - "inner_native_wall_blocks": {}, - "timing_sources": {}, - "environment": {}, - "interrupted": False, - } - ], - } - monkeypatch.setattr( - harness, - "_retained_profile_worker_result_record", - lambda *_args, **_kwargs: { - "addressed_payload_sha256": "a" * 64, - }, - ) - profiles = harness._aggregate_profile_workers(schedule, [worker]) - aggregated = profiles["recurrence"]["profiles"][0]["subprocess_samples"][0] - assert aggregated["peak_rss_after_profile"] == peak - - compact = ladder._runtime_profile_summary( - { - "process_id": "process", - "process_expression": "d d~ > Z g g g g g", - "profiles": profiles["recurrence"]["profiles"], - } - ) - assert compact is not None - compact_worker = compact["measurements"][0]["subprocess_samples"][0] - assert compact_worker["peak_rss_after_profile"] == peak diff --git a/pyamplicol/tests/unit/test_recurrence_semantic_census.py b/pyamplicol/tests/unit/test_recurrence_semantic_census.py deleted file mode 100644 index af2e18786a..0000000000 --- a/pyamplicol/tests/unit/test_recurrence_semantic_census.py +++ /dev/null @@ -1,415 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -from dataclasses import astuple, replace - -import pytest - -from pyamplicol.runtime.recurrence_exact._plan_v2 import ( - DIRECT_NONE_U32, - RECURRENCE_EXACT_SECTIONS_ABI, - RECURRENCE_RUNTIME_LAYOUT_V2_ABI, - _parse_exact_sections, -) -from tools.developer import recurrence_semantic_census as census - - -def _sections(): - raw = { - "abi": RECURRENCE_EXACT_SECTIONS_ABI, - "runtime_layout_abi": RECURRENCE_RUNTIME_LAYOUT_V2_ABI, - "process_id": "synthetic", - "strategy": "topology-replay", - "semantic_digest": "1" * 64, - "runtime_layout_digest": "2" * 64, - "counts": [3, 1, 0, 2], - "currents": [ - [0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 0, DIRECT_NONE_U32], - [1, 0, 1, 1, 1, 1, 0, 0, 0, 3, 1, DIRECT_NONE_U32], - [2, 1, 2, 2, 1, 2, 1, 0, 1, 3, DIRECT_NONE_U32, 0], - ], - "sources": [ - [0, 0, 0, 0, -1, 0, 0], - [1, 1, 1, 1, 1, 0, 0], - ], - "contributions": [[0, 1, 0, 1, 2, 0, 0, 0]], - "finalizations": [[2, 1, 2, 0, 0, 0]], - "closures": [[2, DIRECT_NONE_U32, 2, DIRECT_NONE_U32, 0, 0, 0, 1, 0, 0]], - "row_groups": [ - [0, 0, 0, 0, 0, 2], - [1, 1, 1, 1, 0, 1], - [1, 2, 2, 2, 0, 1], - [2, 3, 3, 3, 0, 1], - ], - "momentum_forms": [[0, 1], [1, 1], [2, 2]], - "momentum_terms": [[0, 1], [1, 1], [0, 1], [1, 1]], - "replay_targets": [[0, 0, 0, 2, 0, 1, 0, 1, 0]], - "source_permutations": [0, 1], - "replay_momentum_signs": [1, 1], - "replay_helicity_map": [0], - "amplitude_destinations": [[0, 0, 0, 0, 1, 0]], - "resolved_helicities": [[0, 0, 0, 0, 2, 0, 2, 0]], - "source_state_assignments": [[0, 0], [1, 1]], - "source_dispatch_variants": [], - "source_embeddings": [], - "source_projections": [], - "resolved_source_selections": [], - "public_helicities": [-1, 1], - "exact_factors": [["1", "1", "0", "1"]], - "public_flow_ids": [0], - "executors": [ - [0, "source", "initialize", [], 1, 1, None, "source"], - [1, "contribution", "add", [1, 1], 1, 2, 10, None], - [2, "finalization", "finalize-in-place", [1], 1, 1, 11, None], - [3, "closure", "closure-add", [1], 1, 1, 12, None], - ], - } - return _parse_exact_sections(raw, "synthetic") - - -def _binding( - executor_id: int, - role: str, - semantic_id: str, - *, - records: tuple[dict[str, object], ...] = (), -) -> census.ExecutorSemanticBinding: - return census.ExecutorSemanticBinding( - executor_id=executor_id, - role=role, - semantic_digest=f"{executor_id + 3:x}" * 64, - semantic_template_ids=(semantic_id,), - direct_template={ - "direct_executor_id": executor_id, - "role": role, - "semantic_digest": f"{executor_id + 3:x}" * 64, - "semantic_template_ids": [semantic_id], - }, - referenced_semantic_records=records - or ( - { - "record_kind": role, - "semantic_digest": f"{executor_id + 7:x}" * 64, - "template_id": semantic_id, - }, - ), - ) - - -def _inputs(): - sections = _sections() - transition = { - "binding_coupling": { - "real_numerator": "1", - "real_denominator": "1", - "imag_numerator": "0", - "imag_denominator": "1", - }, - "color_contraction_template_id": "color:test", - "quantum_flow_template_id": "quantum:test", - "record_kind": "transition", - "semantic_digest": "8" * 64, - "template_id": "transition:test", - } - color = { - "record_kind": "color-contraction", - "semantic_digest": "9" * 64, - "template_id": "color:test", - "transition_witnesses": [{"proof_digest": "a" * 64}], - } - quantum = { - "record_kind": "quantum-flow", - "semantic_digest": "b" * 64, - "template_id": "quantum:test", - } - bindings = { - 0: _binding(0, "source", "source:test"), - 1: _binding( - 1, - "contribution", - "transition:test", - records=(transition, color, quantum), - ), - 2: _binding(2, "finalization", "propagator:test"), - 3: _binding(3, "closure", "closure:test"), - } - metadata = { - "digests": { - "process_semantic_digest": sections.semantic_digest, - "runtime_layout_digest": sections.runtime_layout_digest, - "schedule_digest": "c" * 64, - "native_schedule_semantic_digest": "d" * 64, - }, - "normalization_and_parameters": { - "normalization": {"average_factor": 36, "color_factor": 9}, - "runtime_parameters": [{"name": "alpha_s", "default": 0.118}], - }, - "selectors": { - "color_accuracy": "lc", - "public_color_flows": [{"public_id": "flow:test"}], - }, - "sources": { - "external_pdg_order": [1, -1], - "source_templates": [{"source_template_id": 0}], - }, - } - states = ( - {"semantic_digest": "e" * 64, "template_id": "state:left"}, - {"semantic_digest": "f" * 64, "template_id": "state:right"}, - {"semantic_digest": "0" * 64, "template_id": "state:result"}, - ) - return sections, metadata, bindings, states - - -def _build( - sections=None, - metadata=None, - bindings=None, - states=None, -): - base_sections, base_metadata, base_bindings, base_states = _inputs() - return census.build_semantic_census( - sections=sections or base_sections, - process_metadata=metadata or base_metadata, - executor_bindings=bindings or base_bindings, - state_templates=states or base_states, - ) - - -def _changed_domains(left, right) -> set[str]: - report = census.compare_census_sets({"synthetic": left}, {"synthetic": right}) - assert report["passes"] is False - return { - difference["domain"] - for difference in report["differences"] - if difference["kind"] == "semantic-domain" - } - - -def test_identical_semantic_censuses_pass_with_complete_domain_set() -> None: - built = _build() - - report = census.compare_census_sets( - {"synthetic": built}, {"synthetic": copy.deepcopy(built)} - ) - - assert report["passes"] is True - assert set(built["domains"]) == census._REQUIRED_DOMAINS - assert report["difference_count"] == 0 - - -def test_current_identity_state_support_color_and_helicity_projection_fail_closed() -> ( - None -): - sections, metadata, bindings, states = _inputs() - currents = list(sections.currents) - currents[2] = replace( - currents[2], - state_template_id=1, - selector_domain_id=7, - momentum_form_id=0, - ) - changed = replace(sections, currents=tuple(currents)) - - domains = _changed_domains( - _build(sections, metadata, bindings, states), - _build(changed, metadata, bindings, states), - ) - - assert {"currents", "runtime_layout"} <= domains - - -def test_source_semantics_fail_closed() -> None: - sections, metadata, bindings, states = _inputs() - sources = list(sections.sources) - sources[0] = replace(sources[0], spin_state_class=1) - - domains = _changed_domains( - _build(sections, metadata, bindings, states), - _build(replace(sections, sources=tuple(sources)), metadata, bindings, states), - ) - - assert {"sources", "runtime_layout"} <= domains - - -def test_union_source_rows_may_be_owned_without_a_direct_executor() -> None: - sections, metadata, bindings, states = _inputs() - groups = list(sections.row_groups) - groups[0] = replace(groups[0], executor_id=DIRECT_NONE_U32) - union_sections = replace( - sections, - strategy="all-flow-union", - row_groups=tuple(groups), - ) - - built = _build(union_sections, metadata, bindings, states) - report = census.compare_census_sets( - {"synthetic": built}, - {"synthetic": copy.deepcopy(built)}, - ) - - assert report["passes"] is True - assert built["domains"]["sources"]["record_count"] == 3 - - -def test_interaction_endpoints_sign_and_contribution_multiset_fail_closed() -> None: - sections, metadata, bindings, states = _inputs() - factors = ( - *sections.exact_factors, - replace(sections.exact_factors[0], real_numerator=-1), - ) - contributions = list(sections.contributions) - contributions[0] = replace( - contributions[0], - parent0_base=1, - exact_factor_id=1, - ) - changed = replace( - sections, - exact_factors=factors, - contributions=tuple(contributions), - ) - - domains = _changed_domains( - _build(sections, metadata, bindings, states), - _build(changed, metadata, bindings, states), - ) - - assert {"contribution_multisets", "runtime_layout"} <= domains - - -@pytest.mark.parametrize( - ("record_index", "mutation"), - ( - (0, ("template_id", "transition:changed")), - (0, ("binding_coupling", {"real_numerator": "2"})), - (1, ("transition_witnesses", [{"proof_digest": "0" * 64}])), - ), - ids=("transition-identity", "coupling", "color-witness"), -) -def test_transition_coupling_and_witness_catalogs_fail_closed( - record_index: int, - mutation: tuple[str, object], -) -> None: - sections, metadata, bindings, states = _inputs() - changed_bindings = dict(bindings) - original = bindings[1] - records = [ - copy.deepcopy(dict(record)) for record in original.referenced_semantic_records - ] - key, value = mutation - if key == "binding_coupling": - coupling = dict(records[record_index][key]) - coupling.update(value) - records[record_index][key] = coupling - else: - records[record_index][key] = value - changed_bindings[1] = replace(original, referenced_semantic_records=tuple(records)) - - domains = _changed_domains( - _build(sections, metadata, bindings, states), - _build(sections, metadata, changed_bindings, states), - ) - - assert "semantic_catalog_bindings" in domains - - -def test_closure_endpoints_and_selector_axes_fail_closed() -> None: - sections, metadata, bindings, states = _inputs() - closures = list(sections.closures) - closures[0] = replace(closures[0], amplitude_destination_id=3) - changed_closure = replace(sections, closures=tuple(closures)) - changed_selector = replace(sections, public_flow_ids=(4,)) - - assert "closures" in _changed_domains( - _build(sections, metadata, bindings, states), - _build(changed_closure, metadata, bindings, states), - ) - assert "selectors" in _changed_domains( - _build(sections, metadata, bindings, states), - _build(changed_selector, metadata, bindings, states), - ) - - -def test_normalization_digests_and_layout_each_fail_closed() -> None: - sections, metadata, bindings, states = _inputs() - changed_metadata = copy.deepcopy(metadata) - changed_metadata["normalization_and_parameters"]["normalization"][ - "average_factor" - ] = 18 - assert "normalization_and_parameters" in _changed_domains( - _build(sections, metadata, bindings, states), - _build(sections, changed_metadata, bindings, states), - ) - - changed_digest_sections = replace(sections, semantic_digest="a" * 64) - changed_digest_metadata = copy.deepcopy(metadata) - changed_digest_metadata["digests"]["process_semantic_digest"] = "a" * 64 - assert "digests" in _changed_domains( - _build(sections, metadata, bindings, states), - _build( - changed_digest_sections, - changed_digest_metadata, - bindings, - states, - ), - ) - - currents = list(sections.currents) - currents[2] = replace(currents[2], component_base=8) - assert "runtime_layout" in _changed_domains( - _build(sections, metadata, bindings, states), - _build( - replace(sections, currents=tuple(currents)), - metadata, - bindings, - states, - ), - ) - - -def test_authenticated_storage_hashes_do_not_define_semantic_equivalence() -> None: - sections, metadata, bindings, states = _inputs() - baseline_metadata = copy.deepcopy(metadata) - candidate_metadata = copy.deepcopy(metadata) - for index, field in enumerate( - sorted(census._STORAGE_AUTHENTICATION_DIGEST_FIELDS), - start=1, - ): - baseline_metadata["digests"][field] = f"{index:x}" * 64 - candidate_metadata["digests"][field] = f"{index + 4:x}" * 64 - - baseline = _build(sections, baseline_metadata, bindings, states) - candidate = _build(sections, candidate_metadata, bindings, states) - - assert baseline == candidate - assert ( - census.compare_census_sets( - {"synthetic": baseline}, - {"synthetic": candidate}, - )["passes"] - is True - ) - - -def test_missing_domain_and_inconsistent_transitive_digest_are_rejected() -> None: - built = _build() - incomplete = copy.deepcopy(built) - incomplete["domains"].pop("closures") - with pytest.raises(census.SemanticCensusError, match="incomplete census domains"): - census.compare_census_sets({"synthetic": built}, {"synthetic": incomplete}) - - sections, metadata, bindings, states = _inputs() - metadata["digests"]["process_semantic_digest"] = "a" * 64 - with pytest.raises( - census.SemanticCensusError, match="does not match exact sections" - ): - _build(sections, metadata, bindings, states) - - -def test_exact_section_fixture_uses_authoritative_parser() -> None: - sections = _sections() - - assert sections.currents[2].semantic_id == 2 - assert astuple(sections.contributions[0]) == (0, 1, 0, 1, 2, 0, 0, 0) diff --git a/pyamplicol/tests/unit/test_structural_work_certificate.py b/pyamplicol/tests/unit/test_structural_work_certificate.py deleted file mode 100644 index 731ac3284d..0000000000 --- a/pyamplicol/tests/unit/test_structural_work_certificate.py +++ /dev/null @@ -1,591 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from pathlib import Path - -import pytest - -from tools.developer.structural_work_certificate import ( - StructuralWorkError, - adjacent_multiplicity_census, - certify, - require_static_template_materialization_parity, - static_template_materialization_census, -) - - -def _legacy( - root: Path, - *, - module_currents: int = 406, - module_interactions: int = 2440, - retained_colors: int = 720, - generated_modules: int = 6, -) -> Path: - library = root / "contracted-generated-library" / "Library" - library.mkdir(parents=True) - probe = ( - root / "contracted-generated-library" / "amplicol_color_library_probe.output" - ) - probe.write_text( - "Total number of currents, vertices and amplitudes after filter" - f" 1597 4260 {retained_colors}\n" - ) - for index in range(generated_modules): - (library / f"amp{index + 1}_1_lib.f03").write_text( - f"complex(kind=8),dimension(1:6,{module_currents}) :: val_c\n" - f"complex(kind=8),dimension(1:6,{module_interactions}) :: int_c\n" - ) - return root - - -def _candidate( - root: Path, - payload: dict[str, object], - *, - external_count: int = 7, -) -> Path: - process = root / "processes" / "g_g_to_g_g_g_g_g" - process.mkdir(parents=True) - common = { - "external_pdg_order": [21] * external_count, - "color_accuracy": "full", - "process": "g_g_to_g_g_g_g_g", - } - (process / "execution.json").write_text(json.dumps(common | payload)) - return root - - -@pytest.mark.parametrize( - "payload,mode", - [ - ( - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 101_942, - "contribution_count": 955_368, - }, - "construction": { - "peak_current_count": 372_422, - "peak_contribution_count": 4_868_016, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - "recurrence", - ), - ( - { - "kind": "pyamplicol-runtime-execution", - "helicity_sum_execution": { - "dag_summary": { - "current_count": 90_000, - "interaction_count": 900_000, - } - }, - }, - "compiled", - ), - ( - { - "kind": "pyamplicol-runtime-eager-execution", - "plan": { - "inspection_summary": { - "current_count": 90_000, - "attachment_count": 900_000, - } - }, - }, - "eager", - ), - ], -) -def test_certifies_all_generation_modes( - tmp_path: Path, - payload: dict[str, object], - mode: str, -) -> None: - certificate = certify( - _legacy(tmp_path / "legacy"), - _candidate(tmp_path / "candidate", payload), - ) - assert certificate.status == "ok" - assert certificate.candidate.mode == mode - assert certificate.legacy.replay_current_count == 406 * 720 - assert certificate.legacy.replay_interaction_count == 2440 * 720 - assert certificate.final_work_comparison.classification == "proven-recycling" - assert certificate.final_work_comparison.current_savings_fraction > 0.0 - - -@pytest.mark.parametrize( - "payload", - [ - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": int(406 * 720 * 1.05) + 1, - "contribution_count": 2440 * 720, - }, - "construction": { - "peak_current_count": 406 * 720 + 1, - "peak_contribution_count": 2440 * 720, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - { - "kind": "pyamplicol-runtime-execution", - "helicity_sum_execution": { - "dag_summary": { - "current_count": int(406 * 720 * 1.05) + 1, - "interaction_count": 2440 * 720, - } - }, - }, - { - "kind": "pyamplicol-runtime-eager-execution", - "plan": { - "inspection_summary": { - "current_count": int(406 * 720 * 1.05) + 1, - "attachment_count": 2440 * 720, - } - }, - }, - ], -) -def test_rejects_final_work_above_legacy_replay( - tmp_path: Path, - payload: dict[str, object], -) -> None: - with pytest.raises( - StructuralWorkError, - match="final current work exceeds legacy replay", - ): - certify( - _legacy(tmp_path / "legacy"), - _candidate(tmp_path / "candidate", payload), - ) - - -def test_accepts_only_bounded_unproven_structural_tolerance( - tmp_path: Path, -) -> None: - replay_currents = 406 * 720 - certificate = certify( - _legacy(tmp_path / "legacy"), - _candidate( - tmp_path / "candidate", - { - "kind": "pyamplicol-runtime-execution", - "helicity_sum_execution": { - "dag_summary": { - "current_count": replay_currents + 1, - "interaction_count": 2440 * 720, - } - }, - }, - ), - ) - assert ( - certificate.final_work_comparison.classification - == "within-structural-tolerance" - ) - with pytest.raises(StructuralWorkError, match="unreviewed final-work budget"): - certify( - _legacy(tmp_path / "legacy-too-wide"), - _candidate( - tmp_path / "candidate-too-wide", - { - "kind": "pyamplicol-runtime-execution", - "helicity_sum_execution": { - "dag_summary": { - "current_count": 1, - "interaction_count": 1, - } - }, - }, - ), - max_final_to_legacy=1.051, - ) - - -def test_adjacent_multiplicity_census_normalizes_candidate_growth( - tmp_path: Path, -) -> None: - lower = certify( - _legacy( - tmp_path / "legacy-n4", - module_currents=188, - module_interactions=816, - retained_colors=120, - generated_modules=5, - ), - _candidate( - tmp_path / "candidate-n4", - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 8_372, - "contribution_count": 57_720, - }, - "construction": { - "peak_current_count": 26_052, - "peak_contribution_count": 255_600, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - external_count=6, - ), - ) - higher = certify( - _legacy(tmp_path / "legacy-n5"), - _candidate( - tmp_path / "candidate-n5", - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 101_942, - "contribution_count": 955_368, - }, - "construction": { - "peak_current_count": 372_422, - "peak_contribution_count": 4_868_016, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - ), - ) - census = adjacent_multiplicity_census(lower, higher) - assert census.status == "ok" - assert census.mode == "recurrence" - assert (census.lower_n_final, census.higher_n_final) == (4, 5) - assert census.normalized_current_growth < 1.0 - assert census.normalized_interaction_growth < 1.0 - assert census.normalized_peak_current_growth is not None - assert census.normalized_peak_current_growth < 1.25 - - -def test_n5_static_template_census_exposes_cold_generation_excess( - tmp_path: Path, -) -> None: - certificate = certify( - _legacy(tmp_path / "legacy"), - _candidate( - tmp_path / "candidate", - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 101_942, - "contribution_count": 955_368, - }, - "construction": { - "peak_current_count": 372_422, - "peak_contribution_count": 4_868_016, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - ), - ) - census = static_template_materialization_census(certificate) - assert census.status == "exceeds-budget" - assert census.legacy_generated_module_count == 6 - assert census.legacy_static_current_count == 2_436 - assert census.legacy_static_interaction_count == 14_640 - assert census.legacy_replay_multiplicity_per_module == 120 - assert census.candidate_final_current_ratio == pytest.approx(101_942 / 2_436) - assert census.candidate_final_interaction_ratio == pytest.approx(955_368 / 14_640) - assert census.candidate_peak_current_ratio == pytest.approx(372_422 / 2_436) - assert census.candidate_peak_interaction_ratio == pytest.approx(4_868_016 / 14_640) - assert census.violations == ( - "final currents exceed legacy static-template budget", - "final interactions exceed legacy static-template budget", - "peak currents exceed legacy static-template budget", - "peak interactions exceed legacy static-template budget", - ) - with pytest.raises( - StructuralWorkError, - match="final currents exceed legacy static-template budget", - ): - require_static_template_materialization_parity(certificate) - - -def test_n5_resident_construction_peak_fits_static_template_budget( - tmp_path: Path, -) -> None: - certificate = certify( - _legacy(tmp_path / "legacy"), - _candidate( - tmp_path / "candidate", - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 1_795, - "contribution_count": 9_990, - }, - "construction": { - "peak_current_count": 2_430, - "peak_contribution_count": 11_597, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - ), - ) - construction = certificate.recurrence_construction - assert construction is not None - assert construction.peak_contribution_count == 11_597 - census = require_static_template_materialization_parity(certificate) - assert census.status == "ok" - assert census.candidate_peak_current_count == 2_430 - assert census.candidate_peak_interaction_count == 11_597 - - -def test_n5_resident_construction_peak_rejects_one_row_above_budget( - tmp_path: Path, -) -> None: - certificate = certify( - _legacy(tmp_path / "legacy"), - _candidate( - tmp_path / "candidate", - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 1_795, - "contribution_count": 9_990, - }, - "construction": { - "peak_current_count": 2_366, - "peak_contribution_count": 15_373, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - ), - ) - census = static_template_materialization_census(certificate) - assert census.status == "exceeds-budget" - assert census.violations == ( - "peak interactions exceed legacy static-template budget", - ) - - -@pytest.mark.parametrize( - "payload,mode", - [ - ( - { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 2_436, - "contribution_count": 14_640, - }, - "construction": { - "peak_current_count": 2_436, - "peak_contribution_count": 14_640, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - }, - "recurrence", - ), - ( - { - "kind": "pyamplicol-runtime-execution", - "helicity_sum_execution": { - "dag_summary": { - "current_count": 2_436, - "interaction_count": 14_640, - } - }, - }, - "compiled", - ), - ( - { - "kind": "pyamplicol-runtime-eager-execution", - "plan": { - "inspection_summary": { - "current_count": 2_436, - "attachment_count": 14_640, - } - }, - }, - "eager", - ), - ], -) -def test_static_template_parity_gate_covers_all_generation_modes( - tmp_path: Path, - payload: dict[str, object], - mode: str, -) -> None: - certificate = certify( - _legacy(tmp_path / "legacy"), - _candidate(tmp_path / "candidate", payload), - ) - census = require_static_template_materialization_parity(certificate) - assert census.status == "ok" - assert census.mode == mode - assert census.candidate_final_current_ratio == 1.0 - assert census.candidate_final_interaction_ratio == 1.0 - if mode == "recurrence": - assert census.candidate_peak_current_ratio == 1.0 - assert census.candidate_peak_interaction_ratio == 1.0 - else: - assert census.candidate_peak_current_ratio is None - assert census.candidate_peak_interaction_ratio is None - - -def test_static_template_census_requires_integral_color_replay( - tmp_path: Path, -) -> None: - certificate = certify( - _legacy( - tmp_path / "legacy", - retained_colors=720, - generated_modules=7, - ), - _candidate( - tmp_path / "candidate", - { - "kind": "pyamplicol-runtime-execution", - "helicity_sum_execution": { - "dag_summary": { - "current_count": 1, - "interaction_count": 1, - } - }, - }, - ), - ) - with pytest.raises( - StructuralWorkError, - match="not an integer multiple", - ): - static_template_materialization_census(certificate) - - -def test_rejects_ambiguous_legacy_recurrence_construction_peak( - tmp_path: Path, -) -> None: - payload = { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 10, - "contribution_count": 10, - }, - "construction": { - "peak_current_count": 10, - "peak_contribution_count": 10, - }, - } - }, - } - - with pytest.raises( - StructuralWorkError, - match="authenticated resident peak-contribution semantics", - ): - certify( - _legacy(tmp_path / "legacy"), - _candidate(tmp_path / "candidate", payload), - ) - - -def test_rejects_recurrence_construction_inflation(tmp_path: Path) -> None: - payload = { - "kind": "pyamplicol-runtime-recurrence-execution", - "plan": { - "inspection_summary": { - "schedule": { - "current_count": 10, - "contribution_count": 10, - }, - "construction": { - "peak_current_count": 100, - "peak_contribution_count": 100, - "peak_contribution_count_semantics": ( - "resident-pending-contributions-v1" - ), - }, - } - }, - } - with pytest.raises( - StructuralWorkError, - match="peak/final construction current ratio exceeds budget", - ): - certify( - _legacy(tmp_path / "legacy"), - _candidate(tmp_path / "candidate", payload), - ) - - -def test_rejects_nonuniform_legacy_modules(tmp_path: Path) -> None: - legacy = _legacy(tmp_path / "legacy") - module = legacy / "contracted-generated-library" / "Library" / "amp2_1_lib.f03" - module.write_text( - "complex(kind=8),dimension(1:6,407) :: val_c\n" - "complex(kind=8),dimension(1:6,2440) :: int_c\n" - ) - candidate = _candidate( - tmp_path / "candidate", - { - "kind": "pyamplicol-runtime-eager-execution", - "plan": { - "inspection_summary": { - "current_count": 1, - "attachment_count": 1, - } - }, - }, - ) - with pytest.raises(StructuralWorkError, match="do not share one replay shape"): - certify(legacy, candidate) diff --git a/pyamplicol/tests/unit/test_symjit_2_22_generated_fixture_gate.py b/pyamplicol/tests/unit/test_symjit_2_22_generated_fixture_gate.py deleted file mode 100644 index bf4c41e667..0000000000 --- a/pyamplicol/tests/unit/test_symjit_2_22_generated_fixture_gate.py +++ /dev/null @@ -1,628 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from contextlib import contextmanager -from pathlib import Path -from typing import Any - -import pytest - -from tools.developer import symjit_2_22_generated_fixture_gate as gate - -_FIXTURE_NAMES = ( - "compiled_o3", - "eager_o2", - "recurrence_topology_o2", - "recurrence_union_o2", - "contracted_nlc", -) -_SOURCE_REVISION = "a" * 40 -_NATIVE_BUILD_INPUTS_SHA256 = "b" * 64 -_CANDIDATE_VERSION = "0.1.0.dev0+candidate.0123456789ab" - - -def _manifest(name: str) -> dict[str, Any]: - return { - "artifact_id": name, - "default_process_id": gate._EXPECTED_PROCESS_ID, - "processes": [ - { - "id": gate._EXPECTED_PROCESS_ID, - "expression": gate._EXPECTED_PROCESS_EXPRESSION, - "external_pdgs": list(gate._EXPECTED_EXTERNAL_PDGS), - } - ], - "producer": { - "distribution": "pyamplicol", - "git_revision": _SOURCE_REVISION, - "native_build_inputs_sha256": _NATIVE_BUILD_INPUTS_SHA256, - "version": _CANDIDATE_VERSION, - }, - "extensions": { - "artifact_identity": dict(gate._ARTIFACT_IDENTITY_CONTRACT), - }, - } - - -def _build_info( - *, - source_revision: str = _SOURCE_REVISION, - native_build_inputs_sha256: str = _NATIVE_BUILD_INPUTS_SHA256, - version: str = _CANDIDATE_VERSION, -) -> dict[str, Any]: - return { - "schema_version": 1, - "publishable": False, - "candidate_fingerprint": version.rsplit("+candidate.", maxsplit=1)[1], - "native_build_inputs_sha256": native_build_inputs_sha256, - "selftest_fixture_bootstrap": False, - "source_checkout": "/workspace/source", - "source_revision": source_revision, - "version": version, - } - - -def _preflight( - raw: dict[str, Path], - *, - workspace_root: Path, -) -> gate.FixturePaths: - return gate.preflight_fixtures( - raw, - workspace_root=workspace_root, - source_revision=_SOURCE_REVISION, - native_build_inputs_sha256=_NATIVE_BUILD_INPUTS_SHA256, - ) - - -def _identity_arguments() -> list[str]: - return [ - "--source-revision", - _SOURCE_REVISION, - "--native-build-inputs-sha256", - _NATIVE_BUILD_INPUTS_SHA256, - ] - - -def _workspace(tmp_path: Path) -> tuple[Path, dict[str, Path]]: - root = tmp_path / "workspace" - root.mkdir() - (root / "Cargo.toml").write_text("[workspace]\n", encoding="utf-8") - fixtures: dict[str, Path] = {} - for name in _FIXTURE_NAMES: - artifact = root / "fixtures" / name - artifact.mkdir(parents=True) - (artifact / "artifact.json").write_text( - json.dumps(_manifest(name)), - encoding="utf-8", - ) - fixtures[name] = artifact - return root, fixtures - - -def _execution_paths(root: Path) -> dict[str, Path]: - state = root / ".artifacts" / "gate-state" - return { - "cargo_home": state / "cargo-home", - "cargo_target_dir": state / "cargo-target", - "tmpdir": state / "tmp", - "pip_cache_dir": state / "pip-cache", - "xdg_cache_home": state / "xdg-cache", - "python_cache_prefix": state / "python-cache", - } - - -def test_preflight_requires_distinct_workspace_local_artifact_manifests( - tmp_path: Path, -) -> None: - root, fixtures = _workspace(tmp_path) - resolved = _preflight(fixtures, workspace_root=root) - assert resolved.as_dict() == fixtures - - missing_manifest = root / "fixtures" / "missing-manifest" - missing_manifest.mkdir() - invalid = dict(fixtures) - invalid["compiled_o3"] = missing_manifest - with pytest.raises(gate.GateError, match=r"missing artifact\.json"): - _preflight(invalid, workspace_root=root) - - outside = tmp_path / "outside" - outside.mkdir() - (outside / "artifact.json").write_text("{}", encoding="utf-8") - invalid = dict(fixtures) - invalid["compiled_o3"] = outside - with pytest.raises(gate.GateError, match="workspace-local"): - _preflight(invalid, workspace_root=root) - - duplicate = dict(fixtures) - duplicate["compiled_o3"] = duplicate["eager_o2"] - with pytest.raises(gate.GateError, match="distinct artifact directories"): - _preflight(duplicate, workspace_root=root) - - -@pytest.mark.parametrize("fixture_name", _FIXTURE_NAMES) -def test_preflight_authenticates_the_producer_of_every_fixture_role( - fixture_name: str, - tmp_path: Path, -) -> None: - root, fixtures = _workspace(tmp_path) - manifest = fixtures[fixture_name] / "artifact.json" - payload = json.loads(manifest.read_text(encoding="utf-8")) - payload["producer"]["git_revision"] = "c" * 40 - manifest.write_text(json.dumps(payload), encoding="utf-8") - - with pytest.raises(gate.GateError, match="producer git_revision"): - _preflight(fixtures, workspace_root=root) - - -def test_preflight_requires_exact_candidate_and_z6g_identity( - tmp_path: Path, -) -> None: - root, fixtures = _workspace(tmp_path) - manifest = fixtures["compiled_o3"] / "artifact.json" - - invalid = _manifest("compiled_o3") - invalid["producer"]["version"] = "0.1.0" - manifest.write_text(json.dumps(invalid), encoding="utf-8") - with pytest.raises(gate.GateError, match="not a candidate build"): - _preflight(fixtures, workspace_root=root) - - invalid = _manifest("compiled_o3") - invalid["producer"]["native_build_inputs_sha256"] = "c" * 64 - manifest.write_text(json.dumps(invalid), encoding="utf-8") - with pytest.raises( - gate.GateError, - match="producer native_build_inputs_sha256", - ): - _preflight(fixtures, workspace_root=root) - - invalid = _manifest("compiled_o3") - invalid["processes"][0]["expression"] = "u u~ > z g g g g g g" - manifest.write_text(json.dumps(invalid), encoding="utf-8") - with pytest.raises(gate.GateError, match="exact Z\\+6g fixture"): - _preflight(fixtures, workspace_root=root) - - invalid = _manifest("compiled_o3") - invalid["processes"][0]["external_pdgs"] = [ - 2, - -2, - 23, - 21, - 21, - 21, - 21, - 21, - 21, - ] - manifest.write_text(json.dumps(invalid), encoding="utf-8") - with pytest.raises(gate.GateError, match="exact Z\\+6g fixture"): - _preflight(fixtures, workspace_root=root) - - invalid = _manifest("compiled_o3") - invalid["default_process_id"] = "not-the-z6g-process" - manifest.write_text(json.dumps(invalid), encoding="utf-8") - with pytest.raises(gate.GateError, match="default_process_id"): - _preflight(fixtures, workspace_root=root) - - -def test_preflight_rejects_unauthenticated_identity_arguments( - tmp_path: Path, -) -> None: - root, fixtures = _workspace(tmp_path) - - with pytest.raises(gate.GateError, match="lowercase 40-digit hex"): - gate.preflight_fixtures( - fixtures, - workspace_root=root, - source_revision="A" * 40, - native_build_inputs_sha256=_NATIVE_BUILD_INPUTS_SHA256, - ) - with pytest.raises(gate.GateError, match="lowercase 64-digit hex"): - gate.preflight_fixtures( - fixtures, - workspace_root=root, - source_revision=_SOURCE_REVISION, - native_build_inputs_sha256="b" * 63, - ) - - -def test_execution_paths_are_workspace_local_and_preflight_does_not_create_them( - tmp_path: Path, -) -> None: - root, _ = _workspace(tmp_path) - raw = _execution_paths(root) - - paths = gate.preflight_execution_paths(raw, workspace_root=root) - - assert paths.as_dict() == raw - assert all(not path.exists() for path in raw.values()) - - invalid = dict(raw) - invalid["tmpdir"] = tmp_path / "outside-tmp" - with pytest.raises(gate.GateError, match="workspace-local"): - gate.preflight_execution_paths(invalid, workspace_root=root) - - -def test_environment_uses_every_audited_fixture_mapping(tmp_path: Path) -> None: - root, raw = _workspace(tmp_path) - fixtures = _preflight(raw, workspace_root=root) - - assert gate.artifact_environment(fixtures) == { - "RUSTICOL_COMPILED_DIRECT_ARTIFACT": str(raw["compiled_o3"]), - "RUSTICOL_COMPILED_ARTIFACT": str(raw["compiled_o3"]), - "RUSTICOL_TEST_COMPILED_REPLAY_QUICK_ARTIFACT": str(raw["compiled_o3"]), - "RUSTICOL_SELECTOR_ARTIFACT": str(raw["compiled_o3"]), - "RUSTICOL_EAGER_ARTIFACT": str(raw["eager_o2"]), - "RUSTICOL_RECURRENCE_ARTIFACT": str(raw["recurrence_topology_o2"]), - "RUSTICOL_RECURRENCE_TOPOLOGY_ALLOCATION_ARTIFACT": str( - raw["recurrence_topology_o2"] - ), - "RUSTICOL_RECURRENCE_UNION_ALLOCATION_ARTIFACT": str( - raw["recurrence_union_o2"] - ), - "RUSTICOL_RECURRENCE_CONTRACTED_ALLOCATION_ARTIFACT": str( - raw["contracted_nlc"] - ), - "RUSTICOL_CONTRACTED_SELECTOR_ARTIFACT": str(raw["contracted_nlc"]), - } - - -def test_execution_creates_local_state_and_exports_the_required_environment( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - root, raw_fixtures = _workspace(tmp_path) - fixtures = _preflight(raw_fixtures, workspace_root=root) - raw_execution = _execution_paths(root) - execution = gate.preflight_execution_paths( - raw_execution, - workspace_root=root, - ) - command = gate.GateCommand( - label="mock focused gate", - arguments=("cargo", "test"), - expected_tests=("required_test",), - ) - calls: list[dict[str, object]] = [] - - class Completed: - returncode = 0 - stdout = "test required_test ... ok\n" - - def run(*args: object, **kwargs: object) -> Completed: - del args - calls.append(kwargs) - return Completed() - - monkeypatch.setattr(gate.subprocess, "run", run) - - gate.run_commands( - (command,), - environment=gate.artifact_environment(fixtures), - execution_paths=execution, - workspace_root=root, - ) - - assert all(path.is_dir() for path in raw_execution.values()) - child_environment = calls[0]["env"] - assert isinstance(child_environment, dict) - assert child_environment["PYAMPLICOL_REQUIRE_NATIVE_TESTS"] == "1" - assert child_environment["CARGO_HOME"] == str(raw_execution["cargo_home"]) - assert child_environment["CARGO_TARGET_DIR"] == str( - raw_execution["cargo_target_dir"] - ) - assert child_environment["TMPDIR"] == str(raw_execution["tmpdir"]) - - -def test_authenticated_candidate_overlay_is_local_and_reuses_the_gate_target( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - root, _ = _workspace(tmp_path) - raw_execution = _execution_paths(root) - execution = gate.preflight_execution_paths( - raw_execution, - workspace_root=root, - ) - overlay = raw_execution["tmpdir"] / "pyamplicol-build-test" / "source" - (overlay / ".cargo").mkdir(parents=True) - (overlay / "Cargo.lock").write_text("version = 4\n", encoding="utf-8") - (overlay / ".cargo" / "config.toml").write_text( - "[patch.crates-io]\n", - encoding="utf-8", - ) - build_info = overlay / "src" / "pyamplicol" / "_build_info.json" - build_info.parent.mkdir(parents=True) - build_info.write_text( - json.dumps(_build_info()), - encoding="utf-8", - ) - calls: list[tuple[str, dict[str, Path]]] = [] - dependency_checks: list[str] = [] - - @contextmanager - def fake_overlay(mode: str, **kwargs: Path): - calls.append((mode, kwargs)) - yield overlay, kwargs["cargo_target_directory"] - - monkeypatch.setattr( - gate.build_backend, - "_check_dependencies", - dependency_checks.append, - ) - monkeypatch.setattr(gate.build_backend, "_overlay", fake_overlay) - - with gate.authenticated_candidate_overlay( - execution, - source_revision=_SOURCE_REVISION, - native_build_inputs_sha256=_NATIVE_BUILD_INPUTS_SHA256, - candidate_version=_CANDIDATE_VERSION, - ) as observed: - assert observed == overlay - - assert calls == [ - ( - "candidate", - { - "temporary_directory": raw_execution["tmpdir"], - "cargo_target_directory": raw_execution["cargo_target_dir"], - }, - ) - ] - assert dependency_checks == ["candidate"] - - -@pytest.mark.parametrize( - ("updates", "message"), - [ - ({"source_revision": "c" * 40}, "source_revision"), - ({"native_build_inputs_sha256": "d" * 64}, "native_build_inputs_sha256"), - ( - {"version": "0.1.0.dev0+candidate.fedcba987654"}, - "version", - ), - ({"selftest_fixture_bootstrap": True}, "selftest_fixture_bootstrap"), - ], -) -def test_authenticated_candidate_overlay_rejects_mismatched_build_identity( - updates: dict[str, object], - message: str, - tmp_path: Path, -) -> None: - overlay = tmp_path / "overlay" - build_info = overlay / "src" / "pyamplicol" / "_build_info.json" - build_info.parent.mkdir(parents=True) - payload = _build_info() - payload.update(updates) - build_info.write_text(json.dumps(payload), encoding="utf-8") - - with pytest.raises(gate.GateError, match=message): - gate._authenticate_candidate_overlay_build_info( - overlay.resolve(), - source_revision=_SOURCE_REVISION, - native_build_inputs_sha256=_NATIVE_BUILD_INPUTS_SHA256, - candidate_version=_CANDIDATE_VERSION, - ) - - -def test_preflight_requires_one_candidate_version(tmp_path: Path) -> None: - root, raw = _workspace(tmp_path) - fixtures = _preflight(raw, workspace_root=root) - assert gate._common_fixture_candidate_version(fixtures) == _CANDIDATE_VERSION - - manifest = raw["compiled_o3"] / "artifact.json" - payload = json.loads(manifest.read_text(encoding="utf-8")) - payload["producer"]["version"] = "0.1.0.dev0+candidate.fedcba987654" - manifest.write_text(json.dumps(payload), encoding="utf-8") - with pytest.raises(gate.GateError, match="one candidate build"): - _preflight(raw, workspace_root=root) - - -def test_main_executes_every_command_in_one_authenticated_candidate_overlay( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - root, fixtures = _workspace(tmp_path) - overlay = root / ".artifacts" / "authenticated-overlay" - overlay.mkdir(parents=True) - (overlay / "Cargo.toml").write_text("[workspace]\n", encoding="utf-8") - monkeypatch.setattr(gate, "ROOT", root) - calls: list[tuple[tuple[gate.GateCommand, ...], Path]] = [] - - @contextmanager - def fake_candidate_overlay( - _execution: gate.ExecutionPaths, - *, - source_revision: str, - native_build_inputs_sha256: str, - candidate_version: str, - ): - assert source_revision == _SOURCE_REVISION - assert native_build_inputs_sha256 == _NATIVE_BUILD_INPUTS_SHA256 - assert candidate_version == _CANDIDATE_VERSION - yield overlay - - def capture_commands( - commands: tuple[gate.GateCommand, ...], - *, - environment: object, - execution_paths: object, - workspace_root: Path, - ) -> None: - del environment, execution_paths - calls.append((commands, workspace_root)) - - monkeypatch.setattr( - gate, - "authenticated_candidate_overlay", - fake_candidate_overlay, - ) - monkeypatch.setattr(gate, "run_commands", capture_commands) - arguments = [ - "--compiled-o3-artifact", - str(fixtures["compiled_o3"]), - "--eager-o2-artifact", - str(fixtures["eager_o2"]), - "--recurrence-topology-o2-artifact", - str(fixtures["recurrence_topology_o2"]), - "--recurrence-union-o2-artifact", - str(fixtures["recurrence_union_o2"]), - "--contracted-nlc-artifact", - str(fixtures["contracted_nlc"]), - *_identity_arguments(), - ] - - assert gate.main(arguments) == 0 - assert len(calls) == 1 - commands, workspace_root = calls[0] - assert workspace_root == overlay - assert len(commands) == 8 - assert all( - str(overlay / "Cargo.toml") in command.arguments - for command in commands - ) - assert all( - str(root / "Cargo.toml") not in command.arguments for command in commands - ) - - -def test_plan_contains_every_focused_gate_and_expected_marker( - tmp_path: Path, -) -> None: - root, _ = _workspace(tmp_path) - commands = gate.gate_commands(cargo="/toolchain/bin/cargo", workspace_root=root) - - assert len(commands) == 8 - assert all(command.arguments[0] == "/toolchain/bin/cargo" for command in commands) - assert all("--locked" in command.arguments for command in commands) - assert all(str(root / "Cargo.toml") in command.arguments for command in commands) - assert all( - command.arguments.count(str(root / "Cargo.toml")) == 1 - for command in commands - ) - assert all("--show-output" in command.arguments for command in commands) - assert all("--test-threads=1" in command.arguments for command in commands) - odd_tail_command = next( - command - for command in commands - if command.expected_tests == gate._ODD_TAIL_TESTS - ) - assert "generated_artifact_odd_tails" in odd_tail_command.arguments - assert {test for command in commands for test in command.expected_tests} == { - gate._COMPILED_FULL_TEST, - gate._COMPILED_QUICK_TEST, - gate._EAGER_ALLOCATION_TEST, - gate._RECURRENCE_SMOKE_TEST, - gate._RECURRENCE_BOUNDARY_TEST, - *gate._RECURRENCE_ALLOCATION_TESTS, - *gate._ODD_TAIL_TESTS, - *gate._CAPI_ARTIFACT_TESTS, - *gate._CAPI_SELECTOR_TESTS, - } - - -def test_success_requires_an_ok_marker_for_every_requested_test( - tmp_path: Path, -) -> None: - root, _ = _workspace(tmp_path) - command = gate.gate_commands(cargo="cargo", workspace_root=root)[4] - output = "\n".join( - f"test {test_name} ... ok" for test_name in command.expected_tests - ) - gate.verify_test_markers(command, output) - - with pytest.raises(gate.GateError, match="did not run every required test"): - gate.verify_test_markers( - command, - f"test {command.expected_tests[0]} ... ok\n" - "test unrelated_test ... ok\n", - ) - - -def test_plan_mode_preflights_without_launching_cargo( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - capsys: pytest.CaptureFixture[str], -) -> None: - root, fixtures = _workspace(tmp_path) - monkeypatch.setattr(gate, "ROOT", root) - - def unexpected_run(*args: object, **kwargs: object) -> None: - del args, kwargs - raise AssertionError("plan mode must not launch Cargo") - - monkeypatch.setattr(gate.subprocess, "run", unexpected_run) - arguments = [ - "--compiled-o3-artifact", - str(fixtures["compiled_o3"]), - "--eager-o2-artifact", - str(fixtures["eager_o2"]), - "--recurrence-topology-o2-artifact", - str(fixtures["recurrence_topology_o2"]), - "--recurrence-union-o2-artifact", - str(fixtures["recurrence_union_o2"]), - "--contracted-nlc-artifact", - str(fixtures["contracted_nlc"]), - *_identity_arguments(), - "--plan", - ] - - assert gate.main(arguments) == 0 - payload = json.loads(capsys.readouterr().out) - assert payload["workspace_root"] == str(root) - assert payload["cargo_input"] == { - "mode": "authenticated-candidate-overlay", - "manifest": gate._CANDIDATE_MANIFEST_PLACEHOLDER, - "shared_target": payload["execution_paths"]["cargo_target_dir"], - } - assert payload["fixture_identity"] == { - "producer": { - "distribution": "pyamplicol", - "git_revision": _SOURCE_REVISION, - "native_build_inputs_sha256": _NATIVE_BUILD_INPUTS_SHA256, - "version_pattern": gate._CANDIDATE_VERSION_PATTERN.pattern, - }, - "process": { - "id": gate._EXPECTED_PROCESS_ID, - "expression": gate._EXPECTED_PROCESS_EXPRESSION, - "external_pdgs": list(gate._EXPECTED_EXTERNAL_PDGS), - }, - } - assert len(payload["commands"]) == 8 - assert len(payload["execution_paths"]) == 6 - assert len(payload["environment"]) == 18 - assert payload["environment"]["PYAMPLICOL_REQUIRE_NATIVE_TESTS"] == "1" - assert payload["environment"]["CARGO_TERM_COLOR"] == "never" - default_state_root = ( - root - / ".artifacts" - / "symjit-2.22-migration" - / "generated-fixture-gate" - ) - assert all( - Path(path).is_relative_to(default_state_root) - for path in payload["execution_paths"].values() - ) - assert payload["environment"]["CARGO_HOME"] == payload["execution_paths"][ - "cargo_home" - ] - assert payload["environment"]["CARGO_TARGET_DIR"] == payload[ - "execution_paths" - ]["cargo_target_dir"] - assert payload["environment"]["TMPDIR"] == payload["execution_paths"]["tmpdir"] - assert payload["environment"]["PIP_CACHE_DIR"] == payload["execution_paths"][ - "pip_cache_dir" - ] - assert payload["environment"]["XDG_CACHE_HOME"] == payload[ - "execution_paths" - ]["xdg_cache_home"] - assert all( - gate._CANDIDATE_MANIFEST_PLACEHOLDER in command["arguments"] - for command in payload["commands"] - ) - assert all( - str(root / "Cargo.toml") not in command["arguments"] - for command in payload["commands"] - ) - assert not (root / ".artifacts").exists() diff --git a/pyamplicol/tests/unit/test_symjit_2_22_migration_benchmark_gate.py b/pyamplicol/tests/unit/test_symjit_2_22_migration_benchmark_gate.py deleted file mode 100644 index 3fd07776ed..0000000000 --- a/pyamplicol/tests/unit/test_symjit_2_22_migration_benchmark_gate.py +++ /dev/null @@ -1,2319 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import copy -import datetime as dt -import hashlib -import importlib.util -import json -import math -import sys -from pathlib import Path - -import pytest - -ROOT = Path(__file__).resolve().parents[2] -SCRIPT = ROOT / "tools" / "developer" / "symjit_2_22_migration_benchmark_gate.py" -SPEC = importlib.util.spec_from_file_location( - "symjit_2_22_migration_benchmark_gate", - SCRIPT, -) -assert SPEC is not None and SPEC.loader is not None -gate = importlib.util.module_from_spec(SPEC) -sys.modules[SPEC.name] = gate -SPEC.loader.exec_module(gate) - -ALL_MODES = (*gate.CAPTURE_MODES, *gate.DIAGNOSTIC_MODES) -EXPECTED_CANDIDATE_REVISION = "2" * 40 -EXPECTED_BASELINE_NATIVE_BUILD_INPUTS = "e" * 64 -EXPECTED_CANDIDATE_NATIVE_BUILD_INPUTS = "f" * 64 -EXPECTED_BASELINE_PREPARED_MODEL = "8" * 64 -EXPECTED_CANDIDATE_PREPARED_MODEL = "9" * 64 - - -def _canonical(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def _sha256(value: object) -> str: - return hashlib.sha256(_canonical(value)).hexdigest() - - -def _address(value: dict[str, object]) -> dict[str, object]: - result = dict(value) - result["content_sha256"] = _sha256(result) - return result - - -def _peak(value: int) -> dict[str, object]: - return { - "source": "resource.getrusage", - "self_peak_bytes": value, - "maximum_child_peak_bytes": 0, - "observed_lower_bound_bytes": value, - "semantics": "synthetic process high-water mark", - } - - -def _statistics(values: list[float]) -> tuple[float, float]: - ordered = sorted(values) - median = ordered[len(ordered) // 2] - deviations = sorted(abs(value - median) for value in values) - return median, deviations[len(deviations) // 2] - - -_TEST_EPOCH = dt.datetime(2026, 7, 30, tzinfo=dt.UTC) - - -def _layout_epoch(layout: str) -> dt.datetime: - return _TEST_EPOCH + ( - dt.timedelta(seconds=10_000) - if layout == "all-flow-union" - else dt.timedelta() - ) - - -def _slot_times( - *, - role: str, - layout: str, - schedule_index: int, - round_index: int, -) -> tuple[dt.datetime, dt.datetime, dt.datetime, dt.datetime]: - expected_order = ( - ("baseline", "candidate") - if round_index % 2 == 0 - else ("candidate", "baseline") - ) - order = expected_order.index(role) - pair_start = _layout_epoch(layout) + dt.timedelta(seconds=schedule_index * 10) - issued = pair_start + dt.timedelta(seconds=order * 3) - return ( - issued, - issued + dt.timedelta(seconds=1), - issued + dt.timedelta(seconds=2), - issued + dt.timedelta(seconds=2, milliseconds=500), - ) - - -def _semantic_identity( - layout: str, - mode: str, - *, - selected_union: bool = False, -) -> dict[str, object]: - normalization = {"average_factor": 36, "color_factor": 2187} - reduction_ordering = { - "kind": "lc-diagonal", - "pair_order_abi": "helicity-major-color-minor-v1", - **({"lane_internal": mode} if selected_union else {}), - } - selector_semantics = { - "kind": "pyamplicol-runtime-selectors", - "layout": layout, - } - common_model = { - "name": "built-in-sm", - "content_sha256": "9" * 64, - "compiled_schema_version": 9, - "restriction": None, - } - if selected_union: - color_ids = [ - f"flow:synthetic:{index}" - for index in range(gate.SELECTED_UNION_COLOR_COUNT) - ] - color_entries = [ - { - "index": index, - "id": identifier, - "kind": "lc-flow", - "word": [index + 1], - "coefficient": 1.0, - } - for index, identifier in enumerate(color_ids) - ] - helicity_count = gate.SELECTED_UNION_HELICITY_INDEX + 1 - helicity_ids = [ - ( - gate.SELECTED_UNION_HELICITY_ID - if index == gate.SELECTED_UNION_HELICITY_INDEX - else f"h:synthetic:{index}" - ) - for index in range(helicity_count) - ] - helicity_entries = [ - { - "index": index, - "id": identifier, - "values": ( - list(gate.SELECTED_UNION_HELICITY_VALUES) - if index == gate.SELECTED_UNION_HELICITY_INDEX - else [index] - ), - "coefficient": ( - 1.0 - if index == gate.SELECTED_UNION_HELICITY_INDEX or mode != "compiled" - else 0.0 - ), - "structural_zero": ( - index != gate.SELECTED_UNION_HELICITY_INDEX and mode == "compiled" - ), - } - for index, identifier in enumerate(helicity_ids) - ] - physical_colors = { - "count": len(color_ids), - "ordered_ids": color_ids, - "ordered_ids_sha256": _sha256(color_ids), - "ordered_entries": color_entries, - "ordered_entries_sha256": _sha256(color_entries), - } - physical_helicities = { - "count": len(helicity_ids), - "ordered_ids": helicity_ids, - "ordered_ids_sha256": _sha256(helicity_ids), - "ordered_entries": helicity_entries, - "ordered_entries_sha256": _sha256(helicity_entries), - } - else: - physical_colors = { - "count": 2, - "ordered_entries": [{"index": 0}, {"index": 1}], - } - physical_helicities = { - "count": 2, - "ordered_entries": [{"index": 0}, {"index": 1}], - } - return { - "kind": "pyamplicol-benchmark-artifact-semantic-identity", - "schema_version": 3, - "mode_internal_marker": mode, - "generation_specialized_axes": [], - "coverage": { - "color": "complete", - "helicities": "complete", - "complete_physical_axes": True, - }, - "reduction_coverage": { - "complete": True, - "errors": [], - "expected_physical_pair_count": 4, - "observed_physical_pair_count": 4, - }, - "normalization": normalization, - "normalization_sha256": _sha256(normalization), - "reduction_ordering": reduction_ordering, - "reduction_ordering_sha256": _sha256(reduction_ordering), - "runtime_selector_semantics": selector_semantics, - "runtime_selector_semantics_sha256": _sha256(selector_semantics), - "manifest_model_identity": { - "common_physics_identity": common_model, - "common_physics_identity_sha256": _sha256(common_model), - }, - "physical_color_flows": physical_colors, - "physical_helicities": physical_helicities, - } - - -def _selected_union_projection( - semantic: dict[str, object], - *, - process_id: str, - color_flow_request: str, -) -> dict[str, object]: - colors = semantic["physical_color_flows"] - helicities = semantic["physical_helicities"] - assert isinstance(colors, dict) - assert isinstance(helicities, dict) - entries = helicities["ordered_entries"] - assert isinstance(entries, list) - kinematic_entries = [ - { - "index": entry["index"], - "id": entry["id"], - "values": entry["values"], - **( - { - "coefficient": entry["coefficient"], - "structural_zero": entry["structural_zero"], - } - if entry["id"] == gate.SELECTED_UNION_HELICITY_ID - else {} - ), - } - for entry in entries - ] - selected_entry = entries[gate.SELECTED_UNION_HELICITY_INDEX] - model = semantic["manifest_model_identity"] - assert isinstance(model, dict) - return { - "policy": gate.SELECTED_UNION_SEMANTIC_COMPARISON_POLICY, - "process_id": process_id, - "process_expression": gate.SELECTED_UNION_PROCESS, - "physical_color_flows": { - "count": colors["count"], - "ordered_ids_sha256": colors["ordered_ids_sha256"], - "ordered_entries_sha256": colors["ordered_entries_sha256"], - }, - "physical_helicities": { - "count": helicities["count"], - "ordered_ids_sha256": helicities["ordered_ids_sha256"], - "kinematic_entries_sha256": _sha256(kinematic_entries), - "selected_index": gate.SELECTED_UNION_HELICITY_INDEX, - "selected_entry": selected_entry, - }, - "normalization_sha256": semantic["normalization_sha256"], - "model_common_physics_identity_sha256": model["common_physics_identity_sha256"], - "runtime_selector_semantics_sha256": semantic[ - "runtime_selector_semantics_sha256" - ], - "profile_selector": { - "color_flow_request": color_flow_request, - "resolved_color_flow_id": None, - "helicity_request": gate.SELECTED_UNION_HELICITY_ID, - "resolved_helicity_id": gate.SELECTED_UNION_HELICITY_ID, - "color_flow_count": gate.SELECTED_UNION_COLOR_COUNT, - "helicity_count": helicities["count"], - "workload": "all-flows/runtime-selected-single-helicity", - }, - "resolved_color_ids_sha256": _sha256(colors["ordered_ids"]), - } - - -def _sample( - *, - role: str, - layout: str, - identifier: int, - schedule_index: int, - round_index: int, - batch_size: int, - runtime: float, - cold_load: float, - cold_rss: int, - profiled_rss: int, -) -> tuple[dict[str, object], dict[str, object]]: - _, started, finished, recorded = _slot_times( - role=role, - layout=layout, - schedule_index=schedule_index, - round_index=round_index, - ) - invocation = _address( - { - "kind": "invocation", - "identifier": identifier, - "role": role, - "layout": layout, - "started_at_utc": started.isoformat(), - "finished_at_utc": finished.isoformat(), - "wall_seconds": 12.0, - } - ) - process_record = _address( - { - "kind": "worker-process", - "identifier": identifier, - "role": role, - "layout": layout, - "wall_seconds": 12.0, - } - ) - block_count = gate.MINIMUM_INTERNAL_SAMPLES - repetitions = math.ceil( - (5.0 * 1.02) / (block_count * runtime * batch_size) - ) - blocks: list[dict[str, object]] = [] - for block_index in range(block_count): - native = runtime * repetitions * batch_size - block = _address( - { - "block_index": block_index, - "started_at_utc": ( - started + dt.timedelta(microseconds=block_index) - ).isoformat(), - "finished_at_utc": ( - started + dt.timedelta(microseconds=block_index + 1) - ).isoformat(), - "caller_elapsed_seconds": native, - "native_wall_seconds": native, - "wall_seconds_per_point": runtime, - "repetitions": repetitions, - "batch_size": batch_size, - "evaluation_count": repetitions, - "evaluated_point_count": repetitions * batch_size, - } - ) - blocks.append(block) - observed_native = sum(float(block["native_wall_seconds"]) for block in blocks) - raw_native_wall = { - "kind": gate.RAW_NATIVE_WALL_BLOCK_KIND, - "schema_version": gate.RAW_NATIVE_WALL_BLOCK_SCHEMA, - "measurement_contract": gate.RAW_NATIVE_WALL_MEASUREMENT_CONTRACT, - "source": "runtime._benchmark_f64_wall_time", - "fixture_points_sha256": "b" * 64, - "minimum_native_wall_seconds": 5.0, - "observed_native_wall_seconds": observed_native, - "observed_caller_elapsed_seconds": observed_native, - "minimum_duration_satisfied": True, - "calibration": { - "kind": "benchmark-runner-wall-rate-calibration", - "schema_version": 1, - "benchmark_runner_sample_count": 20, - "benchmark_runner_repetitions_per_sample": 1, - "benchmark_runner_total_repetitions": 20, - "benchmark_runner_wall_seconds_per_point": runtime, - "requested_minimum_block_count": block_count, - "preceded_by_benchmark_runner_warmup_runs": 2, - "duration_headroom_factor": 1.02, - "scaled_repetitions_per_block": repetitions, - }, - "block_count": block_count, - "repetitions_per_block": repetitions, - "evaluation_count": block_count * repetitions, - "evaluated_point_count": block_count * repetitions * batch_size, - "wall_seconds_per_point_median": runtime, - "wall_seconds_per_point_mad": 0.0, - "blocks": blocks, - "blocks_sha256": _sha256(blocks), - } - worker_measurement = { - "batch_size": batch_size, - "sample_count": block_count, - "repetitions_per_sample": repetitions, - "evaluation_count": block_count * repetitions, - "evaluated_point_count": block_count * repetitions * batch_size, - "wall_seconds_per_point": runtime, - "inner_native_wall_blocks": raw_native_wall, - "benchmark_runner_sample_count": 20, - "benchmark_runner_repetitions_per_sample": 1, - "benchmark_runner_evaluation_count": 20, - "benchmark_runner_evaluated_point_count": 20 * batch_size, - "benchmark_runner_wall_seconds_per_point": runtime, - } - sample: dict[str, object] = { - "schedule_index": schedule_index, - "round": round_index, - "wall_seconds_per_point": runtime, - "cold_load_seconds": cold_load, - "peak_rss_after_cold_load": _peak(cold_rss), - "peak_rss_after_profile": _peak(profiled_rss), - "internal_sample_count": block_count, - "repetitions_per_sample": repetitions, - "evaluation_count": block_count * repetitions, - "evaluated_point_count": block_count * repetitions * batch_size, - "inner_native_wall_blocks": raw_native_wall, - "worker_measurement": worker_measurement, - "interrupted": False, - "timing_configuration": { - "minimum_internal_samples": 7, - "warmup_runs": 2, - "target_runtime_seconds": 5.0, - }, - "timing_sources": {"wall": "runtime_core_repeated_wall_time"}, - "worker_invocation": invocation, - "worker_process_record": process_record, - } - result_record = { - "kind": "pyamplicol-retained-profile-worker-result", - "schema_version": 1, - "recorded_at_utc": recorded.isoformat(), - "addressed_payload_sha256": _sha256(sample), - "upstream_worker_result_record_sha256": "a" * 64, - "worker_process_record_sha256": process_record["content_sha256"], - "worker_invocation_sha256": invocation["content_sha256"], - } - sample["worker_result_record"] = _address(result_record) - schedule_entry = { - "schedule_index": schedule_index, - "round": round_index, - "worker_result_sha256": result_record["addressed_payload_sha256"], - "worker_invocation": invocation, - "worker_result_record": sample["worker_result_record"], - } - return sample, schedule_entry - - -def _aggregate(batch_size: int, samples: list[dict[str, object]]) -> dict[str, object]: - runtime = [float(sample["wall_seconds_per_point"]) for sample in samples] - cold = [float(sample["cold_load_seconds"]) for sample in samples] - cold_rss = [ - float(sample["peak_rss_after_cold_load"]["observed_lower_bound_bytes"]) - for sample in samples - ] - profiled_rss = [ - float(sample["peak_rss_after_profile"]["observed_lower_bound_bytes"]) - for sample in samples - ] - runtime_median, runtime_mad = _statistics(runtime) - cold_median, cold_mad = _statistics(cold) - cold_rss_median, _ = _statistics(cold_rss) - profiled_rss_median, _ = _statistics(profiled_rss) - return { - "batch_size": batch_size, - "sample_count": len(samples), - "subprocess_sample_count": len(samples), - "wall_seconds_per_point": runtime_median, - "wall_seconds_per_point_median": runtime_median, - "wall_seconds_per_point_mad": runtime_mad, - "statistics_contract": "subprocess-median-and-raw-mad-v1", - "cold_load_seconds_median": cold_median, - "cold_load_seconds_mad": cold_mad, - "cold_load_peak_rss_bytes_median": cold_rss_median, - "profiled_peak_rss_bytes_median": profiled_rss_median, - "resource_statistics_contract": "subprocess-median-and-raw-mad-v1", - "subprocess_samples": samples, - "interrupted": False, - } - - -def _capture( - *, - role: str, - layout: str, - process: str, - runtime_ratio: float = 1.0, - compiled_to_recurrence_ratio: float = 1.05, - generation_ratio: float = 1.0, - resource_ratio: float = 1.0, - eager_runtime_ratio: float = 1.0, - eager_generation_ratio: float = 1.0, - eager_resource_ratio: float = 1.0, -) -> dict[str, object]: - candidate = role == "candidate" - revision = "2" * 40 if candidate else gate.BASELINE_REVISION - interpreter_path = "/synthetic/shared/bin/python" - prepared_model_path = f"/synthetic/{role}/prepared-model.pack" - prepared_model_sha256 = ("9" if candidate else "8") * 64 - runtime_role_ratio = runtime_ratio if candidate else 1.0 - generation_role_ratio = generation_ratio if candidate else 1.0 - resource_role_ratio = resource_ratio if candidate else 1.0 - eager_runtime_role_ratio = eager_runtime_ratio if candidate else 1.0 - eager_generation_role_ratio = eager_generation_ratio if candidate else 1.0 - eager_resource_role_ratio = eager_resource_ratio if candidate else 1.0 - workload = ( - "single-runtime-selected-flow/helicity-sum" - if layout == "topology-replay" - else "all-flows/runtime-selected-single-helicity" - ) - selected_union = process.casefold().startswith("d ") and layout == "all-flow-union" - selected_union_helicity_count = gate.SELECTED_UNION_HELICITY_INDEX + 1 - selector = { - "color_flow_count": (gate.SELECTED_UNION_COLOR_COUNT if selected_union else 2), - "helicity_count": selected_union_helicity_count if selected_union else 2, - "workload": workload, - "color_flow_request": "flow:2,1" if layout == "topology-replay" else "1", - "helicity_request": ( - "1" - if layout == "topology-replay" - else gate.SELECTED_UNION_HELICITY_ID - if selected_union - else "h:-1,+1" - ), - "resolved_color_flow_id": ("flow:2,1" if layout == "topology-replay" else None), - "resolved_helicity_id": ( - None - if layout == "topology-replay" - else gate.SELECTED_UNION_HELICITY_ID - if selected_union - else "h:-1,+1" - ), - "structural_zero_helicity_count": 0, - } - color_request = selector["color_flow_request"] - helicity_request = selector["helicity_request"] - generation: dict[str, object] = {} - profiles: dict[str, object] = {} - samples_by_cell: dict[tuple[str, int], list[dict[str, object]]] = { - (mode, batch): [] for mode in ALL_MODES for batch in gate.BATCH_SIZES - } - schedule_entries: list[dict[str, object]] = [] - schedule_index = 0 - identifier = 1 - deviations = (-0.003, -0.002, -0.001, 0.0, 0.001, 0.002, 0.003) - for round_index, deviation in enumerate(deviations): - offset = round_index % len(ALL_MODES) - modes = ALL_MODES[offset:] + ALL_MODES[:offset] - for batch_size in gate.BATCH_SIZES: - for mode in modes: - mode_ratio = ( - compiled_to_recurrence_ratio - if mode == "compiled" - else 1.02 - if mode == "eager" - else 1.0 - ) - base_runtime = ( - 1.0e-6 - * (1.0 + 0.1 * gate.BATCH_SIZES.index(batch_size)) - * mode_ratio - ) - mode_runtime_ratio = ( - runtime_role_ratio * eager_runtime_role_ratio - if mode == "eager" - else runtime_role_ratio - ) - mode_resource_ratio = ( - resource_role_ratio * eager_resource_role_ratio - if mode == "eager" - else resource_role_ratio - ) - runtime = base_runtime * mode_runtime_ratio * (1.0 + deviation) - sample, entry = _sample( - role=role, - layout=layout, - identifier=identifier, - schedule_index=schedule_index, - round_index=round_index, - batch_size=batch_size, - runtime=runtime, - cold_load=0.2 * mode_resource_ratio * (1.0 + deviation), - cold_rss=int(100_000_000 * mode_resource_ratio * (1.0 + deviation)), - profiled_rss=int( - 120_000_000 * mode_resource_ratio * (1.0 + deviation) - ), - ) - entry.update({"mode": mode, "batch_size": batch_size}) - schedule_entries.append(entry) - samples_by_cell[(mode, batch_size)].append(sample) - identifier += 1 - schedule_index += 1 - - for mode in ALL_MODES: - semantic = _semantic_identity( - layout, - mode, - selected_union=selected_union, - ) - semantic_sha256 = _sha256(semantic) - optimization = 3 if mode == "compiled" else 2 - mode_generation_ratio = ( - generation_role_ratio * eager_generation_role_ratio - if mode == "eager" - else generation_role_ratio - ) - mode_resource_ratio = ( - resource_role_ratio * eager_resource_role_ratio - if mode == "eager" - else resource_role_ratio - ) - generation[mode] = { - "mode": mode, - "generation_wall_seconds": ( - (12.0 if mode == "compiled" else 11.0 if mode == "eager" else 10.0) - * mode_generation_ratio - ), - "generation_reused": False, - "peak_rss": _peak(int(400_000_000 * mode_resource_ratio)), - "artifact_stats": { - "file_count": 4, - "size_bytes": int(10_000_000 * mode_resource_ratio), - }, - "artifact_identity": { - "semantic_identity": semantic, - "semantic_identity_sha256": semantic_sha256, - }, - "effective_contract": { - "backend": "jit", - "color_accuracy": "lc", - "execution_mode": mode, - "jit_optimization_level": optimization, - "lc_flow_layout": layout, - }, - } - physical_colors = semantic["physical_color_flows"] - assert isinstance(physical_colors, dict) - mode_selector = dict(selector) - if selected_union and mode == "compiled": - mode_selector["structural_zero_helicity_count"] = ( - selected_union_helicity_count - 1 - ) - profiles[mode] = { - "mode": mode, - "process_expression": process, - "process_id": "d_dbar_to_z_6g" - if process.startswith("d ") - else "u_ubar_to_z_6g", - "selector_contract": mode_selector, - "validation": { - "passes": True, - "fixture": { - "point_count": 1, - "points_sha256": "b" * 64, - }, - **( - { - "resolved_color_ids": physical_colors["ordered_ids"], - "resolved_helicity_ids": [gate.SELECTED_UNION_HELICITY_ID], - } - if selected_union - else {} - ), - }, - "artifact_semantic_identity": semantic, - "artifact_semantic_identity_sha256": semantic_sha256, - "profiles": [ - _aggregate(batch, samples_by_cell[(mode, batch)]) - for batch in gate.BATCH_SIZES - ], - } - - native_sha = "d" * 64 if candidate else "c" * 64 - build_inputs_sha = "f" * 64 if candidate else "e" * 64 - lane_measurements = { - mode: { - "passes": True, - "observed_batch_sizes": list(gate.BATCH_SIZES), - "missing_batch_sizes": [], - "errors": [], - } - for mode in gate.CAPTURE_MODES - } - if selected_union: - selected_union_projections = { - mode: _selected_union_projection( - profiles[mode]["artifact_semantic_identity"], - process_id="d_dbar_to_z_6g", - color_flow_request=str(color_request), - ) - for mode in gate.CAPTURE_MODES - } - assert ( - len({_sha256(value) for value in selected_union_projections.values()}) == 1 - ) - common_physics_contract = selected_union_projections["compiled"] - artifact_lane_contracts = { - mode: { - "synthetic_lane_identity": mode, - "selected_union_workload_projection": projection, - } - for mode, projection in selected_union_projections.items() - } - comparison_policy = gate.SELECTED_UNION_SEMANTIC_COMPARISON_POLICY - else: - common_physics_contract = {"synthetic": True} - artifact_lane_contracts = { - mode: {"synthetic_lane_identity": mode} for mode in gate.CAPTURE_MODES - } - comparison_policy = gate.STRICT_SEMANTIC_COMPARISON_POLICY - eager_measurement = { - "passes": True, - "lanes": { - "eager": { - "passes": True, - "observed_batch_sizes": list(gate.BATCH_SIZES), - "missing_batch_sizes": [], - "errors": [], - } - }, - } - capture_acceptance = { - "kind": "pyamplicol-three-lane-layout-capture", - "schema_version": 6, - "complete": True, - "evidence_complete": True, - "passes": True, - "authoritative_eligible": True, - "authoritative_ineligibility_reasons": [], - "generation_specialized_axes_by_mode": {}, - "incomplete_physical_axes": [], - "required_modes": list(gate.CAPTURE_MODES), - "observed_modes": list(gate.CAPTURE_MODES), - "missing_modes": [], - "diagnostic_modes": list(gate.DIAGNOSTIC_MODES), - "eager_diagnostic": { - "requested": True, - "observed": True, - "complete": True, - "passes": True, - "measurement_contract": eager_measurement, - "artifact_semantic_contract": { - "passes": True, - "errors": [], - "lanes_match": True, - }, - "validation_summary": {"passes": True}, - "ineligibility_reasons": [], - }, - "required_batch_sizes": list(gate.BATCH_SIZES), - "observed_batch_sizes": list(gate.BATCH_SIZES), - "missing_batch_sizes": [], - "measurement_contract": { - "passes": True, - "lanes": lane_measurements, - "minimum_authoritative_samples": 7, - "configured_internal_minimum_samples": 7, - "configured_subprocess_samples": 7, - "configured_warmup_runs": 2, - "root_processes_match": True, - "schedule": { - "passes": True, - "errors": [], - "entry_count": len(schedule_entries), - "unique_worker_command_count": len(schedule_entries), - "subprocess_samples_per_cell": 7, - }, - }, - "artifact_semantic_contract": { - "passes": True, - "errors": [], - "lanes_match": True, - "comparison_policy": comparison_policy, - "lane_contracts": artifact_lane_contracts, - "common_physics_contract": common_physics_contract, - }, - "layout": layout, - "generation_only": False, - "lane_self_validation_passes": True, - "pairwise_validation_passes": True, - } - session_id = "synthetic-paired-session" - plan = [ - { - field: entry[field] - for field in ("schedule_index", "round", "mode", "batch_size") - } - for entry in schedule_entries - ] - ready = _address( - { - "kind": "pyamplicol-paired-profile-ready", - "schema_version": 1, - "session_id": session_id, - "role": role, - "layout": layout, - "source_revision": revision, - "ready_at_utc": ( - _layout_epoch(layout) - dt.timedelta(seconds=1) - ).isoformat(), - "profile_schedule_plan": plan, - "profile_schedule_plan_sha256": _sha256(plan), - } - ) - completions: list[dict[str, object]] = [] - for entry in schedule_entries: - index = int(entry["schedule_index"]) - round_index = int(entry["round"]) - expected_order = ( - ("baseline", "candidate") - if round_index % 2 == 0 - else ("candidate", "baseline") - ) - order = expected_order.index(role) - issued, started, finished, recorded = _slot_times( - role=role, - layout=layout, - schedule_index=index, - round_index=round_index, - ) - token = _address( - { - "kind": "pyamplicol-paired-profile-token", - "schema_version": 1, - "session_id": session_id, - "role": role, - "layout": layout, - **{ - field: entry[field] - for field in ("schedule_index", "round", "mode", "batch_size") - }, - "pair_index": index, - "order_in_pair": order, - "issued_at_utc": issued.isoformat(), - } - ) - completion = _address( - { - "kind": "pyamplicol-paired-profile-completion", - "schema_version": 1, - "session_id": session_id, - "role": role, - "layout": layout, - **{ - field: entry[field] - for field in ("schedule_index", "round", "mode", "batch_size") - }, - "token_sha256": token["content_sha256"], - "worker_invocation_sha256": entry["worker_invocation"][ - "content_sha256" - ], - "worker_result_record_sha256": entry["worker_result_record"][ - "content_sha256" - ], - "worker_started_at_utc": started.isoformat(), - "worker_finished_at_utc": finished.isoformat(), - "recorded_at_utc": recorded.isoformat(), - } - ) - entry["paired_profile_token"] = token - entry["paired_profile_completion"] = completion - completions.append(completion) - return { - "kind": gate.CAPTURE_KIND, - "schema_version": gate.MINIMUM_CAPTURE_SCHEMA, - "complete": True, - "passes": True, - "capture_acceptance": capture_acceptance, - "process": process, - "process_name": ("ddbar_Z_6g" if process.startswith("d ") else "uubar_Z_6g"), - "workload": workload, - "source": { - "revision": revision, - "dirty": False, - "untracked_files_checked": True, - }, - "provenance": { - "host": { - "system": "TestOS", - "machine": "test64", - "cpu_model": "synthetic", - "logical_cpu_count": 8, - } - }, - "runtime_provenance": { - "interpreter": { - "implementation": "CPython", - "python_version": "3.12.6", - "path": interpreter_path, - "resolved_path": interpreter_path, - "sha256": "1" * 64, - }, - "native_extension": { - "sha256": native_sha, - "build_inputs_sha256": build_inputs_sha, - "package_version": "0.1.0+candidate", - }, - "active_build_info": { - "payload": { - "source_revision": revision, - "version": "0.1.0+candidate", - } - }, - }, - "configuration": { - "batch_sizes": list(gate.BATCH_SIZES), - "target_runtime_seconds": 5.0, - "minimum_samples": 7, - "subprocess_samples": 7, - "warmup_runs": 2, - "color_flow_request": color_request, - "helicity_request": helicity_request, - "lc_flow_layout": layout, - "validation_seed": 12345, - "point_tile_size": 1024, - "jit_optimization_level": 3, - "generation_only": False, - "modes": list(ALL_MODES), - "model_identities": { - mode: { - "kind": "explicit-prepared-model", - "resource_id": None, - "file": { - "path": prepared_model_path, - "resolved_path": prepared_model_path, - "size_bytes": 1234, - "sha256": prepared_model_sha256, - }, - "compile_excluded_from_generation": True, - } - for mode in ALL_MODES - }, - }, - "generation": generation, - "profile_schedule": { - "kind": "pyamplicol-interleaved-subprocess-profile-schedule", - "schema_version": 2, - "algorithm": "round-major-cyclic-mode-and-batch-interleave-v1", - "sample_unit": "independent-profile-worker-subprocess", - "subprocess_samples_per_cell": 7, - "modes": list(ALL_MODES), - "batch_sizes": list(gate.BATCH_SIZES), - "entries": schedule_entries, - }, - "profiles": profiles, - "paired_profile_coordination": { - "kind": "pyamplicol-paired-profile-coordination", - "schema_version": 1, - "session_id": session_id, - "role": role, - "layout": layout, - "ready_record": ready, - "completion_records": completions, - }, - "validation_summary": { - "passes": True, - "selectors_match": True, - "fixtures_match": True, - "lane_validation_passes": True, - "pairwise_validation_passes": True, - }, - "selector_contracts_match": True, - "validation_fixtures_match": True, - } - - -def _write_campaign( - tmp_path: Path, - *, - process: str = "d d~ > Z g g g g g g", - runtime_ratio: float = 1.0, - compiled_to_recurrence_ratio: float = 1.05, - generation_ratio: float = 1.0, - resource_ratio: float = 1.0, - eager_runtime_ratio: float = 1.0, - eager_generation_ratio: float = 1.0, - eager_resource_ratio: float = 1.0, -) -> dict[str, Path]: - tmp_path.mkdir(parents=True, exist_ok=True) - result: dict[str, Path] = {} - for role in ("baseline", "candidate"): - for layout in gate.LAYOUTS: - payload = _capture( - role=role, - layout=layout, - process=process, - runtime_ratio=runtime_ratio, - compiled_to_recurrence_ratio=compiled_to_recurrence_ratio, - generation_ratio=generation_ratio, - resource_ratio=resource_ratio, - eager_runtime_ratio=eager_runtime_ratio, - eager_generation_ratio=eager_generation_ratio, - eager_resource_ratio=eager_resource_ratio, - ) - path = tmp_path / f"{role}-{layout}.json" - path.write_bytes(_canonical(payload) + b"\n") - result[f"{role}-{layout}"] = path - campaign_path = tmp_path / "paired-campaign.json" - campaign_path.write_bytes( - _canonical(_paired_campaign_record(result, process=process)) + b"\n" - ) - result["campaign"] = campaign_path - watchdog_path = tmp_path / "memory-watchdog-report.json" - watchdog_path.write_bytes( - _canonical(_watchdog_report_record(campaign_path)) + b"\n" - ) - result["watchdog-report"] = watchdog_path - return result - - -def _file_identity(path: Path) -> dict[str, object]: - resolved = path.resolve(strict=True) - data = resolved.read_bytes() - return { - "path": str(path), - "resolved_path": str(resolved), - "size_bytes": len(data), - "sha256": hashlib.sha256(data).hexdigest(), - } - - -def _watchdog_report_record(campaign_path: Path) -> dict[str, object]: - campaign = json.loads(campaign_path.read_text()) - result_identity = _file_identity(campaign_path) - command = [ - campaign["roles"]["candidate"]["python"], - str(ROOT / gate.PAIRED_DRIVER_RELATIVE_PATH), - "--result-json", - str(campaign_path), - "--session-id", - campaign["session_id"], - ] - return _address( - { - "kind": gate.WATCHDOG_REPORT_KIND, - "schema_version": gate.WATCHDOG_REPORT_SCHEMA, - "complete": True, - "passes": True, - "watchdog": _file_identity(ROOT / gate.WATCHDOG_RELATIVE_PATH), - "working_directory": str(ROOT), - "execution": { - "command": command, - "command_sha256": _sha256(command), - "started_at_utc": ( - dt.datetime.fromisoformat(campaign["started_at_utc"]) - - dt.timedelta(seconds=1) - ).isoformat(), - "finished_at_utc": ( - dt.datetime.fromisoformat(campaign["finished_at_utc"]) - + dt.timedelta(seconds=1) - ).isoformat(), - "elapsed_wall_seconds": 20_000.0, - "child_pid": 4242, - "child_exit_code": 0, - "watchdog_exit_code": 0, - "outcome": "command-finished", - "reason": None, - }, - "enforcement": { - "scope": gate.WATCHDOG_SCOPE, - "limit_bytes": gate.WATCHDOG_LIMIT_BYTES, - "poll_interval_seconds": 0.25, - "terminate_grace_seconds": 5.0, - "metric": "process-tree-rss", - "probe_sample_count": 80_000, - "probe_failure_count": 0, - "maximum_consecutive_probe_failures": 0, - "completed_under_retry_policy": True, - "peak_rss_bytes": 10 * 1024**3, - "peak_physical_footprint_bytes": None, - "peak_guard_bytes": 10 * 1024**3, - "peak_processes": 4, - }, - "result_binding": { - "requested": True, - "requested_path": str(campaign_path), - "identity": result_identity, - "error": None, - }, - } - ) - - -def _paired_campaign_record( - paths: dict[str, Path], - *, - process: str, -) -> dict[str, object]: - captures = { - role: { - layout: json.loads(paths[f"{role}-{layout}"].read_text()) - for layout in gate.LAYOUTS - } - for role in ("baseline", "candidate") - } - harness_path = ROOT / gate.PAIRED_HARNESS_RELATIVE_PATH - harness_sha256 = hashlib.sha256(harness_path.read_bytes()).hexdigest() - harness = _address( - { - "kind": gate.PAIRED_HARNESS_KIND, - "schema_version": gate.PAIRED_HARNESS_SCHEMA, - "candidate_relative_path": gate.PAIRED_HARNESS_RELATIVE_PATH, - "head_blob_sha256": harness_sha256, - "working_file_sha256": harness_sha256, - "head_blob_equals_working_file": True, - } - ) - orchestrator_path = ROOT / gate.PAIRED_DRIVER_RELATIVE_PATH - orchestrator_sha256 = hashlib.sha256(orchestrator_path.read_bytes()).hexdigest() - orchestrator = _address( - { - "kind": gate.PAIRED_HARNESS_KIND, - "schema_version": gate.PAIRED_HARNESS_SCHEMA, - "candidate_relative_path": gate.PAIRED_DRIVER_RELATIVE_PATH, - "head_blob_sha256": orchestrator_sha256, - "working_file_sha256": orchestrator_sha256, - "head_blob_equals_working_file": True, - } - ) - layouts: dict[str, object] = {} - latest_recorded = _TEST_EPOCH - for layout in gate.LAYOUTS: - pairs: list[dict[str, object]] = [] - baseline_entries = captures["baseline"][layout]["profile_schedule"]["entries"] - candidate_entries = captures["candidate"][layout]["profile_schedule"]["entries"] - for pair_index, (baseline_entry, candidate_entry) in enumerate( - zip(baseline_entries, candidate_entries, strict=True) - ): - assert all( - baseline_entry[field] == candidate_entry[field] - for field in ("schedule_index", "round", "mode", "batch_size") - ) - round_index = baseline_entry["round"] - role_order = ( - ["baseline", "candidate"] - if round_index % 2 == 0 - else ["candidate", "baseline"] - ) - completions = { - "baseline": baseline_entry["paired_profile_completion"], - "candidate": candidate_entry["paired_profile_completion"], - } - for completion in completions.values(): - latest_recorded = max( - latest_recorded, - dt.datetime.fromisoformat(completion["recorded_at_utc"]), - ) - pairs.append( - _address( - { - "kind": "pyamplicol-paired-profile-pair", - "schema_version": 1, - "pair_index": pair_index, - **{ - field: baseline_entry[field] - for field in ( - "schedule_index", - "round", - "mode", - "batch_size", - ) - }, - "role_order": role_order, - "completions": completions, - } - ) - ) - layouts[layout] = { - "layout": layout, - "ready_records": { - role: captures[role][layout]["paired_profile_coordination"][ - "ready_record" - ] - for role in ("baseline", "candidate") - }, - "paired_schedule_algorithm": ( - "slot-adjacent-round-alternating-role-order-v1" - ), - "pairs": pairs, - "captures": { - role: _file_identity(paths[f"{role}-{layout}"]) - for role in ("baseline", "candidate") - }, - } - roles = {} - for role in ("baseline", "candidate"): - capture = captures[role]["topology-replay"] - runtime = capture["runtime_provenance"]["interpreter"] - model = capture["configuration"]["model_identities"]["recurrence"]["file"] - roles[role] = { - "source_root": f"/synthetic/{role}/source", - "source_revision": capture["source"]["revision"], - "python": runtime["path"], - "python_resolved_target": runtime["resolved_path"], - "python_sha256": runtime["sha256"], - "prepared_model": model["resolved_path"], - "prepared_model_sha256": model["sha256"], - } - topology_configuration = captures["baseline"]["topology-replay"]["configuration"] - expanded_process = ( - "d d~ > Z g g g g g g" - if process.casefold().startswith("d ") - else "u u~ > Z g g g g g g" - ) - return _address( - { - "kind": gate.PAIRED_CAMPAIGN_KIND, - "schema_version": gate.PAIRED_CAMPAIGN_SCHEMA, - "complete": True, - "session_id": "synthetic-paired-session", - "started_at_utc": (_TEST_EPOCH - dt.timedelta(seconds=2)).isoformat(), - "finished_at_utc": ( - latest_recorded + dt.timedelta(seconds=1) - ).isoformat(), - "process": expanded_process, - "orchestrator": orchestrator, - "harness": harness, - "roles": roles, - "configuration": { - "authoritative_modes": list(gate.AUTHORITATIVE_MODES), - "diagnostic_modes": list(gate.DIAGNOSTIC_MODES), - "batch_sizes": list(gate.BATCH_SIZES), - "target_runtime_seconds": topology_configuration[ - "target_runtime_seconds" - ], - "minimum_samples": topology_configuration["minimum_samples"], - "subprocess_samples": topology_configuration["subprocess_samples"], - "warmup_runs": topology_configuration["warmup_runs"], - "watchdog": { - "required": True, - "report_kind": gate.WATCHDOG_REPORT_KIND, - "report_schema_version": gate.WATCHDOG_REPORT_SCHEMA, - "limit_bytes": gate.WATCHDOG_LIMIT_BYTES, - "scope": gate.WATCHDOG_SCOPE, - "binding": gate.WATCHDOG_BINDING, - }, - }, - "layouts": layouts, - } - ) - - -def _compare( - paths: dict[str, Path], - **expected_overrides: str, -) -> dict[str, object]: - expected = { - "expected_candidate_source_revision": EXPECTED_CANDIDATE_REVISION, - "expected_baseline_native_build_inputs_sha256": ( - EXPECTED_BASELINE_NATIVE_BUILD_INPUTS - ), - "expected_candidate_native_build_inputs_sha256": ( - EXPECTED_CANDIDATE_NATIVE_BUILD_INPUTS - ), - "expected_baseline_prepared_model_sha256": ( - EXPECTED_BASELINE_PREPARED_MODEL - ), - "expected_candidate_prepared_model_sha256": ( - EXPECTED_CANDIDATE_PREPARED_MODEL - ), - } - expected.update(expected_overrides) - return gate.compare_capture_files( - campaign=paths["campaign"], - watchdog_report=paths["watchdog-report"], - baseline_topology=paths["baseline-topology-replay"], - baseline_all_flow_union=paths["baseline-all-flow-union"], - candidate_topology=paths["candidate-topology-replay"], - candidate_all_flow_union=paths["candidate-all-flow-union"], - **expected, - ) - - -def _write_payload(path: Path, payload: dict[str, object]) -> None: - path.write_bytes(_canonical(payload) + b"\n") - - -def _readdress(record: dict[str, object]) -> dict[str, object]: - unsigned = dict(record) - unsigned.pop("content_sha256", None) - return _address(unsigned) - - -def _entry_and_sample( - payload: dict[str, object], - schedule_index: int, -) -> tuple[dict[str, object], dict[str, object]]: - entry = payload["profile_schedule"]["entries"][schedule_index] - mode = entry["mode"] - batch_size = entry["batch_size"] - aggregate = next( - aggregate - for aggregate in payload["profiles"][mode]["profiles"] - if aggregate["batch_size"] == batch_size - ) - sample = next( - sample - for sample in aggregate["subprocess_samples"] - if sample["schedule_index"] == schedule_index - ) - return entry, sample - - -def _replace_completion( - payload: dict[str, object], - schedule_index: int, - completion: dict[str, object], -) -> None: - entry = payload["profile_schedule"]["entries"][schedule_index] - entry["paired_profile_completion"] = completion - payload["paired_profile_coordination"]["completion_records"][ - schedule_index - ] = completion - - -def _replace_worker_provenance( - payload: dict[str, object], - schedule_index: int, - *, - invocation: dict[str, object], - process_record: dict[str, object], -) -> None: - entry, sample = _entry_and_sample(payload, schedule_index) - old_result = sample.pop("worker_result_record") - sample["worker_invocation"] = invocation - sample["worker_process_record"] = process_record - result_unsigned = dict(old_result) - result_unsigned.pop("content_sha256") - result_unsigned["addressed_payload_sha256"] = _sha256(sample) - result_unsigned["worker_invocation_sha256"] = invocation["content_sha256"] - result_unsigned["worker_process_record_sha256"] = process_record["content_sha256"] - invocation_finished = dt.datetime.fromisoformat(invocation["finished_at_utc"]) - result_unsigned["recorded_at_utc"] = ( - invocation_finished + dt.timedelta(milliseconds=500) - ).isoformat() - result = _address(result_unsigned) - sample["worker_result_record"] = result - entry["worker_invocation"] = invocation - entry["worker_result_record"] = result - entry["worker_result_sha256"] = result_unsigned["addressed_payload_sha256"] - completion_unsigned = dict(entry["paired_profile_completion"]) - completion_unsigned.pop("content_sha256") - completion_unsigned["worker_invocation_sha256"] = invocation["content_sha256"] - completion_unsigned["worker_result_record_sha256"] = result["content_sha256"] - completion_unsigned["worker_started_at_utc"] = invocation["started_at_utc"] - completion_unsigned["worker_finished_at_utc"] = invocation["finished_at_utc"] - completion_unsigned["recorded_at_utc"] = result_unsigned["recorded_at_utc"] - _replace_completion( - payload, - schedule_index, - _address(completion_unsigned), - ) - - -def _replace_token_issued_at( - payload: dict[str, object], - schedule_index: int, - issued_at: dt.datetime, -) -> None: - entry = payload["profile_schedule"]["entries"][schedule_index] - token = dict(entry["paired_profile_token"]) - token["issued_at_utc"] = issued_at.isoformat() - token = _readdress(token) - entry["paired_profile_token"] = token - completion = dict(entry["paired_profile_completion"]) - completion["token_sha256"] = token["content_sha256"] - _replace_completion(payload, schedule_index, _readdress(completion)) - - -def _replace_ready_at(payload: dict[str, object], ready_at: dt.datetime) -> None: - ready = dict(payload["paired_profile_coordination"]["ready_record"]) - ready["ready_at_utc"] = ready_at.isoformat() - payload["paired_profile_coordination"]["ready_record"] = _readdress(ready) - - -def _rewrite_campaign( - path: Path, - mutation: object, - *, - readdress_harness: bool = False, - readdress_outer: bool = True, -) -> None: - payload = json.loads(path.read_text()) - assert callable(mutation) - mutation(payload) - if readdress_harness: - payload["harness"] = _readdress(payload["harness"]) - if readdress_outer: - payload = _readdress(payload) - _write_payload(path, payload) - - -def _rewrite_watchdog_report( - path: Path, - mutation: object, - *, - readdress: bool = True, -) -> None: - payload = json.loads(path.read_text()) - assert callable(mutation) - mutation(payload) - if readdress: - payload = _readdress(payload) - _write_payload(path, payload) - - -def _rebind_retained_sample( - payload: dict[str, object], - schedule_index: int, -) -> None: - entry, sample = _entry_and_sample(payload, schedule_index) - prior = sample.pop("worker_result_record") - result = dict(prior) - result.pop("content_sha256") - result["addressed_payload_sha256"] = _sha256(sample) - rebound = _address(result) - sample["worker_result_record"] = rebound - entry["worker_result_record"] = rebound - entry["worker_result_sha256"] = result["addressed_payload_sha256"] - completion = dict(entry["paired_profile_completion"]) - completion["worker_result_record_sha256"] = rebound["content_sha256"] - _replace_completion(payload, schedule_index, _readdress(completion)) - - -def _refresh_mode_semantic( - payload: dict[str, object], - mode: str, -) -> dict[str, object]: - semantic = payload["profiles"][mode]["artifact_semantic_identity"] - digest = _sha256(semantic) - payload["profiles"][mode]["artifact_semantic_identity_sha256"] = digest - payload["generation"][mode]["artifact_identity"]["semantic_identity"] = ( - copy.deepcopy(semantic) - ) - payload["generation"][mode]["artifact_identity"]["semantic_identity_sha256"] = ( - digest - ) - return semantic - - -def _rebuild_selected_union_projections(payload: dict[str, object]) -> None: - color_request = payload["configuration"]["color_flow_request"] - projections = { - mode: _selected_union_projection( - payload["profiles"][mode]["artifact_semantic_identity"], - process_id="d_dbar_to_z_6g", - color_flow_request=color_request, - ) - for mode in gate.CAPTURE_MODES - } - assert len({_sha256(value) for value in projections.values()}) == 1 - contract = payload["capture_acceptance"]["artifact_semantic_contract"] - contract["common_physics_contract"] = projections["compiled"] - for mode, projection in projections.items(): - contract["lane_contracts"][mode]["selected_union_workload_projection"] = ( - projection - ) - - -def test_gate_rejects_split_schedule_and_sample_worker_provenance( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - entry, sample = _entry_and_sample(payload, 0) - invocation = dict(sample["worker_invocation"]) - invocation["identifier"] = 999_001 - invocation = _readdress(invocation) - result = dict(sample["worker_result_record"]) - result["worker_invocation_sha256"] = invocation["content_sha256"] - result = _readdress(result) - entry["worker_invocation"] = invocation - entry["worker_result_record"] = result - completion = dict(entry["paired_profile_completion"]) - completion["worker_invocation_sha256"] = invocation["content_sha256"] - completion["worker_result_record_sha256"] = result["content_sha256"] - _replace_completion(payload, 0, _readdress(completion)) - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match="sample worker provenance differs"): - _compare(paths) - - -def test_gate_rejects_global_cross_role_worker_identity_reuse( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - baseline_path = paths["baseline-topology-replay"] - candidate_path = paths["candidate-topology-replay"] - baseline = json.loads(baseline_path.read_text()) - candidate = json.loads(candidate_path.read_text()) - started = _TEST_EPOCH + dt.timedelta(seconds=14) - invocation = _address( - { - "kind": "shared-forged-invocation", - "started_at_utc": started.isoformat(), - "finished_at_utc": (started + dt.timedelta(seconds=1)).isoformat(), - "wall_seconds": 12.0, - } - ) - process_record = _address( - {"kind": "shared-forged-process", "wall_seconds": 12.0} - ) - _replace_worker_provenance( - baseline, - 0, - invocation=invocation, - process_record=process_record, - ) - _replace_worker_provenance( - candidate, - 1, - invocation=invocation, - process_record=process_record, - ) - _write_payload(baseline_path, baseline) - _write_payload(candidate_path, candidate) - - with pytest.raises( - gate.EvidenceError, - match=r"reuses worker_(invocation|process_record)_sha256 identity", - ): - _compare(paths) - - -def test_gate_rejects_second_token_before_first_worker_finishes( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - _replace_token_issued_at( - payload, - 0, - _TEST_EPOCH + dt.timedelta(seconds=1, milliseconds=500), - ) - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match="admitted the second role"): - _compare(paths) - - -def test_gate_rejects_ready_record_after_first_token(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - _replace_ready_at( - payload, - _TEST_EPOCH + dt.timedelta(seconds=3, milliseconds=500), - ) - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match="timestamps are inverted"): - _compare(paths) - - -def test_gate_rejects_cross_layout_overlap(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-all-flow-union"] - payload = json.loads(path.read_text()) - _replace_ready_at(payload, _TEST_EPOCH + dt.timedelta(seconds=100)) - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match="layouts overlap or reorder"): - _compare(paths) - - -def test_gate_binds_valid_outer_campaign_manifest(tmp_path: Path) -> None: - comparison = _compare(_write_campaign(tmp_path)) - campaign = comparison["inputs"]["paired_campaign"] - watchdog = comparison["inputs"]["outer_memory_watchdog"] - assert campaign["campaign_content_sha256"] - assert campaign["harness_content_sha256"] - assert campaign["orchestrator_content_sha256"] - assert watchdog["report_content_sha256"] - assert watchdog["bound_campaign_sha256"] == campaign["sha256"] - assert comparison["inputs"]["externally_pinned_role_inputs"] == { - "candidate_source_revision": EXPECTED_CANDIDATE_REVISION, - "roles": { - "baseline": { - "native_build_inputs_sha256": ( - EXPECTED_BASELINE_NATIVE_BUILD_INPUTS - ), - "prepared_model_sha256": EXPECTED_BASELINE_PREPARED_MODEL, - }, - "candidate": { - "native_build_inputs_sha256": ( - EXPECTED_CANDIDATE_NATIVE_BUILD_INPUTS - ), - "prepared_model_sha256": EXPECTED_CANDIDATE_PREPARED_MODEL, - }, - }, - } - - -@pytest.mark.parametrize( - ("field", "value", "message"), - [ - ( - "expected_candidate_source_revision", - "3" * 40, - "externally pinned source revision", - ), - ( - "expected_baseline_native_build_inputs_sha256", - "3" * 64, - "baseline .*capture.*native-build-input", - ), - ( - "expected_candidate_native_build_inputs_sha256", - "4" * 64, - "candidate .*capture.*native-build-input", - ), - ( - "expected_baseline_prepared_model_sha256", - "5" * 64, - "baseline .*capture.*prepared-model", - ), - ( - "expected_candidate_prepared_model_sha256", - "6" * 64, - "candidate .*capture.*prepared-model", - ), - ], -) -def test_gate_requires_externally_pinned_role_inputs( - field: str, - value: str, - message: str, - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - with pytest.raises(gate.EvidenceError, match=message): - _compare(paths, **{field: value}) - - -@pytest.mark.parametrize( - ("identity", "message"), - ( - ("native", "candidate all-flow-union capture.*native-build-input"), - ("prepared", "candidate all-flow-union capture.*prepared-model"), - ), -) -def test_gate_applies_external_identity_pins_to_every_layout( - identity: str, - message: str, - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-all-flow-union"] - payload = json.loads(path.read_text()) - if identity == "native": - payload["runtime_provenance"]["native_extension"][ - "build_inputs_sha256" - ] = "7" * 64 - else: - for model in payload["configuration"]["model_identities"].values(): - model["file"]["sha256"] = "7" * 64 - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match=message): - _compare(paths) - - -def test_gate_accepts_watchdog_probe_failures_recovered_below_policy( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - - def recovered(payload: dict[str, object]) -> None: - enforcement = payload["enforcement"] - enforcement["probe_failure_count"] = 7 - enforcement["maximum_consecutive_probe_failures"] = 1 - - _rewrite_watchdog_report(paths["watchdog-report"], recovered) - comparison = _compare(paths) - assert comparison["passes"] is True - - -@pytest.mark.parametrize( - ("mutation", "expected"), - ( - ("tool", "authenticated watchdog tool"), - ("limit", "30-GiB enforcement"), - ("retry", "recovered-probe retry policy"), - ("session", "command session differs"), - ("result", "content-address the supplied paired campaign"), - ), -) -def test_gate_rejects_readdressed_watchdog_report_tampering( - tmp_path: Path, - mutation: str, - expected: str, -) -> None: - paths = _write_campaign(tmp_path) - - def tamper(payload: dict[str, object]) -> None: - if mutation == "tool": - payload["watchdog"]["sha256"] = "f" * 64 - elif mutation == "limit": - payload["enforcement"]["limit_bytes"] -= 1 - elif mutation == "retry": - payload["enforcement"]["probe_failure_count"] = 3 - payload["enforcement"]["maximum_consecutive_probe_failures"] = 3 - elif mutation == "session": - command = payload["execution"]["command"] - session_index = command.index("--session-id") + 1 - command[session_index] = "forged-session" - payload["execution"]["command_sha256"] = _sha256(command) - else: - payload["result_binding"]["identity"]["sha256"] = "f" * 64 - - _rewrite_watchdog_report(paths["watchdog-report"], tamper) - with pytest.raises(gate.EvidenceError, match=expected): - _compare(paths) - - -def test_gate_rejects_outer_campaign_address_tamper(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - _rewrite_campaign( - paths["campaign"], - lambda payload: payload.__setitem__("complete", False), - readdress_outer=False, - ) - - with pytest.raises(gate.EvidenceError, match="content address"): - _compare(paths) - - -def test_gate_rejects_campaign_capture_hash_drift(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - with paths["candidate-topology-replay"].open("ab") as stream: - stream.write(b" ") - - with pytest.raises( - gate.EvidenceError, - match="does not identify its supplied capture file", - ): - _compare(paths) - - -@pytest.mark.parametrize( - ("field", "expected"), - ( - ("session", "session_id differs"), - ("revision", "differs from its capture provenance"), - ("pack", "differs from its capture provenance"), - ("configuration", "configuration differs"), - ), -) -def test_gate_rejects_semantically_forged_campaign_fields( - tmp_path: Path, - field: str, - expected: str, -) -> None: - paths = _write_campaign(tmp_path) - - def mutate(payload: dict[str, object]) -> None: - if field == "session": - payload["session_id"] = "forged-session" - elif field == "revision": - payload["roles"]["candidate"]["source_revision"] = "f" * 40 - elif field == "pack": - payload["roles"]["candidate"]["prepared_model_sha256"] = "f" * 64 - else: - payload["configuration"]["warmup_runs"] = 3 - - _rewrite_campaign(paths["campaign"], mutate) - with pytest.raises(gate.EvidenceError, match=expected): - _compare(paths) - - -def test_gate_rejects_capture_with_more_than_two_warmups(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - payload["configuration"]["warmup_runs"] = 3 - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match="exactly 2 warmup"): - _compare(paths) - - -def test_gate_rejects_eight_outer_subprocess_pairs(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - payload["configuration"]["subprocess_samples"] = 8 - _write_payload(path, payload) - - with pytest.raises( - gate.EvidenceError, - match="exactly 7 independent subprocess pairs", - ): - _compare(paths) - - -@pytest.mark.parametrize("field", ("candidate_relative_path", "head_blob_sha256")) -def test_gate_rejects_forged_campaign_harness( - tmp_path: Path, - field: str, -) -> None: - paths = _write_campaign(tmp_path) - - def mutate(payload: dict[str, object]) -> None: - payload["harness"][field] = ( - "tools/developer/forged.py" - if field == "candidate_relative_path" - else "f" * 64 - ) - - _rewrite_campaign( - paths["campaign"], - mutate, - readdress_harness=True, - ) - with pytest.raises(gate.EvidenceError, match="exact candidate benchmark driver"): - _compare(paths) - - -@pytest.mark.parametrize( - "process", - ( - "d d~ > z + 6*g", - "d d~ > Z g g g g g g", - "u u~ > Z g g g g g g", - ), -) -def test_gate_accepts_exact_d_route_and_existing_u_route( - tmp_path: Path, - process: str, -) -> None: - comparison = _compare(_write_campaign(tmp_path, process=process)) - assert comparison["complete"] is True - assert comparison["passes"] is True - assert comparison["failures"] == [] - unsigned = dict(comparison) - digest = unsigned.pop("content_sha256") - assert digest == _sha256(unsigned) - assert len(comparison["runtime_cells"]) == 12 - assert len(comparison["paired_compiled_recurrence_ratios"]) == 4 - assert len(comparison["eager_diagnostic"]["runtime_cells"]) == 6 - assert comparison["eager_diagnostic"]["passes"] is True - assert ( - comparison["eager_diagnostic"]["paired_compiled_recurrence_ratio_applicable"] - is False - ) - - -def test_selected_union_projection_allows_only_audited_lane_metadata_drift( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - payload = json.loads(paths["baseline-all-flow-union"].read_text()) - compiled = payload["profiles"]["compiled"]["artifact_semantic_identity"] - recurrence = payload["profiles"]["recurrence"]["artifact_semantic_identity"] - assert compiled["reduction_ordering"] != recurrence["reduction_ordering"] - assert ( - compiled["physical_helicities"]["ordered_entries"] - != recurrence["physical_helicities"]["ordered_entries"] - ) - contract = payload["capture_acceptance"]["artifact_semantic_contract"] - assert contract["comparison_policy"] == ( - gate.SELECTED_UNION_SEMANTIC_COMPARISON_POLICY - ) - assert all( - lane["selected_union_workload_projection"] - == contract["common_physics_contract"] - for lane in contract["lane_contracts"].values() - ) - comparison = _compare(paths) - assert comparison["passes"] is True - - -@pytest.mark.parametrize( - "mutation", - ("policy", "lane", "color", "model", "selector", "selected"), -) -def test_selected_union_projection_fails_closed_on_projection_drift( - tmp_path: Path, - mutation: str, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-all-flow-union"] - payload = json.loads(path.read_text()) - contract = payload["capture_acceptance"]["artifact_semantic_contract"] - common = contract["common_physics_contract"] - if mutation == "policy": - contract["comparison_policy"] = gate.STRICT_SEMANTIC_COMPARISON_POLICY - elif mutation == "lane": - lane = contract["lane_contracts"]["recurrence"][ - "selected_union_workload_projection" - ] - lane["physical_helicities"]["selected_entry"]["coefficient"] = 2.0 - else: - if mutation == "color": - common["physical_color_flows"]["ordered_ids_sha256"] = "0" * 64 - elif mutation == "model": - common["model_common_physics_identity_sha256"] = "0" * 64 - elif mutation == "selector": - common["profile_selector"]["resolved_color_flow_id"] = "flow:forged" - else: - common["physical_helicities"]["selected_entry"]["coefficient"] = 0.0 - for lane in contract["lane_contracts"].values(): - lane["selected_union_workload_projection"] = copy.deepcopy(common) - _write_payload(path, payload) - with pytest.raises( - gate.EvidenceError, - match=r"policy|projection|selector|helic|coefficient", - ): - _compare(paths) - - -def test_selected_union_projection_drift_across_captures_is_rejected( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-all-flow-union"] - payload = json.loads(path.read_text()) - for mode in ALL_MODES: - semantic = payload["profiles"][mode]["artifact_semantic_identity"] - selected = semantic["physical_helicities"]["ordered_entries"][ - gate.SELECTED_UNION_HELICITY_INDEX - ] - selected["coefficient"] = 2.0 - semantic["physical_helicities"]["ordered_entries_sha256"] = _sha256( - semantic["physical_helicities"]["ordered_entries"] - ) - _refresh_mode_semantic(payload, mode) - _rebuild_selected_union_projections(payload) - _write_payload(path, payload) - - with pytest.raises(gate.EvidenceError, match="workload identities differ"): - _compare(paths) - - -@pytest.mark.parametrize( - ("process", "layout", "helicity"), - ( - ("d d~ > Z g g g g g g", "topology-replay", "1"), - ("u u~ > Z g g g g g g", "all-flow-union", "h:-1,+1"), - ("d d~ > Z g g g g g g", "all-flow-union", "1"), - ), -) -def test_selected_union_exception_is_unavailable_outside_exact_route( - tmp_path: Path, - process: str, - layout: str, - helicity: str, -) -> None: - paths = _write_campaign(tmp_path, process=process) - path = paths[f"candidate-{layout}"] - payload = json.loads(path.read_text()) - payload["configuration"]["helicity_request"] = helicity - payload["capture_acceptance"]["artifact_semantic_contract"]["comparison_policy"] = ( - gate.SELECTED_UNION_SEMANTIC_COMPARISON_POLICY - ) - _write_payload(path, payload) - with pytest.raises(gate.EvidenceError, match=r"policy|must select"): - _compare(paths) - - -def test_strict_topology_still_rejects_full_axis_drift(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - semantic = payload["profiles"]["compiled"]["artifact_semantic_identity"] - semantic["physical_helicities"]["ordered_entries"][0]["index"] = 99 - _refresh_mode_semantic(payload, "compiled") - _write_payload(path, payload) - with pytest.raises(gate.EvidenceError, match="workload identities differ"): - _compare(paths) - - -def test_gate_recomputes_runtime_statistics_and_rejects_forged_aggregate( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - aggregate = payload["profiles"]["compiled"]["profiles"][0] - aggregate["wall_seconds_per_point_median"] *= 0.5 - path.write_bytes(_canonical(payload) + b"\n") - with pytest.raises(gate.EvidenceError, match="not reproducible"): - _compare(paths) - - -def test_gate_independently_revalidates_eager_raw_samples(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - aggregate = payload["profiles"]["eager"]["profiles"][0] - aggregate["wall_seconds_per_point_median"] *= 0.5 - path.write_bytes(_canonical(payload) + b"\n") - with pytest.raises(gate.EvidenceError, match="not reproducible"): - _compare(paths) - - -def test_gate_rejects_readdressed_sub_five_second_native_wall_evidence( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - _, sample = _entry_and_sample(payload, 0) - raw = sample["inner_native_wall_blocks"] - raw["observed_native_wall_seconds"] = 4.999 - raw["minimum_duration_satisfied"] = True - _rebind_retained_sample(payload, 0) - _write_payload(path, payload) - - with pytest.raises( - gate.EvidenceError, - match="raw native-wall measurement contract is invalid", - ): - _compare(paths) - - -def test_gate_rejects_readdressed_raw_calibration_tampering( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - _, sample = _entry_and_sample(payload, 0) - raw = sample["inner_native_wall_blocks"] - raw["calibration"]["duration_headroom_factor"] = 1.01 - sample["worker_measurement"]["inner_native_wall_blocks"] = copy.deepcopy(raw) - _rebind_retained_sample(payload, 0) - _write_payload(path, payload) - - with pytest.raises( - gate.EvidenceError, - match="raw native-wall measurement contract is invalid", - ): - _compare(paths) - - -def test_gate_reports_runtime_and_same_round_ratio_failures(tmp_path: Path) -> None: - runtime = _compare(_write_campaign(tmp_path / "runtime", runtime_ratio=1.04)) - assert runtime["passes"] is False - assert any( - failure.startswith("runtime regression:") for failure in runtime["failures"] - ) - - ratio = _compare( - _write_campaign( - tmp_path / "ratio", - compiled_to_recurrence_ratio=1.20, - ) - ) - assert ratio["passes"] is False - assert any( - failure.startswith("compiled/recurrence ratio regression:") - for failure in ratio["failures"] - ) - - -def test_gate_enforces_generation_cell_and_geometric_mean_limits( - tmp_path: Path, -) -> None: - comparison = _compare(_write_campaign(tmp_path, generation_ratio=1.11)) - assert comparison["passes"] is False - assert comparison["generation"]["geometric_mean_passes"] is False - assert "generation geometric-mean regression" in comparison["failures"] - assert ( - sum( - failure.startswith("generation regression:") - for failure in comparison["failures"] - ) - == 4 - ) - - -def test_eager_diagnostic_runtime_generation_and_resource_failures( - tmp_path: Path, -) -> None: - runtime = _compare( - _write_campaign( - tmp_path / "runtime", - eager_runtime_ratio=1.04, - ) - ) - assert runtime["passes"] is False - assert all(cell["passes"] is True for cell in runtime["runtime_cells"]) - assert runtime["eager_diagnostic"]["runtime_passes"] is False - assert any( - failure.startswith("eager diagnostic runtime regression:") - for failure in runtime["eager_diagnostic"]["failures"] - ) - assert any( - failure.startswith("eager diagnostic runtime regression:") - for failure in runtime["failures"] - ) - - generation = _compare( - _write_campaign( - tmp_path / "generation", - eager_generation_ratio=1.11, - ) - ) - assert generation["passes"] is False - assert generation["generation"]["geometric_mean_passes"] is True - assert generation["eager_diagnostic"]["generation"]["passes"] is False - assert any( - failure.startswith("eager diagnostic generation regression:") - for failure in generation["eager_diagnostic"]["failures"] - ) - assert any( - failure.startswith("eager diagnostic generation regression:") - for failure in generation["failures"] - ) - - resources = _compare( - _write_campaign( - tmp_path / "resources", - eager_resource_ratio=1.04, - ) - ) - assert resources["passes"] is False - assert resources["eager_diagnostic"]["resource_passes"] is False - assert any( - failure.startswith("eager diagnostic resource regression:") - for failure in resources["eager_diagnostic"]["failures"] - ) - assert any( - failure.startswith("eager diagnostic resource regression:") - for failure in resources["failures"] - ) - - -def test_eager_generation_has_a_five_percent_geometric_mean_gate( - tmp_path: Path, -) -> None: - comparison = _compare( - _write_campaign( - tmp_path, - eager_generation_ratio=1.06, - ) - ) - eager_generation = comparison["eager_diagnostic"]["generation"] - assert comparison["passes"] is False - assert all(cell["passes"] is True for cell in eager_generation["cells"]) - assert eager_generation["geometric_mean_passes"] is False - assert eager_generation["passes"] is False - assert any( - failure == "eager diagnostic generation geometric-mean regression" - for failure in comparison["eager_diagnostic"]["failures"] - ) - - -def test_gate_requires_eager_present_and_admissible(tmp_path: Path) -> None: - missing_paths = _write_campaign(tmp_path / "missing") - missing_path = missing_paths["candidate-topology-replay"] - missing = json.loads(missing_path.read_text()) - missing["configuration"]["modes"].remove("eager") - _write_payload(missing_path, missing) - with pytest.raises(gate.EvidenceError, match="compiled, recurrence, and eager"): - _compare(missing_paths) - - inadmissible_paths = _write_campaign(tmp_path / "inadmissible") - inadmissible_path = inadmissible_paths["candidate-topology-replay"] - inadmissible = json.loads(inadmissible_path.read_text()) - eager = inadmissible["capture_acceptance"]["eager_diagnostic"] - eager["complete"] = False - eager["passes"] = None - eager["ineligibility_reasons"] = ["synthetic failure"] - _write_payload(inadmissible_path, inadmissible) - with pytest.raises(gate.EvidenceError, match="not complete and admissible"): - _compare(inadmissible_paths) - - -def test_eager_resource_growth_uses_the_runtime_gain_exception( - tmp_path: Path, -) -> None: - comparison = _compare( - _write_campaign( - tmp_path, - eager_runtime_ratio=0.85, - eager_resource_ratio=1.20, - ) - ) - eager = comparison["eager_diagnostic"] - assert comparison["passes"] is True - assert eager["passes"] is True - assert any( - resource["within_3_percent_growth_limit"] is False - and resource["runtime_gain_exception"]["passes"] is True - for resource in eager["payload_cold_load_rss"] - ) - - -def test_resource_growth_needs_a_ten_percent_noise_clear_runtime_gain( - tmp_path: Path, -) -> None: - regression = _compare(_write_campaign(tmp_path / "regression", resource_ratio=1.04)) - assert regression["passes"] is False - assert any( - failure.startswith("resource regression:") for failure in regression["failures"] - ) - - exception = _compare( - _write_campaign( - tmp_path / "exception", - runtime_ratio=0.85, - resource_ratio=1.20, - ) - ) - assert exception["passes"] is True - assert all( - resource["passes"] is True for resource in exception["payload_cold_load_rss"] - ) - assert any( - resource["within_3_percent_growth_limit"] is False - and resource["runtime_gain_exception"]["passes"] is True - for resource in exception["payload_cold_load_rss"] - ) - - -def test_gate_fails_closed_on_workload_identity_drift(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-all-flow-union"] - payload = json.loads(path.read_text()) - payload["profiles"]["compiled"]["selector_contract"]["color_flow_count"] = 3 - path.write_bytes(_canonical(payload) + b"\n") - with pytest.raises( - gate.EvidenceError, - match="selector differs from its selected-union projection", - ): - _compare(paths) - - -@pytest.mark.parametrize( - ("field", "value"), - (("complete", False), ("passes", None)), -) -def test_gate_requires_top_level_complete_passing_captures( - tmp_path: Path, - field: str, - value: object, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-topology-replay"] - payload = json.loads(path.read_text()) - payload[field] = value - path.write_bytes(_canonical(payload) + b"\n") - with pytest.raises( - gate.EvidenceError, - match="not top-level complete and passing", - ): - _compare(paths) - - -def test_gate_requires_consistent_authoritative_capture_acceptance( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["candidate-all-flow-union"] - payload = json.loads(path.read_text()) - payload["capture_acceptance"]["evidence_complete"] = False - path.write_bytes(_canonical(payload) + b"\n") - with pytest.raises( - gate.EvidenceError, - match="not authoritative, complete, and passing", - ): - _compare(paths) - - -def test_legacy_capture_without_cold_load_has_actionable_error( - tmp_path: Path, -) -> None: - paths = _write_campaign(tmp_path) - path = paths["baseline-topology-replay"] - payload = json.loads(path.read_text()) - del payload["profiles"]["compiled"]["profiles"][0]["subprocess_samples"][0][ - "cold_load_seconds" - ] - path.write_bytes(_canonical(payload) + b"\n") - with pytest.raises( - gate.EvidenceError, - match=r"predates the resource-evidence contract.*re-run", - ): - _compare(paths) - - -def test_cli_writes_canonical_content_addressed_report(tmp_path: Path) -> None: - paths = _write_campaign(tmp_path) - output = tmp_path / "comparison.json" - exit_code = gate.main( - [ - "--baseline-topology", - str(paths["baseline-topology-replay"]), - "--campaign", - str(paths["campaign"]), - "--watchdog-report", - str(paths["watchdog-report"]), - "--baseline-all-flow-union", - str(paths["baseline-all-flow-union"]), - "--candidate-topology", - str(paths["candidate-topology-replay"]), - "--candidate-all-flow-union", - str(paths["candidate-all-flow-union"]), - "--expected-candidate-source-revision", - EXPECTED_CANDIDATE_REVISION, - "--expected-baseline-native-build-inputs-sha256", - EXPECTED_BASELINE_NATIVE_BUILD_INPUTS, - "--expected-candidate-native-build-inputs-sha256", - EXPECTED_CANDIDATE_NATIVE_BUILD_INPUTS, - "--expected-baseline-prepared-model-sha256", - EXPECTED_BASELINE_PREPARED_MODEL, - "--expected-candidate-prepared-model-sha256", - EXPECTED_CANDIDATE_PREPARED_MODEL, - "--output", - str(output), - ] - ) - assert exit_code == 0 - payload = json.loads(output.read_text()) - unsigned = copy.deepcopy(payload) - digest = unsigned.pop("content_sha256") - assert digest == _sha256(unsigned) - assert output.read_bytes() == _canonical(payload) + b"\n" diff --git a/pyamplicol/tests/unit/test_three_mode_report_catalog.py b/pyamplicol/tests/unit/test_three_mode_report_catalog.py deleted file mode 100644 index 72d035f6d7..0000000000 --- a/pyamplicol/tests/unit/test_three_mode_report_catalog.py +++ /dev/null @@ -1,1484 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -from collections import Counter -from copy import deepcopy -from dataclasses import replace -from pathlib import Path - -import pytest - -import tools.performance_report.manual_campaign as manual_campaign -from tools.performance_report.agreements import ( - DIRECT_AGREEMENT_FIELD, - DIRECT_AGREEMENT_KINDS, - INDEPENDENT_AUTHORITY_ABI, - INDEPENDENT_AUTHORITY_FIELD, - LC_LEGACY_PYAMPLICOL_COMPONENT, - incoming_agreement_edges, - independent_numerical_authorities, -) -from tools.performance_report.arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - EMPTY_ARENA_PHASE_VECTOR_FIELDS, - ZERO_ARENA_COUNTER_FIELDS, - ZERO_ARENA_PHASE_TIME_FIELDS, - ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS, - build_arena_profile_evidence, - digest_arena_profile_value, -) -from tools.performance_report.cache import ( - CACHE_SCHEMA_VERSION, - REPORT_VERSION, - _validate_unverified_direct_agreement_coverage, - build_reset_caches, - digest_json, - empty_measurement, - schema_document, - validate_cache, - validate_measurement, -) -from tools.performance_report.catalog import ( - MADGRAPH_FULL_COMPARISON_VIEWS, - REPORT_CATALOG, - STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6, - STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION, - STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT, -) -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, - ZVariant, -) -from tools.performance_report.runner import pointwise_validation -from tools.performance_report.service import ReportPaths, ReportService - - -def test_matrix_catalog_adds_only_the_three_missing_ufo_full_candidates() -> None: - datasets = REPORT_CATALOG.matrix_datasets - - assert len(datasets) == 18 - assert Counter(item.candidate.execution_mode for item in datasets) == { - ExecutionMode.RECURRENCE: 6, - ExecutionMode.COMPILED: 4, - ExecutionMode.EAGER: 4, - ExecutionMode.ON_THE_FLY: 4, - } - assert Counter(item.candidate.model for item in datasets) == { - ModelKey.BUILTIN_SM: 12, - ModelKey.UFO_SM: 6, - } - assert all( - item.baseline.execution_mode is ExecutionMode.AMPLICOL - for item in datasets - if item.candidate.execution_mode is ExecutionMode.RECURRENCE - ) - assert all( - item.baseline.execution_mode is ExecutionMode.RECURRENCE - for item in datasets - if item.candidate.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - and item.candidate.model is ModelKey.BUILTIN_SM - ) - assert all( - item.baseline.execution_mode is ExecutionMode.MADGRAPH - for item in datasets - if item.candidate.model is ModelKey.UFO_SM - and item.candidate.accuracy is Accuracy.FULL - and item.candidate.execution_mode - in { - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - } - ) - - -def test_madgraph_full_reference_is_one_shared_fifty_cell_ufo_surface() -> None: - references = tuple( - cell - for cell in REPORT_CATALOG.reference_cells() - if cell.dataset_id == "reference_madgraph_full" - ) - - assert len(references) == 50 - assert len({cell.cell_id for cell in references}) == 50 - assert all( - cell.measurement.execution_mode is ExecutionMode.MADGRAPH - and cell.measurement.model is ModelKey.UFO_SM - and cell.measurement.accuracy is Accuracy.FULL - and cell.measurement.backend == "fortran" - and cell.workload is Workload.CONTRACTED - for cell in references - ) - - -def test_madgraph_comparison_views_reuse_one_recurrence_profile() -> None: - views = MADGRAPH_FULL_COMPARISON_VIEWS - - assert REPORT_CATALOG.matrix_comparison_views is views - assert len(views) == 4 - assert {view.baseline_dataset_id for view in views} == { - "reference_madgraph_full" - } - assert {view.candidate_dataset_id for view in views} == { - f"matrix_{mode.value.replace('-', '_')}_ufo_sm_full" - for mode in { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - } - } - assert len( - [ - dataset - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.dataset_id == "matrix_recurrence_ufo_sm_full" - ] - ) == 1 - assert len( - [ - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_recurrence_ufo_sm_full" - ] - ) == 50 - assert all( - REPORT_CATALOG.comparison_view(view.comparison_id) is view for view in views - ) - - -def test_madgraph_candidate_baselines_and_direct_cell_ids_are_unambiguous() -> None: - candidates = tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id - in { - "matrix_compiled_ufo_sm_full", - "matrix_eager_ufo_sm_full", - "matrix_on_the_fly_ufo_sm_full", - } - ) - - assert len(candidates) == 150 - assert all( - (baseline := REPORT_CATALOG.baseline_cell(cell)) is not None - and baseline.dataset_id == "reference_madgraph_full" - and baseline.measurement.execution_mode is ExecutionMode.MADGRAPH - for cell in candidates - ) - cell_ids = tuple(cell.cell_id for cell in REPORT_CATALOG.measurement_cells()) - assert len(cell_ids) == len(set(cell_ids)) - - -def test_required_agreement_evidence_bumps_report_cache_contract() -> None: - assert CACHE_SCHEMA_VERSION == 5 - assert REPORT_VERSION == "0.3.0" - - -def test_packaged_report_cache_schema_is_canonical() -> None: - packaged = ( - Path(__file__).resolve().parents[2] - / "src/pyamplicol/_profiling_campaign/results/report-cache.schema.json" - ) - assert json.loads(packaged.read_text(encoding="ascii")) == schema_document() - - -def test_report_cache_schema_accepts_every_direct_agreement_kind() -> None: - def edge_kind_enums(value: object) -> list[tuple[str, ...]]: - if isinstance(value, dict): - found: list[tuple[str, ...]] = [] - edge_kind = value.get("edge_kind") - if isinstance(edge_kind, dict) and isinstance(edge_kind.get("enum"), list): - found.append(tuple(edge_kind["enum"])) - for child in value.values(): - found.extend(edge_kind_enums(child)) - return found - if isinstance(value, list): - return [item for child in value for item in edge_kind_enums(child)] - return [] - - enums = edge_kind_enums(schema_document()) - assert len(enums) == 6 - assert all(enum == DIRECT_AGREEMENT_KINDS for enum in enums) - - -def test_prepared_modes_are_portable_o2_and_compiled_is_o3() -> None: - by_mode = { - mode: { - dataset.candidate.jit_optimization_level - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.candidate.execution_mode is mode - } - for mode in ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - ) - } - - assert by_mode == { - ExecutionMode.RECURRENCE: {2}, - ExecutionMode.COMPILED: {3}, - ExecutionMode.EAGER: {2}, - ExecutionMode.ON_THE_FLY: {2}, - } - - -def test_lc_cells_have_two_runtime_workloads_and_contracted_cells_have_one() -> None: - counts = Counter( - (cell.measurement.accuracy, cell.workload) - for cell in REPORT_CATALOG.matrix_cells() - ) - - assert counts[(Accuracy.LC, Workload.SELECTED_FLOW)] == 461 - assert counts[(Accuracy.LC, Workload.ALL_FLOW)] == 461 - assert counts[(Accuracy.NLC, Workload.CONTRACTED)] == 250 - assert counts[(Accuracy.FULL, Workload.CONTRACTED)] == 400 - assert all( - cell.workload is Workload.CONTRACTED - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.accuracy is not Accuracy.LC - ) - - -def test_extended_lc_families_are_declared_through_n9() -> None: - process_keys = { - "gg_tt_jets", - "gg_gluons", - "dd_3q_lines", - "dd_4q_lines", - "dd_3q_identical_lines", - } - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.n_final == 9 - and cell.process_key in process_keys - and cell.measurement.accuracy is Accuracy.LC - ) - - assert len(cells) == 50 - assert { - ( - cell.process_key, - cell.measurement.execution_mode, - cell.measurement.model, - cell.workload, - ) - for cell in cells - } == { - (process_key, mode, model, workload) - for process_key in process_keys - for mode, model in { - (ExecutionMode.AMPLICOL, None), - (ExecutionMode.RECURRENCE, ModelKey.BUILTIN_SM), - (ExecutionMode.RECURRENCE, ModelKey.UFO_SM), - (ExecutionMode.COMPILED, ModelKey.BUILTIN_SM), - (ExecutionMode.EAGER, ModelKey.BUILTIN_SM), - } - for workload in {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - } - assert { - cell.process_key - for cell in cells - if REPORT_CATALOG.static_na_reason(cell) is not None - } == {"dd_4q_lines"} - - -def test_n_le_four_matrix_smoke_has_594_logical_process_cells() -> None: - cells = [cell for cell in REPORT_CATALOG.matrix_cells() if cell.n_final <= 4] - logical = {(cell.dataset_id, cell.process_key, cell.n_final) for cell in cells} - - assert len(logical) == 594 - assert len(cells) == 759 - - -def test_identical_quark_line_family_has_canonical_order_and_full_coverage() -> None: - family = next( - family for family in REPORT_CATALOG.process_families if family.identifier == 15 - ) - - assert family.key == "dd_3q_identical_lines" - assert family.label_tex == r"$d\bar d\to u\bar u\,u\bar u+(n-4)g$" - assert family.minimum_n == 4 - assert family.maximum_n(Accuracy.LC) == 9 - assert family.maximum_n(Accuracy.NLC) == 6 - assert family.maximum_n(Accuracy.FULL) == 6 - assert family.include_3qqbar is True - assert family.process(3) is None - assert family.process(4) == "d d~ > u u~ u u~" - assert family.process(8) == "d d~ > u u~ u u~ g g g g" - - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.process_key == family.key - ) - assert len(cells) == 110 - assert Counter(REPORT_CATALOG.static_na_reason(cell) for cell in cells) == { - None: 110, - } - assert ( - REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n6-dd-3q-identical-lines-contracted" - ).process - == "d d~ > u u~ u u~ g g" - ) - - -def test_z_catalog_includes_recurrence_eager_and_on_the_fly() -> None: - variants = {variant.key: variant for variant in REPORT_CATALOG.z_variants} - - assert variants["eager_jit_o2"].label == "eager-DAG JIT O2" - assert variants["recurrence_jit_o2"].label == "recurrence JIT O2" - assert variants["recurrence_jit_o2"].jit_optimization_level == 2 - assert variants["on_the_fly_jit_o2"].label == "on-the-fly JIT O2" - assert ( - variants["on_the_fly_jit_o2"].execution_mode - is ExecutionMode.ON_THE_FLY - ) - assert ( - len( - [ - cell - for cell in REPORT_CATALOG.z_cells() - if cell.variant == "recurrence_jit_o2" and cell.n_final <= 4 - ] - ) - == 16 - ) - assert ( - len( - [ - cell - for cell in REPORT_CATALOG.z_cells() - if cell.variant == "on_the_fly_jit_o2" and cell.n_final <= 4 - ] - ) - == 16 - ) - - -def test_scalar_ladders_are_canonical_resettable_cells() -> None: - assert tuple(dataset.dataset_id for dataset in REPORT_CATALOG.scalar_datasets) == ( - "scalar_contact", - "scalar_gravity", - ) - cells = REPORT_CATALOG.scalar_cells() - assert len(cells) == 10 - assert all(cell.workload is Workload.CONTRACTED for cell in cells) - assert all( - cell.measurement.execution_mode is ExecutionMode.COMPILED for cell in cells - ) - assert all(REPORT_CATALOG.baseline_cell(cell) is None for cell in cells) - - -def test_baseline_dependencies_are_canonical_and_mode_ordered() -> None: - recurrence = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - ) - compiled = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.COMPILED - ) - eager = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is ExecutionMode.EAGER - ) - - recurrence_baseline = REPORT_CATALOG.baseline_cell(recurrence) - compiled_baseline = REPORT_CATALOG.baseline_cell(compiled) - eager_baseline = REPORT_CATALOG.baseline_cell(eager) - assert recurrence_baseline is not None - assert recurrence_baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - assert compiled_baseline is not None - assert compiled_baseline.measurement.execution_mode is ExecutionMode.RECURRENCE - assert eager_baseline is not None - assert eager_baseline.measurement.execution_mode is ExecutionMode.RECURRENCE - assert REPORT_CATALOG.cell(compiled.cell_id) == compiled - - -def test_four_line_report_keeps_legacy_display_without_legacy_dependency() -> None: - recurrence = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_recurrence_builtin_sm_lc" - and cell.process_key == "dd_4q_lines" - and cell.n_final == 6 - and cell.workload is Workload.SELECTED_FLOW - ) - compiled = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_compiled_builtin_sm_lc" - and cell.process_key == "dd_4q_lines" - and cell.n_final == 6 - and cell.workload is Workload.SELECTED_FLOW - ) - - display_baseline = REPORT_CATALOG.baseline_cell(recurrence) - assert display_baseline is not None - assert display_baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - assert REPORT_CATALOG.legacy_reference_available(recurrence) is False - assert REPORT_CATALOG.static_na_reason(display_baseline) == ( - "original-amplicol-open-quark-line-limit" - ) - assert REPORT_CATALOG.validation_baseline_cell(recurrence) is None - - compiled_baseline = REPORT_CATALOG.validation_baseline_cell(compiled) - assert compiled_baseline is not None - assert compiled_baseline.measurement.execution_mode is ExecutionMode.RECURRENCE - - three_line_reference = REPORT_CATALOG.cell( - "reference-amplicol-full-n6-dd-3q-lines-contracted" - ) - assert REPORT_CATALOG.legacy_reference_available(three_line_reference) - assert REPORT_CATALOG.static_na_reason(three_line_reference) is None - - -def test_canonical_static_na_census_is_exact() -> None: - static_na = { - cell.cell_id: REPORT_CATALOG.static_na_reason(cell) - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - } - - expected = { - cell_id: STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT - for cell_id in { - "reference-amplicol-lc-n6-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n6-dd-4q-lines-all-flow", - "reference-amplicol-lc-n7-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n7-dd-4q-lines-all-flow", - "reference-amplicol-lc-n8-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n8-dd-4q-lines-all-flow", - "reference-amplicol-lc-n9-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n9-dd-4q-lines-all-flow", - "reference-amplicol-nlc-n6-dd-4q-lines-contracted", - "reference-amplicol-full-n6-dd-4q-lines-contracted", - } - } - expected.update( - { - ( - f"z-{model}-n{n_final}-dd-z-jets-{variant}-{workload}" - ): STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6 - for model in ("builtin-sm", "external-sm") - for n_final in (7, 8, 9) - for variant in ("asm-o3", "cpp-o3") - for workload in ("selected-flow", "all-flow") - } - ) - assert static_na == expected - for cell_id, reason in expected.items(): - if reason != STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6: - continue - cell = REPORT_CATALOG.cell(cell_id) - assert ( - REPORT_CATALOG.static_na_description(cell) - == STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION - ) - - -def test_z_variant_generation_cap_contract_is_paired_and_positive() -> None: - with pytest.raises(ValueError, match="positive integer"): - ZVariant( - "bad", - "bad", - ExecutionMode.COMPILED, - "asm", - maximum_generation_n_final=0, - static_na_reason_code="reason-v1", - ) - with pytest.raises(ValueError, match="requires a static_na_reason_code"): - ZVariant( - "bad", - "bad", - ExecutionMode.COMPILED, - "asm", - maximum_generation_n_final=6, - ) - with pytest.raises(ValueError, match="requires maximum_generation_n_final"): - ZVariant( - "bad", - "bad", - ExecutionMode.COMPILED, - "asm", - static_na_reason_code="reason-v1", - ) - - -def test_contracted_multi_quark_coverage_reaches_n6_in_every_mode() -> None: - process_keys = { - "dd_3q_lines", - "dd_3q_identical_lines", - "dd_4q_lines", - } - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.process_key in process_keys - and cell.n_final == 6 - and cell.measurement.accuracy in {Accuracy.NLC, Accuracy.FULL} - ) - - assert len(cells) == 48 - assert { - ( - cell.process_key, - cell.measurement.accuracy, - cell.measurement.execution_mode, - cell.measurement.model, - ) - for cell in cells - } == { - (process_key, accuracy, mode, model) - for process_key in process_keys - for accuracy in {Accuracy.NLC, Accuracy.FULL} - for mode, model in { - (ExecutionMode.AMPLICOL, None), - (ExecutionMode.RECURRENCE, ModelKey.BUILTIN_SM), - (ExecutionMode.RECURRENCE, ModelKey.UFO_SM), - (ExecutionMode.COMPILED, ModelKey.BUILTIN_SM), - (ExecutionMode.EAGER, ModelKey.BUILTIN_SM), - (ExecutionMode.ON_THE_FLY, ModelKey.BUILTIN_SM), - } - } | { - (process_key, Accuracy.FULL, mode, model) - for process_key in process_keys - for mode, model in { - (ExecutionMode.MADGRAPH, ModelKey.UFO_SM), - (ExecutionMode.COMPILED, ModelKey.UFO_SM), - (ExecutionMode.EAGER, ModelKey.UFO_SM), - (ExecutionMode.ON_THE_FLY, ModelKey.UFO_SM), - } - } - assert ( - REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n6-dd-3q-lines-contracted" - ).process - == "d d~ > u u~ s s~ g g" - ) - - -def test_contracted_n6_catalog_impact_is_scoped_to_multi_quark_families() -> None: - process_keys = { - "dd_3q_lines", - "dd_3q_identical_lines", - "dd_4q_lines", - } - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.process_key in process_keys - and cell.n_final == 6 - and cell.measurement.accuracy is not Accuracy.LC - ) - - assert len(REPORT_CATALOG.measurement_cells()) == 2198 - assert len(REPORT_CATALOG.matrix_cells()) == 1572 - assert len(REPORT_CATALOG.reference_cells()) == 364 - assert len(cells) == 48 - assert {cell.process_key for cell in cells} == process_keys - - -def test_measurement_cells_reuses_one_immutable_catalog_materialization() -> None: - fresh = replace(REPORT_CATALOG) - cold_repr = repr(fresh) - - assert fresh._measurement_cells_cache is None - - first = fresh.measurement_cells() - second = fresh.measurement_cells() - - assert second is first - assert fresh._measurement_cells_cache is first - assert isinstance(first, tuple) - assert repr(fresh) == cold_repr - assert "_measurement_cells_cache" not in repr(fresh) - - -def test_contracted_n6_rows_are_canonical_reset_cache_entries() -> None: - caches = build_reset_caches() - payload = caches["matrix_recurrence_builtin_sm_full.json"] - expected = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "matrix_recurrence_builtin_sm_full" - ) - - validate_cache(payload, expected_cells=expected) - entries = { - entry["cell_id"]: entry for entry in payload["entries"] if entry["n_final"] == 6 - } - assert set(entries) == { - "matrix-recurrence-builtin-sm-full-n6-dd-3q-lines-contracted", - ("matrix-recurrence-builtin-sm-full-n6-dd-3q-identical-lines-contracted"), - "matrix-recurrence-builtin-sm-full-n6-dd-4q-lines-contracted", - } - assert all( - entry["measurement"] == empty_measurement() for entry in entries.values() - ) - - -@pytest.mark.parametrize( - "process_key", - ("dd_3q_lines", "dd_3q_identical_lines"), -) -def test_three_line_reports_retain_the_original_amplicol_oracle( - process_key: str, -) -> None: - recurrence = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_recurrence_builtin_sm_lc" - and cell.process_key == process_key - and cell.n_final == 4 - and cell.workload is Workload.SELECTED_FLOW - ) - - baseline = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert REPORT_CATALOG.legacy_reference_available(recurrence) is True - assert baseline is not None - assert baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - - -def test_equivalent_cells_require_exact_generation_semantics() -> None: - selected_recurrence = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_recurrence_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 3 - and cell.workload is Workload.SELECTED_FLOW - ) - equivalents = REPORT_CATALOG.equivalent_cells(selected_recurrence) - - assert equivalents - assert all( - candidate.cell_id != selected_recurrence.cell_id for candidate in equivalents - ) - assert all( - ( - candidate.process, - candidate.n_final, - candidate.process_key, - candidate.measurement, - candidate.workload, - ) - == ( - selected_recurrence.process, - selected_recurrence.n_final, - selected_recurrence.process_key, - selected_recurrence.measurement, - selected_recurrence.workload, - ) - for candidate in equivalents - ) - assert {(candidate.dataset_id, candidate.variant) for candidate in equivalents} == { - ("z_builtin_sm", "recurrence_jit_o2") - } - - same_process_cells = [ - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.process == selected_recurrence.process - and cell.n_final == selected_recurrence.n_final - and cell.process_key == selected_recurrence.process_key - ] - assert not { - candidate.cell_id - for candidate in same_process_cells - if ( - candidate.measurement.model is ModelKey.UFO_SM - or candidate.workload is Workload.ALL_FLOW - or candidate.measurement.backend != selected_recurrence.measurement.backend - or candidate.measurement.execution_mode - is not selected_recurrence.measurement.execution_mode - ) - } & {candidate.cell_id for candidate in equivalents} - - -def test_equivalent_cells_cover_matching_compiled_backend_but_never_amplicol() -> None: - compiled = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_compiled_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 2 - and cell.workload is Workload.ALL_FLOW - ) - equivalents = REPORT_CATALOG.equivalent_cells(compiled) - - assert {(candidate.dataset_id, candidate.variant) for candidate in equivalents} == { - ("z_builtin_sm", "jit_o3") - } - assert all(candidate.measurement.backend == "jit" for candidate in equivalents) - assert all( - candidate.measurement.jit_optimization_level == 3 for candidate in equivalents - ) - - reference = next( - cell - for cell in REPORT_CATALOG.reference_cells() - if cell.process_key == "dd_z_jets" - and cell.n_final == 2 - and cell.workload is Workload.ALL_FLOW - ) - assert REPORT_CATALOG.equivalent_cells(reference) == () - - -def test_reset_caches_are_canonical_and_cover_every_measurement_cell() -> None: - caches = build_reset_caches() - cells_by_dataset: dict[str, list[object]] = {} - for cell in REPORT_CATALOG.measurement_cells(): - cells_by_dataset.setdefault(cell.dataset_id, []).append(cell) - - assert set(caches) == {f"{dataset_id}.json" for dataset_id in cells_by_dataset} - for name, payload in caches.items(): - dataset_id = name.removesuffix(".json") - validate_cache(payload, expected_cells=cells_by_dataset[dataset_id]) - assert all( - entry["measurement"] == empty_measurement() for entry in payload["entries"] - ) - - -def test_not_available_measurement_cannot_carry_stale_timing() -> None: - measurement = empty_measurement() - measurement["generation_seconds"] = 1.0 - - with pytest.raises(ValueError, match="canonical reset"): - validate_measurement(measurement) - - -def test_successful_measurement_requires_successful_validation() -> None: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "artifact": {}, - "validation": {"status": ResultStatus.VALIDATION_FAILED.value}, - "resources": {}, - "provenance": {}, - } - ) - - with pytest.raises(ValueError, match="validation status"): - validate_measurement(measurement) - - -def _candidate_measurement_with_runtime_postflight() -> dict[str, object]: - observations = [ - { - "module": "pyamplicol", - "kind": "package-member", - "root_index": 0, - "path": "__init__.py", - "size": 10, - "sha256": "1" * 64, - } - ] - policy = { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": len(observations), - "observations": observations, - "observations_sha256": digest_json(observations), - } - identity = { - "kind": "pyamplicol-report-runtime-identity-v1", - "loaded_module_origin_policy": policy, - } - stable_identity = deepcopy(identity) - stable_policy = stable_identity["loaded_module_origin_policy"] - assert isinstance(stable_policy, dict) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - stable_policy.pop(field) - stable_digest = digest_json(stable_identity) - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "artifact": {}, - "validation": { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - }, - "resources": {}, - "provenance": { - "runtime_identity": identity, - "runtime_identity_sha256": digest_json(identity), - "runtime_identity_stable_sha256": stable_digest, - "runtime_identity_postflight_stable_sha256": stable_digest, - "runtime_identity_postflight_loaded_module_origin_policy": deepcopy( - policy - ), - "runtime_identity_postflight_match": True, - }, - } - ) - return measurement - - -def _unverified_candidate_measurement(cell: CellSpec) -> dict[str, object]: - measurement = _candidate_measurement_with_runtime_postflight() - point_identity = "a" * 64 - ordering = "b" * 64 - - def resolved_record(precision: int, source: str) -> dict[str, object]: - record = pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "point_index": 0, - }, - ) - return { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": ResultStatus.OK.value, - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "scale_source": "resolved-component-l1", - "precision_digits": precision, - "points": [record], - } - - binary64 = resolved_record(16, "c" * 64) - p32 = resolved_record(32, "d" * 64) - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": None, - "value_kind": "matrix-element-p16-versus-p32", - } - high_precision = pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - candidate_scale_source="resolved-component-l1-binary64", - baseline_scale_source="resolved-component-l1-p32", - comparison_binding={ - "point_digest": point_identity, - "selector_component_identity": selector_identity, - "selector_component_sha256": digest_json(selector_identity), - "candidate_source_sha256": "c" * 64, - "baseline_source_sha256": "d" * 64, - }, - ) - validation = measurement["validation"] - assert isinstance(validation, dict) - validation.update( - { - "status": ResultStatus.UNVERIFIED.value, - "resolved_sum": binary64, - "high_precision_resolved_sum": p32, - "high_precision": high_precision, - "precision_diagnostic": { - "abi": ("pyamplicol-report-validation-failure-precision-diagnostic-v2"), - "status": "unavailable", - "promotes_measurement": False, - "error": {"kind": "FixtureUnavailable", "message": "fixture"}, - }, - INDEPENDENT_AUTHORITY_FIELD: { - "abi": INDEPENDENT_AUTHORITY_ABI, - "expected_cell_ids": [ - authority.cell_id - for authority in independent_numerical_authorities(cell) - ], - "selected_cell_id": None, - "status": "unavailable", - "reason": "no-successful-independent-authority", - "same_artifact_diagnostics_are_authority": False, - }, - } - ) - measurement["status"] = ResultStatus.UNVERIFIED.value - measurement["failure"] = { - "kind": "IndependentAuthorityUnavailable", - "message": "no successful independent numerical authority is available", - } - return measurement - - -def test_unverified_measurement_contract_is_strict_and_catalog_bound() -> None: - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted" - ) - measurement = _unverified_candidate_measurement(cell) - validate_measurement(measurement, expected_cell=cell) - - validation = measurement["validation"] - assert isinstance(validation, dict) - authority = validation[INDEPENDENT_AUTHORITY_FIELD] - assert isinstance(authority, dict) - canonical = list(authority["expected_cell_ids"]) - malformed_chains = [ - canonical[:-1], - [*canonical, "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted"], - ] - if len(canonical) > 1: - malformed_chains.append(list(reversed(canonical))) - for malformed in malformed_chains: - tampered = deepcopy(measurement) - tampered["validation"][INDEPENDENT_AUTHORITY_FIELD][ # type: ignore[index] - "expected_cell_ids" - ] = malformed - with pytest.raises(ValueError, match="independent-authority"): - validate_measurement(tampered, expected_cell=cell) - - tampered = deepcopy(measurement) - tampered["validation"]["precision_diagnostic"][ # type: ignore[index] - "promotes_measurement" - ] = True - with pytest.raises(ValueError, match="precision diagnostic"): - validate_measurement(tampered, expected_cell=cell) - - -@pytest.mark.parametrize( - "cell_id", - ( - "scalar-contact-n2-scalar-contact-contracted", - "scalar-gravity-n2-scalar-gravity-contracted", - ), -) -def test_standalone_scalar_cell_rejects_inapplicable_unverified_authority( - cell_id: str, -) -> None: - cell = REPORT_CATALOG.cell(cell_id) - measurement = _unverified_candidate_measurement(cell) - - with pytest.raises(ValueError, match="not applicable"): - validate_measurement(measurement, expected_cell=cell) - - -@pytest.mark.parametrize( - "cell_id", - ( - "scalar-contact-n2-scalar-contact-contracted", - "scalar-gravity-n2-scalar-gravity-contracted", - ), -) -def test_standalone_scalar_ok_requires_strict_internal_p32_contract( - cell_id: str, -) -> None: - cell = REPORT_CATALOG.cell(cell_id) - measurement = _unverified_candidate_measurement(cell) - measurement["status"] = ResultStatus.OK.value - measurement["failure"] = None - validation = measurement["validation"] - assert isinstance(validation, dict) - validation["status"] = ResultStatus.OK.value - validation.pop("precision_diagnostic") - validation.pop(INDEPENDENT_AUTHORITY_FIELD) - - validate_measurement(measurement, expected_cell=cell) - validation.pop("high_precision") - with pytest.raises(ValueError, match="high_precision"): - validate_measurement(measurement, expected_cell=cell) - - -def test_recurrence_ok_requires_p32_even_with_legacy_diagnostic_baseline() -> None: - cell = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n1-dd-z-jets-contracted" - ) - measurement = _unverified_candidate_measurement(cell) - measurement["status"] = ResultStatus.OK.value - measurement["failure"] = None - validation = measurement["validation"] - assert isinstance(validation, dict) - validation["status"] = ResultStatus.OK.value - validation.pop("precision_diagnostic") - validation.pop(INDEPENDENT_AUTHORITY_FIELD) - validation["pointwise"] = deepcopy(validation["high_precision"]) - - validate_measurement(measurement, expected_cell=cell) - validation.pop("high_precision") - with pytest.raises(ValueError, match="high_precision"): - validate_measurement(measurement, expected_cell=cell) - - -@pytest.mark.parametrize( - "mutation", - ( - "point", - "ordering", - "binary-precision", - "matrix-value", - "p32-value", - ), -) -def test_standalone_scalar_ok_rejects_cross_record_p32_tampering( - mutation: str, -) -> None: - cell = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - measurement = _unverified_candidate_measurement(cell) - measurement["status"] = ResultStatus.OK.value - measurement["failure"] = None - validation = measurement["validation"] - assert isinstance(validation, dict) - validation["status"] = ResultStatus.OK.value - validation.pop("precision_diagnostic") - validation.pop(INDEPENDENT_AUTHORITY_FIELD) - resolved = validation["resolved_sum"] - high_resolved = validation["high_precision_resolved_sum"] - assert isinstance(resolved, dict) - assert isinstance(high_resolved, dict) - high_points = high_resolved["points"] - assert isinstance(high_points, list) - high_point = high_points[0] - assert isinstance(high_point, dict) - high_binding = high_point["comparison_binding"] - assert isinstance(high_binding, dict) - - if mutation == "point": - high_resolved["point_digest"] = "e" * 64 - high_binding["point_digest"] = "e" * 64 - elif mutation == "ordering": - high_resolved["resolved_ordering_sha256"] = "e" * 64 - high_binding["resolved_ordering_sha256"] = "e" * 64 - elif mutation == "binary-precision": - resolved["precision_digits"] = 17 - elif mutation == "matrix-value": - measurement["matrix_element"] = 2.0 - else: - high_points[0] = pointwise_validation( - 2.0, - 2.0, - candidate_scale=2.0, - baseline_scale=2.0, - candidate_scale_source=str(high_point["candidate_scale_source"]), - baseline_scale_source=str(high_point["baseline_scale_source"]), - comparison_binding=high_binding, - ) - - with pytest.raises(ValueError, match="standalone"): - validate_measurement(measurement, expected_cell=cell) - - -def test_unverified_presentation_overlay_is_attempt_bound_and_json_isolated( - tmp_path: Path, -) -> None: - repo = tmp_path / "repo" - docs = repo / "docs" / "performance_reports" / "manual" - docs.mkdir(parents=True) - service = ReportService( - ReportPaths.from_repo( - repo, - docs_dir=docs, - artifact_root=tmp_path / "campaign-artifacts", - coordination_root=tmp_path / "campaign-artifacts" / "coordination", - ) - ) - cell = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n1-dd-z-jets-contracted" - ) - revision = "a" * 40 - measurement = _unverified_candidate_measurement(cell) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance.update( - { - "report_source_revision": revision, - "manual_campaign": { - "cell_identity": { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "workload": cell.workload.value, - "execution_mode": cell.measurement.execution_mode.value, - "model": cell.measurement.model.value, - "accuracy": cell.measurement.accuracy.value, - "backend": cell.measurement.backend, - "variant": cell.variant, - } - }, - } - ) - validate_measurement(measurement, expected_cell=cell) - - attempt = service.store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE) - attempt.write_json("worker-result.json", measurement) - attempt.mark_failed( - "independent authority unavailable", - artifact_paths=("worker-result.json",), - ) - outcome = manual_campaign.LightweightPresentationOutcome( - profile="campaign-local-v1", - cell_id=cell.cell_id, - source_revision=revision, - campaign_invocation_id="fixture", - attempt_id=attempt.attempt_id, - status=ResultStatus.UNVERIFIED.value, - label="unverified", - completed_at_ns=1, - ) - - publication_caches, publication_merged = ( - manual_campaign._merge_lightweight_snapshot(service, {}) - ) - render_caches, render_merged = manual_campaign._merge_lightweight_snapshot( - service, - {}, - {cell.cell_id: outcome}, - ) - assert publication_merged == 0 - assert render_merged == 1 - - def cell_measurement( - caches: dict[str, dict[str, object]], - ) -> dict[str, object]: - payload = caches[f"{cell.dataset_id}.json"] - entries = payload["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if isinstance(item, dict) and item.get("cell_id") == cell.cell_id - ) - value = entry["measurement"] - assert isinstance(value, dict) - return value - - assert cell_measurement(render_caches)["status"] == ResultStatus.UNVERIFIED.value - assert cell_measurement(render_caches)["generation_seconds"] == 1.0 - assert cell_measurement(publication_caches)["status"] == ( - ResultStatus.NOT_AVAILABLE.value - ) - - tables = service._render_tables(render_caches) - assert ( - "unverified" - in tables["result_matrix_compiled_builtin_sm_full_table.tex"].lower() - ) - service._snapshot_files(publication_caches, tables) - installed_payloads = tuple( - path - for path in service.paths.results_dir.glob("*.json") - if path.name != "report-cache.schema.json" - ) - assert installed_payloads - assert all( - '"status":"unverified"' - not in json.dumps( - json.loads(path.read_text(encoding="ascii")), - separators=(",", ":"), - ) - for path in installed_payloads - ) - - wrong_source = replace(outcome, source_revision="b" * 40) - wrong_attempt = replace( - outcome, - attempt_id="00000000-0000-4000-8000-000000000000", - ) - wrong_identity_measurement = deepcopy(measurement) - wrong_identity_provenance = wrong_identity_measurement["provenance"] - assert isinstance(wrong_identity_provenance, dict) - wrong_identity_manual = wrong_identity_provenance["manual_campaign"] - assert isinstance(wrong_identity_manual, dict) - wrong_identity = wrong_identity_manual["cell_identity"] - assert isinstance(wrong_identity, dict) - wrong_identity["cell_id"] = "different-cell" - wrong_identity_attempt = service.store.new_attempt( - cell.cell_id, - ArtifactPolicy.REGENERATE, - ) - wrong_identity_attempt.write_json( - "worker-result.json", - wrong_identity_measurement, - ) - wrong_identity_attempt.mark_failed( - "independent authority unavailable", - artifact_paths=("worker-result.json",), - ) - wrong_cell = replace(outcome, attempt_id=wrong_identity_attempt.attempt_id) - for malformed in (wrong_source, wrong_attempt, wrong_cell): - fallback = manual_campaign._presentation_measurement( - service, - cell, - malformed, - ) - validate_measurement(fallback, expected_cell=cell) - assert fallback["status"] == ResultStatus.FAILED.value - assert fallback["generation_seconds"] is None - failure = fallback["failure"] - assert isinstance(failure, dict) - assert failure["kind"] == "ManualCampaignOutcome:unverified" - - -def test_unverified_measurement_requires_every_hard_direct_agreement() -> None: - cell = REPORT_CATALOG.cell("matrix-compiled-builtin-sm-lc-n1-dd-z-jets-all-flow") - required = next(edge for edge in incoming_agreement_edges(cell) if edge.required) - legacy = next( - edge - for edge in incoming_agreement_edges(cell) - if edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT - ) - with pytest.raises(ValueError, match="coverage is incomplete"): - _validate_unverified_direct_agreement_coverage( - {DIRECT_AGREEMENT_FIELD: []}, - expected_cell=cell, - catalog=REPORT_CATALOG, - ) - _validate_unverified_direct_agreement_coverage( - { - DIRECT_AGREEMENT_FIELD: [ - { - "edge_kind": required.kind, - "baseline_cell_id": required.baseline.cell_id, - "candidate_cell_id": cell.cell_id, - "status": ResultStatus.OK.value, - }, - { - "edge_kind": legacy.kind, - "baseline_cell_id": legacy.baseline.cell_id, - "candidate_cell_id": cell.cell_id, - "status": ResultStatus.VALIDATION_FAILED.value, - }, - ] - }, - expected_cell=cell, - catalog=REPORT_CATALOG, - ) - - -def _arena_unavailable_candidate_measurement() -> dict[str, object]: - measurement = _candidate_measurement_with_runtime_postflight() - measurement["execution_seconds_per_point"] = None - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance["source_revision"] = "a" * 40 - raw_profile = { - "execution_mode": "compiled", - "profile_boundary": ARENA_PROFILE_BOUNDARY, - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "evaluator_timing_available": False, - "points": 128, - "wall_time_s": 128 * 1.1e-6, - "orchestration_time_s": 128 * 1.1e-6, - **{field: 0 for field in ZERO_ARENA_COUNTER_FIELDS}, - **{field: 0.0 for field in ZERO_ARENA_PHASE_TIME_FIELDS}, - **{field: [] for field in EMPTY_ARENA_PHASE_VECTOR_FIELDS}, - **{field: 0 for field in ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS}, - "compiled_direct_arena_engine_count": 1, - "compiled_direct_arena_call_count": 128, - "evaluator_backend_call_count": 128, - } - arena_evidence = build_arena_profile_evidence( - [raw_profile] * 5, - execution_mode="compiled", - repetitions_per_profile=1, - batch_size=128, - ) - provenance["arena_profile_evidence"] = arena_evidence - provenance["execution_timing"] = { - "abi": "pyamplicol-report-arena-execution-timing-v2", - "status": "unavailable", - "ratio_eligible": False, - "raw_seconds_per_point": None, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "repetitions_per_sample": 1, - "batch_size": 128, - "sample_contract": ("paired_unprofiled_headline_profiled_attribution_v1"), - "profile_protocol": "arena", - "profile_sample_pass": "runtime._profile_arena_repeated", - "profile_boundary": ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" - ), - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": "coarse-arena-boundary-only-v1", - "evaluator_timing_available": False, - "paired_with_headline": True, - "identical_batch": True, - "identical_repetitions": True, - "execution_mode": "compiled", - "warmed_boundary_wall_seconds_per_point": 1.1e-6, - "arena_profile_evidence_sha256": digest_arena_profile_value(arena_evidence), - } - return measurement - - -def test_candidate_null_execution_requires_authenticated_arena_provenance() -> None: - measurement = _arena_unavailable_candidate_measurement() - validate_measurement(measurement) - - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance.pop("execution_timing") - with pytest.raises(ValueError, match="authenticated Arena provenance"): - validate_measurement(measurement) - - -def test_future_evaluator_total_provenance_is_optional_and_fail_closed() -> None: - measurement = _arena_unavailable_candidate_measurement() - validate_measurement(measurement) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance["evaluator_total_timing"] = { - "abi": "pyamplicol-report-evaluator-total-timing-v1", - "status": "measured", - "ratio_eligible": False, - "raw_seconds_per_point": 1.0e-6, - "source": "runtime._benchmark_f64_wall_time.accumulated", - "execution_mode": "compiled", - "sample_contract": ("accumulated-repeated-warmed-evaluator-total-v1"), - "sample_count": 5, - "repetitions_per_sample": 1, - "batch_size": 128, - "points_per_sample": 128, - "measured_point_count": 640, - "accumulated_seconds": 6.4e-4, - } - validate_measurement(measurement) - - total = provenance["evaluator_total_timing"] - assert isinstance(total, dict) - total["accumulated_seconds"] = 1.0 - with pytest.raises(ValueError, match="evaluator_total_timing"): - validate_measurement(measurement) - - -@pytest.mark.parametrize( - ("field", "value"), - ( - ("ratio_eligible", True), - ("raw_seconds_per_point", 0.0), - ("profile_protocol", "frozen-pre-arena"), - ("profile_sample_pass", "runtime.profile_repeated"), - ("borrowed_flat_input", False), - ("evaluator_timing_available", True), - ("native_profile_points_per_sample", None), - ("warmed_boundary_wall_seconds_per_point", 0.0), - ), -) -def test_arena_unavailable_execution_provenance_is_fail_closed( - field: str, - value: object, -) -> None: - measurement = _arena_unavailable_candidate_measurement() - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - timing = provenance["execution_timing"] - assert isinstance(timing, dict) - timing[field] = value - - with pytest.raises(ValueError, match="unavailable-attribution record"): - validate_measurement(measurement) - - -@pytest.mark.parametrize( - ("field", "value", "match"), - [ - ( - "runtime_identity", - None, - "requires runtime_identity", - ), - ( - "runtime_identity_stable_sha256", - "0" * 64, - "runtime_identity_stable_sha256", - ), - ( - "runtime_identity_postflight_stable_sha256", - "0" * 64, - "postflight stable SHA-256", - ), - ( - "runtime_identity_postflight_loaded_module_origin_policy", - {}, - "loaded-origin evidence", - ), - ( - "runtime_identity_postflight_match", - False, - "runtime_identity_postflight_match", - ), - ], -) -def test_successful_candidate_measurement_requires_runtime_postflight( - field: str, - value: object, - match: str, -) -> None: - measurement = _candidate_measurement_with_runtime_postflight() - validate_measurement(measurement) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance[field] = value - with pytest.raises(ValueError, match=match): - validate_measurement(measurement) - - -def test_candidate_runtime_postflight_cannot_lose_initial_origin() -> None: - measurement = _candidate_measurement_with_runtime_postflight() - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - postflight = provenance["runtime_identity_postflight_loaded_module_origin_policy"] - assert isinstance(postflight, dict) - observations = postflight["observations"] - assert isinstance(observations, list) - observations[0] = { - "module": "pyamplicol.replaced", - "kind": "package-member", - "root_index": 0, - "path": "replaced.py", - "size": 10, - "sha256": "2" * 64, - } - postflight["observations_sha256"] = digest_json(observations) - with pytest.raises(ValueError, match="lost a loaded-module origin"): - validate_measurement(measurement) diff --git a/pyamplicol/tests/unit/test_three_mode_report_legacy.py b/pyamplicol/tests/unit/test_three_mode_report_legacy.py deleted file mode 100644 index a4233c31f1..0000000000 --- a/pyamplicol/tests/unit/test_three_mode_report_legacy.py +++ /dev/null @@ -1,2141 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -from contextlib import contextmanager -from dataclasses import dataclass -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from tools.performance_report.cache import validate_measurement -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.legacy import ( - LEGACY_IMODE2_DIAGNOSTIC_ABI, - LEGACY_IMODE2_DIAGNOSTIC_FIELD, - LEGACY_NUMERICAL_AUTHORITY_ABI, - LEGACY_NUMERICAL_AUTHORITY_FIELD, - CommandResult, - LegacyAdapterError, - LegacyMeasurementAdapter, - LegacySettings, - MaintainedLegacyApi, - TimingRow, - _canonical_mapped_color_word, - _canonical_process_entry, - _fixed_helicity, - _generation_lepton_pt_cut, - _helicity_id, - _parse_generated_library_color_probe_output, - adaptive_profile_points, -) -from tools.performance_report.models import Accuracy, ExecutionMode, Workload -from tools.performance_report.runner import ( - ProfilingTimeLimitError, - RunnerError, - SelectorContract, - point_digest, - validate_selector_contract, -) - - -@dataclass(frozen=True) -class FakeEntry: - group: int = 1 - integral: int = 2 - process_pdgs: tuple[int, ...] = (1, -1, 23, 21) - color_order: tuple[int, ...] = (2, 4, 1, 3) - - -class FakeApi: - default_repository = Path("/fake/legacy") - - def __init__(self, pdgs: tuple[int, ...] = (1, -1, 23, 21)) -> None: - self.pdgs = pdgs - self.entry = FakeEntry( - process_pdgs=pdgs, - color_order=( - # Three open strings with any adjoints attached to the final - # string: [fundamental, adjoints..., antifundamental]. - (2, 1, 3, 4, 5, *range(7, len(pdgs) + 1), 6) - if len(pdgs) >= 6 - else (2, 4, 1, 3) - ), - ) - self.selected_calls: list[tuple[int, tuple[int, ...]]] = [] - self.color_calls: list[tuple[str, tuple[int, ...] | None]] = [] - self.lc_probe_result: object | None = None - self.generated_library_probe_value = 9.75 - self.direct_color_probe_value = 9.75 - self.selected_flow_value = 3.25 - self.selected_flow_fixed_helicity_value = 2.5 - self.parsed_probe_count = 0 - - def expected_revision(self) -> str: - return "a" * 40 - - def validate_checkout(self, repository: Path) -> None: - pass - - def compiler_provenance(self, repository: Path) -> object: - return {"identity": "gfortran", "version": "test"} - - def process_pdgs(self, process: str) -> tuple[int, ...]: - return self.pdgs - - def parse_process_file(self, path: Path) -> tuple[object, ...]: - return (self.entry,) - - def select_generated_process_entry( - self, - entries: tuple[object, ...], - *, - generated_process: str, - wanted_pdgs: tuple[int, ...], - ) -> tuple[object, tuple[object, ...]]: - assert wanted_pdgs == self.pdgs - return entries[0], entries - - def source_mapped_color_order( - self, - entry: object, - *, - source_pdgs: tuple[int, ...], - ) -> tuple[int, ...]: - return self.entry.color_order - - def ordered_momenta( - self, - source_pdgs: tuple[int, ...], - target_pdgs: tuple[int, ...], - momenta: tuple[tuple[float, ...], ...], - ) -> tuple[tuple[float, ...], ...]: - return momenta - - def source_to_row_permutation( - self, - source_pdgs: tuple[int, ...], - target_pdgs: tuple[int, ...], - ) -> tuple[int, ...]: - return tuple(range(len(source_pdgs))) - - def parse_probe_output(self, output: str) -> object: - self.parsed_probe_count += 1 - marker = "FAKE_PROBE_VALUE " - values = [ - float(line.removeprefix(marker)) - for line in output.splitlines() - if line.startswith(marker) - ] - assert len(values) == 1 - return SimpleNamespace(value=values[0]) - - def run_selected_flow_probe(self, repository: Path, **kwargs: object) -> object: - self.selected_calls.append((int(kwargs["points"]), tuple(kwargs["helicities"]))) - return SimpleNamespace( - value=self.selected_flow_value, - fixed_helicity_value=self.selected_flow_fixed_helicity_value, - ) - - def run_color_probe(self, repository: Path, **kwargs: object) -> object: - accuracy = str(kwargs["color_accuracy"]) - helicities = kwargs["helicities"] - self.color_calls.append( - (accuracy, None if helicities is None else tuple(helicities)) - ) - if accuracy == Accuracy.LC.value and self.lc_probe_result is not None: - return self.lc_probe_result - aggregate = ( - 2.5 - if accuracy == Accuracy.LC.value - else self.direct_color_probe_value - ) - return SimpleNamespace( - value=aggregate, - lc_row_partitions=( - SimpleNamespace(row=1, value=2.5, permutation=(2, 4, 1)), - ), - lc_partition_sum=2.5, - ) - - -class EntryMappedFakeApi(FakeApi): - """Expose distinct generated entries so selector tests cannot use a stub row.""" - - def __init__( - self, - pdgs: tuple[int, ...], - entries: tuple[FakeEntry, ...], - *, - selected_entry: FakeEntry, - ) -> None: - super().__init__(pdgs) - self.entries = entries - self.selected_entry = selected_entry - self.mapped_entries: list[FakeEntry] = [] - self.probed_entries: list[FakeEntry] = [] - - def parse_process_file(self, path: Path) -> tuple[object, ...]: - return self.entries - - def select_generated_process_entry( - self, - entries: tuple[object, ...], - *, - generated_process: str, - wanted_pdgs: tuple[int, ...], - ) -> tuple[object, tuple[object, ...]]: - assert entries == self.entries - assert wanted_pdgs == self.pdgs - return self.selected_entry, self.entries - - def source_mapped_color_order( - self, - entry: object, - *, - source_pdgs: tuple[int, ...], - ) -> tuple[int, ...]: - assert source_pdgs == self.pdgs - assert isinstance(entry, FakeEntry) - self.mapped_entries.append(entry) - return entry.color_order - - def run_color_probe(self, repository: Path, **kwargs: object) -> object: - entry = kwargs["entry"] - assert isinstance(entry, FakeEntry) - self.probed_entries.append(entry) - return super().run_color_probe(repository, **kwargs) - - -class FakeExecutor: - def __init__( - self, - api: FakeApi, - phase_reporter: FakePhaseReporter | None = None, - ) -> None: - self.api = api - self.commands: list[tuple[str, ...]] = [] - self.command_generation_phase: list[bool] = [] - self.profile_calls = 0 - self.phase_reporter = phase_reporter - - def run( - self, - args: object, - *, - cwd: Path, - environment: object = None, - ) -> CommandResult: - rendered = tuple(str(item) for item in args) - self.commands.append(rendered) - self.command_generation_phase.append( - bool( - self.phase_reporter is not None - and self.phase_reporter.active - ) - ) - if any(item.endswith("process_list.py") for item in rendered): - cwd.mkdir(parents=True, exist_ok=True) - (cwd / "processes.txt").write_text("fake\n", encoding="utf-8") - points = 1 - is_profile = bool( - rendered - and ( - rendered[0] - in { - "./amplicol_library_benchmark", - "./amplicol_color_library_probe", - } - or rendered[0].endswith("amplicol_color_probe") - ) - ) - if is_profile: - points = int(rendered[1]) - rate_factors = ( - 1.0, - 0.99999, - 1.00001, - 1.0, - 1.000005, - 0.999995, - ) - if self.phase_reporter is not None and self.phase_reporter.active: - # A dedicated generation-only probe must not consume a sample - # from the subsequent adaptive runtime profile. - factor = 1.0 - else: - factor = rate_factors[self.profile_calls % len(rate_factors)] - self.profile_calls += 1 - else: - factor = 1.0 - evaluation = points * 0.001 * factor - output = ( - "Timing summary\n" - "generation setup 2.5\n" - f"amplitude evaluation {evaluation}\n" - f"total {evaluation * 1.1}\n" - "FAKE_PROBE_VALUE " - + ( - f"{self.api.generated_library_probe_value}\n" - if rendered and rendered[0] == "./amplicol_color_library_probe" - else "12.5\n" - ) - ) - if rendered and rendered[0] == "./amplicol_color_library_probe": - accuracy = rendered[4] - value = self.api.generated_library_probe_value - output += ( - f"AMPICOL_COLOR_PROBE_COMPONENTS {value} {value} {value}\n" - f"AMPICOL_COLOR_PROBE_VALUE {accuracy} {rendered[2]} " - f"{rendered[3]} {value}\n" - ) - elapsed = 0.25 if rendered and rendered[0] != "make" else 0.1 - return CommandResult( - args=rendered, - cwd=cwd, - elapsed_seconds=elapsed, - returncode=0, - stdout=output, - stderr="", - environment={} if environment is None else dict(environment), - ) - - -class FakeSnapshotter: - def snapshot( - self, - repository: Path, - destination: Path, - *, - executables: tuple[str, ...], - process_file: Path, - ) -> Path: - destination.mkdir(parents=True, exist_ok=True) - (destination / "Library").mkdir(exist_ok=True) - (destination / "processes.txt").write_text("fake\n", encoding="utf-8") - for executable in executables: - (destination / executable).touch() - (destination / executable).chmod(0o755) - return destination - - -class FakePhaseReporter: - def __init__(self) -> None: - self.active = False - self.interval_count = 0 - self.phase = "pre-generation" - self.transitions: list[str] = [] - - @contextmanager - def generation(self): - assert not self.active - assert self.phase == "pre-generation" - self.interval_count += 1 - self.active = True - self.phase = "generation" - try: - yield - finally: - self.active = False - self.phase = "post-generation" - - def profiling_started(self) -> None: - assert self.phase == "post-generation" - self.phase = "profiling" - self.transitions.append(self.phase) - - def validation_started(self) -> None: - assert self.phase == "profiling" - self.phase = "validation" - self.transitions.append(self.phase) - - def complete(self) -> None: - assert self.phase == "validation" - self.phase = "complete" - self.transitions.append(self.phase) - - -def _cell( - accuracy: Accuracy, - workload: Workload, - *, - process_key: str = "dd_z_jets", - n_final: int | None = None, -): - return next( - cell - for cell in REPORT_CATALOG.reference_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.measurement.accuracy is accuracy - and cell.workload is workload - and cell.process_key == process_key - and cell.n_final - == ( - n_final - if n_final is not None - else 1 - if process_key == "dd_z_jets" - else cell.n_final - ) - ) - - -def _adapter( - api: FakeApi | None = None, - *, - phase_reporter: FakePhaseReporter | None = None, -): - fake_api = FakeApi() if api is None else api - executor = FakeExecutor(fake_api, phase_reporter) - return ( - LegacyMeasurementAdapter( - api=fake_api, - executor=executor, - snapshotter=FakeSnapshotter(), - ), - fake_api, - executor, - ) - - -def _settings(repository: Path) -> LegacySettings: - return LegacySettings( - target_runtime_seconds=1.0, - warmup_points=100, - minimum_points=100, - maximum_points=10_000, - repository=repository, - ) - - -def test_canonical_process_entry_retains_preferred_duplicate_word() -> None: - pdgs = (1, -1, 11, -11) - first = FakeEntry(group=1, integral=1, process_pdgs=pdgs, color_order=(2, 1, 3, 4)) - preferred = FakeEntry( - group=2, - integral=1, - process_pdgs=pdgs, - color_order=(2, 1, 4, 3), - ) - api = EntryMappedFakeApi(pdgs, (first, preferred), selected_entry=preferred) - - entry, _mapped, word = _canonical_process_entry( - api, - (first, preferred), - preferred_entry=preferred, - source_pdgs=pdgs, - initial_state_count=2, - ) - - assert entry is preferred - assert word == (2, 1) - - -@pytest.mark.parametrize( - "pdgs", - ( - (1, -1, 2, -2, 3, -3, 21), - (1, -1, 2, -2, 2, -2, 21), - ), -) -def test_real_three_line_process_file_keeps_exact_source_carrier( - pdgs: tuple[int, ...], - tmp_path: Path, -) -> None: - process_file = tmp_path / "processes.txt" - pdg_row = " ".join(str(pdg) for pdg in pdgs) - process_file.write_text( - "\n".join( - ( - "7 1", - pdg_row, - "2", - "4 1 1 1 3 4 5 6 2 7", - f"1 4 {pdg_row} 2 7 1 3 4 5 6 0.5", - "5 1 1 1 3 4 5 6 7 2", - f"1 5 {pdg_row} 2 1 3 4 5 7 6 0.5", - "", - ) - ), - encoding="utf-8", - ) - api = MaintainedLegacyApi() - entries = api.parse_process_file(process_file) - preferred, matches = api.select_generated_process_entry( - entries, - generated_process="d d~ > three open lines plus g", - wanted_pdgs=pdgs, - ) - - entry, mapped, word = _canonical_process_entry( - api, - matches, - preferred_entry=preferred, - source_pdgs=pdgs, - initial_state_count=2, - ) - - assert int(entry.group) == 4 - assert mapped == (2, 7, 1, 3, 4, 5, 6) - assert word == (2, 7, 1, 3, 4, 5, 6) - - -def test_real_two_line_process_file_keeps_cross_paired_source_carrier( - tmp_path: Path, -) -> None: - process_file = tmp_path / "processes.txt" - process_file.write_text( - """6 4 -1 6 -1 -6 21 21 -1 6 -6 -1 21 21 -6 1 -1 -6 21 21 -6 1 -6 -1 21 21 - - -2 - -1 1 1 1 2 3 4 6 5 -1 1 1 -1 21 21 6 -6 5 1 2 3 4 6 2.0 - - - -2 1 1 1 2 3 6 5 4 -1 2 1 -1 21 21 6 -6 5 4 1 2 3 6 2.0 -""", - encoding="utf-8", - ) - pdgs = (1, -1, 6, -6, 21, 21) - api = MaintainedLegacyApi() - entries = api.parse_process_file(process_file) - preferred, matches = api.select_generated_process_entry( - entries, - generated_process="d d~ > t t~ g g", - wanted_pdgs=pdgs, - ) - - entry, mapped, word = _canonical_process_entry( - api, - matches, - preferred_entry=preferred, - source_pdgs=pdgs, - initial_state_count=2, - ) - - assert int(entry.group) == 1 - assert mapped == (3, 1, 2, 5, 6, 4) - assert word == (2, 5, 6, 4, 3, 1) - - -@pytest.mark.parametrize( - ("n_final", "pdgs", "selected_word", "other_word", "reverse_entries"), - ( - ( - 4, - (1, -1, 2, -2, 2, -2), - (2, 1, 3, 4, 5, 6), - (2, 4, 3, 1, 5, 6), - False, - ), - ( - 4, - (1, -1, 2, -2, 2, -2), - (2, 1, 3, 4, 5, 6), - (2, 4, 3, 1, 5, 6), - True, - ), - ( - 5, - (1, -1, 2, -2, 2, -2, 21), - (2, 7, 1, 3, 4, 5, 6), - (2, 1, 3, 4, 5, 7, 6), - False, - ), - ( - 5, - (1, -1, 2, -2, 2, -2, 21), - (2, 7, 1, 3, 4, 5, 6), - (2, 1, 3, 4, 5, 7, 6), - True, - ), - ), -) -def test_identical_three_line_lc_uses_selected_entry_mapped_row( - n_final: int, - pdgs: tuple[int, ...], - selected_word: tuple[int, ...], - other_word: tuple[int, ...], - reverse_entries: bool, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - selected_entry = FakeEntry(group=2, process_pdgs=pdgs, color_order=selected_word) - other_entry = FakeEntry(group=1, process_pdgs=pdgs, color_order=other_word) - entries = ( - (selected_entry, other_entry) - if reverse_entries - else (other_entry, selected_entry) - ) - # The exact-source process-file row is the generated-library carrier. - # Reordering the surrounding candidate rows must not replace it. - api = EntryMappedFakeApi(pdgs, entries, selected_entry=selected_entry) - api.lc_probe_result = SimpleNamespace( - value=4.0, - lc_row_partitions=( - SimpleNamespace(row=1, value=1.5, permutation=other_word), - SimpleNamespace(row=2, value=2.5, permutation=selected_word), - ), - lc_partition_sum=4.0, - ) - adapter, _api, _executor = _adapter(api) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs),), - ), - ) - - measurement = adapter.measure( - _cell( - Accuracy.LC, - Workload.ALL_FLOW, - process_key="dd_3q_identical_lines", - n_final=n_final, - ), - artifact_path=tmp_path / f"identical-n{n_final}", - settings=_settings(tmp_path / "repository"), - ) - - contract = SelectorContract.from_mapping(measurement["selector_contract"]) - assert api.mapped_entries == [selected_entry] - assert api.probed_entries == [selected_entry] - assert contract.selected_color_flow_ids == ( - "flow:" + ",".join(str(label) for label in selected_word), - ) - assert contract.selected_color_words == (selected_word,) - assert measurement["validation"]["lc_common_component"]["value"] == 2.5 - - -@pytest.mark.parametrize( - ( - "n_final", - "pdgs", - "selected_word", - "same_canonical_word", - "other_word", - ), - ( - ( - 4, - (1, -1, 2, -2, 2, -2), - (2, 1, 3, 4, 5, 6), - (3, 4, 2, 1, 5, 6), - (2, 4, 3, 1, 5, 6), - ), - ( - 5, - (1, -1, 2, -2, 2, -2, 21), - (2, 7, 1, 3, 4, 5, 6), - (3, 4, 2, 7, 1, 5, 6), - (2, 1, 3, 4, 5, 7, 6), - ), - ), -) -def test_identical_three_line_lc_rejects_duplicate_canonical_probe_rows( - n_final: int, - pdgs: tuple[int, ...], - selected_word: tuple[int, ...], - same_canonical_word: tuple[int, ...], - other_word: tuple[int, ...], - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - selected_entry = FakeEntry( - group=2, - process_pdgs=pdgs, - color_order=selected_word, - ) - api = EntryMappedFakeApi( - pdgs, - ( - FakeEntry(group=1, process_pdgs=pdgs, color_order=other_word), - selected_entry, - ), - selected_entry=selected_entry, - ) - api.lc_probe_result = SimpleNamespace( - value=3.0, - lc_row_partitions=( - SimpleNamespace(row=1, value=1.0, permutation=selected_word), - SimpleNamespace(row=2, value=2.0, permutation=same_canonical_word), - ), - lc_partition_sum=3.0, - ) - adapter, _api, _executor = _adapter(api) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs),), - ), - ) - - with pytest.raises( - LegacyAdapterError, - match="did not identify exactly one selected physical row", - ): - adapter.measure( - _cell( - Accuracy.LC, - Workload.ALL_FLOW, - process_key="dd_3q_identical_lines", - n_final=n_final, - ), - artifact_path=tmp_path / f"identical-duplicate-n{n_final}", - settings=_settings(tmp_path / "repository"), - ) - - -def test_generated_library_color_probe_parser_accepts_real_counterless_stdout() -> None: - stdout = "\n".join( - ( - " Initialising amplitude for:", - " - a single polarisation/helicity configuration", - " - all colour orders", - "AmpliCol generated-library colour probe", - "points 100", - "group 1", - "integral 1", - "color_accuracy full", - "color_orders 2", - ( - "AMPICOL_COLOR_PROBE_COMPONENTS 4.7180245588895062E-04" - " 3.6371847402940423E-04 3.6371847402940423E-04" - ), - ( - "AMPICOL_COLOR_PROBE_RAW_COMPONENTS 8.1453155359829235E-02" - " 6.2793266551648116E-02 6.2793266551648116E-02" - ), - "AMPICOL_COLOR_PROBE_VALUE full 1 1 3.6371847402940423E-04", - "------------------------------------------------------------------------------", - "Timing summary seconds percent note", - "------------------------------------------------------------------------------", - ( - "amplitude evaluation 0.000056 56.57% " - "outer-loop-diagnostic" - ), - ( - "colour contraction 0.000031 31.31% " - "outer-loop-diagnostic" - ), - "total 0.000099 100.00% ", - "------------------------------------------------------------------------------", - ) - ) - - value = _parse_generated_library_color_probe_output( - stdout, - expected_accuracy="full", - expected_group=1, - expected_integral=1, - ) - - assert "AMPICOL_COLOR_PROBE_CURRENTS" not in stdout - assert value == 3.6371847402940423e-4 - - -@pytest.mark.parametrize( - "workload", - (Workload.SELECTED_FLOW, Workload.ALL_FLOW), -) -def test_legacy_generation_phase_excludes_adaptive_runtime_profile( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - workload: Workload, -) -> None: - repository = tmp_path / "legacy" - repository.mkdir() - phase_reporter = FakePhaseReporter() - adapter, _api, executor = _adapter( - phase_reporter=phase_reporter, - ) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - _api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in _api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in _api.pdgs),), - ), - ) - - result = adapter.measure( - _cell(Accuracy.LC, workload, n_final=2), - artifact_path=tmp_path / "artifact", - settings=_settings(repository), - phase_reporter=phase_reporter, # type: ignore[arg-type] - ) - - assert result["status"] == "ok" - assert phase_reporter.interval_count == 1 - assert not phase_reporter.active - assert phase_reporter.transitions == ["profiling", "validation"] - profiled = tuple( - in_generation - for command, in_generation in zip( - executor.commands, - executor.command_generation_phase, - strict=True, - ) - if command - and ( - command[0] == "./amplicol_library_benchmark" - or command[0].endswith("amplicol_color_probe") - ) - ) - assert profiled - if workload is Workload.SELECTED_FLOW: - assert not any(profiled) - generated = tuple( - in_generation - for command, in_generation in zip( - executor.commands, - executor.command_generation_phase, - strict=True, - ) - if command and command[0] == "./amplicol_generate" - ) - assert generated == (True,) - else: - # Direct all-flow generation is authenticated by one dedicated - # one-point probe. Warm-up and every adaptive timing chunk follow it - # outside the generation interval. - assert profiled[0] is True - assert not any(profiled[1:]) - assert result["generation_seconds"] == pytest.approx(2.5) - - -def test_adaptive_profile_points_are_bounded() -> None: - assert adaptive_profile_points( - 0.0, target_runtime_seconds=20.0, minimum_points=17 - ) == 17 - assert adaptive_profile_points( - 10.0, - target_runtime_seconds=20.0, - warmup_points=100, - minimum_points=100, - maximum_points=1_000, - ) == 200 - assert adaptive_profile_points( - 0.001, - target_runtime_seconds=20.0, - warmup_points=100, - maximum_points=1_000, - ) == 1_000 - - -def test_legacy_command_is_flushed_before_launch(tmp_path: Path) -> None: - log_path = tmp_path / "legacy.log" - commands: list[dict[str, object]] = [] - - class InspectingExecutor: - def run(self, args, *, cwd: Path, environment=None) -> CommandResult: - assert cwd == tmp_path - assert environment is None - assert log_path.read_text(encoding="utf-8") == ( - "$ probe 1\n[launch] intended_points=1\n" - ) - assert commands == [ - { - "args": ["probe", "1"], - "cwd": str(tmp_path.resolve()), - "environment": {}, - "status": "launching", - "intended_points": 1, - } - ] - return CommandResult( - args=tuple(args), - cwd=cwd, - elapsed_seconds=0.25, - returncode=0, - stdout="done\n", - stderr="", - environment={}, - ) - - adapter = LegacyMeasurementAdapter( - api=FakeApi(), - executor=InspectingExecutor(), - snapshotter=FakeSnapshotter(), - ) - - adapter._run( - ("probe", "1"), - cwd=tmp_path, - commands=commands, - log_path=log_path, - ) - - assert commands[0]["returncode"] == 0 - assert "status" not in commands[0] - assert log_path.read_text(encoding="utf-8").endswith("done\n") - - -@pytest.mark.parametrize( - ("source_pdgs", "raw_word", "canonical_word"), - ( - ( - (1, -1, 6, -6), - (3, 1, 2, 4), - (2, 4, 3, 1), - ), - ( - (1, -1, 6, -6, 21), - (3, 1, 2, 5, 4), - (2, 5, 4, 3, 1), - ), - ( - (1, -1, 6, -6, 21, 21), - (3, 1, 2, 5, 6, 4), - (2, 5, 6, 4, 3, 1), - ), - ( - (21, 21, 6, -6), - (3, 1, 2, 4), - (3, 1, 2, 4), - ), - ), -) -def test_legacy_open_string_blocks_match_canonical_public_selector_axis( - source_pdgs: tuple[int, ...], - raw_word: tuple[int, ...], - canonical_word: tuple[int, ...], -) -> None: - word = _canonical_mapped_color_word( - source_pdgs, - raw_word, - initial_state_count=2, - ) - - assert word == canonical_word - helicities = tuple(-1 if label % 2 else 1 for label in range(1, len(word) + 1)) - helicity_id = "h:" + ",".join(f"{value:+d}" for value in helicities) - source_helicities = tuple(enumerate(helicities, start=1)) - legacy_contract = SelectorContract( - selected_color_flow_ids=("flow:" + ",".join(str(label) for label in word),), - selected_color_words=(word,), - all_flow_helicity_ids=(helicity_id,), - all_flow_source_helicities=source_helicities, - point_digest="a" * 64, - ) - candidate_contract = SelectorContract( - selected_color_flow_ids=( - "flow:" + ",".join(str(label) for label in canonical_word), - ), - selected_color_words=(canonical_word,), - all_flow_helicity_ids=(helicity_id,), - all_flow_source_helicities=source_helicities, - point_digest="a" * 64, - ) - assert legacy_contract == candidate_contract - - -def test_legacy_closed_adjoint_word_keeps_generated_row_order() -> None: - assert _canonical_mapped_color_word( - (21, 21, 21, 21), - (1, 3, 2, 4), - initial_state_count=2, - ) == (1, 3, 2, 4) - - -@pytest.mark.parametrize( - "raw_word", - ( - (3, 2, 1, 4), - (1, 3, 2, 4), - (3, 1, 4, 2), - (3, 1, 2, 2), - ), -) -def test_legacy_selector_canonicalization_rejects_non_block_rows( - raw_word: tuple[int, ...], -) -> None: - with pytest.raises( - LegacyAdapterError, - match=r"permutation|concatenation", - ): - _canonical_mapped_color_word( - (1, -1, 6, -6), - raw_word, - initial_state_count=2, - ) - - -def test_profile_rejects_exactly_identical_bounded_chunk_rates( - tmp_path: Path, -) -> None: - adapter, _api, _executor = _adapter() - calls: list[int] = [] - - def invoke(points: int): - calls.append(points) - seconds = points * 1.0e-5 - result = CommandResult( - args=("probe", str(points)), - cwd=tmp_path, - elapsed_seconds=seconds, - returncode=0, - stdout="", - stderr="", - environment={}, - ) - return ( - result, - (TimingRow("amplitude evaluation", seconds),), - None, - ) - - with pytest.raises( - LegacyAdapterError, - match="positive measured uncertainty", - ): - adapter._profile( - invoke, - settings=LegacySettings( - target_runtime_seconds=0.005, - warmup_points=10, - minimum_points=10, - maximum_points=100, - maximum_profile_chunks=8, - repository=tmp_path, - ), - timing_labels=("amplitude evaluation",), - ) - - assert calls == [1, 100, 100, 100, 100, 100, 10, 10, 10] - - -def test_profile_rejects_a_bound_below_five_timed_chunks( - tmp_path: Path, -) -> None: - with pytest.raises( - ValueError, - match="maximum_profile_chunks must not be below", - ): - LegacySettings( - target_runtime_seconds=0.005, - warmup_points=10, - minimum_points=10, - maximum_points=100, - maximum_profile_chunks=2, - repository=tmp_path, - ) - - -def test_selected_flow_uses_generated_mode_one_and_compact_contract( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter() - point = tuple( - (float(index), index + 0.25, index + 0.5, index + 0.75) - for index, _pdg in enumerate(api.pdgs, start=1) - ) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - point, - (point,), - ), - ) - monkeypatch.setattr( - api, - "ordered_momenta", - lambda _source_pdgs, _target_pdgs, momenta: tuple(reversed(momenta)), - ) - measurement = adapter.measure( - _cell(Accuracy.LC, Workload.SELECTED_FLOW, n_final=2), - artifact_path=tmp_path / "selected", - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - assert measurement["status"] == "ok" - assert measurement["matrix_element"] == 3.25 - assert measurement["generation_seconds"] == pytest.approx(0.55) - # The fake driver reports amplitude evaluation at 1.0 ms and the complete - # observable, including squaring, at 1.1 ms. The headline must use total. - assert measurement["wall_seconds_per_point"] == pytest.approx(1.1e-3) - assert measurement["execution_seconds_per_point"] == pytest.approx(1.1e-3) - contract = SelectorContract.from_mapping(measurement["selector_contract"]) - assert contract.selected_color_flow_ids == ("flow:2,4,1",) - assert contract.all_flow_helicity_ids == ("h:-1,+1,-1,+1",) - assert api.selected_calls == [(1, (-1, 1, -1, 1))] - assert api.color_calls == [] - common = measurement["validation"]["lc_common_component"] - assert common["value"] == 2.5 - assert measurement["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] == { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": "selected-flow-generated-library", - } - flattened = [" ".join(command) for command in executor.commands] - assert any("--library=create" in command for command in flattened) - assert any("--seed=101" in command for command in flattened) - assert not any("--phasespace=" in command for command in flattened) - assert not any("--amplicol_momenta_probe=10" in command for command in flattened) - assert not any("--library=create-raw" in command for command in flattened) - assert not any("amplicol_color_probe" in command for command in flattened) - momenta_file = ( - tmp_path / "repository/Utilities/ME_checks/momenta_1_2.txt" - ) - assert momenta_file.is_file() - assert len(momenta_file.read_text(encoding="utf-8").splitlines()) == 4 - profiled = tuple( - command - for command in executor.commands - if command and command[0] == "./amplicol_library_benchmark" - ) - assert profiled - assert all(command[4] == "profile-momenta.dat" for command in profiled) - retained_momenta = ( - tmp_path - / "selected/selected-flow-generated-library/profile-momenta.dat" - ) - assert retained_momenta.is_file() - assert retained_momenta.read_text(encoding="utf-8") == ( - "\n".join( - " ".join(format(component, ".17g") for component in vector) - for vector in reversed(point) - ) - + "\n" - ) - - -def test_selected_flow_excludes_cold_generator_bootstrap_from_generation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter() - original_run = executor.run - generator_builds = 0 - - def run_with_cold_bootstrap( - args: object, - *, - cwd: Path, - environment: object = None, - ) -> CommandResult: - nonlocal generator_builds - result = original_run(args, cwd=cwd, environment=environment) - rendered = tuple(str(item) for item in args) - if ( - rendered - and rendered[0] == "make" - and "amplicol_generate" in rendered - ): - generator_builds += 1 - if generator_builds == 1: - return CommandResult( - args=result.args, - cwd=result.cwd, - elapsed_seconds=17.0, - returncode=result.returncode, - stdout=result.stdout, - stderr=result.stderr, - environment=result.environment, - ) - return result - - monkeypatch.setattr(executor, "run", run_with_cold_bootstrap) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - - measurement = adapter.measure( - _cell(Accuracy.LC, Workload.SELECTED_FLOW), - artifact_path=tmp_path / "selected", - settings=_settings(tmp_path / "repository"), - ) - - assert generator_builds == 2 - assert measurement["generation_seconds"] == pytest.approx(0.55) - commands = measurement["provenance"]["commands"] - assert commands[1]["args"] == ["make", "-j1", "amplicol_generate"] - assert commands[1]["elapsed_seconds"] == 17.0 - make_commands = [command for command in commands if command["args"][0] == "make"] - assert make_commands - assert all( - command["environment"] == {"PDF_BACKEND": "internal"} - for command in make_commands - ) - - -@pytest.mark.parametrize("generation_fails", (False, True)) -@pytest.mark.parametrize("n_final", range(4, 8)) -def test_four_lepton_discovery_restores_cuts_before_benchmark( - generation_fails: bool, - n_final: int, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - pdgs = (1, -1, -11, 11, -11, 11, *(21 for _ in range(n_final - 4))) - adapter, api, executor = _adapter(FakeApi(pdgs)) - api.entry = FakeEntry( - process_pdgs=pdgs, - color_order=(2, *range(7, len(pdgs) + 1), 1, 3, 4, 5, 6), - ) - point = tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: (api.pdgs, point, (point,)), - ) - repository = tmp_path / "repository" - repository.mkdir() - common = repository / "common.f03" - original = " real(kind=8),parameter :: pTl_min = -1d0\n" - common.write_text(original, encoding="utf-8") - common_object = repository / "common.o" - common_object.write_bytes(b"stale") - original_run = executor.run - - def check_configuration(args, *, cwd, environment=None): - if args[0] == "./amplicol_generate": - assert "pTl_min = 30d0" in common.read_text(encoding="utf-8") - assert "--seed=101" in args - assert not common_object.exists() - common_object.write_bytes(b"generation cuts") - if generation_fails: - raise LegacyAdapterError("generation fixture failed") - if "amplicol_library_benchmark" in args: - assert common.read_text(encoding="utf-8") == original - assert not common_object.exists() - return original_run(args, cwd=cwd, environment=environment) - - monkeypatch.setattr(executor, "run", check_configuration) - - def measure(): - return adapter.measure( - _cell( - Accuracy.LC, - Workload.SELECTED_FLOW, - process_key="dd_4l_jets", - n_final=n_final, - ), - artifact_path=tmp_path / "four-leptons", - settings=_settings(repository), - ) - - if generation_fails: - with pytest.raises(LegacyAdapterError, match="generation fixture failed"): - measure() - else: - validate_measurement(measure()) - assert common.read_text(encoding="utf-8") == original - assert not common_object.exists() - - -def test_generation_lepton_cut_requires_known_configuration(tmp_path: Path) -> None: - common = tmp_path / "common.f03" - common.write_text("unexpected configuration\n", encoding="utf-8") - with ( - pytest.raises(LegacyAdapterError, match="could not configure"), - _generation_lepton_pt_cut(tmp_path), - ): - pytest.fail("unsupported configuration must not start generation") - assert common.read_text(encoding="utf-8") == "unexpected configuration\n" - - -@pytest.mark.parametrize( - ("process_key", "base_pdgs"), - ( - ("dd_epemzh_jets", (1, -1, -11, 11, 23, 25)), - ("ud_epve_jets", (2, -1, -11, 12)), - ), -) -@pytest.mark.parametrize( - ("accuracy", "workload", "n_final"), - ( - *( - (Accuracy.LC, Workload.SELECTED_FLOW, n_final) - for n_final in range(4, 8) - ), - (Accuracy.NLC, Workload.CONTRACTED, 4), - ), -) -def test_multibody_lepton_library_uses_t_channel_only_for_seeded_discovery( - process_key: str, - base_pdgs: tuple[int, ...], - accuracy: Accuracy, - workload: Workload, - n_final: int, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - pdgs = (*base_pdgs, *(21 for _ in range(n_final + 2 - len(base_pdgs)))) - adapter, api, executor = _adapter(FakeApi(pdgs)) - api.entry = FakeEntry( - process_pdgs=pdgs, - color_order=( - 2, - *range(len(base_pdgs) + 1, len(pdgs) + 1), - 1, - *range(3, len(base_pdgs) + 1), - ), - ) - point = tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: (api.pdgs, point, (point,)), - ) - - measurement = adapter.measure( - _cell( - accuracy, - workload, - process_key=process_key, - n_final=n_final, - ), - artifact_path=tmp_path / process_key, - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - generation_command = next( - command - for command in executor.commands - if command[0] == "./amplicol_generate" - ) - if workload is Workload.SELECTED_FLOW: - assert "--seed=101" in generation_command - assert "--phasespace=4" in generation_command - assert "--amplicol_momenta_probe=10" not in generation_command - else: - assert "--amplicol_momenta_probe=10" in generation_command - assert "--seed=101" not in generation_command - assert "--phasespace=4" not in generation_command - - -@pytest.mark.parametrize( - ("process_key", "pdgs"), - ( - ("dd_epem_jets", (1, -1, -11, 11)), - ("ud_epve_jets", (2, -1, -11, 12)), - ), -) -def test_massless_two_body_lepton_library_uses_supplied_physical_point( - process_key: str, - pdgs: tuple[int, ...], - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter(FakeApi(pdgs)) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - - measurement = adapter.measure( - _cell( - Accuracy.LC, - Workload.SELECTED_FLOW, - process_key=process_key, - n_final=2, - ), - artifact_path=tmp_path / process_key, - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - flattened = [" ".join(command) for command in executor.commands] - assert any("--amplicol_momenta_probe=10" in command for command in flattened) - assert not any("--seed=101" in command for command in flattened) - - -@pytest.mark.parametrize( - ("final_pdgs", "n_final", "expected_id"), - ( - ((-11, 11, 23, 25), 4, "h:-1,+1,-1,+1,-1,+0"), - ((-11, 11, 23, 25), 5, "h:-1,+1,-1,+1,-1,+0,-1"), - ((-11, 11, 23, 25), 6, "h:-1,+1,-1,+1,-1,+0,-1,+1"), - ((-11, 11, 23, 25), 7, "h:-1,+1,-1,+1,-1,+0,-1,+1,-1"), - ((6, -6, 23, 25), 4, "h:-1,+1,-1,+1,-1,+0"), - ((6, -6, 23, 25), 5, "h:-1,+1,-1,+1,-1,+0,-1"), - ((6, -6, 23, 25), 6, "h:-1,+1,-1,+1,-1,+0,-1,+1"), - ((6, -6, 23, 25), 7, "h:-1,+1,-1,+1,-1,+0,-1,+1,-1"), - ), -) -def test_higgs_selector_ids_match_runtime_signed_zero_axis( - final_pdgs: tuple[int, ...], - n_final: int, - expected_id: str, -) -> None: - pdgs = (1, -1, *final_pdgs, *(21 for _ in range(n_final - 4))) - helicities = _fixed_helicity(pdgs) - points = (((1.0, 0.0, 0.0, 1.0),),) - labels = tuple(range(1, len(pdgs) + 1)) - flow_id = "flow:2,1" - runtime = SimpleNamespace( - physics=SimpleNamespace( - color_flows=(SimpleNamespace(id=flow_id, word=(2, 1)),), - helicities=( - SimpleNamespace(id=expected_id, values=helicities), - ), - external_particles=tuple( - SimpleNamespace(label=label) for label in labels - ), - ) - ) - contract = SelectorContract( - selected_color_flow_ids=(flow_id,), - selected_color_words=((2, 1),), - all_flow_helicity_ids=(_helicity_id(helicities),), - all_flow_source_helicities=tuple( - zip(labels, helicities, strict=True) - ), - point_digest=point_digest(points), - ) - - assert helicities[5] == 0 - assert contract.all_flow_helicity_ids == (expected_id,) - validate_selector_contract(runtime, contract, points) - - -def test_higgs_selector_keeps_nonzero_signs_fail_closed() -> None: - points = (((1.0, 0.0, 0.0, 1.0),),) - helicities = (-1, 1, -1, 1, -1, 0) - identifier = _helicity_id(helicities) - runtime = SimpleNamespace( - physics=SimpleNamespace( - color_flows=(SimpleNamespace(id="flow:2,1", word=(2, 1)),), - helicities=( - SimpleNamespace( - id=identifier, - values=(1, 1, -1, 1, -1, 0), - ), - ), - external_particles=tuple( - SimpleNamespace(label=label) - for label in range(1, len(helicities) + 1) - ), - ) - ) - contract = SelectorContract( - selected_color_flow_ids=("flow:2,1",), - selected_color_words=((2, 1),), - all_flow_helicity_ids=(identifier,), - all_flow_source_helicities=tuple( - enumerate(helicities, start=1) - ), - point_digest=point_digest(points), - ) - - with pytest.raises(RunnerError, match="selected physical helicity"): - validate_selector_contract(runtime, contract, points) - - -def test_all_flow_uses_direct_fixed_helicity_and_its_own_generation_setup( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter() - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - measurement = adapter.measure( - _cell(Accuracy.LC, Workload.ALL_FLOW), - artifact_path=tmp_path / "all", - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - assert measurement["matrix_element"] == 12.5 - assert measurement["generation_seconds"] == 2.5 - assert measurement["wall_seconds_per_point"] == pytest.approx(1.0e-3) - common = measurement["validation"]["lc_common_component"] - assert common["value"] == 2.5 - assert LEGACY_NUMERICAL_AUTHORITY_FIELD not in measurement["validation"] - provenance = measurement["provenance"] - assert provenance["generation_timing_is_workload_specific"] is True - assert provenance["row_selection_policy"] == ( - "exact-external-pdg-order-then-process-file-order-v1" - ) - assert provenance["raw_mapped_color_order"] == [2, 4, 1, 3] - assert ( - provenance["selector_color_word_policy"] - == "outgoing-open-string-blocks-by-fundamental-source-label-v1" - ) - assert ( - provenance["generation_source"] == "direct-imode2-generation-setup" - ) - flattened = [" ".join(command) for command in executor.commands] - assert not any("--library=create" in command for command in flattened) - assert any(command.endswith("amplicol_color_probe") for command in flattened) - - -def test_all_flow_replays_selected_flow_provider_as_authoritative_component( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, _executor = _adapter() - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - provider = adapter.measure( - _cell(Accuracy.LC, Workload.SELECTED_FLOW), - artifact_path=tmp_path / "selected", - settings=_settings(tmp_path / "repository"), - ) - api.lc_probe_result = SimpleNamespace( - value=2.75, - lc_row_partitions=( - SimpleNamespace(row=1, value=2.75, permutation=(2, 4, 1)), - ), - lc_partition_sum=2.75, - ) - - measurement = adapter.measure( - _cell(Accuracy.LC, Workload.ALL_FLOW), - artifact_path=tmp_path / "all", - settings=_settings(tmp_path / "repository"), - selector_provider=provider, - ) - - validate_measurement(measurement) - assert measurement["status"] == "ok" - assert measurement["matrix_element"] == 12.5 - assert measurement["validation"]["lc_common_component"]["value"] == 2.5 - assert measurement["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] == { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": "all-flow-selected-provider-replay", - } - diagnostic = measurement["validation"][LEGACY_IMODE2_DIAGNOSTIC_FIELD] - assert diagnostic == { - "abi": LEGACY_IMODE2_DIAGNOSTIC_ABI, - "certifying": False, - "authoritative_source": "selected-flow-generated-library-component", - "authoritative_value": 2.5, - "imode2_value": 2.75, - "absolute_difference": 0.25, - "relative_difference": 0.1, - } - assert api.selected_calls == [ - (1, (-1, 1, -1, 1)), - (1, (-1, 1, -1, 1)), - ] - - -def test_high_flow_provider_omits_out_of_scope_imode2_component_diagnostic( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - pdgs = (1, -1, 2, -2, 3, -3, 21, 21, 21, 21, 21) - api = FakeApi(pdgs) - adapter, _api, _executor = _adapter(api) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in pdgs),), - ), - ) - provider = adapter.measure( - _cell( - Accuracy.LC, - Workload.SELECTED_FLOW, - process_key="dd_3q_lines", - n_final=9, - ), - artifact_path=tmp_path / "selected", - settings=_settings(tmp_path / "repository"), - ) - - measurement = adapter.measure( - _cell( - Accuracy.LC, - Workload.ALL_FLOW, - process_key="dd_3q_lines", - n_final=9, - ), - artifact_path=tmp_path / "all", - settings=_settings(tmp_path / "repository"), - selector_provider=provider, - ) - - validate_measurement(measurement) - assert measurement["status"] == "ok" - assert measurement["validation"]["lc_common_component"]["value"] == 2.5 - assert measurement["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] == { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": "all-flow-selected-provider-replay", - } - assert LEGACY_IMODE2_DIAGNOSTIC_FIELD not in measurement["validation"] - assert api.color_calls == [] - - -@pytest.mark.parametrize( - ("mutation", "match"), - ( - ("status", "not a successful measurement"), - ("selector", "contract does not match"), - ("component", "invalid common component"), - ), -) -def test_all_flow_rejects_invalid_selected_flow_provider_before_measurement( - mutation: str, - match: str, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter() - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - provider = adapter.measure( - _cell(Accuracy.LC, Workload.SELECTED_FLOW), - artifact_path=tmp_path / "selected", - settings=_settings(tmp_path / "repository"), - ) - provider = copy.deepcopy(provider) - if mutation == "status": - provider["status"] = "validation_failed" - elif mutation == "selector": - provider["selector_contract"]["point_digest"] = "b" * 64 - else: - provider["validation"]["lc_common_component"]["value"] = float("nan") - commands_before = len(executor.commands) - - with pytest.raises(LegacyAdapterError, match=match): - adapter.measure( - _cell(Accuracy.LC, Workload.ALL_FLOW), - artifact_path=tmp_path / "all", - settings=_settings(tmp_path / "repository"), - selector_provider=provider, - ) - - new_commands = executor.commands[commands_before:] - assert not any( - command and command[0].endswith("amplicol_color_probe") - for command in new_commands - ) - - -def test_all_flow_rejects_provider_replay_mismatch( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, _executor = _adapter() - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - provider = adapter.measure( - _cell(Accuracy.LC, Workload.SELECTED_FLOW), - artifact_path=tmp_path / "selected", - settings=_settings(tmp_path / "repository"), - ) - api.selected_flow_fixed_helicity_value = 2.5001 - - with pytest.raises(LegacyAdapterError, match="replay disagrees"): - adapter.measure( - _cell(Accuracy.LC, Workload.ALL_FLOW), - artifact_path=tmp_path / "all", - settings=_settings(tmp_path / "repository"), - selector_provider=provider, - ) - - -@pytest.mark.parametrize( - ("pdgs", "expected", "expected_id"), - ( - ( - (2, -1, -11, 12), - (-1, 1, 1, -1), - "h:-1,+1,+1,-1", - ), - ( - (2, -1, -11, 12, 21), - (-1, 1, 1, -1, -1), - "h:-1,+1,+1,-1,-1", - ), - ), -) -def test_fixed_helicity_uses_nonzero_chiral_charged_current( - pdgs: tuple[int, ...], - expected: tuple[int, ...], - expected_id: str, -) -> None: - helicities = _fixed_helicity(pdgs) - - assert helicities == expected - assert _helicity_id(helicities) == expected_id - - -def test_all_flow_rejects_structural_zero_selector( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - api = FakeApi() - api.lc_probe_result = SimpleNamespace( - value=0.0, - lc_row_partitions=( - SimpleNamespace(row=1, value=0.0, permutation=(2, 4, 1)), - ), - lc_partition_sum=0.0, - ) - adapter, _api, _executor = _adapter(api) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - - with pytest.raises(LegacyAdapterError, match="structural-zero helicity"): - adapter.measure( - _cell(Accuracy.LC, Workload.ALL_FLOW), - artifact_path=tmp_path / "all", - settings=_settings(tmp_path / "repository"), - ) - - -def _measure_with_lc_probe( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - probe: object, -) -> dict[str, object]: - api = FakeApi() - api.lc_probe_result = probe - adapter, _api, _executor = _adapter(api) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - return adapter.measure( - _cell(Accuracy.LC, Workload.ALL_FLOW), - artifact_path=tmp_path / "adversarial", - settings=_settings(tmp_path / "repository"), - ) - - -@pytest.mark.parametrize( - "permutation", - ( - (2, 4), - (2, 4, 4), - (0, 4, 1), - (2, 5, 1), - (2, "4", 1), - ), -) -def test_lc_common_probe_rejects_malformed_row_permutations( - permutation: tuple[object, ...], - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - probe = SimpleNamespace( - value=2.5, - lc_row_partitions=( - SimpleNamespace(row=1, value=2.5, permutation=permutation), - ), - lc_partition_sum=2.5, - ) - - with pytest.raises( - LegacyAdapterError, - match=r"row permutation|every colored source label", - ): - _measure_with_lc_probe(tmp_path, monkeypatch, probe) - - -@pytest.mark.parametrize( - "partitions", - ( - ( - SimpleNamespace(row=1, value=1.0, permutation=(2, 4, 1)), - SimpleNamespace(row=1, value=1.5, permutation=(2, 1, 4)), - ), - ( - SimpleNamespace(row=1, value=1.0, permutation=(2, 4, 1)), - SimpleNamespace(row=2, value=1.5, permutation=(2, 4, 1)), - ), - ), -) -def test_lc_common_probe_rejects_duplicate_rows( - partitions: tuple[object, ...], - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - probe = SimpleNamespace( - value=2.5, - lc_row_partitions=partitions, - lc_partition_sum=2.5, - ) - - with pytest.raises(LegacyAdapterError, match=r"duplicate"): - _measure_with_lc_probe(tmp_path, monkeypatch, probe) - - -@pytest.mark.parametrize( - ("partition_sum", "aggregate", "match"), - ( - (3.0, 3.0, "resolved partitions do not match"), - (2.5, 3.0, "partition sum does not match"), - (float("nan"), 2.5, "aggregate evidence is not finite"), - ), -) -def test_lc_common_probe_authenticates_partition_sum_and_aggregate( - partition_sum: float, - aggregate: float, - match: str, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - probe = SimpleNamespace( - value=aggregate, - lc_row_partitions=( - SimpleNamespace(row=1, value=2.5, permutation=(2, 4, 1)), - ), - lc_partition_sum=partition_sum, - ) - - with pytest.raises(LegacyAdapterError, match=match): - _measure_with_lc_probe(tmp_path, monkeypatch, probe) - - -@pytest.mark.parametrize("accuracy", [Accuracy.NLC, Accuracy.FULL]) -def test_contracted_publishes_dedicated_library_probe_with_imode2_diagnostic( - accuracy: Accuracy, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter() - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - measurement = adapter.measure( - _cell(accuracy, Workload.CONTRACTED), - artifact_path=tmp_path / accuracy.value, - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - assert measurement["status"] == "ok" - assert measurement["matrix_element"] == 9.75 - assert measurement["selector_contract"] is None - assert api.color_calls == [(accuracy.value, None)] - flattened = [" ".join(command) for command in executor.commands] - assert any("--library=create-raw" in command for command in flattened) - assert any("--amplicol_momenta_probe=10" in command for command in flattened) - assert not any("--seed=101" in command for command in flattened) - probe_build = ( - "make", - "-j1", - "amplicol_color_library_probe", - "amplicol_color_probe", - ) - assert probe_build in executor.commands - assert executor.commands.index(probe_build) < next( - index - for index, command in enumerate(executor.commands) - if command[0] == "./amplicol_color_library_probe" - ) - assert api.parsed_probe_count == 0 - diagnostic = measurement["validation"][LEGACY_IMODE2_DIAGNOSTIC_FIELD] - assert diagnostic == { - "abi": LEGACY_IMODE2_DIAGNOSTIC_ABI, - "certifying": False, - "authoritative_source": "dedicated-generated-library-probe", - "authoritative_value": 9.75, - "imode2_value": 9.75, - "absolute_difference": 0.0, - "relative_difference": 0.0, - } - assert measurement["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] == { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": "contracted-generated-library", - } - - -@pytest.mark.parametrize("accuracy", [Accuracy.NLC, Accuracy.FULL]) -def test_contracted_keeps_known_imode2_mismatch_non_certifying( - accuracy: Accuracy, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, _executor = _adapter() - api.direct_color_probe_value = 10.0 - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - - measurement = adapter.measure( - _cell(accuracy, Workload.CONTRACTED), - artifact_path=tmp_path / accuracy.value, - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - assert measurement["status"] == "ok" - assert measurement["matrix_element"] == 9.75 - assert measurement["failure"] is None - diagnostic = measurement["validation"][LEGACY_IMODE2_DIAGNOSTIC_FIELD] - assert diagnostic["certifying"] is False - assert diagnostic["authoritative_value"] == 9.75 - assert diagnostic["imode2_value"] == 10.0 - assert diagnostic["absolute_difference"] == 0.25 - assert diagnostic["relative_difference"] == pytest.approx(0.25 / 9.75) - - -@pytest.mark.parametrize("accuracy", (Accuracy.NLC, Accuracy.FULL)) -def test_three_quark_line_contracted_uses_exact_direct_probe( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - accuracy: Accuracy, -) -> None: - api = FakeApi((1, -1, 2, -2, 3, -3, 21, 21)) - api.entry = FakeEntry( - process_pdgs=api.pdgs, - color_order=(2, 7, 8, 1, 3, 4, 5, 6), - ) - adapter, _api, executor = _adapter(api) - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - - measurement = adapter.measure( - _cell( - accuracy, - Workload.CONTRACTED, - process_key="dd_3q_lines", - n_final=6, - ), - artifact_path=tmp_path / accuracy.value, - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - assert measurement["matrix_element"] == 12.5 - assert measurement["generation_seconds"] == 2.5 - assert api.color_calls == [] - assert ( - measurement["provenance"]["generation_source"] - == "direct-imode2-three-quark-line-setup" - ) - assert measurement["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] == { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": "direct-imode2-three-quark-line", - } - flattened = [" ".join(command) for command in executor.commands] - assert any("amplicol_color_probe" in command for command in flattened) - assert not any("amplicol_generate" in command for command in flattened) - assert not any("amplicol_color_library_probe" in command for command in flattened) - - -def test_more_than_three_open_quark_lines_is_preserved_as_unsupported( - tmp_path: Path, -) -> None: - api = FakeApi((1, -1, 2, -2, 3, -3, 4, -4)) - adapter, _api, executor = _adapter(api) - cell = next( - item - for item in REPORT_CATALOG.reference_cells() - if item.process_key == "dd_4q_lines" - and item.measurement.accuracy is Accuracy.LC - and item.workload is Workload.SELECTED_FLOW - ) - measurement = adapter.measure( - cell, - artifact_path=tmp_path / "unsupported", - settings=_settings(tmp_path / "repository"), - ) - - validate_measurement(measurement) - assert measurement["status"] == "unsupported" - assert "at most 3 open quark lines" in measurement["failure"]["message"] - assert executor.commands == [] - - -def test_profile_never_reuses_warmup_as_the_only_timed_sample( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, api, executor = _adapter() - monkeypatch.setattr( - "tools.performance_report.legacy._shared_point", - lambda _process: ( - api.pdgs, - tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs), - (tuple((1.0, 0.0, 0.0, 0.0) for _ in api.pdgs),), - ), - ) - settings = LegacySettings( - target_runtime_seconds=0.05, - warmup_points=100, - minimum_points=10, - maximum_points=1_000, - repository=tmp_path / "repository", - ) - measurement = adapter.measure( - _cell(Accuracy.LC, Workload.SELECTED_FLOW), - artifact_path=tmp_path / "reuse", - settings=settings, - ) - - benchmark_commands = [ - command - for command in executor.commands - if command and command[0] == "./amplicol_library_benchmark" - ] - assert len(benchmark_commands) == 6 - assert measurement["sample_count"] >= 50 - assert ( - measurement["provenance"]["runtime_profile"]["measurement"][ - "profile_phase" - ] - == "measurement_chunks" - ) - assert ( - measurement["provenance"]["runtime_profile"]["measurement"][ - "chunk_count" - ] - == 5 - ) - - -def test_fast_warmup_still_produces_five_samples_and_measured_rse( - tmp_path: Path, -) -> None: - adapter, _api, _executor = _adapter() - calls: list[int] = [] - rates = iter((0.09, 0.11, 0.10, 0.105, 0.095)) - - def invoke(points: int): - calls.append(points) - seconds = 5.0 if len(calls) == 1 else points * next(rates) - result = CommandResult( - args=("probe", str(points)), - cwd=tmp_path, - elapsed_seconds=seconds, - returncode=0, - stdout="", - stderr="", - environment={}, - ) - return ( - result, - (TimingRow("amplitude evaluation", seconds),), - None, - ) - - profile = adapter._profile( - invoke, - settings=LegacySettings( - target_runtime_seconds=5.0, - warmup_points=10, - minimum_points=10, - maximum_points=10, - repository=tmp_path, - ), - timing_labels=("amplitude evaluation",), - ) - - assert len(calls) == 6 - assert profile.record["chunk_count"] == 5 - assert profile.seconds == pytest.approx(5.0) - assert profile.standard_error_seconds_per_point > 0.0 - assert profile.relative_standard_error > 0.0 - - -def test_legacy_profile_does_not_launch_chunk_larger_than_remaining_budget( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - adapter, _api, _executor = _adapter() - calls: list[int] = [] - clock = iter((0.0, 0.0, 0.0)) - monkeypatch.setattr( - "tools.performance_report.legacy.time.monotonic", - lambda: next(clock), - ) - - def invoke(points: int): - calls.append(points) - result = CommandResult( - args=("probe", str(points)), - cwd=tmp_path, - elapsed_seconds=0.2, - returncode=0, - stdout="", - stderr="", - environment={}, - ) - return result, (TimingRow("total", 0.2),), None - - with pytest.raises(ProfilingTimeLimitError, match="legacy 10-point chunk"): - adapter._profile( - invoke, - settings=LegacySettings( - target_runtime_seconds=1.0, - minimum_points=10, - maximum_points=100, - profiling_time_limit_seconds=1.0, - repository=tmp_path, - ), - timing_labels=("total",), - ) - - assert calls == [1] diff --git a/pyamplicol/tests/unit/test_three_mode_report_render.py b/pyamplicol/tests/unit/test_three_mode_report_render.py deleted file mode 100644 index 17c43c2014..0000000000 --- a/pyamplicol/tests/unit/test_three_mode_report_render.py +++ /dev/null @@ -1,4664 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import copy -import re -from pathlib import Path - -import pytest - -import tools.performance_report.render as report_render -from tools.performance_report.agreements import ( - DIRECT_AGREEMENT_ABI, - DIRECT_AGREEMENT_V2_ABI, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, - LC_LEGACY_PYAMPLICOL_COMPONENT, - STRICT_ABSOLUTE_TOLERANCE, - incoming_agreement_edges, -) -from tools.performance_report.arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - EMPTY_ARENA_PHASE_VECTOR_FIELDS, - ZERO_ARENA_COUNTER_FIELDS, - ZERO_ARENA_PHASE_TIME_FIELDS, - ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS, - build_arena_profile_evidence, - digest_arena_profile_value, -) -from tools.performance_report.cache import build_reset_caches, empty_measurement -from tools.performance_report.campaign_policy import ( - X86_EPYC_GENERATION_LIMIT_SECONDS, - X86_EPYC_MEMORY_LIMIT_BYTES, - X86_EPYC_POLICY, - PolicyCensorKind, - dependency_reference, - policy_censor_measurement, -) -from tools.performance_report.catalog import ( - MADGRAPH_FULL_COMPARISON_VIEWS, - REPORT_CATALOG, -) -from tools.performance_report.models import ( - Accuracy, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from tools.performance_report.render import ( - BaselineCandidateAdapter, - _ratio_value, - render_all_best_mode_tables, - render_all_matrix_tables, - render_all_tables, - render_all_z_ladders, - render_best_mode_table, - render_matrix_comparison_table, - render_matrix_table, - render_scalar_ladder, - render_z_ladder, - summarize_visible_completeness, -) -from tools.performance_report.runner import ( - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD, - pointwise_validation, -) -from tools.performance_report.source_identity import ReportSourceIdentity -from tools.performance_report.validation_summary import ( - render_validation_summary, - summarize_validation, -) - - -def test_unavailable_execution_timing_is_never_ratioed() -> None: - baseline = { - "status": ResultStatus.OK.value, - "execution_seconds_per_point": 1.0e-6, - } - candidate = { - "status": ResultStatus.OK.value, - "execution_seconds_per_point": 1.0e-9, - "provenance": { - "execution_timing": { - "status": "unavailable", - "ratio_eligible": False, - } - }, - } - - assert _ratio_value(candidate, baseline, "execution_seconds_per_point") is None - - -@pytest.fixture -def reset_caches( - monkeypatch: pytest.MonkeyPatch, -) -> dict[str, dict[str, object]]: - monkeypatch.setattr( - report_render, - "validate_on_the_fly_recurrence_authority_validation_record", - lambda *_args, **_kwargs: None, - ) - return build_reset_caches() - - -def test_packaged_blank_tables_match_canonical_reset_renderer( - reset_caches: dict[str, dict[str, object]], -) -> None: - packaged_root = ( - Path(__file__).resolve().parents[2] / "src/pyamplicol/_profiling_campaign" - ) - rendered = render_all_tables(reset_caches, catalog=REPORT_CATALOG) - packaged = { - path.name: path.read_text(encoding="utf-8") - for path in packaged_root.glob("result_*.tex") - } - - assert packaged == rendered - - -def _cache_by_dataset( - caches: dict[str, dict[str, object]], - dataset_id: str, -) -> dict[str, object]: - return next( - payload for payload in caches.values() if payload["dataset_id"] == dataset_id - ) - - -def _set_ok( - cache: dict[str, object], - *, - process_key: str, - n_final: int, - workload: Workload, - generation: float, - wall: float, - execution: float | None, - variant: str | None = None, -) -> None: - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["process_key"] == process_key - and item["n_final"] == n_final - and item["workload"] == workload.value - and item["variant"] == variant - ) - cell = REPORT_CATALOG.cell(str(entry["cell_id"])) - entry["measurement"] = _ok_measurement( - cell, - generation=generation, - wall=wall, - execution=execution, - ) - - -_TEST_SELECTOR_CONTRACT = { - "all_flow_helicity_ids": ["h:test"], - "all_flow_source_helicities": {"1": 1}, - "point_digest": "0" * 64, - "selected_color_flow_ids": ["flow:test"], - "selected_color_words": [[1]], -} - - -def _ok_measurement( - cell, - *, - generation: float, - wall: float, - execution: float | None, -) -> dict[str, object]: - selector = ( - copy.deepcopy(_TEST_SELECTOR_CONTRACT) - if cell.measurement.accuracy is Accuracy.LC - else None - ) - direct_agreements = [ - { - "abi": DIRECT_AGREEMENT_ABI, - "edge_kind": edge.kind, - "value_kind": edge.value_kind, - "baseline_cell_id": edge.baseline.cell_id, - "candidate_cell_id": cell.cell_id, - "status": ResultStatus.OK.value, - "candidate": 1.0, - "baseline": 1.0, - "absolute_difference": 0.0, - "relative_difference": 0.0, - "relative_tolerance": edge.relative_tolerance, - "absolute_tolerance": STRICT_ABSOLUTE_TOLERANCE, - } - for edge in incoming_agreement_edges(cell) - ] - validation: dict[str, object] = { - "status": ResultStatus.OK.value, - "pointwise": { - "status": ResultStatus.OK.value, - "candidate": 1.0, - "baseline": 1.0, - "absolute_difference": 0.0, - "relative_difference": 0.0, - "relative_tolerance": 1.0e-8, - "absolute_tolerance": 1.0e-15, - }, - "high_precision": { - "status": ResultStatus.OK.value, - "candidate": 1.0, - "baseline": 1.0, - "absolute_difference": 0.0, - "relative_difference": 0.0, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-15, - }, - "direct_agreements": direct_agreements, - } - if selector is not None: - validation[LC_COMMON_COMPONENT_FIELD] = { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell.cell_id, - "value": 1.0, - "point_digest": selector["point_digest"], - "helicity_ids": selector["all_flow_helicity_ids"], - "color_flow_ids": selector["selected_color_flow_ids"], - } - execution_mode = cell.measurement.execution_mode - artifact_id = ( - "a" * 64 - if execution_mode is ExecutionMode.ON_THE_FLY - else "b" * 64 - if execution_mode is ExecutionMode.RECURRENCE - else "c" * 64 - ) - if ( - execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - ): - validation[OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD] = { - "authority": {"artifact_id": "b" * 64}, - } - return { - "status": ResultStatus.OK.value, - "generation_seconds": generation, - "wall_seconds_per_point": wall, - "execution_seconds_per_point": execution, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 0.01, - "artifact": {"digest": "artifact"}, - "selector_contract": selector, - "validation": validation, - "resources": {"peak_rss_gib": 1.0}, - "provenance": { - "source": "test", - "runtime_identity": {"artifact_id": artifact_id}, - **( - {"runtime_profile": {"cold_warmup_elapsed_seconds": 0.25}} - if execution_mode is ExecutionMode.ON_THE_FLY - else {} - ), - }, - "failure": None, - } - - -def _set_status( - cache: dict[str, object], - *, - process_key: str, - n_final: int, - workload: Workload, - status: ResultStatus, -) -> None: - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["process_key"] == process_key - and item["n_final"] == n_final - and item["workload"] == workload.value - and item["variant"] is None - ) - measurement = empty_measurement() - measurement["status"] = status.value - entry["measurement"] = measurement - - -def _set_unverified( - cache: dict[str, object], - *, - process_key: str, - n_final: int, - workload: Workload, - generation: float, - wall: float, - evaluator_total: float, - variant: str | None = None, -) -> None: - entry = _entry( - cache, - process_key=process_key, - n_final=n_final, - workload=workload, - variant=variant, - ) - cell = REPORT_CATALOG.cell(str(entry["cell_id"])) - measurement = _ok_measurement( - cell, - generation=generation, - wall=wall, - execution=None, - ) - _mark_evaluator_total( - measurement, - execution_mode=cell.measurement.execution_mode.value, - total=evaluator_total, - ) - measurement["status"] = ResultStatus.UNVERIFIED.value - measurement["failure"] = { - "kind": "IndependentAuthorityUnavailable", - "message": "no successful independent authority", - } - validation = measurement["validation"] - assert isinstance(validation, dict) - validation["status"] = ResultStatus.UNVERIFIED.value - entry["measurement"] = measurement - - -def _set_presentation_outcome( - cache: dict[str, object], - *, - process_key: str, - n_final: int, - workload: Workload, - outcome: str, - label: str | None = None, - variant: str | None = None, -) -> None: - labels = { - "error": (ResultStatus.ERROR, "error"), - "validation_failed": ( - ResultStatus.VALIDATION_FAILED, - "validation failed", - ), - "blocked_dependency": ( - ResultStatus.FAILED, - "blocked dependency", - ), - } - status, default_label = labels.get( - outcome, - (ResultStatus.FAILED, outcome.replace("_", " ")), - ) - entry = _entry( - cache, - process_key=process_key, - n_final=n_final, - workload=workload, - variant=variant, - ) - measurement = empty_measurement() - measurement["status"] = status.value - measurement["failure"] = { - "kind": f"ManualCampaignOutcome:{outcome}", - "message": default_label if label is None else label, - } - entry["measurement"] = measurement - - -def _set_best_mode_nlc_reference(caches: dict[str, dict[str, object]]) -> None: - _set_ok( - _cache_by_dataset(caches, "reference_amplicol_nlc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - - -def _mark_arena_unavailable( - measurement: dict[str, object], - *, - execution_mode: str = "compiled", -) -> None: - measurement["execution_seconds_per_point"] = None - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - raw_profile = { - "execution_mode": execution_mode, - "profile_boundary": ARENA_PROFILE_BOUNDARY, - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "evaluator_timing_available": False, - "points": 128, - "wall_time_s": 128 * 1.1e-6, - "orchestration_time_s": 128 * 1.1e-6, - **{field: 0 for field in ZERO_ARENA_COUNTER_FIELDS}, - **{field: 0.0 for field in ZERO_ARENA_PHASE_TIME_FIELDS}, - **{field: [] for field in EMPTY_ARENA_PHASE_VECTOR_FIELDS}, - **{field: 0 for field in ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS}, - } - if execution_mode == "compiled": - raw_profile.update( - { - "compiled_direct_arena_engine_count": 1, - "compiled_direct_arena_call_count": 128, - "evaluator_backend_call_count": 128, - } - ) - arena_evidence = build_arena_profile_evidence( - [raw_profile] * 5, - execution_mode=execution_mode, - repetitions_per_profile=1, - batch_size=128, - ) - provenance["arena_profile_evidence"] = arena_evidence - provenance["execution_timing"] = { - "abi": "pyamplicol-report-arena-execution-timing-v2", - "status": "unavailable", - "ratio_eligible": False, - "raw_seconds_per_point": None, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "repetitions_per_sample": 1, - "batch_size": 128, - "sample_contract": ("paired_unprofiled_headline_profiled_attribution_v1"), - "profile_protocol": "arena", - "profile_sample_pass": "runtime._profile_arena_repeated", - "profile_boundary": ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" - ), - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": "coarse-arena-boundary-only-v1", - "evaluator_timing_available": False, - "paired_with_headline": True, - "identical_batch": True, - "identical_repetitions": True, - "execution_mode": execution_mode, - "warmed_boundary_wall_seconds_per_point": 1.1e-6, - "arena_profile_evidence_sha256": digest_arena_profile_value(arena_evidence), - } - - -def _mark_evaluator_total( - measurement: dict[str, object], - *, - execution_mode: str = "compiled", - total: float | None = None, -) -> None: - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - wall = measurement["wall_seconds_per_point"] - assert isinstance(wall, float) - raw_total = wall if total is None else total - provenance["evaluator_total_timing"] = { - "abi": "pyamplicol-report-evaluator-total-timing-v1", - "status": "measured", - "ratio_eligible": False, - "raw_seconds_per_point": raw_total, - "source": "runtime._benchmark_f64_wall_time.accumulated", - "execution_mode": execution_mode, - "sample_contract": ("accumulated-repeated-warmed-evaluator-total-v1"), - "sample_count": 5, - "repetitions_per_sample": 1, - "batch_size": 128, - "points_per_sample": 128, - "measured_point_count": 640, - "accumulated_seconds": raw_total * 640, - } - - -def _mark_recurrence_core(measurement: dict[str, object]) -> None: - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - raw_core = measurement["execution_seconds_per_point"] - assert isinstance(raw_core, float) - provenance["execution_timing"] = { - "abi": "pyamplicol-report-execution-timing-v1", - "status": "measured", - "ratio_eligible": True, - "raw_seconds_per_point": raw_core, - "source": "runtime_profile_core_recurrence_schedule_time", - "compiled_direct_arena_active": False, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "sample_contract": ("paired_unprofiled_headline_profiled_attribution_v1"), - } - - -def _fill_visible_scope( - caches: dict[str, dict[str, object]], - *, - max_n_final: int = 4, -) -> None: - for payload in caches.values(): - entries = payload["entries"] - assert isinstance(entries, list) - for entry in entries: - if entry["n_final"] > max_n_final: - continue - cell = REPORT_CATALOG.cell(str(entry["cell_id"])) - if REPORT_CATALOG.static_na_reason(cell) is not None: - continue - entry["measurement"] = _ok_measurement( - cell, - generation=1.0, - wall=2.0e-6, - execution=1.0e-6, - ) - - -def _fill_visible_n4_scope(caches: dict[str, dict[str, object]]) -> None: - _fill_visible_scope(caches, max_n_final=4) - - -_POLICY_IDENTITY = ReportSourceIdentity("1" * 40, "2" * 40, ()) - - -def _entry( - cache: dict[str, object], - *, - process_key: str, - n_final: int, - workload: Workload, - variant: str | None = None, -) -> dict[str, object]: - entries = cache["entries"] - assert isinstance(entries, list) - return next( - item - for item in entries - if item["process_key"] == process_key - and item["n_final"] == n_final - and item["workload"] == workload.value - and item["variant"] == variant - ) - - -def _policy_resources(peak: int) -> dict[str, object]: - return { - "available": True, - "current_rss_bytes": peak, - "peak_rss_bytes": peak, - "child_count": 1, - "cpu_seconds": 1.0, - "wall_seconds": 2.0, - "probe_error": None, - } - - -def _generation_censor(cell) -> dict[str, object]: - phase = { - "abi": "pyamplicol-report-generation-phase-evidence-v1", - "phase_state_abi": "pyamplicol-report-worker-phase-state-v1", - "configured_timeout_seconds": X86_EPYC_GENERATION_LIMIT_SECONDS, - "supervisor_reason": "generation_timeout", - "authenticated": True, - "run_id": "render-policy-test", - "worker_pid": 123, - "final_sequence": 1, - "final_phase": "generation", - "generation_started_monotonic_ns": 1, - "generation_finished_monotonic_ns": None, - "generation_elapsed_seconds": X86_EPYC_GENERATION_LIMIT_SECONDS, - "final_state_sha256": "3" * 64, - "error": None, - } - resources = _policy_resources(1_000_000) - resources["generation_phase"] = phase - return policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - kind=PolicyCensorKind.GENERATION_LIMIT, - source_identity=_POLICY_IDENTITY, - resources=resources, - observed_generation_seconds=X86_EPYC_GENERATION_LIMIT_SECONDS, - phase_evidence=phase, - ) - - -def _memory_censor(cell) -> dict[str, object]: - peak = X86_EPYC_MEMORY_LIMIT_BYTES + 1 - return policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=_POLICY_IDENTITY, - resources=_policy_resources(peak), - observed_rss_bytes=peak, - ) - - -def test_nineteen_matrices_render_in_catalog_and_comparison_order( - reset_caches, -) -> None: - rendered = render_all_matrix_tables(reset_caches) - expected = [ - dataset.table_name - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.baseline.execution_mode is not ExecutionMode.MADGRAPH - ] + [view.table_name for view in MADGRAPH_FULL_COMPARISON_VIEWS] - - assert len(rendered) == 19 - assert list(rendered) == expected - assert not { - dataset.table_name - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.baseline.execution_mode is ExecutionMode.MADGRAPH - } & set(rendered) - lc_tex = next( - rendered[dataset.table_name] - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.candidate.accuracy is Accuracy.LC - ) - contracted_tex = next( - rendered[dataset.table_name] - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.candidate.accuracy is Accuracy.NLC - ) - assert r"\textbf{ID} & \textbf{base process} & \textbf{metric}" in lc_tex - assert r"\multicolumn{8}{c}{\textbf{n=1}}" in lc_tex - assert r"\multicolumn{8}{c}{\textbf{n=2}}" in lc_tex - assert r"\multicolumn{3}{c}{\textbf{n=1}}" in contracted_tex - assert r"\multicolumn{3}{c}{\textbf{n=2}}" in contracted_tex - assert r"\matrixfitwidth{%" in lc_tex - assert r"\rowcolor{refblue}" in lc_tex - assert lc_tex.count(r"\multicolumn{8}{c}") >= 4 - tabular_spec = next( - line for line in lc_tex.splitlines() if line.startswith(r"\begin{tabular}") - ) - assert r"@{\hspace" not in tabular_spec - assert ":" not in tabular_spec - assert r"\dashlinedash" not in lc_tex - assert r"\dashlinegap" not in lc_tex - assert r"\texttt{abs }" not in lc_tex - assert r"\textcolor{ReportMuted}{\scriptsize gen. [s]}" in lc_tex - assert ( - r"\textcolor{ReportMuted}{\scriptsize run " - r"[\(\mu\mathrm{s}/\mathrm{pt}\)]}" - ) in lc_tex - assert r"\matrixcolumnheading" not in lc_tex - - obsolete_clock_macros = ( - r"\matrixwallclock{", - r"\matrixwallabsolute{", - r"\matrixtotalevaluator{", - r"\matrixrecurrencecore{", - r"\matrixruntimepair{", - r"\matrixruntimetriple{", - ) - best_mode_rendered = render_all_best_mode_tables(reset_caches) - for tex in (*rendered.values(), *best_mode_rendered.values()): - table_body = "\n".join( - line for line in tex.splitlines() if not line.startswith(r"\providecommand") - ) - assert all(macro not in table_body for macro in obsolete_clock_macros) - - -def test_madgraph_views_join_shared_reference_without_copying_measurements( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - view = next( - item - for item in MADGRAPH_FULL_COMPARISON_VIEWS - if item.candidate_dataset_id == "matrix_recurrence_ufo_sm_full" - ) - baseline_cache = _cache_by_dataset(caches, view.baseline_dataset_id) - candidate_cache = _cache_by_dataset(caches, view.candidate_dataset_id) - _set_ok( - baseline_cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=8.0, - wall=4.0e-6, - execution=3.0e-6, - ) - _set_ok( - candidate_cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - baseline_measurement = next( - entry["measurement"] - for entry in baseline_cache["entries"] - if entry["process_key"] == "dd_z_jets" and entry["n_final"] == 1 - ) - candidate_measurement = next( - entry["measurement"] - for entry in candidate_cache["entries"] - if entry["process_key"] == "dd_z_jets" and entry["n_final"] == 1 - ) - - dataset = REPORT_CATALOG.dataset(view.candidate_dataset_id) - joined = BaselineCandidateAdapter(caches).matrix_cell( - dataset, - REPORT_CATALOG.process_families[0], - 1, - baseline_dataset_id=view.baseline_dataset_id, - ) - tex = render_matrix_comparison_table(view, caches) - - assert joined.workloads[0].baseline is baseline_measurement - assert joined.workloads[0].candidate is candidate_measurement - assert r"\subsection{UFO-SM recurrence JIT O2 versus MadGraph full-colour}" in tex - assert r"\texttt{8.00}" in tex - assert r"\bestmoderatio{ReportGreen}{0.500}" in tex - assert "MadGraph standalone is the authoritative full-colour" in tex - - -def test_only_amplicol_generation_turns_red_for_legacy_mismatch( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_nlc") - candidate = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=100.0e-6, - execution=90.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=50.0e-6, - execution=40.0e-6, - ) - measurement = next( - entry["measurement"] - for entry in candidate["entries"] - if entry["process_key"] == "dd_z_jets" and entry["n_final"] == 1 - ) - validation = measurement["validation"] - assert isinstance(validation, dict) - - dataset = REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_nlc") - before = render_matrix_table(dataset, caches) - assert r"\textcolor{ReportRed}{\texttt{4.00}}" not in before - - validation["pointwise"]["status"] = ResultStatus.VALIDATION_FAILED.value - validation["legacy_amplicol_comparison"] = { - "status": "mismatch", - "pointwise": {"status": ResultStatus.VALIDATION_FAILED.value}, - } - tex = render_matrix_table(dataset, caches) - - assert r"\textcolor{ReportRed}{\texttt{4.00}}" in tex - assert r"\textcolor{ReportRed}{\texttt{100}}" not in tex - assert r"\matrixstatus{ReportRed}{validation failed}" not in tex - assert tex.replace( - r"\textcolor{ReportRed}{\texttt{4.00}}", - r"\texttt{4.00}", - ) == before - - -def test_best_mode_inherits_legacy_mismatch_from_recurrence_bridge( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_nlc") - recurrence = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - compiled = _cache_by_dataset( - caches, - "matrix_compiled_builtin_sm_nlc", - ) - for cache, generation, wall in ( - (baseline, 4.0, 100.0e-6), - (recurrence, 3.0, 60.0e-6), - (compiled, 2.0, 50.0e-6), - ): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=generation, - wall=wall, - execution=0.8 * wall, - ) - - before = render_best_mode_table(Accuracy.NLC, caches) - recurrence_measurement = next( - entry["measurement"] - for entry in recurrence["entries"] - if entry["process_key"] == "dd_z_jets" and entry["n_final"] == 1 - ) - validation = recurrence_measurement["validation"] - validation["pointwise"]["status"] = ResultStatus.VALIDATION_FAILED.value - validation["legacy_amplicol_comparison"] = {"status": "mismatch"} - - tex = render_best_mode_table(Accuracy.NLC, caches) - - assert r"\textcolor{ReportRed}{\texttt{4.00}}" in tex - assert r"\textcolor{ReportRed}{\texttt{100}}" not in tex - assert tex.replace( - r"\textcolor{ReportRed}{\texttt{4.00}}", - r"\texttt{4.00}", - ) == before - - -def test_identical_quark_line_family_renders_in_every_matrix_block( - reset_caches, -) -> None: - rendered = render_all_matrix_tables(reset_caches) - best = render_all_best_mode_tables(reset_caches) - row = ( - r"\texttt{15} & " - r"$d\bar d\to u\bar u\,u\bar u+(n-4)g$" - ) - - for name, expected_blocks in ( - ("result_matrix_recurrence_builtin_sm_lc_table.tex", 3), - ("result_matrix_recurrence_builtin_sm_nlc_table.tex", 2), - ("result_matrix_recurrence_builtin_sm_full_table.tex", 2), - ): - assert rendered[name].count(row) == expected_blocks - assert best["result_matrix_best_builtin_sm_lc_table.tex"].count(row) == 3 - assert best["result_matrix_best_builtin_sm_nlc_table.tex"].count(row) == 2 - assert best["result_matrix_best_builtin_sm_full_table.tex"].count(row) == 2 - - -def test_matrix_summary_backgrounds_restart_for_each_multiplicity_block( - reset_caches, -) -> None: - rendered = render_all_matrix_tables(reset_caches) - - def summary_patterns(tex: str, span: int) -> list[list[bool]]: - rows = [line for line in tex.splitlines() if r"\textbf{summary:" in line] - return [ - [ - cell.startswith(rf"\multicolumn{{{span}}}{{c}}{{\cellcolor{{refblue}}") - for cell in row.split(" & ")[1:] - ] - for row in rows - ] - - lc_tex = next( - rendered[dataset.table_name] - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.candidate.accuracy is Accuracy.LC - ) - contracted_tex = next( - rendered[dataset.table_name] - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.candidate.accuracy is Accuracy.NLC - ) - - def assert_alternating(tex: str, span: int) -> None: - rows = [line for line in tex.splitlines() if r"\textbf{summary:" in line] - patterns = summary_patterns(tex, span) - for pattern in patterns: - assert pattern == [index % 2 == 0 for index in range(len(pattern))] - assert all( - not row.startswith(r"\multicolumn{3}{@{}l}{\cellcolor{refblue}") - for row in tex.splitlines() - if r"\textbf{summary:" in row - ) - assert all(row.endswith(r" \\[0.08em]") for row in rows[::2]) - assert all(row.endswith(" \\\\") for row in rows[1::2]) - assert r"\addlinespace[0.08em]" not in tex - - summary_headers = [ - line - for line in tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{} & ") and r"\textbf{n=" in line - ] - assert len(summary_headers) == len(rows) // 2 - for header in summary_headers: - groups = header.count(r"\textbf{n=") - assert groups in (2, 3) - assert [ - cell.startswith(rf"\multicolumn{{{span}}}{{c}}{{\cellcolor{{refblue}}") - for cell in header.split(" & ")[1:] - ] == [index % 2 == 0 for index in range(groups)] - - assert_alternating(lc_tex, 8) - assert_alternating(contracted_tex, 3) - - for accuracy, span in ((Accuracy.LC, 8), (Accuracy.NLC, 3)): - best_tex = render_best_mode_table(accuracy, reset_caches) - assert_alternating(best_tex, span) - - fixed_block_two_header = next( - line - for line in lc_tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{} & ") and r"\textbf{n=4}" in line - ) - best_block_two_header = next( - line - for line in render_best_mode_table(Accuracy.LC, reset_caches).splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{} & ") and r"\textbf{n=4}" in line - ) - expected_block_two_header = ( - r"\multicolumn{3}{@{}l}{} & " - r"\multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=4}} & " - r"\multicolumn{8}{c}{\textbf{n=5}} & " - r"\multicolumn{8}{c}{\cellcolor{refblue}\textbf{n=6}} \\" - ) - assert fixed_block_two_header == expected_block_two_header - assert best_block_two_header == expected_block_two_header - - lc_runtime_summary_label = ( - r"\matrixsummaryworkloads" - r"{\textbf{summary: run single-flow, hel. sum}}" - r"{\textbf{summary: run all-flows, single hel.}}" - ) - best_lc_tex = render_best_mode_table(Accuracy.LC, reset_caches) - assert lc_runtime_summary_label in lc_tex - assert lc_runtime_summary_label in best_lc_tex - assert r"\textbf{summary: wall}" not in lc_tex - assert r"\textbf{summary: wall}" not in best_lc_tex - assert r"\textbf{summary: wall}" in contracted_tex - - for tex in (lc_tex, contracted_tex, best_lc_tex): - table_body = "\n".join( - line for line in tex.splitlines() if not line.startswith(r"\providecommand") - ) - assert r"\matrixtotalevaluator{" not in table_body - assert r"\matrixrecurrencecore{" not in table_body - - -def test_best_mode_summary_selects_wall_winner_per_lc_workload(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_lc") - candidates = { - mode: _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_lc", - ) - for mode in ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ) - } - for workload in (Workload.SELECTED_FLOW, Workload.ALL_FLOW): - _set_ok( - reference, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - timings = { - ExecutionMode.RECURRENCE: (3.0e-6, 4.0e-6), - ExecutionMode.COMPILED: (1.0e-6, 2.0e-6), - ExecutionMode.EAGER: (2.0e-6, 1.0e-6), - } - generations = { - ExecutionMode.RECURRENCE: 6.0, - ExecutionMode.COMPILED: 4.0, - ExecutionMode.EAGER: 5.0, - } - for mode, (selected_wall, all_flow_wall) in timings.items(): - for workload, wall in ( - (Workload.SELECTED_FLOW, selected_wall), - (Workload.ALL_FLOW, all_flow_wall), - ): - _set_ok( - candidates[mode], - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=generations[mode], - wall=wall, - execution=wall, - ) - - adapter = BaselineCandidateAdapter(caches) - view = adapter.best_mode_cell( - Accuracy.LC, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[0].mode is ExecutionMode.COMPILED - assert view.workloads[1].mode is ExecutionMode.EAGER - - tex = render_best_mode_table(Accuracy.LC, caches) - row = next(line for line in tex.splitlines() if line.startswith(r"\texttt{1}")) - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - assert ( - r"\textcolor{ReportMuted}{\scriptsize gen. [s]}" - r" & \texttt{10.0} & \matrixpunct{|} & \texttt{10.0} & " - r"\bestmodecodeprefix{c} & " - r"\bestmoderatio{ReportGreen}{0.400} & " - r"\matrixpunct{|} & " - r"\bestmodeabsoluteprefix{\texttt{5.00}} & " - r"\bestmodecode{e}" - ) in row - assert runtime_row.count(r" & & \bestmodewallratio{ReportGreen}{0.100}") == 2 - assert r"\bestmodeopenprefix" not in runtime_row - assert r"\bestmodecode" not in runtime_row - assert ( - r"\providecommand{\bestmodecompactprefix}[1]{" - r"\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}" - r"\hspace{0.04in}}" - ) in tex - assert ( - r"\providecommand{\bestmodemix}[1]{" - r"\textcolor{ReportBlue}{\texttt{[#1]}}}" - ) in tex - assert ( - r"\providecommand{\matrixsummaryfont}{" - r"\fontsize{6.2pt}{7.4pt}\selectfont}" - ) in tex - assert r"\setlength{\fboxsep}{0.9pt}" in tex - assert r"\setlength{\fboxrule}{0.35pt}" in tex - assert r"\usefont{T1}{lmtt}{b}{n}x#2" in tex - assert r">{\matrixentryfontlc}r@{}>{\matrixentryfontlc}l" in tex - assert ( - r"\textbf{metric} & \multicolumn{8}" - r"{c}{\textbf{n=1}}" - ) in tex - assert r"\matrixcolumnheading" not in tex - assert r"\shortstack{\textbf{n=" not in tex - assert r"\bestmodecodeprefix{c}" in row - assert r"\bestmodecode{e}" in row - assert r"\matrixtotalevaluator{" not in row - assert r"\matrixrecurrencecore{" not in row - generation_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: generation}" in line - ) - summary_header = next( - line - for line in tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{} & ") and r"\bestmodemix{" in line - ) - assert ( - r"\textbf{n=1}\hspace{0.08in}\bestmodemix{r:0|c:1|e:0|o:0}" - in summary_header - ) - assert summary_header.count(r"\bestmodemix{") == 1 - assert r"r:0|c:0|e:1" not in summary_header - assert r"\bestmodemix{" not in generation_summary - assert r"\bestmodesummarystats" not in tex - assert generation_summary.count(r"\matrixsummaryratio{ReportGreen}{0.400}") == 4 - assert ( - generation_summary.count(r"\matrixsummaryratiohighlight{ReportGreen}{0.400}") - == 1 - ) - assert r"\texttt{10.0}" not in generation_summary - assert r"\texttt{5.00}" not in generation_summary - - -@pytest.mark.parametrize( - ("accuracy", "expected_mode_counts"), - ( - ( - Accuracy.LC, - ( - "r:2|c:0|e:0|o:0", - "r:8|c:0|e:0|o:0", - "r:9|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - ), - ), - ( - Accuracy.NLC, - ( - "r:2|c:0|e:0|o:0", - "r:8|c:0|e:0|o:0", - "r:9|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:2|c:0|e:0|o:0", - ), - ), - ( - Accuracy.FULL, - ( - "r:2|c:0|e:0|o:0", - "r:8|c:0|e:0|o:0", - "r:9|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:14|c:0|e:0|o:0", - "r:2|c:0|e:0|o:0", - ), - ), - ), -) -def test_best_mode_summary_headers_hold_one_exact_mode_mix_per_populated_group( - reset_caches: dict[str, dict[str, object]], - accuracy: Accuracy, - expected_mode_counts: tuple[str, ...], -) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_scope(caches, max_n_final=9) - - populated_tex = render_best_mode_table(accuracy, caches) - populated_headers = tuple( - line - for line in populated_tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{} & ") and r"\textbf{n=" in line - ) - populated_body = "\n".join( - line - for line in populated_tex.splitlines() - if not line.startswith(r"\providecommand") - ) - assert ( - tuple( - token - for header in populated_headers - for token in re.findall(r"\\bestmodemix\{([^}]*)\}", header) - ) - == expected_mode_counts - ) - assert all( - header.count(r"\bestmodemix{") == header.count(r"\textbf{n=") - for header in populated_headers - ) - assert populated_body.count(r"\bestmodemix{") == len(expected_mode_counts) - assert all( - r"\bestmodemix{" not in line - for line in populated_tex.splitlines() - if r"\textbf{summary:" in line - ) - assert r"\bestmodesummarystats" not in populated_tex - - blank_tex = render_best_mode_table(accuracy, reset_caches) - blank_headers = tuple( - line - for line in blank_tex.splitlines() - if line.startswith(r"\multicolumn{3}{@{}l}{} & ") and r"\textbf{n=" in line - ) - blank_body = "\n".join( - line - for line in blank_tex.splitlines() - if not line.startswith(r"\providecommand") - ) - assert sum(header.count(r"\textbf{n=") for header in blank_headers) == len( - expected_mode_counts - ) - assert r"\bestmodemix{" not in blank_body - assert r"\bestmodesummarystats" not in blank_tex - - -def test_ratio_summary_reports_five_exact_statistics_without_absolute_times() -> None: - summary = report_render._ratio_statistics_tex(((1.0, 1.0), (3.0, 9.0))) - - assert summary == ( - r"\matrixsummarystats{" - r"\matrixsummaryratio{ReportOrange}{1.00}}{" - r"\matrixsummaryratio{ReportRed}{3.00}}{" - r"\matrixsummaryratio{ReportRed}{2.00}}{" - r"\matrixsummaryratio{ReportRed}{2.00}}{" - r"\matrixsummaryratiohighlight{ReportRed}{2.50}}" - ) - assert r"\texttt{" not in summary - - -def test_summary_statistics_share_fixed_anchors_and_compact_notes( - reset_caches, -) -> None: - fixed_tex = render_matrix_table( - next( - dataset - for dataset in REPORT_CATALOG.matrix_datasets - if dataset.candidate.accuracy is Accuracy.LC - ), - reset_caches, - ) - best_tex = render_best_mode_table(Accuracy.LC, reset_caches) - summary_tables = tuple( - tex - for tex in render_all_tables(reset_caches).values() - if r"\providecommand{\matrixsummarystats}" in tex - ) - separator = r"@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}" - summary_column_layout = ( - r"\begin{tabular}[t]{@{}l" - + separator - + "l" - + separator - + "l" - + separator - + "l" - + separator - + r"l@{}}" - ) - fixed_slot_layout = ( - r"\makebox[3.6em][l]{#1}&" - r"\makebox[4.6em][l]{#2}&" - r"\makebox[3.6em][l]{#3}&" - r"\makebox[3.6em][l]{#4}&" - r"\makebox[4.2em][l]{#5}" - ) - - assert len(summary_tables) == 26 - for tex in summary_tables: - assert summary_column_layout in tex - assert fixed_slot_layout in tex - assert r"\makebox[3.6em][r]" not in tex - assert r"\makebox[4.6em][r]" not in tex - assert r"\makebox[4.2em][r]" not in tex - - for tex in (fixed_tex, best_tex): - assert r"\ReportTableNote{{\scriptsize " in tex - assert "Every displayed number uses exactly three significant digits" in tex - assert "weighted-average order" in tex - assert "weighted average" in tex - assert "framed bold entry" in tex - - assert "Fixed-engine tables intentionally omit mode letters" in fixed_tex - assert "selected independently in each cell and workload" in best_tex - assert "Summary mode counts use r|c|e|o" in best_tex - - -def test_lc_summaries_omit_union_generation_and_keep_both_wall_workloads( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_lc", - ) - candidate = _cache_by_dataset( - caches, - "matrix_compiled_builtin_sm_lc", - ) - selected_pairs = ((1.0, 1.0), (3.0, 9.0)) - union_pairs = ((2.0, 20.0), (4.0, 80.0)) - for process_key, selected, union in zip( - ("dd_z_jets", "ud_w_jets"), - selected_pairs, - union_pairs, - strict=True, - ): - for workload, (baseline_value, candidate_value) in ( - (Workload.SELECTED_FLOW, selected), - (Workload.ALL_FLOW, union), - ): - _set_ok( - baseline, - process_key=process_key, - n_final=1, - workload=workload, - generation=baseline_value, - wall=baseline_value, - execution=baseline_value, - ) - _set_ok( - candidate, - process_key=process_key, - n_final=1, - workload=workload, - generation=candidate_value, - wall=candidate_value, - execution=candidate_value, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_lc"), - caches, - ) - generation_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: generation}" in line - ) - wall_summary = next( - line - for line in tex.splitlines() - if r"\textbf{summary: run single-flow, hel. sum}" in line - ) - selected_stats = report_render._ratio_statistics_tex(selected_pairs) - union_stats = report_render._ratio_statistics_tex(union_pairs) - - assert selected_stats in generation_summary - assert union_stats not in generation_summary - assert r"\matrixsummaryworkloads" not in generation_summary - assert rf"\matrixsummaryworkloads{{{selected_stats}}}{{{union_stats}}}" in ( - wall_summary - ) - assert ( - r"\matrixsummaryworkloads" - r"{\textbf{summary: run single-flow, hel. sum}}" - r"{\textbf{summary: run all-flows, single hel.}}" - ) in wall_summary - assert r"\textbf{summary: wall}" not in tex - assert r"\matrixsummarypair" not in generation_summary - assert r"\matrixsummarypair" not in wall_summary - - -def test_best_mode_summary_tie_breaks_in_documented_mode_order(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - for workload in (Workload.SELECTED_FLOW, Workload.ALL_FLOW): - _set_ok( - _cache_by_dataset(caches, "reference_amplicol_lc"), - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - for mode in ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ): - _set_ok( - _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_lc", - ), - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=5.0, - wall=1.0e-6, - execution=1.0e-6, - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.LC, - REPORT_CATALOG.process_families[0], - 1, - ) - assert {item.mode for item in view.workloads} == {ExecutionMode.RECURRENCE} - rendered = render_all_best_mode_tables(caches) - assert list(rendered) == [ - "result_matrix_best_builtin_sm_lc_table.tex", - "result_matrix_best_builtin_sm_nlc_table.tex", - "result_matrix_best_builtin_sm_full_table.tex", - ] - - -@pytest.mark.parametrize( - ("outcome", "label"), - ( - ("error", "error"), - ("validation_failed", "validation failed"), - ("blocked_dependency", "blocked dependency"), - ("dependency_backend_error", "dependency backend error"), - ), -) -def test_fixed_matrix_renders_generic_presentation_outcomes( - reset_caches, - outcome: str, - label: str, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_presentation_outcome( - _cache_by_dataset(caches, "matrix_compiled_builtin_sm_nlc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome=outcome, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc"), - caches, - ) - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity=f"presentation:{outcome}", - label=label, - color="ReportRed", - ) - ) - marker = rf"\matrixstatus{{ReportRed}}{{{display}}}" - - assert tex.count(marker) == 2 - assert "ManualCampaignOutcome" not in tex - if outcome == "blocked_dependency": - assert display == "blocked dep." - assert label not in tex - if outcome == "dependency_backend_error": - assert display == "depe back erro" - assert label not in tex - if "_" in outcome: - assert outcome not in tex - - -def test_fixed_matrix_keeps_policy_like_presentation_outcomes_orange( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "matrix_compiled_builtin_sm_nlc") - _set_presentation_outcome( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome="generation_limit", - label=">1h", - ) - _set_presentation_outcome( - candidate, - process_key="ud_w_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome="error", - ) - _set_presentation_outcome( - candidate, - process_key="dd_z_jets", - n_final=2, - workload=Workload.CONTRACTED, - outcome="resource_frontier", - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc"), - caches, - ) - - assert tex.count(r"\matrixstatus{ReportOrange}{>1h}") == 2 - assert tex.count(r"\matrixstatus{ReportRed}{error}") == 2 - assert tex.count(r"\matrixstatus{ReportOrange}{resource frontier}") == 2 - assert r"\matrixstatus{ReportRed}{>1h}" not in tex - assert r"\matrixstatus{ReportOrange}{error}" not in tex - - -@pytest.mark.parametrize( - "label", - ( - "W" * 64, - "W" * 12, - "W" * 11 + " " + "W" * 11, - "w" * 12 + " " + "w" * 11, - "Q" * 12 + " " + "Q" * 11, - "O" * 12 + " " + "O" * 11, - ), -) -def test_fixed_matrix_compacts_one_worst_case_wide_future_label( - reset_caches, - label: str, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "matrix_compiled_builtin_sm_nlc") - _set_presentation_outcome( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome="future_wide_status", - label=label, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc"), - caches, - ) - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity="presentation:future_wide_status", - label=label, - color="ReportRed", - ) - ) - - assert display == "futu wide stat" - assert tex.count(rf"\matrixstatus{{ReportRed}}{{{display}}}") == 2 - assert label not in tex - - -def test_known_error_slug_does_not_exempt_a_wide_mismatched_label() -> None: - label = "W" * 64 - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity="presentation:error", - label=label, - color="ReportRed", - ) - ) - - assert display == "error" - - -def test_policy_slug_does_not_exempt_an_unrealistically_wide_cap_label() -> None: - label = ">" + "9" * 60 + "GB" - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity="presentation:memory_limit", - label=label, - color="ReportOrange", - ) - ) - - assert display == "memo limi" - - -def test_policy_slug_compacts_a_too_wide_otherwise_valid_cap_label() -> None: - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity="presentation:dependency", - label="dependency >9999.9999s", - color="ReportOrange", - ) - ) - - assert display == "dependency" - - -def test_authenticated_policy_state_keeps_semantics_for_an_overwide_cap() -> None: - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity="policy:dependency", - label="dependency >9999.9999s", - color="ReportOrange", - ) - ) - - assert display == "dependency" - - -@pytest.mark.parametrize( - ("outcome", "label"), - ( - ("error", "error"), - ("validation_failed", "validation failed"), - ("blocked_dependency", "blocked dependency"), - ("dependency_backend_error", "dependency backend error"), - ), -) -def test_best_mode_renders_failure_only_generic_presentation_outcomes( - reset_caches, - outcome: str, - label: str, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_best_mode_nlc_reference(caches) - for mode in ExecutionMode.RECURRENCE, ExecutionMode.COMPILED, ExecutionMode.EAGER: - _set_presentation_outcome( - _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome=outcome, - ) - - tex = render_best_mode_table(Accuracy.NLC, caches) - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity=f"presentation:{outcome}", - label=label, - color="ReportRed", - ) - ) - marker = rf"\matrixstatus{{ReportRed}}{{{display}}}" - - assert tex.count(marker) == 4 - table_body = "\n".join( - line for line in tex.splitlines() if not line.startswith(r"\providecommand") - ) - assert r"\bestmodecode{" not in table_body - - -def test_best_mode_mixed_generic_outcomes_have_deterministic_labels( - reset_caches, -) -> None: - assignments = ( - ("error", "validation_failed", "blocked_dependency"), - ("error", "blocked_dependency", "validation_failed"), - ) - rendered_tables: list[str] = [] - for outcomes in assignments: - caches = copy.deepcopy(reset_caches) - _set_best_mode_nlc_reference(caches) - for mode, outcome in zip( - ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ), - outcomes, - strict=True, - ): - _set_presentation_outcome( - _cache_by_dataset( - caches, - f"matrix_{mode.value.replace('-', '_')}_builtin_sm_nlc", - ), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome=outcome, - ) - - tex = render_best_mode_table(Accuracy.NLC, caches) - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.NLC, - REPORT_CATALOG.process_families[0], - 1, - ) - joined = view.workloads[0] - marker = r"\matrixstatus{ReportRed}{error}" - - assert tex.count(marker) == 4 - assert joined.mode is ExecutionMode.RECURRENCE - assert joined.terminal_label is None - assert r"\bestmodecodeprefix{r}" in tex - assert r"\matrixstatus{ReportRed}{validation failed}" not in tex - assert r"\matrixstatus{ReportRed}{blocked dep.}" not in tex - rendered_tables.append(tex) - - assert rendered_tables[0] == rendered_tables[1] - - -def test_best_mode_compacts_three_maximum_length_future_outcomes( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_best_mode_nlc_reference(caches) - outcomes = ( - ("future_alpha", "alpha_" + "a" * 58), - ("future_bravo", "bravo&" + "b" * 58), - ("future_charlie", "charl%" + "c" * 58), - ) - assert all(len(label) == 64 for _outcome, label in outcomes) - for mode, (outcome, label) in zip( - ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ), - outcomes, - strict=True, - ): - _set_presentation_outcome( - _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome=outcome, - label=label, - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.NLC, - REPORT_CATALOG.process_families[0], - 1, - ) - joined = view.workloads[0] - assert joined.mode is ExecutionMode.RECURRENCE - assert joined.terminal_label is None - - tex = render_best_mode_table(Accuracy.NLC, caches) - marker = r"\matrixstatus{ReportRed}{futu alph}" - assert tex.count(marker) == 4 - assert r"\bestmodecodeprefix{r}" in tex - assert all(label not in tex for _outcome, label in outcomes) - - -def test_best_mode_many_unique_outcomes_have_one_hard_bounded_identity() -> None: - outcomes = tuple( - report_render._TerminalOutcome( - identity=f"presentation:future_{index:02d}", - label=f"future outcome {index:02d}", - color="ReportRed", - ) - for index in range(12) - ) - - summary = report_render._canonical_best_mode_terminal_label(outcomes) - reversed_summary = report_render._canonical_best_mode_terminal_label( - tuple(reversed(outcomes)) - ) - - assert summary is not None - assert reversed_summary is not None - assert summary.outcomes == reversed_summary.outcomes - assert summary.label == reversed_summary.label - assert len(summary.label) <= 48 - assert re.fullmatch(r"12 outcomes \[[0-9a-f]{6}\]", summary.label) - assert {item.identity for item in summary.outcomes} == { - item.identity for item in outcomes - } - assert re.fullmatch( - r"N out\.\[[0-9a-f]{6}\]", - report_render._compact_terminal_summary_display(summary), - ) - - -@pytest.mark.parametrize("count", (12, 1796)) -def test_best_mode_outcome_count_display_has_fixed_width(count: int) -> None: - outcome = report_render._TerminalOutcome( - identity="presentation:error", - label="error", - color="ReportRed", - ) - summary = report_render._TerminalSummary( - outcomes=(outcome, outcome), - label=f"{count} outcomes [abcdef]", - color="ReportRed", - ) - - assert report_render._compact_terminal_summary_display(summary) == ( - "N out.[abcdef]" - ) - - -def test_best_mode_success_wins_over_generic_presentation_outcomes( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_best_mode_nlc_reference(caches) - _set_presentation_outcome( - _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome="error", - ) - _set_ok( - _cache_by_dataset(caches, "matrix_compiled_builtin_sm_nlc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=1.0e-6, - execution=1.0e-6, - ) - _set_presentation_outcome( - _cache_by_dataset(caches, "matrix_eager_builtin_sm_nlc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome="blocked_dependency", - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.NLC, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[0].mode is ExecutionMode.COMPILED - - tex = render_best_mode_table(Accuracy.NLC, caches) - generation_row = next( - line for line in tex.splitlines() if line.startswith(r"\texttt{1}") - ) - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - - assert r"\bestmodecode{c}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{1.00}}" in runtime_row - assert r"\bestmoderatio{" not in generation_row - assert r"\bestmodewallratio{" not in runtime_row - assert r"\bestmodemix{r:0|c:1|e:0}" not in tex - assert r"\matrixstatus{ReportRed}{error}" not in tex - assert r"\matrixstatus{ReportRed}{blocked dependency}" not in tex - - -def test_best_mode_uses_an_exact_equivalent_z_success_over_a_matrix_cap( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_ok( - _cache_by_dataset(caches, "reference_amplicol_lc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - for mode in (ExecutionMode.RECURRENCE, ExecutionMode.COMPILED): - entry = _entry( - _cache_by_dataset(caches, f"matrix_{mode.value}_builtin_sm_lc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - ) - entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(entry["cell_id"])) - ) - _set_ok( - _cache_by_dataset(caches, "z_builtin_sm"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - variant="recurrence_jit_o2", - generation=7.0, - wall=2.0e-6, - execution=1.0e-6, - ) - equivalent_terminal = _entry( - _cache_by_dataset(caches, "z_builtin_sm"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.ALL_FLOW, - variant="recurrence_jit_o2", - ) - equivalent_terminal["measurement"] = _generation_censor( - REPORT_CATALOG.cell(str(equivalent_terminal["cell_id"])) - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.LC, - REPORT_CATALOG.process_families[0], - 1, - ) - selected = view.workloads[0] - assert selected.mode is ExecutionMode.RECURRENCE - assert selected.candidate["status"] == ResultStatus.OK.value - assert selected.candidate["wall_seconds_per_point"] == 2.0e-6 - assert selected.comparison_linked - all_flow = view.workloads[1] - assert all_flow.mode is ExecutionMode.RECURRENCE - assert all_flow.candidate["status"] == ResultStatus.TIMEOUT.value - - tex = render_best_mode_table(Accuracy.LC, caches) - row = next(line for line in tex.splitlines() if line.startswith(r"\texttt{1}")) - assert row.count(r"\bestmodecodeprefix{r}") == 2 - assert r"\matrixstatus{ReportOrange}{>2h}" in row - assert r"\matrixstatus{ReportOrange}{>80GB}" not in tex - - -def test_best_mode_prefers_its_owned_success_before_equivalent_success( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_ok( - _cache_by_dataset(caches, "reference_amplicol_lc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - _set_ok( - _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_lc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=5.0, - wall=5.0e-6, - execution=4.0e-6, - ) - _set_ok( - _cache_by_dataset(caches, "z_builtin_sm"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - variant="recurrence_jit_o2", - generation=1.0, - wall=0.5e-6, - execution=0.4e-6, - ) - _set_ok( - _cache_by_dataset(caches, "matrix_compiled_builtin_sm_lc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=2.0, - wall=2.0e-6, - execution=1.5e-6, - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.LC, - REPORT_CATALOG.process_families[0], - 1, - ) - selected = view.workloads[0] - assert selected.mode is ExecutionMode.COMPILED - assert selected.candidate["wall_seconds_per_point"] == 2.0e-6 - - -def test_best_mode_mixed_policy_censors_fall_back_to_recurrence( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_ok( - _cache_by_dataset(caches, "reference_amplicol_nlc"), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - candidate_entries = { - mode: _entry( - _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - ) - for mode in ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ) - } - recurrence_cell = REPORT_CATALOG.cell( - str(candidate_entries[ExecutionMode.RECURRENCE]["cell_id"]) - ) - recurrence_censor = _generation_censor(recurrence_cell) - candidate_entries[ExecutionMode.RECURRENCE]["measurement"] = recurrence_censor - compiled_cell = REPORT_CATALOG.cell( - str(candidate_entries[ExecutionMode.COMPILED]["cell_id"]) - ) - candidate_entries[ExecutionMode.COMPILED]["measurement"] = _memory_censor( - compiled_cell - ) - eager_cell = REPORT_CATALOG.cell( - str(candidate_entries[ExecutionMode.EAGER]["cell_id"]) - ) - candidate_entries[ExecutionMode.EAGER]["measurement"] = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - eager_cell, - kind=PolicyCensorKind.DEPENDENCY, - source_identity=_POLICY_IDENTITY, - resources=None, - dependencies=( - dependency_reference( - recurrence_cell.cell_id, - recurrence_censor, - ), - ), - ) - - tex = render_best_mode_table(Accuracy.NLC, caches) - row = next(line for line in tex.splitlines() if line.startswith(r"\texttt{1}")) - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - - marker = r"\matrixstatus{ReportOrange}{>2h}" - assert marker in row - assert marker in runtime_row - assert ( - r">{\matrixentryfont}l" - r">{\matrixentryfont}r@{}" - r">{\matrixentryfont}l" - ) in tex - assert r"\bestmodecodeprefix{r}" in row - assert r"\matrixstatus{ReportOrange}{>80GB}" not in row - assert r"\matrixstatus{ReportOrange}{dependency}" not in row - assert r"\matrixna{ReportMuted}" not in row - - -def test_best_mode_mixed_terminal_summaries_are_visibly_complete( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - recurrence = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - compiled = _cache_by_dataset( - caches, - "matrix_compiled_builtin_sm_nlc", - ) - eager = _cache_by_dataset(caches, "matrix_eager_builtin_sm_nlc") - on_the_fly = _cache_by_dataset(caches, "matrix_on_the_fly_builtin_sm_nlc") - recurrence_entries = recurrence["entries"] - assert isinstance(recurrence_entries, list) - for recurrence_entry in recurrence_entries: - if recurrence_entry["n_final"] != 1: - continue - process_key = str(recurrence_entry["process_key"]) - recurrence_cell = REPORT_CATALOG.cell(str(recurrence_entry["cell_id"])) - recurrence_censor = _generation_censor(recurrence_cell) - recurrence_entry["measurement"] = recurrence_censor - compiled_entry = _entry( - compiled, - process_key=process_key, - n_final=1, - workload=Workload.CONTRACTED, - ) - compiled_entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(compiled_entry["cell_id"])) - ) - eager_entry = _entry( - eager, - process_key=process_key, - n_final=1, - workload=Workload.CONTRACTED, - ) - eager_entry["measurement"] = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - REPORT_CATALOG.cell(str(eager_entry["cell_id"])), - kind=PolicyCensorKind.DEPENDENCY, - source_identity=_POLICY_IDENTITY, - resources=None, - dependencies=( - dependency_reference( - recurrence_cell.cell_id, - recurrence_censor, - ), - ), - ) - on_the_fly_entry = _entry( - on_the_fly, - process_key=process_key, - n_final=1, - workload=Workload.CONTRACTED, - ) - on_the_fly_entry["measurement"] = policy_censor_measurement( - X86_EPYC_POLICY, - "x86_EPYC", - REPORT_CATALOG.cell(str(on_the_fly_entry["cell_id"])), - kind=PolicyCensorKind.DEPENDENCY, - source_identity=_POLICY_IDENTITY, - resources=None, - dependencies=( - dependency_reference( - recurrence_cell.cell_id, - recurrence_censor, - ), - ), - ) - - tex = render_best_mode_table(Accuracy.NLC, caches) - generation_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: generation}" in line - ) - wall_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: wall}" in line - ) - marker = r"\matrixstatus{ReportOrange}{>2h}" - assert generation_summary.count(marker) == 1 - assert wall_summary.count(marker) == 1 - - completeness = summarize_visible_completeness( - caches, - max_n_final=4, - policy=X86_EPYC_POLICY, - ) - assert completeness.complete - assert not completeness.applicable_na_display_slots - - -def test_best_mode_terminal_baselines_stay_in_rows_but_not_summaries( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - reference = _cache_by_dataset(caches, "reference_amplicol_nlc") - entries = reference["entries"] - assert isinstance(entries, list) - for entry in entries: - if entry["n_final"] == 1: - entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(entry["cell_id"])) - ) - - tex = render_best_mode_table(Accuracy.NLC, caches) - lines = tex.splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - generation_row = lines[row_index] - runtime_row = lines[row_index + 2] - marker = r"\matrixstatus{ReportOrange}{>80GB}" - assert generation_row.count(marker) == 1 - assert runtime_row.count(marker) == 1 - assert r"\bestmodeabsoluteprefix{\texttt{1.00}}" in generation_row - assert r"\bestmodecode{r}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" in runtime_row - generation_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: generation}" in line - ) - wall_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: wall}" in line - ) - assert marker not in generation_summary - assert marker not in wall_summary - assert r"\matrixna{ReportMuted}" not in generation_row - assert r"\matrixna{ReportMuted}" not in runtime_row - assert r"\matrixna{ReportMuted}" in generation_summary - assert r"\matrixna{ReportMuted}" in wall_summary - - -@pytest.mark.parametrize( - ("accuracy", "workloads"), - ( - (Accuracy.LC, (Workload.SELECTED_FLOW, Workload.ALL_FLOW)), - (Accuracy.NLC, (Workload.CONTRACTED,)), - (Accuracy.FULL, (Workload.CONTRACTED,)), - ), -) -def test_recurrence_renders_absolute_when_amplicol_baseline_is_terminal( - reset_caches, - accuracy: Accuracy, - workloads: tuple[Workload, ...], -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, f"reference_amplicol_{accuracy.value}") - candidate = _cache_by_dataset( - caches, - f"matrix_recurrence_builtin_sm_{accuracy.value}", - ) - for index, workload in enumerate(workloads): - baseline_entry = _entry( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=workload, - ) - baseline_entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(baseline_entry["cell_id"])) - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=4.0 + 6.0 * index, - wall=(2.0 + index) * 1.0e-6, - execution=(1.0 + 0.5 * index) * 1.0e-6, - ) - - dataset = next( - item - for item in REPORT_CATALOG.matrix_datasets - if item.dataset_id == f"matrix_recurrence_builtin_sm_{accuracy.value}" - ) - marker = r"\matrixstatus{ReportOrange}{>80GB}" - for tex, best_mode in ( - (render_matrix_table(dataset, caches), False), - (render_best_mode_table(accuracy, caches), True), - ): - lines = tex.splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - generation_row = lines[row_index] - runtime_row = lines[row_index + 2] - assert generation_row.count(marker) == len(workloads) - assert runtime_row.count(marker) == len(workloads) - assert generation_row.count(r"\bestmodeabsoluteprefix{") == len(workloads) - assert runtime_row.count(r"\bestmodeabsoluteprefix{") == len(workloads) - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" in runtime_row - assert r"\bestmoderatio{" not in generation_row - assert r"\bestmodeprimaryratio{" not in runtime_row - if best_mode: - assert generation_row.count(r"\bestmodecode{r}") == len(workloads) - - best_tex = render_best_mode_table(accuracy, caches) - generation_summary = next( - line - for line in best_tex.splitlines() - if r"\textbf{summary: generation}" in line - ) - wall_summary = next( - line - for line in best_tex.splitlines() - if "summary: run" in line or r"\textbf{summary: wall}" in line - ) - assert marker not in generation_summary - assert marker not in wall_summary - assert r"\matrixsummarystats{" not in generation_summary - assert r"\matrixsummarystats{" not in wall_summary - assert r"\matrixna{ReportMuted}" in generation_summary - assert r"\matrixna{ReportMuted}" in wall_summary - - -def test_recurrence_renders_absolute_when_amplicol_was_not_run( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc") - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - dataset = next( - item - for item in REPORT_CATALOG.matrix_datasets - if item.dataset_id == "matrix_recurrence_builtin_sm_nlc" - ) - - for tex in ( - render_matrix_table(dataset, caches), - render_best_mode_table(Accuracy.NLC, caches), - ): - lines = tex.splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - generation_row = lines[row_index] - runtime_row = lines[row_index + 2] - assert r"\matrixstatus{ReportMuted}{N/A}" in generation_row - assert r"\matrixstatus{ReportMuted}{N/A}" in runtime_row - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" in runtime_row - assert r"\bestmoderatio{" not in generation_row - assert r"\bestmodeprimaryratio{" not in runtime_row - - -def test_later_amplicol_current_does_not_retroactively_link_recurrence( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - recurrence = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc") - reference = _cache_by_dataset(caches, "reference_amplicol_nlc") - _set_ok( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - recurrence_measurement = _entry( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - )["measurement"] - assert isinstance(recurrence_measurement, dict) - validation = recurrence_measurement["validation"] - assert isinstance(validation, dict) - validation.pop("pointwise") - _set_ok( - reference, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - - dataset = REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_nlc") - view = BaselineCandidateAdapter(caches).matrix_cell( - dataset, - REPORT_CATALOG.process_families[0], - 1, - ) - assert not view.workloads[0].comparison_linked - tex = render_matrix_table(dataset, caches) - generation_row = next( - line for line in tex.splitlines() if line.startswith(r"\texttt{1}") - ) - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in generation_row - assert r"\bestmoderatio{" not in generation_row - generation_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: generation}" in line - ) - assert r"\matrixsummarystats{" not in generation_summary - assert r"\matrixna{ReportMuted}" in generation_summary - assert "unlinked baselines keep their status" in tex - - -@pytest.mark.parametrize("mode", (ExecutionMode.COMPILED, ExecutionMode.EAGER)) -@pytest.mark.parametrize("broken_chain", (False, True)) -def test_best_dag_ratio_requires_exact_transitive_amplicol_link( - reset_caches, - mode: ExecutionMode, - broken_chain: bool, -) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_nlc") - recurrence = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc") - candidate = _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ) - for cache, generation, wall in ( - (reference, 10.0, 10.0e-6), - (recurrence, 6.0, 3.0e-6), - (candidate, 2.0, 1.0e-6), - ): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=generation, - wall=wall, - execution=wall, - ) - if broken_chain: - recurrence_measurement = _entry( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - )["measurement"] - assert isinstance(recurrence_measurement, dict) - validation = recurrence_measurement["validation"] - assert isinstance(validation, dict) - pointwise = validation["pointwise"] - assert isinstance(pointwise, dict) - pointwise["baseline"] = 2.0 - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.NLC, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[0].mode is mode - assert view.workloads[0].comparison_linked is not broken_chain - generation_row = next( - line - for line in render_best_mode_table(Accuracy.NLC, caches).splitlines() - if line.startswith(r"\texttt{1}") - ) - if broken_chain: - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" in generation_row - assert r"\bestmoderatio{" not in generation_row - else: - assert r"\bestmoderatio{ReportGreen}{0.200}" in generation_row - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" not in generation_row - - -@pytest.mark.parametrize("broken_selector", (False, True)) -def test_direct_pointwise_link_requires_exact_selector( - reset_caches, - broken_selector: bool, -) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_lc") - recurrence = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_lc") - for cache, generation in ((reference, 10.0), (recurrence, 4.0)): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=generation, - wall=generation * 1.0e-6, - execution=1.0e-6, - ) - if broken_selector: - measurement = _entry( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - )["measurement"] - assert isinstance(measurement, dict) - selector = measurement["selector_contract"] - assert isinstance(selector, dict) - selector["point_digest"] = "1" * 64 - - dataset = REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_lc") - view = BaselineCandidateAdapter(caches).matrix_cell( - dataset, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[0].comparison_linked is not broken_selector - generation_row = next( - line - for line in render_matrix_table(dataset, caches).splitlines() - if line.startswith(r"\texttt{1}") - ) - if broken_selector: - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in generation_row - assert r"\bestmoderatio{" not in generation_row - else: - assert r"\bestmoderatio{ReportGreen}{0.400}" in generation_row - - -@pytest.mark.parametrize("broken_component", (False, True)) -def test_direct_agreement_link_requires_exact_component_identity( - reset_caches, - broken_component: bool, -) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_lc") - recurrence = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_lc") - for cache, generation in ((reference, 10.0), (recurrence, 4.0)): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.ALL_FLOW, - generation=generation, - wall=generation * 1.0e-6, - execution=1.0e-6, - ) - if broken_component: - measurement = _entry( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.ALL_FLOW, - )["measurement"] - assert isinstance(measurement, dict) - validation = measurement["validation"] - assert isinstance(validation, dict) - component = validation[LC_COMMON_COMPONENT_FIELD] - assert isinstance(component, dict) - component["color_flow_ids"] = ["flow:other"] - - dataset = REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_lc") - view = BaselineCandidateAdapter(caches).matrix_cell( - dataset, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[1].comparison_linked is not broken_component - lines = render_matrix_table(dataset, caches).splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - runtime_row = lines[row_index + 2] - if broken_component: - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in runtime_row - assert r"\bestmodeprimaryratio{" not in runtime_row - else: - assert r"\bestmodeprimaryratio{ReportGreen}{0.400}" in runtime_row - - -def test_direct_agreement_v2_remains_comparison_linked(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_lc") - recurrence = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_lc") - for cache, generation in ((reference, 10.0), (recurrence, 4.0)): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.ALL_FLOW, - generation=generation, - wall=generation * 1.0e-6, - execution=1.0e-6, - ) - measurement = _entry( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.ALL_FLOW, - )["measurement"] - assert isinstance(measurement, dict) - validation = measurement["validation"] - assert isinstance(validation, dict) - records = validation["direct_agreements"] - assert isinstance(records, list) and records - for record in records: - assert isinstance(record, dict) - comparison = pointwise_validation( - float(record["candidate"]), - float(record["baseline"]), - relative_tolerance=float(record["relative_tolerance"]), - comparison_binding={"point_digest": "0" * 64}, - ) - comparison.pop("abi") - identity = { - field: record[field] - for field in ( - "edge_kind", - "value_kind", - "baseline_cell_id", - "candidate_cell_id", - ) - } - record.clear() - record.update({"abi": DIRECT_AGREEMENT_V2_ABI, **identity, **comparison}) - - dataset = REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_lc") - view = BaselineCandidateAdapter(caches).matrix_cell( - dataset, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[1].comparison_linked - - -@pytest.mark.parametrize("mode", (ExecutionMode.COMPILED, ExecutionMode.EAGER)) -def test_fixed_compiled_and_eager_preserve_terminal_recurrence_baseline( - reset_caches, - mode: ExecutionMode, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc") - candidate = _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ) - baseline_entry = _entry( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - ) - baseline_entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(baseline_entry["cell_id"])) - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - dataset = next( - item - for item in REPORT_CATALOG.matrix_datasets - if item.dataset_id == f"matrix_{mode.value}_builtin_sm_nlc" - ) - - lines = render_matrix_table(dataset, caches).splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - marker = r"\matrixstatus{ReportOrange}{>80GB}" - assert lines[row_index].count(marker) == 1 - assert lines[row_index + 2].count(marker) == 1 - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in lines[row_index] - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" in lines[row_index + 2] - - -@pytest.mark.parametrize("mode", (ExecutionMode.COMPILED, ExecutionMode.EAGER)) -def test_fixed_compiled_and_eager_show_unverified_absolute_diagnostic_clocks( - reset_caches, - mode: ExecutionMode, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc") - candidate = _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ) - baseline_entry = _entry( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - ) - baseline_entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(baseline_entry["cell_id"])) - ) - _set_unverified( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - evaluator_total=1.0e-6, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset(f"matrix_{mode.value}_builtin_sm_nlc"), - caches, - ) - lines = tex.splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - generation_row = lines[row_index] - runtime_row = lines[row_index + 2] - authority_marker = r"\matrixstatus{ReportOrange}{>80GB}" - unverified_marker = r"\matrixstatus{ReportOrange}{unverified}" - - assert generation_row.count(authority_marker) == 1 - assert runtime_row.count(authority_marker) == 1 - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in generation_row - assert unverified_marker in generation_row - assert ( - r"\bestmodeunverifiedclockprefix{\texttt{1.00}}{\texttt{2.00}}" in runtime_row - ) - assert unverified_marker in runtime_row - assert "Unverified compiled or eager diagnostics show absolute generation" in tex - assert "never enter ratios or summaries" in tex - - -def test_best_mode_never_selects_or_summarizes_unverified_diagnostics( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _set_best_mode_nlc_reference(caches) - for mode in ExecutionMode.COMPILED, ExecutionMode.EAGER: - _set_unverified( - _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - evaluator_total=1.0e-6, - ) - - view = BaselineCandidateAdapter(caches).best_mode_cell( - Accuracy.NLC, - REPORT_CATALOG.process_families[0], - 1, - ) - assert view.workloads[0].mode is None - assert view.workloads[0].terminal_label is None - - tex = render_best_mode_table(Accuracy.NLC, caches) - lines = tex.splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - marker = r"\matrixstatus{ReportOrange}{unverified}" - assert marker not in lines[row_index] - assert marker not in lines[row_index + 2] - assert r"\bestmodecodeprefix{r}" not in lines[row_index] - assert r"\matrixstatus{ReportMuted}{N/A}" in lines[row_index] - assert r"\matrixstatus{ReportMuted}{N/A}" in lines[row_index + 2] - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" not in lines[row_index] - - generation_summary = next( - line for line in lines if r"\textbf{summary: generation}" in line - ) - wall_summary = next(line for line in lines if r"\textbf{summary: wall}" in line) - assert marker not in generation_summary - assert marker not in wall_summary - assert r"\matrixsummarystats{" not in generation_summary - assert r"\matrixsummarystats{" not in wall_summary - assert "never eligible for best-mode selection or summaries" in tex - - -def test_presentation_only_unverified_is_fixed_only_and_not_a_best_mode( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "matrix_compiled_builtin_sm_nlc") - _set_presentation_outcome( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - outcome="unverified", - ) - - fixed = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc"), - caches, - ) - best = render_best_mode_table(Accuracy.NLC, caches) - marker = r"\matrixstatus{ReportOrange}{unverified}" - red_marker = r"\matrixstatus{ReportRed}{unverified}" - - assert marker in fixed - assert marker not in best - assert red_marker not in fixed - assert red_marker not in best - - -@pytest.mark.parametrize( - ("mode", "code"), - ((ExecutionMode.COMPILED, "c"), (ExecutionMode.EAGER, "e")), -) -def test_best_compiled_and_eager_render_absolute_without_amplicol_baseline( - reset_caches, - mode: ExecutionMode, - code: str, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset( - caches, - f"matrix_{mode.value}_builtin_sm_nlc", - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - - lines = render_best_mode_table(Accuracy.NLC, caches).splitlines() - row_index = next( - index for index, line in enumerate(lines) if line.startswith(r"\texttt{1}") - ) - assert r"\matrixstatus{ReportMuted}{N/A}" in lines[row_index] - assert r"\matrixstatus{ReportMuted}{N/A}" in lines[row_index + 2] - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in lines[row_index] - assert rf"\bestmodecode{{{code}}}" in lines[row_index] - assert r"\bestmodeabsoluteprefix{\texttt{2.00}}" in lines[row_index + 2] - assert r"\bestmoderatio{" not in lines[row_index] - assert r"\bestmodeprimaryratio{" not in lines[row_index + 2] - - -@pytest.mark.parametrize( - ("variant", "setup", "execution_mode"), - ( - ("recurrence_jit_o2", "recurrence JIT O2", "recurrence"), - ("jit_o3", "compiled JIT O3", "compiled"), - ("eager_jit_o2", "eager-DAG JIT O2", "eager"), - ), -) -def test_z_pyamplicol_renders_all_clocks_absolute_without_amplicol_baseline( - reset_caches, - variant: str, - setup: str, - execution_mode: str, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_lc") - candidate = _cache_by_dataset(caches, "z_builtin_sm") - for index, workload in enumerate((Workload.SELECTED_FLOW, Workload.ALL_FLOW)): - baseline_entry = _entry( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=workload, - ) - baseline_entry["measurement"] = _memory_censor( - REPORT_CATALOG.cell(str(baseline_entry["cell_id"])) - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=4.0 + 6.0 * index, - wall=(2.0 + index) * 1.0e-6, - execution=(1.0 + 0.5 * index) * 1.0e-6, - variant=variant, - ) - candidate_entry = _entry( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - variant=variant, - ) - measurement = candidate_entry["measurement"] - assert isinstance(measurement, dict) - _mark_evaluator_total( - measurement, - execution_mode=execution_mode, - total=(1.7 + index) * 1.0e-6, - ) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - reference_row = next( - line for line in tex.splitlines() if line.startswith(r"1 & \AC{} reference") - ) - candidate_row = next( - line for line in tex.splitlines() if line.startswith(f"1 & {setup}") - ) - assert reference_row.count(r"\matrixstatus{ReportOrange}{>80GB}") == 4 - assert candidate_row.count(r"\matrixncabsolute{") == 6 - assert r"\matrixratio{" not in candidate_row - assert r"\matrixnaratio{" not in candidate_row - assert "successful pyAmpliCol values are absolute" in tex - - -@pytest.mark.parametrize( - ("variant", "setup", "execution_mode"), - ( - ("jit_o3", "compiled JIT O3", ExecutionMode.COMPILED), - ("eager_jit_o2", "eager-DAG JIT O2", ExecutionMode.EAGER), - ), -) -@pytest.mark.parametrize("broken_chain", (False, True)) -def test_z_dag_ratio_accepts_only_exact_recurrence_to_amplicol_chain( - reset_caches, - variant: str, - setup: str, - execution_mode: ExecutionMode, - broken_chain: bool, -) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_lc") - z_cache = _cache_by_dataset(caches, "z_builtin_sm") - _set_ok( - reference, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=10.0, - wall=10.0e-6, - execution=None, - ) - _set_ok( - z_cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=6.0, - wall=3.0e-6, - execution=2.0e-6, - variant="recurrence_jit_o2", - ) - _set_ok( - z_cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=2.0, - wall=1.0e-6, - execution=0.8e-6, - variant=variant, - ) - candidate = _entry( - z_cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - variant=variant, - )["measurement"] - recurrence = _entry( - z_cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - variant="recurrence_jit_o2", - )["measurement"] - assert isinstance(candidate, dict) - assert isinstance(recurrence, dict) - candidate_validation = candidate["validation"] - recurrence_validation = recurrence["validation"] - assert isinstance(candidate_validation, dict) - assert isinstance(recurrence_validation, dict) - assert isinstance(candidate_validation.get("pointwise"), dict) - if broken_chain: - recurrence_pointwise = recurrence_validation["pointwise"] - assert isinstance(recurrence_pointwise, dict) - recurrence_pointwise["baseline"] = 2.0 - - z_variant = next(item for item in REPORT_CATALOG.z_variants if item.key == variant) - joined = BaselineCandidateAdapter(caches).z_workload( - model=ModelKey.BUILTIN_SM, - n_final=1, - variant=z_variant, - workload=Workload.SELECTED_FLOW, - ) - assert z_variant.execution_mode is execution_mode - assert joined.comparison_linked is not broken_chain - candidate_row = next( - line - for line in render_z_ladder(ModelKey.BUILTIN_SM, caches).splitlines() - if line.startswith(f"1 & {setup}") - ) - if broken_chain: - assert candidate_row.startswith( - f"1 & {setup} & \\matrixncabsolute{{\\texttt{{2}}}}" - ) - assert r"\matrixratio{" not in candidate_row - else: - assert r"\matrixratio{ReportGreen}{0.2}" in candidate_row - - -def test_best_mode_missing_candidates_remain_incomplete_under_strict_policy( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - for mode in ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - ): - entry = _entry( - _cache_by_dataset( - caches, - f"matrix_{mode.value.replace('-', '_')}_builtin_sm_nlc", - ), - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - ) - entry["measurement"] = empty_measurement() - - completeness = summarize_visible_completeness( - caches, - max_n_final=4, - ) - - assert not completeness.complete - assert any( - "result_matrix_best_builtin_sm_nlc_table.tex/n1/dd_z_jets/contracted" in slot - for slot in completeness.applicable_na_display_slots - ) - - -def test_matrix_baseline_labels_follow_dataset_contract(reset_caches) -> None: - rendered = render_all_matrix_tables(reset_caches) - - for dataset in REPORT_CATALOG.matrix_datasets: - if dataset.table_name not in rendered: - continue - tex = rendered[dataset.table_name] - if dataset.candidate.execution_mode in { - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - }: - assert "Baseline: original AmpliCol" in tex - else: - assert "Baseline: recurrence JIT O2" in tex - assert dataset.title in tex - for view in MADGRAPH_FULL_COMPARISON_VIEWS: - tex = rendered[view.table_name] - assert "Baseline: MadGraph standalone" in tex - assert view.title in tex - - -def test_matrix_tables_are_fixed_nonsplittable_blocks(reset_caches) -> None: - rendered = render_all_matrix_tables(reset_caches) - - for tex in rendered.values(): - assert "longtable" not in tex - assert r"\begin{minipage}{\linewidth}" in tex - assert r"\end{minipage}" in tex - assert tex.count(r"\begin{minipage}{\linewidth}") == tex.count( - r"\end{minipage}" - ) - assert tex.count(r"\clearpage") == tex.count(r"\begin{minipage}{\linewidth}") - assert r"\begin{tabular}" in tex - assert r"\ifdim\wd0>\linewidth" in tex - assert r"\resizebox{\linewidth}{!}{\usebox0}" in tex - assert tex.count(r"\matrixfitwidth{%") == tex.count( - r"\begin{minipage}{\linewidth}" - ) - assert r"\makebox[\linewidth][c]{%" not in tex - assert r"\fontsize{6.5pt}{7.5pt}\selectfont" in tex - assert r"\begingroup\matrixsummaryfont" in tex - assert r"\hspace{0.014in}" in tex - assert tex.index(r"\clearpage") < tex.index(r"\subsection{") - assert tex.index(r"\subsection{") < tex.index( - r"\noindent\begin{minipage}{\linewidth}" - ) - - -def test_inapplicable_not_run_and_reset_cells_use_distinct_markers( - reset_caches, -) -> None: - lc = render_matrix_table( - REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_lc"), - reset_caches, - ) - assert r"\matrixnotapplicable{ReportMuted}" in lc - assert r"\matrixstatus{ReportMuted}{not run}" not in lc - assert r"\matrixstatus{ReportMuted}{N/A}" in lc - - for accuracy in (Accuracy.NLC, Accuracy.FULL): - fixed = render_matrix_table( - REPORT_CATALOG.dataset(f"matrix_recurrence_builtin_sm_{accuracy.value}"), - reset_caches, - ) - best = render_best_mode_table(accuracy, reset_caches) - for tex in (fixed, best): - assert tex.count(r"\matrixstatus{ReportMuted}{not run}") == 12 - assert tex.count(r"\matrixnotapplicable{ReportMuted}") == 28 - assert "Not run marks an otherwise defined process" in fixed - - n6_family_one = next( - line - for line in fixed.splitlines() - if line.startswith(r"\texttt{1}") - and r"\matrixstatus{ReportMuted}{not run}" in line - ) - assert r"\matrixnotapplicable{ReportMuted}" not in n6_family_one - family_fourteen = next( - line - for line in fixed.splitlines() - if line.startswith(r"\texttt{14}") - and line.count(r"\matrixnotapplicable{ReportMuted}") == 2 - ) - assert r"\matrixstatus{ReportMuted}{not run}" not in family_fourteen - - assert "Fixed-engine tables intentionally omit mode letters" in lc - - -def test_z_reference_execution_is_explicitly_not_exposed(reset_caches) -> None: - tex = render_z_ladder(ModelKey.BUILTIN_SM, reset_caches) - reference_rows = [line for line in tex.splitlines() if r"\AC{} reference" in line] - - assert len(reference_rows) == 9 - for row in reference_rows: - assert row.count(r"\matrixnotexposed{ReportMuted}") == 2 - assert r"\matrixna{ReportMuted}" not in row - assert "not a missing measurement" in tex - - -@pytest.mark.parametrize("model", (ModelKey.BUILTIN_SM, ModelKey.UFO_SM)) -def test_z_native_generation_cap_renders_static_na_in_both_models( - reset_caches, - model: ModelKey, -) -> None: - tex = render_z_ladder(model, reset_caches) - capped_rows = [ - line - for line in tex.splitlines() - if line.startswith(("7 & ", "8 & ", "9 & ")) - and ("compiled ASM O3" in line or "compiled C++ O3" in line) - ] - - assert len(capped_rows) == 6 - assert all(row.count(r"\matrixstaticna{ReportMuted}") == 6 for row in capped_rows) - assert "user cap: native C++/ASM generation is not attempted above n=6" in tex - assert "native-backend-generation-cap-n6-v1" in tex - - -def test_z_evaluator_total_is_mode_independent_and_not_execution_attribution( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_lc") - candidate = _cache_by_dataset(caches, "z_builtin_sm") - for workload in (Workload.SELECTED_FLOW, Workload.ALL_FLOW): - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=1.0, - wall=1.0e-6, - execution=9.0e-6, - ) - modes = ( - ("jit_o1", "compiled", "compiled JIT O1", 31.0, 41.0), - ("eager_jit_o2", "eager", "eager-DAG JIT O2", 32.0, 42.0), - ( - "recurrence_jit_o2", - "recurrence", - "recurrence JIT O2", - 33.0, - 43.0, - ), - ) - entries = candidate["entries"] - assert isinstance(entries, list) - for variant, execution_mode, _label, selected_total, all_total in modes: - for workload, total in ( - (Workload.SELECTED_FLOW, selected_total), - (Workload.ALL_FLOW, all_total), - ): - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=2.0, - wall=(10.0 + total) * 1.0e-6, - execution=(70.0 + total) * 1.0e-6, - variant=variant, - ) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == workload.value - and entry["variant"] == variant - ) - assert isinstance(measurement, dict) - _mark_evaluator_total( - measurement, - execution_mode=execution_mode, - total=total * 1.0e-6, - ) - if execution_mode == "recurrence": - _mark_recurrence_core(measurement) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - for _variant, _mode, label, selected_total, all_total in modes: - row = next( - line - for line in tex.splitlines() - if line.startswith("1 & ") and label in line - ) - assert ( - rf"\texttt{{{selected_total:.0f}}}\," - rf"\matrixratio{{ReportRed}}{{{selected_total:.0f}}}" - ) in row - assert ( - rf"\texttt{{{all_total:.0f}}}\," - rf"\matrixratio{{ReportRed}}{{{all_total:.0f}}}" - ) in row - assert r"\matrixzrecurrenceclocks" not in row - assert r"\matrixtotalevaluator" not in row - assert r"\matrixrecurrencecore" not in row - assert tex.count(r"\textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]}") == 6 - assert r"\textbf{eval total T}" not in tex - assert r"\textbf{rec. core C}" not in tex - assert "original-AmpliCol wall measurement as denominator" in tex - - -def test_z_unverified_retains_absolute_clocks_without_ratios(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "z_builtin_sm") - _set_unverified( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=4.0, - wall=2.0e-6, - evaluator_total=1.0e-6, - variant="jit_o3", - ) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - row = next( - line - for line in tex.splitlines() - if line.startswith("1 & compiled JIT O3") - ) - marker = r"\matrixstatus{ReportOrange}{unverified}" - - for value in ("4.00", "2.00", "1.00"): - assert ( - rf"\matrixruntimepair{{\texttt{{{value}}}}}" - rf"{{{marker}}}" - ) in row - assert row.count(marker) == 3 - assert r"\matrixratio{" not in row - assert "Unverified diagnostics retain absolute clocks" in tex - - -def test_z_wall_and_evaluator_total_keep_distinct_six_digit_values( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_lc") - candidate = _cache_by_dataset(caches, "z_builtin_sm") - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=1.0, - wall=100.0e-6, - execution=90.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=2.0, - wall=218.105e-6, - execution=183.456e-6, - variant="recurrence_jit_o2", - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.SELECTED_FLOW.value - and entry["variant"] == "recurrence_jit_o2" - ) - assert isinstance(measurement, dict) - _mark_evaluator_total( - measurement, - execution_mode="recurrence", - total=217.812e-6, - ) - _mark_recurrence_core(measurement) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - row = next( - line - for line in tex.splitlines() - if line.startswith("1 & ") and "recurrence JIT O2" in line - ) - - assert r"\texttt{218.105}" in row - assert r"\texttt{217.812}\,\matrixratio{ReportRed}{2.18}" in row - assert r"\texttt{183.456}" not in row - assert r"\matrixrecurrencecore" not in row - - -def test_z_historical_recurrence_without_dedicated_total_is_not_exposed( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "z_builtin_sm") - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=2.0, - wall=9.0e-6, - execution=7.0e-6, - variant="recurrence_jit_o2", - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.SELECTED_FLOW.value - and entry["variant"] == "recurrence_jit_o2" - ) - assert isinstance(measurement, dict) - provenance = measurement["provenance"] - assert isinstance(provenance, dict) - provenance["runtime_profile"] = { - "achieved_runtime_seconds": 0.003, - "completed_sample_count": 5, - "interrupted": False, - "measured_point_count": 1000, - "planned_sample_count": 5, - "repetitions_per_sample": 1, - "target_runtime_achieved": True, - "target_runtime_seconds": 0.002, - } - provenance["execution_timing"] = { - "abi": "pyamplicol-report-execution-timing-v1", - "status": "measured", - "ratio_eligible": True, - "raw_seconds_per_point": 7.0e-6, - "source": "runtime_profile_core_recurrence_schedule_time", - "compiled_direct_arena_active": False, - "sample_count": 5, - "native_profile_points_per_sample": 200, - "sample_contract": ("paired_unprofiled_headline_profiled_attribution_v1"), - } - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - row = next( - line - for line in tex.splitlines() - if line.startswith("1 & ") and "recurrence JIT O2" in line - ) - - assert r"\matrixnotexposed{ReportMuted}" in row - assert r"\texttt{7}" not in row - assert r"\matrixzrecurrenceclocks" not in row - - provenance["execution_timing"]["source"] = ( - "runtime_profile_core_evaluator_call_time" - ) - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - row = next( - line - for line in tex.splitlines() - if line.startswith("1 & ") and "recurrence JIT O2" in line - ) - assert r"\matrixnotexposed{ReportMuted}" in row - assert r"\matrixzrecurrenceclocks" not in row - - -def test_visible_completeness_accounts_for_every_n4_slot(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - - summary = summarize_visible_completeness(caches, max_n_final=4) - evidence = summary.as_dict() - - assert summary.complete - assert evidence["required_measurement_count"] == 1042 - assert evidence["rendered_required_measurement_count"] == 1042 - assert evidence["structurally_not_applicable_display_slot_count"] == 486 - assert evidence["not_exposed_display_slot_count"] == 16 - assert evidence["applicable_na_display_slot_count"] == 0 - assert evidence["missing_rendered_cell_count"] == 0 - - -def test_visible_completeness_authenticates_catalog_static_na_slots( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_scope(caches, max_n_final=9) - - summary = summarize_visible_completeness(caches, max_n_final=9) - evidence = summary.as_dict() - - assert summary.complete - assert evidence["declared_measurement_cell_count"] == 2198 - assert evidence["required_measurement_count"] == 2164 - assert evidence["catalog_static_na_cell_count"] == 34 - assert evidence["rendered_catalog_static_na_cell_count"] == 34 - assert evidence["applicable_na_display_slot_count"] == 0 - assert evidence["missing_rendered_cell_count"] == 0 - - -def test_visible_completeness_rejects_na_in_applicable_slot(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - cache = _cache_by_dataset(caches, "z_builtin_sm") - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["n_final"] == 1 - and item["variant"] == "jit_o3" - and item["workload"] == Workload.SELECTED_FLOW.value - ) - measurement = entry["measurement"] - assert isinstance(measurement, dict) - measurement["generation_seconds"] = None - - summary = summarize_visible_completeness(caches, max_n_final=4) - - assert not summary.complete - assert any(entry["cell_id"] in slot for slot in summary.applicable_na_display_slots) - - -def test_na_detector_recognizes_ratio_macro() -> None: - assert report_render._renders_na(r"\matrixnaratio{ReportMuted}") - - -def test_visible_completeness_rejects_missing_candidate_generation_ratio( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - cache = _cache_by_dataset(caches, "matrix_compiled_builtin_sm_full") - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["process_key"] == "dd_z_jets" - and item["n_final"] == 1 - and item["workload"] == Workload.CONTRACTED.value - ) - measurement = entry["measurement"] - assert isinstance(measurement, dict) - measurement["generation_seconds"] = None - - summary = summarize_visible_completeness(caches, max_n_final=4) - - assert not summary.complete - assert any( - entry["cell_id"] in slot and "/candidate" in slot - for slot in summary.applicable_na_display_slots - ) - - -def test_visible_completeness_rejects_non_ok_required_status(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - _fill_visible_n4_scope(caches) - cache = _cache_by_dataset(caches, "z_builtin_sm") - entries = cache["entries"] - assert isinstance(entries, list) - entry = next( - item - for item in entries - if item["n_final"] == 1 - and item["variant"] == "jit_o3" - and item["workload"] == Workload.SELECTED_FLOW.value - ) - measurement = entry["measurement"] - assert isinstance(measurement, dict) - measurement["status"] = ResultStatus.TIMEOUT.value - - summary = summarize_visible_completeness(caches, max_n_final=4) - - assert not summary.complete - assert not any( - entry["cell_id"] in slot for slot in summary.applicable_na_display_slots - ) - assert any( - entry["cell_id"] in error - and repr(ResultStatus.TIMEOUT.value) in error - and repr(ResultStatus.OK.value) in error - for error in summary.contract_errors - ) - - -def test_adapter_joins_recurrence_baseline_without_copying_timing( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - candidate = _cache_by_dataset( - caches, - "matrix_compiled_builtin_sm_nlc", - ) - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.5e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=1.0e-6, - execution=0.5e-6, - ) - - dataset = REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc") - family = REPORT_CATALOG.process_families[0] - joined = BaselineCandidateAdapter(caches).matrix_cell(dataset, family, 1) - tex = render_matrix_table(dataset, caches) - - assert joined.workloads[0].baseline is not joined.workloads[0].candidate - assert joined.workloads[0].baseline["generation_seconds"] == 4.0 - assert r"\texttt{4.00}" in tex - assert r"\bestmoderatio{ReportGreen}{0.500}" in tex - - -def test_recurrence_matrix_cell_uses_compact_wall_and_core_ratios( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_nlc") - candidate = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=100.0e-6, - execution=90.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=218.105e-6, - execution=183.456e-6, - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - assert isinstance(measurement, dict) - _mark_evaluator_total( - measurement, - execution_mode="recurrence", - total=217.812e-6, - ) - _mark_recurrence_core(measurement) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_nlc"), - caches, - ) - - assert r"\bestmodecompactprefix{2.04}" in tex - assert r"\bestmodeprimaryratio{ReportRed}{2.18}" in tex - assert r"\texttt{217.812}" not in tex - assert r"\texttt{183.456}" not in tex - assert r"\matrixruntimetriple{" not in tex - assert "An evaluator total is never divided by a recurrence core" in tex - - -def test_unavailable_execution_keeps_only_compact_wall_ratio( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - candidate = _cache_by_dataset( - caches, - "matrix_compiled_builtin_sm_nlc", - ) - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=1.0e-6, - execution=None, - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - _mark_arena_unavailable(measurement) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc"), - caches, - ) - - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - assert r"\bestmodeopenprefix" not in runtime_row - assert r" & & \bestmodewallratio{ReportGreen}{0.500}" in runtime_row - assert r"\matrixruntimepair{" not in tex - assert r"\matrixtotalevaluator{" not in tex - assert r"{x0}" not in tex - - -@pytest.mark.parametrize("execution_mode", ("compiled", "eager")) -def test_dag_matrix_never_divides_evaluator_total_by_recurrence_core( - reset_caches, - execution_mode: str, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - dataset_id = ( - "matrix_compiled_builtin_sm_nlc" - if execution_mode == "compiled" - else "matrix_eager_builtin_sm_nlc" - ) - candidate = _cache_by_dataset(caches, dataset_id) - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=1.0e-6, - execution=None, - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - _mark_arena_unavailable(measurement, execution_mode=execution_mode) - _mark_evaluator_total( - measurement, - execution_mode=execution_mode, - total=0.9e-6, - ) - - tex = render_matrix_table(REPORT_CATALOG.dataset(dataset_id), caches) - - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - assert r"\bestmodeopenprefix" not in runtime_row - assert r" & & \bestmodewallratio{ReportGreen}{0.500}" in runtime_row - assert r"\bestmodecompactprefix{0.900}" not in runtime_row - assert r"\texttt{0.900}" not in tex - assert r"\matrixtotalevaluator{" not in tex - assert r"\matrixruntimetriple{" not in tex - - -@pytest.mark.parametrize("execution_mode", ("compiled", "eager")) -def test_dag_matrix_prefers_authenticated_evaluator_total_pair( - reset_caches, - execution_mode: str, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - dataset_id = ( - "matrix_compiled_builtin_sm_nlc" - if execution_mode == "compiled" - else "matrix_eager_builtin_sm_nlc" - ) - candidate = _cache_by_dataset(caches, dataset_id) - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=1.0e-6, - execution=None, - ) - baseline_measurement = next( - entry["measurement"] - for entry in baseline["entries"] - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - candidate_measurement = next( - entry["measurement"] - for entry in candidate["entries"] - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - assert isinstance(baseline_measurement, dict) - assert isinstance(candidate_measurement, dict) - _mark_evaluator_total( - baseline_measurement, - execution_mode="recurrence", - total=1.8e-6, - ) - _mark_arena_unavailable( - candidate_measurement, - execution_mode=execution_mode, - ) - _mark_evaluator_total( - candidate_measurement, - execution_mode=execution_mode, - total=0.9e-6, - ) - - tex = render_matrix_table(REPORT_CATALOG.dataset(dataset_id), caches) - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - - assert r"\bestmodecompactprefix{0.500}" in runtime_row - assert r"\bestmodeprimaryratio{ReportGreen}{0.500}" in runtime_row - assert r"\bestmodecompactprefix{0.900}" not in runtime_row - assert "evaluator-total fallback is diagnostic only" in tex - - -@pytest.mark.parametrize("execution_mode", ("compiled", "eager")) -@pytest.mark.parametrize( - ("legacy_execution", "expected_secondary"), - ((1.5e-6, "0.600"), (None, "0.450")), -) -def test_best_mode_uses_candidate_total_against_legacy_direct_or_wall( - reset_caches, - execution_mode: str, - legacy_execution: float | None, - expected_secondary: str, -) -> None: - caches = copy.deepcopy(reset_caches) - reference = _cache_by_dataset(caches, "reference_amplicol_nlc") - recurrence = _cache_by_dataset(caches, "matrix_recurrence_builtin_sm_nlc") - candidate = _cache_by_dataset( - caches, - f"matrix_{execution_mode}_builtin_sm_nlc", - ) - _set_ok( - reference, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - execution=legacy_execution, - ) - _set_ok( - recurrence, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=3.0, - wall=1.5e-6, - execution=1.2e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=2.0, - wall=1.0e-6, - execution=None, - ) - candidate_measurement = next( - entry["measurement"] - for entry in candidate["entries"] - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - assert isinstance(candidate_measurement, dict) - _mark_arena_unavailable( - candidate_measurement, - execution_mode=execution_mode, - ) - _mark_evaluator_total( - candidate_measurement, - execution_mode=execution_mode, - total=0.9e-6, - ) - - tex = render_best_mode_table(Accuracy.NLC, caches) - runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - ) - - assert rf"\bestmodecompactprefix{{{expected_secondary}}}" in runtime_row - assert r"\bestmodeprimaryratio{ReportGreen}{0.500}" in runtime_row - assert "evaluator-total fallback is diagnostic only" in tex - assert "uses the AmpliCol direct execution clock" in tex - - -@pytest.mark.parametrize( - "surface", - ("z_builtin_sm", "scalar_contact", "scalar_gravity"), -) -def test_ladders_render_generic_presentation_outcomes_through_shared_status_path( - reset_caches, - surface: str, -) -> None: - caches = copy.deepcopy(reset_caches) - cache = _cache_by_dataset(caches, surface) - if surface == "z_builtin_sm": - _set_presentation_outcome( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - outcome="dependency_backend_error", - variant="jit_o3", - ) - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - else: - _set_presentation_outcome( - cache, - process_key=surface, - n_final=2, - workload=Workload.CONTRACTED, - outcome="dependency_backend_error", - ) - dataset = next( - item - for item in REPORT_CATALOG.scalar_datasets - if item.dataset_id == surface - ) - tex = render_scalar_ladder(dataset, caches) - - display = report_render._compact_terminal_display( - report_render._TerminalOutcome( - identity="presentation:dependency_backend_error", - label="dependency backend error", - color="ReportRed", - ) - ) - marker = rf"\matrixstatus{{ReportRed}}{{{display}}}" - assert tex.count(marker) >= 3 - assert "dependency backend error" not in tex - assert r"\matrixstatus{ReportOrange}{dependency backend error}" not in tex - assert "dependency_backend_error" not in tex - - -def test_z_ladder_prints_not_exposed_instead_of_zero( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_lc") - candidate = _cache_by_dataset(caches, "z_builtin_sm") - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=4.0, - wall=2.0e-6, - execution=1.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - generation=2.0, - wall=1.0e-6, - execution=None, - variant="jit_o3", - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["variant"] == "jit_o3" - and entry["workload"] == Workload.SELECTED_FLOW.value - ) - _mark_arena_unavailable(measurement) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - - assert r"\matrixnotexposed{ReportMuted}" in tex - assert r"{x0}" not in tex - - -def test_unavailable_execution_is_not_treated_as_a_summary_ratio( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_nlc", - ) - candidate = _cache_by_dataset( - caches, - "matrix_compiled_builtin_sm_nlc", - ) - for cache, execution in ((baseline, 4.0e-7), (candidate, None)): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.CONTRACTED, - generation=1.0, - wall=1.0e-6, - execution=execution, - ) - entries = candidate["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == "dd_z_jets" - and entry["n_final"] == 1 - and entry["workload"] == Workload.CONTRACTED.value - ) - _mark_arena_unavailable(measurement) - dataset = REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_nlc") - view = BaselineCandidateAdapter(caches).matrix_cell( - dataset, - REPORT_CATALOG.process_families[0], - 1, - ) - - summary = report_render._summary_pair( - (view,), - Workload.CONTRACTED, - "execution_seconds_per_point", - ) - - assert summary == r"\matrixnotexposed{ReportMuted}" - - -def test_adapter_joins_original_amplicol_for_primary_recurrence( - reset_caches, -) -> None: - dataset = REPORT_CATALOG.dataset("matrix_recurrence_ufo_sm_full") - family = REPORT_CATALOG.process_families[0] - adapter = BaselineCandidateAdapter(reset_caches) - joined = adapter.matrix_cell(dataset, family, 1) - reference = adapter.index.get( - "reference_amplicol_full", - family.key, - 1, - Workload.CONTRACTED, - ) - - assert joined.workloads[0].baseline is reference - - -def test_lc_cells_join_two_layout_specific_baselines(reset_caches) -> None: - dataset = REPORT_CATALOG.dataset("matrix_eager_builtin_sm_lc") - family = REPORT_CATALOG.process_families[0] - joined = BaselineCandidateAdapter(reset_caches).matrix_cell( - dataset, - family, - 1, - ) - - assert tuple(item.workload for item in joined.workloads) == ( - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - ) - - -def test_amplicol_all_flow_setup_generation_ratio_is_not_comparable( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_lc") - candidate = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_lc", - ) - for workload, baseline_generation, candidate_generation in ( - (Workload.SELECTED_FLOW, 2.0, 4.0), - (Workload.ALL_FLOW, 1.0e-4, 10.0), - ): - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=baseline_generation, - wall=2.0e-6, - execution=1.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=candidate_generation, - wall=1.0e-6, - execution=0.5e-6, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_lc"), - caches, - ) - - assert tex.count(r"\bestmodeabsoluteprefix{\texttt{10.0}}") == 1 - generation_summary = next( - line for line in tex.splitlines() if r"\textbf{summary: generation}" in line - ) - assert r"\texttt{10}" not in generation_summary - assert r"\matrixratio{ReportRed}{1e+05}" not in tex - assert "setup boundary differs from the reference" in tex - assert "n.c." not in tex - - -def test_four_line_recurrence_renders_absolute_values_without_legacy_oracle( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_lc", - ) - for workload, generation in ( - (Workload.SELECTED_FLOW, 4.0), - (Workload.ALL_FLOW, 10.0), - ): - _set_ok( - candidate, - process_key="dd_4q_lines", - n_final=6, - workload=workload, - generation=generation, - wall=2.0e-6, - execution=1.0e-6, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_lc"), - caches, - ) - - assert r"\bestmodeabsoluteprefix{\texttt{4.00}}" in tex - assert r"\bestmodeabsoluteprefix{\texttt{10.0}}" in tex - assert tex.count(r"\texttt{2.00}") >= 2 - assert r"\matrixruntimetriple{" not in tex - assert tex.count(r"\matrixstaticna{ReportMuted}") >= 2 - assert "static N/A beyond three open quark lines" in tex - assert "n.c." not in tex - - -def test_four_line_contracted_n6_renders_without_legacy_dependency( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_full", - ) - _set_ok( - candidate, - process_key="dd_4q_lines", - n_final=6, - workload=Workload.CONTRACTED, - generation=12.0, - wall=2.0e-6, - execution=1.0e-6, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_recurrence_builtin_sm_full"), - caches, - ) - - assert r"\textbf{n=6}" in tex - fixed_generation_row = next( - line - for line in tex.splitlines() - if line.startswith(r"\texttt{14}") - and r"\bestmodeabsoluteprefix{\texttt{12.0}}" in line - ) - fixed_runtime_row = next( - line - for line in tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - and r"\bestmodeabsoluteprefix{\texttt{2.00}}" in line - ) - assert ( - r"\matrixstaticna{ReportMuted} & " - r"\bestmodeabsoluteprefix{\texttt{12.0}} & " - ) in fixed_generation_row - assert ( - r"\matrixstaticna{ReportMuted} & " - r"\bestmodeabsoluteprefix{\texttt{2.00}} & " - ) in fixed_runtime_row - assert r"\matrixstaticna{ReportMuted}" in tex - assert "static N/A beyond three open quark lines" in tex - assert "n.c." not in tex - - best_tex = render_best_mode_table(Accuracy.FULL, caches) - best_generation_row = next( - line - for line in best_tex.splitlines() - if line.startswith(r"\texttt{14}") - and r"\bestmodeabsoluteprefix{\texttt{12.0}}" in line - ) - best_runtime_row = next( - line - for line in best_tex.splitlines() - if line.startswith(r" & & \textcolor{ReportMuted}{\scriptsize run") - and r"\bestmodeabsoluteprefix{\texttt{2.00}}" in line - ) - assert ( - r"\matrixstaticna{ReportMuted} & " - r"\bestmodeabsoluteprefix{\texttt{12.0}} & \bestmodecode{r}" - ) in best_generation_row - assert ( - r"\matrixstaticna{ReportMuted} & " - r"\bestmodeabsoluteprefix{\texttt{2.00}} & " - ) in best_runtime_row - assert r"\bestmodecode" not in best_runtime_row - - -def test_z_all_flow_setup_generation_ratio_is_not_comparable( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset(caches, "reference_amplicol_lc") - candidate = _cache_by_dataset(caches, "z_builtin_sm") - for workload, baseline_generation, candidate_generation in ( - (Workload.SELECTED_FLOW, 2.0, 4.0), - (Workload.ALL_FLOW, 1.0e-4, 10.0), - ): - _set_ok( - baseline, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=baseline_generation, - wall=2.0e-6, - execution=1.0e-6, - ) - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=candidate_generation, - wall=1.0e-6, - execution=0.5e-6, - variant="jit_o3", - ) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - - assert r"\matrixncabsolute{\texttt{10}}" in tex - assert r"\matrixratio{ReportRed}{1e+05}" not in tex - assert "setup boundary differs from the reference" in tex - assert "n.c." not in tex - - -def test_cross_mode_all_flow_generation_ratio_remains_layout_matched( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - baseline = _cache_by_dataset( - caches, - "matrix_recurrence_builtin_sm_lc", - ) - candidate = _cache_by_dataset(caches, "matrix_compiled_builtin_sm_lc") - for cache, generation in ((baseline, 4.0), (candidate, 2.0)): - _set_ok( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.ALL_FLOW, - generation=generation, - wall=2.0e-6, - execution=1.0e-6, - ) - - tex = render_matrix_table( - REPORT_CATALOG.dataset("matrix_compiled_builtin_sm_lc"), - caches, - ) - - assert r"\bestmoderatio{ReportGreen}{0.500}" in tex - assert r"\matrixncabsolute{\texttt" not in tex - - -def test_two_z_ladders_use_single_line_mode_labels(reset_caches) -> None: - rendered = render_all_z_ladders(reset_caches) - - assert list(rendered) == [ - "result_z_builtin_sm_table.tex", - "result_z_external_sm_table.tex", - ] - for tex in rendered.values(): - assert "longtable" not in tex - assert "eager-DAG JIT O2" in tex - assert "recurrence JIT O2" in tex - assert "on-the-fly JIT O2" in tex - assert "eager-DAG JIT O2\\\\" not in tex - assert "recurrence JIT O2\\\\" not in tex - assert "on-the-fly JIT O2\\\\" not in tex - assert r"\begin{minipage}{\linewidth}" in tex - assert tex.index(r"\clearpage") < tex.index(r"\subsection{") - assert tex.index(r"\subsection{") < tex.index( - r"\noindent\begin{minipage}{\linewidth}" - ) - - -def test_z_on_the_fly_row_keeps_cold_start_generation_pair(reset_caches) -> None: - caches = copy.deepcopy(reset_caches) - candidate = _cache_by_dataset(caches, "z_builtin_sm") - for workload in (Workload.SELECTED_FLOW, Workload.ALL_FLOW): - _set_ok( - candidate, - process_key="dd_z_jets", - n_final=1, - workload=workload, - generation=1.0, - wall=2.0e-6, - execution=1.0e-6, - variant="on_the_fly_jit_o2", - ) - - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - row = next( - line - for line in tex.splitlines() - if line.startswith("1 & on-the-fly JIT O2") - ) - - assert row.count(r"\bestmodecompactabsolute{1.00}{1.25}") == 2 - assert r"\matrixstaticna{ReportMuted}" not in row - assert "one compact query-local process seed" in tex - assert r"absolute \texttt{[G] G+W} pair" in tex - - -def test_dense_scalar_ladder_fits_narrower_columns(reset_caches) -> None: - dataset = next( - item - for item in REPORT_CATALOG.scalar_datasets - if item.dataset_id == "scalar_contact" - ) - - tex = render_scalar_ladder(dataset, reset_caches) - - assert r"@{}L{1.00in}" in tex - assert tex.count(r"L{0.72in}") == len(dataset.multiplicities) - assert r"\setlength{\tabcolsep}{2.2pt}" in tex - assert ( - r"{\fontsize{6.4pt}{7.4pt}\selectfont" - r"\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}} & " - in tex - ) - assert ( - "\nevaluator total " r"[\(\mu\mathrm{s}/\mathrm{pt}\)] & " - not in tex - ) - - -@pytest.mark.parametrize("dataset_id", ("scalar_contact", "scalar_gravity")) -def test_scalar_timing_marks_unavailable_arena_attribution_not_exposed( - reset_caches, - dataset_id: str, -) -> None: - caches = copy.deepcopy(reset_caches) - dataset = next( - item for item in REPORT_CATALOG.scalar_datasets if item.dataset_id == dataset_id - ) - cache = _cache_by_dataset(caches, dataset_id) - _set_ok( - cache, - process_key=dataset_id, - n_final=2, - workload=Workload.CONTRACTED, - generation=1.0, - wall=1.0e-6, - execution=None, - ) - entries = cache["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] for entry in entries if entry["n_final"] == 2 - ) - _mark_arena_unavailable(measurement) - - tex = render_scalar_ladder(dataset, caches) - - assert ( - r"{\fontsize{6.4pt}{7.4pt}\selectfont" - r"\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}}" - in tex - ) - assert r"\matrixnotexposed{ReportMuted}" in tex - assert "successful wall measurement" in tex - - -def test_scalar_timing_uses_dedicated_evaluator_total_not_wall( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - dataset = next( - item - for item in REPORT_CATALOG.scalar_datasets - if item.dataset_id == "scalar_contact" - ) - cache = _cache_by_dataset(caches, "scalar_contact") - _set_ok( - cache, - process_key="scalar_contact", - n_final=2, - workload=Workload.CONTRACTED, - generation=1.0, - wall=218.105e-6, - execution=None, - ) - entries = cache["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] for entry in entries if entry["n_final"] == 2 - ) - assert isinstance(measurement, dict) - _mark_arena_unavailable(measurement) - _mark_evaluator_total( - measurement, - execution_mode="compiled", - total=217.812e-6, - ) - - tex = render_scalar_ladder(dataset, caches) - wall_row = next( - line - for line in tex.splitlines() - if line.startswith(r"wall [\(\mu\mathrm{s}/\mathrm{pt}\)]") - ) - total_row = next( - line - for line in tex.splitlines() - if line.startswith( - r"{\fontsize{6.4pt}{7.4pt}\selectfont" - r"\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}}" - ) - ) - - assert r"\texttt{218.105}" in wall_row - assert r"\texttt{217.812}" in total_row - assert r"\texttt{218.105}" not in total_row - assert r"execution [\(\mu\mathrm{s}/\mathrm{pt}\)]" not in tex - assert "never copied from or derived from wall time" in tex - - -@pytest.mark.parametrize("dataset_id", ("scalar_contact", "scalar_gravity")) -def test_scalar_unverified_retains_absolute_clocks_with_marker( - reset_caches, - dataset_id: str, -) -> None: - caches = copy.deepcopy(reset_caches) - dataset = next( - item for item in REPORT_CATALOG.scalar_datasets if item.dataset_id == dataset_id - ) - cache = _cache_by_dataset(caches, dataset_id) - _set_unverified( - cache, - process_key=dataset_id, - n_final=2, - workload=Workload.CONTRACTED, - generation=4.0, - wall=2.0e-6, - evaluator_total=1.0e-6, - ) - - tex = render_scalar_ladder(dataset, caches) - marker = r"\matrixstatus{ReportOrange}{unverified}" - expected = { - "generation [s]": "4.00", - r"wall [\(\mu\mathrm{s}/\mathrm{pt}\)]": "2.00", - ( - r"{\fontsize{6.4pt}{7.4pt}\selectfont" - r"\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}}" - ): "1.00", - } - for prefix, value in expected.items(): - row = next(line for line in tex.splitlines() if line.startswith(prefix)) - assert ( - rf"\matrixruntimepair{{\texttt{{{value}}}}}" - rf"{{{marker}}}" - ) in row - assert r"\matrixratio{" not in tex - assert "Unverified diagnostics retain absolute generation" in tex - - -@pytest.mark.parametrize("surface", ("z_builtin_sm", "scalar_contact")) -def test_ladder_presentation_only_unverified_is_orange( - reset_caches, - surface: str, -) -> None: - caches = copy.deepcopy(reset_caches) - cache = _cache_by_dataset(caches, surface) - if surface == "z_builtin_sm": - _set_presentation_outcome( - cache, - process_key="dd_z_jets", - n_final=1, - workload=Workload.SELECTED_FLOW, - outcome="unverified", - variant="jit_o3", - ) - tex = render_z_ladder(ModelKey.BUILTIN_SM, caches) - else: - _set_presentation_outcome( - cache, - process_key=surface, - n_final=2, - workload=Workload.CONTRACTED, - outcome="unverified", - ) - dataset = next( - item - for item in REPORT_CATALOG.scalar_datasets - if item.dataset_id == surface - ) - tex = render_scalar_ladder(dataset, caches) - - assert r"\matrixstatus{ReportOrange}{unverified}" in tex - assert r"\matrixstatus{ReportRed}{unverified}" not in tex - - -def test_all_outputs_include_matrices_z_and_scalar_ladders( - reset_caches, -) -> None: - rendered = render_all_tables(reset_caches) - - assert len(rendered) == 27 - assert "result_validation_summary.tex" in rendered - assert set(render_all_best_mode_tables(reset_caches)) < set(rendered) - assert set(render_all_matrix_tables(reset_caches)) < set(rendered) - assert set(render_all_z_ladders(reset_caches)) < set(rendered) - assert "result_scalar_contact_table.tex" in rendered - assert "result_scalar_gravity_table.tex" in rendered - - -def test_validation_summary_counts_complete_scope_and_comparison_kinds( - reset_caches, -) -> None: - caches = copy.deepcopy(reset_caches) - revision = "0123456789abcdef0123456789abcdef01234567" - records = ( - ( - "reference_amplicol_lc", - "dd_z_jets", - 1, - Workload.SELECTED_FLOW, - { - "status": "ok", - "method": "independent-original-amplicol-oracle", - }, - ), - ( - "reference_amplicol_lc", - "dd_z_jets", - 1, - Workload.ALL_FLOW, - { - "status": "ok", - "method": "independent-original-amplicol-oracle", - }, - ), - ( - "matrix_recurrence_builtin_sm_lc", - "dd_z_jets", - 1, - Workload.SELECTED_FLOW, - { - "status": "ok", - "pointwise": { - "status": "validation_failed", - "relative_difference": 1.0e-5, - "relative_tolerance": 1.0e-8, - }, - "resolved_sum": { - "status": "ok", - "maximum_relative_difference": 2.0e-13, - }, - }, - ), - ( - "matrix_recurrence_builtin_sm_lc", - "dd_z_jets", - 1, - Workload.ALL_FLOW, - { - "status": "ok", - "direct_agreements": [ - { - "edge_kind": LC_LEGACY_PYAMPLICOL_COMPONENT, - "status": "ok", - "relative_difference": 8.0e-9, - "relative_tolerance": 1.0e-8, - } - ], - "resolved_sum": { - "status": "ok", - "maximum_relative_difference": 1.0e-13, - }, - }, - ), - ( - "matrix_compiled_builtin_sm_lc", - "dd_z_jets", - 1, - Workload.SELECTED_FLOW, - { - "status": "ok", - "pointwise": { - "status": "ok", - "relative_difference": 3.0e-13, - }, - "resolved_sum": { - "status": "ok", - "maximum_relative_difference": 4.0e-14, - }, - }, - ), - ( - "reference_madgraph_full", - "dd_z_jets", - 1, - Workload.CONTRACTED, - { - "status": "ok", - "method": "independent-madgraph-tree-level-oracle", - }, - ), - ( - "matrix_recurrence_ufo_sm_full", - "dd_z_jets", - 1, - Workload.CONTRACTED, - { - "status": "ok", - "madgraph_comparison": { - "status": "ok", - "relative_difference": 7.0e-12, - "relative_tolerance": 1.0e-10, - }, - "high_precision": { - "status": "ok", - "relative_difference": 4.0e-14, - }, - "resolved_sum": { - "status": "ok", - "maximum_relative_difference": 7.0e-14, - }, - }, - ), - ( - "scalar_contact", - "scalar_contact", - 2, - Workload.CONTRACTED, - { - "status": "ok", - "high_precision": { - "status": "ok", - "relative_difference": 5.0e-14, - }, - "resolved_sum": { - "status": "ok", - "maximum_relative_difference": 6.0e-14, - }, - }, - ), - ) - for dataset_id, process_key, n_final, workload, validation in records: - cache = _cache_by_dataset(caches, dataset_id) - _set_ok( - cache, - process_key=process_key, - n_final=n_final, - workload=workload, - generation=1.0, - wall=1.0e-6, - execution=5.0e-7, - ) - entries = cache["entries"] - assert isinstance(entries, list) - measurement = next( - entry["measurement"] - for entry in entries - if entry["process_key"] == process_key - and entry["n_final"] == n_final - and entry["workload"] == workload.value - ) - measurement["validation"] = validation - measurement["provenance"] = { - "report_measured_source_revision": revision, - } - - summary = summarize_validation(caches) - tex = render_validation_summary(caches) - - assert r"\begin{tabular}{@{}l r r r l@{}}" in tex - assert summary.expected_by_n == ( - (1, 84), - (2, 254), - (3, 282), - (4, 422), - (5, 393), - (6, 223), - (7, 169), - (8, 169), - (9, 168), - ) - assert summary.declared_total == 2198 - assert summary.static_na_by_n == ( - (1, 0), - (2, 0), - (3, 0), - (4, 0), - (5, 0), - (6, 4), - (7, 10), - (8, 10), - (9, 10), - ) - assert summary.static_na_total == 34 - assert summary.expected_total == 2164 - assert summary.passed_total == 8 - assert summary.status_counts == ( - ("not_available", 2156), - ("ok", 8), - ("static-na", 34), - ) - assert summary.madgraph_reference_count == 1 - assert summary.madgraph_comparison_count == 1 - assert summary.madgraph_comparison_maximum_relative_difference == 7.0e-12 - assert summary.legacy_reference_count == 2 - assert summary.legacy_comparison_pass_count == 1 - assert summary.legacy_comparison_failure_count == 1 - assert summary.legacy_comparison_maximum_relative_difference == 1.0e-5 - assert summary.cross_mode_count == 1 - assert summary.cross_mode_maximum_relative_difference == 3.0e-13 - assert summary.resolved_count == 5 - assert summary.resolved_maximum_relative_difference == 2.0e-13 - assert summary.high_precision_count == 2 - assert summary.high_precision_maximum_relative_difference == 5.0e-14 - assert summary.uniform_source_revision == revision - assert "2198 & 34 & 8" in tex - assert "2198 declared cells" in tex - assert "2164 measurable cells" in tex - assert "34 catalog-authenticated static N/A" in tex - assert "659 matrix process/multiplicity positions" in tex - assert "36 reference execution fields" in tex - assert "MadGraph standalone tree-level reference records & 1" in tex - assert r"\PAC{} versus MadGraph binary64 (p200; OTF p16) & 1" in tex - assert r"original-\AC{} legacy diagnostic records & 2" in tex - assert r"\PAC{} versus original-\AC{} legacy diagnostic & 1 pass, 1 mismatch" in tex - assert r"relative tolerance of \(10^{-10}\)" in tex - assert "legacy mismatch does not invalidate a candidate" in tex - assert "independent original" not in tex - assert rf"\nolinkurl{{{revision}}}" in tex diff --git a/pyamplicol/tests/unit/test_three_mode_report_runner.py b/pyamplicol/tests/unit/test_three_mode_report_runner.py deleted file mode 100644 index 0851e5f878..0000000000 --- a/pyamplicol/tests/unit/test_three_mode_report_runner.py +++ /dev/null @@ -1,3034 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import hashlib -import json -import os -from contextlib import contextmanager -from dataclasses import dataclass -from pathlib import Path -from types import SimpleNamespace - -import pytest - -from pyamplicol.generation.artifact_writer import _evaluator as _serialize_evaluator -from tools.performance_report.arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - EMPTY_ARENA_PHASE_VECTOR_FIELDS, - ZERO_ARENA_COUNTER_FIELDS, - ZERO_ARENA_PHASE_TIME_FIELDS, - ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS, - ArenaProfileEvidenceError, - build_arena_profile_evidence, - digest_arena_profile_value, - validate_arena_profile_evidence, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ( - Accuracy, - CellSpec, - ExecutionMode, - Workload, -) -from tools.performance_report.runner import ( - LOADED_RUNTIME_PROFILE_COMMAND_PATH, - PAIRED_ARENA_PROFILE_COMMAND_PATH, - PRECOMPILED_GENERATION_COMMAND_PATH, - PUBLIC_CLI_COMMAND_PATH, - ProfilingTimeLimitError, - RunnerError, - RunnerSettings, - SelectorContract, - _artifact_numerical_relation_metadata, - _authenticated_direct_codegen_identity, - _authenticated_effective_config, - _authenticated_recurrence_source_identity, - _authenticated_symjit_plane_leaves, - _benchmark_measurement, - _calibrate_arena_repetitions, - _real_nonnegative, - _regular_file_identity, - _run_arena_benchmark, - _run_report_benchmark, - _selector_kwargs, - config_values, - derive_selector_contract, - generate_artifact, - point_digest, - pointwise_validation, - profiling_chunk_guard, - provenance_payload, - resolved_sum_validation, - runtime_identity_payload, - validate_artifact_contract, - validate_runtime_contract, - validate_selector_contract, -) - - -def test_provenance_payload_records_measurement_numpy( - monkeypatch: pytest.MonkeyPatch, -) -> None: - class Numpy: - __version__ = "2.4.2-measurement" - - monkeypatch.setattr( - "tools.performance_report.runner.importlib.import_module", - lambda name: Numpy() if name == "numpy" else None, - ) - - provenance = provenance_payload() - - assert provenance["numpy"] == "2.4.2-measurement" - assert provenance["python_implementation"] - - -def test_profiling_chunk_guard_rejects_only_chunks_larger_than_remaining() -> None: - guard = profiling_chunk_guard(10.0, clock=lambda: 9.0) - - assert guard is not None - guard(None, "one-point probe") - guard(1.0, "exactly fitting chunk") - with pytest.raises(ProfilingTimeLimitError, match=r"estimated=1\.00001s"): - guard(1.00001, "oversized chunk") - - -def test_profiling_chunk_guard_rejects_launch_after_deadline() -> None: - guard = profiling_chunk_guard(10.0, clock=lambda: 10.0) - - assert guard is not None - with pytest.raises(ProfilingTimeLimitError, match="remaining=0s"): - guard(None, "one-point probe") - - -def test_artifact_numerical_relation_metadata_preserves_fallback( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import pyamplicol.artifacts as artifacts - from pyamplicol.generation.recurrence_numerical_current_warmup import ( - RecurrenceNumericalEvidenceGeometry, - ) - - geometry = RecurrenceNumericalEvidenceGeometry.from_counts( - current_count=4, - component_count=4, - candidate_probe_count=2, - verification_probe_count=2, - runtime_parameter_count=2, - ) - relation_report = { - "requested_mode": "certified-reuse", - "effective_mode": "off", - "effective_reuse_state": "disabled", - "certified_relation_count": 0, - "applied_relation_count": 0, - "relation_correctness": { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - }, - "fallback": { - "reason": "evidence-envelope-fallback", - "memory_envelope_bytes": 1, - "spooled_producer_resident_bytes": ( - geometry.spooled_producer_resident_upper_bound() - ), - "geometry": geometry.to_json_dict(), - }, - } - manifest = SimpleNamespace( - extensions={ - "generation": { - "concrete_processes": [ - { - "id": "process", - "filters": {"relation_discovery": relation_report}, - } - ] - } - } - ) - loads: list[tuple[Path, bool]] = [] - - def load_manifest(path: Path, *, verify_payloads: bool) -> object: - loads.append((path, verify_payloads)) - return manifest - - monkeypatch.setattr(artifacts, "load_manifest", load_manifest) - - correctness, fallback = _artifact_numerical_relation_metadata( - tmp_path / "artifact", - "process", - ) - - assert loads == [(tmp_path / "artifact", False)] - assert correctness["state"] == "no-applied-relations" - assert fallback == { - "abi": "pyamplicol-numerical-current-reuse-fallback-v1", - "requested_mode": "certified-reuse", - "effective_mode": "off", - "effective_reuse_state": "disabled", - "reason": "evidence-envelope-fallback", - "geometry": geometry.to_json_dict(), - "certified_relation_count": 0, - "applied_relation_count": 0, - } - - -def _raw_arena_profile( - *, - execution_mode: str = "compiled", - points: int = 128, - wall_time: float = 1.1e-6 * 128, -) -> dict[str, object]: - profile: dict[str, object] = { - "execution_mode": execution_mode, - "profile_boundary": ARENA_PROFILE_BOUNDARY, - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "evaluator_timing_available": False, - "points": points, - "wall_time_s": wall_time, - "orchestration_time_s": wall_time, - **{field: 0 for field in ZERO_ARENA_COUNTER_FIELDS}, - **{field: 0.0 for field in ZERO_ARENA_PHASE_TIME_FIELDS}, - **{field: [] for field in EMPTY_ARENA_PHASE_VECTOR_FIELDS}, - **{field: 0 for field in ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS}, - "state_component_count": 11, - "source_component_count": 7, - } - if execution_mode == "compiled": - profile.update( - { - "compiled_direct_arena_engine_count": 2, - "compiled_direct_arena_call_count": 3, - "evaluator_backend_call_count": 3, - } - ) - return profile - - -def _benchmark_fixture( - *, - arena_authenticated: bool = True, - execution_mode: str = "compiled", -) -> SimpleNamespace: - evidence = build_arena_profile_evidence( - (_raw_arena_profile(execution_mode=execution_mode),) * 5, - execution_mode=execution_mode, - repetitions_per_profile=1, - batch_size=128, - ) - return SimpleNamespace( - uncertainty=SimpleNamespace( - standard_error=1.0e-9, - relative_standard_error=0.01, - ), - wall_time_per_point=1.0e-6, - evaluator_time_per_point=None, - sample_count=5, - effective_config=SimpleNamespace(target_runtime=5.0), - timing_breakdown=SimpleNamespace( - wall_time=SimpleNamespace( - mean_seconds_per_point=evidence[ - "warmed_boundary_wall_seconds_per_point" - ] - ), - evaluator_call_time=None, - ), - arena_profile_evidence=evidence, - environment={ - "evaluator_time_raw_seconds_per_point": None, - "evaluator_time_status": "unavailable", - "evaluator_time_ratio_eligible": False, - "evaluator_time_sample_pass": "runtime._profile_arena_repeated", - "timing_breakdown_sample_pass": "runtime._profile_arena_repeated", - "profile_protocol": "arena", - "report_command_path": PAIRED_ARENA_PROFILE_COMMAND_PATH, - "report_public_cli_path": None, - "profile_attribution_boundary": ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" - ), - "profile_attribution_borrowed_flat_input": arena_authenticated, - "profile_attribution_preallocated_output": True, - "profile_attribution_phase_timing_scope": ("coarse-arena-boundary-only-v1"), - "profile_attribution_evaluator_timing_available": False, - "profile_attribution_paired_with_headline": True, - "profile_attribution_identical_batch": True, - "profile_attribution_identical_repetitions": True, - "execution_mode": execution_mode, - "evaluator_sample_count": 5, - "native_profile_points_per_sample": 128, - "native_profile_repetitions_per_sample": 1, - "native_profile_batch_size": 128, - "timing_sample_contract": ( - "paired_unprofiled_headline_profiled_attribution_v1" - ), - "elapsed_seconds": 5.0, - "completed_sample_count": 5, - "planned_sample_count": 5, - "repetitions_per_sample": 128, - "measured_point_count": 640, - "interrupted": False, - }, - ) - - -def test_benchmark_measurement_records_authenticated_arena_unavailable_timing() -> None: - measurement = _benchmark_measurement( - _benchmark_fixture(), - matrix_element=2.0, - ) - - assert measurement["execution_seconds_per_point"] is None - assert measurement["evaluator_total_timing"] is None - assert measurement["execution_timing"] == { - "abi": "pyamplicol-report-arena-execution-timing-v2", - "status": "unavailable", - "ratio_eligible": False, - "raw_seconds_per_point": None, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "repetitions_per_sample": 1, - "batch_size": 128, - "sample_contract": ("paired_unprofiled_headline_profiled_attribution_v1"), - "profile_protocol": "arena", - "profile_sample_pass": "runtime._profile_arena_repeated", - "profile_boundary": ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" - ), - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": "coarse-arena-boundary-only-v1", - "evaluator_timing_available": False, - "paired_with_headline": True, - "identical_batch": True, - "identical_repetitions": True, - "execution_mode": "compiled", - "warmed_boundary_wall_seconds_per_point": 1.1e-6, - "arena_profile_evidence_sha256": digest_arena_profile_value( - measurement["arena_profile_evidence"] - ), - } - assert measurement["benchmark_evidence"] == { - "report_command_path": PAIRED_ARENA_PROFILE_COMMAND_PATH, - "report_public_cli_path": None, - "measurement_phase_elapsed_seconds": 5.0, - "target_runtime_seconds": 5.0, - "achieved_runtime_seconds": 5.0, - "target_runtime_achieved": True, - "completed_sample_count": 5, - "planned_sample_count": 5, - "repetitions_per_sample": 128, - "measured_point_count": 640, - "interrupted": False, - } - - -def test_benchmark_measurement_rejects_unauthenticated_unavailable_timing() -> None: - with pytest.raises(RunnerError, match="warmed Arena profile boundary"): - _benchmark_measurement( - _benchmark_fixture(arena_authenticated=False), - matrix_element=2.0, - ) - - -@pytest.mark.parametrize("execution_mode", ("compiled", "eager")) -def test_benchmark_measurement_authenticates_accumulated_evaluator_total( - execution_mode: str, -) -> None: - benchmark = _benchmark_fixture(execution_mode=execution_mode) - benchmark.wall_time_per_point = 1.0e-6 - benchmark.evaluator_total_time_per_point = 1.0e-6 - benchmark.environment.update( - { - "evaluator_total_time_raw_seconds_per_point": 1.0e-6, - "evaluator_total_time_status": "measured", - "evaluator_total_time_ratio_eligible": False, - "evaluator_total_time_source": ( - "runtime._benchmark_f64_wall_time.accumulated" - ), - "evaluator_total_time_sample_contract": ( - "accumulated-repeated-warmed-evaluator-total-v1" - ), - "evaluator_total_accumulated_seconds": 6.4e-4, - } - ) - - measurement = _benchmark_measurement(benchmark, matrix_element=2.0) - - assert measurement["execution_seconds_per_point"] is None - assert measurement["evaluator_total_timing"] == { - "abi": "pyamplicol-report-evaluator-total-timing-v1", - "status": "measured", - "ratio_eligible": False, - "raw_seconds_per_point": 1.0e-6, - "source": "runtime._benchmark_f64_wall_time.accumulated", - "execution_mode": execution_mode, - "sample_contract": ("accumulated-repeated-warmed-evaluator-total-v1"), - "sample_count": 5, - "repetitions_per_sample": 1, - "batch_size": 128, - "points_per_sample": 128, - "measured_point_count": 640, - "accumulated_seconds": 6.4e-4, - } - - -def test_benchmark_measurement_rejects_inconsistent_accumulated_evaluator_total() -> ( - None -): - benchmark = _benchmark_fixture() - benchmark.evaluator_total_time_per_point = 1.0e-6 - benchmark.environment.update( - { - "evaluator_total_time_raw_seconds_per_point": 1.0e-6, - "evaluator_total_time_status": "measured", - "evaluator_total_time_ratio_eligible": False, - "evaluator_total_time_source": ( - "runtime._benchmark_f64_wall_time.accumulated" - ), - "evaluator_total_time_sample_contract": ( - "accumulated-repeated-warmed-evaluator-total-v1" - ), - "evaluator_total_accumulated_seconds": 1.0, - } - ) - - with pytest.raises(RunnerError, match="accumulated evaluator-total"): - _benchmark_measurement(benchmark, matrix_element=2.0) - - -def test_benchmark_measurement_rejects_synthetic_zero_execution() -> None: - benchmark = _benchmark_fixture() - benchmark.evaluator_time_per_point = 0.0 - benchmark.environment.update( - { - "evaluator_time_status": "measured", - "evaluator_time_raw_seconds_per_point": 0.0, - "evaluator_time_ratio_eligible": False, - "evaluator_time_source": "runtime_profile_core_evaluator_call_time", - "compiled_direct_arena_active": False, - } - ) - - with pytest.raises(RunnerError, match="measured execution timing"): - _benchmark_measurement(benchmark, matrix_element=2.0) - - -def test_benchmark_measurement_rejects_uncertainty_for_unexposed_execution() -> None: - benchmark = _benchmark_fixture() - benchmark.evaluator_uncertainty = SimpleNamespace(standard_error=0.0) - - with pytest.raises(RunnerError, match="warmed Arena profile boundary"): - _benchmark_measurement(benchmark, matrix_element=2.0) - - -def test_benchmark_measurement_retains_supported_recurrence_execution_timing() -> None: - benchmark = _benchmark_fixture() - benchmark.evaluator_time_per_point = 8.0e-7 - benchmark.evaluator_total_time_per_point = 1.2e-6 - benchmark.environment.update( - { - "evaluator_time_status": "measured", - "evaluator_time_raw_seconds_per_point": 8.0e-7, - "evaluator_time_ratio_eligible": True, - "evaluator_time_source": "runtime_profile_core_evaluator_call_time", - "compiled_direct_arena_active": False, - "execution_mode": "recurrence", - "timing_sample_contract": "paired-native-repeated-profile-v1", - "evaluator_total_time_raw_seconds_per_point": 1.2e-6, - "evaluator_total_time_status": "measured", - "evaluator_total_time_ratio_eligible": False, - "evaluator_total_time_source": ( - "runtime._benchmark_f64_wall_time.accumulated" - ), - "evaluator_total_time_sample_contract": ( - "accumulated-repeated-warmed-evaluator-total-v1" - ), - "evaluator_total_accumulated_seconds": 7.68e-4, - } - ) - - measurement = _benchmark_measurement(benchmark, matrix_element=2.0) - - assert measurement["execution_seconds_per_point"] == 8.0e-7 - assert measurement["arena_profile_evidence"] is None - assert measurement["evaluator_total_timing"] == { - "abi": "pyamplicol-report-evaluator-total-timing-v1", - "status": "measured", - "ratio_eligible": False, - "raw_seconds_per_point": 1.2e-6, - "source": "runtime._benchmark_f64_wall_time.accumulated", - "execution_mode": "recurrence", - "sample_contract": ("accumulated-repeated-warmed-evaluator-total-v1"), - "sample_count": 5, - "repetitions_per_sample": 1, - "batch_size": 128, - "points_per_sample": 128, - "measured_point_count": 640, - "accumulated_seconds": 7.68e-4, - } - assert measurement["execution_timing"] == { - "abi": "pyamplicol-report-execution-timing-v1", - "status": "measured", - "ratio_eligible": True, - "raw_seconds_per_point": 8.0e-7, - "source": "runtime_profile_core_evaluator_call_time", - "compiled_direct_arena_active": False, - "sample_count": 5, - "native_profile_points_per_sample": 128, - "sample_contract": "paired-native-repeated-profile-v1", - } - - -@pytest.mark.parametrize( - "execution_mode", - (ExecutionMode.EAGER, ExecutionMode.COMPILED), -) -def test_report_arena_benchmark_uses_private_profiler_without_public_fallback( - execution_mode: ExecutionMode, - monkeypatch: pytest.MonkeyPatch, -) -> None: - class Runtime: - def __init__(self) -> None: - self.wall_calls: list[tuple[object, int, dict[str, object]]] = [] - self.arena_calls: list[tuple[object, int, dict[str, object]]] = [] - self.public_profile_calls = 0 - - def _benchmark_f64_wall_time( - self, - batch: object, - repetitions: int, - **kwargs: object, - ) -> float: - self.wall_calls.append((batch, repetitions, dict(kwargs))) - return 1.0e-3 - - def _profile_arena_repeated( - self, - batch: object, - repetitions: int, - **kwargs: object, - ) -> dict[str, object]: - self.arena_calls.append((batch, repetitions, dict(kwargs))) - assert isinstance(batch, tuple) - return _raw_arena_profile( - execution_mode=execution_mode.value, - points=len(batch) * repetitions, - wall_time=2.0e-3, - ) - - def profile_repeated(self, *_args: object, **_kwargs: object) -> object: - self.public_profile_calls += 1 - raise AssertionError("public profile_repeated must not be used") - - backend = Runtime() - runtime = SimpleNamespace(_backend=backend) - clock_values = [0.0, 0.0, 0.2e-3, 0.2e-3, 0.4e-3, 0.4e-3] - clock = 0.4e-3 - for _ in range(5): - clock_values.extend((clock, clock + 1.2e-3, clock + 1.2e-3, clock + 3.2e-3)) - clock += 3.2e-3 - clock_values.extend((clock, clock + 0.1e-3)) - clock_iterator = iter(clock_values) - monkeypatch.setattr( - "tools.performance_report.runner.time.perf_counter", - lambda: next(clock_iterator), - ) - result = _run_report_benchmark( - runtime, - (((1.0, 0.0, 0.0, 1.0),),), - execution_mode=execution_mode, - benchmark_config=SimpleNamespace( - target_runtime=5.0e-3, - batch_size=2, - warmup_runs=1, - minimum_samples=5, - precision=16, - ), - selectors={"helicities": None, "color_flows": ("flow:1",)}, - ) - - assert result.sample_count == 5 - assert result.evaluator_time_per_point is None - assert result.wall_time_per_point == pytest.approx(6.0e-4) - assert result.evaluator_total_time_per_point == pytest.approx(5.0e-4) - assert result.wall_time_per_point != result.evaluator_total_time_per_point - assert result.environment["elapsed_seconds"] == pytest.approx(6.0e-3) - assert result.environment["evaluator_total_accumulated_seconds"] == pytest.approx( - 5.0e-3 - ) - assert result.environment["measured_point_count"] == 10 - assert result.environment["warmup_elapsed_seconds"] == pytest.approx(0.2e-3) - assert result.environment["calibration_elapsed_seconds"] == pytest.approx(0.2e-3) - assert result.environment["calibration_outer_elapsed_seconds"] == pytest.approx( - 0.2e-3 - ) - assert result.environment["measurement_phase_elapsed_seconds"] == pytest.approx( - 16.0e-3 - ) - assert result.environment["profile_total_elapsed_seconds"] == pytest.approx(16.5e-3) - measurement = _benchmark_measurement(result, matrix_element=2.0) - total_timing = measurement["evaluator_total_timing"] - assert isinstance(total_timing, dict) - assert total_timing["execution_mode"] == execution_mode.value - assert total_timing["raw_seconds_per_point"] == pytest.approx(5.0e-4) - assert total_timing["accumulated_seconds"] == pytest.approx(5.0e-3) - assert total_timing["measured_point_count"] == 10 - assert result.arena_profile_evidence["profile_count"] == 5 - assert backend.public_profile_calls == 0 - assert len(backend.arena_calls) == 6 - for wall_call, arena_call in zip( - backend.wall_calls[-5:], - backend.arena_calls[-5:], - strict=True, - ): - wall_batch, wall_repetitions, wall_kwargs = wall_call - arena_batch, arena_repetitions, arena_kwargs = arena_call - assert arena_batch == wall_batch - assert arena_repetitions == wall_repetitions - assert arena_kwargs == {**wall_kwargs, "include_values": False} - - -def test_report_arena_benchmark_recovers_from_busy_floor_calibration( - monkeypatch: pytest.MonkeyPatch, -) -> None: - class Clock: - value = 0.0 - - def advance(self, duration: float) -> None: - self.value += duration - - class Runtime: - def __init__(self, clock: Clock) -> None: - self.clock = clock - self.wall_repetitions: list[int] = [] - self.profile_repetitions: list[int] = [] - - def _benchmark_f64_wall_time( - self, - batch: object, - repetitions: int, - **_kwargs: object, - ) -> float: - assert isinstance(batch, tuple) - self.wall_repetitions.append(repetitions) - duration = ( - 3.753739778 - if len(self.wall_repetitions) == 1 - else 0.0181 * repetitions - ) - self.clock.advance(duration) - return duration - - def _profile_arena_repeated( - self, - batch: object, - repetitions: int, - **_kwargs: object, - ) -> dict[str, object]: - assert isinstance(batch, tuple) - self.profile_repetitions.append(repetitions) - duration = 1.0e-3 - self.clock.advance(duration) - return _raw_arena_profile( - execution_mode="compiled", - points=len(batch) * repetitions, - wall_time=duration, - ) - - clock = Clock() - runtime = Runtime(clock) - guarded_estimates: list[float | None] = [] - monkeypatch.setattr( - "tools.performance_report.runner.time.perf_counter", - lambda: clock.value, - ) - - result = _run_arena_benchmark( - runtime, - (((1.0, 0.0, 0.0, 1.0),),), - execution_mode="compiled", - benchmark_config=SimpleNamespace( - target_runtime=5.0, - batch_size=2, - warmup_runs=0, - minimum_samples=5, - precision=16, - ), - selectors={"helicities": None, "color_flows": None}, - chunk_guard=lambda estimate, _label: guarded_estimates.append(estimate), - ) - - assert result.sample_count == 5 - assert result.environment["elapsed_seconds"] == pytest.approx(5.068) - assert result.environment["repetitions_per_sample"] == 56 - assert result.environment["calibration"]["blocks"] == [ - {"repetitions": 1, "duration_seconds": 3.753739778}, - {"repetitions": 1, "duration_seconds": 0.0181}, - {"repetitions": 56, "duration_seconds": pytest.approx(1.0136)}, - ] - assert runtime.wall_repetitions == [1, 1, 56, 56, 56, 56, 56, 56] - assert runtime.profile_repetitions == [56] * 5 - assert guarded_estimates[:3] == [ - None, - pytest.approx(3.753739778), - pytest.approx(1.0136), - ] - - -def test_report_arena_calibration_confirms_genuinely_slow_floor_once() -> None: - calls: list[int] = [] - - def timer( - _batch: object, - repetitions: int, - **_arguments: object, - ) -> float: - calls.append(repetitions) - return 2.0 - - repetitions, blocks = _calibrate_arena_repetitions( - timer, - (((1.0, 0.0, 0.0, 1.0),),), - target_runtime=5.0, - sample_count=5, - selector_arguments={}, - ) - - assert repetitions == 1 - assert calls == [1, 1] - assert blocks == [ - {"repetitions": 1, "duration_seconds": 2.0}, - {"repetitions": 1, "duration_seconds": 2.0}, - ] - - -def test_report_arena_benchmark_requires_private_profiler() -> None: - runtime = SimpleNamespace( - _benchmark_f64_wall_time=lambda *_args, **_kwargs: 1.0, - profile_repeated=lambda *_args, **_kwargs: {}, - ) - - with pytest.raises(RunnerError, match=r"_profile_arena_repeated"): - _run_arena_benchmark( - runtime, - (((1.0, 0.0, 0.0, 1.0),),), - execution_mode="compiled", - benchmark_config=SimpleNamespace( - target_runtime=5.0, - batch_size=2, - warmup_runs=1, - minimum_samples=5, - precision=16, - ), - selectors={"helicities": None, "color_flows": None}, - ) - - -def test_report_arena_benchmark_reports_typed_profile_stages( - monkeypatch: pytest.MonkeyPatch, -) -> None: - from pyamplicol.reporting import ( - CallbackProgressSink, - ProgressEnd, - ProgressStart, - ProgressUpdate, - ) - - class Runtime: - def _benchmark_f64_wall_time( - self, - batch: object, - repetitions: int, - **_kwargs: object, - ) -> float: - del batch, repetitions - return 1.0e-3 - - def _profile_arena_repeated( - self, - batch: object, - repetitions: int, - **_kwargs: object, - ) -> dict[str, object]: - assert isinstance(batch, tuple) - return _raw_arena_profile( - points=len(batch) * repetitions, - wall_time=2.0e-3, - ) - - clock = -1.0e-3 - - def tick() -> float: - nonlocal clock - clock += 1.0e-3 - return clock - - monkeypatch.setattr( - "tools.performance_report.runner.time.perf_counter", - tick, - ) - events: list[ProgressStart | ProgressUpdate | ProgressEnd] = [] - _run_arena_benchmark( - Runtime(), - (((1.0, 0.0, 0.0, 1.0),),), - execution_mode="compiled", - benchmark_config=SimpleNamespace( - target_runtime=4.0e-3, - batch_size=2, - warmup_runs=1, - minimum_samples=5, - precision=16, - ), - selectors={"helicities": None, "color_flows": None}, - progress=CallbackProgressSink(events.append), - ) - - starts = {event.task_id for event in events if isinstance(event, ProgressStart)} - updates = {event.task_id for event in events if isinstance(event, ProgressUpdate)} - assert starts == { - "report-profile", - "report-profile:warmup", - "report-profile:calibration", - "report-profile:samples", - } - assert updates == { - "report-profile:warmup", - "report-profile:calibration", - "report-profile:samples", - } - assert isinstance(events[-1], ProgressEnd) - assert events[-1].task_id == "report-profile" - assert events[-1].success is True - - -def test_report_benchmark_keeps_recurrence_on_supported_public_runner( - monkeypatch: pytest.MonkeyPatch, -) -> None: - import pyamplicol.cli - - calls: list[tuple[object, object]] = [] - parsed_argv: list[tuple[str, ...]] = [] - real_parse_cli = pyamplicol.cli.parse_cli - - def parse_cli(argv: tuple[str, ...]): - parsed_argv.append(tuple(argv)) - return real_parse_cli(argv) - - @dataclass(frozen=True) - class Result: - environment: dict[str, object] - - expected = Result(environment={"existing": "evidence"}) - - class BenchmarkRunner: - def __init__( - self, - config: object, - *, - progress: object | None = None, - ) -> None: - self.config = config - assert progress is not None - - def run(self, runtime: object, *, points: object) -> object: - calls.append((runtime, points)) - return expected - - monkeypatch.setattr("pyamplicol.api.BenchmarkRunner", BenchmarkRunner) - monkeypatch.setattr(pyamplicol.cli, "parse_cli", parse_cli) - runtime = SimpleNamespace(_backend=SimpleNamespace()) - points = (((1.0, 0.0, 0.0, 1.0),),) - from pyamplicol.config import BenchmarkConfig - - result = _run_report_benchmark( - runtime, - points, - execution_mode=ExecutionMode.RECURRENCE, - benchmark_config=BenchmarkConfig(), - selectors={"helicities": None, "color_flows": None}, - ) - - assert result is not expected - assert result.environment["profile_total_elapsed_seconds"] >= 0.0 - observed_environment = dict(result.environment) - observed_environment.pop("profile_total_elapsed_seconds") - assert observed_environment == { - "existing": "evidence", - "report_command_path": LOADED_RUNTIME_PROFILE_COMMAND_PATH, - "report_public_cli_path": PUBLIC_CLI_COMMAND_PATH, - } - assert calls == [(runtime, points)] - assert len(parsed_argv) == 1 - assert parsed_argv[0][0] == "profile" - assert "--target-runtime" in parsed_argv[0] - - -@pytest.mark.parametrize( - "field", - ( - "native_input_container_allocation_count", - "native_input_pack_bytes", - "stage_evaluator_output_gather_component_count", - "selector_scatter_value_count", - "amplitude_output_remap_component_count", - ), -) -def test_arena_profile_evidence_rejects_warmed_boundary_traffic( - field: str, -) -> None: - profile = _raw_arena_profile() - profile[field] = 1 - - with pytest.raises(ArenaProfileEvidenceError, match=field): - build_arena_profile_evidence( - (profile,), - execution_mode="compiled", - repetitions_per_profile=1, - batch_size=128, - ) - - -@pytest.mark.parametrize( - "field", - ( - "compiled_direct_arena_engine_count", - "compiled_direct_arena_call_count", - "evaluator_backend_call_count", - ), -) -def test_arena_profile_evidence_keeps_compiled_activity_fail_closed( - field: str, -) -> None: - profile = _raw_arena_profile() - profile[field] = 0 - - with pytest.raises(ArenaProfileEvidenceError, match="activity counters"): - build_arena_profile_evidence( - (profile,), - execution_mode="compiled", - repetitions_per_profile=1, - batch_size=128, - ) - - -def test_arena_profile_evidence_recomputes_all_native_counters() -> None: - evidence = build_arena_profile_evidence( - (_raw_arena_profile(),) * 5, - execution_mode="compiled", - repetitions_per_profile=1, - batch_size=128, - ) - - assert evidence["counter_totals"]["points"] == 640 - assert evidence["counter_totals"]["state_component_count"] == 55 - assert evidence["counter_totals"]["source_component_count"] == 35 - - evidence["counter_totals"]["state_component_count"] = 54 - with pytest.raises( - ArenaProfileEvidenceError, - match="independently recomputed", - ): - validate_arena_profile_evidence( - evidence, - execution_mode="compiled", - sample_count=5, - native_profile_points_per_sample=128, - ) - - -def test_arena_profile_evidence_rejects_recurrence_protocol_claim() -> None: - with pytest.raises(ArenaProfileEvidenceError, match="unsupported"): - build_arena_profile_evidence( - (_raw_arena_profile(execution_mode="recurrence"),), - execution_mode="recurrence", - repetitions_per_profile=1, - batch_size=128, - ) - - -def _digest_json(value: object) -> str: - return hashlib.sha256( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _binding_digest(binding: dict[str, object]) -> str: - if binding["kind"] != "rusticol-intrinsic": - payload = dict(binding) - payload.pop("payload_digest", None) - return _digest_json(payload) - fields = ( - "abi", - "contribution_parent_permutation", - "kind", - "runtime_template", - ) - return _digest_json({field: binding.get(field) for field in fields}) - - -def _refresh_recurrence_catalog( - execution: dict[str, object], - pack: dict[str, object], - *, - refresh_binding_digests: bool = True, -) -> None: - catalog = pack["recurrence_direct_template"] - assert isinstance(catalog, dict) - templates = catalog["templates"] - assert isinstance(templates, list) - for template in templates: - assert isinstance(template, dict) - binding = template["payload_binding"] - assert isinstance(binding, dict) - if refresh_binding_digests: - binding["payload_digest"] = _binding_digest(binding) - semantic = dict(template) - semantic.pop("semantic_digest", None) - template["semantic_digest"] = _digest_json(semantic) - semantic_catalog = dict(catalog) - semantic_catalog.pop("catalog_digest", None) - catalog["catalog_digest"] = _digest_json(semantic_catalog) - execution["direct_template_catalog_digest"] = catalog["catalog_digest"] - plan = execution["plan"] - assert isinstance(plan, dict) - plan["direct_template_catalog_digest"] = catalog["catalog_digest"] - - -def _canonical_symjit_evaluator( - application_path: str, - plane_path: str, - *, - optimization_level: int, - input_len: int = 1, - output_len: int = 1, - source_digest: str = "1" * 64, -) -> dict[str, object]: - return { - "kind": "symjit-application-evaluator", - "runtime_capability": "symjit.application.complex-f64.v1", - "input_len": input_len, - "output_len": output_len, - "application_path": application_path, - "application_abi": "symjit-application-storage-v3", - "element_layout": "complex-f64", - "batch_layout": "row-major", - "compiler_type": "native", - "translation_mode": "indirect", - "optimization_level": optimization_level, - "word_bits": 64, - "endianness": "little", - "required_defuns": [], - "evaluator_state_path": f"{application_path}.state", - "evaluator_state_runtime_capability": ( - "symbolica.legacy-jit-container.complex-f64.v1" - ), - "plane_application": { - "application_path": plane_path, - "application_abi": "pyamplicol-symjit-plane-application-v2", - "storage_abi": "symjit-application-storage-v3", - "element_layout": "split-complex-plane-major", - "descriptor_order": "inputs-re-im-then-outputs-re-im", - "input_complex_count": input_len, - "output_complex_count": output_len, - "input_plane_count": 2 * input_len, - "output_plane_count": 2 * output_len, - "compiler_type": "native", - "translation_mode": "symbolica-structured-instructions", - "optimization_level": optimization_level, - "simd": True, - "complex": True, - "fast_math": True, - "fast_complex": False, - "compression": False, - "threading": False, - "direct_arena": True, - "source_digest": source_digest, - "target": {"word_bits": 64, "endianness": "little"}, - }, - } - - -@pytest.mark.parametrize("optimization_level", (1, 3)) -@pytest.mark.parametrize("chunked", (False, True)) -def test_canonical_symjit_serializer_round_trips_into_report_authentication( - optimization_level: int, - chunked: bool, -) -> None: - raw = _canonical_symjit_evaluator( - "evaluators/left.symjit", - "evaluators/left.plane.symjit", - optimization_level=optimization_level, - ) - raw["backend"] = "jit" - if chunked: - right = _canonical_symjit_evaluator( - "evaluators/right.symjit", - "evaluators/right.plane.symjit", - optimization_level=optimization_level, - ) - right["backend"] = "jit" - serialized = _serialize_evaluator( - { - "kind": "chunked-symbolica-evaluator", - "input_len": 2, - "chunk_input_indices": [[0], [1]], - "required_runtime_capabilities": ["symjit.application.complex-f64.v1"], - "chunks": [raw, right], - } - ) - else: - serialized = _serialize_evaluator(raw) - - leaves = _authenticated_symjit_plane_leaves( - serialized, - source_optimization_level=optimization_level, - context="serialized evaluator", - ) - - assert len(leaves) == (2 if chunked else 1) - for leaf in serialized["chunks"] if chunked else [serialized]: - assert "backend" not in leaf - assert leaf["compiler_type"] == "native" - - -@pytest.mark.parametrize( - ("field", "value"), - ( - ("backend", "native"), - ("backend", None), - ("compiler_type", "interpreter"), - ), -) -def test_symjit_report_authentication_rejects_contradictory_identity( - field: str, - value: object, -) -> None: - evaluator = _canonical_symjit_evaluator( - "evaluators/stage.symjit", - "evaluators/stage.plane.symjit", - optimization_level=3, - ) - evaluator[field] = value - - with pytest.raises(RunnerError, match="leaf contract drifted"): - _authenticated_symjit_plane_leaves( - evaluator, - source_optimization_level=3, - context="corrupt evaluator", - ) - - -def test_symjit_report_authentication_accepts_fallback_free_portable_leaf() -> None: - evaluator = _canonical_symjit_evaluator( - "evaluators/stage.symjit", - "evaluators/stage.plane.symjit", - optimization_level=3, - ) - evaluator["evaluator_state_path"] = None - evaluator["evaluator_state_runtime_capability"] = None - - assert _authenticated_symjit_plane_leaves( - evaluator, - source_optimization_level=3, - context="portable evaluator", - ) == [("evaluators/stage.plane.symjit", "1" * 64)] - - -@pytest.mark.parametrize( - ("state_path", "capability"), - ( - (None, "symbolica.legacy-jit-container.complex-f64.v1"), - ("evaluators/stage.state", None), - ), -) -def test_symjit_report_authentication_rejects_partial_fallback_pair( - state_path: str | None, - capability: str | None, -) -> None: - evaluator = _canonical_symjit_evaluator( - "evaluators/stage.symjit", - "evaluators/stage.plane.symjit", - optimization_level=3, - ) - evaluator["evaluator_state_path"] = state_path - evaluator["evaluator_state_runtime_capability"] = capability - - with pytest.raises(RunnerError, match="fallback contract drifted"): - _authenticated_symjit_plane_leaves( - evaluator, - source_optimization_level=3, - context="partial fallback evaluator", - ) - - -@pytest.mark.parametrize( - "target", - ( - {"word_bits": 64.0, "endianness": "little"}, - { - "word_bits": 64, - "endianness": "little", - "cpu_features": ["z", "a"], - }, - {"word_bits": 64, "endianness": "little", "unknown": True}, - ), -) -def test_symjit_report_authentication_rejects_noncanonical_target( - target: dict[str, object], -) -> None: - evaluator = _canonical_symjit_evaluator( - "evaluators/stage.symjit", - "evaluators/stage.plane.symjit", - optimization_level=3, - ) - plane = evaluator["plane_application"] - assert isinstance(plane, dict) - plane["target"] = target - - with pytest.raises(RunnerError, match="plane application contract drifted"): - _authenticated_symjit_plane_leaves( - evaluator, - source_optimization_level=3, - context="noncanonical target evaluator", - ) - - -def _recurrence_source_fixture( - source_sha256: str, -) -> tuple[dict[str, object], dict[str, object]]: - ordinary_source_path = "kernels/000000/application-0.symjit" - source_path = "kernels/000000/application-0.plane.symjit" - prepared_binding: dict[str, object] = { - "abi": "pyamplicol-recurrence-plane-binding-v2", - "contribution_parent_permutation": [0, 1], - "destination_operation": "finalize-in-place", - "direct_application_abi": "pyamplicol-symjit-plane-application-v2", - "exact_factor_scalar_slots": [0, 1], - "input_plane_count": 1, - "input_plane_projections": [{"kind": "destination-current"}], - "intrinsic_contract_digest": None, - "kind": "prepared-direct-call", - "output_alias_inputs": [0], - "parameter_bindings": [{"index": 0, "kind": "plane"}], - "payload_digest": "", - "payload_paths": [source_path], - "prepared_kernel_id": 0, - "prepared_template_semantic_digest": "d" * 64, - "role": "finalization", - "runtime_template": None, - "scalar_input_count": 2, - "scalar_projections": [ - {"imaginary": False, "kind": "exact-factor"}, - {"imaginary": True, "kind": "exact-factor"}, - ], - "source_application_abi": "pyamplicol-symjit-plane-application-v2", - "source_application_path": source_path, - "source_application_sha256": source_sha256, - "state_plane_indices": [], - } - intrinsic_binding: dict[str, object] = { - "abi": "pyamplicol-recurrence-plane-binding-v2", - "contribution_parent_permutation": [0, 1], - "destination_operation": None, - "direct_application_abi": None, - "exact_factor_scalar_slots": [], - "input_plane_count": 0, - "input_plane_projections": [], - "intrinsic_contract_digest": None, - "kind": "rusticol-intrinsic", - "output_alias_inputs": [], - "parameter_bindings": [], - "payload_digest": "", - "payload_paths": [], - "prepared_kernel_id": None, - "prepared_template_semantic_digest": None, - "role": None, - "runtime_template": "source-current", - "scalar_input_count": 0, - "scalar_projections": [], - "source_application_abi": None, - "source_application_path": None, - "source_application_sha256": None, - "state_plane_indices": [], - } - templates: list[dict[str, object]] = [ - { - "abi": "pyamplicol-recurrence-direct-template-v1", - "alignment_bytes": 64, - "backend": "jit", - "coupling_slot_count": 0, - "destination_aliasing": True, - "destination_component_count": 1, - "destination_operation": "finalize-in-place", - "direct_executor_id": 0, - "evaluator_binding_id": 0, - "evaluator_resolver_key": "prepared-kernel-0", - "exact_expression_digest": "e" * 64, - "momentum_operand_count": 0, - "optimization_level": 2, - "parameter_slot_count": 0, - "parent_arity": 1, - "parent_component_counts": [1], - "payload_binding": prepared_binding, - "portable": True, - "role": "finalization", - "semantic_digest": "", - "semantic_template_ids": ["prepared-finalization"], - "simd_axis": "points-contiguous", - "target_triple": "symjit-storage-v3-portable", - "template_id": "template-0", - }, - { - "abi": "pyamplicol-recurrence-direct-template-v1", - "alignment_bytes": 64, - "backend": "jit", - "coupling_slot_count": 0, - "destination_aliasing": False, - "destination_component_count": 1, - "destination_operation": "initialize", - "direct_executor_id": 1, - "evaluator_binding_id": 1, - "evaluator_resolver_key": "source-current", - "exact_expression_digest": "f" * 64, - "momentum_operand_count": 0, - "optimization_level": 2, - "parameter_slot_count": 0, - "parent_arity": 0, - "parent_component_counts": [], - "payload_binding": intrinsic_binding, - "portable": True, - "role": "source", - "semantic_digest": "", - "semantic_template_ids": ["source-current"], - "simd_axis": "points-contiguous", - "target_triple": "symjit-storage-v3-portable", - "template_id": "template-1", - }, - ] - prepared_digest = "a" * 64 - catalog: dict[str, object] = { - "abi": "pyamplicol-recurrence-direct-template-v1", - "backend": "jit", - "backend_abi": "rusticol.recurrence-direct-backend.v1", - "canonicalization_abi": "pyamplicol-canonical-json-v1", - "catalog_digest": "", - "compiled_model_digest": "b" * 64, - "optimization_level": 2, - "optimization_settings_digest": "c" * 64, - "portable": True, - "prepared_kernel_contract_digest": "4" * 64, - "prepared_kernel_pack_digest": prepared_digest, - "prepared_kernel_payload_digest": "5" * 64, - "recurrence_template_catalog_digest": "6" * 64, - "target_triple": "symjit-storage-v3-portable", - "templates": templates, - } - execution: dict[str, object] = { - "kind": "pyamplicol-runtime-recurrence-execution", - "direct_template_abi": "pyamplicol-recurrence-direct-template-v1", - "direct_backend_abi": "rusticol.recurrence-direct-backend.v1", - "prepared_kernel_pack_digest": prepared_digest, - "direct_template_catalog_digest": "", - "kernel_pack": { - "manifest_path": "model/eager-kernel-pack.json", - "payload_root": "model/eager-kernels", - }, - "plan": { - "direct_template_abi": "pyamplicol-recurrence-direct-template-v1", - "direct_backend_abi": "rusticol.recurrence-direct-backend.v1", - "prepared_kernel_pack_digest": prepared_digest, - "direct_template_catalog_digest": "", - }, - } - pack: dict[str, object] = { - "backend": "jit", - "optimization_settings": { - "backend": "jit", - "jit_optimization_level": 2, - }, - "recurrence_direct_template": catalog, - "kernel_variants": [], - "kernels": [ - { - "kernel_id": 0, - "f64_evaluator_manifest": _canonical_symjit_evaluator( - ordinary_source_path, - source_path, - optimization_level=2, - ), - } - ], - } - _refresh_recurrence_catalog(execution, pack) - return execution, pack - - -def _write_json_payload( - root: Path, - relative: str, - value: object, - *, - process_id: str | None, -) -> SimpleNamespace: - data = json.dumps( - value, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - path = root / relative - path.parent.mkdir(parents=True, exist_ok=True) - path.write_bytes(data) - return SimpleNamespace( - path=relative, - role="evaluator-manifest", - media_type="application/json", - size_bytes=len(data), - sha256=hashlib.sha256(data).hexdigest(), - executable=False, - process_id=process_id, - ) - - -def _runner_recurrence_artifact( - root: Path, -) -> tuple[ - SimpleNamespace, - dict[str, object], - dict[str, object], - SimpleNamespace, - SimpleNamespace, -]: - process_id = "process-1" - index_relative = "processes/evaluators.json" - execution_relative = f"processes/{process_id}/execution.json" - pack_relative = "model/eager-kernel-pack.json" - source_relative = "model/eager-kernels/kernels/000000/application-0.plane.symjit" - source_data = b"authenticated-symjit-application" - source_sha256 = hashlib.sha256(source_data).hexdigest() - execution, pack = _recurrence_source_fixture(source_sha256) - index = { - "schema_version": 3, - "kind": "pyamplicol-runtime-execution-set", - "processes": [ - { - "process_id": process_id, - "manifest_path": f"{process_id}/execution.json", - } - ], - } - index_payload = _write_json_payload( - root, - index_relative, - index, - process_id=None, - ) - execution_payload = _write_json_payload( - root, - execution_relative, - execution, - process_id=process_id, - ) - pack_payload = _write_json_payload( - root, - pack_relative, - pack, - process_id=None, - ) - source_path = root / source_relative - source_path.parent.mkdir(parents=True, exist_ok=True) - source_path.write_bytes(source_data) - source_payload = SimpleNamespace( - path=source_relative, - role="evaluator-state", - media_type="application/octet-stream", - size_bytes=len(source_data), - sha256=source_sha256, - executable=False, - process_id=None, - ) - manifest = SimpleNamespace( - root=root, - runtime={"evaluator_manifest_path": index_relative}, - payloads=( - index_payload, - execution_payload, - pack_payload, - source_payload, - ), - extensions={}, - ) - return manifest, execution, pack, execution_payload, pack_payload - - -def _rewrite_json_payload( - root: Path, - record: SimpleNamespace, - value: object, -) -> None: - data = json.dumps( - value, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - (root / record.path).write_bytes(data) - record.size_bytes = len(data) - record.sha256 = hashlib.sha256(data).hexdigest() - - -def test_checked_runtime_identity_rejects_a_symlink(tmp_path: Path) -> None: - if not hasattr(os, "O_NOFOLLOW"): - pytest.skip("O_NOFOLLOW is unavailable") - target = tmp_path / "target.py" - target.write_text("VALUE = 1\n", encoding="utf-8") - link = tmp_path / "link.py" - link.symlink_to(target) - with pytest.raises(RunnerError, match="checked fd"): - _regular_file_identity(link) - - -def test_effective_config_is_read_from_its_authenticated_artifact_payload( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - relative = "config/effective.toml" - data = b'[evaluator]\nbackend = "jit"\nexecution_mode = "compiled"\n' - path = tmp_path / relative - path.parent.mkdir(parents=True) - path.write_bytes(data) - manifest = SimpleNamespace( - root=tmp_path, - configuration={"effective_path": relative}, - payloads=( - SimpleNamespace( - path=relative, - role="configuration-effective", - media_type="application/toml", - size_bytes=len(data), - sha256=hashlib.sha256(data).hexdigest(), - executable=False, - process_id=None, - ), - ), - ) - monkeypatch.setattr( - "pyamplicol.artifacts.load_manifest", - lambda _path, *, verify_payloads: manifest, - ) - - assert _authenticated_effective_config(tmp_path) == { - "evaluator": { - "backend": "jit", - "execution_mode": "compiled", - } - } - - path.write_bytes(data.replace(b"compiled", b"eager ")) - with pytest.raises(RunnerError, match="artifact manifest"): - _authenticated_effective_config(tmp_path) - - -@dataclass(frozen=True) -class Flow: - id: str - word: tuple[int, ...] - - -@dataclass(frozen=True) -class Helicity: - id: str - values: tuple[int, ...] - - -@dataclass(frozen=True) -class Particle: - label: int - pdg_id: int = 1 - - -class Resolved: - def __init__(self, values: object, totals: tuple[complex, ...]) -> None: - self.values = values - self._totals = totals - - def total(self) -> tuple[complex, ...]: - return self._totals - - -class FakeRuntime: - def __init__(self) -> None: - self.physics = SimpleNamespace( - color_accuracy="lc", - selector_capabilities=("helicity", "color_flow"), - external_particles=(Particle(1), Particle(2), Particle(3)), - helicities=( - Helicity("h:-1,-1,-1", (-1, -1, -1)), - Helicity("h:-1,+1,-1", (-1, 1, -1)), - ), - color_flows=( - Flow("flow:2,1,3", (2, 1, 3)), - Flow("flow:1,2,3", (1, 2, 3)), - ), - ) - self.optimized = (3.0 + 0.0j,) - self.resolved_total = (3.0 + 0.0j,) - - def evaluate(self, _points: object, **_selectors: object) -> tuple[complex, ...]: - return self.optimized - - def evaluate_resolved( - self, - _points: object, - **_selectors: object, - ) -> Resolved: - return Resolved( - ( - ( - (0.0 + 0.0j,), - (3.0 + 0.0j,), - ), - ), - self.resolved_total, - ) - - -def _cell( - mode: ExecutionMode, - accuracy: Accuracy, - workload: Workload, -): - return next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode is mode - and cell.measurement.accuracy is accuracy - and cell.workload is workload - ) - - -def test_generation_phase_watchdog_covers_preparation_and_generator_call( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - import pyamplicol.api - import pyamplicol.cli - import tools.performance_report.runner as report_runner - - events: list[str] = [] - parsed_argv: list[tuple[str, ...]] = [] - real_parse_cli = pyamplicol.cli.parse_cli - - def parse_cli(argv: tuple[str, ...]): - parsed_argv.append(tuple(argv)) - return real_parse_cli(argv) - - class FakeSource: - def compile(self, **_kwargs: object) -> object: - events.append("model-preparation") - return object() - - class FakeModelSource: - @staticmethod - def built_in_sm() -> FakeSource: - return FakeSource() - - @staticmethod - def from_path(_path: Path) -> FakeSource: - return FakeSource() - - class FakeGenerator: - def __init__( - self, - _resolution: object, - *, - progress: object | None = None, - ) -> None: - assert progress is not None - - def generate(self, *_args: object, **_kwargs: object) -> None: - events.append("Generator.generate") - - class SpyReporter: - @contextmanager - def generation(self): - events.append("phase-enter") - try: - yield - finally: - events.append("phase-exit") - - monkeypatch.setattr(pyamplicol.api, "Generator", FakeGenerator) - monkeypatch.setattr(pyamplicol.api, "ModelSource", FakeModelSource) - monkeypatch.setattr(pyamplicol.cli, "parse_cli", parse_cli) - monkeypatch.setattr( - report_runner, - "_authenticated_effective_config", - lambda _path: events.append("post-generation-validation") or {}, - ) - monkeypatch.setattr( - report_runner, - "_single_process_id", - lambda _path, fallback: fallback, - ) - monkeypatch.setattr( - report_runner, - "_artifact_numerical_relation_metadata", - lambda _path, _process_id: ( - { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - }, - None, - ), - ) - - generated = generate_artifact( - _cell(ExecutionMode.COMPILED, Accuracy.LC, Workload.SELECTED_FLOW), - tmp_path / "artifact", - settings=RunnerSettings(), - repo_root=tmp_path, - phase_reporter=SpyReporter(), # type: ignore[arg-type] - ) - - assert events == [ - "phase-enter", - "model-preparation", - "Generator.generate", - "phase-exit", - "post-generation-validation", - ] - assert len(parsed_argv) == 1 - assert parsed_argv[0][0] == "generate" - assert generated.generation_command_path == PRECOMPILED_GENERATION_COMMAND_PATH - - -@pytest.mark.parametrize( - "mode", - (ExecutionMode.EAGER, ExecutionMode.RECURRENCE), -) -def test_prepared_generation_uses_public_cli_parser_and_default_handler( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - mode: ExecutionMode, -) -> None: - import pyamplicol.api - import pyamplicol.cli - import pyamplicol.cli.handlers - import tools.performance_report.runner as report_runner - - parsed_argv: list[tuple[str, ...]] = [] - handler_configs: list[object] = [] - generated_models: list[object] = [] - real_parse_cli = pyamplicol.cli.parse_cli - real_generate = pyamplicol.cli.handlers.DefaultCliServices.generate - - def parse_cli(argv: tuple[str, ...]): - parsed_argv.append(tuple(argv)) - return real_parse_cli(argv) - - def public_generate( - self: object, - config: object, - progress: object, - ) -> object: - handler_configs.append(config) - return real_generate(self, config, progress) # type: ignore[arg-type] - - class FakeSource: - pass - - class FakeModelSource: - @staticmethod - def built_in_sm() -> FakeSource: - return FakeSource() - - @staticmethod - def from_config(_config: object) -> FakeSource: - return FakeSource() - - class FakeGenerator: - def __init__( - self, - *, - config: object, - progress: object | None = None, - ) -> None: - assert progress is not None - self.config = config - - def generate( - self, - _processes: object, - _output: Path, - *, - model: object, - mode: str, - ) -> None: - assert mode == "replace" - generated_models.append(model) - - monkeypatch.setattr(pyamplicol.api, "Generator", FakeGenerator) - monkeypatch.setattr(pyamplicol.api, "ModelSource", FakeModelSource) - monkeypatch.setattr(pyamplicol.cli, "parse_cli", parse_cli) - monkeypatch.setattr( - pyamplicol.cli.handlers.DefaultCliServices, - "generate", - public_generate, - ) - monkeypatch.setattr( - report_runner, - "_authenticated_effective_config", - lambda _path: {}, - ) - monkeypatch.setattr( - report_runner, - "_single_process_id", - lambda _path, fallback: fallback, - ) - monkeypatch.setattr( - report_runner, - "_artifact_numerical_relation_metadata", - lambda _path, _process_id: ( - { - "abi": "pyamplicol-numerical-current-relation-correctness-v1", - "state": "no-applied-relations", - "applied_relation_count": 0, - }, - None, - ), - ) - cell = REPORT_CATALOG.cell( - f"matrix-{mode.value}-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - - generated = generate_artifact( - cell, - tmp_path / "artifact", - settings=RunnerSettings(), - repo_root=tmp_path, - ) - - assert len(parsed_argv) == 1 - assert parsed_argv[0][:2] == ("generate", cell.process) - assert len(handler_configs) == 1 - assert len(generated_models) == 1 - assert generated.generation_command_path == PUBLIC_CLI_COMMAND_PATH - - -@pytest.mark.parametrize( - ("mode", "workload", "expected_layout", "expected_level"), - ( - ( - ExecutionMode.RECURRENCE, - Workload.SELECTED_FLOW, - "topology-replay", - 2, - ), - ( - ExecutionMode.RECURRENCE, - Workload.ALL_FLOW, - "all-flow-union", - 2, - ), - ( - ExecutionMode.COMPILED, - Workload.SELECTED_FLOW, - "topology-replay", - 3, - ), - ( - ExecutionMode.EAGER, - Workload.ALL_FLOW, - "all-flow-union", - 2, - ), - ), -) -def test_config_steers_complete_coverage_and_layout_only( - mode: ExecutionMode, - workload: Workload, - expected_layout: str, - expected_level: int, -) -> None: - cell = _cell(mode, Accuracy.LC, workload) - values = config_values( - cell, - RunnerSettings(worker_cores=1), - repo_root=Path("/repo"), - ) - - assert values["color"]["lc_flow_layout"] == expected_layout # type: ignore[index] - assert values["evaluator"]["execution_mode"] == mode.value # type: ignore[index] - assert ( - values["evaluator"]["jit"]["optimization_level"] # type: ignore[index] - == expected_level - ) - serialized = repr(values) - assert "selected_color_sector_ids" not in serialized - assert "selected_source_helicities" not in serialized - assert "reference_color_order" not in serialized - - -def test_config_threads_manual_profile_sampling_settings() -> None: - values = config_values( - _cell( - ExecutionMode.RECURRENCE, - Accuracy.LC, - Workload.SELECTED_FLOW, - ), - RunnerSettings(warmup_runs=7, minimum_samples=11), - repo_root=Path("/repo"), - ) - - assert values["benchmark"]["warmup_runs"] == 7 # type: ignore[index] - assert values["benchmark"]["minimum_samples"] == 11 # type: ignore[index] - assert values["generation"]["validation"] == { # type: ignore[index] - "enabled": True, - "samples": 1, - "seed": 12345, - "relative_tolerance": 1.0e-12, - "absolute_tolerance": 1.0e-300, - "post_build_validation": False, - } - - -@pytest.mark.parametrize( - ("mode", "workspace_key"), - ( - (ExecutionMode.RECURRENCE, "recurrence"), - (ExecutionMode.EAGER, "eager"), - ), -) -def test_config_derives_selected_engine_workspace_from_campaign_memory_cap( - mode: ExecutionMode, - workspace_key: str, -) -> None: - values = config_values( - _cell(mode, Accuracy.LC, Workload.SELECTED_FLOW), - RunnerSettings(memory_limit_bytes=15_000_000_000), - repo_root=Path("/repo"), - ) - evaluator = values["evaluator"] - assert isinstance(evaluator, dict) - assert evaluator[workspace_key] == {"workspace_mib": 14_305} - assert ({"eager", "recurrence"} - {workspace_key}).isdisjoint(evaluator) - - compiled = config_values( - _cell(ExecutionMode.COMPILED, Accuracy.LC, Workload.SELECTED_FLOW), - RunnerSettings(memory_limit_bytes=15_000_000_000), - repo_root=Path("/repo"), - )["evaluator"] - assert isinstance(compiled, dict) - assert "eager" not in compiled - assert "recurrence" not in compiled - - -def test_runner_rejects_sub_mib_workspace_budget() -> None: - with pytest.raises(ValueError, match="at least one MiB"): - RunnerSettings(memory_limit_bytes=1024 * 1024 - 1) - - -def test_nlc_and_full_use_contracted_topology_replay_configuration() -> None: - for accuracy in (Accuracy.NLC, Accuracy.FULL): - cell = _cell(ExecutionMode.RECURRENCE, accuracy, Workload.CONTRACTED) - values = config_values( - cell, - RunnerSettings(), - repo_root=Path("/repo"), - ) - assert values["color"] == { - "accuracy": accuracy.value, - "lc_flow_layout": "topology-replay", - } - - -def test_selector_contract_uses_canonical_minimum_flow_and_fixed_helicity() -> None: - runtime = FakeRuntime() - points = (((1.0, 0.0, 0.0, 1.0),),) - - contract = derive_selector_contract(runtime, points) - - assert contract.selected_color_flow_ids == ("flow:1,2,3",) - assert contract.selected_color_words == ((1, 2, 3),) - assert contract.all_flow_helicity_ids == ("h:-1,+1,-1",) - assert contract.all_flow_source_helicities == ((1, -1), (2, 1), (3, -1)) - assert contract.point_digest == point_digest(points) - assert SelectorContract.from_mapping(contract.as_dict()) == contract - validate_selector_contract(runtime, contract, points) - - -def test_selector_contract_is_independent_of_runtime_flow_enumeration() -> None: - points = (((1.0, 0.0, 0.0, 1.0),),) - forward = FakeRuntime() - reverse = FakeRuntime() - reverse.physics.color_flows = tuple(reversed(forward.physics.color_flows)) - - assert derive_selector_contract(forward, points) == derive_selector_contract( - reverse, - points, - ) - - -def test_selector_contract_rejects_zero_canonical_minimum_flow() -> None: - class CanonicalMinimumZeroRuntime(FakeRuntime): - def evaluate_resolved( - self, - _points: object, - **selectors: object, - ) -> Resolved: - assert selectors.get("helicities") == ("h:-1,+1,-1",) - selected_flows = selectors.get("color_flows") - if selected_flows == ("flow:1,2,3",): - return Resolved( - ( - ( - (0.0 + 0.0j,), - (0.0 + 0.0j,), - ), - ), - self.resolved_total, - ) - pytest.fail("selector must not fall back to a noncanonical flow") - - with pytest.raises( - RunnerError, - match="canonical fixed-helicity selector is zero", - ): - derive_selector_contract( - CanonicalMinimumZeroRuntime(), - (((1.0, 0.0, 0.0, 1.0),),), - ) - - -def test_selector_contract_ignores_larger_noncanonical_flow_component() -> None: - class CanonicalMinimumRuntime(FakeRuntime): - def evaluate_resolved( - self, - _points: object, - **selectors: object, - ) -> Resolved: - selected_flows = selectors.get("color_flows") - if selected_flows == ("flow:1,2,3",): - return Resolved( - ( - ( - (0.0 + 0.0j,), - (1.0e-18 + 0.0j,), - ), - ), - self.resolved_total, - ) - pytest.fail("selector must not rank noncanonical flow components") - - contract = derive_selector_contract( - CanonicalMinimumRuntime(), - (((1.0, 0.0, 0.0, 1.0),),), - ) - - assert contract.selected_color_flow_ids == ("flow:1,2,3",) - assert contract.all_flow_helicity_ids == ("h:-1,+1,-1",) - - -def test_selector_contract_rejects_duplicate_physical_flow_words() -> None: - runtime = FakeRuntime() - runtime.physics.color_flows = ( - Flow("flow:1,2,3", (1, 2, 3)), - Flow("flow:1,2,3", (1, 2, 3)), - ) - - with pytest.raises(RunnerError, match="color-flow words must be unique"): - derive_selector_contract( - runtime, - (((1.0, 0.0, 0.0, 1.0),),), - ) - - -def test_selector_contract_rejects_noncanonical_physical_axis_ids() -> None: - runtime = FakeRuntime() - runtime.physics.color_flows = ( - Flow("opaque", (1, 2, 3)), - Flow("flow:2,1,3", (2, 1, 3)), - ) - with pytest.raises(RunnerError, match="flow ID does not encode"): - derive_selector_contract( - runtime, - (((1.0, 0.0, 0.0, 1.0),),), - ) - - runtime = FakeRuntime() - runtime.physics.helicities = ( - Helicity("opaque", (-1, 1, -1)), - Helicity("h:-1,-1,-1", (-1, -1, -1)), - ) - with pytest.raises(RunnerError, match="helicity ID does not encode"): - derive_selector_contract( - runtime, - (((1.0, 0.0, 0.0, 1.0),),), - ) - - -def test_selector_contract_rejects_nonfinite_canonical_component() -> None: - class NonfiniteRuntime(FakeRuntime): - def evaluate_resolved( - self, - _points: object, - **selectors: object, - ) -> Resolved: - assert selectors == { - "color_flows": ("flow:1,2,3",), - "helicities": ("h:-1,+1,-1",), - } - return Resolved( - ((((complex(float("nan"), 0.0),),),)), - self.resolved_total, - ) - - with pytest.raises(RunnerError, match="non-finite component"): - derive_selector_contract( - NonfiniteRuntime(), - (((1.0, 0.0, 0.0, 1.0),),), - ) - - -def test_selector_contract_rejects_all_zero_canonical_components() -> None: - class ZeroRuntime(FakeRuntime): - def evaluate_resolved( - self, - _points: object, - **_selectors: object, - ) -> Resolved: - return Resolved( - ( - ( - (0.0 + 0.0j,), - (0.0 + 0.0j,), - ), - ), - self.resolved_total, - ) - - with pytest.raises( - RunnerError, - match="canonical fixed-helicity selector is zero", - ): - derive_selector_contract( - ZeroRuntime(), - (((1.0, 0.0, 0.0, 1.0),),), - ) - - -def test_selector_contract_rejects_changed_point_or_axis() -> None: - runtime = FakeRuntime() - points = (((1.0, 0.0, 0.0, 1.0),),) - contract = derive_selector_contract(runtime, points) - - with pytest.raises(RunnerError, match="measurement point differ"): - validate_selector_contract( - runtime, - contract, - (((2.0, 0.0, 0.0, 2.0),),), - ) - - runtime.physics.color_flows = (Flow("different", (2, 1, 3)),) - with pytest.raises(RunnerError, match="selected physical flow"): - validate_selector_contract(runtime, contract, points) - - -def test_selector_contract_maps_only_exact_signed_zero_runtime_alias() -> None: - runtime = FakeRuntime() - points = (((1.0, 0.0, 0.0, 1.0),),) - runtime.physics.external_particles = tuple( - Particle(label, 23 if label == 6 else 1) - for label in range(1, 7) - ) - runtime.physics.helicities = ( - Helicity( - "h:-1,+1,-1,+1,-1,+0", - (-1, 1, -1, 1, -1, 0), - ), - ) - contract = SelectorContract( - selected_color_flow_ids=("flow:2,1,3",), - selected_color_words=((2, 1, 3),), - all_flow_helicity_ids=("h:-1,+1,-1,+1,-1,0",), - all_flow_source_helicities=( - (1, -1), - (2, 1), - (3, -1), - (4, 1), - (5, -1), - (6, 0), - ), - point_digest=point_digest(points), - ) - - assert contract.runtime_all_flow_helicity_ids == ("h:-1,+1,-1,+1,-1,+0",) - validate_selector_contract(runtime, contract, points) - assert _selector_kwargs( - _cell(ExecutionMode.RECURRENCE, Accuracy.LC, Workload.ALL_FLOW), - contract, - ) == { - "helicities": ("h:-1,+1,-1,+1,-1,+0",), - "color_flows": None, - } - - changed = SelectorContract( - selected_color_flow_ids=contract.selected_color_flow_ids, - selected_color_words=contract.selected_color_words, - all_flow_helicity_ids=("h:+1,+1,-1,+1,-1,0",), - all_flow_source_helicities=contract.all_flow_source_helicities, - point_digest=contract.point_digest, - ) - assert changed.runtime_all_flow_helicity_ids == changed.all_flow_helicity_ids - with pytest.raises(RunnerError, match="selected physical helicity"): - validate_selector_contract(runtime, changed, points) - - -def test_runtime_contract_requires_both_lc_selector_axes() -> None: - runtime = FakeRuntime() - cell = _cell( - ExecutionMode.RECURRENCE, - Accuracy.LC, - Workload.SELECTED_FLOW, - ) - validate_runtime_contract(cell, runtime) - - runtime.physics.selector_capabilities = ("helicity",) - with pytest.raises(RunnerError, match="color_flow"): - validate_runtime_contract(cell, runtime) - - -def test_artifact_contract_rejects_generation_specialization( - monkeypatch: pytest.MonkeyPatch, -) -> None: - cell = _cell( - ExecutionMode.RECURRENCE, - Accuracy.LC, - Workload.SELECTED_FLOW, - ) - process = SimpleNamespace( - execution_mode="recurrence", - generation_specialized_axes=(), - selected_source_helicities=(), - selected_color_sector_ids=(), - lc_flow_layout="topology-replay", - ) - inspection = SimpleNamespace(processes=(process,)) - inspection.runtime_capabilities = ( - "rusticol.recurrence-direct-arena.complex-f64.v1", - ) - monkeypatch.setattr( - "pyamplicol.artifacts.inspect_artifact", - lambda _path: inspection, - ) - validate_artifact_contract(cell, Path("/artifact")) - - process.generation_specialized_axes = ("color_flow",) - with pytest.raises(RunnerError, match="complete runtime coverage"): - validate_artifact_contract(cell, Path("/artifact")) - - -@pytest.mark.parametrize( - ("cell", "capability", "expected_evaluator_abi", "optimization_identity"), - ( - ( - _cell( - ExecutionMode.RECURRENCE, - Accuracy.LC, - Workload.SELECTED_FLOW, - ), - "rusticol.recurrence-direct-arena.complex-f64.v1", - "pyamplicol-recurrence-runtime-layout-v2", - {"source_jit_optimization_level": 2}, - ), - ( - _cell( - ExecutionMode.EAGER, - Accuracy.LC, - Workload.SELECTED_FLOW, - ), - "eager-direct-arena-v1", - "pyamplicol-eager-plane-table-binding-v2", - {"source_jit_optimization_level": 2}, - ), - ( - next( - cell - for cell in REPORT_CATALOG.z_cells() - if cell.variant == "jit_o1" and cell.workload is Workload.SELECTED_FLOW - ), - "compiled-plane-arena-v1", - "pyamplicol-compiled-plane-kernel-v2", - { - "source_jit_optimization_level": 1, - "direct_codegen_optimization_level": 1, - }, - ), - ( - next( - cell - for cell in REPORT_CATALOG.z_cells() - if cell.variant == "cpp_o3" and cell.workload is Workload.SELECTED_FLOW - ), - "compiled-plane-arena-v1", - "pyamplicol-native-compiled-direct-application-v1", - {}, - ), - ), -) -def test_runtime_identity_binds_native_artifact_and_arena( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, - cell: CellSpec, - capability: str, - expected_evaluator_abi: str, - optimization_identity: dict[str, int], -) -> None: - import pyamplicol - - artifact_id = "a" * 64 - manifest = SimpleNamespace( - artifact_id=artifact_id, - processes=( - { - "id": "process-1", - "required_runtime_capabilities": [capability], - }, - ), - runtime={"engine_version": "0.1.0.test"}, - ) - candidate_source_revision = "d" * 40 - measurement_source_revision = "e" * 40 - package_root = tmp_path / "pyamplicol" - package_root.mkdir() - package_init = package_root / "__init__.py" - package_init.write_bytes(b"") - (package_root / "api.py").write_bytes(b"VALUE=1\n") - (package_root / "ignored.pyo").write_bytes(b"ignored") - cache = package_root / "__pycache__" - cache.mkdir() - (cache / "ignored.pyc").write_bytes(b"ignored") - native_path = package_root / "_rusticol.so" - native_path.write_bytes(b"native") - native = SimpleNamespace( - __file__=str(native_path), - package_version=lambda: pyamplicol.__version__, - native_build_inputs_sha256=lambda: "b" * 64, - target_info=lambda: SimpleNamespace( - triple="aarch64-apple-darwin", - cpu_features=("neon",), - ), - ) - package_records = [ - { - "root_index": 0, - "path": path.name, - "size": path.stat().st_size, - "sha256": hashlib.sha256(path.read_bytes()).hexdigest(), - } - for path in (package_init, native_path, package_root / "api.py") - ] - bytecode_policy = { - "kind": "pyamplicol-source-only-bytecode-policy-v1", - "dont_write_bytecode": True, - "external_pycache_prefix": True, - "external_pycache_prefix_absent": True, - "package_local_bytecode_eligible": False, - "isolated_startup": True, - "site_initialization": False, - "python_environment_ignored_at_startup": True, - } - package_tree_identity = { - "kind": "pyamplicol-python-package-tree-v2", - "root": str(package_root.resolve()), - "roots": [str(package_root.resolve())], - "file_count": 3, - "total_bytes": sum(record["size"] for record in package_records), - "sha256": hashlib.sha256( - json.dumps( - package_records, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest(), - "member_set_stable": True, - "namespace_bound_to_root_fd": True, - "bytecode_policy": bytecode_policy, - } - native_identity = { - "path": str(native_path.resolve()), - "size": native_path.stat().st_size, - "sha256": hashlib.sha256(native_path.read_bytes()).hexdigest(), - } - loaded_origin_policy = { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": 1, - "observations": [ - { - "module": "pyamplicol", - "kind": "package-member", - "root_index": 0, - "path": "__init__.py", - "size": 0, - "sha256": hashlib.sha256(b"").hexdigest(), - } - ], - } - loaded_origin_policy["observations_sha256"] = _digest_json( - loaded_origin_policy["observations"] - ) - monkeypatch.setattr( - "pyamplicol.artifacts.load_manifest", - lambda _path, *, verify_payloads: manifest, - ) - monkeypatch.setattr( - "tools.performance_report.runner.importlib.import_module", - lambda name: native if name == "pyamplicol._rusticol" else None, - ) - monkeypatch.setattr( - "pyamplicol._internal.versions._active_build_info", - lambda: { - "schema_version": 1, - "version": pyamplicol.__version__, - "candidate_fingerprint": "candidate", - "source_revision": candidate_source_revision, - "source_checkout": "/repo", - "native_build_inputs_sha256": "b" * 64, - "publishable": False, - }, - ) - monkeypatch.setattr(pyamplicol, "__file__", str(package_init)) - monkeypatch.setattr(pyamplicol, "__path__", [str(package_root)]) - monkeypatch.setattr( - "tools.performance_report.runner.established_preimport_runtime_identity", - lambda: { - "kind": "pyamplicol-preimport-runtime-identity-v1", - "python_package_tree": package_tree_identity, - "native_extension": native_identity, - }, - ) - monkeypatch.setattr( - "tools.performance_report.runner.python_package_tree_identity", - lambda roots: ( - package_tree_identity - if tuple(roots) == (package_root,) - else pytest.fail(f"unexpected package roots: {roots}") - ), - ) - monkeypatch.setattr( - "tools.performance_report.runner.loaded_pyamplicol_origin_policy", - lambda roots, **kwargs: ( - loaded_origin_policy - if ( - tuple(roots) == (package_root,) - and kwargs["native_extension"] == native_path - and kwargs["expected_package_identity"] == package_tree_identity - and kwargs["expected_native_identity"] == native_identity - ) - else pytest.fail("unexpected loaded-origin evidence request") - ), - ) - - def direct_identity( - _manifest: object, - *, - process_id: str, - source_optimization_level: int, - ) -> dict[str, object]: - assert process_id == "process-1" - return { - "kind": "authenticated-compiled-plane-arena-direct-codegen-v1", - "optimization_level": source_optimization_level, - "source_optimization_level": source_optimization_level, - "leaf_count": 2, - "execution_manifest_path": "execution.json", - "execution_manifest_sha256": "e" * 64, - } - - monkeypatch.setattr( - "tools.performance_report.runner._authenticated_direct_codegen_identity", - direct_identity, - ) - - recurrence_identity = { - "kind": "authenticated-recurrence-direct-template-source-v1", - "optimization_level": 2, - "direct_template_count": 5, - "prepared_direct_template_count": 3, - "source_evaluator_leaf_count": 4, - "source_application_abi": "pyamplicol-symjit-plane-application-v2", - "direct_application_abi": "pyamplicol-symjit-plane-application-v2", - "prepared_kernel_pack_digest": "7" * 64, - "direct_template_catalog_digest": "8" * 64, - "execution_manifest_path": "processes/process-1/execution.json", - "execution_manifest_sha256": "f" * 64, - "kernel_pack_path": "model/eager-kernel-pack.json", - "kernel_pack_sha256": "9" * 64, - } - monkeypatch.setattr( - "tools.performance_report.runner._authenticated_recurrence_source_identity", - lambda _manifest, *, process_id, source_optimization_level: ( - recurrence_identity - if process_id == "process-1" and source_optimization_level == 2 - else pytest.fail("unexpected recurrence identity request") - ), - ) - - identity = runtime_identity_payload( - cell, - SimpleNamespace( - artifact_id=artifact_id, - execution_mode=cell.measurement.execution_mode.value, - ), - Path("/artifact"), - "process-1", - expected_source_revision=measurement_source_revision, - ) - - assert identity["artifact_id"] == artifact_id - assert identity["loaded_artifact_id"] == artifact_id - assert identity["loaded_execution_mode"] == cell.measurement.execution_mode.value - assert identity["required_arena_capability"] == capability - assert identity["expected_evaluator_abi"] == expected_evaluator_abi - expected_source_abi = ( - "pyamplicol-native-compiled-direct-application-v1" - if ( - cell.measurement.execution_mode is ExecutionMode.COMPILED - and cell.measurement.backend != "jit" - ) - else { - "jit": "pyamplicol-symjit-plane-application-v2", - "cpp": "symbolica.compiled-cpp.complex-f64.v1", - "asm": "symbolica.compiled-asm.complex-f64.v1", - }[cell.measurement.backend] - ) - assert identity["expected_source_evaluator_abi"] == expected_source_abi - assert ( - identity["expected_source_evaluator_runtime_capability"] - == { - "jit": "symjit.application.complex-f64.v1", - "cpp": "symbolica.compiled-cpp.complex-f64.v1", - "asm": "symbolica.compiled-asm.complex-f64.v1", - }[cell.measurement.backend] - ) - assert identity["native_build_inputs_sha256"] == "b" * 64 - assert identity["source_revision"] == measurement_source_revision - assert ( - identity["candidate_build_identity"]["source_revision"] - == candidate_source_revision - ) - package_tree = identity["python_package_tree"] - assert package_tree == package_tree_identity - assert identity["loaded_module_origin_policy"] == loaded_origin_policy - for field in ( - "source_jit_optimization_level", - "direct_codegen_optimization_level", - ): - if field in optimization_identity: - assert identity[field] == optimization_identity[field] - else: - assert field not in identity - if cell.measurement.execution_mode is ExecutionMode.COMPILED and ( - cell.measurement.backend == "jit" - ): - assert identity["direct_codegen_identity"] == { - "kind": "authenticated-compiled-plane-arena-direct-codegen-v1", - "optimization_level": cell.measurement.jit_optimization_level, - "source_optimization_level": cell.measurement.jit_optimization_level, - "leaf_count": 2, - "execution_manifest_path": "execution.json", - "execution_manifest_sha256": "e" * 64, - } - else: - assert "direct_codegen_identity" not in identity - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - assert identity["source_jit_identity"] == recurrence_identity - else: - assert "source_jit_identity" not in identity - - with pytest.raises(RunnerError, match="loaded artifact identity"): - runtime_identity_payload( - cell, - SimpleNamespace( - artifact_id="c" * 64, - execution_mode=cell.measurement.execution_mode.value, - ), - Path("/artifact"), - "process-1", - expected_source_revision=measurement_source_revision, - ) - - mismatched_mode = ( - "compiled" - if cell.measurement.execution_mode is not ExecutionMode.COMPILED - else "eager" - ) - with pytest.raises(RunnerError, match="loaded execution mode"): - runtime_identity_payload( - cell, - SimpleNamespace( - artifact_id=artifact_id, - execution_mode=mismatched_mode, - ), - Path("/artifact"), - "process-1", - expected_source_revision=measurement_source_revision, - ) - - with pytest.raises(RunnerError, match=r"does not expose.*execution mode"): - runtime_identity_payload( - cell, - SimpleNamespace(artifact_id=artifact_id), - Path("/artifact"), - "process-1", - expected_source_revision=measurement_source_revision, - ) - - -def test_direct_codegen_identity_follows_authenticated_process_index( - tmp_path: Path, -) -> None: - process_id = "process-1" - index_relative = "processes/evaluators.json" - execution_entry_relative = f"{process_id}/execution.json" - execution_relative = f"processes/{execution_entry_relative}" - execution = { - "kind": "pyamplicol-runtime-execution", - "compiled": { - "stage_evaluators": { - "amplitude_stage": { - "evaluator": _canonical_symjit_evaluator( - "evaluators/amplitude.symjit", - "evaluators/amplitude.plane.symjit", - optimization_level=1, - ), - "compiled_plane_arena": { - "leaves": [ - { - "application_path": ( - "evaluators/amplitude.plane.symjit" - ), - "source_application_abi": ( - "pyamplicol-symjit-plane-application-v2" - ), - "optimization_level": 1, - "direct_codegen_optimization_level": 1, - } - ] - }, - } - } - }, - } - evaluator_index = { - "schema_version": 3, - "kind": "pyamplicol-runtime-execution-set", - "processes": [ - { - "process_id": process_id, - "manifest_path": execution_entry_relative, - "required_runtime_capabilities": ["compiled-plane-arena-v1"], - } - ], - } - - def payload( - relative: str, - value: dict[str, object], - *, - payload_process_id: str | None, - ) -> SimpleNamespace: - data = json.dumps( - value, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - path = tmp_path / relative - path.parent.mkdir(parents=True, exist_ok=True) - path.write_bytes(data) - return SimpleNamespace( - path=relative, - role="evaluator-manifest", - media_type="application/json", - size_bytes=len(data), - sha256=hashlib.sha256(data).hexdigest(), - executable=False, - process_id=payload_process_id, - ) - - index_payload = payload( - index_relative, - evaluator_index, - payload_process_id=None, - ) - execution_payload = payload( - execution_relative, - execution, - payload_process_id=process_id, - ) - manifest = SimpleNamespace( - root=tmp_path, - runtime={"evaluator_manifest_path": index_relative}, - payloads=(index_payload, execution_payload), - ) - - identity = _authenticated_direct_codegen_identity( - manifest, - process_id=process_id, - source_optimization_level=1, - ) - - assert identity == { - "kind": "authenticated-compiled-plane-arena-direct-codegen-v1", - "optimization_level": 1, - "source_optimization_level": 1, - "leaf_count": 1, - "execution_manifest_path": execution_relative, - "execution_manifest_sha256": execution_payload.sha256, - } - - -def test_recurrence_source_identity_follows_authenticated_direct_template_pack( - tmp_path: Path, -) -> None: - process_id = "process-1" - index_relative = "processes/evaluators.json" - execution_relative = f"processes/{process_id}/execution.json" - pack_relative = "model/eager-kernel-pack.json" - source_relative = "model/eager-kernels/kernels/000000/application-0.plane.symjit" - source_data = b"authenticated-symjit-application" - source_sha256 = hashlib.sha256(source_data).hexdigest() - execution, pack = _recurrence_source_fixture(source_sha256) - evaluator_index = { - "schema_version": 3, - "kind": "pyamplicol-runtime-execution-set", - "processes": [ - { - "process_id": process_id, - "manifest_path": f"{process_id}/execution.json", - } - ], - } - - def payload( - relative: str, - value: dict[str, object], - *, - payload_process_id: str | None, - ) -> SimpleNamespace: - data = json.dumps( - value, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - path = tmp_path / relative - path.parent.mkdir(parents=True, exist_ok=True) - path.write_bytes(data) - return SimpleNamespace( - path=relative, - role="evaluator-manifest", - media_type="application/json", - size_bytes=len(data), - sha256=hashlib.sha256(data).hexdigest(), - executable=False, - process_id=payload_process_id, - ) - - index_payload = payload( - index_relative, - evaluator_index, - payload_process_id=None, - ) - execution_payload = payload( - execution_relative, - execution, - payload_process_id=process_id, - ) - pack_payload = payload( - pack_relative, - pack, - payload_process_id=None, - ) - source_path = tmp_path / source_relative - source_path.parent.mkdir(parents=True, exist_ok=True) - source_path.write_bytes(source_data) - source_payload = SimpleNamespace( - path=source_relative, - role="evaluator-state", - media_type="application/octet-stream", - size_bytes=len(source_data), - sha256=source_sha256, - executable=False, - process_id=None, - ) - manifest = SimpleNamespace( - root=tmp_path, - runtime={"evaluator_manifest_path": index_relative}, - payloads=(index_payload, execution_payload, pack_payload, source_payload), - extensions={}, - ) - - identity = _authenticated_recurrence_source_identity( - manifest, - process_id=process_id, - source_optimization_level=2, - ) - - assert identity == { - "kind": "authenticated-recurrence-direct-template-source-v1", - "optimization_level": 2, - "direct_template_count": 2, - "prepared_direct_template_count": 1, - "source_evaluator_leaf_count": 1, - "source_application_abi": "pyamplicol-symjit-plane-application-v2", - "direct_application_abi": "pyamplicol-symjit-plane-application-v2", - "prepared_kernel_pack_digest": "a" * 64, - "direct_template_catalog_digest": execution["direct_template_catalog_digest"], - "execution_manifest_path": execution_relative, - "execution_manifest_sha256": execution_payload.sha256, - "kernel_pack_path": pack_relative, - "kernel_pack_sha256": pack_payload.sha256, - } - - catalog = pack["recurrence_direct_template"] - assert isinstance(catalog, dict) - templates = catalog["templates"] - assert isinstance(templates, list) - template = templates[1] - assert isinstance(template, dict) - template["optimization_level"] = 1 - _refresh_recurrence_catalog(execution, pack) - replacement = json.dumps( - pack, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - (tmp_path / pack_relative).write_bytes(replacement) - pack_payload.size_bytes = len(replacement) - pack_payload.sha256 = hashlib.sha256(replacement).hexdigest() - execution_replacement = json.dumps( - execution, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - (tmp_path / execution_relative).write_bytes(execution_replacement) - execution_payload.size_bytes = len(execution_replacement) - execution_payload.sha256 = hashlib.sha256(execution_replacement).hexdigest() - with pytest.raises(RunnerError, match="template 1 contract"): - _authenticated_recurrence_source_identity( - manifest, - process_id=process_id, - source_optimization_level=2, - ) - - -@pytest.mark.parametrize( - ("corruption", "message"), - ( - ("execution_template_abi", "direct_template_abi"), - ("plan_template_abi", "direct_template_abi"), - ("execution_backend_abi", "direct_backend_abi"), - ("plan_backend_abi", "direct_backend_abi"), - ("plan_prepared_digest", "source digests"), - ("plan_catalog_digest", "source digests"), - ("pack_prepared_digest", "kernel-pack digests"), - ("execution_catalog_link", "kernel-pack digests"), - ("catalog_backend_abi", "optimization identity"), - ("catalog_canonicalization_abi", "optimization identity"), - ("catalog_digest", "catalog digest"), - ("template_portable", "template 0 contract"), - ("template_abi", "template 0 contract"), - ("binding_abi", "payload-binding contract"), - ("source_application_abi", "source application"), - ("direct_application_abi", "source application"), - ("payload_digest", "payload-binding contract"), - ("intrinsic_source_application_abi", "intrinsic source contract"), - ("intrinsic_direct_application_abi", "intrinsic source contract"), - ("source_leaf_runtime_capability", "source evaluator leaf contract"), - ("source_leaf_application_abi", "source evaluator leaf contract"), - ("source_leaf_optimization", "source evaluator leaf contract"), - ("source_leaf_path", "payload is missing"), - ("source_payload_digest_link", "not bound to its prepared kernel"), - ), -) -def test_recurrence_source_identity_rejects_every_broken_link( - tmp_path: Path, - corruption: str, - message: str, -) -> None: - ( - manifest, - execution, - pack, - execution_payload, - pack_payload, - ) = _runner_recurrence_artifact(tmp_path) - plan = execution["plan"] - assert isinstance(plan, dict) - catalog = pack["recurrence_direct_template"] - assert isinstance(catalog, dict) - templates = catalog["templates"] - assert isinstance(templates, list) - prepared = templates[0] - intrinsic = templates[1] - assert isinstance(prepared, dict) - assert isinstance(intrinsic, dict) - prepared_binding = prepared["payload_binding"] - intrinsic_binding = intrinsic["payload_binding"] - assert isinstance(prepared_binding, dict) - assert isinstance(intrinsic_binding, dict) - kernels = pack["kernels"] - assert isinstance(kernels, list) - kernel = kernels[0] - assert isinstance(kernel, dict) - source_leaf = kernel["f64_evaluator_manifest"] - assert isinstance(source_leaf, dict) - refresh_catalog: bool | None = None - - if corruption == "execution_template_abi": - execution["direct_template_abi"] = "wrong" - elif corruption == "plan_template_abi": - plan["direct_template_abi"] = "wrong" - elif corruption == "execution_backend_abi": - execution["direct_backend_abi"] = "wrong" - elif corruption == "plan_backend_abi": - plan["direct_backend_abi"] = "wrong" - elif corruption == "plan_prepared_digest": - plan["prepared_kernel_pack_digest"] = "0" * 64 - elif corruption == "plan_catalog_digest": - plan["direct_template_catalog_digest"] = "0" * 64 - elif corruption == "pack_prepared_digest": - catalog["prepared_kernel_pack_digest"] = "0" * 64 - refresh_catalog = True - elif corruption == "execution_catalog_link": - execution["direct_template_catalog_digest"] = "0" * 64 - plan["direct_template_catalog_digest"] = "0" * 64 - elif corruption == "catalog_backend_abi": - catalog["backend_abi"] = "wrong" - refresh_catalog = True - elif corruption == "catalog_canonicalization_abi": - catalog["canonicalization_abi"] = "wrong" - refresh_catalog = True - elif corruption == "catalog_digest": - catalog["compiled_model_digest"] = "0" * 64 - elif corruption == "template_portable": - prepared["portable"] = False - refresh_catalog = True - elif corruption == "template_abi": - prepared["abi"] = "wrong" - refresh_catalog = True - elif corruption == "binding_abi": - prepared_binding["abi"] = "wrong" - refresh_catalog = True - elif corruption == "source_application_abi": - prepared_binding["source_application_abi"] = "wrong" - refresh_catalog = True - elif corruption == "direct_application_abi": - prepared_binding["direct_application_abi"] = "wrong" - refresh_catalog = True - elif corruption == "payload_digest": - prepared_binding["payload_digest"] = "0" * 64 - refresh_catalog = False - elif corruption == "intrinsic_source_application_abi": - intrinsic_binding["source_application_abi"] = "symjit-application-storage-v3" - refresh_catalog = True - elif corruption == "intrinsic_direct_application_abi": - intrinsic_binding["direct_application_abi"] = ( - "pyamplicol-symjit-plane-application-v0" - ) - refresh_catalog = True - elif corruption == "source_leaf_runtime_capability": - source_leaf["runtime_capability"] = "wrong" - elif corruption == "source_leaf_application_abi": - source_leaf["application_abi"] = "wrong" - elif corruption == "source_leaf_optimization": - source_leaf["optimization_level"] = 1 - elif corruption == "source_leaf_path": - plane = source_leaf["plane_application"] - assert isinstance(plane, dict) - plane["application_path"] = "kernels/000000/missing.plane.symjit" - elif corruption == "source_payload_digest_link": - prepared_binding["source_application_sha256"] = "0" * 64 - refresh_catalog = True - else: - pytest.fail(f"unknown corruption {corruption}") - - if refresh_catalog is not None: - _refresh_recurrence_catalog( - execution, - pack, - refresh_binding_digests=refresh_catalog, - ) - _rewrite_json_payload(tmp_path, execution_payload, execution) - _rewrite_json_payload(tmp_path, pack_payload, pack) - with pytest.raises(RunnerError, match=message): - _authenticated_recurrence_source_identity( - manifest, - process_id="process-1", - source_optimization_level=2, - ) - - -def test_resolved_sum_validation_and_pointwise_tolerances() -> None: - runtime = FakeRuntime() - points = (((1.0, 0.0, 0.0, 1.0),),) - contract = derive_selector_contract(runtime, points) - cell = _cell( - ExecutionMode.RECURRENCE, - Accuracy.LC, - Workload.SELECTED_FLOW, - ) - - assert ( - resolved_sum_validation( - runtime, - points, - cell=cell, - selector_contract=contract, - )["status"] - == "ok" - ) - runtime.resolved_total = (2.0 + 0.0j,) - assert ( - resolved_sum_validation( - runtime, - points, - cell=cell, - selector_contract=contract, - )["status"] - == "validation_failed" - ) - - assert pointwise_validation(1.0 + 1.0e-13, 1.0)["status"] == "ok" - assert pointwise_validation(2.0, 1.0)["status"] == "validation_failed" - - -def test_matrix_element_conversion_rejects_sign_and_complex_drift() -> None: - assert _real_nonnegative(2.0 + 0.0j) == 2.0 - assert _real_nonnegative(-1.0e-16 + 0.0j) == 0.0 - with pytest.raises(RunnerError, match="materially negative"): - _real_nonnegative(-1.0e-3 + 0.0j) - with pytest.raises(RunnerError, match="imaginary part"): - _real_nonnegative(1.0 + 1.0e-3j) diff --git a/pyamplicol/tests/unit/test_three_mode_report_scheduler.py b/pyamplicol/tests/unit/test_three_mode_report_scheduler.py deleted file mode 100644 index 03fcf4950e..0000000000 --- a/pyamplicol/tests/unit/test_three_mode_report_scheduler.py +++ /dev/null @@ -1,3736 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import json -import subprocess -import threading -from collections.abc import Mapping, Sequence -from copy import deepcopy -from pathlib import Path - -import pytest - -from tools.performance_report.agreements import ( - DIRECT_AGREEMENT_FIELD, - INDEPENDENT_AUTHORITY_FIELD, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, - independent_numerical_authorities, -) -from tools.performance_report.artifacts import ( - ArtifactAttempt, - ArtifactStore, - CurrentRecord, - DiskFullError, -) -from tools.performance_report.cache import digest_json, empty_measurement -from tools.performance_report.campaign_policy import ( - MACBOOK_M3_MEMORY_LIMIT_BYTES, - MACBOOK_M3_Z_TABLE_F_POLICY, - X86_EPYC_MEMORY_LIMIT_BYTES, - X86_EPYC_NATIVE_COMPILER_SLOTS, - X86_EPYC_POLICY, - X86_EPYC_PROFILE, - X86_EPYC_WORKERS, - PolicyMeasurementState, - policy_status_label, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.measurement import failure_measurement -from tools.performance_report.models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from tools.performance_report.phase_state import WorkerPhaseChannel -from tools.performance_report.resources import ( - GenerationPhaseEvidence, - ResourceUsage, - SupervisedResult, - WorkerObservation, -) -from tools.performance_report.runner import pointwise_validation -from tools.performance_report.scheduler import ( - CampaignResult, - CampaignScheduler, - CampaignSettings, - CellOutcome, - CellSelection, - PlannedCell, - _CoordinationDeferred, - _fresh_equivalent_current, - _partition_dependency_records, - _PreparationFailed, - _symbolica_generation_lock_path, - _worker_environment_overrides, - plan_campaign, - select_cells, -) -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import ReportSourceIdentity - - -def _store(tmp_path: Path) -> ArtifactStore: - return ArtifactStore( - artifact_root=tmp_path / "artifacts", - lock_root=tmp_path / "locks", - ) - - -def test_epyc_worker_environment_injects_shared_native_compiler_gate( - tmp_path: Path, -) -> None: - settings = CampaignSettings( - workers=X86_EPYC_WORKERS, - cell_cores=1, - target_runtime_seconds=5.0, - max_rss_bytes=X86_EPYC_MEMORY_LIMIT_BYTES, - allow_symbolica_parallel=True, - campaign_policy=X86_EPYC_POLICY, - report_profile=X86_EPYC_PROFILE, - ) - - assert _worker_environment_overrides(settings, tmp_path / "coordination") == { - "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR": str( - (tmp_path / "coordination" / "native-compiler-slots").resolve() - ), - "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT": str(X86_EPYC_NATIVE_COMPILER_SLOTS), - } - assert ( - _worker_environment_overrides( - CampaignSettings(), - tmp_path / "strict-coordination", - ) - == {} - ) - - ufo_compiled = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.model is ModelKey.UFO_SM - and cell.measurement.execution_mode is ExecutionMode.COMPILED - ) - strict_root = tmp_path / "strict-coordination" - assert ( - _symbolica_generation_lock_path( - CampaignSettings(), - strict_root, - ufo_compiled, - ) - == (strict_root / "symbolica-ufo-compiled-generation.lock").resolve() - ) - assert ( - _symbolica_generation_lock_path( - CampaignSettings(allow_symbolica_parallel=True), - strict_root, - ufo_compiled, - ) - is None - ) - - -def _ok_measurement( - cell: CellSpec | None = None, - *, - revision: str | None = None, -) -> dict[str, object]: - measurement = empty_measurement() - selector = ( - None - if cell is None or cell.measurement.accuracy is not Accuracy.LC - else { - "selected_color_flow_ids": ["flow:2,1"], - "selected_color_words": [[2, 1]], - "all_flow_helicity_ids": ["h:-1,+1,-1"], - "all_flow_source_helicities": {"1": -1, "2": 1, "3": -1}, - "point_digest": "a" * 64, - } - ) - validation: dict[str, object] = { - "status": ResultStatus.OK.value, - DIRECT_AGREEMENT_FIELD: [], - } - if cell is not None and ( - cell.dataset_id in {"scalar_contact", "scalar_gravity"} - or cell.measurement.execution_mode is ExecutionMode.RECURRENCE - ): - point_identity = "a" * 64 - ordering = "b" * 64 - - def resolved_record(precision: int, source: str) -> dict[str, object]: - point = pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "point_index": 0, - }, - ) - return { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": ResultStatus.OK.value, - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": point_identity, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "scale_source": "resolved-component-l1", - "precision_digits": precision, - "points": [point], - } - - binary64 = resolved_record(16, "c" * 64) - p32 = resolved_record(32, "d" * 64) - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": selector, - "value_kind": "matrix-element-p16-versus-p32", - } - validation.update( - { - "resolved_sum": binary64, - "high_precision_resolved_sum": p32, - "high_precision": pointwise_validation( - 1.0, - 1.0, - candidate_scale=1.0, - baseline_scale=1.0, - candidate_scale_source="resolved-component-l1-binary64", - baseline_scale_source="resolved-component-l1-p32", - comparison_binding={ - "point_digest": point_identity, - "selector_component_identity": selector_identity, - "selector_component_sha256": digest_json(selector_identity), - "candidate_source_sha256": "c" * 64, - "baseline_source_sha256": "d" * 64, - }, - ), - } - ) - if selector is not None: - assert cell is not None - validation[LC_COMMON_COMPONENT_FIELD] = { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell.cell_id, - "value": 1.0, - "point_digest": selector["point_digest"], - "helicity_ids": selector["all_flow_helicity_ids"], - "color_flow_ids": selector["selected_color_flow_ids"], - } - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": 1.0, - "wall_seconds_per_point": 1.0e-6, - "execution_seconds_per_point": 8.0e-7, - "matrix_element": 1.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": {}, - "selector_contract": selector, - "validation": validation, - "resources": {}, - "provenance": ( - {} if revision is None else {"report_source_revision": revision} - ), - } - ) - return measurement - - -def test_selection_combines_all_supported_filter_axes() -> None: - selected = select_cells( - CellSelection( - datasets=frozenset({"matrix_eager_builtin_sm_lc"}), - modes=frozenset({ExecutionMode.EAGER}), - models=frozenset({ModelKey.BUILTIN_SM}), - accuracies=frozenset({Accuracy.LC}), - process_keys=frozenset({"dd_z_jets"}), - multiplicities=frozenset({3}), - workloads=frozenset({Workload.ALL_FLOW}), - ) - ) - - assert len(selected) == 1 - assert selected[0].cell_id.endswith("all-flow") - - -def test_variant_selection_only_filters_cells_with_a_variant_dimension() -> None: - selected = select_cells( - CellSelection( - modes=frozenset({ExecutionMode.COMPILED}), - multiplicities=frozenset({8, 9}), - variants=frozenset({"jit_o3"}), - ) - ) - - assert any(cell.dataset_id == "matrix_compiled_builtin_sm_lc" for cell in selected) - assert any(cell.dataset_id == "z_builtin_sm" for cell in selected) - assert all(cell.variant in {None, "jit_o3"} for cell in selected) - assert not any(cell.variant == "jit_o1" for cell in selected) - - -def test_compiled_plan_can_opt_out_of_automatic_numerical_authorities( - tmp_path: Path, -) -> None: - candidate = select_cells( - CellSelection( - datasets=frozenset({"matrix_compiled_builtin_sm_lc"}), - process_keys=frozenset({"dd_z_jets"}), - multiplicities=frozenset({1}), - workloads=frozenset({Workload.SELECTED_FLOW}), - ) - ) - planned = plan_campaign( - candidate, - store=_store(tmp_path), - settings=CampaignSettings(), - ) - - assert len(planned) == 1 - target = planned[0] - assert target.cell.measurement.execution_mode is ExecutionMode.COMPILED - assert not target.dependency - assert target.baseline_cell_id is None - assert target.optional_baseline_cell_id == ( - "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - assert target.numerical_authority_cell_ids == ( - "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow", - ) - assert target.prerequisite_cell_ids == () - - -@pytest.mark.parametrize( - "dataset_id", - ("matrix_compiled_builtin_sm_lc", "matrix_eager_builtin_sm_lc"), -) -def test_automatic_authority_closure_orders_amplicol_recurrence_then_candidate( - dataset_id: str, - tmp_path: Path, -) -> None: - candidate = _matrix_cell(dataset_id) - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - - planned = plan_campaign( - (candidate,), - store=_store(tmp_path), - settings=CampaignSettings( - add_optional_dependencies=True, - original_amplicol_available=True, - ), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert set(by_id) == {candidate.cell_id, recurrence.cell_id, amplicol.cell_id} - assert not by_id[candidate.cell_id].dependency - assert by_id[recurrence.cell_id].dependency - assert by_id[amplicol.cell_id].dependency - assert by_id[amplicol.cell_id].prerequisite_cell_ids == () - assert by_id[recurrence.cell_id].prerequisite_cell_ids == (amplicol.cell_id,) - assert recurrence.cell_id in by_id[candidate.cell_id].prerequisite_cell_ids - assert by_id[amplicol.cell_id].rank < by_id[recurrence.cell_id].rank - assert by_id[recurrence.cell_id].rank < by_id[candidate.cell_id].rank - - -def test_automatic_authority_closure_without_legacy_adds_recurrence_only( - tmp_path: Path, -) -> None: - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - - planned = plan_campaign( - (candidate,), - store=_store(tmp_path), - settings=CampaignSettings(add_optional_dependencies=True), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert set(by_id) == {candidate.cell_id, recurrence.cell_id} - assert by_id[recurrence.cell_id].dependency - assert by_id[candidate.cell_id].prerequisite_cell_ids == (recurrence.cell_id,) - - -def test_automatic_authority_closure_reuses_active_source_authorities( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - _publish_current(store, recurrence, revision="same") - _publish_current(store, amplicol, revision="same") - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings( - add_optional_dependencies=True, - original_amplicol_available=True, - ), - expected_revision="same", - ) - - assert tuple(item.cell for item in planned) == (candidate,) - - -def test_automatic_authority_closure_replans_historical_authorities( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - _publish_current(store, recurrence, revision="old") - _publish_current(store, amplicol, revision="old") - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings( - add_optional_dependencies=True, - original_amplicol_available=True, - ), - expected_revision="new", - ) - - assert {item.cell.cell_id for item in planned} == { - candidate.cell_id, - recurrence.cell_id, - amplicol.cell_id, - } - - -def test_automatic_authority_closure_reuses_terminal_active_authority( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - terminal = _publish_current(store, recurrence, revision="same") - - def current( - cell: CellSpec, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell == recurrence: - return terminal, PolicyMeasurementState.GENERATION_LIMIT - return None - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(add_optional_dependencies=True), - current_resolver=current, - ) - - assert tuple(item.cell for item in planned) == (candidate,) - assert planned[0].prerequisite_cell_ids == () - assert recurrence.cell_id in planned[0].numerical_authority_cell_ids - - -def test_no_dependencies_added_still_closes_hard_lc_provider_dependency( - tmp_path: Path, -) -> None: - candidate = _matrix_cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - - planned = plan_campaign( - (candidate,), - store=_store(tmp_path), - settings=CampaignSettings(add_optional_dependencies=False), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert candidate.cell_id in by_id - hard_ids = set(by_id[candidate.cell_id].prerequisite_cell_ids) - assert hard_ids - assert all(by_id[cell_id].dependency for cell_id in hard_ids) - assert all( - by_id[cell_id].cell.measurement.execution_mode is ExecutionMode.COMPILED - for cell_id in hard_ids - ) - - -def test_automatic_authority_addition_recursively_closes_its_dependencies( - tmp_path: Path, -) -> None: - candidate = _matrix_cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - recurrence_provider = REPORT_CATALOG.cell( - recurrence.cell_id.replace("all-flow", "selected-flow") - ) - - planned = plan_campaign( - (candidate,), - store=_store(tmp_path), - settings=CampaignSettings(add_optional_dependencies=True), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert recurrence.cell_id in by_id[candidate.cell_id].prerequisite_cell_ids - assert recurrence_provider.cell_id in by_id - assert by_id[recurrence_provider.cell_id].dependency - assert ( - recurrence_provider.cell_id - in by_id[recurrence.cell_id].prerequisite_cell_ids - ) - assert by_id[recurrence_provider.cell_id].rank < by_id[recurrence.cell_id].rank - - -def test_catalog_wide_automatic_authority_closure_is_exact_and_acyclic( - tmp_path: Path, -) -> None: - direct = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - and REPORT_CATALOG.static_na_reason(cell) is None - ) - planned = plan_campaign( - direct, - store=_store(tmp_path), - settings=CampaignSettings( - add_optional_dependencies=True, - original_amplicol_available=True, - ), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert len(by_id) == len(planned) - for candidate in direct: - item = by_id[candidate.cell_id] - for authority in independent_numerical_authorities(candidate): - assert authority.cell_id in by_id - assert by_id[authority.cell_id].rank < item.rank - assert ( - authority.process_key, - authority.n_final, - authority.measurement.accuracy, - authority.workload, - ) == ( - candidate.process_key, - candidate.n_final, - candidate.measurement.accuracy, - candidate.workload, - ) - for item in planned: - assert all( - by_id[prerequisite].rank < item.rank - for prerequisite in item.prerequisite_cell_ids - ) - - -def test_explicit_optional_amplicol_orders_recurrence_without_becoming_hard( - tmp_path: Path, -) -> None: - recurrence = _matrix_cell("matrix_recurrence_builtin_sm_lc") - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - - planned = plan_campaign( - (recurrence, amplicol), - store=_store(tmp_path), - settings=CampaignSettings(), - ) - by_id = {item.cell.cell_id: item for item in planned} - target = by_id[recurrence.cell_id] - - assert set(by_id) == {recurrence.cell_id, amplicol.cell_id} - assert target.baseline_cell_id is None - assert target.optional_baseline_cell_id == amplicol.cell_id - assert target.prerequisite_cell_ids == (amplicol.cell_id,) - assert by_id[amplicol.cell_id].rank < target.rank - - -def test_selected_authority_chain_is_encoded_as_ordering_prerequisites( - tmp_path: Path, -) -> None: - compiled = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(compiled) - assert recurrence is not None - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - eager = _matrix_cell("matrix_eager_builtin_sm_lc") - - planned = plan_campaign( - (compiled, eager, recurrence, amplicol), - store=_store(tmp_path), - settings=CampaignSettings(), - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert by_id[amplicol.cell_id].prerequisite_cell_ids == () - assert by_id[recurrence.cell_id].prerequisite_cell_ids == (amplicol.cell_id,) - for candidate in (compiled, eager): - assert by_id[candidate.cell_id].prerequisite_cell_ids == (recurrence.cell_id,) - - -def test_optional_amplicol_current_is_forwarded_only_when_successful( - tmp_path: Path, -) -> None: - recurrence = _matrix_cell("matrix_recurrence_builtin_sm_lc") - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - record = _publish_current(_store(tmp_path), amplicol, revision="same") - - baseline, peers, blockers = _partition_dependency_records( - baseline_cell_id=None, - comparison_peer_ids=(), - optional_baseline_cell_id=amplicol.cell_id, - currents={ - amplicol.cell_id: (record, PolicyMeasurementState.GENERATION_LIMIT) - }, - ) - assert baseline is None - assert peers == {} - assert blockers == () - - baseline, peers, blockers = _partition_dependency_records( - baseline_cell_id=None, - comparison_peer_ids=(), - optional_baseline_cell_id=amplicol.cell_id, - currents={amplicol.cell_id: (record, PolicyMeasurementState.SUCCESS)}, - ) - assert baseline is record - assert peers == {} - assert blockers == () - - -@pytest.mark.parametrize( - ("state", "expects_baseline"), - ( - (PolicyMeasurementState.SUCCESS, True), - (PolicyMeasurementState.GENERATION_LIMIT, False), - ), -) -def test_scheduler_launches_recurrence_with_only_successful_optional_amplicol( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - state: PolicyMeasurementState, - expects_baseline: bool, -) -> None: - service = _service(tmp_path) - recurrence = _matrix_cell("matrix_recurrence_builtin_sm_lc") - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - optional_record = _publish_current( - service.store, - amplicol, - revision="current-revision", - ) - captured: list[str] = [] - - def current( - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - assert comparison_dependency is (cell == amplicol) - return (optional_record, state) if cell == amplicol else None - - def supervise(command: Sequence[str], **_kwargs: object) -> SupervisedResult: - captured.extend(command) - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_ok_measurement(recurrence, revision="current-revision")) - + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(cell_cores=4, amplicol_build_jobs=1), - ) - scheduler.source_revision = "current-revision" - monkeypatch.setattr(scheduler, "_current", current) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - supervise, - ) - - outcome = scheduler._run_cell( - PlannedCell( - recurrence, - dependency=False, - baseline_cell_id=None, - optional_baseline_cell_id=amplicol.cell_id, - rank=1, - ) - ) - - assert outcome.status == ResultStatus.OK.value - assert ("--baseline-json" in captured) is expects_baseline - assert captured[captured.index("--cell-cores") + 1] == "4" - assert captured[captured.index("--amplicol-build-jobs") + 1] == "1" - - -@pytest.mark.parametrize( - ("variant", "workload"), - ( - ("jit_o1", Workload.SELECTED_FLOW), - ("jit_o1", Workload.ALL_FLOW), - ("eager_jit_o2", Workload.SELECTED_FLOW), - ("eager_jit_o2", Workload.ALL_FLOW), - ), -) -def test_z_compiled_and_eager_plan_recurrence_without_amplicol( - tmp_path: Path, - variant: str, - workload: Workload, -) -> None: - candidate = _z_cell(variant=variant, workload=workload) - baseline = REPORT_CATALOG.validation_baseline_cell(candidate) - assert baseline is not None - - planned = plan_campaign( - (candidate,), - store=_store(tmp_path), - settings=CampaignSettings(), - ) - by_id = {item.cell.cell_id: item for item in planned} - target = by_id[candidate.cell_id] - recurrence_id = target.numerical_authority_cell_ids[0] - - assert target.baseline_cell_id is None - assert target.optional_baseline_cell_id == baseline.cell_id - assert target.numerical_authority_cell_ids == (recurrence_id,) - assert recurrence_id in target.optional_comparison_peer_ids - assert recurrence_id not in by_id - assert recurrence_id not in target.prerequisite_cell_ids - assert all( - item.cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - for item in planned - ) - - -@pytest.mark.parametrize( - ("variant", "workload"), - ( - ("jit_o1", Workload.SELECTED_FLOW), - ("jit_o1", Workload.ALL_FLOW), - ("eager_jit_o2", Workload.SELECTED_FLOW), - ("eager_jit_o2", Workload.ALL_FLOW), - ), -) -@pytest.mark.parametrize( - "recurrence_state", - ( - PolicyMeasurementState.SUCCESS, - PolicyMeasurementState.GENERATION_LIMIT, - None, - ), -) -def test_z_worker_uses_amplicol_only_as_optional_diagnostic( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - variant: str, - workload: Workload, - recurrence_state: PolicyMeasurementState | None, -) -> None: - service = _service(tmp_path) - candidate = _z_cell(variant=variant, workload=workload) - baseline = REPORT_CATALOG.validation_baseline_cell(candidate) - assert baseline is not None - planned = plan_campaign( - (candidate,), - store=service.store, - settings=CampaignSettings(), - ) - target = next(item for item in planned if item.cell == candidate) - recurrence = REPORT_CATALOG.cell(target.numerical_authority_cell_ids[0]) - dependency_records = { - peer_id: _publish_current( - service.store, - REPORT_CATALOG.cell(peer_id), - revision="current-revision", - ) - for peer_id in target.comparison_peer_ids - } - recurrence_record = _publish_current( - service.store, - recurrence, - revision="current-revision", - ) - amplicol_record = _publish_current( - service.store, - baseline, - revision="current-revision", - ) - captured: list[str] = [] - - def current( - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell == candidate: - assert comparison_dependency is False - return None - assert comparison_dependency is True - if cell == baseline: - return amplicol_record, PolicyMeasurementState.SUCCESS - if cell == recurrence: - return ( - None - if recurrence_state is None - else (recurrence_record, recurrence_state) - ) - record = dependency_records.get(cell.cell_id) - return None if record is None else (record, PolicyMeasurementState.SUCCESS) - - def supervise(command: Sequence[str], **_kwargs: object) -> SupervisedResult: - captured.extend(command) - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_ok_measurement(candidate, revision="current-revision")) - + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - scheduler.source_revision = "current-revision" - monkeypatch.setattr(scheduler, "_current", current) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - supervise, - ) - - outcome = scheduler._run_cell(target) - - expected_baseline = ( - recurrence_record - if recurrence_state is PolicyMeasurementState.SUCCESS - else amplicol_record - ) - assert outcome.status == ResultStatus.OK.value - assert captured[captured.index("--baseline-json") + 1] == str( - expected_baseline.result_path - ) - assert ( - tuple( - captured[index + 1] - for index, value in enumerate(captured) - if value == "--expected-authority-cell-id" - ) - == target.numerical_authority_cell_ids - ) - if recurrence_state is PolicyMeasurementState.SUCCESS: - assert captured[captured.index("--selected-authority-cell-id") + 1] == ( - recurrence.cell_id - ) - else: - assert "--selected-authority-cell-id" not in captured - - -@pytest.mark.parametrize( - "recurrence_state", - (None, PolicyMeasurementState.GENERATION_LIMIT), -) -def test_z_worker_runs_when_every_numerical_authority_is_unavailable( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - recurrence_state: PolicyMeasurementState | None, -) -> None: - service = _service(tmp_path) - candidate = _z_cell( - variant="jit_o1", - workload=Workload.SELECTED_FLOW, - ) - baseline = REPORT_CATALOG.validation_baseline_cell(candidate) - assert baseline is not None - planned = plan_campaign( - (candidate,), - store=service.store, - settings=CampaignSettings(), - ) - target = next(item for item in planned if item.cell == candidate) - recurrence = REPORT_CATALOG.cell(target.numerical_authority_cell_ids[0]) - amplicol_record = _publish_current( - service.store, - baseline, - revision="current-revision", - ) - terminal_recurrence = _ok_measurement( - recurrence, - revision="current-revision", - ) - terminal_recurrence["status"] = ResultStatus.TIMEOUT.value - provenance = terminal_recurrence["provenance"] - assert isinstance(provenance, dict) - provenance["policy_censor_sha256"] = "f" * 64 - recurrence_record = service.store.new_attempt( - recurrence.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(terminal_recurrence) - - def current( - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell == candidate: - return None - assert comparison_dependency is True - if cell == baseline: - return amplicol_record, PolicyMeasurementState.GENERATION_LIMIT - if cell == recurrence: - return ( - None - if recurrence_state is None - else (recurrence_record, recurrence_state) - ) - pytest.fail(f"unexpected dependency query for {cell.cell_id}") - - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - scheduler.source_revision = "current-revision" - monkeypatch.setattr(scheduler, "_current", current) - launched: list[Sequence[str]] = [] - - def supervise(command: Sequence[str], **_kwargs: object) -> SupervisedResult: - launched.append(command) - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps( - failure_measurement( - ResultStatus.ERROR, - "synthetic worker reached without authority", - ) - ) - + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - supervise, - ) - - outcome = scheduler._run_cell(target) - - assert outcome.status == ResultStatus.ERROR.value - assert len(launched) == 1 - command = launched[0] - assert "--baseline-json" not in command - assert ( - tuple( - command[index + 1] - for index, value in enumerate(command) - if value == "--expected-authority-cell-id" - ) - == target.numerical_authority_cell_ids - ) - assert "--selected-authority-cell-id" not in command - - -def test_postworker_late_recurrence_certifies_legacy_diagnostic_run( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - candidate = _z_cell(variant="jit_o1", workload=Workload.SELECTED_FLOW) - target = plan_campaign( - (candidate,), - store=service.store, - settings=CampaignSettings(), - )[0] - recurrence = REPORT_CATALOG.cell(target.numerical_authority_cell_ids[0]) - amplicol = REPORT_CATALOG.validation_baseline_cell(candidate) - assert amplicol is not None - recurrence_record = _publish_current( - service.store, - recurrence, - revision="current-revision", - ) - amplicol_record = _publish_current( - service.store, - amplicol, - revision="current-revision", - ) - worker_finished = False - - def current( - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell == candidate: - return None - assert comparison_dependency is True - if cell == recurrence: - return ( - (recurrence_record, PolicyMeasurementState.SUCCESS) - if worker_finished - else None - ) - if cell == amplicol: - return amplicol_record, PolicyMeasurementState.SUCCESS - pytest.fail(f"unexpected dependency query for {cell.cell_id}") - - captured: list[str] = [] - - def supervise(command: Sequence[str], **_kwargs: object) -> SupervisedResult: - nonlocal worker_finished - captured.extend(command) - result_path = Path(command[command.index("--result-json") + 1]) - measurement = _ok_measurement(candidate, revision="current-revision") - measurement["status"] = ResultStatus.UNVERIFIED.value - validation = measurement["validation"] - assert isinstance(validation, dict) - validation["status"] = ResultStatus.UNVERIFIED.value - validation["independent_authority"] = { - "abi": "pyamplicol-report-independent-authority-v1", - "expected_cell_ids": list(target.numerical_authority_cell_ids), - "selected_cell_id": None, - "status": "unavailable", - "reason": "no-successful-independent-authority", - "same_artifact_diagnostics_are_authority": False, - } - result_path.write_text(json.dumps(measurement) + "\n", encoding="ascii") - worker_finished = True - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - reconciled: list[str] = [] - - def reconcile( - _cell: CellSpec, - measurement: Mapping[str, object], - _authority: Mapping[str, object], - *, - authority_cell_id: str, - ) -> dict[str, object]: - reconciled.append(authority_cell_id) - promoted = deepcopy(measurement) - promoted["status"] = ResultStatus.OK.value - promoted_validation = promoted["validation"] - assert isinstance(promoted_validation, dict) - promoted_validation["status"] = ResultStatus.OK.value - return promoted - - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - scheduler.source_revision = "current-revision" - monkeypatch.setattr(scheduler, "_current", current) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - supervise, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.reconcile_independent_authority", - reconcile, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.attach_direct_agreements", - lambda *_args, **_kwargs: None, - ) - - outcome = scheduler._run_cell(target) - - assert outcome.status == ResultStatus.OK.value - assert "--selected-authority-cell-id" not in captured - assert captured[captured.index("--baseline-json") + 1] == str( - amplicol_record.result_path - ) - assert reconciled == [recurrence.cell_id] - - -def test_postworker_tampered_unverified_is_rejected_before_reconciliation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - candidate = _z_cell(variant="jit_o1", workload=Workload.SELECTED_FLOW) - target = plan_campaign( - (candidate,), - store=service.store, - settings=CampaignSettings(), - )[0] - recurrence = REPORT_CATALOG.cell(target.numerical_authority_cell_ids[0]) - recurrence_record = _publish_current( - service.store, - recurrence, - revision="current-revision", - ) - worker_finished = False - - def current( - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell == candidate: - return None - assert comparison_dependency is True - if cell == recurrence and worker_finished: - return recurrence_record, PolicyMeasurementState.SUCCESS - return None - - def supervise(command: Sequence[str], **_kwargs: object) -> SupervisedResult: - nonlocal worker_finished - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps( - failure_measurement( - ResultStatus.UNVERIFIED, - "tampered diagnostic fixture", - ) - ) - + "\n", - encoding="ascii", - ) - worker_finished = True - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - scheduler.source_revision = "current-revision" - monkeypatch.setattr(scheduler, "_current", current) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - supervise, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.reconcile_independent_authority", - lambda *_args, **_kwargs: pytest.fail( - "tampered diagnostic must be rejected before reconciliation" - ), - ) - - with pytest.raises(ValueError, match="measured result requires"): - scheduler._run_cell(target) - - -def test_selected_authorities_finish_before_compiled_and_eager_work( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - scheduler = CampaignScheduler( - _service(tmp_path), - settings=CampaignSettings(workers=2), - ) - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - amplicol = REPORT_CATALOG.validation_baseline_cell(recurrence) - assert amplicol is not None - eager = _matrix_cell("matrix_eager_builtin_sm_lc") - start_order: list[ExecutionMode] = [] - order_guard = threading.Lock() - - def run_in_lane(item: PlannedCell) -> CellOutcome: - with order_guard: - start_order.append(item.cell.measurement.execution_mode) - if item.cell == amplicol: - return CellOutcome(amplicol.cell_id, "ok", "authority complete") - if item.cell == recurrence: - assert start_order == [ExecutionMode.AMPLICOL, ExecutionMode.RECURRENCE] - return CellOutcome(recurrence.cell_id, "ok", "authority complete") - if item.cell == candidate: - assert ExecutionMode.RECURRENCE in start_order - return CellOutcome(candidate.cell_id, "ok", "verified") - assert item.cell == eager - assert ExecutionMode.RECURRENCE in start_order - return CellOutcome(eager.cell_id, "ok", "verified") - - monkeypatch.setattr(scheduler, "_run_cell_in_lane", run_in_lane) - result = scheduler.run( - tuple( - reversed( - ( - PlannedCell(amplicol, False, None, 0), - PlannedCell( - recurrence, - False, - None, - 1, - prerequisite_cell_ids=(amplicol.cell_id,), - ), - PlannedCell( - candidate, - False, - None, - 2, - numerical_authority_cell_ids=( - recurrence.cell_id, - amplicol.cell_id, - ), - prerequisite_cell_ids=(recurrence.cell_id,), - ), - PlannedCell( - eager, - False, - None, - 3, - numerical_authority_cell_ids=( - recurrence.cell_id, - amplicol.cell_id, - ), - prerequisite_cell_ids=(recurrence.cell_id,), - ), - ) - ) - ) - ) - - assert start_order[:2] == [ExecutionMode.AMPLICOL, ExecutionMode.RECURRENCE] - assert set(start_order[2:]) == {ExecutionMode.COMPILED, ExecutionMode.EAGER} - assert {outcome.cell_id for outcome in result.outcomes} == { - recurrence.cell_id, - amplicol.cell_id, - candidate.cell_id, - eager.cell_id, - } - - -@pytest.mark.parametrize( - "authority_status", - ("error", "generation_limit", "memory_limit", "worker_timeout"), -) -def test_terminal_optional_authority_releases_baseline_free_candidate( - authority_status: str, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - scheduler = CampaignScheduler( - _service(tmp_path), - settings=CampaignSettings(workers=2), - ) - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - recurrence = REPORT_CATALOG.validation_baseline_cell(candidate) - assert recurrence is not None - start_order: list[str] = [] - - def run_in_lane(item: PlannedCell) -> CellOutcome: - start_order.append(item.cell.cell_id) - if item.cell == recurrence: - return CellOutcome(recurrence.cell_id, authority_status, "terminal") - assert item.cell == candidate - return CellOutcome(candidate.cell_id, "unverified", "baseline-free") - - monkeypatch.setattr(scheduler, "_run_cell_in_lane", run_in_lane) - result = scheduler.run( - ( - PlannedCell(recurrence, False, None, 0), - PlannedCell( - candidate, - False, - None, - 1, - numerical_authority_cell_ids=(recurrence.cell_id,), - prerequisite_cell_ids=(recurrence.cell_id,), - ), - ) - ) - - assert start_order == [recurrence.cell_id, candidate.cell_id] - outcomes = {outcome.cell_id: outcome.status for outcome in result.outcomes} - assert outcomes == { - recurrence.cell_id: authority_status, - candidate.cell_id: "unverified", - } - - -def test_plan_excludes_held_cell_without_suppressing_independent_work( - tmp_path: Path, -) -> None: - requested = select_cells( - CellSelection( - datasets=frozenset({"matrix_compiled_builtin_sm_lc"}), - process_keys=frozenset({"dd_z_jets", "ud_w_jets"}), - multiplicities=frozenset({1}), - workloads=frozenset({Workload.SELECTED_FLOW}), - ) - ) - held = next(cell for cell in requested if cell.process_key == "dd_z_jets") - - planned = plan_campaign( - requested, - store=_store(tmp_path), - settings=CampaignSettings(), - excluded_cell_ids=frozenset({held.cell_id}), - ) - - planned_ids = {item.cell.cell_id for item in planned} - assert held.cell_id not in planned_ids - assert any(item.cell.process_key == "ud_w_jets" for item in planned) - - -def test_plan_does_not_exclude_candidate_for_held_optional_authority( - tmp_path: Path, -) -> None: - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - initial = plan_campaign( - (candidate,), - store=_store(tmp_path / "initial"), - settings=CampaignSettings(), - ) - assert len(initial) == 1 - held_authority = initial[0].numerical_authority_cell_ids[0] - - planned = plan_campaign( - (candidate,), - store=_store(tmp_path / "excluded"), - settings=CampaignSettings(), - excluded_cell_ids=frozenset({held_authority}), - ) - - assert tuple(item.cell for item in planned) == (candidate,) - - -def test_missing_only_reuses_valid_candidate_without_optional_authorities( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_compiled_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is Workload.SELECTED_FLOW - ) - store.new_attempt(candidate.cell_id, ArtifactPolicy.REGENERATE).publish( - _ok_measurement(candidate) - ) - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(missing_only=True), - ) - - assert planned == () - - -def test_missing_only_skips_only_after_all_dependencies_are_fresh( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = _matrix_cell("matrix_compiled_builtin_sm_lc") - initial = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(), - ) - for item in initial: - _publish_current(store, item.cell, revision="same") - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(missing_only=True), - expected_revision="same", - ) - - assert planned == () - - -def test_four_line_candidates_never_plan_unsupported_legacy_dependencies( - tmp_path: Path, -) -> None: - requested = tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.process_key == "dd_4q_lines" - and cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - ) - - planned = plan_campaign( - requested, - store=_store(tmp_path), - settings=CampaignSettings(), - ) - - assert len(requested) == 45 - # Every candidate mode is measurable; the shared MadGraph full-colour - # reference is pulled in once as a real dependency. - assert len(planned) == len(requested) + 1 - assert all( - item.cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - for item in planned - ) - recurrence = tuple( - item - for item in planned - if item.cell.measurement.execution_mode is ExecutionMode.RECURRENCE - ) - cross_mode = tuple( - item - for item in planned - if item.cell.measurement.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - ) - assert recurrence - assert all(item.baseline_cell_id is None for item in recurrence) - assert cross_mode - assert all(item.baseline_cell_id is None for item in cross_mode) - assert all( - ( - item.numerical_authority_cell_ids - and REPORT_CATALOG.cell( - item.numerical_authority_cell_ids[0] - ).measurement.execution_mode - is ExecutionMode.RECURRENCE - ) - or ( - not item.numerical_authority_cell_ids - and REPORT_CATALOG.dataset( - item.cell.dataset_id - ).baseline.execution_mode - is ExecutionMode.MADGRAPH - ) - for item in cross_mode - ) - unavailable_legacy = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if REPORT_CATALOG.static_na_reason(cell) is not None - ) - legacy_plan = plan_campaign( - unavailable_legacy, - store=_store(tmp_path / "legacy"), - settings=CampaignSettings(), - ) - assert len(unavailable_legacy) == 34 - assert legacy_plan == () - - -def test_z_native_cap_is_resolved_before_any_attempt_is_planned( - tmp_path: Path, -) -> None: - capped = tuple( - cell - for cell in REPORT_CATALOG.z_cells() - if cell.n_final == 7 and cell.variant in {"asm_o3", "cpp_o3"} - ) - - assert len(capped) == 8 - assert {REPORT_CATALOG.static_na_reason(cell) for cell in capped} == { - "native-backend-generation-cap-n6-v1" - } - store_root = tmp_path / "native-cap" - planned = plan_campaign( - capped, - store=_store(store_root), - settings=CampaignSettings(), - ) - - assert planned == () - assert not tuple(store_root.glob("cells/*/attempts/*")) - - -def test_terminal_censor_rescan_cannot_reinsert_static_na_cell( - tmp_path: Path, -) -> None: - lower = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "reference_amplicol_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is Workload.SELECTED_FLOW - ) - higher = next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == lower.dataset_id - and cell.process_key == lower.process_key - and cell.n_final == 2 - and cell.workload is lower.workload - ) - - class StaticHigherCatalog: - def __getattr__(self, name: str) -> object: - return getattr(REPORT_CATALOG, name) - - def static_na_reason(self, cell: CellSpec) -> str | None: - if cell == higher: - return "synthetic-static-na" - return REPORT_CATALOG.static_na_reason(cell) - - settings = CampaignSettings( - workers=X86_EPYC_WORKERS, - cell_cores=1, - target_runtime_seconds=5.0, - max_rss_bytes=X86_EPYC_MEMORY_LIMIT_BYTES, - allow_symbolica_parallel=True, - campaign_policy=X86_EPYC_POLICY, - report_profile=X86_EPYC_PROFILE, - ) - planned = plan_campaign( - (lower, higher), - store=_store(tmp_path), - settings=settings, - catalog=StaticHigherCatalog(), # type: ignore[arg-type] - ) - - assert tuple(item.cell for item in planned) == (lower,) - - -def test_campaign_run_rejects_forged_static_na_plan_before_worker_setup( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell("reference-amplicol-full-n6-dd-4q-lines-contracted") - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - monkeypatch.setattr( - scheduler, - "_ensure_prepared_model", - lambda _planned: pytest.fail("static N/A plan reached prepared-model setup"), - ) - monkeypatch.setattr( - scheduler, - "_run_cell", - lambda _planned: pytest.fail("static N/A plan reached a worker"), - ) - - with pytest.raises( - ValueError, - match=( - r"reference-amplicol-full-n6-dd-4q-lines-contracted.*" - "original-amplicol-open-quark-line-limit" - ), - ): - scheduler.run( - ( - PlannedCell( - cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ), - ) - ) - - assert service.store.load_current(cell.cell_id, missing_ok=True) is None - assert tuple(service.paths.artifact_root.glob("cells/*/attempts/*")) == () - - -def test_campaign_cancelled_while_queued_starts_no_preflight_or_attempt( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = REPORT_CATALOG.cell( - "z-builtin-sm-n3-dd-z-jets-recurrence-jit-o2-selected-flow" - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(cancellation_requested=lambda: True), - ) - monkeypatch.setattr( - scheduler, - "_ensure_prepared_model", - lambda _planned: pytest.fail("cancelled campaign reached model preflight"), - ) - result = scheduler.run( - ( - PlannedCell( - cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ), - ) - ) - - assert result.outcomes == () - assert tuple(service.paths.artifact_root.glob("cells/*/attempts/*")) == () - - -@pytest.mark.parametrize( - ("reason", "returncode", "succeeds"), - ( - ("completed", 0, True), - ("completed", 1, False), - ("cancelled", -15, False), - ), -) -def test_prepared_model_preflight_always_emits_transient_completion( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - reason: str, - returncode: int, - succeeds: bool, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - planned = PlannedCell( - cell, - dependency=False, - baseline_cell_id=None, - rank=1, - ) - prepared_model = tmp_path / "prepared-model.pyamplicol-model" - prepared_model.write_text("fixture\n", encoding="ascii") - events: list[dict[str, object]] = [] - commands: list[tuple[str, ...]] = [] - - def observe(payload: Mapping[str, object]) -> None: - events.append(dict(payload)) - - def fake_supervise( - command: Sequence[str], - **arguments: object, - ) -> SupervisedResult: - commands.append(tuple(command)) - observation_callback = arguments["observation_callback"] - assert callable(observation_callback) - observation_callback( - WorkerObservation( - pid=100, - usage=ResourceUsage(True, 0, 0, 0, 0.0, 0.1), - phase="waiting-for-reap", - phase_sequence=None, - member_pids=(100,), - ) - ) - if succeeds: - result_path = Path(command[command.index("--result-json") + 1]) - result_path.parent.mkdir(parents=True, exist_ok=True) - result_path.write_text( - json.dumps({"path": str(prepared_model)}) + "\n", - encoding="ascii", - ) - return SupervisedResult( - returncode, - reason, # type: ignore[arg-type] - ResourceUsage(True, 0, 0, 0, 0.0, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(progress_observer=observe), - ) - - if succeeds: - scheduler._ensure_prepared_model((planned,)) - else: - with pytest.raises(RuntimeError, match="prepared-model preflight failed"): - scheduler._ensure_prepared_model((planned,)) - - attempt_id = "prepared-model-builtin_sm" - assert [event["event"] for event in events[:2]] == ["started", "worker"] - assert events[1]["attempt_id"] == attempt_id - assert commands[0][commands[0].index("--producer-revision") + 1] == ( - scheduler.source_revision - ) - assert any( - event.get("event") == "resource" - and event.get("phase") == "waiting-for-reap" - for event in events - ) - assert events[-1] == { - "event": "preflight-finished", - "cell_id": cell.cell_id, - "attempt_id": attempt_id, - } - - -@pytest.mark.parametrize( - "three_line_key", - ("dd_3q_lines", "dd_3q_identical_lines"), -) -def test_contracted_n6_multi_quark_plans_separate_legacy_capability( - tmp_path: Path, - three_line_key: str, -) -> None: - three_line = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n6-" - f"{three_line_key.replace('_', '-')}-contracted" - ) - four_line = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-full-n6-dd-4q-lines-contracted" - ) - four_line_compiled = REPORT_CATALOG.cell( - "matrix-compiled-builtin-sm-full-n6-dd-4q-lines-contracted" - ) - - three_line_plan = plan_campaign( - (three_line,), - store=_store(tmp_path / "three-line"), - settings=CampaignSettings(), - ) - assert tuple(item.cell for item in three_line_plan) == (three_line,) - three_line_item = three_line_plan[0] - assert three_line_item.baseline_cell_id is None - assert three_line_item.optional_baseline_cell_id == ( - f"reference-amplicol-full-n6-{three_line_key.replace('_', '-')}-contracted" - ) - - four_line_plan = plan_campaign( - (four_line,), - store=_store(tmp_path / "four-line"), - settings=CampaignSettings(), - ) - assert tuple(item.cell for item in four_line_plan) == (four_line,) - assert four_line_plan[0].baseline_cell_id is None - - compiled_plan = plan_campaign( - (four_line_compiled,), - store=_store(tmp_path / "compiled"), - settings=CampaignSettings(), - ) - assert tuple(item.cell for item in compiled_plan) == (four_line_compiled,) - compiled_item = compiled_plan[0] - assert compiled_item.baseline_cell_id is None - assert compiled_item.numerical_authority_cell_ids == (four_line.cell_id,) - - -def test_missing_only_schedules_stale_direct_peer_and_recomparison( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = _matrix_cell( - "matrix_compiled_builtin_sm_lc", - workload=Workload.ALL_FLOW, - ) - initial = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(), - ) - target = next(item for item in initial if item.cell == candidate) - baseline_id = target.baseline_cell_id - stale_peer_id = next( - peer_id for peer_id in target.comparison_peer_ids if peer_id != baseline_id - ) - for item in initial: - _publish_current( - store, - item.cell, - revision=("old" if item.cell.cell_id == stale_peer_id else "new"), - ) - - repaired = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(missing_only=True), - expected_revision="new", - ) - repaired_by_id = {item.cell.cell_id: item for item in repaired} - - assert stale_peer_id in repaired_by_id - assert candidate.cell_id in repaired_by_id - assert repaired_by_id[candidate.cell_id].force_recompare is True - assert repaired_by_id[stale_peer_id].rank < repaired_by_id[candidate.cell_id].rank - - -@pytest.mark.parametrize( - "execution_mode", - (ExecutionMode.COMPILED, ExecutionMode.EAGER), -) -def test_missing_only_reuses_recurrence_certified_current( - tmp_path: Path, - execution_mode: ExecutionMode, -) -> None: - store = _store(tmp_path) - candidate = REPORT_CATALOG.cell( - f"matrix-{execution_mode.value}-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - authorities = independent_numerical_authorities(candidate) - assert len(authorities) == 1 - (recurrence,) = authorities - candidate_measurement = _ok_measurement(candidate, revision="current") - validation = candidate_measurement["validation"] - assert isinstance(validation, dict) - validation[INDEPENDENT_AUTHORITY_FIELD] = { - "abi": "pyamplicol-report-independent-authority-v1", - "expected_cell_ids": [authority.cell_id for authority in authorities], - "selected_cell_id": recurrence.cell_id, - "status": "verified", - "reason": "independent-authority-agreement", - "same_artifact_diagnostics_are_authority": False, - } - candidate_current = store.new_attempt( - candidate.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(candidate_measurement) - recurrence_current = _publish_current(store, recurrence, revision="current") - - def current( - cell: CellSpec, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell == candidate: - return candidate_current, PolicyMeasurementState.SUCCESS - if cell == recurrence: - return recurrence_current, PolicyMeasurementState.SUCCESS - return None - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(missing_only=True), - current_resolver=current, - ) - - assert planned == () - - -@pytest.mark.parametrize("dataset_id", ("scalar_contact", "scalar_gravity")) -def test_self_certified_scalar_compiled_current_is_reused( - tmp_path: Path, - dataset_id: str, -) -> None: - cell = next( - candidate - for candidate in REPORT_CATALOG.measurement_cells() - if candidate.dataset_id == dataset_id - ) - store = _store(tmp_path) - _publish_current(store, cell, revision="active") - - planned = plan_campaign( - (cell,), - store=store, - settings=CampaignSettings(missing_only=True), - expected_revision="active", - ) - - assert planned == () - - -def test_z_cell_explicitly_reuses_valid_cross_source_comparisons( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - store = _store(tmp_path) - candidate = REPORT_CATALOG.cell( - "z-builtin-sm-n8-dd-z-jets-recurrence-jit-o2-all-flow" - ) - initial = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(), - ) - dependency_ids = {item.cell.cell_id for item in initial if item.cell != candidate} - for item in initial: - if item.cell == candidate: - continue - result = _ok_measurement(item.cell, revision="a" * 40) - result["provenance"]["report_source_tree"] = "b" * 40 - store.new_attempt( - item.cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(result) - monkeypatch.setattr( - "tools.performance_report.scheduler.validate_measurement", - lambda *_args, **_kwargs: None, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler.validate_policy_measurement", - lambda *_args, **_kwargs: PolicyMeasurementState.SUCCESS, - ) - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings( - workers=1, - cell_cores=1, - target_runtime_seconds=5.0, - max_rss_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, - campaign_policy=MACBOOK_M3_Z_TABLE_F_POLICY, - report_profile="macbook_M3", - study_contract_sha256="c" * 64, - reuse_cross_source_comparison_dependencies=True, - ), - expected_revision="d" * 40, - expected_tree="e" * 40, - ) - - assert dependency_ids - assert tuple(item.cell for item in planned) == (candidate,) - - -def test_z_table_f_preflight_does_not_require_optional_amplicol( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - candidate = REPORT_CATALOG.cell( - "z-builtin-sm-n8-dd-z-jets-recurrence-jit-o2-all-flow" - ) - settings = CampaignSettings( - workers=1, - cell_cores=1, - target_runtime_seconds=5.0, - max_rss_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, - campaign_policy=MACBOOK_M3_Z_TABLE_F_POLICY, - report_profile="macbook_M3", - study_contract_sha256="c" * 64, - ) - planned = plan_campaign( - (candidate,), - store=service.store, - settings=settings, - ) - candidate_plan = next(item for item in planned if item.cell == candidate) - optional_ids = { - dependency_id - for dependency_id in ( - candidate_plan.optional_baseline_cell_id, - *candidate_plan.optional_comparison_peer_ids, - ) - if dependency_id is not None - } - required_ids = { - dependency_id - for dependency_id in ( - candidate_plan.baseline_cell_id, - *candidate_plan.comparison_peer_ids, - ) - if dependency_id is not None - } - queried: list[str] = [] - scheduler = object.__new__(CampaignScheduler) - scheduler.settings = settings - scheduler.catalog = REPORT_CATALOG - - def current(cell: CellSpec, **_kwargs: object) -> object: - queried.append(cell.cell_id) - return object() - - monkeypatch.setattr(scheduler, "_current", current) - - scheduler._validate_z_table_f_plan((candidate_plan,)) - - assert optional_ids - assert set(queried) == required_ids - assert set(queried).isdisjoint(optional_ids) - - -def test_missing_only_rejects_stale_report_revision(tmp_path: Path) -> None: - store = _store(tmp_path) - candidate = next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == "matrix_compiled_builtin_sm_lc" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is Workload.SELECTED_FLOW - ) - store.new_attempt(candidate.cell_id, ArtifactPolicy.REGENERATE).publish( - _ok_measurement(candidate, revision="old") - ) - - planned = plan_campaign( - (candidate,), - store=store, - settings=CampaignSettings(missing_only=True), - expected_revision="new", - ) - - assert tuple(item.cell for item in planned) == (candidate,) - - -def _matrix_cell( - dataset_id: str, - *, - workload: Workload = Workload.SELECTED_FLOW, -) -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.dataset_id == dataset_id - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is workload - ) - - -def _z_cell(*, variant: str, workload: Workload) -> CellSpec: - return next( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id == "z_builtin_sm" - and cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.variant == variant - and cell.workload is workload - ) - - -def _service(tmp_path: Path) -> ReportService: - root = tmp_path / "repo" - (root / "src/pyamplicol/_profiling_campaign").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=root, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=root, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=root, - check=True, - ) - (root / "README.md").write_text("# report fixture\n", encoding="ascii") - subprocess.run(("git", "add", "README.md"), cwd=root, check=True) - subprocess.run( - ("git", "commit", "-q", "-m", "Initialize fixture"), - cwd=root, - check=True, - ) - return ReportService( - ReportPaths.from_repo( - root, - artifact_root=tmp_path / "artifacts", - coordination_root=tmp_path / "locks", - ) - ) - - -def _publish_current( - store: ArtifactStore, - cell: CellSpec, - *, - revision: str, -) -> CurrentRecord: - return store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE).publish( - _ok_measurement(cell, revision=revision) - ) - - -def test_equivalent_reuse_requires_fresh_revision_and_never_uses_amplicol( - tmp_path: Path, -) -> None: - store = _store(tmp_path) - candidate = _matrix_cell("matrix_recurrence_builtin_sm_lc") - equivalent = REPORT_CATALOG.equivalent_cells(candidate)[0] - stale = _publish_current(store, equivalent, revision="old") - - assert ( - _fresh_equivalent_current( - store, - candidate, - catalog=REPORT_CATALOG, - expected_revision="new", - ) - is None - ) - - fresh = _publish_current(store, equivalent, revision="new") - selected = _fresh_equivalent_current( - store, - candidate, - catalog=REPORT_CATALOG, - expected_revision="new", - ) - assert selected is not None - assert selected.attempt_id == fresh.attempt_id - assert selected.attempt_id != stale.attempt_id - - reference = next( - cell - for cell in REPORT_CATALOG.reference_cells() - if cell.process_key == "dd_z_jets" - and cell.n_final == 1 - and cell.workload is Workload.SELECTED_FLOW - ) - assert ( - _fresh_equivalent_current( - store, - reference, - catalog=REPORT_CATALOG, - expected_revision="new", - ) - is None - ) - - -def _run_with_captured_worker( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - *, - policy: ArtifactPolicy, - rerun: bool = False, - target_current: bool = False, - madgraph_installation: Path | None = None, -) -> tuple[list[str], CellOutcome, CurrentRecord, CurrentRecord]: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - equivalent = REPORT_CATALOG.equivalent_cells(target)[0] - baseline = REPORT_CATALOG.baseline_cell(target) - assert baseline is not None - revision = "current-revision" - baseline_record = _publish_current( - service.store, - baseline, - revision=revision, - ) - equivalent_record = _publish_current( - service.store, - equivalent, - revision=revision, - ) - if target_current: - _publish_current( - service.store, - target, - revision=revision, - ) - command_seen: list[str] = [] - - def fake_supervise( - command: Sequence[str], - **_kwargs: object, - ) -> SupervisedResult: - command_seen.extend(command) - result_path = Path(command_seen[command_seen.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_ok_measurement(target, revision=revision)) + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - monkeypatch.setattr( - "tools.performance_report.scheduler._symbolica_generation_lock_path", - lambda *_arguments: tmp_path / "generation.lock", - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - artifact_policy=policy, - rerun=rerun, - target_runtime_seconds=1.0, - madgraph_installation=madgraph_installation, - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - scheduler.source_revision = revision - outcome = scheduler._run_cell( - PlannedCell( - target, - dependency=False, - baseline_cell_id=baseline.cell_id, - rank=1, - ) - ) - return command_seen, outcome, equivalent_record, baseline_record - - -@pytest.mark.parametrize("policy", (ArtifactPolicy.REUSE, ArtifactPolicy.RETIME)) -def test_reuse_and_retime_use_equivalent_artifact_but_target_baseline( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - policy: ArtifactPolicy, -) -> None: - command, outcome, equivalent, baseline = _run_with_captured_worker( - tmp_path, - monkeypatch, - policy=policy, - ) - - assert outcome.status == "ok" - assert command[command.index("--reused-measurement-json") + 1] == str( - equivalent.result_path - ) - assert command[command.index("--baseline-json") + 1] == str(baseline.result_path) - assert command[command.index("--cell-id") + 1] == ( - "matrix-recurrence-builtin-sm-lc-n1-dd-z-jets-selected-flow" - ) - assert command[command.index("--docs-dir") + 1].endswith( - "/repo/src/pyamplicol/_profiling_campaign" - ) - assert command[command.index("--artifact-root") + 1].endswith("/artifacts") - assert command[command.index("--coordination-root") + 1].endswith("/locks") - assert "--generation-lock-path" not in command - - -def test_scheduler_propagates_madgraph_installation_to_worker( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - installation = tmp_path / "madgraph" - command, outcome, _equivalent, _baseline = _run_with_captured_worker( - tmp_path, - monkeypatch, - policy=ArtifactPolicy.REUSE, - madgraph_installation=installation, - ) - - assert outcome.status == "ok" - assert command[command.index("--madgraph") + 1] == str(installation) - - -@pytest.mark.parametrize( - ("policy", "rerun", "target_current"), - ( - (ArtifactPolicy.REGENERATE, False, False), - (ArtifactPolicy.RETIME, True, True), - (ArtifactPolicy.REUSE, True, True), - ), -) -def test_explicit_regenerate_or_rerun_forces_generation( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - policy: ArtifactPolicy, - rerun: bool, - target_current: bool, -) -> None: - command, outcome, _equivalent, _baseline = _run_with_captured_worker( - tmp_path, - monkeypatch, - policy=policy, - rerun=rerun, - target_current=target_current, - ) - - assert outcome.status == "ok" - assert "--reused-measurement-json" not in command - assert command[command.index("--generation-lock-path") + 1].endswith( - "/generation.lock" - ) - - -def test_scheduler_never_publishes_first_failed_worker_result( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - baseline = REPORT_CATALOG.baseline_cell(target) - assert baseline is not None - revision = "current-revision" - _publish_current(service.store, baseline, revision=revision) - - def fake_supervise( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps( - failure_measurement( - ResultStatus.ERROR, - "deterministic worker failure", - ) - ) - + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(artifact_policy=ArtifactPolicy.REGENERATE), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - scheduler.source_revision = revision - outcome = scheduler._run_cell( - PlannedCell( - target, - dependency=False, - baseline_cell_id=baseline.cell_id, - rank=1, - ) - ) - - assert outcome.status == ResultStatus.ERROR.value - assert service.store.load_current(target.cell_id, missing_ok=True) is None - attempt_roots = ( - *( - service.paths.artifact_root / "cells" - ).glob(f"*/attempts/{outcome.detail}"), - *( - service.paths.artifact_root / "attempt-history" - ).glob(f"*/{outcome.detail}"), - ) - assert len(attempt_roots) == 1 - manifest = json.loads( - (attempt_roots[0] / "manifest.json").read_text(encoding="ascii") - ) - assert manifest["status"] == "failed" - assert manifest["result_path"] is None - assert not (attempt_roots[0] / "result.json").exists() - worker_result = json.loads( - (attempt_roots[0] / "worker-result.json").read_text(encoding="ascii") - ) - assert worker_result["status"] == ResultStatus.ERROR.value - - -def test_scheduler_result_rewrite_preserves_actionable_disk_full_error( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - baseline = REPORT_CATALOG.baseline_cell(target) - assert baseline is not None - revision = "current-revision" - _publish_current(service.store, baseline, revision=revision) - - def fake_supervise( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_ok_measurement(target, revision=revision)) + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - original_write_json = ArtifactAttempt.write_json - - def fail_result_rewrite( - attempt: ArtifactAttempt, - relative_path: str, - payload: Mapping[str, object], - ) -> Path: - if relative_path == "worker-result.json": - raise DiskFullError( - f"disk full while writing {attempt.root / relative_path}; " - "0 bytes available" - ) - return original_write_json(attempt, relative_path, payload) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - monkeypatch.setattr(ArtifactAttempt, "write_json", fail_result_rewrite) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(artifact_policy=ArtifactPolicy.REGENERATE), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - scheduler.source_revision = revision - - with pytest.raises( - DiskFullError, - match=r"disk full while writing .*worker-result.json; 0 bytes available", - ): - scheduler._run_cell( - PlannedCell( - target, - dependency=False, - baseline_cell_id=baseline.cell_id, - rank=1, - ) - ) - - assert service.store.load_current(target.cell_id, missing_ok=True) is None - - -def test_scheduler_never_publishes_first_skip( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - - outcome = scheduler._publish_skip( - cell, - "required dependency is unavailable", - current=None, - ) - - assert outcome.status == ResultStatus.SKIP.value - assert service.store.load_current(cell.cell_id, missing_ok=True) is None - attempt_roots = tuple( - (service.paths.artifact_root / "cells").glob(f"*/attempts/{outcome.detail}") - ) - assert len(attempt_roots) == 1 - manifest = json.loads( - (attempt_roots[0] / "manifest.json").read_text(encoding="ascii") - ) - assert manifest["status"] == "failed" - assert manifest["result_path"] is None - - -def test_dependency_block_retains_exact_prerequisite_identity( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - prerequisite = "reference-amplicol-lc-n1-dd-z-jets-selected-flow" - - outcome = scheduler._publish_blocked_dependency( - cell, - prerequisite, - current=None, - ) - - assert outcome.status == "blocked_dependency" - assert outcome.prerequisite_cell_ids == (prerequisite,) - assert outcome.detail == ( - f"blocked by dependency: required prerequisite {prerequisite!r} is unavailable" - ) - assert service.store.load_current(cell.cell_id, missing_ok=True) is None - attempts = tuple((service.store._cell_root(cell.cell_id) / "attempts").iterdir()) - assert len(attempts) == 1 - result = json.loads( - (attempts[0] / "worker-result.json").read_text(encoding="utf-8") - ) - assert result["blocked_dependency"] == { - "prerequisite_cell_ids": [prerequisite] - } - - -def test_dag_terminal_direct_peer_blocks_dependent_before_worker_launch( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - prerequisite = _matrix_cell("matrix_recurrence_builtin_sm_lc") - dependent = _matrix_cell("matrix_compiled_builtin_sm_lc") - observed: list[Mapping[str, object]] = [] - launched: list[str] = [] - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - workers=1, - max_rss_bytes=30_000_000_000, - manual_terminal_censors=True, - source_identity_override=ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - progress_observer=lambda payload: observed.append(dict(payload)), - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - blocked_after_terminal: list[str] = [] - publish_blocked = scheduler._publish_blocked_dependency - - def assert_prerequisite_is_terminal_before_blocking( - cell: CellSpec, - prerequisite_cell_ids: str | Sequence[str], - *, - current: CurrentRecord | None, - ) -> CellOutcome: - prerequisite_current = service.store.load_current(prerequisite.cell_id) - assert prerequisite_current is not None - assert prerequisite_current.result["status"] == ResultStatus.MEMORY_LIMIT.value - blocked_after_terminal.append(cell.cell_id) - return publish_blocked( - cell, - prerequisite_cell_ids, - current=current, - ) - - monkeypatch.setattr( - scheduler, - "_publish_blocked_dependency", - assert_prerequisite_is_terminal_before_blocking, - ) - - def fake_supervise( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - cell_id = str(command[command.index("--cell-id") + 1]) - launched.append(cell_id) - if cell_id != prerequisite.cell_id: - pytest.fail("dependency-blocked worker was launched") - return SupervisedResult( - -9, - "memory_limit", - ResourceUsage( - True, - 30_000_000_001, - 30_000_000_001, - 0, - 0.1, - 0.2, - ), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - planned = ( - PlannedCell(prerequisite, dependency=True, baseline_cell_id=None, rank=0), - PlannedCell( - dependent, - dependency=False, - baseline_cell_id=None, - rank=1, - comparison_peer_ids=(prerequisite.cell_id,), - prerequisite_cell_ids=(prerequisite.cell_id,), - ), - ) - - result = scheduler.run(planned) - - assert launched == [prerequisite.cell_id] - outcomes = {outcome.cell_id: outcome for outcome in result.outcomes} - assert outcomes[prerequisite.cell_id].status == "memory_limit" - blocked = outcomes[dependent.cell_id] - assert blocked.status == "blocked_dependency" - assert blocked.prerequisite_cell_ids == (prerequisite.cell_id,) - assert blocked_after_terminal == [dependent.cell_id] - finished = [ - payload - for payload in observed - if payload.get("event") == "finished" - and payload.get("cell_id") == dependent.cell_id - ] - assert len(finished) == 1 - assert finished[0]["prerequisite_cell_ids"] == (prerequisite.cell_id,) - - -def test_scheduler_plumbs_authenticated_generation_only_limit( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - baseline = REPORT_CATALOG.baseline_cell(target) - assert baseline is not None - revision = "current-revision" - _publish_current(service.store, baseline, revision=revision) - captured: dict[str, object] = {} - - def fake_supervise( - command: Sequence[str], - **arguments: object, - ) -> SupervisedResult: - captured["command"] = tuple(command) - captured.update(arguments) - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_ok_measurement(target, revision=revision)) + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - timeout_seconds=90.0, - generation_time_limit_seconds=7200.0, - profiling_time_limit_seconds=60.0, - validation_time_limit_seconds=30.0, - max_rss_bytes=30_000_000_000, - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - scheduler.source_revision = revision - outcome = scheduler._run_cell( - PlannedCell( - target, - dependency=False, - baseline_cell_id=baseline.cell_id, - rank=1, - ) - ) - - assert outcome.status == "ok" - assert captured["timeout_seconds"] == 90.0 - assert captured["generation_timeout_seconds"] == 7200.0 - assert captured["profiling_timeout_seconds"] == 60.0 - assert captured["validation_timeout_seconds"] == 30.0 - channel = captured["phase_channel"] - assert isinstance(channel, WorkerPhaseChannel) - command = captured["command"] - assert isinstance(command, tuple) - assert command[command.index("--phase-state-path") + 1] == str(channel.path) - assert command[command.index("--phase-state-run-id") + 1] == channel.run_id - assert ( - command[command.index("--phase-state-authentication-key") + 1] - == channel.authentication_key - ) - assert command[command.index("--worker-wall-limit") + 1] == "90.0" - assert command[command.index("--memory-limit-bytes") + 1] == "30000000000" - assert captured["max_rss_bytes"] == 30_000_000_000 - output_limits = captured["output_file_limits"] - assert isinstance(output_limits, Mapping) - assert len(output_limits) == 4 - assert set(output_limits.values()) == {64 * 1024 * 1024} - assert Path(command[command.index("--log-path") + 1]) in output_limits - assert Path(command[command.index("--progress-jsonl") + 1]) in output_limits - assert captured["minimum_free_disk_bytes"] == 5 * 1024 * 1024 * 1024 - assert captured["disk_probe_path"] == service.paths.artifact_root - assert command[command.index("--profiling-time-limit") + 1] == "60.0" - assert command[command.index("--validation-time-limit") + 1] == "30.0" - - -def test_scheduler_persists_abrupt_worker_exit_diagnostics_with_empty_worker_log( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - captured: dict[str, object] = {} - - def crash( - command: Sequence[str], - **arguments: object, - ) -> SupervisedResult: - captured.update(arguments) - Path(command[command.index("--log-path") + 1]).touch() - phase_error = "worker exited before closing generation" - return SupervisedResult( - -11, - "worker_exit", - ResourceUsage(True, 0, 1234, 0, 0.2, 0.3), - generation_phase=GenerationPhaseEvidence( - configured_timeout_seconds=3600.0, - supervisor_reason="worker_exit", - authenticated=False, - run_id="phase-run-7", - worker_pid=4321, - final_sequence=1, - final_phase="generation", - generation_started_monotonic_ns=10, - generation_finished_monotonic_ns=None, - generation_elapsed_seconds=0.3, - final_state_sha256="c" * 64, - error=phase_error, - ), - pid=4321, - member_pids=(4321, 4322), - signal_number=11, - signal_name="SIGSEGV", - supervisor_stderr="native evaluator abort\n", - supervisor_stderr_limit_bytes=65536, - phase_state_error=phase_error, - started_at_utc="2026-08-02T00:00:00+00:00", - finished_at_utc="2026-08-02T00:00:01+00:00", - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - crash, - ) - source_revision = "a" * 40 - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - source_identity_override=ReportSourceIdentity( - source_revision, - "b" * 40, - (), - ), - campaign_invocation_id="manual-invocation-7", - remove_heavy_attempt_artifacts=False, - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - - outcome = scheduler._run_cell( - PlannedCell(cell, dependency=False, baseline_cell_id=None, rank=0) - ) - - assert outcome.status == "error" - assert captured["capture_stderr"] is True - attempt_roots = tuple( - (service.paths.artifact_root / "cells").glob(f"*/attempts/{outcome.detail}") - ) - assert len(attempt_roots) == 1 - attempt_root = attempt_roots[0] - assert (attempt_root / "worker.log").read_bytes() == b"" - result = json.loads( - (attempt_root / "worker-result.json").read_text(encoding="ascii") - ) - assert result["status"] == "error" - assert result["failure"] == { - "kind": "WorkerProcessExitError", - "message": "worker terminated by SIGSEGV (signal 11, return code -11)", - } - supervisor = result["resources"]["supervisor"] - assert supervisor == { - "abi": "pyamplicol-report-worker-supervisor-v1", - "campaign_invocation_id": "manual-invocation-7", - "finished_at_utc": "2026-08-02T00:00:01+00:00", - "member_pids": [4321, 4322], - "phase": "generation", - "phase_state_error": "worker exited before closing generation", - "pid": 4321, - "reason": "worker_exit", - "returncode": -11, - "signal_name": "SIGSEGV", - "signal_number": 11, - "source_revision": source_revision, - "started_at_utc": "2026-08-02T00:00:00+00:00", - "stderr": "native evaluator abort\n", - "stderr_limit_bytes": 65536, - "stderr_truncated": False, - "teardown_escalated": False, - "teardown_seconds": 0.0, - } - assert result["provenance"]["report_source_revision"] == source_revision - - -def test_scheduler_persists_and_forwards_exact_phase_state_failure( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - phase_error = ( - "worker phase-state transition timestamp is outside the supervised " - "process lifetime" - ) - - def invalid_phase( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - Path(command[command.index("--log-path") + 1]).touch() - return SupervisedResult( - -15, - "phase_state_error", - ResourceUsage(True, 0, 1234, 0, 0.2, 0.3), - pid=4321, - member_pids=(4321,), - phase_state_error=phase_error, - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - invalid_phase, - ) - events: list[dict[str, object]] = [] - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - source_identity_override=ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - progress_observer=lambda payload: events.append(dict(payload)), - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - - outcome = scheduler._run_cell( - PlannedCell(cell, dependency=False, baseline_cell_id=None, rank=0) - ) - - assert outcome.status == ResultStatus.ERROR.value - assert outcome.terminal_detail == phase_error - attempt_roots = ( - *( - service.paths.artifact_root / "cells" - ).glob(f"*/attempts/{outcome.detail}"), - *( - service.paths.artifact_root / "attempt-history" - ).glob(f"*/{outcome.detail}"), - ) - assert len(attempt_roots) == 1 - result = json.loads( - (attempt_roots[0] / "worker-result.json").read_text(encoding="ascii") - ) - assert result["failure"]["message"] == phase_error - assert result["resources"]["supervisor"]["reason"] == "phase_state_error" - assert result["resources"]["supervisor"]["phase_state_error"] == phase_error - finished = [event for event in events if event["event"] == "finished"] - assert len(finished) == 1 - assert finished[0]["terminal_detail"] == phase_error - - -def test_prepared_model_worker_exit_persists_structured_failed_attempt( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - source_revision = "a" * 40 - phase_error = "worker exited before closing preparation" - supervised = SupervisedResult( - -6, - "worker_exit", - ResourceUsage(True, 0, 2048, 1, 0.4, 0.5), - pid=7654, - member_pids=(7654, 7655), - signal_number=6, - signal_name="SIGABRT", - supervisor_stderr="native model compiler abort\n", - supervisor_stderr_limit_bytes=65536, - phase_state_error=phase_error, - started_at_utc="2026-08-02T01:00:00+00:00", - finished_at_utc="2026-08-02T01:00:01+00:00", - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - source_identity_override=ReportSourceIdentity( - source_revision, - "b" * 40, - (), - ), - campaign_invocation_id="manual-preflight-9", - ), - ) - - outcome = scheduler._preparation_failure_outcome( - cell, - _PreparationFailed( - ModelKey.BUILTIN_SM, - "worker_exit", - "prepared-model worker aborted", - supervised, - ), - ) - - assert outcome.status == "error" - attempt_roots = tuple( - (service.paths.artifact_root / "cells").glob(f"*/attempts/{outcome.detail}") - ) - assert len(attempt_roots) == 1 - attempt_root = attempt_roots[0] - result = json.loads( - (attempt_root / "worker-result.json").read_text(encoding="ascii") - ) - assert result["status"] == "error" - assert result["failure"] == { - "kind": "WorkerProcessExitError", - "message": "worker terminated by SIGABRT (signal 6, return code -6)", - } - assert result["resources"]["supervisor"] == { - "abi": "pyamplicol-report-worker-supervisor-v1", - "campaign_invocation_id": "manual-preflight-9", - "finished_at_utc": "2026-08-02T01:00:01+00:00", - "member_pids": [7654, 7655], - "phase": "preparation", - "phase_state_error": phase_error, - "pid": 7654, - "reason": "worker_exit", - "returncode": -6, - "signal_name": "SIGABRT", - "signal_number": 6, - "source_revision": source_revision, - "started_at_utc": "2026-08-02T01:00:00+00:00", - "stderr": "native model compiler abort\n", - "stderr_limit_bytes": 65536, - "stderr_truncated": False, - "teardown_escalated": False, - "teardown_seconds": 0.0, - } - assert result["provenance"]["report_source_revision"] == source_revision - manifest = json.loads((attempt_root / "manifest.json").read_text(encoding="utf-8")) - assert manifest["status"] == "failed" - assert [record["path"] for record in manifest["artifacts"]] == [ - "worker-result.json" - ] - - -@pytest.mark.parametrize( - ("reason", "state", "kind", "label"), - ( - ("generation_timeout", "generation_limit", "generation_limit", ">7s"), - ("worker_timeout", "worker_timeout", "worker_timeout", "worker >11s"), - ( - "profiling_timeout", - "profiling_timeout", - "profiling_timeout", - "profile >5s", - ), - ( - "validation_timeout", - "validation_timeout", - "validation_timeout", - "validation >3s", - ), - ), -) -def test_manual_stage_timeout_is_published_as_distinct_addressed_current( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - reason: str, - state: str, - kind: str, - label: str, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - lambda _command, **_arguments: SupervisedResult( - -15, - reason, - ResourceUsage(True, 0, 1, 0, 0.1, 11.0), - ), - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - timeout_seconds=11.0, - generation_time_limit_seconds=7.0, - profiling_time_limit_seconds=5.0, - validation_time_limit_seconds=3.0, - manual_terminal_censors=True, - source_identity_override=ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - - outcome = scheduler._run_cell( - PlannedCell(cell, dependency=False, baseline_cell_id=None, rank=0) - ) - - assert outcome.status == state - assert not CampaignResult((PlannedCell(cell, False, None, 0),), (outcome,)).failed - current = service.store.load_current(cell.cell_id) - assert current is not None - assert current.result["status"] == ResultStatus.TIMEOUT.value - assert current.result["resources"]["terminal_reason"] == reason - assert current.result["provenance"]["policy_censor"]["kind"] == kind - assert policy_status_label(current.result) == label - resolved = scheduler._current(cell) - assert resolved is not None - assert resolved[1].value == state - for timing in ( - "generation_seconds", - "wall_seconds_per_point", - "execution_seconds_per_point", - "sample_count", - ): - assert current.result[timing] is None - - -def test_manual_clean_child_profiling_timeout_keeps_typed_reason( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - - class ProfilingTimeLimitError(RuntimeError): - pass - - def fake_supervise( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - result_path = Path(command[command.index("--result-json") + 1]) - result = failure_measurement( - ResultStatus.TIMEOUT, - ProfilingTimeLimitError("profiling budget exhausted"), - resources={"terminal_reason": "profiling_timeout"}, - ) - result_path.write_text(json.dumps(result) + "\n", encoding="ascii") - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 0, 1, 0, 0.1, 5.0), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - timeout_seconds=11.0, - generation_time_limit_seconds=7.0, - profiling_time_limit_seconds=5.0, - validation_time_limit_seconds=3.0, - manual_terminal_censors=True, - source_identity_override=ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - ), - ) - monkeypatch.setattr(scheduler, "_prepare_model_for", lambda _planned: None) - - outcome = scheduler._run_cell( - PlannedCell(cell, dependency=False, baseline_cell_id=None, rank=0) - ) - - assert outcome.status == PolicyMeasurementState.PROFILING_TIMEOUT.value - current = service.store.load_current(cell.cell_id) - assert current is not None - assert current.result["failure"]["kind"] == "ProfilingTimeLimitError" - assert current.result["resources"]["terminal_reason"] == "profiling_timeout" - - -def test_campaign_run_never_publishes_or_renders( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - planned = ( - PlannedCell( - target, - dependency=False, - baseline_cell_id=None, - rank=0, - ), - ) - monkeypatch.setattr(scheduler, "_ensure_prepared_model", lambda _items: None) - monkeypatch.setattr( - scheduler, - "_run_cell", - lambda item: CellOutcome(item.cell.cell_id, "ok", "complete"), - ) - monkeypatch.setattr( - service, - "publish", - lambda **_kwargs: pytest.fail("measurement waited on report publication"), - ) - - result = scheduler.run(planned) - - assert result.failed == () - assert result.outcomes[0].cell_id == target.cell_id - - -def test_shared_model_preparation_does_not_hold_independent_ready_cell( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(workers=2), - ) - recurrence = PlannedCell( - _matrix_cell("matrix_recurrence_builtin_sm_lc"), - dependency=False, - baseline_cell_id=None, - rank=0, - ) - scalar = PlannedCell( - REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted"), - dependency=False, - baseline_cell_id=None, - rank=0, - ) - preparation_started = threading.Event() - independent_started = threading.Event() - - def prepare(_items: Sequence[PlannedCell]) -> None: - preparation_started.set() - assert independent_started.wait(timeout=1.0) - scheduler._prepared_model_paths[ModelKey.BUILTIN_SM] = ( - tmp_path / "prepared-model.bin" - ) - - def run_cell(item: PlannedCell) -> CellOutcome: - if item.cell.cell_id == recurrence.cell.cell_id: - scheduler._prepare_model_for(item) - else: - assert preparation_started.wait(timeout=1.0) - independent_started.set() - return CellOutcome(item.cell.cell_id, "ok", "complete") - - monkeypatch.setattr(scheduler, "_ensure_prepared_model", prepare) - monkeypatch.setattr(scheduler, "_run_cell", run_cell) - - result = scheduler.run((recurrence, scalar)) - - assert {outcome.cell_id for outcome in result.outcomes} == { - recurrence.cell.cell_id, - scalar.cell.cell_id, - } - - -def test_failed_shared_model_preparation_is_memoized( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - scheduler = CampaignScheduler(_service(tmp_path), settings=CampaignSettings()) - planned = PlannedCell( - _matrix_cell("matrix_recurrence_builtin_sm_lc"), - dependency=False, - baseline_cell_id=None, - rank=0, - ) - calls = 0 - failure = _PreparationFailed( - ModelKey.BUILTIN_SM, - "worker_timeout", - "prepared model timed out", - ) - - def fail(_items: Sequence[PlannedCell]) -> None: - nonlocal calls - calls += 1 - raise failure - - monkeypatch.setattr(scheduler, "_ensure_prepared_model", fail) - - with pytest.raises(_PreparationFailed): - scheduler._prepare_model_for(planned) - with pytest.raises(_PreparationFailed): - scheduler._prepare_model_for(planned) - - assert calls == 1 - - -def test_preparation_failure_is_handled_while_cell_lock_is_held( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - scheduler = CampaignScheduler(service, settings=CampaignSettings()) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - planned = PlannedCell( - cell, - dependency=False, - baseline_cell_id=None, - rank=0, - ) - held: set[str] = set() - - class Lock: - def __init__(self, name: str) -> None: - self.name = name - - def __enter__(self) -> None: - held.add(self.name) - - def __exit__(self, *_arguments: object) -> None: - held.remove(self.name) - - monkeypatch.setattr( - service.store, - "named_lock", - lambda name, **_kwargs: Lock(name), - ) - - def fail(_planned: PlannedCell) -> None: - raise _PreparationFailed( - ModelKey.BUILTIN_SM, - "error", - "preparation failed", - ) - - monkeypatch.setattr(scheduler, "_prepare_model_for", fail) - - def handle( - _cell: CellSpec, - _failure: _PreparationFailed, - ) -> CellOutcome: - assert f"campaign-cell-{cell.cell_id}" in held - return CellOutcome(cell.cell_id, "preparation_error", "handled") - - monkeypatch.setattr(scheduler, "_preparation_failure_outcome", handle) - - outcome = scheduler._run_cell(planned) - - assert outcome.status == "preparation_error" - assert held == set() - - -@pytest.mark.parametrize( - ("worker_limit", "generation_limit", "expected_reason"), - ( - (11.0, 7.0, "generation_timeout"), - (5.0, 7.0, "worker_timeout"), - ), -) -def test_preparation_timeout_keeps_the_effective_limit_identity( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - worker_limit: float, - generation_limit: float, - expected_reason: str, -) -> None: - scheduler = CampaignScheduler( - _service(tmp_path), - settings=CampaignSettings( - timeout_seconds=worker_limit, - generation_time_limit_seconds=generation_limit, - ), - ) - planned = PlannedCell( - _matrix_cell("matrix_recurrence_builtin_sm_lc"), - dependency=False, - baseline_cell_id=None, - rank=0, - ) - captured: dict[str, object] = {} - - def timeout(_command: Sequence[str], **arguments: object) -> SupervisedResult: - captured.update(arguments) - return SupervisedResult( - -15, - "worker_timeout", - ResourceUsage(True, 0, 1, 0, 0.1, min(worker_limit, generation_limit)), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - timeout, - ) - - with pytest.raises(_PreparationFailed) as raised: - scheduler._ensure_prepared_model((planned,)) - - assert raised.value.reason == expected_reason - assert captured["timeout_seconds"] == min(worker_limit, generation_limit) - - -def test_manual_preparation_wall_timeout_is_generation_terminal( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cell = _matrix_cell("matrix_recurrence_builtin_sm_lc") - supervised = SupervisedResult( - -15, - "worker_timeout", - ResourceUsage(True, 0, 1, 0, 0.1, 7.0), - ) - failure = _PreparationFailed( - ModelKey.BUILTIN_SM, - "generation_timeout", - "prepared model timed out", - supervised, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - timeout_seconds=11.0, - generation_time_limit_seconds=7.0, - profiling_time_limit_seconds=5.0, - validation_time_limit_seconds=3.0, - manual_terminal_censors=True, - source_identity_override=ReportSourceIdentity( - "a" * 40, - "b" * 40, - (), - ), - ), - ) - - def fail(_planned: PlannedCell) -> None: - raise failure - - monkeypatch.setattr(scheduler, "_prepare_model_for", fail) - - outcome = scheduler._run_cell( - PlannedCell(cell, dependency=False, baseline_cell_id=None, rank=0) - ) - - assert outcome.status == PolicyMeasurementState.GENERATION_LIMIT.value - current = service.store.load_current(cell.cell_id) - assert current is not None - assert current.result["resources"]["terminal_reason"] == "generation_timeout" - - -def test_ready_queue_admits_later_rank_while_an_earlier_cell_is_still_running( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cells = tuple( - sorted( - ( - REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted"), - REPORT_CATALOG.cell("scalar-gravity-n2-scalar-gravity-contracted"), - REPORT_CATALOG.cell("scalar-contact-n3-scalar-contact-contracted"), - ), - key=lambda cell: cell.cell_id, - ) - ) - slow, quick, later = cells - release_slow = threading.Event() - later_started = threading.Event() - failures: list[BaseException] = [] - results: list[object] = [] - - scheduler = CampaignScheduler(service, settings=CampaignSettings(workers=2)) - monkeypatch.setattr(scheduler, "_ensure_prepared_model", lambda _items: None) - - def run_cell(item: PlannedCell) -> CellOutcome: - if item.cell == slow: - assert release_slow.wait(2.0) - elif item.cell == later: - later_started.set() - return CellOutcome(item.cell.cell_id, "ok", "complete") - - monkeypatch.setattr(scheduler, "_run_cell", run_cell) - planned = ( - PlannedCell(slow, False, None, 0), - PlannedCell(quick, False, None, 0), - PlannedCell(later, False, None, 4), - ) - - def run() -> None: - try: - results.append(scheduler.run(planned)) - except BaseException as error: # pragma: no cover - asserted below. - failures.append(error) - - thread = threading.Thread(target=run) - thread.start() - assert later_started.wait(1.0), "later ready work remained behind a rank wave" - release_slow.set() - thread.join(2.0) - - assert not thread.is_alive() - assert failures == [] - assert len(results) == 1 - - -def test_ready_queue_releases_dependents_without_waiting_for_unrelated_work( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - prerequisite = REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted") - unrelated = REPORT_CATALOG.cell("scalar-gravity-n2-scalar-gravity-contracted") - dependent = REPORT_CATALOG.cell("scalar-contact-n3-scalar-contact-contracted") - release_unrelated = threading.Event() - dependent_started = threading.Event() - failures: list[BaseException] = [] - - scheduler = CampaignScheduler(service, settings=CampaignSettings(workers=2)) - monkeypatch.setattr(scheduler, "_ensure_prepared_model", lambda _items: None) - - def run_cell(item: PlannedCell) -> CellOutcome: - if item.cell == unrelated: - assert release_unrelated.wait(2.0) - elif item.cell == dependent: - dependent_started.set() - return CellOutcome(item.cell.cell_id, "ok", "complete") - - monkeypatch.setattr(scheduler, "_run_cell", run_cell) - planned = ( - PlannedCell(prerequisite, False, None, 0), - PlannedCell(unrelated, False, None, 0), - PlannedCell( - dependent, - False, - None, - 3, - prerequisite_cell_ids=(prerequisite.cell_id,), - ), - ) - - def run() -> None: - try: - scheduler.run(planned) - except BaseException as error: # pragma: no cover - asserted below. - failures.append(error) - - thread = threading.Thread(target=run) - thread.start() - assert dependent_started.wait(1.0) - release_unrelated.set() - thread.join(2.0) - - assert not thread.is_alive() - assert failures == [] - - -def test_busy_cell_lock_is_deferred_without_consuming_the_only_worker_slot( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - cells = tuple( - sorted( - ( - REPORT_CATALOG.cell("scalar-contact-n2-scalar-contact-contracted"), - REPORT_CATALOG.cell("scalar-gravity-n2-scalar-gravity-contracted"), - ), - key=lambda cell: cell.cell_id, - ) - ) - locked, available = cells - available_finished = threading.Event() - observed: list[str] = [] - progress_events: list[Mapping[str, object]] = [] - failures: list[BaseException] = [] - - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - workers=1, - progress_observer=lambda payload: progress_events.append(dict(payload)), - ), - ) - monkeypatch.setattr(scheduler, "_ensure_prepared_model", lambda _items: None) - - def run_in_lane(item: PlannedCell) -> CellOutcome: - observed.append(item.cell.cell_id) - if item.cell == available: - available_finished.set() - return CellOutcome(item.cell.cell_id, "ok", "complete") - - monkeypatch.setattr(scheduler, "_run_cell_in_lane", run_in_lane) - planned = ( - PlannedCell(locked, False, None, 0), - PlannedCell(available, False, None, 0), - ) - - def run() -> None: - try: - scheduler.run(planned) - except BaseException as error: # pragma: no cover - asserted below. - failures.append(error) - - with service.store.named_lock(f"campaign-cell-{locked.cell_id}"): - thread = threading.Thread(target=run) - thread.start() - assert available_finished.wait(1.0) - thread.join(2.0) - - assert not thread.is_alive() - assert failures == [] - assert observed == [available.cell_id, locked.cell_id] - assert not any( - payload.get("event") == "finished" - and payload.get("cell_id") == locked.cell_id - and payload.get("status") == "error" - for payload in progress_events - ) - - -def test_busy_equivalent_owner_lock_does_not_block_independent_ready_work( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - equivalent = REPORT_CATALOG.equivalent_cells(target)[0] - baseline = REPORT_CATALOG.baseline_cell(target) - assert baseline is not None - independent = REPORT_CATALOG.cell( - "matrix-recurrence-builtin-sm-nlc-n1-dd-z-jets-contracted" - ) - revision = "current-revision" - owner = _publish_current(service.store, equivalent, revision=revision) - _publish_current(service.store, baseline, revision=revision) - _publish_current(service.store, independent, revision=revision) - independent_finished = threading.Event() - failures: list[BaseException] = [] - results: list[CampaignResult] = [] - - def observe(payload: Mapping[str, object]) -> None: - if ( - payload.get("event") == "finished" - and payload.get("cell_id") == independent.cell_id - ): - independent_finished.set() - - def fake_supervise( - command: Sequence[str], - **_arguments: object, - ) -> SupervisedResult: - result_path = Path(command[command.index("--result-json") + 1]) - result_path.write_text( - json.dumps(_ok_measurement(target, revision=revision)) + "\n", - encoding="ascii", - ) - return SupervisedResult( - 0, - "completed", - ResourceUsage(True, 1, 1, 0, 0.1, 0.1), - ) - - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - fake_supervise, - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings( - workers=1, - artifact_policy=ArtifactPolicy.REUSE, - progress_observer=observe, - ), - ) - scheduler.source_revision = revision - planned = ( - PlannedCell(target, False, baseline.cell_id, 0), - PlannedCell(independent, False, None, 1), - ) - - def run() -> None: - try: - results.append(scheduler.run(planned)) - except BaseException as error: # pragma: no cover - asserted below. - failures.append(error) - - with service.store.named_lock(f"campaign-artifact-use-{owner.attempt_id}"): - thread = threading.Thread(target=run) - thread.start() - assert independent_finished.wait(1.0) - thread.join(2.0) - - assert not thread.is_alive() - assert failures == [] - assert len(results) == 1 - assert {outcome.cell_id for outcome in results[0].outcomes} == { - target.cell_id, - independent.cell_id, - } - - -def test_ufo_compiled_cells_overlap_outside_the_worker_side_compiler_gate( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(workers=2), - ) - ufo_compiled = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.model is ModelKey.UFO_SM - and cell.measurement.execution_mode is ExecutionMode.COMPILED - )[:2] - assert len(ufo_compiled) == 2 - generating = threading.Event() - profiling = threading.Event() - - def run_in_lane(item: PlannedCell) -> CellOutcome: - if item.cell == ufo_compiled[0]: - generating.set() - assert profiling.wait(1.0) - else: - assert generating.wait(1.0) - profiling.set() - return CellOutcome(item.cell.cell_id, "ok", "complete") - - monkeypatch.setattr(scheduler, "_run_cell_in_lane", run_in_lane) - result = scheduler.run( - tuple(PlannedCell(cell, False, None, 0) for cell in ufo_compiled) - ) - - assert generating.is_set() and profiling.is_set() - assert not result.failed - - # A reusable cell does not touch the worker-side compiler gate at all. - monkeypatch.setattr( - scheduler, - "_run_cell_in_lane", - lambda item: CellOutcome(item.cell.cell_id, "reused", "current"), - ) - with service.store.named_lock("campaign-symbolica-compiled-capacity-1"): - outcome = scheduler._run_cell(PlannedCell(ufo_compiled[0], False, None, 0)) - - assert outcome.status == "reused" - assert "campaign-symbolica-compiled-capacity-1" not in ( - scheduler._coordination_lock_names(ufo_compiled[0]) - ) - - -def test_plan_campaign_builds_a_real_resource_predecessor_chain( - tmp_path: Path, -) -> None: - lane = tuple( - sorted( - ( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.measurement.accuracy is Accuracy.LC - and cell.workload is Workload.SELECTED_FLOW - and cell.process_key == "dd_z_jets" - and cell.n_final in {1, 2, 3} - ), - key=lambda cell: cell.n_final, - ) - ) - assert tuple(cell.n_final for cell in lane) == (1, 2, 3) - settings = CampaignSettings( - campaign_policy=X86_EPYC_POLICY, - report_profile=X86_EPYC_PROFILE, - workers=X86_EPYC_WORKERS, - max_rss_bytes=X86_EPYC_MEMORY_LIMIT_BYTES, - allow_symbolica_parallel=True, - ) - planned = plan_campaign( - lane, - store=_store(tmp_path), - settings=settings, - ) - by_id = {item.cell.cell_id: item for item in planned} - - assert by_id[lane[0].cell_id].resource_predecessor_ids == () - assert by_id[lane[1].cell_id].resource_predecessor_ids == (lane[0].cell_id,) - assert by_id[lane[2].cell_id].resource_predecessor_ids == (lane[1].cell_id,) - - -def test_same_model_preparation_lock_contention_is_deferred( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - scheduler = CampaignScheduler(_service(tmp_path), settings=CampaignSettings()) - planned = PlannedCell( - _matrix_cell("matrix_recurrence_builtin_sm_lc"), - dependency=False, - baseline_cell_id=None, - rank=0, - ) - started = threading.Event() - release = threading.Event() - failures: list[BaseException] = [] - - def prepare(_items: Sequence[PlannedCell]) -> None: - started.set() - assert release.wait(2.0) - - monkeypatch.setattr(scheduler, "_ensure_prepared_model", prepare) - - def first() -> None: - try: - scheduler._prepare_model_for(planned) - except BaseException as error: # pragma: no cover - asserted below. - failures.append(error) - - thread = threading.Thread(target=first) - thread.start() - assert started.wait(1.0) - with pytest.raises(_CoordinationDeferred): - scheduler._prepare_model_for(planned) - release.set() - thread.join(2.0) - - assert not thread.is_alive() - assert failures == [] - - -def test_successful_current_resume_never_duplicates_post_populate_cell( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - target = _matrix_cell("matrix_recurrence_builtin_sm_lc") - baseline = REPORT_CATALOG.baseline_cell(target) - assert baseline is not None - revision = "measured-revision" - _publish_current(service.store, baseline, revision=revision) - published = _publish_current(service.store, target, revision=revision) - monkeypatch.setattr( - "tools.performance_report.scheduler.supervise_worker", - lambda *_args, **_kwargs: pytest.fail( - "authenticated post-populate current must not be rerun" - ), - ) - scheduler = CampaignScheduler( - service, - settings=CampaignSettings(missing_only=True), - ) - scheduler.source_revision = revision - - outcome = scheduler._run_cell( - PlannedCell( - target, - dependency=False, - baseline_cell_id=baseline.cell_id, - rank=1, - ) - ) - - current = service.store.load_current(target.cell_id) - assert outcome.status == "skipped-current" - assert outcome.detail == "already complete" - assert current.attempt_id == published.attempt_id - - -@pytest.mark.parametrize("limit", (0.0, float("inf"), float("nan"))) -def test_campaign_rejects_invalid_generation_only_limit(limit: float) -> None: - with pytest.raises(ValueError, match="generation_time_limit_seconds"): - CampaignSettings(generation_time_limit_seconds=limit) diff --git a/pyamplicol/tests/unit/test_three_mode_report_service.py b/pyamplicol/tests/unit/test_three_mode_report_service.py deleted file mode 100644 index 943260d94f..0000000000 --- a/pyamplicol/tests/unit/test_three_mode_report_service.py +++ /dev/null @@ -1,461 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import errno -import hashlib -import json -import shutil -import subprocess -from pathlib import Path - -import pytest - -from tools.performance_report.agreements import DIRECT_AGREEMENT_FIELD -from tools.performance_report.cache import digest_json, empty_measurement, reset_entry -from tools.performance_report.catalog import ( - MADGRAPH_FULL_COMPARISON_VIEWS, - REPORT_CATALOG, -) -from tools.performance_report.measurement import failure_measurement -from tools.performance_report.models import ArtifactPolicy, ResultStatus -from tools.performance_report.publication import publication_absolute_paths -from tools.performance_report.render import render_all_tables -from tools.performance_report.runner import pointwise_validation -from tools.performance_report.service import ( - ReportPaths, - ReportService, - ReportServiceError, -) -from tools.performance_report.source_identity import require_eligible_report_source - - -def _service(tmp_path: Path) -> ReportService: - repo = tmp_path / "repo" - (repo / "docs/arxiv/results").mkdir(parents=True) - subprocess.run(("git", "init", "-q"), cwd=repo, check=True) - subprocess.run( - ("git", "config", "user.email", "report-tests@example.invalid"), - cwd=repo, - check=True, - ) - subprocess.run( - ("git", "config", "user.name", "Report Tests"), - cwd=repo, - check=True, - ) - (repo / "README.md").write_text("# report fixture\n", encoding="ascii") - subprocess.run(("git", "add", "README.md"), cwd=repo, check=True) - subprocess.run( - ("git", "commit", "-q", "-m", "Initialize fixture"), - cwd=repo, - check=True, - ) - return ReportService( - ReportPaths.from_repo( - repo, - artifact_root=tmp_path / "artifacts", - ) - ) - - -def test_reset_publishes_only_canonical_na_caches_and_twenty_seven_tables( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - - paths = service.publish(reset=True, merge_artifacts=False) - result = service.validate() - - assert result["table_count"] == 27 - assert result["statuses"] == { - "not_available": len(REPORT_CATALOG.measurement_cells()) - } - assert len([path for path in paths if path.suffix == ".tex"]) == 27 - assert all( - (service.paths.docs_dir / view.table_name).is_file() - for view in MADGRAPH_FULL_COMPARISON_VIEWS - ) - assert not ( - service.paths.docs_dir / "result_matrix_compiled_ufo_sm_full_table.tex" - ).exists() - assert (service.paths.results_dir / "report-cache.schema.json").is_file() - - -def test_static_na_cache_rejects_terminal_measurement(tmp_path: Path) -> None: - service = _service(tmp_path) - caches = service.reset_payloads() - cell = service.catalog.cell( - "reference-amplicol-full-n6-dd-4q-lines-contracted" - ) - payload = caches[f"{cell.dataset_id}.json"] - entry = next( - item for item in payload["entries"] if item["cell_id"] == cell.cell_id - ) - entry["measurement"] = failure_measurement( - ResultStatus.UNSUPPORTED, - "historical oracle scope", - ) - - with pytest.raises( - ReportServiceError, - match="catalog static N/A cache entry", - ): - service.validate_payloads(caches) - - -def test_static_na_current_never_merges_into_publication_cache( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - cell = service.catalog.cell( - "reference-amplicol-full-n6-dd-4q-lines-contracted" - ) - source = require_eligible_report_source(service.paths.repo_root) - measurement = failure_measurement( - ResultStatus.UNSUPPORTED, - "historical oracle scope", - ) - measurement["provenance"] = { - "report_source_revision": source.revision, - "report_source_tree": source.tree, - } - published = service.store.new_attempt( - cell.cell_id, - ArtifactPolicy.REGENERATE, - ).publish(measurement) - caches = service.reset_payloads() - payload = caches[f"{cell.dataset_id}.json"] - entry = next( - item for item in payload["entries"] if item["cell_id"] == cell.cell_id - ) - entry["measurement"] = failure_measurement( - ResultStatus.UNSUPPORTED, - "noncanonical cached terminal", - ) - - assert service.merge_current(caches) == 0 - assert entry["measurement"] == reset_entry(cell)["measurement"] - assert service.store.load_current(cell.cell_id).attempt_id == published.attempt_id - - -def test_merge_joins_immutable_current_record_by_cell_id(tmp_path: Path) -> None: - service = _service(tmp_path) - service.publish(reset=True, merge_artifacts=False) - source = require_eligible_report_source(service.paths.repo_root) - cell = next( - item - for item in service.catalog.measurement_cells() - if item.measurement.accuracy.value != "lc" - ) - observations = [ - { - "module": "pyamplicol", - "kind": "package-member", - "root_index": 0, - "path": "__init__.py", - "size": 1, - "sha256": "1" * 64, - } - ] - loaded_origin_policy = { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": 1, - "observations": observations, - "observations_sha256": hashlib.sha256( - json.dumps( - observations, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest(), - } - runtime_identity = { - "extension": { - "path": str(service.paths.repo_root / "native/_rusticol.so"), - }, - "loaded_module_origin_policy": loaded_origin_policy, - } - runtime_identity_sha256 = hashlib.sha256( - json.dumps( - runtime_identity, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - stable_runtime_identity = json.loads(json.dumps(runtime_identity)) - stable_policy = stable_runtime_identity["loaded_module_origin_policy"] - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - stable_policy.pop(field) - runtime_identity_stable_sha256 = hashlib.sha256( - json.dumps( - stable_runtime_identity, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - measurement = empty_measurement() - measurement.update( - { - "status": "ok", - "generation_seconds": 1.0, - "wall_seconds_per_point": 2.0, - "execution_seconds_per_point": None, - "matrix_element": 3.0, - "sample_count": 5, - "standard_error_seconds_per_point": 0.0, - "relative_standard_error": 0.0, - "artifact": { - "path": str(service.paths.artifact_root / "cells/example/artifact"), - "log_path": str( - service.paths.artifact_root / "cells/example/worker.log" - ), - }, - "selector_contract": None, - "validation": {"status": "ok", DIRECT_AGREEMENT_FIELD: []}, - "resources": {}, - "provenance": { - "report_source_revision": source.revision, - "report_source_tree": source.tree, - "effective_config": { - "model": { - "cache_dir": str(service.paths.repo_root / ".cache/model"), - } - }, - "runtime_identity": runtime_identity, - "runtime_identity_sha256": runtime_identity_sha256, - "runtime_identity_stable_sha256": ( - runtime_identity_stable_sha256 - ), - "runtime_identity_postflight_stable_sha256": ( - runtime_identity_stable_sha256 - ), - "runtime_identity_postflight_loaded_module_origin_policy": ( - loaded_origin_policy - ), - "runtime_identity_postflight_match": True, - }, - } - ) - service.store.new_attempt(cell.cell_id, ArtifactPolicy.REGENERATE).publish( - measurement - ) - - service.publish() - cache_path = service.paths.results_dir / f"{cell.dataset_id}.json" - payload = json.loads(cache_path.read_text(encoding="ascii")) - entry = next(item for item in payload["entries"] if item["cell_id"] == cell.cell_id) - assert entry["measurement"]["matrix_element"] == 3.0 - publication = entry["measurement"] - assert publication["artifact"]["path"].startswith( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - assert publication["artifact"]["log_path"].startswith( - "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}/" - ) - assert publication["provenance"]["effective_config"]["model"][ - "cache_dir" - ].startswith("${PYAMPLICOL_SOURCE_ROOT}/") - assert publication["provenance"]["runtime_identity"] == runtime_identity - retained_identity = publication["provenance"]["runtime_identity"] - assert ( - hashlib.sha256( - json.dumps( - retained_identity, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - == publication["provenance"]["runtime_identity_sha256"] - ) - assert publication_absolute_paths(payload) == () - - -def test_failed_snapshot_publication_restores_previous_files( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - service.publish(reset=True, merge_artifacts=False) - table = service.paths.docs_dir / "result_scalar_contact_table.tex" - cache = service.paths.results_dir / "scalar_contact.json" - old_table = table.read_bytes() - old_cache = cache.read_bytes() - - original_replace = Path.replace - original_copy2 = shutil.copy2 - calls = 0 - staging_sources: list[Path] = [] - - def observe_staging_copy(source: Path, destination: Path) -> Path: - if ".report-snapshot-" in str(source): - staging_sources.append(source) - return original_copy2(source, destination) - - def fail_after_one_replace(source: Path, destination: Path) -> Path: - nonlocal calls - if ".report-install-" in source.name: - calls += 1 - if calls == 3: - raise OSError("injected publication interruption") - return original_replace(source, destination) - - monkeypatch.setattr(shutil, "copy2", observe_staging_copy) - monkeypatch.setattr(Path, "replace", fail_after_one_replace) - with pytest.raises(OSError, match="injected"): - service.publish(reset=True, merge_artifacts=False) - - assert table.read_bytes() == old_table - assert cache.read_bytes() == old_cache - assert staging_sources - assert all( - source.is_relative_to(service.paths.artifact_root) - for source in staging_sources - ) - assert not tuple(service.paths.docs_dir.glob(".report-snapshot-*")) - snapshot_root = service.paths.artifact_root / "report-snapshot-builds" - assert snapshot_root.is_dir() - assert not tuple(snapshot_root.iterdir()) - assert not tuple(service.paths.docs_dir.glob(".*.report-*-*")) - assert not tuple(service.paths.results_dir.glob(".*.report-*-*")) - - -def test_snapshot_install_remains_atomic_across_artifact_filesystems( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - service = _service(tmp_path) - service.publish(reset=True, merge_artifacts=False) - original_replace = Path.replace - installs: list[tuple[Path, Path]] = [] - - def reject_cross_directory_replace(source: Path, destination: Path) -> Path: - if source.parent != destination.parent: - raise OSError(errno.EXDEV, "injected cross-device replacement") - installs.append((source, destination)) - return original_replace(source, destination) - - monkeypatch.setattr(Path, "replace", reject_cross_directory_replace) - written = service.publish(reset=True, merge_artifacts=False) - - assert written - assert installs - assert all(source.parent == destination.parent for source, destination in installs) - assert not tuple(service.paths.docs_dir.glob(".*.report-*-*")) - assert not tuple(service.paths.results_dir.glob(".*.report-*-*")) - - -def test_audit_rejects_nonpublication_timing_and_source_evidence( - tmp_path: Path, -) -> None: - service = _service(tmp_path) - caches = service.reset_payloads() - payload = caches["scalar_contact.json"] - entry = payload["entries"][0] - cell = service.catalog.cell(str(entry["cell_id"])) - point_digest = "a" * 64 - ordering = "b" * 64 - - def resolved(precision: int, source: str) -> dict[str, object]: - point = pointwise_validation( - 3.0, - 3.0, - candidate_scale=3.0, - baseline_scale=3.0, - comparison_binding={ - "abi": "pyamplicol-report-resolved-component-scale-v1", - "point_digest": point_digest, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "point_index": 0, - }, - ) - return { - "abi": "pyamplicol-report-resolved-sum-validation-v2", - "status": "ok", - "maximum_absolute_difference": 0.0, - "maximum_relative_difference": 0.0, - "maximum_conditioned_residual": 0.0, - "relative_tolerance": 1.0e-12, - "point_digest": point_digest, - "helicity_ids": [], - "color_flow_ids": [], - "resolved_ordering_sha256": ordering, - "resolved_source_sha256": source, - "scale_source": "resolved-component-l1", - "precision_digits": precision, - "points": [point], - } - - binary64 = resolved(16, "c" * 64) - precision32 = resolved(32, "d" * 64) - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": None, - "value_kind": "matrix-element-p16-versus-p32", - } - measurement = empty_measurement() - measurement.update( - { - "status": "ok", - "generation_seconds": 1.0, - "wall_seconds_per_point": 2.0e-6, - "execution_seconds_per_point": 1.0e-6, - "matrix_element": 3.0, - "sample_count": 5, - "standard_error_seconds_per_point": 1.0e-9, - "relative_standard_error": 1.0e-3, - "artifact": {}, - "selector_contract": None, - "validation": { - "status": "ok", - DIRECT_AGREEMENT_FIELD: [], - "resolved_sum": binary64, - "high_precision_resolved_sum": precision32, - "high_precision": pointwise_validation( - 3.0, - 3.0, - candidate_scale=3.0, - baseline_scale=3.0, - candidate_scale_source="resolved-component-l1-binary64", - baseline_scale_source="resolved-component-l1-p32", - comparison_binding={ - "point_digest": point_digest, - "selector_component_identity": selector_identity, - "selector_component_sha256": digest_json(selector_identity), - "candidate_source_sha256": "c" * 64, - "baseline_source_sha256": "d" * 64, - }, - ), - }, - "resources": {}, - "provenance": {}, - "failure": None, - } - ) - entry["measurement"] = measurement - service._snapshot_files( - caches, - render_all_tables(caches, catalog=service.catalog), - ) - - with pytest.raises(ReportServiceError, match="publication policy"): - service.audit() diff --git a/pyamplicol/tests/unit/test_umami_example_environment.py b/pyamplicol/tests/unit/test_umami_example_environment.py deleted file mode 100644 index 1fe7f1e4f2..0000000000 --- a/pyamplicol/tests/unit/test_umami_example_environment.py +++ /dev/null @@ -1,244 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Exercise example preflights without native or optional integration packages.""" - -from __future__ import annotations - -import builtins -import importlib.util -import json -import os -import subprocess -import sys -from pathlib import Path -from types import ModuleType - -import pytest - -EXAMPLE = Path(__file__).resolve().parents[2] / "umami_example" - - -@pytest.fixture -def example_modules(monkeypatch): - def load(name, filename): - spec = importlib.util.spec_from_file_location(name, EXAMPLE / filename) - module = importlib.util.module_from_spec(spec) - monkeypatch.setitem(sys.modules, name, module) - spec.loader.exec_module(module) - return module - - metadata = load("_metadata", "_metadata.py") - runner = load("_umami_example_run", "run.py") - return metadata, runner - - -def install_exporter(monkeypatch, path, *, legacy=False): - """Model the imported package, not pytest's repository source path.""" - package = ModuleType("pyamplicol") - package.__path__ = [str(path.parents[1])] - artifacts = ModuleType("pyamplicol.artifacts") - artifacts.__path__ = [str(path.parent)] - exporter = ModuleType("pyamplicol.artifacts.umami") - exporter.__file__ = str(path) - - def old_exporter(*, processes, compiled_model, grouping="exact"): - raise AssertionError("preflight must not generate metadata") - - def current_exporter(*, processes, compiled_model): - raise AssertionError("preflight must not generate metadata") - - exporter.build_umami_metadata = old_exporter if legacy else current_exporter - package.artifacts = artifacts - artifacts.umami = exporter - for module in (package, artifacts, exporter): - monkeypatch.setitem(sys.modules, module.__name__, module) - return exporter - - -def metadata_document(*, physical=24, exported=4): - entries = [ - {"members": [{} for _ in range(physical // exported)]} for _ in range(exported) - ] - return { - "provider": { - "id": "lc", - "incoming_count": 2, - "color_accuracy": "lc", - "library": "libumami.so", - }, - "channels": [ - {"processes": entries[:2]}, - {"processes": entries[2:3]}, - {"processes": entries[3:]}, - ], - "grouping": { - "physical_contributions": physical, - "exported_contributions": exported, - }, - } - - -def write_metadata(path, data): - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(json.dumps(data)) - return path - - -def forbid_expensive_work(monkeypatch, runner): - def forbidden(*args, **kwargs): - pytest.fail("preflight must finish before dependencies, generation or build") - - monkeypatch.setattr(runner, "generate", forbidden) - monkeypatch.setattr(runner, "execute", forbidden) - monkeypatch.setattr(runner.shutil, "which", forbidden) - original_import = builtins.__import__ - - def import_without_optional(name, *args, **kwargs): - if name.split(".", 1)[0] in {"madspace", "madnis", "vegas", "torch"}: - forbidden() - return original_import(name, *args, **kwargs) - - monkeypatch.setattr(builtins, "__import__", import_without_optional) - - -def test_current_exporter_returns_the_imported_path( - example_modules, monkeypatch, tmp_path -): - metadata, _ = example_modules - installed = tmp_path / "site-packages/pyamplicol/artifacts/umami.py" - install_exporter(monkeypatch, installed) - - assert metadata.require_current_exporter() == installed.resolve() - - -def test_stale_exporter_stops_runner_before_generation( - example_modules, monkeypatch, tmp_path -): - _, runner = example_modules - installed = tmp_path / "site-packages/pyamplicol/artifacts/umami.py" - install_exporter(monkeypatch, installed, legacy=True) - output = tmp_path / "output" - monkeypatch.setattr(sys, "argv", ["run.py", "--output", str(output)]) - forbid_expensive_work(monkeypatch, runner) - - with pytest.raises(RuntimeError) as error: - runner.main() - - message = str(error.value) - assert str(installed) in message - assert sys.executable in message - assert "reinstall" in message.lower() - assert "--output" in message - assert "--reuse" in message - assert not output.exists() - - -@pytest.mark.parametrize("physical", [4, 24]) -def test_current_metadata_accepts_uncompressed_and_grouped_contributions( - example_modules, tmp_path, physical -): - metadata, _ = example_modules - data = metadata_document(physical=physical) - path = write_metadata(tmp_path / "metadata.json", data) - - assert metadata.load_metadata(path) == data - assert metadata.grouping_summary(data) == ( - "3 integration channels, 4 representative contributions, " - f"{physical} physical contributions" - ) - - -def test_current_restricted_metadata_does_not_require_a_grouping_reduction( - example_modules, tmp_path -): - metadata, _ = example_modules - data = metadata_document(physical=1, exported=1) - data["channels"] = data["channels"][:1] - path = write_metadata(tmp_path / "metadata.json", data) - - assert metadata.load_metadata(path) == data - - -@pytest.mark.parametrize( - "grouping", - [ - None, - {}, - {"physical_contributions": 24}, - {"exported_contributions": 4}, - {"mode": "exact", "physical_contributions": 24, "exported_contributions": 24}, - ], -) -def test_legacy_metadata_is_rejected_with_recovery_instructions( - example_modules, tmp_path, grouping -): - metadata, _ = example_modules - data = metadata_document() - if grouping is None: - del data["grouping"] - else: - data["grouping"] = grouping - path = write_metadata(tmp_path / "metadata.json", data) - - with pytest.raises(ValueError) as error: - metadata.load_metadata(path) - - message = str(error.value) - assert str(path) in message - assert "reinstall" in message.lower() - assert "--output" in message - assert "--reuse" in message - - -def test_reuse_rejects_legacy_metadata_before_optional_dependencies_or_build( - example_modules, monkeypatch, tmp_path -): - _, runner = example_modules - install_exporter(monkeypatch, tmp_path / "installed/pyamplicol/artifacts/umami.py") - data = metadata_document() - data["grouping"]["mode"] = "exact" - path = write_metadata(tmp_path / "output/lc/API/umami/metadata.json", data) - monkeypatch.setattr( - sys, - "argv", - ["run.py", "--output", str(tmp_path / "output"), "--reuse", "--accuracy", "lc"], - ) - forbid_expensive_work(monkeypatch, runner) - - with pytest.raises(ValueError, match=r"metadata\.json"): - runner.main() - - assert json.loads(path.read_text()) == data - - -def test_script_detects_the_installed_exporter_from_an_unrelated_working_directory( - tmp_path, -): - """The real script entry point must not depend on pytest's src path injection.""" - site = tmp_path / "site-packages" - package = site / "pyamplicol" - artifacts = package / "artifacts" - artifacts.mkdir(parents=True) - (package / "__init__.py").write_text("") - (artifacts / "__init__.py").write_text("") - exporter = artifacts / "umami.py" - exporter.write_text( - "def build_umami_metadata(*, processes, compiled_model, grouping='exact'):\n" - " raise AssertionError('generation must not start')\n" - ) - output = tmp_path / "output" - result = subprocess.run( - [sys.executable, "-S", str(EXAMPLE / "run.py"), "--output", str(output)], - cwd=tmp_path, - env={**os.environ, "PYTHONPATH": str(site)}, - capture_output=True, - text=True, - timeout=10, - ) - - assert result.returncode != 0 - assert str(exporter) in result.stderr - assert sys.executable in result.stderr - assert "reinstall" in result.stderr.lower() - assert "--reuse" in result.stderr - assert "ModuleNotFoundError" not in result.stderr - assert not output.exists() diff --git a/pyamplicol/tests/unit/test_umami_example_grouping.py b/pyamplicol/tests/unit/test_umami_example_grouping.py deleted file mode 100644 index 6d86be31b0..0000000000 --- a/pyamplicol/tests/unit/test_umami_example_grouping.py +++ /dev/null @@ -1,112 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Check example bookkeeping without installing optional integration packages.""" - -from __future__ import annotations - -import ast -import math -from dataclasses import dataclass, field -from pathlib import Path - -import pytest - - -@pytest.fixture(scope="module") -def helpers(): - directory = Path(__file__).resolve().parents[2] / "umami_example" - namespace = { - "__name__": __name__, - "dataclass": dataclass, - "field": field, - "math": math, - "Path": Path, - } - for filename, names in ( - ("test_integrate.py", {"Channel", "Config", "Cuts", "build_ms_cuts"}), - ("test_grouping.py", {"physical_member_channels", "check_agreement"}), - ): - path = directory / filename - definitions = [ - node - for node in ast.parse(path.read_text(), filename=str(path)).body - if isinstance(node, (ast.ClassDef, ast.FunctionDef)) and node.name in names - ] - assert len(definitions) == len(names) - exec( - compile( - ast.Module(body=definitions, type_ignores=[]), - str(path), - "exec", - dont_inherit=True, - ), - namespace, - ) - return namespace - - -def test_member_channels_compose_maps_and_keep_physical_weights(helpers): - representative = [0, 1, 4, 2, 3] - member_map = [0, 1, 3, 2, 4] - pdgs = [1, -1, 21, 21, 21] - member = { - "runtime": {"permutation": member_map}, - "pdgs": pdgs, - "factor": 0.5, - } - entry = { - "runtime": {"permutation": representative}, - "matrix_elements": [{"factor": 17.0}], - "members": [member, {**member, "factor": 1.0}], - } - data = { - "provider": {"particle_count": 5, "masses": [0.0] * 5}, - "channels": [ - {"processes": []}, - { - "phasespace_order": [0, 2, 1, 3, 4], - "processes": [entry, {**entry, "members": [member]}], - }, - ], - } - channels = helpers["physical_member_channels"](data) - assert [ch.index for ch in channels] == [0, 1, 2] - assert [ch.selector for ch in channels] == [(1, 0), (1, 0), (1, 1)] - assert [ch.processes[0][0][0] for ch in channels] == [0.5, 1.0, 0.5] - for channel in channels: - permutation = channel.momentum_permutation - assert permutation == [0, 1, 2, 4, 3] - assert [permutation[i] for i in representative] == member_map - assert permutation[:2] == [0, 1] - assert channel.color_order == [0, 2, 1, 4, 3] - assert channel.init_states == [(1, -1)] - assert channel.pdg_final == pdgs[2:] - - -@pytest.mark.parametrize( - ("value", "error", "failure"), - [ - (10.02, 0.1, None), - (12.0, 0.1, "differ"), - (10.0, 0.6, "inconclusive"), - (math.nan, 0.1, "positive finite"), - (10.0, 0.0, "positive finite"), - ], -) -def test_integral_agreement(helpers, value, error, failure): - results = { - "grouped": {"integral": value, "uncertainty": error}, - "physical_members": {"integral": 10.0, "uncertainty": 0.1}, - } - if failure: - with pytest.raises(AssertionError, match=failure): - helpers["check_agreement"](results) - else: - comparison = helpers["check_agreement"](results) - assert comparison["combined_error"] == pytest.approx(math.hypot(error, 0.1)) - assert comparison["standard_errors"] < 6.0 - - -def test_species_selective_cuts_are_rejected(helpers): - cfg = helpers["Config"](cuts=helpers["Cuts"](pdgs=[21])) - with pytest.raises(ValueError, match="flavour-blind"): - helpers["build_ms_cuts"](cfg, None) diff --git a/pyamplicol/tests/unit/test_x86_performance_runtime_bundle.py b/pyamplicol/tests/unit/test_x86_performance_runtime_bundle.py deleted file mode 100644 index da99c55fcb..0000000000 --- a/pyamplicol/tests/unit/test_x86_performance_runtime_bundle.py +++ /dev/null @@ -1,731 +0,0 @@ -# SPDX-License-Identifier: 0BSD -from __future__ import annotations - -import argparse -import copy -import hashlib -import json -from pathlib import Path -from types import SimpleNamespace -from typing import Any - -import pytest - -from tools.developer import compiled_mode_matrix as matrix -from tools.developer import x86_performance_runtime_bundle as bundle - - -def _write(path: Path, payload: object) -> Path: - path.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - return path - - -def test_embedded_frozen_install_state_has_accepted_digest() -> None: - encoded = bundle.frozen_install_state_bytes() - assert hashlib.sha256(encoded).hexdigest() == ( - bundle.FROZEN_INSTALL_STATE_SHA256 - ) - payload = json.loads(encoded) - assert payload["created_utc"] == "2026-07-24T16:52:37.275744+00:00" - assert payload["candidate_lock_sha256"] == ( - bundle.FROZEN_CANDIDATE_LOCK_SHA256 - ) - assert payload["cargo_config_sha256"] == bundle.FROZEN_CARGO_CONFIG_SHA256 - assert payload["sources"]["legacy-amplicol"]["revision"] == ( - "79c96cecf2a722e50c3d2030b6894d755f96518a" - ) - - -def test_frozen_cargo_config_keeps_exact_path_dependent_digest() -> None: - assert Path("/private/tmp/pyamplicol-eager-compiled-arena-base-src") == ( - bundle.FROZEN_SOURCE_ROOT - ) - encoded = bundle.frozen_cargo_config_bytes() - assert hashlib.sha256(encoded).hexdigest() == ( - bundle.FROZEN_CARGO_CONFIG_SHA256 - ) - assert encoded.count(bytes(bundle.FROZEN_SOURCE_ROOT)) == 4 - relocated = encoded.replace( - bytes(bundle.FROZEN_SOURCE_ROOT), - b"/tmp/pyamplicol-eager-compiled-arena-base-src", - ) - assert hashlib.sha256(relocated).hexdigest() == ( - "f8aa48f1643251904cd1268d648a5741b4909f678fc4964e0538594165064d29" - ) - - -def test_freeze_baseline_requires_exact_path_revision_and_generated_inputs( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = tmp_path / "baseline" - dependencies = source / "dependencies" - dependencies.mkdir(parents=True) - lock = dependencies / "candidate-Cargo.lock" - config = dependencies / "candidate-cargo-config.toml" - lock.write_bytes(b"lock") - config.write_bytes(b"config") - for relative in bundle._BASELINE_BOOTSTRAP_ROOTS: - (source / relative).mkdir(parents=True) - (source / ".venv/bin").mkdir() - (source / ".venv/bin/python").write_bytes(b"python") - (source / "dependencies/checkouts/symbolica").mkdir(parents=True) - (source / "dependencies/checkouts/symbolica/file").write_bytes(b"checkout") - (source / "dependencies/wheelhouse/dependency.whl").write_bytes(b"wheel") - monkeypatch.setattr(bundle, "FROZEN_SOURCE_ROOT", source.resolve()) - monkeypatch.setattr( - bundle, - "FROZEN_CANDIDATE_LOCK_SHA256", - hashlib.sha256(b"lock").hexdigest(), - ) - monkeypatch.setattr( - bundle, - "FROZEN_CARGO_CONFIG_SHA256", - hashlib.sha256(b"config").hexdigest(), - ) - monkeypatch.setattr(bundle, "frozen_cargo_config_bytes", lambda: b"config") - frozen = dict(bundle.FROZEN_INSTALL_STATE) - frozen["candidate_lock_sha256"] = bundle.FROZEN_CANDIDATE_LOCK_SHA256 - frozen["cargo_config_sha256"] = bundle.FROZEN_CARGO_CONFIG_SHA256 - monkeypatch.setattr(bundle, "FROZEN_INSTALL_STATE", frozen) - encoded = bundle.frozen_install_state_bytes() - (dependencies / "install-state.json").write_bytes(encoded) - monkeypatch.setattr( - bundle, - "FROZEN_INSTALL_STATE_SHA256", - hashlib.sha256(encoded).hexdigest(), - ) - def git_output(_root: Path, *arguments: str) -> str: - if arguments[:2] == ("rev-parse", "--verify"): - return matrix.FROZEN_BASELINE_SOURCE_REVISION + "\n" - if arguments[:1] == ("status",): - return "" - if arguments[:1] == ("ls-files",): - return "\0".join( - ( - *bundle._BASELINE_GENERATED_FILES, - ".venv/bin/python", - "dependencies/checkouts/symbolica/file", - "dependencies/wheelhouse/dependency.whl", - "", - ) - ) - raise AssertionError(arguments) - - monkeypatch.setattr(bundle, "_git_output", git_output) - result = bundle.freeze_baseline(source) - assert result["passes"] is True - bundle._require_content_identity(result) - assert (dependencies / "install-state.json").read_bytes() == encoded - - config.write_bytes(b"changed") - with pytest.raises(bundle.BundleError, match="dependency inputs differ"): - bundle.freeze_baseline(source) - - -def _installation(source: str, inputs: str, marker: str) -> dict[str, object]: - return { - "package_version": "0.1.0.dev0+candidate.test", - "build_info": { - "source_revision": source, - "native_build_inputs_sha256": inputs, - "publishable": False, - }, - "build_info_sha256": marker * 64, - "distribution_content": { - "algorithm": "sha256-relative-path-size-content-v1", - "sha256": marker * 64, - "file_count": 10, - "size_bytes": 100, - }, - "native_module": { - "relative_path": "pyamplicol/_rusticol.abi3.so", - "sha256": marker * 64, - "size_bytes": 50, - }, - } - - -def _baseline_attestation() -> dict[str, object]: - generated_sha256 = { - "dependencies/candidate-Cargo.lock": ( - bundle.FROZEN_CANDIDATE_LOCK_SHA256 - ), - "dependencies/candidate-cargo-config.toml": ( - bundle.FROZEN_CARGO_CONFIG_SHA256 - ), - "dependencies/install-state.json": bundle.FROZEN_INSTALL_STATE_SHA256, - } - ignored_paths = sorted( - ( - *bundle._BASELINE_GENERATED_FILES, - ".venv/bin/python", - "dependencies/checkouts/symbolica/file", - "dependencies/wheelhouse/dependency.whl", - ) - ) - return bundle._attach_content_identity( - { - "kind": bundle.BASELINE_ATTESTATION_KIND, - "schema_version": bundle.SCHEMA_VERSION, - "source_root": str(bundle.FROZEN_SOURCE_ROOT), - "source_revision": matrix.FROZEN_BASELINE_SOURCE_REVISION, - "native_build_inputs_sha256": ( - matrix.FROZEN_BASELINE_NATIVE_INPUTS_SHA256 - ), - "candidate_lock_sha256": bundle.FROZEN_CANDIDATE_LOCK_SHA256, - "cargo_config_sha256": bundle.FROZEN_CARGO_CONFIG_SHA256, - "install_state_sha256": bundle.FROZEN_INSTALL_STATE_SHA256, - "source_inventory": { - "tracked_and_untracked_status_clean": True, - "ignored_entry_count": len(ignored_paths), - "ignored_relative_paths": ignored_paths, - "ignored_paths_sha256": bundle._canonical_sha256(ignored_paths), - "ignored_entries_by_bootstrap_root": { - relative.rstrip("/"): sum( - path.startswith(relative) for path in ignored_paths - ) - for relative in bundle._BASELINE_BOOTSTRAP_ROOTS - }, - "allowed_generated_files": list(bundle._BASELINE_GENERATED_FILES), - "allowed_bootstrap_roots": list(bundle._BASELINE_BOOTSTRAP_ROOTS), - "unexpected_ignored_files": [], - }, - "generated_identity": { - "generated_files": { - relative: { - "relative_path": relative, - "size_bytes": 1, - "sha256": generated_sha256[relative], - } - for relative in bundle._BASELINE_GENERATED_FILES - }, - "bootstrap_trees": { - relative.rstrip("/"): { - "algorithm": "sha256-relative-path-size-content-v1", - "relative_path": relative.rstrip("/"), - "sha256": "a" * 64, - "file_count": 1, - "size_bytes": 1, - } - for relative in bundle._BASELINE_BOOTSTRAP_ROOTS - }, - }, - "passes": True, - } - ) - - -def _set_ignored_inventory( - body: dict[str, object], - paths: list[str], -) -> None: - inventory = body["source_inventory"] - assert isinstance(inventory, dict) - inventory["ignored_entry_count"] = len(paths) - inventory["ignored_relative_paths"] = paths - inventory["ignored_paths_sha256"] = bundle._canonical_sha256(paths) - inventory["ignored_entries_by_bootstrap_root"] = { - relative.rstrip("/"): sum(path.startswith(relative) for path in paths) - for relative in bundle._BASELINE_BOOTSTRAP_ROOTS - } - - -def _manifest_arguments(tmp_path: Path) -> argparse.Namespace: - root = tmp_path / "bundle" - for lane in ("baseline", "current"): - directory = root / "wheels" / lane - directory.mkdir(parents=True) - (directory / f"{lane}.whl").write_bytes(lane.encode()) - prepared = root / "prepared-models" / "ufo-sm-jit-o2.pyamplicol-model" - prepared.parent.mkdir(parents=True) - prepared.write_bytes(b"prepared") - attestation = _baseline_attestation() - (root / "frozen-baseline-attestation.json").write_text( - json.dumps(attestation, sort_keys=True, allow_nan=False), - encoding="utf-8", - ) - return argparse.Namespace( - bundle_root=root, - baseline_python=Path("/runtime/baseline/python"), - current_python=Path("/runtime/current/python"), - dependency_site=Path("/runtime/dependencies"), - workflow_run_id="4242", - expected_current_revision="a" * 40, - expected_current_native_inputs_sha256="b" * 64, - output=tmp_path / "manifest.json", - ) - - -def test_manifest_binds_binaries_dependencies_and_prepared_model( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - arguments = _manifest_arguments(tmp_path) - installations = { - str(arguments.baseline_python): _installation( - matrix.FROZEN_BASELINE_SOURCE_REVISION, - matrix.FROZEN_BASELINE_NATIVE_INPUTS_SHA256, - "c", - ), - str(arguments.current_python): _installation( - arguments.expected_current_revision, - arguments.expected_current_native_inputs_sha256, - "d", - ), - } - monkeypatch.setattr( - bundle, - "_installation", - lambda path: installations[str(path)], - ) - dependency = { - "algorithm": "deps-v1", - "sha256": "e" * 64, - "distributions": {}, - } - monkeypatch.setattr(bundle, "_stable_dependency_site", lambda _path: dependency) - monkeypatch.setattr(bundle.platform, "system", lambda: "Linux") - monkeypatch.setattr(bundle.platform, "machine", lambda: "x86_64") - payload = bundle.create_manifest(arguments) - assert payload["passes"] is True - assert payload["installations"]["baseline"] == installations[ - str(arguments.baseline_python) - ] - assert payload["dependency_site"] == dependency - bundle._require_content_identity(payload) - - verify = argparse.Namespace( - **{ - key: value - for key, value in vars(arguments).items() - if key - not in { - "expected_current_native_inputs_sha256", - "output", - } - }, - manifest=arguments.output, - ) - result = bundle.verify_manifest(verify) - assert result["passes"] is True - assert result["manifest_content_sha256"] == payload["content_identity"]["sha256"] - - wheel = arguments.bundle_root / "wheels" / "current" / "current.whl" - wheel.write_bytes(b"tampered") - with pytest.raises(bundle.BundleError, match="files differ"): - bundle.verify_manifest(verify) - - -def test_manifest_rejects_wrong_frozen_or_current_source( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - arguments = _manifest_arguments(tmp_path) - monkeypatch.setattr(bundle.platform, "system", lambda: "Linux") - monkeypatch.setattr(bundle.platform, "machine", lambda: "x86_64") - monkeypatch.setattr( - bundle, - "_installation", - lambda _path: _installation("f" * 40, "0" * 64, "1"), - ) - with pytest.raises(bundle.BundleError, match="baseline installed build"): - bundle.create_manifest(arguments) - - -def test_content_identity_rejects_manifest_tampering() -> None: - payload = bundle._attach_content_identity({"passes": True, "value": 1}) - bundle._require_content_identity(payload) - payload["value"] = 2 - with pytest.raises(bundle.BundleError, match="content identity"): - bundle._require_content_identity(payload) - payload = bundle._attach_content_identity({"passes": True, "value": 1}) - payload["content_identity"]["unexpected"] = True - with pytest.raises(bundle.BundleError, match="content identity"): - bundle._require_content_identity(payload) - - -def test_baseline_attestation_rejects_unknown_root_field( - tmp_path: Path, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - body["unexpected"] = True - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - with pytest.raises(bundle.BundleError, match="attestation is invalid"): - bundle._baseline_attestation_inventory(root) - - -@pytest.mark.parametrize( - ("field", "operation"), - [ - ("allowed_generated_files", "missing"), - ("allowed_generated_files", "extra"), - ("allowed_generated_files", "wrong-type"), - ("allowed_bootstrap_roots", "missing"), - ("allowed_bootstrap_roots", "extra"), - ("allowed_bootstrap_roots", "wrong-type"), - ], -) -def test_baseline_attestation_rejects_inexact_allowed_inventories( - tmp_path: Path, - field: str, - operation: str, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - inventory = body["source_inventory"] - assert isinstance(inventory, dict) - value = inventory[field] - assert isinstance(value, list) - if operation == "missing": - inventory[field] = value[:-1] - elif operation == "extra": - inventory[field] = [*value, "unexpected/"] - else: - inventory[field] = "not-a-list" - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - with pytest.raises(bundle.BundleError, match="attestation is invalid"): - bundle._baseline_attestation_inventory(root) - - -def test_baseline_attestation_rejects_wrong_ignored_entry_count( - tmp_path: Path, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - body["source_inventory"]["ignored_entry_count"] += 1 - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - with pytest.raises(bundle.BundleError, match="attestation is invalid"): - bundle._baseline_attestation_inventory(root) - - -@pytest.mark.parametrize( - "mutation", - [ - "digest", - "unsorted", - "duplicate", - "outside", - "missing-generated", - "root-count", - ], -) -def test_baseline_attestation_rejects_inexact_ignored_path_inventory( - tmp_path: Path, - mutation: str, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - inventory = body["source_inventory"] - paths = list(inventory["ignored_relative_paths"]) - if mutation == "digest": - inventory["ignored_paths_sha256"] = "0" * 64 - elif mutation == "unsorted": - _set_ignored_inventory(body, list(reversed(paths))) - elif mutation == "duplicate": - _set_ignored_inventory(body, [*paths, paths[-1]]) - elif mutation == "outside": - _set_ignored_inventory(body, sorted((*paths, "src/unexpected.py"))) - elif mutation == "missing-generated": - _set_ignored_inventory( - body, - [path for path in paths if path != bundle._BASELINE_GENERATED_FILES[0]], - ) - else: - counts = inventory["ignored_entries_by_bootstrap_root"] - first_root = next(iter(counts)) - counts[first_root] += 1 - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - with pytest.raises(bundle.BundleError, match="attestation is invalid"): - bundle._baseline_attestation_inventory(root) - - -def test_baseline_attestation_keeps_git_and_tree_counts_independent( - tmp_path: Path, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - ignored_paths = sorted( - ( - *bundle._BASELINE_GENERATED_FILES, - ".venv/bin/python", - "dependencies/checkouts/gammaloop/", - *( - f"dependencies/checkouts/entry-{index:03d}" - for index in range(175) - ), - "dependencies/wheelhouse/dependency.whl", - ) - ) - _set_ignored_inventory(body, ignored_paths) - body["generated_identity"]["bootstrap_trees"][ - "dependencies/checkouts" - ]["file_count"] = 6631 - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - result = bundle._baseline_attestation_inventory(root) - assert result["content_sha256"] - - -def test_ignored_inventory_path_normalization_allows_directory_markers() -> None: - assert bundle._valid_ignored_relative_path( - "dependencies/checkouts/gammaloop/" - ) - for invalid in ( - "dependencies/checkouts/gammaloop//", - "dependencies/./checkouts/gammaloop/", - "dependencies/../checkouts/gammaloop/", - "/dependencies/checkouts/gammaloop/", - ".", - "../", - ): - assert not bundle._valid_ignored_relative_path(invalid) - - -@pytest.mark.parametrize( - ("section", "operation"), - [ - ("generated_files", "missing"), - ("generated_files", "extra"), - ("generated_files", "wrong-type"), - ("bootstrap_trees", "missing"), - ("bootstrap_trees", "extra"), - ("bootstrap_trees", "wrong-type"), - ], -) -def test_baseline_attestation_rejects_inexact_generated_identities( - tmp_path: Path, - section: str, - operation: str, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - generated_identity = body["generated_identity"] - assert isinstance(generated_identity, dict) - identities = generated_identity[section] - assert isinstance(identities, dict) - first_key = next(iter(identities)) - if operation == "missing": - identities.pop(first_key) - elif operation == "extra": - identities["unexpected"] = copy.deepcopy(identities[first_key]) - else: - identities[first_key] = [] - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - with pytest.raises(bundle.BundleError, match="attestation is invalid"): - bundle._baseline_attestation_inventory(root) - - -@pytest.mark.parametrize( - ("section", "field", "value"), - [ - ("generated_files", "relative_path", "wrong/path"), - ("generated_files", "size_bytes", 0), - ("generated_files", "sha256", "0" * 64), - ("bootstrap_trees", "algorithm", "wrong-algorithm"), - ("bootstrap_trees", "relative_path", "wrong/path"), - ("bootstrap_trees", "sha256", "not-a-sha256"), - ("bootstrap_trees", "file_count", 0), - ("bootstrap_trees", "size_bytes", 0), - ], -) -def test_baseline_attestation_rejects_invalid_identity_fields( - tmp_path: Path, - section: str, - field: str, - value: object, -) -> None: - root = tmp_path / "bundle" - root.mkdir() - payload = _baseline_attestation() - body = copy.deepcopy(payload) - body.pop("content_identity") - identities = body["generated_identity"][section] - first_key = next(iter(identities)) - identities[first_key][field] = value - _write( - root / "frozen-baseline-attestation.json", - bundle._attach_content_identity(body), - ) - with pytest.raises(bundle.BundleError, match="attestation is invalid"): - bundle._baseline_attestation_inventory(root) - - -def test_file_identity_rejects_symlink(tmp_path: Path) -> None: - target = tmp_path / "target.whl" - target.write_bytes(b"wheel") - link = tmp_path / "link.whl" - link.symlink_to(target) - with pytest.raises(bundle.BundleError, match="non-symlink"): - bundle._file_identity(link) - - -def test_checked_manifest_rejects_duplicate_and_nonfinite_json( - tmp_path: Path, -) -> None: - duplicate = tmp_path / "duplicate.json" - duplicate.write_text('{"kind":"a","kind":"b"}', encoding="utf-8") - with pytest.raises(bundle.BundleError, match="duplicate JSON key"): - bundle._checked_manifest(duplicate) - nonfinite = tmp_path / "nonfinite.json" - nonfinite.write_text('{"value":NaN}', encoding="utf-8") - with pytest.raises(bundle.BundleError, match="non-finite"): - bundle._checked_manifest(nonfinite) - - -def test_wheel_inventory_rejects_untracked_extra_file(tmp_path: Path) -> None: - root = tmp_path / "bundle" - for lane in ("baseline", "current"): - directory = root / "wheels" / lane - directory.mkdir(parents=True) - (directory / f"{lane}.whl").write_bytes(lane.encode()) - (root / "wheels" / "current" / "unexpected.txt").write_text( - "unexpected\n", - encoding="utf-8", - ) - with pytest.raises(bundle.BundleError, match="exactly one file"): - bundle._wheel_inventory(root) - - -def test_freeze_baseline_rejects_dirty_source( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - source = tmp_path / "baseline" - source.mkdir() - monkeypatch.setattr(bundle, "FROZEN_SOURCE_ROOT", source.resolve()) - monkeypatch.setattr( - bundle, - "FROZEN_CARGO_CONFIG_SHA256", - hashlib.sha256(bundle.frozen_cargo_config_bytes()).hexdigest(), - ) - - def git_output(_root: Path, *arguments: str) -> str: - if arguments[:2] == ("rev-parse", "--verify"): - return matrix.FROZEN_BASELINE_SOURCE_REVISION + "\n" - if arguments[:1] == ("status",): - return " M src/pyamplicol/runtime.py\n" - return "" - - monkeypatch.setattr(bundle, "_git_output", git_output) - with pytest.raises(bundle.BundleError, match="source changes"): - bundle.freeze_baseline(source) - - -def test_materialize_runtime_reconstructs_both_lanes_without_network( - monkeypatch: pytest.MonkeyPatch, - tmp_path: Path, -) -> None: - checkout = tmp_path / "logical-checkout" - checkout.mkdir() - monkeypatch.setattr(bundle, "ROOT", checkout) - bundle_root = tmp_path / "bundle" - dependencies = bundle_root / "dependency-site" - dependencies.mkdir(parents=True) - (dependencies / "dependency.py").write_text("VALUE = 1\n", encoding="utf-8") - for lane in ("baseline", "current"): - wheel = bundle_root / "wheels" / lane / f"{lane}.whl" - wheel.parent.mkdir(parents=True) - wheel.write_bytes(lane.encode()) - runtime_root = tmp_path / "runtime" - - class FakeBuilder: - def __init__(self, **_kwargs: Any) -> None: - pass - - def create(self, path: Path) -> None: - (path / "bin").mkdir(parents=True) - (path / "bin" / "python").write_bytes(b"python") - - def fake_purelib(python: Path) -> Path: - site = python.parents[1] / "site-packages" - site.mkdir() - return site - - monkeypatch.setattr(bundle.venv, "EnvBuilder", FakeBuilder) - monkeypatch.setattr(bundle, "_venv_purelib", fake_purelib) - monkeypatch.setattr( - bundle, - "_stable_dependency_site", - lambda _path: {"sha256": "a" * 64}, - ) - monkeypatch.setattr( - bundle, - "_installation", - lambda python: {"python": str(python), "passes": True}, - ) - monkeypatch.setattr( - bundle.subprocess, - "run", - lambda *_args, **_kwargs: SimpleNamespace( - returncode=0, - stdout="", - stderr="", - ), - ) - result = bundle.materialize_runtime(bundle_root, runtime_root) - assert result["passes"] is True - assert set(result["lanes"]) == {"baseline", "current"} - for lane in ("baseline", "current"): - site = runtime_root / lane / "site-packages" - assert (site / "dependency.py").read_text(encoding="utf-8") == "VALUE = 1\n" - - -def test_materialize_runtime_rejects_nonempty_destination( - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, -) -> None: - checkout = tmp_path / "logical-checkout" - checkout.mkdir() - monkeypatch.setattr(bundle, "ROOT", checkout) - bundle_root = tmp_path / "bundle" - dependencies = bundle_root / "dependency-site" - dependencies.mkdir(parents=True) - for lane in ("baseline", "current"): - wheel = bundle_root / "wheels" / lane / f"{lane}.whl" - wheel.parent.mkdir(parents=True) - wheel.write_bytes(lane.encode()) - runtime_root = tmp_path / "runtime" - runtime_root.mkdir() - (runtime_root / "stale").write_text("stale\n", encoding="utf-8") - with pytest.raises(bundle.BundleError, match="must be empty"): - bundle.materialize_runtime(bundle_root, runtime_root) diff --git a/pyamplicol/tests/unit/test_x86_portable_performance_acceptance.py b/pyamplicol/tests/unit/test_x86_portable_performance_acceptance.py deleted file mode 100644 index 01e70a8fa2..0000000000 --- a/pyamplicol/tests/unit/test_x86_portable_performance_acceptance.py +++ /dev/null @@ -1,430 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import json -import statistics -from pathlib import Path - -import pytest - -from tools.developer import arena_native_x86_acceptance as native -from tools.developer import compiled_mode_matrix as matrix -from tools.developer import compiled_mode_matrix_x86 as matrix_x86 -from tools.developer import x86_portable_performance_acceptance as portable -from tools.developer import x86_qq_recurrence_acceptance as qq - -REVISION = "a" * 40 -WORKFLOW_RUN_ID = "987654321" -NATIVE_INPUTS = "b" * 64 -RUNTIME_BUNDLE = "c" * 64 -NATIVE_MODULE = "d" * 64 - - -def _write(path: Path, payload: object) -> Path: - path.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - return path - - -def _native() -> dict[str, object]: - evidence = { - name: {"semantic_validation": {"passes": True}} - for name in ( - "runtime_preflight", - "compiled_all_jit", - "four_quark", - "eager_compiled_color", - ) - } - return native._attach_content_identity( - { - "kind": native.ACCEPTANCE_KIND, - "schema_version": native.SCHEMA_VERSION, - "status": "ok", - "passes": True, - "request": { - "expected_revision": REVISION, - "expected_target": native.EXPECTED_TARGET, - "point_count": native.EXPECTED_POINT_COUNT, - }, - "source_identity": { - "all_match": True, - "audit": {"revision": REVISION, "dirty": False}, - }, - "runtime_identity": { - "all_match": True, - "audit": { - "active_build_info": { - "payload": { - "source_revision": REVISION, - "native_build_inputs_sha256": NATIVE_INPUTS, - "publishable": False, - } - }, - "native_extension": { - "target": native.EXPECTED_TARGET, - "build_inputs_sha256": NATIVE_INPUTS, - "sha256": NATIVE_MODULE, - }, - }, - }, - "evidence": evidence, - "validation": { - "exact_source_revision": True, - "source_clean_preflight_and_postflight": True, - "source_only_python_runtime": True, - "native_linux_x86_64_target": True, - }, - } - ) - - -def _matrix() -> dict[str, object]: - passing_gate = {"passes": True} - return matrix_x86._attach_content_identity( - { - "kind": matrix_x86.AGGREGATE_KIND, - "schema_version": matrix_x86.SCHEMA_VERSION, - "matrix_contract": matrix.MATRIX_CONTRACT, - "workflow_run_id": WORKFLOW_RUN_ID, - "runtime_bundle_sha256": RUNTIME_BUNDLE, - "expected_current_source_revision": REVISION, - "expected_builds": { - "current": { - "source_revision": REVISION, - "native_build_inputs_sha256": NATIVE_INPUTS, - "native_module_sha256": NATIVE_MODULE, - } - }, - "shard_gate": {"errors": [], "passes": True}, - "matrix_audit": { - "complete": True, - "passes": True, - "coverage": { - "expected": 168, - "observed": 168, - "missing": [], - "unexpected": [], - "passes": True, - }, - "cell_gate": dict(passing_gate), - "identity_gate": dict(passing_gate), - "gain_gate": { - "required_relative_gain": 0.1, - "passes": True, - }, - "generation_gate": { - "maximum_geometric_mean": 1.05, - "geometric_mean_current_over_baseline": 1.01, - "passes": True, - }, - }, - "complete": True, - "passes": True, - } - ) - - -def _qq() -> dict[str, object]: - captures = {} - for role in qq.CAPTURE_CONTRACTS: - cells = [] - for batch_size in qq.PERFORMANCE_BATCH_SIZES: - recurrence = [0.001 for _ in range(7)] - ratios = [1.0 + index * 0.01 for index in range(7)] - compiled = [ - denominator * ratio - for denominator, ratio in zip( - recurrence, - ratios, - strict=True, - ) - ] - median = statistics.median(ratios) - raw_mad = statistics.median( - abs(value - median) for value in ratios - ) - cells.append( - { - "batch_size": batch_size, - "pairing": "same-interleaved-schedule-round-v1", - "sample_count": 7, - "compiled_wall_seconds_per_point_by_round": compiled, - "recurrence_wall_seconds_per_point_by_round": recurrence, - "compiled_over_recurrence_ratios_by_round": ratios, - "ratio_statistics": { - "contract": "median-and-raw-mad-v1", - "median": median, - "raw_mad": raw_mad, - "upper_three_raw_mad": median + 3.0 * raw_mad, - }, - "ceiling": 1.15, - "passes": True, - } - ) - contract = qq.CAPTURE_CONTRACTS[role] - captures[role] = { - "source_revision": REVISION, - "runtime_provenance_sha256": "e" * 64, - "model": {"kind": contract["model"]}, - "layout": contract["layout"], - "workload": contract["workload"], - "numerical_validation": { - "contract": "recomputed-recurrence-z6g-pairwise-and-resolved-v1", - "passes": True, - }, - "performance_cells": cells, - "passes": True, - } - return qq._attach_content_identity( - { - "kind": qq.RESULT_KIND, - "schema_version": qq.SCHEMA_VERSION, - "workflow_run_id": WORKFLOW_RUN_ID, - "target": native.EXPECTED_TARGET, - "expected_current_revision": REVISION, - "runtime_bundle": {"content_sha256": RUNTIME_BUNDLE}, - "policy": { - "required_capture_roles": list(qq.CAPTURE_CONTRACTS), - "required_modes": list(qq.REQUIRED_MODES), - "required_batch_sizes": list(qq.REQUIRED_BATCH_SIZES), - "performance_batch_sizes": list(qq.PERFORMANCE_BATCH_SIZES), - "minimum_target_runtime_seconds_per_worker": 5.0, - "subprocess_samples_per_cell": 7, - "native_wall_blocks_per_worker": 7, - "warmup_runs": 2, - "numerical_validation_samples": 10, - "diagnostic_shortcuts_allowed": False, - "compiled_over_recurrence_ratio_ceiling": 1.15, - "ratio_gate": ( - "median-plus-three-raw-mad-at-or-below-ceiling-v1" - ), - }, - "captures": captures, - "performance_cell_count": 8, - "passes": True, - } - ) - - -@pytest.fixture -def inputs(tmp_path: Path) -> tuple[Path, Path, Path]: - return ( - _write(tmp_path / "native.json", _native()), - _write(tmp_path / "matrix.json", _matrix()), - _write(tmp_path / "qq.json", _qq()), - ) - - -def _audit(inputs: tuple[Path, Path, Path]) -> dict[str, object]: - native_path, matrix_path, qq_path = inputs - return portable.audit( - native_acceptance=native_path, - matrix_acceptance=matrix_path, - qq_acceptance=qq_path, - workflow_run_id=WORKFLOW_RUN_ID, - expected_revision=REVISION, - ) - - -def test_combines_exact_content_addressed_inputs_portably( - inputs: tuple[Path, Path, Path], -) -> None: - result = _audit(inputs) - assert result["passes"] is True - assert result["bindings"] == { - "same_source_revision": True, - "same_native_build_inputs": True, - "same_native_module": True, - "same_performance_runtime_bundle": True, - } - assert str(inputs[0].parent) not in json.dumps(result) - identity = result["content_identity"] - body = dict(result) - body.pop("content_identity") - assert identity["sha256"] == portable._canonical_sha256(body) - - -def test_rejects_different_native_build_inputs( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _matrix() - body = dict(payload) - body.pop("content_identity") - body["expected_builds"]["current"]["native_build_inputs_sha256"] = "0" * 64 - _write(matrix_path, matrix_x86._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="different native build inputs", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_missing_native_identity_digests( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _native() - body = dict(payload) - body.pop("content_identity") - runtime = body["runtime_identity"]["audit"] - runtime["active_build_info"]["payload"].pop("native_build_inputs_sha256") - runtime["native_extension"].pop("build_inputs_sha256") - runtime["native_extension"].pop("sha256") - _write(native_path, native._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="identity digests are invalid", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_missing_matrix_identity_digests( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _matrix() - body = dict(payload) - body.pop("content_identity") - current = body["expected_builds"]["current"] - current.pop("native_build_inputs_sha256") - current.pop("native_module_sha256") - body.pop("runtime_bundle_sha256") - _write(matrix_path, matrix_x86._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="matrix current build identity drifted", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_non_lowercase_identity_digest( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _native() - body = dict(payload) - body.pop("content_identity") - runtime = body["runtime_identity"]["audit"] - runtime["native_extension"]["sha256"] = "A" * 64 - _write(native_path, native._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="identity digests are invalid", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_different_performance_runtime_bundles( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _qq() - body = dict(payload) - body.pop("content_identity") - body["runtime_bundle"]["content_sha256"] = "0" * 64 - _write(qq_path, qq._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="different runtime bundles", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_missing_qq_runtime_bundle_digest( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _qq() - body = dict(payload) - body.pop("content_identity") - body["runtime_bundle"].pop("content_sha256") - _write(qq_path, qq._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="runtime bundle digest is absent", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_duplicate_qq_batch_and_missing_1024( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _qq() - body = dict(payload) - body.pop("content_identity") - cells = body["captures"]["builtin-topology"]["performance_cells"] - cells[1] = dict(cells[0]) - _write(qq_path, qq._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="batch coverage is incomplete", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_malformed_qq_runtime_bundle( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _qq() - body = dict(payload) - body.pop("content_identity") - body["runtime_bundle"] = [] - _write(qq_path, qq._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="runtime bundle identity is absent", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_different_native_module( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _matrix() - body = dict(payload) - body.pop("content_identity") - body["expected_builds"]["current"]["native_module_sha256"] = "0" * 64 - _write(matrix_path, matrix_x86._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="different native modules", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_failed_or_incomplete_matrix_gate( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = _matrix() - body = dict(payload) - body.pop("content_identity") - body["matrix_audit"]["coverage"]["observed"] = 167 - _write(matrix_path, matrix_x86._attach_content_identity(body)) - with pytest.raises( - portable.PortableAcceptanceError, - match="matrix gates are incomplete", - ): - _audit((native_path, matrix_path, qq_path)) - - -def test_rejects_content_tampering( - inputs: tuple[Path, Path, Path], -) -> None: - native_path, matrix_path, qq_path = inputs - payload = json.loads(qq_path.read_text(encoding="utf-8")) - payload["performance_cell_count"] = 7 - _write(qq_path, payload) - with pytest.raises( - portable.PortableAcceptanceError, - match="content identity is invalid", - ): - _audit((native_path, matrix_path, qq_path)) diff --git a/pyamplicol/tests/unit/test_x86_qq_recurrence_acceptance.py b/pyamplicol/tests/unit/test_x86_qq_recurrence_acceptance.py deleted file mode 100644 index af156c161a..0000000000 --- a/pyamplicol/tests/unit/test_x86_qq_recurrence_acceptance.py +++ /dev/null @@ -1,478 +0,0 @@ -# SPDX-License-Identifier: 0BSD - -from __future__ import annotations - -import copy -import json -import statistics -from pathlib import Path -from typing import Any - -import pytest - -from tools.developer import x86_performance_runtime_bundle as bundle_tool -from tools.developer import x86_qq_recurrence_acceptance as acceptance - -REVISION = "a" * 40 -WORKFLOW_RUN_ID = "123456789" -BUILD_INFO_SHA256 = "b" * 64 -NATIVE_SHA256 = "c" * 64 -NATIVE_INPUTS_SHA256 = "d" * 64 -PREPARED_SHA256 = "e" * 64 - - -def _write(path: Path, value: object) -> Path: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text( - json.dumps(value, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - return path - - -def _current_installation() -> dict[str, object]: - return { - "package_version": "0.1.0.dev0+candidate.test", - "build_info": { - "schema_version": 1, - "version": "0.1.0.dev0+candidate.test", - "candidate_fingerprint": "0123456789ab", - "source_revision": REVISION, - "source_checkout": "/workspace/source", - "native_build_inputs_sha256": NATIVE_INPUTS_SHA256, - "publishable": False, - }, - "build_info_sha256": BUILD_INFO_SHA256, - "distribution_content": { - "algorithm": "sha256-relative-path-size-content-v1", - "sha256": "f" * 64, - "file_count": 12, - "size_bytes": 3456, - }, - "native_module": { - "relative_path": "pyamplicol/_rusticol.abi3.so", - "sha256": NATIVE_SHA256, - "size_bytes": 2345, - }, - } - - -def _bundle() -> dict[str, object]: - return bundle_tool._attach_content_identity( - { - "kind": bundle_tool.BUNDLE_KIND, - "schema_version": bundle_tool.SCHEMA_VERSION, - "target": "x86_64-unknown-linux-gnu", - "workflow_run_id": WORKFLOW_RUN_ID, - "expected_current_revision": REVISION, - "installations": { - "baseline": {"test": True}, - "current": _current_installation(), - }, - "dependency_site": {"test": True}, - "wheels": {"test": True}, - "prepared_models": { - "ufo-sm": { - "relative_path": ( - "prepared-models/ufo-sm-jit-o2.pyamplicol-model" - ), - "sha256": PREPARED_SHA256, - "size_bytes": 4567, - } - }, - "frozen_baseline": {"test": True}, - "passes": True, - } - ) - - -def _profile(batch_size: int, *, mode: str, slow: bool = False) -> dict[str, object]: - recurrence = [0.001 * (1.0 + index * 0.01) for index in range(7)] - ratios = ( - [1.20 + index * 0.01 for index in range(7)] - if slow - else [1.00 + index * 0.01 for index in range(7)] - ) - values = ( - recurrence - if mode == "recurrence" - else [wall * ratio for wall, ratio in zip(recurrence, ratios, strict=True)] - ) - median = statistics.median(values) - mad = statistics.median(abs(value - median) for value in values) - return { - "batch_size": batch_size, - "interrupted": False, - "sample_count": 7, - "subprocess_sample_count": 7, - "statistics_contract": "subprocess-median-and-raw-mad-v1", - "wall_seconds_per_point": median, - "wall_seconds_per_point_median": median, - "wall_seconds_per_point_mad": mad, - "subprocess_samples": [ - { - "round": round_index, - "wall_seconds_per_point": value, - } - for round_index, value in enumerate(values) - ], - } - - -def _models(role: str) -> dict[str, object]: - if role.startswith("builtin-"): - packaged = { - "kind": "packaged-prepared-model", - "resource_id": "built-in-sm-jit-o2", - "size_bytes": 1234, - "sha256": "1" * 64, - "compile_excluded_from_generation": True, - } - return { - "compiled": { - "kind": "built-in-sm-source", - "resource_id": None, - "source_revision": REVISION, - "compile_excluded_from_generation": False, - }, - "eager": dict(packaged), - "recurrence": dict(packaged), - } - explicit = { - "kind": "explicit-prepared-model", - "resource_id": None, - "file": { - "path": "/runtime/ufo.pyamplicol-model", - "resolved_path": "/runtime/ufo.pyamplicol-model", - "sha256": PREPARED_SHA256, - "size_bytes": 4567, - }, - "compile_excluded_from_generation": True, - } - return {mode: copy.deepcopy(explicit) for mode in acceptance.REQUIRED_MODES} - - -def _runtime() -> dict[str, object]: - current = _current_installation() - return { - "active_build_info": { - "path": "/runtime/pyamplicol/_build_info.json", - "resolved_path": "/runtime/pyamplicol/_build_info.json", - "sha256": BUILD_INFO_SHA256, - "size_bytes": 400, - "payload": copy.deepcopy(current["build_info"]), - }, - "installed_distribution": { - "package_version": current["package_version"], - "build_info_files": [ - { - "relative_path": "pyamplicol/_build_info.json", - "sha256": BUILD_INFO_SHA256, - "size_bytes": 400, - } - ], - "native_modules": [copy.deepcopy(current["native_module"])], - "distribution_content": copy.deepcopy(current["distribution_content"]), - }, - "native_extension": { - "path": "/runtime/pyamplicol/_rusticol.abi3.so", - "resolved_path": "/runtime/pyamplicol/_rusticol.abi3.so", - "sha256": NATIVE_SHA256, - "size_bytes": 2345, - "build_inputs_sha256": NATIVE_INPUTS_SHA256, - "package_version": "0.1.0-dev.0+candidate.test", - }, - "interpreter": {"test": True}, - "dependencies": {"test": True}, - } - - -def _capture(role: str, *, slow: bool = False) -> dict[str, Any]: - contract = acceptance.CAPTURE_CONTRACTS[role] - return { - "kind": "pyamplicol-recurrence-z6g-benchmark", - "schema_version": acceptance.benchmark.RESULT_SCHEMA, - "complete": True, - "passes": True, - "capture_acceptance": {"test": "capture"}, - "milestone0_acceptance": {"test": "milestone"}, - "source": { - "checkout": "/workspace/source", - "revision": REVISION, - "dirty": False, - "untracked_files_checked": True, - }, - "runtime_provenance": _runtime(), - "provenance": { - "host": { - "system": "Linux", - "machine": "x86_64", - } - }, - "process": "u u~ > Z g g g g g g", - "process_name": "uubar_Z_6g", - "workload": contract["workload"], - "configuration": { - "batch_sizes": [1, 128, 1024], - "target_runtime_seconds": 5.0, - "minimum_samples": 7, - "subprocess_samples": 7, - "warmup_runs": 2, - "generation_timeout_seconds": 900.0, - "profile_timeout_seconds": 300.0, - "color_flow_request": contract["color_flow"], - "helicity_request": contract["helicity"], - "lc_flow_layout": contract["layout"], - "gluon_count": 6, - "validation_samples": 10, - "point_tile_size": 1024, - "jit_optimization_level": 3, - "generation_only": False, - "allow_diagnostic_incomplete_success": False, - "modes": ["compiled", "eager", "recurrence"], - "prepared_model_path": ( - None - if role.startswith("builtin-") - else "/runtime/ufo.pyamplicol-model" - ), - "model_identities": _models(role), - "specialize_flow_at_generation": False, - "external_watchdog_required_for_long_runs": True, - }, - "profile_schedule": {"test": True}, - "profiles": { - "compiled": { - "profiles": [ - _profile(batch_size, mode="compiled", slow=slow) - for batch_size in (1, 128, 1024) - ] - }, - "eager": {"profiles": []}, - "recurrence": { - "profiles": [ - _profile(batch_size, mode="recurrence") - for batch_size in (1, 128, 1024) - ] - }, - }, - "validation_summary": {"test": "validation"}, - } - - -@pytest.fixture -def evidence(tmp_path: Path) -> tuple[Path, dict[str, Path]]: - manifest = _write(tmp_path / "runtime-bundle.json", _bundle()) - captures = { - role: _write(tmp_path / f"{role}.json", _capture(role)) - for role in acceptance.CAPTURE_CONTRACTS - } - return manifest, captures - - -def _audit( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, -) -> dict[str, object]: - manifest, captures = evidence - monkeypatch.setattr(acceptance, "_recompute_harness_contracts", lambda _p: None) - return acceptance.audit( - capture_paths=captures, - runtime_bundle_manifest=manifest, - workflow_run_id=WORKFLOW_RUN_ID, - expected_current_revision=REVISION, - ) - - -def test_accepts_exact_four_capture_contract_and_is_portable( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, -) -> None: - result = _audit(evidence, monkeypatch) - assert result["passes"] is True - assert result["performance_cell_count"] == 8 - assert set(result["captures"]) == set(acceptance.CAPTURE_CONTRACTS) - assert str(evidence[0].parent) not in json.dumps(result) - identity = result["content_identity"] - body = dict(result) - body.pop("content_identity") - assert identity["sha256"] == acceptance._canonical_sha256(body) - - -def test_slow_compiled_capture_fails_performance_gate( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, -) -> None: - manifest, captures = evidence - _write(captures["ufo-union"], _capture("ufo-union", slow=True)) - result = _audit((manifest, captures), monkeypatch) - assert result["passes"] is False - failed = result["captures"]["ufo-union"] - assert all(cell["passes"] is False for cell in failed["performance_cells"]) - - -def test_zero_paired_ratio_uncertainty_is_accepted_when_below_ceiling( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, -) -> None: - manifest, captures = evidence - payload = _capture("builtin-topology") - for batch_size in (128, 1024): - recurrence = acceptance._profile_for_batch( - payload, mode="recurrence", batch_size=batch_size - ) - compiled = acceptance._profile_for_batch( - payload, mode="compiled", batch_size=batch_size - ) - compiled["subprocess_samples"] = copy.deepcopy( - recurrence["subprocess_samples"] - ) - compiled["wall_seconds_per_point"] = recurrence["wall_seconds_per_point"] - compiled["wall_seconds_per_point_median"] = recurrence[ - "wall_seconds_per_point_median" - ] - compiled["wall_seconds_per_point_mad"] = recurrence[ - "wall_seconds_per_point_mad" - ] - _write(captures["builtin-topology"], payload) - result = _audit((manifest, captures), monkeypatch) - cells = result["captures"]["builtin-topology"]["performance_cells"] - assert all(cell["ratio_statistics"]["raw_mad"] == 0.0 for cell in cells) - assert all(cell["ratio_statistics"]["median"] == 1.0 for cell in cells) - assert all( - cell["ratio_statistics"]["upper_three_raw_mad"] == 1.0 for cell in cells - ) - assert all(cell["passes"] is True for cell in cells) - - -@pytest.mark.parametrize( - ("mutation", "message"), - [ - ( - lambda payload: payload["configuration"].__setitem__( - "target_runtime_seconds", 4.999 - ), - "authoritative benchmark policy", - ), - ( - lambda payload: payload["configuration"].__setitem__( - "allow_diagnostic_incomplete_success", True - ), - "authoritative benchmark policy", - ), - ( - lambda payload: payload["configuration"].__setitem__( - "specialize_flow_at_generation", True - ), - "authoritative benchmark policy", - ), - ( - lambda payload: payload["configuration"].__setitem__( - "helicity_request", "1" - ), - "authoritative benchmark policy", - ), - ( - lambda payload: payload["runtime_provenance"][ - "native_extension" - ].__setitem__("sha256", "0" * 64), - "runtime does not match", - ), - ( - lambda payload: payload.__setitem__("provenance", []), - "not measured from exact clean x86 source", - ), - ], -) -def test_rejects_policy_and_runtime_shortcuts( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, - mutation: Any, - message: str, -) -> None: - manifest, captures = evidence - payload = _capture("builtin-union") - mutation(payload) - _write(captures["builtin-union"], payload) - with pytest.raises(acceptance.AcceptanceError, match=message): - _audit((manifest, captures), monkeypatch) - - -def test_rejects_ufo_model_not_bound_to_bundle( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, -) -> None: - manifest, captures = evidence - payload = _capture("ufo-topology") - payload["configuration"]["model_identities"]["compiled"]["file"]["sha256"] = ( - "0" * 64 - ) - _write(captures["ufo-topology"], payload) - with pytest.raises(acceptance.AcceptanceError, match="UFO model identity"): - _audit((manifest, captures), monkeypatch) - - -def test_rejects_missing_or_duplicate_paired_round() -> None: - payload = _capture("builtin-topology") - profile = acceptance._profile_for_batch( - payload, - mode="compiled", - batch_size=128, - ) - profile["subprocess_samples"][6]["round"] = 5 - with pytest.raises(acceptance.AcceptanceError, match="invalid paired samples"): - acceptance._paired_cell_evidence( - payload, - batch_size=128, - ceiling=1.15, - ) - - -def test_runtime_bundle_content_tampering_is_rejected( - evidence: tuple[Path, dict[str, Path]], - monkeypatch: pytest.MonkeyPatch, -) -> None: - manifest, captures = evidence - payload = json.loads(manifest.read_text(encoding="utf-8")) - payload["prepared_models"]["ufo-sm"]["size_bytes"] += 1 - _write(manifest, payload) - with pytest.raises(acceptance.AcceptanceError, match="content identity"): - _audit((manifest, captures), monkeypatch) - - -def test_recompute_uses_authoritative_harness_contracts( - monkeypatch: pytest.MonkeyPatch, -) -> None: - validation = {"passes": True} - capture = { - "complete": True, - "evidence_complete": True, - "passes": True, - "authoritative_eligible": True, - "authoritative_ineligibility_reasons": [], - "generation_specialized_axes_by_mode": {}, - "incomplete_physical_axes": [], - } - milestone = {"accepted": False} - payload = _capture("builtin-topology") - payload["validation_summary"] = validation - payload["capture_acceptance"] = capture - payload["milestone0_acceptance"] = milestone - monkeypatch.setattr( - acceptance.benchmark, - "_pairwise_profile_validation", - lambda _profiles: validation, - ) - monkeypatch.setattr( - acceptance.benchmark, - "_capture_acceptance", - lambda *_args, **_kwargs: capture, - ) - monkeypatch.setattr( - acceptance.benchmark, - "_milestone0_acceptance_manifest", - lambda *_args, **_kwargs: milestone, - ) - acceptance._recompute_harness_contracts(payload) - payload["validation_summary"] = {"passes": False} - with pytest.raises(acceptance.AcceptanceError, match="not reproducible"): - acceptance._recompute_harness_contracts(payload) diff --git a/pyamplicol/tools/developer/amplicol_z6g_m0_capture.py b/pyamplicol/tools/developer/amplicol_z6g_m0_capture.py deleted file mode 100755 index 4c0c7c35ac..0000000000 --- a/pyamplicol/tools/developer/amplicol_z6g_m0_capture.py +++ /dev/null @@ -1,1822 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Capture strict original-AmpliCol evidence for the qq_Z6g M0 gate. - -The public ``capture`` command validates the four pyAmpliCol inputs from an -M0 request template, builds the pinned original-AmpliCol probes, and records -seven paired selected/all-flow subprocess rounds. The private ``_sample`` -command is the content-addressed executable retained in every timing record; -it wraps ``amplicol_library_benchmark`` or ``amplicol_color_probe`` and emits -one strict ``amplicol-m0-probe-result`` JSON object on stdout. - -This program intentionally has no synthetic or diagnostic-success mode. -""" - -from __future__ import annotations - -import argparse -import contextlib -import datetime as dt -import hashlib -import importlib.util -import json -import math -import os -import platform -import shlex -import shutil -import statistics -import subprocess -import sys -import tempfile -from collections.abc import Iterator, Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from types import ModuleType -from typing import Any, NoReturn - -ROOT = Path(__file__).resolve().parents[2] -SCRIPT = Path(__file__).resolve() -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.developer import legacy_amplicol # noqa: E402 - -PROCESS_EXPRESSION = "u u~ > Z g g g g g g" -NORMALIZED_PROCESS = "u u~ > z g g g g g g" -AMPLICOL_EXTERNAL_LEG_PERMUTATION = (0, 1, 3, 4, 5, 6, 7, 8, 2) -SELECTED_ROLE = "selected-flow-helicity-sum" -UNION_ROLE = "all-flow-single-helicity" -ROLES = (SELECTED_ROLE, UNION_ROLE) -SELECTED_WORKLOAD = "single-runtime-selected-flow/helicity-sum" -UNION_WORKLOAD = "all-flows/runtime-selected-single-helicity" -MIN_SAMPLES = 7 -RTOL = 1.0e-12 -ATOL = 1.0e-15 -DEFAULT_TARGET_SECONDS = 5.0 -DEFAULT_WARMUP_POINTS = 100 -DEFAULT_MINIMUM_POINTS = 100 -DEFAULT_MAXIMUM_POINTS = 100_000 -_SAMPLE_RUNTIME_RELATIVE_FILES = ( - Path("tools/developer/amplicol_z6g_m0_capture.py"), - Path("tools/developer/legacy_amplicol.py"), - Path("tools/developer/legacy_oracle/__init__.py"), - Path("tools/developer/legacy_oracle/checkout.py"), - Path("tools/developer/legacy_oracle/evidence.py"), - Path("tools/developer/legacy_oracle/model.py"), - Path("tools/developer/legacy_oracle/probe.py"), - Path("tools/developer/legacy_oracle/processes.py"), - Path("dependencies/contributor-lock.toml"), -) - -_M0_REQUEST_KEYS = { - "kind", - "schema_version", - "captures", - "amplicol_evidence", - "expected", -} -_PROBE_RESULT_KEYS = { - "kind", - "schema_version", - "role", - "sample_index", - "evaluated_point_count", - "elapsed_seconds", - "seconds_per_point", - "selected_totals", - "resolved_sums", -} - - -class CaptureError(RuntimeError): - """The authoritative original-AmpliCol capture could not be completed.""" - - -@dataclass(frozen=True, slots=True) -class CaptureContract: - """Cross-validated physical and provenance contract from four M0 captures.""" - - expected: dict[str, Any] - input_files: tuple[dict[str, Any], ...] - host: dict[str, Any] - fixture: dict[str, Any] - color_axis: dict[str, Any] - helicity_axis: dict[str, Any] - color_flow_request: str - helicity_request: str - selected_values: tuple[complex, ...] - union_values: tuple[complex, ...] - - -@dataclass(frozen=True, slots=True) -class ProbeContext: - """Immutable original-AmpliCol row and snapshotted execution inputs.""" - - runtime: Path - worker_executable: Path - process_file: Path - selected_binary: Path - union_binary: Path - linked_files: tuple[Path, ...] - group: int - integral: int - source_pdgs: tuple[int, ...] - generated_pdgs: tuple[int, ...] - generated_color_order: tuple[int, ...] - permutation: tuple[int, ...] - - -@dataclass(frozen=True, slots=True) -class SourceEvidence: - """Pinned original-AmpliCol source/compiler identity.""" - - source: dict[str, Any] - source_files: tuple[dict[str, Any], ...] - - -def _die(message: str) -> NoReturn: - raise CaptureError(message) - - -def _canonical_bytes(value: object) -> bytes: - return json.dumps( - value, - sort_keys=True, - separators=(",", ":"), - ensure_ascii=False, - allow_nan=False, - ).encode("utf-8") - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_bytes(value)).hexdigest() - - -def _file_sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _file_ref(path: Path) -> dict[str, Any]: - resolved = path.resolve(strict=True) - if not resolved.is_file(): - _die(f"evidence path is not a file: {resolved}") - return { - "path": str(resolved), - "size_bytes": resolved.stat().st_size, - "sha256": _file_sha256(resolved), - } - - -def _write_json(path: Path, payload: Mapping[str, Any]) -> dict[str, Any]: - path.parent.mkdir(parents=True, exist_ok=True) - raw = _canonical_bytes(payload) + b"\n" - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - temporary.write_bytes(raw) - os.replace(temporary, path) - return _file_ref(path) - - -def _content_addressed(payload: Mapping[str, Any]) -> dict[str, Any]: - result = dict(payload) - if "content_sha256" in result: - _die("content-addressing input already contains content_sha256") - result["content_sha256"] = _canonical_sha256(result) - return result - - -def _strict_json(raw: bytes, label: str) -> dict[str, Any]: - def reject_duplicate(pairs: list[tuple[str, Any]]) -> dict[str, Any]: - result: dict[str, Any] = {} - for key, value in pairs: - if key in result: - _die(f"{label} contains duplicate JSON key {key!r}") - result[key] = value - return result - - try: - value = json.loads( - raw, - object_pairs_hook=reject_duplicate, - parse_constant=lambda token: _die( - f"{label} contains non-finite JSON number {token}" - ), - ) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise CaptureError(f"{label} is not strict JSON: {error}") from error - if not isinstance(value, dict): - _die(f"{label} must be a JSON object") - return value - - -def _load_json(path: Path, label: str) -> dict[str, Any]: - try: - return _strict_json(path.read_bytes(), label) - except OSError as error: - raise CaptureError(f"cannot read {label} at {path}: {error}") from error - - -def _load_m0() -> ModuleType: - path = SCRIPT.with_name("eager_compiled_arena_m0.py") - spec = importlib.util.spec_from_file_location("_amplicol_capture_m0", path) - if spec is None or spec.loader is None: - _die(f"cannot load M0 schema validator from {path}") - module = importlib.util.module_from_spec(spec) - sys.modules[spec.name] = module - try: - spec.loader.exec_module(module) - except Exception as error: - raise CaptureError(f"cannot load M0 schema validator: {error}") from error - return module - - -def _same_complex_values( - left: Sequence[complex], - right: Sequence[complex], -) -> bool: - return len(left) == len(right) and all( - abs(lhs - rhs) <= ATOL + RTOL * abs(rhs) - for lhs, rhs in zip(left, right, strict=True) - ) - - -def _contract_from_request(path: Path) -> CaptureContract: - """Revalidate all four captures and extract their common M0 contract.""" - - m0 = _load_m0() - payload = _load_json(path, "M0 request template") - if set(payload) != _M0_REQUEST_KEYS: - _die("M0 request template has unknown or missing root keys") - if ( - payload.get("kind") != m0.REQUEST_KIND - or payload.get("schema_version") != m0.REQUEST_SCHEMA - ): - _die("M0 request template has the wrong kind or schema") - amplicol = payload.get("amplicol_evidence") - if not isinstance(amplicol, Mapping) or set(amplicol) != set(ROLES): - _die("request template must reserve exactly both AmpliCol evidence roles") - expected = m0._validate_expected(payload.get("expected")) - if expected["amplicol_source_revision"] != legacy_amplicol.expected_revision(): - _die( - "request AmpliCol revision differs from the contributor-lock pin: " - f"{expected['amplicol_source_revision']} != " - f"{legacy_amplicol.expected_revision()}" - ) - if expected["external_leg_permutation"] != list(AMPLICOL_EXTERNAL_LEG_PERMUTATION): - _die( - "request AmpliCol source-to-generated permutation must be " - f"{list(AMPLICOL_EXTERNAL_LEG_PERMUTATION)}" - ) - - captures_raw = payload.get("captures") - if not isinstance(captures_raw, Mapping) or set(captures_raw) != set(m0.MODELS): - _die("request template must reference exactly both M0 model families") - benchmark = m0._load_benchmark_module() - captures: dict[tuple[str, str], Any] = {} - input_files: list[dict[str, Any]] = [_file_ref(path)] - for model in m0.MODELS: - layouts = captures_raw[model] - if not isinstance(layouts, Mapping) or set(layouts) != set(m0.LAYOUTS): - _die(f"request captures for {model} must contain both LC layouts") - for layout in m0.LAYOUTS: - ref = m0._file_ref( - layouts[layout], - base=path.resolve().parent, - label=f"request.captures.{model}.{layout}", - ) - loaded = m0._load_json_ref(ref, f"{model}/{layout}") - input_files.append( - { - "path": str(ref.path), - "size_bytes": ref.size_bytes, - "sha256": ref.sha256, - } - ) - captures[(model, layout)] = m0._validate_capture( - loaded, - model=model, - layout=layout, - expected=expected, - benchmark=benchmark, - ) - - first = captures[("built-in-sm", "topology-replay")] - for key, current in captures.items(): - if ( - current.source_identity != first.source_identity - or current.runtime_identity != first.runtime_identity - or current.host != first.host - or current.fixture != first.fixture - or current.normalization_sha256 != first.normalization_sha256 - or current.color_axis != first.color_axis - or current.helicity_axis != first.helicity_axis - ): - _die(f"capture {key} differs from the common M0 physical contract") - for layout in m0.LAYOUTS: - builtin = captures[("built-in-sm", layout)] - ufo = captures[("ufo-sm", layout)] - if not _same_complex_values( - builtin.validation_values, - ufo.validation_values, - ): - _die(f"built-in and UFO validation values differ for {layout}") - - topology = captures[("built-in-sm", "topology-replay")] - union = captures[("built-in-sm", "all-flow-union")] - topology_payload = topology.loaded.payload - fixture_payload = topology_payload["profiles"]["compiled"]["validation"]["fixture"] - raw_file = fixture_payload["file"] - raw_path_value = raw_file.get("resolved_path", raw_file.get("path")) - if not isinstance(raw_path_value, str): - _die("topology capture has no absolute raw validation-momenta path") - fixture_path = Path(raw_path_value).resolve(strict=True) - fixture_ref = _file_ref(fixture_path) - if ( - fixture_ref["sha256"] != first.fixture["file_sha256"] - or fixture_payload.get("point_count") != first.fixture["point_count"] - or fixture_payload.get("points_sha256") != first.fixture["points_sha256"] - ): - _die("topology raw fixture identity differs from its capture") - - topology_selector = topology.selector - union_selector = union.selector - if topology_selector.get("color_flow_request") != union_selector.get( - "color_flow_request" - ) or topology_selector.get("helicity_request") != union_selector.get( - "helicity_request" - ): - _die("the two LC layouts used different runtime selector requests") - return CaptureContract( - expected=dict(expected), - input_files=tuple(input_files), - host=dict(first.host), - fixture={ - "path": fixture_path, - "file": fixture_ref, - "point_count": first.fixture["point_count"], - "points_sha256": first.fixture["points_sha256"], - }, - color_axis={ - "count": first.color_axis["count"], - "ordered_ids_sha256": first.color_axis["ordered_ids_sha256"], - }, - helicity_axis={ - "count": first.helicity_axis["count"], - "ordered_ids_sha256": first.helicity_axis["ordered_ids_sha256"], - }, - color_flow_request=str(topology_selector["color_flow_request"]), - helicity_request=str(topology_selector["helicity_request"]), - selected_values=tuple(topology.validation_values), - union_values=tuple(union.validation_values), - ) - - -def _host_identity() -> dict[str, Any]: - """Use the same host identity algorithm as the schema-6 harness.""" - - cpu_model = platform.processor().strip() - if not cpu_model and platform.system() == "Darwin": - completed = subprocess.run( - ("sysctl", "-n", "machdep.cpu.brand_string"), - check=False, - capture_output=True, - text=True, - ) - if completed.returncode == 0: - cpu_model = completed.stdout.strip() - if not cpu_model and platform.system() == "Linux": - try: - for line in Path("/proc/cpuinfo").read_text(encoding="utf-8").splitlines(): - if line.casefold().startswith(("model name", "hardware")): - cpu_model = line.partition(":")[2].strip() - break - except OSError: - pass - uname = platform.uname() - return { - "platform": platform.platform(), - "system": uname.system, - "release": uname.release, - "version": uname.version, - "machine": uname.machine, - "processor": uname.processor, - "cpu_model": cpu_model or None, - "logical_cpu_count": os.cpu_count(), - } - - -def _require_clean_revision( - repository: Path, - *, - expected_revision: str, - label: str, -) -> None: - revision = _run( - ("git", "rev-parse", "--verify", "HEAD"), - cwd=repository, - label=f"{label} revision", - ).stdout.strip() - if revision != expected_revision: - _die( - f"{label} revision differs from the request pin: " - f"{revision} != {expected_revision}" - ) - status = _run( - ("git", "status", "--porcelain=v1", "--untracked-files=all"), - cwd=repository, - label=f"{label} cleanliness", - ).stdout - if status: - _die(f"{label} has tracked or untracked pre-capture state:\n{status}") - - -def _run( - command: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - environment: Mapping[str, str] | None = None, - label: str, - log_path: Path | None = None, -) -> subprocess.CompletedProcess[str]: - rendered = [os.fspath(item) for item in command] - completed = subprocess.run( - rendered, - cwd=cwd, - env=None if environment is None else {**os.environ, **environment}, - capture_output=True, - check=False, - text=True, - ) - if log_path is not None: - log_path.parent.mkdir(parents=True, exist_ok=True) - with log_path.open("a", encoding="utf-8") as stream: - stream.write(f"$ {' '.join(rendered)}\n") - stream.write(completed.stdout) - stream.write(completed.stderr) - if not completed.stdout.endswith("\n"): - stream.write("\n") - if completed.returncode != 0: - _die( - f"{label} exited with {completed.returncode}: {' '.join(rendered)}\n" - f"stdout:\n{completed.stdout}\nstderr:\n{completed.stderr}" - ) - return completed - - -@contextlib.contextmanager -def _staged_process_file(repository: Path, process_file: Path) -> Iterator[str]: - target = repository / "processes.txt" - backup = repository / f".processes.txt.m0-backup-{os.getpid()}" - existed = target.is_file() - if backup.exists(): - _die(f"stale process-file backup exists: {backup}") - if existed: - shutil.copy2(target, backup) - shutil.copy2(process_file, target) - try: - yield target.name - finally: - if existed: - shutil.move(backup, target) - else: - target.unlink(missing_ok=True) - backup.unlink(missing_ok=True) - - -def _fixture_points( - path: Path, -) -> tuple[tuple[int, ...], tuple[tuple[tuple[float, ...], ...], ...]]: - payload = _load_json(path, "validation-momenta fixture") - if ( - payload.get("kind") != "pyamplicol-rusticol-validation-momenta" - or payload.get("schema_version") != 1 - or "points" not in payload - ): - _die("validation-momenta fixture has the wrong schema") - raw_points = payload["points"] - if not isinstance(raw_points, list) or not raw_points: - _die("validation-momenta fixture has no points") - pdgs: tuple[int, ...] | None = None - points: list[tuple[tuple[float, ...], ...]] = [] - for point_index, raw_point in enumerate(raw_points): - if not isinstance(raw_point, list) or len(raw_point) != 9: - _die(f"fixture point {point_index} does not have nine external legs") - point_pdgs: list[int] = [] - momenta: list[tuple[float, ...]] = [] - for particle in raw_point: - if not isinstance(particle, Mapping): - _die(f"fixture point {point_index} contains a non-object particle") - momentum = particle.get("momentum") - particle_pdg = particle.get("pdg") - if ( - isinstance(particle_pdg, bool) - or not isinstance(particle_pdg, int) - or not isinstance(momentum, list) - or len(momentum) != 4 - ): - _die(f"fixture point {point_index} contains an invalid particle") - converted = tuple(float(component) for component in momentum) - if not all(math.isfinite(component) for component in converted): - _die(f"fixture point {point_index} contains non-finite momentum") - point_pdgs.append(particle_pdg) - momenta.append(converted) - current_pdgs = tuple(point_pdgs) - if pdgs is None: - pdgs = current_pdgs - elif current_pdgs != pdgs: - _die("fixture external-particle order changes between points") - points.append(tuple(momenta)) - assert pdgs is not None - normalized_process = " ".join(str(payload.get("process", "")).split()).casefold() - if normalized_process != NORMALIZED_PROCESS: - _die("validation-momenta fixture is not the qq_Z6g process") - if legacy_amplicol.process_pdgs(NORMALIZED_PROCESS) != pdgs: - _die("fixture external PDGs differ from the original-AmpliCol process parser") - return pdgs, tuple(points) - - -def _write_ordered_momenta( - path: Path, - *, - source_pdgs: Sequence[int], - target_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], -) -> None: - ordered = legacy_amplicol._ordered_binary64_momenta( - source_pdgs, - target_pdgs, - momenta, - ) - path.write_text( - "\n".join( - " ".join(format(float(component), ".17g") for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - - -def _generate_process_file( - *, - repository: Path, - setup: Path, - log_path: Path, -) -> Path: - """Run the case-sensitive legacy generator with its lowercase spelling.""" - - _run( - ( - sys.executable, - repository / "process_list.py", - "--serial", - NORMALIZED_PROCESS, - ), - cwd=setup, - label="original-AmpliCol process generation", - log_path=log_path, - ) - process_file = setup / "processes.txt" - if not process_file.is_file(): - _die("original-AmpliCol process_list.py did not write processes.txt") - return process_file - - -def _copy_sample_runtime_sources(runtime: Path) -> tuple[Path, tuple[Path, ...]]: - bundle = runtime / "python-src" - copied: list[Path] = [] - for relative in _SAMPLE_RUNTIME_RELATIVE_FILES: - source = (ROOT / relative).resolve(strict=True) - target = bundle / relative - target.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(source, target) - copied.append(target.resolve()) - producer = (bundle / _SAMPLE_RUNTIME_RELATIVE_FILES[0]).resolve(strict=True) - return producer, tuple(copied) - - -def _copy_generated_library_tree( - repository: Path, - runtime: Path, -) -> tuple[Path, ...]: - source_root = repository / "Library" - if not source_root.is_dir(): - _die(f"generated original-AmpliCol Library tree is absent: {source_root}") - amplitudes = source_root / "amplitudes.bin" - if not amplitudes.is_file(): - _die(f"generated original-AmpliCol amplitudes payload is absent: {amplitudes}") - sources = tuple(sorted(path for path in source_root.rglob("*") if path.is_file())) - if not sources: - _die(f"generated original-AmpliCol Library tree is empty: {source_root}") - copied: list[Path] = [] - for source in sources: - target = runtime / "Library" / source.relative_to(source_root) - target.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(source, target) - copied.append(target.resolve()) - return tuple(copied) - - -def _copy_runtime(repository: Path, output: Path, process_file: Path) -> ProbeContext: - runtime = output / "runtime" - runtime.mkdir(parents=True) - interpreter = Path(sys.executable).resolve(strict=True) - bundled_producer, bundled_sources = _copy_sample_runtime_sources(runtime) - worker_executable = runtime / "amplicol_z6g_m0_sample" - worker_executable.write_text( - "#!/bin/sh\n" - f"exec {shlex.quote(str(interpreter))} -I -S -B " - f'{shlex.quote(str(bundled_producer))} "$@"\n', - encoding="utf-8", - ) - worker_executable.chmod(0o755) - selected_binary = runtime / "amplicol_library_benchmark" - union_binary = runtime / "amplicol_color_probe" - shutil.copy2(repository / selected_binary.name, selected_binary) - shutil.copy2(repository / union_binary.name, union_binary) - runtime_process = runtime / "processes.txt" - shutil.copy2(process_file, runtime_process) - generated_library_files = _copy_generated_library_tree(repository, runtime) - libraries: list[Path] = [] - for pattern in ("libamp*.so", "libamp*.dylib", "libamp*.a"): - for source in sorted(repository.glob(pattern)): - target = runtime / source.name - if not target.exists(): - shutil.copy2(source, target) - libraries.append(target) - if not libraries: - _die("generated selected-flow library produced no libamp library") - return ProbeContext( - runtime=runtime.resolve(), - worker_executable=worker_executable.resolve(), - process_file=runtime_process.resolve(), - selected_binary=selected_binary.resolve(), - union_binary=union_binary.resolve(), - linked_files=( - interpreter, - *bundled_sources, - selected_binary.resolve(), - union_binary.resolve(), - runtime_process.resolve(), - *generated_library_files, - *(path.resolve() for path in libraries), - ), - group=0, - integral=0, - source_pdgs=(), - generated_pdgs=(), - generated_color_order=(), - permutation=(), - ) - - -def _validated_executable_row( - *, - requested_entry: Any, - emitted_probe: Any, - source_pdgs: Sequence[int], - expected_flow_word: Sequence[int], - expected_permutation: Sequence[int], -) -> tuple[Any, tuple[int, ...]]: - requested_identity = (int(requested_entry.group), int(requested_entry.integral)) - emitted_identity = (int(emitted_probe.group), int(emitted_probe.integral)) - if emitted_identity != requested_identity: - _die( - "generated-library selected-flow probe returned row " - f"{emitted_identity}, expected {requested_identity}" - ) - emitted_pdgs = tuple(int(value) for value in emitted_probe.process_pdgs) - if sorted(emitted_pdgs) != sorted( - int(value) for value in requested_entry.process_pdgs - ): - _die( - "generated-library selected-flow PDG multiset differs from the " - "requested generated row" - ) - executable_entry = legacy_amplicol.ProcessEntry( - group=emitted_identity[0], - integral=emitted_identity[1], - process_pdgs=emitted_pdgs, - color_order=tuple(int(value) for value in emitted_probe.color_order), - ) - mapped = legacy_amplicol.source_mapped_color_order( - executable_entry, - source_pdgs=source_pdgs, - ) - colored = { - index - for index, pdg in enumerate(source_pdgs, start=1) - if abs(int(pdg)) == 21 or 1 <= abs(int(pdg)) <= 6 - } - color_word = tuple(label for label in mapped if label in colored) - if list(color_word) != list(expected_flow_word): - _die( - "selected original-AmpliCol executable row differs from the stable " - f"M0 flow word: {color_word} != {tuple(expected_flow_word)}" - ) - permutation = tuple( - legacy_amplicol._permutation(source_pdgs, executable_entry.process_pdgs) - ) - if list(permutation) != list(expected_permutation): - _die( - "executable source-to-generated external-leg permutation differs " - "from M0 request" - ) - return executable_entry, permutation - - -def _prepare_probes( - *, - repository: Path, - output: Path, - fixture_path: Path, - expected_flow_word: Sequence[int], - expected_permutation: Sequence[int], - jobs: int, -) -> ProbeContext: - """Generate one LC row, build both probes, and snapshot execution inputs.""" - - legacy_amplicol.prepare_checkout(repository) - _require_clean_revision( - repository, - expected_revision=legacy_amplicol.expected_revision(), - label="original-AmpliCol checkout", - ) - legacy_amplicol.validate_checkout(repository) - source_pdgs, points = _fixture_points(fixture_path) - setup = output / "setup" - setup.mkdir(parents=True) - log = setup / "build.log" - process_file = _generate_process_file( - repository=repository, - setup=setup, - log_path=log, - ) - entries = legacy_amplicol.parse_process_file(process_file) - entry, _matches = legacy_amplicol.select_generated_process_entry( - entries, - generated_process=NORMALIZED_PROCESS, - wanted_pdgs=source_pdgs, - ) - - momenta_directory = repository / "Utilities" / "ME_checks" - momenta_directory.mkdir(parents=True, exist_ok=True) - for candidate in entries: - target = momenta_directory / ( - f"momenta_{candidate.group}_{candidate.integral}.txt" - ) - _write_ordered_momenta( - target, - source_pdgs=source_pdgs, - target_pdgs=candidate.process_pdgs, - momenta=points[0], - ) - with _staged_process_file(repository, process_file) as process_argument: - commands: tuple[tuple[str, ...], ...] = ( - ("make", "cleanlib"), - ("make", f"-j{jobs}", "amplicol_generate"), - ( - "./amplicol_generate", - "--library=create", - f"--process={process_argument}", - "--amplicol_momenta_probe=10", - "--amplicol_probe_quiet", - "--timing=none", - ), - ("make", f"-j{jobs}", "amplicol_generate_library"), - ("make", f"-j{jobs}", "amplicol_library_benchmark"), - ("make", f"-j{jobs}", "amplicol_color_probe"), - ) - for command in commands: - _run( - command, - cwd=repository, - label=f"original-AmpliCol build step {command[0]}", - log_path=log, - ) - legacy_amplicol.validate_checkout(repository) - emitted_probe = legacy_amplicol.run_selected_flow_library_probe( - repository, - entry=entry, - source_pdgs=source_pdgs, - momenta=points[0], - points=1, - ) - executable_entry, permutation = _validated_executable_row( - requested_entry=entry, - emitted_probe=emitted_probe, - source_pdgs=source_pdgs, - expected_flow_word=expected_flow_word, - expected_permutation=expected_permutation, - ) - snapshot = _copy_runtime(repository, output, process_file) - return ProbeContext( - runtime=snapshot.runtime, - worker_executable=snapshot.worker_executable, - process_file=snapshot.process_file, - selected_binary=snapshot.selected_binary, - union_binary=snapshot.union_binary, - linked_files=snapshot.linked_files, - group=int(executable_entry.group), - integral=int(executable_entry.integral), - source_pdgs=tuple(source_pdgs), - generated_pdgs=tuple(executable_entry.process_pdgs), - generated_color_order=tuple(executable_entry.color_order), - permutation=permutation, - ) - - -def _source_tree_sha256(identities: Sequence[Mapping[str, Any]]) -> str: - members = sorted( - ( - { - "size_bytes": identity["size_bytes"], - "sha256": identity["sha256"], - } - for identity in identities - ), - key=lambda identity: (identity["sha256"], identity["size_bytes"]), - ) - return _canonical_sha256( - { - "kind": "amplicol-source-content-set", - "schema_version": 1, - "members": members, - } - ) - - -def _source_evidence(repository: Path) -> SourceEvidence: - legacy_amplicol.validate_checkout(repository) - completed = _run( - ("git", "ls-files", "-z"), - cwd=repository, - label="original-AmpliCol tracked-source inventory", - ) - source_paths: list[Path] = [] - seen: set[Path] = set() - for item in completed.stdout.split("\0"): - if not item: - continue - path = (repository / item).resolve(strict=True) - if not path.is_file(): - _die(f"tracked original-AmpliCol source is not a file: {path}") - if path in seen: - _die(f"tracked original-AmpliCol sources resolve to duplicate path: {path}") - seen.add(path) - source_paths.append(path) - if not source_paths: - _die("original-AmpliCol tracked-source inventory is empty") - source_files = tuple(_file_ref(path) for path in sorted(source_paths)) - compiler = legacy_amplicol._compiler_provenance(repository) - source = { - "revision": legacy_amplicol.expected_revision(), - "dirty": False, - "compiler": { - "id": compiler.identity, - "version": compiler.version, - "target": compiler.target, - "flags_sha256": _canonical_sha256(list(compiler.flags)), - }, - "source_tree_sha256": _source_tree_sha256(source_files), - } - return SourceEvidence(source=source, source_files=source_files) - - -def _csv_ints(values: Sequence[int]) -> str: - return ",".join(str(int(value)) for value in values) - - -def _sample_command( - *, - role: str, - round_index: int, - points: int, - contract: CaptureContract, - context: ProbeContext, -) -> list[str]: - expected = contract.expected - selector_argument = ( - f"--color-flow-id={expected['color_flow']['id']}" - if role == SELECTED_ROLE - else f"--helicity-id={expected['helicity']['id']}" - ) - return [ - str(context.worker_executable), - "_sample", - f"--workload={role}", - f"--round={round_index}", - f"--momenta={contract.fixture['path']}", - f"--momenta-sha256={contract.fixture['file']['sha256']}", - f"--momenta-points-sha256={contract.fixture['points_sha256']}", - f"--source-revision={expected['amplicol_source_revision']}", - selector_argument, - f"--color-flow-word={_csv_ints(expected['color_flow']['word'])}", - f"--helicity-values={_csv_ints(expected['helicity']['values'])}", - f"--evaluated-points={points}", - f"--runtime={context.runtime}", - f"--selected-binary={context.selected_binary}", - f"--union-binary={context.union_binary}", - f"--process-file={context.process_file}", - f"--process-file-sha256={_file_sha256(context.process_file)}", - f"--group={context.group}", - f"--integral={context.integral}", - f"--source-pdgs={_csv_ints(context.source_pdgs)}", - f"--generated-pdgs={_csv_ints(context.generated_pdgs)}", - f"--generated-color-order={_csv_ints(context.generated_color_order)}", - f"--source-to-generated-permutation={_csv_ints(context.permutation)}", - ] - - -def _parse_probe_stdout( - stdout: str, - *, - role: str, - sample_index: int, - evaluated_points: int, -) -> dict[str, Any]: - payload = _strict_json(stdout.encode("utf-8"), "probe stdout") - if set(payload) != _PROBE_RESULT_KEYS: - _die("probe stdout has unknown or missing keys") - if ( - payload.get("kind") != "amplicol-m0-probe-result" - or payload.get("schema_version") != 1 - or payload.get("role") != role - or payload.get("sample_index") != sample_index - or payload.get("evaluated_point_count") != evaluated_points - ): - _die("probe stdout identity differs from its command") - elapsed = payload.get("elapsed_seconds") - seconds_per_point = payload.get("seconds_per_point") - if ( - isinstance(elapsed, bool) - or not isinstance(elapsed, int | float) - or not math.isfinite(float(elapsed)) - or float(elapsed) <= 0.0 - or isinstance(seconds_per_point, bool) - or not isinstance(seconds_per_point, int | float) - or not math.isfinite(float(seconds_per_point)) - or float(seconds_per_point) <= 0.0 - or not math.isclose( - float(seconds_per_point), - float(elapsed) / evaluated_points, - rel_tol=0.0, - abs_tol=max(1.0e-18, abs(float(seconds_per_point)) * 1.0e-15), - ) - ): - _die("probe stdout timing scalars are invalid or stale") - for field in ("selected_totals", "resolved_sums"): - rows = payload.get(field) - if not isinstance(rows, list) or not rows: - _die(f"probe stdout {field} is empty") - for row in rows: - if ( - not isinstance(row, list) - or len(row) != 2 - or any( - isinstance(value, bool) - or not isinstance(value, int | float) - or not math.isfinite(float(value)) - for value in row - ) - ): - _die(f"probe stdout {field} has an invalid complex pair") - return payload - - -def _utc_now() -> str: - return dt.datetime.now(dt.UTC).isoformat() - - -def _complex_pairs(values: Sequence[complex]) -> list[list[float]]: - return [[float(value.real), float(value.imag)] for value in values] - - -def _pairs_as_complex(values: object, label: str) -> tuple[complex, ...]: - if not isinstance(values, list): - _die(f"{label} must be a list") - result: list[complex] = [] - for row in values: - if not isinstance(row, list) or len(row) != 2: - _die(f"{label} has an invalid complex pair") - result.append(complex(float(row[0]), float(row[1]))) - return tuple(result) - - -def _timing_rows(output: str) -> dict[str, float]: - rows: dict[str, float] = {} - in_summary = False - for line in output.splitlines(): - if "Timing summary" in line: - in_summary = True - continue - if not in_summary: - continue - tokens = line.strip().split() - for index in range(1, len(tokens)): - try: - value = float(tokens[index]) - except ValueError: - continue - label = " ".join(tokens[:index]).casefold() - if label in rows: - _die(f"probe timing summary repeats row {label!r}") - if not math.isfinite(value) or value <= 0.0: - _die(f"probe timing row {label!r} is not finite and positive") - rows[label] = value - break - return rows - - -def _timing_value(output: str, label: str) -> float: - rows = _timing_rows(output) - wanted = label.casefold() - exact = rows.get(wanted) - if exact is not None: - return exact - matches = [value for row, value in rows.items() if wanted in row] - if len(matches) != 1: - _die(f"probe output has no unique positive timing row for {label!r}") - return matches[0] - - -def _library_environment(runtime: Path) -> dict[str, str]: - root = str(runtime.resolve()) - result: dict[str, str] = {} - for name in ("LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"): - existing = os.environ.get(name) - result[name] = root if not existing else f"{root}{os.pathsep}{existing}" - return result - - -@contextlib.contextmanager -def _temporary_environment(values: Mapping[str, str]) -> Iterator[None]: - prior = {name: os.environ.get(name) for name in values} - os.environ.update(values) - try: - yield - finally: - for name, value in prior.items(): - if value is None: - os.environ.pop(name, None) - else: - os.environ[name] = value - - -def _entry(arguments: argparse.Namespace) -> Any: - return legacy_amplicol.ProcessEntry( - group=arguments.group, - integral=arguments.integral, - process_pdgs=tuple(arguments.generated_pdgs), - color_order=tuple(arguments.generated_color_order), - ) - - -def _timed_selected( - arguments: argparse.Namespace, - *, - source_pdgs: Sequence[int], - first_point: Sequence[Sequence[float]], -) -> tuple[float, Any]: - with tempfile.TemporaryDirectory(prefix="pac-m0-selected-", dir="/tmp") as raw: - momentum_path = Path(raw) / "momenta.dat" - _write_ordered_momenta( - momentum_path, - source_pdgs=source_pdgs, - target_pdgs=arguments.generated_pdgs, - momenta=first_point, - ) - completed = _run( - ( - arguments.selected_binary, - str(arguments.evaluated_points), - str(arguments.group), - str(arguments.integral), - momentum_path, - ), - cwd=arguments.runtime, - environment=_library_environment(arguments.runtime), - label="selected-flow original-AmpliCol probe", - ) - output = completed.stdout + "\n" + completed.stderr - return ( - _timing_value(output, "amplitude evaluation"), - legacy_amplicol._parse_selected_flow_probe_output(output), - ) - - -def _timed_union( - arguments: argparse.Namespace, - *, - source_pdgs: Sequence[int], - first_point: Sequence[Sequence[float]], -) -> tuple[float, Any]: - permutation = tuple(arguments.source_to_generated_permutation) - ordered_helicities = [arguments.helicity_values[index] for index in permutation] - with tempfile.TemporaryDirectory(prefix="pac-m0-union-", dir="/tmp") as raw: - work = Path(raw) - process_copy = work / "processes.txt" - momentum_path = work / "momenta.dat" - shutil.copy2(arguments.process_file, process_copy) - _write_ordered_momenta( - momentum_path, - source_pdgs=source_pdgs, - target_pdgs=arguments.generated_pdgs, - momenta=first_point, - ) - completed = _run( - ( - arguments.union_binary, - str(arguments.evaluated_points), - str(arguments.group), - str(arguments.integral), - "lc", - process_copy, - momentum_path, - *(str(value) for value in ordered_helicities), - ), - cwd=work, - label="all-flow original-AmpliCol probe", - ) - output = completed.stdout + "\n" + completed.stderr - return ( - _timing_value(output, "total"), - legacy_amplicol._parse_probe_output(output), - ) - - -def _sample_values( - arguments: argparse.Namespace, - *, - source_pdgs: Sequence[int], - points: Sequence[Sequence[Sequence[float]]], - timed_result: Any, -) -> tuple[tuple[complex, ...], tuple[complex, ...]]: - entry = _entry(arguments) - if arguments.workload == SELECTED_ROLE and ( - timed_result.group != arguments.group - or timed_result.integral != arguments.integral - or tuple(timed_result.process_pdgs) != tuple(arguments.generated_pdgs) - or tuple(timed_result.color_order) != tuple(arguments.generated_color_order) - ): - _die("selected-flow timing probe returned a different generated row") - selected: list[complex] = [] - resolved: list[complex] = [] - for index, momenta in enumerate(points): - if index == 0: - probe = timed_result - elif arguments.workload == SELECTED_ROLE: - with _temporary_environment(_library_environment(arguments.runtime)): - probe = legacy_amplicol.run_selected_flow_library_probe( - arguments.runtime, - entry=entry, - source_pdgs=source_pdgs, - momenta=momenta, - points=1, - ) - else: - probe = legacy_amplicol.run_color_probe( - arguments.runtime, - process_file=arguments.process_file, - entry=entry, - source_pdgs=source_pdgs, - momenta=momenta, - color_accuracy="lc", - helicities=arguments.helicity_values, - ) - value = complex(float(probe.value), 0.0) - selected.append(value) - if arguments.workload == SELECTED_ROLE: - # The generated LC library's scalar is its internal resolved - # helicity sum after serialized hel_fac/normalization application. - resolved.append(value) - else: - partition_sum = probe.lc_partition_sum - if partition_sum is None or not probe.lc_row_partitions: - _die("all-flow color probe emitted no resolved LC-row partition") - resolved.append(complex(float(partition_sum), 0.0)) - if not _same_complex_values(selected, resolved): - _die("original-AmpliCol selected total and resolved sum do not close") - return tuple(selected), tuple(resolved) - - -def _sample_payload(arguments: argparse.Namespace) -> dict[str, Any]: - if arguments.source_revision != legacy_amplicol.expected_revision(): - _die("sample source revision differs from the contributor-lock pin") - expected_flow_id = "flow:" + _csv_ints(arguments.color_flow_word) - expected_helicity_id = "h:" + ",".join( - f"{value:+d}" for value in arguments.helicity_values - ) - if ( - len(arguments.color_flow_word) != 8 - or len(arguments.helicity_values) != 9 - or any(value not in (-1, 1) for value in arguments.helicity_values) - or len(arguments.source_pdgs) != 9 - or len(arguments.generated_pdgs) != 9 - or len(arguments.source_to_generated_permutation) != 9 - ): - _die("sample physical selector or external-leg dimensions are invalid") - if ( - arguments.workload == SELECTED_ROLE - and arguments.color_flow_id != expected_flow_id - ) or ( - arguments.workload == UNION_ROLE - and arguments.helicity_id != expected_helicity_id - ): - _die("sample stable selector ID differs from its explicit physical values") - for path, digest, label in ( - (arguments.momenta, arguments.momenta_sha256, "momenta"), - ( - arguments.process_file, - arguments.process_file_sha256, - "process file", - ), - ): - if _file_sha256(path.resolve(strict=True)) != digest: - _die(f"sample {label} content differs from its command digest") - if ( - not arguments.selected_binary.is_file() - or not os.access(arguments.selected_binary, os.X_OK) - or not arguments.union_binary.is_file() - or not os.access(arguments.union_binary, os.X_OK) - ): - _die("sample probe binary is missing or non-executable") - source_pdgs, points = _fixture_points(arguments.momenta) - if tuple(arguments.source_pdgs) != source_pdgs: - _die("sample source PDGs differ from the momenta fixture") - if tuple(arguments.source_to_generated_permutation) != tuple( - legacy_amplicol._permutation( - arguments.source_pdgs, - arguments.generated_pdgs, - ) - ): - _die("sample source-to-generated permutation is stale") - if _canonical_sha256(points) != arguments.momenta_points_sha256: - _die("sample momenta point digest differs from its command") - if arguments.workload == SELECTED_ROLE: - elapsed, timed_result = _timed_selected( - arguments, - source_pdgs=source_pdgs, - first_point=points[0], - ) - else: - elapsed, timed_result = _timed_union( - arguments, - source_pdgs=source_pdgs, - first_point=points[0], - ) - selected, resolved = _sample_values( - arguments, - source_pdgs=source_pdgs, - points=points, - timed_result=timed_result, - ) - seconds_per_point = elapsed / arguments.evaluated_points - return { - "kind": "amplicol-m0-probe-result", - "schema_version": 1, - "role": arguments.workload, - "sample_index": arguments.round, - "evaluated_point_count": arguments.evaluated_points, - "elapsed_seconds": elapsed, - "seconds_per_point": seconds_per_point, - "selected_totals": _complex_pairs(selected), - "resolved_sums": _complex_pairs(resolved), - } - - -def _interleave_group_sha256(records: Sequence[Mapping[str, Any]]) -> str: - return _canonical_sha256( - { - "kind": "pyamplicol-m0-paired-interleave", - "schema_version": 1, - "records": [dict(record) for record in records], - } - ) - - -def _comparison_payload( - selected: Sequence[complex], - resolved: Sequence[complex], -) -> dict[str, Any]: - if not _same_complex_values(selected, resolved): - _die("cannot publish a non-closing validation comparison") - maximum_absolute = 0.0 - maximum_relative = 0.0 - rows: list[dict[str, Any]] = [] - for index, (left, right) in enumerate(zip(selected, resolved, strict=True)): - difference = abs(left - right) - relative = difference / max(abs(right), ATOL) - maximum_absolute = max(maximum_absolute, difference) - maximum_relative = max(maximum_relative, relative) - rows.append({"point_index": index, "passes": True}) - return { - "selected_totals": _complex_pairs(selected), - "resolved_sums": _complex_pairs(resolved), - "point_comparisons": rows, - "maximum_absolute_difference": maximum_absolute, - "maximum_relative_difference": maximum_relative, - "passes": True, - } - - -def _manifest( - *, - role: str, - contract: CaptureContract, - context: ProbeContext, - source: SourceEvidence, - binary_evidence: Mapping[str, Any], - samples: Sequence[Mapping[str, Any]], - interleave_group_sha256: str, - selected: Sequence[complex], - resolved: Sequence[complex], -) -> dict[str, Any]: - expected = contract.expected - timing_values = [float(sample["seconds_per_point"]) for sample in samples] - median = statistics.median(timing_values) - mad = statistics.median(abs(value - median) for value in timing_values) - union = role == UNION_ROLE - payload = { - "kind": "pyamplicol-amplicol-m0-raw-evidence", - "schema_version": 1, - "complete": True, - "evidence_scope": "authoritative-host-capture-v1", - "workload": UNION_WORKLOAD if union else SELECTED_WORKLOAD, - "source": source.source, - "host": contract.host, - "process": { - "expression": PROCESS_EXPRESSION, - "normalized_expression": NORMALIZED_PROCESS, - }, - "physical_axes": { - "color_flow": contract.color_axis, - "helicity": contract.helicity_axis, - }, - "selector": { - "color_flow_request": contract.color_flow_request, - "resolved_color_flow_id": (None if union else expected["color_flow"]["id"]), - "color_flow_word": expected["color_flow"]["word"], - "helicity_request": contract.helicity_request, - "resolved_helicity_id": (expected["helicity"]["id"] if union else None), - "helicity_values": expected["helicity"]["values"], - "sum_axis": "color_flow" if union else "helicity", - "source_to_generated_permutation": list(context.permutation), - "complete_physical_axes": True, - "generation_specialized_axes": [], - }, - "momenta": { - "point_count": contract.fixture["point_count"], - "points_sha256": contract.fixture["points_sha256"], - "raw_file": contract.fixture["file"], - }, - "normalization_sha256": expected["normalization_sha256"], - "timing": { - "boundary": "direct-library-total" if union else "amplitude-evaluation", - "batch_semantics": "scalar-normalized-per-point", - "statistics_contract": "subprocess-median-and-raw-mad-v1", - "interleave_group_sha256": interleave_group_sha256, - "sample_count": len(samples), - "median_seconds_per_point": median, - "mad_seconds_per_point": mad, - "samples": [dict(sample) for sample in samples], - "samples_sha256": _canonical_sha256(samples), - }, - "validation": _comparison_payload(selected, resolved), - "binary_evidence": dict(binary_evidence), - } - return _content_addressed(payload) - - -def _raw_sample( - *, - role: str, - sample_index: int, - command_sha256: str, - stdout: str, - parsed: Mapping[str, Any], -) -> dict[str, Any]: - return _content_addressed( - { - "kind": "pyamplicol-amplicol-m0-raw-sample", - "schema_version": 1, - "role": role, - "sample_index": sample_index, - "command_sha256": command_sha256, - "evaluated_point_count": parsed["evaluated_point_count"], - "elapsed_seconds": parsed["elapsed_seconds"], - "seconds_per_point": parsed["seconds_per_point"], - "stdout": stdout, - "stdout_sha256": hashlib.sha256(stdout.encode("utf-8")).hexdigest(), - } - ) - - -def _adaptive_points( - elapsed: float, - *, - warmup_points: int, - target_seconds: float, - minimum_points: int, - maximum_points: int, -) -> int: - if not math.isfinite(elapsed) or elapsed <= 0.0: - _die("probe calibration did not report a positive finite time") - estimate = math.ceil(target_seconds * warmup_points / elapsed) - return max(minimum_points, min(maximum_points, estimate)) - - -def _run_sample_command( - command: Sequence[str], - *, - role: str, - round_index: int, - points: int, -) -> tuple[str, dict[str, Any], str, str]: - started = _utc_now() - completed = _run( - command, - cwd=ROOT, - label=f"{role} round {round_index}", - ) - finished = _utc_now() - parsed = _parse_probe_stdout( - completed.stdout, - role=role, - sample_index=round_index, - evaluated_points=points, - ) - if completed.stderr: - _die(f"{role} round {round_index} wrote unexpected stderr") - return completed.stdout, parsed, started, finished - - -def _verify_immutable_files(identities: Sequence[Mapping[str, Any]]) -> None: - for identity in identities: - path = Path(str(identity["path"])) - if _file_ref(path) != dict(identity): - _die(f"content-addressed capture input drifted: {path}") - - -def _capture(arguments: argparse.Namespace) -> dict[str, Any]: - request = arguments.request_template.resolve(strict=True) - repository = arguments.repository.resolve(strict=False) - output = arguments.output_directory.resolve(strict=False) - if output.exists() and any(output.iterdir()): - _die(f"output directory must not contain prior state: {output}") - output.mkdir(parents=True, exist_ok=True) - contract = _contract_from_request(request) - _require_clean_revision( - ROOT, - expected_revision=contract.expected["pyamplicol_source_revision"], - label="pyAmpliCol producer checkout", - ) - host = _host_identity() - if host != contract.host: - _die("current host identity differs from the four pyAmpliCol captures") - context = _prepare_probes( - repository=repository, - output=output, - fixture_path=contract.fixture["path"], - expected_flow_word=contract.expected["color_flow"]["word"], - expected_permutation=contract.expected["external_leg_permutation"], - jobs=arguments.jobs, - ) - source = _source_evidence(repository) - if source.source["revision"] != contract.expected["amplicol_source_revision"]: - _die("prepared original-AmpliCol source differs from the request pin") - - executable_ref = _file_ref(context.worker_executable) - linked_refs = tuple(_file_ref(path) for path in context.linked_files) - binary_evidence = { - "executable": executable_ref, - "linked_libraries": list(linked_refs), - "source_files": list(source.source_files), - } - - points_by_role: dict[str, int] = {} - explicit = { - SELECTED_ROLE: arguments.selected_points, - UNION_ROLE: arguments.union_points, - } - for role in ROLES: - if explicit[role] is not None: - points_by_role[role] = explicit[role] - continue - warmup_command = _sample_command( - role=role, - round_index=-1, - points=arguments.warmup_points, - contract=contract, - context=context, - ) - _stdout, parsed, _started, _finished = _run_sample_command( - warmup_command, - role=role, - round_index=-1, - points=arguments.warmup_points, - ) - points_by_role[role] = _adaptive_points( - float(parsed["elapsed_seconds"]), - warmup_points=arguments.warmup_points, - target_seconds=arguments.target_seconds, - minimum_points=arguments.minimum_points, - maximum_points=arguments.maximum_points, - ) - - samples: dict[str, list[dict[str, Any]]] = {role: [] for role in ROLES} - values: dict[str, tuple[tuple[complex, ...], tuple[complex, ...]]] = {} - interleave_records: list[dict[str, Any]] = [] - raw_directory = output / "raw-samples" - for round_index in range(MIN_SAMPLES): - for offset, role in enumerate(ROLES): - position = 2 * round_index + offset - points = points_by_role[role] - command = _sample_command( - role=role, - round_index=round_index, - points=points, - contract=contract, - context=context, - ) - command_sha256 = _canonical_sha256(command) - stdout, parsed, started, finished = _run_sample_command( - command, - role=role, - round_index=round_index, - points=points, - ) - selected = _pairs_as_complex( - parsed["selected_totals"], - f"{role} selected totals", - ) - resolved = _pairs_as_complex( - parsed["resolved_sums"], - f"{role} resolved sums", - ) - expected_values = ( - contract.selected_values - if role == SELECTED_ROLE - else contract.union_values - ) - if not _same_complex_values(selected, expected_values): - _die(f"{role} original-AmpliCol values differ from pyAmpliCol") - prior = values.setdefault(role, (selected, resolved)) - if not _same_complex_values(prior[0], selected) or not _same_complex_values( - prior[1], - resolved, - ): - _die(f"{role} validation values changed between subprocess rounds") - raw_payload = _raw_sample( - role=role, - sample_index=round_index, - command_sha256=command_sha256, - stdout=stdout, - parsed=parsed, - ) - raw_ref = _write_json( - raw_directory / f"{position:02d}-{role}.json", - raw_payload, - ) - sample = { - "sample_index": round_index, - "interleave_round": round_index, - "interleave_position": position, - "started_at_utc": started, - "finished_at_utc": finished, - "subprocess": True, - "command": command, - "command_sha256": command_sha256, - "evaluated_point_count": parsed["evaluated_point_count"], - "elapsed_seconds": parsed["elapsed_seconds"], - "seconds_per_point": parsed["seconds_per_point"], - "interrupted": False, - "raw_output_file": raw_ref, - } - samples[role].append(sample) - interleave_records.append( - { - "role": role, - "round": round_index, - "position": position, - "started_at_utc": started, - "finished_at_utc": finished, - "command_sha256": command_sha256, - } - ) - - interleave_sha256 = _interleave_group_sha256(interleave_records) - evidence_refs: dict[str, dict[str, Any]] = {} - for role in ROLES: - selected, resolved = values[role] - manifest = _manifest( - role=role, - contract=contract, - context=context, - source=source, - binary_evidence=binary_evidence, - samples=samples[role], - interleave_group_sha256=interleave_sha256, - selected=selected, - resolved=resolved, - ) - evidence_refs[role] = _write_json( - output / f"{role}.json", - manifest, - ) - - legacy_amplicol.validate_checkout(repository) - _require_clean_revision( - ROOT, - expected_revision=contract.expected["pyamplicol_source_revision"], - label="pyAmpliCol producer checkout", - ) - _verify_immutable_files( - ( - *contract.input_files, - executable_ref, - contract.fixture["file"], - *linked_refs, - *source.source_files, - *( - sample["raw_output_file"] - for role_samples in samples.values() - for sample in role_samples - ), - ) - ) - index = _content_addressed( - { - "kind": "pyamplicol-amplicol-m0-capture-index", - "schema_version": 1, - "complete": True, - "request_template": contract.input_files[0], - "source": source.source, - "host": contract.host, - "process": NORMALIZED_PROCESS, - "paired_round_count": MIN_SAMPLES, - "evaluated_points": points_by_role, - "interleave_group_sha256": interleave_sha256, - "amplicol_evidence": evidence_refs, - } - ) - _write_json(output / "capture-index.json", index) - return index - - -def _comma_separated_ints(value: str) -> tuple[int, ...]: - try: - result = tuple(int(item) for item in value.split(",")) - except ValueError as error: - raise argparse.ArgumentTypeError("must be comma-separated integers") from error - if not result: - raise argparse.ArgumentTypeError("must not be empty") - return result - - -def _positive_int(value: str) -> int: - parsed = int(value) - if parsed <= 0: - raise argparse.ArgumentTypeError("must be positive") - return parsed - - -def _positive_float(value: str) -> float: - parsed = float(value) - if not math.isfinite(parsed) or parsed <= 0.0: - raise argparse.ArgumentTypeError("must be finite and positive") - return parsed - - -def _sha256(value: str) -> str: - invalid = any(character not in "0123456789abcdef" for character in value) - if len(value) != 64 or invalid: - raise argparse.ArgumentTypeError("must be a lowercase SHA-256") - return value - - -def _revision(value: str) -> str: - invalid = any(character not in "0123456789abcdef" for character in value) - if len(value) != 40 or invalid: - raise argparse.ArgumentTypeError("must be a full lowercase Git SHA") - return value - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - subparsers = parser.add_subparsers(dest="command", required=True) - capture = subparsers.add_parser( - "capture", - help="build the pinned probes and capture two authoritative M0 manifests", - ) - capture.add_argument("--request-template", type=Path, required=True) - capture.add_argument( - "--repository", - type=Path, - default=legacy_amplicol.DEFAULT_REPOSITORY, - help="clean original-AmpliCol checkout at the contributor-lock revision", - ) - capture.add_argument("--output-directory", type=Path, required=True) - capture.add_argument("--jobs", type=_positive_int, default=1) - capture.add_argument( - "--target-seconds", - type=_positive_float, - default=DEFAULT_TARGET_SECONDS, - ) - capture.add_argument( - "--warmup-points", - type=_positive_int, - default=DEFAULT_WARMUP_POINTS, - ) - capture.add_argument( - "--minimum-points", - type=_positive_int, - default=DEFAULT_MINIMUM_POINTS, - ) - capture.add_argument( - "--maximum-points", - type=_positive_int, - default=DEFAULT_MAXIMUM_POINTS, - ) - capture.add_argument("--selected-points", type=_positive_int) - capture.add_argument("--union-points", type=_positive_int) - - sample = subparsers.add_parser("_sample", help=argparse.SUPPRESS) - sample.add_argument("--workload", choices=ROLES, required=True) - sample.add_argument("--round", type=int, required=True) - sample.add_argument("--momenta", type=Path, required=True) - sample.add_argument("--momenta-sha256", type=_sha256, required=True) - sample.add_argument("--momenta-points-sha256", type=_sha256, required=True) - sample.add_argument("--source-revision", type=_revision, required=True) - selectors = sample.add_mutually_exclusive_group(required=True) - selectors.add_argument("--color-flow-id") - selectors.add_argument("--helicity-id") - sample.add_argument( - "--color-flow-word", - type=_comma_separated_ints, - required=True, - ) - sample.add_argument( - "--helicity-values", - type=_comma_separated_ints, - required=True, - ) - sample.add_argument("--evaluated-points", type=_positive_int, required=True) - sample.add_argument("--runtime", type=Path, required=True) - sample.add_argument("--selected-binary", type=Path, required=True) - sample.add_argument("--union-binary", type=Path, required=True) - sample.add_argument("--process-file", type=Path, required=True) - sample.add_argument("--process-file-sha256", type=_sha256, required=True) - sample.add_argument("--group", type=_positive_int, required=True) - sample.add_argument("--integral", type=_positive_int, required=True) - sample.add_argument( - "--source-pdgs", - type=_comma_separated_ints, - required=True, - ) - sample.add_argument( - "--generated-pdgs", - type=_comma_separated_ints, - required=True, - ) - sample.add_argument( - "--generated-color-order", - type=_comma_separated_ints, - required=True, - ) - sample.add_argument( - "--source-to-generated-permutation", - type=_comma_separated_ints, - required=True, - ) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - parser = _parser() - arguments = parser.parse_args(argv) - try: - if arguments.command == "_sample": - if ( - arguments.workload == SELECTED_ROLE and arguments.color_flow_id is None - ) or (arguments.workload == UNION_ROLE and arguments.helicity_id is None): - _die("sample selector kind does not match its workload") - payload = _sample_payload(arguments) - sys.stdout.write(_canonical_bytes(payload).decode("utf-8") + "\n") - return 0 - if arguments.maximum_points < arguments.minimum_points: - _die("maximum-points must not be below minimum-points") - index = _capture(arguments) - sys.stdout.write(_canonical_bytes(index).decode("utf-8") + "\n") - return 0 - except CaptureError as error: - print(f"amplicol Z+6g M0 capture failed: {error}", file=sys.stderr) - return 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/arena_native_x86_acceptance.py b/pyamplicol/tools/developer/arena_native_x86_acceptance.py deleted file mode 100644 index 4fc333469e..0000000000 --- a/pyamplicol/tools/developer/arena_native_x86_acceptance.py +++ /dev/null @@ -1,1834 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Authenticate and bind the native-x86 Arena acceptance evidence. - -The ``preflight`` phase runs after the candidate wheel deployment check and -authenticates the clean source checkout, installed Python package, native -extension, build provenance, and candidate wheel before any ``pyamplicol`` -import. The ``audit`` phase repeats that authentication after the Arena gates, -validates their complete numerical contracts, and writes one content-addressed -acceptance manifest that binds every input evidence file. - -Both phases re-exec with ``-I -S -B`` and an absent external bytecode-cache -prefix. This is the same source-only bootstrap policy used by the compiled -Arena gate programs. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib -import importlib.machinery -import io -import json -import math -import os -import platform -import re -import stat -import subprocess -import sys -import sysconfig -import tempfile -import uuid -import zipfile -from collections.abc import Mapping, Sequence -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -_EXACT_REEXEC_MARKER = "PYAMPLICOL_X86_ACCEPTANCE_EXACT_REEXEC" -_EXACT_IMPORT_PATHS = "PYAMPLICOL_X86_ACCEPTANCE_IMPORT_PATHS" - - -def _bootstrap_source_only_python() -> None: - """Re-exec before importing repository or candidate runtime modules.""" - - if os.environ.get(_EXACT_REEXEC_MARKER) == "1": - if ( - sys.flags.isolated != 1 - or sys.flags.no_site != 1 - or sys.flags.ignore_environment != 1 - or sys.flags.dont_write_bytecode != 1 - or not sys.dont_write_bytecode - ): - raise RuntimeError("exact Python re-exec flags are incomplete") - raw_paths = json.loads(os.environ[_EXACT_IMPORT_PATHS]) - if not isinstance(raw_paths, list) or not all( - isinstance(path, str) and Path(path).is_absolute() for path in raw_paths - ): - raise RuntimeError("exact Python import paths are invalid") - cache_prefix = os.environ.get("PYTHONPYCACHEPREFIX") - if ( - not isinstance(cache_prefix, str) - or not Path(cache_prefix).is_absolute() - or Path(cache_prefix).exists() - ): - raise RuntimeError("exact Python cache prefix is not absent") - for import_path in reversed(raw_paths): - if import_path not in sys.path: - sys.path.insert(0, import_path) - sys.pycache_prefix = cache_prefix - return - - prefix = Path(tempfile.gettempdir()) / ( - f".pyamplicol-x86-acceptance-no-bytecode-{os.getpid()}-{uuid.uuid4().hex}" - ) - if prefix.exists(): - raise RuntimeError( - f"isolated Python cache prefix unexpectedly exists: {prefix}" - ) - import_paths: list[str] = [] - native_root = next( - ( - candidate - for entry in sys.path - if (candidate := Path(entry) / "pyamplicol").is_dir() - and any( - path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in candidate.iterdir() - ) - ), - None, - ) - if native_root is not None: - import_paths.append(str(native_root.parent.resolve(strict=True))) - for scheme_name in ("purelib", "platlib"): - scheme_path = sysconfig.get_path(scheme_name) - if not isinstance(scheme_path, str): - continue - try: - resolved = str(Path(scheme_path).resolve(strict=True)) - except OSError: - continue - if resolved not in import_paths: - import_paths.append(resolved) - environment = os.environ.copy() - environment["PYTHONDONTWRITEBYTECODE"] = "1" - environment["PYTHONPYCACHEPREFIX"] = str(prefix) - environment[_EXACT_REEXEC_MARKER] = "1" - environment[_EXACT_IMPORT_PATHS] = json.dumps(import_paths) - os.execve( - sys.executable, - ( - sys.executable, - "-I", - "-S", - "-B", - str(Path(__file__).resolve(strict=True)), - *sys.argv[1:], - ), - environment, - ) - raise RuntimeError("exact Python re-exec returned unexpectedly") - - -if __name__ == "__main__": - _bootstrap_source_only_python() - -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.performance_report.runtime_evidence import ( # noqa: E402 - RuntimeEvidenceError, - established_preimport_runtime_identity, - loaded_pyamplicol_origin_policy, - native_extension_in_package, - preimport_python_runtime_identity, - source_only_bytecode_policy, -) - -PREFLIGHT_KIND = "pyamplicol-arena-native-x86-runtime-preflight" -ACCEPTANCE_KIND = "pyamplicol-arena-native-x86-acceptance" -ALL_JIT_KIND = "pyamplicol-compiled-all-jit-direct-arena-gate" -FOUR_QUARK_KIND = "pyamplicol-four-quark-compiled-direct-arena-gate" -COLOR_MATRIX_KIND = "pyamplicol-eager-benchmark-matrix" -SCHEMA_VERSION = 1 -COLOR_MATRIX_SCHEMA_VERSION = 3 -EXPECTED_TARGET = "x86_64-unknown-linux-gnu" -EXPECTED_POINT_COUNT = 3 -EXPECTED_MEMORY_LIMIT_GIB = 30 -REVISION_PATTERN = re.compile(r"[0-9a-f]{40}") -SHA256_PATTERN = re.compile(r"[0-9a-f]{64}") -HASH_CHUNK_BYTES = 1024 * 1024 -CONTENT_IDENTITY_ALGORITHM = "sha256-canonical-json-body-v1" -PREFLIGHT_FILENAME = "runtime-identity-preflight.json" -ACCEPTANCE_FILENAME = "arena-native-x86-acceptance.json" -ALL_JIT_RELATIVE_PATH = Path( - "compiled-all-jit", - "compiled-all-jit-arena-gate.json", -) -FOUR_QUARK_RELATIVE_PATH = Path( - "four-quark", - "four-quark-compiled-gate.json", -) -COLOR_MATRIX_RELATIVE_PATH = Path("eager-compiled-color", "result.json") - -_ALL_JIT_LEVELS = { - "jit-o0": 0, - "jit-o1": 1, - "jit-o2": 2, - "jit-o3": 3, -} -_ALL_JIT_POINT_SEEDS = (846_731, 846_739, 846_763) -_ALL_JIT_COMPARISONS = { - "f64_vs_precision32_total", - "f64_evaluate_vs_resolved_total", - "precision32_evaluate_vs_resolved_total", - "f64_vs_precision32_resolved_components", -} -_CROSS_LEVEL_COMPARISONS = { - "f64_totals", - "precision32_totals", - "f64_resolved_components", - "precision32_resolved_components", -} -_FOUR_QUARK_LANES = { - "lc-topology-replay": ("lc", "topology-replay", False), - "lc-all-flow-union": ("lc", "all-flow-union", False), - "nlc-contracted": ("nlc", "topology-replay", True), - "full-contracted": ("full", "topology-replay", True), -} -_FOUR_QUARK_POINT_SEEDS = (443_041, 443_099, 443_137) -_FOUR_QUARK_BASE_COMPARISONS = { - "f64_vs_precision32_total", - "f64_vs_precision32_components", - "f64_evaluate_vs_resolved_total", - "precision32_evaluate_vs_resolved_total", - "helicity_selector_evaluate_vs_resolved_total", -} -_CROSS_LC_COMPARISONS = { - "f64_totals", - "precision32_totals", - "f64_resolved_components", - "precision32_resolved_components", - "color_selector", - "helicity_selector", -} -_SMOKE_CASES = { - "dd_z_3g": ("d d~ > z g g g", 4), - "dd_3q_1g": ("d d~ > u u~ s s~ g", 5), -} -_COLORS = ("lc", "nlc", "full") -_COLOR_MATRIX_GATES = { - "matrix_scope_complete", - "correctness", - "per_point_selector_patterns", - "builtin_ufo_topology_parity", - "smoke_under_five_minutes", - "n4_n5_reusable_compiled_at_most_1_25x_specialized", - "nlc_full_each_at_least_7x", - "lc_no_generation_regression", - "per_process_geometric_mean_at_least_7x", -} -_CORRECTNESS_FIELDS = { - "total", - "resolved_f64", - "resolved_precision32", - "eager_resolved_sum", - "compiled_resolved_sum", - "passes", -} -_STABLE_STAT_FIELDS = ( - "st_dev", - "st_ino", - "st_mode", - "st_size", - "st_mtime_ns", - "st_ctime_ns", -) - - -class AcceptanceError(RuntimeError): - """Raised when native-x86 acceptance evidence cannot be trusted.""" - - -def _canonical_json(value: object) -> bytes: - try: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ).encode("utf-8") - except (TypeError, ValueError) as error: - raise AcceptanceError("evidence is not canonical JSON") from error - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_json(value)).hexdigest() - - -def _attach_content_identity(body: Mapping[str, object]) -> dict[str, object]: - result = dict(body) - result["content_identity"] = { - "algorithm": CONTENT_IDENTITY_ALGORITHM, - "sha256": _canonical_sha256(body), - } - return result - - -def _mapping(value: object, *, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise AcceptanceError(f"{label} must be an object") - return value - - -def _list(value: object, *, label: str) -> list[Any]: - if not isinstance(value, list): - raise AcceptanceError(f"{label} must be an array") - return value - - -def _require_true(value: object, *, label: str) -> None: - if value is not True: - raise AcceptanceError(f"{label} must be true") - - -def _require_positive_int(value: object, *, label: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value <= 0: - raise AcceptanceError(f"{label} must be a positive integer") - return value - - -def _require_nonempty_string(value: object, *, label: str) -> str: - if not isinstance(value, str) or not value: - raise AcceptanceError(f"{label} must be a non-empty string") - return value - - -def _require_sha256(value: object, *, label: str) -> str: - if not isinstance(value, str) or SHA256_PATTERN.fullmatch(value) is None: - raise AcceptanceError(f"{label} must be a lowercase SHA-256 digest") - return value - - -def _require_content_identity(payload: Mapping[str, object], *, label: str) -> None: - identity = _mapping( - payload.get("content_identity"), - label=f"{label}.content_identity", - ) - if identity.get("algorithm") != CONTENT_IDENTITY_ALGORITHM: - raise AcceptanceError(f"{label} has the wrong content-identity algorithm") - body = dict(payload) - body.pop("content_identity") - if identity.get("sha256") != _canonical_sha256(body): - raise AcceptanceError(f"{label} content identity is invalid") - - -def _same_stat(left: os.stat_result, right: os.stat_result) -> bool: - return all( - getattr(left, field) == getattr(right, field) for field in _STABLE_STAT_FIELDS - ) - - -def _checked_file_bytes(path: Path, *, label: str) -> tuple[bytes, dict[str, object]]: - """Read one stable regular file through a no-follow descriptor.""" - - try: - parent = path.parent.expanduser().resolve(strict=True) - except OSError as error: - raise AcceptanceError(f"cannot resolve {label} parent: {path}") from error - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_NOFOLLOW", 0) - | getattr(os, "O_BINARY", 0) - ) - descriptor: int | None = None - parent_fd: int | None = None - try: - parent_fd = os.open( - parent, - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_DIRECTORY", 0) - | getattr(os, "O_NOFOLLOW", 0), - ) - namespace_before = os.stat( - path.name, - dir_fd=parent_fd, - follow_symlinks=False, - ) - if not stat.S_ISREG(namespace_before.st_mode): - raise AcceptanceError(f"{label} is not a regular file: {path}") - descriptor = os.open(path.name, flags, dir_fd=parent_fd) - opened_before = os.fstat(descriptor) - if not _same_stat(namespace_before, opened_before): - raise AcceptanceError(f"{label} changed while it was opened: {path}") - digest = hashlib.sha256() - blocks: list[bytes] = [] - byte_count = 0 - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - while block := stream.read(HASH_CHUNK_BYTES): - digest.update(block) - blocks.append(block) - byte_count += len(block) - opened_after = os.fstat(stream.fileno()) - namespace_after = os.stat( - path.name, - dir_fd=parent_fd, - follow_symlinks=False, - ) - except OSError as error: - raise AcceptanceError(f"cannot authenticate {label}: {path}") from error - finally: - if descriptor is not None: - os.close(descriptor) - if parent_fd is not None: - os.close(parent_fd) - if ( - byte_count != opened_before.st_size - or not _same_stat(opened_before, opened_after) - or not _same_stat(opened_after, namespace_after) - ): - raise AcceptanceError(f"{label} changed while it was hashed: {path}") - return b"".join(blocks), { - "path": str(parent / path.name), - "size_bytes": byte_count, - "sha256": digest.hexdigest(), - } - - -def _checked_file_identity(path: Path, *, label: str) -> dict[str, object]: - return _checked_file_bytes(path, label=label)[1] - - -def _reject_json_constant(value: str) -> None: - raise AcceptanceError(f"JSON contains a non-finite number: {value}") - - -def _reject_duplicate_keys(pairs: list[tuple[str, Any]]) -> dict[str, Any]: - result: dict[str, Any] = {} - for key, value in pairs: - if key in result: - raise AcceptanceError(f"JSON object contains duplicate key: {key!r}") - result[key] = value - return result - - -def _checked_json( - path: Path, - *, - label: str, -) -> tuple[dict[str, Any], dict[str, object]]: - encoded, identity = _checked_file_bytes(path, label=label) - try: - payload = json.loads( - encoded.decode("utf-8"), - object_pairs_hook=_reject_duplicate_keys, - parse_constant=_reject_json_constant, - ) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise AcceptanceError(f"{label} is not strict UTF-8 JSON: {path}") from error - if not isinstance(payload, dict): - raise AcceptanceError(f"{label} must contain a JSON object") - _canonical_json(payload) - return payload, identity - - -def _write_json_atomic(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp") - try: - temporary.write_text( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=False, - indent=2, - sort_keys=True, - ) - + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - except OSError as error: - temporary.unlink(missing_ok=True) - raise AcceptanceError(f"cannot write acceptance evidence: {path}") from error - - -def _remove_stale_file(path: Path) -> None: - try: - metadata = path.lstat() - except FileNotFoundError: - return - except OSError as error: - raise AcceptanceError(f"cannot inspect stale evidence: {path}") from error - if not stat.S_ISREG(metadata.st_mode): - raise AcceptanceError(f"refusing non-regular stale evidence: {path}") - try: - path.unlink() - except OSError as error: - raise AcceptanceError(f"cannot remove stale evidence: {path}") from error - - -def _evidence_root(path: Path) -> Path: - root = path.expanduser().resolve(strict=False) - checkout = ROOT.resolve(strict=True) - if root == Path(root.anchor) or root == checkout: - raise AcceptanceError("refusing a broad evidence root") - try: - root.relative_to(checkout) - except ValueError: - pass - else: - raise AcceptanceError("Arena evidence root must be outside the checkout") - root.mkdir(parents=True, exist_ok=True) - return root - - -def _git_output(arguments: Sequence[str]) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=ROOT, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - detail = completed.stderr.strip() or completed.stdout.strip() - raise AcceptanceError(f"git {' '.join(arguments)} failed: {detail}") - return completed.stdout.strip() - - -def _source_identity( - *, - expected_revision: str, - expected_workspace: Path, -) -> dict[str, object]: - if REVISION_PATTERN.fullmatch(expected_revision) is None: - raise AcceptanceError("expected revision must be a full lowercase Git SHA") - try: - workspace = expected_workspace.expanduser().resolve(strict=True) - checkout = ROOT.resolve(strict=True) - except OSError as error: - raise AcceptanceError("expected source workspace is unavailable") from error - if workspace != checkout: - raise AcceptanceError("acceptance helper is executing from another workspace") - revision = _git_output(("rev-parse", "--verify", "HEAD")) - status = _git_output(("status", "--porcelain=v1", "--untracked-files=all")) - if revision != expected_revision or status: - raise AcceptanceError("candidate checkout is not the clean dispatched revision") - return { - "checkout": str(checkout), - "revision": revision, - "dirty": False, - "untracked_files_checked": True, - } - - -def _ensure_source_only_python() -> None: - try: - source_only_bytecode_policy() - except RuntimeEvidenceError as error: - raise AcceptanceError( - "source-only Python bootstrap did not complete before authentication" - ) from error - - -def _establish_preimport_runtime_identity() -> None: - candidates = [] - for entry in sys.path: - package_root = Path(entry) / "pyamplicol" - if not package_root.is_dir(): - continue - if any( - path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in package_root.iterdir() - ): - resolved = package_root.resolve(strict=True) - if resolved not in candidates: - candidates.append(resolved) - if len(candidates) != 1: - raise AcceptanceError( - "exactly one native pyamplicol package must be importable before audit" - ) - try: - native = native_extension_in_package(candidates[0]) - preimport_python_runtime_identity( - (candidates[0],), - native_extension=native, - ) - except RuntimeEvidenceError as error: - raise AcceptanceError(str(error)) from error - - -def _wheel_build_info(encoded: bytes) -> dict[str, Any]: - try: - with zipfile.ZipFile(io.BytesIO(encoded)) as archive: - matches = [ - info - for info in archive.infolist() - if info.filename == "pyamplicol/_build_info.json" - ] - if len(matches) != 1: - raise AcceptanceError( - "candidate wheel must contain one pyamplicol/_build_info.json" - ) - raw = archive.read(matches[0]) - except (OSError, zipfile.BadZipFile, KeyError) as error: - raise AcceptanceError("candidate wheel is not a valid wheel archive") from error - try: - value = json.loads( - raw.decode("utf-8"), - object_pairs_hook=_reject_duplicate_keys, - parse_constant=_reject_json_constant, - ) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise AcceptanceError("candidate wheel build info is invalid JSON") from error - if not isinstance(value, dict): - raise AcceptanceError("candidate wheel build info is not an object") - return value - - -def _runtime_identity( - source: Mapping[str, object], -) -> dict[str, object]: - try: - pyamplicol = importlib.import_module("pyamplicol") - native = importlib.import_module("pyamplicol._rusticol") - versions = importlib.import_module("pyamplicol._internal.versions") - except ImportError as error: - raise AcceptanceError("candidate native runtime is unavailable") from error - package_roots = tuple( - Path(str(path)).expanduser().resolve(strict=True) - for path in pyamplicol.__path__ - ) - candidate_root = (ROOT / ".venv").resolve(strict=True) - if len(package_roots) != 1 or not package_roots[0].is_relative_to(candidate_root): - raise AcceptanceError("pyamplicol was not imported from the candidate venv") - native_path_raw = getattr(native, "__file__", None) - if not isinstance(native_path_raw, str): - raise AcceptanceError("candidate native extension has no path") - native_path = Path(native_path_raw).expanduser().resolve(strict=True) - if native_path.parent != package_roots[0]: - raise AcceptanceError("native extension is outside the candidate package") - target = str(native.target_info().triple) - if ( - platform.system() != "Linux" - or platform.machine() != "x86_64" - or "x86_64" not in sysconfig.get_platform() - or target != EXPECTED_TARGET - ): - raise AcceptanceError("Arena acceptance requires native Linux x86_64") - native_inputs = native.native_build_inputs_sha256() - _require_sha256(native_inputs, label="native build-input identity") - build_info = versions._active_build_info() - if not isinstance(build_info, Mapping): - raise AcceptanceError("candidate exposes no strict build provenance") - try: - build_checkout = ( - Path(str(build_info.get("source_checkout"))) - .expanduser() - .resolve(strict=True) - ) - except OSError as error: - raise AcceptanceError("candidate build checkout is unavailable") from error - if ( - build_info.get("source_revision") != source.get("revision") - or build_checkout != ROOT.resolve(strict=True) - or build_info.get("native_build_inputs_sha256") != native_inputs - or build_info.get("publishable") is not False - or build_info.get("selftest_fixture_bootstrap") is not False - ): - raise AcceptanceError("candidate build provenance is not exact") - artifact_directory = (ROOT / ".artifacts" / "candidate").resolve(strict=True) - wheels = tuple(sorted(artifact_directory.glob("*.whl"))) - if len(wheels) != 1: - raise AcceptanceError("candidate build must produce exactly one wheel") - wheel_bytes, wheel_identity = _checked_file_bytes( - wheels[0], - label="candidate wheel", - ) - wheel_build_info = _wheel_build_info(wheel_bytes) - if wheel_build_info != dict(build_info): - raise AcceptanceError( - "candidate wheel and installed runtime expose different build provenance" - ) - preimport = established_preimport_runtime_identity() - try: - loaded_policy = loaded_pyamplicol_origin_policy( - package_roots, - native_extension=native_path, - expected_package_identity=preimport["python_package_tree"], - expected_native_identity=preimport["native_extension"], - ) - except RuntimeEvidenceError as error: - raise AcceptanceError(str(error)) from error - interpreter_identity = _checked_file_identity( - Path(sys.executable).resolve(strict=True), - label="candidate interpreter", - ) - return { - "kind": "pyamplicol-arena-native-x86-runtime-identity", - "schema_version": 1, - "interpreter": { - **interpreter_identity, - "python_version": platform.python_version(), - "implementation": platform.python_implementation(), - }, - "platform": { - "system": platform.system(), - "machine": platform.machine(), - "python_platform": sysconfig.get_platform(), - "target": target, - }, - "preimport_runtime_identity": preimport, - "package": { - "roots": [str(path) for path in package_roots], - "version": str(getattr(pyamplicol, "__version__", "")), - }, - "loaded_module_origin_policy": loaded_policy, - "native_extension": { - **_checked_file_identity(native_path, label="candidate native extension"), - "target": target, - "build_inputs_sha256": native_inputs, - }, - "active_build_info": { - "payload": dict(build_info), - "canonical_sha256": _canonical_sha256(build_info), - }, - "candidate_wheel": { - **wheel_identity, - "build_info_canonical_sha256": _canonical_sha256(wheel_build_info), - "matches_active_build_info": True, - }, - "passes": True, - } - - -def _stable_runtime_identity(value: Mapping[str, object]) -> dict[str, object]: - stable = dict(value) - raw_policy = stable.get("loaded_module_origin_policy") - if isinstance(raw_policy, Mapping): - policy = dict(raw_policy) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - policy.pop(field, None) - stable["loaded_module_origin_policy"] = policy - return stable - - -def _runtime_identity_sha256(value: Mapping[str, object]) -> str: - return _canonical_sha256(_stable_runtime_identity(value)) - - -def _cross_process_runtime_binding( - value: Mapping[str, object], - *, - label: str, -) -> dict[str, object]: - """Normalize the byte identities shared by helper and gate processes.""" - - preimport = value.get("preimport_runtime_identity") - if isinstance(preimport, Mapping): - package_tree = _mapping( - preimport.get("python_package_tree"), - label=f"{label}.preimport_runtime_identity.python_package_tree", - ) - else: - package_tree = _mapping( - value.get("python_package_tree"), - label=f"{label}.python_package_tree", - ) - interpreter = _mapping( - value.get("interpreter"), - label=f"{label}.interpreter", - ) - native = _mapping( - value.get("native_extension"), - label=f"{label}.native_extension", - ) - active = _mapping( - value.get("active_build_info"), - label=f"{label}.active_build_info", - ) - package = _mapping(value.get("package"), label=f"{label}.package") - return { - "interpreter": { - name: interpreter.get(name) - for name in ( - "path", - "size_bytes", - "sha256", - "python_version", - "implementation", - ) - }, - "python_package_tree": dict(package_tree), - "native_extension": { - name: native.get(name) - for name in ("path", "size_bytes", "sha256", "build_inputs_sha256") - }, - "active_build_info": dict(active), - "package_version": package.get("version"), - } - - -def _require_gate_provenance( - payload: Mapping[str, object], - *, - label: str, - expected_revision: str, - expected_workspace: Path, - expected_runtime: Mapping[str, object] | None = None, -) -> None: - source = _mapping(payload.get("source_identity"), label=f"{label}.source_identity") - source_postflight = _mapping( - payload.get("source_identity_postflight"), - label=f"{label}.source_identity_postflight", - ) - _require_true(payload.get("source_identity_match"), label=f"{label}.source match") - expected_source = { - "checkout": str(expected_workspace.resolve(strict=True)), - "revision": expected_revision, - "dirty": False, - "untracked_files_checked": True, - } - if dict(source) != expected_source or dict(source_postflight) != expected_source: - raise AcceptanceError(f"{label} source identity is not exact") - runtime = _mapping( - payload.get("runtime_identity"), - label=f"{label}.runtime_identity", - ) - runtime_postflight = _mapping( - payload.get("runtime_identity_postflight"), - label=f"{label}.runtime_identity_postflight", - ) - _require_true(payload.get("runtime_identity_match"), label=f"{label}.runtime match") - if _stable_runtime_identity(runtime) != _stable_runtime_identity( - runtime_postflight - ): - raise AcceptanceError(f"{label} runtime identity changed") - if expected_runtime is not None and _cross_process_runtime_binding( - runtime, - label=f"{label}.runtime_identity", - ) != _cross_process_runtime_binding( - expected_runtime, - label="acceptance runtime identity", - ): - raise AcceptanceError(f"{label} did not use the preflight candidate runtime") - active = _mapping( - runtime.get("active_build_info"), - label=f"{label}.runtime_identity.active_build_info", - ) - build_info = _mapping( - active.get("payload"), - label=f"{label}.runtime_identity.active_build_info.payload", - ) - if build_info.get("source_revision") != expected_revision or active.get( - "canonical_sha256" - ) != _canonical_sha256(build_info): - raise AcceptanceError(f"{label} runtime build provenance is invalid") - script = _mapping( - payload.get("gate_script_identity"), - label=f"{label}.gate_script_identity", - ) - script_postflight = _mapping( - payload.get("gate_script_identity_postflight"), - label=f"{label}.gate_script_identity_postflight", - ) - _require_true( - payload.get("gate_script_identity_match"), - label=f"{label}.gate script match", - ) - if dict(script) != dict(script_postflight): - raise AcceptanceError(f"{label} gate script identity changed") - _require_sha256(script.get("sha256"), label=f"{label}.gate script SHA-256") - - -def _require_comparison(value: object, *, label: str) -> None: - comparison = _mapping(value, label=label) - _require_true(comparison.get("passes"), label=f"{label}.passes") - if ( - "failing_value_count" in comparison - and comparison.get("failing_value_count") != 0 - ): - raise AcceptanceError(f"{label} has failing numerical values") - counts = [ - comparison.get(name) - for name in ("value_count", "component_count") - if name in comparison - ] - if counts and not any( - isinstance(count, int) and not isinstance(count, bool) and count > 0 - for count in counts - ): - raise AcceptanceError(f"{label} comparison is empty") - - -def _require_comparison_mapping( - value: object, - *, - label: str, - expected_names: set[str], -) -> None: - comparisons = _mapping(value, label=label) - if set(comparisons) != expected_names: - raise AcceptanceError(f"{label} has incomplete comparison coverage") - for name, comparison in comparisons.items(): - _require_comparison(comparison, label=f"{label}.{name}") - - -def _validate_all_jit( - payload: Mapping[str, object], - *, - expected_revision: str, - expected_workspace: Path, - point_count: int, - expected_runtime: Mapping[str, object] | None = None, -) -> dict[str, object]: - label = "all-JIT evidence" - _require_content_identity(payload, label=label) - if ( - payload.get("kind") != ALL_JIT_KIND - or payload.get("schema_version") != SCHEMA_VERSION - or payload.get("status") != "ok" - ): - raise AcceptanceError(f"{label} has the wrong kind, schema, or status") - _require_true(payload.get("passes"), label=f"{label}.passes") - if payload.get("failures") != []: - raise AcceptanceError(f"{label} contains failures") - _require_gate_provenance( - payload, - label=label, - expected_revision=expected_revision, - expected_workspace=expected_workspace, - expected_runtime=expected_runtime, - ) - request = _mapping(payload.get("request"), label=f"{label}.request") - if ( - request.get("process") != "g g > g g" - or request.get("jit_optimization_levels") != [0, 1, 2, 3] - or request.get("point_count") != point_count - or request.get("point_seeds") != list(_ALL_JIT_POINT_SEEDS[:point_count]) - or request.get("relative_tolerance") != 1.0e-12 - or request.get("absolute_tolerance") != 1.0e-15 - or request.get("memory_limit_gib") != EXPECTED_MEMORY_LIMIT_GIB - ): - raise AcceptanceError(f"{label} request is not the required request") - momenta = _mapping( - request.get("momenta_identity"), - label=f"{label}.request.momenta_identity", - ) - if ( - momenta.get("algorithm") != "sha256-float-hex-momenta-v1" - or momenta.get("point_count") != point_count - or momenta.get("external_particle_count") != 4 - ): - raise AcceptanceError(f"{label} momenta identity is invalid") - _require_sha256(momenta.get("sha256"), label=f"{label}.momenta SHA-256") - _require_nonempty_string( - request.get("mandatory_watchdog_command"), - label=f"{label}.mandatory_watchdog_command", - ) - levels = _mapping(payload.get("levels"), label=f"{label}.levels") - if set(levels) != set(_ALL_JIT_LEVELS): - raise AcceptanceError(f"{label} does not cover JIT O0 through O3") - for name, optimization_level in _ALL_JIT_LEVELS.items(): - lane = _mapping(levels[name], label=f"{label}.levels.{name}") - _require_true(lane.get("passes"), label=f"{label}.levels.{name}.passes") - expected_configuration = { - "process": "g g > g g", - "color_accuracy": "lc", - "lc_flow_layout": "topology-replay", - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": optimization_level, - } - if lane.get("configuration") != expected_configuration: - raise AcceptanceError(f"{label}.{name} configuration drifted") - generation = _mapping( - lane.get("generation"), - label=f"{label}.{name}.generation", - ) - worker = _mapping( - generation.get("worker_provenance"), - label=f"{label}.{name}.generation.worker_provenance", - ) - if ( - worker.get("source_revision") != expected_revision - or worker.get("postflight_identity_match") is not True - ): - raise AcceptanceError(f"{label}.{name} worker provenance drifted") - artifact = _mapping( - lane.get("artifact_identity"), - label=f"{label}.{name}.artifact_identity", - ) - _require_positive_int( - artifact.get("payload_count"), - label=f"{label}.{name}.artifact payload count", - ) - arena_audit = _mapping( - artifact.get("direct_arena_audit"), - label=f"{label}.{name}.artifact direct Arena audit", - ) - _require_true( - arena_audit.get("passes"), - label=f"{label}.{name}.artifact direct Arena audit passes", - ) - numerical = _mapping( - lane.get("numerical_validation"), - label=f"{label}.{name}.numerical_validation", - ) - _require_true( - numerical.get("passes"), - label=f"{label}.{name}.numerical_validation.passes", - ) - if ( - numerical.get("execution_mode") != "compiled" - or numerical.get("point_count") != point_count - or numerical.get("point_seeds") != list(_ALL_JIT_POINT_SEEDS[:point_count]) - ): - raise AcceptanceError(f"{label}.{name} numerical request drifted") - _require_comparison_mapping( - numerical.get("comparisons"), - label=f"{label}.{name}.comparisons", - expected_names=_ALL_JIT_COMPARISONS, - ) - native_profile = _mapping( - numerical.get("native_profile"), - label=f"{label}.{name}.native_profile", - ) - _require_true( - native_profile.get("passes"), - label=f"{label}.{name}.native_profile.passes", - ) - if native_profile.get("execution_mode") != "compiled": - raise AcceptanceError(f"{label}.{name} did not profile compiled execution") - engine = _mapping( - native_profile.get("direct_arena_engine_counter"), - label=f"{label}.{name}.direct_arena_engine_counter", - ) - calls = _mapping( - native_profile.get("direct_arena_call_counter"), - label=f"{label}.{name}.direct_arena_call_counter", - ) - _require_positive_int(engine.get("value"), label=f"{label}.{name}.engines") - _require_positive_int(calls.get("value"), label=f"{label}.{name}.calls") - cross = _mapping( - payload.get("cross_level_numerical_parity"), - label=f"{label}.cross_level_numerical_parity", - ) - _require_true(cross.get("passes"), label=f"{label}.cross-level passes") - if cross.get("baseline_optimization_level") != 3: - raise AcceptanceError(f"{label} cross-level baseline is not O3") - cross_comparisons = _mapping( - cross.get("comparisons"), - label=f"{label}.cross-level comparisons", - ) - if set(cross_comparisons) != {"o0_vs_o3", "o1_vs_o3", "o2_vs_o3"}: - raise AcceptanceError(f"{label} cross-level coverage is incomplete") - for name, comparisons in cross_comparisons.items(): - _require_comparison_mapping( - comparisons, - label=f"{label}.cross-level comparisons.{name}", - expected_names=_CROSS_LEVEL_COMPARISONS, - ) - return { - "kind": ALL_JIT_KIND, - "schema_version": SCHEMA_VERSION, - "point_count": point_count, - "levels": sorted(levels), - "numerical_validation": True, - "passes": True, - } - - -def _validate_four_quark( - payload: Mapping[str, object], - *, - expected_revision: str, - expected_workspace: Path, - point_count: int, - expected_runtime: Mapping[str, object] | None = None, -) -> dict[str, object]: - label = "four-quark evidence" - _require_content_identity(payload, label=label) - if ( - payload.get("kind") != FOUR_QUARK_KIND - or payload.get("schema_version") != SCHEMA_VERSION - or payload.get("status") != "ok" - ): - raise AcceptanceError(f"{label} has the wrong kind, schema, or status") - _require_true(payload.get("passes"), label=f"{label}.passes") - if payload.get("failures") != []: - raise AcceptanceError(f"{label} contains failures") - _require_gate_provenance( - payload, - label=label, - expected_revision=expected_revision, - expected_workspace=expected_workspace, - expected_runtime=expected_runtime, - ) - request = _mapping(payload.get("request"), label=f"{label}.request") - if ( - request.get("process") != "d d~ > u u~ s s~ c c~" - or request.get("independent_quark_line_count") != 4 - or request.get("expected_external_pdgs") != [-4, -3, -2, -1, 1, 2, 3, 4] - or request.get("max_quark_lines") != 4 - or request.get("point_count") != point_count - or request.get("point_seeds") != list(_FOUR_QUARK_POINT_SEEDS[:point_count]) - or request.get("relative_tolerance") != 1.0e-12 - or request.get("absolute_tolerance") != 1.0e-300 - or request.get("memory_limit_gib") != EXPECTED_MEMORY_LIMIT_GIB - ): - raise AcceptanceError(f"{label} request is not the required request") - momenta = _mapping( - request.get("momenta_identity"), - label=f"{label}.request.momenta_identity", - ) - if ( - momenta.get("algorithm") != "sha256-float-hex-momenta-v1" - or momenta.get("point_count") != point_count - or momenta.get("external_particle_count") != 8 - ): - raise AcceptanceError(f"{label} momenta identity is invalid") - _require_sha256(momenta.get("sha256"), label=f"{label}.momenta SHA-256") - _require_nonempty_string( - request.get("mandatory_watchdog_command"), - label=f"{label}.mandatory_watchdog_command", - ) - rejections = _list( - payload.get("invalid_union_configurations"), - label=f"{label}.invalid_union_configurations", - ) - rejected_colors: set[str] = set() - for index, raw in enumerate(rejections): - rejection = _mapping( - raw, - label=f"{label}.invalid_union_configurations[{index}]", - ) - color = rejection.get("color_accuracy") - if ( - color not in {"nlc", "full"} - or rejection.get("lc_flow_layout") != "all-flow-union" - or rejection.get("rejected") is not True - or not isinstance(rejection.get("message"), str) - or "all-flow-union" not in str(rejection.get("message")) - ): - raise AcceptanceError(f"{label} invalid-union rejection is incomplete") - rejected_colors.add(str(color)) - if rejected_colors != {"nlc", "full"} or len(rejections) != 2: - raise AcceptanceError(f"{label} did not reject both invalid union requests") - lanes = _mapping(payload.get("lanes"), label=f"{label}.lanes") - if set(lanes) != set(_FOUR_QUARK_LANES): - raise AcceptanceError(f"{label} lane coverage is incomplete") - for name, (color, layout, contracted) in _FOUR_QUARK_LANES.items(): - lane = _mapping(lanes[name], label=f"{label}.lanes.{name}") - _require_true(lane.get("passes"), label=f"{label}.{name}.passes") - expected_configuration = { - "process": "d d~ > u u~ s s~ c c~", - "max_quark_lines": 4, - "color_accuracy": color, - "lc_flow_layout": layout, - "contracted_color": contracted, - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": 3, - } - if lane.get("configuration") != expected_configuration: - raise AcceptanceError(f"{label}.{name} configuration drifted") - generation = _mapping( - lane.get("generation"), - label=f"{label}.{name}.generation", - ) - worker = _mapping( - generation.get("worker_provenance"), - label=f"{label}.{name}.generation.worker_provenance", - ) - if ( - worker.get("source_revision") != expected_revision - or worker.get("postflight_identity_match") is not True - ): - raise AcceptanceError(f"{label}.{name} worker provenance drifted") - artifact = _mapping( - lane.get("artifact_identity"), - label=f"{label}.{name}.artifact_identity", - ) - _require_positive_int( - artifact.get("payload_count"), - label=f"{label}.{name}.artifact payload count", - ) - arena_audit = _mapping( - artifact.get("direct_arena_audit"), - label=f"{label}.{name}.artifact direct Arena audit", - ) - _require_true( - arena_audit.get("passes"), - label=f"{label}.{name}.artifact direct Arena audit passes", - ) - numerical = _mapping( - lane.get("numerical_validation"), - label=f"{label}.{name}.numerical_validation", - ) - _require_true( - numerical.get("passes"), - label=f"{label}.{name}.numerical_validation.passes", - ) - if numerical.get("point_count") != point_count or numerical.get( - "point_seeds" - ) != list(_FOUR_QUARK_POINT_SEEDS[:point_count]): - raise AcceptanceError(f"{label}.{name} numerical request drifted") - expected_comparisons = set(_FOUR_QUARK_BASE_COMPARISONS) - if not contracted: - expected_comparisons.add("color_selector_evaluate_vs_resolved_total") - _require_comparison_mapping( - numerical.get("comparisons"), - label=f"{label}.{name}.comparisons", - expected_names=expected_comparisons, - ) - execution = _mapping( - numerical.get("runtime_execution"), - label=f"{label}.{name}.runtime_execution", - ) - if execution.get("execution_mode") != "compiled": - raise AcceptanceError(f"{label}.{name} did not execute compiled mode") - profiles = _mapping( - execution.get("direct_arena_profiles"), - label=f"{label}.{name}.direct_arena_profiles", - ) - expected_profiles = {"complete", "helicity_selector"} - if not contracted: - expected_profiles.update({"color_selector", "combined_selector"}) - if set(profiles) != expected_profiles: - raise AcceptanceError(f"{label}.{name} profile coverage is incomplete") - for profile_name, raw_profile in profiles.items(): - profile = _mapping( - raw_profile, - label=f"{label}.{name}.profiles.{profile_name}", - ) - _require_true( - profile.get("passes"), - label=f"{label}.{name}.profiles.{profile_name}.passes", - ) - _require_positive_int( - profile.get("compiled_direct_arena_engine_count"), - label=f"{label}.{name}.{profile_name}.engines", - ) - _require_positive_int( - profile.get("compiled_direct_arena_call_count"), - label=f"{label}.{name}.{profile_name}.calls", - ) - if profile.get("legacy_boundary_component_total") != 0: - raise AcceptanceError( - f"{label}.{name}.{profile_name} used a legacy boundary" - ) - cross = _mapping( - payload.get("lc_cross_layout_parity"), - label=f"{label}.lc_cross_layout_parity", - ) - _require_true(cross.get("passes"), label=f"{label}.LC cross-layout passes") - _require_true( - cross.get("physical_axes_match"), - label=f"{label}.LC physical axes match", - ) - _require_comparison_mapping( - cross.get("comparisons"), - label=f"{label}.LC cross-layout comparisons", - expected_names=_CROSS_LC_COMPARISONS, - ) - return { - "kind": FOUR_QUARK_KIND, - "schema_version": SCHEMA_VERSION, - "point_count": point_count, - "independent_quark_line_count": 4, - "lanes": sorted(lanes), - "invalid_union_requests_rejected": sorted(rejected_colors), - "numerical_validation": True, - "passes": True, - } - - -def _require_pointwise_items(value: object, *, label: str) -> None: - items = _list(value, label=label) - if not items: - raise AcceptanceError(f"{label} must not be empty") - for index, item in enumerate(items): - comparison = _mapping(item, label=f"{label}[{index}]") - _require_true(comparison.get("passes"), label=f"{label}[{index}].passes") - - -def _validate_correctness( - value: object, - *, - label: str, - require_specialized: bool, -) -> None: - correctness = _mapping(value, label=label) - expected_fields = set(_CORRECTNESS_FIELDS) - if require_specialized: - expected_fields.add("specialized_compiled") - if set(correctness) != expected_fields: - raise AcceptanceError(f"{label} has incomplete numerical fields") - _require_true(correctness.get("passes"), label=f"{label}.passes") - for name in ("total", "eager_resolved_sum", "compiled_resolved_sum"): - _require_pointwise_items(correctness.get(name), label=f"{label}.{name}") - for name in ("resolved_f64", "resolved_precision32"): - resolved = _mapping(correctness.get(name), label=f"{label}.{name}") - _require_true(resolved.get("passes"), label=f"{label}.{name}.passes") - _require_positive_int( - resolved.get("point_count"), - label=f"{label}.{name}.point_count", - ) - _require_positive_int( - resolved.get("component_count"), - label=f"{label}.{name}.component_count", - ) - for match_field in ( - "helicity_ids_match", - "color_ids_match", - "shape_matches", - ): - _require_true( - resolved.get(match_field), - label=f"{label}.{name}.{match_field}", - ) - if require_specialized: - _validate_correctness( - correctness.get("specialized_compiled"), - label=f"{label}.specialized_compiled", - require_specialized=False, - ) - - -def _validate_color_matrix( - payload: Mapping[str, object], - *, - expected_revision: str, - expected_runtime: Mapping[str, object] | None = None, -) -> dict[str, object]: - label = "eager/compiled color matrix" - if ( - payload.get("kind") != COLOR_MATRIX_KIND - or payload.get("schema_version") != COLOR_MATRIX_SCHEMA_VERSION - or payload.get("suite") != "smoke" - ): - raise AcceptanceError(f"{label} has the wrong kind, schema, or suite") - _require_true(payload.get("complete"), label=f"{label}.complete") - _require_true(payload.get("passes"), label=f"{label}.passes") - if payload.get("source_revision") != expected_revision: - raise AcceptanceError(f"{label} came from another source revision") - if expected_runtime is not None: - interpreter = _mapping( - expected_runtime.get("interpreter"), - label="acceptance runtime identity.interpreter", - ) - observed_platform = payload.get("platform") - if ( - payload.get("python") != interpreter.get("python_version") - or not isinstance(observed_platform, str) - or "Linux" not in observed_platform - or "x86_64" not in observed_platform - ): - raise AcceptanceError(f"{label} did not run on the candidate x86 host") - configuration = _mapping( - payload.get("configuration"), - label=f"{label}.configuration", - ) - expected_configuration = { - "batch_sizes": [128, 1024], - "colors": ["lc", "nlc", "full"], - "generation_timeout": 300.0, - "memory_limit_gib": 30.0, - "minimum_samples": 5, - "target_runtime": 5.0, - "selector_target_runtime": 1.0, - "selector_seed": 0xC0FFEE, - } - if dict(configuration) != expected_configuration: - raise AcceptanceError(f"{label} request configuration drifted") - gates = _mapping(payload.get("gates"), label=f"{label}.gates") - if set(gates) != _COLOR_MATRIX_GATES: - raise AcceptanceError(f"{label} hard-gate coverage is incomplete") - for name, value in gates.items(): - _require_true(value, label=f"{label}.gates.{name}") - records = _list(payload.get("records"), label=f"{label}.records") - expected_cells = { - (case, "built-in", color) for case in _SMOKE_CASES for color in _COLORS - } - observed_cells: set[tuple[str, str, str]] = set() - workload_count = 0 - for index, raw_record in enumerate(records): - record_label = f"{label}.records[{index}]" - record = _mapping(raw_record, label=record_label) - case = _mapping(record.get("case"), label=f"{record_label}.case") - case_key = case.get("key") - model = record.get("model") - color = record.get("color") - if not all(isinstance(value, str) for value in (case_key, model, color)): - raise AcceptanceError(f"{record_label} cell identity is invalid") - cell = (str(case_key), str(model), str(color)) - if cell not in expected_cells or cell in observed_cells: - raise AcceptanceError(f"{record_label} is unexpected or duplicated") - observed_cells.add(cell) - expected_process, expected_n_final = _SMOKE_CASES[str(case_key)] - if ( - case.get("process") != expected_process - or case.get("n_final") != expected_n_final - or case.get("smoke") is not True - ): - raise AcceptanceError(f"{record_label} process metadata drifted") - _require_nonempty_string( - record.get("process_id"), - label=f"{record_label}.process_id", - ) - _require_true( - record.get("compiled_generation_under_hard_limit"), - label=f"{record_label}.compiled_generation_under_hard_limit", - ) - generation = _mapping( - record.get("generation"), - label=f"{record_label}.generation", - ) - if set(generation) != {"compiled", "eager"}: - raise AcceptanceError(f"{record_label} generation coverage is incomplete") - for mode, raw_generation in generation.items(): - mode_generation = _mapping( - raw_generation, - label=f"{record_label}.generation.{mode}", - ) - core_seconds = mode_generation.get("core_phase_seconds") - if ( - isinstance(core_seconds, bool) - or not isinstance(core_seconds, (int, float)) - or float(core_seconds) <= 0 - ): - raise AcceptanceError( - f"{record_label}.generation.{mode} has no core timing" - ) - workloads = _list( - record.get("workloads"), - label=f"{record_label}.workloads", - ) - expected_workloads = ( - {"single-flow-helicity-sum", "all-flow-single-helicity"} - if color == "lc" - else {"summed"} - ) - if {workload.get("name") for workload in workloads} != expected_workloads: - raise AcceptanceError(f"{record_label} workload scope is incomplete") - if len(workloads) != len(expected_workloads): - raise AcceptanceError(f"{record_label} contains duplicate workloads") - for workload_index, raw_workload in enumerate(workloads): - workload_count += 1 - workload_label = f"{record_label}.workloads[{workload_index}]" - workload = _mapping(raw_workload, label=workload_label) - _validate_correctness( - workload.get("correctness"), - label=f"{workload_label}.correctness", - require_specialized=color == "lc", - ) - profiles = _list( - workload.get("profiles"), - label=f"{workload_label}.profiles", - ) - if {profile.get("batch_size") for profile in profiles} != {128, 1024}: - raise AcceptanceError(f"{workload_label} batch coverage is incomplete") - if len(profiles) != 2: - raise AcceptanceError(f"{workload_label} contains duplicate batches") - expected_profile_modes = {"compiled_complete", "eager_complete"} - if color == "lc": - expected_profile_modes.add("compiled_specialized") - for profile_index, raw_profile in enumerate(profiles): - profile_label = f"{workload_label}.profiles[{profile_index}]" - profile = _mapping(raw_profile, label=profile_label) - batch_size = profile.get("batch_size") - for mode in expected_profile_modes: - timing = _mapping( - profile.get(mode), - label=f"{profile_label}.{mode}", - ) - result = _mapping( - timing.get("result"), - label=f"{profile_label}.{mode}.result", - ) - sample_count = _require_positive_int( - result.get("sample_count"), - label=f"{profile_label}.{mode}.result.sample_count", - ) - wall = result.get("wall_time_per_point") - if ( - sample_count < 1 - or isinstance(wall, bool) - or not isinstance(wall, (int, float)) - or not math.isfinite(float(wall)) - or float(wall) < 0 - or result.get("interrupted") is not False - ): - raise AcceptanceError( - f"{profile_label}.{mode} runtime profile is invalid" - ) - effective = _mapping( - result.get("effective_config"), - label=f"{profile_label}.{mode}.result.effective_config", - ) - if effective.get("batch_size") != batch_size: - raise AcceptanceError( - f"{profile_label}.{mode} profiled another batch size" - ) - selector_profiles = record.get("selector_pattern_profiles") - if color == "lc": - selectors = _mapping( - selector_profiles, - label=f"{record_label}.selector_pattern_profiles", - ) - if set(selectors) != {"compiled", "eager"}: - raise AcceptanceError( - f"{record_label} selector-profile coverage is incomplete" - ) - for mode, raw_profile in selectors.items(): - profile = _mapping( - raw_profile, - label=f"{record_label}.selector_pattern_profiles.{mode}", - ) - result = _mapping( - profile.get("result"), - label=f"{record_label}.selector_pattern_profiles.{mode}.result", - ) - _require_true( - result.get("passes"), - label=( - f"{record_label}.selector_pattern_profiles.{mode}.result.passes" - ), - ) - elif selector_profiles is not None: - raise AcceptanceError( - f"{record_label} contracted color has unexpected selector profiles" - ) - if observed_cells != expected_cells or len(records) != len(expected_cells): - raise AcceptanceError(f"{label} matrix cell scope is incomplete") - return { - "kind": COLOR_MATRIX_KIND, - "schema_version": COLOR_MATRIX_SCHEMA_VERSION, - "suite": "smoke", - "cells": [ - {"case": case, "model": model, "color": color} - for case, model, color in sorted(observed_cells) - ], - "cell_count": len(observed_cells), - "workload_count": workload_count, - "hard_gates": sorted(gates), - "numerical_validation": True, - "passes": True, - } - - -def _validate_preflight( - payload: Mapping[str, object], - *, - expected_revision: str, - expected_workspace: Path, -) -> tuple[Mapping[str, object], Mapping[str, object]]: - label = "runtime preflight" - _require_content_identity(payload, label=label) - if ( - payload.get("kind") != PREFLIGHT_KIND - or payload.get("schema_version") != SCHEMA_VERSION - or payload.get("status") != "ok" - ): - raise AcceptanceError(f"{label} has the wrong kind, schema, or status") - _require_true(payload.get("passes"), label=f"{label}.passes") - if payload.get("failures") != []: - raise AcceptanceError(f"{label} contains failures") - request = _mapping(payload.get("request"), label=f"{label}.request") - expected_request = { - "expected_revision": expected_revision, - "expected_workspace": str(expected_workspace.resolve(strict=True)), - "expected_target": EXPECTED_TARGET, - } - if dict(request) != expected_request: - raise AcceptanceError(f"{label} request drifted") - source = _mapping(payload.get("source_identity"), label=f"{label}.source_identity") - source_postflight = _mapping( - payload.get("source_identity_postflight"), - label=f"{label}.source_identity_postflight", - ) - _require_true(payload.get("source_identity_match"), label=f"{label}.source match") - if dict(source) != dict(source_postflight): - raise AcceptanceError(f"{label} source identity changed") - if ( - source.get("revision") != expected_revision - or source.get("checkout") != str(expected_workspace.resolve(strict=True)) - or source.get("dirty") is not False - or source.get("untracked_files_checked") is not True - ): - raise AcceptanceError(f"{label} source identity is not exact") - runtime = _mapping( - payload.get("runtime_identity"), - label=f"{label}.runtime_identity", - ) - runtime_postflight = _mapping( - payload.get("runtime_identity_postflight"), - label=f"{label}.runtime_identity_postflight", - ) - _require_true(payload.get("runtime_identity_match"), label=f"{label}.runtime match") - if _stable_runtime_identity(runtime) != _stable_runtime_identity( - runtime_postflight - ): - raise AcceptanceError(f"{label} runtime identity changed") - if payload.get("stable_runtime_identity_sha256") != _runtime_identity_sha256( - runtime - ): - raise AcceptanceError(f"{label} stable runtime identity digest is invalid") - platform_identity = _mapping( - runtime.get("platform"), - label=f"{label}.runtime_identity.platform", - ) - if platform_identity.get("target") != EXPECTED_TARGET: - raise AcceptanceError(f"{label} has the wrong native target") - return source, runtime - - -def _preflight( - *, - evidence_root: Path, - expected_revision: str, - expected_workspace: Path, -) -> dict[str, object]: - root = _evidence_root(evidence_root) - destination = root / PREFLIGHT_FILENAME - _remove_stale_file(destination) - _remove_stale_file(root / ACCEPTANCE_FILENAME) - source = _source_identity( - expected_revision=expected_revision, - expected_workspace=expected_workspace, - ) - runtime = _runtime_identity(source) - source_postflight = _source_identity( - expected_revision=expected_revision, - expected_workspace=expected_workspace, - ) - runtime_postflight = _runtime_identity(source_postflight) - if source_postflight != source: - raise AcceptanceError("source identity changed during native-x86 preflight") - if _stable_runtime_identity(runtime_postflight) != _stable_runtime_identity( - runtime - ): - raise AcceptanceError("runtime identity changed during native-x86 preflight") - payload = _attach_content_identity( - { - "kind": PREFLIGHT_KIND, - "schema_version": SCHEMA_VERSION, - "status": "ok", - "passes": True, - "request": { - "expected_revision": expected_revision, - "expected_workspace": str(expected_workspace.resolve(strict=True)), - "expected_target": EXPECTED_TARGET, - }, - "source_identity": source, - "source_identity_postflight": source_postflight, - "source_identity_match": True, - "runtime_identity": runtime, - "runtime_identity_postflight": runtime_postflight, - "runtime_identity_match": True, - "stable_runtime_identity_sha256": _runtime_identity_sha256(runtime), - "failures": [], - } - ) - _write_json_atomic(destination, payload) - return payload - - -def _audit( - *, - evidence_root: Path, - expected_revision: str, - expected_workspace: Path, - point_count: int, -) -> dict[str, object]: - root = _evidence_root(evidence_root) - destination = root / ACCEPTANCE_FILENAME - _remove_stale_file(destination) - source = _source_identity( - expected_revision=expected_revision, - expected_workspace=expected_workspace, - ) - runtime = _runtime_identity(source) - - preflight, preflight_file = _checked_json( - root / PREFLIGHT_FILENAME, - label="runtime preflight evidence", - ) - preflight_source, preflight_runtime = _validate_preflight( - preflight, - expected_revision=expected_revision, - expected_workspace=expected_workspace, - ) - if dict(preflight_source) != source: - raise AcceptanceError("source identity differs from the preflight") - if _stable_runtime_identity(preflight_runtime) != _stable_runtime_identity(runtime): - raise AcceptanceError("runtime identity differs from the preflight") - - all_jit, all_jit_file = _checked_json( - root / ALL_JIT_RELATIVE_PATH, - label="all-JIT evidence", - ) - all_jit_summary = _validate_all_jit( - all_jit, - expected_revision=expected_revision, - expected_workspace=expected_workspace, - point_count=point_count, - expected_runtime=runtime, - ) - four_quark, four_quark_file = _checked_json( - root / FOUR_QUARK_RELATIVE_PATH, - label="four-quark evidence", - ) - four_quark_summary = _validate_four_quark( - four_quark, - expected_revision=expected_revision, - expected_workspace=expected_workspace, - point_count=point_count, - expected_runtime=runtime, - ) - color_matrix, color_matrix_file = _checked_json( - root / COLOR_MATRIX_RELATIVE_PATH, - label="eager/compiled color matrix evidence", - ) - color_matrix_summary = _validate_color_matrix( - color_matrix, - expected_revision=expected_revision, - expected_runtime=runtime, - ) - - source_postflight = _source_identity( - expected_revision=expected_revision, - expected_workspace=expected_workspace, - ) - runtime_postflight = _runtime_identity(source_postflight) - if source_postflight != source: - raise AcceptanceError("source identity changed during final evidence audit") - if _stable_runtime_identity(runtime_postflight) != _stable_runtime_identity( - runtime - ): - raise AcceptanceError("runtime identity changed during final evidence audit") - payload = _attach_content_identity( - { - "kind": ACCEPTANCE_KIND, - "schema_version": SCHEMA_VERSION, - "status": "ok", - "passes": True, - "request": { - "expected_revision": expected_revision, - "expected_workspace": str(expected_workspace.resolve(strict=True)), - "expected_target": EXPECTED_TARGET, - "point_count": point_count, - "required_evidence": { - "runtime_preflight": PREFLIGHT_FILENAME, - "compiled_all_jit": ALL_JIT_RELATIVE_PATH.as_posix(), - "four_quark": FOUR_QUARK_RELATIVE_PATH.as_posix(), - "eager_compiled_color": COLOR_MATRIX_RELATIVE_PATH.as_posix(), - }, - }, - "source_identity": { - "preflight": dict(preflight_source), - "audit": source, - "postflight": source_postflight, - "all_match": True, - }, - "runtime_identity": { - "stable_sha256": _runtime_identity_sha256(runtime), - "preflight_stable_sha256": _runtime_identity_sha256(preflight_runtime), - "audit": runtime, - "postflight": runtime_postflight, - "all_match": True, - }, - "evidence": { - "runtime_preflight": { - "file_identity": preflight_file, - "semantic_validation": { - "kind": PREFLIGHT_KIND, - "schema_version": SCHEMA_VERSION, - "passes": True, - }, - }, - "compiled_all_jit": { - "file_identity": all_jit_file, - "semantic_validation": all_jit_summary, - }, - "four_quark": { - "file_identity": four_quark_file, - "semantic_validation": four_quark_summary, - }, - "eager_compiled_color": { - "file_identity": color_matrix_file, - "semantic_validation": color_matrix_summary, - }, - }, - "validation": { - "exact_source_revision": True, - "source_clean_preflight_and_postflight": True, - "source_only_python_runtime": True, - "native_linux_x86_64_target": True, - "runtime_preimport_bytes_unchanged": True, - "candidate_wheel_matches_loaded_runtime": True, - "compiled_all_jit_numerical_gate": True, - "four_quark_all_valid_color_lanes_numerical_gate": True, - "eager_compiled_full_smoke_color_matrix_numerical_gate": True, - "all_evidence_files_content_bound": True, - }, - "failures": [], - } - ) - _write_json_atomic(destination, payload) - return payload - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - subparsers = result.add_subparsers(dest="command", required=True) - for command in ("preflight", "audit"): - child = subparsers.add_parser(command) - child.add_argument("--evidence-root", type=Path, required=True) - child.add_argument("--expected-revision", required=True) - child.add_argument("--expected-workspace", type=Path, required=True) - if command == "audit": - child.add_argument( - "--point-count", - type=int, - choices=(2, 3), - default=EXPECTED_POINT_COUNT, - ) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - _ensure_source_only_python() - _establish_preimport_runtime_identity() - arguments = parser().parse_args(argv) - try: - if arguments.command == "preflight": - payload = _preflight( - evidence_root=arguments.evidence_root, - expected_revision=arguments.expected_revision, - expected_workspace=arguments.expected_workspace, - ) - else: - payload = _audit( - evidence_root=arguments.evidence_root, - expected_revision=arguments.expected_revision, - expected_workspace=arguments.expected_workspace, - point_count=arguments.point_count, - ) - except (AcceptanceError, OSError, RuntimeError, ValueError) as error: - print(f"arena-native-x86-acceptance: {error}", file=sys.stderr) - return 2 - print(json.dumps(payload, allow_nan=False, sort_keys=True)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/catalog_final_source_structural_preflight.py b/pyamplicol/tools/developer/catalog_final_source_structural_preflight.py deleted file mode 100644 index 826e727396..0000000000 --- a/pyamplicol/tools/developer/catalog_final_source_structural_preflight.py +++ /dev/null @@ -1,477 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Assemble and authenticate the all-catalog final-source restart manifest. - -This producer is intentionally structural-only: it never benchmarks or derives -proof claims from timings. Each successful candidate artifact must contain a -``structural-preflight-proof.json`` emitted by generation, and each comparable -legacy artifact must contain ``legacy-structural-proof.json`` emitted by the -legacy probe. The producer authenticates those sidecars against their source -revision and every persisted object before assembling the exact 1,356 rows -consumed by :mod:`tools.developer.catalog_restart_parity_gate`. - -Missing sidecars are reported as missing producer hooks. Counts or digests are -never guessed from a summary. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import re -from pathlib import Path -from typing import Any - -from pyamplicol.artifacts import load_manifest -from pyamplicol.generation.structural_source_proof import ( - ROLE as STRUCTURAL_SOURCE_PROOF_ROLE, -) -from pyamplicol.generation.structural_source_proof import ( - validate_generation_structural_proof, -) -from tools.developer.catalog_restart_parity_gate import SCHEMA -from tools.developer.catalog_structural_parity_audit import ( - CatalogParityError, - _candidate_counts, - _load_currents, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ExecutionMode, ResultStatus - -CELL_PROOF_SCHEMA = "pyamplicol-cell-final-source-structural-proof-v1" -LEGACY_PROOF_SCHEMA = "pyamplicol-legacy-final-structural-proof-v1" -_SHA256 = re.compile(r"[0-9a-f]{64}") -_REVISION = re.compile(r"[0-9a-f]{40}") -_MODES = { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, -} - - -class FinalSourceProducerError(RuntimeError): - """Exact restart evidence is absent, stale, or unauthenticated.""" - - -def _read(path: Path) -> dict[str, Any]: - try: - value = json.loads(path.read_text()) - except (OSError, json.JSONDecodeError) as error: - raise FinalSourceProducerError(f"cannot read {path}: {error}") from error - if not isinstance(value, dict): - raise FinalSourceProducerError(f"{path} must contain a JSON object") - return value - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - while chunk := stream.read(1024 * 1024): - digest.update(chunk) - return digest.hexdigest() - - -def _artifact(result: dict[str, Any], cell_id: str) -> Path: - artifact = result.get("artifact") - raw = artifact.get("path") if isinstance(artifact, dict) else None - if not isinstance(raw, str) or not raw: - raise FinalSourceProducerError(f"{cell_id}: result has no artifact path") - path = Path(raw) - if not path.is_dir(): - raise FinalSourceProducerError(f"{cell_id}: artifact is absent: {path}") - return path - - -def _counts(value: object, label: str) -> dict[str, int]: - if not isinstance(value, dict): - raise FinalSourceProducerError(f"{label} must be an object") - fields = ( - "source_current_count", - "produced_current_count", - "kernel_evaluation_count", - "attachment_count", - "amplitude_destination_count", - ) - output: dict[str, int] = {} - for field in fields: - item = value.get(field) - if not isinstance(item, int) or isinstance(item, bool) or item < 0: - raise FinalSourceProducerError( - f"{label}.{field} must be a non-negative integer" - ) - output[field] = item - if output["source_current_count"] + output["produced_current_count"] <= 0: - raise FinalSourceProducerError(f"{label} has no logical currents") - return output - - -def _proof_digest_fields(value: object, label: str) -> dict[str, Any]: - if not isinstance(value, dict): - raise FinalSourceProducerError(f"{label} is absent") - output = dict(value) - for field in ( - "current_member_map_sha256", - "interaction_row_map_sha256", - "closure_map_sha256", - "source_contract_sha256", - ): - item = output.get(field) - if not isinstance(item, str) or _SHA256.fullmatch(item) is None: - raise FinalSourceProducerError(f"{label}.{field} is not exact") - return output - - -def _authenticate_evidence_files( - artifact: Path, - value: object, - *, - label: str, -) -> None: - if not isinstance(value, list) or not value: - raise FinalSourceProducerError(f"{label} evidence-file inventory is absent") - root = artifact.resolve() - for index, raw in enumerate(value): - if not isinstance(raw, dict): - raise FinalSourceProducerError( - f"{label} evidence file {index} is malformed" - ) - relative = raw.get("path") - expected = raw.get("sha256") - if ( - not isinstance(relative, str) - or not relative - or not isinstance(expected, str) - or _SHA256.fullmatch(expected) is None - ): - raise FinalSourceProducerError(f"{label} evidence file {index} is invalid") - path = (artifact / relative).resolve() - try: - path.relative_to(root) - except ValueError as error: - raise FinalSourceProducerError( - f"{label} evidence file escapes artifact: {relative}" - ) from error - if not path.is_file() or _sha256(path) != expected: - raise FinalSourceProducerError( - f"{label} evidence file is absent or changed: {relative}" - ) - - -def _candidate_record( - cell: Any, - result: dict[str, Any], - revision: str, -) -> dict[str, Any]: - if result.get("status") != ResultStatus.OK.value: - raise FinalSourceProducerError(f"{cell.cell_id}: candidate current is not ok") - artifact = _artifact(result, cell.cell_id) - proof_path = artifact / "structural-preflight-proof.json" - if not proof_path.is_file(): - raise FinalSourceProducerError( - f"{cell.cell_id}: missing generation hook {proof_path.name}" - ) - proof = _read(proof_path) - if ( - proof.get("schema") != CELL_PROOF_SCHEMA - or proof.get("cell_id") != cell.cell_id - or proof.get("source_revision") != revision - or proof.get("color_accuracy") != cell.measurement.accuracy.value - or proof.get("workload") != cell.workload.value - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: structural proof is stale or has wrong identity" - ) - manifest = load_manifest(artifact) - artifact_identity = proof.get("artifact_identity") - if ( - not isinstance(artifact_identity, dict) - or artifact_identity.get("artifact_id") != manifest.artifact_id - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: cell proof artifact identity is stale" - ) - structural_records = [ - record - for record in manifest.payloads - if record.role == STRUCTURAL_SOURCE_PROOF_ROLE - and record.process_id == artifact_identity.get("process_id") - ] - if len(structural_records) != 1: - raise FinalSourceProducerError( - f"{cell.cell_id}: generation structural proof payload is ambiguous" - ) - structural_record = structural_records[0] - if ( - artifact_identity.get("structural_proof_path") != structural_record.path - or artifact_identity.get("structural_proof_sha256") != structural_record.sha256 - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: generation structural proof identity is stale" - ) - generation_proof = _read(artifact / structural_record.path) - producer_native_inputs = manifest.producer.get("native_build_inputs_sha256") - if not isinstance(producer_native_inputs, str): - raise FinalSourceProducerError( - f"{cell.cell_id}: artifact native-input identity is absent" - ) - try: - authenticated_generation_proof = validate_generation_structural_proof( - generation_proof, - artifact_root=artifact, - expected_process_id=str(artifact_identity["process_id"]), - expected_source_revision=revision, - expected_native_build_inputs_sha256=producer_native_inputs, - ) - except ValueError as error: - raise FinalSourceProducerError( - f"{cell.cell_id}: generation structural proof does not recompute" - ) from error - if ( - proof.get("persisted_lane_inventory") - != (authenticated_generation_proof["physical_lane_inventory"]) - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: cell proof changed the generation lane inventory" - ) - candidate = _candidate_counts(result, workload=cell.workload) - if candidate.source_revision != revision: - raise FinalSourceProducerError( - f"{cell.cell_id}: measured source is not the final source revision" - ) - phases = { - name: _counts(proof.get(name), f"{cell.cell_id} candidate.{name}") - for name in ("active", "final_materialized", "peak_materialized") - } - expected = { - "active": (candidate.active, candidate.active_closure_count), - "final_materialized": ( - candidate.final_materialized, - candidate.final_materialized_closure_count, - ), - "peak_materialized": ( - candidate.peak_materialized, - candidate.peak_materialized_closure_count, - ), - } - for name, (structural, closure_count) in expected.items(): - phase = phases[name] - if ( - phase["source_current_count"] + phase["produced_current_count"] - != structural.current_count - or phase["kernel_evaluation_count"] != structural.evaluation_count - or phase["attachment_count"] != structural.attachment_count - or ( - closure_count is not None - and phase["amplitude_destination_count"] != closure_count - ) - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: {name} proof disagrees with runtime structure" - ) - semantic = _proof_digest_fields( - proof.get("semantic_proof"), - f"{cell.cell_id} semantic proof", - ) - if ( - semantic.get("status") != "proven" - or semantic.get("strength") not in {"exact-symbolic", "exact-reconstructed"} - or semantic.get("source_revision") != revision - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: semantic proof is not exact and source-bound" - ) - numerical = proof.get("numerical_validation") - if ( - not isinstance(numerical, dict) - or numerical.get("status") != "ok" - or not isinstance(numerical.get("precision_decimal_digits"), int) - or numerical["precision_decimal_digits"] < 50 - or not isinstance(numerical.get("comparison_sha256"), str) - or _SHA256.fullmatch(numerical["comparison_sha256"]) is None - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: precision>=50 numerical proof hook is missing" - ) - return { - "source_revision": revision, - "evidence_root": str(artifact.resolve()), - "artifact_identity": artifact_identity, - **phases, - "semantic_proof": semantic, - "numerical_validation": numerical, - "generation_structural_proof": authenticated_generation_proof, - "persisted_lane_inventory": proof["persisted_lane_inventory"], - } - - -def _legacy_record(cell: Any, result: dict[str, Any] | None) -> dict[str, Any]: - if not REPORT_CATALOG.legacy_reference_available(cell): - return { - "scope": "unavailable", - "reason": "original-amplicol-open-quark-line-limit", - } - if result is None or result.get("status") != ResultStatus.OK.value: - raise FinalSourceProducerError( - f"{cell.cell_id}: authenticated legacy current is absent" - ) - artifact = _artifact(result, cell.cell_id) - path = artifact / "legacy-structural-proof.json" - if not path.is_file(): - raise FinalSourceProducerError( - f"{cell.cell_id}: missing legacy probe hook {path.name}" - ) - proof = _read(path) - if proof.get("schema") != LEGACY_PROOF_SCHEMA: - raise FinalSourceProducerError( - f"{cell.cell_id}: legacy structural proof schema is unsupported" - ) - provenance = result.get("provenance") - result_revision = ( - provenance.get("revision") if isinstance(provenance, dict) else None - ) - if ( - proof.get("cell_id") != cell.cell_id - or proof.get("accuracy") != cell.measurement.accuracy.value - or proof.get("workload") != cell.workload.value - or not isinstance(result_revision, str) - or _REVISION.fullmatch(result_revision) is None - or proof.get("source_revision") != result_revision - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: legacy structural proof is stale or has wrong identity" - ) - _authenticate_evidence_files( - artifact, - proof.get("evidence_files"), - label=f"{cell.cell_id} legacy", - ) - active = _counts(proof.get("active"), f"{cell.cell_id} legacy.active") - static = _counts(proof.get("static"), f"{cell.cell_id} legacy.static") - mapping = proof.get("object_mapping") - multiplicity = proof.get("row_multiplicity") - if not isinstance(mapping, dict) or mapping.get("status") != "exact": - raise FinalSourceProducerError( - f"{cell.cell_id}: exact legacy object mapping is absent" - ) - _proof_digest_fields( - { - "current_member_map_sha256": mapping.get("current_object_map_sha256"), - "interaction_row_map_sha256": mapping.get("kernel_term_map_sha256"), - "closure_map_sha256": mapping.get("combine_route_map_sha256"), - "source_contract_sha256": mapping.get("source_contract_sha256"), - }, - f"{cell.cell_id} legacy mapping", - ) - if ( - not isinstance(multiplicity, dict) - or multiplicity.get("status") != "exact" - or not isinstance(multiplicity.get("histogram_sha256"), str) - or _SHA256.fullmatch(multiplicity["histogram_sha256"]) is None - or ( - cell.workload.value == "contracted" - and ( - not isinstance(multiplicity.get("call_count"), int) - or multiplicity["call_count"] < 0 - ) - ) - ): - raise FinalSourceProducerError( - f"{cell.cell_id}: exact legacy row histogram is absent" - ) - return { - "scope": "available", - "active": active, - "static": static, - "object_mapping": mapping, - "row_multiplicity": multiplicity, - } - - -def produce( - artifact_root: Path, - *, - source_revision: str, -) -> dict[str, Any]: - if _REVISION.fullmatch(source_revision) is None: - raise FinalSourceProducerError("source revision must be a full Git SHA") - try: - currents = _load_currents(artifact_root) - except CatalogParityError as error: - raise FinalSourceProducerError(str(error)) from error - references = { - ( - cell.process_key, - cell.n_final, - cell.measurement.accuracy, - cell.workload, - ): cell - for cell in REPORT_CATALOG.reference_cells() - } - rows: list[dict[str, Any]] = [] - for cell in REPORT_CATALOG.matrix_cells(): - if cell.measurement.execution_mode not in _MODES: - continue - result = currents.get(cell.cell_id) - if result is None: - raise FinalSourceProducerError( - f"{cell.cell_id}: final-source candidate current is absent" - ) - reference = references[ - ( - cell.process_key, - cell.n_final, - cell.measurement.accuracy, - cell.workload, - ) - ] - comparable = REPORT_CATALOG.legacy_reference_available(cell) - rows.append( - { - "cell_id": cell.cell_id, - "process_key": cell.process_key, - "n_final": cell.n_final, - "mode": cell.measurement.execution_mode.value, - "model": cell.measurement.model.value, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "classification": ( - "certified-parity" if comparable else "legacy-scope-unavailable" - ), - "candidate": _candidate_record(cell, result, source_revision), - "legacy": _legacy_record(reference, currents.get(reference.cell_id)), - } - ) - if len(rows) != 1356: - raise FinalSourceProducerError( - f"catalog producer expected 1356 rows, generated {len(rows)}" - ) - return {"schema": SCHEMA, "source_revision": source_revision, "cells": rows} - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--artifact-root", type=Path, required=True) - parser.add_argument("--source-revision", required=True) - parser.add_argument("--output", type=Path, required=True) - return parser - - -def main() -> int: - args = _parser().parse_args() - try: - payload = produce( - args.artifact_root, - source_revision=args.source_revision, - ) - except FinalSourceProducerError as error: - print(f"final-source structural preflight unavailable: {error}") - return 2 - args.output.parent.mkdir(parents=True, exist_ok=True) - args.output.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n") - print(f"wrote {len(payload['cells'])} authenticated catalog rows") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/catalog_restart_parity_gate.py b/pyamplicol/tools/developer/catalog_restart_parity_gate.py deleted file mode 100644 index fdfa4d4c0e..0000000000 --- a/pyamplicol/tools/developer/catalog_restart_parity_gate.py +++ /dev/null @@ -1,665 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Fail-closed restart gate for a final-source structural parity preflight. - -This validator deliberately does not generate or optimize amplitudes. It is an -independent consumer of a final-source preflight manifest. In particular, it -does not trust a producer's summary boolean or precomputed ratios. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import re -from collections import Counter -from collections.abc import Mapping -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -from pyamplicol.artifacts import load_manifest -from pyamplicol.generation.structural_source_proof import ( - SEMANTIC_MAP_DOMAINS, - validate_generation_structural_proof, -) -from tools.developer.catalog_structural_scope_registry import ( - validate_reviewed_matrix_scope, -) -from tools.developer.final_source_numerical_truth import ( - TruthProducerError, - canonical_sha256, - validate_witness_payload, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ExecutionMode, Workload - -SCHEMA = "pyamplicol-final-source-structural-preflight-v1" -OUTPUT_SCHEMA = "pyamplicol-independent-restart-parity-gate-v1" -MAX_RATIO = 1.05 -_SHA256 = re.compile(r"[0-9a-f]{64}") -_REVISION = re.compile(r"[0-9a-f]{40}") -_EXACT_PROOF_STRENGTHS = {"exact-symbolic", "exact-reconstructed"} -_CANDIDATE_MODES = { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, -} - - -class RestartParityError(ValueError): - """The final-source preflight manifest is malformed.""" - - -@dataclass(frozen=True) -class Counts: - source_current_count: int - produced_current_count: int - kernel_evaluation_count: int - attachment_count: int - amplitude_destination_count: int - - @property - def logical_current_count(self) -> int: - return self.source_current_count + self.produced_current_count - - def add(self, other: Counts) -> Counts: - return Counts( - self.source_current_count + other.source_current_count, - self.produced_current_count + other.produced_current_count, - self.kernel_evaluation_count + other.kernel_evaluation_count, - self.attachment_count + other.attachment_count, - self.amplitude_destination_count + other.amplitude_destination_count, - ) - - -def _mapping(value: object, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise RestartParityError(f"{label} must be an object") - return value - - -def _array(value: object, label: str) -> list[Any]: - if not isinstance(value, list): - raise RestartParityError(f"{label} must be an array") - return value - - -def _text(value: object, label: str) -> str: - if not isinstance(value, str) or not value: - raise RestartParityError(f"{label} must be a non-empty string") - return value - - -def _digest(value: object, label: str) -> str: - text = _text(value, label) - if _SHA256.fullmatch(text) is None: - raise RestartParityError(f"{label} must be a lowercase SHA-256") - return text - - -def _revision(value: object, label: str) -> str: - text = _text(value, label) - if _REVISION.fullmatch(text) is None: - raise RestartParityError(f"{label} must be a full lowercase Git revision") - return text - - -def _count(value: object, label: str) -> int: - if not isinstance(value, int) or isinstance(value, bool) or value < 0: - raise RestartParityError(f"{label} must be a non-negative integer") - return value - - -def _counts(value: object, label: str) -> Counts: - payload = _mapping(value, label) - counts = Counts( - _count(payload.get("source_current_count"), f"{label}.source_current_count"), - _count( - payload.get("produced_current_count"), - f"{label}.produced_current_count", - ), - _count( - payload.get("kernel_evaluation_count"), - f"{label}.kernel_evaluation_count", - ), - _count(payload.get("attachment_count"), f"{label}.attachment_count"), - _count( - payload.get("amplitude_destination_count"), - f"{label}.amplitude_destination_count", - ), - ) - if counts.logical_current_count == 0: - raise RestartParityError(f"{label} has no logical currents") - return counts - - -def _candidate_cells() -> tuple[Any, ...]: - return tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode in _CANDIDATE_MODES - ) - - -def _identity_reasons(cell: Any, record: Mapping[str, Any]) -> list[str]: - expected = { - "process_key": cell.process_key, - "n_final": cell.n_final, - "mode": cell.measurement.execution_mode.value, - "model": cell.measurement.model.value, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - } - return [ - f"identity-{name}-mismatch" - for name, value in expected.items() - if record.get(name) != value - ] - - -def _proof_reasons( - candidate: Mapping[str, Any], - revision: str, - *, - cell: Any, -) -> list[str]: - reasons: list[str] = [] - try: - proof = _mapping(candidate.get("semantic_proof"), "candidate.semantic_proof") - if proof.get("status") != "proven": - reasons.append("semantic-proof-not-proven") - if proof.get("strength") not in _EXACT_PROOF_STRENGTHS: - reasons.append("semantic-proof-not-exact") - if proof.get("source_revision") != revision: - reasons.append("semantic-proof-source-revision-mismatch") - for field in ( - "current_member_map_sha256", - "interaction_row_map_sha256", - "closure_map_sha256", - "source_contract_sha256", - ): - _digest(proof.get(field), f"candidate.semantic_proof.{field}") - witnesses = _mapping( - proof.get("witnesses"), - "candidate.semantic_proof.witnesses", - ) - semantic_fields = { - "current_member_map": "current_member_map_sha256", - "interaction_row_map": "interaction_row_map_sha256", - "closure_map": "closure_map_sha256", - "source_contract": "source_contract_sha256", - } - content_identities: set[str] = set() - for witness_name, digest_name in semantic_fields.items(): - witness = witnesses.get(witness_name) - if not isinstance(witness, list) or not witness: - raise RestartParityError( - f"candidate.semantic_proof.witnesses.{witness_name} " - "must be a non-empty array" - ) - recomputed = canonical_sha256(f"{witness_name}-v1", witness) - if recomputed != proof.get(digest_name): - reasons.append(f"semantic-{witness_name}-digest-mismatch") - if recomputed in content_identities: - reasons.append("semantic-witness-content-identity-duplicate") - content_identities.add(recomputed) - except RestartParityError: - reasons.append("semantic-proof-incomplete") - - discovery = candidate.get("numerical_relation_discovery") - if discovery is not None: - try: - discovery_map = _mapping( - discovery, - "candidate.numerical_relation_discovery", - ) - if discovery_map.get("used_for_generation") is True: - if discovery_map.get("reconstructed_exact") is not True: - reasons.append("numerical-only-relation-used-for-generation") - else: - _digest( - discovery_map.get("exact_proof_sha256"), - "candidate.numerical_relation_discovery.exact_proof_sha256", - ) - except RestartParityError: - reasons.append("numerical-relation-discovery-malformed") - - try: - numerical = _mapping( - candidate.get("numerical_validation"), - "candidate.numerical_validation", - ) - validate_witness_payload( - numerical, - expected_source_revision=revision, - expected_cell_id=cell.cell_id, - expected_mode=cell.measurement.execution_mode.value, - expected_accuracy=cell.measurement.accuracy.value, - expected_workload=cell.workload.value, - ) - except (RestartParityError, TruthProducerError): - reasons.append("numerical-validation-incomplete") - return reasons - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - while chunk := stream.read(1024 * 1024): - digest.update(chunk) - return digest.hexdigest() - - -def _evidence_path(root: Path, relative: str) -> Path: - resolved_root = root.resolve() - path = (resolved_root / relative).resolve() - try: - path.relative_to(resolved_root) - except ValueError as error: - raise RestartParityError( - f"persisted object escapes evidence root: {relative}" - ) from error - return path - - -def _candidate_counts_and_inventory( - candidate: Mapping[str, Any], -) -> tuple[dict[str, Counts], list[str]]: - reasons: list[str] = [] - phases: dict[str, Counts] = {} - try: - for phase in ("active", "final_materialized", "peak_materialized"): - phases[phase] = _counts(candidate.get(phase), f"candidate.{phase}") - except RestartParityError: - return {}, ["candidate-structural-counts-incomplete"] - - try: - evidence_root = Path( - _text(candidate.get("evidence_root"), "candidate.evidence_root") - ) - if not evidence_root.is_dir(): - raise RestartParityError("candidate evidence root is absent") - artifact_identity = _mapping( - candidate.get("artifact_identity"), - "candidate.artifact_identity", - ) - artifact_id = _digest( - artifact_identity.get("artifact_id"), - "candidate.artifact_identity.artifact_id", - ) - process_id = _text( - artifact_identity.get("process_id"), - "candidate.artifact_identity.process_id", - ) - structural_path = _text( - artifact_identity.get("structural_proof_path"), - "candidate.artifact_identity.structural_proof_path", - ) - structural_sha = _digest( - artifact_identity.get("structural_proof_sha256"), - "candidate.artifact_identity.structural_proof_sha256", - ) - manifest = load_manifest(evidence_root) - if manifest.artifact_id != artifact_id: - reasons.append("candidate-artifact-identity-mismatch") - records = [ - record - for record in manifest.payloads - if record.path == structural_path and record.process_id == process_id - ] - if len(records) != 1 or records[0].sha256 != structural_sha: - reasons.append("generation-structural-proof-manifest-mismatch") - structural_file = _evidence_path(evidence_root, structural_path) - if not structural_file.is_file() or _sha256(structural_file) != structural_sha: - reasons.append("generation-structural-proof-content-mismatch") - generation_proof = _mapping( - candidate.get("generation_structural_proof"), - "candidate.generation_structural_proof", - ) - if _mapping( - candidate.get("persisted_lane_inventory"), - "candidate.persisted_lane_inventory", - ) != generation_proof.get("physical_lane_inventory"): - reasons.append("persisted-lane-inventory-not-generation-bound") - native_inputs = manifest.producer.get("native_build_inputs_sha256") - if not isinstance(native_inputs, str): - raise RestartParityError("candidate native-input identity is absent") - authenticated = validate_generation_structural_proof( - generation_proof, - artifact_root=evidence_root, - expected_process_id=process_id, - expected_source_revision=str(manifest.producer.get("git_revision")), - expected_native_build_inputs_sha256=native_inputs, - ) - generation_maps = _mapping( - authenticated.get("semantic_maps"), - "generation semantic maps", - ) - semantic = candidate.get("semantic_proof") - if isinstance(semantic, Mapping): - witnesses = semantic.get("witnesses") - if isinstance(witnesses, Mapping): - for name in SEMANTIC_MAP_DOMAINS: - generation_map = _mapping( - generation_maps.get(name), - f"generation semantic map {name}", - ) - if witnesses.get(name) != generation_map.get("rows") or ( - semantic.get(f"{name}_sha256") != generation_map.get("sha256") - ): - reasons.append(f"semantic-{name}-not-generation-bound") - numerical = candidate.get("numerical_validation") - if isinstance(numerical, Mapping): - numerical_candidate = numerical.get("candidate_artifact") - if isinstance(numerical_candidate, Mapping) and ( - numerical_candidate.get("artifact_id") != artifact_id - or numerical_candidate.get("structural_proof_sha256") != structural_sha - ): - reasons.append("numerical-validation-not-structural-proof-bound") - except (RestartParityError, ValueError, OSError): - reasons.append("persisted-lane-inventory-malformed") - return phases, reasons - - -def _legacy_counts( - legacy: Mapping[str, Any], - *, - workload: Workload, -) -> tuple[Counts, Counts, list[str]]: - reasons: list[str] = [] - try: - active = _counts(legacy.get("active"), "legacy.active") - static = _counts(legacy.get("static"), "legacy.static") - mapping = _mapping(legacy.get("object_mapping"), "legacy.object_mapping") - if mapping.get("status") != "exact": - reasons.append("legacy-object-mapping-not-exact") - for field in ( - "current_object_map_sha256", - "kernel_term_map_sha256", - "combine_route_map_sha256", - ): - _digest(mapping.get(field), f"legacy.object_mapping.{field}") - multiplicity = _mapping( - legacy.get("row_multiplicity"), - "legacy.row_multiplicity", - ) - if multiplicity.get("status") != "exact": - reasons.append("legacy-row-multiplicity-not-exact") - _digest( - multiplicity.get("histogram_sha256"), - "legacy.row_multiplicity.histogram_sha256", - ) - if workload is Workload.CONTRACTED and multiplicity.get("call_count") is None: - reasons.append("legacy-contracted-call-histogram-missing") - if workload is Workload.CONTRACTED: - _count( - multiplicity.get("call_count"), - "legacy.row_multiplicity.call_count", - ) - except RestartParityError: - return ( - Counts(0, 0, 0, 0, 0), - Counts(0, 0, 0, 0, 0), - ["legacy-structural-evidence-incomplete"], - ) - return active, static, reasons - - -def _phase_ratios(candidate: Counts, legacy: Counts) -> dict[str, float]: - values = { - "logical_current": ( - candidate.logical_current_count, - legacy.logical_current_count, - ), - "kernel_evaluation": ( - candidate.kernel_evaluation_count, - legacy.kernel_evaluation_count, - ), - "attachment": (candidate.attachment_count, legacy.attachment_count), - } - ratios: dict[str, float] = {} - for name, (numerator, denominator) in values.items(): - if denominator <= 0: - raise RestartParityError(f"legacy {name} budget is not positive") - ratio = numerator / denominator - if not math.isfinite(ratio): - raise RestartParityError(f"{name} ratio is not finite") - ratios[name] = ratio - return ratios - - -def _exception_reasons(record: Mapping[str, Any]) -> list[str]: - try: - exception = _mapping( - record.get("representation_exception"), - "representation_exception", - ) - if exception.get("status") != "reviewed": - return ["representation-exception-not-reviewed"] - _revision(exception.get("review_revision"), "exception.review_revision") - _digest(exception.get("object_mapping_sha256"), "exception.object_mapping") - _text(exception.get("reason"), "exception.reason") - return [] - except RestartParityError: - return ["representation-exception-incomplete"] - - -def _validate_row( - cell: Any, - record: Mapping[str, Any], - revision: str, -) -> dict[str, Any]: - reasons = _identity_reasons(cell, record) - classification = record.get("classification") - candidate = record.get("candidate") - if not isinstance(candidate, Mapping): - return { - "cell_id": cell.cell_id, - "classification": classification, - "status": "failed", - "reason_codes": sorted({*reasons, "candidate-evidence-missing"}), - "ratios": {}, - } - if candidate.get("source_revision") != revision: - reasons.append("candidate-source-revision-mismatch") - reasons.extend(_proof_reasons(candidate, revision, cell=cell)) - phases, inventory_reasons = _candidate_counts_and_inventory(candidate) - reasons.extend(inventory_reasons) - - legacy_available = REPORT_CATALOG.legacy_reference_available(cell) - ratios: dict[str, dict[str, float]] = {} - if not legacy_available: - if classification != "legacy-scope-unavailable": - reasons.append("legacy-scope-classification-mismatch") - legacy = record.get("legacy") - if not isinstance(legacy, Mapping) or legacy.get("reason") != ( - "original-amplicol-open-quark-line-limit" - ): - reasons.append("legacy-scope-unavailable-reason-missing") - else: - if classification not in { - "certified-parity", - "reviewed-representation-exception", - }: - reasons.append("comparable-row-not-classified") - legacy = record.get("legacy") - if not isinstance(legacy, Mapping) or legacy.get("scope") != "available": - reasons.append("legacy-evidence-missing") - else: - active, static, legacy_reasons = _legacy_counts( - legacy, - workload=cell.workload, - ) - reasons.extend(legacy_reasons) - if phases and not legacy_reasons: - try: - ratios = { - "active": _phase_ratios(phases["active"], active), - "final_materialized": _phase_ratios( - phases["final_materialized"], - static, - ), - "peak_materialized": _phase_ratios( - phases["peak_materialized"], - static, - ), - } - except RestartParityError: - reasons.append("structural-ratio-unavailable") - violations = [ - f"{phase}-{metric}-exceeds-1.05" - for phase, metrics in ratios.items() - for metric, ratio in metrics.items() - if ratio > MAX_RATIO - ] - if violations: - if classification == "reviewed-representation-exception": - reasons.extend(_exception_reasons(record)) - else: - reasons.extend(violations) - elif classification == "reviewed-representation-exception": - reasons.append("representation-exception-unnecessary") - - reason_codes = sorted(set(reasons)) - return { - "cell_id": cell.cell_id, - "classification": classification, - "status": "ok" if not reason_codes else "failed", - "reason_codes": reason_codes, - "ratios": ratios, - } - - -def validate_manifest( - payload: Mapping[str, Any], - *, - expected_revision: str, -) -> dict[str, Any]: - reviewed_scope = validate_reviewed_matrix_scope() - revision = _revision(expected_revision, "expected revision") - if payload.get("schema") != SCHEMA: - raise RestartParityError(f"manifest schema must be {SCHEMA!r}") - if payload.get("source_revision") != revision: - raise RestartParityError("manifest is not bound to the expected final revision") - records = _array(payload.get("cells"), "manifest cells") - by_id: dict[str, Mapping[str, Any]] = {} - duplicate_ids: set[str] = set() - for index, raw in enumerate(records): - record = _mapping(raw, f"manifest cell {index}") - cell_id = _text(record.get("cell_id"), f"manifest cell {index}.cell_id") - if cell_id in by_id: - duplicate_ids.add(cell_id) - by_id[cell_id] = record - - rows: list[dict[str, Any]] = [] - expected_ids: set[str] = set() - for cell in _candidate_cells(): - expected_ids.add(cell.cell_id) - record = by_id.get(cell.cell_id) - if record is None: - rows.append( - { - "cell_id": cell.cell_id, - "classification": None, - "status": "failed", - "reason_codes": ["missing-record"], - "ratios": {}, - } - ) - continue - row = _validate_row(cell, record, revision) - if cell.cell_id in duplicate_ids: - row["status"] = "failed" - row["reason_codes"] = sorted({*row["reason_codes"], "duplicate-record"}) - rows.append(row) - for cell_id in sorted(set(by_id) - expected_ids): - rows.append( - { - "cell_id": cell_id, - "classification": by_id[cell_id].get("classification"), - "status": "failed", - "reason_codes": ["unexpected-record"], - "ratios": {}, - } - ) - - rows_by_id = {str(row["cell_id"]): row for row in rows} - comparison_cells: dict[str, list[str]] = {} - for cell_id in expected_ids: - record = by_id.get(cell_id) - candidate = None if record is None else record.get("candidate") - numerical = ( - candidate.get("numerical_validation") - if isinstance(candidate, Mapping) - else None - ) - digest = ( - numerical.get("comparison_sha256") - if isinstance(numerical, Mapping) - else None - ) - if isinstance(digest, str) and _SHA256.fullmatch(digest) is not None: - comparison_cells.setdefault(digest, []).append(cell_id) - for duplicated in comparison_cells.values(): - if len(duplicated) < 2: - continue - for cell_id in duplicated: - row = rows_by_id[cell_id] - row["status"] = "failed" - row["reason_codes"] = sorted( - { - *row["reason_codes"], - "numerical-comparison-content-identity-duplicate", - } - ) - - failures = [row for row in rows if row["status"] != "ok"] - classifications = Counter( - str(row["classification"]) for row in rows if row["status"] == "ok" - ) - reason_counts = Counter( - reason for row in failures for reason in row["reason_codes"] - ) - return { - "schema": OUTPUT_SCHEMA, - "source_revision": revision, - "reviewed_out_of_catalog_scope": reviewed_scope, - "summary": { - "expected_cell_count": len(_candidate_cells()), - "reported_row_count": len(rows), - "passed_row_count": len(rows) - len(failures), - "failed_row_count": len(failures), - "classification_counts": dict(sorted(classifications.items())), - "failure_reason_counts": dict(sorted(reason_counts.items())), - "restart_ready": not failures, - }, - "rows": rows, - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--manifest", type=Path, required=True) - parser.add_argument("--expected-source-revision", required=True) - parser.add_argument("--output", type=Path, required=True) - return parser - - -def main() -> int: - args = _parser().parse_args() - payload = json.loads(args.manifest.read_text()) - result = validate_manifest( - _mapping(payload, "manifest"), - expected_revision=args.expected_source_revision, - ) - args.output.parent.mkdir(parents=True, exist_ok=True) - args.output.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n") - print(json.dumps(result["summary"], indent=2, sort_keys=True)) - return 0 if result["summary"]["restart_ready"] is True else 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/catalog_structural_parity_audit.py b/pyamplicol/tools/developer/catalog_structural_parity_audit.py deleted file mode 100644 index 9508800fce..0000000000 --- a/pyamplicol/tools/developer/catalog_structural_parity_audit.py +++ /dev/null @@ -1,1422 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Audit report-catalog structural work against original AmpliCol evidence. - -The performance report stores immutable per-cell artifacts. This tool reads -those artifacts without importing a native pyAmpliCol runtime and emits one -machine-readable row for every matrix candidate cell. It deliberately keeps -two comparisons separate: - -* active/dynamic work per phase-space point; -* final and peak static materialization during artifact generation. - -A candidate can beat AmpliCol dynamically while still materializing far more -work. Neither comparison is silently substituted for the other. -""" - -from __future__ import annotations - -import argparse -import json -import math -import re -from collections import Counter -from dataclasses import asdict, dataclass -from datetime import UTC, datetime -from pathlib import Path -from typing import Any - -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ExecutionMode, ResultStatus, Workload - - -class CatalogParityError(RuntimeError): - """The artifact tree cannot produce an authenticated census.""" - - -_MODULE_CURRENT = re.compile( - r"dimension\s*\(\s*1\s*:\s*\d+\s*,\s*(\d+)\s*\)\s*::\s*val_c\b", - re.IGNORECASE, -) -_MODULE_INTERACTION = re.compile( - r"dimension\s*\(\s*1\s*:\s*\d+\s*,\s*(\d+)\s*\)\s*::\s*int_c\b", - re.IGNORECASE, -) -_AFTER_FILTER = re.compile( - r"Total number of currents, vertices and amplitudes after filter" - r"\s+(\d+)\s+(\d+)\s+(\d+)", -) -_DIRECT_CURRENT = re.compile(r"AMPICOL_COLOR_PROBE_CURRENTS\s+(\d+)") -_DIRECT_INTERACTION = re.compile(r"AMPICOL_COLOR_PROBE_VERTICES\s+(\d+)") -_DIRECT_AMPLITUDE = re.compile(r"AMPICOL_COLOR_PROBE_AMPLITUDES\s+(\d+)") -_LIBRARY_CALL = re.compile( - r"AMPICOL_COLOR_PROBE_LIBRARY_CALLS\s+(\d+)\s+(\d+)\s+(\d+)" -) -_PROCESS_ROW = re.compile(r"group:(\d+):integral:(\d+)") -_SUBROUTINE = re.compile( - r"^\s*subroutine\s+(\w+)\b(.*?)^\s*end\s+subroutine\s+\1\b", - re.IGNORECASE | re.MULTILINE | re.DOTALL, -) -_EXTERNAL_CURRENT = re.compile( - r"call\s+ext_\w+\s*\(.*?val_c\s*\(\s*1\s*,\s*(\d+)\s*\).*?\)", - re.IGNORECASE | re.DOTALL, -) -_INT1_ARRAY = re.compile( - r"integer\s*,\s*parameter\s*,\s*dimension\s*\(([^)]*)\)\s*::\s*" - r"int1\s*=\s*(?:reshape\s*\(\s*)?\[\s*&?(.*?)\]" - r"(?:\s*,\s*shape\s*=\s*\[[^]]*\]\s*\))?", - re.IGNORECASE | re.DOTALL, -) -_COMBINE_SHAPE = re.compile(r"0:(\d+),(\d+)") - -MAX_RATIO = 1.05 -_DYNAMIC_COLOR_PROJECTION_ABI = ( - "pyamplicol-generic-dag-dynamic-color-projection-v2" -) -_PEAK_CONTRIBUTION_COUNT_SEMANTICS = "resident-pending-contributions-v1" - - -@dataclass(frozen=True) -class WorkCounts: - current_count: int - evaluation_count: int | None - attachment_count: int | None - - -@dataclass(frozen=True) -class LegacyObjectMapping: - """Exact generated-module mapping to the structural comparison objects.""" - - abi: str - declared_current_count: int - declared_interaction_count: int - source_current_count: int - produced_current_count: int - vertex_term_count: int - combine_route_count: int - current_ids_complete: bool - interaction_ids_complete: bool - contribution_references_complete: bool - - -@dataclass(frozen=True) -class LegacyCounts: - evidence_kind: str - active: WorkCounts | None - static: WorkCounts - generated_module_count: int - retained_amplitude_count: int | None - module_shapes: tuple[tuple[int, int], ...] - selected_module: str | None - selected_module_object_mapping: LegacyObjectMapping | None - limitation: str | None - - -@dataclass(frozen=True) -class CandidateCounts: - mode: str - active: WorkCounts - final_materialized: WorkCounts - peak_materialized: WorkCounts - active_evidence_kind: str - active_evidence_exact: bool - selector_certificate_available: bool - source_revision: str | None - active_closure_count: int | None - final_materialized_closure_count: int | None - peak_materialized_closure_count: int | None - - -def _read_json(path: Path) -> dict[str, Any]: - try: - payload = json.loads(path.read_text()) - except (OSError, json.JSONDecodeError) as error: - raise CatalogParityError(f"cannot read {path}: {error}") from error - if not isinstance(payload, dict): - raise CatalogParityError(f"JSON root is not an object: {path}") - return payload - - -def _positive(value: Any, label: str) -> int: - if not isinstance(value, int) or isinstance(value, bool) or value <= 0: - raise CatalogParityError(f"{label} must be a positive integer") - return value - - -def _optional_positive(value: Any, label: str) -> int | None: - if value is None: - return None - return _positive(value, label) - - -def _optional_nonnegative(value: Any, label: str) -> int | None: - if value is None: - return None - if not isinstance(value, int) or isinstance(value, bool) or value < 0: - raise CatalogParityError(f"{label} must be a nonnegative integer") - return value - - -def _require_bool(value: Any, label: str) -> bool: - if not isinstance(value, bool): - raise CatalogParityError(f"{label} must be boolean") - return value - - -def _compiled_execution_lanes( - execution: dict[str, Any], -) -> tuple[tuple[str, dict[str, Any]], ...]: - """Enumerate every physically persisted compiled DAG lane exactly once.""" - - lanes: list[tuple[str, dict[str, Any]]] = [] - seen: set[tuple[object, ...]] = set() - - def payload_paths(value: object) -> tuple[str, ...]: - paths: list[str] = [] - - def visit(item: object, field: str | None = None) -> None: - if isinstance(item, dict): - for key, child in item.items(): - visit(child, str(key)) - elif isinstance(item, list): - for child in item: - visit(child, field) - elif ( - isinstance(item, str) - and field is not None - and (field == "path" or field.endswith("_path")) - ): - paths.append(item) - - visit(value) - return tuple(sorted(set(paths))) - - def add(record: object, path: str) -> None: - if not isinstance(record, dict): - raise CatalogParityError(f"compiled execution lane {path} is malformed") - summary = record.get("dag_summary") - if not isinstance(summary, dict): - raise CatalogParityError( - f"compiled execution lane {path} lacks DAG summary" - ) - physical_paths = payload_paths(record.get("compiled")) - identity: tuple[object, ...] = ( - ("payloads", *physical_paths) - if physical_paths - else ("manifest-path", path) - ) - if identity in seen: - return - seen.add(identity) - lanes.append((path, record)) - helicity_sum = record.get("helicity_sum_execution") - if helicity_sum is not None: - add(helicity_sum, f"{path}.helicity_sum_execution") - for key in ("color_selector_executions", "helicity_selector_executions"): - raw = record.get(key, []) - if raw is None: - continue - if not isinstance(raw, list): - raise CatalogParityError(f"compiled {path}.{key} is malformed") - for index, wrapper in enumerate(raw): - if not isinstance(wrapper, dict): - raise CatalogParityError( - f"compiled {path}.{key}[{index}] is malformed" - ) - add(wrapper.get("execution"), f"{path}.{key}[{index}].execution") - - add(execution, "primary") - return tuple(lanes) - - -def _sum_compiled_materialization( - lanes: tuple[tuple[str, dict[str, Any]], ...], -) -> tuple[WorkCounts, int | None]: - summaries = [record["dag_summary"] for _path, record in lanes] - evaluations = [ - _optional_positive( - summary.get("interaction_evaluation_count"), - "compiled interaction evaluation count", - ) - for summary in summaries - ] - closures = [ - _optional_nonnegative( - summary.get("amplitude_root_count"), - "compiled amplitude-root count", - ) - for summary in summaries - ] - return ( - WorkCounts( - sum( - _positive(summary.get("current_count"), "compiled current count") - for summary in summaries - ), - ( - None - if any(value is None for value in evaluations) - else sum(value for value in evaluations if value is not None) - ), - sum( - _positive( - summary.get("interaction_count"), - "compiled interaction attachment count", - ) - for summary in summaries - ), - ), - ( - None - if any(value is None for value in closures) - else sum(value for value in closures if value is not None) - ), - ) - - -def _single_execution(artifact: Path) -> Path: - executions = sorted((artifact / "processes").glob("*/execution.json")) - if len(executions) != 1: - raise CatalogParityError( - f"{artifact} must contain one process execution; found {len(executions)}" - ) - return executions[0] - - -def _module_shape(path: Path) -> tuple[int, int]: - text = path.read_text() - current = _MODULE_CURRENT.search(text) - interaction = _MODULE_INTERACTION.search(text) - if current is None or interaction is None: - raise CatalogParityError(f"legacy module lacks val_c/int_c dimensions: {path}") - return int(current.group(1)), int(interaction.group(1)) - - -def _module_object_mapping(path: Path) -> LegacyObjectMapping: - """Prove val_c/int_c are the same objects counted by candidate schedules. - - Original AmpliCol's generated module stores external and produced currents - in ``val_c``. Every vertex term is stored in ``int_c`` and then referenced - by a current-combination routine. The proof below rejects sparse arrays or - dangling terms instead of treating a maximum array index as work. - """ - - text = path.read_text() - declared_currents, declared_interactions = _module_shape(path) - source_ids = {int(value) for value in _EXTERNAL_CURRENT.findall(text)} - produced_ids: set[int] = set() - vertex_term_ids: set[int] = set() - contribution_reference_ids: set[int] = set() - combine_route_count = 0 - - for match in _SUBROUTINE.finditer(text): - name = match.group(1).lower() - body = match.group(2) - array = _INT1_ARRAY.search(body) - if array is None: - continue - values = [int(value) for value in re.findall(r"\d+", array.group(2))] - if name.startswith("vertex_"): - vertex_term_ids.update(values) - continue - if not name.startswith("combine_currents"): - continue - shape = _COMBINE_SHAPE.fullmatch(array.group(1).replace(" ", "")) - if shape is None: - raise CatalogParityError( - f"legacy current-combination int1 shape is unsupported: {path}" - ) - stride = int(shape.group(1)) + 1 - column_count = int(shape.group(2)) - if len(values) != stride * column_count: - raise CatalogParityError( - f"legacy current-combination int1 payload has the wrong size: {path}" - ) - for start in range(0, len(values), stride): - produced_ids.add(values[start]) - contribution_ids = values[start + 1 : start + stride] - contribution_reference_ids.update(contribution_ids) - combine_route_count += len(contribution_ids) - - expected_currents = set(range(1, declared_currents + 1)) - expected_interactions = set(range(1, declared_interactions + 1)) - mapping = LegacyObjectMapping( - abi="pyamplicol-legacy-module-object-mapping-v1", - declared_current_count=declared_currents, - declared_interaction_count=declared_interactions, - source_current_count=len(source_ids), - produced_current_count=len(produced_ids), - vertex_term_count=len(vertex_term_ids), - combine_route_count=combine_route_count, - current_ids_complete=(source_ids | produced_ids) == expected_currents, - interaction_ids_complete=vertex_term_ids == expected_interactions, - contribution_references_complete=( - contribution_reference_ids == expected_interactions - ), - ) - if not ( - mapping.current_ids_complete - and mapping.interaction_ids_complete - and mapping.contribution_references_complete - ): - raise CatalogParityError( - f"legacy module has sparse or dangling current/interaction objects: {path}" - ) - return mapping - - -def _legacy_counts( - result: dict[str, Any], - *, - workload: Workload, -) -> LegacyCounts: - artifact_payload = result.get("artifact") - if not isinstance(artifact_payload, dict): - raise CatalogParityError("legacy result has no artifact") - artifact_raw = artifact_payload.get("path") - if not isinstance(artifact_raw, str) or not artifact_raw: - raise CatalogParityError("legacy artifact path is absent") - artifact = Path(artifact_raw) - modules = sorted(artifact.rglob("amp*_lib.f03")) - shapes = tuple(_module_shape(module) for module in modules) - module_mappings = tuple(_module_object_mapping(module) for module in modules) - - if workload is Workload.ALL_FLOW: - log = artifact / "legacy.log" - text = log.read_text() - current = _DIRECT_CURRENT.search(text) - interaction = _DIRECT_INTERACTION.search(text) - amplitude = _DIRECT_AMPLITUDE.search(text) - if current is None or interaction is None or amplitude is None: - raise CatalogParityError("all-flow legacy log lacks structural counters") - counts = WorkCounts( - int(current.group(1)), - int(interaction.group(1)), - None, - ) - return LegacyCounts( - evidence_kind="direct-fixed-helicity-all-flow-probe", - active=counts, - static=counts, - generated_module_count=0, - retained_amplitude_count=int(amplitude.group(1)), - module_shapes=(), - selected_module=None, - selected_module_object_mapping=None, - limitation=None, - ) - - if not modules: - raise CatalogParityError("generated-library legacy artifact has no modules") - - if workload is Workload.SELECTED_FLOW: - row = artifact_payload.get("process_row") - if not isinstance(row, str): - raise CatalogParityError("selected-flow legacy result lacks process row") - match = _PROCESS_ROW.fullmatch(row) - if match is None: - raise CatalogParityError(f"malformed selected-flow process row: {row!r}") - selected_name = f"amp{match.group(1)}_{match.group(2)}_lib.f03" - selected = [module for module in modules if module.name == selected_name] - if len(selected) != 1: - raise CatalogParityError( - f"selected-flow module {selected_name} occurs {len(selected)} times" - ) - current, interaction = _module_shape(selected[0]) - object_mapping = _module_object_mapping(selected[0]) - active = WorkCounts( - current, - interaction, - object_mapping.combine_route_count, - ) - static = WorkCounts( - sum(module_current for module_current, _ in shapes), - sum(module_interaction for _, module_interaction in shapes), - sum(mapping.combine_route_count for mapping in module_mappings), - ) - return LegacyCounts( - evidence_kind="generated-library-selected-row", - active=active, - # The selected-flow timing executes one row, but original - # AmpliCol first materializes the complete generated library. - # Preserve that distinction when comparing generation work. - static=static, - generated_module_count=len(modules), - retained_amplitude_count=1, - module_shapes=shapes, - selected_module=selected_name, - selected_module_object_mapping=object_mapping, - limitation=None, - ) - - probes = sorted(artifact.rglob("amplicol_color_library_probe.output")) - if len(probes) != 1: - raise CatalogParityError( - "contracted legacy artifact must contain one color-library probe" - ) - match = _AFTER_FILTER.search(probes[0].read_text()) - if match is None: - raise CatalogParityError("contracted legacy probe lacks after-filter counts") - row = artifact_payload.get("process_row") - if not isinstance(row, str): - raise CatalogParityError("contracted legacy result lacks process row") - row_match = _PROCESS_ROW.fullmatch(row) - if row_match is None: - raise CatalogParityError(f"malformed contracted process row: {row!r}") - selected_name = f"amp{row_match.group(1)}_{row_match.group(2)}_lib.f03" - selected = [module for module in modules if module.name == selected_name] - if len(selected) != 1: - raise CatalogParityError( - f"contracted module {selected_name} occurs {len(selected)} times" - ) - object_mapping = _module_object_mapping(selected[0]) - retained = int(match.group(3)) - static = WorkCounts( - sum(current for current, _ in shapes), - sum(interaction for _, interaction in shapes), - sum(mapping.combine_route_count for mapping in module_mappings), - ) - calls = { - (int(group), int(integral)): int(count) - for group, integral, count in _LIBRARY_CALL.findall(probes[0].read_text()) - } - active: WorkCounts | None = None - limitation = ( - "contracted probe predates exact generated-library call histogram" - ) - if calls: - by_name = {module.name: module for module in modules} - missing = [ - f"amp{group}_{integral}_lib.f03" - for group, integral in calls - if f"amp{group}_{integral}_lib.f03" not in by_name - ] - if missing: - raise CatalogParityError( - "contracted probe call histogram references absent modules: " - + ", ".join(sorted(missing)) - ) - active = WorkCounts( - sum( - _module_shape(by_name[f"amp{group}_{integral}_lib.f03"])[0] * count - for (group, integral), count in calls.items() - ), - sum( - _module_shape(by_name[f"amp{group}_{integral}_lib.f03"])[1] * count - for (group, integral), count in calls.items() - ), - sum( - _module_object_mapping( - by_name[f"amp{group}_{integral}_lib.f03"] - ).combine_route_count - * count - for (group, integral), count in calls.items() - ), - ) - limitation = None - return LegacyCounts( - evidence_kind=( - "generated-library-contracted-exact-call-histogram" - if active is not None - else "generated-library-contracted-call-histogram-unavailable" - ), - active=active, - static=static, - generated_module_count=len(modules), - retained_amplitude_count=retained, - module_shapes=shapes, - selected_module=selected_name, - selected_module_object_mapping=object_mapping, - limitation=limitation, - ) - - -def _candidate_counts( - result: dict[str, Any], - *, - workload: Workload, -) -> CandidateCounts: - artifact_payload = result.get("artifact") - if not isinstance(artifact_payload, dict): - raise CatalogParityError("candidate result has no artifact") - artifact_raw = artifact_payload.get("path") - if not isinstance(artifact_raw, str) or not artifact_raw: - raise CatalogParityError("candidate artifact path is absent") - execution = _read_json(_single_execution(Path(artifact_raw))) - kind = execution.get("kind") - selector_available = False - active_kind = "persisted-plan" - active_exact = workload is Workload.CONTRACTED - active_closures: int | None = None - final_closures: int | None = None - peak_closures: int | None = None - - if kind == "pyamplicol-runtime-recurrence-execution": - mode = ExecutionMode.RECURRENCE.value - try: - inspection = execution["plan"]["inspection_summary"] - schedule = inspection["schedule"] - construction = inspection["construction"] - except (KeyError, TypeError) as error: - raise CatalogParityError( - "recurrence execution summary is incomplete" - ) from error - if ( - construction.get("peak_contribution_count_semantics") - != _PEAK_CONTRIBUTION_COUNT_SEMANTICS - ): - raise CatalogParityError( - "recurrence construction lacks authenticated resident " - "peak-contribution semantics" - ) - final = WorkCounts( - _positive(schedule.get("current_count"), "recurrence current count"), - _positive( - schedule.get("contribution_count"), - "recurrence contribution count", - ), - _positive( - schedule.get("contribution_count"), - "recurrence contribution count", - ), - ) - peak = WorkCounts( - _positive( - construction.get("peak_current_count"), - "recurrence peak current count", - ), - _positive( - construction.get("peak_contribution_count"), - "recurrence peak contribution count", - ), - _positive( - construction.get("peak_contribution_count"), - "recurrence peak contribution count", - ), - ) - active = final - final_closures = _optional_nonnegative( - schedule.get("closure_term_count"), - "recurrence closure-term count", - ) - active_closures = final_closures - peak_closures = _optional_nonnegative( - construction.get("peak_closure_term_count"), - "recurrence peak closure-term count", - ) - selector = inspection.get("selector_work_certificate") - if workload is Workload.SELECTED_FLOW and isinstance(selector, dict): - representatives = selector.get("representatives") - if isinstance(representatives, list) and representatives: - parsed = [ - WorkCounts( - _positive(item.get("current_count"), "selector current count"), - _positive( - item.get("contribution_count"), - "selector contribution count", - ), - _positive( - item.get("contribution_count"), - "selector contribution count", - ), - ) - for item in representatives - if isinstance(item, dict) - ] - if parsed: - # The report selector can target any physical flow. The - # worst representative is the fail-closed catalog gate. - active = WorkCounts( - max(item.current_count for item in parsed), - max( - item.evaluation_count - for item in parsed - if item.evaluation_count is not None - ), - max( - item.attachment_count - for item in parsed - if item.attachment_count is not None - ), - ) - selector_available = True - active_exact = True - active_kind = "selector-active-worst-representative" - active_closures = max( - ( - _optional_nonnegative( - item.get("closure_count"), - "selector closure count", - ) - or 0 - ) - for item in representatives - if isinstance(item, dict) - ) - elif kind == "pyamplicol-runtime-execution": - mode = ExecutionMode.COMPILED.value - if workload is Workload.ALL_FLOW: - # The all-flow report workload fixes one physical helicity and - # sums color. Its executed lane is the primary DAG. Unlike the - # selected-flow (one color, helicity sum) and contracted lanes, - # it therefore need not expose an auxiliary helicity-sum DAG. - summary = execution.get("dag_summary") - active_kind = "compiled-primary-fixed-helicity-all-flow" - selector_records = execution.get("helicity_selector_executions") - else: - helicity_sum = execution.get("helicity_sum_execution") - if not isinstance(helicity_sum, dict): - raise CatalogParityError("compiled execution lacks helicity-sum lane") - summary = helicity_sum.get("dag_summary") - active_kind = "compiled-helicity-sum" - selector_records = ( - helicity_sum.get("color_selector_executions") - if workload is Workload.SELECTED_FLOW - else None - ) - if not isinstance(summary, dict): - raise CatalogParityError("compiled execution lacks DAG summary") - active = WorkCounts( - _positive(summary.get("current_count"), "compiled current count"), - _optional_positive( - summary.get("interaction_evaluation_count"), - "compiled interaction evaluation count", - ), - _positive( - summary.get("interaction_count"), - "compiled interaction attachment count", - ), - ) - active_closures = _optional_nonnegative( - summary.get("amplitude_root_count"), - "compiled active amplitude-root count", - ) - final, final_closures = _sum_compiled_materialization( - _compiled_execution_lanes(execution) - ) - peak = final - peak_closures = final_closures - if isinstance(selector_records, list) and selector_records: - selector_counts: list[WorkCounts] = [] - for record in selector_records: - if not isinstance(record, dict): - continue - selector_execution = record.get("execution") - if not isinstance(selector_execution, dict): - continue - selector_summary = selector_execution.get("dag_summary") - if not isinstance(selector_summary, dict): - continue - selector_counts.append( - WorkCounts( - _positive( - selector_summary.get("current_count"), - "compiled selector current count", - ), - _optional_positive( - selector_summary.get("interaction_evaluation_count"), - "compiled selector interaction evaluation count", - ), - _positive( - selector_summary.get("interaction_count"), - "compiled selector interaction attachment count", - ), - ) - ) - if selector_counts: - active = WorkCounts( - max(item.current_count for item in selector_counts), - ( - None - if any( - item.evaluation_count is None for item in selector_counts - ) - else max( - item.evaluation_count - for item in selector_counts - if item.evaluation_count is not None - ) - ), - max( - item.attachment_count - for item in selector_counts - if item.attachment_count is not None - ), - ) - selector_available = True - active_exact = True - active_kind = ( - "compiled-selected-color-worst-sector" - if workload is Workload.SELECTED_FLOW - else "compiled-fixed-helicity-worst-class" - ) - active_closures = max( - ( - _optional_nonnegative( - record.get("execution", {}) - .get("dag_summary", {}) - .get("amplitude_root_count"), - "compiled selector amplitude-root count", - ) - or 0 - ) - for record in selector_records - if isinstance(record, dict) - ) - elif kind == "pyamplicol-runtime-eager-execution": - mode = ExecutionMode.EAGER.value - try: - inspection = execution["plan"]["inspection_summary"] - except (KeyError, TypeError) as error: - raise CatalogParityError( - "eager execution lacks inspection summary" - ) from error - final = WorkCounts( - _positive(inspection.get("current_count"), "eager current count"), - _optional_positive( - inspection.get("invocation_count"), - "eager invocation count", - ), - _positive(inspection.get("attachment_count"), "eager attachment count"), - ) - peak = final - active = final - final_closures = _optional_nonnegative( - inspection.get("closure_count"), - "eager closure count", - ) - active_closures = final_closures - peak_closures = final_closures - selector_work = inspection.get("selector_work") - if isinstance(selector_work, dict): - if selector_work.get("abi") != "pyamplicol-eager-selector-work-v1": - raise CatalogParityError("eager selector-work ABI is unsupported") - prefix = { - Workload.SELECTED_FLOW: "selected_flow", - Workload.ALL_FLOW: "all_flow", - Workload.CONTRACTED: "contracted", - }[workload] - active = WorkCounts( - _positive( - selector_work.get(f"{prefix}_current_count"), - f"eager {prefix} active current count", - ), - _positive( - selector_work.get(f"{prefix}_evaluation_count"), - f"eager {prefix} active evaluation count", - ), - _positive( - selector_work.get(f"{prefix}_attachment_count"), - f"eager {prefix} active attachment count", - ), - ) - selector_available = True - active_exact = True - active_kind = f"eager-{prefix.replace('_', '-')}-selector-census" - active_closures = _optional_nonnegative( - selector_work.get(f"{prefix}_closure_count"), - f"eager {prefix} active closure count", - ) - else: - raise CatalogParityError(f"unsupported candidate execution kind {kind!r}") - - provenance = result.get("provenance") - source_revision = None - if isinstance(provenance, dict): - value = provenance.get("report_measured_source_revision") - if isinstance(value, str): - source_revision = value - return CandidateCounts( - mode=mode, - active=active, - final_materialized=final, - peak_materialized=peak, - active_evidence_kind=active_kind, - active_evidence_exact=active_exact, - selector_certificate_available=selector_available, - source_revision=source_revision, - active_closure_count=active_closures, - final_materialized_closure_count=final_closures, - peak_materialized_closure_count=peak_closures, - ) - - -def _ratio(candidate: int, legacy: int) -> float: - value = candidate / legacy - if not math.isfinite(value): - raise CatalogParityError("non-finite structural-work ratio") - return value - - -def _load_currents(artifact_root: Path) -> dict[str, dict[str, Any]]: - results: dict[str, dict[str, Any]] = {} - for pointer_path in sorted((artifact_root / "cells").glob("*/current.json")): - pointer = _read_json(pointer_path) - cell_id = pointer.get("cell_id") - manifest_raw = pointer.get("manifest_path") - if not isinstance(cell_id, str) or not isinstance(manifest_raw, str): - raise CatalogParityError(f"malformed current pointer {pointer_path}") - manifest_path = pointer_path.parent / manifest_raw - manifest = _read_json(manifest_path) - result_raw = manifest.get("result_path") - if not isinstance(result_raw, str): - raise CatalogParityError(f"manifest lacks result path: {manifest_path}") - result_path = manifest_path.parent / result_raw - result = _read_json(result_path) - result["_audit_result_path"] = str(result_path) - results[cell_id] = result - return results - - -def _cell_row( - cell: Any, - currents: dict[str, dict[str, Any]], -) -> dict[str, Any]: - base = { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "mode": cell.measurement.execution_mode.value, - "model": None - if cell.measurement.model is None - else cell.measurement.model.value, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "limit": MAX_RATIO, - } - candidate_result = currents.get(cell.cell_id) - if candidate_result is None: - return base | {"status": "candidate-unavailable"} - candidate_status = candidate_result.get("status") - if candidate_status != ResultStatus.OK.value: - return base | { - "status": "candidate-non-ok", - "candidate_status": candidate_status, - "candidate_result_path": candidate_result.get("_audit_result_path"), - } - - reference = next( - candidate - for candidate in REPORT_CATALOG.reference_cells() - if candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.measurement.accuracy == cell.measurement.accuracy - and candidate.workload == cell.workload - ) - if not REPORT_CATALOG.legacy_reference_available(cell): - return base | { - "status": "legacy-unsupported", - "candidate_result_path": candidate_result.get("_audit_result_path"), - } - legacy_result = currents.get(reference.cell_id) - if legacy_result is None: - return base | { - "status": "legacy-unavailable", - "legacy_cell_id": reference.cell_id, - "candidate_result_path": candidate_result.get("_audit_result_path"), - } - legacy_status = legacy_result.get("status") - if legacy_status != ResultStatus.OK.value: - return base | { - "status": "legacy-non-ok", - "legacy_cell_id": reference.cell_id, - "legacy_status": legacy_status, - "candidate_result_path": candidate_result.get("_audit_result_path"), - "legacy_result_path": legacy_result.get("_audit_result_path"), - } - - try: - candidate_counts = _candidate_counts( - candidate_result, - workload=cell.workload, - ) - legacy_counts = _legacy_counts(legacy_result, workload=cell.workload) - except CatalogParityError as error: - return base | { - "status": "evidence-unavailable", - "error": str(error), - "legacy_cell_id": reference.cell_id, - "candidate_result_path": candidate_result.get("_audit_result_path"), - "legacy_result_path": legacy_result.get("_audit_result_path"), - } - - ratios: dict[str, float | None] = { - "active_current": None, - "active_evaluation": None, - "active_attachment": None, - "final_static_current": _ratio( - candidate_counts.final_materialized.current_count, - legacy_counts.static.current_count, - ), - "final_static_evaluation": None, - "final_static_attachment": None, - "peak_static_current": _ratio( - candidate_counts.peak_materialized.current_count, - legacy_counts.static.current_count, - ), - "peak_static_evaluation": None, - "peak_static_attachment": None, - } - if ( - candidate_counts.final_materialized.evaluation_count is not None - and legacy_counts.static.evaluation_count is not None - ): - ratios["final_static_evaluation"] = _ratio( - candidate_counts.final_materialized.evaluation_count, - legacy_counts.static.evaluation_count, - ) - if ( - candidate_counts.final_materialized.attachment_count is not None - and legacy_counts.static.attachment_count is not None - ): - ratios["final_static_attachment"] = _ratio( - candidate_counts.final_materialized.attachment_count, - legacy_counts.static.attachment_count, - ) - if ( - candidate_counts.peak_materialized.evaluation_count is not None - and legacy_counts.static.evaluation_count is not None - ): - ratios["peak_static_evaluation"] = _ratio( - candidate_counts.peak_materialized.evaluation_count, - legacy_counts.static.evaluation_count, - ) - if ( - candidate_counts.peak_materialized.attachment_count is not None - and legacy_counts.static.attachment_count is not None - ): - ratios["peak_static_attachment"] = _ratio( - candidate_counts.peak_materialized.attachment_count, - legacy_counts.static.attachment_count, - ) - if legacy_counts.active is not None and candidate_counts.active_evidence_exact: - ratios["active_current"] = _ratio( - candidate_counts.active.current_count, - legacy_counts.active.current_count, - ) - if ( - candidate_counts.active.evaluation_count is not None - and legacy_counts.active.evaluation_count is not None - ): - ratios["active_evaluation"] = _ratio( - candidate_counts.active.evaluation_count, - legacy_counts.active.evaluation_count, - ) - if ( - candidate_counts.active.attachment_count is not None - and legacy_counts.active.attachment_count is not None - ): - ratios["active_attachment"] = _ratio( - candidate_counts.active.attachment_count, - legacy_counts.active.attachment_count, - ) - violations = tuple( - key for key, value in ratios.items() if value is not None and value > MAX_RATIO - ) - unknown = tuple(key for key, value in ratios.items() if value is None) - status = ( - "ok" - if not violations and not unknown - else ("exceeds-1.05" if violations else "active-parity-unresolved") - ) - return base | { - "status": status, - "legacy_cell_id": reference.cell_id, - "candidate": asdict(candidate_counts), - "legacy": asdict(legacy_counts), - "ratios": ratios, - "violations": violations, - "unresolved_metrics": unknown, - "candidate_result_path": candidate_result.get("_audit_result_path"), - "legacy_result_path": legacy_result.get("_audit_result_path"), - } - - -def audit(artifact_root: Path) -> dict[str, Any]: - currents = _load_currents(artifact_root) - cells = [ - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode - in {ExecutionMode.RECURRENCE, ExecutionMode.COMPILED, ExecutionMode.EAGER} - ] - rows = [_cell_row(cell, currents) for cell in cells] - status_counts = Counter(row["status"] for row in rows) - comparable = [ - row - for row in rows - if row["status"] in {"ok", "exceeds-1.05", "active-parity-unresolved"} - ] - violations = [row for row in comparable if row.get("violations")] - active_violations = [ - row - for row in violations - if any(metric.startswith("active_") for metric in row["violations"]) - ] - final_static_violations = [ - row - for row in violations - if any(metric.startswith("final_static_") for metric in row["violations"]) - ] - peak_static_violations = [ - row - for row in violations - if any(metric.startswith("peak_static_") for metric in row["violations"]) - ] - return { - "schema": "pyamplicol-catalog-structural-parity-census-v1", - "created_utc": datetime.now(UTC).isoformat(), - "artifact_root": str(artifact_root.resolve()), - "policy": { - "maximum_unreviewed_ratio_to_original_amplicol": MAX_RATIO, - "active_and_static_materialization_are_independent_gates": True, - "compiled_and_eager_peak_defaults_to_final_materialization": True, - "selected_recurrence_active_work_uses_worst_selector_representative": True, - }, - "summary": { - "catalog_candidate_cell_count": len(rows), - "current_pointer_count": len(currents), - "status_counts": dict(sorted(status_counts.items())), - "comparable_cell_count": len(comparable), - "violation_cell_count": len(violations), - "active_violation_cell_count": len(active_violations), - "final_static_violation_cell_count": len(final_static_violations), - "peak_static_violation_cell_count": len(peak_static_violations), - "fully_certified_catalog_parity": ( - len(comparable) == len(rows) and not violations - ), - "violation_by_metric": dict( - sorted( - Counter( - metric for row in violations for metric in row["violations"] - ).items() - ) - ), - "violation_by_mode": dict( - sorted(Counter(row["mode"] for row in violations).items()) - ), - "violation_by_process": dict( - sorted(Counter(row["process_key"] for row in violations).items()) - ), - }, - "cells": rows, - } - - -def _source_work_counts(value: object, label: str) -> WorkCounts: - if not isinstance(value, dict): - raise CatalogParityError(f"{label} must be an object") - return WorkCounts( - _positive(value.get("current_count"), f"{label} current count"), - _positive(value.get("evaluation_count"), f"{label} evaluation count"), - _positive(value.get("attachment_count"), f"{label} attachment count"), - ) - - -def _require_exact_projection_certificate( - value: object, - label: str, - *, - expected_source_revision: str, - projection_applied: bool, -) -> None: - if value is None and not projection_applied: - return - if not isinstance(value, dict): - raise CatalogParityError(f"{label} projection certificate is malformed") - required_digests = ( - "source_semantics_sha256", - "selector_domains_sha256", - "current_class_members_sha256", - "current_remap_sha256", - "interaction_groups_sha256", - "closure_groups_sha256", - "rectangle_cardinalities_sha256", - "row_identity_sha256", - ) - remap = value.get("old_to_new_current_ids") - if ( - value.get("abi") != _DYNAMIC_COLOR_PROJECTION_ABI - or value.get("source_revision") != expected_source_revision - or value.get("applied") is not projection_applied - or value.get("equality_check_status") - not in { - "passed-exact-cartesian-products-no-duplicates", - "passed-no-projectable-classes", - } - or not isinstance(remap, list) - or not remap - or any(not isinstance(item, int) or item < 0 for item in remap) - or any( - not isinstance(value.get(field), str) - or re.fullmatch(r"[0-9a-f]{64}", value[field]) is None - for field in required_digests - ) - ): - raise CatalogParityError( - f"{label} lacks a complete exact rectangular projection proof" - ) - - -def audit_source_manifest(payload: dict[str, Any]) -> dict[str, Any]: - """Fail closed on a source-derived, timing-free all-catalog census.""" - - if payload.get("schema") != "pyamplicol-catalog-source-structural-evidence-v1": - raise CatalogParityError("source structural evidence schema is unsupported") - source_revision = payload.get("source_revision") - if ( - not isinstance(source_revision, str) - or re.fullmatch(r"[0-9a-f]{40}", source_revision) is None - ): - raise CatalogParityError("source structural evidence revision is invalid") - raw_cells = payload.get("cells") - if not isinstance(raw_cells, list): - raise CatalogParityError("source structural evidence cells must be a list") - expected_cells = tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode - in {ExecutionMode.RECURRENCE, ExecutionMode.COMPILED, ExecutionMode.EAGER} - ) - expected_by_id = {cell.cell_id: cell for cell in expected_cells} - rows_by_id: dict[str, dict[str, Any]] = {} - for raw in raw_cells: - if not isinstance(raw, dict) or not isinstance(raw.get("cell_id"), str): - raise CatalogParityError("source structural evidence has malformed cell") - cell_id = raw["cell_id"] - if cell_id in rows_by_id: - raise CatalogParityError( - f"source structural evidence repeats cell {cell_id}" - ) - rows_by_id[cell_id] = raw - missing = sorted(set(expected_by_id) - set(rows_by_id)) - extra = sorted(set(rows_by_id) - set(expected_by_id)) - if missing or extra: - raise CatalogParityError( - "source structural evidence does not cover the exact catalog " - f"(missing={missing[:5]}, extra={extra[:5]})" - ) - - audited: list[dict[str, Any]] = [] - violation_count = 0 - unresolved_count = 0 - scope_unavailable_count = 0 - for cell_id, cell in expected_by_id.items(): - raw = rows_by_id[cell_id] - if raw.get("source_revision") != source_revision: - raise CatalogParityError( - f"source structural evidence {cell_id} revision mismatch" - ) - if raw.get("proof_strength") != "exact-source-construction": - raise CatalogParityError( - f"source structural evidence {cell_id} is not an exact proof" - ) - candidate = raw.get("candidate") - if not isinstance(candidate, dict): - raise CatalogParityError(f"{cell_id} candidate evidence is absent") - candidate_active = _source_work_counts( - candidate.get("active"), - f"{cell_id} candidate active", - ) - candidate_final = _source_work_counts( - candidate.get("final_materialized"), - f"{cell_id} candidate final", - ) - candidate_peak = _source_work_counts( - candidate.get("peak_materialized"), - f"{cell_id} candidate peak", - ) - _optional_nonnegative( - candidate.get("active_closure_count"), - f"{cell_id} candidate active closure count", - ) - _optional_nonnegative( - candidate.get("final_closure_count"), - f"{cell_id} candidate final closure count", - ) - _optional_nonnegative( - candidate.get("peak_closure_count"), - f"{cell_id} candidate peak closure count", - ) - _require_exact_projection_certificate( - candidate.get("dynamic_color_projection"), - cell_id, - expected_source_revision=source_revision, - projection_applied=_require_bool( - candidate.get("dynamic_color_projection_applied"), - f"{cell_id} candidate dynamic-color projection applied", - ), - ) - - if not REPORT_CATALOG.legacy_reference_available(cell): - if ( - raw.get("status") != "legacy-scope-unavailable" - or not isinstance(raw.get("scope_reason"), str) - or raw.get("legacy") is not None - ): - raise CatalogParityError( - f"{cell_id} must explicitly record legacy-scope-unavailable" - ) - scope_unavailable_count += 1 - audited.append( - { - "cell_id": cell_id, - "status": "legacy-scope-unavailable", - "scope_reason": raw["scope_reason"], - "candidate": { - "active": asdict(candidate_active), - "final_materialized": asdict(candidate_final), - "peak_materialized": asdict(candidate_peak), - }, - "ratios": None, - "violations": (), - } - ) - continue - - if raw.get("status") != "ok": - raise CatalogParityError( - f"{cell_id} comparable source evidence status must be ok" - ) - legacy = raw.get("legacy") - if not isinstance(legacy, dict): - raise CatalogParityError(f"{cell_id} legacy evidence is absent") - legacy_active = _source_work_counts( - legacy.get("active"), - f"{cell_id} legacy active", - ) - legacy_static = _source_work_counts( - legacy.get("static"), - f"{cell_id} legacy static", - ) - ratios = { - "active_current": _ratio( - candidate_active.current_count, legacy_active.current_count - ), - "active_evaluation": _ratio( - candidate_active.evaluation_count or 0, - legacy_active.evaluation_count or 0, - ), - "active_attachment": _ratio( - candidate_active.attachment_count or 0, - legacy_active.attachment_count or 0, - ), - "final_static_current": _ratio( - candidate_final.current_count, legacy_static.current_count - ), - "final_static_evaluation": _ratio( - candidate_final.evaluation_count or 0, - legacy_static.evaluation_count or 0, - ), - "final_static_attachment": _ratio( - candidate_final.attachment_count or 0, - legacy_static.attachment_count or 0, - ), - "peak_static_current": _ratio( - candidate_peak.current_count, legacy_static.current_count - ), - "peak_static_evaluation": _ratio( - candidate_peak.evaluation_count or 0, - legacy_static.evaluation_count or 0, - ), - "peak_static_attachment": _ratio( - candidate_peak.attachment_count or 0, - legacy_static.attachment_count or 0, - ), - } - violations = tuple( - name for name, ratio in ratios.items() if ratio > MAX_RATIO - ) - violation_count += bool(violations) - audited.append( - { - "cell_id": cell_id, - "status": "ok" if not violations else "exceeds-1.05", - "candidate": { - "active": asdict(candidate_active), - "final_materialized": asdict(candidate_final), - "peak_materialized": asdict(candidate_peak), - }, - "legacy": { - "active": asdict(legacy_active), - "static": asdict(legacy_static), - }, - "ratios": ratios, - "violations": violations, - } - ) - comparable_count = len(audited) - scope_unavailable_count - return { - "schema": "pyamplicol-catalog-source-structural-parity-preflight-v1", - "created_utc": datetime.now(UTC).isoformat(), - "source_revision": source_revision, - "policy": { - "maximum_ratio_to_original_amplicol": MAX_RATIO, - "currents_evaluations_and_attachments_are_independent_gates": True, - "amplitude_roots_are_reported_but_not_conflated_with_int_c": True, - "legacy_scope_unavailable_is_explicit_and_has_no_fabricated_ratio": True, - }, - "summary": { - "catalog_candidate_cell_count": len(expected_cells), - "comparable_cell_count": comparable_count, - "legacy_scope_unavailable_cell_count": scope_unavailable_count, - "violation_cell_count": violation_count, - "unresolved_cell_count": unresolved_count, - "complete_catalog_coverage": True, - "all_comparable_cells_within_limit": violation_count == 0, - "fully_certified_catalog_parity": violation_count == 0, - }, - "cells": audited, - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - source = parser.add_mutually_exclusive_group(required=True) - source.add_argument("--artifact-root", type=Path) - source.add_argument( - "--source-manifest", - type=Path, - help=( - "timing-free source-construction evidence covering every matrix " - "candidate cell" - ), - ) - parser.add_argument("--output", type=Path, required=True) - parser.add_argument( - "--require-complete-parity", - action="store_true", - help=( - "exit nonzero unless every catalog candidate has complete evidence " - "and all active/final/peak ratios are <=1.05" - ), - ) - return parser - - -def _parity_exit_code(payload: dict[str, Any], *, required: bool) -> int: - if not required: - return 0 - summary = payload.get("summary") - if not isinstance(summary, dict): - return 2 - return 0 if summary.get("fully_certified_catalog_parity") is True else 2 - - -def main() -> int: - args = _parser().parse_args() - payload = ( - audit_source_manifest(_read_json(args.source_manifest)) - if args.source_manifest is not None - else audit(args.artifact_root) - ) - args.output.parent.mkdir(parents=True, exist_ok=True) - args.output.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n") - print(json.dumps(payload["summary"], indent=2, sort_keys=True)) - return _parity_exit_code(payload, required=args.require_complete_parity) - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/catalog_structural_scope_registry.py b/pyamplicol/tools/developer/catalog_structural_scope_registry.py deleted file mode 100644 index 68645638f6..0000000000 --- a/pyamplicol/tools/developer/catalog_structural_scope_registry.py +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Reviewed, fail-closed scope for matrix structural-parity coverage gaps. - -The 1,356-row restart gate covers every candidate cell that the canonical -matrix catalog defines. This registry makes the two intentionally absent -classes explicit so that they cannot be mistaken for silently unproved rows. -Any catalog change in these classes requires a review and registry update. -""" - -from __future__ import annotations - -from typing import Any - -from tools.performance_report.catalog import PROCESS_FAMILIES, REPORT_CATALOG -from tools.performance_report.models import ( - Accuracy, - ExecutionMode, - ModelKey, - Workload, -) - -SCHEMA = "pyamplicol-reviewed-matrix-structural-scope-v2" -REVIEW_ID = "matrix-structural-scope-2026-08-21" - -_PROCESS_KEYS = ( - "dd_z_jets", - "ud_w_jets", - "dd_epem_jets", - "ud_epve_jets", - "dd_zz_jets", - "gg_tt_jets", - "dd_tt_jets", - "gg_gluons", - "dd_zzz_jets", - "dd_epemzh_jets", - "dd_ttzh_jets", - "dd_4l_jets", - "dd_3q_lines", - "dd_4q_lines", - "dd_3q_identical_lines", -) -_CANDIDATE_MODES = { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, -} -_FOUR_QUARK_LC_PLANES = { - (ExecutionMode.RECURRENCE, ModelKey.BUILTIN_SM, Workload.SELECTED_FLOW), - (ExecutionMode.RECURRENCE, ModelKey.BUILTIN_SM, Workload.ALL_FLOW), - (ExecutionMode.RECURRENCE, ModelKey.UFO_SM, Workload.SELECTED_FLOW), - (ExecutionMode.RECURRENCE, ModelKey.UFO_SM, Workload.ALL_FLOW), - (ExecutionMode.COMPILED, ModelKey.BUILTIN_SM, Workload.SELECTED_FLOW), - (ExecutionMode.COMPILED, ModelKey.BUILTIN_SM, Workload.ALL_FLOW), - (ExecutionMode.EAGER, ModelKey.BUILTIN_SM, Workload.SELECTED_FLOW), - (ExecutionMode.EAGER, ModelKey.BUILTIN_SM, Workload.ALL_FLOW), -} -_FOUR_QUARK_CONTRACTED_PLANES = { - (ExecutionMode.RECURRENCE, ModelKey.BUILTIN_SM, Workload.CONTRACTED), - (ExecutionMode.RECURRENCE, ModelKey.UFO_SM, Workload.CONTRACTED), - (ExecutionMode.COMPILED, ModelKey.BUILTIN_SM, Workload.CONTRACTED), - (ExecutionMode.EAGER, ModelKey.BUILTIN_SM, Workload.CONTRACTED), -} -_FOUR_QUARK_UFO_FULL_PLANES = { - (ExecutionMode.COMPILED, ModelKey.UFO_SM, Workload.CONTRACTED), - (ExecutionMode.EAGER, ModelKey.UFO_SM, Workload.CONTRACTED), -} - -REVIEWED_MATRIX_SCOPE: dict[str, Any] = { - "schema": SCHEMA, - "review": { - "status": "reviewed", - "review_id": REVIEW_ID, - }, - "intentionally_out_of_catalog": [ - { - "scope_id": "ufo-compiled-and-eager-lc-nlc", - "status": "reviewed-unavailable", - "process_keys": list(_PROCESS_KEYS), - "mode_model_pairs": [ - {"mode": "compiled", "model": "ufo_sm"}, - {"mode": "eager", "model": "ufo_sm"}, - ], - "accuracies": ["lc", "nlc"], - "workload_by_accuracy": { - "lc": ["selected-flow", "all-flow"], - "nlc": ["contracted"], - }, - "reason": ( - "canonical-matrix-defines-ufo-compiled-and-eager-for-full-colour-only" - ), - "catalog_cell_count": 0, - }, - ], - "candidate_only_requirements": [ - { - "scope_id": "four-open-quark-lines-lc-candidate-proof", - "process_key": "dd_4q_lines", - "accuracy": "lc", - "n_final": [6, 7, 8, 9], - "mode_model_workload_plane_count": 8, - "catalog_cell_count": 32, - "legacy_comparison": { - "status": "unavailable", - "reason": "original-amplicol-open-quark-line-limit", - }, - "proof_requirement": ( - "candidate exact structural and precision-50 self-proof remains " - "mandatory in catalog_restart_parity_gate" - ), - }, - { - "scope_id": "four-open-quark-lines-contracted-candidate-proof", - "process_key": "dd_4q_lines", - "accuracies": ["nlc", "full"], - "n_final": [6], - "mode_model_workload_plane_count_by_accuracy": {"nlc": 4, "full": 6}, - "catalog_cell_count": 10, - "legacy_comparison": { - "status": "unavailable", - "reason": "original-amplicol-open-quark-line-limit", - }, - "proof_requirement": ( - "candidate exact structural and precision-50 self-proof remains " - "mandatory in catalog_restart_parity_gate" - ), - }, - ], -} - - -class CatalogStructuralScopeError(RuntimeError): - """The canonical matrix drifted from its reviewed coverage scope.""" - - -def validate_reviewed_matrix_scope() -> dict[str, Any]: - """Validate and return the reviewed out-of-catalog scope declaration.""" - - process_keys = tuple(family.key for family in PROCESS_FAMILIES) - if process_keys != _PROCESS_KEYS: - raise CatalogStructuralScopeError( - "process catalog changed; reviewed matrix structural scope is stale" - ) - candidates = tuple( - cell - for cell in REPORT_CATALOG.matrix_cells() - if cell.measurement.execution_mode in _CANDIDATE_MODES - ) - - ufo_compiled_or_eager = [ - cell - for cell in candidates - if cell.measurement.model is ModelKey.UFO_SM - and cell.measurement.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - ] - if len(ufo_compiled_or_eager) != 100 or any( - cell.measurement.accuracy is not Accuracy.FULL - or cell.workload is not Workload.CONTRACTED - for cell in ufo_compiled_or_eager - ): - raise CatalogStructuralScopeError( - "UFO compiled/eager full-colour scope differs from the reviewed matrix" - ) - - four_quark = [ - cell for cell in candidates if cell.process_key == "dd_4q_lines" - ] - non_lc = [ - cell - for cell in four_quark - if cell.measurement.accuracy in {Accuracy.NLC, Accuracy.FULL} - ] - actual_non_lc = { - ( - cell.measurement.accuracy, - cell.n_final, - cell.measurement.execution_mode, - cell.measurement.model, - cell.workload, - ) - for cell in non_lc - } - expected_non_lc = { - (accuracy, 6, mode, model, workload) - for accuracy in {Accuracy.NLC, Accuracy.FULL} - for mode, model, workload in _FOUR_QUARK_CONTRACTED_PLANES - } | { - (Accuracy.FULL, 6, mode, model, workload) - for mode, model, workload in _FOUR_QUARK_UFO_FULL_PLANES - } - if actual_non_lc != expected_non_lc or len(non_lc) != 10: - raise CatalogStructuralScopeError( - "four-quark contracted candidate-only structural proof coverage " - "is incomplete" - ) - lc = [ - cell for cell in four_quark if cell.measurement.accuracy is Accuracy.LC - ] - actual_lc = { - ( - cell.n_final, - cell.measurement.execution_mode, - cell.measurement.model, - cell.workload, - ) - for cell in lc - } - expected_lc = { - (n_final, mode, model, workload) - for n_final in (6, 7, 8, 9) - for mode, model, workload in _FOUR_QUARK_LC_PLANES - } - if actual_lc != expected_lc or len(lc) != 32: - raise CatalogStructuralScopeError( - "four-quark LC candidate-only structural proof coverage is incomplete" - ) - if any(REPORT_CATALOG.legacy_reference_available(cell) for cell in four_quark): - raise CatalogStructuralScopeError( - "four-quark candidate-only cells unexpectedly have a legacy reference" - ) - unavailable = [ - cell - for cell in candidates - if not REPORT_CATALOG.legacy_reference_available(cell) - ] - if {cell.cell_id for cell in unavailable} != { - cell.cell_id for cell in four_quark - }: - raise CatalogStructuralScopeError( - "an unreviewed legacy-unavailable matrix class is present" - ) - return REVIEWED_MATRIX_SCOPE - - -__all__ = [ - "REVIEWED_MATRIX_SCOPE", - "REVIEW_ID", - "SCHEMA", - "CatalogStructuralScopeError", - "validate_reviewed_matrix_scope", -] diff --git a/pyamplicol/tools/developer/compiled_all_jit_arena_gate.py b/pyamplicol/tools/developer/compiled_all_jit_arena_gate.py deleted file mode 100644 index a0fadf7ca0..0000000000 --- a/pyamplicol/tools/developer/compiled_all_jit_arena_gate.py +++ /dev/null @@ -1,1887 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""End-to-end compiled Direct-Arena gate for every JIT optimization level. - -The gate generates four independent ``g g > g g`` artifacts, one for each -supported JIT source optimization level (O0, O1, O2, and O3). Every artifact -must be built and evaluated by a candidate installed from the exact clean -source revision. The gate then: - -* authenticates every artifact payload and the native loader's artifact ID; -* recursively requires ``compiled-plane-arena-v1`` for every fused stage; -* requires every source and Direct-Arena leaf to retain the requested JIT - optimization level; -* rejects DirectApplication metadata below every model-parameter evaluator; -* evaluates deterministic physical points through native f64 and retained - precision-32 execution; -* compares ``evaluate()`` with ``evaluate_resolved().total()``; -* compares totals and resolved components pointwise across O0/O1/O2/O3; and -* when profiling is exposed, requires nonzero Direct-Arena backend calls and - zero legacy pack/gather/scatter/remap traffic. - -Run this only from a clean, exact-source candidate. The outer 30 GiB watchdog -is mandatory and covers this process plus every generation worker: - -``` -.venv/bin/python tools/ci/memory_watchdog.py --limit-gib 30 -- \ - .venv/bin/python tools/developer/compiled_all_jit_arena_gate.py \ - --output-root /private/tmp/pyamplicol-compiled-all-jit-arena-gate -``` -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib -import importlib.machinery -import json -import math -import os -import platform -import re -import resource -import shutil -import stat -import subprocess -import sys -import sysconfig -import tempfile -import time -import tomllib -import uuid -from collections.abc import Iterable, Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -_EXACT_REEXEC_MARKER = "PYAMPLICOL_EXACT_PYTHON_REEXEC" -_EXACT_IMPORT_PATHS = "PYAMPLICOL_EXACT_IMPORT_PATHS" - - -def _bootstrap_source_only_python() -> None: - """Re-exec before importing any repository or candidate module.""" - - if os.environ.get(_EXACT_REEXEC_MARKER) == "1": - if ( - sys.flags.isolated != 1 - or sys.flags.no_site != 1 - or sys.flags.ignore_environment != 1 - or sys.flags.dont_write_bytecode != 1 - or not sys.dont_write_bytecode - ): - raise RuntimeError("exact Python re-exec flags are incomplete") - raw_paths = json.loads(os.environ[_EXACT_IMPORT_PATHS]) - if not isinstance(raw_paths, list) or not all( - isinstance(path, str) and Path(path).is_absolute() for path in raw_paths - ): - raise RuntimeError("exact Python import paths are invalid") - cache_prefix = os.environ.get("PYTHONPYCACHEPREFIX") - if ( - not isinstance(cache_prefix, str) - or not Path(cache_prefix).is_absolute() - or Path(cache_prefix).exists() - ): - raise RuntimeError("exact Python cache prefix is not absent") - for import_path in reversed(raw_paths): - if import_path not in sys.path: - sys.path.insert(0, import_path) - sys.pycache_prefix = cache_prefix - return - - prefix = Path(tempfile.gettempdir()) / ( - f".pyamplicol-no-bytecode-{os.getpid()}-{uuid.uuid4().hex}" - ) - if prefix.exists(): - raise RuntimeError( - f"isolated Python cache prefix unexpectedly exists: {prefix}" - ) - import_paths: list[str] = [] - native_root = next( - ( - candidate - for entry in sys.path - if (candidate := Path(entry) / "pyamplicol").is_dir() - and any( - path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in candidate.iterdir() - ) - ), - None, - ) - if native_root is not None: - import_paths.append(str(native_root.parent.resolve(strict=True))) - for scheme_name in ("purelib", "platlib"): - scheme_path = sysconfig.get_path(scheme_name) - if not isinstance(scheme_path, str): - continue - try: - resolved = str(Path(scheme_path).resolve(strict=True)) - except OSError: - continue - if resolved not in import_paths: - import_paths.append(resolved) - environment = os.environ.copy() - environment["PYTHONDONTWRITEBYTECODE"] = "1" - environment["PYTHONPYCACHEPREFIX"] = str(prefix) - environment[_EXACT_REEXEC_MARKER] = "1" - environment[_EXACT_IMPORT_PATHS] = json.dumps(import_paths) - os.execve( - sys.executable, - ( - sys.executable, - "-I", - "-S", - "-B", - str(Path(__file__).resolve(strict=True)), - *sys.argv[1:], - ), - environment, - ) - raise RuntimeError("exact Python re-exec returned unexpectedly") - - -if __name__ == "__main__": - _bootstrap_source_only_python() - -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.performance_report.runtime_evidence import ( # noqa: E402 - RuntimeEvidenceError, - established_preimport_runtime_identity, - loaded_pyamplicol_origin_policy, - native_extension_in_package, - preimport_python_runtime_identity, - python_package_tree_identity, - source_only_bytecode_policy, -) - -PROCESS = "g g > g g" -EXPECTED_EXTERNAL_PDGS = (21, 21, 21, 21) -JIT_LEVELS = (0, 1, 2, 3) -POINT_SEEDS = (846_731, 846_739, 846_763) -VALIDATION_SEED = 20260725 -SQRT_S = 1_000.0 -RELATIVE_TOLERANCE = 1.0e-12 -ABSOLUTE_TOLERANCE = 1.0e-15 -COMPILED_PLANE_ARENA_CAPABILITY = "compiled-plane-arena-v1" -COMPILED_PLANE_DIRECT_APPLICATION_ABI = "pyamplicol-compiled-plane-kernel-v2" -NATIVE_COMPILED_DIRECT_APPLICATION_ABI = ( - "pyamplicol-native-compiled-direct-application-v1" -) -SYMJIT_APPLICATION_ABI = "symjit-application-storage-v3" -SYMJIT_PLANE_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -SYMJIT_RUNTIME_CAPABILITY = "symjit.application.complex-f64.v1" -RESULT_KIND = "pyamplicol-compiled-all-jit-direct-arena-gate" -SCHEMA_VERSION = 1 -HASH_CHUNK_BYTES = 1024 * 1024 -REVISION_PATTERN = re.compile(r"[0-9a-f]{40}") -SHA256_PATTERN = re.compile(r"[0-9a-f]{64}") -WATCHDOG_INVOCATION = ( - ".venv/bin/python tools/ci/memory_watchdog.py --limit-gib 30 -- " - ".venv/bin/python tools/developer/compiled_all_jit_arena_gate.py " - "--output-root /private/tmp/pyamplicol-compiled-all-jit-arena-gate" -) - -_ZERO_PROFILE_COUNTERS = ( - "stage_input_copy_component_count", - "stage_leaf_input_copy_component_count", - "stage_evaluator_output_gather_component_count", - "stage_output_assign_component_count", - "amplitude_input_copy_component_count", - "amplitude_leaf_input_copy_component_count", - "amplitude_evaluator_output_gather_component_count", - "amplitude_output_remap_component_count", - "selector_gather_point_count", - "selector_gather_bytes", - "selector_scatter_value_count", - "compiled_direct_arena_boundary_input_bytes", - "compiled_direct_arena_boundary_current_output_bytes", - "compiled_direct_arena_boundary_amplitude_output_bytes", -) -_ZERO_PROFILE_TIMES = ( - "stage_input_pack_time_s", - "stage_leaf_input_pack_time_s", - "stage_evaluator_output_gather_time_s", - "output_assign_time_s", - "amplitude_input_pack_time_s", - "amplitude_leaf_input_pack_time_s", - "amplitude_evaluator_output_gather_time_s", - "amplitude_output_remap_time_s", - "selector_gather_time_s", - "selector_scatter_time_s", -) -_DIRECT_ENGINE_COUNTER = "compiled_direct_arena_engine_count" -_DIRECT_CALL_COUNTER = "compiled_direct_arena_call_count" - - -class GateError(RuntimeError): - """Raised when all-JIT Direct-Arena evidence cannot be trusted.""" - - -@dataclass(slots=True) -class EvaluationCapture: - """Non-serializable values retained for cross-level comparisons.""" - - physics_axes: dict[str, object] - f64_total: tuple[complex, ...] - precision32_total: tuple[complex, ...] - f64_components: tuple[complex, ...] - precision32_components: tuple[complex, ...] - - -def _canonical_json(value: object) -> bytes: - try: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ).encode("utf-8") - except (TypeError, ValueError) as error: - raise GateError("evidence is not canonical JSON") from error - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_json(value)).hexdigest() - - -def _regular_file_identity( - path: Path, - *, - aggregate: Any | None = None, - tree_relative: bytes | None = None, -) -> tuple[int, str]: - """Hash one stable regular file through one no-follow descriptor.""" - - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_NOFOLLOW", 0) - | getattr(os, "O_BINARY", 0) - ) - digest = hashlib.sha256() - descriptor: int | None = None - try: - descriptor = os.open(path, flags) - before = os.fstat(descriptor) - if not stat.S_ISREG(before.st_mode): - raise GateError(f"identity target is not a regular file: {path}") - if aggregate is not None: - if tree_relative is None: - raise GateError("tree hashing requires a relative path") - aggregate.update(len(tree_relative).to_bytes(8, "big")) - aggregate.update(tree_relative) - aggregate.update(before.st_size.to_bytes(8, "big")) - byte_count = 0 - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - while block := stream.read(HASH_CHUNK_BYTES): - digest.update(block) - if aggregate is not None: - aggregate.update(block) - byte_count += len(block) - after = os.fstat(stream.fileno()) - except OSError as error: - raise GateError( - f"cannot hash regular file through a checked fd: {path}" - ) from error - finally: - if descriptor is not None: - os.close(descriptor) - stable_fields = ( - "st_dev", - "st_ino", - "st_mode", - "st_size", - "st_mtime_ns", - "st_ctime_ns", - ) - if byte_count != before.st_size or any( - getattr(before, name) != getattr(after, name) for name in stable_fields - ): - raise GateError(f"identity target changed while it was hashed: {path}") - return byte_count, digest.hexdigest() - - -def _sha256_file(path: Path) -> str: - return _regular_file_identity(path)[1] - - -def _file_identity(path: Path) -> dict[str, object]: - try: - resolved = path.expanduser().resolve(strict=True) - except OSError as error: - raise GateError(f"cannot identify file: {path}") from error - size, sha256 = _regular_file_identity(resolved) - return { - "path": str(resolved), - "size_bytes": size, - "sha256": sha256, - } - - -def _tree_identity(path: Path) -> dict[str, object]: - """Hash relative names, sizes, and contents for a relocatable tree ID.""" - - try: - root = path.expanduser().resolve(strict=True) - candidates = list(root.rglob("*")) - except OSError as error: - raise GateError(f"cannot inspect identity tree: {path}") from error - if not root.is_dir(): - raise GateError(f"identity target is not a directory: {root}") - for candidate in candidates: - if candidate.is_symlink(): - raise GateError( - f"identity tree contains an unsupported symlink: {candidate}" - ) - members = sorted( - (candidate for candidate in candidates if candidate.is_file()), - key=lambda candidate: candidate.relative_to(root).as_posix(), - ) - digest = hashlib.sha256() - size_bytes = 0 - try: - for member in members: - relative = member.relative_to(root).as_posix().encode("utf-8") - size, _ = _regular_file_identity( - member, - aggregate=digest, - tree_relative=relative, - ) - size_bytes += size - except OSError as error: - raise GateError(f"cannot hash identity tree: {root}") from error - return { - "algorithm": "sha256-relative-path-size-content-v1", - "sha256": digest.hexdigest(), - "file_count": len(members), - "size_bytes": size_bytes, - } - - -def _python_package_tree_identity(path: Path) -> dict[str, object]: - try: - return python_package_tree_identity(path) - except RuntimeEvidenceError as error: - raise GateError(str(error)) from error - - -def _ensure_source_only_python() -> None: - """Verify the stdlib-only bootstrap completed before repository imports.""" - - try: - source_only_bytecode_policy() - except RuntimeEvidenceError as error: - raise GateError( - "source-only Python bootstrap did not complete before gate imports" - ) from error - - -def _establish_preimport_runtime_identity() -> None: - native_root = next( - ( - candidate - for entry in sys.path - if (candidate := Path(entry) / "pyamplicol").is_dir() - and any( - path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in candidate.iterdir() - ) - ), - None, - ) - if native_root is None: - raise GateError("candidate Python path has no native pyamplicol package") - native = native_extension_in_package(native_root) - preimport_python_runtime_identity((native_root,), native_extension=native) - - -def _json_object(path: Path, *, label: str) -> dict[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise GateError(f"cannot read {label}: {path}") from error - if not isinstance(value, dict): - raise GateError(f"{label} must be a JSON object: {path}") - return value - - -def _mapping(value: object, *, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise GateError(f"{label} must be an object") - return value - - -def _sequence(value: object, *, label: str) -> Sequence[Any]: - if isinstance(value, (str, bytes)) or not isinstance(value, Sequence): - raise GateError(f"{label} must be an array") - return value - - -def _safe_relative_path(value: object, *, label: str) -> str: - if not isinstance(value, str) or not value: - raise GateError(f"{label} must be a non-empty path") - path = Path(value) - if path.is_absolute() or ".." in path.parts: - raise GateError(f"{label} must be artifact-relative") - return value - - -def _git_output(arguments: Sequence[str]) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=ROOT, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - detail = completed.stderr.strip() or completed.stdout.strip() - raise GateError(f"git {' '.join(arguments)} failed: {detail}") - return completed.stdout.strip() - - -def _source_identity() -> dict[str, object]: - revision = _git_output(("rev-parse", "--verify", "HEAD")) - if REVISION_PATTERN.fullmatch(revision) is None: - raise GateError("source checkout has no full Git revision") - status = _git_output(("status", "--porcelain=v1", "--untracked-files=all")) - if status: - raise GateError( - "source checkout is dirty; build and run the gate from one committed SHA" - ) - return { - "checkout": str(ROOT.resolve(strict=True)), - "revision": revision, - "dirty": False, - "untracked_files_checked": True, - } - - -def _runtime_identity(source: Mapping[str, object]) -> dict[str, object]: - try: - pyamplicol = importlib.import_module("pyamplicol") - native = importlib.import_module("pyamplicol._rusticol") - versions = importlib.import_module("pyamplicol._internal.versions") - except ImportError as error: - raise GateError( - "the candidate pyamplicol native runtime is unavailable" - ) from error - native_path_raw = getattr(native, "__file__", None) - if not isinstance(native_path_raw, str): - raise GateError("native extension has no filesystem path") - native_digest_function = getattr(native, "native_build_inputs_sha256", None) - if not callable(native_digest_function): - raise GateError("native extension exposes no build-input digest") - native_digest = native_digest_function() - if ( - not isinstance(native_digest, str) - or SHA256_PATTERN.fullmatch(native_digest) is None - ): - raise GateError("native extension build-input digest is invalid") - build_info_function = getattr(versions, "_active_build_info", None) - build_info = build_info_function() if callable(build_info_function) else None - if not isinstance(build_info, Mapping): - raise GateError("candidate exposes no strict build provenance") - if build_info.get("source_revision") != source.get("revision"): - raise GateError( - "candidate native runtime was built from another source revision" - ) - if build_info.get("native_build_inputs_sha256") != native_digest: - raise GateError("candidate build info and native build inputs disagree") - checkout = build_info.get("source_checkout") - if not isinstance(checkout, str): - raise GateError("candidate build info has no source checkout") - try: - bound_checkout = Path(checkout).expanduser().resolve(strict=True) - except OSError as error: - raise GateError("candidate source checkout is unavailable") from error - if bound_checkout != ROOT.resolve(strict=True): - raise GateError("candidate was built from another source checkout") - package_path_raw = getattr(pyamplicol, "__file__", None) - if not isinstance(package_path_raw, str): - raise GateError("pyamplicol package has no filesystem identity") - package_roots = tuple(Path(str(path)) for path in pyamplicol.__path__) - preimport_identity = established_preimport_runtime_identity() - return { - "interpreter": { - **_file_identity(Path(sys.executable)), - "python_version": platform.python_version(), - "implementation": platform.python_implementation(), - }, - "package": { - **_file_identity(Path(package_path_raw)), - "version": str(getattr(pyamplicol, "__version__", "")), - }, - "python_package_tree": _python_package_tree_identity(package_roots), - "loaded_module_origin_policy": loaded_pyamplicol_origin_policy( - package_roots, - native_extension=Path(native_path_raw), - expected_package_identity=preimport_identity["python_package_tree"], - expected_native_identity=preimport_identity["native_extension"], - ), - "native_extension": { - **_file_identity(Path(native_path_raw)), - "build_inputs_sha256": native_digest, - }, - "active_build_info": { - "payload": dict(build_info), - "canonical_sha256": _canonical_sha256(build_info), - }, - } - - -def _stable_runtime_identity(value: Mapping[str, object]) -> dict[str, object]: - """Exclude only the monotonically growing loaded-module observation set.""" - - stable = dict(value) - raw_policy = stable.get("loaded_module_origin_policy") - if isinstance(raw_policy, Mapping): - policy = dict(raw_policy) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - policy.pop(field, None) - stable["loaded_module_origin_policy"] = policy - return stable - - -def _runtime_identity_sha256(value: Mapping[str, object]) -> str: - return _canonical_sha256(_stable_runtime_identity(value)) - - -def _peak_rss_gib() -> float: - raw = float(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) - divisor = float(1024**3 if platform.system() == "Darwin" else 1024**2) - return raw / divisor - - -def _generation_worker( - artifact: Path, - optimization_level: int, - expected_revision: str, - expected_script_sha256: str, -) -> dict[str, object]: - source = _source_identity() - if source["revision"] != expected_revision: - raise GateError("generation worker source revision changed") - script = _file_identity(Path(__file__)) - if script["sha256"] != expected_script_sha256: - raise GateError("generation worker gate script identity changed") - runtime = _runtime_identity(source) - - from pyamplicol import Generator - from pyamplicol.config import ( - ColorConfig, - EvaluatorConfig, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationValidationConfig, - JITConfig, - OutputConfig, - RunConfig, - ) - - run = RunConfig( - action="generate", - color=ColorConfig(accuracy="lc", lc_flow_layout="topology-replay"), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - validation=GenerationValidationConfig( - enabled=True, - samples=2, - seed=VALIDATION_SEED, - relative_tolerance=RELATIVE_TOLERANCE, - absolute_tolerance=ABSOLUTE_TOLERANCE, - post_build_validation=True, - ), - ), - evaluator=EvaluatorConfig( - backend="jit", - execution_mode="compiled", - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=optimization_level), - ), - output=OutputConfig(format="json", color="never", progress="off"), - ) - started_wall = time.monotonic() - started_cpu = time.process_time() - result = Generator(run).generate(PROCESS, artifact, mode="error") - source_postflight = _source_identity() - runtime_postflight = _runtime_identity(source_postflight) - script_postflight = _file_identity(Path(__file__)) - if source_postflight != source: - raise GateError("generation worker source identity changed during generation") - if _stable_runtime_identity(runtime_postflight) != _stable_runtime_identity( - runtime - ): - raise GateError("generation worker runtime identity changed during generation") - if script_postflight != script: - raise GateError("generation worker script identity changed during generation") - return { - "optimization_level": optimization_level, - "artifact": str(result.output), - "process_ids": [process.name for process in result.processes.requests], - "worker_provenance": { - "source_revision": source["revision"], - "runtime_identity_sha256": _runtime_identity_sha256(runtime), - "native_extension_sha256": runtime["native_extension"]["sha256"], - "native_build_inputs_sha256": runtime["native_extension"][ - "build_inputs_sha256" - ], - "gate_script_sha256": script["sha256"], - "postflight_identity_match": True, - }, - "generation": { - "wall_seconds": time.monotonic() - started_wall, - "process_cpu_seconds": time.process_time() - started_cpu, - "worker_peak_rss_gib": _peak_rss_gib(), - "workers": 1, - "validation_samples": 2, - "validation_seed": VALIDATION_SEED, - "post_build_validation": True, - }, - } - - -def _worker_command( - artifact: Path, - optimization_level: int, - expected_revision: str, - expected_script_sha256: str, -) -> tuple[str, ...]: - return ( - sys.executable, - "-I", - "-S", - "-B", - str(Path(__file__).resolve()), - "--_generate-one", - "--artifact", - str(artifact), - "--jit-level", - str(optimization_level), - "--expected-revision", - expected_revision, - "--expected-script-sha256", - expected_script_sha256, - ) - - -def _invoke_generation_worker( - artifact: Path, - optimization_level: int, - expected_revision: str, - expected_script_sha256: str, - *, - timeout: float, -) -> dict[str, object]: - command = _worker_command( - artifact, - optimization_level, - expected_revision, - expected_script_sha256, - ) - started = time.monotonic() - try: - completed = subprocess.run( - command, - cwd=ROOT, - check=False, - capture_output=True, - text=True, - timeout=timeout, - ) - except subprocess.TimeoutExpired as error: - raise GateError( - f"JIT O{optimization_level} generation exceeded {timeout:.1f} seconds" - ) from error - if completed.returncode != 0: - detail = completed.stderr.strip() or completed.stdout.strip() - raise GateError( - f"JIT O{optimization_level} generation failed:\n{detail[-6000:]}" - ) - try: - payload = json.loads(completed.stdout) - except json.JSONDecodeError as error: - raise GateError( - f"JIT O{optimization_level} worker emitted invalid JSON" - ) from error - if ( - not isinstance(payload, dict) - or payload.get("optimization_level") != optimization_level - ): - raise GateError(f"JIT O{optimization_level} worker returned the wrong level") - payload["orchestration_wall_seconds"] = time.monotonic() - started - payload["command"] = { - "argv": list(command), - "canonical_sha256": _canonical_sha256(list(command)), - } - if completed.stderr.strip(): - payload["worker_stderr_sha256"] = hashlib.sha256( - completed.stderr.encode() - ).hexdigest() - return payload - - -def _walk_mappings( - value: object, - *, - path: tuple[str, ...] = (), -) -> Iterable[tuple[tuple[str, ...], Mapping[str, Any]]]: - if isinstance(value, Mapping): - yield path, value - for name, child in value.items(): - yield from _walk_mappings(child, path=(*path, str(name))) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - yield from _walk_mappings(child, path=(*path, str(index))) - - -def _source_evaluator_leaves( - evaluator: Mapping[str, Any], - *, - label: str, -) -> list[Mapping[str, Any]]: - kind = evaluator.get("kind") - if kind == "symjit-application-evaluator": - return [evaluator] - if kind != "chunked-symbolica-evaluator": - raise GateError(f"{label} has unsupported evaluator kind {kind!r}") - chunks = _sequence(evaluator.get("chunks"), label=f"{label}.chunks") - leaves: list[Mapping[str, Any]] = [] - for index, raw_chunk in enumerate(chunks): - chunk = _mapping(raw_chunk, label=f"{label}.chunks[{index}]") - leaves.extend( - _source_evaluator_leaves( - chunk, - label=f"{label}.chunks[{index}]", - ) - ) - if not leaves: - raise GateError(f"{label} has no evaluator leaves") - return leaves - - -def _assert_model_parameter_not_direct(value: object, *, label: str) -> None: - if isinstance(value, Mapping): - if value.get("kind") == "compiled-plane-arena-stage": - raise GateError( - f"{label} illegally uses a compiled plane DirectApplication" - ) - if "compiled_plane_arena" in value or "native_direct_application" in value: - raise GateError(f"{label} illegally carries DirectApplication metadata") - if value.get("application_abi") in { - COMPILED_PLANE_DIRECT_APPLICATION_ABI, - NATIVE_COMPILED_DIRECT_APPLICATION_ABI, - }: - raise GateError(f"{label} illegally uses the direct application ABI") - for name, child in value.items(): - _assert_model_parameter_not_direct(child, label=f"{label}.{name}") - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - _assert_model_parameter_not_direct(child, label=f"{label}[{index}]") - - -def _audit_direct_descriptor( - descriptor: Mapping[str, Any], - *, - stage: Mapping[str, Any], - optimization_level: int, - label: str, -) -> dict[str, int]: - if descriptor.get("kind") != "compiled-plane-arena-stage": - raise GateError(f"{label}.compiled_plane_arena has the wrong kind") - if descriptor.get("schema_version") != 1: - raise GateError(f"{label}.compiled_plane_arena has the wrong schema") - expected_scalars = { - "application_abi": COMPILED_PLANE_DIRECT_APPLICATION_ABI, - "source_application_abi": SYMJIT_PLANE_APPLICATION_ABI, - "element_layout": "split-complex-component-major", - "input_output_aliasing": "forbidden", - "output_output_aliasing": "forbidden", - "output_operation": "overwrite", - "output_factor": "identity", - } - for name, expected in expected_scalars.items(): - if descriptor.get(name) != expected: - raise GateError(f"{label}.compiled_plane_arena.{name} is not {expected!r}") - - inputs = _sequence( - descriptor.get("input_bindings"), - label=f"{label}.compiled_plane_arena.input_bindings", - ) - if [ - _mapping(item, label=f"{label}.input_bindings[{index}]").get("parameter_index") - for index, item in enumerate(inputs) - ] != list(range(len(inputs))): - raise GateError(f"{label} Direct-Arena input bindings are not contiguous") - - outputs = _sequence( - descriptor.get("output_bindings"), - label=f"{label}.compiled_plane_arena.output_bindings", - ) - if [ - _mapping(item, label=f"{label}.output_bindings[{index}]").get("output_index") - for index, item in enumerate(outputs) - ] != list(range(len(outputs))): - raise GateError(f"{label} Direct-Arena output bindings are not contiguous") - - evaluator = _mapping(stage.get("evaluator"), label=f"{label}.evaluator") - source_leaves = _source_evaluator_leaves(evaluator, label=f"{label}.evaluator") - direct_leaves = _sequence( - descriptor.get("leaves"), - label=f"{label}.compiled_plane_arena.leaves", - ) - if len(direct_leaves) != len(source_leaves) or not direct_leaves: - raise GateError(f"{label} Direct-Arena/source leaf counts disagree") - - output_cursor = 0 - for index, (direct_raw, source) in enumerate( - zip(direct_leaves, source_leaves, strict=True) - ): - direct = _mapping(direct_raw, label=f"{label}.leaves[{index}]") - if ( - source.get("application_abi") != SYMJIT_APPLICATION_ABI - or source.get("runtime_capability") != SYMJIT_RUNTIME_CAPABILITY - ): - raise GateError( - f"{label} ordinary SymJIT fallback leaf identity is inconsistent" - ) - _safe_relative_path( - source.get("application_path"), - label=f"{label}.source_leaves[{index}].application_path", - ) - plane = _mapping( - source.get("plane_application"), - label=f"{label}.source_leaves[{index}].plane_application", - ) - source_path = _safe_relative_path( - plane.get("application_path"), - label=( - f"{label}.source_leaves[{index}].plane_application.application_path" - ), - ) - if ( - direct.get("application_path") != source_path - or direct.get("source_application_abi") - != SYMJIT_PLANE_APPLICATION_ABI - or plane.get("application_abi") != SYMJIT_PLANE_APPLICATION_ABI - or plane.get("storage_abi") != SYMJIT_APPLICATION_ABI - or plane.get("translation_mode") - != "symbolica-structured-instructions" - or plane.get("direct_arena") is not True - or not isinstance(plane.get("source_digest"), str) - or SHA256_PATTERN.fullmatch(str(plane.get("source_digest"))) is None - ): - raise GateError(f"{label} Direct-Arena leaf identity is inconsistent") - if ( - direct.get("optimization_level") != optimization_level - or source.get("optimization_level") != optimization_level - or plane.get("optimization_level") != optimization_level - ): - raise GateError( - f"{label} Direct-Arena/source leaf does not retain JIT " - f"O{optimization_level}" - ) - if direct.get("direct_codegen_optimization_level") != optimization_level: - raise GateError( - f"{label} Direct-Arena leaf direct codegen does not match its " - "plane application" - ) - indices = _sequence( - direct.get("input_indices"), - label=f"{label}.leaves[{index}].input_indices", - ) - if ( - any( - isinstance(value, bool) or not isinstance(value, int) or value < 0 - for value in indices - ) - or len(indices) != direct.get("input_len") - or len(indices) != source.get("input_len") - ): - raise GateError(f"{label} Direct-Arena leaf inputs are invalid") - output_start = direct.get("output_start") - output_stop = direct.get("output_stop") - output_len = direct.get("output_len") - if ( - output_start != output_cursor - or isinstance(output_stop, bool) - or not isinstance(output_stop, int) - or isinstance(output_len, bool) - or not isinstance(output_len, int) - or output_stop - output_start != output_len - or output_len != source.get("output_len") - ): - raise GateError(f"{label} Direct-Arena leaf outputs are invalid") - output_cursor = output_stop - if output_cursor != len(outputs) or output_cursor != stage.get("output_length"): - raise GateError(f"{label} Direct-Arena leaves do not cover stage outputs") - return { - "leaf_count": len(direct_leaves), - "input_binding_count": len(inputs), - "output_binding_count": len(outputs), - } - - -def _audit_execution_payload( - payload: Mapping[str, Any], - optimization_level: int, -) -> dict[str, object]: - capability_declarations = 0 - stage_set_count = 0 - stage_count = 0 - descriptor_count = 0 - leaf_count = 0 - model_parameter_slot_count = 0 - model_parameter_evaluator_count = 0 - audited_stage_sets: list[dict[str, object]] = [] - for path, record in _walk_mappings(payload): - label = ".".join(path) or "execution" - capabilities = record.get("required_runtime_capabilities") - if ( - isinstance(capabilities, Sequence) - and not isinstance(capabilities, (str, bytes)) - and COMPILED_PLANE_ARENA_CAPABILITY in capabilities - ): - capability_declarations += 1 - if "model_parameter_evaluator" in record: - model_parameter_slot_count += 1 - model_parameters = record["model_parameter_evaluator"] - if model_parameters is not None: - model_parameter_evaluator_count += 1 - _assert_model_parameter_not_direct( - model_parameters, - label=f"{label}.model_parameter_evaluator", - ) - if record.get("kind") != "generic-dag-stage-evaluator-artifacts": - continue - - stage_set_count += 1 - if record.get("runtime_available") is not True: - raise GateError(f"{label} compiled stage runtime is unavailable") - required = _sequence( - record.get("required_runtime_capabilities"), - label=f"{label}.required_runtime_capabilities", - ) - if COMPILED_PLANE_ARENA_CAPABILITY not in required: - raise GateError(f"{label} does not require compiled-plane-arena-v1") - stages = list(_sequence(record.get("stages"), label=f"{label}.stages")) - amplitude = _mapping( - record.get("amplitude_stage"), - label=f"{label}.amplitude_stage", - ) - all_stages = (*stages, amplitude) - if record.get("stage_count") != len(all_stages): - raise GateError(f"{label}.stage_count does not cover all stages") - set_leaf_count = 0 - for index, raw_stage in enumerate(all_stages): - stage = _mapping(raw_stage, label=f"{label}.stages[{index}]") - descriptor = _mapping( - stage.get("compiled_plane_arena"), - label=f"{label}.stages[{index}].compiled_plane_arena", - ) - counts = _audit_direct_descriptor( - descriptor, - stage=stage, - optimization_level=optimization_level, - label=f"{label}.stages[{index}]", - ) - stage_count += 1 - descriptor_count += 1 - leaf_count += counts["leaf_count"] - set_leaf_count += counts["leaf_count"] - audited_stage_sets.append( - { - "path": label, - "stage_count": len(all_stages), - "leaf_count": set_leaf_count, - "source_optimization_level": optimization_level, - } - ) - if capability_declarations < 1: - raise GateError("execution payload does not declare compiled-plane-arena-v1") - if stage_set_count < 1 or descriptor_count < 1 or leaf_count < 1: - raise GateError("execution payload has no complete Direct-Arena stage set") - if model_parameter_slot_count < 1: - raise GateError("execution payload has no model-parameter evaluator slot") - return { - "capability": COMPILED_PLANE_ARENA_CAPABILITY, - "source_optimization_level": optimization_level, - "capability_declaration_count": capability_declarations, - "stage_set_count": stage_set_count, - "stage_count": stage_count, - "descriptor_count": descriptor_count, - "leaf_count": leaf_count, - "model_parameter_slot_count": model_parameter_slot_count, - "model_parameter_evaluator_count": model_parameter_evaluator_count, - "model_parameter_direct_application_count": 0, - "stage_sets": audited_stage_sets, - "passes": True, - } - - -def _artifact_identity_and_audit( - artifact: Path, - optimization_level: int, -) -> tuple[dict[str, object], str]: - manifest_path = artifact / "artifact.json" - manifest = _json_object(manifest_path, label="artifact manifest") - artifact_id = manifest.get("artifact_id") - if ( - not isinstance(artifact_id, str) - or SHA256_PATTERN.fullmatch(artifact_id) is None - ): - raise GateError(f"JIT O{optimization_level} artifact ID is invalid") - processes = _sequence(manifest.get("processes"), label="artifact.processes") - if len(processes) != 1: - raise GateError( - f"JIT O{optimization_level} artifact must contain exactly one process" - ) - process = _mapping(processes[0], label="artifact.processes[0]") - if process.get("expression") != PROCESS: - raise GateError(f"JIT O{optimization_level} artifact has the wrong process") - if tuple(process.get("external_pdgs", ())) != EXPECTED_EXTERNAL_PDGS: - raise GateError(f"JIT O{optimization_level} external PDGs drifted") - if process.get("color_accuracy") != "lc": - raise GateError(f"JIT O{optimization_level} color accuracy drifted") - capabilities = _sequence( - process.get("required_runtime_capabilities"), - label="artifact.processes[0].required_runtime_capabilities", - ) - if COMPILED_PLANE_ARENA_CAPABILITY not in capabilities: - raise GateError( - f"JIT O{optimization_level} artifact lacks compiled-plane-arena-v1" - ) - process_id = process.get("id") - if not isinstance(process_id, str) or not process_id: - raise GateError(f"JIT O{optimization_level} process ID is invalid") - - try: - effective = tomllib.loads( - (artifact / "config" / "effective.toml").read_text(encoding="utf-8") - ) - except (OSError, tomllib.TOMLDecodeError) as error: - raise GateError( - f"JIT O{optimization_level} effective configuration is invalid" - ) from error - expected_config = ( - (effective.get("color", {}).get("accuracy"), "lc"), - ( - effective.get("color", {}).get("lc_flow_layout"), - "topology-replay", - ), - (effective.get("evaluator", {}).get("backend"), "jit"), - (effective.get("evaluator", {}).get("execution_mode"), "compiled"), - ( - effective.get("evaluator", {}).get("jit", {}).get("optimization_level"), - optimization_level, - ), - ) - if any(observed != expected for observed, expected in expected_config): - raise GateError( - f"JIT O{optimization_level} effective compiled configuration drifted" - ) - - payloads = _sequence(manifest.get("payloads"), label="artifact.payloads") - payload_bytes = 0 - for index, raw_payload in enumerate(payloads): - payload = _mapping(raw_payload, label=f"artifact.payloads[{index}]") - relative = _safe_relative_path( - payload.get("path"), - label=f"artifact.payloads[{index}].path", - ) - expected_size = payload.get("size_bytes") - expected_digest = payload.get("sha256") - path = artifact / relative - try: - size = path.stat().st_size - except OSError as error: - raise GateError( - f"JIT O{optimization_level} payload is missing: {relative}" - ) from error - if ( - isinstance(expected_size, bool) - or not isinstance(expected_size, int) - or size != expected_size - or not isinstance(expected_digest, str) - or _sha256_file(path) != expected_digest - ): - raise GateError( - f"JIT O{optimization_level} payload identity failed: {relative}" - ) - payload_bytes += size - - execution_path = artifact / "processes" / process_id / "execution.json" - execution = _json_object(execution_path, label="process execution") - if execution.get("color_accuracy") != "lc": - raise GateError(f"JIT O{optimization_level} execution color drifted") - arena_audit = _audit_execution_payload(execution, optimization_level) - return ( - { - "path": str(artifact.resolve(strict=True)), - "artifact_id": artifact_id, - "manifest": _file_identity(manifest_path), - "tree": _tree_identity(artifact), - "payload_count": len(payloads), - "payload_bytes": payload_bytes, - "effective_configuration": { - "process": PROCESS, - "color_accuracy": "lc", - "lc_flow_layout": "topology-replay", - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": optimization_level, - }, - "direct_arena_audit": arena_audit, - }, - process_id, - ) - - -def _deterministic_points( - count: int, -) -> tuple[tuple[tuple[float, ...], ...], ...]: - from pyamplicol.generation.phase_space import massive_rambo_final_state - - if count not in (2, 3): - raise GateError("the numerical gate requires exactly two or three points") - incoming = ( - (SQRT_S / 2.0, 0.0, 0.0, SQRT_S / 2.0), - (SQRT_S / 2.0, 0.0, 0.0, -SQRT_S / 2.0), - ) - return tuple( - ( - *incoming, - *massive_rambo_final_state( - 2, - sqrt_s=SQRT_S, - masses=(0.0, 0.0), - seed=seed, - ), - ) - for seed in POINT_SEEDS[:count] - ) - - -def _points_identity( - points: Sequence[Sequence[Sequence[float]]], -) -> dict[str, object]: - hexadecimal = [ - [[float(component).hex() for component in momentum] for momentum in point] - for point in points - ] - maximum_conservation_residual = 0.0 - maximum_mass_squared = 0.0 - for point in points: - incoming = point[:2] - outgoing = point[2:] - for component in range(4): - residual = sum(momentum[component] for momentum in incoming) - sum( - momentum[component] for momentum in outgoing - ) - maximum_conservation_residual = max( - maximum_conservation_residual, - float(abs(residual)), - ) - for momentum in point: - mass_squared = momentum[0] ** 2 - sum(value**2 for value in momentum[1:]) - maximum_mass_squared = max( - maximum_mass_squared, - float(abs(mass_squared)), - ) - if maximum_conservation_residual > 1.0e-9 or maximum_mass_squared > 1.0e-8: - raise GateError("deterministic validation momenta are not physical") - return { - "algorithm": "sha256-float-hex-momenta-v1", - "sha256": _canonical_sha256(hexadecimal), - "point_count": len(points), - "external_particle_count": len(points[0]) if points else 0, - "maximum_momentum_conservation_residual": (maximum_conservation_residual), - "maximum_abs_mass_squared": maximum_mass_squared, - } - - -def _as_complex(value: object) -> complex: - try: - result = complex(value) - except (TypeError, ValueError, OverflowError) as error: - raise GateError( - f"evaluation returned a non-numeric value: {value!r}" - ) from error - if not math.isfinite(result.real) or not math.isfinite(result.imag): - raise GateError("evaluation returned a non-finite value") - return result - - -def _flatten_resolved(resolved: object) -> tuple[complex, ...]: - return tuple( - _as_complex(value) - for point in resolved.values - for helicity in point - for value in helicity - ) - - -def _comparison( - left: Sequence[complex], - right: Sequence[complex], - *, - label: str, -) -> dict[str, object]: - if len(left) != len(right) or not left: - raise GateError(f"{label} vectors have incompatible or empty shapes") - maximum_absolute = 0.0 - maximum_relative = 0.0 - failing = 0 - for left_value, right_value in zip(left, right, strict=True): - absolute = abs(left_value - right_value) - relative = absolute / max( - abs(left_value), - abs(right_value), - ABSOLUTE_TOLERANCE, - ) - maximum_absolute = max(maximum_absolute, absolute) - maximum_relative = max(maximum_relative, relative) - if absolute > ABSOLUTE_TOLERANCE and relative > RELATIVE_TOLERANCE: - failing += 1 - result = { - "label": label, - "value_count": len(left), - "maximum_absolute_difference": maximum_absolute, - "maximum_relative_difference": maximum_relative, - "relative_tolerance": RELATIVE_TOLERANCE, - "absolute_tolerance": ABSOLUTE_TOLERANCE, - "failing_value_count": failing, - "passes": failing == 0, - } - if failing: - raise GateError( - f"{label} failed for {failing}/{len(left)} values " - f"(max relative {maximum_relative:.3e})" - ) - return result - - -def _complex_vector_digest(values: Sequence[complex]) -> str: - return _canonical_sha256([[value.real.hex(), value.imag.hex()] for value in values]) - - -def _physics_axes(physics: object) -> dict[str, object]: - return { - "process_id": physics.process_id, - "process": physics.process, - "color_accuracy": physics.color_accuracy, - "external_pdgs": [particle.pdg_id for particle in physics.external_particles], - "helicities": [ - { - "id": item.id, - "values": list(item.values), - "computed": item.computed, - "representative_id": item.representative_id, - "coefficient": item.coefficient, - } - for item in physics.helicities - ], - "color_flows": [ - { - "id": item.id, - "word": list(item.word), - "computed": item.computed, - "representative_id": item.representative_id, - "coefficient": item.coefficient, - } - for item in physics.color_flows - ], - "selector_capabilities": list(physics.selector_capabilities), - "reduction_kind": physics.reduction.kind, - } - - -def _required_nonnegative_profile_integer( - profile: Mapping[str, object], - name: str, -) -> int: - value = profile.get(name) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"native profile field {name!r} is not a non-negative integer") - return value - - -def _audit_profile(profile: Mapping[str, object]) -> dict[str, object]: - if profile.get("execution_mode") != "compiled": - raise GateError("native profile did not execute the compiled lane") - for name in _ZERO_PROFILE_COUNTERS: - value = _required_nonnegative_profile_integer(profile, name) - if value != 0: - raise GateError(f"compiled Direct-Arena profile observed {name}={value}") - for name in _ZERO_PROFILE_TIMES: - value = profile.get(name) - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or float(value) != 0.0 - ): - raise GateError( - f"compiled Direct-Arena profile observed nonzero/invalid {name}" - ) - - engine_count = _required_nonnegative_profile_integer( - profile, - _DIRECT_ENGINE_COUNTER, - ) - if engine_count < 1: - raise GateError("native profile reports no compiled Direct-Arena engines") - call_count = _required_nonnegative_profile_integer( - profile, - _DIRECT_CALL_COUNTER, - ) - if call_count < 1: - raise GateError("native profile reports no compiled Direct-Arena calls") - backend_call_count = _required_nonnegative_profile_integer( - profile, - "evaluator_backend_call_count", - ) - if backend_call_count != call_count: - raise GateError( - "compiled Direct-Arena call count does not cover every evaluator " - "backend call" - ) - - counters = { - name: _required_nonnegative_profile_integer(profile, name) - for name in ( - *_ZERO_PROFILE_COUNTERS, - _DIRECT_ENGINE_COUNTER, - _DIRECT_CALL_COUNTER, - "evaluator_backend_call_count", - ) - } - return { - "available": True, - "execution_mode": "compiled", - "direct_arena_engine_counter": { - "name": _DIRECT_ENGINE_COUNTER, - "value": engine_count, - }, - "direct_arena_call_counter": { - "name": _DIRECT_CALL_COUNTER, - "value": call_count, - }, - "zero_legacy_traffic_counters": counters, - "zero_legacy_traffic_times": { - name: float(profile[name]) for name in _ZERO_PROFILE_TIMES - }, - "passes": True, - } - - -def _runtime_execution_mode(runtime: object) -> tuple[str, str]: - value = getattr(runtime, "execution_mode", None) - if isinstance(value, str): - return value, "Runtime.execution_mode" - backend = getattr(runtime, "_backend", None) - value = getattr(backend, "execution_mode", None) - if isinstance(value, str): - return value, "native runtime adapter execution_mode" - raise GateError("loaded runtime exposes no execution-mode identity") - - -def _profile_runtime( - runtime: object, - points: Sequence[Sequence[Sequence[float]]], -) -> dict[str, object]: - profiler = getattr(runtime, "profile", None) - surface = "Runtime.profile" - if not callable(profiler): - backend = getattr(runtime, "_backend", None) - profiler = getattr(backend, "profile", None) - surface = "native runtime adapter profile" - if not callable(profiler): - raise GateError( - "installed public/runtime-adapter API exposes no profiler; " - "Direct-Arena activity cannot be proven" - ) - payload = profiler(points, precision=16, include_values=False) - if not isinstance(payload, Mapping): - raise GateError("native runtime profile is not an object") - return {**_audit_profile(payload), "surface": surface} - - -def _evaluate_artifact( - artifact: Path, - *, - process_id: str, - optimization_level: int, - points: tuple[tuple[tuple[float, ...], ...], ...], -) -> tuple[dict[str, object], EvaluationCapture]: - from pyamplicol import Runtime - - manifest_id = _json_object( - artifact / "artifact.json", - label="artifact manifest", - ).get("artifact_id") - runtime = Runtime.load(artifact, process=process_id) - if runtime.artifact_id != manifest_id: - raise GateError( - f"JIT O{optimization_level} native runtime authenticated another artifact" - ) - execution_mode, execution_mode_surface = _runtime_execution_mode(runtime) - if execution_mode != "compiled": - raise GateError(f"JIT O{optimization_level} loaded a non-compiled runtime") - physics = runtime.physics - if physics.process != PROCESS: - raise GateError(f"JIT O{optimization_level} runtime process drifted") - if tuple(particle.pdg_id for particle in physics.external_particles) != ( - EXPECTED_EXTERNAL_PDGS - ): - raise GateError(f"JIT O{optimization_level} runtime external PDGs drifted") - if physics.color_accuracy != "lc": - raise GateError(f"JIT O{optimization_level} runtime color accuracy drifted") - - f64_total = tuple(_as_complex(value) for value in runtime.evaluate(points)) - precision32_raw = runtime.evaluate(points, precision=32) - precision32_total = tuple(_as_complex(value) for value in precision32_raw) - f64_resolved = runtime.evaluate_resolved(points) - precision32_resolved = runtime.evaluate_resolved(points, precision=32) - if ( - tuple(f64_resolved.helicity_ids) != physics.helicity_ids - or tuple(precision32_resolved.helicity_ids) != physics.helicity_ids - or tuple(f64_resolved.color_ids) != physics.color_ids - or tuple(precision32_resolved.color_ids) != physics.color_ids - ): - raise GateError(f"JIT O{optimization_level} resolved physical axes drifted") - f64_components = _flatten_resolved(f64_resolved) - precision32_components = _flatten_resolved(precision32_resolved) - comparisons = { - "f64_vs_precision32_total": _comparison( - f64_total, - precision32_total, - label=f"JIT O{optimization_level} f64/precision32 totals", - ), - "f64_evaluate_vs_resolved_total": _comparison( - f64_total, - tuple(_as_complex(value) for value in f64_resolved.total()), - label=f"JIT O{optimization_level} f64 evaluate/resolved total", - ), - "precision32_evaluate_vs_resolved_total": _comparison( - precision32_total, - tuple(_as_complex(value) for value in precision32_resolved.total()), - label=(f"JIT O{optimization_level} precision32 evaluate/resolved total"), - ), - "f64_vs_precision32_resolved_components": _comparison( - f64_components, - precision32_components, - label=f"JIT O{optimization_level} f64/precision32 components", - ), - } - axes = _physics_axes(physics) - capture = EvaluationCapture( - physics_axes=axes, - f64_total=f64_total, - precision32_total=precision32_total, - f64_components=f64_components, - precision32_components=precision32_components, - ) - return ( - { - "artifact_id": runtime.artifact_id, - "execution_mode": execution_mode, - "execution_mode_surface": execution_mode_surface, - "point_count": len(points), - "point_seeds": list(POINT_SEEDS[: len(points)]), - "physics_axes": { - **axes, - "canonical_sha256": _canonical_sha256(axes), - }, - "f64_total": [[value.real, value.imag] for value in f64_total], - "precision32_total_decimal": [str(value) for value in precision32_raw], - "resolved": { - "shape": list(f64_resolved.shape), - "component_count": len(f64_components), - "f64_component_sha256": _complex_vector_digest(f64_components), - "precision32_component_sha256": _complex_vector_digest( - precision32_components - ), - }, - "comparisons": comparisons, - "native_profile": _profile_runtime(runtime, points), - "passes": True, - }, - capture, - ) - - -def _cross_level_parity( - captures: Mapping[int, EvaluationCapture], -) -> dict[str, object]: - if set(captures) != set(JIT_LEVELS): - raise GateError("cross-level parity requires O0, O1, O2, and O3") - baseline_level = 3 - baseline = captures[baseline_level] - comparisons: dict[str, dict[str, object]] = {} - for optimization_level in JIT_LEVELS: - if optimization_level == baseline_level: - continue - candidate = captures[optimization_level] - if candidate.physics_axes != baseline.physics_axes: - raise GateError( - f"JIT O{optimization_level}/O{baseline_level} physical axes differ" - ) - comparisons[f"o{optimization_level}_vs_o{baseline_level}"] = { - "f64_totals": _comparison( - candidate.f64_total, - baseline.f64_total, - label=f"JIT O{optimization_level}/O{baseline_level} f64 totals", - ), - "precision32_totals": _comparison( - candidate.precision32_total, - baseline.precision32_total, - label=( - f"JIT O{optimization_level}/O{baseline_level} precision32 totals" - ), - ), - "f64_resolved_components": _comparison( - candidate.f64_components, - baseline.f64_components, - label=( - f"JIT O{optimization_level}/O{baseline_level} " - "f64 resolved components" - ), - ), - "precision32_resolved_components": _comparison( - candidate.precision32_components, - baseline.precision32_components, - label=( - f"JIT O{optimization_level}/O{baseline_level} " - "precision32 resolved components" - ), - ), - } - return { - "baseline_optimization_level": baseline_level, - "physical_axes_sha256": _canonical_sha256(baseline.physics_axes), - "comparisons": comparisons, - "passes": True, - } - - -def _attach_content_identity(body: Mapping[str, object]) -> dict[str, object]: - result = dict(body) - result["content_identity"] = { - "algorithm": "sha256-canonical-json-body-v1", - "sha256": _canonical_sha256(body), - } - return result - - -def _write_json_atomic(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp") - encoded = json.dumps( - payload, - allow_nan=False, - ensure_ascii=False, - indent=2, - sort_keys=True, - ) - try: - temporary.write_text(encoded + "\n", encoding="utf-8") - temporary.replace(path) - except OSError as error: - temporary.unlink(missing_ok=True) - raise GateError(f"cannot write evidence: {path}") from error - - -def _lane_name(optimization_level: int) -> str: - return f"jit-o{optimization_level}" - - -def _prepare_output_root(output_root: Path, *, replace: bool) -> Path: - root = output_root.expanduser().resolve(strict=False) - if root == ROOT or root == Path(root.anchor): - raise GateError("refusing a broad output root") - try: - root.relative_to(ROOT.resolve(strict=True)) - except ValueError: - pass - else: - raise GateError( - "output root must be outside the source checkout so every isolated " - "generation worker can reauthenticate a clean revision" - ) - if root.exists(): - if not root.is_dir(): - raise GateError(f"output root is not a directory: {root}") - occupied = [ - _lane_name(level) - for level in JIT_LEVELS - if (root / _lane_name(level)).exists() - ] - if occupied and not replace: - raise GateError( - f"artifact lanes already exist ({', '.join(occupied)}); pass --replace" - ) - if replace: - for level in JIT_LEVELS: - target = root / _lane_name(level) - if target.exists(): - shutil.rmtree(target) - root.mkdir(parents=True, exist_ok=True) - return root - - -def run_gate(arguments: argparse.Namespace) -> dict[str, object]: - source = _source_identity() - runtime = _runtime_identity(source) - script = _file_identity(Path(__file__)) - output_root = _prepare_output_root( - arguments.output_root, - replace=arguments.replace, - ) - points = _deterministic_points(arguments.points) - points_identity = _points_identity(points) - levels: dict[str, dict[str, object]] = {} - captures: dict[int, EvaluationCapture] = {} - failures: list[dict[str, str]] = [] - started = time.monotonic() - expected_revision = str(source["revision"]) - expected_runtime_sha = _runtime_identity_sha256(runtime) - - for optimization_level in JIT_LEVELS: - lane_name = _lane_name(optimization_level) - artifact = output_root / lane_name - try: - generation = _invoke_generation_worker( - artifact, - optimization_level, - expected_revision, - str(script["sha256"]), - timeout=arguments.generation_timeout, - ) - worker = _mapping( - generation.get("worker_provenance"), - label=f"{lane_name}.worker_provenance", - ) - if ( - worker.get("source_revision") != expected_revision - or worker.get("runtime_identity_sha256") != expected_runtime_sha - or worker.get("gate_script_sha256") != script["sha256"] - or worker.get("postflight_identity_match") is not True - ): - raise GateError(f"{lane_name} worker provenance drifted") - identity, process_id = _artifact_identity_and_audit( - artifact, - optimization_level, - ) - numerical, capture = _evaluate_artifact( - artifact, - process_id=process_id, - optimization_level=optimization_level, - points=points, - ) - levels[lane_name] = { - "configuration": { - "process": PROCESS, - "color_accuracy": "lc", - "lc_flow_layout": "topology-replay", - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": optimization_level, - }, - "generation": generation, - "artifact_identity": identity, - "numerical_validation": numerical, - "passes": True, - } - captures[optimization_level] = capture - except (GateError, OSError, RuntimeError, ValueError) as error: - failures.append( - { - "lane": lane_name, - "error_type": type(error).__name__, - "message": str(error), - } - ) - levels[lane_name] = { - "configuration": { - "process": PROCESS, - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": optimization_level, - }, - "passes": False, - } - - try: - cross_level = _cross_level_parity(captures) - except GateError as error: - failures.append( - { - "lane": "cross-level", - "error_type": type(error).__name__, - "message": str(error), - } - ) - cross_level = {"passes": False, "message": str(error)} - source_postflight = _source_identity() - runtime_postflight = _runtime_identity(source_postflight) - script_postflight = _file_identity(Path(__file__)) - if source_postflight != source: - raise GateError("source identity changed during the all-JIT gate") - if _stable_runtime_identity(runtime_postflight) != _stable_runtime_identity( - runtime - ): - raise GateError("candidate runtime identity changed during the all-JIT gate") - if script_postflight != script: - raise GateError("gate script identity changed during the all-JIT gate") - passed = ( - not failures - and all(level.get("passes") is True for level in levels.values()) - and cross_level.get("passes") is True - ) - return _attach_content_identity( - { - "kind": RESULT_KIND, - "schema_version": SCHEMA_VERSION, - "status": "ok" if passed else "validation_failed", - "passes": passed, - "request": { - "process": PROCESS, - "jit_optimization_levels": list(JIT_LEVELS), - "point_count": arguments.points, - "point_seeds": list(POINT_SEEDS[: arguments.points]), - "momenta_identity": points_identity, - "relative_tolerance": RELATIVE_TOLERANCE, - "absolute_tolerance": ABSOLUTE_TOLERANCE, - "mandatory_watchdog_command": WATCHDOG_INVOCATION, - "memory_limit_gib": 30, - }, - "source_identity": source, - "source_identity_postflight": source_postflight, - "source_identity_match": True, - "runtime_identity": runtime, - "runtime_identity_postflight": runtime_postflight, - "runtime_identity_match": True, - "gate_script_identity": script, - "gate_script_identity_postflight": script_postflight, - "gate_script_identity_match": True, - "levels": levels, - "cross_level_numerical_parity": cross_level, - "resources": { - "orchestration_wall_seconds": time.monotonic() - started, - "orchestrator_peak_rss_gib": _peak_rss_gib(), - "mandatory_process_tree_limit_gib": 30, - }, - "failures": failures, - } - ) - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser( - description=__doc__, - epilog=f"Mandatory invocation: {WATCHDOG_INVOCATION}", - ) - result.add_argument("--output-root", type=Path) - result.add_argument( - "--evidence", - type=Path, - help="default: OUTPUT_ROOT/compiled-all-jit-arena-gate.json", - ) - result.add_argument( - "--points", - type=int, - choices=(2, 3), - default=2, - help="number of deterministic physical points (default: 2)", - ) - result.add_argument( - "--generation-timeout", - type=float, - default=3_600.0, - help="per-level generation timeout in seconds", - ) - result.add_argument( - "--replace", - action="store_true", - help="remove only the four named JIT-level directories before generation", - ) - result.add_argument("--_generate-one", action="store_true", help=argparse.SUPPRESS) - result.add_argument("--artifact", type=Path, help=argparse.SUPPRESS) - result.add_argument( - "--jit-level", - type=int, - choices=JIT_LEVELS, - help=argparse.SUPPRESS, - ) - result.add_argument("--expected-revision", help=argparse.SUPPRESS) - result.add_argument("--expected-script-sha256", help=argparse.SUPPRESS) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - _establish_preimport_runtime_identity() - if arguments._generate_one: - if ( - arguments.artifact is None - or arguments.jit_level is None - or arguments.expected_revision is None - or arguments.expected_script_sha256 is None - ): - parser().error( - "--_generate-one requires --artifact, --jit-level, and " - "--expected-revision and --expected-script-sha256" - ) - if SHA256_PATTERN.fullmatch(arguments.expected_script_sha256) is None: - parser().error("--expected-script-sha256 must be a SHA-256 digest") - try: - payload = _generation_worker( - arguments.artifact, - arguments.jit_level, - arguments.expected_revision, - arguments.expected_script_sha256, - ) - except (GateError, OSError, RuntimeError, ValueError) as error: - print(f"compiled-all-jit-arena worker: {error}", file=sys.stderr) - return 2 - print(json.dumps(payload, allow_nan=False, sort_keys=True)) - return 0 - if arguments.output_root is None: - parser().error("--output-root is required") - if arguments.generation_timeout <= 0 or not math.isfinite( - arguments.generation_timeout - ): - parser().error("--generation-timeout must be positive and finite") - evidence_path = ( - arguments.evidence - if arguments.evidence is not None - else arguments.output_root / "compiled-all-jit-arena-gate.json" - ) - try: - result = run_gate(arguments) - _write_json_atomic(evidence_path.expanduser().resolve(strict=False), result) - except (GateError, OSError, RuntimeError, ValueError) as error: - print(f"compiled-all-jit-arena: {error}", file=sys.stderr) - return 2 - print(json.dumps(result, allow_nan=False, indent=2, sort_keys=True)) - return 0 if result["passes"] else 1 - - -if __name__ == "__main__": - _ensure_source_only_python() - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/compiled_microkernel_acceptance.py b/pyamplicol/tools/developer/compiled_microkernel_acceptance.py deleted file mode 100644 index 9a4d8c8ceb..0000000000 --- a/pyamplicol/tools/developer/compiled_microkernel_acceptance.py +++ /dev/null @@ -1,2106 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Audit DirectTable microkernel evidence without importing production code. - -The input is a validated, normalized campaign document. This tool is -deliberately independent of the generator and loader that produce the -evidence: declared counts, byte totals, ordering, coverage, numerical results, -and timing gates are recomputed here. - -The normalized contract is intentionally strict. Unknown or missing fields, -compiled-stage-plan v1, incompatible direct ABIs, incomplete odd-tail data, -and malformed islands raise :class:`AcceptanceError`; a well-formed campaign -that misses a landing threshold returns ``passes: false``. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import statistics -import sys -import tomllib -from collections.abc import Mapping, Sequence -from pathlib import Path - -CAMPAIGN_KIND = "pyamplicol-compiled-microkernel-campaign" -CAMPAIGN_SCHEMA_VERSION = 2 -RESULT_KIND = "pyamplicol-compiled-microkernel-acceptance" -RESULT_SCHEMA_VERSION = 2 -STAGE_PLAN_KIND = "compiled-stage-plan" -STAGE_PLAN_SCHEMA_VERSION = 2 - -DIRECT_APPLICATION_ABI = "pyamplicol-compiled-plane-kernel-v2" -SOURCE_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -DIRECT_TABLE_BINDING_ABI = "pyamplicol-eager-plane-table-binding-v2" -DIRECT_TABLE_DESCRIPTOR_ABI = "pyamplicol-eager-plane-table-descriptor-v1" - -_ROOT = Path(__file__).resolve().parents[2] -with (_ROOT / "dependencies" / "release-lock.toml").open("rb") as _stream: - _LOCKED_SYMJIT = tomllib.load(_stream)["symjit"] -DEPENDENCY_SOURCE = "registry+https://github.com/rust-lang/crates.io-index" -DEPENDENCY_VERSION = str(_LOCKED_SYMJIT["version"]) - -TARGET_PROCESS = "u u~ > Z+6g" -TARGET_FLOW = "flow:2,4,5,6,7,8,9,1" -TARGET_LAYOUT = "topology-replay" -TARGET_COLOR_ACCURACY = "lc" -TARGET_HELICITY_MODE = "sum" - -REQUIRED_BATCHES = (1, 127, 128, 129, 1023, 1024, 1025) -PRIMARY_BATCHES = (128, 1024) -MIN_SAMPLE_PAIRS = 7 -MIN_SAMPLE_DURATION_SECONDS = 5.0 -MIN_PRIMARY_GAIN = 0.10 -MAX_BATCH_ONE_REGRESSION = 0.05 -MAX_RESOURCE_REGRESSION = 0.10 -MIN_CODE_SIZE_REDUCTION = 0.25 -MAX_NON_TARGET_REGRESSION = 0.02 -MAD_MULTIPLIER = 3.0 -RELATIVE_TOLERANCE = 1.0e-12 -ABSOLUTE_TOLERANCE = 1.0e-15 - -MAX_KERNEL_IDENTITIES = 8 -MAX_COMPLEX_INPUTS = 16 -MAX_COMPLEX_OUTPUTS = 4 -VECTOR_WEYL_KERNEL_FAMILY = "vector-weyl" -THREE_VECTOR_SINGLETON_KERNEL_FAMILY = "three-vector-singleton" -EXACT_CODE_SIZE_METRIC = "executed-selected-machine-code-scalar-plus-simd-v1" -MAX_KERNEL_SOURCE_BYTES = 64 * 1024 -MAX_SEMANTIC_ROW_BYTES = 4 * 1024 * 1024 -MIN_CENSUS_COVERAGE = 0.50 -MAX_PROJECTED_TEXT_FRACTION = 0.25 - -CENSUS_DENOMINATOR_CONTRACT = ( - "materialized-active-repeated-prepared-kernel-occurrences-v1" -) -TARGET_ACTIVE_NON_SOURCE_CURRENT_SLOTS = 55 -TARGET_MATERIALIZED_INTERACTIONS = 203 -TARGET_TWO_COMPONENT_CURRENT_SLOTS = 26 -TARGET_THREE_VECTOR_SINGLETON_CURRENT_SLOTS = 5 -TARGET_ELIGIBLE_PREPARED_KERNEL_OCCURRENCES = 103 -TARGET_ACTIVE_PREPARED_KERNEL_COUNTS = { - 4: 35, - 7: 49, - 24: 49, - 36: 40, - 41: 30, -} -TARGET_ELIGIBLE_PREPARED_KERNEL_COUNTS = { - 4: 5, - 7: 49, - 24: 49, -} -TARGET_PROOF_DAG_NON_SOURCE_CURRENT_SLOTS = 1425 -TARGET_PROOF_DAG_INTERACTIONS = 8338 - -REQUIRED_REGRESSION_CASES = frozenset( - { - "z6g-lc-union", - "gg-ttbar-3g-nlc", - "gg-ttbar-3g-full-color", - "ddbar-z3g-residual-only", - "builtin-model", - "ufo-sm-model", - "four-quark-lines-lc", - "four-quark-lines-nlc", - "four-quark-lines-full-color", - "mutable-parameters", - "structural-zeros", - "global-selectors", - "per-point-selectors", - "malformed-plans", - } -) -REQUIRED_NON_TARGET_PERFORMANCE = frozenset({"z6g-lc-union", "eager"}) - -_SHA256_LENGTH = 64 -_DIAGNOSTIC_KEYS = frozenset( - { - "island_count", - "kernel_count", - "invocation_count", - "attachment_count", - "table_machine_code_bytes", - "residual_machine_code_bytes", - "semantic_row_bytes", - "arena_bytes", - "warmed_allocation_count", - } -) - - -class AcceptanceError(RuntimeError): - """Raised when evidence is malformed or incomplete.""" - - -def _error(path: str, message: str) -> None: - raise AcceptanceError(f"{path}: {message}") - - -def _mapping(value: object, path: str) -> Mapping[str, object]: - if not isinstance(value, Mapping): - _error(path, "expected an object") - if not all(isinstance(key, str) for key in value): - _error(path, "object keys must be strings") - return value - - -def _sequence(value: object, path: str) -> Sequence[object]: - if isinstance(value, (str, bytes)) or not isinstance(value, Sequence): - _error(path, "expected an array") - return value - - -def _exact_keys( - value: Mapping[str, object], - expected: frozenset[str] | set[str], - path: str, -) -> None: - actual = set(value) - missing = sorted(expected - actual) - extra = sorted(actual - expected) - if missing or extra: - _error(path, f"field mismatch; missing={missing}, extra={extra}") - - -def _integer( - value: object, - path: str, - *, - minimum: int | None = None, -) -> int: - if isinstance(value, bool) or not isinstance(value, int): - _error(path, "expected an integer") - if minimum is not None and value < minimum: - _error(path, f"must be at least {minimum}") - return value - - -def _number( - value: object, - path: str, - *, - minimum: float | None = None, -) -> float: - if isinstance(value, bool) or not isinstance(value, (int, float)): - _error(path, "expected a finite number") - result = float(value) - if not math.isfinite(result): - _error(path, "expected a finite number") - if minimum is not None and result < minimum: - _error(path, f"must be at least {minimum}") - return result - - -def _positive_number(value: object, path: str) -> float: - result = _number(value, path) - if result <= 0.0: - _error(path, "must be greater than zero") - return result - - -def _string(value: object, path: str, *, nonempty: bool = True) -> str: - if not isinstance(value, str): - _error(path, "expected a string") - if nonempty and not value: - _error(path, "must not be empty") - return value - - -def _sha256(value: object, path: str) -> str: - result = _string(value, path) - if len(result) != _SHA256_LENGTH: - _error(path, "expected a lowercase SHA-256 digest") - if any(character not in "0123456789abcdef" for character in result): - _error(path, "expected a lowercase SHA-256 digest") - return result - - -def canonical_sha256(value: object) -> str: - """Return the canonical JSON SHA-256 used by evidence certificates.""" - - try: - payload = json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("utf-8") - except (TypeError, ValueError) as exc: - raise AcceptanceError(f"value is not canonical JSON: {exc}") from exc - return hashlib.sha256(payload).hexdigest() - - -def _authenticated_digest(value: Mapping[str, object], path: str) -> str: - declared = _sha256(value.get("sha256"), f"{path}.sha256") - payload = {key: item for key, item in value.items() if key != "sha256"} - actual = canonical_sha256(payload) - if declared != actual: - _error(path, f"SHA-256 mismatch: declared {declared}, computed {actual}") - return declared - - -def _unique_integers( - value: object, - path: str, - *, - minimum: int | None = 0, -) -> list[int]: - result = [ - _integer(item, f"{path}[{index}]", minimum=minimum) - for index, item in enumerate(_sequence(value, path)) - ] - if len(result) != len(set(result)): - _error(path, "values must be unique") - return result - - -def _unique_strings(value: object, path: str) -> list[str]: - result = [ - _string(item, f"{path}[{index}]") - for index, item in enumerate(_sequence(value, path)) - ] - if len(result) != len(set(result)): - _error(path, "values must be unique") - return result - - -def _dense_ids(values: Sequence[int], path: str) -> None: - if list(values) != list(range(len(values))): - _error(path, "IDs must be dense, ordered, and zero-based") - - -def _validate_diagnostics(value: object, path: str) -> dict[str, int]: - diagnostics = _mapping(value, path) - _exact_keys(diagnostics, _DIAGNOSTIC_KEYS, path) - return { - key: _integer(diagnostics[key], f"{path}.{key}", minimum=0) - for key in sorted(_DIAGNOSTIC_KEYS) - } - - -def _validate_residual_leaf( - value: object, - path: str, - residual_current_ids: set[int], -) -> tuple[int, list[int]]: - leaf = _mapping(value, path) - _exact_keys( - leaf, - { - "leaf_id", - "current_ids", - "source_sha256", - "source_abi", - "source_bytes", - "machine_code_bytes", - "optimization_level", - }, - path, - ) - _integer(leaf["leaf_id"], f"{path}.leaf_id", minimum=0) - current_ids = _unique_integers(leaf["current_ids"], f"{path}.current_ids") - if not current_ids: - _error(f"{path}.current_ids", "must not be empty") - if not set(current_ids) <= residual_current_ids: - _error(f"{path}.current_ids", "contains a non-residual destination") - _sha256(leaf["source_sha256"], f"{path}.source_sha256") - if leaf["source_abi"] != DIRECT_APPLICATION_ABI: - _error(f"{path}.source_abi", "incompatible DirectApplication ABI") - _integer(leaf["source_bytes"], f"{path}.source_bytes", minimum=1) - machine_code_bytes = _integer( - leaf["machine_code_bytes"], - f"{path}.machine_code_bytes", - minimum=0, - ) - if leaf["optimization_level"] != 3: - _error(f"{path}.optimization_level", "compiled residuals must use O3") - return machine_code_bytes, current_ids - - -def _validate_kernel(value: object, path: str) -> dict[str, object]: - kernel = _mapping(value, path) - _exact_keys( - kernel, - { - "kernel_id", - "kernel_family", - "motif_sha256", - "source_sha256", - "descriptor_sha256", - "source_abi", - "binding_abi", - "descriptor_abi", - "canonical_input_order", - "input_permutation", - "result_signature", - "mutable_parameter_sha256", - "coupling_provenance_sha256", - "selector_domain_sha256", - "finalizer_sha256", - "input_complex_count", - "output_complex_count", - "source_bytes", - "machine_code_bytes", - "optimization_level", - }, - path, - ) - kernel_id = _integer(kernel["kernel_id"], f"{path}.kernel_id", minimum=0) - kernel_family = _string(kernel["kernel_family"], f"{path}.kernel_family") - if kernel_family not in { - VECTOR_WEYL_KERNEL_FAMILY, - THREE_VECTOR_SINGLETON_KERNEL_FAMILY, - }: - _error( - f"{path}.kernel_family", - "only vector-Weyl and singleton three-vector kernels are authorized", - ) - for field in ( - "motif_sha256", - "source_sha256", - "descriptor_sha256", - "mutable_parameter_sha256", - "coupling_provenance_sha256", - "selector_domain_sha256", - "finalizer_sha256", - ): - _sha256(kernel[field], f"{path}.{field}") - expected_abis = { - "source_abi": DIRECT_APPLICATION_ABI, - "binding_abi": DIRECT_TABLE_BINDING_ABI, - "descriptor_abi": DIRECT_TABLE_DESCRIPTOR_ABI, - } - for field, expected in expected_abis.items(): - if kernel[field] != expected: - _error(f"{path}.{field}", f"expected {expected!r}") - canonical_order = _unique_strings( - kernel["canonical_input_order"], - f"{path}.canonical_input_order", - ) - if not canonical_order: - _error(f"{path}.canonical_input_order", "must not be empty") - permutation = _unique_integers( - kernel["input_permutation"], - f"{path}.input_permutation", - ) - if sorted(permutation) != list(range(len(canonical_order))): - _error(f"{path}.input_permutation", "must permute every canonical input") - result_signature = _string( - kernel["result_signature"], - f"{path}.result_signature", - ) - input_count = _integer( - kernel["input_complex_count"], - f"{path}.input_complex_count", - minimum=1, - ) - output_count = _integer( - kernel["output_complex_count"], - f"{path}.output_complex_count", - minimum=1, - ) - if input_count > MAX_COMPLEX_INPUTS: - _error(f"{path}.input_complex_count", "exceeds the initial-slice bound") - if input_count != len(canonical_order): - _error( - f"{path}.input_complex_count", - "must match the canonical input descriptor count", - ) - if ( - kernel_family == THREE_VECTOR_SINGLETON_KERNEL_FAMILY - and input_count != MAX_COMPLEX_INPUTS - ): - _error( - f"{path}.input_complex_count", - "the authorized three-vector family requires exactly 16 inputs", - ) - expected_result = { - VECTOR_WEYL_KERNEL_FAMILY: ("vector-weyl:2", 2), - THREE_VECTOR_SINGLETON_KERNEL_FAMILY: ("three-vector:4", 4), - }[kernel_family] - if (result_signature, output_count) != expected_result: - _error( - path, - f"{kernel_family!r} requires result signature/output {expected_result!r}", - ) - source_bytes = _integer( - kernel["source_bytes"], - f"{path}.source_bytes", - minimum=1, - ) - if source_bytes > MAX_KERNEL_SOURCE_BYTES: - _error(f"{path}.source_bytes", "exceeds 64 KiB") - machine_code_bytes = _integer( - kernel["machine_code_bytes"], - f"{path}.machine_code_bytes", - minimum=0, - ) - if kernel["optimization_level"] != 3: - _error(f"{path}.optimization_level", "microkernels must use O3") - return { - "kernel_id": kernel_id, - "kernel_family": kernel_family, - "motif_sha256": kernel["motif_sha256"], - "output_complex_count": output_count, - "machine_code_bytes": machine_code_bytes, - "finalizer_sha256": kernel["finalizer_sha256"], - } - - -def _validate_certificate( - value: object, - path: str, - *, - kind: str, - island_current_ids: list[int], - order: bool, -) -> dict[int, list[int]]: - certificate = _mapping(value, path) - _exact_keys(certificate, {"kind", "rows", "sha256"}, path) - if certificate["kind"] != kind: - _error(f"{path}.kind", f"expected {kind!r}") - rows = _sequence(certificate["rows"], f"{path}.rows") - parsed: dict[int, list[int]] = {} - value_field = "evaluation_group_ids" if order else "predecessor_current_ids" - for index, raw_row in enumerate(rows): - row_path = f"{path}.rows[{index}]" - row = _mapping(raw_row, row_path) - _exact_keys(row, {"current_id", value_field}, row_path) - current_id = _integer(row["current_id"], f"{row_path}.current_id") - if current_id in parsed: - _error(f"{row_path}.current_id", "duplicate certificate current") - parsed[current_id] = _unique_integers( - row[value_field], - f"{row_path}.{value_field}", - minimum=None if order else 0, - ) - if set(parsed) != set(island_current_ids): - _error(f"{path}.rows", "must cover exactly the island destinations") - if not order: - island_set = set(island_current_ids) - for current_id, predecessors in parsed.items(): - conflict = (set(predecessors) & island_set) - {current_id} - if conflict: - _error( - f"{path}.rows", - "dependency certificate groups dependent destinations " - f"{current_id} and {sorted(conflict)}", - ) - _authenticated_digest(certificate, path) - return parsed - - -def _validate_island( - value: object, - path: str, - kernels: Mapping[int, Mapping[str, object]], - table_current_ids: set[int], -) -> dict[str, object]: - island = _mapping(value, path) - _exact_keys( - island, - { - "island_id", - "kernel_id", - "current_ids", - "selector_partition_sha256", - "invocations", - "attachments", - "factor_catalog", - "plane_bindings", - "dependency_certificate", - "order_certificate", - "semantic_row_bytes", - "arena_bytes", - }, - path, - ) - island_id = _integer(island["island_id"], f"{path}.island_id", minimum=0) - kernel_id = _integer(island["kernel_id"], f"{path}.kernel_id", minimum=0) - if kernel_id not in kernels: - _error(f"{path}.kernel_id", "references an unknown kernel") - kernel = kernels[kernel_id] - current_ids = _unique_integers(island["current_ids"], f"{path}.current_ids") - if not current_ids: - _error(f"{path}.current_ids", "must not be empty") - if not set(current_ids) <= table_current_ids: - _error(f"{path}.current_ids", "contains a non-table destination") - _sha256( - island["selector_partition_sha256"], - f"{path}.selector_partition_sha256", - ) - - factor_rows = _sequence(island["factor_catalog"], f"{path}.factor_catalog") - factor_ids: list[int] = [] - for index, raw_factor in enumerate(factor_rows): - factor_path = f"{path}.factor_catalog[{index}]" - factor = _mapping(raw_factor, factor_path) - _exact_keys(factor, {"factor_id", "factor_sha256"}, factor_path) - factor_ids.append( - _integer(factor["factor_id"], f"{factor_path}.factor_id", minimum=0) - ) - _sha256(factor["factor_sha256"], f"{factor_path}.factor_sha256") - _dense_ids(factor_ids, f"{path}.factor_catalog.factor_id") - - binding_rows = _sequence(island["plane_bindings"], f"{path}.plane_bindings") - binding_ids: list[int] = [] - binding_roles: set[str] = set() - for index, raw_binding in enumerate(binding_rows): - binding_path = f"{path}.plane_bindings[{index}]" - binding = _mapping(raw_binding, binding_path) - _exact_keys( - binding, - {"plane_id", "role", "canonical_index", "permutation_index"}, - binding_path, - ) - binding_ids.append( - _integer(binding["plane_id"], f"{binding_path}.plane_id", minimum=0) - ) - role = _string(binding["role"], f"{binding_path}.role") - if role not in {"current", "momentum", "parameter", "factor"}: - _error(f"{binding_path}.role", "unknown plane role") - binding_roles.add(role) - _integer( - binding["canonical_index"], - f"{binding_path}.canonical_index", - minimum=0, - ) - _integer( - binding["permutation_index"], - f"{binding_path}.permutation_index", - minimum=0, - ) - _dense_ids(binding_ids, f"{path}.plane_bindings.plane_id") - if binding_roles != {"current", "momentum", "parameter", "factor"}: - _error(f"{path}.plane_bindings", "must bind all four plane roles") - - invocation_rows = _sequence(island["invocations"], f"{path}.invocations") - invocation_ids: list[int] = [] - invocations: dict[int, tuple[int, int, int]] = {} - for index, raw_invocation in enumerate(invocation_rows): - invocation_path = f"{path}.invocations[{index}]" - invocation = _mapping(raw_invocation, invocation_path) - _exact_keys( - invocation, - { - "invocation_id", - "evaluation_group_id", - "attachment_start", - "attachment_count", - }, - invocation_path, - ) - invocation_id = _integer( - invocation["invocation_id"], - f"{invocation_path}.invocation_id", - minimum=0, - ) - invocation_ids.append(invocation_id) - invocations[invocation_id] = ( - _integer( - invocation["evaluation_group_id"], - f"{invocation_path}.evaluation_group_id", - ), - _integer( - invocation["attachment_start"], - f"{invocation_path}.attachment_start", - minimum=0, - ), - _integer( - invocation["attachment_count"], - f"{invocation_path}.attachment_count", - minimum=1, - ), - ) - if not invocation_ids: - _error(f"{path}.invocations", "must not be empty") - _dense_ids(invocation_ids, f"{path}.invocations.invocation_id") - invocation_group_ids = [values[0] for values in invocations.values()] - if len(invocation_group_ids) != len(set(invocation_group_ids)): - _error( - f"{path}.invocations", - "materialized occurrence IDs must be unique within an island", - ) - - attachment_rows = _sequence(island["attachments"], f"{path}.attachments") - attachment_ids: list[int] = [] - actual_by_current: dict[int, list[tuple[int, str]]] = { - current_id: [] for current_id in current_ids - } - for index, raw_attachment in enumerate(attachment_rows): - attachment_path = f"{path}.attachments[{index}]" - attachment = _mapping(raw_attachment, attachment_path) - _exact_keys( - attachment, - { - "attachment_id", - "invocation_id", - "current_id", - "evaluation_group_id", - "operation", - "destination_complex_count", - "factor_id", - }, - attachment_path, - ) - attachment_id = _integer( - attachment["attachment_id"], - f"{attachment_path}.attachment_id", - minimum=0, - ) - attachment_ids.append(attachment_id) - invocation_id = _integer( - attachment["invocation_id"], - f"{attachment_path}.invocation_id", - minimum=0, - ) - if invocation_id not in invocations: - _error(f"{attachment_path}.invocation_id", "unknown invocation") - evaluation_group_id = _integer( - attachment["evaluation_group_id"], - f"{attachment_path}.evaluation_group_id", - ) - invocation_group, start, count = invocations[invocation_id] - if evaluation_group_id != invocation_group: - _error( - f"{attachment_path}.evaluation_group_id", - "does not match its invocation", - ) - if not start <= attachment_id < start + count: - _error( - f"{attachment_path}.attachment_id", - "lies outside its invocation range", - ) - current_id = _integer( - attachment["current_id"], - f"{attachment_path}.current_id", - minimum=0, - ) - if current_id not in actual_by_current: - _error(f"{attachment_path}.current_id", "unknown island destination") - operation = _string( - attachment["operation"], - f"{attachment_path}.operation", - ) - if operation not in {"overwrite", "accumulate"}: - _error(f"{attachment_path}.operation", "unknown write operation") - destination_count = _integer( - attachment["destination_complex_count"], - f"{attachment_path}.destination_complex_count", - minimum=1, - ) - if destination_count != kernel["output_complex_count"]: - _error( - f"{attachment_path}.destination_complex_count", - "attachment does not bind the complete kernel destination", - ) - factor_id = _integer( - attachment["factor_id"], - f"{attachment_path}.factor_id", - minimum=0, - ) - if factor_id not in set(factor_ids): - _error(f"{attachment_path}.factor_id", "unknown factor") - actual_by_current[current_id].append((evaluation_group_id, operation)) - if not attachment_ids: - _error(f"{path}.attachments", "must not be empty") - _dense_ids(attachment_ids, f"{path}.attachments.attachment_id") - - expected_start = 0 - for invocation_id in invocation_ids: - _, start, count = invocations[invocation_id] - if start != expected_start: - _error( - f"{path}.invocations[{invocation_id}].attachment_start", - "invocation attachment ranges must be contiguous", - ) - owned = [ - index - for index, raw_attachment in enumerate(attachment_rows) - if _mapping(raw_attachment, path)["invocation_id"] == invocation_id - ] - if owned != list(range(start, start + count)): - _error( - f"{path}.invocations[{invocation_id}]", - "declared range does not exactly own its attachment rows", - ) - expected_start += count - if expected_start != len(attachment_rows): - _error(f"{path}.invocations", "ranges do not cover every attachment") - - dependency_rows = _validate_certificate( - island["dependency_certificate"], - f"{path}.dependency_certificate", - kind="complete-current-independence-v1", - island_current_ids=current_ids, - order=False, - ) - if set(dependency_rows) != set(current_ids): - _error(f"{path}.dependency_certificate", "internal coverage mismatch") - order_rows = _validate_certificate( - island["order_certificate"], - f"{path}.order_certificate", - kind="evaluation-group-order-v1", - island_current_ids=current_ids, - order=True, - ) - for current_id, actual_rows in actual_by_current.items(): - if not actual_rows: - _error(f"{path}.attachments", f"current {current_id} is unwritten") - operations = [operation for _, operation in actual_rows] - if operations[0] != "overwrite": - _error(f"{path}.attachments", f"current {current_id} is not initialized") - if any(operation != "accumulate" for operation in operations[1:]): - _error( - f"{path}.attachments", - f"current {current_id} has an invalid later write", - ) - groups = [group for group, _ in actual_rows] - if groups != order_rows[current_id]: - _error( - f"{path}.order_certificate", - f"current {current_id} attachment order differs", - ) - if kernel["kernel_family"] == THREE_VECTOR_SINGLETON_KERNEL_FAMILY: - if any(len(rows) != 1 for rows in actual_by_current.values()): - _error( - f"{path}.attachments", - "three-vector islands may own only singleton currents", - ) - if any(count != 1 for _, _, count in invocations.values()): - _error( - f"{path}.invocations", - "three-vector singleton invocations must attach exactly once", - ) - if len(invocation_rows) != len(current_ids): - _error( - path, - "three-vector singleton islands require one invocation per current", - ) - - semantic_row_bytes = _integer( - island["semantic_row_bytes"], - f"{path}.semantic_row_bytes", - minimum=0, - ) - arena_bytes = _integer( - island["arena_bytes"], - f"{path}.arena_bytes", - minimum=0, - ) - return { - "island_id": island_id, - "kernel_id": kernel_id, - "kernel_family": kernel["kernel_family"], - "current_ids": current_ids, - "evaluation_group_ids": sorted({values[0] for values in invocations.values()}), - "invocation_count": len(invocation_rows), - "attachment_count": len(attachment_rows), - "semantic_row_bytes": semantic_row_bytes, - "arena_bytes": arena_bytes, - } - - -def audit_stage_plan_v2(value: object, path: str = "stage_plan") -> dict[str, object]: - """Validate and independently summarize one normalized v2 stage plan.""" - - plan = _mapping(value, path) - _exact_keys( - plan, - { - "kind", - "schema_version", - "stage_id", - "direct_application_abi", - "direct_table_binding_abi", - "direct_table_descriptor_abi", - "output_current_ids", - "table_current_ids", - "residual_current_ids", - "residual_leaves", - "kernels", - "islands", - "finalizers", - "diagnostics", - }, - path, - ) - if plan["kind"] != STAGE_PLAN_KIND: - _error(f"{path}.kind", f"expected {STAGE_PLAN_KIND!r}") - if plan["schema_version"] != STAGE_PLAN_SCHEMA_VERSION: - _error( - f"{path}.schema_version", - "compiled-stage-plan v2 is required; regenerate the artifact", - ) - stage_id = _string(plan["stage_id"], f"{path}.stage_id") - expected_abis = { - "direct_application_abi": DIRECT_APPLICATION_ABI, - "direct_table_binding_abi": DIRECT_TABLE_BINDING_ABI, - "direct_table_descriptor_abi": DIRECT_TABLE_DESCRIPTOR_ABI, - } - for field, expected in expected_abis.items(): - if plan[field] != expected: - _error(f"{path}.{field}", f"expected {expected!r}; regenerate artifact") - - output_ids = _unique_integers( - plan["output_current_ids"], - f"{path}.output_current_ids", - ) - if not output_ids: - _error(f"{path}.output_current_ids", "must not be empty") - table_ids = _unique_integers( - plan["table_current_ids"], - f"{path}.table_current_ids", - ) - residual_ids = _unique_integers( - plan["residual_current_ids"], - f"{path}.residual_current_ids", - ) - if set(table_ids) & set(residual_ids): - _error(path, "a destination may not be split between table and residual") - if set(table_ids) | set(residual_ids) != set(output_ids): - _error(path, "table and residual destinations must partition all outputs") - - residual_rows = _sequence(plan["residual_leaves"], f"{path}.residual_leaves") - residual_leaf_ids: list[int] = [] - residual_machine_code_bytes = 0 - residual_owned: list[int] = [] - for index, raw_leaf in enumerate(residual_rows): - leaf_path = f"{path}.residual_leaves[{index}]" - leaf = _mapping(raw_leaf, leaf_path) - residual_leaf_ids.append( - _integer(leaf.get("leaf_id"), f"{leaf_path}.leaf_id", minimum=0) - ) - machine_bytes, owned = _validate_residual_leaf( - raw_leaf, - leaf_path, - set(residual_ids), - ) - residual_machine_code_bytes += machine_bytes - residual_owned.extend(owned) - _dense_ids(residual_leaf_ids, f"{path}.residual_leaves.leaf_id") - if len(residual_owned) != len(set(residual_owned)): - _error(f"{path}.residual_leaves", "residual destinations overlap") - if set(residual_owned) != set(residual_ids): - _error(f"{path}.residual_leaves", "must own every residual destination") - - kernel_rows = _sequence(plan["kernels"], f"{path}.kernels") - if len(kernel_rows) > MAX_KERNEL_IDENTITIES: - _error(f"{path}.kernels", "exceeds eight kernel identities") - kernels: dict[int, Mapping[str, object]] = {} - motif_ids: set[object] = set() - kernel_machine_code_bytes = 0 - kernel_ids: list[int] = [] - for index, raw_kernel in enumerate(kernel_rows): - kernel_path = f"{path}.kernels[{index}]" - summary = _validate_kernel(raw_kernel, kernel_path) - kernel_id = int(summary["kernel_id"]) - kernel_ids.append(kernel_id) - if summary["motif_sha256"] in motif_ids: - _error(f"{kernel_path}.motif_sha256", "duplicate canonical motif") - motif_ids.add(summary["motif_sha256"]) - kernels[kernel_id] = summary - kernel_machine_code_bytes += int(summary["machine_code_bytes"]) - _dense_ids(kernel_ids, f"{path}.kernels.kernel_id") - - island_rows = _sequence(plan["islands"], f"{path}.islands") - island_ids: list[int] = [] - island_summaries: list[dict[str, object]] = [] - table_owned: list[int] = [] - for index, raw_island in enumerate(island_rows): - island_path = f"{path}.islands[{index}]" - summary = _validate_island( - raw_island, - island_path, - kernels, - set(table_ids), - ) - island_ids.append(int(summary["island_id"])) - island_summaries.append(summary) - table_owned.extend(summary["current_ids"]) # type: ignore[arg-type] - _dense_ids(island_ids, f"{path}.islands.island_id") - if len(table_owned) != len(set(table_owned)): - _error(f"{path}.islands", "table destinations overlap between islands") - if set(table_owned) != set(table_ids): - _error(f"{path}.islands", "must own every table destination") - if bool(kernel_rows) != bool(island_rows): - _error(path, "unused kernels and kernel-less islands are forbidden") - - finalizer_rows = _sequence(plan["finalizers"], f"{path}.finalizers") - finalized: list[int] = [] - island_by_current = { - current_id: summary - for summary in island_summaries - for current_id in summary["current_ids"] # type: ignore[union-attr] - } - for index, raw_finalizer in enumerate(finalizer_rows): - finalizer_path = f"{path}.finalizers[{index}]" - finalizer = _mapping(raw_finalizer, finalizer_path) - _exact_keys( - finalizer, - {"current_id", "island_id", "identity_sha256"}, - finalizer_path, - ) - current_id = _integer( - finalizer["current_id"], - f"{finalizer_path}.current_id", - minimum=0, - ) - finalized.append(current_id) - if current_id not in island_by_current: - _error(f"{finalizer_path}.current_id", "not a table destination") - expected_island = island_by_current[current_id] - if finalizer["island_id"] != expected_island["island_id"]: - _error( - f"{finalizer_path}.island_id", - "finalizer must run after its complete island", - ) - kernel = kernels[int(expected_island["kernel_id"])] - identity = _sha256( - finalizer["identity_sha256"], - f"{finalizer_path}.identity_sha256", - ) - if identity != kernel["finalizer_sha256"]: - _error( - f"{finalizer_path}.identity_sha256", - "does not match the canonical motif finalizer", - ) - if len(finalized) != len(set(finalized)) or set(finalized) != set(table_ids): - _error(f"{path}.finalizers", "must finalize every table destination once") - - declared = _validate_diagnostics(plan["diagnostics"], f"{path}.diagnostics") - recomputed = { - "island_count": len(island_rows), - "kernel_count": len(kernel_rows), - "invocation_count": sum( - int(summary["invocation_count"]) for summary in island_summaries - ), - "attachment_count": sum( - int(summary["attachment_count"]) for summary in island_summaries - ), - "table_machine_code_bytes": kernel_machine_code_bytes, - "residual_machine_code_bytes": residual_machine_code_bytes, - "semantic_row_bytes": sum( - int(summary["semantic_row_bytes"]) for summary in island_summaries - ), - "arena_bytes": sum(int(summary["arena_bytes"]) for summary in island_summaries), - # This counter comes from the runtime allocation probe, while every - # other field above is derivable from static plan rows. - "warmed_allocation_count": declared["warmed_allocation_count"], - } - if declared != recomputed: - _error( - f"{path}.diagnostics", - f"declared values differ from recomputed values: {recomputed}", - ) - return { - "stage_id": stage_id, - "diagnostics": recomputed, - "table_occurrence_families": { - f"{stage_id}:{group_id}": str(summary["kernel_family"]) - for summary in island_summaries - for group_id in summary["evaluation_group_ids"] # type: ignore[union-attr] - }, - "table_destination_family_counts": { - family: sum( - len(summary["current_ids"]) # type: ignore[arg-type] - for summary in island_summaries - if summary["kernel_family"] == family - ) - for family in ( - VECTOR_WEYL_KERNEL_FAMILY, - THREE_VECTOR_SINGLETON_KERNEL_FAMILY, - ) - }, - "residual_only": not table_ids, - "table_only": not residual_ids, - } - - -def _sum_diagnostics( - summaries: Sequence[Mapping[str, object]], -) -> dict[str, int]: - return { - key: sum( - int(_mapping(summary["diagnostics"], "summary.diagnostics")[key]) - for summary in summaries - ) - for key in sorted(_DIAGNOSTIC_KEYS) - } - - -def _validate_census( - value: object, - path: str, - table_occurrence_families: Mapping[str, str], - table_destination_family_counts: Mapping[str, int], -) -> dict[str, float | int]: - census = _mapping(value, path) - _exact_keys( - census, - { - "denominator_contract", - "active_non_source_current_slots", - "materialized_interaction_count", - "two_component_current_slots", - "four_component_three_vector_singleton_slots", - "active_prepared_kernel_occurrences", - "eligible_prepared_kernel_occurrence_ids", - "proof_dag_non_source_current_slots", - "proof_dag_interaction_count", - "projected_generated_text_bytes", - "projected_replaced_text_bytes", - }, - path, - ) - if census["denominator_contract"] != CENSUS_DENOMINATOR_CONTRACT: - _error( - f"{path}.denominator_contract", - "coverage denominator must be all repeated prepared-kernel " - "occurrences in the materialized executable schedule", - ) - expected_counts = { - "active_non_source_current_slots": TARGET_ACTIVE_NON_SOURCE_CURRENT_SLOTS, - "materialized_interaction_count": TARGET_MATERIALIZED_INTERACTIONS, - "two_component_current_slots": TARGET_TWO_COMPONENT_CURRENT_SLOTS, - "four_component_three_vector_singleton_slots": ( - TARGET_THREE_VECTOR_SINGLETON_CURRENT_SLOTS - ), - "proof_dag_non_source_current_slots": ( - TARGET_PROOF_DAG_NON_SOURCE_CURRENT_SLOTS - ), - "proof_dag_interaction_count": TARGET_PROOF_DAG_INTERACTIONS, - } - for field, expected in expected_counts.items(): - actual = _integer(census[field], f"{path}.{field}", minimum=0) - if actual != expected: - _error( - f"{path}.{field}", - f"expected frozen target census count {expected}, got {actual}", - ) - if ( - census["active_non_source_current_slots"] - == (census["proof_dag_non_source_current_slots"]) - or census["materialized_interaction_count"] - == (census["proof_dag_interaction_count"]) - ): - _error(path, "proof-DAG counts are mislabeled as active schedule counts") - - active_rows = _sequence( - census["active_prepared_kernel_occurrences"], - f"{path}.active_prepared_kernel_occurrences", - ) - active: dict[str, int] = {} - for index, raw_row in enumerate(active_rows): - row_path = f"{path}.active_prepared_kernel_occurrences[{index}]" - row = _mapping(raw_row, row_path) - _exact_keys(row, {"occurrence_id", "prepared_kernel_id"}, row_path) - occurrence_id = _string(row["occurrence_id"], f"{row_path}.occurrence_id") - if occurrence_id in active: - _error(f"{row_path}.occurrence_id", "duplicate occurrence") - active[occurrence_id] = _integer( - row["prepared_kernel_id"], - f"{row_path}.prepared_kernel_id", - minimum=0, - ) - if len(active) != TARGET_MATERIALIZED_INTERACTIONS: - _error( - f"{path}.active_prepared_kernel_occurrences", - f"must enumerate all {TARGET_MATERIALIZED_INTERACTIONS} occurrences", - ) - active_kernel_counts: dict[int, int] = {} - for prepared_kernel_id in active.values(): - active_kernel_counts[prepared_kernel_id] = ( - active_kernel_counts.get(prepared_kernel_id, 0) + 1 - ) - if active_kernel_counts != TARGET_ACTIVE_PREPARED_KERNEL_COUNTS: - _error( - f"{path}.active_prepared_kernel_occurrences", - "prepared-kernel distribution differs from the frozen census: " - f"{active_kernel_counts}", - ) - if any(count < 2 for count in active_kernel_counts.values()): - _error( - f"{path}.active_prepared_kernel_occurrences", - "the denominator may contain only repeated prepared kernels", - ) - eligible = set( - _unique_strings( - census["eligible_prepared_kernel_occurrence_ids"], - f"{path}.eligible_prepared_kernel_occurrence_ids", - ) - ) - if not eligible <= set(active): - _error( - f"{path}.eligible_prepared_kernel_occurrence_ids", - "must be an active subset", - ) - if eligible != set(table_occurrence_families): - _error( - f"{path}.eligible_prepared_kernel_occurrence_ids", - "must exactly match occurrences covered by table invocations", - ) - eligible_kernel_counts: dict[int, int] = {} - for occurrence_id in eligible: - prepared_kernel_id = active[occurrence_id] - eligible_kernel_counts[prepared_kernel_id] = ( - eligible_kernel_counts.get(prepared_kernel_id, 0) + 1 - ) - expected_family = ( - THREE_VECTOR_SINGLETON_KERNEL_FAMILY - if prepared_kernel_id == 4 - else VECTOR_WEYL_KERNEL_FAMILY - ) - if table_occurrence_families[occurrence_id] != expected_family: - _error( - f"{path}.eligible_prepared_kernel_occurrence_ids", - f"{occurrence_id} binds the wrong structural kernel family", - ) - if eligible_kernel_counts != TARGET_ELIGIBLE_PREPARED_KERNEL_COUNTS: - _error( - f"{path}.eligible_prepared_kernel_occurrence_ids", - "eligible prepared-kernel distribution must be exactly " - f"{TARGET_ELIGIBLE_PREPARED_KERNEL_COUNTS}, got " - f"{eligible_kernel_counts}", - ) - expected_destination_counts = { - VECTOR_WEYL_KERNEL_FAMILY: TARGET_TWO_COMPONENT_CURRENT_SLOTS, - THREE_VECTOR_SINGLETON_KERNEL_FAMILY: ( - TARGET_THREE_VECTOR_SINGLETON_CURRENT_SLOTS - ), - } - if dict(table_destination_family_counts) != expected_destination_counts: - _error( - path, - "table destination family counts must match the authorized " - f"complete-current slice {expected_destination_counts}", - ) - coverage = len(eligible) / len(active) - if len(eligible) != TARGET_ELIGIBLE_PREPARED_KERNEL_OCCURRENCES: - _error( - f"{path}.eligible_prepared_kernel_occurrence_ids", - f"expected {TARGET_ELIGIBLE_PREPARED_KERNEL_OCCURRENCES} occurrences", - ) - if coverage < MIN_CENSUS_COVERAGE: - _error( - f"{path}.eligible_prepared_kernel_occurrence_ids", - "coverage is below 50%", - ) - - generated = _integer( - census["projected_generated_text_bytes"], - f"{path}.projected_generated_text_bytes", - minimum=0, - ) - replaced = _integer( - census["projected_replaced_text_bytes"], - f"{path}.projected_replaced_text_bytes", - minimum=1, - ) - fraction = generated / replaced - if fraction > MAX_PROJECTED_TEXT_FRACTION: - _error( - f"{path}.projected_generated_text_bytes", - "projected text exceeds 25% of replaced text", - ) - return { - "active_prepared_kernel_occurrence_count": len(active), - "eligible_prepared_kernel_occurrence_count": len(eligible), - "coverage": coverage, - "projected_text_fraction": fraction, - } - - -def _validate_artifact_metrics( - value: object, - path: str, -) -> dict[str, object]: - artifact = _mapping(value, path) - _exact_keys( - artifact, - { - "artifact_sha256", - "build_identity_sha256", - "generation_seconds", - "artifact_bytes", - "load_seconds", - "peak_rss_bytes", - "code_size_metric_available", - "code_size_metric_kind", - "selected_machine_code_bytes", - "portable_source_applications", - }, - path, - ) - metric_available = artifact["code_size_metric_available"] - if not isinstance(metric_available, bool): - _error(f"{path}.code_size_metric_available", "expected a boolean") - metric_kind = artifact["code_size_metric_kind"] - selected_machine_code: int | None - if metric_available: - if metric_kind != EXACT_CODE_SIZE_METRIC: - _error( - f"{path}.code_size_metric_kind", - f"must identify exact executed code as {EXACT_CODE_SIZE_METRIC!r}", - ) - selected_machine_code = _integer( - artifact["selected_machine_code_bytes"], - f"{path}.selected_machine_code_bytes", - minimum=1, - ) - else: - if metric_kind is not None: - _error( - f"{path}.code_size_metric_kind", - "must be null when the exact metric is unavailable", - ) - if artifact["selected_machine_code_bytes"] is not None: - _error( - f"{path}.selected_machine_code_bytes", - "must be null when the exact machine-code metric is unavailable", - ) - selected_machine_code = None - applications = _sequence( - artifact["portable_source_applications"], - f"{path}.portable_source_applications", - ) - portable_source_bytes = 0 - portable_source_digests: list[str] = [] - for index, raw_application in enumerate(applications): - application_path = f"{path}.portable_source_applications[{index}]" - application = _mapping(raw_application, application_path) - _exact_keys( - application, - { - "source_application_sha256", - "source_application_bytes", - "source_application_abi", - }, - application_path, - ) - digest = _sha256( - application["source_application_sha256"], - f"{application_path}.source_application_sha256", - ) - if digest in portable_source_digests: - _error(application_path, "portable source payloads must be deduplicated") - portable_source_digests.append(digest) - portable_source_bytes += _integer( - application["source_application_bytes"], - f"{application_path}.source_application_bytes", - minimum=1, - ) - if application["source_application_abi"] != SOURCE_APPLICATION_ABI: - _error( - f"{application_path}.source_application_abi", - f"expected {SOURCE_APPLICATION_ABI!r}", - ) - if not applications: - _error(f"{path}.portable_source_applications", "must not be empty") - return { - "artifact_sha256": _sha256( - artifact["artifact_sha256"], - f"{path}.artifact_sha256", - ), - "build_identity_sha256": _sha256( - artifact["build_identity_sha256"], - f"{path}.build_identity_sha256", - ), - "generation_seconds": _positive_number( - artifact["generation_seconds"], - f"{path}.generation_seconds", - ), - "artifact_bytes": _integer( - artifact["artifact_bytes"], - f"{path}.artifact_bytes", - minimum=1, - ), - "load_seconds": _positive_number( - artifact["load_seconds"], - f"{path}.load_seconds", - ), - "peak_rss_bytes": _integer( - artifact["peak_rss_bytes"], - f"{path}.peak_rss_bytes", - minimum=1, - ), - "code_size_metric_available": metric_available, - "code_size_metric_kind": metric_kind, - "selected_machine_code_bytes": selected_machine_code, - "portable_source_application_bytes": portable_source_bytes, - "portable_source_application_set_sha256": canonical_sha256( - portable_source_digests - ), - } - - -def _validate_candidate( - value: object, - path: str, -) -> tuple[dict[str, object], dict[str, object]]: - candidate = _mapping(value, path) - _exact_keys( - candidate, - { - "metrics", - "stage_plans", - "diagnostics", - "census", - }, - path, - ) - metrics = _validate_artifact_metrics(candidate["metrics"], f"{path}.metrics") - stage_rows = _sequence(candidate["stage_plans"], f"{path}.stage_plans") - if not stage_rows: - _error(f"{path}.stage_plans", "must not be empty") - summaries = [ - audit_stage_plan_v2(row, f"{path}.stage_plans[{index}]") - for index, row in enumerate(stage_rows) - ] - stage_ids = [str(summary["stage_id"]) for summary in summaries] - if len(stage_ids) != len(set(stage_ids)): - _error(f"{path}.stage_plans", "stage IDs must be unique") - diagnostics = _validate_diagnostics( - candidate["diagnostics"], - f"{path}.diagnostics", - ) - recomputed = _sum_diagnostics(summaries) - if diagnostics != recomputed: - _error( - f"{path}.diagnostics", - f"artifact totals differ from stage totals: {recomputed}", - ) - if diagnostics["semantic_row_bytes"] > MAX_SEMANTIC_ROW_BYTES: - _error(f"{path}.diagnostics.semantic_row_bytes", "exceeds 4 MiB") - if diagnostics["kernel_count"] > MAX_KERNEL_IDENTITIES: - _error(f"{path}.diagnostics.kernel_count", "exceeds eight identities") - concrete_machine_code_bytes = ( - diagnostics["table_machine_code_bytes"] - + diagnostics["residual_machine_code_bytes"] - ) - selected_machine_code_bytes = metrics["selected_machine_code_bytes"] - if ( - metrics["code_size_metric_available"] is True - and isinstance(selected_machine_code_bytes, int) - and selected_machine_code_bytes < concrete_machine_code_bytes - ): - _error( - f"{path}.metrics.selected_machine_code_bytes", - "is smaller than concrete table plus residual machine code", - ) - table_occurrence_families: dict[str, str] = {} - table_destination_family_counts = { - VECTOR_WEYL_KERNEL_FAMILY: 0, - THREE_VECTOR_SINGLETON_KERNEL_FAMILY: 0, - } - for summary in summaries: - occurrence_families = _mapping( - summary["table_occurrence_families"], - "summary.table_occurrence_families", - ) - overlap = set(table_occurrence_families) & set(occurrence_families) - if overlap: - _error( - f"{path}.stage_plans", - f"table occurrence IDs overlap: {sorted(overlap)}", - ) - table_occurrence_families.update( - {str(key): str(item) for key, item in occurrence_families.items()} - ) - destination_counts = _mapping( - summary["table_destination_family_counts"], - "summary.table_destination_family_counts", - ) - for family in table_destination_family_counts: - table_destination_family_counts[family] += int(destination_counts[family]) - census = _validate_census( - candidate["census"], - f"{path}.census", - table_occurrence_families, - table_destination_family_counts, - ) - return metrics, { - "diagnostics": diagnostics, - "census": census, - "stage_count": len(summaries), - "residual_only_stage_count": sum( - bool(summary["residual_only"]) for summary in summaries - ), - "table_only_stage_count": sum( - bool(summary["table_only"]) for summary in summaries - ), - } - - -def _complex_array(value: object, path: str, expected_length: int) -> list[complex]: - rows = _sequence(value, path) - if len(rows) != expected_length: - _error(path, f"expected {expected_length} complex values") - result: list[complex] = [] - for index, raw_pair in enumerate(rows): - pair_path = f"{path}[{index}]" - pair = _sequence(raw_pair, pair_path) - if len(pair) != 2: - _error(pair_path, "complex values must be [real, imag]") - result.append( - complex( - _number(pair[0], f"{pair_path}[0]"), - _number(pair[1], f"{pair_path}[1]"), - ) - ) - return result - - -def _resolved_array( - value: object, - path: str, - expected_length: int, -) -> list[list[complex]]: - rows = _sequence(value, path) - if len(rows) != expected_length: - _error(path, f"expected {expected_length} point rows") - result: list[list[complex]] = [] - for index, raw_row in enumerate(rows): - row_path = f"{path}[{index}]" - entries = _sequence(raw_row, row_path) - if not entries: - _error(row_path, "resolved contributions must not be empty") - result.append(_complex_array(entries, row_path, len(entries))) - return result - - -def _close(left: complex, right: complex) -> bool: - return abs(left - right) <= (ABSOLUTE_TOLERANCE + RELATIVE_TOLERANCE * abs(right)) - - -def _assert_close_arrays( - left: Sequence[complex], - right: Sequence[complex], - path: str, -) -> float: - if len(left) != len(right): - _error(path, "array shapes differ") - maximum = 0.0 - for index, (actual, expected) in enumerate(zip(left, right, strict=True)): - difference = abs(actual - expected) - maximum = max(maximum, difference) - if not _close(actual, expected): - _error( - f"{path}[{index}]", - f"{actual!r} differs from {expected!r}", - ) - return maximum - - -def _validate_correctness( - value: object, - path: str, - batch: int, -) -> dict[str, float]: - correctness = _mapping(value, path) - _exact_keys(correctness, {"baseline", "candidate"}, path) - lanes: dict[str, dict[str, object]] = {} - for lane in ("baseline", "candidate"): - lane_path = f"{path}.{lane}" - raw_lane = _mapping(correctness[lane], lane_path) - _exact_keys( - raw_lane, - {"evaluate", "resolved_total", "resolved_contributions"}, - lane_path, - ) - evaluated = _complex_array( - raw_lane["evaluate"], - f"{lane_path}.evaluate", - batch, - ) - total = _complex_array( - raw_lane["resolved_total"], - f"{lane_path}.resolved_total", - batch, - ) - resolved = _resolved_array( - raw_lane["resolved_contributions"], - f"{lane_path}.resolved_contributions", - batch, - ) - lanes[lane] = { - "evaluate": evaluated, - "resolved_total": total, - "resolved_contributions": resolved, - } - _assert_close_arrays( - evaluated, - total, - f"{lane_path}.evaluate_vs_resolved_total", - ) - _assert_close_arrays( - [sum(row, start=0j) for row in resolved], - total, - f"{lane_path}.resolved_contributions_vs_total", - ) - - baseline = lanes["baseline"] - candidate = lanes["candidate"] - total_error = _assert_close_arrays( - candidate["evaluate"], # type: ignore[arg-type] - baseline["evaluate"], # type: ignore[arg-type] - f"{path}.candidate_vs_baseline_total", - ) - baseline_resolved = baseline["resolved_contributions"] - candidate_resolved = candidate["resolved_contributions"] - if not isinstance(baseline_resolved, list) or not isinstance( - candidate_resolved, - list, - ): - _error(path, "internal resolved representation error") - resolved_error = 0.0 - for point_index, (candidate_row, baseline_row) in enumerate( - zip(candidate_resolved, baseline_resolved, strict=True) - ): - resolved_error = max( - resolved_error, - _assert_close_arrays( - candidate_row, - baseline_row, - f"{path}.candidate_vs_baseline_resolved[{point_index}]", - ), - ) - return { - "maximum_total_absolute_error": total_error, - "maximum_resolved_absolute_error": resolved_error, - } - - -def _median_and_mad(values: Sequence[float]) -> tuple[float, float]: - median = statistics.median(values) - mad = statistics.median(abs(value - median) for value in values) - return median, mad - - -def _validate_measurements( - value: object, - path: str, -) -> dict[str, object]: - rows = _sequence(value, path) - if len(rows) < 2 * MIN_SAMPLE_PAIRS or len(rows) % 2: - _error(path, "requires at least seven complete subprocess pairs") - parsed: list[dict[str, float | int | str]] = [] - for index, raw_row in enumerate(rows): - row_path = f"{path}[{index}]" - row = _mapping(raw_row, row_path) - _exact_keys( - row, - { - "pair_index", - "sequence_index", - "lane", - "duration_seconds", - "seconds_per_point", - "warmed_allocation_count", - }, - row_path, - ) - lane = _string(row["lane"], f"{row_path}.lane") - if lane not in {"baseline", "candidate"}: - _error(f"{row_path}.lane", "expected baseline or candidate") - duration = _number( - row["duration_seconds"], - f"{row_path}.duration_seconds", - minimum=0.0, - ) - if duration < MIN_SAMPLE_DURATION_SECONDS: - _error(f"{row_path}.duration_seconds", "sample ran for under 5 s") - allocations = _integer( - row["warmed_allocation_count"], - f"{row_path}.warmed_allocation_count", - minimum=0, - ) - parsed.append( - { - "pair_index": _integer( - row["pair_index"], - f"{row_path}.pair_index", - minimum=0, - ), - "sequence_index": _integer( - row["sequence_index"], - f"{row_path}.sequence_index", - minimum=0, - ), - "lane": lane, - "duration_seconds": duration, - "seconds_per_point": _positive_number( - row["seconds_per_point"], - f"{row_path}.seconds_per_point", - ), - "warmed_allocation_count": allocations, - } - ) - if [row["sequence_index"] for row in parsed] != list(range(len(parsed))): - _error(path, "sequence indices must be ordered, dense, and zero-based") - pair_count = len(parsed) // 2 - pairs: list[tuple[float, float]] = [] - first_lane = str(parsed[0]["lane"]) - second_lane = "candidate" if first_lane == "baseline" else "baseline" - for pair_index in range(pair_count): - first = parsed[2 * pair_index] - second = parsed[2 * pair_index + 1] - if first["pair_index"] != pair_index or second["pair_index"] != pair_index: - _error(path, "pair indices must be dense and align with sequence order") - expected_order = ( - (first_lane, second_lane) - if pair_index % 2 == 0 - else (second_lane, first_lane) - ) - if (first["lane"], second["lane"]) != expected_order: - _error(path, "subprocess lane order must alternate between pairs") - by_lane = {str(first["lane"]): first, str(second["lane"]): second} - pairs.append( - ( - float(by_lane["baseline"]["seconds_per_point"]), - float(by_lane["candidate"]["seconds_per_point"]), - ) - ) - baseline_values = [pair[0] for pair in pairs] - candidate_values = [pair[1] for pair in pairs] - changes = [baseline - candidate for baseline, candidate in pairs] - baseline_median, baseline_mad = _median_and_mad(baseline_values) - candidate_median, candidate_mad = _median_and_mad(candidate_values) - change_median, change_mad = _median_and_mad(changes) - return { - "pair_count": pair_count, - "baseline_median_seconds_per_point": baseline_median, - "baseline_mad_seconds_per_point": baseline_mad, - "candidate_median_seconds_per_point": candidate_median, - "candidate_mad_seconds_per_point": candidate_mad, - "paired_change_median_seconds_per_point": change_median, - "paired_change_mad_seconds_per_point": change_mad, - "relative_gain": (baseline_median - candidate_median) / baseline_median, - "paired_change_beyond_three_mad": (change_median > MAD_MULTIPLIER * change_mad), - "candidate_warmed_allocation_count": max( - int(row["warmed_allocation_count"]) - for row in parsed - if row["lane"] == "candidate" - ), - } - - -def _validate_workload(value: object, path: str) -> None: - workload = _mapping(value, path) - _exact_keys( - workload, - { - "process", - "color_accuracy", - "lc_flow_layout", - "selected_flow", - "helicity_mode", - "source_sha256", - "model_sha256", - "point_set_sha256", - "runtime_target_sha256", - "host_sha256", - }, - path, - ) - expected = { - "process": TARGET_PROCESS, - "color_accuracy": TARGET_COLOR_ACCURACY, - "lc_flow_layout": TARGET_LAYOUT, - "selected_flow": TARGET_FLOW, - "helicity_mode": TARGET_HELICITY_MODE, - } - for field, expected_value in expected.items(): - if workload[field] != expected_value: - _error(f"{path}.{field}", f"expected {expected_value!r}") - for field in ( - "source_sha256", - "model_sha256", - "point_set_sha256", - "runtime_target_sha256", - "host_sha256", - ): - _sha256(workload[field], f"{path}.{field}") - - -def _validate_dependency(value: object, path: str) -> None: - dependency = _mapping(value, path) - _exact_keys( - dependency, - { - "source", - "version", - "local_patch_count", - "direct_application_abi", - "direct_table_binding_abi", - "direct_table_descriptor_abi", - }, - path, - ) - expected = { - "source": DEPENDENCY_SOURCE, - "version": DEPENDENCY_VERSION, - "local_patch_count": 0, - "direct_application_abi": DIRECT_APPLICATION_ABI, - "direct_table_binding_abi": DIRECT_TABLE_BINDING_ABI, - "direct_table_descriptor_abi": DIRECT_TABLE_DESCRIPTOR_ABI, - } - for field, expected_value in expected.items(): - if dependency[field] != expected_value: - _error(f"{path}.{field}", f"expected {expected_value!r}") - - -def _gate( - gates: dict[str, dict[str, object]], - name: str, - passed: bool, - **details: object, -) -> None: - gates[name] = {"passes": bool(passed), **details} - - -def _validate_regressions( - functional_value: object, - performance_value: object, - gates: dict[str, dict[str, object]], -) -> None: - functional_rows = _sequence(functional_value, "campaign.regression_cases") - seen: set[str] = set() - for index, raw_case in enumerate(functional_rows): - path = f"campaign.regression_cases[{index}]" - case = _mapping(raw_case, path) - _exact_keys(case, {"name", "passed", "evidence_sha256"}, path) - name = _string(case["name"], f"{path}.name") - if name in seen: - _error(f"{path}.name", "duplicate regression case") - seen.add(name) - if not isinstance(case["passed"], bool): - _error(f"{path}.passed", "expected a boolean") - _sha256(case["evidence_sha256"], f"{path}.evidence_sha256") - _gate(gates, f"regression:{name}", bool(case["passed"])) - missing = sorted(REQUIRED_REGRESSION_CASES - seen) - if missing: - _error("campaign.regression_cases", f"missing required cases: {missing}") - - performance_rows = _sequence( - performance_value, - "campaign.non_target_performance", - ) - performance_seen: set[str] = set() - for index, raw_lane in enumerate(performance_rows): - path = f"campaign.non_target_performance[{index}]" - lane = _mapping(raw_lane, path) - _exact_keys( - lane, - {"name", "baseline_seconds_per_point", "candidate_seconds_per_point"}, - path, - ) - name = _string(lane["name"], f"{path}.name") - if name in performance_seen: - _error(f"{path}.name", "duplicate performance lane") - performance_seen.add(name) - baseline = [ - _positive_number( - item, - f"{path}.baseline_seconds_per_point[{item_index}]", - ) - for item_index, item in enumerate( - _sequence( - lane["baseline_seconds_per_point"], - f"{path}.baseline_seconds_per_point", - ) - ) - ] - candidate = [ - _positive_number( - item, - f"{path}.candidate_seconds_per_point[{item_index}]", - ) - for item_index, item in enumerate( - _sequence( - lane["candidate_seconds_per_point"], - f"{path}.candidate_seconds_per_point", - ) - ) - ] - if len(baseline) < MIN_SAMPLE_PAIRS or len(candidate) < MIN_SAMPLE_PAIRS: - _error(path, "requires at least seven samples in each lane") - baseline_median, baseline_mad = _median_and_mad(baseline) - candidate_median, _ = _median_and_mad(candidate) - relative_regression = (candidate_median - baseline_median) / baseline_median - absolute_regression = candidate_median - baseline_median - passed = ( - relative_regression <= MAX_NON_TARGET_REGRESSION - or absolute_regression <= MAD_MULTIPLIER * baseline_mad - ) - _gate( - gates, - f"non_target_performance:{name}", - passed, - relative_regression=relative_regression, - absolute_regression_seconds_per_point=absolute_regression, - baseline_mad_seconds_per_point=baseline_mad, - ) - missing_performance = sorted(REQUIRED_NON_TARGET_PERFORMANCE - performance_seen) - if missing_performance: - _error( - "campaign.non_target_performance", - f"missing required lanes: {missing_performance}", - ) - - -def audit_campaign(value: object) -> dict[str, object]: - """Audit a complete baseline/candidate campaign.""" - - campaign = _mapping(value, "campaign") - _exact_keys( - campaign, - { - "kind", - "schema_version", - "content_sha256", - "dependency", - "workload", - "baseline", - "candidate", - "batches", - "regression_cases", - "non_target_performance", - }, - "campaign", - ) - if campaign["kind"] != CAMPAIGN_KIND: - _error("campaign.kind", f"expected {CAMPAIGN_KIND!r}") - if campaign["schema_version"] != CAMPAIGN_SCHEMA_VERSION: - _error("campaign.schema_version", "unsupported campaign schema") - declared_digest = _sha256( - campaign["content_sha256"], - "campaign.content_sha256", - ) - actual_digest = canonical_sha256( - {key: item for key, item in campaign.items() if key != "content_sha256"} - ) - if declared_digest != actual_digest: - _error( - "campaign.content_sha256", - f"declared {declared_digest}, computed {actual_digest}", - ) - _validate_dependency(campaign["dependency"], "campaign.dependency") - _validate_workload(campaign["workload"], "campaign.workload") - baseline = _validate_artifact_metrics(campaign["baseline"], "campaign.baseline") - candidate, candidate_summary = _validate_candidate( - campaign["candidate"], - "campaign.candidate", - ) - - gates: dict[str, dict[str, object]] = {} - resource_fields = ( - "generation_seconds", - "artifact_bytes", - "load_seconds", - "peak_rss_bytes", - ) - for field in resource_fields: - baseline_value = float(baseline[field]) - candidate_value = float(candidate[field]) - ratio = candidate_value / baseline_value - _gate( - gates, - f"resource:{field}", - ratio <= 1.0 + MAX_RESOURCE_REGRESSION, - candidate_to_baseline_ratio=ratio, - ) - code_size_available = ( - baseline["code_size_metric_available"] is True - and candidate["code_size_metric_available"] is True - ) - if code_size_available: - machine_code_ratio = float(candidate["selected_machine_code_bytes"]) / float( - baseline["selected_machine_code_bytes"] - ) - _gate( - gates, - "selected_machine_code_reduction", - machine_code_ratio <= 1.0 - MIN_CODE_SIZE_REDUCTION, - metric_available=True, - candidate_to_baseline_ratio=machine_code_ratio, - ) - else: - _gate( - gates, - "selected_machine_code_reduction", - False, - metric_available=False, - reason=( - "exact residual portable-source-application machine-code " - "shape is unavailable from the pinned SymJIT API" - ), - ) - diagnostics = _mapping( - candidate_summary["diagnostics"], - "candidate_summary.diagnostics", - ) - batches = _mapping(campaign["batches"], "campaign.batches") - if set(batches) != {str(batch) for batch in REQUIRED_BATCHES}: - _error( - "campaign.batches", - f"must contain exactly batches {list(REQUIRED_BATCHES)}", - ) - batch_summaries: dict[str, object] = {} - measured_candidate_allocations = 0 - workload = _mapping(campaign["workload"], "campaign.workload") - for batch in REQUIRED_BATCHES: - path = f"campaign.batches.{batch}" - batch_value = _mapping(batches[str(batch)], path) - _exact_keys( - batch_value, - {"point_set_sha256", "correctness", "measurements"}, - path, - ) - point_digest = _sha256( - batch_value["point_set_sha256"], - f"{path}.point_set_sha256", - ) - if point_digest != workload["point_set_sha256"]: - _error( - f"{path}.point_set_sha256", - "must match the campaign point-set identity", - ) - correctness = _validate_correctness( - batch_value["correctness"], - f"{path}.correctness", - batch, - ) - measurements = _validate_measurements( - batch_value["measurements"], - f"{path}.measurements", - ) - measured_candidate_allocations = max( - measured_candidate_allocations, - int(measurements["candidate_warmed_allocation_count"]), - ) - batch_summaries[str(batch)] = { - "correctness": correctness, - "performance": measurements, - } - relative_gain = float(measurements["relative_gain"]) - if batch in PRIMARY_BATCHES: - _gate( - gates, - f"primary_gain:batch_{batch}", - ( - relative_gain >= MIN_PRIMARY_GAIN - and bool(measurements["paired_change_beyond_three_mad"]) - ), - relative_gain=relative_gain, - paired_change_beyond_three_mad=measurements[ - "paired_change_beyond_three_mad" - ], - ) - if batch == 1: - regression = -relative_gain - _gate( - gates, - "batch_1_regression", - regression <= MAX_BATCH_ONE_REGRESSION, - relative_regression=regression, - ) - warmed_allocations = max( - int(diagnostics["warmed_allocation_count"]), - measured_candidate_allocations, - ) - _gate( - gates, - "zero_warmed_allocations", - warmed_allocations == 0, - warmed_allocation_count=warmed_allocations, - ) - _validate_regressions( - campaign["regression_cases"], - campaign["non_target_performance"], - gates, - ) - - return { - "kind": RESULT_KIND, - "schema_version": RESULT_SCHEMA_VERSION, - "campaign_sha256": declared_digest, - "passes": all(bool(gate["passes"]) for gate in gates.values()), - "gates": gates, - "candidate": candidate_summary, - "code_size_diagnostics": { - "baseline_metric_available": baseline["code_size_metric_available"], - "candidate_metric_available": candidate["code_size_metric_available"], - "baseline_metric_kind": baseline["code_size_metric_kind"], - "candidate_metric_kind": candidate["code_size_metric_kind"], - "baseline_portable_source_application_bytes": baseline[ - "portable_source_application_bytes" - ], - "candidate_portable_source_application_bytes": candidate[ - "portable_source_application_bytes" - ], - "portable_source_metric_is_machine_code": False, - }, - "batches": batch_summaries, - } - - -def _reject_duplicate_pairs(pairs: list[tuple[str, object]]) -> dict[str, object]: - result: dict[str, object] = {} - for key, value in pairs: - if key in result: - raise AcceptanceError(f"duplicate JSON object key {key!r}") - result[key] = value - return result - - -def load_campaign(path: Path) -> Mapping[str, object]: - """Load JSON while rejecting duplicate keys and non-finite constants.""" - - def reject_constant(value: str) -> object: - raise AcceptanceError(f"non-finite JSON constant {value!r}") - - try: - value = json.loads( - path.read_text(encoding="utf-8"), - object_pairs_hook=_reject_duplicate_pairs, - parse_constant=reject_constant, - ) - except (OSError, UnicodeError, json.JSONDecodeError) as exc: - raise AcceptanceError(f"cannot load {path}: {exc}") from exc - return _mapping(value, str(path)) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("campaign", type=Path) - parser.add_argument( - "--output", - type=Path, - help="write the acceptance result as canonical JSON", - ) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - args = _parser().parse_args(argv) - try: - result = audit_campaign(load_campaign(args.campaign)) - except AcceptanceError as exc: - print(f"compiled-microkernel-acceptance: {exc}", file=sys.stderr) - return 2 - rendered = json.dumps(result, indent=2, sort_keys=True) + "\n" - if args.output is None: - sys.stdout.write(rendered) - else: - args.output.write_text(rendered, encoding="utf-8") - return 0 if result["passes"] else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/emit_candidate_structural_preflight.py b/pyamplicol/tools/developer/emit_candidate_structural_preflight.py deleted file mode 100644 index ae08351c08..0000000000 --- a/pyamplicol/tools/developer/emit_candidate_structural_preflight.py +++ /dev/null @@ -1,358 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Atomically attach exact structural restart evidence to one generated artifact.""" - -from __future__ import annotations - -import argparse -import json -import os -import re -import tempfile -from pathlib import Path -from typing import Any - -from pyamplicol.artifacts.manifest import load_manifest -from pyamplicol.generation.structural_source_proof import ( - ROLE as STRUCTURAL_SOURCE_PROOF_ROLE, -) -from pyamplicol.generation.structural_source_proof import ( - SEMANTIC_MAP_DOMAINS, - validate_generation_structural_proof, -) -from tools.developer.catalog_final_source_structural_preflight import ( - CELL_PROOF_SCHEMA, - FinalSourceProducerError, -) -from tools.developer.catalog_structural_parity_audit import ( - _candidate_counts, - _compiled_execution_lanes, -) -from tools.developer.final_source_numerical_truth import ( - TruthProducerError, - validate_witness_payload, -) -from tools.performance_report.models import Workload - -PROOF_PATH = "structural-preflight-proof.json" -_REVISION = re.compile(r"[0-9a-f]{40}") - - -def _read(path: Path) -> dict[str, Any]: - value = json.loads(path.read_text()) - if not isinstance(value, dict): - raise FinalSourceProducerError(f"{path} must contain a JSON object") - return value - - -def _execution(artifact: Path) -> tuple[Path, dict[str, Any]]: - paths = sorted((artifact / "processes").glob("*/execution.json")) - if len(paths) != 1: - raise FinalSourceProducerError( - "structural proof emission requires exactly one concrete process" - ) - return paths[0], _read(paths[0]) - - -def _source_counts( - execution: dict[str, Any], - workload: Workload, -) -> tuple[int, int, int]: - kind = execution.get("kind") - if kind == "pyamplicol-runtime-recurrence-execution": - schedule = execution["plan"]["inspection_summary"]["schedule"] - count = schedule.get("source_row_count") - if not isinstance(count, int) or count <= 0: - raise FinalSourceProducerError( - "recurrence inspection lacks exact source_row_count" - ) - return count, count, count - if kind == "pyamplicol-runtime-eager-execution": - count = execution["plan"]["inspection_summary"].get("source_count") - if not isinstance(count, int) or count <= 0: - raise FinalSourceProducerError("eager inspection lacks exact source_count") - return count, count, count - if kind != "pyamplicol-runtime-execution": - raise FinalSourceProducerError(f"unsupported execution kind {kind!r}") - lanes = _compiled_execution_lanes(execution) - final = sum(int(record["dag_summary"]["source_count"]) for _, record in lanes) - if workload is Workload.ALL_FLOW: - active_summary = execution["dag_summary"] - else: - active_summary = execution["helicity_sum_execution"]["dag_summary"] - active = active_summary.get("source_count") - if not isinstance(active, int) or active <= 0 or final <= 0: - raise FinalSourceProducerError("compiled DAG summaries lack source_count") - return active, final, final - - -def _phase( - total: Any, - source_count: int, - closure_count: int | None, -) -> dict[str, int]: - if ( - total.evaluation_count is None - or total.attachment_count is None - or closure_count is None - or source_count > total.current_count - ): - raise FinalSourceProducerError( - "runtime inspection lacks exact structural/evaluator/closure counts" - ) - return { - "source_current_count": source_count, - "produced_current_count": total.current_count - source_count, - "kernel_evaluation_count": total.evaluation_count, - "attachment_count": total.attachment_count, - "amplitude_destination_count": closure_count, - } - - -def _execution_mode(execution: dict[str, Any]) -> str: - try: - return { - "pyamplicol-runtime-recurrence-execution": "recurrence", - "pyamplicol-runtime-execution": "compiled", - "pyamplicol-runtime-eager-execution": "eager", - }[str(execution.get("kind"))] - except KeyError as error: - raise FinalSourceProducerError("execution mode is unsupported") from error - - -def _numerical_proof( - path: Path, - revision: str, - *, - cell_id: str | None = None, - mode: str | None = None, - accuracy: str | None = None, - workload: str | None = None, - candidate_artifact_id: str | None = None, - structural_proof_sha256: str | None = None, -) -> dict[str, Any]: - proof = _read(path) - try: - return validate_witness_payload( - proof, - expected_source_revision=revision, - expected_cell_id=cell_id, - expected_mode=mode, - expected_accuracy=accuracy, - expected_workload=workload, - expected_candidate_artifact_id=candidate_artifact_id, - expected_structural_proof_sha256=structural_proof_sha256, - ) - except TruthProducerError as error: - raise FinalSourceProducerError( - "numerical proof is not a recomputable independent precision>=50 witness" - ) from error - - -def build_proof( - artifact: Path, - *, - cell_id: str, - source_revision: str, - workload: Workload, - numerical_proof: Path, -) -> dict[str, Any]: - if _REVISION.fullmatch(source_revision) is None: - raise FinalSourceProducerError("source revision must be a full Git SHA") - manifest = load_manifest(artifact) - if manifest.producer.get("git_revision") != source_revision: - raise FinalSourceProducerError( - "artifact producer revision does not equal the requested final source" - ) - execution_path, execution = _execution(artifact) - fake_result = { - "artifact": {"path": str(artifact)}, - "provenance": {"report_measured_source_revision": source_revision}, - } - counts = _candidate_counts(fake_result, workload=workload) - active_source, final_source, peak_source = _source_counts(execution, workload) - active = _phase(counts.active, active_source, counts.active_closure_count) - final = _phase( - counts.final_materialized, - final_source, - counts.final_materialized_closure_count, - ) - peak = _phase( - counts.peak_materialized, - peak_source, - counts.peak_materialized_closure_count, - ) - relative_execution = execution_path.relative_to(artifact).as_posix() - execution_record = next( - record for record in manifest.payloads if record.path == relative_execution - ) - structural_records = [ - record - for record in manifest.payloads - if record.role == STRUCTURAL_SOURCE_PROOF_ROLE - and record.process_id == str(execution.get("key")) - ] - if len(structural_records) != 1: - raise FinalSourceProducerError( - "artifact must contain exactly one generation structural proof" - ) - structural_record = structural_records[0] - structural_path = artifact / structural_record.path - structural = _read(structural_path) - native_inputs = manifest.producer.get("native_build_inputs_sha256") - if not isinstance(native_inputs, str): - raise FinalSourceProducerError( - "artifact producer native-input identity is absent" - ) - try: - generation_proof = validate_generation_structural_proof( - structural, - artifact_root=artifact, - expected_process_id=str(execution.get("key")), - expected_source_revision=source_revision, - expected_native_build_inputs_sha256=native_inputs, - expected_execution_path=relative_execution, - expected_execution_sha256=execution_record.sha256, - execution=execution, - ) - except ValueError as error: - raise FinalSourceProducerError( - "generation structural proof does not recompute" - ) from error - maps = generation_proof["semantic_maps"] - assert isinstance(maps, dict) - semantic_witnesses = {name: maps[name]["rows"] for name in SEMANTIC_MAP_DOMAINS} - semantic_digests = {name: maps[name]["sha256"] for name in SEMANTIC_MAP_DOMAINS} - process_id = str(execution.get("key")) - if process_id != structural_record.process_id: - raise FinalSourceProducerError( - "generation structural proof process identity changed" - ) - physical_inventory = generation_proof["physical_lane_inventory"] - assert isinstance(physical_inventory, dict) - proof = { - "schema": CELL_PROOF_SCHEMA, - "cell_id": cell_id, - "source_revision": source_revision, - "artifact_identity": { - "artifact_id": manifest.artifact_id, - "process_id": process_id, - "structural_proof_path": structural_record.path, - "structural_proof_sha256": structural_record.sha256, - }, - "color_accuracy": execution.get("color_accuracy"), - "workload": workload.value, - "active": active, - "final_materialized": final, - "peak_materialized": peak, - "semantic_proof": { - "status": "proven", - "strength": "exact-symbolic", - "source_revision": source_revision, - "current_member_map_sha256": semantic_digests["current_member_map"], - "interaction_row_map_sha256": semantic_digests["interaction_row_map"], - "closure_map_sha256": semantic_digests["closure_map"], - "source_contract_sha256": semantic_digests["source_contract"], - "witnesses": semantic_witnesses, - }, - "numerical_validation": _numerical_proof( - numerical_proof, - source_revision, - cell_id=cell_id, - mode=_execution_mode(execution), - accuracy=str(execution.get("color_accuracy")), - workload=workload.value, - candidate_artifact_id=manifest.artifact_id, - structural_proof_sha256=structural_record.sha256, - ), - "persisted_lane_inventory": physical_inventory, - } - return proof - - -def emit( - artifact: Path, - *, - cell_id: str, - source_revision: str, - workload: Workload, - numerical_proof: Path, - output: Path | None = None, -) -> Path: - proof = build_proof( - artifact, - cell_id=cell_id, - source_revision=source_revision, - workload=workload, - numerical_proof=numerical_proof, - ) - destination = artifact / PROOF_PATH if output is None else output - destination.parent.mkdir(parents=True, exist_ok=True) - descriptor, temporary_name = tempfile.mkstemp( - prefix=f".{destination.name}.", - suffix=".tmp", - dir=destination.parent, - ) - temporary = Path(temporary_name) - try: - with os.fdopen(descriptor, "w", encoding="ascii") as stream: - json.dump( - proof, - stream, - ensure_ascii=True, - sort_keys=True, - separators=(",", ":"), - allow_nan=False, - ) - stream.write("\n") - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, destination) - finally: - temporary.unlink(missing_ok=True) - return destination - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--artifact", type=Path, required=True) - parser.add_argument("--cell-id", required=True) - parser.add_argument("--source-revision", required=True) - parser.add_argument( - "--workload", - choices=[item.value for item in Workload], - required=True, - ) - parser.add_argument("--precision50-proof", type=Path, required=True) - parser.add_argument( - "--output", - type=Path, - help=( - "atomic per-cell sidecar destination; report workers should place " - "this beside the immutable attempt/result" - ), - ) - args = parser.parse_args() - output = emit( - args.artifact, - cell_id=args.cell_id, - source_revision=args.source_revision, - workload=Workload(args.workload), - numerical_proof=args.precision50_proof, - output=args.output, - ) - print( - json.dumps( - { - "cell_id": args.cell_id, - "output": str(output.resolve()), - "status": "ok", - }, - sort_keys=True, - ) - ) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_gluon_candidate_probe.cpp b/pyamplicol/tools/developer/fft_gluon_candidate_probe.cpp deleted file mode 100644 index 51f831306f..0000000000 --- a/pyamplicol/tools/developer/fft_gluon_candidate_probe.cpp +++ /dev/null @@ -1,811 +0,0 @@ -// SPDX-License-Identifier: 0BSD - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - -constexpr std::size_t kPointCount = 10; -constexpr std::size_t kWarmSampleCount = 10; -constexpr std::size_t kRepresentativePoint = 0; -constexpr double kPi = 3.141592653589793238462643383279502884; -constexpr double kUnitCouplingAlphaS = 1.0 / (4.0 * kPi); - -struct Event { - std::vector momenta; - std::vector helicities; -}; - -double process_cpu_seconds() { - struct timespec value {}; - if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &value) != 0) { - throw std::runtime_error("clock_gettime(CLOCK_PROCESS_CPUTIME_ID) failed"); - } - return static_cast(value.tv_sec) + - static_cast(value.tv_nsec) * 1.0e-9; -} - -double monotonic_wall_seconds() { - struct timespec value {}; - if (clock_gettime(CLOCK_MONOTONIC, &value) != 0) { - throw std::runtime_error("clock_gettime(CLOCK_MONOTONIC) failed"); - } - return static_cast(value.tv_sec) + - static_cast(value.tv_nsec) * 1.0e-9; -} - -std::string last_rusticol_error() { - std::size_t required = 0; - (void)rusticol_last_error_message(nullptr, 0, &required); - if (required == 0) { - return "unknown Rusticol error"; - } - std::vector buffer(required); - (void)rusticol_last_error_message(buffer.data(), buffer.size(), &required); - return std::string(buffer.data()); -} - -void check_rusticol(const int status) { - if (status != RUSTICOL_STATUS_OK) { - throw std::runtime_error(last_rusticol_error()); - } -} - -class RuntimeHandle { - public: - RuntimeHandle(const std::string &artifact, const std::string &process) { - check_rusticol(rusticol_runtime_load( - artifact.c_str(), process.c_str(), nullptr, &handle_)); - if (handle_ == nullptr) { - throw std::runtime_error("Rusticol returned a null runtime handle"); - } - } - - ~RuntimeHandle() { - if (handle_ != nullptr) { - (void)rusticol_runtime_free(handle_); - } - } - - RuntimeHandle(const RuntimeHandle &) = delete; - RuntimeHandle &operator=(const RuntimeHandle &) = delete; - - RusticolRuntimeHandle *get() const { return handle_; } - - private: - RusticolRuntimeHandle *handle_ = nullptr; -}; - -using RuntimeStringGetter = int (*)( - const RusticolRuntimeHandle *, char *, std::size_t, std::size_t *); - -std::string runtime_string( - const RusticolRuntimeHandle *handle, - const RuntimeStringGetter getter) { - std::size_t required = 0; - check_rusticol(getter(handle, nullptr, 0, &required)); - if (required == 0) { - throw std::runtime_error("Rusticol returned an empty string capacity"); - } - std::vector buffer(required); - check_rusticol(getter(handle, buffer.data(), buffer.size(), &required)); - return std::string(buffer.data()); -} - -std::string runtime_helicity_id( - const RusticolRuntimeHandle *handle, - const std::size_t index) { - std::size_t required = 0; - check_rusticol(rusticol_runtime_helicity_id( - handle, index, nullptr, 0, &required)); - if (required == 0) { - throw std::runtime_error("Rusticol returned an empty helicity ID capacity"); - } - std::vector buffer(required); - check_rusticol(rusticol_runtime_helicity_id( - handle, index, buffer.data(), buffer.size(), &required)); - return std::string(buffer.data()); -} - -Event read_event(const std::string &path) { - std::ifstream stream(path); - if (!stream) { - throw std::runtime_error("cannot open event: " + path); - } - std::string line; - bool in_momenta = false; - bool in_helicities = false; - std::size_t declared_helicities = 0; - Event event; - while (std::getline(stream, line)) { - std::istringstream fields(line); - std::string tag; - fields >> tag; - if (tag.empty()) { - continue; - } - if (tag == "BEGIN_MOMENTA") { - in_momenta = true; - continue; - } - if (tag == "END_MOMENTA") { - in_momenta = false; - continue; - } - if (tag == "NHELICITIES") { - fields >> declared_helicities; - continue; - } - if (tag == "BEGIN_HELICITIES") { - in_helicities = true; - continue; - } - if (tag == "END_HELICITIES") { - in_helicities = false; - continue; - } - if (in_momenta) { - double energy = 0.0; - double px = 0.0; - double py = 0.0; - double pz = 0.0; - std::istringstream row(line); - if (!(row >> energy >> px >> py >> pz)) { - throw std::runtime_error("invalid momentum row in " + path); - } - event.momenta.insert(event.momenta.end(), {energy, px, py, pz}); - } else if (in_helicities) { - std::istringstream row(line); - int value = 0; - while (row >> value) { - if (value != -1 && value != 1) { - throw std::runtime_error("invalid helicity value in " + path); - } - event.helicities.push_back(static_cast(value)); - } - } - } - if (event.momenta.empty() || event.momenta.size() % 4 != 0) { - throw std::runtime_error("event has no complete momenta: " + path); - } - if (declared_helicities != 1 || - event.helicities.size() != event.momenta.size() / 4) { - throw std::runtime_error( - "candidate event must contain exactly one complete helicity: " + path); - } - return event; -} - -std::uint64_t process_peak_rss_kib() { - struct rusage usage {}; - if (getrusage(RUSAGE_SELF, &usage) != 0) { - throw std::runtime_error("getrusage(RUSAGE_SELF) failed"); - } -#if defined(__APPLE__) - return static_cast(usage.ru_maxrss) / 1024U; -#else - return static_cast(usage.ru_maxrss); -#endif -} - -double evaluate_one( - RusticolRuntimeHandle *runtime, - const std::vector &point, - const bool generation_specialized_total, - const std::uint32_t *selected_helicity_index, - const char *const *selected_color_ids, - const std::size_t selected_color_count, - double &minimum_absolute_value, - double &sink) { - double value = 0.0; - if (generation_specialized_total) { - check_rusticol(rusticol_runtime_evaluate_f64( - runtime, point.data(), point.size(), 1, &value, 1)); - } else { - check_rusticol(rusticol_runtime_evaluate_selected_f64( - runtime, - point.data(), - point.size(), - 1, - nullptr, - 0, - selected_color_ids, - selected_color_count, - selected_helicity_index, - selected_helicity_index == nullptr ? 0 : 1, - nullptr, - 0, - &value, - 1)); - } - if (!std::isfinite(value)) { - throw std::runtime_error("Rusticol returned an invalid scalar result"); - } - const double absolute = std::abs(value); - minimum_absolute_value = std::min(minimum_absolute_value, absolute); - sink += value; - return value; -} - -void evaluate_repeated_batch( - RusticolRuntimeHandle *runtime, - const std::vector &momenta, - const bool generation_specialized_total, - const std::vector &selected_helicity_indices, - const char *const *selected_color_ids, - const std::size_t selected_color_count, - std::vector &values) { - const std::size_t point_count = values.size(); - if (generation_specialized_total) { - check_rusticol(rusticol_runtime_evaluate_f64( - runtime, - momenta.data(), - momenta.size(), - point_count, - values.data(), - values.size())); - } else { - check_rusticol(rusticol_runtime_evaluate_selected_f64( - runtime, - momenta.data(), - momenta.size(), - point_count, - nullptr, - 0, - selected_color_ids, - selected_color_count, - selected_helicity_indices.empty() - ? nullptr - : selected_helicity_indices.data(), - selected_helicity_indices.size(), - nullptr, - 0, - values.data(), - values.size())); - } -} - -void consume_batch_results( - const std::vector &values, - double &minimum_absolute_value, - double &sink) { - for (const double value : values) { - if (!std::isfinite(value)) { - throw std::runtime_error("Rusticol returned an invalid batched result"); - } - minimum_absolute_value = std::min(minimum_absolute_value, std::abs(value)); - sink += value; - } -} - -double authenticate_batch_results( - const std::vector &values, - const std::array &expected, - double &minimum_absolute_value, - double &sink) { - double maximum_relative_error = 0.0; - for (std::size_t index = 0; index < values.size(); ++index) { - const double value = values[index]; - const double expected_value = expected[index % expected.size()]; - if (!std::isfinite(value)) { - throw std::runtime_error("Rusticol returned an invalid batched result"); - } - const double scale = std::max( - {std::abs(value), std::abs(expected_value), 1.0e-300}); - maximum_relative_error = std::max( - maximum_relative_error, std::abs(value - expected_value) / scale); - minimum_absolute_value = std::min(minimum_absolute_value, std::abs(value)); - sink += value; - } - if (maximum_relative_error > 1.0e-12) { - throw std::runtime_error( - "batched evaluation disagrees with the scalar representative point"); - } - return maximum_relative_error; -} - -struct Arguments { - std::string artifact; - std::string process; - double target_seconds = 0.25; - double alpha_s = kUnitCouplingAlphaS; - std::size_t samples = kWarmSampleCount; - std::size_t batch_size = 1; - bool first_ready_only = false; - bool report_start_to_first_warm_wall = false; - bool sum_helicities = false; - std::string color_id; - std::vector event_paths; -}; - -Arguments parse_arguments(int argc, char **argv) { - if (argc < 3) { - throw std::runtime_error( - "usage: fft_gluon_candidate_probe ARTIFACT PROCESS " - "[--alpha-s A] [--target-seconds S --samples N " - "--batch-size N] [--color-id ID] [--sum-helicities] " - "[--first-ready-only] [--report-start-to-first-warm-wall] EVENT...]"); - } - Arguments arguments; - arguments.artifact = argv[1]; - arguments.process = argv[2]; - for (int index = 3; index < argc; ++index) { - const std::string token = argv[index]; - if (token == "--target-seconds") { - if (++index >= argc) { - throw std::runtime_error("--target-seconds requires a value"); - } - arguments.target_seconds = std::stod(argv[index]); - } else if (token == "--alpha-s") { - if (++index >= argc) { - throw std::runtime_error("--alpha-s requires a value"); - } - arguments.alpha_s = std::stod(argv[index]); - } else if (token == "--samples") { - if (++index >= argc) { - throw std::runtime_error("--samples requires a value"); - } - arguments.samples = static_cast(std::stoull(argv[index])); - } else if (token == "--batch-size") { - if (++index >= argc) { - throw std::runtime_error("--batch-size requires a value"); - } - arguments.batch_size = - static_cast(std::stoull(argv[index])); - } else if (token == "--first-ready-only") { - arguments.first_ready_only = true; - } else if (token == "--report-start-to-first-warm-wall") { - arguments.report_start_to_first_warm_wall = true; - } else if (token == "--sum-helicities") { - arguments.sum_helicities = true; - } else if (token == "--color-id") { - if (++index >= argc) { - throw std::runtime_error("--color-id requires a value"); - } - const std::string value = argv[index]; - if (value.empty() || value.front() == '-' || - value.find_first_of(" \t\r\n") != std::string::npos) { - throw std::runtime_error("--color-id requires one nonempty ID token"); - } - if (!arguments.color_id.empty()) { - throw std::runtime_error("--color-id may be supplied at most once"); - } - arguments.color_id = value; - } else if (!token.empty() && token[0] == '-') { - throw std::runtime_error("unknown option: " + token); - } else { - arguments.event_paths.push_back(token); - } - } - if (!std::isfinite(arguments.alpha_s) || arguments.alpha_s <= 0.0) { - throw std::runtime_error("--alpha-s must be finite and positive"); - } - if (!std::isfinite(arguments.target_seconds) || - arguments.target_seconds < 0.25) { - throw std::runtime_error("calibration target must be at least 0.25 seconds"); - } - if (arguments.samples != kWarmSampleCount) { - throw std::runtime_error("the acceptance probe requires exactly 10 samples"); - } - if (arguments.batch_size == 0) { - throw std::runtime_error("--batch-size must be positive"); - } - if (arguments.event_paths.size() != kPointCount) { - throw std::runtime_error("the acceptance probe requires exactly 10 events"); - } - return arguments; -} - -void write_first_ready( - const std::string &process, - const std::string &execution_mode, - const std::string &color_accuracy, - const std::string &selected_color_id, - const std::size_t helicity_count, - const std::string &selected_helicity_id, - const bool sum_helicities, - const double load_seconds, - const double first_warm_seconds, - const double warm_up_api_seconds, - const double minimum_absolute_value, - const std::uint64_t peak_rss_kib) { - std::cout << std::setprecision(17) << std::scientific - << "FFT_CANDIDATE_FIRST_READY_V1\n" - << "PROCESS " << process << "\n" - << "EXECUTION_MODE " << execution_mode << "\n"; - if (!selected_color_id.empty()) { - std::cout << "COLOR_ACCURACY " << color_accuracy << "\n" - << "SELECTED_COLOR_ID " << selected_color_id << "\n"; - } - std::cout << "TIMER_SOURCE process-cpu-time\n" - << "HELICITY_COVERAGE_COUNT " << helicity_count << "\n" - << "SELECTED_HELICITY_ID " - << (sum_helicities ? "-" : selected_helicity_id) << "\n"; - if (sum_helicities) { - // This is the complete physical axis requested through the null-selector - // C ABI. Backends may eliminate authenticated structural zeros internally. - std::cout << "HELICITY_WORKLOAD sum\n" - << "TIMED_HELICITY_COUNT " << helicity_count << "\n"; - } - std::cout << "POINT_COUNT " << kPointCount << "\n" - << "LOAD_SECONDS " << load_seconds << "\n" - << "FIRST_WARM_SECONDS " << first_warm_seconds << "\n" - << "WARM_UP_API_SECONDS " << warm_up_api_seconds << "\n" - << "MIN_ABSOLUTE_VALUE " << minimum_absolute_value << "\n" - << "MAX_RSS_KIB " << peak_rss_kib << "\n"; -} - -} // namespace - -int main(int argc, char **argv) { - try { - const double start_to_first_warm_wall_start = monotonic_wall_seconds(); - const Arguments arguments = parse_arguments(argc, argv); - std::vector events; - events.reserve(arguments.event_paths.size()); - for (const auto &path : arguments.event_paths) { - events.push_back(read_event(path)); - } - const std::vector expected_helicity = - events.front().helicities; - const std::size_t point_size = events.front().momenta.size(); - for (const auto &event : events) { - if (event.momenta.size() != point_size || - event.helicities != expected_helicity) { - throw std::runtime_error( - "all candidate events must share one multiplicity and helicity"); - } - } - - const double load_start = process_cpu_seconds(); - if (rusticol_abi_version() != RUSTICOL_ABI_VERSION) { - throw std::runtime_error("Rusticol public C ABI version mismatch"); - } - RuntimeHandle runtime(arguments.artifact, arguments.process); - RusticolRuntimeHandle *const handle = runtime.get(); - check_rusticol(rusticol_runtime_set_model_parameter( - handle, - "normalization.alpha_s_me_check", - arguments.alpha_s, - 0.0)); - const std::string process = runtime_string(handle, rusticol_runtime_process_key); - const std::string execution_mode = - runtime_string(handle, rusticol_runtime_execution_mode); - const std::string color_accuracy = - runtime_string(handle, rusticol_runtime_color_accuracy); - if (arguments.color_id.empty()) { - if (color_accuracy != "full") { - throw std::runtime_error("candidate artifact is not full colour"); - } - } else if (color_accuracy != "lc") { - throw std::runtime_error( - "a selected-color probe requires a leading-colour artifact"); - } - if (execution_mode != "on-the-fly" && execution_mode != "recurrence" && - execution_mode != "compiled") { - throw std::runtime_error("candidate artifact has an unsupported execution mode"); - } - std::size_t external_count = 0; - check_rusticol(rusticol_runtime_external_count(handle, &external_count)); - if (external_count * 4 != point_size) { - throw std::runtime_error("candidate event multiplicity does not match artifact"); - } - if (arguments.batch_size > - std::numeric_limits::max() / point_size) { - throw std::runtime_error("batch momentum size overflows size_t"); - } - std::size_t runtime_helicity_count = 0; - check_rusticol(rusticol_runtime_helicity_count( - handle, &runtime_helicity_count)); - std::string selected_helicity_id; - std::uint32_t selected_helicity_index = 0; - std::size_t matching_helicity_count = 0; - for (std::size_t index = 0; index < runtime_helicity_count; ++index) { - std::size_t required = 0; - check_rusticol(rusticol_runtime_helicity_vector( - handle, index, nullptr, 0, &required)); - if (required != expected_helicity.size()) { - continue; - } - std::vector helicity(required); - check_rusticol(rusticol_runtime_helicity_vector( - handle, index, helicity.data(), helicity.size(), &required)); - if (helicity == expected_helicity) { - ++matching_helicity_count; - selected_helicity_id = runtime_helicity_id(handle, index); - if (index > std::numeric_limits::max()) { - throw std::runtime_error( - "selected helicity index exceeds the public C ABI"); - } - selected_helicity_index = static_cast(index); - } - } - if (matching_helicity_count != 1) { - throw std::runtime_error( - "candidate artifact does not expose one matching selected helicity"); - } - const std::uint32_t *const evaluation_helicity_index = - arguments.sum_helicities ? nullptr : &selected_helicity_index; - const char *selected_helicity_ids[] = {selected_helicity_id.c_str()}; - const char *selected_color_ids[] = {arguments.color_id.c_str()}; - const char *const *const evaluation_color_ids = - arguments.color_id.empty() ? nullptr : selected_color_ids; - const std::size_t evaluation_color_count = - arguments.color_id.empty() ? 0 : 1; - // Full/NLC recurrence artifacts expose contracted colour, and the - // acceptance recurrence lane is generated with exactly one retained - // helicity. Its unselected total is therefore exactly the same - // one-helicity matrix element as the selected query, without paying - // the selector C ABI and planner overhead. OTF intentionally keeps - // complete helicity coverage and must continue through selection. - const bool generation_specialized_total = - execution_mode == "recurrence" && runtime_helicity_count == 1 && - arguments.color_id.empty(); - const double load_seconds = process_cpu_seconds() - load_start; - - double minimum_absolute_value = std::numeric_limits::infinity(); - double sink = 0.0; - std::array point_values {}; - std::array point_value_recorded {}; - std::vector batch_momenta; - batch_momenta.reserve(point_size * arguments.batch_size); - for (std::size_t point = 0; point < arguments.batch_size; ++point) { - const Event &event = events[point % events.size()]; - batch_momenta.insert( - batch_momenta.end(), - event.momenta.begin(), - event.momenta.end()); - } - std::vector batch_helicity_indices; - if (evaluation_helicity_index != nullptr) { - batch_helicity_indices.assign( - arguments.batch_size, *evaluation_helicity_index); - } - std::vector batch_values(arguments.batch_size, 0.0); - - const auto evaluate_representative = [&]() { - if (arguments.batch_size == 1) { - return evaluate_one( - handle, - events[kRepresentativePoint].momenta, - generation_specialized_total, - evaluation_helicity_index, - evaluation_color_ids, - evaluation_color_count, - minimum_absolute_value, - sink); - } - evaluate_repeated_batch( - handle, - batch_momenta, - generation_specialized_total, - batch_helicity_indices, - evaluation_color_ids, - evaluation_color_count, - batch_values); - return batch_values.front(); - }; - RusticolWarmUpResult warm_up {}; - double warm_up_api_seconds = 0.0; - double batch_max_relative_error = 0.0; - double start_to_first_warm_wall_seconds = 0.0; - const double first_warm_start = process_cpu_seconds(); - if (execution_mode == "on-the-fly") { - check_rusticol(rusticol_runtime_warm_up_f64_with_cores( - handle, - events.front().momenta.data(), - events.front().momenta.size(), - arguments.sum_helicities ? nullptr : selected_helicity_ids, - arguments.sum_helicities ? 0 : 1, - evaluation_color_ids, - evaluation_color_count, - 0, - nullptr, - nullptr, - &warm_up)); - if (warm_up.schema_version != 1 || - warm_up.first_evaluation_completed == 0 || - !std::isfinite(warm_up.elapsed_seconds) || - !(warm_up.elapsed_seconds > 0.0)) { - throw std::runtime_error("Rusticol returned an invalid OTF warm-up result"); - } - warm_up_api_seconds = warm_up.elapsed_seconds; - } - for (std::size_t point = 0; point < events.size(); ++point) { - point_values[point] = evaluate_one( - handle, - events[point].momenta, - generation_specialized_total, - evaluation_helicity_index, - evaluation_color_ids, - evaluation_color_count, - minimum_absolute_value, - sink); - point_value_recorded[point] = true; - } - if (arguments.batch_size > 1) { - if (!point_value_recorded[kRepresentativePoint]) { - point_values[kRepresentativePoint] = evaluate_one( - handle, - events[kRepresentativePoint].momenta, - generation_specialized_total, - evaluation_helicity_index, - evaluation_color_ids, - evaluation_color_count, - minimum_absolute_value, - sink); - point_value_recorded[kRepresentativePoint] = true; - } - (void)evaluate_representative(); - } - start_to_first_warm_wall_seconds = - monotonic_wall_seconds() - start_to_first_warm_wall_start; - const double first_warm_seconds = - process_cpu_seconds() - first_warm_start; - if (arguments.batch_size > 1) { - batch_max_relative_error = authenticate_batch_results( - batch_values, - point_values, - minimum_absolute_value, - sink); - } - - std::uint64_t peak_rss_kib = process_peak_rss_kib(); - if (warm_up.peak_rss_available != 0) { - peak_rss_kib = std::max( - peak_rss_kib, - (warm_up.peak_rss_bytes + 1023U) / 1024U); - } - if (!std::isfinite(sink) || !std::isfinite(minimum_absolute_value)) { - throw std::runtime_error("candidate first-pass sink is invalid"); - } - if (arguments.first_ready_only) { - write_first_ready( - process, - execution_mode, - color_accuracy, - arguments.color_id, - runtime_helicity_count, - selected_helicity_id, - arguments.sum_helicities, - load_seconds, - first_warm_seconds, - warm_up_api_seconds, - minimum_absolute_value, - peak_rss_kib); - return 0; - } - - std::size_t calibration_calls = 0; - double calibration_seconds = 0.0; - std::size_t repetitions = 1; - for (;;) { - const double calibration_start = process_cpu_seconds(); - double last_value = 0.0; - for (std::size_t repetition = 0; - repetition < repetitions; - ++repetition) { - last_value = evaluate_representative(); - } - const double elapsed = process_cpu_seconds() - calibration_start; - if (arguments.batch_size > 1) { - consume_batch_results(batch_values, minimum_absolute_value, sink); - } - if (!point_value_recorded[kRepresentativePoint]) { - point_values[kRepresentativePoint] = last_value; - point_value_recorded[kRepresentativePoint] = true; - } - if (elapsed >= arguments.target_seconds) { - calibration_calls = repetitions; - calibration_seconds = elapsed; - break; - } - if (repetitions > std::numeric_limits::max() / 2) { - throw std::runtime_error("calibration repetition count overflow"); - } - repetitions *= 2; - } - - std::array warm_cells {}; - for (std::size_t sample = 0; sample < arguments.samples; ++sample) { - const double cell_start = process_cpu_seconds(); - for (std::size_t repetition = 0; - repetition < calibration_calls; - ++repetition) { - (void)evaluate_representative(); - } - warm_cells[sample] = - (process_cpu_seconds() - cell_start) / - (static_cast(calibration_calls) * - static_cast(arguments.batch_size)); - if (arguments.batch_size > 1) { - consume_batch_results(batch_values, minimum_absolute_value, sink); - } - } - - peak_rss_kib = std::max(peak_rss_kib, process_peak_rss_kib()); - if (!std::isfinite(sink) || !std::isfinite(minimum_absolute_value)) { - throw std::runtime_error("candidate benchmark sink is invalid"); - } - if (!std::all_of( - point_value_recorded.begin(), - point_value_recorded.end(), - [](const bool recorded) { return recorded; }) || - !std::all_of( - point_values.begin(), - point_values.end(), - [](const double value) { - return std::isfinite(value); - })) { - throw std::runtime_error("candidate point-value evidence is invalid"); - } - - std::cout << std::setprecision(17) << std::scientific - << "FFT_CANDIDATE_PROBE_V4\n" - << "PROCESS " << process << "\n" - << "EXECUTION_MODE " << execution_mode << "\n"; - if (!arguments.color_id.empty()) { - std::cout << "COLOR_ACCURACY " << color_accuracy << "\n" - << "SELECTED_COLOR_ID " << arguments.color_id << "\n"; - } - std::cout << "TIMER_SOURCE process-cpu-time\n" - << "HELICITY_COVERAGE_COUNT " << runtime_helicity_count << "\n" - << "SELECTED_HELICITY_ID " - << (arguments.sum_helicities ? "-" : selected_helicity_id) - << "\n"; - if (arguments.sum_helicities) { - std::cout << "HELICITY_WORKLOAD sum\n" - << "TIMED_HELICITY_COUNT " << runtime_helicity_count << "\n"; - } - std::cout << "POINT_COUNT " << events.size() << "\n" - << "LOAD_SECONDS " << load_seconds << "\n" - << "FIRST_WARM_SECONDS " << first_warm_seconds << "\n" - << "WARM_UP_API_SECONDS " << warm_up_api_seconds << "\n"; - if (arguments.batch_size > 1) { - std::cout << "BENCHMARK_BATCH_SIZE " << arguments.batch_size << "\n" - << "BATCH_INPUT_PATTERN cyclic-10-events\n" - << "BATCH_AUTHENTICATED_POINT_COUNT " - << arguments.batch_size << "\n" - << "BATCH_MAX_RELATIVE_ERROR " - << batch_max_relative_error << "\n"; - } - if (arguments.batch_size > 1 || - arguments.report_start_to_first_warm_wall) { - std::cout << "START_TO_FIRST_WARM_WALL_SECONDS " - << start_to_first_warm_wall_seconds << "\n"; - } - for (std::size_t point = 0; point < events.size(); ++point) { - std::cout << "POINT_VALUE " << (point + 1) << " " - << point_values[point] << "\n"; - } - std::cout << "CALIBRATION_CELL " << (kRepresentativePoint + 1) << " " - << calibration_calls << " " << calibration_seconds << "\n"; - for (std::size_t sample = 0; sample < arguments.samples; ++sample) { - std::cout << "WARM_CELL_SECONDS " << (sample + 1) << " " - << (kRepresentativePoint + 1) << " " - << warm_cells[sample] << "\n"; - } - std::cout << "MIN_ABSOLUTE_VALUE " << minimum_absolute_value << "\n" - << "MAX_RSS_KIB " << peak_rss_kib << "\n"; - return 0; - } catch (const std::exception &error) { - std::cerr << "fft candidate probe: " << error.what() << "\n"; - return 1; - } -} diff --git a/pyamplicol/tools/developer/fft_gluon_performance_acceptance.py b/pyamplicol/tools/developer/fft_gluon_performance_acceptance.py deleted file mode 100644 index 07a6675be8..0000000000 --- a/pyamplicol/tools/developer/fft_gluon_performance_acceptance.py +++ /dev/null @@ -1,2687 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Paired pure-gluon FFT performance, RSS, and cold-start acceptance. - -The authoritative reference implementation is loaded from the pinned -developer checkout's ``Benchmark/run_benchmark.py`` and called directly; none -of its implementation is copied here. Candidate timing uses the public -Rusticol C ABI probe in this directory. Linux uses the reference driver's GNU -process wrappers. Darwin translates those wrappers to the study's getrusage -worker; the common watchdog and subprocess timeout retain the same hard bounds. - -This file intentionally is not wired into a default target. Use ``--dry-run`` -to inspect the complete bounded campaign without compiling or writing files. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.util -import json -import math -import os -import re -import shlex -import shutil -import stat -import statistics -import subprocess -import sys -import time -from collections.abc import Callable, Mapping, Sequence -from contextlib import contextmanager -from dataclasses import asdict, dataclass -from pathlib import Path -from types import ModuleType -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.performance_report.source_identity import ( # noqa: E402 - ReportSourceIdentity, - ReportSourceIdentityError, - require_eligible_report_source, -) - -PERFORMANCE_ROOT = ROOT / ".artifacts" / "fft-performance" -DEFAULT_REFERENCE_ROOT = ROOT / "dependencies" / "checkouts" / "reference-fft" -REFERENCE_ROOT = DEFAULT_REFERENCE_ROOT -REFERENCE_DRIVER = REFERENCE_ROOT / "Benchmark" / "run_benchmark.py" -REFERENCE_REVISION = "9c3cb4fb4658200884553bab796e85bd5e7fe7a9" -PROBE_SOURCE = ROOT / "tools" / "developer" / "fft_gluon_candidate_probe.cpp" -SCALING_STUDY_DRIVER = ROOT / "tools" / "developer" / "fft_scaling_study.py" -WATCHDOG = ROOT / "tools" / "ci" / "memory_watchdog.py" - -KIND = "pyamplicol-pure-gluon-fft-performance-acceptance" -SCHEMA_VERSION = 8 -REFERENCE_BACKEND = "AmpliGluonTraceDefaultBG" -REFERENCE_BUILD_PROGRAM = "benchmark_ampligluon_trace" -REFERENCE_CLEAN_BUILD_SCOPE = "ampligluon-trace-backend-only" -# Recurrence is generated for one known-nonzero helicity. OTF retains complete -# runtime-selector coverage and is measured through one fixed-helicity query. -# Both are valid, lane-specific acceptance workloads. Running recurrence first -# prevents OTF from warming its cold path. -LANES = ("recurrence", "on-the-fly") -MANDATORY_MULTIPLICITIES = tuple(range(4, 10)) -OPTIONAL_MULTIPLICITIES = (10, 11) -POINT_COUNT = 10 -REPRESENTATIVE_POINT = 1 -BASE_SEED = 1729 -WARM_SAMPLE_COUNT = 10 -MINIMUM_CALIBRATION_SECONDS = 0.25 -MEMORY_LIMIT_GIB = 30.0 -OPTIONAL_COLD_LIMIT_SECONDS = 15.0 * 60.0 -MANDATORY_LANE_TIMEOUT_SECONDS = 60.0 * 60.0 -WARM_RATIO_LIMIT = 1.25 -RSS_RATIO_LIMIT = 2.0 -COLD_RATIO_LIMIT = 5.0 -NUMERICAL_RELATIVE_TOLERANCE = 1.0e-10 -INITIAL_GLUON_AVERAGE_FACTOR = 256 -UNIT_COUPLING_ALPHA_S = 1.0 / (4.0 * math.pi) -DARWIN_RSS_MARKER = "FFT_MAX_RSS_KIB" -REFERENCE_RSS_MARKER = "BENCHMARK_MAX_RSS_KIB" -WATCHDOG_CLEANUP_WAIT_SECONDS = 7.0 -SINGLE_THREAD_ENVIRONMENT = ( - "OMP_NUM_THREADS", - "OPENBLAS_NUM_THREADS", - "MKL_NUM_THREADS", - "RAYON_NUM_THREADS", - "VECLIB_MAXIMUM_THREADS", - "ACCELERATE_MAX_THREADS", -) -_RUN_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*") - - -class AcceptanceError(RuntimeError): - """Raised when the paired campaign or its evidence is invalid.""" - - -def configure_reference_root(path: Path) -> None: - """Select the independent pinned Reference FFT checkout for this process.""" - - global REFERENCE_ROOT, REFERENCE_DRIVER - REFERENCE_ROOT = path.expanduser().resolve() - REFERENCE_DRIVER = REFERENCE_ROOT / "Benchmark" / "run_benchmark.py" - - -class NumericalParityError(AcceptanceError): - """Raised when an evaluated candidate disagrees with the reference.""" - - -class ReferenceColdLimitError(AcceptanceError): - """Raised when Reference setup exhausts its aggregate cold-cell budget.""" - - -@dataclass(frozen=True) -class ReferenceSourceIdentity: - """Pinned revision and deterministic identity of the reference inputs.""" - - revision: str - content_sha256: str - file_count: int - - def provenance(self) -> dict[str, object]: - return { - "revision": self.revision, - "required_revision": REFERENCE_REVISION, - "content_sha256": self.content_sha256, - "tracked_and_nonignored_file_count": self.file_count, - } - - -@dataclass(frozen=True) -class CandidateProbeMetrics: - process: str - execution_mode: str - helicity_coverage_count: int - selected_helicity_id: str - point_count: int - point_values: tuple[float, ...] - load_seconds: float - first_warm_seconds: float - warm_up_api_seconds: float - calibration_calls: tuple[int, ...] - calibration_seconds: tuple[float, ...] - warm_cell_seconds: tuple[tuple[float, ...], ...] - warm_samples_seconds: tuple[float, ...] - warm_median_seconds: float - minimum_absolute_value: float - max_rss_kib: int - - -@dataclass(frozen=True) -class NumericalParityEvidence: - normalization_alpha_s_me_check: float - candidate_scale_factor: int - relative_tolerance: float - maximum_relative_error: float - maximum_relative_error_point: int - passes: bool - - -@dataclass(frozen=True) -class CandidateMetrics: - lane: str - total_gluons: int - generator_seed: int - generation_seconds: float - load_seconds: float - first_warm_seconds: float - max_rss_kib: int - probe: CandidateProbeMetrics - numerical_parity: NumericalParityEvidence - - @property - def cold_to_ready_seconds(self) -> float: - return self.generation_seconds + self.load_seconds + self.first_warm_seconds - - -@dataclass(frozen=True) -class CandidateFirstReadyMetrics: - process: str - execution_mode: str - helicity_coverage_count: int - selected_helicity_id: str - point_count: int - load_seconds: float - first_warm_seconds: float - warm_up_api_seconds: float - minimum_absolute_value: float - max_rss_kib: int - - -class WatchedCompletedProcess(subprocess.CompletedProcess[str]): - """Completed watchdog process with parent-side timing evidence.""" - - def __init__( - self, - args: Sequence[str], - returncode: int, - stdout: str, - stderr: str, - *, - elapsed_seconds: float, - log_write_seconds: float, - timed_out: bool, - timeout_cleanup: str, - peak_guard_kib: int | None = None, - peak_rss_kib: int | None = None, - ) -> None: - super().__init__(args, returncode, stdout, stderr) - self.elapsed_seconds = elapsed_seconds - self.log_write_seconds = log_write_seconds - self.peak_guard_kib = peak_guard_kib - self.peak_rss_kib = peak_rss_kib - self.timed_out = timed_out - self.timeout_cleanup = timeout_cleanup - - -@dataclass(frozen=True) -class ReferenceMetrics: - total_gluons: int - generator_seed: int - backend: str - clean_build_scope: str - clean_build_command_count: int - clean_build_seconds: float - setup_to_driver_seconds: float - initialization_seconds: float - first_pass_seconds: float - warm_samples_seconds: tuple[float, ...] - warm_median_seconds: float - max_rss_kib: int - selected_helicity: tuple[int, ...] - selected_path: str - event_paths: tuple[str, ...] - matrix_elements: tuple[float, ...] - driver_max_rss_kib: int | None = None - watchdog_max_rss_kib: int | None = None - direct_command_watchdog_max_rss_kib: int | None = None - translated_child_max_rss_kib: int | None = None - watchdog_max_peak_guard_kib: int | None = None - warm_repetitions: tuple[int, ...] = () - warm_repetition_quantum: int | None = None - warm_calibration_seconds: tuple[float, ...] = () - helicity_workload: str = "fixed" - helicity_coverage_count: int = 1 - timed_helicity_count: int = 1 - active_helicity_count: int = 1 - exhaustive_event_paths: tuple[str, ...] = () - - @property - def cold_to_ready_seconds(self) -> float: - return ( - self.clean_build_seconds - + self.initialization_seconds - + self.first_pass_seconds - ) - - @property - def setup_to_ready_seconds(self) -> float: - return ( - self.setup_to_driver_seconds - + self.initialization_seconds - + self.first_pass_seconds - ) - - -@dataclass(frozen=True) -class GateResult: - total_gluons: int - lane: str - warm_ratio: float - rss_ratio: float - cold_ratio: float - warm_passes: bool - rss_passes: bool - cold_passes: bool - numerical_passes: bool - - @property - def passes(self) -> bool: - return ( - self.warm_passes - and self.rss_passes - and self.cold_passes - and self.numerical_passes - ) - - -@dataclass(frozen=True) -class _ReferenceRun: - metrics: ReferenceMetrics - event_paths: tuple[Path, ...] - - -def generator_seed(total_gluons: int) -> int: - if total_gluons < 4: - raise AcceptanceError(f"unsupported total-gluon multiplicity {total_gluons}") - return BASE_SEED + total_gluons - - -def _positive_finite(value: object) -> bool: - return ( - isinstance(value, int | float) - and not isinstance(value, bool) - and math.isfinite(float(value)) - and float(value) > 0.0 - ) - - -def _finite_number(value: object) -> bool: - return ( - isinstance(value, int | float) - and not isinstance(value, bool) - and math.isfinite(float(value)) - ) - - -def candidate_reference_scale_factor(total_gluons: int) -> int: - """Undo pyAmpliCol's initial-state average and final-gluon symmetry factor.""" - - if total_gluons < 2: - raise AcceptanceError("total-gluon multiplicity must be at least two") - return INITIAL_GLUON_AVERAGE_FACTOR * math.factorial(total_gluons - 2) - - -def compare_candidate_to_reference( - *, - total_gluons: int, - candidate_values: Sequence[float], - reference_values: Sequence[float], -) -> NumericalParityEvidence: - """Compare the same ordered points after aligning public ME conventions.""" - - if len(candidate_values) != POINT_COUNT or len(reference_values) != POINT_COUNT: - raise AcceptanceError("numerical parity requires exactly 10 paired values") - if not all(_finite_number(value) for value in candidate_values): - raise AcceptanceError("candidate numerical parity values must be finite") - if not all(_positive_finite(value) for value in reference_values): - raise AcceptanceError("reference numerical parity values must be positive") - scale_factor = candidate_reference_scale_factor(total_gluons) - errors: list[float] = [] - for candidate, reference in zip(candidate_values, reference_values, strict=True): - scaled_candidate = float(candidate) * scale_factor - scale = max(abs(scaled_candidate), abs(float(reference))) - errors.append(abs(scaled_candidate - float(reference)) / scale) - maximum = max(errors) - maximum_point = errors.index(maximum) + 1 - return NumericalParityEvidence( - normalization_alpha_s_me_check=UNIT_COUPLING_ALPHA_S, - candidate_scale_factor=scale_factor, - relative_tolerance=NUMERICAL_RELATIVE_TOLERANCE, - maximum_relative_error=maximum, - maximum_relative_error_point=maximum_point, - passes=maximum <= NUMERICAL_RELATIVE_TOLERANCE, - ) - - -def parse_candidate_probe_output(output: str) -> CandidateProbeMetrics: - """Parse per-cell process-CPU evidence emitted by the public-C probe.""" - - lines = [line.strip() for line in output.splitlines() if line.strip()] - if not lines or lines[0] != "FFT_CANDIDATE_PROBE_V4": - raise AcceptanceError("candidate probe header is missing or invalid") - scalar: dict[str, str] = {} - point_values: dict[int, float] = {} - calibration: dict[int, tuple[int, float]] = {} - warm_cells: dict[tuple[int, int], float] = {} - for line in lines[1:]: - fields = line.split() - if fields[0] == "POINT_VALUE": - if len(fields) != 3: - raise AcceptanceError("candidate point-value row is malformed") - point = int(fields[1]) - if point in point_values: - raise AcceptanceError("candidate point value is duplicated") - point_values[point] = float(fields[2]) - continue - if fields[0] == "CALIBRATION_CELL": - if len(fields) != 4: - raise AcceptanceError("candidate calibration cell is malformed") - point = int(fields[1]) - if point in calibration: - raise AcceptanceError("candidate calibration cell is duplicated") - calibration[point] = (int(fields[2]), float(fields[3])) - continue - if fields[0] == "WARM_CELL_SECONDS": - if len(fields) != 4: - raise AcceptanceError("candidate warm cell row is malformed") - key = (int(fields[1]), int(fields[2])) - if key in warm_cells: - raise AcceptanceError("candidate warm cell is duplicated") - warm_cells[key] = float(fields[3]) - continue - if len(fields) < 2: - raise AcceptanceError("candidate scalar row is malformed") - key = fields[0] - if key in scalar: - raise AcceptanceError(f"candidate scalar {key} is duplicated") - scalar[key] = " ".join(fields[1:]) - required = { - "PROCESS", - "EXECUTION_MODE", - "TIMER_SOURCE", - "HELICITY_COVERAGE_COUNT", - "SELECTED_HELICITY_ID", - "POINT_COUNT", - "LOAD_SECONDS", - "FIRST_WARM_SECONDS", - "WARM_UP_API_SECONDS", - "MIN_ABSOLUTE_VALUE", - "MAX_RSS_KIB", - } - if set(scalar) != required: - missing = sorted(required - set(scalar)) - extra = sorted(set(scalar) - required) - raise AcceptanceError( - f"candidate probe scalar fields differ: missing={missing}, extra={extra}" - ) - expected_points = set(range(1, POINT_COUNT + 1)) - if set(point_values) != expected_points: - raise AcceptanceError("candidate probe must report all 10 point values") - if set(calibration) != {REPRESENTATIVE_POINT}: - raise AcceptanceError( - "candidate probe must calibrate only representative point 1" - ) - expected_warm_cells = { - (sample, REPRESENTATIVE_POINT) for sample in range(1, WARM_SAMPLE_COUNT + 1) - } - if set(warm_cells) != expected_warm_cells: - raise AcceptanceError( - "candidate probe must contain one point-1 cell in each of 10 batches" - ) - execution_mode = scalar["EXECUTION_MODE"] - if execution_mode not in LANES: - raise AcceptanceError("candidate probe reported an unknown execution mode") - if scalar["TIMER_SOURCE"] != "process-cpu-time": - raise AcceptanceError("candidate probe did not use process CPU time") - point_count = int(scalar["POINT_COUNT"]) - helicity_coverage_count = int(scalar["HELICITY_COVERAGE_COUNT"]) - max_rss_kib = int(scalar["MAX_RSS_KIB"]) - numeric = { - key: float(scalar[key]) - for key in ( - "LOAD_SECONDS", - "FIRST_WARM_SECONDS", - "WARM_UP_API_SECONDS", - "MIN_ABSOLUTE_VALUE", - ) - } - calibration_calls = (calibration[REPRESENTATIVE_POINT][0],) - calibration_seconds = (calibration[REPRESENTATIVE_POINT][1],) - ordered_point_values = tuple( - point_values[index] for index in range(1, POINT_COUNT + 1) - ) - warm_cell_rows = tuple( - (warm_cells[(sample, REPRESENTATIVE_POINT)],) - for sample in range(1, WARM_SAMPLE_COUNT + 1) - ) - warm_samples = tuple(row[0] for row in warm_cell_rows) - if point_count != POINT_COUNT: - raise AcceptanceError("candidate probe did not use 10 phase-space points") - if helicity_coverage_count < 1 or not scalar["SELECTED_HELICITY_ID"].startswith( - "h:" - ): - raise AcceptanceError("candidate selected-helicity metadata is invalid") - if any(value < 1 for value in calibration_calls): - raise AcceptanceError("candidate calibration call count is not positive") - if any(value < MINIMUM_CALIBRATION_SECONDS for value in calibration_seconds): - raise AcceptanceError( - "every candidate calibration cell must reach 0.25 seconds" - ) - if max_rss_kib < 1: - raise AcceptanceError("candidate peak RSS is not positive") - warm_up_api_seconds = numeric["WARM_UP_API_SECONDS"] - if execution_mode == "recurrence": - if warm_up_api_seconds != 0.0: - raise AcceptanceError( - "recurrence candidate called the OTF-only warm-up API" - ) - elif not _positive_finite(warm_up_api_seconds): - raise AcceptanceError("OTF candidate warm-up API timing is not positive") - positive_numeric = ( - numeric["LOAD_SECONDS"], - numeric["FIRST_WARM_SECONDS"], - *calibration_seconds, - *(value for row in warm_cell_rows for value in row), - ) - if not all(_positive_finite(value) for value in positive_numeric): - raise AcceptanceError("candidate probe contains a non-positive timing") - if ( - not _finite_number(numeric["MIN_ABSOLUTE_VALUE"]) - or numeric["MIN_ABSOLUTE_VALUE"] < 0.0 - or not all(_finite_number(value) for value in ordered_point_values) - ): - raise AcceptanceError("candidate probe contains an invalid matrix element") - return CandidateProbeMetrics( - process=scalar["PROCESS"], - execution_mode=execution_mode, - helicity_coverage_count=helicity_coverage_count, - selected_helicity_id=scalar["SELECTED_HELICITY_ID"], - point_count=point_count, - point_values=ordered_point_values, - load_seconds=numeric["LOAD_SECONDS"], - first_warm_seconds=numeric["FIRST_WARM_SECONDS"], - warm_up_api_seconds=warm_up_api_seconds, - calibration_calls=calibration_calls, - calibration_seconds=calibration_seconds, - warm_cell_seconds=warm_cell_rows, - warm_samples_seconds=warm_samples, - warm_median_seconds=statistics.median(warm_samples), - minimum_absolute_value=numeric["MIN_ABSOLUTE_VALUE"], - max_rss_kib=max_rss_kib, - ) - - -def parse_candidate_first_ready_output(output: str) -> CandidateFirstReadyMetrics: - """Parse a cold-only probe that exits before calibration and warm batches.""" - - lines = [line.strip() for line in output.splitlines() if line.strip()] - if not lines or lines[0] != "FFT_CANDIDATE_FIRST_READY_V1": - raise AcceptanceError("candidate first-ready header is missing or invalid") - scalar: dict[str, str] = {} - for line in lines[1:]: - fields = line.split() - if len(fields) < 2 or fields[0] in scalar: - raise AcceptanceError("candidate first-ready scalar rows are malformed") - scalar[fields[0]] = " ".join(fields[1:]) - required = { - "PROCESS", - "EXECUTION_MODE", - "TIMER_SOURCE", - "HELICITY_COVERAGE_COUNT", - "SELECTED_HELICITY_ID", - "POINT_COUNT", - "LOAD_SECONDS", - "FIRST_WARM_SECONDS", - "WARM_UP_API_SECONDS", - "MIN_ABSOLUTE_VALUE", - "MAX_RSS_KIB", - } - if set(scalar) != required: - raise AcceptanceError("candidate first-ready scalar fields differ") - execution_mode = scalar["EXECUTION_MODE"] - if execution_mode not in LANES or scalar["TIMER_SOURCE"] != "process-cpu-time": - raise AcceptanceError( - "candidate first-ready execution/timer metadata is invalid" - ) - point_count = int(scalar["POINT_COUNT"]) - coverage = int(scalar["HELICITY_COVERAGE_COUNT"]) - max_rss_kib = int(scalar["MAX_RSS_KIB"]) - load_seconds = float(scalar["LOAD_SECONDS"]) - first_warm_seconds = float(scalar["FIRST_WARM_SECONDS"]) - warm_up_api_seconds = float(scalar["WARM_UP_API_SECONDS"]) - minimum_absolute_value = float(scalar["MIN_ABSOLUTE_VALUE"]) - if ( - point_count != POINT_COUNT - or coverage < 1 - or not scalar["SELECTED_HELICITY_ID"].startswith("h:") - or max_rss_kib < 1 - or not all( - _positive_finite(value) for value in (load_seconds, first_warm_seconds) - ) - or not _finite_number(minimum_absolute_value) - or minimum_absolute_value < 0.0 - ): - raise AcceptanceError("candidate first-ready evidence is invalid") - if execution_mode == "recurrence": - if warm_up_api_seconds != 0.0: - raise AcceptanceError( - "recurrence candidate called the OTF-only warm-up API" - ) - elif not _positive_finite(warm_up_api_seconds): - raise AcceptanceError("OTF first-ready warm-up API timing is not positive") - return CandidateFirstReadyMetrics( - process=scalar["PROCESS"], - execution_mode=execution_mode, - helicity_coverage_count=coverage, - selected_helicity_id=scalar["SELECTED_HELICITY_ID"], - point_count=point_count, - load_seconds=load_seconds, - first_warm_seconds=first_warm_seconds, - warm_up_api_seconds=warm_up_api_seconds, - minimum_absolute_value=minimum_absolute_value, - max_rss_kib=max_rss_kib, - ) - - -def select_global_lane( - references: Mapping[int, ReferenceMetrics], - candidates: Mapping[str, Mapping[int, CandidateMetrics]], -) -> str: - """Choose the fastest globally consistent lane that passes every gate.""" - - eligibility = lane_eligibility(candidates) - scores: list[tuple[float, str]] = [] - for lane in LANES: - lane_policy = eligibility[lane] - if lane_policy["eligible"] and all( - gate.passes - for gate in _lane_gate_results( - lane, - references, - candidates[lane], - MANDATORY_MULTIPLICITIES, - ) - ): - scores.append((float(lane_policy["warm_geometric_mean_seconds"]), lane)) - if not scores: - raise AcceptanceError("no eligible lane passes every mandatory acceptance gate") - # The lane name is a stable tie-breaker; selection never changes per N. - return min(scores)[1] - - -def lane_eligibility( - candidates: Mapping[str, Mapping[int, CandidateMetrics]], -) -> dict[str, dict[str, object]]: - """Summarize mandatory evidence and acceptance eligibility per lane.""" - - result: dict[str, dict[str, object]] = {} - mandatory = set(MANDATORY_MULTIPLICITIES) - for lane in LANES: - lane_records = candidates.get(lane) - if lane_records is None or not mandatory <= set(lane_records): - raise AcceptanceError( - f"lane {lane} does not cover every mandatory multiplicity" - ) - records = tuple(lane_records[total] for total in MANDATORY_MULTIPLICITIES) - if any( - record.lane != lane - or record.total_gluons != total - or record.probe.execution_mode != lane - for total, record in zip(MANDATORY_MULTIPLICITIES, records, strict=True) - ): - raise AcceptanceError(f"lane {lane} contains inconsistent evidence") - values = tuple(record.probe.warm_median_seconds for record in records) - if not all(_positive_finite(value) for value in values): - raise AcceptanceError(f"lane {lane} has an invalid warm measurement") - workload = _lane_workload_eligibility(lane, records) - result[lane] = { - **workload, - "mandatory_helicity_coverage_count": { - str(total): record.probe.helicity_coverage_count - for total, record in zip(MANDATORY_MULTIPLICITIES, records, strict=True) - }, - "warm_geometric_mean_seconds": math.exp( - statistics.fmean(math.log(value) for value in values) - ), - } - return result - - -def _lane_workload_eligibility( - lane: str, - records: Sequence[CandidateMetrics], -) -> dict[str, object]: - """Apply the lane-specific helicity workload contract once.""" - - if lane not in LANES or not records: - raise AcceptanceError("lane workload evidence is invalid") - coverage = tuple(record.probe.helicity_coverage_count for record in records) - generation_specialized = all(count == 1 for count in coverage) - complete_helicity_coverage = all(count > 1 for count in coverage) - if lane == "recurrence": - eligible = generation_specialized - contract = "generation-specialized-known-nonzero" - reason = ( - "eligible: one generation-selected known-nonzero helicity" - if eligible - else "ineligible: recurrence artifact is not generation-specialized" - ) - else: - eligible = complete_helicity_coverage - contract = "complete-runtime-selector-fixed-helicity-query" - reason = ( - "eligible: complete runtime-selector axis with one fixed query" - if eligible - else "ineligible: OTF artifact does not retain complete selector coverage" - ) - return { - "eligible": eligible, - "reason": reason, - "coverage_contract": contract, - "generation_specialized": generation_specialized, - "complete_helicity_coverage": complete_helicity_coverage, - } - - -def evaluate_gates( - winner: str, - references: Mapping[int, ReferenceMetrics], - candidates: Mapping[str, Mapping[int, CandidateMetrics]], - *, - multiplicities: Sequence[int] = MANDATORY_MULTIPLICITIES, -) -> tuple[GateResult, ...]: - """Apply all ratios to the one global winner without lane mixing.""" - - if winner not in LANES or winner not in candidates: - raise AcceptanceError("global winning lane is unavailable") - if not lane_eligibility(candidates)[winner]["eligible"]: - raise AcceptanceError( - f"lane {winner} does not satisfy its helicity workload contract" - ) - return _lane_gate_results(winner, references, candidates[winner], multiplicities) - - -def _lane_gate_results( - lane: str, - references: Mapping[int, ReferenceMetrics], - records: Mapping[int, CandidateMetrics], - multiplicities: Sequence[int], -) -> tuple[GateResult, ...]: - results: list[GateResult] = [] - for total_gluons in multiplicities: - if total_gluons not in references or total_gluons not in records: - raise AcceptanceError( - f"paired winner/reference evidence is missing for N={total_gluons}" - ) - results.append( - _paired_gate_result( - lane, - references[total_gluons], - records[total_gluons], - ) - ) - return tuple(results) - - -def _paired_gate_result( - lane: str, - reference: ReferenceMetrics, - candidate: CandidateMetrics, -) -> GateResult: - if candidate.lane != lane or candidate.total_gluons != reference.total_gluons: - raise AcceptanceError("paired acceptance evidence is inconsistent") - warm_ratio = candidate.probe.warm_median_seconds / reference.warm_median_seconds - rss_ratio = candidate.max_rss_kib / reference.max_rss_kib - cold_ratio = candidate.cold_to_ready_seconds / reference.cold_to_ready_seconds - if not all( - _positive_finite(value) for value in (warm_ratio, rss_ratio, cold_ratio) - ): - raise AcceptanceError("paired acceptance ratio is invalid") - return GateResult( - total_gluons=reference.total_gluons, - lane=lane, - warm_ratio=warm_ratio, - rss_ratio=rss_ratio, - cold_ratio=cold_ratio, - warm_passes=warm_ratio <= WARM_RATIO_LIMIT, - rss_passes=rss_ratio <= RSS_RATIO_LIMIT, - cold_passes=cold_ratio <= COLD_RATIO_LIMIT, - numerical_passes=candidate.numerical_parity.passes, - ) - - -def _observed_mandatory_gate_viability( - references: Mapping[int, ReferenceMetrics], - candidates: Mapping[str, Mapping[int, CandidateMetrics]], - *, - multiplicities: Sequence[int], -) -> dict[str, object]: - """Report whether one lane can still pass every completed mandatory row.""" - - completed = tuple(multiplicities) - if not completed or any(total not in references for total in completed): - raise AcceptanceError("observed mandatory reference evidence is incomplete") - lanes: dict[str, object] = {} - viable_lanes: list[str] = [] - for lane in LANES: - records = candidates.get(lane) - if records is None or any(total not in records for total in completed): - raise AcceptanceError( - f"observed mandatory candidate evidence is incomplete for {lane}" - ) - selected = tuple(records[total] for total in completed) - if any( - record.lane != lane - or record.total_gluons != total - or record.probe.execution_mode != lane - for total, record in zip(completed, selected, strict=True) - ): - raise AcceptanceError(f"lane {lane} contains inconsistent evidence") - workload = _lane_workload_eligibility(lane, selected) - eligible = bool(workload["eligible"]) - gates = _lane_gate_results(lane, references, records, completed) - viable = eligible and all(gate.passes for gate in gates) - if viable: - viable_lanes.append(lane) - lanes[lane] = { - **workload, - "viable": viable, - "gates": [_plain_gate(gate) for gate in gates], - } - return { - "completed_multiplicities": list(completed), - "lanes": lanes, - "viable_lanes": viable_lanes, - } - - -def optional_candidate_is_feasible(candidate: CandidateMetrics) -> bool: - return ( - candidate.generation_seconds < OPTIONAL_COLD_LIMIT_SECONDS - and candidate.first_warm_seconds < OPTIONAL_COLD_LIMIT_SECONDS - and candidate.max_rss_kib <= int(MEMORY_LIMIT_GIB * 1024**2) - ) - - -def process_expression(total_gluons: int) -> str: - return "g g > " + " ".join("g" for _ in range(total_gluons - 2)) - - -def process_name(total_gluons: int) -> str: - return f"gg_N{total_gluons}" - - -def _toml_helicity_map(helicities: Sequence[int]) -> str: - if not helicities or any(value not in (-1, 1) for value in helicities): - raise AcceptanceError("generation-selected helicity must contain only +/-1") - return ( - "{" - + ",".join( - f"{index}={value}" for index, value in enumerate(helicities, start=1) - ) - + "}" - ) - - -def candidate_generation_command( - *, - python: str, - lane: str, - total_gluons: int, - helicities: Sequence[int], - artifact: Path, -) -> tuple[str, ...]: - if lane not in LANES: - raise AcceptanceError(f"unknown candidate lane {lane}") - if len(helicities) != total_gluons: - raise AcceptanceError("candidate helicity multiplicity is inconsistent") - common = ( - python, - "-m", - "pyamplicol", - "generate", - process_expression(total_gluons), - str(artifact), - "--name", - process_name(total_gluons), - "--model", - "built-in-sm", - "--color-accuracy", - "full", - "--color-contraction", - "symmetric-group-fft", - "--execution-mode", - lane, - "--workers", - "1", - "--mode", - "error", - "--no-emit-api-bundle", - "--set", - "generation.validation.enabled=false", - "--set", - "generation.validation.post_build_validation=false", - "--set", - "model.cache=false", - "--set", - "evaluator.batch_size=1", - "--set", - "evaluator.optimization.cores=1", - "--set", - "evaluator.jit.optimization_level=2", - "--progress", - "off", - "--color", - "never", - "--log-level", - "error", - ) - if lane == "on-the-fly": - return common - insertion = common.index("--no-emit-api-bundle") + 1 - return ( - *common[:insertion], - "--set", - f"process.selected_source_helicities={_toml_helicity_map(helicities)}", - *common[insertion:], - ) - - -def _watchdog_command( - command: Sequence[str], - *, - python: str, - memory_limit_gib: float = MEMORY_LIMIT_GIB, - report_json: Path | None = None, -) -> tuple[str, ...]: - command_prefix = ( - python, - str(WATCHDOG), - "--limit-gib", - f"{memory_limit_gib:g}", - ) - if report_json is not None: - command_prefix = (*command_prefix, "--report-json", str(report_json)) - return (*command_prefix, "--", *command) - - -def _read_watchdog_usage_kib(report_path: Path) -> tuple[int, int]: - """Read exact RSS and enforced-guard peaks from one successful report.""" - - try: - payload = json.loads(report_path.read_text(encoding="utf-8")) - enforcement = payload["enforcement"] - peak_rss_bytes = enforcement["peak_rss_bytes"] - peak_guard_bytes = enforcement["peak_guard_bytes"] - except (OSError, json.JSONDecodeError, KeyError, TypeError) as error: - raise AcceptanceError( - f"watchdog report is missing or malformed: {report_path}" - ) from error - if ( - payload.get("complete") is not True - or payload.get("passes") is not True - or not isinstance(peak_rss_bytes, int) - or isinstance(peak_rss_bytes, bool) - or peak_rss_bytes < 0 - or not isinstance(peak_guard_bytes, int) - or isinstance(peak_guard_bytes, bool) - or peak_guard_bytes < 0 - ): - raise AcceptanceError(f"watchdog report is not successful: {report_path}") - return ( - (peak_rss_bytes + 1023) // 1024, - (peak_guard_bytes + 1023) // 1024, - ) - - -def _workspace_environment(python: str) -> dict[str, str]: - cache_root = PERFORMANCE_ROOT / "cache" - environment = os.environ.copy() - environment.update( - { - "TMPDIR": str(PERFORMANCE_ROOT / "tmp"), - "CARGO_HOME": str(cache_root / "cargo-home"), - "CARGO_TARGET_DIR": str(cache_root / "cargo-target"), - "PIP_CACHE_DIR": str(cache_root / "pip-cache"), - "XDG_CACHE_HOME": str(cache_root / "xdg-cache"), - "PYTHONPYCACHEPREFIX": str(cache_root / "python-cache"), - "CARGO_NET_OFFLINE": "true", - "PIP_NO_INDEX": "1", - **{name: "1" for name in SINGLE_THREAD_ENVIRONMENT}, - "PYTHONPATH": str(ROOT / "src"), - "PYTHONDONTWRITEBYTECODE": "1", - "SYMBOLICA_HIDE_BANNER": "1", - "FFT_ACCEPTANCE_PYTHON": python, - } - ) - return environment - - -def _create_workspace_directories(run_root: Path) -> None: - if run_root.exists(): - raise AcceptanceError( - f"acceptance run already exists; choose another --run-id: {run_root}" - ) - for path in ( - PERFORMANCE_ROOT / "tmp", - PERFORMANCE_ROOT / "cache" / "cargo-home", - PERFORMANCE_ROOT / "cache" / "cargo-target", - PERFORMANCE_ROOT / "cache" / "pip-cache", - PERFORMANCE_ROOT / "cache" / "xdg-cache", - PERFORMANCE_ROOT / "cache" / "python-cache", - run_root / "logs", - ): - path.mkdir(parents=True, exist_ok=True) - - -def _translate_darwin_reference_command( - command: Sequence[str], - *, - python: str = sys.executable, -) -> tuple[tuple[str, ...], bool]: - """Use the study's getrusage wrapper instead of unavailable Darwin sysctls.""" - - original = tuple(str(item) for item in command) - if original[:2] == ("/usr/bin/time", "-l"): - payload = original[2:] - if not payload: - raise AcceptanceError("Darwin time wrapper has no payload") - return (python, str(SCALING_STUDY_DRIVER), "_time-rss", *payload), True - if not original or original[0] != "/usr/bin/timeout": - return original, False - if ( - len(original) < 10 - or original[1:3] != ("--signal=TERM", "--kill-after=5s") - or not original[3].endswith("s") - or original[4] != "/usr/bin/time" - or original[5] != f"--format={REFERENCE_RSS_MARKER} %M" - or original[6] != "/usr/bin/prlimit" - or not original[7].startswith("--as=") - or original[8] != "--" - ): - raise AcceptanceError("unrecognized GNU reference measurement wrapper") - try: - timeout_value = float(original[3][:-1]) - memory_bytes = int(original[7].partition("=")[2]) - except ValueError as error: - raise AcceptanceError("invalid GNU reference measurement bound") from error - if not _positive_finite(timeout_value) or memory_bytes < 1: - raise AcceptanceError("invalid GNU reference measurement bound") - payload = original[9:] - if not payload: - raise AcceptanceError("GNU reference measurement wrapper has no payload") - return (python, str(SCALING_STUDY_DRIVER), "_time-rss", *payload), True - - -def _resolve_gnu_tool(name: str, fallback: str) -> str: - resolved = shutil.which(name) - if resolved is not None: - return resolved - if Path(fallback).is_file(): - return fallback - raise AcceptanceError( - f"required GNU utility is unavailable: {name} " - f"(also checked {fallback})" - ) - - -def _translate_gnu_reference_command( - command: Sequence[str], - *, - python: str = sys.executable, -) -> tuple[tuple[str, ...], bool]: - """Measure Linux reference commands with getrusage and resolved wrappers.""" - - original = tuple(str(item) for item in command) - if original[:2] == ("/usr/bin/time", "-l"): - payload = original[2:] - if not payload: - raise AcceptanceError("time wrapper has no payload") - return (python, str(SCALING_STUDY_DRIVER), "_time-rss", *payload), True - if not original or original[0] != "/usr/bin/timeout": - return original, False - if ( - len(original) < 10 - or original[1:3] != ("--signal=TERM", "--kill-after=5s") - or not original[3].endswith("s") - or original[4] != "/usr/bin/time" - or original[5] != f"--format={REFERENCE_RSS_MARKER} %M" - or original[6] != "/usr/bin/prlimit" - or not original[7].startswith("--as=") - or original[8] != "--" - ): - raise AcceptanceError("unrecognized GNU reference measurement wrapper") - try: - timeout_value = float(original[3][:-1]) - memory_bytes = int(original[7].partition("=")[2]) - except ValueError as error: - raise AcceptanceError("invalid GNU reference measurement bound") from error - if not _positive_finite(timeout_value) or memory_bytes < 1: - raise AcceptanceError("invalid GNU reference measurement bound") - return ( - python, - str(SCALING_STUDY_DRIVER), - "_time-rss", - _resolve_gnu_tool("timeout", original[0]), - *original[1:4], - _resolve_gnu_tool("prlimit", original[6]), - *original[7:], - ), True - - -def _synthesize_reference_rss_marker( - completed: subprocess.CompletedProcess[str], -) -> subprocess.CompletedProcess[str]: - """Copy the getrusage wrapper's exact FFT RSS into the reference protocol.""" - - matches: list[int] = [] - for line in completed.stderr.splitlines(): - fields = line.split() - if len(fields) == 2 and fields[0] == DARWIN_RSS_MARKER: - matches.append(int(fields[1])) - if len(matches) != 1 or matches[0] < 1: - raise AcceptanceError("Darwin getrusage wrapper did not report exact RSS") - stderr = completed.stderr.rstrip("\n") - return subprocess.CompletedProcess( - args=completed.args, - returncode=completed.returncode, - stdout=completed.stdout, - stderr=f"{stderr}\n{REFERENCE_RSS_MARKER} {matches[0]}\n", - ) - - -def _parse_translated_reference_child_rss_kib(stderr: str) -> int: - markers: dict[str, list[int]] = { - DARWIN_RSS_MARKER: [], - REFERENCE_RSS_MARKER: [], - } - for line in stderr.splitlines(): - fields = line.split() - if len(fields) == 2 and fields[0] in markers: - try: - markers[fields[0]].append(int(fields[1])) - except ValueError as error: - raise AcceptanceError( - "translated Reference RSS marker is malformed" - ) from error - fft_values = markers[DARWIN_RSS_MARKER] - benchmark_values = markers[REFERENCE_RSS_MARKER] - if ( - len(fft_values) != 1 - or len(benchmark_values) != 1 - or fft_values[0] < 1 - or fft_values != benchmark_values - ): - raise AcceptanceError( - "translated Reference command lacks one matching exact child RSS marker" - ) - return fft_values[0] - - -def _formal_reference_evaluator_rss_kib( - driver_child_rss_kib: int, - direct_command_watchdog_rss_kib: int, - translated_child_rss_kib: int, -) -> int: - values = ( - driver_child_rss_kib, - direct_command_watchdog_rss_kib, - translated_child_rss_kib, - ) - if ( - any( - not isinstance(value, int) or isinstance(value, bool) or value < 0 - for value in values - ) - or driver_child_rss_kib < 1 - ): - raise AcceptanceError("Reference evaluator RSS evidence is invalid") - # The formal ratio compares the two fresh evaluator processes. Compiler - # and wrapper peaks remain watchdog/cap telemetry, not part of this value. - return driver_child_rss_kib - - -def _run_watched( - command: Sequence[str], - *, - python: str, - environment: Mapping[str, str], - timeout_seconds: float, - log_path: Path, - memory_limit_gib: float = MEMORY_LIMIT_GIB, - watchdog_report_path: Path | None = None, - normalize_completed: ( - Callable[[subprocess.CompletedProcess[str]], subprocess.CompletedProcess[str]] - | None - ) = None, -) -> WatchedCompletedProcess: - """Run one watchdog and give it time to reap its separate-session child.""" - - if not _positive_finite(timeout_seconds): - raise AcceptanceError("watched command timeout must be positive") - if not _positive_finite(memory_limit_gib): - raise AcceptanceError("watched command memory limit must be positive") - if watchdog_report_path is not None: - watchdog_report_path.parent.mkdir(parents=True, exist_ok=True) - if watchdog_report_path.exists(): - raise AcceptanceError( - f"watchdog report already exists: {watchdog_report_path}" - ) - watched_command = _watchdog_command( - command, - python=python, - memory_limit_gib=memory_limit_gib, - report_json=watchdog_report_path, - ) - started = time.perf_counter() - process = subprocess.Popen( - watched_command, - cwd=ROOT, - env=dict(environment), - text=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - timed_out = False - timeout_cleanup = "not-required" - try: - stdout, stderr = process.communicate(timeout=timeout_seconds) - except subprocess.TimeoutExpired: - timed_out = True - process.terminate() - timeout_cleanup = "sigterm-complete" - try: - stdout, stderr = process.communicate(timeout=WATCHDOG_CLEANUP_WAIT_SECONDS) - except subprocess.TimeoutExpired: - process.kill() - stdout, stderr = process.communicate() - timeout_cleanup = "sigkill-fallback" - elapsed_seconds = time.perf_counter() - started - completed: subprocess.CompletedProcess[str] = subprocess.CompletedProcess( - args=watched_command, - returncode=process.returncode, - stdout=stdout, - stderr=stderr, - ) - normalization_error: Exception | None = None - if normalize_completed is not None and not timed_out and completed.returncode == 0: - try: - completed = normalize_completed(completed) - except ( - Exception - ) as error: # Preserve the raw child evidence before surfacing it. - normalization_error = error - peak_guard_kib: int | None = None - peak_rss_kib: int | None = None - watchdog_report_error: Exception | None = None - if watchdog_report_path is not None and not timed_out and completed.returncode == 0: - try: - peak_rss_kib, peak_guard_kib = _read_watchdog_usage_kib( - watchdog_report_path - ) - except Exception as error: - watchdog_report_error = error - log_path.parent.mkdir(parents=True, exist_ok=True) - log_started = time.perf_counter() - log_path.write_text( - json.dumps( - { - "command": list(command), - "watchdog_command": list(watched_command), - "elapsed_seconds": elapsed_seconds, - "elapsed_excludes_log_write": True, - "returncode": completed.returncode, - "stdout": completed.stdout, - "stderr": completed.stderr, - "timed_out": timed_out, - "timeout_cleanup": timeout_cleanup, - "normalization_error": ( - None - if normalization_error is None - else f"{type(normalization_error).__name__}: {normalization_error}" - ), - "watchdog_report": ( - None if watchdog_report_path is None else str(watchdog_report_path) - ), - "watchdog_peak_guard_kib": peak_guard_kib, - "watchdog_peak_rss_kib": peak_rss_kib, - "watchdog_report_error": ( - None - if watchdog_report_error is None - else f"{type(watchdog_report_error).__name__}: " - f"{watchdog_report_error}" - ), - }, - indent=2, - sort_keys=True, - ) - + "\n", - encoding="utf-8", - ) - log_write_seconds = time.perf_counter() - log_started - result = WatchedCompletedProcess( - completed.args, - completed.returncode, - completed.stdout, - completed.stderr, - elapsed_seconds=elapsed_seconds, - log_write_seconds=log_write_seconds, - peak_guard_kib=peak_guard_kib, - peak_rss_kib=peak_rss_kib, - timed_out=timed_out, - timeout_cleanup=timeout_cleanup, - ) - if timed_out: - raise AcceptanceError( - f"command timed out after {timeout_seconds:g}s " - f"(watchdog cleanup: {timeout_cleanup}): {shlex.join(command)}; " - f"see {log_path}" - ) - if result.returncode != 0: - raise AcceptanceError( - f"command failed with status {result.returncode}: " - f"{shlex.join(command)}; see {log_path}" - ) - if normalization_error is not None: - raise normalization_error - if watchdog_report_error is not None: - raise watchdog_report_error - return result - - -def _load_reference_module() -> ModuleType: - if not REFERENCE_DRIVER.is_file(): - raise AcceptanceError(f"reference driver is missing: {REFERENCE_DRIVER}") - name = "_pyamplicol_fft_reference_benchmark" - specification = importlib.util.spec_from_file_location(name, REFERENCE_DRIVER) - if specification is None or specification.loader is None: - raise AcceptanceError("cannot load bundled AmpliGluonTrace benchmark") - module = importlib.util.module_from_spec(specification) - sys.modules[name] = module - specification.loader.exec_module(module) - return module - - -@contextmanager -def _arguments(arguments: Sequence[str]): - previous = sys.argv - sys.argv = [str(REFERENCE_DRIVER), *arguments] - try: - yield - finally: - sys.argv = previous - - -def _reference_arguments( - reference: ModuleType, - *, - total_gluons: int, - build_dir: Path, - fc: str, - target_seconds: float, - timeout_seconds: float, - memory_limit_gib: float = MEMORY_LIMIT_GIB, - repetition_quantum: int | None = None, - warm_sample_count: int = WARM_SAMPLE_COUNT, -) -> argparse.Namespace: - if ( - isinstance(warm_sample_count, bool) - or not isinstance(warm_sample_count, int) - or warm_sample_count < 1 - ): - raise AcceptanceError("reference warm_sample_count must be positive") - argv = ( - "--min-gluons", - str(total_gluons), - "--max-gluons", - str(total_gluons), - "--points", - str(POINT_COUNT), - "--seed", - str(BASE_SEED), - "--mhv-samples", - "1", - "--non-mhv-samples", - "1", - "--backend", - REFERENCE_BACKEND, - "--target-seconds", - f"{target_seconds:.17g}", - "--batches", - str(warm_sample_count), - "--initialization-runs", - "1", - "--skip-initialization-preflight", - "--max-memory-gib", - f"{memory_limit_gib:g}", - "--backend-timeout", - f"{timeout_seconds:g}", - "--build-dir", - str(build_dir), - "--fc", - fc, - ) - if repetition_quantum is not None: - argv = (*argv, "--repetition-quantum", str(repetition_quantum)) - with _arguments(argv): - parsed = reference.parse_arguments() - reference.validate_arguments(parsed) - return parsed - - -def _reference_representative_warm_samples( - cell_timings: Mapping[tuple[int, int, int], float], - *, - warm_sample_count: int = WARM_SAMPLE_COUNT, -) -> tuple[float, ...]: - """Validate DefaultBG's one representative event/configuration per batch.""" - - expected = { - (batch, REPRESENTATIVE_POINT, 1) - for batch in range(1, warm_sample_count + 1) - } - if set(cell_timings) != expected: - raise AcceptanceError( - "reference must report one point-1 cell in each requested batch" - ) - values = tuple( - cell_timings[(batch, REPRESENTATIVE_POINT, 1)] - for batch in range(1, warm_sample_count + 1) - ) - if not all(_positive_finite(value) for value in values): - raise AcceptanceError("reference representative timing cells are not positive") - return values - - -def _bounded_reference_cold_timeout( - effective_timeout: float, - cold_limit_seconds: float | None, - cold_started: float, -) -> float: - if cold_limit_seconds is None: - return effective_timeout - remaining_cold = cold_limit_seconds - (time.perf_counter() - cold_started) - if remaining_cold <= 0.0: - raise ReferenceColdLimitError( - "reference campaign exhausted its aggregate cold deadline" - ) - return min(effective_timeout, remaining_cold) - - -def _is_reference_backend_build_command( - command: Sequence[str], - *, - build_dir: Path, - build_phase_active: bool, -) -> bool: - """Identify compiler/linker commands belonging only to AmpliGluonTrace.""" - - if not build_phase_active: - return False - backend_dir = (build_dir / REFERENCE_BUILD_PROGRAM).resolve() - backend_prefix = f"{backend_dir}{os.sep}" - include_prefixes = ( - backend_prefix, - f"-I{backend_prefix}", - f"-J{backend_prefix}", - ) - return any( - str(token) == str(backend_dir) or str(token).startswith(include_prefixes) - for token in command - ) - - -def _run_reference( - *, - reference: ModuleType, - total_gluons: int, - run_root: Path, - python: str, - environment: Mapping[str, str], - fc: str, - target_seconds: float, - timeout_seconds: float, - cold_limit_seconds: float | None = None, - memory_limit_gib: float = MEMORY_LIMIT_GIB, - repetition_quantum: int | None = None, - warm_sample_count: int = WARM_SAMPLE_COUNT, - sum_helicities: bool = False, -) -> _ReferenceRun: - reference_root = run_root / "reference" / f"N{total_gluons}" - build_dir = reference_root / "build" - if build_dir.exists(): - raise AcceptanceError("reference build directory is not clean") - effective_repetition_quantum = 1 if sum_helicities else repetition_quantum - arguments = _reference_arguments( - reference, - total_gluons=total_gluons, - build_dir=build_dir, - fc=fc, - target_seconds=target_seconds, - timeout_seconds=timeout_seconds, - memory_limit_gib=memory_limit_gib, - repetition_quantum=effective_repetition_quantum, - warm_sample_count=warm_sample_count, - ) - command_index = 0 - command_log_write_seconds = 0.0 - watchdog_max_rss_kib = 0 - direct_command_watchdog_max_rss_kib = 0 - translated_child_max_rss_kib = 0 - watchdog_max_peak_guard_kib = 0 - clean_build_seconds = 0.0 - clean_build_command_count = 0 - build_phase_active = False - original_run_command = reference.run_command - campaign_timeout_seconds = timeout_seconds - cold_started = time.perf_counter() - - def watched_reference_command( - command: Sequence[str], - description: str, - timeout_seconds: float | None = None, - ) -> subprocess.CompletedProcess[str]: - nonlocal command_index, command_log_write_seconds - nonlocal watchdog_max_peak_guard_kib, watchdog_max_rss_kib - nonlocal direct_command_watchdog_max_rss_kib - nonlocal translated_child_max_rss_kib - nonlocal clean_build_command_count, clean_build_seconds - command_index += 1 - safe_description = re.sub(r"[^A-Za-z0-9._-]+", "-", description).strip("-") - translated = False - command_to_run = tuple(str(item) for item in command) - is_clean_backend_build = _is_reference_backend_build_command( - command_to_run, - build_dir=build_dir, - build_phase_active=build_phase_active, - ) - if sys.platform == "darwin": - command_to_run, translated = _translate_darwin_reference_command( - command_to_run, - python=python, - ) - else: - command_to_run, translated = _translate_gnu_reference_command( - command_to_run, - python=python, - ) - effective_timeout = ( - campaign_timeout_seconds + 30.0 - if timeout_seconds is None - else timeout_seconds + 30.0 - ) - if translated and timeout_seconds is not None: - # run_driver already supplies backend_timeout + its cleanup grace. - effective_timeout = timeout_seconds - effective_timeout = _bounded_reference_cold_timeout( - effective_timeout, cold_limit_seconds, cold_started - ) - log_path = reference_root / "logs" / f"{command_index:03d}-{safe_description}" - completed = _run_watched( - command_to_run, - python=python, - environment=environment, - timeout_seconds=effective_timeout, - log_path=log_path.with_suffix(".json"), - memory_limit_gib=memory_limit_gib, - watchdog_report_path=log_path.with_suffix(".watchdog.json"), - normalize_completed=( - _synthesize_reference_rss_marker if translated else None - ), - ) - if completed.peak_rss_kib is None or completed.peak_guard_kib is None: - raise AcceptanceError("reference command has no watchdog RSS evidence") - watchdog_max_rss_kib = max(watchdog_max_rss_kib, completed.peak_rss_kib) - if translated: - translated_child_max_rss_kib = max( - translated_child_max_rss_kib, - _parse_translated_reference_child_rss_kib(completed.stderr), - ) - else: - direct_command_watchdog_max_rss_kib = max( - direct_command_watchdog_max_rss_kib, - completed.peak_rss_kib, - ) - watchdog_max_peak_guard_kib = max( - watchdog_max_peak_guard_kib, completed.peak_guard_kib - ) - if is_clean_backend_build: - clean_build_seconds += completed.elapsed_seconds - clean_build_command_count += 1 - command_log_write_seconds += completed.log_write_seconds - return completed - - reference.run_command = watched_reference_command - try: - compiler = shlex.split(arguments.fc) - flags = shlex.split(arguments.fflags) - if not compiler: - raise AcceptanceError("reference Fortran compiler is empty") - compiler_identity = reference.compiler_version(compiler).strip() - build_phase_active = True - try: - rambo, proxy, executables = reference.build_executables( - arguments, - compiler, - compiler_identity, - flags, - ) - finally: - build_phase_active = False - reference_executable = executables.get(REFERENCE_BACKEND) - expected_build_dir = (build_dir / REFERENCE_BUILD_PROGRAM).resolve() - if ( - reference_executable is None - or expected_build_dir not in reference_executable.resolve().parents - or clean_build_command_count < 1 - or not _positive_finite(clean_build_seconds) - ): - raise AcceptanceError( - "reference clean backend build boundary is incomplete" - ) - events, _, exhaustive_helicities = reference.generate_events( - rambo, - total_gluons, - arguments, - ) - weights, _, _, _ = reference.run_helicity_proxy( - proxy, - events, - exhaustive_helicities, - arguments, - ) - _, _, selected = reference.select_helicity_samples( - events, - exhaustive_helicities, - weights, - total_gluons, - arguments, - ) - representative = selected[0] - if representative.path == "zero" or representative.proxy_weight <= 0.0: - raise AcceptanceError("reference selected an analytically zero helicity") - uniform_events: list[Path] = [] - event_dir = reference_root / "selected-helicity-events" - for point, source_event in enumerate(events, start=1): - destination = event_dir / f"N{total_gluons}-point-{point:02d}.event" - reference.write_single_helicity_event( - source_event, - destination, - representative.helicities, - ) - uniform_events.append(destination) - setup_to_driver_seconds = ( - time.perf_counter() - cold_started - command_log_write_seconds - ) - if not _positive_finite(setup_to_driver_seconds): - raise AcceptanceError("reference setup timing is not positive") - if sum_helicities: - run = reference.run_driver( - REFERENCE_BACKEND, - reference_executable, - events, - arguments, - False, - sum_helicities=True, - ) - else: - run = reference.run_driver( - REFERENCE_BACKEND, - reference_executable, - uniform_events, - arguments, - False, - ) - finally: - reference.run_command = original_run_command - - batch_values = _reference_representative_warm_samples( - run.cell_timings, - warm_sample_count=warm_sample_count, - ) - warm_repetitions: tuple[int, ...] = () - warm_calibration_seconds: tuple[float, ...] = () - if effective_repetition_quantum is not None: - expected_repetition_keys = { - (batch, REPRESENTATIVE_POINT, 1) - for batch in range(1, warm_sample_count + 1) - } - if ( - run.cell_repetitions is None - or set(run.cell_repetitions) != expected_repetition_keys - or any( - value < effective_repetition_quantum - or value % effective_repetition_quantum != 0 - for value in run.cell_repetitions.values() - ) - ): - raise AcceptanceError( - "reference did not use the requested repetition quantum" - ) - warm_repetitions = tuple( - run.cell_repetitions[(batch, REPRESENTATIVE_POINT, 1)] - for batch in range(1, warm_sample_count + 1) - ) - if len(set(warm_repetitions)) != 1: - raise AcceptanceError("reference changed repetitions after calibration") - expected_calibration_keys = {(REPRESENTATIVE_POINT, 1)} - if ( - run.cell_calibration_seconds is None - or set(run.cell_calibration_seconds) != expected_calibration_keys - or any( - value < target_seconds - for value in run.cell_calibration_seconds.values() - ) - ): - raise AcceptanceError( - "reference repetition calibration did not reach its timing target" - ) - warm_calibration_seconds = tuple(run.cell_calibration_seconds.values()) - if ( - run.first_helicity_sweep is None - or not _positive_finite(run.first_helicity_sweep) - or run.peak_rss_kib is None - or run.peak_rss_kib < 1 - ): - raise AcceptanceError("reference cold/RSS metrics are incomplete") - if sum_helicities: - exhaustive_keys = set(exhaustive_helicities) - if set(run.matrix_elements) != exhaustive_keys or any( - not math.isfinite(value) or value < 0.0 - for value in run.matrix_elements.values() - ): - raise AcceptanceError( - "reference did not return the exhaustive helicity grid" - ) - helicity_coverage_count = len( - [key for key in exhaustive_keys if key[0] == REPRESENTATIVE_POINT] - ) - active_helicity_count = sum( - not reference.is_analytic_zero_helicity(helicities) - for (point, _), helicities in exhaustive_helicities.items() - if point == REPRESENTATIVE_POINT - ) - if ( - helicity_coverage_count < 1 - or active_helicity_count < 1 - or active_helicity_count > helicity_coverage_count - ): - raise AcceptanceError("reference exhaustive helicity census is invalid") - matrix_elements = tuple( - math.fsum( - run.matrix_elements[key] - for key in sorted(exhaustive_keys) - if key[0] == point - ) - for point in range(1, POINT_COUNT + 1) - ) - if any(not _positive_finite(value) for value in matrix_elements): - raise AcceptanceError("reference helicity sum is zero or non-finite") - else: - expected_matrix_element_keys = { - (point, 1) for point in range(1, POINT_COUNT + 1) - } - if set(run.matrix_elements) != expected_matrix_element_keys or any( - not _positive_finite(value) for value in run.matrix_elements.values() - ): - raise AcceptanceError( - "reference did not confirm the selected helicity at all 10 points" - ) - matrix_elements = tuple( - run.matrix_elements[(point, 1)] for point in range(1, POINT_COUNT + 1) - ) - helicity_coverage_count = 1 - active_helicity_count = 1 - if watchdog_max_peak_guard_kib > int(memory_limit_gib * 1024**2): - raise AcceptanceError("reference exceeded the watchdog peak-guard bound") - metrics = ReferenceMetrics( - total_gluons=total_gluons, - generator_seed=generator_seed(total_gluons), - backend=REFERENCE_BACKEND, - clean_build_scope=REFERENCE_CLEAN_BUILD_SCOPE, - clean_build_command_count=clean_build_command_count, - clean_build_seconds=clean_build_seconds, - setup_to_driver_seconds=setup_to_driver_seconds, - initialization_seconds=run.initialization, - first_pass_seconds=run.first_helicity_sweep, - warm_samples_seconds=batch_values, - warm_median_seconds=statistics.median(batch_values), - max_rss_kib=_formal_reference_evaluator_rss_kib( - run.peak_rss_kib, - direct_command_watchdog_max_rss_kib, - translated_child_max_rss_kib, - ), - selected_helicity=tuple(representative.helicities), - selected_path=representative.path, - event_paths=tuple(str(path) for path in uniform_events), - matrix_elements=matrix_elements, - driver_max_rss_kib=run.peak_rss_kib, - watchdog_max_rss_kib=watchdog_max_rss_kib, - direct_command_watchdog_max_rss_kib=( - direct_command_watchdog_max_rss_kib or None - ), - translated_child_max_rss_kib=translated_child_max_rss_kib or None, - watchdog_max_peak_guard_kib=watchdog_max_peak_guard_kib, - warm_repetitions=warm_repetitions, - warm_repetition_quantum=effective_repetition_quantum, - warm_calibration_seconds=warm_calibration_seconds, - helicity_workload="sum" if sum_helicities else "fixed", - helicity_coverage_count=helicity_coverage_count, - timed_helicity_count=active_helicity_count, - active_helicity_count=active_helicity_count, - exhaustive_event_paths=( - tuple(str(path) for path in events) if sum_helicities else () - ), - ) - if ( - cold_limit_seconds is not None - and metrics.setup_to_ready_seconds > cold_limit_seconds - ): - raise ReferenceColdLimitError( - "reference setup/initialization/first pass exceeded its cold deadline" - ) - return _ReferenceRun(metrics=metrics, event_paths=tuple(uniform_events)) - - -def _build_probe( - *, - run_root: Path, - python: str, - cxx: str, - environment: Mapping[str, str], - memory_limit_gib: float = MEMORY_LIMIT_GIB, -) -> tuple[Path, dict[str, Any]]: - sdk = _run_watched( - (python, "-m", "rusticol_config", "--json"), - python=python, - environment=environment, - timeout_seconds=60.0, - log_path=run_root / "logs" / "sdk-config.json", - memory_limit_gib=memory_limit_gib, - ) - try: - sdk_info = json.loads(sdk.stdout) - except json.JSONDecodeError as error: - raise AcceptanceError("Rusticol SDK query returned invalid JSON") from error - required = {"cflags", "link_flags", "target", "package_version"} - if not isinstance(sdk_info, dict) or not required <= set(sdk_info): - raise AcceptanceError("Rusticol SDK query is incomplete") - executable = run_root / "candidate-probe" / "fft-gluon-candidate-probe" - executable.parent.mkdir(parents=True, exist_ok=True) - compiler = shlex.split(cxx) - if not compiler: - raise AcceptanceError("C++ compiler command is empty") - command = ( - *compiler, - "-std=c++17", - "-O3", - "-DNDEBUG", - *map(str, sdk_info["cflags"]), - str(PROBE_SOURCE), - "-o", - str(executable), - *map(str, sdk_info["link_flags"]), - *_candidate_probe_executable_link_flags(sys.platform), - ) - _run_watched( - command, - python=python, - environment=environment, - timeout_seconds=600.0, - log_path=run_root / "logs" / "candidate-probe-build.json", - memory_limit_gib=memory_limit_gib, - ) - return executable, sdk_info - - -def _candidate_probe_executable_link_flags(platform_name: str) -> tuple[str, ...]: - """Discard SDK code that is unreachable from this standalone probe.""" - - if platform_name == "darwin": - # Apple ld keeps exported symbols as dead-strip roots. A standalone - # benchmark executable has no plugin ABI, so retaining the static - # archive's thousands of Rust globals defeats ordinary link-time GC. - return ("-Wl,-dead_strip", "-Wl,-no_exported_symbols") - return () - - -def _candidate_probe_command( - *, - probe: Path, - artifact: Path, - total_gluons: int, - target_seconds: float, - event_paths: Sequence[Path], - first_ready_only: bool, -) -> tuple[str, ...]: - return ( - str(probe), - str(artifact), - process_name(total_gluons), - "--target-seconds", - f"{target_seconds:.17g}", - "--samples", - str(WARM_SAMPLE_COUNT), - *(("--first-ready-only",) if first_ready_only else ()), - *(str(path) for path in event_paths), - ) - - -def _validate_candidate_probe_identity( - metrics: CandidateProbeMetrics | CandidateFirstReadyMetrics, - *, - lane: str, - total_gluons: int, - expected_helicities: Sequence[int], -) -> None: - if metrics.execution_mode != lane: - raise AcceptanceError("candidate probe execution mode differs from its lane") - if metrics.process != process_name(total_gluons): - raise AcceptanceError("candidate probe process differs from its paired process") - if lane == "recurrence" and metrics.helicity_coverage_count != 1: - raise AcceptanceError( - "recurrence candidate did not preserve generation helicity specialization" - ) - if lane == "on-the-fly" and metrics.helicity_coverage_count <= 1: - raise AcceptanceError( - "on-the-fly candidate did not preserve complete runtime selector coverage" - ) - expected_helicity_id = "h:" + ",".join( - f"{helicity:+d}" for helicity in expected_helicities - ) - if metrics.selected_helicity_id != expected_helicity_id: - raise AcceptanceError( - "candidate probe helicity differs from the generation-selected " - "known-nonzero helicity" - ) - - -def _run_candidate( - *, - lane: str, - total_gluons: int, - reference: _ReferenceRun, - probe: Path, - run_root: Path, - python: str, - environment: Mapping[str, str], - target_seconds: float, - timeout_seconds: float, - continuation_stage_limit_seconds: float | None = None, -) -> CandidateMetrics: - candidate_root = run_root / "candidate" / lane / f"N{total_gluons}" - artifact = candidate_root / "artifact" - candidate_environment = dict(environment) - candidate_environment["PYAMPLICOL_CACHE_DIR"] = str( - candidate_root / "disabled-model-cache" - ) - command = candidate_generation_command( - python=python, - lane=lane, - total_gluons=total_gluons, - helicities=reference.metrics.selected_helicity, - artifact=artifact, - ) - lane_wall_started = time.perf_counter() - generation_started = lane_wall_started - generation = _run_watched( - command, - python=python, - environment=candidate_environment, - timeout_seconds=( - min(timeout_seconds, continuation_stage_limit_seconds) - if continuation_stage_limit_seconds is not None - else timeout_seconds - ), - log_path=candidate_root / "generation.json", - ) - generation_seconds = ( - time.perf_counter() - generation_started - generation.log_write_seconds - ) - if not _positive_finite(generation_seconds): - raise AcceptanceError("candidate generation timing is not positive") - if ( - continuation_stage_limit_seconds is not None - and generation_seconds >= continuation_stage_limit_seconds - ): - raise AcceptanceError( - "candidate generation did not remain below the 15 minute continuation cap" - ) - - cold_metrics: CandidateFirstReadyMetrics | None = None - if continuation_stage_limit_seconds is not None: - first_ready = _run_watched( - _candidate_probe_command( - probe=probe, - artifact=artifact, - total_gluons=total_gluons, - target_seconds=target_seconds, - event_paths=reference.event_paths, - first_ready_only=True, - ), - python=python, - environment=candidate_environment, - # The continuation contract limits the reported first warm-up, - # independently of artifact load. Give the fresh process the - # enclosing lane deadline so a valid sub-15-minute warm-up is not - # killed merely because loading preceded it. - timeout_seconds=timeout_seconds, - log_path=candidate_root / "probe-first-ready.json", - ) - cold_metrics = parse_candidate_first_ready_output(first_ready.stdout) - _validate_candidate_probe_identity( - cold_metrics, - lane=lane, - total_gluons=total_gluons, - expected_helicities=reference.metrics.selected_helicity, - ) - if cold_metrics.first_warm_seconds >= continuation_stage_limit_seconds: - raise AcceptanceError( - "candidate first warm-up did not remain below the 15 minute " - "continuation cap" - ) - if cold_metrics.max_rss_kib > int(MEMORY_LIMIT_GIB * 1024**2): - raise AcceptanceError( - "candidate first-ready process exceeded the 30 GiB RSS cap" - ) - - if continuation_stage_limit_seconds is None: - remaining_warm = timeout_seconds - (time.perf_counter() - lane_wall_started) - if remaining_warm <= 0.0: - raise AcceptanceError("candidate generation exhausted its lane timeout") - else: - # Optional feasibility has already been decided by the fresh cold-only - # process. The warmed campaign gets an independent bounded window. - remaining_warm = timeout_seconds - completed = _run_watched( - _candidate_probe_command( - probe=probe, - artifact=artifact, - total_gluons=total_gluons, - target_seconds=target_seconds, - event_paths=reference.event_paths, - first_ready_only=False, - ), - python=python, - environment=candidate_environment, - timeout_seconds=remaining_warm, - log_path=( - candidate_root / "probe-warm.json" - if cold_metrics is not None - else candidate_root / "probe.json" - ), - ) - probe_metrics = parse_candidate_probe_output(completed.stdout) - _validate_candidate_probe_identity( - probe_metrics, - lane=lane, - total_gluons=total_gluons, - expected_helicities=reference.metrics.selected_helicity, - ) - load_seconds = ( - cold_metrics.load_seconds - if cold_metrics is not None - else probe_metrics.load_seconds - ) - first_warm_seconds = ( - cold_metrics.first_warm_seconds - if cold_metrics is not None - else probe_metrics.first_warm_seconds - ) - max_rss_kib = max( - probe_metrics.max_rss_kib, - cold_metrics.max_rss_kib if cold_metrics is not None else 0, - ) - numerical_parity = compare_candidate_to_reference( - total_gluons=total_gluons, - candidate_values=probe_metrics.point_values, - reference_values=reference.metrics.matrix_elements, - ) - return CandidateMetrics( - lane=lane, - total_gluons=total_gluons, - generator_seed=generator_seed(total_gluons), - generation_seconds=generation_seconds, - load_seconds=load_seconds, - first_warm_seconds=first_warm_seconds, - max_rss_kib=max_rss_kib, - probe=probe_metrics, - numerical_parity=numerical_parity, - ) - - -def _cpu_policy(platform_name: str) -> dict[str, object]: - thread_environment = {name: "1" for name in SINGLE_THREAD_ENVIRONMENT} - if platform_name == "darwin": - return { - "requested_cpu_cores": 1, - "method": "single-thread-environment", - "thread_environment": thread_environment, - "affinity_available": False, - "affinity_enforced": False, - "cpu": None, - } - if platform_name.startswith("linux"): - return { - "requested_cpu_cores": 1, - "method": "sched-affinity-and-single-thread-environment", - "thread_environment": thread_environment, - "affinity_available": bool( - hasattr(os, "sched_getaffinity") and hasattr(os, "sched_setaffinity") - ), - "affinity_enforced": False, - "cpu": None, - } - raise AcceptanceError(f"unsupported performance host platform {platform_name!r}") - - -def _enforce_one_core(platform_name: str) -> dict[str, object]: - policy = _cpu_policy(platform_name) - if platform_name == "darwin": - return policy - if not policy["affinity_available"]: - raise AcceptanceError("Linux host does not expose sched affinity") - try: - allowed = sorted(os.sched_getaffinity(0)) - if not allowed: - raise AcceptanceError("the process has no allowed CPU") - core = allowed[0] - os.sched_setaffinity(0, {core}) - except OSError as error: - raise AcceptanceError("could not enforce Linux CPU affinity") from error - return policy | {"affinity_enforced": True, "cpu": core} - - -def _plain_candidate(candidate: CandidateMetrics) -> dict[str, object]: - payload = asdict(candidate) - payload["cold_to_ready_seconds"] = candidate.cold_to_ready_seconds - return payload - - -def _plain_reference(reference: ReferenceMetrics) -> dict[str, object]: - payload = asdict(reference) - payload["cold_to_ready_seconds"] = reference.cold_to_ready_seconds - payload["setup_to_ready_seconds"] = reference.setup_to_ready_seconds - return payload - - -def _plain_gate(gate: GateResult) -> dict[str, object]: - return asdict(gate) | {"passes": gate.passes} - - -def _gate_report(gates: Sequence[GateResult]) -> dict[str, object]: - """Serialize every completed gate and aggregate its acceptance result.""" - - return { - "gates": [_plain_gate(gate) for gate in gates], - # Infeasible optional rows are skipped before producing a GateResult. - # Every row that was measured is therefore acceptance-authoritative. - "passes": all(gate.passes for gate in gates), - } - - -def _write_report(path: Path, payload: Mapping[str, object]) -> None: - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - temporary.parent.mkdir(parents=True, exist_ok=True) - temporary.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - - -def _reference_git_output(*arguments: str) -> bytes: - try: - completed = subprocess.run( - ("git", "-C", str(REFERENCE_ROOT), *arguments), - check=False, - capture_output=True, - ) - except OSError as error: - raise AcceptanceError( - f"cannot inspect FFT reference source: {error}" - ) from error - if completed.returncode != 0: - detail = os.fsdecode(completed.stderr).strip() - raise AcceptanceError( - "cannot inspect FFT reference source" + (f": {detail}" if detail else "") - ) - return completed.stdout - - -def _hash_identity_field(digest: Any, value: bytes) -> None: - digest.update(len(value).to_bytes(8, "big")) - digest.update(value) - - -def _reference_source_identity() -> ReferenceSourceIdentity: - """Hash every tracked or nonignored reference input at the pinned HEAD.""" - - repository_root = Path( - os.fsdecode(_reference_git_output("rev-parse", "--show-toplevel")).strip() - ).resolve() - if repository_root != REFERENCE_ROOT.resolve(): - raise AcceptanceError( - f"FFT reference source is not an independent repository: {REFERENCE_ROOT}" - ) - revision = os.fsdecode( - _reference_git_output("rev-parse", "--verify", "HEAD") - ).strip() - if revision != REFERENCE_REVISION: - raise AcceptanceError( - "FFT reference source is at the wrong revision: " - f"expected {REFERENCE_REVISION}, found {revision}" - ) - - raw_paths = _reference_git_output( - "ls-files", "-z", "--cached", "--others", "--exclude-standard", "--" - ) - paths = sorted(path for path in raw_paths.split(b"\0") if path) - if not paths: - raise AcceptanceError("FFT reference source contains no authenticated inputs") - - digest = hashlib.sha256() - _hash_identity_field(digest, b"pyamplicol-fft-reference-content-v1") - for raw_path in paths: - relative = Path(os.fsdecode(raw_path)) - if relative.is_absolute() or ".." in relative.parts: - raise AcceptanceError("FFT reference source reported an unsafe path") - path = REFERENCE_ROOT / relative - try: - before = path.lstat() - if stat.S_ISREG(before.st_mode): - kind = b"file+x" if before.st_mode & 0o111 else b"file" - content = path.read_bytes() - elif stat.S_ISLNK(before.st_mode): - kind = b"symlink" - content = os.fsencode(os.readlink(path)) - else: - raise AcceptanceError( - f"FFT reference input has unsupported file type: {relative}" - ) - after = path.lstat() - except OSError as error: - raise AcceptanceError( - f"cannot authenticate FFT reference input {relative}: {error}" - ) from error - before_identity = ( - before.st_mode, - before.st_size, - before.st_mtime_ns, - before.st_ino, - ) - after_identity = ( - after.st_mode, - after.st_size, - after.st_mtime_ns, - after.st_ino, - ) - if before_identity != after_identity: - raise AcceptanceError( - f"FFT reference input changed while being authenticated: {relative}" - ) - _hash_identity_field(digest, raw_path) - _hash_identity_field(digest, kind) - _hash_identity_field(digest, content) - return ReferenceSourceIdentity(revision, digest.hexdigest(), len(paths)) - - -def _require_reference_source_identity( - expected: ReferenceSourceIdentity | None = None, -) -> ReferenceSourceIdentity: - current = _reference_source_identity() - if expected is not None and current != expected: - raise AcceptanceError( - "FFT reference source identity changed during the campaign: " - f"started at {expected.revision}/{expected.content_sha256}, now " - f"{current.revision}/{current.content_sha256}" - ) - return current - - -def _require_campaign_source_identity( - expected: ReportSourceIdentity | None = None, -) -> ReportSourceIdentity: - """Authenticate a clean HEAD before measuring or retaining any result.""" - - try: - current = require_eligible_report_source(ROOT) - except ReportSourceIdentityError as error: - raise AcceptanceError( - f"FFT performance source is ineligible: {error}" - ) from error - if expected is not None and current != expected: - raise AcceptanceError( - "FFT performance source identity changed during the campaign: " - f"started at {expected.revision}/{expected.tree}, now " - f"{current.revision}/{current.tree}" - ) - return current - - -def dry_run_plan( - *, - run_id: str, - python: str, - include_optional: bool, - platform_name: str | None = None, -) -> dict[str, object]: - host_platform = sys.platform if platform_name is None else platform_name - cpu_policy = _cpu_policy(host_platform) - multiplicities = ( - (*MANDATORY_MULTIPLICITIES, *OPTIONAL_MULTIPLICITIES) - if include_optional - else MANDATORY_MULTIPLICITIES - ) - return { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "dry_run": True, - "host_platform": host_platform, - "run_root": str(PERFORMANCE_ROOT / "runs" / run_id), - "reference_driver": str(REFERENCE_DRIVER), - "reference": { - "backend": REFERENCE_BACKEND, - "source_revision": REFERENCE_REVISION, - "source_identity": ( - "pinned-head-plus-tracked-and-nonignored-content-sha256" - ), - "color_contraction": "fft", - "kinematics": "default-bg", - "clean_build_per_multiplicity": True, - "clean_build_scope": REFERENCE_CLEAN_BUILD_SCOPE, - "clean_build_program": REFERENCE_BUILD_PROGRAM, - "clean_build_timing": ( - "sum of watched compiler/linker wall times for the " - "AmpliGluonTrace backend; RAMBO and helicity-proxy builds excluded" - ), - "initialization_and_first_pass_separate": True, - "formal_cold_to_ready_metric": ( - "clean AmpliGluonTrace backend build plus initialization plus " - "first complete pass" - ), - "scaling_setup_to_ready_metric": ( - "all setup through driver plus initialization plus first complete pass" - ), - "process_measurement": ( - "darwin-getrusage-child-plus-watchdog" - if host_platform == "darwin" - else "reference-gnu-time-timeout-prlimit-plus-watchdog" - ), - "rss_marker": DARWIN_RSS_MARKER, - "rss_metric": ( - "fresh evaluator-process peak RSS from the reference driver; " - "compiler and wrapper RSS are excluded from the formal ratio" - ), - "memory_guard_metric": ( - "max(process-tree RSS, Darwin physical footprint); enforcement only" - ), - }, - "candidate_probe_source": str(PROBE_SOURCE), - "multiplicities": [ - { - "total_gluons": total, - "generator_seed": generator_seed(total), - "required": total in MANDATORY_MULTIPLICITIES, - "point_count": POINT_COUNT, - "candidate_lanes": list(LANES if total <= 9 else ("global-winner",)), - "selected_helicity": "reference-proxy-selected-nonzero", - } - for total in multiplicities - ], - "measurement": { - "cpu_cores": 1, - "batch_size": 1, - "calibration_seconds_minimum": MINIMUM_CALIBRATION_SECONDS, - "calibration_scope": "representative-point-1-only", - "candidate_timer_source": "process-cpu-time", - "warm_batch_reduction": "point-1-cell-direct", - "timed_event_cells_per_batch": 1, - "warm_samples": WARM_SAMPLE_COUNT, - "warm_excludes_first_call": True, - "memory_limit_gib": MEMORY_LIMIT_GIB, - "fresh_process_same_os_rss": True, - "model_cache": "disabled-per-lane-and-multiplicity", - "mandatory_lane_order": list(LANES), - "optional_cold_and_warm_processes_separate": True, - "cpu_policy": cpu_policy, - }, - "helicity_policy": { - "recurrence": "generation-specialized-known-nonzero", - "on-the-fly": "complete-runtime-selector-fixed-helicity-query", - }, - "numerical_parity": { - "reference_values": "ordered-10-AmpliGluonTrace-matrix-elements", - "candidate_values": ( - "recurrence-first-pass-all-10;" - "otf-first-pass-points-2-10-plus-point-1-calibration" - ), - "candidate_runtime_parameter": "normalization.alpha_s_me_check", - "candidate_runtime_parameter_value": UNIT_COUPLING_ALPHA_S, - "candidate_to_reference_scale": "256*factorial(N-2)", - "relative_error_scale": "max(abs(candidate),abs(reference))", - "relative_tolerance": NUMERICAL_RELATIVE_TOLERANCE, - "failure_is_fatal": True, - "extra_evaluations": 0, - }, - "global_lane_policy": ( - "recurrence and on-the-fly are eligible under their respective " - "helicity workloads; the fastest lane passing every mandatory gate " - "supplies every reported metric and optional continuation" - ), - "thresholds": { - "warm_ratio_maximum": WARM_RATIO_LIMIT, - "rss_ratio_maximum": RSS_RATIO_LIMIT, - "cold_to_ready_ratio_maximum": COLD_RATIO_LIMIT, - "optional_generation_seconds_maximum_exclusive": ( - OPTIONAL_COLD_LIMIT_SECONDS - ), - "optional_first_warm_seconds_maximum_exclusive": ( - OPTIONAL_COLD_LIMIT_SECONDS - ), - "optional_continuation_deadlines_are_independent": True, - }, - "candidate_generation_template": list( - candidate_generation_command( - python=python, - lane="recurrence", - total_gluons=4, - helicities=(1, 1, 1, 1), - artifact=PERFORMANCE_ROOT - / "runs" - / run_id - / "candidate" - / "LANE" - / "N", - ) - ), - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--dry-run", action="store_true") - parser.add_argument("--include-optional", action="store_true") - parser.add_argument("--run-id", default="manual") - parser.add_argument("--python", default=sys.executable) - parser.add_argument("--cxx", default=os.environ.get("CXX", "c++")) - parser.add_argument("--fc", default=os.environ.get("FC", "gfortran")) - parser.add_argument( - "--reference-fft-root", - type=Path, - default=DEFAULT_REFERENCE_ROOT, - help=( - "pinned AllGluonsMultipletFFT checkout used by Reference FFT " - "(default path is populated by " - "dev-install --with-reference-fft)" - ), - ) - parser.add_argument( - "--target-seconds", - type=float, - default=MINIMUM_CALIBRATION_SECONDS, - ) - return parser - - -def _validate_arguments(arguments: argparse.Namespace) -> None: - if _RUN_ID.fullmatch(arguments.run_id) is None or arguments.run_id in {".", ".."}: - raise AcceptanceError("--run-id is not a safe workspace-local name") - if ( - not math.isfinite(arguments.target_seconds) - or arguments.target_seconds < MINIMUM_CALIBRATION_SECONDS - ): - raise AcceptanceError("--target-seconds must be at least 0.25") - if not arguments.python or not arguments.cxx or not arguments.fc: - raise AcceptanceError("compiler and Python commands must be nonempty") - - -def _campaign(arguments: argparse.Namespace) -> dict[str, object]: - source_identity = _require_campaign_source_identity() - reference_source_identity = _require_reference_source_identity() - run_root = PERFORMANCE_ROOT / "runs" / arguments.run_id - _create_workspace_directories(run_root) - environment = _workspace_environment(arguments.python) - os.environ.update(environment) - cpu_policy = _enforce_one_core(sys.platform) - probe, sdk_info = _build_probe( - run_root=run_root, - python=arguments.python, - cxx=arguments.cxx, - environment=environment, - ) - reference_module = _load_reference_module() - references: dict[int, ReferenceMetrics] = {} - candidates: dict[str, dict[int, CandidateMetrics]] = {lane: {} for lane in LANES} - optional_status: dict[str, object] = {} - report_path = run_root / "report.json" - execution_policy = dry_run_plan( - run_id=arguments.run_id, - python=arguments.python, - include_optional=arguments.include_optional, - ) - execution_policy["dry_run"] = False - - def partial(status: str) -> dict[str, object]: - payload: dict[str, object] = { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "dry_run": False, - "status": status, - "terminal": status != "running", - "source_identity": source_identity.provenance(), - "reference_source_identity": reference_source_identity.provenance(), - "policy": execution_policy, - "environment": { - "platform": sys.platform, - "threads": 1, - "cpu_policy": cpu_policy, - "sdk_target": sdk_info["target"], - "sdk_package_version": sdk_info["package_version"], - }, - "reference": { - str(total): _plain_reference(record) - for total, record in sorted(references.items()) - }, - "candidates": { - lane: { - str(total): _plain_candidate(record) - for total, record in sorted(records.items()) - } - for lane, records in candidates.items() - }, - "optional": optional_status, - } - return payload - - def require_numerical_parity(candidate: CandidateMetrics) -> None: - evidence = candidate.numerical_parity - if evidence.passes: - return - failed = partial("failed-numerical-parity") - failed.update( - { - "passes": False, - "failure": { - "kind": "numerical-parity", - "lane": candidate.lane, - "total_gluons": candidate.total_gluons, - "maximum_relative_error": evidence.maximum_relative_error, - "relative_tolerance": evidence.relative_tolerance, - }, - } - ) - _write_report(report_path, failed) - raise NumericalParityError( - "candidate/reference matrix-element mismatch for " - f"{candidate.lane} N={candidate.total_gluons} at point " - f"{evidence.maximum_relative_error_point}: relative error " - f"{evidence.maximum_relative_error:.17g} exceeds " - f"{evidence.relative_tolerance:.17g}" - ) - - completed_mandatory: list[int] = [] - for total_gluons in MANDATORY_MULTIPLICITIES: - reference = _run_reference( - reference=reference_module, - total_gluons=total_gluons, - run_root=run_root, - python=arguments.python, - environment=environment, - fc=arguments.fc, - target_seconds=arguments.target_seconds, - timeout_seconds=MANDATORY_LANE_TIMEOUT_SECONDS, - ) - references[total_gluons] = reference.metrics - for lane in LANES: - candidate = _run_candidate( - lane=lane, - total_gluons=total_gluons, - reference=reference, - probe=probe, - run_root=run_root, - python=arguments.python, - environment=environment, - target_seconds=arguments.target_seconds, - timeout_seconds=MANDATORY_LANE_TIMEOUT_SECONDS, - ) - candidates[lane][total_gluons] = candidate - require_numerical_parity(candidate) - completed_mandatory.append(total_gluons) - viability = _observed_mandatory_gate_viability( - references, - candidates, - multiplicities=completed_mandatory, - ) - if not viability["viable_lanes"]: - failed = partial("failed-performance-gates") - failed.update( - { - "passes": False, - "failure": { - "kind": "no-global-lane-remains", - "message": ( - "no eligible lane can satisfy every completed " - "mandatory warm-runtime, RSS, cold-to-ready, and " - "numerical gate" - ), - }, - "observed_gate_viability": viability, - } - ) - _write_report(report_path, failed) - return failed - running = partial("running") - running["observed_gate_viability"] = viability - _write_report(report_path, running) - - winner = select_global_lane(references, candidates) - mandatory_gates = evaluate_gates(winner, references, candidates) - optional_gates: tuple[GateResult, ...] = () - if arguments.include_optional: - optional_totals: list[int] = [] - for total_gluons in OPTIONAL_MULTIPLICITIES: - try: - reference = _run_reference( - reference=reference_module, - total_gluons=total_gluons, - run_root=run_root, - python=arguments.python, - environment=environment, - fc=arguments.fc, - target_seconds=arguments.target_seconds, - timeout_seconds=OPTIONAL_COLD_LIMIT_SECONDS, - ) - candidate = _run_candidate( - lane=winner, - total_gluons=total_gluons, - reference=reference, - probe=probe, - run_root=run_root, - python=arguments.python, - environment=environment, - target_seconds=arguments.target_seconds, - timeout_seconds=MANDATORY_LANE_TIMEOUT_SECONDS, - continuation_stage_limit_seconds=OPTIONAL_COLD_LIMIT_SECONDS, - ) - if not candidate.numerical_parity.passes: - references[total_gluons] = reference.metrics - candidates[winner][total_gluons] = candidate - optional_status[str(total_gluons)] = { - "status": "failed-numerical-parity" - } - require_numerical_parity(candidate) - if not optional_candidate_is_feasible(candidate): - optional_status[str(total_gluons)] = { - "status": "skipped", - "reason": "candidate exceeded the 15 minute or 30 GiB cap", - } - break - references[total_gluons] = reference.metrics - candidates[winner][total_gluons] = candidate - optional_totals.append(total_gluons) - optional_status[str(total_gluons)] = {"status": "measured"} - _write_report(report_path, partial("running")) - except NumericalParityError: - raise - except AcceptanceError as error: - optional_status[str(total_gluons)] = { - "status": "skipped", - "reason": str(error), - } - break - optional_gates = evaluate_gates( - winner, - references, - candidates, - multiplicities=optional_totals, - ) - - gates = (*mandatory_gates, *optional_gates) - final = partial("complete") - final.update( - { - "global_winning_lane": winner, - "lane_eligibility": lane_eligibility(candidates), - "optional": optional_status, - } - ) - final.update(_gate_report(gates)) - _write_report(report_path, final) - return final - - -def main(argv: Sequence[str] | None = None) -> int: - try: - arguments = _parser().parse_args(argv) - configure_reference_root(arguments.reference_fft_root) - _validate_arguments(arguments) - if arguments.dry_run: - print( - json.dumps( - dry_run_plan( - run_id=arguments.run_id, - python=arguments.python, - include_optional=arguments.include_optional, - ), - indent=2, - sort_keys=True, - ) - ) - return 0 - result = _campaign(arguments) - print(json.dumps(result, indent=2, sort_keys=True)) - return 0 if result["passes"] is True else 1 - except (AcceptanceError, OSError, ValueError) as error: - print(f"fft performance acceptance: {error}", file=sys.stderr) - return 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_madgraph_selected_runtime.py b/pyamplicol/tools/developer/fft_madgraph_selected_runtime.py deleted file mode 100755 index d9776acac2..0000000000 --- a/pyamplicol/tools/developer/fft_madgraph_selected_runtime.py +++ /dev/null @@ -1,3200 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Generate and benchmark MadGraph standalone FullColor processes. - -The campaign is deliberately process-by-process and resumable. For each -selected process family and final-state multiplicity ``n>=2`` it asks the -user's MadGraph installation to generate an ordinary, helicity-general -standalone process under configured per-cell wall-time and process-tree memory -guards. A generated check program then calls the -direct ``MATRIX(P,NHEL,IC)`` kernel at ten authenticated phase-space points -used by the pyAmpliCol campaign. The default workload is one fixed selected -helicity. ``--compare-helicity-sums`` instead calls the generated -``SMATRIX(P,ANS)`` with ``USERHEL=-1``. MadGraph owns the complete helicity -sum, its IDEN normalization, and the warmed ``GOODHEL`` pruning; summed runs -never reuse fixed-helicity measurements. - -The final-plot protocol measures MadGraph only through family-specific -multiplicity limits. Requested higher multiplicities are retained as explicit -not-applicable cells without loading their event data or invoking MadGraph. - -Each measured overlay cell contains cold-to-ready wall time, a conservative -peak RSS across generation/build/runtime, and the median of ten warm point-01 -CPU-time samples. A resource/time failure is the honest frontier for that -process family; higher multiplicities are recorded as skipped. Completed cells -are checkpointed before campaign-owned generated intermediates are pruned, so -interrupted campaigns resume cheaply. -""" - -from __future__ import annotations - -import argparse -import fcntl -import hashlib -import json -import math -import os -import platform -import re -import shutil -import signal -import statistics -import subprocess -import sys -import tempfile -import time -from collections import Counter -from collections.abc import Mapping, Sequence -from contextlib import suppress -from dataclasses import dataclass -from datetime import UTC, datetime -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -WATCHDOG = ROOT / "tools" / "ci" / "memory_watchdog.py" - -KIND = "pyamplicol-fullcolor-selected-scalar-runtime-series-overlay" -PROGRESS_KIND = "pyamplicol-fullcolor-selected-scalar-runtime-series-progress" -SOURCE_KIND = "pyamplicol-fullcolor-selected-scalar-composite" -SCALING_STUDY_KIND = "pyamplicol-fullcolor-fft-scaling-study" -SCHEMA_VERSION = 1 -MEASUREMENT_HOST_SCHEMA_VERSION = 1 -CHECKPOINT_PROTOCOL = { - "kind": "pyamplicol-selected-madgraph-runtime-cell", - "schema_version": 1, -} -LEGACY_CHECKPOINT_PRODUCER_KEY = "producer_sha256" -CHECKPOINT_RESOURCE_LIMIT_KEYS = frozenset( - {"generation_timeout_seconds", "memory_limit_gib"} -) -CHECKPOINT_TIMING_POLICY_KEYS = frozenset({"target_seconds", "warm_sample_count"}) -MEASUREMENT_HOST_KEYS = frozenset( - {"schema_version", "node_sha256", "system", "machine", "python"} -) -MODE = "madgraph-standalone" -FIXED_LABEL = "MadGraph standalone (fixed h)" -SUM_LABEL = "MadGraph standalone (helicity sum)" -LABEL = FIXED_LABEL -FAMILIES = ("gg", "ddbar") -FINAL_MULTIPLICITIES = tuple(range(2, 10)) -MAX_PROTOCOL_MEASURED_MULTIPLICITY = 6 -FAMILY_MAX_PROTOCOL_MEASURED_MULTIPLICITY = {"gg": 5, "ddbar": 6} -POINT_COUNT = 10 -WARM_SAMPLE_COUNT = 1 -TIMING_DRIVER_BATCH_COUNT = WARM_SAMPLE_COUNT + 1 -TARGET_SECONDS = 3.0 * 60.0 -RELATIVE_TOLERANCE = 1.0e-10 -MAX_GENERATION_SECONDS = 3600.0 -DEFAULT_GENERATION_TIMEOUT_SECONDS = 3595.0 -MAX_MEMORY_GIB = 30.0 -SOURCE_MODE = {"gg": "reference-fft", "ddbar": "recurrence-fft"} -SUM_SOURCE_MODE = {"gg": "recurrence-fft", "ddbar": "recurrence-fft"} -TIMEOUT_EXIT_CODE = 124 -TIMEOUT_MARKER = "madgraph-benchmark: bounded command reached its time limit" -CACHE_LOCK_ROOT = ( - Path(tempfile.gettempdir()) - / f"pyamplicol-{os.getuid()}" - / "madgraph-cache-locks" -) -RESOURCE_FRONTIER_CATEGORIES = frozenset( - { - "dependency-unavailable", - "generation-memory-limit", - "generation-time-limit", - "memory-limit", - "resource-unavailable", - "runtime-time-limit", - "structural-memory-limit", - "structural-unavailable", - } -) - - -class SelectedMadGraphError(RuntimeError): - """The selected-event MadGraph campaign could not be authenticated.""" - - -class ResourceFrontierError(SelectedMadGraphError): - """A measured resource limit establishes an honest availability frontier.""" - - def __init__(self, category: str, reason: str) -> None: - if category not in RESOURCE_FRONTIER_CATEGORIES: - raise ValueError(f"non-resource frontier category: {category}") - super().__init__(reason) - self.category = category - - -@dataclass(frozen=True, slots=True) -class EventData: - path: Path - sha256: str - final_gluons: int - strong_coupling: float - helicity: tuple[int, ...] - momenta: tuple[tuple[float, float, float, float], ...] - - -@dataclass(frozen=True, slots=True) -class SelectedCell: - family: str - n: int - total_external: int - process: str - helicity: tuple[int, ...] - events: tuple[EventData, ...] - reference_point_values: tuple[float, ...] - source_mode: str - helicity_workload: str - source_alpha_s: float - - -@dataclass(frozen=True, slots=True) -class SourceUnavailable: - reason: str - censors_higher_multiplicities: bool - - -@dataclass(frozen=True, slots=True) -class SourceSelection: - path: Path - sha256: str - alpha_s: float - cells: Mapping[str, Mapping[int, SelectedCell]] - unavailable: Mapping[str, Mapping[int, SourceUnavailable]] - helicity_workload: str - measurement_host: Mapping[str, Any] | None - - -@dataclass(frozen=True, slots=True) -class DriverResult: - total_external: int - initialization_seconds: float - first_pass_seconds: float - point_values: tuple[float, ...] - cell_seconds: tuple[tuple[float, ...], ...] - checksum: float - evaluations_per_sweep: int - helicity_coverage_count: int - - -def _workload_label(helicity_workload: str) -> str: - if helicity_workload == "fixed": - return FIXED_LABEL - if helicity_workload == "sum": - return SUM_LABEL - raise SelectedMadGraphError( - f"unsupported helicity workload {helicity_workload!r}" - ) - - -def source_mode(family: str, helicity_workload: str) -> str: - _workload_label(helicity_workload) - modes = SUM_SOURCE_MODE if helicity_workload == "sum" else SOURCE_MODE - try: - return modes[family] - except KeyError as error: - raise SelectedMadGraphError(f"unsupported family {family!r}") from error - - -def _declared_helicity_workload( - policy: Mapping[str, Any], *, legacy_default: str = "fixed" -) -> str: - measurement = _mapping( - policy.get("measurement", policy), context="helicity workload policy" - ) - declared = measurement.get("helicity_workload") - warm_sum = measurement.get("warm_helicity_sum") - warm_fixed = measurement.get("warm_fixed_helicity") - markers: set[str] = set() - if declared is not None: - markers.add(str(declared)) - if warm_sum is True: - markers.add("sum") - if warm_fixed is True: - markers.add("fixed") - if warm_sum is False and warm_fixed is False: - raise SelectedMadGraphError("helicity workload policy disables both workloads") - if len(markers) > 1 or any(value not in {"fixed", "sum"} for value in markers): - raise SelectedMadGraphError("helicity workload policy is contradictory") - return next(iter(markers), legacy_default) - - -def process_expression(family: str, n: int) -> str: - if family not in FAMILIES: - raise SelectedMadGraphError(f"unsupported process family {family!r}") - if isinstance(n, bool) or not isinstance(n, int) or n < 2: - raise SelectedMadGraphError(f"unsupported final-state multiplicity {n}") - extra = " ".join("g" for _ in range(n - 2)) - base = "g g > g g" if family == "gg" else "d d~ > d d~" - return base + (f" {extra}" if extra else "") - - -def protocol_measured_multiplicity_limit(family: str) -> int: - if family not in FAMILIES: - raise SelectedMadGraphError(f"unsupported process family {family!r}") - return FAMILY_MAX_PROTOCOL_MEASURED_MULTIPLICITY.get( - family, MAX_PROTOCOL_MEASURED_MULTIPLICITY - ) - - -def protocol_measures_multiplicity(family: str, n: int) -> bool: - if isinstance(n, bool) or not isinstance(n, int) or n < 2: - raise SelectedMadGraphError(f"unsupported final-state multiplicity {n}") - return n <= protocol_measured_multiplicity_limit(family) - - -def protocol_measured_multiplicity_limits() -> dict[str, int]: - return { - family: protocol_measured_multiplicity_limit(family) - for family in FAMILIES - } - - -def _mapping(value: object, *, context: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise SelectedMadGraphError(f"{context} must be an object") - return value - - -def validate_measurement_host(value: object, *, context: str) -> dict[str, Any]: - """Validate the stable, non-identifying host identity used by a campaign.""" - - host = _mapping(value, context=context) - if set(host) != MEASUREMENT_HOST_KEYS: - raise SelectedMadGraphError(f"{context} has the wrong fields") - schema_version = host.get("schema_version") - if ( - isinstance(schema_version, bool) - or schema_version != MEASUREMENT_HOST_SCHEMA_VERSION - ): - raise SelectedMadGraphError(f"{context} has the wrong schema") - for key in ("system", "machine", "python"): - if not isinstance(host.get(key), str) or not host[key].strip(): - raise SelectedMadGraphError(f"{context}.{key} must be nonempty") - node_sha256 = host.get("node_sha256") - if ( - not isinstance(node_sha256, str) - or re.fullmatch(r"[0-9a-f]{64}", node_sha256) is None - ): - raise SelectedMadGraphError( - f"{context}.node_sha256 must be a lowercase SHA-256" - ) - return { - "schema_version": MEASUREMENT_HOST_SCHEMA_VERSION, - "node_sha256": node_sha256, - "system": str(host["system"]), - "machine": str(host["machine"]), - "python": str(host["python"]), - } - - -def measurement_host_identity() -> dict[str, Any]: - """Return the identity that binds performance measurements to one host.""" - - node = platform.node().strip() - if not node: - raise SelectedMadGraphError("cannot determine the measurement host name") - return validate_measurement_host( - { - "schema_version": MEASUREMENT_HOST_SCHEMA_VERSION, - "node_sha256": hashlib.sha256(node.encode("utf-8")).hexdigest(), - "system": platform.system(), - "machine": platform.machine(), - "python": platform.python_version(), - }, - context="local measurement host", - ) - - -def _finite_number(value: object, *, context: str, nonnegative: bool = False) -> float: - if isinstance(value, bool) or not isinstance(value, int | float): - raise SelectedMadGraphError(f"{context} must be a finite number") - result = float(value) - if not math.isfinite(result) or (nonnegative and result < 0.0): - raise SelectedMadGraphError(f"{context} must be a finite number") - return result - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _display_path(path: Path) -> str: - resolved = path.expanduser().resolve(strict=False) - try: - return str(resolved.relative_to(ROOT)) - except ValueError: - return str(resolved) - - -def _event_path(raw_path: object, *, context: str) -> Path: - if not isinstance(raw_path, str) or not raw_path: - raise SelectedMadGraphError(f"{context} must be a nonempty path string") - path = Path(raw_path).expanduser() - if not path.is_absolute(): - path = ROOT / path - path = path.resolve(strict=False) - if not path.is_file() and "IMPLEMENTATION_DOCS" in path.parts: - marker = path.parts.index("IMPLEMENTATION_DOCS") - rebased = ROOT.joinpath(*path.parts[marker:]).resolve(strict=False) - if rebased.is_file(): - path = rebased - if not path.is_file(): - raise SelectedMadGraphError(f"selected event does not exist: {path}") - return path - - -def _single_block( - lines: Sequence[str], begin_marker: str, end_marker: str, *, path: Path -) -> list[str]: - if lines.count(begin_marker) != 1 or lines.count(end_marker) != 1: - raise SelectedMadGraphError( - f"{path} must contain one {begin_marker}/{end_marker} block" - ) - begin = lines.index(begin_marker) - end = lines.index(end_marker) - if end <= begin: - raise SelectedMadGraphError(f"{path} has a malformed {begin_marker} block") - return list(lines[begin + 1 : end]) - - -def _read_event( - path: Path, *, expected_n: int, default_strong_coupling: float = 1.0 -) -> EventData: - try: - raw = path.read_bytes() - lines = [ - line.strip() for line in raw.decode("utf-8").splitlines() if line.strip() - ] - except (OSError, UnicodeDecodeError) as error: - raise SelectedMadGraphError( - f"cannot read selected event {path}: {error}" - ) from error - if not lines or lines[0] not in { - "AMPLIGLUON_EVENT_V1", - "PYAMPLICOL_SCALING_EVENT_V1", - }: - raise SelectedMadGraphError(f"{path} has an unsupported event format") - - strong_coupling = default_strong_coupling - if lines[0] == "AMPLIGLUON_EVENT_V1": - final_rows = [ - line.split() for line in lines if line.startswith("FINAL_GLUONS ") - ] - coupling_rows = [ - line.split() for line in lines if line.startswith("STRONG_COUPLING ") - ] - if len(final_rows) != 1 or final_rows[0] != [ - "FINAL_GLUONS", - str(expected_n), - ]: - raise SelectedMadGraphError(f"{path} has the wrong FINAL_GLUONS") - if len(coupling_rows) != 1 or len(coupling_rows[0]) != 2: - raise SelectedMadGraphError(f"{path} has an invalid STRONG_COUPLING") - try: - strong_coupling = float(coupling_rows[0][1]) - except ValueError as error: - raise SelectedMadGraphError( - f"{path} has an invalid STRONG_COUPLING" - ) from error - if not math.isfinite(strong_coupling) or strong_coupling <= 0.0: - raise SelectedMadGraphError(f"{path} has an invalid STRONG_COUPLING") - - momentum_rows = _single_block(lines, "BEGIN_MOMENTA", "END_MOMENTA", path=path) - if len(momentum_rows) != expected_n + 2: - raise SelectedMadGraphError(f"{path} has the wrong number of momenta") - try: - momenta = tuple( - tuple(float(value) for value in row.split()) for row in momentum_rows - ) - except ValueError as error: - raise SelectedMadGraphError(f"{path} has invalid momentum values") from error - if any( - len(momentum) != 4 or any(not math.isfinite(value) for value in momentum) - for momentum in momenta - ): - raise SelectedMadGraphError(f"{path} has invalid momentum rows") - - count_rows = [line.split() for line in lines if line.startswith("NHELICITIES ")] - if len(count_rows) != 1 or count_rows[0] != ["NHELICITIES", "1"]: - raise SelectedMadGraphError(f"{path} must contain exactly one helicity") - helicity_rows = _single_block( - lines, "BEGIN_HELICITIES", "END_HELICITIES", path=path - ) - if len(helicity_rows) != 1: - raise SelectedMadGraphError(f"{path} must contain one helicity row") - try: - helicity = tuple(int(value) for value in helicity_rows[0].split()) - except ValueError as error: - raise SelectedMadGraphError(f"{path} has an invalid helicity row") from error - if len(helicity) != expected_n + 2 or any( - value not in (-1, 1) for value in helicity - ): - raise SelectedMadGraphError(f"{path} has an invalid helicity row") - return EventData( - path=path, - sha256=hashlib.sha256(raw).hexdigest(), - final_gluons=expected_n, - strong_coupling=strong_coupling, - helicity=helicity, - momenta=momenta, # type: ignore[arg-type] - ) - - -def load_source_selection( - path: Path, - *, - multiplicities: Sequence[int] | Mapping[str, Sequence[int]] = FINAL_MULTIPLICITIES, - families: Sequence[str] = FAMILIES, - helicity_workload: str = "fixed", -) -> SourceSelection: - _workload_label(helicity_workload) - if not families or any(family not in FAMILIES for family in families): - raise SelectedMadGraphError("source selection families are unsupported") - path = path.expanduser().resolve(strict=False) - try: - raw = path.read_bytes() - payload = json.loads(raw) - except (OSError, json.JSONDecodeError) as error: - raise SelectedMadGraphError( - f"cannot read source report {path}: {error}" - ) from error - if not isinstance(payload, dict) or payload.get("kind") not in { - SOURCE_KIND, - SCALING_STUDY_KIND, - }: - raise SelectedMadGraphError("source report has the wrong kind") - raw_measurement_host = payload.get("measurement_host") - measurement_host = ( - validate_measurement_host( - raw_measurement_host, context="source report measurement_host" - ) - if raw_measurement_host is not None - else None - ) - policy = _mapping(payload.get("policy"), context="source report policy") - observed_workload = _declared_helicity_workload(policy) - if observed_workload != helicity_workload: - raise SelectedMadGraphError( - "source report helicity workload differs from the requested " - f"MadGraph workload: {observed_workload!r} != {helicity_workload!r}" - ) - measurement = _mapping( - policy.get("measurement"), context="source report policy.measurement" - ) - alpha_s = _finite_number( - measurement.get("alpha_s"), - context="source report policy.measurement.alpha_s", - ) - if alpha_s <= 0.0: - raise SelectedMadGraphError("source report alpha_s must be positive") - default_strong_coupling = math.sqrt(4.0 * math.pi * alpha_s) - cells = _mapping(payload.get("cells"), context="source report cells") - selected: dict[str, dict[int, SelectedCell]] = {} - unavailable: dict[str, dict[int, SourceUnavailable]] = {} - selected_families = tuple(family for family in FAMILIES if family in set(families)) - for family in selected_families: - mode = source_mode(family, helicity_workload) - raw_family = _mapping( - cells.get(family), context=f"source report cells.{family}" - ) - raw_mode = _mapping( - raw_family.get(mode), context=f"source report cells.{family}.{mode}" - ) - selected[family] = {} - unavailable[family] = {} - family_multiplicities = ( - multiplicities.get(family, ()) - if isinstance(multiplicities, Mapping) - else multiplicities - ) - if isinstance(family_multiplicities, str): - raise SelectedMadGraphError( - "source selection multiplicities must be integer sequences" - ) - for n in family_multiplicities: - context = f"source report cells.{family}.{mode}.{n}" - cell = _mapping(raw_mode.get(str(n)), context=context) - expected_process = process_expression(family, n) - for key, expected in ( - ("family", family), - ("mode", mode), - ("n", n), - ("total_external", n + 2), - ("process", expected_process), - ): - if cell.get(key) != expected: - raise SelectedMadGraphError( - f"{context}.{key} has the wrong identity" - ) - if cell.get("status") != "measured": - if ( - cell.get("status") in {"failed", "skipped"} - and isinstance(cell.get("failure_reason"), str) - and cell["failure_reason"].strip() - ): - unavailable[family][n] = SourceUnavailable( - reason=str(cell["failure_reason"]), - censors_higher_multiplicities=( - cell.get("censors_higher_multiplicities") is True - ), - ) - continue - raise SelectedMadGraphError( - f"{context}.status is not a measured or unavailable cell" - ) - cell_workload = _declared_helicity_workload(cell) - if cell_workload != helicity_workload: - raise SelectedMadGraphError( - f"{context} helicity workload differs from the source policy" - ) - raw_helicity = cell.get("helicity") - if ( - not isinstance(raw_helicity, Sequence) - or isinstance(raw_helicity, str) - or len(raw_helicity) != n + 2 - or any( - isinstance(value, bool) - or not isinstance(value, int) - or value not in (-1, 1) - for value in raw_helicity - ) - ): - raise SelectedMadGraphError(f"{context}.helicity is invalid") - helicity = tuple(int(value) for value in raw_helicity) - raw_paths = cell.get("event_paths") - if not isinstance(raw_paths, Sequence) or isinstance(raw_paths, str): - raise SelectedMadGraphError(f"{context}.event_paths is invalid") - paths = tuple( - _event_path(value, context=f"{context}.event_paths") - for value in raw_paths - ) - if len(paths) != POINT_COUNT or len(set(paths)) != POINT_COUNT: - raise SelectedMadGraphError( - f"{context}.event_paths must contain ten unique paths" - ) - events = tuple( - _read_event( - event, - expected_n=n, - default_strong_coupling=default_strong_coupling, - ) - for event in paths - ) - if len({event.sha256 for event in events}) != POINT_COUNT: - raise SelectedMadGraphError( - f"{context}.event_paths must contain ten unique event payloads" - ) - if any(event.helicity != helicity for event in events): - raise SelectedMadGraphError(f"{context} event helicities differ") - raw_points = cell.get("point_values") - if not isinstance(raw_points, Sequence) or isinstance(raw_points, str): - raise SelectedMadGraphError(f"{context}.point_values is invalid") - points = tuple( - _finite_number( - value, context=f"{context}.point_values", nonnegative=True - ) - for value in raw_points - ) - if len(points) != POINT_COUNT or not any(value > 0.0 for value in points): - raise SelectedMadGraphError( - f"{context}.point_values must contain ten nonzero data" - ) - selected[family][n] = SelectedCell( - family=family, - n=n, - total_external=n + 2, - process=expected_process, - helicity=helicity, - events=events, - reference_point_values=points, - source_mode=mode, - helicity_workload=helicity_workload, - source_alpha_s=alpha_s, - ) - return SourceSelection( - path=path, - sha256=hashlib.sha256(raw).hexdigest(), - alpha_s=alpha_s, - cells=selected, - unavailable=unavailable, - helicity_workload=helicity_workload, - measurement_host=measurement_host, - ) - - -def parse_driver_output( - output: str, - *, - batches: int, - expected_total_external: int, - expected_events: int, - helicity_workload: str = "fixed", - expected_helicity_coverage_count: int | None = None, -) -> DriverResult: - _workload_label(helicity_workload) - scalar: dict[str, str] = {} - points: dict[int, float] = {} - cells: dict[tuple[int, int], float] = {} - allowed_scalars = { - "BACKEND", - "HELICITY_EVALUATOR", - "TOTAL_EXTERNAL", - "INITIALIZATION_SECONDS", - "FIRST_SAMPLE_PASS_SECONDS", - "EVALUATIONS_PER_SWEEP", - "HELICITY_COVERAGE_COUNT", - "CHECKSUM", - } - try: - for line in output.splitlines(): - fields = line.split() - if not fields: - continue - key = fields[0] - if key == "MATRIX_ELEMENT": - if len(fields) != 4 or fields[2] != "1": - raise SelectedMadGraphError("malformed MadGraph matrix-element row") - index = int(fields[1]) - if index in points: - raise SelectedMadGraphError("duplicate MadGraph matrix-element row") - points[index] = float(fields[3].replace("D", "E").replace("d", "e")) - elif key == "EVALUATION_CELL_SECONDS": - if len(fields) != 5 or fields[2:4] != ["1", "1"]: - raise SelectedMadGraphError("malformed MadGraph timing-cell row") - index = (int(fields[1]), 1) - if index in cells: - raise SelectedMadGraphError("duplicate MadGraph timing-cell row") - cells[index] = float(fields[4].replace("D", "E").replace("d", "e")) - elif key == "EVALUATION_SWEEP_SECONDS": - continue - elif key in allowed_scalars: - if len(fields) != 2 or key in scalar: - raise SelectedMadGraphError( - f"malformed or duplicate MadGraph {key}" - ) - scalar[key] = fields[1] - else: - raise SelectedMadGraphError(f"unexpected MadGraph output row: {line!r}") - except ValueError as error: - raise SelectedMadGraphError( - "invalid numeric value in MadGraph output" - ) from error - if set(scalar) != allowed_scalars: - raise SelectedMadGraphError("MadGraph output has incomplete scalar metadata") - expected_backend = ( - "MadGraph5_aMCatNLOFixedHelicity" - if helicity_workload == "fixed" - else "MadGraph5_aMCatNLOHelicitySum" - ) - expected_evaluator = ( - "MATRIX_DIRECT_VECTOR" - if helicity_workload == "fixed" - else "SMATRIX_GENERATED_COMPLETE_HELICITY_SUM" - ) - if scalar["BACKEND"] != expected_backend: - raise SelectedMadGraphError("unexpected MadGraph backend identity") - if scalar["HELICITY_EVALUATOR"] != expected_evaluator: - raise SelectedMadGraphError( - "MadGraph used the wrong workload-specific evaluator" - ) - total_external = int(scalar["TOTAL_EXTERNAL"]) - initialization = float(scalar["INITIALIZATION_SECONDS"].replace("D", "E")) - first_pass = float(scalar["FIRST_SAMPLE_PASS_SECONDS"].replace("D", "E")) - checksum = float(scalar["CHECKSUM"].replace("D", "E")) - expected_evaluations = 1 - if helicity_workload == "sum": - if ( - isinstance(expected_helicity_coverage_count, bool) - or not isinstance(expected_helicity_coverage_count, int) - or expected_helicity_coverage_count < 1 - ): - raise SelectedMadGraphError( - "summed output validation requires generated NCOMB coverage" - ) - expected_coverage = expected_helicity_coverage_count - else: - expected_coverage = 1 - evaluations_per_sweep = int(scalar["EVALUATIONS_PER_SWEEP"]) - helicity_coverage_count = int(scalar["HELICITY_COVERAGE_COUNT"]) - if ( - total_external != expected_total_external - or evaluations_per_sweep != expected_evaluations - or helicity_coverage_count != expected_coverage - ): - raise SelectedMadGraphError("MadGraph output has the wrong process dimensions") - if set(points) != set(range(1, expected_events + 1)): - raise SelectedMadGraphError( - "MadGraph output did not report every validation point" - ) - if set(cells) != {(batch, 1) for batch in range(1, batches + 1)}: - raise SelectedMadGraphError("MadGraph output has incomplete timing cells") - values = (initialization, first_pass, checksum, *points.values(), *cells.values()) - if any(not math.isfinite(value) or value < 0.0 for value in values): - raise SelectedMadGraphError("MadGraph output contains invalid numeric data") - if checksum <= 0.0: - raise SelectedMadGraphError("MadGraph checksum must be positive") - return DriverResult( - total_external=total_external, - initialization_seconds=initialization, - first_pass_seconds=first_pass, - point_values=tuple(points[index] for index in range(1, expected_events + 1)), - cell_seconds=tuple((cells[(batch, 1)],) for batch in range(1, batches + 1)), - checksum=checksum, - evaluations_per_sweep=evaluations_per_sweep, - helicity_coverage_count=helicity_coverage_count, - ) - - -def _fortran_double(value: float) -> str: - return format(value, ".17e").replace("e", "D") - - -def render_check_source( - selected: SelectedCell, - *, - summed_helicity_coverage_count: int | None = None, - target_seconds: float = TARGET_SECONDS, - warm_sample_count: int = WARM_SAMPLE_COUNT, -) -> str: - """Render a check driver; the generated MATRIX remains helicity-general.""" - - n_external = selected.total_external - summed = selected.helicity_workload == "sum" - _workload_label(selected.helicity_workload) - backend_identity = ( - "MadGraph5_aMCatNLOHelicitySum" - if summed - else "MadGraph5_aMCatNLOFixedHelicity" - ) - evaluator_identity = ( - "SMATRIX_GENERATED_COMPLETE_HELICITY_SUM" - if summed - else "MATRIX_DIRECT_VECTOR" - ) - if summed: - if ( - isinstance(summed_helicity_coverage_count, bool) - or not isinstance(summed_helicity_coverage_count, int) - or summed_helicity_coverage_count < 1 - ): - raise SelectedMadGraphError( - "summed driver requires generated NCOMB helicity coverage" - ) - helicity_coverage_count = summed_helicity_coverage_count - else: - helicity_coverage_count = 1 - if ( - isinstance(target_seconds, bool) - or not math.isfinite(target_seconds) - or target_seconds <= 0.0 - ): - raise SelectedMadGraphError("target_seconds must be positive and finite") - if ( - isinstance(warm_sample_count, bool) - or not isinstance(warm_sample_count, int) - or warm_sample_count < 1 - ): - raise SelectedMadGraphError("warm_sample_count must be positive") - timing_driver_batch_count = warm_sample_count + 1 - lines = [ - " PROGRAM DRIVER", - " IMPLICIT NONE", - " INTEGER NEXTERNAL,NEVENTS,NSAMPLES", - f" PARAMETER (NEXTERNAL={n_external},NEVENTS={POINT_COUNT})", - f" PARAMETER (NSAMPLES={timing_driver_batch_count})", - " INTEGER E,B,R,NREP,CLOCK0,CLOCK1,CLOCKRATE", - " INTEGER HEL(NEXTERNAL),IC(NEXTERNAL)", - " DOUBLE PRECISION P(0:3,NEXTERNAL,NEVENTS)", - ( - " DOUBLE PRECISION V(NEVENTS),VALUE,BEFORE,AFTER" - if summed - else " DOUBLE PRECISION V(NEVENTS),MATRIX,BEFORE,AFTER" - ), - " DOUBLE PRECISION TARGET,ELAPSED,CHECKSUM,FIRST0,FIRST1", - " DOUBLE PRECISION PI,ASVALUE", - " PARAMETER (PI=3.141592653589793D0)", - ] - if summed: - lines.extend( - [ - " INTEGER USERHEL", - " COMMON/HELUSERCHOICE/USERHEL", - ] - ) - else: - lines.append(" EXTERNAL MATRIX") - lines.extend( - [ - f" DATA HEL /{','.join(str(value) for value in selected.helicity)}/", - f" DATA IC /{n_external}*1/", - ] - ) - for event_index, event in enumerate(selected.events, start=1): - for leg_index, momentum in enumerate(event.momenta, start=1): - for component, value in enumerate(momentum): - lines.append( - f" P({component},{leg_index},{event_index})=" - f"{_fortran_double(value)}" - ) - if summed: - as_value = _fortran_double(selected.source_alpha_s) - else: - coupling = selected.events[0].strong_coupling - if any( - not math.isclose( - event.strong_coupling, coupling, rel_tol=1.0e-14, abs_tol=0.0 - ) - for event in selected.events[1:] - ): - raise SelectedMadGraphError( - "selected events use different strong couplings" - ) - as_value = f"{_fortran_double(coupling * coupling)}/(4D0*PI)" - validation_evaluation = ( - " CALL SMATRIX(P(0,1,E),V(E))" - if summed - else " V(E)=MATRIX(P(0,1,E),HEL,IC)" - ) - timed_evaluation = ( - ( - " CALL SMATRIX(P(0,1,1),VALUE)", - " CHECKSUM=CHECKSUM+VALUE", - ) - if summed - else (" CHECKSUM=CHECKSUM+MATRIX(P(0,1,1),HEL,IC)",) - ) - repeated_evaluation = tuple(f" {line}" for line in timed_evaluation) - lines.extend( - [ - f" TARGET={_fortran_double(target_seconds)}", - f" ASVALUE={as_value}", - *((" USERHEL=-1",) if summed else ()), - " CALL SYSTEM_CLOCK(CLOCK0,CLOCKRATE)", - " CALL SETPARA('../../Cards/param_card.dat')", - " CALL UPDATE_AS_PARAM2(1D0,ASVALUE)", - " CALL SYSTEM_CLOCK(CLOCK1)", - " WRITE(*,'(A,1X,A)') 'BACKEND',", - f" $ '{backend_identity}'", - " WRITE(*,'(A,1X,A)') 'HELICITY_EVALUATOR',", - f" $ '{evaluator_identity}'", - " WRITE(*,'(A,1X,I0)') 'TOTAL_EXTERNAL',NEXTERNAL", - " WRITE(*,'(A,1X,ES24.16)') 'INITIALIZATION_SECONDS',", - " $ DBLE(CLOCK1-CLOCK0)/DBLE(CLOCKRATE)", - " CALL CPU_TIME(FIRST0)", - " DO E=1,NEVENTS", - validation_evaluation, - " ENDDO", - " CALL CPU_TIME(FIRST1)", - " WRITE(*,'(A,1X,ES24.16)') 'FIRST_SAMPLE_PASS_SECONDS',", - " $ FIRST1-FIRST0", - " DO E=1,NEVENTS", - " WRITE(*,'(A,2(1X,I0),1X,ES24.16)')", - " $ 'MATRIX_ELEMENT',E,1,V(E)", - " ENDDO", - " WRITE(*,'(A,1X,I0)') 'EVALUATIONS_PER_SWEEP',", - " $ 1", - " WRITE(*,'(A,1X,I0)') 'HELICITY_COVERAGE_COUNT',", - f" $ {helicity_coverage_count}", - " NREP=1", - " CHECKSUM=0D0", - " 10 CONTINUE", - " CALL CPU_TIME(BEFORE)", - " DO R=1,NREP", - *timed_evaluation, - " ENDDO", - " CALL CPU_TIME(AFTER)", - " ELAPSED=AFTER-BEFORE", - " IF (ELAPSED.LT.TARGET) THEN", - " IF (NREP.GT.1000000000) STOP 91", - " NREP=2*NREP", - " GOTO 10", - " ENDIF", - " WRITE(*,'(A,1X,I0,1X,ES24.16)')", - " $ 'EVALUATION_SWEEP_SECONDS',1,ELAPSED/DBLE(NREP)", - " WRITE(*,'(A,3(1X,I0),1X,ES24.16)')", - " $ 'EVALUATION_CELL_SECONDS',1,1,1,ELAPSED/DBLE(NREP)", - " DO B=2,NSAMPLES", - " CHECKSUM=0D0", - " CALL CPU_TIME(BEFORE)", - " DO R=1,NREP", - *repeated_evaluation, - " ENDDO", - " CALL CPU_TIME(AFTER)", - " ELAPSED=(AFTER-BEFORE)/DBLE(NREP)", - " WRITE(*,'(A,1X,I0,1X,ES24.16)')", - " $ 'EVALUATION_SWEEP_SECONDS',B,ELAPSED", - " WRITE(*,'(A,3(1X,I0),1X,ES24.16)')", - " $ 'EVALUATION_CELL_SECONDS',B,1,1,ELAPSED", - " ENDDO", - " WRITE(*,'(A,1X,ES24.16)') 'CHECKSUM',CHECKSUM", - " END", - ] - ) - if any(len(line) > 132 for line in lines): - raise SelectedMadGraphError( - "generated fixed-form check source exceeds 132 columns" - ) - body = "\n".join(lines) + "\n" - if summed: - if body.count("CALL SMATRIX(") != 3 or re.search( - r"(? None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_suffix(path.suffix + f".{os.getpid()}.tmp") - serialized = json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n" - temporary.write_text(serialized, encoding="utf-8") - if not replace and path.exists(): - temporary.unlink() - raise SelectedMadGraphError(f"refusing to replace {path}") - temporary.replace(path) - - -def _cache_lock_path(cache_dir: Path) -> Path: - resolved = cache_dir.expanduser().resolve(strict=False) - digest = hashlib.sha256(os.fsencode(resolved)).hexdigest() - return CACHE_LOCK_ROOT / f"{digest}.lock" - - -def _acquire_cache_lock(cache_dir: Path) -> Any: - """Reject overlapping writers even if the cache tree is replaced.""" - - path = _cache_lock_path(cache_dir) - path.parent.mkdir(parents=True, exist_ok=True) - handle = path.open("a+b") - try: - fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError as error: - handle.close() - raise SelectedMadGraphError( - f"another MadGraph profiler holds cache lock {path}" - ) from error - return handle - - -def _terminate_process(process: subprocess.Popen[Any]) -> None: - if process.poll() is not None: - return - try: - os.killpg(process.pid, signal.SIGTERM) - except ProcessLookupError: - return - try: - process.wait(timeout=5.0) - except subprocess.TimeoutExpired: - with suppress(ProcessLookupError): - os.killpg(process.pid, signal.SIGKILL) - process.wait() - - -def _python_script_command(script: Path, *arguments: str) -> list[str]: - return [str(sys.executable), str(script), *arguments] - - -def _generation_worker(arguments: argparse.Namespace) -> int: - output = arguments.generated_output.resolve(strict=False) - result_path = arguments.worker_result.resolve(strict=False) - cell_root = result_path.parent.parent.parent.resolve(strict=False) - if output.parent != cell_root: - raise SelectedMadGraphError( - "generation output is outside its dedicated cell directory" - ) - if output.exists(): - shutil.rmtree(output) - disk_free_before = shutil.disk_usage(cell_root).free - card = result_path.parent / "generate.mg5" - card.write_text( - "\n".join( - ( - "set automatic_html_opening False", - "import model sm-default", - f"generate {arguments.process} QED=0", - f"output standalone {output} -f", - "", - ) - ), - encoding="utf-8", - ) - stdout_path = result_path.parent / "mg5.stdout.log" - stderr_path = result_path.parent / "mg5.stderr.log" - started = time.monotonic() - timed_out = False - returncode: int | None = None - error_text: str | None = None - with stdout_path.open("wb") as stdout, stderr_path.open("wb") as stderr: - try: - process = subprocess.Popen( - _python_script_command( - arguments.mg5_root / "bin" / "mg5_aMC", str(card) - ), - cwd=arguments.mg5_root, - stdout=stdout, - stderr=stderr, - start_new_session=True, - ) - try: - returncode = process.wait(timeout=arguments.generation_timeout_seconds) - except subprocess.TimeoutExpired: - timed_out = True - _terminate_process(process) - returncode = process.returncode - except OSError as error: - error_text = str(error) - elapsed = time.monotonic() - started - process_dirs = sorted( - str(path) - for path in (output / "SubProcesses").glob("P*") - if (path / "matrix.f").is_file() - ) - status = "measured" if returncode == 0 and len(process_dirs) == 1 else "failed" - reason = None - category = None - if timed_out: - category = "generation-time-limit" - reason = ( - "MadGraph generation exceeded " - f"{arguments.generation_timeout_seconds:g} seconds" - ) - elif error_text is not None: - category = "generation-launch-error" - reason = error_text - elif returncode != 0: - log_tail = "" - with suppress(OSError): - log_tail = ( - stdout_path.read_text(encoding="utf-8", errors="replace")[-4000:] - + stderr_path.read_text(encoding="utf-8", errors="replace")[-4000:] - ) - if "No space left on device" in log_tail: - category = "infrastructure-disk-exhaustion" - reason = "campaign filesystem ran out of space during MadGraph generation" - else: - category = "generation-error" - reason = f"MadGraph exited with status {returncode}" - elif len(process_dirs) != 1: - category = "generation-structure-error" - reason = f"expected one standalone subprocess, found {len(process_dirs)}" - _json_atomic( - result_path, - { - "status": status, - "failure_category": category, - "failure_reason": reason, - "elapsed_wall_seconds": elapsed, - "returncode": returncode, - "timed_out": timed_out, - "process": arguments.process, - "output": str(output), - "process_dirs": process_dirs, - "card": str(card), - "stdout": str(stdout_path), - "stderr": str(stderr_path), - "disk_free_bytes_before": disk_free_before, - "disk_free_bytes_after": shutil.disk_usage(cell_root).free, - }, - ) - return 0 - - -def _timeout_worker(arguments: argparse.Namespace) -> int: - if not math.isfinite(arguments.timeout_seconds) or arguments.timeout_seconds <= 0.0: - raise SelectedMadGraphError("timeout must be a positive finite number") - command = list(arguments.command) - if command and command[0] == "--": - command.pop(0) - if not command: - raise SelectedMadGraphError("timeout worker requires a command") - try: - process = subprocess.Popen(command, start_new_session=True) - except OSError as error: - raise SelectedMadGraphError( - f"bounded command could not start: {error}" - ) from error - try: - return process.wait(timeout=arguments.timeout_seconds) - except subprocess.TimeoutExpired: - _terminate_process(process) - print(TIMEOUT_MARKER, file=sys.stderr, flush=True) - return TIMEOUT_EXIT_CODE - - -def _run_watchdog( - command: Sequence[str], *, cwd: Path, report: Path, limit_gib: float -) -> subprocess.CompletedProcess[str]: - if report.exists(): - raise SelectedMadGraphError(f"watchdog report already exists: {report}") - return subprocess.run( - [ - str(sys.executable), - str(WATCHDOG), - "--limit-gib", - format(limit_gib, ".17g"), - "--report-json", - str(report), - "--", - *command, - ], - cwd=cwd, - text=True, - capture_output=True, - check=False, - env={**os.environ, "LC_ALL": "C"}, - ) - - -def _read_json(path: Path, *, context: str) -> Mapping[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise SelectedMadGraphError(f"cannot read {context} {path}: {error}") from error - return _mapping(value, context=context) - - -def _new_attempt_directory(cell_dir: Path, stage: str) -> Path: - if stage not in {"generation", "measurement"}: - raise SelectedMadGraphError(f"unsupported attempt stage {stage!r}") - attempts = cell_dir / f"{stage}-attempts" - attempts.mkdir(parents=True, exist_ok=True) - indices = [ - int(match.group(1)) - for path in attempts.iterdir() - if path.is_dir() - and (match := re.fullmatch(r"attempt-(\d+)", path.name)) is not None - ] - index = max(indices, default=0) + 1 - while True: - attempt = attempts / f"attempt-{index:03d}" - try: - attempt.mkdir() - except FileExistsError: - index += 1 - continue - return attempt - - -def _prune_cell_generated(cell_dir: Path) -> bool: - cell_root = cell_dir.resolve(strict=True) - generated = cell_root / "generated" - if not os.path.lexists(generated): - return False - if generated.is_symlink(): - raise SelectedMadGraphError( - f"refusing generated-output symlink during cleanup: {generated}" - ) - target = generated.resolve(strict=True) - if target != generated or target.parent != cell_root or target.name != "generated": - raise SelectedMadGraphError( - f"refusing unexpected generated-output cleanup target: {target}" - ) - if not target.is_dir(): - raise SelectedMadGraphError( - f"generated-output cleanup target is not a directory: {target}" - ) - try: - shutil.rmtree(target) - except OSError as error: - raise SelectedMadGraphError( - f"cannot prune campaign-owned generated output {target}: {error}" - ) from error - return True - - -def _load_checkpoint_cell( - checkpoint: Path, - *, - identity: Mapping[str, Any], - cell_dir: Path, - keep_generated: bool, -) -> dict[str, Any] | None: - saved = _read_json(checkpoint, context="MadGraph cell checkpoint") - saved_identity = saved.get("checkpoint_identity") - cell = dict(_mapping(saved.get("cell"), context="checkpoint.cell")) - status = cell.get("status") - if status == "failed": - category = str(cell.get("failure_category")) - if category not in RESOURCE_FRONTIER_CATEGORIES: - raise SelectedMadGraphError( - f"checkpoint contains a non-resource failed frontier: {category}" - ) - elif status != "measured": - raise SelectedMadGraphError( - f"checkpoint contains unsupported cell status {status!r}" - ) - identity_matches = saved_identity == identity - if not identity_matches and isinstance(saved_identity, Mapping): - compatible, expected = _checkpoint_identity_comparison( - saved_identity, identity, cell_status=str(status) - ) - if compatible != expected and status == "failed": - reusable_failure = dict(compatible) - requested_failure = dict(expected) - resource_limit_changed = any( - reusable_failure.get(key) != requested_failure.get(key) - for key in CHECKPOINT_RESOURCE_LIMIT_KEYS - ) - timing_policy_changed = any( - reusable_failure.get(key) != requested_failure.get(key) - for key in CHECKPOINT_TIMING_POLICY_KEYS - ) - for key in CHECKPOINT_RESOURCE_LIMIT_KEYS | CHECKPOINT_TIMING_POLICY_KEYS: - reusable_failure.pop(key, None) - requested_failure.pop(key, None) - if ( - (resource_limit_changed or timing_policy_changed) - and reusable_failure == requested_failure - ): - if not keep_generated: - _prune_cell_generated(cell_dir) - return None - identity_matches = compatible == expected - if not identity_matches: - raise SelectedMadGraphError( - f"checkpoint identity changed at {cell_dir.parent.name}/{cell_dir.name}; " - "use a fresh cache directory" - ) - if not keep_generated: - _prune_cell_generated(cell_dir) - return cell - - -def _checkpoint_identity_comparison( - saved_identity: Mapping[str, Any], - identity: Mapping[str, Any], - *, - cell_status: str, -) -> tuple[dict[str, Any], dict[str, Any]]: - compatible = dict(saved_identity) - expected = dict(identity) - same_source_cell = compatible.get("source_cell_sha256") == expected.get( - "source_cell_sha256" - ) and isinstance(compatible.get("source_cell_sha256"), str) - if not same_source_cell: - return compatible, expected - # Expanding a sparse source report does not change this cell's inputs. - compatible.pop("source_report_sha256", None) - expected.pop("source_report_sha256", None) - if ( - LEGACY_CHECKPOINT_PRODUCER_KEY in compatible - and "checkpoint_protocol" in expected - and "checkpoint_protocol" not in compatible - ): - compatible.pop(LEGACY_CHECKPOINT_PRODUCER_KEY, None) - expected.pop("checkpoint_protocol", None) - if cell_status == "measured": - # Successful timings remain usable if only retry caps or the sampling - # target changed; new/retried cells record the current policy. - for key in CHECKPOINT_RESOURCE_LIMIT_KEYS | CHECKPOINT_TIMING_POLICY_KEYS: - compatible.pop(key, None) - expected.pop(key, None) - return compatible, expected - - -def _generation_attempt( - *, - selected: SelectedCell, - cell_dir: Path, - mg5_root: Path, - timeout: float, - limit_gib: float, -) -> tuple[Mapping[str, Any], Mapping[str, Any]]: - attempt = _new_attempt_directory(cell_dir, "generation") - worker_result = attempt / "result.json" - watchdog_report = attempt / "watchdog.json" - command = [ - *_python_script_command(Path(__file__).resolve()), - "_generate-cell", - "--mg5-root", - str(mg5_root), - "--generated-output", - str(cell_dir / "generated"), - "--worker-result", - str(worker_result), - "--process", - selected.process, - "--generation-timeout-seconds", - format(timeout, ".17g"), - ] - completed = _run_watchdog( - command, cwd=ROOT, report=watchdog_report, limit_gib=limit_gib - ) - watchdog = _read_json(watchdog_report, context="generation watchdog") - if worker_result.is_file(): - generation = _read_json(worker_result, context="generation worker result") - else: - enforcement = _mapping( - watchdog.get("enforcement"), context="watchdog.enforcement" - ) - execution = _mapping(watchdog.get("execution"), context="watchdog.execution") - generation = { - "status": "failed", - "failure_category": ( - "infrastructure-disk-exhaustion" - if _is_disk_exhaustion(completed.stderr) - else ( - "generation-memory-limit" - if execution.get("outcome") == "memory-limit-exceeded" - else "generation-watchdog-error" - ) - ), - "failure_reason": ( - "campaign filesystem ran out of space during MadGraph generation" - if _is_disk_exhaustion(completed.stderr) - else ( - "MadGraph generation reached the " - f"{limit_gib:g}-GiB process-tree memory limit" - if execution.get("outcome") == "memory-limit-exceeded" - else f"generation watchdog failed: {execution.get('outcome')}" - ) - ), - "elapsed_wall_seconds": execution.get("elapsed_wall_seconds"), - "returncode": completed.returncode, - "process_dirs": [], - "output": str(cell_dir / "generated"), - "watchdog_peak_guard_bytes": enforcement.get("peak_guard_bytes"), - } - return generation, watchdog - - -def _extract_integer(source: str, name: str) -> int: - match = re.search(rf"\b{name}\s*=\s*(\d+)\b", source, re.IGNORECASE) - if match is None or int(match.group(1)) < 1: - raise SelectedMadGraphError(f"generated MATRIX source lacks positive {name}") - return int(match.group(1)) - - -def _expected_smatrix_iden(family: str, final_multiplicity: int) -> int: - if family == "gg": - return 256 * math.factorial(final_multiplicity) - if family == "ddbar": - return 36 * math.factorial(final_multiplicity - 2) - raise SelectedMadGraphError(f"unsupported family {family!r}") - - -def _validate_matrix_source( - path: Path, - *, - family: str, - final_multiplicity: int, -) -> dict[str, Any]: - expected_external = final_multiplicity + 2 - text = path.read_text(encoding="utf-8", errors="strict") - match = re.search(r"(?ims)^\s*REAL\*8 FUNCTION MATRIX\b(.*?)(?=^\s*END\s*$)", text) - if match is None: - raise SelectedMadGraphError("generated source has no direct MATRIX function") - body = match.group(1) - if re.search(r"\bSMATRIX(?:HEL)?\b|\bIHEL\b|\bNCOMB\b", body, re.IGNORECASE): - raise SelectedMadGraphError("generated MATRIX is not a direct-helicity kernel") - if not re.search(r"INTEGER\s+NHEL\s*\(\s*NEXTERNAL\s*\)", body, re.IGNORECASE): - raise SelectedMadGraphError("generated MATRIX lacks its NHEL vector") - n_external = _extract_integer(text, "NEXTERNAL") - if n_external != expected_external: - raise SelectedMadGraphError( - "generated MATRIX has the wrong external multiplicity" - ) - smatrix = re.search(r"(?ims)^\s*SUBROUTINE SMATRIX\b(.*?)(?=^\s*END\s*$)", text) - if smatrix is None: - raise SelectedMadGraphError( - "generated standalone source is not helicity-general" - ) - smatrix_body = smatrix.group(1) - ncomb = _extract_integer(smatrix_body, "NCOMB") - expected_ncomb = 2**expected_external - if ncomb != expected_ncomb: - raise SelectedMadGraphError( - "generated SMATRIX has the wrong complete-helicity coverage: " - f"expected NCOMB={expected_ncomb}, observed {ncomb}" - ) - if re.search( - r"INTEGER\s+NHEL\s*\(\s*NEXTERNAL\s*,\s*NCOMB\s*\)", - smatrix_body, - re.IGNORECASE, - ) is None: - raise SelectedMadGraphError( - "generated SMATRIX lacks its NHEL(NEXTERNAL,NCOMB) table" - ) - iden_matches = re.findall( - r"^[ \t]{6,}DATA[ \t]+IDEN[ \t]*/[ \t]*(\d+)[ \t]*/[ \t]*$", - smatrix.group(1), - re.IGNORECASE | re.MULTILINE, - ) - if len(iden_matches) != 1 or int(iden_matches[0]) < 1: - raise SelectedMadGraphError( - "generated SMATRIX lacks one positive IDEN denominator" - ) - iden_uses = re.findall( - r"^[ \t]{6,}ANS[ \t]*=[ \t]*ANS[ \t]*/[ \t]*" - r"DBLE[ \t]*\([ \t]*IDEN[ \t]*\)[ \t]*$", - smatrix.group(1), - re.IGNORECASE | re.MULTILINE, - ) - if len(iden_uses) != 1: - raise SelectedMadGraphError( - "generated SMATRIX does not apply its IDEN denominator exactly once" - ) - smatrix_iden = int(iden_matches[0]) - expected_iden = _expected_smatrix_iden(family, final_multiplicity) - if smatrix_iden != expected_iden: - raise SelectedMadGraphError( - "generated SMATRIX has the wrong IDEN denominator: " - f"expected {expected_iden}, observed {smatrix_iden}" - ) - return { - "matrix_sha256": hashlib.sha256(text.encode("utf-8")).hexdigest(), - "generated_matrix_graphs": _extract_integer(body, "NGRAPHS"), - "colour_flows": _extract_integer(body, "NCOLOR"), - "smatrix_iden": smatrix_iden, - "generation_helicity_coverage": "all", - "generated_helicity_coverage_count": ncomb, - } - - -def _parse_time_max_rss(stderr: str) -> int | None: - system = platform.system() - if system == "Darwin": - matches = re.findall( - r"^\s*(\d+)\s+maximum resident set size\s*$", stderr, re.MULTILINE - ) - if len(matches) != 1: - return None - return math.ceil(int(matches[0]) / 1024) - if system == "Linux": - matches = re.findall( - r"^\s*Maximum resident set size \(kbytes\):\s*(\d+)\s*$", - stderr, - re.MULTILINE, - ) - if len(matches) != 1: - return None - return int(matches[0]) - return None - - -def _external_time_command(command: Sequence[str]) -> list[str]: - """Add the host's external time utility when its dialect is known.""" - - system = platform.system() - if system == "Darwin": - time_path = Path("/usr/bin/time") - prefix = [str(time_path), "-l"] if time_path.is_file() else [] - elif system == "Linux": - located = shutil.which("time") - prefix = [located, "-v"] if located is not None else [] - else: - prefix = [] - return [*prefix, *command] - - -def _watchdog_resource(report: Mapping[str, Any]) -> dict[str, Any]: - enforcement = _mapping(report.get("enforcement"), context="watchdog.enforcement") - execution = _mapping(report.get("execution"), context="watchdog.execution") - peak_guard = int(enforcement.get("peak_guard_bytes", 0)) - return { - "elapsed_wall_seconds": _finite_number( - execution.get("elapsed_wall_seconds"), - context="watchdog elapsed", - nonnegative=True, - ), - "peak_guard_bytes": peak_guard, - "peak_guard_kib": math.ceil(peak_guard / 1024), - "peak_rss_bytes": int(enforcement.get("peak_rss_bytes", 0)), - "peak_physical_footprint_bytes": enforcement.get( - "peak_physical_footprint_bytes" - ), - "metric": enforcement.get("metric"), - "limit_bytes": enforcement.get("limit_bytes"), - "outcome": execution.get("outcome"), - "passes": report.get("passes") is True, - } - - -def _run_bounded_command( - command: Sequence[str], - *, - cwd: Path, - report: Path, - limit_gib: float, - timeout_seconds: float | None = None, -) -> tuple[subprocess.CompletedProcess[str], Mapping[str, Any]]: - bounded = list(command) - if timeout_seconds is not None: - if not math.isfinite(timeout_seconds) or timeout_seconds <= 0.0: - raise SelectedMadGraphError("cold-to-ready time budget is exhausted") - bounded = [ - *_python_script_command(Path(__file__).resolve()), - "_run-with-timeout", - "--timeout-seconds", - format(timeout_seconds, ".17g"), - "--", - *bounded, - ] - completed = _run_watchdog( - _external_time_command(bounded), - cwd=cwd, - report=report, - limit_gib=limit_gib, - ) - report.with_name(f"{report.stem}.stdout.log").write_text( - completed.stdout, encoding="utf-8" - ) - report.with_name(f"{report.stem}.stderr.log").write_text( - completed.stderr, encoding="utf-8" - ) - return completed, _read_json(report, context="bounded command watchdog") - - -def _bounded_command_timed_out( - completed: subprocess.CompletedProcess[str], -) -> bool: - return ( - completed.returncode == TIMEOUT_EXIT_CODE and TIMEOUT_MARKER in completed.stderr - ) - - -def _remaining_cold_to_ready_budget( - limit_seconds: float, *resources: Mapping[str, Any] -) -> float: - used = sum(float(resource["elapsed_wall_seconds"]) for resource in resources) - remaining = limit_seconds - used - if not math.isfinite(remaining) or remaining <= 0.0: - raise ResourceFrontierError( - "generation-time-limit", - "cold-to-ready generation reached the strict time limit", - ) - return remaining - - -def _relative_error(observed: float, reference: float) -> float: - if observed == reference: - return 0.0 - return abs(observed - reference) / max(abs(observed), abs(reference), 1.0e-300) - - -def _numerical_normalization_factor( - family: str, *, smatrix_iden: int, helicity_workload: str = "fixed" -) -> float: - if family not in FAMILIES: - raise SelectedMadGraphError(f"unsupported family {family!r}") - if smatrix_iden < 1: - raise SelectedMadGraphError("SMATRIX IDEN denominator must be positive") - _workload_label(helicity_workload) - if helicity_workload == "sum": - return 1.0 - return 1.0 if family == "gg" else 1.0 / float(smatrix_iden) - - -def _is_disk_exhaustion(error: BaseException | str) -> bool: - text = str(error) - return "No space left on device" in text or "[Errno 28]" in text - - -def _directory_size(path: Path) -> int: - return sum( - entry.stat().st_size - for entry in path.rglob("*") - if entry.is_file() and not entry.is_symlink() - ) - - -def _measure_generated_cell( - *, - source: SourceSelection, - selected: SelectedCell, - generation: Mapping[str, Any], - generation_watchdog: Mapping[str, Any], - cell_dir: Path, - fc: str, - fflags: str, - make: str, - limit_gib: float, - mg5_root: Path, - cold_to_ready_limit_seconds: float, - target_seconds: float = TARGET_SECONDS, - warm_sample_count: int = WARM_SAMPLE_COUNT, -) -> dict[str, Any]: - process_dirs = generation.get("process_dirs") - if ( - not isinstance(process_dirs, Sequence) - or isinstance(process_dirs, str) - or len(process_dirs) != 1 - ): - raise SelectedMadGraphError( - "generation result has the wrong subprocess inventory" - ) - generated_root = Path(str(generation.get("output"))).resolve(strict=True) - process_dir = Path(str(process_dirs[0])).resolve(strict=True) - matrix_source = process_dir / "matrix.f" - matrix = _validate_matrix_source( - matrix_source, - family=selected.family, - final_multiplicity=selected.n, - ) - generation_resource = _watchdog_resource(generation_watchdog) - if not generation_resource["passes"]: - if generation_resource["outcome"] == "memory-limit-exceeded": - raise ResourceFrontierError( - "memory-limit", - f"MadGraph generation reached the strict {limit_gib:g}-GiB " - "memory limit", - ) - raise SelectedMadGraphError( - "generation memory enforcement did not pass: " - f"{generation_resource['outcome']}" - ) - build_budget_seconds = _remaining_cold_to_ready_budget( - cold_to_ready_limit_seconds, generation_resource - ) - check_source = process_dir.parent / "check_sa.f" - check_body = render_check_source( - selected, - summed_helicity_coverage_count=( - matrix["generated_helicity_coverage_count"] - if selected.helicity_workload == "sum" - else None - ), - target_seconds=target_seconds, - warm_sample_count=warm_sample_count, - ) - check_source.write_text(check_body, encoding="ascii") - - makefile = process_dir / "makefile" - if not makefile.exists(): - raise SelectedMadGraphError("generated subprocess has no makefile") - measurement_attempt = _new_attempt_directory(cell_dir, "measurement") - build_report = measurement_attempt / "build-watchdog.json" - retained = measurement_attempt / "retained" - retained.mkdir() - retained_matrix = retained / "matrix.f" - retained_check = retained / "check_sa.f" - retained_executable = retained / "check" - shutil.copy2(matrix_source, retained_matrix) - shutil.copy2(check_source, retained_check) - build_command = [make, "check", f"FC={fc}", f"FFLAGS={fflags}"] - build, build_watchdog = _run_bounded_command( - build_command, - cwd=process_dir, - report=build_report, - limit_gib=limit_gib, - timeout_seconds=build_budget_seconds, - ) - build_resource = _watchdog_resource(build_watchdog) - if build.returncode != 0: - detail = (build.stdout + "\n" + build.stderr)[-8000:] - if build_resource["outcome"] == "memory-limit-exceeded": - raise ResourceFrontierError( - "memory-limit", - f"cold-to-ready generation reached the strict {limit_gib:g}-GiB " - "memory limit", - ) - if _bounded_command_timed_out(build): - raise ResourceFrontierError( - "generation-time-limit", - "cold-to-ready generation reached the strict time limit", - ) - raise SelectedMadGraphError(f"generated standalone build failed:\n{detail}") - if not build_resource["passes"]: - raise SelectedMadGraphError( - f"build memory enforcement did not pass: {build_resource['outcome']}" - ) - executable = process_dir / "check" - if not executable.is_file(): - raise SelectedMadGraphError( - "generated standalone build produced no check executable" - ) - generated_size_bytes = _directory_size(generated_root) - - shutil.copy2(executable, retained_executable) - - runtime_budget_seconds = _remaining_cold_to_ready_budget( - cold_to_ready_limit_seconds, generation_resource, build_resource - ) - runtime_report = measurement_attempt / "runtime-watchdog.json" - runtime, runtime_watchdog = _run_bounded_command( - [str(executable)], - cwd=process_dir, - report=runtime_report, - limit_gib=limit_gib, - timeout_seconds=runtime_budget_seconds, - ) - runtime_resource = _watchdog_resource(runtime_watchdog) - if runtime.returncode != 0: - detail = (runtime.stdout + "\n" + runtime.stderr)[-8000:] - if runtime_resource["outcome"] == "memory-limit-exceeded": - raise ResourceFrontierError( - "memory-limit", - f"initialized runtime reached the strict {limit_gib:g}-GiB " - "memory limit", - ) - if _bounded_command_timed_out(runtime): - raise ResourceFrontierError( - "generation-time-limit", - "initialization/check execution exhausted the remaining " - "cold-to-ready time budget", - ) - raise SelectedMadGraphError(f"generated standalone runtime failed:\n{detail}") - if not runtime_resource["passes"]: - raise SelectedMadGraphError( - f"runtime memory enforcement did not pass: {runtime_resource['outcome']}" - ) - parsed = parse_driver_output( - runtime.stdout, - batches=warm_sample_count + 1, - expected_total_external=selected.total_external, - expected_events=POINT_COUNT, - helicity_workload=selected.helicity_workload, - expected_helicity_coverage_count=( - int(matrix["generated_helicity_coverage_count"]) - if selected.helicity_workload == "sum" - else None - ), - ) - # Fixed MATRIX is deliberately unaveraged and retains the historical - # family-specific reference convention. Summed mode calls SMATRIX, which - # already applies IDEN exactly once, so its normalized source points need - # no further factor. - normalization_factor = _numerical_normalization_factor( - selected.family, - smatrix_iden=int(matrix["smatrix_iden"]), - helicity_workload=selected.helicity_workload, - ) - relative_errors = tuple( - _relative_error(observed * normalization_factor, reference) - for observed, reference in zip( - parsed.point_values, selected.reference_point_values, strict=True - ) - ) - maximum_error = max(relative_errors) - if maximum_error > RELATIVE_TOLERANCE: - raise SelectedMadGraphError( - f"MadGraph points disagree with {selected.source_mode} " - f"(maximum relative error {maximum_error:.6e})" - ) - calibration = parsed.cell_seconds[0][0] - warm_samples = tuple(row[0] for row in parsed.cell_seconds[1:]) - if len(warm_samples) != warm_sample_count or any( - value <= 0.0 for value in warm_samples - ): - raise SelectedMadGraphError( - "MadGraph did not provide the requested positive warm samples" - ) - warm = statistics.median(warm_samples) - cold_to_ready_seconds = ( - generation_resource["elapsed_wall_seconds"] - + build_resource["elapsed_wall_seconds"] - + parsed.initialization_seconds - ) - cold_to_ready_peak_kib = max( - generation_resource["peak_guard_kib"], - build_resource["peak_guard_kib"], - runtime_resource["peak_guard_kib"], - ) - if cold_to_ready_seconds >= cold_to_ready_limit_seconds: - raise ResourceFrontierError( - "generation-time-limit", - "cold-to-ready generation reached the strict time limit", - ) - runtime_self_rss = _parse_time_max_rss(runtime.stderr) - event_paths = [str(event.path) for event in selected.events] - event_hashes = [event.sha256 for event in selected.events] - mg_version = (mg5_root / "VERSION").read_text(encoding="utf-8").strip() - summed = selected.helicity_workload == "sum" - label = _workload_label(selected.helicity_workload) - timed_helicity_count = parsed.helicity_coverage_count - if summed and timed_helicity_count != matrix["generated_helicity_coverage_count"]: - raise SelectedMadGraphError( - "MadGraph output helicity coverage differs from generated NCOMB" - ) - return { - "status": "measured", - "family": selected.family, - "mode": MODE, - "label": label, - "n": selected.n, - "total_external": selected.total_external, - "process": selected.process, - "alpha_s": ( - selected.source_alpha_s - if summed - else selected.events[0].strong_coupling ** 2 / (4.0 * math.pi) - ), - "helicity": list(selected.helicity), - "helicity_workload": selected.helicity_workload, - "warm_fixed_helicity": not summed, - "warm_helicity_sum": summed, - "timed_helicity_count": timed_helicity_count, - "event_paths": event_paths, - "event_sha256": event_hashes, - "point_values": list(parsed.point_values), - "matrix_element": parsed.point_values[0], - "generation_seconds": cold_to_ready_seconds, - "warm_seconds_per_point": warm, - "max_rss_kib": cold_to_ready_peak_kib, - "warm_samples_seconds": list(warm_samples), - "metrics": { - "generation_seconds": cold_to_ready_seconds, - "warm_seconds_per_point": warm, - "max_rss_kib": cold_to_ready_peak_kib, - }, - "probe": { - "timer_source": "process-cpu-time", - "warm_median_seconds": warm, - "warm_samples_seconds": list(warm_samples), - "warm_sample_count": warm_sample_count, - "calibration_target_seconds": target_seconds, - "calibration_sample_seconds": calibration, - "published_driver_batches": list(range(2, warm_sample_count + 2)), - "timed_event_index": 1, - "validation_event_count": POINT_COUNT, - "validation_first_pass_seconds": parsed.first_pass_seconds, - "runtime_self_max_rss_kib": runtime_self_rss, - "runtime_process_tree_peak_guard_kib": runtime_resource["peak_guard_kib"], - }, - "numerical": { - "reference_mode": selected.source_mode, - "relative_tolerance": RELATIVE_TOLERANCE, - "normalization_factor_reference_per_madgraph": normalization_factor, - "normalization_contract": ( - ( - "generated SMATRIX applies its IDEN denominator exactly once; " - "no additional normalization" - ) - if summed - else "identity" - if selected.family == "gg" - else ( - "generated SMATRIX IDEN denominator applied to unaveraged " - "direct MATRIX; includes incoming spin/colour averaging " - "and identical-final-state symmetry" - ) - ), - "maximum_relative_error": maximum_error, - "relative_errors": list(relative_errors), - "passes": True, - }, - "protocol": { - "evaluator": ( - "SMATRIX(P,ANS)-generated-complete-helicity-sum" - if summed - else "MATRIX(P,NHEL,IC)-direct" - ), - "generation_helicity_coverage": "all", - "helicity_workload": selected.helicity_workload, - "warm_fixed_helicity": not summed, - "warm_helicity_sum": summed, - "helicity_summed": summed, - "timed_helicity_count": timed_helicity_count, - "helicity_sum_implementation": ( - "generated-SMATRIX-with-USERHEL-minus-one" - if summed - else "not-applicable" - ), - "warmed_native_call_pruning": ( - "generated GOODHEL cache may skip structurally zero helicities" - if summed - else "not-applicable" - ), - "color_sum": ( - "generated-SMATRIX-summed-and-averaged" - if summed - else "full-unaveraged" - ), - "incoming_color_average": summed, - "incoming_helicity_average": summed, - "final_state_symmetry_factor": summed, - "timer_source": "process-cpu-time", - "batch_size": 1, - "warm_sample_count": warm_sample_count, - "validated_point_count": POINT_COUNT, - "timed_point_index": 1, - "calibration_target_seconds": target_seconds, - "fixed_repetitions_after_calibration": True, - "calibration_sample_included": False, - "initialization_included": False, - "first_pass_included": False, - "build_included": False, - }, - "runtime_refresh": { - "accepted": True, - "fresh_process": True, - "scope": "generation-resource-and-warm-runtime", - }, - "provenance": { - "source_report": { - "path": _display_path(source.path), - "sha256": source.sha256, - "cell": ( - f"cells.{selected.family}.{selected.source_mode}.{selected.n}" - ), - }, - "source_alpha_s": source.alpha_s, - "runtime_alpha_s": ( - source.alpha_s - if summed - else selected.events[0].strong_coupling ** 2 / (4.0 * math.pi) - ), - "madgraph_root": str(mg5_root), - "madgraph_version": mg_version, - "matrix_sha256": matrix["matrix_sha256"], - "generated_matrix_graphs": matrix["generated_matrix_graphs"], - "colour_flows": matrix["colour_flows"], - "smatrix_iden": matrix["smatrix_iden"], - "generation_helicity_coverage": "all", - "helicity_workload": selected.helicity_workload, - "warm_fixed_helicity": not summed, - "warm_helicity_sum": summed, - "timed_helicity_count": timed_helicity_count, - "compiler": fc, - "fflags": fflags, - "check_source_sha256": hashlib.sha256( - check_body.encode("ascii") - ).hexdigest(), - "generated_output_size_bytes": generated_size_bytes, - "cold_to_ready": { - "elapsed_wall_seconds": cold_to_ready_seconds, - "peak_guard_kib": cold_to_ready_peak_kib, - "included_stages": [ - "mg5-output", - "standalone-check-build", - "required-model-initialization", - ], - "initialization_seconds": parsed.initialization_seconds, - }, - "measurement_attempt": str(measurement_attempt), - "build_watchdog_report": str(build_report), - "build_stdout_log": str( - build_report.with_name(f"{build_report.stem}.stdout.log") - ), - "build_stderr_log": str( - build_report.with_name(f"{build_report.stem}.stderr.log") - ), - "runtime_watchdog_report": str(runtime_report), - "runtime_stdout_log": str( - runtime_report.with_name(f"{runtime_report.stem}.stdout.log") - ), - "runtime_stderr_log": str( - runtime_report.with_name(f"{runtime_report.stem}.stderr.log") - ), - "retained": { - "matrix_source": str(retained_matrix), - "matrix_sha256": _sha256(retained_matrix), - "check_source": str(retained_check), - "check_source_sha256": _sha256(retained_check), - "executable": str(retained_executable), - "executable_sha256": _sha256(retained_executable), - }, - "generation": generation_resource, - "build": build_resource, - "runtime": runtime_resource, - "runtime_self_max_rss_kib": runtime_self_rss, - }, - } - - -def _failure_cell(selected: SelectedCell, category: str, reason: str) -> dict[str, Any]: - if category not in RESOURCE_FRONTIER_CATEGORIES: - raise SelectedMadGraphError( - f"refusing non-resource failure as a physics frontier: {category}" - ) - return { - "status": "failed", - "family": selected.family, - "mode": MODE, - "label": _workload_label(selected.helicity_workload), - "n": selected.n, - "total_external": selected.total_external, - "process": selected.process, - "helicity_workload": selected.helicity_workload, - "failure_category": category, - "failure_reason": reason, - "censors_higher_multiplicities": True, - "availability_frontier_n": selected.n - 1, - } - - -def _dependency_failure_cell( - family: str, - n: int, - reason: str, - *, - helicity_workload: str = "fixed", - censors_higher_multiplicities: bool = True, -) -> dict[str, Any]: - cell: dict[str, Any] = { - "status": "failed", - "family": family, - "mode": MODE, - "label": _workload_label(helicity_workload), - "n": n, - "total_external": n + 2, - "process": process_expression(family, n), - "helicity_workload": helicity_workload, - "failure_category": "dependency-unavailable", - "failure_reason": ( - f"source {source_mode(family, helicity_workload)} cell is unavailable: " - f"{reason}" - ), - "censors_higher_multiplicities": censors_higher_multiplicities, - } - if censors_higher_multiplicities: - cell["availability_frontier_n"] = n - 1 - return cell - - -def _frontier_cell( - family: str, - n: int, - *, - failure_n: int, - reason: str, - helicity_workload: str = "fixed", -) -> dict[str, Any]: - return { - "status": "skipped", - "family": family, - "mode": MODE, - "label": _workload_label(helicity_workload), - "n": n, - "total_external": n + 2, - "process": process_expression(family, n), - "helicity_workload": helicity_workload, - "failure_category": "skipped-after-frontier", - "failure_reason": reason, - "censors_higher_multiplicities": True, - "availability_frontier_n": failure_n - 1, - "skipped_after_frontier": True, - } - - -def _diagnostic_skip_cell( - family: str, n: int, reason: str, *, helicity_workload: str = "fixed" -) -> dict[str, Any]: - return { - "status": "skipped", - "family": family, - "mode": MODE, - "label": _workload_label(helicity_workload), - "n": n, - "total_external": n + 2, - "process": process_expression(family, n), - "helicity_workload": helicity_workload, - "failure_category": "diagnostic-selection-omitted", - "failure_reason": reason, - "censors_higher_multiplicities": False, - "skipped_after_frontier": False, - } - - -def _protocol_scope_cell( - family: str, n: int, *, helicity_workload: str = "fixed" -) -> dict[str, Any]: - limit = protocol_measured_multiplicity_limit(family) - if protocol_measures_multiplicity(family, n): - raise SelectedMadGraphError( - f"MadGraph protocol scope does not apply at n={n}" - ) - if family == "gg" and n == 6: - category = "protocol-scope-pure-gluon-n6" - reason = ( - "final-plot protocol skips pure-gluon MadGraph standalone n=6: " - "the generated 116 MiB matrix.f source triggered a deterministic " - "gfortran -O3 f951 internal compiler error after a 6h41m build " - "attempt; higher candidate and reference frontiers are profiled " - "independently" - ) - else: - category = f"protocol-scope-n>{limit}" - reason = ( - f"final-plot protocol measures {family} MadGraph standalone only " - f"through n={limit}; higher candidate and reference frontiers are " - "profiled independently" - ) - return { - "status": "not-applicable", - "family": family, - "mode": MODE, - "label": _workload_label(helicity_workload), - "n": n, - "total_external": n + 2, - "process": process_expression(family, n), - "helicity_workload": helicity_workload, - "failure_category": category, - "failure_reason": reason, - "censors_higher_multiplicities": False, - "protocol_scope": { - "maximum_measured_multiplicity": limit, - "disposition": "not-applicable", - }, - } - - -def _checkpoint_identity( - source: SourceSelection, - selected: SelectedCell, - mg5_root: Path, - fc: str, - fflags: str, - make: str, - timeout_seconds: float, - memory_limit_gib: float, - target_seconds: float, - warm_sample_count: int, -) -> dict[str, Any]: - source_cell_payload = { - "schema_version": 1, - "alpha_s": source.alpha_s, - "family": selected.family, - "n": selected.n, - "process": selected.process, - "source_mode": selected.source_mode, - "helicity_workload": selected.helicity_workload, - "helicity": list(selected.helicity), - "event_sha256": [event.sha256 for event in selected.events], - "reference_point_values": list(selected.reference_point_values), - } - source_cell_sha256 = hashlib.sha256( - json.dumps( - source_cell_payload, - sort_keys=True, - separators=(",", ":"), - allow_nan=False, - ).encode("utf-8") - ).hexdigest() - return { - "checkpoint_protocol": CHECKPOINT_PROTOCOL, - "measurement_host": measurement_host_identity(), - "source_report_sha256": source.sha256, - "source_cell_sha256": source_cell_sha256, - "family": selected.family, - "n": selected.n, - "process": selected.process, - "helicity_workload": selected.helicity_workload, - "helicity": list(selected.helicity), - "event_sha256": [event.sha256 for event in selected.events], - "mg5_root": str(mg5_root), - "mg5_version_sha256": _sha256(mg5_root / "VERSION"), - "fc": fc, - "fflags": fflags, - "make": make, - "generation_timeout_seconds": timeout_seconds, - "memory_limit_gib": memory_limit_gib, - "target_seconds": target_seconds, - "warm_sample_count": warm_sample_count, - } - - -def _rebind_source_provenance( - cell: Mapping[str, Any], *, source: SourceSelection, selected: SelectedCell -) -> tuple[dict[str, Any], bool]: - copied = dict(cell) - if copied.get("status") != "measured": - return copied, False - raw_provenance = _mapping( - copied.get("provenance"), context="checkpoint cell provenance" - ) - provenance = dict(raw_provenance) - expected_source = { - "path": _display_path(source.path), - "sha256": source.sha256, - "cell": f"cells.{selected.family}.{selected.source_mode}.{selected.n}", - } - changed = provenance.get("source_report") != expected_source - provenance["source_report"] = expected_source - copied["provenance"] = provenance - return copied, changed - - -def _runtime_policy( - multiplicities: Sequence[int], - *, - timeout_seconds: float, - memory_limit_gib: float, - target_seconds: float = TARGET_SECONDS, - warm_sample_count: int = WARM_SAMPLE_COUNT, - helicity_workload: str = "fixed", -) -> dict[str, Any]: - summed = helicity_workload == "sum" - _workload_label(helicity_workload) - return { - "final_state_multiplicities": list(multiplicities), - "process_families": list(FAMILIES), - "point_validation_count": POINT_COUNT, - "warm_timed_point_index": 1, - "warm_sample_count": warm_sample_count, - "calibration_target_seconds": target_seconds, - "generation_timeout_seconds": timeout_seconds, - "outer_memory_watchdog_gib": memory_limit_gib, - "watchdog_enforced_per_generation_build_and_runtime": True, - "standalone_source": "fresh helicity-general MadGraph standalone", - "evaluator": ( - "generated SMATRIX(P,ANS) with USERHEL=-1 and warmed GOODHEL pruning" - if summed - else "direct MATRIX(P,NHEL,IC)" - ), - "generation_helicity_coverage": "all", - "helicity_workload": helicity_workload, - "warm_fixed_helicity": not summed, - "warm_helicity_sum": summed, - "maximum_measured_multiplicity": MAX_PROTOCOL_MEASURED_MULTIPLICITY, - "family_maximum_measured_multiplicity": ( - protocol_measured_multiplicity_limits() - ), - "higher_multiplicity_policy": "not-applicable-protocol-scope", - "metric_scope": { - "generation_seconds": ( - "cold-to-ready MG5 generation, check build, and required " - "model initialization" - ), - "max_rss_kib": ( - "maximum conservative process-tree peak guard across " - "generation, build, and initialized runtime" - ), - "warm_seconds_per_point": ( - f"median of {warm_sample_count} post-calibration point-01 CPU " - "sample(s) of one " - + ( - "complete physical-helicity sum" - if summed - else "fixed-helicity evaluation" - ) - ), - }, - } - - -def _progress_cell_identity( - family: str, n: int, *, helicity_workload: str = "fixed" -) -> dict[str, Any]: - return { - "family": family, - "mode": MODE, - "n": n, - "total_external": n + 2, - "process": process_expression(family, n), - "helicity_workload": helicity_workload, - } - - -def _runtime_progress_report( - *, - source: SourceSelection, - runtime_series: Mapping[str, Mapping[str, Mapping[str, Mapping[str, Any]]]], - selected_multiplicities: Sequence[int], - selected_families: Sequence[str], - timeout_seconds: float, - memory_limit_gib: float, - target_seconds: float, - warm_sample_count: int, - started_at_utc: str, - current_cell: Mapping[str, Any] | None, -) -> dict[str, Any]: - counts = Counter( - str(cell.get("status")) - for family_series in runtime_series.values() - for mode_cells in family_series.values() - for cell in mode_cells.values() - ) - completed = sum(counts.values()) - total = len(FAMILIES) * len(selected_multiplicities) - pending = [ - _progress_cell_identity( - family, n, helicity_workload=source.helicity_workload - ) - for family in FAMILIES - for n in selected_multiplicities - if str(n) not in runtime_series[family][MODE] - ] - if completed == total: - status = "complete-with-failures" if counts["failed"] else "complete" - current: Mapping[str, Any] | None = None - else: - status = "running" - current = current_cell - return { - "kind": PROGRESS_KIND, - "schema_version": SCHEMA_VERSION, - "status": status, - "started_at_utc": started_at_utc, - "updated_at_utc": datetime.now(UTC).isoformat(), - "source_report": { - "path": _display_path(source.path), - "sha256": source.sha256, - }, - "producer": { - "path": _display_path(Path(__file__).resolve()), - "sha256": _sha256(Path(__file__).resolve()), - }, - "host": measurement_host_identity(), - "policy": _runtime_policy( - selected_multiplicities, - timeout_seconds=timeout_seconds, - memory_limit_gib=memory_limit_gib, - target_seconds=target_seconds, - warm_sample_count=warm_sample_count, - helicity_workload=source.helicity_workload, - ) - | {"selected_process_families": list(selected_families)}, - "current_cell": dict(current) if current is not None else None, - "pending_cells": pending, - "summary": { - "completed_cell_count": completed, - "pending_cell_count": len(pending), - "total_cell_count": total, - "runtime_series_status_counts": dict(sorted(counts.items())), - }, - "runtime_series": runtime_series, - } - - -def load_runtime_progress(path: Path) -> dict[str, Any]: - """Read and authenticate one atomically published sparse progress report.""" - - payload = _read_json(path, context="MadGraph runtime progress") - if ( - payload.get("kind") != PROGRESS_KIND - or payload.get("schema_version") != SCHEMA_VERSION - ): - raise SelectedMadGraphError("MadGraph runtime progress has the wrong schema") - validate_measurement_host( - payload.get("host"), context="MadGraph runtime progress host" - ) - status = payload.get("status") - if status not in {"running", "complete", "complete-with-failures"}: - raise SelectedMadGraphError("MadGraph runtime progress has an invalid status") - source = _mapping( - payload.get("source_report"), context="MadGraph runtime progress source" - ) - source_path = source.get("path") - source_sha256 = source.get("sha256") - if ( - not isinstance(source_path, str) - or not source_path - or not isinstance(source_sha256, str) - or re.fullmatch(r"[0-9a-f]{64}", source_sha256) is None - ): - raise SelectedMadGraphError( - "MadGraph runtime progress has invalid source-report provenance" - ) - policy = _mapping( - payload.get("policy"), context="MadGraph runtime progress policy" - ) - helicity_workload = _declared_helicity_workload(policy) - raw_multiplicities = policy.get("final_state_multiplicities") - if ( - not isinstance(raw_multiplicities, Sequence) - or isinstance(raw_multiplicities, str) - or not raw_multiplicities - or any( - isinstance(n, bool) or not isinstance(n, int) or n < 2 - for n in raw_multiplicities - ) - ): - raise SelectedMadGraphError( - "MadGraph runtime progress has invalid multiplicities" - ) - multiplicities = tuple(int(n) for n in raw_multiplicities) - if tuple(sorted(set(multiplicities))) != multiplicities: - raise SelectedMadGraphError( - "MadGraph runtime progress multiplicities are not sorted and unique" - ) - if policy.get("process_families") != list(FAMILIES): - raise SelectedMadGraphError( - "MadGraph runtime progress has invalid process families" - ) - if ( - policy.get("maximum_measured_multiplicity") - != MAX_PROTOCOL_MEASURED_MULTIPLICITY - or policy.get("family_maximum_measured_multiplicity") - != protocol_measured_multiplicity_limits() - or policy.get("higher_multiplicity_policy") - != "not-applicable-protocol-scope" - ): - raise SelectedMadGraphError( - "MadGraph runtime progress has invalid multiplicity scope" - ) - raw_series = _mapping( - payload.get("runtime_series"), context="MadGraph runtime progress series" - ) - if set(raw_series) != set(FAMILIES): - raise SelectedMadGraphError( - "MadGraph runtime progress series has invalid process families" - ) - completed_identities: set[tuple[str, int]] = set() - counts: Counter[str] = Counter() - for family in FAMILIES: - family_series = _mapping( - raw_series.get(family), - context=f"MadGraph runtime progress series.{family}", - ) - if set(family_series) != {MODE}: - raise SelectedMadGraphError( - f"MadGraph runtime progress series.{family} has invalid modes" - ) - mode_cells = _mapping( - family_series.get(MODE), - context=f"MadGraph runtime progress series.{family}.{MODE}", - ) - for raw_n, raw_cell in mode_cells.items(): - try: - n = int(raw_n) - except (TypeError, ValueError) as error: - raise SelectedMadGraphError( - "MadGraph runtime progress has an invalid cell key" - ) from error - if str(n) != raw_n or n not in multiplicities: - raise SelectedMadGraphError( - "MadGraph runtime progress has an out-of-policy cell" - ) - cell = _mapping( - raw_cell, - context=f"MadGraph runtime progress series.{family}.{MODE}.{n}", - ) - expected = _progress_cell_identity( - family, n, helicity_workload=helicity_workload - ) - if any(cell.get(key) != value for key, value in expected.items()): - raise SelectedMadGraphError( - "MadGraph runtime progress cell identity is invalid" - ) - cell_status = cell.get("status") - if cell_status not in { - "measured", - "failed", - "skipped", - "not-applicable", - }: - raise SelectedMadGraphError( - "MadGraph runtime progress cell status is invalid" - ) - is_protocol_scoped = not protocol_measures_multiplicity(family, n) - if (cell_status == "not-applicable") != is_protocol_scoped: - raise SelectedMadGraphError( - "MadGraph runtime progress protocol scope is invalid" - ) - completed_identities.add((family, n)) - counts[str(cell_status)] += 1 - raw_pending = payload.get("pending_cells") - if not isinstance(raw_pending, Sequence) or isinstance(raw_pending, str): - raise SelectedMadGraphError( - "MadGraph runtime progress pending_cells is invalid" - ) - pending_identities: set[tuple[str, int]] = set() - for raw_pending_cell in raw_pending: - pending_cell = _mapping( - raw_pending_cell, context="MadGraph runtime progress pending cell" - ) - family = pending_cell.get("family") - n = pending_cell.get("n") - if ( - family not in FAMILIES - or isinstance(n, bool) - or not isinstance(n, int) - or n not in multiplicities - or any( - pending_cell.get(key) != value - for key, value in _progress_cell_identity( - str(family), n, helicity_workload=helicity_workload - ).items() - ) - ): - raise SelectedMadGraphError( - "MadGraph runtime progress pending cell identity is invalid" - ) - pending_identities.add((str(family), n)) - all_identities = { - (family, n) for family in FAMILIES for n in multiplicities - } - if ( - len(pending_identities) != len(raw_pending) - or completed_identities & pending_identities - or completed_identities | pending_identities != all_identities - ): - raise SelectedMadGraphError( - "MadGraph runtime progress completed/pending partition is invalid" - ) - summary = _mapping( - payload.get("summary"), context="MadGraph runtime progress summary" - ) - expected_summary = { - "completed_cell_count": len(completed_identities), - "pending_cell_count": len(pending_identities), - "total_cell_count": len(all_identities), - "runtime_series_status_counts": dict(sorted(counts.items())), - } - if dict(summary) != expected_summary: - raise SelectedMadGraphError("MadGraph runtime progress summary is invalid") - current = payload.get("current_cell") - if current is not None: - current_cell = _mapping( - current, context="MadGraph runtime progress current_cell" - ) - family = current_cell.get("family") - n = current_cell.get("n") - if ( - family not in FAMILIES - or isinstance(n, bool) - or not isinstance(n, int) - or (str(family), n) not in pending_identities - or any( - current_cell.get(key) != value - for key, value in _progress_cell_identity( - str(family), n, helicity_workload=helicity_workload - ).items() - ) - or not isinstance(current_cell.get("stage"), str) - or not current_cell["stage"] - ): - raise SelectedMadGraphError( - "MadGraph runtime progress current_cell is invalid" - ) - if status == "running" and not pending_identities: - raise SelectedMadGraphError( - "running MadGraph runtime progress has no pending cells" - ) - if status != "running" and (pending_identities or current is not None): - raise SelectedMadGraphError( - "terminal MadGraph runtime progress still has pending work" - ) - expected_status = "complete-with-failures" if counts["failed"] else "complete" - if status != "running" and status != expected_status: - raise SelectedMadGraphError( - "terminal MadGraph runtime progress status disagrees with its cells" - ) - return payload - - -def _default_progress_output(output: Path) -> Path: - return output.with_name(f"{output.stem}.progress.json") - - -def build_runtime_report( - *, - source_report: Path, - cache_dir: Path, - fc: str, - fflags: str, - make: str = os.environ.get("MAKE", "make"), - timeout_seconds: float, - mg5_root: Path, - family: str | None = None, - min_n: int = 2, - max_n: int = 9, - multiplicities: Sequence[int] | None = None, - memory_limit_gib: float = MAX_MEMORY_GIB, - target_seconds: float = TARGET_SECONDS, - warm_sample_count: int = WARM_SAMPLE_COUNT, - keep_generated: bool = False, - progress_output: Path | None = None, - helicity_workload: str = "fixed", -) -> dict[str, Any]: - resolved_cache = cache_dir.expanduser().resolve(strict=False) - lock = _acquire_cache_lock(resolved_cache) - try: - return _build_runtime_report_locked( - source_report=source_report, - cache_dir=resolved_cache, - fc=fc, - fflags=fflags, - make=make, - timeout_seconds=timeout_seconds, - mg5_root=mg5_root, - family=family, - min_n=min_n, - max_n=max_n, - multiplicities=multiplicities, - memory_limit_gib=memory_limit_gib, - target_seconds=target_seconds, - warm_sample_count=warm_sample_count, - keep_generated=keep_generated, - progress_output=progress_output, - helicity_workload=helicity_workload, - ) - finally: - lock.close() - - -def _build_runtime_report_locked( - *, - source_report: Path, - cache_dir: Path, - fc: str, - fflags: str, - make: str, - timeout_seconds: float, - mg5_root: Path, - family: str | None = None, - min_n: int = 2, - max_n: int = 9, - multiplicities: Sequence[int] | None = None, - memory_limit_gib: float = MAX_MEMORY_GIB, - target_seconds: float = TARGET_SECONDS, - warm_sample_count: int = WARM_SAMPLE_COUNT, - keep_generated: bool = False, - progress_output: Path | None = None, - helicity_workload: str = "fixed", -) -> dict[str, Any]: - _workload_label(helicity_workload) - if family is not None and family not in FAMILIES: - raise SelectedMadGraphError(f"unsupported family {family!r}") - raw_multiplicities: Sequence[int] = ( - multiplicities if multiplicities is not None else range(min_n, max_n + 1) - ) - if not raw_multiplicities or any( - isinstance(n, bool) or not isinstance(n, int) or n < 2 - for n in raw_multiplicities - ): - raise SelectedMadGraphError("multiplicities must be integers >=2") - selected_multiplicities = tuple(sorted(set(raw_multiplicities))) - if ( - isinstance(timeout_seconds, bool) - or not math.isfinite(timeout_seconds) - or timeout_seconds <= 0.0 - ): - raise SelectedMadGraphError("generation timeout must be positive and finite") - if ( - isinstance(memory_limit_gib, bool) - or not math.isfinite(memory_limit_gib) - or memory_limit_gib <= 0.0 - ): - raise SelectedMadGraphError("memory limit must be positive and finite") - if ( - isinstance(target_seconds, bool) - or not math.isfinite(target_seconds) - or target_seconds <= 0.0 - ): - raise SelectedMadGraphError("target seconds must be positive and finite") - if ( - isinstance(warm_sample_count, bool) - or not isinstance(warm_sample_count, int) - or warm_sample_count < 1 - ): - raise SelectedMadGraphError("warm sample count must be positive") - mg5_root = mg5_root.expanduser().resolve(strict=True) - if ( - not (mg5_root / "bin" / "mg5_aMC").is_file() - or not (mg5_root / "VERSION").is_file() - ): - raise SelectedMadGraphError(f"invalid MadGraph installation: {mg5_root}") - if not WATCHDOG.is_file(): - raise SelectedMadGraphError(f"memory watchdog is missing: {WATCHDOG}") - cache_dir = cache_dir.expanduser().resolve(strict=False) - cache_dir.mkdir(parents=True, exist_ok=True) - selected_families = FAMILIES if family is None else (family,) - measured_multiplicities = { - name: tuple( - n - for n in selected_multiplicities - if protocol_measures_multiplicity(name, n) - ) - for name in selected_families - } - runtime_series: dict[str, dict[str, dict[str, Any]]] = { - name: {MODE: {}} for name in FAMILIES - } - source = load_source_selection( - source_report, - multiplicities=measured_multiplicities, - families=selected_families, - helicity_workload=helicity_workload, - ) - local_host = measurement_host_identity() - if source.measurement_host is not None and source.measurement_host != local_host: - raise SelectedMadGraphError( - "source campaign and MadGraph runtime must use the same measurement host" - ) - started_at_utc = datetime.now(UTC).isoformat() - progress_path = ( - progress_output.expanduser().resolve(strict=False) - if progress_output is not None - else None - ) - - def load_reusable_checkpoint(name: str, n: int) -> dict[str, Any] | None: - if ( - name not in selected_families - or not protocol_measures_multiplicity(name, n) - or n in source.unavailable[name] - ): - return None - selected = source.cells[name][n] - cell_dir = cache_dir / name / f"n{n}" - checkpoint = cell_dir / "cell.json" - if not checkpoint.is_file(): - return None - identity = _checkpoint_identity( - source, - selected, - mg5_root, - fc, - fflags, - make, - timeout_seconds, - memory_limit_gib, - target_seconds, - warm_sample_count, - ) - cell = _load_checkpoint_cell( - checkpoint, - identity=identity, - cell_dir=cell_dir, - keep_generated=keep_generated, - ) - if cell is None: - return None - cell, provenance_changed = _rebind_source_provenance( - cell, source=source, selected=selected - ) - if provenance_changed: - _json_atomic(checkpoint, {"checkpoint_identity": identity, "cell": cell}) - return cell - - # Make a resumed/expanded run's first atomic progress snapshot at least as - # informative as its reusable cache. Otherwise the initial empty running - # snapshot temporarily hides a previously published terminal prefix. - for name in selected_families: - for n in selected_multiplicities: - reusable = load_reusable_checkpoint(name, n) - if reusable is not None: - runtime_series[name][MODE][str(n)] = reusable - - def publish_progress(current_cell: Mapping[str, Any] | None) -> None: - if progress_path is None: - return - progress = _runtime_progress_report( - source=source, - runtime_series=runtime_series, - selected_multiplicities=selected_multiplicities, - selected_families=selected_families, - timeout_seconds=timeout_seconds, - memory_limit_gib=memory_limit_gib, - target_seconds=target_seconds, - warm_sample_count=warm_sample_count, - started_at_utc=started_at_utc, - current_cell=current_cell, - ) - _json_atomic(progress_path, progress) - - publish_progress(None) - for name in FAMILIES: - if name not in selected_families: - for n in selected_multiplicities: - if not protocol_measures_multiplicity(name, n): - publish_progress( - _progress_cell_identity( - name, n, helicity_workload=helicity_workload - ) - | {"stage": "protocol-scope-not-applicable"} - ) - runtime_series[name][MODE][str(n)] = _protocol_scope_cell( - name, n, helicity_workload=helicity_workload - ) - publish_progress(None) - continue - publish_progress( - _progress_cell_identity( - name, n, helicity_workload=helicity_workload - ) - | {"stage": "diagnostic-family-omission"} - ) - runtime_series[name][MODE][str(n)] = _diagnostic_skip_cell( - name, - n, - "family omitted by diagnostic selection", - helicity_workload=helicity_workload, - ) - publish_progress(None) - continue - failure_n: int | None = None - failure_reason = "" - for n in selected_multiplicities: - if not protocol_measures_multiplicity(name, n): - publish_progress( - _progress_cell_identity( - name, n, helicity_workload=helicity_workload - ) - | {"stage": "protocol-scope-not-applicable"} - ) - runtime_series[name][MODE][str(n)] = _protocol_scope_cell( - name, n, helicity_workload=helicity_workload - ) - publish_progress(None) - continue - if failure_n is not None: - publish_progress( - _progress_cell_identity( - name, n, helicity_workload=helicity_workload - ) - | {"stage": "frontier-skip"} - ) - runtime_series[name][MODE][str(n)] = _frontier_cell( - name, - n, - failure_n=failure_n, - reason=failure_reason, - helicity_workload=helicity_workload, - ) - publish_progress(None) - continue - reusable = runtime_series[name][MODE].get(str(n)) - if reusable is not None: - if ( - reusable.get("status") == "failed" - and reusable.get("censors_higher_multiplicities") is True - ): - failure_n = n - failure_reason = str(reusable.get("failure_reason")) - continue - unavailable = source.unavailable[name].get(n) - if unavailable is not None: - publish_progress( - _progress_cell_identity( - name, n, helicity_workload=helicity_workload - ) - | { - "stage": ( - "source-dependency-frontier" - if unavailable.censors_higher_multiplicities - else "source-dependency-unavailable" - ) - } - ) - cell = _dependency_failure_cell( - name, - n, - unavailable.reason, - helicity_workload=helicity_workload, - censors_higher_multiplicities=( - unavailable.censors_higher_multiplicities - ), - ) - runtime_series[name][MODE][str(n)] = cell - if unavailable.censors_higher_multiplicities: - failure_n = n - failure_reason = str(cell["failure_reason"]) - publish_progress(None) - continue - selected = source.cells[name][n] - cell_dir = cache_dir / name / f"n{n}" - cell_dir.mkdir(parents=True, exist_ok=True) - checkpoint = cell_dir / "cell.json" - publish_progress( - _progress_cell_identity( - name, n, helicity_workload=helicity_workload - ) - | { - "stage": ( - "checkpoint-reuse" - if checkpoint.is_file() - else "generate-build-benchmark" - ) - } - ) - identity = _checkpoint_identity( - source, - selected, - mg5_root, - fc, - fflags, - make, - timeout_seconds, - memory_limit_gib, - target_seconds, - warm_sample_count, - ) - cell: dict[str, Any] | None = None - if checkpoint.is_file(): - cell = _load_checkpoint_cell( - checkpoint, - identity=identity, - cell_dir=cell_dir, - keep_generated=keep_generated, - ) - if cell is not None: - cell, provenance_changed = _rebind_source_provenance( - cell, source=source, selected=selected - ) - if provenance_changed: - _json_atomic( - checkpoint, - {"checkpoint_identity": identity, "cell": cell}, - ) - if cell is None: - generation, generation_watchdog = _generation_attempt( - selected=selected, - cell_dir=cell_dir, - mg5_root=mg5_root, - timeout=timeout_seconds, - limit_gib=memory_limit_gib, - ) - if generation.get("status") != "measured": - category = str( - generation.get("failure_category") or "generation-error" - ) - reason = str( - generation.get("failure_reason") or "MadGraph generation failed" - ) - if category not in RESOURCE_FRONTIER_CATEGORIES: - if not keep_generated: - _prune_cell_generated(cell_dir) - raise SelectedMadGraphError( - f"{name}/n{n} generation diagnostic ({category}): {reason}" - ) - cell = _failure_cell(selected, category, reason) - else: - try: - cell = _measure_generated_cell( - source=source, - selected=selected, - generation=generation, - generation_watchdog=generation_watchdog, - cell_dir=cell_dir, - fc=fc, - fflags=fflags, - make=make, - limit_gib=memory_limit_gib, - mg5_root=mg5_root, - cold_to_ready_limit_seconds=timeout_seconds, - target_seconds=target_seconds, - warm_sample_count=warm_sample_count, - ) - except ResourceFrontierError as error: - cell = _failure_cell(selected, error.category, str(error)) - except (OSError, SelectedMadGraphError) as error: - if not keep_generated: - _prune_cell_generated(cell_dir) - context = ( - "campaign filesystem ran out of space" - if _is_disk_exhaustion(error) - else "MadGraph build/runtime diagnostic failed" - ) - raise SelectedMadGraphError( - f"{name}/n{n}: {context}: {error}" - ) from error - _json_atomic( - checkpoint, {"checkpoint_identity": identity, "cell": cell} - ) - if not keep_generated: - _prune_cell_generated(cell_dir) - runtime_series[name][MODE][str(n)] = cell - if ( - cell.get("status") == "failed" - and cell.get("censors_higher_multiplicities") is True - ): - failure_n = n - failure_reason = str(cell.get("failure_reason")) - publish_progress(None) - - counts = Counter( - str(cell.get("status")) - for family_series in runtime_series.values() - for mode_cells in family_series.values() - for cell in mode_cells.values() - ) - return { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "status": ( - "complete" if counts.get("failed", 0) == 0 else "complete-with-failures" - ), - "failure_count": counts.get("failed", 0), - "created_at_utc": datetime.now(UTC).isoformat(), - "policy": _runtime_policy( - selected_multiplicities, - timeout_seconds=timeout_seconds, - memory_limit_gib=memory_limit_gib, - target_seconds=target_seconds, - warm_sample_count=warm_sample_count, - helicity_workload=helicity_workload, - ), - "host": local_host, - "summary": {"runtime_series_status_counts": dict(sorted(counts.items()))}, - "runtime_series": runtime_series, - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--source-report", - type=Path, - required=True, - help="authenticated campaign report supplying event and helicity selections", - ) - parser.add_argument("--cache-dir", type=Path, required=True) - parser.add_argument("--output", type=Path, required=True) - parser.add_argument( - "--progress-output", - type=Path, - help=( - "atomic sparse progress JSON (default: .progress.json)" - ), - ) - parser.add_argument("--mg5-root", type=Path, required=True) - parser.add_argument("--fc", default=os.environ.get("FC", "gfortran")) - parser.add_argument("--fflags", default="-O3") - parser.add_argument("--make", default=os.environ.get("MAKE", "make")) - parser.add_argument( - "--generation-timeout-seconds", - "--timeout-seconds", - dest="timeout_seconds", - type=float, - default=DEFAULT_GENERATION_TIMEOUT_SECONDS, - ) - parser.add_argument("--memory-limit-gib", type=float, default=MAX_MEMORY_GIB) - parser.add_argument( - "--target-seconds", - type=float, - default=TARGET_SECONDS, - help="target post-calibration runtime for the timed MadGraph sample", - ) - parser.add_argument("--family", choices=FAMILIES) - parser.add_argument("--min-n", type=int, default=2) - parser.add_argument("--max-n", type=int, default=9) - parser.add_argument( - "--multiplicity", - dest="multiplicities", - action="append", - type=int, - help="exact final-state multiplicity; repeat for a sparse scan", - ) - parser.add_argument( - "--protocol-scope-multiplicity", - dest="protocol_scope_multiplicities", - action="append", - type=int, - help=( - "requested multiplicity recorded as not-applicable without " - "measurement when outside the selected family protocol scope; " - "repeat for a sparse final-plot scan" - ), - ) - parser.add_argument("--keep-generated", action="store_true") - parser.add_argument( - "--compare-helicity-sums", - action="store_true", - help=( - "benchmark generated SMATRIX(P,ANS) with USERHEL=-1 and warmed " - "GOODHEL pruning instead of one fixed direct-MATRIX helicity" - ), - ) - return parser - - -def _worker_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(add_help=False) - parser.add_argument("--mg5-root", type=Path, required=True) - parser.add_argument("--generated-output", type=Path, required=True) - parser.add_argument("--worker-result", type=Path, required=True) - parser.add_argument("--process", required=True) - parser.add_argument("--generation-timeout-seconds", type=float, required=True) - return parser - - -def _timeout_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(add_help=False) - parser.add_argument("--timeout-seconds", type=float, required=True) - parser.add_argument("command", nargs=argparse.REMAINDER) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - raw = list(sys.argv[1:] if argv is None else argv) - if raw and raw[0] == "_run-with-timeout": - try: - return _timeout_worker(_timeout_parser().parse_args(raw[1:])) - except SelectedMadGraphError as error: - print(f"MadGraph benchmark error: {error}", file=sys.stderr) - return 2 - if raw and raw[0] == "_generate-cell": - try: - return _generation_worker(_worker_parser().parse_args(raw[1:])) - except SelectedMadGraphError as error: - print(f"MadGraph benchmark error: {error}", file=sys.stderr) - return 2 - arguments = _parser().parse_args(raw) - try: - measured = tuple(arguments.multiplicities or ()) - scoped = tuple(arguments.protocol_scope_multiplicities or ()) - selected_families = ( - FAMILIES if arguments.family is None else (arguments.family,) - ) - if scoped and any( - any( - protocol_measures_multiplicity(family, n) - for family in selected_families - ) - for n in scoped - ): - raise SelectedMadGraphError( - "--protocol-scope-multiplicity accepts only multiplicities outside " - "the selected family protocol scope" - ) - if measured and any( - not any( - protocol_measures_multiplicity(family, n) - for family in selected_families - ) - for n in measured - ): - raise SelectedMadGraphError( - "--multiplicity must measure at least one selected family; use " - "--protocol-scope-multiplicity for pure protocol-scope cells" - ) - if set(measured) & set(scoped): - raise SelectedMadGraphError( - "measured and protocol-scoped multiplicities must be disjoint" - ) - selected_multiplicities = ( - tuple(sorted(set(measured) | set(scoped))) - if measured or scoped - else None - ) - output = arguments.output.expanduser().resolve(strict=False) - progress_output = ( - arguments.progress_output.expanduser().resolve(strict=False) - if arguments.progress_output is not None - else _default_progress_output(output) - ) - report = build_runtime_report( - source_report=arguments.source_report, - cache_dir=arguments.cache_dir, - fc=arguments.fc, - fflags=arguments.fflags, - make=arguments.make, - timeout_seconds=arguments.timeout_seconds, - family=arguments.family, - min_n=arguments.min_n, - max_n=arguments.max_n, - multiplicities=selected_multiplicities, - mg5_root=arguments.mg5_root, - memory_limit_gib=arguments.memory_limit_gib, - target_seconds=arguments.target_seconds, - keep_generated=arguments.keep_generated, - progress_output=progress_output, - helicity_workload=( - "sum" if arguments.compare_helicity_sums else "fixed" - ), - ) - _json_atomic(output, report) - except SelectedMadGraphError as error: - print(f"MadGraph benchmark error: {error}", file=sys.stderr) - return 2 - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_numerical_acceptance.py b/pyamplicol/tools/developer/fft_numerical_acceptance.py deleted file mode 100644 index 00a7dc3313..0000000000 --- a/pyamplicol/tools/developer/fft_numerical_acceptance.py +++ /dev/null @@ -1,2062 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Opt-in process-table numerical acceptance for FFT colour contraction. - -This gate is deliberately separate from the ordinary numerical-acceptance -campaign. It constructs its process surface from the performance catalog, -discovers one nonzero helicity with a cached direct oracle, and compares direct -and symmetric-group-FFT colour contraction without ever generating an artifact -per process. Recurrence artifacts specialize that tuple at generation time; -on-the-fly artifacts retain complete helicity coverage and apply the identical -recorded tuple through the runtime selector API. - -The real campaign is intentionally entered only through -``just fft-numerical-acceptance``. ``--dry-run`` authenticates the frozen -MadGraph fixture and prints the complete planned comparison surface without -loading the native runtime or writing files. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import re -import sys -import tomllib -import uuid -from collections import OrderedDict -from collections.abc import Callable, Mapping, Sequence -from dataclasses import dataclass -from datetime import UTC, datetime -from decimal import Decimal, localcontext -from pathlib import Path -from typing import Generic, Literal, TypeVar, cast - -ROOT = Path(__file__).resolve().parents[2] -if __package__ in {None, ""}: - sys.path.insert(0, str(ROOT)) - -from tools.developer.numerical_acceptance import ( # noqa: E402 - DEFAULT_FIXTURE, - POINT_SEED, - RELATIVE_TOLERANCE, - current_model_identity, - prepare_ufo_sm_model, - validation_momenta, -) -from tools.developer.reference_capture.common import canonical_decimal # noqa: E402 -from tools.performance_report.catalog import PROCESS_FAMILIES # noqa: E402 -from tools.performance_report.models import ( # noqa: E402 - Accuracy, - open_quark_line_count, -) -from tools.performance_report.selector_policy import ( # noqa: E402 - _preferred_helicities, - fixed_selector_helicity, - selector_helicity_id, -) - -GATE_KIND = "pyamplicol-fft-numerical-acceptance" -GATE_SCHEMA_VERSION = 1 -SELECTED_MAX_N_FINAL = 5 -TOTAL_MAX_N_FINAL = 4 -SELECTED_CASE_COUNT = 47 -TOTAL_CASE_COUNT = 33 - -MethodName = Literal["direct", "symmetric-group-fft"] -ModelName = Literal["built-in-sm", "ufo-sm"] -ModeName = Literal["recurrence", "on-the-fly"] -AccuracyName = Literal["full", "nlc"] -SelectionExecution = Literal[ - "generation-specialized", - "runtime-query-complete-coverage", -] - -METHODS: tuple[MethodName, ...] = ("direct", "symmetric-group-fft") -MODELS: tuple[ModelName, ...] = ("built-in-sm", "ufo-sm") -MODES: tuple[ModeName, ...] = ("recurrence", "on-the-fly") -ACCURACIES: tuple[AccuracyName, ...] = ("full", "nlc") - -_PURE_ADJOINT_REFLECTION_CASE_ID = "catalog:gg_gluons:n2" -_OPEN_LINE_REFLECTION_CASE_ID = "catalog:gg_tt_jets:n2" -# Query-family closures retain one amplitude destination per requested colour; -# the certified reflection fold is visible in the shared current finalizations. -_REFLECTION_CENSUS_FIELDS = ( - "union_unique_current_count", - "union_contribution_rows", - "union_finalization_rows", -) -_EXPECTED_PURE_ADJOINT_REFLECTION_CENSUS = { - "direct": (22, 36, 6), - "symmetric-group-fft": (13, 18, 3), -} - - -class FFTAcceptanceError(RuntimeError): - """The FFT acceptance contract could not be executed or authenticated.""" - - -class FFTAcceptanceMismatch(AssertionError): - """At least one strict numerical or nonzero assertion failed.""" - - -@dataclass(frozen=True, slots=True) -class CatalogCase: - case_id: str - family_id: int - family_key: str - n_final: int - process: str - - @property - def artifact_name(self) -> str: - return self.case_id.replace(":", "_").replace("-", "_") - - -def _symmetric_group_degree(case: CatalogCase) -> int: - """Return the nontrivial group degree implied by one catalog process.""" - - initial, separator, final = case.process.partition(">") - if not separator: - raise FFTAcceptanceError( - f"catalog case {case.case_id} has no initial/final separator" - ) - tokens = (*initial.split(), *final.split()) - adjoint_count = sum(token == "g" for token in tokens) - try: - open_line_count = open_quark_line_count(case.process) - except ValueError as error: - raise FFTAcceptanceError( - f"catalog case {case.case_id} has invalid open-line content" - ) from error - return adjoint_count if open_line_count else max(adjoint_count - 1, 0) - - -def _expected_inspection_method( - request_method: MethodName, - case: CatalogCase, -) -> str | None: - if request_method == "direct": - return None - return "symmetric-group-fourier" if _symmetric_group_degree(case) >= 2 else None - - -def catalog_cases(max_n_final: int = SELECTED_MAX_N_FINAL) -> tuple[CatalogCase, ...]: - """Derive the contracted-colour process surface from the live catalog.""" - - if max_n_final < 1: - raise ValueError("max_n_final must be positive") - cases: list[CatalogCase] = [] - for n_final in range(1, max_n_final + 1): - for family in sorted(PROCESS_FAMILIES, key=lambda item: item.identifier): - process = family.process(n_final) - if process is None or n_final > family.maximum_n(Accuracy.FULL): - continue - cases.append( - CatalogCase( - case_id=f"catalog:{family.key}:n{n_final}", - family_id=family.identifier, - family_key=family.key, - n_final=n_final, - process=process, - ) - ) - result = tuple(cases) - expected = { - TOTAL_MAX_N_FINAL: TOTAL_CASE_COUNT, - SELECTED_MAX_N_FINAL: SELECTED_CASE_COUNT, - }.get(max_n_final) - if expected is not None and len(result) != expected: - raise FFTAcceptanceError( - f"the performance catalog through n_final={max_n_final} must contain " - f"{expected} contracted-colour cases; observed {len(result)}" - ) - return result - - -@dataclass(frozen=True, slots=True) -class FrozenFullCase: - case: CatalogCase - momenta: tuple[tuple[Decimal, ...], ...] - expected_full: Decimal - - -@dataclass(frozen=True, slots=True) -class FrozenFullEvidence: - """The immutable FullColour subset of the tracked MadGraph capture.""" - - path: Path - madgraph_version: str - model_source_sha256: str - driver_sha256: str - cases: tuple[FrozenFullCase, ...] - - def case(self, case_id: str) -> FrozenFullCase: - for case in self.cases: - if case.case.case_id == case_id: - return case - raise KeyError(case_id) - - -def _mapping(value: object, where: str) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise FFTAcceptanceError(f"{where} must be an object") - return cast(Mapping[str, object], value) - - -def _reflection_census_triplet( - census: Mapping[str, object], - *, - label: str, -) -> tuple[int, int, int]: - if ( - census.get("basis") != "shared-query-family-union-v1" - or census.get("scope") != "active-family-union" - ): - raise FFTAcceptanceError( - f"{label} has the wrong active-family census identity: " - f"basis={census.get('basis')!r}, scope={census.get('scope')!r}" - ) - values: list[int] = [] - for field in _REFLECTION_CENSUS_FIELDS: - value = census.get(field) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise FFTAcceptanceError( - f"{label} has invalid {field}: {value!r}" - ) - values.append(value) - return cast(tuple[int, int, int], tuple(values)) - - -def validate_on_the_fly_reflection_census( - *, - pure_adjoint_direct: Mapping[str, object], - pure_adjoint_fft: Mapping[str, object], - open_line_direct: Mapping[str, object], - open_line_fft: Mapping[str, object], -) -> dict[str, object]: - """Lock the demonstrated n=2 production reflection boundary.""" - - pure = { - "direct": _reflection_census_triplet( - pure_adjoint_direct, - label=f"{_PURE_ADJOINT_REFLECTION_CASE_ID} direct", - ), - "symmetric-group-fft": _reflection_census_triplet( - pure_adjoint_fft, - label=f"{_PURE_ADJOINT_REFLECTION_CASE_ID} symmetric-group-fft", - ), - } - for method, expected in _EXPECTED_PURE_ADJOINT_REFLECTION_CENSUS.items(): - observed = pure[method] - if observed != expected: - raise FFTAcceptanceError( - f"{_PURE_ADJOINT_REFLECTION_CASE_ID} {method} active-family census " - f"{_REFLECTION_CENSUS_FIELDS!r} is {observed!r}; expected {expected!r}" - ) - - open_direct = dict(open_line_direct) - open_fft = dict(open_line_fft) - open_triplets = { - "direct": _reflection_census_triplet( - open_direct, - label=f"{_OPEN_LINE_REFLECTION_CASE_ID} direct", - ), - "symmetric-group-fft": _reflection_census_triplet( - open_fft, - label=f"{_OPEN_LINE_REFLECTION_CASE_ID} symmetric-group-fft", - ), - } - if open_direct != open_fft: - differences = { - field: { - "direct": open_direct.get(field), - "symmetric-group-fft": open_fft.get(field), - } - for field in sorted(open_direct.keys() | open_fft.keys()) - if open_direct.get(field) != open_fft.get(field) - } - raise FFTAcceptanceError( - f"{_OPEN_LINE_REFLECTION_CASE_ID} has a nontrivial FFT workspace but " - "an open color line, so its direct and FFT active-family censuses " - f"must be identical; differences={differences!r}" - ) - - return { - "basis": "selected-helicity-production-active-family-census-v1", - "source": "Runtime.inspect().on_the_fly_state.active_family_union_census", - "pure_adjoint": { - "case_id": _PURE_ADJOINT_REFLECTION_CASE_ID, - "fields": list(_REFLECTION_CENSUS_FIELDS), - "direct": list(pure["direct"]), - "symmetric_group_fft": list(pure["symmetric-group-fft"]), - }, - "open_line": { - "case_id": _OPEN_LINE_REFLECTION_CASE_ID, - "direct_equals_symmetric_group_fft": True, - "fields": list(_REFLECTION_CENSUS_FIELDS), - "shared": list(open_triplets["direct"]), - }, - } - - -def _sequence(value: object, where: str) -> Sequence[object]: - if isinstance(value, (str, bytes, bytearray)) or not isinstance(value, Sequence): - raise FFTAcceptanceError(f"{where} must be an array") - return cast(Sequence[object], value) - - -def _canonical_fixture_decimal(value: object, where: str) -> Decimal: - if not isinstance(value, str): - raise FFTAcceptanceError(f"{where} must be a canonical decimal string") - try: - parsed = Decimal(value) - except ArithmeticError as error: - raise FFTAcceptanceError(f"{where} is not a decimal") from error - if not parsed.is_finite() or canonical_decimal(parsed) != value: - raise FFTAcceptanceError(f"{where} must be a canonical finite decimal") - return parsed - - -def _duplicate_rejecting_object( - pairs: list[tuple[str, object]], -) -> dict[str, object]: - result: dict[str, object] = {} - for key, value in pairs: - if key in result: - raise FFTAcceptanceError(f"frozen fixture repeats JSON key {key!r}") - result[key] = value - return result - - -def load_frozen_full_evidence(path: Path = DEFAULT_FIXTURE) -> FrozenFullEvidence: - """Authenticate and load only the immutable independent FullColour evidence. - - The capture records the exact MadGraph driver digest used to produce it. - Replaying immutable values must not require that today's capture adapter has - the same digest: doing so would turn harmless adapter maintenance into a - demand to rerun the explicitly frozen independent oracle. - """ - - source = path.expanduser().resolve(strict=True) - try: - payload = json.loads( - source.read_text(encoding="ascii"), - object_pairs_hook=_duplicate_rejecting_object, - parse_constant=lambda token: (_ for _ in ()).throw( - FFTAcceptanceError(f"frozen fixture has non-finite token {token!r}") - ), - ) - except FFTAcceptanceError: - raise - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise FFTAcceptanceError( - f"cannot read frozen fixture {source}: {error}" - ) from error - root = _mapping(payload, "frozen fixture") - if ( - root.get("kind") != "pyamplicol-ufo-sm-numerical-acceptance" - or root.get("schema_version") != 1 - or root.get("catalog_max_n_final") != TOTAL_MAX_N_FINAL - ): - raise FFTAcceptanceError("frozen fixture has the wrong identity or bounds") - point_policy = _mapping(root.get("point_policy"), "point_policy") - if dict(point_policy) != { - "generator": "generic_validation_point", - "seed": POINT_SEED, - "stored_components": "canonical-binary64-decimal", - }: - raise FFTAcceptanceError( - "frozen fixture does not use the seed-101 point policy" - ) - comparison = _mapping(root.get("comparison"), "comparison") - if ( - _canonical_fixture_decimal( - comparison.get("relative_tolerance"), "comparison.relative_tolerance" - ) - != RELATIVE_TOLERANCE - or comparison.get("absolute_tolerance") is not None - ): - raise FFTAcceptanceError( - "frozen fixture does not use strict relative-only tolerance 1e-10" - ) - model = _mapping(root.get("model"), "model") - if dict(model) != current_model_identity().as_payload(): - raise FFTAcceptanceError( - "frozen fixture model identity differs from the packaged UFO-SM" - ) - references = _mapping(root.get("references"), "references") - full_reference = _mapping(references.get("full"), "references.full") - if ( - full_reference.get("kind") != "madgraph-standalone-ufo-sm" - or full_reference.get("precision") != "binary64" - or full_reference.get("command_protocol") - != "generate-output-standalone-launch-force" - or full_reference.get("external_parameters_sha256") - != model.get("external_parameters_sha256") - ): - raise FFTAcceptanceError("frozen FullColour reference identity is invalid") - madgraph_version = full_reference.get("madgraph_version") - model_source_sha256 = full_reference.get("model_source_sha256") - driver_sha256 = full_reference.get("driver_sha256") - if not isinstance(madgraph_version, str) or not madgraph_version: - raise FFTAcceptanceError("frozen MadGraph version is invalid") - for label, digest in ( - ("model source", model_source_sha256), - ("driver", driver_sha256), - ): - if not isinstance(digest, str) or re.fullmatch(r"[0-9a-f]{64}", digest) is None: - raise FFTAcceptanceError(f"frozen MadGraph {label} digest is invalid") - - specs = catalog_cases(TOTAL_MAX_N_FINAL) - raw_cases = _sequence(root.get("catalog_cases"), "catalog_cases") - if len(raw_cases) != len(specs): - raise FFTAcceptanceError( - f"frozen fixture must contain {len(specs)} catalog cases" - ) - cases: list[FrozenFullCase] = [] - for spec, raw_case in zip(specs, raw_cases, strict=True): - record = _mapping(raw_case, f"frozen case {spec.case_id}") - observed_identity = ( - record.get("id"), - record.get("family_id"), - record.get("family_key"), - record.get("n_final"), - record.get("process"), - ) - expected_identity = ( - spec.case_id, - spec.family_id, - spec.family_key, - spec.n_final, - spec.process, - ) - if observed_identity != expected_identity: - raise FFTAcceptanceError( - f"frozen case {spec.case_id} differs from the live catalog" - ) - raw_momenta = _sequence(record.get("momenta"), f"{spec.case_id}.momenta") - momenta = tuple( - tuple( - _canonical_fixture_decimal( - component, - f"{spec.case_id}.momenta[{row_index}][{component_index}]", - ) - for component_index, component in enumerate( - _sequence(row, f"{spec.case_id}.momenta[{row_index}]") - ) - ) - for row_index, row in enumerate(raw_momenta) - ) - if len(momenta) != spec.n_final + 2 or any( - len(momentum) != 4 for momentum in momenta - ): - raise FFTAcceptanceError( - f"frozen case {spec.case_id} has malformed momentum dimensions" - ) - expected = _mapping(record.get("expected"), f"{spec.case_id}.expected") - expected_full = _canonical_fixture_decimal( - expected.get("full"), f"{spec.case_id}.expected.full" - ) - if expected_full < 0: - raise FFTAcceptanceError( - f"frozen case {spec.case_id} has a negative FullColour value" - ) - cases.append(FrozenFullCase(spec, momenta, expected_full)) - return FrozenFullEvidence( - source, - madgraph_version, - cast(str, model_source_sha256), - cast(str, driver_sha256), - tuple(cases), - ) - - -@dataclass(frozen=True, slots=True) -class ComparisonSpec: - authority: Literal["direct-vs-fft", "frozen-madgraph"] - model: ModelName - mode: ModeName - accuracy: AccuracyName - helicity_scope: Literal["selected", "total"] - case_id: str - - def as_payload(self) -> dict[str, object]: - return { - "authority": self.authority, - "model": self.model, - "mode": self.mode, - "accuracy": self.accuracy, - "helicity_scope": self.helicity_scope, - "case_id": self.case_id, - "selection_execution": ( - None - if self.helicity_scope == "total" - else selection_execution(self.mode) - ), - } - - -def selection_execution(mode: ModeName) -> SelectionExecution: - """Describe how one recorded helicity is applied in an execution mode.""" - - if mode == "recurrence": - return "generation-specialized" - return "runtime-query-complete-coverage" - - -def comparison_specs() -> tuple[ComparisonSpec, ...]: - """Return the complete required parity and independent-oracle matrix.""" - - selected = catalog_cases(SELECTED_MAX_N_FINAL) - totals = catalog_cases(TOTAL_MAX_N_FINAL) - specs: list[ComparisonSpec] = [] - for model in MODELS: - for mode in MODES: - for accuracy in ACCURACIES: - specs.extend( - ComparisonSpec( - "direct-vs-fft", - model, - mode, - accuracy, - "selected", - case.case_id, - ) - for case in selected - ) - specs.extend( - ComparisonSpec( - "direct-vs-fft", - model, - mode, - "full", - "total", - case.case_id, - ) - for case in totals - ) - for mode in MODES: - specs.extend( - ComparisonSpec( - "frozen-madgraph", - "ufo-sm", - mode, - "full", - "total", - case.case_id, - ) - for case in totals - ) - return tuple(specs) - - -def _fixture_case_ids(fixture: FrozenFullEvidence) -> tuple[str, ...]: - return tuple(case.case.case_id for case in fixture.cases) - - -def dry_run_payload( - fixture_path: Path = DEFAULT_FIXTURE, -) -> dict[str, object]: - """Authenticate all static inputs and describe the non-mutating campaign.""" - - fixture = load_frozen_full_evidence(fixture_path) - selected = catalog_cases(SELECTED_MAX_N_FINAL) - totals = catalog_cases(TOTAL_MAX_N_FINAL) - expected_fixture_ids = tuple(case.case_id for case in totals) - if _fixture_case_ids(fixture) != expected_fixture_ids: - raise FFTAcceptanceError( - "the frozen UFO-SM fixture no longer matches the live n_final<=4 catalog" - ) - specs = comparison_specs() - direct_fft = sum(spec.authority == "direct-vs-fft" for spec in specs) - frozen = sum(spec.authority == "frozen-madgraph" for spec in specs) - return { - "kind": GATE_KIND, - "schema_version": GATE_SCHEMA_VERSION, - "dry_run": True, - "point_policy": { - "generator": "generic_validation_point", - "seed": POINT_SEED, - }, - "comparison_policy": { - "relative_tolerance": canonical_decimal(RELATIVE_TOLERANCE), - "absolute_tolerance": None, - }, - "catalog": { - "source": "tools/performance_report/catalog.py:PROCESS_FAMILIES", - "selected_max_n_final": SELECTED_MAX_N_FINAL, - "selected_case_count_per_model": len(selected), - "total_max_n_final": TOTAL_MAX_N_FINAL, - "total_case_count_per_model": len(totals), - "cases": [ - { - "id": case.case_id, - "family_id": case.family_id, - "family_key": case.family_key, - "n_final": case.n_final, - "process": case.process, - } - for case in selected - ], - }, - "process_set_cache_policy": { - "base_key_axes": [ - "method", - "model", - "mode", - "accuracy", - "helicity_scope", - ], - "selected_partition": ( - "recurrence only: canonical external-helicity-domain signature " - "plus exact discovered tuple" - ), - "selected_execution": { - "recurrence": "generation-specialized", - "on-the-fly": "runtime-query-complete-coverage", - }, - "on_the_fly_complete_coverage": ( - "one ProcessSet per method/model/accuracy, shared by selected " - "runtime queries and FullColour totals" - ), - "discovery": ( - "grouped direct recurrence preferred-selector probes; at most " - "one all-helicity fallback ProcessSet per model/accuracy, only " - "for observed zero rows" - ), - "per_process_generation": False, - }, - "frozen_authority": { - "fixture": str(fixture_path.resolve(strict=True)), - "model": "ufo-sm", - "accuracy": "full", - "max_n_final": TOTAL_MAX_N_FINAL, - "case_count_per_mode": len(fixture.cases), - "madgraph_version": fixture.madgraph_version, - "captured_model_source_sha256": fixture.model_source_sha256, - "captured_driver_sha256": fixture.driver_sha256, - "madgraph_rerun": False, - }, - "comparison_counts": { - "direct_vs_fft": direct_fft, - "frozen_madgraph": frozen, - "total": len(specs), - }, - "comparisons": [spec.as_payload() for spec in specs], - } - - -def _decimal_component(value: object, where: str) -> tuple[Decimal, Decimal]: - if isinstance(value, bool): - raise FFTAcceptanceError(f"{where} must be numeric") - if isinstance(value, Decimal): - real, imaginary = value, Decimal(0) - elif isinstance(value, int): - real, imaginary = Decimal(value), Decimal(0) - else: - try: - number = complex(value) # type: ignore[arg-type] - except (OverflowError, TypeError, ValueError) as error: - raise FFTAcceptanceError(f"{where} must be numeric") from error - if not math.isfinite(number.real) or not math.isfinite(number.imag): - raise FFTAcceptanceError(f"{where} must be finite") - real = Decimal(canonical_decimal(number.real)) - imaginary = Decimal(canonical_decimal(number.imag)) - if not real.is_finite() or not imaginary.is_finite(): - raise FFTAcceptanceError(f"{where} must be finite") - return real, imaginary - - -@dataclass(frozen=True, slots=True) -class StrictRelativeComparison: - candidate_real: Decimal - candidate_imaginary: Decimal - reference_real: Decimal - reference_imaginary: Decimal - difference: Decimal - scale: Decimal - bound: Decimal - passed: bool - - def as_payload(self) -> dict[str, object]: - return { - "candidate": [ - canonical_decimal(self.candidate_real), - canonical_decimal(self.candidate_imaginary), - ], - "reference": [ - canonical_decimal(self.reference_real), - canonical_decimal(self.reference_imaginary), - ], - "difference": canonical_decimal(self.difference), - "scale": canonical_decimal(self.scale), - "bound": canonical_decimal(self.bound), - "passed": self.passed, - } - - -def strict_relative_compare( - candidate: object, - reference: object, - *, - tolerance: Decimal = RELATIVE_TOLERANCE, -) -> StrictRelativeComparison: - """Apply the established scale-relative comparison with no absolute floor.""" - - candidate_real, candidate_imaginary = _decimal_component( - candidate, "candidate matrix element" - ) - reference_real, reference_imaginary = _decimal_component( - reference, "reference matrix element" - ) - if tolerance < 0 or not tolerance.is_finite(): - raise FFTAcceptanceError("relative tolerance must be finite and non-negative") - precision = max( - 80, - *( - len(value.as_tuple().digits) + 20 - for value in ( - candidate_real, - candidate_imaginary, - reference_real, - reference_imaginary, - ) - ), - ) - with localcontext() as context: - context.prec = precision - candidate_magnitude = ( - candidate_real * candidate_real + candidate_imaginary * candidate_imaginary - ).sqrt() - reference_magnitude = ( - reference_real * reference_real + reference_imaginary * reference_imaginary - ).sqrt() - difference = ( - (candidate_real - reference_real) ** 2 - + (candidate_imaginary - reference_imaginary) ** 2 - ).sqrt() - scale = max(candidate_magnitude, reference_magnitude) - bound = tolerance * scale - passed = difference == 0 if scale == 0 else difference <= bound - return StrictRelativeComparison( - candidate_real=candidate_real, - candidate_imaginary=candidate_imaginary, - reference_real=reference_real, - reference_imaginary=reference_imaginary, - difference=difference, - scale=scale, - bound=bound, - passed=passed, - ) - - -@dataclass(frozen=True, slots=True) -class HelicityObservation: - helicity_id: str - values: tuple[int, ...] - structural_zero: bool - matrix_element: object - - -@dataclass(frozen=True, slots=True) -class ChosenHelicity: - observation: HelicityObservation - domains: tuple[tuple[int, ...], ...] - source: Literal["preferred-structural-selector", "largest-nonzero-fallback"] - - @property - def signature(self) -> tuple[tuple[tuple[int, ...], ...], tuple[int, ...]]: - return self.domains, self.observation.values - - -def choose_nonzero_helicity( - observations: Sequence[HelicityObservation], - *, - preferred: Sequence[int], -) -> ChosenHelicity: - """Choose a stable nonzero row, preferring the report selector policy.""" - - rows = tuple(observations) - if not rows: - raise FFTAcceptanceError("helicity discovery returned no physical rows") - width = len(rows[0].values) - if width == 0 or any(len(row.values) != width for row in rows): - raise FFTAcceptanceError("helicity discovery rows have inconsistent width") - if len({row.helicity_id for row in rows}) != len(rows): - raise FFTAcceptanceError("helicity discovery rows have duplicate IDs") - domains = tuple( - tuple(sorted({row.values[index] for row in rows})) for index in range(width) - ) - nonzero = tuple( - row - for row in rows - if not row.structural_zero - and strict_relative_compare(row.matrix_element, 0).scale > 0 - ) - preferred_tuple = tuple(int(value) for value in preferred) - preferred_rows = tuple(row for row in nonzero if row.values == preferred_tuple) - if len(preferred_rows) == 1: - return ChosenHelicity( - preferred_rows[0], domains, "preferred-structural-selector" - ) - if not nonzero: - raise FFTAcceptanceError( - "direct all-helicity oracle found no nonzero physical helicity" - ) - ordered = sorted(nonzero, key=lambda row: (row.values, row.helicity_id)) - selected = max( - ordered, - key=lambda row: strict_relative_compare(row.matrix_element, 0).scale, - ) - return ChosenHelicity(selected, domains, "largest-nonzero-fallback") - - -@dataclass(frozen=True, slots=True) -class SelectionRecord: - model: ModelName - accuracy: AccuracyName - case: CatalogCase - helicity_id: str - values: tuple[int, ...] - domains: tuple[tuple[int, ...], ...] - source: str - discovery_value: object - - @property - def signature(self) -> tuple[tuple[tuple[int, ...], ...], tuple[int, ...]]: - return self.domains, self.values - - @property - def source_mapping(self) -> tuple[tuple[int, int], ...]: - return tuple(enumerate(self.values, start=1)) - - def as_payload(self) -> dict[str, object]: - value_real, value_imaginary = _decimal_component( - self.discovery_value, "discovery matrix element" - ) - return { - "model": self.model, - "accuracy": self.accuracy, - "case_id": self.case.case_id, - "process": self.case.process, - "n_final": self.case.n_final, - "helicity_id": self.helicity_id, - "source_helicities": [list(item) for item in self.source_mapping], - "external_helicity_domains": [list(domain) for domain in self.domains], - "selection_source": self.source, - "discovery_oracle": { - "method": "direct", - "mode": "recurrence", - "value": [ - canonical_decimal(value_real), - canonical_decimal(value_imaginary), - ], - "nonzero": strict_relative_compare(self.discovery_value, 0).scale > 0, - }, - } - - -def _signature_digest( - signature: tuple[tuple[tuple[int, ...], ...], tuple[int, ...]], -) -> str: - domains, values = signature - encoded = json.dumps( - {"domains": domains, "values": values}, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return hashlib.sha256(encoded).hexdigest()[:16] - - -@dataclass(frozen=True, slots=True) -class SelectedGroup: - signature: tuple[tuple[tuple[int, ...], ...], tuple[int, ...]] - cases: tuple[CatalogCase, ...] - - @property - def scope(self) -> str: - return f"selected-{_signature_digest(self.signature)}" - - @property - def source_mapping(self) -> tuple[tuple[int, int], ...]: - return tuple(enumerate(self.signature[1], start=1)) - - -def group_selected_cases( - cases: Sequence[CatalogCase], - selections: Mapping[str, SelectionRecord], -) -> tuple[SelectedGroup, ...]: - """Partition a selected scope by domain and exact discovered tuple.""" - - grouped: OrderedDict[ - tuple[tuple[tuple[int, ...], ...], tuple[int, ...]], list[CatalogCase] - ] = OrderedDict() - for case in cases: - try: - selection = selections[case.case_id] - except KeyError as error: - raise FFTAcceptanceError( - f"missing discovered helicity for {case.case_id}" - ) from error - if selection.case != case: - raise FFTAcceptanceError( - f"discovered helicity identity differs for {case.case_id}" - ) - grouped.setdefault(selection.signature, []).append(case) - return tuple( - SelectedGroup(signature, tuple(group_cases)) - for signature, group_cases in grouped.items() - ) - - -@dataclass(frozen=True, slots=True) -class ArtifactKey: - method: MethodName - model: ModelName - mode: ModeName - accuracy: AccuracyName - helicity_scope: str - - @property - def slug(self) -> str: - method = "fft" if self.method == "symmetric-group-fft" else "direct" - mode = self.mode.replace("-", "_") - return "-".join((method, self.model, mode, self.accuracy, self.helicity_scope)) - - def as_payload(self) -> dict[str, str]: - return { - "method": self.method, - "model": self.model, - "mode": self.mode, - "accuracy": self.accuracy, - "helicity_scope": self.helicity_scope, - } - - -@dataclass(frozen=True, slots=True) -class GroupRequest: - key: ArtifactKey - cases: tuple[CatalogCase, ...] - selected_source_helicities: tuple[tuple[int, int], ...] | None = None - external_helicity_domains: tuple[tuple[int, ...], ...] | None = None - - def __post_init__(self) -> None: - if not self.cases: - raise ValueError("a ProcessSet group must not be empty") - if len({case.case_id for case in self.cases}) != len(self.cases): - raise ValueError("a ProcessSet group contains duplicate cases") - selected = self.selected_source_helicities - domains = self.external_helicity_domains - if (selected is None) != (domains is None): - raise ValueError("selected source tuples and domains must be paired") - if selected is not None: - if self.key.mode == "on-the-fly": - raise ValueError( - "on-the-fly ProcessSets must retain complete helicity coverage" - ) - if tuple(label for label, _value in selected) != tuple( - range(1, len(selected) + 1) - ): - raise ValueError("selected source labels must be dense and one-based") - if domains is None or len(domains) != len(selected): - raise ValueError("selected source tuple and domain widths differ") - for (label, value), domain in zip(selected, domains, strict=True): - if value not in domain: - raise ValueError( - f"selected helicity {value} for label {label} is outside " - f"its domain {domain!r}" - ) - - def as_payload(self) -> dict[str, object]: - return { - "boundary": self.key.as_payload(), - "helicity_generation_contract": ( - "complete-coverage" - if self.selected_source_helicities is None - else "generation-specialized" - ), - "case_count": len(self.cases), - "case_ids": [case.case_id for case in self.cases], - "selected_source_helicities": ( - None - if self.selected_source_helicities is None - else [list(item) for item in self.selected_source_helicities] - ), - "external_helicity_domains": ( - None - if self.external_helicity_domains is None - else [list(item) for item in self.external_helicity_domains] - ), - } - - -def otf_complete_group_request( - *, - method: MethodName, - model: ModelName, - accuracy: AccuracyName, - cases: Sequence[CatalogCase], -) -> GroupRequest: - """Build the single reusable OTF helicity-coverage boundary for one lane.""" - - return GroupRequest( - ArtifactKey( - method, - model, - "on-the-fly", - accuracy, - "complete-helicity-runtime-query-and-total", - ), - tuple(cases), - ) - - -RecordT = TypeVar("RecordT") - - -class ProcessSetCache(Generic[RecordT]): - """Memoize one builder call per exact method/model/mode/scope boundary.""" - - def __init__(self, builder: Callable[[GroupRequest], RecordT]) -> None: - self._builder = builder - self._requests: dict[ArtifactKey, GroupRequest] = {} - self._records: dict[ArtifactKey, RecordT] = {} - self._generation_order: list[ArtifactKey] = [] - - def get(self, request: GroupRequest) -> RecordT: - previous = self._requests.get(request.key) - if previous is not None: - if previous != request: - raise FFTAcceptanceError( - "a ProcessSet cache boundary was reused with a different case " - f"or helicity scope: {request.key.slug}" - ) - return self._records[request.key] - record = self._builder(request) - self._requests[request.key] = request - self._records[request.key] = record - self._generation_order.append(request.key) - return record - - @property - def generation_count(self) -> int: - return len(self._generation_order) - - @property - def entries(self) -> tuple[tuple[GroupRequest, RecordT], ...]: - return tuple( - (self._requests[key], self._records[key]) for key in self._generation_order - ) - - -@dataclass(frozen=True, slots=True) -class ArtifactRecord: - request: GroupRequest - path: Path - - -def _run_config(request: GroupRequest) -> object: - from pyamplicol.config import ( - Action, - ColorAccuracy, - ColorConfig, - ColorContraction, - EvaluatorConfig, - EvaluatorExecutionMode, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationRelationDiscoveryConfig, - GenerationValidationConfig, - JITConfig, - ProcessConfig, - RelationDiscoveryMode, - RunConfig, - ) - - selected = request.selected_source_helicities or () - return RunConfig( - action=Action.GENERATE, - process=ProcessConfig( - selected_source_helicities={str(label): value for label, value in selected} - ), - color=ColorConfig( - accuracy=ColorAccuracy(request.key.accuracy), - contraction=ColorContraction(request.key.method), - ), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - validation=GenerationValidationConfig( - enabled=False, - post_build_validation=False, - ), - relation_discovery=GenerationRelationDiscoveryConfig( - mode=RelationDiscoveryMode.OFF - ), - ), - evaluator=EvaluatorConfig( - execution_mode=EvaluatorExecutionMode(request.key.mode), - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=2), - ), - ) - - -class NativeArtifactBuilder: - """Generate and authenticate one grouped native ProcessSet artifact.""" - - def __init__( - self, - artifact_root: Path, - *, - models: Mapping[ModelName, object | None], - ) -> None: - self.artifact_root = artifact_root - self.models = models - self.artifact_root.mkdir(parents=True, exist_ok=False) - - def __call__(self, request: GroupRequest) -> ArtifactRecord: - from pyamplicol import Generator, ProcessSet - - path = self.artifact_root / request.key.slug - process_set = ProcessSet.from_expressions( - (case.process for case in request.cases), - names=tuple(case.artifact_name for case in request.cases), - ) - Generator(_run_config(request)).generate( - process_set, - path, - model=self.models[request.key.model], # type: ignore[arg-type] - ) - self._validate(path, request) - return ArtifactRecord(request=request, path=path) - - @staticmethod - def _validate(path: Path, request: GroupRequest) -> None: - from pyamplicol.artifacts import inspect_artifact - - try: - effective = tomllib.loads( - (path / "config" / "effective.toml").read_text(encoding="utf-8") - ) - observed_lane = ( - str(cast(Mapping[str, object], effective["color"])["accuracy"]), - str(cast(Mapping[str, object], effective["color"])["contraction"]), - str( - cast(Mapping[str, object], effective["evaluator"])["execution_mode"] - ), - ) - except (KeyError, OSError, TypeError, tomllib.TOMLDecodeError) as error: - raise FFTAcceptanceError( - f"artifact {request.key.slug} has no valid effective config" - ) from error - expected_lane = ( - request.key.accuracy, - request.key.method, - request.key.mode, - ) - if observed_lane != expected_lane: - raise FFTAcceptanceError( - f"artifact {request.key.slug} effective lane is {observed_lane!r}; " - f"expected {expected_lane!r}" - ) - - inspection = inspect_artifact(path) - cases_by_name = {case.artifact_name: case for case in request.cases} - public_names: set[str] = set() - for process in inspection.processes: - process_names = (process.id, *(alias.id for alias in process.aliases)) - public_names.update(process_names) - unknown_names = tuple( - name for name in process_names if name not in cases_by_name - ) - if unknown_names: - raise FFTAcceptanceError( - f"artifact {request.key.slug} contains unknown public process " - f"names {unknown_names!r}" - ) - if process.color_accuracy != request.key.accuracy: - raise FFTAcceptanceError( - f"artifact {request.key.slug} contains the wrong color accuracy" - ) - if process.execution_mode != request.key.mode: - raise FFTAcceptanceError( - f"artifact {request.key.slug} contains the wrong execution mode" - ) - expected_methods = { - _expected_inspection_method(request.key.method, cases_by_name[name]) - for name in process_names - } - if len(expected_methods) != 1: - raise FFTAcceptanceError( - f"artifact {request.key.slug} aliases processes with different " - "symmetric-group eligibility" - ) - expected_method = expected_methods.pop() - method = process.recurrence_color_contraction_method - if method != expected_method: - raise FFTAcceptanceError( - f"artifact {request.key.slug} carries inspection method " - f"{method!r}; expected {expected_method!r} for public " - f"processes {process_names!r}" - ) - if request.selected_source_helicities is None: - if process.selected_source_helicities: - raise FFTAcceptanceError( - f"all-helicity artifact {request.key.slug} is specialized" - ) - if ( - process.helicity_coverage != "complete" - or "helicity" in process.generation_specialized_axes - ): - raise FFTAcceptanceError( - f"all-helicity artifact {request.key.slug} does not retain " - "complete reusable helicity coverage" - ) - elif ( - process.helicity_coverage != "selected" - or "helicity" not in process.generation_specialized_axes - ): - raise FFTAcceptanceError( - f"selected artifact {request.key.slug} is not " - "generation-specialized" - ) - expected_names = {case.artifact_name for case in request.cases} - if public_names != expected_names: - raise FFTAcceptanceError( - f"artifact {request.key.slug} public process names differ: " - f"missing={sorted(expected_names - public_names)!r}, " - f"extra={sorted(public_names - expected_names)!r}" - ) - - -def _runtime_points(case: CatalogCase) -> tuple[tuple[tuple[float, ...], ...], ...]: - return ( - tuple( - tuple(float(component) for component in momentum) - for momentum in validation_momenta(case.process) - ), - ) - - -def _preferred_structural_selection( - case: CatalogCase, - *, - model: ModelName, - accuracy: AccuracyName, -) -> SelectionRecord: - """Build the existing deterministic selector without all-helicity generation.""" - - from pyamplicol.models.builtin.process_ir import build_process_ir - - process = build_process_ir(case.process, color_accuracy=accuracy) - pdgs = tuple(int(leg.pdg) for leg in process.legs if leg.pdg is not None) - if len(pdgs) != case.n_final + 2: - raise FFTAcceptanceError( - f"{case.case_id} structural selector has the wrong external width" - ) - values = fixed_selector_helicity(pdgs) - domains = tuple(_preferred_helicities(pdg) for pdg in pdgs) - if any(value not in domain for value, domain in zip(values, domains, strict=True)): - raise FFTAcceptanceError( - f"{case.case_id} structural selector is outside its physical domain" - ) - return SelectionRecord( - model=model, - accuracy=accuracy, - case=case, - helicity_id=selector_helicity_id(values), - values=values, - domains=domains, - source="preferred-structural-selector", - discovery_value=0, - ) - - -def _validate_runtime_lane(runtime: object, key: ArtifactKey) -> None: - if getattr(runtime, "execution_mode", None) != key.mode: - raise FFTAcceptanceError( - f"runtime {key.slug} loaded with the wrong execution mode" - ) - physics = getattr(runtime, "physics", None) - if getattr(physics, "color_accuracy", None) != key.accuracy: - raise FFTAcceptanceError(f"runtime {key.slug} loaded with the wrong accuracy") - - -def _discover_case_selection( - record: ArtifactRecord, - case: CatalogCase, -) -> SelectionRecord: - from pyamplicol import Runtime - - runtime = Runtime.load(record.path, process=case.artifact_name) - try: - _validate_runtime_lane(runtime, record.request.key) - resolved = runtime.evaluate_resolved(_runtime_points(case)) - physics = runtime.physics - helicities = tuple(physics.helicities) - if resolved.helicity_ids != tuple(item.id for item in helicities): - raise FFTAcceptanceError( - f"{case.case_id} discovery resolved helicity order is inconsistent" - ) - if resolved.color_accuracy != record.request.key.accuracy: - raise FFTAcceptanceError( - f"{case.case_id} discovery resolved the wrong color accuracy" - ) - if len(resolved.values) != 1 or any( - len(color_values) != 1 for color_values in resolved.values[0] - ): - raise FFTAcceptanceError( - f"{case.case_id} discovery did not return one contracted color value" - ) - particles = tuple(physics.external_particles) - preferred = fixed_selector_helicity( - tuple(int(particle.pdg_id) for particle in particles) - ) - chosen = choose_nonzero_helicity( - tuple( - HelicityObservation( - helicity_id=helicity.helicity_id - if hasattr(helicity, "helicity_id") - else helicity.id, - values=tuple(int(value) for value in helicity.values), - structural_zero=bool(helicity.structural_zero), - matrix_element=resolved.values[0][index][0], - ) - for index, helicity in enumerate(helicities) - ), - preferred=preferred, - ) - return SelectionRecord( - model=record.request.key.model, - accuracy=record.request.key.accuracy, - case=case, - helicity_id=chosen.observation.helicity_id, - values=chosen.observation.values, - domains=chosen.domains, - source=chosen.source, - discovery_value=chosen.observation.matrix_element, - ) - finally: - runtime.clear() - - -def _evaluate_scalar( - record: ArtifactRecord, - case: CatalogCase, - *, - selection: SelectionRecord | None, - active_family_census: dict[str, object] | None = None, -) -> object: - from pyamplicol import Runtime - - runtime = Runtime.load(record.path, process=case.artifact_name) - try: - _validate_runtime_lane(runtime, record.request.key) - selected_helicity_ids: tuple[str, ...] | None = None - if selection is not None: - if selection.case != case: - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} received a selection " - "for a different process" - ) - if ( - selection.model != record.request.key.model - or selection.accuracy != record.request.key.accuracy - ): - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} received a selection " - "from a different model or accuracy lane" - ) - physical = tuple(runtime.physics.helicities) - observed = tuple( - tuple(int(value) for value in item.values) for item in physical - ) - if record.request.key.mode == "recurrence": - if observed != (selection.values,): - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} exposes selected " - f"helicities {observed!r}; expected {(selection.values,)!r}" - ) - if runtime.physics.helicity_coverage != "selected": - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} is not " - "generation-selected" - ) - else: - if ( - record.request.selected_source_helicities is not None - or runtime.physics.helicity_coverage != "complete" - ): - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} is not a " - "complete-coverage on-the-fly runtime" - ) - matches = tuple( - item for item in physical if tuple(item.values) == selection.values - ) - if len(matches) != 1: - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} exposes " - f"{len(matches)} rows for recorded tuple {selection.values!r}" - ) - observed_id = str(matches[0].id) - if observed_id != selection.helicity_id: - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} maps recorded " - f"tuple to {observed_id!r}; expected {selection.helicity_id!r}" - ) - selected_helicity_ids = (observed_id,) - values = runtime.evaluate( - _runtime_points(case), - helicities=selected_helicity_ids, - ) - if len(values) != 1: - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} returned {len(values)} " - "matrix elements for one point" - ) - if active_family_census is not None: - if record.request.key.mode != "on-the-fly": - raise FFTAcceptanceError( - "active-family census capture requires an on-the-fly runtime" - ) - if active_family_census: - raise FFTAcceptanceError( - "active-family census capture destination must start empty" - ) - inspect = getattr(runtime, "inspect", None) - if not callable(inspect): - raise FFTAcceptanceError( - f"{case.case_id}/{record.request.key.slug} has no runtime " - "inspection" - ) - inspection = _mapping( - inspect(), - f"{case.case_id}/{record.request.key.slug} runtime inspection", - ) - state = _mapping( - inspection.get("on_the_fly_state"), - f"{case.case_id}/{record.request.key.slug} on-the-fly state", - ) - active = _mapping( - state.get("active_family_union_census"), - f"{case.case_id}/{record.request.key.slug} active-family census", - ) - active_family_census.update(active) - return values[0] - finally: - runtime.clear() - - -class NativeAcceptanceHarness: - """Run the complete opt-in matrix with grouped ProcessSet generation.""" - - def __init__( - self, - run_root: Path, - *, - fixture: FrozenFullEvidence, - fixture_path: Path, - ) -> None: - self.run_root = run_root - self.fixture = fixture - self.fixture_path = fixture_path - self.selected_cases = catalog_cases(SELECTED_MAX_N_FINAL) - self.total_cases = catalog_cases(TOTAL_MAX_N_FINAL) - self.comparisons: list[dict[str, object]] = [] - self.selections: dict[tuple[ModelName, AccuracyName, str], SelectionRecord] = {} - self._values: dict[ - tuple[Path, str, tuple[str, tuple[int, ...]] | None], object - ] = {} - self._reflection_censuses: dict[ - tuple[str, MethodName], dict[str, object] - ] = {} - - for frozen in fixture.cases: - if frozen.momenta != validation_momenta(frozen.case.process): - raise FFTAcceptanceError( - f"frozen case {frozen.case.case_id} differs from its current " - "generic_validation_point(seed=101)" - ) - - models: dict[ModelName, object | None] = { - "built-in-sm": None, - "ufo-sm": prepare_ufo_sm_model(run_root / "prepared-ufo-sm"), - } - builder = NativeArtifactBuilder(run_root / "artifacts", models=models) - self.cache: ProcessSetCache[ArtifactRecord] = ProcessSetCache(builder) - - def _discover_selections( - self, - ) -> tuple[ - dict[tuple[ModelName, AccuracyName, str], ArtifactRecord], - frozenset[tuple[ModelName, AccuracyName]], - ]: - """Probe the cheap structural tuple and expand only observed zeros.""" - - probe_records: dict[tuple[ModelName, AccuracyName, str], ArtifactRecord] = {} - fallback_scopes: set[tuple[ModelName, AccuracyName]] = set() - for model in MODELS: - for accuracy in ACCURACIES: - preferred = { - case.case_id: _preferred_structural_selection( - case, - model=model, - accuracy=accuracy, - ) - for case in self.selected_cases - } - zero_cases: list[CatalogCase] = [] - for group in group_selected_cases(self.selected_cases, preferred): - request = GroupRequest( - ArtifactKey( - "direct", - model, - "recurrence", - accuracy, - f"preferred-probe-{_signature_digest(group.signature)}", - ), - group.cases, - selected_source_helicities=group.source_mapping, - external_helicity_domains=group.signature[0], - ) - record = self.cache.get(request) - for case in group.cases: - candidate = preferred[case.case_id] - value = self._value(record, case, selection=candidate) - probe_records[(model, accuracy, case.case_id)] = record - if strict_relative_compare(value, 0).scale == 0: - zero_cases.append(case) - continue - self.selections[(model, accuracy, case.case_id)] = ( - SelectionRecord( - model=model, - accuracy=accuracy, - case=case, - helicity_id=candidate.helicity_id, - values=candidate.values, - domains=candidate.domains, - source="preferred-structural-selector", - discovery_value=value, - ) - ) - if not zero_cases: - continue - fallback_scopes.add((model, accuracy)) - fallback_request = GroupRequest( - ArtifactKey( - "direct", - model, - "recurrence", - accuracy, - "all-helicity-fallback-discovery", - ), - tuple(zero_cases), - ) - fallback_record = self.cache.get(fallback_request) - for case in zero_cases: - selection = _discover_case_selection(fallback_record, case) - if selection.values == preferred[case.case_id].values: - raise FFTAcceptanceError( - f"{case.case_id} fallback discovery retained the zero " - "preferred tuple" - ) - self.selections[(model, accuracy, case.case_id)] = selection - return probe_records, frozenset(fallback_scopes) - - def _selected_artifacts( - self, - probe_records: Mapping[tuple[ModelName, AccuracyName, str], ArtifactRecord], - fallback_scopes: frozenset[tuple[ModelName, AccuracyName]], - ) -> dict[ - tuple[ModelName, ModeName, AccuracyName, MethodName, str], ArtifactRecord - ]: - records: dict[ - tuple[ModelName, ModeName, AccuracyName, MethodName, str], ArtifactRecord - ] = {} - for model in MODELS: - for accuracy in ACCURACIES: - selections = { - case.case_id: self.selections[(model, accuracy, case.case_id)] - for case in self.selected_cases - } - groups = group_selected_cases(self.selected_cases, selections) - for method in METHODS: - for group in groups: - if ( - method == "direct" - and (model, accuracy) not in fallback_scopes - ): - for case in group.cases: - records[ - ( - model, - "recurrence", - accuracy, - method, - case.case_id, - ) - ] = probe_records[(model, accuracy, case.case_id)] - continue - request = GroupRequest( - ArtifactKey( - method, - model, - "recurrence", - accuracy, - group.scope, - ), - group.cases, - selected_source_helicities=group.source_mapping, - external_helicity_domains=group.signature[0], - ) - record = self.cache.get(request) - for case in group.cases: - records[ - ( - model, - "recurrence", - accuracy, - method, - case.case_id, - ) - ] = record - - otf_record = self.cache.get( - otf_complete_group_request( - method=method, - model=model, - accuracy=accuracy, - cases=self.selected_cases, - ) - ) - for case in self.selected_cases: - records[ - ( - model, - "on-the-fly", - accuracy, - method, - case.case_id, - ) - ] = otf_record - return records - - def _total_artifacts( - self, - selected: Mapping[ - tuple[ModelName, ModeName, AccuracyName, MethodName, str], - ArtifactRecord, - ], - ) -> dict[tuple[ModelName, ModeName, MethodName], ArtifactRecord]: - records: dict[tuple[ModelName, ModeName, MethodName], ArtifactRecord] = {} - for model in MODELS: - for mode in MODES: - for method in METHODS: - if mode == "on-the-fly": - otf_records = tuple( - selected[(model, mode, "full", method, case.case_id)] - for case in self.selected_cases - ) - if len({record.path for record in otf_records}) != 1: - raise FFTAcceptanceError( - "on-the-fly selected queries do not share one " - "complete-coverage ProcessSet" - ) - record = otf_records[0] - if ( - record.request.selected_source_helicities is not None - or not {case.case_id for case in self.total_cases} - <= {case.case_id for case in record.request.cases} - ): - raise FFTAcceptanceError( - "on-the-fly FullColour totals cannot reuse the " - "complete selected-query ProcessSet" - ) - records[(model, mode, method)] = record - continue - request = GroupRequest( - ArtifactKey( - method, - model, - mode, - "full", - "all-helicity-total", - ), - self.total_cases, - ) - records[(model, mode, method)] = self.cache.get(request) - return records - - def _value( - self, - record: ArtifactRecord, - case: CatalogCase, - *, - selection: SelectionRecord | None, - ) -> object: - selection_key = ( - None if selection is None else (selection.helicity_id, selection.values) - ) - key = (record.path, case.case_id, selection_key) - existing = self._values.get(key) - if existing is not None: - return existing - artifact_key = record.request.key - census_key = ( - (case.case_id, artifact_key.method) - if ( - selection is not None - and case.case_id - in { - _PURE_ADJOINT_REFLECTION_CASE_ID, - _OPEN_LINE_REFLECTION_CASE_ID, - } - and artifact_key.model == "built-in-sm" - and artifact_key.mode == "on-the-fly" - and artifact_key.accuracy == "full" - and artifact_key.helicity_scope - == "complete-helicity-runtime-query-and-total" - and record.request.selected_source_helicities is None - ) - else None - ) - active_family_census: dict[str, object] | None = ( - {} if census_key is not None else None - ) - if active_family_census is None: - value = _evaluate_scalar(record, case, selection=selection) - else: - value = _evaluate_scalar( - record, - case, - selection=selection, - active_family_census=active_family_census, - ) - if census_key is not None: - if active_family_census is None: - raise FFTAcceptanceError( - f"production census capture was not initialized for {census_key!r}" - ) - previous = self._reflection_censuses.setdefault( - census_key, - active_family_census, - ) - if previous != active_family_census: - raise FFTAcceptanceError( - f"production active-family census changed for {census_key!r}" - ) - self._values[key] = value - return value - - def _validated_reflection_census(self) -> dict[str, object]: - def required(case_id: str, method: MethodName) -> Mapping[str, object]: - try: - return self._reflection_censuses[(case_id, method)] - except KeyError as error: - raise FFTAcceptanceError( - "the 574-comparison campaign did not evaluate the required " - f"built-in-SM/full/on-the-fly selected census {case_id}/{method}" - ) from error - - return validate_on_the_fly_reflection_census( - pure_adjoint_direct=required( - _PURE_ADJOINT_REFLECTION_CASE_ID, - "direct", - ), - pure_adjoint_fft=required( - _PURE_ADJOINT_REFLECTION_CASE_ID, - "symmetric-group-fft", - ), - open_line_direct=required( - _OPEN_LINE_REFLECTION_CASE_ID, - "direct", - ), - open_line_fft=required( - _OPEN_LINE_REFLECTION_CASE_ID, - "symmetric-group-fft", - ), - ) - - def _record_direct_fft( - self, - *, - model: ModelName, - mode: ModeName, - accuracy: AccuracyName, - scope: Literal["selected", "total"], - case: CatalogCase, - direct_record: ArtifactRecord, - fft_record: ArtifactRecord, - selection: SelectionRecord | None, - ) -> None: - direct = self._value(direct_record, case, selection=selection) - fft = self._value(fft_record, case, selection=selection) - comparison = strict_relative_compare(fft, direct) - direct_nonzero = ( - strict_relative_compare(direct, 0).scale > 0 - if selection is not None - else None - ) - self.comparisons.append( - { - "authority": "direct-vs-fft", - "model": model, - "mode": mode, - "accuracy": accuracy, - "helicity_scope": scope, - "case_id": case.case_id, - "n_final": case.n_final, - "selection": ( - None - if selection is None - else { - "helicity_id": selection.helicity_id, - "source_helicities": [ - list(item) for item in selection.source_mapping - ], - "execution": selection_execution(mode), - "artifact_helicity_coverage": ( - "selected" if mode == "recurrence" else "complete" - ), - "direct_nonzero": direct_nonzero, - } - ), - "comparison": comparison.as_payload(), - "passed": comparison.passed and direct_nonzero is not False, - } - ) - - def _record_frozen( - self, - *, - mode: ModeName, - case: CatalogCase, - fft_record: ArtifactRecord, - ) -> None: - frozen = self.fixture.case(case.case_id) - candidate = self._value(fft_record, case, selection=None) - comparison = strict_relative_compare(candidate, frozen.expected_full) - self.comparisons.append( - { - "authority": "frozen-madgraph", - "model": "ufo-sm", - "mode": mode, - "accuracy": "full", - "helicity_scope": "total", - "case_id": case.case_id, - "n_final": case.n_final, - "fixture": str(self.fixture_path), - "comparison": comparison.as_payload(), - "passed": comparison.passed, - } - ) - - def run(self) -> dict[str, object]: - probe_records, fallback_scopes = self._discover_selections() - selected = self._selected_artifacts(probe_records, fallback_scopes) - totals = self._total_artifacts(selected) - - for model in MODELS: - for mode in MODES: - for accuracy in ACCURACIES: - for case in self.selected_cases: - selection = self.selections[(model, accuracy, case.case_id)] - self._record_direct_fft( - model=model, - mode=mode, - accuracy=accuracy, - scope="selected", - case=case, - direct_record=selected[ - (model, mode, accuracy, "direct", case.case_id) - ], - fft_record=selected[ - ( - model, - mode, - accuracy, - "symmetric-group-fft", - case.case_id, - ) - ], - selection=selection, - ) - for case in self.total_cases: - self._record_direct_fft( - model=model, - mode=mode, - accuracy="full", - scope="total", - case=case, - direct_record=totals[(model, mode, "direct")], - fft_record=totals[(model, mode, "symmetric-group-fft")], - selection=None, - ) - - for mode in MODES: - for case in self.total_cases: - self._record_frozen( - mode=mode, - case=case, - fft_record=totals[("ufo-sm", mode, "symmetric-group-fft")], - ) - - expected = comparison_specs() - if len(self.comparisons) != len(expected): - raise FFTAcceptanceError( - f"campaign produced {len(self.comparisons)} comparisons; " - f"expected {len(expected)}" - ) - reflection_census = self._validated_reflection_census() - accepted = all(bool(item["passed"]) for item in self.comparisons) - cache_payload: list[dict[str, object]] = [] - for request, record in self.cache.entries: - entry = request.as_payload() - entry["artifact"] = str(record.path.relative_to(self.run_root)) - entry["generation_count"] = 1 - cache_payload.append(entry) - return { - "kind": GATE_KIND, - "schema_version": GATE_SCHEMA_VERSION, - "accepted": accepted, - "point_policy": { - "generator": "generic_validation_point", - "seed": POINT_SEED, - }, - "comparison_policy": { - "relative_tolerance": canonical_decimal(RELATIVE_TOLERANCE), - "absolute_tolerance": None, - }, - "on_the_fly_reflection_census": reflection_census, - "catalog": { - "source": "tools/performance_report/catalog.py:PROCESS_FAMILIES", - "selected_max_n_final": SELECTED_MAX_N_FINAL, - "selected_case_count_per_model": len(self.selected_cases), - "total_max_n_final": TOTAL_MAX_N_FINAL, - "total_case_count_per_model": len(self.total_cases), - }, - "frozen_authority": { - "fixture": str(self.fixture_path), - "madgraph_version": self.fixture.madgraph_version, - "captured_model_source_sha256": (self.fixture.model_source_sha256), - "captured_driver_sha256": self.fixture.driver_sha256, - "madgraph_rerun": False, - }, - "process_set_cache": { - "generation_count": self.cache.generation_count, - "per_process_generation": False, - "selected_execution": { - "recurrence": "generation-specialized", - "on-the-fly": "runtime-query-complete-coverage", - }, - "on_the_fly_total_reuses_complete_selected_query_artifact": True, - "entries": cache_payload, - }, - "selections": [ - self.selections[key].as_payload() for key in sorted(self.selections) - ], - "comparisons": self.comparisons, - "comparison_counts": { - "direct_vs_fft": sum( - item["authority"] == "direct-vs-fft" for item in self.comparisons - ), - "frozen_madgraph": sum( - item["authority"] == "frozen-madgraph" for item in self.comparisons - ), - "total": len(self.comparisons), - }, - } - - -def _fresh_run_root(output_root: Path) -> Path: - resolved = output_root.expanduser().resolve(strict=False) - if not resolved.is_relative_to(ROOT): - raise FFTAcceptanceError("acceptance output must remain inside the workspace") - resolved.mkdir(parents=True, exist_ok=True) - stamp = datetime.now(UTC).strftime("%Y%m%dT%H%M%SZ") - run_root = resolved / f"run-{stamp}-{uuid.uuid4().hex[:10]}" - run_root.mkdir() - return run_root - - -def _write_report(payload: Mapping[str, object], path: Path) -> None: - encoded = ( - json.dumps( - payload, - ensure_ascii=True, - indent=2, - sort_keys=False, - allow_nan=False, - ) - + "\n" - ) - with path.open("x", encoding="ascii", newline="\n") as stream: - stream.write(encoded) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--fixture", - type=Path, - default=DEFAULT_FIXTURE, - help="tracked UFO-SM seed-101 numerical fixture", - ) - parser.add_argument( - "--output-root", - type=Path, - default=ROOT / ".artifacts" / "fft-numerical-acceptance", - help="workspace-local parent for one fresh campaign directory", - ) - parser.add_argument( - "--dry-run", - action="store_true", - help="authenticate inputs and print the comparison plan without writes", - ) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - args = _parser().parse_args(argv) - fixture_path = args.fixture.expanduser().resolve(strict=True) - if args.dry_run: - print( - json.dumps( - dry_run_payload(fixture_path), - ensure_ascii=True, - indent=2, - allow_nan=False, - ) - ) - return 0 - - fixture = load_frozen_full_evidence(fixture_path) - if _fixture_case_ids(fixture) != tuple( - case.case_id for case in catalog_cases(TOTAL_MAX_N_FINAL) - ): - raise FFTAcceptanceError( - "the frozen UFO-SM fixture no longer matches the live n_final<=4 catalog" - ) - run_root = _fresh_run_root(args.output_root) - payload = NativeAcceptanceHarness( - run_root, - fixture=fixture, - fixture_path=fixture_path, - ).run() - report = run_root / "report.json" - _write_report(payload, report) - print(report) - if not payload["accepted"]: - raise FFTAcceptanceMismatch( - f"FFT numerical acceptance failed; complete report: {report}" - ) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_results_summary_pdf.py b/pyamplicol/tools/developer/fft_results_summary_pdf.py deleted file mode 100644 index 88909c8083..0000000000 --- a/pyamplicol/tools/developer/fft_results_summary_pdf.py +++ /dev/null @@ -1,557 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Assemble the published FullColor scaling plots into one summary PDF.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -try: - from reportlab.lib.pagesizes import A4, landscape - from reportlab.lib.utils import ImageReader - from reportlab.pdfbase import pdfmetrics - from reportlab.pdfgen import canvas -except ModuleNotFoundError as error: # pragma: no cover - environment dependent - raise SystemExit( - "fft_results_summary_pdf.py requires reportlab; use the bundled " - "Codex PDF runtime or install reportlab" - ) from error - - -ROOT = Path(__file__).resolve().parents[2] -RESULTS = ROOT / "IMPLEMENTATION_DOCS" / "RESULTS" -FINAL_REPORT = ( - RESULTS - / "fft-scaling-study" - / "data" - / "campaign-report-scalar-selected-n2-n9-final.json" -) -PLOT_MANIFEST_NAME = "plot-manifest.json" -PLOT_DATA_NAME = "plot-data.json" -PLOT_FILENAMES = ( - "fullcolor-gg-generation.png", - "fullcolor-gg-warm-runtime.png", - "fullcolor-gg-rss.png", - "fullcolor-ddbar-generation.png", - "fullcolor-ddbar-warm-runtime.png", - "fullcolor-ddbar-rss.png", -) - - -@dataclass(frozen=True, slots=True) -class PlotPage: - section: str - path: Path - - -def _plot_pages( - plot_directory: Path | None = None, - *, - helicity_workload: str = "fixed", -) -> tuple[PlotPage, ...]: - if helicity_workload not in {"fixed", "sum"}: - raise ValueError("helicity_workload must be 'fixed' or 'sum'") - plot_root = RESULTS / "fft-scaling-study" / "plots" - return tuple( - PlotPage( - ( - "Current-host fixed-helicity comparison (n=2..9)" - if helicity_workload == "fixed" - else "Current-host helicity-summed comparison (n=2..9)" - ), - ( - plot_root - / ( - "scalar-selected-n2-n9-final" - if helicity_workload == "fixed" - else "scalar-helicity-sum-n2-n9-final" - ) - if plot_directory is None - else plot_directory - ) - / name, - ) - for name in PLOT_FILENAMES - ) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--output", - type=Path, - default=RESULTS / "summary_plots_final.pdf", - help=( - "output PDF (default: IMPLEMENTATION_DOCS/RESULTS/summary_plots_final.pdf)" - ), - ) - parser.add_argument( - "--campaign-report", - type=Path, - default=FINAL_REPORT, - help=( - "report supplying FFT and helicity-coverage provenance for the PDF header" - ), - ) - parser.add_argument( - "--plot-directory", - type=Path, - help=( - "directory containing the six plot PNGs (default: published final " - "plot directory)" - ), - ) - return parser - - -def _mapping(value: object, *, context: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise ValueError(f"{context} must be an object") - return value - - -def _campaign_note(report: Mapping[str, Any]) -> str: - policy = _mapping(report.get("policy"), context="campaign policy") - if policy.get("fft_enabled") is not True: - raise ValueError("campaign policy must record fft_enabled=true") - contractions = _mapping( - policy.get("selected_pyamplicol_color_contractions"), - context="selected pyAmpliCol color contractions", - ) - expected_contractions = {"direct", "symmetric-group-fft"} - for execution_mode in ("recurrence", "on-the-fly"): - raw = contractions.get(execution_mode) - selected = ( - {str(contraction) for contraction in raw} - if isinstance(raw, Sequence) and not isinstance(raw, str) - else set() - ) - if selected != expected_contractions: - raise ValueError( - "campaign policy must select direct and symmetric-group FFT for " - f"{execution_mode}" - ) - measurement = _mapping( - policy.get("measurement"), context="campaign measurement policy" - ) - if measurement.get("generation_helicity_coverage") != "all": - raise ValueError( - "campaign policy must record generation_helicity_coverage='all'" - ) - helicity_workload = _campaign_helicity_workload(policy, measurement) - batch_size = measurement.get("warm_benchmark_batch_size") - if ( - not isinstance(batch_size, int) - or isinstance(batch_size, bool) - or batch_size < 1 - ): - raise ValueError( - "campaign policy must record a positive warm_benchmark_batch_size" - ) - _validate_campaign_cell_workloads(report, helicity_workload) - if measurement.get("compiled_fft_enabled") is not False: - raise ValueError("campaign policy must record compiled_fft_enabled=false") - if helicity_workload == "fixed": - note = ( - "--fft | recurrence: persisted all-helicity physical schedule | " - "OTF compact artifact: all runtime helicities\n" - "pyAmpliCol setup: generation + fresh load + first fixed-helicity " - "evaluation; OTF includes family warm-up\n" - "Reference setup: build/init/first pass | AmpliCol setup: " - "process/color-object generation\n" - "Warmed runtime measured separately | compiled FFT disabled\n" - f"pyAmpliCol CLI profile: batch {batch_size} (cyclic 10 points) | " - "Reference/AmpliCol: scalar aggregates normalized per point" - ) - else: - note = ( - "--fft | recurrence: persisted all-helicity physical schedule | " - "OTF compact artifact: all runtime helicities\n" - "pyAmpliCol setup: generation + fresh load + first complete helicity " - "sum; OTF includes family warm-up\n" - "Reference setup: build/init/first pass | AmpliCol setup: process/raw-" - "library generation/build + immutable snapshot\n" - "Warmed runtime measured separately | compiled FFT disabled\n" - f"pyAmpliCol CLI profile: batch {batch_size} (cyclic 10 points) | " - "Reference/AmpliCol: scalar aggregates normalized per point\n" - "AmpliCol: create-raw bulk H family + probe-local zero pruning | " - "Reference FFT: analytic-nonzero H sweep" - ) - status = report.get("status") - if not isinstance(status, str) or not status.startswith("complete"): - return "IN PROGRESS SNAPSHOT | absent cells are unattempted\n" + note - memory_limit = measurement.get("memory_watchdog_gib") - generation_limit = measurement.get("generation_timeout_seconds") - runtime_limit = measurement.get("runtime_timeout_seconds") - if (memory_limit, generation_limit, runtime_limit) != (30.0, 3600.0, 3600.0): - return "CLUSTER SCAN | configured per-cell resource caps\n" + note - return note - - -def _campaign_helicity_workload( - policy: Mapping[str, Any], measurement: Mapping[str, Any] -) -> str: - measurement_declared = measurement.get("helicity_workload") - policy_declared = policy.get("helicity_workload") - if ( - measurement_declared is not None - and policy_declared is not None - and str(measurement_declared) != str(policy_declared) - ): - raise ValueError( - "policy and measurement helicity_workload declarations disagree" - ) - declared = ( - measurement_declared - if measurement_declared is not None - else policy_declared - ) - if declared is not None: - workload = str(declared) - if workload not in {"fixed", "sum"}: - raise ValueError("campaign helicity_workload must be 'fixed' or 'sum'") - if workload == "sum" and ( - measurement.get("warm_fixed_helicity") is not False - or measurement.get("warm_helicity_sum") is not True - ): - raise ValueError( - "summed campaign must record warm_fixed_helicity=false and " - "warm_helicity_sum=true" - ) - if workload == "fixed" and ( - measurement.get("warm_fixed_helicity") is not True - or measurement.get("warm_helicity_sum") is True - ): - raise ValueError( - "fixed campaign must record warm_fixed_helicity=true without " - "warm_helicity_sum=true" - ) - elif measurement.get("warm_helicity_sum") is True: - if measurement.get("warm_fixed_helicity") is True: - raise ValueError("campaign helicity workload markers are contradictory") - workload = "sum" - elif measurement.get("warm_fixed_helicity") is True: - workload = "fixed" - else: - raise ValueError( - "campaign policy must identify a fixed or summed warm-helicity workload" - ) - if workload == "fixed" and measurement.get("warm_fixed_helicity") is not True: - raise ValueError("fixed campaign must record warm_fixed_helicity=true") - if workload == "sum" and measurement.get("warm_fixed_helicity") is True: - raise ValueError("summed campaign cannot record warm_fixed_helicity=true") - return workload - - -def _cell_helicity_workload(cell: Mapping[str, Any]) -> str | None: - markers: set[str] = set() - declared = cell.get("helicity_workload") - if declared is not None: - workload = str(declared) - if workload not in {"fixed", "sum"}: - raise ValueError("measured cell helicity_workload must be 'fixed' or 'sum'") - markers.add(workload) - if cell.get("warm_helicity_sum") is True: - markers.add("sum") - if cell.get("warm_fixed_helicity") is True: - markers.add("fixed") - protocol = cell.get("protocol") - if isinstance(protocol, Mapping): - if protocol.get("helicity_summed") is True: - markers.add("sum") - if ( - protocol.get("helicity_summed") is False - or protocol.get("warm_fixed_helicity") is True - ): - markers.add("fixed") - if len(markers) > 1: - raise ValueError("measured cell helicity workload markers are contradictory") - return next(iter(markers), None) - - -def _validate_campaign_cell_workloads( - report: Mapping[str, Any], expected: str -) -> None: - for section_name in ("cells", "runtime_series"): - section = report.get(section_name) - if not isinstance(section, Mapping): - continue - for family, raw_modes in section.items(): - if not isinstance(raw_modes, Mapping): - continue - for mode, raw_cells in raw_modes.items(): - if not isinstance(raw_cells, Mapping): - continue - for raw_n, raw_cell in raw_cells.items(): - if not isinstance(raw_cell, Mapping): - continue - if raw_cell.get("status") != "measured": - continue - observed = _cell_helicity_workload(raw_cell) - context = f"{section_name}.{family}.{mode}.n={raw_n}" - if expected == "sum" and observed != "sum": - raise ValueError( - f"{context} is not authenticated as helicity-summed" - ) - if expected == "fixed" and observed == "sum": - raise ValueError( - f"{context} is summed data in a fixed-helicity campaign" - ) - - -def _load_campaign_note(path: Path) -> str: - report = _load_campaign(path) - return _campaign_note(report) - - -def _load_campaign(path: Path) -> Mapping[str, Any]: - try: - report = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise ValueError(f"cannot read campaign report {path}: {error}") from error - if not isinstance(report, Mapping): - raise ValueError("campaign report must be a JSON object") - return report - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as source: - for chunk in iter(lambda: source.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def _validate_plot_manifest( - plot_directory: Path, - campaign_report: Path, - helicity_workload: str, -) -> None: - manifest_path = plot_directory / PLOT_MANIFEST_NAME - try: - manifest = json.loads(manifest_path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise ValueError( - f"cannot read plot manifest {manifest_path}: {error}" - ) from error - if not isinstance(manifest, Mapping): - raise ValueError("plot manifest must be a JSON object") - if ( - manifest.get("kind") != "pyamplicol-fft-scaling-plots" - or manifest.get("schema_version") != 1 - ): - raise ValueError("plot manifest has an unsupported identity or schema") - if manifest.get("report_sha256") != _sha256(campaign_report): - raise ValueError("plot manifest was rendered from a different campaign report") - if manifest.get("helicity_workload") != helicity_workload: - raise ValueError("plot manifest helicity workload does not match the campaign") - raw_plots = manifest.get("plots") - if not isinstance(raw_plots, Mapping) or set(raw_plots) != set(PLOT_FILENAMES): - raise ValueError("plot manifest does not name the exact published plot set") - for filename in PLOT_FILENAMES: - plot_path = plot_directory / filename - if raw_plots.get(filename) != _sha256(plot_path): - raise ValueError(f"plot manifest hash does not match {filename}") - - -def _validated_plot_data_bytes( - plot_directory: Path, - campaign_report: Path, - helicity_workload: str, -) -> bytes: - data_path = plot_directory / PLOT_DATA_NAME - try: - raw = data_path.read_bytes() - payload = json.loads(raw) - except (OSError, json.JSONDecodeError) as error: - raise ValueError(f"cannot read plot data {data_path}: {error}") from error - if not isinstance(payload, Mapping): - raise ValueError("plot data must be a JSON object") - if ( - payload.get("kind") != "pyamplicol-fft-scaling-plot-data" - or payload.get("schema_version") != 1 - ): - raise ValueError("plot data has an unsupported identity or schema") - if payload.get("report_sha256") != _sha256(campaign_report): - raise ValueError("plot data was rendered from a different campaign report") - if payload.get("helicity_workload") != helicity_workload: - raise ValueError("plot data helicity workload does not match the campaign") - families = payload.get("families") - if not isinstance(families, Mapping) or set(families) != {"gg", "ddbar"}: - raise ValueError("plot data must contain gg and ddbar families") - return raw - - -def _publish_plot_data_sidecar(raw: bytes, output: Path) -> Path: - destination = output.with_suffix(".json") - temporary = destination.with_suffix(destination.suffix + ".tmp") - temporary.write_bytes(raw) - temporary.replace(destination) - return destination - - -def _campaign_note_lines( - campaign_note: str, - *, - available_width: float, - font_name: str = "Helvetica", - font_size: float = 6.6, -) -> tuple[str, ...]: - """Preserve authored line breaks and wrap any line to the page width.""" - - wrapped: list[str] = [] - for source_line in campaign_note.splitlines(): - words = source_line.split() - if not words: - wrapped.append("") - continue - current = words[0] - for word in words[1:]: - candidate = f"{current} {word}" - candidate_width = pdfmetrics.stringWidth( - candidate, font_name, font_size - ) - if candidate_width <= available_width: - current = candidate - else: - wrapped.append(current) - current = word - wrapped.append(current) - return tuple(wrapped) - - -def _campaign_header_height(note_lines: Sequence[str]) -> float: - """Reserve a title band plus one eight-point row for every note line.""" - - return max(31.0, 15.0 + 8.0 * len(note_lines)) - - -def _draw_page( - document: canvas.Canvas, - page: PlotPage, - *, - page_number: int, - page_count: int, - campaign_note: str, -) -> None: - width, height = landscape(A4) - margin = 18.0 - footer_height = 13.0 - available_width = width - 2 * margin - note_lines = _campaign_note_lines( - campaign_note, - available_width=available_width, - ) - header_height = _campaign_header_height(note_lines) - available_height = height - 2 * margin - header_height - footer_height - - image_width, image_height = ImageReader(page.path).getSize() - scale = min(available_width / image_width, available_height / image_height) - drawn_width = image_width * scale - drawn_height = image_height * scale - x = (width - drawn_width) / 2 - y = margin + footer_height + (available_height - drawn_height) / 2 - - document.setFillColorRGB(1, 1, 1) - document.rect(0, 0, width, height, fill=1, stroke=0) - document.setFillColorRGB(0.14, 0.17, 0.20) - document.setFont("Helvetica-Bold", 9) - document.drawString(margin, height - margin - 7, page.section) - document.setFont("Helvetica", 6.6) - document.setFillColorRGB(0.35, 0.39, 0.43) - for line_index, line in enumerate(note_lines): - document.drawString( - margin, - height - margin - 15.5 - 8.0 * line_index, - line, - ) - document.drawImage( - str(page.path), - x, - y, - width=drawn_width, - height=drawn_height, - preserveAspectRatio=True, - anchor="c", - ) - document.setFillColorRGB(0.35, 0.39, 0.43) - document.setFont("Helvetica", 7.5) - document.drawRightString( - width - margin, - margin - 1, - f"pyAmpliCol FullColor scaling results - page {page_number}/{page_count}", - ) - document.showPage() - - -def main() -> int: - arguments = _parser().parse_args() - try: - campaign_report = _load_campaign(arguments.campaign_report) - campaign_note = _campaign_note(campaign_report) - policy = _mapping(campaign_report.get("policy"), context="campaign policy") - measurement = _mapping( - policy.get("measurement"), context="campaign measurement policy" - ) - helicity_workload = _campaign_helicity_workload(policy, measurement) - except ValueError as error: - raise SystemExit(f"invalid campaign provenance: {error}") from error - pages = _plot_pages( - arguments.plot_directory, - helicity_workload=helicity_workload, - ) - missing = [page.path for page in pages if not page.path.is_file()] - if missing: - raise SystemExit("missing published plot(s): " + ", ".join(map(str, missing))) - try: - _validate_plot_manifest( - pages[0].path.parent, - arguments.campaign_report, - helicity_workload, - ) - plot_data = _validated_plot_data_bytes( - pages[0].path.parent, - arguments.campaign_report, - helicity_workload, - ) - except ValueError as error: - raise SystemExit(f"invalid plot provenance: {error}") from error - - output = arguments.output.expanduser().resolve(strict=False) - output.parent.mkdir(parents=True, exist_ok=True) - temporary = output.with_suffix(output.suffix + ".tmp") - document = canvas.Canvas( - str(temporary), - pagesize=landscape(A4), - pageCompression=1, - invariant=1, - ) - document.setTitle( - "pyAmpliCol FullColor scaling summary plots" - if helicity_workload == "fixed" - else "pyAmpliCol FullColor helicity-summed scaling summary plots" - ) - document.setAuthor("pyAmpliCol") - for index, page in enumerate(pages, start=1): - _draw_page( - document, - page, - page_number=index, - page_count=len(pages), - campaign_note=campaign_note, - ) - document.save() - temporary.replace(output) - _publish_plot_data_sidecar(plot_data, output) - print(output) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_scaling_final_publication_report.py b/pyamplicol/tools/developer/fft_scaling_final_publication_report.py deleted file mode 100644 index 35930e35f2..0000000000 --- a/pyamplicol/tools/developer/fft_scaling_final_publication_report.py +++ /dev/null @@ -1,1275 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Merge the fresh n=2..9 scaling campaign with its MadGraph series. - -This is intentionally a narrow publication boundary. It does not splice old -pyAmpliCol measurements into the fresh campaign: the campaign cells and policy -are retained as one source, while the independently measured MadGraph cells are -attached as an external series after their resource, event, and numerical -provenance has been authenticated. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import re -import sys -from collections import Counter -from collections.abc import Mapping, Sequence -from copy import deepcopy -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.developer import fft_madgraph_selected_runtime as madgraph # noqa: E402 -from tools.developer import fft_scaling_selected_scalar_report as selected # noqa: E402 - -RESULTS = ROOT / "IMPLEMENTATION_DOCS" / "RESULTS" / "fft-scaling-study" -DATA = RESULTS / "data" - -CAMPAIGN_KIND = "pyamplicol-fullcolor-fft-scaling-study" -FINAL_KIND = "pyamplicol-fullcolor-fft-scaling-final-publication" -SCHEMA_VERSION = 1 -FINAL_MULTIPLICITIES = tuple(range(2, 10)) -MADGRAPH_MAX_MEASURED_MULTIPLICITY = 6 -FAMILY_MODES = { - "gg": ( - "reference-fft", - "amplicol", - "recurrence-direct", - "recurrence-fft", - "otf-direct", - "otf-fft", - ), - "ddbar": ( - "amplicol", - "recurrence-direct", - "recurrence-fft", - "otf-direct", - "otf-fft", - ), -} -MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY = ( - madgraph.protocol_measured_multiplicity_limits() -) -SOURCE_MODE = {"gg": "reference-fft", "ddbar": "recurrence-fft"} -SUM_SOURCE_MODE = {"gg": "recurrence-fft", "ddbar": "recurrence-fft"} -CANDIDATE_MODE_CONTRACT = { - "recurrence-direct": ("recurrence", "direct"), - "recurrence-fft": ("recurrence", "symmetric-group-fft"), - "otf-direct": ("on-the-fly", "direct"), - "otf-fft": ("on-the-fly", "symmetric-group-fft"), -} -METRIC_KEYS = ( - "generation_seconds", - "warm_seconds_per_point", - "max_rss_kib", -) -EXPECTED_EXPRESSIONS = { - "gg": "g g > g g + (n-2)*g", - "ddbar": "d d~ > d d~ + (n-2)*g", -} -EXPECTED_RATIO_REFERENCES = {"gg": "reference-fft", "ddbar": "amplicol"} -MAX_GENERATION_SECONDS = 3600.0 -MAX_RUNTIME_SECONDS = 3600.0 -MAX_RSS_GIB = 30.0 -MAX_RSS_KIB = MAX_RSS_GIB * 1024**2 -POINT_COUNT = 10 -WARM_SAMPLE_COUNT = madgraph.WARM_SAMPLE_COUNT - - -class PublicationMergeError(RuntimeError): - """The two inputs cannot be merged without weakening their contracts.""" - - -def _expected_madgraph_iden(family: str, n: int) -> int: - if family == "gg": - return 256 * math.factorial(n) - if family == "ddbar": - return 36 * math.factorial(n - 2) - raise PublicationMergeError(f"unsupported MadGraph family {family!r}") - - -def _source_mode(family: str, helicity_workload: str) -> str: - modes = SUM_SOURCE_MODE if helicity_workload == "sum" else SOURCE_MODE - try: - return modes[family] - except KeyError as error: - raise PublicationMergeError( - f"unsupported MadGraph family {family!r}" - ) from error - - -def _madgraph_normalization_factor( - family: str, n: int, *, helicity_workload: str = "fixed" -) -> float: - if helicity_workload == "sum": - return 1.0 - if helicity_workload != "fixed": - raise PublicationMergeError( - f"unsupported helicity workload {helicity_workload!r}" - ) - return 1.0 if family == "gg" else 1.0 / _expected_madgraph_iden(family, n) - - -def _helicity_workload(policy: Mapping[str, Any]) -> str: - measurement = _mapping( - policy.get("measurement"), context="campaign measurement policy" - ) - declared = measurement.get("helicity_workload") - if declared is None: - workload = "sum" if measurement.get("warm_helicity_sum") is True else "fixed" - else: - workload = str(declared) - if workload not in {"fixed", "sum"}: - raise PublicationMergeError("campaign helicity workload is unsupported") - if workload == "sum" and ( - measurement.get("warm_fixed_helicity") is not False - or measurement.get("warm_helicity_sum") is not True - ): - raise PublicationMergeError("summed campaign helicity markers are incompatible") - if workload == "fixed" and ( - measurement.get("warm_fixed_helicity") is not True - or measurement.get("warm_helicity_sum") is True - ): - raise PublicationMergeError("fixed campaign helicity markers are incompatible") - return workload - - -def _overlay_helicity_workload(policy: Mapping[str, Any]) -> str: - declared = policy.get("helicity_workload") - if declared is None: - workload = "sum" if policy.get("warm_helicity_sum") is True else "fixed" - else: - workload = str(declared) - if workload not in {"fixed", "sum"}: - raise PublicationMergeError("MadGraph helicity workload is unsupported") - if workload == "sum" and ( - policy.get("warm_fixed_helicity") is not False - or policy.get("warm_helicity_sum") is not True - ): - raise PublicationMergeError("summed MadGraph helicity markers are incompatible") - if workload == "fixed" and ( - policy.get("warm_fixed_helicity") is not True - or policy.get("warm_helicity_sum") is True - ): - raise PublicationMergeError("fixed MadGraph helicity markers are incompatible") - return workload - - -@dataclass(frozen=True, slots=True) -class Document: - key: str - path: Path - sha256: str - payload: dict[str, Any] - - @property - def display_path(self) -> str: - try: - return str(self.path.relative_to(ROOT)) - except ValueError: - return str(self.path) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--campaign-report", - type=Path, - default=( - RESULTS / "raw" / "runs" / "final-publication-scalar-n2-n9" / "report.json" - ), - help="fresh all-helicity pyAmpliCol/Reference/AmpliCol report", - ) - parser.add_argument( - "--madgraph-overlay", - type=Path, - required=True, - help="completed live MadGraph runtime-series overlay", - ) - parser.add_argument( - "--output", - type=Path, - default=DATA / "campaign-report-scalar-selected-n2-n9-final.json", - help="final publication report", - ) - return parser - - -def _sha256_bytes(raw: bytes) -> str: - return hashlib.sha256(raw).hexdigest() - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - try: - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - except OSError as error: - raise PublicationMergeError(f"cannot hash {path}: {error}") from error - return digest.hexdigest() - - -def _load_document(key: str, path: Path) -> Document: - path = path.expanduser().resolve(strict=False) - try: - raw = path.read_bytes() - payload = json.loads(raw) - except (OSError, json.JSONDecodeError) as error: - raise PublicationMergeError(f"cannot read {key} {path}: {error}") from error - if not isinstance(payload, dict): - raise PublicationMergeError(f"{key} must be a JSON object") - return Document(key=key, path=path, sha256=_sha256_bytes(raw), payload=payload) - - -def _mapping(value: object, *, context: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise PublicationMergeError(f"{context} must be an object") - return value - - -def _measurement_host(value: object, *, context: str) -> dict[str, Any]: - try: - return madgraph.validate_measurement_host(value, context=context) - except madgraph.SelectedMadGraphError as error: - raise PublicationMergeError(str(error)) from error - - -def _sequence(value: object, *, context: str) -> Sequence[Any]: - if not isinstance(value, Sequence) or isinstance(value, str): - raise PublicationMergeError(f"{context} must be an array") - return value - - -def _finite_number(value: object, *, context: str) -> float: - if isinstance(value, bool) or not isinstance(value, int | float): - raise PublicationMergeError(f"{context} must be a finite number") - result = float(value) - if not math.isfinite(result): - raise PublicationMergeError(f"{context} must be a finite number") - return result - - -def _positive_number(value: object, *, context: str) -> float: - result = _finite_number(value, context=context) - if result <= 0.0: - raise PublicationMergeError(f"{context} must be positive") - return result - - -def _process_expression(family: str, n: int) -> str: - extra = " ".join("g" for _ in range(n - 2)) - base = "g g > g g" if family == "gg" else "d d~ > d d~" - return base + (f" {extra}" if extra else "") - - -def _relative_error(left: float, right: float) -> float: - if left == right: - return 0.0 - return abs(left - right) / max(abs(left), abs(right), 1.0e-300) - - -def _validate_limit( - raw_limits: Mapping[str, Any], key: str, expected_limit: float -) -> None: - limit = _mapping(raw_limits.get(key), context=f"cell_admission_limits.{key}") - if ( - limit.get("operator") != "<" - or _finite_number( - limit.get("limit"), context=f"cell_admission_limits.{key}.limit" - ) - != expected_limit - ): - raise PublicationMergeError( - f"cell_admission_limits.{key} must be strictly < {expected_limit:g}" - ) - - -def _validate_campaign_policy(document: Document) -> Mapping[str, Any]: - report = document.payload - if report.get("kind") != CAMPAIGN_KIND or report.get("schema_version") != 1: - raise PublicationMergeError("campaign report has the wrong kind or schema") - policy = _mapping(report.get("policy"), context="campaign policy") - if policy.get("kind") != CAMPAIGN_KIND or policy.get("schema_version") != 1: - raise PublicationMergeError("campaign policy has the wrong kind or schema") - if policy.get("final_state_multiplicities") != list(FINAL_MULTIPLICITIES): - raise PublicationMergeError("campaign must physically cover only n=2..9") - if policy.get("total_external_particles") != [n + 2 for n in FINAL_MULTIPLICITIES]: - raise PublicationMergeError("campaign total-external-particle range is wrong") - if policy.get("fft_enabled") is not True: - raise PublicationMergeError("campaign policy must record --fft") - contractions = _mapping( - policy.get("selected_pyamplicol_color_contractions"), - context="selected pyAmpliCol contractions", - ) - expected_contractions = { - "recurrence": ["direct", "symmetric-group-fft"], - "on-the-fly": ["direct", "symmetric-group-fft"], - } - if dict(contractions) != expected_contractions: - raise PublicationMergeError( - "campaign must select direct and symmetric-group FFT for recurrence " - "and on-the-fly only" - ) - - raw_families = _mapping( - policy.get("process_families"), context="campaign process families" - ) - if set(raw_families) != set(FAMILY_MODES): - raise PublicationMergeError("campaign must contain exactly gg and ddbar") - for family, expected_modes in FAMILY_MODES.items(): - family_policy = _mapping( - raw_families.get(family), context=f"campaign process family {family}" - ) - if family_policy.get("expression") != EXPECTED_EXPRESSIONS[family]: - raise PublicationMergeError(f"campaign {family} expression is wrong") - if family_policy.get("ratio_reference") != EXPECTED_RATIO_REFERENCES[family]: - raise PublicationMergeError(f"campaign {family} ratio baseline is wrong") - if family_policy.get("modes") != list(expected_modes): - raise PublicationMergeError( - f"campaign {family} must select exactly {list(expected_modes)}" - ) - - measurement = _mapping( - policy.get("measurement"), context="campaign measurement policy" - ) - helicity_workload = _helicity_workload(policy) - expected_measurement = { - "color_accuracy": "full", - "n_definition": "final-state-particle-count", - "generation_helicity_coverage": "all", - "warm_fixed_helicity": helicity_workload == "fixed", - "warm_benchmark_batch_size": 128, - "warm_sample_count": WARM_SAMPLE_COUNT, - "compiled_fft_enabled": False, - "memory_policy": "per-cell-strictly-below-publication-ceiling", - } - for key, expected in expected_measurement.items(): - if measurement.get(key) != expected: - raise PublicationMergeError( - f"campaign measurement policy has incompatible {key}" - ) - if ( - _finite_number( - measurement.get("requested_memory_ceiling_gib"), - context="requested memory ceiling", - ) - != MAX_RSS_GIB - or _finite_number( - measurement.get("memory_watchdog_gib"), context="memory watchdog" - ) - != MAX_RSS_GIB - ): - raise PublicationMergeError("campaign memory policy must use the 30-GiB cap") - limits = _mapping( - measurement.get("cell_admission_limits"), context="cell admission limits" - ) - _validate_limit(limits, "generation_seconds", MAX_GENERATION_SECONDS) - _validate_limit(limits, "runtime_seconds", MAX_RUNTIME_SECONDS) - _validate_limit(limits, "peak_rss_gib", MAX_RSS_GIB) - - run_root_raw = policy.get("run_root") - if not isinstance(run_root_raw, str) or not run_root_raw: - raise PublicationMergeError("campaign policy.run_root is required") - if Path(run_root_raw).expanduser().resolve(strict=False) != document.path.parent: - raise PublicationMergeError("campaign report is outside its recorded run_root") - return policy - - -def campaign_policy_is_publication_profile(report: Mapping[str, Any]) -> bool: - """Return whether a report declares the exact canonical publication policy. - - Cell and overlay authentication deliberately remain in the strict merger; - callers use this only to decide whether that merger is the required render - boundary. - """ - - try: - payload = dict(report) - policy = payload.get("policy") - run_root = policy.get("run_root") if isinstance(policy, Mapping) else None - if not isinstance(run_root, str) or not run_root: - return False - _validate_campaign_policy( - Document( - key="campaign policy probe", - path=Path(run_root) / "report.json", - sha256="0" * 64, - payload=payload, - ) - ) - except PublicationMergeError: - return False - return True - - -def _validate_helicity(value: object, *, n: int, context: str) -> tuple[int, ...]: - raw = _sequence(value, context=context) - if len(raw) != n + 2 or any( - not isinstance(item, int) or isinstance(item, bool) or item not in (-1, 1) - for item in raw - ): - raise PublicationMergeError(f"{context} is invalid") - return tuple(int(item) for item in raw) - - -def _validate_points( - value: object, - *, - context: str, - expected_count: int = POINT_COUNT, -) -> tuple[float, ...]: - raw = _sequence(value, context=context) - points = tuple(_finite_number(item, context=context) for item in raw) - if len(points) != expected_count or not any(point != 0.0 for point in points): - raise PublicationMergeError( - f"{context} must contain exactly {expected_count} values with a " - "nonzero result" - ) - return points - - -def _validate_campaign_cells( - document: Document, *, helicity_workload: str = "fixed" -) -> Counter[str]: - raw_cells = _mapping(document.payload.get("cells"), context="campaign cells") - if set(raw_cells) != set(FAMILY_MODES): - raise PublicationMergeError("campaign cells must contain exactly gg and ddbar") - status_counts: Counter[str] = Counter() - for family, expected_modes in FAMILY_MODES.items(): - family_cells = _mapping( - raw_cells.get(family), context=f"campaign cells.{family}" - ) - if set(family_cells) != set(expected_modes): - raise PublicationMergeError( - f"campaign cells.{family} has an unexpected mode set" - ) - for mode in expected_modes: - mode_cells = _mapping( - family_cells.get(mode), context=f"campaign cells.{family}.{mode}" - ) - if set(mode_cells) != {str(n) for n in FINAL_MULTIPLICITIES}: - raise PublicationMergeError( - f"campaign cells.{family}.{mode} must describe n=2..9" - ) - frontier_seen = False - for n in FINAL_MULTIPLICITIES: - context = f"campaign cells.{family}.{mode}.{n}" - cell = _mapping(mode_cells.get(str(n)), context=context) - status = cell.get("status") - if status not in {"measured", "failed", "skipped"}: - raise PublicationMergeError(f"{context}.status is unsupported") - if status == "measured" and frontier_seen: - raise PublicationMergeError( - f"{context} resumes measurement after its availability frontier" - ) - if status == "failed" and frontier_seen: - raise PublicationMergeError( - f"{context} repeats a failure after its availability frontier" - ) - if ( - status == "failed" - and cell.get("censors_higher_multiplicities") is not True - ): - raise PublicationMergeError( - f"{context} records a non-censoring failure in a " - "completed campaign" - ) - if status == "skipped" and not isinstance( - cell.get("censors_higher_multiplicities"), bool - ): - raise PublicationMergeError( - f"{context} must state whether its skip censors higher n" - ) - if status != "measured" and not frontier_seen: - frontier_seen = True - for key, expected in ( - ("family", family), - ("mode", mode), - ("n", n), - ("total_external", n + 2), - ("process", _process_expression(family, n)), - ("color_accuracy", "full"), - ): - if cell.get(key) != expected: - raise PublicationMergeError(f"{context}.{key} is wrong") - label = cell.get("label") - if not isinstance(label, str) or not label.strip(): - raise PublicationMergeError(f"{context}.label is required") - candidate_contract = CANDIDATE_MODE_CONTRACT.get(mode) - if candidate_contract is not None: - expected_execution, expected_contraction = candidate_contract - for key, expected in ( - ("execution_mode", expected_execution), - ("color_contraction", expected_contraction), - ("generation_helicity_coverage", "all"), - ("warm_fixed_helicity", helicity_workload == "fixed"), - ): - if cell.get(key) != expected: - raise PublicationMergeError(f"{context}.{key} is wrong") - if helicity_workload == "sum" and cell.get( - "warm_helicity_sum" - ) is not True: - raise PublicationMergeError( - f"{context}.warm_helicity_sum is wrong" - ) - if status == "measured": - metrics = _mapping( - cell.get("metrics"), context=f"{context}.metrics" - ) - values = { - key: _positive_number( - metrics.get(key), context=f"{context}.metrics.{key}" - ) - for key in METRIC_KEYS - } - if values["generation_seconds"] >= MAX_GENERATION_SECONDS: - raise PublicationMergeError( - f"{context} violates the strict one-hour generation cap" - ) - if values["max_rss_kib"] >= MAX_RSS_KIB: - raise PublicationMergeError( - f"{context} violates the strict 30-GiB RSS cap" - ) - _validate_helicity(cell.get("helicity"), n=n, context=context) - _validate_points( - cell.get("point_values"), - context=context, - expected_count=1 if mode == "amplicol" else POINT_COUNT, - ) - event_paths = _sequence( - cell.get("event_paths"), context=f"{context}.event_paths" - ) - if len(event_paths) != POINT_COUNT or any( - not isinstance(path, str) or not path for path in event_paths - ): - raise PublicationMergeError( - f"{context}.event_paths must contain ten paths" - ) - numerical = cell.get("numerical") - if isinstance(numerical, Mapping): - available = numerical.get("available") - if available is True and numerical.get("passes") is not True: - raise PublicationMergeError( - f"{context} failed its numerical comparison" - ) - else: - reason = cell.get("failure_reason") - if not isinstance(reason, str) or not reason.strip(): - raise PublicationMergeError( - f"{context}.failure_reason is required" - ) - status_counts[str(status)] += 1 - - expected_status = ( - "complete-with-failures" if status_counts["failed"] else "complete" - ) - if document.payload.get("status") != expected_status: - raise PublicationMergeError("campaign status disagrees with its cells") - if document.payload.get("failure_count") != status_counts["failed"]: - raise PublicationMergeError("campaign failure_count disagrees with its cells") - return status_counts - - -def _validate_madgraph_policy( - document: Document, *, helicity_workload: str = "fixed" -) -> None: - report = document.payload - if ( - report.get("kind") != selected.RUNTIME_SERIES_OVERLAY_KIND - or report.get("schema_version") != SCHEMA_VERSION - ): - raise PublicationMergeError("MadGraph overlay has the wrong kind or schema") - policy = _mapping(report.get("policy"), context="MadGraph policy") - if _overlay_helicity_workload(policy) != helicity_workload: - raise PublicationMergeError( - "MadGraph overlay helicity workload differs from the campaign" - ) - expected = { - "final_state_multiplicities": list(FINAL_MULTIPLICITIES), - "process_families": list(FAMILY_MODES), - "point_validation_count": POINT_COUNT, - "warm_timed_point_index": 1, - "warm_sample_count": WARM_SAMPLE_COUNT, - "watchdog_enforced_per_generation_build_and_runtime": True, - "generation_helicity_coverage": "all", - "warm_fixed_helicity": helicity_workload == "fixed", - "maximum_measured_multiplicity": MADGRAPH_MAX_MEASURED_MULTIPLICITY, - "family_maximum_measured_multiplicity": ( - MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY - ), - "higher_multiplicity_policy": "not-applicable-protocol-scope", - } - for key, value in expected.items(): - if policy.get(key) != value: - raise PublicationMergeError(f"MadGraph policy has incompatible {key}") - timeout = _positive_number( - policy.get("generation_timeout_seconds"), - context="MadGraph generation timeout", - ) - if timeout >= MAX_GENERATION_SECONDS: - raise PublicationMergeError( - "MadGraph generation timeout must be below one hour" - ) - memory = _positive_number( - policy.get("outer_memory_watchdog_gib"), context="MadGraph memory watchdog" - ) - if memory > MAX_RSS_GIB: - raise PublicationMergeError("MadGraph memory watchdog exceeds 30 GiB") - metric_scope = _mapping(policy.get("metric_scope"), context="MadGraph metric scope") - if set(metric_scope) != set(METRIC_KEYS) or any( - not isinstance(value, str) or not value.strip() - for value in metric_scope.values() - ): - raise PublicationMergeError( - "MadGraph metric scope must define all three metrics" - ) - - -def _madgraph_protocol_scope_categories(family: str, n: int, limit: int) -> set[str]: - categories = {f"protocol-scope-n>{limit}"} - if family == "gg" and n == 6: - categories.add("protocol-scope-pure-gluon-n6") - return categories - - -def _resolve_recorded_path(raw: object, *, context: str) -> Path: - if not isinstance(raw, str) or not raw: - raise PublicationMergeError(f"{context} must be a nonempty path") - path = Path(raw).expanduser() - if not path.is_absolute(): - path = ROOT / path - return path.resolve(strict=False) - - -def _event_identity(cell: Mapping[str, Any], *, context: str) -> tuple[Path, ...]: - raw_paths = _sequence(cell.get("event_paths"), context=f"{context}.event_paths") - raw_hashes = _sequence(cell.get("event_sha256"), context=f"{context}.event_sha256") - if len(raw_paths) != POINT_COUNT or len(raw_hashes) != POINT_COUNT: - raise PublicationMergeError(f"{context} must identify ten events") - paths = tuple( - _resolve_recorded_path(path, context=f"{context}.event_paths") - for path in raw_paths - ) - for path, expected_hash in zip(paths, raw_hashes, strict=True): - if ( - not isinstance(expected_hash, str) - or len(expected_hash) != 64 - or _sha256_file(path) != expected_hash - ): - raise PublicationMergeError(f"{context} event SHA-256 provenance differs") - return paths - - -def _source_cell( - report: Mapping[str, Any], family: str, mode: str, n: int, *, context: str -) -> Mapping[str, Any]: - cells = _mapping(report.get("cells"), context=f"{context}.cells") - family_cells = _mapping(cells.get(family), context=f"{context}.cells.{family}") - mode_cells = _mapping( - family_cells.get(mode), context=f"{context}.cells.{family}.{mode}" - ) - return _mapping( - mode_cells.get(str(n)), context=f"{context}.cells.{family}.{mode}.{n}" - ) - - -def _cell_event_hashes(cell: Mapping[str, Any], *, context: str) -> tuple[str, ...]: - raw_paths = _sequence(cell.get("event_paths"), context=f"{context}.event_paths") - if len(raw_paths) != POINT_COUNT: - raise PublicationMergeError(f"{context}.event_paths must contain ten paths") - return tuple( - _sha256_file(_resolve_recorded_path(path, context=f"{context}.event_paths")) - for path in raw_paths - ) - - -def _validate_summed_retained_sources( - provenance: Mapping[str, Any], *, n: int, context: str -) -> None: - retained = _mapping( - provenance.get("retained"), context=f"{context}.provenance.retained" - ) - matrix_path = _resolve_recorded_path( - retained.get("matrix_source"), context=f"{context}.retained.matrix_source" - ) - check_path = _resolve_recorded_path( - retained.get("check_source"), context=f"{context}.retained.check_source" - ) - matrix_sha = _sha256_file(matrix_path) - check_sha = _sha256_file(check_path) - if ( - retained.get("matrix_sha256") != matrix_sha - or provenance.get("matrix_sha256") != matrix_sha - or retained.get("check_source_sha256") != check_sha - or provenance.get("check_source_sha256") != check_sha - ): - raise PublicationMergeError(f"{context} retained source SHA-256 differs") - try: - matrix_source = matrix_path.read_text(encoding="utf-8") - check_source = check_path.read_text(encoding="ascii") - except (OSError, UnicodeError) as error: - raise PublicationMergeError( - f"{context} cannot read retained generated sources: {error}" - ) from error - expected_ncomb = 2 ** (n + 2) - ncomb_values = { - int(value) - for value in re.findall(r"\bNCOMB\s*=\s*(\d+)\b", matrix_source, re.I) - } - if expected_ncomb not in ncomb_values or re.search( - r"INTEGER\s+NHEL\s*\(\s*NEXTERNAL\s*,\s*NCOMB\s*\)", - matrix_source, - re.I, - ) is None: - raise PublicationMergeError(f"{context} has incompatible NCOMB/NHEL source") - iden = provenance.get("smatrix_iden") - if ( - not isinstance(iden, int) - or len( - re.findall( - rf"^[ \t]{{6,}}DATA[ \t]+IDEN[ \t]*/[ \t]*{iden}[ \t]*/", - matrix_source, - re.I | re.M, - ) - ) - != 1 - or len( - re.findall( - r"^[ \t]{6,}ANS[ \t]*=[ \t]*ANS[ \t]*/[ \t]*" - r"DBLE[ \t]*\([ \t]*IDEN[ \t]*\)", - matrix_source, - re.I | re.M, - ) - ) - != 1 - ): - raise PublicationMergeError(f"{context} has incompatible SMATRIX IDEN use") - if ( - "USERHEL=-1" not in check_source.replace(" ", "") - or check_source.count("CALL SMATRIX(") != 3 - or re.search(r"(? Document: - campaign_policy = _mapping( - campaign.payload.get("policy"), context="campaign policy" - ) - campaign_measurement = _mapping( - campaign_policy.get("measurement"), context="campaign measurement policy" - ) - campaign_alpha_s = ( - _positive_number( - campaign_measurement.get("alpha_s"), context="campaign alpha_s" - ) - if helicity_workload == "sum" - else None - ) - raw_series = _mapping( - overlay.payload.get("runtime_series"), context="MadGraph runtime_series" - ) - source_identity: tuple[str, str] | None = None - measured_count_by_family: Counter[str] = Counter() - status_counts: Counter[str] = Counter() - for family in FAMILY_MODES: - measured_limit = MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY[family] - family_series = _mapping( - raw_series.get(family), context=f"MadGraph runtime_series.{family}" - ) - mode_cells = _mapping( - family_series.get("madgraph-standalone"), - context=f"MadGraph runtime_series.{family}.madgraph-standalone", - ) - for n in FINAL_MULTIPLICITIES: - context = f"MadGraph runtime_series.{family}.madgraph-standalone.{n}" - cell = _mapping(mode_cells.get(str(n)), context=context) - status = str(cell.get("status")) - if status not in { - "measured", - "failed", - "skipped", - "not-applicable", - }: - raise PublicationMergeError(f"{context}.status is unsupported") - if n > measured_limit: - if status != "not-applicable": - raise PublicationMergeError( - f"{context} must be protocol-scoped not-applicable" - ) - scope = _mapping( - cell.get("protocol_scope"), - context=f"{context}.protocol_scope", - ) - if ( - cell.get("failure_category") - not in _madgraph_protocol_scope_categories( - family, n, measured_limit - ) - or cell.get("censors_higher_multiplicities") is not False - or scope.get("maximum_measured_multiplicity") - != measured_limit - or scope.get("disposition") != "not-applicable" - or not isinstance(cell.get("failure_reason"), str) - or not cell["failure_reason"].strip() - ): - raise PublicationMergeError( - f"{context} has incompatible protocol-scope metadata" - ) - elif status == "not-applicable": - raise PublicationMergeError( - f"{context} cannot be not-applicable at n<={measured_limit}" - ) - status_counts[status] += 1 - if status != "measured": - continue - measured_count_by_family[family] += 1 - metrics = _mapping(cell.get("metrics"), context=f"{context}.metrics") - values = { - key: _positive_number(metrics.get(key), context=f"{context}.{key}") - for key in METRIC_KEYS - } - for key, value in values.items(): - if _finite_number(cell.get(key), context=f"{context}.{key}") != value: - raise PublicationMergeError( - f"{context}.{key} disagrees with the metrics object" - ) - if values["generation_seconds"] >= MAX_GENERATION_SECONDS: - raise PublicationMergeError(f"{context} exceeds one hour") - if values["max_rss_kib"] >= MAX_RSS_KIB: - raise PublicationMergeError(f"{context} reaches 30 GiB RSS") - protocol = _mapping(cell.get("protocol"), context=f"{context}.protocol") - expected_evaluator = ( - "SMATRIX(P,ANS)-generated-complete-helicity-sum" - if helicity_workload == "sum" - else "MATRIX(P,NHEL,IC)-direct" - ) - expected_color_sum = ( - "generated-SMATRIX-summed-and-averaged" - if helicity_workload == "sum" - else "full-unaveraged" - ) - if ( - protocol.get("generation_helicity_coverage") != "all" - or protocol.get("warm_fixed_helicity") - is not (helicity_workload == "fixed") - or protocol.get("helicity_summed") - is not (helicity_workload == "sum") - or protocol.get("evaluator") != expected_evaluator - or protocol.get("color_sum") != expected_color_sum - ): - raise PublicationMergeError( - f"{context} has the wrong helicity protocol" - ) - if helicity_workload == "sum" and ( - protocol.get("warm_helicity_sum") is not True - or protocol.get("timed_helicity_count") != 2 ** (n + 2) - or protocol.get("helicity_sum_implementation") - != "generated-SMATRIX-with-USERHEL-minus-one" - or protocol.get("warmed_native_call_pruning") - != "generated GOODHEL cache may skip structurally zero helicities" - or _finite_number(cell.get("alpha_s"), context=f"{context}.alpha_s") - != campaign_alpha_s - ): - raise PublicationMergeError( - f"{context} has incompatible summed-helicity metadata" - ) - refresh = _mapping( - cell.get("runtime_refresh"), context=f"{context}.runtime_refresh" - ) - if ( - refresh.get("accepted") is not True - or refresh.get("fresh_process") is not True - or refresh.get("scope") != "generation-resource-and-warm-runtime" - ): - raise PublicationMergeError(f"{context} is not a fresh accepted cell") - numerical = _mapping(cell.get("numerical"), context=f"{context}.numerical") - expected_factor = _madgraph_normalization_factor( - family, n, helicity_workload=helicity_workload - ) - if ( - numerical.get("reference_mode") - != _source_mode(family, helicity_workload) - or numerical.get("passes") is not True - or not math.isclose( - _positive_number( - numerical.get("normalization_factor_reference_per_madgraph"), - context=f"{context}.normalization_factor", - ), - expected_factor, - rel_tol=0.0, - abs_tol=1.0e-16, - ) - ): - raise PublicationMergeError(f"{context} has incompatible normalization") - provenance = _mapping( - cell.get("provenance"), context=f"{context}.provenance" - ) - if provenance.get("smatrix_iden") != _expected_madgraph_iden(family, n): - raise PublicationMergeError( - f"{context} has the wrong generated SMATRIX denominator" - ) - if helicity_workload == "sum": - if ( - _finite_number( - provenance.get("source_alpha_s"), - context=f"{context}.provenance.source_alpha_s", - ) - != campaign_alpha_s - or _finite_number( - provenance.get("runtime_alpha_s"), - context=f"{context}.provenance.runtime_alpha_s", - ) - != campaign_alpha_s - or provenance.get("timed_helicity_count") != 2 ** (n + 2) - ): - raise PublicationMergeError( - f"{context} has incompatible summed runtime provenance" - ) - _validate_summed_retained_sources( - provenance, n=n, context=context - ) - source = _mapping( - provenance.get("source_report"), - context=f"{context}.provenance.source_report", - ) - path = source.get("path") - sha256 = source.get("sha256") - expected_pointer = ( - f"cells.{family}.{_source_mode(family, helicity_workload)}.{n}" - ) - if source.get("cell") != expected_pointer: - raise PublicationMergeError(f"{context} has the wrong source cell") - if not isinstance(path, str) or not isinstance(sha256, str): - raise PublicationMergeError(f"{context} lacks source-report identity") - identity = (path, sha256) - if source_identity is None: - source_identity = identity - elif source_identity != identity: - raise PublicationMergeError( - "measured MadGraph cells use different source reports" - ) - - if any(measured_count_by_family[family] < 1 for family in FAMILY_MODES): - raise PublicationMergeError( - "MadGraph must measure at least one cell per family" - ) - expected_status = ( - "complete-with-failures" if status_counts["failed"] else "complete" - ) - if overlay.payload.get("status") != expected_status: - raise PublicationMergeError("MadGraph status disagrees with its cells") - if overlay.payload.get("failure_count") != status_counts["failed"]: - raise PublicationMergeError("MadGraph failure_count disagrees with its cells") - summary = _mapping(overlay.payload.get("summary"), context="MadGraph summary") - if summary.get("runtime_series_status_counts") != dict( - sorted(status_counts.items()) - ): - raise PublicationMergeError("MadGraph summary disagrees with its cells") - if source_identity is None: - raise PublicationMergeError("MadGraph overlay has no measured provenance") - - source_path = _resolve_recorded_path( - source_identity[0], context="MadGraph source report path" - ) - source_document = _load_document("MadGraph source report", source_path) - if source_document.sha256 != source_identity[1]: - raise PublicationMergeError("MadGraph source-report SHA-256 differs") - if source_document.payload.get("schema_version") != SCHEMA_VERSION: - raise PublicationMergeError("MadGraph source report has the wrong schema") - source_host = _measurement_host( - source_document.payload.get("measurement_host"), - context="MadGraph source report measurement_host", - ) - if source_host != measurement_host: - raise PublicationMergeError( - "campaign and MadGraph source report use different measurement hosts" - ) - if helicity_workload == "sum": - source_policy = _mapping( - source_document.payload.get("policy"), context="MadGraph source policy" - ) - if _helicity_workload(source_policy) != "sum": - raise PublicationMergeError( - "MadGraph summed overlay points to a non-summed source report" - ) - source_measurement = _mapping( - source_policy.get("measurement"), - context="MadGraph source measurement policy", - ) - if ( - _positive_number( - source_measurement.get("alpha_s"), context="MadGraph source alpha_s" - ) - != campaign_alpha_s - ): - raise PublicationMergeError("MadGraph source alpha_s differs") - - campaign_cells = _mapping(campaign.payload.get("cells"), context="campaign cells") - for family in FAMILY_MODES: - mode = _source_mode(family, helicity_workload) - mode_cells = _mapping( - _mapping( - campaign_cells.get(family), context=f"campaign cells.{family}" - ).get(mode), - context=f"campaign cells.{family}.{mode}", - ) - overlay_cells = _mapping( - _mapping( - raw_series.get(family), context=f"MadGraph runtime_series.{family}" - ).get("madgraph-standalone"), - context=f"MadGraph runtime_series.{family}.madgraph-standalone", - ) - for n in FINAL_MULTIPLICITIES: - context = f"MadGraph runtime_series.{family}.madgraph-standalone.{n}" - madgraph_cell = _mapping(overlay_cells.get(str(n)), context=context) - if madgraph_cell.get("status") != "measured": - continue - source_cell = _source_cell( - source_document.payload, - family, - mode, - n, - context="MadGraph source report", - ) - if source_cell.get("status") != "measured": - raise PublicationMergeError(f"{context} points to an unmeasured source") - helicity = _validate_helicity( - madgraph_cell.get("helicity"), n=n, context=f"{context}.helicity" - ) - if helicity != _validate_helicity( - source_cell.get("helicity"), - n=n, - context=f"MadGraph source cells.{family}.{mode}.{n}.helicity", - ): - raise PublicationMergeError( - f"{context} helicity differs from its source" - ) - madgraph_paths = _event_identity(madgraph_cell, context=context) - source_paths = tuple( - _resolve_recorded_path(path, context="MadGraph source event path") - for path in _sequence( - source_cell.get("event_paths"), - context="MadGraph source event paths", - ) - ) - if madgraph_paths != source_paths: - raise PublicationMergeError( - f"{context} event paths differ from its source" - ) - factor = _madgraph_normalization_factor( - family, n, helicity_workload=helicity_workload - ) - source_points = _validate_points( - source_cell.get("point_values"), context="MadGraph source point values" - ) - madgraph_points = _validate_points( - madgraph_cell.get("point_values"), context=f"{context}.point_values" - ) - if ( - max( - _relative_error(observed * factor, reference) - for observed, reference in zip( - madgraph_points, source_points, strict=True - ) - ) - > 1.0e-10 - ): - raise PublicationMergeError( - f"{context} numerically differs from its source" - ) - - fresh_cell = _mapping(mode_cells.get(str(n)), context="fresh source cell") - if fresh_cell.get("status") != "measured": - continue - if helicity != _validate_helicity( - fresh_cell.get("helicity"), n=n, context="fresh source helicity" - ): - raise PublicationMergeError(f"{context} differs from fresh helicity") - if tuple(madgraph_cell["event_sha256"]) != _cell_event_hashes( - fresh_cell, context=f"fresh campaign cells.{family}.{mode}.{n}" - ): - raise PublicationMergeError(f"{context} differs from fresh events") - fresh_points = _validate_points( - fresh_cell.get("point_values"), context="fresh source point values" - ) - if ( - max( - _relative_error(observed * factor, reference) - for observed, reference in zip( - madgraph_points, fresh_points, strict=True - ) - ) - > 1.0e-10 - ): - raise PublicationMergeError( - f"{context} numerically differs from the fresh campaign" - ) - return source_document - - -def build_final_report( - *, campaign_path: Path, madgraph_overlay_path: Path -) -> dict[str, Any]: - campaign = _load_document("campaign report", campaign_path) - overlay = _load_document("MadGraph overlay", madgraph_overlay_path) - campaign_host = _measurement_host( - campaign.payload.get("measurement_host"), - context="campaign measurement_host", - ) - overlay_host = _measurement_host( - overlay.payload.get("host"), context="MadGraph overlay host" - ) - if campaign_host != overlay_host: - raise PublicationMergeError( - "campaign and MadGraph overlay use different measurement hosts" - ) - campaign_policy = _validate_campaign_policy(campaign) - helicity_workload = _helicity_workload(campaign_policy) - campaign_counts = _validate_campaign_cells( - campaign, helicity_workload=helicity_workload - ) - _validate_madgraph_policy( - overlay, helicity_workload=helicity_workload - ) - source_document = _validate_madgraph_provenance( - campaign, - overlay, - helicity_workload=helicity_workload, - measurement_host=campaign_host, - ) - - report = deepcopy(campaign.payload) - report_measurement = _mapping( - _mapping(report.get("policy"), context="final report policy").get( - "measurement" - ), - context="final report measurement policy", - ) - report_measurement.pop("fixed_helicity", None) - if helicity_workload == "sum": - report_policy = _mapping(report.get("policy"), context="final report policy") - plot = report_policy.get("plot") - if isinstance(plot, dict): - raw_notes = plot.get("notes") - notes = ( - [str(note) for note in raw_notes] - if isinstance(raw_notes, list) - else [] - ) - notes = [ - note - for note in notes - if not ( - "MadGraph" in note - and ( - "omitted" in note.lower() - or "fixed-helicity" in note.lower() - ) - ) - ] - replacement = ( - "MadGraph standalone uses generated SMATRIX with USERHEL=-1; " - "warmed GOODHEL pruning remains enabled." - ) - if replacement not in notes: - notes.append(replacement) - plot["notes"] = notes - report["kind"] = FINAL_KIND - report["summary"] = { - "cell_status_counts": dict(sorted(campaign_counts.items())), - } - try: - selected._apply_runtime_series_overlay( - report, - selected.SourceReport( - key="madgraph-overlay", - path=overlay.path, - sha256=overlay.sha256, - payload=overlay.payload, - ), - ) - except selected.CompositeError as error: - raise PublicationMergeError(str(error)) from error - external_counts = Counter( - str(cell.get("status")) - for family_series in report["runtime_series"].values() - for mode_cells in family_series.values() - for cell in mode_cells.values() - ) - total_failures = campaign_counts["failed"] + external_counts["failed"] - report["status"] = "complete-with-failures" if total_failures else "complete" - report["failure_count"] = total_failures - report["summary"]["total_failure_count"] = total_failures - report["publication_provenance"] = { - "campaign_report": { - "path": campaign.display_path, - "sha256": campaign.sha256, - "kind": CAMPAIGN_KIND, - "status": campaign.payload["status"], - "failure_count": campaign_counts["failed"], - }, - "madgraph_overlay": { - "path": overlay.display_path, - "sha256": overlay.sha256, - "kind": selected.RUNTIME_SERIES_OVERLAY_KIND, - "status": overlay.payload["status"], - "failure_count": external_counts["failed"], - }, - "madgraph_source_report": { - "path": source_document.display_path, - "sha256": source_document.sha256, - "kind": source_document.payload.get("kind"), - }, - "measurement_host": dict(campaign_host), - "same_host_authenticated": True, - "final_state_multiplicities": list(FINAL_MULTIPLICITIES), - "merge_policy": "fresh-campaign-cells-plus-authenticated-external-series", - } - return report - - -def _write_report(path: Path, report: Mapping[str, Any]) -> None: - output = path.expanduser().resolve(strict=False) - output.parent.mkdir(parents=True, exist_ok=True) - temporary = output.with_suffix(output.suffix + ".tmp") - temporary.write_text( - json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8" - ) - temporary.replace(output) - - -def main() -> int: - arguments = _parser().parse_args() - try: - report = build_final_report( - campaign_path=arguments.campaign_report, - madgraph_overlay_path=arguments.madgraph_overlay, - ) - _write_report(arguments.output, report) - except PublicationMergeError as error: - raise SystemExit(f"error: {error}") from error - print(arguments.output.expanduser().resolve(strict=False)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_scaling_selected_scalar_report.py b/pyamplicol/tools/developer/fft_scaling_selected_scalar_report.py deleted file mode 100644 index 3d0b0664cf..0000000000 --- a/pyamplicol/tools/developer/fft_scaling_selected_scalar_report.py +++ /dev/null @@ -1,1341 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Build the selected-mode scalar FullColor report for final-state n=2..9.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import statistics -from collections import Counter -from collections.abc import Mapping, Sequence -from copy import deepcopy -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -RESULTS = ROOT / "IMPLEMENTATION_DOCS" / "RESULTS" / "fft-scaling-study" -DATA = RESULTS / "data" - -KIND = "pyamplicol-fullcolor-selected-scalar-composite" -OVERLAY_KIND = "pyamplicol-fullcolor-selected-scalar-runtime-overlay" -CLEAN_RUNTIME_OVERLAY_KIND = ( - "pyamplicol-fullcolor-selected-scalar-clean-runtime-overlay" -) -RUNTIME_SERIES_OVERLAY_KIND = ( - "pyamplicol-fullcolor-selected-scalar-runtime-series-overlay" -) -RUNTIME_SERIES_PROGRESS_KIND = ( - "pyamplicol-fullcolor-selected-scalar-runtime-series-progress" -) -SCHEMA_VERSION = 1 -LOW_MULTIPLICITIES = tuple(range(2, 7)) -HIGH_MULTIPLICITIES = tuple(range(7, 10)) -FINAL_MULTIPLICITIES = (*LOW_MULTIPLICITIES, *HIGH_MULTIPLICITIES) -SOURCE_BOUNDARY_AFTER_N = 6 -FAMILY_MODES = { - "gg": ( - "reference-fft", - "amplicol", - "recurrence-direct", - "recurrence-fft", - ), - "ddbar": ("amplicol", "recurrence-direct", "recurrence-fft"), -} -HIGH_MODES = { - "gg": ("reference-fft", "amplicol", "recurrence-fft"), - "ddbar": ("amplicol", "recurrence-fft"), -} -CANDIDATE_MODES = frozenset(("recurrence-direct", "recurrence-fft")) -METRIC_KEYS = ( - "generation_seconds", - "warm_seconds_per_point", - "max_rss_kib", -) -OVERLAY_MULTIPLICITIES = frozenset((7, 8)) -DIRECT_LABEL = "pyAmpliCol - recurrence (n≤6)" -SCALAR_KIND = "pyamplicol-fullcolor-fft-scaling-study" -CANONICAL_KIND = "pyamplicol-fullcolor-fft-scaling-batch128-composite" -RUNTIME_TARGETS = { - "gg": { - "reference-fft": tuple(range(2, 10)), - "amplicol": tuple(range(2, 8)), - "recurrence-direct": tuple(range(2, 7)), - "recurrence-fft": tuple(range(2, 9)), - }, - "ddbar": { - "amplicol": tuple(range(2, 9)), - "recurrence-direct": tuple(range(2, 7)), - "recurrence-fft": tuple(range(2, 10)), - }, -} -RUNTIME_TARGET_COUNT = sum( - len(multiplicities) - for family_modes in RUNTIME_TARGETS.values() - for multiplicities in family_modes.values() -) -EXPECTED_CENSORED_CELLS = { - ("gg", "amplicol", 8): "skipped", - ("gg", "amplicol", 9): "skipped", - ("gg", "recurrence-fft", 9): "failed", - ("ddbar", "amplicol", 9): "failed", -} -RUNTIME_SERIES_MODES = frozenset(("madgraph-standalone",)) -MADGRAPH_MAX_MEASURED_MULTIPLICITY = 6 -MADGRAPH_FAMILY_MAX_MEASURED_MULTIPLICITY = {"gg": 5, "ddbar": 6} -LEGACY_MADGRAPH_WARM_SAMPLE_COUNT = 10 - - -class CompositeError(RuntimeError): - """The source reports cannot form the requested composite without guessing.""" - - -@dataclass(frozen=True, slots=True) -class SourceReport: - key: str - path: Path - sha256: str - payload: dict[str, Any] - - @property - def display_path(self) -> str: - resolved = self.path.expanduser().resolve(strict=False) - try: - return str(resolved.relative_to(ROOT)) - except ValueError: - return str(resolved) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--scalar-report", - type=Path, - default=DATA / "campaign-report-scalar-latency-current.json", - help="scalar warm-runtime source report", - ) - parser.add_argument( - "--canonical-report", - type=Path, - default=DATA / "campaign-report-final.json", - help="canonical low-n cold/resource source report", - ) - parser.add_argument( - "--high-report", - type=Path, - default=DATA / "campaign-report-high-n-scalar.json", - help="scalar high-n source report", - ) - parser.add_argument( - "--runtime-overlay", - type=Path, - help=( - "optional accepted warm-runtime overlay; supports the historical " - "gg recurrence-FFT n=7/n=8 refresh and the complete clean-runtime " - "refresh" - ), - ) - parser.add_argument( - "--runtime-series-overlay", - type=Path, - help=( - "optional sparse runtime-only comparison series, such as MadGraph " - "standalone" - ), - ) - parser.add_argument( - "--output", - type=Path, - default=DATA / "campaign-report-scalar-selected-n2-n9.json", - help="output composite report", - ) - return parser - - -def _load_source(key: str, path: Path, *, require_cells: bool = True) -> SourceReport: - try: - raw = path.read_bytes() - payload = json.loads(raw) - except (OSError, json.JSONDecodeError) as error: - raise CompositeError(f"cannot read {key} report {path}: {error}") from error - if not isinstance(payload, dict): - raise CompositeError(f"{key} report must be a JSON object") - if require_cells and not isinstance(payload.get("cells"), dict): - raise CompositeError(f"{key} report must contain a cells object") - return SourceReport( - key=key, - path=path, - sha256=hashlib.sha256(raw).hexdigest(), - payload=payload, - ) - - -def _mapping(value: object, *, context: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise CompositeError(f"{context} must be an object") - return value - - -def _validate_source_contract( - source: SourceReport, - *, - expected_kind: str, - expected_multiplicities: Sequence[int], -) -> None: - if source.payload.get("kind") != expected_kind: - raise CompositeError(f"{source.key} report kind must be {expected_kind!r}") - if source.payload.get("schema_version") != SCHEMA_VERSION: - raise CompositeError(f"{source.key} report schema_version must be 1") - policy = _mapping(source.payload.get("policy"), context=f"{source.key} policy") - raw_multiplicities = policy.get("final_state_multiplicities") - if not isinstance(raw_multiplicities, Sequence) or isinstance( - raw_multiplicities, str - ): - raise CompositeError( - f"{source.key} policy.final_state_multiplicities must be an array" - ) - if tuple(raw_multiplicities) != tuple(expected_multiplicities): - raise CompositeError( - f"{source.key} report multiplicities must be " - f"{list(expected_multiplicities)}" - ) - - -def _cell(source: SourceReport, family: str, mode: str, n: int) -> dict[str, Any]: - context = f"{source.key} cells.{family}.{mode}.{n}" - cells = _mapping(source.payload["cells"], context=f"{source.key} cells") - family_cells = _mapping(cells.get(family), context=f"{source.key} cells.{family}") - mode_cells = _mapping( - family_cells.get(mode), context=f"{source.key} cells.{family}.{mode}" - ) - raw_cell = _mapping(mode_cells.get(str(n)), context=context) - return deepcopy(dict(raw_cell)) - - -def _positive_number(value: object, *, context: str) -> float: - if isinstance(value, bool) or not isinstance(value, int | float): - raise CompositeError(f"{context} must be a positive finite number") - result = float(value) - if not math.isfinite(result) or result <= 0.0: - raise CompositeError(f"{context} must be a positive finite number") - return result - - -def _finite_number(value: object, *, context: str) -> float: - if isinstance(value, bool) or not isinstance(value, int | float): - raise CompositeError(f"{context} must be a finite number") - result = float(value) - if not math.isfinite(result): - raise CompositeError(f"{context} must be a finite number") - return result - - -def _metric(cell: Mapping[str, Any], key: str, *, context: str) -> float: - metrics = _mapping(cell.get("metrics"), context=f"{context}.metrics") - return _positive_number(metrics.get(key), context=f"{context}.metrics.{key}") - - -def _source_pointer(source: SourceReport, family: str, mode: str, n: int) -> str: - return f"{source.key}:cells.{family}.{mode}.{n}" - - -def _measured_cell( - source: SourceReport, family: str, mode: str, n: int -) -> dict[str, Any]: - cell = _cell(source, family, mode, n) - if cell.get("status") != "measured": - raise CompositeError( - f"{_source_pointer(source, family, mode, n)} must be measured" - ) - return cell - - -def _low_cell( - scalar: SourceReport, - canonical: SourceReport, - family: str, - mode: str, - n: int, -) -> dict[str, Any]: - scalar_cell = _measured_cell(scalar, family, mode, n) - canonical_cell = _measured_cell(canonical, family, mode, n) - rss_source = canonical if mode in CANDIDATE_MODES else scalar - rss_cell = canonical_cell if mode in CANDIDATE_MODES else scalar_cell - - result = scalar_cell - result["metrics"] = { - "generation_seconds": _metric( - canonical_cell, - "generation_seconds", - context=_source_pointer(canonical, family, mode, n), - ), - "warm_seconds_per_point": _metric( - scalar_cell, - "warm_seconds_per_point", - context=_source_pointer(scalar, family, mode, n), - ), - "max_rss_kib": _metric( - rss_cell, - "max_rss_kib", - context=_source_pointer(rss_source, family, mode, n), - ), - } - if mode == "recurrence-direct": - result["label"] = DIRECT_LABEL - result["plot_provenance"] = { - "status": _source_pointer(scalar, family, mode, n), - "metrics": { - "generation_seconds": _source_pointer(canonical, family, mode, n), - "warm_seconds_per_point": _source_pointer(scalar, family, mode, n), - "max_rss_kib": _source_pointer(rss_source, family, mode, n), - }, - } - return result - - -def _high_cell(high: SourceReport, family: str, mode: str, n: int) -> dict[str, Any]: - result = _cell(high, family, mode, n) - status = result.get("status") - if status not in {"measured", "failed", "skipped"}: - raise CompositeError( - f"{_source_pointer(high, family, mode, n)} has unsupported status " - f"{status!r}" - ) - provenance: dict[str, Any] = {"status": _source_pointer(high, family, mode, n)} - if status == "measured": - for metric in METRIC_KEYS: - _metric( - result, - metric, - context=_source_pointer(high, family, mode, n), - ) - provenance["metrics"] = { - metric: _source_pointer(high, family, mode, n) for metric in METRIC_KEYS - } - result["plot_provenance"] = provenance - return result - - -def _policy(high: SourceReport) -> dict[str, Any]: - high_policy = _mapping(high.payload.get("policy"), context="high policy") - high_families = _mapping( - high_policy.get("process_families"), context="high policy.process_families" - ) - process_families: dict[str, Any] = {} - for family, modes in FAMILY_MODES.items(): - source_family = _mapping( - high_families.get(family), - context=f"high policy.process_families.{family}", - ) - expression = source_family.get("expression") - ratio_reference = source_family.get("ratio_reference") - if not isinstance(expression, str) or not isinstance(ratio_reference, str): - raise CompositeError(f"high policy for {family} lacks plot metadata") - process_families[family] = { - "expression": expression, - "modes": list(modes), - "ratio_reference": ratio_reference, - } - return { - "final_state_multiplicities": list(FINAL_MULTIPLICITIES), - "measurement": { - "alpha_s": 0.118, - "color_accuracy": "full", - "fixed_helicity": True, - "n_definition": "final-state-particle-count", - "warm_benchmark_batch_size": 1, - "warm_samples": 10, - "source_boundary_after_n": SOURCE_BOUNDARY_AFTER_N, - "warm_timing_metric": ( - "scalar latency: n=2..6 from scalar-latency-current and " - "n=7..9 from high-n-scalar" - ), - "generation_metric": ( - "cold-to-ready telemetry: n=2..6 from canonical-final and " - "n=7..9 from high-n-scalar" - ), - "rss_metric": ( - "implementation RSS: Reference FFT and AmpliCol n=2..6 use " - "scalar implementation-self RSS; pyAmpliCol n=2..6 uses the " - "canonical max of generation-child and runtime-self RSS; " - "n=7..9 retains high-n-scalar definitions" - ), - }, - "plot": { - "source_boundary_after_n": SOURCE_BOUNDARY_AFTER_N, - "source_boundary_label": "n=2..6 / n=7..9 source boundary", - "metric_source_boundaries": { - metric: { - "source_boundary_after_n": SOURCE_BOUNDARY_AFTER_N, - "source_boundary_label": "n=2..6 / n=7..9 source boundary", - } - for metric in METRIC_KEYS - }, - }, - "process_families": process_families, - } - - -def _relative_error(left: float, right: float) -> float: - if left == right: - return 0.0 - return abs(left - right) / max(abs(left), abs(right), 1.0e-300) - - -def _load_overlay(path: Path) -> SourceReport: - source = _load_source("runtime-overlay", path) - if source.payload.get("schema_version") != SCHEMA_VERSION: - raise CompositeError("runtime overlay schema_version must be 1") - return source - - -def _apply_runtime_overlay(report: dict[str, Any], overlay: SourceReport) -> None: - if overlay.payload.get("kind") != OVERLAY_KIND: - raise CompositeError(f"runtime overlay kind must be {OVERLAY_KIND!r}") - raw_cells = _mapping(overlay.payload.get("cells"), context="runtime-overlay cells") - if not raw_cells: - raise CompositeError("runtime overlay cells must not be empty") - unexpected = set(raw_cells) - {str(n) for n in OVERLAY_MULTIPLICITIES} - if unexpected: - raise CompositeError( - "runtime overlay may target only gg recurrence-fft n=7 or n=8; " - f"got {sorted(unexpected)}" - ) - - for raw_n, raw_overlay_cell in raw_cells.items(): - n = int(raw_n) - overlay_cell = _mapping( - raw_overlay_cell, context=f"runtime-overlay cells.{raw_n}" - ) - warm = _positive_number( - overlay_cell.get("warm_seconds_per_point"), - context=f"runtime-overlay cells.{raw_n}.warm_seconds_per_point", - ) - samples_raw = overlay_cell.get("warm_samples_seconds") - if not isinstance(samples_raw, Sequence) or isinstance(samples_raw, str): - raise CompositeError( - f"runtime-overlay cells.{raw_n}.warm_samples_seconds " - "must contain ten samples" - ) - samples = [ - _positive_number( - value, - context=f"runtime-overlay cells.{raw_n}.warm_samples_seconds", - ) - for value in samples_raw - ] - if len(samples) != 10: - raise CompositeError( - f"runtime-overlay cells.{raw_n}.warm_samples_seconds " - "must contain ten samples" - ) - if not math.isclose(statistics.median(samples), warm, rel_tol=1e-12): - raise CompositeError( - f"runtime-overlay cells.{raw_n} warm value is not the sample median" - ) - - refresh = deepcopy( - dict( - _mapping( - overlay_cell.get("runtime_refresh"), - context=f"runtime-overlay cells.{raw_n}.runtime_refresh", - ) - ) - ) - if refresh.get("accepted") is not True: - raise CompositeError( - f"runtime-overlay cells.{raw_n}.runtime_refresh.accepted must be true" - ) - points_raw = overlay_cell.get("point_values") - if not isinstance(points_raw, Sequence) or isinstance(points_raw, str): - raise CompositeError( - f"runtime-overlay cells.{raw_n}.point_values must be an array" - ) - points = [ - _finite_number(value, context=f"runtime-overlay cells.{raw_n}.point_values") - for value in points_raw - ] - - cell = report["cells"]["gg"]["recurrence-fft"][raw_n] - base_points_raw = cell.get("point_values") - if not isinstance(base_points_raw, Sequence) or isinstance( - base_points_raw, str - ): - raise CompositeError(f"composite gg recurrence-fft n={n} lacks points") - base_points = [float(value) for value in base_points_raw] - if len(points) != len(base_points): - raise CompositeError( - f"runtime-overlay cells.{raw_n}.point_values has the wrong length" - ) - maximum_error = max( - ( - _relative_error(left, right) - for left, right in zip(points, base_points, strict=True) - ), - default=0.0, - ) - if maximum_error > 1.0e-10: - raise CompositeError( - f"runtime-overlay cells.{raw_n} point values disagree " - f"(maximum relative error {maximum_error:.3e})" - ) - - cell["metrics"]["warm_seconds_per_point"] = warm - probe = _mapping(cell.get("probe"), context=f"composite gg recurrence n={n}") - updated_probe = deepcopy(dict(probe)) - updated_probe["warm_median_seconds"] = warm - updated_probe["warm_samples_seconds"] = samples - updated_probe["point_values"] = points - cell["probe"] = updated_probe - cell["point_values"] = points - previous_refresh = cell.get("runtime_refresh") - refresh["overlay_source"] = f"runtime-overlay:cells.{raw_n}" - refresh["maximum_relative_point_error_against_high_report"] = maximum_error - if isinstance(previous_refresh, Mapping): - refresh["supersedes"] = deepcopy(dict(previous_refresh)) - cell["runtime_refresh"] = refresh - cell["plot_provenance"]["metrics"]["warm_seconds_per_point"] = ( - f"runtime-overlay:cells.{raw_n}" - ) - - -def _runtime_target_keys() -> set[tuple[str, str, int]]: - return { - (family, mode, n) - for family, family_modes in RUNTIME_TARGETS.items() - for mode, multiplicities in family_modes.items() - for n in multiplicities - } - - -def _overlay_samples( - raw_cell: Mapping[str, Any], *, context: str, expected_count: int | Sequence[int] -) -> tuple[float, list[float]]: - if isinstance(expected_count, int) and not isinstance(expected_count, bool): - expected_counts = {expected_count} - elif isinstance(expected_count, Sequence) and not isinstance(expected_count, str): - expected_counts = { - value - for value in expected_count - if isinstance(value, int) and not isinstance(value, bool) - } - else: - expected_counts = set() - if not expected_counts: - raise CompositeError(f"{context} has no valid expected warm sample count") - warm = _positive_number( - raw_cell.get("warm_seconds_per_point"), - context=f"{context}.warm_seconds_per_point", - ) - raw_samples = raw_cell.get("warm_samples_seconds") - if not isinstance(raw_samples, Sequence) or isinstance(raw_samples, str): - raise CompositeError(f"{context}.warm_samples_seconds must be an array") - samples = [ - _positive_number(value, context=f"{context}.warm_samples_seconds") - for value in raw_samples - ] - if len(samples) not in expected_counts: - expected = " or ".join(str(value) for value in sorted(expected_counts)) - raise CompositeError( - f"{context}.warm_samples_seconds must contain {expected} samples" - ) - if not math.isclose(statistics.median(samples), warm, rel_tol=1e-12): - raise CompositeError(f"{context} warm value is not the sample median") - return warm, samples - - -def _overlay_points( - raw_cell: Mapping[str, Any], - base_cell: Mapping[str, Any], - *, - context: str, -) -> tuple[list[float], float]: - raw_points = raw_cell.get("point_values") - if not isinstance(raw_points, Sequence) or isinstance(raw_points, str): - raise CompositeError(f"{context}.point_values must be an array") - points = [ - _finite_number(value, context=f"{context}.point_values") for value in raw_points - ] - base_points_raw = base_cell.get("point_values") - if not isinstance(base_points_raw, Sequence) or isinstance(base_points_raw, str): - raise CompositeError(f"{context} base cell lacks point values") - base_points = [ - _finite_number(value, context=f"{context} base point values") - for value in base_points_raw - ] - if len(points) != len(base_points) or not points: - raise CompositeError(f"{context}.point_values has the wrong length") - maximum_error = max( - _relative_error(left, right) - for left, right in zip(points, base_points, strict=True) - ) - if maximum_error > 1.0e-10: - raise CompositeError( - f"{context}.point_values disagree with the retained inputs " - f"(maximum relative error {maximum_error:.3e})" - ) - return points, maximum_error - - -def _apply_clean_runtime_overlay(report: dict[str, Any], overlay: SourceReport) -> None: - if overlay.payload.get("kind") != CLEAN_RUNTIME_OVERLAY_KIND: - raise CompositeError( - f"clean runtime overlay kind must be {CLEAN_RUNTIME_OVERLAY_KIND!r}" - ) - if overlay.payload.get("status") != "complete": - raise CompositeError("clean runtime overlay status must be 'complete'") - raw_cells = _mapping( - overlay.payload.get("cells"), context="clean-runtime-overlay cells" - ) - observed: dict[tuple[str, str, int], Mapping[str, Any]] = {} - for family, raw_family_cells in raw_cells.items(): - family_cells = _mapping( - raw_family_cells, context=f"clean-runtime-overlay cells.{family}" - ) - for mode, raw_mode_cells in family_cells.items(): - mode_cells = _mapping( - raw_mode_cells, - context=f"clean-runtime-overlay cells.{family}.{mode}", - ) - for raw_n, raw_cell in mode_cells.items(): - try: - n = int(raw_n) - except (TypeError, ValueError) as error: - raise CompositeError( - "clean runtime overlay multiplicities must be integers" - ) from error - key = (str(family), str(mode), n) - if key in observed: - raise CompositeError(f"clean runtime overlay repeats {key}") - observed[key] = _mapping( - raw_cell, - context=(f"clean-runtime-overlay cells.{family}.{mode}.{raw_n}"), - ) - expected = _runtime_target_keys() - if set(observed) != expected: - missing = sorted(expected - set(observed)) - extra = sorted(set(observed) - expected) - raise CompositeError( - "clean runtime overlay must contain exactly " - f"{RUNTIME_TARGET_COUNT} measurable cells; missing={missing}, " - f"extra={extra}" - ) - - raw_censored = _mapping( - overlay.payload.get("censored_cells"), - context="clean-runtime-overlay censored_cells", - ) - observed_censored: dict[tuple[str, str, int], Mapping[str, Any]] = {} - for family, raw_family_cells in raw_censored.items(): - for mode, raw_mode_cells in _mapping( - raw_family_cells, - context=f"clean-runtime-overlay censored_cells.{family}", - ).items(): - for raw_n, raw_cell in _mapping( - raw_mode_cells, - context=(f"clean-runtime-overlay censored_cells.{family}.{mode}"), - ).items(): - try: - n = int(raw_n) - except (TypeError, ValueError) as error: - raise CompositeError( - "clean runtime overlay censored multiplicities must be integers" - ) from error - key = (str(family), str(mode), n) - if key in observed_censored: - raise CompositeError( - f"clean runtime overlay repeats censored cell {key}" - ) - observed_censored[key] = _mapping( - raw_cell, - context=( - f"clean-runtime-overlay censored_cells.{family}.{mode}.{raw_n}" - ), - ) - if set(observed_censored) != set(EXPECTED_CENSORED_CELLS): - raise CompositeError( - "clean runtime overlay must preserve exactly the four resource-" - "censored cells" - ) - for key, expected_status in EXPECTED_CENSORED_CELLS.items(): - if observed_censored[key].get("status") != expected_status: - raise CompositeError( - f"clean runtime overlay censored cell {key} changed status" - ) - family, mode, n = key - if report["cells"][family][mode][str(n)].get("status") != expected_status: - raise CompositeError(f"composite censored cell {key} changed status") - - for family, mode, n in sorted( - expected, key=lambda value: (value[2], value[0], value[1]) - ): - context = f"clean-runtime-overlay cells.{family}.{mode}.{n}" - raw_cell = observed[(family, mode, n)] - if raw_cell.get("status") != "measured": - raise CompositeError(f"{context}.status must be 'measured'") - base_cell = report["cells"][family][mode][str(n)] - if base_cell.get("status") != "measured": - raise CompositeError(f"{context} targets a non-measured base cell") - for key, expected_value in ( - ("family", family), - ("mode", mode), - ("n", n), - ("process", base_cell.get("process")), - ("total_external", n + 2), - ("helicity", base_cell.get("helicity")), - ("event_paths", base_cell.get("event_paths")), - ): - if raw_cell.get(key) != expected_value: - raise CompositeError(f"{context}.{key} has the wrong identity") - event_sha256 = raw_cell.get("event_sha256") - if ( - not isinstance(event_sha256, Sequence) - or isinstance(event_sha256, str) - or len(event_sha256) != 10 - or any( - not isinstance(value, str) - or len(value) != 64 - or any(character not in "0123456789abcdef" for character in value) - for value in event_sha256 - ) - ): - raise CompositeError( - f"{context}.event_sha256 must contain ten lowercase SHA-256 values" - ) - expected_samples = 1 if mode == "amplicol" else 10 - warm, samples = _overlay_samples( - raw_cell, context=context, expected_count=expected_samples - ) - points, maximum_error = _overlay_points(raw_cell, base_cell, context=context) - refresh = deepcopy( - dict( - _mapping( - raw_cell.get("runtime_refresh"), - context=f"{context}.runtime_refresh", - ) - ) - ) - if ( - refresh.get("accepted") is not True - or refresh.get("fresh_process") is not True - or refresh.get("scope") != "warm-runtime-only" - ): - raise CompositeError( - f"{context}.runtime_refresh must describe one accepted fresh " - "warm-runtime-only process" - ) - refresh["overlay_source"] = f"clean-runtime-overlay:cells.{family}.{mode}.{n}" - refresh["maximum_relative_point_error_against_retained_input"] = maximum_error - refresh["event_sha256"] = deepcopy(list(event_sha256)) - previous_refresh = base_cell.get("runtime_refresh") - if isinstance(previous_refresh, Mapping): - refresh["supersedes"] = deepcopy(dict(previous_refresh)) - base_cell["metrics"]["warm_seconds_per_point"] = warm - base_cell["point_values"] = points - base_cell["runtime_refresh"] = refresh - base_cell["plot_provenance"]["metrics"]["warm_seconds_per_point"] = ( - f"clean-runtime-overlay:cells.{family}.{mode}.{n}" - ) - probe = base_cell.get("probe") - if isinstance(probe, Mapping): - updated_probe = deepcopy(dict(probe)) - updated_probe["warm_median_seconds"] = warm - updated_probe["warm_samples_seconds"] = samples - updated_probe["point_values"] = points - base_cell["probe"] = updated_probe - reference = base_cell.get("reference") - if isinstance(reference, Mapping): - updated_reference = deepcopy(dict(reference)) - updated_reference["warm_median_seconds"] = warm - updated_reference["warm_samples_seconds"] = samples - updated_reference["matrix_elements"] = points - base_cell["reference"] = updated_reference - adaptive_points = raw_cell.get("adaptive_runtime_points") - if mode == "amplicol": - if ( - not isinstance(adaptive_points, int) - or isinstance(adaptive_points, bool) - or adaptive_points < 1 - ): - raise CompositeError( - f"{context}.adaptive_runtime_points must be positive" - ) - base_cell["adaptive_runtime_points"] = adaptive_points - - measurement = report["policy"]["measurement"] - measurement["warm_timing_metric"] = ( - "clean warmed-runtime refresh: all 46 measurable selected cells use " - "fresh processes on retained deterministic inputs" - ) - measurement["warm_samples"] = { - "reference-fft": 10, - "pyamplicol": 10, - "amplicol": 1, - } - measurement["warm_timer_source"] = "process-cpu-time" - measurement["warm_target_seconds"] = 0.25 - measurement["warm_runtime_artifact_policy"] = ( - "runtime-compatible generated artifacts and external standalone inputs " - "are retained; generation and RSS metrics remain historical" - ) - plot = report["policy"]["plot"] - boundaries = plot.get("metric_source_boundaries") - if not isinstance(boundaries, dict): - raise CompositeError("composite plot metric boundaries are malformed") - boundaries["warm_seconds_per_point"] = None - report["runtime_refresh"] = { - "scope": "warm-runtime-only", - "coverage": "complete", - "fresh_measured_cell_count": RUNTIME_TARGET_COUNT, - "preserved_resource_censored_cell_count": len(EXPECTED_CENSORED_CELLS), - } - - -def _process_expression(family: str, n: int) -> str: - extra = " ".join("g" for _ in range(n - 2)) - if family == "gg": - return "g g > g g" + (f" {extra}" if extra else "") - return "d d~ > d d~" + (f" {extra}" if extra else "") - - -def _helicity_workload_from_policy( - policy: Mapping[str, Any], *, legacy_default: str = "fixed" -) -> str: - measurement = _mapping( - policy.get("measurement", policy), context="helicity workload policy" - ) - markers: set[str] = set() - declared = measurement.get("helicity_workload") - if declared is not None: - markers.add(str(declared)) - if measurement.get("warm_fixed_helicity") is True: - markers.add("fixed") - if measurement.get("warm_helicity_sum") is True: - markers.add("sum") - if len(markers) > 1 or any(value not in {"fixed", "sum"} for value in markers): - raise CompositeError("helicity workload policy is contradictory") - return next(iter(markers), legacy_default) - - -def _madgraph_family_measured_limits( - policy: Mapping[str, Any] | None, -) -> dict[str, int]: - if policy is None: - return { - family: MADGRAPH_MAX_MEASURED_MULTIPLICITY for family in FAMILY_MODES - } - raw_limits = policy.get("family_maximum_measured_multiplicity") - if raw_limits is None: - return { - family: MADGRAPH_MAX_MEASURED_MULTIPLICITY for family in FAMILY_MODES - } - if not isinstance(raw_limits, Mapping): - raise CompositeError( - "runtime series overlay has invalid family multiplicity limits" - ) - limits: dict[str, int] = {} - for family in FAMILY_MODES: - value = raw_limits.get(family) - if ( - isinstance(value, bool) - or not isinstance(value, int) - or value < 2 - or value > MADGRAPH_MAX_MEASURED_MULTIPLICITY - ): - raise CompositeError( - "runtime series overlay has invalid family multiplicity limits" - ) - limits[family] = int(value) - if set(raw_limits) != set(FAMILY_MODES): - raise CompositeError( - "runtime series overlay has invalid family multiplicity limits" - ) - return limits - - -def _madgraph_protocol_scope_categories(family: str, n: int, limit: int) -> set[str]: - categories = {f"protocol-scope-n>{limit}"} - if family == "gg" and n == 6: - categories.add("protocol-scope-pure-gluon-n6") - return categories - - -def _madgraph_warm_sample_count(policy: Mapping[str, Any] | None) -> int: - if policy is None: - return LEGACY_MADGRAPH_WARM_SAMPLE_COUNT - raw_count = policy.get("warm_sample_count") - if raw_count is None: - return LEGACY_MADGRAPH_WARM_SAMPLE_COUNT - if isinstance(raw_count, bool) or not isinstance(raw_count, int) or raw_count < 1: - raise CompositeError("runtime series overlay has invalid warm_sample_count") - return raw_count - - -def _apply_runtime_series_overlay( - report: dict[str, Any], overlay: SourceReport -) -> None: - overlay_kind = overlay.payload.get("kind") - if overlay_kind not in { - RUNTIME_SERIES_OVERLAY_KIND, - RUNTIME_SERIES_PROGRESS_KIND, - }: - raise CompositeError( - "runtime series source must be a terminal overlay or authenticated " - "sparse progress snapshot" - ) - sparse_progress = overlay_kind == RUNTIME_SERIES_PROGRESS_KIND - raw_series = _mapping( - overlay.payload.get("runtime_series"), context="runtime-series-overlay" - ) - report_policy = _mapping(report.get("policy"), context="report policy") - report_workload = _helicity_workload_from_policy(report_policy) - raw_multiplicities = report_policy.get("final_state_multiplicities") - if ( - not isinstance(raw_multiplicities, Sequence) - or isinstance(raw_multiplicities, str) - or not raw_multiplicities - or any( - not isinstance(value, int) or isinstance(value, bool) or value < 2 - for value in raw_multiplicities - ) - ): - raise CompositeError("report has invalid final-state multiplicities") - multiplicities = tuple(int(value) for value in raw_multiplicities) - raw_overlay_policy = overlay.payload.get("policy") - overlay_policy: Mapping[str, Any] | None = None - if raw_overlay_policy is None and not sparse_progress: - # Historical terminal overlays predate their explicit policy block and - # cover the report's complete multiplicity set by contract. - raw_overlay_multiplicities: object = list(multiplicities) - else: - overlay_policy = _mapping( - raw_overlay_policy, context="runtime-series-overlay policy" - ) - raw_overlay_multiplicities = overlay_policy.get("final_state_multiplicities") - overlay_workload = _helicity_workload_from_policy(overlay_policy) - if overlay_workload != report_workload: - raise CompositeError( - "runtime series overlay helicity workload differs from the report" - ) - family_limits = _madgraph_family_measured_limits(overlay_policy) - expected_warm_samples = _madgraph_warm_sample_count(overlay_policy) - if ( - not isinstance(raw_overlay_multiplicities, Sequence) - or isinstance(raw_overlay_multiplicities, str) - or not raw_overlay_multiplicities - or any( - not isinstance(value, int) or isinstance(value, bool) - for value in raw_overlay_multiplicities - ) - ): - raise CompositeError("runtime series overlay has invalid multiplicities") - overlay_multiplicities = tuple(int(value) for value in raw_overlay_multiplicities) - if overlay_multiplicities != tuple( - value for value in multiplicities if value in set(overlay_multiplicities) - ): - raise CompositeError( - "runtime series overlay multiplicities must be an ordered subset " - "of the report" - ) - if set(raw_series) != set(FAMILY_MODES): - raise CompositeError("runtime series overlay must contain gg and ddbar") - copied: dict[str, dict[str, dict[str, Any]]] = {} - status_counts: Counter[str] = Counter() - for family, raw_family_series in raw_series.items(): - family_series = _mapping( - raw_family_series, context=f"runtime-series-overlay.{family}" - ) - if set(family_series) != RUNTIME_SERIES_MODES: - raise CompositeError( - f"runtime-series-overlay.{family} must contain only MadGraph standalone" - ) - copied[family] = {} - for mode, raw_mode_cells in family_series.items(): - mode_cells = _mapping( - raw_mode_cells, - context=f"runtime-series-overlay.{family}.{mode}", - ) - expected_ns = {str(n) for n in overlay_multiplicities} - observed_ns = set(mode_cells) - if observed_ns - expected_ns or ( - not sparse_progress and observed_ns != expected_ns - ): - raise CompositeError( - f"runtime-series-overlay.{family}.{mode} must describe exactly " - f"n={list(overlay_multiplicities)}" - ) - frontier_seen = False - copied_cells: dict[str, Any] = {} - for n in ( - value for value in overlay_multiplicities if str(value) in mode_cells - ): - context = f"runtime-series-overlay.{family}.{mode}.{n}" - cell = deepcopy(dict(_mapping(mode_cells[str(n)], context=context))) - status = cell.get("status") - if status not in { - "measured", - "failed", - "skipped", - "not-applicable", - }: - raise CompositeError(f"{context}.status is unsupported") - measured_limit = family_limits[family] - if n > measured_limit: - if status != "not-applicable": - raise CompositeError( - f"{context} must be protocol-scoped not-applicable" - ) - elif status == "not-applicable": - raise CompositeError( - f"{context} cannot be not-applicable at n<={measured_limit}" - ) - if status == "measured" and frontier_seen: - raise CompositeError( - f"{context} resumes measurement after the series frontier" - ) - if ( - status == "failed" - and cell.get("censors_higher_multiplicities") is True - ): - if frontier_seen: - raise CompositeError( - f"{context} repeats the series failure frontier" - ) - frontier_seen = True - if ( - status == "skipped" - and cell.get("censors_higher_multiplicities") is True - and not frontier_seen - ): - raise CompositeError( - f"{context} skips before a recorded failure frontier" - ) - for key, expected_value in ( - ("family", family), - ("mode", mode), - ("n", n), - ("process", _process_expression(family, n)), - ("total_external", n + 2), - ): - if cell.get(key) != expected_value: - raise CompositeError(f"{context}.{key} has the wrong identity") - label = cell.get("label") - if not isinstance(label, str) or not label.strip(): - raise CompositeError(f"{context}.label is required") - if status == "not-applicable": - scope = _mapping( - cell.get("protocol_scope"), - context=f"{context}.protocol_scope", - ) - if ( - cell.get("failure_category") - not in _madgraph_protocol_scope_categories( - family, n, measured_limit - ) - or cell.get("censors_higher_multiplicities") is not False - or scope.get("maximum_measured_multiplicity") - != measured_limit - or scope.get("disposition") != "not-applicable" - ): - raise CompositeError( - f"{context} has incompatible protocol-scope metadata" - ) - if status == "measured": - _overlay_samples( - cell, - context=context, - expected_count=( - expected_warm_samples, - LEGACY_MADGRAPH_WARM_SAMPLE_COUNT, - ), - ) - metrics = _mapping( - cell.get("metrics"), context=f"{context}.metrics" - ) - measured_metrics = { - key: _finite_number( - metrics.get(key), context=f"{context}.metrics.{key}" - ) - for key in METRIC_KEYS - } - if any(value <= 0.0 for value in measured_metrics.values()): - raise CompositeError( - f"{context}.metrics must contain three positive values" - ) - if not math.isclose( - measured_metrics["warm_seconds_per_point"], - _finite_number( - cell.get("warm_seconds_per_point"), - context=f"{context}.warm_seconds_per_point", - ), - rel_tol=0.0, - abs_tol=0.0, - ): - raise CompositeError( - f"{context} warm metric and timing median disagree" - ) - helicity = cell.get("helicity") - if ( - not isinstance(helicity, Sequence) - or isinstance(helicity, str) - or len(helicity) != n + 2 - or any( - not isinstance(value, int) - or isinstance(value, bool) - or value not in (-1, 1) - for value in helicity - ) - ): - raise CompositeError(f"{context}.helicity is invalid") - matrix_element = _finite_number( - cell.get("matrix_element"), - context=f"{context}.matrix_element", - ) - point_values_raw = cell.get("point_values") - if not isinstance(point_values_raw, Sequence) or isinstance( - point_values_raw, str - ): - raise CompositeError( - f"{context}.point_values must contain ten values" - ) - point_values = [ - _finite_number(value, context=f"{context}.point_values") - for value in point_values_raw - ] - if ( - len(point_values) != 10 - or _relative_error(matrix_element, point_values[0]) > 1.0e-12 - ): - raise CompositeError( - f"{context}.matrix_element must match point_values[0]" - ) - event_paths = cell.get("event_paths") - event_sha256 = cell.get("event_sha256") - if ( - not isinstance(event_paths, Sequence) - or isinstance(event_paths, str) - or len(event_paths) != 10 - or any(not isinstance(value, str) for value in event_paths) - or not isinstance(event_sha256, Sequence) - or isinstance(event_sha256, str) - or len(event_sha256) != 10 - or any( - not isinstance(value, str) - or len(value) != 64 - or any( - character not in "0123456789abcdef" - for character in value - ) - for value in event_sha256 - ) - ): - raise CompositeError( - f"{context} event identity must contain ten paths and " - "SHA-256 values" - ) - protocol = _mapping( - cell.get("protocol"), context=f"{context}.protocol" - ) - expected_protocol = { - "evaluator": ( - "SMATRIX(P,ANS)-generated-complete-helicity-sum" - if report_workload == "sum" - else "MATRIX(P,NHEL,IC)-direct" - ), - "helicity_summed": report_workload == "sum", - "color_sum": ( - "generated-SMATRIX-summed-and-averaged" - if report_workload == "sum" - else "full-unaveraged" - ), - "batch_size": 1, - "initialization_included": False, - } - if report_workload == "sum": - expected_protocol.update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "timed_helicity_count": 2 ** (n + 2), - } - ) - if ( - cell.get("helicity_workload") != "sum" - or cell.get("warm_fixed_helicity") is not False - or cell.get("warm_helicity_sum") is not True - or cell.get("timed_helicity_count") != 2 ** (n + 2) - ): - raise CompositeError( - f"{context} summed workload metadata is incompatible" - ) - if any( - protocol.get(key) != value - for key, value in expected_protocol.items() - ): - raise CompositeError(f"{context}.protocol is incompatible") - else: - if ( - not isinstance(cell.get("failure_reason"), str) - or not cell["failure_reason"].strip() - ): - raise CompositeError(f"{context}.failure_reason is required") - status_counts[str(status)] += 1 - copied_cells[str(n)] = cell - copied[family][mode] = copied_cells - report["runtime_series"] = copied - report["summary"]["runtime_series_status_counts"] = dict( - sorted(status_counts.items()) - ) - - -def apply_runtime_series_source(report: dict[str, Any], overlay: SourceReport) -> None: - """Validate, attach, and provenance-record one immutable runtime series.""" - - _apply_runtime_series_overlay(report, overlay) - plot_provenance = report.setdefault("plot_provenance", {}) - if not isinstance(plot_provenance, dict): - raise CompositeError("report plot_provenance must be an object") - source_reports = plot_provenance.setdefault("source_reports", {}) - if not isinstance(source_reports, dict): - raise CompositeError("report source-report provenance must be an object") - source_reports[overlay.key] = { - "path": overlay.display_path, - "sha256": overlay.sha256, - } - - -def build_selected_report( - *, - scalar_path: Path, - canonical_path: Path, - high_path: Path, - runtime_overlay_path: Path | None = None, - runtime_series_overlay_path: Path | None = None, -) -> dict[str, Any]: - scalar = _load_source("scalar-current", scalar_path) - canonical = _load_source("canonical-final", canonical_path) - high = _load_source("high-n-scalar", high_path) - _validate_source_contract( - scalar, - expected_kind=SCALAR_KIND, - expected_multiplicities=range(2, 8), - ) - _validate_source_contract( - canonical, - expected_kind=CANONICAL_KIND, - expected_multiplicities=range(2, 8), - ) - _validate_source_contract( - high, - expected_kind=SCALAR_KIND, - expected_multiplicities=range(7, 11), - ) - sources = (scalar, canonical, high) - - cells: dict[str, dict[str, dict[str, dict[str, Any]]]] = {} - for family, modes in FAMILY_MODES.items(): - family_cells: dict[str, dict[str, dict[str, Any]]] = {} - for mode in modes: - mode_cells = { - str(n): _low_cell(scalar, canonical, family, mode, n) - for n in LOW_MULTIPLICITIES - } - if mode in HIGH_MODES[family]: - mode_cells.update( - { - str(n): _high_cell(high, family, mode, n) - for n in HIGH_MULTIPLICITIES - } - ) - family_cells[mode] = mode_cells - cells[family] = family_cells - - status_counts = Counter( - str(cell.get("status")) - for family_cells in cells.values() - for mode_cells in family_cells.values() - for cell in mode_cells.values() - ) - report: dict[str, Any] = { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "status": "complete-with-failures" if status_counts["failed"] else "complete", - "failure_count": status_counts["failed"], - "policy": _policy(high), - "plot_provenance": { - "source_reports": { - source.key: { - "path": source.display_path, - "sha256": source.sha256, - } - for source in sources - }, - "low_n": list(LOW_MULTIPLICITIES), - "high_n": list(HIGH_MULTIPLICITIES), - "recurrence_direct_max_n": max(LOW_MULTIPLICITIES), - "excluded_n": [10], - }, - "summary": {"cell_status_counts": dict(sorted(status_counts.items()))}, - "cells": cells, - } - - if runtime_overlay_path is not None: - overlay = _load_overlay(runtime_overlay_path) - if overlay.payload.get("kind") == OVERLAY_KIND: - _apply_runtime_overlay(report, overlay) - elif overlay.payload.get("kind") == CLEAN_RUNTIME_OVERLAY_KIND: - _apply_clean_runtime_overlay(report, overlay) - else: - raise CompositeError( - "runtime overlay kind must be either the historical or clean " - "runtime overlay kind" - ) - report["plot_provenance"]["source_reports"][overlay.key] = { - "path": overlay.display_path, - "sha256": overlay.sha256, - } - if runtime_series_overlay_path is not None: - series_overlay = _load_source( - "runtime-series-overlay", - runtime_series_overlay_path, - require_cells=False, - ) - if series_overlay.payload.get("schema_version") != SCHEMA_VERSION: - raise CompositeError("runtime series overlay schema_version must be 1") - apply_runtime_series_source(report, series_overlay) - return report - - -def _write_report(path: Path, report: Mapping[str, Any]) -> None: - path = path.expanduser().resolve(strict=False) - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_suffix(path.suffix + ".tmp") - temporary.write_text( - json.dumps(report, indent=2, sort_keys=True) + "\n", encoding="utf-8" - ) - temporary.replace(path) - - -def main() -> int: - arguments = _parser().parse_args() - try: - report = build_selected_report( - scalar_path=arguments.scalar_report, - canonical_path=arguments.canonical_report, - high_path=arguments.high_report, - runtime_overlay_path=arguments.runtime_overlay, - runtime_series_overlay_path=arguments.runtime_series_overlay, - ) - _write_report(arguments.output, report) - except CompositeError as error: - raise SystemExit(f"error: {error}") from error - print(arguments.output.expanduser().resolve(strict=False)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_scaling_study.py b/pyamplicol/tools/developer/fft_scaling_study.py deleted file mode 100644 index 3093e9b22b..0000000000 --- a/pyamplicol/tools/developer/fft_scaling_study.py +++ /dev/null @@ -1,3943 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Resumable FullColor scaling study for direct and FFT contractions. - -Every pyAmpliCol artifact retains complete helicity coverage. By default the -warm runtime query fixes the same nonzero helicity used by the comparison -curves; ``--compare-helicity-sums`` instead times the complete physical sum. -Every external command that can grow with multiplicity is run through the -repository memory watchdog. -""" - -from __future__ import annotations - -import argparse -import contextlib -import copy -import fcntl -import hashlib -import json -import math -import os -import re -import resource -import shutil -import statistics -import subprocess -import sys -import tempfile -import time -from collections.abc import Callable, Iterator, Mapping, Sequence -from dataclasses import asdict, dataclass, replace -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -SOURCE_ROOT = ROOT / "src" -if str(SOURCE_ROOT) not in sys.path: - sys.path.insert(0, str(SOURCE_ROOT)) -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.ci import memory_watchdog # noqa: E402 -from tools.developer import ( # noqa: E402 - fft_gluon_performance_acceptance as performance, -) -from tools.developer import legacy_amplicol # noqa: E402 -from tools.performance_report import legacy as legacy_report # noqa: E402 -from tools.performance_report import ( # noqa: E402 - legacy_structure as legacy_structure_tools, -) -from tools.performance_report.legacy_structure import ( # noqa: E402 - legacy_structural_probe_lock, -) -from tools.performance_report.models import ( # noqa: E402 - Accuracy, - CellSpec, - ExecutionMode, - MeasurementSpec, - Workload, -) - -KIND = "pyamplicol-fullcolor-fft-scaling-study" -SCHEMA_VERSION = 1 -STUDY_ROOT = ROOT / "IMPLEMENTATION_DOCS" / "RESULTS" / "fft-scaling-study" / "raw" -FINAL_MULTIPLICITIES = tuple(range(2, 8)) -POINT_COUNT = performance.POINT_COUNT -BENCHMARK_BATCH_SIZE = 128 -DEFAULT_PROFILE_TARGET_SECONDS = 3.0 * 60.0 -PROFILE_SAMPLE_COUNT = 1 -PROFILE_WARMUP_RUNS = 0 -PROFILE_PRECISION = 16 -REQUESTED_MEMORY_LIMIT_GIB = 30.0 -MAX_MEMORY_LIMIT_GIB = REQUESTED_MEMORY_LIMIT_GIB -DEFAULT_TIME_LIMIT_SECONDS = 60.0 * 60.0 -MAX_TIME_LIMIT_SECONDS = 60.0 * 60.0 -DEFAULT_ALPHA_S = 0.118 -DEFAULT_OTF_MAX_MULTIPLICITY = 6 -NUMERICAL_RELATIVE_TOLERANCE = 1.0e-10 -AMPLI_COL_MAX_POINTS = 1_000_000_000 -AMPLI_COL_CALIBRATION_HEADROOM = 1.05 -FORTRAN_FLOAT = r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[EeDd][+-]?[0-9]+)?" -AMPLI_COL_TIMING_ROW = re.compile( - rf"^\s*(generation setup|total)\s+({FORTRAN_FLOAT})\s+", - re.MULTILINE, -) -RSS_MARKER = performance.DARWIN_RSS_MARKER -WATCHDOG_PEAK_GUARD = re.compile(r"peak_guard=([0-9]+(?:\.[0-9]+)?) GiB") -WATCHDOG_PEAK_RSS = re.compile(r"peak_rss=([0-9]+(?:\.[0-9]+)?) GiB") -JSON_PATH_REFERENCE = re.compile( - r"(?P(?:/|\.{1,2}/)[^\s'\"<>]+?\.json)(?=$|[\s,;:)])" -) -SYMBOLICA_LICENSE_BUSY_FRAGMENT = ( - "cannot start new unlicensed symbolica instance since there is already another " - "one running on the machine" -) -SYMBOLICA_GENERATION_LOCK_ENV = "PYAMPICOL_FFT_SYMBOLICA_GENERATION_LOCK" -SYMBOLICA_BUSY_RETRY_SECONDS = 5.0 -SYMBOLICA_LOCK_POLL_SECONDS = 0.25 -LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY = "legacy-amplicol-structural-limit" -_LEGACY_AMPLICOL_PROBE_NAMES = frozenset( - {"amplicol_color_probe", "amplicol_color_library_probe"} -) - - -class StudyError(RuntimeError): - """The bounded scaling-study contract could not be satisfied.""" - - -_RESOURCE_FAILURE_CATEGORIES = frozenset( - { - "generation-time-limit", - "memory-limit", - "runtime-time-limit", - "setup-or-runtime-time-limit", - } -) -_CENSORING_FAILURE_CATEGORIES = _RESOURCE_FAILURE_CATEGORIES | frozenset( - {LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY} -) -MUTABLE_RESUME_MEASUREMENT_POLICY_KEYS = frozenset( - { - "calibration_target_seconds", - "candidate_profile_minimum_samples", - "candidate_profile_target_runtime_seconds", - "candidate_profile_warmup_runs", - "cell_admission_limits", - "generation_timeout_seconds", - "memory_policy", - "memory_watchdog_gib", - "requested_memory_ceiling_gib", - "runtime_timeout_seconds", - "warm_sample_count", - "warm_samples", - "warm_timing_metric", - } -) - - -class _CellResourceLimitError(StudyError): - """A cell reached one explicitly enforced time or memory limit.""" - - def __init__(self, message: str, *, category: str) -> None: - if category not in _RESOURCE_FAILURE_CATEGORIES: - raise ValueError(f"invalid cell resource-limit category {category!r}") - super().__init__(message) - self.category = category - - -class _CellCommandError(StudyError): - """A watched command failed in a stage with a known timeout category.""" - - def __init__(self, message: str, *, timeout_category: str) -> None: - if timeout_category not in { - "generation-time-limit", - "runtime-time-limit", - "setup-or-runtime-time-limit", - }: - raise ValueError(f"invalid command timeout category {timeout_category!r}") - super().__init__(message) - self.timeout_category = timeout_category - - -def report_helicity_workload(report: Mapping[str, Any]) -> str: - """Return the strictly declared fixed or summed report workload.""" - - policy = report.get("policy") - if not isinstance(policy, Mapping): - raise StudyError("campaign report has no policy object") - measurement = policy.get("measurement") - if not isinstance(measurement, Mapping): - raise StudyError("campaign report has no measurement policy") - policy_declared = policy.get("helicity_workload") - measurement_declared = measurement.get("helicity_workload") - if ( - policy_declared is not None - and measurement_declared is not None - and str(policy_declared) != str(measurement_declared) - ): - raise StudyError( - "policy and measurement helicity_workload declarations disagree" - ) - declared = ( - measurement_declared - if measurement_declared is not None - else policy_declared - ) - if declared is None: - if ( - measurement.get("warm_fixed_helicity") is True - and measurement.get("warm_helicity_sum") is True - ): - raise StudyError("campaign helicity workload markers are contradictory") - if measurement.get("warm_helicity_sum") is True: - declared = "sum" - elif measurement.get("warm_fixed_helicity") is True: - declared = "fixed" - else: - raise StudyError("campaign report does not declare its helicity workload") - workload = str(declared) - if workload not in {"fixed", "sum"}: - raise StudyError("campaign helicity_workload must be 'fixed' or 'sum'") - if workload == "sum" and ( - measurement.get("warm_fixed_helicity") is not False - or measurement.get("warm_helicity_sum") is not True - ): - raise StudyError( - "summed campaign must record warm_fixed_helicity=false and " - "warm_helicity_sum=true" - ) - if workload == "fixed" and ( - measurement.get("warm_fixed_helicity") is not True - or measurement.get("warm_helicity_sum") is True - ): - raise StudyError( - "fixed campaign must record warm_fixed_helicity=true without " - "warm_helicity_sum=true" - ) - return workload - - -@dataclass(frozen=True, slots=True) -class Mode: - key: str - label: str - kind: str - execution_mode: str | None = None - contraction: str | None = None - - -@dataclass(frozen=True, slots=True) -class AmpliColWarmSamples: - repetitions: int - samples_seconds: tuple[float, ...] - sample_totals_seconds: tuple[float, ...] - sample_set_attempts: int - - -MODES = ( - Mode("reference-fft", "Reference FFT", "reference"), - Mode("amplicol", "AmpliCol", "amplicol"), - Mode( - "recurrence-direct", - "pyAmpliCol - recurrence", - "candidate", - "recurrence", - "direct", - ), - Mode( - "recurrence-fft", - "pyAmpliCol - recurrence - FFT", - "candidate", - "recurrence", - "symmetric-group-fft", - ), - Mode("otf-direct", "pyAmpliCol - OTF", "candidate", "on-the-fly", "direct"), - Mode( - "otf-fft", - "pyAmpliCol - OTF - FFT", - "candidate", - "on-the-fly", - "symmetric-group-fft", - ), - Mode("compiled-direct", "pyAmpliCol - Compiled", "candidate", "compiled", "direct"), - Mode( - "compiled-fft", - "pyAmpliCol - Compiled - FFT", - "candidate", - "compiled", - "symmetric-group-fft", - ), -) -MODE_BY_KEY = {mode.key: mode for mode in MODES} -FAMILIES = ("gg", "ddbar") -_CANDIDATE_MODE_BY_EXECUTION_AND_CONTRACTION = { - (mode.execution_mode, mode.contraction): mode - for mode in MODES - if mode.kind == "candidate" -} - - -def process_expression(family: str, final_multiplicity: int) -> str: - if final_multiplicity < 2: - raise StudyError(f"unsupported final-state multiplicity {final_multiplicity}") - extra = " ".join("g" for _ in range(final_multiplicity - 2)) - if family == "gg": - return "g g > g g" + (f" {extra}" if extra else "") - if family == "ddbar": - return "d d~ > d d~" + (f" {extra}" if extra else "") - raise StudyError(f"unknown process family {family!r}") - - -def process_key(family: str, final_multiplicity: int) -> str: - return f"{family}_n{final_multiplicity}" - - -def fixed_ddbar_helicity(final_multiplicity: int) -> tuple[int, ...]: - return tuple(-1 if index % 2 == 0 else 1 for index in range(final_multiplicity + 2)) - - -def _multiplicities(arguments: argparse.Namespace) -> tuple[int, ...]: - if arguments.multiplicities is not None: - return tuple(sorted(set(arguments.multiplicities))) - return tuple(range(arguments.min_n, arguments.max_n + 1)) - - -def _fill_multiplicities(arguments: argparse.Namespace) -> tuple[int, ...]: - """Return the policy multiplicities selected for this campaign invocation. - - ``--multiplicity`` remains part of the persisted measurement policy. The - separate fill selector lets an orchestrator populate that fixed policy in - bounded slices without changing resume identity. - """ - - policy = _multiplicities(arguments) - requested = arguments.fill_multiplicities - if requested is None: - return policy - return tuple(sorted(set(requested))) - - -def _fill_modes(arguments: argparse.Namespace, family: str) -> tuple[Mode, ...]: - """Return policy modes selected for this fill without changing identity.""" - - policy = _selected_modes(arguments, family) - requested = arguments.fill_modes - if requested is None: - return policy - requested_set = set(requested) - return tuple(mode for mode in policy if mode.key in requested_set) - - -def _study_root(arguments: argparse.Namespace) -> Path: - return arguments.study_root.expanduser().resolve(strict=False) - - -def _selected_families(arguments: argparse.Namespace) -> tuple[str, ...]: - requested = set(arguments.families or FAMILIES) - return tuple(family for family in FAMILIES if family in requested) - - -def _selected_modes(arguments: argparse.Namespace, family: str) -> tuple[Mode, ...]: - requested = ( - set(MODE_BY_KEY) - {"compiled-fft"} - if arguments.modes is None - else set(arguments.modes) - ) - if arguments.fft_enabled and not getattr(arguments, "explicit_modes", False): - selected_execution_modes = { - MODE_BY_KEY[key].execution_mode - for key in requested - if MODE_BY_KEY[key].kind == "candidate" - } - for execution_mode in selected_execution_modes: - direct = _CANDIDATE_MODE_BY_EXECUTION_AND_CONTRACTION.get( - (execution_mode, "direct") - ) - if direct is not None: - requested.add(direct.key) - # Compiled FFT is presently a selected-helicity diagnostic lane, - # so it is not auto-added to this helicity-general campaign. - if execution_mode == "compiled": - continue - fft = _CANDIDATE_MODE_BY_EXECUTION_AND_CONTRACTION.get( - (execution_mode, "symmetric-group-fft") - ) - if fft is not None: - requested.add(fft.key) - return tuple( - mode - for mode in MODES - if mode.key in requested - and not (family == "ddbar" and mode.kind == "reference") - ) - - -def _positive_finite(value: object) -> bool: - return ( - isinstance(value, int | float) - and not isinstance(value, bool) - and math.isfinite(float(value)) - and float(value) > 0.0 - ) - - -def _write_event( - path: Path, - momenta: Sequence[Sequence[float]], - helicity: Sequence[int], -) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - rows = [ - "PYAMPLICOL_SCALING_EVENT_V1", - "BEGIN_MOMENTA", - *(" ".join(format(float(value), ".17e") for value in row) for row in momenta), - "END_MOMENTA", - "NHELICITIES 1", - "BEGIN_HELICITIES", - " ".join(f"{int(value):+d}" for value in helicity), - "END_HELICITIES", - ] - path.write_text("\n".join(rows) + "\n", encoding="utf-8") - - -def _read_event(path: Path) -> tuple[tuple[tuple[float, ...], ...], tuple[int, ...]]: - momenta: list[tuple[float, ...]] = [] - helicity: list[int] = [] - in_momenta = False - in_helicities = False - for line in path.read_text(encoding="utf-8").splitlines(): - stripped = line.strip() - if stripped == "BEGIN_MOMENTA": - in_momenta = True - elif stripped == "END_MOMENTA": - in_momenta = False - elif stripped == "BEGIN_HELICITIES": - in_helicities = True - elif stripped == "END_HELICITIES": - in_helicities = False - elif in_momenta: - row = tuple(float(value) for value in stripped.split()) - if len(row) != 4: - raise StudyError(f"invalid momentum row in {path}") - momenta.append(row) - elif in_helicities: - helicity.extend(int(value) for value in stripped.split()) - if len(momenta) != len(helicity) or any(value not in (-1, 1) for value in helicity): - raise StudyError(f"invalid fixed-helicity event {path}") - return tuple(momenta), tuple(helicity) - - -def _ddbar_events(run_root: Path, final_multiplicity: int) -> tuple[Path, ...]: - from pyamplicol.generation.phase_space import massive_rambo_final_state - - helicity = fixed_ddbar_helicity(final_multiplicity) - incoming = ( - (500.0, 0.0, 0.0, 500.0), - (500.0, 0.0, 0.0, -500.0), - ) - result: list[Path] = [] - for point in range(1, POINT_COUNT + 1): - path = ( - run_root - / "events" - / "ddbar" - / f"n{final_multiplicity}" - / f"point-{point:02d}.event" - ) - if not path.is_file(): - outgoing = massive_rambo_final_state( - final_multiplicity, - sqrt_s=1000.0, - masses=(0.0,) * final_multiplicity, - seed=91_000 + 100 * final_multiplicity + point, - ) - _write_event(path, (*incoming, *outgoing), helicity) - result.append(path) - return tuple(result) - - -def _candidate_generation_command( - *, - python: str, - family: str, - final_multiplicity: int, - mode: Mode, - artifact: Path, - batch_size: int, - optimization_cores: int | None = None, -) -> tuple[str, ...]: - assert mode.execution_mode is not None and mode.contraction is not None - command = ( - python, - "-m", - "pyamplicol", - "generate", - process_expression(family, final_multiplicity), - str(artifact), - "--name", - process_key(family, final_multiplicity), - "--model", - "built-in-sm", - "--color-accuracy", - "full", - "--color-contraction", - mode.contraction, - "--execution-mode", - mode.execution_mode, - "--set", - f"evaluator.batch_size={batch_size}", - ) - if optimization_cores is not None: - command += ( - "--set", - f"evaluator.optimization.cores={optimization_cores}", - ) - return command - - -def _helicity_identifier(helicity: Sequence[int]) -> str: - values = tuple(int(value) for value in helicity) - if not values or any(value not in (-1, 1) for value in values): - raise StudyError("candidate fixed helicity is invalid") - return "h:" + ",".join(f"{value:+d}" for value in values) - - -def _write_candidate_cli_inputs( - *, - cell_root: Path, - events: Sequence[Path], - alpha_s: float, -) -> tuple[Path, Path]: - momenta = [_read_event(path)[0] for path in events] - if len(momenta) != POINT_COUNT: - raise StudyError("candidate CLI evaluation requires exactly ten shared points") - momenta_path = cell_root / "cli-momenta.json" - parameters_path = cell_root / "cli-model-parameters.json" - momenta_path.write_text( - json.dumps(momenta, indent=2, allow_nan=False) + "\n", - encoding="utf-8", - ) - parameters_path.write_text( - json.dumps( - {"normalization.alpha_s_me_check": alpha_s}, - indent=2, - sort_keys=True, - allow_nan=False, - ) - + "\n", - encoding="utf-8", - ) - return momenta_path, parameters_path - - -def _candidate_evaluate_command( - *, - python: str, - artifact: Path, - process: str, - momenta: Path, - model_parameters: Path, - helicity: Sequence[int], - sum_helicities: bool, -) -> tuple[str, ...]: - command = ( - python, - "-m", - "pyamplicol", - "evaluate", - str(artifact), - "--process", - process, - "--momenta", - str(momenta), - "--model-parameters", - str(model_parameters), - "--precision", - str(PROFILE_PRECISION), - ) - if not sum_helicities: - command += ("--helicity", _helicity_identifier(helicity)) - return ( - *command, - "--json", - "--progress", - "off", - "--color", - "never", - "--log-level", - "error", - ) - - -def _candidate_profile_command( - *, - python: str, - artifact: Path, - process: str, - momenta: Path, - helicity: Sequence[int], - sum_helicities: bool, - target_seconds: float, - batch_size: int, - minimum_samples: int = PROFILE_SAMPLE_COUNT, -) -> tuple[str, ...]: - command = ( - python, - "-m", - "pyamplicol", - "profile", - str(artifact), - "--process", - process, - "--momenta", - str(momenta), - "--target-runtime", - f"{target_seconds:.17g}", - "--batch-size", - str(batch_size), - "--precision", - str(PROFILE_PRECISION), - "--warmup-runs", - str(PROFILE_WARMUP_RUNS), - "--minimum-samples", - str(minimum_samples), - ) - if not sum_helicities: - command += ("--helicity", _helicity_identifier(helicity)) - return ( - *command, - "--json", - "--progress", - "off", - "--color", - "never", - "--log-level", - "error", - ) - - -def _parse_candidate_evaluate_json(output: str) -> list[float]: - try: - payload = json.loads(output) - except json.JSONDecodeError as error: - raise StudyError("candidate CLI evaluate output is not JSON") from error - if not isinstance(payload, list) or len(payload) != POINT_COUNT: - raise StudyError("candidate CLI evaluate did not return ten point values") - values: list[float] = [] - for entry in payload: - if not isinstance(entry, Mapping) or set(entry) != {"real", "imag"}: - raise StudyError( - "candidate CLI evaluate value is not a complex JSON scalar" - ) - try: - real = float(entry["real"]) - imaginary = float(entry["imag"]) - except (TypeError, ValueError) as error: - raise StudyError("candidate CLI evaluate value is not numeric") from error - if ( - not math.isfinite(real) - or not math.isfinite(imaginary) - or abs(imaginary) > 1.0e-12 * max(abs(real), 1.0e-300) - ): - raise StudyError("candidate CLI evaluate value is not finite and real") - values.append(real) - return values - - -def _parse_candidate_profile_json( - output: str, - *, - artifact: Path, - family: str, - final_multiplicity: int, - execution_mode: str, - helicity: Sequence[int], - sum_helicities: bool, - target_seconds: float, - batch_size: int, - minimum_samples: int = PROFILE_SAMPLE_COUNT, -) -> dict[str, object]: - try: - payload = json.loads(output) - except json.JSONDecodeError as error: - raise StudyError("candidate CLI profile output is not JSON") from error - if not isinstance(payload, dict): - raise StudyError("candidate CLI profile output is not an object") - expected_helicities = [] if sum_helicities else [_helicity_identifier(helicity)] - expected_config = { - "batch_size": batch_size, - "color_flow_ids": [], - "helicity_ids": expected_helicities, - "minimum_samples": minimum_samples, - "precision": PROFILE_PRECISION, - "target_runtime": target_seconds, - "warmup_runs": PROFILE_WARMUP_RUNS, - } - requested = payload.get("requested_config") - effective = payload.get("effective_config") - environment = payload.get("environment") - if requested != expected_config or effective != expected_config: - raise StudyError("candidate CLI profile configuration differs from the request") - if not isinstance(environment, Mapping): - raise StudyError("candidate CLI profile has no environment evidence") - try: - wall_time = float(payload["wall_time_per_point"]) - sample_count = int(payload["sample_count"]) - repetitions = int(payload["repetitions_per_sample"]) - completed_samples = int(environment["completed_sample_count"]) - measured_points = int(environment["measured_point_count"]) - except (KeyError, TypeError, ValueError) as error: - raise StudyError("candidate CLI profile timing fields are malformed") from error - target = environment.get("target") - if ( - payload.get("process_id") != process_key(family, final_multiplicity) - or payload.get("process_expression") - != process_expression(family, final_multiplicity) - or environment.get("execution_mode") != execution_mode - or environment.get("color_accuracy") != "full" - or environment.get("batch_size") != batch_size - or environment.get("precision") != PROFILE_PRECISION - or environment.get("selected_color_ids") != [] - or environment.get("selected_helicity_ids") != expected_helicities - or not isinstance(target, str) - or Path(target).expanduser().resolve(strict=False) - != artifact.expanduser().resolve(strict=False) - or payload.get("interrupted") is not False - or environment.get("interrupted") is not False - or sample_count < minimum_samples - or completed_samples != sample_count - or repetitions < 1 - or measured_points != sample_count * repetitions * batch_size - or not _positive_finite(wall_time) - ): - raise StudyError("candidate CLI profile provenance is inconsistent") - if execution_mode == "on-the-fly" and ( - not _positive_finite(environment.get("cold_warmup_elapsed_seconds")) - or environment.get("cold_warmup_runtime_cold_before_first_evaluation") - is not True - or environment.get("cold_warmup_runtime_retained_after_first_evaluation") - is not True - ): - raise StudyError("OTF CLI profile lacks authenticated cold warm-up evidence") - return payload - - -def _relative_error(observed: float, expected: float) -> float: - return abs(observed - expected) / max(abs(observed), abs(expected), 1.0e-300) - - -def _require_bounded_rss(max_rss_kib: int, memory_limit_gib: float) -> int: - if max_rss_kib < 1: - raise StudyError("runtime RSS evidence is not positive") - if max_rss_kib >= int(memory_limit_gib * 1024**2): - raise _CellResourceLimitError( - f"runtime RSS reached the strict <{memory_limit_gib:g} GiB bound", - category="memory-limit", - ) - return max_rss_kib - - -def _numerical_evidence( - *, - family: str, - final_multiplicity: int, - alpha_s: float, - observed: Sequence[float], - baseline: Mapping[str, object] | None, -) -> dict[str, object]: - if baseline is None or baseline.get("status") != "measured": - return {"available": False, "passes": None, "reason": "baseline unavailable"} - baseline_values = baseline.get("point_values") - if not isinstance(baseline_values, list) or not baseline_values: - raise StudyError("baseline cell has no numerical values") - if family == "gg": - if len(observed) not in {1, len(baseline_values)}: - raise StudyError("reference/candidate point counts differ") - exponent = final_multiplicity - factor = ( - performance.INITIAL_GLUON_AVERAGE_FACTOR - * math.factorial(exponent) - / (4.0 * math.pi * alpha_s) ** exponent - ) - errors = [ - _relative_error(float(value) * factor, float(reference)) - for value, reference in zip( - observed, baseline_values[: len(observed)], strict=True - ) - ] - else: - errors = [_relative_error(float(observed[0]), float(baseline_values[0]))] - factor = 1.0 - maximum = max(errors) - return { - "available": True, - "normalization_factor": factor, - "maximum_relative_error": maximum, - "relative_tolerance": NUMERICAL_RELATIVE_TOLERANCE, - "passes": maximum <= NUMERICAL_RELATIVE_TOLERANCE, - } - - -def _timed_command( - command: Sequence[str], *, python: str -) -> tuple[tuple[str, ...], Any]: - return (python, str(Path(__file__).resolve()), "_time-rss", *command), None - - -def _parse_rss_marker(stderr: str) -> int: - matches = re.findall(rf"^{re.escape(RSS_MARKER)}\s+(\d+)\s*$", stderr, re.MULTILINE) - if len(matches) != 1 or int(matches[0]) < 1: - raise StudyError("timed process did not report one positive RSS marker") - return int(matches[0]) - - -def _parse_watchdog_peak_guard_kib(stderr: str) -> int: - matches = WATCHDOG_PEAK_GUARD.findall(stderr) - if len(matches) != 1: - raise StudyError("watched process did not report one peak_guard value") - value = float(matches[0]) - if not math.isfinite(value) or value < 0.0: - raise StudyError("watched process peak_guard is invalid") - return round(value * 1024**2) - - -def _parse_watchdog_peak_rss_kib(stderr: str) -> int: - matches = WATCHDOG_PEAK_RSS.findall(stderr) - if len(matches) != 1: - raise StudyError("watched process did not report one peak_rss value") - value = float(matches[0]) - # Very short children can finish before the watchdog's first full sample; - # its GiB-formatted diagnostic then rounds a sub-MiB observation to 0.000. - if not math.isfinite(value) or value < 0.0: - raise StudyError("watched process peak_rss is invalid") - return round(value * 1024**2) - - -def _exec_in_command( - python: str, directory: Path, command: Sequence[str] -) -> tuple[str, ...]: - return (python, str(Path(__file__).resolve()), "_exec-in", str(directory), *command) - - -def _parse_amplicol_timing_aggregate(output: str) -> tuple[float, float, int]: - rows: dict[str, float] = {} - for label, raw_value in AMPLI_COL_TIMING_ROW.findall(output): - if label in rows: - raise StudyError(f"AmpliCol timing row {label!r} is duplicated") - rows[label] = float(raw_value.replace("D", "E").replace("d", "e")) - point_matches = re.findall(r"^points\s+(\d+)\s*$", output, re.MULTILINE) - if set(rows) != {"generation setup", "total"} or len(point_matches) != 1: - raise StudyError("AmpliCol timing output is incomplete") - points = int(point_matches[0]) - if ( - points < 1 - or rows["generation setup"] < 0.0 - or not _positive_finite(rows["total"]) - ): - raise StudyError("AmpliCol timing output contains invalid values") - return rows["generation setup"], rows["total"], points - - -def _parse_amplicol_timing(output: str) -> tuple[float, float, int]: - generation_setup, total, points = _parse_amplicol_timing_aggregate(output) - return generation_setup, total / points, points - - -def _amplicol_fixed_repetitions( - points: int, total_seconds: float, target_seconds: float -) -> int: - if points < 1 or points > AMPLI_COL_MAX_POINTS: - raise StudyError("AmpliCol calibration point count is outside its bound") - if not _positive_finite(total_seconds) or not _positive_finite(target_seconds): - raise StudyError("AmpliCol calibration timing is invalid") - if total_seconds >= target_seconds: - return points - required = max( - points + 1, - math.ceil( - points * target_seconds / total_seconds * AMPLI_COL_CALIBRATION_HEADROOM - ), - ) - if required > AMPLI_COL_MAX_POINTS: - raise StudyError( - "AmpliCol requires more than its bounded point count to reach the " - "warm calibration target" - ) - return required - - -def _collect_amplicol_warm_samples( - *, - seed_points: int, - seed_total_seconds: float, - target_seconds: float, - run_sample: Callable[[int, int, int], str], -) -> AmpliColWarmSamples: - """Collect equal-repetition profiling aggregates that meet the time floor.""" - - repetitions = _amplicol_fixed_repetitions( - seed_points, seed_total_seconds, target_seconds - ) - sample_set_attempt = 0 - while True: - sample_set_attempt += 1 - samples: list[float] = [] - totals: list[float] = [] - for sample_index in range(1, PROFILE_SAMPLE_COUNT + 1): - output = run_sample(sample_set_attempt, sample_index, repetitions) - _, total, observed_points = _parse_amplicol_timing_aggregate(output) - if observed_points != repetitions: - raise StudyError( - "AmpliCol fixed-repetition probe reported a different point count" - ) - if total < target_seconds: - repetitions = _amplicol_fixed_repetitions( - repetitions, total, target_seconds - ) - break - totals.append(total) - samples.append(total / repetitions) - else: - return AmpliColWarmSamples( - repetitions=repetitions, - samples_seconds=tuple(samples), - sample_totals_seconds=tuple(totals), - sample_set_attempts=sample_set_attempt, - ) - - -def _empty_report(arguments: argparse.Namespace) -> dict[str, object]: - return { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "status": "running", - "policy": dry_run_plan(arguments), - "cells": { - family: {mode.key: {} for mode in _selected_modes(arguments, family)} - for family in _selected_families(arguments) - }, - } - - -def _load_report(path: Path, arguments: argparse.Namespace) -> dict[str, object]: - if not path.is_file(): - return _empty_report(arguments) - if not arguments.resume: - raise StudyError(f"study report already exists; pass --resume: {path}") - payload = json.loads(path.read_text(encoding="utf-8")) - if payload.get("kind") != KIND or payload.get("schema_version") != SCHEMA_VERSION: - raise StudyError("existing scaling-study report has the wrong schema") - if not isinstance(payload.get("cells"), dict): - raise StudyError("existing scaling-study report has no cells") - requested_policy = dry_run_plan(arguments) - if payload.get("policy") != requested_policy: - stored_comparison = _resume_policy_comparison(payload.get("policy")) - requested_comparison = _resume_policy_comparison(requested_policy) - if stored_comparison != requested_comparison: - raise StudyError("resume arguments differ from the stored study policy") - payload["policy"] = requested_policy - normalize_loaded_failure_cells(payload, path.parent) - payload["status"] = "running" - return payload - - -def _resume_policy_comparison(policy: object) -> object: - if not isinstance(policy, Mapping): - return policy - normalized = copy.deepcopy(dict(policy)) - normalized.pop("run_root", None) - measurement = normalized.get("measurement") - if isinstance(measurement, dict): - for key in MUTABLE_RESUME_MEASUREMENT_POLICY_KEYS: - measurement.pop(key, None) - return normalized - - -def _record( - report: dict[str, object], - report_path: Path, - family: str, - mode: str, - final_multiplicity: int, - cell: Mapping[str, object], -) -> None: - cells = report["cells"] - assert isinstance(cells, dict) - family_cells = cells[family] - assert isinstance(family_cells, dict) - curve = family_cells[mode] - assert isinstance(curve, dict) - curve[str(final_multiplicity)] = dict(cell) - performance._write_report(report_path, report) - - -def _curve(report: Mapping[str, object], family: str, mode: str) -> dict[str, object]: - cells = report["cells"] - assert isinstance(cells, dict) - family_cells = cells[family] - assert isinstance(family_cells, dict) - result = family_cells[mode] - assert isinstance(result, dict) - return result - - -def _failure_count(report: Mapping[str, object]) -> int: - cells = report.get("cells") - if not isinstance(cells, Mapping): - return 0 - return sum( - cell.get("status") == "failed" - for family_cells in cells.values() - if isinstance(family_cells, Mapping) - for curve in family_cells.values() - if isinstance(curve, Mapping) - for cell in curve.values() - if isinstance(cell, Mapping) - ) - - -def selected_cells_complete( - report: Mapping[str, object], - *, - family: str, - modes: Sequence[str], - multiplicities: Sequence[int], -) -> bool: - """Return whether the requested cells have authoritative terminal records.""" - - cells = report.get("cells") - if not isinstance(cells, Mapping): - return False - family_cells = cells.get(family) - if not isinstance(family_cells, Mapping): - return False - for mode in modes: - curve = family_cells.get(mode) - if not isinstance(curve, Mapping): - return False - for final_multiplicity in multiplicities: - cell = curve.get(str(final_multiplicity)) - if not isinstance(cell, Mapping): - return False - status = cell.get("status") - if status in {"measured", "skipped"}: - continue - if status == "failed" and cell.get("censors_higher_multiplicities") is True: - continue - return False - return True - - -def resource_frontier_inversions( - report: Mapping[str, object], -) -> tuple[tuple[str, str, int, int], ...]: - """Find measured cells retained above an earlier resource frontier.""" - - cells = report.get("cells") - if not isinstance(cells, Mapping): - return () - inversions: list[tuple[str, str, int, int]] = [] - for family, family_cells in cells.items(): - if not isinstance(family, str) or not isinstance(family_cells, Mapping): - continue - for mode, curve in family_cells.items(): - if not isinstance(mode, str) or not isinstance(curve, Mapping): - continue - frontier: int | None = None - for raw_n, cell in sorted( - curve.items(), - key=lambda item: int(item[0]) if str(item[0]).isdigit() else 10**9, - ): - if not str(raw_n).isdigit() or not isinstance(cell, Mapping): - continue - final_multiplicity = int(raw_n) - if cell.get("censors_higher_multiplicities") is True and cell.get( - "status" - ) in {"failed", "skipped"}: - failed_at = cell.get("failed_at_n") - frontier = min( - frontier if frontier is not None else final_multiplicity, - int(failed_at) - if isinstance(failed_at, int) - else final_multiplicity, - ) - elif cell.get("status") == "measured" and frontier is not None: - inversions.append((family, mode, frontier, final_multiplicity)) - return tuple(inversions) - - -def compose_report( - arguments: argparse.Namespace, - curve_sources: Mapping[str, Mapping[str, Mapping[str, object]]], - *, - halt_reason: str | None = None, -) -> dict[str, object]: - """Compose one canonical study report from already-authenticated curves. - - The orchestration layer may schedule isolated curve shards, but report - shape, completeness, failure accounting, and terminal status remain owned - here at the scaling-study boundary. - """ - - report = _empty_report(arguments) - cells = report["cells"] - assert isinstance(cells, dict) - policy_multiplicities = set(_multiplicities(arguments)) - for family in _selected_families(arguments): - source_family = curve_sources.get(family, {}) - target_family = cells[family] - assert isinstance(target_family, dict) - for mode in _selected_modes(arguments, family): - source_curve = source_family.get(mode.key, {}) - if not isinstance(source_curve, Mapping): - raise StudyError( - f"composed {family}/{mode.key} curve must be an object" - ) - malformed = [ - raw_n - for raw_n in source_curve - if not isinstance(raw_n, str) or not raw_n.isdigit() - ] - unexpected = sorted( - int(raw_n) - for raw_n in source_curve - if isinstance(raw_n, str) - and raw_n.isdigit() - and int(raw_n) not in policy_multiplicities - ) - if unexpected or malformed: - raise StudyError( - f"composed {family}/{mode.key} curve is outside its policy" - ) - target_family[mode.key] = copy.deepcopy(dict(source_curve)) - - failures = _failure_count(report) - complete = all( - selected_cells_complete( - report, - family=family, - modes=tuple(mode.key for mode in _selected_modes(arguments, family)), - multiplicities=_multiplicities(arguments), - ) - for family in _selected_families(arguments) - ) - inversions = resource_frontier_inversions(report) - if inversions: - report["resource_frontier_inversions"] = [list(item) for item in inversions] - else: - report.pop("resource_frontier_inversions", None) - if halt_reason is not None: - report["status"] = "stopped-correctness-failure" - report["status_reason"] = halt_reason - elif complete: - report["status"] = "complete-with-failures" if failures else "complete" - report.pop("status_reason", None) - else: - report["status"] = "running" - report.pop("status_reason", None) - report["failure_count"] = failures - return report - - -def _gg_reference_dependency_skip( - report: Mapping[str, object], final_multiplicity: int -) -> dict[str, object] | None: - reference = _curve(report, "gg", "reference-fft").get(str(final_multiplicity)) - if not isinstance(reference, Mapping): - return None - status = reference.get("status") - if status == "failed": - if reference.get("censors_higher_multiplicities") is not True: - return None - failed_at = final_multiplicity - elif status == "skipped" and isinstance(reference.get("failed_at_n"), int): - failed_at = int(reference["failed_at_n"]) - else: - return None - return { - "status": "skipped", - "failure_category": "dependency-unavailable", - "failure_reason": ( - "Reference FFT baseline/input unavailable because its curve was " - f"resource-censored at n={failed_at}" - ), - "censors_higher_multiplicities": False, - "dependency": { - "family": "gg", - "mode": "reference-fft", - "n": final_multiplicity, - "status": status, - "resource_failure_at_n": failed_at, - }, - } - - -def _amplicol_gg_dense_index_preflight( - final_multiplicity: int, memory_limit_gib: float -) -> dict[str, object]: - total_external = final_multiplicity + 2 - color_orders = math.factorial(total_external - 1) - lower_bound_bytes = 2 * color_orders**2 - memory_limit_bytes = int(memory_limit_gib * 1024**3) - return { - "formula": "2*((total_external-1)!)^2 bytes", - "color_orders": color_orders, - "lower_bound_bytes": lower_bound_bytes, - "memory_limit_bytes": memory_limit_bytes, - "feasible": lower_bound_bytes < memory_limit_bytes, - } - - -def _cell_base( - family: str, - mode: Mode, - final_multiplicity: int, - *, - sum_helicities: bool = False, -) -> dict[str, object]: - result: dict[str, object] = { - "family": family, - "mode": mode.key, - "label": mode.label, - "n": final_multiplicity, - "total_external": final_multiplicity + 2, - "process": process_expression(family, final_multiplicity), - "color_accuracy": "full", - } - if sum_helicities: - result.update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - } - ) - if mode.kind == "candidate": - result["execution_mode"] = mode.execution_mode - result["color_contraction"] = mode.contraction - result["generation_helicity_coverage"] = "all" - if not sum_helicities: - result["warm_fixed_helicity"] = True - return result - - -def _compiled_fft_not_applicable_cell( - *, - family: str, - mode: Mode, - final_multiplicity: int, - sum_helicities: bool = False, -) -> dict[str, object] | None: - """Exclude the selected-helicity-only compiled FFT diagnostic lane.""" - - if mode.key != "compiled-fft": - return None - return _cell_base( - family, - mode, - final_multiplicity, - sum_helicities=sum_helicities, - ) | { - "status": "not-applicable", - "failure_category": "publication-requires-helicity-general-artifact", - "failure_reason": ( - "compiled FFT is disabled in this publication campaign because its " - "current backend supports only a generation-selected diagnostic " - "helicity, while publication artifacts must support all runtime " - "helicities; compiled-direct remains supported" - ), - "failure_reason_short": ( - "selected-helicity diagnostic only; compiled-direct remains supported" - ), - "censors_higher_multiplicities": False, - "applicability": { - "compiled_direct": True, - "compiled_fft": False, - "reason_code": "publication-requires-all-runtime-helicities", - }, - } - - -def otf_protocol_scope_cell( - *, - family: str, - mode: Mode, - final_multiplicity: int, - sum_helicities: bool = False, - maximum_multiplicity: int = DEFAULT_OTF_MAX_MULTIPLICITY, -) -> dict[str, object] | None: - """Apply the workload-specific OTF publication frontier.""" - - if ( - mode.execution_mode != "on-the-fly" - or final_multiplicity <= maximum_multiplicity - ): - return None - return _cell_base( - family, - mode, - final_multiplicity, - sum_helicities=sum_helicities, - ) | { - "status": "skipped", - "failure_category": "publication-protocol-scope", - "failure_reason": ( - "the final scaling scan deliberately limits on-the-fly curves to " - f"n<={maximum_multiplicity} for this helicity workload; beyond that " - "it retains recurrence, AmpliCol, and Reference FFT where applicable" - ), - "censors_higher_multiplicities": True, - "failed_at_n": maximum_multiplicity + 1, - } - - -def apply_protocol_scope_cells( - report: dict[str, object], - *, - family: str, - modes: Sequence[str], - multiplicities: Sequence[int], - maximum_multiplicity: int = DEFAULT_OTF_MAX_MULTIPLICITY, -) -> bool: - """Populate deliberate non-measurement OTF cells for an orchestrated shard.""" - - sum_helicities = report_helicity_workload(report) == "sum" - changed = False - for mode_key in modes: - mode = MODE_BY_KEY[mode_key] - curve = _curve(report, family, mode_key) - for final_multiplicity in multiplicities: - cell = otf_protocol_scope_cell( - family=family, - mode=mode, - final_multiplicity=final_multiplicity, - sum_helicities=sum_helicities, - maximum_multiplicity=maximum_multiplicity, - ) - if cell is not None and str(final_multiplicity) not in curve: - curve[str(final_multiplicity)] = cell - changed = True - return changed - - -def _referenced_command_records( - detail: str, cell_root: Path -) -> tuple[tuple[Path, Mapping[str, object]], ...]: - """Load only watched-command records explicitly cited by the exception.""" - - candidate_paths: dict[str, Path] = {} - for match in JSON_PATH_REFERENCE.finditer(detail): - raw_path = Path(match.group("path")) - path = raw_path if raw_path.is_absolute() else cell_root / raw_path - candidate_paths[str(path.resolve(strict=False))] = path - records: list[tuple[Path, Mapping[str, object]]] = [] - try: - local_paths = sorted(cell_root.rglob("*.json")) - except OSError: - local_paths = [] - for path in local_paths: - rendered_paths = {str(path)} - with contextlib.suppress(OSError): - rendered_paths.add(str(path.resolve())) - if not any(rendered in detail for rendered in rendered_paths): - continue - candidate_paths[str(path.resolve(strict=False))] = path - for path in sorted(candidate_paths.values(), key=str): - try: - payload = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError, TypeError): - continue - if not isinstance(payload, Mapping): - continue - command = payload.get("command") - watchdog_command = payload.get("watchdog_command") - timed_out = payload.get("timed_out") - returncode = payload.get("returncode") - if ( - not isinstance(command, list) - or not command - or not all(isinstance(value, str) for value in command) - or not isinstance(watchdog_command, list) - or not watchdog_command - or not all(isinstance(value, str) for value in watchdog_command) - or not isinstance(timed_out, bool) - or not isinstance(returncode, int) - or isinstance(returncode, bool) - ): - continue - records.append((path, payload)) - return tuple(records) - - -def _legacy_amplicol_probe_command(record: Mapping[str, object]) -> bool: - command = record.get("command") - if not isinstance(command, list): - return False - return any( - isinstance(value, str) and Path(value).name in _LEGACY_AMPLICOL_PROBE_NAMES - for value in command - ) - - -def _legacy_amplicol_structural_crash(record: Mapping[str, object]) -> bool: - if not _legacy_amplicol_probe_command(record): - return False - output = "\n".join( - str(record.get(field, "")) for field in ("stdout", "stderr") - ).lower() - return ( - ("program received signal sigsegv" in output or "segmentation fault" in output) - and "init_col" in output - ) - - -def _mark_legacy_amplicol_structural_limit(cell: dict[str, object]) -> None: - cell["failure_category"] = LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY - cell["failure_reason_short"] = "legacy AmpliCol structural colour-init limit" - cell["censors_higher_multiplicities"] = True - - -def normalize_loaded_failure_cells( - report: dict[str, object], run_root: Path -) -> bool: - """Upgrade historical legacy-probe colour-init crashes to censoring cells.""" - - cells = report.get("cells") - if not isinstance(cells, dict): - return False - changed = False - for family, family_cells in cells.items(): - if not isinstance(family, str) or not isinstance(family_cells, dict): - continue - curve = family_cells.get("amplicol") - if not isinstance(curve, dict): - continue - for raw_n, cell in curve.items(): - if ( - not isinstance(raw_n, str) - or not raw_n.isdigit() - or not isinstance(cell, dict) - or cell.get("status") != "failed" - or cell.get("failure_category") - == LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY - ): - continue - reason = cell.get("failure_reason") - if not isinstance(reason, str): - continue - cell_root = run_root / "amplicol" / family / f"n{raw_n}" - if any( - _legacy_amplicol_structural_crash(record) - for _, record in _referenced_command_records(reason, cell_root) - ): - _mark_legacy_amplicol_structural_limit(cell) - changed = True - return changed - - -def _is_memory_watchdog_record(record: Mapping[str, object]) -> bool: - command = record["command"] - watchdog_command = record["watchdog_command"] - assert isinstance(command, list) - assert isinstance(watchdog_command, list) - try: - separator = watchdog_command.index("--") - except ValueError: - return False - return ( - str(performance.WATCHDOG) in watchdog_command[:separator] - and watchdog_command[separator + 1 :] == command - ) - - -def _watchdog_outcome( - record: Mapping[str, object], cell_root: Path -) -> str | None: - raw_report_path = record.get("watchdog_report") - if not isinstance(raw_report_path, str) or not raw_report_path: - return None - report_path = Path(raw_report_path) - if not report_path.is_absolute(): - report_path = ROOT / report_path - try: - resolved_report = report_path.resolve(strict=True) - resolved_report.relative_to(cell_root.resolve(strict=False)) - payload = json.loads(resolved_report.read_text(encoding="utf-8")) - execution = payload["execution"] - except ( - OSError, - ValueError, - json.JSONDecodeError, - KeyError, - TypeError, - ): - return None - if ( - not isinstance(payload, Mapping) - or payload.get("kind") != memory_watchdog.WATCHDOG_REPORT_KIND - or payload.get("schema_version") != memory_watchdog.WATCHDOG_REPORT_SCHEMA - or payload.get("complete") is not True - or not isinstance(execution, Mapping) - or not isinstance(execution.get("outcome"), str) - ): - return None - return str(execution["outcome"]) - - -def _typed_command_failure_category( - error: Exception, - cell_root: Path, - records: Sequence[tuple[Path, Mapping[str, object]]], -) -> str: - timeout_category = ( - error.timeout_category - if isinstance(error, _CellCommandError) - else "generation-time-limit" - ) - if any(record["timed_out"] is True for _, record in records): - return timeout_category - for _, record in records: - watchdog_outcome = _watchdog_outcome(record, cell_root) - if watchdog_outcome == "memory-limit-exceeded": - return "memory-limit" - if watchdog_outcome is not None: - continue - if ( - record["returncode"] == memory_watchdog.MEMORY_LIMIT_EXIT_CODE - and _is_memory_watchdog_record(record) - ): - return "memory-limit" - if any(_legacy_amplicol_structural_crash(record) for _, record in records): - return LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY - return "error" - - -def _failure_cell( - base: Mapping[str, object], error: Exception, cell_root: Path -) -> dict[str, object]: - detail = str(error) - command_records = _referenced_command_records(detail, cell_root) - disk_evidence = "\n".join( - ( - detail, - *( - str(record.get(field, "")) - for _, record in command_records - for field in ("stdout", "stderr") - ), - ) - ).lower() - category = "error" - if getattr(error, "errno", None) == 28 or any( - marker in disk_evidence - for marker in ("no space left on device", "errno 28", "enospc") - ): - category = "disk-infrastructure-failure" - elif isinstance(error, _CellResourceLimitError): - category = error.category - elif isinstance(error, legacy_report.ProfilingTimeLimitError): - category = "runtime-time-limit" - else: - category = _typed_command_failure_category( - error, cell_root, command_records - ) - censors_higher_multiplicities = category in _CENSORING_FAILURE_CATEGORIES - cell = dict(base) | { - "status": "failed", - "censors_higher_multiplicities": censors_higher_multiplicities, - "failure_category": category, - "failure_reason": detail, - } - if category == LEGACY_AMPLICOL_STRUCTURAL_LIMIT_CATEGORY: - _mark_legacy_amplicol_structural_limit(cell) - return cell - - -def _reference_cell( - *, - arguments: argparse.Namespace, - reference: Any, - run_root: Path, - environment: Mapping[str, str], - final_multiplicity: int, -) -> dict[str, object]: - try: - result = performance._run_reference( - reference=reference, - total_gluons=final_multiplicity + 2, - run_root=run_root, - python=arguments.python, - environment=environment, - fc=arguments.fc, - target_seconds=arguments.target_seconds, - timeout_seconds=arguments.runtime_timeout, - cold_limit_seconds=arguments.generation_timeout, - memory_limit_gib=arguments.memory_limit_gib, - repetition_quantum=arguments.batch_size, - warm_sample_count=PROFILE_SAMPLE_COUNT, - sum_helicities=arguments.compare_helicity_sums, - ) - except performance.ReferenceColdLimitError as error: - raise _CellResourceLimitError( - str(error), category="generation-time-limit" - ) from error - metrics = result.metrics - if metrics.setup_to_ready_seconds >= arguments.generation_timeout: - raise _CellResourceLimitError( - "reference generation reached the strict generation cap", - category="generation-time-limit", - ) - shared_event_paths = tuple(str(path) for path in result.event_paths) - if tuple(metrics.event_paths) != shared_event_paths: - raise StudyError("reference shared event-path provenance is inconsistent") - timed_event_paths = ( - tuple(str(path) for path in metrics.exhaustive_event_paths) - if arguments.compare_helicity_sums - else shared_event_paths - ) - if ( - len(shared_event_paths) != POINT_COUNT - or len(timed_event_paths) != POINT_COUNT - ): - raise StudyError("reference event-path provenance must contain ten points") - return _cell_base( - "gg", - MODE_BY_KEY["reference-fft"], - final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) | { - "status": "measured", - "helicity": list(metrics.selected_helicity), - # Compatibility: candidate/shared kinematics continue to consume - # event_paths. The explicit aliases prevent a summed Reference timing - # run from falsely claiming that those fixed-H files were timed. - "event_paths": list(shared_event_paths), - "shared_event_paths": list(shared_event_paths), - "timed_event_paths": list(timed_event_paths), - "event_path_semantics": { - "shared": "fixed-helicity event files reused by comparison curves", - "timed": ( - "exhaustive-helicity Reference input files" - if arguments.compare_helicity_sums - else "same fixed-helicity event files as shared" - ), - "event_paths_compatibility_alias": "shared_event_paths", - }, - "point_values": list(metrics.matrix_elements), - "metrics": { - "generation_seconds": metrics.setup_to_ready_seconds, - "warm_seconds_per_point": metrics.warm_median_seconds, - "max_rss_kib": _require_bounded_rss( - metrics.max_rss_kib, arguments.memory_limit_gib - ), - }, - "reference": asdict(metrics), - **( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "helicity_coverage_count": metrics.helicity_coverage_count, - "timed_helicity_count": metrics.timed_helicity_count, - "active_helicity_count": metrics.active_helicity_count, - "helicity_count_semantics": { - "coverage": "complete physical input-helicity axis", - "active": "analytic-nonzero configurations", - "timed": "analytic-nonzero configurations evaluated per sum", - }, - } - if arguments.compare_helicity_sums - else {} - ), - } - - -class _WatchedLegacyExecutor: - """Route the authoritative legacy-library workflow through cell limits.""" - - def __init__( - self, - *, - arguments: argparse.Namespace, - environment: Mapping[str, str], - log_root: Path, - ) -> None: - self.arguments = arguments - self.environment = dict(environment) - self.log_root = log_root - self.command_index = 0 - self.generation_deadline = time.monotonic() + arguments.generation_timeout - self.runtime_deadline: float | None = None - self.maximum_rss_kib = 0 - self.maximum_guard_kib = 0 - - def run( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - environment: Mapping[str, str] | None = None, - ) -> legacy_report.CommandResult: - rendered = tuple(os.fspath(item) for item in args) - if not rendered: - raise StudyError("legacy AmpliCol requested an empty command") - executable = Path(rendered[0]).name - if ( - executable == "amplicol_color_library_probe" - and self.runtime_deadline is None - ): - self.runtime_deadline = time.monotonic() + self.arguments.runtime_timeout - deadline = ( - self.runtime_deadline - if self.runtime_deadline is not None - else self.generation_deadline - ) - remaining = deadline - time.monotonic() - if remaining <= 0.0: - stage = "runtime" if self.runtime_deadline is not None else "generation" - raise _CellResourceLimitError( - f"AmpliCol generated-library {stage} deadline expired", - category=f"{stage}-time-limit", - ) - self.command_index += 1 - command_environment = { - **self.environment, - **({} if environment is None else dict(environment)), - } - log_path = self.log_root / f"{self.command_index:03d}-{executable}.json" - try: - completed = performance._run_watched( - _exec_in_command( - self.arguments.python, - cwd, - rendered, - ), - python=self.arguments.python, - environment=command_environment, - timeout_seconds=remaining, - log_path=log_path, - memory_limit_gib=self.arguments.memory_limit_gib, - watchdog_report_path=log_path.with_suffix(".watchdog.json"), - ) - except performance.AcceptanceError as error: - stage = "runtime" if self.runtime_deadline is not None else "generation" - raise _CellCommandError( - f"AmpliCol generated-library {stage} command failed: {error}", - timeout_category=f"{stage}-time-limit", - ) from error - if completed.peak_rss_kib is None or completed.peak_guard_kib is None: - raise StudyError("AmpliCol generated-library RSS evidence is missing") - self.maximum_rss_kib = max(self.maximum_rss_kib, completed.peak_rss_kib) - self.maximum_guard_kib = max(self.maximum_guard_kib, completed.peak_guard_kib) - return legacy_report.CommandResult( - args=rendered, - cwd=cwd, - elapsed_seconds=completed.elapsed_seconds, - returncode=completed.returncode, - stdout=completed.stdout, - stderr=completed.stderr, - environment={} if environment is None else dict(environment), - ) - - -_SUMMED_AMPLICOL_PROBE_OVERLAY_ABI = ( - "pyamplicol-summed-amplicol-probe-source-overlay-v1" -) -_SUMMED_AMPLICOL_FERMION_GUARD = ( - " ! No fermion permutation sign is represented here. Keep fermions\n" - " ! fixed and use this fallback only for identical bosonic legs.\n" - " if (label.ne.local_label .and. &\n" - " phys_model%is_fermion(pgl(jgroup)%processes(label,jint))) then\n" -) -_SUMMED_AMPLICOL_UNIQUE_FERMION_GUARD = ( - " ! Relabelling a fermion is sign-free only when its exact PDG is\n" - " ! unique on this side. Repeated identical fermions remain fixed.\n" - " if (.not.fermion_relabel_is_unique(" - "jgroup,jint,label,local_label)) then\n" -) -_SUMMED_AMPLICOL_FALLBACK_GUARD = """ if (pos.ne.local_label .and. & - phys_model%is_fermion(pgl(jgroup)%processes(pos,jint))) cycle -""" -_SUMMED_AMPLICOL_UNIQUE_FALLBACK_GUARD = ( - " if (.not.fermion_relabel_is_unique(" - "jgroup,jint,pos,local_label)) cycle\n" -) -_SUMMED_AMPLICOL_HELPER_ANCHOR = ( - " logical function is_pure_gluon_word(jgroup,jint,word,nord)\n" -) -_SUMMED_AMPLICOL_HELPER = """ logical function fermion_relabel_is_unique( & - jgroup,jint,label,local_label) - implicit none - integer,intent(in) :: jgroup,jint,label,local_label - integer :: position, generated_count, local_count, particle - fermion_relabel_is_unique = .true. - if (label.eq.local_label) return - particle = pgl(jgroup)%processes(label,jint) - if (.not.phys_model%is_fermion(particle)) return - generated_count = 0 - local_count = 0 - do position=1,n - if ((position.le.2).eqv.(label.le.2)) then - if (pgl(jgroup)%processes(position,jint).eq.particle) & - generated_count = generated_count + 1 - endif - if ((position.le.2).eqv.(local_label.le.2)) then - if (local_part(position,1).eq.local_part(local_label,1)) & - local_count = local_count + 1 - endif - enddo - fermion_relabel_is_unique = generated_count.eq.1 .and. local_count.eq.1 - end function fermion_relabel_is_unique - -""" - - -def _replace_summed_amplicol_probe_anchor( - source: str, old: str, new: str, *, label: str -) -> str: - count = source.count(old) - if count != 1: - raise StudyError( - f"pinned summed AmpliCol probe anchor {label!r} occurs {count} times, " - "expected exactly once" - ) - return source.replace(old, new, 1) - - -def _transform_summed_amplicol_probe_source(payload: bytes) -> bytes: - """Apply the exact unique-same-side-fermion row-map fix to pinned source.""" - - try: - source = payload.decode("utf-8") - except UnicodeDecodeError as error: - raise StudyError("pinned AmpliCol library probe source is not UTF-8") from error - source = _replace_summed_amplicol_probe_anchor( - source, - _SUMMED_AMPLICOL_FERMION_GUARD, - _SUMMED_AMPLICOL_UNIQUE_FERMION_GUARD, - label="colour-row fermion guard", - ) - source = _replace_summed_amplicol_probe_anchor( - source, - _SUMMED_AMPLICOL_FALLBACK_GUARD, - _SUMMED_AMPLICOL_UNIQUE_FALLBACK_GUARD, - label="singlet-row fermion guard", - ) - source = _replace_summed_amplicol_probe_anchor( - source, - _SUMMED_AMPLICOL_HELPER_ANCHOR, - _SUMMED_AMPLICOL_HELPER + _SUMMED_AMPLICOL_HELPER_ANCHOR, - label="unique-fermion helper insertion", - ) - return source.encode("utf-8") - - -def _summed_amplicol_source_stat(value: os.stat_result) -> dict[str, int]: - return { - "mode": value.st_mode, - "size": value.st_size, - "uid": value.st_uid, - "gid": value.st_gid, - "atime_ns": value.st_atime_ns, - "mtime_ns": value.st_mtime_ns, - } - - -@contextlib.contextmanager -def _summed_amplicol_probe_source_overlay( - repository: Path, - artifact_root: Path, -) -> Any: - """Temporarily install the summed-probe fix into one clean pinned checkout.""" - - repository = repository.expanduser().resolve() - source = repository / "amplicol_color_library_probe.f03" - with legacy_structural_probe_lock(repository): - # Validate under the same lock as the temporary edit. This rejects a - # modified checkout rather than treating arbitrary source as an overlay input. - legacy_amplicol.validate_checkout(repository) - if not source.is_file(): - raise StudyError( - f"pinned AmpliCol library probe source is absent: {source}" - ) - original_stat = source.stat() - original = source.read_bytes() - patched = _transform_summed_amplicol_probe_source(original) - if patched == original: - raise StudyError("summed AmpliCol probe overlay made no source change") - snapshot = artifact_root / "amplicol_color_library_probe.f03" - manifest = artifact_root / "provenance.json" - record: dict[str, object] = { - "abi": _SUMMED_AMPLICOL_PROBE_OVERLAY_ABI, - "scope": "summed-generated-library-amplicol-cells-only", - "checkout_validation": "clean-pinned-revision-under-structural-probe-lock", - "revision": legacy_amplicol.expected_revision(), - "repository": str(repository), - "source": source.name, - "original_sha256": hashlib.sha256(original).hexdigest(), - "patched_sha256": hashlib.sha256(patched).hexdigest(), - "patched_source_snapshot": str(snapshot), - "manifest": str(manifest), - "source_stat_before": _summed_amplicol_source_stat(original_stat), - "restoration": {"status": "pending"}, - } - completed = False - try: - legacy_structure_tools._atomic_write(snapshot, patched) - legacy_structure_tools._atomic_json(manifest, record) - legacy_structure_tools._atomic_write(source, patched) - os.chmod(source, original_stat.st_mode) - yield record - completed = True - finally: - legacy_structure_tools._atomic_write(source, original) - os.chmod(source, original_stat.st_mode) - os.utime( - source, - ns=(original_stat.st_atime_ns, original_stat.st_mtime_ns), - ) - restored = source.read_bytes() - # Undo any atime update caused by the byte-for-byte verification. - os.utime( - source, - ns=(original_stat.st_atime_ns, original_stat.st_mtime_ns), - ) - restored_stat = source.stat() - stat_after = _summed_amplicol_source_stat(restored_stat) - stat_before = _summed_amplicol_source_stat(original_stat) - if restored != original or stat_after != stat_before: - raise StudyError( - "summed AmpliCol probe overlay failed to restore its source" - ) - record["restoration"] = { - "status": "restored", - "body_exit": "success" if completed else "exception", - "sha256": hashlib.sha256(restored).hexdigest(), - "source_stat_after": stat_after, - } - legacy_structure_tools._atomic_json(manifest, record) - - -def _amplicol_summed_cell( - *, - arguments: argparse.Namespace, - family: str, - final_multiplicity: int, - events: Sequence[Path], - helicity: Sequence[int], - baseline: Mapping[str, object] | None, - run_root: Path, - environment: Mapping[str, str], -) -> dict[str, object]: - """Measure the create-raw bulk-family complete helicity sum.""" - - base = _cell_base( - family, - MODE_BY_KEY["amplicol"], - final_multiplicity, - sum_helicities=True, - ) - cell_root = run_root / "amplicol" / family / f"n{final_multiplicity}" - setup = cell_root / "setup" - setup.mkdir(parents=True, exist_ok=True) - momenta, event_helicity = _read_event(events[0]) - if tuple(helicity) != event_helicity: - raise StudyError("AmpliCol event helicity differs from the shared input") - - cell = CellSpec( - dataset_id="fft-scaling-helicity-sum", - process=process_expression(family, final_multiplicity), - n_final=final_multiplicity, - process_key=family, - measurement=MeasurementSpec( - execution_mode=ExecutionMode.AMPLICOL, - model=None, - accuracy=Accuracy.FULL, - backend="original-amplicol-generated-library", - jit_optimization_level=None, - ), - workload=Workload.CONTRACTED, - ) - executor = _WatchedLegacyExecutor( - arguments=arguments, - environment=environment, - log_root=cell_root / "commands", - ) - adapter = legacy_report.LegacyMeasurementAdapter( - executor=executor, - structural_proof=False, - ) - settings = legacy_report.LegacySettings( - target_runtime_seconds=arguments.target_seconds, - warmup_points=1, - minimum_points=1, - maximum_points=AMPLI_COL_MAX_POINTS, - minimum_profile_chunks=PROFILE_SAMPLE_COUNT, - maximum_profile_chunks=PROFILE_SAMPLE_COUNT + 1, - jobs=1, - repository=arguments.amplicol_repository, - validate_checkout=False, - profiling_time_limit_seconds=arguments.runtime_timeout, - ) - commands: list[dict[str, object]] = [] - log_path = cell_root / "legacy-generated-library.log" - generation_started = time.perf_counter() - with _summed_amplicol_probe_source_overlay( - arguments.amplicol_repository, - cell_root / "summed-probe-source-overlay", - ) as probe_source_overlay: - context = adapter._prepare_process( - cell, - repository=arguments.amplicol_repository, - artifact_path=setup, - commands=commands, - log_path=log_path, - ) - context = replace( - context, - momenta=tuple(tuple(float(value) for value in row) for row in momenta), - points=(tuple(tuple(float(value) for value in row) for row in momenta),), - ) - adapter._generate_library( - context=context, - repository=arguments.amplicol_repository, - raw_color=True, - n_final=final_multiplicity, - settings=settings, - commands=commands, - log_path=log_path, - ) - adapter._run( - ("make", "-j1", "amplicol_color_library_probe"), - cwd=arguments.amplicol_repository, - commands=commands, - log_path=log_path, - ) - generated = adapter.snapshotter.snapshot( - arguments.amplicol_repository, - cell_root / "contracted-generated-library", - executables=("amplicol_color_library_probe",), - process_file=context.process_file, - ) - ordered = adapter.api.ordered_momenta( - context.source_pdgs, - context.entry.process_pdgs, - context.momenta, - ) - momentum_path = generated / "momenta.dat" - momentum_path.write_text( - "\n".join( - " ".join(format(component, ".17g") for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - generation_seconds = time.perf_counter() - generation_started - if generation_seconds >= arguments.generation_timeout: - raise _CellResourceLimitError( - "AmpliCol generated-library generation reached its cap", - category="generation-time-limit", - ) - library_environment = legacy_report._library_environment(generated) - profile = adapter._profile( - lambda count: adapter._invoke_command( - ( - "./amplicol_color_library_probe", - str(count), - str(context.entry.group), - str(context.entry.integral), - Accuracy.FULL.value, - momentum_path.name, - ), - cwd=generated, - environment=library_environment, - commands=commands, - log_path=log_path, - ), - settings=settings, - timing_labels=("total",), - ) - validation_result, _, _ = adapter._invoke_command( - ( - "./amplicol_color_library_probe", - "1", - str(context.entry.group), - str(context.entry.integral), - Accuracy.FULL.value, - momentum_path.name, - ), - cwd=generated, - environment=library_environment, - commands=commands, - log_path=log_path, - ) - matrix_element = legacy_report._parse_generated_library_color_probe_output( - validation_result.stdout + "\n" + validation_result.stderr, - expected_accuracy=Accuracy.FULL.value, - expected_group=int(context.entry.group), - expected_integral=int(context.entry.integral), - ) - if not _positive_finite(matrix_element): - raise StudyError("AmpliCol generated library returned a zero/non-finite sum") - numerical = _numerical_evidence( - family=family, - final_multiplicity=final_multiplicity, - alpha_s=arguments.alpha_s, - observed=(matrix_element,), - baseline=baseline, - ) - if numerical["passes"] is False: - raise StudyError( - "AmpliCol generated-library numerical comparison failed: relative " - f"error {numerical['maximum_relative_error']:.6g}" - ) - helicity_coverage_count = 2 ** len(context.source_pdgs) - warm_seconds_per_point = profile.seconds / profile.points - return base | { - "status": "measured", - "helicity": list(helicity), - "event_paths": [str(path) for path in events], - "point_values": [matrix_element], - "metrics": { - "generation_seconds": generation_seconds, - "warm_seconds_per_point": warm_seconds_per_point, - "max_rss_kib": _require_bounded_rss( - executor.maximum_rss_kib, - arguments.memory_limit_gib, - ), - }, - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "helicity_coverage_count": helicity_coverage_count, - "helicity_count_semantics": { - "coverage": "complete physical input-helicity axis", - "timed": None, - "timed_unavailable_reason": ( - "the create-raw probe prunes combinations with no mapped colour-" - "row amplitude but does not expose its retained count" - ), - }, - "helicity_compaction": ( - "probe-local no-mapped-amplitude pruning only; create-raw does not " - "apply the generated library's hel_fac filter" - ), - "generated_library": str(generated), - "runtime_profile": { - "points": profile.points, - "seconds": profile.seconds, - "standard_error_seconds_per_point": ( - profile.standard_error_seconds_per_point - ), - "relative_standard_error": profile.relative_standard_error, - "record": dict(profile.record), - "warmup": dict(profile.warmup_record), - }, - "resource_peaks_kib": { - "maximum_child_rss": executor.maximum_rss_kib, - "maximum_child_guard": executor.maximum_guard_kib, - }, - "process_entry": asdict(context.entry) - | {"matching_row_count": context.matching_rows}, - "numerical": numerical, - "provenance": { - "implementation": ( - "original-amplicol-create-raw-bulk-family-complete-helicity-sum" - ), - "helicity_selector": None, - "probe_source_overlay": probe_source_overlay, - "commands": commands, - }, - } - - -def _amplicol_cell( - *, - arguments: argparse.Namespace, - family: str, - final_multiplicity: int, - events: Sequence[Path], - helicity: Sequence[int], - baseline: Mapping[str, object] | None, - run_root: Path, - environment: Mapping[str, str], -) -> dict[str, object]: - if arguments.compare_helicity_sums: - return _amplicol_summed_cell( - arguments=arguments, - family=family, - final_multiplicity=final_multiplicity, - events=events, - helicity=helicity, - baseline=baseline, - run_root=run_root, - environment=environment, - ) - base = _cell_base( - family, - MODE_BY_KEY["amplicol"], - final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) - cell_root = run_root / "amplicol" / family / f"n{final_multiplicity}" - setup = cell_root / "setup" - setup.mkdir(parents=True, exist_ok=True) - generation = performance._run_watched( - _exec_in_command( - arguments.python, - setup, - ( - arguments.python, - str(arguments.amplicol_repository / "process_list.py"), - "--serial", - process_expression(family, final_multiplicity), - ), - ), - python=arguments.python, - environment=environment, - timeout_seconds=arguments.generation_timeout, - log_path=cell_root / "process-generation.json", - memory_limit_gib=arguments.memory_limit_gib, - watchdog_report_path=cell_root / "process-generation-watchdog.json", - ) - process_file = setup / "processes.txt" - entries = legacy_amplicol.parse_process_file(process_file) - source_pdgs = legacy_amplicol.process_pdgs( - process_expression(family, final_multiplicity) - ) - entry, matches = legacy_amplicol.select_generated_process_entry( - entries, - generated_process=process_expression(family, final_multiplicity), - wanted_pdgs=source_pdgs, - ) - momenta, event_helicity = _read_event(events[0]) - if tuple(helicity) != event_helicity: - raise StudyError( - "AmpliCol event helicity differs from the frozen cell helicity" - ) - permutation = legacy_amplicol._permutation(source_pdgs, entry.process_pdgs) - ordered_momenta = legacy_amplicol._ordered_binary64_momenta( - source_pdgs, entry.process_pdgs, momenta - ) - ordered_helicity = tuple(int(helicity[index]) for index in permutation) - momentum_path = setup / "momenta.dat" - momentum_path.write_text( - "\n".join( - " ".join(format(float(component), ".17g") for component in row) - for row in ordered_momenta - ) - + "\n", - encoding="utf-8", - ) - - def probe_command(points: int) -> tuple[str, ...]: - return _exec_in_command( - arguments.python, - setup, - ( - str((arguments.amplicol_repository / "amplicol_color_probe").resolve()), - str(points), - str(entry.group), - str(entry.integral), - "full", - str(process_file), - str(momentum_path), - *(str(value) for value in ordered_helicity), - ), - ) - - probe_wall_budget = min( - arguments.runtime_timeout, - arguments.generation_timeout - generation.elapsed_seconds, - ) - if probe_wall_budget <= 0.0: - raise _CellResourceLimitError( - "AmpliCol process generation exhausted the generation cap", - category="generation-time-limit", - ) - probe_wall_elapsed = 0.0 - runtime_self_rss_kib = 0 - runtime_watchdog_rss_kib = 0 - runtime_guard_rss_kib = 0 - - def run_probe( - points: int, probe_environment: Mapping[str, str], log_path: Path - ) -> performance.WatchedCompletedProcess: - nonlocal probe_wall_elapsed - nonlocal runtime_guard_rss_kib - nonlocal runtime_self_rss_kib - nonlocal runtime_watchdog_rss_kib - remaining = probe_wall_budget - probe_wall_elapsed - if remaining <= 0.0: - raise _CellResourceLimitError( - "AmpliCol warm sampling exhausted the per-cell time cap", - category="setup-or-runtime-time-limit", - ) - timed_command, normalizer = _timed_command( - probe_command(points), python=arguments.python - ) - try: - completed = performance._run_watched( - timed_command, - python=arguments.python, - environment=probe_environment, - timeout_seconds=remaining, - log_path=log_path, - memory_limit_gib=arguments.memory_limit_gib, - watchdog_report_path=log_path.with_suffix(".watchdog.json"), - normalize_completed=normalizer, - ) - except performance.AcceptanceError as error: - raise _CellCommandError( - f"AmpliCol setup/runtime probe failed: {error}", - timeout_category="setup-or-runtime-time-limit", - ) from error - probe_wall_elapsed += completed.elapsed_seconds - if completed.peak_rss_kib is None or completed.peak_guard_kib is None: - raise StudyError("AmpliCol runtime watchdog peak evidence is missing") - runtime_self_rss_kib = max( - runtime_self_rss_kib, _parse_rss_marker(completed.stderr) - ) - runtime_watchdog_rss_kib = max(runtime_watchdog_rss_kib, completed.peak_rss_kib) - runtime_guard_rss_kib = max(runtime_guard_rss_kib, completed.peak_guard_kib) - return completed - - adaptive_environment = dict(environment) - adaptive_environment["AMPICOL_COLOR_PROBE_TARGET_RUNTIME_S"] = ( - f"{arguments.target_seconds:.17g}" - ) - completed = run_probe( - AMPLI_COL_MAX_POINTS, adaptive_environment, cell_root / "probe.json" - ) - generation_setup, seed_total_seconds, adaptive_points = ( - _parse_amplicol_timing_aggregate(completed.stdout) - ) - generation_seconds = generation.elapsed_seconds + generation_setup - if generation_seconds >= arguments.generation_timeout: - raise _CellResourceLimitError( - "AmpliCol generation reached the strict generation cap", - category="generation-time-limit", - ) - - fixed_environment = dict(environment) - fixed_environment.pop("AMPICOL_COLOR_PROBE_TARGET_RUNTIME_S", None) - - def run_sample(sample_set: int, sample: int, repetitions: int) -> str: - return run_probe( - repetitions, - fixed_environment, - cell_root / f"warm-sample-set-{sample_set:02d}-sample-{sample:02d}.json", - ).stdout - - warm = _collect_amplicol_warm_samples( - seed_points=adaptive_points, - seed_total_seconds=seed_total_seconds, - target_seconds=arguments.target_seconds, - run_sample=run_sample, - ) - warm_per_point = statistics.median(warm.samples_seconds) - probe = legacy_amplicol._parse_probe_output(completed.stdout) - if not math.isfinite(probe.value) or abs(probe.value) <= 1.0e-300: - raise StudyError("AmpliCol frozen helicity is zero or non-finite") - numerical = _numerical_evidence( - family=family, - final_multiplicity=final_multiplicity, - alpha_s=arguments.alpha_s, - observed=(probe.value,), - baseline=baseline, - ) - if numerical["passes"] is False: - raise StudyError( - "AmpliCol numerical comparison failed: relative error " - f"{numerical['maximum_relative_error']:.6g}" - ) - if generation.peak_rss_kib is None or generation.peak_guard_kib is None: - raise StudyError("AmpliCol generation watchdog peak evidence is missing") - generation_rss_kib = generation.peak_rss_kib - generation_guard_rss_kib = generation.peak_guard_kib - max_rss_kib = _require_bounded_rss( - max(runtime_self_rss_kib, generation_rss_kib), arguments.memory_limit_gib - ) - return base | { - "status": "measured", - "helicity": list(helicity), - "event_paths": [str(path) for path in events], - "point_values": [probe.value], - "metrics": { - "generation_seconds": generation_seconds, - "warm_seconds_per_point": warm_per_point, - "max_rss_kib": max_rss_kib, - }, - "adaptive_runtime_points": adaptive_points, - "warm_repetitions": [warm.repetitions] * len(warm.samples_seconds), - "warm_samples_seconds": list(warm.samples_seconds), - "warm_sample_totals_seconds": list(warm.sample_totals_seconds), - "warm_sample_set_attempts": warm.sample_set_attempts, - "warm_calibration_seed": { - "points": adaptive_points, - "total_seconds": seed_total_seconds, - "seconds_per_point": seed_total_seconds / adaptive_points, - }, - "resource_peaks_kib": { - "generation": generation_rss_kib, - "generation_guard": generation_guard_rss_kib, - "runtime_self": runtime_self_rss_kib, - "runtime_watchdog": runtime_watchdog_rss_kib, - "runtime_guard": runtime_guard_rss_kib, - "runtime_watchdog_included_in_plotted_rss": False, - }, - "process_entry": asdict(entry) | {"matching_row_count": len(matches)}, - "numerical": numerical, - } - - -def _load_successful_candidate_generation( - cell_root: Path, -) -> performance.WatchedCompletedProcess | None: - """Reuse one completed generation phase after a later probe failure.""" - - log_path = cell_root / "generation.json" - if not (cell_root / "artifact" / "artifact.json").is_file(): - return None - try: - payload = json.loads(log_path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError): - return None - if not isinstance(payload, Mapping): - return None - command = payload.get("command") - elapsed_seconds = payload.get("elapsed_seconds") - stdout = payload.get("stdout") - stderr = payload.get("stderr") - timeout_cleanup = payload.get("timeout_cleanup") - if ( - payload.get("returncode") != 0 - or payload.get("timed_out") is not False - or not isinstance(command, list) - or not all(isinstance(item, str) for item in command) - or not _positive_finite(elapsed_seconds) - or not isinstance(stdout, str) - or not isinstance(stderr, str) - or not isinstance(timeout_cleanup, str) - ): - return None - return performance.WatchedCompletedProcess( - command, - 0, - stdout, - stderr, - elapsed_seconds=float(elapsed_seconds), - log_write_seconds=0.0, - timed_out=False, - timeout_cleanup=timeout_cleanup, - ) - - -def _candidate_cli_failure_allows_generation_reuse( - cell: Mapping[str, object], -) -> bool: - reason = cell.get("failure_reason") - return isinstance(reason, str) and reason.startswith( - ("candidate CLI evaluate", "candidate CLI profile", "OTF CLI profile") - ) - - -def _symbolica_generation_lock_path( - environment: Mapping[str, str], *, force: bool = False -) -> Path | None: - configured = environment.get(SYMBOLICA_GENERATION_LOCK_ENV) - if configured is not None: - if configured.strip().lower() in {"", "0", "false", "no", "off", "none"}: - return None - return Path(configured).expanduser().resolve(strict=False) - if not force and environment.get("SYMBOLICA_LICENSE", "").strip(): - return None - uid = str(os.getuid()) if hasattr(os, "getuid") else "unknown" - root = Path("/tmp") if os.name == "posix" else Path(tempfile.gettempdir()) - return root / f"pyamplicol-symbolica-generation-{uid}.lock" - - -@contextlib.contextmanager -def _bounded_symbolica_generation_lock( - lock_path: Path | None, timeout_seconds: float -) -> Iterator[None]: - if lock_path is None: - yield - return - deadline = time.monotonic() + timeout_seconds - lock_path.parent.mkdir(parents=True, exist_ok=True) - with lock_path.open("a+", encoding="utf-8") as handle: - while True: - try: - fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - break - except BlockingIOError as error: - remaining = deadline - time.monotonic() - if remaining <= 0.0: - raise _CellResourceLimitError( - "candidate artifact generation waited for the Symbolica " - "generation lock until the strict generation cap", - category="generation-time-limit", - ) from error - time.sleep(min(SYMBOLICA_LOCK_POLL_SECONDS, remaining)) - try: - yield - finally: - fcntl.flock(handle.fileno(), fcntl.LOCK_UN) - - -def _symbolica_license_busy_log(log_path: Path) -> bool: - try: - payload = json.loads(log_path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError): - return False - if not isinstance(payload, Mapping): - return False - output = "\n".join( - str(payload.get(field, "")) for field in ("stdout", "stderr") - ).lower() - return SYMBOLICA_LICENSE_BUSY_FRAGMENT in output - - -def _candidate_generation_time_exhausted() -> _CellResourceLimitError: - return _CellResourceLimitError( - "candidate artifact generation exhausted the strict generation cap", - category="generation-time-limit", - ) - - -def _run_candidate_generation( - *, - arguments: argparse.Namespace, - family: str, - final_multiplicity: int, - mode: Mode, - artifact: Path, - cell_root: Path, - environment: Mapping[str, str], -) -> performance.WatchedCompletedProcess: - command = _candidate_generation_command( - python=arguments.python, - family=family, - final_multiplicity=final_multiplicity, - mode=mode, - artifact=artifact, - batch_size=arguments.batch_size, - optimization_cores=arguments.optimization_cores, - ) - log_path = cell_root / "generation.json" - started = time.monotonic() - lock_path = _symbolica_generation_lock_path(environment) - attempts = 0 - maximum_attempts = ( - max(2, math.ceil(arguments.generation_timeout / SYMBOLICA_BUSY_RETRY_SECONDS)) - + 1 - ) - while True: - attempts += 1 - remaining = arguments.generation_timeout - (time.monotonic() - started) - if remaining <= 0.0: - raise _candidate_generation_time_exhausted() - try: - with _bounded_symbolica_generation_lock(lock_path, remaining): - remaining = arguments.generation_timeout - (time.monotonic() - started) - if remaining <= 0.0: - raise _candidate_generation_time_exhausted() - return performance._run_watched( - command, - python=arguments.python, - environment=environment, - timeout_seconds=remaining, - log_path=log_path, - memory_limit_gib=arguments.memory_limit_gib, - ) - except performance.AcceptanceError as error: - if not _symbolica_license_busy_log(log_path): - raise - if attempts >= maximum_attempts: - raise _candidate_generation_time_exhausted() from error - lock_path = lock_path or _symbolica_generation_lock_path( - environment, force=True - ) - remaining = arguments.generation_timeout - (time.monotonic() - started) - if remaining <= SYMBOLICA_BUSY_RETRY_SECONDS: - raise _candidate_generation_time_exhausted() from error - time.sleep(min(SYMBOLICA_BUSY_RETRY_SECONDS, remaining)) - - -def _validate_publication_candidate_artifact( - artifact: Path, - process: str, -) -> int: - """Require an authoritative all-runtime-helicity artifact contract.""" - - execution_path = artifact / "processes" / process / "execution.json" - try: - execution = json.loads(execution_path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError, TypeError): - execution = None - on_the_fly_kind = "pyamplicol-runtime-on-the-fly-execution" - if isinstance(execution, Mapping) and execution.get("kind") == on_the_fly_kind: - try: - selector_policy = execution["selector_policy"] - selector_census = selector_policy["selector_census"] - physical_helicity_count = selector_census["physical_helicity_count"] - runtime_metadata = execution["runtime_metadata"] - process_seed_identity = runtime_metadata["process_seed_identity"] - external_sources = process_seed_identity["external_sources"] - except (KeyError, TypeError) as error: - raise StudyError( - "candidate on-the-fly artifact has a malformed helicity contract" - ) from error - if ( - not isinstance(execution.get("schema_version"), int) - or isinstance(execution.get("schema_version"), bool) - or execution.get("schema_version") != 3 - or execution.get("kind") != on_the_fly_kind - or not isinstance(selector_policy, Mapping) - or selector_policy.get("color_coverage") != "contracted" - or not isinstance(selector_census, Mapping) - or not isinstance(physical_helicity_count, int) - or isinstance(physical_helicity_count, bool) - or physical_helicity_count <= 1 - or not isinstance(runtime_metadata, Mapping) - or not isinstance(process_seed_identity, Mapping) - or not isinstance(external_sources, list) - or not external_sources - ): - raise StudyError( - "candidate on-the-fly artifact has an invalid helicity contract" - ) - - derived_helicity_count = 1 - source_slots: set[int] = set() - for source_index, source in enumerate(external_sources): - if not isinstance(source, Mapping): - raise StudyError( - "candidate on-the-fly artifact has a malformed source identity" - ) - source_slot = source.get("source_slot") - states = source.get("states") - if ( - not isinstance(source_slot, int) - or isinstance(source_slot, bool) - or source_slot != source_index - or source_slot in source_slots - or not isinstance(states, list) - or not states - ): - raise StudyError( - "candidate on-the-fly artifact has an invalid source identity" - ) - source_slots.add(source_slot) - state_indices: set[int] = set() - public_helicities: set[int] = set() - for state in states: - if not isinstance(state, Mapping): - raise StudyError( - "candidate on-the-fly artifact has a malformed source state" - ) - state_index = state.get("state_index") - public_helicity = state.get("public_helicity") - if ( - not isinstance(state_index, int) - or isinstance(state_index, bool) - or state_index < 0 - or state_index in state_indices - or not isinstance(public_helicity, int) - or isinstance(public_helicity, bool) - or public_helicity in public_helicities - ): - raise StudyError( - "candidate on-the-fly artifact has an invalid source state" - ) - state_indices.add(state_index) - public_helicities.add(public_helicity) - derived_helicity_count *= len(states) - if derived_helicity_count != physical_helicity_count: - raise StudyError( - "candidate on-the-fly artifact helicity census disagrees with " - "its process seed" - ) - return physical_helicity_count - - physics_path = artifact / "processes" / process / "physics.json" - try: - physics = json.loads(physics_path.read_text(encoding="utf-8")) - coverage = physics["coverage"] - selectors = physics["extensions"]["runtime_selectors"] - helicity_axis = selectors["axes"]["helicity"] - specialized_axes = selectors["generation_specialized_axes"] - helicities = physics["helicities"] - except (OSError, json.JSONDecodeError, KeyError, TypeError) as error: - raise StudyError( - "candidate artifact has no readable helicity-coverage contract" - ) from error - if ( - not isinstance(physics, Mapping) - or not isinstance(coverage, Mapping) - or not isinstance(selectors, Mapping) - or not isinstance(helicity_axis, Mapping) - or not isinstance(specialized_axes, list) - or not isinstance(helicities, list) - or len(helicities) <= 1 - or coverage.get("helicities") != "complete" - or helicity_axis.get("generation_coverage") != "complete" - or helicity_axis.get("generation_selection") != {} - or helicity_axis.get("runtime_contract") != "complete-reusable" - or "helicity" in specialized_axes - ): - raise StudyError( - "candidate artifact is not reusable for all runtime helicities" - ) - return len(helicities) - - -def _candidate_cell( - *, - arguments: argparse.Namespace, - family: str, - final_multiplicity: int, - mode: Mode, - events: Sequence[Path], - helicity: Sequence[int], - baseline: Mapping[str, object] | None, - cell_root: Path, - environment: Mapping[str, str], -) -> dict[str, object]: - assert mode.execution_mode is not None - base = _cell_base( - family, - mode, - final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) - artifact = cell_root / "artifact" - generation = _load_successful_candidate_generation(cell_root) - if generation is None: - generation = _run_candidate_generation( - arguments=arguments, - family=family, - final_multiplicity=final_multiplicity, - mode=mode, - artifact=artifact, - cell_root=cell_root, - environment=environment, - ) - generation_helicity_count = _validate_publication_candidate_artifact( - artifact, - process_key(family, final_multiplicity), - ) - momenta_path, parameters_path = _write_candidate_cli_inputs( - cell_root=cell_root, - events=events, - alpha_s=arguments.alpha_s, - ) - evaluate_command = _candidate_evaluate_command( - python=arguments.python, - artifact=artifact, - process=process_key(family, final_multiplicity), - momenta=momenta_path, - model_parameters=parameters_path, - helicity=helicity, - sum_helicities=arguments.compare_helicity_sums, - ) - evaluate_timeout = arguments.generation_timeout - generation.elapsed_seconds - if evaluate_timeout <= 0.0: - raise _CellResourceLimitError( - "candidate artifact generation exhausted the strict generation cap", - category="generation-time-limit", - ) - try: - evaluated = performance._run_watched( - evaluate_command, - python=arguments.python, - environment=environment, - timeout_seconds=evaluate_timeout, - log_path=cell_root / "evaluate.json", - memory_limit_gib=arguments.memory_limit_gib, - ) - except performance.AcceptanceError as error: - raise _CellCommandError( - f"candidate CLI evaluate failed: {error}", - timeout_category="generation-time-limit", - ) from error - values = _parse_candidate_evaluate_json(evaluated.stdout) - generation_seconds = generation.elapsed_seconds + evaluated.elapsed_seconds - if generation_seconds >= arguments.generation_timeout: - raise _CellResourceLimitError( - "candidate generation/fresh CLI evaluation reached the strict " - "generation cap", - category="generation-time-limit", - ) - generation_rss_kib = _parse_watchdog_peak_rss_kib(generation.stderr) - generation_guard_rss_kib = _parse_watchdog_peak_guard_kib(generation.stderr) - evaluate_rss_kib = _parse_watchdog_peak_rss_kib(evaluated.stderr) - evaluate_guard_rss_kib = _parse_watchdog_peak_guard_kib(evaluated.stderr) - if not any(abs(float(value)) > 1.0e-300 for value in values): - raise StudyError("candidate CLI evaluation is structurally zero") - numerical = _numerical_evidence( - family=family, - final_multiplicity=final_multiplicity, - alpha_s=arguments.alpha_s, - observed=[float(value) for value in values], - baseline=baseline, - ) - if numerical["passes"] is False: - raise StudyError( - "candidate numerical comparison failed: relative error " - f"{numerical['maximum_relative_error']:.6g}" - ) - profile_command = _candidate_profile_command( - python=arguments.python, - artifact=artifact, - process=process_key(family, final_multiplicity), - momenta=momenta_path, - helicity=helicity, - sum_helicities=arguments.compare_helicity_sums, - target_seconds=arguments.target_seconds, - batch_size=arguments.batch_size, - ) - try: - profiled = performance._run_watched( - profile_command, - python=arguments.python, - environment=environment, - timeout_seconds=arguments.runtime_timeout, - log_path=cell_root / "profile.json", - memory_limit_gib=arguments.memory_limit_gib, - ) - except performance.AcceptanceError as error: - raise _CellCommandError( - f"candidate CLI profile failed: {error}", - timeout_category="runtime-time-limit", - ) from error - profile = _parse_candidate_profile_json( - profiled.stdout, - artifact=artifact, - family=family, - final_multiplicity=final_multiplicity, - execution_mode=mode.execution_mode, - helicity=helicity, - sum_helicities=arguments.compare_helicity_sums, - target_seconds=arguments.target_seconds, - batch_size=arguments.batch_size, - ) - profile_rss_kib = _parse_watchdog_peak_rss_kib(profiled.stderr) - profile_guard_rss_kib = _parse_watchdog_peak_guard_kib(profiled.stderr) - measured_rss_kib = max( - generation_rss_kib, - evaluate_rss_kib, - profile_rss_kib, - ) - return base | { - "status": "measured", - "helicity": list(helicity), - "event_paths": [str(path) for path in events], - "artifact": str(artifact), - "point_values": values, - "metrics": { - "generation_seconds": generation_seconds, - "warm_seconds_per_point": profile["wall_time_per_point"], - "max_rss_kib": _require_bounded_rss( - measured_rss_kib, - arguments.memory_limit_gib, - ), - }, - "cli_evaluate": { - "command": list(evaluate_command), - "elapsed_seconds": evaluated.elapsed_seconds, - "result": json.loads(evaluated.stdout), - "model_parameters": { - "normalization.alpha_s_me_check": arguments.alpha_s - }, - }, - "runtime_profile_command": list(profile_command), - "runtime_profile": profile, - "resource_peaks_kib": { - "generation": generation_rss_kib, - "generation_guard": generation_guard_rss_kib, - "evaluate_watchdog": evaluate_rss_kib, - "evaluate_guard": evaluate_guard_rss_kib, - "profile_watchdog": profile_rss_kib, - "profile_guard": profile_guard_rss_kib, - "all_process_tree_peaks_included_in_plotted_rss": True, - }, - "numerical": numerical, - "generation_helicity_coverage": "all", - "generation_helicity_count": generation_helicity_count, - **( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "timed_helicity_count": generation_helicity_count, - "helicity_count_semantics": { - "coverage": "complete physical runtime input-helicity axis", - "timed": ( - "complete physical axis requested once through the null " - "helicity selector; internal structural-zero elimination " - "does not change the API workload" - ), - }, - } - if arguments.compare_helicity_sums - else {"warm_fixed_helicity": True} - ), - } - - -def _inputs( - report: Mapping[str, object], run_root: Path, family: str, final_multiplicity: int -) -> tuple[tuple[Path, ...], tuple[int, ...]]: - if family == "ddbar": - return _ddbar_events(run_root, final_multiplicity), fixed_ddbar_helicity( - final_multiplicity - ) - reference = _curve(report, "gg", "reference-fft").get(str(final_multiplicity)) - if not isinstance(reference, dict) or reference.get("status") != "measured": - raise StudyError("shared FFT reference cell is unavailable") - raw_events = reference.get("shared_event_paths", reference.get("event_paths")) - legacy_events = reference.get("event_paths") - raw_helicity = reference.get("helicity") - if ( - not isinstance(raw_events, list) - or not isinstance(legacy_events, list) - or raw_events != legacy_events - or not isinstance(raw_helicity, list) - ): - raise StudyError("shared FFT reference cell has incomplete inputs") - events = tuple(Path(str(path)) for path in raw_events) - if len(events) != POINT_COUNT or not all(path.is_file() for path in events): - raise StudyError("shared FFT reference events are unavailable") - return events, tuple(int(value) for value in raw_helicity) - - -def _baseline( - report: Mapping[str, object], family: str, final_multiplicity: int -) -> Mapping[str, object] | None: - key = "reference-fft" if family == "gg" else "amplicol" - value = _curve(report, family, key).get(str(final_multiplicity)) - return value if isinstance(value, dict) else None - - -def _prepare_support_directories(study_root: Path | None = None) -> None: - study_root = STUDY_ROOT if study_root is None else study_root - cache_root = study_root / "cache" - for path in ( - study_root / "tmp", - cache_root / "cargo-home", - cache_root / "cargo-target", - cache_root / "pip-cache", - cache_root / "xdg-cache", - cache_root / "python-cache", - ): - path.mkdir(parents=True, exist_ok=True) - - -def _study_environment(python: str, study_root: Path | None = None) -> dict[str, str]: - study_root = STUDY_ROOT if study_root is None else study_root - environment = performance._workspace_environment(python) - cache_root = study_root / "cache" - environment.update( - { - "TMPDIR": str(study_root / "tmp"), - "CARGO_HOME": str(cache_root / "cargo-home"), - "CARGO_TARGET_DIR": str(cache_root / "cargo-target"), - "PIP_CACHE_DIR": str(cache_root / "pip-cache"), - "XDG_CACHE_HOME": str(cache_root / "xdg-cache"), - "PYTHONPYCACHEPREFIX": str(cache_root / "python-cache"), - } - ) - return environment - - -def _clear_campaign_cell(path: Path) -> None: - """Remove only this campaign's exact stale cell/staging path.""" - - if path.is_dir(): - shutil.rmtree(path) - elif path.exists(): - path.unlink() - - -def _candidate_staging_root(cell_root: Path) -> Path: - return cell_root.with_name(f".{cell_root.name}.staging") - - -def _adopt_interrupted_candidate_generation( - *, - staging_root: Path, - cell_root: Path, - expected_command: Sequence[str], - process: str, -) -> bool: - """Atomically retain an interrupted cell's verified generation phase.""" - - if cell_root.exists() or not staging_root.is_dir(): - return False - generation = _load_successful_candidate_generation(staging_root) - if generation is None or tuple(generation.args) != tuple(expected_command): - return False - try: - _validate_publication_candidate_artifact(staging_root / "artifact", process) - except StudyError: - return False - staging_root.replace(cell_root) - return True - - -def _discard_candidate_artifact(cell_root: Path) -> None: - """Keep bounded failure logs but not an unpublishable artifact payload.""" - - artifact = cell_root / "artifact" - if artifact.is_dir(): - shutil.rmtree(artifact) - elif artifact.exists(): - artifact.unlink() - - -def _promote_candidate_cell( - staging_root: Path, - cell_root: Path, - cell: dict[str, object], -) -> None: - """Atomically publish one completed cell and normalize its artifact path.""" - - if not staging_root.is_dir() or cell_root.exists(): - raise StudyError("candidate cell staging cannot be promoted atomically") - artifact = cell.get("artifact") - if isinstance(artifact, str): - expected = staging_root / "artifact" - if Path(artifact) != expected: - raise StudyError("candidate cell recorded an unexpected staged artifact") - staging_root.replace(cell_root) - if isinstance(artifact, str): - cell["artifact"] = str(cell_root / "artifact") - - -def _acquire_campaign_lock(lock_root: Path | None = None) -> Any: - """Prevent two scaling-study campaign drivers from overlapping.""" - - lock_root = STUDY_ROOT if lock_root is None else lock_root - lock_path = lock_root / ".campaign.lock" - handle = lock_path.open("a+", encoding="utf-8") - try: - fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError as error: - handle.close() - raise StudyError(f"another campaign driver holds {lock_path}") from error - return handle - - -def _campaign(arguments: argparse.Namespace) -> dict[str, object]: - global STUDY_ROOT - study_root = _study_root(arguments) - # A driver process owns one campaign. Resolve the selected root once so - # all legacy no-argument helper seams and their lock agree with --study-root. - STUDY_ROOT = study_root - run_root = study_root / "runs" / arguments.run_id - report_path = run_root / "report.json" - run_root.mkdir(parents=True, exist_ok=True) - campaign_lock = _acquire_campaign_lock() - report = _load_report(report_path, arguments) - performance._write_report(report_path, report) - _prepare_support_directories() - environment = _study_environment(arguments.python) - os.environ.update(environment) - multiplicities = _multiplicities(arguments) - fill_multiplicities = _fill_multiplicities(arguments) - families = _selected_families(arguments) - modes_by_family = { - family: _selected_modes(arguments, family) for family in families - } - fill_modes_by_family = { - family: _fill_modes(arguments, family) for family in families - } - selected_modes = { - mode.key: mode for modes in fill_modes_by_family.values() for mode in modes - } - - # Summed AmpliCol cells patch the generated-library probe source under - # legacy_structural_probe_lock(); validating here would race with peer cells. - if ( - any(mode.kind == "amplicol" for mode in selected_modes.values()) - and not arguments.compare_helicity_sums - ): - legacy_amplicol.validate_checkout(arguments.amplicol_repository) - amplicol_probe = arguments.amplicol_repository / "amplicol_color_probe" - if not amplicol_probe.is_file(): - if not arguments.build_amplicol: - raise StudyError( - "AmpliCol probe is missing; rerun with --build-amplicol: " - f"{amplicol_probe}" - ) - performance._run_watched( - ( - "make", - "-C", - str(arguments.amplicol_repository), - "-j1", - "PDF_BACKEND=internal", - "amplicol_color_probe", - ), - python=arguments.python, - environment=environment, - timeout_seconds=arguments.generation_timeout, - log_path=run_root / "logs" / "amplicol-probe-build.json", - memory_limit_gib=arguments.memory_limit_gib, - ) - - reference_module = ( - performance._load_reference_module() - if any(mode.kind == "reference" for mode in selected_modes.values()) - else None - ) - for final_multiplicity in fill_multiplicities: - for family in families: - for mode in fill_modes_by_family[family]: - curve = _curve(report, family, mode.key) - candidate_cell_root = ( - run_root - / "candidate" - / mode.key - / family - / f"n{final_multiplicity}" - if mode.kind == "candidate" - else None - ) - reuse_candidate_generation = False - existing = curve.get(str(final_multiplicity)) - if isinstance(existing, dict): - obsolete_protocol_scope = ( - existing.get("failure_category") - == "publication-protocol-scope" - and mode.execution_mode == "on-the-fly" - and final_multiplicity <= arguments.otf_max_multiplicity - ) - if obsolete_protocol_scope: - del curve[str(final_multiplicity)] - performance._write_report(report_path, report) - existing = None - if isinstance(existing, dict): - higher_measurement_exists = any( - isinstance(other, dict) - and other.get("status") == "measured" - and int(other_n) > final_multiplicity - for other_n, other in curve.items() - if str(other_n).isdigit() - ) - retry_lower_resource_frontier = ( - existing.get("status") == "failed" - and existing.get("censors_higher_multiplicities") is True - and higher_measurement_exists - ) - if ( - existing.get("status") == "failed" - and ( - existing.get("censors_higher_multiplicities") is False - or retry_lower_resource_frontier - ) - ): - reuse_candidate_generation = ( - not retry_lower_resource_frontier - and candidate_cell_root is not None - and _candidate_cli_failure_allows_generation_reuse( - existing - ) - and _load_successful_candidate_generation( - candidate_cell_root - ) - is not None - ) - del curve[str(final_multiplicity)] - performance._write_report(report_path, report) - else: - continue - censored_at: int | None = next( - ( - n - for n in multiplicities - if isinstance(curve.get(str(n)), dict) - and curve[str(n)].get("censors_higher_multiplicities") is True - ), - None, - ) - base = _cell_base( - family, - mode, - final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) - if censored_at is not None and final_multiplicity > censored_at: - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - base - | { - "status": "skipped", - "failure_reason": ( - "curve censored after resource limit at " - f"n={censored_at}" - ), - "failed_at_n": censored_at, - "censors_higher_multiplicities": True, - }, - ) - continue - compiled_fft_na = _compiled_fft_not_applicable_cell( - family=family, - mode=mode, - final_multiplicity=final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) - if compiled_fft_na is not None: - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - compiled_fft_na, - ) - continue - otf_scope = otf_protocol_scope_cell( - family=family, - mode=mode, - final_multiplicity=final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - maximum_multiplicity=arguments.otf_max_multiplicity, - ) - if otf_scope is not None: - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - otf_scope, - ) - continue - if family == "gg" and mode.kind != "reference": - dependency_skip = _gg_reference_dependency_skip( - report, final_multiplicity - ) - if dependency_skip is not None: - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - base | dependency_skip, - ) - continue - if family == "gg" and mode.kind == "amplicol": - preflight = _amplicol_gg_dense_index_preflight( - final_multiplicity, arguments.memory_limit_gib - ) - if preflight["feasible"] is False: - lower_bound_gib = int(preflight["lower_bound_bytes"]) / 1024**3 - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - base - | { - "status": "skipped", - "failure_category": "structural-memory-limit", - "failure_reason": ( - "AmpliCol dense symmetric color-index lower bound " - f"is {lower_bound_gib:.3f} GiB, above the " - f"{arguments.memory_limit_gib:g} GiB cap" - ), - "censors_higher_multiplicities": True, - "preflight": preflight, - }, - ) - continue - if mode.kind == "reference": - cell_root = run_root / "reference" / f"N{final_multiplicity + 2}" - candidate_staging_root = None - elif mode.kind == "amplicol": - cell_root = ( - run_root / "amplicol" / family / f"n{final_multiplicity}" - ) - candidate_staging_root = None - else: - assert candidate_cell_root is not None - interrupted_staging_root = _candidate_staging_root( - candidate_cell_root - ) - if not reuse_candidate_generation and arguments.resume: - reuse_candidate_generation = ( - _adopt_interrupted_candidate_generation( - staging_root=interrupted_staging_root, - cell_root=candidate_cell_root, - expected_command=_candidate_generation_command( - python=arguments.python, - family=family, - final_multiplicity=final_multiplicity, - mode=mode, - artifact=interrupted_staging_root / "artifact", - batch_size=arguments.batch_size, - optimization_cores=arguments.optimization_cores, - ), - process=process_key(family, final_multiplicity), - ) - ) - candidate_staging_root = ( - None if reuse_candidate_generation else interrupted_staging_root - ) - cell_root = candidate_staging_root or candidate_cell_root - try: - if not reuse_candidate_generation: - if candidate_cell_root is not None: - _clear_campaign_cell(candidate_cell_root) - assert candidate_staging_root is not None - _clear_campaign_cell(candidate_staging_root) - candidate_staging_root.mkdir(parents=True) - else: - _clear_campaign_cell(cell_root) - if mode.kind == "reference": - assert reference_module is not None - cell = _reference_cell( - arguments=arguments, - reference=reference_module, - run_root=run_root, - environment=environment, - final_multiplicity=final_multiplicity, - ) - else: - events, helicity = _inputs( - report, run_root, family, final_multiplicity - ) - baseline = _baseline(report, family, final_multiplicity) - if mode.kind == "amplicol": - cell = _amplicol_cell( - arguments=arguments, - family=family, - final_multiplicity=final_multiplicity, - events=events, - helicity=helicity, - baseline=baseline if family == "gg" else None, - run_root=run_root, - environment=environment, - ) - else: - cell = _candidate_cell( - arguments=arguments, - family=family, - final_multiplicity=final_multiplicity, - mode=mode, - events=events, - helicity=helicity, - baseline=baseline, - cell_root=cell_root, - environment=environment, - ) - if candidate_staging_root is not None: - assert candidate_cell_root is not None - _promote_candidate_cell( - candidate_staging_root, - candidate_cell_root, - cell, - ) - except ( - StudyError, - performance.AcceptanceError, - legacy_amplicol.LegacyOracleError, - legacy_report.LegacyAdapterError, - legacy_report.ProfilingTimeLimitError, - OSError, - ValueError, - ) as error: - cell = _failure_cell(base, error, cell_root) - if candidate_staging_root is not None: - assert candidate_cell_root is not None - if ( - cell["censors_higher_multiplicities"] is True - or not _candidate_cli_failure_allows_generation_reuse( - cell - ) - ): - _discard_candidate_artifact(candidate_staging_root) - if candidate_staging_root.is_dir(): - _promote_candidate_cell( - candidate_staging_root, - candidate_cell_root, - cell, - ) - if cell["censors_higher_multiplicities"] is False: - report["status"] = "stopped-correctness-failure" - report["failure_count"] = _failure_count(report) + 1 - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - cell, - ) - raise StudyError( - "non-resource failure recorded at " - f"{family}/{mode.key}/n{final_multiplicity}; " - "repair it, then resume to retry that cell" - ) from error - _record( - report, - report_path, - family, - mode.key, - final_multiplicity, - cell, - ) - - failures = _failure_count(report) - inversions = resource_frontier_inversions(report) - if inversions: - report["resource_frontier_inversions"] = [list(item) for item in inversions] - else: - report.pop("resource_frontier_inversions", None) - policy_complete = all( - str(final_multiplicity) in _curve(report, family, mode.key) - for final_multiplicity in multiplicities - for family in families - for mode in modes_by_family[family] - ) - report["status"] = ( - ("complete-with-failures" if failures else "complete") - if policy_complete - else "running" - ) - report.pop("status_reason", None) - report["failure_count"] = failures - performance._write_report(report_path, report) - campaign_lock.close() - return report - - -def dry_run_plan(arguments: argparse.Namespace) -> dict[str, object]: - multiplicities = _multiplicities(arguments) - families = _selected_families(arguments) - modes_by_family = { - family: _selected_modes(arguments, family) for family in families - } - selected_candidate_modes = { - mode.key: mode - for modes in modes_by_family.values() - for mode in modes - if mode.kind == "candidate" and mode.key != "compiled-fft" - } - contractions_by_execution_mode = { - execution_mode: [ - contraction - for contraction in ("direct", "symmetric-group-fft") - if any( - mode.execution_mode == execution_mode - and mode.contraction == contraction - for mode in selected_candidate_modes.values() - ) - ] - for execution_mode in ("recurrence", "on-the-fly", "compiled") - if any( - mode.execution_mode == execution_mode - for mode in selected_candidate_modes.values() - ) - } - candidate_generation_metric = ( - "artifact-generation wall time plus a fresh public `pyamplicol evaluate` " - "process loading the artifact and evaluating the ten shared points, " - "including OTF selected-family warm-up when applicable" - ) - candidate_warm_metric = ( - "public `pyamplicol profile --json` wall_time_per_point from true " - f"{arguments.batch_size}-point calls cycling the ten shared points; two " - f"warm-up calls, at least {PROFILE_SAMPLE_COUNT} independent timed block, and " - f"{arguments.target_seconds:g}s cumulative target runtime" - ) - plan = { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "run_root": str(_study_root(arguments) / "runs" / arguments.run_id), - "fft_enabled": bool(arguments.fft_enabled), - "selected_pyamplicol_color_contractions": contractions_by_execution_mode, - "tools": { - "python": arguments.python, - "cxx": arguments.cxx, - "fc": arguments.fc, - "amplicol_repository": str(arguments.amplicol_repository.resolve()), - "reference_fft_root": str(arguments.reference_fft_root.resolve()), - }, - "process_families": { - family: { - "expression": ( - "g g > g g + (n-2)*g" if family == "gg" else "d d~ > d d~ + (n-2)*g" - ), - "ratio_reference": ("reference-fft" if family == "gg" else "amplicol"), - "modes": [mode.key for mode in modes_by_family[family]], - } - for family in families - }, - "final_state_multiplicities": list(multiplicities), - "total_external_particles": [n + 2 for n in multiplicities], - "measurement": { - "color_accuracy": "full", - "n_definition": "final-state-particle-count", - "generation_helicity_coverage": "all", - "warm_fixed_helicity": True, - "warm_samples": PROFILE_SAMPLE_COUNT, - "calibration_target_seconds": arguments.target_seconds, - "candidate_profile_target_runtime_seconds": arguments.target_seconds, - "candidate_profile_warmup_runs": PROFILE_WARMUP_RUNS, - "candidate_profile_minimum_samples": PROFILE_SAMPLE_COUNT, - "warm_benchmark_batch_size": arguments.batch_size, - "warm_sample_count": PROFILE_SAMPLE_COUNT, - "candidate_optimization_cores": ( - arguments.optimization_cores - if arguments.optimization_cores is not None - else "configured-default" - ), - "generation_timeout_seconds": arguments.generation_timeout, - "runtime_timeout_seconds": arguments.runtime_timeout, - "requested_memory_ceiling_gib": arguments.memory_limit_gib, - "memory_watchdog_gib": arguments.memory_limit_gib, - "memory_policy": ( - "per-cell-strictly-below-publication-ceiling" - if arguments.memory_limit_gib == REQUESTED_MEMORY_LIMIT_GIB - else "per-cell-strictly-below-configured-ceiling" - ), - "cell_admission_limits": { - "generation_seconds": { - "operator": "<", - "limit": arguments.generation_timeout, - }, - "runtime_seconds": { - "operator": "<", - "limit": arguments.runtime_timeout, - }, - "peak_rss_gib": { - "operator": "<", - "limit": arguments.memory_limit_gib, - }, - }, - "schedule_order": "multiplicity-then-family-then-mode", - "alpha_s": arguments.alpha_s, - "resource_failure_censors_higher_n_in_same_curve": True, - "non_resource_failure_policy": "record-and-abort-for-repair", - "amplicol_gg_dense_index_preflight": ( - "skip and censor only AmpliCol gg when " - "2*((total_external-1)!)^2 bytes exceeds the memory watchdog cap" - ), - "compiled_fft_applicability": ( - "not applicable to this helicity-general publication campaign: " - "the current compiled FFT backend is a generation-selected " - "diagnostic lane; compiled-direct remains supported" - ), - "compiled_fft_enabled": False, - "generation_metric": { - "reference-fft": ( - "compiler identity/build, event generation, helicity proxy/" - "selection, selected-event writing, initialization, and first pass" - ), - "amplicol": ( - "process-list wall time plus Fortran CPU-time color-object setup" - ), - "pyamplicol": candidate_generation_metric, - }, - "candidate_rss_metric": ( - "maximum process-tree peak RSS across public generation, fresh " - "CLI evaluate, and fresh CLI profile children" - ), - "candidate_numerical_metric": ( - "ten-point public `pyamplicol evaluate --json` with the study " - "alpha_s runtime parameter; fixed-H passes one stable selector and " - "the summed workload omits the selector" - ), - "candidate_profile_model_parameters": ( - "artifact defaults; the profile CLI has no model-parameter option " - "and timing control flow is value-independent at alpha_s=0.118" - ), - "amplicol_rss_metric": ( - "maximum of process-generation actual peak RSS and Fortran runtime " - "child peak RSS; watchdog process-tree RSS/guard are cap telemetry" - ), - "warm_timing_metric": { - "reference-fft": ( - f"median of {PROFILE_SAMPLE_COUNT} process-CPU sample(s) " - "after calibrating whole " - f"{arguments.batch_size}-call scalar repetition groups; " - "normalized per evaluation " - "(not a vectorized batch API)" - ), - "amplicol": ( - f"median of {PROFILE_SAMPLE_COUNT} independent process-CPU " - "aggregate(s) with one fixed scalar repetition count; every " - "retained aggregate meets the calibration target and is " - "normalized per evaluation" - ), - "pyamplicol": candidate_warm_metric, - }, - }, - } - if arguments.compare_helicity_sums: - measurement = plan["measurement"] - assert isinstance(measurement, dict) - measurement.update( - { - "helicity_workload": "sum", - "warm_fixed_helicity": False, - "warm_helicity_sum": True, - "candidate_timed_helicity_contract": ( - "complete null-selector physical-helicity axis; authenticated " - "structural zeros may be eliminated internally" - ), - "helicity_count_semantics": { - "candidate": ( - "coverage and timed count are the complete physical API " - "axis requested by a null helicity selector" - ), - "reference_fft": ( - "coverage is the complete physical axis; active/timed is " - "the exact analytic-nonzero subset evaluated per sum" - ), - "amplicol": ( - "coverage is the complete physical axis; create-raw " - "evaluates the all-helicity amplitude family in bulk and " - "the probe prunes no-row combinations, but it does not " - "expose that retained count or apply the hel_fac filter" - ), - }, - } - ) - generation_metric = measurement["generation_metric"] - assert isinstance(generation_metric, dict) - generation_metric["reference-fft"] = ( - "compiler identity/build, exhaustive event generation, exact " - "nonzero-helicity sweep initialization, and first complete sum" - ) - generation_metric["amplicol"] = ( - "process-list generation, raw contracted-library generation/build, " - "and immutable generated-library snapshot" - ) - warm_metric = measurement["warm_timing_metric"] - assert isinstance(warm_metric, dict) - warm_metric["reference-fft"] = ( - f"median of {PROFILE_SAMPLE_COUNT} calibrated process-CPU sample(s) " - "of one complete analytic-nonzero helicity sum at the " - "representative point" - ) - warm_metric["amplicol"] = ( - f"adaptive aggregate of at least {PROFILE_SAMPLE_COUNT} independently " - "timed create-raw bulk-family evaluations followed by a complete " - "physical-helicity sum with probe-local no-row pruning, normalized " - "per point" - ) - return plan - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--dry-run", action="store_true") - parser.add_argument("--resume", action="store_true") - parser.add_argument( - "--compare-helicity-sums", - action="store_true", - help=( - "measure the complete physical-helicity sum instead of the fixed " - "selected-helicity workload; this is part of report/cache identity" - ), - ) - parser.add_argument("--run-id", default="fullcolor-n2-n7") - parser.add_argument( - "--study-root", - type=Path, - default=STUDY_ROOT, - help=( - "isolated cache/run root (default: repository FFT scaling raw root); " - "use distinct roots for deliberately parallel campaign shards" - ), - ) - parser.add_argument( - "--min-n", - type=int, - default=min(FINAL_MULTIPLICITIES), - help="first plotted final-state multiplicity (default: 2)", - ) - parser.add_argument( - "--max-n", - type=int, - default=max(FINAL_MULTIPLICITIES), - help="last plotted final-state multiplicity (default: 7)", - ) - parser.add_argument( - "--multiplicity", - dest="multiplicities", - action="append", - type=int, - help=( - "exact final-state multiplicity to run; repeat for a sparse scan " - "(overrides --min-n/--max-n)" - ), - ) - parser.add_argument( - "--fill-multiplicity", - dest="fill_multiplicities", - action="append", - type=int, - help=( - "populate only this multiplicity in the fixed --multiplicity policy; " - "repeat for a bounded resumable fill (not part of report identity)" - ), - ) - parser.add_argument( - "--fill-mode", - dest="fill_modes", - action="append", - choices=tuple(MODE_BY_KEY), - help=( - "populate only this mode in the fixed --mode policy; repeat for a " - "bounded resumable fill (not part of report identity)" - ), - ) - parser.add_argument( - "--family", - dest="families", - action="append", - choices=FAMILIES, - help="process family to run; repeat to select both (default: all)", - ) - parser.add_argument( - "--mode", - dest="modes", - action="append", - choices=tuple(MODE_BY_KEY), - help="curve to run; repeat as needed (default: all applicable curves)", - ) - parser.add_argument( - "--fft", - dest="fft_enabled", - action="store_true", - help=( - "for every selected applicable pyAmpliCol execution mode, retain " - "its direct curve and add its symmetric-group FFT curve" - ), - ) - parser.add_argument( - "--explicit-modes", - action="store_true", - help="honor repeated --mode values exactly without FFT companion expansion", - ) - parser.add_argument( - "--batch-size", - type=int, - default=BENCHMARK_BATCH_SIZE, - help=( - "candidate public CLI profile batch size and Reference scalar " - "repetition quantum (default: 128)" - ), - ) - parser.add_argument( - "--optimization-cores", - type=int, - help=( - "explicit evaluator.optimization.cores for candidate generation; " - "the configured default is retained when omitted" - ), - ) - parser.add_argument("--python", default=sys.executable) - parser.add_argument("--cxx", default=os.environ.get("CXX", "c++")) - parser.add_argument("--fc", default=os.environ.get("FC", "gfortran")) - parser.add_argument("--alpha-s", type=float, default=DEFAULT_ALPHA_S) - parser.add_argument( - "--target-seconds", - type=float, - default=DEFAULT_PROFILE_TARGET_SECONDS, - help=( - "target cumulative runtime for each timed profiling cell after the " - "first calibration/probe evaluation (default: 180)" - ), - ) - parser.add_argument( - "--generation-timeout", type=float, default=DEFAULT_TIME_LIMIT_SECONDS - ) - parser.add_argument( - "--runtime-timeout", type=float, default=DEFAULT_TIME_LIMIT_SECONDS - ) - parser.add_argument("--memory-limit-gib", type=float, default=MAX_MEMORY_LIMIT_GIB) - parser.add_argument( - "--otf-max-multiplicity", - type=int, - default=DEFAULT_OTF_MAX_MULTIPLICITY, - help=( - "largest final-state multiplicity admitted for on-the-fly modes " - f"(default publication frontier: {DEFAULT_OTF_MAX_MULTIPLICITY})" - ), - ) - parser.add_argument( - "--amplicol-repository", - type=Path, - default=legacy_amplicol.DEFAULT_REPOSITORY, - ) - parser.add_argument( - "--reference-fft-root", - type=Path, - default=performance.DEFAULT_REFERENCE_ROOT, - ) - parser.add_argument("--build-amplicol", action="store_true") - return parser - - -def _validate_arguments(arguments: argparse.Namespace) -> None: - if performance._RUN_ID.fullmatch(arguments.run_id) is None or arguments.run_id in { - ".", - "..", - }: - raise StudyError("--run-id is not a safe workspace-local name") - if arguments.alpha_s != DEFAULT_ALPHA_S: - raise StudyError( - "this FullColor study requires --alpha-s 0.118 to match pinned AmpliCol" - ) - if arguments.multiplicities is not None and ( - not arguments.multiplicities or min(arguments.multiplicities) < 2 - ): - raise StudyError("--multiplicity values must be integers >=2") - if arguments.multiplicities is None and ( - arguments.min_n < 2 or arguments.max_n < arguments.min_n - ): - raise StudyError( - "--min-n/--max-n must define a nonempty range starting at n>=2" - ) - if arguments.fill_multiplicities is not None: - if min(arguments.fill_multiplicities, default=1) < 2: - raise StudyError("--fill-multiplicity values must be integers >=2") - outside_policy = sorted( - set(arguments.fill_multiplicities) - set(_multiplicities(arguments)) - ) - if outside_policy: - raise StudyError( - "--fill-multiplicity values must belong to the fixed policy: " - + ", ".join(str(value) for value in outside_policy) - ) - if arguments.batch_size < 1: - raise StudyError("--batch-size must be positive") - if ( - not _positive_finite(arguments.target_seconds) - or arguments.target_seconds < 0.25 - ): - raise StudyError("--target-seconds must be at least 0.25") - if not _positive_finite(arguments.generation_timeout): - raise StudyError("--generation-timeout must be positive and finite") - if not _positive_finite(arguments.runtime_timeout): - raise StudyError("--runtime-timeout must be positive and finite") - if not _positive_finite(arguments.memory_limit_gib): - raise StudyError("--memory-limit-gib must be positive and finite") - if arguments.otf_max_multiplicity < 2: - raise StudyError("--otf-max-multiplicity must be at least 2") - if arguments.optimization_cores is not None and arguments.optimization_cores < 1: - raise StudyError("--optimization-cores must be positive") - families = _selected_families(arguments) - if not families: - raise StudyError("at least one --family is required") - modes_by_family = { - family: _selected_modes(arguments, family) for family in families - } - if any(not modes for modes in modes_by_family.values()): - raise StudyError("the selected --mode values leave a family with no curves") - if arguments.fill_modes is not None: - policy_modes = { - mode.key for modes in modes_by_family.values() for mode in modes - } - outside_policy = sorted(set(arguments.fill_modes) - policy_modes) - if outside_policy: - raise StudyError( - "--fill-mode values must belong to the fixed --mode policy: " - + ", ".join(outside_policy) - ) - if not any(_fill_modes(arguments, family) for family in families): - raise StudyError("--fill-mode leaves no selected curves to populate") - gg_modes = {mode.key for mode in modes_by_family.get("gg", ())} - if gg_modes - {"reference-fft"} and "reference-fft" not in gg_modes: - raise StudyError("gg candidate/AmpliCol curves require --mode reference-fft") - ddbar_modes = {mode.key for mode in modes_by_family.get("ddbar", ())} - if any(MODE_BY_KEY[key].kind == "candidate" for key in ddbar_modes) and ( - "amplicol" not in ddbar_modes - ): - raise StudyError("ddbar candidate curves require --mode amplicol") - selected_modes = { - mode.key: mode for modes in modes_by_family.values() for mode in modes - } - if arguments.batch_size == 1 and any( - mode.execution_mode == "compiled" and mode.key != "compiled-fft" - for mode in selected_modes.values() - ): - raise StudyError("--batch-size 1 is not supported for compiled curves") - - -def _exec_in(argv: Sequence[str]) -> int: - if len(argv) < 2: - raise StudyError("_exec-in requires a directory and command") - directory = Path(argv[0]) - directory.mkdir(parents=True, exist_ok=True) - os.chdir(directory) - command = list(argv[1:]) - os.execvpe(command[0], command, os.environ) - raise AssertionError("os.execvpe returned") - - -def _time_rss(argv: Sequence[str]) -> int: - """Run one child and report its getrusage high-water mark.""" - - if not argv: - raise StudyError("_time-rss requires a command") - completed = subprocess.run(tuple(argv), check=False) - maximum_rss = int(resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss) - maximum_rss_kib = maximum_rss // 1024 if sys.platform == "darwin" else maximum_rss - if maximum_rss_kib < 1: - raise StudyError("_time-rss child did not report a positive RSS") - print(f"{RSS_MARKER} {maximum_rss_kib}", file=sys.stderr) - return completed.returncode - - -def main(argv: Sequence[str] | None = None) -> int: - raw = list(sys.argv[1:] if argv is None else argv) - try: - if raw and raw[0] == "_exec-in": - return _exec_in(raw[1:]) - if raw and raw[0] == "_time-rss": - return _time_rss(raw[1:]) - arguments = _parser().parse_args(raw) - performance.configure_reference_root(arguments.reference_fft_root) - _validate_arguments(arguments) - if arguments.dry_run: - print(json.dumps(dry_run_plan(arguments), indent=2, sort_keys=True)) - return 0 - result = _campaign(arguments) - print( - json.dumps( - {"status": result["status"], "failure_count": result["failure_count"]}, - indent=2, - ) - ) - return 0 - except ( - StudyError, - performance.AcceptanceError, - legacy_report.LegacyAdapterError, - legacy_report.ProfilingTimeLimitError, - OSError, - ValueError, - ) as error: - print(f"FFT scaling study: {error}", file=sys.stderr) - return 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/fft_scaling_study_plots.py b/pyamplicol/tools/developer/fft_scaling_study_plots.py deleted file mode 100644 index 827c1ea9fa..0000000000 --- a/pyamplicol/tools/developer/fft_scaling_study_plots.py +++ /dev/null @@ -1,1701 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Render the FullColor scaling-study report as six publication-style PNGs. - -The input report may be complete or still in progress. Positive measured -values are plotted; failed, not-applicable, and skipped cells are summarized -below each relevant figure. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import re -import sys -import textwrap -from collections.abc import Iterable, Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -try: - import matplotlib - - matplotlib.use("Agg") - import matplotlib.pyplot as plt - from matplotlib.axes import Axes - from matplotlib.lines import Line2D -except ModuleNotFoundError as error: # pragma: no cover - environment dependent - raise SystemExit( - "fft_scaling_study_plots.py requires matplotlib; run it with a Python " - "environment that provides matplotlib" - ) from error - - -@dataclass(frozen=True, slots=True) -class Metric: - key: str - slug: str - title: str - axis_label: str - scale: float = 1.0 - - -@dataclass(frozen=True, slots=True) -class AxisOptions: - main_y_range: tuple[float, float] | None = None - ratio_y_range: tuple[float, float] | None = None - ratio_y_scale: str = "log" - - -@dataclass(frozen=True, slots=True) -class LineFilterOptions: - main_include_lines: tuple[str, ...] | None = None - main_veto_lines: tuple[str, ...] = () - ratio_include_lines: tuple[str, ...] | None = None - ratio_veto_lines: tuple[str, ...] = () - - -METRICS = ( - Metric( - "generation_seconds", - "generation", - "Setup time", - "Time [s]", - ), - Metric( - "warm_seconds_per_point", - "warm-runtime", - "Warmed runtime per point", - "Time per point [s]", - ), - Metric("max_rss_kib", "rss", "Peak RSS", "Peak RSS [MiB]", 1 / 1024), -) -FAMILIES = ("gg", "ddbar") -FAMILY_TITLES = { - "gg": r"$g g \;\to\; g g + (n-2)g$", - "ddbar": r"$d \bar{d} \;\to\; d \bar{d} + (n-2)g$", -} -FAMILY_BASELINES = {"gg": "reference-fft", "ddbar": "amplicol"} -RECOLA_MODE = "recola" -RECOLA_LABEL = "Recola" -RECOLA_FAMILY_MAP = { - "all_gluon": "gg", - "down_quark_qcd": "ddbar", -} -MODE_LABELS = { - "reference-fft": "Reference FFT", - "amplicol": "AmpliCol", - "recurrence-direct": "pyAmpliCol - recurrence", - "recurrence-fft": "pyAmpliCol - recurrence - FFT", - "otf-direct": "pyAmpliCol - OTF", - "otf-fft": "pyAmpliCol - OTF - FFT", - "compiled-direct": "pyAmpliCol - Compiled", - "compiled-fft": "pyAmpliCol - Compiled - FFT", - "madgraph-standalone": "MadGraph standalone (fixed h)", - RECOLA_MODE: RECOLA_LABEL, -} -MODE_STYLES = { - "reference-fft": ("#000000", "o", "-"), - "amplicol": ("#F0E442", "D", "-"), - "recurrence-direct": ("#009E73", "o", "--"), - "recurrence-fft": ("#009E73", "s", "-"), - "otf-direct": ("#0072B2", "^", "--"), - "otf-fft": ("#0072B2", "v", "-"), - "compiled-direct": ("#D55E00", "P", "--"), - "compiled-fft": ("#7A3E9D", "X", "-"), - "madgraph-standalone": ("#CC3311", "*", "-"), - RECOLA_MODE: ("#AA4499", "h", "-"), -} -PLOT_LINE_SELECTOR_MODES = { - "reference-fft": ("reference-fft",), - "amplicol": ("amplicol",), - "pyamplicol-recurrence": ("recurrence-direct", "recurrence-fft"), - "pyamplicol-otf": ("otf-direct", "otf-fft"), - "madgraph": ("madgraph-standalone",), - "recurrence-direct": ("recurrence-direct",), - "recurrence-fft": ("recurrence-fft",), - "otf-direct": ("otf-direct",), - "otf-fft": ("otf-fft",), - "madgraph-standalone": ("madgraph-standalone",), - "recola": (RECOLA_MODE,), - "compiled-direct": ("compiled-direct",), - "compiled-fft": ("compiled-fft",), -} -PLOT_LINE_CHOICES = tuple(PLOT_LINE_SELECTOR_MODES) -LEGEND_MODE_ORDER = { - # Matplotlib fills a multi-column legend down each column. Keep each - # Direct/FFT strategy pair together, with FFT (solid) above Direct - # (dashed), so the encoding can be read at a glance. - "gg": ( - "reference-fft", - "amplicol", - "recurrence-fft", - "recurrence-direct", - "otf-fft", - "otf-direct", - "madgraph-standalone", - RECOLA_MODE, - ), - "ddbar": ( - "amplicol", - "madgraph-standalone", - "recurrence-fft", - "recurrence-direct", - "otf-fft", - "otf-direct", - RECOLA_MODE, - ), -} -STATUS_ORDER = {"failed": 0, "not-applicable": 1, "skipped": 2} -PROVISIONAL_WARM_STATUS = "excluded-provisional-warm-quality" -EXIT_STATUS = re.compile(r"command failed with status\s+(-?\d+)") -PLOT_MANIFEST_NAME = "plot-manifest.json" -PLOT_DATA_NAME = "plot-data.json" -PLOT_FILENAMES = tuple( - f"fullcolor-{family}-{metric.slug}.png" - for family in FAMILIES - for metric in METRICS -) -DEFAULT_AXIS_OPTIONS = AxisOptions() -DEFAULT_LINE_FILTER_OPTIONS = LineFilterOptions() - - -class PlotError(RuntimeError): - """The report cannot be rendered without guessing its meaning.""" - - -def _finite_float(raw: str) -> float: - value = float(raw) - if not math.isfinite(value): - raise argparse.ArgumentTypeError("must be finite") - return value - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("report", type=Path, help="scaling-study report.json") - parser.add_argument("output_directory", type=Path, help="directory for six PNGs") - parser.add_argument( - "--dpi", - type=int, - default=160, - help="PNG resolution in dots per inch (default: 160)", - ) - parser.add_argument( - "--recola-results", - type=Path, - help="overlay a Recola profiling JSON as an external Recola series", - ) - parser.add_argument( - "--main-y-range", - type=_finite_float, - nargs=2, - metavar=("MIN", "MAX"), - help="force the main-panel log y-range for every plot", - ) - parser.add_argument( - "--ratio-y-range", - type=_finite_float, - nargs=2, - metavar=("MIN", "MAX"), - help="force the ratio-panel y-range for every plot", - ) - parser.add_argument( - "--ratio-y-scale", - choices=("log", "linear"), - default="log", - help="ratio-panel y-axis scale (default: log)", - ) - parser.add_argument( - "--main-include-lines", - nargs="+", - choices=PLOT_LINE_CHOICES, - metavar="LINE", - help="main-panel line ids to include; overrides --main-veto-lines", - ) - parser.add_argument( - "--main-veto-lines", - nargs="+", - choices=PLOT_LINE_CHOICES, - metavar="LINE", - help="main-panel line ids to hide when --main-include-lines is absent", - ) - parser.add_argument( - "--ratio-include-lines", - nargs="+", - choices=PLOT_LINE_CHOICES, - metavar="LINE", - help="ratio-panel line ids to include; overrides --ratio-veto-lines", - ) - parser.add_argument( - "--ratio-veto-lines", - nargs="+", - choices=PLOT_LINE_CHOICES, - metavar="LINE", - help="ratio-panel line ids to hide when --ratio-include-lines is absent", - ) - return parser - - -def _validate_y_range( - values: Sequence[float] | None, - *, - option: str, - positive: bool, -) -> tuple[float, float] | None: - if values is None: - return None - if len(values) != 2: - raise PlotError(f"{option} requires exactly two values") - low, high = (float(values[0]), float(values[1])) - if not math.isfinite(low) or not math.isfinite(high): - raise PlotError(f"{option} values must be finite") - if high <= low: - raise PlotError(f"{option} requires MIN < MAX") - if positive and low <= 0.0: - raise PlotError(f"{option} must be positive for a logarithmic y-axis") - return low, high - - -def _axis_options_from_arguments(arguments: argparse.Namespace) -> AxisOptions: - ratio_y_scale = str(arguments.ratio_y_scale) - if ratio_y_scale not in {"log", "linear"}: - raise PlotError("--ratio-y-scale must be 'log' or 'linear'") - return AxisOptions( - main_y_range=_validate_y_range( - arguments.main_y_range, - option="--main-y-range", - positive=True, - ), - ratio_y_range=_validate_y_range( - arguments.ratio_y_range, - option="--ratio-y-range", - positive=ratio_y_scale == "log", - ), - ratio_y_scale=ratio_y_scale, - ) - - -def _validated_line_names( - values: Sequence[str] | None, - *, - option: str, - default: tuple[str, ...] | None, -) -> tuple[str, ...] | None: - if values is None: - return default - selected = tuple(str(value) for value in values) - if len(set(selected)) != len(selected): - raise PlotError(f"{option} must not contain duplicates") - invalid = sorted(set(selected) - set(PLOT_LINE_CHOICES)) - if invalid: - raise PlotError(f"{option} has unknown line id(s): {', '.join(invalid)}") - return selected - - -def _line_filter_options_from_arguments( - arguments: argparse.Namespace, -) -> LineFilterOptions: - return LineFilterOptions( - main_include_lines=_validated_line_names( - arguments.main_include_lines, - option="--main-include-lines", - default=None, - ), - main_veto_lines=_validated_line_names( - arguments.main_veto_lines, - option="--main-veto-lines", - default=(), - ) - or (), - ratio_include_lines=_validated_line_names( - arguments.ratio_include_lines, - option="--ratio-include-lines", - default=None, - ), - ratio_veto_lines=_validated_line_names( - arguments.ratio_veto_lines, - option="--ratio-veto-lines", - default=(), - ) - or (), - ) - - -def _load_report_snapshot(path: Path) -> tuple[dict[str, Any], str]: - try: - raw = path.read_bytes() - payload = json.loads(raw) - except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise PlotError(f"cannot read {path}: {error}") from error - if not isinstance(payload, dict) or not isinstance(payload.get("cells"), dict): - raise PlotError("report must be a JSON object containing a cells object") - return payload, hashlib.sha256(raw).hexdigest() - - -def _load_report(path: Path) -> dict[str, Any]: - return _load_report_snapshot(path)[0] - - -def _mapping(value: object) -> Mapping[str, Any]: - return value if isinstance(value, Mapping) else {} - - -def _mode_order(report: Mapping[str, Any], family: str) -> tuple[str, ...]: - policy = _mapping(report.get("policy")) - family_policy = _mapping(_mapping(policy.get("process_families")).get(family)) - requested = family_policy.get("modes") - if isinstance(requested, Sequence) and not isinstance(requested, str): - modes = tuple(str(mode) for mode in requested) - if modes: - return modes - family_cells = _mapping(_mapping(report.get("cells")).get(family)) - return tuple(family_cells) - - -def _multiplicities(report: Mapping[str, Any]) -> tuple[int, ...]: - policy = _mapping(report.get("policy")) - requested = policy.get("final_state_multiplicities") - if isinstance(requested, Sequence) and not isinstance(requested, str): - values = tuple(sorted({int(value) for value in requested})) - if values: - return values - observed: set[int] = set() - for family in FAMILIES: - for cells in _mapping(_mapping(report.get("cells")).get(family)).values(): - observed.update(int(value) for value in _mapping(cells)) - if not observed: - raise PlotError("report has no requested or observed multiplicities") - return tuple(sorted(observed)) - - -def _source_boundary( - report: Mapping[str, Any], metric_key: str | None = None -) -> tuple[float, str] | None: - policy = _mapping(report.get("policy")) - plot = _mapping(policy.get("plot")) - metric_boundaries = _mapping(plot.get("metric_source_boundaries")) - if metric_key is not None and metric_key in metric_boundaries: - metric_boundary = metric_boundaries[metric_key] - if metric_boundary is None: - return None - boundary_policy = _mapping(metric_boundary) - else: - boundary_policy = plot - raw_boundary = boundary_policy.get("source_boundary_after_n") - if raw_boundary is None: - return None - if isinstance(raw_boundary, bool) or not isinstance(raw_boundary, int): - raise PlotError("policy.plot.source_boundary_after_n must be an integer") - multiplicities = _multiplicities(report) - if raw_boundary not in multiplicities or raw_boundary + 1 not in multiplicities: - raise PlotError( - "policy.plot.source_boundary_after_n must separate two plotted " - "multiplicities" - ) - raw_label = boundary_policy.get("source_boundary_label") - label = ( - raw_label - if isinstance(raw_label, str) and raw_label.strip() - else f"source boundary after n={raw_boundary}" - ) - return raw_boundary + 0.5, label - - -def _protocol_summary( - report: Mapping[str, Any], *, ratio_y_scale: str = "log" -) -> str: - policy = _mapping(report.get("policy")) - measurement = _mapping(policy.get("measurement")) - if policy.get("fft_enabled") is not True: - return f"main Y log; ratio Y {ratio_y_scale}" - details = ["Campaign --fft enabled"] - if measurement.get("generation_helicity_coverage") == "all": - details.append("artifacts: all runtime helicities") - workload = _helicity_workload(report) - if workload == "fixed": - details.append("setup/warm workload: one fixed helicity") - elif workload == "sum": - details.append("setup/warm workload: complete helicity sum") - details.append("AmpliCol: create-raw bulk H family") - batch_size = measurement.get("warm_benchmark_batch_size") - if ( - not isinstance(batch_size, int) - or isinstance(batch_size, bool) - or batch_size < 1 - ): - raise PlotError("measurement warm_benchmark_batch_size must be positive") - details.append(f"pyAmpliCol CLI profile: batch {batch_size} (cyclic 10 points)") - details.append("Reference/AmpliCol: scalar aggregates normalized per point") - if measurement.get("compiled_fft_enabled") is False: - details.append("compiled FFT disabled") - details.append(f"main Y log; ratio Y {ratio_y_scale}") - return " | ".join(details) - - -def _protocol_summary_lines( - report: Mapping[str, Any], - *, - max_line_length: int = 110, - ratio_y_scale: str = "log", -) -> tuple[str, ...]: - """Wrap the protocol at semantic separators for a stable plot header.""" - - if max_line_length < 1: - raise ValueError("max_line_length must be positive") - sections = _protocol_summary(report, ratio_y_scale=ratio_y_scale).split(" | ") - lines: list[str] = [] - current = "" - for section in sections: - candidate = section if not current else f"{current} | {section}" - if current and len(candidate) > max_line_length: - lines.append(current) - current = section - else: - current = candidate - if current: - lines.append(current) - return tuple(lines) - - -def _helicity_workload(report: Mapping[str, Any]) -> str: - """Return the explicitly measured warm-helicity workload. - - Older selected-scalar reports predate ``helicity_workload`` and are - identified by their existing ``warm_fixed_helicity`` contract. - """ - - policy = _mapping(report.get("policy")) - measurement = _mapping(policy.get("measurement")) - measurement_declared = measurement.get("helicity_workload") - policy_declared = policy.get("helicity_workload") - if ( - measurement_declared is not None - and policy_declared is not None - and str(measurement_declared) != str(policy_declared) - ): - raise PlotError( - "policy and measurement helicity_workload declarations disagree" - ) - declared = ( - measurement_declared - if measurement_declared is not None - else policy_declared - ) - if declared is not None: - value = str(declared) - if value not in {"fixed", "sum"}: - raise PlotError("policy helicity_workload must be 'fixed' or 'sum'") - if value == "sum" and ( - measurement.get("warm_fixed_helicity") is not False - or measurement.get("warm_helicity_sum") is not True - ): - raise PlotError( - "summed policy must record warm_fixed_helicity=false and " - "warm_helicity_sum=true" - ) - if value == "fixed" and ( - measurement.get("warm_fixed_helicity") is not True - or measurement.get("warm_helicity_sum") is True - ): - raise PlotError( - "fixed policy must record warm_fixed_helicity=true without " - "warm_helicity_sum=true" - ) - return value - if ( - measurement.get("warm_helicity_sum") is True - and measurement.get("warm_fixed_helicity") is True - ): - raise PlotError("campaign helicity workload markers are contradictory") - if measurement.get("warm_helicity_sum") is True: - return "sum" - if measurement.get("warm_fixed_helicity") is True: - return "fixed" - return "fixed" - - -def _metric_title(report: Mapping[str, Any], metric: Metric) -> str: - if metric.key == "warm_seconds_per_point" and _helicity_workload(report) == "sum": - return "Warmed helicity-summed runtime per point" - return metric.title - - -def _metric_axis_label(report: Mapping[str, Any], metric: Metric) -> str: - if metric.key == "warm_seconds_per_point" and _helicity_workload(report) == "sum": - return "Time per helicity-summed point [s]" - return metric.axis_label - - -def _label(family_cells: Mapping[str, Any], mode: str) -> str: - for cell in _mapping(family_cells.get(mode)).values(): - label = _mapping(cell).get("label") - if isinstance(label, str) and label: - return label - return MODE_LABELS.get(mode, mode) - - -def _positive_number(value: object) -> float | None: - if isinstance(value, bool) or not isinstance(value, int | float): - return None - result = float(value) - if not math.isfinite(result) or result <= 0.0: - return None - return result - - -def _load_recola_results(path: Path) -> tuple[Mapping[str, Any], str]: - try: - raw = path.read_bytes() - payload = json.loads(raw) - except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise PlotError(f"cannot read Recola results {path}: {error}") from error - if not isinstance(payload, Mapping): - raise PlotError("Recola results must be a JSON object") - return payload, hashlib.sha256(raw).hexdigest() - - -def _recola_cell_workload( - cell: Mapping[str, Any], - config: Mapping[str, Any], - *, - context: str, -) -> str: - polarized = cell.get("polarized") - if not isinstance(polarized, bool): - polarized = config.get("polarized") - if not isinstance(polarized, bool): - raise PlotError(f"{context} lacks a boolean Recola polarized marker") - return "fixed" if polarized else "sum" - - -def _recola_metrics(cell: Mapping[str, Any]) -> dict[str, float]: - metrics: dict[str, float] = {} - generation_seconds = _positive_number(cell.get("gen_time_s")) - if generation_seconds is not None: - metrics["generation_seconds"] = generation_seconds - warm_seconds = _positive_number(cell.get("run_time_s")) - if warm_seconds is not None: - metrics["warm_seconds_per_point"] = warm_seconds - rss_values = [ - value - for field in ( - "peak_generation_rss_mib", - "ram_after_generation_mib", - "ram_after_profile_mib", - ) - if (value := _positive_number(cell.get(field))) is not None - ] - if rss_values: - metrics["max_rss_kib"] = max(rss_values) * 1024.0 - return metrics - - -def _recola_failure_category(reason: str) -> str: - if "RSS" in reason or "MAX_RSS" in reason: - return "memory-limit" - if "generation time" in reason or "MAX_GEN_T" in reason: - return "generation-time-limit" - return "generation-timeout" - - -def _recola_source_metadata( - path: Path, - digest: str, - cells_by_family: Mapping[str, Sequence[int]], -) -> dict[str, Any]: - return { - "kind": "recola-profile-results", - "path": str(path.expanduser().resolve(strict=False)), - "sha256": digest, - "mode": RECOLA_MODE, - "label": RECOLA_LABEL, - "family_map": dict(RECOLA_FAMILY_MAP), - "metrics": { - "generation_seconds": "gen_time_s", - "warm_seconds_per_point": "run_time_s", - "max_rss_kib": ( - "max(peak_generation_rss_mib, ram_after_generation_mib, " - "ram_after_profile_mib) * 1024" - ), - }, - "multiplicities": { - family: list(multiplicities) - for family, multiplicities in cells_by_family.items() - }, - } - - -def _attach_recola_results(report: dict[str, Any], path: Path) -> dict[str, Any]: - payload, digest = _load_recola_results(path) - results = payload.get("results") - if not isinstance(results, Mapping): - raise PlotError("Recola results must contain a results object") - config = _mapping(payload.get("config")) - expected_workload = _helicity_workload(report) - config_polarized = config.get("polarized") - if isinstance(config_polarized, bool): - config_workload = "fixed" if config_polarized else "sum" - if config_workload != expected_workload: - raise PlotError( - f"Recola results are {config_workload} workload but the campaign " - f"report is {expected_workload}" - ) - series: dict[str, dict[str, dict[str, Any]]] = {} - multiplicities_by_family: dict[str, list[int]] = {family: [] for family in FAMILIES} - measured_count = 0 - - for raw_family, raw_family_results in results.items(): - if not isinstance(raw_family_results, Mapping): - raise PlotError(f"Recola results family {raw_family!r} must be an object") - for raw_n, raw_cell in raw_family_results.items(): - if raw_cell is None: - continue - if not isinstance(raw_cell, Mapping): - raise PlotError(f"Recola {raw_family}/n={raw_n} must be an object") - try: - multiplicity = int(raw_n) - except (TypeError, ValueError) as error: - raise PlotError( - f"Recola multiplicity {raw_family}/n={raw_n!r} is not an integer" - ) from error - source_family = str(raw_cell.get("family") or raw_family) - target_family = RECOLA_FAMILY_MAP.get(source_family) - if target_family is None: - continue - context = f"Recola {source_family}/n={multiplicity}" - status = raw_cell.get("status") - if status == "limit_reached": - reason = raw_cell.get("error") - reason_text = ( - reason - if isinstance(reason, str) and reason.strip() - else "Recola generation limit reached" - ) - cell_payload = { - "status": "failed", - "label": RECOLA_LABEL, - "failure_category": _recola_failure_category(reason_text), - "failure_reason": reason_text, - } - else: - metrics = _recola_metrics(raw_cell) - if not metrics: - continue - observed_workload = _recola_cell_workload( - raw_cell, - config, - context=context, - ) - if observed_workload != expected_workload: - raise PlotError( - f"{context} is {observed_workload} workload but the " - f"campaign report is {expected_workload}" - ) - cell_payload = { - "status": "measured", - "label": RECOLA_LABEL, - "metrics": metrics, - "helicity_workload": observed_workload, - "warm_fixed_helicity": observed_workload == "fixed", - "warm_helicity_sum": observed_workload == "sum", - "process": raw_cell.get("process"), - "helicity": raw_cell.get("helicity"), - "profiled_call": raw_cell.get("profiled_call"), - } - measured_count += 1 - series.setdefault(target_family, {})[str(multiplicity)] = cell_payload - multiplicities_by_family[target_family].append(multiplicity) - - if measured_count == 0: - raise PlotError("Recola results contain no measured cells") - - runtime_series = report.setdefault("runtime_series", {}) - if not isinstance(runtime_series, dict): - raise PlotError("report runtime_series must be an object when present") - for family, cells in series.items(): - family_runtime = runtime_series.setdefault(family, {}) - if not isinstance(family_runtime, dict): - raise PlotError(f"report runtime_series.{family} must be an object") - family_cells = _mapping(_mapping(report.get("cells")).get(family)) - if RECOLA_MODE in family_runtime or RECOLA_MODE in family_cells: - raise PlotError(f"external series duplicates {family}/{RECOLA_MODE}") - family_runtime[RECOLA_MODE] = { - raw_n: cells[raw_n] for raw_n in sorted(cells, key=int) - } - - return _recola_source_metadata( - path, - digest, - { - family: sorted(set(multiplicities)) - for family, multiplicities in multiplicities_by_family.items() - if multiplicities - }, - ) - - -def _series( - family_cells: Mapping[str, Any], mode: str, metric: Metric -) -> list[tuple[int, float]]: - values: list[tuple[int, float]] = [] - for raw_n, raw_cell in _mapping(family_cells.get(mode)).items(): - multiplicity = int(raw_n) - cell = _mapping(raw_cell) - if cell.get("status") != "measured": - continue - exclusion = _mapping(_mapping(cell.get("excluded_metrics")).get(metric.key)) - exclusion_status = exclusion.get("status") - if isinstance(exclusion_status, str) and exclusion_status.startswith( - "excluded-" - ): - # Compatibility with already-written rolling snapshots: the - # superseded 3% advisory gate moved otherwise valid measurements - # under excluded_metrics. Plot those values exactly like any - # other measured warm point so curves and ratios stay continuous. - if ( - metric.key == "warm_seconds_per_point" - and exclusion_status == PROVISIONAL_WARM_STATUS - ): - value = _positive_number(exclusion.get("value")) - else: - continue - else: - value = _positive_number(_mapping(cell.get("metrics")).get(metric.key)) - if value is not None: - values.append((multiplicity, value * metric.scale)) - return sorted(values) - - -def _family_cells_for_metric( - report: Mapping[str, Any], family: str, metric: Metric -) -> tuple[dict[str, Any], tuple[str, ...]]: - family_cells = dict(_mapping(_mapping(report.get("cells")).get(family))) - modes = _mode_order(report, family) - runtime_series = _mapping(_mapping(report.get("runtime_series")).get(family)) - for mode, raw_cells in runtime_series.items(): - mode = str(mode) - if mode in family_cells or mode in modes: - raise PlotError(f"external series duplicates {family}/{mode}") - cells = _mapping(raw_cells) - family_cells[mode] = { - str(raw_n): dict(_mapping(raw_cell)) for raw_n, raw_cell in cells.items() - } - modes = (*modes, mode) - _validate_cell_workloads(report, family, family_cells) - excluded_modes = _metric_series_exclusions(report, family, metric) - if excluded_modes: - modes = tuple(mode for mode in modes if mode not in excluded_modes) - for mode in excluded_modes: - family_cells.pop(mode, None) - return family_cells, modes - - -def _declared_cell_workload(cell: Mapping[str, Any]) -> str | None: - markers: set[str] = set() - declared = cell.get("helicity_workload") - if declared is not None: - workload = str(declared) - if workload not in {"fixed", "sum"}: - raise PlotError("measured cell helicity_workload must be 'fixed' or 'sum'") - markers.add(workload) - if cell.get("warm_helicity_sum") is True: - markers.add("sum") - if cell.get("warm_fixed_helicity") is True: - markers.add("fixed") - protocol = _mapping(cell.get("protocol")) - helicity_summed = protocol.get("helicity_summed") - if helicity_summed is True: - markers.add("sum") - if helicity_summed is False or protocol.get("warm_fixed_helicity") is True: - markers.add("fixed") - if len(markers) > 1: - raise PlotError("measured cell helicity workload markers are contradictory") - return next(iter(markers), None) - - -def _validate_cell_workloads( - report: Mapping[str, Any], - family: str, - family_cells: Mapping[str, Any], -) -> None: - expected = _helicity_workload(report) - for mode, raw_cells in family_cells.items(): - for raw_n, raw_cell in _mapping(raw_cells).items(): - cell = _mapping(raw_cell) - if cell.get("status") != "measured": - continue - observed = _declared_cell_workload(cell) - context = f"{family}/{mode}/n={raw_n}" - if expected == "sum" and observed != "sum": - raise PlotError( - f"{context} is not authenticated as a helicity-summed cell" - ) - if expected == "fixed" and observed == "sum": - raise PlotError( - f"{context} is summed data in a fixed-helicity campaign" - ) - - -def _metric_series_exclusions( - report: Mapping[str, Any], family: str, metric: Metric -) -> Mapping[str, Any]: - plot = _mapping(_mapping(report.get("policy")).get("plot")) - metric_exclusions = _mapping(plot.get("metric_series_exclusions")) - family_exclusions = _mapping( - _mapping(metric_exclusions.get(metric.key)).get(family) - ) - return {str(mode): reason for mode, reason in family_exclusions.items()} - - -def _plot_policy_notes( - report: Mapping[str, Any], - family: str, - metric: Metric, - original_family_cells: Mapping[str, Any], - *, - visible_modes: Sequence[str] | None = None, -) -> list[str]: - visible_mode_set = set(visible_modes) if visible_modes is not None else None - plot = _mapping(_mapping(report.get("policy")).get("plot")) - notes: list[str] = [] - raw_notes = plot.get("notes") - if isinstance(raw_notes, Sequence) and not isinstance(raw_notes, str): - notes.extend( - note.strip() - for raw_note in raw_notes - if isinstance(raw_note, str) and (note := raw_note.strip()) - ) - - grouped: dict[str, list[str]] = {} - for mode, raw_reason in _metric_series_exclusions(report, family, metric).items(): - if visible_mode_set is not None and mode not in visible_mode_set: - continue - reason = ( - raw_reason.strip() - if isinstance(raw_reason, str) and raw_reason.strip() - else "excluded by the report's metric protocol policy" - ) - grouped.setdefault(reason, []).append(_label(original_family_cells, mode)) - for reason, labels in grouped.items(): - notes.append(f"{', '.join(labels)}: {metric.title.lower()} omitted ({reason}).") - return notes - - -def _consecutive_runs( - values: Sequence[tuple[int, float]], -) -> Iterable[list[tuple[int, float]]]: - run: list[tuple[int, float]] = [] - for point in values: - if run and point[0] != run[-1][0] + 1: - yield run - run = [] - run.append(point) - if run: - yield run - - -def _line_selector_modes(lines: Sequence[str]) -> set[str]: - modes: set[str] = set() - for line in lines: - modes.update(PLOT_LINE_SELECTOR_MODES[line]) - return modes - - -def _filtered_modes( - modes: Sequence[str], - *, - include_lines: Sequence[str] | None, - veto_lines: Sequence[str], -) -> tuple[str, ...]: - if include_lines is not None: - selected = _line_selector_modes(include_lines) - return tuple(mode for mode in modes if mode in selected) - vetoed = _line_selector_modes(veto_lines) - return tuple(mode for mode in modes if mode not in vetoed) - - -def _visible_modes( - modes: Sequence[str], - *, - line_filters: LineFilterOptions, -) -> tuple[tuple[str, ...], tuple[str, ...], tuple[str, ...]]: - main_modes = _filtered_modes( - modes, - include_lines=line_filters.main_include_lines, - veto_lines=line_filters.main_veto_lines, - ) - ratio_modes = _filtered_modes( - modes, - include_lines=line_filters.ratio_include_lines, - veto_lines=line_filters.ratio_veto_lines, - ) - visible = tuple( - mode for mode in modes if mode in set(main_modes) or mode in set(ratio_modes) - ) - return main_modes, ratio_modes, visible - - -def _line_filter_payload(line_filters: LineFilterOptions) -> dict[str, Any]: - return { - "main": { - "include_lines": ( - None - if line_filters.main_include_lines is None - else list(line_filters.main_include_lines) - ), - "veto_lines": list(line_filters.main_veto_lines), - }, - "ratio": { - "include_lines": ( - None - if line_filters.ratio_include_lines is None - else list(line_filters.ratio_include_lines) - ), - "veto_lines": list(line_filters.ratio_veto_lines), - }, - "precedence": "include-lines override veto-lines per panel", - } - - -def _log_limits(values: Sequence[float]) -> tuple[float, float]: - low = min(values) - high = max(values) - if low == high: - return low / 2.0, high * 2.0 - span = math.log10(high) - math.log10(low) - padding = max(0.10, span * 0.06) - return 10 ** (math.log10(low) - padding), 10 ** (math.log10(high) + padding) - - -def _linear_limits(values: Sequence[float]) -> tuple[float, float]: - low = min(values) - high = max(values) - if low == high: - padding = max(abs(low) * 0.5, 0.5) - else: - padding = max((high - low) * 0.08, 0.05) - return low - padding, high + padding - - -def _main_y_limits( - values: Sequence[float], axis_options: AxisOptions -) -> tuple[float, float]: - if axis_options.main_y_range is not None: - return axis_options.main_y_range - if values: - return _log_limits(values) - return 0.5, 2.0 - - -def _ratio_y_limits( - values: Sequence[float], axis_options: AxisOptions -) -> tuple[float, float]: - if axis_options.ratio_y_range is not None: - return axis_options.ratio_y_range - scale_values = [*values, 1.0] - if axis_options.ratio_y_scale == "linear": - return _linear_limits(scale_values) - return _log_limits(scale_values) - - -def _axis_payload( - *, - scale: str, - limits: tuple[float, float], -) -> dict[str, Any]: - return {"scale": scale, "range": [limits[0], limits[1]]} - - -def _format_n(values: Sequence[int]) -> str: - ordered = sorted(set(values)) - ranges: list[str] = [] - start = previous = ordered[0] - for value in ordered[1:]: - if value == previous + 1: - previous = value - continue - ranges.append(str(start) if start == previous else f"{start}-{previous}") - start = previous = value - ranges.append(str(start) if start == previous else f"{start}-{previous}") - return ", ".join(ranges) - - -def _timeout_label(report: Mapping[str, Any], policy_key: str) -> str: - policy = _mapping(report.get("policy")) - measurement = _mapping(policy.get("measurement")) - seconds = _positive_number(measurement.get(policy_key)) - return "configured" if seconds is None else f"{seconds / 60:g} min" - - -def _failure_detail(report: Mapping[str, Any], cell: Mapping[str, Any]) -> str: - short = cell.get("failure_reason_short") - if isinstance(short, str) and short.strip(): - return short.strip() - category = cell.get("failure_category") - reason = cell.get("failure_reason") - reason_text = reason if isinstance(reason, str) else "" - if category == "memory-limit": - return "memory watchdog limit" - if category == "legacy-amplicol-structural-limit": - return "legacy AmpliCol structural limit" - if category in {"runtime-time-limit", "runtime-timeout"}: - return f"{_timeout_label(report, 'runtime_timeout_seconds')} runtime limit" - if category == "setup-or-runtime-time-limit": - return ( - f"{_timeout_label(report, 'generation_timeout_seconds')} " - "setup/runtime limit" - ) - if category in {"generation-time-limit", "generation-timeout", "timeout"}: - return ( - f"{_timeout_label(report, 'generation_timeout_seconds')} " - "setup-time limit" - ) - match = EXIT_STATUS.search(reason_text) - if match: - return f"generation error (exit {match.group(1)})" - if reason_text and len(reason_text) <= 90: - return reason_text.rstrip(".") - return str(category or "generation error") - - -def _status_notes( - report: Mapping[str, Any], - family: str, - modes: Sequence[str], - *, - family_cells: Mapping[str, Any] | None = None, -) -> list[str]: - if family_cells is None: - family_cells = _mapping(_mapping(report.get("cells")).get(family)) - notes: list[str] = [] - for mode in modes: - grouped: dict[tuple[str, str], list[int]] = {} - for raw_n, raw_cell in _mapping(family_cells.get(mode)).items(): - multiplicity = int(raw_n) - cell = _mapping(raw_cell) - status = cell.get("status") - if status not in STATUS_ORDER: - continue - if status == "failed": - detail = _failure_detail(report, cell) - else: - reason = cell.get("failure_reason") - detail = reason.rstrip(".") if isinstance(reason, str) else status - grouped.setdefault((str(status), detail), []).append(multiplicity) - if not grouped: - continue - fragments = [] - for (status, detail), values in sorted( - grouped.items(), key=lambda item: (STATUS_ORDER[item[0][0]], item[1]) - ): - display_status = "N/A" if status == "not-applicable" else status - fragments.append(f"n={_format_n(values)} {display_status} ({detail})") - notes.append(f"{_label(family_cells, mode)}: " + "; ".join(fragments) + ".") - report_status = report.get("status") - if not isinstance(report_status, str) or not report_status.startswith("complete"): - status_reason = report.get("status_reason") - if report_status == "stopped-protocol-investigation": - reason = ( - status_reason.strip() - if isinstance(status_reason, str) and status_reason.strip() - else "measurement protocol under investigation" - ) - notes.append( - f"Campaign stopped: {reason}. Absent cells are unattempted and omitted." - ) - else: - notes.append( - "Campaign is still running; absent cells are unattempted and omitted." - ) - return notes - - -def _wrapped_notes(notes: Sequence[str], width: int = 138) -> list[str]: - lines: list[str] = [] - for note in notes: - wrapped = textwrap.wrap( - note, - width=width, - break_long_words=False, - break_on_hyphens=False, - subsequent_indent=" ", - ) - if wrapped: - lines.extend(("• " + wrapped[0], *wrapped[1:])) - return lines - - -def _style_axes(axis: Axes) -> None: - axis.grid(True, which="major", color="#D7DCE2", linewidth=0.7, alpha=0.85) - axis.grid(True, which="minor", axis="y", color="#E9ECF0", linewidth=0.5, alpha=0.7) - for spine in axis.spines.values(): - spine.set_color("#75808C") - spine.set_linewidth(0.8) - axis.tick_params(colors="#20262D", labelsize=9) - - -def _draw_run( - axis: Axes, - run: Sequence[tuple[int, float]], - *, - color: str, - marker: str, - linestyle: str, -) -> None: - x_values = [point[0] for point in run] - y_values = [point[1] for point in run] - axis.plot( - x_values, - y_values, - color=color, - marker=marker, - linestyle=linestyle, - linewidth=1.7, - markersize=5.3, - markeredgewidth=0.8, - markeredgecolor="white" if marker not in {"+", "x"} else color, - zorder=3, - ) - - -def _plot_metric( - report: Mapping[str, Any], - family: str, - metric: Metric, - output_path: Path, - *, - dpi: int, - axis_options: AxisOptions = DEFAULT_AXIS_OPTIONS, - line_filters: LineFilterOptions = DEFAULT_LINE_FILTER_OPTIONS, -) -> None: - original_family_cells = _mapping(_mapping(report.get("cells")).get(family)) - family_cells, modes = _family_cells_for_metric(report, family, metric) - main_modes, ratio_modes, visible_modes = _visible_modes( - modes, - line_filters=line_filters, - ) - multiplicities = _multiplicities(report) - baseline = FAMILY_BASELINES[family] - report_status = report.get("status") - allow_empty = not ( - isinstance(report_status, str) and report_status.startswith("complete") - ) - if baseline not in modes and not allow_empty: - raise PlotError( - f"{family} mode list does not contain ratio baseline {baseline!r}" - ) - - series = {mode: _series(family_cells, mode, metric) for mode in modes} - all_main_values = [value for values in series.values() for _, value in values] - main_values = [ - value for mode in main_modes for _, value in series.get(mode, ()) - ] - if not all_main_values and not allow_empty: - raise PlotError(f"no measured positive {metric.key} values for {family}") - baseline_values = dict(series.get(baseline, ())) - ratios: dict[str, list[tuple[int, float]]] = {} - for mode, values in series.items(): - ratios[mode] = [ - (n, value / baseline_values[n]) - for n, value in values - if n in baseline_values and baseline_values[n] > 0.0 - ] - all_ratio_values = [value for values in ratios.values() for _, value in values] - ratio_values = [ - value for mode in ratio_modes for _, value in ratios.get(mode, ()) - ] - if not all_ratio_values and not allow_empty: - raise PlotError(f"no ratios can be formed for {family} {metric.key}") - - notes = _wrapped_notes( - [ - *_status_notes(report, family, visible_modes, family_cells=family_cells), - *_plot_policy_notes( - report, - family, - metric, - original_family_cells, - visible_modes=visible_modes, - ), - ] - ) - # Reserve enough space below the ratio axes for its tick labels and x-axis - # title before the failure-note block begins. Keeping these as separate - # vertical bands avoids collisions in partial campaigns with several notes. - notes_height = 1.15 + 0.20 * max(1, len(notes)) - figure_height = 8.07 + 0.20 * max(0, len(notes) - 1) - bottom = notes_height / figure_height - figure = plt.figure(figsize=(12.2, figure_height), facecolor="white") - grid = figure.add_gridspec( - 2, - 1, - height_ratios=(3.0, 1.35), - hspace=0.08, - left=0.105, - right=0.975, - top=0.765, - bottom=bottom, - ) - main_axis = figure.add_subplot(grid[0]) - ratio_axis = figure.add_subplot(grid[1], sharex=main_axis) - - legend_entries: dict[str, tuple[Line2D, str]] = {} - for mode in modes: - color, marker, linestyle = MODE_STYLES.get(mode, ("#59636E", "o", "-")) - if mode in visible_modes and (series[mode] or ratios[mode]): - legend_entries[mode] = ( - Line2D( - [0], - [0], - color=color, - marker=marker, - linestyle=linestyle, - linewidth=1.7, - markersize=5.3, - markeredgewidth=0.8, - ), - _label(family_cells, mode), - ) - if mode in main_modes: - for run in _consecutive_runs(series[mode]): - _draw_run( - main_axis, - run, - color=color, - marker=marker, - linestyle=linestyle, - ) - if mode in ratio_modes: - for run in _consecutive_runs(ratios[mode]): - _draw_run( - ratio_axis, - run, - color=color, - marker=marker, - linestyle=linestyle, - ) - - main_axis.set_yscale("log") - main_axis.set_ylim(*_main_y_limits(main_values, axis_options)) - if not main_values: - main_axis.set_yticks([]) - main_axis.text( - 0.5, - 0.5, - "No protocol-valid measurements are currently available\n" - "for this process and metric.", - transform=main_axis.transAxes, - ha="center", - va="center", - fontsize=11, - color="#4B5560", - ) - main_axis.set_ylabel(_metric_axis_label(report, metric), fontsize=10) - main_axis.tick_params(axis="x", labelbottom=False) - ratio_axis.set_yscale(axis_options.ratio_y_scale) - ratio_axis.axhline(1.0, color="#59636E", linewidth=0.9, linestyle=":", zorder=1) - ratio_axis.set_ylim(*_ratio_y_limits(ratio_values, axis_options)) - ratio_axis.set_ylabel( - f"Ratio to\n{_label(original_family_cells, baseline)}", fontsize=9 - ) - if not ratio_values: - ratio_axis.text( - 0.5, - 0.5, - "Ratios unavailable until the baseline is remeasured.", - transform=ratio_axis.transAxes, - ha="center", - va="center", - fontsize=9.5, - color="#4B5560", - ) - ratio_axis.set_xlabel("Final-state multiplicity n", fontsize=10) - ratio_axis.set_xticks(multiplicities) - ratio_axis.set_xlim(min(multiplicities) - 0.25, max(multiplicities) + 0.25) - _style_axes(main_axis) - _style_axes(ratio_axis) - - source_boundary = _source_boundary(report, metric.key) - if source_boundary is not None: - boundary_x, boundary_label = source_boundary - for axis in (main_axis, ratio_axis): - axis.axvline( - boundary_x, - color="#75808C", - linewidth=1.0, - linestyle=(0, (2.5, 2.5)), - zorder=2, - ) - main_axis.text( - boundary_x, - 0.975, - boundary_label, - transform=main_axis.get_xaxis_transform(), - ha="center", - va="top", - fontsize=7.8, - color="#59636E", - bbox={ - "boxstyle": "round,pad=0.18", - "facecolor": "white", - "edgecolor": "none", - "alpha": 0.88, - }, - zorder=4, - ) - - figure.suptitle( - f"FullColor {_metric_title(report, metric)}: {FAMILY_TITLES[family]}", - x=0.54, - y=0.975, - fontsize=15, - fontweight="semibold", - ) - protocol_lines = _protocol_summary_lines( - report, - ratio_y_scale=axis_options.ratio_y_scale, - ) - figure.text( - 0.54, - 0.945, - "\n".join(protocol_lines), - ha="center", - va="top", - fontsize=8.7, - color="#59636E", - linespacing=1.15, - ) - if legend_entries: - preferred_modes = LEGEND_MODE_ORDER[family] - legend_modes = [mode for mode in preferred_modes if mode in legend_entries] - legend_modes.extend( - mode - for mode in modes - if mode in legend_entries and mode not in preferred_modes - ) - handles = [legend_entries[mode][0] for mode in legend_modes] - labels = [legend_entries[mode][1] for mode in legend_modes] - figure.legend( - handles, - labels, - loc="upper center", - bbox_to_anchor=(0.54, 0.91 - 0.011 * len(protocol_lines)), - ncol=4 if family == "gg" or len(labels) > 6 else 3, - frameon=False, - fontsize=8.8, - handlelength=2.5, - columnspacing=1.35, - ) - - if notes: - figure.text( - 0.105, - (notes_height - 0.68) / figure_height, - "Failures and omitted points", - ha="left", - va="top", - fontsize=9.2, - fontweight="semibold", - color="#20262D", - ) - line_step = 0.20 / figure_height - y = (notes_height - 0.96) / figure_height - for line in notes: - figure.text( - 0.105, - y, - line, - ha="left", - va="top", - fontsize=8.2, - color="#4B5560", - ) - y -= line_step - - temporary_path = output_path.with_suffix(output_path.suffix + ".tmp") - figure.savefig( - temporary_path, - format="png", - dpi=dpi, - facecolor="white", - metadata={"Software": "pyAmpliCol fft_scaling_study_plots.py"}, - ) - plt.close(figure) - temporary_path.replace(output_path) - - -def _point_payload(point: tuple[int, float]) -> dict[str, float | int]: - return {"n": point[0], "value": point[1]} - - -def _source_boundary_payload( - report: Mapping[str, Any], metric: Metric -) -> dict[str, float | str] | None: - boundary = _source_boundary(report, metric.key) - if boundary is None: - return None - x_position, label = boundary - return {"x": x_position, "label": label} - - -def _metric_data_payload( - report: Mapping[str, Any], - family: str, - metric: Metric, - *, - axis_options: AxisOptions = DEFAULT_AXIS_OPTIONS, - line_filters: LineFilterOptions = DEFAULT_LINE_FILTER_OPTIONS, -) -> dict[str, Any]: - family_cells, modes = _family_cells_for_metric(report, family, metric) - main_modes, ratio_modes, visible_modes = _visible_modes( - modes, - line_filters=line_filters, - ) - series = {mode: _series(family_cells, mode, metric) for mode in modes} - main_values = [ - value for mode in main_modes for _, value in series.get(mode, ()) - ] - baseline = FAMILY_BASELINES[family] - baseline_values = dict(series.get(baseline, ())) - mode_payloads: dict[str, Any] = {} - ratio_values: list[float] = [] - for mode in visible_modes: - values = series[mode] - ratios = [ - (n, value / baseline_values[n]) - for n, value in values - if n in baseline_values and baseline_values[n] > 0.0 - ] - if mode in ratio_modes: - ratio_values.extend(value for _, value in ratios) - mode_payloads[mode] = { - "label": _label(family_cells, mode), - "visible_in_main": mode in main_modes, - "visible_in_ratio": mode in ratio_modes, - "series": ( - [_point_payload(point) for point in values] - if mode in main_modes - else [] - ), - "ratio_to_baseline": ( - [_point_payload(point) for point in ratios] - if mode in ratio_modes - else [] - ), - } - return { - "source_metric_key": metric.key, - "slug": metric.slug, - "title": _metric_title(report, metric), - "axis_label": _metric_axis_label(report, metric), - "scale_from_report": metric.scale, - "source_boundary": _source_boundary_payload(report, metric), - "baseline_mode": baseline, - "main_axis": _axis_payload( - scale="log", - limits=_main_y_limits(main_values, axis_options), - ), - "ratio_axis": _axis_payload( - scale=axis_options.ratio_y_scale, - limits=_ratio_y_limits(ratio_values, axis_options), - ), - "modes": mode_payloads, - } - - -def _plot_data_payload( - report_sha256: str, - report: Mapping[str, Any], - *, - axis_options: AxisOptions = DEFAULT_AXIS_OPTIONS, - line_filters: LineFilterOptions = DEFAULT_LINE_FILTER_OPTIONS, - external_sources: Mapping[str, Any] | None = None, -) -> dict[str, Any]: - payload = { - "kind": "pyamplicol-fft-scaling-plot-data", - "schema_version": 1, - "report_sha256": report_sha256, - "helicity_workload": _helicity_workload(report), - "line_filters": _line_filter_payload(line_filters), - "families": { - family: { - "title": FAMILY_TITLES[family], - "metrics": { - metric.slug: _metric_data_payload( - report, - family, - metric, - axis_options=axis_options, - line_filters=line_filters, - ) - for metric in METRICS - }, - } - for family in FAMILIES - }, - } - if external_sources: - payload["external_sources"] = dict(external_sources) - return payload - - -def _write_plot_data( - report_sha256: str, - report: Mapping[str, Any], - output_directory: Path, - *, - axis_options: AxisOptions = DEFAULT_AXIS_OPTIONS, - line_filters: LineFilterOptions = DEFAULT_LINE_FILTER_OPTIONS, - external_sources: Mapping[str, Any] | None = None, -) -> Path: - data_path = output_directory / PLOT_DATA_NAME - temporary_path = data_path.with_suffix(data_path.suffix + ".tmp") - temporary_path.write_text( - json.dumps( - _plot_data_payload( - report_sha256, - report, - axis_options=axis_options, - line_filters=line_filters, - external_sources=external_sources, - ), - indent=2, - sort_keys=True, - allow_nan=False, - ) - + "\n", - encoding="utf-8", - ) - temporary_path.replace(data_path) - return data_path - - -def _configure_matplotlib() -> None: - plt.rcParams.update( - { - "font.family": "DejaVu Sans", - "axes.facecolor": "white", - "axes.labelcolor": "#20262D", - "figure.facecolor": "white", - "savefig.facecolor": "white", - "text.color": "#20262D", - } - ) - - -def _render( - report: Mapping[str, Any], - output_directory: Path, - *, - dpi: int, - axis_options: AxisOptions = DEFAULT_AXIS_OPTIONS, - line_filters: LineFilterOptions = DEFAULT_LINE_FILTER_OPTIONS, -) -> None: - if dpi < 72 or dpi > 600: - raise PlotError("--dpi must be between 72 and 600") - output_directory.mkdir(parents=True, exist_ok=True) - _configure_matplotlib() - for family in FAMILIES: - for metric in METRICS: - output_path = output_directory / f"fullcolor-{family}-{metric.slug}.png" - _plot_metric( - report, - family, - metric, - output_path, - dpi=dpi, - axis_options=axis_options, - line_filters=line_filters, - ) - print(output_path) - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as source: - for chunk in iter(lambda: source.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def _write_plot_manifest( - report_sha256: str, - report: Mapping[str, Any], - output_directory: Path, - *, - external_sources: Mapping[str, Any] | None = None, -) -> Path: - """Bind a rendered plot set to its exact source report and workload.""" - - plot_hashes: dict[str, str] = {} - for filename in PLOT_FILENAMES: - plot_path = output_directory / filename - if not plot_path.is_file(): - raise PlotError(f"rendered plot is missing: {plot_path}") - plot_hashes[filename] = _sha256(plot_path) - manifest = { - "kind": "pyamplicol-fft-scaling-plots", - "schema_version": 1, - "report_sha256": report_sha256, - "helicity_workload": _helicity_workload(report), - "plots": plot_hashes, - } - if external_sources: - manifest["external_sources"] = dict(external_sources) - manifest_path = output_directory / PLOT_MANIFEST_NAME - temporary_path = manifest_path.with_suffix(manifest_path.suffix + ".tmp") - temporary_path.write_text( - json.dumps(manifest, indent=2, sort_keys=True) + "\n", - encoding="utf-8", - ) - temporary_path.replace(manifest_path) - print(manifest_path) - return manifest_path - - -def main() -> int: - arguments = _parser().parse_args() - try: - axis_options = _axis_options_from_arguments(arguments) - line_filters = _line_filter_options_from_arguments(arguments) - report, report_sha256 = _load_report_snapshot(arguments.report) - external_sources: dict[str, Any] = {} - if arguments.recola_results is not None: - external_sources["recola_results"] = _attach_recola_results( - report, - arguments.recola_results, - ) - _render( - report, - arguments.output_directory, - dpi=arguments.dpi, - axis_options=axis_options, - line_filters=line_filters, - ) - _write_plot_manifest( - report_sha256, - report, - arguments.output_directory, - external_sources=external_sources, - ) - _write_plot_data( - report_sha256, - report, - arguments.output_directory, - axis_options=axis_options, - line_filters=line_filters, - external_sources=external_sources, - ) - except PlotError as error: - print(f"error: {error}", file=sys.stderr) - return 2 - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/final_source_numerical_truth.py b/pyamplicol/tools/developer/final_source_numerical_truth.py deleted file mode 100644 index e517fd2933..0000000000 --- a/pyamplicol/tools/developer/final_source_numerical_truth.py +++ /dev/null @@ -1,1315 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Produce a source-bound, independent numerical truth witness for one cell. - -The producer is deliberately not a benchmark. It evaluates one retained -validation point and records no wall-clock measurements. The candidate's -native lane is checked against two precision>=50 executions: - -* the candidate artifact's retained exact evaluator, and -* a distinct reference artifact carrying an authenticated pre-optimization or - independent-oracle semantics contract. - -The second artifact is mandatory. A candidate exact evaluator is useful, but -is not accepted as its own independent reference. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import os -import re -import tempfile -from collections.abc import Callable, Mapping, Sequence -from dataclasses import dataclass -from decimal import Decimal, InvalidOperation, localcontext -from pathlib import Path -from typing import Any, Protocol - -from pyamplicol.generation.structural_source_proof import ( - ROLE as STRUCTURAL_SOURCE_PROOF_ROLE, -) -from pyamplicol.generation.structural_source_proof import ( - validate_generation_structural_proof, -) -from tools.performance_report.models import Accuracy, ExecutionMode, Workload - -SCHEMA = "pyamplicol-final-source-numerical-truth-v1" -REFERENCE_SCHEMA = "pyamplicol-independent-reference-semantics-v1" -REFERENCE_ROLES = { - "independent-oracle", - "pre-optimization-reference", -} -MINIMUM_PRECISION = 50 -DEFAULT_PRECISION = 80 -DEFAULT_EXACT_AGREEMENT_DIGITS = 50 -DEFAULT_NATIVE_RELATIVE_TOLERANCE = Decimal("1e-10") -DEFAULT_NATIVE_ABSOLUTE_TOLERANCE = Decimal("1e-14") -_REVISION = re.compile(r"[0-9a-f]{40}") -_SHA256 = re.compile(r"[0-9a-f]{64}") - - -class TruthProducerError(RuntimeError): - """Independent final-source numerical truth could not be established.""" - - -class _Resolved(Protocol): - values: Sequence[Sequence[Sequence[complex | Decimal]]] - helicity_ids: Sequence[str] - color_ids: Sequence[str] - color_accuracy: str - - -class _Runtime(Protocol): - artifact_id: str - execution_mode: str - - def evaluate_resolved( - self, - momenta: object, - *, - helicities: Sequence[str] | None, - color_flows: Sequence[str] | None, - precision: int, - ) -> _Resolved: ... - - -@dataclass(frozen=True) -class _Artifact: - root: Path - manifest: Mapping[str, Any] - artifact_id: str - process_id: str - source_revision: str - color_accuracy: str - execution_path: str - execution_sha256: str - validation_path: str - validation_sha256: str - structural_proof_path: str | None - structural_proof_sha256: str | None - - -def canonical_sha256(domain: str, value: object) -> str: - encoded = json.dumps( - {"domain": domain, "value": value}, - ensure_ascii=True, - sort_keys=True, - separators=(",", ":"), - allow_nan=False, - ).encode("ascii") - return hashlib.sha256(encoded).hexdigest() - - -def comparison_sha256(payload: Mapping[str, Any]) -> str: - value = dict(payload) - value.pop("comparison_sha256", None) - return canonical_sha256("final-source-numerical-truth-v1", value) - - -def _read_json(path: Path, label: str) -> Mapping[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise TruthProducerError(f"cannot read {label} {path}: {error}") from error - if not isinstance(value, Mapping): - raise TruthProducerError(f"{label} {path} must contain a JSON object") - return value - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - while chunk := stream.read(1024 * 1024): - digest.update(chunk) - return digest.hexdigest() - - -def _required_text(value: object, label: str) -> str: - if not isinstance(value, str) or not value: - raise TruthProducerError(f"{label} must be a non-empty string") - return value - - -def _required_sha(value: object, label: str) -> str: - text = _required_text(value, label) - if _SHA256.fullmatch(text) is None: - raise TruthProducerError(f"{label} must be a lowercase SHA-256") - return text - - -def _required_revision(value: object, label: str) -> str: - text = _required_text(value, label) - if _REVISION.fullmatch(text) is None: - raise TruthProducerError(f"{label} must be a full lowercase Git revision") - return text - - -def _required_int(value: object, label: str, *, minimum: int = 0) -> int: - if not isinstance(value, int) or isinstance(value, bool) or value < minimum: - raise TruthProducerError(f"{label} must be an integer >= {minimum}") - return value - - -def _confined(root: Path, relative: str, label: str) -> Path: - if not relative: - raise TruthProducerError(f"{label} path is empty") - resolved_root = root.resolve() - path = (resolved_root / relative).resolve() - try: - path.relative_to(resolved_root) - except ValueError as error: - raise TruthProducerError(f"{label} escapes its artifact: {relative}") from error - return path - - -def _payload_record( - manifest: Mapping[str, Any], - *, - path: str | None = None, - role: str | None = None, - process_id: str | None = None, -) -> Mapping[str, Any]: - payloads = manifest.get("payloads") - if not isinstance(payloads, list): - raise TruthProducerError("artifact manifest has no payload inventory") - matches = [ - record - for record in payloads - if isinstance(record, Mapping) - and (path is None or record.get("path") == path) - and (role is None or record.get("role") == role) - and (process_id is None or record.get("process_id") == process_id) - ] - if len(matches) != 1: - description = path or f"role={role!r}, process={process_id!r}" - raise TruthProducerError( - f"artifact must declare exactly one payload for {description}" - ) - return matches[0] - - -def _artifact( - root: Path, - *, - source_revision: str, - process_id: str | None, - label: str, - require_structural_proof: bool, -) -> _Artifact: - resolved = root.resolve() - manifest = _read_json(resolved / "artifact.json", f"{label} manifest") - artifact_id = _required_sha(manifest.get("artifact_id"), f"{label} artifact_id") - producer = manifest.get("producer") - if not isinstance(producer, Mapping): - raise TruthProducerError(f"{label} producer identity is absent") - actual_revision = _required_revision( - producer.get("git_revision"), - f"{label} producer.git_revision", - ) - if actual_revision != source_revision: - raise TruthProducerError( - f"{label} source revision {actual_revision} does not equal " - f"{source_revision}" - ) - selected = ( - process_id - if process_id is not None - else _required_text( - manifest.get("default_process_id"), - f"{label} default_process_id", - ) - ) - processes = manifest.get("processes") - if not isinstance(processes, list): - raise TruthProducerError(f"{label} manifest has no process inventory") - process = next( - ( - record - for record in processes - if isinstance(record, Mapping) and record.get("id") == selected - ), - None, - ) - if process is None: - raise TruthProducerError(f"{label} process {selected!r} is absent") - accuracy = _required_text( - process.get("color_accuracy"), - f"{label} process color_accuracy", - ) - execution = _payload_record( - manifest, - role="evaluator-manifest", - process_id=selected, - ) - execution_path = _required_text( - execution.get("path"), - f"{label} execution path", - ) - execution_sha = _required_sha( - execution.get("sha256"), - f"{label} execution digest", - ) - validation = _payload_record( - manifest, - role="validation-momenta", - process_id=selected, - ) - validation_path = _required_text( - validation.get("path"), - f"{label} validation path", - ) - validation_sha = _required_sha( - validation.get("sha256"), - f"{label} validation digest", - ) - for path, expected, name in ( - (execution_path, execution_sha, "execution"), - (validation_path, validation_sha, "validation momenta"), - ): - concrete = _confined(resolved, path, f"{label} {name}") - if not concrete.is_file() or _sha256_file(concrete) != expected: - raise TruthProducerError(f"{label} {name} payload is absent or changed") - structural_path: str | None = None - structural_sha: str | None = None - if require_structural_proof: - structural = _payload_record( - manifest, - role=STRUCTURAL_SOURCE_PROOF_ROLE, - process_id=selected, - ) - structural_path = _required_text( - structural.get("path"), - f"{label} structural proof path", - ) - structural_sha = _required_sha( - structural.get("sha256"), - f"{label} structural proof digest", - ) - concrete = _confined( - resolved, - structural_path, - f"{label} structural proof", - ) - if not concrete.is_file() or _sha256_file(concrete) != structural_sha: - raise TruthProducerError( - f"{label} structural proof payload is absent or changed" - ) - native_inputs = _required_sha( - producer.get("native_build_inputs_sha256"), - f"{label} producer.native_build_inputs_sha256", - ) - execution_payload = _read_json( - _confined(resolved, execution_path, f"{label} execution"), - f"{label} execution", - ) - try: - validate_generation_structural_proof( - _read_json(concrete, f"{label} structural proof"), - artifact_root=resolved, - expected_process_id=selected, - expected_source_revision=actual_revision, - expected_native_build_inputs_sha256=native_inputs, - expected_execution_path=execution_path, - expected_execution_sha256=execution_sha, - execution=execution_payload, - ) - except ValueError as error: - raise TruthProducerError( - f"{label} generation structural proof does not recompute" - ) from error - return _Artifact( - root=resolved, - manifest=manifest, - artifact_id=artifact_id, - process_id=selected, - source_revision=actual_revision, - color_accuracy=accuracy, - execution_path=execution_path, - execution_sha256=execution_sha, - validation_path=validation_path, - validation_sha256=validation_sha, - structural_proof_path=structural_path, - structural_proof_sha256=structural_sha, - ) - - -def _canonical_decimal(value: object, label: str) -> str: - if isinstance(value, bool): - raise TruthProducerError(f"{label} cannot be boolean") - try: - if isinstance(value, Decimal): - decimal = value - elif isinstance(value, float): - if not math.isfinite(value): - raise TruthProducerError(f"{label} is not finite") - decimal = Decimal(format(value, ".17g")) - elif isinstance(value, (int, str)): - decimal = Decimal(value) - else: - raise TruthProducerError(f"{label} is not a decimal scalar") - except InvalidOperation as error: - raise TruthProducerError(f"{label} is not a valid decimal") from error - if not decimal.is_finite(): - raise TruthProducerError(f"{label} is not finite") - if decimal == 0: - return "0" - rendered = format(decimal, "f") - if "." in rendered: - rendered = rendered.rstrip("0").rstrip(".") - return rendered - - -def _validation_payload(artifact: _Artifact, label: str) -> dict[str, Any]: - raw = _read_json( - _confined(artifact.root, artifact.validation_path, f"{label} validation"), - f"{label} validation", - ) - points = raw.get("points") - if ( - raw.get("available") is not True - or not isinstance(points, list) - or len(points) != 1 - ): - raise TruthProducerError( - f"{label} must retain exactly one available validation point" - ) - particles = points[0] - if not isinstance(particles, list) or not particles: - raise TruthProducerError(f"{label} validation point is empty") - canonical_particles: list[dict[str, Any]] = [] - for particle_index, particle in enumerate(particles): - if not isinstance(particle, Mapping): - raise TruthProducerError( - f"{label} validation particle {particle_index} is malformed" - ) - pdg = particle.get("pdg") - momentum = particle.get("momentum") - if ( - not isinstance(pdg, int) - or isinstance(pdg, bool) - or not isinstance(momentum, list) - or len(momentum) != 4 - ): - raise TruthProducerError( - f"{label} validation particle {particle_index} is malformed" - ) - canonical_particles.append( - { - "pdg": pdg, - "momentum": [ - _canonical_decimal( - component, - f"{label} validation particle {particle_index} component", - ) - for component in momentum - ], - } - ) - return {"points": [canonical_particles]} - - -def _momenta(payload: Mapping[str, Any]) -> tuple[tuple[tuple[str, ...], ...], ...]: - points = payload["points"] - assert isinstance(points, list) - return tuple( - tuple(tuple(str(value) for value in particle["momentum"]) for particle in point) - for point in points - ) - - -def _reference_contract( - reference: _Artifact, - contract_relative_path: str, -) -> dict[str, Any]: - record = _payload_record(reference.manifest, path=contract_relative_path) - if record.get("role") != "independent-reference-semantics": - raise TruthProducerError( - "reference contract must use role 'independent-reference-semantics'" - ) - expected_contract_sha = _required_sha( - record.get("sha256"), - "reference contract payload digest", - ) - contract_path = _confined( - reference.root, - contract_relative_path, - "reference contract", - ) - if ( - not contract_path.is_file() - or _sha256_file(contract_path) != expected_contract_sha - ): - raise TruthProducerError("reference contract is absent or changed") - raw = _read_json(contract_path, "reference contract") - semantics = raw.get("semantics") - if ( - raw.get("schema") != REFERENCE_SCHEMA - or raw.get("status") != "materialized" - or raw.get("source_revision") != reference.source_revision - or raw.get("artifact_id") != reference.artifact_id - or raw.get("process_id") != reference.process_id - or semantics not in REFERENCE_ROLES - ): - raise TruthProducerError( - "reference contract is stale or does not certify independent semantics" - ) - payloads = raw.get("semantic_payloads") - if not isinstance(payloads, list) or not payloads: - raise TruthProducerError("reference contract has no semantic payloads") - normalized_payloads: list[dict[str, str]] = [] - content_ids: set[str] = set() - for index, item in enumerate(payloads): - if not isinstance(item, Mapping): - raise TruthProducerError(f"reference semantic payload {index} is malformed") - relative = _required_text( - item.get("path"), - f"reference semantic payload {index} path", - ) - expected = _required_sha( - item.get("sha256"), - f"reference semantic payload {index} digest", - ) - declared = _payload_record(reference.manifest, path=relative) - if declared.get("sha256") != expected: - raise TruthProducerError( - f"reference semantic payload {relative} disagrees with manifest" - ) - concrete = _confined(reference.root, relative, "reference semantic payload") - if not concrete.is_file() or _sha256_file(concrete) != expected: - raise TruthProducerError( - f"reference semantic payload {relative} is absent or changed" - ) - if expected in content_ids: - raise TruthProducerError( - "reference semantic payload inventory repeats a content identity" - ) - content_ids.add(expected) - normalized_payloads.append({"path": relative, "sha256": expected}) - normalized = { - "schema": REFERENCE_SCHEMA, - "status": "materialized", - "semantics": semantics, - "source_revision": reference.source_revision, - "artifact_id": reference.artifact_id, - "process_id": reference.process_id, - "contract_sha256": expected_contract_sha, - "semantic_payloads": normalized_payloads, - } - normalized["semantic_identity_sha256"] = canonical_sha256( - "independent-reference-semantics-v1", - normalized, - ) - return normalized - - -def _selector_payload( - *, - workload: Workload, - helicity_ids: Sequence[str], - color_ids: Sequence[str], -) -> dict[str, Any]: - helicities = list(helicity_ids) - colors = list(color_ids) - if ( - len(set(helicities)) != len(helicities) - or len(set(colors)) != len(colors) - or any(not value for value in (*helicities, *colors)) - ): - raise TruthProducerError("selector IDs must be non-empty and unique") - if workload is Workload.SELECTED_FLOW: - if len(helicities) != 1 or len(colors) != 1: - raise TruthProducerError( - "selected-flow truth requires exactly one helicity and color selector" - ) - elif helicities or colors: - raise TruthProducerError( - f"{workload.value} truth must not apply resolved-axis selectors" - ) - payload: dict[str, Any] = { - "workload": workload.value, - "helicity_ids": helicities, - "color_ids": colors, - } - payload["selector_sha256"] = canonical_sha256( - "final-source-selectors-v1", - payload, - ) - return payload - - -def _axes(resolved: _Resolved) -> dict[str, Any]: - payload: dict[str, Any] = { - "color_accuracy": str(resolved.color_accuracy), - "helicity_ids": [str(value) for value in resolved.helicity_ids], - "color_ids": [str(value) for value in resolved.color_ids], - } - payload["resolved_axes_sha256"] = canonical_sha256( - "final-source-resolved-axes-v1", - payload, - ) - return payload - - -def _exact_values(resolved: _Resolved, label: str) -> list[list[list[str]]]: - output: list[list[list[str]]] = [] - for point_index, point in enumerate(resolved.values): - rows: list[list[str]] = [] - for helicity_index, row in enumerate(point): - values: list[str] = [] - for color_index, value in enumerate(row): - if not isinstance(value, Decimal): - raise TruthProducerError( - f"{label}[{point_index},{helicity_index},{color_index}] " - "is not independently materialized Decimal output" - ) - values.append( - _canonical_decimal( - value, - f"{label}[{point_index},{helicity_index},{color_index}]", - ) - ) - rows.append(values) - output.append(rows) - return output - - -def _native_values( - resolved: _Resolved, - label: str, -) -> list[list[list[list[str]]]]: - output: list[list[list[list[str]]]] = [] - for point_index, point in enumerate(resolved.values): - rows: list[list[list[str]]] = [] - for helicity_index, row in enumerate(point): - values: list[list[str]] = [] - for color_index, value in enumerate(row): - complex_value = complex(value) - if not math.isfinite(complex_value.real) or not math.isfinite( - complex_value.imag - ): - raise TruthProducerError( - f"{label}[{point_index},{helicity_index},{color_index}] " - "is not finite" - ) - values.append( - [ - _canonical_decimal(complex_value.real, f"{label} real"), - _canonical_decimal(complex_value.imag, f"{label} imaginary"), - ] - ) - rows.append(values) - output.append(rows) - return output - - -def _flatten_exact(values: object, label: str) -> list[Decimal]: - if not isinstance(values, list) or not values: - raise TruthProducerError(f"{label} must contain at least one point") - flattened: list[Decimal] = [] - try: - for point in values: - if not isinstance(point, list) or not point: - raise TruthProducerError(f"{label} has an empty helicity axis") - for row in point: - if not isinstance(row, list) or not row: - raise TruthProducerError(f"{label} has an empty color axis") - for value in row: - if not isinstance(value, str): - raise TruthProducerError( - f"{label} exact values must be decimal strings" - ) - decimal = Decimal(value) - if not decimal.is_finite(): - raise TruthProducerError(f"{label} contains non-finite values") - flattened.append(decimal) - except InvalidOperation as error: - raise TruthProducerError(f"{label} contains invalid decimals") from error - return flattened - - -def _flatten_native(values: object, label: str) -> list[tuple[Decimal, Decimal]]: - if not isinstance(values, list) or not values: - raise TruthProducerError(f"{label} must contain at least one point") - flattened: list[tuple[Decimal, Decimal]] = [] - try: - for point in values: - if not isinstance(point, list) or not point: - raise TruthProducerError(f"{label} has an empty helicity axis") - for row in point: - if not isinstance(row, list) or not row: - raise TruthProducerError(f"{label} has an empty color axis") - for value in row: - if ( - not isinstance(value, list) - or len(value) != 2 - or not all(isinstance(item, str) for item in value) - ): - raise TruthProducerError( - f"{label} native values must be [real, imaginary] strings" - ) - pair = (Decimal(value[0]), Decimal(value[1])) - if not all(item.is_finite() for item in pair): - raise TruthProducerError(f"{label} contains non-finite values") - flattened.append(pair) - except InvalidOperation as error: - raise TruthProducerError(f"{label} contains invalid decimals") from error - return flattened - - -def _agreement( - candidate_exact: object, - candidate_native: object, - reference_exact: object, - *, - precision: int, - exact_agreement_digits: int, - native_relative_tolerance: Decimal, - native_absolute_tolerance: Decimal, -) -> dict[str, Any]: - candidate = _flatten_exact(candidate_exact, "candidate_exact.values") - native = _flatten_native(candidate_native, "candidate_native.values") - reference = _flatten_exact(reference_exact, "reference_exact.values") - if len(candidate) != len(reference) or len(native) != len(reference): - raise TruthProducerError("candidate/reference resolved value shapes differ") - if exact_agreement_digits > precision - 5: - raise TruthProducerError( - "exact agreement digits must leave at least five guard digits" - ) - exact_tolerance = Decimal(1).scaleb(-exact_agreement_digits) - exact_max_absolute = Decimal(0) - exact_max_relative = Decimal(0) - native_max_absolute = Decimal(0) - native_max_relative = Decimal(0) - native_max_imaginary = Decimal(0) - exact_passes = True - native_passes = True - with localcontext() as context: - context.prec = max(precision + 20, 100) - for exact_value, (native_real, native_imaginary), reference_value in zip( - candidate, - native, - reference, - strict=True, - ): - exact_absolute = abs(exact_value - reference_value) - exact_relative = exact_absolute / max( - abs(exact_value), - abs(reference_value), - Decimal(1).scaleb(-precision), - ) - native_absolute = abs(native_real - reference_value) - native_relative = native_absolute / max( - abs(native_real), - abs(reference_value), - Decimal("1e-300"), - ) - exact_max_absolute = max(exact_max_absolute, exact_absolute) - exact_max_relative = max(exact_max_relative, exact_relative) - native_max_absolute = max(native_max_absolute, native_absolute) - native_max_relative = max(native_max_relative, native_relative) - native_max_imaginary = max( - native_max_imaginary, - abs(native_imaginary), - ) - exact_passes = exact_passes and ( - exact_absolute <= exact_tolerance or exact_relative <= exact_tolerance - ) - native_passes = ( - native_passes - and ( - native_absolute <= native_absolute_tolerance - or native_relative <= native_relative_tolerance - ) - and abs(native_imaginary) <= native_absolute_tolerance - ) - return { - "component_count": len(reference), - "exact_agreement_decimal_digits": exact_agreement_digits, - "exact_absolute_tolerance": _canonical_decimal( - exact_tolerance, - "exact tolerance", - ), - "native_relative_tolerance": _canonical_decimal( - native_relative_tolerance, - "native relative tolerance", - ), - "native_absolute_tolerance": _canonical_decimal( - native_absolute_tolerance, - "native absolute tolerance", - ), - "candidate_exact_vs_reference": { - "maximum_absolute_difference": _canonical_decimal( - exact_max_absolute, - "exact maximum absolute difference", - ), - "maximum_relative_difference": _canonical_decimal( - exact_max_relative, - "exact maximum relative difference", - ), - "passes": exact_passes, - }, - "candidate_native_vs_reference": { - "maximum_absolute_difference": _canonical_decimal( - native_max_absolute, - "native maximum absolute difference", - ), - "maximum_relative_difference": _canonical_decimal( - native_max_relative, - "native maximum relative difference", - ), - "maximum_imaginary_magnitude": _canonical_decimal( - native_max_imaginary, - "native maximum imaginary magnitude", - ), - "passes": native_passes, - }, - "passes": exact_passes and native_passes, - } - - -def _value_record( - *, - precision: int, - executor: str, - values: object, - domain: str, -) -> dict[str, Any]: - record: dict[str, Any] = { - "precision_decimal_digits": precision, - "executor": executor, - "values": values, - } - record["values_sha256"] = canonical_sha256(domain, values) - return record - - -def validate_witness_payload( - raw: Mapping[str, Any], - *, - expected_source_revision: str | None = None, - expected_cell_id: str | None = None, - expected_mode: str | None = None, - expected_accuracy: str | None = None, - expected_workload: str | None = None, - expected_candidate_artifact_id: str | None = None, - expected_structural_proof_sha256: str | None = None, -) -> dict[str, Any]: - """Recompute every numerical digest and agreement in a serialized witness.""" - - payload = dict(raw) - if payload.get("schema") != SCHEMA or payload.get("status") != "ok": - raise TruthProducerError("numerical truth witness schema/status is invalid") - revision = _required_revision(payload.get("source_revision"), "source_revision") - if expected_source_revision is not None and revision != expected_source_revision: - raise TruthProducerError("numerical truth source revision mismatch") - for name, expected in ( - ("cell_id", expected_cell_id), - ("mode", expected_mode), - ("accuracy", expected_accuracy), - ("workload", expected_workload), - ): - actual = _required_text(payload.get(name), name) - if expected is not None and actual != expected: - raise TruthProducerError(f"numerical truth {name} mismatch") - precision = _required_int( - payload.get("precision_decimal_digits"), - "precision_decimal_digits", - minimum=MINIMUM_PRECISION, - ) - candidate_artifact = payload.get("candidate_artifact") - reference_artifact = payload.get("reference_artifact") - if not isinstance(candidate_artifact, Mapping) or not isinstance( - reference_artifact, - Mapping, - ): - raise TruthProducerError("candidate/reference artifact identity is absent") - candidate_id = _required_sha( - candidate_artifact.get("artifact_id"), - "candidate artifact_id", - ) - reference_id = _required_sha( - reference_artifact.get("artifact_id"), - "reference artifact_id", - ) - if candidate_id == reference_id: - raise TruthProducerError( - "candidate and independent reference repeat one content identity" - ) - if ( - expected_candidate_artifact_id is not None - and candidate_id != expected_candidate_artifact_id - ): - raise TruthProducerError("candidate artifact identity mismatch") - structural_proof_sha256 = _required_sha( - candidate_artifact.get("structural_proof_sha256"), - "candidate structural proof digest", - ) - _required_text( - candidate_artifact.get("structural_proof_path"), - "candidate structural proof path", - ) - if ( - expected_structural_proof_sha256 is not None - and structural_proof_sha256 != expected_structural_proof_sha256 - ): - raise TruthProducerError("candidate structural proof identity mismatch") - if candidate_artifact.get("source_revision") != revision or ( - reference_artifact.get("source_revision") != revision - ): - raise TruthProducerError("artifact identity is not source-bound") - contract = reference_artifact.get("semantics_contract") - if ( - not isinstance(contract, Mapping) - or contract.get("schema") != REFERENCE_SCHEMA - or contract.get("status") != "materialized" - or contract.get("semantics") not in REFERENCE_ROLES - or contract.get("source_revision") != revision - or contract.get("artifact_id") != reference_id - ): - raise TruthProducerError("independent reference semantics are not materialized") - semantic_payloads = contract.get("semantic_payloads") - if not isinstance(semantic_payloads, list) or not semantic_payloads: - raise TruthProducerError("independent reference semantic payloads are absent") - content_ids: set[str] = set() - for index, item in enumerate(semantic_payloads): - if not isinstance(item, Mapping): - raise TruthProducerError(f"reference semantic payload {index} is malformed") - _required_text(item.get("path"), f"semantic payload {index} path") - content_id = _required_sha( - item.get("sha256"), - f"semantic payload {index} digest", - ) - if content_id in content_ids: - raise TruthProducerError( - "reference semantic payloads repeat one content identity" - ) - content_ids.add(content_id) - semantic_normalized = dict(contract) - declared_semantic_identity = _required_sha( - semantic_normalized.pop("semantic_identity_sha256", None), - "reference semantic identity", - ) - if declared_semantic_identity != canonical_sha256( - "independent-reference-semantics-v1", - semantic_normalized, - ): - raise TruthProducerError("reference semantic identity digest mismatch") - - momenta = payload.get("validation_momenta") - selectors = payload.get("selectors") - axes = payload.get("resolved_axes") - if not all(isinstance(value, Mapping) for value in (momenta, selectors, axes)): - raise TruthProducerError("momenta/selectors/resolved axes are absent") - momenta_map = dict(momenta) - declared_momenta = _required_sha( - momenta_map.pop("validation_momenta_sha256", None), - "validation momenta digest", - ) - if declared_momenta != canonical_sha256( - "final-source-validation-momenta-v1", - momenta_map, - ): - raise TruthProducerError("validation momenta digest mismatch") - selector_map = dict(selectors) - declared_selectors = _required_sha( - selector_map.pop("selector_sha256", None), - "selector digest", - ) - if declared_selectors != canonical_sha256( - "final-source-selectors-v1", - selector_map, - ): - raise TruthProducerError("selector digest mismatch") - axes_map = dict(axes) - declared_axes = _required_sha( - axes_map.pop("resolved_axes_sha256", None), - "resolved axes digest", - ) - if declared_axes != canonical_sha256( - "final-source-resolved-axes-v1", - axes_map, - ): - raise TruthProducerError("resolved axes digest mismatch") - if axes_map.get("color_accuracy") != payload.get("accuracy"): - raise TruthProducerError("resolved axes accuracy mismatch") - - records: dict[str, Mapping[str, Any]] = {} - for name, domain in ( - ("candidate_native", "final-source-candidate-native-values-v1"), - ("candidate_exact", "final-source-candidate-exact-values-v1"), - ("reference_exact", "final-source-reference-exact-values-v1"), - ): - record = payload.get(name) - if not isinstance(record, Mapping): - raise TruthProducerError(f"{name} record is absent") - record_precision = _required_int( - record.get("precision_decimal_digits"), - f"{name} precision", - minimum=16, - ) - if name == "candidate_native": - if record_precision != 16: - raise TruthProducerError("candidate native precision must be 16") - elif record_precision != precision: - raise TruthProducerError(f"{name} precision mismatch") - values = record.get("values") - declared = _required_sha(record.get("values_sha256"), f"{name} values digest") - if declared != canonical_sha256(domain, values): - raise TruthProducerError(f"{name} values digest mismatch") - records[name] = record - - agreement = payload.get("agreement") - if not isinstance(agreement, Mapping): - raise TruthProducerError("numerical agreement payload is absent") - exact_digits = _required_int( - agreement.get("exact_agreement_decimal_digits"), - "exact agreement digits", - minimum=1, - ) - try: - native_relative = Decimal( - _required_text( - agreement.get("native_relative_tolerance"), - "native relative tolerance", - ) - ) - native_absolute = Decimal( - _required_text( - agreement.get("native_absolute_tolerance"), - "native absolute tolerance", - ) - ) - except InvalidOperation as error: - raise TruthProducerError("native tolerance is not decimal") from error - recomputed = _agreement( - records["candidate_exact"].get("values"), - records["candidate_native"].get("values"), - records["reference_exact"].get("values"), - precision=precision, - exact_agreement_digits=exact_digits, - native_relative_tolerance=native_relative, - native_absolute_tolerance=native_absolute, - ) - if dict(agreement) != recomputed or recomputed["passes"] is not True: - raise TruthProducerError("numerical agreement payload does not recompute") - declared_comparison = _required_sha( - payload.get("comparison_sha256"), - "comparison_sha256", - ) - if declared_comparison != comparison_sha256(payload): - raise TruthProducerError("comparison_sha256 does not authenticate the witness") - return payload - - -def build_witness( - candidate_root: Path, - reference_root: Path, - *, - reference_contract_path: str, - cell_id: str, - source_revision: str, - mode: ExecutionMode, - accuracy: Accuracy, - workload: Workload, - helicity_ids: Sequence[str] = (), - color_ids: Sequence[str] = (), - candidate_process_id: str | None = None, - reference_process_id: str | None = None, - precision: int = DEFAULT_PRECISION, - exact_agreement_digits: int = DEFAULT_EXACT_AGREEMENT_DIGITS, - native_relative_tolerance: Decimal = DEFAULT_NATIVE_RELATIVE_TOLERANCE, - native_absolute_tolerance: Decimal = DEFAULT_NATIVE_ABSOLUTE_TOLERANCE, - runtime_loader: Callable[..., _Runtime] | None = None, -) -> dict[str, Any]: - """Materialize and authenticate one structural-only comparison witness.""" - - revision = _required_revision(source_revision, "source_revision") - if precision < MINIMUM_PRECISION: - raise TruthProducerError( - f"comparison precision must be >= {MINIMUM_PRECISION} decimal digits" - ) - candidate = _artifact( - candidate_root, - source_revision=revision, - process_id=candidate_process_id, - label="candidate", - require_structural_proof=True, - ) - reference = _artifact( - reference_root, - source_revision=revision, - process_id=reference_process_id, - label="reference", - require_structural_proof=False, - ) - if candidate.artifact_id == reference.artifact_id: - raise TruthProducerError( - "candidate and independent reference artifacts have one content identity" - ) - if candidate.color_accuracy != accuracy.value or ( - reference.color_accuracy != accuracy.value - ): - raise TruthProducerError("candidate/reference color accuracy mismatch") - reference_contract = _reference_contract(reference, reference_contract_path) - candidate_momenta = _validation_payload(candidate, "candidate") - reference_momenta = _validation_payload(reference, "reference") - if candidate_momenta != reference_momenta: - raise TruthProducerError( - "candidate/reference validation momenta or external PDG order differ" - ) - selector_payload = _selector_payload( - workload=workload, - helicity_ids=helicity_ids, - color_ids=color_ids, - ) - if runtime_loader is None: - from pyamplicol import Runtime - - runtime_loader = Runtime.load - candidate_runtime = runtime_loader( - candidate.root, - process=candidate.process_id, - ) - reference_runtime = runtime_loader( - reference.root, - process=reference.process_id, - ) - if candidate_runtime.artifact_id != candidate.artifact_id or ( - reference_runtime.artifact_id != reference.artifact_id - ): - raise TruthProducerError("loaded runtime artifact identity mismatch") - if candidate_runtime.execution_mode != mode.value: - raise TruthProducerError("candidate runtime execution mode mismatch") - selectors = { - "helicities": tuple(helicity_ids) or None, - "color_flows": tuple(color_ids) or None, - } - points = _momenta(candidate_momenta) - try: - candidate_native_resolved = candidate_runtime.evaluate_resolved( - points, - precision=16, - **selectors, - ) - candidate_exact_resolved = candidate_runtime.evaluate_resolved( - points, - precision=precision, - **selectors, - ) - reference_exact_resolved = reference_runtime.evaluate_resolved( - points, - precision=precision, - **selectors, - ) - except Exception as error: - raise TruthProducerError( - "independent precision comparison could not be materialized" - ) from error - candidate_axes = _axes(candidate_exact_resolved) - if _axes(candidate_native_resolved) != candidate_axes or ( - _axes(reference_exact_resolved) != candidate_axes - ): - raise TruthProducerError("candidate/reference resolved axes differ") - candidate_native_values = _native_values( - candidate_native_resolved, - "candidate native", - ) - candidate_exact_values = _exact_values( - candidate_exact_resolved, - "candidate exact", - ) - reference_exact_values = _exact_values( - reference_exact_resolved, - "reference exact", - ) - agreement = _agreement( - candidate_exact_values, - candidate_native_values, - reference_exact_values, - precision=precision, - exact_agreement_digits=exact_agreement_digits, - native_relative_tolerance=native_relative_tolerance, - native_absolute_tolerance=native_absolute_tolerance, - ) - if agreement["passes"] is not True: - raise TruthProducerError( - "candidate does not agree with the independent reference" - ) - momenta_record: dict[str, Any] = { - "candidate_payload_sha256": candidate.validation_sha256, - "reference_payload_sha256": reference.validation_sha256, - **candidate_momenta, - } - momenta_record["validation_momenta_sha256"] = canonical_sha256( - "final-source-validation-momenta-v1", - momenta_record, - ) - payload: dict[str, Any] = { - "schema": SCHEMA, - "status": "ok", - "cell_id": cell_id, - "source_revision": revision, - "mode": mode.value, - "accuracy": accuracy.value, - "workload": workload.value, - "precision_decimal_digits": precision, - "validation_momenta": momenta_record, - "selectors": selector_payload, - "resolved_axes": candidate_axes, - "candidate_artifact": { - "artifact_id": candidate.artifact_id, - "source_revision": revision, - "process_id": candidate.process_id, - "execution_mode": candidate_runtime.execution_mode, - "execution_payload_path": candidate.execution_path, - "execution_payload_sha256": candidate.execution_sha256, - "structural_proof_path": candidate.structural_proof_path, - "structural_proof_sha256": candidate.structural_proof_sha256, - }, - "reference_artifact": { - "artifact_id": reference.artifact_id, - "source_revision": revision, - "process_id": reference.process_id, - "execution_mode": reference_runtime.execution_mode, - "execution_payload_path": reference.execution_path, - "execution_payload_sha256": reference.execution_sha256, - "semantics_contract": reference_contract, - }, - "candidate_native": _value_record( - precision=16, - executor=f"native-{mode.value}", - values=candidate_native_values, - domain="final-source-candidate-native-values-v1", - ), - "candidate_exact": _value_record( - precision=precision, - executor=f"retained-exact-{mode.value}", - values=candidate_exact_values, - domain="final-source-candidate-exact-values-v1", - ), - "reference_exact": _value_record( - precision=precision, - executor=str(reference_contract["semantics"]), - values=reference_exact_values, - domain="final-source-reference-exact-values-v1", - ), - "agreement": agreement, - } - payload["comparison_sha256"] = comparison_sha256(payload) - return validate_witness_payload( - payload, - expected_source_revision=revision, - expected_cell_id=cell_id, - expected_mode=mode.value, - expected_accuracy=accuracy.value, - expected_workload=workload.value, - expected_candidate_artifact_id=candidate.artifact_id, - expected_structural_proof_sha256=candidate.structural_proof_sha256, - ) - - -def _atomic_write(path: Path, payload: Mapping[str, Any]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - descriptor, temporary_name = tempfile.mkstemp( - prefix=f".{path.name}.", - suffix=".tmp", - dir=path.parent, - ) - temporary = Path(temporary_name) - try: - with os.fdopen(descriptor, "w", encoding="ascii") as stream: - json.dump( - payload, - stream, - ensure_ascii=True, - indent=2, - sort_keys=True, - allow_nan=False, - ) - stream.write("\n") - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - finally: - temporary.unlink(missing_ok=True) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--candidate-artifact", type=Path, required=True) - parser.add_argument("--reference-artifact", type=Path, required=True) - parser.add_argument("--reference-contract-path", required=True) - parser.add_argument("--cell-id", required=True) - parser.add_argument("--source-revision", required=True) - parser.add_argument( - "--mode", - choices=[item.value for item in ExecutionMode], - required=True, - ) - parser.add_argument( - "--accuracy", - choices=[item.value for item in Accuracy], - required=True, - ) - parser.add_argument( - "--workload", - choices=[item.value for item in Workload], - required=True, - ) - parser.add_argument("--helicity-id", action="append", default=[]) - parser.add_argument("--color-id", action="append", default=[]) - parser.add_argument("--candidate-process-id") - parser.add_argument("--reference-process-id") - parser.add_argument("--precision", type=int, default=DEFAULT_PRECISION) - parser.add_argument( - "--exact-agreement-digits", - type=int, - default=DEFAULT_EXACT_AGREEMENT_DIGITS, - ) - parser.add_argument("--output", type=Path, required=True) - return parser - - -def main() -> int: - arguments = _parser().parse_args() - try: - payload = build_witness( - arguments.candidate_artifact, - arguments.reference_artifact, - reference_contract_path=arguments.reference_contract_path, - cell_id=arguments.cell_id, - source_revision=arguments.source_revision, - mode=ExecutionMode(arguments.mode), - accuracy=Accuracy(arguments.accuracy), - workload=Workload(arguments.workload), - helicity_ids=arguments.helicity_id, - color_ids=arguments.color_id, - candidate_process_id=arguments.candidate_process_id, - reference_process_id=arguments.reference_process_id, - precision=arguments.precision, - exact_agreement_digits=arguments.exact_agreement_digits, - ) - except TruthProducerError as error: - print(f"final-source numerical truth unavailable: {error}") - return 2 - _atomic_write(arguments.output, payload) - print( - json.dumps( - { - "cell_id": payload["cell_id"], - "comparison_sha256": payload["comparison_sha256"], - "precision_decimal_digits": payload["precision_decimal_digits"], - "status": payload["status"], - }, - sort_keys=True, - ) - ) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/four_quark_compiled_gate.py b/pyamplicol/tools/developer/four_quark_compiled_gate.py deleted file mode 100644 index 5409d1181d..0000000000 --- a/pyamplicol/tools/developer/four_quark_compiled_gate.py +++ /dev/null @@ -1,2491 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Validate compiled Direct-Arena execution for four independent quark lines. - -The physical process is fixed to ``d d~ > u u~ s s~ c c~``. A successful -run generates exactly these compiled/JIT/O3 artifacts: - -* LC topology replay; -* LC all-flow union; -* NLC contracted color; -* full contracted color. - -The gate also proves that NLC/full all-flow-union configurations fail closed, -evaluates two or three deterministic phase-space points in f64 and precision -32, checks resolved sums, compares the two LC layouts component by component -and through runtime selectors, and recursively authenticates every -compiled-stage-plan v2 residual/table ownership descriptor. - -Run the complete gate from a clean, exact-source candidate: - -``` -.venv/bin/python tools/ci/memory_watchdog.py --limit-gib 30 -- \ - .venv/bin/python tools/developer/four_quark_compiled_gate.py \ - --output-root /private/tmp/pyamplicol-four-quark-compiled-gate -``` - -The outer watchdog is mandatory. Generation workers are descendants of the -guarded process and intentionally do not start nested watchdogs. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib -import importlib.machinery -import json -import math -import os -import platform -import re -import resource -import shutil -import stat -import subprocess -import sys -import sysconfig -import tempfile -import time -import tomllib -import uuid -from collections.abc import Iterable, Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -_EXACT_REEXEC_MARKER = "PYAMPLICOL_EXACT_PYTHON_REEXEC" -_EXACT_IMPORT_PATHS = "PYAMPLICOL_EXACT_IMPORT_PATHS" - - -def _bootstrap_source_only_python() -> None: - """Re-exec before importing any repository or candidate module.""" - - if os.environ.get(_EXACT_REEXEC_MARKER) == "1": - if ( - sys.flags.isolated != 1 - or sys.flags.no_site != 1 - or sys.flags.ignore_environment != 1 - or sys.flags.dont_write_bytecode != 1 - or not sys.dont_write_bytecode - ): - raise RuntimeError("exact Python re-exec flags are incomplete") - raw_paths = json.loads(os.environ[_EXACT_IMPORT_PATHS]) - if not isinstance(raw_paths, list) or not all( - isinstance(path, str) and Path(path).is_absolute() for path in raw_paths - ): - raise RuntimeError("exact Python import paths are invalid") - cache_prefix = os.environ.get("PYTHONPYCACHEPREFIX") - if ( - not isinstance(cache_prefix, str) - or not Path(cache_prefix).is_absolute() - or Path(cache_prefix).exists() - ): - raise RuntimeError("exact Python cache prefix is not absent") - for import_path in reversed(raw_paths): - if import_path not in sys.path: - sys.path.insert(0, import_path) - sys.pycache_prefix = cache_prefix - return - - prefix = Path(tempfile.gettempdir()) / ( - f".pyamplicol-no-bytecode-{os.getpid()}-{uuid.uuid4().hex}" - ) - if prefix.exists(): - raise RuntimeError( - f"isolated Python cache prefix unexpectedly exists: {prefix}" - ) - import_paths: list[str] = [] - native_root = next( - ( - candidate - for entry in sys.path - if (candidate := Path(entry) / "pyamplicol").is_dir() - and any( - path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in candidate.iterdir() - ) - ), - None, - ) - if native_root is not None: - import_paths.append(str(native_root.parent.resolve(strict=True))) - for scheme_name in ("purelib", "platlib"): - scheme_path = sysconfig.get_path(scheme_name) - if not isinstance(scheme_path, str): - continue - try: - resolved = str(Path(scheme_path).resolve(strict=True)) - except OSError: - continue - if resolved not in import_paths: - import_paths.append(resolved) - environment = os.environ.copy() - environment["PYTHONDONTWRITEBYTECODE"] = "1" - environment["PYTHONPYCACHEPREFIX"] = str(prefix) - environment[_EXACT_REEXEC_MARKER] = "1" - environment[_EXACT_IMPORT_PATHS] = json.dumps(import_paths) - os.execve( - sys.executable, - ( - sys.executable, - "-I", - "-S", - "-B", - str(Path(__file__).resolve(strict=True)), - *sys.argv[1:], - ), - environment, - ) - raise RuntimeError("exact Python re-exec returned unexpectedly") - - -if __name__ == "__main__": - _bootstrap_source_only_python() - -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.performance_report.runtime_evidence import ( # noqa: E402 - RuntimeEvidenceError, - established_preimport_runtime_identity, - loaded_pyamplicol_origin_policy, - native_extension_in_package, - preimport_python_runtime_identity, - python_package_tree_identity, - source_only_bytecode_policy, -) - -PROCESS = "d d~ > u u~ s s~ c c~" -EXPECTED_EXTERNAL_PDGS = (-4, -3, -2, -1, 1, 2, 3, 4) -MAX_QUARK_LINES = 4 -VALIDATION_SEED = 20260725 -POINT_SEEDS = (443_041, 443_099, 443_137) -SQRT_S = 2_000.0 -RELATIVE_TOLERANCE = 1.0e-12 -ABSOLUTE_TOLERANCE = 1.0e-300 -COMPILED_PLANE_ARENA_CAPABILITY = "compiled-plane-arena-v2" -COMPILED_PLANE_DIRECT_APPLICATION_ABI = "pyamplicol-compiled-plane-kernel-v2" -COMPILED_DIRECT_TABLE_BINDING_ABI = "pyamplicol-eager-plane-table-binding-v2" -COMPILED_DIRECT_TABLE_DESCRIPTOR_ABI = "pyamplicol-eager-plane-table-descriptor-v1" -NATIVE_COMPILED_DIRECT_APPLICATION_ABI = ( - "pyamplicol-native-compiled-direct-application-v1" -) -SYMJIT_APPLICATION_ABI = "symjit-application-storage-v3" -SYMJIT_PLANE_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -SYMJIT_RUNTIME_CAPABILITY = "symjit.application.complex-f64.v1" -RESULT_KIND = "pyamplicol-four-quark-compiled-direct-arena-gate" -SCHEMA_VERSION = 1 -COMPILED_STAGE_PLAN_KIND = "compiled-plane-arena-stage-v2" -COMPILED_STAGE_PLAN_SCHEMA_VERSION = 2 -COMPILED_RESIDUAL_LEAF_KIND = "compiled-plane-arena-residual-direct-application-v2" -HASH_CHUNK_BYTES = 1024 * 1024 -REVISION_PATTERN = re.compile(r"[0-9a-f]{40}") -SHA256_PATTERN = re.compile(r"[0-9a-f]{64}") -WATCHDOG_INVOCATION = ( - ".venv/bin/python tools/ci/memory_watchdog.py --limit-gib 30 -- " - ".venv/bin/python tools/developer/four_quark_compiled_gate.py " - "--output-root /private/tmp/pyamplicol-four-quark-compiled-gate" -) -_ZERO_PROFILE_COUNTERS = ( - "stage_input_copy_component_count", - "stage_leaf_input_copy_component_count", - "stage_evaluator_output_gather_component_count", - "stage_output_assign_component_count", - "amplitude_input_copy_component_count", - "amplitude_leaf_input_copy_component_count", - "amplitude_evaluator_output_gather_component_count", - "amplitude_output_remap_component_count", - "selector_gather_point_count", - "selector_gather_bytes", - "selector_scatter_value_count", - "compiled_direct_arena_boundary_input_bytes", - "compiled_direct_arena_boundary_current_output_bytes", - "compiled_direct_arena_boundary_amplitude_output_bytes", -) -_ZERO_PROFILE_TIMES = ( - "stage_input_pack_time_s", - "stage_leaf_input_pack_time_s", - "stage_evaluator_output_gather_time_s", - "output_assign_time_s", - "amplitude_input_pack_time_s", - "amplitude_leaf_input_pack_time_s", - "amplitude_evaluator_output_gather_time_s", - "amplitude_output_remap_time_s", - "selector_gather_time_s", - "selector_scatter_time_s", -) - - -class GateError(RuntimeError): - """Raised when four-quark evidence cannot be trusted.""" - - -@dataclass(frozen=True, slots=True) -class Lane: - name: str - color_accuracy: str - lc_flow_layout: str - contracted: bool - - -LANES = ( - Lane("lc-topology-replay", "lc", "topology-replay", False), - Lane("lc-all-flow-union", "lc", "all-flow-union", False), - Lane("nlc-contracted", "nlc", "topology-replay", True), - Lane("full-contracted", "full", "topology-replay", True), -) - - -@dataclass(slots=True) -class EvaluationCapture: - """Non-serializable values retained only for cross-lane comparisons.""" - - physics_axes: dict[str, object] - f64_total: tuple[complex, ...] - exact_total: tuple[complex, ...] - f64_components: tuple[complex, ...] - exact_components: tuple[complex, ...] - color_probe: tuple[complex, ...] | None - helicity_probe: tuple[complex, ...] - - -def _canonical_json(value: object) -> bytes: - try: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ).encode("utf-8") - except (TypeError, ValueError) as error: - raise GateError("evidence is not canonical JSON") from error - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_json(value)).hexdigest() - - -def _regular_file_identity( - path: Path, - *, - aggregate: Any | None = None, - tree_relative: bytes | None = None, -) -> tuple[int, str]: - """Hash one stable regular file through one no-follow descriptor.""" - - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_NOFOLLOW", 0) - | getattr(os, "O_BINARY", 0) - ) - digest = hashlib.sha256() - descriptor: int | None = None - try: - descriptor = os.open(path, flags) - before = os.fstat(descriptor) - if not stat.S_ISREG(before.st_mode): - raise GateError(f"identity target is not a regular file: {path}") - if aggregate is not None: - if tree_relative is None: - raise GateError("tree hashing requires a relative path") - aggregate.update(len(tree_relative).to_bytes(8, "big")) - aggregate.update(tree_relative) - aggregate.update(before.st_size.to_bytes(8, "big")) - byte_count = 0 - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - while block := stream.read(HASH_CHUNK_BYTES): - digest.update(block) - if aggregate is not None: - aggregate.update(block) - byte_count += len(block) - after = os.fstat(stream.fileno()) - except OSError as error: - raise GateError( - f"cannot hash regular file through a checked fd: {path}" - ) from error - finally: - if descriptor is not None: - os.close(descriptor) - stable_fields = ( - "st_dev", - "st_ino", - "st_mode", - "st_size", - "st_mtime_ns", - "st_ctime_ns", - ) - if byte_count != before.st_size or any( - getattr(before, name) != getattr(after, name) for name in stable_fields - ): - raise GateError(f"identity target changed while it was hashed: {path}") - return byte_count, digest.hexdigest() - - -def _sha256_file(path: Path) -> str: - return _regular_file_identity(path)[1] - - -def _file_identity(path: Path) -> dict[str, object]: - try: - resolved = path.expanduser().resolve(strict=True) - except OSError as error: - raise GateError(f"cannot identify file: {path}") from error - size, sha256 = _regular_file_identity(resolved) - return { - "path": str(resolved), - "size_bytes": size, - "sha256": sha256, - } - - -def _tree_identity(path: Path) -> dict[str, object]: - """Hash relative names, sizes, and contents for a relocatable tree ID.""" - - try: - root = path.expanduser().resolve(strict=True) - candidates = list(root.rglob("*")) - except OSError as error: - raise GateError(f"cannot inspect identity tree: {path}") from error - if not root.is_dir(): - raise GateError(f"identity target is not a directory: {root}") - for candidate in candidates: - if candidate.is_symlink(): - raise GateError( - f"identity tree contains an unsupported symlink: {candidate}" - ) - members = sorted( - (candidate for candidate in candidates if candidate.is_file()), - key=lambda candidate: candidate.relative_to(root).as_posix(), - ) - digest = hashlib.sha256() - size_bytes = 0 - try: - for member in members: - relative = member.relative_to(root).as_posix().encode("utf-8") - size, _ = _regular_file_identity( - member, - aggregate=digest, - tree_relative=relative, - ) - size_bytes += size - except OSError as error: - raise GateError(f"cannot hash identity tree: {root}") from error - return { - "algorithm": "sha256-relative-path-size-content-v1", - "sha256": digest.hexdigest(), - "file_count": len(members), - "size_bytes": size_bytes, - } - - -def _python_package_tree_identity(path: Path) -> dict[str, object]: - try: - return python_package_tree_identity(path) - except RuntimeEvidenceError as error: - raise GateError(str(error)) from error - - -def _ensure_source_only_python() -> None: - """Verify the stdlib-only bootstrap completed before repository imports.""" - - try: - source_only_bytecode_policy() - except RuntimeEvidenceError as error: - raise GateError( - "source-only Python bootstrap did not complete before gate imports" - ) from error - - -def _establish_preimport_runtime_identity() -> None: - native_root = next( - ( - candidate - for entry in sys.path - if (candidate := Path(entry) / "pyamplicol").is_dir() - and any( - path.name.startswith("_rusticol") - and path.name.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)) - for path in candidate.iterdir() - ) - ), - None, - ) - if native_root is None: - raise GateError("candidate Python path has no native pyamplicol package") - native = native_extension_in_package(native_root) - preimport_python_runtime_identity((native_root,), native_extension=native) - - -def _json_object(path: Path, *, label: str) -> dict[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise GateError(f"cannot read {label}: {path}") from error - if not isinstance(value, dict): - raise GateError(f"{label} must be a JSON object: {path}") - return value - - -def _mapping(value: object, *, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise GateError(f"{label} must be an object") - return value - - -def _sequence(value: object, *, label: str) -> Sequence[Any]: - if isinstance(value, (str, bytes)) or not isinstance(value, Sequence): - raise GateError(f"{label} must be an array") - return value - - -def _git_output(arguments: Sequence[str]) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=ROOT, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - detail = completed.stderr.strip() or completed.stdout.strip() - raise GateError(f"git {' '.join(arguments)} failed: {detail}") - return completed.stdout.strip() - - -def _source_identity() -> dict[str, object]: - revision = _git_output(("rev-parse", "--verify", "HEAD")) - if REVISION_PATTERN.fullmatch(revision) is None: - raise GateError("source checkout has no full Git revision") - status = _git_output(("status", "--porcelain=v1", "--untracked-files=all")) - if status: - raise GateError( - "source checkout is dirty; build and run the gate from one committed SHA" - ) - return { - "checkout": str(ROOT.resolve(strict=True)), - "revision": revision, - "dirty": False, - "untracked_files_checked": True, - } - - -def _runtime_identity(source: Mapping[str, object]) -> dict[str, object]: - try: - pyamplicol = importlib.import_module("pyamplicol") - native = importlib.import_module("pyamplicol._rusticol") - versions = importlib.import_module("pyamplicol._internal.versions") - except ImportError as error: - raise GateError( - "the candidate pyamplicol native runtime is unavailable" - ) from error - native_path_raw = getattr(native, "__file__", None) - if not isinstance(native_path_raw, str): - raise GateError("native extension has no filesystem path") - native_digest_function = getattr(native, "native_build_inputs_sha256", None) - if not callable(native_digest_function): - raise GateError("native extension exposes no build-input digest") - native_digest = native_digest_function() - if ( - not isinstance(native_digest, str) - or SHA256_PATTERN.fullmatch(native_digest) is None - ): - raise GateError("native extension build-input digest is invalid") - build_info_function = getattr(versions, "_active_build_info", None) - build_info = build_info_function() if callable(build_info_function) else None - if not isinstance(build_info, Mapping): - raise GateError("candidate exposes no strict build provenance") - if build_info.get("source_revision") != source.get("revision"): - raise GateError( - "candidate native runtime was built from another source revision" - ) - if build_info.get("native_build_inputs_sha256") != native_digest: - raise GateError("candidate build info and native build inputs disagree") - checkout = build_info.get("source_checkout") - if not isinstance(checkout, str): - raise GateError("candidate build info has no source checkout") - try: - bound_checkout = Path(checkout).expanduser().resolve(strict=True) - except OSError as error: - raise GateError("candidate source checkout is unavailable") from error - if bound_checkout != ROOT.resolve(strict=True): - raise GateError("candidate was built from another source checkout") - package_path_raw = getattr(pyamplicol, "__file__", None) - if not isinstance(package_path_raw, str): - raise GateError("pyamplicol package has no filesystem identity") - package_roots = tuple(Path(str(path)) for path in pyamplicol.__path__) - preimport_identity = established_preimport_runtime_identity() - return { - "interpreter": { - **_file_identity(Path(sys.executable)), - "python_version": platform.python_version(), - "implementation": platform.python_implementation(), - }, - "package": { - **_file_identity(Path(package_path_raw)), - "version": str(getattr(pyamplicol, "__version__", "")), - }, - "python_package_tree": _python_package_tree_identity(package_roots), - "loaded_module_origin_policy": loaded_pyamplicol_origin_policy( - package_roots, - native_extension=Path(native_path_raw), - expected_package_identity=preimport_identity["python_package_tree"], - expected_native_identity=preimport_identity["native_extension"], - ), - "native_extension": { - **_file_identity(Path(native_path_raw)), - "build_inputs_sha256": native_digest, - }, - "active_build_info": { - "payload": dict(build_info), - "canonical_sha256": _canonical_sha256(build_info), - }, - } - - -def _stable_runtime_identity(value: Mapping[str, object]) -> dict[str, object]: - """Exclude only the monotonically growing loaded-module observation set.""" - - stable = dict(value) - raw_policy = stable.get("loaded_module_origin_policy") - if isinstance(raw_policy, Mapping): - policy = dict(raw_policy) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - policy.pop(field, None) - stable["loaded_module_origin_policy"] = policy - return stable - - -def _runtime_identity_sha256(value: Mapping[str, object]) -> str: - return _canonical_sha256(_stable_runtime_identity(value)) - - -def _peak_rss_gib() -> float: - raw = float(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) - # Darwin reports bytes; Linux and the other supported Unix platforms use KiB. - divisor = float(1024**3 if platform.system() == "Darwin" else 1024**2) - return raw / divisor - - -def _generation_worker( - artifact: Path, - lane: Lane, - *, - expected_revision: str, - expected_runtime_sha256: str, - expected_script_sha256: str, -) -> dict[str, object]: - source = _source_identity() - if source["revision"] != expected_revision: - raise GateError("generation worker source revision changed") - runtime = _runtime_identity(source) - if _runtime_identity_sha256(runtime) != expected_runtime_sha256: - raise GateError("generation worker candidate runtime identity changed") - script = _file_identity(Path(__file__)) - if script["sha256"] != expected_script_sha256: - raise GateError("generation worker gate script identity changed") - - from pyamplicol import Generator - from pyamplicol.config import ( - ColorConfig, - EvaluatorConfig, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationValidationConfig, - JITConfig, - OutputConfig, - ProcessConfig, - RunConfig, - ) - - run = RunConfig( - action="generate", - process=ProcessConfig(max_quark_lines=MAX_QUARK_LINES), - color=ColorConfig( - accuracy=lane.color_accuracy, - lc_flow_layout=lane.lc_flow_layout, - ), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - validation=GenerationValidationConfig( - enabled=True, - samples=2, - seed=VALIDATION_SEED, - relative_tolerance=RELATIVE_TOLERANCE, - absolute_tolerance=ABSOLUTE_TOLERANCE, - post_build_validation=True, - ), - ), - evaluator=EvaluatorConfig( - backend="jit", - execution_mode="compiled", - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=3), - ), - output=OutputConfig(format="json", color="never", progress="off"), - ) - started_wall = time.monotonic() - started_cpu = time.process_time() - result = Generator(run).generate(PROCESS, artifact, mode="error") - elapsed_wall = time.monotonic() - started_wall - elapsed_cpu = time.process_time() - started_cpu - source_postflight = _source_identity() - runtime_postflight = _runtime_identity(source_postflight) - script_postflight = _file_identity(Path(__file__)) - if source_postflight != source: - raise GateError("generation worker source identity changed during generation") - if _stable_runtime_identity(runtime_postflight) != _stable_runtime_identity( - runtime - ): - raise GateError("generation worker runtime identity changed during generation") - if script_postflight != script: - raise GateError("generation worker script identity changed during generation") - return { - "lane": lane.name, - "artifact": str(result.output), - "worker_script": script, - "worker_provenance": { - "source_revision": source["revision"], - "runtime_identity_sha256": _runtime_identity_sha256(runtime), - "gate_script_sha256": script["sha256"], - "postflight_identity_match": True, - }, - "process_ids": [process.name for process in result.processes.requests], - "generation": { - "wall_seconds": elapsed_wall, - "process_cpu_seconds": elapsed_cpu, - "worker_peak_rss_gib": _peak_rss_gib(), - "workers": 1, - "validation_samples": 2, - "validation_seed": VALIDATION_SEED, - "post_build_validation": True, - }, - } - - -def _worker_command( - artifact: Path, - lane: Lane, - *, - expected_revision: str, - expected_runtime_sha256: str, - expected_script_sha256: str, -) -> tuple[str, ...]: - return ( - sys.executable, - "-I", - "-S", - "-B", - str(Path(__file__).resolve()), - "--_generate-one", - "--artifact", - str(artifact), - "--lane", - lane.name, - "--expected-revision", - expected_revision, - "--expected-runtime-sha256", - expected_runtime_sha256, - "--expected-script-sha256", - expected_script_sha256, - ) - - -def _invoke_generation_worker( - artifact: Path, - lane: Lane, - *, - timeout: float, - expected_revision: str, - expected_runtime_sha256: str, - expected_script_sha256: str, -) -> dict[str, object]: - command = _worker_command( - artifact, - lane, - expected_revision=expected_revision, - expected_runtime_sha256=expected_runtime_sha256, - expected_script_sha256=expected_script_sha256, - ) - started = time.monotonic() - try: - completed = subprocess.run( - command, - cwd=ROOT, - check=False, - capture_output=True, - text=True, - timeout=timeout, - ) - except subprocess.TimeoutExpired as error: - raise GateError( - f"{lane.name} generation exceeded {timeout:.1f} seconds" - ) from error - if completed.returncode != 0: - detail = completed.stderr.strip() or completed.stdout.strip() - raise GateError(f"{lane.name} generation failed:\n{detail[-6000:]}") - try: - payload = json.loads(completed.stdout) - except json.JSONDecodeError as error: - raise GateError(f"{lane.name} worker emitted invalid JSON") from error - if not isinstance(payload, dict) or payload.get("lane") != lane.name: - raise GateError(f"{lane.name} worker returned the wrong lane") - worker_script = _mapping( - payload.get("worker_script"), - label=f"{lane.name} worker script identity", - ) - if worker_script.get("sha256") != expected_script_sha256: - raise GateError(f"{lane.name} worker executed another gate script") - worker_provenance = _mapping( - payload.get("worker_provenance"), - label=f"{lane.name} worker provenance", - ) - if ( - worker_provenance.get("source_revision") != expected_revision - or worker_provenance.get("runtime_identity_sha256") != expected_runtime_sha256 - or worker_provenance.get("gate_script_sha256") != expected_script_sha256 - or worker_provenance.get("postflight_identity_match") is not True - ): - raise GateError(f"{lane.name} worker provenance drifted") - payload["orchestration_wall_seconds"] = time.monotonic() - started - payload["command"] = { - "argv": list(command), - "canonical_sha256": _canonical_sha256(list(command)), - } - if completed.stderr.strip(): - payload["worker_stderr_sha256"] = hashlib.sha256( - completed.stderr.encode() - ).hexdigest() - return payload - - -def _assert_union_rejections() -> list[dict[str, object]]: - from pyamplicol.config import ColorConfig, ConfigurationError - - result: list[dict[str, object]] = [] - for accuracy in ("nlc", "full"): - try: - ColorConfig(accuracy=accuracy, lc_flow_layout="all-flow-union") - except ConfigurationError as error: - message = str(error) - if "all-flow-union" not in message or "requires" not in message: - raise GateError( - f"{accuracy} union rejection was not actionable: {message}" - ) from error - result.append( - { - "color_accuracy": accuracy, - "lc_flow_layout": "all-flow-union", - "rejected": True, - "error_type": type(error).__name__, - "message": message, - } - ) - else: - raise GateError(f"{accuracy} all-flow-union did not fail closed") - return result - - -def _safe_relative_path(value: object, *, label: str) -> str: - if not isinstance(value, str) or not value: - raise GateError(f"{label} must be a non-empty path") - path = Path(value) - if path.is_absolute() or ".." in path.parts: - raise GateError(f"{label} must be artifact-relative") - return value - - -def _source_evaluator_leaves( - evaluator: Mapping[str, Any], - *, - label: str, -) -> list[Mapping[str, Any]]: - kind = evaluator.get("kind") - if kind == "symjit-application-evaluator": - return [evaluator] - if kind != "chunked-symbolica-evaluator": - raise GateError(f"{label} has unsupported evaluator kind {kind!r}") - chunks = _sequence(evaluator.get("chunks"), label=f"{label}.chunks") - if not chunks: - raise GateError(f"{label} has no evaluator leaves") - leaves: list[Mapping[str, Any]] = [] - for index, chunk in enumerate(chunks): - leaves.extend( - _source_evaluator_leaves( - _mapping(chunk, label=f"{label}.chunks[{index}]"), - label=f"{label}.chunks[{index}]", - ) - ) - return leaves - - -def _nonnegative_int(value: object, *, label: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"{label} must be a nonnegative integer") - return value - - -def _int_list(value: object, *, label: str) -> list[int]: - return [ - _nonnegative_int(item, label=f"{label}[{index}]") - for index, item in enumerate(_sequence(value, label=label)) - ] - - -def _authenticated_certificate( - value: object, - *, - label: str, -) -> Mapping[str, Any]: - certificate = _mapping(value, label=label) - digest = certificate.get("digest") - if not isinstance(digest, str) or SHA256_PATTERN.fullmatch(digest) is None: - raise GateError(f"{label}.digest is not a SHA-256") - subject = {name: item for name, item in certificate.items() if name != "digest"} - if _canonical_sha256(subject) != digest: - raise GateError(f"{label}.digest does not authenticate the certificate") - return certificate - - -def _audit_stage_order_certificate( - descriptor: Mapping[str, Any], - *, - stage: Mapping[str, Any], - label: str, -) -> dict[str, object]: - certificate = _authenticated_certificate( - descriptor.get("order_certificate"), - label=f"{label}.compiled_plane_arena.order_certificate", - ) - if certificate.get("kind") != "whole-current-canonical-order-v1": - raise GateError(f"{label} has an incompatible order certificate") - output_length = _nonnegative_int( - stage.get("output_length"), - label=f"{label}.output_length", - ) - slots = [ - _mapping(item, label=f"{label}.output_slots[{index}]") - for index, item in enumerate( - _sequence(stage.get("output_slots"), label=f"{label}.output_slots") - ) - ] - destinations = [ - _mapping(item, label=f"{label}.destinations[{index}]") - for index, item in enumerate( - _sequence( - certificate.get("destinations"), - label=f"{label}.order_certificate.destinations", - ) - ) - ] - if len(destinations) != len(slots): - raise GateError(f"{label} order certificate does not cover output slots") - is_amplitude = str(stage.get("stage_kind", "")).startswith("amplitude") - output_cursor = 0 - current_ids: list[int] = [] - residual_ranges: list[tuple[int, int]] = [] - table_owners: dict[int, tuple[int, int]] = {} - ordered_interactions: list[int] = [] - ordered_groups: list[int] = [] - for index, (destination, slot) in enumerate(zip(destinations, slots, strict=True)): - destination_label = f"{label}.order_certificate.destinations[{index}]" - output_start = _nonnegative_int( - destination.get("output_start"), - label=f"{destination_label}.output_start", - ) - output_stop = _nonnegative_int( - destination.get("output_stop"), - label=f"{destination_label}.output_stop", - ) - slot_start = _nonnegative_int( - slot.get("output_start"), - label=f"{label}.output_slots[{index}].output_start", - ) - slot_stop = _nonnegative_int( - slot.get("output_stop"), - label=f"{label}.output_slots[{index}].output_stop", - ) - expected_owner_kind = "amplitude" if is_amplitude else "current" - owner_id = _nonnegative_int( - destination.get("owner_id"), - label=f"{destination_label}.owner_id", - ) - if ( - destination.get("destination_id") != index - or destination.get("owner_kind") != expected_owner_kind - or output_start != output_cursor - or output_start >= output_stop - or output_stop > output_length - or (output_start, output_stop) != (slot_start, slot_stop) - ): - raise GateError(f"{destination_label} is not canonical") - if is_amplitude: - if slot.get("current_id") != -1: - raise GateError(f"{destination_label} misidentifies an amplitude") - else: - current_id = _nonnegative_int( - slot.get("current_id"), - label=f"{label}.output_slots[{index}].current_id", - ) - if owner_id != current_id or current_id in current_ids: - raise GateError(f"{destination_label} repeats a current") - current_ids.append(current_id) - interactions = _int_list( - destination.get("interaction_ids"), - label=f"{destination_label}.interaction_ids", - ) - groups = _int_list( - destination.get("evaluation_group_ids"), - label=f"{destination_label}.evaluation_group_ids", - ) - ordered_interactions.extend(interactions) - ordered_groups.extend(groups) - ownership = _mapping( - destination.get("ownership"), - label=f"{destination_label}.ownership", - ) - ownership_kind = ownership.get("kind") - if ownership_kind == "residual": - if set(ownership) != {"kind"}: - raise GateError(f"{destination_label} residual ownership is malformed") - residual_ranges.append((output_start, output_stop)) - elif ownership_kind == "table" and not is_amplitude: - if set(ownership) != {"kind", "island_id", "row_index"}: - raise GateError(f"{destination_label} table ownership is malformed") - island_id = _nonnegative_int( - ownership.get("island_id"), - label=f"{destination_label}.ownership.island_id", - ) - row_index = _nonnegative_int( - ownership.get("row_index"), - label=f"{destination_label}.ownership.row_index", - ) - table_owners[owner_id] = (island_id, row_index) - else: - raise GateError(f"{destination_label} has invalid ownership") - output_cursor = output_stop - if output_cursor != output_length: - raise GateError(f"{label} order certificate does not cover stage outputs") - if ( - _int_list( - certificate.get("current_ids"), - label=f"{label}.order_certificate.current_ids", - ) - != current_ids - ): - raise GateError(f"{label} order certificate current order is inconsistent") - source_interactions = _int_list( - certificate.get("source_stage_interaction_ids"), - label=f"{label}.order_certificate.source_stage_interaction_ids", - ) - stage_interactions = _int_list( - stage.get("interaction_ids"), - label=f"{label}.interaction_ids", - ) - execution_interactions = _int_list( - certificate.get("interaction_ids"), - label=f"{label}.order_certificate.interaction_ids", - ) - execution_groups = _int_list( - certificate.get("evaluation_group_ids"), - label=f"{label}.order_certificate.evaluation_group_ids", - ) - if ( - source_interactions != stage_interactions - or execution_interactions != ordered_interactions - or execution_groups != ordered_groups - or len(execution_interactions) != len(set(execution_interactions)) - or set(execution_interactions) != set(source_interactions) - ): - raise GateError(f"{label} order certificate changes contribution order") - return { - "destinations": destinations, - "residual_ranges": residual_ranges, - "table_owners": table_owners, - } - - -def _audit_direct_descriptor( - descriptor: Mapping[str, Any], - *, - stage: Mapping[str, Any], - label: str, -) -> dict[str, int]: - if descriptor.get("kind") != COMPILED_STAGE_PLAN_KIND: - raise GateError(f"{label}.compiled_plane_arena has the wrong kind") - if descriptor.get("schema_version") != COMPILED_STAGE_PLAN_SCHEMA_VERSION: - raise GateError(f"{label}.compiled_plane_arena has the wrong schema") - expected_scalars = { - "application_abi": COMPILED_PLANE_DIRECT_APPLICATION_ABI, - "source_application_abi": SYMJIT_PLANE_APPLICATION_ABI, - "element_layout": "split-complex-component-major", - "input_output_aliasing": "forbidden", - "output_output_aliasing": "forbidden", - "output_operation": "overwrite", - "output_factor": "identity", - } - for name, expected in expected_scalars.items(): - if descriptor.get(name) != expected: - raise GateError(f"{label}.compiled_plane_arena.{name} is not {expected!r}") - inputs = _sequence( - descriptor.get("input_bindings"), - label=f"{label}.compiled_plane_arena.input_bindings", - ) - input_indices = [ - _mapping(item, label=f"{label}.input_bindings[{index}]").get("parameter_index") - for index, item in enumerate(inputs) - ] - if input_indices != list(range(len(inputs))): - raise GateError(f"{label} Direct-Arena input bindings are not contiguous") - outputs = _sequence( - descriptor.get("output_bindings"), - label=f"{label}.compiled_plane_arena.output_bindings", - ) - output_indices = [ - _mapping(item, label=f"{label}.output_bindings[{index}]").get("output_index") - for index, item in enumerate(outputs) - ] - if output_indices != list(range(len(outputs))): - raise GateError(f"{label} Direct-Arena output bindings are not contiguous") - if len(outputs) != stage.get("output_length"): - raise GateError(f"{label} Direct-Arena outputs do not cover the stage") - order = _audit_stage_order_certificate( - descriptor, - stage=stage, - label=label, - ) - residual_ranges = list(order["residual_ranges"]) - table_owners = dict(order["table_owners"]) - - evaluator_raw = stage.get("evaluator") - source_leaves = ( - [] - if evaluator_raw is None - else _source_evaluator_leaves( - _mapping(evaluator_raw, label=f"{label}.evaluator"), - label=f"{label}.evaluator", - ) - ) - direct_leaves = list( - _sequence( - descriptor.get("residual_leaves"), - label=f"{label}.compiled_plane_arena.residual_leaves", - ) - ) - if len(direct_leaves) != len(source_leaves): - raise GateError(f"{label} residual/source leaf counts disagree") - residual_outputs: list[int] = [] - owned_residual_ranges: list[tuple[int, int]] = [] - for index, (direct_raw, source) in enumerate( - zip(direct_leaves, source_leaves, strict=True) - ): - direct = _mapping(direct_raw, label=f"{label}.residual_leaves[{index}]") - if ( - direct.get("kind") != COMPILED_RESIDUAL_LEAF_KIND - or direct.get("leaf_id") != index - ): - raise GateError(f"{label} residual leaf identity is incompatible") - if ( - source.get("application_abi") != SYMJIT_APPLICATION_ABI - or source.get("runtime_capability") != SYMJIT_RUNTIME_CAPABILITY - ): - raise GateError( - f"{label} ordinary SymJIT fallback leaf identity is inconsistent" - ) - _safe_relative_path( - source.get("application_path"), - label=f"{label}.source_leaves[{index}].application_path", - ) - plane = _mapping( - source.get("plane_application"), - label=f"{label}.source_leaves[{index}].plane_application", - ) - source_path = _safe_relative_path( - plane.get("application_path"), - label=( - f"{label}.source_leaves[{index}].plane_application.application_path" - ), - ) - if ( - direct.get("application_path") != source_path - or direct.get("source_application_abi") - != SYMJIT_PLANE_APPLICATION_ABI - or plane.get("application_abi") != SYMJIT_PLANE_APPLICATION_ABI - or plane.get("storage_abi") != SYMJIT_APPLICATION_ABI - or plane.get("translation_mode") - != "symbolica-structured-instructions" - or plane.get("direct_arena") is not True - or not isinstance(plane.get("source_digest"), str) - or SHA256_PATTERN.fullmatch(str(plane.get("source_digest"))) is None - ): - raise GateError(f"{label} Direct-Arena leaf identity is inconsistent") - if ( - direct.get("optimization_level") != 3 - or source.get("optimization_level") != 3 - or plane.get("optimization_level") != 3 - ): - raise GateError(f"{label} Direct-Arena leaf is not JIT O3") - if direct.get("direct_codegen_optimization_level") != 3: - raise GateError( - f"{label} Direct-Arena leaf direct codegen does not match its " - "plane application" - ) - indices = _sequence( - direct.get("input_indices"), - label=f"{label}.leaves[{index}].input_indices", - ) - if ( - any( - isinstance(value, bool) or not isinstance(value, int) or value < 0 - for value in indices - ) - or len(indices) != direct.get("input_len") - or len(indices) != source.get("input_len") - ): - raise GateError(f"{label} Direct-Arena leaf inputs are invalid") - output_len = _nonnegative_int( - direct.get("output_len"), - label=f"{label}.residual_leaves[{index}].output_len", - ) - direct_output_indices = _int_list( - direct.get("output_indices"), - label=f"{label}.residual_leaves[{index}].output_indices", - ) - if ( - output_len != source.get("output_len") - or len(direct_output_indices) != output_len - or len(direct_output_indices) != len(set(direct_output_indices)) - ): - raise GateError(f"{label} Direct-Arena leaf outputs are invalid") - leaf_ranges = [] - for range_index, raw_range in enumerate( - _sequence( - direct.get("output_ranges"), - label=f"{label}.residual_leaves[{index}].output_ranges", - ) - ): - output_range = _mapping( - raw_range, - label=( - f"{label}.residual_leaves[{index}].output_ranges[{range_index}]" - ), - ) - start = _nonnegative_int( - output_range.get("output_start"), - label=f"{label}.residual_range.output_start", - ) - stop = _nonnegative_int( - output_range.get("output_stop"), - label=f"{label}.residual_range.output_stop", - ) - if start >= stop: - raise GateError(f"{label} residual range is empty") - leaf_ranges.append((start, stop)) - expanded = [ - output for start, stop in leaf_ranges for output in range(start, stop) - ] - if expanded != direct_output_indices: - raise GateError(f"{label} residual leaf splits or reorders destinations") - residual_outputs.extend(direct_output_indices) - owned_residual_ranges.extend(leaf_ranges) - - declared_residual_ranges = [ - ( - _nonnegative_int( - _mapping(item, label=f"{label}.residual_output_ranges[{index}]").get( - "output_start" - ), - label=f"{label}.residual_output_ranges[{index}].output_start", - ), - _nonnegative_int( - _mapping(item, label=f"{label}.residual_output_ranges[{index}]").get( - "output_stop" - ), - label=f"{label}.residual_output_ranges[{index}].output_stop", - ), - ) - for index, item in enumerate( - _sequence( - descriptor.get("residual_output_ranges"), - label=f"{label}.compiled_plane_arena.residual_output_ranges", - ) - ) - ] - if ( - declared_residual_ranges != residual_ranges - or owned_residual_ranges != residual_ranges - or residual_outputs - != [output for start, stop in residual_ranges for output in range(start, stop)] - ): - raise GateError(f"{label} residual ownership is not exact") - - kernels = [ - _mapping(item, label=f"{label}.kernels[{index}]") - for index, item in enumerate( - _sequence( - descriptor.get("kernels"), - label=f"{label}.compiled_plane_arena.kernels", - ) - ) - ] - if len(kernels) > 8: - raise GateError(f"{label} exceeds eight DirectTable kernels") - for index, kernel in enumerate(kernels): - if ( - kernel.get("kernel_id") != index - or kernel.get("source_application_abi") - != SYMJIT_PLANE_APPLICATION_ABI - or kernel.get("application_abi") != COMPILED_PLANE_DIRECT_APPLICATION_ABI - or kernel.get("binding_abi") != COMPILED_DIRECT_TABLE_BINDING_ABI - or kernel.get("descriptor_abi") != COMPILED_DIRECT_TABLE_DESCRIPTOR_ABI - or kernel.get("optimization_level") != 3 - ): - raise GateError(f"{label} DirectTable kernel contract is incompatible") - for field in ( - "motif_digest", - "exact_source_digest", - "application_sha256", - "descriptor_sha256", - ): - value = kernel.get(field) - if not isinstance(value, str) or SHA256_PATTERN.fullmatch(value) is None: - raise GateError(f"{label}.kernels[{index}].{field} is invalid") - _safe_relative_path( - kernel.get("application_path"), - label=f"{label}.kernels[{index}].application_path", - ) - _safe_relative_path( - kernel.get("descriptor_path"), - label=f"{label}.kernels[{index}].descriptor_path", - ) - source_size = _nonnegative_int( - kernel.get("application_size_bytes"), - label=f"{label}.kernels[{index}].application_size_bytes", - ) - input_count = _nonnegative_int( - kernel.get("input_complex_count"), - label=f"{label}.kernels[{index}].input_complex_count", - ) - output_count = _nonnegative_int( - kernel.get("output_complex_count"), - label=f"{label}.kernels[{index}].output_complex_count", - ) - if ( - source_size == 0 - or source_size > 64 * 1024 - or not 1 <= input_count <= 16 - or not 1 <= output_count <= 2 - ): - raise GateError(f"{label} DirectTable kernel exceeds slice bounds") - - islands = [ - _mapping(item, label=f"{label}.islands[{index}]") - for index, item in enumerate( - _sequence( - descriptor.get("islands"), - label=f"{label}.compiled_plane_arena.islands", - ) - ) - ] - island_currents: dict[int, tuple[int, int]] = {} - invocation_count = 0 - attachment_count = 0 - for index, island in enumerate(islands): - kernel_id = _nonnegative_int( - island.get("kernel_id"), - label=f"{label}.islands[{index}].kernel_id", - ) - if island.get("island_id") != index or kernel_id >= len(kernels): - raise GateError(f"{label} DirectTable island identity is invalid") - current_ids = _int_list( - island.get("current_ids"), - label=f"{label}.islands[{index}].current_ids", - ) - if not current_ids or len(current_ids) != len(set(current_ids)): - raise GateError(f"{label} DirectTable island destinations are invalid") - invocations = [ - _mapping(item, label=f"{label}.islands[{index}].invocations[{row}]") - for row, item in enumerate( - _sequence( - island.get("invocation_rows"), - label=f"{label}.islands[{index}].invocation_rows", - ) - ) - ] - attachments = [ - _mapping(item, label=f"{label}.islands[{index}].attachments[{row}]") - for row, item in enumerate( - _sequence( - island.get("attachment_rows"), - label=f"{label}.islands[{index}].attachment_rows", - ) - ) - ] - if len(invocations) != len(current_ids) or len(attachments) != len(current_ids): - raise GateError(f"{label} DirectTable rows do not match destinations") - for row_index, invocation in enumerate(invocations): - if ( - invocation.get("attachment_start") != row_index - or invocation.get("attachment_count") != 1 - ): - raise GateError(f"{label} DirectTable attachment ranges are invalid") - owner = table_owners.get(current_ids[row_index]) - if owner != (index, row_index): - raise GateError(f"{label} table ownership certificate is inconsistent") - island_currents[current_ids[row_index]] = (index, row_index) - for attachment in attachments: - if attachment.get("operation") not in {"overwrite", "accumulate"}: - raise GateError(f"{label} DirectTable write operation is invalid") - dependency = _authenticated_certificate( - island.get("dependency_certificate"), - label=f"{label}.islands[{index}].dependency_certificate", - ) - if ( - dependency.get("kind") != "independent-whole-current-group-v1" - or _int_list( - dependency.get("current_ids"), - label=f"{label}.islands[{index}].dependency.current_ids", - ) - != current_ids - ): - raise GateError(f"{label} dependency certificate is incompatible") - rows = [ - _mapping(item, label=f"{label}.islands[{index}].dependency.rows[{row}]") - for row, item in enumerate( - _sequence( - dependency.get("rows"), - label=f"{label}.islands[{index}].dependency.rows", - ) - ) - ] - if len(rows) != len(current_ids): - raise GateError(f"{label} dependency certificate is incomplete") - grouped = set(current_ids) - for row_index, row in enumerate(rows): - predecessors = set( - _int_list( - row.get("predecessor_current_ids"), - label=f"{label}.islands[{index}].predecessors[{row_index}]", - ) - ) - if row.get("current_id") != current_ids[row_index] or ( - predecessors & grouped - ) - {current_ids[row_index]}: - raise GateError(f"{label} groups dependent current destinations") - invocation_count += len(invocations) - attachment_count += len(attachments) - if island_currents != table_owners: - raise GateError(f"{label} table ownership is not exhaustive") - if stage.get("stage_kind", "").startswith("amplitude") and islands: - raise GateError(f"{label} amplitude stage illegally contains table islands") - if evaluator_raw is None and (direct_leaves or not islands): - raise GateError(f"{label} evaluator omission is not a table-only stage") - - census = _mapping( - descriptor.get("census"), - label=f"{label}.compiled_plane_arena.census", - ) - expected_census = { - "stage_kernel_count": len(kernels), - "stage_island_count": len(islands), - "stage_invocation_count": invocation_count, - "stage_attachment_count": attachment_count, - "stage_residual_leaf_count": len(direct_leaves), - "stage_table_destination_count": len(table_owners), - "stage_residual_destination_count": len(residual_ranges), - } - if census.get("schema_version") != 1: - raise GateError(f"{label} compiled-stage census has the wrong schema") - for field, expected in expected_census.items(): - if census.get(field) != expected: - raise GateError(f"{label} compiled-stage census {field} is inconsistent") - return { - "leaf_count": len(direct_leaves), - "input_binding_count": len(inputs), - "output_binding_count": len(outputs), - "kernel_count": len(kernels), - "island_count": len(islands), - "invocation_count": invocation_count, - "attachment_count": attachment_count, - "residual_destination_count": len(residual_ranges), - "table_destination_count": len(table_owners), - } - - -def _assert_model_parameter_not_direct(value: object, *, label: str) -> None: - if isinstance(value, Mapping): - if value.get("kind") in { - "compiled-plane-arena-stage", - COMPILED_STAGE_PLAN_KIND, - }: - raise GateError( - f"{label} illegally uses a compiled plane DirectApplication" - ) - if "compiled_plane_arena" in value or "native_direct_application" in value: - raise GateError(f"{label} illegally carries DirectApplication metadata") - if value.get("application_abi") in { - COMPILED_PLANE_DIRECT_APPLICATION_ABI, - NATIVE_COMPILED_DIRECT_APPLICATION_ABI, - }: - raise GateError(f"{label} illegally uses the direct application ABI") - for name, child in value.items(): - _assert_model_parameter_not_direct(child, label=f"{label}.{name}") - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - _assert_model_parameter_not_direct(child, label=f"{label}[{index}]") - - -def _walk_mappings( - value: object, - *, - path: tuple[str, ...] = (), -) -> Iterable[tuple[tuple[str, ...], Mapping[str, Any]]]: - if isinstance(value, Mapping): - yield path, value - for name, child in value.items(): - yield from _walk_mappings(child, path=(*path, str(name))) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - yield from _walk_mappings(child, path=(*path, str(index))) - - -def _audit_execution_payload(payload: Mapping[str, Any]) -> dict[str, object]: - capability_declarations = 0 - stage_set_count = 0 - stage_count = 0 - descriptor_count = 0 - leaf_count = 0 - kernel_count = 0 - island_count = 0 - invocation_count = 0 - attachment_count = 0 - residual_destination_count = 0 - table_destination_count = 0 - model_parameter_slot_count = 0 - model_parameter_evaluator_count = 0 - for path, record in _walk_mappings(payload): - label = ".".join(path) or "execution" - capabilities = record.get("required_runtime_capabilities") - if ( - isinstance(capabilities, Sequence) - and not isinstance(capabilities, (str, bytes)) - and COMPILED_PLANE_ARENA_CAPABILITY in capabilities - ): - capability_declarations += 1 - if "model_parameter_evaluator" in record: - model_parameter_slot_count += 1 - model_parameters = record["model_parameter_evaluator"] - if model_parameters is not None: - model_parameter_evaluator_count += 1 - _assert_model_parameter_not_direct( - model_parameters, - label=f"{label}.model_parameter_evaluator", - ) - if record.get("kind") != "generic-dag-stage-evaluator-artifacts": - continue - stage_set_count += 1 - if record.get("runtime_available") is not True: - raise GateError(f"{label} compiled stage runtime is unavailable") - capabilities = _sequence( - record.get("required_runtime_capabilities"), - label=f"{label}.required_runtime_capabilities", - ) - if COMPILED_PLANE_ARENA_CAPABILITY not in capabilities: - raise GateError( - f"{label} does not require {COMPILED_PLANE_ARENA_CAPABILITY}" - ) - stages = list(_sequence(record.get("stages"), label=f"{label}.stages")) - amplitude = _mapping( - record.get("amplitude_stage"), - label=f"{label}.amplitude_stage", - ) - all_stages = (*stages, amplitude) - if record.get("stage_count") != len(all_stages): - raise GateError(f"{label}.stage_count does not cover all stages") - for index, raw_stage in enumerate(all_stages): - stage = _mapping(raw_stage, label=f"{label}.stages[{index}]") - descriptor = _mapping( - stage.get("compiled_plane_arena"), - label=f"{label}.stages[{index}].compiled_plane_arena", - ) - counts = _audit_direct_descriptor( - descriptor, - stage=stage, - label=f"{label}.stages[{index}]", - ) - stage_count += 1 - descriptor_count += 1 - leaf_count += counts["leaf_count"] - kernel_count += counts["kernel_count"] - island_count += counts["island_count"] - invocation_count += counts["invocation_count"] - attachment_count += counts["attachment_count"] - residual_destination_count += counts["residual_destination_count"] - table_destination_count += counts["table_destination_count"] - if capability_declarations < 1: - raise GateError( - f"execution payload does not declare {COMPILED_PLANE_ARENA_CAPABILITY}" - ) - if stage_set_count < 1 or descriptor_count < 1 or leaf_count < 1: - raise GateError("execution payload has no complete Direct-Arena stage set") - if model_parameter_slot_count < 1: - raise GateError("execution payload has no model-parameter evaluator slot") - return { - "capability": COMPILED_PLANE_ARENA_CAPABILITY, - "capability_declaration_count": capability_declarations, - "stage_set_count": stage_set_count, - "stage_count": stage_count, - "descriptor_count": descriptor_count, - "leaf_count": leaf_count, - "kernel_count": kernel_count, - "island_count": island_count, - "invocation_count": invocation_count, - "attachment_count": attachment_count, - "residual_destination_count": residual_destination_count, - "table_destination_count": table_destination_count, - "model_parameter_slot_count": model_parameter_slot_count, - "model_parameter_evaluator_count": model_parameter_evaluator_count, - "model_parameter_direct_application_count": 0, - "passes": True, - } - - -def _artifact_identity_and_audit( - artifact: Path, - lane: Lane, -) -> tuple[dict[str, object], str]: - manifest_path = artifact / "artifact.json" - manifest = _json_object(manifest_path, label="artifact manifest") - artifact_id = manifest.get("artifact_id") - if ( - not isinstance(artifact_id, str) - or SHA256_PATTERN.fullmatch(artifact_id) is None - ): - raise GateError(f"{lane.name} artifact ID is invalid") - processes = _sequence(manifest.get("processes"), label="artifact.processes") - if len(processes) != 1: - raise GateError(f"{lane.name} artifact must contain exactly one process") - process = _mapping(processes[0], label="artifact.processes[0]") - if process.get("expression") != PROCESS: - raise GateError(f"{lane.name} artifact contains the wrong process") - if sorted(process.get("external_pdgs", ())) != list(EXPECTED_EXTERNAL_PDGS): - raise GateError(f"{lane.name} does not contain four quark/antiquark pairs") - if process.get("color_accuracy") != lane.color_accuracy: - raise GateError(f"{lane.name} artifact color accuracy is wrong") - capabilities = _sequence( - process.get("required_runtime_capabilities"), - label="artifact.processes[0].required_runtime_capabilities", - ) - if COMPILED_PLANE_ARENA_CAPABILITY not in capabilities: - raise GateError(f"{lane.name} artifact lacks {COMPILED_PLANE_ARENA_CAPABILITY}") - process_id = process.get("id") - if not isinstance(process_id, str) or not process_id: - raise GateError(f"{lane.name} artifact process ID is invalid") - - generation = _mapping( - _mapping(manifest.get("extensions"), label="artifact.extensions").get( - "generation" - ), - label="artifact.extensions.generation", - ) - concrete = _sequence( - generation.get("concrete_processes"), - label="artifact.extensions.generation.concrete_processes", - ) - if len(concrete) != 1: - raise GateError(f"{lane.name} generation metadata is ambiguous") - filters = _mapping( - _mapping(concrete[0], label="concrete process").get("filters"), - label="concrete process filters", - ) - if lane.color_accuracy == "lc": - if filters.get("lc_flow_layout") != lane.lc_flow_layout: - raise GateError(f"{lane.name} generation layout metadata is wrong") - elif "lc_flow_layout" in filters: - raise GateError( - f"{lane.name} generation metadata illegally carries an LC layout" - ) - - try: - effective = tomllib.loads( - (artifact / "config" / "effective.toml").read_text(encoding="utf-8") - ) - except (OSError, tomllib.TOMLDecodeError) as error: - raise GateError(f"{lane.name} effective configuration is invalid") from error - expected_config = ( - (effective.get("process", {}).get("max_quark_lines"), MAX_QUARK_LINES), - (effective.get("color", {}).get("accuracy"), lane.color_accuracy), - (effective.get("color", {}).get("lc_flow_layout"), lane.lc_flow_layout), - (effective.get("evaluator", {}).get("backend"), "jit"), - (effective.get("evaluator", {}).get("execution_mode"), "compiled"), - ( - effective.get("evaluator", {}).get("jit", {}).get("optimization_level"), - 3, - ), - ) - if any(observed != expected for observed, expected in expected_config): - raise GateError(f"{lane.name} effective compiled/JIT/O3 configuration drifted") - - payloads = _sequence(manifest.get("payloads"), label="artifact.payloads") - payload_bytes = 0 - for index, raw_payload in enumerate(payloads): - payload = _mapping(raw_payload, label=f"artifact.payloads[{index}]") - relative = _safe_relative_path( - payload.get("path"), - label=f"artifact.payloads[{index}].path", - ) - expected_size = payload.get("size_bytes") - expected_digest = payload.get("sha256") - path = artifact / relative - try: - size = path.stat().st_size - except OSError as error: - raise GateError(f"{lane.name} payload is missing: {relative}") from error - if ( - isinstance(expected_size, bool) - or not isinstance(expected_size, int) - or size != expected_size - or not isinstance(expected_digest, str) - or _sha256_file(path) != expected_digest - ): - raise GateError(f"{lane.name} payload identity failed: {relative}") - payload_bytes += size - - execution_path = artifact / "processes" / process_id / "execution.json" - execution = _json_object(execution_path, label="process execution") - if execution.get("color_accuracy") != lane.color_accuracy: - raise GateError(f"{lane.name} execution color accuracy is wrong") - arena_audit = _audit_execution_payload(execution) - identity = { - "path": str(artifact.resolve(strict=True)), - "artifact_id": artifact_id, - "manifest": _file_identity(manifest_path), - "tree": _tree_identity(artifact), - "payload_count": len(payloads), - "payload_bytes": payload_bytes, - "effective_configuration": { - "max_quark_lines": MAX_QUARK_LINES, - "color_accuracy": lane.color_accuracy, - "lc_flow_layout": lane.lc_flow_layout, - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": 3, - }, - "direct_arena_audit": arena_audit, - } - return identity, process_id - - -def _deterministic_points(count: int) -> tuple[tuple[tuple[float, ...], ...], ...]: - from pyamplicol.generation.phase_space import massive_rambo_final_state - - if count not in (2, 3): - raise GateError("the numerical gate requires exactly two or three points") - incoming = ( - (SQRT_S / 2.0, 0.0, 0.0, SQRT_S / 2.0), - (SQRT_S / 2.0, 0.0, 0.0, -SQRT_S / 2.0), - ) - return tuple( - ( - *incoming, - *massive_rambo_final_state( - 6, - sqrt_s=SQRT_S, - masses=(0.0,) * 6, - seed=seed, - ), - ) - for seed in POINT_SEEDS[:count] - ) - - -def _as_complex(value: object) -> complex: - try: - result = complex(value) - except (TypeError, ValueError, OverflowError) as error: - raise GateError( - f"evaluation returned a non-numeric value: {value!r}" - ) from error - if not math.isfinite(result.real) or not math.isfinite(result.imag): - raise GateError("evaluation returned a non-finite value") - return result - - -def _flatten_resolved(resolved: object) -> tuple[complex, ...]: - return tuple( - _as_complex(value) - for point in resolved.values - for helicity in point - for value in helicity - ) - - -def _resolved_value_digest(resolved: object) -> str: - return _canonical_sha256( - [ - [[str(value) for value in helicity] for helicity in point] - for point in resolved.values - ] - ) - - -def _points_identity( - points: Sequence[Sequence[Sequence[float]]], -) -> dict[str, object]: - hexadecimal = [ - [[float(component).hex() for component in momentum] for momentum in point] - for point in points - ] - maximum_conservation_residual = 0.0 - maximum_mass_squared = 0.0 - for point in points: - incoming = point[:2] - outgoing = point[2:] - for component in range(4): - residual = sum(momentum[component] for momentum in incoming) - sum( - momentum[component] for momentum in outgoing - ) - maximum_conservation_residual = max( - maximum_conservation_residual, - float(abs(residual)), - ) - for momentum in point: - mass_squared = momentum[0] ** 2 - sum(value**2 for value in momentum[1:]) - maximum_mass_squared = max( - maximum_mass_squared, - float(abs(mass_squared)), - ) - if maximum_conservation_residual > 1.0e-9 or maximum_mass_squared > 1.0e-8: - raise GateError("deterministic validation momenta are not physical") - return { - "algorithm": "sha256-float-hex-momenta-v1", - "sha256": _canonical_sha256(hexadecimal), - "point_count": len(points), - "external_particle_count": len(points[0]) if points else 0, - "maximum_momentum_conservation_residual": maximum_conservation_residual, - "maximum_abs_mass_squared": maximum_mass_squared, - } - - -def _comparison( - left: Sequence[complex], - right: Sequence[complex], - *, - label: str, -) -> dict[str, object]: - if len(left) != len(right) or not left: - raise GateError(f"{label} vectors have incompatible or empty shapes") - maximum_absolute = 0.0 - maximum_relative = 0.0 - failing = 0 - for left_value, right_value in zip(left, right, strict=True): - absolute = abs(left_value - right_value) - relative = absolute / max(abs(left_value), abs(right_value), ABSOLUTE_TOLERANCE) - maximum_absolute = max(maximum_absolute, absolute) - maximum_relative = max(maximum_relative, relative) - if absolute > ABSOLUTE_TOLERANCE and relative > RELATIVE_TOLERANCE: - failing += 1 - result = { - "label": label, - "value_count": len(left), - "maximum_absolute_difference": maximum_absolute, - "maximum_relative_difference": maximum_relative, - "relative_tolerance": RELATIVE_TOLERANCE, - "absolute_tolerance": ABSOLUTE_TOLERANCE, - "failing_value_count": failing, - "passes": failing == 0, - } - if failing: - raise GateError( - f"{label} failed for {failing}/{len(left)} values " - f"(max relative {maximum_relative:.3e})" - ) - return result - - -def _complex_vector_digest(values: Sequence[complex]) -> str: - return _canonical_sha256([[value.real.hex(), value.imag.hex()] for value in values]) - - -def _physics_axes(physics: object) -> dict[str, object]: - return { - "process_id": physics.process_id, - "process": physics.process, - "color_accuracy": physics.color_accuracy, - "external_pdgs": [particle.pdg_id for particle in physics.external_particles], - "helicities": [ - { - "id": item.id, - "values": list(item.values), - "computed": item.computed, - "representative_id": item.representative_id, - "coefficient": item.coefficient, - } - for item in physics.helicities - ], - "color_flows": [ - { - "id": item.id, - "word": list(item.word), - "computed": item.computed, - "representative_id": item.representative_id, - "coefficient": item.coefficient, - } - for item in physics.color_flows - ], - "contracted_color_ids": [ - item.id for item in physics.contracted_color_components - ], - "selector_capabilities": list(physics.selector_capabilities), - "reduction_kind": physics.reduction.kind, - } - - -def _select_helicity_probe(physics: Any, *, lane_name: str) -> tuple[Any, int]: - eligible = tuple( - helicity - for helicity in physics.helicities - if helicity.computed - and not helicity.structural_zero - and helicity.coefficient != 0.0 - and helicity.representative_id == helicity.id - ) - if not eligible: - raise GateError(f"{lane_name} has no executable helicity selector probe") - return eligible[len(eligible) // 2], len(eligible) - - -def _evaluate_artifact( - artifact: Path, - *, - process_id: str, - lane: Lane, - points: tuple[tuple[tuple[float, ...], ...], ...], -) -> tuple[dict[str, object], EvaluationCapture]: - from pyamplicol import Runtime - - runtime = Runtime.load(artifact, process=process_id) - if runtime.execution_mode != "compiled": - raise GateError(f"{lane.name} runtime did not load the compiled lane") - if runtime.artifact_id != _json_object( - artifact / "artifact.json", label="artifact manifest" - ).get("artifact_id"): - raise GateError(f"{lane.name} native runtime authenticated another artifact") - physics = runtime.physics - observed_pdgs = sorted(particle.pdg_id for particle in physics.external_particles) - if observed_pdgs != list(EXPECTED_EXTERNAL_PDGS): - raise GateError(f"{lane.name} runtime does not expose four quark lines") - if physics.color_accuracy != lane.color_accuracy: - raise GateError(f"{lane.name} runtime color accuracy is wrong") - if lane.contracted: - if ( - physics.color_flows - or len(physics.contracted_color_components) != 1 - or physics.reduction.kind != "contracted-color" - ): - raise GateError(f"{lane.name} did not expose contracted color") - elif ( - not physics.color_flows - or physics.contracted_color_components - or physics.reduction.kind != "lc-diagonal" - ): - raise GateError(f"{lane.name} did not expose physical LC flows") - - direct_profiles = { - "complete": _profile_compiled_runtime(runtime, points), - } - f64_total = tuple(_as_complex(value) for value in runtime.evaluate(points)) - exact_total_raw = runtime.evaluate(points, precision=32) - exact_total = tuple(_as_complex(value) for value in exact_total_raw) - f64_resolved = runtime.evaluate_resolved(points) - exact_resolved = runtime.evaluate_resolved(points, precision=32) - if ( - tuple(f64_resolved.helicity_ids) != physics.helicity_ids - or tuple(exact_resolved.helicity_ids) != physics.helicity_ids - or tuple(f64_resolved.color_ids) != physics.color_ids - or tuple(exact_resolved.color_ids) != physics.color_ids - ): - raise GateError(f"{lane.name} resolved physical axes drifted") - f64_components = _flatten_resolved(f64_resolved) - exact_components = _flatten_resolved(exact_resolved) - f64_resolved_total = tuple(_as_complex(value) for value in f64_resolved.total()) - exact_resolved_total = tuple(_as_complex(value) for value in exact_resolved.total()) - - comparisons = { - "f64_vs_precision32_total": _comparison( - f64_total, exact_total, label=f"{lane.name} f64/precision32 totals" - ), - "f64_vs_precision32_components": _comparison( - f64_components, - exact_components, - label=f"{lane.name} f64/precision32 resolved components", - ), - "f64_evaluate_vs_resolved_total": _comparison( - f64_total, - f64_resolved_total, - label=f"{lane.name} f64 evaluate/resolved total", - ), - "precision32_evaluate_vs_resolved_total": _comparison( - exact_total, - exact_resolved_total, - label=f"{lane.name} precision32 evaluate/resolved total", - ), - } - - helicity, eligible_helicity_count = _select_helicity_probe( - physics, lane_name=lane.name - ) - helicity_id = helicity.id - helicity_probe = tuple( - _as_complex(value) - for value in runtime.evaluate(points, helicities=(helicity_id,)) - ) - helicity_resolved = runtime.evaluate_resolved(points, helicities=(helicity_id,)) - comparisons["helicity_selector_evaluate_vs_resolved_total"] = _comparison( - helicity_probe, - tuple(_as_complex(value) for value in helicity_resolved.total()), - label=f"{lane.name} helicity selector evaluate/resolved total", - ) - direct_profiles["helicity_selector"] = _profile_compiled_runtime( - runtime, - points, - helicities=(helicity_id,), - ) - color_id: str | None = None - color_probe: tuple[complex, ...] | None = None - if physics.color_flow_ids: - color_id = physics.color_flow_ids[len(physics.color_flow_ids) // 2] - color_probe = tuple( - _as_complex(value) - for value in runtime.evaluate(points, color_flows=(color_id,)) - ) - color_resolved = runtime.evaluate_resolved(points, color_flows=(color_id,)) - comparisons["color_selector_evaluate_vs_resolved_total"] = _comparison( - color_probe, - tuple(_as_complex(value) for value in color_resolved.total()), - label=f"{lane.name} color selector evaluate/resolved total", - ) - direct_profiles["color_selector"] = _profile_compiled_runtime( - runtime, - points, - color_flows=(color_id,), - ) - direct_profiles["combined_selector"] = _profile_compiled_runtime( - runtime, - points, - helicities=(helicity_id,), - color_flows=(color_id,), - ) - - axes = _physics_axes(physics) - capture = EvaluationCapture( - physics_axes=axes, - f64_total=f64_total, - exact_total=exact_total, - f64_components=f64_components, - exact_components=exact_components, - color_probe=color_probe, - helicity_probe=helicity_probe, - ) - evidence = { - "point_count": len(points), - "point_seeds": list(POINT_SEEDS[: len(points)]), - "sqrt_s": SQRT_S, - "physics_axes": { - **axes, - "canonical_sha256": _canonical_sha256(axes), - }, - "f64_total": [[value.real, value.imag] for value in f64_total], - "precision32_total_decimal": [str(value) for value in exact_total_raw], - "resolved": { - "shape": list(f64_resolved.shape), - "component_count": len(f64_components), - "f64_component_digest": _complex_vector_digest(f64_components), - "precision32_component_decimal_digest": _resolved_value_digest( - exact_resolved - ), - "precision32_decimal_digits": 32, - }, - "selector_probes": { - "helicity_id": helicity_id, - "helicity": { - "id": helicity.id, - "index": helicity.index, - "values": list(helicity.values), - "computed": helicity.computed, - "structural_zero": helicity.structural_zero, - "representative_id": helicity.representative_id, - "coefficient": helicity.coefficient, - }, - "eligible_helicity_count": eligible_helicity_count, - "color_flow_id": color_id, - }, - "runtime_execution": { - "execution_mode": runtime.execution_mode, - "direct_arena_profiles": direct_profiles, - }, - "comparisons": comparisons, - "finite_value_count": ( - len(f64_total) - + len(exact_total) - + len(f64_components) - + len(exact_components) - + len(helicity_probe) - + (0 if color_probe is None else len(color_probe)) - ), - "passes": True, - } - return evidence, capture - - -def _profile_compiled_runtime( - runtime: object, - points: object, - *, - helicities: tuple[str, ...] | None = None, - color_flows: tuple[str, ...] | None = None, -) -> dict[str, object]: - profiler = getattr(runtime, "profile", None) - surface = "Runtime.profile" - if not callable(profiler): - backend = getattr(runtime, "_backend", None) - profiler = getattr(backend, "profile", None) - surface = "native runtime adapter profile" - if not callable(profiler): - raise GateError( - "installed public/runtime-adapter API exposes no profiler; " - "compiled Direct-Arena activity cannot be proven" - ) - payload = profiler( - points, - helicities=helicities, - color_flows=color_flows, - precision=16, - include_values=False, - ) - return { - **_audit_compiled_direct_profile(payload), - "surface": surface, - "helicity_selector_count": 0 if helicities is None else len(helicities), - "color_selector_count": 0 if color_flows is None else len(color_flows), - } - - -def _audit_compiled_direct_profile(profile: object) -> dict[str, object]: - """Require observed Direct-Arena work and no legacy evaluator boundaries.""" - - payload = _mapping(profile, label="compiled runtime profile") - if payload.get("execution_mode") != "compiled": - raise GateError("compiled runtime profile reports another execution mode") - engines = payload.get("compiled_direct_arena_engine_count") - if isinstance(engines, bool) or not isinstance(engines, int) or engines <= 0: - raise GateError("compiled Direct-Arena profile observed no Arena engines") - calls = payload.get("compiled_direct_arena_call_count") - if isinstance(calls, bool) or not isinstance(calls, int) or calls <= 0: - raise GateError("compiled Direct-Arena profile observed no backend calls") - backend_calls = payload.get("evaluator_backend_call_count") - if ( - isinstance(backend_calls, bool) - or not isinstance(backend_calls, int) - or backend_calls <= 0 - or backend_calls != calls - ): - raise GateError( - "compiled Direct-Arena calls do not cover every evaluator backend call" - ) - boundary_counts: dict[str, int] = {} - for field in _ZERO_PROFILE_COUNTERS: - value = payload.get(field) - if isinstance(value, bool) or not isinstance(value, int) or value != 0: - raise GateError( - "compiled Direct-Arena profile observed legacy boundary traffic: " - f"{field}={value!r}" - ) - boundary_counts[field] = value - boundary_times: dict[str, float] = {} - for field in _ZERO_PROFILE_TIMES: - value = payload.get(field) - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or float(value) != 0.0 - ): - raise GateError( - "compiled Direct-Arena profile observed legacy boundary timing: " - f"{field}={value!r}" - ) - boundary_times[field] = float(value) - return { - "compiled_direct_arena_engine_count": engines, - "compiled_direct_arena_call_count": calls, - "evaluator_backend_call_count": backend_calls, - "legacy_boundary_component_counts": boundary_counts, - "legacy_boundary_component_total": sum(boundary_counts.values()), - "legacy_boundary_times_seconds": boundary_times, - "passes": True, - } - - -def _cross_lc_parity( - topology: EvaluationCapture, - union: EvaluationCapture, -) -> dict[str, object]: - axes_match = topology.physics_axes == union.physics_axes - if not axes_match: - raise GateError("LC topology-replay and union physical axes differ") - if topology.color_probe is None or union.color_probe is None: - raise GateError("LC selector comparison has no physical color probe") - comparisons = { - "f64_totals": _comparison( - topology.f64_total, - union.f64_total, - label="LC topology/union f64 totals", - ), - "precision32_totals": _comparison( - topology.exact_total, - union.exact_total, - label="LC topology/union precision32 totals", - ), - "f64_resolved_components": _comparison( - topology.f64_components, - union.f64_components, - label="LC topology/union f64 resolved components", - ), - "precision32_resolved_components": _comparison( - topology.exact_components, - union.exact_components, - label="LC topology/union precision32 resolved components", - ), - "color_selector": _comparison( - topology.color_probe, - union.color_probe, - label="LC topology/union color selector", - ), - "helicity_selector": _comparison( - topology.helicity_probe, - union.helicity_probe, - label="LC topology/union helicity selector", - ), - } - return { - "physical_axes_match": axes_match, - "physical_axes_sha256": _canonical_sha256(topology.physics_axes), - "comparisons": comparisons, - "passes": True, - } - - -def _attach_content_identity(body: Mapping[str, object]) -> dict[str, object]: - result = dict(body) - result["content_identity"] = { - "algorithm": "sha256-canonical-json-body-v1", - "sha256": _canonical_sha256(body), - } - return result - - -def _write_json_atomic(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp") - encoded = json.dumps( - payload, - allow_nan=False, - ensure_ascii=False, - indent=2, - sort_keys=True, - ) - try: - temporary.write_text(encoded + "\n", encoding="utf-8") - temporary.replace(path) - except OSError as error: - temporary.unlink(missing_ok=True) - raise GateError(f"cannot write evidence: {path}") from error - - -def _prepare_output_root(output_root: Path, *, replace: bool) -> Path: - root = output_root.expanduser().resolve(strict=False) - if root == ROOT or root == Path(root.anchor): - raise GateError("refusing a broad output root") - if root.exists(): - if not root.is_dir(): - raise GateError(f"output root is not a directory: {root}") - occupied = [lane for lane in LANES if (root / lane.name).exists()] - if occupied and not replace: - names = ", ".join(lane.name for lane in occupied) - raise GateError(f"artifact lanes already exist ({names}); pass --replace") - if replace: - for lane in LANES: - target = root / lane.name - if target.exists(): - shutil.rmtree(target) - root.mkdir(parents=True, exist_ok=True) - return root - - -def run_gate(arguments: argparse.Namespace) -> dict[str, object]: - source = _source_identity() - runtime = _runtime_identity(source) - script = _file_identity(Path(__file__)) - runtime_sha256 = _runtime_identity_sha256(runtime) - union_rejections = _assert_union_rejections() - output_root = _prepare_output_root( - arguments.output_root, - replace=arguments.replace, - ) - points = _deterministic_points(arguments.points) - points_identity = _points_identity(points) - lanes: dict[str, dict[str, object]] = {} - captures: dict[str, EvaluationCapture] = {} - failures: list[dict[str, str]] = [] - started = time.monotonic() - for lane in LANES: - artifact = output_root / lane.name - try: - generation = _invoke_generation_worker( - artifact, - lane, - timeout=arguments.generation_timeout, - expected_revision=str(source["revision"]), - expected_runtime_sha256=runtime_sha256, - expected_script_sha256=str(script["sha256"]), - ) - identity, process_id = _artifact_identity_and_audit(artifact, lane) - numerical, capture = _evaluate_artifact( - artifact, - process_id=process_id, - lane=lane, - points=points, - ) - lanes[lane.name] = { - "configuration": { - "process": PROCESS, - "max_quark_lines": MAX_QUARK_LINES, - "color_accuracy": lane.color_accuracy, - "lc_flow_layout": lane.lc_flow_layout, - "contracted_color": lane.contracted, - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": 3, - }, - "generation": generation, - "artifact_identity": identity, - "numerical_validation": numerical, - "passes": True, - } - captures[lane.name] = capture - except (GateError, OSError, RuntimeError, ValueError) as error: - failures.append( - { - "lane": lane.name, - "error_type": type(error).__name__, - "message": str(error), - } - ) - lanes[lane.name] = { - "configuration": { - "process": PROCESS, - "max_quark_lines": MAX_QUARK_LINES, - "color_accuracy": lane.color_accuracy, - "lc_flow_layout": lane.lc_flow_layout, - "contracted_color": lane.contracted, - "backend": "jit", - "execution_mode": "compiled", - "jit_optimization_level": 3, - }, - "passes": False, - } - cross_lc: dict[str, object] | None = None - if {"lc-topology-replay", "lc-all-flow-union"} <= captures.keys(): - try: - cross_lc = _cross_lc_parity( - captures["lc-topology-replay"], - captures["lc-all-flow-union"], - ) - except GateError as error: - failures.append( - { - "lane": "lc-cross-layout", - "error_type": type(error).__name__, - "message": str(error), - } - ) - cross_lc = {"passes": False, "message": str(error)} - else: - cross_lc = { - "passes": False, - "message": "both LC captures are required", - } - source_postflight = _source_identity() - runtime_postflight = _runtime_identity(source_postflight) - script_postflight = _file_identity(Path(__file__)) - if source_postflight != source: - raise GateError("source identity changed during the four-quark gate") - if _stable_runtime_identity(runtime_postflight) != _stable_runtime_identity( - runtime - ): - raise GateError("candidate runtime identity changed during the four-quark gate") - if script_postflight != script: - raise GateError("gate script identity changed during the four-quark gate") - passed = ( - not failures - and all(lane.get("passes") is True for lane in lanes.values()) - and cross_lc.get("passes") is True - ) - body = { - "kind": RESULT_KIND, - "schema_version": SCHEMA_VERSION, - "status": "ok" if passed else "validation_failed", - "passes": passed, - "request": { - "process": PROCESS, - "independent_quark_line_count": 4, - "expected_external_pdgs": list(EXPECTED_EXTERNAL_PDGS), - "max_quark_lines": MAX_QUARK_LINES, - "point_count": arguments.points, - "point_seeds": list(POINT_SEEDS[: arguments.points]), - "momenta_identity": points_identity, - "relative_tolerance": RELATIVE_TOLERANCE, - "absolute_tolerance": ABSOLUTE_TOLERANCE, - "mandatory_watchdog_command": WATCHDOG_INVOCATION, - "memory_limit_gib": 30, - }, - "source_identity": source, - "source_identity_postflight": source_postflight, - "source_identity_match": True, - "runtime_identity": runtime, - "runtime_identity_postflight": runtime_postflight, - "runtime_identity_match": True, - "gate_script_identity": script, - "gate_script_identity_postflight": script_postflight, - "gate_script_identity_match": True, - "invalid_union_configurations": union_rejections, - "lanes": lanes, - "lc_cross_layout_parity": cross_lc, - "resources": { - "orchestration_wall_seconds": time.monotonic() - started, - "orchestrator_peak_rss_gib": _peak_rss_gib(), - "mandatory_process_tree_limit_gib": 30, - }, - "failures": failures, - } - return _attach_content_identity(body) - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser( - description=__doc__, - epilog=f"Mandatory invocation: {WATCHDOG_INVOCATION}", - ) - result.add_argument("--output-root", type=Path) - result.add_argument( - "--evidence", - type=Path, - help="default: OUTPUT_ROOT/four-quark-compiled-gate.json", - ) - result.add_argument( - "--points", - type=int, - choices=(2, 3), - default=2, - help="number of deterministic physical points (default: 2)", - ) - result.add_argument( - "--generation-timeout", - type=float, - default=10_800.0, - help="per-lane generation timeout in seconds", - ) - result.add_argument( - "--replace", - action="store_true", - help="remove only the four named lane directories before generation", - ) - result.add_argument("--_generate-one", action="store_true", help=argparse.SUPPRESS) - result.add_argument("--artifact", type=Path, help=argparse.SUPPRESS) - result.add_argument( - "--lane", - choices=tuple(lane.name for lane in LANES), - help=argparse.SUPPRESS, - ) - result.add_argument( - "--expected-script-sha256", - help=argparse.SUPPRESS, - ) - result.add_argument("--expected-revision", help=argparse.SUPPRESS) - result.add_argument("--expected-runtime-sha256", help=argparse.SUPPRESS) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - _establish_preimport_runtime_identity() - if arguments._generate_one: - if arguments.artifact is None or arguments.lane is None: - parser().error("--_generate-one requires --artifact and --lane") - if ( - not isinstance(arguments.expected_script_sha256, str) - or SHA256_PATTERN.fullmatch(arguments.expected_script_sha256) is None - or not isinstance(arguments.expected_revision, str) - or REVISION_PATTERN.fullmatch(arguments.expected_revision) is None - or not isinstance(arguments.expected_runtime_sha256, str) - or SHA256_PATTERN.fullmatch(arguments.expected_runtime_sha256) is None - ): - parser().error( - "--_generate-one requires full source/runtime/script identities" - ) - if _sha256_file(Path(__file__)) != arguments.expected_script_sha256: - print( - "four-quark-compiled-gate worker: gate script identity mismatch", - file=sys.stderr, - ) - return 2 - lane = next(item for item in LANES if item.name == arguments.lane) - try: - payload = _generation_worker( - arguments.artifact, - lane, - expected_revision=arguments.expected_revision, - expected_runtime_sha256=arguments.expected_runtime_sha256, - expected_script_sha256=arguments.expected_script_sha256, - ) - except (GateError, OSError, RuntimeError, ValueError) as error: - print(f"four-quark-compiled-gate worker: {error}", file=sys.stderr) - return 2 - print(json.dumps(payload, allow_nan=False, sort_keys=True)) - return 0 - if arguments.output_root is None: - parser().error("--output-root is required") - if arguments.generation_timeout <= 0 or not math.isfinite( - arguments.generation_timeout - ): - parser().error("--generation-timeout must be positive and finite") - evidence_path = ( - arguments.evidence - if arguments.evidence is not None - else arguments.output_root / "four-quark-compiled-gate.json" - ) - try: - result = run_gate(arguments) - _write_json_atomic(evidence_path.expanduser().resolve(strict=False), result) - except (GateError, OSError, RuntimeError, ValueError) as error: - print(f"four-quark-compiled-gate: {error}", file=sys.stderr) - return 2 - print(json.dumps(result, allow_nan=False, indent=2, sort_keys=True)) - return 0 if result["passes"] else 1 - - -if __name__ == "__main__": - _ensure_source_only_python() - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/native_direct_cpp_probe.py b/pyamplicol/tools/developer/native_direct_cpp_probe.py deleted file mode 100644 index 6056788269..0000000000 --- a/pyamplicol/tools/developer/native_direct_cpp_probe.py +++ /dev/null @@ -1,805 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Build and measure one genuine compiled-C++ DirectApplication leaf. - -The input must be a real schema-v3 compiled-C++ process artifact. The probe -loads its retained Symbolica evaluator state, selects the largest compatible -leaf that consumes a model scalar, emits the optimized instruction stream -directly against split planes, and compiles a direct-only native library. The -original dense library is loaded separately as a parity/timing oracle. - -Run this script under ``tools/ci/memory_watchdog.py --limit-gib 30``. -""" - -from __future__ import annotations - -import argparse -import ctypes -import json -import platform -import statistics -import sys -import time -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -import numpy as np -from symbolica import CompiledComplexEvaluator, Evaluator - -from pyamplicol.evaluators.native_direct_cpp import ( - NativeDirectCppCompiler, - NativeDirectCppParameterKind, - NativeDirectCppSpec, - compile_native_direct_cpp, - render_native_direct_cpp, -) -from pyamplicol.generation.evaluator_container import PacbinReader - - -@dataclass(frozen=True, slots=True) -class RetainedLeaf: - process_id: str - stage_index: int - chunk_index: int - function_name: str - input_len: int - output_len: int - parameter_kinds: tuple[NativeDirectCppParameterKind, ...] - source_path: Path - library_path: Path - evaluator: Any - instruction_count: int - - -class InputPlane(ctypes.Structure): - _fields_ = [("values", ctypes.POINTER(ctypes.c_double))] - - -class OutputPlane(ctypes.Structure): - _fields_ = [("values", ctypes.POINTER(ctypes.c_double))] - - -class Scalar(ctypes.Structure): - _fields_ = [("value", ctypes.POINTER(ctypes.c_double))] - - -class Metadata(ctypes.Structure): - _fields_ = [ - ("abi_version", ctypes.c_uint32), - ("struct_size", ctypes.c_uint32), - ("flags", ctypes.c_uint32), - ("input_plane_count", ctypes.c_uint32), - ("scalar_input_count", ctypes.c_uint32), - ("output_plane_count", ctypes.c_uint32), - ("simd_lane_width", ctypes.c_uint32), - ("reserved", ctypes.c_uint32), - ] - - -@dataclass(slots=True) -class BoundDirectCall: - function: Any - input_descriptors: Any - scalar_descriptors: Any - output_descriptors: Any - input_planes: list[np.ndarray] - scalar_values: list[ctypes.c_double] - output_planes: list[np.ndarray] - input_count: int - scalar_count: int - output_count: int - - def evaluate(self, point_start: int, point_count: int) -> int: - return int( - self.function( - self.input_descriptors, - self.input_count, - self.scalar_descriptors, - self.scalar_count, - self.output_descriptors, - self.output_count, - point_start, - point_count, - ) - ) - - -def _arguments() -> argparse.Namespace: - parser = argparse.ArgumentParser() - parser.add_argument("artifact", type=Path) - parser.add_argument( - "--process", - help="stable process id; defaults to the artifact default process", - ) - parser.add_argument( - "--output-dir", - type=Path, - default=Path("/private/tmp/pyamplicol-native-direct-cpp-probe"), - ) - parser.add_argument("--compiler", default="c++") - parser.add_argument("--optimization-level", type=int, default=3) - parser.add_argument("--simd-lane-width", type=int, default=2) - parser.add_argument("--points", type=int, default=129) - parser.add_argument("--stride", type=int, default=136) - parser.add_argument("--samples", type=int, default=7) - parser.add_argument("--repeats", type=int, default=2_000) - parser.add_argument("--json-out", type=Path) - return parser.parse_args() - - -def _read_json(path: Path) -> dict[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise RuntimeError(f"could not read JSON document {path}") from error - if not isinstance(value, dict): - raise RuntimeError(f"JSON document is not an object: {path}") - return value - - -def _process_id(outer: dict[str, Any], requested: str | None) -> str: - if requested is not None: - return requested - default = outer.get("default_process_id") - if not isinstance(default, str) or not default: - raise RuntimeError("artifact has no default process id") - return default - - -def _parameter_kind(component: dict[str, Any]) -> NativeDirectCppParameterKind: - storage_is_scalar = component.get("kind") == "model_parameter" - real_valued = component.get("real_valued") is True - if storage_is_scalar: - return ( - NativeDirectCppParameterKind.REAL_SCALAR - if real_valued - else NativeDirectCppParameterKind.COMPLEX_SCALAR - ) - return ( - NativeDirectCppParameterKind.REAL_PLANE - if real_valued - else NativeDirectCppParameterKind.COMPLEX_PLANE - ) - - -def _load_evaluator_state( - reader: PacbinReader, - logical_path: str, -) -> Any: - member = reader.member(logical_path) - payload = reader.read_member(logical_path, length=member.length) - return Evaluator.load(payload) - - -def _select_retained_leaf( - artifact: Path, - process_id: str, - target_triple: str, - cpu_features: tuple[str, ...], - lane_width: int, -) -> RetainedLeaf: - process_root = artifact / "processes" / process_id - execution = _read_json(process_root / "execution.json") - compiled = execution.get("compiled") - if not isinstance(compiled, dict): - raise RuntimeError("process has no compiled execution blueprint") - stage_evaluators = compiled.get("stage_evaluators") - if not isinstance(stage_evaluators, dict): - raise RuntimeError("process has no compiled stage evaluators") - stages = stage_evaluators.get("stages") - if not isinstance(stages, list): - raise RuntimeError("compiled stage evaluator list is absent") - - candidates: list[RetainedLeaf] = [] - with PacbinReader.open( - artifact / "evaluators.pacbin", - verify_payloads=True, - ) as reader: - for stage_ordinal, raw_stage in enumerate(stages): - if not isinstance(raw_stage, dict): - continue - raw_components = raw_stage.get("input_components") - evaluator = raw_stage.get("evaluator") - if not isinstance(raw_components, list) or not isinstance(evaluator, dict): - continue - components: dict[int, dict[str, Any]] = {} - for raw_component in raw_components: - if not isinstance(raw_component, dict): - continue - parameter_index = raw_component.get("parameter_index") - if isinstance(parameter_index, int) and not isinstance( - parameter_index, bool - ): - components[parameter_index] = raw_component - chunks = evaluator.get("chunks") - maps = evaluator.get("chunk_input_indices") - if not isinstance(chunks, list) or not isinstance(maps, list): - continue - for chunk_index, (raw_chunk, raw_map) in enumerate( - zip(chunks, maps, strict=True) - ): - if not isinstance(raw_chunk, dict) or not isinstance(raw_map, list): - continue - try: - parent_indices = tuple(int(index) for index in raw_map) - kinds = tuple( - _parameter_kind(components[index]) for index in parent_indices - ) - except (KeyError, TypeError, ValueError): - continue - if not any( - kind - in { - NativeDirectCppParameterKind.REAL_SCALAR, - NativeDirectCppParameterKind.COMPLEX_SCALAR, - } - for kind in kinds - ): - continue - function_name = raw_chunk.get("function_name") - state_path = raw_chunk.get("evaluator_state_path") - source_path = raw_chunk.get("source_path") - library_path = raw_chunk.get("library_path") - input_len = raw_chunk.get("input_len") - output_len = raw_chunk.get("output_len") - if not isinstance(source_path, str) and isinstance(library_path, str): - # Repackaged manifests deliberately omit the source path - # key, but retain it beside the native library. - source_path = str( - Path(library_path).parent - / ( - f"{function_name}.cpp" - if isinstance(function_name, str) - else "" - ) - ) - if ( - not isinstance(function_name, str) - or not isinstance(state_path, str) - or not isinstance(source_path, str) - or not isinstance(library_path, str) - or not isinstance(input_len, int) - or not isinstance(output_len, int) - or len(kinds) != input_len - ): - continue - logical_state_path = f"processes/{process_id}/{state_path}" - try: - source_evaluator = _load_evaluator_state( - reader, - logical_state_path, - ) - spec = NativeDirectCppSpec( - function_name=function_name, - parameter_kinds=kinds, - output_count=output_len, - target_triple=target_triple, - cpu_features=cpu_features, - simd_lane_width=lane_width, - ) - rendered = render_native_direct_cpp(source_evaluator, spec) - except Exception: - continue - candidates.append( - RetainedLeaf( - process_id=process_id, - stage_index=int(raw_stage.get("stage_index", stage_ordinal)), - chunk_index=chunk_index, - function_name=function_name, - input_len=input_len, - output_len=output_len, - parameter_kinds=kinds, - source_path=process_root / Path(source_path), - library_path=process_root / Path(library_path), - evaluator=source_evaluator, - instruction_count=rendered.instruction_count, - ) - ) - if not candidates: - raise RuntimeError( - "no genuine compiled leaf with a model scalar fits the fail-closed " - "native DirectApplication instruction subset" - ) - return max( - candidates, - key=lambda candidate: ( - candidate.instruction_count, - candidate.output_len, - -candidate.stage_index, - -candidate.chunk_index, - ), - ) - - -def _pointer(array: np.ndarray) -> ctypes.POINTER(ctypes.c_double): - if array.dtype != np.float64 or not array.flags.c_contiguous: - raise RuntimeError("direct plane is not contiguous float64") - return array.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) - - -def _bind_direct( - library: Any, - leaf: RetainedLeaf, - dense_inputs: np.ndarray, - stride: int, -) -> BoundDirectCall: - input_planes: list[np.ndarray] = [] - scalar_values: list[ctypes.c_double] = [] - for parameter, kind in enumerate(leaf.parameter_kinds): - values = dense_inputs[:, parameter] - if kind is NativeDirectCppParameterKind.COMPLEX_PLANE: - input_planes.append(np.ascontiguousarray(values.real)) - input_planes.append(np.ascontiguousarray(values.imag)) - elif kind is NativeDirectCppParameterKind.REAL_PLANE: - input_planes.append(np.ascontiguousarray(values.real)) - elif kind is NativeDirectCppParameterKind.COMPLEX_SCALAR: - scalar_values.append(ctypes.c_double(float(values[0].real))) - scalar_values.append(ctypes.c_double(float(values[0].imag))) - else: - scalar_values.append(ctypes.c_double(float(values[0].real))) - input_descriptors = (InputPlane * len(input_planes))( - *(InputPlane(_pointer(values)) for values in input_planes) - ) - scalar_descriptors = (Scalar * len(scalar_values))( - *(Scalar(ctypes.pointer(value)) for value in scalar_values) - ) - output_planes = [ - np.full(stride, np.nan, dtype=np.float64) for _ in range(2 * leaf.output_len) - ] - output_descriptors = (OutputPlane * len(output_planes))( - *(OutputPlane(_pointer(values)) for values in output_planes) - ) - symbol = getattr(library, f"{leaf.function_name}_direct_application_v1") - symbol.argtypes = [ - ctypes.POINTER(InputPlane), - ctypes.c_uint32, - ctypes.POINTER(Scalar), - ctypes.c_uint32, - ctypes.POINTER(OutputPlane), - ctypes.c_uint32, - ctypes.c_uint32, - ctypes.c_uint32, - ] - symbol.restype = ctypes.c_int - return BoundDirectCall( - function=symbol, - input_descriptors=input_descriptors, - scalar_descriptors=scalar_descriptors, - output_descriptors=output_descriptors, - input_planes=input_planes, - scalar_values=scalar_values, - output_planes=output_planes, - input_count=len(input_planes), - scalar_count=len(scalar_values), - output_count=len(output_planes), - ) - - -def _metadata( - library: Any, - leaf: RetainedLeaf, -) -> tuple[Metadata, dict[str, object]]: - prefix = f"{leaf.function_name}_direct_application_v1" - metadata_function = getattr(library, f"{prefix}_metadata") - metadata_function.argtypes = [] - metadata_function.restype = Metadata - metadata = metadata_function() - strings: dict[str, object] = {} - for suffix in ("target_triple", "cpu_features", "source_sha256"): - function = getattr(library, f"{prefix}_{suffix}") - function.argtypes = [] - function.restype = ctypes.c_char_p - raw = function() - if raw is None: - raise RuntimeError(f"direct metadata string {suffix} is null") - strings[suffix] = raw.decode("ascii") - stack_function = getattr(library, f"{prefix}_logical_stack_bytes") - stack_function.argtypes = [] - stack_function.restype = ctypes.c_uint32 - strings["logical_stack_bytes"] = int(stack_function()) - return metadata, strings - - -def _deterministic_inputs( - leaf: RetainedLeaf, - stride: int, -) -> np.ndarray: - rng = np.random.default_rng(0xD1EC7A) - values = ( - rng.normal(0.0, 0.25, size=(stride, leaf.input_len)) - + 1j * rng.normal(0.0, 0.25, size=(stride, leaf.input_len)) - ).astype(np.complex128) - for parameter, kind in enumerate(leaf.parameter_kinds): - if kind in { - NativeDirectCppParameterKind.REAL_PLANE, - NativeDirectCppParameterKind.REAL_SCALAR, - }: - values[:, parameter].imag = 0.0 - if kind in { - NativeDirectCppParameterKind.REAL_SCALAR, - NativeDirectCppParameterKind.COMPLEX_SCALAR, - }: - scalar = complex(values[0, parameter]) - if kind is NativeDirectCppParameterKind.REAL_SCALAR: - scalar = complex(0.375, 0.0) - values[:, parameter] = scalar - values[0, 0] = complex(values[0, 0].real, -0.0) - return values - - -def _resolved_direct_outputs( - bound: BoundDirectCall, - start: int, - count: int, - output_len: int, -) -> np.ndarray: - stop = start + count - return np.column_stack( - [ - bound.output_planes[2 * output][start:stop] - + 1j * bound.output_planes[2 * output + 1][start:stop] - for output in range(output_len) - ] - ) - - -def _test_parity_and_tails( - dense: Any, - dense_inputs: np.ndarray, - bound: BoundDirectCall, - leaf: RetainedLeaf, - points: int, - stride: int, -) -> dict[str, object]: - expected = np.asarray(dense.evaluate(dense_inputs), dtype=np.complex128) - if expected.shape != (stride, leaf.output_len): - raise RuntimeError(f"dense oracle returned unexpected shape {expected.shape}") - tail_ranges = ( - (0, 1), - (0, 2), - (0, 3), - (0, min(127, points)), - (1, min(127, points - 1)), - (0, min(128, points)), - (0, points), - ) - maximum_error = 0.0 - for start, count in tail_ranges: - if count < 1: - continue - for plane in bound.output_planes: - plane.fill(np.nan) - status = bound.evaluate(start, count) - if status != 0: - raise RuntimeError( - f"direct leaf returned status {status} for range {start}+{count}" - ) - actual = _resolved_direct_outputs( - bound, - start, - count, - leaf.output_len, - ) - reference = expected[start : start + count] - np.testing.assert_allclose(actual, reference, rtol=1e-12, atol=1e-15) - maximum_error = max( - maximum_error, - float(np.max(np.abs(actual - reference), initial=0.0)), - ) - for plane in bound.output_planes: - if ( - not np.isnan(plane[:start]).all() - or not np.isnan(plane[start + count :]).all() - ): - raise RuntimeError( - "direct odd-tail call overwrote an inactive sentinel" - ) - - bound.output_descriptors[0].values = bound.input_descriptors[0].values - alias_status = bound.evaluate(0, 1) - bound.output_descriptors[0].values = _pointer(bound.output_planes[0]) - if alias_status != 4: - raise RuntimeError( - f"native direct input/output alias returned {alias_status}, expected 4" - ) - count_status = int( - bound.function( - bound.input_descriptors, - bound.input_count - 1, - bound.scalar_descriptors, - bound.scalar_count, - bound.output_descriptors, - bound.output_count, - 0, - 1, - ) - ) - if count_status != 2: - raise RuntimeError( - f"native direct descriptor mismatch returned {count_status}, expected 2" - ) - return { - "ranges": [list(item) for item in tail_ranges], - "maximum_absolute_error": maximum_error, - "rtol": 1e-12, - "atol": 1e-15, - "alias_status": alias_status, - "descriptor_count_status": count_status, - } - - -def _median_mad(values: list[int]) -> tuple[float, float]: - median = float(statistics.median(values)) - mad = float(statistics.median(abs(value - median) for value in values)) - return median, mad - - -def _sample( - function: Any, - *, - samples: int, - repeats: int, -) -> list[int]: - output: list[int] = [] - for _sample in range(samples): - started = time.perf_counter_ns() - for _repeat in range(repeats): - function() - output.append((time.perf_counter_ns() - started) // repeats) - return output - - -def _timings( - dense: Any, - dense_inputs: np.ndarray, - bound: BoundDirectCall, - leaf: RetainedLeaf, - points: int, - samples: int, - repeats: int, -) -> dict[str, object]: - packed = np.empty((points, leaf.input_len), dtype=np.complex128) - scattered = np.empty((points, leaf.output_len), dtype=np.complex128) - dense_view = dense_inputs[:points] - - def direct_call() -> None: - status = bound.evaluate(0, points) - if status != 0: - raise RuntimeError(f"timed direct leaf returned status {status}") - - def dense_prepacked() -> None: - result = dense.evaluate(dense_view) - if np.asarray(result).shape != scattered.shape: - raise RuntimeError("timed dense oracle changed shape") - - def dense_gather_call_scatter() -> None: - packed[:, :] = dense_view - result = np.asarray(dense.evaluate(packed), dtype=np.complex128) - scattered[:, :] = result - - direct_call() - dense_prepacked() - dense_gather_call_scatter() - direct_samples: list[int] = [] - raw_samples: list[int] = [] - full_samples: list[int] = [] - for sample in range(samples): - paths = ( - ( - ("direct", direct_call), - ("raw_dense", dense_prepacked), - ("full_dense", dense_gather_call_scatter), - ) - if sample % 2 == 0 - else ( - ("full_dense", dense_gather_call_scatter), - ("raw_dense", dense_prepacked), - ("direct", direct_call), - ) - ) - for label, function in paths: - values = _sample(function, samples=1, repeats=repeats) - { - "direct": direct_samples, - "raw_dense": raw_samples, - "full_dense": full_samples, - }[label].extend(values) - direct_median, direct_mad = _median_mad(direct_samples) - raw_median, raw_mad = _median_mad(raw_samples) - full_median, full_mad = _median_mad(full_samples) - return { - "boundary": ( - "Python FFI probe: raw_dense is prepacked CompiledComplexEvaluator; " - "full_dense adds NumPy gather/scatter; direct is one prebound native call" - ), - "points": points, - "samples": samples, - "repeats": repeats, - "direct_ns_per_call": direct_samples, - "raw_dense_ns_per_call": raw_samples, - "full_dense_ns_per_call": full_samples, - "direct_median_ns_per_call": direct_median, - "direct_mad_ns_per_call": direct_mad, - "raw_dense_median_ns_per_call": raw_median, - "raw_dense_mad_ns_per_call": raw_mad, - "full_dense_median_ns_per_call": full_median, - "full_dense_mad_ns_per_call": full_mad, - "direct_ns_per_point": direct_median / points, - "raw_dense_ns_per_point": raw_median / points, - "full_dense_ns_per_point": full_median / points, - "raw_dense_over_direct": raw_median / direct_median, - "full_dense_over_direct": full_median / direct_median, - } - - -def main() -> int: - args = _arguments() - if args.points < 3 or args.stride < args.points: - raise RuntimeError("probe stride must cover at least three active points") - if args.samples < 3 or args.samples % 2 == 0 or args.repeats < 1: - raise RuntimeError("probe needs an odd sample count >= 3 and positive repeats") - artifact = args.artifact.resolve() - outer = _read_json(artifact / "artifact.json") - process_id = _process_id(outer, args.process) - producer = outer.get("producer") - target = producer.get("target") if isinstance(producer, dict) else None - if not isinstance(target, dict): - raise RuntimeError("artifact producer target metadata is absent") - target_triple = target.get("triple") - raw_cpu_features = target.get("cpu_features") - if not isinstance(target_triple, str) or not isinstance(raw_cpu_features, list): - raise RuntimeError("artifact producer target metadata is invalid") - cpu_features = tuple(str(feature) for feature in raw_cpu_features) - leaf = _select_retained_leaf( - artifact, - process_id, - target_triple, - cpu_features, - args.simd_lane_width, - ) - spec = NativeDirectCppSpec( - function_name=leaf.function_name, - parameter_kinds=leaf.parameter_kinds, - output_count=leaf.output_len, - target_triple=target_triple, - cpu_features=cpu_features, - simd_lane_width=args.simd_lane_width, - ) - args.output_dir.mkdir(parents=True, exist_ok=True) - direct_source = args.output_dir / f"{leaf.function_name}.direct.cpp" - direct_library = args.output_dir / f"lib{leaf.function_name}.direct" - compiler = NativeDirectCppCompiler( - executable=args.compiler, - optimization_level=args.optimization_level, - native_arch=bool(cpu_features), - extra_flags=(), - ) - built = compile_native_direct_cpp( - leaf.evaluator, - spec=spec, - compiler=compiler, - output_source_path=direct_source, - output_library_path=direct_library, - ) - library = ctypes.CDLL(str(built.library_path)) - metadata, auxiliary_metadata = _metadata(library, leaf) - if metadata.abi_version != 1 or metadata.struct_size != ctypes.sizeof(Metadata): - raise RuntimeError("native direct primary metadata is incompatible") - if metadata.flags != 0x3F or metadata.reserved != 0: - raise RuntimeError("native direct primary metadata flags are incompatible") - if auxiliary_metadata["target_triple"] != target_triple: - raise RuntimeError("native direct target triple metadata changed") - if auxiliary_metadata["cpu_features"] != ",".join(cpu_features): - raise RuntimeError("native direct CPU feature metadata changed") - if auxiliary_metadata["source_sha256"] != built.source.evaluator_state_sha256: - raise RuntimeError("native direct source-state digest metadata changed") - - dense_inputs = _deterministic_inputs(leaf, args.stride) - dense = CompiledComplexEvaluator.load( - str(leaf.library_path), - leaf.function_name, - leaf.input_len, - leaf.output_len, - ) - bound = _bind_direct(library, leaf, dense_inputs, args.stride) - if ( - metadata.input_plane_count != bound.input_count - or metadata.scalar_input_count != bound.scalar_count - or metadata.output_plane_count != bound.output_count - or metadata.simd_lane_width != args.simd_lane_width - ): - raise RuntimeError("native direct descriptor metadata disagrees with bindings") - parity = _test_parity_and_tails( - dense, - dense_inputs, - bound, - leaf, - args.points, - args.stride, - ) - timings = _timings( - dense, - dense_inputs, - bound, - leaf, - args.points, - args.samples, - args.repeats, - ) - dense_source_bytes = leaf.source_path.stat().st_size - dense_library_bytes = leaf.library_path.stat().st_size - direct_source_bytes = built.source_path.stat().st_size - direct_library_bytes = built.library_path.stat().st_size - artifact_bytes = sum( - path.stat().st_size for path in artifact.rglob("*") if path.is_file() - ) - payload_delta = ( - direct_source_bytes - - dense_source_bytes - + direct_library_bytes - - dense_library_bytes - ) - result = { - "schema_version": 1, - "status": "pass", - "artifact": str(artifact), - "artifact_id": outer.get("artifact_id"), - "process_id": process_id, - "host": { - "platform": platform.platform(), - "machine": platform.machine(), - "python": sys.version.split()[0], - }, - "leaf": { - "stage_index": leaf.stage_index, - "chunk_index": leaf.chunk_index, - "function_name": leaf.function_name, - "input_len": leaf.input_len, - "output_len": leaf.output_len, - "parameter_kinds": [kind.value for kind in leaf.parameter_kinds], - "instruction_count": built.source.instruction_count, - "temporary_count": built.source.temporary_count, - "input_plane_count": built.source.input_plane_count, - "scalar_input_count": built.source.scalar_input_count, - "output_plane_count": built.source.output_plane_count, - "logical_stack_bytes": built.source.logical_stack_bytes, - "evaluator_state_sha256": built.source.evaluator_state_sha256, - }, - "producer": { - "abi": "pyamplicol-native-compiled-direct-application-v1", - "target_triple": target_triple, - "cpu_features": list(cpu_features), - "simd_lane_width": args.simd_lane_width, - "source_path": str(built.source_path), - "library_path": str(built.library_path), - "compiler_command": list(built.compiler_command), - "compile_seconds": built.compile_seconds, - "direct_source_calls_dense_symbol": ( - f"{leaf.function_name}_complexf64(" in built.source.source - ), - }, - "parity": parity, - "timings": timings, - "payload": { - "original_artifact_bytes": artifact_bytes, - "dense_source_bytes": dense_source_bytes, - "direct_source_bytes": direct_source_bytes, - "dense_library_bytes": dense_library_bytes, - "direct_library_bytes": direct_library_bytes, - "replacement_delta_bytes": payload_delta, - "replacement_delta_fraction_of_artifact": payload_delta / artifact_bytes, - }, - } - if result["producer"]["direct_source_calls_dense_symbol"]: - raise RuntimeError("generated direct entry contains a forbidden dense call") - serialized = json.dumps(result, indent=2, sort_keys=True) - print(serialized) - if args.json_out is not None: - args.json_out.parent.mkdir(parents=True, exist_ok=True) - args.json_out.write_text(f"{serialized}\n", encoding="utf-8") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/numerical_acceptance.py b/pyamplicol/tools/developer/numerical_acceptance.py deleted file mode 100644 index 6127ef622b..0000000000 --- a/pyamplicol/tools/developer/numerical_acceptance.py +++ /dev/null @@ -1,2005 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Durable UFO-SM numerical acceptance capture and replay. - -The fixture written by this module deliberately contains one deterministic -point and one fully summed matrix element per process. Full-colour values are -independent MadGraph standalone results. LC and NLC values are high-precision -recurrence regression references captured only after the full-colour gate has -passed. - -Normal unit tests exercise the wire contract with synthetic values. Real -generation is entered either through :class:`NumericalAcceptanceHarness` or -the ``capture`` command and is intentionally not part of the default test run. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.metadata -import json -import math -import re -import sys -from collections.abc import Iterable, Mapping, Sequence -from dataclasses import dataclass -from decimal import Decimal, InvalidOperation, localcontext -from pathlib import Path -from typing import Literal, cast - -ROOT = Path(__file__).resolve().parents[2] -if __package__ in {None, ""}: - sys.path.insert(0, str(ROOT)) - -from tools.developer.reference_capture.common import canonical_decimal # noqa: E402 -from tools.performance_report.catalog import PROCESS_FAMILIES # noqa: E402 - -MODEL_ROOT = ROOT / "src" / "pyamplicol" / "assets" / "models" / "json" / "sm" -MODEL_SOURCE = MODEL_ROOT / "sm.json" -MODEL_RESTRICTION = MODEL_ROOT / "restrict_default.json" -DEFAULT_FIXTURE = ( - ROOT / "tests" / "fixtures" / "numerical_acceptance" / "ufo-sm-seed101-v1.json" -) - -FIXTURE_KIND = "pyamplicol-ufo-sm-numerical-acceptance" -FIXTURE_SCHEMA_VERSION = 1 -CATALOG_MAX_N_FINAL = 4 -CATALOG_CASE_COUNT = 33 -POINT_SEED = 101 -RELATIVE_TOLERANCE = Decimal("0.0000000001") -FULL_CANDIDATE_PRECISION_DIGITS = 200 -NATIVE_PRECISION_DIGITS = 16 - -AccuracyName = Literal["full", "lc", "nlc"] -ModeName = Literal["recurrence", "eager", "compiled", "on-the-fly"] -LCFlowLayoutName = Literal["topology-replay", "all-flow-union"] -ArtifactGroup = Literal["catalog", "extra"] - -_SHA256_RE = re.compile(r"^[0-9a-f]{64}$") -_REVISION_RE = re.compile(r"^[0-9a-f]{40}$") - - -class NumericalAcceptanceError(RuntimeError): - """The acceptance fixture or capture contract is invalid.""" - - -class NumericalAcceptanceMismatch(AssertionError): - """A matrix element failed the strict scale-conditioned comparison.""" - - -@dataclass(frozen=True, slots=True) -class AcceptanceCaseSpec: - """One catalog or deliberately separate full-colour stress process.""" - - case_id: str - process: str - n_final: int - family_id: int | None = None - family_key: str | None = None - - @property - def is_catalog(self) -> bool: - return self.family_id is not None - - @property - def artifact_name(self) -> str: - """Return a stable public ProcessSet name accepted by pyAmpliCol.""" - - return self.case_id.replace(":", "_").replace("-", "_") - - -def catalog_cases() -> tuple[AcceptanceCaseSpec, ...]: - """Derive the complete 33-process n=1..4 catalog surface.""" - - cases: list[AcceptanceCaseSpec] = [] - for n_final in range(1, CATALOG_MAX_N_FINAL + 1): - for family in sorted(PROCESS_FAMILIES, key=lambda item: item.identifier): - process = family.process(n_final) - if process is None: - continue - cases.append( - AcceptanceCaseSpec( - case_id=f"catalog:{family.key}:n{n_final}", - process=process, - n_final=n_final, - family_id=family.identifier, - family_key=family.key, - ) - ) - result = tuple(cases) - if len(result) != CATALOG_CASE_COUNT: - raise NumericalAcceptanceError( - "the n=1..4 performance catalog no longer contains exactly " - f"{CATALOG_CASE_COUNT} processes (observed {len(result)})" - ) - return result - - -EXTRA_FULL_COLOUR_CASES = ( - AcceptanceCaseSpec( - case_id="extra:identical-u-four-lines", - process="u u~ > u u~ u u~ u u~", - n_final=6, - ), - AcceptanceCaseSpec( - case_id="extra:identical-electron-three-pair", - process="e+ e- > e+ e- e+ e- e+ e-", - n_final=6, - ), -) - - -@dataclass(frozen=True, slots=True) -class AcceptanceLane: - """One native generation/evaluation lane in the acceptance matrix.""" - - accuracy: AccuracyName - mode: ModeName - jit_optimization_level: int - lc_flow_layout: LCFlowLayoutName = "topology-replay" - - def __post_init__(self) -> None: - if self.lc_flow_layout == "all-flow-union" and self.accuracy != "lc": - raise ValueError("all-flow-union acceptance is available only for LC") - if self.lc_flow_layout == "all-flow-union" and self.mode == "on-the-fly": - raise ValueError( - "on-the-fly acceptance uses its compact query-local LC artifact" - ) - - @property - def lane_id(self) -> str: - if self.lc_flow_layout == "all-flow-union": - return f"lc-all-flow-union-{self.mode}" - return f"{self.accuracy}-{self.mode}" - - @property - def includes_extra_cases(self) -> bool: - return self.accuracy == "full" - - @property - def evaluation_precisions(self) -> tuple[int, ...]: - """Return the supported acceptance precisions for this lane.""" - - if self.accuracy == "full" and self.mode != "on-the-fly": - return (NATIVE_PRECISION_DIGITS, FULL_CANDIDATE_PRECISION_DIGITS) - return (NATIVE_PRECISION_DIGITS,) - - def evaluation_precisions_for( - self, - group: ArtifactGroup, - ) -> tuple[int, ...]: - """Return the minimal precision replay for one artifact group.""" - - if group == "extra": - return (NATIVE_PRECISION_DIGITS,) - return self.evaluation_precisions - - -ACCEPTANCE_LANES = ( - AcceptanceLane("full", "recurrence", 2), - AcceptanceLane("full", "eager", 2), - AcceptanceLane("full", "compiled", 3), - AcceptanceLane("full", "on-the-fly", 2), - AcceptanceLane("lc", "recurrence", 2), - AcceptanceLane("lc", "eager", 2), - AcceptanceLane("lc", "compiled", 3), - AcceptanceLane("lc", "on-the-fly", 2), - AcceptanceLane("lc", "recurrence", 2, "all-flow-union"), - AcceptanceLane("lc", "eager", 2, "all-flow-union"), - AcceptanceLane("lc", "compiled", 3, "all-flow-union"), - AcceptanceLane("nlc", "recurrence", 2), - AcceptanceLane("nlc", "eager", 2), - AcceptanceLane("nlc", "compiled", 3), - AcceptanceLane("nlc", "on-the-fly", 2), -) -FULL_LANES = tuple(lane for lane in ACCEPTANCE_LANES if lane.accuracy == "full") -LC_ALL_FLOW_UNION_LANES = tuple( - lane for lane in ACCEPTANCE_LANES if lane.lc_flow_layout == "all-flow-union" -) - - -@dataclass(frozen=True, slots=True) -class ModelIdentity: - source_sha256: str - restriction_sha256: str - external_parameters_sha256: str - - def as_payload(self) -> dict[str, object]: - return { - "kind": "ufo-sm-json-default-restriction", - "source_sha256": self.source_sha256, - "restriction_sha256": self.restriction_sha256, - "external_parameters_sha256": self.external_parameters_sha256, - } - - -@dataclass(frozen=True, slots=True) -class MadGraphReferenceIdentity: - madgraph_version: str - model_source_sha256: str - driver_sha256: str - external_parameters_sha256: str - - def as_payload(self) -> dict[str, object]: - return { - "kind": "madgraph-standalone-ufo-sm", - "precision": "binary64", - "command_protocol": "generate-output-standalone-launch-force", - "madgraph_version": self.madgraph_version, - "model_source_sha256": self.model_source_sha256, - "driver_sha256": self.driver_sha256, - "external_parameters_sha256": self.external_parameters_sha256, - } - - -@dataclass(frozen=True, slots=True) -class AcceptanceCase: - spec: AcceptanceCaseSpec - momenta: tuple[tuple[Decimal, Decimal, Decimal, Decimal], ...] - expected: tuple[tuple[AccuracyName, Decimal], ...] - - def expected_for(self, accuracy: AccuracyName) -> Decimal: - for key, value in self.expected: - if key == accuracy: - return value - raise NumericalAcceptanceError( - f"case {self.spec.case_id!r} has no {accuracy} reference" - ) - - def runtime_momenta(self) -> tuple[tuple[tuple[float, ...], ...], ...]: - return ( - tuple( - tuple(float(component) for component in momentum) - for momentum in self.momenta - ), - ) - - -@dataclass(frozen=True, slots=True) -class AcceptanceFixture: - model: ModelIdentity - full_reference: MadGraphReferenceIdentity - captured_source_revision: str - catalog: tuple[AcceptanceCase, ...] - extra_full_colour: tuple[AcceptanceCase, ...] - - def case(self, case_id: str) -> AcceptanceCase: - for case in (*self.catalog, *self.extra_full_colour): - if case.spec.case_id == case_id: - return case - raise KeyError(case_id) - - -@dataclass(frozen=True, slots=True) -class RelativeComparison: - actual_real: Decimal - actual_imaginary: Decimal - expected: Decimal - difference: Decimal - scale: Decimal - bound: Decimal - passed: bool - - -@dataclass(frozen=True, slots=True) -class MadGraphIngest: - values: Mapping[str, Decimal] - identity: MadGraphReferenceIdentity - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def current_model_identity() -> ModelIdentity: - """Return the material identity shared by pyAmpliCol and MadGraph.""" - - try: - model = json.loads(MODEL_SOURCE.read_text(encoding="utf-8")) - restriction = json.loads(MODEL_RESTRICTION.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise NumericalAcceptanceError( - "cannot read the packaged UFO-SM model" - ) from error - if not isinstance(model, Mapping) or not isinstance(restriction, Mapping): - raise NumericalAcceptanceError("the packaged UFO-SM model is malformed") - parameters = model.get("parameters") - if not isinstance(parameters, list): - raise NumericalAcceptanceError("the packaged UFO-SM model has no parameters") - externals: dict[str, list[float]] = {} - for raw_parameter in parameters: - if not isinstance(raw_parameter, Mapping): - raise NumericalAcceptanceError("the UFO-SM parameter list is malformed") - if raw_parameter.get("nature") != "external": - continue - name = raw_parameter.get("name") - restricted = restriction.get(name) if isinstance(name, str) else None - if ( - not isinstance(name, str) - or not isinstance(restricted, list) - or len(restricted) != 2 - or isinstance(restricted[0], bool) - or not isinstance(restricted[0], (int, float)) - or isinstance(restricted[1], bool) - or not isinstance(restricted[1], (int, float)) - or float(restricted[1]) != 0.0 - ): - raise NumericalAcceptanceError( - "the UFO-SM default restriction does not bind every external " - "parameter to a real value" - ) - if name in externals: - raise NumericalAcceptanceError(f"duplicate UFO-SM external {name!r}") - externals[name] = [float(restricted[0]), 0.0] - if not externals or set(externals) != set(restriction): - raise NumericalAcceptanceError( - "the UFO-SM default restriction and external parameter set differ" - ) - canonical = json.dumps( - externals, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return ModelIdentity( - source_sha256=_sha256_file(MODEL_SOURCE), - restriction_sha256=_sha256_file(MODEL_RESTRICTION), - external_parameters_sha256=hashlib.sha256(canonical).hexdigest(), - ) - - -def validation_momenta( - process: str, -) -> tuple[tuple[Decimal, Decimal, Decimal, Decimal], ...]: - """Materialize the exact decimal spelling of the seed-101 binary64 point.""" - - from pyamplicol.models.builtin.validation import generic_validation_point - - point = generic_validation_point(process, seed=POINT_SEED) - rows: list[tuple[Decimal, Decimal, Decimal, Decimal]] = [] - for particle in point: - values = tuple( - Decimal(canonical_decimal(float(component))) - for component in particle.momentum - ) - if len(values) != 4: - raise NumericalAcceptanceError( - f"validation point for {process!r} has a malformed momentum" - ) - rows.append(cast(tuple[Decimal, Decimal, Decimal, Decimal], values)) - return tuple(rows) - - -def _momenta_payload( - momenta: tuple[tuple[Decimal, Decimal, Decimal, Decimal], ...], -) -> list[list[str]]: - return [ - [canonical_decimal(component) for component in momentum] for momentum in momenta - ] - - -def _decimal_from_number(value: object, where: str) -> Decimal: - if isinstance(value, bool): - raise NumericalAcceptanceError(f"{where} must be a finite real number") - if isinstance(value, Decimal): - result = value - elif isinstance(value, int): - result = Decimal(value) - elif isinstance(value, float): - if not math.isfinite(value): - raise NumericalAcceptanceError(f"{where} must be finite") - result = Decimal(canonical_decimal(value)) - elif isinstance(value, str): - try: - result = Decimal(value) - except InvalidOperation as error: - raise NumericalAcceptanceError(f"{where} is not a decimal") from error - else: - raise NumericalAcceptanceError(f"{where} must be a finite real number") - if not result.is_finite(): - raise NumericalAcceptanceError(f"{where} must be finite") - return result - - -def _complex_decimal(value: object) -> tuple[Decimal, Decimal]: - if isinstance(value, Decimal): - if not value.is_finite(): - raise NumericalAcceptanceError("matrix element is not finite") - return value, Decimal(0) - if isinstance(value, bool): - raise NumericalAcceptanceError("matrix element must be numeric") - try: - number = complex(value) # type: ignore[arg-type] - except (TypeError, ValueError, OverflowError) as error: - raise NumericalAcceptanceError("matrix element must be numeric") from error - if not math.isfinite(number.real) or not math.isfinite(number.imag): - raise NumericalAcceptanceError("matrix element is not finite") - return ( - Decimal(canonical_decimal(number.real)), - Decimal(canonical_decimal(number.imag)), - ) - - -def compare_relative( - actual: object, - expected: Decimal, - *, - tolerance: Decimal = RELATIVE_TOLERANCE, -) -> RelativeComparison: - """Compare a real reference without an absolute-tolerance escape hatch.""" - - expected = _decimal_from_number(expected, "expected matrix element") - tolerance = _decimal_from_number(tolerance, "relative tolerance") - if tolerance < 0: - raise NumericalAcceptanceError("relative tolerance must be non-negative") - actual_real, actual_imaginary = _complex_decimal(actual) - precision = max( - 80, - len(actual_real.as_tuple().digits) + 20, - len(actual_imaginary.as_tuple().digits) + 20, - len(expected.as_tuple().digits) + 20, - ) - with localcontext() as context: - context.prec = precision - actual_magnitude = ( - actual_real * actual_real + actual_imaginary * actual_imaginary - ).sqrt() - delta_real = actual_real - expected - difference = ( - delta_real * delta_real + actual_imaginary * actual_imaginary - ).sqrt() - scale = max(actual_magnitude, abs(expected)) - bound = tolerance * scale - passed = difference == 0 if scale == 0 else difference <= bound - return RelativeComparison( - actual_real=actual_real, - actual_imaginary=actual_imaginary, - expected=expected, - difference=difference, - scale=scale, - bound=bound, - passed=passed, - ) - - -def assert_relative_match( - actual: object, - expected: Decimal, - *, - context: str, - tolerance: Decimal = RELATIVE_TOLERANCE, -) -> None: - comparison = compare_relative(actual, expected, tolerance=tolerance) - if comparison.passed: - return - raise NumericalAcceptanceMismatch( - f"{context}: actual={comparison.actual_real}" - f"{comparison.actual_imaginary:+}i, expected={comparison.expected}, " - f"difference={comparison.difference}, scale={comparison.scale}, " - f"strict relative bound={comparison.bound}" - ) - - -def _mapping(value: object, where: str) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise NumericalAcceptanceError(f"{where} must be an object") - return cast(Mapping[str, object], value) - - -def _sequence(value: object, where: str) -> Sequence[object]: - if isinstance(value, (str, bytes, bytearray)) or not isinstance(value, Sequence): - raise NumericalAcceptanceError(f"{where} must be an array") - return cast(Sequence[object], value) - - -def _exact_keys( - value: Mapping[str, object], expected: Iterable[str], where: str -) -> None: - expected_set = set(expected) - observed = set(value) - if observed != expected_set: - raise NumericalAcceptanceError( - f"{where} fields differ: missing={sorted(expected_set - observed)}, " - f"extra={sorted(observed - expected_set)}" - ) - - -def _string(value: object, where: str) -> str: - if not isinstance(value, str) or not value: - raise NumericalAcceptanceError(f"{where} must be a non-empty string") - return value - - -def _integer(value: object, where: str) -> int: - if isinstance(value, bool) or not isinstance(value, int): - raise NumericalAcceptanceError(f"{where} must be an integer") - return value - - -def _sha256(value: object, where: str) -> str: - text = _string(value, where) - if _SHA256_RE.fullmatch(text) is None: - raise NumericalAcceptanceError(f"{where} must be a lowercase SHA-256") - return text - - -def _revision(value: object, where: str) -> str: - text = _string(value, where) - if _REVISION_RE.fullmatch(text) is None or text == "0" * 40: - raise NumericalAcceptanceError(f"{where} must be a real lowercase Git SHA") - return text - - -def _canonical_decimal(value: object, where: str) -> Decimal: - if not isinstance(value, str): - raise NumericalAcceptanceError( - f"{where} must be a canonical fixed-point decimal string" - ) - try: - parsed = Decimal(value) - normalized = canonical_decimal(parsed) - except (InvalidOperation, RuntimeError) as error: - raise NumericalAcceptanceError(f"{where} is not a finite decimal") from error - if not parsed.is_finite() or normalized != value: - raise NumericalAcceptanceError( - f"{where} must be a canonical fixed-point decimal string" - ) - return parsed - - -def _duplicate_rejecting_object(pairs: list[tuple[str, object]]) -> dict[str, object]: - result: dict[str, object] = {} - for key, value in pairs: - if key in result: - raise NumericalAcceptanceError(f"duplicate JSON field {key!r}") - result[key] = value - return result - - -def _read_json(path: Path) -> object: - try: - return json.loads( - path.read_text(encoding="ascii"), - object_pairs_hook=_duplicate_rejecting_object, - parse_constant=lambda token: (_ for _ in ()).throw( - NumericalAcceptanceError(f"non-finite JSON token {token!r}") - ), - ) - except NumericalAcceptanceError: - raise - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise NumericalAcceptanceError( - f"cannot read JSON document {path}: {error}" - ) from error - - -def _parse_model(value: object) -> ModelIdentity: - record = _mapping(value, "model") - _exact_keys( - record, - { - "kind", - "source_sha256", - "restriction_sha256", - "external_parameters_sha256", - }, - "model", - ) - if record.get("kind") != "ufo-sm-json-default-restriction": - raise NumericalAcceptanceError("model.kind is unsupported") - return ModelIdentity( - source_sha256=_sha256(record["source_sha256"], "model.source_sha256"), - restriction_sha256=_sha256( - record["restriction_sha256"], "model.restriction_sha256" - ), - external_parameters_sha256=_sha256( - record["external_parameters_sha256"], - "model.external_parameters_sha256", - ), - ) - - -def _parse_full_reference(value: object) -> MadGraphReferenceIdentity: - from tools.performance_report.madgraph import MADGRAPH_DRIVER_SOURCE_SHA256 - - record = _mapping(value, "references.full") - _exact_keys( - record, - { - "kind", - "precision", - "command_protocol", - "madgraph_version", - "model_source_sha256", - "driver_sha256", - "external_parameters_sha256", - }, - "references.full", - ) - fixed = { - "kind": "madgraph-standalone-ufo-sm", - "precision": "binary64", - "command_protocol": "generate-output-standalone-launch-force", - } - for key, expected in fixed.items(): - if record.get(key) != expected: - raise NumericalAcceptanceError( - f"references.full.{key} must equal {expected!r}" - ) - driver_sha256 = _sha256(record["driver_sha256"], "references.full.driver_sha256") - if driver_sha256 != MADGRAPH_DRIVER_SOURCE_SHA256: - raise NumericalAcceptanceError( - "references.full.driver_sha256 differs from the canonical adapter driver" - ) - return MadGraphReferenceIdentity( - madgraph_version=_string( - record["madgraph_version"], "references.full.madgraph_version" - ), - model_source_sha256=_sha256( - record["model_source_sha256"], - "references.full.model_source_sha256", - ), - driver_sha256=driver_sha256, - external_parameters_sha256=_sha256( - record["external_parameters_sha256"], - "references.full.external_parameters_sha256", - ), - ) - - -def _parse_regression_reference(value: object, accuracy: str) -> str: - where = f"references.{accuracy}" - record = _mapping(value, where) - _exact_keys( - record, - {"kind", "precision_digits", "captured_source_revision"}, - where, - ) - if record.get("kind") != "pyamplicol-recurrence-regression": - raise NumericalAcceptanceError(f"{where}.kind is unsupported") - if _integer(record.get("precision_digits"), f"{where}.precision_digits") != ( - FULL_CANDIDATE_PRECISION_DIGITS - ): - raise NumericalAcceptanceError( - f"{where}.precision_digits must be {FULL_CANDIDATE_PRECISION_DIGITS}" - ) - return _revision( - record.get("captured_source_revision"), - f"{where}.captured_source_revision", - ) - - -def _parse_momenta( - value: object, where: str -) -> tuple[tuple[Decimal, Decimal, Decimal, Decimal], ...]: - rows: list[tuple[Decimal, Decimal, Decimal, Decimal]] = [] - for row_index, raw_row in enumerate(_sequence(value, where)): - components = _sequence(raw_row, f"{where}[{row_index}]") - if len(components) != 4: - raise NumericalAcceptanceError( - f"{where}[{row_index}] must contain four components" - ) - parsed = tuple( - _canonical_decimal(component, f"{where}[{row_index}][{index}]") - for index, component in enumerate(components) - ) - rows.append(cast(tuple[Decimal, Decimal, Decimal, Decimal], parsed)) - if not rows: - raise NumericalAcceptanceError(f"{where} must not be empty") - return tuple(rows) - - -def _parse_case( - raw: object, - spec: AcceptanceCaseSpec, - *, - catalog: bool, -) -> AcceptanceCase: - where = f"case {spec.case_id}" - record = _mapping(raw, where) - catalog_fields = { - "id", - "family_id", - "family_key", - "n_final", - "process", - "momenta", - "expected", - } - extra_fields = {"id", "process", "momenta", "expected"} - _exact_keys(record, catalog_fields if catalog else extra_fields, where) - if record.get("id") != spec.case_id or record.get("process") != spec.process: - raise NumericalAcceptanceError(f"{where} identity differs from the catalog") - if catalog and ( - _integer(record.get("family_id"), f"{where}.family_id") != spec.family_id - or record.get("family_key") != spec.family_key - or _integer(record.get("n_final"), f"{where}.n_final") != spec.n_final - ): - raise NumericalAcceptanceError(f"{where} metadata differs from the catalog") - momenta = _parse_momenta(record.get("momenta"), f"{where}.momenta") - expected_momenta = validation_momenta(spec.process) - if momenta != expected_momenta: - raise NumericalAcceptanceError( - f"{where}.momenta differ from generic_validation_point(seed={POINT_SEED})" - ) - expected_record = _mapping(record.get("expected"), f"{where}.expected") - expected_accuracies: tuple[AccuracyName, ...] = ( - ("full", "lc", "nlc") if catalog else ("full",) - ) - _exact_keys(expected_record, expected_accuracies, f"{where}.expected") - expected: list[tuple[AccuracyName, Decimal]] = [] - for accuracy in expected_accuracies: - parsed = _canonical_decimal( - expected_record.get(accuracy), f"{where}.expected.{accuracy}" - ) - if parsed < 0: - raise NumericalAcceptanceError( - f"{where}.expected.{accuracy} must be non-negative" - ) - expected.append((accuracy, parsed)) - return AcceptanceCase(spec=spec, momenta=momenta, expected=tuple(expected)) - - -def parse_acceptance_fixture( - payload: object, - *, - validate_current_model: bool = True, -) -> AcceptanceFixture: - """Strictly parse and semantically bind a numerical acceptance payload.""" - - root = _mapping(payload, "fixture") - _exact_keys( - root, - { - "kind", - "schema_version", - "model", - "point_policy", - "comparison", - "references", - "catalog_max_n_final", - "catalog_cases", - "extra_full_colour_cases", - }, - "fixture", - ) - if root.get("kind") != FIXTURE_KIND: - raise NumericalAcceptanceError("fixture.kind is unsupported") - if _integer(root.get("schema_version"), "fixture.schema_version") != ( - FIXTURE_SCHEMA_VERSION - ): - raise NumericalAcceptanceError("fixture.schema_version is unsupported") - if _integer(root.get("catalog_max_n_final"), "catalog_max_n_final") != ( - CATALOG_MAX_N_FINAL - ): - raise NumericalAcceptanceError( - f"catalog_max_n_final must be {CATALOG_MAX_N_FINAL}" - ) - - model = _parse_model(root.get("model")) - if validate_current_model and model != current_model_identity(): - raise NumericalAcceptanceError( - "fixture UFO-SM model identity differs from the current packaged model" - ) - - point_policy = _mapping(root.get("point_policy"), "point_policy") - _exact_keys( - point_policy, {"generator", "seed", "stored_components"}, "point_policy" - ) - expected_point_policy = { - "generator": "generic_validation_point", - "seed": POINT_SEED, - "stored_components": "canonical-binary64-decimal", - } - if dict(point_policy) != expected_point_policy: - raise NumericalAcceptanceError( - f"point_policy must equal {expected_point_policy!r}" - ) - - comparison = _mapping(root.get("comparison"), "comparison") - _exact_keys( - comparison, - { - "relative_tolerance", - "absolute_tolerance", - "full_candidate_precision_digits", - "native_precision", - }, - "comparison", - ) - if ( - _canonical_decimal( - comparison.get("relative_tolerance"), "comparison.relative_tolerance" - ) - != RELATIVE_TOLERANCE - or comparison.get("absolute_tolerance") is not None - or _integer( - comparison.get("full_candidate_precision_digits"), - "comparison.full_candidate_precision_digits", - ) - != FULL_CANDIDATE_PRECISION_DIGITS - or comparison.get("native_precision") != "binary64" - ): - raise NumericalAcceptanceError( - "comparison must use strict relative-only 1e-10, p200, and binary64" - ) - - references = _mapping(root.get("references"), "references") - _exact_keys(references, {"full", "lc", "nlc"}, "references") - full_reference = _parse_full_reference(references.get("full")) - lc_revision = _parse_regression_reference(references.get("lc"), "lc") - nlc_revision = _parse_regression_reference(references.get("nlc"), "nlc") - if lc_revision != nlc_revision: - raise NumericalAcceptanceError( - "LC and NLC regression references must come from one source revision" - ) - if full_reference.external_parameters_sha256 != model.external_parameters_sha256: - raise NumericalAcceptanceError( - "MadGraph and pyAmpliCol external-parameter identities differ" - ) - - catalog_specs = catalog_cases() - raw_catalog = _sequence(root.get("catalog_cases"), "catalog_cases") - raw_extra = _sequence( - root.get("extra_full_colour_cases"), "extra_full_colour_cases" - ) - if len(raw_catalog) != len(catalog_specs): - raise NumericalAcceptanceError( - f"catalog_cases must contain exactly {len(catalog_specs)} records" - ) - if len(raw_extra) != len(EXTRA_FULL_COLOUR_CASES): - raise NumericalAcceptanceError( - "extra_full_colour_cases must contain exactly the two declared " - "non-catalog benchmarks" - ) - catalog = tuple( - _parse_case(raw, spec, catalog=True) - for raw, spec in zip(raw_catalog, catalog_specs, strict=True) - ) - extra = tuple( - _parse_case(raw, spec, catalog=False) - for raw, spec in zip(raw_extra, EXTRA_FULL_COLOUR_CASES, strict=True) - ) - ids = tuple(case.spec.case_id for case in (*catalog, *extra)) - if len(ids) != len(set(ids)): - raise NumericalAcceptanceError("fixture case IDs are not unique") - return AcceptanceFixture( - model=model, - full_reference=full_reference, - captured_source_revision=lc_revision, - catalog=catalog, - extra_full_colour=extra, - ) - - -def load_acceptance_fixture(path: Path = DEFAULT_FIXTURE) -> AcceptanceFixture: - """Load the tracked acceptance fixture with full semantic validation.""" - - return parse_acceptance_fixture(_read_json(path)) - - -def _serialized_value(value: object, where: str) -> str: - decimal = _decimal_from_number(value, where) - if decimal < 0: - raise NumericalAcceptanceError(f"{where} must be non-negative") - return canonical_decimal(decimal) - - -def build_fixture_payload( - *, - full_values: Mapping[str, object], - lc_values: Mapping[str, object], - nlc_values: Mapping[str, object], - full_reference: MadGraphReferenceIdentity, - captured_source_revision: str, -) -> dict[str, object]: - """Build, then strictly re-parse, a complete fixture payload. - - Callers must provide every value; this function never substitutes or - invents a numerical result. - """ - - catalog_specs = catalog_cases() - catalog_ids = {case.case_id for case in catalog_specs} - extra_ids = {case.case_id for case in EXTRA_FULL_COLOUR_CASES} - if set(full_values) != catalog_ids | extra_ids: - raise NumericalAcceptanceError( - "full_values must cover exactly all catalog and extra cases" - ) - if set(lc_values) != catalog_ids or set(nlc_values) != catalog_ids: - raise NumericalAcceptanceError( - "LC and NLC values must each cover exactly the 33 catalog cases" - ) - revision = _revision(captured_source_revision, "captured_source_revision") - - catalog_payload: list[dict[str, object]] = [] - for spec in catalog_specs: - catalog_payload.append( - { - "id": spec.case_id, - "family_id": spec.family_id, - "family_key": spec.family_key, - "n_final": spec.n_final, - "process": spec.process, - "momenta": _momenta_payload(validation_momenta(spec.process)), - "expected": { - "full": _serialized_value( - full_values[spec.case_id], f"full_values[{spec.case_id}]" - ), - "lc": _serialized_value( - lc_values[spec.case_id], f"lc_values[{spec.case_id}]" - ), - "nlc": _serialized_value( - nlc_values[spec.case_id], f"nlc_values[{spec.case_id}]" - ), - }, - } - ) - extra_payload = [ - { - "id": spec.case_id, - "process": spec.process, - "momenta": _momenta_payload(validation_momenta(spec.process)), - "expected": { - "full": _serialized_value( - full_values[spec.case_id], f"full_values[{spec.case_id}]" - ) - }, - } - for spec in EXTRA_FULL_COLOUR_CASES - ] - regression_reference = { - "kind": "pyamplicol-recurrence-regression", - "precision_digits": FULL_CANDIDATE_PRECISION_DIGITS, - "captured_source_revision": revision, - } - payload: dict[str, object] = { - "kind": FIXTURE_KIND, - "schema_version": FIXTURE_SCHEMA_VERSION, - "model": current_model_identity().as_payload(), - "point_policy": { - "generator": "generic_validation_point", - "seed": POINT_SEED, - "stored_components": "canonical-binary64-decimal", - }, - "comparison": { - "relative_tolerance": canonical_decimal(RELATIVE_TOLERANCE), - "absolute_tolerance": None, - "full_candidate_precision_digits": FULL_CANDIDATE_PRECISION_DIGITS, - "native_precision": "binary64", - }, - "references": { - "full": full_reference.as_payload(), - "lc": dict(regression_reference), - "nlc": dict(regression_reference), - }, - "catalog_max_n_final": CATALOG_MAX_N_FINAL, - "catalog_cases": catalog_payload, - "extra_full_colour_cases": extra_payload, - } - parse_acceptance_fixture(payload) - return payload - - -def write_acceptance_fixture(payload: object, path: Path) -> AcceptanceFixture: - """Validate and exclusively create a fixture; never overwrite one.""" - - fixture = parse_acceptance_fixture(payload) - destination = path.expanduser().resolve(strict=False) - destination.parent.mkdir(parents=True, exist_ok=True) - encoded = ( - json.dumps( - payload, - ensure_ascii=True, - indent=2, - sort_keys=False, - allow_nan=False, - ) - + "\n" - ) - try: - with destination.open("x", encoding="ascii", newline="\n") as stream: - stream.write(encoded) - except FileExistsError as error: - raise NumericalAcceptanceError( - f"refusing to overwrite existing fixture {destination}" - ) from error - return fixture - - -def lane_run_config(lane: AcceptanceLane) -> object: - """Return the lean, deterministic generation config for one lane.""" - - from pyamplicol.config import ( - Action, - ColorAccuracy, - ColorConfig, - EvaluatorConfig, - EvaluatorExecutionMode, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationRelationDiscoveryConfig, - GenerationValidationConfig, - JITConfig, - LCFlowLayout, - RelationDiscoveryMode, - RunConfig, - ) - - return RunConfig( - action=Action.GENERATE, - color=ColorConfig( - accuracy=ColorAccuracy(lane.accuracy), - lc_flow_layout=LCFlowLayout(lane.lc_flow_layout), - ), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - validation=GenerationValidationConfig( - enabled=False, - post_build_validation=False, - ), - relation_discovery=GenerationRelationDiscoveryConfig( - mode=RelationDiscoveryMode.OFF - ), - ), - evaluator=EvaluatorConfig( - execution_mode=EvaluatorExecutionMode(lane.mode), - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=lane.jit_optimization_level), - ), - ) - - -def lane_case_specs( - lane: AcceptanceLane, - *, - group: ArtifactGroup = "catalog", -) -> tuple[AcceptanceCaseSpec, ...]: - """Return the static process order without pulling n=6 into catalog builds.""" - - if group == "catalog": - return catalog_cases() - if group == "extra" and lane.includes_extra_cases: - return EXTRA_FULL_COLOUR_CASES - raise NumericalAcceptanceError( - f"{lane.lane_id} has no {group!r} acceptance artifact" - ) - - -def lane_process_set( - lane: AcceptanceLane, - *, - group: ArtifactGroup = "catalog", -) -> object: - """Return one ordered ProcessSet for a lane's catalog or extra group.""" - - from pyamplicol import ProcessSet - - cases = lane_case_specs(lane, group=group) - return ProcessSet.from_expressions( - (case.process for case in cases), - names=tuple(case.artifact_name for case in cases), - ) - - -def prepare_ufo_sm_model(work_root: Path) -> object: - """Prepare one recurrence JIT-O2 UFO-SM bundle reusable by all lanes.""" - - from pyamplicol import ModelSource - - root = work_root.expanduser().resolve(strict=False) - root.mkdir(parents=True, exist_ok=True) - recurrence_lane = AcceptanceLane("full", "recurrence", 2) - evaluator = lane_run_config(recurrence_lane).evaluator # type: ignore[attr-defined] - model = ModelSource.from_path( - MODEL_SOURCE, - restriction=MODEL_RESTRICTION, - ).compile( - cache_dir=root / "model-cache", - use_cache=True, - prepared_output=root / "ufo-sm-jit-o2.pyamplicol-model", - evaluator=evaluator, - ) - if not getattr(model, "is_prepared", False): - raise NumericalAcceptanceError("UFO-SM preparation returned no prepared model") - return model - - -def generate_lane_artifact( - lane: AcceptanceLane, - *, - artifact_path: Path, - model: object, - group: ArtifactGroup = "catalog", -) -> Path: - """Generate exactly one ProcessSet artifact for one lane/group pair.""" - - from pyamplicol import Generator - - destination = artifact_path.expanduser().resolve(strict=False) - Generator(lane_run_config(lane)).generate( - lane_process_set(lane, group=group), - destination, - model=model, # type: ignore[arg-type] - ) - _validate_artifact_lane(destination, lane) - return destination - - -def _validate_artifact_lane( - artifact: Path, - lane: AcceptanceLane, -) -> None: - """Bind a generated lane to its exact effective mode, accuracy, and layout.""" - - import tomllib - - effective_path = artifact / "config" / "effective.toml" - try: - effective = tomllib.loads(effective_path.read_text(encoding="utf-8")) - color = effective["color"] - evaluator = effective["evaluator"] - observed = ( - str(color["accuracy"]), - str(evaluator["execution_mode"]), - str(color["lc_flow_layout"]), - ) - except (KeyError, OSError, TypeError, tomllib.TOMLDecodeError) as exc: - raise NumericalAcceptanceError( - f"{lane.lane_id} has no valid effective lane configuration" - ) from exc - expected = (lane.accuracy, lane.mode, lane.lc_flow_layout) - if observed != expected: - raise NumericalAcceptanceError( - f"{lane.lane_id} effective lane is {observed!r}; expected {expected!r}" - ) - - -def _validate_runtime_lane( - runtime: object, - lane: AcceptanceLane, - *, - context: str, -) -> None: - observed_mode = getattr(runtime, "execution_mode", None) - physics = getattr(runtime, "physics", None) - observed_accuracy = getattr(physics, "color_accuracy", None) - if observed_mode != lane.mode or observed_accuracy != lane.accuracy: - raise NumericalAcceptanceError( - f"{context} loaded as mode={observed_mode!r}, " - f"color_accuracy={observed_accuracy!r}; expected " - f"{lane.mode!r}/{lane.accuracy!r}" - ) - - -class NumericalAcceptanceHarness: - """Generate each lane once and fail fast through its ordered processes.""" - - def __init__( - self, - fixture: AcceptanceFixture, - *, - artifact_root: Path, - model: object, - ) -> None: - self.fixture = fixture - self.artifact_root = artifact_root.expanduser().resolve(strict=False) - self.artifact_root.mkdir(parents=True, exist_ok=True) - self.model = model - self._artifacts: dict[tuple[str, ArtifactGroup], Path] = {} - - @classmethod - def prepare( - cls, - fixture_path: Path, - *, - work_root: Path, - ) -> NumericalAcceptanceHarness: - root = work_root.expanduser().resolve(strict=False) - fixture = load_acceptance_fixture(fixture_path) - model = prepare_ufo_sm_model(root / "prepared-model") - return cls(fixture, artifact_root=root / "artifacts", model=model) - - def _artifact(self, lane: AcceptanceLane, *, group: ArtifactGroup) -> Path: - key = (lane.lane_id, group) - existing = self._artifacts.get(key) - if existing is not None: - return existing - artifact_name = lane.lane_id if group == "catalog" else f"{lane.lane_id}-extra" - artifact = generate_lane_artifact( - lane, - artifact_path=self.artifact_root / artifact_name, - model=self.model, - group=group, - ) - self._artifacts[key] = artifact - return artifact - - def _assert_case(self, case: AcceptanceCase, lane: AcceptanceLane) -> None: - from pyamplicol import Runtime - - group: ArtifactGroup = "catalog" if case.spec.is_catalog else "extra" - runtime = Runtime.load( - self._artifact(lane, group=group), - process=case.spec.artifact_name, - ) - try: - _validate_runtime_lane(runtime, lane, context=lane.lane_id) - expected = case.expected_for(lane.accuracy) - for precision in lane.evaluation_precisions_for(group): - actual = runtime.evaluate( - case.runtime_momenta(), - precision=precision, - )[0] - assert_relative_match( - actual, - expected, - context=f"{case.spec.case_id}/{lane.lane_id}/p{precision}", - ) - finally: - runtime.clear() - - def assert_catalog_lane(self, lane: AcceptanceLane) -> None: - for case in self.fixture.catalog: - self._assert_case(case, lane) - - def assert_catalog_case(self, case_id: str) -> None: - case = self.fixture.case(case_id) - if not case.spec.is_catalog: - raise NumericalAcceptanceError( - "assert_catalog_case requires a catalog case" - ) - for lane in ACCEPTANCE_LANES: - self._assert_case(case, lane) - - def assert_full_extra(self, case_id: str) -> None: - case = self.fixture.case(case_id) - if case.spec.is_catalog: - raise NumericalAcceptanceError( - "assert_full_extra requires a deliberately non-catalog case" - ) - for lane in FULL_LANES: - self._assert_case(case, lane) - - -def _normalized_report_momenta( - value: object, -) -> tuple[tuple[tuple[float, ...], ...], ...]: - points: list[tuple[tuple[float, ...], ...]] = [] - for raw_point in _sequence(value, "MadGraph provenance.report_momenta"): - rows: list[tuple[float, ...]] = [] - for raw_row in _sequence(raw_point, "MadGraph report point"): - components = _sequence(raw_row, "MadGraph report momentum") - if len(components) != 4: - raise NumericalAcceptanceError( - "MadGraph report momentum must have four components" - ) - row = tuple(float(component) for component in components) - if any(not math.isfinite(component) for component in row): - raise NumericalAcceptanceError("MadGraph report momentum is not finite") - rows.append(row) - points.append(tuple(rows)) - return tuple(points) - - -def _madgraph_measurement( - measurement_value: object, - spec: AcceptanceCaseSpec, -) -> tuple[Decimal, MadGraphReferenceIdentity]: - from tools.performance_report.madgraph import ( - MADGRAPH_DRIVER_SOURCE_SHA256, - madgraph_command_card, - ) - from tools.performance_report.runner import point_digest - - measurement = _mapping(measurement_value, f"MadGraph measurement {spec.case_id}") - if measurement.get("status") != "ok": - raise NumericalAcceptanceError( - f"MadGraph measurement {spec.case_id} is not successful" - ) - matrix_element = _decimal_from_number( - measurement.get("matrix_element"), - f"MadGraph measurement {spec.case_id}.matrix_element", - ) - if matrix_element < 0: - raise NumericalAcceptanceError( - f"MadGraph measurement {spec.case_id} is negative" - ) - expected_point = ( - tuple( - tuple(float(component) for component in row) - for row in validation_momenta(spec.process) - ), - ) - validation = _mapping(measurement.get("validation"), "MadGraph validation") - if ( - validation.get("status") != "ok" - or validation.get("method") != "independent-madgraph-tree-level-oracle" - or validation.get("point_digest") != point_digest(expected_point) - ): - raise NumericalAcceptanceError( - f"MadGraph measurement {spec.case_id} has invalid point evidence" - ) - provenance = _mapping(measurement.get("provenance"), "MadGraph provenance") - model = _mapping(provenance.get("model"), "MadGraph provenance.model") - exact_card = _mapping( - provenance.get("exact_param_card"), - "MadGraph provenance.exact_param_card", - ) - restriction_card = _mapping( - provenance.get("default_restriction"), - "MadGraph provenance.default_restriction", - ) - external_sha = current_model_identity().external_parameters_sha256 - expected_command_card = madgraph_command_card(spec.process) - expected_command_sha = hashlib.sha256( - expected_command_card.encode("utf-8") - ).hexdigest() - driver_sha256 = _sha256( - provenance.get("driver_sha256"), "MadGraph provenance.driver_sha256" - ) - if ( - provenance.get("method") != "madgraph-standalone-custom-fortran-driver" - or provenance.get("command_card") != expected_command_card - or provenance.get("command_card_sha256") != expected_command_sha - or _normalized_report_momenta(provenance.get("report_momenta")) - != expected_point - or model.get("name") != "sm" - or driver_sha256 != MADGRAPH_DRIVER_SOURCE_SHA256 - or exact_card.get("binary64_exact_match") is not True - or restriction_card.get("binary64_exact_match") is not True - or exact_card.get("external_parameters_sha256") != external_sha - or restriction_card.get("external_parameters_sha256") != external_sha - or exact_card.get("format") != "%.14e" - or restriction_card.get("format") != "%.14e" - ): - raise NumericalAcceptanceError( - f"MadGraph measurement {spec.case_id} violates the standalone/model " - "authority contract" - ) - for label, card in ( - ("exact_param_card", exact_card), - ("default_restriction", restriction_card), - ): - count = card.get("external_parameter_count") - if isinstance(count, bool) or not isinstance(count, int) or count < 1: - raise NumericalAcceptanceError( - f"MadGraph measurement {spec.case_id} has invalid {label} coverage" - ) - identity = MadGraphReferenceIdentity( - madgraph_version=_string( - provenance.get("version"), "MadGraph provenance.version" - ), - model_source_sha256=_sha256( - model.get("source_sha256"), "MadGraph provenance.model.source_sha256" - ), - driver_sha256=driver_sha256, - external_parameters_sha256=external_sha, - ) - return matrix_element, identity - - -def _one_madgraph_identity( - identities: Iterable[MadGraphReferenceIdentity], -) -> MadGraphReferenceIdentity: - unique = set(identities) - if len(unique) != 1: - raise NumericalAcceptanceError( - "MadGraph records do not share one version/model/driver identity" - ) - return next(iter(unique)) - - -def ingest_authenticated_madgraph_cache(path: Path) -> MadGraphIngest: - """Load catalog values only after existing campaign-cache validation.""" - - from tools.performance_report.cache import validate_cache - from tools.performance_report.catalog import REPORT_CATALOG - - payload = _read_json(path) - cache = _mapping(payload, "MadGraph cache") - if cache.get("dataset_id") != "reference_madgraph_full": - raise NumericalAcceptanceError( - "MadGraph cache must be the reference_madgraph_full dataset" - ) - entries = _sequence(cache.get("entries"), "MadGraph cache.entries") - expected_cells = { - cell.cell_id: cell - for cell in REPORT_CATALOG.reference_cells() - if cell.dataset_id == "reference_madgraph_full" - } - observed_cell_ids: list[str] = [] - for index, raw_entry in enumerate(entries): - entry = _mapping(raw_entry, f"MadGraph cache.entries[{index}]") - cell_id = entry.get("cell_id") - if not isinstance(cell_id, str) or cell_id not in expected_cells: - raise NumericalAcceptanceError( - f"MadGraph cache contains unknown cell {cell_id!r}" - ) - observed_cell_ids.append(cell_id) - if set(observed_cell_ids) != set(expected_cells): - raise NumericalAcceptanceError( - "MadGraph cache does not cover the complete authenticated " - "reference_madgraph_full dataset" - ) - try: - validate_cache( - payload, - expected_cells=expected_cells.values(), - catalog=REPORT_CATALOG, - ) - except (TypeError, ValueError) as error: - raise NumericalAcceptanceError( - f"MadGraph campaign cache authentication failed: {error}" - ) from error - entries_by_process = { - (entry.get("process_key"), entry.get("n_final")): entry - for entry in (_mapping(raw, "MadGraph cache entry") for raw in entries) - } - values: dict[str, Decimal] = {} - identities: list[MadGraphReferenceIdentity] = [] - for spec in catalog_cases(): - entry = entries_by_process.get((spec.family_key, spec.n_final)) - if entry is None or entry.get("process") != spec.process: - raise NumericalAcceptanceError( - f"MadGraph cache lacks catalog record {spec.case_id}" - ) - value, identity = _madgraph_measurement(entry.get("measurement"), spec) - values[spec.case_id] = value - identities.append(identity) - return MadGraphIngest(values=values, identity=_one_madgraph_identity(identities)) - - -def _gate_point(path: Path, spec: AcceptanceCaseSpec) -> None: - raw_rows = _sequence(_read_json(path), f"gate point {path}") - observed: list[tuple[float, ...]] = [] - for index, raw_row in enumerate(raw_rows): - components = _sequence(raw_row, f"gate point {path}[{index}]") - if len(components) != 4: - raise NumericalAcceptanceError( - f"gate point {path} contains a malformed momentum" - ) - try: - row = tuple(float(component) for component in components) - except (TypeError, ValueError, OverflowError) as error: - raise NumericalAcceptanceError( - f"gate point {path} contains a non-numeric momentum" - ) from error - if any(not math.isfinite(component) for component in row): - raise NumericalAcceptanceError(f"gate point {path} is not finite") - observed.append(row) - expected = tuple( - tuple(float(component) for component in row) - for row in validation_momenta(spec.process) - ) - if tuple(observed) != expected: - raise NumericalAcceptanceError( - f"gate point {path} differs from {spec.case_id} seed-{POINT_SEED}" - ) - - -def ingest_authenticated_madgraph_wave_root(root: Path) -> MadGraphIngest: - """Reuse the complete n=1..4 MadGraph authority prefix from a wave.""" - - gate_root = root.expanduser().resolve(strict=True) - manifest = _mapping(_read_json(gate_root / "manifest.json"), "wave manifest") - if ( - manifest.get("kind") != "pyamplicol-madgraph-ufo-sm-full-p200-wave-gate-v1" - or manifest.get("status") not in {"running", "ok"} - or _integer(manifest.get("seed"), "wave seed") != POINT_SEED - or _integer(manifest.get("max_n"), "wave max_n") < CATALOG_MAX_N_FINAL - or manifest.get("ordering") != "n-final-then-family-id-then-mode" - ): - raise NumericalAcceptanceError( - "wave root cannot supply the ordered n=1..4 MadGraph authority prefix" - ) - - specs = catalog_cases() - plan = _sequence(manifest.get("plan"), "wave plan") - if len(plan) < len(specs): - raise NumericalAcceptanceError("wave plan does not contain all 33 cases") - for ordinal, (raw_plan, spec) in enumerate( - zip(plan[: len(specs)], specs, strict=True) - ): - record = _mapping(raw_plan, f"wave plan[{ordinal}]") - if ( - record.get("cell_ordinal") != ordinal - or record.get("n_final") != spec.n_final - or record.get("family_id") != spec.family_id - or record.get("process_key") != spec.family_key - or record.get("process") != spec.process - ): - raise NumericalAcceptanceError( - f"wave plan[{ordinal}] differs from {spec.case_id}" - ) - - values: dict[str, Decimal] = {} - identities: list[MadGraphReferenceIdentity] = [] - for spec in specs: - case_root = gate_root / f"n{spec.n_final}" / f"family-{spec.family_id:02d}" - _gate_point(case_root / "point-seed-101.json", spec) - value, identity = _madgraph_measurement( - _read_json(case_root / "madgraph-measurement.json"), - spec, - ) - authority = _mapping( - _read_json(case_root / "madgraph-authority.json"), - f"wave authority {spec.case_id}", - ) - if ( - authority.get("process") != spec.process - or authority.get("n_final") != spec.n_final - or authority.get("seed") != POINT_SEED - or _decimal_from_number( - authority.get("madgraph_value"), - f"wave authority {spec.case_id}.madgraph_value", - ) - != value - ): - raise NumericalAcceptanceError( - f"wave authority for {spec.case_id} is inconsistent" - ) - values[spec.case_id] = value - identities.append(identity) - return MadGraphIngest(values=values, identity=_one_madgraph_identity(identities)) - - -def ingest_authenticated_extra_madgraph_root(root: Path) -> MadGraphIngest: - """Reuse the two MadGraph authority records from the successful n=6 gate.""" - - gate_root = root.expanduser().resolve(strict=True) - manifest = _mapping(_read_json(gate_root / "manifest.json"), "stress manifest") - process_keys = ("uu_four_identical_lines", "ee_four_identical_lines") - expected_process_order = [ - {"key": key, "process": spec.process, "n_final": spec.n_final} - for key, spec in zip(process_keys, EXTRA_FULL_COLOUR_CASES, strict=True) - ] - if ( - manifest.get("kind") - != "pyamplicol-authenticated-noncatalog-n6-madgraph-stress-v1" - or manifest.get("status") != "ok" - or manifest.get("stage") != "complete" - or _integer(manifest.get("seed"), "stress seed") != POINT_SEED - or manifest.get("process_order") != expected_process_order - or manifest.get("catalog_policy") - != "direct synthetic CellSpec; REPORT_CATALOG not modified" - ): - raise NumericalAcceptanceError( - "extra root cannot supply the authenticated n=6 MadGraph authority" - ) - - required_checks = ( - "status", - "exact_seed_101_point", - "exact_command_card", - "custom_fortran_method", - "custom_driver_digest", - "exact_generated_process", - ) - values: dict[str, Decimal] = {} - identities: list[MadGraphReferenceIdentity] = [] - for case_ordinal, (key, spec) in enumerate( - zip(process_keys, EXTRA_FULL_COLOUR_CASES, strict=True) - ): - case_root = gate_root / f"case-{case_ordinal + 1:02d}-{key}" - _gate_point(case_root / "point-seed-101.json", spec) - value, identity = _madgraph_measurement( - _read_json(case_root / "madgraph-measurement.json"), - spec, - ) - authority = _mapping( - _read_json(case_root / "madgraph-authority-verification.json"), - f"stress authority {spec.case_id}", - ) - checks = _mapping( - authority.get("checks"), f"stress authority {spec.case_id}.checks" - ) - expected_point = ( - tuple( - tuple(float(component) for component in row) - for row in validation_momenta(spec.process) - ), - ) - if ( - authority.get("process") != spec.process - or authority.get("seed") != POINT_SEED - or _normalized_report_momenta((authority.get("point"),)) != expected_point - or _decimal_from_number( - authority.get("matrix_element_binary64"), - f"stress authority {spec.case_id}.matrix_element_binary64", - ) - != value - or any(checks.get(name) is not True for name in required_checks) - ): - raise NumericalAcceptanceError( - f"stress MadGraph authority for {spec.case_id} is inconsistent" - ) - values[spec.case_id] = value - identities.append(identity) - return MadGraphIngest(values=values, identity=_one_madgraph_identity(identities)) - - -def capture_extra_madgraph_values( - *, - installation: Path, - artifact_root: Path, -) -> MadGraphIngest: - """Capture the two non-catalog MadGraph benchmarks with the shared adapter.""" - - from tools.performance_report.madgraph import ( - MadGraphMeasurementAdapter, - MadGraphSettings, - ) - from tools.performance_report.models import ( - Accuracy, - CellSpec, - ExecutionMode, - MeasurementSpec, - ModelKey, - Workload, - ) - - settings = MadGraphSettings( - installation=installation, - json_model_path=MODEL_SOURCE, - restriction_json_path=MODEL_RESTRICTION, - ) - adapter = MadGraphMeasurementAdapter() - values: dict[str, Decimal] = {} - identities: list[MadGraphReferenceIdentity] = [] - for spec in EXTRA_FULL_COLOUR_CASES: - cell = CellSpec( - dataset_id="numerical_acceptance_extra_full", - process=spec.process, - n_final=spec.n_final, - process_key=spec.case_id, - measurement=MeasurementSpec( - ExecutionMode.MADGRAPH, - ModelKey.UFO_SM, - Accuracy.FULL, - "fortran", - None, - ), - workload=Workload.CONTRACTED, - ) - measurement = adapter.measure( - cell, - artifact_path=artifact_root / spec.artifact_name, - settings=settings, - ) - value, identity = _madgraph_measurement(measurement, spec) - values[spec.case_id] = value - identities.append(identity) - return MadGraphIngest(values=values, identity=_one_madgraph_identity(identities)) - - -@dataclass(frozen=True, slots=True) -class _RuntimeBuildIdentity: - source_revision: str - native_build_inputs_sha256: str - version: str - - -def _current_runtime_identity() -> _RuntimeBuildIdentity: - """Authenticate the installed runtime without consulting the dirty checkout.""" - - try: - import pyamplicol - from pyamplicol._internal.versions import active_native_source_identity - - expected_prefix = (ROOT / ".venv").resolve(strict=True) - observed_prefix = Path(sys.prefix).resolve(strict=True) - package_raw = getattr(pyamplicol, "__file__", None) - if not isinstance(package_raw, str): - raise NumericalAcceptanceError( - "the active pyamplicol package has no filesystem origin" - ) - package_path = Path(package_raw).resolve(strict=True) - if ( - observed_prefix != expected_prefix - or not package_path.is_relative_to(expected_prefix) - or "site-packages" not in package_path.relative_to(expected_prefix).parts - ): - raise NumericalAcceptanceError( - "capture must import pyamplicol from this repository's .venv " - "site-packages" - ) - revision, native_digest = active_native_source_identity() - return _RuntimeBuildIdentity( - source_revision=_revision(revision, "active runtime source revision"), - native_build_inputs_sha256=_sha256( - native_digest, "active runtime native build inputs" - ), - version=_string( - importlib.metadata.version("pyamplicol"), - "active runtime package version", - ), - ) - except NumericalAcceptanceError: - raise - except (ImportError, OSError, RuntimeError, ValueError) as error: - raise NumericalAcceptanceError( - f"could not authenticate the active pyamplicol runtime: {error}" - ) from error - - -def _capture_recurrence_references( - *, - model: object, - artifact_root: Path, - full_values: Mapping[str, Decimal], -) -> tuple[dict[str, Decimal], dict[str, Decimal]]: - """Recheck current recurrence p200/p16 and capture LC/NLC references.""" - - from pyamplicol import Runtime - - artifact_root.mkdir(parents=True, exist_ok=True) - captured: dict[str, dict[str, Decimal]] = {"lc": {}, "nlc": {}} - - for group in cast(tuple[ArtifactGroup, ArtifactGroup], ("catalog", "extra")): - lane = AcceptanceLane("full", "recurrence", 2) - artifact = generate_lane_artifact( - lane, - artifact_path=artifact_root / f"capture-{lane.lane_id}-{group}", - model=model, - group=group, - ) - for spec in lane_case_specs(lane, group=group): - momenta = ( - tuple( - tuple(float(component) for component in row) - for row in validation_momenta(spec.process) - ), - ) - runtime = Runtime.load(artifact, process=spec.artifact_name) - try: - _validate_runtime_lane( - runtime, - lane, - context=f"capture/{spec.case_id}", - ) - precise = runtime.evaluate( - momenta, precision=FULL_CANDIDATE_PRECISION_DIGITS - )[0] - assert_relative_match( - precise, - full_values[spec.case_id], - context=f"capture/{spec.case_id}/full-recurrence/p200", - ) - native = runtime.evaluate(momenta, precision=NATIVE_PRECISION_DIGITS)[0] - assert_relative_match( - native, - full_values[spec.case_id], - context=f"capture/{spec.case_id}/full-recurrence/p16", - ) - finally: - runtime.clear() - - for accuracy in cast(tuple[AccuracyName, AccuracyName], ("lc", "nlc")): - lane = AcceptanceLane(accuracy, "recurrence", 2) - artifact = generate_lane_artifact( - lane, - artifact_path=artifact_root / f"capture-{lane.lane_id}", - model=model, - ) - for spec in lane_case_specs(lane): - momenta = ( - tuple( - tuple(float(component) for component in row) - for row in validation_momenta(spec.process) - ), - ) - runtime = Runtime.load(artifact, process=spec.artifact_name) - try: - _validate_runtime_lane( - runtime, - lane, - context=f"capture/{spec.case_id}", - ) - precise = runtime.evaluate( - momenta, precision=FULL_CANDIDATE_PRECISION_DIGITS - )[0] - precise_decimal = _decimal_from_number( - precise, f"captured {spec.case_id}/{accuracy}/p200" - ) - native = runtime.evaluate(momenta, precision=NATIVE_PRECISION_DIGITS)[0] - assert_relative_match( - native, - precise_decimal, - context=f"capture/{spec.case_id}/{accuracy}/p16", - ) - captured[accuracy][spec.case_id] = precise_decimal - finally: - runtime.clear() - return captured["lc"], captured["nlc"] - - -def _paths_overlap(left: Path, right: Path) -> bool: - return left == right or left.is_relative_to(right) or right.is_relative_to(left) - - -def capture_acceptance_fixture( - *, - madgraph_cache: Path | None = None, - madgraph_wave_root: Path | None = None, - madgraph_installation: Path | None = None, - extra_madgraph_root: Path | None = None, - work_root: Path, - output: Path, -) -> AcceptanceFixture: - """Capture a fixture, refusing to publish until all strict gates pass.""" - - if (madgraph_cache is None) == (madgraph_wave_root is None): - raise NumericalAcceptanceError( - "provide exactly one of madgraph_cache or madgraph_wave_root" - ) - if extra_madgraph_root is None and madgraph_installation is None: - raise NumericalAcceptanceError( - "madgraph_installation is required when extra_madgraph_root is absent" - ) - destination = output.expanduser().resolve(strict=False) - root = work_root.expanduser().resolve(strict=False) - if destination.exists(): - raise NumericalAcceptanceError( - f"refusing to overwrite existing fixture {destination}" - ) - if root.exists(): - raise NumericalAcceptanceError(f"capture work root already exists: {root}") - if _paths_overlap(destination, root): - raise NumericalAcceptanceError( - "fixture output must be outside the disposable capture work root" - ) - for source in ( - madgraph_cache, - madgraph_wave_root, - extra_madgraph_root, - madgraph_installation, - ): - if source is None: - continue - resolved_source = source.expanduser().resolve(strict=False) - if _paths_overlap(destination, resolved_source) or _paths_overlap( - root, resolved_source - ): - raise NumericalAcceptanceError( - "fixture output and work root must not overlap a MadGraph input" - ) - - runtime_identity = _current_runtime_identity() - try: - root.mkdir(parents=True, exist_ok=False) - except FileExistsError as error: - raise NumericalAcceptanceError( - f"capture work root already exists: {root}" - ) from error - - catalog_madgraph = ( - ingest_authenticated_madgraph_cache(madgraph_cache) - if madgraph_cache is not None - else ingest_authenticated_madgraph_wave_root(cast(Path, madgraph_wave_root)) - ) - if extra_madgraph_root is not None: - extra_madgraph = ingest_authenticated_extra_madgraph_root(extra_madgraph_root) - else: - extra_madgraph = capture_extra_madgraph_values( - installation=cast(Path, madgraph_installation), - artifact_root=root / "madgraph-extra", - ) - if catalog_madgraph.identity != extra_madgraph.identity: - raise NumericalAcceptanceError( - "catalog and extra MadGraph records have different authority identities" - ) - full_values = {**catalog_madgraph.values, **extra_madgraph.values} - model = prepare_ufo_sm_model(root / "prepared-model") - lc_values, nlc_values = _capture_recurrence_references( - model=model, - artifact_root=root / "pyamplicol", - full_values=full_values, - ) - payload = build_fixture_payload( - full_values=full_values, - lc_values=lc_values, - nlc_values=nlc_values, - full_reference=catalog_madgraph.identity, - captured_source_revision=runtime_identity.source_revision, - ) - return write_acceptance_fixture(payload, destination) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - subparsers = parser.add_subparsers(dest="command", required=True) - validate = subparsers.add_parser("validate", help="validate an existing fixture") - validate.add_argument("fixture", type=Path) - capture = subparsers.add_parser( - "capture", - help="capture strict full-colour controls and p200 regression references", - ) - catalog_source = capture.add_mutually_exclusive_group(required=True) - catalog_source.add_argument("--madgraph-cache", type=Path) - catalog_source.add_argument("--madgraph-wave-root", type=Path) - capture.add_argument("--madgraph-installation", type=Path) - capture.add_argument( - "--extra-madgraph-root", - type=Path, - help="reuse a successful authenticated non-catalog n=6 stress gate", - ) - capture.add_argument("--work-root", type=Path, required=True) - capture.add_argument("--output", type=Path, required=True) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(argv) - if arguments.command == "validate": - fixture = load_acceptance_fixture(arguments.fixture) - print( - f"validated {len(fixture.catalog)} catalog and " - f"{len(fixture.extra_full_colour)} extra cases" - ) - return 0 - if arguments.command == "capture": - fixture = capture_acceptance_fixture( - madgraph_cache=arguments.madgraph_cache, - madgraph_wave_root=arguments.madgraph_wave_root, - madgraph_installation=arguments.madgraph_installation, - extra_madgraph_root=arguments.extra_madgraph_root, - work_root=arguments.work_root, - output=arguments.output, - ) - print( - f"captured {len(fixture.catalog)} catalog and " - f"{len(fixture.extra_full_colour)} extra cases to " - f"{arguments.output}" - ) - return 0 - raise NumericalAcceptanceError(f"unsupported command {arguments.command!r}") - - -if __name__ == "__main__": - raise SystemExit(main()) - - -__all__ = [ - "ACCEPTANCE_LANES", - "CATALOG_CASE_COUNT", - "CATALOG_MAX_N_FINAL", - "DEFAULT_FIXTURE", - "EXTRA_FULL_COLOUR_CASES", - "FULL_CANDIDATE_PRECISION_DIGITS", - "FULL_LANES", - "LC_ALL_FLOW_UNION_LANES", - "NATIVE_PRECISION_DIGITS", - "POINT_SEED", - "RELATIVE_TOLERANCE", - "AcceptanceCase", - "AcceptanceCaseSpec", - "AcceptanceFixture", - "AcceptanceLane", - "MadGraphReferenceIdentity", - "NumericalAcceptanceError", - "NumericalAcceptanceHarness", - "NumericalAcceptanceMismatch", - "build_fixture_payload", - "capture_acceptance_fixture", - "catalog_cases", - "compare_relative", - "current_model_identity", - "ingest_authenticated_extra_madgraph_root", - "ingest_authenticated_madgraph_cache", - "ingest_authenticated_madgraph_wave_root", - "lane_case_specs", - "lane_process_set", - "lane_run_config", - "load_acceptance_fixture", - "main", - "parse_acceptance_fixture", - "prepare_ufo_sm_model", - "validation_momenta", - "write_acceptance_fixture", -] diff --git a/pyamplicol/tools/developer/on_the_fly_high_multiplicity.py b/pyamplicol/tools/developer/on_the_fly_high_multiplicity.py deleted file mode 100644 index 60ed89aff4..0000000000 --- a/pyamplicol/tools/developer/on_the_fly_high_multiplicity.py +++ /dev/null @@ -1,2834 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Guarded, process-parametric high-multiplicity LC study for on-the-fly mode. - -Run ``selected`` first: it creates the multiplicity's sole fresh OTF artifact. -Run ``all-flow`` separately with ``--candidate-artifact`` pointing at that -artifact. Selected n=5/6/7 cells use exactly one independent authority: -authenticated original AmpliCol where supported, otherwise recurrence for the -four-open-quark-line family. Selected n=8/9 and every all-flow invocation are -intentionally OTF-only feasibility probes. -""" - -from __future__ import annotations - -import argparse -import json -import math -import os -import re -import sys -import time -from collections.abc import Callable, Mapping, Sequence -from contextlib import ExitStack -from dataclasses import dataclass, replace -from pathlib import Path -from typing import Any -from unittest import mock - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -import pyamplicol.generation.service as generation_service # noqa: E402 -from pyamplicol import ( # noqa: E402 - BenchmarkRunner, - Generator, - ModelSource, - ProcessRequest, - Runtime, -) -from pyamplicol.api.errors import ArtifactError, EvaluationError # noqa: E402 -from pyamplicol.artifacts import load_manifest # noqa: E402 -from pyamplicol.config import ( # noqa: E402 - ColorConfig, - EvaluatorConfig, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationRelationDiscoveryConfig, - GenerationValidationConfig, - JITConfig, - RunConfig, -) -from pyamplicol.models.builtin.validation import generic_validation_point # noqa: E402 -from tools.ci.memory_watchdog import GIB, run_guarded # noqa: E402 -from tools.developer import legacy_amplicol # noqa: E402 -from tools.developer import on_the_fly_lc_gate as n4 # noqa: E402 -from tools.developer.legacy_oracle.model import ( # noqa: E402 - PINNED_REFERENCE_REVISION, -) -from tools.performance_report.artifacts import ( # noqa: E402 - ArtifactStore, - ArtifactStoreError, -) -from tools.performance_report.cache import validate_measurement # noqa: E402 -from tools.performance_report.catalog import REPORT_CATALOG # noqa: E402 -from tools.performance_report.legacy import ( # noqa: E402 - LegacyAdapterError, - _canonical_mapped_color_word, - _initial_state_count, -) -from tools.performance_report.models import Accuracy, Workload # noqa: E402 -from tools.performance_report.runner import ( # noqa: E402 - RunnerError, - SelectorContract, - derive_selector_contract, - point_digest, - validate_selector_contract, -) -from tools.performance_report.selector_policy import ( # noqa: E402 - SelectorPolicyError, - canonical_lc_flow_word, - fixed_selector_helicity, - selector_color_flow_id, - selector_helicity_id, -) -from tools.performance_report.service import ( # noqa: E402 - ReportPaths, - validate_profile_name, -) -from tools.performance_report.source_identity import ( # noqa: E402 - ReportSourceIdentity, - ReportSourceIdentityError, - require_eligible_report_source, -) - -KIND = "pyamplicol-on-the-fly-high-multiplicity-study" -SCHEMA_VERSION = 6 -SUPPORTED_PROCESS_IDS = (7, 8, 11, 13, 14, 15) -SUPPORTED_MULTIPLICITIES = (5, 6, 7, 8, 9) -SUPPORTED_PROCESS_MULTIPLICITIES = { - 7: (5, 6, 7, 8, 9), - 8: (5, 6, 7, 8, 9), - 11: (5, 6, 7), - 13: (5, 6, 7), - 14: (6, 7), - 15: (5, 6, 7), -} -AMPLI_COL_AUTHORITY_IDS = frozenset({7, 8, 11, 13, 15}) -AUTHORITY_AMPLICOL = "amplicol" -AUTHORITY_RECURRENCE = "recurrence" -AUTHORITY_OTF_ONLY = "otf-only" -LIFECYCLE_EXHAUSTIVE = "exhaustive-clear-rebuild" -LIFECYCLE_LEAN = "lean-retained-requested-family" -REQUESTED_COLD_WARMUP_KIND = "on-the-fly-requested-workload-cold-warmup-v2" -SEEDS = n4.SEEDS -BATCH_SIZE = 128 -WARMUP_RUNS = 2 -MINIMUM_SAMPLES = 5 -OTF_QUERY_CONSTRUCTION_THREADS = 4 -RECURRENCE_GENERATION_THREADS = 1 -WATCHDOG_BYTES = 30 * GIB -STATE_KIND = "rusticol-on-the-fly-runtime-state-census-v1" -STATE_INSPECTION_KEY = "on_the_fly_state" -STATE_FAMILY_CACHE_POLICY = "last-family-only" -STATE_FAMILY_CACHE_LIMIT = 1 -STATE_COUNTS = ( - "process_preparation_count", - "retained_family_count", - "pending_family_count", - "retained_selection_count", - "retained_request_count", - "retained_amplitude_destination_count", - "retained_executor_handle_count", - "retained_query_local_trace_count", - "retained_embedded_lookup_key_count", - "semantic_executor_binding_count", -) -COMPACT_ZERO_COUNTS = ( - "pending_family_count", - "retained_query_local_trace_count", - "retained_embedded_lookup_key_count", -) -ACTIVE_COUNT_FIELDS = ( - "query_count", - "union_unique_current_count", - "union_unique_current_component_count", - "union_source_rows", - "union_contribution_rows", - "union_finalization_rows", - "union_closure_rows", - "union_amplitude_destination_count", - "union_source_executor_call_groups", - "union_contribution_executor_call_groups", - "union_finalization_executor_call_groups", - "union_closure_executor_call_groups", -) -OPERATION_ROLES = ("source", "contribution", "finalization", "closure") -STATE_FIELDS = frozenset( - { - "kind", - "process_id", - "family_cache_policy", - "family_cache_limit", - *STATE_COUNTS, - "active_family_union_census", - } -) - -Point = tuple[tuple[float, ...], ...] -Points = tuple[Point, ...] - - -class StudyError(RuntimeError): - """The bounded study contract was not satisfied.""" - - -@dataclass(frozen=True, slots=True) -class Case: - process_table_id: int - process_key: str - multiplicity: int - process: str - process_id: str - pdgs: tuple[int, ...] - - -@dataclass(frozen=True, slots=True) -class Selector: - flow_word: tuple[int, ...] - flow_id: str - helicities: tuple[int, ...] - helicity_id: str - - def mapping(self, points: Points) -> dict[str, object]: - return { - "selected_color_flow_ids": [self.flow_id], - "selected_color_words": [list(self.flow_word)], - "all_flow_helicity_ids": [self.helicity_id], - "all_flow_source_helicities": { - str(index): value - for index, value in enumerate(self.helicities, start=1) - }, - "point_digest": point_digest(points), - } - - -@dataclass(frozen=True, slots=True) -class Evaluation: - total: tuple[object, ...] - resolved: object | None - total_vs_resolved: dict[str, object] | None = None - - -@dataclass(frozen=True, slots=True) -class AmplicolReference: - selector: Selector - contract: SelectorContract - selector_contract: dict[str, object] - matrix_element: float - timing: dict[str, object] - lineage: dict[str, object] - library_path: Path | None = None - process_row: tuple[int, int] | None = None - - -def _positive_float(text: str) -> float: - value = float(text) - if not math.isfinite(value) or value <= 0.0: - raise argparse.ArgumentTypeError("must be a positive finite number") - return value - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", required=True, type=Path) - parser.add_argument( - "--process-id", required=True, type=int, choices=SUPPORTED_PROCESS_IDS - ) - parser.add_argument( - "--multiplicity", required=True, type=int, choices=SUPPORTED_MULTIPLICITIES - ) - parser.add_argument( - "--workload", choices=("selected", "all-flow"), default="selected" - ) - parser.add_argument("--prepared-model", type=Path) - parser.add_argument( - "--reference-repo-root", - type=Path, - help="repository root owning the authenticated AmpliCol profile; " - "required only for AmpliCol-authority selected cells", - ) - parser.add_argument( - "--reference-profile", - help="ReportPaths profile containing authenticated AmpliCol currents; " - "required only for AmpliCol-authority selected cells", - ) - parser.add_argument( - "--candidate-artifact", - type=Path, - help="sole OTF artifact created by the selected invocation", - ) - parser.add_argument( - "--selected-report", - type=Path, - help="passed selected-workload report that created the OTF candidate", - ) - parser.add_argument("--target-runtime", type=_positive_float, default=5.0) - parser.add_argument("--worker", action="store_true", help=argparse.SUPPRESS) - return parser - - -def _case(process_table_id: int, multiplicity: int) -> Case: - if process_table_id not in SUPPORTED_PROCESS_IDS: - raise StudyError(f"unsupported process-table ID {process_table_id}") - if multiplicity not in SUPPORTED_MULTIPLICITIES: - raise StudyError(f"unsupported multiplicity n={multiplicity}") - if multiplicity not in SUPPORTED_PROCESS_MULTIPLICITIES[process_table_id]: - raise StudyError( - f"process-table ID {process_table_id} does not define a planned " - f"high-multiplicity cell at n={multiplicity}" - ) - family = next( - ( - candidate - for candidate in REPORT_CATALOG.process_families - if candidate.identifier == process_table_id - ), - None, - ) - expected_keys = { - 7: "dd_tt_jets", - 8: "gg_gluons", - 11: "dd_ttzh_jets", - 13: "dd_3q_lines", - 14: "dd_4q_lines", - 15: "dd_3q_identical_lines", - } - if family is None or family.key != expected_keys[process_table_id]: - raise StudyError("process-table catalog identity changed") - process = family.process(multiplicity) - if process is None: - raise StudyError("process-table family does not define this multiplicity") - bases = { - 7: (1, -1, 6, -6), - 8: (21, 21, 21, 21), - 11: (1, -1, 6, -6, 23, 25), - 13: (1, -1, 2, -2, 3, -3), - 14: (1, -1, 2, -2, 3, -3, 4, -4), - 15: (1, -1, 2, -2, 2, -2), - } - base_final_count = len(bases[process_table_id]) - 2 - pdgs = ( - *bases[process_table_id], - *(21 for _ in range(multiplicity - base_final_count)), - ) - return Case( - process_table_id, - family.key, - multiplicity, - process, - f"otf_p{process_table_id}_{family.key}_n{multiplicity}", - pdgs, - ) - - -def _lifecycle_policy(case: Case, workload: str) -> dict[str, object]: - if workload not in {"selected", "all-flow"}: - raise StudyError(f"unsupported lifecycle workload {workload!r}") - lean = case.multiplicity >= 7 or ( - case.process_table_id == 8 and case.multiplicity >= 6 - ) - if not lean: - return { - "mode": LIFECYCLE_EXHAUSTIVE, - "retain_requested_family_after_cold_warmup": False, - "clear_rebuild": "required", - "reason": "lower-cost cell provides the exhaustive lifecycle proof", - "expected_prior_campaign_prerequisite": None, - } - baselines = tuple( - multiplicity - for multiplicity in SUPPORTED_PROCESS_MULTIPLICITIES[case.process_table_id] - if multiplicity < case.multiplicity - and not ( - multiplicity >= 7 or (case.process_table_id == 8 and multiplicity >= 6) - ) - ) - if not baselines: - raise StudyError("lean lifecycle has no exhaustive lower-cost baseline") - baseline = max(baselines) - return { - "mode": LIFECYCLE_LEAN, - "retain_requested_family_after_cold_warmup": True, - "clear_rebuild": "omitted", - "reason": ( - "the requested family is high-cost; same-workload clear/rebuild at " - "the recorded lower multiplicity is an expected prior campaign " - "prerequisite not authenticated by this report" - ), - "expected_prior_campaign_prerequisite": { - "evidence_status": "expected-not-authenticated-by-this-report", - "process_table_id": case.process_table_id, - "multiplicity": baseline, - "workload": workload, - "policy": LIFECYCLE_EXHAUSTIVE, - }, - } - - -def _clear_rebuild_evidence(policy: Mapping[str, object]) -> dict[str, object]: - omitted = policy.get("mode") == LIFECYCLE_LEAN - return { - "status": "omitted" if omitted else "performed", - "reason": policy["reason"], - "expected_prior_campaign_prerequisite": policy[ - "expected_prior_campaign_prerequisite" - ], - } - - -def _authority_kind(case: Case, workload: str) -> str: - if workload == "all-flow": - return AUTHORITY_OTF_ONLY - if workload != "selected": - raise StudyError(f"unsupported workload {workload!r}") - if case.process_table_id == 14: - return AUTHORITY_RECURRENCE - if case.multiplicity >= 8: - return AUTHORITY_OTF_ONLY - if case.process_table_id in AMPLI_COL_AUTHORITY_IDS: - return AUTHORITY_AMPLICOL - raise StudyError("selected cell has no declared authority policy") - - -def _validate_arguments(args: argparse.Namespace) -> None: - case = _case(args.process_id, args.multiplicity) - authority = _authority_kind(case, args.workload) - has_reference_root = args.reference_repo_root is not None - has_reference_profile = args.reference_profile is not None - if has_reference_root != has_reference_profile: - raise StudyError( - "--reference-repo-root and --reference-profile must be supplied together" - ) - if authority == AUTHORITY_AMPLICOL: - if not has_reference_root: - raise StudyError("AmpliCol-authority selected cells require reference args") - if ( - not isinstance(args.reference_profile, str) - or not args.reference_profile.strip() - ): - raise StudyError("--reference-profile must be non-empty") - elif has_reference_root: - raise StudyError("reference args are only valid for AmpliCol-authority cells") - if args.workload == "selected": - if args.prepared_model is None: - raise StudyError("selected requires --prepared-model") - if args.candidate_artifact is not None: - raise StudyError("selected creates the candidate artifact") - if args.selected_report is not None: - raise StudyError("selected creates, rather than consumes, its report") - elif args.candidate_artifact is None: - raise StudyError("all-flow requires --candidate-artifact") - elif args.selected_report is None: - raise StudyError("all-flow requires --selected-report") - elif args.prepared_model is not None: - raise StudyError( - "all-flow reuses the selected artifact without --prepared-model" - ) - - -def _existing(path: Path, *, directory: bool, label: str) -> Path: - result = Path(os.path.abspath(path.expanduser())) - if not (result.is_dir() if directory else result.is_file()): - raise StudyError(f"{label} does not exist: {result}") - return result - - -def _points(case: Case) -> Points: - return tuple( - tuple(tuple(map(float, particle.momentum)) for particle in point) - for point in ( - generic_validation_point(case.process, sqrt_s=1000.0, seed=seed) - for seed in SEEDS - ) - ) - - -def _timing_points(points: Points) -> Points: - if not points: - raise StudyError("benchmark requires the seed-101 correctness point") - return (points[0],) * BATCH_SIZE - - -def _colored_source_labels(case: Case) -> tuple[int, ...]: - """Return the exact public source labels carried by an LC flow word.""" - - labels = tuple( - label - for label, pdg in enumerate(case.pdgs, start=1) - if abs(pdg) in {1, 2, 3, 4, 5, 6, 21} - ) - if not labels: - raise StudyError("LC selector process has no colored external sources") - return labels - - -def _selector_from_contract(case: Case, contract: SelectorContract) -> Selector: - expected_helicities = fixed_selector_helicity(case.pdgs) - expected_helicity_id = selector_helicity_id(expected_helicities) - expected_sources = tuple(enumerate(expected_helicities, start=1)) - if ( - len(contract.selected_color_words) != 1 - or len(contract.selected_color_flow_ids) != 1 - or contract.runtime_all_flow_helicity_ids != (expected_helicity_id,) - or contract.all_flow_source_helicities != expected_sources - ): - raise StudyError("AmpliCol selector contract has the wrong process axis") - word = contract.selected_color_words[0] - flow_id = contract.selected_color_flow_ids[0] - if ( - len(word) != len(_colored_source_labels(case)) - or set(word) != set(_colored_source_labels(case)) - or selector_color_flow_id(word) != flow_id - ): - raise StudyError("AmpliCol selector flow does not round-trip") - return Selector(word, flow_id, expected_helicities, expected_helicity_id) - - -def _compact_selector_context( - runtime: object, - case: Case, - requested: tuple[str, ...], -) -> dict[str, object]: - backend = getattr(runtime, "_backend", None) - operation = getattr(backend, "_on_the_fly_benchmark_context", None) - if not callable(operation): - raise StudyError("candidate has no compact on-the-fly selector context") - raw = operation(requested) - if not isinstance(raw, Mapping): - raise StudyError("candidate compact selector context is unavailable") - selected = raw.get("selected_color_ids") - if ( - raw.get("process_id") != case.process_id - or raw.get("process_expression") != case.process - or raw.get("color_accuracy") != "lc" - or isinstance(raw.get("helicity_count"), bool) - or not isinstance(raw.get("helicity_count"), int) - or int(raw["helicity_count"]) < 1 - or isinstance(raw.get("color_count"), bool) - or not isinstance(raw.get("color_count"), int) - or int(raw["color_count"]) < 1 - or not isinstance(selected, Sequence) - or isinstance(selected, (str, bytes)) - or len(selected) != len(requested) - or any(not isinstance(value, str) or not value for value in selected) - ): - raise StudyError("candidate compact selector context has the wrong identity") - return { - "process_id": case.process_id, - "process_expression": case.process, - "color_accuracy": "lc", - "helicity_count": raw["helicity_count"], - "color_count": raw["color_count"], - "requested_color_ids": list(requested), - "selected_color_ids": list(selected), - } - - -def _flow_word(flow_id: str) -> tuple[int, ...]: - if not flow_id.startswith("flow:"): - raise StudyError("compact selector did not return a semantic flow ID") - try: - word = canonical_lc_flow_word( - tuple(int(token) for token in flow_id.removeprefix("flow:").split(",")) - ) - except (SelectorPolicyError, ValueError) as error: - raise StudyError( - "compact selector returned an invalid semantic flow ID" - ) from error - if selector_color_flow_id(word) != flow_id: - raise StudyError("compact selector flow ID does not round-trip") - return word - - -def _selector_from_compact_ordinal_one( - runtime: object, - case: Case, - points: Points, -) -> tuple[Selector, SelectorContract, dict[str, object]]: - """Derive the first labelled flow through the compact seed axis only.""" - - context = _compact_selector_context(runtime, case, ("1",)) - selected = context["selected_color_ids"] - if not isinstance(selected, list) or len(selected) != 1: - raise StudyError("compact ordinal 1 did not resolve exactly one flow") - flow_id = selected[0] - if not isinstance(flow_id, str): - raise StudyError("compact ordinal 1 did not resolve a semantic flow ID") - flow_word = _flow_word(flow_id) - if len(flow_word) != len(_colored_source_labels(case)) or set(flow_word) != set( - _colored_source_labels(case) - ): - raise StudyError("compact ordinal-1 flow has the wrong external axis") - helicities = fixed_selector_helicity(case.pdgs) - selector = Selector( - flow_word=flow_word, - flow_id=flow_id, - helicities=helicities, - helicity_id=selector_helicity_id(helicities), - ) - contract = SelectorContract( - selected_color_flow_ids=(selector.flow_id,), - selected_color_words=(selector.flow_word,), - all_flow_helicity_ids=(selector.helicity_id,), - all_flow_source_helicities=tuple(enumerate(selector.helicities, start=1)), - point_digest=point_digest(points), - ) - context["selector_source"] = "compact-seed-one-based-color-ordinal-1" - context["resolved_semantic_flow_id"] = flow_id - return selector, contract, context - - -def _reference_cell(case: Case, workload: str) -> object: - expected_workload = ( - Workload.SELECTED_FLOW if workload == "selected" else Workload.ALL_FLOW - ) - matches = tuple( - cell - for cell in REPORT_CATALOG.reference_cells() - if cell.process_key == case.process_key - and cell.n_final == case.multiplicity - and cell.measurement.accuracy is Accuracy.LC - and cell.workload is expected_workload - ) - if len(matches) != 1: - raise StudyError("AmpliCol reference catalog cell is not unique") - cell = matches[0] - if cell.process != case.process: - raise StudyError("AmpliCol reference process differs from the process table") - return cell - - -def _required_reference_number( - measurement: Mapping[str, object], field: str, *, allow_zero: bool = False -) -> float: - value = measurement.get(field) - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise StudyError(f"AmpliCol reference omitted {field}") - result = float(value) - if not math.isfinite(result) or result < 0.0 or (result == 0.0 and not allow_zero): - raise StudyError(f"AmpliCol reference has invalid {field}") - return result - - -def _required_reference_sample_count(measurement: Mapping[str, object]) -> int: - value = measurement.get("sample_count") - if isinstance(value, bool) or not isinstance(value, int) or value < MINIMUM_SAMPLES: - raise StudyError("AmpliCol reference has insufficient actual samples") - return value - - -def _active_report_source() -> ReportSourceIdentity: - try: - return require_eligible_report_source(ROOT) - except ReportSourceIdentityError as error: - raise StudyError(f"active report source is ineligible: {error}") from error - - -def _authenticate_reference_source( - provenance: Mapping[str, object], active_source: ReportSourceIdentity -) -> None: - """Keep the current exact source-lineage policy isolated for later audit.""" - - source_fields = { - "revision": PINNED_REFERENCE_REVISION, - "report_source_revision": active_source.revision, - "report_measured_source_revision": active_source.revision, - "report_source_tree": active_source.tree, - "report_measured_source_tree": active_source.tree, - "report_source_clean": True, - } - if any( - provenance.get(field) != expected for field, expected in source_fields.items() - ): - raise StudyError("AmpliCol reference source differs from the active source") - - -def _reference_timing_contract( - provenance: Mapping[str, object], - case: Case, - workload: str, - target_runtime: float, -) -> dict[str, object]: - manual = provenance.get("manual_campaign") - if not isinstance(manual, Mapping): - raise StudyError("AmpliCol reference omitted manual-campaign timing evidence") - expected_workload = ( - Workload.SELECTED_FLOW if workload == "selected" else Workload.ALL_FLOW - ) - expected_cell = _reference_cell(case, workload) - expected_identity = { - "accuracy": "lc", - "backend": "fortran", - "cell_id": expected_cell.cell_id, - "dataset_id": "reference_amplicol_lc", - "execution_mode": "amplicol", - "model": None, - "n_final": case.multiplicity, - "process": case.process, - "process_key": case.process_key, - "variant": None, - "workload": expected_workload.value, - } - identity = manual.get("cell_identity") - batch_size = manual.get("batch_size") - warmup_runs = manual.get("warmup_runs") - minimum_samples = manual.get("minimum_samples") - recorded_target = manual.get("target_runtime_seconds") - if not isinstance(identity, Mapping) or dict(identity) != expected_identity: - raise StudyError("AmpliCol manual-campaign cell identity is mismatched") - if batch_size != BATCH_SIZE: - raise StudyError("AmpliCol manual-campaign batch size is mismatched") - if warmup_runs != WARMUP_RUNS: - raise StudyError("AmpliCol manual-campaign warm-up count is mismatched") - if ( - isinstance(minimum_samples, bool) - or not isinstance(minimum_samples, int) - or minimum_samples < MINIMUM_SAMPLES - ): - raise StudyError("AmpliCol manual-campaign sample minimum is insufficient") - if ( - isinstance(recorded_target, bool) - or not isinstance(recorded_target, (int, float)) - or float(recorded_target) != target_runtime - ): - raise StudyError("AmpliCol manual-campaign target runtime is mismatched") - if provenance.get("generation_timing_is_workload_specific") is not True: - raise StudyError("AmpliCol generation timing is not workload-specific") - return { - "batch_size": BATCH_SIZE, - "warmup_runs": WARMUP_RUNS, - "minimum_samples": int(minimum_samples), - "target_runtime_seconds": target_runtime, - "cell_identity": expected_identity, - "generation_timing_is_workload_specific": True, - } - - -def _rebind_reference_selector( - raw_contract: Mapping[str, object], case: Case, points: Points -) -> tuple[SelectorContract, SelectorContract, Selector]: - try: - stored_contract = SelectorContract.from_mapping(raw_contract) - except (TypeError, ValueError) as error: - raise StudyError("AmpliCol reference selector contract is invalid") from error - singleton_digest = point_digest((points[0],)) - if stored_contract.point_digest != singleton_digest: - raise StudyError("AmpliCol selector digest is not the seed-101 singleton") - rebound_contract = replace(stored_contract, point_digest=point_digest(points)) - if { - field: value - for field, value in rebound_contract.as_dict().items() - if field != "point_digest" - } != { - field: value - for field, value in stored_contract.as_dict().items() - if field != "point_digest" - }: - raise StudyError("AmpliCol selector rebinding changed a physical axis") - return ( - stored_contract, - rebound_contract, - _selector_from_contract(case, rebound_contract), - ) - - -def _load_amplicol_reference( - repo_root: Path, - profile: str, - case: Case, - workload: str, - points: Points, - target_runtime: float, - active_source: ReportSourceIdentity, -) -> AmplicolReference: - root = _existing(repo_root, directory=True, label="reference repository root") - try: - validated_profile = validate_profile_name(profile) - docs = root / "docs" / "performance_reports" / validated_profile - artifacts = docs / "campaign_artifacts" - paths = ReportPaths.from_repo( - root, - docs_dir=docs, - artifact_root=artifacts, - coordination_root=artifacts / "coordination", - ) - except ValueError as error: - raise StudyError(f"invalid AmpliCol reference profile: {profile!r}") from error - for path, label in ( - (paths.docs_dir, "reference report profile"), - (paths.artifact_root, "reference artifact root"), - (paths.coordination_root, "reference coordination root"), - ): - _existing(path, directory=True, label=label) - cell = _reference_cell(case, workload) - store = ArtifactStore( - artifact_root=paths.artifact_root, - lock_root=paths.coordination_root, - current_publication_paths=paths, - ) - try: - current = store.load_current(cell.cell_id) - assert current is not None - validate_measurement(current.result, expected_cell=cell) - except (ArtifactStoreError, FileNotFoundError, ValueError) as error: - raise StudyError( - f"AmpliCol reference current is not authenticated: {cell.cell_id}" - ) from error - if current.cell_id != cell.cell_id or current.result.get("status") != "ok": - raise StudyError("AmpliCol reference current has the wrong workload identity") - - raw_contract = current.result.get("selector_contract") - if not isinstance(raw_contract, Mapping): - raise StudyError("AmpliCol reference omitted its selector contract") - stored_contract, rebound_contract, selector = _rebind_reference_selector( - raw_contract, case, points - ) - - measurement = current.result - timing = { - "execution_mode": "amplicol", - "cell_id": cell.cell_id, - "generation_seconds": _required_reference_number( - measurement, "generation_seconds" - ), - "wall_seconds_per_point": _required_reference_number( - measurement, "wall_seconds_per_point" - ), - "evaluator_seconds_per_point": _required_reference_number( - measurement, "execution_seconds_per_point" - ), - "relative_standard_error": _required_reference_number( - measurement, "relative_standard_error", allow_zero=True - ), - "sample_count": _required_reference_sample_count(measurement), - } - matrix_element = _required_reference_number( - measurement, "matrix_element", allow_zero=True - ) - raw_artifact = measurement.get("artifact") - artifact_path = ( - raw_artifact.get("path") if isinstance(raw_artifact, Mapping) else None - ) - process_row = ( - raw_artifact.get("process_row") if isinstance(raw_artifact, Mapping) else None - ) - row_match = ( - re.fullmatch(r"group:([1-9][0-9]*):integral:([1-9][0-9]*)", process_row) - if isinstance(process_row, str) - else None - ) - if not isinstance(artifact_path, str) or row_match is None: - raise StudyError("AmpliCol reference omitted its generated-library row") - recorded_artifact_path = _existing( - Path(artifact_path), - directory=True, - label="AmpliCol current-owned artifact", - ) - expected_artifact_path = _existing( - current.result_path.parent / "artifact", - directory=True, - label="AmpliCol authenticated attempt artifact", - ) - if recorded_artifact_path != expected_artifact_path: - raise StudyError("AmpliCol reference artifact is outside its current attempt") - library_path = _existing( - recorded_artifact_path / "selected-flow-generated-library", - directory=True, - label="AmpliCol selected-flow generated-library snapshot", - ) - executable = _existing( - library_path / "amplicol_library_benchmark", - directory=False, - label="AmpliCol selected-flow replay executable", - ) - if not os.access(executable, os.X_OK): - raise StudyError("AmpliCol selected-flow replay executable is not executable") - _existing( - library_path / "processes.txt", - directory=False, - label="AmpliCol selected-flow process table", - ) - _existing( - library_path / "Library", - directory=True, - label="AmpliCol selected-flow serialized library", - ) - if not tuple(library_path.glob("libamp*.so")): - raise StudyError("AmpliCol selected-flow snapshot has no shared libraries") - parsed_process_row = (int(row_match.group(1)), int(row_match.group(2))) - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - raise StudyError("AmpliCol reference omitted source provenance") - _authenticate_reference_source(provenance, active_source) - timing_contract = _reference_timing_contract( - provenance, case, workload, target_runtime - ) - return AmplicolReference( - selector=selector, - contract=rebound_contract, - selector_contract=rebound_contract.as_dict(), - matrix_element=matrix_element, - timing=timing, - lineage={ - "profile": profile, - "repo_root": str(paths.repo_root), - "artifact_root": str(paths.artifact_root), - "cell_id": cell.cell_id, - "attempt_id": current.attempt_id, - "manifest_sha256": current.manifest_sha256, - "result_path": str(current.result_path), - "process_table_id": case.process_table_id, - "process_key": case.process_key, - "process": case.process, - "multiplicity": case.multiplicity, - "workload": workload, - "source_revision": active_source.revision, - "source_tree": active_source.tree, - "original_amplicol_revision": PINNED_REFERENCE_REVISION, - "timing_contract": timing_contract, - "stored_selector_point_digest": stored_contract.point_digest, - "correctness_selector_point_digest": rebound_contract.point_digest, - "selector_rebinding": "point-digest-only", - "stored_matrix_element": matrix_element, - "selected_flow_generated_library": str(library_path), - "process_row": { - "group": parsed_process_row[0], - "integral": parsed_process_row[1], - }, - }, - library_path=library_path, - process_row=parsed_process_row, - ) - - -def _lower_hex(value: object, length: int, label: str) -> str: - if ( - not isinstance(value, str) - or len(value) != length - or value != value.lower() - or any(character not in "0123456789abcdef" for character in value) - ): - raise StudyError(f"{label} is not a lowercase hexadecimal identity") - return value - - -def _artifact_identity( - path: Path, - runtime: object, - case: Case, - expected_mode: str, -) -> dict[str, object]: - try: - manifest = load_manifest(path, verify_payloads=False) - except (ArtifactError, OSError) as error: - raise StudyError(f"cannot load artifact manifest: {path}") from error - records = tuple(manifest.processes) - if len(records) != 1: - raise StudyError("study artifacts must contain exactly one process") - process = records[0] - if ( - process.get("id") != case.process_id - or process.get("expression") != case.process - or tuple(process.get("external_pdgs", ())) != case.pdgs - or process.get("color_accuracy") != "lc" - ): - raise StudyError("artifact manifest has the wrong process identity") - - artifact_id = _lower_hex(manifest.artifact_id, 64, "manifest artifact ID") - if ( - getattr(runtime, "artifact_id", None) != artifact_id - or getattr(runtime, "execution_mode", None) != expected_mode - or getattr(runtime, "representative_process_key", None) != case.process_id - ): - raise StudyError("runtime identity differs from its artifact manifest") - backend = getattr(runtime, "_backend", None) - native = getattr(backend, "_runtime", None) - native_artifact_id = getattr(native, "artifact_id", None) - metadata = getattr(backend, "_native_metadata", None) - if native_artifact_id != artifact_id or not isinstance(metadata, Mapping): - raise StudyError("native runtime omitted its authenticated artifact identity") - if ( - metadata.get("execution_mode") != expected_mode - or metadata.get("process") != case.process - or metadata.get("process_key") != case.process_id - or metadata.get("representative_process") != case.process - or metadata.get("representative_process_key") != case.process_id - or metadata.get("color_accuracy") != "lc" - or tuple(metadata.get("external_pdg_order", ())) != case.pdgs - or metadata.get("external_count") != len(case.pdgs) - ): - raise StudyError("native runtime metadata has the wrong process identity") - - producer = manifest.producer - source_revision = _lower_hex( - producer.get("git_revision"), 40, "producer source revision" - ) - native_digest = _lower_hex( - producer.get("native_build_inputs_sha256"), - 64, - "producer native-input digest", - ) - model_identity = dict(manifest.model) - return { - "path": str(manifest.root), - "artifact_id": artifact_id, - "native_authenticated_artifact_id": native_artifact_id, - "execution_mode": expected_mode, - "process_id": case.process_id, - "process_expression": case.process, - "external_pdgs": list(case.pdgs), - "producer_identity": { - "source_revision": source_revision, - "native_build_inputs_sha256": native_digest, - }, - "model_identity": model_identity, - } - - -def _common_producer_identity( - artifacts: Mapping[str, Mapping[str, object]], -) -> dict[str, object]: - identities = tuple(record.get("producer_identity") for record in artifacts.values()) - if not identities or any(not isinstance(value, Mapping) for value in identities): - raise StudyError("artifact producer identity evidence is incomplete") - first = dict(identities[0]) # type: ignore[arg-type] - if any(dict(value) != first for value in identities[1:]): # type: ignore[arg-type] - raise StudyError("study artifacts were produced by different native sources") - return first - - -def _common_model_identity( - artifacts: Mapping[str, Mapping[str, object]], -) -> dict[str, object]: - identities = tuple(record.get("model_identity") for record in artifacts.values()) - if not identities or any(not isinstance(value, Mapping) for value in identities): - raise StudyError("artifact model identity evidence is incomplete") - first = dict(identities[0]) # type: ignore[arg-type] - if any(dict(value) != first for value in identities[1:]): # type: ignore[arg-type] - raise StudyError("study artifacts were generated from different models") - return first - - -def _candidate_source_binding( - active: ReportSourceIdentity, producer: Mapping[str, object] -) -> dict[str, object]: - producer_revision = _lower_hex( - producer.get("source_revision"), 40, "candidate producer source revision" - ) - if active.revision != producer_revision: - raise StudyError("generated candidate differs from the active source") - return { - "status": "passed", - "policy": "exact-source-revision", - "source_revision": producer_revision, - "source_tree": active.tree, - } - - -def _config(mode: str, layout: str) -> RunConfig: - if mode not in {"on-the-fly", "recurrence"}: - raise StudyError(f"high-multiplicity harness forbids execution mode {mode!r}") - return RunConfig( - action="generate", - color=ColorConfig(accuracy="lc", lc_flow_layout=layout), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - relation_discovery=GenerationRelationDiscoveryConfig(mode="off"), - validation=GenerationValidationConfig( - enabled=False, post_build_validation=False - ), - ), - evaluator=EvaluatorConfig( - backend="jit", - execution_mode=mode, - optimization=EvaluatorOptimizationConfig( - cores=( - OTF_QUERY_CONSTRUCTION_THREADS - if mode == "on-the-fly" - else RECURRENCE_GENERATION_THREADS - ) - ), - jit=JITConfig(optimization_level=2), - ), - ) - - -def _generate_otf(case: Case, path: Path, model: object) -> dict[str, object]: - original = generation_service._invoke_rust_on_the_fly_seed_batch_builder_v1 - seed_calls = seed_count = materialized_calls = 0 - - def capture(*args: object, **kwargs: object) -> object: - nonlocal seed_calls, seed_count - seed_calls += 1 - projections = n4._on_the_fly_source_projections(args, kwargs) - result = original(*args, **kwargs) - if not isinstance(result, tuple) or len(result) != len(projections): - raise StudyError("OTF seed binding changed the process batch") - seed_count += len(result) - return result - - def reject(name: str) -> Callable[..., object]: - def operation(*_args: object, **_kwargs: object) -> object: - nonlocal materialized_calls - materialized_calls += 1 - raise StudyError(f"OTF generation entered materialized lane {name}") - - return operation - - started = time.perf_counter() - with ExitStack() as patches: - patches.enter_context( - mock.patch.object( - generation_service, - "_invoke_rust_on_the_fly_seed_batch_builder_v1", - capture, - ) - ) - for name, owner, attribute in n4._materialized_process_lane_patch_targets(): - patches.enter_context(mock.patch.object(owner, attribute, reject(name))) - Generator(_config("on-the-fly", "topology-replay")).generate( - ProcessRequest.parse(case.process, name=case.process_id), path, model=model - ) - elapsed_seconds = time.perf_counter() - started - if (seed_calls, seed_count, materialized_calls) != (1, 1, 0): - raise StudyError("OTF generation did not create exactly one compact seed") - execution = _read(path / "processes" / case.process_id / "execution.json") - runtime_options = execution.get("runtime_options") - if ( - not isinstance(runtime_options, Mapping) - or set(runtime_options) != {"point_tile_size", "query_construction_threads"} - or runtime_options.get("query_construction_threads") - != OTF_QUERY_CONSTRUCTION_THREADS - ): - raise StudyError("OTF artifact did not authenticate its four-thread budget") - return { - "seconds": elapsed_seconds, - "seed_binding_calls": seed_calls, - "seed_count": seed_count, - "materialized_lane_calls": materialized_calls, - "query_construction_threads": OTF_QUERY_CONSTRUCTION_THREADS, - "query_construction_threads_source": ( - "resolved evaluator.optimization.cores in execution.runtime_options" - ), - } - - -def _generate_recurrence(case: Case, path: Path, model: object) -> dict[str, object]: - started = time.perf_counter() - Generator(_config("recurrence", "topology-replay")).generate( - ProcessRequest.parse(case.process, name=case.process_id), path, model=model - ) - return { - "execution_mode": "recurrence", - "layout": "topology-replay", - "seconds": time.perf_counter() - started, - "generation_threads": RECURRENCE_GENERATION_THREADS, - "generation_threads_source": "evaluator.optimization.cores", - } - - -def _census(runtime: object, process_id: str) -> dict[str, Any]: - inspect_runtime = getattr(runtime, "inspect", None) - if not callable(inspect_runtime): - raise StudyError("OTF runtime does not expose public inspect()") - inspection = inspect_runtime() - value = ( - inspection.get(STATE_INSPECTION_KEY) - if isinstance(inspection, Mapping) - else None - ) - if not isinstance(value, Mapping): - raise StudyError("OTF runtime census is unavailable") - result = dict(value) - _assert_state_contract(result, "OTF runtime census", process_id=process_id) - return result - - -def _assert_cache_contract(value: Mapping[str, object], label: str) -> None: - limit = value.get("family_cache_limit") - if ( - value.get("family_cache_policy") != STATE_FAMILY_CACHE_POLICY - or isinstance(limit, bool) - or not isinstance(limit, int) - or limit != STATE_FAMILY_CACHE_LIMIT - ): - raise StudyError(f"{label} has the wrong last-family-only cache contract") - - -def _assert_state_contract( - value: Mapping[str, object], - label: str, - *, - process_id: str | None = None, -) -> None: - if set(value) != STATE_FIELDS: - raise StudyError(f"{label} has the wrong field set") - actual_process_id = value.get("process_id") - if ( - value.get("kind") != STATE_KIND - or not isinstance(actual_process_id, str) - or not actual_process_id - or (process_id is not None and actual_process_id != process_id) - ): - raise StudyError(f"{label} has the wrong identity") - _assert_cache_contract(value, label) - for field in STATE_COUNTS: - count = value.get(field) - if isinstance(count, bool) or not isinstance(count, int) or count < 0: - raise StudyError(f"{label} has invalid {field}") - active = value.get("active_family_union_census") - if active is not None and not isinstance(active, Mapping): - raise StudyError(f"{label} has an invalid active-family census") - - -def _assert_cold( - value: Mapping[str, object], - label: str, - *, - process_id: str | None = None, -) -> None: - _assert_state_contract(value, label, process_id=process_id) - if ( - any(value[field] != 0 for field in STATE_COUNTS) - or value.get("active_family_union_census") is not None - ): - raise StudyError(f"{label} retained mutable OTF state") - - -def _active_family_census(value: object, label: str) -> dict[str, object]: - if not isinstance(value, Mapping): - raise StudyError(f"{label} has no active family-union census") - expected_fields = {"basis", "scope", *ACTIVE_COUNT_FIELDS} - if set(value) != expected_fields: - raise StudyError(f"{label} has the wrong active family-union field set") - if ( - value.get("basis") != "shared-query-family-union-v1" - or value.get("scope") != "active-family-union" - ): - raise StudyError(f"{label} has the wrong active family-union identity") - result = dict(value) - for field in ACTIVE_COUNT_FIELDS: - count = result.get(field) - if isinstance(count, bool) or not isinstance(count, int) or count < 0: - raise StudyError(f"{label} has invalid active-family {field}") - if ( - result["query_count"] < 1 - or result["union_unique_current_count"] - > result["union_unique_current_component_count"] - or result["union_amplitude_destination_count"] < 1 - or result["union_amplitude_destination_count"] > result["query_count"] - ): - raise StudyError(f"{label} has inconsistent active-family dimensions") - for role in OPERATION_ROLES: - if result[f"union_{role}_executor_call_groups"] > result[f"union_{role}_rows"]: - raise StudyError(f"{label} has more {role} call groups than rows") - return result - - -def _assert_family_state( - value: Mapping[str, object], - label: str, - *, - process_id: str | None = None, -) -> dict[str, object]: - _assert_state_contract(value, label, process_id=process_id) - if ( - value["process_preparation_count"] != 1 - or value["retained_family_count"] != STATE_FAMILY_CACHE_LIMIT - or value["retained_selection_count"] != STATE_FAMILY_CACHE_LIMIT - or value["retained_executor_handle_count"] != STATE_FAMILY_CACHE_LIMIT - or value["semantic_executor_binding_count"] < 1 - or any(value[field] != 0 for field in COMPACT_ZERO_COUNTS) - or value["retained_request_count"] < 1 - or value["retained_amplitude_destination_count"] < 1 - or value["retained_amplitude_destination_count"] - > value["retained_request_count"] - ): - raise StudyError(f"{label} has an invalid compact retained-state census") - active = _active_family_census(value.get("active_family_union_census"), label) - if ( - active["query_count"] > value["retained_request_count"] - or active["union_amplitude_destination_count"] - > value["retained_amplitude_destination_count"] - ): - raise StudyError(f"{label} active family exceeds retained requests") - return active - - -def _failed_candidate_preserves_retained_family( - runtime: object, - case: Case, - selector: Selector, - candidate_workload: str, - retained: Mapping[str, object], -) -> dict[str, object]: - """Prove a zero-point cold candidate cannot evict the retained family.""" - - kwargs = _selector_kwargs(candidate_workload, selector) - message: str - try: - runtime.evaluate((), **kwargs) - except EvaluationError as error: - message = str(error) - if "requires at least one point" not in message: - raise StudyError( - "failed OTF candidate did not reach zero-point execution" - ) from error - else: - raise StudyError("zero-point OTF candidate unexpectedly succeeded") - after = _census(runtime, case.process_id) - if after != retained: - raise StudyError("failed OTF candidate changed the retained family") - return { - "status": "passed", - "candidate_workload": candidate_workload, - "point_count": 0, - "failure": message, - "retained_family_after_failure": after, - } - - -def _selector_kwargs(workload: str, selector: Selector) -> dict[str, tuple[str, ...]]: - if workload == "selected": - return {"color_flows": (selector.flow_id,)} - if workload == "all-flow": - return {"helicities": (selector.helicity_id,)} - if workload == "exact": - return { - "color_flows": (selector.flow_id,), - "helicities": (selector.helicity_id,), - } - raise StudyError(f"unknown study workload {workload!r}") - - -def _evaluate( - runtime: object, - points: Points, - workload: str, - selector: Selector, - *, - resolved: bool, - _precomputed_total: tuple[object, ...] | None = None, -) -> Evaluation: - kwargs = _selector_kwargs(workload, selector) - total = ( - tuple(runtime.evaluate(points, **kwargs)) - if _precomputed_total is None - else _precomputed_total - ) - detail = runtime.evaluate_resolved(points, **kwargs) if resolved else None - total_vs_resolved = None - if len(total) != len(points): - raise StudyError("runtime returned the wrong point count") - if detail is not None: - axes = ( - (("color_ids", (selector.flow_id,)),) - if workload == "selected" - else (("helicity_ids", (selector.helicity_id,)),) - if workload == "all-flow" - else ( - ("color_ids", (selector.flow_id,)), - ("helicity_ids", (selector.helicity_id,)), - ) - ) - if any(tuple(getattr(detail, axis, ())) != expected for axis, expected in axes): - raise StudyError("resolved output changed the public selector ID") - resolved_total = getattr(detail, "total", None) - if not callable(resolved_total): - raise StudyError("resolved output omitted its public total") - try: - total_vs_resolved = n4._series( - total, - tuple(resolved_total()), - f"{workload} public total/resolved total", - ) - except n4.GateError as error: - raise StudyError(str(error)) from error - return Evaluation(total, detail, total_vs_resolved) - - -def _first_selected_evaluation( - runtime: object, - points: Points, - selector: Selector, - requested_workload: str, - *, - resolved: bool, -) -> Evaluation: - """Build selected family A for lifecycle checks without timing it.""" - - if not points: - raise StudyError("selected lifecycle evaluation requires at least one point") - kwargs = _selector_kwargs("selected", selector) - total = tuple(runtime.evaluate(points, **kwargs)) - return _evaluate( - runtime, - points, - "selected", - selector, - resolved=resolved and requested_workload == "selected", - _precomputed_total=total, - ) - - -def _requested_workload_cold_warmup( - runtime: object, - case: Case, - selector: Selector, - points: Points, - workload: str, - *, - ratio_eligible: bool, - retain_family: bool = False, -) -> dict[str, object]: - """Time one requested-workload call on a cold 128xseed-101 batch.""" - - cold = _census(runtime, case.process_id) - _assert_cold(cold, "requested-workload warm-up cold runtime") - batch = _timing_points(points) - kwargs = _selector_kwargs(workload, selector) - started_ns = time.perf_counter_ns() - total = tuple(runtime.evaluate(batch, **kwargs)) - elapsed_ns = time.perf_counter_ns() - started_ns - if elapsed_ns < 0 or len(total) != BATCH_SIZE: - raise StudyError("requested-workload cold warm-up returned invalid evidence") - warmed = _census(runtime, case.process_id) - active = _assert_family_state(warmed, f"cold {workload} warm-up") - cleared = None - if not retain_family: - runtime.clear() - cleared = _census(runtime, case.process_id) - _assert_cold(cleared, "requested-workload warm-up clear") - seconds = elapsed_ns / 1_000_000_000.0 - return { - "kind": REQUESTED_COLD_WARMUP_KIND, - "timer": "time.perf_counter_ns", - "runtime_state": "census-proven-cold", - "requested_workload": workload, - "batch_size": BATCH_SIZE, - "point_count": len(batch), - "seed": SEEDS[0], - "singleton_seed_point_digest": point_digest((points[0],)), - "batch_point_policy": "seed-101 correctness point 0 repeated 128 times", - "elapsed_nanoseconds": elapsed_ns, - "seconds": seconds, - "seconds_per_point": seconds / BATCH_SIZE, - "output_count": len(total), - "before": cold, - "after_first_evaluation": warmed, - "active_family_union_census": active, - "after_clear": cleared, - "clear_call_status": ( - "omitted-retained-for-lean-lifecycle" - if retain_family - else "performed-for-exhaustive-lifecycle" - ), - "clear_restored_cold_state": None if retain_family else True, - "retained_for_followup": retain_family, - "excluded_from_elapsed": [ - "Runtime.load", - "artifact generation", - "resolved-output follow-up", - "correctness lifecycle", - "warmed BenchmarkRunner", - ], - "ratio_eligible": ratio_eligible, - "generation_pair_eligible": True, - "acceptance_eligible": False, - "query_construction_threads": OTF_QUERY_CONSTRUCTION_THREADS, - "query_construction_threads_source": ( - "authenticated execution.runtime_options" - ), - } - - -def _compare(left: Evaluation, right: Evaluation, label: str) -> dict[str, object]: - try: - return { - "total": n4._series(left.total, right.total, f"{label} total"), - "resolved": ( - None - if left.resolved is None or right.resolved is None - else n4._resolved_component_checks( - left.resolved, right.resolved, f"{label} resolved" - ) - ), - } - except n4.GateError as error: - raise StudyError(str(error)) from error - - -def _amplicol_singleton_check( - evaluation: Evaluation, - reference: AmplicolReference, - points: Points, -) -> dict[str, object]: - if not evaluation.total or not points: - raise StudyError("AmpliCol singleton comparison has no seed-101 result") - try: - comparison = n4._series( - (evaluation.total[0],), - (reference.matrix_element,), - "OTF seed-101/AmpliCol stored matrix_element", - n4.AMPICOL_REL_TOL, - ) - except n4.GateError as error: - raise StudyError(str(error)) from error - return { - "status": "passed", - "seed": SEEDS[0], - "point_count": 1, - "point_digest": point_digest((points[0],)), - "stored_amplicol_matrix_element": reference.matrix_element, - "otf_matrix_element": float(complex(evaluation.total[0]).real), - "comparison": comparison, - } - - -def _amplicol_series( - candidate: Sequence[object], - reference: Sequence[object], - label: str, -) -> dict[str, object]: - try: - return n4._series(candidate, reference, label, n4.AMPICOL_REL_TOL) - except n4.GateError as error: - raise StudyError(str(error)) from error - - -def _replay_amplicol( - reference: AmplicolReference, - case: Case, - points: Points, -) -> tuple[tuple[float, ...], dict[str, object]]: - """Replay the immutable selected-flow library at every correctness point.""" - - library = reference.library_path - process_row = reference.process_row - if library is None or process_row is None: - raise StudyError("AmpliCol reference omitted replayable library evidence") - try: - entries = legacy_amplicol.parse_process_file(library / "processes.txt") - matches = tuple( - entry - for entry in entries - if (int(entry.group), int(entry.integral)) == process_row - ) - if len(matches) != 1: - raise StudyError("AmpliCol generated-library process row is not unique") - entry = matches[0] - mapped = legacy_amplicol.source_mapped_color_order( - entry, - source_pdgs=case.pdgs, - ) - replay_word = _canonical_mapped_color_word( - case.pdgs, - mapped, - initial_state_count=_initial_state_count(case.process), - ) - if replay_word != reference.selector.flow_word: - raise StudyError("AmpliCol replay row differs from its selector contract") - root = str(library.resolve(strict=True)) - environment: dict[str, str] = {} - for name in ("LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"): - existing = os.environ.get(name) - environment[name] = ( - root if not existing else f"{root}{os.pathsep}{existing}" - ) - values: list[float] = [] - with mock.patch.dict(os.environ, environment): - for point in points: - probe = legacy_amplicol.run_selected_flow_library_probe( - library, - entry=entry, - source_pdgs=case.pdgs, - momenta=point, - helicities=None, - points=1, - ) - emitted_entry = replace( - entry, - process_pdgs=tuple(probe.process_pdgs), - color_order=tuple(probe.color_order), - ) - emitted_mapped = legacy_amplicol.source_mapped_color_order( - emitted_entry, - source_pdgs=case.pdgs, - ) - emitted_word = _canonical_mapped_color_word( - case.pdgs, - emitted_mapped, - initial_state_count=_initial_state_count(case.process), - ) - if emitted_word != reference.selector.flow_word: - raise StudyError( - "AmpliCol replay emitted a different semantic selector flow" - ) - values.append(float(probe.value)) - except (LegacyAdapterError, legacy_amplicol.LegacyOracleError, OSError) as error: - raise StudyError( - f"AmpliCol generated-library replay failed: {error}" - ) from error - replayed = tuple(values) - if len(replayed) != len(points): - raise StudyError("AmpliCol generated-library replay has the wrong point axis") - stored_check = _amplicol_series( - replayed[:1], - (reference.matrix_element,), - "AmpliCol replay seed-101/stored matrix_element", - ) - return replayed, { - "status": "passed", - "source": "authenticated-selected-flow-generated-library-snapshot", - "library_path": str(library), - "process_row": {"group": process_row[0], "integral": process_row[1]}, - "selector_flow_id": reference.selector.flow_id, - "point_count": len(points), - "point_digest": point_digest(points), - "seeds": list(SEEDS), - "helicity_policy": "sum-all-helicities", - "subprocess_launches": len(points), - "seed101_replay_vs_stored_matrix_element": stored_check, - } - - -def _lifecycle( - runtime: object, - case: Case, - selector: Selector, - points: Points, - workload: str, - resolved: bool, -) -> tuple[Evaluation, Evaluation, dict[str, object]]: - policy = _lifecycle_policy(case, workload) - if policy["mode"] == LIFECYCLE_LEAN: - retained = _census(runtime, case.process_id) - _assert_family_state(retained, "retained requested family") - headline = _evaluate(runtime, points, workload, selector, resolved=resolved) - headline_census = _census(runtime, case.process_id) - if headline_census != retained: - raise StudyError( - "8-point headline evaluation did not reuse retained family" - ) - repeat_points = points[:1] - repeated = _evaluate(runtime, repeat_points, workload, selector, resolved=False) - repeated_census = _census(runtime, case.process_id) - if repeated_census != headline_census: - raise StudyError("retained-family seed-101 repeat did not plateau") - repeat_comparison = _compare( - repeated, - Evaluation(headline.total[:1], None), - "retained-family seed-101 repeat", - ) - return ( - headline, - headline, - { - "policy": policy, - "retained_requested_family": retained, - "requested_family": headline_census, - "requested_repeat": repeated_census, - "headline_point_count": len(points), - "headline_seeds": list(SEEDS), - "plateau_repeat_point_count": len(repeat_points), - "plateau_repeat_seed": SEEDS[0], - "plateau_repeat_self_consistency": repeat_comparison, - "clear_rebuild": _clear_rebuild_evidence(policy), - "final_plateau": repeated_census, - "sequence": ( - "retained requested family; 8-point headline; " - "seed-101 plateau repeat" - ), - }, - ) - - cold = _census(runtime, case.process_id) - _assert_cold(cold, "cold runtime") - selected_a = _first_selected_evaluation( - runtime, - points, - selector, - workload, - resolved=resolved, - ) - census_a = _census(runtime, case.process_id) - _assert_family_state(census_a, "selected A") - if workload == "selected": - exact_c = _evaluate(runtime, points, "exact", selector, resolved=False) - census_c = _census(runtime, case.process_id) - _assert_family_state(census_c, "exact-selector C") - repeated = _evaluate(runtime, points, "exact", selector, resolved=False) - repeated_census = _census(runtime, case.process_id) - if repeated_census != census_c: - raise StudyError("repeated exact-selector C did not plateau") - _compare(repeated, exact_c, "exact-selector C repeat") - failed_candidate = _failed_candidate_preserves_retained_family( - runtime, - case, - selector, - "selected", - census_c, - ) - selected_revisit = _evaluate( - runtime, points, "selected", selector, resolved=False - ) - revisit = _census(runtime, case.process_id) - _assert_family_state(revisit, "selected A cold rebuild") - if revisit != census_a: - raise StudyError("selected A cold rebuild did not evict C exactly") - _compare(selected_revisit, selected_a, "selected A revisit") - selected_revisit_repeat = _evaluate( - runtime, points, "selected", selector, resolved=False - ) - revisit_repeat = _census(runtime, case.process_id) - if revisit_repeat != revisit: - raise StudyError("immediate selected A repeat was not warm") - _compare( - selected_revisit_repeat, - selected_revisit, - "selected A immediate warm repeat", - ) - - runtime.clear() - cleared = _census(runtime, case.process_id) - _assert_cold(cleared, "Runtime.clear()") - rebuilt = _evaluate(runtime, points, "selected", selector, resolved=resolved) - rebuilt_a_census = _census(runtime, case.process_id) - if rebuilt_a_census != census_a: - raise StudyError("post-clear selected A did not rebuild exactly") - _evaluate(runtime, points, "exact", selector, resolved=False) - rebuilt_c_census = _census(runtime, case.process_id) - if rebuilt_c_census != census_c: - raise StudyError("post-clear exact-selector C did not rebuild exactly") - rebuilt_revisit = _evaluate( - runtime, points, "selected", selector, resolved=False - ) - rebuilt_revisit_census = _census(runtime, case.process_id) - if rebuilt_revisit_census != census_a: - raise StudyError("post-clear selected A revisit did not evict C exactly") - _compare(rebuilt_revisit, rebuilt, "post-clear selected A revisit") - rebuilt_repeat = _evaluate( - runtime, points, "selected", selector, resolved=False - ) - rebuilt_census = _census(runtime, case.process_id) - if rebuilt_census != rebuilt_revisit_census: - raise StudyError("post-clear selected A immediate repeat was not warm") - _compare( - rebuilt_repeat, - rebuilt_revisit, - "post-clear selected A immediate warm repeat", - ) - _compare(rebuilt, selected_a, "post-clear selected A headline") - return ( - selected_a, - rebuilt, - { - "cold": cold, - "selected_a": census_a, - "requested_family": census_c, - "requested_repeat": repeated_census, - "failed_selected_a_candidate": failed_candidate, - "selected_a_revisit": revisit, - "selected_a_revisit_repeat": revisit_repeat, - "after_clear": cleared, - "after_rebuild_selected_a": rebuilt_a_census, - "after_rebuild_exact_c": rebuilt_c_census, - "after_rebuild_selected_a_revisit": rebuilt_revisit_census, - "after_rebuild_selected_a_repeat": rebuilt_census, - "after_rebuild": rebuilt_census, - "final_plateau": rebuilt_census, - "policy": policy, - "clear_rebuild": _clear_rebuild_evidence(policy), - "sequence": "A,C,C,failed-A,C,A,A; clear; A,C,A,A", - }, - ) - - first = _evaluate(runtime, points, "all-flow", selector, resolved=resolved) - target_census = _census(runtime, case.process_id) - _assert_family_state(target_census, "all-flow B") - repeated = _evaluate(runtime, points, "all-flow", selector, resolved=resolved) - repeated_census = _census(runtime, case.process_id) - if repeated_census != target_census: - raise StudyError("repeated all-flow B did not plateau") - _compare(repeated, first, "all-flow B repeat") - failed_candidate = _failed_candidate_preserves_retained_family( - runtime, - case, - selector, - "selected", - target_census, - ) - selected_revisit = _evaluate(runtime, points, "selected", selector, resolved=False) - revisit = _census(runtime, case.process_id) - _assert_family_state(revisit, "selected A cold rebuild") - if revisit != census_a: - raise StudyError("selected A cold rebuild did not evict B exactly") - _compare(selected_revisit, selected_a, "selected A revisit") - selected_revisit_repeat = _evaluate( - runtime, points, "selected", selector, resolved=False - ) - revisit_repeat = _census(runtime, case.process_id) - if revisit_repeat != revisit: - raise StudyError("immediate selected A repeat was not warm") - _compare( - selected_revisit_repeat, - selected_revisit, - "selected A immediate warm repeat", - ) - - runtime.clear() - cleared = _census(runtime, case.process_id) - _assert_cold(cleared, "Runtime.clear()") - _evaluate(runtime, points, "selected", selector, resolved=False) - rebuilt = _evaluate(runtime, points, "all-flow", selector, resolved=resolved) - rebuilt_census = _census(runtime, case.process_id) - if rebuilt_census != target_census: - raise StudyError("post-clear all-flow B did not rebuild exactly") - _compare(rebuilt, first, "post-clear all-flow B") - return ( - first, - rebuilt, - { - "cold": cold, - "selected_a": census_a, - "requested_family": target_census, - "requested_repeat": repeated_census, - "failed_selected_a_candidate": failed_candidate, - "selected_a_revisit": revisit, - "selected_a_revisit_repeat": revisit_repeat, - "after_clear": cleared, - "after_rebuild": rebuilt_census, - "final_plateau": rebuilt_census, - "policy": policy, - "clear_rebuild": _clear_rebuild_evidence(policy), - "sequence": "A,B,B,failed-A,B,A,A; clear; A,B", - }, - ) - - -def _recurrence_authority_contract( - case: Case, - recurrence: object, - points: Points, -) -> tuple[Selector, SelectorContract, dict[str, object]]: - if getattr(recurrence, "execution_mode", None) != "recurrence": - raise StudyError("recurrence authority has the wrong execution mode") - try: - contract = derive_selector_contract(recurrence, points) - validate_selector_contract(recurrence, contract, points) - except RunnerError as error: - raise StudyError(str(error)) from error - return _selector_from_contract(case, contract), contract, contract.as_dict() - - -def _cross_check_compact_selector( - runtime: object, - case: Case, - selector: Selector, - *, - require_ordinal_one: bool, -) -> dict[str, object]: - requested = (selector.flow_id, "1") if require_ordinal_one else (selector.flow_id,) - context = _compact_selector_context(runtime, case, requested) - selected = context["selected_color_ids"] - if ( - selected != [selector.flow_id] * len(requested) - or _flow_word(selector.flow_id) != selector.flow_word - ): - source = " and compact ordinal 1" if require_ordinal_one else "" - raise StudyError(f"candidate compact selector differs from authority{source}") - context["semantic_authority_flow_id"] = selector.flow_id - context["ordinal_one_required"] = require_ordinal_one - context["ordinal_one_matches_authority"] = True if require_ordinal_one else None - return context - - -def _benchmark( - runtime: object, - mode: str, - points: Points, - workload: str, - selector: Selector, - target: float, -) -> dict[str, object]: - kwargs = _selector_kwargs(workload, selector) - config = n4._benchmark_config( - target, - BATCH_SIZE, - helicities=kwargs.get("helicities", ()), - flows=kwargs.get("color_flows", ()), - ) - result = BenchmarkRunner(config).run(runtime, points=_timing_points(points)) - effective = result.effective_config - if result.interrupted: - raise StudyError("benchmark was interrupted") - if ( - effective.target_runtime != target - or effective.precision != 16 - or effective.batch_size != BATCH_SIZE - or effective.warmup_runs != WARMUP_RUNS - or effective.minimum_samples < MINIMUM_SAMPLES - or result.sample_count < MINIMUM_SAMPLES - or tuple(effective.helicity_ids) != tuple(config.helicity_ids) - or tuple(effective.color_flow_ids) != tuple(config.color_flow_ids) - ): - raise StudyError("benchmark did not satisfy the effective timing contract") - try: - timing = n4._public_timing(result, mode) - except n4.GateError as error: - raise StudyError(str(error)) from error - timing["simd"] = { - "status": "not-proven", - "reason": "native executed-block telemetry is absent", - } - return timing - - -def _selected_report_lineage( - path: Path, - case: Case, - candidate: Mapping[str, object], - active_source: ReportSourceIdentity, -) -> dict[str, object]: - outer = _read(path) - selected = outer.get("study") - if ( - outer.get("kind") != f"{KIND}-run" - or outer.get("schema_version") != SCHEMA_VERSION - or outer.get("status") != "passed" - or not isinstance(selected, Mapping) - or selected.get("kind") != KIND - or selected.get("schema_version") != SCHEMA_VERSION - or selected.get("status") != "passed" - or selected.get("workload") != "selected" - or selected.get("process") != dataclass_payload(case) - ): - raise StudyError("selected report has the wrong study identity") - expected_authority = _authority_kind(case, "selected") - authority = selected.get("authority") - correctness = selected.get("correctness") - compact = selected.get("compact_selector_context") - lifecycle_policy = selected.get("lifecycle_policy") - cache_lifecycle = selected.get("cache_lifecycle") - requested_cold_warmup = selected.get("requested_workload_cold_warmup") - expected_lifecycle_policy = _lifecycle_policy(case, "selected") - candidate_source_binding = selected.get("candidate_source_binding") - expected_producer = candidate.get("producer_identity") - expected_model = candidate.get("model_identity") - if ( - not isinstance(authority, Mapping) - or authority.get("kind") != expected_authority - or not isinstance(correctness, Mapping) - or not isinstance(compact, Mapping) - or lifecycle_policy != expected_lifecycle_policy - or not isinstance(cache_lifecycle, Mapping) - or cache_lifecycle.get("policy") != expected_lifecycle_policy - or not isinstance(candidate_source_binding, Mapping) - or not isinstance(expected_producer, Mapping) - or not isinstance(expected_model, Mapping) - or selected.get("producer_identity") != dict(expected_producer) - or selected.get("model_identity") != dict(expected_model) - or selected.get("active_source") != active_source.provenance() - or candidate_source_binding - != _candidate_source_binding(active_source, expected_producer) - ): - raise StudyError("selected report omitted its authority/source lineage") - if ( - not isinstance(requested_cold_warmup, Mapping) - or requested_cold_warmup.get("query_construction_threads") - != OTF_QUERY_CONSTRUCTION_THREADS - ): - raise StudyError("selected report omitted its warm-up thread contract") - lean_lifecycle = expected_lifecycle_policy["mode"] == LIFECYCLE_LEAN - self_consistency_key = ( - "retained_family_plateau_self_consistency" - if lean_lifecycle - else "pre_post_clear_self_consistency" - ) - self_consistency = correctness.get(self_consistency_key) - expected_self_consistency_checks = 1 if lean_lifecycle else len(SEEDS) - self_consistency_valid = ( - isinstance(self_consistency, Mapping) - and isinstance(self_consistency.get("total"), Mapping) - and self_consistency["total"].get("checks") == expected_self_consistency_checks - ) - if lean_lifecycle: - retained_requested_family = cache_lifecycle.get("retained_requested_family") - retained_state_valid = False - if isinstance(retained_requested_family, Mapping): - try: - _assert_family_state( - retained_requested_family, - "selected report retained requested family", - process_id=case.process_id, - ) - except StudyError: - pass - else: - retained_state_valid = True - lifecycle_valid = ( - cache_lifecycle.get("headline_point_count") == len(SEEDS) - and cache_lifecycle.get("headline_seeds") == list(SEEDS) - and cache_lifecycle.get("plateau_repeat_point_count") == 1 - and cache_lifecycle.get("final_plateau") == retained_requested_family - and cache_lifecycle.get("clear_rebuild") - == _clear_rebuild_evidence(expected_lifecycle_policy) - and retained_state_valid - and isinstance(requested_cold_warmup, Mapping) - and requested_cold_warmup.get("kind") == REQUESTED_COLD_WARMUP_KIND - and requested_cold_warmup.get("requested_workload") == "selected" - and requested_cold_warmup.get("batch_size") == BATCH_SIZE - and requested_cold_warmup.get("point_count") == BATCH_SIZE - and requested_cold_warmup.get("query_construction_threads") - == OTF_QUERY_CONSTRUCTION_THREADS - and requested_cold_warmup.get("retained_for_followup") is True - and requested_cold_warmup.get("clear_call_status") - == "omitted-retained-for-lean-lifecycle" - and requested_cold_warmup.get("after_clear") is None - and requested_cold_warmup.get("after_first_evaluation") - == retained_requested_family - ) - else: - final_plateau = cache_lifecycle.get("final_plateau") - after_clear = cache_lifecycle.get("after_clear") - selected_a_state = cache_lifecycle.get("selected_a") - requested_family = cache_lifecycle.get("requested_family") - lifecycle_state_valid = False - if ( - isinstance(final_plateau, Mapping) - and isinstance(after_clear, Mapping) - and isinstance(selected_a_state, Mapping) - and isinstance(requested_family, Mapping) - ): - try: - _assert_family_state( - final_plateau, - "selected report final family plateau", - process_id=case.process_id, - ) - _assert_family_state( - selected_a_state, - "selected report selected A family", - process_id=case.process_id, - ) - _assert_family_state( - requested_family, - "selected report exact-selector C family", - process_id=case.process_id, - ) - _assert_cold( - after_clear, - "selected report post-clear state", - process_id=case.process_id, - ) - except StudyError: - pass - else: - lifecycle_state_valid = True - failed_candidate = cache_lifecycle.get("failed_selected_a_candidate") - lifecycle_valid = ( - lifecycle_state_valid - and cache_lifecycle.get("clear_rebuild") - == _clear_rebuild_evidence(expected_lifecycle_policy) - and cache_lifecycle.get("sequence") - == "A,C,C,failed-A,C,A,A; clear; A,C,A,A" - and cache_lifecycle.get("requested_repeat") == requested_family - and cache_lifecycle.get("selected_a_revisit") == selected_a_state - and cache_lifecycle.get("selected_a_revisit_repeat") == selected_a_state - and cache_lifecycle.get("after_rebuild_selected_a") == selected_a_state - and cache_lifecycle.get("after_rebuild_exact_c") == requested_family - and cache_lifecycle.get("after_rebuild_selected_a_revisit") - == selected_a_state - and cache_lifecycle.get("after_rebuild_selected_a_repeat") - == selected_a_state - and final_plateau == selected_a_state - and isinstance(failed_candidate, Mapping) - and failed_candidate.get("status") == "passed" - and failed_candidate.get("candidate_workload") == "selected" - and failed_candidate.get("point_count") == 0 - and failed_candidate.get("retained_family_after_failure") - == requested_family - ) - if expected_authority == AUTHORITY_OTF_ONLY: - correctness_valid = ( - correctness.get("status") == "not-claimed" - and self_consistency_valid - and lifecycle_valid - ) - compact_valid = compact.get( - "selector_source" - ) == "compact-seed-one-based-color-ordinal-1" and compact.get( - "requested_color_ids" - ) == ["1"] - else: - if lean_lifecycle: - before_key = ( - "otf_retained_vs_amplicol_replay" - if expected_authority == AUTHORITY_AMPLICOL - else "otf_retained_vs_recurrence" - ) - after_key = None - else: - before_key, after_key = ( - ("otf_before_vs_amplicol_replay", "otf_after_vs_amplicol_replay") - if expected_authority == AUTHORITY_AMPLICOL - else ("otf_before_vs_recurrence", "otf_after_vs_recurrence") - ) - before_comparison = correctness.get(before_key) - after_comparison = None if after_key is None else correctness.get(after_key) - if expected_authority == AUTHORITY_AMPLICOL: - authority_checks_valid = ( - isinstance(before_comparison, Mapping) - and before_comparison.get("checks") == len(SEEDS) - and ( - lean_lifecycle - or ( - isinstance(after_comparison, Mapping) - and after_comparison.get("checks") == len(SEEDS) - ) - ) - ) - else: - authority_checks_valid = ( - isinstance(before_comparison, Mapping) - and isinstance(before_comparison.get("total"), Mapping) - and before_comparison["total"].get("checks") == len(SEEDS) - and ( - lean_lifecycle - or ( - isinstance(after_comparison, Mapping) - and isinstance(after_comparison.get("total"), Mapping) - and after_comparison["total"].get("checks") == len(SEEDS) - ) - ) - ) - correctness_valid = ( - correctness.get("status") == "passed" - and authority_checks_valid - and self_consistency_valid - and lifecycle_valid - ) - compact_valid = ( - compact.get("ordinal_one_required") is False - and compact.get("ordinal_one_matches_authority") is None - ) - if not correctness_valid or not compact_valid: - raise StudyError("selected report omitted its correctness/selector proof") - watchdog = outer.get("watchdog") - if ( - not isinstance(watchdog, Mapping) - or watchdog.get("passes") is not True - or watchdog.get("limit_bytes") != WATCHDOG_BYTES - ): - raise StudyError("selected report omitted its 30 GiB watchdog proof") - generation = selected.get("generation") - on_the_fly = ( - generation.get("on_the_fly") if isinstance(generation, Mapping) else None - ) - if ( - not isinstance(on_the_fly, Mapping) - or on_the_fly.get("seed_binding_calls") != 1 - or on_the_fly.get("seed_count") != 1 - or on_the_fly.get("materialized_lane_calls") != 0 - or on_the_fly.get("query_construction_threads") - != OTF_QUERY_CONSTRUCTION_THREADS - ): - raise StudyError("selected report does not prove one compact OTF seed") - timing_contract = selected.get("timing_contract") - if ( - not isinstance(timing_contract, Mapping) - or timing_contract.get("on_the_fly_query_construction_threads") - != OTF_QUERY_CONSTRUCTION_THREADS - or timing_contract.get("recurrence_generation_threads") - != RECURRENCE_GENERATION_THREADS - ): - raise StudyError("selected report omitted its bounded thread contract") - raw_contract = selected.get("selector_contract") - if not isinstance(raw_contract, Mapping): - raise StudyError("selected report omitted its selector contract") - try: - selected_contract = SelectorContract.from_mapping(raw_contract).as_dict() - except (TypeError, ValueError) as error: - raise StudyError("selected report selector contract is invalid") from error - selected_flow_ids = selected_contract["selected_color_flow_ids"] - if not isinstance(selected_flow_ids, list) or len(selected_flow_ids) != 1: - raise StudyError("selected report selector contract has the wrong flow axis") - selected_flow_id = selected_flow_ids[0] - if expected_authority == AUTHORITY_OTF_ONLY: - compact_contract_valid = ( - compact.get("requested_color_ids") == ["1"] - and compact.get("selected_color_ids") == [selected_flow_id] - and compact.get("resolved_semantic_flow_id") == selected_flow_id - ) - else: - compact_contract_valid = ( - compact.get("requested_color_ids") == [selected_flow_id] - and compact.get("selected_color_ids") == [selected_flow_id] - and compact.get("semantic_authority_flow_id") == selected_flow_id - ) - if not compact_contract_valid: - raise StudyError("selected report selector contract and compact proof disagree") - artifacts = selected.get("artifacts") - recorded = artifacts.get("candidate") if isinstance(artifacts, Mapping) else None - recorded_path = recorded.get("path") if isinstance(recorded, Mapping) else None - current_path = candidate.get("path") - if not isinstance(recorded_path, str) or not isinstance(current_path, str): - raise StudyError("selected report omitted the candidate artifact path") - try: - canonical = str(Path(recorded_path).expanduser().resolve(strict=True)) - except OSError as error: - raise StudyError("selected report candidate artifact is unavailable") from error - if ( - recorded_path != canonical - or current_path != canonical - or recorded.get("artifact_id") != candidate.get("artifact_id") - ): - raise StudyError("selected report and --candidate-artifact disagree") - generation_seconds = on_the_fly.get("seconds") - if ( - isinstance(generation_seconds, bool) - or not isinstance(generation_seconds, (int, float)) - or not math.isfinite(float(generation_seconds)) - or float(generation_seconds) <= 0.0 - ): - raise StudyError("selected report omitted OTF generation timing") - return { - "path": str(path.expanduser().resolve(strict=True)), - "kind": outer["kind"], - "status": "passed", - "candidate_path": canonical, - "candidate_artifact_id": candidate["artifact_id"], - "selected_authority_kind": expected_authority, - "producer_identity": dict(expected_producer), - "model_identity": dict(expected_model), - "active_source": active_source.provenance(), - "correctness_status": correctness["status"], - "compact_selector_proof": dict(compact), - "watchdog": dict(watchdog), - "seed_binding_calls": 1, - "seed_count": 1, - "on_the_fly_query_construction_threads": OTF_QUERY_CONSTRUCTION_THREADS, - "on_the_fly_generation_seconds": float(generation_seconds), - "selector_contract": selected_contract, - } - - -def _generation_reporting( - workload: str, - *, - generation_seconds: float, - warmup_seconds: float, - amplicol_generation_seconds: float | None, - source: str, -) -> tuple[dict[str, object], dict[str, float]]: - if workload not in {"selected", "all-flow"}: - raise StudyError(f"unknown generation-report workload {workload!r}") - if ( - not math.isfinite(generation_seconds) - or generation_seconds <= 0.0 - or not math.isfinite(warmup_seconds) - or warmup_seconds < 0.0 - ): - raise StudyError("OTF generation/warm-up comparison timing is invalid") - has_amplicol = amplicol_generation_seconds is not None - comparison: dict[str, object] = { - "notation": "([xG] x(G+W))" if has_amplicol else "[G] G+W", - "reporting": ( - "ratios-to-amplicol" if has_amplicol else "absolute-on-the-fly-seconds" - ), - "source": source, - "warmup_source": f"this-{workload}-cold-batch128-run", - "on_the_fly_generation_seconds": generation_seconds, - "on_the_fly_warmup_seconds": warmup_seconds, - "on_the_fly_generation_plus_warmup_seconds": ( - generation_seconds + warmup_seconds - ), - } - if not has_amplicol: - return comparison, {} - assert amplicol_generation_seconds is not None - if ( - not math.isfinite(amplicol_generation_seconds) - or amplicol_generation_seconds <= 0.0 - ): - raise StudyError("AmpliCol generation comparison timing is invalid") - generation_ratios = { - "generation_only": generation_seconds / amplicol_generation_seconds, - "generation_plus_warmup": (generation_seconds + warmup_seconds) - / amplicol_generation_seconds, - } - comparison.update( - { - "amplicol_generation_seconds": amplicol_generation_seconds, - "generation_only_over_amplicol": generation_ratios["generation_only"], - "generation_plus_warmup_over_amplicol": generation_ratios[ - "generation_plus_warmup" - ], - } - ) - return comparison, generation_ratios - - -def _run_worker(args: argparse.Namespace) -> dict[str, object]: - _validate_arguments(args) - case = _case(args.process_id, args.multiplicity) - authority_kind = _authority_kind(case, args.workload) - points = _points(case) - active_source = _active_report_source() - reference: AmplicolReference | None = None - if authority_kind == AUTHORITY_AMPLICOL: - assert args.reference_repo_root is not None - assert isinstance(args.reference_profile, str) - reference = _load_amplicol_reference( - args.reference_repo_root, - args.reference_profile, - case, - "selected", - points, - args.target_runtime, - active_source, - ) - output = Path(os.path.abspath(args.output.expanduser())) - generation: dict[str, object] = {} - model = None - if args.workload == "selected": - prepared = _existing( - args.prepared_model, directory=False, label="prepared model" - ) - model = ModelSource.from_path(prepared).compile() - candidate_path = output / "candidate-artifact" - generation["on_the_fly"] = _generate_otf(case, candidate_path, model) - else: - candidate_path = _existing( - args.candidate_artifact, directory=True, label="candidate artifact" - ) - candidate = Runtime.load(candidate_path, process=case.process_id) - artifacts: dict[str, dict[str, object]] = { - "candidate": _artifact_identity(candidate_path, candidate, case, "on-the-fly") - } - candidate_producer_identity = artifacts["candidate"].get("producer_identity") - if not isinstance(candidate_producer_identity, Mapping): - raise StudyError("candidate artifact producer identity evidence is incomplete") - candidate_source_binding = _candidate_source_binding( - active_source, candidate_producer_identity - ) - selected_report_lineage = None - selector: Selector - selector_contract: SelectorContract - contract: dict[str, object] - compact_selector_context: dict[str, object] - recurrence = None - if args.workload == "all-flow": - selected_report_path = _existing( - args.selected_report, directory=False, label="selected report" - ) - selected_report_lineage = _selected_report_lineage( - selected_report_path, case, artifacts["candidate"], active_source - ) - raw_contract = selected_report_lineage.get("selector_contract") - if not isinstance(raw_contract, Mapping): - raise StudyError("selected-report lineage omitted its selector contract") - try: - selector_contract = SelectorContract.from_mapping(raw_contract) - except (TypeError, ValueError) as error: - raise StudyError("selected-report selector contract is invalid") from error - if selector_contract.point_digest != point_digest(points): - raise StudyError("selected-report selector points differ from all-flow") - selector = _selector_from_contract(case, selector_contract) - contract = selector_contract.as_dict() - compact_selector_context = _cross_check_compact_selector( - candidate, case, selector, require_ordinal_one=False - ) - elif authority_kind == AUTHORITY_AMPLICOL: - assert reference is not None - selector = reference.selector - selector_contract = reference.contract - contract = reference.selector_contract - compact_selector_context = _cross_check_compact_selector( - candidate, case, selector, require_ordinal_one=False - ) - elif authority_kind == AUTHORITY_RECURRENCE: - assert model is not None - recurrence_path = output / "recurrence-authority" - generation["recurrence"] = _generate_recurrence(case, recurrence_path, model) - recurrence = Runtime.load(recurrence_path, process=case.process_id) - artifacts["recurrence_authority"] = _artifact_identity( - recurrence_path, recurrence, case, "recurrence" - ) - selector, selector_contract, contract = _recurrence_authority_contract( - case, recurrence, points - ) - compact_selector_context = _cross_check_compact_selector( - candidate, case, selector, require_ordinal_one=False - ) - else: - selector, selector_contract, compact_selector_context = ( - _selector_from_compact_ordinal_one(candidate, case, points) - ) - contract = selector_contract.as_dict() - - producer_identity = _common_producer_identity(artifacts) - model_identity = _common_model_identity(artifacts) - - lifecycle_policy = _lifecycle_policy(case, args.workload) - lean_lifecycle = lifecycle_policy["mode"] == LIFECYCLE_LEAN - requested_cold_warmup = _requested_workload_cold_warmup( - candidate, - case, - selector, - points, - args.workload, - ratio_eligible=reference is not None or recurrence is not None, - retain_family=lean_lifecycle, - ) - before, after, lifecycle = _lifecycle( - candidate, - case, - selector, - points, - args.workload, - authority_kind in {AUTHORITY_AMPLICOL, AUTHORITY_RECURRENCE}, - ) - if lean_lifecycle: - otf_self_consistency = lifecycle["plateau_repeat_self_consistency"] - self_consistency_key = "retained_family_plateau_self_consistency" - else: - otf_self_consistency = _compare(before, after, "OTF pre/post clear") - self_consistency_key = "pre_post_clear_self_consistency" - if reference is not None: - amplicol_values, amplicol_replay = _replay_amplicol(reference, case, points) - correctness = { - "status": "passed", - "authority": "authenticated-amplicol-generated-library-replay", - "claim_scope": { - "external_amplicol_point_count": len(points), - "external_amplicol_seeds": list(SEEDS), - "otf_lifecycle_point_count": len(points), - "otf_lifecycle_seeds": list(SEEDS), - }, - "amplicol_replay": amplicol_replay, - "otf_seed101_vs_amplicol_matrix_element": _amplicol_singleton_check( - before, reference, points - ), - ( - "otf_retained_vs_amplicol_replay" - if lean_lifecycle - else "otf_before_vs_amplicol_replay" - ): _amplicol_series( - before.total, - amplicol_values, - ( - "OTF retained/AmpliCol generated-library replay" - if lean_lifecycle - else "OTF before/AmpliCol generated-library replay" - ), - ), - self_consistency_key: otf_self_consistency, - "within_runtime_total_vs_resolved": { - "on_the_fly_before": before.total_vs_resolved, - **( - {} - if lean_lifecycle - else {"on_the_fly_after": after.total_vs_resolved} - ), - }, - } - if not lean_lifecycle: - correctness["otf_after_vs_amplicol_replay"] = _amplicol_series( - after.total, - amplicol_values, - "OTF after/AmpliCol generated-library replay", - ) - elif recurrence is not None: - rec = _evaluate(recurrence, points, args.workload, selector, resolved=True) - correctness = { - "status": "passed", - "authority": "fresh-recurrence", - self_consistency_key: otf_self_consistency, - "within_runtime_total_vs_resolved": { - "on_the_fly_before": before.total_vs_resolved, - **( - {} - if lean_lifecycle - else {"on_the_fly_after": after.total_vs_resolved} - ), - "recurrence": rec.total_vs_resolved, - }, - ( - "otf_retained_vs_recurrence" - if lean_lifecycle - else "otf_before_vs_recurrence" - ): _compare( - before, - rec, - ( - "OTF retained/recurrence" - if lean_lifecycle - else "OTF before/recurrence" - ), - ), - } - if not lean_lifecycle: - correctness["otf_after_vs_recurrence"] = _compare( - after, rec, "OTF after/recurrence" - ) - else: - correctness = { - "status": "not-claimed", - "reason": ( - "all-flow is an OTF-only feasibility workload" - if args.workload == "all-flow" - else "n=8/9 is OTF-only; numerical parity is not claimed" - ), - self_consistency_key: otf_self_consistency, - } - - timings = { - "on_the_fly": _benchmark( - candidate, - "on-the-fly", - points, - args.workload, - selector, - args.target_runtime, - ), - } - if reference is not None: - timings["amplicol"] = reference.timing - if _census(candidate, case.process_id) != lifecycle["final_plateau"]: - raise StudyError("timed requested family did not plateau") - if recurrence is not None: - timings["recurrence"] = _benchmark( - recurrence, - "recurrence", - points, - args.workload, - selector, - args.target_runtime, - ) - candidate_timing = timings["on_the_fly"] - candidate_wall = float(candidate_timing["wall_seconds_per_point"]) - candidate_evaluator = float(candidate_timing["evaluator_seconds_per_point"]) - - generation_warmup_seconds = float(requested_cold_warmup.get("seconds", -1.0)) - if args.workload == "selected": - on_the_fly_generation = generation.get("on_the_fly") - if not isinstance(on_the_fly_generation, Mapping): - raise StudyError("selected study omitted OTF generation timing") - generation_seconds = float(on_the_fly_generation.get("seconds", -1.0)) - generation_source = "this-selected-run" - else: - if not isinstance(selected_report_lineage, Mapping): - raise StudyError("all-flow study omitted selected-report lineage") - generation_seconds = float( - selected_report_lineage.get("on_the_fly_generation_seconds", -1.0) - ) - generation_source = "reused-selected-artifact-generation" - generation_comparison, generation_ratios = _generation_reporting( - args.workload, - generation_seconds=generation_seconds, - warmup_seconds=generation_warmup_seconds, - amplicol_generation_seconds=( - None if reference is None else float(reference.timing["generation_seconds"]) - ), - source=generation_source, - ) - ratios: dict[str, object] = {} - if reference is not None: - runtime_ratio: dict[str, object] = { - "wall_seconds_per_point": candidate_wall - / float(reference.timing["wall_seconds_per_point"]), - "evaluator_seconds_per_point": candidate_evaluator - / float(reference.timing["evaluator_seconds_per_point"]), - } - runtime_ratio.update(generation_ratios) - ratios["on_the_fly_over_amplicol"] = runtime_ratio - if recurrence is not None: - recurrence_timing = timings["recurrence"] - ratios["on_the_fly_over_recurrence"] = { - "wall_seconds_per_point": candidate_wall - / float(recurrence_timing["wall_seconds_per_point"]), - "evaluator_seconds_per_point": candidate_evaluator - / float(recurrence_timing["evaluator_seconds_per_point"]), - } - recurrence_generation = generation.get("recurrence") - if not isinstance(recurrence_generation, Mapping): - raise StudyError("recurrence authority omitted generation timing") - recurrence_generation_seconds = float(recurrence_generation["seconds"]) - if ( - not math.isfinite(recurrence_generation_seconds) - or recurrence_generation_seconds <= 0.0 - ): - raise StudyError("recurrence authority generation timing is invalid") - recurrence_generation_ratios = { - "generation_only": generation_seconds / recurrence_generation_seconds, - "generation_plus_warmup": (generation_seconds + generation_warmup_seconds) - / recurrence_generation_seconds, - } - generation_comparison.update( - { - "recurrence_notation": "([xG] x(G+W))", - "recurrence_generation_seconds": recurrence_generation_seconds, - "generation_only_over_recurrence": recurrence_generation_ratios[ - "generation_only" - ], - "generation_plus_warmup_over_recurrence": ( - recurrence_generation_ratios["generation_plus_warmup"] - ), - } - ) - recurrence_ratio = ratios["on_the_fly_over_recurrence"] - assert isinstance(recurrence_ratio, dict) - recurrence_ratio.update(recurrence_generation_ratios) - return { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "status": "passed", - "scope": ( - "otf-only-feasibility" - if authority_kind == AUTHORITY_OTF_ONLY - else f"{authority_kind}-authority" - ), - "authority": { - "kind": authority_kind, - "workload_policy": ( - "all-flow-reuses-selected-artifact-without-comparator" - if args.workload == "all-flow" - else "selected-cell-authority" - ), - }, - "process": dataclass_payload(case), - "workload": args.workload, - "artifacts": artifacts, - "producer_identity": producer_identity, - "model_identity": model_identity, - "amplicol_reference": None if reference is None else reference.lineage, - "active_source": active_source.provenance(), - "candidate_source_binding": candidate_source_binding, - "lifecycle_policy": lifecycle_policy, - "selected_report_lineage": selected_report_lineage, - "candidate_reuse": ( - { - "status": "contract", - "selected_created_candidate": True, - "all_flow_must_reuse_this_artifact": True, - } - if args.workload == "selected" - else { - "status": "actual-reuse", - "selected_created_candidate": False, - "all_flow_reused_candidate": True, - } - ), - "selector_contract": contract, - "compact_selector_context": compact_selector_context, - "points": { - "seeds": list(SEEDS), - "sqrt_s": 1000.0, - "count": len(points), - "digest": point_digest(points), - }, - "generation": generation, - "correctness": correctness, - "requested_workload_cold_warmup": requested_cold_warmup, - "cache_lifecycle": lifecycle, - "timing_contract": { - "batch_size": BATCH_SIZE, - "batch_point_source": "seed-101 correctness point 0 repeated 128 times", - "correctness_point_count": len(points), - "correctness_seeds": list(SEEDS), - "warmup_runs": WARMUP_RUNS, - "minimum_samples": MINIMUM_SAMPLES, - "target_runtime_seconds": args.target_runtime, - "on_the_fly_query_construction_threads": (OTF_QUERY_CONSTRUCTION_THREADS), - "recurrence_generation_threads": RECURRENCE_GENERATION_THREADS, - "thread_budget_source": ( - "resolved evaluator.optimization.cores authenticated in the " - "OTF execution manifest" - ), - "runtime_notation": "([evaluator] wall)", - "performance_is_acceptance_gate": False, - }, - "timings": timings, - "generation_comparison": generation_comparison, - "descriptive_ratios": ratios, - "forbidden_paths": { - "compiled_generation": "not-called", - "recurrence_generation": ( - "authority" if recurrence is not None else "not-called" - ), - "amplicol_reference": ( - "authority" if reference is not None else "not-loaded" - ), - "external_comparator": ( - authority_kind - if authority_kind != AUTHORITY_OTF_ONLY - else "not-created" - ), - "physics_enumeration": ( - "recurrence-authority-only" if recurrence is not None else "not-called" - ), - "resolved_output": ( - "authority-cells-only" - if authority_kind != AUTHORITY_OTF_ONLY - else "not-called" - ), - "prepared_model_on_all_flow": ( - "forbidden" if args.workload == "all-flow" else "not-applicable" - ), - "materialized_process_lanes": "OTF-generation-poisoned", - }, - } - - -def dataclass_payload(case: Case) -> dict[str, object]: - return { - "process_table_id": case.process_table_id, - "process_key": case.process_key, - "multiplicity": case.multiplicity, - "expression": case.process, - "process_id": case.process_id, - "external_pdgs": list(case.pdgs), - } - - -def _write(path: Path, value: object) -> None: - if path.exists() or path.is_symlink(): - raise StudyError(f"refusing to replace evidence: {path}") - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - try: - temporary.write_text( - json.dumps(value, allow_nan=False, indent=2, sort_keys=True) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - except (OSError, TypeError, ValueError) as error: - temporary.unlink(missing_ok=True) - raise StudyError(f"cannot write evidence: {path}") from error - - -def _read(path: Path) -> dict[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise StudyError(f"cannot read evidence: {path}") from error - if not isinstance(value, dict): - raise StudyError(f"evidence is not an object: {path}") - return value - - -def _worker_command(args: argparse.Namespace, output: Path) -> list[str]: - _validate_arguments(args) - command = [ - sys.executable, - str(Path(__file__).resolve()), - "--worker", - "--output", - str(output), - "--process-id", - str(args.process_id), - "--multiplicity", - str(args.multiplicity), - "--workload", - args.workload, - "--target-runtime", - str(args.target_runtime), - ] - if args.reference_repo_root is not None: - command.extend( - ( - "--reference-repo-root", - str( - _existing( - args.reference_repo_root, - directory=True, - label="reference repository root", - ) - ), - "--reference-profile", - args.reference_profile, - ) - ) - for option, value, directory, label in ( - ("--prepared-model", args.prepared_model, False, "prepared model"), - ("--candidate-artifact", args.candidate_artifact, True, "candidate artifact"), - ("--selected-report", args.selected_report, False, "selected report"), - ): - if value is not None: - command.extend( - (option, str(_existing(value, directory=directory, label=label))) - ) - return command - - -def _worker_main(args: argparse.Namespace) -> int: - try: - result = _run_worker(args) - except Exception as error: - _write( - args.output / "worker.json", - { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "status": "failed", - "error": str(error), - }, - ) - return 1 - _write(args.output / "worker.json", result) - return 0 - - -def _driver_main(args: argparse.Namespace) -> int: - _validate_arguments(args) - output = Path(os.path.abspath(args.output.expanduser())) - if output.exists() or output.is_symlink(): - raise StudyError(f"output already exists: {output}") - output.mkdir(parents=True) - watchdog_path = output / "watchdog.json" - exit_code = run_guarded( - _worker_command(args, output), - limit_bytes=WATCHDOG_BYTES, - report_path=watchdog_path, - physical_footprint_probe=n4._physical_footprint_probe(), - ) - try: - watchdog = n4._watchdog_summary(_read(watchdog_path)) - except n4.GateError as error: - raise StudyError(str(error)) from error - worker_path = output / "worker.json" - worker = _read(worker_path) if worker_path.is_file() else None - if ( - exit_code - or watchdog["passes"] is not True - or not worker - or worker.get("status") != "passed" - ): - detail = None if worker is None else worker.get("error") - raise StudyError(f"guarded worker failed: {watchdog['outcome']!r}, {detail!r}") - report = { - "kind": f"{KIND}-run", - "schema_version": SCHEMA_VERSION, - "status": "passed", - "study": worker, - "watchdog": watchdog, - } - _write(output / "report.json", report) - print(f"On-the-fly high-multiplicity study passed: {output / 'report.json'}") - return 0 - - -def main(argv: Sequence[str] | None = None) -> int: - args = _parser().parse_args(argv) - try: - return _worker_main(args) if args.worker else _driver_main(args) - except StudyError as error: - print(f"error: {error}", file=sys.stderr) - return 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/on_the_fly_lc_gate.py b/pyamplicol/tools/developer/on_the_fly_lc_gate.py deleted file mode 100644 index a9bfd5f2a7..0000000000 --- a/pyamplicol/tools/developer/on_the_fly_lc_gate.py +++ /dev/null @@ -1,3679 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Developer-only first real LC gate for the on-the-fly evaluator. - -One topology-replay ``d d~ > t t~ g g`` artifact must serve both intended -workloads: selected-flow/helicity-sum and all-flow/single-helicity. Dense -correctness against one production recurrence :class:`pyamplicol.Runtime` per -workload is mandatory; the timing comparison that follows is diagnostic only. -""" - -from __future__ import annotations - -import argparse -import dataclasses -import importlib -import json -import math -import os -import platform -import statistics -import sys -import tempfile -import time -from collections.abc import Callable, Mapping, Sequence -from contextlib import ExitStack -from dataclasses import dataclass -from functools import partial -from pathlib import Path -from typing import Any -from unittest import mock - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -import pyamplicol.generation.service as generation_service # noqa: E402 -from pyamplicol import ( # noqa: E402 - BenchmarkRunner, - CompiledModel, - Generator, - ModelSource, - ProcessRequest, - Runtime, -) -from pyamplicol._internal.versions import ( # noqa: E402 - ON_THE_FLY_LC_COLOR_RUNTIME_CAPABILITY, - ON_THE_FLY_RUNTIME_CAPABILITY, -) -from pyamplicol.api.errors import ArtifactError # noqa: E402 -from pyamplicol.artifacts import confined_path, load_manifest # noqa: E402 -from pyamplicol.config import ( # noqa: E402 - BenchmarkConfig, - ColorConfig, - EvaluatorConfig, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationRelationDiscoveryConfig, - GenerationValidationConfig, - JITConfig, - RunConfig, -) -from pyamplicol.generation.evaluator_container import ( # noqa: E402 - PacbinError, - PacbinMemberKind, - PacbinReader, -) -from pyamplicol.models.builtin.validation import generic_validation_point # noqa: E402 -from pyamplicol.processes import canonical_process_key # noqa: E402 -from tools.ci.memory_watchdog import ( # noqa: E402 - GIB, - DarwinPhysicalFootprintProbe, - PhysicalFootprintProbe, - run_guarded, -) -from tools.performance_report.runner import ( # noqa: E402 - point_digest, - pointwise_validation, -) - -PROCESS = "d d~ > t t~ g g" -PROCESS_KEY = canonical_process_key(PROCESS) -PROCESS_ID = "otf_dd_tt_gg" -EXTERNAL_PDGS = (1, -1, 6, -6, 21, 21) -ON_THE_FLY_CAPABILITIES = tuple( - sorted( - ( - ON_THE_FLY_LC_COLOR_RUNTIME_CAPABILITY, - ON_THE_FLY_RUNTIME_CAPABILITY, - ) - ) -) -ON_THE_FLY_SEED_MEMBER_PATH = "on-the-fly/process-seed-v1.bin" -FLOW_ID = "flow:2,5,6,4,3,1" -FLOW_WORD = (2, 5, 6, 4, 3, 1) -HELICITY_ID = "h:-1,+1,-1,+1,-1,+1" -HELICITY_VALUES = (-1, 1, -1, 1, -1, 1) -AMPICOL_CELL_ID = "reference-amplicol-lc-n4-dd-tt-jets-selected-flow" -SEEDS = (101, 211, 307, 401, 503, 607, 709, 811) -REL_TOL = 1.0e-12 -AMPICOL_REL_TOL = 1.0e-8 -WATCHDOG_BYTES = 30 * GIB -WARMUPS = 2 -MINIMUM_SAMPLES = 5 -CORRECTNESS_AUTHORITY_CONTRACT = "recurrence-only-v1" -WORK_CENSUS_BASIS = "fully-resident-query-local-trace-v1" -FAMILY_WORK_CENSUS_BASIS = "shared-query-family-union-v1" -OPERATION_COUNT_FIELDS = ( - "source_operation_count", - "contribution_operation_count", - "finalization_operation_count", - "closure_operation_count", -) -WORK_CENSUS_COUNT_FIELDS = ( - "logical_current_count", - "resident_current_count", - "resident_current_component_count", - *OPERATION_COUNT_FIELDS, - "total_kernel_application_count", - "semantic_executor_binding_count", - "distinct_prepared_executor_count", -) -PUBLIC_PROFILE_WORK_FIELDS = tuple( - f"recurrence_{role}_{unit}_count" - for role in ("source", "contribution", "finalization", "closure") - for unit in ("call", "row") -) -FAMILY_CENSUS_COUNT_FIELDS = ( - "query_count", - "source_frame_partition_count", - "projection_applied_query_count", - "projection_pre_current_count", - "projection_pre_contribution_count", - "projection_pre_closure_count", - "projection_post_current_count", - "projection_post_contribution_count", - "projection_post_closure_count", - "dynamic_current_occurrence_count", - "dynamic_current_component_occurrence_count", - "dynamic_source_rows", - "dynamic_contribution_rows", - "dynamic_finalization_rows", - "dynamic_closure_rows", - "dynamic_source_calls", - "dynamic_contribution_calls", - "dynamic_finalization_calls", - "dynamic_closure_calls", - "union_unique_current_count", - "union_unique_current_component_count", - "union_source_rows", - "union_contribution_rows", - "union_finalization_rows", - "union_closure_rows", - "union_amplitude_destination_count", - "union_source_executor_call_groups", - "union_contribution_executor_call_groups", - "union_finalization_executor_call_groups", - "union_closure_executor_call_groups", -) -MATERIALIZED_PROCESS_LANE_SYMBOLS = ( - "GenerationBackend._prepare_process_construction", - "build_color_plan", - "compile_generic_dag", - "_invoke_rust_eager_lowering_v1", - "_invoke_rust_recurrence_lowering_v2", - "run_generic_dag_numerical_current_warmup", - "run_recurrence_numerical_current_warmup", -) -_FORBIDDEN_MATERIALIZATION_FIELDS = frozenset( - { - "color_components", - "color_plan", - "compiled", - "compiled_execution", - "compiled_plan", - "dag", - "dag_summary", - "direct_plan", - "direct_recurrence_plan", - "eager", - "eager_plan", - "eager_runtime", - "generic_dag", - "helicity_components", - "lc_topology_replay", - "recurrence", - "recurrence_plan", - "recurrence_runtime", - "runtime_schema", - "stages", - "structural", - "structural_proof", - "structural_source_proof", - } -) -Point = tuple[tuple[float, ...], ...] -Points = tuple[Point, ...] - - -class GateError(RuntimeError): - """The fixed gate could not produce valid evidence.""" - - -@dataclass(frozen=True, slots=True) -class RetainedInputs: - builder: object - template: object - direct_json: bytes - pack_digest: str - - -@dataclass(frozen=True, slots=True) -class Query: - flow_id: str - flow_index: int - helicity_id: str - helicities: tuple[int, ...] - - @property - def label(self) -> str: - return f"{self.flow_id}|{self.helicity_id}" - - -@dataclass(frozen=True, slots=True) -class PublicEvaluation: - total: tuple[object, ...] - resolved: object - - -@dataclass(frozen=True, slots=True) -class RecurrenceAuthorityCorrectness: - recurrence_selected: PublicEvaluation - recurrence_all_flow: PublicEvaluation - on_the_fly_selected: PublicEvaluation - on_the_fly_all_flow: PublicEvaluation - public_correctness: dict[str, object] - clear_checks: dict[str, object] - - -@dataclass(frozen=True, slots=True) -class PublicGatePhase: - runtime: object - selected_recurrence_runtime: object - all_flow_recurrence_runtime: object - comparator_selectors: tuple[tuple[str, tuple[object, object]], ...] - points: Points - timing_points: Points - correctness: RecurrenceAuthorityCorrectness - artifact_contract: dict[str, object] - load_seconds: float - public_profiles: dict[str, object] - timings: dict[str, dict[str, dict[str, object]]] - - -def _positive_float(text: str) -> float: - value = float(text) - if not math.isfinite(value) or value <= 0.0: - raise argparse.ArgumentTypeError("must be a positive finite number") - return value - - -def _positive_int(text: str) -> int: - value = int(text) - if value <= 0: - raise argparse.ArgumentTypeError("must be a positive integer") - return value - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", required=True, type=Path) - candidate_source = parser.add_mutually_exclusive_group(required=True) - candidate_source.add_argument( - "--prepared-model", - type=Path, - help="explicit prepared built-in-SM .pyamplicol-model bundle", - ) - candidate_source.add_argument( - "--candidate-artifact", - type=Path, - help=( - "reuse an existing compact on-the-fly artifact; valid only with " - "--public-correctness-only" - ), - ) - parser.add_argument( - "--amplicol-result", - type=Path, - help="stored successful AmpliCol worker-result.json (optional sanity point)", - ) - parser.add_argument( - "--recurrence-selected-artifact", - required=True, - type=Path, - help=( - "explicit LC topology-replay recurrence comparator for the " - "selected-flow/helicity-sum workload" - ), - ) - parser.add_argument( - "--recurrence-all-flow-artifact", - required=True, - type=Path, - help=( - "explicit LC all-flow-union recurrence comparator for the " - "all-flow/single-helicity workload" - ), - ) - parser.add_argument("--target-runtime", type=_positive_float, default=1.0) - parser.add_argument("--batch-size", type=_positive_int, default=128) - parser.add_argument( - "--public-correctness-only", - action="store_true", - help=( - "provisional developer lane: public recurrence-authority correctness, " - "profiles, and BenchmarkRunner timings only; never creates a private " - "probe carrier or private census" - ), - ) - parser.add_argument( - "--bypass-color-projection", - action="store_true", - help=( - "diagnostic: execute the selected graph before late color-alias projection" - ), - ) - parser.add_argument("--worker", action="store_true", help=argparse.SUPPRESS) - return parser - - -def _on_the_fly_config() -> RunConfig: - return RunConfig( - action="generate", - color=ColorConfig(accuracy="lc", lc_flow_layout="topology-replay"), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - relation_discovery=GenerationRelationDiscoveryConfig(mode="off"), - validation=GenerationValidationConfig( - enabled=True, post_build_validation=True - ), - ), - evaluator=EvaluatorConfig( - backend="jit", - execution_mode="on-the-fly", - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=2), - ), - ) - - -def _recurrence_probe_config() -> RunConfig: - return RunConfig( - action="generate", - color=ColorConfig(accuracy="lc", lc_flow_layout="topology-replay"), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - relation_discovery=GenerationRelationDiscoveryConfig(mode="off"), - validation=GenerationValidationConfig( - enabled=False, post_build_validation=False - ), - ), - evaluator=EvaluatorConfig( - backend="jit", - execution_mode="recurrence", - optimization=EvaluatorOptimizationConfig(cores=1), - jit=JITConfig(optimization_level=2), - ), - ) - - -def _points() -> Points: - return tuple( - tuple(tuple(map(float, particle.momentum)) for particle in point) - for point in ( - generic_validation_point(PROCESS, sqrt_s=1000.0, seed=seed) - for seed in SEEDS - ) - ) - - -def _repeat(points: Points, count: int) -> Points: - if not points or count <= 0: - raise GateError("point repetition needs non-empty points and a positive count") - return tuple(points[index % len(points)] for index in range(count)) - - -def _flatten(points: Points) -> list[float]: - return [x for point in points for momentum in point for x in momentum] - - -def _real(value: object, label: str) -> float: - try: - result = complex(value) # type: ignore[arg-type] - except (TypeError, ValueError, OverflowError) as error: - raise GateError(f"{label} is not numeric") from error - if not math.isfinite(result.real) or not math.isfinite(result.imag): - raise GateError(f"{label} is not finite") - if result.imag != 0.0: - raise GateError(f"{label} is not real") - return result.real - - -def _series( - candidate: Sequence[object], - reference: Sequence[object], - label: str, - tolerance: float = REL_TOL, -) -> dict[str, object]: - if not candidate or len(candidate) != len(reference): - raise GateError(f"{label} has incompatible or empty point axes") - rows = tuple( - pointwise_validation( - _real(left, "candidate"), - _real(right, "reference"), - relative_tolerance=tolerance, - ) - for left, right in zip(candidate, reference, strict=True) - ) - failed = next( - (index for index, row in enumerate(rows) if row["status"] != "ok"), None - ) - if failed is not None: - raise GateError( - f"{label} disagrees at point {failed}: " - f"residual={rows[failed]['conditioned_residual']!r}" - ) - worst = max( - range(len(rows)), key=lambda index: float(rows[index]["conditioned_residual"]) - ) - return { - "checks": len(rows), - "maximum_conditioned_residual": rows[worst]["conditioned_residual"], - "maximum_absolute_difference": max( - float(row["absolute_difference"]) for row in rows - ), - "worst_point_index": worst, - "worst": rows[worst], - } - - -def _summaries(rows: Sequence[Mapping[str, object]]) -> dict[str, object]: - if not rows: - raise GateError("component comparison set is empty") - worst = max( - range(len(rows)), - key=lambda index: float(rows[index]["maximum_conditioned_residual"]), - ) - return { - "component_count": len(rows), - "checks": sum(int(row["checks"]) for row in rows), - "maximum_conditioned_residual": rows[worst]["maximum_conditioned_residual"], - "maximum_absolute_difference": max( - float(row["maximum_absolute_difference"]) for row in rows - ), - "worst_component_index": worst, - "worst": rows[worst], - } - - -def _sum(rows: Sequence[Sequence[object]], point_count: int) -> tuple[float, ...]: - parsed = tuple(tuple(_real(value, "component") for value in row) for row in rows) - if not parsed or point_count <= 0 or any(len(row) != point_count for row in parsed): - raise GateError("component rows do not match the point count") - return tuple( - math.fsum(row[point] for row in parsed) for point in range(point_count) - ) - - -def _calibrate(pilot_seconds: float, target_seconds: float) -> int: - if ( - not math.isfinite(pilot_seconds) - or pilot_seconds <= 0.0 - or not math.isfinite(target_seconds) - or target_seconds <= 0.0 - ): - raise GateError("benchmark pilot and target must be positive and finite") - repetitions = max(1, math.ceil(target_seconds / pilot_seconds)) - if repetitions >= 1 << 32: - raise GateError("benchmark repetitions exceed the native u32 domain") - return repetitions - - -def _canonical_direct(value: object) -> bytes: - to_dict = getattr(value, "to_dict", None) - if not callable(to_dict): - raise GateError("captured direct catalog has no mapping") - return json.dumps( - to_dict(), - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def _prepared_model_path(path: Path) -> Path: - try: - resolved = path.expanduser().resolve(strict=True) - except OSError as error: - raise GateError(f"prepared model does not exist: {path}") from error - if not resolved.is_file(): - raise GateError(f"prepared model is not a regular file: {resolved}") - if not resolved.name.lower().endswith(".pyamplicol-model"): - raise GateError("prepared model must end with '.pyamplicol-model'") - return resolved - - -def _candidate_artifact_path(path: Path) -> Path: - try: - resolved = path.expanduser().resolve(strict=True) - except OSError as error: - raise GateError(f"candidate artifact does not exist: {path}") from error - if not resolved.is_dir(): - raise GateError(f"candidate artifact is not a directory: {resolved}") - return resolved - - -def _validate_mode_arguments(arguments: argparse.Namespace) -> None: - prepared_model = getattr(arguments, "prepared_model", None) - candidate_artifact = getattr(arguments, "candidate_artifact", None) - public_only = bool(getattr(arguments, "public_correctness_only", False)) - if public_only: - if getattr(arguments, "bypass_color_projection", False): - raise GateError( - "--bypass-color-projection is unavailable with " - "--public-correctness-only" - ) - if getattr(arguments, "amplicol_result", None) is not None: - raise GateError( - "--amplicol-result needs the full private gate and is unavailable " - "with --public-correctness-only" - ) - return - if prepared_model is None: - raise GateError("the full gate requires --prepared-model") - if candidate_artifact is not None: - raise GateError( - "--candidate-artifact is valid only with --public-correctness-only" - ) - - -def _reject_materialization_fields(value: object, label: str) -> None: - if isinstance(value, Mapping): - for raw_name, nested in value.items(): - name = str(raw_name).lower().replace("-", "_") - path = f"{label}.{raw_name}" - if name in _FORBIDDEN_MATERIALIZATION_FIELDS: - raise GateError( - f"{label} contains forbidden materialization field {path!r}" - ) - _reject_materialization_fields(nested, path) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, nested in enumerate(value): - _reject_materialization_fields(nested, f"{label}[{index}]") - - -def _on_the_fly_source_projections( - args: tuple[object, ...], kwargs: Mapping[str, object] -) -> tuple[Mapping[str, object], ...]: - raw = args[0] if args else kwargs.get("ordered_source_projection_jsons") - if not isinstance(raw, Sequence) or isinstance(raw, (str, bytes)) or not raw: - raise GateError("on-the-fly batch seed binding omitted its source projections") - result: list[Mapping[str, object]] = [] - for index, encoded in enumerate(raw): - if not isinstance(encoded, bytes): - raise GateError( - f"on-the-fly source projection {index} is not encoded bytes" - ) - try: - projection = json.loads(encoded) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise GateError( - f"on-the-fly source projection {index} is not valid JSON" - ) from error - record = _mapping(projection, f"on-the-fly source projection {index}") - _reject_materialization_fields(record, f"on-the-fly source projection {index}") - result.append(record) - return tuple(result) - - -def _materialized_process_lane_patch_targets() -> tuple[tuple[str, object, str], ...]: - return ( - ( - "GenerationBackend._prepare_process_construction", - generation_service.GenerationBackend, - "_prepare_process_construction", - ), - ("build_color_plan", generation_service, "build_color_plan"), - ("compile_generic_dag", generation_service, "compile_generic_dag"), - ( - "_invoke_rust_eager_lowering_v1", - generation_service, - "_invoke_rust_eager_lowering_v1", - ), - ( - "_invoke_rust_recurrence_lowering_v2", - generation_service, - "_invoke_rust_recurrence_lowering_v2", - ), - ( - "run_generic_dag_numerical_current_warmup", - generation_service, - "run_generic_dag_numerical_current_warmup", - ), - ( - "run_recurrence_numerical_current_warmup", - generation_service, - "run_recurrence_numerical_current_warmup", - ), - ) - - -def _generate_on_the_fly( - artifact: Path, model: CompiledModel -) -> tuple[float, dict[str, int]]: - seed_batch_binding_call_count = 0 - seed_build_count = 0 - original_seed_builder = ( - generation_service._invoke_rust_on_the_fly_seed_batch_builder_v1 - ) - - def capture_seed_batch(*args: object, **kwargs: object) -> object: - nonlocal seed_batch_binding_call_count, seed_build_count - seed_batch_binding_call_count += 1 - projections = _on_the_fly_source_projections(args, kwargs) - result = original_seed_builder(*args, **kwargs) - if not isinstance(result, tuple): - raise GateError("on-the-fly batch seed binding returned a non-tuple") - if len(result) != len(projections): - raise GateError( - "on-the-fly batch seed binding changed the process count: " - f"{len(projections)} projection(s), {len(result)} seed(s)" - ) - seed_build_count += len(result) - return result - - materialized_lane_call_counts = { - name: 0 for name in MATERIALIZED_PROCESS_LANE_SYMBOLS - } - - def reject_materialized_lane( - name: str, - ) -> Callable[..., object]: - def reject(*_args: object, **_kwargs: object) -> object: - materialized_lane_call_counts[name] += 1 - raise GateError( - f"on-the-fly generation entered materialized process lane {name}" - ) - - return reject - - started = time.perf_counter() - with ExitStack() as patches: - patches.enter_context( - mock.patch.object( - generation_service, - "_invoke_rust_on_the_fly_seed_batch_builder_v1", - capture_seed_batch, - ) - ) - for name, owner, attribute in _materialized_process_lane_patch_targets(): - patches.enter_context( - mock.patch.object( - owner, - attribute, - reject_materialized_lane(name), - ) - ) - Generator(_on_the_fly_config()).generate( - ProcessRequest.parse(PROCESS, name=PROCESS_ID), artifact, model=model - ) - if seed_batch_binding_call_count != 1 or seed_build_count != 1: - raise GateError( - "expected one on-the-fly batch binding call producing one seed, " - f"observed {seed_batch_binding_call_count} call(s) and " - f"{seed_build_count} seed(s)" - ) - return time.perf_counter() - started, { - "expanded_process_count": 1, - "on_the_fly_seed_batch_binding_call_count": (seed_batch_binding_call_count), - "on_the_fly_seed_build_count": seed_build_count, - "recurrence_lowering_call_count": materialized_lane_call_counts[ - "_invoke_rust_recurrence_lowering_v2" - ], - "materialized_process_lane_count": sum(materialized_lane_call_counts.values()), - } - - -def _generate_probe_carrier(artifact: Path, model: CompiledModel) -> RetainedInputs: - captured: list[RetainedInputs] = [] - original = generation_service._invoke_rust_recurrence_lowering_v2 - - def capture(*args: object, **kwargs: object) -> object: - if len(args) < 4: - raise GateError("lowering call omitted its canonical inputs") - direct = _canonical_direct(args[2]) - supplied = kwargs.get("direct_template_catalog_json") - if supplied is not None and supplied != direct: - raise GateError("lowering direct-catalog bytes are not canonical") - captured.append(RetainedInputs(args[0], args[1], direct, str(args[3]))) - return original(*args, **kwargs) - - with mock.patch.object( - generation_service, "_invoke_rust_recurrence_lowering_v2", capture - ): - Generator(_recurrence_probe_config()).generate( - ProcessRequest.parse(PROCESS, name=PROCESS_ID), artifact, model=model - ) - if len(captured) != 1: - raise GateError(f"expected one lowering call, observed {len(captured)}") - return captured[0] - - -def _generate_candidate_with_prepared_model( - artifact: Path, prepared_model: Path -) -> tuple[float, dict[str, int], CompiledModel, Path, float]: - resolved = _prepared_model_path(prepared_model) - started = time.perf_counter() - model = ModelSource.from_path(resolved).compile() - load_seconds = time.perf_counter() - started - generation_seconds, generation_census = _generate_on_the_fly(artifact, model) - return generation_seconds, generation_census, model, resolved, load_seconds - - -def _selectors(physics: object) -> tuple[object, object]: - flows = tuple( - flow - for flow in getattr(physics, "color_flows", ()) - if flow.id == FLOW_ID and tuple(flow.word) == FLOW_WORD - ) - helicities = tuple( - helicity - for helicity in getattr(physics, "helicities", ()) - if helicity.id == HELICITY_ID and tuple(helicity.values) == HELICITY_VALUES - ) - if len(flows) != 1 or len(helicities) != 1: - raise GateError("artifact does not expose the exact fixed flow and helicity") - if helicities[0].structural_zero: - raise GateError("fixed all-flow helicity is structurally zero") - return flows[0], helicities[0] - - -def _query(flow: object, helicity: object) -> Query: - index = flow.index - values = tuple(helicity.values) - if isinstance(index, bool) or not isinstance(index, int) or index < 0: - raise GateError("color-flow native index is invalid") - if not values or any( - isinstance(value, bool) or not isinstance(value, int) for value in values - ): - raise GateError("helicity values are invalid") - return Query(flow.id, index, helicity.id, values) - - -def _probe() -> Callable[..., dict[str, Any]]: - candidate = getattr( - importlib.import_module("pyamplicol._rusticol"), - "_on_the_fly_artifact_probe_v1", - None, - ) - if not callable(candidate): - raise GateError("native extension lacks on-the-fly benchmark test support") - return candidate - - -def _family_probe() -> Callable[..., dict[str, Any]]: - candidate = getattr( - importlib.import_module("pyamplicol._rusticol"), - "_on_the_fly_query_family_census_v1", - None, - ) - if not callable(candidate): - raise GateError("native extension lacks on-the-fly family-census support") - return candidate - - -def _invoke( - probe: Callable[..., dict[str, Any]], - artifact: Path, - retained: RetainedInputs, - query: Query, - points: Points, - *, - repetitions: int = 0, - enable_color_projection: bool = True, - query_family: Sequence[Query] | None = None, -) -> dict[str, Any]: - benchmark = repetitions > 0 - return probe( - str(artifact), - PROCESS_ID, - retained.builder, - retained.template, - retained.direct_json, - retained.pack_digest, - query.flow_index, - list(query.helicities), - _flatten(points), - len(points), - benchmark=benchmark, - benchmark_warmup_repetitions=WARMUPS if benchmark else 0, - benchmark_repetitions=repetitions, - collect_current_diagnostics=False, - enable_color_projection=enable_color_projection, - query_family=( - None - if query_family is None - else [ - (member.flow_index, list(member.helicities)) for member in query_family - ] - ), - ) - - -def _probe_values( - report: Mapping[str, object], point_count: int, repetitions: int = 0 -) -> tuple[float, ...]: - poison = ( - "direct_plan_load_attempts", - "direct_plan_decode_attempts", - "direct_plan_materialization_attempts", - "established_builder_attempts", - ) - benchmark = repetitions > 0 - cycles = WARMUPS + repetitions if benchmark else 1 - hits = cycles if benchmark else 0 - if ( - report.get("process_id") != PROCESS_ID - or report.get("point_count") != point_count - or report.get("trace_build_count") != 1 - or report.get("trace_cache_hit_count") != hits - or report.get("momentum_fill_count") != cycles - or report.get("currents") != [] - or any(report.get(name) != 0 for name in poison) - ): - raise GateError("hidden query violated its build/cache/fill/poison contract") - _work_census(report) - values = report.get("normalized_values") - if not isinstance(values, Sequence) or isinstance(values, (str, bytes)): - raise GateError("hidden query has no normalized values") - parsed = tuple(_real(value, "hidden value") for value in values) - if len(parsed) != point_count: - raise GateError("hidden query returned the wrong point count") - elapsed = report.get("benchmark_elapsed_seconds") - per_point = report.get("benchmark_seconds_per_point") - if benchmark: - if not isinstance(elapsed, (int, float)) or not isinstance( - per_point, (int, float) - ): - raise GateError("hidden benchmark omitted timings") - expected = float(elapsed) / (repetitions * point_count) - valid_timing = ( - math.isfinite(float(elapsed)) - and float(elapsed) >= 0.0 - and math.isclose(float(per_point), expected, rel_tol=1.0e-15, abs_tol=0.0) - ) - if not valid_timing: - raise GateError("hidden benchmark timings are inconsistent") - elif elapsed is not None or per_point is not None: - raise GateError("untimed hidden query returned timings") - return parsed - - -def _work_census(report: Mapping[str, object]) -> dict[str, object]: - if report.get("work_census_basis") != WORK_CENSUS_BASIS: - raise GateError("hidden query has an unknown work-census basis") - counts: dict[str, int] = {} - for name in WORK_CENSUS_COUNT_FIELDS: - value = report.get(name) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"hidden query work census has invalid {name}") - counts[name] = value - if counts["resident_current_count"] != counts["logical_current_count"]: - raise GateError("hidden query does not use a fully resident current arena") - if counts["resident_current_component_count"] < counts["resident_current_count"]: - raise GateError("hidden query resident current components are inconsistent") - if counts["total_kernel_application_count"] != sum( - counts[name] for name in OPERATION_COUNT_FIELDS - ): - raise GateError("hidden query kernel and operation counts disagree") - semantic = counts["semantic_executor_binding_count"] - prepared = counts["distinct_prepared_executor_count"] - total = counts["total_kernel_application_count"] - if not 0 < prepared <= semantic <= total: - raise GateError("hidden query prepared-executor counts are inconsistent") - return {"work_census_basis": WORK_CENSUS_BASIS, **counts} - - -def _family_probe_result( - report: Mapping[str, object], - queries: Sequence[Query], - point_count: int, - repetitions: int = 0, -) -> dict[str, object]: - if not queries: - raise GateError("hidden family report has no requested queries") - benchmark = repetitions > 0 - cycles = WARMUPS + repetitions if benchmark else 1 - poison = ( - "direct_plan_load_attempts", - "direct_plan_decode_attempts", - "direct_plan_materialization_attempts", - "established_builder_attempts", - ) - if ( - report.get("process_id") != PROCESS_ID - or report.get("point_count") != point_count - or report.get("work_census_basis") != FAMILY_WORK_CENSUS_BASIS - or report.get("trace_build_count") != len(queries) - or report.get("trace_cache_hit_count") != 0 - or report.get("momentum_fill_count") != cycles - or report.get("currents") != [] - or any(report.get(name) != 0 for name in poison) - ): - raise GateError("hidden family violated its build/cache/fill/poison contract") - family = report.get("query_family") - if not isinstance(family, Mapping): - raise GateError("hidden family report is absent") - raw_census = family.get("census") - if not isinstance(raw_census, Mapping): - raise GateError("hidden family census is absent") - census: dict[str, int] = {} - for name in FAMILY_CENSUS_COUNT_FIELDS: - value = raw_census.get(name) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"hidden family census has invalid {name}") - census[name] = value - if ( - census["query_count"] != len(queries) - or census["source_frame_partition_count"] != 1 - or census["union_amplitude_destination_count"] != len(queries) - ): - raise GateError("hidden family census has the wrong query/source shape") - for role in ("source", "contribution", "finalization", "closure"): - if ( - family.get(f"execution_{role}_rows") != census[f"union_{role}_rows"] - or family.get(f"execution_{role}_calls") - != census[f"union_{role}_executor_call_groups"] - ): - raise GateError(f"hidden family execution disagrees for {role}") - union_total = sum( - census[f"union_{role}_rows"] - for role in ("source", "contribution", "finalization", "closure") - ) - if ( - report.get("source_operation_count") != census["union_source_rows"] - or report.get("contribution_operation_count") - != census["union_contribution_rows"] - or report.get("finalization_operation_count") - != census["union_finalization_rows"] - or report.get("closure_operation_count") != census["union_closure_rows"] - or report.get("total_kernel_application_count") != union_total - or family.get("execution_cache_hit") is not benchmark - or family.get("private_timing_excludes_source_crossing") is not True - ): - raise GateError("hidden family top-level execution census is inconsistent") - cold_prepare = family.get("cold_prepare_seconds") - if ( - isinstance(cold_prepare, bool) - or not isinstance(cold_prepare, (int, float)) - or not math.isfinite(float(cold_prepare)) - or float(cold_prepare) < 0.0 - ): - raise GateError("hidden family cold preparation timing is invalid") - - raw_queries = family.get("queries") - if not isinstance(raw_queries, Sequence) or isinstance(raw_queries, (str, bytes)): - raise GateError("hidden family query outputs are absent") - if len(raw_queries) != len(queries): - raise GateError("hidden family returned the wrong query count") - rows: list[dict[str, object]] = [] - for expected, raw in zip(queries, raw_queries, strict=True): - if not isinstance(raw, Mapping): - raise GateError("hidden family query output is not a mapping") - if ( - raw.get("selected_public_flow_id") != expected.flow_index - or tuple(raw.get("public_helicities", ())) != expected.helicities - or not isinstance(raw.get("query_digest"), str) - ): - raise GateError("hidden family query identity/order changed") - raw_amplitudes = raw.get("raw_amplitudes") - normalized_values = raw.get("normalized_values") - if ( - not isinstance(raw_amplitudes, Sequence) - or isinstance(raw_amplitudes, (str, bytes)) - or not isinstance(normalized_values, Sequence) - or isinstance(normalized_values, (str, bytes)) - or len(raw_amplitudes) != point_count - or len(normalized_values) != point_count - ): - raise GateError("hidden family query returned the wrong point axis") - parsed_raw = tuple( - complex( - _real(pair[0], "family raw real"), - _real(pair[1], "family raw imag"), - ) - for pair in raw_amplitudes - if isinstance(pair, Sequence) - and not isinstance(pair, (str, bytes)) - and len(pair) == 2 - ) - if len(parsed_raw) != point_count: - raise GateError("hidden family query has malformed raw amplitudes") - parsed_normalized = tuple( - _real(value, "family normalized value") for value in normalized_values - ) - rows.append( - { - "query": expected.label, - "query_digest": raw["query_digest"], - "raw_amplitudes": parsed_raw, - "normalized_values": parsed_normalized, - } - ) - - elapsed = family.get("private_warmed_elapsed_seconds") - per_point = family.get("private_warmed_seconds_per_point") - if benchmark: - if not isinstance(elapsed, (int, float)) or not isinstance( - per_point, (int, float) - ): - raise GateError("hidden family benchmark omitted timings") - expected = float(elapsed) / (repetitions * point_count) - if ( - not math.isfinite(float(elapsed)) - or float(elapsed) < 0.0 - or not math.isclose(float(per_point), expected, rel_tol=1.0e-15) - ): - raise GateError("hidden family benchmark timings are inconsistent") - elif elapsed is not None or per_point is not None: - raise GateError("untimed hidden family returned timings") - return { - "queries": rows, - "census": census, - "union_total_kernel_application_count": union_total, - "cold_prepare_seconds": float(cold_prepare), - "private_warmed_elapsed_seconds": elapsed, - "private_warmed_seconds_per_point": per_point, - "private_timing_excludes_source_crossing": True, - } - - -def _axes(resolved: object) -> tuple[dict[str, int], dict[str, int]]: - helicities = tuple(resolved.helicity_ids) - colors = tuple(resolved.color_ids) - if ( - not helicities - or not colors - or len(set(helicities)) != len(helicities) - or len(set(colors)) != len(colors) - ): - raise GateError("resolved axes are empty or ambiguous") - return ( - {value: index for index, value in enumerate(helicities)}, - {value: index for index, value in enumerate(colors)}, - ) - - -def _resolved_component_checks( - candidate: object, reference: object, label: str -) -> dict[str, object]: - candidate_helicities = tuple(candidate.helicity_ids) - candidate_colors = tuple(candidate.color_ids) - reference_helicities = tuple(reference.helicity_ids) - reference_colors = tuple(reference.color_ids) - candidate_helicity_axis, candidate_color_axis = _axes(candidate) - reference_helicity_axis, reference_color_axis = _axes(reference) - if set(candidate_helicities) != set(reference_helicities) or set( - candidate_colors - ) != set(reference_colors): - raise GateError(f"{label} resolved selector axes differ") - candidate_values = tuple(candidate.values) - reference_values = tuple(reference.values) - if not candidate_values or len(candidate_values) != len(reference_values): - raise GateError(f"{label} resolved point axes differ or are empty") - rows: list[dict[str, object]] = [] - try: - for helicity_id in candidate_helicities: - candidate_helicity_index = candidate_helicity_axis[helicity_id] - reference_helicity_index = reference_helicity_axis[helicity_id] - for color_id in candidate_colors: - candidate_color_index = candidate_color_axis[color_id] - reference_color_index = reference_color_axis[color_id] - rows.append( - _series( - tuple( - point[candidate_helicity_index][candidate_color_index] - for point in candidate_values - ), - tuple( - point[reference_helicity_index][reference_color_index] - for point in reference_values - ), - f"{label} {helicity_id}/{color_id}", - ) - ) - except (IndexError, TypeError) as error: - raise GateError(f"{label} resolved values have an invalid shape") from error - return _summaries(rows) - - -def _public_evaluation( - runtime: object, - points: Points, - workload: str, - label: str, -) -> PublicEvaluation: - if workload == "selected_flow_helicity_sum": - selectors = {"color_flows": (FLOW_ID,)} - expected_axis = "color_ids" - expected_ids = (FLOW_ID,) - elif workload == "all_flow_single_helicity": - selectors = {"helicities": (HELICITY_ID,)} - expected_axis = "helicity_ids" - expected_ids = (HELICITY_ID,) - else: - raise GateError(f"unknown public correctness workload: {workload}") - total = tuple(runtime.evaluate(points, **selectors)) - resolved = runtime.evaluate_resolved(points, **selectors) - if tuple(getattr(resolved, expected_axis, ())) != expected_ids: - raise GateError(f"{label} did not resolve the exact public selector ID") - if len(total) != len(points): - raise GateError(f"{label} returned the wrong point count") - return PublicEvaluation(total=total, resolved=resolved) - - -def _recurrence_authority_correctness( - runtime: object, - selected_recurrence_runtime: object, - all_flow_recurrence_runtime: object, - points: Points, -) -> RecurrenceAuthorityCorrectness: - recurrence_selected = _public_evaluation( - selected_recurrence_runtime, - points, - "selected_flow_helicity_sum", - "selected recurrence authority", - ) - recurrence_all_flow = _public_evaluation( - all_flow_recurrence_runtime, - points, - "all_flow_single_helicity", - "all-flow recurrence authority", - ) - on_the_fly_selected = _public_evaluation( - runtime, - points, - "selected_flow_helicity_sum", - "on-the-fly selected candidate", - ) - on_the_fly_all_flow = _public_evaluation( - runtime, - points, - "all_flow_single_helicity", - "on-the-fly all-flow candidate", - ) - public_correctness = { - "selected_flow_helicity_sum": { - "total_authority": _series( - on_the_fly_selected.total, - recurrence_selected.total, - "on-the-fly selected total/recurrence authority", - ), - "resolved_authority": _resolved_component_checks( - on_the_fly_selected.resolved, - recurrence_selected.resolved, - "on-the-fly selected resolved/recurrence authority", - ), - "total_resolved_identity": _series( - on_the_fly_selected.total, - on_the_fly_selected.resolved.total(), - "on-the-fly selected total/resolved", - ), - }, - "all_flow_single_helicity": { - "total_authority": _series( - on_the_fly_all_flow.total, - recurrence_all_flow.total, - "on-the-fly all-flow total/recurrence authority", - ), - "resolved_authority": _resolved_component_checks( - on_the_fly_all_flow.resolved, - recurrence_all_flow.resolved, - "on-the-fly all-flow resolved/recurrence authority", - ), - "total_resolved_identity": _series( - on_the_fly_all_flow.total, - on_the_fly_all_flow.resolved.total(), - "on-the-fly all-flow total/resolved", - ), - }, - } - - runtime.clear() - selected_after_clear = _public_evaluation( - runtime, - points, - "selected_flow_helicity_sum", - "on-the-fly selected candidate after clear", - ) - all_flow_after_clear = _public_evaluation( - runtime, - points, - "all_flow_single_helicity", - "on-the-fly all-flow candidate after clear", - ) - clear_checks = { - "selected_total": _series( - selected_after_clear.total, - recurrence_selected.total, - "on-the-fly selected total/recurrence authority after clear", - ), - "selected_resolved": _resolved_component_checks( - selected_after_clear.resolved, - recurrence_selected.resolved, - "on-the-fly selected resolved/recurrence authority after clear", - ), - "all_flow_total": _series( - all_flow_after_clear.total, - recurrence_all_flow.total, - "on-the-fly all-flow total/recurrence authority after clear", - ), - "all_flow_resolved": _resolved_component_checks( - all_flow_after_clear.resolved, - recurrence_all_flow.resolved, - "on-the-fly all-flow resolved/recurrence authority after clear", - ), - } - return RecurrenceAuthorityCorrectness( - recurrence_selected=recurrence_selected, - recurrence_all_flow=recurrence_all_flow, - on_the_fly_selected=on_the_fly_selected, - on_the_fly_all_flow=on_the_fly_all_flow, - public_correctness=public_correctness, - clear_checks=clear_checks, - ) - - -def _dense_authority( - selected_runtime: object, - all_flow_runtime: object, - point_count: int, -) -> dict[str, object]: - return { - "authority_kind": "validated_recurrence", - "authority_execution_mode": "recurrence", - "runtime_api": "Runtime.evaluate_resolved", - "selected_flow_artifact_id": selected_runtime.artifact_id, - "all_flow_artifact_id": all_flow_runtime.artifact_id, - "point_count": point_count, - "certifies": ( - "selected_flow_helicity_sum", - "all_flow_single_helicity", - ), - } - - -def _benchmark_config( - target: float, - batch: int, - *, - helicities: tuple[str, ...] = (), - flows: tuple[str, ...] = (), -) -> BenchmarkConfig: - return BenchmarkConfig( - target_runtime=target, - batch_size=batch, - precision=16, - warmup_runs=WARMUPS, - minimum_samples=MINIMUM_SAMPLES, - helicity_ids=helicities, - color_flow_ids=flows, - ) - - -def _public_recurrence_work(result: object) -> dict[str, object] | None: - breakdown = result.timing_breakdown - counters = None if breakdown is None else breakdown.counters - if counters is None: - return None - role_counts = { - "source_calls_per_runtime_call": counters.recurrence_source_calls_per_call, - "source_rows_per_runtime_call": counters.recurrence_source_rows_per_call, - "contribution_calls_per_runtime_call": ( - counters.recurrence_contribution_calls_per_call - ), - "contribution_rows_per_runtime_call": ( - counters.recurrence_contribution_rows_per_call - ), - "finalization_calls_per_runtime_call": ( - counters.recurrence_finalization_calls_per_call - ), - "finalization_rows_per_runtime_call": ( - counters.recurrence_finalization_rows_per_call - ), - "closure_calls_per_runtime_call": counters.recurrence_closure_calls_per_call, - "closure_rows_per_runtime_call": counters.recurrence_closure_rows_per_call, - } - if not any(value is not None for value in role_counts.values()): - return None - return { - "basis": counters.normalization, - "semantics": ( - "rows are logical DirectPlan applications; calls are grouped " - "prepared-backend invocations" - ), - **role_counts, - } - - -def _public_timing(result: object, execution_mode: str) -> dict[str, object]: - breakdown = result.timing_breakdown - if breakdown is None or breakdown.execution_mode != execution_mode: - raise GateError( - f"public {execution_mode} benchmark has no matching timing breakdown" - ) - evaluator_label = ( - "recurrence core" - if execution_mode == "recurrence" - else "warmed evaluator envelope" - ) - return { - "execution_mode": execution_mode, - "sample_count": result.sample_count, - "repetitions_per_sample": result.repetitions_per_sample, - "wall_seconds_per_point": result.wall_time_per_point, - "evaluator_seconds_per_point": result.evaluator_time_per_point, - "evaluator_total_seconds_per_point": result.evaluator_total_time_per_point, - "clock_attribution": { - "wall_seconds_per_point": "BenchmarkRunner outer wall clock", - "evaluator_seconds_per_point": evaluator_label, - "evaluator_total_seconds_per_point": ( - "independently accumulated warmed evaluator-total clock" - ), - "relationship": ( - "all reported clocks are independent; equality is neither assumed " - "nor asserted" - ), - }, - "interrupted": result.interrupted, - "effective_config": dataclasses.asdict(result.effective_config), - "uncertainty": dataclasses.asdict(result.uncertainty), - "recurrence_runtime_work": ( - None if execution_mode == "compiled" else _public_recurrence_work(result) - ), - } - - -def _exact_on_the_fly_capabilities(value: object, label: str) -> None: - capabilities = _items(value, label) - if capabilities != ON_THE_FLY_CAPABILITIES: - raise GateError( - f"{label} must contain exactly the two LC on-the-fly capabilities" - ) - - -def _manifest_payload_record( - manifest: Any, - relative: str, - *, - role: str, - process_id: str | None, -) -> object: - records = tuple( - record - for record in getattr(manifest, "payloads", ()) - if record.path == relative - ) - if len(records) != 1: - raise GateError( - f"on-the-fly artifact must authenticate exactly one {relative!r} payload" - ) - record = records[0] - if record.role != role or record.process_id != process_id or record.executable: - raise GateError( - f"authenticated on-the-fly payload {relative!r} has wrong ownership, " - "role, or executable state" - ) - return record - - -def _authenticated_json_payload( - manifest: Any, - relative: str, - *, - role: str, - process_id: str | None, - label: str, -) -> Mapping[str, object]: - _manifest_payload_record( - manifest, - relative, - role=role, - process_id=process_id, - ) - try: - path = confined_path(manifest.root, relative) - payload = json.loads(path.read_text(encoding="utf-8")) - except (ArtifactError, OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise GateError(f"cannot read authenticated {label}: {relative}") from error - return _mapping(payload, label) - - -def _resolved_artifact_relative( - manifest: Any, base: Path, relative: object, label: str -) -> str: - if not isinstance(relative, str) or not relative: - raise GateError(f"{label} is not a non-empty relative path") - joined = (base / relative).as_posix() - try: - path = confined_path(manifest.root, joined) - except ArtifactError as error: - raise GateError(f"{label} is not confined to the artifact") from error - return path.relative_to(manifest.root).as_posix() - - -def _on_the_fly_artifact_contract(artifact: Path, runtime: object) -> dict[str, object]: - try: - manifest = load_manifest(artifact, verify_payloads=True) - except (ArtifactError, OSError) as error: - raise GateError( - f"cannot authenticate generated on-the-fly artifact: {artifact}" - ) from error - - _exact_on_the_fly_capabilities( - manifest.runtime.get("required_runtime_capabilities"), - "artifact runtime capabilities", - ) - processes = tuple(manifest.processes) - if len(processes) != 1 or processes[0].get("id") != PROCESS_ID: - raise GateError( - "generated on-the-fly artifact must contain exactly the fixed process" - ) - process = processes[0] - expression = process.get("expression") - if ( - not isinstance(expression, str) - or canonical_process_key(expression) != PROCESS_KEY - or process.get("color_accuracy") != "lc" - ): - raise GateError("generated on-the-fly artifact has wrong process identity") - _exact_on_the_fly_capabilities( - process.get("required_runtime_capabilities"), - "process runtime capabilities", - ) - - evaluator_relative = str(manifest.runtime["evaluator_manifest_path"]) - evaluator_set = _authenticated_json_payload( - manifest, - evaluator_relative, - role="evaluator-manifest", - process_id=None, - label="on-the-fly evaluator set", - ) - if set(evaluator_set) != { - "schema_version", - "kind", - "required_runtime_capabilities", - "processes", - } or ( - evaluator_set.get("schema_version") != 3 - or evaluator_set.get("kind") != "pyamplicol-runtime-execution-set" - ): - raise GateError("generated on-the-fly evaluator set is not compact v3") - _exact_on_the_fly_capabilities( - evaluator_set.get("required_runtime_capabilities"), - "evaluator-set runtime capabilities", - ) - entries = _records(evaluator_set.get("processes"), "evaluator-set processes") - if len(entries) != 1: - raise GateError("on-the-fly evaluator set must select exactly one process") - entry = entries[0] - if ( - set(entry) - != { - "process_id", - "manifest_path", - "required_runtime_capabilities", - } - or entry.get("process_id") != PROCESS_ID - ): - raise GateError("on-the-fly evaluator-set process entry is invalid") - _exact_on_the_fly_capabilities( - entry.get("required_runtime_capabilities"), - "evaluator-set process capabilities", - ) - execution_relative = _resolved_artifact_relative( - manifest, - Path(evaluator_relative).parent, - entry.get("manifest_path"), - "on-the-fly execution path", - ) - record = _authenticated_json_payload( - manifest, - execution_relative, - role="evaluator-manifest", - process_id=PROCESS_ID, - label="on-the-fly execution", - ) - _reject_materialization_fields(record, "on-the-fly execution") - if set(record) != { - "schema_version", - "kind", - "required_runtime_capabilities", - "process", - "key", - "color_accuracy", - "external_pdg_order", - "kernel_pack", - "runtime_options", - "selector_policy", - "runtime_metadata", - "runtime_container", - }: - raise GateError("generated on-the-fly execution has non-compact fields") - _exact_on_the_fly_capabilities( - record.get("required_runtime_capabilities"), - "execution runtime capabilities", - ) - container = _mapping( - record.get("runtime_container"), "on-the-fly runtime container" - ) - if ( - record.get("schema_version") != 3 - or record.get("kind") != "pyamplicol-runtime-on-the-fly-execution" - or record.get("process") != expression - or record.get("key") != PROCESS_ID - or record.get("color_accuracy") != "lc" - or tuple(_items(record.get("external_pdg_order"), "external PDG order")) - != tuple(process["external_pdgs"]) - or set(container) - != { - "kind", - "schema_version", - "storage_abi", - "path", - "seed_member_path", - } - or container.get("kind") != "pyamplicol-on-the-fly-runtime-container" - or container.get("schema_version") != 1 - or container.get("storage_abi") != "pacbin-v1" - or container.get("path") != "on-the-fly-runtime.pacbin" - or container.get("seed_member_path") != ON_THE_FLY_SEED_MEMBER_PATH - ): - raise GateError("generated on-the-fly artifact has the wrong compact contract") - kernel_pack = _mapping(record.get("kernel_pack"), "on-the-fly kernel pack") - if kernel_pack != { - "manifest_path": "model/eager-kernel-pack.json", - "payload_root": "model/eager-kernels", - }: - raise GateError("generated on-the-fly kernel-pack paths are not canonical") - runtime_options = _mapping( - record.get("runtime_options"), "on-the-fly runtime options" - ) - if ( - set(runtime_options) != {"point_tile_size", "query_construction_threads"} - or runtime_options.get("query_construction_threads") != 1 - ): - raise GateError("generated on-the-fly runtime options differ") - selector_policy = _mapping( - record.get("selector_policy"), - "on-the-fly selector policy", - ) - if selector_policy != { - "color_coverage": "complete", - "reference_color_word": None, - "trace_reflections_folded": False, - "selector_census": { - "physical_helicity_count": 64, - "physical_color_flow_count": 12, - }, - }: - raise GateError("generated on-the-fly selector census is invalid") - - physics_relative = str(process["physics_path"]) - public = _authenticated_json_payload( - manifest, - physics_relative, - role="runtime-physics", - process_id=PROCESS_ID, - label="on-the-fly public metadata", - ) - _reject_materialization_fields(public, "on-the-fly public metadata") - if set(public) != { - "schema_version", - "kind", - "process_id", - "process", - "color_accuracy", - "external_particles", - "model_parameters", - } or ( - public.get("schema_version") != 1 - or public.get("kind") != "pyamplicol-on-the-fly-public-metadata" - or public.get("process_id") != PROCESS_ID - or public.get("process") != expression - or public.get("color_accuracy") != "lc" - ): - raise GateError("generated on-the-fly public metadata is not compact LC") - - validation_relative = f"processes/{PROCESS_ID}/validation-momenta.json" - _manifest_payload_record( - manifest, - validation_relative, - role="validation-momenta", - process_id=PROCESS_ID, - ) - runtime_relative = _resolved_artifact_relative( - manifest, - Path(execution_relative).parent, - container.get("path"), - "on-the-fly runtime container path", - ) - runtime_record = _manifest_payload_record( - manifest, - runtime_relative, - role="evaluator-state", - process_id=PROCESS_ID, - ) - process_evaluator_state = tuple( - payload - for payload in manifest.payloads - if payload.role == "evaluator-state" and payload.process_id == PROCESS_ID - ) - if process_evaluator_state != (runtime_record,): - raise GateError( - "runtime PACBIN must be the sole process-owned evaluator-state payload" - ) - - expected_inventory = { - execution_relative, - physics_relative, - runtime_relative, - validation_relative, - } - process_prefix = f"processes/{PROCESS_ID}/" - authenticated_inventory = { - payload.path - for payload in manifest.payloads - if payload.process_id == PROCESS_ID or payload.path.startswith(process_prefix) - } - process_root = manifest.root / "processes" / PROCESS_ID - try: - physical_inventory = { - path.relative_to(manifest.root).as_posix() - for path in process_root.rglob("*") - if path.is_file() - } - except OSError as error: - raise GateError( - "cannot inventory generated on-the-fly process files" - ) from error - if ( - authenticated_inventory != expected_inventory - or physical_inventory != expected_inventory - ): - unexpected = sorted( - (authenticated_inventory | physical_inventory) - expected_inventory - ) - missing = sorted( - expected_inventory - (authenticated_inventory & physical_inventory) - ) - raise GateError( - "generated on-the-fly process inventory contains materialized sidecars " - f"or omissions; unexpected={unexpected!r}, missing={missing!r}" - ) - - try: - runtime_path = confined_path(manifest.root, runtime_relative) - with PacbinReader.open(runtime_path, verify_payloads=True) as reader: - members = reader.members - except (ArtifactError, OSError, PacbinError) as error: - raise GateError("cannot authenticate on-the-fly runtime PACBIN") from error - if ( - len(members) != 1 - or members[0].logical_path != ON_THE_FLY_SEED_MEMBER_PATH - or members[0].kind is not PacbinMemberKind.ON_THE_FLY_PROCESS_SEED - or members[0].length <= 0 - ): - raise GateError( - "on-the-fly runtime PACBIN must contain exactly one process seed" - ) - if ( - runtime.execution_mode != "on-the-fly" - or runtime.representative_process_key != PROCESS_ID - or runtime.artifact_id != manifest.artifact_id - ): - raise GateError("Runtime.load did not select the generated on-the-fly process") - return { - "artifact": str(manifest.root), - "artifact_id": runtime.artifact_id, - "execution_mode": runtime.execution_mode, - "representative_process_key": runtime.representative_process_key, - "execution_kind": record["kind"], - "required_runtime_capabilities": ON_THE_FLY_CAPABILITIES, - "selector_census": selector_policy["selector_census"], - "process_file_inventory": tuple(sorted(expected_inventory)), - "process_evaluator_state_payload_count": len(process_evaluator_state), - "runtime_container_kind": container["kind"], - "runtime_container_authenticated": True, - "runtime_container_member_count": len(members), - "seed_member_path": container["seed_member_path"], - "seed_member_kind": members[0].kind.name, - "dense_physics_accessed": False, - "validation_boundary": ( - "authenticated manifest/public/execution metadata and PACBIN followed " - "by compact post-build Runtime.load; candidate dense physics metadata " - "is never opened" - ), - } - - -def _on_the_fly_public_profile( - runtime: object, - points: Points, - expected: Sequence[object], - *, - helicities: tuple[str, ...] = (), - flows: tuple[str, ...] = (), -) -> dict[str, object]: - backend = getattr(runtime, "_backend", None) - profiler = getattr(backend, "profile", None) - if not callable(profiler): - raise GateError("public Runtime backend has no existing profile API") - payload = profiler( - points, - helicities=helicities or None, - color_flows=flows or None, - precision=16, - include_values=True, - ) - if ( - not isinstance(payload, Mapping) - or payload.get("execution_mode") != "on-the-fly" - ): - raise GateError("on-the-fly profile did not report its execution lane") - values = payload.get("values") - if not isinstance(values, Sequence) or isinstance(values, (str, bytes)): - raise GateError("on-the-fly profile omitted requested values") - value_check = _series(tuple(values), expected, "on-the-fly profile values") - counts: dict[str, int] = {} - for name in PUBLIC_PROFILE_WORK_FIELDS: - counts[name] = _count(payload.get(name), f"on-the-fly profile {name}") - if any( - counts[f"recurrence_{role}_call_count"] > counts[f"recurrence_{role}_row_count"] - for role in ("source", "contribution", "finalization", "closure") - ): - raise GateError("on-the-fly profile has more grouped calls than rows") - wall = payload.get("wall_time_s") - if ( - isinstance(wall, bool) - or not isinstance(wall, (int, float)) - or not math.isfinite(float(wall)) - or float(wall) < 0.0 - ): - raise GateError("on-the-fly profile wall clock is invalid") - return { - "api": "existing Runtime backend profile", - "execution_mode": "on-the-fly", - "point_count": len(points), - "selectors": {"helicities": helicities, "color_flows": flows}, - "value_check": value_check, - "wall_seconds": float(wall), - "work": { - "basis": "one warmed public profile call", - "semantics": ( - "rows are executed recurrence-style transitions; calls are grouped " - "prepared-executor invocations and are not current counts" - ), - **counts, - }, - } - - -def _workload_operation_census( - rows: Sequence[Mapping[str, object]], -) -> dict[str, object]: - sums = {name: 0 for name in OPERATION_COUNT_FIELDS} - total = 0 - for row in rows: - census = row.get("work_census") - if ( - not isinstance(census, Mapping) - or census.get("work_census_basis") != WORK_CENSUS_BASIS - ): - raise GateError("timed query has no valid work census") - for name in OPERATION_COUNT_FIELDS: - value = census.get(name) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError("timed query operation census is invalid") - sums[name] += value - kernel_count = census.get("total_kernel_application_count") - if ( - isinstance(kernel_count, bool) - or not isinstance(kernel_count, int) - or kernel_count < 0 - ): - raise GateError("timed query kernel-application census is invalid") - total += kernel_count - if total != sum(sums.values()): - raise GateError("workload kernel and operation sums disagree") - return { - "aggregation_basis": "sum-one-execution-per-serialized-query-v1", - "query_census_basis": WORK_CENSUS_BASIS, - "query_count": len(rows), - **sums, - "total_kernel_application_count": total, - } - - -def _query_family_census( - probe: Callable[..., dict[str, Any]], - retained: RetainedInputs, - queries: Sequence[Query], - hidden_timing: Mapping[str, object], - enable_color_projection: bool, -) -> dict[str, object]: - if not queries: - raise GateError("query-family census needs at least one query") - raw = probe( - retained.builder, - retained.template, - retained.direct_json, - retained.pack_digest, - [query.flow_index for query in queries], - [list(query.helicities) for query in queries], - enable_color_projection=enable_color_projection, - ) - if not isinstance(raw, Mapping): - raise GateError("native query-family census is not a mapping") - counts: dict[str, int] = {} - for name in FAMILY_CENSUS_COUNT_FIELDS: - value = raw.get(name) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"native query-family census has invalid {name}") - counts[name] = value - if counts["query_count"] != len(queries): - raise GateError("native query-family census has the wrong query count") - if not 0 < counts["source_frame_partition_count"] <= len(queries): - raise GateError( - "native query-family census has invalid source-frame partitions" - ) - - rows = hidden_timing.get("queries") - operation_census = hidden_timing.get("workload_operation_census") - if ( - not isinstance(rows, Sequence) - or isinstance(rows, (str, bytes)) - or not isinstance(operation_census, Mapping) - ): - raise GateError("timed workload has no query-local census") - current_occurrences = 0 - component_occurrences = 0 - for row in rows: - if not isinstance(row, Mapping) or not isinstance( - row.get("work_census"), Mapping - ): - raise GateError("timed workload query has no work census") - work = row["work_census"] - for name, target in ( - ("logical_current_count", "current"), - ("resident_current_component_count", "component"), - ): - value = work.get(name) - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"timed workload has invalid {target} census") - if name == "logical_current_count": - current_occurrences += value - else: - component_occurrences += value - expected_rows = { - "dynamic_source_rows": "source_operation_count", - "dynamic_contribution_rows": "contribution_operation_count", - "dynamic_finalization_rows": "finalization_operation_count", - "dynamic_closure_rows": "closure_operation_count", - } - if ( - counts["dynamic_current_occurrence_count"] != current_occurrences - or counts["dynamic_current_component_occurrence_count"] != component_occurrences - or any( - counts[native] != operation_census.get(query_local) - for native, query_local in expected_rows.items() - ) - or counts["projection_post_current_count"] != current_occurrences - or counts["projection_post_contribution_count"] - != counts["dynamic_contribution_rows"] - or counts["projection_post_closure_count"] != counts["dynamic_closure_rows"] - ): - raise GateError( - "native query-family census disagrees with independently timed query traces" - ) - for role in ("source", "contribution", "finalization", "closure"): - if counts[f"dynamic_{role}_calls"] != counts[f"dynamic_{role}_rows"]: - raise GateError("query-local dynamic call census is inconsistent") - if counts[f"union_{role}_executor_call_groups"] > counts[f"union_{role}_rows"]: - raise GateError("query-family executor groups outnumber union rows") - if ( - counts["union_amplitude_destination_count"] != len(queries) - or counts["union_unique_current_count"] > current_occurrences - or counts["union_unique_current_component_count"] > component_occurrences - or any( - counts[f"union_{role}_rows"] > counts[f"dynamic_{role}_rows"] - for role in ("source", "contribution", "finalization", "closure") - ) - ): - raise GateError("query-family union census does not bound query-local work") - return { - "basis": "exact-current-core-key-query-family-union-v1", - "semantics": ( - "dynamic counts sum today's independently executed query-local traces; " - "union counts intern exact semantic currents/interactions within each " - "authenticated source-frame partition while retaining one amplitude " - "destination per requested query" - ), - **counts, - } - - -def _assert_executable_family_matches_structural_census( - executable: Mapping[str, object], structural: Mapping[str, object] -) -> None: - for name in FAMILY_CENSUS_COUNT_FIELDS: - if executable.get(name) != structural.get(name): - raise GateError( - f"executable family census disagrees with the independent structural " - f"census for {name}" - ) - - -def _mapping(value: object, label: str) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise GateError(f"{label} is not a mapping") - return value - - -def _items(value: object, label: str) -> tuple[object, ...]: - if not isinstance(value, Sequence) or isinstance(value, (str, bytes)): - raise GateError(f"{label} is not a sequence") - return tuple(value) - - -def _records(value: object, label: str) -> tuple[Mapping[str, object], ...]: - return tuple( - _mapping(item, f"{label}[{index}]") - for index, item in enumerate(_items(value, label)) - ) - - -def _count(value: object, label: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise GateError(f"{label} is not a non-negative integer") - return value - - -def _field(value: object, name: str) -> object: - if isinstance(value, Mapping): - return value.get(name) - return getattr(value, name, None) - - -def _artifact_execution( - artifact: Path, - execution_mode: str, - runtime: object | None = None, -) -> tuple[object, Mapping[str, object], Path]: - try: - root = artifact.expanduser().resolve(strict=True) - except OSError as error: - raise GateError(f"comparator artifact does not exist: {artifact}") from error - if not root.is_dir(): - raise GateError(f"comparator artifact is not a directory: {root}") - if runtime is None: - runtime = Runtime.load(root) - physics = _validate_comparator_physics(runtime, execution_mode, str(root)) - process_id = physics.process_id - path = root / "processes" / process_id / "execution.json" - try: - payload = json.loads(path.read_text(encoding="utf-8")) - except ( - OSError, - UnicodeDecodeError, - json.JSONDecodeError, - ) as error: - raise GateError(f"cannot read comparator execution record: {path}") from error - return runtime, _mapping(payload, "comparator execution record"), root - - -def _validate_comparator_physics( - runtime: object, execution_mode: str, label: str -) -> object: - physics = runtime.physics - process = getattr(physics, "process", None) - process_id = getattr(physics, "process_id", None) - color_accuracy = getattr(physics, "color_accuracy", None) - external_pdgs: list[int] = [] - for index, particle in enumerate(getattr(physics, "external_particles", ())): - pdg_id = _field(particle, "pdg_id") - if isinstance(pdg_id, bool) or not isinstance(pdg_id, int): - raise GateError( - f"{label} external particle {index} has an invalid PDG ID: {pdg_id!r}" - ) - external_pdgs.append(pdg_id) - if runtime.execution_mode != execution_mode or color_accuracy != "lc": - raise GateError(f"{label} is not an LC {execution_mode} authority") - if ( - not isinstance(process, str) - or process != PROCESS - or canonical_process_key(process) != PROCESS_KEY - or process_id != PROCESS_ID - ): - raise GateError( - f"{label} has the wrong canonical process identity: {process!r}" - ) - if tuple(external_pdgs) != EXTERNAL_PDGS: - raise GateError( - f"{label} has the wrong external PDG ordering: {tuple(external_pdgs)!r}" - ) - return physics - - -def _recurrence_counts( - record: Mapping[str, object], - *, - components: object | None = None, - destinations: object | None = None, - certificate: bool = False, -) -> dict[str, int]: - closure_key = "closure_count" if certificate else "closure_term_count" - result = { - "source_row_count": _count( - record.get("source_row_count"), "recurrence source-row count" - ), - "current_count": _count( - record.get("current_count"), "recurrence current count" - ), - "semantic_current_component_count": _count( - ( - record.get("semantic_component_count") - if components is None - else components - ), - "recurrence semantic-component count", - ), - "contribution_count": _count( - record.get("contribution_count"), "recurrence contribution count" - ), - "finalization_count": _count( - record.get("finalization_count"), "recurrence finalization count" - ), - "closure_count": _count(record.get(closure_key), "recurrence closure count"), - "amplitude_destination_count": _count( - ( - record.get("amplitude_destination_count") - if destinations is None - else destinations - ), - "recurrence amplitude-destination count", - ), - } - if result["semantic_current_component_count"] < result["current_count"]: - raise GateError("recurrence has fewer components than currents") - result["kernel_row_count"] = sum( - result[name] - for name in ( - "source_row_count", - "contribution_count", - "finalization_count", - "closure_count", - ) - ) - if certificate and result["kernel_row_count"] != _count( - record.get("row_count"), "recurrence certificate row count" - ): - raise GateError("recurrence certificate row count is inconsistent") - return result - - -def _exact_public_index(records: object, selector_id: str, label: str) -> int: - matches = [ - record for record in records if getattr(record, "id", None) == selector_id - ] - if len(matches) != 1: - raise GateError(f"{label} selector {selector_id!r} is absent or ambiguous") - index = getattr(matches[0], "index", None) - if isinstance(index, bool) or not isinstance(index, int) or index < 0: - raise GateError(f"{label} selector {selector_id!r} has an invalid public index") - return index - - -def _recurrence_artifact_census( - artifact: Path, *, layout: str, runtime: object | None = None -) -> dict[str, object]: - runtime, payload, root = _artifact_execution(artifact, "recurrence", runtime) - if payload.get("kind") != "pyamplicol-runtime-recurrence-execution": - raise GateError("recurrence comparator has the wrong execution kind") - summary = _mapping(payload.get("recurrence_summary"), "recurrence summary") - plan = _mapping(payload.get("plan"), "recurrence plan") - inspection = _mapping(plan.get("inspection_summary"), "recurrence inspection") - if inspection.get("lc_flow_layout") != layout: - raise GateError(f"recurrence comparator is not {layout!r}") - schedule = _mapping(inspection.get("schedule"), "recurrence schedule") - arena = _mapping(inspection.get("direct_arena"), "recurrence direct arena") - whole = _recurrence_counts( - schedule, components=arena.get("semantic_component_count") - ) - if ( - summary.get("current_count") != whole["current_count"] - or summary.get("contribution_count") != whole["contribution_count"] - or summary.get("closure_term_count") != whole["closure_count"] - ): - raise GateError("recurrence schedule summaries disagree") - certificate = _mapping( - inspection.get("selector_work_certificate"), - "recurrence selector-work certificate", - ) - union = _recurrence_counts( - _mapping(certificate.get("persisted_union"), "recurrence persisted union"), - destinations=whole["amplitude_destination_count"], - certificate=True, - ) - if union != whole: - raise GateError("recurrence whole schedule and persisted union disagree") - - physics = runtime.physics - if layout == "topology-replay": - public_index = _exact_public_index( - physics.color_flows, FLOW_ID, "recurrence color-flow" - ) - metadata = _mapping(payload.get("runtime_metadata"), "recurrence metadata") - public_flows = _records( - metadata.get("public_color_flows"), "recurrence public color flows" - ) - bindings = [ - record for record in public_flows if record.get("public_id") == FLOW_ID - ] - if len(bindings) != 1: - raise GateError("recurrence color-flow binding is absent or ambiguous") - target_sector = _count( - bindings[0].get("target_sector_id"), "recurrence target sector" - ) - if target_sector != public_index: - raise GateError( - "recurrence public color-flow index and target sector differ" - ) - representatives = _records( - certificate.get("representatives"), "recurrence representatives" - ) - selected = [ - record - for record in representatives - if record.get("representative_sector_id") == target_sector - ] - if len(selected) != 1: - raise GateError( - "recurrence selected-flow certificate is absent or ambiguous" - ) - live = _recurrence_counts(selected[0], certificate=True) - selector = { - "kind": "exact_public_color_flow_index", - "id": FLOW_ID, - "public_index": public_index, - "representative_sector_id": target_sector, - } - else: - public_index = _exact_public_index( - physics.helicities, HELICITY_ID, "recurrence helicity" - ) - representatives = _records( - certificate.get("representatives"), "recurrence representatives" - ) - if representatives: - raise GateError("all-flow-union recurrence certificate has alternatives") - live = union - selector = { - "kind": "exact_public_helicity_index", - "id": HELICITY_ID, - "public_index": public_index, - } - return { - "artifact": str(root), - "artifact_id": runtime.artifact_id, - "layout": layout, - "basis": "authenticated-persisted-recurrence-selector-certificate-v1", - "selector": selector, - "whole": whole, - "selector_live": live, - "semantics": ( - "whole is the persisted recurrence DirectPlan; selector_live is the " - "authenticated exact-selector certificate and is not inferred from " - "runtime timing counters" - ), - } - - -def _compiled_execution_counts( - execution: Mapping[str, object], label: str -) -> dict[str, int]: - if execution.get("kind") != "pyamplicol-runtime-execution": - raise GateError(f"{label} has the wrong execution kind") - summary = _mapping(execution.get("dag_summary"), f"{label} DAG summary") - schema = _mapping(execution.get("runtime_schema"), f"{label} runtime schema") - storage = _mapping(schema.get("current_storage"), f"{label} current storage") - result = { - "source_count": _count(summary.get("source_count"), f"{label} source count"), - "current_count": _count(summary.get("current_count"), f"{label} current count"), - "current_component_count": _count( - storage.get("component_count"), f"{label} component count" - ), - "interaction_attachment_count": _count( - summary.get("interaction_count"), f"{label} interaction count" - ), - "interaction_evaluation_count": _count( - summary.get("interaction_evaluation_count"), - f"{label} interaction-evaluation count", - ), - "amplitude_root_count": _count( - summary.get("amplitude_root_count"), f"{label} amplitude-root count" - ), - } - if result["current_component_count"] < result["current_count"]: - raise GateError(f"{label} has fewer components than currents") - if result["interaction_evaluation_count"] > result["interaction_attachment_count"]: - raise GateError(f"{label} evaluates more interactions than it attaches") - return result - - -def _compiled_artifact_census( - artifact: Path, *, workload: str, runtime: object | None = None -) -> dict[str, object]: - runtime, payload, root = _artifact_execution(artifact, "compiled", runtime) - primary = _compiled_execution_counts(payload, "compiled primary") - physics = runtime.physics - if workload == "selected_flow_helicity_sum": - public_index = _exact_public_index( - physics.color_flows, FLOW_ID, "compiled color-flow" - ) - compiled = _mapping(payload.get("compiled"), "compiled metadata") - topology = _mapping( - compiled.get("lc_topology_replay"), "compiled topology replay" - ) - matches = [ - record - for record in _records(topology.get("groups"), "compiled topology groups") - if public_index - in tuple( - _count(value, "compiled active sector") - for value in _items(record.get("active_sector_ids"), "active sectors") - ) - ] - if len(matches) != 1: - raise GateError("compiled color-flow topology group is absent or ambiguous") - materialized_sector = _count( - matches[0].get("materialized_sector_id"), - "compiled materialized sector", - ) - program_record = _mapping( - payload.get("helicity_sum_execution"), "compiled helicity-sum program" - ) - reductions = _mapping( - program_record.get("physics_reduction"), - "compiled helicity-sum physics reduction", - ) - reduction_groups = _records( - reductions.get("groups"), "compiled physics-reduction groups" - ) - if not any( - FLOW_ID in tuple(record.get("physical_color_ids", ())) - for record in reduction_groups - ): - raise GateError( - "compiled helicity-sum program does not bind the exact flow" - ) - children = _records( - program_record.get("color_selector_executions"), - "compiled color-selector executions", - ) - selected = [ - record - for record in children - if record.get("materialized_sector_id") == materialized_sector - ] - if len(selected) != 1: - raise GateError("compiled selected-flow child is absent or ambiguous") - leaf_record = _mapping(selected[0].get("execution"), "compiled selected leaf") - levels: dict[str, object] = { - "primary": primary, - "program": _compiled_execution_counts( - program_record, "compiled helicity-sum program" - ), - "executed_leaf": _compiled_execution_counts( - leaf_record, "compiled selected-flow leaf" - ), - } - selector = { - "kind": "exact_public_color_flow_index", - "id": FLOW_ID, - "public_index": public_index, - "materialized_sector_id": materialized_sector, - } - elif workload == "all_flow_single_helicity": - public_index = _exact_public_index( - physics.helicities, HELICITY_ID, "compiled helicity" - ) - current = payload - depth = 0 - while "helicity_selector_executions" in current: - children = _records( - current.get("helicity_selector_executions"), - "compiled helicity-selector executions", - ) - matching = [ - record - for record in children - if public_index - in tuple( - _count(value, "compiled selector-domain index") - for value in _items( - record.get("selector_domain_ids"), - "compiled selector-domain indices", - ) - ) - ] - if len(matching) != 1: - raise GateError( - "compiled helicity-selector child is absent or ambiguous" - ) - current = _mapping( - matching[0].get("execution"), "compiled helicity-selector child" - ) - depth += 1 - if depth == 0: - raise GateError("compiled all-flow artifact has no selector execution") - levels = { - "primary": primary, - "executed_leaf": _compiled_execution_counts( - current, "compiled all-flow executed leaf" - ), - } - selector = { - "kind": "exact_public_helicity_index", - "id": HELICITY_ID, - "public_index": public_index, - "selector_depth": depth, - } - else: - raise GateError(f"unknown compiled census workload: {workload}") - return { - "artifact": str(root), - "artifact_id": runtime.artifact_id, - "basis": "authenticated-exact-child-compiled-generic-dag-v1", - "workload": workload, - "selector": selector, - "levels": levels, - "semantics": ( - "GenericDAG counts are reported independently for the outer primary, " - "an enclosing program where present, and the one exact executed leaf; " - "alternative compiled nodes are never summed, and these attachment/" - "evaluation counts are not asserted equal to recurrence or on-the-fly rows" - ), - } - - -def _hidden_timing( - probe: Callable[..., dict[str, Any]], - artifact: Path, - retained: RetainedInputs, - queries: Sequence[Query], - points: Points, - target: float, - enable_color_projection: bool = True, -) -> dict[str, object]: - if not queries: - raise GateError("workload has no physical queries") - invoke = partial( - _invoke, - probe, - artifact, - retained, - points=points, - enable_color_projection=enable_color_projection, - ) - pilot_seconds = 0.0 - pilot_census: dict[Query, dict[str, object]] = {} - for query in queries: - report = invoke(query, repetitions=1) - _probe_values(report, len(points), 1) - pilot_census[query] = _work_census(report) - pilot_seconds += float(report["benchmark_elapsed_seconds"]) - repetitions = _calibrate(pilot_seconds, target) - rows = [] - for query in queries: - report = invoke(query, repetitions=repetitions) - _probe_values(report, len(points), repetitions) - work_census = _work_census(report) - if work_census != pilot_census[query]: - raise GateError("query work census changed between benchmark passes") - rows.append( - { - "query": query.label, - "trace_digest": report.get("trace_digest"), - "elapsed_seconds": report["benchmark_elapsed_seconds"], - "seconds_per_point": report["benchmark_seconds_per_point"], - "trace_build_count": 1, - "trace_cache_hit_count": WARMUPS + repetitions, - "momentum_fill_count": WARMUPS + repetitions, - "work_census": work_census, - } - ) - return { - "query_count": len(rows), - "pilot_aggregate_seconds": pilot_seconds, - "warmups": WARMUPS, - "repetitions": repetitions, - "aggregate_elapsed_seconds": math.fsum( - float(row["elapsed_seconds"]) for row in rows - ), - "additive_seconds_per_point": math.fsum( - float(row["seconds_per_point"]) for row in rows - ), - "queries": rows, - "workload_operation_census": _workload_operation_census(rows), - "timer_includes": ( - "trace-cache lookup", - "momentum fill", - "structural-trace execution", - ), - "timer_excludes": ( - "artifact/pack load", - "trace construction", - "parameter/workspace setup", - "source-major conversion", - "normalization/output/Python conversion", - ), - "acceptance_gate": False, - } - - -def _hidden_family_timing( - probe: Callable[..., dict[str, Any]], - artifact: Path, - retained: RetainedInputs, - queries: Sequence[Query], - points: Points, - target: float, - enable_color_projection: bool = True, -) -> tuple[dict[str, object], dict[str, object]]: - if not queries: - raise GateError("family workload has no physical queries") - invoke = partial( - _invoke, - probe, - artifact, - retained, - queries[0], - points, - enable_color_projection=enable_color_projection, - query_family=queries, - ) - pilot = _family_probe_result(invoke(repetitions=1), queries, len(points), 1) - pilot_elapsed = pilot.get("private_warmed_elapsed_seconds") - if not isinstance(pilot_elapsed, (int, float)): - raise GateError("family pilot omitted its warmed elapsed time") - repetitions = _calibrate(float(pilot_elapsed), target) - measured = _family_probe_result( - invoke(repetitions=repetitions), queries, len(points), repetitions - ) - if measured["census"] != pilot["census"]: - raise GateError("family union census changed between benchmark passes") - return measured, { - "query_count": len(queries), - "pilot_seconds": float(pilot_elapsed), - "warmups": WARMUPS, - "repetitions": repetitions, - "cold_prepare_seconds": measured["cold_prepare_seconds"], - "private_warmed_elapsed_seconds": measured["private_warmed_elapsed_seconds"], - "private_warmed_seconds_per_point": measured[ - "private_warmed_seconds_per_point" - ], - "clock_attribution": { - "private_warmed_seconds_per_point": ( - "on-the-fly private query-family execution clock" - ), - "relationship": ( - "independent of recurrence core, recurrence wall, and AmpliCol wall" - ), - }, - "private_timing_excludes_source_crossing": True, - "work_census_basis": FAMILY_WORK_CENSUS_BASIS, - "work_census": measured["census"], - "total_kernel_application_count": measured[ - "union_total_kernel_application_count" - ], - "timer_includes": ( - "shared source fill", - "one grouped union execution", - "flat caller-output write", - ), - "timer_excludes": ( - "artifact/pack load", - "query construction", - "family preparation", - "parameter/workspace setup", - "source-major crossing", - "normalization/Python conversion", - ), - "timing_status": "private-provisional", - "acceptance_gate": False, - } - - -def _hidden_family_correctness( - probe: Callable[..., dict[str, Any]], - artifact: Path, - retained: RetainedInputs, - queries: Sequence[Query], - points: Points, - normalized_authority: Sequence[Sequence[object]], - query_local_reports: Sequence[Mapping[str, object]], - enable_color_projection: bool = True, -) -> tuple[tuple[tuple[float, ...], ...], dict[str, object]]: - if ( - not queries - or len(queries) != len(normalized_authority) - or len(queries) != len(query_local_reports) - ): - raise GateError("family correctness inputs have incompatible query axes") - report = _invoke( - probe, - artifact, - retained, - queries[0], - points, - enable_color_projection=enable_color_projection, - query_family=queries, - ) - parsed = _family_probe_result(report, queries, len(points)) - parsed_rows = parsed["queries"] - if not isinstance(parsed_rows, Sequence): - raise GateError("family correctness report lost its query rows") - normalized_checks: list[dict[str, object]] = [] - raw_real_checks: list[dict[str, object]] = [] - raw_imag_checks: list[dict[str, object]] = [] - normalized_rows: list[tuple[float, ...]] = [] - for query, row, authority, query_local in zip( - queries, - parsed_rows, - normalized_authority, - query_local_reports, - strict=True, - ): - if not isinstance(row, Mapping): - raise GateError("family correctness row is malformed") - normalized = row.get("normalized_values") - raw = row.get("raw_amplitudes") - local_raw = query_local.get("raw_amplitudes") - if ( - not isinstance(normalized, Sequence) - or not isinstance(raw, Sequence) - or not isinstance(local_raw, Sequence) - or len(raw) != len(local_raw) - ): - raise GateError("family correctness row is incomplete") - normalized_tuple = tuple(_real(value, "family value") for value in normalized) - normalized_rows.append(normalized_tuple) - normalized_checks.append( - _series(normalized_tuple, authority, f"{query.label} family/public") - ) - family_complex = tuple(complex(value) for value in raw) - local_complex = tuple( - complex( - _real(value[0], "local raw real"), - _real(value[1], "local raw imag"), - ) - for value in local_raw - if isinstance(value, Sequence) - and not isinstance(value, (str, bytes)) - and len(value) == 2 - ) - if len(local_complex) != len(family_complex): - raise GateError("query-local raw amplitude row is malformed") - raw_real_checks.append( - _series( - tuple(value.real for value in family_complex), - tuple(value.real for value in local_complex), - f"{query.label} family/query-local raw real", - ) - ) - raw_imag_checks.append( - _series( - tuple(value.imag for value in family_complex), - tuple(value.imag for value in local_complex), - f"{query.label} family/query-local raw imaginary", - ) - ) - return tuple(normalized_rows), { - "normalized_component_checks": _summaries(normalized_checks), - "raw_real_component_checks": _summaries(raw_real_checks), - "raw_imaginary_component_checks": _summaries(raw_imag_checks), - "work_census_basis": FAMILY_WORK_CENSUS_BASIS, - "work_census": parsed["census"], - "total_kernel_application_count": parsed[ - "union_total_kernel_application_count" - ], - } - - -def _anchor(path: Path | None) -> dict[str, object]: - if path is None: - return {"available": False, "comparison_performed": False} - try: - payload = json.loads(path.read_text(encoding="utf-8")) - validation = payload["validation"] - selector = payload["selector_contract"] - common = validation["lc_common_component"] - except ( - OSError, - UnicodeDecodeError, - json.JSONDecodeError, - KeyError, - TypeError, - ) as error: - raise GateError(f"cannot read AmpliCol context record: {path}") from error - if payload.get("status") != "ok": - raise GateError("AmpliCol context is not a successful record") - try: - selector_matches = ( - tuple(selector.get("selected_color_flow_ids", ())) == (FLOW_ID,) - and tuple(map(tuple, selector.get("selected_color_words", ()))) - == (FLOW_WORD,) - and tuple(common.get("helicity_ids", ())) == (HELICITY_ID,) - and tuple(common.get("color_flow_ids", ())) == (FLOW_ID,) - ) - except TypeError: - selector_matches = False - return { - "available": True, - "path": str(path.resolve(strict=True)), - "cell_id": common.get("cell_id"), - "point_digest": common.get("point_digest"), - "component": common.get("value"), - "selected_flow_sum": payload.get("matrix_element"), - "execution_seconds_per_point": payload.get("execution_seconds_per_point"), - "wall_seconds_per_point": payload.get("wall_seconds_per_point"), - "clock_attribution": { - "execution_seconds_per_point": ( - "stored original-AmpliCol direct execution clock" - ), - "wall_seconds_per_point": "stored original-AmpliCol worker wall clock", - "relationship": ( - "independent clocks; equality is neither assumed nor asserted, and " - "both are independent of pyAmpliCol/on-the-fly clocks" - ), - }, - "selector_matches": selector_matches, - "comparison_performed": False, - } - - -def _anchor_checks( - context: Mapping[str, object], - digest: str, - *, - public_component: object, - hidden_component: object, - public_sum: object, - hidden_sum: object, -) -> dict[str, object]: - result = dict(context) - result["generated_point_digest"] = digest - if not context.get("available"): - return result - if context.get("cell_id") != AMPICOL_CELL_ID: - result["reason"] = "cell identity differs; historical result is context only" - return result - if context.get("selector_matches") is not True: - result["reason"] = ( - "selector identity differs; historical result is context only" - ) - return result - if context.get("point_digest") != digest: - result["reason"] = "point digest differs; historical result is context only" - return result - result.update( - { - "comparison_performed": True, - "public_component": _series( - (public_component,), - (context["component"],), - "public/AmpliCol component", - AMPICOL_REL_TOL, - ), - "hidden_component": _series( - (hidden_component,), - (context["component"],), - "on-the-fly/AmpliCol component", - AMPICOL_REL_TOL, - ), - "public_selected_flow_sum": _series( - (public_sum,), - (context["selected_flow_sum"],), - "public/AmpliCol selected-flow sum", - AMPICOL_REL_TOL, - ), - "hidden_selected_flow_sum": _series( - (hidden_sum,), - (context["selected_flow_sum"],), - "on-the-fly/AmpliCol selected-flow sum", - AMPICOL_REL_TOL, - ), - } - ) - return result - - -def _benchmark_runtime( - runtime: object, - execution_mode: str, - points: Points, - target: float, - batch: int, - *, - helicities: tuple[str, ...] = (), - flows: tuple[str, ...] = (), -) -> dict[str, object]: - result = BenchmarkRunner( - _benchmark_config(target, batch, helicities=helicities, flows=flows) - ).run(runtime, points=points) - timing = _public_timing(result, execution_mode) - wall = float(timing["wall_seconds_per_point"]) - if not math.isfinite(wall) or wall <= 0.0: - raise GateError(f"public {execution_mode} benchmark has non-positive wall time") - return timing - - -def _run_public_gate_phase( - artifact: Path, - recurrence_selected_artifact: Path, - recurrence_all_flow_artifact: Path, - target: float, - batch: int, -) -> PublicGatePhase: - started = time.perf_counter() - runtime = Runtime.load(artifact, process=PROCESS_ID) - load_seconds = time.perf_counter() - started - artifact_contract = _on_the_fly_artifact_contract(artifact, runtime) - - selected_recurrence_runtime = Runtime.load(recurrence_selected_artifact) - all_flow_recurrence_runtime = Runtime.load(recurrence_all_flow_artifact) - authorities = ( - ("selected recurrence", selected_recurrence_runtime, "recurrence"), - ("all-flow recurrence", all_flow_recurrence_runtime, "recurrence"), - ) - comparator_selectors: list[tuple[str, tuple[object, object]]] = [] - for label, authority, expected_mode in authorities: - physics = _validate_comparator_physics(authority, expected_mode, label) - comparator_selectors.append((label, _selectors(physics))) - - points = _points() - correctness = _recurrence_authority_correctness( - runtime, - selected_recurrence_runtime, - all_flow_recurrence_runtime, - points, - ) - - # This block is deliberately after the complete before/after-clear public - # authority gate. A mismatch must not produce profile or timing evidence. - public_profiles = { - "selected_flow_helicity_sum": _on_the_fly_public_profile( - runtime, - points, - correctness.on_the_fly_selected.total, - flows=(FLOW_ID,), - ), - "all_flow_single_helicity": _on_the_fly_public_profile( - runtime, - points, - correctness.on_the_fly_all_flow.total, - helicities=(HELICITY_ID,), - ), - } - timing_points = _repeat(points, batch) - timings = { - "on_the_fly": { - "selected_flow_helicity_sum": _benchmark_runtime( - runtime, - "on-the-fly", - timing_points, - target, - batch, - flows=(FLOW_ID,), - ), - "all_flow_single_helicity": _benchmark_runtime( - runtime, - "on-the-fly", - timing_points, - target, - batch, - helicities=(HELICITY_ID,), - ), - }, - "recurrence": { - "selected_flow_helicity_sum": _benchmark_runtime( - selected_recurrence_runtime, - "recurrence", - timing_points, - target, - batch, - flows=(FLOW_ID,), - ), - "all_flow_single_helicity": _benchmark_runtime( - all_flow_recurrence_runtime, - "recurrence", - timing_points, - target, - batch, - helicities=(HELICITY_ID,), - ), - }, - } - return PublicGatePhase( - runtime=runtime, - selected_recurrence_runtime=selected_recurrence_runtime, - all_flow_recurrence_runtime=all_flow_recurrence_runtime, - comparator_selectors=tuple(comparator_selectors), - points=points, - timing_points=timing_points, - correctness=correctness, - artifact_contract=artifact_contract, - load_seconds=load_seconds, - public_profiles=public_profiles, - timings=timings, - ) - - -def _run( - output: Path, - prepared_model: Path, - amplicol: Path | None, - recurrence_selected_artifact: Path, - recurrence_all_flow_artifact: Path, - target: float, - batch: int, - enable_color_projection: bool = True, -) -> dict[str, object]: - artifact = output / "artifact" - with tempfile.TemporaryDirectory( - prefix=".on-the-fly-private-probe-", dir=output - ) as probe_directory: - probe_carrier = Path(probe_directory) / "recurrence-artifact" - ( - generation_seconds, - generation_census, - model, - prepared_path, - prepared_load_seconds, - ) = _generate_candidate_with_prepared_model(artifact, prepared_model) - public = _run_public_gate_phase( - artifact, - recurrence_selected_artifact, - recurrence_all_flow_artifact, - target, - batch, - ) - runtime = public.runtime - selected_recurrence_runtime = public.selected_recurrence_runtime - all_flow_recurrence_runtime = public.all_flow_recurrence_runtime - points = public.points - timing_points = public.timing_points - correctness = public.correctness - artifact_contract = public.artifact_contract - load_seconds = public.load_seconds - public_profiles = public.public_profiles - timings = public.timings - - # The default lane creates its private carrier only after the complete - # public correctness/profile/timing phase has passed. The provisional - # public-only lane never reaches this call. - retained = _generate_probe_carrier(probe_carrier, model) - probe_runtime = Runtime.load(probe_carrier, process=PROCESS_ID) - if probe_runtime.execution_mode != "recurrence": - raise GateError("private probe carrier is not a recurrence artifact") - fixed_flow, fixed_helicity = _selectors(probe_runtime.physics) - for label, (flow, helicity) in public.comparator_selectors: - if flow.id != fixed_flow.id or helicity.id != fixed_helicity.id: - raise GateError( - f"probe carrier and {label} authority disagree on public IDs" - ) - selected_authority = correctness.recurrence_selected.total - all_authority = correctness.recurrence_all_flow.total - selected_resolved = correctness.recurrence_selected.resolved - all_resolved = correctness.recurrence_all_flow.resolved - selected_public = correctness.on_the_fly_selected.total - selected_public_resolved = correctness.on_the_fly_selected.resolved - public_correctness = correctness.public_correctness - clear_checks = correctness.clear_checks - - selected_helicity_axis, selected_color_axis = _axes(selected_resolved) - selected_fixed_c = selected_color_axis[FLOW_ID] - all_helicity_axis, all_color_axis = _axes(all_resolved) - all_fixed_h = all_helicity_axis[HELICITY_ID] - - recurrence_selected_census = _recurrence_artifact_census( - recurrence_selected_artifact, - layout="topology-replay", - runtime=selected_recurrence_runtime, - ) - recurrence_all_flow_census = _recurrence_artifact_census( - recurrence_all_flow_artifact, - layout="all-flow-union", - runtime=all_flow_recurrence_runtime, - ) - probe = _probe() - family_probe = _family_probe() - cache: dict[Query, tuple[tuple[float, ...], float, dict[str, Any]]] = {} - - def hidden(flow: object, helicity: object) -> tuple[float, ...]: - query = _query(flow, helicity) - if query not in cache: - before = time.perf_counter() - report = _invoke( - probe, - probe_carrier, - retained, - query, - points, - enable_color_projection=enable_color_projection, - ) - cache[query] = ( - _probe_values(report, len(points)), - time.perf_counter() - before, - report, - ) - return cache[query][0] - - selected_hidden: list[tuple[float, ...]] = [] - selected_reference: list[tuple[complex, ...]] = [] - selected_queries: list[Query] = [] - selected_checks: list[dict[str, object]] = [] - for helicity in probe_runtime.physics.helicities: - if helicity.id not in selected_helicity_axis: - raise GateError("probe carrier helicity is absent from authority") - row = tuple( - complex(point[selected_helicity_axis[helicity.id]][selected_fixed_c]) - for point in selected_resolved.values - ) - if helicity.structural_zero: - selected_checks.append(_series((0.0,) * len(points), row, helicity.id)) - continue - candidate = hidden(fixed_flow, helicity) - selected_hidden.append(candidate) - selected_reference.append(row) - selected_queries.append(_query(fixed_flow, helicity)) - selected_checks.append(_series(candidate, row, helicity.id)) - - flow_hidden: list[tuple[float, ...]] = [] - flow_reference: list[tuple[complex, ...]] = [] - flow_queries: list[Query] = [] - flow_checks: list[dict[str, object]] = [] - for flow in probe_runtime.physics.color_flows: - if flow.id not in all_color_axis: - raise GateError("probe carrier color flow is absent from authority") - row = tuple( - complex(point[all_fixed_h][all_color_axis[flow.id]]) - for point in all_resolved.values - ) - try: - candidate = hidden(flow, fixed_helicity) - except Exception as error: - raise GateError( - "the private topology carrier cannot serve the all-flow " - f"single-helicity query {flow.id}; this is a design finding" - ) from error - flow_hidden.append(candidate) - flow_reference.append(row) - flow_queries.append(_query(flow, fixed_helicity)) - flow_checks.append(_series(candidate, row, flow.id)) - - selected_hidden_sum = _sum(selected_hidden, len(points)) - flow_hidden_sum = _sum(flow_hidden, len(points)) - selected_family_rows, selected_family_correctness = _hidden_family_correctness( - probe, - probe_carrier, - retained, - selected_queries, - points, - selected_reference, - [cache[query][2] for query in selected_queries], - enable_color_projection, - ) - flow_family_rows, flow_family_correctness = _hidden_family_correctness( - probe, - probe_carrier, - retained, - flow_queries, - points, - flow_reference, - [cache[query][2] for query in flow_queries], - enable_color_projection, - ) - selected_family_sum = _sum(selected_family_rows, len(points)) - flow_family_sum = _sum(flow_family_rows, len(points)) - - fixed_hidden = hidden(fixed_flow, fixed_helicity) - public_helicity_axis, public_color_axis = _axes(selected_public_resolved) - fixed_public = tuple( - complex( - point[public_helicity_axis[HELICITY_ID]][public_color_axis[FLOW_ID]] - ) - for point in selected_public_resolved.values - ) - digest = point_digest((points[0],)) - sanity = _anchor_checks( - _anchor(amplicol), - digest, - public_component=fixed_public[0], - hidden_component=fixed_hidden[0], - public_sum=selected_public[0], - hidden_sum=selected_hidden_sum[0], - ) - - selected_hidden_timing = _hidden_timing( - probe, - probe_carrier, - retained, - selected_queries, - timing_points, - target, - enable_color_projection, - ) - flow_hidden_timing = _hidden_timing( - probe, - probe_carrier, - retained, - flow_queries, - timing_points, - target, - enable_color_projection, - ) - selected_structural = _query_family_census( - family_probe, - retained, - selected_queries, - selected_hidden_timing, - enable_color_projection, - ) - flow_structural = _query_family_census( - family_probe, - retained, - flow_queries, - flow_hidden_timing, - enable_color_projection, - ) - _, selected_family_timing = _hidden_family_timing( - probe, - probe_carrier, - retained, - selected_queries, - timing_points, - target, - enable_color_projection, - ) - _, flow_family_timing = _hidden_family_timing( - probe, - probe_carrier, - retained, - flow_queries, - timing_points, - target, - enable_color_projection, - ) - selected_family_census = _mapping( - selected_family_timing.get("work_census"), - "selected on-the-fly family census", - ) - flow_family_census = _mapping( - flow_family_timing.get("work_census"), - "all-flow on-the-fly family census", - ) - _assert_executable_family_matches_structural_census( - selected_family_census, selected_structural - ) - _assert_executable_family_matches_structural_census( - flow_family_census, flow_structural - ) - - for workload, private in ( - ("selected_flow_helicity_sum", selected_family_timing), - ("all_flow_single_helicity", flow_family_timing), - ): - private["diagnostic_ratio_to_recurrence_outer_wall"] = float( - private["private_warmed_seconds_per_point"] - ) / float(timings["recurrence"][workload]["wall_seconds_per_point"]) - private["ratio_is_acceptance_gate"] = False - - def comparison( - workload: str, - family_census: Mapping[str, object], - recurrence_census: Mapping[str, object], - ) -> dict[str, object]: - recurrence_live = _mapping( - recurrence_census.get("selector_live"), - "recurrence selector-live census", - ) - return { - "logical_current_counts": { - "on_the_fly_warmed_family_unique": family_census[ - "union_unique_current_count" - ], - "recurrence_selector_live": recurrence_live["current_count"], - }, - "current_component_counts": { - "on_the_fly_warmed_family_unique": family_census[ - "union_unique_current_component_count" - ], - "recurrence_selector_live": recurrence_live[ - "semantic_current_component_count" - ], - }, - "role_native_operation_counts": { - "on_the_fly_transition_rows": { - role: family_census[f"union_{role}_rows"] - for role in ( - "source", - "contribution", - "finalization", - "closure", - ) - }, - "recurrence_selector_live_rows": { - "source": recurrence_live["source_row_count"], - "contribution": recurrence_live["contribution_count"], - "finalization": recurrence_live["finalization_count"], - "closure": recurrence_live["closure_count"], - }, - }, - "on_the_fly_private_warmed_unique_currents_and_rows": family_census, - "on_the_fly_public_warmed_rows_and_grouped_calls": ( - public_profiles[workload]["work"] - ), - "recurrence_public_warmed_rows_and_grouped_calls": timings[ - "recurrence" - ][workload]["recurrence_runtime_work"], - "recurrence_persisted_and_selector_live_plan": recurrence_census, - "counter_warning": ( - "on-the-fly/recurrence rows are transitions and grouped executor " - "calls. Unlike counters are not equated." - ), - } - - cold = tuple(value[1] for value in cache.values()) - return { - "kind": "pyamplicol-on-the-fly-lc-gate", - "status": "passed", - "correctness_authority_contract": CORRECTNESS_AUTHORITY_CONTRACT, - "process": PROCESS, - "process_id": PROCESS_ID, - "artifact": str(artifact), - "artifact_id": runtime.artifact_id, - "on_the_fly_artifact": artifact_contract, - "private_probe_carrier": { - "execution_mode": "recurrence", - "artifact_id": probe_runtime.artifact_id, - "role": ( - "ephemeral topology carrier for private Rust diagnostics only; " - "not the candidate, not an authority, and excluded from candidate " - "generation/load timing" - ), - "retained_after_gate": False, - }, - "layout": "topology-replay", - "color_projection": { - "query": _query(fixed_flow, fixed_helicity).label, - **{ - name: value - for name, value in cache[_query(fixed_flow, fixed_helicity)][ - 2 - ].items() - if "projection_" in name - }, - }, - "public_correctness": public_correctness, - "public_profiles": public_profiles, - "clear_and_rebuild": clear_checks, - "dense_correctness_authority": _dense_authority( - selected_recurrence_runtime, - all_flow_recurrence_runtime, - len(points), - ), - "prepared_model": { - "path": str(prepared_path), - "load_seconds": prepared_load_seconds, - }, - "cold_boundaries": { - "on_the_fly_generation_seconds": generation_seconds, - "on_the_fly_runtime_load_seconds": load_seconds, - "generation_census": generation_census, - "semantics": ( - "cold service generation and Runtime.load/post-build work are not " - "warmed work; the recurrence probe carrier is excluded" - ), - }, - "explicit_artifact_roots": { - "on_the_fly_candidate": str(artifact), - "recurrence_selected": str(recurrence_selected_artifact), - "recurrence_all_flow": str(recurrence_all_flow_artifact), - }, - "comparator_artifacts": { - "recurrence_selected_flow_helicity_sum": (recurrence_selected_census), - "recurrence_all_flow_single_helicity": recurrence_all_flow_census, - }, - "points": { - "seeds": SEEDS, - "seed_101_digest": digest, - "dense": len(points), - }, - "cold_private_query_outer_seconds": { - "queries": len(cold), - "minimum": min(cold), - "median": statistics.median(cold), - "maximum": max(cold), - "total": math.fsum(cold), - "not_warmed_work": True, - }, - "selected_flow_helicity_sum": { - "private_component_checks": _summaries(selected_checks), - "private_probe_aggregate": _series( - selected_hidden_sum, - selected_authority, - "selected-flow private probe/recurrence authority", - ), - "private_family_correctness": selected_family_correctness, - "private_family_aggregate": _series( - selected_family_sum, - selected_authority, - "selected-flow private family/recurrence authority", - ), - "private_query_local_warm": selected_hidden_timing, - "private_family_warm": selected_family_timing, - "public_timings": { - lane: value["selected_flow_helicity_sum"] - for lane, value in timings.items() - }, - "descriptive_work_comparison": comparison( - "selected_flow_helicity_sum", - selected_family_census, - recurrence_selected_census, - ), - }, - "all_flow_single_helicity": { - "private_component_checks": _summaries(flow_checks), - "private_probe_aggregate": _series( - flow_hidden_sum, - all_authority, - "all-flow private probe/recurrence authority", - ), - "private_family_correctness": flow_family_correctness, - "private_family_aggregate": _series( - flow_family_sum, - all_authority, - "all-flow private family/recurrence authority", - ), - "private_query_local_warm": flow_hidden_timing, - "private_family_warm": flow_family_timing, - "public_timings": { - lane: value["all_flow_single_helicity"] - for lane, value in timings.items() - }, - "descriptive_work_comparison": comparison( - "all_flow_single_helicity", - flow_family_census, - recurrence_all_flow_census, - ), - }, - "amplicol_sanity": sanity, - "clock_contract": { - "on_the_fly_private_warmed": ( - "private Rust family clock excluding source crossing and Python" - ), - "on_the_fly_public": ( - "BenchmarkRunner evaluator/evaluator-total and outer wall clocks" - ), - "recurrence": ("recurrence core/evaluator-total and outer wall clocks"), - "amplicol": ("direct execution and worker wall clocks when supplied"), - "relationship": ( - "all scopes are independent; no equality or interchangeability " - "is assumed" - ), - }, - "integration_contract": { - "python_api": ( - "existing Generator, Runtime.load/evaluate/evaluate_resolved/" - "clear, existing runtime profile backend, and BenchmarkRunner" - ), - "rust_lane": "separate native on-the-fly execution lane", - "new_public_evaluation_api": False, - }, - "performance_is_acceptance_gate": False, - } - - -def _run_public_correctness_only( - output: Path, - prepared_model: Path | None, - candidate_artifact: Path | None, - recurrence_selected_artifact: Path, - recurrence_all_flow_artifact: Path, - target: float, - batch: int, -) -> dict[str, object]: - if (prepared_model is None) == (candidate_artifact is None): - raise GateError( - "public correctness-only mode needs exactly one candidate source" - ) - - generation_seconds: float | None - generation_census: dict[str, int] | None - prepared_record: dict[str, object] - if candidate_artifact is None: - if prepared_model is None: # guarded by the exclusive candidate-source check - raise GateError("public correctness-only generation needs a prepared model") - artifact = output / "artifact" - ( - generation_seconds, - generation_census, - _model, - prepared_path, - prepared_load_seconds, - ) = _generate_candidate_with_prepared_model(artifact, prepared_model) - candidate_source = "generated-in-guarded-worker" - prepared_record = { - "status": "loaded", - "path": str(prepared_path), - "load_seconds": prepared_load_seconds, - } - else: - artifact = _candidate_artifact_path(candidate_artifact) - generation_seconds = None - generation_census = None - candidate_source = "reused-existing-artifact" - prepared_record = { - "status": "not-loaded", - "path": None, - "load_seconds": None, - } - - public = _run_public_gate_phase( - artifact, - recurrence_selected_artifact, - recurrence_all_flow_artifact, - target, - batch, - ) - correctness = public.correctness - public_timings = { - workload: { - lane: public.timings[lane][workload] - for lane in ("on_the_fly", "recurrence") - } - for workload in ( - "selected_flow_helicity_sum", - "all_flow_single_helicity", - ) - } - - def comparator(path: Path, runtime: object, role: str) -> dict[str, object]: - return { - "artifact": str(Path(os.path.abspath(path.expanduser()))), - "artifact_id": runtime.artifact_id, - "execution_mode": runtime.execution_mode, - "role": role, - } - - skipped_reason = ( - "the explicit --public-correctness-only developer lane forbids private " - "carrier generation, hidden probes, private census, and private timing" - ) - return { - "kind": "pyamplicol-on-the-fly-lc-public-correctness-only", - "status": "passed", - "correctness_authority_contract": CORRECTNESS_AUTHORITY_CONTRACT, - "scope": "provisional-public-correctness-only", - "provisional": True, - "public_only": True, - "full_gate_status": "not-run", - "source_bound": False, - "source_binding": "not-asserted", - "process": PROCESS, - "process_id": PROCESS_ID, - "artifact": str(artifact), - "artifact_id": public.runtime.artifact_id, - "candidate_source": candidate_source, - "on_the_fly_artifact": public.artifact_contract, - "layout": "topology-replay", - "public_correctness": correctness.public_correctness, - "clear_and_rebuild": correctness.clear_checks, - "public_profiles": public.public_profiles, - "public_timings": public_timings, - "dense_correctness_authority": _dense_authority( - public.selected_recurrence_runtime, - public.all_flow_recurrence_runtime, - len(public.points), - ), - "prepared_model": prepared_record, - "cold_boundaries": { - "on_the_fly_generation_seconds": generation_seconds, - "on_the_fly_runtime_load_seconds": public.load_seconds, - "generation_census": generation_census, - "generation_reused": candidate_artifact is not None, - }, - "explicit_artifact_roots": { - "on_the_fly_candidate": str(artifact), - "recurrence_selected": str(recurrence_selected_artifact), - "recurrence_all_flow": str(recurrence_all_flow_artifact), - }, - "comparator_artifacts": { - "recurrence_selected_flow_helicity_sum": comparator( - recurrence_selected_artifact, - public.selected_recurrence_runtime, - "selected-flow/helicity-sum recurrence authority", - ), - "recurrence_all_flow_single_helicity": comparator( - recurrence_all_flow_artifact, - public.all_flow_recurrence_runtime, - "all-flow/single-helicity recurrence authority", - ), - }, - "points": { - "seeds": SEEDS, - "seed_101_digest": point_digest((public.points[0],)), - "dense": len(public.points), - }, - "private_probe_carrier": { - "status": "skipped", - "available": False, - "reason": skipped_reason, - "retained_after_gate": False, - }, - "private_census": { - "status": "unavailable", - "query_local": "unavailable", - "query_family": "unavailable", - "reason": skipped_reason, - }, - "private_timing": { - "status": "unavailable", - "query_local": "unavailable", - "query_family": "unavailable", - "reason": skipped_reason, - }, - "clock_contract": { - "on_the_fly_public": ( - "BenchmarkRunner evaluator/evaluator-total and outer wall clocks" - ), - "recurrence": "recurrence core/evaluator-total and outer wall clocks", - "private": "unavailable in provisional public-only mode", - "relationship": ( - "all public clock scopes are independent; no equality or " - "interchangeability is assumed" - ), - }, - "integration_contract": { - "python_api": ( - "existing Runtime.load/evaluate/evaluate_resolved/clear, existing " - "runtime profile backend, and BenchmarkRunner" - ), - "new_public_evaluation_api": False, - "private_native_diagnostics_invoked": False, - }, - "performance_is_acceptance_gate": False, - } - - -def _write(path: Path, value: object) -> None: - if path.exists() or path.is_symlink(): - raise GateError(f"refusing to replace evidence: {path}") - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - try: - temporary.write_text( - json.dumps(value, allow_nan=False, indent=2, sort_keys=True) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - except (OSError, TypeError, ValueError) as error: - temporary.unlink(missing_ok=True) - raise GateError(f"cannot write evidence: {path}") from error - - -def _read(path: Path) -> dict[str, Any]: - try: - result = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise GateError(f"cannot read evidence: {path}") from error - if not isinstance(result, dict): - raise GateError(f"evidence is not an object: {path}") - return result - - -def _watchdog_summary(report: Mapping[str, object]) -> dict[str, object]: - execution = report.get("execution") - enforcement = report.get("enforcement") - if not isinstance(execution, Mapping) or not isinstance(enforcement, Mapping): - raise GateError("watchdog report is incomplete") - return { - "passes": report.get("passes"), - "outcome": execution.get("outcome"), - "reason": execution.get("reason"), - "elapsed_wall_seconds": execution.get("elapsed_wall_seconds"), - "limit_bytes": enforcement.get("limit_bytes"), - "peak_rss_bytes": enforcement.get("peak_rss_bytes"), - "peak_physical_footprint_bytes": enforcement.get( - "peak_physical_footprint_bytes" - ), - "peak_guard_bytes": enforcement.get("peak_guard_bytes"), - "peak_processes": enforcement.get("peak_processes"), - } - - -def _physical_footprint_probe() -> PhysicalFootprintProbe | None: - if platform.system() != "Darwin": - return None - try: - return DarwinPhysicalFootprintProbe() - except Exception as error: - raise GateError("Darwin physical-footprint guard is unavailable") from error - - -def _worker_command(arguments: argparse.Namespace, output: Path) -> list[str]: - _validate_mode_arguments(arguments) - command = [ - sys.executable, - str(Path(__file__).resolve()), - "--worker", - "--output", - str(output), - "--target-runtime", - str(arguments.target_runtime), - "--batch-size", - str(arguments.batch_size), - ] - if arguments.prepared_model is not None: - command.extend( - ("--prepared-model", str(_prepared_model_path(arguments.prepared_model))) - ) - else: - command.extend( - ( - "--candidate-artifact", - str(_candidate_artifact_path(arguments.candidate_artifact)), - ) - ) - if arguments.public_correctness_only: - command.append("--public-correctness-only") - if arguments.amplicol_result is not None: - amplicol = Path(os.path.abspath(arguments.amplicol_result.expanduser())) - command.extend(("--amplicol-result", str(amplicol))) - for option, value in ( - ("--recurrence-selected-artifact", arguments.recurrence_selected_artifact), - ("--recurrence-all-flow-artifact", arguments.recurrence_all_flow_artifact), - ): - command.extend((option, os.path.abspath(value.expanduser()))) - if arguments.bypass_color_projection: - command.append("--bypass-color-projection") - return command - - -def _worker_main(arguments: argparse.Namespace) -> int: - _validate_mode_arguments(arguments) - destination = arguments.output / "worker.json" - try: - if arguments.public_correctness_only: - result = _run_public_correctness_only( - arguments.output, - arguments.prepared_model, - arguments.candidate_artifact, - arguments.recurrence_selected_artifact, - arguments.recurrence_all_flow_artifact, - arguments.target_runtime, - arguments.batch_size, - ) - else: - result = _run( - arguments.output, - arguments.prepared_model, - arguments.amplicol_result, - arguments.recurrence_selected_artifact, - arguments.recurrence_all_flow_artifact, - arguments.target_runtime, - arguments.batch_size, - not arguments.bypass_color_projection, - ) - except Exception as error: - _write( - destination, - { - "kind": ( - "pyamplicol-on-the-fly-lc-public-correctness-only" - if arguments.public_correctness_only - else "pyamplicol-on-the-fly-lc-gate" - ), - "status": "failed", - "correctness_authority_contract": CORRECTNESS_AUTHORITY_CONTRACT, - "scope": ( - "provisional-public-correctness-only" - if arguments.public_correctness_only - else "full" - ), - "error": str(error), - }, - ) - print(f"on-the-fly LC gate failed: {error}", file=sys.stderr) - return 1 - _write(destination, result) - return 0 - - -def _driver_report( - worker: Mapping[str, object], watchdog: Mapping[str, object] -) -> dict[str, object]: - public_only = worker.get("public_only") is True - result: dict[str, object] = { - "kind": ( - "pyamplicol-on-the-fly-lc-public-correctness-only-run" - if public_only - else "pyamplicol-on-the-fly-lc-gate-run" - ), - "status": "passed", - "scope": ("provisional-public-correctness-only" if public_only else "full"), - "provisional": public_only, - "worker": worker, - "watchdog": watchdog, - } - if public_only: - result.update({"source_bound": False, "source_binding": "not-asserted"}) - return result - - -def _driver_main(arguments: argparse.Namespace) -> int: - output = Path(os.path.abspath(arguments.output.expanduser())) - if output.exists() or output.is_symlink(): - raise GateError(f"output already exists: {output}") - output.mkdir(parents=True) - watchdog_path = output / "watchdog.json" - exit_code = run_guarded( - _worker_command(arguments, output), - limit_bytes=WATCHDOG_BYTES, - report_path=watchdog_path, - physical_footprint_probe=_physical_footprint_probe(), - ) - watchdog = _watchdog_summary(_read(watchdog_path)) - worker_path = output / "worker.json" - worker = _read(worker_path) if worker_path.is_file() else None - if exit_code != 0 or watchdog["passes"] is not True: - detail = None if worker is None else worker.get("error") - raise GateError( - f"guarded worker failed: {watchdog['outcome']!r}, {detail!r}; {output}" - ) - if worker is None or worker.get("status") != "passed": - raise GateError("guarded worker omitted its successful result") - public_only = worker.get("public_only") is True - destination = output / "report.json" - _write(destination, _driver_report(worker, watchdog)) - label = "public correctness-only lane" if public_only else "LC gate" - print(f"On-the-fly {label} passed: {destination}") - return 0 - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(argv) - try: - return _worker_main(arguments) if arguments.worker else _driver_main(arguments) - except GateError as error: - print(f"error: {error}", file=sys.stderr) - return 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/otf_contracted_parity_gate.py b/pyamplicol/tools/developer/otf_contracted_parity_gate.py deleted file mode 100644 index 18ed36d48f..0000000000 --- a/pyamplicol/tools/developer/otf_contracted_parity_gate.py +++ /dev/null @@ -1,812 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Run one bounded OTF-contracted numerical parity cell. - -The caller is responsible for placing each invocation under the repository -memory watchdog. A recurrence/NLC/p16-or-p200 invocation creates a local -authority; an OTF/NLC/p16 invocation authenticates that result, while OTF/full/p16 -authenticates either a retained MadGraph wave record or the frozen acceptance -fixture. Every invocation generates exactly one process, evaluates one point -once, and refuses to replace evidence. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.metadata -import json -import math -import os -import subprocess -import tempfile -import time -import tomllib -from collections.abc import Mapping, Sequence -from contextlib import suppress -from decimal import Decimal, InvalidOperation, localcontext -from pathlib import Path -from typing import Any - -KIND = "pyamplicol-otf-contracted-parity-cell-v1" -SEED = 101 -TOLERANCE = Decimal("1e-10") - - -class GateError(RuntimeError): - """The bounded parity cell was malformed or failed.""" - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", required=True, type=Path) - parser.add_argument("--artifact", required=True, type=Path) - parser.add_argument("--prepared-model", required=True, type=Path) - parser.add_argument("--process", required=True) - parser.add_argument("--process-name", required=True) - parser.add_argument("--n-final", required=True, type=int) - parser.add_argument("--family-id", type=int) - parser.add_argument("--point", type=Path) - parser.add_argument("--accuracy", required=True, choices=("nlc", "full")) - parser.add_argument( - "--mode", required=True, choices=("recurrence", "on-the-fly") - ) - parser.add_argument("--precision", required=True, type=int, choices=(16, 200)) - parser.add_argument( - "--query-construction-cores", - type=int, - choices=(1, 4), - default=1, - ) - authority = parser.add_mutually_exclusive_group() - authority.add_argument("--recurrence-authority", type=Path) - authority.add_argument("--madgraph-authority", type=Path) - authority.add_argument("--acceptance-fixture", type=Path) - parser.add_argument("--fixture-case-id") - return parser - - -def _read_json(path: Path) -> Any: - try: - return json.loads( - path.read_text(encoding="ascii"), - parse_float=Decimal, - parse_int=Decimal, - parse_constant=lambda value: (_ for _ in ()).throw( - GateError(f"non-finite JSON token {value!r} in {path}") - ), - ) - except GateError: - raise - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise GateError(f"cannot read JSON document {path}: {error}") from error - - -def _object(value: Any, where: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise GateError(f"{where} must be a JSON object") - return value - - -def _sequence(value: Any, where: str) -> Sequence[Any]: - if isinstance(value, (str, bytes, bytearray)) or not isinstance(value, Sequence): - raise GateError(f"{where} must be a JSON array") - return value - - -def _decimal(value: Any, where: str) -> Decimal: - if isinstance(value, bool): - raise GateError(f"{where} must be a finite number") - try: - result = value if isinstance(value, Decimal) else Decimal(str(value)) - except (InvalidOperation, ValueError) as error: - raise GateError(f"{where} must be a finite number") from error - if not result.is_finite(): - raise GateError(f"{where} must be finite") - return result - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _lower_hex(value: Any, length: int, where: str) -> str: - if ( - not isinstance(value, str) - or len(value) != length - or any(character not in "0123456789abcdef" for character in value) - ): - raise GateError(f"{where} must be {length} lowercase hexadecimal digits") - return value - - -def _candidate_identity(package: Any, distribution_version: str) -> dict[str, Any]: - """Authenticate a contributor build without requiring a clean revision.""" - - package_root = Path(package.__file__).resolve().parent - installed_info_path = package_root / "_build_info.json" - installed = _object(_read_json(installed_info_path), "installed build-info") - version = installed.get("version") - if not isinstance(version, str) or not version or version != distribution_version: - raise GateError("installed build-info version differs from the distribution") - native_digest = _lower_hex( - installed.get("native_build_inputs_sha256"), - 64, - "installed native build-input digest", - ) - source_revision = installed.get("source_revision") - if source_revision is not None: - source_revision = _lower_hex(source_revision, 40, "installed source revision") - source_checkout = installed.get("source_checkout") - if not isinstance(source_checkout, str) or not source_checkout: - raise GateError("installed build-info has no source checkout") - source_root = Path(source_checkout).expanduser().resolve(strict=True) - if source_root != Path(__file__).resolve().parents[2]: - raise GateError("installed candidate belongs to a different source checkout") - source_info_path = ( - source_root / ".artifacts" / "source-runtime" / "_build_info.json" - ) - source = _object(_read_json(source_info_path), "source-runtime build-info") - if ( - source.get("version") != version - or source.get("source_revision") != source_revision - or source.get("native_build_inputs_sha256") != native_digest - ): - raise GateError("installed and source-runtime build-info identities differ") - runtime = _object(source.get("source_runtime"), "source-runtime contract") - extension_sha256 = _lower_hex( - runtime.get("extension_sha256"), 64, "source-runtime extension digest" - ) - if ( - runtime.get("mode") != "candidate" - or runtime.get("native_build_inputs_sha256") != native_digest - ): - raise GateError("source-runtime native identity differs from build-info") - - from pyamplicol import _rusticol as native - - extension_path = Path(native.__file__).resolve(strict=True) - if runtime.get("extension_name") != extension_path.name: - raise GateError( - "source-runtime extension name differs from the installed module" - ) - if _sha256(extension_path) != extension_sha256: - raise GateError("installed native extension digest differs from build-info") - native_version_operation = getattr(native, "package_version", None) - native_digest_operation = getattr(native, "native_build_inputs_sha256", None) - if not callable(native_version_operation) or not callable(native_digest_operation): - raise GateError("native extension has no version/build-input identity") - native_version = native_version_operation() - if ( - not isinstance(native_version, str) - or native_version.replace("-dev.", ".dev") != version - ): - raise GateError("native extension version differs from build-info") - if native_digest_operation() != native_digest: - raise GateError("native extension build-input digest differs from build-info") - - completed = subprocess.run( - ("git", "-C", os.fspath(source_root), "rev-parse", "HEAD"), - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - raise GateError("cannot record current Git HEAD provenance") - git_head = _lower_hex(completed.stdout.strip(), 40, "current Git HEAD") - return { - "kind": "installed-contributor-native-candidate-v1", - "version": version, - "native_build_inputs_sha256": native_digest, - "native_extension_sha256": extension_sha256, - "source_revision": source_revision, - "current_git_head_provenance_only": git_head, - "installed_build_info": { - "path": os.fspath(installed_info_path), - "sha256": _sha256(installed_info_path), - }, - "source_runtime_build_info": { - "path": os.fspath(source_info_path), - "sha256": _sha256(source_info_path), - }, - "native_extension": { - "path": os.fspath(extension_path), - "sha256": extension_sha256, - }, - } - - -def _point_rows(value: Any, where: str) -> tuple[tuple[float, ...], ...]: - rows: list[tuple[float, ...]] = [] - for index, raw_row in enumerate(_sequence(value, where)): - row = _sequence(raw_row, f"{where}[{index}]") - if len(row) != 4: - raise GateError(f"{where}[{index}] must contain four components") - try: - values = tuple(float(component) for component in row) - except (TypeError, ValueError, OverflowError) as error: - raise GateError(f"{where}[{index}] contains a non-number") from error - if any(not math.isfinite(component) for component in values): - raise GateError(f"{where}[{index}] contains a non-finite number") - rows.append(values) - if not rows: - raise GateError(f"{where} must not be empty") - return tuple(rows) - - -def _point_digest(point: tuple[tuple[float, ...], ...]) -> str: - canonical = json.dumps( - [[repr(component) for component in row] for row in point], - ensure_ascii=True, - separators=(",", ":"), - ).encode("ascii") - return hashlib.sha256(canonical).hexdigest() - - -def _same_point( - left: tuple[tuple[float, ...], ...], right: tuple[tuple[float, ...], ...] -) -> bool: - return left == right - - -def _fixture_case( - path: Path, case_id: str, process: str -) -> tuple[tuple[tuple[float, ...], ...], Decimal, dict[str, Any]]: - fixture = _object(_read_json(path), "acceptance fixture") - if ( - fixture.get("kind") != "pyamplicol-ufo-sm-numerical-acceptance" - or fixture.get("schema_version") != Decimal(1) - ): - raise GateError("acceptance fixture identity is unsupported") - comparison = _object(fixture.get("comparison"), "fixture comparison") - if ( - comparison.get("relative_tolerance") != "0.0000000001" - or comparison.get("absolute_tolerance") is not None - or comparison.get("full_candidate_precision_digits") != Decimal(200) - ): - raise GateError("acceptance fixture does not carry the strict p200 contract") - cases = _sequence( - fixture.get("extra_full_colour_cases"), "fixture extra_full_colour_cases" - ) - matches = [ - _object(raw, "fixture extra case") - for raw in cases - if isinstance(raw, Mapping) and raw.get("id") == case_id - ] - if len(matches) != 1 or matches[0].get("process") != process: - raise GateError(f"fixture case {case_id!r} does not match {process!r}") - case = matches[0] - expected = _decimal( - _object(case.get("expected"), "fixture expected").get("full"), - "fixture full target", - ) - point = _point_rows(case.get("momenta"), "fixture momenta") - return point, expected, { - "kind": "frozen-madgraph-acceptance-fixture", - "path": os.fspath(path), - "sha256": _sha256(path), - "case_id": case_id, - } - - -def _point_from_path(path: Path) -> tuple[tuple[float, ...], ...]: - return _point_rows(_read_json(path), f"point {path}") - - -def _madgraph_target( - path: Path, - *, - process: str, - n_final: int, - point: tuple[tuple[float, ...], ...], -) -> tuple[Decimal, dict[str, Any]]: - authority = _object(_read_json(path), "MadGraph authority") - if ( - authority.get("process") != process - or authority.get("n_final") != Decimal(n_final) - or authority.get("seed") != Decimal(SEED) - ): - raise GateError("retained MadGraph authority identity differs from this cell") - declared_point = authority.get("point_path") - if not isinstance(declared_point, str): - raise GateError("retained MadGraph authority has no point_path") - authority_point_path = Path(declared_point).expanduser().resolve(strict=True) - authority_point = _point_from_path(authority_point_path) - if not _same_point(point, authority_point): - raise GateError("worker point differs from the retained MadGraph point") - expected = _decimal(authority.get("madgraph_value"), "MadGraph value") - measurement_path = path.parent / "madgraph-measurement.json" - measurement = _object(_read_json(measurement_path), "MadGraph measurement") - validation = _object(measurement.get("validation"), "MadGraph validation") - if ( - measurement.get("status") != "ok" - or validation.get("status") != "ok" - or validation.get("method") - != "independent-madgraph-tree-level-oracle" - or _decimal(measurement.get("matrix_element"), "MadGraph measurement value") - != expected - ): - raise GateError("retained MadGraph measurement is not a successful authority") - return expected, { - "kind": "retained-authenticated-madgraph-wave", - "path": os.fspath(path), - "sha256": _sha256(path), - "measurement_path": os.fspath(measurement_path), - "measurement_sha256": _sha256(measurement_path), - "point_path": os.fspath(authority_point_path), - "point_sha256": _sha256(authority_point_path), - } - - -def _recurrence_target( - path: Path, - *, - process: str, - point_digest: str, - producer_version: str, -) -> tuple[Decimal, dict[str, Any]]: - record = _object(_read_json(path), "recurrence authority") - lane = _object(record.get("lane"), "recurrence authority lane") - actual = _object(record.get("actual"), "recurrence authority actual") - producer = _object(record.get("producer"), "recurrence authority producer") - authority_precision = lane.get("precision") - if ( - record.get("kind") != KIND - or record.get("status") != "anchor" - or record.get("process") != process - or record.get("point_digest") != point_digest - or lane.get("accuracy") != "nlc" - or lane.get("mode") != "recurrence" - or authority_precision not in {Decimal(16), Decimal(200)} - or producer.get("version") != producer_version - ): - raise GateError("recurrence authority does not match this OTF/NLC cell") - imaginary = _decimal(actual.get("imaginary"), "recurrence imaginary part") - if imaginary != 0: - raise GateError("recurrence authority is not exactly real") - return _decimal(actual.get("real"), "recurrence real part"), { - "kind": f"same-candidate-recurrence-p{authority_precision}", - "precision": int(authority_precision), - "path": os.fspath(path), - "sha256": _sha256(path), - } - - -def _actual(value: Any) -> tuple[Decimal, Decimal, str]: - if isinstance(value, Decimal): - if not value.is_finite(): - raise GateError("matrix element is non-finite") - return value, Decimal(0), str(value) - try: - number = complex(value) - except (TypeError, ValueError, OverflowError) as error: - raise GateError("matrix element is not numeric") from error - if not math.isfinite(number.real) or not math.isfinite(number.imag): - raise GateError("matrix element is non-finite") - return Decimal(repr(number.real)), Decimal(repr(number.imag)), repr(value) - - -def _comparison(real: Decimal, imaginary: Decimal, expected: Decimal) -> dict[str, Any]: - with localcontext() as context: - context.prec = 512 - magnitude = (real * real + imaginary * imaginary).sqrt() - difference = ((real - expected) ** 2 + imaginary**2).sqrt() - scale = max(magnitude, abs(expected)) - bound = TOLERANCE * scale - passed = difference == 0 if scale == 0 else difference <= bound - residual = Decimal(0) if scale == 0 else difference / scale - return { - "expected": str(expected), - "absolute_difference": str(difference), - "scale": str(scale), - "conditioned_residual": str(residual), - "relative_tolerance": str(TOLERANCE), - "bound": str(bound), - "passed": passed, - } - - -def _run_config(accuracy: str, mode: str, cores: int) -> Any: - from pyamplicol.config import ( - Action, - ColorAccuracy, - ColorConfig, - EvaluatorConfig, - EvaluatorExecutionMode, - EvaluatorOptimizationConfig, - GenerationConfig, - GenerationRelationDiscoveryConfig, - GenerationValidationConfig, - JITConfig, - LCFlowLayout, - RelationDiscoveryMode, - RunConfig, - ) - - return RunConfig( - action=Action.GENERATE, - color=ColorConfig( - accuracy=ColorAccuracy(accuracy), - lc_flow_layout=LCFlowLayout.TOPOLOGY_REPLAY, - ), - generation=GenerationConfig( - workers=1, - emit_api_bundle=False, - validation=GenerationValidationConfig( - enabled=False, - post_build_validation=False, - ), - relation_discovery=GenerationRelationDiscoveryConfig( - mode=RelationDiscoveryMode.OFF - ), - ), - evaluator=EvaluatorConfig( - execution_mode=EvaluatorExecutionMode(mode), - optimization=EvaluatorOptimizationConfig(cores=cores), - jit=JITConfig(optimization_level=2), - ), - ) - - -def _atomic_json(path: Path, payload: Mapping[str, Any]) -> None: - if path.exists() or path.is_symlink(): - raise GateError(f"refusing to replace evidence: {path}") - path.parent.mkdir(parents=True, exist_ok=True) - descriptor, temporary = tempfile.mkstemp( - prefix=f".{path.name}.", suffix=".tmp", dir=path.parent - ) - try: - with os.fdopen(descriptor, "w", encoding="ascii") as stream: - json.dump(payload, stream, ensure_ascii=True, separators=(",", ":")) - stream.write("\n") - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - finally: - with suppress(FileNotFoundError): - os.unlink(temporary) - - -def _validate_arguments(args: argparse.Namespace) -> None: - expected_lane = { - ("nlc", "recurrence", 16): "anchor", - ("nlc", "recurrence", 200): "anchor", - ("nlc", "on-the-fly", 16): "recurrence", - ("full", "on-the-fly", 16): "full", - }.get((args.accuracy, args.mode, args.precision)) - if expected_lane is None: - raise GateError( - "unsupported gate lane; only NLC recurrence-p16/p200 and OTF-p16" - ) - has_recurrence = args.recurrence_authority is not None - has_full = ( - args.madgraph_authority is not None - or args.acceptance_fixture is not None - ) - if expected_lane == "anchor" and (has_recurrence or has_full): - raise GateError("recurrence-p200 anchor must not declare an authority") - if expected_lane == "recurrence" and not has_recurrence: - raise GateError("OTF/NLC requires --recurrence-authority") - if expected_lane == "full" and not has_full: - raise GateError("OTF/full requires a MadGraph authority") - if (args.acceptance_fixture is None) != (args.fixture_case_id is None): - raise GateError("--acceptance-fixture and --fixture-case-id are paired") - if args.acceptance_fixture is None and args.point is None: - raise GateError("non-fixture cells require --point") - if args.n_final < 1 or args.n_final > 6: - raise GateError("n_final must be in 1..6") - if args.mode == "recurrence" and args.query_construction_cores != 1: - raise GateError("recurrence authorities use exactly one core") - - -def _authenticate_artifact( - artifact: Path, - *, - process_name: str, - mode: str, - query_construction_cores: int, - candidate_identity: Mapping[str, Any], -) -> dict[str, Any]: - """Authenticate cheap persisted boundaries before any runtime evaluation.""" - - manifest_path = artifact / "artifact.json" - manifest = _object(_read_json(manifest_path), "artifact manifest") - manifest_producer = _object(manifest.get("producer"), "artifact producer") - artifact_producer_version = manifest_producer.get("version") - artifact_source_revision = manifest_producer.get("git_revision") - artifact_native_digest = manifest_producer.get( - "native_build_inputs_sha256" - ) - if ( - manifest_producer.get("distribution") != "pyamplicol" - or artifact_producer_version != candidate_identity["version"] - or artifact_source_revision != candidate_identity["source_revision"] - or artifact_native_digest - != candidate_identity["native_build_inputs_sha256"] - ): - raise GateError("artifact producer differs from installed candidate") - effective_path = artifact / "config" / "effective.toml" - try: - effective = tomllib.loads(effective_path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, tomllib.TOMLDecodeError) as error: - raise GateError(f"cannot read effective configuration: {error}") from error - effective_cores = ( - effective.get("evaluator", {}).get("optimization", {}).get("cores") - ) - if effective_cores != query_construction_cores: - raise GateError( - "effective configuration does not authenticate the requested core budget" - ) - query_construction_threads = None - if mode == "on-the-fly": - execution_path = artifact / "processes" / process_name / "execution.json" - execution = _object(_read_json(execution_path), "OTF execution manifest") - runtime_options = _object( - execution.get("runtime_options"), "OTF runtime options" - ) - query_construction_threads = runtime_options.get( - "query_construction_threads" - ) - if query_construction_threads != Decimal(query_construction_cores): - raise GateError( - "OTF execution manifest does not authenticate the requested " - "query-construction thread budget" - ) - return { - "producer": { - "version": artifact_producer_version, - "source_revision_provenance": artifact_source_revision, - "native_build_inputs_sha256": artifact_native_digest, - "artifact_id": manifest.get("artifact_id"), - "artifact_manifest_sha256": _sha256(manifest_path), - }, - "effective_config": { - "path": os.fspath(effective_path), - "sha256": _sha256(effective_path), - "evaluator_optimization_cores": effective_cores, - }, - "runtime_options": { - "query_construction_threads": ( - None - if query_construction_threads is None - else int(query_construction_threads) - ), - }, - } - - -def main(argv: Sequence[str] | None = None) -> int: - args = _parser().parse_args(argv) - _validate_arguments(args) - output = args.output.expanduser().resolve(strict=False) - preflight_path = output.with_name(f"{output.stem}.preflight.json") - artifact = args.artifact.expanduser().resolve(strict=False) - prepared = args.prepared_model.expanduser().resolve(strict=True) - if not prepared.is_file(): - raise GateError(f"prepared model is not a regular file: {prepared}") - if output.exists() or output.is_symlink(): - raise GateError(f"result already exists: {output}") - if preflight_path.exists() or preflight_path.is_symlink(): - raise GateError(f"preflight evidence already exists: {preflight_path}") - if artifact.exists() or artifact.is_symlink(): - raise GateError(f"artifact already exists: {artifact}") - - fixture_target: Decimal | None = None - fixture_lineage: dict[str, Any] | None = None - if args.acceptance_fixture is not None: - fixture_path = args.acceptance_fixture.expanduser().resolve(strict=True) - point, fixture_target, fixture_lineage = _fixture_case( - fixture_path, args.fixture_case_id, args.process - ) - else: - point_path = args.point.expanduser().resolve(strict=True) - point = _point_from_path(point_path) - digest = _point_digest(point) - - import pyamplicol - from pyamplicol import Generator, ModelSource, ProcessSet, Runtime - - producer_version = importlib.metadata.version("pyamplicol") - candidate_identity = _candidate_identity(pyamplicol, producer_version) - expected: Decimal | None = None - authority: dict[str, Any] | None = None - if args.recurrence_authority is not None: - authority_path = args.recurrence_authority.expanduser().resolve(strict=True) - expected, authority = _recurrence_target( - authority_path, - process=args.process, - point_digest=digest, - producer_version=producer_version, - ) - elif args.madgraph_authority is not None: - authority_path = args.madgraph_authority.expanduser().resolve(strict=True) - expected, authority = _madgraph_target( - authority_path, - process=args.process, - n_final=args.n_final, - point=point, - ) - elif fixture_target is not None: - expected, authority = fixture_target, fixture_lineage - - model_started = time.perf_counter() - model = ModelSource.from_path(prepared).compile() - model_seconds = time.perf_counter() - model_started - artifact.parent.mkdir(parents=True, exist_ok=True) - generation_started = time.perf_counter() - Generator( - _run_config( - args.accuracy, - args.mode, - args.query_construction_cores, - ) - ).generate( - ProcessSet.from_expressions( - (args.process,), - names=(args.process_name,), - ), - artifact, - model=model, - ) - generation_seconds = time.perf_counter() - generation_started - preflight_common = { - "kind": "pyamplicol-otf-contracted-parity-preflight-v1", - "schema_version": 1, - "artifact": os.fspath(artifact), - "candidate_identity": candidate_identity, - "process": args.process, - "point_digest": digest, - "authority": authority, - "requested_lane": { - "accuracy": args.accuracy, - "mode": args.mode, - "precision": args.precision, - "workers": 1, - "cores": args.query_construction_cores, - }, - "generation_seconds": generation_seconds, - "evaluation_state": "not-started", - } - try: - artifact_identity = _authenticate_artifact( - artifact, - process_name=args.process_name, - mode=args.mode, - query_construction_cores=args.query_construction_cores, - candidate_identity=candidate_identity, - ) - except Exception as error: - _atomic_json( - preflight_path, - { - **preflight_common, - "status": "failed", - "error": { - "type": type(error).__name__, - "message": str(error), - }, - }, - ) - raise - _atomic_json( - preflight_path, - { - **preflight_common, - "status": "passed", - "artifact_identity": artifact_identity, - }, - ) - producer = artifact_identity["producer"] - effective_config = artifact_identity["effective_config"] - query_construction_threads = artifact_identity["runtime_options"][ - "query_construction_threads" - ] - - load_started = time.perf_counter() - runtime = Runtime.load(artifact, process=args.process_name) - load_seconds = time.perf_counter() - load_started - try: - inspection = _object(runtime.inspect(), "compact runtime inspection") - runtime_metadata = _object( - inspection.get("runtime_metadata"), - "compact runtime metadata", - ) - observed_mode = runtime_metadata.get("execution_mode") - observed_accuracy = runtime_metadata.get("color_accuracy") - if ( - runtime.execution_mode != args.mode - or observed_mode != args.mode - or observed_accuracy != args.accuracy - ): - raise GateError( - "runtime lane differs from requested " - f"{args.mode}/{args.accuracy}: " - f"{runtime.execution_mode}/{observed_mode}/{observed_accuracy}" - ) - evaluation_started = time.perf_counter() - values = runtime.evaluate((point,), precision=args.precision) - evaluation_seconds = time.perf_counter() - evaluation_started - finally: - runtime.clear() - if len(values) != 1: - raise GateError(f"single-point evaluation returned {len(values)} values") - real, imaginary, exact = _actual(values[0]) - if real < 0: - raise GateError("matrix element is negative") - - comparison = None if expected is None else _comparison(real, imaginary, expected) - status = ( - "anchor" - if comparison is None - else ("passed" if comparison["passed"] is True else "mismatch") - ) - record: dict[str, Any] = { - "kind": KIND, - "schema_version": 1, - "status": status, - "seed": SEED, - "process": args.process, - "process_name": args.process_name, - "n_final": args.n_final, - "family_id": args.family_id, - "point_digest": digest, - "point_count": 1, - "selector_policy": "none-contracted-singleton", - "warmup_count": 0, - "repetition_count": 0, - "lane": { - "accuracy": args.accuracy, - "mode": args.mode, - "precision": args.precision, - "workers": 1, - "cores": args.query_construction_cores, - "query_construction_threads": ( - None - if query_construction_threads is None - else int(query_construction_threads) - ), - "relation_discovery": "off", - }, - "actual": { - "real": str(real), - "imaginary": str(imaginary), - "exact_runtime_string": exact, - }, - "authority": authority, - "comparison": comparison, - "timings_seconds": { - "prepared_model_load": model_seconds, - "generation": generation_seconds, - "runtime_load": load_seconds, - "single_evaluation": evaluation_seconds, - }, - "prepared_model": { - "path": os.fspath(prepared), - "sha256": _sha256(prepared), - }, - "artifact": os.fspath(artifact), - "preflight": { - "path": os.fspath(preflight_path), - "sha256": _sha256(preflight_path), - }, - "effective_config": effective_config, - "candidate_identity": candidate_identity, - "producer": producer, - "python_package": os.fspath(Path(pyamplicol.__file__).resolve()), - } - _atomic_json(output, record) - if comparison is not None and comparison["passed"] is not True: - raise GateError( - f"strict parity failed for {args.process}/{args.accuracy}: " - f"residual={comparison['conditioned_residual']}" - ) - print(json.dumps(record, ensure_ascii=True, indent=2)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/otf_wave1_runtime_benchmark.py b/pyamplicol/tools/developer/otf_wave1_runtime_benchmark.py deleted file mode 100644 index ad8303d3cc..0000000000 --- a/pyamplicol/tools/developer/otf_wave1_runtime_benchmark.py +++ /dev/null @@ -1,222 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Measure the two fixed warmed OTF LC Wave-1 workloads with the native timer.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import math -import platform -import statistics -import sys -from datetime import UTC, datetime -from pathlib import Path -from typing import Any - -ARTIFACT_ID = "81de5672cafb4cedd4a8cb4064e4b5e6caefb25f031e6b5fbb22990f82a073fc" -PROCESS_ID = "catalog_dd_tt_jets_n4" -PROCESS = "d d~ > t t~ g g" -CASE_ID = "catalog:dd_tt_jets:n4" -FLOW_ID = "flow:2,5,6,4,3,1" -HELICITY_ID = "h:-1,+1,-1,+1,-1,+1" -POINT_SHA256 = "111d277e8eb86e8d183adba74c0c83a3e4d20a6317a10bdb7c63893f5e5017c0" -BATCH_SHA256 = "a875706b2f87d9105b483b2d5d33285005902ed29485a8934601598852016c71" -BATCH_SIZE = 128 -REPETITIONS = 4 -WARMUPS = 3 -SAMPLES = 11 - - -def _canonical_sha256(value: object) -> str: - payload = json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return hashlib.sha256(payload).hexdigest() - - -def _file_sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _point(fixture: Path) -> tuple[tuple[float, ...], ...]: - payload = json.loads(fixture.read_text(encoding="utf-8")) - case = next( - ( - item - for item in payload.get("catalog_cases", ()) - if item.get("id") == CASE_ID - ), - None, - ) - if not isinstance(case, dict) or case.get("process") != PROCESS: - raise RuntimeError(f"fixture omits the fixed case {CASE_ID!r}") - point = tuple(tuple(float(value) for value in row) for row in case["momenta"]) - if _canonical_sha256((point,)) != POINT_SHA256: - raise RuntimeError("fixed acceptance point identity changed") - return point - - -def _installed_identity(package_root: Path, version: str) -> dict[str, object]: - build_info_path = package_root / "_build_info.json" - build_info = json.loads(build_info_path.read_text(encoding="utf-8")) - extensions = tuple(package_root.glob("_rusticol*.so")) - if len(extensions) != 1: - raise RuntimeError("installed native extension is absent or ambiguous") - return { - "package_root": str(package_root), - "package_version": version, - "source_revision": build_info.get("source_revision"), - "native_build_inputs_sha256": build_info.get("native_build_inputs_sha256"), - "native_extension_sha256": _file_sha256(extensions[0]), - } - - -def _value_record(value: object) -> dict[str, object]: - resolved = complex(value) # type: ignore[arg-type] - if not math.isfinite(resolved.real) or not math.isfinite(resolved.imag): - raise RuntimeError("selector smoke evaluation is not finite") - return { - "real": resolved.real, - "imag": resolved.imag, - "real_hex": resolved.real.hex(), - "imag_hex": resolved.imag.hex(), - } - - -def _summary(samples: list[float]) -> dict[str, object]: - median = statistics.median(samples) - return { - "seconds_per_point": samples, - "median_seconds_per_point": median, - "mad_seconds_per_point": statistics.median( - abs(value - median) for value in samples - ), - "minimum_seconds_per_point": min(samples), - "maximum_seconds_per_point": max(samples), - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--artifact", required=True, type=Path) - parser.add_argument("--fixture", required=True, type=Path) - parser.add_argument("--label", required=True) - parser.add_argument("--output", required=True, type=Path) - return parser - - -def main() -> int: - arguments = _parser().parse_args() - artifact = arguments.artifact.resolve(strict=True) - fixture = arguments.fixture.resolve(strict=True) - destination = arguments.output.resolve() - if destination.exists() or destination.is_symlink(): - raise RuntimeError(f"refusing to replace benchmark evidence: {destination}") - - import pyamplicol - from pyamplicol import Runtime - - point = _point(fixture) - batch = tuple(point for _ in range(BATCH_SIZE)) - if _canonical_sha256(batch) != BATCH_SHA256: - raise RuntimeError("fixed benchmark batch identity changed") - - runtime = Runtime.load(artifact, process=PROCESS_ID) - if runtime.artifact_id != ARTIFACT_ID: - raise RuntimeError("benchmark artifact identity changed") - if runtime.execution_mode != "on-the-fly": - raise RuntimeError( - f"expected on-the-fly runtime, got {runtime.execution_mode!r}" - ) - backend = getattr(runtime, "_backend", None) - timer = getattr(backend, "_benchmark_f64_wall_time", None) - if not callable(timer): - raise RuntimeError("native f64 wall timer is unavailable") - - workloads: tuple[tuple[str, dict[str, tuple[str, ...]]], ...] = ( - ("selected_flow_helicity_sum", {"color_flows": (FLOW_ID,)}), - ("all_flow_single_helicity", {"helicities": (HELICITY_ID,)}), - ) - smoke_values = { - name: _value_record(runtime.evaluate((point,), precision=16, **selectors)[0]) - for name, selectors in workloads - } - for warmup in range(WARMUPS): - ordered = workloads if warmup % 2 == 0 else tuple(reversed(workloads)) - for _, selectors in ordered: - elapsed = float(timer(batch, 1, precision=16, **selectors)) - if not math.isfinite(elapsed) or elapsed <= 0.0: - raise RuntimeError("native wall warmup returned an invalid duration") - - raw: dict[str, list[float]] = {name: [] for name, _ in workloads} - divisor = REPETITIONS * BATCH_SIZE - for sample in range(SAMPLES): - ordered = workloads if sample % 2 == 0 else tuple(reversed(workloads)) - for name, selectors in ordered: - # Only the last selector family is retained. Prime the exact route - # after every order switch so the measured block is wholly warm. - prime_elapsed = float(timer(batch, 1, precision=16, **selectors)) - if not math.isfinite(prime_elapsed) or prime_elapsed <= 0.0: - raise RuntimeError("native selector prime returned an invalid duration") - elapsed = float(timer(batch, REPETITIONS, precision=16, **selectors)) - if not math.isfinite(elapsed) or elapsed <= 0.0: - raise RuntimeError("native wall sample returned an invalid duration") - raw[name].append(elapsed / divisor) - - package_root = Path(pyamplicol.__file__).resolve().parent - result: dict[str, Any] = { - "kind": "pyamplicol-otf-wave1-native-wall-benchmark", - "schema_version": 1, - "label": arguments.label, - "created_at_utc": datetime.now(UTC).isoformat(), - "driver_sha256": _file_sha256(Path(__file__).resolve()), - "installation": _installed_identity(package_root, pyamplicol.__version__), - "environment": { - "python": sys.version, - "platform": platform.platform(), - "machine": platform.machine(), - }, - "contract": { - "timer": "Runtime._benchmark_f64_wall_time", - "artifact": str(artifact), - "artifact_id": ARTIFACT_ID, - "process_id": PROCESS_ID, - "process": PROCESS, - "point_case_id": CASE_ID, - "point_sha256": POINT_SHA256, - "batch_sha256": BATCH_SHA256, - "batch_size": BATCH_SIZE, - "repetitions": REPETITIONS, - "warmups": WARMUPS, - "samples": SAMPLES, - "precision": 16, - "per_sample_selector_prime_repetitions": 1, - "selector_prime_timing": "excluded", - "sample_order": "ABBA", - "selectors": { - "selected_flow_helicity_sum": {"color_flows": [FLOW_ID]}, - "all_flow_single_helicity": {"helicities": [HELICITY_ID]}, - }, - }, - "smoke_values": smoke_values, - "workloads": {name: _summary(raw[name]) for name, _ in workloads}, - } - destination.parent.mkdir(parents=True, exist_ok=True) - with destination.open("x", encoding="utf-8") as stream: - json.dump(result, stream, allow_nan=False, indent=2, sort_keys=True) - stream.write("\n") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/prepare_builtin_without_auxiliary_qcd.py b/pyamplicol/tools/developer/prepare_builtin_without_auxiliary_qcd.py deleted file mode 100644 index f3bb7249db..0000000000 --- a/pyamplicol/tools/developer/prepare_builtin_without_auxiliary_qcd.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Prepare a diagnostic built-in model without auxiliary four-gluon kernels. - -This intentionally incomplete model is useful only for locating recurrence -parity failures. It removes the trivalent auxiliary-tensor decomposition of the -four-gluon interaction while retaining the rest of the built-in model. -""" - -from __future__ import annotations - -import argparse -from pathlib import Path - -from recurrence_z6g_benchmark import _generation_config - -from pyamplicol import ModelSource -from pyamplicol.models.builtin.definitions import BuiltinSMDefinitionMixin - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("output", type=Path) - arguments = parser.parse_args() - output = arguments.output.expanduser().resolve() - - original = BuiltinSMDefinitionMixin._build_vertices - - def without_auxiliary_vertices( - model: BuiltinSMDefinitionMixin, - ) -> list[object]: - return [ - vertex - for vertex in original(model) - if int(vertex.kind) not in {1, 2, 3} - ] - - BuiltinSMDefinitionMixin._build_vertices = without_auxiliary_vertices - try: - ModelSource.built_in_sm().compile( - use_cache=False, - prepared_output=output, - evaluator=_generation_config( - "recurrence", - validation_samples=1, - ).evaluator, - ) - finally: - BuiltinSMDefinitionMixin._build_vertices = original - print(output) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/prepare_class_c_bridge.py b/pyamplicol/tools/developer/prepare_class_c_bridge.py deleted file mode 100644 index f6224b6209..0000000000 --- a/pyamplicol/tools/developer/prepare_class_c_bridge.py +++ /dev/null @@ -1,559 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Prepare a Class-C bridge with descendant tools and the staged ancestor runtime. - -The live checkout must already be at the reviewed descendant while its source -runtime and report environment still authenticate the measured ancestor. This -helper materializes a temporary, tracked ancestor worktree, binds only the -ignored files that make up the retained source runtime, and invokes the -descendant report controller against that authenticated package. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.util -import inspect -import json -import os -import re -import shutil -import subprocess -import sys -import tempfile -from collections.abc import Mapping, Sequence -from pathlib import Path - -ROOT = Path(__file__).resolve().parents[2] -_PROFILE_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,63}") -_NATIVE_EXTENSION_SUFFIXES = (".dylib", ".pyd", ".so") -_LEGACY_NATIVE_BUILD_INPUT_FILES = ( - Path("Cargo.lock"), - Path("Cargo.toml"), - Path("pyproject.toml"), - Path("rust-toolchain.toml"), - Path("dependencies/candidate-Cargo.lock"), - Path("dependencies/candidate-cargo-config.toml"), - Path("dependencies/contributor-lock.toml"), - Path("dependencies/install-state.json"), - Path("dependencies/release-lock.toml"), -) -_LEGACY_NATIVE_BUILD_INPUT_TREES = ( - Path("build_backend"), - Path("dependencies/patches"), - Path("rust"), -) -_LEGACY_NATIVE_BUILD_INPUT_SUFFIXES = { - ".f90", - ".h", - ".hpp", - ".json", - ".patch", - ".py", - ".pyi", - ".rs", - ".toml", -} -_IGNORED_NATIVE_INPUTS = ( - Path("dependencies/candidate-Cargo.lock"), - Path("dependencies/candidate-cargo-config.toml"), - Path("dependencies/install-state.json"), -) -_STAGED_SDK_DIRECTORIES = ( - Path("_sdk/fortran"), - Path("_sdk/include"), - Path("_sdk/lib"), -) -_STAGED_SDK_FILES = ( - Path("_sdk/link.json"), - Path("_sdk/metadata.json"), -) - - -class ClassCPrepareBootstrapError(RuntimeError): - """The ancestor source runtime could not be materialized exactly.""" - - -def _run_git(root: Path, *arguments: str) -> subprocess.CompletedProcess[str]: - return subprocess.run( - ("git", "-C", str(root), *arguments), - check=False, - capture_output=True, - text=True, - ) - - -def _git_commit(root: Path, revision: str) -> str: - completed = _run_git(root, "rev-parse", "--verify", f"{revision}^{{commit}}") - value = completed.stdout.strip() - if ( - completed.returncode != 0 - or len(value) != 40 - or any(character not in "0123456789abcdef" for character in value) - ): - raise ClassCPrepareBootstrapError( - f"cannot resolve Git revision {revision!r}" - ) - return value - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _native_build_inputs_digest( - root: Path, - *, - normalize_release_cargo_lock: bool = False, -) -> str: - identity_path = root / "build_backend/native_build_identity.py" - if identity_path.is_file(): - identity_name = hashlib.sha256( - str(root.resolve()).encode("utf-8") - ).hexdigest()[:12] - spec = importlib.util.spec_from_file_location( - f"_pyamplicol_ancestor_native_identity_{identity_name}", - identity_path, - ) - if spec is None or spec.loader is None: - raise ClassCPrepareBootstrapError( - "ancestor native-build identity module is unavailable" - ) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - digest = getattr(module, "native_build_inputs_digest", None) - if not callable(digest): - raise ClassCPrepareBootstrapError( - "ancestor native-build identity module has no digest callable" - ) - try: - parameters = inspect.signature(digest).parameters.values() - except (TypeError, ValueError) as error: - raise ClassCPrepareBootstrapError( - "ancestor native-build identity callable cannot be inspected" - ) from error - supports_release_projection = any( - parameter.name == "normalize_release_cargo_lock" - or parameter.kind is inspect.Parameter.VAR_KEYWORD - for parameter in parameters - ) - if normalize_release_cargo_lock and not supports_release_projection: - raise ClassCPrepareBootstrapError( - "ancestor native-build identity cannot verify a release-mode " - "source runtime" - ) - if supports_release_projection: - return str( - digest( - root, - normalize_release_cargo_lock=normalize_release_cargo_lock, - ) - ) - return str(digest(root)) - - if normalize_release_cargo_lock: - raise ClassCPrepareBootstrapError( - "legacy ancestor native-build identity cannot verify a release-mode " - "source runtime" - ) - paths = [ - root / relative for relative in _LEGACY_NATIVE_BUILD_INPUT_FILES - ] - for relative in _LEGACY_NATIVE_BUILD_INPUT_TREES: - tree = root / relative - if not tree.is_dir(): - continue - paths.extend( - path - for path in tree.rglob("*") - if path.is_file() - and not {"__pycache__", "target"}.intersection( - path.relative_to(tree).parts - ) - and path.suffix in _LEGACY_NATIVE_BUILD_INPUT_SUFFIXES - ) - digest = hashlib.sha256() - for path in sorted(set(paths)): - if not path.is_file(): - continue - relative = path.relative_to(root).as_posix().encode("utf-8") - data = path.read_bytes() - digest.update(len(relative).to_bytes(8, "little")) - digest.update(relative) - digest.update(len(data).to_bytes(8, "little")) - digest.update(data) - return digest.hexdigest() - - -def _regular_file(path: Path, description: str) -> Path: - try: - resolved = path.resolve(strict=True) - except OSError as error: - raise ClassCPrepareBootstrapError(f"{description} is unavailable") from error - if path.is_symlink() or not resolved.is_file(): - raise ClassCPrepareBootstrapError( - f"{description} must be one regular file" - ) - return resolved - - -def _hardlink(source: Path, destination: Path, description: str) -> None: - source = _regular_file(source, description) - destination.parent.mkdir(parents=True, exist_ok=True) - if destination.exists() or destination.is_symlink(): - raise ClassCPrepareBootstrapError( - f"ancestor runtime destination already exists: {destination}" - ) - os.link(source, destination) - if destination.is_symlink() or not destination.is_file(): - raise ClassCPrepareBootstrapError( - f"ancestor runtime member is not regular: {destination}" - ) - - -def _hardlink_tree(source: Path, destination: Path, description: str) -> None: - try: - root = source.resolve(strict=True) - except OSError as error: - raise ClassCPrepareBootstrapError(f"{description} is unavailable") from error - if source.is_symlink() or not root.is_dir(): - raise ClassCPrepareBootstrapError( - f"{description} must be one regular directory tree" - ) - for member in sorted(root.rglob("*")): - relative = member.relative_to(root) - if member.is_symlink(): - raise ClassCPrepareBootstrapError( - f"{description} contains a symlink: {relative}" - ) - if member.is_dir(): - (destination / relative).mkdir(parents=True, exist_ok=True) - elif member.is_file(): - _hardlink(member, destination / relative, description) - else: - raise ClassCPrepareBootstrapError( - f"{description} contains a non-file member: {relative}" - ) - - -def _read_build_info(path: Path) -> dict[str, object]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise ClassCPrepareBootstrapError( - "retained source-runtime build info is unreadable" - ) from error - if not isinstance(value, dict): - raise ClassCPrepareBootstrapError( - "retained source-runtime build info is invalid" - ) - return value - - -def _bind_ancestor_runtime( - live_root: Path, - ancestor_root: Path, -) -> dict[str, object]: - """Bind the exact ignored source-runtime inputs into a tracked A worktree.""" - - live_package = live_root / "src/pyamplicol" - ancestor_package = ancestor_root / "src/pyamplicol" - extensions = tuple( - path - for path in live_package.glob("_rusticol.*") - if path.is_file() - and not path.is_symlink() - and path.name.endswith(_NATIVE_EXTENSION_SUFFIXES) - ) - if len(extensions) != 1: - raise ClassCPrepareBootstrapError( - "live staged runtime must expose exactly one regular native extension" - ) - extension = extensions[0] - - source_runtime = live_root / ".artifacts/source-runtime" - try: - source_runtime_target = source_runtime.resolve(strict=True) - except OSError as error: - raise ClassCPrepareBootstrapError( - "retained source-runtime directory is unavailable" - ) from error - if not source_runtime_target.is_dir(): - raise ClassCPrepareBootstrapError( - "retained source-runtime path is not a directory" - ) - build_info = _read_build_info(source_runtime_target / "_build_info.json") - contract = build_info.get("source_runtime") - if not isinstance(contract, Mapping): - raise ClassCPrepareBootstrapError( - "retained source-runtime contract is missing" - ) - raw_mode = contract.get("mode") - if raw_mode is None: - # Historical source-runtime markers predate the explicit identity mode - # and always used the raw candidate/source-checkout projection. - runtime_mode = "candidate" - elif raw_mode in {"candidate", "release"}: - runtime_mode = str(raw_mode) - valid_build_mode = ( - runtime_mode == "candidate" - and build_info.get("publishable") is False - ) or ( - runtime_mode == "release" - and ( - build_info.get("publishable") is True - or ( - build_info.get("publishable") is False - and build_info.get("release_prepared_model_bootstrap") is True - ) - ) - ) - if not valid_build_mode: - raise ClassCPrepareBootstrapError( - "retained source-runtime identity mode conflicts with build info" - ) - else: - raise ClassCPrepareBootstrapError( - "retained source-runtime identity mode is invalid" - ) - extension_sha256 = _sha256(extension) - if ( - contract.get("extension_name") != extension.name - or contract.get("extension_sha256") != extension_sha256 - ): - raise ClassCPrepareBootstrapError( - "retained native extension differs from source-runtime build info" - ) - - _hardlink( - extension, - ancestor_package / extension.name, - "retained native extension", - ) - for relative in _STAGED_SDK_DIRECTORIES: - _hardlink_tree( - live_package / relative, - ancestor_package / relative, - f"retained SDK tree {relative}", - ) - for relative in _STAGED_SDK_FILES: - _hardlink( - live_package / relative, - ancestor_package / relative, - f"retained SDK member {relative}", - ) - try: - metadata = json.loads( - (live_package / "_sdk/metadata.json").read_text(encoding="utf-8") - ) - target = str(metadata["target"]) - except (OSError, KeyError, TypeError, ValueError, json.JSONDecodeError) as error: - raise ClassCPrepareBootstrapError( - "retained SDK target metadata is invalid" - ) from error - if not target or target in {".", ".."} or "/" in target or "\\" in target: - raise ClassCPrepareBootstrapError( - f"retained SDK target is unsafe: {target!r}" - ) - _hardlink_tree( - live_package / "assets/selftest" / target, - ancestor_package / "assets/selftest" / target, - "retained target self-test fixture", - ) - - ancestor_artifacts = ancestor_root / ".artifacts" - ancestor_artifacts.mkdir() - os.symlink( - source_runtime_target, - ancestor_artifacts / "source-runtime", - target_is_directory=True, - ) - if runtime_mode == "candidate": - dependencies = ancestor_root / "dependencies" - checkouts = (live_root / "dependencies/checkouts").resolve(strict=True) - if not checkouts.is_dir(): - raise ClassCPrepareBootstrapError( - "retained managed dependency checkout root is unavailable" - ) - os.symlink(checkouts, dependencies / "checkouts", target_is_directory=True) - for relative in _IGNORED_NATIVE_INPUTS: - source = (live_root / relative).resolve(strict=True) - if not source.is_file(): - raise ClassCPrepareBootstrapError( - f"retained native input is unavailable: {relative}" - ) - destination = ancestor_root / relative - if destination.exists() or destination.is_symlink(): - raise ClassCPrepareBootstrapError( - f"ancestor native input unexpectedly exists: {relative}" - ) - os.symlink(source, destination) - - observed_native_digest = _native_build_inputs_digest( - ancestor_root, - normalize_release_cargo_lock=runtime_mode == "release", - ) - expected_native_digest = contract.get("native_build_inputs_sha256") - if ( - not isinstance(expected_native_digest, str) - or observed_native_digest != expected_native_digest - ): - raise ClassCPrepareBootstrapError( - "materialized ancestor native inputs differ from retained build info" - ) - return { - "candidate_fingerprint": build_info.get("candidate_fingerprint"), - "extension_name": extension.name, - "extension_sha256": extension_sha256, - "native_build_inputs_sha256": observed_native_digest, - "package_version": build_info.get("version"), - "target": target, - } - - -def _profile(value: str) -> str: - if _PROFILE_RE.fullmatch(value) is None or ".." in value: - raise argparse.ArgumentTypeError("invalid performance-report profile") - return value - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--repo-root", type=Path, default=ROOT) - parser.add_argument("--report-profile", type=_profile, required=True) - parser.add_argument("--artifact-root", type=Path) - parser.add_argument("--coordination-root", type=Path) - parser.add_argument("--ancestor-revision", required=True) - parser.add_argument("--descendant-revision", required=True) - parser.add_argument( - "--impact", - choices=("hzz-orientation-v1", "recurrence-summary-cap-v1"), - required=True, - ) - return parser - - -def _cleanup_worktree(repo_root: Path, worktree: Path) -> None: - completed = _run_git(repo_root, "worktree", "remove", "--force", str(worktree)) - if completed.returncode != 0: - _run_git(repo_root, "worktree", "prune") - - -def main(argv: Sequence[str] | None = None) -> int: - args = _parser().parse_args(argv) - try: - repo_root = args.repo_root.expanduser().resolve(strict=True) - ancestor = _git_commit(repo_root, args.ancestor_revision) - descendant = _git_commit(repo_root, args.descendant_revision) - if ancestor == descendant or _git_commit(repo_root, "HEAD") != descendant: - raise ClassCPrepareBootstrapError( - "live checkout must be at the distinct requested descendant" - ) - ancestry = _run_git( - repo_root, - "merge-base", - "--is-ancestor", - ancestor, - descendant, - ) - if ancestry.returncode != 0: - raise ClassCPrepareBootstrapError( - "Class-C descendant is not a Git descendant of its ancestor" - ) - entrypoint = ( - repo_root - / "docs/performance_reports" - / args.report_profile - / "result_tables.py" - ) - if not entrypoint.is_file() or entrypoint.is_symlink(): - raise ClassCPrepareBootstrapError( - "descendant report entrypoint is unavailable" - ) - - temporary_parent = Path( - tempfile.mkdtemp( - prefix=".pyamplicol-class-c-ancestor-runtime-", - dir=repo_root.parent, - ) - ) - ancestor_root = temporary_parent / "worktree" - try: - added = _run_git( - repo_root, - "worktree", - "add", - "--detach", - str(ancestor_root), - ancestor, - ) - if added.returncode != 0: - raise ClassCPrepareBootstrapError( - "cannot materialize the tracked ancestor worktree: " - f"{added.stderr.strip()}" - ) - runtime = _bind_ancestor_runtime(repo_root, ancestor_root) - print( - json.dumps( - { - "ancestor_revision": ancestor, - "ancestor_runtime_root": str(ancestor_root), - "descendant_revision": descendant, - "descendant_tools_root": str(repo_root), - **runtime, - }, - allow_nan=False, - sort_keys=True, - ), - flush=True, - ) - command = [ - sys.executable, - str(entrypoint), - "--repo-root", - str(repo_root), - "--report-profile", - args.report_profile, - "--class-c-ancestor-runtime-root", - str(ancestor_root), - ] - if args.artifact_root is not None: - command.extend(("--artifact-root", str(args.artifact_root))) - if args.coordination_root is not None: - command.extend( - ("--coordination-root", str(args.coordination_root)) - ) - command.extend( - ( - "prepare-class-c-bridge", - "--ancestor-revision", - ancestor, - "--descendant-revision", - descendant, - "--impact", - args.impact, - ) - ) - completed = subprocess.run(command, check=False) - if completed.returncode != 0: - raise ClassCPrepareBootstrapError( - "descendant Class-C prepare controller failed " - f"with exit code {completed.returncode}" - ) - finally: - if ancestor_root.exists(): - _cleanup_worktree(repo_root, ancestor_root) - shutil.rmtree(temporary_parent, ignore_errors=True) - return 0 - except (ClassCPrepareBootstrapError, OSError) as error: - print(f"error: {error}", file=sys.stderr) - return 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/qq_z6g_final_comparison.py b/pyamplicol/tools/developer/qq_z6g_final_comparison.py deleted file mode 100644 index ca015e342f..0000000000 --- a/pyamplicol/tools/developer/qq_z6g_final_comparison.py +++ /dev/null @@ -1,2209 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Render the authenticated final qq -> Z+6g Arena comparison as Markdown. - -The tool accepts only a content-addressed M0 request and its accepted combined -decision. It re-runs the strict M0 validators over all four pyAmpliCol -captures and both original-AmpliCol workloads, checks that the stored decision -is exactly the recomputed decision apart from its creation timestamp/digest, -and then renders deterministic Markdown from the validated evidence. -""" - -from __future__ import annotations - -import argparse -import contextlib -import hashlib -import importlib.util -import json -import math -import os -import statistics -import sys -from collections.abc import Mapping, Sequence -from dataclasses import asdict, dataclass -from pathlib import Path -from types import ModuleType -from typing import Any, NoReturn - -SCRIPT = Path(__file__).resolve() -DEFAULT_OUTPUT = Path( - ".artifacts/developer/qq-z6g-arena-comparison.md" -) -PRE_ARENA_REQUEST_KIND = "pyamplicol-qq-z6g-pre-arena-evidence-request" -PRE_ARENA_REQUEST_SCHEMA = 1 -_PRE_ARENA_REQUEST_KEYS = { - "kind", - "schema_version", - "matrix_aggregate", - "primary_results", -} -RATIO_PAIRS = ( - ("compiled", "eager"), - ("compiled", "recurrence"), - ("eager", "recurrence"), -) - - -class ComparisonError(RuntimeError): - """The accepted evidence cannot support the requested comparison.""" - - -@dataclass(frozen=True) -class Evidence: - """Strictly revalidated M0 inputs used to render one document.""" - - m0: ModuleType - expected: dict[str, Any] - captures: dict[tuple[str, str], Any] - amplicol: dict[str, Any] - validation: dict[str, Any] - acceptance: dict[str, Any] - request_raw_sha256: str - request_canonical_sha256: str - acceptance_raw_sha256: str - acceptance_content_sha256: str - pre_arena: PreArenaEvidence - - -@dataclass(frozen=True) -class PreArenaEvidence: - """Authenticated frozen AArch64 matrix evidence for the primary workload.""" - - matrix: ModuleType - manifest: Any - aggregate: Any - results: dict[str, Any] - timings: dict[tuple[str, str, str, int], dict[str, Any]] - baseline_build: dict[str, Any] - current_build: dict[str, Any] - baseline_runtime_sha256: str - platform: dict[str, Any] - - -def _die(message: str) -> NoReturn: - raise ComparisonError(message) - - -def _canonical_bytes(value: object) -> bytes: - return json.dumps( - value, - ensure_ascii=True, - allow_nan=False, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_bytes(value)).hexdigest() - - -def _file_sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - while chunk := stream.read(1024 * 1024): - digest.update(chunk) - return digest.hexdigest() - - -def _load_m0() -> ModuleType: - path = SCRIPT.with_name("eager_compiled_arena_m0.py") - spec = importlib.util.spec_from_file_location("_qq_z6g_comparison_m0", path) - if spec is None or spec.loader is None: - _die(f"cannot load M0 validator from {path}") - module = importlib.util.module_from_spec(spec) - sys.modules[spec.name] = module - try: - spec.loader.exec_module(module) - except Exception as error: - raise ComparisonError(f"cannot load M0 validator: {error}") from error - return module - - -def _load_matrix() -> ModuleType: - path = SCRIPT.with_name("compiled_mode_matrix.py") - spec = importlib.util.spec_from_file_location("_qq_z6g_comparison_matrix", path) - if spec is None or spec.loader is None: - _die(f"cannot load frozen matrix contract from {path}") - module = importlib.util.module_from_spec(spec) - sys.modules[spec.name] = module - try: - spec.loader.exec_module(module) - except Exception as error: - raise ComparisonError(f"cannot load frozen matrix contract: {error}") from error - return module - - -def _mapping(value: object, label: str) -> dict[str, Any]: - if not isinstance(value, dict): - _die(f"{label} must be an object") - return value - - -def _list(value: object, label: str) -> list[Any]: - if not isinstance(value, list): - _die(f"{label} must be a list") - return value - - -def _text(value: object, label: str) -> str: - if not isinstance(value, str) or not value: - _die(f"{label} must be a non-empty string") - return value - - -def _integer(value: object, label: str, *, minimum: int = 0) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < minimum: - _die(f"{label} must be an integer >= {minimum}") - return value - - -def _number( - value: object, - label: str, - *, - positive: bool = False, - nonnegative: bool = False, -) -> float: - if ( - isinstance(value, bool) - or not isinstance(value, int | float) - or not math.isfinite(float(value)) - ): - _die(f"{label} must be finite") - result = float(value) - if positive and result <= 0.0: - _die(f"{label} must be positive") - if nonnegative and result < 0.0: - _die(f"{label} must be nonnegative") - return result - - -def _sha256(value: object, label: str) -> str: - result = _text(value, label) - if len(result) != 64 or any( - character not in "0123456789abcdef" for character in result - ): - _die(f"{label} must be a lowercase SHA-256") - return result - - -def _revision(value: object, label: str) -> str: - result = _text(value, label) - if len(result) != 40 or any( - character not in "0123456789abcdef" for character in result - ): - _die(f"{label} must be a full lowercase Git revision") - return result - - -def _load_json_ref( - m0: ModuleType, - path: Path, - expected_sha256: str, - label: str, -) -> Any: - m0._require_sha256(expected_sha256, f"{label} raw SHA-256") - resolved = path.resolve(strict=True) - reference = m0.FileRef( - path=resolved, - stated_path=str(path), - size_bytes=resolved.stat().st_size, - sha256=expected_sha256, - ) - return m0._load_json_ref(reference, label) - - -def _decision_semantics( - *, - acceptance: Mapping[str, Any], - recomputed: Mapping[str, Any], - m0: ModuleType, -) -> dict[str, Any]: - expected_keys = set(recomputed) | {"content_sha256"} - if set(acceptance) != expected_keys: - _die("M0 acceptance has unknown or missing root keys") - without_digest = dict(acceptance) - content_sha256 = without_digest.pop("content_sha256") - if _sha256(content_sha256, "M0 acceptance content digest") != _canonical_sha256( - without_digest - ): - _die("M0 acceptance content digest is stale") - m0._utc(acceptance.get("created_at_utc"), "M0 acceptance creation time") - accepted_semantics = dict(without_digest) - recomputed_semantics = dict(recomputed) - accepted_semantics.pop("created_at_utc") - recomputed_semantics.pop("created_at_utc") - if accepted_semantics != recomputed_semantics: - _die("stored M0 acceptance differs from a fresh strict recomputation") - return accepted_semantics - - -def _manifest_ref( - *, - m0: ModuleType, - value: object, - base: Path, - label: str, -) -> Any: - try: - reference = m0._file_ref(value, base=base, label=label) - return m0._load_json_ref(reference, label) - except Exception as error: - raise ComparisonError(f"{label} is invalid: {error}") from error - - -def _matrix_primary_cells(matrix: ModuleType) -> dict[str, Any]: - primary = { - cell.cell_id: cell - for cell in matrix.CANONICAL_CELLS - if cell.category == "primary" - } - if len(primary) != 24: - _die("frozen matrix no longer contains exactly 24 primary qq_Z6g cells") - expected_axes = { - (model, mode, workload, batch) - for model in ("built-in", "ufo-sm") - for mode in ("eager", "compiled") - for workload in ("lc-topology", "lc-union") - for batch in (1, 128, 1024) - } - observed_axes = { - ( - cell.model_kind, - cell.execution_mode, - cell.workload_key, - cell.batch_size, - ) - for cell in primary.values() - } - if observed_axes != expected_axes: - _die("frozen matrix primary qq_Z6g axes have drifted") - return primary - - -def _validate_matrix_aggregate( - *, - matrix: ModuleType, - loaded: Any, - expected_pre_arena_source_revision: str, - expected_pre_arena_build_sha256: str, - expected_pre_arena_runtime_sha256: str, -) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any], dict[str, Any]]: - payload = loaded.payload - if ( - payload.get("kind") != matrix.RESULT_KIND - or payload.get("schema_version") != matrix.SCHEMA_VERSION - or payload.get("matrix_contract") != matrix.MATRIX_CONTRACT - or payload.get("complete") is not True - or payload.get("run_complete") is not True - or payload.get("passes") is not True - ): - _die("pre-Arena 168-cell matrix aggregate is not a complete acceptance") - - definition = _mapping(payload.get("matrix_definition"), "matrix definition") - canonical_definition = [ - asdict(cell) | {"cell_id": cell.cell_id} for cell in matrix.CANONICAL_CELLS - ] - if definition.get("sha256") != matrix._canonical_sha256(canonical_definition): - _die("pre-Arena matrix definition digest differs from the frozen 168 cells") - coverage = _mapping(payload.get("coverage"), "matrix coverage") - if ( - coverage.get("expected") != 168 - or coverage.get("observed") != 168 - or coverage.get("missing") != [] - or coverage.get("unexpected") != [] - or coverage.get("passes") is not True - ): - _die("pre-Arena matrix does not cover exactly 168 cells") - for gate_name in ( - "cell_gate", - "identity_gate", - "gain_gate", - "generation_gate", - "outer_provenance_gate", - ): - gate = _mapping(payload.get(gate_name), f"matrix {gate_name}") - if gate.get("passes") is not True: - _die(f"pre-Arena matrix {gate_name} did not pass") - - expected_builds = _mapping(payload.get("expected_builds"), "matrix builds") - if set(expected_builds) != {"baseline", "current"}: - _die("pre-Arena matrix build inventory is incomplete") - baseline_build = _mapping(expected_builds["baseline"], "baseline build") - current_build = _mapping(expected_builds["current"], "matrix current build") - for lane, build in ( - ("baseline", baseline_build), - ("current", current_build), - ): - if set(build) != { - "source_revision", - "native_build_inputs_sha256", - "distribution_content_sha256", - "native_module_sha256", - }: - _die(f"matrix {lane} build identity has unknown or missing fields") - _revision(build["source_revision"], f"matrix {lane} source revision") - for field in ( - "native_build_inputs_sha256", - "distribution_content_sha256", - "native_module_sha256", - ): - _sha256(build[field], f"matrix {lane} {field}") - if ( - baseline_build["source_revision"] != expected_pre_arena_source_revision - or baseline_build["source_revision"] != matrix.FROZEN_BASELINE_SOURCE_REVISION - ): - _die("matrix baseline is not the explicitly pinned frozen pre-Arena source") - if _canonical_sha256(baseline_build) != expected_pre_arena_build_sha256: - _die("matrix baseline build identity differs from its explicit digest pin") - - identity_gate = _mapping(payload["identity_gate"], "matrix identity gate") - distinct = _mapping( - identity_gate.get("distinct_sha256"), - "matrix distinct identities", - ) - baseline_runtimes = _list( - distinct.get("runtime:baseline"), - "matrix baseline runtime identities", - ) - if baseline_runtimes != [expected_pre_arena_runtime_sha256]: - _die("matrix baseline runtime identity differs from its explicit digest pin") - _sha256(baseline_runtimes[0], "matrix baseline runtime identity") - - provenance = _mapping(payload.get("provenance"), "matrix provenance") - preflight = _mapping(provenance.get("preflight"), "matrix preflight") - postflight = _mapping(provenance.get("postflight"), "matrix postflight") - if preflight != postflight: - _die("matrix host/runtime state changed between preflight and postflight") - if preflight.get("system") != "Darwin" or preflight.get("machine") != "arm64": - _die("pre-Arena matrix is not the required Darwin AArch64 campaign") - repository = _mapping(preflight.get("repository"), "matrix repository") - if ( - repository.get("clean") is not True - or repository.get("head_revision") != current_build["source_revision"] - ): - _die("matrix current source was not its exact clean measured revision") - platform_record = { - key: preflight.get(key) for key in ("platform", "system", "machine") - } - - cells = _list(payload.get("cells"), "matrix cell audit") - if len(cells) != 168: - _die("matrix aggregate does not retain all 168 cell audit records") - audits: dict[str, Any] = {} - for raw in cells: - audit = _mapping(raw, "matrix cell audit record") - cell_id = _text(audit.get("cell_id"), "matrix cell id") - if cell_id in audits: - _die(f"matrix aggregate repeats cell {cell_id}") - if audit.get("passes") is not True or audit.get("errors") != []: - _die(f"matrix aggregate cell {cell_id} did not pass") - audits[cell_id] = audit - expected_cell_ids = {cell.cell_id for cell in matrix.CANONICAL_CELLS} - if set(audits) != expected_cell_ids: - _die("matrix aggregate cell audit inventory differs from the frozen matrix") - return audits, baseline_build, current_build, platform_record - - -def _matrix_result_distributions( - *, - matrix: ModuleType, - cell: Any, - result: Mapping[str, Any], - audit: Mapping[str, Any], - baseline_runtime_sha256: str, -) -> dict[str, Any]: - regression = matrix.regression - if ( - result.get("kind") != regression.RESULT_KIND - or result.get("schema_version") != regression.SCHEMA_VERSION - or result.get("complete") is not True - or result.get("performance_result_authoritative") is not True - or result.get("passes") is not True - ): - _die(f"pre-Arena primary result {cell.cell_id} is not authoritative") - if matrix._canonical_sha256(result) != audit.get("result_content_sha256"): - _die(f"pre-Arena primary result {cell.cell_id} differs from its aggregate") - if matrix._canonical_sha256(audit.get("configuration")) != matrix._canonical_sha256( - asdict(cell) - ): - _die(f"pre-Arena aggregate cell {cell.cell_id} configuration drifted") - for gate_name in ( - "gate", - "correctness_gate", - "arena_profile_gate", - "resource_gate", - ): - gate = _mapping(result.get(gate_name), f"{cell.cell_id} {gate_name}") - if gate.get("passes") is not True: - _die(f"pre-Arena primary result {cell.cell_id} {gate_name} failed") - - configuration = _mapping( - result.get("configuration"), - f"{cell.cell_id} configuration", - ) - expected_fields = { - "process": cell.process, - "model_label": cell.model_kind, - "execution_mode": cell.execution_mode, - "workload": cell.workload, - "jit_optimization_level": cell.jit_optimization_level, - "color_accuracy": cell.color_accuracy, - "lc_flow_layout": cell.lc_flow_layout, - "batch_size": cell.batch_size, - "helicities": list(cell.helicities), - "color_flows": list(cell.color_flows), - "native_wall_time_source": regression.NATIVE_WALL_TIME_SOURCE, - "native_wall_time_sample_pass": regression.NATIVE_WALL_TIME_SAMPLE_PASS, - "timing_sample_contract": regression.PAIRED_TIMING_SAMPLE_CONTRACT, - } - for field, expected in expected_fields.items(): - if configuration.get(field) != expected: - _die(f"pre-Arena primary {cell.cell_id} configuration.{field} drifted") - sample_count = _integer( - configuration.get("independent_samples_per_lane"), - f"{cell.cell_id} sample count", - minimum=matrix.ACCEPTANCE_SAMPLE_COUNT, - ) - measurements = _list( - result.get("measurements"), - f"{cell.cell_id} measurements", - ) - if len(measurements) != sample_count * 2: - _die(f"pre-Arena primary result {cell.cell_id} sample inventory is incomplete") - - values: dict[str, list[float]] = {"baseline": [], "current": []} - runtime_digests: dict[str, set[str]] = { - "baseline": set(), - "current": set(), - } - observed_orders: dict[int, list[str]] = {} - for raw in measurements: - measurement = _mapping(raw, f"{cell.cell_id} measurement") - lane = measurement.get("lane") - if lane not in values: - _die(f"pre-Arena primary result {cell.cell_id} has an unknown lane") - pair_index = _integer( - measurement.get("pair_index"), - f"{cell.cell_id} pair index", - minimum=1, - ) - order = _integer( - measurement.get("measurement_order"), - f"{cell.cell_id} measurement order", - minimum=1, - ) - if order not in (1, 2): - _die(f"pre-Arena primary result {cell.cell_id} has invalid pair order") - pair = observed_orders.setdefault(pair_index, ["", ""]) - if pair[order - 1]: - _die(f"pre-Arena primary result {cell.cell_id} repeats a pair position") - pair[order - 1] = str(lane) - values[str(lane)].append( - _number( - measurement.get("wall_seconds_per_point"), - f"{cell.cell_id}/{lane} wall time", - positive=True, - ) - ) - runtime = _mapping( - measurement.get("runtime_identity"), - f"{cell.cell_id}/{lane} runtime identity", - ) - runtime_digests[str(lane)].add( - matrix._canonical_sha256(matrix._stable_runtime_identity_value(runtime)) - ) - expected_orders = { - pair_index: ( - ["baseline", "current"] - if (pair_index - 1) % 2 == 0 - else ["current", "baseline"] - ) - for pair_index in range(1, sample_count + 1) - } - if observed_orders != expected_orders or result.get("pair_orders") != list( - expected_orders.values() - ): - _die(f"pre-Arena primary result {cell.cell_id} is not paired/interleaved") - if runtime_digests["baseline"] != {baseline_runtime_sha256}: - _die(f"pre-Arena primary result {cell.cell_id} baseline runtime drifted") - aggregate_runtime_digests = _mapping( - audit.get("runtime_identity_sha256_by_lane"), - f"{cell.cell_id} aggregate runtime identities", - ) - if { - lane: next(iter(digests)) for lane, digests in runtime_digests.items() - } != aggregate_runtime_digests: - _die(f"pre-Arena primary result {cell.cell_id} runtime audit is stale") - - recomputed = { - lane: regression._distribution(lane_values) - for lane, lane_values in values.items() - } - if result.get("distributions") != recomputed: - _die(f"pre-Arena primary result {cell.cell_id} distributions are stale") - paired = regression._paired_distribution(measurements) - if result.get("paired_distribution") != paired: - _die(f"pre-Arena primary result {cell.cell_id} paired statistics are stale") - correctness = regression._correctness_gate(measurements) - if result.get("correctness_gate") != correctness: - _die(f"pre-Arena primary result {cell.cell_id} correctness gate is stale") - return recomputed - - -def validate_pre_arena_evidence( - *, - m0: ModuleType, - manifest_path: Path, - manifest_sha256: str, - expected_pre_arena_source_revision: str, - expected_pre_arena_build_sha256: str, - expected_pre_arena_runtime_sha256: str, -) -> PreArenaEvidence: - """Authenticate the frozen AArch64 matrix and all 24 primary result files.""" - - matrix = _load_matrix() - manifest_loaded = _load_json_ref( - m0, - manifest_path, - manifest_sha256, - "pre-Arena evidence request", - ) - manifest = manifest_loaded.payload - if set(manifest) != _PRE_ARENA_REQUEST_KEYS: - _die("pre-Arena evidence request has unknown or missing root keys") - if ( - manifest.get("kind") != PRE_ARENA_REQUEST_KIND - or manifest.get("schema_version") != PRE_ARENA_REQUEST_SCHEMA - ): - _die("pre-Arena evidence request kind/schema is unsupported") - base = manifest_loaded.ref.path.parent - aggregate_loaded = _manifest_ref( - m0=m0, - value=manifest.get("matrix_aggregate"), - base=base, - label="pre-Arena matrix aggregate", - ) - audits, baseline_build, current_build, platform_record = _validate_matrix_aggregate( - matrix=matrix, - loaded=aggregate_loaded, - expected_pre_arena_source_revision=expected_pre_arena_source_revision, - expected_pre_arena_build_sha256=expected_pre_arena_build_sha256, - expected_pre_arena_runtime_sha256=expected_pre_arena_runtime_sha256, - ) - primary = _matrix_primary_cells(matrix) - refs = _list(manifest.get("primary_results"), "pre-Arena primary results") - if len(refs) != len(primary): - _die("pre-Arena evidence request must contain exactly 24 primary results") - results: dict[str, Any] = {} - timings: dict[tuple[str, str, str, int], dict[str, Any]] = {} - for index, value in enumerate(refs): - record = _mapping(value, f"pre-Arena primary result ref {index}") - if set(record) != {"cell_id", "path", "size_bytes", "sha256"}: - _die(f"pre-Arena primary result ref {index} has unknown/missing fields") - cell_id = _text(record["cell_id"], f"pre-Arena primary result {index} id") - cell = primary.get(cell_id) - if cell is None or cell_id in results: - _die(f"pre-Arena primary result inventory has invalid cell {cell_id}") - loaded = _manifest_ref( - m0=m0, - value={key: record[key] for key in ("path", "size_bytes", "sha256")}, - base=base, - label=f"pre-Arena primary result {cell_id}", - ) - distributions = _matrix_result_distributions( - matrix=matrix, - cell=cell, - result=loaded.payload, - audit=audits[cell_id], - baseline_runtime_sha256=expected_pre_arena_runtime_sha256, - ) - results[cell_id] = loaded - model = "built-in-sm" if cell.model_kind == "built-in" else "ufo-sm" - layout = ( - "topology-replay" - if cell.workload_key == "lc-topology" - else "all-flow-union" - ) - key = (model, layout, cell.execution_mode, cell.batch_size) - if key in timings: - _die(f"pre-Arena primary timing key is duplicated: {key}") - timings[key] = distributions - if set(results) != set(primary) or len(timings) != 24: - _die("pre-Arena primary result inventory is incomplete") - return PreArenaEvidence( - matrix=matrix, - manifest=manifest_loaded, - aggregate=aggregate_loaded, - results=results, - timings=timings, - baseline_build=baseline_build, - current_build=current_build, - baseline_runtime_sha256=expected_pre_arena_runtime_sha256, - platform=platform_record, - ) - - -def _bind_matrix_current_to_final( - *, - pre_arena: PreArenaEvidence, - final_capture: Any, - expected_source_revision: str, -) -> None: - current = pre_arena.current_build - runtime = _mapping(final_capture.runtime_identity, "final Arena runtime identity") - native = _mapping(runtime.get("native_extension"), "final native extension") - distribution = _mapping( - runtime.get("installed_distribution"), - "final installed distribution", - ) - distribution_content = _mapping( - distribution.get("distribution_content"), - "final distribution content", - ) - expected = { - "source_revision": expected_source_revision, - "native_build_inputs_sha256": _sha256( - native.get("build_inputs_sha256"), - "final native build-input digest", - ), - "distribution_content_sha256": _sha256( - distribution_content.get("sha256"), - "final distribution-content digest", - ), - "native_module_sha256": _sha256( - native.get("sha256"), - "final native-module digest", - ), - } - if current != expected: - _die( - "168-cell matrix current build does not equal the final M0 " - "source/native runtime" - ) - - -def validate_evidence( - *, - request_path: Path, - request_sha256: str, - acceptance_path: Path, - acceptance_sha256: str, - expected_source_revision: str, - expected_runtime_provenance_sha256: str, - pre_arena_manifest_path: Path, - pre_arena_manifest_sha256: str, - expected_pre_arena_source_revision: str, - expected_pre_arena_build_sha256: str, - expected_pre_arena_runtime_sha256: str, -) -> Evidence: - """Re-run the complete M0 decision and bind it to explicit final identities.""" - - m0 = _load_m0() - expected_source_revision = _revision( - expected_source_revision, - "--expected-source-revision", - ) - expected_runtime_provenance_sha256 = _sha256( - expected_runtime_provenance_sha256, - "--expected-runtime-provenance-sha256", - ) - expected_pre_arena_source_revision = _revision( - expected_pre_arena_source_revision, - "--expected-pre-arena-source-revision", - ) - expected_pre_arena_build_sha256 = _sha256( - expected_pre_arena_build_sha256, - "--expected-pre-arena-build-sha256", - ) - expected_pre_arena_runtime_sha256 = _sha256( - expected_pre_arena_runtime_sha256, - "--expected-pre-arena-runtime-sha256", - ) - request_loaded = _load_json_ref( - m0, - request_path, - request_sha256, - "M0 request", - ) - request = request_loaded.payload - m0._require_exact_keys(request, m0._REQUEST_KEYS, "M0 request") - if ( - request.get("kind") != m0.REQUEST_KIND - or request.get("schema_version") != m0.REQUEST_SCHEMA - ): - _die("M0 request kind/schema is unsupported") - expected = m0._validate_expected(request.get("expected")) - if expected["pyamplicol_source_revision"] != expected_source_revision: - _die("M0 request does not pin the explicitly requested final source revision") - if expected["runtime_provenance_sha256"] != expected_runtime_provenance_sha256: - _die("M0 request does not pin the explicitly requested final runtime identity") - - capture_refs, amplicol_refs = m0._request_refs( - request, - request_loaded.ref.path.parent, - ) - benchmark = m0._load_benchmark_module() - captures = { - key: m0._validate_capture( - m0._load_json_ref(ref, f"{key[0]}/{key[1]} capture"), - model=key[0], - layout=key[1], - expected=expected, - benchmark=benchmark, - ) - for key, ref in capture_refs.items() - } - amplicol = { - role: m0._validate_amplicol( - m0._load_json_ref(ref, f"amplicol/{role}"), - role=role, - expected=expected, - ) - for role, ref in amplicol_refs.items() - } - validation = m0._cross_validate(captures, amplicol) - recomputed = m0._accepted_manifest( - request_loaded=request_loaded, - captures=captures, - amplicol=amplicol, - validation=validation, - expected=expected, - ) - - acceptance_loaded = _load_json_ref( - m0, - acceptance_path, - acceptance_sha256, - "M0 acceptance", - ) - acceptance = acceptance_loaded.payload - _decision_semantics( - acceptance=acceptance, - recomputed=recomputed, - m0=m0, - ) - if ( - acceptance.get("accepted") is not True - or acceptance.get("status") != "accepted" - or acceptance.get("errors") != [] - ): - _die("M0 decision is not an error-free acceptance") - common = _mapping(acceptance.get("common_contract"), "acceptance.common_contract") - source = _mapping(common.get("source"), "acceptance.common_contract.source") - if source.get("revision") != expected_source_revision: - _die("accepted source identity differs from the explicit final revision") - if common.get("runtime_provenance_sha256") != expected_runtime_provenance_sha256: - _die("accepted runtime identity differs from the explicit final digest") - pre_arena = validate_pre_arena_evidence( - m0=m0, - manifest_path=pre_arena_manifest_path, - manifest_sha256=pre_arena_manifest_sha256, - expected_pre_arena_source_revision=expected_pre_arena_source_revision, - expected_pre_arena_build_sha256=expected_pre_arena_build_sha256, - expected_pre_arena_runtime_sha256=expected_pre_arena_runtime_sha256, - ) - primary = _matrix_primary_cells(pre_arena.matrix) - topology_cell = next( - cell for cell in primary.values() if cell.workload_key == "lc-topology" - ) - union_cell = next( - cell for cell in primary.values() if cell.workload_key == "lc-union" - ) - if tuple(topology_cell.color_flows) != (expected["color_flow"]["id"],) or tuple( - union_cell.helicities - ) != (expected["helicity"]["id"],): - _die("pre-Arena and final Arena captures use different runtime selectors") - first_capture = captures[("built-in-sm", "topology-replay")] - if ( - pre_arena.platform["system"] != first_capture.host["system"] - or pre_arena.platform["machine"] != first_capture.host["machine"] - ): - _die("pre-Arena and final Arena evidence are not from one architecture") - _bind_matrix_current_to_final( - pre_arena=pre_arena, - final_capture=first_capture, - expected_source_revision=expected_source_revision, - ) - return Evidence( - m0=m0, - expected=expected, - captures=captures, - amplicol=amplicol, - validation=validation, - acceptance=acceptance, - request_raw_sha256=request_sha256, - request_canonical_sha256=request_loaded.canonical_sha256, - acceptance_raw_sha256=acceptance_sha256, - acceptance_content_sha256=_sha256( - acceptance["content_sha256"], - "M0 acceptance content digest", - ), - pre_arena=pre_arena, - ) - - -def _escape(value: object) -> str: - return str(value).replace("|", "\\|").replace("\n", " ") - - -def _table(headers: Sequence[str], rows: Sequence[Sequence[object]]) -> list[str]: - if any(len(row) != len(headers) for row in rows): - _die("internal Markdown table width mismatch") - result = [ - "| " + " | ".join(_escape(header) for header in headers) + " |", - "| " + " | ".join("---" for _ in headers) + " |", - ] - result.extend( - "| " + " | ".join(_escape(value) for value in row) + " |" for row in rows - ) - return result - - -def _model_label(model: str) -> str: - return {"built-in-sm": "Built-in SM", "ufo-sm": "UFO SM"}[model] - - -def _layout_label(layout: str) -> str: - return { - "topology-replay": "Selected LC flow / helicity sum", - "all-flow-union": "All LC flows / one helicity", - }[layout] - - -def _mode_label(mode: str) -> str: - return { - "compiled": "Compiled DAG (JIT O3)", - "eager": "Eager DAG", - "recurrence": "Recurrence", - }[mode] - - -def _seconds(value: float) -> str: - return f"{value:.9g} s" - - -def _microseconds(value: float) -> str: - return f"{value * 1.0e6:.9g} µs/point" - - -def _ratio(value: float) -> str: - return f"{value:.9g}x" - - -def _digest(value: str) -> str: - return f"`{value}`" - - -def _bytes(value: int) -> str: - return f"{value:,} B ({value / (1024 * 1024):.3f} MiB)" - - -def _complex(value: complex) -> str: - return f"`{value.real:.17g}{value.imag:+.17g}i`" - - -def _comparison_stats( - left: Sequence[complex], - right: Sequence[complex], - *, - absolute_floor: float, -) -> tuple[float, float]: - if len(left) != len(right) or not left: - _die("numerical comparison has mismatched or empty point inventories") - maximum_absolute = 0.0 - maximum_relative = 0.0 - for lhs, rhs in zip(left, right, strict=True): - difference = abs(lhs - rhs) - relative = difference / max(abs(rhs), absolute_floor) - maximum_absolute = max(maximum_absolute, difference) - maximum_relative = max(maximum_relative, relative) - return maximum_absolute, maximum_relative - - -def _capture_input_rows(evidence: Evidence) -> list[list[object]]: - rows: list[list[object]] = [ - [ - "Combined request", - _digest(evidence.request_raw_sha256), - _digest(evidence.request_canonical_sha256), - ], - [ - "Combined acceptance", - _digest(evidence.acceptance_raw_sha256), - _digest(evidence.acceptance_content_sha256), - ], - ] - for model in evidence.m0.MODELS: - for layout in evidence.m0.LAYOUTS: - loaded = evidence.captures[(model, layout)].loaded - rows.append( - [ - f"{_model_label(model)} — {_layout_label(layout)}", - _digest(loaded.ref.sha256), - _digest(loaded.canonical_sha256), - ] - ) - for role in ( - evidence.m0.AMPLICOL_SELECTED_ROLE, - evidence.m0.AMPLICOL_UNION_ROLE, - ): - loaded = evidence.amplicol[role].loaded - rows.append( - [ - f"Original AmpliCol — {role}", - _digest(loaded.ref.sha256), - _digest(loaded.canonical_sha256), - ] - ) - for label, loaded in ( - ("Pre-Arena evidence request", evidence.pre_arena.manifest), - ("Pre-Arena 168-cell aggregate", evidence.pre_arena.aggregate), - ): - rows.append( - [ - label, - _digest(loaded.ref.sha256), - _digest(loaded.canonical_sha256), - ] - ) - for cell_id, loaded in sorted(evidence.pre_arena.results.items()): - rows.append( - [ - f"Pre-Arena primary — {cell_id}", - _digest(loaded.ref.sha256), - _digest(loaded.canonical_sha256), - ] - ) - return rows - - -def _runtime_identity_rows(evidence: Evidence) -> list[list[object]]: - first = evidence.captures[("built-in-sm", "topology-replay")] - runtime = _mapping(first.runtime_identity, "runtime identity") - interpreter = _mapping(runtime.get("interpreter"), "runtime interpreter") - native = _mapping(runtime.get("native_extension"), "native extension") - distribution = _mapping( - runtime.get("installed_distribution"), - "installed distribution", - ) - distribution_content = _mapping( - distribution.get("distribution_content"), - "distribution content", - ) - build_info = _mapping(runtime.get("active_build_info"), "active build info") - build_payload = _mapping(build_info.get("payload"), "active build payload") - source_revision = evidence.expected["pyamplicol_source_revision"] - if build_payload.get("source_revision") != source_revision: - _die("active build info source revision is stale") - distribution_file_count = _integer( - distribution_content.get("file_count"), - "distribution file count", - minimum=1, - ) - distribution_size = _integer( - distribution_content.get("size_bytes"), - "distribution size", - minimum=1, - ) - distribution_sha256 = _sha256( - distribution_content.get("sha256"), - "distribution digest", - ) - return [ - ["pyAmpliCol source revision", _digest(source_revision)], - [ - "Runtime-provenance digest", - _digest(evidence.expected["runtime_provenance_sha256"]), - ], - [ - "Candidate/package version", - _text(distribution.get("package_version"), "distribution package version"), - ], - [ - "Candidate fingerprint", - _text(build_payload.get("candidate_fingerprint"), "candidate fingerprint"), - ], - [ - "Native extension SHA-256", - _digest(_sha256(native.get("sha256"), "native extension digest")), - ], - [ - "Native build-input SHA-256", - _digest( - _sha256( - native.get("build_inputs_sha256"), - "native build-input digest", - ) - ), - ], - [ - "Installed distribution", - ( - f"{distribution_file_count} files, " - f"{_bytes(distribution_size)}; " - f"{_digest(distribution_sha256)}" - ), - ], - [ - "Python interpreter", - ( - f"{_text(interpreter.get('implementation'), 'interpreter')} " - f"{_text(interpreter.get('python_version'), 'Python version')}; " - f"{_digest(_sha256(interpreter.get('sha256'), 'interpreter digest'))}" - ), - ], - ] - - -def _original_identity_rows(evidence: Evidence) -> list[list[object]]: - selected = evidence.amplicol[evidence.m0.AMPLICOL_SELECTED_ROLE] - source = _mapping(selected.source_identity, "original AmpliCol source") - compiler = _mapping(source.get("compiler"), "original AmpliCol compiler") - return [ - [ - "Original AmpliCol revision", - _digest(_revision(source.get("revision"), "AmpliCol revision")), - ], - [ - "Tracked source-tree SHA-256", - _digest(_sha256(source.get("source_tree_sha256"), "AmpliCol source tree")), - ], - [ - "Fortran compiler", - ( - f"{_text(compiler.get('id'), 'compiler id')} — " - f"{_text(compiler.get('version'), 'compiler version')}" - ), - ], - ["Compiler target", _text(compiler.get("target"), "compiler target")], - [ - "Compiler-flags SHA-256", - _digest(_sha256(compiler.get("flags_sha256"), "compiler flags")), - ], - ] - - -def _pre_arena_identity_rows(evidence: Evidence) -> list[list[object]]: - baseline = evidence.pre_arena.baseline_build - current = evidence.pre_arena.current_build - platform_record = evidence.pre_arena.platform - return [ - [ - "Frozen pre-Arena source revision", - _digest( - _revision( - baseline["source_revision"], - "pre-Arena source revision", - ) - ), - ], - [ - "Frozen pre-Arena build identity SHA-256", - _digest(_canonical_sha256(baseline)), - ], - [ - "Frozen pre-Arena runtime identity SHA-256", - _digest(evidence.pre_arena.baseline_runtime_sha256), - ], - [ - "Frozen pre-Arena native build-input SHA-256", - _digest(baseline["native_build_inputs_sha256"]), - ], - [ - "Frozen pre-Arena distribution SHA-256", - _digest(baseline["distribution_content_sha256"]), - ], - [ - "Frozen pre-Arena native module SHA-256", - _digest(baseline["native_module_sha256"]), - ], - [ - "168-cell matrix Arena source revision", - _digest( - _revision( - current["source_revision"], - "matrix Arena source revision", - ) - ), - ], - [ - "168-cell matrix Arena native module SHA-256", - _digest(current["native_module_sha256"]), - ], - [ - "Matrix platform", - ( - f"{_text(platform_record['system'], 'matrix system')} " - f"{_text(platform_record['machine'], 'matrix machine')} — " - f"{_text(platform_record['platform'], 'matrix platform')}" - ), - ], - ] - - -def _numerical_sections(evidence: Evidence) -> list[str]: - lines: list[str] = [ - "## Numerical agreement", - "", - ( - "The combined M0 validator re-evaluated every retained point, required " - "selected totals to close against resolved sums, required all three " - "pyAmpliCol lanes to agree, required built-in and UFO models to agree, " - "and required both original-AmpliCol workloads to agree with their " - "built-in pyAmpliCol counterparts." - ), - "", - "### Pointwise values across model implementations and original AmpliCol", - "", - ] - point_rows: list[list[object]] = [] - for layout in evidence.m0.LAYOUTS: - builtin = evidence.captures[("built-in-sm", layout)].validation_values - ufo = evidence.captures[("ufo-sm", layout)].validation_values - role = ( - evidence.m0.AMPLICOL_UNION_ROLE - if layout == "all-flow-union" - else evidence.m0.AMPLICOL_SELECTED_ROLE - ) - original = evidence.amplicol[role].values - if len(builtin) != len(ufo) or len(builtin) != len(original): - _die(f"{layout} pointwise inventories differ after M0 validation") - for index, (built, external, independent) in enumerate( - zip(builtin, ufo, original, strict=True) - ): - maximum_absolute, maximum_relative = _comparison_stats( - (built, built), - (external, independent), - absolute_floor=evidence.m0.ATOL, - ) - point_rows.append( - [ - _layout_label(layout), - index, - _complex(built), - _complex(external), - _complex(independent), - f"{maximum_absolute:.9g}", - f"{maximum_relative:.9g}", - "yes", - ] - ) - lines.extend( - _table( - ( - "Workload", - "Point", - "Built-in SM", - "UFO SM", - "Original AmpliCol", - "Max |Δ|", - "Max relative Δ", - "Pass", - ), - point_rows, - ) - ) - lines.extend(["", "### Selected-total versus resolved-sum closure", ""]) - closure_rows: list[list[object]] = [] - lane_rows: list[list[object]] = [] - component_rows: list[list[object]] = [] - for model in evidence.m0.MODELS: - for layout in evidence.m0.LAYOUTS: - capture = evidence.captures[(model, layout)] - payload = capture.loaded.payload - profiles = _mapping(payload.get("profiles"), "capture profiles") - for mode in evidence.m0.MODES: - profile = _mapping(profiles.get(mode), f"{model}/{layout}/{mode}") - validation = _mapping( - profile.get("validation"), - f"{model}/{layout}/{mode} validation", - ) - if validation.get("passes") is not True: - _die(f"{model}/{layout}/{mode} validation is not passing") - closure_absolute = _number( - validation.get("maximum_absolute_difference"), - "closure max abs", - nonnegative=True, - ) - closure_relative = _number( - validation.get("maximum_relative_difference"), - "closure max rel", - nonnegative=True, - ) - closure_rows.append( - [ - _model_label(model), - _layout_label(layout), - _mode_label(mode), - f"{closure_absolute:.9g}", - f"{closure_relative:.9g}", - "yes", - ] - ) - comparisons = _mapping( - payload.get("lane_comparisons"), - f"{model}/{layout} lane comparisons", - ) - summary = _mapping( - payload.get("validation_summary"), - f"{model}/{layout} validation summary", - ) - resolved = _mapping( - summary.get("resolved_component_comparisons"), - f"{model}/{layout} component comparisons", - ) - for left, right in RATIO_PAIRS: - key = f"{left}__{right}" - comparison = _mapping(comparisons.get(key), f"{model}/{layout}/{key}") - if comparison.get("passes") is not True: - _die(f"{model}/{layout}/{key} total comparison failed") - lane_absolute = _number( - comparison.get("maximum_absolute_difference"), - "lane max abs", - nonnegative=True, - ) - lane_relative = _number( - comparison.get("maximum_relative_difference"), - "lane max rel", - nonnegative=True, - ) - lane_rows.append( - [ - _model_label(model), - _layout_label(layout), - f"{left} vs {right}", - f"{lane_absolute:.9g}", - f"{lane_relative:.9g}", - "yes", - ] - ) - component = _mapping( - resolved.get(key), - f"{model}/{layout}/{key} component comparison", - ) - if component.get("passes") is not True: - _die(f"{model}/{layout}/{key} component comparison failed") - component_absolute = _number( - component.get("maximum_absolute_difference"), - "component max abs", - nonnegative=True, - ) - component_relative = _number( - component.get("maximum_relative_difference"), - "component max rel", - nonnegative=True, - ) - component_rows.append( - [ - _model_label(model), - _layout_label(layout), - f"{left} vs {right}", - _integer( - component.get("compared_component_count"), - "compared component count", - minimum=1, - ), - f"{component_absolute:.9g}", - f"{component_relative:.9g}", - "yes", - ] - ) - lines.extend( - _table( - ( - "Model", - "Workload", - "Mode", - "Max |selected - resolved|", - "Max relative Δ", - "Pass", - ), - closure_rows, - ) - ) - lines.extend(["", "### Cross-lane total agreement", ""]) - lines.extend( - _table( - ("Model", "Workload", "Lane pair", "Max |Δ|", "Max relative Δ", "Pass"), - lane_rows, - ) - ) - lines.extend(["", "### Cross-lane resolved-component agreement", ""]) - lines.extend( - _table( - ( - "Model", - "Workload", - "Lane pair", - "Components", - "Max |Δ|", - "Max relative Δ", - "Pass", - ), - component_rows, - ) - ) - return lines - - -def _generation_sections(evidence: Evidence) -> list[str]: - lines = [ - "## Generation, artifact, and memory evidence", - "", - ( - "Generation wall time and RSS are single worker observations, not " - "multi-sample runtime statistics. RSS is the retained high-water-mark " - "lower bound described by each capture." - ), - "", - ] - rows: list[list[object]] = [] - phase_rows: list[list[object]] = [] - for model in evidence.m0.MODELS: - for layout in evidence.m0.LAYOUTS: - payload = evidence.captures[(model, layout)].loaded.payload - generation = _mapping( - payload.get("generation"), - f"{model}/{layout} generation", - ) - if set(generation) != set(evidence.m0.MODES): - _die(f"{model}/{layout} generation inventory is incomplete") - for mode in evidence.m0.MODES: - record = _mapping( - generation[mode], - f"{model}/{layout}/{mode} generation", - ) - reused = record.get("generation_reused") - if not isinstance(reused, bool): - _die(f"{model}/{layout}/{mode} reuse flag is invalid") - raw_wall = record.get("generation_wall_seconds") - wall = ( - "Unavailable (artifact reused)" - if raw_wall is None and reused - else _seconds( - _number( - raw_wall, - f"{model}/{layout}/{mode} generation wall", - positive=True, - ) - ) - ) - stats = _mapping( - record.get("artifact_stats"), - f"{model}/{layout}/{mode} artifact stats", - ) - files = _integer( - stats.get("file_count"), - "artifact file count", - minimum=1, - ) - size = _integer( - stats.get("size_bytes"), - "artifact size", - minimum=1, - ) - peak = record.get("peak_rss") - if peak is None and reused: - rss = "Unavailable (artifact reused)" - else: - peak_map = _mapping(peak, "generation peak RSS") - rss = _bytes( - _integer( - peak_map.get("observed_lower_bound_bytes"), - "generation RSS lower bound", - minimum=1, - ) - ) - phases = _mapping( - record.get("phase_timings_seconds"), - f"{model}/{layout}/{mode} phase timings", - ) - phase_values = { - str(name): _number( - value, - f"{model}/{layout}/{mode}/{name}", - nonnegative=True, - ) - for name, value in phases.items() - } - if not phase_values: - _die(f"{model}/{layout}/{mode} has no phase timings") - model_load = ( - _seconds(phase_values["model-loading"]) - if "model-loading" in phase_values - else "Unavailable" - ) - semantic_sha = _sha256( - record.get("artifact_semantic_identity_sha256"), - "artifact semantic identity", - ) - rows.append( - [ - _model_label(model), - _layout_label(layout), - _mode_label(mode), - wall, - model_load, - files, - _bytes(size), - rss, - _digest(semantic_sha), - ] - ) - for phase_name in sorted(phase_values): - phase_rows.append( - [ - _model_label(model), - _layout_label(layout), - _mode_label(mode), - phase_name, - _seconds(phase_values[phase_name]), - ] - ) - lines.extend( - _table( - ( - "Model", - "Workload", - "Mode", - "Generation wall", - "Model-load phase", - "Files", - "Artifact bytes", - "Generation peak RSS lower bound", - "Artifact semantic SHA-256", - ), - rows, - ) - ) - lines.extend(["", "### Retained generation phase breakdown", ""]) - lines.extend( - _table( - ("Model", "Workload", "Mode", "Phase", "Seconds"), - phase_rows, - ) - ) - lines.extend( - [ - "", - "### Metrics not retained by the authenticated capture", - "", - ] - ) - lines.extend( - _table( - ("Metric", "Status", "Reason"), - ( - ( - "Cold artifact load time", - "Unavailable", - "Not retained in the final schema-6 aggregate.", - ), - ( - "Profile-worker RSS", - "Unavailable", - ( - "Not retained in the final schema-6 aggregate; only " - "generation RSS is reported above." - ), - ), - ( - "Memory traffic", - "Unavailable", - "No authenticated byte/counter measurement is present.", - ), - ( - "Allocation counts/bytes", - "Unavailable", - "No authenticated allocator measurement is present.", - ), - ), - ) - ) - return lines - - -def _raw_round_values( - capture: Any, - *, - mode: str, - batch: int, -) -> dict[int, float]: - payload = capture.loaded.payload - profiles = _mapping(payload.get("profiles"), "capture profiles") - profile = _mapping(profiles.get(mode), f"profile {mode}") - measurements = _list(profile.get("profiles"), f"profile {mode} measurements") - matches = [ - _mapping(row, f"{mode}/{batch} measurement") - for row in measurements - if isinstance(row, dict) and row.get("batch_size") == batch - ] - if len(matches) != 1: - _die(f"{mode}/batch-{batch} does not have exactly one measurement") - samples = _list( - matches[0].get("subprocess_samples"), - f"{mode}/batch-{batch} subprocess samples", - ) - result: dict[int, float] = {} - ordered: list[float] = [] - for sample in samples: - row = _mapping(sample, f"{mode}/batch-{batch} sample") - round_index = _integer(row.get("round"), "schedule round") - if round_index in result: - _die(f"{mode}/batch-{batch} repeats schedule round {round_index}") - value = _number( - row.get("wall_seconds_per_point"), - f"{mode}/batch-{batch}/round-{round_index} wall time", - positive=True, - ) - if row.get("interrupted") is not False: - _die(f"{mode}/batch-{batch}/round-{round_index} was interrupted") - result[round_index] = value - ordered.append(value) - retained = capture.timings[mode][str(batch)] - if ordered != retained["raw_seconds_per_point"]: - _die(f"{mode}/batch-{batch} raw samples differ from validated M0 timings") - return result - - -def _runtime_sections(evidence: Evidence) -> list[str]: - lines = [ - "## Runtime performance", - "", - ( - "Values are subprocess medians with raw MAD, normalized to one physical " - "phase-space point. The headline source is " - "`runtime_core_repeated_wall_time`." - ), - "", - "### Median ± raw MAD", - "", - ] - timing_rows: list[list[object]] = [] - ratio_rows: list[list[object]] = [] - for model in evidence.m0.MODELS: - for layout in evidence.m0.LAYOUTS: - capture = evidence.captures[(model, layout)] - for mode in evidence.m0.MODES: - for batch in evidence.m0.BATCHES: - timing = _mapping( - capture.timings[mode][str(batch)], - f"{model}/{layout}/{mode}/{batch} timing", - ) - median = _number( - timing.get("median_seconds_per_point"), - "runtime median", - positive=True, - ) - mad = _number( - timing.get("mad_seconds_per_point"), - "runtime MAD", - nonnegative=True, - ) - count = _integer( - timing.get("sample_count"), - "runtime sample count", - minimum=evidence.m0.MIN_SAMPLES, - ) - timing_rows.append( - [ - _model_label(model), - _layout_label(layout), - _mode_label(mode), - batch, - _microseconds(median), - _microseconds(mad), - count, - ] - ) - for batch in evidence.m0.BATCHES: - by_mode = { - mode: _raw_round_values(capture, mode=mode, batch=batch) - for mode in evidence.m0.MODES - } - round_sets = {tuple(sorted(values)) for values in by_mode.values()} - if len(round_sets) != 1: - _die(f"{model}/{layout}/batch-{batch} round sets differ by mode") - rounds = next(iter(round_sets)) - if len(rounds) < evidence.m0.MIN_SAMPLES: - _die(f"{model}/{layout}/batch-{batch} lacks seven paired rounds") - ratios: list[str] = [] - for left, right in RATIO_PAIRS: - values = [ - by_mode[left][round_index] / by_mode[right][round_index] - for round_index in rounds - ] - median = statistics.median(values) - mad = statistics.median(abs(value - median) for value in values) - ratios.append(f"{_ratio(median)} ± {_ratio(mad)}") - ratio_rows.append( - [ - _model_label(model), - _layout_label(layout), - batch, - len(rounds), - *ratios, - ] - ) - lines.extend( - _table( - ("Model", "Workload", "Mode", "Batch", "Median", "Raw MAD", "Subprocesses"), - timing_rows, - ) - ) - lines.extend(["", "### Same-round runtime ratios", ""]) - lines.append( - "Each ratio is formed within the same scheduler round before taking " - "its median and raw MAD." - ) - lines.append("") - lines.extend( - _table( - ( - "Model", - "Workload", - "Batch", - "Paired rounds", - "Compiled / eager", - "Compiled / recurrence", - "Eager / recurrence", - ), - ratio_rows, - ) - ) - return lines - - -def _pre_arena_comparison_sections(evidence: Evidence) -> list[str]: - lines = [ - "## Frozen pre-Arena comparison", - "", - ( - "The baseline and matrix-Arena columns come from the authenticated " - "AArch64 168-cell campaign. The final-Arena column comes from the " - "strict M0 campaign. All use the same physical process, model family, " - "LC selector, execution mode, batch, and runtime-core wall-time " - "boundary. These campaigns were not scheduler-round paired, so the " - "cross-campaign ratios below are ratios of independently computed " - "medians; no paired uncertainty is claimed." - ), - "", - ] - rows: list[list[object]] = [] - for model in evidence.m0.MODELS: - for layout in evidence.m0.LAYOUTS: - capture = evidence.captures[(model, layout)] - for mode in ("compiled", "eager"): - for batch in evidence.m0.BATCHES: - distributions = evidence.pre_arena.timings[ - (model, layout, mode, batch) - ] - baseline = _mapping( - distributions.get("baseline"), - "pre-Arena timing distribution", - ) - matrix_current = _mapping( - distributions.get("current"), - "matrix Arena timing distribution", - ) - final_current = _mapping( - capture.timings[mode][str(batch)], - "final Arena timing distribution", - ) - baseline_median = _number( - baseline.get("median_seconds_per_point"), - "pre-Arena median", - positive=True, - ) - baseline_mad = _number( - baseline.get("mad_seconds_per_point"), - "pre-Arena MAD", - nonnegative=True, - ) - matrix_median = _number( - matrix_current.get("median_seconds_per_point"), - "matrix Arena median", - positive=True, - ) - matrix_mad = _number( - matrix_current.get("mad_seconds_per_point"), - "matrix Arena MAD", - nonnegative=True, - ) - final_median = _number( - final_current.get("median_seconds_per_point"), - "final Arena median", - positive=True, - ) - final_mad = _number( - final_current.get("mad_seconds_per_point"), - "final Arena MAD", - nonnegative=True, - ) - final_ratio = final_median / baseline_median - rows.append( - [ - _model_label(model), - _layout_label(layout), - _mode_label(mode), - batch, - ( - f"{_microseconds(baseline_median)} ± " - f"{_microseconds(baseline_mad)}" - ), - ( - f"{_microseconds(matrix_median)} ± " - f"{_microseconds(matrix_mad)}" - ), - ( - f"{_microseconds(final_median)} ± " - f"{_microseconds(final_mad)}" - ), - _ratio(matrix_median / baseline_median), - _ratio(final_ratio), - f"{(1.0 - final_ratio) * 100.0:.6g}%", - ] - ) - lines.extend( - _table( - ( - "Model", - "Workload", - "Mode", - "Batch", - "Frozen pre-Arena median ± MAD", - "168-cell Arena median ± MAD", - "Final M0 Arena median ± MAD", - "Matrix Arena / pre-Arena", - "Final Arena / pre-Arena", - "Final relative gain", - ), - rows, - ) - ) - lines.extend( - [ - "", - ( - "A final relative gain is positive when the final Arena runtime is " - "faster than the frozen pre-Arena baseline." - ), - ] - ) - return lines - - -def _amplicol_round_values(evidence: Any) -> dict[int, float]: - timing = _mapping(evidence.timing, "AmpliCol timing") - values = _list( - timing.get("raw_seconds_per_point"), - "AmpliCol raw seconds per point", - ) - records = list(evidence.interleave_records) - if len(values) != len(records): - _die("AmpliCol timing values and interleave records differ in length") - result: dict[int, float] = {} - for value, record in zip(values, records, strict=True): - round_index = _integer(record.get("round"), "AmpliCol interleave round") - if round_index in result: - _die(f"AmpliCol workload repeats round {round_index}") - result[round_index] = _number( - value, - f"AmpliCol round {round_index} timing", - positive=True, - ) - return result - - -def _amplicol_sections(evidence: Evidence) -> list[str]: - lines = [ - "## Original AmpliCol comparison", - "", - ( - "The original-AmpliCol selected-flow and all-flow measurements were " - "captured as seven chronological selected-then-union subprocess pairs. " - "They use different internal timing boundaries from pyAmpliCol, shown " - "explicitly below." - ), - "", - ] - external_rows: list[list[object]] = [] - role_order = ( - evidence.m0.AMPLICOL_SELECTED_ROLE, - evidence.m0.AMPLICOL_UNION_ROLE, - ) - for role in role_order: - timing = _mapping(evidence.amplicol[role].timing, f"AmpliCol {role} timing") - external_rows.append( - [ - role, - timing.get("timing_boundary"), - _microseconds( - _number( - timing.get("median_seconds_per_point"), - f"AmpliCol {role} median", - positive=True, - ) - ), - _microseconds( - _number( - timing.get("mad_seconds_per_point"), - f"AmpliCol {role} MAD", - nonnegative=True, - ) - ), - _integer( - timing.get("sample_count"), - f"AmpliCol {role} samples", - minimum=evidence.m0.MIN_SAMPLES, - ), - ] - ) - lines.extend( - _table( - ("Workload", "Timing boundary", "Median", "Raw MAD", "Subprocesses"), - external_rows, - ) - ) - selected_rounds = _amplicol_round_values(evidence.amplicol[role_order[0]]) - union_rounds = _amplicol_round_values(evidence.amplicol[role_order[1]]) - if set(selected_rounds) != set(union_rounds): - _die("original-AmpliCol selected/union paired rounds differ") - selected_over_union = [ - selected_rounds[index] / union_rounds[index] - for index in sorted(selected_rounds) - ] - ratio_median = statistics.median(selected_over_union) - ratio_mad = statistics.median( - abs(value - ratio_median) for value in selected_over_union - ) - lines.extend( - [ - "", - ( - f"Same-round original selected/union ratio: " - f"**{_ratio(ratio_median)} ± {_ratio(ratio_mad)} raw MAD** " - f"across {len(selected_over_union)} paired rounds." - ), - "", - "### pyAmpliCol median / original-AmpliCol median", - "", - ] - ) - comparison_rows: list[list[object]] = [] - for layout, role in ( - ("topology-replay", role_order[0]), - ("all-flow-union", role_order[1]), - ): - amplicol_median = _number( - evidence.amplicol[role].timing["median_seconds_per_point"], - "AmpliCol comparison median", - positive=True, - ) - for model in evidence.m0.MODELS: - capture = evidence.captures[(model, layout)] - for mode in evidence.m0.MODES: - for batch in evidence.m0.BATCHES: - py_median = _number( - capture.timings[mode][str(batch)]["median_seconds_per_point"], - "pyAmpliCol comparison median", - positive=True, - ) - comparison_rows.append( - [ - _layout_label(layout), - _model_label(model), - _mode_label(mode), - batch, - _ratio(py_median / amplicol_median), - "runtime-core wall / " - + evidence.amplicol[role].timing["timing_boundary"], - ] - ) - lines.extend( - _table( - ( - "Workload", - "Model", - "Mode", - "Batch", - "pyAmpliCol / AmpliCol", - "Boundary pairing", - ), - comparison_rows, - ) - ) - return lines - - -def render_markdown(evidence: Evidence) -> str: - """Render deterministic Markdown from already revalidated evidence.""" - - first = evidence.captures[("built-in-sm", "topology-replay")] - host = _mapping(first.host, "capture host") - color_axis = first.color_axis - helicity_axis = first.helicity_axis - lines: list[str] = [ - ( - "" - ), - "", - "# Final qq → Z + 6g Arena comparison", - "", - ( - "Status: **accepted** by the strict combined M0 gate. This document " - "contains no benchmark values that were not present in the authenticated " - "capture set or deterministically recomputed from its raw samples." - ), - "", - "## Scope and workload semantics", - "", - f"- Process: `{evidence.m0.PROCESS}`.", - ( - f"- Physical axes retained in every artifact: " - f"{_integer(color_axis.get('count'), 'color-flow count', minimum=1)} " - f"LC flows and " - f"{_integer(helicity_axis.get('count'), 'helicity count', minimum=1)} " - "helicity configurations." - ), - ( - f"- Selected-flow workload: runtime flow " - f"`{evidence.expected['color_flow']['id']}` with a complete helicity sum." - ), - ( - f"- Union workload: all physical LC flows with runtime helicity " - f"`{evidence.expected['helicity']['id']}`." - ), - ( - "- All four captures retain complete flow/helicity axes and have no " - "generation-specialized axes." - ), - ( - "- Compiled means the compiled DAG with effective JIT O3. Eager and " - "recurrence are separate runtime engines over the same authenticated " - "physics/model contracts." - ), - "", - "### LC/NLC/full-color boundary", - "", - ( - "**The all-flow union evidence here is LC-only.** It sums all physical " - "LC flows for one runtime-selected helicity. NLC and full-color modes use " - "contracted color evaluation and are outside this M0 capture set; no " - "NLC/full runtime number or union equivalence is inferred from these LC " - "measurements." - ), - "", - "## Evidence and identities", - "", - "### Content-addressed inputs", - "", - ] - lines.extend( - _table( - ("Logical evidence", "Raw file SHA-256", "Canonical/content SHA-256"), - _capture_input_rows(evidence), - ) - ) - lines.extend(["", "### pyAmpliCol source and runtime", ""]) - lines.extend(_table(("Identity", "Value"), _runtime_identity_rows(evidence))) - lines.extend(["", "### Frozen pre-Arena matrix and runtime", ""]) - lines.extend(_table(("Identity", "Value"), _pre_arena_identity_rows(evidence))) - lines.extend(["", "### Original AmpliCol source and compiler", ""]) - lines.extend(_table(("Identity", "Value"), _original_identity_rows(evidence))) - lines.extend(["", "### Host", ""]) - lines.extend( - _table( - ("Field", "Value"), - ( - ("Platform", host.get("platform")), - ("System/release", f"{host.get('system')} {host.get('release')}"), - ("Machine", host.get("machine")), - ("CPU model", host.get("cpu_model")), - ("Logical CPUs", host.get("logical_cpu_count")), - ), - ) - ) - lines.extend(["", "### Model identities", ""]) - lines.extend( - _table( - ("Model", "Common physics SHA-256", "Generation-model SHA-256"), - [ - [ - _model_label(model), - _digest( - evidence.expected["model_common_physics_identity_sha256"][model] - ), - _digest( - evidence.expected["generation_model_identities_sha256"][model] - ), - ] - for model in evidence.m0.MODELS - ], - ) - ) - lines.extend(["", *_numerical_sections(evidence)]) - lines.extend(["", *_generation_sections(evidence)]) - lines.extend(["", *_runtime_sections(evidence)]) - lines.extend(["", *_pre_arena_comparison_sections(evidence)]) - lines.extend(["", *_amplicol_sections(evidence)]) - lines.extend( - [ - "", - "## Methodology and interpretation caveats", - "", - ( - "- Runtime cells use at least seven independent worker subprocesses. " - "Each worker retains native wall blocks; the headline statistic is " - "the median of subprocess wall-seconds-per-point values and its raw " - "MAD." - ), - ( - "- Same-round ratios divide paired subprocess measurements before " - "taking the ratio median/MAD. A ratio below one favors the numerator." - ), - ( - "- Frozen pre-Arena comparisons are cross-campaign median ratios, " - "not same-round ratios; the table retains the raw MAD for every " - "campaign instead of constructing a synthetic paired uncertainty." - ), - ( - "- Batch sizes 1, 128, and 1024 are API/runtime batching choices; all " - "reported values remain normalized per evaluated physical point." - ), - ( - "- Generation timings, artifact sizes, and generation RSS are not " - "steady-state runtime measurements. Generation RSS is a high-water " - "lower bound, not an aggregate process-tree sample." - ), - ( - "- Original-AmpliCol and pyAmpliCol timing boundaries differ. Their " - "ratios are reported for transparency, not presented as identical " - "microbenchmark boundaries." - ), - ( - "- Zero or unavailable evaluator-attribution, cold-load, traffic, or " - "allocation fields are not substituted with estimates. The headline " - "runtime tables use retained wall-time evidence only." - ), - ( - f"- Numerical acceptance used relative tolerance " - f"`{evidence.m0.RTOL:.17g}` and absolute tolerance " - f"`{evidence.m0.ATOL:.17g}`." - ), - "", - ] - ) - return "\n".join(lines) - - -def _write_atomic(path: Path, text: str) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp") - try: - temporary.write_text(text, encoding="utf-8") - os.replace(temporary, path) - finally: - with contextlib.suppress(FileNotFoundError): - temporary.unlink() - - -def generate( - *, - request_path: Path, - request_sha256: str, - acceptance_path: Path, - acceptance_sha256: str, - expected_source_revision: str, - expected_runtime_provenance_sha256: str, - pre_arena_manifest_path: Path, - pre_arena_manifest_sha256: str, - expected_pre_arena_source_revision: str, - expected_pre_arena_build_sha256: str, - expected_pre_arena_runtime_sha256: str, - output_path: Path, -) -> str: - evidence = validate_evidence( - request_path=request_path, - request_sha256=request_sha256, - acceptance_path=acceptance_path, - acceptance_sha256=acceptance_sha256, - expected_source_revision=expected_source_revision, - expected_runtime_provenance_sha256=expected_runtime_provenance_sha256, - pre_arena_manifest_path=pre_arena_manifest_path, - pre_arena_manifest_sha256=pre_arena_manifest_sha256, - expected_pre_arena_source_revision=expected_pre_arena_source_revision, - expected_pre_arena_build_sha256=expected_pre_arena_build_sha256, - expected_pre_arena_runtime_sha256=expected_pre_arena_runtime_sha256, - ) - markdown = render_markdown(evidence) - _write_atomic(output_path, markdown) - return hashlib.sha256(markdown.encode("utf-8")).hexdigest() - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - result.add_argument("--request", type=Path, required=True) - result.add_argument("--request-sha256", required=True) - result.add_argument("--acceptance", type=Path, required=True) - result.add_argument("--acceptance-sha256", required=True) - result.add_argument("--expected-source-revision", required=True) - result.add_argument("--expected-runtime-provenance-sha256", required=True) - result.add_argument("--pre-arena-manifest", type=Path, required=True) - result.add_argument("--pre-arena-manifest-sha256", required=True) - result.add_argument("--expected-pre-arena-source-revision", required=True) - result.add_argument("--expected-pre-arena-build-sha256", required=True) - result.add_argument("--expected-pre-arena-runtime-sha256", required=True) - result.add_argument( - "--output", - type=Path, - default=DEFAULT_OUTPUT, - help=f"Markdown output (default: {DEFAULT_OUTPUT})", - ) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - try: - markdown_sha256 = generate( - request_path=arguments.request, - request_sha256=arguments.request_sha256, - acceptance_path=arguments.acceptance, - acceptance_sha256=arguments.acceptance_sha256, - expected_source_revision=arguments.expected_source_revision, - expected_runtime_provenance_sha256=( - arguments.expected_runtime_provenance_sha256 - ), - pre_arena_manifest_path=arguments.pre_arena_manifest, - pre_arena_manifest_sha256=arguments.pre_arena_manifest_sha256, - expected_pre_arena_source_revision=( - arguments.expected_pre_arena_source_revision - ), - expected_pre_arena_build_sha256=(arguments.expected_pre_arena_build_sha256), - expected_pre_arena_runtime_sha256=( - arguments.expected_pre_arena_runtime_sha256 - ), - output_path=arguments.output, - ) - except Exception as error: - print(f"qq_Z6g comparison rejected: {error}", file=sys.stderr) - return 2 - print( - json.dumps( - { - "output": str(arguments.output), - "markdown_sha256": markdown_sha256, - }, - sort_keys=True, - ) - ) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/pyamplicol/tools/developer/rebuild_rusticol.py b/pyamplicol/tools/developer/rebuild_rusticol.py deleted file mode 100644 index 7e17c0c7f2..0000000000 --- a/pyamplicol/tools/developer/rebuild_rusticol.py +++ /dev/null @@ -1,279 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Rebuild and restage only Rusticol for a candidate source checkout.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import os -import shutil -import stat -import subprocess -import sys -import tempfile -import zipfile -from pathlib import Path - -ROOT = Path(__file__).resolve().parents[2] -SOURCE_PACKAGE = ROOT / "src" / "pyamplicol" -SOURCE_RUNTIME_INFO = ROOT / ".artifacts" / "source-runtime" / "_build_info.json" -RUSTICOL_MANIFEST = Path("rust/crates/rusticol-python/Cargo.toml") -NATIVE_SUFFIXES = (".dylib", ".pyd", ".so") - -sys.path.insert(0, str(ROOT)) -sys.path.insert(0, str(ROOT / "build_backend")) -import _pyamplicol_build as build_backend # noqa: E402 - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--python", - type=Path, - default=ROOT / ".venv" / "bin" / "python", - ) - parser.add_argument( - "--maturin", - type=Path, - default=ROOT / ".venv" / "bin" / "maturin", - ) - parser.add_argument( - "--cargo-test", - action="append", - default=[], - metavar="FILTER", - help="run a rusticol-core test filter in the contributor overlay", - ) - parser.add_argument( - "--test-only", - action="store_true", - help="run requested cargo tests without rebuilding the extension", - ) - return parser - - -def _read_candidate_info() -> dict[str, object]: - try: - payload = json.loads(SOURCE_RUNTIME_INFO.read_text(encoding="utf-8")) - except (OSError, TypeError, ValueError) as error: - raise RuntimeError( - "candidate source-runtime metadata is unavailable; " - "run `just dev-install` once" - ) from error - if not isinstance(payload, dict) or payload.get("publishable") is not False: - raise RuntimeError("Rusticol-only rebuilds require a staged candidate runtime") - version = payload.get("version") - if not isinstance(version, str) or not version: - raise RuntimeError("candidate source-runtime metadata has no package version") - return payload - - -def _native_extension() -> Path: - extensions = sorted( - path - for path in SOURCE_PACKAGE.glob("_rusticol.*") - if path.is_file() and path.name.endswith(NATIVE_SUFFIXES) - ) - if len(extensions) != 1: - raise RuntimeError( - f"expected one staged Rusticol extension, found {len(extensions)}" - ) - return extensions[0] - - -def _wheel_extension(wheel: Path) -> tuple[str, bytes, int]: - with zipfile.ZipFile(wheel) as archive: - candidates = [ - info - for info in archive.infolist() - if info.filename.startswith("pyamplicol/_rusticol.") - and info.filename.endswith(NATIVE_SUFFIXES) - ] - if len(candidates) != 1: - raise RuntimeError( - f"expected one Rusticol extension in {wheel}, found {len(candidates)}" - ) - info = candidates[0] - return Path(info.filename).name, archive.read(info), info.external_attr >> 16 - - -def _install_extension(wheel: Path) -> Path: - name, payload, mode = _wheel_extension(wheel) - destination = SOURCE_PACKAGE / name - with tempfile.NamedTemporaryFile( - dir=SOURCE_PACKAGE, - prefix=f".{name}.", - delete=False, - ) as stream: - temporary = Path(stream.name) - stream.write(payload) - try: - temporary.chmod(mode or 0o755) - os.replace(temporary, destination) - finally: - temporary.unlink(missing_ok=True) - for stale in SOURCE_PACKAGE.glob("_rusticol.*"): - if stale != destination and stale.name.endswith(NATIVE_SUFFIXES): - stale.unlink() - return destination - - -def _stage_untracked_source(overlay: Path) -> None: - completed = subprocess.run( - [ - "git", - "ls-files", - "--others", - "--exclude-standard", - "-z", - "--", - ], - cwd=ROOT, - check=True, - capture_output=True, - ) - for raw in completed.stdout.split(b"\0"): - if not raw: - continue - relative = Path(os.fsdecode(raw)) - if ( - relative.is_absolute() - or ".." in relative.parts - or not build_backend._is_allowlisted(relative) - or build_backend._is_excluded(relative) - ): - continue - source = ROOT / relative - mode = source.lstat().st_mode - if not stat.S_ISREG(mode): - raise RuntimeError(f"untracked build input is not a regular file: {source}") - target = overlay / relative - target.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(source, target, follow_symlinks=False) - - -def _publish_info( - payload: dict[str, object], - *, - extension: Path, - native_digest: str, -) -> None: - payload["native_build_inputs_sha256"] = native_digest - payload["source_runtime"] = { - "extension_name": extension.name, - "extension_sha256": hashlib.sha256(extension.read_bytes()).hexdigest(), - "mode": "candidate", - "native_build_inputs_sha256": native_digest, - } - SOURCE_RUNTIME_INFO.parent.mkdir(parents=True, exist_ok=True) - temporary = SOURCE_RUNTIME_INFO.with_name( - f".{SOURCE_RUNTIME_INFO.name}.rusticol-{os.getpid()}" - ) - temporary.write_text( - json.dumps(payload, indent=2, sort_keys=True) + "\n", - encoding="utf-8", - ) - os.replace(temporary, SOURCE_RUNTIME_INFO) - - -def main() -> int: - args = _parser().parse_args() - _read_candidate_info() - with build_backend._overlay("candidate") as (overlay, _): - _stage_untracked_source(overlay) - target = ROOT / ".artifacts" / "rusticol-rebuild" / "target" - payload = json.loads( - (overlay / "src" / "pyamplicol" / "_build_info.json").read_text( - encoding="utf-8" - ) - ) - native_digest = str(payload["native_build_inputs_sha256"]) - environment = build_backend._clean_environment( - { - "CARGO_TARGET_DIR": str(target), - "PYAMPLICOL_NATIVE_BUILD_INPUTS_SHA256": native_digest, - "PYAMPLICOL_PACKAGE_VERSION": str(payload["version"]), - } - ) - for test_filter in args.cargo_test: - subprocess.run( - [ - "cargo", - "test", - "--release", - "--locked", - "--offline", - "--manifest-path", - str(overlay / "rust" / "crates" / "rusticol-core" / "Cargo.toml"), - test_filter, - ], - cwd=overlay, - env=environment, - check=True, - ) - if args.test_only: - if not args.cargo_test: - raise RuntimeError("--test-only requires at least one --cargo-test") - return 0 - with tempfile.TemporaryDirectory(prefix="pyamplicol-rusticol-wheel-") as raw: - wheel_directory = Path(raw) - subprocess.run( - [ - str(args.maturin), - "build", - "--release", - "--locked", - "--offline", - "--manifest-path", - str(overlay / RUSTICOL_MANIFEST), - "--features", - "extension-module,numpy", - "--interpreter", - str(args.python), - "--out", - str(wheel_directory), - ], - cwd=overlay, - env=environment, - check=True, - ) - wheels = sorted(wheel_directory.glob("*.whl")) - if len(wheels) != 1: - raise RuntimeError(f"expected one Rusticol wheel, found {len(wheels)}") - extension = _install_extension(wheels[0]) - subprocess.run( - [ - str(args.python), - "-m", - "pip", - "install", - "--force-reinstall", - "--no-deps", - str(wheels[0]), - ], - cwd=ROOT, - check=True, - ) - _publish_info(payload, extension=extension, native_digest=native_digest) - subprocess.run( - [ - str(args.python), - "-c", - ( - "from pyamplicol import _rusticol; " - "from pyamplicol._internal.versions import verify_native_module; " - "verify_native_module(_rusticol); " - "print(_rusticol.package_version(), " - "_rusticol.native_build_inputs_sha256())" - ), - ], - cwd=ROOT, - check=True, - ) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/recurrence_numerical_ab_parity.py b/pyamplicol/tools/developer/recurrence_numerical_ab_parity.py deleted file mode 100644 index ed8adc0d42..0000000000 --- a/pyamplicol/tools/developer/recurrence_numerical_ab_parity.py +++ /dev/null @@ -1,2144 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Validate recurrence numerical parity across a frozen baseline and candidate. - -The acceptance matrix is deliberately fixed: - -* ``d d~ > Z g g g g``; -* ``d d~ > t t~ g g g``; -* ``g g > g g g g``; -* LC ``topology-replay`` and ``all-flow-union`` for every process. - -Each baseline/candidate capture runs in its own process tree under the audited -30 GiB watchdog. The worker reuses the recurrence benchmark's source/runtime -provenance, generation configuration, artifact semantic identity, deterministic -validation fixture, and loaded-artifact verification. It does not run timing -loops: it loads the generated artifact once and records selected totals plus -every selected resolved component through the public runtime API. - -This is developer-only validation tooling. It does not alter a public API, -CLI, artifact schema, or recurrence ABI. -""" - -from __future__ import annotations - -import argparse -import datetime as dt -import hashlib -import json -import math -import os -import signal -import subprocess -import sys -import time -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -DRIVER_PATH = Path(__file__).resolve() -DRIVER_ROOT = DRIVER_PATH.parents[2] -if str(DRIVER_ROOT) not in sys.path: - sys.path.insert(0, str(DRIVER_ROOT)) - -from tools.developer import recurrence_generation_ab_ladder as ladder # noqa: E402 -from tools.developer import recurrence_z6g_benchmark as harness # noqa: E402 - -RESULT_KIND = "pyamplicol-recurrence-numerical-ab-parity" -RESULT_SCHEMA = 1 -CAPTURE_KIND = "pyamplicol-recurrence-numerical-parity-capture" -CAPTURE_SCHEMA = 1 -COMPARISON_KIND = "pyamplicol-recurrence-numerical-parity-comparison" -COMPARISON_SCHEMA = 1 -ALLOWED_OUTPUT_PARENT = ( - DRIVER_ROOT / ".artifacts" / "recurrence-generation-opt" -).resolve() -WATCHDOG_PATH = DRIVER_ROOT / "tools" / "ci" / "memory_watchdog.py" -SOURCE_CHECKOUT_ENV = "PYAMPLICOL_RECURRENCE_Z6G_SOURCE_CHECKOUT" -WATCHDOG_LIMIT_GIB = 30.0 -ABSOLUTE_TOLERANCE = 1.0e-15 -RELATIVE_TOLERANCE = 1.0e-12 -DEFAULT_VALIDATION_SAMPLES = 10 -DEFAULT_POINT_TILE_SIZE = 1024 -DEFAULT_JIT_OPTIMIZATION_LEVEL = 2 -DEFAULT_WORKER_TIMEOUT_SECONDS = 2.0 * 60.0 * 60.0 -LAYOUTS = ("topology-replay", "all-flow-union") -PROCESS_CASES = ( - ("dd_z_4g", "d d~ > Z g g g g"), - ("dd_tt_3g", "d d~ > t t~ g g g"), - ("gg_4g", "g g > g g g g"), -) -EXPECTED_SOURCE_REVISIONS = { - "baseline": "172e58fd33a3c65563866c50cfbb5e1ddcd7b302", - "candidate": "4e2b1e02dddde2d55b7250cbd52a93001f09b2c2", -} -_SHA256_LENGTH = 64 -_SHA256_DIGITS = frozenset("0123456789abcdef") - - -class ParityError(RuntimeError): - """Raised when numerical parity evidence is incomplete or invalid.""" - - -@dataclass(frozen=True, slots=True) -class Variant: - """One source-bound installed pyAmpliCol runtime.""" - - name: str - python: Path - checkout: Path - pythonpath: Path - prepared_model: Path - - -@dataclass(frozen=True, slots=True) -class ProcessOutcome: - """One watchdog-guarded capture process outcome.""" - - exit_code: int | None - timed_out: bool - wall_seconds: float - error: str | None - - -def _utc_now() -> str: - return dt.datetime.now(dt.UTC).isoformat().replace("+00:00", "Z") - - -def _canonical_json(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ).encode("utf-8") - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_json(value)).hexdigest() - - -def _is_sha256(value: object) -> bool: - return ( - isinstance(value, str) - and len(value) == _SHA256_LENGTH - and all(character in _SHA256_DIGITS for character in value) - ) - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _path_identity(path: Path) -> dict[str, object]: - resolved = path.resolve(strict=True) - return { - "path": str(resolved), - "resolved_path": str(resolved), - "size_bytes": resolved.stat().st_size, - "sha256": _sha256_file(resolved), - } - - -def _content_address(value: Mapping[str, object]) -> dict[str, object]: - result = dict(value) - if "content_sha256" in result: - raise ParityError("content-addressed record already contains a digest") - result["content_sha256"] = _canonical_sha256(result) - return result - - -def _validate_content_address( - value: object, - *, - kind: str, - schema_version: int, - label: str, -) -> dict[str, Any]: - if not isinstance(value, Mapping): - raise ParityError(f"{label} is not an object") - result = dict(value) - digest = result.pop("content_sha256", None) - if ( - value.get("kind") != kind - or isinstance(value.get("schema_version"), bool) - or not isinstance(value.get("schema_version"), int) - or value.get("schema_version") != schema_version - or not _is_sha256(digest) - or digest != _canonical_sha256(result) - ): - raise ParityError(f"{label} failed its content-address contract") - return dict(value) - - -def _atomic_write_json(path: Path, value: object) -> None: - if path.exists(): - raise ParityError(f"refusing to replace existing evidence: {path}") - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - try: - temporary.write_text( - json.dumps(value, allow_nan=False, indent=2, sort_keys=True) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - except (OSError, TypeError, ValueError) as error: - temporary.unlink(missing_ok=True) - raise ParityError(f"cannot write evidence JSON: {path}") from error - - -def _json_object(path: Path, *, label: str) -> dict[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise ParityError(f"cannot read {label}: {path}") from error - if not isinstance(value, dict): - raise ParityError(f"{label} must contain one object") - return value - - -def _normalized_process(value: str) -> str: - return " ".join(value.split()).casefold() - - -def _validate_process_case(process_key: str, process_expression: str) -> None: - if not any( - process_key == expected_key - and _normalized_process(process_expression) - == _normalized_process(expected_expression) - for expected_key, expected_expression in PROCESS_CASES - ): - raise ParityError("process is outside the fixed numerical-parity matrix") - - -def _positive_int(value: str) -> int: - parsed = int(value) - if parsed <= 0: - raise argparse.ArgumentTypeError("must be a positive integer") - return parsed - - -def _positive_float(value: str) -> float: - parsed = float(value) - if not math.isfinite(parsed) or parsed <= 0.0: - raise argparse.ArgumentTypeError("must be a positive finite number") - return parsed - - -def _resolve_inside_workspace( - path: Path, - *, - label: str, - regular_file: bool | None = None, -) -> Path: - try: - resolved = path.expanduser().resolve(strict=True) - resolved.relative_to(DRIVER_ROOT.resolve()) - except (OSError, ValueError) as error: - raise ParityError(f"{label} must exist inside the workspace: {path}") from error - if regular_file is True and not resolved.is_file(): - raise ParityError(f"{label} is not a regular file: {resolved}") - if regular_file is False and not resolved.is_dir(): - raise ParityError(f"{label} is not a directory: {resolved}") - return resolved - - -def _resolve_python_inside_workspace(path: Path, *, label: str) -> Path: - """Retain a workspace interpreter symlink whose target may be external.""" - - absolute = Path(os.path.abspath(path.expanduser())) - try: - absolute.relative_to(DRIVER_ROOT.resolve()) - absolute.parent.resolve(strict=True).relative_to(DRIVER_ROOT.resolve()) - except (OSError, ValueError) as error: - raise ParityError(f"{label} must exist inside the workspace: {path}") from error - if not absolute.is_file(): - raise ParityError(f"{label} is not a regular file: {absolute}") - return absolute - - -def _resolve_output_root(path: Path) -> Path: - requested = path.expanduser().resolve() - try: - requested.relative_to(ALLOWED_OUTPUT_PARENT) - except ValueError as error: - raise ParityError( - f"output root must remain below {ALLOWED_OUTPUT_PARENT}" - ) from error - if requested == ALLOWED_OUTPUT_PARENT: - raise ParityError("output root must be a child of the artifact parent") - if requested.exists(): - raise ParityError(f"output root already exists: {requested}") - return requested - - -def _variant( - name: str, - *, - python: Path, - checkout: Path, - pythonpath: Path, - prepared_model: Path, -) -> Variant: - return Variant( - name=name, - python=_resolve_python_inside_workspace(python, label=f"{name} Python"), - checkout=_resolve_inside_workspace( - checkout, - label=f"{name} checkout", - regular_file=False, - ), - pythonpath=_resolve_inside_workspace( - pythonpath, - label=f"{name} Python path", - regular_file=False, - ), - prepared_model=_resolve_inside_workspace( - prepared_model, - label=f"{name} prepared model", - regular_file=True, - ), - ) - - -def _git_stdout(checkout: Path, *arguments: str, label: str) -> str: - environment = os.environ.copy() - environment["GIT_OPTIONAL_LOCKS"] = "0" - completed = subprocess.run( - ("git", *arguments), - cwd=checkout, - env=environment, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - detail = completed.stderr.strip() - raise ParityError( - f"cannot inspect {label} checkout" + ("" if not detail else f": {detail}") - ) - return completed.stdout.strip() - - -def _preflight_variant_source(variant: Variant) -> dict[str, object]: - expected_revision = EXPECTED_SOURCE_REVISIONS.get(variant.name) - if expected_revision is None: - raise ParityError(f"no expected revision is pinned for {variant.name}") - checkout = variant.checkout.resolve() - top_level = _git_stdout( - checkout, - "rev-parse", - "--show-toplevel", - label=variant.name, - ) - revision = _git_stdout( - checkout, - "rev-parse", - "--verify", - "HEAD", - label=variant.name, - ) - status = _git_stdout( - checkout, - "status", - "--porcelain=v1", - "--untracked-files=all", - label=variant.name, - ) - if Path(top_level).resolve() != checkout: - raise ParityError(f"{variant.name} checkout is not its Git worktree root") - if revision != expected_revision: - raise ParityError( - f"{variant.name} revision is {revision}, expected {expected_revision}" - ) - if status: - raise ParityError(f"{variant.name} checkout is dirty before the campaign") - return { - "checkout": str(checkout), - "revision": revision, - "dirty": False, - "untracked_files_checked": True, - } - - -def _complex_payload(value: complex) -> list[float]: - if not math.isfinite(value.real) or not math.isfinite(value.imag): - raise ParityError("runtime returned a non-finite complex value") - return [float(value.real), float(value.imag)] - - -def _complex_value(value: object, *, label: str) -> complex: - if ( - not isinstance(value, list) - or len(value) != 2 - or any( - isinstance(component, bool) - or not isinstance(component, (float, int)) - or not math.isfinite(float(component)) - for component in value - ) - ): - raise ParityError(f"{label} is not a finite complex pair") - return complex(float(value[0]), float(value[1])) - - -def _value_comparison( - baseline: object, - candidate: object, - *, - absolute_tolerance: float = ABSOLUTE_TOLERANCE, - relative_tolerance: float = RELATIVE_TOLERANCE, -) -> dict[str, object]: - baseline_value = _complex_value(baseline, label="baseline value") - candidate_value = _complex_value(candidate, label="candidate value") - absolute = abs(candidate_value - baseline_value) - relative = absolute / max( - abs(baseline_value), - abs(candidate_value), - 1.0e-300, - ) - return { - "baseline": _complex_payload(baseline_value), - "candidate": _complex_payload(candidate_value), - "absolute_difference": absolute, - "relative_difference": relative, - "absolute_tolerance": absolute_tolerance, - "relative_tolerance": relative_tolerance, - "passes": (absolute <= absolute_tolerance or relative <= relative_tolerance), - } - - -def _axis_ids(values: Sequence[object], *, label: str) -> list[str]: - result = [getattr(value, "id", None) for value in values] - if ( - not result - or any(not isinstance(value, str) or not value for value in result) - or len(set(result)) != len(result) - ): - raise ParityError(f"runtime exposes an invalid {label} axis") - return [str(value) for value in result] - - -def _select_workload( - physics: object, - *, - layout: str, -) -> tuple[dict[str, tuple[str, ...]], dict[str, object]]: - color_flows = tuple(getattr(physics, "color_flows", ())) - helicities = tuple(getattr(physics, "helicities", ())) - color_ids = _axis_ids(color_flows, label="color-flow") - helicity_ids = _axis_ids(helicities, label="helicity") - structural_zero_ids = [ - str(helicity.id) - for helicity in helicities - if getattr(helicity, "structural_zero", False) is True - ] - if layout == "topology-replay": - selected_color_id = color_ids[0] - selectors = {"color_flows": (selected_color_id,)} - contract = { - "workload": "single-runtime-selected-flow/helicity-sum", - "physical_color_ids": color_ids, - "physical_helicity_ids": helicity_ids, - "structural_zero_helicity_ids": structural_zero_ids, - "selected_color_flow_ids": [selected_color_id], - "selected_helicity_ids": [], - } - elif layout == "all-flow-union": - selected_helicity_id = next( - ( - helicity_id - for helicity_id in helicity_ids - if helicity_id not in set(structural_zero_ids) - ), - None, - ) - if selected_helicity_id is None: - raise ParityError("runtime exposes no non-structural-zero helicity") - selectors = {"helicities": (selected_helicity_id,)} - contract = { - "workload": "all-flows/runtime-selected-single-helicity", - "physical_color_ids": color_ids, - "physical_helicity_ids": helicity_ids, - "structural_zero_helicity_ids": structural_zero_ids, - "selected_color_flow_ids": [], - "selected_helicity_ids": [selected_helicity_id], - } - else: - raise ParityError(f"unsupported LC flow layout: {layout}") - contract["contract_sha256"] = _canonical_sha256(contract) - return selectors, contract - - -def _parameters_identity(artifact: Path) -> dict[str, object]: - path = artifact / "model" / "parameters.json" - payload = _json_object(path, label="artifact parameter payload") - return { - "file": _path_identity(path), - "payload": payload, - "payload_sha256": _canonical_sha256(payload), - } - - -def _generation_arguments(arguments: argparse.Namespace) -> argparse.Namespace: - return argparse.Namespace( - mode="recurrence", - artifact=arguments.artifact, - prepared_model=arguments.prepared_model, - process_expression=arguments.process_expression, - gluon_count=1, - validation_samples=arguments.validation_samples, - point_tile_size=arguments.point_tile_size, - jit_optimization_level=arguments.jit_optimization_level, - lc_flow_layout=arguments.layout, - specialize_flow_at_generation=False, - color_flow="1", - helicity="1", - write_mode="error", - ) - - -def _generation_request( - *, - validation_samples: int, - point_tile_size: int, - jit_optimization_level: int, -) -> dict[str, object]: - return { - "validation_samples": validation_samples, - "validation_seed": harness.VALIDATION_SEED, - "point_tile_size": point_tile_size, - "jit_optimization_level": jit_optimization_level, - "specialize_flow_at_generation": False, - } - - -def _capture_validation( - runtime: object, - *, - artifact: Path, - process_id: str, - layout: str, -) -> dict[str, object]: - points, fixture = harness._validation_fixture(artifact, process_id) - if not points: - raise ParityError("generated artifact contains no validation points") - selectors, selector_contract = _select_workload( - runtime.physics, - layout=layout, - ) - selected = tuple(complex(value) for value in runtime.evaluate(points, **selectors)) - resolved = runtime.evaluate_resolved(points, **selectors) - resolved_sums = tuple(complex(value) for value in resolved.total()) - if len(selected) != len(points) or len(resolved_sums) != len(points): - raise ParityError("runtime result count disagrees with validation fixture") - point_comparisons: list[dict[str, object]] = [] - for point_index, (selected_value, resolved_value) in enumerate( - zip(selected, resolved_sums, strict=True) - ): - comparison = _value_comparison( - _complex_payload(selected_value), - _complex_payload(resolved_value), - ) - point_comparisons.append( - { - "point_index": point_index, - "selected_total": comparison["baseline"], - "resolved_sum": comparison["candidate"], - "absolute_difference": comparison["absolute_difference"], - "relative_difference": comparison["relative_difference"], - "passes": comparison["passes"], - } - ) - resolved_components = [ - [ - _complex_payload(complex(value)) - for helicity_row in point_values - for value in helicity_row - ] - for point_values in resolved.values - ] - validation: dict[str, object] = { - "fixture": { - **fixture, - "points": [[list(momentum) for momentum in point] for point in points], - }, - "selector_contract": selector_contract, - "selected_totals": [_complex_payload(value) for value in selected], - "resolved_sums": [_complex_payload(value) for value in resolved_sums], - "resolved_helicity_ids": list(resolved.helicity_ids), - "resolved_color_ids": list(resolved.color_ids), - "resolved_components": resolved_components, - "point_comparisons": point_comparisons, - "maximum_absolute_difference": max( - float(item["absolute_difference"]) for item in point_comparisons - ), - "maximum_relative_difference": max( - float(item["relative_difference"]) for item in point_comparisons - ), - "passes": all(bool(item["passes"]) for item in point_comparisons), - } - harness._validated_lane_validation_values( - validation, - fixture, - mode="recurrence", - ) - return validation - - -def _run_capture_worker(arguments: argparse.Namespace) -> dict[str, object]: - from pyamplicol import Runtime - - artifact = arguments.artifact.resolve() - capture_path = arguments.capture_json.resolve() - prepared_model_path = arguments.prepared_model.resolve(strict=True) - try: - artifact.relative_to(ALLOWED_OUTPUT_PARENT) - capture_path.relative_to(ALLOWED_OUTPUT_PARENT) - prepared_model_path.relative_to(DRIVER_ROOT.resolve()) - except ValueError as error: - raise ParityError( - "capture worker inputs and outputs must remain inside the workspace" - ) from error - if artifact.parent != capture_path.parent: - raise ParityError("capture worker artifact and evidence must share one root") - if artifact.exists() or capture_path.exists(): - raise ParityError("capture worker refuses to replace existing output") - if arguments.layout not in LAYOUTS: - raise ParityError(f"unsupported LC flow layout: {arguments.layout}") - _validate_process_case(arguments.process_key, arguments.process_expression) - - source_before = harness._git_source_identity() - runtime_before = harness._runtime_provenance(source_before) - prepared_model = _path_identity(prepared_model_path) - arguments.prepared_model = prepared_model_path - generation_arguments = _generation_arguments(arguments) - generation = harness._generate_worker(generation_arguments) - artifact_identity_before = harness._artifact_identity(artifact) - effective_contract = harness._validate_artifact_contract( - artifact, - artifact_identity_before, - arguments=generation_arguments, - mode="recurrence", - ) - - process_id = artifact_identity_before.get("process_id") - if not isinstance(process_id, str) or not process_id: - raise ParityError("generated artifact has no process identity") - runtime = Runtime.load(artifact, process=arguments.process_expression) - loaded_before = harness._loaded_runtime_artifact_verification( - runtime, - expected_artifact_id=artifact_identity_before.get("artifact_id"), - phase="before-numerical-parity-evaluation", - ) - physics = runtime.physics - observed_process = getattr(physics, "process", None) - if not isinstance(observed_process, str) or _normalized_process( - observed_process - ) != _normalized_process(arguments.process_expression): - raise ParityError("loaded runtime process disagrees with the request") - if getattr(physics, "color_accuracy", None) != "lc": - raise ParityError("loaded runtime does not expose LC physics") - - validation = _capture_validation( - runtime, - artifact=artifact, - process_id=process_id, - layout=arguments.layout, - ) - loaded_after = harness._loaded_runtime_artifact_verification( - runtime, - expected_artifact_id=artifact_identity_before.get("artifact_id"), - phase="after-numerical-parity-evaluation", - ) - artifact_identity_after = harness._artifact_identity(artifact) - source_after = harness._git_source_identity() - runtime_after = harness._runtime_provenance(source_after) - if artifact_identity_after != artifact_identity_before: - raise ParityError("artifact changed while numerical parity was evaluated") - if source_after != source_before: - raise ParityError("source checkout changed while capture was running") - if runtime_after != runtime_before: - raise ParityError("installed runtime changed while capture was running") - - capture = _content_address( - { - "kind": CAPTURE_KIND, - "schema_version": CAPTURE_SCHEMA, - "variant": arguments.variant, - "process_key": arguments.process_key, - "requested_process": arguments.process_expression, - "observed_process": observed_process, - "layout": arguments.layout, - "generation_request": _generation_request( - validation_samples=arguments.validation_samples, - point_tile_size=arguments.point_tile_size, - jit_optimization_level=arguments.jit_optimization_level, - ), - "captured_at_utc": _utc_now(), - "source": source_before, - "runtime_provenance": runtime_before, - "prepared_model": prepared_model, - "generation": generation, - "artifact": artifact_identity_before, - "effective_contract": effective_contract, - "parameters": _parameters_identity(artifact), - "loaded_artifact_verification": { - "before_evaluation": loaded_before, - "after_evaluation": loaded_after, - }, - "validation": validation, - "peak_rss_after_evaluation": harness._resource_peak(), - "tolerances": { - "absolute": ABSOLUTE_TOLERANCE, - "relative": RELATIVE_TOLERANCE, - }, - } - ) - capture = _validate_capture( - capture, - expected_variant=arguments.variant, - expected_process_key=arguments.process_key, - expected_process=arguments.process_expression, - expected_layout=arguments.layout, - expected_checkout=Path(str(source_before["checkout"])), - expected_artifact_root=artifact.parent, - expected_generation_request=_generation_request( - validation_samples=arguments.validation_samples, - point_tile_size=arguments.point_tile_size, - jit_optimization_level=arguments.jit_optimization_level, - ), - ) - _atomic_write_json(capture_path, capture) - return capture - - -def _validate_file_identity(value: object, *, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise ParityError(f"{label} file identity is missing") - path = value.get("path") - size_bytes = value.get("size_bytes") - if ( - not isinstance(path, str) - or not path - or isinstance(size_bytes, bool) - or not isinstance(size_bytes, int) - or size_bytes < 0 - or not _is_sha256(value.get("sha256")) - ): - raise ParityError(f"{label} file identity is invalid") - resolved_path = value.get("resolved_path") - if resolved_path is not None and ( - not isinstance(resolved_path, str) or not Path(resolved_path).is_absolute() - ): - raise ParityError(f"{label} resolved file identity is invalid") - return value - - -def _file_identity_paths( - value: Mapping[str, Any], - *, - label: str, -) -> tuple[Path, ...]: - raw_paths = [value.get("path")] - if "resolved_path" in value: - raw_paths.append(value.get("resolved_path")) - if any( - not isinstance(raw, str) or not Path(raw).is_absolute() for raw in raw_paths - ): - raise ParityError(f"{label} path is not absolute") - return tuple(Path(str(raw)).resolve(strict=False) for raw in raw_paths) - - -def _validate_tree_identity(value: object, *, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise ParityError(f"{label} tree identity is missing") - file_count = value.get("file_count") - size_bytes = value.get("size_bytes") - if ( - value.get("algorithm") != "sha256-relative-path-size-content-v1" - or isinstance(file_count, bool) - or not isinstance(file_count, int) - or file_count <= 0 - or isinstance(size_bytes, bool) - or not isinstance(size_bytes, int) - or size_bytes <= 0 - or not _is_sha256(value.get("sha256")) - ): - raise ParityError(f"{label} tree identity is invalid") - return value - - -def _validate_runtime_provenance_record( - value: Mapping[str, Any], - *, - source: Mapping[str, Any], -) -> None: - required = { - "interpreter", - "installed_distribution", - "active_build_info", - "native_extension", - "dependencies", - } - if not required.issubset(value): - raise ParityError("runtime provenance is incomplete") - interpreter = _validate_file_identity( - value["interpreter"], - label="runtime interpreter", - ) - native = _validate_file_identity( - value["native_extension"], - label="native extension", - ) - active = _validate_file_identity( - value["active_build_info"], - label="active build info", - ) - if ( - not isinstance(interpreter.get("python_version"), str) - or not isinstance(interpreter.get("implementation"), str) - or not isinstance(native.get("package_version"), str) - or not _is_sha256(native.get("build_inputs_sha256")) - or not isinstance(active.get("payload"), Mapping) - ): - raise ParityError("runtime executable provenance is invalid") - build_payload = active["payload"] - if ( - build_payload.get("source_checkout") != source.get("checkout") - or build_payload.get("source_revision") != source.get("revision") - or build_payload.get("native_build_inputs_sha256") - != native.get("build_inputs_sha256") - ): - raise ParityError("runtime build provenance is not source-bound") - - distribution = value["installed_distribution"] - if not isinstance(distribution, Mapping): - raise ParityError("installed distribution provenance is missing") - _validate_tree_identity( - distribution.get("distribution_content"), - label="installed distribution", - ) - native_modules = distribution.get("native_modules") - build_info_files = distribution.get("build_info_files") - if ( - not isinstance(distribution.get("package_version"), str) - or not isinstance(native_modules, list) - or not native_modules - or not isinstance(build_info_files, list) - or not build_info_files - ): - raise ParityError("installed distribution provenance is incomplete") - validated_native_modules = [ - _validate_file_identity(entry, label="installed native module") - for entry in native_modules - ] - validated_build_info = [ - _validate_file_identity(entry, label="installed build-info") - for entry in build_info_files - ] - if native.get("sha256") not in { - entry.get("sha256") for entry in validated_native_modules - } or active.get("sha256") not in { - entry.get("sha256") for entry in validated_build_info - }: - raise ParityError("active runtime files are absent from its distribution") - - dependencies = value["dependencies"] - if not isinstance(dependencies, Mapping) or not dependencies: - raise ParityError("runtime dependency provenance is missing") - for name, dependency in dependencies.items(): - if ( - not isinstance(name, str) - or not name - or not isinstance(dependency, Mapping) - or not isinstance(dependency.get("present"), bool) - or not isinstance(dependency.get("path"), str) - or not isinstance(dependency.get("resolved_path"), str) - ): - raise ParityError("runtime dependency provenance is invalid") - if dependency["present"] is True: - _validate_file_identity( - dependency, - label=f"runtime dependency {name}", - ) - - -def _validate_artifact_identity_record( - value: Mapping[str, Any], -) -> dict[str, Mapping[str, Any]]: - if ( - not isinstance(value.get("path"), str) - or not Path(str(value["path"])).is_absolute() - or not isinstance(value.get("process_id"), str) - or not value["process_id"] - or value["process_id"] in {".", ".."} - or Path(str(value["process_id"])).name != value["process_id"] - or not isinstance(value.get("producer"), Mapping) - ): - raise ParityError("artifact provenance is incomplete") - artifact_root = Path(str(value["path"])).resolve(strict=False) - manifest = _validate_file_identity( - value.get("manifest"), - label="artifact manifest", - ) - expected_manifest_path = artifact_root / "artifact.json" - if any( - path != expected_manifest_path - for path in _file_identity_paths(manifest, label="artifact manifest") - ): - raise ParityError("artifact manifest path is not bound to the artifact") - tree = _validate_tree_identity(value.get("tree"), label="artifact") - payloads = value.get("payloads") - if not isinstance(payloads, list) or not payloads: - raise ParityError("artifact payload provenance is missing") - payload_inventory: dict[str, Mapping[str, Any]] = {} - for payload in payloads: - if not isinstance(payload, Mapping): - raise ParityError("artifact payload provenance is invalid") - path = payload.get("path") - size_bytes = payload.get("size_bytes") - if ( - not isinstance(path, str) - or not path - or Path(path).is_absolute() - or ".." in Path(path).parts - or not isinstance(payload.get("role"), str) - or isinstance(size_bytes, bool) - or not isinstance(size_bytes, int) - or size_bytes < 0 - or not _is_sha256(payload.get("sha256")) - ): - raise ParityError("artifact payload provenance is invalid") - if path in payload_inventory: - raise ParityError("artifact payload provenance contains duplicate paths") - payload_inventory[path] = payload - if tree.get("file_count") != len(payload_inventory) + 1 or tree.get( - "size_bytes" - ) != int(manifest["size_bytes"]) + sum( - int(payload["size_bytes"]) for payload in payload_inventory.values() - ): - raise ParityError( - "artifact tree is not bound to manifest and payload inventory" - ) - - model_identity = value.get("model_identity") - if not isinstance(model_identity, Mapping): - raise ParityError("artifact model identity is missing") - for field, digest_field in ( - ("manifest", "manifest_sha256"), - ("common_physics_identity", "common_physics_identity_sha256"), - ): - body = model_identity.get(field) - if not isinstance(body, Mapping) or model_identity.get( - digest_field - ) != _canonical_sha256(body): - raise ParityError("artifact model identity is invalid") - return payload_inventory - - -def _validate_artifact_payload_link( - artifact: Mapping[str, Any], - payload_inventory: Mapping[str, Mapping[str, Any]], - file_identity: object, - *, - relative_path: str, - role: str, - process_id: str | None, - label: str, -) -> None: - identity = _validate_file_identity(file_identity, label=label) - artifact_root = Path(str(artifact["path"])).resolve(strict=False) - expected_path = (artifact_root / relative_path).resolve(strict=False) - payload = payload_inventory.get(relative_path) - if ( - any( - path != expected_path - for path in _file_identity_paths(identity, label=label) - ) - or not isinstance(payload, Mapping) - or payload.get("role") != role - or payload.get("process_id") != process_id - or payload.get("sha256") != identity.get("sha256") - or payload.get("size_bytes") != identity.get("size_bytes") - ): - raise ParityError(f"{label} is not bound to the artifact payload inventory") - - -def _validate_capture( - value: object, - *, - expected_variant: str, - expected_process_key: str, - expected_process: str, - expected_layout: str, - expected_checkout: Path | None = None, - expected_artifact_root: Path | None = None, - expected_generation_request: Mapping[str, object] | None = None, -) -> dict[str, Any]: - capture = _validate_content_address( - value, - kind=CAPTURE_KIND, - schema_version=CAPTURE_SCHEMA, - label=f"{expected_variant} numerical capture", - ) - source = capture.get("source") - artifact = capture.get("artifact") - effective = capture.get("effective_contract") - validation = capture.get("validation") - parameters = capture.get("parameters") - prepared = capture.get("prepared_model") - generation_request = capture.get("generation_request") - generation = capture.get("generation") - runtime_provenance = capture.get("runtime_provenance") - loaded = capture.get("loaded_artifact_verification") - semantic = ( - artifact.get("semantic_identity") if isinstance(artifact, Mapping) else None - ) - coverage = semantic.get("coverage") if isinstance(semantic, Mapping) else None - reduction_coverage = ( - semantic.get("execution_reduction_coverage") - if isinstance(semantic, Mapping) - else None - ) - model_source = ( - generation.get("model_source") if isinstance(generation, Mapping) else None - ) - if ( - capture.get("variant") != expected_variant - or capture.get("process_key") != expected_process_key - or not isinstance(capture.get("requested_process"), str) - or _normalized_process(str(capture["requested_process"])) - != _normalized_process(expected_process) - or not isinstance(capture.get("observed_process"), str) - or _normalized_process(str(capture["observed_process"])) - != _normalized_process(expected_process) - or capture.get("layout") != expected_layout - or not isinstance(generation_request, Mapping) - or set(generation_request) - != { - "validation_samples", - "validation_seed", - "point_tile_size", - "jit_optimization_level", - "specialize_flow_at_generation", - } - or isinstance(generation_request.get("validation_samples"), bool) - or not isinstance(generation_request.get("validation_samples"), int) - or int(generation_request["validation_samples"]) <= 0 - or isinstance(generation_request.get("validation_seed"), bool) - or not isinstance(generation_request.get("validation_seed"), int) - or generation_request.get("validation_seed") != harness.VALIDATION_SEED - or isinstance(generation_request.get("point_tile_size"), bool) - or not isinstance(generation_request.get("point_tile_size"), int) - or int(generation_request["point_tile_size"]) <= 0 - or isinstance(generation_request.get("jit_optimization_level"), bool) - or not isinstance(generation_request.get("jit_optimization_level"), int) - or generation_request.get("jit_optimization_level") not in {0, 1, 2, 3} - or generation_request.get("specialize_flow_at_generation") is not False - or capture.get("tolerances") - != { - "absolute": ABSOLUTE_TOLERANCE, - "relative": RELATIVE_TOLERANCE, - } - or not isinstance(source, Mapping) - or source.get("dirty") is not False - or source.get("untracked_files_checked") is not True - or not isinstance(source.get("checkout"), str) - or not Path(str(source["checkout"])).is_absolute() - or not isinstance(source.get("revision"), str) - or len(str(source["revision"])) != 40 - or any(character not in _SHA256_DIGITS for character in str(source["revision"])) - or source.get("revision") != EXPECTED_SOURCE_REVISIONS.get(expected_variant) - or not isinstance(runtime_provenance, Mapping) - or not isinstance(artifact, Mapping) - or not _is_sha256(artifact.get("artifact_id")) - or artifact.get("color_accuracy") != "lc" - or not isinstance(artifact.get("process_expression"), str) - or _normalized_process(str(artifact["process_expression"])) - != _normalized_process(expected_process) - or not isinstance(semantic, Mapping) - or artifact.get("semantic_identity_sha256") != _canonical_sha256(semantic) - or not isinstance(coverage, Mapping) - or coverage.get("complete_physical_axes") is not True - or coverage.get("color") != "complete" - or coverage.get("helicities") != "complete" - or not isinstance(reduction_coverage, Mapping) - or reduction_coverage.get("complete") is not True - or reduction_coverage.get("errors") != [] - or semantic.get("generation_specialized_axes") != [] - or not isinstance(semantic.get("runtime_selector_semantics"), Mapping) - or semantic["runtime_selector_semantics"].get("generation_specialized_axes") - != [] - or semantic["runtime_selector_semantics"]["generation_specialized_axes"] - != semantic["generation_specialized_axes"] - or not isinstance(effective, Mapping) - or effective.get("execution_mode") != "recurrence" - or effective.get("backend") != "jit" - or isinstance(effective.get("jit_optimization_level"), bool) - or effective.get("jit_optimization_level") - != harness.PREPARED_JIT_PORTABLE_OPTIMIZATION_LEVEL - or effective.get("color_accuracy") != "lc" - or effective.get("lc_flow_layout") != expected_layout - or not isinstance(validation, Mapping) - or validation.get("passes") is not True - or not isinstance(parameters, Mapping) - or not isinstance(parameters.get("payload"), Mapping) - or parameters.get("payload_sha256") != _canonical_sha256(parameters["payload"]) - or not isinstance(prepared, Mapping) - or not _is_sha256(prepared.get("sha256")) - or not isinstance(generation, Mapping) - or generation.get("mode") != "recurrence" - or generation.get("generation_reused") is not False - or generation.get("specialized_flow_word") is not None - or not isinstance(model_source, Mapping) - or model_source.get("kind") != "explicit-prepared-model" - or model_source.get("file") != prepared - or model_source.get("compile_excluded_from_generation") is not True - or not isinstance(loaded, Mapping) - ): - raise ParityError(f"{expected_variant} numerical capture is inconsistent") - _validate_runtime_provenance_record(runtime_provenance, source=source) - payload_inventory = _validate_artifact_identity_record(artifact) - _validate_file_identity(prepared, label="prepared model") - _validate_artifact_payload_link( - artifact, - payload_inventory, - parameters.get("file"), - relative_path="model/parameters.json", - role="model-parameters", - process_id=None, - label="artifact parameters", - ) - if expected_checkout is not None and source.get("checkout") != str( - expected_checkout.resolve() - ): - raise ParityError(f"{expected_variant} capture used the wrong checkout") - if expected_generation_request is not None and _canonical_sha256( - generation_request - ) != _canonical_sha256(expected_generation_request): - raise ParityError( - f"{expected_variant} capture used the wrong generation request" - ) - if expected_artifact_root is not None: - raw_artifact_path = artifact.get("path") - if not isinstance(raw_artifact_path, str): - raise ParityError(f"{expected_variant} capture has no artifact path") - if Path(raw_artifact_path).resolve() != ( - expected_artifact_root.resolve() / "artifact" - ): - raise ParityError( - f"{expected_variant} artifact is outside its assigned location" - ) - fixture = validation.get("fixture") - selector = validation.get("selector_contract") - try: - normalized_points = ( - tuple( - tuple( - tuple(float(component) for component in momentum) - for momentum in point - ) - for point in fixture.get("points", ()) - ) - if isinstance(fixture, Mapping) - else () - ) - except (TypeError, ValueError) as error: - raise ParityError( - f"{expected_variant} validation fixture is not numerical" - ) from error - if ( - not isinstance(fixture, Mapping) - or not isinstance(fixture.get("points"), list) - or isinstance(fixture.get("point_count"), bool) - or not isinstance(fixture.get("point_count"), int) - or fixture.get("point_count") != len(fixture["points"]) - or not fixture["points"] - or fixture.get("points_sha256") != _canonical_sha256(normalized_points) - or fixture.get("points_sha256") != _canonical_sha256(fixture.get("points")) - or not isinstance(selector, Mapping) - or selector.get("contract_sha256") - != _canonical_sha256( - {key: entry for key, entry in selector.items() if key != "contract_sha256"} - ) - ): - raise ParityError(f"{expected_variant} fixture or selector is invalid") - _validate_artifact_payload_link( - artifact, - payload_inventory, - fixture.get("file"), - relative_path=(f"processes/{artifact['process_id']}/validation-momenta.json"), - role="validation-momenta", - process_id=str(artifact["process_id"]), - label="validation fixture", - ) - harness._validated_lane_validation_values( - validation, - {key: entry for key, entry in fixture.items() if key != "points"}, - mode=expected_variant, - ) - harness._validate_loaded_runtime_artifact_verification( - loaded.get("before_evaluation"), - expected_artifact_id=artifact["artifact_id"], - phase="before-numerical-parity-evaluation", - ) - harness._validate_loaded_runtime_artifact_verification( - loaded.get("after_evaluation"), - expected_artifact_id=artifact["artifact_id"], - phase="after-numerical-parity-evaluation", - ) - _semantic_selector_body(capture) - _validate_selector_semantics(capture, layout=expected_layout) - return capture - - -def _semantic_selector_body(capture: Mapping[str, Any]) -> dict[str, object]: - try: - artifact = capture["artifact"] - validation = capture["validation"] - semantic = artifact["semantic_identity"] - body = { - "artifact_physical_color_flows": semantic["physical_color_flows"], - "artifact_physical_helicities": semantic["physical_helicities"], - "artifact_normalization": semantic["normalization"], - "artifact_manifest_model_identity": semantic["manifest_model_identity"], - "artifact_runtime_selector_semantics": semantic[ - "runtime_selector_semantics" - ], - "artifact_reduction_ordering": semantic["reduction_ordering"], - "artifact_execution_reduction_identity": semantic[ - "execution_reduction_identity" - ], - "artifact_generation_specialized_axes": semantic[ - "generation_specialized_axes" - ], - "runtime_selector_contract": validation["selector_contract"], - "resolved_helicity_ids": validation["resolved_helicity_ids"], - "resolved_color_ids": validation["resolved_color_ids"], - } - except (KeyError, TypeError) as error: - raise ParityError("capture has incomplete selector semantics") from error - if any(value is None for value in body.values()): - raise ParityError("capture has incomplete selector semantics") - return body - - -def _ordered_semantic_axis( - value: object, - *, - label: str, -) -> tuple[list[str], list[Mapping[str, Any]]]: - if not isinstance(value, Mapping): - raise ParityError(f"capture has no {label} semantic axis") - count = value.get("count") - ordered_ids = value.get("ordered_ids") - ordered_entries = value.get("ordered_entries") - if ( - isinstance(count, bool) - or not isinstance(count, int) - or count <= 0 - or not isinstance(ordered_ids, list) - or len(ordered_ids) != count - or any(not isinstance(entry, str) or not entry for entry in ordered_ids) - or len(set(ordered_ids)) != count - or not isinstance(ordered_entries, list) - or len(ordered_entries) != count - or any(not isinstance(entry, Mapping) for entry in ordered_entries) - or [entry.get("id") for entry in ordered_entries if isinstance(entry, Mapping)] - != ordered_ids - ): - raise ParityError(f"capture has an invalid {label} semantic axis") - return list(ordered_ids), list(ordered_entries) - - -def _validate_selector_semantics( - capture: Mapping[str, Any], - *, - layout: str, -) -> None: - semantic = capture["artifact"]["semantic_identity"] - validation = capture["validation"] - selector = validation["selector_contract"] - if set(selector) != { - "workload", - "physical_color_ids", - "physical_helicity_ids", - "structural_zero_helicity_ids", - "selected_color_flow_ids", - "selected_helicity_ids", - "contract_sha256", - }: - raise ParityError("capture selector contract has an invalid schema") - color_ids, _color_entries = _ordered_semantic_axis( - semantic.get("physical_color_flows"), - label="color-flow", - ) - helicity_ids, helicity_entries = _ordered_semantic_axis( - semantic.get("physical_helicities"), - label="helicity", - ) - structural_zero_ids = [ - str(entry["id"]) - for entry in helicity_entries - if entry.get("structural_zero") is True - ] - common_matches = ( - selector.get("physical_color_ids") == color_ids - and selector.get("physical_helicity_ids") == helicity_ids - and selector.get("structural_zero_helicity_ids") == structural_zero_ids - ) - if layout == "topology-replay": - layout_matches = ( - selector.get("workload") == "single-runtime-selected-flow/helicity-sum" - and selector.get("selected_color_flow_ids") == color_ids[:1] - and selector.get("selected_helicity_ids") == [] - and validation.get("resolved_color_ids") == color_ids[:1] - and validation.get("resolved_helicity_ids") == helicity_ids - ) - elif layout == "all-flow-union": - selected_helicity = next( - ( - helicity_id - for helicity_id in helicity_ids - if helicity_id not in set(structural_zero_ids) - ), - None, - ) - layout_matches = ( - selected_helicity is not None - and selector.get("workload") == "all-flows/runtime-selected-single-helicity" - and selector.get("selected_color_flow_ids") == [] - and selector.get("selected_helicity_ids") == [selected_helicity] - and validation.get("resolved_color_ids") == color_ids - and validation.get("resolved_helicity_ids") == [selected_helicity] - ) - else: - layout_matches = False - if not common_matches or not layout_matches: - raise ParityError("capture selector contract disagrees with physical axes") - - -def _comparison_errors( - baseline: Mapping[str, Any], - candidate: Mapping[str, Any], -) -> list[str]: - errors: list[str] = [] - baseline_validation = baseline["validation"] - candidate_validation = candidate["validation"] - if baseline["prepared_model"]["sha256"] != candidate["prepared_model"]["sha256"]: - errors.append("prepared model bytes differ") - if _canonical_sha256(baseline["generation_request"]) != _canonical_sha256( - candidate["generation_request"] - ): - errors.append("generation requests differ") - if ( - baseline["parameters"]["payload_sha256"] - != candidate["parameters"]["payload_sha256"] - ): - errors.append("default model parameters differ") - if ( - baseline_validation["fixture"]["points_sha256"] - != candidate_validation["fixture"]["points_sha256"] - ): - errors.append("deterministic phase-space fixtures differ") - if _canonical_sha256(_semantic_selector_body(baseline)) != _canonical_sha256( - _semantic_selector_body(candidate) - ): - errors.append("physical axes, selectors, normalization, or reduction differ") - if baseline_validation.get("passes") is not True: - errors.append("baseline selected/resolved self-comparison failed") - if candidate_validation.get("passes") is not True: - errors.append("candidate selected/resolved self-comparison failed") - return errors - - -def _compare_captures( - baseline_value: object, - candidate_value: object, - *, - process_key: str, - process_expression: str, - layout: str, -) -> dict[str, object]: - _validate_process_case(process_key, process_expression) - if layout not in LAYOUTS: - raise ParityError(f"unsupported LC flow layout: {layout}") - baseline = _validate_capture( - baseline_value, - expected_variant="baseline", - expected_process_key=process_key, - expected_process=process_expression, - expected_layout=layout, - ) - candidate = _validate_capture( - candidate_value, - expected_variant="candidate", - expected_process_key=process_key, - expected_process=process_expression, - expected_layout=layout, - ) - errors = _comparison_errors(baseline, candidate) - baseline_validation = baseline["validation"] - candidate_validation = candidate["validation"] - fixtures_match = ( - baseline_validation["fixture"]["points_sha256"] - == candidate_validation["fixture"]["points_sha256"] - ) - baseline_selector_sha256 = _canonical_sha256(_semantic_selector_body(baseline)) - candidate_selector_sha256 = _canonical_sha256(_semantic_selector_body(candidate)) - selectors_match = baseline_selector_sha256 == candidate_selector_sha256 - - pointwise: list[dict[str, object]] = [] - baseline_totals = baseline_validation["selected_totals"] - candidate_totals = candidate_validation["selected_totals"] - if ( - fixtures_match - and selectors_match - and len(baseline_totals) == len(candidate_totals) - ): - for point_index, (baseline_total, candidate_total) in enumerate( - zip(baseline_totals, candidate_totals, strict=True) - ): - pointwise.append( - _content_address( - { - "kind": "pyamplicol-recurrence-numerical-point-comparison", - "schema_version": 1, - "point_index": point_index, - **_value_comparison(baseline_total, candidate_total), - } - ) - ) - else: - errors.append("selected-total inventories cannot be paired") - - componentwise: list[dict[str, object]] = [] - baseline_components = baseline_validation["resolved_components"] - candidate_components = candidate_validation["resolved_components"] - helicity_ids = baseline_validation["resolved_helicity_ids"] - color_ids = baseline_validation["resolved_color_ids"] - component_count = len(helicity_ids) * len(color_ids) - components_pairable = ( - fixtures_match - and selectors_match - and len(baseline_components) == len(candidate_components) - and all( - len(point) == component_count - for point in (*baseline_components, *candidate_components) - ) - ) - if components_pairable: - for point_index, (baseline_point, candidate_point) in enumerate( - zip(baseline_components, candidate_components, strict=True) - ): - for component_index, (baseline_component, candidate_component) in enumerate( - zip(baseline_point, candidate_point, strict=True) - ): - helicity_index, color_index = divmod( - component_index, - len(color_ids), - ) - componentwise.append( - _content_address( - { - "kind": ( - "pyamplicol-recurrence-numerical-" - "resolved-component-comparison" - ), - "schema_version": 1, - "point_index": point_index, - "component_index": component_index, - "helicity_id": helicity_ids[helicity_index], - "color_id": color_ids[color_index], - **_value_comparison( - baseline_component, - candidate_component, - ), - } - ) - ) - else: - errors.append("resolved-component inventories cannot be paired") - - selector_comparison = _content_address( - { - "kind": "pyamplicol-recurrence-numerical-selector-comparison", - "schema_version": 1, - "baseline_sha256": baseline_selector_sha256, - "candidate_sha256": candidate_selector_sha256, - "passes": selectors_match, - } - ) - fixture_comparison = _content_address( - { - "kind": "pyamplicol-recurrence-numerical-fixture-comparison", - "schema_version": 1, - "baseline_points_sha256": baseline_validation["fixture"]["points_sha256"], - "candidate_points_sha256": candidate_validation["fixture"]["points_sha256"], - "point_count": len(baseline_validation["fixture"]["points"]), - "passes": fixtures_match, - } - ) - passes = ( - not errors - and fixture_comparison["passes"] is True - and selector_comparison["passes"] is True - and bool(pointwise) - and bool(componentwise) - and all(bool(item["passes"]) for item in pointwise) - and all(bool(item["passes"]) for item in componentwise) - ) - return _content_address( - { - "kind": COMPARISON_KIND, - "schema_version": COMPARISON_SCHEMA, - "process_key": process_key, - "process_expression": process_expression, - "layout": layout, - "baseline_capture_sha256": baseline["content_sha256"], - "candidate_capture_sha256": candidate["content_sha256"], - "tolerances": { - "absolute": ABSOLUTE_TOLERANCE, - "relative": RELATIVE_TOLERANCE, - }, - "fixture_comparison": fixture_comparison, - "selector_comparison": selector_comparison, - "parameter_comparison": _content_address( - { - "kind": ("pyamplicol-recurrence-numerical-parameter-comparison"), - "schema_version": 1, - "baseline_sha256": baseline["parameters"]["payload_sha256"], - "candidate_sha256": candidate["parameters"]["payload_sha256"], - "passes": ( - baseline["parameters"]["payload_sha256"] - == candidate["parameters"]["payload_sha256"] - ), - } - ), - "pointwise_comparisons": pointwise, - "resolved_component_comparisons": componentwise, - "summary": { - "point_count": len(pointwise), - "resolved_component_count": len(componentwise), - "maximum_absolute_point_difference": max( - (float(item["absolute_difference"]) for item in pointwise), - default=None, - ), - "maximum_relative_point_difference": max( - (float(item["relative_difference"]) for item in pointwise), - default=None, - ), - "maximum_absolute_component_difference": max( - (float(item["absolute_difference"]) for item in componentwise), - default=None, - ), - "maximum_relative_component_difference": max( - (float(item["relative_difference"]) for item in componentwise), - default=None, - ), - }, - "errors": errors, - "passes": passes, - } - ) - - -def _worker_environment( - variant: Variant, - capture_root: Path, -) -> tuple[dict[str, str], dict[str, str]]: - temporary = capture_root / "tmp" - cache = capture_root / "cache" - pycache = capture_root / "pycache" - matplotlib = cache / "matplotlib" - for path in (temporary, cache, pycache, matplotlib): - path.mkdir(parents=True, exist_ok=False) - overrides = { - SOURCE_CHECKOUT_ENV: str(variant.checkout), - "MPLCONFIGDIR": str(matplotlib), - "PYTHONHASHSEED": "0", - "PYTHONNOUSERSITE": "1", - "PYTHONDONTWRITEBYTECODE": "1", - "PYTHONPYCACHEPREFIX": str(pycache), - "PYTHONPATH": str(variant.pythonpath), - "SYMBOLICA_HIDE_BANNER": "1", - "TEMP": str(temporary), - "TMP": str(temporary), - "TMPDIR": str(temporary), - "XDG_CACHE_HOME": str(cache), - } - environment = os.environ.copy() - environment.update(overrides) - return environment, overrides - - -def _worker_command( - variant: Variant, - *, - capture_root: Path, - process_key: str, - process_expression: str, - layout: str, - validation_samples: int, - point_tile_size: int, - jit_optimization_level: int, -) -> list[str]: - artifact = capture_root / "artifact" - capture_json = capture_root / "capture.json" - return [ - str(variant.python), - str(WATCHDOG_PATH), - "--limit-gib", - f"{WATCHDOG_LIMIT_GIB:g}", - "--", - str(variant.python), - str(DRIVER_PATH), - "_worker", - "--variant", - variant.name, - "--process-key", - process_key, - "--process-expression", - process_expression, - "--layout", - layout, - "--prepared-model", - str(variant.prepared_model), - "--artifact", - str(artifact), - "--capture-json", - str(capture_json), - "--validation-samples", - str(validation_samples), - "--point-tile-size", - str(point_tile_size), - "--jit-optimization-level", - str(jit_optimization_level), - ] - - -def _terminate_process_tree(process: subprocess.Popen[bytes]) -> None: - if process.poll() is not None: - return - if os.name == "posix": - try: - os.killpg(process.pid, signal.SIGTERM) - except ProcessLookupError: - return - else: - process.terminate() - try: - process.wait(timeout=5.0) - return - except subprocess.TimeoutExpired: - pass - if os.name == "posix": - try: - os.killpg(process.pid, signal.SIGKILL) - except ProcessLookupError: - return - else: - process.kill() - process.wait() - - -def _run_process( - command: Sequence[str], - *, - cwd: Path, - environment: Mapping[str, str], - stdout_path: Path, - stderr_path: Path, - timeout_seconds: float, -) -> ProcessOutcome: - started = time.perf_counter() - process: subprocess.Popen[bytes] | None = None - try: - with stdout_path.open("wb") as stdout, stderr_path.open("wb") as stderr: - process = subprocess.Popen( - list(command), - cwd=cwd, - env=dict(environment), - stdout=stdout, - stderr=stderr, - start_new_session=(os.name == "posix"), - ) - try: - exit_code = process.wait(timeout=timeout_seconds) - except subprocess.TimeoutExpired: - _terminate_process_tree(process) - return ProcessOutcome( - exit_code=None, - timed_out=True, - wall_seconds=time.perf_counter() - started, - error=f"capture timeout after {timeout_seconds:g} seconds", - ) - except OSError as error: - if process is not None: - _terminate_process_tree(process) - return ProcessOutcome( - exit_code=None, - timed_out=False, - wall_seconds=time.perf_counter() - started, - error=f"{type(error).__name__}: {error}", - ) - return ProcessOutcome( - exit_code=exit_code, - timed_out=False, - wall_seconds=time.perf_counter() - started, - error=None, - ) - - -def _capture_variant( - variant: Variant, - *, - capture_root: Path, - process_key: str, - process_expression: str, - layout: str, - validation_samples: int, - point_tile_size: int, - jit_optimization_level: int, - worker_timeout_seconds: float, -) -> tuple[dict[str, Any], dict[str, object]]: - capture_root.mkdir(parents=True, exist_ok=False) - environment, overrides = _worker_environment(variant, capture_root) - stdout_path = capture_root / "stdout.log" - stderr_path = capture_root / "stderr.log" - command = _worker_command( - variant, - capture_root=capture_root, - process_key=process_key, - process_expression=process_expression, - layout=layout, - validation_samples=validation_samples, - point_tile_size=point_tile_size, - jit_optimization_level=jit_optimization_level, - ) - started_at = _utc_now() - outcome = _run_process( - command, - cwd=variant.checkout, - environment=environment, - stdout_path=stdout_path, - stderr_path=stderr_path, - timeout_seconds=worker_timeout_seconds, - ) - finished_at = _utc_now() - watchdog = ladder.parse_watchdog_log(stderr_path) - capture_path = capture_root / "capture.json" - if ( - outcome.timed_out - or outcome.error is not None - or outcome.exit_code != 0 - or watchdog.get("terminal_record") != "command-finished" - or watchdog.get("limit_gib") != WATCHDOG_LIMIT_GIB - or watchdog.get("limit_exceeded") is not False - or watchdog.get("child_exit_code") != 0 - or not capture_path.is_file() - ): - raise ParityError( - f"{variant.name}/{process_key}/{layout} capture failed; " - f"exit={outcome.exit_code}, timed_out={outcome.timed_out}, " - f"error={outcome.error}, watchdog={watchdog.get('terminal_record')}" - ) - capture = _validate_capture( - _json_object(capture_path, label="numerical capture"), - expected_variant=variant.name, - expected_process_key=process_key, - expected_process=process_expression, - expected_layout=layout, - expected_checkout=variant.checkout, - expected_artifact_root=capture_root, - expected_generation_request=_generation_request( - validation_samples=validation_samples, - point_tile_size=point_tile_size, - jit_optimization_level=jit_optimization_level, - ), - ) - invocation = _content_address( - { - "kind": "pyamplicol-recurrence-numerical-capture-invocation", - "schema_version": 1, - "variant": variant.name, - "process_key": process_key, - "layout": layout, - "started_at_utc": started_at, - "finished_at_utc": finished_at, - "wall_seconds": outcome.wall_seconds, - "command": { - "argv": command, - "argv_sha256": _canonical_sha256(command), - }, - "environment_overrides": overrides, - "stdout": _path_identity(stdout_path), - "stderr": _path_identity(stderr_path), - "capture_file": _path_identity(capture_path), - "watchdog": watchdog, - } - ) - _atomic_write_json(capture_root / "invocation.json", invocation) - return capture, invocation - - -def _comparison_file_name(process_key: str, layout: str) -> str: - return f"{process_key}__{layout.replace('-', '_')}.json" - - -def _tooling_identity() -> dict[str, object]: - return { - "driver": _path_identity(DRIVER_PATH), - "watchdog": _path_identity(WATCHDOG_PATH), - "recurrence_harness": _path_identity( - DRIVER_ROOT / "tools" / "developer" / "recurrence_z6g_benchmark.py" - ), - "campaign_ladder": _path_identity( - DRIVER_ROOT / "tools" / "developer" / "recurrence_generation_ab_ladder.py" - ), - } - - -def _pin_variant_binding( - bindings: dict[str, dict[str, object]], - *, - variant: Variant, - capture: Mapping[str, Any], - expected_model: Mapping[str, object], - expected_generation_request: Mapping[str, object], - expected_source: Mapping[str, object], -) -> None: - if ( - _canonical_sha256(capture["prepared_model"]) - != _canonical_sha256(expected_model) - or _canonical_sha256(capture["source"]) != _canonical_sha256(expected_source) - or _canonical_sha256(capture["generation_request"]) - != _canonical_sha256(expected_generation_request) - ): - raise ParityError( - f"{variant.name} capture escaped its configured source binding" - ) - observed_binding = { - "source": capture["source"], - "runtime_provenance": capture["runtime_provenance"], - "prepared_model": capture["prepared_model"], - } - expected_binding = bindings.setdefault(variant.name, observed_binding) - if _canonical_sha256(observed_binding) != _canonical_sha256(expected_binding): - raise ParityError( - f"{variant.name} source or runtime changed during the campaign" - ) - - -def run(arguments: argparse.Namespace) -> dict[str, object]: - output_root = _resolve_output_root(arguments.output_root) - baseline = _variant( - "baseline", - python=arguments.baseline_python, - checkout=arguments.baseline_checkout, - pythonpath=arguments.baseline_pythonpath, - prepared_model=arguments.baseline_prepared_model, - ) - candidate = _variant( - "candidate", - python=arguments.candidate_python, - checkout=arguments.candidate_checkout, - pythonpath=arguments.candidate_pythonpath, - prepared_model=arguments.candidate_prepared_model, - ) - preflight_sources = { - "baseline": _preflight_variant_source(baseline), - "candidate": _preflight_variant_source(candidate), - } - baseline_model = _path_identity(baseline.prepared_model) - candidate_model = _path_identity(candidate.prepared_model) - if baseline_model["sha256"] != candidate_model["sha256"]: - raise ParityError("baseline and candidate prepared-model bytes differ") - if baseline.checkout == candidate.checkout: - raise ParityError("baseline and candidate checkouts must be distinct") - if not WATCHDOG_PATH.is_file(): - raise ParityError(f"audited memory watchdog is missing: {WATCHDOG_PATH}") - - tooling_before = _tooling_identity() - expected_generation_request = _generation_request( - validation_samples=arguments.validation_samples, - point_tile_size=arguments.point_tile_size, - jit_optimization_level=arguments.jit_optimization_level, - ) - output_root.mkdir(parents=True, exist_ok=False) - started_at = _utc_now() - started = time.perf_counter() - comparisons: list[dict[str, object]] = [] - capture_records: list[dict[str, object]] = [] - variant_bindings: dict[str, dict[str, object]] = {} - sequence_index = 0 - for case_index, (process_key, process_expression) in enumerate(PROCESS_CASES): - for layout in LAYOUTS: - variants = ( - (baseline, candidate) - if (case_index + LAYOUTS.index(layout)) % 2 == 0 - else (candidate, baseline) - ) - captures: dict[str, dict[str, Any]] = {} - invocations: dict[str, dict[str, object]] = {} - for variant in variants: - capture_root = ( - output_root - / "captures" - / f"{sequence_index:02d}-{process_key}-{layout}" - / variant.name - ) - capture, invocation = _capture_variant( - variant, - capture_root=capture_root, - process_key=process_key, - process_expression=process_expression, - layout=layout, - validation_samples=arguments.validation_samples, - point_tile_size=arguments.point_tile_size, - jit_optimization_level=arguments.jit_optimization_level, - worker_timeout_seconds=arguments.worker_timeout, - ) - captures[variant.name] = capture - invocations[variant.name] = invocation - expected_model = ( - baseline_model if variant.name == "baseline" else candidate_model - ) - _pin_variant_binding( - variant_bindings, - variant=variant, - capture=capture, - expected_model=expected_model, - expected_generation_request=expected_generation_request, - expected_source=preflight_sources[variant.name], - ) - comparison = _compare_captures( - captures["baseline"], - captures["candidate"], - process_key=process_key, - process_expression=process_expression, - layout=layout, - ) - comparison_path = ( - output_root / "comparisons" / _comparison_file_name(process_key, layout) - ) - _atomic_write_json(comparison_path, comparison) - comparisons.append( - { - "process_key": process_key, - "process_expression": process_expression, - "layout": layout, - "passes": comparison["passes"], - "comparison_file": _path_identity(comparison_path), - "comparison_content_sha256": comparison["content_sha256"], - } - ) - capture_records.append( - { - "process_key": process_key, - "layout": layout, - "order": [variant.name for variant in variants], - "baseline_capture_sha256": captures["baseline"]["content_sha256"], - "candidate_capture_sha256": captures["candidate"]["content_sha256"], - "baseline_invocation_sha256": invocations["baseline"][ - "content_sha256" - ], - "candidate_invocation_sha256": invocations["candidate"][ - "content_sha256" - ], - } - ) - sequence_index += 1 - tooling_after = _tooling_identity() - if _canonical_sha256(tooling_after) != _canonical_sha256(tooling_before): - raise ParityError("validator tooling changed during the campaign") - final_sources = { - "baseline": _preflight_variant_source(baseline), - "candidate": _preflight_variant_source(candidate), - } - if _canonical_sha256(final_sources) != _canonical_sha256(preflight_sources): - raise ParityError("baseline or candidate source changed during the campaign") - finished_at = _utc_now() - result = _content_address( - { - "kind": RESULT_KIND, - "schema_version": RESULT_SCHEMA, - "status": ( - "passed" - if all(item["passes"] is True for item in comparisons) - else "failed" - ), - "passes": all(item["passes"] is True for item in comparisons), - "started_at_utc": started_at, - "finished_at_utc": finished_at, - "wall_seconds": time.perf_counter() - started, - "configuration": { - "processes": [ - { - "key": process_key, - "expression": process_expression, - } - for process_key, process_expression in PROCESS_CASES - ], - "layouts": list(LAYOUTS), - "validation_samples": arguments.validation_samples, - "validation_seed": harness.VALIDATION_SEED, - "point_tile_size": arguments.point_tile_size, - "jit_optimization_level": arguments.jit_optimization_level, - "worker_timeout_seconds": arguments.worker_timeout, - "absolute_tolerance": ABSOLUTE_TOLERANCE, - "relative_tolerance": RELATIVE_TOLERANCE, - "watchdog_limit_gib": WATCHDOG_LIMIT_GIB, - "generation_request_sha256": _canonical_sha256( - expected_generation_request - ), - }, - "tooling": tooling_before, - "variants": { - "baseline": { - "python": str(baseline.python), - "checkout": str(baseline.checkout), - "source": preflight_sources["baseline"], - "pythonpath": str(baseline.pythonpath), - "prepared_model": baseline_model, - }, - "candidate": { - "python": str(candidate.python), - "checkout": str(candidate.checkout), - "source": preflight_sources["candidate"], - "pythonpath": str(candidate.pythonpath), - "prepared_model": candidate_model, - }, - }, - "capture_records": capture_records, - "variant_bindings": { - name: { - **binding, - "binding_sha256": _canonical_sha256(binding), - } - for name, binding in sorted(variant_bindings.items()) - }, - "comparisons": comparisons, - "comparison_count": len(comparisons), - "passing_comparison_count": sum( - item["passes"] is True for item in comparisons - ), - } - ) - _atomic_write_json(output_root / "result.json", result) - return result - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - result.add_argument("--baseline-python", type=Path, required=True) - result.add_argument("--candidate-python", type=Path, required=True) - result.add_argument("--baseline-checkout", type=Path, required=True) - result.add_argument("--candidate-checkout", type=Path, required=True) - result.add_argument("--baseline-pythonpath", type=Path, required=True) - result.add_argument("--candidate-pythonpath", type=Path, required=True) - result.add_argument("--baseline-prepared-model", type=Path, required=True) - result.add_argument("--candidate-prepared-model", type=Path, required=True) - result.add_argument("--output-root", type=Path, required=True) - result.add_argument( - "--validation-samples", - type=_positive_int, - default=DEFAULT_VALIDATION_SAMPLES, - ) - result.add_argument( - "--point-tile-size", - type=_positive_int, - default=DEFAULT_POINT_TILE_SIZE, - ) - result.add_argument( - "--jit-optimization-level", - type=int, - choices=(0, 1, 2, 3), - default=DEFAULT_JIT_OPTIMIZATION_LEVEL, - ) - result.add_argument( - "--worker-timeout", - type=_positive_float, - default=DEFAULT_WORKER_TIMEOUT_SECONDS, - ) - return result - - -def _worker_parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(add_help=False) - result.add_argument("--variant", choices=("baseline", "candidate"), required=True) - result.add_argument("--process-key", required=True) - result.add_argument("--process-expression", required=True) - result.add_argument("--layout", choices=LAYOUTS, required=True) - result.add_argument("--prepared-model", type=Path, required=True) - result.add_argument("--artifact", type=Path, required=True) - result.add_argument("--capture-json", type=Path, required=True) - result.add_argument("--validation-samples", type=_positive_int, required=True) - result.add_argument("--point-tile-size", type=_positive_int, required=True) - result.add_argument( - "--jit-optimization-level", - type=int, - choices=(0, 1, 2, 3), - required=True, - ) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - values = list(sys.argv[1:] if argv is None else argv) - try: - if values[:1] == ["_worker"]: - arguments = _worker_parser().parse_args(values[1:]) - capture = _run_capture_worker(arguments) - print( - json.dumps( - { - "kind": capture["kind"], - "content_sha256": capture["content_sha256"], - "passes": capture["validation"]["passes"], - }, - allow_nan=False, - sort_keys=True, - ) - ) - return 0 - arguments = parser().parse_args(values) - result = run(arguments) - except ( - ParityError, - harness.HarnessError, - ImportError, - OSError, - RuntimeError, - ValueError, - json.JSONDecodeError, - ) as error: - print(f"recurrence-numerical-ab-parity: {error}", file=sys.stderr) - return 2 - print( - json.dumps( - { - "kind": result["kind"], - "result_json": str( - arguments.output_root.expanduser().resolve() / "result.json" - ), - "status": result["status"], - "passes": result["passes"], - "content_sha256": result["content_sha256"], - }, - allow_nan=False, - sort_keys=True, - ) - ) - return 0 if result["passes"] is True else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/recurrence_runtime_ab_analyzer.py b/pyamplicol/tools/developer/recurrence_runtime_ab_analyzer.py deleted file mode 100644 index 1f88069c48..0000000000 --- a/pyamplicol/tools/developer/recurrence_runtime_ab_analyzer.py +++ /dev/null @@ -1,802 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Analyze the recurrence runtime no-regression A/B gate. - -The input is a ``recurrence_generation_ab_ladder.py`` campaign. Timing -observations are paired by outer A/B pair and inner subprocess round, so host -drift is not silently treated as independent noise. The candidate/baseline -ratio is analyzed in log space with a one-sided 95% Student-t bound. - -This analyzer deliberately accepts only runtime-worker RSS evidence. The -generation worker and outer watchdog both cover artifact generation and cannot -establish runtime-only memory use. -""" - -from __future__ import annotations - -import argparse -import json -import math -import os -import statistics -import sys -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -ALLOWED_OUTPUT_PARENT = ROOT / ".artifacts" / "recurrence-generation-opt" - -CAMPAIGN_KIND = "pyamplicol-recurrence-generation-ab-ladder" -CAMPAIGN_SCHEMA_VERSION = 1 -RESULT_KIND = "pyamplicol-recurrence-runtime-ab-analysis" -RESULT_SCHEMA_VERSION = 1 -LAYOUTS = ("topology-replay", "all-flow-union") -DEFAULT_MULTIPLICITIES = (6, 7) -DEFAULT_BATCH_SIZES = (1, 128, 1024) -MINIMUM_PAIRED_SAMPLES = 7 -MAXIMUM_PAIRED_SAMPLES = 21 -CONFIDENCE_LEVEL = 0.95 -NO_SLOWDOWN_RATIO = 1.0 -DEFAULT_MATERIAL_RSS_RATIO = 1.10 - -# One-sided 95% Student-t quantiles. The gate admits 7..21 paired -# observations, so only df=6..20 are reachable. Values are fixed here to -# avoid introducing a scientific-library dependency into the developer tool. -_ONE_SIDED_T_95 = { - 6: 1.9431802805153022, - 7: 1.894578605061305, - 8: 1.8595480375228424, - 9: 1.8331129326536337, - 10: 1.8124611228107335, - 11: 1.7958848187036691, - 12: 1.782287555649159, - 13: 1.7709333959867988, - 14: 1.7613101357748562, - 15: 1.7530503556925547, - 16: 1.74588367627624, - 17: 1.7396067260750672, - 18: 1.734063606617536, - 19: 1.729132811521367, - 20: 1.7247182429207863, -} - - -class RuntimeABError(RuntimeError): - """Raised when runtime A/B evidence violates its contract.""" - - -@dataclass(frozen=True, slots=True) -class WorkerObservation: - """One baseline/candidate worker pair from the same schedule round.""" - - pair_index: int - round_index: int - baseline_order_in_pair: int - candidate_order_in_pair: int - baseline_seconds_per_point: float - candidate_seconds_per_point: float - baseline_runtime_peak_rss_bytes: int | None - candidate_runtime_peak_rss_bytes: int | None - - -def _mapping(value: object, *, description: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise RuntimeABError(f"{description} must be a JSON object") - return value - - -def _list(value: object, *, description: str) -> list[Any]: - if not isinstance(value, list): - raise RuntimeABError(f"{description} must be a JSON array") - return value - - -def _positive_int(value: object, *, description: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value <= 0: - raise RuntimeABError(f"{description} must be a positive integer") - return value - - -def _nonnegative_int(value: object, *, description: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise RuntimeABError(f"{description} must be a nonnegative integer") - return value - - -def _positive_float(value: object, *, description: str) -> float: - if ( - isinstance(value, bool) - or not isinstance(value, (float, int)) - or not math.isfinite(float(value)) - or float(value) <= 0.0 - ): - raise RuntimeABError(f"{description} must be a positive finite number") - return float(value) - - -def _runtime_peak_rss_bytes(sample: Mapping[str, Any]) -> int | None: - """Return only the profile worker's post-runtime high-water evidence.""" - - normalized = sample.get("runtime_peak_rss_bytes") - peak = sample.get("peak_rss_after_profile") - observed: int | None = None - if normalized is not None: - observed = _positive_int( - normalized, - description="runtime_peak_rss_bytes", - ) - if peak is not None: - record = _mapping( - peak, - description="profile worker peak_rss_after_profile", - ) - source = record.get("source") - if source != "resource.getrusage": - raise RuntimeABError("profile worker RSS must come from resource.getrusage") - record_observed = _positive_int( - record.get("observed_lower_bound_bytes"), - description=("profile worker peak_rss_after_profile observed lower bound"), - ) - if observed is not None and observed != record_observed: - raise RuntimeABError("normalized and structured runtime RSS disagree") - observed = record_observed - return observed - - -def paired_log_ratio_interval( - baseline: Sequence[float | int], - candidate: Sequence[float | int], -) -> dict[str, float | int | str]: - """Return a deterministic paired one-sided 95% log-ratio interval.""" - - if len(baseline) != len(candidate): - raise RuntimeABError("baseline and candidate sample counts differ") - sample_count = len(baseline) - if not MINIMUM_PAIRED_SAMPLES <= sample_count <= MAXIMUM_PAIRED_SAMPLES: - raise RuntimeABError( - "paired sample count must remain between 7 and 21 inclusive" - ) - log_ratios: list[float] = [] - baseline_values: list[float] = [] - candidate_values: list[float] = [] - for index, (baseline_value, candidate_value) in enumerate( - zip(baseline, candidate, strict=True) - ): - baseline_float = _positive_float( - baseline_value, - description=f"baseline observation {index}", - ) - candidate_float = _positive_float( - candidate_value, - description=f"candidate observation {index}", - ) - baseline_values.append(baseline_float) - candidate_values.append(candidate_float) - log_ratios.append(math.log(candidate_float / baseline_float)) - - mean_log_ratio = statistics.fmean(log_ratios) - standard_deviation = statistics.stdev(log_ratios) - standard_error = standard_deviation / math.sqrt(sample_count) - critical = _ONE_SIDED_T_95[sample_count - 1] - half_width = critical * standard_error - return { - "statistics_contract": ("paired-log-ratio-student-t-one-sided-95-v1"), - "confidence_level": CONFIDENCE_LEVEL, - "sample_count": sample_count, - "degrees_of_freedom": sample_count - 1, - "student_t_critical": critical, - "candidate_over_baseline_geometric_mean": math.exp(mean_log_ratio), - "candidate_over_baseline_lower_confidence_bound": math.exp( - mean_log_ratio - half_width - ), - "candidate_over_baseline_upper_confidence_bound": math.exp( - mean_log_ratio + half_width - ), - "baseline_median": statistics.median(baseline_values), - "candidate_median": statistics.median(candidate_values), - "candidate_over_baseline_median_ratio": ( - statistics.median(candidate_values) / statistics.median(baseline_values) - ), - "log_ratio_sample_standard_deviation": standard_deviation, - "log_ratio_standard_error": standard_error, - } - - -def _gate_decision( - interval: Mapping[str, object], - *, - allowed_ratio: float, - failure_label: str, -) -> dict[str, object]: - sample_count = _positive_int( - interval.get("sample_count"), - description="confidence interval sample count", - ) - upper = _positive_float( - interval.get("candidate_over_baseline_upper_confidence_bound"), - description="candidate/baseline upper confidence bound", - ) - lower = _positive_float( - interval.get("candidate_over_baseline_lower_confidence_bound"), - description="candidate/baseline lower confidence bound", - ) - if upper <= allowed_ratio: - status = "passed" - elif lower > allowed_ratio: - status = failure_label - elif sample_count < MAXIMUM_PAIRED_SAMPLES: - status = "needs-more-samples" - else: - status = "rejected-inconclusive" - return { - "status": status, - "passes": status == "passed", - "allowed_candidate_over_baseline_ratio": allowed_ratio, - "additional_paired_samples_allowed": max( - 0, - MAXIMUM_PAIRED_SAMPLES - sample_count, - ), - } - - -def _measurement( - sample: Mapping[str, Any], - *, - batch_size: int, -) -> Mapping[str, Any]: - telemetry = _mapping(sample.get("telemetry"), description="sample telemetry") - profile = _mapping( - telemetry.get("runtime_profile"), - description="sample recurrence runtime profile", - ) - measurements = _list( - profile.get("measurements"), - description="runtime profile measurements", - ) - matches = [ - _mapping(item, description="runtime profile measurement") - for item in measurements - if isinstance(item, Mapping) and item.get("batch_size") == batch_size - ] - if len(matches) != 1: - raise RuntimeABError( - f"runtime profile must contain exactly one batch {batch_size} measurement" - ) - measurement = matches[0] - subprocess_samples = _list( - measurement.get("subprocess_samples"), - description=f"batch {batch_size} subprocess samples", - ) - sample_count = _positive_int( - measurement.get("sample_count"), - description=f"batch {batch_size} sample count", - ) - if sample_count != len(subprocess_samples): - raise RuntimeABError( - f"batch {batch_size} sample count does not match its worker list" - ) - if measurement.get("interrupted") is not False: - raise RuntimeABError(f"batch {batch_size} measurement was interrupted") - return measurement - - -def _worker_rounds( - measurement: Mapping[str, Any], - *, - batch_size: int, -) -> dict[int, Mapping[str, Any]]: - raw_samples = _list( - measurement.get("subprocess_samples"), - description=f"batch {batch_size} subprocess samples", - ) - rounds: dict[int, Mapping[str, Any]] = {} - schedule_indices: set[int] = set() - for raw in raw_samples: - sample = _mapping(raw, description="runtime worker sample") - round_index = _nonnegative_int( - sample.get("round"), - description="runtime worker round", - ) - schedule_index = _nonnegative_int( - sample.get("schedule_index"), - description="runtime worker schedule index", - ) - if round_index in rounds: - raise RuntimeABError( - f"batch {batch_size} duplicates worker round {round_index}" - ) - if schedule_index in schedule_indices: - raise RuntimeABError( - f"batch {batch_size} reuses worker schedule index {schedule_index}" - ) - _positive_float( - sample.get("wall_seconds_per_point"), - description="runtime worker wall seconds per point", - ) - if sample.get("interrupted") is not False: - raise RuntimeABError("runtime worker sample was interrupted") - rounds[round_index] = sample - schedule_indices.add(schedule_index) - if set(rounds) != set(range(len(raw_samples))): - raise RuntimeABError( - f"batch {batch_size} worker rounds are not contiguous from zero" - ) - return rounds - - -def _sample_variant(sample: Mapping[str, Any]) -> str: - variant = sample.get("variant") - if variant not in {"baseline", "candidate"}: - raise RuntimeABError("campaign sample has an invalid A/B variant") - return str(variant) - - -def _cell_observations( - samples: Sequence[Mapping[str, Any]], - *, - multiplicity: int, - layout: str, - batch_size: int, -) -> list[WorkerObservation]: - pair_members: dict[int, dict[str, Mapping[str, Any]]] = {} - for sample in samples: - if sample.get("multiplicity") != multiplicity or sample.get("layout") != layout: - continue - if sample.get("runtime_enabled") is not True: - raise RuntimeABError( - f"n={multiplicity}/{layout} sample did not enable runtime profiling" - ) - if sample.get("status") != "passed": - raise RuntimeABError( - f"n={multiplicity}/{layout} has a non-passing runtime sample" - ) - pair_index = _nonnegative_int( - sample.get("pair_index"), - description="outer A/B pair index", - ) - variant = _sample_variant(sample) - members = pair_members.setdefault(pair_index, {}) - if variant in members: - raise RuntimeABError( - f"outer pair {pair_index} duplicates the {variant} sample" - ) - members[variant] = sample - - observations: list[WorkerObservation] = [] - previous_first_variant: str | None = None - for pair_index, members in sorted(pair_members.items()): - if set(members) != {"baseline", "candidate"}: - raise RuntimeABError( - f"outer pair {pair_index} is missing a baseline or candidate" - ) - baseline_sample = members["baseline"] - candidate_sample = members["candidate"] - baseline_order = _nonnegative_int( - baseline_sample.get("order_in_pair"), - description="baseline order in outer pair", - ) - candidate_order = _nonnegative_int( - candidate_sample.get("order_in_pair"), - description="candidate order in outer pair", - ) - if {baseline_order, candidate_order} != {0, 1}: - raise RuntimeABError( - f"outer pair {pair_index} does not contain positions zero and one" - ) - first_variant = "baseline" if baseline_order == 0 else "candidate" - if previous_first_variant == first_variant: - raise RuntimeABError( - "outer baseline/candidate order did not alternate between pairs" - ) - previous_first_variant = first_variant - - baseline_rounds = _worker_rounds( - _measurement(baseline_sample, batch_size=batch_size), - batch_size=batch_size, - ) - candidate_rounds = _worker_rounds( - _measurement(candidate_sample, batch_size=batch_size), - batch_size=batch_size, - ) - if set(baseline_rounds) != set(candidate_rounds): - raise RuntimeABError(f"outer pair {pair_index} has unmatched worker rounds") - for round_index in sorted(baseline_rounds): - baseline_worker = baseline_rounds[round_index] - candidate_worker = candidate_rounds[round_index] - observations.append( - WorkerObservation( - pair_index=pair_index, - round_index=round_index, - baseline_order_in_pair=baseline_order, - candidate_order_in_pair=candidate_order, - baseline_seconds_per_point=_positive_float( - baseline_worker.get("wall_seconds_per_point"), - description="baseline runtime wall seconds per point", - ), - candidate_seconds_per_point=_positive_float( - candidate_worker.get("wall_seconds_per_point"), - description="candidate runtime wall seconds per point", - ), - baseline_runtime_peak_rss_bytes=_runtime_peak_rss_bytes( - baseline_worker - ), - candidate_runtime_peak_rss_bytes=_runtime_peak_rss_bytes( - candidate_worker - ), - ) - ) - return observations - - -def _cell_result( - observations: Sequence[WorkerObservation], - *, - multiplicity: int, - layout: str, - batch_size: int, - material_rss_ratio: float, -) -> dict[str, object]: - if not observations: - return { - "multiplicity": multiplicity, - "layout": layout, - "batch_size": batch_size, - "status": "missing", - "passes": False, - "paired_sample_count": 0, - } - if len(observations) > MAXIMUM_PAIRED_SAMPLES: - raise RuntimeABError( - f"n={multiplicity}/{layout}/batch={batch_size} exceeds the 21-pair cap" - ) - baseline_timing = [ - observation.baseline_seconds_per_point for observation in observations - ] - candidate_timing = [ - observation.candidate_seconds_per_point for observation in observations - ] - timing_interval = paired_log_ratio_interval( - baseline_timing, - candidate_timing, - ) - timing_gate = _gate_decision( - timing_interval, - allowed_ratio=NO_SLOWDOWN_RATIO, - failure_label="rejected-supported-slowdown", - ) - - rss_complete = all( - observation.baseline_runtime_peak_rss_bytes is not None - and observation.candidate_runtime_peak_rss_bytes is not None - for observation in observations - ) - if rss_complete: - baseline_rss = [ - int(observation.baseline_runtime_peak_rss_bytes) - for observation in observations - ] - candidate_rss = [ - int(observation.candidate_runtime_peak_rss_bytes) - for observation in observations - ] - rss_interval: dict[str, object] | None = paired_log_ratio_interval( - baseline_rss, - candidate_rss, - ) - rss_gate: dict[str, object] = _gate_decision( - rss_interval, - allowed_ratio=material_rss_ratio, - failure_label="rejected-supported-material-rss-increase", - ) - else: - rss_interval = None - rss_gate = { - "status": "missing-runtime-only-rss", - "passes": False, - "allowed_candidate_over_baseline_ratio": material_rss_ratio, - "missing_paired_observation_count": sum( - observation.baseline_runtime_peak_rss_bytes is None - or observation.candidate_runtime_peak_rss_bytes is None - for observation in observations - ), - } - - statuses = {str(timing_gate["status"]), str(rss_gate["status"])} - if any(status.startswith("rejected") for status in statuses): - status = "rejected" - elif "missing-runtime-only-rss" in statuses: - status = "incomplete-runtime-rss" - elif "needs-more-samples" in statuses: - status = "needs-more-samples" - else: - status = "passed" - return { - "multiplicity": multiplicity, - "layout": layout, - "batch_size": batch_size, - "status": status, - "passes": status == "passed", - "paired_sample_count": len(observations), - "pairing_contract": "outer-pair-index-and-inner-round-v1", - "observations": [ - { - "pair_index": observation.pair_index, - "round": observation.round_index, - "baseline_order_in_pair": observation.baseline_order_in_pair, - "candidate_order_in_pair": observation.candidate_order_in_pair, - "baseline_seconds_per_point": (observation.baseline_seconds_per_point), - "candidate_seconds_per_point": ( - observation.candidate_seconds_per_point - ), - "baseline_runtime_peak_rss_bytes": ( - observation.baseline_runtime_peak_rss_bytes - ), - "candidate_runtime_peak_rss_bytes": ( - observation.candidate_runtime_peak_rss_bytes - ), - } - for observation in observations - ], - "timing": { - "interval": timing_interval, - "gate": timing_gate, - }, - "runtime_rss": { - "evidence_contract": ("profile-worker-post-runtime-resource-high-water-v1"), - "interval": rss_interval, - "gate": rss_gate, - }, - } - - -def analyze_campaign( - campaign: Mapping[str, Any], - *, - multiplicities: Sequence[int] = DEFAULT_MULTIPLICITIES, - layouts: Sequence[str] = LAYOUTS, - batch_sizes: Sequence[int] = DEFAULT_BATCH_SIZES, - material_rss_ratio: float = DEFAULT_MATERIAL_RSS_RATIO, -) -> dict[str, object]: - """Analyze every requested runtime cell and fail closed on missing evidence.""" - - if ( - campaign.get("kind") != CAMPAIGN_KIND - or campaign.get("schema_version") != CAMPAIGN_SCHEMA_VERSION - ): - raise RuntimeABError("input is not a supported recurrence A/B campaign") - if not math.isfinite(material_rss_ratio) or material_rss_ratio < 1.0: - raise RuntimeABError("material RSS ratio must be finite and at least one") - - requested_multiplicities = tuple(dict.fromkeys(multiplicities)) - requested_layouts = tuple(dict.fromkeys(layouts)) - requested_batches = tuple(dict.fromkeys(batch_sizes)) - if not requested_multiplicities or not requested_layouts or not requested_batches: - raise RuntimeABError("the requested runtime matrix must be non-empty") - if any( - isinstance(value, bool) or not isinstance(value, int) or value <= 0 - for value in (*requested_multiplicities, *requested_batches) - ): - raise RuntimeABError("multiplicities and batch sizes must be positive") - if any(layout not in LAYOUTS for layout in requested_layouts): - raise RuntimeABError("the runtime matrix contains an unsupported LC layout") - - configuration = _mapping( - campaign.get("configuration"), - description="campaign configuration", - ) - configuration_errors: list[str] = [] - if configuration.get("warmup_runs") != 2: - configuration_errors.append("warmup_runs must equal 2") - if configuration.get("target_runtime_seconds") != 5.0: - configuration_errors.append("target_runtime_seconds must equal 5") - minimum_samples = configuration.get("minimum_samples") - if ( - isinstance(minimum_samples, bool) - or not isinstance(minimum_samples, int) - or minimum_samples < 7 - ): - configuration_errors.append("minimum_samples must be at least 7") - subprocess_samples = configuration.get("subprocess_samples") - if ( - isinstance(subprocess_samples, bool) - or not isinstance(subprocess_samples, int) - or not 7 <= subprocess_samples <= 21 - ): - configuration_errors.append("subprocess_samples must be between 7 and 21") - if ( - configuration.get("ordering_policy") - != "alternating-baseline-candidate-pairs-v1" - ): - configuration_errors.append("outer A/B ordering policy is not alternating") - if configuration.get("cold_cache_policy") != "unique-roots-per-outer-sample-v1": - configuration_errors.append("outer samples do not use isolated cache roots") - configured_batches = configuration.get("batch_sizes") - if not isinstance(configured_batches, list) or not set(requested_batches).issubset( - configured_batches - ): - configuration_errors.append("campaign does not configure every batch size") - configured_runtime_n = configuration.get("runtime_multiplicities") - if not isinstance(configured_runtime_n, list) or not set( - requested_multiplicities - ).issubset(configured_runtime_n): - configuration_errors.append( - "campaign does not runtime-profile every multiplicity" - ) - configured_layouts = configuration.get("layouts") - if not isinstance(configured_layouts, list) or not set(requested_layouts).issubset( - configured_layouts - ): - configuration_errors.append("campaign does not include every LC layout") - if configuration_errors: - raise RuntimeABError( - "campaign configuration violates the runtime gate: " - + "; ".join(configuration_errors) - ) - - raw_samples = _list(campaign.get("samples"), description="campaign samples") - samples = [ - _mapping(sample, description="campaign sample") for sample in raw_samples - ] - cell_results = [] - for multiplicity in requested_multiplicities: - for layout in requested_layouts: - for batch_size in requested_batches: - observations = _cell_observations( - samples, - multiplicity=multiplicity, - layout=layout, - batch_size=batch_size, - ) - cell_results.append( - _cell_result( - observations, - multiplicity=multiplicity, - layout=layout, - batch_size=batch_size, - material_rss_ratio=material_rss_ratio, - ) - ) - - statuses = {str(cell["status"]) for cell in cell_results} - if "rejected" in statuses: - status = "rejected" - elif "missing" in statuses: - status = "incomplete-matrix" - elif "incomplete-runtime-rss" in statuses: - status = "incomplete-runtime-rss" - elif "needs-more-samples" in statuses: - status = "needs-more-samples" - else: - status = "passed" - return { - "kind": RESULT_KIND, - "schema_version": RESULT_SCHEMA_VERSION, - "status": status, - "passes": status == "passed", - "source_campaign_id": campaign.get("campaign_id"), - "gate_contract": { - "multiplicities": list(requested_multiplicities), - "layouts": list(requested_layouts), - "batch_sizes": list(requested_batches), - "minimum_paired_samples": MINIMUM_PAIRED_SAMPLES, - "maximum_paired_samples": MAXIMUM_PAIRED_SAMPLES, - "confidence_level": CONFIDENCE_LEVEL, - "timing_allowed_candidate_over_baseline_ratio": NO_SLOWDOWN_RATIO, - "material_rss_candidate_over_baseline_ratio": material_rss_ratio, - "warmup_runs": 2, - "target_runtime_seconds": 5.0, - }, - "cell_count": len(cell_results), - "passing_cell_count": sum(cell.get("passes") is True for cell in cell_results), - "cells": cell_results, - } - - -def _json_object(path: Path) -> dict[str, Any]: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error: - raise RuntimeABError(f"cannot read campaign JSON: {path}") from error - if not isinstance(value, dict): - raise RuntimeABError("campaign JSON must contain one object") - return value - - -def _positive_cli_int(value: str) -> int: - parsed = int(value) - if parsed <= 0: - raise argparse.ArgumentTypeError("must be a positive integer") - return parsed - - -def _material_rss_ratio(value: str) -> float: - parsed = float(value) - if not math.isfinite(parsed) or parsed < 1.0: - raise argparse.ArgumentTypeError("must be finite and at least 1.0") - return parsed - - -def _write_json(path: Path, value: object, *, replace: bool) -> None: - allowed = ALLOWED_OUTPUT_PARENT.resolve() - destination = path.expanduser().resolve() - try: - destination.relative_to(allowed) - except ValueError as error: - raise RuntimeABError( - f"output must remain under {ALLOWED_OUTPUT_PARENT}" - ) from error - if destination.exists() and not replace: - raise RuntimeABError( - f"output already exists; pass --replace to overwrite: {destination}" - ) - destination.parent.mkdir(parents=True, exist_ok=True) - temporary = destination.with_name(f".{destination.name}.tmp-{os.getpid()}") - try: - temporary.write_text( - json.dumps(value, allow_nan=False, indent=2, sort_keys=True) + "\n", - encoding="utf-8", - ) - os.replace(temporary, destination) - except (OSError, TypeError, ValueError) as error: - temporary.unlink(missing_ok=True) - raise RuntimeABError(f"cannot write analysis JSON: {destination}") from error - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - result.add_argument("--campaign", type=Path, required=True) - result.add_argument("--output-json", type=Path) - result.add_argument("--replace", action="store_true") - result.add_argument( - "--n", - dest="multiplicities", - action="append", - type=_positive_cli_int, - ) - result.add_argument("--layout", action="append", choices=LAYOUTS) - result.add_argument( - "--batch-size", - action="append", - type=_positive_cli_int, - ) - result.add_argument( - "--material-rss-ratio", - type=_material_rss_ratio, - default=DEFAULT_MATERIAL_RSS_RATIO, - help="largest candidate/baseline runtime RSS ratio accepted (default: 1.10)", - ) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - try: - arguments = parser().parse_args(argv) - campaign = _json_object(arguments.campaign) - analysis = analyze_campaign( - campaign, - multiplicities=( - DEFAULT_MULTIPLICITIES - if arguments.multiplicities is None - else arguments.multiplicities - ), - layouts=LAYOUTS if arguments.layout is None else arguments.layout, - batch_sizes=( - DEFAULT_BATCH_SIZES - if arguments.batch_size is None - else arguments.batch_size - ), - material_rss_ratio=arguments.material_rss_ratio, - ) - if arguments.output_json is not None: - _write_json(arguments.output_json, analysis, replace=arguments.replace) - except RuntimeABError as error: - print(f"recurrence-runtime-ab-analyzer: {error}", file=sys.stderr) - return 2 - print(json.dumps(analysis, allow_nan=False, sort_keys=True)) - return 0 if analysis["passes"] is True else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/recurrence_semantic_census.py b/pyamplicol/tools/developer/recurrence_semantic_census.py deleted file mode 100644 index 5494c1e254..0000000000 --- a/pyamplicol/tools/developer/recurrence_semantic_census.py +++ /dev/null @@ -1,1211 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Fail-closed semantic census comparison for recurrence artifacts. - -This developer-only tool deliberately reuses pyAmpliCol's authenticated -artifact inventory, prepared-kernel-pack decoders, and native recurrence exact -section loader. It does not decode ``recurrence-runtime.pacbin`` or -``recurrence-binding.bin`` independently. - -The persisted exact sections enumerate current support/state projections, -runtime interactions, closures, selector axes, and layout. Some pre-lowering -``CurrentCoreKey`` fields—notably dynamic LC color-state and local helicity -identities—are intentionally absent from the runtime ABI. Those fields are -therefore authenticated transitively by the process/native semantic digests -and the exact selector/catalog projections; this tool never claims to -reconstruct them. -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import re -import sys -from collections.abc import Iterable, Mapping, Sequence -from dataclasses import astuple, dataclass -from pathlib import Path -from typing import Any - -from pyamplicol.models.prepared import EAGER_KERNEL_ABI, PreparedKernelPack -from pyamplicol.models.recurrence_direct_template import ( - RECURRENCE_DIRECT_IDENTITY_FINALIZER, -) -from pyamplicol.runtime.recurrence_exact._execution import _role_index -from pyamplicol.runtime.recurrence_exact._plan_v2 import ( - DIRECT_NONE_U32, - _load_recurrence_exact_sections_v1, - _RecurrenceExactSectionsV1, -) -from tools.developer.recurrence_artifact_compare import ( - ArtifactSnapshot, - _json_object, - _load_artifact, -) -from tools.developer.recurrence_artifact_compare import ( - ComparisonError as ArtifactComparisonError, -) - -CENSUS_KIND = "pyamplicol-recurrence-semantic-census" -CENSUS_SCHEMA_VERSION = 1 -COMPARISON_KIND = "pyamplicol-recurrence-semantic-census-comparison" -COMPARISON_SCHEMA_VERSION = 1 -MAX_REPORTED_DIFFERENCES = 256 -_UNASSIGNED_ROW = object() - -_SHA256_RE = re.compile(r"[0-9a-f]{64}") -_EXECUTION_PATH_RE = re.compile(r"processes/([^/]+)/execution[.]json") -_REQUIRED_DOMAINS = frozenset( - { - "digests", - "currents", - "sources", - "contribution_multisets", - "closures", - "selectors", - "normalization_and_parameters", - "semantic_catalog_bindings", - "runtime_layout", - } -) -_CATALOG_SECTION_NAMES = ( - "parameters", - "current_states", - "sources", - "quantum_flows", - "transitions", - "propagators", - "closures", - "color_contractions", - "symmetry_proofs", - "runtime_helicity_contracts", - "evaluator_bindings", -) -_STORAGE_AUTHENTICATION_DIGEST_FIELDS = frozenset( - { - "runtime_container_index_sha256", - "runtime_container_sha256", - "runtime_plan_member_sha256", - "process_binding_sha256", - } -) - - -class SemanticCensusError(RuntimeError): - """Raised when an input cannot produce an authenticated exact census.""" - - -@dataclass(frozen=True, slots=True) -class ExecutorSemanticBinding: - """Authenticated semantic context for one exact runtime executor.""" - - executor_id: int - role: str - semantic_digest: str - semantic_template_ids: tuple[str, ...] - direct_template: Mapping[str, object] - referenced_semantic_records: tuple[Mapping[str, object], ...] - - -def _mapping(value: object, context: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping) or not all(isinstance(key, str) for key in value): - raise SemanticCensusError(f"{context} must be an object with string keys") - return value - - -def _sequence(value: object, context: str) -> Sequence[Any]: - if isinstance(value, str | bytes | bytearray) or not isinstance(value, Sequence): - raise SemanticCensusError(f"{context} must be an array") - return value - - -def _sha256(value: object, context: str) -> str: - if not isinstance(value, str) or _SHA256_RE.fullmatch(value) is None: - raise SemanticCensusError(f"{context} must be a lowercase SHA-256") - return value - - -def _nonnegative_int(value: object, context: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise SemanticCensusError(f"{context} must be a non-negative integer") - return value - - -def _canonical_bytes(value: object) -> bytes: - try: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - except (TypeError, ValueError) as error: - raise SemanticCensusError( - "semantic census value is not canonical JSON" - ) from error - - -def _domain_census(name: str, records: Iterable[object]) -> dict[str, object]: - digest = hashlib.sha256() - domain = name.encode("ascii") - digest.update(len(domain).to_bytes(8, "little")) - digest.update(domain) - _count = 0 - for _count, record in enumerate(records, start=1): - encoded = _canonical_bytes(record) - digest.update(len(encoded).to_bytes(8, "little")) - digest.update(encoded) - return { - "record_count": _count, - "sha256": digest.hexdigest(), - } - - -def _exact_factor( - sections: _RecurrenceExactSectionsV1, - factor_id: int, - context: str, -) -> tuple[int, int, int, int]: - if factor_id < 0 or factor_id >= len(sections.exact_factors): - raise SemanticCensusError(f"{context} references an absent exact factor") - return astuple(sections.exact_factors[factor_id]) - - -def _momentum( - sections: _RecurrenceExactSectionsV1, - form_id: int, - context: str, -) -> tuple[tuple[int, int], ...]: - if form_id < 0 or form_id >= len(sections.momentum_forms): - raise SemanticCensusError(f"{context} references an absent momentum form") - form = sections.momentum_forms[form_id] - stop = form.term_start + form.term_count - if form.term_start < 0 or stop > len(sections.momentum_terms): - raise SemanticCensusError(f"{context} momentum form is out of bounds") - terms = tuple( - (term.source_slot, term.coefficient) - for term in sections.momentum_terms[form.term_start : stop] - ) - if any( - slot >= sections.external_source_count or coefficient == 0 - for slot, coefficient in terms - ) or tuple(slot for slot, _ in terms) != tuple(sorted({slot for slot, _ in terms})): - raise SemanticCensusError(f"{context} momentum form is not canonical") - return terms - - -def _executor_rows( - sections: _RecurrenceExactSectionsV1, - role: str, - row_count: int, - bindings: Mapping[int, ExecutorSemanticBinding], - *, - allow_unbound: bool = False, -) -> tuple[ExecutorSemanticBinding | None, ...]: - expected_role = _role_index(role) - result: list[ExecutorSemanticBinding | object | None] = [ - _UNASSIGNED_ROW - ] * row_count - for group_index, group in enumerate(sections.row_groups): - if group.role != expected_role: - continue - binding = ( - None - if allow_unbound and group.executor_id == DIRECT_NONE_U32 - else bindings.get(group.executor_id) - ) - if binding is None and not ( - allow_unbound and group.executor_id == DIRECT_NONE_U32 - ): - raise SemanticCensusError( - f"{role} row group {group_index} has no matching semantic executor" - ) - if binding is not None and binding.role != role: - raise SemanticCensusError( - f"{role} row group {group_index} has no matching semantic executor" - ) - stop = group.row_start + group.row_count - if group.row_start < 0 or stop > row_count: - raise SemanticCensusError( - f"{role} row group {group_index} is out of bounds" - ) - for row_id in range(group.row_start, stop): - if result[row_id] is not _UNASSIGNED_ROW: - raise SemanticCensusError( - f"{role} runtime row {row_id} belongs to multiple row groups" - ) - result[row_id] = binding - if any(binding is _UNASSIGNED_ROW for binding in result): - missing = next( - index for index, binding in enumerate(result) if binding is _UNASSIGNED_ROW - ) - raise SemanticCensusError( - f"{role} runtime row {missing} has no exact row-group owner" - ) - return tuple( - binding if isinstance(binding, ExecutorSemanticBinding) else None - for binding in result - ) - - -def _executor_reference(binding: ExecutorSemanticBinding) -> dict[str, object]: - return { - "direct_executor_id": binding.executor_id, - "direct_semantic_digest": binding.semantic_digest, - "semantic_template_ids": list(binding.semantic_template_ids), - } - - -def _current_records( - sections: _RecurrenceExactSectionsV1, - state_templates: Sequence[Mapping[str, object]], -) -> Iterable[dict[str, object]]: - for current in sections.currents: - if current.state_template_id >= len(state_templates): - raise SemanticCensusError( - f"current {current.semantic_id} references an absent state template" - ) - state = state_templates[current.state_template_id] - state_identity = { - "template_id": state.get("template_id"), - "semantic_digest": state.get("semantic_digest"), - } - if not isinstance(state_identity["template_id"], str): - raise SemanticCensusError( - f"current {current.semantic_id} state template has no identity" - ) - _sha256( - state_identity["semantic_digest"], - f"current {current.semantic_id} state semantic digest", - ) - momentum = _momentum( - sections, - current.momentum_form_id, - f"current {current.semantic_id}", - ) - source: object = None - if current.source_row != DIRECT_NONE_U32: - if current.source_row >= len(sections.sources): - raise SemanticCensusError( - f"current {current.semantic_id} references an absent source row" - ) - source_row = sections.sources[current.source_row] - source = { - "row_id": current.source_row, - "source_slot": source_row.source_slot, - "spin_state_class": source_row.spin_state_class, - "source_template_or_dispatch_domain": ( - source_row.source_template_or_dispatch_domain - ), - } - yield { - "semantic_id": current.semantic_id, - "node_kind": current.node_kind, - "state_template_id": current.state_template_id, - "state_template": state_identity, - "component_count": current.component_count, - "momentum": momentum, - "support_source_slots": [slot for slot, _ in momentum], - "stage": current.stage, - # The runtime ABI persists selector domains, not the discarded - # dynamic color/local-helicity CurrentCoreKey fields. - "color_selector_domain_id": current.selector_domain_id, - "helicity_selector_domain_id": current.selector_domain_id, - "source": source, - "finalization_row": ( - None - if current.finalization_row == DIRECT_NONE_U32 - else current.finalization_row - ), - } - - -def _source_records( - sections: _RecurrenceExactSectionsV1, - bindings: Mapping[int, ExecutorSemanticBinding], - source_metadata: Mapping[str, object], -) -> Iterable[dict[str, object]]: - yield {"runtime_source_metadata": source_metadata} - executor_rows = _executor_rows( - sections, - "source", - len(sections.sources), - bindings, - allow_unbound=True, - ) - for row_id, (source, binding) in enumerate( - zip(sections.sources, executor_rows, strict=True) - ): - yield { - "row_id": row_id, - "source_slot": source.source_slot, - "destination_component_base": source.destination_base, - "momentum": _momentum( - sections, source.momentum_form_id, f"source row {row_id}" - ), - "source_template_or_dispatch_domain": ( - source.source_template_or_dispatch_domain - ), - "spin_state_class": source.spin_state_class, - "exact_factor": _exact_factor( - sections, source.exact_factor_id, f"source row {row_id}" - ), - "selector_domain_id": source.selector_domain_id, - "executor": (None if binding is None else _executor_reference(binding)), - } - - -def _contribution_records( - sections: _RecurrenceExactSectionsV1, - bindings: Mapping[int, ExecutorSemanticBinding], -) -> Iterable[dict[str, object]]: - executor_rows = _executor_rows( - sections, - "contribution", - len(sections.contributions), - bindings, - ) - for row_id, (row, binding) in enumerate( - zip(sections.contributions, executor_rows, strict=True) - ): - parent1 = ( - None - if row.parent1_base == DIRECT_NONE_U32 - else { - "component_base": row.parent1_base, - "momentum": _momentum( - sections, - row.parent1_momentum, - f"contribution {row_id} parent 1", - ), - } - ) - yield { - # The native constructor emits this table in canonical key order, - # so hashing persisted order is also a canonical multiset census, - # independent of transient candidate-enumeration order. - "canonical_row_id": row_id, - "parents": [ - { - "component_base": row.parent0_base, - "momentum": _momentum( - sections, - row.parent0_momentum, - f"contribution {row_id} parent 0", - ), - }, - parent1, - ], - "destination_component_base": row.destination_base, - "exact_factor": _exact_factor( - sections, row.exact_factor_id, f"contribution {row_id}" - ), - "selector_domain_id": row.selector_domain_id, - "flags": row.flags, - "executor": _executor_reference(binding), - } - - -def _closure_records( - sections: _RecurrenceExactSectionsV1, - bindings: Mapping[int, ExecutorSemanticBinding], -) -> Iterable[dict[str, object]]: - executor_rows = _executor_rows( - sections, "closure", len(sections.closures), bindings - ) - for row_id, (row, binding) in enumerate( - zip(sections.closures, executor_rows, strict=True) - ): - parent1 = ( - None - if row.parent1_base == DIRECT_NONE_U32 - else { - "component_base": row.parent1_base, - "momentum": _momentum( - sections, - row.parent1_momentum, - f"closure {row_id} parent 1", - ), - } - ) - yield { - "canonical_row_id": row_id, - "parents": [ - { - "component_base": row.parent0_base, - "momentum": _momentum( - sections, - row.parent0_momentum, - f"closure {row_id} parent 0", - ), - }, - parent1, - ], - "amplitude_destination_id": row.amplitude_destination_id, - "exact_factor": _exact_factor( - sections, row.exact_factor_id, f"closure {row_id}" - ), - "component_factor_start": row.component_factor_start, - "component_count": row.component_count, - "selector_domain_id": row.selector_domain_id, - "flags": row.flags, - "executor": _executor_reference(binding), - } - - -def _selector_records( - sections: _RecurrenceExactSectionsV1, - selector_metadata: Mapping[str, object], -) -> Iterable[dict[str, object]]: - yield {"runtime_selector_metadata": selector_metadata} - tables = ( - ("replay_targets", sections.replay_targets), - ("source_permutations", sections.source_permutations), - ("replay_momentum_signs", sections.replay_momentum_signs), - ("replay_helicity_map", sections.replay_helicity_map), - ("amplitude_destinations", sections.amplitude_destinations), - ("resolved_helicities", sections.resolved_helicities), - ("source_state_assignments", sections.source_state_assignments), - ("source_dispatch_variants", sections.source_dispatch_variants), - ("source_embeddings", sections.source_embeddings), - ("source_projections", sections.source_projections), - ("resolved_source_selections", sections.resolved_source_selections), - ("public_helicities", sections.public_helicities), - ("public_flow_ids", sections.public_flow_ids), - ) - for name, rows in tables: - yield {"table": name, "row_count": len(rows)} - for row_id, row in enumerate(rows): - yield { - "table": name, - "row_id": row_id, - "row": (astuple(row) if hasattr(row, "__dataclass_fields__") else row), - } - - -def _semantic_catalog_records( - bindings: Mapping[int, ExecutorSemanticBinding], - sections: _RecurrenceExactSectionsV1, -) -> Iterable[dict[str, object]]: - used_executor_ids = sorted( - { - group.executor_id - for group in sections.row_groups - if group.executor_id != DIRECT_NONE_U32 - } - ) - for executor_id in used_executor_ids: - binding = bindings.get(executor_id) - if binding is None: - raise SemanticCensusError( - f"runtime schedule references absent direct executor {executor_id}" - ) - yield { - "direct_executor_id": executor_id, - "direct_template": binding.direct_template, - "referenced_semantic_records": list(binding.referenced_semantic_records), - } - - -def _runtime_layout_records( - sections: _RecurrenceExactSectionsV1, -) -> Iterable[dict[str, object]]: - yield { - "counts": { - "current_arena_components": sections.current_arena_components, - "amplitude_destination_count": sections.amplitude_destination_count, - "parameter_value_count": sections.parameter_value_count, - "external_source_count": sections.external_source_count, - } - } - for name, rows in ( - ("currents", sections.currents), - ("sources", sections.sources), - ("contributions", sections.contributions), - ("finalizations", sections.finalizations), - ("closures", sections.closures), - ("row_groups", sections.row_groups), - ("momentum_forms", sections.momentum_forms), - ("momentum_terms", sections.momentum_terms), - ("exact_factors", sections.exact_factors), - ("executors", sections.executors), - ): - yield {"table": name, "row_count": len(rows)} - for row_id, row in enumerate(rows): - yield {"table": name, "row_id": row_id, "row": astuple(row)} - - -def build_semantic_census( - *, - sections: _RecurrenceExactSectionsV1, - process_metadata: Mapping[str, object], - executor_bindings: Mapping[int, ExecutorSemanticBinding], - state_templates: Sequence[Mapping[str, object]], -) -> dict[str, object]: - """Build one timing-free census from already authenticated typed inputs.""" - - raw_digests = _mapping(process_metadata.get("digests"), "process metadata digests") - digests = { - key: value - for key, value in raw_digests.items() - if key not in _STORAGE_AUTHENTICATION_DIGEST_FIELDS - } - normalization = _mapping( - process_metadata.get("normalization_and_parameters"), - "process normalization/parameters", - ) - selector_metadata = _mapping( - process_metadata.get("selectors"), "process selector metadata" - ) - source_metadata = _mapping( - process_metadata.get("sources"), "process source metadata" - ) - if digests.get("process_semantic_digest") != sections.semantic_digest: - raise SemanticCensusError( - "process metadata semantic digest does not match exact sections" - ) - if digests.get("runtime_layout_digest") != sections.runtime_layout_digest: - raise SemanticCensusError( - "process metadata runtime-layout digest does not match exact sections" - ) - - domains = { - "digests": _domain_census("digests", (digests,)), - "currents": _domain_census( - "currents", _current_records(sections, state_templates) - ), - "sources": _domain_census( - "sources", - _source_records(sections, executor_bindings, source_metadata), - ), - "contribution_multisets": _domain_census( - "contribution_multisets", - _contribution_records(sections, executor_bindings), - ), - "closures": _domain_census( - "closures", _closure_records(sections, executor_bindings) - ), - "selectors": _domain_census( - "selectors", _selector_records(sections, selector_metadata) - ), - "normalization_and_parameters": _domain_census( - "normalization_and_parameters", (normalization,) - ), - "semantic_catalog_bindings": _domain_census( - "semantic_catalog_bindings", - _semantic_catalog_records(executor_bindings, sections), - ), - "runtime_layout": _domain_census( - "runtime_layout", _runtime_layout_records(sections) - ), - } - if set(domains) != _REQUIRED_DOMAINS: # pragma: no cover - construction invariant - raise SemanticCensusError("semantic census domain coverage is incomplete") - content = { - "kind": CENSUS_KIND, - "schema_version": CENSUS_SCHEMA_VERSION, - "process_id": sections.process_id, - "strategy": sections.strategy, - "coverage": { - "exact_sections_decoder": ( - "pyamplicol.runtime.recurrence_exact._plan_v2." - "_load_recurrence_exact_sections_v1" - ), - "prepared_catalog_decoder": ( - "pyamplicol.models.prepared.PreparedKernelPack.from_dict" - ), - "directly_enumerated": [ - "current semantic IDs, node kinds, state templates, momentum support", - "source rows and spin-state classes", - "canonical contribution rows, signs, and runtime endpoints", - "closures and amplitude destinations", - "flow/helicity/source-dispatch selector axes", - "normalization, parameter projection, and runtime layout", - ], - "transitively_authenticated_not_reconstructed": [ - "pre-lowering dynamic LC color-state IDs", - "pre-lowering local current-helicity identities", - "discarded construction-only flavour/quantum/coupling key fields", - ], - "canonical_contribution_policy": ( - "persisted-native-canonical-emission-is-the-multiset-order-v1" - ), - }, - "domains": domains, - } - content["census_sha256"] = hashlib.sha256(_canonical_bytes(content)).hexdigest() - return content - - -def _semantic_record_index( - catalog_payload: Mapping[str, object], -) -> tuple[dict[str, Mapping[str, object]], tuple[Mapping[str, object], ...]]: - by_id: dict[str, Mapping[str, object]] = {} - state_templates: tuple[Mapping[str, object], ...] = () - for section_name in _CATALOG_SECTION_NAMES: - rows = _sequence( - catalog_payload.get(section_name), - f"recurrence catalog {section_name}", - ) - parsed_rows: list[Mapping[str, object]] = [] - for index, raw in enumerate(rows): - row = _mapping(raw, f"recurrence catalog {section_name}[{index}]") - identity = row.get("template_id", row.get("resolver_key")) - if not isinstance(identity, str) or not identity: - raise SemanticCensusError( - f"recurrence catalog {section_name}[{index}] lacks an identity" - ) - if identity in by_id: - raise SemanticCensusError( - f"recurrence catalog repeats semantic identity {identity!r}" - ) - by_id[identity] = row - parsed_rows.append(row) - if section_name == "current_states": - state_templates = tuple(parsed_rows) - if not state_templates: - raise SemanticCensusError("recurrence catalog has no current-state templates") - return by_id, state_templates - - -def _referenced_record_closure( - roots: Iterable[str], - records: Mapping[str, Mapping[str, object]], -) -> tuple[Mapping[str, object], ...]: - pending = list(roots) - visited: set[str] = set() - - def references(value: object) -> Iterable[str]: - if isinstance(value, str): - if value in records: - yield value - elif isinstance(value, Mapping): - for child in value.values(): - yield from references(child) - elif isinstance(value, Sequence) and not isinstance( - value, str | bytes | bytearray - ): - for child in value: - yield from references(child) - - while pending: - identity = pending.pop() - if identity in visited: - continue - record = records.get(identity) - if record is None: - raise SemanticCensusError( - f"direct executor references absent semantic record {identity!r}" - ) - visited.add(identity) - pending.extend( - reference for reference in references(record) if reference not in visited - ) - return tuple(records[identity] for identity in sorted(visited)) - - -def _executor_bindings( - pack: PreparedKernelPack, - sections: _RecurrenceExactSectionsV1, -) -> tuple[ - dict[int, ExecutorSemanticBinding], - tuple[Mapping[str, object], ...], -]: - semantic_catalog = pack.recurrence_template_catalog - direct_catalog = pack.recurrence_direct_template_catalog - if semantic_catalog is None or direct_catalog is None: - raise SemanticCensusError( - "prepared kernel pack lacks authenticated recurrence catalogs" - ) - semantic_payload = semantic_catalog.to_dict() - record_by_id, state_templates = _semantic_record_index(semantic_payload) - bindings: dict[int, ExecutorSemanticBinding] = {} - for template in direct_catalog.templates: - roots = template.semantic_template_ids - if template.evaluator_resolver_key != RECURRENCE_DIRECT_IDENTITY_FINALIZER: - roots = (*roots, template.evaluator_resolver_key) - binding = ExecutorSemanticBinding( - executor_id=template.direct_executor_id, - role=template.role, - semantic_digest=template.semantic_digest, - semantic_template_ids=template.semantic_template_ids, - direct_template=template.to_dict(), - referenced_semantic_records=_referenced_record_closure(roots, record_by_id), - ) - if binding.executor_id in bindings: - raise SemanticCensusError( - f"direct catalog repeats executor {binding.executor_id}" - ) - bindings[binding.executor_id] = binding - - if len(sections.executors) != len(bindings): - raise SemanticCensusError( - "exact executor inventory differs from the authenticated direct catalog" - ) - for executor in sections.executors: - binding = bindings.get(executor.executor_id) - if binding is None: - raise SemanticCensusError( - f"exact sections reference absent executor {executor.executor_id}" - ) - template = binding.direct_template - expected = ( - binding.role, - template.get("destination_operation"), - tuple(_sequence(template.get("parent_component_counts"), "parent counts")), - template.get("destination_component_count"), - template.get("momentum_operand_count"), - _mapping(template.get("payload_binding"), "direct payload binding").get( - "prepared_kernel_id" - ), - _mapping(template.get("payload_binding"), "direct payload binding").get( - "runtime_template" - ), - ) - actual = ( - executor.role, - executor.destination_operation, - executor.parent_component_counts, - executor.destination_component_count, - executor.momentum_operand_count, - executor.prepared_kernel_id, - executor.runtime_template, - ) - if actual != expected: - raise SemanticCensusError( - "exact executor " - f"{executor.executor_id} differs from its direct template" - ) - return bindings, state_templates - - -def _schedule_summary_counts( - sections: _RecurrenceExactSectionsV1, -) -> dict[str, int]: - return { - "amplitude_destination_count": len(sections.amplitude_destinations), - "closure_term_count": len(sections.closures), - "contribution_count": len(sections.contributions), - "current_count": len(sections.currents), - "exact_factor_count": len(sections.exact_factors), - "finalization_count": len(sections.finalizations), - "replay_target_count": len(sections.replay_targets), - "resolved_helicity_count": len(sections.resolved_helicities), - "source_row_count": len(sections.sources), - } - - -def _process_metadata( - *, - snapshot: ArtifactSnapshot, - process_id: str, - execution: Mapping[str, object], - sections: _RecurrenceExactSectionsV1, - pack: PreparedKernelPack, -) -> dict[str, object]: - if execution.get("key") != process_id: - raise SemanticCensusError("execution key does not match its process path") - plan = _mapping(execution.get("plan"), "recurrence execution plan") - inspection = _mapping( - plan.get("inspection_summary"), "recurrence inspection summary" - ) - binding = _mapping(plan.get("process_binding"), "recurrence process binding") - runtime_schedule = _mapping( - plan.get("runtime_schedule"), "recurrence runtime schedule" - ) - runtime_metadata = _mapping( - execution.get("runtime_metadata"), "recurrence runtime metadata" - ) - schedule_summary = _mapping( - inspection.get("schedule"), "recurrence schedule summary" - ) - expected_counts = _schedule_summary_counts(sections) - for name, expected in expected_counts.items(): - if schedule_summary.get(name) != expected: - raise SemanticCensusError( - f"inspection schedule count {name} differs from exact sections" - ) - - direct_catalog = pack.recurrence_direct_template_catalog - semantic_catalog = pack.recurrence_template_catalog - assert direct_catalog is not None and semantic_catalog is not None - schedule_digest = _sha256( - inspection.get("schedule_digest"), "inspection schedule digest" - ) - schedule_path = runtime_schedule.get("path") - if not isinstance(schedule_path, str) or schedule_path not in snapshot.payloads: - raise SemanticCensusError( - "runtime schedule path is absent from the authenticated artifact" - ) - schedule_payload = snapshot.payloads[schedule_path] - if ( - _sha256( - runtime_schedule.get("sha256"), - "runtime container digest", - ) - != schedule_payload.sha256 - or _nonnegative_int( - runtime_schedule.get("size_bytes"), - "runtime container size", - ) - != schedule_payload.size_bytes - ): - raise SemanticCensusError( - "runtime schedule metadata does not authenticate its payload" - ) - path_parts = Path(schedule_path).parts - if len(path_parts) < 3 or path_parts[-2] != schedule_digest: - raise SemanticCensusError( - "runtime schedule path does not embed the inspection schedule digest" - ) - - semantic_digest = _sha256( - binding.get("process_semantic_digest"), "process semantic digest" - ) - runtime_layout_digest = _sha256( - inspection.get("runtime_layout_digest"), "runtime-layout digest" - ) - _sha256( - runtime_schedule.get("index_sha256"), - "runtime container index digest", - ) - _sha256( - _mapping( - inspection.get("runtime_container_member"), - "runtime container member", - ).get("sha256"), - "runtime plan member digest", - ) - binding_path = binding.get("path") - if not isinstance(binding_path, str) or not binding_path: - raise SemanticCensusError("process binding path is invalid") - binding_payload = snapshot.payloads.get(f"processes/{process_id}/{binding_path}") - if binding_payload is None or ( - _sha256(binding.get("sha256"), "process binding digest") - != binding_payload.sha256 - or _nonnegative_int(binding.get("size_bytes"), "process binding size") - != binding_payload.size_bytes - ): - raise SemanticCensusError( - "process binding metadata does not authenticate its payload" - ) - equalities = ( - (sections.process_id, process_id, "exact process identity"), - (sections.strategy, inspection.get("lc_flow_layout"), "recurrence strategy"), - (sections.semantic_digest, semantic_digest, "exact semantic digest"), - ( - plan.get("builder_input_sha256"), - semantic_digest, - "builder-input semantic digest", - ), - ( - inspection.get("semantic_digest"), - semantic_digest, - "inspection semantic digest", - ), - ( - sections.runtime_layout_digest, - runtime_layout_digest, - "exact runtime-layout digest", - ), - ( - binding.get("schedule_digest"), - schedule_digest, - "process-binding schedule digest", - ), - ( - execution.get("direct_template_catalog_digest"), - direct_catalog.catalog_digest, - "execution direct-template digest", - ), - ( - plan.get("direct_template_catalog_digest"), - direct_catalog.catalog_digest, - "plan direct-template digest", - ), - ( - execution.get("prepared_kernel_pack_digest"), - direct_catalog.prepared_kernel_pack_digest, - "execution prepared-pack digest", - ), - ( - plan.get("prepared_kernel_pack_digest"), - direct_catalog.prepared_kernel_pack_digest, - "plan prepared-pack digest", - ), - ( - direct_catalog.recurrence_template_catalog_digest, - semantic_catalog.header.catalog_digest, - "semantic/direct recurrence catalog digest", - ), - ) - for actual, expected, context in equalities: - if actual != expected: - raise SemanticCensusError(f"{context} is inconsistent") - - digests = { - "process_semantic_digest": semantic_digest, - "native_schedule_semantic_digest": _sha256( - binding.get("native_schedule_semantic_digest"), - "native schedule semantic digest", - ), - "runtime_layout_digest": runtime_layout_digest, - "schedule_digest": schedule_digest, - "builder_input_sha256": _sha256( - plan.get("builder_input_sha256"), "builder input digest" - ), - "direct_template_catalog_digest": direct_catalog.catalog_digest, - "recurrence_template_catalog_digest": (semantic_catalog.header.catalog_digest), - "prepared_kernel_pack_digest": direct_catalog.prepared_kernel_pack_digest, - "process_binding_remap": binding.get("remap"), - "process_support_words": binding.get("process_support_words"), - "abis": { - "builder_input": execution.get("builder_input_abi"), - "direct_backend": execution.get("direct_backend_abi"), - "direct_template": execution.get("direct_template_abi"), - "recurrence_plan": execution.get("recurrence_plan_abi"), - "runtime_layout": execution.get("runtime_layout_abi"), - "process_binding": binding.get("abi"), - }, - } - return { - "digests": digests, - "normalization_and_parameters": { - "normalization": runtime_metadata.get("normalization"), - "parameter_projection": runtime_metadata.get("parameter_projection"), - "prepared_parameter_defaults": runtime_metadata.get( - "prepared_parameter_defaults" - ), - "runtime_parameters": runtime_metadata.get("runtime_parameters"), - "parameter_value_count": sections.parameter_value_count, - }, - "selectors": { - "color_accuracy": execution.get("color_accuracy"), - "color_contraction": runtime_metadata.get("color_contraction"), - "public_color_flows": runtime_metadata.get("public_color_flows"), - "runtime_options": execution.get("runtime_options"), - }, - "sources": { - "process": execution.get("process"), - "external_pdg_order": execution.get("external_pdg_order"), - "external_legs": runtime_metadata.get("external_legs"), - "particle_masses": runtime_metadata.get("particle_masses"), - "source_templates": runtime_metadata.get("source_templates"), - }, - } - - -def _load_pack(snapshot: ArtifactSnapshot) -> PreparedKernelPack: - relative = "model/eager-kernel-pack.json" - payload = snapshot.payloads.get(relative) - if payload is None: - raise SemanticCensusError( - "recurrence artifact lacks the prepared kernel-pack manifest" - ) - raw = _json_object(payload.path, description="prepared kernel pack") - kernel_abi = raw.pop("eager_kernel_abi", None) - if kernel_abi != EAGER_KERNEL_ABI: - raise SemanticCensusError( - f"prepared kernel pack has unsupported eager ABI {kernel_abi!r}" - ) - try: - return PreparedKernelPack.from_dict(raw) - except ValueError as error: - raise SemanticCensusError( - "prepared kernel pack failed authoritative decoding" - ) from error - - -def _artifact_censuses(snapshot: ArtifactSnapshot) -> dict[str, dict[str, object]]: - pack = _load_pack(snapshot) - result: dict[str, dict[str, object]] = {} - for execution_path in sorted(snapshot.executions): - match = _EXECUTION_PATH_RE.fullmatch(execution_path) - if match is None: # pragma: no cover - authenticated by artifact loader - raise SemanticCensusError( - f"unexpected recurrence execution path {execution_path!r}" - ) - process_id = match.group(1) - try: - sections = _load_recurrence_exact_sections_v1(snapshot.root, process_id) - except Exception as error: - raise SemanticCensusError( - f"native exact-section loading failed for process {process_id!r}" - ) from error - bindings, state_templates = _executor_bindings(pack, sections) - execution = snapshot.executions[execution_path] - metadata = _process_metadata( - snapshot=snapshot, - process_id=process_id, - execution=execution, - sections=sections, - pack=pack, - ) - result[process_id] = build_semantic_census( - sections=sections, - process_metadata=metadata, - executor_bindings=bindings, - state_templates=state_templates, - ) - if not result: - raise SemanticCensusError("recurrence artifact has no process census") - return result - - -def compare_census_sets( - baseline: Mapping[str, Mapping[str, object]], - candidate: Mapping[str, Mapping[str, object]], -) -> dict[str, object]: - """Compare two already-built process-census sets without an allowlist.""" - - differences: list[dict[str, object]] = [] - baseline_ids = set(baseline) - candidate_ids = set(candidate) - for process_id in sorted(baseline_ids - candidate_ids): - differences.append( - { - "kind": "process-inventory", - "process_id": process_id, - "baseline": "present", - "candidate": "missing", - } - ) - for process_id in sorted(candidate_ids - baseline_ids): - differences.append( - { - "kind": "process-inventory", - "process_id": process_id, - "baseline": "missing", - "candidate": "present", - } - ) - process_reports: list[dict[str, object]] = [] - for process_id in sorted(baseline_ids & candidate_ids): - left = baseline[process_id] - right = candidate[process_id] - for field in ("kind", "schema_version", "process_id", "strategy", "coverage"): - if left.get(field) != right.get(field): - differences.append( - { - "kind": "census-contract", - "process_id": process_id, - "field": field, - "baseline": left.get(field), - "candidate": right.get(field), - } - ) - left_domains = _mapping(left.get("domains"), "baseline census domains") - right_domains = _mapping(right.get("domains"), "candidate census domains") - if ( - set(left_domains) != _REQUIRED_DOMAINS - or set(right_domains) != _REQUIRED_DOMAINS - ): - raise SemanticCensusError( - f"process {process_id!r} has incomplete census domains" - ) - matched: list[str] = [] - changed: list[str] = [] - for domain in sorted(_REQUIRED_DOMAINS): - left_domain = _mapping( - left_domains[domain], f"baseline {process_id} {domain}" - ) - right_domain = _mapping( - right_domains[domain], f"candidate {process_id} {domain}" - ) - if left_domain == right_domain: - matched.append(domain) - continue - changed.append(domain) - differences.append( - { - "kind": "semantic-domain", - "process_id": process_id, - "domain": domain, - "baseline": dict(left_domain), - "candidate": dict(right_domain), - } - ) - process_reports.append( - { - "process_id": process_id, - "strategy": left.get("strategy"), - "matched_domains": matched, - "changed_domains": changed, - "baseline_census_sha256": left.get("census_sha256"), - "candidate_census_sha256": right.get("census_sha256"), - "passes": not changed - and all( - difference.get("process_id") != process_id - for difference in differences - ), - } - ) - difference_count = len(differences) - return { - "kind": COMPARISON_KIND, - "schema_version": COMPARISON_SCHEMA_VERSION, - "passes": difference_count == 0, - "policy": { - "allowlisted_differences": [], - "domain_set": sorted(_REQUIRED_DOMAINS), - "unknown_or_missing_domains": "reject", - "nonpersisted_pre_lowering_keys": ( - "authenticate-transitively-never-reconstruct-v1" - ), - }, - "processes": process_reports, - "difference_count": difference_count, - "differences_truncated": difference_count > MAX_REPORTED_DIFFERENCES, - "differences": differences[:MAX_REPORTED_DIFFERENCES], - } - - -def compare_artifact_censuses( - baseline_artifact: Path, - candidate_artifact: Path, -) -> dict[str, object]: - """Authenticate, decode, census, and compare two recurrence artifacts.""" - - try: - baseline_snapshot = _load_artifact(baseline_artifact, label="baseline") - candidate_snapshot = _load_artifact(candidate_artifact, label="candidate") - except ArtifactComparisonError as error: - raise SemanticCensusError(str(error)) from error - baseline = _artifact_censuses(baseline_snapshot) - candidate = _artifact_censuses(candidate_snapshot) - report = compare_census_sets(baseline, candidate) - report["baseline"] = { - "path": str(baseline_snapshot.root), - "artifact_id": baseline_snapshot.manifest["artifact_id"], - "process_count": len(baseline), - } - report["candidate"] = { - "path": str(candidate_snapshot.root), - "artifact_id": candidate_snapshot.manifest["artifact_id"], - "process_count": len(candidate), - } - return report - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - result.add_argument("--baseline", type=Path, required=True) - result.add_argument("--candidate", type=Path, required=True) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - try: - report = compare_artifact_censuses(arguments.baseline, arguments.candidate) - except SemanticCensusError as error: - print(f"recurrence-semantic-census: {error}", file=sys.stderr) - return 2 - print(json.dumps(report, indent=2, sort_keys=True, allow_nan=False)) - return 0 if report["passes"] else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/reset_performance_campaign.py b/pyamplicol/tools/developer/reset_performance_campaign.py deleted file mode 100644 index d754da7e47..0000000000 --- a/pyamplicol/tools/developer/reset_performance_campaign.py +++ /dev/null @@ -1,651 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -# ruff: noqa: E402 -"""Prepare, commit, recover, and verify one full report-campaign restart.""" - -from __future__ import annotations - -import argparse -import json -import os -import shutil -import subprocess -import sys -import tomllib -import uuid -from collections.abc import Mapping, Sequence -from pathlib import Path - -_REPOSITORY_ROOT = Path(__file__).resolve().parents[2] -if os.fspath(_REPOSITORY_ROOT) not in sys.path: - sys.path.insert(0, os.fspath(_REPOSITORY_ROOT)) - -from tools.performance_report.artifacts import ArtifactStore -from tools.performance_report.cache import empty_measurement -from tools.performance_report.campaign_activity import ( - blocking_process_lines, - is_snapshot_publisher_process, - parse_lsof_field_output, -) -from tools.performance_report.campaign_policy import validate_policy_profile -from tools.performance_report.campaign_reset import ( - BASELINE_GATE_FILENAME, - CAMPAIGN_MARKER_FILENAME, - EXPECTED_AMPLICOL_CELL_COUNT, - EXPECTED_CATALOG_CELL_COUNT, - EXPECTED_NON_AMPLICOL_CELL_COUNT, - CampaignResetError, - OriginalAmplicolSeed, - ResetTransactionPaths, - assert_campaign_marker, - build_seed_manifest, - campaign_marker, - canonical_json_bytes, - commit_or_recover_reset, - lightweight_archive_inventory, - mark_campaign_ready, - sha256_path, - sha256_payload, - stage_seed_store, - temporary_staging_root, - write_prepared_journal, -) -from tools.performance_report.catalog import REPORT_CATALOG -from tools.performance_report.models import ExecutionMode -from tools.performance_report.service import ReportPaths, ReportService -from tools.performance_report.source_identity import require_eligible_report_source -from tools.performance_report.workspace import load_profile_campaign_policy - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description=( - "Archive an old performance campaign and seed a clean epoch with " - "same-host authenticated original-AmpliCol currents." - ) - ) - subparsers = parser.add_subparsers(dest="command", required=True) - prepare = subparsers.add_parser("prepare") - for item in (prepare,): - item.add_argument("--source-repo-root", type=Path, required=True) - item.add_argument("--destination-repo-root", type=Path, required=True) - item.add_argument("--profile", required=True) - item.add_argument("--campaign-id", required=True) - item.add_argument("--archive-id", required=True) - item.add_argument("--expected-source-revision", required=True) - item.add_argument("--expected-source-tree", required=True) - item.add_argument("--source-artifact-root", type=Path) - item.add_argument("--source-coordination-root", type=Path) - item.add_argument("--destination-artifact-root", type=Path) - item.add_argument("--destination-coordination-root", type=Path) - item.add_argument("--archive-root", type=Path) - - for command in ("commit", "recover"): - item = subparsers.add_parser(command) - item.add_argument("--journal", type=Path, required=True) - - verify = subparsers.add_parser("verify-baseline") - verify.add_argument("--repo-root", type=Path, required=True) - verify.add_argument("--profile", required=True) - verify.add_argument("--campaign-id", required=True) - verify.add_argument("--expected-source-revision", required=True) - verify.add_argument("--expected-source-tree", required=True) - verify.add_argument("--expected-marker-sha256") - verify.add_argument("--artifact-root", type=Path) - verify.add_argument("--coordination-root", type=Path) - - marker = subparsers.add_parser("assert-marker") - marker.add_argument("--repo-root", type=Path, required=True) - marker.add_argument("--profile", required=True) - marker.add_argument("--campaign-id", required=True) - marker.add_argument("--expected-source-revision", required=True) - marker.add_argument("--expected-source-tree", required=True) - marker.add_argument("--expected-marker-sha256") - marker.add_argument("--artifact-root", type=Path) - return parser - - -def _run( - command: Sequence[str], - *, - cwd: Path, - check: bool = True, -) -> subprocess.CompletedProcess[str]: - return subprocess.run( - tuple(command), - cwd=cwd, - check=check, - capture_output=True, - text=True, - ) - - -def _strict_idle( - *, - coordination_roots: Sequence[Path], - entrypoints: Sequence[Path], -) -> None: - process_output = _run( - ("ps", "-axo", "pid=,comm=,args="), - cwd=Path.cwd(), - ).stdout - blocking = list( - blocking_process_lines( - process_output, - entrypoints=entrypoints, - ) - ) - for line in process_output.splitlines(): - fields = line.strip().split(None, 2) - if len(fields) == 3 and is_snapshot_publisher_process(fields[2]): - blocking.append(line.strip()) - if blocking: - raise CampaignResetError( - "campaign reset requires process idleness: " - + "; ".join(blocking[:12]) - ) - open_files: list[str] = [] - for root in coordination_roots: - if not root.exists(): - continue - result = _run( - ("lsof", "-Fpcfnt", "+D", os.fspath(root)), - cwd=Path.cwd(), - check=False, - ) - open_files.extend( - f"{item.pid}:{item.command}:{item.descriptor}:{item.path}" - for item in parse_lsof_field_output(result.stdout) - ) - if open_files: - raise CampaignResetError( - "campaign reset requires every coordination FD closed: " - + "; ".join(open_files[:12]) - ) - - -def _copy_tree(source: Path, destination: Path) -> None: - if destination.exists(): - raise CampaignResetError(f"staging destination already exists: {destination}") - if not source.is_dir() or source.is_symlink(): - raise CampaignResetError(f"source is not a regular directory: {source}") - shutil.copytree(source, destination, symlinks=False) - - -def _filesystem_device(path: Path) -> int: - candidate = path.expanduser().resolve(strict=False) - while not candidate.exists(): - parent = candidate.parent - if parent == candidate: - raise CampaignResetError( - f"cannot resolve filesystem device for {path}" - ) - candidate = parent - return candidate.stat().st_dev - - -def _require_same_filesystem(paths: Sequence[Path]) -> None: - devices = {_filesystem_device(path) for path in paths} - if len(devices) != 1: - raise CampaignResetError( - "campaign reset roots/staging/archive are not on one filesystem" - ) - - -def _pinned_legacy_revision(repo_root: Path) -> str: - path = repo_root / "dependencies" / "contributor-lock.toml" - try: - payload = tomllib.loads(path.read_text(encoding="utf-8")) - legacy = payload["legacy_amplicol"] - revision = legacy["revision"] - except (OSError, KeyError, TypeError, tomllib.TOMLDecodeError) as error: - raise CampaignResetError( - "cannot load contributor-lock original-AmpliCol revision" - ) from error - if not isinstance(revision, str): - raise CampaignResetError( - "contributor-lock original-AmpliCol revision is malformed" - ) - return revision - - -def _write_json(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{uuid.uuid4()}.tmp") - with temporary.open("wb") as stream: - stream.write(canonical_json_bytes(payload)) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - - -def _resolved_paths(arguments: argparse.Namespace) -> tuple[ - Path, - Path, - ReportPaths, - ReportPaths, - Path, -]: - source = arguments.source_repo_root.expanduser().resolve(strict=True) - destination = arguments.destination_repo_root.expanduser().resolve(strict=True) - source_paths = ReportPaths.from_repo( - source, - profile=arguments.profile, - artifact_root=arguments.source_artifact_root, - coordination_root=arguments.source_coordination_root, - ) - destination_paths = ReportPaths.from_repo( - destination, - profile=arguments.profile, - artifact_root=arguments.destination_artifact_root, - coordination_root=arguments.destination_coordination_root, - ) - archive = ( - arguments.archive_root.expanduser().resolve(strict=False) - if arguments.archive_root is not None - else ( - source - / ".artifacts" - / "performance-report-archive" - / arguments.archive_id - / arguments.profile - ) - ) - return source, destination, source_paths, destination_paths, archive - - -def _prepare(arguments: argparse.Namespace) -> dict[str, object]: - ( - source, - destination, - source_paths, - destination_paths, - archive_root, - ) = _resolved_paths(arguments) - identity = require_eligible_report_source(destination) - if ( - identity.revision != arguments.expected_source_revision - or identity.tree != arguments.expected_source_tree - ): - raise CampaignResetError("destination source identity differs") - if archive_root.exists(): - raise CampaignResetError(f"archive already exists: {archive_root}") - if ( - destination_paths.artifact_root.exists() - or destination_paths.coordination_root.exists() - ): - raise CampaignResetError("destination campaign roots already exist") - _strict_idle( - coordination_roots=(source_paths.coordination_root,), - entrypoints=( - source_paths.docs_dir / "result_tables.py", - destination_paths.docs_dir / "result_tables.py", - ), - ) - policy = load_profile_campaign_policy( - destination, - arguments.profile, - expected_source_revision=identity.revision, - ) - validate_policy_profile(policy, arguments.profile) - _require_same_filesystem( - ( - source_paths.docs_dir, - source_paths.artifact_root, - source_paths.coordination_root, - destination_paths.docs_dir, - destination_paths.artifact_root.parent, - destination_paths.coordination_root.parent, - archive_root.parent, - ) - ) - source_store = ArtifactStore( - artifact_root=source_paths.artifact_root, - lock_root=source_paths.coordination_root, - ) - seed_manifest = build_seed_manifest( - profile=arguments.profile, - store=source_store, - policy=policy, - final_source_revision=identity.revision, - final_source_tree=identity.tree, - expected_legacy_revision=_pinned_legacy_revision(destination), - ) - staging = temporary_staging_root( - destination_paths.artifact_root.parent, - campaign_id=arguments.campaign_id, - ) - fresh_artifacts = staging / "fresh-artifacts" - fresh_coordination = staging / "fresh-coordination" - fresh_store = stage_seed_store( - source_store=source_store, - destination_root=fresh_artifacts, - destination_lock_root=fresh_coordination, - seed_manifest=seed_manifest, - ) - archive_publication = staging / "archive-publication" - _copy_tree(source_paths.docs_dir, archive_publication) - fresh_publication = staging / "fresh-publication" - _copy_tree(destination_paths.docs_dir, fresh_publication) - inventory = lightweight_archive_inventory( - ( - source_paths.docs_dir, - source_paths.artifact_root, - source_paths.coordination_root, - ) - ) - archive_manifest: dict[str, object] = { - "schema": "pyamplicol-performance-campaign-archive-v1", - "archive_id": arguments.archive_id, - "profile": arguments.profile, - "source_repo_root": os.fspath(source), - "source_publication": os.fspath(source_paths.docs_dir), - "source_artifact_root": os.fspath(source_paths.artifact_root), - "source_coordination_root": os.fspath(source_paths.coordination_root), - "inventory": inventory, - } - archive_manifest["archive_manifest_sha256"] = sha256_payload(archive_manifest) - _write_json(staging / "archive-manifest.json", archive_manifest) - marker = campaign_marker( - campaign_id=arguments.campaign_id, - profile=arguments.profile, - source_revision=identity.revision, - source_tree=identity.tree, - policy_sha256=sha256_payload(policy.as_manifest()), - seed_manifest_sha256=str(seed_manifest["seed_manifest_sha256"]), - archive_manifest_sha256=str( - archive_manifest["archive_manifest_sha256"] - ), - ) - _write_json(fresh_artifacts / CAMPAIGN_MARKER_FILENAME, marker) - staged_service = ReportService( - ReportPaths( - repo_root=destination, - docs_dir=fresh_publication, - results_dir=fresh_publication / "results", - artifact_root=fresh_artifacts, - coordination_root=fresh_coordination, - ) - ) - staged_service.bind_original_amplicol_seed( - OriginalAmplicolSeed.load( - fresh_artifacts / "original_amplicol_seed.json", - profile=arguments.profile, - store=fresh_store, - expected_final_source_revision=identity.revision, - expected_final_source_tree=identity.tree, - expected_manifest_sha256=str( - seed_manifest["seed_manifest_sha256"] - ), - ) - ) - staged_service.publish(reset=True, merge_artifacts=False) - staged_service.publish(reset=False, merge_artifacts=True) - paths = ResetTransactionPaths( - source_publication=source_paths.docs_dir, - source_artifact_root=source_paths.artifact_root, - source_coordination_root=source_paths.coordination_root, - destination_publication=destination_paths.docs_dir, - destination_artifact_root=destination_paths.artifact_root, - destination_coordination_root=destination_paths.coordination_root, - archive_root=archive_root, - staging_root=staging, - guard_path=archive_root.parent / ".campaign-reset.guard", - ) - journal = write_prepared_journal( - profile=arguments.profile, - campaign_id=arguments.campaign_id, - archive_id=arguments.archive_id, - paths=paths, - archive_manifest_sha256=str( - archive_manifest["archive_manifest_sha256"] - ), - seed_manifest_sha256=str(seed_manifest["seed_manifest_sha256"]), - marker_sha256=str(marker["marker_sha256"]), - ) - return { - "status": "PREPARED", - "journal": os.fspath(paths.journal_path), - "journal_sha256": journal["journal_sha256"], - "archive_manifest_sha256": archive_manifest[ - "archive_manifest_sha256" - ], - "seed_manifest_sha256": seed_manifest["seed_manifest_sha256"], - "marker_sha256": marker["marker_sha256"], - "reused": seed_manifest["seed_count"], - } - - -def _commit(arguments: argparse.Namespace) -> dict[str, object]: - journal = json.loads( - arguments.journal.expanduser().resolve(strict=True).read_text() - ) - paths = journal.get("paths", {}) - if not isinstance(paths, Mapping): - raise CampaignResetError("campaign reset journal paths are malformed") - coordination = tuple( - Path(str(paths[key])) - for key in ("source_coordination_root", "destination_coordination_root") - if Path(str(paths[key])).exists() - ) - _strict_idle(coordination_roots=coordination, entrypoints=()) - return commit_or_recover_reset(arguments.journal.expanduser().resolve()) - - -def _publisher_command( - *, - repo_root: Path, - profile: str, - artifact_root: Path, - coordination_root: Path, - command: str, -) -> tuple[str, ...]: - return ( - sys.executable, - os.fspath( - repo_root / "docs" / "performance_reports" / profile / "result_tables.py" - ), - "--repo-root", - os.fspath(repo_root), - "--report-profile", - profile, - "--artifact-root", - os.fspath(artifact_root), - "--coordination-root", - os.fspath(coordination_root), - command, - ) - - -def _verify_baseline(arguments: argparse.Namespace) -> dict[str, object]: - repo = arguments.repo_root.expanduser().resolve(strict=True) - paths = ReportPaths.from_repo( - repo, - profile=arguments.profile, - artifact_root=arguments.artifact_root, - coordination_root=arguments.coordination_root, - ) - marker = assert_campaign_marker( - paths.artifact_root, - campaign_id=arguments.campaign_id, - profile=arguments.profile, - source_revision=arguments.expected_source_revision, - source_tree=arguments.expected_source_tree, - expected_marker_sha256=arguments.expected_marker_sha256, - require_ready=False, - ) - store = ArtifactStore( - artifact_root=paths.artifact_root, - lock_root=paths.coordination_root, - ) - seed = OriginalAmplicolSeed.load( - paths.artifact_root / "original_amplicol_seed.json", - profile=arguments.profile, - store=store, - expected_final_source_revision=arguments.expected_source_revision, - expected_final_source_tree=arguments.expected_source_tree, - expected_manifest_sha256=str(marker["seed_manifest_sha256"]), - ) - records = {record.cell_id: record for record in store.recover_current_records()} - if set(records) != set(seed.pins_by_cell): - raise CampaignResetError("fresh current inventory differs from seed pins") - for cell_id in records: - if store.cell_attempt_ids(cell_id) != (records[cell_id].attempt_id,): - raise CampaignResetError(f"{cell_id}: fresh attempt inventory differs") - observed_attempts = { - attempt - for path in store.cells_root.glob("*/attempts") - if path.is_dir() - for attempt in path.iterdir() - if attempt.is_dir() - } - expected_attempts = {record.manifest_path.parent for record in records.values()} - if observed_attempts != expected_attempts: - raise CampaignResetError( - "fresh store contains a non-seed or orphan attempt" - ) - _strict_idle( - coordination_roots=(paths.coordination_root,), - entrypoints=(paths.docs_dir / "result_tables.py",), - ) - publication = _run( - _publisher_command( - repo_root=repo, - profile=arguments.profile, - artifact_root=paths.artifact_root, - coordination_root=paths.coordination_root, - command="publish-snapshot", - ), - cwd=repo, - ) - publication_log = paths.artifact_root / "baseline-publication.log" - publication_log.write_text( - publication.stdout + publication.stderr, - encoding="utf-8", - ) - snapshot = json.loads( - _run( - _publisher_command( - repo_root=repo, - profile=arguments.profile, - artifact_root=paths.artifact_root, - coordination_root=paths.coordination_root, - command="validate-snapshot", - ), - cwd=repo, - ).stdout - ) - service = ReportService(paths) - caches = service.load_caches() - entries = { - str(entry["cell_id"]): entry["measurement"] - for cache in caches.values() - for entry in cache["entries"] - } - cells = REPORT_CATALOG.measurement_cells() - if ( - len(cells) != EXPECTED_CATALOG_CELL_COUNT - or set(entries) != {cell.cell_id for cell in cells} - ): - raise CampaignResetError("baseline gate does not cover exactly 1,796 cells") - amplicol = { - cell.cell_id - for cell in cells - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - } - non_amplicol = {cell.cell_id for cell in cells} - amplicol - if ( - len(amplicol) != EXPECTED_AMPLICOL_CELL_COUNT - or len(non_amplicol) != EXPECTED_NON_AMPLICOL_CELL_COUNT - ): - raise CampaignResetError( - "baseline gate catalog split differs from 314/1,482" - ) - for cell_id in non_amplicol: - if entries[cell_id] != empty_measurement(): - raise CampaignResetError(f"{cell_id}: pyAmpliCol row is not canonical N/A") - for cell_id in amplicol: - populated = entries[cell_id].get("status") != "not_available" - if populated != (cell_id in seed.pins_by_cell): - raise CampaignResetError( - f"{cell_id}: baseline population differs from seed pins" - ) - pdf = paths.docs_dir / "pyAmpliCol.pdf" - info = _run(("pdfinfo", os.fspath(pdf)), cwd=repo).stdout - page_values = [ - line.split(":", 1)[1].strip() - for line in info.splitlines() - if line.startswith("Pages:") and ":" in line - ] - if page_values != ["73"]: - raise CampaignResetError("baseline PDF does not contain exactly 73 pages") - reused = len(seed.pins_by_cell) - gate: dict[str, object] = { - "schema": "pyamplicol-performance-baseline-gate-v1", - "campaign_id": arguments.campaign_id, - "profile": arguments.profile, - "source_revision": arguments.expected_source_revision, - "source_tree": arguments.expected_source_tree, - "prepared_marker_sha256": marker["marker_sha256"], - "seed_manifest_sha256": seed.digest, - "catalog_cell_count": len(cells), - "amplicol_cell_count": len(amplicol), - "non_amplicol_na_count": len(non_amplicol), - "reused": reused, - "new": 0, - "completed": reused, - "remaining": len(cells) - reused, - "pdf_sha256": sha256_path(pdf), - "pdf_mtime_ns": pdf.stat().st_mtime_ns, - "pdf_pages": 73, - "publisher_log_sha256": sha256_path(publication_log), - "snapshot": snapshot, - } - gate["baseline_gate_sha256"] = sha256_payload(gate) - _write_json(paths.artifact_root / BASELINE_GATE_FILENAME, gate) - ready_marker = mark_campaign_ready( - paths.artifact_root, - baseline_gate_sha256=str(gate["baseline_gate_sha256"]), - ) - assert_campaign_marker( - paths.artifact_root, - campaign_id=arguments.campaign_id, - profile=arguments.profile, - source_revision=arguments.expected_source_revision, - source_tree=arguments.expected_source_tree, - expected_marker_sha256=str(ready_marker["marker_sha256"]), - ) - return {**gate, "ready_marker_sha256": ready_marker["marker_sha256"]} - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(argv) - try: - if arguments.command == "prepare": - result = _prepare(arguments) - elif arguments.command in {"commit", "recover"}: - result = _commit(arguments) - elif arguments.command == "verify-baseline": - result = _verify_baseline(arguments) - else: - paths = ReportPaths.from_repo( - arguments.repo_root.expanduser().resolve(strict=True), - profile=arguments.profile, - artifact_root=arguments.artifact_root, - ) - result = assert_campaign_marker( - paths.artifact_root, - campaign_id=arguments.campaign_id, - profile=arguments.profile, - source_revision=arguments.expected_source_revision, - source_tree=arguments.expected_source_tree, - expected_marker_sha256=arguments.expected_marker_sha256, - ) - except CampaignResetError as error: - raise SystemExit(f"campaign reset failed: {error}") from error - print(json.dumps(result, allow_nan=False, sort_keys=True)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/structural_work_certificate.py b/pyamplicol/tools/developer/structural_work_certificate.py deleted file mode 100644 index 752efdc11b..0000000000 --- a/pyamplicol/tools/developer/structural_work_certificate.py +++ /dev/null @@ -1,609 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Certify pure-gluon full-color work against an AmpliCol replay. - -The legacy generated library materializes one reduced current/interaction -module and replays one module for every retained color ordering. pyAmpliCol -instead fuses those color orderings into one recurrence/DAG/eager schedule. -Comparing pyAmpliCol with only one legacy module is therefore misleading. This -tool computes the exact legacy dynamic replay work and checks that the final -pyAmpliCol schedule does not evaluate more currents or interactions. - -For recurrence artifacts it additionally bounds construction-only inflation. -Those peaks are intentionally kept separate from the final runtime work: they -diagnose cold-generation regressions without pretending that discarded -construction candidates execute at every phase-space point. -""" - -from __future__ import annotations - -import argparse -import json -import math -import re -from dataclasses import asdict, dataclass -from pathlib import Path -from typing import Any - - -class StructuralWorkError(RuntimeError): - """The artifacts cannot produce a valid structural-work certificate.""" - - -_AFTER_FILTER = re.compile( - r"Total number of currents, vertices and amplitudes after filter" - r"\s+(\d+)\s+(\d+)\s+(\d+)" -) -_VAL_C = re.compile(r"dimension\s*\(\s*1\s*:\s*\d+\s*,\s*(\d+)\s*\)\s*::\s*val_c\b") -_INT_C = re.compile(r"dimension\s*\(\s*1\s*:\s*\d+\s*,\s*(\d+)\s*\)\s*::\s*int_c\b") -_PEAK_CONTRIBUTION_COUNT_SEMANTICS = "resident-pending-contributions-v1" - - -@dataclass(frozen=True) -class LegacyReplayWork: - module_current_count: int - module_interaction_count: int - retained_color_ordering_count: int - replay_current_count: int - replay_interaction_count: int - generated_module_count: int - - -@dataclass(frozen=True) -class CandidateFinalWork: - mode: str - current_count: int - interaction_count: int - current_ratio_to_legacy_replay: float - interaction_ratio_to_legacy_replay: float - - -@dataclass(frozen=True) -class FinalWorkComparison: - current_delta_count: int - interaction_delta_count: int - current_savings_fraction: float - interaction_savings_fraction: float - classification: str - - -@dataclass(frozen=True) -class RecurrenceConstructionWork: - peak_current_count: int - peak_contribution_count: int - peak_to_final_current_ratio: float - peak_to_final_contribution_ratio: float - peak_current_ratio_to_legacy_replay: float - - -@dataclass(frozen=True) -class StructuralWorkCertificate: - schema: str - process: str - external_pdg_order: tuple[int, ...] - legacy: LegacyReplayWork - candidate: CandidateFinalWork - final_work_comparison: FinalWorkComparison - recurrence_construction: RecurrenceConstructionWork | None - limits: dict[str, float] - status: str - - -@dataclass(frozen=True) -class AdjacentMultiplicityCensus: - schema: str - mode: str - lower_n_final: int - higher_n_final: int - legacy_current_growth: float - candidate_current_growth: float - normalized_current_growth: float - legacy_interaction_growth: float - candidate_interaction_growth: float - normalized_interaction_growth: float - normalized_peak_current_growth: float | None - limits: dict[str, float] - status: str - - -@dataclass(frozen=True) -class StaticTemplateMaterializationCensus: - schema: str - mode: str - legacy_generated_module_count: int - legacy_static_current_count: int - legacy_static_interaction_count: int - legacy_replay_multiplicity_per_module: int - candidate_final_current_count: int - candidate_final_interaction_count: int - candidate_final_current_ratio: float - candidate_final_interaction_ratio: float - candidate_peak_current_count: int | None - candidate_peak_interaction_count: int | None - candidate_peak_current_ratio: float | None - candidate_peak_interaction_ratio: float | None - limits: dict[str, float] - violations: tuple[str, ...] - status: str - - -MAX_UNPROVEN_FINAL_TO_LEGACY = 1.05 -MAX_ADJACENT_FINAL_GROWTH = 1.05 -MAX_ADJACENT_PEAK_GROWTH = 1.25 -MAX_STATIC_TEMPLATE_MATERIALIZATION = 1.05 - - -def _read_json(path: Path) -> dict[str, Any]: - try: - payload = json.loads(path.read_text()) - except (OSError, json.JSONDecodeError) as error: - raise StructuralWorkError(f"cannot read JSON {path}: {error}") from error - if not isinstance(payload, dict): - raise StructuralWorkError(f"JSON root is not an object: {path}") - return payload - - -def _single_file(root: Path, name: str) -> Path: - files = sorted(root.rglob(name)) - if len(files) != 1: - raise StructuralWorkError( - f"{root} must contain exactly one {name}; found {len(files)}" - ) - return files[0] - - -def legacy_replay_work(legacy_artifact: Path) -> LegacyReplayWork: - probe = _single_file(legacy_artifact, "amplicol_color_library_probe.output") - match = _AFTER_FILTER.search(probe.read_text()) - if match is None: - raise StructuralWorkError( - "legacy probe lacks authenticated after-filter counts" - ) - _, _, retained_amplitudes = (int(value) for value in match.groups()) - if retained_amplitudes <= 0: - raise StructuralWorkError("legacy probe has no retained color orderings") - - modules = sorted(legacy_artifact.rglob("amp*_lib.f03")) - if not modules: - raise StructuralWorkError("legacy artifact has no generated library modules") - dimensions: set[tuple[int, int]] = set() - for module in modules: - text = module.read_text() - current = _VAL_C.search(text) - interaction = _INT_C.search(text) - if current is None or interaction is None: - raise StructuralWorkError( - f"legacy module lacks val_c/int_c dimensions: {module}" - ) - dimensions.add((int(current.group(1)), int(interaction.group(1)))) - if len(dimensions) != 1: - raise StructuralWorkError( - "legacy pure-gluon modules do not share one replay shape" - ) - module_currents, module_interactions = dimensions.pop() - return LegacyReplayWork( - module_current_count=module_currents, - module_interaction_count=module_interactions, - retained_color_ordering_count=retained_amplitudes, - replay_current_count=module_currents * retained_amplitudes, - replay_interaction_count=module_interactions * retained_amplitudes, - generated_module_count=len(modules), - ) - - -def _positive_integer(payload: dict[str, Any], key: str, label: str) -> int: - value = payload.get(key) - if not isinstance(value, int) or isinstance(value, bool) or value <= 0: - raise StructuralWorkError(f"{label} {key} must be a positive integer") - return value - - -def candidate_final_work( - execution: dict[str, Any], - legacy: LegacyReplayWork, -) -> tuple[CandidateFinalWork, RecurrenceConstructionWork | None]: - kind = execution.get("kind") - construction = None - if kind == "pyamplicol-runtime-recurrence-execution": - try: - inspection = execution["plan"]["inspection_summary"] - schedule = inspection["schedule"] - except (KeyError, TypeError) as error: - raise StructuralWorkError( - "recurrence execution lacks inspection schedule" - ) from error - mode = "recurrence" - currents = _positive_integer(schedule, "current_count", "recurrence schedule") - interactions = _positive_integer( - schedule, "contribution_count", "recurrence schedule" - ) - construction_payload = inspection.get("construction") - if not isinstance(construction_payload, dict): - raise StructuralWorkError( - "recurrence execution lacks construction diagnostics" - ) - if ( - construction_payload.get("peak_contribution_count_semantics") - != _PEAK_CONTRIBUTION_COUNT_SEMANTICS - ): - raise StructuralWorkError( - "recurrence construction lacks authenticated resident " - "peak-contribution semantics" - ) - peak_currents = _positive_integer( - construction_payload, - "peak_current_count", - "recurrence construction", - ) - peak_contributions = _positive_integer( - construction_payload, - "peak_contribution_count", - "recurrence construction", - ) - construction = RecurrenceConstructionWork( - peak_current_count=peak_currents, - peak_contribution_count=peak_contributions, - peak_to_final_current_ratio=peak_currents / currents, - peak_to_final_contribution_ratio=peak_contributions / interactions, - peak_current_ratio_to_legacy_replay=( - peak_currents / legacy.replay_current_count - ), - ) - elif kind == "pyamplicol-runtime-execution": - summary = execution.get("helicity_sum_execution", {}).get("dag_summary") - if not isinstance(summary, dict): - raise StructuralWorkError( - "compiled execution lacks helicity-sum DAG summary" - ) - mode = "compiled" - currents = _positive_integer(summary, "current_count", "compiled DAG") - interactions = _positive_integer(summary, "interaction_count", "compiled DAG") - elif kind == "pyamplicol-runtime-eager-execution": - try: - summary = execution["plan"]["inspection_summary"] - except (KeyError, TypeError) as error: - raise StructuralWorkError( - "eager execution lacks inspection summary" - ) from error - mode = "eager" - currents = _positive_integer(summary, "current_count", "eager plan") - # Attachments are the eager representation of DAG interaction fan-in. - interactions = _positive_integer(summary, "attachment_count", "eager plan") - else: - raise StructuralWorkError(f"unsupported candidate execution kind: {kind!r}") - - return ( - CandidateFinalWork( - mode=mode, - current_count=currents, - interaction_count=interactions, - current_ratio_to_legacy_replay=currents / legacy.replay_current_count, - interaction_ratio_to_legacy_replay=( - interactions / legacy.replay_interaction_count - ), - ), - construction, - ) - - -def _final_work_comparison( - legacy: LegacyReplayWork, - candidate: CandidateFinalWork, -) -> FinalWorkComparison: - current_delta = candidate.current_count - legacy.replay_current_count - interaction_delta = candidate.interaction_count - legacy.replay_interaction_count - classification = ( - "proven-recycling" - if current_delta <= 0 and interaction_delta <= 0 - else "within-structural-tolerance" - ) - return FinalWorkComparison( - current_delta_count=current_delta, - interaction_delta_count=interaction_delta, - current_savings_fraction=-current_delta / legacy.replay_current_count, - interaction_savings_fraction=( - -interaction_delta / legacy.replay_interaction_count - ), - classification=classification, - ) - - -def certify( - legacy_artifact: Path, - candidate_artifact: Path, - *, - max_final_to_legacy: float = MAX_UNPROVEN_FINAL_TO_LEGACY, - max_peak_current_to_legacy: float = 1.5, - max_peak_to_final_current: float = 4.0, - max_peak_to_final_contribution: float = 6.0, -) -> StructuralWorkCertificate: - if ( - not math.isfinite(max_final_to_legacy) - or max_final_to_legacy <= 0.0 - or max_final_to_legacy > MAX_UNPROVEN_FINAL_TO_LEGACY - ): - raise StructuralWorkError( - "unreviewed final-work budget must be positive and no greater " - f"than {MAX_UNPROVEN_FINAL_TO_LEGACY:.2f}x legacy replay" - ) - legacy = legacy_replay_work(legacy_artifact) - execution_path = _single_file(candidate_artifact, "execution.json") - execution = _read_json(execution_path) - external = execution.get("external_pdg_order") - if ( - not isinstance(external, list) - or len(external) < 4 - or any(pdg != 21 for pdg in external) - or execution.get("color_accuracy") != "full" - ): - raise StructuralWorkError( - "certificate currently requires a full-color pure-gluon process" - ) - candidate, construction = candidate_final_work(execution, legacy) - limits = { - "max_final_to_legacy_replay": max_final_to_legacy, - "max_peak_current_to_legacy_replay": max_peak_current_to_legacy, - "max_peak_to_final_current": max_peak_to_final_current, - "max_peak_to_final_contribution": max_peak_to_final_contribution, - } - failures = [] - if candidate.current_ratio_to_legacy_replay > max_final_to_legacy: - failures.append("final current work exceeds legacy replay") - if candidate.interaction_ratio_to_legacy_replay > max_final_to_legacy: - failures.append("final interaction work exceeds legacy replay") - if construction is not None: - if ( - construction.peak_current_ratio_to_legacy_replay - > max_peak_current_to_legacy - ): - failures.append("peak construction currents exceed legacy replay budget") - if construction.peak_to_final_current_ratio > max_peak_to_final_current: - failures.append("peak/final construction current ratio exceeds budget") - if ( - construction.peak_to_final_contribution_ratio - > max_peak_to_final_contribution - ): - failures.append("peak/final construction contribution ratio exceeds budget") - if failures: - raise StructuralWorkError("; ".join(failures)) - - process = execution.get("process") - if not isinstance(process, str) or not process: - process = execution_path.parent.name - return StructuralWorkCertificate( - schema="pyamplicol-structural-work-certificate-v1", - process=process, - external_pdg_order=tuple(external), - legacy=legacy, - candidate=candidate, - final_work_comparison=_final_work_comparison(legacy, candidate), - recurrence_construction=construction, - limits=limits, - status="ok", - ) - - -def adjacent_multiplicity_census( - lower: StructuralWorkCertificate, - higher: StructuralWorkCertificate, - *, - max_normalized_final_growth: float = MAX_ADJACENT_FINAL_GROWTH, - max_normalized_peak_growth: float = MAX_ADJACENT_PEAK_GROWTH, -) -> AdjacentMultiplicityCensus: - lower_n_final = len(lower.external_pdg_order) - 2 - higher_n_final = len(higher.external_pdg_order) - 2 - if higher_n_final != lower_n_final + 1: - raise StructuralWorkError( - "structural-work census requires adjacent final-state multiplicities" - ) - if lower.candidate.mode != higher.candidate.mode: - raise StructuralWorkError( - "structural-work census requires one candidate generation mode" - ) - for value, label in [ - (max_normalized_final_growth, "adjacent final-work growth"), - (max_normalized_peak_growth, "adjacent construction-peak growth"), - ]: - if not math.isfinite(value) or value <= 0.0: - raise StructuralWorkError(f"{label} limit must be positive and finite") - - legacy_current_growth = ( - higher.legacy.replay_current_count / lower.legacy.replay_current_count - ) - candidate_current_growth = ( - higher.candidate.current_count / lower.candidate.current_count - ) - legacy_interaction_growth = ( - higher.legacy.replay_interaction_count / lower.legacy.replay_interaction_count - ) - candidate_interaction_growth = ( - higher.candidate.interaction_count / lower.candidate.interaction_count - ) - normalized_current_growth = candidate_current_growth / legacy_current_growth - normalized_interaction_growth = ( - candidate_interaction_growth / legacy_interaction_growth - ) - normalized_peak_current_growth = None - if ( - lower.recurrence_construction is not None - and higher.recurrence_construction is not None - ): - peak_growth = ( - higher.recurrence_construction.peak_current_count - / lower.recurrence_construction.peak_current_count - ) - normalized_peak_current_growth = peak_growth / legacy_current_growth - - failures = [] - if normalized_current_growth > max_normalized_final_growth: - failures.append( - "adjacent final-current growth exceeds legacy-normalized budget" - ) - if normalized_interaction_growth > max_normalized_final_growth: - failures.append( - "adjacent final-interaction growth exceeds legacy-normalized budget" - ) - if ( - normalized_peak_current_growth is not None - and normalized_peak_current_growth > max_normalized_peak_growth - ): - failures.append( - "adjacent construction-peak growth exceeds legacy-normalized budget" - ) - if failures: - raise StructuralWorkError("; ".join(failures)) - - return AdjacentMultiplicityCensus( - schema="pyamplicol-adjacent-structural-work-census-v1", - mode=lower.candidate.mode, - lower_n_final=lower_n_final, - higher_n_final=higher_n_final, - legacy_current_growth=legacy_current_growth, - candidate_current_growth=candidate_current_growth, - normalized_current_growth=normalized_current_growth, - legacy_interaction_growth=legacy_interaction_growth, - candidate_interaction_growth=candidate_interaction_growth, - normalized_interaction_growth=normalized_interaction_growth, - normalized_peak_current_growth=normalized_peak_current_growth, - limits={ - "max_normalized_final_growth": max_normalized_final_growth, - "max_normalized_peak_growth": max_normalized_peak_growth, - }, - status="ok", - ) - - -def static_template_materialization_census( - certificate: StructuralWorkCertificate, - *, - max_materialization_to_legacy_static: float = (MAX_STATIC_TEMPLATE_MATERIALIZATION), -) -> StaticTemplateMaterializationCensus: - """Compare artifact materialization with generated legacy templates. - - Legacy dynamic replay is the correct runtime-work comparator, but it can - hide a severe cold-generation expansion. This independent census treats - the generated module inventory as the static baseline and reports both the - final artifact and recurrence-construction peak. - """ - - limit = float(max_materialization_to_legacy_static) - if not math.isfinite(limit) or limit <= 0.0: - raise StructuralWorkError( - "static-template materialization limit must be positive and finite" - ) - legacy = certificate.legacy - if ( - legacy.generated_module_count <= 0 - or legacy.retained_color_ordering_count % legacy.generated_module_count - ): - raise StructuralWorkError( - "legacy color replay count is not an integer multiple of its " - "generated module inventory" - ) - static_currents = legacy.module_current_count * legacy.generated_module_count - static_interactions = ( - legacy.module_interaction_count * legacy.generated_module_count - ) - candidate = certificate.candidate - final_current_ratio = candidate.current_count / static_currents - final_interaction_ratio = candidate.interaction_count / static_interactions - construction = certificate.recurrence_construction - peak_currents = None if construction is None else construction.peak_current_count - peak_interactions = ( - None if construction is None else construction.peak_contribution_count - ) - peak_current_ratio = ( - None if peak_currents is None else peak_currents / static_currents - ) - peak_interaction_ratio = ( - None if peak_interactions is None else peak_interactions / static_interactions - ) - violations = [] - if final_current_ratio > limit: - violations.append("final currents exceed legacy static-template budget") - if final_interaction_ratio > limit: - violations.append("final interactions exceed legacy static-template budget") - if peak_current_ratio is not None and peak_current_ratio > limit: - violations.append("peak currents exceed legacy static-template budget") - if peak_interaction_ratio is not None and peak_interaction_ratio > limit: - violations.append("peak interactions exceed legacy static-template budget") - return StaticTemplateMaterializationCensus( - schema="pyamplicol-static-template-materialization-census-v1", - mode=candidate.mode, - legacy_generated_module_count=legacy.generated_module_count, - legacy_static_current_count=static_currents, - legacy_static_interaction_count=static_interactions, - legacy_replay_multiplicity_per_module=( - legacy.retained_color_ordering_count // legacy.generated_module_count - ), - candidate_final_current_count=candidate.current_count, - candidate_final_interaction_count=candidate.interaction_count, - candidate_final_current_ratio=final_current_ratio, - candidate_final_interaction_ratio=final_interaction_ratio, - candidate_peak_current_count=peak_currents, - candidate_peak_interaction_count=peak_interactions, - candidate_peak_current_ratio=peak_current_ratio, - candidate_peak_interaction_ratio=peak_interaction_ratio, - limits={"max_materialization_to_legacy_static": limit}, - violations=tuple(violations), - status="ok" if not violations else "exceeds-budget", - ) - - -def require_static_template_materialization_parity( - certificate: StructuralWorkCertificate, - *, - max_materialization_to_legacy_static: float = (MAX_STATIC_TEMPLATE_MATERIALIZATION), -) -> StaticTemplateMaterializationCensus: - """Fail closed unless final and peak materialization have static parity.""" - - census = static_template_materialization_census( - certificate, - max_materialization_to_legacy_static=(max_materialization_to_legacy_static), - ) - if census.violations: - raise StructuralWorkError("; ".join(census.violations)) - return census - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("legacy_artifact", type=Path) - parser.add_argument("candidate_artifact", type=Path) - parser.add_argument( - "--max-final-to-legacy", - type=float, - default=MAX_UNPROVEN_FINAL_TO_LEGACY, - ) - parser.add_argument("--max-peak-current-to-legacy", type=float, default=1.5) - parser.add_argument("--max-peak-to-final-current", type=float, default=4.0) - parser.add_argument("--max-peak-to-final-contribution", type=float, default=6.0) - parser.add_argument( - "--require-static-template-parity", - action="store_true", - help=( - "also reject final/peak materialization above 1.05x the generated " - "legacy template inventory" - ), - ) - return parser - - -def main() -> int: - arguments = _parser().parse_args() - certificate = certify( - arguments.legacy_artifact, - arguments.candidate_artifact, - max_final_to_legacy=arguments.max_final_to_legacy, - max_peak_current_to_legacy=arguments.max_peak_current_to_legacy, - max_peak_to_final_current=arguments.max_peak_to_final_current, - max_peak_to_final_contribution=(arguments.max_peak_to_final_contribution), - ) - if arguments.require_static_template_parity: - require_static_template_materialization_parity(certificate) - print(json.dumps(asdict(certificate), indent=2, sort_keys=True)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/symjit_2_22_generated_fixture_gate.py b/pyamplicol/tools/developer/symjit_2_22_generated_fixture_gate.py deleted file mode 100644 index f7a7a050f4..0000000000 --- a/pyamplicol/tools/developer/symjit_2_22_generated_fixture_gate.py +++ /dev/null @@ -1,1034 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Run the fail-closed SymJIT 2.22 generated-artifact fixture gates.""" - -from __future__ import annotations - -import argparse -import json -import re -import shlex -import subprocess -import sys -from collections.abc import Iterator, Mapping, Sequence -from contextlib import contextmanager -from dataclasses import dataclass, fields -from pathlib import Path - -ROOT = Path(__file__).resolve().parents[2] -sys.path.insert(0, str(ROOT / "build_backend")) - -import _pyamplicol_build as build_backend # noqa: E402 - -_DEFAULT_EXECUTION_ROOT = ( - Path(".artifacts") - / "symjit-2.22-migration" - / "generated-fixture-gate" -) -_CANDIDATE_MANIFEST_PLACEHOLDER = "/Cargo.toml" -_EXPECTED_PROCESS_EXPRESSION = "d d~ > z g g g g g g" -_EXPECTED_PROCESS_ID = "d_dbar_to_z_g_g_g_g_g_g" -_EXPECTED_EXTERNAL_PDGS = (1, -1, 23, 21, 21, 21, 21, 21, 21) -_SOURCE_REVISION_PATTERN = re.compile(r"[0-9a-f]{40}") -_NATIVE_BUILD_INPUTS_PATTERN = re.compile(r"[0-9a-f]{64}") -_CANDIDATE_VERSION_PATTERN = re.compile( - r"[0-9]+\.[0-9]+\.[0-9]+\.dev0\+candidate\.[0-9a-f]{12}" -) -_ARTIFACT_IDENTITY_CONTRACT = { - "kind": "pyamplicol-runtime-payload-identity", - "schema_version": 1, -} - - -class GateError(RuntimeError): - """Raised when a fixture or focused gate fails closed.""" - - -@dataclass(frozen=True) -class FixturePaths: - compiled_o3: Path - eager_o2: Path - recurrence_topology_o2: Path - recurrence_union_o2: Path - contracted_nlc: Path - - def as_dict(self) -> dict[str, Path]: - return {field.name: getattr(self, field.name) for field in fields(self)} - - -@dataclass(frozen=True) -class ExecutionPaths: - cargo_home: Path - cargo_target_dir: Path - tmpdir: Path - pip_cache_dir: Path - xdg_cache_home: Path - python_cache_prefix: Path - - def as_dict(self) -> dict[str, Path]: - return {field.name: getattr(self, field.name) for field in fields(self)} - - def environment(self) -> dict[str, str]: - return { - "CARGO_HOME": str(self.cargo_home), - "CARGO_TARGET_DIR": str(self.cargo_target_dir), - "TMPDIR": str(self.tmpdir), - "PIP_CACHE_DIR": str(self.pip_cache_dir), - "XDG_CACHE_HOME": str(self.xdg_cache_home), - "PYTHONPYCACHEPREFIX": str(self.python_cache_prefix), - "PYAMPLICOL_REQUIRE_NATIVE_TESTS": "1", - "CARGO_TERM_COLOR": "never", - } - - def create(self) -> None: - for path in self.as_dict().values(): - path.mkdir(parents=True, exist_ok=True) - - -@dataclass(frozen=True) -class GateCommand: - label: str - arguments: tuple[str, ...] - expected_tests: tuple[str, ...] - - -_ARTIFACT_ENVIRONMENT_ROUTES = ( - ("RUSTICOL_COMPILED_DIRECT_ARTIFACT", "compiled_o3"), - ("RUSTICOL_COMPILED_ARTIFACT", "compiled_o3"), - ("RUSTICOL_TEST_COMPILED_REPLAY_QUICK_ARTIFACT", "compiled_o3"), - ("RUSTICOL_SELECTOR_ARTIFACT", "compiled_o3"), - ("RUSTICOL_EAGER_ARTIFACT", "eager_o2"), - ("RUSTICOL_RECURRENCE_ARTIFACT", "recurrence_topology_o2"), - ( - "RUSTICOL_RECURRENCE_TOPOLOGY_ALLOCATION_ARTIFACT", - "recurrence_topology_o2", - ), - ("RUSTICOL_RECURRENCE_UNION_ALLOCATION_ARTIFACT", "recurrence_union_o2"), - ( - "RUSTICOL_RECURRENCE_CONTRACTED_ALLOCATION_ARTIFACT", - "contracted_nlc", - ), - ("RUSTICOL_CONTRACTED_SELECTOR_ARTIFACT", "contracted_nlc"), -) - -_COMPILED_FULL_TEST = ( - "engine::compiled_direct_prototype::tests::" - "retained_compiled_o3_artifact_native_runtime_direct_matches_legacy_contract" -) -_COMPILED_QUICK_TEST = ( - "engine::compiled_direct_prototype::tests::" - "retained_compiled_replay_totals_quick_contract" -) -_EAGER_ALLOCATION_TEST = ( - "engine::eager_integration_tests::" - "generated_eager_native_into_is_warmed_allocation_free_when_fixture_is_supplied" -) -_RECURRENCE_SMOKE_TEST = ( - "engine::recurrence_integration_tests::" - "generated_recurrence_artifact_loads_when_fixture_is_supplied" -) -_RECURRENCE_BOUNDARY_TEST = ( - "engine::recurrence_integration_tests::" - "generated_recurrence_odd_tails_report_zero_direct_boundary_traffic_when_fixtures_are_supplied" -) -_RECURRENCE_ALLOCATION_TESTS = ( - "genuine_topology_replay_artifact_warmed_loop_allocates_zero_heap_bytes", - "genuine_all_flow_union_artifact_warmed_loop_allocates_zero_heap_bytes", - "genuine_contracted_color_artifact_warmed_loop_allocates_zero_heap_bytes", - "genuine_contracted_color_prepared_selector_allocates_zero_heap_bytes", -) -_ODD_TAIL_TESTS = ( - "genuine_compiled_o3_odd_tails_preserve_numerics_allocations_and_boundary_traffic", - "genuine_eager_o2_odd_tails_preserve_numerics_allocations_and_boundary_traffic", - "genuine_topology_recurrence_o2_odd_tails_preserve_numerics_and_allocations", - "genuine_all_flow_union_recurrence_o2_odd_tails_preserve_numerics_and_allocations", -) -_CAPI_ARTIFACT_TESTS = ( - "generated_compiled_artifact_reports_compiled_execution_mode", - "generated_eager_artifact_loads_and_evaluates_through_the_c_abi", -) -_CAPI_SELECTOR_TESTS = ( - "direct_total_outputs_preserve_bits_canaries_and_capacity_errors", - "homogeneous_and_alternating_per_point_selectors_match_resolved_components", - "malformed_selector_buffers_fail_without_touching_output", - "contracted_color_rejects_global_and_per_point_flow_selectors", -) - - -def _workspace_artifact( - raw_path: str | Path, - *, - label: str, - workspace_root: Path, - source_revision: str, - native_build_inputs_sha256: str, -) -> Path: - root = workspace_root.resolve() - candidate = Path(raw_path) - if not candidate.is_absolute(): - candidate = root / candidate - try: - resolved = candidate.resolve(strict=True) - except OSError as error: - raise GateError(f"{label} artifact does not exist: {candidate}") from error - try: - resolved.relative_to(root) - except ValueError as error: - raise GateError( - f"{label} artifact must be workspace-local: {resolved}" - ) from error - if not resolved.is_dir(): - raise GateError(f"{label} artifact is not a directory: {resolved}") - - manifest = resolved / "artifact.json" - if not manifest.is_file(): - raise GateError(f"{label} artifact is missing artifact.json: {resolved}") - try: - manifest = manifest.resolve(strict=True) - except OSError as error: - raise GateError( - f"{label} artifact.json could not be resolved: {manifest}" - ) from error - try: - manifest.relative_to(root) - except ValueError as error: - raise GateError( - f"{label} artifact.json must be workspace-local: {manifest}" - ) from error - try: - payload = json.loads(manifest.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise GateError( - f"{label} artifact.json is not valid JSON: {manifest}" - ) from error - if not isinstance(payload, dict): - raise GateError(f"{label} artifact.json must contain a JSON object: {manifest}") - _validate_fixture_identity( - payload, - label=label, - manifest=manifest, - source_revision=source_revision, - native_build_inputs_sha256=native_build_inputs_sha256, - ) - return resolved - - -def _validated_identity_digest( - value: str, - *, - label: str, - length: int, - pattern: re.Pattern[str], -) -> str: - if pattern.fullmatch(value) is None: - raise GateError(f"{label} must be a lowercase {length}-digit hex value") - return value - - -def _validate_fixture_identity( - payload: Mapping[str, object], - *, - label: str, - manifest: Path, - source_revision: str, - native_build_inputs_sha256: str, -) -> None: - extensions = payload.get("extensions") - if ( - not isinstance(extensions, dict) - or extensions.get("artifact_identity") != _ARTIFACT_IDENTITY_CONTRACT - ): - raise GateError( - f"{label} lacks the current artifact identity contract; " - f"regenerate it: {manifest}" - ) - producer = payload.get("producer") - if not isinstance(producer, dict): - raise GateError(f"{label} producer must be a JSON object: {manifest}") - expected_producer = { - "distribution": "pyamplicol", - "git_revision": source_revision, - "native_build_inputs_sha256": native_build_inputs_sha256, - } - for key, expected in expected_producer.items(): - observed = producer.get(key) - if observed != expected: - raise GateError( - f"{label} producer {key} does not match the authenticated " - f"candidate (expected {expected!r}, got {observed!r}): {manifest}" - ) - version = producer.get("version") - if ( - not isinstance(version, str) - or _CANDIDATE_VERSION_PATTERN.fullmatch(version) is None - ): - raise GateError( - f"{label} producer version is not a candidate build " - f"(got {version!r}): {manifest}" - ) - - processes = payload.get("processes") - if ( - not isinstance(processes, list) - or len(processes) != 1 - or not isinstance(processes[0], dict) - ): - raise GateError( - f"{label} must contain exactly one object-valued process: {manifest}" - ) - process = processes[0] - expected_process = { - "id": _EXPECTED_PROCESS_ID, - "expression": _EXPECTED_PROCESS_EXPRESSION, - "external_pdgs": list(_EXPECTED_EXTERNAL_PDGS), - } - for key, expected in expected_process.items(): - observed = process.get(key) - if observed != expected: - raise GateError( - f"{label} process {key} does not identify the exact Z+6g " - f"fixture (expected {expected!r}, got {observed!r}): {manifest}" - ) - default_process_id = payload.get("default_process_id") - if default_process_id != _EXPECTED_PROCESS_ID: - raise GateError( - f"{label} default_process_id does not identify the exact Z+6g " - f"fixture (expected {_EXPECTED_PROCESS_ID!r}, " - f"got {default_process_id!r}): {manifest}" - ) - - -def preflight_fixtures( - raw_paths: Mapping[str, str | Path], - *, - workspace_root: Path, - source_revision: str, - native_build_inputs_sha256: str, -) -> FixturePaths: - source_revision = _validated_identity_digest( - source_revision, - label="source revision", - length=40, - pattern=_SOURCE_REVISION_PATTERN, - ) - native_build_inputs_sha256 = _validated_identity_digest( - native_build_inputs_sha256, - label="native build inputs SHA-256", - length=64, - pattern=_NATIVE_BUILD_INPUTS_PATTERN, - ) - expected_names = {field.name for field in fields(FixturePaths)} - if set(raw_paths) != expected_names: - missing = sorted(expected_names.difference(raw_paths)) - unexpected = sorted(set(raw_paths).difference(expected_names)) - raise GateError( - "fixture arguments do not match the required roles " - f"(missing={missing}, unexpected={unexpected})" - ) - resolved = { - name: _workspace_artifact( - raw_paths[name], - label=name.replace("_", " "), - workspace_root=workspace_root, - source_revision=source_revision, - native_build_inputs_sha256=native_build_inputs_sha256, - ) - for name in sorted(expected_names) - } - if len(set(resolved.values())) != len(resolved): - raise GateError( - "the five fixture roles must name distinct artifact directories" - ) - fixtures = FixturePaths(**resolved) - _common_fixture_candidate_version(fixtures) - return fixtures - - -def _workspace_execution_path( - raw_path: str | Path, - *, - label: str, - workspace_root: Path, -) -> Path: - root = workspace_root.resolve() - candidate = Path(raw_path) - if not candidate.is_absolute(): - candidate = root / candidate - try: - resolved = candidate.resolve(strict=False) - except OSError as error: - raise GateError(f"could not resolve {label}: {candidate}") from error - try: - relative = resolved.relative_to(root) - except ValueError as error: - raise GateError(f"{label} must be workspace-local: {resolved}") from error - if not relative.parts: - raise GateError(f"{label} must be below the workspace root: {resolved}") - if resolved.exists() and not resolved.is_dir(): - raise GateError(f"{label} exists but is not a directory: {resolved}") - return resolved - - -def preflight_execution_paths( - raw_paths: Mapping[str, str | Path], - *, - workspace_root: Path, -) -> ExecutionPaths: - expected_names = {field.name for field in fields(ExecutionPaths)} - if set(raw_paths) != expected_names: - missing = sorted(expected_names.difference(raw_paths)) - unexpected = sorted(set(raw_paths).difference(expected_names)) - raise GateError( - "execution path arguments do not match the required roles " - f"(missing={missing}, unexpected={unexpected})" - ) - resolved = { - name: _workspace_execution_path( - raw_paths[name], - label=name.replace("_", " "), - workspace_root=workspace_root, - ) - for name in sorted(expected_names) - } - if len(set(resolved.values())) != len(resolved): - raise GateError("cache and temporary directories must be distinct") - return ExecutionPaths(**resolved) - - -def artifact_environment(fixtures: FixturePaths) -> dict[str, str]: - paths = fixtures.as_dict() - return { - environment_name: str(paths[fixture_name]) - for environment_name, fixture_name in _ARTIFACT_ENVIRONMENT_ROUTES - } - - -def _common_fixture_candidate_version(fixtures: FixturePaths) -> str: - versions: dict[str, str] = {} - for label, artifact in fixtures.as_dict().items(): - manifest = artifact / "artifact.json" - try: - payload = json.loads(manifest.read_text(encoding="utf-8")) - producer = payload["producer"] - version = producer["version"] - except ( - KeyError, - OSError, - TypeError, - UnicodeError, - json.JSONDecodeError, - ) as error: - raise GateError( - f"{label.replace('_', ' ')} candidate version could not be " - f"re-authenticated: {manifest}" - ) from error - if ( - not isinstance(version, str) - or _CANDIDATE_VERSION_PATTERN.fullmatch(version) is None - ): - raise GateError( - f"{label.replace('_', ' ')} producer version is not a " - f"candidate build (got {version!r}): {manifest}" - ) - versions[label] = version - unique = set(versions.values()) - if len(unique) != 1: - raise GateError( - "the five authenticated fixtures were not generated by one " - f"candidate build: {versions}" - ) - return unique.pop() - - -def _authenticate_candidate_overlay_build_info( - overlay: Path, - *, - source_revision: str, - native_build_inputs_sha256: str, - candidate_version: str, -) -> None: - build_info_path = overlay / "src" / "pyamplicol" / "_build_info.json" - if build_info_path.is_symlink(): - raise GateError( - "authenticated candidate overlay build info must not be a symlink: " - f"{build_info_path}" - ) - try: - resolved_build_info = build_info_path.resolve(strict=True) - resolved_build_info.relative_to(overlay) - except (OSError, ValueError) as error: - raise GateError( - "authenticated candidate overlay build info is missing or escaped " - f"the overlay: {build_info_path}" - ) from error - if not resolved_build_info.is_file(): - raise GateError( - "authenticated candidate overlay build info is not a regular file: " - f"{resolved_build_info}" - ) - try: - payload = json.loads(resolved_build_info.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise GateError( - "authenticated candidate overlay build info is not valid JSON: " - f"{resolved_build_info}" - ) from error - if not isinstance(payload, dict): - raise GateError( - "authenticated candidate overlay build info must be a JSON object: " - f"{resolved_build_info}" - ) - - schema_version = payload.get("schema_version") - if ( - not isinstance(schema_version, int) - or isinstance(schema_version, bool) - or schema_version != 1 - ): - raise GateError( - "authenticated candidate overlay build identity does not match " - "the generated fixtures: schema_version must be integer 1" - ) - if payload.get("publishable") is not False: - raise GateError( - "authenticated candidate overlay build identity does not match " - "the generated fixtures: publishable must be false" - ) - if payload.get("selftest_fixture_bootstrap") is not False: - raise GateError( - "authenticated candidate overlay build identity does not match " - "the generated fixtures: selftest_fixture_bootstrap must be false" - ) - expected = { - "source_revision": source_revision, - "native_build_inputs_sha256": native_build_inputs_sha256, - "version": candidate_version, - } - for key, value in expected.items(): - if payload.get(key) != value: - raise GateError( - "authenticated candidate overlay build identity does not match " - f"the generated fixtures: {key} expected {value!r}, got " - f"{payload.get(key)!r}" - ) - fingerprint = payload.get("candidate_fingerprint") - if ( - not isinstance(fingerprint, str) - or re.fullmatch(r"[0-9a-f]{12}", fingerprint) is None - or not candidate_version.endswith(f"+candidate.{fingerprint}") - ): - raise GateError( - "authenticated candidate overlay fingerprint does not match its " - f"candidate version: {resolved_build_info}" - ) - if "release_prepared_model_bootstrap" in payload: - raise GateError( - "authenticated candidate overlay unexpectedly enables release " - f"prepared-model bootstrap: {resolved_build_info}" - ) - - -@contextmanager -def authenticated_candidate_overlay( - execution_paths: ExecutionPaths, - *, - source_revision: str, - native_build_inputs_sha256: str, - candidate_version: str, -) -> Iterator[Path]: - """Stage one authenticated candidate graph shared by every Cargo command.""" - - source_revision = _validated_identity_digest( - source_revision, - label="source revision", - length=40, - pattern=_SOURCE_REVISION_PATTERN, - ) - native_build_inputs_sha256 = _validated_identity_digest( - native_build_inputs_sha256, - label="native build inputs SHA-256", - length=64, - pattern=_NATIVE_BUILD_INPUTS_PATTERN, - ) - if _CANDIDATE_VERSION_PATTERN.fullmatch(candidate_version) is None: - raise GateError( - "candidate version must identify an authenticated candidate build" - ) - try: - execution_paths.create() - build_backend._check_dependencies("candidate") - with build_backend._overlay( - "candidate", - temporary_directory=execution_paths.tmpdir, - cargo_target_directory=execution_paths.cargo_target_dir, - ) as (overlay, cargo_target): - resolved_overlay = overlay.resolve(strict=True) - resolved_tmpdir = execution_paths.tmpdir.resolve(strict=True) - resolved_target = cargo_target.resolve(strict=False) - try: - resolved_overlay.relative_to(resolved_tmpdir) - except ValueError as error: - raise GateError( - "authenticated candidate overlay escaped the workspace-local " - f"temporary root: {resolved_overlay}" - ) from error - if resolved_target != execution_paths.cargo_target_dir: - raise GateError( - "authenticated candidate overlay selected the wrong Cargo " - f"target directory: {resolved_target}" - ) - for required in ( - resolved_overlay / "Cargo.lock", - resolved_overlay / ".cargo" / "config.toml", - ): - if not required.is_file(): - raise GateError( - "authenticated candidate overlay is incomplete: " - f"{required}" - ) - _authenticate_candidate_overlay_build_info( - resolved_overlay, - source_revision=source_revision, - native_build_inputs_sha256=native_build_inputs_sha256, - candidate_version=candidate_version, - ) - yield resolved_overlay - except GateError: - raise - except (OSError, RuntimeError, subprocess.CalledProcessError) as error: - raise GateError( - f"could not stage the authenticated candidate Cargo overlay: {error}" - ) from error - - -def _core_lib_command( - cargo: str, - manifest: Path, - label: str, - test_name: str, -) -> GateCommand: - return GateCommand( - label=label, - arguments=( - cargo, - "test", - "--locked", - "--manifest-path", - str(manifest), - "-p", - "rusticol-core", - "--lib", - test_name, - "--", - "--exact", - "--show-output", - "--test-threads=1", - ), - expected_tests=(test_name,), - ) - - -def gate_commands( - *, - cargo: str, - workspace_root: Path, -) -> tuple[GateCommand, ...]: - manifest = workspace_root.resolve() / "Cargo.toml" - if not manifest.is_file(): - raise GateError(f"workspace Cargo.toml is missing: {manifest}") - - commands = [ - _core_lib_command( - cargo, - manifest, - "compiled O3 full allocation and selector contract", - _COMPILED_FULL_TEST, - ), - _core_lib_command( - cargo, - manifest, - "compiled O3 quick replay allocation contract", - _COMPILED_QUICK_TEST, - ), - _core_lib_command( - cargo, - manifest, - "eager O2 allocation and selector contract", - _EAGER_ALLOCATION_TEST, - ), - GateCommand( - label="recurrence topology/union O2 generated-artifact contracts", - arguments=( - cargo, - "test", - "--locked", - "--manifest-path", - str(manifest), - "-p", - "rusticol-core", - "--lib", - "engine::recurrence_integration_tests::", - "--", - "--show-output", - "--test-threads=1", - ), - expected_tests=( - _RECURRENCE_SMOKE_TEST, - _RECURRENCE_BOUNDARY_TEST, - ), - ), - GateCommand( - label="recurrence generated-artifact allocation contracts", - arguments=( - cargo, - "test", - "--locked", - "--manifest-path", - str(manifest), - "-p", - "rusticol-core", - "--test", - "recurrence_direct_arena_allocations", - "--", - "--show-output", - "--test-threads=1", - ), - expected_tests=_RECURRENCE_ALLOCATION_TESTS, - ), - GateCommand( - label="compiled, eager, and recurrence genuine-artifact odd-tail contracts", - arguments=( - cargo, - "test", - "--locked", - "--manifest-path", - str(manifest), - "-p", - "rusticol-core", - "--test", - "generated_artifact_odd_tails", - "--", - "--show-output", - "--test-threads=1", - ), - expected_tests=_ODD_TAIL_TESTS, - ), - GateCommand( - label="compiled and eager C ABI generated-artifact contracts", - arguments=( - cargo, - "test", - "--locked", - "--manifest-path", - str(manifest), - "-p", - "rusticol-capi", - "--test", - "eager_artifact", - "--", - "--show-output", - "--test-threads=1", - ), - expected_tests=_CAPI_ARTIFACT_TESTS, - ), - GateCommand( - label="compiled and contracted C ABI selector contracts", - arguments=( - cargo, - "test", - "--locked", - "--manifest-path", - str(manifest), - "-p", - "rusticol-capi", - "--test", - "runtime_selectors", - "--", - "--show-output", - "--test-threads=1", - ), - expected_tests=_CAPI_SELECTOR_TESTS, - ), - ] - return tuple(commands) - - -def verify_test_markers(command: GateCommand, output: str) -> None: - missing = [ - test_name - for test_name in command.expected_tests - if re.search( - rf"(?m)^test {re.escape(test_name)} \.\.\. ok(?:[ \t].*)?\r?$", - output, - ) - is None - ] - if missing: - raise GateError( - f"{command.label} did not run every required test; " - f"missing successful markers: {missing}" - ) - - -def run_commands( - commands: Sequence[GateCommand], - *, - environment: Mapping[str, str], - execution_paths: ExecutionPaths, - workspace_root: Path, -) -> None: - required_environment = { - environment_name - for environment_name, _fixture_name in _ARTIFACT_ENVIRONMENT_ROUTES - } - if set(environment) != required_environment: - missing = sorted(required_environment.difference(environment)) - unexpected = sorted(set(environment).difference(required_environment)) - raise GateError( - "generated-fixture environment is incomplete " - f"(missing={missing}, unexpected={unexpected})" - ) - try: - execution_paths.create() - except OSError as error: - raise GateError( - f"could not create workspace-local execution directories: {error}" - ) from error - updates = { - **environment, - **execution_paths.environment(), - **build_backend._macos_native_build_updates(), - } - inherited = { - name: value - for name, value in build_backend._clean_environment(updates).items() - if not (name.startswith("RUSTICOL_") and name.endswith("_ARTIFACT")) - } - inherited.update(environment) - - print("[generated-fixture-gate] artifact mappings", flush=True) - for name in sorted(environment): - print(f"{name}={shlex.quote(environment[name])}", flush=True) - print("[generated-fixture-gate] execution environment", flush=True) - for name, value in sorted(execution_paths.environment().items()): - print(f"{name}={shlex.quote(value)}", flush=True) - - for command in commands: - print(f"[generated-fixture-gate] {command.label}", flush=True) - print(f"$ {shlex.join(command.arguments)}", flush=True) - try: - completed = subprocess.run( - command.arguments, - cwd=workspace_root, - env=inherited, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - text=True, - check=False, - ) - except OSError as error: - raise GateError(f"could not launch {command.label}: {error}") from error - sys.stdout.write(completed.stdout) - sys.stdout.flush() - if completed.returncode != 0: - raise GateError( - f"{command.label} failed with exit status {completed.returncode}" - ) - verify_test_markers(command, completed.stdout) - - -def plan_payload( - fixtures: FixturePaths, - commands: Sequence[GateCommand], - *, - execution_paths: ExecutionPaths, - workspace_root: Path, - source_revision: str, - native_build_inputs_sha256: str, -) -> dict[str, object]: - environment = artifact_environment(fixtures) - environment.update(execution_paths.environment()) - source_manifest = str(workspace_root.resolve() / "Cargo.toml") - return { - "schema_version": 1, - "workspace_root": str(workspace_root.resolve()), - "cargo_input": { - "mode": "authenticated-candidate-overlay", - "manifest": _CANDIDATE_MANIFEST_PLACEHOLDER, - "shared_target": str(execution_paths.cargo_target_dir), - }, - "fixture_identity": { - "producer": { - "distribution": "pyamplicol", - "git_revision": source_revision, - "native_build_inputs_sha256": native_build_inputs_sha256, - "version_pattern": _CANDIDATE_VERSION_PATTERN.pattern, - }, - "process": { - "id": _EXPECTED_PROCESS_ID, - "expression": _EXPECTED_PROCESS_EXPRESSION, - "external_pdgs": list(_EXPECTED_EXTERNAL_PDGS), - }, - }, - "artifacts": { - name: str(path) for name, path in fixtures.as_dict().items() - }, - "execution_paths": { - name: str(path) - for name, path in execution_paths.as_dict().items() - }, - "environment": environment, - "commands": [ - { - "label": command.label, - "arguments": [ - ( - _CANDIDATE_MANIFEST_PLACEHOLDER - if argument == source_manifest - else argument - ) - for argument in command.arguments - ], - "expected_tests": list(command.expected_tests), - } - for command in commands - ], - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) - parser.add_argument("--compiled-o3-artifact", required=True) - parser.add_argument("--eager-o2-artifact", required=True) - parser.add_argument("--recurrence-topology-o2-artifact", required=True) - parser.add_argument("--recurrence-union-o2-artifact", required=True) - parser.add_argument("--contracted-nlc-artifact", required=True) - parser.add_argument( - "--source-revision", - required=True, - help="authenticated candidate source revision (40 lowercase hex digits)", - ) - parser.add_argument( - "--native-build-inputs-sha256", - required=True, - help="authenticated candidate native-build-input digest", - ) - parser.add_argument( - "--cargo-home", - default=str(_DEFAULT_EXECUTION_ROOT / "cargo-home"), - help="workspace-local Cargo home", - ) - parser.add_argument( - "--cargo-target-dir", - default=str(_DEFAULT_EXECUTION_ROOT / "cargo-target"), - help="workspace-local Cargo target directory", - ) - parser.add_argument( - "--tmpdir", - default=str(_DEFAULT_EXECUTION_ROOT / "tmp"), - help="workspace-local temporary directory", - ) - parser.add_argument( - "--pip-cache-dir", - default=str(_DEFAULT_EXECUTION_ROOT / "pip-cache"), - help="workspace-local pip cache", - ) - parser.add_argument( - "--xdg-cache-home", - default=str(_DEFAULT_EXECUTION_ROOT / "xdg-cache"), - help="workspace-local XDG cache", - ) - parser.add_argument( - "--python-cache-prefix", - default=str(_DEFAULT_EXECUTION_ROOT / "python-cache"), - help="workspace-local Python bytecode cache", - ) - parser.add_argument( - "--cargo", - default="cargo", - help="Cargo executable to invoke from PATH or by explicit path", - ) - parser.add_argument( - "--plan", - action="store_true", - help="preflight fixtures and print the exact JSON plan without running Cargo", - ) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - parser = _parser() - arguments = parser.parse_args(argv) - raw_paths = { - "compiled_o3": arguments.compiled_o3_artifact, - "eager_o2": arguments.eager_o2_artifact, - "recurrence_topology_o2": arguments.recurrence_topology_o2_artifact, - "recurrence_union_o2": arguments.recurrence_union_o2_artifact, - "contracted_nlc": arguments.contracted_nlc_artifact, - } - raw_execution_paths = { - "cargo_home": arguments.cargo_home, - "cargo_target_dir": arguments.cargo_target_dir, - "tmpdir": arguments.tmpdir, - "pip_cache_dir": arguments.pip_cache_dir, - "xdg_cache_home": arguments.xdg_cache_home, - "python_cache_prefix": arguments.python_cache_prefix, - } - try: - fixtures = preflight_fixtures( - raw_paths, - workspace_root=ROOT, - source_revision=arguments.source_revision, - native_build_inputs_sha256=arguments.native_build_inputs_sha256, - ) - execution_paths = preflight_execution_paths( - raw_execution_paths, - workspace_root=ROOT, - ) - candidate_version = _common_fixture_candidate_version(fixtures) - if arguments.plan: - commands = gate_commands(cargo=arguments.cargo, workspace_root=ROOT) - print( - json.dumps( - plan_payload( - fixtures, - commands, - execution_paths=execution_paths, - workspace_root=ROOT, - source_revision=arguments.source_revision, - native_build_inputs_sha256=( - arguments.native_build_inputs_sha256 - ), - ), - indent=2, - sort_keys=True, - ) - ) - return 0 - with authenticated_candidate_overlay( - execution_paths, - source_revision=arguments.source_revision, - native_build_inputs_sha256=arguments.native_build_inputs_sha256, - candidate_version=candidate_version, - ) as overlay: - commands = gate_commands( - cargo=arguments.cargo, - workspace_root=overlay, - ) - run_commands( - commands, - environment=artifact_environment(fixtures), - execution_paths=execution_paths, - workspace_root=overlay, - ) - except GateError as error: - print(f"error: {error}", file=sys.stderr) - return 2 - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/symjit_2_22_migration_benchmark_gate.py b/pyamplicol/tools/developer/symjit_2_22_migration_benchmark_gate.py deleted file mode 100644 index afb77a815a..0000000000 --- a/pyamplicol/tools/developer/symjit_2_22_migration_benchmark_gate.py +++ /dev/null @@ -1,4140 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Compare authenticated SymJIT 2.22 migration benchmark captures. - -The recurrence z+6g harness deliberately records raw, independently warmed -subprocess measurements. This gate consumes one topology-replay and one -all-flow-union capture for both the immutable pre-migration baseline and the -candidate. It validates their workload identities, recomputes every statistic -used for acceptance from the retained raw samples, authenticates the outer -30-GiB watchdog report against the paired command/session/result, and emits one -content-addressed comparison record. The exact candidate revision, both native -build-input digests, and both prepared-model digests are independent required -inputs rather than identities inferred from the captures being judged. - -This is a focused migration gate. It reports compiled/recurrence and eager -inventories separately, but applies the same regression acceptance rules to -all three required lanes. -""" - -from __future__ import annotations - -import argparse -import datetime as dt -import hashlib -import json -import math -import os -import statistics -import sys -import tempfile -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -CAPTURE_KIND = "pyamplicol-recurrence-z6g-benchmark" -MINIMUM_CAPTURE_SCHEMA = 7 -COMPARISON_KIND = "pyamplicol-symjit-2.22-migration-benchmark-comparison" -COMPARISON_SCHEMA = 2 -BASELINE_REVISION = "172e58fd33a3c65563866c50cfbb5e1ddcd7b302" - -LAYOUTS = ("topology-replay", "all-flow-union") -AUTHORITATIVE_MODES = ("compiled", "recurrence") -DIAGNOSTIC_MODES = ("eager",) -MODES = AUTHORITATIVE_MODES -CAPTURE_MODES = AUTHORITATIVE_MODES -BATCH_SIZES = (1, 128, 1024) -RATIO_BATCH_SIZES = (128, 1024) -MINIMUM_SUBPROCESS_SAMPLES = 7 -MINIMUM_INTERNAL_SAMPLES = 7 -MINIMUM_WARMUPS = 2 -MINIMUM_TARGET_RUNTIME_SECONDS = 5.0 - -RUNTIME_RELATIVE_LIMIT = 1.03 -RUNTIME_NOISE_MAD_MULTIPLIER = 3.0 -COMPILED_RECURRENCE_RATIO_LIMIT = 1.15 -GENERATION_CELL_LIMIT = 1.10 -GENERATION_GEOMEAN_LIMIT = 1.05 -RESOURCE_GROWTH_LIMIT = 1.03 -RESOURCE_EXCEPTION_GAIN = 0.10 - -STRICT_SEMANTIC_COMPARISON_POLICY = "strict-exact-v1" -SELECTED_UNION_SEMANTIC_COMPARISON_POLICY = ( - "ddbar-z6g-all-flow-union-selected-helicity-v1" -) -SELECTED_UNION_PROCESS = "d d~ > Z g g g g g g" -SELECTED_UNION_HELICITY_ID = "h:-1,+1,-1,+1,-1,+1,-1,+1,-1" -SELECTED_UNION_HELICITY_VALUES = (-1, 1, -1, 1, -1, 1, -1, 1, -1) -SELECTED_UNION_HELICITY_INDEX = 234 -SELECTED_UNION_COLOR_COUNT = 720 -PAIRED_CAMPAIGN_KIND = "pyamplicol-symjit-2.22-paired-benchmark-campaign" -PAIRED_CAMPAIGN_SCHEMA = 2 -PAIRED_HARNESS_KIND = "pyamplicol-paired-benchmark-harness-identity" -PAIRED_HARNESS_SCHEMA = 1 -PAIRED_HARNESS_RELATIVE_PATH = "tools/developer/recurrence_z6g_benchmark.py" -PAIRED_DRIVER_RELATIVE_PATH = "tools/developer/symjit_2_22_paired_benchmark.py" -RAW_NATIVE_WALL_BLOCK_KIND = "pyamplicol-raw-native-wall-blocks" -RAW_NATIVE_WALL_BLOCK_SCHEMA = 2 -RAW_NATIVE_WALL_MEASUREMENT_CONTRACT = ( - "warmed-native-wall-minimum-duration-v1" -) -WATCHDOG_REPORT_KIND = "pyamplicol-memory-watchdog-execution-report" -WATCHDOG_REPORT_SCHEMA = 2 -WATCHDOG_LIMIT_BYTES = 30 * 1024**3 -WATCHDOG_SCOPE = "complete-orchestrator-process-tree-v1" -WATCHDOG_BINDING = "outer-command-session-result-v1" -WATCHDOG_RELATIVE_PATH = "tools/ci/memory_watchdog.py" - -_SHA256_LENGTH = 64 -_REVISION_LENGTH = 40 - - -class EvidenceError(RuntimeError): - """Raised when a capture cannot support an acceptance decision.""" - - -@dataclass(frozen=True) -class Distribution: - """Raw values and statistics recomputed by this gate.""" - - values: tuple[float, ...] - median: float - raw_mad: float - - def as_dict(self) -> dict[str, object]: - return { - "sample_count": len(self.values), - "values": list(self.values), - "median": self.median, - "raw_mad": self.raw_mad, - } - - -@dataclass(frozen=True) -class CellEvidence: - """One validated mode/batch cell from a capture.""" - - runtime: Distribution - cold_load: Distribution - cold_load_rss: Distribution - profiled_rss: Distribution - by_round: Mapping[int, float] - - -@dataclass(frozen=True) -class GenerationEvidence: - """Fresh generation metrics for one mode.""" - - wall_seconds: float - payload_size_bytes: int - peak_rss_bytes: int - - -@dataclass(frozen=True) -class CaptureEvidence: - """Validated evidence extracted from one recurrence-z6g capture.""" - - input_identity: Mapping[str, object] - layout: str - logical_process: str - source_revision: str - build_identity: Mapping[str, object] - host_identity: Mapping[str, object] - campaign_identity: Mapping[str, object] - workload_identities: Mapping[str, Mapping[str, object]] - cells: Mapping[tuple[str, int], CellEvidence] - generation: Mapping[str, GenerationEvidence] - configured_modes: tuple[str, ...] - paired_profile_coordination: Mapping[str, object] - eager_diagnostic: Mapping[str, object] - interpreter_path: str - interpreter_resolved_path: str - prepared_model_path: str - prepared_model_sha256: str - - -def _canonical_json_bytes(value: object) -> bytes: - try: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - except (TypeError, ValueError) as error: - raise EvidenceError("evidence is not canonical-JSON serializable") from error - - -def _sha256(value: object) -> str: - return hashlib.sha256(_canonical_json_bytes(value)).hexdigest() - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - try: - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - except OSError as error: - raise EvidenceError(f"cannot read capture: {path}") from error - return digest.hexdigest() - - -def _input_identity(path: Path) -> dict[str, object]: - try: - resolved = path.expanduser().resolve(strict=True) - stat = resolved.stat() - except OSError as error: - raise EvidenceError(f"cannot inspect capture: {path}") from error - if not resolved.is_file(): - raise EvidenceError(f"capture is not a regular file: {path}") - return { - "path": str(path), - "resolved_path": str(resolved), - "size_bytes": stat.st_size, - "sha256": _sha256_file(resolved), - } - - -def _read_json_mapping( - path: Path, - *, - label: str, -) -> tuple[dict[str, Any], dict[str, object]]: - identity = _input_identity(path) - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise EvidenceError(f"{label} is not valid UTF-8 JSON: {path}") from error - if not isinstance(value, dict): - raise EvidenceError(f"{label} root is not an object: {path}") - return value, identity - - -def _read_capture(path: Path) -> tuple[dict[str, Any], dict[str, object]]: - return _read_json_mapping(path, label="capture") - - -def _mapping(value: object, label: str) -> Mapping[str, Any]: - if not isinstance(value, Mapping): - raise EvidenceError(f"{label} is missing or is not an object") - return value - - -def _sequence(value: object, label: str) -> Sequence[Any]: - if isinstance(value, (str, bytes, bytearray)) or not isinstance(value, Sequence): - raise EvidenceError(f"{label} is missing or is not an array") - return value - - -def _string(value: object, label: str) -> str: - if not isinstance(value, str) or not value: - raise EvidenceError(f"{label} is missing or is not a non-empty string") - return value - - -def _exact_int(value: object, label: str, *, minimum: int | None = None) -> int: - if isinstance(value, bool) or not isinstance(value, int): - raise EvidenceError(f"{label} is missing or is not an integer") - if minimum is not None and value < minimum: - raise EvidenceError(f"{label} must be at least {minimum}") - return value - - -def _positive_number(value: object, label: str) -> float: - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise EvidenceError(f"{label} is missing or is not numeric") - result = float(value) - if not math.isfinite(result) or result <= 0.0: - raise EvidenceError(f"{label} must be a positive finite number") - return result - - -def _nonnegative_number(value: object, label: str) -> float: - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise EvidenceError(f"{label} is missing or is not numeric") - result = float(value) - if not math.isfinite(result) or result < 0.0: - raise EvidenceError(f"{label} must be a finite non-negative number") - return result - - -def _valid_sha256(value: object, label: str) -> str: - result = _string(value, label) - if len(result) != _SHA256_LENGTH: - raise EvidenceError(f"{label} is not a SHA-256 digest") - try: - int(result, 16) - except ValueError as error: - raise EvidenceError(f"{label} is not a SHA-256 digest") from error - if result != result.lower(): - raise EvidenceError(f"{label} is not a lowercase SHA-256 digest") - return result - - -def _valid_revision(value: object, label: str) -> str: - result = _string(value, label) - if len(result) != _REVISION_LENGTH: - raise EvidenceError(f"{label} is not a full Git revision") - try: - int(result, 16) - except ValueError as error: - raise EvidenceError(f"{label} is not a Git revision") from error - if result != result.lower(): - raise EvidenceError(f"{label} is not a lowercase Git revision") - return result - - -def _validate_content_address(value: object, label: str) -> Mapping[str, Any]: - record = _mapping(value, label) - unsigned = dict(record) - digest = _valid_sha256( - unsigned.pop("content_sha256", None), f"{label}.content_sha256" - ) - if digest != _sha256(unsigned): - raise EvidenceError(f"{label} content address does not match its payload") - return record - - -def _validate_nested_content_addresses(value: object, label: str) -> None: - if isinstance(value, Mapping): - if "content_sha256" in value: - record = _validate_content_address(value, label) - for field, child in record.items(): - if field != "content_sha256": - _validate_nested_content_addresses(child, f"{label}.{field}") - return - for field, child in value.items(): - _validate_nested_content_addresses(child, f"{label}.{field}") - elif isinstance(value, Sequence) and not isinstance( - value, - (str, bytes, bytearray), - ): - for index, child in enumerate(value): - _validate_nested_content_addresses(child, f"{label}[{index}]") - - -def _utc_timestamp(value: object, label: str) -> dt.datetime: - if not isinstance(value, str): - raise EvidenceError(f"{label} is not a UTC timestamp") - try: - parsed = dt.datetime.fromisoformat(value) - except ValueError as error: - raise EvidenceError(f"{label} is not a UTC timestamp") from error - if parsed.tzinfo is None or parsed.utcoffset() != dt.timedelta(0): - raise EvidenceError(f"{label} is not a UTC timestamp") - return parsed - - -def _distribution(values: Sequence[float], label: str) -> Distribution: - if len(values) < MINIMUM_SUBPROCESS_SAMPLES: - raise EvidenceError( - f"{label} has {len(values)} subprocess samples; " - f"at least {MINIMUM_SUBPROCESS_SAMPLES} are required" - ) - checked = tuple(_positive_number(value, f"{label} raw sample") for value in values) - median = float(statistics.median(checked)) - raw_mad = float(statistics.median(abs(value - median) for value in checked)) - return Distribution(values=checked, median=median, raw_mad=raw_mad) - - -def _rss_observation(value: object, label: str) -> float: - peak = _mapping(value, label) - if peak.get("source") != "resource.getrusage": - raise EvidenceError(f"{label} has an unsupported RSS source") - self_peak = _exact_int( - peak.get("self_peak_bytes"), f"{label}.self_peak_bytes", minimum=0 - ) - child_peak = _exact_int( - peak.get("maximum_child_peak_bytes"), - f"{label}.maximum_child_peak_bytes", - minimum=0, - ) - observed = _exact_int( - peak.get("observed_lower_bound_bytes"), - f"{label}.observed_lower_bound_bytes", - minimum=1, - ) - if observed != max(self_peak, child_peak): - raise EvidenceError(f"{label} is not a consistent resource peak") - return float(observed) - - -def _recorded_statistic( - observed: object, - expected: float, - label: str, -) -> None: - value = _nonnegative_number(observed, label) - if not math.isclose(value, expected, rel_tol=1.0e-14, abs_tol=0.0): - raise EvidenceError( - f"{label} is not reproducible from retained raw subprocess samples" - ) - - -def _logical_process(value: object, label: str) -> str: - normalized = " ".join(_string(value, label).split()).casefold() - supported = { - "u u~ > z g g g g g g": "u u~ > Z g g g g g g", - "d d~ > z + 6*g": "d d~ > Z g g g g g g", - "d d~ > z g g g g g g": "d d~ > Z g g g g g g", - } - try: - return supported[normalized] - except KeyError as error: - raise EvidenceError( - f"{label} is not the supported u u~ or exact d d~ > Z + 6g route" - ) from error - - -def _expected_semantic_comparison_policy( - *, - logical_process: str, - layout: str, - configuration: Mapping[str, Any], - label: str, -) -> str: - if logical_process == SELECTED_UNION_PROCESS and layout == "all-flow-union": - if configuration.get("helicity_request") != SELECTED_UNION_HELICITY_ID: - raise EvidenceError( - f"{label} exact d all-flow-union route must select " - f"{SELECTED_UNION_HELICITY_ID}" - ) - return SELECTED_UNION_SEMANTIC_COMPARISON_POLICY - return STRICT_SEMANTIC_COMPARISON_POLICY - - -def _validated_selected_union_projection( - value: object, - *, - configuration: Mapping[str, Any], - label: str, -) -> Mapping[str, Any]: - projection = _mapping(value, label) - expected_fields = { - "policy", - "process_id", - "process_expression", - "physical_color_flows", - "physical_helicities", - "normalization_sha256", - "model_common_physics_identity_sha256", - "runtime_selector_semantics_sha256", - "profile_selector", - "resolved_color_ids_sha256", - } - if set(projection) != expected_fields: - raise EvidenceError(f"{label} has an unexpected projection schema") - if ( - projection.get("policy") != SELECTED_UNION_SEMANTIC_COMPARISON_POLICY - or _logical_process( - projection.get("process_expression"), - f"{label}.process_expression", - ) - != SELECTED_UNION_PROCESS - ): - raise EvidenceError(f"{label} has the wrong selected-union policy or process") - _string(projection.get("process_id"), f"{label}.process_id") - - colors = _mapping( - projection.get("physical_color_flows"), - f"{label}.physical_color_flows", - ) - if ( - set(colors) - != { - "count", - "ordered_ids_sha256", - "ordered_entries_sha256", - } - or _exact_int( - colors.get("count"), - f"{label}.physical_color_flows.count", - minimum=1, - ) - != SELECTED_UNION_COLOR_COUNT - ): - raise EvidenceError(f"{label} does not bind exactly 720 physical colors") - for field in ("ordered_ids_sha256", "ordered_entries_sha256"): - _valid_sha256(colors.get(field), f"{label}.physical_color_flows.{field}") - - helicities = _mapping( - projection.get("physical_helicities"), - f"{label}.physical_helicities", - ) - if set(helicities) != { - "count", - "ordered_ids_sha256", - "kinematic_entries_sha256", - "selected_index", - "selected_entry", - }: - raise EvidenceError(f"{label} has an invalid physical-helicity projection") - helicity_count = _exact_int( - helicities.get("count"), - f"{label}.physical_helicities.count", - minimum=SELECTED_UNION_HELICITY_INDEX + 1, - ) - selected_index = _exact_int( - helicities.get("selected_index"), - f"{label}.physical_helicities.selected_index", - minimum=0, - ) - if selected_index != SELECTED_UNION_HELICITY_INDEX: - raise EvidenceError(f"{label} selected helicity has the wrong ordered index") - for field in ("ordered_ids_sha256", "kinematic_entries_sha256"): - _valid_sha256(helicities.get(field), f"{label}.physical_helicities.{field}") - selected = _mapping( - helicities.get("selected_entry"), - f"{label}.physical_helicities.selected_entry", - ) - if ( - set(selected) != {"index", "id", "values", "coefficient", "structural_zero"} - or selected.get("index") != selected_index - or selected.get("id") != SELECTED_UNION_HELICITY_ID - or selected.get("values") != list(SELECTED_UNION_HELICITY_VALUES) - or selected.get("structural_zero") is not False - ): - raise EvidenceError(f"{label} selected helicity entry is not canonical/live") - _positive_number( - selected.get("coefficient"), - f"{label}.physical_helicities.selected_entry.coefficient", - ) - - selector = _mapping( - projection.get("profile_selector"), - f"{label}.profile_selector", - ) - if ( - set(selector) - != { - "color_flow_request", - "resolved_color_flow_id", - "helicity_request", - "resolved_helicity_id", - "color_flow_count", - "helicity_count", - "workload", - } - or selector.get("color_flow_request") != configuration.get("color_flow_request") - or selector.get("resolved_color_flow_id") is not None - or selector.get("helicity_request") != SELECTED_UNION_HELICITY_ID - or selector.get("resolved_helicity_id") != SELECTED_UNION_HELICITY_ID - or selector.get("color_flow_count") != SELECTED_UNION_COLOR_COUNT - or selector.get("helicity_count") != helicity_count - or selector.get("workload") != "all-flows/runtime-selected-single-helicity" - ): - raise EvidenceError(f"{label} has the wrong selected-union selector") - for field in ( - "normalization_sha256", - "model_common_physics_identity_sha256", - "runtime_selector_semantics_sha256", - "resolved_color_ids_sha256", - ): - _valid_sha256(projection.get(field), f"{label}.{field}") - return projection - - -def _capture_semantic_projection( - acceptance: Mapping[str, Any], - *, - configuration: Mapping[str, Any], - logical_process: str, - layout: str, - label: str, -) -> Mapping[str, Any] | None: - semantic_contract = _mapping( - acceptance.get("artifact_semantic_contract"), - f"{label}.artifact_semantic_contract", - ) - lane_contracts = _mapping( - semantic_contract.get("lane_contracts"), - f"{label}.artifact_semantic_contract.lane_contracts", - ) - expected_policy = _expected_semantic_comparison_policy( - logical_process=logical_process, - layout=layout, - configuration=configuration, - label=label, - ) - if semantic_contract.get("comparison_policy") != expected_policy: - raise EvidenceError( - f"{label} artifact-semantic comparison policy does not match its route" - ) - if expected_policy == STRICT_SEMANTIC_COMPARISON_POLICY: - if any( - isinstance(lane, Mapping) and "selected_union_workload_projection" in lane - for lane in lane_contracts.values() - ): - raise EvidenceError( - f"{label} strict route unexpectedly contains a " - "selected-union projection" - ) - return None - - common = _validated_selected_union_projection( - semantic_contract.get("common_physics_contract"), - configuration=configuration, - label=f"{label}.artifact_semantic_contract.common_physics_contract", - ) - for mode in CAPTURE_MODES: - lane = _mapping( - lane_contracts.get(mode), - f"{label}.artifact_semantic_contract.lane_contracts.{mode}", - ) - lane_projection = lane.get("selected_union_workload_projection") - if lane_projection != common: - raise EvidenceError( - f"{label} {mode} selected-union projection differs from common" - ) - return common - - -def _validate_capture_acceptance( - payload: Mapping[str, Any], - configuration: Mapping[str, Any], - *, - expected_layout: str, - subprocess_samples: int, - internal_samples: int, - warmups: int, - configured_modes: Sequence[str], -) -> Mapping[str, Any]: - label = f"{expected_layout}.capture_acceptance" - if payload.get("complete") is not True or payload.get("passes") is not True: - raise EvidenceError( - f"{expected_layout} capture is not top-level complete and passing" - ) - acceptance = _mapping(payload.get("capture_acceptance"), label) - if ( - acceptance.get("kind") != "pyamplicol-three-lane-layout-capture" - or _exact_int( - acceptance.get("schema_version"), - f"{label}.schema_version", - ) - < 6 - ): - raise EvidenceError(f"{label} has an unsupported identity") - required_true = ( - "complete", - "evidence_complete", - "passes", - "authoritative_eligible", - "lane_self_validation_passes", - "pairwise_validation_passes", - ) - if any(acceptance.get(field) is not True for field in required_true): - raise EvidenceError(f"{label} is not authoritative, complete, and passing") - if ( - acceptance.get("authoritative_ineligibility_reasons") != [] - or acceptance.get("generation_specialized_axes_by_mode") != {} - or acceptance.get("incomplete_physical_axes") != [] - or acceptance.get("missing_modes") != [] - or acceptance.get("missing_batch_sizes") != [] - or acceptance.get("generation_only") is not False - or acceptance.get("layout") != expected_layout - ): - raise EvidenceError(f"{label} contains authoritative ineligibility evidence") - if ( - list( - _sequence( - acceptance.get("required_modes"), - f"{label}.required_modes", - ) - ) - != list(CAPTURE_MODES) - or list( - _sequence( - acceptance.get("observed_modes"), - f"{label}.observed_modes", - ) - ) - != list(CAPTURE_MODES) - or set( - _sequence( - acceptance.get("required_batch_sizes"), - f"{label}.required_batch_sizes", - ) - ) - != set(BATCH_SIZES) - or set( - _sequence( - acceptance.get("observed_batch_sizes"), - f"{label}.observed_batch_sizes", - ) - ) - != set(BATCH_SIZES) - ): - raise EvidenceError(f"{label} required/observed inventory is inconsistent") - - measurement = _mapping( - acceptance.get("measurement_contract"), - f"{label}.measurement_contract", - ) - if ( - measurement.get("passes") is not True - or measurement.get("root_processes_match") is not True - or measurement.get("configured_internal_minimum_samples") != internal_samples - or measurement.get("configured_subprocess_samples") != subprocess_samples - or measurement.get("configured_warmup_runs") != warmups - or _exact_int( - measurement.get("minimum_authoritative_samples"), - f"{label}.measurement_contract.minimum_authoritative_samples", - minimum=MINIMUM_SUBPROCESS_SAMPLES, - ) - > subprocess_samples - ): - raise EvidenceError(f"{label} measurement contract is inconsistent") - schedule_contract = _mapping( - measurement.get("schedule"), - f"{label}.measurement_contract.schedule", - ) - expected_entry_count = len(configured_modes) * len(BATCH_SIZES) * subprocess_samples - if ( - schedule_contract.get("passes") is not True - or schedule_contract.get("errors") != [] - or schedule_contract.get("entry_count") != expected_entry_count - or schedule_contract.get("unique_worker_command_count") != expected_entry_count - or schedule_contract.get("subprocess_samples_per_cell") != subprocess_samples - ): - raise EvidenceError(f"{label} schedule contract is incomplete") - lane_contracts = _mapping( - measurement.get("lanes"), - f"{label}.measurement_contract.lanes", - ) - if set(lane_contracts) != set(CAPTURE_MODES): - raise EvidenceError(f"{label} measurement lane inventory is inconsistent") - for mode in CAPTURE_MODES: - lane = _mapping( - lane_contracts.get(mode), - f"{label}.measurement_contract.lanes.{mode}", - ) - if ( - lane.get("passes") is not True - or lane.get("errors") != [] - or set( - _sequence( - lane.get("observed_batch_sizes"), - f"{label}.measurement_contract.lanes.{mode}.observed_batch_sizes", - ) - ) - != set(BATCH_SIZES) - or lane.get("missing_batch_sizes") != [] - ): - raise EvidenceError(f"{label} {mode} measurement lane is incomplete") - - semantic_contract = _mapping( - acceptance.get("artifact_semantic_contract"), - f"{label}.artifact_semantic_contract", - ) - semantic_lanes = _mapping( - semantic_contract.get("lane_contracts"), - f"{label}.artifact_semantic_contract.lane_contracts", - ) - if ( - semantic_contract.get("passes") is not True - or semantic_contract.get("errors") != [] - or semantic_contract.get("lanes_match") is not True - or not isinstance(semantic_contract.get("common_physics_contract"), Mapping) - or set(semantic_lanes) != set(CAPTURE_MODES) - ): - raise EvidenceError(f"{label} artifact-semantic contract is incomplete") - - eager = _mapping( - acceptance.get("eager_diagnostic"), - f"{label}.eager_diagnostic", - ) - eager_measurement = _mapping( - eager.get("measurement_contract"), - f"{label}.eager_diagnostic.measurement_contract", - ) - eager_semantics = _mapping( - eager.get("artifact_semantic_contract"), - f"{label}.eager_diagnostic.artifact_semantic_contract", - ) - eager_validation = _mapping( - eager.get("validation_summary"), - f"{label}.eager_diagnostic.validation_summary", - ) - if ( - eager.get("requested") is not True - or eager.get("observed") is not True - or eager.get("complete") is not True - or eager.get("passes") is not True - or eager.get("ineligibility_reasons") != [] - or eager_measurement.get("passes") is not True - or eager_semantics.get("passes") is not True - or eager_semantics.get("lanes_match") is not True - or eager_validation.get("passes") is not True - ): - raise EvidenceError(f"{label} eager diagnostic is not complete and admissible") - authoritative_validation = { - "passes": acceptance.get("passes"), - "lane_validation_passes": acceptance.get("lane_self_validation_passes"), - "pairwise_validation_passes": acceptance.get("pairwise_validation_passes"), - } - if ( - authoritative_validation["passes"] is not True - or authoritative_validation["lane_validation_passes"] is not True - or authoritative_validation["pairwise_validation_passes"] is not True - ): - raise EvidenceError( - f"{expected_layout} capture validation summary is not passing" - ) - if set( - _sequence( - configuration.get("modes"), - f"{expected_layout}.configuration.modes", - ) - ) != set(configured_modes): - raise EvidenceError(f"{label} does not match the configured lane inventory") - return acceptance - - -def _semantic_digest( - semantic: Mapping[str, Any], - field: str, - digest_field: str, - label: str, -) -> tuple[object, str]: - value = semantic.get(field) - if value is None: - raise EvidenceError(f"{label}.{field} is missing") - digest = _valid_sha256( - semantic.get(digest_field), - f"{label}.{digest_field}", - ) - if digest != _sha256(value): - raise EvidenceError(f"{label}.{digest_field} does not match {field}") - return value, digest - - -def _bind_selected_union_projection( - projection: Mapping[str, Any], - *, - semantic: Mapping[str, Any], - selector: Mapping[str, Any], - validation: Mapping[str, Any], - process_id: str, - normalization_sha256: str, - model_sha256: str, - selector_semantics_sha256: str, - label: str, -) -> None: - if projection.get("process_id") != process_id: - raise EvidenceError(f"{label} projected process ID differs from its profile") - projected_selector = _mapping( - projection.get("profile_selector"), - f"{label}.selected_union_projection.profile_selector", - ) - selector_fields = ( - "color_flow_request", - "resolved_color_flow_id", - "helicity_request", - "resolved_helicity_id", - "color_flow_count", - "helicity_count", - "workload", - ) - if set(selector) != {*selector_fields, "structural_zero_helicity_count"} or { - field: selector.get(field) for field in selector_fields - } != dict(projected_selector): - raise EvidenceError( - f"{label} selector differs from its selected-union projection" - ) - - projected_colors = _mapping( - projection.get("physical_color_flows"), - f"{label}.selected_union_projection.physical_color_flows", - ) - colors = _mapping( - semantic.get("physical_color_flows"), - f"{label}.physical_color_flows", - ) - color_ids = list( - _sequence( - colors.get("ordered_ids"), - f"{label}.physical_color_flows.ordered_ids", - ) - ) - color_entries = list( - _sequence( - colors.get("ordered_entries"), - f"{label}.physical_color_flows.ordered_entries", - ) - ) - if ( - colors.get("count") != SELECTED_UNION_COLOR_COUNT - or len(color_ids) != SELECTED_UNION_COLOR_COUNT - or len(color_entries) != SELECTED_UNION_COLOR_COUNT - or len(set(color_ids)) != SELECTED_UNION_COLOR_COUNT - or any( - not isinstance(identifier, str) or not identifier - for identifier in color_ids - ) - or _valid_sha256( - colors.get("ordered_ids_sha256"), - f"{label}.physical_color_flows.ordered_ids_sha256", - ) - != _sha256(color_ids) - or _valid_sha256( - colors.get("ordered_entries_sha256"), - f"{label}.physical_color_flows.ordered_entries_sha256", - ) - != _sha256(color_entries) - or projected_colors.get("count") != colors.get("count") - or projected_colors.get("ordered_ids_sha256") - != colors.get("ordered_ids_sha256") - or projected_colors.get("ordered_entries_sha256") - != colors.get("ordered_entries_sha256") - ): - raise EvidenceError( - f"{label} physical colors differ from selected-union projection" - ) - - projected_helicities = _mapping( - projection.get("physical_helicities"), - f"{label}.selected_union_projection.physical_helicities", - ) - helicities = _mapping( - semantic.get("physical_helicities"), - f"{label}.physical_helicities", - ) - helicity_ids = list( - _sequence( - helicities.get("ordered_ids"), - f"{label}.physical_helicities.ordered_ids", - ) - ) - raw_helicity_entries = list( - _sequence( - helicities.get("ordered_entries"), - f"{label}.physical_helicities.ordered_entries", - ) - ) - helicity_count = _exact_int( - helicities.get("count"), - f"{label}.physical_helicities.count", - minimum=SELECTED_UNION_HELICITY_INDEX + 1, - ) - if ( - len(helicity_ids) != helicity_count - or len(raw_helicity_entries) != helicity_count - or len(set(helicity_ids)) != helicity_count - or _valid_sha256( - helicities.get("ordered_ids_sha256"), - f"{label}.physical_helicities.ordered_ids_sha256", - ) - != _sha256(helicity_ids) - or projected_helicities.get("count") != helicity_count - or projected_helicities.get("ordered_ids_sha256") - != helicities.get("ordered_ids_sha256") - ): - raise EvidenceError( - f"{label} physical helicities differ from selected-union projection" - ) - kinematic_entries: list[dict[str, object]] = [] - selected_entry: dict[str, object] | None = None - for index, raw_entry in enumerate(raw_helicity_entries): - entry = _mapping( - raw_entry, - f"{label}.physical_helicities.ordered_entries[{index}]", - ) - identifier = entry.get("id") - values = entry.get("values") - if ( - entry.get("index") != index - or helicity_ids[index] != identifier - or not isinstance(identifier, str) - or not isinstance(values, list) - ): - raise EvidenceError(f"{label} physical helicity ordering is invalid") - projected_entry: dict[str, object] = { - "index": index, - "id": identifier, - "values": values, - } - if identifier == SELECTED_UNION_HELICITY_ID: - projected_entry.update( - { - "coefficient": entry.get("coefficient"), - "structural_zero": entry.get("structural_zero"), - } - ) - selected_entry = dict(entry) - kinematic_entries.append(projected_entry) - if ( - helicity_ids[SELECTED_UNION_HELICITY_INDEX] != SELECTED_UNION_HELICITY_ID - or selected_entry is None - or selected_entry != projected_helicities.get("selected_entry") - or projected_helicities.get("selected_index") != SELECTED_UNION_HELICITY_INDEX - or projected_helicities.get("kinematic_entries_sha256") - != _sha256(kinematic_entries) - ): - raise EvidenceError( - f"{label} selected helicity differs from selected-union projection" - ) - - resolved_colors = list( - _sequence( - validation.get("resolved_color_ids"), - f"{label}.validation.resolved_color_ids", - ) - ) - if ( - resolved_colors != color_ids - or projection.get("resolved_color_ids_sha256") != _sha256(resolved_colors) - or validation.get("resolved_helicity_ids") != [SELECTED_UNION_HELICITY_ID] - or projection.get("normalization_sha256") != normalization_sha256 - or projection.get("model_common_physics_identity_sha256") != model_sha256 - or projection.get("runtime_selector_semantics_sha256") - != selector_semantics_sha256 - ): - raise EvidenceError( - f"{label} selected-union physics/digests differ from projection" - ) - - -def _workload_identity( - *, - profile: Mapping[str, Any], - generation: Mapping[str, Any], - mode: str, - layout: str, - logical_process: str, - expected_workload: str, - selected_union_projection: Mapping[str, Any] | None, - label: str, -) -> dict[str, object]: - if profile.get("mode") != mode: - raise EvidenceError(f"{label}.mode does not match its lane") - if ( - _logical_process( - profile.get("process_expression"), f"{label}.process_expression" - ) - != logical_process - ): - raise EvidenceError(f"{label} process expression drifted from its capture") - process_id = _string(profile.get("process_id"), f"{label}.process_id") - selector = _mapping(profile.get("selector_contract"), f"{label}.selector_contract") - if selector.get("workload") != expected_workload: - raise EvidenceError(f"{label}.selector_contract has the wrong workload") - validation = _mapping(profile.get("validation"), f"{label}.validation") - if validation.get("passes") is not True: - raise EvidenceError(f"{label} numerical validation did not pass") - fixture = _mapping(validation.get("fixture"), f"{label}.validation.fixture") - point_count = _exact_int( - fixture.get("point_count"), - f"{label}.validation.fixture.point_count", - minimum=1, - ) - points_sha256 = _valid_sha256( - fixture.get("points_sha256"), - f"{label}.validation.fixture.points_sha256", - ) - - semantic = _mapping( - profile.get("artifact_semantic_identity"), - f"{label}.artifact_semantic_identity", - ) - semantic_digest = _valid_sha256( - profile.get("artifact_semantic_identity_sha256"), - f"{label}.artifact_semantic_identity_sha256", - ) - if semantic_digest != _sha256(semantic): - raise EvidenceError( - f"{label} artifact semantic identity is not content-addressed" - ) - generation_identity = _mapping( - generation.get("artifact_identity"), - f"{label}.generation.artifact_identity", - ) - if ( - generation_identity.get("semantic_identity") != semantic - or generation_identity.get("semantic_identity_sha256") != semantic_digest - ): - raise EvidenceError( - f"{label} profile and generation artifact identities differ" - ) - if semantic.get("generation_specialized_axes") != []: - raise EvidenceError(f"{label} has generation-specialized physical axes") - coverage = _mapping(semantic.get("coverage"), f"{label}.coverage") - if coverage.get("complete_physical_axes") is not True: - raise EvidenceError(f"{label} does not contain complete physical axes") - reduction_coverage = _mapping( - semantic.get("reduction_coverage"), - f"{label}.reduction_coverage", - ) - if reduction_coverage.get("complete") is not True: - raise EvidenceError(f"{label} reduction coverage is incomplete") - - normalization, normalization_sha256 = _semantic_digest( - semantic, - "normalization", - "normalization_sha256", - label, - ) - reduction_ordering, reduction_ordering_sha256 = _semantic_digest( - semantic, - "reduction_ordering", - "reduction_ordering_sha256", - label, - ) - selector_semantics, selector_semantics_sha256 = _semantic_digest( - semantic, - "runtime_selector_semantics", - "runtime_selector_semantics_sha256", - label, - ) - model_identity = _mapping( - semantic.get("manifest_model_identity"), - f"{label}.manifest_model_identity", - ) - common_model = _mapping( - model_identity.get("common_physics_identity"), - f"{label}.manifest_model_identity.common_physics_identity", - ) - common_model_sha256 = _valid_sha256( - model_identity.get("common_physics_identity_sha256"), - f"{label}.manifest_model_identity.common_physics_identity_sha256", - ) - if common_model_sha256 != _sha256(common_model): - raise EvidenceError(f"{label} common model identity is not content-addressed") - physical_color_flows = semantic.get("physical_color_flows") - physical_helicities = semantic.get("physical_helicities") - if physical_color_flows is None or physical_helicities is None: - raise EvidenceError(f"{label} physical-axis identity is incomplete") - - effective = _mapping( - generation.get("effective_contract"), - f"{label}.generation.effective_contract", - ) - expected_optimization = 3 if mode == "compiled" else 2 - expected_effective = { - "backend": "jit", - "color_accuracy": "lc", - "execution_mode": mode, - "jit_optimization_level": expected_optimization, - "lc_flow_layout": layout, - } - if any(effective.get(key) != value for key, value in expected_effective.items()): - raise EvidenceError( - f"{label} does not use {mode} JIT O{expected_optimization} " - f"with the requested {layout} layout" - ) - - common_identity = { - "process": logical_process, - "process_id": process_id, - "layout": layout, - "mode": mode, - "workload": expected_workload, - "validation_fixture": { - "point_count": point_count, - "points_sha256": points_sha256, - }, - "coverage_sha256": _sha256(coverage), - "effective_contract": expected_effective, - } - if selected_union_projection is not None: - _bind_selected_union_projection( - selected_union_projection, - semantic=semantic, - selector=selector, - validation=validation, - process_id=process_id, - normalization_sha256=normalization_sha256, - model_sha256=common_model_sha256, - selector_semantics_sha256=selector_semantics_sha256, - label=label, - ) - return { - **common_identity, - "semantic_comparison_policy": (SELECTED_UNION_SEMANTIC_COMPARISON_POLICY), - "selected_union_projection_sha256": _sha256(selected_union_projection), - } - - # Store digests for the large physical inventories so the comparison - # remains compact while still binding every ordered entry. - return { - **common_identity, - "selector_contract_sha256": _sha256(selector), - "common_model_identity_sha256": common_model_sha256, - "normalization_sha256": normalization_sha256, - "normalization_payload_sha256": _sha256(normalization), - "reduction_ordering_sha256": reduction_ordering_sha256, - "reduction_ordering_payload_sha256": _sha256(reduction_ordering), - "runtime_selector_semantics_sha256": selector_semantics_sha256, - "runtime_selector_semantics_payload_sha256": _sha256(selector_semantics), - "physical_color_flows_sha256": _sha256(physical_color_flows), - "physical_helicities_sha256": _sha256(physical_helicities), - } - - -def _validated_schedule_worker_records( - schedule_entry: Mapping[str, Any], - label: str, -) -> tuple[ - Mapping[str, Any], - Mapping[str, Any], - str, - str, - str, -]: - invocation = _validate_content_address( - schedule_entry.get("worker_invocation"), - f"{label}.worker_invocation", - ) - result = _validate_content_address( - schedule_entry.get("worker_result_record"), - f"{label}.worker_result_record", - ) - invocation_sha256 = _valid_sha256( - invocation.get("content_sha256"), - f"{label}.worker_invocation.content_sha256", - ) - result_sha256 = _valid_sha256( - result.get("content_sha256"), - f"{label}.worker_result_record.content_sha256", - ) - process_sha256 = _valid_sha256( - result.get("worker_process_record_sha256"), - f"{label}.worker_result_record.worker_process_record_sha256", - ) - if result.get("worker_invocation_sha256") != invocation_sha256: - raise EvidenceError( - f"{label} result is not bound to its scheduled worker invocation" - ) - return ( - invocation, - result, - invocation_sha256, - process_sha256, - result_sha256, - ) - - -def _validate_sample_address( - sample: Mapping[str, Any], - schedule_entry: Mapping[str, Any], - label: str, - seen_addresses: set[str], -) -> None: - invocation = _validate_content_address( - sample.get("worker_invocation"), f"{label}.worker_invocation" - ) - process_record = _validate_content_address( - sample.get("worker_process_record"), - f"{label}.worker_process_record", - ) - result_record = _validate_content_address( - sample.get("worker_result_record"), - f"{label}.worker_result_record", - ) - invocation_sha256 = _valid_sha256( - invocation.get("content_sha256"), - f"{label}.worker_invocation.content_sha256", - ) - process_sha256 = _valid_sha256( - process_record.get("content_sha256"), - f"{label}.worker_process_record.content_sha256", - ) - result_sha256 = _valid_sha256( - result_record.get("content_sha256"), - f"{label}.worker_result_record.content_sha256", - ) - for address_name, address in ( - ("invocation", invocation_sha256), - ("process", process_sha256), - ("result", result_sha256), - ): - scoped = f"{address_name}:{address}" - if scoped in seen_addresses: - raise EvidenceError(f"{label} reuses a {address_name} subprocess identity") - seen_addresses.add(scoped) - if ( - result_record.get("worker_invocation_sha256") != invocation_sha256 - or result_record.get("worker_process_record_sha256") != process_sha256 - ): - raise EvidenceError(f"{label} worker result is not bound to its subprocess") - ( - scheduled_invocation, - scheduled_result, - scheduled_invocation_sha256, - scheduled_process_sha256, - scheduled_result_sha256, - ) = _validated_schedule_worker_records( - schedule_entry, - f"{label}.profile_schedule_entry", - ) - if ( - scheduled_invocation != invocation - or scheduled_result != result_record - or scheduled_invocation_sha256 != invocation_sha256 - or scheduled_process_sha256 != process_sha256 - or scheduled_result_sha256 != result_sha256 - ): - raise EvidenceError( - f"{label} sample worker provenance differs from its profile schedule entry" - ) - completion = _validate_content_address( - schedule_entry.get("paired_profile_completion"), - f"{label}.paired_profile_completion", - ) - if ( - completion.get("worker_invocation_sha256") != invocation_sha256 - or completion.get("worker_result_record_sha256") != result_sha256 - or completion.get("worker_started_at_utc") != invocation.get("started_at_utc") - or completion.get("worker_finished_at_utc") != invocation.get("finished_at_utc") - ): - raise EvidenceError( - f"{label} paired completion differs from its retained sample worker" - ) - invocation_started = _utc_timestamp( - invocation.get("started_at_utc"), - f"{label}.worker_invocation.started_at_utc", - ) - invocation_finished = _utc_timestamp( - invocation.get("finished_at_utc"), - f"{label}.worker_invocation.finished_at_utc", - ) - if invocation_started > invocation_finished: - raise EvidenceError(f"{label} worker invocation timestamps are inverted") - unsigned_sample = { - str(key): value - for key, value in sample.items() - if key != "worker_result_record" - } - addressed_payload = _valid_sha256( - result_record.get("addressed_payload_sha256"), - f"{label}.worker_result_record.addressed_payload_sha256", - ) - if addressed_payload != _sha256(unsigned_sample): - raise EvidenceError(f"{label} retained raw sample content address is invalid") - if schedule_entry.get("worker_result_sha256") != addressed_payload: - raise EvidenceError(f"{label} is not bound to its profile schedule entry") - - -def _validate_raw_native_wall_measurement( - sample: Mapping[str, Any], - *, - batch_size: int, - internal_samples: int, - warmups: int, - target_runtime: float, - sample_wall: float, - fixture_points_sha256: str, - label: str, -) -> None: - raw = _mapping( - sample.get("inner_native_wall_blocks"), - f"{label}.inner_native_wall_blocks", - ) - blocks = _sequence( - raw.get("blocks"), - f"{label}.inner_native_wall_blocks.blocks", - ) - block_count = _exact_int( - raw.get("block_count"), - f"{label}.inner_native_wall_blocks.block_count", - minimum=MINIMUM_INTERNAL_SAMPLES, - ) - repetitions = _exact_int( - raw.get("repetitions_per_block"), - f"{label}.inner_native_wall_blocks.repetitions_per_block", - minimum=1, - ) - evaluation_count = _exact_int( - raw.get("evaluation_count"), - f"{label}.inner_native_wall_blocks.evaluation_count", - minimum=1, - ) - evaluated_point_count = _exact_int( - raw.get("evaluated_point_count"), - f"{label}.inner_native_wall_blocks.evaluated_point_count", - minimum=1, - ) - minimum_duration = _positive_number( - raw.get("minimum_native_wall_seconds"), - f"{label}.inner_native_wall_blocks.minimum_native_wall_seconds", - ) - observed_duration = _positive_number( - raw.get("observed_native_wall_seconds"), - f"{label}.inner_native_wall_blocks.observed_native_wall_seconds", - ) - observed_caller_duration = _positive_number( - raw.get("observed_caller_elapsed_seconds"), - f"{label}.inner_native_wall_blocks.observed_caller_elapsed_seconds", - ) - invocation = _mapping( - sample.get("worker_invocation"), - f"{label}.worker_invocation", - ) - process_record = _mapping( - sample.get("worker_process_record"), - f"{label}.worker_process_record", - ) - invocation_wall = _positive_number( - invocation.get("wall_seconds"), - f"{label}.worker_invocation.wall_seconds", - ) - process_wall = _positive_number( - process_record.get("wall_seconds"), - f"{label}.worker_process_record.wall_seconds", - ) - calibration = _mapping( - raw.get("calibration"), - f"{label}.inner_native_wall_blocks.calibration", - ) - runner_samples = _exact_int( - calibration.get("benchmark_runner_sample_count"), - f"{label}.inner_native_wall_blocks.calibration." - "benchmark_runner_sample_count", - minimum=1, - ) - runner_repetitions = _exact_int( - calibration.get("benchmark_runner_repetitions_per_sample"), - f"{label}.inner_native_wall_blocks.calibration." - "benchmark_runner_repetitions_per_sample", - minimum=1, - ) - runner_wall = _positive_number( - calibration.get("benchmark_runner_wall_seconds_per_point"), - f"{label}.inner_native_wall_blocks.calibration." - "benchmark_runner_wall_seconds_per_point", - ) - requested_block_count = _exact_int( - calibration.get("requested_minimum_block_count"), - f"{label}.inner_native_wall_blocks.calibration." - "requested_minimum_block_count", - minimum=MINIMUM_INTERNAL_SAMPLES, - ) - scaled_repetitions = _exact_int( - calibration.get("scaled_repetitions_per_block"), - f"{label}.inner_native_wall_blocks.calibration." - "scaled_repetitions_per_block", - minimum=1, - ) - headroom = _positive_number( - calibration.get("duration_headroom_factor"), - f"{label}.inner_native_wall_blocks.calibration." - "duration_headroom_factor", - ) - calibration_target = target_runtime * headroom - calibration_denominator = requested_block_count * runner_wall * batch_size - if ( - not math.isfinite(calibration_target) - or not math.isfinite(calibration_denominator) - or calibration_denominator <= 0.0 - ): - raise EvidenceError(f"{label} raw native-wall calibration is not finite") - expected_scaled_repetitions = max( - runner_repetitions, - math.ceil(calibration_target / calibration_denominator), - ) - worker_measurement = _mapping( - sample.get("worker_measurement"), - f"{label}.worker_measurement", - ) - if ( - raw.get("kind") != RAW_NATIVE_WALL_BLOCK_KIND - or raw.get("schema_version") != RAW_NATIVE_WALL_BLOCK_SCHEMA - or raw.get("measurement_contract") - != RAW_NATIVE_WALL_MEASUREMENT_CONTRACT - or raw.get("source") != "runtime._benchmark_f64_wall_time" - or raw.get("fixture_points_sha256") != fixture_points_sha256 - or raw.get("minimum_duration_satisfied") is not True - or minimum_duration != target_runtime - or observed_duration < target_runtime - or observed_caller_duration < target_runtime - or observed_caller_duration < observed_duration - or invocation_wall < observed_duration - or invocation_wall < observed_caller_duration - or process_wall < observed_duration - or process_wall < observed_caller_duration - or len(blocks) != block_count - or evaluation_count != block_count * repetitions - or evaluated_point_count != evaluation_count * batch_size - or raw.get("blocks_sha256") != _sha256(list(blocks)) - or calibration.get("kind") != "benchmark-runner-wall-rate-calibration" - or calibration.get("schema_version") != 1 - or calibration.get("benchmark_runner_total_repetitions") - != runner_samples * runner_repetitions - or requested_block_count != max(MINIMUM_INTERNAL_SAMPLES, internal_samples) - or scaled_repetitions != repetitions - or scaled_repetitions != expected_scaled_repetitions - or _exact_int( - calibration.get("preceded_by_benchmark_runner_warmup_runs"), - f"{label}.inner_native_wall_blocks.calibration." - "preceded_by_benchmark_runner_warmup_runs", - minimum=MINIMUM_WARMUPS, - ) - != warmups - or headroom != 1.02 - or worker_measurement.get("batch_size") != batch_size - or worker_measurement.get("sample_count") != block_count - or worker_measurement.get("repetitions_per_sample") != repetitions - or worker_measurement.get("evaluation_count") != evaluation_count - or worker_measurement.get("evaluated_point_count") - != evaluated_point_count - or worker_measurement.get("wall_seconds_per_point") != sample_wall - or worker_measurement.get("inner_native_wall_blocks") != raw - or worker_measurement.get("benchmark_runner_sample_count") - != runner_samples - or worker_measurement.get("benchmark_runner_repetitions_per_sample") - != runner_repetitions - or worker_measurement.get("benchmark_runner_evaluation_count") - != runner_samples * runner_repetitions - or worker_measurement.get("benchmark_runner_evaluated_point_count") - != runner_samples * runner_repetitions * batch_size - or worker_measurement.get("benchmark_runner_wall_seconds_per_point") - != runner_wall - ): - raise EvidenceError( - f"{label} raw native-wall measurement contract is invalid" - ) - - wall_values: list[float] = [] - native_durations: list[float] = [] - caller_durations: list[float] = [] - previous_finished: dt.datetime | None = None - for block_index, raw_block in enumerate(blocks): - block_label = ( - f"{label}.inner_native_wall_blocks.blocks[{block_index}]" - ) - block = _validate_content_address(raw_block, block_label) - native = _positive_number( - block.get("native_wall_seconds"), - f"{block_label}.native_wall_seconds", - ) - wall = _positive_number( - block.get("wall_seconds_per_point"), - f"{block_label}.wall_seconds_per_point", - ) - caller = _positive_number( - block.get("caller_elapsed_seconds"), - f"{block_label}.caller_elapsed_seconds", - ) - if ( - block.get("block_index") != block_index - or block.get("repetitions") != repetitions - or block.get("batch_size") != batch_size - or block.get("evaluation_count") != repetitions - or block.get("evaluated_point_count") != repetitions * batch_size - or caller < native - or not math.isclose( - wall, - native / (repetitions * batch_size), - rel_tol=1.0e-15, - abs_tol=0.0, - ) - ): - raise EvidenceError(f"{block_label} is internally inconsistent") - block_started = _utc_timestamp( - block.get("started_at_utc"), - f"{block_label}.started_at_utc", - ) - block_finished = _utc_timestamp( - block.get("finished_at_utc"), - f"{block_label}.finished_at_utc", - ) - if ( - block_started > block_finished - or ( - previous_finished is not None - and previous_finished > block_started - ) - ): - raise EvidenceError(f"{block_label} timestamps are inverted") - previous_finished = block_finished - wall_values.append(wall) - native_durations.append(native) - caller_durations.append(caller) - - recomputed_median = statistics.median(wall_values) - recomputed_mad = statistics.median( - abs(value - recomputed_median) for value in wall_values - ) - if ( - sum(native_durations) != observed_duration - or sum(caller_durations) != observed_caller_duration - or observed_duration < MINIMUM_TARGET_RUNTIME_SECONDS - or _positive_number( - raw.get("wall_seconds_per_point_median"), - f"{label}.inner_native_wall_blocks.wall_seconds_per_point_median", - ) - != recomputed_median - or _nonnegative_number( - raw.get("wall_seconds_per_point_mad"), - f"{label}.inner_native_wall_blocks.wall_seconds_per_point_mad", - ) - != recomputed_mad - or sample_wall != recomputed_median - or sample.get("internal_sample_count") != block_count - or sample.get("repetitions_per_sample") != repetitions - or sample.get("evaluation_count") != evaluation_count - or sample.get("evaluated_point_count") != evaluated_point_count - ): - raise EvidenceError( - f"{label} raw native-wall duration/statistics are not reproducible" - ) - - -def _extract_cell( - *, - aggregate: Mapping[str, Any], - mode: str, - batch_size: int, - subprocess_samples: int, - internal_samples: int, - warmups: int, - target_runtime: float, - fixture_points_sha256: str, - schedule_by_index: Mapping[int, Mapping[str, Any]], - seen_addresses: set[str], - label: str, -) -> CellEvidence: - if aggregate.get("batch_size") != batch_size: - raise EvidenceError(f"{label}.batch_size does not match its inventory slot") - samples = _sequence( - aggregate.get("subprocess_samples"), f"{label}.subprocess_samples" - ) - if len(samples) != subprocess_samples: - raise EvidenceError( - f"{label} has {len(samples)} subprocess samples, but its campaign " - f"declares {subprocess_samples}" - ) - runtime_values: list[float] = [] - cold_values: list[float] = [] - cold_rss_values: list[float] = [] - profiled_rss_values: list[float] = [] - by_round: dict[int, float] = {} - for sample_index, raw_sample in enumerate(samples): - sample_label = f"{label}.subprocess_samples[{sample_index}]" - sample = _mapping(raw_sample, sample_label) - round_index = _exact_int( - sample.get("round"), f"{sample_label}.round", minimum=0 - ) - if round_index in by_round: - raise EvidenceError(f"{label} duplicates subprocess round {round_index}") - schedule_index = _exact_int( - sample.get("schedule_index"), - f"{sample_label}.schedule_index", - minimum=0, - ) - schedule_entry = schedule_by_index.get(schedule_index) - if schedule_entry is None: - raise EvidenceError( - f"{sample_label} has no matching profile schedule entry" - ) - if ( - schedule_entry.get("mode") != mode - or schedule_entry.get("batch_size") != batch_size - or schedule_entry.get("round") != round_index - ): - raise EvidenceError(f"{sample_label} does not match its schedule slot") - if sample.get("interrupted") is not False: - raise EvidenceError(f"{sample_label} was interrupted") - timing = _mapping( - sample.get("timing_configuration"), - f"{sample_label}.timing_configuration", - ) - sample_warmups = _exact_int( - timing.get("warmup_runs"), - f"{sample_label}.timing_configuration.warmup_runs", - minimum=MINIMUM_WARMUPS, - ) - sample_target = _positive_number( - timing.get("target_runtime_seconds"), - f"{sample_label}.timing_configuration.target_runtime_seconds", - ) - sample_internal_minimum = _exact_int( - timing.get("minimum_internal_samples"), - f"{sample_label}.timing_configuration.minimum_internal_samples", - minimum=MINIMUM_INTERNAL_SAMPLES, - ) - if ( - sample_warmups != warmups - or sample_target != target_runtime - or sample_internal_minimum != internal_samples - ): - raise EvidenceError(f"{sample_label} timing configuration drifted") - _exact_int( - sample.get("internal_sample_count"), - f"{sample_label}.internal_sample_count", - minimum=MINIMUM_INTERNAL_SAMPLES, - ) - sources = _mapping( - sample.get("timing_sources"), f"{sample_label}.timing_sources" - ) - if sources.get("wall") != "runtime_core_repeated_wall_time": - raise EvidenceError( - f"{sample_label} is not an unprofiled native-wall sample" - ) - - runtime = _positive_number( - sample.get("wall_seconds_per_point"), - f"{sample_label}.wall_seconds_per_point", - ) - _validate_raw_native_wall_measurement( - sample, - batch_size=batch_size, - internal_samples=internal_samples, - warmups=warmups, - target_runtime=target_runtime, - sample_wall=runtime, - fixture_points_sha256=fixture_points_sha256, - label=sample_label, - ) - if "cold_load_seconds" not in sample: - raise EvidenceError( - f"{sample_label} lacks cold_load_seconds. The capture predates " - "the resource-evidence contract; re-run the baseline/candidate " - "recurrence_z6g campaign with the current harness before comparing." - ) - cold = _positive_number( - sample.get("cold_load_seconds"), - f"{sample_label}.cold_load_seconds", - ) - if ( - "peak_rss_after_cold_load" not in sample - or "peak_rss_after_profile" not in sample - ): - raise EvidenceError( - f"{sample_label} lacks cold-load/profile RSS evidence. Re-run " - "the baseline/candidate recurrence_z6g campaign with the current " - "harness before comparing." - ) - cold_rss = _rss_observation( - sample.get("peak_rss_after_cold_load"), - f"{sample_label}.peak_rss_after_cold_load", - ) - profiled_rss = _rss_observation( - sample.get("peak_rss_after_profile"), - f"{sample_label}.peak_rss_after_profile", - ) - _validate_sample_address(sample, schedule_entry, sample_label, seen_addresses) - runtime_values.append(runtime) - cold_values.append(cold) - cold_rss_values.append(cold_rss) - profiled_rss_values.append(profiled_rss) - by_round[round_index] = runtime - expected_rounds = set(range(subprocess_samples)) - if set(by_round) != expected_rounds: - raise EvidenceError(f"{label} does not retain exactly one sample per round") - - runtime_distribution = _distribution(runtime_values, f"{label}.runtime") - cold_distribution = _distribution(cold_values, f"{label}.cold_load") - cold_rss_distribution = _distribution(cold_rss_values, f"{label}.cold_load_rss") - profiled_rss_distribution = _distribution( - profiled_rss_values, - f"{label}.profiled_rss", - ) - if aggregate.get("statistics_contract") != "subprocess-median-and-raw-mad-v1": - raise EvidenceError(f"{label} has an unsupported statistics contract") - if ( - aggregate.get("resource_statistics_contract") - != "subprocess-median-and-raw-mad-v1" - ): - raise EvidenceError(f"{label} has an unsupported resource statistics contract") - if aggregate.get("interrupted") is not False: - raise EvidenceError(f"{label} aggregate is interrupted") - if ( - aggregate.get("sample_count") != subprocess_samples - or aggregate.get("subprocess_sample_count") != subprocess_samples - ): - raise EvidenceError(f"{label} aggregate sample count is inconsistent") - _recorded_statistic( - aggregate.get("wall_seconds_per_point_median"), - runtime_distribution.median, - f"{label}.wall_seconds_per_point_median", - ) - _recorded_statistic( - aggregate.get("wall_seconds_per_point_mad"), - runtime_distribution.raw_mad, - f"{label}.wall_seconds_per_point_mad", - ) - _recorded_statistic( - aggregate.get("cold_load_seconds_median"), - cold_distribution.median, - f"{label}.cold_load_seconds_median", - ) - _recorded_statistic( - aggregate.get("cold_load_seconds_mad"), - cold_distribution.raw_mad, - f"{label}.cold_load_seconds_mad", - ) - _recorded_statistic( - aggregate.get("cold_load_peak_rss_bytes_median"), - cold_rss_distribution.median, - f"{label}.cold_load_peak_rss_bytes_median", - ) - _recorded_statistic( - aggregate.get("profiled_peak_rss_bytes_median"), - profiled_rss_distribution.median, - f"{label}.profiled_peak_rss_bytes_median", - ) - return CellEvidence( - runtime=runtime_distribution, - cold_load=cold_distribution, - cold_load_rss=cold_rss_distribution, - profiled_rss=profiled_rss_distribution, - by_round=by_round, - ) - - -def _validate_paired_profile_coordination( - payload: Mapping[str, Any], - *, - role: str, - layout: str, - revision: str, - schedule_by_index: Mapping[int, Mapping[str, Any]], -) -> Mapping[str, object]: - label = f"{role}/{layout}.paired_profile_coordination" - coordination = _mapping(payload.get("paired_profile_coordination"), label) - if ( - coordination.get("kind") != "pyamplicol-paired-profile-coordination" - or coordination.get("schema_version") != 1 - or coordination.get("role") != role - or coordination.get("layout") != layout - ): - raise EvidenceError(f"{label} has an unsupported identity") - session_id = _string(coordination.get("session_id"), f"{label}.session_id") - ready = _validate_content_address( - coordination.get("ready_record"), - f"{label}.ready_record", - ) - plan = _sequence( - ready.get("profile_schedule_plan"), - f"{label}.ready_record.profile_schedule_plan", - ) - expected_plan = [ - { - field: schedule_by_index[index].get(field) - for field in ("schedule_index", "round", "mode", "batch_size") - } - for index in sorted(schedule_by_index) - ] - if ( - ready.get("kind") != "pyamplicol-paired-profile-ready" - or ready.get("schema_version") != 1 - or ready.get("session_id") != session_id - or ready.get("role") != role - or ready.get("layout") != layout - or ready.get("source_revision") != revision - or list(plan) != expected_plan - or ready.get("profile_schedule_plan_sha256") != _sha256(expected_plan) - ): - raise EvidenceError(f"{label} ready record does not bind the capture") - ready_at = _utc_timestamp( - ready.get("ready_at_utc"), - f"{label}.ready_record.ready_at_utc", - ) - raw_completions = _sequence( - coordination.get("completion_records"), - f"{label}.completion_records", - ) - if len(raw_completions) != len(schedule_by_index): - raise EvidenceError(f"{label} completion inventory is incomplete") - slots: dict[int, dict[str, object]] = {} - for index, entry in schedule_by_index.items(): - token = _validate_content_address( - entry.get("paired_profile_token"), - f"{label}.slots[{index}].token", - ) - completion = _validate_content_address( - entry.get("paired_profile_completion"), - f"{label}.slots[{index}].completion", - ) - expected = { - "session_id": session_id, - "role": role, - "layout": layout, - "schedule_index": index, - "round": entry.get("round"), - "mode": entry.get("mode"), - "batch_size": entry.get("batch_size"), - } - if ( - token.get("kind") != "pyamplicol-paired-profile-token" - or token.get("schema_version") != 1 - or completion.get("kind") != "pyamplicol-paired-profile-completion" - or completion.get("schema_version") != 1 - or any(token.get(field) != value for field, value in expected.items()) - or any(completion.get(field) != value for field, value in expected.items()) - or completion.get("token_sha256") != token.get("content_sha256") - ): - raise EvidenceError(f"{label} slot {index} changed paired coordinates") - ( - invocation, - _, - invocation_sha256, - process_sha256, - result_sha256, - ) = _validated_schedule_worker_records( - entry, - f"{label}.slots[{index}]", - ) - if ( - completion.get("worker_invocation_sha256") != invocation_sha256 - or completion.get("worker_result_record_sha256") != result_sha256 - or completion.get("worker_started_at_utc") - != invocation.get("started_at_utc") - or completion.get("worker_finished_at_utc") - != invocation.get("finished_at_utc") - ): - raise EvidenceError( - f"{label} slot {index} completion is not bound to its worker" - ) - issued = _utc_timestamp( - token.get("issued_at_utc"), - f"{label}.slots[{index}].token.issued_at_utc", - ) - started = _utc_timestamp( - completion.get("worker_started_at_utc"), - f"{label}.slots[{index}].completion.worker_started_at_utc", - ) - finished = _utc_timestamp( - completion.get("worker_finished_at_utc"), - f"{label}.slots[{index}].completion.worker_finished_at_utc", - ) - recorded = _utc_timestamp( - completion.get("recorded_at_utc"), - f"{label}.slots[{index}].completion.recorded_at_utc", - ) - if not ready_at <= issued <= started <= finished <= recorded: - raise EvidenceError(f"{label} slot {index} timestamps are inverted") - slots[index] = { - "token": dict(token), - "completion": dict(completion), - "issued": issued, - "started": started, - "finished": finished, - "recorded": recorded, - "worker_invocation_sha256": invocation_sha256, - "worker_process_record_sha256": process_sha256, - "worker_result_record_sha256": result_sha256, - } - if list(raw_completions) != [slots[index]["completion"] for index in sorted(slots)]: - raise EvidenceError(f"{label} completion summary differs from its schedule") - return { - "session_id": session_id, - "role": role, - "layout": layout, - "slots": slots, - "ready_at": ready_at, - "ready_record": dict(ready), - } - - -def _validate_capture( - payload: Mapping[str, Any], - input_identity: Mapping[str, object], - *, - role: str, - expected_layout: str, -) -> CaptureEvidence: - label = f"{role}/{expected_layout}" - if payload.get("kind") != CAPTURE_KIND: - raise EvidenceError(f"{label} has the wrong capture kind") - schema = _exact_int(payload.get("schema_version"), f"{label}.schema_version") - if schema < MINIMUM_CAPTURE_SCHEMA: - raise EvidenceError( - f"{label} schema {schema} predates the required raw-evidence contract" - ) - logical_process = _logical_process(payload.get("process"), f"{label}.process") - expected_workload = ( - "single-runtime-selected-flow/helicity-sum" - if expected_layout == "topology-replay" - else "all-flows/runtime-selected-single-helicity" - ) - if payload.get("workload") != expected_workload: - raise EvidenceError(f"{label} has the wrong workload") - - configuration = _mapping(payload.get("configuration"), f"{label}.configuration") - if configuration.get("lc_flow_layout") != expected_layout: - raise EvidenceError(f"{label} is in the wrong layout slot") - if configuration.get("generation_only") is not False: - raise EvidenceError(f"{label} is a generation-only capture") - configured_modes = list( - _sequence(configuration.get("modes"), f"{label}.configuration.modes") - ) - allowed_modes = {*CAPTURE_MODES, *DIAGNOSTIC_MODES} - if set(configured_modes) != allowed_modes or len(configured_modes) != len( - set(configured_modes) - ): - raise EvidenceError( - f"{label} must contain compiled, recurrence, and eager exactly once" - ) - configured_batches = tuple( - _exact_int(value, f"{label}.configuration.batch_sizes") - for value in _sequence( - configuration.get("batch_sizes"), - f"{label}.configuration.batch_sizes", - ) - ) - if len(configured_batches) != len(BATCH_SIZES) or set(configured_batches) != set( - BATCH_SIZES - ): - raise EvidenceError(f"{label} must contain exactly batches {list(BATCH_SIZES)}") - subprocess_samples = _exact_int( - configuration.get("subprocess_samples"), - f"{label}.configuration.subprocess_samples", - minimum=MINIMUM_SUBPROCESS_SAMPLES, - ) - if subprocess_samples != MINIMUM_SUBPROCESS_SAMPLES: - raise EvidenceError( - f"{label} must retain exactly {MINIMUM_SUBPROCESS_SAMPLES} " - "independent subprocess pairs" - ) - internal_samples = _exact_int( - configuration.get("minimum_samples"), - f"{label}.configuration.minimum_samples", - minimum=MINIMUM_INTERNAL_SAMPLES, - ) - warmups = _exact_int( - configuration.get("warmup_runs"), - f"{label}.configuration.warmup_runs", - minimum=MINIMUM_WARMUPS, - ) - if warmups != MINIMUM_WARMUPS: - raise EvidenceError( - f"{label} must use exactly {MINIMUM_WARMUPS} warmup runs" - ) - target_runtime = _positive_number( - configuration.get("target_runtime_seconds"), - f"{label}.configuration.target_runtime_seconds", - ) - if target_runtime < MINIMUM_TARGET_RUNTIME_SECONDS: - raise EvidenceError( - f"{label} target runtime is below {MINIMUM_TARGET_RUNTIME_SECONDS:g}s" - ) - if configuration.get("jit_optimization_level") != 3: - raise EvidenceError(f"{label} compiled JIT is not configured for O3") - acceptance = _validate_capture_acceptance( - payload, - configuration, - expected_layout=expected_layout, - subprocess_samples=subprocess_samples, - internal_samples=internal_samples, - warmups=warmups, - configured_modes=configured_modes, - ) - selected_union_projection = _capture_semantic_projection( - acceptance, - configuration=configuration, - logical_process=logical_process, - layout=expected_layout, - label=label, - ) - - source = _mapping(payload.get("source"), f"{label}.source") - revision = _string(source.get("revision"), f"{label}.source.revision") - if len(revision) != _REVISION_LENGTH: - raise EvidenceError(f"{label}.source.revision is not a full Git revision") - try: - int(revision, 16) - except ValueError as error: - raise EvidenceError(f"{label}.source.revision is not a Git revision") from error - if ( - source.get("dirty") is not False - or source.get("untracked_files_checked") is not True - ): - raise EvidenceError(f"{label} source checkout is not clean and authenticated") - - provenance = _mapping(payload.get("provenance"), f"{label}.provenance") - host = dict(_mapping(provenance.get("host"), f"{label}.provenance.host")) - runtime = _mapping(payload.get("runtime_provenance"), f"{label}.runtime_provenance") - interpreter = _mapping( - runtime.get("interpreter"), f"{label}.runtime_provenance.interpreter" - ) - native_extension = _mapping( - runtime.get("native_extension"), - f"{label}.runtime_provenance.native_extension", - ) - build_info = _mapping( - _mapping( - runtime.get("active_build_info"), - f"{label}.runtime_provenance.active_build_info", - ).get("payload"), - f"{label}.runtime_provenance.active_build_info.payload", - ) - if build_info.get("source_revision") != revision: - raise EvidenceError( - f"{label} installed build does not match its source revision" - ) - build_identity = { - "source_revision": revision, - "native_extension_sha256": _valid_sha256( - native_extension.get("sha256"), - f"{label}.runtime_provenance.native_extension.sha256", - ), - "native_build_inputs_sha256": _valid_sha256( - native_extension.get("build_inputs_sha256"), - f"{label}.runtime_provenance.native_extension.build_inputs_sha256", - ), - "package_version": _string( - native_extension.get("package_version"), - f"{label}.runtime_provenance.native_extension.package_version", - ), - "build_info_version": _string( - build_info.get("version"), - f"{label}.runtime_provenance.active_build_info.payload.version", - ), - } - interpreter_identity = { - "implementation": _string( - interpreter.get("implementation"), - f"{label}.runtime_provenance.interpreter.implementation", - ), - "python_version": _string( - interpreter.get("python_version"), - f"{label}.runtime_provenance.interpreter.python_version", - ), - "executable_sha256": _valid_sha256( - interpreter.get("sha256"), - f"{label}.runtime_provenance.interpreter.sha256", - ), - } - interpreter_path = _string( - interpreter.get("path"), - f"{label}.runtime_provenance.interpreter.path", - ) - interpreter_resolved_path = _string( - interpreter.get("resolved_path"), - f"{label}.runtime_provenance.interpreter.resolved_path", - ) - model_identities = _mapping( - configuration.get("model_identities"), - f"{label}.configuration.model_identities", - ) - if set(model_identities) != set(configured_modes): - raise EvidenceError( - f"{label} prepared-model identity inventory is incomplete" - ) - prepared_paths: set[str] = set() - prepared_hashes: set[str] = set() - for mode in configured_modes: - model_identity = _mapping( - model_identities.get(mode), - f"{label}.configuration.model_identities.{mode}", - ) - if model_identity.get("kind") != "explicit-prepared-model": - raise EvidenceError( - f"{label} paired campaign did not use an explicit prepared model" - ) - model_file = _mapping( - model_identity.get("file"), - f"{label}.configuration.model_identities.{mode}.file", - ) - prepared_paths.add( - _string( - model_file.get("resolved_path"), - f"{label}.configuration.model_identities.{mode}.file.resolved_path", - ) - ) - prepared_hashes.add( - _valid_sha256( - model_file.get("sha256"), - f"{label}.configuration.model_identities.{mode}.file.sha256", - ) - ) - if len(prepared_paths) != 1 or len(prepared_hashes) != 1: - raise EvidenceError(f"{label} modes use different prepared model packs") - prepared_model_path = prepared_paths.pop() - prepared_model_sha256 = prepared_hashes.pop() - - schedule = _mapping(payload.get("profile_schedule"), f"{label}.profile_schedule") - if ( - schedule.get("kind") != "pyamplicol-interleaved-subprocess-profile-schedule" - or schedule.get("schema_version") != 2 - or schedule.get("algorithm") - != "round-major-cyclic-mode-and-batch-interleave-v1" - or schedule.get("sample_unit") != "independent-profile-worker-subprocess" - or schedule.get("subprocess_samples_per_cell") != subprocess_samples - or set( - _sequence( - schedule.get("modes"), - f"{label}.profile_schedule.modes", - ) - ) - != set(configured_modes) - or set( - _sequence( - schedule.get("batch_sizes"), - f"{label}.profile_schedule.batch_sizes", - ) - ) - != set(BATCH_SIZES) - ): - raise EvidenceError(f"{label} profile schedule identity is inconsistent") - entries = _sequence(schedule.get("entries"), f"{label}.profile_schedule.entries") - expected_entry_count = len(configured_modes) * len(BATCH_SIZES) * subprocess_samples - if len(entries) != expected_entry_count: - raise EvidenceError( - f"{label} profile schedule has {len(entries)} entries; " - f"{expected_entry_count} are required" - ) - schedule_by_index: dict[int, Mapping[str, Any]] = {} - for position, raw_entry in enumerate(entries): - entry = _mapping(raw_entry, f"{label}.profile_schedule.entries[{position}]") - index = _exact_int( - entry.get("schedule_index"), - f"{label}.profile_schedule.entries[{position}].schedule_index", - minimum=0, - ) - if index != position or index in schedule_by_index: - raise EvidenceError(f"{label} profile schedule index is not canonical") - schedule_by_index[index] = entry - paired_profile_coordination = _validate_paired_profile_coordination( - payload, - role=role, - layout=expected_layout, - revision=revision, - schedule_by_index=schedule_by_index, - ) - - generations = _mapping(payload.get("generation"), f"{label}.generation") - raw_profiles = _mapping(payload.get("profiles"), f"{label}.profiles") - if set(generations) != set(configured_modes) or set(raw_profiles) != set( - configured_modes - ): - raise EvidenceError( - f"{label} three-lane generation/profile inventory is incomplete" - ) - generation_evidence: dict[str, GenerationEvidence] = {} - workload_identities: dict[str, Mapping[str, object]] = {} - cells: dict[tuple[str, int], CellEvidence] = {} - seen_addresses: set[str] = set() - eager_acceptance = _mapping( - acceptance.get("eager_diagnostic"), - f"{label}.capture_acceptance.eager_diagnostic", - ) - eager_admissible = bool( - "eager" in configured_modes - and eager_acceptance.get("complete") is True - and eager_acceptance.get("passes") is True - ) - parsed_modes = (*CAPTURE_MODES, "eager") if eager_admissible else CAPTURE_MODES - for mode in parsed_modes: - generation = _mapping(generations.get(mode), f"{label}.generation.{mode}") - if generation.get("mode") != mode: - raise EvidenceError(f"{label}.generation.{mode} has the wrong mode") - if generation.get("generation_reused") is not False: - raise EvidenceError( - f"{label}.generation.{mode} was reused; a fresh generation " - "time is required" - ) - generation_wall = _positive_number( - generation.get("generation_wall_seconds"), - f"{label}.generation.{mode}.generation_wall_seconds", - ) - stats = _mapping( - generation.get("artifact_stats"), - f"{label}.generation.{mode}.artifact_stats", - ) - _exact_int( - stats.get("file_count"), - f"{label}.generation.{mode}.artifact_stats.file_count", - minimum=1, - ) - payload_size = _exact_int( - stats.get("size_bytes"), - f"{label}.generation.{mode}.artifact_stats.size_bytes", - minimum=1, - ) - generation_peak = int( - _rss_observation( - generation.get("peak_rss"), - f"{label}.generation.{mode}.peak_rss", - ) - ) - generation_evidence[mode] = GenerationEvidence( - wall_seconds=generation_wall, - payload_size_bytes=payload_size, - peak_rss_bytes=generation_peak, - ) - - profile = _mapping(raw_profiles.get(mode), f"{label}.profiles.{mode}") - workload_identities[mode] = _workload_identity( - profile=profile, - generation=generation, - mode=mode, - layout=expected_layout, - logical_process=logical_process, - expected_workload=expected_workload, - selected_union_projection=selected_union_projection, - label=f"{label}.profiles.{mode}", - ) - validation_fixture = _mapping( - workload_identities[mode].get("validation_fixture"), - f"{label}.profiles.{mode}.validation_fixture", - ) - fixture_points_sha256 = _valid_sha256( - validation_fixture.get("points_sha256"), - f"{label}.profiles.{mode}.validation_fixture.points_sha256", - ) - aggregates = _sequence( - profile.get("profiles"), - f"{label}.profiles.{mode}.profiles", - ) - by_batch: dict[int, Mapping[str, Any]] = {} - for aggregate_index, raw_aggregate in enumerate(aggregates): - aggregate = _mapping( - raw_aggregate, - f"{label}.profiles.{mode}.profiles[{aggregate_index}]", - ) - batch = _exact_int( - aggregate.get("batch_size"), - f"{label}.profiles.{mode}.profiles[{aggregate_index}].batch_size", - minimum=1, - ) - if batch in by_batch: - raise EvidenceError(f"{label}.profiles.{mode} duplicates batch {batch}") - by_batch[batch] = aggregate - if set(by_batch) != set(BATCH_SIZES): - raise EvidenceError( - f"{label}.profiles.{mode} does not contain exactly {list(BATCH_SIZES)}" - ) - for batch_size in BATCH_SIZES: - cells[(mode, batch_size)] = _extract_cell( - aggregate=by_batch[batch_size], - mode=mode, - batch_size=batch_size, - subprocess_samples=subprocess_samples, - internal_samples=internal_samples, - warmups=warmups, - target_runtime=target_runtime, - fixture_points_sha256=fixture_points_sha256, - schedule_by_index=schedule_by_index, - seen_addresses=seen_addresses, - label=f"{label}.profiles.{mode}.batch[{batch_size}]", - ) - - # Each round must retain exactly one independently scheduled subprocess for - # every lane and batch. Compiled/recurrence ratios are paired by this - # shared round identity, and eager is independently evaluated below. - for batch_size in BATCH_SIZES: - for round_index in range(subprocess_samples): - pair = [ - entry - for entry in schedule_by_index.values() - if entry.get("batch_size") == batch_size - and entry.get("round") == round_index - and entry.get("mode") in configured_modes - ] - if len(pair) != len(configured_modes) or { - entry.get("mode") for entry in pair - } != set(configured_modes): - raise EvidenceError( - f"{label} batch {batch_size} round {round_index} does not " - "contain one subprocess for every capture lane" - ) - - campaign_identity = { - "logical_process": logical_process, - "layout": expected_layout, - "workload": expected_workload, - "batch_sizes": list(BATCH_SIZES), - "subprocess_samples": subprocess_samples, - "minimum_internal_samples": configuration.get("minimum_samples"), - "warmup_runs": warmups, - "target_runtime_seconds": target_runtime, - "color_flow_request": configuration.get("color_flow_request"), - "helicity_request": configuration.get("helicity_request"), - "validation_seed": configuration.get("validation_seed"), - "point_tile_size": configuration.get("point_tile_size"), - "interpreter": interpreter_identity, - "configured_modes": list(configured_modes), - } - addressed_input_identity = dict(input_identity) - addressed_input_identity["capture_acceptance_sha256"] = _sha256(acceptance) - return CaptureEvidence( - input_identity=addressed_input_identity, - layout=expected_layout, - logical_process=logical_process, - source_revision=revision, - build_identity=build_identity, - host_identity=host, - campaign_identity=campaign_identity, - workload_identities=workload_identities, - cells=cells, - generation=generation_evidence, - configured_modes=tuple(configured_modes), - paired_profile_coordination=paired_profile_coordination, - eager_diagnostic=dict(eager_acceptance), - interpreter_path=interpreter_path, - interpreter_resolved_path=interpreter_resolved_path, - prepared_model_path=prepared_model_path, - prepared_model_sha256=prepared_model_sha256, - ) - - -def _geometric_mean(values: Sequence[float], label: str) -> float: - checked = [_positive_number(value, label) for value in values] - if not checked: - raise EvidenceError(f"{label} is empty") - return math.exp(math.fsum(math.log(value) for value in checked) / len(checked)) - - -def _runtime_cell_comparison( - *, - layout: str, - mode: str, - batch_size: int, - baseline: CellEvidence, - candidate: CellEvidence, -) -> dict[str, object]: - relative_limit = RUNTIME_RELATIVE_LIMIT * baseline.runtime.median - noise_limit = ( - baseline.runtime.median - + RUNTIME_NOISE_MAD_MULTIPLIER * baseline.runtime.raw_mad - ) - passes_relative = candidate.runtime.median <= relative_limit - passes_noise = candidate.runtime.median <= noise_limit - gain_at_least_ten_percent = ( - candidate.runtime.median - <= (1.0 - RESOURCE_EXCEPTION_GAIN) * baseline.runtime.median - ) - gain_beyond_noise = ( - candidate.runtime.median - <= baseline.runtime.median - - RUNTIME_NOISE_MAD_MULTIPLIER * baseline.runtime.raw_mad - ) - return { - "layout": layout, - "mode": mode, - "batch_size": batch_size, - "baseline": baseline.runtime.as_dict(), - "candidate": candidate.runtime.as_dict(), - "candidate_to_baseline_ratio": ( - candidate.runtime.median / baseline.runtime.median - ), - "relative_limit_seconds_per_point": relative_limit, - "noise_limit_seconds_per_point": noise_limit, - "passes_relative_limit": passes_relative, - "passes_noise_limit": passes_noise, - "passes": passes_relative and passes_noise, - "resource_exception_runtime_gain": { - "gain_at_least_10_percent": gain_at_least_ten_percent, - "gain_beyond_3_baseline_raw_mad": gain_beyond_noise, - "passes": gain_at_least_ten_percent and gain_beyond_noise, - }, - } - - -def _paired_ratio( - *, - layout: str, - batch_size: int, - capture: CaptureEvidence, -) -> dict[str, object]: - compiled = capture.cells[("compiled", batch_size)].by_round - recurrence = capture.cells[("recurrence", batch_size)].by_round - if set(compiled) != set(recurrence): - raise EvidenceError( - f"{layout} batch {batch_size} compiled/recurrence rounds do not match" - ) - rounds = sorted(compiled) - ratios = [compiled[round_index] / recurrence[round_index] for round_index in rounds] - distribution = _distribution(ratios, f"{layout}/{batch_size} paired ratio") - upper_bound = ( - distribution.median + RUNTIME_NOISE_MAD_MULTIPLIER * distribution.raw_mad - ) - return { - "rounds": rounds, - "compiled_to_recurrence_ratio": distribution.as_dict(), - "median_plus_3_raw_mad": upper_bound, - } - - -def _resource_comparison( - *, - layout: str, - mode: str, - metric: str, - baseline: Distribution, - candidate: Distribution, - runtime_gain: Mapping[str, object], - batch_size: int | None = None, -) -> dict[str, object]: - ratio = candidate.median / baseline.median - within_growth_limit = ratio <= RESOURCE_GROWTH_LIMIT - exception = runtime_gain.get("passes") is True - result: dict[str, object] = { - "layout": layout, - "mode": mode, - "metric": metric, - "baseline": baseline.as_dict(), - "candidate": candidate.as_dict(), - "candidate_to_baseline_ratio": ratio, - "within_3_percent_growth_limit": within_growth_limit, - "runtime_gain_exception": dict(runtime_gain), - "passes": within_growth_limit or exception, - } - if batch_size is not None: - result["batch_size"] = batch_size - return result - - -def _single_resource_comparison( - *, - layout: str, - mode: str, - metric: str, - baseline: float, - candidate: float, - runtime_gain: Mapping[str, object], -) -> dict[str, object]: - baseline_distribution = Distribution((baseline,), baseline, 0.0) - candidate_distribution = Distribution((candidate,), candidate, 0.0) - return _resource_comparison( - layout=layout, - mode=mode, - metric=metric, - baseline=baseline_distribution, - candidate=candidate_distribution, - runtime_gain=runtime_gain, - ) - - -def _assert_role_consistency( - captures: Mapping[str, CaptureEvidence], - *, - role: str, -) -> None: - topology = captures["topology-replay"] - union = captures["all-flow-union"] - if topology.source_revision != union.source_revision: - raise EvidenceError(f"{role} captures use different source revisions") - if topology.build_identity != union.build_identity: - raise EvidenceError(f"{role} captures use different native builds") - if topology.host_identity != union.host_identity: - raise EvidenceError(f"{role} captures were not measured on the same host") - if topology.logical_process != union.logical_process: - raise EvidenceError(f"{role} captures use different processes") - if topology.paired_profile_coordination.get( - "session_id" - ) != union.paired_profile_coordination.get("session_id"): - raise EvidenceError(f"{role} captures use different paired sessions") - topology_campaign = dict(topology.campaign_identity) - union_campaign = dict(union.campaign_identity) - for field in ("layout", "workload", "color_flow_request", "helicity_request"): - topology_campaign.pop(field, None) - union_campaign.pop(field, None) - if topology_campaign != union_campaign: - raise EvidenceError(f"{role} capture campaign configuration drifted by layout") - - -def _assert_paired_role_order( - baseline: CaptureEvidence, - candidate: CaptureEvidence, - *, - layout: str, -) -> None: - baseline_coordination = baseline.paired_profile_coordination - candidate_coordination = candidate.paired_profile_coordination - if baseline_coordination.get("session_id") != candidate_coordination.get( - "session_id" - ): - raise EvidenceError(f"{layout} roles use different paired sessions") - baseline_slots = _mapping( - baseline_coordination.get("slots"), - f"{layout}.baseline paired slots", - ) - candidate_slots = _mapping( - candidate_coordination.get("slots"), - f"{layout}.candidate paired slots", - ) - if set(baseline_slots) != set(candidate_slots): - raise EvidenceError(f"{layout} paired role slots differ") - previous_finished: dt.datetime | None = None - for index in sorted(baseline_slots): - baseline_slot = _mapping( - baseline_slots[index], f"{layout}.baseline paired slot {index}" - ) - candidate_slot = _mapping( - candidate_slots[index], f"{layout}.candidate paired slot {index}" - ) - baseline_token = _mapping( - baseline_slot.get("token"), f"{layout}.baseline token {index}" - ) - candidate_token = _mapping( - candidate_slot.get("token"), f"{layout}.candidate token {index}" - ) - coordinates = ("schedule_index", "round", "mode", "batch_size", "pair_index") - if ( - any( - baseline_token.get(field) != candidate_token.get(field) - for field in coordinates - ) - or baseline_token.get("pair_index") != index - ): - raise EvidenceError(f"{layout} paired slot {index} coordinates differ") - round_index = _exact_int( - baseline_token.get("round"), - f"{layout}.paired slot {index}.round", - minimum=0, - ) - expected_order = ( - ("baseline", "candidate") - if round_index % 2 == 0 - else ("candidate", "baseline") - ) - by_role = { - "baseline": baseline_slot, - "candidate": candidate_slot, - } - order_coordinates = tuple( - ( - _exact_int( - _mapping( - by_role[role].get("token"), - f"{layout}.{role} token {index}", - ).get("order_in_pair"), - f"{layout}.{role} token {index}.order_in_pair", - minimum=0, - ), - role, - ) - for role in ("baseline", "candidate") - ) - if {order for order, _ in order_coordinates} != {0, 1}: - raise EvidenceError( - f"{layout} paired slot {index} has invalid role positions" - ) - observed_order = tuple(role for _, role in sorted(order_coordinates)) - if observed_order != expected_order: - raise EvidenceError( - f"{layout} paired slot {index} does not alternate role order" - ) - for identity in ( - "worker_invocation_sha256", - "worker_process_record_sha256", - "worker_result_record_sha256", - ): - if baseline_slot.get(identity) == candidate_slot.get(identity): - raise EvidenceError( - f"{layout} paired slot {index} reuses {identity} " - "identity across roles" - ) - first = by_role[expected_order[0]] - second = by_role[expected_order[1]] - first_issued = first.get("issued") - first_started = first.get("started") - first_finished = first.get("finished") - second_issued = second.get("issued") - second_started = second.get("started") - second_finished = second.get("finished") - if not all( - isinstance(value, dt.datetime) - for value in ( - first_issued, - first_started, - first_finished, - second_issued, - second_started, - second_finished, - ) - ): - raise EvidenceError(f"{layout} paired slot {index} lacks timestamps") - assert isinstance(first_issued, dt.datetime) - assert isinstance(first_started, dt.datetime) - assert isinstance(first_finished, dt.datetime) - assert isinstance(second_issued, dt.datetime) - assert isinstance(second_started, dt.datetime) - assert isinstance(second_finished, dt.datetime) - if first_finished > second_issued: - raise EvidenceError( - f"{layout} paired slot {index} admitted the second role " - "before the first worker finished" - ) - if first_finished > second_started: - raise EvidenceError(f"{layout} paired slot {index} workers overlap") - if previous_finished is not None and previous_finished > first_issued: - raise EvidenceError(f"{layout} paired slots overlap or reorder") - previous_finished = second_finished - - -def _assert_cross_layout_sequence( - baseline: Mapping[str, CaptureEvidence], - candidate: Mapping[str, CaptureEvidence], -) -> None: - topology_finished: list[dt.datetime] = [] - for role, captures in (("baseline", baseline), ("candidate", candidate)): - slots = _mapping( - captures["topology-replay"].paired_profile_coordination.get("slots"), - f"{role} topology paired slots", - ) - for index, raw_slot in slots.items(): - finished = _mapping( - raw_slot, - f"{role} topology paired slot {index}", - ).get("finished") - if not isinstance(finished, dt.datetime): - raise EvidenceError( - f"{role} topology paired slot {index} lacks a finish timestamp" - ) - topology_finished.append(finished) - union_ready = [ - captures["all-flow-union"].paired_profile_coordination.get("ready_at") - for captures in (baseline, candidate) - ] - if not topology_finished or not all( - isinstance(value, dt.datetime) for value in union_ready - ): - raise EvidenceError("paired campaign lacks cross-layout timestamps") - if max(topology_finished) > min(union_ready): - raise EvidenceError( - "paired campaign layouts overlap or reorder; all-flow-union became " - "ready before topology-replay completed" - ) - - -def _assert_global_worker_identity_separation( - baseline: Mapping[str, CaptureEvidence], - candidate: Mapping[str, CaptureEvidence], -) -> None: - for identity in ( - "worker_invocation_sha256", - "worker_process_record_sha256", - "worker_result_record_sha256", - ): - seen: dict[str, tuple[str, str, object]] = {} - for role, captures in (("baseline", baseline), ("candidate", candidate)): - for layout in LAYOUTS: - slots = _mapping( - captures[layout].paired_profile_coordination.get("slots"), - f"{role}/{layout} paired slots", - ) - for index, raw_slot in slots.items(): - slot = _mapping( - raw_slot, - f"{role}/{layout} paired slot {index}", - ) - digest = _valid_sha256( - slot.get(identity), - f"{role}/{layout} paired slot {index}.{identity}", - ) - previous = seen.get(digest) - if previous is not None: - raise EvidenceError( - f"{role}/{layout} paired slot {index} reuses {identity} " - f"identity from {previous[0]}/{previous[1]} " - f"slot {previous[2]}" - ) - seen[digest] = (role, layout, index) - - -def _assert_externally_pinned_role_inputs( - baseline: Mapping[str, CaptureEvidence], - candidate: Mapping[str, CaptureEvidence], - *, - expected_candidate_source_revision: str, - expected_baseline_native_build_inputs_sha256: str, - expected_candidate_native_build_inputs_sha256: str, - expected_baseline_prepared_model_sha256: str, - expected_candidate_prepared_model_sha256: str, -) -> dict[str, object]: - expected_candidate_source_revision = _valid_revision( - expected_candidate_source_revision, - "expected candidate source revision", - ) - expected = { - "baseline": { - "native_build_inputs_sha256": _valid_sha256( - expected_baseline_native_build_inputs_sha256, - "expected baseline native-build-input digest", - ), - "prepared_model_sha256": _valid_sha256( - expected_baseline_prepared_model_sha256, - "expected baseline prepared-model digest", - ), - }, - "candidate": { - "native_build_inputs_sha256": _valid_sha256( - expected_candidate_native_build_inputs_sha256, - "expected candidate native-build-input digest", - ), - "prepared_model_sha256": _valid_sha256( - expected_candidate_prepared_model_sha256, - "expected candidate prepared-model digest", - ), - }, - } - if expected_candidate_source_revision == BASELINE_REVISION: - raise EvidenceError( - "expected candidate source revision still identifies the baseline" - ) - for role, captures in (("baseline", baseline), ("candidate", candidate)): - for layout, capture in captures.items(): - if ( - role == "candidate" - and capture.source_revision != expected_candidate_source_revision - ): - raise EvidenceError( - f"candidate {layout} capture does not match the externally " - "pinned source revision" - ) - if ( - capture.build_identity.get("native_build_inputs_sha256") - != expected[role]["native_build_inputs_sha256"] - ): - raise EvidenceError( - f"{role} {layout} capture does not match the externally " - "pinned native-build-input digest" - ) - if ( - capture.prepared_model_sha256 - != expected[role]["prepared_model_sha256"] - ): - raise EvidenceError( - f"{role} {layout} capture does not match the externally " - "pinned prepared-model digest" - ) - return { - "candidate_source_revision": expected_candidate_source_revision, - "roles": expected, - } - - -def _assert_pair_identity( - baseline: Mapping[str, CaptureEvidence], - candidate: Mapping[str, CaptureEvidence], -) -> None: - if baseline["topology-replay"].source_revision != BASELINE_REVISION: - raise EvidenceError( - "baseline source revision is not the immutable migration baseline " - f"{BASELINE_REVISION}" - ) - if candidate["topology-replay"].source_revision == BASELINE_REVISION: - raise EvidenceError("candidate capture still identifies the baseline revision") - baseline_host = baseline["topology-replay"].host_identity - candidate_host = candidate["topology-replay"].host_identity - if baseline_host != candidate_host: - raise EvidenceError( - "baseline and candidate captures were not run on the same host" - ) - _assert_global_worker_identity_separation(baseline, candidate) - for layout in LAYOUTS: - baseline_capture = baseline[layout] - candidate_capture = candidate[layout] - _assert_paired_role_order( - baseline_capture, - candidate_capture, - layout=layout, - ) - if baseline_capture.campaign_identity != candidate_capture.campaign_identity: - raise EvidenceError( - f"{layout} baseline/candidate campaign configurations differ" - ) - modes = list(CAPTURE_MODES) - if ( - baseline_capture.eager_diagnostic.get("complete") is True - and baseline_capture.eager_diagnostic.get("passes") is True - and candidate_capture.eager_diagnostic.get("complete") is True - and candidate_capture.eager_diagnostic.get("passes") is True - ): - modes.append("eager") - for mode in modes: - if ( - baseline_capture.workload_identities[mode] - != candidate_capture.workload_identities[mode] - ): - raise EvidenceError( - f"{layout}/{mode} baseline/candidate workload identities differ" - ) - _assert_cross_layout_sequence(baseline, candidate) - - -def compare_captures( - *, - baseline: Mapping[str, CaptureEvidence], - candidate: Mapping[str, CaptureEvidence], -) -> dict[str, object]: - """Build the content-addressed comparison for four validated captures.""" - - if set(baseline) != set(LAYOUTS) or set(candidate) != set(LAYOUTS): - raise EvidenceError("comparison requires both layouts for both revisions") - _assert_role_consistency(baseline, role="baseline") - _assert_role_consistency(candidate, role="candidate") - _assert_pair_identity(baseline, candidate) - - runtime_cells: list[dict[str, object]] = [] - eager_runtime_cells: list[dict[str, object]] = [] - runtime_by_key: dict[tuple[str, str, int], Mapping[str, object]] = {} - failures: list[str] = [] - eager_failures: list[str] = [] - all_captures = [ - captures[layout] for captures in (baseline, candidate) for layout in LAYOUTS - ] - eager_requested = all( - "eager" in capture.configured_modes for capture in all_captures - ) - eager_available = bool( - eager_requested - and all( - capture.eager_diagnostic.get("complete") is True - and capture.eager_diagnostic.get("passes") is True - for capture in all_captures - ) - ) - eager_inadmissibility_reasons = [ - { - "role": role, - "layout": layout, - "reasons": capture.eager_diagnostic.get("ineligibility_reasons"), - } - for role, captures in (("baseline", baseline), ("candidate", candidate)) - for layout, capture in captures.items() - if "eager" in capture.configured_modes - and ( - capture.eager_diagnostic.get("complete") is not True - or capture.eager_diagnostic.get("passes") is not True - ) - ] - for layout in LAYOUTS: - for mode in CAPTURE_MODES: - for batch_size in BATCH_SIZES: - cell_result = _runtime_cell_comparison( - layout=layout, - mode=mode, - batch_size=batch_size, - baseline=baseline[layout].cells[(mode, batch_size)], - candidate=candidate[layout].cells[(mode, batch_size)], - ) - runtime_cells.append(cell_result) - runtime_by_key[(layout, mode, batch_size)] = cell_result - if cell_result["passes"] is not True: - failures.append( - f"runtime regression: {layout}/{mode}/batch-{batch_size}" - ) - if eager_available: - for layout in LAYOUTS: - for batch_size in BATCH_SIZES: - cell_result = _runtime_cell_comparison( - layout=layout, - mode="eager", - batch_size=batch_size, - baseline=baseline[layout].cells[("eager", batch_size)], - candidate=candidate[layout].cells[("eager", batch_size)], - ) - eager_runtime_cells.append(cell_result) - runtime_by_key[(layout, "eager", batch_size)] = cell_result - if cell_result["passes"] is not True: - eager_failures.append( - "eager diagnostic runtime regression: " - f"{layout}/eager/batch-{batch_size}" - ) - - paired_ratios: list[dict[str, object]] = [] - for layout in LAYOUTS: - for batch_size in RATIO_BATCH_SIZES: - baseline_ratio = _paired_ratio( - layout=layout, - batch_size=batch_size, - capture=baseline[layout], - ) - candidate_ratio = _paired_ratio( - layout=layout, - batch_size=batch_size, - capture=candidate[layout], - ) - candidate_upper = _positive_number( - candidate_ratio["median_plus_3_raw_mad"], - f"{layout}/{batch_size} candidate paired-ratio upper bound", - ) - passes = candidate_upper <= COMPILED_RECURRENCE_RATIO_LIMIT - paired_ratios.append( - { - "layout": layout, - "batch_size": batch_size, - "baseline": baseline_ratio, - "candidate": candidate_ratio, - "limit": COMPILED_RECURRENCE_RATIO_LIMIT, - "passes": passes, - } - ) - if not passes: - failures.append( - f"compiled/recurrence ratio regression: {layout}/batch-{batch_size}" - ) - - generation_cells: list[dict[str, object]] = [] - generation_ratios: list[float] = [] - for layout in LAYOUTS: - for mode in MODES: - baseline_wall = baseline[layout].generation[mode].wall_seconds - candidate_wall = candidate[layout].generation[mode].wall_seconds - ratio = candidate_wall / baseline_wall - passes = ratio <= GENERATION_CELL_LIMIT - generation_ratios.append(ratio) - generation_cells.append( - { - "layout": layout, - "mode": mode, - "baseline_wall_seconds": baseline_wall, - "candidate_wall_seconds": candidate_wall, - "candidate_to_baseline_ratio": ratio, - "limit": GENERATION_CELL_LIMIT, - "passes": passes, - } - ) - if not passes: - failures.append(f"generation regression: {layout}/{mode}") - generation_geomean = _geometric_mean( - generation_ratios, - "generation candidate/baseline ratios", - ) - generation_geomean_passes = generation_geomean <= GENERATION_GEOMEAN_LIMIT - if not generation_geomean_passes: - failures.append("generation geometric-mean regression") - - eager_generation_cells: list[dict[str, object]] = [] - eager_generation_ratios: list[float] = [] - if eager_available: - for layout in LAYOUTS: - baseline_wall = baseline[layout].generation["eager"].wall_seconds - candidate_wall = candidate[layout].generation["eager"].wall_seconds - ratio = candidate_wall / baseline_wall - eager_generation_ratios.append(ratio) - passes = ratio <= GENERATION_CELL_LIMIT - eager_generation_cells.append( - { - "layout": layout, - "mode": "eager", - "baseline_wall_seconds": baseline_wall, - "candidate_wall_seconds": candidate_wall, - "candidate_to_baseline_ratio": ratio, - "limit": GENERATION_CELL_LIMIT, - "passes": passes, - } - ) - if not passes: - eager_failures.append( - f"eager diagnostic generation regression: {layout}/eager" - ) - eager_generation_geomean = ( - _geometric_mean( - eager_generation_ratios, - "eager generation candidate/baseline ratios", - ) - if eager_available - else None - ) - eager_generation_geomean_passes = ( - eager_generation_geomean <= GENERATION_GEOMEAN_LIMIT - if eager_generation_geomean is not None - else None - ) - if eager_generation_geomean_passes is False: - eager_failures.append("eager diagnostic generation geometric-mean regression") - - # A mode-level payload or generation-RSS exception requires a >=10% - # geometric-mean runtime gain and a gain beyond three baseline raw MADs in - # every measured batch. Cell-level cold-load/RSS exceptions use the - # corresponding batch's runtime evidence directly. - mode_runtime_gain: dict[tuple[str, str], dict[str, object]] = {} - for layout in LAYOUTS: - modes_with_diagnostic = ( - (*CAPTURE_MODES, "eager") if eager_available else CAPTURE_MODES - ) - for mode in modes_with_diagnostic: - comparisons = [ - runtime_by_key[(layout, mode, batch_size)] for batch_size in BATCH_SIZES - ] - ratios = [ - _positive_number( - comparison["candidate_to_baseline_ratio"], - f"{layout}/{mode} candidate/baseline runtime ratio", - ) - for comparison in comparisons - ] - ratio_geomean = _geometric_mean( - ratios, - f"{layout}/{mode} runtime ratios", - ) - beyond_noise_all = all( - _mapping( - comparison["resource_exception_runtime_gain"], - "runtime gain evidence", - ).get("gain_beyond_3_baseline_raw_mad") - is True - for comparison in comparisons - ) - mode_runtime_gain[(layout, mode)] = { - "runtime_ratio_geometric_mean": ratio_geomean, - "gain_at_least_10_percent": ( - ratio_geomean <= 1.0 - RESOURCE_EXCEPTION_GAIN - ), - "gain_beyond_3_baseline_raw_mad_in_every_batch": beyond_noise_all, - "passes": ( - ratio_geomean <= 1.0 - RESOURCE_EXCEPTION_GAIN and beyond_noise_all - ), - } - - resources: list[dict[str, object]] = [] - eager_resources: list[dict[str, object]] = [] - for layout in LAYOUTS: - modes_with_diagnostic = ( - (*CAPTURE_MODES, "eager") if eager_available else CAPTURE_MODES - ) - for mode in modes_with_diagnostic: - baseline_generation = baseline[layout].generation[mode] - candidate_generation = candidate[layout].generation[mode] - aggregate_gain = mode_runtime_gain[(layout, mode)] - mode_resources = eager_resources if mode == "eager" else resources - mode_resources.extend( - ( - _single_resource_comparison( - layout=layout, - mode=mode, - metric="artifact_payload_size_bytes", - baseline=float(baseline_generation.payload_size_bytes), - candidate=float(candidate_generation.payload_size_bytes), - runtime_gain=aggregate_gain, - ), - _single_resource_comparison( - layout=layout, - mode=mode, - metric="generation_peak_rss_bytes", - baseline=float(baseline_generation.peak_rss_bytes), - candidate=float(candidate_generation.peak_rss_bytes), - runtime_gain=aggregate_gain, - ), - ) - ) - for batch_size in BATCH_SIZES: - baseline_cell = baseline[layout].cells[(mode, batch_size)] - candidate_cell = candidate[layout].cells[(mode, batch_size)] - gain = _mapping( - runtime_by_key[(layout, mode, batch_size)][ - "resource_exception_runtime_gain" - ], - "runtime gain evidence", - ) - mode_resources.extend( - ( - _resource_comparison( - layout=layout, - mode=mode, - batch_size=batch_size, - metric="cold_load_seconds", - baseline=baseline_cell.cold_load, - candidate=candidate_cell.cold_load, - runtime_gain=gain, - ), - _resource_comparison( - layout=layout, - mode=mode, - batch_size=batch_size, - metric="cold_load_peak_rss_bytes", - baseline=baseline_cell.cold_load_rss, - candidate=candidate_cell.cold_load_rss, - runtime_gain=gain, - ), - _resource_comparison( - layout=layout, - mode=mode, - batch_size=batch_size, - metric="profiled_peak_rss_bytes", - baseline=baseline_cell.profiled_rss, - candidate=candidate_cell.profiled_rss, - runtime_gain=gain, - ), - ) - ) - for diagnostic, inventory in ( - (False, resources), - (True, eager_resources), - ): - for resource in inventory: - if resource["passes"] is not True: - batch_suffix = ( - "" - if "batch_size" not in resource - else f"/batch-{resource['batch_size']}" - ) - prefix = ( - "eager diagnostic resource regression" - if diagnostic - else "resource regression" - ) - failure_inventory = eager_failures if diagnostic else failures - failure_inventory.append( - f"{prefix}: " - f"{resource['layout']}/{resource['mode']}{batch_suffix}/" - f"{resource['metric']}" - ) - - identity = { - "logical_process": baseline["topology-replay"].logical_process, - "host_identity_sha256": _sha256(baseline["topology-replay"].host_identity), - "baseline_source_revision": baseline["topology-replay"].source_revision, - "candidate_source_revision": candidate["topology-replay"].source_revision, - "baseline_build_identity_sha256": _sha256( - baseline["topology-replay"].build_identity - ), - "candidate_build_identity_sha256": _sha256( - candidate["topology-replay"].build_identity - ), - "workloads": { - layout: { - mode: _sha256(baseline[layout].workload_identities[mode]) - for mode in CAPTURE_MODES - } - for layout in LAYOUTS - }, - } - eager_runtime_passes = ( - all(cell["passes"] is True for cell in eager_runtime_cells) - if eager_available - else None - ) - eager_generation_passes = ( - eager_generation_geomean_passes is True - and all(cell["passes"] is True for cell in eager_generation_cells) - if eager_available - else None - ) - eager_resource_passes = ( - all(resource["passes"] is True for resource in eager_resources) - if eager_available - else None - ) - if not eager_available: - eager_failures.append("eager campaign is not admissible") - failures.extend(eager_failures) - comparison_result: dict[str, object] = { - "kind": COMPARISON_KIND, - "schema_version": COMPARISON_SCHEMA, - "complete": True, - "passes": not failures, - "identity": identity, - "identity_sha256": _sha256(identity), - "inputs": { - role: {layout: dict(captures[layout].input_identity) for layout in LAYOUTS} - for role, captures in ( - ("baseline", baseline), - ("candidate", candidate), - ) - }, - "thresholds": { - "runtime_candidate_median_relative_to_baseline": RUNTIME_RELATIVE_LIMIT, - "runtime_baseline_raw_mad_multiplier": RUNTIME_NOISE_MAD_MULTIPLIER, - "compiled_to_recurrence_ratio_median_plus_3_raw_mad": ( - COMPILED_RECURRENCE_RATIO_LIMIT - ), - "generation_cell_candidate_to_baseline": GENERATION_CELL_LIMIT, - "generation_geometric_mean_candidate_to_baseline": ( - GENERATION_GEOMEAN_LIMIT - ), - "resource_growth_candidate_to_baseline": RESOURCE_GROWTH_LIMIT, - "resource_exception_minimum_runtime_gain": RESOURCE_EXCEPTION_GAIN, - }, - "runtime_cells": runtime_cells, - "paired_compiled_recurrence_ratios": paired_ratios, - "generation": { - "cells": generation_cells, - "candidate_to_baseline_ratio_geometric_mean": generation_geomean, - "geometric_mean_limit": GENERATION_GEOMEAN_LIMIT, - "geometric_mean_passes": generation_geomean_passes, - "passes": ( - generation_geomean_passes - and all(cell["passes"] is True for cell in generation_cells) - ), - }, - "payload_cold_load_rss": resources, - "eager_diagnostic": { - "requested": eager_requested, - "admissible": eager_available, - "inadmissibility_reasons": eager_inadmissibility_reasons, - "runtime_cells": eager_runtime_cells, - "runtime_passes": eager_runtime_passes, - "generation": { - "cells": eager_generation_cells, - "candidate_to_baseline_ratio_geometric_mean": ( - eager_generation_geomean - ), - "geometric_mean_limit": GENERATION_GEOMEAN_LIMIT, - "geometric_mean_passes": eager_generation_geomean_passes, - "passes": eager_generation_passes, - }, - "payload_cold_load_rss": eager_resources, - "resource_passes": eager_resource_passes, - "paired_compiled_recurrence_ratio_applicable": False, - "passes": ( - eager_runtime_passes - and eager_generation_passes - and eager_resource_passes - if eager_available - else None - ), - "failures": eager_failures, - }, - "failures": failures, - } - comparison_result["content_sha256"] = _sha256(comparison_result) - return comparison_result - - -def _validate_campaign_capture_identity( - value: object, - *, - evidence: CaptureEvidence, - label: str, -) -> None: - identity = _mapping(value, label) - if set(identity) != {"path", "resolved_path", "size_bytes", "sha256"}: - raise EvidenceError(f"{label} has an unsupported capture identity") - resolved_path = _string(identity.get("resolved_path"), f"{label}.resolved_path") - if ( - _string(identity.get("path"), f"{label}.path") - != evidence.input_identity.get("path") - or resolved_path != evidence.input_identity.get("resolved_path") - or _exact_int( - identity.get("size_bytes"), - f"{label}.size_bytes", - minimum=1, - ) - != evidence.input_identity.get("size_bytes") - or _valid_sha256(identity.get("sha256"), f"{label}.sha256") - != evidence.input_identity.get("sha256") - ): - raise EvidenceError(f"{label} does not identify its supplied capture file") - - -def _validate_paired_campaign( - payload: Mapping[str, Any], - input_identity: Mapping[str, object], - *, - baseline: Mapping[str, CaptureEvidence], - candidate: Mapping[str, CaptureEvidence], -) -> Mapping[str, object]: - label = "paired campaign" - campaign = _validate_content_address(payload, label) - _validate_nested_content_addresses(campaign, label) - expected_root_fields = { - "kind", - "schema_version", - "complete", - "session_id", - "started_at_utc", - "finished_at_utc", - "process", - "orchestrator", - "harness", - "roles", - "configuration", - "layouts", - "content_sha256", - } - if ( - set(campaign) != expected_root_fields - or campaign.get("kind") != PAIRED_CAMPAIGN_KIND - or campaign.get("schema_version") != PAIRED_CAMPAIGN_SCHEMA - or campaign.get("complete") is not True - ): - raise EvidenceError(f"{label} has an unsupported identity") - session_id = _string(campaign.get("session_id"), f"{label}.session_id") - started = _utc_timestamp( - campaign.get("started_at_utc"), - f"{label}.started_at_utc", - ) - finished = _utc_timestamp( - campaign.get("finished_at_utc"), - f"{label}.finished_at_utc", - ) - if started > finished: - raise EvidenceError(f"{label} timestamps are inverted") - logical_process = _logical_process(campaign.get("process"), f"{label}.process") - if logical_process != baseline["topology-replay"].logical_process: - raise EvidenceError(f"{label} process differs from its supplied captures") - - harness = _mapping(campaign.get("harness"), f"{label}.harness") - expected_harness_fields = { - "kind", - "schema_version", - "candidate_relative_path", - "head_blob_sha256", - "working_file_sha256", - "head_blob_equals_working_file", - "content_sha256", - } - harness_path = ( - Path(__file__).resolve().parents[2] / PAIRED_HARNESS_RELATIVE_PATH - ) - harness_sha256 = _sha256_file(harness_path) - if ( - set(harness) != expected_harness_fields - or harness.get("kind") != PAIRED_HARNESS_KIND - or harness.get("schema_version") != PAIRED_HARNESS_SCHEMA - or harness.get("candidate_relative_path") != PAIRED_HARNESS_RELATIVE_PATH - or harness.get("head_blob_equals_working_file") is not True - or _valid_sha256( - harness.get("head_blob_sha256"), - f"{label}.harness.head_blob_sha256", - ) - != harness_sha256 - or _valid_sha256( - harness.get("working_file_sha256"), - f"{label}.harness.working_file_sha256", - ) - != harness_sha256 - ): - raise EvidenceError( - f"{label} harness is not the exact candidate benchmark driver" - ) - orchestrator = _mapping( - campaign.get("orchestrator"), - f"{label}.orchestrator", - ) - orchestrator_path = ( - Path(__file__).resolve().parents[2] / PAIRED_DRIVER_RELATIVE_PATH - ) - orchestrator_sha256 = _sha256_file(orchestrator_path) - if ( - set(orchestrator) != expected_harness_fields - or orchestrator.get("kind") != PAIRED_HARNESS_KIND - or orchestrator.get("schema_version") != PAIRED_HARNESS_SCHEMA - or orchestrator.get("candidate_relative_path") - != PAIRED_DRIVER_RELATIVE_PATH - or orchestrator.get("head_blob_equals_working_file") is not True - or _valid_sha256( - orchestrator.get("head_blob_sha256"), - f"{label}.orchestrator.head_blob_sha256", - ) - != orchestrator_sha256 - or _valid_sha256( - orchestrator.get("working_file_sha256"), - f"{label}.orchestrator.working_file_sha256", - ) - != orchestrator_sha256 - ): - raise EvidenceError( - f"{label} orchestrator is not the exact paired benchmark driver" - ) - - captures_by_role = {"baseline": baseline, "candidate": candidate} - roles = _mapping(campaign.get("roles"), f"{label}.roles") - if set(roles) != set(captures_by_role): - raise EvidenceError(f"{label} role inventory is incomplete") - expected_role_fields = { - "source_root", - "source_revision", - "python", - "python_resolved_target", - "python_sha256", - "prepared_model", - "prepared_model_sha256", - } - for role, captures in captures_by_role.items(): - role_record = _mapping(roles.get(role), f"{label}.roles.{role}") - reference = captures["topology-replay"] - if any( - capture.paired_profile_coordination.get("session_id") != session_id - for capture in captures.values() - ): - raise EvidenceError( - f"{label}.session_id differs from its {role} captures" - ) - if set(role_record) != expected_role_fields: - raise EvidenceError(f"{label}.roles.{role} has an unsupported identity") - for field in ( - "source_root", - "python", - "python_resolved_target", - "prepared_model", - ): - _string(role_record.get(field), f"{label}.roles.{role}.{field}") - if ( - role_record.get("source_revision") != reference.source_revision - or role_record.get("python") != reference.interpreter_path - or role_record.get("python_resolved_target") - != reference.interpreter_resolved_path - or _valid_sha256( - role_record.get("python_sha256"), - f"{label}.roles.{role}.python_sha256", - ) - != reference.campaign_identity["interpreter"]["executable_sha256"] - or role_record.get("prepared_model") != reference.prepared_model_path - or _valid_sha256( - role_record.get("prepared_model_sha256"), - f"{label}.roles.{role}.prepared_model_sha256", - ) - != reference.prepared_model_sha256 - ): - raise EvidenceError( - f"{label}.roles.{role} differs from its capture provenance" - ) - - reference_campaign = baseline["topology-replay"].campaign_identity - expected_configuration = { - "authoritative_modes": list(AUTHORITATIVE_MODES), - "diagnostic_modes": list(DIAGNOSTIC_MODES), - "batch_sizes": list(BATCH_SIZES), - "target_runtime_seconds": reference_campaign["target_runtime_seconds"], - "minimum_samples": reference_campaign["minimum_internal_samples"], - "subprocess_samples": reference_campaign["subprocess_samples"], - "warmup_runs": reference_campaign["warmup_runs"], - "watchdog": { - "required": True, - "report_kind": WATCHDOG_REPORT_KIND, - "report_schema_version": WATCHDOG_REPORT_SCHEMA, - "limit_bytes": WATCHDOG_LIMIT_BYTES, - "scope": WATCHDOG_SCOPE, - "binding": WATCHDOG_BINDING, - }, - } - configuration = _mapping( - campaign.get("configuration"), - f"{label}.configuration", - ) - if dict(configuration) != expected_configuration: - raise EvidenceError(f"{label} configuration differs from its captures") - - layouts = _mapping(campaign.get("layouts"), f"{label}.layouts") - if set(layouts) != set(LAYOUTS): - raise EvidenceError(f"{label} layout inventory is incomplete") - for layout in LAYOUTS: - layout_record = _mapping(layouts.get(layout), f"{label}.layouts.{layout}") - if ( - set(layout_record) - != { - "layout", - "ready_records", - "paired_schedule_algorithm", - "pairs", - "captures", - } - or layout_record.get("layout") != layout - or layout_record.get("paired_schedule_algorithm") - != "slot-adjacent-round-alternating-role-order-v1" - ): - raise EvidenceError(f"{label}.layouts.{layout} has an unsupported identity") - ready_records = _mapping( - layout_record.get("ready_records"), - f"{label}.layouts.{layout}.ready_records", - ) - capture_identities = _mapping( - layout_record.get("captures"), - f"{label}.layouts.{layout}.captures", - ) - if set(ready_records) != set(captures_by_role) or set( - capture_identities - ) != set(captures_by_role): - raise EvidenceError( - f"{label}.layouts.{layout} role inventory is incomplete" - ) - for role, captures in captures_by_role.items(): - evidence = captures[layout] - if ( - ready_records.get(role) - != evidence.paired_profile_coordination["ready_record"] - ): - raise EvidenceError( - f"{label}.layouts.{layout}.{role} ready record differs " - "from its capture" - ) - _validate_campaign_capture_identity( - capture_identities.get(role), - evidence=evidence, - label=f"{label}.layouts.{layout}.captures.{role}", - ) - ready_at = evidence.paired_profile_coordination.get("ready_at") - if not isinstance(ready_at, dt.datetime) or not started <= ready_at: - raise EvidenceError( - f"{label}.layouts.{layout}.{role} became ready before " - "the campaign started" - ) - - raw_pairs = _sequence( - layout_record.get("pairs"), - f"{label}.layouts.{layout}.pairs", - ) - baseline_slots = _mapping( - baseline[layout].paired_profile_coordination.get("slots"), - f"{label}.layouts.{layout}.baseline slots", - ) - candidate_slots = _mapping( - candidate[layout].paired_profile_coordination.get("slots"), - f"{label}.layouts.{layout}.candidate slots", - ) - if len(raw_pairs) != len(baseline_slots): - raise EvidenceError( - f"{label}.layouts.{layout} pair inventory is incomplete" - ) - for pair_index, raw_pair in enumerate(raw_pairs): - pair = _mapping( - raw_pair, - f"{label}.layouts.{layout}.pairs[{pair_index}]", - ) - baseline_slot = _mapping( - baseline_slots[pair_index], - f"{label}.layouts.{layout}.baseline slot {pair_index}", - ) - candidate_slot = _mapping( - candidate_slots[pair_index], - f"{label}.layouts.{layout}.candidate slot {pair_index}", - ) - token = _mapping( - baseline_slot.get("token"), - f"{label}.layouts.{layout}.baseline token {pair_index}", - ) - round_index = _exact_int( - token.get("round"), - f"{label}.layouts.{layout}.pairs[{pair_index}].round", - minimum=0, - ) - expected_order = ( - ["baseline", "candidate"] - if round_index % 2 == 0 - else ["candidate", "baseline"] - ) - expected_coordinates = { - field: token.get(field) - for field in ( - "schedule_index", - "round", - "mode", - "batch_size", - ) - } - completions = _mapping( - pair.get("completions"), - f"{label}.layouts.{layout}.pairs[{pair_index}].completions", - ) - if ( - pair.get("kind") != "pyamplicol-paired-profile-pair" - or pair.get("schema_version") != 1 - or pair.get("pair_index") != pair_index - or any( - pair.get(field) != value - for field, value in expected_coordinates.items() - ) - or pair.get("role_order") != expected_order - or dict(completions) - != { - "baseline": baseline_slot["completion"], - "candidate": candidate_slot["completion"], - } - ): - raise EvidenceError( - f"{label}.layouts.{layout}.pairs[{pair_index}] differs " - "from its captures" - ) - for role_slot in (baseline_slot, candidate_slot): - recorded = role_slot.get("recorded") - if not isinstance(recorded, dt.datetime) or recorded > finished: - raise EvidenceError( - f"{label}.layouts.{layout} completed after the campaign" - ) - - result = dict(input_identity) - result["campaign_content_sha256"] = _valid_sha256( - campaign.get("content_sha256"), - f"{label}.content_sha256", - ) - result["harness_content_sha256"] = _valid_sha256( - harness.get("content_sha256"), - f"{label}.harness.content_sha256", - ) - result["orchestrator_content_sha256"] = _valid_sha256( - orchestrator.get("content_sha256"), - f"{label}.orchestrator.content_sha256", - ) - return result - - -def _validate_watchdog_report( - payload: Mapping[str, Any], - input_identity: Mapping[str, object], - *, - campaign: Mapping[str, Any], - campaign_input_identity: Mapping[str, object], -) -> Mapping[str, object]: - label = "outer memory watchdog report" - report = _validate_content_address(payload, label) - _validate_nested_content_addresses(report, label) - expected_fields = { - "kind", - "schema_version", - "complete", - "passes", - "watchdog", - "working_directory", - "execution", - "enforcement", - "result_binding", - "content_sha256", - } - if ( - set(report) != expected_fields - or report.get("kind") != WATCHDOG_REPORT_KIND - or report.get("schema_version") != WATCHDOG_REPORT_SCHEMA - or report.get("complete") is not True - or report.get("passes") is not True - ): - raise EvidenceError(f"{label} is not complete and passing") - - watchdog_identity = _mapping( - report.get("watchdog"), - f"{label}.watchdog", - ) - watchdog_path = Path(__file__).resolve().parents[2] / WATCHDOG_RELATIVE_PATH - if ( - set(watchdog_identity) != {"path", "resolved_path", "size_bytes", "sha256"} - or watchdog_identity.get("resolved_path") != str(watchdog_path.resolve()) - or _exact_int( - watchdog_identity.get("size_bytes"), - f"{label}.watchdog.size_bytes", - minimum=1, - ) - != watchdog_path.stat().st_size - or _valid_sha256( - watchdog_identity.get("sha256"), - f"{label}.watchdog.sha256", - ) - != _sha256_file(watchdog_path) - ): - raise EvidenceError( - f"{label} was not emitted by the authenticated watchdog tool" - ) - - execution = _mapping(report.get("execution"), f"{label}.execution") - if set(execution) != { - "command", - "command_sha256", - "started_at_utc", - "finished_at_utc", - "elapsed_wall_seconds", - "child_pid", - "child_exit_code", - "watchdog_exit_code", - "outcome", - "reason", - }: - raise EvidenceError(f"{label} execution has an unsupported schema") - command = list(_sequence(execution.get("command"), f"{label}.execution.command")) - if ( - len(command) < 2 - or any(not isinstance(value, str) or not value for value in command) - or _valid_sha256( - execution.get("command_sha256"), - f"{label}.execution.command_sha256", - ) - != _sha256(command) - or execution.get("child_exit_code") != 0 - or execution.get("watchdog_exit_code") != 0 - or execution.get("outcome") != "command-finished" - or execution.get("reason") is not None - or _exact_int( - execution.get("child_pid"), - f"{label}.execution.child_pid", - minimum=1, - ) - < 1 - or _positive_number( - execution.get("elapsed_wall_seconds"), - f"{label}.execution.elapsed_wall_seconds", - ) - <= 0.0 - ): - raise EvidenceError(f"{label} did not record a successful child execution") - watchdog_started = _utc_timestamp( - execution.get("started_at_utc"), - f"{label}.execution.started_at_utc", - ) - watchdog_finished = _utc_timestamp( - execution.get("finished_at_utc"), - f"{label}.execution.finished_at_utc", - ) - campaign_started = _utc_timestamp( - campaign.get("started_at_utc"), - "paired campaign.started_at_utc", - ) - campaign_finished = _utc_timestamp( - campaign.get("finished_at_utc"), - "paired campaign.finished_at_utc", - ) - if not watchdog_started <= campaign_started <= campaign_finished <= watchdog_finished: - raise EvidenceError( - f"{label} timestamps do not enclose the paired campaign" - ) - - enforcement = _mapping(report.get("enforcement"), f"{label}.enforcement") - if ( - set(enforcement) - != { - "scope", - "limit_bytes", - "poll_interval_seconds", - "terminate_grace_seconds", - "metric", - "probe_sample_count", - "probe_failure_count", - "maximum_consecutive_probe_failures", - "completed_under_retry_policy", - "peak_rss_bytes", - "peak_physical_footprint_bytes", - "peak_guard_bytes", - "peak_processes", - } - or enforcement.get("scope") != WATCHDOG_SCOPE - or enforcement.get("limit_bytes") != WATCHDOG_LIMIT_BYTES - or enforcement.get("metric") - not in { - "process-tree-rss", - "max(process-tree-rss,darwin-process-tree-physical-footprint)", - } - or enforcement.get("completed_under_retry_policy") is not True - or _exact_int( - enforcement.get("probe_sample_count"), - f"{label}.enforcement.probe_sample_count", - minimum=1, - ) - < 1 - or _positive_number( - enforcement.get("poll_interval_seconds"), - f"{label}.enforcement.poll_interval_seconds", - ) - <= 0.0 - or _nonnegative_number( - enforcement.get("terminate_grace_seconds"), - f"{label}.enforcement.terminate_grace_seconds", - ) - < 0.0 - ): - raise EvidenceError( - f"{label} does not prove successful 30-GiB enforcement" - ) - probe_failure_count = _exact_int( - enforcement.get("probe_failure_count"), - f"{label}.enforcement.probe_failure_count", - minimum=0, - ) - maximum_consecutive_probe_failures = _exact_int( - enforcement.get("maximum_consecutive_probe_failures"), - f"{label}.enforcement.maximum_consecutive_probe_failures", - minimum=0, - ) - if ( - maximum_consecutive_probe_failures > 2 - or maximum_consecutive_probe_failures > probe_failure_count - or (probe_failure_count == 0) != (maximum_consecutive_probe_failures == 0) - ): - raise EvidenceError( - f"{label} exceeds the watchdog's recovered-probe retry policy" - ) - peak_rss = _exact_int( - enforcement.get("peak_rss_bytes"), - f"{label}.enforcement.peak_rss_bytes", - minimum=0, - ) - peak_guard = _exact_int( - enforcement.get("peak_guard_bytes"), - f"{label}.enforcement.peak_guard_bytes", - minimum=0, - ) - _exact_int( - enforcement.get("peak_processes"), - f"{label}.enforcement.peak_processes", - minimum=1, - ) - physical_peak = enforcement.get("peak_physical_footprint_bytes") - if physical_peak is not None: - physical_peak = _exact_int( - physical_peak, - f"{label}.enforcement.peak_physical_footprint_bytes", - minimum=0, - ) - metric = enforcement.get("metric") - if ( - peak_guard > WATCHDOG_LIMIT_BYTES - or ( - metric == "process-tree-rss" - and (physical_peak is not None or peak_guard != peak_rss) - ) - or ( - metric - == "max(process-tree-rss,darwin-process-tree-physical-footprint)" - and ( - physical_peak is None - or peak_guard != max(peak_rss, physical_peak) - ) - ) - ): - raise EvidenceError(f"{label} peak observations are internally inconsistent") - - working_directory = Path( - _string(report.get("working_directory"), f"{label}.working_directory") - ) - if not working_directory.is_absolute(): - raise EvidenceError(f"{label} working directory is not absolute") - - def option(name: str) -> str: - indices = [index for index, value in enumerate(command) if value == name] - if ( - len(indices) != 1 - or indices[0] + 1 >= len(command) - or not isinstance(command[indices[0] + 1], str) - or not command[indices[0] + 1] - ): - raise EvidenceError(f"{label} command has no unique {name}") - return command[indices[0] + 1] - - roles = _mapping(campaign.get("roles"), "paired campaign.roles") - candidate_role = _mapping( - roles.get("candidate"), - "paired campaign.roles.candidate", - ) - if command[0] != candidate_role.get("python"): - raise EvidenceError( - f"{label} command did not use the candidate campaign interpreter" - ) - command_driver = Path(command[1]).expanduser() - if not command_driver.is_absolute(): - command_driver = working_directory / command_driver - if command_driver.resolve() != ( - Path(__file__).resolve().parents[2] / PAIRED_DRIVER_RELATIVE_PATH - ).resolve(): - raise EvidenceError( - f"{label} command did not execute the paired benchmark driver" - ) - if option("--session-id") != campaign.get("session_id"): - raise EvidenceError(f"{label} command session differs from the campaign") - result_argument = Path(option("--result-json")).expanduser() - if not result_argument.is_absolute(): - result_argument = working_directory / result_argument - result_resolved = str(result_argument.resolve()) - if result_resolved != campaign_input_identity.get("resolved_path"): - raise EvidenceError( - f"{label} command result path differs from the supplied campaign" - ) - - binding = _mapping(report.get("result_binding"), f"{label}.result_binding") - if set(binding) != {"requested", "requested_path", "identity", "error"}: - raise EvidenceError(f"{label} result binding has an unsupported schema") - identity = _mapping( - binding.get("identity"), - f"{label}.result_binding.identity", - ) - if ( - binding.get("requested") is not True - or binding.get("error") is not None - or set(identity) != {"path", "resolved_path", "size_bytes", "sha256"} - or identity.get("path") != binding.get("requested_path") - or str(Path(_string(identity.get("path"), f"{label}.result path")).expanduser()) - != str(Path(option("--result-json")).expanduser()) - or identity.get("resolved_path") != result_resolved - or identity.get("resolved_path") - != campaign_input_identity.get("resolved_path") - or identity.get("size_bytes") != campaign_input_identity.get("size_bytes") - or identity.get("sha256") != campaign_input_identity.get("sha256") - ): - raise EvidenceError( - f"{label} does not content-address the supplied paired campaign" - ) - - result = dict(input_identity) - result["report_content_sha256"] = _valid_sha256( - report.get("content_sha256"), - f"{label}.content_sha256", - ) - result["command_sha256"] = _valid_sha256( - execution.get("command_sha256"), - f"{label}.execution.command_sha256", - ) - result["bound_campaign_sha256"] = _valid_sha256( - identity.get("sha256"), - f"{label}.result_binding.identity.sha256", - ) - result["watchdog_sha256"] = _valid_sha256( - watchdog_identity.get("sha256"), - f"{label}.watchdog.sha256", - ) - return result - - -def compare_capture_files( - *, - campaign: Path, - watchdog_report: Path, - baseline_topology: Path, - baseline_all_flow_union: Path, - candidate_topology: Path, - candidate_all_flow_union: Path, - expected_candidate_source_revision: str, - expected_baseline_native_build_inputs_sha256: str, - expected_candidate_native_build_inputs_sha256: str, - expected_baseline_prepared_model_sha256: str, - expected_candidate_prepared_model_sha256: str, -) -> dict[str, object]: - """Load, validate, and compare the four required capture files.""" - - campaign_payload, campaign_input_identity = _read_json_mapping( - campaign, - label="paired campaign", - ) - watchdog_payload, watchdog_input_identity = _read_json_mapping( - watchdog_report, - label="outer memory watchdog report", - ) - paths = { - "baseline": { - "topology-replay": baseline_topology, - "all-flow-union": baseline_all_flow_union, - }, - "candidate": { - "topology-replay": candidate_topology, - "all-flow-union": candidate_all_flow_union, - }, - } - evidence: dict[str, dict[str, CaptureEvidence]] = { - "baseline": {}, - "candidate": {}, - } - for role in ("baseline", "candidate"): - for layout in LAYOUTS: - payload, input_identity = _read_capture(paths[role][layout]) - evidence[role][layout] = _validate_capture( - payload, - input_identity, - role=role, - expected_layout=layout, - ) - expected_role_inputs = _assert_externally_pinned_role_inputs( - evidence["baseline"], - evidence["candidate"], - expected_candidate_source_revision=expected_candidate_source_revision, - expected_baseline_native_build_inputs_sha256=( - expected_baseline_native_build_inputs_sha256 - ), - expected_candidate_native_build_inputs_sha256=( - expected_candidate_native_build_inputs_sha256 - ), - expected_baseline_prepared_model_sha256=( - expected_baseline_prepared_model_sha256 - ), - expected_candidate_prepared_model_sha256=( - expected_candidate_prepared_model_sha256 - ), - ) - comparison = compare_captures( - baseline=evidence["baseline"], - candidate=evidence["candidate"], - ) - campaign_identity = _validate_paired_campaign( - campaign_payload, - campaign_input_identity, - baseline=evidence["baseline"], - candidate=evidence["candidate"], - ) - watchdog_identity = _validate_watchdog_report( - watchdog_payload, - watchdog_input_identity, - campaign=campaign_payload, - campaign_input_identity=campaign_input_identity, - ) - unsigned = dict(comparison) - unsigned.pop("content_sha256") - inputs = dict(_mapping(unsigned.get("inputs"), "comparison.inputs")) - inputs["externally_pinned_role_inputs"] = expected_role_inputs - inputs["paired_campaign"] = dict(campaign_identity) - inputs["outer_memory_watchdog"] = dict(watchdog_identity) - unsigned["inputs"] = inputs - unsigned["content_sha256"] = _sha256(unsigned) - return unsigned - - -def _write_json_atomic(path: Path, value: Mapping[str, object]) -> None: - try: - path.parent.mkdir(parents=True, exist_ok=True) - data = _canonical_json_bytes(value) + b"\n" - with tempfile.NamedTemporaryFile( - mode="wb", - dir=path.parent, - prefix=f".{path.name}.", - suffix=".tmp", - delete=False, - ) as stream: - temporary = Path(stream.name) - stream.write(data) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - except OSError as error: - raise EvidenceError(f"cannot write comparison JSON: {path}") from error - finally: - temporary_path = locals().get("temporary") - if isinstance(temporary_path, Path) and temporary_path.exists(): - temporary_path.unlink() - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - result.add_argument("--campaign", type=Path, required=True) - result.add_argument("--watchdog-report", type=Path, required=True) - result.add_argument("--baseline-topology", type=Path, required=True) - result.add_argument("--baseline-all-flow-union", type=Path, required=True) - result.add_argument("--candidate-topology", type=Path, required=True) - result.add_argument("--candidate-all-flow-union", type=Path, required=True) - result.add_argument("--expected-candidate-source-revision", required=True) - result.add_argument( - "--expected-baseline-native-build-inputs-sha256", - required=True, - ) - result.add_argument( - "--expected-candidate-native-build-inputs-sha256", - required=True, - ) - result.add_argument( - "--expected-baseline-prepared-model-sha256", - required=True, - ) - result.add_argument( - "--expected-candidate-prepared-model-sha256", - required=True, - ) - result.add_argument("--output", type=Path, required=True) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - try: - comparison = compare_capture_files( - campaign=arguments.campaign, - watchdog_report=arguments.watchdog_report, - baseline_topology=arguments.baseline_topology, - baseline_all_flow_union=arguments.baseline_all_flow_union, - candidate_topology=arguments.candidate_topology, - candidate_all_flow_union=arguments.candidate_all_flow_union, - expected_candidate_source_revision=( - arguments.expected_candidate_source_revision - ), - expected_baseline_native_build_inputs_sha256=( - arguments.expected_baseline_native_build_inputs_sha256 - ), - expected_candidate_native_build_inputs_sha256=( - arguments.expected_candidate_native_build_inputs_sha256 - ), - expected_baseline_prepared_model_sha256=( - arguments.expected_baseline_prepared_model_sha256 - ), - expected_candidate_prepared_model_sha256=( - arguments.expected_candidate_prepared_model_sha256 - ), - ) - _write_json_atomic(arguments.output, comparison) - except EvidenceError as error: - print(f"benchmark evidence error: {error}", file=sys.stderr) - return 2 - return 0 if comparison["passes"] is True else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/x86_performance_runtime_bundle.py b/pyamplicol/tools/developer/x86_performance_runtime_bundle.py deleted file mode 100644 index e3655cb246..0000000000 --- a/pyamplicol/tools/developer/x86_performance_runtime_bundle.py +++ /dev/null @@ -1,1141 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Build-time authentication helpers for the x86 performance runtime bundle. - -The frozen pre-Arena candidate predates reproducible dependency-state -timestamps. ``freeze-baseline`` restores the already accepted generated state -only after every path-independent dependency input matches its pinned digest. -The other commands content-bind or verify the two installed candidates, their -shared external dependency distributions, wheel bytes, and the UFO prepared -model used by the recurrence comparison. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.metadata -import json -import os -import platform -import re -import shutil -import stat -import subprocess -import sys -import venv -from collections.abc import Mapping, Sequence -from pathlib import Path, PurePosixPath -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.developer import compiled_mode_matrix as matrix # noqa: E402 -from tools.developer import compiled_mode_regression as regression # noqa: E402 - -BUNDLE_KIND = "pyamplicol-x86-performance-runtime-bundle" -BASELINE_ATTESTATION_KIND = "pyamplicol-frozen-baseline-source-attestation" -SCHEMA_VERSION = 1 -CONTENT_IDENTITY_ALGORITHM = "sha256-canonical-json-body-v1" -FROZEN_SOURCE_ROOT = Path("/private/tmp/pyamplicol-eager-compiled-arena-base-src") -FROZEN_CANDIDATE_LOCK_SHA256 = ( - "3ec1fd00ed1369adcb736a6816495bb21bcc11a377d0922a59cc0b845a0df3ef" -) -FROZEN_CARGO_CONFIG_SHA256 = ( - "f14f5d6595a26680e636c5f25f2ea9d88772a6e44b6777c363cb8b810e2ca661" -) -FROZEN_INSTALL_STATE_SHA256 = ( - "d4835339f2e35ac5e3ba4ec10941f6cffa4465fec505e3560e25e7eba534bb09" -) -_SHA256 = re.compile(r"[0-9a-f]{64}") -_GIT_SHA = re.compile(r"[0-9a-f]{40}") -_BASELINE_IGNORED_ENTRY_LIMIT = 100_000 -_BASELINE_GENERATED_FILES = ( - "dependencies/candidate-Cargo.lock", - "dependencies/candidate-cargo-config.toml", - "dependencies/install-state.json", -) -_BASELINE_BOOTSTRAP_ROOTS = ( - ".venv/", - "dependencies/checkouts/", - "dependencies/wheelhouse/", -) - -FROZEN_INSTALL_STATE: dict[str, object] = { - "candidate_lock_sha256": FROZEN_CANDIDATE_LOCK_SHA256, - "cargo_config_sha256": FROZEN_CARGO_CONFIG_SHA256, - "contributor_lock_sha256": ( - "91a4cd4d03bc3d35b7e2794f04bed4580428f5d17ea2f846fa530c5df8197cb5" - ), - "created_utc": "2026-07-24T16:52:37.275744+00:00", - "patches": [ - { - "applies_to_revision": "48197f32536c894b51ef25b2cf05ddd05c22675f", - "name": "symjit-aarch64-compression-and-direct-arena", - "path": "patches/symjit/0001-aarch64-compression-and-direct-arena.patch", - "sha256": ( - "6d456e69fc160ec5361188f60f994d10fb2dd3360eb47a91c4979a1bde69626e" - ), - "target": "symjit", - } - ], - "publishable": False, - "python_runtime_lock_sha256": ( - "f8c929cfe925630a96e1a9d80bb8d6106964ace84a4efc4df171784a4f8f522b" - ), - "release_lock_sha256": ( - "3302cacd840eb9f14e9e00e4c4c712d1a4735a45c1702224b84e4f34385f50ee" - ), - "schema_version": 1, - "sources": { - "gammaloop": { - "revision": "fff1d66ee7ca039b9e165fe8d29da91f4c27113c", - "url": "https://github.com/alphal00p/gammaloop.git", - "worktree_sha256": ( - "2576a8cd3bd5cd58c649af7c6b480d7a8c3ed86afd0c7ac8b20be605d7e9f005" - ), - }, - "legacy-amplicol": { - "branch": "amplicol_with_patches", - "revision": "79c96cecf2a722e50c3d2030b6894d755f96518a", - "url": "git@github.com:rikkert-frederix/AmpliCol.git", - "worktree_sha256": ( - "2b6678c6fe477fcc0f99b5ed636e34b6c783ba778c328268e57d34de44bd7d65" - ), - }, - "symbolica": { - "revision": "77c137481904b8a5531ede86e3ef36b82beed7fd", - "url": "https://github.com/symbolica-dev/symbolica.git", - "worktree_sha256": ( - "3a52b012e62783988a9567260d022b049d9d07183a8604e7cbfc99218344cd59" - ), - }, - "symbolica-community": { - "revision": "0deaa0f1484ec5c24f5f109176fa66f0d30134ca", - "url": "https://github.com/symbolica-dev/symbolica-community.git", - "worktree_sha256": ( - "bbe726e158192c2bac478cf482f68576d8bd49d06f28282e0e4cc5fa43c1c479" - ), - }, - "symjit": { - "archive_sha256": ( - "876930348cc06761ca780570fb282d009f143f4a469e321e3b5039c5ee217424" - ), - "patch_sha256": ( - "6d456e69fc160ec5361188f60f994d10fb2dd3360eb47a91c4979a1bde69626e" - ), - "revision": "48197f32536c894b51ef25b2cf05ddd05c22675f", - "url": ( - "https://github.com/siravan/symjit/archive/" - "48197f32536c894b51ef25b2cf05ddd05c22675f.tar.gz" - ), - "version": "2.21.1", - "worktree_sha256": ( - "932bb24df2633cc8bbf9c743a80282662d11e70b692885de5ff7a3ed20b3df31" - ), - }, - }, -} - - -class BundleError(RuntimeError): - """Raised when the runtime bundle cannot be authenticated.""" - - -def _canonical_bytes(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ).encode() - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256(_canonical_bytes(value)).hexdigest() - - -def _attach_content_identity(body: Mapping[str, object]) -> dict[str, object]: - result = dict(body) - result["content_identity"] = { - "algorithm": CONTENT_IDENTITY_ALGORITHM, - "sha256": _canonical_sha256(body), - } - return result - - -def _require_content_identity(payload: Mapping[str, object]) -> None: - identity = payload.get("content_identity") - body = dict(payload) - body.pop("content_identity", None) - if ( - not isinstance(identity, Mapping) - or set(identity) != {"algorithm", "sha256"} - or identity.get("algorithm") != CONTENT_IDENTITY_ALGORITHM - or identity.get("sha256") != _canonical_sha256(body) - ): - raise BundleError("runtime bundle content identity is invalid") - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - while chunk := stream.read(1024 * 1024): - digest.update(chunk) - return digest.hexdigest() - - -def _file_identity(path: Path) -> dict[str, object]: - expanded = path.expanduser().absolute() - try: - before = expanded.lstat() - except OSError as error: - raise BundleError(f"cannot inspect bundle input: {path}") from error - if not stat.S_ISREG(before.st_mode) or expanded.is_symlink(): - raise BundleError(f"bundle input is not a regular non-symlink file: {path}") - resolved = expanded.resolve(strict=True) - digest = _sha256_file(resolved) - try: - after = expanded.lstat() - except OSError as error: - raise BundleError(f"cannot recheck bundle input: {path}") from error - stable_fields = ("st_dev", "st_ino", "st_mode", "st_size", "st_mtime_ns") - if any(getattr(before, field) != getattr(after, field) for field in stable_fields): - raise BundleError(f"bundle input changed while it was hashed: {path}") - return { - "relative_path": None, - "size_bytes": before.st_size, - "sha256": digest, - } - - -def _reject_constant(value: str) -> None: - raise BundleError(f"non-finite JSON constant is forbidden: {value}") - - -def _reject_duplicate_keys(pairs: list[tuple[str, Any]]) -> dict[str, Any]: - result: dict[str, Any] = {} - for key, value in pairs: - if key in result: - raise BundleError(f"duplicate JSON key is forbidden: {key}") - result[key] = value - return result - - -def _checked_json(path: Path, *, label: str) -> dict[str, Any]: - expanded = path.expanduser().absolute() - try: - before = expanded.lstat() - except OSError as error: - raise BundleError(f"cannot inspect {label}") from error - if not stat.S_ISREG(before.st_mode) or expanded.is_symlink() or before.st_size <= 0: - raise BundleError(f"{label} is not a nonempty regular non-symlink file") - try: - encoded = expanded.read_bytes() - after = expanded.lstat() - except OSError as error: - raise BundleError(f"cannot read {label}") from error - stable_fields = ("st_dev", "st_ino", "st_mode", "st_size", "st_mtime_ns") - if any(getattr(before, field) != getattr(after, field) for field in stable_fields): - raise BundleError(f"{label} changed while it was read") - try: - payload = json.loads( - encoded, - parse_constant=_reject_constant, - object_pairs_hook=_reject_duplicate_keys, - ) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise BundleError(f"{label} is not strict JSON") from error - if not isinstance(payload, dict): - raise BundleError(f"{label} is not a JSON object") - return payload - - -def _git_output(root: Path, *arguments: str) -> str: - completed = subprocess.run( - ("git", *arguments), - cwd=root, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - raise BundleError(f"git inspection failed: {completed.stderr.strip()}") - return completed.stdout - - -def _write_json_atomic(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - temporary.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - - -def frozen_install_state_bytes() -> bytes: - return ( - json.dumps( - FROZEN_INSTALL_STATE, - indent=2, - sort_keys=True, - allow_nan=False, - ) - + "\n" - ).encode() - - -def frozen_cargo_config_bytes() -> bytes: - root = FROZEN_SOURCE_ROOT.as_posix() - return ( - "# Generated by dependencies/install_dependencies.py\n" - "[patch.crates-io]\n" - f'graphica = {{ path = "{root}/dependencies/checkouts/' - 'symbolica/lib/graphica" }\n' - f'numerica = {{ path = "{root}/dependencies/checkouts/' - 'symbolica/lib/numerica" }\n' - f'symbolica = {{ path = "{root}/dependencies/checkouts/symbolica" }}\n' - f'symjit = {{ path = "{root}/dependencies/checkouts/symjit" }}\n' - ).encode() - - -def _baseline_ignored_inventory(root: Path) -> dict[str, object]: - status = _git_output(root, "status", "--porcelain=v1", "--untracked-files=all") - if status: - raise BundleError("frozen baseline has tracked or unexpected source changes") - raw_ignored = _git_output( - root, - "ls-files", - "--others", - "--ignored", - "--exclude-standard", - "-z", - ) - ignored = sorted(path for path in raw_ignored.split("\0") if path) - unexpected = [ - path - for path in ignored - if path not in _BASELINE_GENERATED_FILES - and not any(path.startswith(prefix) for prefix in _BASELINE_BOOTSTRAP_ROOTS) - ] - if unexpected: - raise BundleError( - "frozen baseline has unexpected ignored source/bootstrap files: " - + ", ".join(unexpected[:20]) - ) - missing_generated = [ - relative - for relative in _BASELINE_GENERATED_FILES - if not (root / relative).is_file() - ] - missing_roots = [ - relative - for relative in _BASELINE_BOOTSTRAP_ROOTS - if not (root / relative).is_dir() - ] - if missing_generated or missing_roots: - raise BundleError( - "frozen baseline bootstrap is incomplete: " - f"files={missing_generated}, roots={missing_roots}" - ) - ignored_entries_by_bootstrap_root = { - relative.rstrip("/"): sum(path.startswith(relative) for path in ignored) - for relative in _BASELINE_BOOTSTRAP_ROOTS - } - return { - "tracked_and_untracked_status_clean": True, - "ignored_entry_count": len(ignored), - "ignored_relative_paths": ignored, - "ignored_paths_sha256": _canonical_sha256(ignored), - "ignored_entries_by_bootstrap_root": (ignored_entries_by_bootstrap_root), - "allowed_generated_files": list(_BASELINE_GENERATED_FILES), - "allowed_bootstrap_roots": list(_BASELINE_BOOTSTRAP_ROOTS), - "unexpected_ignored_files": [], - } - - -def _baseline_generated_identities(root: Path) -> dict[str, object]: - generated_files: dict[str, object] = {} - for relative in _BASELINE_GENERATED_FILES: - identity = _file_identity(root / relative) - identity["relative_path"] = relative - generated_files[relative] = identity - bootstrap_trees: dict[str, object] = {} - for relative in _BASELINE_BOOTSTRAP_ROOTS: - logical_path = relative.rstrip("/") - identity = regression._tree_identity(root / relative) - identity["relative_path"] = logical_path - bootstrap_trees[logical_path] = identity - return { - "generated_files": generated_files, - "bootstrap_trees": bootstrap_trees, - } - - -def freeze_baseline(source_root: Path) -> dict[str, object]: - root = source_root.expanduser().resolve(strict=True) - if hashlib.sha256(frozen_cargo_config_bytes()).hexdigest() != ( - FROZEN_CARGO_CONFIG_SHA256 - ): - raise BundleError("frozen cargo-config path contract is inconsistent") - if root != FROZEN_SOURCE_ROOT: - raise BundleError( - f"frozen baseline must use the path {FROZEN_SOURCE_ROOT}, got {root}" - ) - if _git_output(root, "rev-parse", "--verify", "HEAD").strip() != ( - matrix.FROZEN_BASELINE_SOURCE_REVISION - ): - raise BundleError("baseline checkout is not the frozen source revision") - ignored_inventory = _baseline_ignored_inventory(root) - dependencies = root / "dependencies" - lock = dependencies / "candidate-Cargo.lock" - config = dependencies / "candidate-cargo-config.toml" - state = dependencies / "install-state.json" - identities = { - "candidate_lock": _sha256_file(lock), - "cargo_config": _sha256_file(config), - } - if identities != { - "candidate_lock": FROZEN_CANDIDATE_LOCK_SHA256, - "cargo_config": FROZEN_CARGO_CONFIG_SHA256, - }: - raise BundleError(f"generated baseline dependency inputs differ: {identities}") - if state.is_file(): - try: - generated = json.loads(state.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise BundleError("generated baseline install state is invalid") from error - if not isinstance(generated, dict): - raise BundleError("generated baseline install state is not an object") - for key in ( - "candidate_lock_sha256", - "cargo_config_sha256", - "contributor_lock_sha256", - "patches", - "publishable", - "python_runtime_lock_sha256", - "release_lock_sha256", - "schema_version", - ): - if generated.get(key) != FROZEN_INSTALL_STATE[key]: - raise BundleError( - f"generated baseline state disagrees with frozen field {key}" - ) - generated_sources = generated.get("sources") - frozen_sources = FROZEN_INSTALL_STATE["sources"] - if not isinstance(generated_sources, Mapping) or not isinstance( - frozen_sources, Mapping - ): - raise BundleError("generated baseline source inventory is invalid") - for name, frozen in frozen_sources.items(): - if name == "legacy-amplicol" and name not in generated_sources: - continue - if generated_sources.get(name) != frozen: - raise BundleError( - f"generated baseline source {name} differs from the freeze" - ) - encoded = frozen_install_state_bytes() - if hashlib.sha256(encoded).hexdigest() != FROZEN_INSTALL_STATE_SHA256: - raise AssertionError("embedded frozen install state bytes changed") - temporary = state.with_name(f".{state.name}.tmp-{os.getpid()}") - temporary.write_bytes(encoded) - os.replace(temporary, state) - result = _attach_content_identity( - { - "kind": BASELINE_ATTESTATION_KIND, - "schema_version": SCHEMA_VERSION, - "source_root": str(root), - "source_revision": matrix.FROZEN_BASELINE_SOURCE_REVISION, - "native_build_inputs_sha256": (matrix.FROZEN_BASELINE_NATIVE_INPUTS_SHA256), - "candidate_lock_sha256": identities["candidate_lock"], - "cargo_config_sha256": identities["cargo_config"], - "install_state_sha256": _sha256_file(state), - "source_inventory": ignored_inventory, - "generated_identity": _baseline_generated_identities(root), - "passes": _sha256_file(state) == FROZEN_INSTALL_STATE_SHA256, - } - ) - if result["passes"] is not True or not _valid_baseline_attestation_payload(result): - raise BundleError("frozen install state could not be materialized exactly") - return result - - -def _stable_installation(identity: Mapping[str, Any]) -> dict[str, object]: - build_files = identity.get("build_info_files") - native_modules = identity.get("native_modules") - distribution = identity.get("distribution_content") - if ( - not isinstance(build_files, list) - or len(build_files) != 1 - or not isinstance(build_files[0], Mapping) - or not isinstance(build_files[0].get("payload"), Mapping) - or not isinstance(native_modules, list) - or len(native_modules) != 1 - or not isinstance(native_modules[0], Mapping) - or not isinstance(distribution, Mapping) - ): - raise BundleError("installed pyamplicol identity is incomplete") - payload = dict(build_files[0]["payload"]) - return { - "package_version": identity.get("package_version"), - "build_info": payload, - "build_info_sha256": build_files[0].get("sha256"), - "distribution_content": { - key: distribution.get(key) - for key in ("algorithm", "sha256", "file_count", "size_bytes") - }, - "native_module": { - key: native_modules[0].get(key) - for key in ("relative_path", "sha256", "size_bytes") - }, - } - - -def _installation(python: Path) -> dict[str, object]: - identity = regression._installed_pyamplicol_identity( - python.expanduser().resolve(strict=True), - environment=regression._environment(), - ) - return _stable_installation(identity) - - -def _stable_dependency_site(path: Path) -> dict[str, object]: - identity = regression._dependency_site_identity(path) - distributions = identity["distributions"] - return { - "algorithm": identity["algorithm"], - "sha256": identity["sha256"], - "distributions": { - name: { - key: record[key] - for key in ( - "name", - "version", - "algorithm", - "sha256", - "file_count", - "size_bytes", - ) - } - for name, record in sorted(distributions.items()) - }, - } - - -def _wheel_inventory(root: Path) -> dict[str, dict[str, object]]: - result: dict[str, dict[str, object]] = {} - wheels_root = root / "wheels" - if ( - not wheels_root.is_dir() - or wheels_root.is_symlink() - or {path.name for path in wheels_root.iterdir()} != {"baseline", "current"} - ): - raise BundleError("runtime bundle wheel lane inventory is not exact") - for lane in ("baseline", "current"): - lane_root = wheels_root / lane - entries = sorted(lane_root.iterdir(), key=lambda path: path.name) - candidates = [ - path - for path in entries - if path.suffix == ".whl" and path.is_file() and not path.is_symlink() - ] - if len(candidates) != 1 or entries != candidates: - raise BundleError( - f"runtime bundle requires exactly one file, the {lane} wheel" - ) - identity = _file_identity(candidates[0]) - identity["relative_path"] = candidates[0].relative_to(root).as_posix() - result[lane] = identity - return result - - -def _prepared_inventory(root: Path) -> dict[str, object]: - path = root / "prepared-models" / "ufo-sm-jit-o2.pyamplicol-model" - identity = _file_identity(path) - identity["relative_path"] = path.relative_to(root).as_posix() - return identity - - -def _nonnegative_integer(value: object) -> bool: - return isinstance(value, int) and not isinstance(value, bool) and value >= 0 - - -def _positive_integer(value: object) -> bool: - return _nonnegative_integer(value) and value > 0 - - -def _valid_ignored_relative_path(value: object) -> bool: - if not isinstance(value, str) or not value or "\\" in value: - return False - directory_marker = value.endswith("/") - path = value[:-1] if directory_marker else value - if not path: - return False - normalized = PurePosixPath(path) - expected = normalized.as_posix() + ("/" if directory_marker else "") - return ( - value == expected - and expected not in {".", "./"} - and not normalized.is_absolute() - and ".." not in normalized.parts - ) - - -def _valid_generated_file_identity( - value: object, - *, - relative_path: str, - expected_sha256: str, -) -> bool: - return ( - isinstance(value, Mapping) - and set(value) == {"relative_path", "size_bytes", "sha256"} - and value.get("relative_path") == relative_path - and _positive_integer(value.get("size_bytes")) - and value.get("sha256") == expected_sha256 - ) - - -def _valid_bootstrap_tree_identity( - value: object, - *, - relative_path: str, -) -> bool: - return ( - isinstance(value, Mapping) - and set(value) - == { - "algorithm", - "relative_path", - "sha256", - "file_count", - "size_bytes", - } - and value.get("algorithm") == "sha256-relative-path-size-content-v1" - and value.get("relative_path") == relative_path - and isinstance(value.get("sha256"), str) - and _SHA256.fullmatch(str(value.get("sha256"))) is not None - and _positive_integer(value.get("file_count")) - and _positive_integer(value.get("size_bytes")) - ) - - -def _valid_baseline_attestation_payload(payload: Mapping[str, object]) -> bool: - source_inventory = payload.get("source_inventory") - generated_identity = payload.get("generated_identity") - if ( - not isinstance(source_inventory, Mapping) - or set(source_inventory) - != { - "tracked_and_untracked_status_clean", - "ignored_entry_count", - "ignored_relative_paths", - "ignored_paths_sha256", - "ignored_entries_by_bootstrap_root", - "allowed_generated_files", - "allowed_bootstrap_roots", - "unexpected_ignored_files", - } - or source_inventory.get("tracked_and_untracked_status_clean") is not True - or source_inventory.get("allowed_generated_files") - != list(_BASELINE_GENERATED_FILES) - or source_inventory.get("allowed_bootstrap_roots") - != list(_BASELINE_BOOTSTRAP_ROOTS) - or source_inventory.get("unexpected_ignored_files") != [] - or not isinstance(generated_identity, Mapping) - or set(generated_identity) != {"generated_files", "bootstrap_trees"} - ): - return False - ignored_paths = source_inventory.get("ignored_relative_paths") - ignored_counts = source_inventory.get("ignored_entries_by_bootstrap_root") - bootstrap_paths = { - relative.rstrip("/"): relative for relative in _BASELINE_BOOTSTRAP_ROOTS - } - if ( - not isinstance(ignored_paths, list) - or not 0 < len(ignored_paths) <= _BASELINE_IGNORED_ENTRY_LIMIT - or any(not _valid_ignored_relative_path(path) for path in ignored_paths) - or ignored_paths != sorted(set(ignored_paths)) - or source_inventory.get("ignored_entry_count") != len(ignored_paths) - or source_inventory.get("ignored_paths_sha256") - != _canonical_sha256(ignored_paths) - or not isinstance(ignored_counts, Mapping) - or set(ignored_counts) != set(bootstrap_paths) - or any(not _nonnegative_integer(count) for count in ignored_counts.values()) - or any(relative not in ignored_paths for relative in _BASELINE_GENERATED_FILES) - or any( - path not in _BASELINE_GENERATED_FILES - and not any(path.startswith(prefix) for prefix in bootstrap_paths.values()) - for path in ignored_paths - ) - or any( - ignored_counts[logical] - != sum(path.startswith(prefix) for path in ignored_paths) - for logical, prefix in bootstrap_paths.items() - ) - or len(_BASELINE_GENERATED_FILES) + sum(ignored_counts.values()) - != len(ignored_paths) - ): - return False - generated_files = generated_identity.get("generated_files") - bootstrap_trees = generated_identity.get("bootstrap_trees") - expected_file_sha256 = { - "dependencies/candidate-Cargo.lock": FROZEN_CANDIDATE_LOCK_SHA256, - "dependencies/candidate-cargo-config.toml": FROZEN_CARGO_CONFIG_SHA256, - "dependencies/install-state.json": FROZEN_INSTALL_STATE_SHA256, - } - expected_bootstrap_paths = { - relative.rstrip("/") for relative in _BASELINE_BOOTSTRAP_ROOTS - } - return ( - isinstance(generated_files, Mapping) - and set(generated_files) == set(_BASELINE_GENERATED_FILES) - and all( - _valid_generated_file_identity( - generated_files.get(relative), - relative_path=relative, - expected_sha256=expected_file_sha256[relative], - ) - for relative in _BASELINE_GENERATED_FILES - ) - and isinstance(bootstrap_trees, Mapping) - and set(bootstrap_trees) == expected_bootstrap_paths - and all( - _valid_bootstrap_tree_identity( - bootstrap_trees.get(relative), - relative_path=relative, - ) - for relative in expected_bootstrap_paths - ) - ) - - -def _baseline_attestation_inventory(root: Path) -> dict[str, object]: - path = root / "frozen-baseline-attestation.json" - payload = _checked_json(path, label="frozen baseline source attestation") - _require_content_identity(payload) - if ( - set(payload) - != { - "kind", - "schema_version", - "source_root", - "source_revision", - "native_build_inputs_sha256", - "candidate_lock_sha256", - "cargo_config_sha256", - "install_state_sha256", - "source_inventory", - "generated_identity", - "passes", - "content_identity", - } - or payload.get("kind") != BASELINE_ATTESTATION_KIND - or payload.get("schema_version") != SCHEMA_VERSION - or payload.get("source_root") != str(FROZEN_SOURCE_ROOT) - or payload.get("source_revision") != matrix.FROZEN_BASELINE_SOURCE_REVISION - or payload.get("native_build_inputs_sha256") - != matrix.FROZEN_BASELINE_NATIVE_INPUTS_SHA256 - or payload.get("candidate_lock_sha256") != FROZEN_CANDIDATE_LOCK_SHA256 - or payload.get("cargo_config_sha256") != FROZEN_CARGO_CONFIG_SHA256 - or payload.get("install_state_sha256") != FROZEN_INSTALL_STATE_SHA256 - or not _valid_baseline_attestation_payload(payload) - or payload.get("passes") is not True - ): - raise BundleError("frozen baseline source attestation is invalid") - identity = _file_identity(path) - identity["relative_path"] = path.relative_to(root).as_posix() - return { - "file": identity, - "content_sha256": payload["content_identity"]["sha256"], - } - - -def create_manifest(arguments: argparse.Namespace) -> dict[str, object]: - if platform.system() != "Linux" or platform.machine() not in {"x86_64", "AMD64"}: - raise BundleError("x86 runtime bundle must be produced on Linux x86-64") - bundle_root = arguments.bundle_root.expanduser().resolve(strict=True) - baseline = _installation(arguments.baseline_python) - current = _installation(arguments.current_python) - for lane, identity, expected_source, expected_inputs in ( - ( - "baseline", - baseline, - matrix.FROZEN_BASELINE_SOURCE_REVISION, - matrix.FROZEN_BASELINE_NATIVE_INPUTS_SHA256, - ), - ( - "current", - current, - arguments.expected_current_revision, - arguments.expected_current_native_inputs_sha256, - ), - ): - build = identity["build_info"] - if ( - not isinstance(build, Mapping) - or build.get("source_revision") != expected_source - or build.get("native_build_inputs_sha256") != expected_inputs - or build.get("publishable") is not False - ): - raise BundleError(f"{lane} installed build identity is not exact") - payload = _attach_content_identity( - { - "kind": BUNDLE_KIND, - "schema_version": SCHEMA_VERSION, - "target": "x86_64-unknown-linux-gnu", - "workflow_run_id": arguments.workflow_run_id, - "expected_current_revision": arguments.expected_current_revision, - "installations": {"baseline": baseline, "current": current}, - "dependency_site": _stable_dependency_site(arguments.dependency_site), - "wheels": _wheel_inventory(bundle_root), - "prepared_models": {"ufo-sm": _prepared_inventory(bundle_root)}, - "frozen_baseline_source_attestation": ( - _baseline_attestation_inventory(bundle_root) - ), - "frozen_baseline": { - "source_root": str(FROZEN_SOURCE_ROOT), - "source_revision": matrix.FROZEN_BASELINE_SOURCE_REVISION, - "native_build_inputs_sha256": ( - matrix.FROZEN_BASELINE_NATIVE_INPUTS_SHA256 - ), - "candidate_lock_sha256": FROZEN_CANDIDATE_LOCK_SHA256, - "cargo_config_sha256": FROZEN_CARGO_CONFIG_SHA256, - "install_state_sha256": FROZEN_INSTALL_STATE_SHA256, - }, - "passes": True, - } - ) - _write_json_atomic(arguments.output, payload) - return payload - - -def _checked_manifest(path: Path) -> dict[str, Any]: - payload = _checked_json(path, label="runtime bundle manifest") - _require_content_identity(payload) - if ( - payload.get("kind") != BUNDLE_KIND - or payload.get("schema_version") != SCHEMA_VERSION - or payload.get("target") != "x86_64-unknown-linux-gnu" - or payload.get("passes") is not True - ): - raise BundleError("runtime bundle manifest contract is invalid") - return payload - - -def verify_manifest(arguments: argparse.Namespace) -> dict[str, object]: - payload = _checked_manifest(arguments.manifest) - if ( - payload.get("workflow_run_id") != arguments.workflow_run_id - or payload.get("expected_current_revision") - != arguments.expected_current_revision - ): - raise BundleError("runtime bundle workflow/source binding changed") - observed = { - "installations": { - "baseline": _installation(arguments.baseline_python), - "current": _installation(arguments.current_python), - }, - "dependency_site": _stable_dependency_site(arguments.dependency_site), - } - expected = { - "installations": payload.get("installations"), - "dependency_site": payload.get("dependency_site"), - } - if observed != expected: - raise BundleError("installed runtime/dependency identity differs from bundle") - bundle_root = arguments.bundle_root.expanduser().resolve(strict=True) - if _wheel_inventory(bundle_root) != payload.get("wheels") or { - "ufo-sm": _prepared_inventory(bundle_root) - } != payload.get("prepared_models"): - raise BundleError("runtime bundle files differ from their manifest") - if _baseline_attestation_inventory(bundle_root) != payload.get( - "frozen_baseline_source_attestation" - ): - raise BundleError("frozen baseline attestation differs from its manifest") - return { - "kind": "pyamplicol-x86-performance-runtime-bundle-verification", - "schema_version": 1, - "manifest_content_sha256": payload["content_identity"]["sha256"], - "passes": True, - } - - -def bundle_dependencies(source_site: Path, destination: Path) -> dict[str, object]: - source = source_site.expanduser().resolve(strict=True) - destination = destination.expanduser().absolute() - if destination.exists(): - if destination.is_symlink() or not destination.is_dir(): - raise BundleError("dependency bundle destination is unsafe") - if any(destination.iterdir()): - raise BundleError("dependency bundle destination must be empty") - else: - destination.mkdir(parents=True) - available = { - re.sub(r"[-_.]+", "-", str(dist.metadata.get("Name", ""))).casefold(): dist - for dist in importlib.metadata.distributions(path=[str(source)]) - } - for distribution_name, _import_name in regression.DEPENDENCY_DISTRIBUTIONS: - key = re.sub(r"[-_.]+", "-", distribution_name).casefold() - distribution = available.get(key) - if distribution is None: - raise BundleError(f"dependency site lacks {distribution_name}") - for entry in distribution.files or (): - relative = Path(str(entry)) - if ( - relative.is_absolute() - or ".." in relative.parts - or "__pycache__" in relative.parts - or relative.suffix == ".pyc" - ): - continue - source_file = (source / relative).resolve(strict=True) - source_file.relative_to(source) - if not source_file.is_file(): - continue - target = destination / relative - target.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(source_file, target) - source_identity = _stable_dependency_site(source) - destination_identity = _stable_dependency_site(destination) - if source_identity != destination_identity: - raise BundleError("copied dependency bundle identity changed") - return destination_identity - - -def _empty_external_directory(path: Path, *, label: str) -> Path: - destination = path.expanduser().absolute() - checkout = ROOT.resolve(strict=True) - if destination == Path(destination.anchor): - raise BundleError(f"{label} cannot be a filesystem root") - try: - destination.relative_to(checkout) - except ValueError: - pass - else: - raise BundleError(f"{label} must be outside the source checkout") - if destination.exists(): - if destination.is_symlink() or not destination.is_dir(): - raise BundleError(f"{label} is unsafe") - if any(destination.iterdir()): - raise BundleError(f"{label} must be empty") - else: - destination.mkdir(parents=True) - return destination - - -def _venv_python(root: Path) -> Path: - relative = Path("Scripts/python.exe") if os.name == "nt" else Path("bin/python") - return (root / relative).resolve(strict=True) - - -def _venv_purelib(python: Path) -> Path: - completed = subprocess.run( - ( - str(python), - "-c", - "import sysconfig; print(sysconfig.get_paths()['purelib'])", - ), - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - raise BundleError("cannot resolve materialized runtime site-packages") - try: - result = Path(completed.stdout.strip()).resolve(strict=True) - except OSError as error: - raise BundleError( - "materialized runtime site-packages is unavailable" - ) from error - if not result.is_dir(): - raise BundleError("materialized runtime site-packages is not a directory") - return result - - -def materialize_runtime( - bundle_root: Path, - runtime_root: Path, -) -> dict[str, object]: - """Rebuild the two fixed-path venvs from portable bundle members.""" - - bundle = bundle_root.expanduser().resolve(strict=True) - destination = _empty_external_directory( - runtime_root, - label="materialized runtime root", - ) - dependencies = (bundle / "dependency-site").resolve(strict=True) - if not dependencies.is_dir(): - raise BundleError("runtime bundle has no dependency site") - dependency_identity = _stable_dependency_site(dependencies) - wheels = _wheel_inventory(bundle) - lanes: dict[str, dict[str, object]] = {} - for lane in ("baseline", "current"): - lane_root = destination / lane - # A copied interpreter keeps ``resolve(strict=True)`` inside the lane; - # symlinked venv interpreters would collapse to the setup-python host - # executable and lose the selected site-packages identity. - venv.EnvBuilder(with_pip=True, symlinks=False).create(lane_root) - python = _venv_python(lane_root) - purelib = _venv_purelib(python) - for entry in sorted(dependencies.iterdir(), key=lambda path: path.name): - target = purelib / entry.name - if entry.is_dir(): - shutil.copytree(entry, target) - elif entry.is_file(): - shutil.copy2(entry, target) - else: - raise BundleError(f"dependency bundle member is unsafe: {entry}") - if _stable_dependency_site(purelib) != dependency_identity: - raise BundleError(f"{lane} materialized dependency identity changed") - wheel = bundle / str(wheels[lane]["relative_path"]) - environment = os.environ.copy() - environment.update( - { - "PIP_DISABLE_PIP_VERSION_CHECK": "1", - "PIP_NO_INDEX": "1", - "PYTHONDONTWRITEBYTECODE": "1", - } - ) - completed = subprocess.run( - ( - str(python), - "-m", - "pip", - "install", - "--no-compile", - "--no-deps", - str(wheel), - ), - check=False, - capture_output=True, - text=True, - env=environment, - ) - if completed.returncode != 0: - raise BundleError( - f"cannot install {lane} runtime wheel: {completed.stderr.strip()}" - ) - lanes[lane] = { - "python": str(python), - "site_packages": str(purelib), - "installation": _installation(python), - } - return { - "runtime_root": str(destination), - "dependency_site": str(dependencies), - "dependency_site_identity": dependency_identity, - "lanes": lanes, - "passes": True, - } - - -def prepare_ufo(output: Path, artifact_root: Path) -> dict[str, object]: - from tools.performance_report.artifacts import ArtifactStore - from tools.performance_report.prepared import ensure_report_ufo_sm_prepared_model - - store = ArtifactStore( - artifact_root=artifact_root.expanduser().absolute(), - lock_root=artifact_root.expanduser().absolute() / "locks", - ) - prepared, _reused = ensure_report_ufo_sm_prepared_model( - store=store, - repo_root=ROOT, - worker_cores=1, - ) - destination = output.expanduser().absolute() - destination.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(prepared, destination) - return _file_identity(destination) - - -def _sha256_argument(value: str) -> str: - if _SHA256.fullmatch(value) is None: - raise argparse.ArgumentTypeError("must be a lowercase SHA-256") - return value - - -def _git_sha_argument(value: str) -> str: - if _GIT_SHA.fullmatch(value) is None: - raise argparse.ArgumentTypeError("must be a lowercase Git SHA") - return value - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - commands = result.add_subparsers(dest="command", required=True) - frozen = commands.add_parser("freeze-baseline") - frozen.add_argument("--source-root", type=Path, required=True) - frozen.add_argument("--output", type=Path, required=True) - - dependencies = commands.add_parser("bundle-dependencies") - dependencies.add_argument("--source-site", type=Path, required=True) - dependencies.add_argument("--destination", type=Path, required=True) - - materialize = commands.add_parser("materialize") - materialize.add_argument("--bundle-root", type=Path, required=True) - materialize.add_argument("--runtime-root", type=Path, required=True) - - prepared = commands.add_parser("prepare-ufo") - prepared.add_argument("--output", type=Path, required=True) - prepared.add_argument("--artifact-root", type=Path, required=True) - - for name in ("create-manifest", "verify"): - command = commands.add_parser(name) - command.add_argument("--bundle-root", type=Path, required=True) - command.add_argument("--baseline-python", type=Path, required=True) - command.add_argument("--current-python", type=Path, required=True) - command.add_argument("--dependency-site", type=Path, required=True) - command.add_argument("--workflow-run-id", required=True) - command.add_argument( - "--expected-current-revision", - type=_git_sha_argument, - required=True, - ) - if name == "create-manifest": - command.add_argument( - "--expected-current-native-inputs-sha256", - type=_sha256_argument, - required=True, - ) - command.add_argument("--output", type=Path, required=True) - else: - command.add_argument("--manifest", type=Path, required=True) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - try: - if arguments.command == "freeze-baseline": - payload = freeze_baseline(arguments.source_root) - _write_json_atomic(arguments.output, payload) - elif arguments.command == "bundle-dependencies": - payload = bundle_dependencies( - arguments.source_site, - arguments.destination, - ) - elif arguments.command == "materialize": - payload = materialize_runtime( - arguments.bundle_root, - arguments.runtime_root, - ) - elif arguments.command == "prepare-ufo": - payload = prepare_ufo(arguments.output, arguments.artifact_root) - elif arguments.command == "create-manifest": - payload = create_manifest(arguments) - else: - payload = verify_manifest(arguments) - except (BundleError, OSError, regression.RegressionError) as error: - print(f"x86-performance-runtime-bundle: {error}", file=sys.stderr) - return 2 - print(json.dumps(payload, sort_keys=True, allow_nan=False)) - return 0 if payload.get("passes", True) is True else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/x86_portable_performance_acceptance.py b/pyamplicol/tools/developer/x86_portable_performance_acceptance.py deleted file mode 100644 index bae786f638..0000000000 --- a/pyamplicol/tools/developer/x86_portable_performance_acceptance.py +++ /dev/null @@ -1,645 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Combine x86 correctness, 168-cell matrix, and ``qq -> Z+6g`` evidence. - -The inputs are independently content-addressed artifacts from the same -dispatched source revision. The output intentionally contains no host-local -paths so it can be retained as the final portable candidate verdict. -""" - -from __future__ import annotations - -import argparse -import json -import math -import os -import re -import statistics -import sys -from collections.abc import Mapping, Sequence -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.developer import arena_native_x86_acceptance as native # noqa: E402 -from tools.developer import compiled_mode_matrix as matrix # noqa: E402 -from tools.developer import compiled_mode_matrix_x86 as matrix_x86 # noqa: E402 -from tools.developer import x86_qq_recurrence_acceptance as qq # noqa: E402 - -RESULT_KIND = "pyamplicol-x86-portable-candidate-acceptance" -SCHEMA_VERSION = 1 -CONTENT_IDENTITY_ALGORITHM = "sha256-canonical-json-body-v1" -_GIT_SHA = re.compile(r"[0-9a-f]{40}") -_SHA256 = re.compile(r"[0-9a-f]{64}") - - -class PortableAcceptanceError(RuntimeError): - """Raised when independently produced x86 evidence does not compose.""" - - -def _canonical_sha256(value: object) -> str: - return matrix_x86._canonical_sha256(value) - - -def _is_sha256(value: object) -> bool: - return isinstance(value, str) and _SHA256.fullmatch(value) is not None - - -def _positive_finite(value: object) -> bool: - return ( - isinstance(value, (int, float)) - and not isinstance(value, bool) - and math.isfinite(float(value)) - and float(value) > 0.0 - ) - - -def _seven_positive_values(value: object) -> list[float] | None: - if ( - not isinstance(value, list) - or len(value) != 7 - or not all(_positive_finite(item) for item in value) - ): - return None - return [float(item) for item in value] - - -def _attach_content_identity(body: Mapping[str, object]) -> dict[str, object]: - result = dict(body) - result["content_identity"] = { - "algorithm": CONTENT_IDENTITY_ALGORITHM, - "sha256": _canonical_sha256(body), - } - return result - - -def _write_json_atomic(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - temporary.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - - -def _require_content_identity( - payload: Mapping[str, object], - *, - label: str, -) -> str: - identity = payload.get("content_identity") - body = dict(payload) - body.pop("content_identity", None) - if ( - not isinstance(identity, Mapping) - or set(identity) != {"algorithm", "sha256"} - or identity.get("algorithm") != CONTENT_IDENTITY_ALGORITHM - or identity.get("sha256") != _canonical_sha256(body) - ): - raise PortableAcceptanceError(f"{label} content identity is invalid") - return str(identity["sha256"]) - - -def _portable_file_identity(identity: Mapping[str, object]) -> dict[str, object]: - return { - key: identity[key] - for key in ("size_bytes", "sha256", "canonical_sha256") - if key in identity - } - - -def _checked_input( - path: Path, - *, - label: str, -) -> tuple[dict[str, Any], dict[str, object], str]: - try: - payload, identity = matrix_x86._checked_json(path, label=label) - except matrix_x86.ShardError as error: - raise PortableAcceptanceError(str(error)) from error - digest = _require_content_identity(payload, label=label) - return payload, _portable_file_identity(identity), digest - - -def _audit_native( - payload: Mapping[str, Any], - *, - expected_revision: str, -) -> dict[str, object]: - request = payload.get("request") - source = payload.get("source_identity") - runtime = payload.get("runtime_identity") - evidence = payload.get("evidence") - validation = payload.get("validation") - if ( - payload.get("kind") != native.ACCEPTANCE_KIND - or payload.get("schema_version") != native.SCHEMA_VERSION - or payload.get("status") != "ok" - or payload.get("passes") is not True - or not isinstance(request, Mapping) - or request.get("expected_revision") != expected_revision - or request.get("expected_target") != native.EXPECTED_TARGET - or request.get("point_count") != native.EXPECTED_POINT_COUNT - or not isinstance(source, Mapping) - or source.get("all_match") is not True - or not isinstance(runtime, Mapping) - or runtime.get("all_match") is not True - or not isinstance(evidence, Mapping) - or set(evidence) - != { - "runtime_preflight", - "compiled_all_jit", - "four_quark", - "eager_compiled_color", - } - or not isinstance(validation, Mapping) - or not validation - or any(value is not True for value in validation.values()) - ): - raise PortableAcceptanceError("native correctness acceptance is incomplete") - for name, record in evidence.items(): - semantic = ( - record.get("semantic_validation") - if isinstance(record, Mapping) - else None - ) - if not isinstance(semantic, Mapping) or semantic.get("passes") is not True: - raise PortableAcceptanceError( - f"native correctness evidence {name} did not pass" - ) - audit_source = source.get("audit") - audit_runtime = runtime.get("audit") - active_build = ( - audit_runtime.get("active_build_info") - if isinstance(audit_runtime, Mapping) - else None - ) - build_payload = ( - active_build.get("payload") - if isinstance(active_build, Mapping) - else None - ) - native_extension = ( - audit_runtime.get("native_extension") - if isinstance(audit_runtime, Mapping) - else None - ) - native_build_inputs = ( - build_payload.get("native_build_inputs_sha256") - if isinstance(build_payload, Mapping) - else None - ) - native_module_sha256 = ( - native_extension.get("sha256") - if isinstance(native_extension, Mapping) - else None - ) - if ( - not isinstance(audit_source, Mapping) - or audit_source.get("revision") != expected_revision - or audit_source.get("dirty") is not False - or not isinstance(build_payload, Mapping) - or build_payload.get("source_revision") != expected_revision - or build_payload.get("publishable") is not False - or not isinstance(native_extension, Mapping) - or native_extension.get("target") != native.EXPECTED_TARGET - or native_extension.get("build_inputs_sha256") - != native_build_inputs - ): - raise PortableAcceptanceError("native correctness runtime/source drifted") - if not _is_sha256(native_build_inputs) or not _is_sha256(native_module_sha256): - raise PortableAcceptanceError( - "native correctness identity digests are invalid" - ) - return { - "target": native.EXPECTED_TARGET, - "point_count": native.EXPECTED_POINT_COUNT, - "native_build_inputs_sha256": native_build_inputs, - "native_module_sha256": native_module_sha256, - "required_evidence": sorted(evidence), - "passes": True, - } - - -def _audit_matrix( - payload: Mapping[str, Any], - *, - workflow_run_id: str, - expected_revision: str, -) -> dict[str, object]: - shard_gate = payload.get("shard_gate") - audit = payload.get("matrix_audit") - if ( - payload.get("kind") != matrix_x86.AGGREGATE_KIND - or payload.get("schema_version") != matrix_x86.SCHEMA_VERSION - or payload.get("matrix_contract") != matrix.MATRIX_CONTRACT - or payload.get("workflow_run_id") != workflow_run_id - or payload.get("expected_current_source_revision") != expected_revision - or payload.get("complete") is not True - or payload.get("passes") is not True - or not isinstance(shard_gate, Mapping) - or shard_gate.get("passes") is not True - or shard_gate.get("errors") != [] - or not isinstance(audit, Mapping) - or audit.get("complete") is not True - or audit.get("passes") is not True - ): - raise PortableAcceptanceError("168-cell matrix acceptance is incomplete") - coverage = audit.get("coverage") - cell_gate = audit.get("cell_gate") - identity_gate = audit.get("identity_gate") - gain_gate = audit.get("gain_gate") - generation_gate = audit.get("generation_gate") - if ( - not isinstance(coverage, Mapping) - or coverage.get("expected") != 168 - or coverage.get("observed") != 168 - or coverage.get("missing") != [] - or coverage.get("unexpected") != [] - or coverage.get("passes") is not True - or not all( - isinstance(gate, Mapping) and gate.get("passes") is True - for gate in (cell_gate, identity_gate, gain_gate, generation_gate) - ) - ): - raise PortableAcceptanceError("168-cell matrix gates are incomplete") - expected_builds = payload.get("expected_builds") - current = ( - expected_builds.get("current") - if isinstance(expected_builds, Mapping) - else None - ) - current_native_inputs = ( - current.get("native_build_inputs_sha256") - if isinstance(current, Mapping) - else None - ) - current_native_module = ( - current.get("native_module_sha256") - if isinstance(current, Mapping) - else None - ) - runtime_bundle_sha256 = payload.get("runtime_bundle_sha256") - if ( - not isinstance(current, Mapping) - or current.get("source_revision") != expected_revision - or not _is_sha256(current_native_inputs) - or not _is_sha256(current_native_module) - or not _is_sha256(runtime_bundle_sha256) - ): - raise PortableAcceptanceError("matrix current build identity drifted") - return { - "matrix_contract": matrix.MATRIX_CONTRACT, - "cell_count": 168, - "shard_count": matrix_x86.SHARD_COUNT, - "runtime_bundle_sha256": runtime_bundle_sha256, - "current_native_build_inputs_sha256": current_native_inputs, - "current_native_module_sha256": current_native_module, - "gain_gate": { - "required_relative_gain": gain_gate.get("required_relative_gain"), - "passes": True, - }, - "generation_gate": { - "maximum_geometric_mean": generation_gate.get( - "maximum_geometric_mean" - ), - "observed_geometric_mean": generation_gate.get( - "geometric_mean_current_over_baseline" - ), - "passes": True, - }, - "passes": True, - } - - -def _audit_qq( - payload: Mapping[str, Any], - *, - workflow_run_id: str, - expected_revision: str, -) -> dict[str, object]: - captures = payload.get("captures") - policy = payload.get("policy") - expected_policy = { - "required_capture_roles": list(qq.CAPTURE_CONTRACTS), - "required_modes": list(qq.REQUIRED_MODES), - "required_batch_sizes": list(qq.REQUIRED_BATCH_SIZES), - "performance_batch_sizes": list(qq.PERFORMANCE_BATCH_SIZES), - "minimum_target_runtime_seconds_per_worker": 5.0, - "subprocess_samples_per_cell": 7, - "native_wall_blocks_per_worker": 7, - "warmup_runs": 2, - "numerical_validation_samples": 10, - "compiled_over_recurrence_ratio_ceiling": ( - qq.COMPILED_RECURRENCE_RATIO_CEILING - ), - "ratio_gate": "median-plus-three-raw-mad-at-or-below-ceiling-v1", - "diagnostic_shortcuts_allowed": False, - } - if ( - payload.get("kind") != qq.RESULT_KIND - or payload.get("schema_version") != qq.SCHEMA_VERSION - or payload.get("workflow_run_id") != workflow_run_id - or payload.get("target") != native.EXPECTED_TARGET - or payload.get("expected_current_revision") != expected_revision - or payload.get("performance_cell_count") != 8 - or payload.get("passes") is not True - or not isinstance(captures, Mapping) - or set(captures) != set(qq.CAPTURE_CONTRACTS) - or policy != expected_policy - ): - raise PortableAcceptanceError("qq Z+6g acceptance is incomplete") - cell_count = 0 - maximum_upper = 0.0 - for role, capture in captures.items(): - contract = qq.CAPTURE_CONTRACTS[role] - cells = ( - capture.get("performance_cells") - if isinstance(capture, Mapping) - else None - ) - numerical = ( - capture.get("numerical_validation") - if isinstance(capture, Mapping) - else None - ) - if ( - not isinstance(capture, Mapping) - or capture.get("passes") is not True - or capture.get("source_revision") != expected_revision - or not _is_sha256(capture.get("runtime_provenance_sha256")) - or capture.get("layout") != contract["layout"] - or capture.get("workload") != contract["workload"] - or not isinstance(capture.get("model"), Mapping) - or capture["model"].get("kind") != contract["model"] - or not isinstance(numerical, Mapping) - or numerical.get("contract") - != "recomputed-recurrence-z6g-pairwise-and-resolved-v1" - or numerical.get("passes") is not True - or not isinstance(cells, list) - or len(cells) != 2 - ): - raise PortableAcceptanceError(f"qq Z+6g capture {role} is incomplete") - batches = [ - cell.get("batch_size") if isinstance(cell, Mapping) else None - for cell in cells - ] - if ( - any( - isinstance(batch, bool) or not isinstance(batch, int) - for batch in batches - ) - or len(set(batches)) != len(batches) - or set(batches) != set(qq.PERFORMANCE_BATCH_SIZES) - ): - raise PortableAcceptanceError( - f"qq Z+6g capture {role} batch coverage is incomplete" - ) - for cell in cells: - statistics_record = ( - cell.get("ratio_statistics") - if isinstance(cell, Mapping) - else None - ) - upper = ( - statistics_record.get("upper_three_raw_mad") - if isinstance(statistics_record, Mapping) - else None - ) - compiled = _seven_positive_values( - cell.get("compiled_wall_seconds_per_point_by_round") - if isinstance(cell, Mapping) - else None - ) - recurrence = _seven_positive_values( - cell.get("recurrence_wall_seconds_per_point_by_round") - if isinstance(cell, Mapping) - else None - ) - ratios = _seven_positive_values( - cell.get("compiled_over_recurrence_ratios_by_round") - if isinstance(cell, Mapping) - else None - ) - if ( - not isinstance(cell, Mapping) - or cell.get("passes") is not True - or cell.get("sample_count") != 7 - or cell.get("batch_size") not in qq.PERFORMANCE_BATCH_SIZES - or cell.get("pairing") != "same-interleaved-schedule-round-v1" - or cell.get("ceiling") - != qq.COMPILED_RECURRENCE_RATIO_CEILING - or compiled is None - or recurrence is None - or ratios is None - or not isinstance(statistics_record, Mapping) - or statistics_record.get("contract") != "median-and-raw-mad-v1" - or not _positive_finite(statistics_record.get("median")) - or not _positive_finite(statistics_record.get("raw_mad")) - or not _positive_finite(upper) - or float(upper) > qq.COMPILED_RECURRENCE_RATIO_CEILING - ): - raise PortableAcceptanceError( - f"qq Z+6g capture {role} performance gate failed" - ) - recomputed_ratios = [ - compiled_value / recurrence_value - for compiled_value, recurrence_value in zip( - compiled, - recurrence, - strict=True, - ) - ] - median = statistics.median(recomputed_ratios) - raw_mad = statistics.median( - abs(value - median) for value in recomputed_ratios - ) - recomputed_upper = median + 3.0 * raw_mad - if ( - any( - not math.isclose( - observed, - expected, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - for observed, expected in zip( - ratios, - recomputed_ratios, - strict=True, - ) - ) - or not math.isclose( - float(statistics_record["median"]), - median, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - or not math.isclose( - float(statistics_record["raw_mad"]), - raw_mad, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - or not math.isclose( - float(upper), - recomputed_upper, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - ): - raise PortableAcceptanceError( - f"qq Z+6g capture {role} ratio evidence changed" - ) - cell_count += 1 - maximum_upper = max(maximum_upper, float(upper)) - runtime_bundle = payload.get("runtime_bundle") - if not isinstance(runtime_bundle, Mapping): - raise PortableAcceptanceError("qq Z+6g runtime bundle identity is absent") - runtime_bundle_sha256 = runtime_bundle.get("content_sha256") - if not _is_sha256(runtime_bundle_sha256): - raise PortableAcceptanceError("qq Z+6g runtime bundle digest is absent") - return { - "capture_count": len(captures), - "performance_cell_count": cell_count, - "runtime_bundle_sha256": runtime_bundle_sha256, - "compiled_over_recurrence_ratio_ceiling": ( - qq.COMPILED_RECURRENCE_RATIO_CEILING - ), - "maximum_observed_upper_three_raw_mad": maximum_upper, - "numerical_validation": True, - "passes": True, - } - - -def audit( - *, - native_acceptance: Path, - matrix_acceptance: Path, - qq_acceptance: Path, - workflow_run_id: str, - expected_revision: str, -) -> dict[str, object]: - native_payload, native_file, native_digest = _checked_input( - native_acceptance, - label="native x86 correctness acceptance", - ) - matrix_payload, matrix_file, matrix_digest = _checked_input( - matrix_acceptance, - label="x86 168-cell matrix acceptance", - ) - qq_payload, qq_file, qq_digest = _checked_input( - qq_acceptance, - label="x86 qq Z+6g acceptance", - ) - native_summary = _audit_native( - native_payload, - expected_revision=expected_revision, - ) - matrix_summary = _audit_matrix( - matrix_payload, - workflow_run_id=workflow_run_id, - expected_revision=expected_revision, - ) - qq_summary = _audit_qq( - qq_payload, - workflow_run_id=workflow_run_id, - expected_revision=expected_revision, - ) - if ( - native_summary["native_build_inputs_sha256"] - != matrix_summary["current_native_build_inputs_sha256"] - ): - raise PortableAcceptanceError( - "correctness and performance used different native build inputs" - ) - if ( - native_summary["native_module_sha256"] - != matrix_summary["current_native_module_sha256"] - ): - raise PortableAcceptanceError( - "correctness and performance used different native modules" - ) - if ( - matrix_summary["runtime_bundle_sha256"] - != qq_summary["runtime_bundle_sha256"] - ): - raise PortableAcceptanceError( - "matrix and qq evidence used different runtime bundles" - ) - return _attach_content_identity( - { - "kind": RESULT_KIND, - "schema_version": SCHEMA_VERSION, - "workflow_run_id": workflow_run_id, - "source_revision": expected_revision, - "target": native.EXPECTED_TARGET, - "inputs": { - "native_correctness": { - "file": native_file, - "content_sha256": native_digest, - }, - "compiled_eager_matrix": { - "file": matrix_file, - "content_sha256": matrix_digest, - }, - "qq_z6g_recurrence": { - "file": qq_file, - "content_sha256": qq_digest, - }, - }, - "correctness": native_summary, - "compiled_eager_matrix": matrix_summary, - "qq_z6g_recurrence": qq_summary, - "bindings": { - "same_source_revision": True, - "same_native_build_inputs": True, - "same_native_module": True, - "same_performance_runtime_bundle": True, - }, - "passes": True, - } - ) - - -def _git_sha(value: str) -> str: - if _GIT_SHA.fullmatch(value) is None: - raise argparse.ArgumentTypeError("must be a lowercase 40-character Git SHA") - return value - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - result.add_argument("--native-acceptance", type=Path, required=True) - result.add_argument("--matrix-acceptance", type=Path, required=True) - result.add_argument("--qq-acceptance", type=Path, required=True) - result.add_argument("--workflow-run-id", required=True) - result.add_argument("--expected-revision", type=_git_sha, required=True) - result.add_argument("--output", type=Path, required=True) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - try: - result = audit( - native_acceptance=arguments.native_acceptance, - matrix_acceptance=arguments.matrix_acceptance, - qq_acceptance=arguments.qq_acceptance, - workflow_run_id=arguments.workflow_run_id, - expected_revision=arguments.expected_revision, - ) - _write_json_atomic(arguments.output, result) - except (OSError, PortableAcceptanceError) as error: - print(f"x86-portable-performance-acceptance: {error}", file=sys.stderr) - return 2 - print(json.dumps(result, sort_keys=True, allow_nan=False)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/developer/x86_qq_recurrence_acceptance.py b/pyamplicol/tools/developer/x86_qq_recurrence_acceptance.py deleted file mode 100644 index 07d243b9f5..0000000000 --- a/pyamplicol/tools/developer/x86_qq_recurrence_acceptance.py +++ /dev/null @@ -1,767 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Audit the four authoritative x86 ``qq -> Z+6g`` recurrence captures. - -This command deliberately consumes the complete three-lane output from -``recurrence_z6g_benchmark.py``. It does not provide a shorter diagnostic -profiling path. Every stored validation, artifact-semantic, worker, timing, -and interleaving contract is recomputed before the compiled/recurrence -performance ratios are considered. -""" - -from __future__ import annotations - -import argparse -import json -import math -import os -import re -import statistics -import sys -from collections.abc import Mapping, Sequence -from pathlib import Path -from types import SimpleNamespace -from typing import Any - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -from tools.developer import ( # noqa: E402 - compiled_mode_matrix_x86 as shard_io, -) -from tools.developer import ( # noqa: E402 - recurrence_z6g_benchmark as benchmark, -) -from tools.developer import ( # noqa: E402 - x86_performance_runtime_bundle as runtime_bundle, -) - -RESULT_KIND = "pyamplicol-x86-qq-z6g-recurrence-acceptance" -SCHEMA_VERSION = 1 -CONTENT_IDENTITY_ALGORITHM = "sha256-canonical-json-body-v1" -COMPILED_RECURRENCE_RATIO_CEILING = 1.15 -PERFORMANCE_BATCH_SIZES = (128, 1024) -REQUIRED_BATCH_SIZES = tuple(benchmark.DEFAULT_BATCH_SIZES) -REQUIRED_MODES = tuple(benchmark.EXECUTION_MODES) -TOPOLOGY_FLOW_ID = "flow:2,4,5,6,7,8,9,1" -UNION_HELICITY_ID = "h:-1,+1,-1,+1,-1,+1,-1,+1,-1" -_GIT_SHA = re.compile(r"[0-9a-f]{40}") - -CAPTURE_CONTRACTS: dict[str, dict[str, object]] = { - "builtin-topology": { - "model": "builtin", - "layout": "topology-replay", - "color_flow": TOPOLOGY_FLOW_ID, - "helicity": "1", - "workload": "single-runtime-selected-flow/helicity-sum", - }, - "builtin-union": { - "model": "builtin", - "layout": "all-flow-union", - "color_flow": "1", - "helicity": UNION_HELICITY_ID, - "workload": "all-flows/runtime-selected-single-helicity", - }, - "ufo-topology": { - "model": "ufo", - "layout": "topology-replay", - "color_flow": TOPOLOGY_FLOW_ID, - "helicity": "1", - "workload": "single-runtime-selected-flow/helicity-sum", - }, - "ufo-union": { - "model": "ufo", - "layout": "all-flow-union", - "color_flow": "1", - "helicity": UNION_HELICITY_ID, - "workload": "all-flows/runtime-selected-single-helicity", - }, -} - - -class AcceptanceError(RuntimeError): - """Raised when capture provenance or structure cannot be authenticated.""" - - -def _canonical_sha256(value: object) -> str: - return shard_io._canonical_sha256(value) - - -def _attach_content_identity(body: Mapping[str, object]) -> dict[str, object]: - result = dict(body) - result["content_identity"] = { - "algorithm": CONTENT_IDENTITY_ALGORITHM, - "sha256": _canonical_sha256(body), - } - return result - - -def _write_json_atomic(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{os.getpid()}") - temporary.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="utf-8", - ) - os.replace(temporary, path) - - -def _exact_int(value: object, expected: int) -> bool: - return not isinstance(value, bool) and isinstance(value, int) and value == expected - - -def _positive_number(value: object) -> bool: - return ( - not isinstance(value, bool) - and isinstance(value, (int, float)) - and math.isfinite(float(value)) - and float(value) > 0.0 - ) - - -def _configuration_namespace(configuration: Mapping[str, object]) -> SimpleNamespace: - """Reconstruct only the arguments used by the harness acceptance functions.""" - - return SimpleNamespace( - batch_size=configuration.get("batch_sizes"), - color_flow=configuration.get("color_flow_request"), - generation_only=configuration.get("generation_only"), - gluon_count=configuration.get("gluon_count"), - helicity=configuration.get("helicity_request"), - jit_optimization_level=configuration.get("jit_optimization_level"), - lc_flow_layout=configuration.get("lc_flow_layout"), - minimum_samples=configuration.get("minimum_samples"), - modes=configuration.get("modes"), - process_expression=None, - specialize_flow_at_generation=configuration.get( - "specialize_flow_at_generation" - ), - subprocess_samples=configuration.get("subprocess_samples"), - target_runtime=configuration.get("target_runtime_seconds"), - warmup_runs=configuration.get("warmup_runs"), - ) - - -def _recompute_harness_contracts(payload: Mapping[str, Any]) -> None: - """Re-run the authoritative harness validators over retained evidence.""" - - configuration = payload.get("configuration") - profiles = payload.get("profiles") - schedule = payload.get("profile_schedule") - stored_validation = payload.get("validation_summary") - stored_capture = payload.get("capture_acceptance") - stored_milestone = payload.get("milestone0_acceptance") - if ( - not isinstance(configuration, Mapping) - or not isinstance(profiles, Mapping) - or not isinstance(schedule, Mapping) - or not isinstance(stored_validation, Mapping) - or not isinstance(stored_capture, Mapping) - or not isinstance(stored_milestone, Mapping) - ): - raise AcceptanceError("capture lacks complete harness evidence") - arguments = _configuration_namespace(configuration) - try: - validation = benchmark._pairwise_profile_validation(profiles) - capture = benchmark._capture_acceptance( - arguments, - profiles, - validation, - profile_schedule=schedule, - ) - milestone = benchmark._milestone0_acceptance_manifest(arguments, capture) - except ( - AttributeError, - KeyError, - TypeError, - ValueError, - benchmark.HarnessError, - ) as error: - raise AcceptanceError("capture evidence cannot be revalidated") from error - if validation != stored_validation: - raise AcceptanceError("stored numerical validation is not reproducible") - if capture != stored_capture: - raise AcceptanceError("stored capture acceptance is not reproducible") - if milestone != stored_milestone: - raise AcceptanceError("stored milestone evidence is not reproducible") - if ( - capture.get("complete") is not True - or capture.get("evidence_complete") is not True - or capture.get("passes") is not True - or capture.get("authoritative_eligible") is not True - or capture.get("authoritative_ineligibility_reasons") != [] - or capture.get("generation_specialized_axes_by_mode") != {} - or capture.get("incomplete_physical_axes") != [] - or validation.get("passes") is not True - ): - raise AcceptanceError("capture is not complete authoritative passing evidence") - - -def _validate_configuration( - payload: Mapping[str, Any], - *, - role: str, -) -> Mapping[str, Any]: - configuration = payload.get("configuration") - contract = CAPTURE_CONTRACTS[role] - if not isinstance(configuration, Mapping): - raise AcceptanceError(f"{role} has no configuration") - if ( - configuration.get("modes") != list(REQUIRED_MODES) - or configuration.get("batch_sizes") != list(REQUIRED_BATCH_SIZES) - or configuration.get("lc_flow_layout") != contract["layout"] - or configuration.get("color_flow_request") != contract["color_flow"] - or configuration.get("helicity_request") != contract["helicity"] - or not _exact_int(configuration.get("gluon_count"), 6) - or not _exact_int(configuration.get("jit_optimization_level"), 3) - or not _exact_int(configuration.get("minimum_samples"), 7) - or not _exact_int(configuration.get("subprocess_samples"), 7) - or not _exact_int(configuration.get("warmup_runs"), 2) - or not _exact_int(configuration.get("point_tile_size"), 1024) - or not _exact_int(configuration.get("validation_samples"), 10) - or not _positive_number(configuration.get("target_runtime_seconds")) - or float(configuration["target_runtime_seconds"]) < 5.0 - or configuration.get("generation_only") is not False - or configuration.get("allow_diagnostic_incomplete_success") is not False - or configuration.get("specialize_flow_at_generation") is not False - or configuration.get("external_watchdog_required_for_long_runs") is not True - ): - raise AcceptanceError(f"{role} does not use the authoritative benchmark policy") - if ( - payload.get("process") != "u u~ > Z g g g g g g" - or payload.get("process_name") != "uubar_Z_6g" - or payload.get("workload") != contract["workload"] - ): - raise AcceptanceError(f"{role} process/workload identity is wrong") - return configuration - - -def _stable_capture_installation(runtime: Mapping[str, Any]) -> dict[str, object]: - active = runtime.get("active_build_info") - distribution = runtime.get("installed_distribution") - native = runtime.get("native_extension") - if ( - not isinstance(active, Mapping) - or not isinstance(active.get("payload"), Mapping) - or not isinstance(distribution, Mapping) - or not isinstance(native, Mapping) - ): - raise AcceptanceError("capture runtime identity is incomplete") - build_files = distribution.get("build_info_files") - native_modules = distribution.get("native_modules") - content = distribution.get("distribution_content") - if ( - not isinstance(build_files, list) - or len(build_files) != 1 - or not isinstance(build_files[0], Mapping) - or not isinstance(native_modules, list) - or len(native_modules) != 1 - or not isinstance(native_modules[0], Mapping) - or not isinstance(content, Mapping) - ): - raise AcceptanceError("capture installed-distribution identity is incomplete") - return { - "package_version": distribution.get("package_version"), - "build_info": dict(active["payload"]), - "build_info_sha256": active.get("sha256"), - "distribution_content": { - key: content.get(key) - for key in ("algorithm", "sha256", "file_count", "size_bytes") - }, - "native_module": { - key: native_modules[0].get(key) - for key in ("relative_path", "sha256", "size_bytes") - }, - "native_runtime": { - "sha256": native.get("sha256"), - "size_bytes": native.get("size_bytes"), - "build_inputs_sha256": native.get("build_inputs_sha256"), - "package_version": native.get("package_version"), - }, - "distribution_build_info_sha256": build_files[0].get("sha256"), - } - - -def _validate_runtime( - payload: Mapping[str, Any], - *, - role: str, - expected_revision: str, - bundle: Mapping[str, Any], -) -> str: - source = payload.get("source") - runtime = payload.get("runtime_provenance") - provenance = payload.get("provenance") - host = ( - provenance.get("host") - if isinstance(provenance, Mapping) - else None - ) - if ( - not isinstance(source, Mapping) - or source.get("revision") != expected_revision - or source.get("dirty") is not False - or source.get("untracked_files_checked") is not True - or not isinstance(runtime, Mapping) - or not isinstance(host, Mapping) - or host.get("system") != "Linux" - or host.get("machine") not in {"x86_64", "AMD64"} - ): - raise AcceptanceError(f"{role} was not measured from exact clean x86 source") - installations = bundle.get("installations") - current = ( - installations.get("current") - if isinstance(installations, Mapping) - else None - ) - if not isinstance(current, Mapping): - raise AcceptanceError("runtime bundle has no current installation identity") - observed = _stable_capture_installation(runtime) - expected_native = current.get("native_module") - expected_build = current.get("build_info") - if ( - observed.get("package_version") != current.get("package_version") - or observed.get("build_info") != expected_build - or observed.get("build_info_sha256") != current.get("build_info_sha256") - or observed.get("distribution_build_info_sha256") - != current.get("build_info_sha256") - or observed.get("distribution_content") - != current.get("distribution_content") - or observed.get("native_module") != expected_native - or not isinstance(expected_build, Mapping) - or not isinstance(expected_native, Mapping) - or observed["native_runtime"].get("sha256") - != expected_native.get("sha256") - or observed["native_runtime"].get("size_bytes") - != expected_native.get("size_bytes") - or observed["native_runtime"].get("build_inputs_sha256") - != expected_build.get("native_build_inputs_sha256") - ): - raise AcceptanceError(f"{role} runtime does not match the frozen bundle") - return _canonical_sha256(runtime) - - -def _validate_model( - configuration: Mapping[str, Any], - *, - role: str, - expected_revision: str, - bundle: Mapping[str, Any], -) -> dict[str, object]: - identities = configuration.get("model_identities") - if not isinstance(identities, Mapping) or set(identities) != set(REQUIRED_MODES): - raise AcceptanceError(f"{role} has an incomplete model identity inventory") - model_kind = CAPTURE_CONTRACTS[role]["model"] - if model_kind == "builtin": - if configuration.get("prepared_model_path") is not None: - raise AcceptanceError(f"{role} unexpectedly uses an explicit model") - compiled = identities.get("compiled") - if ( - not isinstance(compiled, Mapping) - or compiled - != { - "kind": "built-in-sm-source", - "resource_id": None, - "source_revision": expected_revision, - "compile_excluded_from_generation": False, - } - ): - raise AcceptanceError(f"{role} compiled lane is not built-in source") - packaged: dict[str, object] | None = None - for mode in ("eager", "recurrence"): - identity = identities.get(mode) - if ( - not isinstance(identity, Mapping) - or identity.get("kind") != "packaged-prepared-model" - or identity.get("resource_id") != benchmark.PREPARED_MODEL_ID - or identity.get("compile_excluded_from_generation") is not True - or not _positive_number(identity.get("size_bytes")) - or not isinstance(identity.get("sha256"), str) - ): - raise AcceptanceError(f"{role} {mode} model identity is invalid") - stable = { - key: identity.get(key) - for key in ( - "kind", - "resource_id", - "size_bytes", - "sha256", - "compile_excluded_from_generation", - ) - } - if packaged is None: - packaged = stable - elif stable != packaged: - raise AcceptanceError(f"{role} packaged model identities differ") - assert packaged is not None - return {"kind": "builtin", "packaged_prepared_model": packaged} - if not isinstance(configuration.get("prepared_model_path"), str): - raise AcceptanceError(f"{role} has no explicit UFO prepared model") - prepared_models = bundle.get("prepared_models") - expected_file = ( - prepared_models.get("ufo-sm") - if isinstance(prepared_models, Mapping) - else None - ) - if not isinstance(expected_file, Mapping): - raise AcceptanceError("runtime bundle has no UFO prepared-model identity") - stable_explicit: dict[str, object] | None = None - for mode in REQUIRED_MODES: - identity = identities.get(mode) - file_identity = identity.get("file") if isinstance(identity, Mapping) else None - if ( - not isinstance(identity, Mapping) - or identity.get("kind") != "explicit-prepared-model" - or identity.get("resource_id") is not None - or identity.get("compile_excluded_from_generation") is not True - or not isinstance(file_identity, Mapping) - or file_identity.get("sha256") != expected_file.get("sha256") - or file_identity.get("size_bytes") != expected_file.get("size_bytes") - ): - raise AcceptanceError(f"{role} {mode} UFO model identity is invalid") - stable = { - "kind": identity.get("kind"), - "resource_id": identity.get("resource_id"), - "compile_excluded_from_generation": identity.get( - "compile_excluded_from_generation" - ), - "file": { - "sha256": file_identity.get("sha256"), - "size_bytes": file_identity.get("size_bytes"), - }, - } - if stable_explicit is None: - stable_explicit = stable - elif stable != stable_explicit: - raise AcceptanceError(f"{role} explicit model identities differ") - assert stable_explicit is not None - return {"kind": "ufo", "prepared_model": stable_explicit} - - -def _profile_for_batch( - payload: Mapping[str, Any], - *, - mode: str, - batch_size: int, -) -> Mapping[str, Any]: - profiles = payload.get("profiles") - lane = profiles.get(mode) if isinstance(profiles, Mapping) else None - measurements = lane.get("profiles") if isinstance(lane, Mapping) else None - if not isinstance(measurements, list): - raise AcceptanceError(f"{mode} profile inventory is missing") - matches = [ - measurement - for measurement in measurements - if isinstance(measurement, Mapping) - and measurement.get("batch_size") == batch_size - ] - if len(matches) != 1: - raise AcceptanceError(f"{mode} batch {batch_size} is not unique") - return matches[0] - - -def _paired_cell_evidence( - payload: Mapping[str, Any], - *, - batch_size: int, - ceiling: float, -) -> dict[str, object]: - by_mode: dict[str, dict[int, float]] = {} - for mode in ("compiled", "recurrence"): - measurement = _profile_for_batch( - payload, - mode=mode, - batch_size=batch_size, - ) - samples = measurement.get("subprocess_samples") - if ( - measurement.get("interrupted") is not False - or not _exact_int(measurement.get("sample_count"), 7) - or not _exact_int(measurement.get("subprocess_sample_count"), 7) - or measurement.get("statistics_contract") - != "subprocess-median-and-raw-mad-v1" - or not isinstance(samples, list) - or len(samples) != 7 - ): - raise AcceptanceError( - f"{mode} batch {batch_size} is not seven-sample evidence" - ) - rounds: dict[int, float] = {} - for sample in samples: - round_index = sample.get("round") if isinstance(sample, Mapping) else None - wall = ( - sample.get("wall_seconds_per_point") - if isinstance(sample, Mapping) - else None - ) - if ( - isinstance(round_index, bool) - or not isinstance(round_index, int) - or round_index < 0 - or round_index >= 7 - or round_index in rounds - or not _positive_number(wall) - ): - raise AcceptanceError( - f"{mode} batch {batch_size} has invalid paired samples" - ) - rounds[round_index] = float(wall) - if set(rounds) != set(range(7)): - raise AcceptanceError( - f"{mode} batch {batch_size} does not cover seven rounds" - ) - values = list(rounds.values()) - observed_median = statistics.median(values) - observed_mad = statistics.median( - abs(value - observed_median) for value in values - ) - if ( - not math.isclose( - float(measurement.get("wall_seconds_per_point_median", math.nan)), - observed_median, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - or not math.isclose( - float(measurement.get("wall_seconds_per_point_mad", math.nan)), - observed_mad, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - ): - raise AcceptanceError( - f"{mode} batch {batch_size} headline statistics changed" - ) - by_mode[mode] = rounds - ratios = [ - by_mode["compiled"][round_index] / by_mode["recurrence"][round_index] - for round_index in range(7) - ] - ratio_median = statistics.median(ratios) - ratio_mad = statistics.median(abs(value - ratio_median) for value in ratios) - upper = ratio_median + 3.0 * ratio_mad - passes = ( - math.isfinite(ratio_median) - and ratio_median >= 0.0 - and math.isfinite(ratio_mad) - and ratio_mad >= 0.0 - and math.isfinite(upper) - and upper >= 0.0 - and ratio_median <= ceiling - and upper <= ceiling - ) - return { - "batch_size": batch_size, - "pairing": "same-interleaved-schedule-round-v1", - "sample_count": len(ratios), - "compiled_wall_seconds_per_point_by_round": [ - by_mode["compiled"][index] for index in range(7) - ], - "recurrence_wall_seconds_per_point_by_round": [ - by_mode["recurrence"][index] for index in range(7) - ], - "compiled_over_recurrence_ratios_by_round": ratios, - "ratio_statistics": { - "contract": "median-and-raw-mad-v1", - "median": ratio_median, - "raw_mad": ratio_mad, - "upper_three_raw_mad": upper, - }, - "ceiling": ceiling, - "passes": passes, - } - - -def _checked_bundle( - path: Path, - *, - workflow_run_id: str, - expected_revision: str, -) -> tuple[dict[str, Any], dict[str, object]]: - payload, file_identity = shard_io._checked_json( - path, - label="x86 runtime bundle manifest", - ) - try: - runtime_bundle._require_content_identity(payload) - except runtime_bundle.BundleError as error: - raise AcceptanceError("runtime bundle content identity is invalid") from error - if ( - payload.get("kind") != runtime_bundle.BUNDLE_KIND - or payload.get("schema_version") != runtime_bundle.SCHEMA_VERSION - or payload.get("target") != "x86_64-unknown-linux-gnu" - or payload.get("workflow_run_id") != workflow_run_id - or payload.get("expected_current_revision") != expected_revision - or payload.get("passes") is not True - ): - raise AcceptanceError("runtime bundle is not bound to this workflow/source") - return payload, file_identity - - -def audit( - *, - capture_paths: Mapping[str, Path], - runtime_bundle_manifest: Path, - workflow_run_id: str, - expected_current_revision: str, - ratio_ceiling: float = COMPILED_RECURRENCE_RATIO_CEILING, -) -> dict[str, object]: - if set(capture_paths) != set(CAPTURE_CONTRACTS): - raise AcceptanceError("exactly the four canonical capture roles are required") - if not _positive_number(ratio_ceiling): - raise AcceptanceError("compiled/recurrence ratio ceiling must be positive") - bundle, bundle_file = _checked_bundle( - runtime_bundle_manifest, - workflow_run_id=workflow_run_id, - expected_revision=expected_current_revision, - ) - capture_evidence: dict[str, object] = {} - runtime_digests: set[str] = set() - for role in CAPTURE_CONTRACTS: - payload, file_identity = shard_io._checked_json( - capture_paths[role], - label=f"{role} recurrence capture", - ) - if ( - payload.get("kind") != benchmark.RESULT_KIND - or payload.get("schema_version") != benchmark.RESULT_SCHEMA - or payload.get("complete") is not True - or payload.get("passes") is not True - ): - raise AcceptanceError(f"{role} is not a passing benchmark result") - configuration = _validate_configuration(payload, role=role) - runtime_digest = _validate_runtime( - payload, - role=role, - expected_revision=expected_current_revision, - bundle=bundle, - ) - runtime_digests.add(runtime_digest) - model = _validate_model( - configuration, - role=role, - expected_revision=expected_current_revision, - bundle=bundle, - ) - _recompute_harness_contracts(payload) - cells = [ - _paired_cell_evidence( - payload, - batch_size=batch_size, - ceiling=float(ratio_ceiling), - ) - for batch_size in PERFORMANCE_BATCH_SIZES - ] - capture_evidence[role] = { - "capture_file": { - key: file_identity[key] - for key in ("size_bytes", "sha256", "canonical_sha256") - }, - "source_revision": expected_current_revision, - "runtime_provenance_sha256": runtime_digest, - "model": model, - "layout": CAPTURE_CONTRACTS[role]["layout"], - "workload": CAPTURE_CONTRACTS[role]["workload"], - "numerical_validation": { - "contract": "recomputed-recurrence-z6g-pairwise-and-resolved-v1", - "passes": True, - }, - "performance_cells": cells, - "passes": all(cell["passes"] is True for cell in cells), - } - if len(runtime_digests) != 1: - raise AcceptanceError("the four captures used different runtime provenance") - all_cells = [ - cell - for capture in capture_evidence.values() - if isinstance(capture, Mapping) - for cell in capture["performance_cells"] - ] - body = { - "kind": RESULT_KIND, - "schema_version": SCHEMA_VERSION, - "workflow_run_id": workflow_run_id, - "target": "x86_64-unknown-linux-gnu", - "expected_current_revision": expected_current_revision, - "runtime_bundle": { - "content_sha256": bundle["content_identity"]["sha256"], - "file_sha256": bundle_file["sha256"], - }, - "policy": { - "required_capture_roles": list(CAPTURE_CONTRACTS), - "required_modes": list(REQUIRED_MODES), - "required_batch_sizes": list(REQUIRED_BATCH_SIZES), - "performance_batch_sizes": list(PERFORMANCE_BATCH_SIZES), - "minimum_target_runtime_seconds_per_worker": 5.0, - "subprocess_samples_per_cell": 7, - "native_wall_blocks_per_worker": 7, - "warmup_runs": 2, - "numerical_validation_samples": 10, - "compiled_over_recurrence_ratio_ceiling": float(ratio_ceiling), - "ratio_gate": "median-plus-three-raw-mad-at-or-below-ceiling-v1", - "diagnostic_shortcuts_allowed": False, - }, - "captures": capture_evidence, - "performance_cell_count": len(all_cells), - "passes": ( - len(all_cells) == len(CAPTURE_CONTRACTS) * len(PERFORMANCE_BATCH_SIZES) - and all(cell["passes"] is True for cell in all_cells) - ), - } - return _attach_content_identity(body) - - -def _git_sha(value: str) -> str: - if _GIT_SHA.fullmatch(value) is None: - raise argparse.ArgumentTypeError("must be a lowercase 40-character Git SHA") - return value - - -def parser() -> argparse.ArgumentParser: - result = argparse.ArgumentParser(description=__doc__) - for role in CAPTURE_CONTRACTS: - result.add_argument(f"--{role}", type=Path, required=True) - result.add_argument("--runtime-bundle-manifest", type=Path, required=True) - result.add_argument("--workflow-run-id", required=True) - result.add_argument( - "--expected-current-revision", - type=_git_sha, - required=True, - ) - result.add_argument( - "--compiled-recurrence-ratio-ceiling", - type=float, - default=COMPILED_RECURRENCE_RATIO_CEILING, - ) - result.add_argument("--output", type=Path, required=True) - return result - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = parser().parse_args(argv) - try: - result = audit( - capture_paths={ - role: getattr(arguments, role.replace("-", "_")) - for role in CAPTURE_CONTRACTS - }, - runtime_bundle_manifest=arguments.runtime_bundle_manifest, - workflow_run_id=arguments.workflow_run_id, - expected_current_revision=arguments.expected_current_revision, - ratio_ceiling=arguments.compiled_recurrence_ratio_ceiling, - ) - _write_json_atomic(arguments.output, result) - except ( - AcceptanceError, - OSError, - shard_io.ShardError, - ) as error: - print(f"x86-qq-recurrence-acceptance: {error}", file=sys.stderr) - return 2 - print(json.dumps(result, sort_keys=True, allow_nan=False)) - return 0 if result["passes"] is True else 1 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/fft_profiling/__init__.py b/pyamplicol/tools/fft_profiling/__init__.py deleted file mode 100644 index e68b21fb13..0000000000 --- a/pyamplicol/tools/fft_profiling/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Cluster-oriented FFT profiling orchestration.""" diff --git a/pyamplicol/tools/fft_profiling/fft_profiling.py b/pyamplicol/tools/fft_profiling/fft_profiling.py deleted file mode 100755 index b1352324a6..0000000000 --- a/pyamplicol/tools/fft_profiling/fft_profiling.py +++ /dev/null @@ -1,5274 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: 0BSD -"""Run and render the FullColor FFT profiling scan on a workstation or cluster. - -This is deliberately an orchestration layer. Physics generation, timings, -per-cell resource enforcement, numerical validation, report validation, -plotting, and PDF assembly remain owned by the existing developer tools. - -Typical use:: - - python tools/fft_profiling/fft_profiling.py --dry-run --cores 8 - python tools/fft_profiling/fft_profiling.py --lines pyamplicol-recurrence - python tools/fft_profiling/fft_profiling.py --cores 8 --candidate-cores 2 - python tools/fft_profiling/fft_profiling.py --compare-helicity-sums --cores 8 - python tools/fft_profiling/fft_profiling.py --resume --cores 16 - python tools/fft_profiling/fft_profiling.py --render - -``--render`` never waits for active workers. It freezes one already-published -campaign snapshot and delegates the six PNGs and PDF to the authoritative -renderers. ``--campaign-report`` can render another live scaling-study report, -which is useful for an existing non-orchestrated campaign. -""" - -from __future__ import annotations - -import argparse -import contextlib -import copy -import fcntl -import hashlib -import json -import math -import os -import shlex -import shutil -import signal -import subprocess -import sys -import tempfile -import time -import uuid -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any, BinaryIO - -ROOT = Path(__file__).resolve().parents[2] -if str(ROOT) not in sys.path: - sys.path.insert(0, str(ROOT)) - -try: - import colorama - import progressbar -except ModuleNotFoundError as error: # pragma: no cover - installation dependent - raise SystemExit( - "fft_profiling.py requires the project dependencies progressbar2 and " - "colorama; install pyAmpliCol in this Python environment" - ) from error - -from tools.ci import memory_watchdog # noqa: E402 -from tools.developer import fft_madgraph_selected_runtime as madgraph # noqa: E402 -from tools.developer import ( # noqa: E402 - fft_scaling_final_publication_report as publication, -) -from tools.developer import fft_scaling_selected_scalar_report as selected # noqa: E402 -from tools.developer import fft_scaling_study as study # noqa: E402 - -KIND = "pyamplicol-fft-profiling-orchestrator" -SCHEMA_VERSION = 1 -DEFAULT_RUNS_ROOT = ROOT / "IMPLEMENTATION_DOCS" / "RESULTS" / "fft-profiling" / "runs" -DEFAULT_FIXED_OUTPUT = DEFAULT_RUNS_ROOT / "cluster-fullcolor-n2-n9" -DEFAULT_SUM_OUTPUT = DEFAULT_RUNS_ROOT / "cluster-fullcolor-helicity-sum-n2-n9" -CANONICAL_RESULTS_ROOT = ROOT / "IMPLEMENTATION_DOCS" / "RESULTS" -STUDY_TOOL = ROOT / "tools" / "developer" / "fft_scaling_study.py" -MERGE_TOOL = ROOT / "tools" / "developer" / "fft_scaling_final_publication_report.py" -PLOT_TOOL = ROOT / "tools" / "developer" / "fft_scaling_study_plots.py" -PDF_TOOL = ROOT / "tools" / "developer" / "fft_results_summary_pdf.py" -MADGRAPH_TOOL = ROOT / "tools" / "developer" / "fft_madgraph_selected_runtime.py" -RENDER_REQUIREMENTS = ("matplotlib==3.11.2", "reportlab==4.5.1") -TERMINAL_STATUSES = frozenset({"complete", "complete-with-failures"}) -ORCHESTRATOR_TERMINAL_CELL_STATUSES = frozenset( - {"measured", "failed", "skipped", "not-applicable"} -) -MUTABLE_RESOURCE_IDENTITY_PATHS = frozenset( - { - "scan.target_seconds", - "resources.per_cell_generation_timeout_seconds", - "resources.per_cell_memory_limit_gib", - "resources.per_cell_runtime_timeout_seconds", - } -) -RETRYABLE_CELL_STATUSES = frozenset({"failed", "skipped"}) -LEGACY_MADGRAPH_NOTE = ( - "MadGraph points are retained from a same-workstation snapshot that " - "predates the node-fingerprint field; strict terminal host authentication " - "is therefore unavailable for this anytime render." -) - - -class ProfilingError(RuntimeError): - """The cluster profiling orchestration contract could not be satisfied.""" - - -class CampaignSignal(KeyboardInterrupt): - """A termination signal requested a resumable campaign shutdown.""" - - def __init__(self, signum: int) -> None: - super().__init__(signum) - self.signum = signum - - -@dataclass(frozen=True, slots=True) -class Shard: - name: str - family: str - modes: tuple[str, ...] - owned_modes: tuple[str, ...] - dependency: tuple[str, str] | None - phase: int - candidate: bool - - -@dataclass(frozen=True, slots=True) -class ShardWork: - shard: Shard - final_multiplicity: int - owned_mode: str - - -@dataclass(slots=True) -class ActiveJob: - shard: Shard - final_multiplicity: int | None - owned_mode: str | None - command: tuple[str, ...] - process: subprocess.Popen[bytes] - stdout: BinaryIO - stderr: BinaryIO - sampler: memory_watchdog.ProcessTreeSampler - claimed_cores: int - detail: str - - -@dataclass(frozen=True, slots=True) -class RenderSelection: - source: Path - overlay: Path | None - - -CellIdentity = tuple[str, str, int] - - -SHARDS = ( - Shard("gg-reference", "gg", ("reference-fft",), ("reference-fft",), None, 1, False), - Shard("ddbar-amplicol", "ddbar", ("amplicol",), ("amplicol",), None, 1, False), - Shard( - "gg-recurrence", - "gg", - ("reference-fft", "recurrence-direct", "recurrence-fft"), - ("recurrence-direct", "recurrence-fft"), - ("gg-reference", "reference-fft"), - 2, - True, - ), - Shard( - "gg-otf", - "gg", - ("reference-fft", "otf-direct", "otf-fft"), - ("otf-direct", "otf-fft"), - ("gg-reference", "reference-fft"), - 2, - True, - ), - Shard( - "ddbar-recurrence", - "ddbar", - ("amplicol", "recurrence-direct", "recurrence-fft"), - ("recurrence-direct", "recurrence-fft"), - ("ddbar-amplicol", "amplicol"), - 2, - True, - ), - Shard( - "ddbar-otf", - "ddbar", - ("amplicol", "otf-direct", "otf-fft"), - ("otf-direct", "otf-fft"), - ("ddbar-amplicol", "amplicol"), - 2, - True, - ), - Shard( - "gg-amplicol", - "gg", - ("reference-fft", "amplicol"), - ("amplicol",), - ("gg-reference", "reference-fft"), - 2, - False, - ), -) -SHARD_BY_NAME = {shard.name: shard for shard in SHARDS} -MODE_OWNER = { - (shard.family, mode): shard.name for shard in SHARDS for mode in shard.owned_modes -} -FAMILIES = ("gg", "ddbar") -LINE_GROUPS = ( - "reference-fft", - "amplicol", - "pyamplicol-recurrence", - "pyamplicol-otf", - "madgraph", -) -LINE_MODE_SELECTORS = ( - "recurrence-direct", - "recurrence-fft", - "otf-direct", - "otf-fft", -) -LINE_CHOICES = (*LINE_GROUPS, *LINE_MODE_SELECTORS) -RENDER_LINE_CHOICES = ( - *LINE_CHOICES, - "madgraph-standalone", - "recola", - "compiled-direct", - "compiled-fft", -) -LINE_SELECTOR_SHARDS = { - "reference-fft": ("gg-reference",), - "amplicol": ("ddbar-amplicol", "gg-amplicol"), - "pyamplicol-recurrence": ("gg-recurrence", "ddbar-recurrence"), - "pyamplicol-otf": ("gg-otf", "ddbar-otf"), - "madgraph": (), - "recurrence-direct": ("gg-recurrence", "ddbar-recurrence"), - "recurrence-fft": ("gg-recurrence", "ddbar-recurrence"), - "otf-direct": ("gg-otf", "ddbar-otf"), - "otf-fft": ("gg-otf", "ddbar-otf"), -} -LINE_SELECTOR_OWNED_MODES = { - "reference-fft": ("reference-fft",), - "amplicol": ("amplicol",), - "pyamplicol-recurrence": ("recurrence-direct", "recurrence-fft"), - "pyamplicol-otf": ("otf-direct", "otf-fft"), - "madgraph": (), - "recurrence-direct": ("recurrence-direct",), - "recurrence-fft": ("recurrence-fft",), - "otf-direct": ("otf-direct",), - "otf-fft": ("otf-fft",), -} - - -def _positive_finite(raw: str) -> float: - value = float(raw) - if not math.isfinite(value) or value <= 0.0: - raise argparse.ArgumentTypeError("must be positive and finite") - return value - - -def _finite_float(raw: str) -> float: - value = float(raw) - if not math.isfinite(value): - raise argparse.ArgumentTypeError("must be finite") - return value - - -def _positive_integer(raw: str) -> int: - value = int(raw) - if value < 1: - raise argparse.ArgumentTypeError("must be positive") - return value - - -def _default_madgraph_root() -> Path | None: - configured = os.environ.get("PYAMPLICOL_MADGRAPH_ROOT") - candidates = ( - *((Path(configured).expanduser(),) if configured else ()), - ROOT / "dependencies" / "checkouts" / "MG5_aMC", - ROOT.parent / "MG5_aMC", - Path.home() / "MG5" / "MG5_aMC_v3_7_1", - ) - return next( - ( - candidate.resolve(strict=False) - for candidate in candidates - if (candidate / "bin" / "mg5_aMC").is_file() - and (candidate / "VERSION").is_file() - ), - None, - ) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, - ) - action = parser.add_mutually_exclusive_group() - action.add_argument( - "--refresh", - action="store_true", - help=( - "remove the exact recognized profiling --output and restart from scratch" - ), - ) - action.add_argument( - "--render", - action="store_true", - help="render the latest frozen snapshot immediately; never wait for workers", - ) - action.add_argument("--status", action="store_true", help="print JSON status") - action.add_argument( - "--dry-run", - action="store_true", - help="print the deterministic plan as JSON without writing or launching", - ) - parser.add_argument( - "--resume", - action="store_true", - help="explicit alias for the default automatic resume behavior", - ) - rerun = parser.add_mutually_exclusive_group() - rerun.add_argument( - "--retry", - action="store_true", - help=( - "rerun failed/skipped cells in the current --families/--lines/" - "--multiplicities selection without refreshing the whole output" - ), - ) - rerun.add_argument( - "--overwrite", - action="store_true", - help=( - "rerun every cell in the current --families/--lines/--multiplicities " - "selection, replacing each old result only when its worker starts" - ), - ) - parser.add_argument( - "--output", - type=Path, - default=None, - help=( - "complete profiling run/render directory (default is a distinct " - "fixed-helicity or helicity-sum run directory)" - ), - ) - parser.add_argument( - "--compare-helicity-sums", - action="store_true", - help=( - "profile the complete physical-helicity-summed matrix element in " - "an independent campaign, including a genuine summed MadGraph " - "standalone series when --madgraph-root is available" - ), - ) - parser.add_argument( - "--multiplicities", - type=int, - nargs="+", - default=list(range(2, 10)), - metavar="N", - help=( - "final-state multiplicities to add to the resumable scan; unfinished " - "prior requests are also recovered (default: 2 3 ... 9)" - ), - ) - parser.add_argument( - "--lines", - nargs="+", - choices=LINE_CHOICES, - default=list(LINE_GROUPS), - metavar="LINE", - help=( - "plot line groups to add to the resumable scan: reference-fft, " - "amplicol, pyamplicol-recurrence (direct and FFT), " - "pyamplicol-otf (direct and FFT), concrete pyAmpliCol modes " - "recurrence-direct, recurrence-fft, otf-direct, otf-fft, and/or " - "madgraph; repeated runs add exactly the requested selectors and " - "multiplicities in the same --output (default: all groups)" - ), - ) - parser.add_argument( - "--families", - "--process-families", - nargs="+", - choices=FAMILIES, - default=list(FAMILIES), - metavar="FAMILY", - help=( - "process families to add to the scan: gg for g g > g g + gluons, " - "ddbar for d d~ > d d~ + gluons (default: both)" - ), - ) - parser.add_argument( - "--cores", - type=_positive_integer, - default=max(1, os.cpu_count() or 1), - help="total scheduler core budget (default: detected logical cores)", - ) - parser.add_argument( - "--candidate-cores", - type=_positive_integer, - default=1, - help=( - "cores claimed by one candidate shard and passed exactly as " - "evaluator.optimization.cores (default: 1)" - ), - ) - parser.add_argument( - "--batch-size", - type=_positive_integer, - default=study.BENCHMARK_BATCH_SIZE, - help=( - "points in each pyAmpliCol public profile call; Reference FFT and " - "AmpliCol remain scalar aggregates normalized per point " - f"(default: {study.BENCHMARK_BATCH_SIZE})" - ), - ) - parser.add_argument( - "--memory-limit-gib", - type=_positive_finite, - default=study.REQUESTED_MEMORY_LIMIT_GIB, - help="strict RAM cutoff for each measurement child (default: 30)", - ) - parser.add_argument( - "--time-limit-seconds", - type=_positive_finite, - default=study.DEFAULT_TIME_LIMIT_SECONDS, - help="generation and runtime cutoff for each cell (default: 3600)", - ) - parser.add_argument("--python", default=sys.executable) - parser.add_argument("--cxx", default=os.environ.get("CXX", "c++")) - parser.add_argument("--fc", default=os.environ.get("FC", "gfortran")) - parser.add_argument("--make", default=os.environ.get("MAKE", "make")) - parser.add_argument( - "--target-seconds", - type=_positive_finite, - default=study.DEFAULT_PROFILE_TARGET_SECONDS, - help=( - "target runtime for each profiling cell after its first " - "calibration/probe evaluation (default: 180)" - ), - ) - parser.add_argument( - "--otf-max-multiplicity", - type=int, - default=study.DEFAULT_OTF_MAX_MULTIPLICITY, - help=( - "largest final-state multiplicity to admit for pyAmpliCol OTF " - "measurements; raise this for an explicit high-multiplicity top-up " - f"(default: {study.DEFAULT_OTF_MAX_MULTIPLICITY})" - ), - ) - parser.add_argument( - "--amplicol-root", - "--amplicol-repository", - dest="amplicol_root", - type=Path, - default=study.legacy_amplicol.DEFAULT_REPOSITORY, - help=( - "original-AmpliCol checkout (default path is populated by " - "dev-install --with-legacy-amplicol)" - ), - ) - parser.add_argument( - "--reference-fft-root", - type=Path, - default=study.performance.DEFAULT_REFERENCE_ROOT, - help=( - "pinned AllGluonsMultipletFFT checkout for Reference FFT " - "(default path is populated by dev-install --with-reference-fft)" - ), - ) - parser.add_argument( - "--build-amplicol", - action="store_true", - help="allow the prerequisite AmpliCol shard to build its probe once", - ) - parser.add_argument( - "--madgraph-root", - type=Path, - default=_default_madgraph_root(), - help=( - "MadGraph installation used for the same-host standalone series " - "(defaults to PYAMPLICOL_MADGRAPH_ROOT or a developer checkout)" - ), - ) - parser.add_argument( - "--madgraph-overlay", - type=Path, - help="with --render --campaign-report, an existing authenticated overlay", - ) - parser.add_argument( - "--campaign-report", - type=Path, - help="with --render, freeze and render this existing live report", - ) - parser.add_argument( - "--recola-results", - type=Path, - help="with --render, overlay a Recola profiling JSON as a Recola line", - ) - parser.add_argument( - "--main-y-range", - type=_finite_float, - nargs=2, - metavar=("MIN", "MAX"), - help="with --render, force the main-panel log y-range for every plot", - ) - parser.add_argument( - "--ratio-y-range", - type=_finite_float, - nargs=2, - metavar=("MIN", "MAX"), - help="with --render, force the ratio-panel y-range for every plot", - ) - parser.add_argument( - "--ratio-y-scale", - choices=("log", "linear"), - default="log", - help="with --render, ratio-panel y-axis scale (default: log)", - ) - parser.add_argument( - "--main-include-lines", - nargs="+", - choices=RENDER_LINE_CHOICES, - metavar="LINE", - help="with --render, main-panel line ids to include; overrides vetoes", - ) - parser.add_argument( - "--main-veto-lines", - nargs="+", - choices=RENDER_LINE_CHOICES, - metavar="LINE", - help="with --render, main-panel line ids to hide when include is absent", - ) - parser.add_argument( - "--ratio-include-lines", - nargs="+", - choices=RENDER_LINE_CHOICES, - metavar="LINE", - help="with --render, ratio-panel line ids to include; overrides vetoes", - ) - parser.add_argument( - "--ratio-veto-lines", - nargs="+", - choices=RENDER_LINE_CHOICES, - metavar="LINE", - help="with --render, ratio-panel line ids to hide when include is absent", - ) - parser.add_argument("--dpi", type=int, default=160) - parser.add_argument("--poll-seconds", type=_positive_finite, default=0.5) - parser.add_argument("--no-color", action="store_true") - return parser - - -def _absolute(path: Path) -> Path: - return path.expanduser().resolve(strict=False) - - -def _configured_run_path(arguments: argparse.Namespace) -> Path: - if arguments.output is not None: - return arguments.output - return ( - DEFAULT_SUM_OUTPUT if arguments.compare_helicity_sums else DEFAULT_FIXED_OUTPUT - ) - - -def _run_directory(arguments: argparse.Namespace) -> Path: - return _absolute(_configured_run_path(arguments)) - - -def _helicity_workload(arguments: argparse.Namespace) -> str: - return "sum" if arguments.compare_helicity_sums else "fixed" - - -def _pdf_filename(arguments: argparse.Namespace) -> str: - return ( - "summary_plots_final_helicity_sum.pdf" - if arguments.compare_helicity_sums - else "summary_plots_final.pdf" - ) - - -def _canonical_pdf_path(arguments: argparse.Namespace) -> Path: - return CANONICAL_RESULTS_ROOT / _pdf_filename(arguments) - - -def _json_filename(arguments: argparse.Namespace) -> str: - return Path(_pdf_filename(arguments)).with_suffix(".json").name - - -def _canonical_publication_enabled(arguments: argparse.Namespace) -> bool: - return arguments.output is None and arguments.campaign_report is None - - -def _universe(arguments: argparse.Namespace) -> tuple[int, ...]: - stored = getattr(arguments, "universe_multiplicities", None) - if stored is not None: - return tuple(int(value) for value in stored) - return tuple(range(2, 10)) - - -def _selection(arguments: argparse.Namespace) -> tuple[int, ...]: - return tuple(sorted(set(arguments.multiplicities))) - - -def _family_selection(arguments: argparse.Namespace) -> tuple[str, ...]: - selected = set(arguments.families) - return tuple(family for family in FAMILIES if family in selected) - - -def _line_selection(arguments: argparse.Namespace) -> tuple[str, ...]: - selected = set(arguments.lines) - return tuple(line for line in LINE_CHOICES if line in selected) - - -def _requested_line_groups( - arguments: argparse.Namespace, run_directory: Path -) -> tuple[str, ...]: - _ = run_directory - selected = set(_line_selection(arguments)) - return tuple(line for line in LINE_CHOICES if line in selected) - - -def _madgraph_requested(arguments: argparse.Namespace, run_directory: Path) -> bool: - return "madgraph" in _requested_line_groups(arguments, run_directory) - - -def _requested_shards( - arguments: argparse.Namespace, run_directory: Path -) -> tuple[Shard, ...]: - selected_families = set(_family_selection(arguments)) - names = { - name - for line in _requested_line_groups(arguments, run_directory) - for name in LINE_SELECTOR_SHARDS[line] - if SHARD_BY_NAME[name].family in selected_families - } - if _madgraph_requested(arguments, run_directory): - source_modes = ( - publication.SUM_SOURCE_MODE - if arguments.compare_helicity_sums - else publication.SOURCE_MODE - ) - names.update( - MODE_OWNER[(family, mode)] - for family, mode in source_modes.items() - if family in selected_families - ) - pending = list(names) - while pending: - shard = SHARD_BY_NAME[pending.pop()] - if shard.dependency is None: - continue - dependency_name, _ = shard.dependency - if dependency_name not in names: - names.add(dependency_name) - pending.append(dependency_name) - return tuple(shard for shard in SHARDS if shard.name in names) - - -def _line_selected_owned_modes( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> tuple[str, ...]: - selected: set[str] = set() - for line in _requested_line_groups(arguments, run_directory): - for mode in LINE_SELECTOR_OWNED_MODES[line]: - if mode in shard.owned_modes: - selected.add(mode) - if _madgraph_requested(arguments, run_directory): - source_modes = ( - publication.SUM_SOURCE_MODE - if arguments.compare_helicity_sums - else publication.SOURCE_MODE - ) - for family, mode in source_modes.items(): - if MODE_OWNER[(family, mode)] == shard.name: - selected.add(mode) - return tuple(mode for mode in shard.owned_modes if mode in selected) - - -def _shard_owned_modes( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> tuple[str, ...]: - selected = set(_line_selected_owned_modes(arguments, run_directory, shard)) - requested_names = { - requested.name for requested in _requested_shards(arguments, run_directory) - } - for requested in SHARDS: - if requested.name not in requested_names or requested.dependency is None: - continue - dependency_name, dependency_mode = requested.dependency - if dependency_name == shard.name and dependency_mode in shard.owned_modes: - selected.add(dependency_mode) - return tuple(mode for mode in shard.owned_modes if mode in selected) - - -def _shard_modes( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> tuple[str, ...]: - selected = set(_shard_owned_modes(arguments, run_directory, shard)) - if selected and shard.dependency is not None: - _, dependency_mode = shard.dependency - selected.add(dependency_mode) - return tuple(mode for mode in shard.modes if mode in selected) - - -def _counted_owned_modes( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> tuple[str, ...]: - if arguments.retry or arguments.overwrite: - return _line_selected_owned_modes(arguments, run_directory, shard) - return _shard_owned_modes(arguments, run_directory, shard) - - -def _scheduled_shards( - arguments: argparse.Namespace, run_directory: Path -) -> tuple[Shard, ...]: - if not (arguments.retry or arguments.overwrite): - return _requested_shards(arguments, run_directory) - return tuple( - shard - for shard in _requested_shards(arguments, run_directory) - if _counted_owned_modes(arguments, run_directory, shard) - ) - - -def _shard_run_id(shard: Shard, final_multiplicity: int | None = None) -> str: - if final_multiplicity is None: - return shard.name - return f"{shard.name}-n{final_multiplicity}" - - -def _work_split_path(work: ShardWork) -> bool: - return len(work.shard.owned_modes) > 1 - - -def _work_run_id(work: ShardWork) -> str: - if not _work_split_path(work): - return _shard_run_id(work.shard, work.final_multiplicity) - return f"{work.shard.name}-{work.owned_mode}-n{work.final_multiplicity}" - - -def _work_identity(work: ShardWork) -> CellIdentity: - return (work.shard.family, work.owned_mode, work.final_multiplicity) - - -def _shard_cell_root( - run_directory: Path, shard: Shard, final_multiplicity: int -) -> Path: - return run_directory / "shards" / shard.name / "cells" / f"n{final_multiplicity}" - - -def _work_cell_root(run_directory: Path, work: ShardWork) -> Path: - if not _work_split_path(work): - return _shard_cell_root(run_directory, work.shard, work.final_multiplicity) - return ( - run_directory - / "shards" - / work.shard.name - / "mode-cells" - / work.owned_mode - / f"n{work.final_multiplicity}" - ) - - -def _shard_study_root( - run_directory: Path, shard: Shard, final_multiplicity: int | None = None -) -> Path: - if final_multiplicity is None: - return run_directory / "shards" / shard.name / "study" - return _shard_cell_root(run_directory, shard, final_multiplicity) / "study" - - -def _work_study_root(run_directory: Path, work: ShardWork) -> Path: - return _work_cell_root(run_directory, work) / "study" - - -def _shard_report_path( - run_directory: Path, shard: Shard, final_multiplicity: int | None = None -) -> Path: - return ( - _shard_study_root(run_directory, shard, final_multiplicity) - / "runs" - / _shard_run_id(shard, final_multiplicity) - / "report.json" - ) - - -def _work_report_path(run_directory: Path, work: ShardWork) -> Path: - return ( - _work_study_root(run_directory, work) - / "runs" - / _work_run_id(work) - / "report.json" - ) - - -def _master_study_root(run_directory: Path) -> Path: - return run_directory / "master" - - -def _master_report_path(run_directory: Path) -> Path: - return _master_study_root(run_directory) / "runs" / "campaign" / "report.json" - - -def _madgraph_overlay_path(run_directory: Path) -> Path: - return run_directory / "madgraph" / "overlay.json" - - -def _madgraph_progress_path(run_directory: Path) -> Path: - return run_directory / "madgraph" / "overlay.progress.json" - - -def _madgraph_cache_path(run_directory: Path) -> Path: - return run_directory / "madgraph" / "cache" - - -def _requested_multiplicities( - arguments: argparse.Namespace, run_directory: Path -) -> tuple[int, ...]: - _ = run_directory - return _selection(arguments) - - -def _manifest_int_history( - manifest: Mapping[str, Any], primary: str, fallback: str -) -> list[int]: - values = manifest.get(primary, manifest.get(fallback, [])) - if not isinstance(values, list) or any( - not isinstance(value, int) for value in values - ): - raise ProfilingError("profiling manifest has invalid fill history") - return values - - -def _manifest_line_history(manifest: Mapping[str, Any]) -> list[str]: - values = manifest.get( - "line_group_history", manifest.get("requested_line_groups", []) - ) - if ( - not isinstance(values, list) - or any(not isinstance(value, str) for value in values) - or not set(values).issubset(LINE_CHOICES) - ): - raise ProfilingError("profiling manifest has invalid line-group history") - selected = set(values) - return [line for line in LINE_CHOICES if line in selected] - - -def _manifest_family_history(manifest: Mapping[str, Any]) -> list[str]: - identity = manifest.get("identity") - scan = identity.get("scan") if isinstance(identity, Mapping) else None - fallback = ( - scan.get("families") - if isinstance(scan, Mapping) and isinstance(scan.get("families"), list) - else [] - ) - values = manifest.get( - "process_family_history", manifest.get("requested_families", fallback) - ) - if ( - not isinstance(values, list) - or any(not isinstance(value, str) for value in values) - or not set(values).issubset(FAMILIES) - ): - raise ProfilingError("profiling manifest has invalid process-family history") - selected = set(values) - return [family for family in FAMILIES if family in selected] - - -def _manifest_backed_arguments( - arguments: argparse.Namespace, run_directory: Path -) -> argparse.Namespace: - manifest_path = _manifest_path(run_directory) - if not manifest_path.is_file(): - return arguments - manifest = _load_json(manifest_path, context="profiling manifest") - identity = manifest.get("identity") - if not isinstance(identity, Mapping): - return arguments - backed = copy.copy(arguments) - scan = identity.get("scan") - if isinstance(scan, Mapping): - workload = scan.get("helicity_workload") - if workload in {"fixed", "sum"}: - backed.compare_helicity_sums = workload == "sum" - if isinstance(scan.get("batch_size"), int): - backed.batch_size = scan["batch_size"] - if isinstance(scan.get("target_seconds"), int | float): - backed.target_seconds = float(scan["target_seconds"]) - resources = identity.get("resources") - if isinstance(resources, Mapping): - if isinstance(resources.get("candidate_optimization_cores"), int): - backed.candidate_cores = resources["candidate_optimization_cores"] - if isinstance(resources.get("per_cell_memory_limit_gib"), int | float): - backed.memory_limit_gib = float(resources["per_cell_memory_limit_gib"]) - generation_timeout = resources.get("per_cell_generation_timeout_seconds") - runtime_timeout = resources.get("per_cell_runtime_timeout_seconds") - if isinstance(generation_timeout, int | float) and isinstance( - runtime_timeout, int | float - ): - backed.time_limit_seconds = float(max(generation_timeout, runtime_timeout)) - tools = identity.get("tools") - if isinstance(tools, Mapping): - for attribute in ("python", "cxx", "fc"): - value = tools.get(attribute) - if isinstance(value, str) and value: - setattr(backed, attribute, value) - for attribute in ("amplicol_root", "reference_fft_root", "madgraph_root"): - value = tools.get(attribute) - if isinstance(value, str) and value: - setattr(backed, attribute, Path(value)) - return backed - - -def _composition_arguments( - arguments: argparse.Namespace, run_directory: Path -) -> argparse.Namespace: - backed = _manifest_backed_arguments(arguments, run_directory) - manifest_path = _manifest_path(run_directory) - if not manifest_path.is_file(): - return backed - manifest = _load_json(manifest_path, context="profiling manifest") - composed = copy.copy(backed) - composed.multiplicities = _manifest_int_history( - manifest, "fill_history_multiplicities", "requested_multiplicities" - ) - composed.lines = _manifest_line_history(manifest) - composed.families = _manifest_family_history(manifest) - return composed - - -def _madgraph_source_path(arguments: argparse.Namespace, run_directory: Path) -> Path: - multiplicities = _requested_multiplicities(arguments, run_directory) - selection = "-".join(str(value) for value in multiplicities) - return run_directory / "madgraph" / "source-reports" / f"n-{selection}.json" - - -def _manifest_path(run_directory: Path) -> Path: - return run_directory / "manifest.json" - - -def _study_cli_arguments( - arguments: argparse.Namespace, - *, - study_root: Path, - run_id: str, - families: Sequence[str], - modes: Sequence[str], - resume: bool, - build_amplicol: bool = False, - fill_multiplicities: Sequence[int] | None = None, - fill_modes: Sequence[str] | None = None, -) -> tuple[str, ...]: - result = [ - "--study-root", - str(study_root), - "--run-id", - run_id, - "--fft", - "--explicit-modes", - "--batch-size", - str(arguments.batch_size), - "--optimization-cores", - str(arguments.candidate_cores), - "--python", - str(arguments.python), - "--cxx", - str(arguments.cxx), - "--fc", - str(arguments.fc), - "--alpha-s", - format(study.DEFAULT_ALPHA_S, ".17g"), - "--target-seconds", - format(arguments.target_seconds, ".17g"), - "--generation-timeout", - format(arguments.time_limit_seconds, ".17g"), - "--runtime-timeout", - format(arguments.time_limit_seconds, ".17g"), - "--memory-limit-gib", - format(arguments.memory_limit_gib, ".17g"), - "--otf-max-multiplicity", - str(arguments.otf_max_multiplicity), - "--amplicol-repository", - str(_absolute(arguments.amplicol_root)), - "--reference-fft-root", - str(_absolute(arguments.reference_fft_root)), - ] - for multiplicity in _universe(arguments): - result.extend(("--multiplicity", str(multiplicity))) - for multiplicity in ( - _selection(arguments) - if fill_multiplicities is None - else tuple(fill_multiplicities) - ): - result.extend(("--fill-multiplicity", str(multiplicity))) - if fill_modes is not None: - for mode in fill_modes: - result.extend(("--fill-mode", mode)) - for family in families: - result.extend(("--family", family)) - for mode in modes: - result.extend(("--mode", mode)) - if resume: - result.append("--resume") - if build_amplicol: - result.append("--build-amplicol") - if arguments.compare_helicity_sums: - result.append("--compare-helicity-sums") - return tuple(result) - - -def _shard_cli_arguments( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - final_multiplicity: int | None = None, - *, - modes: Sequence[str] | None = None, - fill_modes: Sequence[str] | None = None, -) -> tuple[str, ...]: - return _study_cli_arguments( - arguments, - study_root=_shard_study_root(run_directory, shard, final_multiplicity), - run_id=_shard_run_id(shard, final_multiplicity), - families=(shard.family,), - modes=( - tuple(modes) - if modes is not None - else _shard_modes(arguments, run_directory, shard) - ), - resume=True, - build_amplicol=arguments.build_amplicol and shard.name == "ddbar-amplicol", - fill_multiplicities=( - _requested_multiplicities(arguments, run_directory) - if final_multiplicity is None - else (final_multiplicity,) - ), - fill_modes=fill_modes, - ) - - -def _master_arguments( - arguments: argparse.Namespace, run_directory: Path -) -> argparse.Namespace: - modes = tuple( - dict.fromkeys( - mode - for family in FAMILIES - for mode in publication.FAMILY_MODES[family] - ) - ) - original = arguments.multiplicities - arguments.multiplicities = list(_universe(arguments)) - try: - raw_arguments = _study_cli_arguments( - arguments, - study_root=_master_study_root(run_directory), - run_id="campaign", - families=FAMILIES, - modes=modes, - resume=True, - ) - finally: - arguments.multiplicities = original - namespace = study._parser().parse_args(raw_arguments) - study._validate_arguments(namespace) - return namespace - - -def _shard_arguments( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - final_multiplicity: int | None = None, - *, - modes: Sequence[str] | None = None, -) -> argparse.Namespace: - namespace = study._parser().parse_args( - _shard_cli_arguments( - arguments, - run_directory, - shard, - final_multiplicity, - modes=modes, - ) - ) - study._validate_arguments(namespace) - return namespace - - -def _work_owned_modes( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> tuple[str, ...]: - counted = _counted_owned_modes(arguments, run_directory, work.shard) - if work.owned_mode not in counted: - return () - return (work.owned_mode,) - - -def _work_modes( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> tuple[str, ...]: - selected = set(_work_owned_modes(arguments, run_directory, work)) - if selected and work.shard.dependency is not None: - _, dependency_mode = work.shard.dependency - selected.add(dependency_mode) - return tuple(mode for mode in work.shard.modes if mode in selected) - - -def _work_cli_arguments( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> tuple[str, ...]: - return _study_cli_arguments( - arguments, - study_root=_work_study_root(run_directory, work), - run_id=_work_run_id(work), - families=(work.shard.family,), - modes=_work_modes(arguments, run_directory, work), - resume=True, - build_amplicol=arguments.build_amplicol and work.shard.name == "ddbar-amplicol", - fill_multiplicities=(work.final_multiplicity,), - fill_modes=_work_owned_modes(arguments, run_directory, work), - ) - - -def _work_arguments( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> argparse.Namespace: - namespace = study._parser().parse_args( - _work_cli_arguments(arguments, run_directory, work) - ) - study._validate_arguments(namespace) - return namespace - - -def _validate_y_range( - values: Sequence[float] | None, - *, - option: str, - positive: bool, -) -> None: - if values is None: - return - if len(values) != 2: - raise ProfilingError(f"{option} requires exactly two values") - low, high = (float(values[0]), float(values[1])) - if not math.isfinite(low) or not math.isfinite(high): - raise ProfilingError(f"{option} values must be finite") - if high <= low: - raise ProfilingError(f"{option} requires MIN < MAX") - if positive and low <= 0.0: - raise ProfilingError(f"{option} must be positive for a logarithmic y-axis") - - -def _validate_render_line_filter(values: Sequence[str] | None, *, option: str) -> None: - if values is None: - return - selected = tuple(str(value) for value in values) - if len(set(selected)) != len(selected): - raise ProfilingError(f"{option} must not contain duplicates") - invalid = sorted(set(selected) - set(RENDER_LINE_CHOICES)) - if invalid: - raise ProfilingError(f"{option} has unknown line id(s): {', '.join(invalid)}") - - -def _validate_arguments(arguments: argparse.Namespace) -> None: - _normalize_executables(arguments) - if arguments.refresh: - _reject_refresh_symlinks(_configured_run_path(arguments)) - targeted_rerun = arguments.retry or arguments.overwrite - if targeted_rerun and arguments.refresh: - raise ProfilingError( - "--retry/--overwrite are targeted alternatives to --refresh" - ) - if targeted_rerun and (arguments.render or arguments.status): - raise ProfilingError( - "--retry/--overwrite are valid only for profiling runs" - ) - if arguments.candidate_cores > arguments.cores: - raise ProfilingError("--candidate-cores cannot exceed --cores") - if arguments.dpi < 72 or arguments.dpi > 600: - raise ProfilingError("--dpi must be between 72 and 600") - _validate_y_range(arguments.main_y_range, option="--main-y-range", positive=True) - _validate_y_range( - arguments.ratio_y_range, - option="--ratio-y-range", - positive=arguments.ratio_y_scale == "log", - ) - _validate_render_line_filter( - arguments.main_include_lines, - option="--main-include-lines", - ) - _validate_render_line_filter( - arguments.main_veto_lines, - option="--main-veto-lines", - ) - _validate_render_line_filter( - arguments.ratio_include_lines, - option="--ratio-include-lines", - ) - _validate_render_line_filter( - arguments.ratio_veto_lines, - option="--ratio-veto-lines", - ) - if arguments.target_seconds < 0.25: - raise ProfilingError("--target-seconds must be at least 0.25") - if not 2 <= arguments.otf_max_multiplicity <= 9: - raise ProfilingError("--otf-max-multiplicity must be in the range 2..9") - if ( - not arguments.multiplicities - or min(arguments.multiplicities) < 2 - or max(arguments.multiplicities) > 9 - ): - raise ProfilingError( - "--multiplicities values must be integers in the final-PDF scan range 2..9" - ) - if len(set(arguments.multiplicities)) != len(arguments.multiplicities): - raise ProfilingError("--multiplicities must not contain duplicates") - if len(set(arguments.lines)) != len(arguments.lines): - raise ProfilingError("--lines must not contain duplicates") - if len(set(arguments.families)) != len(arguments.families): - raise ProfilingError("--families must not contain duplicates") - # The authoritative parser owns run-id, n-range, mode, and resource checks. - _master_arguments(arguments, _run_directory(arguments)) - if arguments.campaign_report is not None and not arguments.render: - raise ProfilingError("--campaign-report is valid only with --render") - if arguments.recola_results is not None: - if not arguments.render: - raise ProfilingError("--recola-results is valid only with --render") - if not _absolute(arguments.recola_results).is_file(): - raise ProfilingError( - f"Recola results JSON is missing: {_absolute(arguments.recola_results)}" - ) - render_only_options = { - "--main-y-range": arguments.main_y_range is not None, - "--ratio-y-range": arguments.ratio_y_range is not None, - "--ratio-y-scale": arguments.ratio_y_scale != "log", - "--main-include-lines": arguments.main_include_lines is not None, - "--main-veto-lines": arguments.main_veto_lines is not None, - "--ratio-include-lines": arguments.ratio_include_lines is not None, - "--ratio-veto-lines": arguments.ratio_veto_lines is not None, - } - for option, configured in render_only_options.items(): - if configured and not arguments.render: - raise ProfilingError(f"{option} is valid only with --render") - run_directory = _run_directory(arguments) - if ( - not arguments.render - and not _requested_shards(arguments, run_directory) - and not _madgraph_requested(arguments, run_directory) - ): - raise ProfilingError( - "the selected --families and --lines leave no applicable profiling work" - ) - - -def _normalize_executables(arguments: argparse.Namespace) -> None: - for attribute in ("python", "cxx", "fc", "make"): - raw = str(getattr(arguments, attribute)) - path = Path(raw).expanduser() - if path.parent != Path("."): - # Preserve virtual-environment launcher symlinks: resolving the - # final component would silently bypass the venv's site-packages. - setattr(arguments, attribute, str(Path(os.path.abspath(path)))) - continue - located = shutil.which(raw) - if located is not None: - setattr(arguments, attribute, str(Path(os.path.abspath(located)))) - - -def _identity(arguments: argparse.Namespace, run_directory: Path) -> dict[str, Any]: - return { - "run_directory": str(run_directory), - "measurement_host": madgraph.measurement_host_identity(), - "scan": { - "multiplicity_universe": list(_universe(arguments)), - "helicity_workload": _helicity_workload(arguments), - "families": list(FAMILIES), - "modes": { - family: list(publication.FAMILY_MODES[family]) - for family in FAMILIES - }, - "batch_size": arguments.batch_size, - "fft_enabled": True, - "target_seconds": arguments.target_seconds, - }, - "resources": { - "candidate_optimization_cores": arguments.candidate_cores, - "per_cell_memory_limit_gib": arguments.memory_limit_gib, - "per_cell_generation_timeout_seconds": arguments.time_limit_seconds, - "per_cell_runtime_timeout_seconds": arguments.time_limit_seconds, - }, - "tools": { - "python": str(arguments.python), - "cxx": str(arguments.cxx), - "fc": str(arguments.fc), - "amplicol_root": str(_absolute(arguments.amplicol_root)), - "reference_fft_root": str(_absolute(arguments.reference_fft_root)), - "madgraph_root": ( - str(_absolute(arguments.madgraph_root)) - if arguments.madgraph_root is not None - else None - ), - }, - } - - -def _child_command( - arguments: argparse.Namespace, - run_directory: Path, - work: ShardWork, -) -> tuple[str, ...]: - return ( - str(arguments.python), - str(STUDY_TOOL), - *_work_cli_arguments(arguments, run_directory, work), - ) - - -def _measurement_multiplicities( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> tuple[int, ...]: - owned_modes = _counted_owned_modes(arguments, run_directory, shard) - return _measurement_multiplicities_for_modes( - arguments, run_directory, shard, owned_modes - ) - - -def _measurement_multiplicities_for_modes( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - owned_modes: Sequence[str], -) -> tuple[int, ...]: - _ = run_directory - if not owned_modes: - return () - return tuple( - final_multiplicity - for final_multiplicity in _selection(arguments) - if not all( - study.otf_protocol_scope_cell( - family=shard.family, - mode=study.MODE_BY_KEY[mode], - final_multiplicity=final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - maximum_multiplicity=arguments.otf_max_multiplicity, - ) - is not None - for mode in owned_modes - ) - ) - - -def _work_measurement_multiplicities( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> tuple[int, ...]: - return _measurement_multiplicities_for_modes( - arguments, - run_directory, - work.shard, - _work_owned_modes(arguments, run_directory, work), - ) - - -def _render_commands( - arguments: argparse.Namespace, - *, - source_report: Path, - staged_report: Path, - staged_plots: Path, - staged_pdf: Path, - strict: bool, - madgraph_overlay: Path | None, -) -> tuple[tuple[str, ...], ...]: - commands: list[tuple[str, ...]] = [] - plot_report = source_report - if strict: - if madgraph_overlay is None: - raise ProfilingError( - "strict terminal rendering requires an authenticated MadGraph overlay" - ) - commands.append( - ( - str(arguments.python), - str(MERGE_TOOL), - "--campaign-report", - str(source_report), - "--madgraph-overlay", - str(_absolute(madgraph_overlay)), - "--output", - str(staged_report), - ) - ) - plot_report = staged_report - plot_command = [ - str(arguments.python), - str(PLOT_TOOL), - str(plot_report), - str(staged_plots), - "--dpi", - str(arguments.dpi), - ] - if arguments.recola_results is not None: - plot_command.extend( - ("--recola-results", str(_absolute(arguments.recola_results))) - ) - if arguments.main_y_range is not None: - plot_command.extend( - ("--main-y-range", *(str(value) for value in arguments.main_y_range)) - ) - if arguments.ratio_y_range is not None: - plot_command.extend( - ("--ratio-y-range", *(str(value) for value in arguments.ratio_y_range)) - ) - if arguments.ratio_y_scale != "log": - plot_command.extend(("--ratio-y-scale", arguments.ratio_y_scale)) - for option, values in ( - ("--main-include-lines", arguments.main_include_lines), - ("--main-veto-lines", arguments.main_veto_lines), - ("--ratio-include-lines", arguments.ratio_include_lines), - ("--ratio-veto-lines", arguments.ratio_veto_lines), - ): - if values is not None: - plot_command.extend((option, *(str(value) for value in values))) - commands.extend( - ( - tuple(plot_command), - ( - str(arguments.python), - str(PDF_TOOL), - "--campaign-report", - str(plot_report), - "--plot-directory", - str(staged_plots), - "--output", - str(staged_pdf), - ), - ) - ) - return tuple(commands) - - -def dry_run_plan(arguments: argparse.Namespace) -> dict[str, Any]: - run_directory = _run_directory(arguments) - example_stage = run_directory / "render" / ".staging-EXAMPLE" - pdf_filename = _pdf_filename(arguments) - requested_shard_names = { - shard.name for shard in _scheduled_shards(arguments, run_directory) - } - works_by_shard: dict[str, list[ShardWork]] = {shard.name: [] for shard in SHARDS} - for phase_number in _scheduled_phase_numbers(arguments, run_directory): - for work in _phase_work_items(arguments, run_directory, phase_number): - works_by_shard[work.shard.name].append(work) - requested_lines = _requested_line_groups(arguments, run_directory) - requested_families = _family_selection(arguments) - madgraph_requested = _madgraph_requested(arguments, run_directory) - shard_jobs = { - shard.name: [ - { - "n": work.final_multiplicity, - "mode": work.owned_mode, - "study_root": str(_work_study_root(run_directory, work)), - "report": str(_work_report_path(run_directory, work)), - "argv": list(_child_command(arguments, run_directory, work)), - "shell_command": shlex.join( - _child_command(arguments, run_directory, work) - ), - } - for work in works_by_shard[shard.name] - ] - for shard in SHARDS - } - commands = { - shard.name: { - "scheduled": shard.name in requested_shard_names, - "phase": shard.phase, - "family": shard.family, - "modes": list(_shard_modes(arguments, run_directory, shard)), - "owned_modes": list(_counted_owned_modes(arguments, run_directory, shard)), - "dependency": list(shard.dependency) if shard.dependency else None, - "claimed_cores": (arguments.candidate_cores if shard.candidate else 1), - "measurement_multiplicities": list( - _measurement_multiplicities(arguments, run_directory, shard) - ), - "protocol_skip_multiplicities": sorted( - set(_selection(arguments)) - - set(_measurement_multiplicities(arguments, run_directory, shard)) - ), - "study_root": str(_shard_study_root(run_directory, shard)), - "report": str(_shard_report_path(run_directory, shard)), - "jobs": shard_jobs[shard.name], - "argv": ( - shard_jobs[shard.name][0]["argv"] if shard_jobs[shard.name] else None - ), - "shell_command": ( - shard_jobs[shard.name][0]["shell_command"] - if shard_jobs[shard.name] - else None - ), - } - for shard in SHARDS - } - strict = ( - set(requested_lines) == set(LINE_GROUPS) - and requested_families == FAMILIES - and _publication_profile(arguments) - ) - render_commands = _render_commands( - arguments, - source_report=_master_report_path(run_directory), - staged_report=example_stage / "report.json", - staged_plots=example_stage / "plots", - staged_pdf=example_stage / pdf_filename, - strict=strict, - madgraph_overlay=_madgraph_overlay_path(run_directory), - ) - return { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "helicity_workload": _helicity_workload(arguments), - "batch_size": arguments.batch_size, - "requested_fill_multiplicities": list(_selection(arguments)), - "requested_process_families": list(requested_families), - "requested_line_groups": list(requested_lines), - "identity": _identity(arguments, run_directory), - "scheduler": { - "total_core_budget": arguments.cores, - "candidate_cores_per_active_candidate_work_item": arguments.candidate_cores, - "baseline_cores_per_active_work_item": 1, - "parallelism": "weighted dependency-aware shard-multiplicity workers", - }, - "shards": commands, - "madgraph": { - "phase": 4, - "applicable": madgraph_requested, - "helicity_workload": _helicity_workload(arguments), - "process_families": list(requested_families), - "measurement_multiplicities": [ - n - for n in _requested_multiplicities(arguments, run_directory) - if any( - madgraph.protocol_measures_multiplicity(family, n) - for family in requested_families - ) - ], - "protocol_scope_multiplicities": [ - n - for n in _requested_multiplicities(arguments, run_directory) - if not any( - madgraph.protocol_measures_multiplicity(family, n) - for family in requested_families - ) - ], - "measurement_multiplicities_by_family": { - family: [ - n - for n in _requested_multiplicities(arguments, run_directory) - if madgraph.protocol_measures_multiplicity(family, n) - ] - for family in requested_families - }, - "protocol_scope_multiplicities_by_family": { - family: [ - n - for n in _requested_multiplicities(arguments, run_directory) - if not madgraph.protocol_measures_multiplicity(family, n) - ] - for family in requested_families - }, - "dependency": ( - "completed pyAmpliCol source cells for the requested MadGraph fill" - if madgraph_requested - else None - ), - "not_applicable_reason": ( - None if madgraph_requested else "madgraph line group not selected" - ), - "report": str(_madgraph_overlay_path(run_directory)), - "argv": ( - list(_madgraph_command(arguments, run_directory)) - if madgraph_requested and arguments.madgraph_root is not None - else None - ), - "shell_command": ( - shlex.join(_madgraph_command(arguments, run_directory)) - if madgraph_requested and arguments.madgraph_root is not None - else None - ), - }, - "outputs": { - "manifest": str(_manifest_path(run_directory)), - "master_report": str(_master_report_path(run_directory)), - "render_pointer": str(run_directory / "render" / "current"), - "final_pdf": str(run_directory / "render" / "current" / pdf_filename), - "final_json": str( - run_directory / "render" / "current" / _json_filename(arguments) - ), - "canonical_pdf": ( - str(_canonical_pdf_path(arguments)) - if _canonical_publication_enabled(arguments) - else None - ), - "canonical_json": ( - str(_canonical_pdf_path(arguments).with_suffix(".json")) - if _canonical_publication_enabled(arguments) - else None - ), - }, - "terminal_render": { - "strict_publication_profile": strict, - "commands": [list(command) for command in render_commands], - "shell_commands": [shlex.join(command) for command in render_commands], - }, - "prerequisites": [ - "Python environment containing pyAmpliCol, progressbar2, colorama, " - "matplotlib, and reportlab", - f"C++ compiler: {arguments.cxx}", - f"Fortran compiler: {arguments.fc}", - f"make: {arguments.make}", - f"legacy AmpliCol checkout: {_absolute(arguments.amplicol_root)}", - f"Reference FFT checkout: {_absolute(arguments.reference_fft_root)}", - ( - f"MadGraph installation: {_absolute(arguments.madgraph_root)}" - if madgraph_requested and arguments.madgraph_root is not None - else ( - "MadGraph installation: REQUIRED (--madgraph-root)" - if madgraph_requested - else "MadGraph installation: not required by selected lines" - ) - ), - ], - } - - -def _canonical_json(value: object) -> bytes: - return (json.dumps(value, indent=2, sort_keys=True, allow_nan=False) + "\n").encode( - "utf-8" - ) - - -def _write_json_atomic(path: Path, value: Mapping[str, Any]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - raw = _canonical_json(value) - if path.is_file() and path.read_bytes() == raw: - return - temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp") - temporary.write_bytes(raw) - temporary.replace(path) - - -def _load_json(path: Path, *, context: str) -> dict[str, Any]: - try: - value = json.loads(path.read_bytes()) - except (OSError, json.JSONDecodeError) as error: - raise ProfilingError(f"cannot read {context} {path}: {error}") from error - if not isinstance(value, dict): - raise ProfilingError(f"{context} {path} must be a JSON object") - return value - - -def _identity_diff(stored: object, requested: object, prefix: str = "") -> list[str]: - if isinstance(stored, Mapping) and isinstance(requested, Mapping): - differences: list[str] = [] - for key in sorted(set(stored) | set(requested)): - child = f"{prefix}.{key}" if prefix else str(key) - if key not in stored: - differences.append(f"{child}: missing -> {requested[key]!r}") - elif key not in requested: - differences.append(f"{child}: {stored[key]!r} -> missing") - else: - differences.extend(_identity_diff(stored[key], requested[key], child)) - return differences - return [] if stored == requested else [f"{prefix}: {stored!r} -> {requested!r}"] - - -def _identity_path_value(identity: object, path: str) -> object: - value = identity - for key in path.split("."): - if not isinstance(value, Mapping): - return None - value = value.get(key) - return value - - -def _identity_difference_path(difference: str) -> str: - return difference.split(":", 1)[0] - - -def _mutable_resource_identity_update_allowed( - stored: object, requested: object, differences: Sequence[str] -) -> bool: - changed_paths = { - _identity_difference_path(difference) for difference in differences - } - if not changed_paths or not changed_paths <= MUTABLE_RESOURCE_IDENTITY_PATHS: - return False - for path in changed_paths: - old = _identity_path_value(stored, path) - new = _identity_path_value(requested, path) - if ( - not isinstance(old, int | float) - or isinstance(old, bool) - or not isinstance(new, int | float) - or isinstance(new, bool) - or float(new) <= 0 - ): - return False - return True - - -def _immutable_identity_differences(differences: Sequence[str]) -> list[str]: - return [ - difference - for difference in differences - if _identity_difference_path(difference) not in MUTABLE_RESOURCE_IDENTITY_PATHS - ] - - -def _create_or_resume_manifest( - arguments: argparse.Namespace, run_directory: Path -) -> dict[str, Any]: - path = _manifest_path(run_directory) - requested_identity = _identity(arguments, run_directory) - if path.is_file(): - manifest = _load_json(path, context="profiling manifest") - if ( - manifest.get("kind") != KIND - or manifest.get("schema_version") != SCHEMA_VERSION - ): - raise ProfilingError("profiling manifest has the wrong schema") - differences = _identity_diff(manifest.get("identity"), requested_identity) - identity_updated = False - if differences: - if _mutable_resource_identity_update_allowed( - manifest.get("identity"), requested_identity, differences - ): - manifest["identity"] = requested_identity - identity_updated = True - else: - preview = "\n ".join(differences[:12]) - raise ProfilingError( - "resume measurement identity differs from the manifest:\n " - + preview - ) - selected = list(_selection(arguments)) - selected_lines = list(_line_selection(arguments)) - selected_families = list(_family_selection(arguments)) - prior = _manifest_int_history( - manifest, "fill_history_multiplicities", "requested_multiplicities" - ) - history = sorted(set(prior) | set(selected)) - prior_lines = _manifest_line_history(manifest) - line_history = [ - line - for line in LINE_CHOICES - if line in set(prior_lines) | set(selected_lines) - ] - prior_families = _manifest_family_history(manifest) - family_history = [ - family - for family in FAMILIES - if family in set(prior_families) | set(selected_families) - ] - updates = { - "requested_multiplicities": selected, - "requested_families": selected_families, - "requested_line_groups": selected_lines, - "active_multiplicities": selected, - "active_families": selected_families, - "active_line_groups": selected_lines, - "fill_history_multiplicities": history, - "process_family_history": family_history, - "line_group_history": line_history, - } - if identity_updated or any( - manifest.get(key) != value for key, value in updates.items() - ): - manifest.update(updates) - _write_json_atomic(path, manifest) - return manifest - selected = list(_selection(arguments)) - selected_lines = list(_line_selection(arguments)) - selected_families = list(_family_selection(arguments)) - manifest = { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "identity": requested_identity, - "initial_scheduler_core_budget": arguments.cores, - "requested_multiplicities": selected, - "requested_families": selected_families, - "requested_line_groups": selected_lines, - "active_multiplicities": selected, - "active_families": selected_families, - "active_line_groups": selected_lines, - "fill_history_multiplicities": selected, - "process_family_history": selected_families, - "line_group_history": selected_lines, - } - _write_json_atomic(path, manifest) - return manifest - - -def _expected_shard_policy( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - final_multiplicity: int | None = None, - *, - modes: Sequence[str] | None = None, -) -> dict[str, object]: - return study.dry_run_plan( - _shard_arguments( - arguments, - run_directory, - shard, - final_multiplicity, - modes=modes, - ) - ) - - -def _pyamplicol_contractions_for_modes( - modes: Sequence[str], -) -> dict[str, list[str]]: - selected: dict[str, list[str]] = {} - for mode in modes: - if mode == "recurrence-direct": - selected.setdefault("recurrence", []).append("direct") - elif mode == "recurrence-fft": - selected.setdefault("recurrence", []).append("symmetric-group-fft") - elif mode == "otf-direct": - selected.setdefault("on-the-fly", []).append("direct") - elif mode == "otf-fft": - selected.setdefault("on-the-fly", []).append("symmetric-group-fft") - return selected - - -def _policy_with_expected_mode_subset( - policy: object, *, family: str, modes: Sequence[str] -) -> object: - if not isinstance(policy, Mapping): - return policy - normalized = copy.deepcopy(dict(policy)) - normalized.pop("run_root", None) - process_families = normalized.get("process_families") - if isinstance(process_families, dict): - family_policy = process_families.get(family) - if isinstance(family_policy, dict): - actual_modes = family_policy.get("modes") - if ( - isinstance(actual_modes, list) - and set(modes).issubset(set(actual_modes)) - ): - family_policy["modes"] = list(modes) - - expected_contractions = _pyamplicol_contractions_for_modes(modes) - contractions = normalized.get("selected_pyamplicol_color_contractions") - if expected_contractions: - if isinstance(contractions, Mapping) and all( - set(values).issubset(set(contractions.get(key, ()))) - for key, values in expected_contractions.items() - ): - normalized["selected_pyamplicol_color_contractions"] = ( - expected_contractions - ) - else: - normalized.pop("selected_pyamplicol_color_contractions", None) - measurement = normalized.get("measurement") - if isinstance(measurement, dict): - for key in ( - "cell_admission_limits", - *study.MUTABLE_RESUME_MEASUREMENT_POLICY_KEYS, - "generation_timeout_seconds", - "memory_policy", - "memory_watchdog_gib", - "requested_memory_ceiling_gib", - "runtime_timeout_seconds", - ): - measurement.pop(key, None) - return normalized - - -def _shard_policy_matches_requested_modes( - stored: object, - expected: object, - *, - family: str, - modes: Sequence[str], -) -> bool: - return _policy_with_expected_mode_subset( - stored, family=family, modes=modes - ) == _policy_with_expected_mode_subset(expected, family=family, modes=modes) - - -def _validate_shard_report( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - report: Mapping[str, Any], - *, - context: str, - final_multiplicity: int | None = None, - modes: Sequence[str] | None = None, - allow_partial_modes: bool = False, -) -> None: - expected_modes = ( - tuple(modes) - if modes is not None - else _shard_modes(arguments, run_directory, shard) - ) - cells = report.get("cells") - if not isinstance(cells, Mapping): - raise ProfilingError(f"{context} has no cells") - family_cells = cells.get(shard.family) - if not isinstance(family_cells, Mapping): - raise ProfilingError(f"{context} mode set differs") - present_modes = tuple(mode for mode in expected_modes if mode in family_cells) - if not present_modes or ( - not allow_partial_modes and set(present_modes) != set(expected_modes) - ): - raise ProfilingError(f"{context} mode set differs") - if report.get("kind") != study.KIND or report.get( - "schema_version" - ) != study.SCHEMA_VERSION or not _shard_policy_matches_requested_modes( - report.get("policy"), - _expected_shard_policy( - arguments, - run_directory, - shard, - final_multiplicity, - modes=present_modes, - ), - family=shard.family, - modes=present_modes, - ): - raise ProfilingError(f"{context} policy/schema differs") - - -def _load_single_shard_report( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - path: Path, - *, - final_multiplicity: int | None = None, - modes: Sequence[str] | None = None, - allow_partial_modes: bool = False, -) -> dict[str, Any]: - report = _load_json(path, context=f"{shard.name} shard report") - _validate_shard_report( - arguments, - run_directory, - shard, - report, - context=f"{shard.name} shard report", - final_multiplicity=final_multiplicity, - modes=modes, - allow_partial_modes=allow_partial_modes, - ) - study.normalize_loaded_failure_cells(report, path.parent) - return report - - -def _mode_set_validation_error(error: ProfilingError) -> bool: - return str(error).endswith(" mode set differs") - - -def _load_compatible_shard_report( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - path: Path, - *, - final_multiplicity: int | None = None, - modes: Sequence[str] | None = None, - allow_partial_modes: bool = False, -) -> dict[str, Any] | None: - try: - return _load_single_shard_report( - arguments, - run_directory, - shard, - path, - final_multiplicity=final_multiplicity, - modes=modes, - allow_partial_modes=allow_partial_modes, - ) - except ProfilingError as error: - if allow_partial_modes: - return None - if not _mode_set_validation_error(error): - raise - try: - return _load_single_shard_report( - arguments, - run_directory, - shard, - path, - final_multiplicity=final_multiplicity, - modes=modes, - allow_partial_modes=True, - ) - except ProfilingError as error: - if _mode_set_validation_error(error): - return None - raise - - -def _merge_cell_record( - target_curve: dict[str, object], - raw_n: str, - cell: Mapping[str, Any], -) -> None: - existing = target_curve.get(raw_n) - if ( - isinstance(existing, Mapping) - and existing.get("status") == "measured" - and cell.get("status") != "measured" - ): - return - target_curve[raw_n] = copy.deepcopy(dict(cell)) - - -def _obsolete_otf_protocol_scope_cell( - arguments: argparse.Namespace, - *, - mode: str, - raw_n: str, - cell: Mapping[str, Any], -) -> bool: - return ( - raw_n.isdigit() - and mode in study.MODE_BY_KEY - and study.MODE_BY_KEY[mode].execution_mode == "on-the-fly" - and int(raw_n) <= arguments.otf_max_multiplicity - and cell.get("failure_category") == "publication-protocol-scope" - ) - - -def _cell_terminal_for_orchestrator(cell: object) -> bool: - return ( - isinstance(cell, Mapping) - and cell.get("status") in ORCHESTRATOR_TERMINAL_CELL_STATUSES - ) - - -def _selected_cells_terminal_for_orchestrator( - report: Mapping[str, Any], - *, - family: str, - modes: Sequence[str], - multiplicities: Sequence[int], -) -> bool: - cells = report.get("cells") - if not isinstance(cells, Mapping): - return False - family_cells = cells.get(family) - if not isinstance(family_cells, Mapping): - return False - for mode in modes: - curve = family_cells.get(mode) - if not isinstance(curve, Mapping): - return False - for final_multiplicity in multiplicities: - if not _cell_terminal_for_orchestrator( - curve.get(str(final_multiplicity)) - ): - return False - return True - - -def _report_modes_for_shard(report: Mapping[str, Any], shard: Shard) -> tuple[str, ...]: - cells = report.get("cells") - if not isinstance(cells, Mapping): - return () - family_cells = cells.get(shard.family) - if not isinstance(family_cells, Mapping): - return () - return tuple(mode for mode in shard.modes if mode in family_cells) - - -def _remove_selected_cells_from_report( - shard: Shard, - report: dict[str, Any], - *, - modes: Sequence[str], - multiplicities: Sequence[int], - statuses: frozenset[str] | None, -) -> set[tuple[str, str, int]]: - removed: set[tuple[str, str, int]] = set() - cells = report.get("cells") - if not isinstance(cells, Mapping): - return removed - family_cells = cells.get(shard.family) - if not isinstance(family_cells, Mapping): - return removed - for mode in modes: - curve = family_cells.get(mode) - if not isinstance(curve, dict): - continue - for final_multiplicity in multiplicities: - raw_n = str(final_multiplicity) - cell = curve.get(raw_n) - if ( - isinstance(cell, Mapping) - and (statuses is None or cell.get("status") in statuses) - ): - del curve[raw_n] - removed.add((shard.family, mode, final_multiplicity)) - return removed - - -def _rewrite_selected_report( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - path: Path, - *, - final_multiplicity: int | None, - modes: Sequence[str], - multiplicities: Sequence[int], - statuses: frozenset[str] | None, - context: str, -) -> set[tuple[str, str, int]]: - if not path.is_file(): - return set() - report = _load_json(path, context=context) - report_modes = _report_modes_for_shard(report, shard) - selected_modes = tuple(mode for mode in modes if mode in report_modes) - if not selected_modes: - return set() - _validate_shard_report( - arguments, - run_directory, - shard, - report, - context=context, - final_multiplicity=final_multiplicity, - modes=report_modes, - allow_partial_modes=True, - ) - study.normalize_loaded_failure_cells(report, path.parent) - removed = _remove_selected_cells_from_report( - shard, - report, - modes=selected_modes, - multiplicities=multiplicities, - statuses=statuses, - ) - if not removed: - return set() - rewritten = study.compose_report( - _shard_arguments( - arguments, - run_directory, - shard, - final_multiplicity, - modes=report_modes, - ), - report["cells"], - ) - _write_json_atomic(path, rewritten) - return removed - - -def _rewrite_retry_report( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - path: Path, - *, - final_multiplicity: int | None, - multiplicities: Sequence[int], -) -> set[tuple[str, str, int]]: - return _rewrite_selected_report( - arguments, - run_directory, - shard, - path, - final_multiplicity=final_multiplicity, - modes=_counted_owned_modes(arguments, run_directory, shard), - multiplicities=multiplicities, - statuses=RETRYABLE_CELL_STATUSES, - context=f"{shard.name} retry report", - ) - - -def _apply_retry_invalidation( - arguments: argparse.Namespace, run_directory: Path -) -> int: - if not arguments.retry: - return 0 - requested = _requested_multiplicities(arguments, run_directory) - removed: set[tuple[str, str, int]] = set() - for shard in _scheduled_shards(arguments, run_directory): - removed.update( - _rewrite_retry_report( - arguments, - run_directory, - shard, - _shard_report_path(run_directory, shard), - final_multiplicity=None, - multiplicities=requested, - ) - ) - for final_multiplicity in requested: - removed.update( - _rewrite_retry_report( - arguments, - run_directory, - shard, - _shard_report_path(run_directory, shard, final_multiplicity), - final_multiplicity=final_multiplicity, - multiplicities=(final_multiplicity,), - ) - ) - for mode in _counted_owned_modes(arguments, run_directory, shard): - removed.update( - _rewrite_retry_report( - arguments, - run_directory, - shard, - _work_report_path( - run_directory, - ShardWork(shard, final_multiplicity, mode), - ), - final_multiplicity=final_multiplicity, - multiplicities=(final_multiplicity,), - ) - ) - return len(removed) - - -def _reject_overwrite_symlinks(path: Path) -> None: - absolute = Path(os.path.abspath(path.expanduser())) - for candidate in (absolute, *absolute.parents): - if candidate.is_symlink(): - raise ProfilingError( - f"refusing --overwrite through symlinked path component: {candidate}" - ) - - -def _prepare_overwrite_work( - arguments: argparse.Namespace, - run_directory: Path, - work: ShardWork, -) -> int: - """Invalidate one selected cell immediately before launching its worker.""" - - if not arguments.overwrite: - return 0 - cell_root = _work_cell_root(run_directory, work) - _reject_overwrite_symlinks(cell_root) - backup: Path | None = None - if cell_root.exists(): - backup = cell_root.with_name( - f".{cell_root.name}.overwrite-{uuid.uuid4().hex}" - ) - cell_root.replace(backup) - - removed: set[tuple[str, str, int]] = set() - try: - report_paths: dict[Path, int | None] = { - _shard_report_path(run_directory, work.shard): None - } - shard_root = run_directory / "shards" / work.shard.name - for pattern in ( - f"cells/n{work.final_multiplicity}/study/runs/*/report.json", - f"mode-cells/*/n{work.final_multiplicity}/study/runs/*/report.json", - ): - report_paths.update( - (path, work.final_multiplicity) for path in shard_root.glob(pattern) - ) - for path, final_multiplicity in sorted( - report_paths.items(), key=lambda item: str(item[0]) - ): - removed.update( - _rewrite_selected_report( - arguments, - run_directory, - work.shard, - path, - final_multiplicity=final_multiplicity, - modes=(work.owned_mode,), - multiplicities=(work.final_multiplicity,), - statuses=None, - context=( - f"{work.shard.name} overwrite report for " - f"{work.shard.family}/{work.owned_mode}/" - f"n{work.final_multiplicity}" - ), - ) - ) - except BaseException: - if backup is not None and not cell_root.exists(): - backup.replace(cell_root) - raise - if backup is not None: - shutil.rmtree(backup) - return len(removed) - - -def _resource_frontier_failure_at( - cell: Mapping[str, Any], fallback_multiplicity: int -) -> int | None: - if cell.get("censors_higher_multiplicities") is not True or cell.get( - "status" - ) not in {"failed", "skipped"}: - return None - failed_at = cell.get("failed_at_n") - if isinstance(failed_at, int) and not isinstance(failed_at, bool): - return failed_at - return fallback_multiplicity - - -def _mode_resource_frontier( - curve: Mapping[str, Any], final_multiplicity: int -) -> int | None: - frontier: int | None = None - for raw_n, cell in curve.items(): - if not str(raw_n).isdigit() or not isinstance(cell, Mapping): - continue - failed_at = _resource_frontier_failure_at(cell, int(raw_n)) - if failed_at is not None and failed_at < final_multiplicity: - frontier = min(frontier if frontier is not None else failed_at, failed_at) - return frontier - - -def _resource_frontier_skip_cell( - arguments: argparse.Namespace, - *, - family: str, - mode: str, - final_multiplicity: int, - failed_at: int, -) -> dict[str, object]: - reason = f"curve censored after resource limit at n={failed_at}" - return study._cell_base( - family, - study.MODE_BY_KEY[mode], - final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) | { - "status": "skipped", - "failure_reason": reason, - "failed_at_n": failed_at, - "censors_higher_multiplicities": True, - } - - -def _apply_resource_frontier_censoring( - arguments: argparse.Namespace, - report: dict[str, Any], - shard: Shard, - *, - modes: Sequence[str], - multiplicities: Sequence[int], -) -> bool: - cells = report["cells"] - assert isinstance(cells, dict) - family_cells = cells[shard.family] - assert isinstance(family_cells, dict) - changed = False - for mode in modes: - curve = family_cells[mode] - assert isinstance(curve, dict) - for final_multiplicity in multiplicities: - frontier = _mode_resource_frontier(curve, final_multiplicity) - if frontier is None: - continue - raw_n = str(final_multiplicity) - existing = curve.get(raw_n) - if isinstance(existing, Mapping): - if ( - existing.get("status") in {"failed", "skipped"} - and existing.get("censors_higher_multiplicities") is True - ): - continue - if existing.get("status") == "measured": - continue - curve[raw_n] = _resource_frontier_skip_cell( - arguments, - family=shard.family, - mode=mode, - final_multiplicity=final_multiplicity, - failed_at=frontier, - ) - changed = True - return changed - - -def _dependency_skip_cell( - arguments: argparse.Namespace, - *, - shard: Shard, - mode: str, - final_multiplicity: int, - dependency_name: str, - dependency_mode: str, - dependency_cell: Mapping[str, Any], -) -> dict[str, object]: - failed_at = _resource_frontier_failure_at(dependency_cell, final_multiplicity) - dependency: dict[str, object] = { - "shard": dependency_name, - "family": shard.family, - "mode": dependency_mode, - "n": final_multiplicity, - "status": str(dependency_cell.get("status")), - } - if failed_at is not None: - dependency["resource_failure_at_n"] = failed_at - return study._cell_base( - shard.family, - study.MODE_BY_KEY[mode], - final_multiplicity, - sum_helicities=arguments.compare_helicity_sums, - ) | { - "status": "skipped", - "failure_category": "dependency-unavailable", - "failure_reason": ( - f"{dependency_mode} baseline/input unavailable because " - f"{dependency_name} recorded " - f"{dependency_cell.get('status')} at n={final_multiplicity}" - ), - "censors_higher_multiplicities": False, - "dependency": dependency, - } - - -def _apply_dependency_skips( - arguments: argparse.Namespace, - run_directory: Path, - report: dict[str, Any], - shard: Shard, - *, - multiplicities: Sequence[int], -) -> bool: - if shard.dependency is None: - return False - dependency_name, dependency_mode = shard.dependency - dependency_shard = SHARD_BY_NAME[dependency_name] - source = _load_shard_report(arguments, run_directory, dependency_shard) - if source is None: - return False - source_cells = source["cells"] - target_cells = report["cells"] - assert isinstance(source_cells, Mapping) - assert isinstance(target_cells, dict) - source_family = source_cells[shard.family] - target_family = target_cells[shard.family] - assert isinstance(source_family, Mapping) - assert isinstance(target_family, dict) - dependency_curve = source_family[dependency_mode] - assert isinstance(dependency_curve, Mapping) - changed = False - for final_multiplicity in multiplicities: - if not _selected_cells_terminal_for_orchestrator( - source, - family=shard.family, - modes=(dependency_mode,), - multiplicities=(final_multiplicity,), - ): - continue - dependency_cell = dependency_curve.get(str(final_multiplicity)) - if ( - not isinstance(dependency_cell, Mapping) - or dependency_cell.get("status") == "measured" - ): - continue - for mode in _shard_owned_modes(arguments, run_directory, shard): - curve = target_family[mode] - assert isinstance(curve, dict) - if str(final_multiplicity) in curve: - continue - curve[str(final_multiplicity)] = _dependency_skip_cell( - arguments, - shard=shard, - mode=mode, - final_multiplicity=final_multiplicity, - dependency_name=dependency_name, - dependency_mode=dependency_mode, - dependency_cell=dependency_cell, - ) - changed = True - return changed - - -def _load_shard_report( - arguments: argparse.Namespace, - run_directory: Path, - shard: Shard, - *, - required: bool = False, - modes: Sequence[str] | None = None, - allow_partial_modes: bool = False, -) -> dict[str, Any] | None: - shard_modes = ( - tuple(modes) - if modes is not None - else _shard_modes(arguments, run_directory, shard) - ) - sources: list[tuple[dict[str, Any], int | None]] = [] - aggregate_path = _shard_report_path(run_directory, shard) - if aggregate_path.is_file(): - aggregate = _load_compatible_shard_report( - arguments, - run_directory, - shard, - aggregate_path, - final_multiplicity=None, - modes=shard_modes, - allow_partial_modes=allow_partial_modes, - ) - if aggregate is not None: - sources.append((aggregate, None)) - cell_reports: dict[Path, int] = {} - for path in (run_directory / "shards" / shard.name / "cells").glob( - "n*/study/runs/*/report.json" - ): - raw_n = path.parent.parent.parent.parent.name - if raw_n.startswith("n") and raw_n[1:].isdigit(): - cell_reports[path] = int(raw_n[1:]) - for path in (run_directory / "shards" / shard.name / "mode-cells").glob( - "*/n*/study/runs/*/report.json" - ): - raw_n = path.parent.parent.parent.parent.name - if raw_n.startswith("n") and raw_n[1:].isdigit(): - cell_reports[path] = int(raw_n[1:]) - for final_multiplicity in _requested_multiplicities(arguments, run_directory): - legacy_path = _shard_report_path(run_directory, shard, final_multiplicity) - if legacy_path.is_file(): - cell_reports[legacy_path] = final_multiplicity - for mode in shard_modes: - if mode not in shard.owned_modes: - continue - work = ShardWork(shard, final_multiplicity, mode) - work_path = _work_report_path(run_directory, work) - if work_path.is_file(): - cell_reports[work_path] = final_multiplicity - for path, final_multiplicity in sorted( - cell_reports.items(), key=lambda item: (item[1], str(item[0])) - ): - if not path.is_file(): - continue - report = _load_compatible_shard_report( - arguments, - run_directory, - shard, - path, - final_multiplicity=final_multiplicity, - modes=shard_modes, - allow_partial_modes=allow_partial_modes, - ) - if report is not None: - sources.append((report, final_multiplicity)) - if not sources: - if required: - raise ProfilingError(f"required shard report is missing: {aggregate_path}") - return None - curve_sources: dict[str, dict[str, dict[str, object]]] = { - shard.family: {mode: {} for mode in shard_modes} - } - target_family = curve_sources[shard.family] - for source, source_multiplicity in sources: - cells = source["cells"] - assert isinstance(cells, Mapping) - family_cells = cells[shard.family] - assert isinstance(family_cells, Mapping) - for mode in shard_modes: - source_curve = family_cells.get(mode) - if not isinstance(source_curve, Mapping): - continue - target_curve = target_family[mode] - if source_multiplicity is None: - for raw_n, cell in source_curve.items(): - if ( - isinstance(raw_n, str) - and raw_n.isdigit() - and isinstance(cell, Mapping) - and not _obsolete_otf_protocol_scope_cell( - arguments, - mode=mode, - raw_n=raw_n, - cell=cell, - ) - ): - _merge_cell_record(target_curve, raw_n, cell) - continue - cell = source_curve.get(str(source_multiplicity)) - if isinstance(cell, Mapping) and not _obsolete_otf_protocol_scope_cell( - arguments, - mode=mode, - raw_n=str(source_multiplicity), - cell=cell, - ): - _merge_cell_record( - target_curve, str(source_multiplicity), cell - ) - report = study.compose_report( - _shard_arguments(arguments, run_directory, shard, modes=shard_modes), - curve_sources, - ) - _apply_resource_frontier_censoring( - arguments, - report, - shard, - modes=shard_modes, - multiplicities=_requested_multiplicities(arguments, run_directory), - ) - return study.compose_report( - _shard_arguments(arguments, run_directory, shard, modes=shard_modes), - report["cells"], - ) - - -def _publish_shard_report( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> dict[str, Any] | None: - report = _load_shard_report(arguments, run_directory, shard) - if report is not None: - _write_json_atomic(_shard_report_path(run_directory, shard), report) - return report - - -def _selected_shard_complete( - arguments: argparse.Namespace, - shard: Shard, - report: Mapping[str, Any] | None, - *, - multiplicities: Sequence[int] | None = None, -) -> bool: - return ( - report is not None - and not str(report.get("status", "")).startswith("stopped") - and _selected_cells_terminal_for_orchestrator( - report, - family=shard.family, - modes=_counted_owned_modes(arguments, _run_directory(arguments), shard), - multiplicities=( - _selection(arguments) - if multiplicities is None - else tuple(multiplicities) - ), - ) - ) - - -def _selected_work_complete( - arguments: argparse.Namespace, - run_directory: Path, - work: ShardWork, - report: Mapping[str, Any] | None, -) -> bool: - return report is not None and _selected_cells_terminal_for_orchestrator( - report, - family=work.shard.family, - modes=_work_owned_modes(arguments, run_directory, work), - multiplicities=(work.final_multiplicity,), - ) - - -def _phase_work_items( - arguments: argparse.Namespace, run_directory: Path, phase_number: int -) -> tuple[ShardWork, ...]: - works = [ - ShardWork(shard, final_multiplicity, owned_mode) - for final_multiplicity in _requested_multiplicities(arguments, run_directory) - for shard in _scheduled_shards(arguments, run_directory) - if shard.phase == phase_number - for owned_mode in _counted_owned_modes(arguments, run_directory, shard) - if final_multiplicity - in _work_measurement_multiplicities( - arguments, - run_directory, - ShardWork(shard, final_multiplicity, owned_mode), - ) - ] - return tuple( - sorted( - works, - key=lambda work: ( - work.final_multiplicity, - 0 if work.shard.name == "gg-amplicol" else 1, - work.shard.name, - ), - ) - ) - - -def _scheduled_phase_numbers( - arguments: argparse.Namespace, run_directory: Path -) -> tuple[int, ...]: - return tuple( - sorted( - { - shard.phase - for shard in _scheduled_shards(arguments, run_directory) - if _counted_owned_modes(arguments, run_directory, shard) - } - ) - ) - - -def _work_dependency_ready( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> bool: - if work.shard.dependency is None: - return True - dependency_name, dependency_mode = work.shard.dependency - dependency_shard = SHARD_BY_NAME[dependency_name] - source = _load_shard_report(arguments, run_directory, dependency_shard) - return source is not None and _selected_cells_terminal_for_orchestrator( - source, - family=work.shard.family, - modes=(dependency_mode,), - multiplicities=(work.final_multiplicity,), - ) - - -def _empty_cell_report( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> dict[str, Any]: - return study.compose_report(_work_arguments(arguments, run_directory, work), {}) - - -def _project_work_report( - arguments: argparse.Namespace, - run_directory: Path, - work: ShardWork, - report: Mapping[str, Any], -) -> dict[str, Any]: - cells = report.get("cells") - family_cells = cells.get(work.shard.family) if isinstance(cells, Mapping) else None - projected = { - work.shard.family: { - mode: copy.deepcopy(dict(curve)) - for mode in _work_modes(arguments, run_directory, work) - if isinstance(family_cells, Mapping) - and isinstance((curve := family_cells.get(mode)), Mapping) - } - } - return study.compose_report( - _work_arguments(arguments, run_directory, work), projected - ) - - -def _load_cell_report( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> dict[str, Any]: - path = _work_report_path(run_directory, work) - if not path.is_file(): - legacy_path = _shard_report_path( - run_directory, work.shard, work.final_multiplicity - ) - if legacy_path.is_file() and legacy_path != path: - return _project_work_report( - arguments, - run_directory, - work, - _load_single_shard_report( - arguments, - run_directory, - work.shard, - legacy_path, - final_multiplicity=work.final_multiplicity, - modes=_work_modes(arguments, run_directory, work), - ), - ) - return _empty_cell_report(arguments, run_directory, work) - return _project_work_report( - arguments, - run_directory, - work, - _load_single_shard_report( - arguments, - run_directory, - work.shard, - path, - final_multiplicity=work.final_multiplicity, - modes=_work_modes(arguments, run_directory, work), - ), - ) - - -def _seed_cell_inputs( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> None: - report = _load_cell_report(arguments, run_directory, work) - target_cells = report["cells"] - assert isinstance(target_cells, dict) - target_family = target_cells[work.shard.family] - assert isinstance(target_family, dict) - - existing = _load_shard_report(arguments, run_directory, work.shard) - if existing is not None: - existing_cells = existing["cells"] - assert isinstance(existing_cells, Mapping) - existing_family = existing_cells[work.shard.family] - assert isinstance(existing_family, Mapping) - for mode in _work_owned_modes(arguments, run_directory, work): - source_curve = existing_family[mode] - target_curve = target_family[mode] - assert isinstance(source_curve, Mapping) - assert isinstance(target_curve, dict) - target_curve.update(copy.deepcopy(dict(source_curve))) - - if work.shard.dependency is not None: - dependency_name, dependency_mode = work.shard.dependency - dependency_shard = SHARD_BY_NAME[dependency_name] - source = _load_shard_report( - arguments, run_directory, dependency_shard, required=True - ) - if not _selected_cells_terminal_for_orchestrator( - source, - family=work.shard.family, - modes=(dependency_mode,), - multiplicities=(work.final_multiplicity,), - ): - raise ProfilingError( - f"dependency {dependency_name} has not completed " - f"{work.shard.family}/{dependency_mode}/n{work.final_multiplicity}" - ) - source_cells = source["cells"] - assert isinstance(source_cells, Mapping) - source_family = source_cells[work.shard.family] - assert isinstance(source_family, Mapping) - dependency_curve = source_family[dependency_mode] - target_curve = target_family[dependency_mode] - assert isinstance(dependency_curve, Mapping) - assert isinstance(target_curve, dict) - dependency_cell = dependency_curve.get(str(work.final_multiplicity)) - if isinstance(dependency_cell, Mapping): - target_curve[str(work.final_multiplicity)] = copy.deepcopy( - dict(dependency_cell) - ) - - report["status"] = "running" - _write_json_atomic(_work_report_path(run_directory, work), report) - - -def _seed_protocol_scope( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> None: - owned_modes = _shard_owned_modes(arguments, run_directory, shard) - if not any(mode.startswith("otf-") for mode in owned_modes): - return - target = _shard_report_path(run_directory, shard) - namespace = _shard_arguments(arguments, run_directory, shard) - report = _load_shard_report( - arguments, run_directory, shard - ) or study.compose_report(namespace, {}) - if study.apply_protocol_scope_cells( - report, - family=shard.family, - modes=owned_modes, - multiplicities=_requested_multiplicities(arguments, run_directory), - maximum_multiplicity=arguments.otf_max_multiplicity, - ): - report["status"] = "running" - _write_json_atomic(target, report) - - -def _publication_profile(arguments: argparse.Namespace) -> bool: - run_directory = _run_directory(arguments) - namespace = _master_arguments( - _manifest_backed_arguments(arguments, run_directory), run_directory - ) - return publication.campaign_policy_is_publication_profile( - study.compose_report(namespace, {}) - ) - - -def _report_publication_profile(report: Mapping[str, Any]) -> bool: - return report.get( - "status" - ) in TERMINAL_STATUSES and publication.campaign_policy_is_publication_profile( - report - ) - - -def _compose_master( - arguments: argparse.Namespace, - run_directory: Path, - *, - active: Sequence[str] = (), - halt_reason: str | None = None, -) -> dict[str, Any]: - compose_arguments = _composition_arguments(arguments, run_directory) - namespace = _master_arguments(compose_arguments, run_directory) - reports: dict[str, dict[str, Any] | None] = {} - shard_status: dict[str, str] = {} - for shard in SHARDS: - shard_modes = _shard_modes(compose_arguments, run_directory, shard) - shard_report = ( - _load_shard_report( - compose_arguments, - run_directory, - shard, - modes=shard_modes, - allow_partial_modes=True, - ) - if shard_modes - else None - ) - reports[shard.name] = shard_report - shard_status[shard.name] = ( - str(shard_report.get("status")) if shard_report is not None else "pending" - ) - curve_sources: dict[str, dict[str, Mapping[str, object]]] = { - "gg": {}, - "ddbar": {}, - } - for family in FAMILIES: - for mode in publication.FAMILY_MODES[family]: - owner = SHARD_BY_NAME[MODE_OWNER[(family, mode)]] - owner_report = reports[owner.name] - if owner_report is None: - continue - owner_cells = owner_report["cells"] - assert isinstance(owner_cells, Mapping) - owner_family = owner_cells[family] - assert isinstance(owner_family, Mapping) - if mode not in owner_family: - continue - curve = owner_family[mode] - assert isinstance(curve, Mapping) - curve_sources[family][mode] = curve - - report = study.compose_report( - namespace, - curve_sources, - halt_reason=halt_reason, - ) - report["measurement_host"] = madgraph.measurement_host_identity() - policy = report["policy"] - assert isinstance(policy, dict) - measurement = policy["measurement"] - assert isinstance(measurement, dict) - measurement["schedule_order"] = ( - "dependency-ordered-parallel-shard-multiplicity-workers" - ) - plot = policy.setdefault("plot", {}) - assert isinstance(plot, dict) - if arguments.compare_helicity_sums: - plot["notes"] = [ - "Complete physical-helicity-summed matrix-element workload; " - "MadGraph standalone uses generated SMATRIX with USERHEL=-1; " - "warmed GOODHEL pruning remains enabled." - ] - elif not _publication_profile(compose_arguments): - plot["notes"] = [ - "Cluster scan with configured per-cell resource caps; this is not the " - "canonical 30-GiB/one-hour publication profile." - ] - report["profiling_orchestration"] = { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "shard_status": shard_status, - "active_shards": list(active), - "total_core_budget": arguments.cores, - "candidate_optimization_cores": arguments.candidate_cores, - } - return report - - -def _publish_master( - arguments: argparse.Namespace, - run_directory: Path, - *, - active: Sequence[str] = (), - halt_reason: str | None = None, -) -> dict[str, Any]: - report = _compose_master( - arguments, run_directory, active=active, halt_reason=halt_reason - ) - _write_json_atomic(_master_report_path(run_directory), report) - return report - - -def _completed_cells(report: Mapping[str, Any]) -> int: - cells = report.get("cells") - if not isinstance(cells, Mapping): - return 0 - return sum( - len(mode_cells) - for family_cells in cells.values() - if isinstance(family_cells, Mapping) - for mode_cells in family_cells.values() - if isinstance(mode_cells, Mapping) - ) - - -def _selected_cell_identities( - arguments: argparse.Namespace, - *, - multiplicities: Sequence[int] | None = None, -) -> tuple[CellIdentity, ...]: - run_directory = _run_directory(arguments) - requested = ( - _selection(arguments) if multiplicities is None else tuple(multiplicities) - ) - return tuple( - (shard.family, mode, final_multiplicity) - for shard in _scheduled_shards(arguments, run_directory) - for mode in _counted_owned_modes(arguments, run_directory, shard) - for final_multiplicity in requested - ) - - -def _cell_identity_terminal( - report: Mapping[str, Any], identity: CellIdentity -) -> bool: - family, mode, final_multiplicity = identity - return _selected_cells_terminal_for_orchestrator( - report, - family=family, - modes=(mode,), - multiplicities=(final_multiplicity,), - ) - - -def _selected_completed_cells( - arguments: argparse.Namespace, - report: Mapping[str, Any], - *, - multiplicities: Sequence[int] | None = None, - ignored_cells: set[CellIdentity] | frozenset[CellIdentity] = frozenset(), -) -> int: - return sum( - identity not in ignored_cells and _cell_identity_terminal(report, identity) - for identity in _selected_cell_identities( - arguments, multiplicities=multiplicities - ) - ) - - -def _selected_master_complete( - arguments: argparse.Namespace, - report: Mapping[str, Any], - *, - multiplicities: Sequence[int] | None = None, - ignored_cells: set[CellIdentity] | frozenset[CellIdentity] = frozenset(), -) -> bool: - return not str(report.get("status", "")).startswith("stopped") and all( - identity not in ignored_cells and _cell_identity_terminal(report, identity) - for identity in _selected_cell_identities( - arguments, multiplicities=multiplicities - ) - ) - - -def _selected_pending_cells( - arguments: argparse.Namespace, - report: Mapping[str, Any], - *, - multiplicities: Sequence[int] | None = None, - ignored_cells: set[CellIdentity] | frozenset[CellIdentity] = frozenset(), -) -> int: - return sum( - identity in ignored_cells or not _cell_identity_terminal(report, identity) - for identity in _selected_cell_identities( - arguments, multiplicities=multiplicities - ) - ) - - -def _run_checked( - command: Sequence[str], *, environment: Mapping[str, str] | None = None -) -> None: - completed = subprocess.run( - tuple(command), - check=False, - env=environment, - stdout=subprocess.PIPE, - text=True, - ) - if completed.returncode != 0: - stdout = completed.stdout.strip() - detail = ( - f"command failed with status {completed.returncode}: {shlex.join(command)}" - ) - if stdout: - detail = f"{detail}\nstdout:\n{stdout}" - raise ProfilingError(detail) - - -def _source_snapshot(path: Path) -> tuple[bytes, dict[str, Any], str]: - try: - raw = path.read_bytes() - report = json.loads(raw) - except (OSError, json.JSONDecodeError) as error: - raise ProfilingError( - f"cannot freeze campaign report {path}: {error}" - ) from error - if not isinstance(report, dict): - raise ProfilingError("campaign report must be a JSON object") - return raw, report, hashlib.sha256(raw).hexdigest() - - -def _fallback_render_candidates() -> tuple[Path, ...]: - """Return legacy/current campaign reports eligible for implicit rendering.""" - - study_root = CANONICAL_RESULTS_ROOT / "fft-scaling-study" - profiling_root = CANONICAL_RESULTS_ROOT / "fft-profiling" / "runs" - candidates = { - *study_root.joinpath("data").glob("campaign-report*.json"), - *study_root.joinpath("raw", "runs").glob("*/report.json"), - *profiling_root.glob("*/master/runs/*/report.json"), - *profiling_root.glob("*/composites/*/report.json"), - *profiling_root.glob("*/source-snapshots/*/report.json"), - } - # A render generation is an immutable report snapshot. Discover the few - # structural nesting depths produced by the orchestrator and isolated - # extension tooling without recursively walking generated artifacts. - for depth in range(1, 4): - prefix = "/".join("*" for _ in range(depth)) - candidates.update( - profiling_root.glob(f"{prefix}/render/generations/*/report.json") - ) - return tuple(sorted((_absolute(path) for path in candidates), key=str)) - - -def _fallback_madgraph_candidates() -> tuple[Path, ...]: - """Return discoverable terminal and partial MadGraph overlays.""" - - study_root = CANONICAL_RESULTS_ROOT / "fft-scaling-study" - profiling_root = CANONICAL_RESULTS_ROOT / "fft-profiling" / "runs" - candidates = { - *study_root.joinpath("data").glob("*madgraph*overlay*.json"), - *profiling_root.glob("*/overlay.json"), - *profiling_root.glob("*/overlay.progress.json"), - *profiling_root.glob("*/madgraph/overlay.json"), - *profiling_root.glob("*/madgraph/overlay.progress.json"), - } - return tuple(sorted((_absolute(path) for path in candidates), key=str)) - - -def _render_inventory( - report: Mapping[str, Any], *, requested: set[int] -) -> tuple[int, int, int, int, int]: - measured: set[tuple[str, str, int]] = set() - recorded: set[tuple[str, str, int]] = set() - madgraph_measured: set[tuple[str, str, int]] = set() - for section in ("cells", "runtime_series"): - families = report.get(section) - if not isinstance(families, Mapping): - continue - for family, family_cells in families.items(): - if not isinstance(family_cells, Mapping): - continue - for mode, mode_cells in family_cells.items(): - if not isinstance(mode_cells, Mapping): - continue - for raw_n, cell in mode_cells.items(): - if not str(raw_n).isdigit() or not isinstance(cell, Mapping): - continue - identity = (str(family), str(mode), int(raw_n)) - recorded.add(identity) - if cell.get("status") == "measured": - measured.add(identity) - if mode == "madgraph-standalone": - madgraph_measured.add(identity) - return ( - len({identity for identity in measured if identity[2] in requested}), - len({identity for identity in madgraph_measured if identity[2] in requested}), - len({identity for identity in recorded if identity[2] in requested}), - len(measured), - len(recorded), - ) - - -def _render_candidate_score( - arguments: argparse.Namespace, - report: Mapping[str, Any], - *, - source: Path, - overlay: Path | None, -) -> tuple[int, int, int, int, int, int, int, int, str, str]: - requested = set(_selection(arguments)) - policy = report.get("policy") - multiplicities = ( - policy.get("final_state_multiplicities") - if isinstance(policy, Mapping) - else None - ) - observed = ( - {int(value) for value in multiplicities} - if isinstance(multiplicities, list) - and all( - isinstance(value, int) and not isinstance(value, bool) - for value in multiplicities - ) - else set() - ) - measured, madgraph_measured, recorded, measured_all, recorded_all = ( - _render_inventory(report, requested=requested) - ) - overlay_kind = "" - if overlay is not None: - with contextlib.suppress(ProfilingError): - overlay_kind = str( - _load_json(overlay, context="MadGraph render overlay").get("kind", "") - ) - return ( - measured, - madgraph_measured, - measured_all, - recorded, - recorded_all, - int(requested <= observed), - len(observed & requested), - int(overlay_kind == madgraph.KIND), - str(source), - str(overlay or ""), - ) - - -def _compatible_render_report( - arguments: argparse.Namespace, path: Path -) -> dict[str, Any] | None: - try: - _raw, report, _digest = _source_snapshot(path) - if ( - report.get("kind") != study.KIND - or report.get("schema_version") != study.SCHEMA_VERSION - or not isinstance(report.get("cells"), Mapping) - ): - return None - _validate_render_workload(arguments, report) - if report.get("measurement_host") is None and _has_madgraph_series(report): - _append_plot_note(report, LEGACY_MADGRAPH_NOTE) - except (OSError, ProfilingError, TypeError, ValueError): - return None - return report - - -def _implicit_render_selection( - arguments: argparse.Namespace, run_directory: Path -) -> RenderSelection: - primary = _master_report_path(run_directory) - candidates = {primary, *_fallback_render_candidates()} - overlays = _fallback_madgraph_candidates() - ranked: list[ - tuple[ - tuple[int, int, int, int, int, int, int, int, str, str], - RenderSelection, - ] - ] = [] - for source in sorted(candidates, key=str): - if not source.is_file(): - continue - report = _compatible_render_report(arguments, source) - if report is None: - continue - variants: list[tuple[dict[str, Any], Path | None]] = [(report, None)] - for overlay in overlays: - enriched = copy.deepcopy(report) - try: - _attach_partial_overlay(enriched, overlay) - except ProfilingError: - continue - variants.append((enriched, overlay)) - for candidate_report, overlay in variants: - ranked.append( - ( - _render_candidate_score( - arguments, - candidate_report, - source=source, - overlay=overlay, - ), - RenderSelection(source=source, overlay=overlay), - ) - ) - if not ranked: - return RenderSelection(source=primary, overlay=None) - return max(ranked, key=lambda item: item[0])[1] - - -def _fallback_render_source(arguments: argparse.Namespace) -> Path | None: - """Choose the richest compatible report for an otherwise bare render.""" - - primary = _master_report_path(_run_directory(arguments)) - selection = _implicit_render_selection(arguments, _run_directory(arguments)) - return selection.source if selection.source != primary else None - - -def _render_source(arguments: argparse.Namespace, run_directory: Path) -> Path: - if arguments.campaign_report is not None: - return _absolute(arguments.campaign_report) - primary = _master_report_path(run_directory) - if arguments.output is not None: - return primary - return _implicit_render_selection(arguments, run_directory).source - - -def _validate_render_workload( - arguments: argparse.Namespace, report: Mapping[str, Any] -) -> None: - try: - observed = study.report_helicity_workload(report) - except study.StudyError as error: - raise ProfilingError(f"invalid campaign helicity workload: {error}") from error - expected = _helicity_workload(arguments) - if observed != expected: - raise ProfilingError( - f"requested {expected!r} helicity workload but the frozen campaign " - f"report declares {observed!r}; select the matching " - "--compare-helicity-sums setting" - ) - - -def _has_madgraph_series(report: Mapping[str, Any]) -> bool: - for section in ("cells", "runtime_series"): - families = report.get(section) - if not isinstance(families, Mapping): - continue - if any( - isinstance(family, Mapping) and "madgraph-standalone" in family - for family in families.values() - ): - return True - return False - - -def _append_plot_note(report: dict[str, Any], note: str) -> None: - policy = report.get("policy") - if not isinstance(policy, dict): - return - plot = policy.setdefault("plot", {}) - if not isinstance(plot, dict): - return - raw_notes = plot.get("notes") - notes = [str(item) for item in raw_notes] if isinstance(raw_notes, list) else [] - if note not in notes: - notes.append(note) - plot["notes"] = notes - - -def _legacy_madgraph_host_matches_current(value: object) -> bool: - legacy_keys = {"system", "machine", "python"} - if not isinstance(value, Mapping) or set(value) != legacy_keys: - return False - current = madgraph.measurement_host_identity() - return all(value[key] == current[key] for key in legacy_keys) - - -def _attach_partial_overlay(report: dict[str, Any], path: Path) -> None: - raw, payload, digest = _source_snapshot(path) - report.setdefault("summary", {}) - try: - if payload.get("kind") == madgraph.PROGRESS_KIND: - with tempfile.TemporaryDirectory(prefix="fft-mg-progress-") as directory: - frozen_progress = Path(directory) / "progress.json" - frozen_progress.write_bytes(raw) - payload = madgraph.load_runtime_progress(frozen_progress) - raw_campaign_host = report.get("measurement_host") - if raw_campaign_host is not None: - campaign_host = madgraph.validate_measurement_host( - raw_campaign_host, context="campaign measurement_host" - ) - overlay_host = madgraph.validate_measurement_host( - payload.get("host"), context="MadGraph overlay host" - ) - if campaign_host != overlay_host: - raise madgraph.SelectedMadGraphError( - "campaign and MadGraph overlay use different measurement hosts" - ) - elif not _legacy_madgraph_host_matches_current(payload.get("host")): - raise madgraph.SelectedMadGraphError( - "legacy MadGraph overlay does not match this workstation" - ) - selected.apply_runtime_series_source( - report, - selected.SourceReport( - key=( - "madgraph-progress" - if payload.get("kind") == madgraph.PROGRESS_KIND - else "madgraph-overlay" - ), - path=path, - sha256=digest, - payload=payload, - ), - ) - if raw_campaign_host is None: - _append_plot_note(report, LEGACY_MADGRAPH_NOTE) - overlay_policy = payload.get("policy") - if ( - isinstance(overlay_policy, Mapping) - and madgraph._declared_helicity_workload(overlay_policy) == "sum" - ): - report_policy = report.get("policy") - if isinstance(report_policy, dict): - plot = report_policy.setdefault("plot", {}) - if isinstance(plot, dict): - raw_notes = plot.get("notes") - notes = ( - [str(note) for note in raw_notes] - if isinstance(raw_notes, list) - else [] - ) - notes = [ - note - for note in notes - if not ( - "MadGraph" in note - and ( - "omitted" in note.lower() - or "fixed-helicity" in note.lower() - ) - ) - ] - replacement = ( - "MadGraph standalone uses generated SMATRIX with " - "USERHEL=-1; warmed GOODHEL pruning remains enabled." - ) - if replacement not in notes: - notes.append(replacement) - plot["notes"] = notes - except ( - KeyError, - selected.CompositeError, - madgraph.SelectedMadGraphError, - ) as error: - raise ProfilingError(f"invalid MadGraph overlay {path}: {error}") from error - - -def _matching_madgraph_overlay( - arguments: argparse.Namespace, - run_directory: Path, - *, - require_exact: bool = True, -) -> Path | None: - path = _madgraph_overlay_path(run_directory) - if not path.is_file(): - return None - try: - payload = _load_json(path, context="MadGraph overlay") - except ProfilingError: - return None - policy = payload.get("policy") - raw_multiplicities = ( - policy.get("final_state_multiplicities") - if isinstance(policy, Mapping) - else None - ) - try: - overlay_workload = ( - madgraph._declared_helicity_workload(policy) - if isinstance(policy, Mapping) - else None - ) - except madgraph.SelectedMadGraphError: - return None - try: - overlay_host = madgraph.validate_measurement_host( - payload.get("host"), context="MadGraph overlay host" - ) - except madgraph.SelectedMadGraphError: - if require_exact: - return None - # Historical overlays remain usable for explicitly nonterminal - # anytime rendering, but can never enter the strict final merger. - if not _legacy_madgraph_host_matches_current(payload.get("host")): - return None - overlay_host = None - if ( - not isinstance(policy, Mapping) - or overlay_workload != _helicity_workload(arguments) - or ( - overlay_host is not None - and overlay_host != madgraph.measurement_host_identity() - ) - or policy.get("maximum_measured_multiplicity") - != madgraph.MAX_PROTOCOL_MEASURED_MULTIPLICITY - or policy.get("family_maximum_measured_multiplicity") - != madgraph.protocol_measured_multiplicity_limits() - or policy.get("higher_multiplicity_policy") != "not-applicable-protocol-scope" - ): - return None - if ( - not isinstance(raw_multiplicities, list) - or not raw_multiplicities - or any(not isinstance(value, int) for value in raw_multiplicities) - ): - return None - requested = _requested_multiplicities(arguments, run_directory) - observed = tuple(raw_multiplicities) - raw_families = policy.get("selected_process_families") - if isinstance(raw_families, list) and set(raw_families) < set( - _family_selection(arguments) - ): - return None - if require_exact: - if observed != requested: - return None - elif observed != tuple(value for value in requested if value in set(observed)): - return None - return path - - -def _madgraph_render_source( - arguments: argparse.Namespace, run_directory: Path -) -> Path | None: - progress = _matching_madgraph_progress(arguments, run_directory) - if progress is not None and progress.get("status") == "running": - return _madgraph_progress_path(run_directory) - terminal = _matching_madgraph_overlay(arguments, run_directory, require_exact=False) - if terminal is not None: - return terminal - if progress is not None: - return _madgraph_progress_path(run_directory) - return None - - -def _publish_render_generation( - stage: Path, render_root: Path, digest: str, pdf_filename: str -) -> Path: - generations = render_root / "generations" - generations.mkdir(parents=True, exist_ok=True) - destination = generations / f"{digest[:16]}-{uuid.uuid4().hex[:8]}" - stage.replace(destination) - current = render_root / "current" - if current.exists() and not current.is_symlink(): - raise ProfilingError( - f"refusing to replace non-symlink render pointer: {current}" - ) - temporary_link = render_root / f".current-{uuid.uuid4().hex}.tmp" - relative = os.path.relpath(destination, render_root) - os.symlink(relative, temporary_link) - os.replace(temporary_link, current) - return current / pdf_filename - - -def _publish_canonical_pdf(source: Path, arguments: argparse.Namespace) -> Path: - destination = _canonical_pdf_path(arguments) - destination.parent.mkdir(parents=True, exist_ok=True) - for source_path, destination_path in ( - (source, destination), - (source.with_suffix(".json"), destination.with_suffix(".json")), - ): - if not source_path.is_file(): - raise ProfilingError(f"canonical render source is missing: {source_path}") - temporary = destination_path.with_name( - f".{destination_path.name}.{os.getpid()}.{uuid.uuid4().hex[:8]}.tmp" - ) - try: - shutil.copyfile(source_path, temporary) - os.replace(temporary, destination_path) - finally: - with contextlib.suppress(FileNotFoundError): - temporary.unlink() - return destination - - -def render_snapshot( - arguments: argparse.Namespace, *, renderer_preflight: bool = True -) -> Path: - run_directory = _run_directory(arguments) - lock = _acquire_render_lock(run_directory) - try: - return _render_snapshot_locked( - arguments, - run_directory=run_directory, - renderer_preflight=renderer_preflight, - ) - finally: - lock.close() - - -def _render_snapshot_locked( - arguments: argparse.Namespace, - *, - run_directory: Path, - renderer_preflight: bool, -) -> Path: - if arguments.campaign_report is not None: - render_arguments = arguments - elif arguments.output is not None: - render_arguments = _composition_arguments(arguments, run_directory) - else: - render_arguments = _manifest_backed_arguments(arguments, run_directory) - if ( - arguments.output is not None - and arguments.campaign_report is None - and _manifest_path(run_directory).is_file() - ): - _publish_master(render_arguments, run_directory) - if arguments.campaign_report is not None: - selection = RenderSelection( - source=_absolute(arguments.campaign_report), - overlay=( - _absolute(arguments.madgraph_overlay) - if arguments.madgraph_overlay is not None - else None - ), - ) - elif arguments.output is not None: - selection = RenderSelection( - source=_master_report_path(run_directory), - overlay=_madgraph_render_source(render_arguments, run_directory), - ) - else: - selection = _implicit_render_selection(render_arguments, run_directory) - source = selection.source - if not source.is_file(): - raise ProfilingError( - f"no campaign snapshot yet: {source}; start the scan before --render" - ) - if renderer_preflight: - _preflight_renderer(render_arguments) - raw, report, digest = _source_snapshot(source) - _validate_render_workload(render_arguments, report) - pdf_filename = _pdf_filename(render_arguments) - terminal_overlay = ( - _matching_madgraph_overlay(render_arguments, run_directory) - if arguments.campaign_report is None - else None - ) - selected_overlay_kind = "" - if selection.overlay is not None and selection.overlay.is_file(): - with contextlib.suppress(ProfilingError): - selected_overlay_kind = str( - _load_json( - selection.overlay, - context="selected MadGraph render overlay", - ).get("kind", "") - ) - strict = bool( - _report_publication_profile(report) - and selection.overlay is not None - and selection.overlay.is_file() - and selected_overlay_kind == madgraph.KIND - and ( - arguments.campaign_report is not None - or ( - source == _master_report_path(run_directory) - and selection.overlay == terminal_overlay - ) - ) - ) - overlay = selection.overlay if strict else None - partial_overlay = selection.overlay or (run_directory / "madgraph" / ".unavailable") - - render_root = run_directory / "render" - render_root.mkdir(parents=True, exist_ok=True) - stage = Path(tempfile.mkdtemp(prefix=".staging-", dir=render_root)) - try: - if strict: - # The strict merger checks that the campaign file lives inside its - # recorded run_root. Keep an immutable digest-named freeze beside - # the source so all downstream provenance remains resolvable. - frozen_source = source.parent / f"render-snapshot-{digest}.json" - if frozen_source.is_file() and frozen_source.read_bytes() != raw: - raise ProfilingError( - f"render snapshot digest collision: {frozen_source}" - ) - if not frozen_source.is_file(): - temporary = frozen_source.with_suffix(".json.tmp") - temporary.write_bytes(raw) - temporary.replace(frozen_source) - staged_report = stage / "report.json" - else: - frozen_source = stage / "report.json" - frozen = copy.deepcopy(report) - if _report_publication_profile(report) and not strict: - # The candidate campaign is terminal, but the same-host MG - # phase is not. Keep anytime rendering visibly nonterminal. - frozen["status"] = "running-madgraph-series" - if partial_overlay.is_file(): - _attach_partial_overlay(frozen, partial_overlay) - frozen["render_snapshot"] = { - "status": "in-progress" - if report.get("status") not in TERMINAL_STATUSES - else "cluster-terminal", - "source_report": str(source), - "source_sha256": digest, - } - _write_json_atomic(frozen_source, frozen) - staged_report = frozen_source - staged_plots = stage / "plots" - staged_pdf = stage / pdf_filename - commands = _render_commands( - render_arguments, - source_report=frozen_source, - staged_report=staged_report, - staged_plots=staged_plots, - staged_pdf=staged_pdf, - strict=strict, - madgraph_overlay=overlay, - ) - render_environment = _renderer_environment(render_arguments) - for command in commands: - _run_checked(command, environment=render_environment) - expected_plots = { - f"fullcolor-{family}-{metric}.png" - for family in ("gg", "ddbar") - for metric in ("generation", "warm-runtime", "rss") - } - observed_plots = { - path.name for path in staged_plots.glob("*.png") if path.stat().st_size > 0 - } - staged_json = staged_pdf.with_suffix(".json") - if observed_plots != expected_plots or not ( - staged_pdf.is_file() and staged_pdf.stat().st_size > 0 - ) or not ( - staged_json.is_file() and staged_json.stat().st_size > 0 - ): - raise ProfilingError( - "render commands did not produce one complete output set" - ) - published = _publish_render_generation(stage, render_root, digest, pdf_filename) - if _canonical_publication_enabled(render_arguments): - _publish_canonical_pdf(published, render_arguments) - return published - except BaseException: - if stage.is_dir(): - shutil.rmtree(stage) - raise - - -def _safe_refresh(run_directory: Path) -> bool: - _validate_refresh_target(run_directory) - render_lock = _acquire_render_lock(run_directory) - try: - try: - cache_lock = madgraph._acquire_cache_lock( - _madgraph_cache_path(run_directory) - ) - except madgraph.SelectedMadGraphError as error: - raise ProfilingError(f"cannot refresh while {error}") from error - try: - return _safe_refresh_locked(run_directory) - finally: - cache_lock.close() - finally: - render_lock.close() - - -def _safe_refresh_locked(run_directory: Path) -> bool: - _validate_refresh_target(run_directory) - resolved = run_directory.resolve(strict=False) - if not resolved.exists(): - return False - manifest_path = resolved / "manifest.json" - if not manifest_path.is_file(): - raise ProfilingError( - "--refresh requires an existing recognized profiling manifest at " - f"{manifest_path}" - ) - manifest = _load_json(manifest_path, context="profiling refresh manifest") - identity = manifest.get("identity") - if ( - manifest.get("kind") != KIND - or manifest.get("schema_version") != SCHEMA_VERSION - or not isinstance(identity, Mapping) - or identity.get("run_directory") != str(resolved) - ): - raise ProfilingError( - f"refusing --refresh for unrecognized profiling directory: {resolved}" - ) - shutil.rmtree(resolved) - return True - - -def _validate_refresh_target(run_directory: Path) -> None: - _reject_refresh_symlinks(run_directory) - unsafe = { - Path("/").resolve(), - Path.home().resolve(), - ROOT.resolve(), - DEFAULT_RUNS_ROOT.resolve(strict=False), - } - resolved = run_directory.resolve(strict=False) - if resolved in unsafe or len(resolved.parts) < 4: - raise ProfilingError(f"refusing ambiguous --refresh target: {resolved}") - - -def _reject_refresh_symlinks(path: Path) -> None: - expanded = path.expanduser() - absolute = Path(os.path.abspath(expanded)) - for candidate in (absolute, *absolute.parents): - if candidate.is_symlink(): - raise ProfilingError( - f"refusing --refresh through symlinked path component: {candidate}" - ) - - -def _command_available(command: str) -> bool: - path = Path(command).expanduser() - return ( - path.is_file() and os.access(path, os.X_OK) - if path.parent != Path(".") - else shutil.which(command) is not None - ) - - -def _dependency_status(arguments: argparse.Namespace) -> dict[str, Any]: - amplicol = _absolute(arguments.amplicol_root) - reference_fft = _absolute(arguments.reference_fft_root) - madgraph = ( - _absolute(arguments.madgraph_root) - if arguments.madgraph_root is not None - else None - ) - return { - "python": { - "path": str(arguments.python), - "available": _command_available(str(arguments.python)), - }, - "cxx": { - "path": str(arguments.cxx), - "available": _command_available(str(arguments.cxx)), - }, - "fortran": { - "path": str(arguments.fc), - "available": _command_available(str(arguments.fc)), - }, - "make": { - "path": str(arguments.make), - "available": _command_available(str(arguments.make)), - }, - "amplicol_root": { - "path": str(amplicol), - "compatible": (amplicol / "process_list.py").is_file(), - "probe": str(amplicol / "amplicol_color_probe"), - "probe_available": (amplicol / "amplicol_color_probe").is_file(), - }, - "reference_fft_root": { - "path": str(reference_fft), - "compatible": (reference_fft / "Benchmark" / "run_benchmark.py").is_file(), - }, - "madgraph_root": { - "path": str(madgraph) if madgraph is not None else None, - "applicable": True, - "compatible": bool( - madgraph is not None - and (madgraph / "bin" / "mg5_aMC").is_file() - and (madgraph / "VERSION").is_file() - ), - }, - } - - -def _preflight(arguments: argparse.Namespace) -> None: - status = _dependency_status(arguments) - run_directory = _run_directory(arguments) - requested_shards = _requested_shards(arguments, run_directory) - for key in ("python", "cxx", "fortran"): - if status[key]["available"] is not True: - raise ProfilingError( - f"required {key} executable is unavailable: {status[key]['path']}" - ) - if _pyamplicol_runtime_required(requested_shards): - _preflight_pyamplicol_runtime(arguments) - needs_amplicol = any( - "amplicol" in _shard_modes(arguments, run_directory, shard) - for shard in requested_shards - ) - if needs_amplicol: - amplicol = status["amplicol_root"] - if amplicol["compatible"] is not True: - raise ProfilingError( - f"invalid --amplicol-root: {amplicol['path']}; pass a compatible " - "checkout or run `just dev-install --with-legacy-amplicol`" - ) - if ( - not arguments.compare_helicity_sums - and amplicol["probe_available"] is not True - and not arguments.build_amplicol - ): - raise ProfilingError( - "AmpliCol probe is missing; pass --build-amplicol to build it once: " - f"{amplicol['probe']}" - ) - needs_reference_fft = any( - "reference-fft" in _shard_modes(arguments, run_directory, shard) - for shard in requested_shards - ) - if needs_reference_fft: - reference_fft = status["reference_fft_root"] - if reference_fft["compatible"] is not True: - raise ProfilingError( - "invalid --reference-fft-root: expected " - f"Benchmark/run_benchmark.py below {reference_fft['path']}; pass a " - "compatible checkout or run " - "`just dev-install --with-reference-fft`" - ) - if _madgraph_requested(arguments, run_directory): - if status["make"]["available"] is not True: - raise ProfilingError( - f"required make executable is unavailable: {status['make']['path']}" - ) - madgraph = status["madgraph_root"] - if madgraph["compatible"] is not True: - raise ProfilingError( - "MadGraph installation is missing or incompatible; pass " - "--madgraph-root PATH containing bin/mg5_aMC and VERSION" - ) - _preflight_renderer(arguments) - - -def _preflight_renderer(arguments: argparse.Namespace) -> None: - if not _command_available(str(arguments.python)): - raise ProfilingError( - f"renderer --python executable is unavailable: {arguments.python}" - ) - renderer = subprocess.run( - ( - str(arguments.python), - "-c", - "import matplotlib, platform, reportlab; print(platform.python_version())", - ), - check=False, - capture_output=True, - text=True, - env=_renderer_environment(arguments), - ) - if renderer.returncode != 0: - install_command = shlex.join( - ( - str(arguments.python), - "-m", - "pip", - "install", - *RENDER_REQUIREMENTS, - ) - ) - raise ProfilingError( - "plot/PDF dependencies are missing from --python; install them with " - f"{install_command}" - ) - selected_version = renderer.stdout.strip() - driver_version = str(madgraph.measurement_host_identity()["python"]) - if selected_version != driver_version: - raise ProfilingError( - "--python uses Python " - f"{selected_version!r}, but the profiling driver uses {driver_version!r}; " - "run fft_profiling.py with the selected interpreter" - ) - - -def _renderer_environment(arguments: argparse.Namespace) -> dict[str, str]: - cache = _run_directory(arguments) / "render" / ".matplotlib" - cache.mkdir(parents=True, exist_ok=True) - environment = os.environ.copy() - environment["MPLCONFIGDIR"] = str(cache) - return environment - - -def _madgraph_timeout(arguments: argparse.Namespace) -> float: - # The canonical publication overlay has historically used a strict 3595-s - # MG limit while the pyAmpliCol cells use the strict 3600-s admission edge. - # Custom cluster limits are transmitted without clamping. - return ( - study.DEFAULT_TIME_LIMIT_SECONDS - 5.0 - if arguments.time_limit_seconds == study.DEFAULT_TIME_LIMIT_SECONDS - else arguments.time_limit_seconds - ) - - -def _madgraph_command( - arguments: argparse.Namespace, run_directory: Path -) -> tuple[str, ...]: - if arguments.madgraph_root is None: - raise ProfilingError("--madgraph-root is required for the same-host series") - result = [ - str(arguments.python), - str(MADGRAPH_TOOL), - "--source-report", - str(_madgraph_source_path(arguments, run_directory)), - "--cache-dir", - str(_madgraph_cache_path(run_directory)), - "--output", - str(_madgraph_overlay_path(run_directory)), - "--mg5-root", - str(_absolute(arguments.madgraph_root)), - "--fc", - str(arguments.fc), - "--make", - str(arguments.make), - "--generation-timeout-seconds", - format(_madgraph_timeout(arguments), ".17g"), - "--memory-limit-gib", - format(arguments.memory_limit_gib, ".17g"), - "--target-seconds", - format(arguments.target_seconds, ".17g"), - ] - selected_families = _family_selection(arguments) - for multiplicity in _requested_multiplicities(arguments, run_directory): - measured_by_requested_family = any( - madgraph.protocol_measures_multiplicity(family, multiplicity) - for family in selected_families - ) - result.extend( - ( - ( - "--multiplicity" - if measured_by_requested_family - else "--protocol-scope-multiplicity" - ), - str(multiplicity), - ) - ) - if len(selected_families) == 1: - result.extend(("--family", selected_families[0])) - if arguments.compare_helicity_sums: - result.append("--compare-helicity-sums") - return tuple(result) - - -def _madgraph_source_projection( - arguments: argparse.Namespace, - run_directory: Path, - report: Mapping[str, Any], -) -> dict[str, Any]: - policy = report.get("policy") - if not isinstance(policy, Mapping): - raise ProfilingError("MadGraph source report has no policy") - measurement = policy.get("measurement") - if not isinstance(measurement, Mapping): - raise ProfilingError("MadGraph source report has no measurement policy") - alpha_s = measurement.get("alpha_s") - if not isinstance(alpha_s, int | float) or isinstance(alpha_s, bool): - raise ProfilingError("MadGraph source report has invalid alpha_s") - workload = _helicity_workload(arguments) - cells = report.get("cells") - if not isinstance(cells, Mapping): - raise ProfilingError("MadGraph source report has no cells") - requested = { - str(value) for value in _requested_multiplicities(arguments, run_directory) - } - source_cells: dict[str, dict[str, dict[str, object]]] = {} - for family in _family_selection(arguments): - mode = madgraph.source_mode(family, _helicity_workload(arguments)) - family_cells = cells.get(family) - if not isinstance(family_cells, Mapping): - raise ProfilingError(f"MadGraph source report has no {family} cells") - curve = family_cells.get(mode) - if not isinstance(curve, Mapping): - raise ProfilingError(f"MadGraph source report has no {family}/{mode} curve") - source_cells[family] = { - mode: { - str(raw_n): copy.deepcopy(cell) - for raw_n, cell in curve.items() - if str(raw_n) in requested - } - } - projected: dict[str, Any] = { - "kind": madgraph.SOURCE_KIND, - "schema_version": 1, - "status": "complete", - "policy": { - "helicity_workload": workload, - "measurement": { - "alpha_s": float(alpha_s), - "helicity_workload": workload, - "warm_fixed_helicity": workload == "fixed", - "warm_helicity_sum": workload == "sum", - }, - }, - "cells": source_cells, - } - if isinstance(report.get("measurement_host"), Mapping): - projected["measurement_host"] = copy.deepcopy(report["measurement_host"]) - return projected - - -def _freeze_madgraph_source(arguments: argparse.Namespace, run_directory: Path) -> Path: - master_path = _master_report_path(run_directory) - _raw, master, _ = _source_snapshot(master_path) - if not _madgraph_source_ready(arguments, run_directory, master): - raise ProfilingError( - "cannot freeze MadGraph source before its selected source cells " - "are complete" - ) - source = _madgraph_source_projection(arguments, run_directory, master) - destination = _madgraph_source_path(arguments, run_directory) - if destination.is_file(): - existing = _load_json(destination, context="frozen MadGraph source") - normalized_existing = _madgraph_source_projection( - arguments, run_directory, existing - ) - if normalized_existing == source: - return destination - _write_json_atomic(destination, source) - return destination - - -def _madgraph_source_ready( - arguments: argparse.Namespace, - run_directory: Path, - master: Mapping[str, Any] | None = None, -) -> bool: - if not _madgraph_requested(arguments, run_directory): - return False - if master is None: - master_path = _master_report_path(run_directory) - if not master_path.is_file(): - return False - _raw, master, _ = _source_snapshot(master_path) - for family in _family_selection(arguments): - source_mode = madgraph.source_mode(family, _helicity_workload(arguments)) - if not _selected_cells_terminal_for_orchestrator( - master, - family=family, - modes=(source_mode,), - multiplicities=_requested_multiplicities(arguments, run_directory), - ): - return False - return True - - -def _ensure_madgraph_overlay( - arguments: argparse.Namespace, - run_directory: Path, - dashboard: Dashboard, -) -> None: - if not _madgraph_requested(arguments, run_directory): - return - _freeze_madgraph_source(arguments, run_directory) - if _matching_madgraph_overlay(arguments, run_directory) is not None: - _diagnostic( - "Reusing the matching MadGraph overlay.", - colorama.Fore.CYAN, - ) - return - _run_madgraph(arguments, run_directory, dashboard) - - -def _start_madgraph_overlay( - arguments: argparse.Namespace, - run_directory: Path, -) -> ActiveJob | None: - if not _madgraph_requested(arguments, run_directory): - return None - _freeze_madgraph_source(arguments, run_directory) - if _matching_madgraph_overlay(arguments, run_directory) is not None: - _diagnostic( - "Reusing the matching MadGraph overlay.", - colorama.Fore.CYAN, - ) - return None - return _launch_madgraph_job(arguments, run_directory) - - -def _maybe_start_madgraph_overlay( - arguments: argparse.Namespace, - run_directory: Path, - active: list[ActiveJob], -) -> bool: - if ( - active - or not _madgraph_requested(arguments, run_directory) - or not _madgraph_source_ready(arguments, run_directory) - ): - return False - job = _start_madgraph_overlay(arguments, run_directory) - if job is None: - return True - active.append(job) - return False - - -def _format_duration(seconds: float | None) -> str: - if seconds is None or not math.isfinite(seconds): - return "?" - value = max(0, int(seconds)) - hours, remainder = divmod(value, 3600) - minutes, seconds_i = divmod(remainder, 60) - return f"{hours:d}:{minutes:02d}:{seconds_i:02d}" - - -def _aggregate_rss(active: Sequence[ActiveJob]) -> int | None: - if not active: - return 0 - try: - records = memory_watchdog.process_snapshot() - return sum(job.sampler.sample(records).rss_bytes for job in active) - except memory_watchdog.ProbeError: - return None - - -def _matching_madgraph_progress( - arguments: argparse.Namespace, run_directory: Path -) -> dict[str, Any] | None: - path = _madgraph_progress_path(run_directory) - if not path.is_file(): - return None - try: - payload = madgraph.load_runtime_progress(path) - except madgraph.SelectedMadGraphError: - return None - policy = payload.get("policy") - try: - progress_workload = ( - madgraph._declared_helicity_workload(policy) - if isinstance(policy, Mapping) - else None - ) - progress_host = madgraph.validate_measurement_host( - payload.get("host"), context="MadGraph runtime progress host" - ) - except madgraph.SelectedMadGraphError: - return None - requested_multiplicities = _requested_multiplicities(arguments, run_directory) - raw_multiplicities = policy.get("final_state_multiplicities") - if ( - not isinstance(policy, Mapping) - or progress_workload != _helicity_workload(arguments) - or progress_host != madgraph.measurement_host_identity() - or policy.get("family_maximum_measured_multiplicity") - != madgraph.protocol_measured_multiplicity_limits() - ): - return None - if ( - not isinstance(raw_multiplicities, list) - or not raw_multiplicities - or any(not isinstance(value, int) for value in raw_multiplicities) - ): - return None - observed_multiplicities = tuple(raw_multiplicities) - observed_set = set(observed_multiplicities) - if observed_multiplicities != tuple( - value for value in requested_multiplicities if value in observed_set - ): - return None - raw_families = policy.get("selected_process_families") - if isinstance(raw_families, list) and set(raw_families) < set( - _family_selection(arguments) - ): - return None - return payload - - -def _madgraph_completed(arguments: argparse.Namespace, run_directory: Path) -> int: - if not _madgraph_requested(arguments, run_directory): - return 0 - terminal = _matching_madgraph_overlay(arguments, run_directory) - progress_payload = _matching_madgraph_progress(arguments, run_directory) - if progress_payload is not None and progress_payload.get("status") == "running": - report = progress_payload - elif terminal is not None: - report = _load_json(terminal, context="MadGraph overlay") - elif progress_payload is not None: - report = progress_payload - else: - return 0 - series = report.get("runtime_series") - if not isinstance(series, Mapping): - return 0 - requested_families = set(_family_selection(arguments)) - requested_multiplicities = { - str(value) for value in _requested_multiplicities(arguments, run_directory) - } - return sum( - 1 - for family, family_cells in series.items() - if family in requested_families - if isinstance(family_cells, Mapping) - for mode_cells in family_cells.values() - if isinstance(mode_cells, Mapping) - for raw_n in mode_cells - if str(raw_n) in requested_multiplicities - ) - - -class Dashboard: - def __init__( - self, - *, - total: int, - core_budget: int, - helicity_workload: str, - batch_size: int, - ) -> None: - self.total = total - self.core_budget = core_budget - self.started = time.monotonic() - self.workload = helicity_workload - self.batch_size = batch_size - self.bar = progressbar.ProgressBar( - max_value=total, - fd=sys.stderr, - widgets=[ - progressbar.Variable("headline", width=96), - " ", - progressbar.Bar(), - " ", - progressbar.Percentage(), - ], - ) - self.bar.start() - - def update( - self, - completed: int, - *, - phase: str, - active: Sequence[ActiveJob], - ) -> None: - elapsed = time.monotonic() - self.started - rss = _aggregate_rss(active) - rss_text = "RSS n/a" if rss is None else f"RSS {rss / 1024**3:.2f} GiB" - active_cores = sum(job.claimed_cores for job in active) - jobs = ",".join(job.detail for job in active) or "idle" - headline = ( - f"{completed}/{self.total} cells | {self.workload} " - f"batch={self.batch_size} | " - f"{phase}: {jobs} | " - f"cores active={active_cores}/{self.core_budget} | {rss_text} | " - f"elapsed {_format_duration(elapsed)}" - ) - self.bar.update(min(completed, self.total), headline=headline, force=True) - - def finish(self) -> None: - self.bar.finish(dirty=True) - - -def _color_enabled(arguments: argparse.Namespace) -> bool: - return ( - not arguments.no_color and "NO_COLOR" not in os.environ and sys.stderr.isatty() - ) - - -def _diagnostic(message: str, color: str = "") -> None: - suffix = colorama.Style.RESET_ALL if color else "" - print(f"{color}{message}{suffix}", file=sys.stderr, flush=True) - - -def _python_source_environment(arguments: argparse.Namespace) -> dict[str, str]: - environment = os.environ.copy() - source = str(ROOT / "src") - existing = environment.get("PYTHONPATH") - environment["PYTHONPATH"] = ( - source if not existing else os.pathsep.join((source, existing)) - ) - environment["PYTHONDONTWRITEBYTECODE"] = "1" - environment.setdefault("SYMBOLICA_HIDE_BANNER", "1") - environment["FFT_ACCEPTANCE_PYTHON"] = str(arguments.python) - return environment - - -def _pyamplicol_runtime_required(requested_shards: Sequence[Shard]) -> bool: - return any( - shard.family == "ddbar" - or any(study.MODE_BY_KEY[mode].kind == "candidate" for mode in shard.modes) - for shard in requested_shards - ) - - -def _preflight_pyamplicol_runtime(arguments: argparse.Namespace) -> None: - completed = subprocess.run( - ( - str(arguments.python), - "-c", - ( - "import pyamplicol; " - "from pyamplicol.generation.phase_space import " - "massive_rambo_final_state; " - "print(pyamplicol.__version__)" - ), - ), - check=False, - capture_output=True, - text=True, - env=_python_source_environment(arguments), - ) - if completed.returncode == 0: - return - detail = (completed.stderr or completed.stdout).strip() - if len(detail) > 4000: - detail = detail[-4000:] - raise ProfilingError( - "selected --python cannot import pyAmpliCol from this checkout; " - "rerun `just dev-install` in this workspace or fix the Python/native " - f"runtime before profiling.\n{detail}" - ) - - -def _claimed_cores(arguments: argparse.Namespace, shard: Shard | ShardWork) -> int: - if isinstance(shard, ShardWork): - shard = shard.shard - return arguments.candidate_cores if shard.candidate else 1 - - -def _launch_shard( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> ActiveJob: - command = _child_command(arguments, run_directory, work) - log_root = _work_cell_root(run_directory, work) / "orchestrator-logs" - log_root.mkdir(parents=True, exist_ok=True) - stdout = (log_root / "stdout.log").open("wb") - stderr = (log_root / "stderr.log").open("wb") - claimed = _claimed_cores(arguments, work) - environment = os.environ.copy() - for key in ( - "OMP_NUM_THREADS", - "OPENBLAS_NUM_THREADS", - "MKL_NUM_THREADS", - "NUMEXPR_NUM_THREADS", - "VECLIB_MAXIMUM_THREADS", - "RAYON_NUM_THREADS", - ): - environment[key] = str(claimed) - try: - process = subprocess.Popen( - command, - stdout=stdout, - stderr=stderr, - env=environment, - start_new_session=True, - ) - except BaseException: - stdout.close() - stderr.close() - raise - return ActiveJob( - shard=work.shard, - final_multiplicity=work.final_multiplicity, - owned_mode=work.owned_mode, - command=command, - process=process, - stdout=stdout, - stderr=stderr, - sampler=memory_watchdog.ProcessTreeSampler(process.pid, process.pid), - claimed_cores=claimed, - detail=f"{work.shard.family}/{work.owned_mode}/n{work.final_multiplicity}", - ) - - -def _work_detail( - arguments: argparse.Namespace, run_directory: Path, work: ShardWork -) -> str: - report = _load_shard_report(arguments, run_directory, work.shard) - for mode in _work_owned_modes(arguments, run_directory, work): - if report is None or not _selected_cells_terminal_for_orchestrator( - report, - family=work.shard.family, - modes=(mode,), - multiplicities=(work.final_multiplicity,), - ): - return f"{work.shard.family}/{mode}/n{work.final_multiplicity}" - return f"{work.shard.name}/n{work.final_multiplicity}/finalizing" - - -def _shard_detail( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> str: - report = _load_shard_report(arguments, run_directory, shard) - for final_multiplicity in _requested_multiplicities(arguments, run_directory): - for mode in _counted_owned_modes(arguments, run_directory, shard): - work = ShardWork(shard, final_multiplicity, mode) - if not _selected_work_complete(arguments, run_directory, work, report): - return _work_detail(arguments, run_directory, work) - return f"{shard.name}/finalizing" - - -def _terminate_jobs(active: Sequence[ActiveJob]) -> None: - for job in active: - if job.process.poll() is None: - with contextlib.suppress(ProcessLookupError): - os.killpg(job.process.pid, signal.SIGTERM) - deadline = time.monotonic() + 5.0 - for job in active: - remaining = max(0.0, deadline - time.monotonic()) - with contextlib.suppress(subprocess.TimeoutExpired): - job.process.wait(timeout=remaining) - for job in active: - if job.process.poll() is None: - with contextlib.suppress(ProcessLookupError): - os.killpg(job.process.pid, signal.SIGKILL) - job.process.wait() - job.stdout.close() - job.stderr.close() - - -@contextlib.contextmanager -def _termination_signal_handlers(): - previous: dict[int, Any] = {} - - def interrupt(signum: int, _frame: object) -> None: - raise CampaignSignal(signum) - - for signum in (signal.SIGTERM, signal.SIGHUP): - previous[signum] = signal.getsignal(signum) - signal.signal(signum, interrupt) - try: - yield - finally: - for signum, handler in previous.items(): - signal.signal(signum, handler) - - -def _prepare_phase_shard_state( - arguments: argparse.Namespace, run_directory: Path, shard: Shard -) -> dict[str, Any] | None: - _seed_protocol_scope(arguments, run_directory, shard) - report = _load_shard_report(arguments, run_directory, shard) - loaded = report is not None - if report is None and shard.dependency is None: - return None - if report is None: - report = study.compose_report( - _shard_arguments(arguments, run_directory, shard), {} - ) - changed = _apply_resource_frontier_censoring( - arguments, - report, - shard, - modes=_counted_owned_modes(arguments, run_directory, shard), - multiplicities=_requested_multiplicities(arguments, run_directory), - ) - changed = ( - _apply_dependency_skips( - arguments, - run_directory, - report, - shard, - multiplicities=_requested_multiplicities(arguments, run_directory), - ) - or changed - ) - if changed: - report = study.compose_report( - _shard_arguments(arguments, run_directory, shard), report["cells"] - ) - if loaded or changed: - _write_json_atomic(_shard_report_path(run_directory, shard), report) - return report - - -def _overwrite_work_blocker( - arguments: argparse.Namespace, - run_directory: Path, - work: ShardWork, - report: Mapping[str, Any] | None, -) -> str | None: - if report is not None: - cells = report.get("cells") - family_cells = ( - cells.get(work.shard.family) if isinstance(cells, Mapping) else None - ) - curve = ( - family_cells.get(work.owned_mode) - if isinstance(family_cells, Mapping) - else None - ) - if isinstance(curve, Mapping): - frontier = _mode_resource_frontier(curve, work.final_multiplicity) - if frontier is not None: - return f"resource limit at n={frontier}" - - if work.shard.dependency is None: - return None - dependency_name, dependency_mode = work.shard.dependency - dependency_shard = SHARD_BY_NAME[dependency_name] - dependency = _load_shard_report(arguments, run_directory, dependency_shard) - if dependency is None: - return None - cells = dependency.get("cells") - family_cells = cells.get(work.shard.family) if isinstance(cells, Mapping) else None - curve = ( - family_cells.get(dependency_mode) - if isinstance(family_cells, Mapping) - else None - ) - cell = ( - curve.get(str(work.final_multiplicity)) - if isinstance(curve, Mapping) - else None - ) - if ( - isinstance(cell, Mapping) - and _cell_terminal_for_orchestrator(cell) - and cell.get("status") != "measured" - ): - return f"dependency {dependency_name} is {cell.get('status')}" - return None - - -def _refresh_phase_pending( - arguments: argparse.Namespace, - run_directory: Path, - pending: Sequence[ShardWork], - active: Sequence[ActiveJob], - *, - overwrite_pending: set[CellIdentity] | None = None, -) -> list[ShardWork]: - forced = overwrite_pending if overwrite_pending is not None else set() - reports: dict[str, dict[str, Any] | None] = {} - for shard in {work.shard for work in pending}: - reports[shard.name] = _prepare_phase_shard_state( - arguments, run_directory, shard - ) - active_keys = { - (job.shard.name, job.final_multiplicity, job.owned_mode) - for job in active - if job.final_multiplicity is not None - } - blocked: set[CellIdentity] = set() - for work in pending: - identity = _work_identity(work) - if identity not in forced: - continue - blocker = _overwrite_work_blocker( - arguments, run_directory, work, reports.get(work.shard.name) - ) - if blocker is None: - continue - blocked.add(identity) - forced.remove(identity) - _diagnostic( - f"Retaining existing {work.shard.family}/{work.owned_mode}/" - f"n{work.final_multiplicity}; overwrite was not attempted because " - f"of {blocker}.", - colorama.Fore.YELLOW, - ) - return [ - work - for work in pending - if _work_identity(work) not in blocked - if (work.shard.name, work.final_multiplicity, work.owned_mode) - not in active_keys - and ( - _work_identity(work) in forced - or not _selected_work_complete( - arguments, - run_directory, - work, - reports.get(work.shard.name) - if work.shard.name in reports - else _load_shard_report(arguments, run_directory, work.shard), - ) - ) - ] - - -def _work_launch_conflicts( - arguments: argparse.Namespace, work: ShardWork, active: Sequence[ActiveJob] -) -> bool: - if arguments.compare_helicity_sums and work.owned_mode == "amplicol": - return any(job.owned_mode == "amplicol" for job in active) - if not arguments.build_amplicol or work.shard.name != "ddbar-amplicol": - return False - probe = _absolute(arguments.amplicol_root) / "amplicol_color_probe" - return not probe.is_file() and any( - job.shard.name == work.shard.name for job in active - ) - - -def _phase( - arguments: argparse.Namespace, - run_directory: Path, - phase_number: int, - dashboard: Dashboard, - *, - background: list[ActiveJob] | None = None, - madgraph_overlay_ready: bool = False, - overwrite_pending: set[CellIdentity] | None = None, -) -> bool: - pending = list(_phase_work_items(arguments, run_directory, phase_number)) - active: list[ActiveJob] = [] - failure: str | None = None - background_jobs = background if background is not None else [] - try: - while pending or active: - failure = _poll_madgraph_jobs(arguments, run_directory, background_jobs) - if failure is not None: - break - pending = _refresh_phase_pending( - arguments, - run_directory, - pending, - active, - overwrite_pending=overwrite_pending, - ) - used = sum(job.claimed_cores for job in active + background_jobs) - launched = True - while launched: - launched = False - for index, work in enumerate(pending): - if not _work_dependency_ready(arguments, run_directory, work): - continue - claim = _claimed_cores(arguments, work) - if used + claim > arguments.cores: - continue - if _work_launch_conflicts(arguments, work, active): - continue - identity = _work_identity(work) - if ( - overwrite_pending is not None - and identity in overwrite_pending - ): - _prepare_overwrite_work(arguments, run_directory, work) - overwrite_pending.remove(identity) - _seed_cell_inputs(arguments, run_directory, work) - report = _publish_shard_report(arguments, run_directory, work.shard) - if _selected_work_complete(arguments, run_directory, work, report): - pending.pop(index) - launched = True - break - job = _launch_shard(arguments, run_directory, work) - active.append(job) - pending.pop(index) - used += claim - launched = True - break - - for job in active: - assert job.final_multiplicity is not None - assert job.owned_mode is not None - job.detail = _work_detail( - arguments, - run_directory, - ShardWork(job.shard, job.final_multiplicity, job.owned_mode), - ) - names = tuple( - ( - f"{job.shard.name}:{job.owned_mode}:n{job.final_multiplicity}" - if job.owned_mode is not None - else f"{job.shard.name}:n{job.final_multiplicity}" - ) - for job in active - ) - master = _publish_master(arguments, run_directory, active=names) - if not madgraph_overlay_ready: - madgraph_overlay_ready = _maybe_start_madgraph_overlay( - arguments, run_directory, background_jobs - ) - dashboard.update( - _selected_completed_cells( - arguments, - master, - ignored_cells=( - overwrite_pending - if overwrite_pending is not None - else frozenset() - ), - ) - + _madgraph_completed(arguments, run_directory), - phase=f"phase {phase_number}", - active=tuple(background_jobs) + tuple(active), - ) - if not active and pending: - if background_jobs and any( - _work_dependency_ready(arguments, run_directory, work) - for work in pending - ): - time.sleep(arguments.poll_seconds) - continue - unready = next( - ( - work - for work in pending - if not _work_dependency_ready(arguments, run_directory, work) - ), - None, - ) - if unready is not None: - dependency_name = ( - unready.shard.dependency[0] - if unready.shard.dependency is not None - else "unknown" - ) - failure = ( - f"{unready.shard.name} cannot start " - f"n{unready.final_multiplicity} because dependency " - f"{dependency_name} is incomplete" - ) - break - if not active: - break - time.sleep(arguments.poll_seconds) - failure = _poll_madgraph_jobs(arguments, run_directory, background_jobs) - if failure is not None: - break - for job in tuple(active): - returncode = job.process.poll() - if returncode is None: - continue - job.stdout.close() - job.stderr.close() - active.remove(job) - assert job.final_multiplicity is not None - assert job.owned_mode is not None - report = _publish_shard_report(arguments, run_directory, job.shard) - work = ShardWork(job.shard, job.final_multiplicity, job.owned_mode) - if not _selected_work_complete( - arguments, run_directory, work, report - ): - failure = ( - f"{job.shard.name} n{job.final_multiplicity} exited " - f"{returncode} without completing the requested " - "authoritative cells; inspect its " - "orchestrator logs" - ) - break - if failure is not None: - break - finally: - if active: - _terminate_jobs(active) - if failure is not None: - _publish_master(arguments, run_directory, halt_reason=failure) - raise ProfilingError(failure) - return madgraph_overlay_ready - - -def _run_madgraph( - arguments: argparse.Namespace, - run_directory: Path, - dashboard: Dashboard, -) -> None: - active = [_launch_madgraph_job(arguments, run_directory)] - try: - _wait_madgraph_jobs(arguments, run_directory, dashboard, active) - except BaseException: - if active: - _terminate_jobs(active) - raise - - -def _launch_madgraph_job( - arguments: argparse.Namespace, run_directory: Path -) -> ActiveJob: - command = _madgraph_command(arguments, run_directory) - log_root = run_directory / "madgraph" / "orchestrator-logs" - log_root.mkdir(parents=True, exist_ok=True) - stdout = (log_root / "stdout.log").open("wb") - stderr = (log_root / "stderr.log").open("wb") - process = subprocess.Popen( - command, - stdout=stdout, - stderr=stderr, - start_new_session=True, - ) - pseudo = Shard("madgraph", "gg", (), (), None, 4, False) - job = ActiveJob( - shard=pseudo, - final_multiplicity=None, - owned_mode=None, - command=command, - process=process, - stdout=stdout, - stderr=stderr, - sampler=memory_watchdog.ProcessTreeSampler(process.pid, process.pid), - claimed_cores=1, - detail="madgraph/initializing", - ) - return job - - -def _update_madgraph_job_detail(run_directory: Path, job: ActiveJob) -> None: - progress_path = _madgraph_progress_path(run_directory) - if not progress_path.is_file(): - return - try: - progress = madgraph.load_runtime_progress(progress_path) - current = progress.get("current_cell") - if isinstance(current, Mapping): - job.detail = ( - f"{current.get('family')}/{current.get('mode')}/" - f"n{current.get('n')}" - ) - else: - job.detail = "madgraph/finalizing" - except madgraph.SelectedMadGraphError: - job.detail = "madgraph/progress-unavailable" - - -def _poll_madgraph_jobs( - arguments: argparse.Namespace, - run_directory: Path, - active: list[ActiveJob], -) -> str | None: - log_root = run_directory / "madgraph" / "orchestrator-logs" - for job in tuple(active): - _update_madgraph_job_detail(run_directory, job) - returncode = job.process.poll() - if returncode is None: - continue - job.stdout.close() - job.stderr.close() - active.remove(job) - if ( - returncode != 0 - or _matching_madgraph_overlay(arguments, run_directory) is None - ): - return f"MadGraph series exited {returncode}; inspect {log_root}" - return None - - -def _wait_madgraph_jobs( - arguments: argparse.Namespace, - run_directory: Path, - dashboard: Dashboard, - active: list[ActiveJob], -) -> None: - while active: - failure = _poll_madgraph_jobs(arguments, run_directory, active) - if failure is not None: - raise ProfilingError(failure) - master = _load_json(_master_report_path(run_directory), context="master report") - dashboard.update( - _selected_completed_cells(arguments, master) - + _madgraph_completed(arguments, run_directory), - phase="phase 4", - active=active, - ) - if active: - time.sleep(arguments.poll_seconds) - - -def _canonical_madgraph_overlay_authenticated( - arguments: argparse.Namespace, - run_directory: Path, - master: Mapping[str, Any], -) -> bool: - """Use the strict publication boundary to skip a completed canonical overlay.""" - - if not _report_publication_profile(master): - return False - overlay = _matching_madgraph_overlay(arguments, run_directory) - if overlay is None: - return False - try: - publication.build_final_report( - campaign_path=_master_report_path(run_directory), - madgraph_overlay_path=overlay, - ) - except publication.PublicationMergeError: - return False - return True - - -def _lock_path(run_directory: Path, purpose: str) -> Path: - run_directory.parent.mkdir(parents=True, exist_ok=True) - digest = hashlib.sha256(str(run_directory).encode("utf-8")).hexdigest()[:12] - return run_directory.parent / (f".{run_directory.name}.{digest}.{purpose}.lock") - - -def _acquire_render_lock(run_directory: Path) -> BinaryIO: - """Serialize render generations and refresh without blocking workers.""" - - path = _lock_path(run_directory, "render") - handle = path.open("a+b") - fcntl.flock(handle.fileno(), fcntl.LOCK_EX) - return handle - - -def _acquire_execution_lock(run_directory: Path) -> BinaryIO: - # The lock must survive --refresh deleting/recreating the selected output. - # Keeping it beside the output closes the destructive race without locking - # unrelated profiling runs in the same parent directory. - path = _lock_path(run_directory, "orchestrator") - handle = path.open("a+b") - try: - fcntl.flock(handle.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError as error: - handle.close() - raise ProfilingError(f"another profiling driver holds {path}") from error - return handle - - -def _render_phase_boundary(arguments: argparse.Namespace, run_directory: Path) -> Path: - _publish_master(arguments, run_directory) - return render_snapshot(arguments, renderer_preflight=False) - - -def run_campaign(arguments: argparse.Namespace) -> Path: - if arguments.refresh: - _reject_refresh_symlinks(_configured_run_path(arguments)) - run_directory = _run_directory(arguments) - if arguments.refresh: - _validate_refresh_target(run_directory) - lock = _acquire_execution_lock(run_directory) - dashboard: Dashboard | None = None - madgraph_jobs: list[ActiveJob] = [] - try: - with _termination_signal_handlers(): - if arguments.refresh: - removed = _safe_refresh(run_directory) - _diagnostic( - ( - f"Removed recognized profiling output {run_directory}; " - "restarting." - if removed - else f"No profiling output exists at {run_directory}; starting." - ), - colorama.Fore.YELLOW, - ) - _create_or_resume_manifest(arguments, run_directory) - _preflight(arguments) - retried = _apply_retry_invalidation(arguments, run_directory) - if retried: - _diagnostic( - f"Retrying {retried} failed/skipped profiling cell" - f"{'' if retried == 1 else 's'}.", - colorama.Fore.CYAN, - ) - overwrite_pending = ( - { - _work_identity(work) - for phase_number in _scheduled_phase_numbers( - arguments, run_directory - ) - for work in _phase_work_items( - arguments, run_directory, phase_number - ) - } - if arguments.overwrite - else set() - ) - if overwrite_pending: - _diagnostic( - f"Overwriting {len(overwrite_pending)} selected profiling cell" - f"{'' if len(overwrite_pending) == 1 else 's'} as each worker " - "starts.", - colorama.Fore.CYAN, - ) - initial = _publish_master(arguments, run_directory) - requested = _requested_multiplicities(arguments, run_directory) - completed = _selected_completed_cells( - arguments, - initial, - multiplicities=requested, - ignored_cells=overwrite_pending, - ) - total = ( - completed - + _selected_pending_cells( - arguments, - initial, - multiplicities=requested, - ignored_cells=overwrite_pending, - ) - + ( - len(_family_selection(arguments)) * len(requested) - if _madgraph_requested(arguments, run_directory) - else 0 - ) - ) - dashboard = Dashboard( - total=total, - core_budget=arguments.cores, - helicity_workload=_helicity_workload(arguments), - batch_size=arguments.batch_size, - ) - dashboard.update(completed, phase="initializing", active=()) - madgraph_overlay_ready = False - for phase_number in _scheduled_phase_numbers(arguments, run_directory): - madgraph_overlay_ready = _phase( - arguments, - run_directory, - phase_number, - dashboard, - background=madgraph_jobs, - madgraph_overlay_ready=madgraph_overlay_ready, - overwrite_pending=overwrite_pending, - ) or madgraph_overlay_ready - if not madgraph_overlay_ready: - madgraph_overlay_ready = _maybe_start_madgraph_overlay( - arguments, run_directory, madgraph_jobs - ) - _render_phase_boundary(arguments, run_directory) - terminal = _publish_master(arguments, run_directory) - if not _selected_master_complete( - arguments, - terminal, - multiplicities=requested, - ignored_cells=overwrite_pending, - ): - raise ProfilingError( - "pyAmpliCol master did not complete the requested fill" - ) - if _madgraph_requested(arguments, run_directory): - if madgraph_jobs: - _wait_madgraph_jobs( - arguments, run_directory, dashboard, madgraph_jobs - ) - madgraph_overlay_ready = True - elif not madgraph_overlay_ready: - _ensure_madgraph_overlay(arguments, run_directory, dashboard) - madgraph_overlay_ready = True - if _canonical_madgraph_overlay_authenticated( - arguments, run_directory, terminal - ): - _diagnostic( - "MadGraph overlay authenticated for the terminal snapshot.", - colorama.Fore.CYAN, - ) - final_count = _selected_completed_cells( - arguments, - terminal, - multiplicities=requested, - ignored_cells=overwrite_pending, - ) + _madgraph_completed(arguments, run_directory) - dashboard.update(final_count, phase="rendering", active=()) - pdf = render_snapshot(arguments, renderer_preflight=False) - message = ( - "Completed profiling scan" - if terminal.get("status") in TERMINAL_STATUSES - else ( - "Completed requested line groups and multiplicities; " - "campaign snapshot remains resumable" - ) - ) - _diagnostic(f"{message}: {pdf}", colorama.Fore.GREEN) - return pdf - except (KeyboardInterrupt, CampaignSignal): - with contextlib.suppress(Exception): - _publish_master( - arguments, - run_directory, - halt_reason="interrupted by user; rerun the same command to resume", - ) - raise - finally: - if madgraph_jobs: - _terminate_jobs(madgraph_jobs) - if dashboard is not None: - dashboard.finish() - lock.close() - - -def status_payload(arguments: argparse.Namespace) -> dict[str, Any]: - run_directory = _run_directory(arguments) - manifest_path = _manifest_path(run_directory) - master_path = _master_report_path(run_directory) - manifest = ( - _load_json(manifest_path, context="profiling manifest") - if manifest_path.is_file() - else None - ) - master = ( - _load_json(master_path, context="master report") - if master_path.is_file() - else None - ) - if manifest is not None: - identity_diff = _identity_diff( - manifest.get("identity"), _identity(arguments, run_directory) - ) - differences = _immutable_identity_differences(identity_diff) - if differences: - preview = "\n ".join(differences[:12]) - raise ProfilingError( - "status measurement identity differs from the manifest:\n " + preview - ) - if master is not None: - _validate_render_workload(arguments, master) - return { - "kind": KIND, - "schema_version": SCHEMA_VERSION, - "helicity_workload": _helicity_workload(arguments), - "batch_size": arguments.batch_size, - "output": str(run_directory), - "requested_multiplicities": list(_selection(arguments)), - "requested_families": list(_family_selection(arguments)), - "requested_line_groups": list(_requested_line_groups(arguments, run_directory)), - "fill_history_multiplicities": ( - _manifest_int_history( - manifest, "fill_history_multiplicities", "requested_multiplicities" - ) - if manifest is not None - else [] - ), - "line_group_history": ( - _manifest_line_history(manifest) if manifest is not None else [] - ), - "process_family_history": ( - _manifest_family_history(manifest) if manifest is not None else [] - ), - "manifest": str(manifest_path), - "manifest_available": manifest is not None, - "configured_tools": ( - manifest.get("identity", {}).get("tools") - if isinstance(manifest, Mapping) - and isinstance(manifest.get("identity"), Mapping) - else None - ), - "master_report": str(master_path), - "campaign_status": master.get("status") - if master is not None - else "not-started", - "completed_requested_measurement_cells": ( - _selected_completed_cells(arguments, master) - + _madgraph_completed(arguments, run_directory) - if master is not None - else 0 - ), - "completed_measurement_cells": ( - _completed_cells(master) + _madgraph_completed(arguments, run_directory) - if master is not None - else 0 - ), - "dependencies": _dependency_status(arguments), - "madgraph_overlay": { - "path": str(_madgraph_overlay_path(run_directory)), - "applicable": ( - _madgraph_requested(arguments, run_directory) - if manifest is not None - else "madgraph" in _line_selection(arguments) - ), - "helicity_workload": _helicity_workload(arguments), - "available": ( - _matching_madgraph_overlay(arguments, run_directory) is not None - ), - }, - "rendered_pdf": { - "path": str( - run_directory / "render" / "current" / _pdf_filename(arguments) - ), - "available": ( - run_directory / "render" / "current" / _pdf_filename(arguments) - ).is_file(), - }, - "canonical_pdf": { - "path": str(_canonical_pdf_path(arguments)), - "applicable": _canonical_publication_enabled(arguments), - "available": ( - _canonical_publication_enabled(arguments) - and _canonical_pdf_path(arguments).is_file() - ), - }, - } - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(sys.argv[1:] if argv is None else argv) - enabled_color = _color_enabled(arguments) - colorama.init(strip=not enabled_color, convert=False) - try: - _validate_arguments(arguments) - if arguments.dry_run: - print(json.dumps(dry_run_plan(arguments), indent=2, sort_keys=True)) - return 0 - if arguments.status: - print(json.dumps(status_payload(arguments), indent=2, sort_keys=True)) - return 0 - if arguments.render: - pdf = render_snapshot(arguments) - print(pdf) - return 0 - pdf = run_campaign(arguments) - print(pdf) - return 0 - except CampaignSignal as error: - _diagnostic( - f"Profiling stopped by signal {error.signum}; rerun the same command " - "to resume." - ) - return 128 + error.signum - except KeyboardInterrupt: - _diagnostic("Profiling interrupted; rerun the same command to resume.") - return 130 - except ( - OSError, - ProfilingError, - madgraph.SelectedMadGraphError, - study.StudyError, - ) as error: - _diagnostic(f"FFT profiling: {error}", colorama.Fore.RED) - return 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/performance_report/__init__.py b/pyamplicol/tools/performance_report/__init__.py deleted file mode 100644 index 90be2eeefc..0000000000 --- a/pyamplicol/tools/performance_report/__init__.py +++ /dev/null @@ -1,33 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Three-mode performance-report support. - -The package deliberately keeps measurement, storage, scheduling, and rendering -separate. ``src/pyamplicol/_profiling_campaign/result_tables.py`` is the -canonical command entry point. -""" - -from .catalog import MADGRAPH_FULL_COMPARISON_VIEWS, REPORT_CATALOG, ReportCatalog -from .models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - MatrixComparisonView, - ModelKey, - ResultStatus, - Workload, -) - -__all__ = [ - "MADGRAPH_FULL_COMPARISON_VIEWS", - "REPORT_CATALOG", - "Accuracy", - "ArtifactPolicy", - "CellSpec", - "ExecutionMode", - "MatrixComparisonView", - "ModelKey", - "ReportCatalog", - "ResultStatus", - "Workload", -] diff --git a/pyamplicol/tools/performance_report/__main__.py b/pyamplicol/tools/performance_report/__main__.py deleted file mode 100644 index 71b9b00a85..0000000000 --- a/pyamplicol/tools/performance_report/__main__.py +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Installed worker entry point for packaged profiling campaigns.""" - -from __future__ import annotations - -from .cli import main - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/performance_report/aggregate_audit.py b/pyamplicol/tools/performance_report/aggregate_audit.py deleted file mode 100644 index 29ad111183..0000000000 --- a/pyamplicol/tools/performance_report/aggregate_audit.py +++ /dev/null @@ -1,259 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Authenticate a main commit assembled from audited architecture reports.""" - -from __future__ import annotations - -import argparse -import json -import subprocess -from collections.abc import Mapping, Sequence -from pathlib import Path, PurePosixPath - -from .service import validate_profile_name - - -class AggregateAuditError(RuntimeError): - """The aggregate report commit is not an allowed report-only descendant.""" - - -_PROFILE_ROOT = PurePosixPath("docs/performance_reports") -_FIXED_OUTPUTS = frozenset( - { - "pyAmpliCol.pdf", - "report_environment.json", - "report_environment.tex", - "result_validation_summary.tex", - } -) - - -def _git( - repo_root: Path, - arguments: Sequence[str], - *, - text: bool = True, -) -> str | bytes: - completed = subprocess.run( - ("git", *arguments), - cwd=repo_root, - check=False, - capture_output=True, - text=text, - ) - if completed.returncode != 0: - detail = ( - completed.stderr.strip() - if text - else completed.stderr.decode("utf-8", errors="replace").strip() - ) - raise AggregateAuditError( - f"git {' '.join(arguments)} failed: {detail or completed.returncode}" - ) - return completed.stdout - - -def _commit(repo_root: Path, revision: str) -> str: - output = _git(repo_root, ("rev-parse", "--verify", f"{revision}^{{commit}}")) - assert isinstance(output, str) - return output.strip() - - -def _profile_for_output(path: str) -> str | None: - candidate = PurePosixPath(path) - try: - relative = candidate.relative_to(_PROFILE_ROOT) - except ValueError: - return None - if len(relative.parts) < 2: - return None - profile = relative.parts[0] - try: - validate_profile_name(profile) - except ValueError: - return None - output = PurePosixPath(*relative.parts[1:]) - if len(output.parts) == 1: - name = output.name - if name in _FIXED_OUTPUTS: - return profile - if name.startswith("result_") and name.endswith("_table.tex"): - return profile - return None - if ( - len(output.parts) == 2 - and output.parts[0] == "results" - and output.name.endswith(".json") - ): - return profile - return None - - -def _changed_paths( - repo_root: Path, - base_revision: str, - revision: str, -) -> tuple[tuple[str, str], ...]: - raw = _git( - repo_root, - ( - "diff", - "--no-renames", - "--name-status", - "-z", - f"{base_revision}..{revision}", - ), - text=False, - ) - assert isinstance(raw, bytes) - fields = raw.split(b"\0") - if fields[-1:] == [b""]: - fields.pop() - if len(fields) % 2: - raise AggregateAuditError("malformed NUL-delimited git diff output") - changed: list[tuple[str, str]] = [] - for offset in range(0, len(fields), 2): - status = fields[offset].decode("ascii", errors="strict") - path = fields[offset + 1].decode("utf-8", errors="surrogateescape") - changed.append((status, path)) - return tuple(changed) - - -def _tree_entry(repo_root: Path, revision: str, path: str) -> bytes: - raw = _git( - repo_root, - ("ls-tree", "-z", revision, "--", path), - text=False, - ) - assert isinstance(raw, bytes) - return raw - - -def _profile_tree(repo_root: Path, revision: str, profile: str) -> str: - path = (_PROFILE_ROOT / profile).as_posix() - output = _git(repo_root, ("rev-parse", f"{revision}:{path}")) - assert isinstance(output, str) - return output.strip() - - -def audit_aggregate_report( - repo_root: Path, - *, - base_revision: str, - revision: str, - audited_profiles: Mapping[str, str], -) -> dict[str, object]: - """Verify exact report-only paths and audited profile subtree identities.""" - - root = repo_root.expanduser().resolve(strict=True) - base = _commit(root, base_revision) - aggregate = _commit(root, revision) - _git(root, ("merge-base", "--is-ancestor", base, aggregate)) - - audited = { - validate_profile_name(profile): _commit(root, profile_revision) - for profile, profile_revision in audited_profiles.items() - } - if not audited: - raise AggregateAuditError("at least one audited profile is required") - - changed = _changed_paths(root, base, aggregate) - changed_profiles: set[str] = set() - for status, path in changed: - if status not in {"A", "M"}: - raise AggregateAuditError( - f"aggregate path must be added or modified, not {status}: {path}" - ) - profile = _profile_for_output(path) - if profile is None: - raise AggregateAuditError( - f"aggregate commit changes a non-publication output: {path}" - ) - entry = _tree_entry(root, aggregate, path) - if not entry.startswith(b"100644 blob ") or not entry.endswith(b"\0"): - raise AggregateAuditError( - f"aggregate output is not one regular non-executable file: {path}" - ) - changed_profiles.add(profile) - - if not changed_profiles: - raise AggregateAuditError("aggregate commit contains no report outputs") - missing = changed_profiles.difference(audited) - if missing: - raise AggregateAuditError( - "aggregate changes profiles without audited revisions: " - + ", ".join(sorted(missing)) - ) - - for profile in sorted(changed_profiles): - profile_revision = audited[profile] - _git( - root, - ("merge-base", "--is-ancestor", profile_revision, aggregate), - ) - aggregate_tree = _profile_tree(root, aggregate, profile) - audited_tree = _profile_tree(root, profile_revision, profile) - if aggregate_tree != audited_tree: - raise AggregateAuditError( - f"aggregate {profile!r} subtree differs from its audited revision" - ) - - return { - "schema": "pyamplicol-report-aggregate-audit-v1", - "base_revision": base, - "aggregate_revision": aggregate, - "changed_path_count": len(changed), - "changed_profiles": sorted(changed_profiles), - "audited_profile_revisions": { - profile: audited[profile] for profile in sorted(changed_profiles) - }, - "status": "ok", - } - - -def _audited_profile(value: str) -> tuple[str, str]: - profile, separator, revision = value.partition("=") - if not separator or not revision: - raise argparse.ArgumentTypeError( - "audited profile must use PROFILE=REVISION" - ) - try: - validated = validate_profile_name(profile) - except ValueError as error: - raise argparse.ArgumentTypeError(str(error)) from error - return validated, revision - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description="Authenticate a main commit assembled from audited reports." - ) - parser.add_argument("--repo-root", type=Path, default=Path.cwd()) - parser.add_argument("--base-revision", required=True) - parser.add_argument("--revision", default="HEAD") - parser.add_argument( - "--audited-profile", - action="append", - default=[], - type=_audited_profile, - metavar="PROFILE=REVISION", - ) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(argv) - audited = dict(arguments.audited_profile) - if len(audited) != len(arguments.audited_profile): - raise AggregateAuditError("each audited profile may appear only once") - result = audit_aggregate_report( - arguments.repo_root, - base_revision=arguments.base_revision, - revision=arguments.revision, - audited_profiles=audited, - ) - print(json.dumps(result, sort_keys=True)) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/performance_report/agreements.py b/pyamplicol/tools/performance_report/agreements.py deleted file mode 100644 index fb3f235da0..0000000000 --- a/pyamplicol/tools/performance_report/agreements.py +++ /dev/null @@ -1,1135 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Direct numerical-agreement edges required by the publication contract.""" - -from __future__ import annotations - -import hashlib -import json -import math -from collections.abc import Mapping, Sequence -from dataclasses import dataclass - -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import ( - Accuracy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .runner import ( - ABSOLUTE_TOLERANCE, - CONDITIONED_COMPARISON_ABI, - INDEPENDENT_RELATIVE_TOLERANCE, - MADGRAPH_RELATIVE_TOLERANCE, - RELATIVE_TOLERANCE, - SelectorContract, - _real_nonnegative, - point_digest, - pointwise_validation, - validate_conditioned_comparison_record, -) - -DIRECT_AGREEMENT_ABI = "pyamplicol-report-direct-agreement-v1" -DIRECT_AGREEMENT_V1_ABI = DIRECT_AGREEMENT_ABI -DIRECT_AGREEMENT_V2_ABI = "pyamplicol-report-direct-agreement-v2" -LC_COMMON_COMPONENT_ABI = "pyamplicol-report-lc-common-component-v1" -BUILTIN_UFO_RECURRENCE = "builtin-ufo-recurrence" -Z_RECURRENCE_CROSS_MODE = "z-recurrence-cross-mode" -LC_CROSS_LAYOUT_COMPONENT = "lc-cross-layout-component" -LC_LEGACY_PYAMPLICOL_COMPONENT = "lc-legacy-pyamplicol-component" -MADGRAPH_FULL_COLOUR = "madgraph-full-colour" -DIRECT_AGREEMENT_KINDS = ( - BUILTIN_UFO_RECURRENCE, - Z_RECURRENCE_CROSS_MODE, - LC_CROSS_LAYOUT_COMPONENT, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_FULL_COLOUR, -) -DIRECT_AGREEMENT_FIELD = "direct_agreements" -MADGRAPH_COMPARISON_FIELD = "madgraph_comparison" -MADGRAPH_COMPARISON_ABI = "pyamplicol-report-madgraph-comparison-v1" -LC_COMMON_COMPONENT_FIELD = "lc_common_component" -INDEPENDENT_AUTHORITY_ABI = "pyamplicol-report-independent-authority-v1" -INDEPENDENT_AUTHORITY_FIELD = "independent_authority" -STRICT_RELATIVE_TOLERANCE = RELATIVE_TOLERANCE -STRICT_ABSOLUTE_TOLERANCE = ABSOLUTE_TOLERANCE - - -class AgreementError(RuntimeError): - """A required direct numerical comparison could not be established.""" - - -@dataclass(frozen=True, slots=True) -class AgreementEdge: - kind: str - baseline: CellSpec - candidate: CellSpec - - @property - def value_kind(self) -> str: - return ( - LC_COMMON_COMPONENT_FIELD - if self.kind in {LC_CROSS_LAYOUT_COMPONENT, LC_LEGACY_PYAMPLICOL_COMPONENT} - else "matrix_element" - ) - - @property - def relative_tolerance(self) -> float: - return agreement_relative_tolerance(self.kind) - - @property - def required(self) -> bool: - """Whether this peer is a hard measurement prerequisite. - - Original-AmpliCol LC agreement is useful as a legacy diagnostic when - available, but its absence must not censor an otherwise independently - validated pyAmpliCol measurement. Z cross-mode recurrence is likewise - an availability-only numerical authority. Model-source and - cross-layout pyAmpliCol edges remain mandatory. - """ - - return self.kind not in { - LC_LEGACY_PYAMPLICOL_COMPONENT, - Z_RECURRENCE_CROSS_MODE, - } - - -def validation_baseline_is_required( - cell: CellSpec, - baseline: CellSpec | None, -) -> bool: - """Return whether ``baseline`` is a hard numerical prerequisite. - - Recurrence has its own resolved-sum and high-precision validation path, so - original AmpliCol is an optional diagnostic for recurrence. Compiled and - eager comparison surfaces use recurrence as their availability-only - numerical authority rather than a hard prerequisite. - """ - - if baseline is None: - return False - if baseline.measurement.execution_mode is ExecutionMode.MADGRAPH: - # The MadGraph direct edge is the single authoritative boundary. - return False - if cell.measurement.execution_mode in { - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - } and baseline.measurement.execution_mode in { - ExecutionMode.RECURRENCE, - ExecutionMode.AMPLICOL, - }: - return False - if baseline.measurement.execution_mode is not ExecutionMode.AMPLICOL: - return True - return cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - - -def _unique_cell( - matches: Sequence[CellSpec], - *, - context: str, -) -> CellSpec: - if len(matches) != 1: - qualifier = "no" if not matches else "several" - raise AgreementError(f"{context} has {qualifier} matching report peer cells") - return matches[0] - - -def _builtin_recurrence_peer( - cell: CellSpec, - cells: Sequence[CellSpec], -) -> CellSpec | None: - if ( - cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or cell.measurement.model is not ModelKey.UFO_SM - ): - return None - return _unique_cell( - tuple( - candidate - for candidate in cells - if candidate.measurement.execution_mode is ExecutionMode.RECURRENCE - and candidate.measurement.model is ModelKey.BUILTIN_SM - and candidate.measurement.accuracy is cell.measurement.accuracy - and candidate.process == cell.process - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is cell.workload - and ( - ( - cell.dataset_id.startswith("matrix_recurrence_") - and candidate.dataset_id.startswith("matrix_recurrence_builtin_sm_") - and candidate.variant is None - ) - or ( - cell.dataset_id == "z_external_sm" - and candidate.dataset_id == "z_builtin_sm" - and candidate.variant == "recurrence_jit_o2" - and cell.variant == "recurrence_jit_o2" - ) - ) - ), - context=f"{cell.cell_id} built-in/UFO recurrence agreement", - ) - - -def _z_recurrence_peer( - cell: CellSpec, - cells: Sequence[CellSpec], -) -> CellSpec | None: - if not cell.dataset_id.startswith("z_") or cell.measurement.execution_mode not in { - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - }: - return None - return _unique_cell( - tuple( - candidate - for candidate in cells - if candidate.dataset_id == cell.dataset_id - and candidate.measurement.execution_mode is ExecutionMode.RECURRENCE - and candidate.measurement.model is cell.measurement.model - and candidate.measurement.accuracy is cell.measurement.accuracy - and candidate.variant == "recurrence_jit_o2" - and candidate.process == cell.process - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is cell.workload - ), - context=f"{cell.cell_id} Z recurrence agreement", - ) - - -def _lc_layout_peer( - cell: CellSpec, - cells: Sequence[CellSpec], - *, - catalog: ReportCatalog, -) -> CellSpec | None: - if ( - cell.measurement.accuracy is not Accuracy.LC - or cell.workload is not Workload.ALL_FLOW - or ( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and not catalog.legacy_reference_available(cell) - ) - ): - return None - return _unique_cell( - tuple( - candidate - for candidate in cells - if candidate.dataset_id == cell.dataset_id - and candidate.process == cell.process - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.measurement == cell.measurement - and candidate.variant == cell.variant - and candidate.workload is Workload.SELECTED_FLOW - ), - context=f"{cell.cell_id} LC cross-layout agreement", - ) - - -def _lc_legacy_peer( - cell: CellSpec, - cells: Sequence[CellSpec], - *, - catalog: ReportCatalog, -) -> CellSpec | None: - if ( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - or cell.measurement.accuracy is not Accuracy.LC - or cell.workload is not Workload.ALL_FLOW - or not catalog.legacy_reference_available(cell) - ): - return None - return _unique_cell( - tuple( - candidate - for candidate in cells - if candidate.dataset_id == "reference_amplicol_lc" - and candidate.measurement.execution_mode is ExecutionMode.AMPLICOL - and candidate.measurement.accuracy is Accuracy.LC - and candidate.process == cell.process - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is Workload.ALL_FLOW - ), - context=f"{cell.cell_id} legacy/pyAmpliCol LC agreement", - ) - - -def _madgraph_full_colour_peer( - cell: CellSpec, - cells: Sequence[CellSpec], -) -> CellSpec | None: - if ( - cell.measurement.execution_mode - not in { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - } - or cell.measurement.model is not ModelKey.UFO_SM - or cell.measurement.accuracy is not Accuracy.FULL - or cell.workload is not Workload.CONTRACTED - or cell.dataset_id - not in { - "matrix_recurrence_ufo_sm_full", - "matrix_compiled_ufo_sm_full", - "matrix_eager_ufo_sm_full", - "matrix_on_the_fly_ufo_sm_full", - } - ): - return None - return _unique_cell( - tuple( - candidate - for candidate in cells - if candidate.dataset_id == "reference_madgraph_full" - and candidate.measurement.execution_mode is ExecutionMode.MADGRAPH - and candidate.process == cell.process - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is Workload.CONTRACTED - ), - context=f"{cell.cell_id} MadGraph full-colour agreement", - ) - - -def agreement_relative_tolerance(kind: str) -> float: - """Return the independent tolerance assigned to one direct-edge family.""" - - if kind == LC_LEGACY_PYAMPLICOL_COMPONENT: - return INDEPENDENT_RELATIVE_TOLERANCE - if kind == MADGRAPH_FULL_COLOUR: - return MADGRAPH_RELATIVE_TOLERANCE - if kind in DIRECT_AGREEMENT_KINDS: - return STRICT_RELATIVE_TOLERANCE - raise AgreementError(f"unsupported direct-agreement kind {kind!r}") - - -def madgraph_candidate_precision(cell: CellSpec) -> int: - """Return the precision supported by one full-colour MadGraph candidate.""" - - return 16 if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY else 200 - - -def incoming_agreement_edges( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[AgreementEdge, ...]: - """Return the exact direct-comparison peers consumed by ``cell``.""" - - cells = catalog.measurement_cells() - edges: list[AgreementEdge] = [] - builtin = _builtin_recurrence_peer(cell, cells) - if builtin is not None: - edges.append(AgreementEdge(BUILTIN_UFO_RECURRENCE, builtin, cell)) - recurrence = _z_recurrence_peer(cell, cells) - if recurrence is not None: - edges.append(AgreementEdge(Z_RECURRENCE_CROSS_MODE, recurrence, cell)) - layout = _lc_layout_peer(cell, cells, catalog=catalog) - if layout is not None: - edges.append(AgreementEdge(LC_CROSS_LAYOUT_COMPONENT, layout, cell)) - legacy = _lc_legacy_peer(cell, cells, catalog=catalog) - if legacy is not None: - edges.append(AgreementEdge(LC_LEGACY_PYAMPLICOL_COMPONENT, legacy, cell)) - madgraph = _madgraph_full_colour_peer(cell, cells) - if madgraph is not None: - edges.append(AgreementEdge(MADGRAPH_FULL_COLOUR, madgraph, cell)) - return tuple( - sorted( - edges, - key=lambda edge: ( - DIRECT_AGREEMENT_KINDS.index(edge.kind), - edge.baseline.cell_id, - ), - ) - ) - - -def independent_numerical_authorities( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the canonical ordered independent-authority chain. - - This identity is shared by planning, the isolated worker, strict result - validation, and late reconciliation. Original AmpliCol is deliberately - excluded: it remains a report diagnostic, but no longer certifies a - candidate after MadGraph became the authoritative full-colour boundary. - """ - - if cell.measurement.execution_mode not in { - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - }: - return () - candidates: list[CellSpec] = [] - baseline = catalog.validation_baseline_cell(cell) - recurrence_peer = next( - ( - edge.baseline - for edge in incoming_agreement_edges(cell, catalog=catalog) - if edge.kind == Z_RECURRENCE_CROSS_MODE - ), - None, - ) - recurrence = ( - recurrence_peer - if recurrence_peer is not None - else ( - baseline - if baseline is not None - and baseline.measurement.execution_mode is ExecutionMode.RECURRENCE - else None - ) - ) - if recurrence is not None: - candidates.append(recurrence) - return tuple(candidates) - - -def requires_independent_numerical_authority( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> bool: - """Whether ``cell`` needs an external numerical authority to become OK. - - This is a success-classification rule, not a hard scheduling dependency. - Standalone absolute benchmark surfaces have no catalog authority chain and - are certified by their own strict internal validation contract. Matrix - and Z compiled/eager comparison surfaces do expose such a chain and remain - unverified until one of its endpoints agrees. - """ - - return bool(independent_numerical_authorities(cell, catalog=catalog)) - - -def agreement_edges( - *, - catalog: ReportCatalog = REPORT_CATALOG, - maximum_n_final: int | None = None, -) -> tuple[AgreementEdge, ...]: - selected = tuple( - cell - for cell in catalog.measurement_cells() - if maximum_n_final is None or cell.n_final <= maximum_n_final - ) - selected_ids = {cell.cell_id for cell in selected} - return tuple( - edge - for cell in sorted(selected, key=lambda item: item.cell_id) - for edge in incoming_agreement_edges(cell, catalog=catalog) - if edge.baseline.cell_id in selected_ids - ) - - -def _lc_component_record( - cell: CellSpec, - contract: SelectorContract, - value: float, -) -> dict[str, object]: - return { - "abi": LC_COMMON_COMPONENT_ABI, - "cell_id": cell.cell_id, - "value": value, - "point_digest": contract.point_digest, - "helicity_ids": list(contract.all_flow_helicity_ids), - "color_flow_ids": list(contract.selected_color_flow_ids), - } - - -def evaluate_lc_common_component( - runtime: object, - points: object, - *, - cell: CellSpec, - contract: SelectorContract, -) -> dict[str, object]: - """Evaluate the selector intersection common to both LC layouts.""" - - # Selected-flow topology replay exposes its complete physical-helicity - # axis, but need not have an independently executable singleton lane. - # Resolve that same workload, then select the untimed comparison by ID. - full_helicity_axis = cell.workload is Workload.SELECTED_FLOW - resolved = runtime.evaluate_resolved( # type: ignore[attr-defined] - points, - precision=16, - helicities=( - None if full_helicity_axis else contract.runtime_all_flow_helicity_ids - ), - color_flows=contract.selected_color_flow_ids, - ) - helicity_ids = tuple(getattr(resolved, "helicity_ids", ())) - color_ids = tuple(getattr(resolved, "color_ids", ())) - expected_helicity_ids = contract.runtime_all_flow_helicity_ids - if ( - len(expected_helicity_ids) != 1 - or len(set(helicity_ids)) != len(helicity_ids) - or expected_helicity_ids[0] not in helicity_ids - or (not full_helicity_axis and helicity_ids != expected_helicity_ids) - ): - raise AgreementError( - f"{cell.cell_id} LC common component has a different helicity axis" - ) - if color_ids != contract.selected_color_flow_ids: - raise AgreementError( - f"{cell.cell_id} LC common component has a different color-flow axis" - ) - values = getattr(resolved, "values", None) - try: - helicity_index = helicity_ids.index(expected_helicity_ids[0]) - raw_value = values[0][helicity_index][0] - if ( - len(values) != 1 - or len(values[0]) != len(helicity_ids) - or any(len(row) != 1 for row in values[0]) - ): - raise IndexError - except (IndexError, TypeError) as error: - raise AgreementError( - f"{cell.cell_id} LC common component is not a scalar" - ) from error - return _lc_component_record( - cell, - contract, - _real_nonnegative(raw_value), - ) - - -def legacy_lc_common_component( - cell: CellSpec, - contract: SelectorContract, - value: float, -) -> dict[str, object]: - """Shape an independently probed original-AmpliCol LC row component.""" - - return _lc_component_record(cell, contract, float(value)) - - -def _measurement_number( - measurement: Mapping[str, object], - *, - edge: AgreementEdge, - role: str, -) -> float: - if edge.kind == MADGRAPH_FULL_COLOUR and role == "candidate": - validation = measurement.get("validation") - comparison = ( - validation.get(MADGRAPH_COMPARISON_FIELD) - if isinstance(validation, Mapping) - else None - ) - if not isinstance(comparison, Mapping): - raise AgreementError(f"{edge.candidate.cell_id} has no MadGraph comparison") - value = comparison.get("candidate") - elif edge.value_kind == "matrix_element": - value = measurement.get("matrix_element") - else: - validation = measurement.get("validation") - if not isinstance(validation, Mapping): - raise AgreementError( - f"{edge.candidate.cell_id} {role} validation is unavailable" - ) - observation = validation.get(LC_COMMON_COMPONENT_FIELD) - if not isinstance(observation, Mapping): - raise AgreementError( - f"{edge.candidate.cell_id} {role} LC common component is unavailable" - ) - value = observation.get("value") - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise AgreementError( - f"{edge.candidate.cell_id} {role} {edge.value_kind} is not numeric" - ) - number = float(value) - if not math.isfinite(number): - raise AgreementError( - f"{edge.candidate.cell_id} {role} {edge.value_kind} is not finite" - ) - return number - - -def _agreement_source_digest(value: object) -> str: - return hashlib.sha256( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _measurement_point_digest(measurement: Mapping[str, object]) -> str: - selector = measurement.get("selector_contract") - if isinstance(selector, Mapping): - raw = selector.get("point_digest") - if isinstance(raw, str): - return raw - validation = measurement.get("validation") - if isinstance(validation, Mapping): - raw = validation.get("point_digest") - if isinstance(raw, str): - return raw - provenance = measurement.get("provenance") - if isinstance(provenance, Mapping) and "report_momenta" in provenance: - return point_digest(provenance["report_momenta"]) - raise AgreementError("direct agreement measurement has no point identity") - - -def _measurement_scale( - measurement: Mapping[str, object], - *, - edge: AgreementEdge, - role: str, - number: float, -) -> tuple[float, str, str]: - validation = measurement.get("validation") - if edge.value_kind == LC_COMMON_COMPONENT_FIELD and isinstance(validation, Mapping): - component = validation.get(LC_COMMON_COMPONENT_FIELD) - if isinstance(component, Mapping): - return ( - abs(number), - "authority-component-magnitude", - _agreement_source_digest(component), - ) - if ( - edge.kind != MADGRAPH_FULL_COLOUR - and edge.value_kind == "matrix_element" - and isinstance(validation, Mapping) - ): - resolved = validation.get("resolved_sum") - if isinstance(resolved, Mapping): - records = resolved.get("points") - source = resolved.get("resolved_source_sha256") - if ( - isinstance(records, list) - and len(records) == 1 - and isinstance(records[0], Mapping) - and isinstance(source, str) - ): - raw_scale = records[0].get("candidate_scale") - if ( - not isinstance(raw_scale, bool) - and isinstance(raw_scale, (int, float)) - and math.isfinite(float(raw_scale)) - and float(raw_scale) >= abs(number) - ): - return float(raw_scale), "resolved-component-l1", source - stable_validation = ( - {key: item for key, item in validation.items() if key != DIRECT_AGREEMENT_FIELD} - if isinstance(validation, Mapping) - else validation - ) - source = _agreement_source_digest( - { - "role": role, - "value_kind": edge.value_kind, - "value": number, - "selector_contract": measurement.get("selector_contract"), - "validation": stable_validation, - "provenance": measurement.get("provenance"), - } - ) - return abs(number), "authority-value-magnitude", source - - -def madgraph_comparison_record( - edge: AgreementEdge, - *, - candidate: float, - baseline_measurement: Mapping[str, object], - point_identity: str, -) -> dict[str, object]: - """Build strict candidate-versus-binary64-MadGraph evidence.""" - - if edge.kind != MADGRAPH_FULL_COLOUR: - raise AgreementError("MadGraph comparison requires a MadGraph edge") - baseline = _measurement_number( - baseline_measurement, - edge=edge, - role="baseline", - ) - baseline_point = _measurement_point_digest(baseline_measurement) - if point_identity != baseline_point: - raise AgreementError("MadGraph comparison points differ") - candidate_precision = madgraph_candidate_precision(edge.candidate) - candidate_source = _agreement_source_digest( - { - "cell_id": edge.candidate.cell_id, - "precision": candidate_precision, - "point_digest": point_identity, - "value": candidate, - } - ) - baseline_source = _agreement_source_digest( - { - "cell_id": edge.baseline.cell_id, - "point_digest": baseline_point, - "matrix_element": baseline, - "provenance": baseline_measurement.get("provenance"), - } - ) - identity = { - "candidate_cell_id": edge.candidate.cell_id, - "baseline_cell_id": edge.baseline.cell_id, - "candidate_precision": candidate_precision, - "baseline_precision": "binary64", - "point_digest": point_identity, - } - comparison = pointwise_validation( - candidate, - baseline, - relative_tolerance=MADGRAPH_RELATIVE_TOLERANCE, - candidate_scale=abs(candidate), - baseline_scale=abs(baseline), - candidate_scale_source=f"p{candidate_precision}-value-magnitude", - baseline_scale_source="madgraph-binary64-value-magnitude", - comparison_binding={ - "point_digest": point_identity, - "selector_component_identity": identity, - "selector_component_sha256": _agreement_source_digest(identity), - "candidate_source_sha256": candidate_source, - "baseline_source_sha256": baseline_source, - }, - ) - return { - "abi": MADGRAPH_COMPARISON_ABI, - "candidate_cell_id": edge.candidate.cell_id, - "baseline_cell_id": edge.baseline.cell_id, - "candidate_precision": candidate_precision, - "baseline_precision": "binary64", - **{key: value for key, value in comparison.items() if key != "abi"}, - } - - -def validate_madgraph_comparison_record( - value: object, - *, - expected_candidate_id: str | None = None, - expected_candidate_precision: int | None = None, -) -> None: - if not isinstance(value, Mapping): - raise ValueError(f"{MADGRAPH_COMPARISON_FIELD} must be an object") - identity_fields = { - "abi", - "candidate_cell_id", - "baseline_cell_id", - "candidate_precision", - "baseline_precision", - } - comparison_fields = { - "status", - "candidate", - "baseline", - "candidate_scale", - "baseline_scale", - "candidate_scale_source", - "baseline_scale_source", - "comparison_scale", - "absolute_difference", - "relative_difference", - "conditioned_residual", - "error_bound", - "relative_tolerance", - "comparison_binding", - } - if set(value) != identity_fields | comparison_fields: - raise ValueError(f"{MADGRAPH_COMPARISON_FIELD} fields differ from the ABI") - candidate_id = value.get("candidate_cell_id") - baseline_id = value.get("baseline_cell_id") - if ( - value.get("abi") != MADGRAPH_COMPARISON_ABI - or not isinstance(candidate_id, str) - or not candidate_id - or ( - expected_candidate_id is not None - and candidate_id != expected_candidate_id - ) - or not isinstance(baseline_id, str) - or not baseline_id - or value.get("candidate_precision") not in {16, 200} - or ( - expected_candidate_precision is not None - and value.get("candidate_precision") != expected_candidate_precision - ) - or value.get("baseline_precision") != "binary64" - ): - raise ValueError(f"{MADGRAPH_COMPARISON_FIELD} identity is invalid") - comparison = { - key: item for key, item in value.items() if key not in identity_fields - } - comparison["abi"] = CONDITIONED_COMPARISON_ABI - validate_conditioned_comparison_record(comparison, require_binding=True) - if float(comparison["relative_tolerance"]) != MADGRAPH_RELATIVE_TOLERANCE: - raise ValueError(f"{MADGRAPH_COMPARISON_FIELD} tolerance is invalid") - - -def direct_agreement_record( - edge: AgreementEdge, - *, - candidate_measurement: Mapping[str, object], - baseline_measurement: Mapping[str, object], -) -> dict[str, object]: - candidate = _measurement_number( - candidate_measurement, - edge=edge, - role="candidate", - ) - baseline = _measurement_number( - baseline_measurement, - edge=edge, - role="baseline", - ) - candidate_scale, candidate_scale_source, candidate_source = _measurement_scale( - candidate_measurement, - edge=edge, - role="candidate", - number=candidate, - ) - baseline_scale, baseline_scale_source, baseline_source = _measurement_scale( - baseline_measurement, - edge=edge, - role="baseline", - number=baseline, - ) - candidate_point = _measurement_point_digest(candidate_measurement) - baseline_point = _measurement_point_digest(baseline_measurement) - if candidate_point != baseline_point: - raise AgreementError("direct agreement points differ") - selector_identity = { - "candidate_cell_id": edge.candidate.cell_id, - "baseline_cell_id": edge.baseline.cell_id, - "candidate_accuracy": edge.candidate.measurement.accuracy.value, - "baseline_accuracy": edge.baseline.measurement.accuracy.value, - "candidate_workload": edge.candidate.workload.value, - "baseline_workload": edge.baseline.workload.value, - "value_kind": edge.value_kind, - "candidate_selector": candidate_measurement.get("selector_contract"), - "baseline_selector": baseline_measurement.get("selector_contract"), - } - comparison = pointwise_validation( - candidate, - baseline, - relative_tolerance=edge.relative_tolerance, - candidate_scale=candidate_scale, - baseline_scale=baseline_scale, - candidate_scale_source=candidate_scale_source, - baseline_scale_source=baseline_scale_source, - comparison_binding={ - "point_digest": candidate_point, - "selector_component_identity": selector_identity, - "selector_component_sha256": _agreement_source_digest(selector_identity), - "candidate_source_sha256": candidate_source, - "baseline_source_sha256": baseline_source, - }, - ) - comparison.pop("abi") - return { - "abi": DIRECT_AGREEMENT_V2_ABI, - "edge_kind": edge.kind, - "value_kind": edge.value_kind, - "baseline_cell_id": edge.baseline.cell_id, - "candidate_cell_id": edge.candidate.cell_id, - **comparison, - } - - -def validate_direct_agreement_records( - value: object, - *, - expected_candidate_id: str | None = None, -) -> None: - """Validate the complete per-measurement direct-agreement wire contract.""" - - if not isinstance(value, list): - raise ValueError(f"{DIRECT_AGREEMENT_FIELD} must be an array") - identity_fields = { - "abi", - "edge_kind", - "value_kind", - "baseline_cell_id", - "candidate_cell_id", - } - v1_fields = identity_fields | { - "status", - "candidate", - "baseline", - "absolute_difference", - "relative_difference", - "relative_tolerance", - "absolute_tolerance", - } - v2_fields = identity_fields | { - "status", - "candidate", - "baseline", - "candidate_scale", - "baseline_scale", - "candidate_scale_source", - "baseline_scale_source", - "comparison_scale", - "absolute_difference", - "relative_difference", - "conditioned_residual", - "error_bound", - "relative_tolerance", - "comparison_binding", - } - seen: set[tuple[str, str, str]] = set() - for index, raw in enumerate(value): - if not isinstance(raw, Mapping): - raise ValueError(f"{DIRECT_AGREEMENT_FIELD}[{index}] must be an object") - abi = raw.get("abi") - expected_fields = v2_fields if abi == DIRECT_AGREEMENT_V2_ABI else v1_fields - if set(raw) != expected_fields: - raise ValueError( - f"{DIRECT_AGREEMENT_FIELD}[{index}] fields differ from the ABI" - ) - kind = raw.get("edge_kind") - if not isinstance(kind, str) or kind not in DIRECT_AGREEMENT_KINDS: - raise ValueError( - f"{DIRECT_AGREEMENT_FIELD}[{index}] edge kind is unsupported" - ) - expected_value_kind = ( - LC_COMMON_COMPONENT_FIELD - if kind in {LC_CROSS_LAYOUT_COMPONENT, LC_LEGACY_PYAMPLICOL_COMPONENT} - else "matrix_element" - ) - baseline_id = raw.get("baseline_cell_id") - candidate_id = raw.get("candidate_cell_id") - if ( - abi not in {DIRECT_AGREEMENT_V2_ABI, DIRECT_AGREEMENT_V1_ABI} - or raw.get("value_kind") != expected_value_kind - or not isinstance(baseline_id, str) - or not baseline_id - or not isinstance(candidate_id, str) - or not candidate_id - or ( - expected_candidate_id is not None - and candidate_id != expected_candidate_id - ) - ): - raise ValueError(f"{DIRECT_AGREEMENT_FIELD}[{index}] identity is invalid") - key = (kind, baseline_id, candidate_id) - if key in seen: - raise ValueError(f"{DIRECT_AGREEMENT_FIELD}[{index}] duplicates an edge") - seen.add(key) - expected_relative_tolerance = agreement_relative_tolerance(kind) - comparison = { - key: item for key, item in raw.items() if key not in identity_fields - } - if abi == DIRECT_AGREEMENT_V2_ABI: - comparison["abi"] = CONDITIONED_COMPARISON_ABI - try: - validate_conditioned_comparison_record( - comparison, - require_binding=abi == DIRECT_AGREEMENT_V2_ABI, - ) - except ValueError as error: - raise ValueError( - f"{DIRECT_AGREEMENT_FIELD}[{index}] numerical record is invalid" - ) from error - if float(comparison["relative_tolerance"]) != expected_relative_tolerance: - raise ValueError(f"{DIRECT_AGREEMENT_FIELD}[{index}] tolerance is invalid") - if ( - abi == DIRECT_AGREEMENT_V1_ABI - and float(comparison["absolute_tolerance"]) != STRICT_ABSOLUTE_TOLERANCE - ): - raise ValueError( - f"{DIRECT_AGREEMENT_FIELD}[{index}] legacy tolerance is invalid" - ) - if ( - raw.get("status") != ResultStatus.OK.value - and kind != LC_LEGACY_PYAMPLICOL_COMPONENT - ): - raise ValueError( - f"{DIRECT_AGREEMENT_FIELD}[{index}] agreement is not successful" - ) - - -def validate_lc_common_component( - value: object, - *, - expected_cell_id: str | None = None, - selector_contract: object = None, -) -> None: - """Validate one LC component record before it is admitted to the cache.""" - - if not isinstance(value, Mapping): - raise ValueError(f"{LC_COMMON_COMPONENT_FIELD} must be an object") - expected_fields = { - "abi", - "cell_id", - "value", - "point_digest", - "helicity_ids", - "color_flow_ids", - } - if set(value) != expected_fields: - raise ValueError(f"{LC_COMMON_COMPONENT_FIELD} fields differ from the ABI") - cell_id = value.get("cell_id") - number = value.get("value") - point_digest = value.get("point_digest") - helicity_ids = value.get("helicity_ids") - color_flow_ids = value.get("color_flow_ids") - if ( - value.get("abi") != LC_COMMON_COMPONENT_ABI - or not isinstance(cell_id, str) - or not cell_id - or (expected_cell_id is not None and cell_id != expected_cell_id) - or isinstance(number, bool) - or not isinstance(number, (int, float)) - or not math.isfinite(float(number)) - or not isinstance(point_digest, str) - or len(point_digest) != 64 - or any(character not in "0123456789abcdef" for character in point_digest) - or not isinstance(helicity_ids, list) - or not helicity_ids - or any(not isinstance(item, str) or not item for item in helicity_ids) - or len(set(helicity_ids)) != len(helicity_ids) - or not isinstance(color_flow_ids, list) - or not color_flow_ids - or any(not isinstance(item, str) or not item for item in color_flow_ids) - or len(set(color_flow_ids)) != len(color_flow_ids) - ): - raise ValueError(f"{LC_COMMON_COMPONENT_FIELD} record is invalid") - if selector_contract is not None: - try: - selector = SelectorContract.from_mapping( - selector_contract # type: ignore[arg-type] - ) - except (TypeError, ValueError, RuntimeError) as error: - raise ValueError("selector contract is invalid") from error - if ( - point_digest != selector.point_digest - or helicity_ids != list(selector.all_flow_helicity_ids) - or color_flow_ids != list(selector.selected_color_flow_ids) - ): - raise ValueError( - f"{LC_COMMON_COMPONENT_FIELD} is not bound to the selector" - ) - - -def attach_direct_agreements( - cell: CellSpec, - measurement: dict[str, object], - peers: Mapping[str, Mapping[str, object]], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> None: - """Attach every incoming direct edge and make authoritative failures terminal.""" - - initial_status = measurement.get("status") - if initial_status not in { - ResultStatus.OK.value, - ResultStatus.UNVERIFIED.value, - }: - return - validation = measurement.get("validation") - if not isinstance(validation, Mapping): - raise AgreementError(f"{cell.cell_id} has no validation record") - mutable_validation = dict(validation) - expected = incoming_agreement_edges(cell, catalog=catalog) - expected_peer_ids = {edge.baseline.cell_id for edge in expected} - required_peer_ids = {edge.baseline.cell_id for edge in expected if edge.required} - observed_peer_ids = set(peers) - if not required_peer_ids.issubset(observed_peer_ids) or not ( - observed_peer_ids <= expected_peer_ids - ): - raise AgreementError( - f"{cell.cell_id} direct-agreement peers differ: " - f"required={sorted(required_peer_ids)}, " - f"allowed={sorted(expected_peer_ids)}, " - f"observed={sorted(observed_peer_ids)}" - ) - records: list[dict[str, object]] = [] - for edge in expected: - if edge.baseline.cell_id not in peers: - assert not edge.required - continue - peer = peers[edge.baseline.cell_id] - if peer.get("status") != ResultStatus.OK.value: - raise AgreementError( - f"{cell.cell_id} peer {edge.baseline.cell_id} is not successful" - ) - if measurement.get("selector_contract") != peer.get("selector_contract"): - raise AgreementError( - f"{cell.cell_id} selector contract differs from direct peer " - f"{edge.baseline.cell_id}" - ) - records.append( - direct_agreement_record( - edge, - candidate_measurement=measurement, - baseline_measurement=peer, - ) - ) - mutable_validation[DIRECT_AGREEMENT_FIELD] = records - failed = any( - record["status"] != ResultStatus.OK.value - and record["edge_kind"] != LC_LEGACY_PYAMPLICOL_COMPONENT - for record in records - ) - if failed: - mutable_validation["status"] = ResultStatus.VALIDATION_FAILED.value - measurement["status"] = ResultStatus.VALIDATION_FAILED.value - measurement["failure"] = { - "kind": "MeasurementValidationError", - "message": "required direct numerical agreement failed", - } - elif initial_status == ResultStatus.UNVERIFIED.value: - # Hard model/layout/provider agreements remain mandatory even when the - # independent recurrence numerical authority is unavailable. - # Passing them is necessary but deliberately cannot promote a - # diagnostic candidate to a reusable success. - mutable_validation["status"] = ResultStatus.UNVERIFIED.value - measurement["validation"] = mutable_validation - - -__all__ = [ - "BUILTIN_UFO_RECURRENCE", - "DIRECT_AGREEMENT_ABI", - "DIRECT_AGREEMENT_FIELD", - "DIRECT_AGREEMENT_KINDS", - "DIRECT_AGREEMENT_V2_ABI", - "INDEPENDENT_AUTHORITY_ABI", - "INDEPENDENT_AUTHORITY_FIELD", - "LC_COMMON_COMPONENT_ABI", - "LC_COMMON_COMPONENT_FIELD", - "LC_CROSS_LAYOUT_COMPONENT", - "LC_LEGACY_PYAMPLICOL_COMPONENT", - "MADGRAPH_COMPARISON_ABI", - "MADGRAPH_COMPARISON_FIELD", - "MADGRAPH_FULL_COLOUR", - "STRICT_ABSOLUTE_TOLERANCE", - "STRICT_RELATIVE_TOLERANCE", - "Z_RECURRENCE_CROSS_MODE", - "AgreementEdge", - "AgreementError", - "agreement_edges", - "agreement_relative_tolerance", - "attach_direct_agreements", - "direct_agreement_record", - "evaluate_lc_common_component", - "incoming_agreement_edges", - "independent_numerical_authorities", - "legacy_lc_common_component", - "madgraph_candidate_precision", - "madgraph_comparison_record", - "requires_independent_numerical_authority", - "validate_direct_agreement_records", - "validate_lc_common_component", - "validate_madgraph_comparison_record", - "validation_baseline_is_required", -] diff --git a/pyamplicol/tools/performance_report/arena_profile.py b/pyamplicol/tools/performance_report/arena_profile.py deleted file mode 100644 index 70c816a98d..0000000000 --- a/pyamplicol/tools/performance_report/arena_profile.py +++ /dev/null @@ -1,401 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Fail-closed evidence for the private warmed-Arena profiling boundary.""" - -from __future__ import annotations - -import hashlib -import json -import math -from collections.abc import Mapping, Sequence - -ARENA_PROFILE_EVIDENCE_ABI = "pyamplicol-report-arena-profile-evidence-v1" -ARENA_PROFILE_PROTOCOL = "arena" -ARENA_PROFILE_SAMPLE_PASS = "runtime._profile_arena_repeated" -ARENA_PROFILE_BOUNDARY = ( - "warmed-direct-arena-borrowed-input-preallocated-output-v1" -) -ARENA_PHASE_TIMING_SCOPE = "coarse-arena-boundary-only-v1" -PAIRED_TIMING_SAMPLE_CONTRACT = ( - "paired_unprofiled_headline_profiled_attribution_v1" -) - -ZERO_ARENA_COUNTER_FIELDS = ( - "native_input_container_allocation_count", - "native_input_pack_bytes", - "native_input_crossing_bytes", - "stage_input_copy_component_count", - "stage_leaf_input_copy_component_count", - "stage_evaluator_output_gather_component_count", - "stage_output_assign_component_count", - "amplitude_input_copy_component_count", - "amplitude_leaf_input_copy_component_count", - "amplitude_evaluator_output_gather_component_count", - "amplitude_output_remap_component_count", - "selector_gather_point_count", - "selector_gather_bytes", - "selector_scatter_value_count", - "observed_scratch_reallocation_count", - "native_output_allocation_count", -) -ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS = ( - "compiled_direct_arena_boundary_input_bytes", - "compiled_direct_arena_boundary_current_output_bytes", - "compiled_direct_arena_boundary_amplitude_output_bytes", -) -COMPILED_ACTIVITY_COUNTER_FIELDS = ( - "compiled_direct_arena_engine_count", - "compiled_direct_arena_call_count", - "evaluator_backend_call_count", -) -ZERO_ARENA_PHASE_TIME_FIELDS = ( - "native_input_pack_time_s", - "native_input_crossing_time_s", - "state_prepare_time_s", - "state_clear_time_s", - "source_fill_time_s", - "momentum_input_setup_time_s", - "momentum_setup_time_s", - "model_parameter_setup_time_s", - "stage_input_pack_time_s", - "stage_leaf_input_pack_time_s", - "stage_evaluator_call_time_s", - "stage_evaluator_time_s", - "stage_backend_call_time_s", - "stage_evaluator_output_gather_time_s", - "output_assign_time_s", - "amplitude_input_pack_time_s", - "amplitude_leaf_input_pack_time_s", - "amplitude_evaluator_call_time_s", - "amplitude_backend_call_time_s", - "amplitude_evaluator_output_gather_time_s", - "amplitude_output_remap_time_s", - "amplitude_evaluator_time_s", - "reduction_time_s", - "resolved_reduction_materialization_inclusive_time_s", - "total_materialization_time_s", - "final_output_copy_time_s", - "eager_initialize_time_s", - "eager_gather_time_s", - "eager_kernel_call_time_s", - "eager_invocation_scatter_time_s", - "eager_finalization_time_s", - "eager_scatter_finalization_time_s", - "eager_closure_time_s", - "eager_reduction_time_s", - "eager_copy_out_time_s", - "recurrence_momentum_fill_time_s", - "recurrence_union_source_fill_time_s", - "recurrence_schedule_time_s", - "recurrence_source_kernel_time_s", - "recurrence_contribution_kernel_time_s", - "recurrence_finalization_time_s", - "recurrence_closure_time_s", - "recurrence_replay_output_mapping_time_s", - "selector_planner_time_s", - "selector_gather_time_s", - "selector_scatter_time_s", -) -EMPTY_ARENA_PHASE_VECTOR_FIELDS = ( - "stage_input_pack_by_stage_time_s", - "stage_leaf_input_pack_by_stage_time_s", - "stage_evaluator_call_by_stage_time_s", - "stage_backend_call_by_stage_time_s", - "stage_evaluator_output_gather_by_stage_time_s", - "stage_output_assign_by_stage_time_s", -) -ARENA_PROFILE_EVIDENCE_FIELDS = frozenset( - { - "abi", - "execution_mode", - "profile_count", - "repetitions_per_profile", - "batch_size", - "evaluated_points_per_profile", - "total_evaluated_points", - "warmed_boundary_wall_seconds_per_point", - "raw_profiles", - "raw_profiles_sha256", - "counter_totals", - "counter_totals_sha256", - } -) - - -class ArenaProfileEvidenceError(ValueError): - """Raised when warmed-Arena profile evidence is incomplete or inconsistent.""" - - -def _canonical_json(value: object) -> bytes: - try: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - except (TypeError, ValueError) as error: - raise ArenaProfileEvidenceError( - "Arena profile evidence is not canonical JSON" - ) from error - - -def digest_arena_profile_value(value: object) -> str: - return hashlib.sha256(_canonical_json(value)).hexdigest() - - -def _json_copy(value: object) -> object: - return json.loads(_canonical_json(value).decode("ascii")) - - -def _positive_integer(value: object, name: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 1: - raise ArenaProfileEvidenceError(f"{name} must be a positive integer") - return value - - -def _integer(profile: Mapping[str, object], field: str) -> int: - value = profile.get(field) - if isinstance(value, bool) or not isinstance(value, int): - raise ArenaProfileEvidenceError( - f"Arena profile field {field!r} must be an integer" - ) - return value - - -def _finite(profile: Mapping[str, object], field: str) -> float: - value = profile.get(field) - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - ): - raise ArenaProfileEvidenceError( - f"Arena profile field {field!r} must be finite" - ) - return float(value) - - -def _counter_fields( - profiles: Sequence[Mapping[str, object]], -) -> tuple[str, ...]: - """Return every scalar native count/traffic field exposed by the samples.""" - - inventories = [ - { - field - for field, value in profile.items() - if field == "points" - or ( - (field.endswith("_count") or field.endswith("_bytes")) - and isinstance(value, int) - and not isinstance(value, bool) - ) - } - for profile in profiles - ] - expected = inventories[0] - if any(inventory != expected for inventory in inventories[1:]): - raise ArenaProfileEvidenceError( - "Arena profile counter inventory differs between raw samples" - ) - return tuple(sorted(expected)) - - -def _validate_raw_profile( - profile: Mapping[str, object], - *, - execution_mode: str, - evaluated_points: int, -) -> None: - if profile.get("execution_mode") != execution_mode: - raise ArenaProfileEvidenceError( - "Arena profile execution mode does not match the measured runtime" - ) - if ( - profile.get("profile_boundary") != ARENA_PROFILE_BOUNDARY - or profile.get("borrowed_flat_input") is not True - or profile.get("preallocated_output") is not True - or profile.get("phase_timing_scope") != ARENA_PHASE_TIMING_SCOPE - or profile.get("evaluator_timing_available") is not False - ): - raise ArenaProfileEvidenceError( - "Arena profile does not authenticate the warmed borrowed-input, " - "preallocated-output boundary" - ) - if _integer(profile, "points") != evaluated_points: - raise ArenaProfileEvidenceError( - "Arena profile point count does not match batch repetitions" - ) - wall = _finite(profile, "wall_time_s") - orchestration = _finite(profile, "orchestration_time_s") - if wall <= 0.0 or orchestration != wall: - raise ArenaProfileEvidenceError( - "Arena profile boundary wall time must be positive and fully " - "accounted by orchestration" - ) - zero_counter_fields = [ - *ZERO_ARENA_COUNTER_FIELDS, - *ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS, - ] - for field in zero_counter_fields: - if _integer(profile, field) != 0: - raise ArenaProfileEvidenceError( - f"Arena profile field {field!r} must be zero" - ) - for field in ZERO_ARENA_PHASE_TIME_FIELDS: - if _finite(profile, field) != 0.0: - raise ArenaProfileEvidenceError( - f"Arena profile field {field!r} must be zero" - ) - for field in EMPTY_ARENA_PHASE_VECTOR_FIELDS: - if profile.get(field) != []: - raise ArenaProfileEvidenceError( - f"Arena profile field {field!r} must be an empty list" - ) - if execution_mode == "compiled": - engine_count = _integer(profile, "compiled_direct_arena_engine_count") - call_count = _integer(profile, "compiled_direct_arena_call_count") - backend_count = _integer(profile, "evaluator_backend_call_count") - if engine_count <= 0 or call_count <= 0 or backend_count <= 0: - raise ArenaProfileEvidenceError( - "compiled Arena profile activity counters must be positive" - ) - if call_count != backend_count: - raise ArenaProfileEvidenceError( - "compiled Arena calls do not cover every evaluator backend call" - ) - - -def build_arena_profile_evidence( - raw_profiles: Sequence[Mapping[str, object]], - *, - execution_mode: str, - repetitions_per_profile: int, - batch_size: int, -) -> dict[str, object]: - """Validate raw samples and build their independently recomputed evidence.""" - - if execution_mode not in {"compiled", "eager"}: - raise ArenaProfileEvidenceError("Arena profile execution mode is unsupported") - repetitions = _positive_integer( - repetitions_per_profile, - "repetitions_per_profile", - ) - points_per_batch = _positive_integer(batch_size, "batch_size") - if ( - isinstance(raw_profiles, (str, bytes, bytearray)) - or not isinstance(raw_profiles, Sequence) - or not raw_profiles - ): - raise ArenaProfileEvidenceError("Arena profile evidence requires raw samples") - evaluated_points = repetitions * points_per_batch - canonical_profiles: list[dict[str, object]] = [] - wall_per_point: list[float] = [] - for index, raw_profile in enumerate(raw_profiles): - if not isinstance(raw_profile, Mapping): - raise ArenaProfileEvidenceError( - f"Arena profile sample {index} is not an object" - ) - copied = _json_copy(dict(raw_profile)) - if not isinstance(copied, dict): - raise ArenaProfileEvidenceError( - f"Arena profile sample {index} is not an object" - ) - _validate_raw_profile( - copied, - execution_mode=execution_mode, - evaluated_points=evaluated_points, - ) - canonical_profiles.append(copied) - wall_per_point.append(float(copied["wall_time_s"]) / evaluated_points) - counter_totals = { - field: 0 for field in _counter_fields(canonical_profiles) - } - for copied in canonical_profiles: - for field in counter_totals: - counter_totals[field] += _integer(copied, field) - profile_count = len(canonical_profiles) - warmed_wall = math.fsum(wall_per_point) / profile_count - return { - "abi": ARENA_PROFILE_EVIDENCE_ABI, - "execution_mode": execution_mode, - "profile_count": profile_count, - "repetitions_per_profile": repetitions, - "batch_size": points_per_batch, - "evaluated_points_per_profile": evaluated_points, - "total_evaluated_points": profile_count * evaluated_points, - "warmed_boundary_wall_seconds_per_point": warmed_wall, - "raw_profiles": canonical_profiles, - "raw_profiles_sha256": digest_arena_profile_value(canonical_profiles), - "counter_totals": counter_totals, - "counter_totals_sha256": digest_arena_profile_value(counter_totals), - } - - -def validate_arena_profile_evidence( - value: object, - *, - execution_mode: str, - sample_count: int, - native_profile_points_per_sample: int, -) -> Mapping[str, object]: - """Recompute and authenticate stored warmed-Arena evidence.""" - - if not isinstance(value, Mapping) or set(value) != ARENA_PROFILE_EVIDENCE_FIELDS: - raise ArenaProfileEvidenceError( - "Arena profile evidence fields do not match the contract" - ) - raw_profiles = value.get("raw_profiles") - if not isinstance(raw_profiles, Sequence) or isinstance( - raw_profiles, - (str, bytes, bytearray), - ): - raise ArenaProfileEvidenceError("Arena profile raw samples are invalid") - repetitions = _positive_integer( - value.get("repetitions_per_profile"), - "repetitions_per_profile", - ) - batch_size = _positive_integer(value.get("batch_size"), "batch_size") - rebuilt = build_arena_profile_evidence( - raw_profiles, # type: ignore[arg-type] - execution_mode=execution_mode, - repetitions_per_profile=repetitions, - batch_size=batch_size, - ) - if dict(value) != rebuilt: - raise ArenaProfileEvidenceError( - "Arena profile evidence differs from independently recomputed values" - ) - if rebuilt["profile_count"] != sample_count: - raise ArenaProfileEvidenceError( - "Arena profile count does not match the measurement sample count" - ) - if ( - rebuilt["evaluated_points_per_profile"] - != native_profile_points_per_sample - ): - raise ArenaProfileEvidenceError( - "Arena profile point count does not match timing provenance" - ) - return value - - -__all__ = [ - "ARENA_PHASE_TIMING_SCOPE", - "ARENA_PROFILE_BOUNDARY", - "ARENA_PROFILE_EVIDENCE_ABI", - "ARENA_PROFILE_EVIDENCE_FIELDS", - "ARENA_PROFILE_PROTOCOL", - "ARENA_PROFILE_SAMPLE_PASS", - "COMPILED_ACTIVITY_COUNTER_FIELDS", - "EMPTY_ARENA_PHASE_VECTOR_FIELDS", - "PAIRED_TIMING_SAMPLE_CONTRACT", - "ZERO_ARENA_COUNTER_FIELDS", - "ZERO_ARENA_PHASE_TIME_FIELDS", - "ZERO_COMPILED_BOUNDARY_COUNTER_FIELDS", - "ArenaProfileEvidenceError", - "build_arena_profile_evidence", - "digest_arena_profile_value", - "validate_arena_profile_evidence", -] diff --git a/pyamplicol/tools/performance_report/artifacts.py b/pyamplicol/tools/performance_report/artifacts.py deleted file mode 100644 index 06771dae81..0000000000 --- a/pyamplicol/tools/performance_report/artifacts.py +++ /dev/null @@ -1,1686 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Immutable report artifacts, validated current pointers, and filesystem locks.""" - -from __future__ import annotations - -import errno -import fcntl -import hashlib -import json -import os -import re -import shutil -import threading -import time -import uuid -from collections.abc import Callable, Iterable, Iterator, Mapping -from contextlib import contextmanager -from dataclasses import dataclass -from enum import StrEnum -from pathlib import Path -from types import TracebackType -from typing import TYPE_CHECKING, Any, BinaryIO - -from .models import ArtifactPolicy - -if TYPE_CHECKING: - from .service import ReportPaths - -ATTEMPT_SCHEMA = "pyamplicol-performance-attempt-v1" -CURRENT_SCHEMA = "pyamplicol-performance-current-v1" -PORTABLE_CURRENT_SCHEMA = "pyamplicol-performance-portable-current-v1" - -_ATTEMPT_KEYS = { - "schema", - "cell_id", - "attempt_id", - "status", - "artifact_policy", - "based_on", - "result_path", - "artifacts", - "error", -} -_CURRENT_KEYS = { - "schema", - "cell_id", - "attempt_id", - "manifest_path", - "manifest_sha256", -} -_FILE_KEYS = {"path", "size", "sha256"} -_BASED_ON_KEYS = {"attempt_id", "manifest_sha256"} -_SHA256_RE = re.compile(r"[0-9a-f]{64}") -_LOCK_STATE = threading.local() - - -class ArtifactStoreError(RuntimeError): - """Base error for the immutable report artifact store.""" - - -class ManifestValidationError(ArtifactStoreError): - """An artifact manifest or current pointer failed validation.""" - - -class LockTimeoutError(ArtifactStoreError): - """A filesystem lock could not be acquired before its deadline.""" - - -class LockCancelledError(ArtifactStoreError): - """A caller cancelled while waiting for a filesystem lock.""" - - -class DiskFullError(ArtifactStoreError): - """A report write failed because its filesystem has no free space.""" - - -class ArtifactAction(StrEnum): - """Concrete action selected from an artifact policy and current state.""" - - REUSE_CURRENT = "reuse-current" - RETIME_CURRENT = "retime-current" - GENERATE = "generate" - - -def _thread_lock_depths() -> dict[Path, int]: - process_id = os.getpid() - if getattr(_LOCK_STATE, "process_id", None) != process_id: - _LOCK_STATE.process_id = process_id - _LOCK_STATE.depths = {} - depths = getattr(_LOCK_STATE, "depths", None) - if depths is None: - depths = {} - _LOCK_STATE.depths = depths - return depths - - -@dataclass(frozen=True, slots=True) -class ArtifactFile: - relative_path: str - path: Path - size: int - sha256: str - - -@dataclass(frozen=True, slots=True) -class CurrentRecord: - cell_id: str - attempt_id: str - manifest_path: Path - manifest_sha256: str - result_path: Path - result: Mapping[str, Any] - artifacts: tuple[ArtifactFile, ...] - artifact_policy: ArtifactPolicy - - -@dataclass(frozen=True, slots=True) -class ArtifactDecision: - requested_policy: ArtifactPolicy - action: ArtifactAction - current: CurrentRecord | None - - @property - def requires_generation(self) -> bool: - return self.action is ArtifactAction.GENERATE - - @property - def requires_timing(self) -> bool: - return self.action is not ArtifactAction.REUSE_CURRENT - - -def _canonical_json_bytes(payload: Mapping[str, Any]) -> bytes: - try: - encoded = json.dumps( - payload, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ) - except (TypeError, ValueError) as error: - raise ArtifactStoreError(f"payload is not canonical JSON: {error}") from error - return f"{encoded}\n".encode() - - -def _fsync_directory(path: Path) -> None: - descriptor = os.open(path, os.O_RDONLY) - try: - os.fsync(descriptor) - finally: - os.close(descriptor) - - -def _raise_disk_full(error: OSError, path: Path) -> None: - if error.errno != errno.ENOSPC: - raise error - probe = path if path.is_dir() else path.parent - while not probe.exists() and probe != probe.parent: - probe = probe.parent - try: - free = shutil.disk_usage(probe).free - detail = f"; {free} bytes available" - except OSError: - detail = "" - raise DiskFullError(f"disk full while writing {path}{detail}") from error - - -def _atomic_write_json(path: Path, payload: Mapping[str, Any]) -> None: - try: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{uuid.uuid4()}") - data = _canonical_json_bytes(payload) - with temporary.open("xb") as stream: - stream.write(data) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - _fsync_directory(path.parent) - except OSError as error: - _raise_disk_full(error, path) - finally: - if "temporary" in locals(): - temporary.unlink(missing_ok=True) - - -def _read_json_object(path: Path, *, description: str) -> dict[str, Any]: - try: - payload = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise ManifestValidationError( - f"could not read {description} {path}: {error}" - ) from error - if not isinstance(payload, dict): - raise ManifestValidationError(f"{description} must be a JSON object: {path}") - return payload - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for chunk in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def _validate_sha256(value: object, *, field: str) -> str: - if not isinstance(value, str) or _SHA256_RE.fullmatch(value) is None: - raise ManifestValidationError(f"{field} must be a lowercase SHA-256 digest") - return value - - -def _validate_uuid(value: object, *, field: str) -> str: - if not isinstance(value, str): - raise ManifestValidationError(f"{field} must be a UUID string") - try: - parsed = uuid.UUID(value) - except ValueError as error: - raise ManifestValidationError(f"{field} must be a UUID string") from error - if str(parsed) != value: - raise ManifestValidationError(f"{field} must use canonical UUID spelling") - return value - - -def _validate_cell_id(cell_id: object) -> str: - if not isinstance(cell_id, str) or not cell_id or "\x00" in cell_id: - raise ManifestValidationError("cell_id must be a non-empty string") - if len(cell_id.encode()) > 4096: - raise ManifestValidationError("cell_id is unreasonably long") - return cell_id - - -def _safe_component(value: str, *, prefix_length: int = 48) -> str: - digest = hashlib.sha256(value.encode()).hexdigest()[:16] - prefix = re.sub(r"[^A-Za-z0-9_.-]+", "-", value).strip(".-") - if not prefix: - prefix = "item" - return f"{prefix[:prefix_length]}-{digest}" - - -def _strict_relative_path(value: object, *, field: str) -> Path: - if not isinstance(value, str) or not value: - raise ManifestValidationError(f"{field} must be a non-empty relative path") - path = Path(value) - if path.is_absolute() or any(part in {"", ".", ".."} for part in path.parts): - raise ManifestValidationError(f"{field} contains an unsafe path: {value!r}") - return path - - -def _resolve_member( - root: Path, - relative: object, - *, - field: str, - require_file: bool = True, -) -> tuple[str, Path]: - relative_path = _strict_relative_path(relative, field=field) - candidate = root.joinpath(relative_path) - if candidate.is_symlink(): - raise ManifestValidationError( - f"{field} is not a regular attempt file: {relative_path}" - ) - try: - resolved = candidate.resolve(strict=require_file) - except OSError as error: - raise ManifestValidationError( - f"{field} does not resolve to a readable file: {relative_path}" - ) from error - try: - resolved.relative_to(root.resolve()) - except ValueError as error: - raise ManifestValidationError( - f"{field} escapes its attempt directory: {relative_path}" - ) from error - if require_file and (not resolved.is_file() or candidate.is_symlink()): - raise ManifestValidationError( - f"{field} is not a regular attempt file: {relative_path}" - ) - return relative_path.as_posix(), resolved - - -@contextmanager -def _filesystem_lock( - path: Path, - *, - timeout: float | None, - poll_interval: float, - cancellation_requested: Callable[[], bool] | None = None, -) -> Iterator[None]: - if timeout is not None and timeout < 0: - raise ValueError("lock timeout must be non-negative or None") - if poll_interval <= 0: - raise ValueError("lock poll interval must be positive") - lock_path = path.expanduser().resolve(strict=False) - depths = _thread_lock_depths() - depth = depths.get(lock_path, 0) - if depth: - depths[lock_path] = depth + 1 - try: - yield - finally: - remaining = depths[lock_path] - 1 - if remaining: - depths[lock_path] = remaining - else: - del depths[lock_path] - return - lock_path.parent.mkdir(parents=True, exist_ok=True) - stream: BinaryIO = lock_path.open("a+b") - deadline = None if timeout is None else time.monotonic() + timeout - try: - while True: - if cancellation_requested is not None and cancellation_requested(): - raise LockCancelledError( - f"cancelled while waiting for filesystem lock {lock_path}" - ) - try: - fcntl.flock(stream.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - break - except OSError as error: - if error.errno not in (errno.EACCES, errno.EAGAIN): - raise - if deadline is not None and time.monotonic() >= deadline: - raise LockTimeoutError( - f"timed out acquiring filesystem lock {lock_path}" - ) from error - remaining = ( - poll_interval - if deadline is None - else min(poll_interval, max(0.0, deadline - time.monotonic())) - ) - time.sleep(remaining) - depths[lock_path] = 1 - yield - finally: - depths.pop(lock_path, None) - try: - fcntl.flock(stream.fileno(), fcntl.LOCK_UN) - finally: - stream.close() - - -class ArtifactStore: - """Store immutable attempts and atomically select one validated current result.""" - - def __init__( - self, - *, - artifact_root: Path, - lock_root: Path, - current_publication_paths: ReportPaths | None = None, - ) -> None: - self.artifact_root = Path(artifact_root).expanduser().resolve(strict=False) - self.lock_root = Path(lock_root).expanduser().resolve(strict=False) - self.current_publication_paths = current_publication_paths - if current_publication_paths is not None and ( - current_publication_paths.artifact_root != self.artifact_root - or current_publication_paths.coordination_root != self.lock_root - ): - raise ValueError( - "portable current roots must match the artifact store roots" - ) - self.cells_root = self.artifact_root / "cells" - self.attempt_history_root = self.artifact_root / "attempt-history" - self.cells_root.mkdir(parents=True, exist_ok=True) - self.lock_root.mkdir(parents=True, exist_ok=True) - - @property - def current_schema(self) -> str: - return ( - CURRENT_SCHEMA - if self.current_publication_paths is None - else PORTABLE_CURRENT_SCHEMA - ) - - def _stored_current_result( - self, - result: Mapping[str, Any], - ) -> Mapping[str, Any]: - if self.current_publication_paths is None: - return result - from .publication import portable_current_value - - portable = portable_current_value(result, self.current_publication_paths) - if not isinstance(portable, Mapping): # pragma: no cover - input is a mapping. - raise ArtifactStoreError("portable current result must remain an object") - return portable - - def materialize_current_result( - self, - result: Mapping[str, Any], - ) -> Mapping[str, Any]: - """Resolve an authenticated stored current against this store's roots.""" - - if self.current_publication_paths is None: - return result - from .publication import PublicationPortabilityError, materialize_current_value - - try: - materialized = materialize_current_value( - result, - self.current_publication_paths, - ) - except PublicationPortabilityError as error: - raise ManifestValidationError( - f"portable current result contains an unsafe locator: {error}" - ) from error - if not isinstance(materialized, Mapping): # pragma: no cover - input is object. - raise ManifestValidationError( - "portable current result did not materialize as an object" - ) - return materialized - - def _cell_root(self, cell_id: str) -> Path: - validated = _validate_cell_id(cell_id) - return self.cells_root / _safe_component(validated) - - def _validate_cells_root(self) -> None: - if self.cells_root.is_symlink() or not self.cells_root.is_dir(): - raise ManifestValidationError( - f"artifact cells root is not a regular directory: {self.cells_root}" - ) - try: - resolved = self.cells_root.resolve(strict=True) - except OSError as error: - raise ManifestValidationError( - f"artifact cells root is unavailable: {self.cells_root}" - ) from error - if resolved != self.cells_root: - raise ManifestValidationError( - f"artifact cells root escapes its canonical path: {self.cells_root}" - ) - - def _validate_cell_root_path( - self, - cell_root: Path, - *, - missing_ok: bool, - ) -> Path | None: - self._validate_cells_root() - if cell_root.parent != self.cells_root: - raise ManifestValidationError( - f"cell root is outside the artifact inventory: {cell_root}" - ) - if cell_root.is_symlink(): - raise ManifestValidationError( - f"cell root is a symbolic link: {cell_root}" - ) - if not cell_root.exists(): - if missing_ok: - return None - raise ManifestValidationError( - f"artifact cell root is absent: {cell_root}" - ) - if not cell_root.is_dir(): - raise ManifestValidationError( - f"cell root is not a regular directory: {cell_root}" - ) - try: - resolved = cell_root.resolve(strict=True) - except OSError as error: - raise ManifestValidationError( - f"cell root is unavailable: {cell_root}" - ) from error - if resolved != cell_root: - raise ManifestValidationError( - f"cell root escapes its canonical path: {cell_root}" - ) - return cell_root - - def _existing_cell_root( - self, - cell_id: str, - *, - missing_ok: bool, - ) -> Path | None: - return self._validate_cell_root_path( - self._cell_root(cell_id), - missing_ok=missing_ok, - ) - - def _cell_lock_path(self, cell_id: str) -> Path: - validated = _validate_cell_id(cell_id) - return self.lock_root / "cells" / f"{_safe_component(validated)}.lock" - - def _attempt_root(self, cell_id: str, attempt_id: str) -> Path: - validated_cell = _validate_cell_id(cell_id) - validated_attempt = _validate_uuid(attempt_id, field="attempt_id") - return self._cell_root(validated_cell) / "attempts" / validated_attempt - - def _attempt_history_cell_root(self, cell_id: str) -> Path: - validated = _validate_cell_id(cell_id) - return self.attempt_history_root / _safe_component(validated) - - @staticmethod - def _validate_direct_inventory_directory( - path: Path, - *, - parent: Path, - description: str, - missing_ok: bool, - ) -> Path | None: - if path.parent != parent: - raise ManifestValidationError( - f"{description} is outside its canonical inventory: {path}" - ) - if path.is_symlink(): - raise ManifestValidationError(f"{description} is a symbolic link: {path}") - if not path.exists(): - if missing_ok: - return None - raise ManifestValidationError(f"{description} is absent: {path}") - if not path.is_dir(): - raise ManifestValidationError( - f"{description} is not a regular directory: {path}" - ) - try: - resolved = path.resolve(strict=True) - except OSError as error: - raise ManifestValidationError( - f"{description} is unavailable: {path}" - ) from error - if resolved != path: - raise ManifestValidationError( - f"{description} escapes its canonical path: {path}" - ) - return path - - def _existing_live_attempt_root( - self, - cell_id: str, - attempt_id: str, - ) -> Path | None: - cell_root = self._existing_cell_root(cell_id, missing_ok=True) - if cell_root is None: - return None - attempts_root = self._validate_direct_inventory_directory( - cell_root / "attempts", - parent=cell_root, - description="attempts root", - missing_ok=True, - ) - if attempts_root is None: - return None - return self._validate_direct_inventory_directory( - attempts_root / _validate_uuid(attempt_id, field="attempt_id"), - parent=attempts_root, - description="attempt root", - missing_ok=True, - ) - - def _existing_archived_attempt_root( - self, - cell_id: str, - attempt_id: str, - ) -> Path | None: - history_root = self._validate_direct_inventory_directory( - self.attempt_history_root, - parent=self.artifact_root, - description="attempt history root", - missing_ok=True, - ) - if history_root is None: - return None - history_cell = self._validate_direct_inventory_directory( - self._attempt_history_cell_root(cell_id), - parent=history_root, - description="attempt history cell root", - missing_ok=True, - ) - if history_cell is None: - return None - return self._validate_direct_inventory_directory( - history_cell / _validate_uuid(attempt_id, field="attempt_id"), - parent=history_cell, - description="archived attempt root", - missing_ok=True, - ) - - @contextmanager - def cell_lock( - self, - cell_id: str, - *, - timeout: float | None = None, - poll_interval: float = 0.05, - cancellation_requested: Callable[[], bool] | None = None, - ) -> Iterator[None]: - with _filesystem_lock( - self._cell_lock_path(cell_id), - timeout=timeout, - poll_interval=poll_interval, - cancellation_requested=cancellation_requested, - ): - yield - - @contextmanager - def named_lock( - self, - name: str, - *, - timeout: float | None = None, - poll_interval: float = 0.05, - cancellation_requested: Callable[[], bool] | None = None, - ) -> Iterator[None]: - validated = _validate_cell_id(name) - path = self.lock_root / "named" / f"{_safe_component(validated)}.lock" - with _filesystem_lock( - path, - timeout=timeout, - poll_interval=poll_interval, - cancellation_requested=cancellation_requested, - ): - yield - - def decide( - self, - cell_id: str, - policy: ArtifactPolicy, - ) -> ArtifactDecision: - current = self.load_current(cell_id, missing_ok=True) - if policy is ArtifactPolicy.REUSE and current is not None: - action = ArtifactAction.REUSE_CURRENT - elif policy is ArtifactPolicy.RETIME and current is not None: - action = ArtifactAction.RETIME_CURRENT - else: - action = ArtifactAction.GENERATE - return ArtifactDecision(policy, action, current) - - def new_attempt( - self, - cell_id: str, - policy: ArtifactPolicy, - *, - based_on: CurrentRecord | None = None, - ) -> ArtifactAttempt: - validated = _validate_cell_id(cell_id) - if based_on is not None and based_on.cell_id != validated: - raise ArtifactStoreError("based-on record belongs to a different cell") - attempt_id = str(uuid.uuid4()) - self._validate_cells_root() - cell_root = self._cell_root(validated) - if cell_root.exists() or cell_root.is_symlink(): - self._validate_cell_root_path(cell_root, missing_ok=False) - root = cell_root / "attempts" / attempt_id - try: - root.mkdir(parents=True, exist_ok=False) - _fsync_directory(root.parent) - except OSError as error: - _raise_disk_full(error, root) - return ArtifactAttempt( - store=self, - cell_id=validated, - attempt_id=attempt_id, - root=root, - artifact_policy=policy, - based_on=based_on, - ) - - def seal_existing_worker_result( - self, - cell_id: str, - attempt_id: str, - *, - worker_result_sha256: str, - artifact_policy: ArtifactPolicy, - validate_result: Callable[[Mapping[str, Any], Path], None], - ) -> CurrentRecord: - """Seal one controller-orphaned worker result without rerunning it.""" - - validated_cell = _validate_cell_id(cell_id) - validated_attempt = _validate_uuid(attempt_id, field="attempt_id") - expected_worker_digest = _validate_sha256( - worker_result_sha256, - field="worker_result_sha256", - ) - cell_root = self._existing_cell_root(validated_cell, missing_ok=False) - assert cell_root is not None - attempt_root = cell_root / "attempts" / validated_attempt - with self.cell_lock(validated_cell): - pointer_path = cell_root / "current.json" - if pointer_path.exists() or pointer_path.is_symlink(): - raise ArtifactStoreError( - "orphan sealing cannot replace an existing current" - ) - if ( - attempt_root.is_symlink() - or not attempt_root.is_dir() - or attempt_root.parent.is_symlink() - ): - raise ArtifactStoreError( - "orphan attempt is not its canonical regular directory" - ) - for reserved in ("result.json", "manifest.json"): - path = attempt_root / reserved - if path.exists() or path.is_symlink(): - raise ArtifactStoreError( - f"orphan attempt already contains {reserved}" - ) - _, worker_result = _resolve_member( - attempt_root, - "worker-result.json", - field="worker-result.json", - ) - if _sha256(worker_result) != expected_worker_digest: - raise ArtifactStoreError("worker-result.json digest mismatch") - result = _read_json_object( - worker_result, - description="orphan worker result", - ) - validate_result(result, attempt_root) - artifact_paths: list[str] = [] - for path in sorted(attempt_root.rglob("*")): - if path.is_symlink(): - raise ArtifactStoreError( - f"orphan attempt contains a symbolic link: {path}" - ) - if path.is_file(): - artifact_paths.append(path.relative_to(attempt_root).as_posix()) - elif not path.is_dir(): - raise ArtifactStoreError( - f"orphan attempt contains a special file: {path}" - ) - if "worker-result.json" not in artifact_paths: - raise ArtifactStoreError("orphan attempt lacks worker-result.json") - attempt = ArtifactAttempt( - store=self, - cell_id=validated_cell, - attempt_id=validated_attempt, - root=attempt_root, - artifact_policy=artifact_policy, - based_on=None, - ) - record = attempt.publish( - result, - artifact_paths=artifact_paths, - ) - if _sha256(worker_result) != expected_worker_digest: - raise ArtifactStoreError( - "worker-result.json changed during orphan sealing" - ) - return record - - def load_current( - self, - cell_id: str, - *, - missing_ok: bool = False, - ) -> CurrentRecord | None: - validated = _validate_cell_id(cell_id) - cell_root = self._existing_cell_root(validated, missing_ok=True) - if cell_root is None: - if missing_ok: - return None - raise FileNotFoundError(f"no artifact cell for {validated!r}") - pointer_path = cell_root / "current.json" - if pointer_path.is_symlink(): - raise ManifestValidationError( - f"current pointer is a symbolic link: {pointer_path}" - ) - if not pointer_path.exists(): - if missing_ok: - return None - raise FileNotFoundError(f"no current artifact for cell {validated!r}") - if not pointer_path.is_file(): - raise ManifestValidationError( - f"current pointer is not a regular file: {pointer_path}" - ) - return self._validate_current_pointer( - pointer_path, - expected_cell_id=validated, - expected_cell_root=cell_root, - ) - - def recover_current_records(self) -> tuple[CurrentRecord, ...]: - records: list[CurrentRecord] = [] - self._validate_cells_root() - for pointer_path in sorted(self.cells_root.glob("*/current.json")): - self._validate_cell_root_path(pointer_path.parent, missing_ok=False) - records.append( - self._validate_current_pointer( - pointer_path, - expected_cell_id=None, - expected_cell_root=pointer_path.parent, - ) - ) - return tuple(records) - - def cell_attempt_ids(self, cell_id: str) -> tuple[str, ...]: - """Return the canonical immutable-attempt inventory for one cell.""" - - cell_root = self._existing_cell_root(cell_id, missing_ok=True) - if cell_root is None: - return () - attempts_root = cell_root / "attempts" - if not attempts_root.exists(): - return () - if attempts_root.is_symlink() or not attempts_root.is_dir(): - raise ManifestValidationError( - f"attempt inventory is not a regular directory: {attempts_root}" - ) - attempt_ids: list[str] = [] - for path in sorted(attempts_root.iterdir()): - if path.is_symlink() or not path.is_dir(): - raise ManifestValidationError( - f"attempt inventory contains a non-directory: {path}" - ) - attempt_ids.append( - _validate_uuid(path.name, field="attempt inventory member") - ) - return tuple(attempt_ids) - - def load_sealed_unsuccessful_worker_result( - self, - cell_id: str, - attempt_id: str, - ) -> Mapping[str, Any]: - """Load one explicitly named failed result through its sealed manifest. - - This is deliberately not a history search. Presentation metadata - names the exact attempt UUID, and this method authenticates only that - attempt's compact ``worker-result.json``. It supports the canonical - live and archived locations used by bounded artifact cleanup. - """ - - validated_cell = _validate_cell_id(cell_id) - validated_attempt = _validate_uuid(attempt_id, field="attempt_id") - live_root = self._existing_live_attempt_root( - validated_cell, - validated_attempt, - ) - archived_root = self._existing_archived_attempt_root( - validated_cell, - validated_attempt, - ) - roots = tuple( - root - for root in (live_root, archived_root) - if root is not None - ) - if len(roots) != 1: - raise ManifestValidationError( - "named unsuccessful attempt is absent or has colliding locations" - ) - root = roots[0] - archived = root == archived_root - if root.is_symlink() or not root.is_dir(): - raise ManifestValidationError( - f"named unsuccessful attempt is not a regular directory: {root}" - ) - manifest_path = root / "manifest.json" - if manifest_path.is_symlink() or not manifest_path.is_file(): - raise ManifestValidationError( - f"named unsuccessful attempt has no regular manifest: {root}" - ) - manifest = _read_json_object( - manifest_path, - description="unsuccessful attempt manifest", - ) - if ( - set(manifest) != _ATTEMPT_KEYS - or manifest.get("schema") != ATTEMPT_SCHEMA - or manifest.get("cell_id") != validated_cell - or manifest.get("attempt_id") != validated_attempt - or manifest.get("status") not in {"failed", "interrupted"} - or manifest.get("result_path") is not None - or not isinstance(manifest.get("error"), str) - or not manifest.get("error") - ): - raise ManifestValidationError( - "named unsuccessful attempt manifest is invalid" - ) - try: - ArtifactPolicy(manifest.get("artifact_policy")) - except (TypeError, ValueError) as error: - raise ManifestValidationError( - "unsuccessful attempt artifact policy is invalid" - ) from error - self._validate_based_on(manifest.get("based_on")) - raw_artifacts = manifest.get("artifacts") - if not isinstance(raw_artifacts, list): - raise ManifestValidationError( - "unsuccessful attempt artifacts must be an array" - ) - artifacts: list[ArtifactFile] = [] - for index, raw in enumerate(raw_artifacts): - if not isinstance(raw, dict) or set(raw) != _FILE_KEYS: - raise ManifestValidationError( - f"artifact record {index} has an unsupported schema shape" - ) - relative = _strict_relative_path( - raw.get("path"), - field=f"artifacts[{index}].path", - ) - self._validate_unsuccessful_artifact_ancestors(root, relative) - candidate = root.joinpath(relative) - if archived and not candidate.exists() and not candidate.is_symlink(): - if not relative.parts or relative.parts[0] != "artifact": - raise ManifestValidationError( - "archived compact diagnostic artifact is missing: " - f"{relative.as_posix()}" - ) - self._validate_missing_archived_artifact_record( - raw, - index=index, - ) - continue - artifacts.append(self._validate_artifact_file(root, raw, index=index)) - paths = [ - _strict_relative_path(raw.get("path"), field="artifact path").as_posix() - for raw in raw_artifacts - if isinstance(raw, Mapping) - ] - if len(paths) != len(set(paths)): - raise ManifestValidationError( - "unsuccessful attempt manifest has duplicate artifacts" - ) - matches = tuple( - artifact - for artifact in artifacts - if artifact.relative_path == "worker-result.json" - ) - if len(matches) != 1: - raise ManifestValidationError( - "unsuccessful attempt does not authenticate worker-result.json" - ) - return self.materialize_current_result( - _read_json_object( - matches[0].path, - description="unsuccessful worker result", - ) - ) - - @staticmethod - def _validate_unsuccessful_artifact_ancestors( - attempt_root: Path, - relative: Path, - ) -> None: - cursor = attempt_root - for offset, part in enumerate(relative.parts): - cursor = cursor / part - if cursor.is_symlink(): - raise ManifestValidationError( - "unsuccessful artifact traverses a symbolic link: " - f"{relative.as_posix()}" - ) - if ( - offset < len(relative.parts) - 1 - and cursor.exists() - and not cursor.is_dir() - ): - raise ManifestValidationError( - "unsuccessful artifact traverses a non-directory: " - f"{relative.as_posix()}" - ) - - @staticmethod - def _validate_missing_archived_artifact_record( - raw_record: Mapping[str, object], - *, - index: int, - ) -> None: - size = raw_record.get("size") - if isinstance(size, bool) or not isinstance(size, int) or size < 0: - raise ManifestValidationError( - f"artifacts[{index}].size must be a non-negative integer" - ) - _validate_sha256( - raw_record.get("sha256"), - field=f"artifacts[{index}].sha256", - ) - - def lightweight_current_payload( - self, - cell_id: str, - *, - missing_ok: bool = False, - ) -> tuple[str, Mapping[str, Any]] | None: - """Read authenticated pointer/manifest/result metadata without big files. - - This deliberately authenticates the small manifest and result records - only. It is used solely to protect live artifact owners during history - pruning; ordinary current loading retains full artifact validation. - """ - - validated = _validate_cell_id(cell_id) - cell_root = self._existing_cell_root(validated, missing_ok=True) - if cell_root is None: - if missing_ok: - return None - raise FileNotFoundError(f"no artifact cell for {validated!r}") - pointer_path = cell_root / "current.json" - if pointer_path.is_symlink(): - raise ManifestValidationError( - f"current pointer is a symbolic link: {pointer_path}" - ) - if not pointer_path.exists(): - if missing_ok: - return None - raise FileNotFoundError(f"no current artifact for cell {validated!r}") - if not pointer_path.is_file(): - raise ManifestValidationError( - f"current pointer is not a regular file: {pointer_path}" - ) - pointer = _read_json_object(pointer_path, description="current pointer") - if ( - set(pointer) != _CURRENT_KEYS - or pointer.get("schema") != self.current_schema - ): - raise ManifestValidationError("current pointer has an unsupported shape") - if pointer.get("cell_id") != validated: - raise ManifestValidationError("current pointer cell_id does not match") - attempt_id = _validate_uuid(pointer.get("attempt_id"), field="attempt_id") - expected_manifest = f"attempts/{attempt_id}/manifest.json" - if pointer.get("manifest_path") != expected_manifest: - raise ManifestValidationError( - "current pointer manifest_path is not its canonical attempt manifest" - ) - _, manifest_path = _resolve_member( - cell_root, - expected_manifest, - field="manifest_path", - ) - expected_digest = _validate_sha256( - pointer.get("manifest_sha256"), field="manifest_sha256" - ) - if _sha256(manifest_path) != expected_digest: - raise ManifestValidationError("current manifest digest mismatch") - manifest = _read_json_object(manifest_path, description="attempt manifest") - if ( - set(manifest) != _ATTEMPT_KEYS - or manifest.get("schema") != ATTEMPT_SCHEMA - or manifest.get("cell_id") != validated - or manifest.get("attempt_id") != attempt_id - or manifest.get("status") != "ok" - or manifest.get("error") is not None - ): - raise ManifestValidationError("current attempt manifest is invalid") - try: - ArtifactPolicy(manifest.get("artifact_policy")) - except (TypeError, ValueError) as error: - raise ManifestValidationError( - "current manifest artifact policy is invalid" - ) from error - self._validate_based_on(manifest.get("based_on")) - result_relative = _strict_relative_path( - manifest.get("result_path"), field="result_path" - ).as_posix() - raw_artifacts = manifest.get("artifacts") - if not isinstance(raw_artifacts, list): - raise ManifestValidationError("current manifest artifacts are invalid") - artifact_paths: list[str] = [] - for index, record in enumerate(raw_artifacts): - if not isinstance(record, dict) or set(record) != _FILE_KEYS: - raise ManifestValidationError( - f"current artifact record {index} is invalid" - ) - relative = _strict_relative_path( - record.get("path"), field=f"artifacts[{index}].path" - ).as_posix() - _validate_sha256(record.get("sha256"), field=f"artifacts[{index}].sha256") - size = record.get("size") - if not isinstance(size, int) or isinstance(size, bool) or size < 0: - raise ManifestValidationError( - f"artifacts[{index}].size must be a non-negative integer" - ) - artifact_paths.append(relative) - if len(set(artifact_paths)) != len(artifact_paths): - raise ManifestValidationError("current manifest has duplicate artifacts") - result_record = next( - ( - record - for record in raw_artifacts - if isinstance(record, dict) and record.get("path") == result_relative - ), - None, - ) - if result_record is None: - raise ManifestValidationError("current result is absent from manifest") - result_file = self._validate_artifact_file( - manifest_path.parent, - result_record, - index=raw_artifacts.index(result_record), - ) - result = self.materialize_current_result( - _read_json_object(result_file.path, description="attempt result") - ) - return attempt_id, result - - def protected_attempt_ids( - self, - cell_id: str, - *, - consumer_cell_ids: Iterable[str], - ) -> frozenset[str]: - """Return target attempts retained by live current/equivalent consumers.""" - - validated = _validate_cell_id(cell_id) - attempt_ids = self.cell_attempt_ids(validated) - candidate_artifacts = { - self._attempt_root(validated, attempt_id) - .joinpath("artifact") - .resolve(strict=False): attempt_id - for attempt_id in attempt_ids - } - protected: set[str] = set() - own = self.lightweight_current_payload(validated, missing_ok=True) - if own is not None: - protected.add(own[0]) - consumers = {_validate_cell_id(value) for value in consumer_cell_ids} - for consumer_id in sorted(consumers): - current = self.lightweight_current_payload(consumer_id, missing_ok=True) - if current is None: - continue - artifact = current[1].get("artifact") - raw_path = artifact.get("path") if isinstance(artifact, Mapping) else None - if not isinstance(raw_path, str) or not raw_path: - continue - if not Path(raw_path).is_absolute(): - raise ManifestValidationError( - f"current artifact path is not absolute: {raw_path!r}" - ) - referenced_artifact = Path(raw_path) - if referenced_artifact.is_symlink() or not referenced_artifact.is_dir(): - raise ManifestValidationError( - f"current artifact path is unavailable or unsafe: {raw_path!r}" - ) - owner = candidate_artifacts.get( - referenced_artifact.expanduser().resolve(strict=False) - ) - if owner is not None: - protected.add(owner) - return frozenset(protected) - - def archive_obsolete_attempts( - self, - cell_id: str, - *, - consumer_cell_ids: Iterable[str], - ) -> tuple[str, ...]: - """Archive sealed noncurrent attempts and remove only heavy payloads. - - The caller must already hold the campaign-cell lock. Per-attempt use - locks are acquired non-blockingly so a concurrent equivalent reuse is - never disturbed. - """ - - validated = _validate_cell_id(cell_id) - if self.attempt_history_root.exists() and ( - self.attempt_history_root.is_symlink() - or not self.attempt_history_root.is_dir() - ): - raise ArtifactStoreError( - "attempt history root is not a regular directory: " - f"{self.attempt_history_root}" - ) - history_cell = self._attempt_history_cell_root(validated) - try: - self._prune_archived_payloads(history_cell) - except OSError as error: - _raise_disk_full(error, history_cell) - archived: list[str] = [] - for attempt_id in self.cell_attempt_ids(validated): - try: - with self.named_lock( - f"campaign-artifact-use-{attempt_id}", timeout=0.0 - ): - protected = self.protected_attempt_ids( - validated, - consumer_cell_ids=consumer_cell_ids, - ) - if attempt_id in protected: - continue - source = self._attempt_root(validated, attempt_id) - manifest = source / "manifest.json" - if ( - source.is_symlink() - or not source.is_dir() - or manifest.is_symlink() - or not manifest.is_file() - ): - continue - raw = _read_json_object(manifest, description="attempt manifest") - if ( - set(raw) != _ATTEMPT_KEYS - or raw.get("schema") != ATTEMPT_SCHEMA - or raw.get("cell_id") != validated - or raw.get("attempt_id") != attempt_id - or raw.get("status") not in {"ok", "failed", "interrupted"} - ): - raise ManifestValidationError( - f"sealed attempt metadata is invalid: {source}" - ) - if history_cell.exists() and ( - history_cell.is_symlink() or not history_cell.is_dir() - ): - raise ArtifactStoreError( - "attempt history is not a regular directory: " - f"{history_cell}" - ) - history_cell.mkdir(parents=True, exist_ok=True) - destination = history_cell / attempt_id - if destination.exists() or destination.is_symlink(): - raise ArtifactStoreError( - f"attempt history collision: {destination}" - ) - self._validate_attempt_tree(source) - os.replace(source, destination) - _fsync_directory(source.parent) - _fsync_directory(history_cell) - self._remove_archived_artifact(destination) - archived.append(attempt_id) - except LockTimeoutError: - continue - except OSError as error: - _raise_disk_full(error, history_cell) - return tuple(archived) - - def _prune_archived_payloads(self, history_cell: Path) -> None: - if not history_cell.exists(): - return - if history_cell.is_symlink() or not history_cell.is_dir(): - raise ArtifactStoreError( - f"attempt history is not a regular directory: {history_cell}" - ) - for archived in sorted(history_cell.iterdir()): - if archived.is_symlink() or not archived.is_dir(): - raise ArtifactStoreError( - f"attempt history contains a non-directory: {archived}" - ) - _validate_uuid(archived.name, field="attempt history member") - self._remove_archived_artifact(archived) - - @staticmethod - def _validate_attempt_tree(attempt: Path) -> None: - for root, directories, files in os.walk(attempt, topdown=True): - root_path = Path(root) - for name in (*directories, *files): - member = root_path / name - if member.is_symlink() or ( - not member.is_dir() and not member.is_file() - ): - raise ArtifactStoreError( - f"attempt contains an unsafe member: {member}" - ) - - @staticmethod - def _validate_archived_artifact(archived_attempt: Path) -> None: - artifact = archived_attempt / "artifact" - if not artifact.exists() and not artifact.is_symlink(): - return - if artifact.is_symlink() or not artifact.is_dir(): - raise ArtifactStoreError( - f"archived artifact payload is not a regular directory: {artifact}" - ) - for root, directories, files in os.walk(artifact, topdown=True): - root_path = Path(root) - for name in (*directories, *files): - member = root_path / name - if member.is_symlink() or ( - not member.is_dir() and not member.is_file() - ): - raise ArtifactStoreError( - f"archived artifact payload contains an unsafe member: {member}" - ) - - @classmethod - def _remove_archived_artifact(cls, archived_attempt: Path) -> None: - artifact = archived_attempt / "artifact" - cls._validate_archived_artifact(archived_attempt) - if not artifact.exists(): - return - shutil.rmtree(artifact) - _fsync_directory(archived_attempt) - - def _validate_current_pointer( - self, - pointer_path: Path, - *, - expected_cell_id: str | None, - expected_cell_root: Path, - ) -> CurrentRecord: - self._validate_cell_root_path(expected_cell_root, missing_ok=False) - if ( - pointer_path.parent != expected_cell_root - or pointer_path.name != "current.json" - or pointer_path.is_symlink() - or not pointer_path.is_file() - ): - raise ManifestValidationError( - f"current pointer is not its canonical regular file: {pointer_path}" - ) - pointer = _read_json_object(pointer_path, description="current pointer") - if set(pointer) != _CURRENT_KEYS: - raise ManifestValidationError( - f"current pointer has an unsupported schema shape: {pointer_path}" - ) - if pointer["schema"] != self.current_schema: - raise ManifestValidationError( - f"unsupported current pointer schema: {pointer['schema']!r}" - ) - cell_id = _validate_cell_id(pointer["cell_id"]) - if expected_cell_id is not None and cell_id != expected_cell_id: - raise ManifestValidationError("current pointer cell_id does not match") - if expected_cell_root != self._cell_root(cell_id): - raise ManifestValidationError( - "current pointer is stored under the wrong cell directory" - ) - attempt_id = _validate_uuid(pointer["attempt_id"], field="attempt_id") - expected_manifest = f"attempts/{attempt_id}/manifest.json" - if pointer["manifest_path"] != expected_manifest: - raise ManifestValidationError( - "current pointer manifest_path is not its canonical attempt manifest" - ) - _, manifest_path = _resolve_member( - expected_cell_root, - pointer["manifest_path"], - field="manifest_path", - ) - expected_digest = _validate_sha256( - pointer["manifest_sha256"], - field="manifest_sha256", - ) - actual_digest = _sha256(manifest_path) - if actual_digest != expected_digest: - raise ManifestValidationError("current manifest digest mismatch") - return self._validate_attempt_manifest( - manifest_path, - expected_cell_id=cell_id, - expected_attempt_id=attempt_id, - expected_digest=expected_digest, - ) - - def _validate_attempt_manifest( - self, - manifest_path: Path, - *, - expected_cell_id: str, - expected_attempt_id: str, - expected_digest: str, - ) -> CurrentRecord: - manifest = _read_json_object(manifest_path, description="attempt manifest") - if set(manifest) != _ATTEMPT_KEYS: - raise ManifestValidationError( - f"attempt manifest has an unsupported schema shape: {manifest_path}" - ) - if manifest["schema"] != ATTEMPT_SCHEMA: - raise ManifestValidationError( - f"unsupported attempt manifest schema: {manifest['schema']!r}" - ) - if _validate_cell_id(manifest["cell_id"]) != expected_cell_id: - raise ManifestValidationError("attempt manifest cell_id does not match") - if ( - _validate_uuid(manifest["attempt_id"], field="attempt_id") - != expected_attempt_id - ): - raise ManifestValidationError("attempt manifest attempt_id does not match") - if manifest["status"] != "ok": - raise ManifestValidationError( - "current pointer targets a non-success attempt" - ) - if manifest["error"] is not None: - raise ManifestValidationError("successful attempt contains an error") - try: - policy = ArtifactPolicy(manifest["artifact_policy"]) - except (TypeError, ValueError) as error: - raise ManifestValidationError( - "attempt manifest has an unsupported artifact policy" - ) from error - self._validate_based_on(manifest["based_on"]) - result_relative = _strict_relative_path( - manifest["result_path"], - field="result_path", - ).as_posix() - raw_artifacts = manifest["artifacts"] - if not isinstance(raw_artifacts, list) or not raw_artifacts: - raise ManifestValidationError( - "successful attempt must contain artifact records" - ) - attempt_root = manifest_path.parent - artifacts: list[ArtifactFile] = [] - seen: set[str] = set() - for index, raw_record in enumerate(raw_artifacts): - artifacts.append( - self._validate_artifact_file( - attempt_root, - raw_record, - index=index, - ) - ) - relative = artifacts[-1].relative_path - if relative in seen: - raise ManifestValidationError( - f"duplicate artifact path in attempt manifest: {relative}" - ) - seen.add(relative) - if result_relative not in seen: - raise ManifestValidationError( - "result_path is not authenticated as an artifact" - ) - result_file = next( - artifact - for artifact in artifacts - if artifact.relative_path == result_relative - ) - result = self.materialize_current_result( - _read_json_object(result_file.path, description="attempt result") - ) - return CurrentRecord( - cell_id=expected_cell_id, - attempt_id=expected_attempt_id, - manifest_path=manifest_path, - manifest_sha256=expected_digest, - result_path=result_file.path, - result=result, - artifacts=tuple(artifacts), - artifact_policy=policy, - ) - - @staticmethod - def _validate_based_on(raw: object) -> None: - if raw is None: - return - if not isinstance(raw, dict) or set(raw) != _BASED_ON_KEYS: - raise ManifestValidationError("based_on has an unsupported schema shape") - _validate_uuid(raw["attempt_id"], field="based_on.attempt_id") - _validate_sha256( - raw["manifest_sha256"], - field="based_on.manifest_sha256", - ) - - @staticmethod - def _validate_artifact_file( - attempt_root: Path, - raw_record: object, - *, - index: int, - ) -> ArtifactFile: - if not isinstance(raw_record, dict) or set(raw_record) != _FILE_KEYS: - raise ManifestValidationError( - f"artifact record {index} has an unsupported schema shape" - ) - relative, path = _resolve_member( - attempt_root, - raw_record["path"], - field=f"artifacts[{index}].path", - ) - size = raw_record["size"] - if not isinstance(size, int) or isinstance(size, bool) or size < 0: - raise ManifestValidationError( - f"artifacts[{index}].size must be a non-negative integer" - ) - if path.stat().st_size != size: - raise ManifestValidationError(f"artifact size mismatch: {relative}") - expected_digest = _validate_sha256( - raw_record["sha256"], - field=f"artifacts[{index}].sha256", - ) - if _sha256(path) != expected_digest: - raise ManifestValidationError(f"artifact digest mismatch: {relative}") - return ArtifactFile(relative, path, size, expected_digest) - - def _publish(self, attempt: ArtifactAttempt) -> CurrentRecord: - manifest_path = attempt.root / "manifest.json" - digest = _sha256(manifest_path) - pointer = { - "schema": self.current_schema, - "cell_id": attempt.cell_id, - "attempt_id": attempt.attempt_id, - "manifest_path": f"attempts/{attempt.attempt_id}/manifest.json", - "manifest_sha256": digest, - } - with self.cell_lock(attempt.cell_id): - self._validate_attempt_manifest( - manifest_path, - expected_cell_id=attempt.cell_id, - expected_attempt_id=attempt.attempt_id, - expected_digest=digest, - ) - pointer_path = self._cell_root(attempt.cell_id) / "current.json" - _atomic_write_json(pointer_path, pointer) - return self._validate_current_pointer( - pointer_path, - expected_cell_id=attempt.cell_id, - expected_cell_root=pointer_path.parent, - ) - - -class ArtifactAttempt: - """One immutable UUID-qualified attempt for a report cell.""" - - def __init__( - self, - *, - store: ArtifactStore, - cell_id: str, - attempt_id: str, - root: Path, - artifact_policy: ArtifactPolicy, - based_on: CurrentRecord | None, - ) -> None: - self.store = store - self.cell_id = cell_id - self.attempt_id = attempt_id - self.root = root - self.artifact_policy = artifact_policy - self.based_on = based_on - self._sealed = False - - def __enter__(self) -> ArtifactAttempt: - return self - - def __exit__( - self, - exception_type: type[BaseException] | None, - exception: BaseException | None, - traceback: TracebackType | None, - ) -> bool: - del traceback - if not self._sealed: - if exception_type is None: - self.mark_interrupted("attempt exited without publication") - else: - self.mark_interrupted(f"{exception_type.__name__}: {exception}") - return False - - def path(self, relative_path: str) -> Path: - if self._sealed: - raise ArtifactStoreError("attempt is already sealed") - _, path = _resolve_member( - self.root, - relative_path, - field="attempt output path", - require_file=False, - ) - try: - path.parent.mkdir(parents=True, exist_ok=True) - except OSError as error: - _raise_disk_full(error, path) - return path - - def write_json( - self, - relative_path: str, - payload: Mapping[str, Any], - ) -> Path: - path = self.path(relative_path) - _atomic_write_json(path, payload) - return path - - def publish( - self, - result: Mapping[str, Any], - *, - artifact_paths: Iterable[str] = (), - ) -> CurrentRecord: - self._require_open() - self.write_json("result.json", self.store._stored_current_result(result)) - relative_paths = {"result.json", *artifact_paths} - records = [self._file_record(relative) for relative in sorted(relative_paths)] - manifest = self._manifest( - status="ok", - result_path="result.json", - artifacts=records, - error=None, - ) - _atomic_write_json(self.root / "manifest.json", manifest) - self._sealed = True - return self.store._publish(self) - - def mark_failed( - self, - error: str, - *, - artifact_paths: Iterable[str] = (), - ) -> None: - self._seal_unsuccessful( - "failed", - error, - artifact_paths=artifact_paths, - ) - - def mark_interrupted( - self, - error: str, - *, - artifact_paths: Iterable[str] = (), - ) -> None: - self._seal_unsuccessful( - "interrupted", - error, - artifact_paths=artifact_paths, - ) - - def discard(self) -> None: - """Remove an unpublished attempt instead of retaining partial history.""" - - self._require_open() - if self.root.is_symlink() or not self.root.is_dir(): - raise ArtifactStoreError( - f"attempt is not its canonical regular directory: {self.root}" - ) - shutil.rmtree(self.root) - self._sealed = True - - def _seal_unsuccessful( - self, - status: str, - error: str, - *, - artifact_paths: Iterable[str] = (), - ) -> None: - self._require_open() - if not isinstance(error, str) or not error: - raise ArtifactStoreError("failed attempt error must be a non-empty string") - manifest = self._manifest( - status=status, - result_path=None, - artifacts=[ - self._file_record(relative) for relative in sorted(set(artifact_paths)) - ], - error=error, - ) - _atomic_write_json(self.root / "manifest.json", manifest) - self._sealed = True - - def _file_record(self, relative_path: str) -> dict[str, Any]: - relative, path = _resolve_member( - self.root, - relative_path, - field="artifact path", - ) - if path.name == "manifest.json": - raise ArtifactStoreError("manifest.json cannot authenticate itself") - return { - "path": relative, - "size": path.stat().st_size, - "sha256": _sha256(path), - } - - def _manifest( - self, - *, - status: str, - result_path: str | None, - artifacts: list[dict[str, Any]], - error: str | None, - ) -> dict[str, Any]: - based_on = None - if self.based_on is not None: - based_on = { - "attempt_id": self.based_on.attempt_id, - "manifest_sha256": self.based_on.manifest_sha256, - } - return { - "schema": ATTEMPT_SCHEMA, - "cell_id": self.cell_id, - "attempt_id": self.attempt_id, - "status": status, - "artifact_policy": self.artifact_policy.value, - "based_on": based_on, - "result_path": result_path, - "artifacts": artifacts, - "error": error, - } - - def _require_open(self) -> None: - if self._sealed: - raise ArtifactStoreError("attempt is already sealed") - - -__all__ = [ - "ATTEMPT_SCHEMA", - "CURRENT_SCHEMA", - "PORTABLE_CURRENT_SCHEMA", - "ArtifactAction", - "ArtifactAttempt", - "ArtifactDecision", - "ArtifactFile", - "ArtifactStore", - "ArtifactStoreError", - "CurrentRecord", - "DiskFullError", - "LockCancelledError", - "LockTimeoutError", - "ManifestValidationError", -] diff --git a/pyamplicol/tools/performance_report/boundary.py b/pyamplicol/tools/performance_report/boundary.py deleted file mode 100644 index c69df0bd56..0000000000 --- a/pyamplicol/tools/performance_report/boundary.py +++ /dev/null @@ -1,169 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Authoritative per-cell boundaries for asynchronous report publication.""" - -from __future__ import annotations - -import json -import re -from collections.abc import Callable, Mapping -from pathlib import Path -from typing import Any - -from .artifacts import ArtifactStore, ArtifactStoreError, CurrentRecord - -CELL_BOUNDARY_SCHEMA = "pyamplicol-performance-cell-boundary-v1" -_SHA256_RE = re.compile(r"[0-9a-f]{64}") - - -class CellBoundaryError(ArtifactStoreError): - """A fast-controller cell boundary was not authoritative.""" - - -def _artifact_digest(record: CurrentRecord, relative_path: str) -> str: - matches = [ - artifact.sha256 - for artifact in record.artifacts - if artifact.relative_path == relative_path - ] - if len(matches) != 1: - raise CellBoundaryError( - f"current attempt does not authenticate exactly one {relative_path}" - ) - return matches[0] - - -def _current_identity(record: CurrentRecord) -> dict[str, object]: - return { - "attempt_id": record.attempt_id, - "manifest_path": str(record.manifest_path), - "manifest_sha256": record.manifest_sha256, - "result_path": str(record.result_path), - "result_sha256": next( - artifact.sha256 - for artifact in record.artifacts - if artifact.path == record.result_path - ), - "status": record.result.get("status"), - "worker_result_sha256": _artifact_digest( - record, - "worker-result.json", - ), - } - - -def snapshot_cell_boundary( - store: ArtifactStore, - cell_id: str, -) -> dict[str, object]: - """Snapshot one locked attempt inventory and authenticated current.""" - - with store.cell_lock(cell_id): - return _snapshot_cell_boundary_unlocked(store, cell_id) - - -def _snapshot_cell_boundary_unlocked( - store: ArtifactStore, - cell_id: str, -) -> dict[str, object]: - attempt_ids = store.cell_attempt_ids(cell_id) - current = store.load_current(cell_id, missing_ok=True) - return { - "schema": CELL_BOUNDARY_SCHEMA, - "cell_id": cell_id, - "attempt_ids": list(attempt_ids), - "current": None if current is None else _current_identity(current), - } - - -def load_cell_boundary(path: Path) -> Mapping[str, Any]: - """Load a new snapshot or the legacy fast-wrapper snapshot shape.""" - - try: - payload = json.loads(path.read_text(encoding="ascii")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise CellBoundaryError( - f"cannot read pre-populate cell boundary {path}: {error}" - ) from error - if not isinstance(payload, dict): - raise CellBoundaryError("pre-populate cell boundary must be an object") - return payload - - -def authenticate_current_delta( - store: ArtifactStore, - *, - cell_id: str, - expected_attempt_id: str, - before: Mapping[str, Any], - validate_result: Callable[[Mapping[str, Any]], None] | None = None, -) -> dict[str, object]: - """Require exactly one new immutable attempt and its successful current.""" - - before_schema = before.get("schema") - if before_schema not in {None, CELL_BOUNDARY_SCHEMA}: - raise CellBoundaryError("pre-populate cell boundary schema differs") - before_cell = before.get("cell_id") - if before_cell not in {None, cell_id}: - raise CellBoundaryError("pre-populate cell boundary cell_id differs") - before_attempts = before.get("attempt_ids") - if ( - not isinstance(before_attempts, list) - or not all(isinstance(value, str) for value in before_attempts) - or len(set(before_attempts)) != len(before_attempts) - ): - raise CellBoundaryError( - "pre-populate cell boundary has an invalid attempt inventory" - ) - if before.get("current") is not None: - raise CellBoundaryError( - "accepted missing cell had a current before populate" - ) - - with store.cell_lock(cell_id): - after = _snapshot_cell_boundary_unlocked(store, cell_id) - after_attempts = after["attempt_ids"] - assert isinstance(after_attempts, list) - added = sorted(set(after_attempts) - set(before_attempts)) - removed = sorted(set(before_attempts) - set(after_attempts)) - if ( - added != [expected_attempt_id] - or removed - or len(after_attempts) != len(before_attempts) + 1 - ): - raise CellBoundaryError( - "populate did not add exactly its reported immutable attempt" - ) - current = after["current"] - if not isinstance(current, dict): - raise CellBoundaryError("accepted cell has no authenticated current") - if ( - current.get("attempt_id") != expected_attempt_id - or current.get("status") != "ok" - ): - raise CellBoundaryError( - "accepted current identity or result status differs" - ) - for field in ( - "manifest_sha256", - "result_sha256", - "worker_result_sha256", - ): - value = current.get(field) - if not isinstance(value, str) or _SHA256_RE.fullmatch(value) is None: - raise CellBoundaryError( - f"accepted current lacks authenticated {field}" - ) - record = store.load_current(cell_id) - assert record is not None - if validate_result is not None: - validate_result(record.result) - return after - - -__all__ = [ - "CELL_BOUNDARY_SCHEMA", - "CellBoundaryError", - "authenticate_current_delta", - "load_cell_boundary", - "snapshot_cell_boundary", -] diff --git a/pyamplicol/tools/performance_report/cache.py b/pyamplicol/tools/performance_report/cache.py deleted file mode 100644 index 7223adc35a..0000000000 --- a/pyamplicol/tools/performance_report/cache.py +++ /dev/null @@ -1,1674 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Canonical reset caches and strict compact measurement validation.""" - -from __future__ import annotations - -import hashlib -import json -import math -from collections import Counter -from collections.abc import Iterable, Mapping -from pathlib import Path -from typing import Any - -from .agreements import ( - DIRECT_AGREEMENT_FIELD, - DIRECT_AGREEMENT_KINDS, - INDEPENDENT_AUTHORITY_ABI, - INDEPENDENT_AUTHORITY_FIELD, - LC_COMMON_COMPONENT_FIELD, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_COMPARISON_FIELD, - MADGRAPH_FULL_COLOUR, - incoming_agreement_edges, - independent_numerical_authorities, - madgraph_candidate_precision, - requires_independent_numerical_authority, - validate_direct_agreement_records, - validate_lc_common_component, - validate_madgraph_comparison_record, -) -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import Accuracy, CellSpec, ExecutionMode, ResultStatus -from .runner import ( - CONDITIONED_COMPARISON_ABI, - CONVENTIONAL_WARMUP_FIELDS, - CONVENTIONAL_WARMUP_TIMING_SCOPE, - OTF_ACTIVE_FAMILY_COUNT_FIELDS, - OTF_COLD_WARMUP_FIELDS, - OTF_COLD_WARMUP_RUNTIME_FRESHNESSES, - OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE, - OTF_COLD_WARMUP_TIMING_SCOPE, - OTF_RECURRENCE_AUTHORITY_VALIDATION_ABI, - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD, - OTF_RUNTIME_STATE_CENSUS_KIND, - OTF_RUNTIME_STATE_COUNT_FIELDS, - OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY, - WARMUP_TIMER_SOURCE, - validate_conditioned_comparison_record, - validate_on_the_fly_recurrence_authority_validation_record, - validate_profile_warmup_evidence, - validate_resolved_sum_validation_record, -) -from .timing import ( - ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI, - EVALUATOR_TOTAL_TIMING_KEY, - MEASURED_EXECUTION_TIMING_ABI, - evaluator_total_timing_record, - unavailable_execution_timing_record, -) - -CACHE_SCHEMA_VERSION = 5 -REPORT_VERSION = "0.3.0" -_MEASURED_EXECUTION_TIMING_FIELDS = frozenset( - { - "abi", - "status", - "ratio_eligible", - "raw_seconds_per_point", - "source", - "compiled_direct_arena_active", - "sample_count", - "native_profile_points_per_sample", - "sample_contract", - } -) -_LOADED_ORIGIN_OBSERVATION_FIELDS = frozenset( - { - "observed_module_count", - "observations", - "observations_sha256", - } -) -_RUNTIME_POSTFLIGHT_FIELDS = frozenset( - { - "runtime_identity_sha256", - "runtime_identity_stable_sha256", - "runtime_identity_postflight_stable_sha256", - "runtime_identity_postflight_loaded_module_origin_policy", - "runtime_identity_postflight_match", - } -) -_PRECISION_DIAGNOSTIC_ABI = ( - "pyamplicol-report-validation-failure-precision-diagnostic-v2" -) - - -def _canonical_json(value: object) -> bytes: - return json.dumps( - value, - sort_keys=True, - separators=(",", ":"), - ensure_ascii=True, - ).encode("utf-8") - - -def digest_json(value: object) -> str: - return hashlib.sha256(_canonical_json(value)).hexdigest() - - -def _stable_runtime_identity(identity: Mapping[str, object]) -> dict[str, object]: - stable = dict(identity) - raw_policy = stable.get("loaded_module_origin_policy") - if isinstance(raw_policy, Mapping): - stable["loaded_module_origin_policy"] = { - field: value - for field, value in raw_policy.items() - if field not in _LOADED_ORIGIN_OBSERVATION_FIELDS - } - return stable - - -def _loaded_origin_policy( - value: object, - name: str, -) -> tuple[Mapping[str, object], list[object]]: - policy = _required_mapping(value, name) - observations = policy.get("observations") - count = policy.get("observed_module_count") - if ( - policy.get("kind") != "pyamplicol-loaded-module-origin-policy-v1" - or policy.get("all_loaded_origins_authenticated") is not True - or policy.get("native_image_origin_bound") is not True - or policy.get("loaded_bytecode_eligible") is not False - or isinstance(count, bool) - or not isinstance(count, int) - or count < 1 - or not isinstance(observations, list) - or len(observations) != count - or policy.get("observations_sha256") != digest_json(observations) - ): - raise ValueError(f"{name} is not authenticated loaded-origin evidence") - return policy, observations - - -def _validate_runtime_identity_postflight( - provenance: Mapping[str, object], - validation: Mapping[str, object], -) -> None: - """Require the initial/post-evaluation runtime identity binding.""" - - raw_identity = provenance.get("runtime_identity") - if raw_identity is None: - if ( - provenance.get("method") == "original-amplicol-generated-library" - or validation.get("method") == "independent-original-amplicol-oracle" - or ( - "source_revision" not in provenance - and not (_RUNTIME_POSTFLIGHT_FIELDS & provenance.keys()) - ) - ): - return - raise ValueError("successful pyAmpliCol measurement requires runtime_identity") - identity = _required_mapping(raw_identity, "provenance.runtime_identity") - if provenance.get("runtime_identity_sha256") != digest_json(identity): - raise ValueError("provenance.runtime_identity_sha256 does not match") - stable_digest = digest_json(_stable_runtime_identity(identity)) - if provenance.get("runtime_identity_stable_sha256") != stable_digest: - raise ValueError("provenance.runtime_identity_stable_sha256 does not match") - if provenance.get("runtime_identity_postflight_stable_sha256") != stable_digest: - raise ValueError( - "provenance.runtime_identity postflight stable SHA-256 differs" - ) - if provenance.get("runtime_identity_postflight_match") is not True: - raise ValueError("provenance.runtime_identity_postflight_match must be true") - - initial_policy, initial_observations = _loaded_origin_policy( - identity.get("loaded_module_origin_policy"), - "provenance.runtime_identity.loaded_module_origin_policy", - ) - postflight_policy, postflight_observations = _loaded_origin_policy( - provenance.get("runtime_identity_postflight_loaded_module_origin_policy"), - ("provenance.runtime_identity_postflight_loaded_module_origin_policy"), - ) - stable_initial_policy = { - field: value - for field, value in initial_policy.items() - if field not in _LOADED_ORIGIN_OBSERVATION_FIELDS - } - stable_postflight_policy = { - field: value - for field, value in postflight_policy.items() - if field not in _LOADED_ORIGIN_OBSERVATION_FIELDS - } - if stable_postflight_policy != stable_initial_policy: - raise ValueError("provenance runtime postflight origin policy changed") - postflight_keys = {_canonical_json(record) for record in postflight_observations} - if any( - _canonical_json(record) not in postflight_keys - for record in initial_observations - ): - raise ValueError("provenance runtime postflight lost a loaded-module origin") - - -def empty_measurement() -> dict[str, object]: - return { - "status": ResultStatus.NOT_AVAILABLE.value, - "generation_seconds": None, - "wall_seconds_per_point": None, - "execution_seconds_per_point": None, - "matrix_element": None, - "sample_count": None, - "standard_error_seconds_per_point": None, - "relative_standard_error": None, - "artifact": None, - "selector_contract": None, - "validation": None, - "resources": None, - "provenance": None, - "failure": None, - } - - -def _measurement_spec_payload(cell: CellSpec) -> dict[str, object]: - measurement = cell.measurement - return { - "execution_mode": measurement.execution_mode.value, - "model": None if measurement.model is None else measurement.model.value, - "accuracy": measurement.accuracy.value, - "backend": measurement.backend, - "jit_optimization_level": measurement.jit_optimization_level, - } - - -def reset_entry(cell: CellSpec) -> dict[str, object]: - return { - "cell_id": cell.cell_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "variant": cell.variant, - "workload": cell.workload.value, - "measurement_spec": _measurement_spec_payload(cell), - "measurement": empty_measurement(), - } - - -def build_reset_cache(dataset_id: str, cells: Iterable[CellSpec]) -> dict[str, object]: - selected = tuple(sorted(cells, key=lambda cell: cell.cell_id)) - if not selected: - raise ValueError(f"dataset {dataset_id!r} has no cells") - if any(cell.dataset_id != dataset_id for cell in selected): - raise ValueError("cache cells must all belong to the requested dataset") - descriptors = [_measurement_spec_payload(cell) for cell in selected] - unique_descriptors = { - json.dumps(descriptor, sort_keys=True) for descriptor in descriptors - } - return { - "$schema": "./report-cache.schema.json", - "schema_version": CACHE_SCHEMA_VERSION, - "report_version": REPORT_VERSION, - "kind": "performance_measurements", - "dataset_id": dataset_id, - "measurement_specs": [ - json.loads(value) for value in sorted(unique_descriptors) - ], - "entries": [reset_entry(cell) for cell in selected], - } - - -def build_reset_caches( - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, dict[str, object]]: - grouped: dict[str, list[CellSpec]] = {} - for cell in catalog.measurement_cells(): - grouped.setdefault(cell.dataset_id, []).append(cell) - return { - f"{dataset_id}.json": build_reset_cache(dataset_id, cells) - for dataset_id, cells in sorted(grouped.items()) - } - - -def _required_mapping(value: object, name: str) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise ValueError(f"{name} must be an object") - return value - - -def _required_number_or_none(value: object, name: str) -> float | None: - if value is None: - return None - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise ValueError(f"{name} must be a number or null") - number = float(value) - if not number >= 0.0: - raise ValueError(f"{name} must be non-negative") - return number - - -def _validate_execution_timing( - value: object, - *, - execution_seconds_per_point: float | None, - measurement_sample_count: int, - arena_profile_evidence: object, -) -> None: - timing = _required_mapping(value, "measurement.provenance.execution_timing") - if timing.get("abi") == ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI: - measurement = { - "execution_seconds_per_point": execution_seconds_per_point, - "provenance": { - "execution_timing": timing, - "arena_profile_evidence": arena_profile_evidence, - }, - } - if ( - unavailable_execution_timing_record( - measurement, - "execution_seconds_per_point", - ) - is None - or timing.get("sample_count") != measurement_sample_count - ): - raise ValueError( - "measurement.provenance.execution_timing is not an " - "authenticated Arena unavailable-attribution record" - ) - return - if set(timing) != _MEASURED_EXECUTION_TIMING_FIELDS: - raise ValueError( - "measurement.provenance.execution_timing fields do not match contract" - ) - if timing.get("abi") != MEASURED_EXECUTION_TIMING_ABI: - raise ValueError("measurement.provenance.execution_timing ABI is invalid") - raw = timing.get("raw_seconds_per_point") - if ( - isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - or float(raw) <= 0.0 - ): - raise ValueError("measurement.provenance.execution_timing raw time is invalid") - sample_count = timing.get("sample_count") - if ( - isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < 1 - or sample_count != measurement_sample_count - ): - raise ValueError( - "measurement.provenance.execution_timing sample_count is invalid" - ) - native_points = timing.get("native_profile_points_per_sample") - if native_points is not None and ( - isinstance(native_points, bool) - or not isinstance(native_points, int) - or native_points < 1 - ): - raise ValueError( - "measurement.provenance.execution_timing native point count is invalid" - ) - sample_contract = timing.get("sample_contract") - if not isinstance(sample_contract, str) or not sample_contract: - raise ValueError( - "measurement.provenance.execution_timing sample contract is invalid" - ) - if timing.get("status") != "measured": - raise ValueError( - "measurement.provenance.execution_timing status is unsupported" - ) - if ( - execution_seconds_per_point is None - or float(raw) != execution_seconds_per_point - or execution_seconds_per_point <= 0.0 - or timing.get("ratio_eligible") is not True - or not isinstance(timing.get("compiled_direct_arena_active"), bool) - or not isinstance(timing.get("source"), str) - or not timing.get("source") - ): - raise ValueError( - "measurement.provenance.execution_timing measured record is inconsistent" - ) - - -def _validate_conditioned_measurement_bindings( - validation: Mapping[str, object], - *, - expected_cell: CellSpec | None, - selector_contract: object, -) -> None: - resolved = validation.get("resolved_sum") - if not isinstance(resolved, Mapping): - return - point_identity = resolved.get("point_digest") - resolved_source = resolved.get("resolved_source_sha256") - high_resolved = validation.get("high_precision_resolved_sum") - high_source = ( - high_resolved.get("resolved_source_sha256") - if isinstance(high_resolved, Mapping) - else None - ) - component = validation.get(LC_COMMON_COMPONENT_FIELD) - for field in ("pointwise", "high_precision"): - record = validation.get(field) - if not ( - isinstance(record, Mapping) - and record.get("abi") == CONDITIONED_COMPARISON_ABI - ): - continue - binding = _required_mapping( - record.get("comparison_binding"), - f"validation.{field}.comparison_binding", - ) - identity = _required_mapping( - binding.get("selector_component_identity"), - f"validation.{field}.selector_component_identity", - ) - if binding.get("point_digest") != point_identity: - raise ValueError(f"validation.{field} is bound to a different point") - value_kind = identity.get("value_kind") - if expected_cell is not None: - expected_identity = { - "cell_id": expected_cell.cell_id, - "accuracy": expected_cell.measurement.accuracy.value, - "workload": expected_cell.workload.value, - "selector_contract": selector_contract, - "value_kind": value_kind, - } - for key, expected in expected_identity.items(): - if identity.get(key) != expected: - raise ValueError( - f"validation.{field} selector/component identity differs" - ) - if value_kind == LC_COMMON_COMPONENT_FIELD: - if not isinstance(component, Mapping): - raise ValueError(f"validation.{field} has no LC component scale source") - component_identity = identity.get("component_identity") - if not isinstance(component_identity, Mapping): - raise ValueError( - f"validation.{field} LC component identity is unavailable" - ) - for key in ("point_digest", "helicity_ids", "color_flow_ids"): - if component_identity.get(key) != component.get(key): - raise ValueError( - f"validation.{field} LC component identity differs" - ) - expected_candidate_source = digest_json(component) - else: - expected_candidate_source = resolved_source - if binding.get("candidate_source_sha256") != expected_candidate_source: - raise ValueError( - f"validation.{field} candidate scale source differs from resolved " - "evidence" - ) - if field == "high_precision" and ( - value_kind != "matrix-element-p16-versus-p32" - or binding.get("baseline_source_sha256") != high_source - ): - raise ValueError( - "validation.high_precision source binding differs from p32 evidence" - ) - - -def _validate_independent_authority_record( - validation: Mapping[str, object], - *, - expected_cell: CellSpec, - expected_status: str, - catalog: ReportCatalog, -) -> None: - if not requires_independent_numerical_authority( - expected_cell, - catalog=catalog, - ): - raise ValueError( - "independent-authority evidence is not applicable to this catalog cell" - ) - raw = validation.get(INDEPENDENT_AUTHORITY_FIELD) - record = _required_mapping(raw, f"validation.{INDEPENDENT_AUTHORITY_FIELD}") - expected_fields = { - "abi", - "expected_cell_ids", - "selected_cell_id", - "status", - "reason", - "same_artifact_diagnostics_are_authority", - } - canonical_ids = [ - cell.cell_id - for cell in independent_numerical_authorities( - expected_cell, - catalog=catalog, - ) - ] - if ( - set(record) != expected_fields - or record.get("abi") != INDEPENDENT_AUTHORITY_ABI - or record.get("expected_cell_ids") != canonical_ids - or record.get("status") != expected_status - or record.get("same_artifact_diagnostics_are_authority") is not False - ): - raise ValueError("independent-authority record is invalid") - selected = record.get("selected_cell_id") - reason = record.get("reason") - if expected_status == "unavailable": - if selected is not None or reason != "no-successful-independent-authority": - raise ValueError("unavailable independent-authority record is invalid") - elif ( - not isinstance(selected, str) - or selected not in canonical_ids - or not isinstance(reason, str) - or not reason - ): - raise ValueError("selected independent-authority record is invalid") - - -def _validate_unverified_precision_diagnostic(value: object) -> None: - record = _required_mapping(value, "validation.precision_diagnostic") - if ( - record.get("abi") != _PRECISION_DIAGNOSTIC_ABI - or record.get("promotes_measurement") is not False - ): - raise ValueError("unverified precision diagnostic is invalid") - if record.get("status") == "unavailable": - error = _required_mapping( - record.get("error"), - "validation.precision_diagnostic.error", - ) - if not isinstance(error.get("kind"), str) or not isinstance( - error.get("message"), str - ): - raise ValueError("unavailable precision diagnostic has no error") - return - if record.get("status") != "diagnostic-only": - raise ValueError("unverified precision diagnostic status is invalid") - attempts = record.get("attempts") - if not isinstance(attempts, list) or [ - attempt.get("precision_digits") if isinstance(attempt, Mapping) else None - for attempt in attempts - ] != [32, 200]: - raise ValueError("unverified precision diagnostic must retain p32 and p200") - if any( - attempt.get("status") not in {"evaluated", "unavailable"} - for attempt in attempts - if isinstance(attempt, Mapping) - ) or any(not isinstance(attempt, Mapping) for attempt in attempts): - raise ValueError("unverified precision diagnostic attempt is invalid") - - -def _validate_standalone_internal_validation( - measurement: Mapping[str, object], - validation: Mapping[str, object], -) -> None: - """Validate the p16/resolved/p32 contract for standalone benchmarks.""" - - if INDEPENDENT_AUTHORITY_FIELD in validation: - raise ValueError( - "standalone measurement cannot store independent-authority evidence" - ) - resolved = _required_mapping( - validation.get("resolved_sum"), - "validation.resolved_sum", - ) - high_resolved = _required_mapping( - validation.get("high_precision_resolved_sum"), - "validation.high_precision_resolved_sum", - ) - high_precision = _required_mapping( - validation.get("high_precision"), - "validation.high_precision", - ) - resolved_points = resolved.get("points") - high_points = high_resolved.get("points") - if ( - not isinstance(resolved_points, list) - or len(resolved_points) != 1 - or not isinstance(resolved_points[0], Mapping) - or not isinstance(high_points, list) - or len(high_points) != 1 - or not isinstance(high_points[0], Mapping) - ): - raise ValueError( - "standalone measurement requires one p16 and one p32 resolved point" - ) - resolved_point = resolved_points[0] - high_point = high_points[0] - if ( - resolved.get("status") != ResultStatus.OK.value - or resolved.get("precision_digits") != 16 - or high_resolved.get("status") != ResultStatus.OK.value - or high_resolved.get("precision_digits") != 32 - or high_precision.get("status") != ResultStatus.OK.value - ): - raise ValueError( - "standalone measurement requires successful resolved and p32 validation" - ) - identity_fields = ( - "point_digest", - "helicity_ids", - "color_flow_ids", - "resolved_ordering_sha256", - ) - if any( - resolved.get(field) != high_resolved.get(field) for field in identity_fields - ): - raise ValueError( - "standalone p16 and p32 resolved evidence has different identity" - ) - matrix_element = measurement.get("matrix_element") - if ( - isinstance(matrix_element, bool) - or not isinstance(matrix_element, (int, float)) - or not math.isfinite(float(matrix_element)) - ): - raise ValueError("standalone measurement matrix element is not finite") - expected_links = ( - (resolved_point.get("candidate"), matrix_element), - (high_precision.get("candidate"), matrix_element), - (high_precision.get("baseline"), high_point.get("candidate")), - ( - high_precision.get("candidate_scale"), - resolved_point.get("candidate_scale"), - ), - ( - high_precision.get("baseline_scale"), - high_point.get("candidate_scale"), - ), - (high_precision.get("relative_tolerance"), resolved.get("relative_tolerance")), - ( - high_precision.get("relative_tolerance"), - high_resolved.get("relative_tolerance"), - ), - ) - if any(observed != expected for observed, expected in expected_links): - raise ValueError( - "standalone matrix element and p16/p32 evidence are not exactly linked" - ) - if ( - high_precision.get("candidate_scale_source") != "resolved-component-l1-binary64" - or high_precision.get("baseline_scale_source") != "resolved-component-l1-p32" - ): - raise ValueError("standalone p16/p32 scale-source labels are invalid") - - -def _validate_unverified_direct_agreement_coverage( - validation: Mapping[str, object], - *, - expected_cell: CellSpec, - catalog: ReportCatalog, -) -> None: - direct_records = validation.get(DIRECT_AGREEMENT_FIELD) - if not isinstance(direct_records, list): - raise ValueError("unverified result has no direct-agreement records") - observed_edges = { - ( - record.get("edge_kind"), - record.get("baseline_cell_id"), - record.get("candidate_cell_id"), - ) - for record in direct_records - if isinstance(record, Mapping) - } - if any( - record.get("status") != ResultStatus.OK.value - and record.get("edge_kind") != LC_LEGACY_PYAMPLICOL_COMPONENT - for record in direct_records - if isinstance(record, Mapping) - ): - raise ValueError("unverified result has a failed direct-agreement record") - catalog_edges = incoming_agreement_edges(expected_cell, catalog=catalog) - required_edges = { - (edge.kind, edge.baseline.cell_id, edge.candidate.cell_id) - for edge in catalog_edges - if edge.required - } - allowed_edges = { - (edge.kind, edge.baseline.cell_id, edge.candidate.cell_id) - for edge in catalog_edges - } - if not required_edges.issubset(observed_edges) or not ( - observed_edges <= allowed_edges - ): - raise ValueError("unverified result direct-agreement coverage is incomplete") - - -def _validate_successful_otf_recurrence_authority( - measurement: Mapping[str, object], - validation: Mapping[str, object], - *, - expected_cell: CellSpec, - catalog: ReportCatalog, -) -> None: - if ( - expected_cell.measurement.execution_mode is not ExecutionMode.ON_THE_FLY - or expected_cell.measurement.accuracy is not Accuracy.LC - ): - return - recurrence = catalog.validation_baseline_cell(expected_cell) - if ( - recurrence is None - or recurrence.measurement.execution_mode is not ExecutionMode.RECURRENCE - ): - raise ValueError("on-the-fly recurrence authority is invalid") - provenance = _required_mapping( - measurement.get("provenance"), "measurement.provenance" - ) - runtime_identity = _required_mapping( - provenance.get("runtime_identity"), - "measurement.provenance.runtime_identity", - ) - candidate_artifact_id = runtime_identity.get("artifact_id") - if not isinstance(candidate_artifact_id, str): - raise ValueError("on-the-fly runtime identity has no artifact ID") - validate_on_the_fly_recurrence_authority_validation_record( - validation.get(OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD), - expected_cell=expected_cell, - selector_contract=measurement.get("selector_contract"), - candidate_artifact_id=candidate_artifact_id, - expected_authority_cell_id=recurrence.cell_id, - ) - - -def _validate_successful_otf_warmup_evidence( - measurement: Mapping[str, object], - *, - expected_cell: CellSpec, -) -> None: - if expected_cell.measurement.execution_mode is not ExecutionMode.ON_THE_FLY: - return - provenance = _required_mapping( - measurement.get("provenance"), "measurement.provenance" - ) - if provenance.get("runtime_load_included_in_cold_warmup") is not False: - raise ValueError( - "on-the-fly runtime load must be excluded from cold warm-up timing" - ) - if provenance.get("generation_timer_excludes_model_preparation") is not True: - raise ValueError("on-the-fly generation timing must exclude model preparation") - effective = _required_mapping( - provenance.get("effective_config"), - "measurement.provenance.effective_config", - ) - benchmark = _required_mapping( - effective.get("benchmark"), - "measurement.provenance.effective_config.benchmark", - ) - expected_batch_size = benchmark.get("batch_size") - expected_warmup_runs = benchmark.get("warmup_runs") - if ( - isinstance(expected_batch_size, bool) - or not isinstance(expected_batch_size, int) - or expected_batch_size < 1 - ): - raise ValueError("on-the-fly effective benchmark batch_size must be positive") - if ( - isinstance(expected_warmup_runs, bool) - or not isinstance(expected_warmup_runs, int) - or expected_warmup_runs < 0 - ): - raise ValueError( - "on-the-fly effective benchmark warmup_runs must be non-negative" - ) - validate_profile_warmup_evidence( - provenance.get("runtime_profile"), - execution_mode=expected_cell.measurement.execution_mode, - expected_batch_size=expected_batch_size, - expected_warmup_run_count=expected_warmup_runs, - ) - - -def validate_measurement( - value: object, - *, - expected_cell: CellSpec | None = None, - catalog: ReportCatalog = REPORT_CATALOG, -) -> None: - measurement = _required_mapping(value, "measurement") - expected_keys = set(empty_measurement()) - if set(measurement) != expected_keys: - missing = sorted(expected_keys - set(measurement)) - extra = sorted(set(measurement) - expected_keys) - raise ValueError( - f"measurement fields do not match schema; missing={missing}, extra={extra}" - ) - try: - status = ResultStatus(str(measurement["status"])) - except ValueError as exc: - raise ValueError("measurement.status is unsupported") from exc - for field in ( - "generation_seconds", - "wall_seconds_per_point", - "execution_seconds_per_point", - "standard_error_seconds_per_point", - "relative_standard_error", - ): - _required_number_or_none(measurement[field], f"measurement.{field}") - sample_count = measurement["sample_count"] - if sample_count is not None and ( - isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < 1 - ): - raise ValueError("measurement.sample_count must be a positive integer or null") - if status is ResultStatus.NOT_AVAILABLE: - expected = empty_measurement() - if dict(measurement) != expected: - raise ValueError("not_available measurement must be the canonical reset") - elif status in {ResultStatus.OK, ResultStatus.UNVERIFIED}: - retained_diagnostic = status is ResultStatus.UNVERIFIED - for field in ( - "generation_seconds", - "wall_seconds_per_point", - "matrix_element", - "sample_count", - "artifact", - "validation", - "resources", - "provenance", - ): - if measurement[field] is None: - raise ValueError(f"measured result requires {field}") - validation = _required_mapping(measurement["validation"], "validation") - expected_validation_status = ( - ResultStatus.UNVERIFIED.value - if retained_diagnostic - else ResultStatus.OK.value - ) - if validation.get("status") != expected_validation_status: - raise ValueError("measurement validation status is inconsistent") - if "resolved_sum" in validation: - validate_resolved_sum_validation_record(validation["resolved_sum"]) - for field in ("pointwise", "high_precision"): - if field in validation: - validate_conditioned_comparison_record( - validation[field], - require_binding=True, - ) - if "high_precision_resolved_sum" in validation: - validate_resolved_sum_validation_record( - validation["high_precision_resolved_sum"] - ) - _validate_conditioned_measurement_bindings( - validation, - expected_cell=expected_cell, - selector_contract=measurement.get("selector_contract"), - ) - validate_direct_agreement_records( - validation.get(DIRECT_AGREEMENT_FIELD), - expected_candidate_id=( - None if expected_cell is None else expected_cell.cell_id - ), - ) - madgraph_edges = ( - () - if expected_cell is None - else tuple( - edge - for edge in incoming_agreement_edges( - expected_cell, - catalog=catalog, - ) - if edge.kind == MADGRAPH_FULL_COLOUR - ) - ) - if madgraph_edges: - validate_madgraph_comparison_record( - validation.get(MADGRAPH_COMPARISON_FIELD), - expected_candidate_id=expected_cell.cell_id, - expected_candidate_precision=madgraph_candidate_precision( - expected_cell - ), - ) - elif MADGRAPH_COMPARISON_FIELD in validation: - raise ValueError( - "measurement without a MadGraph edge has MadGraph comparison evidence" - ) - selector_contract = measurement.get("selector_contract") - if expected_cell is not None: - expects_lc = expected_cell.measurement.accuracy is Accuracy.LC - if expects_lc and not isinstance(selector_contract, Mapping): - raise ValueError("successful LC measurement requires selector_contract") - if not expects_lc and selector_contract is not None: - raise ValueError( - "successful non-LC measurement cannot contain selector_contract" - ) - requires_lc_component = ( - expected_cell.measurement.accuracy is Accuracy.LC - if expected_cell is not None - else isinstance(selector_contract, Mapping) - ) - if requires_lc_component: - validate_lc_common_component( - validation.get(LC_COMMON_COMPONENT_FIELD), - expected_cell_id=( - None if expected_cell is None else expected_cell.cell_id - ), - selector_contract=selector_contract, - ) - elif validation.get(LC_COMMON_COMPONENT_FIELD) is not None: - raise ValueError("non-LC measurement cannot contain lc_common_component") - if expected_cell is not None and not retained_diagnostic: - _validate_successful_otf_recurrence_authority( - measurement, - validation, - expected_cell=expected_cell, - catalog=catalog, - ) - if retained_diagnostic: - if ( - expected_cell is None - or expected_cell.measurement.execution_mode - not in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - ): - raise ValueError( - "unverified timing requires a compiled/eager catalog cell" - ) - _validate_independent_authority_record( - validation, - expected_cell=expected_cell, - expected_status="unavailable", - catalog=catalog, - ) - _validate_unverified_direct_agreement_coverage( - validation, - expected_cell=expected_cell, - catalog=catalog, - ) - resolved = _required_mapping( - validation.get("resolved_sum"), - "validation.resolved_sum", - ) - high_resolved = _required_mapping( - validation.get("high_precision_resolved_sum"), - "validation.high_precision_resolved_sum", - ) - high_precision = _required_mapping( - validation.get("high_precision"), - "validation.high_precision", - ) - if any( - record.get("status") != ResultStatus.OK.value - for record in (resolved, high_resolved, high_precision) - ): - raise ValueError( - "unverified result requires successful same-artifact diagnostics" - ) - _validate_unverified_precision_diagnostic( - validation.get("precision_diagnostic") - ) - elif ( - expected_cell is not None - and ( - expected_cell.measurement.execution_mode - is ExecutionMode.RECURRENCE - or ( - expected_cell.measurement.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - and not requires_independent_numerical_authority( - expected_cell, - catalog=catalog, - ) - ) - ) - ): - _validate_standalone_internal_validation(measurement, validation) - elif INDEPENDENT_AUTHORITY_FIELD in validation: - if expected_cell is None: - raise ValueError( - "independent-authority evidence requires a catalog cell" - ) - _validate_independent_authority_record( - validation, - expected_cell=expected_cell, - expected_status="verified", - catalog=catalog, - ) - pointwise = _required_mapping( - validation.get("pointwise"), - "validation.pointwise", - ) - if pointwise.get("status") != ResultStatus.OK.value: - raise ValueError( - "verified independent-authority comparison is not successful" - ) - if "precision_diagnostic" in validation: - _validate_unverified_precision_diagnostic( - validation.get("precision_diagnostic") - ) - provenance = _required_mapping( - measurement["provenance"], "measurement.provenance" - ) - if expected_cell is not None: - _validate_successful_otf_warmup_evidence( - measurement, - expected_cell=expected_cell, - ) - execution_seconds = _required_number_or_none( - measurement["execution_seconds_per_point"], - "measurement.execution_seconds_per_point", - ) - raw_execution_timing = provenance.get("execution_timing") - if raw_execution_timing is not None: - _validate_execution_timing( - raw_execution_timing, - execution_seconds_per_point=execution_seconds, - measurement_sample_count=int(measurement["sample_count"]), - arena_profile_evidence=provenance.get("arena_profile_evidence"), - ) - elif execution_seconds is None and "source_revision" in provenance: - raise ValueError( - "successful pyAmpliCol measurement with unavailable execution " - "timing requires authenticated Arena provenance" - ) - if ( - EVALUATOR_TOTAL_TIMING_KEY in provenance - and evaluator_total_timing_record(measurement) is None - ): - raise ValueError( - "measurement.provenance.evaluator_total_timing is not an " - "authenticated accumulated evaluator-total record" - ) - _validate_runtime_identity_postflight(provenance, validation) - if retained_diagnostic: - failure = _required_mapping( - measurement["failure"], - "measurement.failure", - ) - if ( - set(failure) != {"kind", "message"} - or failure.get("kind") != "IndependentAuthorityUnavailable" - or not isinstance(failure.get("message"), str) - or not failure.get("message") - ): - raise ValueError("unverified result failure metadata is invalid") - elif measurement["failure"] is not None: - raise ValueError("successful measurement cannot contain failure metadata") - elif measurement["failure"] is None: - raise ValueError("non-success measurement requires failure metadata") - - -def validate_cache( - payload: object, - *, - expected_cells: Iterable[CellSpec] | None = None, - catalog: ReportCatalog = REPORT_CATALOG, -) -> None: - expected_cell_list = None if expected_cells is None else tuple(expected_cells) - expected_by_id = ( - {} - if expected_cell_list is None - else {cell.cell_id: cell for cell in expected_cell_list} - ) - cache = _required_mapping(payload, "cache") - if cache.get("schema_version") != CACHE_SCHEMA_VERSION: - raise ValueError("cache schema_version is unsupported") - if cache.get("report_version") != REPORT_VERSION: - raise ValueError("cache report_version is unsupported") - if cache.get("kind") != "performance_measurements": - raise ValueError("cache kind is unsupported") - dataset_id = cache.get("dataset_id") - if not isinstance(dataset_id, str) or not dataset_id: - raise ValueError("cache dataset_id must be a non-empty string") - entries = cache.get("entries") - if not isinstance(entries, list): - raise ValueError("cache entries must be a list") - ids: list[str] = [] - for index, raw_entry in enumerate(entries): - entry = _required_mapping(raw_entry, f"entries[{index}]") - cell_id = entry.get("cell_id") - if not isinstance(cell_id, str) or not cell_id: - raise ValueError(f"entries[{index}].cell_id must be a non-empty string") - ids.append(cell_id) - if entry.get("process_key") is not None and not isinstance( - entry.get("process_key"), str - ): - raise ValueError(f"entries[{index}].process_key must be a string or null") - if not isinstance(entry.get("process"), str): - raise ValueError(f"entries[{index}].process must be a string") - n_final = entry.get("n_final") - if isinstance(n_final, bool) or not isinstance(n_final, int) or n_final < 1: - raise ValueError(f"entries[{index}].n_final must be positive") - validate_measurement( - entry.get("measurement"), - expected_cell=expected_by_id.get(cell_id), - catalog=catalog, - ) - duplicate_ids = sorted( - cell_id for cell_id, count in Counter(ids).items() if count > 1 - ) - if duplicate_ids: - raise ValueError(f"cache contains duplicate cell IDs: {duplicate_ids}") - if expected_cell_list is not None: - expected = sorted(cell.cell_id for cell in expected_cell_list) - if sorted(ids) != expected: - raise ValueError(f"cache coverage differs for dataset {dataset_id}") - - -def schema_document() -> dict[str, object]: - statuses = [status.value for status in ResultStatus] - nullable_number: dict[str, Any] = {"type": ["number", "null"], "minimum": 0} - cold_warmup_required = sorted(OTF_COLD_WARMUP_FIELDS) - otf_warmup_required = sorted(CONVENTIONAL_WARMUP_FIELDS | OTF_COLD_WARMUP_FIELDS) - nonnegative_integer: dict[str, Any] = {"type": "integer", "minimum": 0} - active_family_fields = { - "basis": {"const": "shared-query-family-union-v1"}, - "scope": {"const": "active-family-union"}, - **{ - field: dict(nonnegative_integer) for field in OTF_ACTIVE_FAMILY_COUNT_FIELDS - }, - } - active_family_census: dict[str, Any] = { - "oneOf": [ - {"type": "null"}, - { - "type": "object", - "required": sorted(active_family_fields), - "properties": active_family_fields, - "additionalProperties": False, - }, - ] - } - runtime_state_fields = { - "kind": {"const": OTF_RUNTIME_STATE_CENSUS_KIND}, - "process_id": {"type": "string", "minLength": 1}, - "family_cache_policy": {"const": OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY}, - "family_cache_limit": {"const": OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT}, - **{ - field: dict(nonnegative_integer) for field in OTF_RUNTIME_STATE_COUNT_FIELDS - }, - "active_family_union_census": active_family_census, - } - runtime_state_fields["retained_family_count"] = { - "type": "integer", - "minimum": 0, - "maximum": OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT, - } - runtime_state_census: dict[str, Any] = { - "type": "object", - "required": sorted(runtime_state_fields), - "properties": runtime_state_fields, - "additionalProperties": False, - } - runtime_profile: dict[str, Any] = { - "type": "object", - "properties": { - "cold_warmup_elapsed_seconds": { - "type": "number", - "exclusiveMinimum": 0, - }, - "cold_warmup_run_count": {"const": 1}, - "cold_warmup_batch_size": {"type": "integer", "minimum": 1}, - "cold_warmup_point_count": {"type": "integer", "minimum": 1}, - "cold_warmup_timer_source": {"const": WARMUP_TIMER_SOURCE}, - "cold_warmup_timing_scope": {"const": OTF_COLD_WARMUP_TIMING_SCOPE}, - "cold_warmup_runtime_freshness": { - "enum": sorted(OTF_COLD_WARMUP_RUNTIME_FRESHNESSES) - }, - "cold_warmup_runtime_state_evidence": { - "const": OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - }, - "cold_warmup_runtime_state_before": runtime_state_census, - "cold_warmup_runtime_state_after": runtime_state_census, - "cold_warmup_runtime_cold_before_first_evaluation": {"type": "boolean"}, - "cold_warmup_runtime_retained_before_first_evaluation": {"type": "boolean"}, - "cold_warmup_runtime_retained_after_first_evaluation": {"const": True}, - "cold_warmup_ratio_eligible": {"const": False}, - "cold_warmup_acceptance_eligible": {"const": False}, - "warmup_elapsed_seconds": {"type": "number", "minimum": 0}, - "warmup_configured_run_count": { - "type": "integer", - "minimum": 0, - }, - "warmup_batch_size": {"type": "integer", "minimum": 1}, - "warmup_point_count": {"type": "integer", "minimum": 0}, - "warmup_run_outer_wall_seconds": { - "type": "array", - "items": {"type": "number", "minimum": 0}, - }, - "first_warmup_run_outer_wall_seconds": { - "type": ["number", "null"], - "minimum": 0, - }, - "warmup_timer_source": {"const": WARMUP_TIMER_SOURCE}, - "warmup_timing_scope": {"const": CONVENTIONAL_WARMUP_TIMING_SCOPE}, - }, - "dependentRequired": { - field: otf_warmup_required for field in cold_warmup_required - }, - } - provenance_record: dict[str, Any] = { - "oneOf": [ - {"type": "null"}, - { - "type": "object", - "properties": { - "runtime_profile": runtime_profile, - "runtime_load_included_in_cold_warmup": {"const": False}, - "generation_timer_excludes_model_preparation": {"const": True}, - }, - }, - ] - } - direct_identity_properties: dict[str, Any] = { - "edge_kind": {"enum": list(DIRECT_AGREEMENT_KINDS)}, - "value_kind": {"enum": ["matrix_element", LC_COMMON_COMPONENT_FIELD]}, - "baseline_cell_id": {"type": "string", "minLength": 1}, - "candidate_cell_id": {"type": "string", "minLength": 1}, - "status": {"enum": statuses}, - "candidate": {"type": "number"}, - "baseline": {"type": "number"}, - "absolute_difference": {"type": "number", "minimum": 0}, - "relative_difference": {"type": "number", "minimum": 0}, - "relative_tolerance": {"type": "number", "minimum": 0}, - } - direct_v1: dict[str, Any] = { - "type": "object", - "required": [ - "abi", - "edge_kind", - "value_kind", - "baseline_cell_id", - "candidate_cell_id", - "status", - "candidate", - "baseline", - "absolute_difference", - "relative_difference", - "relative_tolerance", - "absolute_tolerance", - ], - "properties": { - "abi": {"const": "pyamplicol-report-direct-agreement-v1"}, - **direct_identity_properties, - "absolute_tolerance": {"type": "number", "minimum": 0}, - }, - "additionalProperties": False, - } - direct_v2_fields = [ - "abi", - "edge_kind", - "value_kind", - "baseline_cell_id", - "candidate_cell_id", - "status", - "candidate", - "baseline", - "candidate_scale", - "baseline_scale", - "candidate_scale_source", - "baseline_scale_source", - "comparison_scale", - "absolute_difference", - "relative_difference", - "conditioned_residual", - "error_bound", - "relative_tolerance", - "comparison_binding", - ] - direct_v2: dict[str, Any] = { - "type": "object", - "required": direct_v2_fields, - "properties": { - "abi": {"const": "pyamplicol-report-direct-agreement-v2"}, - **direct_identity_properties, - "candidate_scale": {"type": "number", "minimum": 0}, - "baseline_scale": {"type": "number", "minimum": 0}, - "candidate_scale_source": {"type": "string", "minLength": 1}, - "baseline_scale_source": {"type": "string", "minLength": 1}, - "comparison_scale": {"type": "number", "minimum": 0}, - "conditioned_residual": {"type": "number", "minimum": 0}, - "error_bound": {"type": "number", "minimum": 0}, - "comparison_binding": {"type": "object", "minProperties": 1}, - }, - "additionalProperties": False, - } - direct_agreement_record: dict[str, Any] = {"oneOf": [direct_v1, direct_v2]} - lc_common_component: dict[str, Any] = { - "type": "object", - "required": [ - "abi", - "cell_id", - "value", - "point_digest", - "helicity_ids", - "color_flow_ids", - ], - "properties": { - "abi": {"const": "pyamplicol-report-lc-common-component-v1"}, - "cell_id": {"type": "string", "minLength": 1}, - "value": {"type": "number"}, - "point_digest": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "helicity_ids": { - "type": "array", - "minItems": 1, - "uniqueItems": True, - "items": {"type": "string", "minLength": 1}, - }, - "color_flow_ids": { - "type": "array", - "minItems": 1, - "uniqueItems": True, - "items": {"type": "string", "minLength": 1}, - }, - }, - "additionalProperties": False, - } - otf_total_summary: dict[str, Any] = { - "type": "object", - "required": [ - "check_count", - "maximum_conditioned_residual", - "maximum_absolute_delta", - ], - "properties": { - "check_count": {"type": "integer", "minimum": 1}, - "maximum_conditioned_residual": {"type": "number", "minimum": 0}, - "maximum_absolute_delta": {"type": "number", "minimum": 0}, - }, - "additionalProperties": False, - } - otf_component_summary: dict[str, Any] = { - "type": "object", - "required": [ - "check_count", - "component_count", - "maximum_conditioned_residual", - "maximum_absolute_delta", - ], - "properties": { - **otf_total_summary["properties"], - "component_count": {"type": "integer", "minimum": 1}, - }, - "additionalProperties": False, - } - otf_comparison: dict[str, Any] = { - "type": "object", - "required": ["authority_cell_id", "total", "resolved_components"], - "properties": { - "authority_cell_id": {"type": "string", "minLength": 1}, - "total": otf_total_summary, - "resolved_components": otf_component_summary, - }, - "additionalProperties": False, - } - otf_stage: dict[str, Any] = { - "type": "object", - "required": [ - "candidate_total_source_sha256", - "candidate_resolved_total_source_sha256", - "candidate_resolved_ordering_sha256", - "candidate_resolved_source_sha256", - "candidate_resolved_sum", - "comparison", - ], - "properties": { - "candidate_total_source_sha256": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "candidate_resolved_total_source_sha256": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "candidate_resolved_ordering_sha256": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "candidate_resolved_source_sha256": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "candidate_resolved_sum": otf_total_summary, - "comparison": otf_comparison, - }, - "additionalProperties": False, - } - otf_authority: dict[str, Any] = { - "type": "object", - "required": [ - "cell_id", - "artifact_id", - "total_source_sha256", - "resolved_total_source_sha256", - "resolved_ordering_sha256", - "resolved_source_sha256", - "resolved_sum", - ], - "properties": { - "cell_id": {"type": "string", "minLength": 1}, - **{ - field: {"type": "string", "pattern": "^[0-9a-f]{64}$"} - for field in ( - "artifact_id", - "total_source_sha256", - "resolved_total_source_sha256", - "resolved_ordering_sha256", - "resolved_source_sha256", - ) - }, - "resolved_sum": otf_total_summary, - }, - "additionalProperties": False, - } - otf_recurrence_authority: dict[str, Any] = { - "type": "object", - "required": [ - "abi", - "status", - "candidate_cell_id", - "candidate_artifact_id", - "workload", - "precision_digits", - "relative_tolerance", - "point_digest", - "selector_sha256", - "point_count", - "resolved_component_count", - "resolved_check_count", - "authority", - "before_clear", - "after_clear", - "lifecycle", - ], - "properties": { - "abi": {"const": OTF_RECURRENCE_AUTHORITY_VALIDATION_ABI}, - "status": {"const": ResultStatus.OK.value}, - "candidate_cell_id": {"type": "string", "minLength": 1}, - "candidate_artifact_id": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "workload": {"enum": ["selected-flow", "all-flow"]}, - "precision_digits": {"const": 16}, - "relative_tolerance": {"const": 1.0e-12}, - "point_digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"}, - "selector_sha256": { - "type": "string", - "pattern": "^[0-9a-f]{64}$", - }, - "point_count": {"type": "integer", "minimum": 1}, - "resolved_component_count": {"type": "integer", "minimum": 1}, - "resolved_check_count": {"type": "integer", "minimum": 1}, - "authority": otf_authority, - "before_clear": otf_stage, - "after_clear": otf_stage, - "lifecycle": { - "type": "object", - "required": [ - "authority_artifact_loaded_only", - "candidate_loaded_before_validation", - "validated_before_clear", - "validated_after_clear", - "clear_call_count", - "final_clear_before_profile", - ], - "properties": { - "authority_artifact_loaded_only": {"const": True}, - "candidate_loaded_before_validation": {"const": True}, - "validated_before_clear": {"const": True}, - "validated_after_clear": {"const": True}, - "clear_call_count": {"const": 2}, - "final_clear_before_profile": {"const": True}, - }, - "additionalProperties": False, - }, - }, - "additionalProperties": False, - } - validation_properties = { - "status": {"enum": statuses}, - DIRECT_AGREEMENT_FIELD: { - "type": "array", - "items": direct_agreement_record, - }, - INDEPENDENT_AUTHORITY_FIELD: { - "type": "object", - "required": [ - "abi", - "expected_cell_ids", - "selected_cell_id", - "status", - "reason", - "same_artifact_diagnostics_are_authority", - ], - "properties": { - "abi": {"const": INDEPENDENT_AUTHORITY_ABI}, - "expected_cell_ids": { - "type": "array", - "uniqueItems": True, - "items": {"type": "string", "minLength": 1}, - }, - "selected_cell_id": {"type": ["string", "null"]}, - "status": { - "enum": ["unavailable", "verified", "mismatch", "incompatible"] - }, - "reason": {"type": "string", "minLength": 1}, - "same_artifact_diagnostics_are_authority": {"const": False}, - }, - "additionalProperties": False, - }, - LC_COMMON_COMPONENT_FIELD: lc_common_component, - MADGRAPH_COMPARISON_FIELD: {"type": "object"}, - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD: otf_recurrence_authority, - } - validation_record: dict[str, Any] = { - "oneOf": [ - {"type": "null"}, - { - "type": "object", - "properties": validation_properties, - }, - ] - } - successful_validation_record: dict[str, Any] = { - "type": "object", - "required": [DIRECT_AGREEMENT_FIELD], - "properties": validation_properties, - } - return { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://pyamplicol.dev/schema/report-cache-v5.json", - "title": "pyAmpliCol performance cache", - "type": "object", - "required": [ - "$schema", - "schema_version", - "report_version", - "kind", - "dataset_id", - "measurement_specs", - "entries", - ], - "properties": { - "$schema": {"const": "./report-cache.schema.json"}, - "schema_version": {"const": CACHE_SCHEMA_VERSION}, - "report_version": {"const": REPORT_VERSION}, - "kind": {"const": "performance_measurements"}, - "dataset_id": {"type": "string", "minLength": 1}, - "measurement_specs": {"type": "array", "items": {"type": "object"}}, - "entries": { - "type": "array", - "items": { - "type": "object", - "required": [ - "cell_id", - "process_key", - "process", - "n_final", - "variant", - "workload", - "measurement_spec", - "measurement", - ], - "properties": { - "cell_id": {"type": "string", "minLength": 1}, - "process_key": {"type": ["string", "null"]}, - "process": {"type": "string", "minLength": 1}, - "n_final": {"type": "integer", "minimum": 1}, - "variant": {"type": ["string", "null"]}, - "workload": { - "enum": ["selected-flow", "all-flow", "contracted"] - }, - "measurement_spec": {"type": "object"}, - "measurement": { - "type": "object", - "required": list(empty_measurement()), - "properties": { - "status": {"enum": statuses}, - "generation_seconds": nullable_number, - "wall_seconds_per_point": nullable_number, - "execution_seconds_per_point": nullable_number, - "matrix_element": { - "type": ["number", "string", "null"] - }, - "sample_count": { - "type": ["integer", "null"], - "minimum": 1, - }, - "standard_error_seconds_per_point": nullable_number, - "relative_standard_error": nullable_number, - "artifact": {"type": ["object", "null"]}, - "selector_contract": {"type": ["object", "null"]}, - "validation": validation_record, - "resources": {"type": ["object", "null"]}, - "provenance": provenance_record, - "failure": {"type": ["object", "null"]}, - }, - "allOf": [ - { - "if": { - "properties": { - "status": {"const": ResultStatus.OK.value} - }, - "required": ["status"], - }, - "then": { - "properties": { - "validation": (successful_validation_record) - } - }, - }, - { - "if": { - "properties": { - "status": { - "const": ResultStatus.UNVERIFIED.value - } - }, - "required": ["status"], - }, - "then": { - "properties": { - "validation": { - "type": "object", - "required": [ - "status", - DIRECT_AGREEMENT_FIELD, - INDEPENDENT_AUTHORITY_FIELD, - "resolved_sum", - "high_precision_resolved_sum", - "high_precision", - "precision_diagnostic", - ], - "properties": validation_properties, - }, - "failure": {"type": "object"}, - } - }, - }, - ], - "additionalProperties": False, - }, - }, - "additionalProperties": False, - }, - }, - }, - "additionalProperties": False, - } - - -def write_reset_caches( - results_dir: Path, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[Path, ...]: - results_dir.mkdir(parents=True, exist_ok=True) - caches = build_reset_caches(catalog) - written: list[Path] = [] - schema_path = results_dir / "report-cache.schema.json" - schema_path.write_bytes(_canonical_json(schema_document()) + b"\n") - written.append(schema_path) - for name, payload in caches.items(): - path = results_dir / name - path.write_bytes(_canonical_json(payload) + b"\n") - written.append(path) - return tuple(written) - - -__all__ = [ - "CACHE_SCHEMA_VERSION", - "REPORT_VERSION", - "build_reset_cache", - "build_reset_caches", - "digest_json", - "empty_measurement", - "schema_document", - "validate_cache", - "validate_measurement", - "write_reset_caches", -] diff --git a/pyamplicol/tools/performance_report/campaign_activity.py b/pyamplicol/tools/performance_report/campaign_activity.py deleted file mode 100644 index 9d9da4df8c..0000000000 --- a/pyamplicol/tools/performance_report/campaign_activity.py +++ /dev/null @@ -1,288 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Bounded campaign-idle census that excludes report-only publication work.""" - -from __future__ import annotations - -import os -import shlex -import subprocess -from collections.abc import Iterable, Sequence -from dataclasses import dataclass -from pathlib import Path - -_MEASUREMENT_ACTIONS = frozenset({"populate", "_worker", "_prepare"}) -_INSTALL_ENTRYPOINTS = frozenset( - { - "install_dependencies.py", - "prepare_source_runtime.py", - } -) -_NATIVE_BUILD_EXECUTABLES = frozenset({"cargo", "maturin", "rustc"}) -_LATEX_EXECUTABLES = frozenset( - {"latexmk", "lualatex", "pdflatex", "xelatex"} -) - - -class CampaignActivityError(RuntimeError): - """Raised when a measurement or mutation owner remains active.""" - - -@dataclass(frozen=True, slots=True) -class OpenFile: - """One machine-readable ``lsof`` file-descriptor record.""" - - pid: int - command: str - descriptor: str - file_type: str - path: Path - - -@dataclass(frozen=True, slots=True) -class CampaignActivity: - """Blocking processes and coordination file descriptors.""" - - processes: tuple[str, ...] - coordination_files: tuple[OpenFile, ...] - - @property - def idle(self) -> bool: - return not self.processes and not self.coordination_files - - -def _arguments(command: str) -> tuple[str, ...]: - try: - return tuple(shlex.split(command)) - except ValueError: - return tuple(command.split()) - - -def _argument_basename(argument: str) -> str: - return Path(argument).name.lower() - - -def is_snapshot_publisher_process(command: str) -> bool: - """Return whether ``command`` is private snapshot render/compile work.""" - - arguments = _arguments(command) - lowered = tuple(argument.lower() for argument in arguments) - if "publish-snapshot" in lowered: - return True - basenames = {_argument_basename(argument) for argument in arguments} - return bool( - basenames & _LATEX_EXECUTABLES - and any(Path(argument).name == "pyAmpliCol.tex" for argument in arguments) - ) - - -def _is_campaign_process( - command: str, - *, - entrypoints: frozenset[str], -) -> bool: - if is_snapshot_publisher_process(command): - return False - arguments = _arguments(command) - if not arguments: - return False - basenames = {_argument_basename(argument) for argument in arguments} - if basenames & _INSTALL_ENTRYPOINTS: - return True - if _argument_basename(arguments[0]) in _NATIVE_BUILD_EXECUTABLES: - return True - if not any(argument in _MEASUREMENT_ACTIONS for argument in arguments): - return False - if not entrypoints: - return True - resolved_arguments = { - os.path.realpath(argument) - for argument in arguments - if argument.endswith(".py") - } - return bool(resolved_arguments & entrypoints) - - -def blocking_process_lines( - process_output: str, - *, - entrypoints: Iterable[Path] = (), -) -> tuple[str, ...]: - """Filter ``ps -axo pid=,comm=,args=`` output to campaign blockers.""" - - exact_entrypoints = frozenset( - os.path.realpath(os.fspath(path)) for path in entrypoints - ) - blocked: list[str] = [] - for raw_line in process_output.splitlines(): - line = raw_line.strip() - fields = line.split(None, 2) - if len(fields) != 3: - continue - if _is_campaign_process(fields[2], entrypoints=exact_entrypoints): - blocked.append(line) - return tuple(blocked) - - -def parse_lsof_field_output(output: str) -> tuple[OpenFile, ...]: - """Parse ``lsof -Fpcfnt`` output without depending on display columns.""" - - records: list[OpenFile] = [] - pid: int | None = None - command = "" - descriptor = "" - file_type = "" - path: Path | None = None - - def flush_file() -> None: - nonlocal descriptor, file_type, path - if pid is not None and descriptor and path is not None: - records.append( - OpenFile( - pid=pid, - command=command, - descriptor=descriptor, - file_type=file_type, - path=path, - ) - ) - descriptor = "" - file_type = "" - path = None - - for line in output.splitlines(): - if not line: - continue - field, value = line[0], line[1:] - if field == "p": - flush_file() - try: - pid = int(value) - except ValueError: - pid = None - command = "" - elif field == "c": - command = value - elif field == "f": - flush_file() - descriptor = value - file_type = "" - elif field == "t": - file_type = value - elif field == "n": - path = Path(value) - flush_file() - return tuple(records) - - -def is_publisher_private_coordination_file( - record: OpenFile, - *, - coordination_root: Path, -) -> bool: - """Recognize only regular publisher-private coordination state.""" - - publication_root = ( - coordination_root.expanduser().resolve(strict=False) / "publication" - ) - path = record.path.expanduser().resolve(strict=False) - return ( - record.file_type == "REG" - and path != publication_root - and publication_root in path.parents - ) - - -def blocking_coordination_files( - lsof_output: str, - *, - coordination_root: Path, -) -> tuple[OpenFile, ...]: - """Exclude publisher-private files but retain every lock/write owner.""" - - return tuple( - record - for record in parse_lsof_field_output(lsof_output) - if not is_publisher_private_coordination_file( - record, - coordination_root=coordination_root, - ) - ) - - -def campaign_activity( - *, - coordination_root: Path, - entrypoints: Sequence[Path] = (), -) -> CampaignActivity: - """Take one read-only process/coordination census.""" - - processes = subprocess.run( - ("ps", "-axo", "pid=,comm=,args="), - check=True, - capture_output=True, - text=True, - ).stdout - lsof = subprocess.run( - ( - "lsof", - "-Fpcfnt", - "+D", - os.fspath(coordination_root), - ), - check=False, - capture_output=True, - text=True, - ) - return CampaignActivity( - processes=blocking_process_lines( - processes, - entrypoints=entrypoints, - ), - coordination_files=blocking_coordination_files( - lsof.stdout, - coordination_root=coordination_root, - ), - ) - - -def require_campaign_idle( - *, - coordination_root: Path, - entrypoints: Sequence[Path] = (), -) -> None: - """Reject real campaign activity without treating the publisher as a worker.""" - - activity = campaign_activity( - coordination_root=coordination_root, - entrypoints=entrypoints, - ) - if activity.processes: - raise CampaignActivityError( - "measurement or install process remains active: " - f"{list(activity.processes[:10])}" - ) - if activity.coordination_files: - held = [ - ( - f"{record.command}[{record.pid}] " - f"{record.descriptor} {record.file_type} {record.path}" - ) - for record in activity.coordination_files[:10] - ] - raise CampaignActivityError( - f"campaign coordination files remain held: {held}" - ) - - -__all__ = [ - "CampaignActivity", - "CampaignActivityError", - "OpenFile", - "blocking_coordination_files", - "blocking_process_lines", - "campaign_activity", - "is_publisher_private_coordination_file", - "is_snapshot_publisher_process", - "parse_lsof_field_output", - "require_campaign_idle", -] diff --git a/pyamplicol/tools/performance_report/campaign_holds.py b/pyamplicol/tools/performance_report/campaign_holds.py deleted file mode 100644 index 0f1508155b..0000000000 --- a/pyamplicol/tools/performance_report/campaign_holds.py +++ /dev/null @@ -1,464 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Fail-closed re-admission of dependency-held campaign cells.""" - -from __future__ import annotations - -import re -from collections.abc import Callable, Iterable, Mapping -from dataclasses import dataclass - -from .agreements import ( - incoming_agreement_edges, - validation_baseline_is_required, -) -from .artifacts import ArtifactStore, CurrentRecord -from .cache import validate_measurement -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import CellSpec, ResultStatus - -PRIOR_HELD_DISPOSITION_ABI = "pyamplicol-prior-held-disposition-v1" -PRIOR_HELD_HISTORY_ABI = "pyamplicol-prior-held-history-v1" -DEPENDENCY_HOLD_REASON = "authenticated non-ok dependency" -_SHA256_RE = re.compile(r"[0-9a-f]{64}") -_GIT_OBJECT_RE = re.compile(r"[0-9a-f]{40,64}") - - -class PriorHeldEligibilityError(RuntimeError): - """A historical hold could not be classified without guessing.""" - - -@dataclass(frozen=True, slots=True) -class PriorHeldDisposition: - """One authenticated historical-hold eligibility decision.""" - - cell_id: str - eligible: bool - reason: str - historical_reasons: tuple[str, ...] - historical_observations: tuple[tuple[str, str, str], ...] - target_attempt_ids: tuple[str, ...] - prerequisite_ids: tuple[str, ...] - blocking_prerequisites: tuple[tuple[str, str], ...] - - def as_dict(self) -> dict[str, object]: - return { - "abi": PRIOR_HELD_DISPOSITION_ABI, - "cell_id": self.cell_id, - "eligible": self.eligible, - "reason": self.reason, - "historical_reasons": list(self.historical_reasons), - "historical_observations": [ - { - "reason": reason, - "summary_path": summary_path, - "summary_sha256": summary_sha256, - } - for summary_path, summary_sha256, reason in ( - self.historical_observations - ) - ], - "target_attempt_ids": list(self.target_attempt_ids), - "prerequisite_ids": list(self.prerequisite_ids), - "blocking_prerequisites": [ - {"cell_id": cell_id, "state": state} - for cell_id, state in self.blocking_prerequisites - ], - } - - -def prior_held_history_record( - cell_id: str, - observations: Iterable[Mapping[str, object]], -) -> dict[str, object]: - """Build one complete, deterministic historical-hold record.""" - - if not isinstance(cell_id, str) or not cell_id: - raise PriorHeldEligibilityError( - "historical hold record has an invalid catalog cell identity" - ) - normalized: list[dict[str, str]] = [] - for index, observation in enumerate(observations): - if not isinstance(observation, Mapping) or set(observation) != { - "reason", - "summary_path", - "summary_sha256", - }: - raise PriorHeldEligibilityError( - f"{cell_id} historical hold observation {index} is invalid" - ) - reason = observation.get("reason") - summary_path = observation.get("summary_path") - summary_sha256 = observation.get("summary_sha256") - if ( - not isinstance(reason, str) - or not reason - or not isinstance(summary_path, str) - or not summary_path - or not isinstance(summary_sha256, str) - or _SHA256_RE.fullmatch(summary_sha256) is None - ): - raise PriorHeldEligibilityError( - f"{cell_id} historical hold observation {index} is invalid" - ) - normalized.append( - { - "reason": reason, - "summary_path": summary_path, - "summary_sha256": summary_sha256, - } - ) - if not normalized: - raise PriorHeldEligibilityError(f"{cell_id} historical hold history is empty") - normalized.sort(key=lambda observation: observation["summary_path"]) - summary_paths = [observation["summary_path"] for observation in normalized] - if len(set(summary_paths)) != len(summary_paths): - raise PriorHeldEligibilityError( - f"{cell_id} historical hold history repeats a summary" - ) - return { - "abi": PRIOR_HELD_HISTORY_ABI, - "cell_id": cell_id, - "observations": normalized, - "reasons": [observation["reason"] for observation in normalized], - } - - -def _validated_historical_history( - cell_id: str, - raw_record: object, -) -> tuple[tuple[str, ...], tuple[tuple[str, str, str], ...]]: - if not isinstance(raw_record, Mapping): - raise PriorHeldEligibilityError( - f"{cell_id} historical hold record must be an object" - ) - observations = raw_record.get("observations") - if ( - raw_record.get("abi") != PRIOR_HELD_HISTORY_ABI - or raw_record.get("cell_id") != cell_id - or not isinstance(observations, list) - ): - raise PriorHeldEligibilityError(f"{cell_id} historical hold record is invalid") - rebuilt = prior_held_history_record(cell_id, observations) - if dict(raw_record) != rebuilt: - raise PriorHeldEligibilityError( - f"{cell_id} historical hold record is inconsistent" - ) - reasons = rebuilt["reasons"] - assert isinstance(reasons, list) - normalized = rebuilt["observations"] - assert isinstance(normalized, list) - return ( - tuple(str(reason) for reason in reasons), - tuple( - ( - str(observation["summary_path"]), - str(observation["summary_sha256"]), - str(observation["reason"]), - ) - for observation in normalized - ), - ) - - -def catalog_prerequisite_cells( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return required baseline and agreement/equivalence prerequisites.""" - - candidate_baseline = catalog.validation_baseline_cell(cell) - baseline = ( - candidate_baseline - if validation_baseline_is_required(cell, candidate_baseline) - else None - ) - peers = tuple( - edge.baseline - for edge in incoming_agreement_edges(cell, catalog=catalog) - if edge.required - ) - return tuple( - sorted( - { - prerequisite.cell_id: prerequisite - for prerequisite in ( - *((baseline,) if baseline is not None else ()), - *peers, - ) - }.values(), - key=lambda prerequisite: prerequisite.cell_id, - ) - ) - - -def catalog_prerequisite_closure( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the complete acyclic prerequisite closure for one cell.""" - - resolved: dict[str, CellSpec] = {} - visiting: set[str] = set() - - def visit(candidate: CellSpec) -> None: - if candidate.cell_id in visiting: - raise PriorHeldEligibilityError( - f"report prerequisite cycle reaches {candidate.cell_id!r}" - ) - visiting.add(candidate.cell_id) - try: - for prerequisite in catalog_prerequisite_cells( - candidate, - catalog=catalog, - ): - if prerequisite.cell_id not in resolved: - visit(prerequisite) - resolved[prerequisite.cell_id] = prerequisite - finally: - visiting.remove(candidate.cell_id) - - visit(cell) - return tuple(resolved[cell_id] for cell_id in sorted(resolved)) - - -def _catalog_cells_by_id(catalog: ReportCatalog) -> dict[str, CellSpec]: - cells = catalog.measurement_cells() - by_id = {cell.cell_id: cell for cell in cells} - if len(by_id) != len(cells): - raise PriorHeldEligibilityError( - "report catalog contains duplicate cell identities" - ) - return by_id - - -def _validated_current_state( - store: ArtifactStore, - cell: CellSpec, - *, - expected_source_revision: str | None, - expected_source_tree: str | None, - authenticate_current: Callable[[CellSpec, CurrentRecord], bool] | None, -) -> str: - current = store.load_current(cell.cell_id, missing_ok=True) - if current is None: - return "missing" - try: - validate_measurement(current.result, expected_cell=cell) - except ValueError as error: - raise PriorHeldEligibilityError( - f"{cell.cell_id} current measurement is invalid: {error}" - ) from error - raw_status = current.result.get("status") - try: - status = ResultStatus(str(raw_status)) - except ValueError as error: - raise PriorHeldEligibilityError( - f"{cell.cell_id} current status is unknown" - ) from error - if status is not ResultStatus.OK: - return status.value - if expected_source_revision is not None: - provenance = current.result.get("provenance") - if ( - not isinstance(provenance, Mapping) - or provenance.get("report_source_revision") != expected_source_revision - or provenance.get("report_measured_source_revision") - != expected_source_revision - or ( - expected_source_tree is not None - and ( - provenance.get("report_source_tree") != expected_source_tree - or provenance.get("report_measured_source_tree") - != expected_source_tree - ) - ) - ): - return "source-stale" - if authenticate_current is not None: - authenticated = authenticate_current(cell, current) - if authenticated is not True: - return "unauthenticated" - return ResultStatus.OK.value - - -def classify_prior_held_cells( - store: ArtifactStore, - prior_held_records: Mapping[str, object], - *, - active_scoped_hold_ids: Iterable[str] = (), - catalog: ReportCatalog = REPORT_CATALOG, - expected_source_revision: str | None = None, - expected_source_tree: str | None = None, - authenticate_current: Callable[[CellSpec, CurrentRecord], bool] | None = None, -) -> dict[str, PriorHeldDisposition]: - """Classify historical holds without permanently excluding resolved cells. - - Only histories in which every reason is - :data:`DEPENDENCY_HOLD_REASON` can become eligible. Eligibility also - requires an explicit source-authentication policy, a target that has never - acquired an attempt or current, no active scoped defect hold, and an - immutable, schema-valid ``ok`` current for every transitive baseline or - direct agreement/equivalence prerequisite. - """ - - prior_ids = tuple(prior_held_records) - active_ids = frozenset(active_scoped_hold_ids) - if any( - not isinstance(cell_id, str) or not cell_id - for cell_id in (*prior_ids, *active_ids) - ): - raise PriorHeldEligibilityError( - "hold input contains an invalid catalog cell identity" - ) - if (expected_source_revision is None) != (expected_source_tree is None): - raise PriorHeldEligibilityError( - "expected source revision and tree must be provided together" - ) - if expected_source_revision is not None and ( - not isinstance(expected_source_revision, str) - or _GIT_OBJECT_RE.fullmatch(expected_source_revision) is None - or not isinstance(expected_source_tree, str) - or _GIT_OBJECT_RE.fullmatch(expected_source_tree) is None - ): - raise PriorHeldEligibilityError( - "expected source revision and tree must be Git object identities" - ) - if expected_source_revision is None and authenticate_current is None: - raise PriorHeldEligibilityError( - "current source authentication policy is required" - ) - by_id = _catalog_cells_by_id(catalog) - unknown = sorted((set(prior_ids) | active_ids) - set(by_id)) - if unknown: - raise PriorHeldEligibilityError( - f"hold input contains unknown catalog cells: {unknown}" - ) - - dispositions: dict[str, PriorHeldDisposition] = {} - for cell_id in sorted(prior_ids): - cell = by_id[cell_id] - historical_reasons, historical_observations = _validated_historical_history( - cell_id, - prior_held_records[cell_id], - ) - with store.cell_lock(cell_id): - current = store.load_current(cell_id, missing_ok=True) - attempt_ids = store.cell_attempt_ids(cell_id) - if current is not None and current.attempt_id not in attempt_ids: - raise PriorHeldEligibilityError( - f"{cell_id} current is absent from its attempt inventory" - ) - prerequisites = catalog_prerequisite_closure(cell, catalog=catalog) - prerequisite_ids = tuple(prerequisite.cell_id for prerequisite in prerequisites) - - if attempt_ids or current is not None: - dispositions[cell_id] = PriorHeldDisposition( - cell_id, - False, - "target-already-attempted", - historical_reasons, - historical_observations, - attempt_ids, - prerequisite_ids, - (), - ) - continue - if cell_id in active_ids: - dispositions[cell_id] = PriorHeldDisposition( - cell_id, - False, - "active-scoped-defect-hold", - historical_reasons, - historical_observations, - (), - prerequisite_ids, - (), - ) - continue - if any(reason != DEPENDENCY_HOLD_REASON for reason in historical_reasons): - dispositions[cell_id] = PriorHeldDisposition( - cell_id, - False, - "historical-hold-not-dependency", - historical_reasons, - historical_observations, - (), - prerequisite_ids, - (), - ) - continue - - blocking: list[tuple[str, str]] = [] - for prerequisite in prerequisites: - if prerequisite.cell_id in active_ids: - blocking.append( - ( - prerequisite.cell_id, - "active-scoped-defect-hold", - ) - ) - continue - state = _validated_current_state( - store, - prerequisite, - expected_source_revision=expected_source_revision, - expected_source_tree=expected_source_tree, - authenticate_current=authenticate_current, - ) - if state != ResultStatus.OK.value: - blocking.append((prerequisite.cell_id, state)) - dispositions[cell_id] = PriorHeldDisposition( - cell_id, - not blocking, - "eligible" if not blocking else "prerequisite-not-ok", - historical_reasons, - historical_observations, - (), - prerequisite_ids, - tuple(blocking), - ) - return dispositions - - -def active_prior_held_ids( - store: ArtifactStore, - prior_held_records: Mapping[str, object], - *, - active_scoped_hold_ids: Iterable[str] = (), - catalog: ReportCatalog = REPORT_CATALOG, - expected_source_revision: str | None = None, - expected_source_tree: str | None = None, - authenticate_current: Callable[[CellSpec, CurrentRecord], bool] | None = None, -) -> frozenset[str]: - """Return only historical holds that are still fail-closed.""" - - dispositions = classify_prior_held_cells( - store, - prior_held_records, - active_scoped_hold_ids=active_scoped_hold_ids, - catalog=catalog, - expected_source_revision=expected_source_revision, - expected_source_tree=expected_source_tree, - authenticate_current=authenticate_current, - ) - return frozenset( - cell_id - for cell_id, disposition in dispositions.items() - if not disposition.eligible - ) - - -__all__ = [ - "DEPENDENCY_HOLD_REASON", - "PRIOR_HELD_DISPOSITION_ABI", - "PRIOR_HELD_HISTORY_ABI", - "PriorHeldDisposition", - "PriorHeldEligibilityError", - "active_prior_held_ids", - "catalog_prerequisite_cells", - "catalog_prerequisite_closure", - "classify_prior_held_cells", - "prior_held_history_record", -] diff --git a/pyamplicol/tools/performance_report/campaign_policy.py b/pyamplicol/tools/performance_report/campaign_policy.py deleted file mode 100644 index ddd2de7552..0000000000 --- a/pyamplicol/tools/performance_report/campaign_policy.py +++ /dev/null @@ -1,1505 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Profile-bound completion and resource policies for report campaigns.""" - -from __future__ import annotations - -import hashlib -import json -import math -import re -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from enum import StrEnum - -try: - from tools.ci.memory_watchdog import ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON, - DARWIN_PHYSICAL_FOOTPRINT_PROBE_REASON, - MEMORY_PROBE_REASON, - RSS_LIMIT_REASON, - ) -except ModuleNotFoundError as error: - if error.name not in {"tools", "tools.ci", "tools.ci.memory_watchdog"}: - raise - from ._memory_watchdog import ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON, - DARWIN_PHYSICAL_FOOTPRINT_PROBE_REASON, - MEMORY_PROBE_REASON, - RSS_LIMIT_REASON, - ) - -from .cache import empty_measurement -from .models import Accuracy, CellSpec, ExecutionMode, ResultStatus, Workload -from .resources import PROCESS_TREE_MEMORY_METRIC_ABI -from .source_identity import SOURCE_IDENTITY_SCHEMA, ReportSourceIdentity -from .worker_harness import ( - WORKER_HARNESS_PROVENANCE_FIELD, - WorkerHarnessError, - require_worker_harness_identity, -) - -CAMPAIGN_POLICY_SCHEMA = "pyamplicol-report-campaign-policy-v1" -LEGACY_POLICY_CENSOR_ABI = "pyamplicol-report-policy-censor-v2" -POLICY_CENSOR_ABI = "pyamplicol-report-policy-censor-v3" -RESOURCE_FRONTIER_ABI = "pyamplicol-report-resource-frontier-v1" -GENERATION_PHASE_EVIDENCE_ABI = "pyamplicol-report-generation-phase-evidence-v1" -WORKER_PHASE_STATE_ABI = "pyamplicol-report-worker-phase-state-v1" -STRICT_POLICY_NAME = "strict-complete-v1" -MACBOOK_M3_POLICY_NAME = "macbook-m3-v1" -MACBOOK_M3_Z_TABLE_F_POLICY_NAME = "macbook-m3-z-table-f-v1" -X86_EPYC_POLICY_NAME = "x86-epyc-v1" -MACBOOK_M3_PROFILE = "macbook_M3" -X86_EPYC_PROFILE = "x86_EPYC" -MACBOOK_M3_WORKERS = 1 -MACBOOK_M3_CELL_CORES = 1 -MACBOOK_M3_TARGET_RUNTIME_SECONDS = 5.0 -MACBOOK_M3_MEMORY_LIMIT_BYTES = 30_000_000_000 -MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS = 60.0 * 60.0 -X86_EPYC_LEGACY_WORKERS = 10 -X86_EPYC_WORKERS = 25 -X86_EPYC_CELL_CORES = 1 -X86_EPYC_TARGET_RUNTIME_SECONDS = 5.0 -X86_EPYC_GENERATION_LIMIT_SECONDS = 2.0 * 60.0 * 60.0 -X86_EPYC_LEGACY_MEMORY_LIMIT_BYTES = 100_000_000_000 -X86_EPYC_MEMORY_LIMIT_BYTES = 80_000_000_000 -X86_EPYC_NATIVE_COMPILER_SLOTS = 4 - -_SHA256_RE = re.compile(r"^[0-9a-f]{64}$") -_SOURCE_FIELDS = frozenset( - { - "report_source_identity_schema", - "report_source_revision", - "report_source_tree", - "report_measured_source_revision", - "report_measured_source_tree", - "report_source_clean", - } -) -_STUDY_CONTRACT_BINDING_FIELDS = frozenset( - { - "abi", - "study_id", - "study_contract_sha256", - } -) -_LEGACY_CENSOR_FIELDS = frozenset( - { - "abi", - "policy", - "profile", - "cell_id", - "kind", - "generation_limit_seconds", - "memory_limit_bytes", - "observed_generation_seconds", - "observed_rss_bytes", - "phase_evidence", - "dependencies", - "frontier", - } -) -_CENSOR_FIELDS = _LEGACY_CENSOR_FIELDS | { - "observed_guard_bytes", - "memory_metric_abi", - "memory_limit_reason", -} -_MEMORY_RESOURCE_FIELDS = frozenset( - { - "memory_metric_abi", - "current_physical_footprint_bytes", - "peak_physical_footprint_bytes", - "current_guard_bytes", - "peak_guard_bytes", - "memory_limit_bytes", - "memory_limit_reason", - "memory_probe_reason", - } -) -_MEMORY_LIMIT_REASONS = frozenset( - { - RSS_LIMIT_REASON, - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON, - } -) -_MEMORY_PROBE_REASONS = frozenset( - { - MEMORY_PROBE_REASON, - DARWIN_PHYSICAL_FOOTPRINT_PROBE_REASON, - } -) -_DEPENDENCY_FIELDS = frozenset({"cell_id", "status", "censor_sha256"}) -_FRONTIER_FIELDS = frozenset({"abi", "lane", "root"}) -_FRONTIER_LANE_FIELDS = frozenset( - { - "process_key", - "execution_mode", - "model", - "accuracy", - "backend", - "jit_optimization_level", - "workload", - "variant", - } -) -_FRONTIER_ROOT_FIELDS = frozenset( - { - "cell_id", - "n_final", - "kind", - "status", - "censor_sha256", - } -) -_GENERATION_PHASE_FIELDS = frozenset( - { - "abi", - "phase_state_abi", - "configured_timeout_seconds", - "supervisor_reason", - "authenticated", - "run_id", - "worker_pid", - "final_sequence", - "final_phase", - "generation_started_monotonic_ns", - "generation_finished_monotonic_ns", - "generation_elapsed_seconds", - "final_state_sha256", - "error", - } -) - - -class CampaignPolicyError(ValueError): - """A report campaign or terminal measurement violates its bound policy.""" - - -class PolicyCensorKind(StrEnum): - GENERATION_LIMIT = "generation_limit" - MEMORY_LIMIT = "memory_limit" - WORKER_TIMEOUT = "worker_timeout" - PROFILING_TIMEOUT = "profiling_timeout" - VALIDATION_TIMEOUT = "validation_timeout" - DEPENDENCY = "dependency" - RESOURCE_FRONTIER = "resource_frontier" - - -class PolicyMeasurementState(StrEnum): - SUCCESS = "success" - GENERATION_LIMIT = "generation_limit" - MEMORY_LIMIT = "memory_limit" - WORKER_TIMEOUT = "worker_timeout" - PROFILING_TIMEOUT = "profiling_timeout" - VALIDATION_TIMEOUT = "validation_timeout" - DEPENDENCY = "dependency" - RESOURCE_FRONTIER = "resource_frontier" - - -@dataclass(frozen=True, slots=True) -class CampaignPolicy: - name: str - allow_terminal_censors: bool - workers: int | None = None - cell_cores: int | None = None - target_runtime_seconds: float = X86_EPYC_TARGET_RUNTIME_SECONDS - generation_limit_seconds: float | None = None - memory_limit_bytes: int | None = None - require_symbolica_parallel: bool = False - generation_limit_all_cells: bool = False - - def as_manifest(self) -> dict[str, object]: - return { - "schema": CAMPAIGN_POLICY_SCHEMA, - "name": self.name, - "allow_terminal_censors": self.allow_terminal_censors, - "workers": self.workers, - "cell_cores": self.cell_cores, - "target_runtime_seconds": self.target_runtime_seconds, - "generation_limit_seconds": self.generation_limit_seconds, - "memory_limit_bytes": self.memory_limit_bytes, - "generation_limit_exemptions": ( - "none" - if self.generation_limit_all_cells - or self.generation_limit_seconds is None - else ( - "all original-AmpliCol cells and pyAmpliCol " - "compiled/recurrence LC selected-flow cells" - ) - ), - "require_symbolica_parallel": self.require_symbolica_parallel, - } - - -STRICT_POLICY = CampaignPolicy( - name=STRICT_POLICY_NAME, - allow_terminal_censors=False, -) -MACBOOK_M3_POLICY = CampaignPolicy( - name=MACBOOK_M3_POLICY_NAME, - allow_terminal_censors=True, - workers=MACBOOK_M3_WORKERS, - cell_cores=MACBOOK_M3_CELL_CORES, - target_runtime_seconds=MACBOOK_M3_TARGET_RUNTIME_SECONDS, - memory_limit_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, -) -MACBOOK_M3_Z_TABLE_F_POLICY = CampaignPolicy( - name=MACBOOK_M3_Z_TABLE_F_POLICY_NAME, - allow_terminal_censors=True, - workers=MACBOOK_M3_WORKERS, - cell_cores=MACBOOK_M3_CELL_CORES, - target_runtime_seconds=MACBOOK_M3_TARGET_RUNTIME_SECONDS, - generation_limit_seconds=(MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS), - memory_limit_bytes=MACBOOK_M3_MEMORY_LIMIT_BYTES, - generation_limit_all_cells=True, -) -X86_EPYC_POLICY = CampaignPolicy( - name=X86_EPYC_POLICY_NAME, - allow_terminal_censors=True, - workers=X86_EPYC_WORKERS, - cell_cores=X86_EPYC_CELL_CORES, - target_runtime_seconds=X86_EPYC_TARGET_RUNTIME_SECONDS, - generation_limit_seconds=X86_EPYC_GENERATION_LIMIT_SECONDS, - memory_limit_bytes=X86_EPYC_MEMORY_LIMIT_BYTES, - require_symbolica_parallel=True, -) - - -def campaign_policy(name: str) -> CampaignPolicy: - if name == STRICT_POLICY_NAME: - return STRICT_POLICY - if name == MACBOOK_M3_POLICY_NAME: - return MACBOOK_M3_POLICY - if name == MACBOOK_M3_Z_TABLE_F_POLICY_NAME: - return MACBOOK_M3_Z_TABLE_F_POLICY - if name == X86_EPYC_POLICY_NAME: - return X86_EPYC_POLICY - raise CampaignPolicyError(f"unsupported report campaign policy {name!r}") - - -def default_campaign_policy(profile: str) -> CampaignPolicy: - if profile == MACBOOK_M3_PROFILE: - return MACBOOK_M3_POLICY - if profile == X86_EPYC_PROFILE: - return X86_EPYC_POLICY - return STRICT_POLICY - - -def validate_policy_profile(policy: CampaignPolicy, profile: str) -> None: - macbook_policies = { - MACBOOK_M3_POLICY, - MACBOOK_M3_Z_TABLE_F_POLICY, - } - if policy in macbook_policies and profile != MACBOOK_M3_PROFILE: - raise CampaignPolicyError( - f"{policy.name} is reserved for profile {MACBOOK_M3_PROFILE!r}" - ) - if policy is X86_EPYC_POLICY and profile != X86_EPYC_PROFILE: - raise CampaignPolicyError( - f"{X86_EPYC_POLICY_NAME} is reserved for profile {X86_EPYC_PROFILE!r}" - ) - if profile == X86_EPYC_PROFILE and policy is not X86_EPYC_POLICY: - raise CampaignPolicyError( - f"profile {X86_EPYC_PROFILE!r} requires {X86_EPYC_POLICY_NAME}" - ) - if profile == MACBOOK_M3_PROFILE and policy not in macbook_policies: - raise CampaignPolicyError( - f"profile {MACBOOK_M3_PROFILE!r} requires a MacBook M3 policy" - ) - - -def policy_from_manifest(value: object, *, profile: str) -> CampaignPolicy: - if not isinstance(value, Mapping): - raise CampaignPolicyError("workspace campaign_policy must be an object") - name = value.get("name") - if not isinstance(name, str): - raise CampaignPolicyError("workspace campaign_policy has no name") - policy = campaign_policy(name) - accepted_manifests = [policy.as_manifest()] - if policy is X86_EPYC_POLICY: - legacy_manifest = policy.as_manifest() - legacy_manifest["workers"] = X86_EPYC_LEGACY_WORKERS - legacy_manifest["memory_limit_bytes"] = X86_EPYC_LEGACY_MEMORY_LIMIT_BYTES - accepted_manifests.append(legacy_manifest) - if dict(value) not in accepted_manifests: - raise CampaignPolicyError( - "workspace campaign_policy differs from its canonical definition" - ) - validate_policy_profile(policy, profile) - return policy - - -def generation_limit_exempt(cell: CellSpec) -> bool: - measurement = cell.measurement - return measurement.execution_mode is ExecutionMode.AMPLICOL or ( - measurement.execution_mode in {ExecutionMode.COMPILED, ExecutionMode.RECURRENCE} - and measurement.accuracy is Accuracy.LC - and cell.workload is Workload.SELECTED_FLOW - ) - - -def generation_limit_for_cell( - policy: CampaignPolicy, - cell: CellSpec, -) -> float | None: - if policy.generation_limit_seconds is None: - return None - if policy.generation_limit_all_cells: - return policy.generation_limit_seconds - if generation_limit_exempt(cell): - return None - return policy.generation_limit_seconds - - -def validate_campaign_settings(policy: CampaignPolicy, settings: object) -> None: - """Reject settings that weaken or misstate an architecture policy.""" - - if policy is STRICT_POLICY: - return - checks = ( - (getattr(settings, "workers", None), policy.workers, "workers"), - (getattr(settings, "cell_cores", None), policy.cell_cores, "cell_cores"), - ( - getattr(settings, "target_runtime_seconds", None), - policy.target_runtime_seconds, - "target_runtime_seconds", - ), - ( - getattr(settings, "max_rss_bytes", None), - policy.memory_limit_bytes, - "max_rss_bytes", - ), - ( - getattr(settings, "generation_time_limit_seconds", None), - None, - "generation_time_limit_seconds", - ), - (getattr(settings, "timeout_seconds", None), None, "timeout_seconds"), - ( - getattr(settings, "campaign_max_rss_bytes", None), - None, - "campaign_max_rss_bytes", - ), - ( - getattr(settings, "allow_symbolica_parallel", None), - policy.require_symbolica_parallel, - "allow_symbolica_parallel", - ), - ) - mismatches = [ - f"{field}={observed!r}, expected {expected!r}" - for observed, expected, field in checks - if observed != expected - ] - if mismatches: - raise CampaignPolicyError( - f"{policy.name} settings differ: " + "; ".join(mismatches) - ) - - -def _canonical_digest(value: object) -> str: - return hashlib.sha256( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _finite_number(value: object, field: str) -> float: - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise CampaignPolicyError(f"{field} must be a finite number") - number = float(value) - if not math.isfinite(number): - raise CampaignPolicyError(f"{field} must be finite") - return number - - -def _source_provenance( - source_identity: ReportSourceIdentity | Mapping[str, object], -) -> dict[str, object]: - provenance = ( - source_identity.provenance() - if isinstance(source_identity, ReportSourceIdentity) - else dict(source_identity) - ) - if set(provenance) != _SOURCE_FIELDS: - raise CampaignPolicyError("policy censor source identity is malformed") - return provenance - - -def dependency_reference( - cell_id: str, - measurement: Mapping[str, object], -) -> dict[str, object]: - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - raise CampaignPolicyError(f"dependency {cell_id!r} has no policy provenance") - digest = provenance.get("policy_censor_sha256") - if not isinstance(digest, str) or _SHA256_RE.fullmatch(digest) is None: - raise CampaignPolicyError(f"dependency {cell_id!r} has no policy-censor digest") - return { - "cell_id": cell_id, - "status": str(measurement.get("status")), - "censor_sha256": digest, - } - - -def resource_lane_identity(cell: CellSpec) -> dict[str, object]: - """Return the canonical multiplicity-independent resource lane.""" - - measurement = cell.measurement - return { - "process_key": cell.process_key, - "execution_mode": measurement.execution_mode.value, - "model": None if measurement.model is None else measurement.model.value, - "accuracy": measurement.accuracy.value, - "backend": measurement.backend, - "jit_optimization_level": measurement.jit_optimization_level, - "workload": cell.workload.value, - "variant": cell.variant, - } - - -def resource_frontier_reference( - cell: CellSpec, - source_cell: CellSpec, - source_measurement: Mapping[str, object], -) -> dict[str, object]: - """Bind a higher cell directly to its first lower hard-resource censor.""" - - if source_cell.n_final >= cell.n_final or resource_lane_identity( - source_cell - ) != resource_lane_identity(cell): - raise CampaignPolicyError( - "resource-frontier source is not lower in the same lane" - ) - provenance = source_measurement.get("provenance") - censor = ( - provenance.get("policy_censor") if isinstance(provenance, Mapping) else None - ) - digest = ( - provenance.get("policy_censor_sha256") - if isinstance(provenance, Mapping) - else None - ) - if ( - not isinstance(censor, Mapping) - or censor.get("kind") - not in { - PolicyCensorKind.GENERATION_LIMIT.value, - PolicyCensorKind.MEMORY_LIMIT.value, - } - or source_measurement.get("status") - not in { - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - } - or not isinstance(digest, str) - or _SHA256_RE.fullmatch(digest) is None - ): - raise CampaignPolicyError( - "resource-frontier source is not a direct hard-resource censor" - ) - return { - "abi": RESOURCE_FRONTIER_ABI, - "lane": resource_lane_identity(cell), - "root": { - "cell_id": source_cell.cell_id, - "n_final": source_cell.n_final, - "kind": censor["kind"], - "status": source_measurement["status"], - "censor_sha256": digest, - }, - } - - -def policy_censor_measurement( - policy: CampaignPolicy, - profile: str, - cell: CellSpec, - *, - kind: PolicyCensorKind, - source_identity: ReportSourceIdentity | Mapping[str, object], - resources: Mapping[str, object] | None, - observed_generation_seconds: float | None = None, - observed_rss_bytes: int | None = None, - observed_guard_bytes: int | None = None, - memory_metric_abi: str | None = None, - memory_limit_reason: str | None = None, - phase_evidence: Mapping[str, object] | None = None, - dependencies: Sequence[Mapping[str, object]] = (), - frontier: Mapping[str, object] | None = None, -) -> dict[str, object]: - if not policy.allow_terminal_censors: - raise CampaignPolicyError( - "terminal censors require an architecture campaign policy" - ) - validate_policy_profile(policy, profile) - if kind is PolicyCensorKind.GENERATION_LIMIT: - status = ResultStatus.TIMEOUT - elif kind is PolicyCensorKind.MEMORY_LIMIT: - status = ResultStatus.MEMORY_LIMIT - elif kind in { - PolicyCensorKind.DEPENDENCY, - PolicyCensorKind.RESOURCE_FRONTIER, - }: - status = ResultStatus.SKIP - else: # pragma: no cover - exhaustive StrEnum defense - raise CampaignPolicyError(f"unsupported policy censor kind {kind!r}") - legacy_rss_memory_censor = ( - kind is PolicyCensorKind.MEMORY_LIMIT - and observed_guard_bytes is None - and memory_metric_abi is None - and memory_limit_reason is None - ) - record: dict[str, object] = { - "abi": ( - LEGACY_POLICY_CENSOR_ABI if legacy_rss_memory_censor else POLICY_CENSOR_ABI - ), - "policy": policy.name, - "profile": profile, - "cell_id": cell.cell_id, - "kind": kind.value, - "generation_limit_seconds": policy.generation_limit_seconds, - "memory_limit_bytes": policy.memory_limit_bytes, - "observed_generation_seconds": observed_generation_seconds, - "observed_rss_bytes": observed_rss_bytes, - "phase_evidence": (None if phase_evidence is None else dict(phase_evidence)), - "dependencies": [dict(item) for item in dependencies], - "frontier": None if frontier is None else dict(frontier), - } - if not legacy_rss_memory_censor: - record.update( - { - "observed_guard_bytes": observed_guard_bytes, - "memory_metric_abi": memory_metric_abi, - "memory_limit_reason": memory_limit_reason, - } - ) - provenance = { - **_source_provenance(source_identity), - "policy_censor": record, - "policy_censor_sha256": _canonical_digest(record), - } - result = empty_measurement() - result.update( - { - "status": status.value, - "resources": None if resources is None else dict(resources), - "provenance": provenance, - "failure": { - "kind": "ReportPolicyCensor", - "message": ( - ( - "process generation exceeded its authenticated " - f"{float(policy.generation_limit_seconds or 0):g}-second " - "limit" - ) - if kind is PolicyCensorKind.GENERATION_LIMIT - else ( - "worker process tree exceeded " - f"{int(policy.memory_limit_bytes or 0) / 1_000_000_000:g} " - "GB under its authenticated memory guard" - if kind is PolicyCensorKind.MEMORY_LIMIT - else ( - "higher multiplicity omitted after a lower-multiplicity " - "resource ceiling" - if kind is PolicyCensorKind.RESOURCE_FRONTIER - else ( - "required numerical-agreement dependency was censored" - ) - ) - ) - ), - }, - } - ) - validate_policy_measurement( - policy, - profile, - cell, - result, - expected_source_revision=str(provenance["report_source_revision"]), - expected_source_tree=str(provenance["report_source_tree"]), - ) - return result - - -def _policy_record( - policy: CampaignPolicy, - profile: str, - cell: CellSpec, - measurement: Mapping[str, object], - *, - expected_source_revision: str, - expected_source_tree: str | None, -) -> tuple[PolicyCensorKind, Mapping[str, object]]: - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - raise CampaignPolicyError("terminal measurement has no provenance") - base_fields = _SOURCE_FIELDS | { - "policy_censor", - "policy_censor_sha256", - } - provenance_fields = set(provenance) - if policy is MACBOOK_M3_Z_TABLE_F_POLICY and "study_contract" in provenance: - if provenance_fields != base_fields | { - "study_contract", - WORKER_HARNESS_PROVENANCE_FIELD, - }: - raise CampaignPolicyError( - "terminal measurement provenance is not canonical" - ) - study_contract = provenance.get("study_contract") - if ( - not isinstance(study_contract, Mapping) - or set(study_contract) != _STUDY_CONTRACT_BINDING_FIELDS - or study_contract.get("abi") != "pyamplicol-z-table-f-attempt-binding-v1" - or study_contract.get("study_id") != "macbook-m3-z-table-f" - or not isinstance( - study_contract.get("study_contract_sha256"), - str, - ) - or _SHA256_RE.fullmatch(str(study_contract["study_contract_sha256"])) - is None - ): - raise CampaignPolicyError( - "terminal measurement study contract is not canonical" - ) - try: - require_worker_harness_identity( - measurement, - expected_measured_revision=expected_source_revision, - expected_measured_tree=expected_source_tree, - ) - except WorkerHarnessError as error: - raise CampaignPolicyError(str(error)) from error - elif provenance_fields != base_fields: - raise CampaignPolicyError("terminal measurement provenance is not canonical") - if ( - provenance.get("report_source_identity_schema") != SOURCE_IDENTITY_SCHEMA - or provenance.get("report_source_revision") != expected_source_revision - or provenance.get("report_measured_source_revision") != expected_source_revision - or provenance.get("report_source_clean") is not True - ): - raise CampaignPolicyError("terminal measurement source identity does not match") - if expected_source_tree is not None and ( - provenance.get("report_source_tree") != expected_source_tree - or provenance.get("report_measured_source_tree") != expected_source_tree - ): - raise CampaignPolicyError("terminal measurement source tree does not match") - raw = provenance.get("policy_censor") - if not isinstance(raw, Mapping): - raise CampaignPolicyError("policy_censor fields do not match the ABI") - censor_abi = raw.get("abi") - expected_fields = ( - _LEGACY_CENSOR_FIELDS - if censor_abi == LEGACY_POLICY_CENSOR_ABI - else _CENSOR_FIELDS - ) - if set(raw) != expected_fields: - raise CampaignPolicyError("policy_censor fields do not match the ABI") - digest = provenance.get("policy_censor_sha256") - if digest != _canonical_digest(raw): - raise CampaignPolicyError("policy_censor_sha256 does not match") - try: - kind = PolicyCensorKind(str(raw.get("kind"))) - except ValueError as error: - raise CampaignPolicyError("policy_censor kind is unsupported") from error - if policy is MACBOOK_M3_Z_TABLE_F_POLICY and censor_abi != POLICY_CENSOR_ABI: - raise CampaignPolicyError( - "the Z-table F policy requires policy-censor v3 evidence" - ) - if ( - censor_abi not in {LEGACY_POLICY_CENSOR_ABI, POLICY_CENSOR_ABI} - or raw.get("policy") != policy.name - or raw.get("profile") != profile - or raw.get("cell_id") != cell.cell_id - or raw.get("generation_limit_seconds") != policy.generation_limit_seconds - or raw.get("memory_limit_bytes") != policy.memory_limit_bytes - ): - raise CampaignPolicyError("policy_censor identity or limits differ") - return kind, raw - - -def _optional_nonnegative_integer(value: object, field: str) -> int | None: - if value is None: - return None - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise CampaignPolicyError(f"{field} is not a non-negative integer") - return value - - -def _validate_memory_metric( - resources: Mapping[str, object], - policy: CampaignPolicy, -) -> None: - metric_abi = resources.get("memory_metric_abi") - present_fields = _MEMORY_RESOURCE_FIELDS.intersection(resources) - if metric_abi is None: - if present_fields: - raise CampaignPolicyError( - "memory metric fields require an authenticated metric ABI" - ) - return - if ( - metric_abi != PROCESS_TREE_MEMORY_METRIC_ABI - or present_fields != _MEMORY_RESOURCE_FIELDS - ): - raise CampaignPolicyError("memory metric ABI or fields are unsupported") - - current_rss = _optional_nonnegative_integer( - resources.get("current_rss_bytes"), - "current_rss_bytes", - ) - peak_rss = _optional_nonnegative_integer( - resources.get("peak_rss_bytes"), - "peak_rss_bytes", - ) - current_physical = _optional_nonnegative_integer( - resources.get("current_physical_footprint_bytes"), - "current_physical_footprint_bytes", - ) - peak_physical = _optional_nonnegative_integer( - resources.get("peak_physical_footprint_bytes"), - "peak_physical_footprint_bytes", - ) - current_guard = _optional_nonnegative_integer( - resources.get("current_guard_bytes"), - "current_guard_bytes", - ) - peak_guard = _optional_nonnegative_integer( - resources.get("peak_guard_bytes"), - "peak_guard_bytes", - ) - if current_rss is None or peak_rss is None: - raise CampaignPolicyError("memory metric has incomplete RSS evidence") - expected_current_guard = max( - current_rss, - current_physical if current_physical is not None else current_rss, - ) - expected_peak_guard = max( - peak_rss, - peak_physical if peak_physical is not None else peak_rss, - ) - if current_guard != expected_current_guard or peak_guard != expected_peak_guard: - raise CampaignPolicyError("memory guard does not match RSS/footprint maxima") - - memory_limit = resources.get("memory_limit_bytes") - assert policy.memory_limit_bytes is not None - if ( - isinstance(memory_limit, bool) - or not isinstance(memory_limit, int) - or memory_limit != policy.memory_limit_bytes - ): - raise CampaignPolicyError("memory metric limit differs from policy") - reason = resources.get("memory_limit_reason") - if reason is not None and reason not in _MEMORY_LIMIT_REASONS: - raise CampaignPolicyError("memory metric reason is unsupported") - probe_reason = resources.get("memory_probe_reason") - if probe_reason is not None: - if probe_reason not in _MEMORY_PROBE_REASONS: - raise CampaignPolicyError("memory probe reason is unsupported") - raise CampaignPolicyError( - "policy measurement has incomplete memory observations" - ) - if reason == DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON and ( - current_physical is None - or current_physical < current_rss - or current_guard <= memory_limit - ): - raise CampaignPolicyError( - "physical-footprint limit reason contradicts current evidence" - ) - if reason == RSS_LIMIT_REASON and ( - current_rss - < (current_physical if current_physical is not None else current_rss) - or current_guard <= memory_limit - ): - raise CampaignPolicyError("RSS limit reason contradicts current evidence") - - -def _validate_resources( - measurement: Mapping[str, object], - policy: CampaignPolicy, - *, - allow_pinned_orphan_unavailable_resources: bool = False, -) -> Mapping[str, object]: - resources = measurement.get("resources") - if not isinstance(resources, Mapping): - raise CampaignPolicyError( - "architecture-policy measurement has no resource evidence" - ) - if allow_pinned_orphan_unavailable_resources and dict(resources) == { - "monitor": "external-cell-supervisor", - "peak_rss_gib": None, - }: - if policy.memory_limit_bytes is None: - raise CampaignPolicyError("architecture policy has no memory ceiling") - return resources - peak = resources.get("peak_rss_bytes") - if ( - resources.get("available") is not True - or resources.get("probe_error") is not None - or isinstance(peak, bool) - or not isinstance(peak, int) - or peak < 0 - ): - raise CampaignPolicyError( - "architecture-policy resource monitoring is unavailable or incomplete" - ) - if policy.memory_limit_bytes is None: - raise CampaignPolicyError("architecture policy has no memory ceiling") - _validate_memory_metric(resources, policy) - if policy is MACBOOK_M3_Z_TABLE_F_POLICY: - current_physical = resources.get("current_physical_footprint_bytes") - peak_physical = resources.get("peak_physical_footprint_bytes") - if ( - resources.get("memory_metric_abi") != PROCESS_TREE_MEMORY_METRIC_ABI - or isinstance(current_physical, bool) - or not isinstance(current_physical, int) - or current_physical < 0 - or isinstance(peak_physical, bool) - or not isinstance(peak_physical, int) - or peak_physical < 0 - ): - raise CampaignPolicyError( - "the Z-table F policy requires non-null authenticated " - "current and peak Darwin physical-footprint evidence" - ) - reason = resources.get("memory_limit_reason") - current_rss = resources.get("current_rss_bytes") - assert isinstance(current_rss, int) and not isinstance(current_rss, bool) - if reason is not None: - expected_reason = ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON - if current_physical >= current_rss - else RSS_LIMIT_REASON - ) - if reason != expected_reason: - raise CampaignPolicyError( - "the Z-table F memory-limit reason does not match the " - "authenticated Darwin guard" - ) - return resources - - -def _validate_generation_phase( - value: object, - policy: CampaignPolicy, - *, - expected_reason: str, -) -> Mapping[str, object]: - if not isinstance(value, Mapping) or set(value) != _GENERATION_PHASE_FIELDS: - raise CampaignPolicyError( - "generation-phase evidence fields do not match the ABI" - ) - assert policy.generation_limit_seconds is not None - run_id = value.get("run_id") - worker_pid = value.get("worker_pid") - sequence = value.get("final_sequence") - started = value.get("generation_started_monotonic_ns") - finished = value.get("generation_finished_monotonic_ns") - elapsed = _finite_number( - value.get("generation_elapsed_seconds"), - "generation_phase.generation_elapsed_seconds", - ) - state_digest = value.get("final_state_sha256") - if expected_reason == "generation_timeout": - boundary_valid = ( - sequence == 1 - and value.get("final_phase") == "generation" - and isinstance(started, int) - and not isinstance(started, bool) - and started > 0 - and finished is None - ) or ( - sequence == 0 - and value.get("final_phase") == "pre-generation" - and started is None - and finished is None - ) - else: - boundary_valid = ( - sequence == 2 - and value.get("final_phase") == "post-generation" - and isinstance(started, int) - and not isinstance(started, bool) - and started > 0 - and isinstance(finished, int) - and not isinstance(finished, bool) - and finished >= started - ) - if ( - value.get("abi") != GENERATION_PHASE_EVIDENCE_ABI - or value.get("phase_state_abi") != WORKER_PHASE_STATE_ABI - or value.get("configured_timeout_seconds") != policy.generation_limit_seconds - or value.get("supervisor_reason") != expected_reason - or value.get("authenticated") is not True - or not isinstance(run_id, str) - or not run_id - or isinstance(worker_pid, bool) - or not isinstance(worker_pid, int) - or worker_pid <= 0 - or isinstance(sequence, bool) - or not isinstance(sequence, int) - or not boundary_valid - or not isinstance(state_digest, str) - or _SHA256_RE.fullmatch(state_digest) is None - or value.get("error") is not None - ): - raise CampaignPolicyError( - "generation-phase evidence is unauthenticated or inconsistent" - ) - if expected_reason == "generation_timeout": - if elapsed < policy.generation_limit_seconds: - raise CampaignPolicyError( - "generation-phase evidence did not reach its ceiling" - ) - elif elapsed > policy.generation_limit_seconds: - raise CampaignPolicyError( - "successful generation-phase evidence exceeded its ceiling" - ) - return value - - -def validate_policy_measurement( - policy: CampaignPolicy, - profile: str, - cell: CellSpec, - measurement: Mapping[str, object], - *, - expected_source_revision: str, - expected_source_tree: str | None = None, - allow_pinned_orphan_unavailable_resources: bool = False, -) -> PolicyMeasurementState: - """Validate one successful or policy-terminal current measurement.""" - - validate_policy_profile(policy, profile) - status = str(measurement.get("status")) - if status == ResultStatus.OK.value: - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - raise CampaignPolicyError("successful measurement has no provenance") - if ( - provenance.get("report_source_identity_schema") != SOURCE_IDENTITY_SCHEMA - or provenance.get("report_source_revision") != expected_source_revision - or provenance.get("report_measured_source_revision") - != expected_source_revision - or provenance.get("report_source_clean") is not True - ): - raise CampaignPolicyError( - "successful measurement source identity does not match" - ) - if expected_source_tree is not None and ( - provenance.get("report_source_tree") != expected_source_tree - or provenance.get("report_measured_source_tree") != expected_source_tree - ): - raise CampaignPolicyError( - "successful measurement source tree does not match" - ) - if policy is MACBOOK_M3_Z_TABLE_F_POLICY: - try: - require_worker_harness_identity( - measurement, - expected_measured_revision=expected_source_revision, - expected_measured_tree=expected_source_tree, - ) - except WorkerHarnessError as error: - raise CampaignPolicyError(str(error)) from error - if policy.allow_terminal_censors: - resources = _validate_resources( - measurement, - policy, - allow_pinned_orphan_unavailable_resources=( - allow_pinned_orphan_unavailable_resources - ), - ) - peak = ( - resources.get("peak_guard_bytes") - if resources.get("memory_metric_abi") is not None - else resources.get("peak_rss_bytes") - ) - if peak is not None: - assert isinstance(peak, int) and not isinstance(peak, bool) - assert policy.memory_limit_bytes is not None - if peak > policy.memory_limit_bytes: - raise CampaignPolicyError( - "successful architecture measurement exceeded its " - "memory ceiling" - ) - generation = _finite_number( - measurement.get("generation_seconds"), - "generation_seconds", - ) - limit = generation_limit_for_cell(policy, cell) - if limit is not None and generation > limit: - raise CampaignPolicyError( - "successful architecture measurement exceeded its " - "generation ceiling" - ) - if limit is not None: - _validate_generation_phase( - resources.get("generation_phase"), - policy, - expected_reason="completed", - ) - return PolicyMeasurementState.SUCCESS - - if policy is STRICT_POLICY: - raise CampaignPolicyError( - "strict report profiles require a successful measurement" - ) - kind, record = _policy_record( - policy, - profile, - cell, - measurement, - expected_source_revision=expected_source_revision, - expected_source_tree=expected_source_tree, - ) - failure = measurement.get("failure") - if ( - not isinstance(failure, Mapping) - or failure.get("kind") != "ReportPolicyCensor" - or not isinstance(failure.get("message"), str) - ): - raise CampaignPolicyError("terminal measurement failure is not canonical") - for field in ( - "generation_seconds", - "wall_seconds_per_point", - "execution_seconds_per_point", - "matrix_element", - "sample_count", - "standard_error_seconds_per_point", - "relative_standard_error", - "artifact", - "selector_contract", - "validation", - ): - if measurement.get(field) is not None: - raise CampaignPolicyError( - f"terminal measurement unexpectedly contains {field}" - ) - dependencies = record.get("dependencies") - if not isinstance(dependencies, list): - raise CampaignPolicyError("policy_censor dependencies must be an array") - frontier = record.get("frontier") - - if kind is PolicyCensorKind.GENERATION_LIMIT: - cell_limit = generation_limit_for_cell(policy, cell) - if cell_limit is None or status != ResultStatus.TIMEOUT.value: - raise CampaignPolicyError( - "generation censor status or exemption is invalid" - ) - observed = _finite_number( - record.get("observed_generation_seconds"), - "observed_generation_seconds", - ) - if observed < cell_limit: - raise CampaignPolicyError( - "generation censor did not reach its authenticated ceiling" - ) - phase = record.get("phase_evidence") - _validate_generation_phase( - phase, - policy, - expected_reason="generation_timeout", - ) - assert isinstance(phase, Mapping) - if observed != float(phase["generation_elapsed_seconds"]): - raise CampaignPolicyError( - "generation censor observed time differs from phase evidence" - ) - resources = _validate_resources(measurement, policy) - if resources.get("generation_phase") != phase: - raise CampaignPolicyError( - "generation censor phase evidence differs from resources" - ) - if ( - record.get("observed_rss_bytes") is not None - or record.get("observed_guard_bytes") is not None - or record.get("memory_limit_reason") is not None - or record.get("memory_metric_abi") is not None - or dependencies - or frontier is not None - ): - raise CampaignPolicyError("generation censor fields are inconsistent") - return PolicyMeasurementState.GENERATION_LIMIT - - if kind is PolicyCensorKind.MEMORY_LIMIT: - if status != ResultStatus.MEMORY_LIMIT.value: - raise CampaignPolicyError("memory censor status is invalid") - resources = _validate_resources(measurement, policy) - assert policy.memory_limit_bytes is not None - legacy_censor = record.get("abi") == LEGACY_POLICY_CENSOR_ABI - observed_rss = record.get("observed_rss_bytes") - common_invalid = ( - record.get("observed_generation_seconds") is not None - or record.get("phase_evidence") is not None - or dependencies - or frontier is not None - ) - if legacy_censor: - invalid = ( - isinstance(observed_rss, bool) - or not isinstance(observed_rss, int) - or observed_rss <= policy.memory_limit_bytes - or observed_rss != resources.get("peak_rss_bytes") - or common_invalid - ) - else: - observed_guard = record.get("observed_guard_bytes") - invalid = ( - isinstance(observed_rss, bool) - or not isinstance(observed_rss, int) - or observed_rss != resources.get("peak_rss_bytes") - or isinstance(observed_guard, bool) - or not isinstance(observed_guard, int) - or observed_guard <= policy.memory_limit_bytes - or observed_guard != resources.get("peak_guard_bytes") - or record.get("memory_metric_abi") != PROCESS_TREE_MEMORY_METRIC_ABI - or resources.get("memory_metric_abi") != PROCESS_TREE_MEMORY_METRIC_ABI - or record.get("memory_limit_reason") - != resources.get("memory_limit_reason") - or record.get("memory_limit_reason") not in _MEMORY_LIMIT_REASONS - or common_invalid - ) - if invalid: - raise CampaignPolicyError("memory censor evidence is inconsistent") - return PolicyMeasurementState.MEMORY_LIMIT - - if status != ResultStatus.SKIP.value: - raise CampaignPolicyError("derived censor status is invalid") - if ( - record.get("observed_generation_seconds") is not None - or record.get("observed_rss_bytes") is not None - or record.get("observed_guard_bytes") is not None - or record.get("memory_limit_reason") is not None - or record.get("memory_metric_abi") is not None - or record.get("phase_evidence") is not None - or measurement.get("resources") is not None - ): - raise CampaignPolicyError("derived censor fields are inconsistent") - if kind is PolicyCensorKind.RESOURCE_FRONTIER: - if dependencies or not isinstance(frontier, Mapping): - raise CampaignPolicyError( - "resource-frontier censor fields are inconsistent" - ) - if set(frontier) != _FRONTIER_FIELDS: - raise CampaignPolicyError("resource-frontier reference is malformed") - lane = frontier.get("lane") - root = frontier.get("root") - if ( - frontier.get("abi") != RESOURCE_FRONTIER_ABI - or not isinstance(lane, Mapping) - or set(lane) != _FRONTIER_LANE_FIELDS - or dict(lane) != resource_lane_identity(cell) - or not isinstance(root, Mapping) - or set(root) != _FRONTIER_ROOT_FIELDS - ): - raise CampaignPolicyError("resource-frontier identity is invalid") - cell_id = root.get("cell_id") - digest = root.get("censor_sha256") - root_n = root.get("n_final") - root_kind = root.get("kind") - root_status = root.get("status") - if ( - not isinstance(cell_id, str) - or not cell_id - or isinstance(root_n, bool) - or not isinstance(root_n, int) - or root_n < 1 - or root_n >= cell.n_final - or root_kind - not in { - PolicyCensorKind.GENERATION_LIMIT.value, - PolicyCensorKind.MEMORY_LIMIT.value, - } - or root_status - not in { - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - } - or not isinstance(digest, str) - or _SHA256_RE.fullmatch(digest) is None - ): - raise CampaignPolicyError("resource-frontier reference is invalid") - if ( - root_kind == PolicyCensorKind.GENERATION_LIMIT.value - and root_status != ResultStatus.TIMEOUT.value - ) or ( - root_kind == PolicyCensorKind.MEMORY_LIMIT.value - and root_status != ResultStatus.MEMORY_LIMIT.value - ): - raise CampaignPolicyError("resource-frontier kind and status differ") - return PolicyMeasurementState.RESOURCE_FRONTIER - if frontier is not None or not dependencies: - raise CampaignPolicyError("dependency censor fields are inconsistent") - seen: set[str] = set() - for dependency in dependencies: - if not isinstance(dependency, Mapping) or set(dependency) != _DEPENDENCY_FIELDS: - raise CampaignPolicyError("dependency censor reference is malformed") - cell_id = dependency.get("cell_id") - digest = dependency.get("censor_sha256") - dep_status = dependency.get("status") - if ( - not isinstance(cell_id, str) - or not cell_id - or cell_id in seen - or dep_status - not in { - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - ResultStatus.SKIP.value, - } - or not isinstance(digest, str) - or _SHA256_RE.fullmatch(digest) is None - ): - raise CampaignPolicyError("dependency censor reference is invalid") - seen.add(cell_id) - return PolicyMeasurementState.DEPENDENCY - - -def _generation_limit_label(record: Mapping[str, object]) -> str | None: - raw_limit = record.get("generation_limit_seconds") - if ( - isinstance(raw_limit, bool) - or not isinstance(raw_limit, (int, float)) - or not math.isfinite(float(raw_limit)) - or float(raw_limit) <= 0.0 - ): - return None - limit = float(raw_limit) - hours = limit / 3600.0 - if hours.is_integer(): - return f">{int(hours)}h" - return f">{limit:g}s" - - -def _manual_time_limit_label( - record: Mapping[str, object], - field: str, - prefix: str, -) -> str | None: - raw_limit = record.get(field) - if ( - isinstance(raw_limit, bool) - or not isinstance(raw_limit, (int, float)) - or not math.isfinite(float(raw_limit)) - or float(raw_limit) <= 0.0 - ): - return None - limit = float(raw_limit) - hours = limit / 3600.0 - rendered = f"{int(hours)}h" if hours.is_integer() else f"{limit:g}s" - return f"{prefix} >{rendered}" - - -def policy_measurement_state_hint( - measurement: Mapping[str, object], -) -> PolicyMeasurementState | None: - """Decode a current's status/kind pair without deeper artifact checks. - - This is intentionally only a lightweight classification helper. Callers - remain responsible for the profile-specific validation and source checks - required at their publication or reuse boundary. - """ - - status = measurement.get("status") - if status == ResultStatus.OK.value: - return PolicyMeasurementState.SUCCESS - provenance = measurement.get("provenance") - censor = ( - provenance.get("policy_censor") if isinstance(provenance, Mapping) else None - ) - kind = censor.get("kind") if isinstance(censor, Mapping) else None - manual = ( - provenance.get("manual_campaign") if isinstance(provenance, Mapping) else None - ) - timeout_states = { - PolicyCensorKind.GENERATION_LIMIT.value: ( - PolicyMeasurementState.GENERATION_LIMIT - ), - PolicyCensorKind.WORKER_TIMEOUT.value: PolicyMeasurementState.WORKER_TIMEOUT, - PolicyCensorKind.PROFILING_TIMEOUT.value: ( - PolicyMeasurementState.PROFILING_TIMEOUT - ), - PolicyCensorKind.VALIDATION_TIMEOUT.value: ( - PolicyMeasurementState.VALIDATION_TIMEOUT - ), - } - if status == ResultStatus.TIMEOUT.value: - state = timeout_states.get(kind) - if state is not None: - return state - if ( - kind is None - and isinstance(manual, Mapping) - and _generation_limit_label(manual) is not None - ): - return PolicyMeasurementState.GENERATION_LIMIT - return None - if ( - status == ResultStatus.MEMORY_LIMIT.value - and kind == PolicyCensorKind.MEMORY_LIMIT.value - ): - return PolicyMeasurementState.MEMORY_LIMIT - if ( - status == ResultStatus.MEMORY_LIMIT.value - and kind is None - and isinstance(manual, Mapping) - and isinstance(manual.get("memory_limit_bytes"), int) - and not isinstance(manual.get("memory_limit_bytes"), bool) - and int(manual["memory_limit_bytes"]) > 0 - ): - return PolicyMeasurementState.MEMORY_LIMIT - if status == ResultStatus.SKIP.value: - return { - PolicyCensorKind.DEPENDENCY.value: PolicyMeasurementState.DEPENDENCY, - PolicyCensorKind.RESOURCE_FRONTIER.value: ( - PolicyMeasurementState.RESOURCE_FRONTIER - ), - }.get(kind) - return None - - -def policy_status_label(measurement: Mapping[str, object]) -> str | None: - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return None - record = provenance.get("policy_censor") - if not isinstance(record, Mapping): - manual = provenance.get("manual_campaign") - if not isinstance(manual, Mapping): - return None - status = measurement.get("status") - if status == ResultStatus.TIMEOUT.value: - return _generation_limit_label(manual) - if status == ResultStatus.MEMORY_LIMIT.value: - record = manual - kind = PolicyCensorKind.MEMORY_LIMIT.value - else: - return None - else: - kind = record.get("kind") - if kind == PolicyCensorKind.GENERATION_LIMIT.value: - return _generation_limit_label(record) - if kind == PolicyCensorKind.MEMORY_LIMIT.value: - memory_limit = record.get("memory_limit_bytes") - if ( - isinstance(memory_limit, bool) - or not isinstance(memory_limit, int) - or memory_limit <= 0 - or memory_limit % 1_000_000_000 - ): - return None - return f">{memory_limit // 1_000_000_000}GB" - if kind == PolicyCensorKind.WORKER_TIMEOUT.value: - return _manual_time_limit_label( - record, - "worker_wall_limit_seconds", - "worker", - ) - if kind == PolicyCensorKind.PROFILING_TIMEOUT.value: - return _manual_time_limit_label( - record, - "profiling_time_limit_seconds", - "profile", - ) - if kind == PolicyCensorKind.VALIDATION_TIMEOUT.value: - return _manual_time_limit_label( - record, - "validation_time_limit_seconds", - "validation", - ) - if kind in { - PolicyCensorKind.DEPENDENCY.value, - PolicyCensorKind.RESOURCE_FRONTIER.value, - }: - if kind == PolicyCensorKind.RESOURCE_FRONTIER.value: - raw_frontier = record.get("frontier") - root = ( - raw_frontier.get("root") if isinstance(raw_frontier, Mapping) else None - ) - dependencies = [root] if isinstance(root, Mapping) else [] - else: - dependencies = record.get("dependencies") - labels: set[str] = set() - if isinstance(dependencies, list): - for dependency in dependencies: - if not isinstance(dependency, Mapping): - continue - status = dependency.get("status") - if status == ResultStatus.TIMEOUT.value: - labels.add(_generation_limit_label(record) or "timeout") - elif status == ResultStatus.MEMORY_LIMIT.value: - memory_limit = record.get("memory_limit_bytes") - if ( - isinstance(memory_limit, int) - and not isinstance(memory_limit, bool) - and memory_limit > 0 - and memory_limit % 1_000_000_000 == 0 - ): - labels.add(f">{memory_limit // 1_000_000_000}GB") - else: - labels.add("blocked") - else: - labels.add("blocked") - detail = "/".join(sorted(labels)) if labels else "blocked" - return f"dependency {detail}" - return None - - -__all__ = [ - "CAMPAIGN_POLICY_SCHEMA", - "GENERATION_PHASE_EVIDENCE_ABI", - "LEGACY_POLICY_CENSOR_ABI", - "MACBOOK_M3_CELL_CORES", - "MACBOOK_M3_MEMORY_LIMIT_BYTES", - "MACBOOK_M3_POLICY", - "MACBOOK_M3_POLICY_NAME", - "MACBOOK_M3_PROFILE", - "MACBOOK_M3_TARGET_RUNTIME_SECONDS", - "MACBOOK_M3_WORKERS", - "MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS", - "MACBOOK_M3_Z_TABLE_F_POLICY", - "MACBOOK_M3_Z_TABLE_F_POLICY_NAME", - "POLICY_CENSOR_ABI", - "RESOURCE_FRONTIER_ABI", - "STRICT_POLICY", - "STRICT_POLICY_NAME", - "WORKER_PHASE_STATE_ABI", - "X86_EPYC_CELL_CORES", - "X86_EPYC_GENERATION_LIMIT_SECONDS", - "X86_EPYC_LEGACY_MEMORY_LIMIT_BYTES", - "X86_EPYC_LEGACY_WORKERS", - "X86_EPYC_MEMORY_LIMIT_BYTES", - "X86_EPYC_NATIVE_COMPILER_SLOTS", - "X86_EPYC_POLICY", - "X86_EPYC_POLICY_NAME", - "X86_EPYC_PROFILE", - "X86_EPYC_TARGET_RUNTIME_SECONDS", - "X86_EPYC_WORKERS", - "CampaignPolicy", - "CampaignPolicyError", - "PolicyCensorKind", - "PolicyMeasurementState", - "campaign_policy", - "default_campaign_policy", - "dependency_reference", - "generation_limit_exempt", - "generation_limit_for_cell", - "policy_censor_measurement", - "policy_from_manifest", - "policy_measurement_state_hint", - "policy_status_label", - "resource_frontier_reference", - "resource_lane_identity", - "validate_campaign_settings", - "validate_policy_measurement", - "validate_policy_profile", -] diff --git a/pyamplicol/tools/performance_report/campaign_reset.py b/pyamplicol/tools/performance_report/campaign_reset.py deleted file mode 100644 index 582e1eacb4..0000000000 --- a/pyamplicol/tools/performance_report/campaign_reset.py +++ /dev/null @@ -1,1320 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Auditable campaign epochs and host-local original-AmpliCol seeds. - -This module deliberately keeps old measurement provenance immutable. A new -campaign may authorize a digest-pinned, same-profile original-AmpliCol current, -but it never rewrites that current to impersonate the new report source. -""" - -from __future__ import annotations - -import errno -import fcntl -import hashlib -import json -import math -import os -import re -import shutil -import tempfile -import uuid -from collections.abc import Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path -from typing import Any - -from .artifacts import ArtifactStore, CurrentRecord -from .cache import validate_measurement -from .campaign_policy import CampaignPolicy, validate_policy_measurement -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import Accuracy, CellSpec, ExecutionMode, ResultStatus, Workload - -SEED_FILENAME = "original_amplicol_seed.json" -CAMPAIGN_MARKER_FILENAME = "campaign-epoch.json" -RESET_JOURNAL_FILENAME = "campaign-reset-journal.json" -BASELINE_GATE_FILENAME = "baseline-gate.json" -SEED_SCHEMA = "pyamplicol-original-amplicol-seed-v1" -CAMPAIGN_MARKER_SCHEMA = "pyamplicol-performance-campaign-epoch-v1" -RESET_JOURNAL_SCHEMA = "pyamplicol-performance-campaign-reset-v1" -BASELINE_GATE_SCHEMA = "pyamplicol-performance-baseline-gate-v1" -EXPECTED_CATALOG_CELL_COUNT = 2198 -EXPECTED_AMPLICOL_CELL_COUNT = 314 -EXPECTED_NON_AMPLICOL_CELL_COUNT = 1884 -_SUPPORTED_SEED_CATALOG_CARDINALITIES = frozenset( - { - (1646, 284, 1362), - (1666, 288, 1378), - (1706, 296, 1410), - (1796, 314, 1482), - ( - EXPECTED_CATALOG_CELL_COUNT, - EXPECTED_AMPLICOL_CELL_COUNT, - EXPECTED_NON_AMPLICOL_CELL_COUNT, - ), - } -) - -_SHA256_RE = re.compile(r"^[0-9a-f]{64}$") -_GIT_REVISION_RE = re.compile(r"^[0-9a-f]{40}$") -_PROFILE_RE = re.compile(r"^[A-Za-z0-9_.-]+$") -_LEGACY_METHOD = "original-amplicol-generated-library" -_LEGACY_VALIDATION_METHOD = "independent-original-amplicol-oracle" -_COMPILER_FIELDS = frozenset( - {"identity", "version", "flags", "target", "executable_sha256"} -) -_HASHED_ARCHIVE_BASENAMES = frozenset( - { - "current.json", - "manifest.json", - "result.json", - "worker-result.json", - "report-workspace.json", - "report_environment.json", - "measurement_lineage.json", - "pyAmpliCol.pdf", - } -) - - -class CampaignResetError(RuntimeError): - """The requested campaign epoch transition is not auditable.""" - - -def canonical_json_bytes(payload: object) -> bytes: - return ( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ).encode("ascii") - - -def sha256_path(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for chunk in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def sha256_payload(payload: object) -> str: - return hashlib.sha256(canonical_json_bytes(payload)).hexdigest() - - -def _atomic_write_json(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{uuid.uuid4()}.tmp") - try: - with temporary.open("xb") as stream: - stream.write(canonical_json_bytes(payload)) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - _fsync_directory(path.parent) - finally: - temporary.unlink(missing_ok=True) - - -def _fsync_directory(path: Path) -> None: - descriptor = os.open(path, os.O_RDONLY) - try: - os.fsync(descriptor) - finally: - os.close(descriptor) - - -def _read_object(path: Path, *, label: str) -> dict[str, Any]: - try: - payload = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise CampaignResetError(f"cannot read {label} {path}: {error}") from error - if not isinstance(payload, dict): - raise CampaignResetError(f"{label} must be a JSON object: {path}") - return payload - - -def _require_sha256(value: object, *, label: str) -> str: - if not isinstance(value, str) or _SHA256_RE.fullmatch(value) is None: - raise CampaignResetError(f"{label} is not a lowercase SHA-256 digest") - return value - - -def _require_revision(value: object, *, label: str) -> str: - if not isinstance(value, str) or _GIT_REVISION_RE.fullmatch(value) is None: - raise CampaignResetError(f"{label} is not a full Git revision") - return value - - -def _current_pointer_path(record: CurrentRecord) -> Path: - return record.manifest_path.parent.parent.parent / "current.json" - - -def _legacy_contract( - record: CurrentRecord, - *, - requires_selector: bool, - expected_legacy_revision: str | None = None, - expected_point_digest: str | None = None, -) -> dict[str, object]: - provenance = record.result.get("provenance") - validation = record.result.get("validation") - selector = record.result.get("selector_contract") - resources = record.result.get("resources") - if not isinstance(provenance, Mapping): - raise CampaignResetError(f"{record.cell_id}: provenance is missing") - if provenance.get("method") != _LEGACY_METHOD: - raise CampaignResetError( - f"{record.cell_id}: result is not original generated-library AmpliCol" - ) - legacy_revision = _require_revision( - provenance.get("revision"), - label=f"{record.cell_id}.provenance.revision", - ) - if ( - expected_legacy_revision is not None - and legacy_revision != expected_legacy_revision - ): - raise CampaignResetError( - f"{record.cell_id}: original-AmpliCol revision is not " - "contributor-lock pinned" - ) - source_revision = _require_revision( - provenance.get("report_source_revision"), - label=f"{record.cell_id}.provenance.report_source_revision", - ) - source_tree = _require_revision( - provenance.get("report_source_tree"), - label=f"{record.cell_id}.provenance.report_source_tree", - ) - if ( - provenance.get("report_measured_source_revision") != source_revision - or provenance.get("report_measured_source_tree") != source_tree - or provenance.get("report_source_clean") is not True - ): - raise CampaignResetError( - f"{record.cell_id}: report source provenance is not internally exact" - ) - compiler = provenance.get("compiler") - if not isinstance(compiler, Mapping) or set(compiler) != _COMPILER_FIELDS: - raise CampaignResetError(f"{record.cell_id}: compiler identity is missing") - if ( - not isinstance(compiler.get("identity"), str) - or not compiler["identity"] - or not isinstance(compiler.get("version"), str) - or not compiler["version"] - or not isinstance(compiler.get("target"), str) - or not compiler["target"] - or not isinstance(compiler.get("flags"), list) - or not all(isinstance(flag, str) for flag in compiler["flags"]) - ): - raise CampaignResetError( - f"{record.cell_id}: compiler identity/version/flags/target are malformed" - ) - _require_sha256( - compiler.get("executable_sha256"), - label=f"{record.cell_id}.compiler.executable_sha256", - ) - if ( - not isinstance(validation, Mapping) - or validation.get("status") != "ok" - or validation.get("method") != _LEGACY_VALIDATION_METHOD - ): - raise CampaignResetError( - f"{record.cell_id}: numerical validation is not successful" - ) - validation_point_digest = _require_sha256( - validation.get("point_digest"), - label=f"{record.cell_id}.validation.point_digest", - ) - if requires_selector: - if not isinstance(selector, Mapping): - raise CampaignResetError( - f"{record.cell_id}: LC selector contract is missing" - ) - from .agreements import ( - LC_COMMON_COMPONENT_FIELD, - validate_lc_common_component, - ) - from .runner import SelectorContract - - try: - typed_selector = SelectorContract.from_mapping(selector) - validate_lc_common_component( - validation.get(LC_COMMON_COMPONENT_FIELD), - expected_cell_id=record.cell_id, - selector_contract=selector, - ) - except (TypeError, ValueError, RuntimeError) as error: - raise CampaignResetError( - f"{record.cell_id}: LC selector evidence is invalid" - ) from error - if typed_selector.point_digest != validation_point_digest: - raise CampaignResetError( - f"{record.cell_id}: LC selector and validation points differ" - ) - if ( - expected_point_digest is not None - and typed_selector.point_digest != expected_point_digest - ): - raise CampaignResetError( - f"{record.cell_id}: LC selector point predates the active " - "deterministic point corpus" - ) - common_component = validation[LC_COMMON_COMPONENT_FIELD] - assert isinstance(common_component, Mapping) - if float(common_component["value"]) <= 0.0: - raise CampaignResetError( - f"{record.cell_id}: LC selector common component is structural zero" - ) - selector_digest: str | None = sha256_payload(dict(selector)) - elif selector is not None: - raise CampaignResetError( - f"{record.cell_id}: contracted AmpliCol result has a selector contract" - ) - else: - selector_digest = None - if not isinstance(resources, Mapping): - raise CampaignResetError(f"{record.cell_id}: resource evidence is missing") - target = provenance.get("target_runtime_seconds") - achieved = ( - provenance.get("runtime_profile", {}) - if isinstance(provenance.get("runtime_profile"), Mapping) - else {} - ) - measurement = ( - achieved.get("measurement") - if isinstance(achieved, Mapping) - else None - ) - if ( - not isinstance(target, (int, float)) - or isinstance(target, bool) - or not math.isfinite(float(target)) - or float(target) <= 0.0 - or not isinstance(measurement, Mapping) - or measurement.get("target_runtime_achieved") is not True - ): - raise CampaignResetError( - f"{record.cell_id}: finite target-runtime evidence is missing" - ) - return { - "legacy_revision": legacy_revision, - "report_source_revision": source_revision, - "report_source_tree": source_tree, - "compiler_sha256": sha256_payload(dict(compiler)), - "selector_contract_sha256": selector_digest, - "validation_sha256": sha256_payload(dict(validation)), - "resource_evidence_sha256": sha256_payload(dict(resources)), - "target_runtime_seconds": float(target), - "workload_specific_generation": ( - provenance.get("generation_timing_is_workload_specific") is True - ), - "row_selection_policy": provenance.get("row_selection_policy"), - "selector_color_word_policy": provenance.get( - "selector_color_word_policy" - ), - } - - -def _pin_for_record( - record: CurrentRecord, - *, - profile: str, - catalog: ReportCatalog, - policy: CampaignPolicy, - expected_legacy_revision: str, -) -> dict[str, object]: - cell = catalog.cell(record.cell_id) - if cell.measurement.execution_mode is not ExecutionMode.AMPLICOL: - raise CampaignResetError(f"{record.cell_id}: seed cell is not AmpliCol") - if record.result.get("status") != ResultStatus.OK.value: - raise CampaignResetError(f"{record.cell_id}: seed result is not ok") - validate_measurement(record.result, expected_cell=cell) - expected_point_digest: str | None = None - if cell.measurement.accuracy is Accuracy.LC: - from .measurement import shared_validation_points - from .runner import point_digest - - expected_point_digest = point_digest(shared_validation_points(cell.process)) - contract = _legacy_contract( - record, - requires_selector=( - cell.measurement.accuracy is Accuracy.LC - ), - expected_legacy_revision=expected_legacy_revision, - expected_point_digest=expected_point_digest, - ) - validate_policy_measurement( - policy, - profile, - cell, - record.result, - expected_source_revision=str(contract["report_source_revision"]), - expected_source_tree=str(contract["report_source_tree"]), - ) - pointer = _current_pointer_path(record) - return { - "cell_id": record.cell_id, - "attempt_id": record.attempt_id, - "current_pointer_sha256": sha256_path(pointer), - "manifest_sha256": record.manifest_sha256, - "result_sha256": sha256_path(record.result_path), - "artifact_count": len(record.artifacts), - "artifact_manifest_sha256": sha256_payload( - [ - { - "path": artifact.relative_path, - "sha256": artifact.sha256, - "size": artifact.size, - } - for artifact in record.artifacts - ] - ), - "contract": contract, - } - - -def _lc_seed_family_rejections( - *, - cells: Mapping[str, CellSpec], - records_by_cell: Mapping[str, CurrentRecord], - admitted_cell_ids: set[str], -) -> dict[str, str]: - """Reject LC seeds unless both layouts authenticate one exact selector. - - A selected-flow seed is the selector authority for a subsequently measured - all-flow row. Reusing only one historical layout, or two layouts carrying - different contracts, can therefore make a fresh dependent compare values - evaluated at different physical components. Reject the complete pair so - the current adapter derives both rows from the same deterministic point and - selector; never rewrite historical numerical evidence. - """ - - families: dict[tuple[object, ...], dict[Workload, str]] = {} - for cell_id, cell in cells.items(): - if ( - cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - or cell.measurement.accuracy is not Accuracy.LC - ): - continue - key = ( - cell.dataset_id, - cell.process, - cell.process_key, - cell.n_final, - cell.measurement, - cell.variant, - ) - families.setdefault(key, {})[cell.workload] = cell_id - - rejected: dict[str, str] = {} - for family in families.values(): - selected_id = family.get(Workload.SELECTED_FLOW) - all_flow_id = family.get(Workload.ALL_FLOW) - if selected_id is None or all_flow_id is None: - continue - admitted = { - cell_id - for cell_id in (selected_id, all_flow_id) - if cell_id in admitted_cell_ids - } - if not admitted: - continue - if admitted != {selected_id, all_flow_id}: - reason = ( - "LC seed family is incomplete; selected/all-flow rows must be " - "remeasured under one selector authority" - ) - rejected.update((cell_id, reason) for cell_id in admitted) - continue - selected = records_by_cell[selected_id].result.get("selector_contract") - all_flow = records_by_cell[all_flow_id].result.get("selector_contract") - if selected != all_flow: - reason = ( - "LC selected/all-flow seed contracts differ; both layouts must " - "be remeasured under one selector authority" - ) - rejected[selected_id] = reason - rejected[all_flow_id] = reason - return rejected - - -def build_seed_manifest( - *, - profile: str, - store: ArtifactStore, - policy: CampaignPolicy, - final_source_revision: str, - final_source_tree: str, - expected_legacy_revision: str, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, object]: - """Return the fail-closed same-profile AmpliCol seed manifest.""" - - if _PROFILE_RE.fullmatch(profile) is None: - raise CampaignResetError(f"invalid report profile {profile!r}") - _require_revision(final_source_revision, label="final_source_revision") - _require_revision(final_source_tree, label="final_source_tree") - _require_revision( - expected_legacy_revision, - label="expected_legacy_revision", - ) - pins_by_cell: dict[str, dict[str, object]] = {} - records_by_cell: dict[str, CurrentRecord] = {} - rejected_by_cell: dict[str, str] = {} - cells = {cell.cell_id: cell for cell in catalog.measurement_cells()} - for record in store.recover_current_records(): - cell = cells.get(record.cell_id) - if ( - cell is None - or cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - ): - continue - records_by_cell[record.cell_id] = record - try: - pins_by_cell[record.cell_id] = _pin_for_record( - record, - profile=profile, - catalog=catalog, - policy=policy, - expected_legacy_revision=expected_legacy_revision, - ) - except (CampaignResetError, KeyError, ValueError) as error: - rejected_by_cell[record.cell_id] = str(error) - family_rejections = _lc_seed_family_rejections( - cells=cells, - records_by_cell=records_by_cell, - admitted_cell_ids=set(pins_by_cell), - ) - for cell_id, reason in family_rejections.items(): - pins_by_cell.pop(cell_id, None) - rejected_by_cell[cell_id] = reason - pins = sorted(pins_by_cell.values(), key=lambda item: str(item["cell_id"])) - rejected = [ - {"cell_id": cell_id, "reason": reason} - for cell_id, reason in sorted(rejected_by_cell.items()) - ] - amplicol_count = sum( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - for cell in cells.values() - ) - if ( - len(cells) != EXPECTED_CATALOG_CELL_COUNT - or amplicol_count != EXPECTED_AMPLICOL_CELL_COUNT - or len(cells) - amplicol_count != EXPECTED_NON_AMPLICOL_CELL_COUNT - ): - raise CampaignResetError( - "campaign reset catalog cardinality differs from " - f"{EXPECTED_CATALOG_CELL_COUNT}/{EXPECTED_AMPLICOL_CELL_COUNT}/" - f"{EXPECTED_NON_AMPLICOL_CELL_COUNT}" - ) - payload: dict[str, object] = { - "schema": SEED_SCHEMA, - "profile": profile, - "final_source_revision": final_source_revision, - "final_source_tree": final_source_tree, - "expected_legacy_revision": expected_legacy_revision, - "catalog_cell_count": len(cells), - "amplicol_catalog_cell_count": amplicol_count, - "seed_count": len(pins), - "pins": pins, - "rejected": rejected, - } - payload["seed_manifest_sha256"] = sha256_payload(payload) - return payload - - -@dataclass(frozen=True, slots=True) -class OriginalAmplicolSeed: - """Digest-pinned authorization for host-local inherited baselines.""" - - profile: str - payload: Mapping[str, object] - pins_by_cell: Mapping[str, Mapping[str, object]] - - @classmethod - def load( - cls, - path: Path, - *, - profile: str, - store: ArtifactStore, - catalog: ReportCatalog = REPORT_CATALOG, - expected_final_source_revision: str | None = None, - expected_final_source_tree: str | None = None, - expected_manifest_sha256: str | None = None, - ) -> OriginalAmplicolSeed: - raw = _read_object(path, label="original AmpliCol seed") - digest = raw.pop("seed_manifest_sha256", None) - if raw.get("schema") != SEED_SCHEMA or raw.get("profile") != profile: - raise CampaignResetError("original AmpliCol seed identity differs") - if _require_sha256(digest, label="seed_manifest_sha256") != sha256_payload( - raw - ): - raise CampaignResetError("original AmpliCol seed digest differs") - if expected_manifest_sha256 is not None and digest != expected_manifest_sha256: - raise CampaignResetError( - "original AmpliCol seed is not pinned by the campaign marker" - ) - final_revision = _require_revision( - raw.get("final_source_revision"), - label="seed.final_source_revision", - ) - final_tree = _require_revision( - raw.get("final_source_tree"), - label="seed.final_source_tree", - ) - if ( - expected_final_source_revision is not None - and final_revision != expected_final_source_revision - ): - raise CampaignResetError( - "original AmpliCol seed final source revision differs" - ) - if ( - expected_final_source_tree is not None - and final_tree != expected_final_source_tree - ): - raise CampaignResetError("original AmpliCol seed final source tree differs") - catalog_cells = catalog.measurement_cells() - expected_amplicol_count = sum( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - for cell in catalog_cells - ) - seed_catalog_count = raw.get("catalog_cell_count") - seed_amplicol_count = raw.get("amplicol_catalog_cell_count") - seed_non_amplicol_count = ( - seed_catalog_count - seed_amplicol_count - if isinstance(seed_catalog_count, int) - and not isinstance(seed_catalog_count, bool) - and isinstance(seed_amplicol_count, int) - and not isinstance(seed_amplicol_count, bool) - else None - ) - if ( - len(catalog_cells) != EXPECTED_CATALOG_CELL_COUNT - or expected_amplicol_count != EXPECTED_AMPLICOL_CELL_COUNT - or len(catalog_cells) - expected_amplicol_count - != EXPECTED_NON_AMPLICOL_CELL_COUNT - or ( - seed_catalog_count, - seed_amplicol_count, - seed_non_amplicol_count, - ) - not in _SUPPORTED_SEED_CATALOG_CARDINALITIES - or seed_catalog_count > len(catalog_cells) - or seed_amplicol_count > expected_amplicol_count - ): - raise CampaignResetError( - "original AmpliCol seed catalog coverage differs" - ) - pins = raw.get("pins") - if not isinstance(pins, list) or raw.get("seed_count") != len(pins): - raise CampaignResetError("original AmpliCol seed pin count differs") - by_cell: dict[str, Mapping[str, object]] = {} - for item in pins: - if not isinstance(item, Mapping): - raise CampaignResetError("original AmpliCol seed pin is malformed") - cell_id = item.get("cell_id") - if not isinstance(cell_id, str) or cell_id in by_cell: - raise CampaignResetError("original AmpliCol seed cell is duplicated") - cell = catalog.cell(cell_id) - if cell.measurement.execution_mode is not ExecutionMode.AMPLICOL: - raise CampaignResetError(f"{cell_id}: seed pin is not AmpliCol") - record = store.load_current(cell_id) - if record is None or not cls._matches(record, item): - raise CampaignResetError(f"{cell_id}: seeded current digest differs") - by_cell[cell_id] = item - complete = dict(raw) - complete["seed_manifest_sha256"] = digest - return cls(profile=profile, payload=complete, pins_by_cell=by_cell) - - @staticmethod - def _matches(record: CurrentRecord, pin: Mapping[str, object]) -> bool: - contract = pin.get("contract") - try: - requires_selector = ( - REPORT_CATALOG.cell(record.cell_id).measurement.accuracy.value == "lc" - ) - except KeyError: - return False - try: - observed = _legacy_contract( - record, - requires_selector=requires_selector, - expected_legacy_revision=( - str(contract.get("legacy_revision")) - if isinstance(contract, Mapping) - else None - ), - ) - except CampaignResetError: - return False - return ( - record.result.get("status") == ResultStatus.OK.value - and record.attempt_id == pin.get("attempt_id") - and record.manifest_sha256 == pin.get("manifest_sha256") - and sha256_path(_current_pointer_path(record)) - == pin.get("current_pointer_sha256") - and sha256_path(record.result_path) == pin.get("result_sha256") - and len(record.artifacts) == pin.get("artifact_count") - and sha256_payload( - [ - { - "path": artifact.relative_path, - "sha256": artifact.sha256, - "size": artifact.size, - } - for artifact in record.artifacts - ] - ) - == pin.get("artifact_manifest_sha256") - and isinstance(contract, Mapping) - and dict(contract) == observed - ) - - @property - def digest(self) -> str: - return str(self.payload["seed_manifest_sha256"]) - - def source_for_current( - self, - record: CurrentRecord, - *, - active_revision: str, - active_tree: str, - ) -> tuple[str, str] | None: - if ( - active_revision != self.payload.get("final_source_revision") - or active_tree != self.payload.get("final_source_tree") - ): - return None - provenance = record.result.get("provenance") - if isinstance(provenance, Mapping) and ( - provenance.get("report_source_revision") == active_revision - and provenance.get("report_source_tree") == active_tree - and provenance.get("report_measured_source_revision") - == active_revision - and provenance.get("report_measured_source_tree") == active_tree - ): - return active_revision, active_tree - pin = self.pins_by_cell.get(record.cell_id) - if pin is None or not self._matches(record, pin): - return None - contract = pin.get("contract") - assert isinstance(contract, Mapping) - return ( - str(contract["report_source_revision"]), - str(contract["report_source_tree"]), - ) - - -def load_seed_if_present( - *, - profile: str, - store: ArtifactStore, - catalog: ReportCatalog = REPORT_CATALOG, -) -> OriginalAmplicolSeed | None: - path = store.artifact_root / SEED_FILENAME - if not path.exists(): - return None - if path.is_symlink() or not path.is_file(): - raise CampaignResetError(f"seed manifest is not a regular file: {path}") - marker = _load_campaign_marker( - store.artifact_root, - profile=profile, - require_ready=True, - ) - return OriginalAmplicolSeed.load( - path, - profile=profile, - store=store, - catalog=catalog, - expected_final_source_revision=str(marker["source_revision"]), - expected_final_source_tree=str(marker["source_tree"]), - expected_manifest_sha256=str(marker["seed_manifest_sha256"]), - ) - - -def _link_or_copy(source: Path, destination: Path) -> None: - destination.parent.mkdir(parents=True, exist_ok=True) - try: - os.link(source, destination) - except OSError as error: - if error.errno not in { - errno.EXDEV, - errno.EPERM, - errno.EACCES, - getattr(errno, "EOPNOTSUPP", errno.EPERM), - }: - raise - shutil.copy2(source, destination) - - -def stage_seed_store( - *, - source_store: ArtifactStore, - destination_root: Path, - destination_lock_root: Path, - seed_manifest: Mapping[str, object], -) -> ArtifactStore: - """Create a fresh store containing only digest-pinned seed attempts.""" - - if destination_root.exists() or destination_lock_root.exists(): - raise CampaignResetError("fresh campaign staging roots already exist") - destination = ArtifactStore( - artifact_root=destination_root, - lock_root=destination_lock_root, - ) - pins = seed_manifest.get("pins") - if not isinstance(pins, list): - raise CampaignResetError("seed manifest pins are malformed") - records = { - record.cell_id: record for record in source_store.recover_current_records() - } - for pin in pins: - if not isinstance(pin, Mapping) or not isinstance(pin.get("cell_id"), str): - raise CampaignResetError("seed manifest pin is malformed") - record = records.get(str(pin["cell_id"])) - if record is None or not OriginalAmplicolSeed._matches(record, pin): - raise CampaignResetError(f"{pin['cell_id']}: source seed changed") - destination_cell = destination._cell_root(record.cell_id) - source_cell = _current_pointer_path(record).parent - destination_cell.mkdir(parents=True, exist_ok=True) - _link_or_copy( - source_cell / "current.json", - destination_cell / "current.json", - ) - source_attempt = record.manifest_path.parent - destination_attempt = ( - destination_cell / "attempts" / record.attempt_id - ) - destination_attempt.mkdir(parents=True, exist_ok=True) - authenticated_files = { - record.manifest_path, - *(artifact.path for artifact in record.artifacts), - } - for source in sorted(authenticated_files): - if source.is_symlink() or not source.is_file(): - raise CampaignResetError( - f"seed contains an unauthenticated file type: {source}" - ) - relative = source.relative_to(source_attempt) - _link_or_copy(source, destination_attempt / relative) - complete = dict(seed_manifest) - _atomic_write_json(destination_root / SEED_FILENAME, complete) - OriginalAmplicolSeed.load( - destination_root / SEED_FILENAME, - profile=str(seed_manifest["profile"]), - store=destination, - expected_final_source_revision=str( - seed_manifest["final_source_revision"] - ), - expected_final_source_tree=str(seed_manifest["final_source_tree"]), - expected_manifest_sha256=str(seed_manifest["seed_manifest_sha256"]), - ) - return destination - - -def lightweight_archive_inventory(roots: Sequence[Path]) -> dict[str, object]: - """Inventory an archive without re-reading manifest-authenticated binaries.""" - - entries: list[dict[str, object]] = [] - for root in roots: - resolved = root.expanduser().resolve(strict=False) - if not resolved.exists(): - continue - for path in sorted((resolved, *resolved.rglob("*"))): - stat = path.lstat() - entry: dict[str, object] = { - "root": os.fspath(resolved), - "path": ( - "." - if path == resolved - else path.relative_to(resolved).as_posix() - ), - "type": ( - "symlink" - if path.is_symlink() - else "directory" - if path.is_dir() - else "file" - if path.is_file() - else "special" - ), - "size": stat.st_size, - "mtime_ns": stat.st_mtime_ns, - } - if path.is_file() and ( - path.name in _HASHED_ARCHIVE_BASENAMES - or path.suffix in {".json", ".pdf"} - ): - entry["sha256"] = sha256_path(path) - entries.append(entry) - payload: dict[str, object] = { - "schema": "pyamplicol-performance-archive-inventory-v1", - "entries": entries, - } - payload["inventory_sha256"] = sha256_payload(payload) - return payload - - -def campaign_marker( - *, - campaign_id: str, - profile: str, - source_revision: str, - source_tree: str, - policy_sha256: str, - seed_manifest_sha256: str, - archive_manifest_sha256: str, -) -> dict[str, object]: - if not campaign_id or "/" in campaign_id or "\x00" in campaign_id: - raise CampaignResetError("campaign_id is not a safe component") - payload: dict[str, object] = { - "schema": CAMPAIGN_MARKER_SCHEMA, - "state": "PREPARED", - "campaign_id": campaign_id, - "profile": profile, - "source_revision": _require_revision( - source_revision, label="source_revision" - ), - "source_tree": _require_revision(source_tree, label="source_tree"), - "policy_sha256": _require_sha256( - policy_sha256, label="policy_sha256" - ), - "seed_manifest_sha256": _require_sha256( - seed_manifest_sha256, label="seed_manifest_sha256" - ), - "archive_manifest_sha256": _require_sha256( - archive_manifest_sha256, label="archive_manifest_sha256" - ), - "baseline_gate_sha256": None, - "prepared_marker_sha256": None, - } - payload["marker_sha256"] = sha256_payload(payload) - return payload - - -def _load_campaign_marker( - artifact_root: Path, - *, - profile: str, - require_ready: bool, -) -> dict[str, object]: - path = artifact_root / CAMPAIGN_MARKER_FILENAME - marker = _read_object(path, label="campaign marker") - digest = marker.pop("marker_sha256", None) - if ( - marker.get("schema") != CAMPAIGN_MARKER_SCHEMA - or marker.get("profile") != profile - or marker.get("state") not in {"PREPARED", "READY"} - or _require_sha256(digest, label="marker_sha256") - != sha256_payload(marker) - ): - raise CampaignResetError("active campaign marker differs") - if require_ready: - if marker.get("state") != "READY": - raise CampaignResetError("campaign baseline gate is not READY") - gate_digest = _require_sha256( - marker.get("baseline_gate_sha256"), - label="baseline_gate_sha256", - ) - prepared_digest = _require_sha256( - marker.get("prepared_marker_sha256"), - label="prepared_marker_sha256", - ) - gate = _read_object( - artifact_root / BASELINE_GATE_FILENAME, - label="campaign baseline gate", - ) - observed_gate_digest = gate.pop("baseline_gate_sha256", None) - if ( - _require_sha256( - observed_gate_digest, - label="baseline_gate.baseline_gate_sha256", - ) - != sha256_payload(gate) - or observed_gate_digest != gate_digest - or gate.get("prepared_marker_sha256") != prepared_digest - or gate.get("campaign_id") != marker.get("campaign_id") - or gate.get("profile") != profile - or gate.get("source_revision") != marker.get("source_revision") - or gate.get("source_tree") != marker.get("source_tree") - ): - raise CampaignResetError("campaign baseline gate differs") - marker["marker_sha256"] = digest - return marker - - -def mark_campaign_ready( - artifact_root: Path, - *, - baseline_gate_sha256: str, -) -> dict[str, object]: - raw_marker = _read_object( - artifact_root / CAMPAIGN_MARKER_FILENAME, - label="campaign marker", - ) - profile = raw_marker.get("profile") - if not isinstance(profile, str) or not profile: - raise CampaignResetError("campaign marker profile is malformed") - marker = _load_campaign_marker( - artifact_root, - profile=profile, - require_ready=False, - ) - if marker.get("state") != "PREPARED": - raise CampaignResetError("campaign marker is not PREPARED") - prepared_digest = str(marker.pop("marker_sha256")) - marker["state"] = "READY" - marker["baseline_gate_sha256"] = _require_sha256( - baseline_gate_sha256, - label="baseline_gate_sha256", - ) - marker["prepared_marker_sha256"] = prepared_digest - marker["marker_sha256"] = sha256_payload(marker) - _atomic_write_json(artifact_root / CAMPAIGN_MARKER_FILENAME, marker) - return marker - - -def assert_campaign_marker( - artifact_root: Path, - *, - campaign_id: str, - profile: str, - source_revision: str, - source_tree: str, - expected_marker_sha256: str | None = None, - require_ready: bool = True, -) -> dict[str, object]: - marker = _load_campaign_marker( - artifact_root, - profile=profile, - require_ready=require_ready, - ) - digest = marker["marker_sha256"] - if ( - marker.get("campaign_id") != campaign_id - or marker.get("profile") != profile - or marker.get("source_revision") != source_revision - or marker.get("source_tree") != source_tree - ): - raise CampaignResetError("active campaign marker differs") - if expected_marker_sha256 is not None and digest != expected_marker_sha256: - raise CampaignResetError("active campaign marker digest differs") - return marker - - -def temporary_staging_root(parent: Path, *, campaign_id: str) -> Path: - parent.mkdir(parents=True, exist_ok=True) - return Path( - tempfile.mkdtemp( - prefix=f".campaign-reset-{campaign_id}.", - dir=parent, - ) - ) - - -@dataclass(frozen=True, slots=True) -class ResetTransactionPaths: - """Explicit paths participating in one same-filesystem epoch transition.""" - - source_publication: Path - source_artifact_root: Path - source_coordination_root: Path - destination_publication: Path - destination_artifact_root: Path - destination_coordination_root: Path - archive_root: Path - staging_root: Path - guard_path: Path - - @property - def journal_path(self) -> Path: - return self.staging_root / RESET_JOURNAL_FILENAME - - -def _transaction_payload( - *, - state: str, - profile: str, - campaign_id: str, - archive_id: str, - paths: ResetTransactionPaths, - archive_manifest_sha256: str, - seed_manifest_sha256: str, - marker_sha256: str, -) -> dict[str, object]: - payload: dict[str, object] = { - "schema": RESET_JOURNAL_SCHEMA, - "state": state, - "profile": profile, - "campaign_id": campaign_id, - "archive_id": archive_id, - "paths": { - field: os.fspath(getattr(paths, field)) - for field in ( - "source_publication", - "source_artifact_root", - "source_coordination_root", - "destination_publication", - "destination_artifact_root", - "destination_coordination_root", - "archive_root", - "staging_root", - "guard_path", - ) - }, - "archive_manifest_sha256": archive_manifest_sha256, - "seed_manifest_sha256": seed_manifest_sha256, - "marker_sha256": marker_sha256, - } - payload["journal_sha256"] = sha256_payload(payload) - return payload - - -def write_prepared_journal( - *, - profile: str, - campaign_id: str, - archive_id: str, - paths: ResetTransactionPaths, - archive_manifest_sha256: str, - seed_manifest_sha256: str, - marker_sha256: str, -) -> dict[str, object]: - payload = _transaction_payload( - state="PREPARED", - profile=profile, - campaign_id=campaign_id, - archive_id=archive_id, - paths=paths, - archive_manifest_sha256=archive_manifest_sha256, - seed_manifest_sha256=seed_manifest_sha256, - marker_sha256=marker_sha256, - ) - _atomic_write_json(paths.journal_path, payload) - return payload - - -def _validated_journal(path: Path) -> dict[str, Any]: - payload = _read_object(path, label="campaign reset journal") - digest = payload.pop("journal_sha256", None) - if ( - payload.get("schema") != RESET_JOURNAL_SCHEMA - or payload.get("state") not in {"PREPARED", "COMMITTING", "COMMITTED"} - or _require_sha256(digest, label="journal_sha256") - != sha256_payload(payload) - ): - raise CampaignResetError("campaign reset journal differs") - payload["journal_sha256"] = digest - return payload - - -def _paths_from_journal(payload: Mapping[str, object]) -> ResetTransactionPaths: - raw = payload.get("paths") - if not isinstance(raw, Mapping): - raise CampaignResetError("campaign reset journal paths are malformed") - names = ( - "source_publication", - "source_artifact_root", - "source_coordination_root", - "destination_publication", - "destination_artifact_root", - "destination_coordination_root", - "archive_root", - "staging_root", - "guard_path", - ) - if set(raw) != set(names): - raise CampaignResetError("campaign reset journal path set differs") - resolved: dict[str, Path] = {} - for name in names: - value = raw.get(name) - if not isinstance(value, str) or not Path(value).is_absolute(): - raise CampaignResetError(f"campaign reset path {name} is not absolute") - resolved[name] = Path(value).resolve(strict=False) - return ResetTransactionPaths(**resolved) - - -def _rename_forward(source: Path, destination: Path, *, label: str) -> None: - if destination.exists(): - if source.exists(): - raise CampaignResetError( - f"{label}: both source and destination exist" - ) - return - if not source.exists(): - raise CampaignResetError(f"{label}: source is missing") - destination.parent.mkdir(parents=True, exist_ok=True) - os.replace(source, destination) - _fsync_directory(destination.parent) - - -def _filesystem_device(path: Path) -> int: - candidate = path.expanduser().resolve(strict=False) - while not candidate.exists(): - parent = candidate.parent - if parent == candidate: - raise CampaignResetError( - f"cannot resolve filesystem device for {path}" - ) - candidate = parent - return candidate.stat().st_dev - - -def _require_transaction_filesystem(paths: ResetTransactionPaths) -> None: - devices = { - _filesystem_device(path) - for path in ( - paths.source_publication, - paths.source_artifact_root, - paths.source_coordination_root, - paths.destination_publication, - paths.destination_artifact_root, - paths.destination_coordination_root, - paths.archive_root, - paths.staging_root, - paths.guard_path, - ) - } - if len(devices) != 1: - raise CampaignResetError( - "campaign reset journal crosses filesystem boundaries" - ) - - -def _install_publication_tree(source: Path, destination: Path) -> None: - if not source.is_dir() or source.is_symlink(): - raise CampaignResetError("staged publication is not a regular directory") - destination.mkdir(parents=True, exist_ok=True) - for staged in sorted(source.rglob("*")): - relative = staged.relative_to(source) - target = destination / relative - if staged.is_symlink(): - raise CampaignResetError( - f"staged publication contains a symlink: {staged}" - ) - if staged.is_dir(): - target.mkdir(parents=True, exist_ok=True) - continue - if not staged.is_file(): - raise CampaignResetError( - f"staged publication contains a special file: {staged}" - ) - target.parent.mkdir(parents=True, exist_ok=True) - temporary = target.with_name(f".{target.name}.{uuid.uuid4()}.tmp") - shutil.copy2(staged, temporary) - os.replace(temporary, target) - _fsync_directory(target.parent) - - -def commit_or_recover_reset(journal_path: Path) -> dict[str, object]: - """Finish a PREPARED reset transaction; repeated calls are idempotent.""" - - journal = _validated_journal(journal_path) - paths = _paths_from_journal(journal) - _require_transaction_filesystem(paths) - paths.guard_path.parent.mkdir(parents=True, exist_ok=True) - with paths.guard_path.open("a+b") as guard: - fcntl.flock(guard.fileno(), fcntl.LOCK_EX) - try: - journal = _validated_journal(journal_path) - if journal["state"] == "COMMITTED": - return journal - committing = dict(journal) - committing["state"] = "COMMITTING" - committing.pop("journal_sha256", None) - committing["journal_sha256"] = sha256_payload(committing) - _atomic_write_json(journal_path, committing) - - archive_artifacts = paths.archive_root / "artifacts" - archive_coordination = paths.archive_root / "coordination" - archive_publication = paths.archive_root / "publication" - staged_artifacts = paths.staging_root / "fresh-artifacts" - staged_coordination = paths.staging_root / "fresh-coordination" - staged_publication = paths.staging_root / "fresh-publication" - staged_archive_publication = ( - paths.staging_root / "archive-publication" - ) - staged_archive_manifest = ( - paths.staging_root / "archive-manifest.json" - ) - _rename_forward( - staged_archive_publication, - archive_publication, - label="archive publication", - ) - _rename_forward( - staged_archive_manifest, - paths.archive_root / "archive-manifest.json", - label="archive manifest", - ) - _rename_forward( - paths.source_artifact_root, - archive_artifacts, - label="archive artifact root", - ) - _rename_forward( - paths.source_coordination_root, - archive_coordination, - label="archive coordination root", - ) - _rename_forward( - staged_artifacts, - paths.destination_artifact_root, - label="install fresh artifact root", - ) - _rename_forward( - staged_coordination, - paths.destination_coordination_root, - label="install fresh coordination root", - ) - _install_publication_tree( - staged_publication, - paths.destination_publication, - ) - committed = dict(committing) - committed["state"] = "COMMITTED" - committed.pop("journal_sha256", None) - committed["journal_sha256"] = sha256_payload(committed) - archive_journal = paths.archive_root / RESET_JOURNAL_FILENAME - _atomic_write_json(archive_journal, committed) - _atomic_write_json(journal_path, committed) - return committed - finally: - fcntl.flock(guard.fileno(), fcntl.LOCK_UN) - - -__all__ = [ - "BASELINE_GATE_FILENAME", - "CAMPAIGN_MARKER_FILENAME", - "CAMPAIGN_MARKER_SCHEMA", - "EXPECTED_AMPLICOL_CELL_COUNT", - "EXPECTED_CATALOG_CELL_COUNT", - "EXPECTED_NON_AMPLICOL_CELL_COUNT", - "RESET_JOURNAL_FILENAME", - "SEED_FILENAME", - "SEED_SCHEMA", - "CampaignResetError", - "OriginalAmplicolSeed", - "ResetTransactionPaths", - "assert_campaign_marker", - "build_seed_manifest", - "campaign_marker", - "canonical_json_bytes", - "commit_or_recover_reset", - "lightweight_archive_inventory", - "load_seed_if_present", - "mark_campaign_ready", - "sha256_path", - "sha256_payload", - "stage_seed_store", - "temporary_staging_root", - "write_prepared_journal", -] diff --git a/pyamplicol/tools/performance_report/catalog.py b/pyamplicol/tools/performance_report/catalog.py deleted file mode 100644 index b4780ae46b..0000000000 --- a/pyamplicol/tools/performance_report/catalog.py +++ /dev/null @@ -1,821 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Canonical report process, mode, dataset, and cell catalog.""" - -from __future__ import annotations - -from dataclasses import dataclass, field - -from .models import ( - LEGACY_AMPLICOL_MAX_OPEN_QUARK_LINES, - Accuracy, - CellSpec, - ExecutionMode, - MatrixComparisonView, - MatrixDataset, - MeasurementSpec, - ModelKey, - ModelSpec, - ProcessFamily, - ScalarDataset, - Workload, - ZVariant, - open_quark_line_count, -) - -BUILTIN_SM = ModelSpec( - ModelKey.BUILTIN_SM, - "built-in-sm", - "Built-in Standard Model", - "built-in-sm", -) -UFO_SM = ModelSpec(ModelKey.UFO_SM, "external-sm", "UFO-SM", "json") -SCALAR_CONTACT = ModelSpec( - ModelKey.SCALAR_CONTACT, - "scalar-contact", - "Massless scalar contact model", - "json", -) -SCALAR_GRAVITY = ModelSpec( - ModelKey.SCALAR_GRAVITY, - "scalar-gravity", - "Scalar-gravity model", - "json", -) - -MODELS = { - model.key: model - for model in (BUILTIN_SM, UFO_SM, SCALAR_CONTACT, SCALAR_GRAVITY) -} - -PROCESS_FAMILIES = ( - ProcessFamily(1, "dd_z_jets", r"$d\bar d\to Z+(n-1)g$", ("d", "d~"), ("z",), 9), - ProcessFamily( - 2, - "ud_w_jets", - r"$u\bar d\to W^++(n-1)g$", - ("u", "d~"), - ("w+",), - 9, - include_cc=True, - ), - ProcessFamily( - 3, - "dd_epem_jets", - r"$d\bar d\to e^+e^-+(n-2)g$", - ("d", "d~"), - ("e+", "e-"), - 9, - ), - ProcessFamily( - 4, - "ud_epve_jets", - r"$u\bar d\to e^+\nu_e+(n-2)g$", - ("u", "d~"), - ("e+", "ve"), - 9, - include_cc=True, - ), - ProcessFamily( - 5, - "dd_zz_jets", - r"$d\bar d\to ZZ+(n-2)g$", - ("d", "d~"), - ("z", "z"), - 9, - ), - ProcessFamily( - 6, - "gg_tt_jets", - r"$gg\to t\bar t+(n-2)g$", - ("g", "g"), - ("t", "t~"), - 9, - ), - ProcessFamily( - 7, - "dd_tt_jets", - r"$d\bar d\to t\bar t+(n-2)g$", - ("d", "d~"), - ("t", "t~"), - 9, - ), - ProcessFamily( - 8, - "gg_gluons", - r"$gg\to gg+(n-2)g$", - ("g", "g"), - ("g", "g"), - 9, - ), - ProcessFamily( - 9, - "dd_zzz_jets", - r"$d\bar d\to ZZZ+(n-3)g$", - ("d", "d~"), - ("z", "z", "z"), - 9, - ), - ProcessFamily( - 10, - "dd_epemzh_jets", - r"$d\bar d\to e^+e^-ZH+(n-4)g$", - ("d", "d~"), - ("e+", "e-", "z", "h"), - 9, - ), - ProcessFamily( - 11, - "dd_ttzh_jets", - r"$d\bar d\to t\bar t ZH+(n-4)g$", - ("d", "d~"), - ("t", "t~", "z", "h"), - 9, - ), - ProcessFamily( - 12, - "dd_4l_jets", - r"$d\bar d\to e^+e^-e^+e^-+(n-4)g$", - ("d", "d~"), - ("e+", "e-", "e+", "e-"), - 9, - ), - ProcessFamily( - 13, - "dd_3q_lines", - r"$d\bar d\to u\bar u\,s\bar s+(n-4)g$", - ("d", "d~"), - ("u", "u~", "s", "s~"), - 9, - maximum_contracted_n=6, - include_3qqbar=True, - ), - ProcessFamily( - 14, - "dd_4q_lines", - r"$d\bar d\to u\bar u\,s\bar s\,c\bar c+(n-6)g$", - ("d", "d~"), - ("u", "u~", "s", "s~", "c", "c~"), - 9, - maximum_contracted_n=6, - include_3qqbar=True, - ), - ProcessFamily( - 15, - "dd_3q_identical_lines", - r"$d\bar d\to u\bar u\,u\bar u+(n-4)g$", - ("d", "d~"), - ("u", "u~", "u", "u~"), - 9, - maximum_contracted_n=6, - include_3qqbar=True, - ), -) - - -def matrix_multiplicities(accuracy: Accuracy) -> tuple[int, ...]: - """Return publication multiplicities for one matrix accuracy. - - LC retains the full report ladder. Contracted NLC/full-colour tables - expose ``n=6`` so multi-quark families can declare candidate coverage - independently of the historical AmpliCol implementation. - """ - - return tuple(range(1, 10 if accuracy is Accuracy.LC else 7)) - - -def _measurement( - mode: ExecutionMode, - model: ModelKey | None, - accuracy: Accuracy, -) -> MeasurementSpec: - if mode is ExecutionMode.AMPLICOL: - return MeasurementSpec(mode, None, accuracy, "fortran", None) - if mode is ExecutionMode.MADGRAPH: - return MeasurementSpec(mode, model, accuracy, "fortran", None) - if mode is ExecutionMode.COMPILED: - return MeasurementSpec(mode, model, accuracy, "jit", 3) - return MeasurementSpec(mode, model, accuracy, "jit", 2) - - -def _matrix_dataset( - *, - mode: ExecutionMode, - model: ModelKey, - accuracy: Accuracy, - baseline_mode: ExecutionMode, - multiplicities: tuple[int, ...] | None = None, - static_na_reason_code: str | None = None, -) -> MatrixDataset: - model_label = "Built-in SM" if model is ModelKey.BUILTIN_SM else "UFO-SM" - accuracy_label = { - Accuracy.LC: "LC", - Accuracy.NLC: "NLC", - Accuracy.FULL: "full-colour", - }[accuracy] - mode_label = { - ExecutionMode.RECURRENCE: "recurrence", - ExecutionMode.COMPILED: "compiled JIT O3", - ExecutionMode.EAGER: "eager-DAG JIT O2", - ExecutionMode.ON_THE_FLY: "on-the-fly JIT O2", - }[mode] - baseline_label = { - ExecutionMode.AMPLICOL: "AmpliCol", - ExecutionMode.MADGRAPH: "MadGraph", - ExecutionMode.RECURRENCE: "recurrence JIT O2", - }[baseline_mode] - baseline_model = ( - ModelKey.UFO_SM - if baseline_mode is ExecutionMode.MADGRAPH - else ModelKey.BUILTIN_SM - ) - stem = f"matrix_{mode.value.replace('-', '_')}_{model.value}_{accuracy.value}" - return MatrixDataset( - dataset_id=stem, - cache_name=f"{stem}.json", - table_name=f"result_{stem}_table.tex", - title=f"{model_label} {mode_label} versus {baseline_label} {accuracy_label}", - candidate=_measurement(mode, model, accuracy), - baseline=_measurement(baseline_mode, baseline_model, accuracy), - multiplicities=( - matrix_multiplicities(accuracy) - if multiplicities is None - else multiplicities - ), - static_na_reason_code=static_na_reason_code, - ) - - -MATRIX_DATASETS = tuple( - _matrix_dataset( - mode=ExecutionMode.RECURRENCE, - model=model, - accuracy=accuracy, - baseline_mode=ExecutionMode.AMPLICOL, - ) - for model in (ModelKey.BUILTIN_SM, ModelKey.UFO_SM) - for accuracy in Accuracy -) + tuple( - _matrix_dataset( - mode=mode, - model=ModelKey.BUILTIN_SM, - accuracy=accuracy, - baseline_mode=ExecutionMode.RECURRENCE, - ) - for mode in (ExecutionMode.COMPILED, ExecutionMode.EAGER) - for accuracy in Accuracy -) + tuple( - _matrix_dataset( - mode=ExecutionMode.ON_THE_FLY, - model=ModelKey.BUILTIN_SM, - accuracy=accuracy, - baseline_mode=ExecutionMode.AMPLICOL, - multiplicities=( - (1, 2, 3, 4) - if accuracy is Accuracy.LC - else matrix_multiplicities(accuracy) - ), - ) - for accuracy in Accuracy -) + tuple( - _matrix_dataset( - mode=mode, - model=ModelKey.UFO_SM, - accuracy=Accuracy.FULL, - baseline_mode=ExecutionMode.MADGRAPH, - ) - for mode in ( - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - ) -) - - -def _madgraph_full_comparison_view( - mode: ExecutionMode, -) -> MatrixComparisonView: - mode_label = { - ExecutionMode.RECURRENCE: "recurrence JIT O2", - ExecutionMode.COMPILED: "compiled JIT O3", - ExecutionMode.EAGER: "eager-DAG JIT O2", - ExecutionMode.ON_THE_FLY: "on-the-fly JIT O2", - }[mode] - stem = f"matrix_{mode.value.replace('-', '_')}_ufo_sm_full_vs_madgraph" - return MatrixComparisonView( - comparison_id=stem, - candidate_dataset_id=( - f"matrix_{mode.value.replace('-', '_')}_ufo_sm_full" - ), - baseline_dataset_id="reference_madgraph_full", - title=f"UFO-SM {mode_label} versus MadGraph full-colour", - table_name=f"result_{stem}_table.tex", - ) - - -MADGRAPH_FULL_COMPARISON_VIEWS = tuple( - _madgraph_full_comparison_view(mode) - for mode in ( - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - ) -) - -SCALAR_DATASETS = ( - ScalarDataset( - dataset_id="scalar_contact", - cache_name="scalar_contact.json", - table_name="result_scalar_contact_table.tex", - title="Scalar-contact ladder", - model=ModelKey.SCALAR_CONTACT, - process_template="scalar_0 scalar_0 > n*scalar_0", - final_particle="scalar_0", - multiplicities=tuple(range(2, 9)), - measurement=_measurement( - ExecutionMode.COMPILED, - ModelKey.SCALAR_CONTACT, - Accuracy.FULL, - ), - ), - ScalarDataset( - dataset_id="scalar_gravity", - cache_name="scalar_gravity.json", - table_name="result_scalar_gravity_table.tex", - title="Scalar-gravity ladder", - model=ModelKey.SCALAR_GRAVITY, - process_template="scalar_0 scalar_0 > n*graviton", - final_particle="graviton", - multiplicities=tuple(range(2, 5)), - measurement=_measurement( - ExecutionMode.COMPILED, - ModelKey.SCALAR_GRAVITY, - Accuracy.FULL, - ), - ), -) - -Z_VARIANTS = ( - ZVariant("reference", "Independent reference", ExecutionMode.AMPLICOL, "fortran"), - ZVariant("jit_o1", "JIT level 1", ExecutionMode.COMPILED, "jit", 1), - ZVariant( - "asm_o3", - "ASM O3", - ExecutionMode.COMPILED, - "asm", - maximum_generation_n_final=6, - static_na_reason_code="native-backend-generation-cap-n6-v1", - ), - ZVariant( - "cpp_o3", - "C++ O3", - ExecutionMode.COMPILED, - "cpp", - cpp_optimization="O3", - maximum_generation_n_final=6, - static_na_reason_code="native-backend-generation-cap-n6-v1", - ), - ZVariant("jit_o3", "JIT level 3", ExecutionMode.COMPILED, "jit", 3), - ZVariant( - "eager_jit_o2", - "eager-DAG JIT O2", - ExecutionMode.EAGER, - "jit", - 2, - ), - ZVariant( - "recurrence_jit_o2", - "recurrence JIT O2", - ExecutionMode.RECURRENCE, - "jit", - 2, - ), - ZVariant( - "on_the_fly_jit_o2", - "on-the-fly JIT O2", - ExecutionMode.ON_THE_FLY, - "jit", - 2, - ), -) - -STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT = ( - "original-amplicol-open-quark-line-limit" -) -STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6 = ( - "native-backend-generation-cap-n6-v1" -) -STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION = ( - "user cap: native C++/ASM generation is not attempted above n=6" -) - - -def z_dataset_id(model: ModelKey) -> str: - if model is ModelKey.BUILTIN_SM: - return "z_builtin_sm" - if model is ModelKey.UFO_SM: - return "z_external_sm" - raise ValueError("Z ladders support only built-in SM and UFO-SM") - - -@dataclass(frozen=True, slots=True) -class ReportCatalog: - models: dict[ModelKey, ModelSpec] - process_families: tuple[ProcessFamily, ...] - matrix_datasets: tuple[MatrixDataset, ...] - matrix_comparison_views: tuple[MatrixComparisonView, ...] - scalar_datasets: tuple[ScalarDataset, ...] - z_variants: tuple[ZVariant, ...] - _measurement_cells_cache: tuple[CellSpec, ...] | None = field( - default=None, - init=False, - repr=False, - compare=False, - hash=False, - ) - - def dataset(self, dataset_id: str) -> MatrixDataset: - matches = [ - dataset - for dataset in self.matrix_datasets - if dataset.dataset_id == dataset_id - ] - if not matches: - raise KeyError(f"unknown matrix dataset {dataset_id!r}") - return matches[0] - - def comparison_view(self, comparison_id: str) -> MatrixComparisonView: - matches = [ - view - for view in self.matrix_comparison_views - if view.comparison_id == comparison_id - ] - if not matches: - raise KeyError(f"unknown matrix comparison view {comparison_id!r}") - return matches[0] - - def matrix_cells(self) -> tuple[CellSpec, ...]: - cells: list[CellSpec] = [] - for dataset in self.matrix_datasets: - for family in self.process_families: - for n_final in dataset.multiplicities: - process = family.process(n_final) - if process is None or n_final > family.maximum_n( - dataset.candidate.accuracy - ): - continue - workloads = ( - (Workload.SELECTED_FLOW, Workload.ALL_FLOW) - if dataset.candidate.accuracy is Accuracy.LC - else (Workload.CONTRACTED,) - ) - for workload in workloads: - cells.append( - CellSpec( - dataset_id=dataset.dataset_id, - process=process, - n_final=n_final, - process_key=family.key, - measurement=dataset.candidate, - workload=workload, - ) - ) - return tuple(cells) - - def reference_cells(self) -> tuple[CellSpec, ...]: - cells: list[CellSpec] = [] - for accuracy in Accuracy: - multiplicities = matrix_multiplicities(accuracy) - for family in self.process_families: - for n_final in multiplicities: - process = family.process(n_final) - if process is None or n_final > family.maximum_n(accuracy): - continue - workloads = ( - (Workload.SELECTED_FLOW, Workload.ALL_FLOW) - if accuracy is Accuracy.LC - else (Workload.CONTRACTED,) - ) - for workload in workloads: - cells.append( - CellSpec( - dataset_id=f"reference_amplicol_{accuracy.value}", - process=process, - n_final=n_final, - process_key=family.key, - measurement=_measurement( - ExecutionMode.AMPLICOL, - None, - accuracy, - ), - workload=workload, - ) - ) - for family in self.process_families: - for n_final in matrix_multiplicities(Accuracy.FULL): - process = family.process(n_final) - if process is None or n_final > family.maximum_n(Accuracy.FULL): - continue - cells.append( - CellSpec( - dataset_id="reference_madgraph_full", - process=process, - n_final=n_final, - process_key=family.key, - measurement=_measurement( - ExecutionMode.MADGRAPH, - ModelKey.UFO_SM, - Accuracy.FULL, - ), - workload=Workload.CONTRACTED, - ) - ) - return tuple(cells) - - def scalar_cells(self) -> tuple[CellSpec, ...]: - return tuple( - CellSpec( - dataset_id=dataset.dataset_id, - process=dataset.process(n_final), - n_final=n_final, - process_key=dataset.dataset_id, - measurement=dataset.measurement, - workload=Workload.CONTRACTED, - ) - for dataset in self.scalar_datasets - for n_final in dataset.multiplicities - ) - - def z_cells(self) -> tuple[CellSpec, ...]: - cells: list[CellSpec] = [] - for model in (ModelKey.BUILTIN_SM, ModelKey.UFO_SM): - for n_final in range(1, 10): - process = PROCESS_FAMILIES[0].process(n_final) - assert process is not None - for variant in self.z_variants: - if variant.execution_mode is ExecutionMode.AMPLICOL: - continue - measurement = MeasurementSpec( - variant.execution_mode, - model, - Accuracy.LC, - variant.backend, - variant.jit_optimization_level, - ) - for workload in ( - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - ): - cells.append( - CellSpec( - dataset_id=z_dataset_id(model), - process=process, - n_final=n_final, - process_key="dd_z_jets", - measurement=measurement, - workload=workload, - variant=variant.key, - ) - ) - return tuple(cells) - - def measurement_cells(self) -> tuple[CellSpec, ...]: - cached = self._measurement_cells_cache - if cached is None: - cached = ( - *self.reference_cells(), - *self.matrix_cells(), - *self.scalar_cells(), - *self.z_cells(), - ) - object.__setattr__(self, "_measurement_cells_cache", cached) - return cached - - def cell(self, cell_id: str) -> CellSpec: - matches = [ - cell for cell in self.measurement_cells() if cell.cell_id == cell_id - ] - if len(matches) != 1: - qualifier = "unknown" if not matches else "ambiguous" - raise KeyError(f"{qualifier} report cell {cell_id!r}") - return matches[0] - - def equivalent_cells(self, cell: CellSpec) -> tuple[CellSpec, ...]: - """Return artifact owners whose generated artifact this cell may reuse.""" - - if cell.measurement.execution_mode in { - ExecutionMode.AMPLICOL, - ExecutionMode.MADGRAPH, - }: - return () - directional_otf_artifact = ( - cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - and cell.workload in {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - ) - if directional_otf_artifact and cell.workload is Workload.SELECTED_FLOW: - return () - - def identity(candidate: CellSpec) -> tuple[object, ...]: - return ( - candidate.process, - candidate.n_final, - candidate.process_key, - candidate.measurement, - None if directional_otf_artifact else candidate.workload, - ) - - expected = identity(cell) - return tuple( - sorted( - ( - candidate - for candidate in self.measurement_cells() - if candidate.cell_id != cell.cell_id - and ( - not directional_otf_artifact - or ( - candidate.workload is Workload.SELECTED_FLOW - and candidate.dataset_id == cell.dataset_id - and candidate.variant == cell.variant - ) - ) - and identity(candidate) == expected - ), - key=lambda candidate: candidate.cell_id, - ) - ) - - def baseline_cell(self, cell: CellSpec) -> CellSpec | None: - """Return the display baseline for ``cell``. - - This retains the original-AmpliCol row even when the historical - implementation cannot evaluate the process. Use - :meth:`validation_baseline_cell` for measurement dependencies. - """ - - if ( - cell.measurement.execution_mode - in {ExecutionMode.AMPLICOL, ExecutionMode.MADGRAPH} - or cell.dataset_id in { - dataset.dataset_id for dataset in self.scalar_datasets - } - ): - return None - if cell.dataset_id.startswith("z_"): - baseline_mode = ExecutionMode.AMPLICOL - dataset_id = f"reference_amplicol_{cell.measurement.accuracy.value}" - else: - dataset = self.dataset(cell.dataset_id) - baseline_mode = dataset.baseline.execution_mode - if baseline_mode is ExecutionMode.AMPLICOL: - dataset_id = f"reference_amplicol_{cell.measurement.accuracy.value}" - elif baseline_mode is ExecutionMode.MADGRAPH: - dataset_id = "reference_madgraph_full" - else: - dataset_id = ( - "matrix_recurrence_builtin_sm_" - f"{cell.measurement.accuracy.value}" - ) - return next( - candidate - for candidate in self.measurement_cells() - if candidate.dataset_id == dataset_id - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is cell.workload - and candidate.measurement.execution_mode is baseline_mode - ) - - def legacy_reference_available(self, cell: CellSpec) -> bool: - """Whether original AmpliCol can evaluate ``cell``'s concrete process.""" - - return ( - open_quark_line_count(cell.process) - <= LEGACY_AMPLICOL_MAX_OPEN_QUARK_LINES - ) - - def static_na_reason(self, cell: CellSpec) -> str | None: - """Return the catalog-authenticated reason ``cell`` is not measurable. - - Static N/A cells remain declared catalog rows so publication layout and - descriptor identities stay stable. They are excluded from campaign - planning and authenticated-current completeness because the historical - oracle cannot represent the concrete process at all. - """ - - if cell.dataset_id.startswith("matrix_"): - dataset = self.dataset(cell.dataset_id) - if dataset.static_na_reason_code is not None: - return dataset.static_na_reason_code - if cell.dataset_id.startswith("z_") and cell.variant is not None: - variant = next( - ( - candidate - for candidate in self.z_variants - if candidate.key == cell.variant - ), - None, - ) - if ( - variant is not None - and variant.maximum_generation_n_final is not None - and cell.n_final > variant.maximum_generation_n_final - ): - return variant.static_na_reason_code - if ( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and not self.legacy_reference_available(cell) - ): - return STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT - return None - - def static_na_description(self, cell: CellSpec) -> str | None: - """Return a stable human explanation for a catalog static N/A cell.""" - - reason = self.static_na_reason(cell) - if reason == STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6: - return STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION - return reason - - def validation_baseline_cell(self, cell: CellSpec) -> CellSpec | None: - """Return the executable numerical baseline for ``cell``. - - Original AmpliCol remains visible in the report for processes beyond - its three-open-line scope, but it must not censor pyAmpliCol's - otherwise model-generic recurrence measurements. - """ - - if ( - cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.dataset_id.startswith("z_") - ): - return next( - candidate - for candidate in self.measurement_cells() - if candidate.dataset_id == cell.dataset_id - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is cell.workload - and candidate.variant == "recurrence_jit_o2" - ) - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY and ( - self.dataset(cell.dataset_id).baseline.execution_mode - is not ExecutionMode.MADGRAPH - ): - return next( - candidate - for candidate in self.measurement_cells() - if candidate.dataset_id - == ( - "matrix_recurrence_builtin_sm_" - f"{cell.measurement.accuracy.value}" - ) - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is cell.workload - ) - baseline = self.baseline_cell(cell) - if ( - baseline is not None - and baseline.measurement.execution_mode is ExecutionMode.MADGRAPH - ): - # MadGraph is consumed once through the strict direct edge. - return None - if ( - baseline is not None - and baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - and not self.legacy_reference_available(cell) - ): - return None - return baseline - - -REPORT_CATALOG = ReportCatalog( - MODELS, - PROCESS_FAMILIES, - MATRIX_DATASETS, - MADGRAPH_FULL_COMPARISON_VIEWS, - SCALAR_DATASETS, - Z_VARIANTS, -) - -__all__ = [ - "BUILTIN_SM", - "MADGRAPH_FULL_COMPARISON_VIEWS", - "MATRIX_DATASETS", - "MODELS", - "PROCESS_FAMILIES", - "REPORT_CATALOG", - "SCALAR_CONTACT", - "SCALAR_DATASETS", - "SCALAR_GRAVITY", - "STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6", - "STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION", - "STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT", - "UFO_SM", - "Z_VARIANTS", - "ReportCatalog", - "matrix_multiplicities", - "z_dataset_id", -] diff --git a/pyamplicol/tools/performance_report/cli.py b/pyamplicol/tools/performance_report/cli.py deleted file mode 100644 index 64b3add7f4..0000000000 --- a/pyamplicol/tools/performance_report/cli.py +++ /dev/null @@ -1,1609 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Command-line entry point for the three-mode performance report.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import os -import shutil -import subprocess -import sys -import tempfile -from collections.abc import Mapping, Sequence -from pathlib import Path - -from .artifacts import ArtifactStoreError -from .boundary import ( - authenticate_current_delta, - load_cell_boundary, - snapshot_cell_boundary, -) -from .cache import validate_measurement -from .campaign_policy import ( - MACBOOK_M3_POLICY_NAME, - MACBOOK_M3_PROFILE, - MACBOOK_M3_Z_TABLE_F_POLICY_NAME, - STRICT_POLICY, - STRICT_POLICY_NAME, - X86_EPYC_POLICY_NAME, - PolicyMeasurementState, - validate_policy_measurement, -) -from .campaign_policy import ( - campaign_policy as resolve_campaign_policy, -) -from .catalog import REPORT_CATALOG -from .measurement_lineage import ( - CLASS_C_HZZ_IMPACT, - CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - MeasurementLineageError, - audit_measurement_lineage, - class_c_pending_path, - finalize_class_c_bridge, - load_and_audit_measurement_lineage, - load_measurement_lineage, - prepare_class_c_bridge, -) -from .models import ( - Accuracy, - ArtifactPolicy, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .prepared import ensure_report_prepared_model -from .publisher import ( - DEFAULT_EXPECTED_PAGE_COUNT, - DEFAULT_PDF_TIMEOUT_SECONDS, - DEFAULT_PUBLICATION_INTERVAL_SECONDS, - _report_source_copy_ignore, - run_publisher, - validate_published_snapshot, -) -from .runner import DEFAULT_TARGET_RUNTIME_SECONDS -from .scheduler import ( - CampaignScheduler, - CampaignSettings, - CellSelection, - plan_campaign, - select_cells, - validate_campaign_plan, -) -from .service import ( - CANONICAL_REPORT_ENTRYPOINT, - ReportPaths, - ReportService, - validate_profile_name, -) -from .source_identity import require_eligible_report_source -from .standalone_build import StandaloneBuildError, validate_latex_log -from .study_contract import ( - StudyContractError, - audit_z_table_f_policy_projection, - load_z_table_f_study_contract, - require_z_table_f_explicit_cell, - z_table_f_worker_harness_identity, -) -from .worker import _JsonlProgressSink, write_cell_result -from .worker_harness import ( - LEGACY_ADAPTER, - POLICY_ENTRYPOINT, - worker_harness_identity, -) -from .workspace import ( - ReportWorkspaceError, - export_profile, - initialize_profile, - load_profile_campaign_policy, - refresh_profile_environment, - require_active_profile_environment, -) - -_PINNED_EPYC_ORPHAN_CELL_ID = "reference-amplicol-lc-n8-gg-gluons-selected-flow" -_PINNED_EPYC_ORPHAN_ATTEMPT_ID = "83e5c9c7-dbf6-4d61-b724-f4580df2cfa3" -_PINNED_EPYC_ORPHAN_WORKER_SHA256 = ( - "5f3a42f9e3d034efedd8b670e7acbf2b54a427449106dbabc29050f3d93afbe6" -) -_PINNED_EPYC_ORPHAN_RESOURCES = { - "monitor": "external-cell-supervisor", - "peak_rss_gib": None, -} - - -def _is_pinned_epyc_orphan_without_rss( - *, - profile: str, - cell_id: str, - attempt_id: str, - worker_result_sha256: str, - result: Mapping[str, object], -) -> bool: - """Match the sole authenticated legacy worker result lacking RSS.""" - - resources = result.get("resources") - return ( - profile == "x86_EPYC" - and cell_id == _PINNED_EPYC_ORPHAN_CELL_ID - and attempt_id == _PINNED_EPYC_ORPHAN_ATTEMPT_ID - and worker_result_sha256 == _PINNED_EPYC_ORPHAN_WORKER_SHA256 - and isinstance(resources, Mapping) - and dict(resources) == _PINNED_EPYC_ORPHAN_RESOURCES - ) - - -def _repo_root() -> Path: - return Path(__file__).resolve().parents[2] - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _authenticated_worker_harness( - args: argparse.Namespace, - repo_root: Path, -) -> dict[str, object] | None: - """Recheck both checkouts before an internal split worker can run.""" - - names = ( - "measurement_source_root", - "expected_measurement_source_revision", - "expected_measurement_source_tree", - "expected_policy_wrapper_revision", - "expected_policy_wrapper_tree", - "expected_policy_entrypoint_sha256", - "expected_legacy_adapter_sha256", - "study_contract_sha256", - ) - values = {name: getattr(args, name) for name in names} - if all(value is None for value in values.values()): - return None - if any(value is None for value in values.values()): - raise ValueError( - "split worker wrapper/source options must be specified together" - ) - if args.command not in {"_prepare", "_worker"}: - raise ValueError( - "split worker wrapper/source options are restricted to workers" - ) - measured_root = ( - Path(values["measurement_source_root"]).expanduser().resolve(strict=True) - ) - if measured_root != repo_root.resolve(strict=True): - raise ValueError("worker --repo-root must equal --measurement-source-root") - measured = require_eligible_report_source(measured_root) - if ( - measured.revision != values["expected_measurement_source_revision"] - or measured.tree != values["expected_measurement_source_tree"] - ): - raise ValueError( - "worker measured-source identity differs from its authorization" - ) - wrapper_root = _repo_root().resolve(strict=True) - wrapper = require_eligible_report_source(wrapper_root) - if ( - wrapper.revision != values["expected_policy_wrapper_revision"] - or wrapper.tree != values["expected_policy_wrapper_tree"] - ): - raise ValueError( - "worker policy-wrapper identity differs from its authorization" - ) - entrypoint_sha256 = _sha256_file(wrapper_root / POLICY_ENTRYPOINT) - legacy_adapter_sha256 = _sha256_file(wrapper_root / LEGACY_ADAPTER) - if ( - entrypoint_sha256 != values["expected_policy_entrypoint_sha256"] - or legacy_adapter_sha256 != values["expected_legacy_adapter_sha256"] - ): - raise ValueError( - "worker policy-wrapper file identity differs from its authorization" - ) - return worker_harness_identity( - study_contract_sha256=str(values["study_contract_sha256"]), - policy_wrapper_revision=wrapper.revision, - policy_wrapper_tree=wrapper.tree, - policy_entrypoint_sha256=entrypoint_sha256, - legacy_adapter_sha256=legacy_adapter_sha256, - measured_source_revision=measured.revision, - measured_source_tree=measured.tree, - ) - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description="Build and populate the pyAmpliCol performance report.", - ) - parser.add_argument( - "--repo-root", - type=Path, - default=_repo_root(), - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--report-profile", - type=validate_profile_name, - help=( - "use docs/performance_reports/PROFILE with isolated evaluator " - "artifacts and coordination state" - ), - ) - parser.add_argument("--docs-dir", type=Path, help=argparse.SUPPRESS) - parser.add_argument("--artifact-root", type=Path, help=argparse.SUPPRESS) - parser.add_argument("--coordination-root", type=Path, help=argparse.SUPPRESS) - parser.add_argument( - "--class-c-ancestor-runtime-root", - type=Path, - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--measurement-source-root", - type=Path, - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--expected-measurement-source-revision", - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--expected-measurement-source-tree", - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--expected-policy-wrapper-revision", - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--expected-policy-wrapper-tree", - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--expected-policy-entrypoint-sha256", - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--expected-legacy-adapter-sha256", - help=argparse.SUPPRESS, - ) - parser.add_argument( - "--study-contract-sha256", - help=argparse.SUPPRESS, - ) - subparsers = parser.add_subparsers(dest="command", required=True) - for command, help_text in ( - ("validate", "validate canonical caches and rendered tables"), - ("audit", "verify exact cache coverage and checked-in table rendering"), - ("reset", "reset all report measurements to N/A"), - ("render", "merge immutable results and render tables"), - ("recover", "recover immutable worker results and render tables"), - ): - item = subparsers.add_parser(command, help=help_text) - if command in {"reset", "render", "recover"}: - item.add_argument( - "--compile", - action="store_true", - help="compile pyAmpliCol.pdf after publishing tables", - ) - - study_audit = subparsers.add_parser( - "audit-z-table-study", - help=argparse.SUPPRESS, - ) - study_audit.add_argument("--study-contract", type=Path, required=True) - study_audit.add_argument("--maximum-n", type=int, required=True) - - publish_snapshot = subparsers.add_parser( - "publish-snapshot", - help="copy, validate, render, and compile one current-cache snapshot", - ) - publish_snapshot.add_argument("--watch", action="store_true") - publish_snapshot.add_argument( - "--interval-seconds", - type=float, - default=DEFAULT_PUBLICATION_INTERVAL_SECONDS, - ) - publish_snapshot.add_argument( - "--pdf-timeout-seconds", - type=float, - default=DEFAULT_PDF_TIMEOUT_SECONDS, - ) - publish_snapshot.add_argument( - "--expected-page-count", - type=int, - default=DEFAULT_EXPECTED_PAGE_COUNT, - ) - subparsers.add_parser( - "validate-snapshot", - help="validate the published cache/table/PDF snapshot identities", - ) - snapshot_boundary = subparsers.add_parser( - "snapshot-cell-boundary", - help="snapshot one authoritative current and immutable-attempt inventory", - ) - snapshot_boundary.add_argument("--cell-id", required=True) - accept_boundary = subparsers.add_parser( - "accept-cell-boundary", - help="authenticate a new current without consulting report caches", - ) - accept_boundary.add_argument("--cell-id", required=True) - accept_boundary.add_argument("--expected-attempt-id", required=True) - accept_boundary.add_argument( - "--before-snapshot", - type=Path, - required=True, - ) - - initialize = subparsers.add_parser( - "init-profile", - help="create an isolated architecture-specific report workspace", - ) - initialize.add_argument("profile", type=validate_profile_name) - initialize.add_argument( - "--source-profile", - type=validate_profile_name, - help="copy publication inputs from another report profile instead of docs/", - ) - initialize.add_argument( - "--reset-measurements", - action="store_true", - help="replace copied measurements with canonical N/A caches and tables", - ) - initialize.add_argument( - "--measurement-policy", - choices=( - STRICT_POLICY_NAME, - MACBOOK_M3_POLICY_NAME, - X86_EPYC_POLICY_NAME, - ), - help=( - "bind a canonical completion/resource policy; defaults to the " - "matching architecture policy for macbook_M3 or x86_EPYC and " - "strict completion for every other profile" - ), - ) - - refresh_environment = subparsers.add_parser( - "refresh-profile-environment", - help="authenticate and record the exact installed measurement runtime", - ) - refresh_environment.add_argument("--expected-source-revision", required=True) - - prepare_bridge = subparsers.add_parser( - "prepare-class-c-bridge", - help="snapshot an exact frozen campaign before one bounded source correction", - ) - prepare_bridge.add_argument("--ancestor-revision", required=True) - prepare_bridge.add_argument("--descendant-revision", required=True) - prepare_bridge.add_argument( - "--impact", - choices=( - CLASS_C_HZZ_IMPACT, - CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - ), - required=True, - ) - - finalize_bridge = subparsers.add_parser( - "finalize-class-c-bridge", - help="authenticate the corrected runtime and publish its source lineage", - ) - finalize_bridge.add_argument("--ancestor-revision", required=True) - finalize_bridge.add_argument("--descendant-revision", required=True) - - audit_bridge = subparsers.add_parser( - "audit-source-bridge", - help="audit one finalized mixed-source profile without changing it", - ) - audit_bridge.add_argument("--expected-active-source-revision", required=True) - - seal_orphan = subparsers.add_parser( - "seal-existing-worker-result", - help="authenticate and seal one completed controller-orphaned worker result", - ) - seal_orphan.add_argument("--cell-id", required=True) - seal_orphan.add_argument("--attempt-id", required=True) - seal_orphan.add_argument("--worker-result-sha256", required=True) - seal_orphan.add_argument( - "--artifact-policy", - choices=tuple(policy.value for policy in ArtifactPolicy), - required=True, - ) - seal_orphan.add_argument("--expected-source-revision", required=True) - - export = subparsers.add_parser( - "export-profile", - help="copy a tracked report workspace without evaluator artifacts", - ) - export.add_argument("profile", type=validate_profile_name) - export.add_argument("destination", type=Path) - export.add_argument( - "--include-pdf", - action=argparse.BooleanOptionalAction, - default=True, - ) - - final_audit = subparsers.add_parser( - "final-audit", - help=( - "run the measured-SHA/runtime and report-only publication " - "numerical, artifact, and PDF gate" - ), - ) - final_audit.add_argument("--expected-source-revision", required=True) - final_audit.add_argument( - "--publication-revision", - help="require the clean publication checkout to equal this full Git SHA", - ) - final_audit.add_argument("--max-n-final", type=int, default=9) - final_audit.add_argument("--expected-cell-count", type=int, default=2198) - final_audit.add_argument( - "--structural-only", - action="store_true", - help="authenticate records and artifacts without numerical replay", - ) - - worker = subparsers.add_parser("_worker", help=argparse.SUPPRESS) - worker.add_argument("--cell-id", required=True) - worker.add_argument("--attempt-root", type=Path, required=True) - worker.add_argument("--result-json", type=Path, required=True) - worker.add_argument("--log-path", type=Path) - worker.add_argument("--baseline-json", type=Path) - worker.add_argument( - "--expected-authority-cell-id", - action="append", - default=[], - help=argparse.SUPPRESS, - ) - worker.add_argument( - "--selected-authority-cell-id", - help=argparse.SUPPRESS, - ) - worker.add_argument( - "--peer-json", - action="append", - nargs=2, - metavar=("CELL_ID", "PATH"), - default=[], - help=argparse.SUPPRESS, - ) - worker.add_argument("--prepared-model", type=Path) - worker.add_argument("--reused-measurement-json", type=Path) - worker.add_argument("--legacy-repository", type=Path, help=argparse.SUPPRESS) - worker.add_argument( - "--legacy-source-repository", - type=Path, - help=argparse.SUPPRESS, - ) - worker.add_argument("--legacy-workspace", type=Path, help=argparse.SUPPRESS) - worker.add_argument( - "--legacy-copy-source", - action="store_true", - help=argparse.SUPPRESS, - ) - worker.add_argument("--legacy-source-revision", help=argparse.SUPPRESS) - worker.add_argument("--madgraph", type=Path, help=argparse.SUPPRESS) - worker.add_argument( - "--target-runtime", - type=float, - default=DEFAULT_TARGET_RUNTIME_SECONDS, - ) - worker.add_argument("--batch-size", type=int, default=128) - worker.add_argument("--cell-cores", type=int, default=1) - worker.add_argument( - "--amplicol-build-jobs", - type=int, - default=1, - help=argparse.SUPPRESS, - ) - worker.add_argument("--memory-limit-bytes", type=int, help=argparse.SUPPRESS) - worker.add_argument("--warmup-runs", type=int, default=2) - worker.add_argument("--minimum-samples", type=int, default=5) - worker.add_argument("--progress-jsonl", type=Path) - worker.add_argument("--worker-wall-limit", type=float, help=argparse.SUPPRESS) - worker.add_argument( - "--profiling-time-limit", - type=float, - help=argparse.SUPPRESS, - ) - worker.add_argument( - "--validation-time-limit", - type=float, - help=argparse.SUPPRESS, - ) - worker.add_argument("--generation-lock-path", type=Path, help=argparse.SUPPRESS) - worker.add_argument("--manual-source-revision", help=argparse.SUPPRESS) - worker.add_argument("--manual-source-tree", help=argparse.SUPPRESS) - worker.add_argument("--phase-state-path", type=Path, help=argparse.SUPPRESS) - worker.add_argument("--phase-state-run-id", help=argparse.SUPPRESS) - worker.add_argument( - "--phase-state-authentication-key", - help=argparse.SUPPRESS, - ) - - prepare = subparsers.add_parser("_prepare", help=argparse.SUPPRESS) - prepare.add_argument( - "--model", - required=True, - choices=(ModelKey.BUILTIN_SM.value, ModelKey.UFO_SM.value), - ) - prepare.add_argument("--result-json", type=Path, required=True) - prepare.add_argument("--progress-jsonl", type=Path) - prepare.add_argument("--cell-cores", type=int, default=1) - prepare.add_argument("--producer-revision", help=argparse.SUPPRESS) - - populate = subparsers.add_parser( - "populate", - help="run selected cells through isolated direct-API workers", - ) - populate.add_argument("--dataset", action="append", default=[]) - populate.add_argument( - "--mode", - action="append", - choices=tuple(mode.value for mode in ExecutionMode), - default=[], - ) - populate.add_argument( - "--model", - action="append", - choices=tuple(model.value for model in ModelKey), - default=[], - ) - populate.add_argument( - "--accuracy", - action="append", - choices=tuple(accuracy.value for accuracy in Accuracy), - default=[], - ) - populate.add_argument("--process-key", action="append", default=[]) - populate.add_argument("--process", action="append", default=[]) - populate.add_argument("--n-final", action="append", default=[]) - populate.add_argument( - "--variant", - action="append", - default=[], - help=( - "filter named Z implementations; rows without a variant dimension " - "remain eligible" - ), - ) - populate.add_argument( - "--workload", - choices=("selected-flow", "all-flow", "both", "contracted"), - ) - populate.add_argument("--cell-id", action="append", default=[]) - populate.add_argument( - "--exclude-cell-id", - action="append", - default=[], - help=( - "omit a held cell and any selected cell whose unresolved " - "dependency closure reaches it" - ), - ) - populate.add_argument("--missing-only", action="store_true") - populate.add_argument("--rerun", action="store_true") - populate.add_argument( - "--artifact-policy", - choices=tuple(policy.value for policy in ArtifactPolicy), - default=ArtifactPolicy.REGENERATE.value, - ) - populate.add_argument("--workers", type=int, default=1) - populate.add_argument("--cell-cores", type=int, default=1) - populate.add_argument("--amplicol-build-jobs", type=int, default=1) - populate.add_argument( - "--target-runtime", - type=float, - default=DEFAULT_TARGET_RUNTIME_SECONDS, - ) - populate.add_argument("--batch-size", type=int, default=128) - populate.add_argument("--timeout-seconds", type=float) - populate.add_argument( - "--generation-time-limit-seconds", - type=float, - help="limit only the authenticated Generator.generate phase", - ) - populate.add_argument("--max-ram-gib", type=float) - populate.add_argument( - "--max-ram-gb", - type=float, - help="decimal GB ceiling for each worker process tree", - ) - populate.add_argument("--campaign-max-ram-gib", type=float) - populate.add_argument( - "--campaign-max-ram-gb", - type=float, - help="decimal GB ceiling for all concurrent worker process trees", - ) - populate.add_argument( - "--limit-gib", - type=float, - help="compatibility alias for --campaign-max-ram-gib", - ) - populate.add_argument("--allow-symbolica-parallel", action="store_true") - populate.add_argument( - "--fast-lineage", - action="store_true", - help=argparse.SUPPRESS, - ) - populate.add_argument("--dry-run", action="store_true") - populate.add_argument( - "--refresh-pdf", - choices=("never", "end"), - default="never", - ) - populate.add_argument( - "--study-policy", - choices=(MACBOOK_M3_Z_TABLE_F_POLICY_NAME,), - help=argparse.SUPPRESS, - ) - populate.add_argument( - "--study-contract", - type=Path, - help=argparse.SUPPRESS, - ) - populate.add_argument( - "--reuse-cross-source-comparison-dependencies", action="store_true" - ) - return parser - - -def _git_commit(root: Path, revision: str) -> str: - completed = subprocess.run( - ("git", "-C", str(root), "rev-parse", "--verify", f"{revision}^{{commit}}"), - check=False, - capture_output=True, - text=True, - ) - value = completed.stdout.strip() - if ( - completed.returncode != 0 - or len(value) != 40 - or any(character not in "0123456789abcdef" for character in value) - ): - raise MeasurementLineageError( - f"cannot resolve Class-C runtime revision {revision!r}" - ) - return value - - -def _class_c_ancestor_runtime_identity( - repo_root: Path, - runtime_root: Path, - *, - ancestor_revision: str, - descendant_revision: str, -) -> dict[str, object]: - """Authenticate the ancestor package selected by the direct bootstrap.""" - - try: - root = runtime_root.expanduser().resolve(strict=True) - source_package = (root / "src/pyamplicol").resolve(strict=True) - except OSError as error: - raise MeasurementLineageError( - "Class-C ancestor runtime root is unavailable" - ) from error - if root == repo_root.resolve(strict=False) or not source_package.is_dir(): - raise MeasurementLineageError( - "Class-C ancestor runtime must be a separate source checkout" - ) - ancestor = _git_commit(root, ancestor_revision) - descendant = _git_commit(repo_root, descendant_revision) - if _git_commit(root, "HEAD") != ancestor: - raise MeasurementLineageError( - "Class-C ancestor runtime checkout is not at the requested ancestor" - ) - if _git_commit(repo_root, "HEAD") != descendant: - raise MeasurementLineageError( - "Class-C controller checkout is not at the requested descendant" - ) - tracked = subprocess.run( - ( - "git", - "-C", - str(root), - "status", - "--porcelain=v1", - "--untracked-files=no", - ), - check=False, - capture_output=True, - text=True, - ) - if tracked.returncode != 0 or tracked.stdout: - raise MeasurementLineageError( - "Class-C ancestor runtime has tracked source modifications" - ) - - import pyamplicol - - try: - package_origin = Path(str(pyamplicol.__file__)).resolve(strict=True) - except OSError as error: - raise MeasurementLineageError( - "loaded Class-C ancestor package origin is unavailable" - ) from error - if package_origin.parent != source_package: - raise MeasurementLineageError( - "loaded pyamplicol package does not originate in the Class-C " - "ancestor runtime checkout" - ) - from .runtime_evidence import established_preimport_runtime_identity - - preimport = established_preimport_runtime_identity() - tree = preimport.get("python_package_tree") - native = preimport.get("native_extension") - if ( - not isinstance(tree, Mapping) - or tree.get("roots") != [str(source_package)] - or not isinstance(native, Mapping) - ): - raise MeasurementLineageError( - "Class-C ancestor package was not exclusively preauthenticated" - ) - native_path = native.get("path") - if ( - not isinstance(native_path, str) - or Path(native_path).resolve(strict=False).parent != source_package - ): - raise MeasurementLineageError( - "Class-C ancestor native extension was not preauthenticated" - ) - return { - "revision": ancestor, - "root": str(root), - "package_root": str(source_package), - "python_package_tree_sha256": tree.get("sha256"), - "native_extension_sha256": native.get("sha256"), - } - - -def _multiplicities(values: Sequence[str]) -> frozenset[int]: - selected: set[int] = set() - for value in values: - for item in value.split(","): - text = item.strip() - if not text: - continue - if ".." in text: - start_text, stop_text = text.split("..", 1) - start, stop = int(start_text), int(stop_text) - if start > stop: - raise ValueError("n-final range start must not exceed its end") - selected.update(range(start, stop + 1)) - else: - selected.add(int(text)) - if any(value < 1 for value in selected): - raise ValueError("n-final values must be positive") - return frozenset(selected) - - -def _workloads(value: str | None) -> frozenset[Workload]: - if value is None: - return frozenset() - if value == "both": - return frozenset({Workload.SELECTED_FLOW, Workload.ALL_FLOW}) - return frozenset({Workload(value)}) - - -def _selection(args: argparse.Namespace) -> CellSelection: - return CellSelection( - datasets=frozenset(args.dataset), - modes=frozenset(ExecutionMode(value) for value in args.mode), - models=frozenset(ModelKey(value) for value in args.model), - accuracies=frozenset(Accuracy(value) for value in args.accuracy), - process_keys=frozenset(args.process_key), - processes=frozenset(args.process), - multiplicities=_multiplicities(args.n_final), - variants=frozenset(args.variant), - workloads=_workloads(args.workload), - cell_ids=frozenset(args.cell_id), - ) - - -def _gib_bytes(value: float | None) -> int | None: - if value is None: - return None - if value <= 0.0: - raise ValueError("RAM limits must be positive") - return int(value * 1024**3) - - -def _gb_bytes(value: float | None) -> int | None: - if value is None: - return None - if value <= 0.0: - raise ValueError("RAM limits must be positive") - return int(value * 1_000_000_000) - - -def _compile_pdf(service: ReportService) -> Path: - latexmk = shutil.which("latexmk") - if latexmk is None: - raise FileNotFoundError("latexmk is required for --compile") - environment = os.environ.copy() - environment.update({"LANG": "C", "LC_ALL": "C", "LC_CTYPE": "C"}) - build_root = service.paths.artifact_root / "pdf-builds" - build_root.mkdir(parents=True, exist_ok=True) - staging = Path(tempfile.mkdtemp(prefix="report-pdf-", dir=build_root)) - try: - build_docs = staging / "docs" - shutil.copytree( - service.paths.docs_dir, - build_docs, - ignore=_report_source_copy_ignore( - service.paths.docs_dir, - "*.aux", - "*.fdb_latexmk", - "*.fls", - "*.log", - "*.out", - "*.toc", - "pyAmpliCol.pdf", - ".coordination", - ), - ) - completed = subprocess.run( - ( - latexmk, - "-pdf", - "-interaction=nonstopmode", - "-halt-on-error", - "-file-line-error", - "pyAmpliCol.tex", - ), - cwd=build_docs, - check=False, - capture_output=True, - text=True, - env=environment, - ) - if completed.returncode != 0: - tail = "\n".join( - (*completed.stdout.splitlines(), *completed.stderr.splitlines())[-80:] - ) - raise RuntimeError( - f"latexmk failed with exit {completed.returncode}:\n{tail}" - ) - latex_log = build_docs / "pyAmpliCol.log" - try: - log = latex_log.read_text(encoding="utf-8", errors="replace") - validate_latex_log(log) - except OSError as error: - raise RuntimeError(f"cannot read LaTeX log: {error}") from error - except StandaloneBuildError as error: - raise RuntimeError(str(error)) from error - built_pdf = build_docs / "pyAmpliCol.pdf" - if not built_pdf.is_file() or built_pdf.stat().st_size == 0: - raise RuntimeError("latexmk did not produce a non-empty PDF") - output = service.paths.docs_dir / "pyAmpliCol.pdf" - temporary = output.with_name(f".{output.name}.new") - shutil.copy2(built_pdf, temporary) - temporary.replace(output) - return output - finally: - shutil.rmtree(staging, ignore_errors=True) - - -def _launch_async_publication( - service: ReportService, - *, - entrypoint: Path | None = None, -) -> Path: - """Request a one-shot report publication without waiting for it.""" - - entrypoint_candidate = ( - service.paths.repo_root / CANONICAL_REPORT_ENTRYPOINT - if entrypoint is None - else entrypoint - ).expanduser() - if entrypoint_candidate.is_symlink(): - raise RuntimeError("asynchronous publication entrypoint is unavailable") - selected_entrypoint = entrypoint_candidate.resolve(strict=True) - if not selected_entrypoint.is_file(): - raise RuntimeError("asynchronous publication entrypoint is unavailable") - log_root = service.paths.artifact_root / "publication-logs" - log_root.mkdir(parents=True, exist_ok=True) - log_path = log_root / "refresh-pdf-end.log" - command = ( - sys.executable, - "-I", - "-S", - "-B", - os.fspath(selected_entrypoint), - "--repo-root", - os.fspath(service.paths.repo_root), - "--docs-dir", - os.fspath(service.paths.docs_dir), - "--artifact-root", - os.fspath(service.paths.artifact_root), - "--coordination-root", - os.fspath(service.paths.coordination_root), - "publish-snapshot", - ) - environment = os.environ.copy() - for name in ( - "PYAMPLICOL_EXACT_PYTHON_REEXEC", - "PYAMPLICOL_EXACT_IMPORT_PATHS", - "PYTHONPYCACHEPREFIX", - ): - environment.pop(name, None) - with log_path.open("ab") as stream: - subprocess.Popen( - command, - stdin=subprocess.DEVNULL, - stdout=stream, - stderr=subprocess.STDOUT, - env=environment, - start_new_session=True, - close_fds=True, - ) - return log_path - - -def main(argv: Sequence[str] | None = None) -> int: - parser = _parser() - args = parser.parse_args(argv) - repo_root = args.repo_root.expanduser().resolve(strict=False) - try: - worker_harness = _authenticated_worker_harness(args, repo_root) - except (OSError, TypeError, ValueError) as error: - parser.error(str(error)) - if ( - args.class_c_ancestor_runtime_root is not None - and args.command != "prepare-class-c-bridge" - ): - parser.error( - "--class-c-ancestor-runtime-root is restricted to prepare-class-c-bridge" - ) - if args.command == "init-profile": - output = initialize_profile( - repo_root, - args.profile, - source_profile=args.source_profile, - reset_measurements=args.reset_measurements, - measurement_policy=args.measurement_policy, - ) - print(output.relative_to(repo_root)) - return 0 - if args.command == "export-profile": - output = export_profile( - repo_root, - args.profile, - args.destination, - include_pdf=args.include_pdf, - ) - print(output) - return 0 - - service = ReportService( - ReportPaths.from_repo( - repo_root, - profile=args.report_profile, - docs_dir=args.docs_dir, - artifact_root=args.artifact_root, - coordination_root=args.coordination_root, - ) - ) - - if args.command == "publish-snapshot": - run_publisher( - service, - watch=args.watch, - interval_seconds=args.interval_seconds, - expected_page_count=args.expected_page_count, - pdf_timeout_seconds=args.pdf_timeout_seconds, - ) - return 0 - if args.command == "validate-snapshot": - print( - json.dumps( - validate_published_snapshot(service), - allow_nan=False, - sort_keys=True, - ) - ) - return 0 - if args.command == "snapshot-cell-boundary": - if args.cell_id not in { - cell.cell_id for cell in REPORT_CATALOG.measurement_cells() - }: - parser.error(f"unknown --cell-id {args.cell_id!r}") - print( - json.dumps( - snapshot_cell_boundary(service.store, args.cell_id), - allow_nan=False, - sort_keys=True, - ) - ) - return 0 - if args.command == "accept-cell-boundary": - try: - cell = REPORT_CATALOG.cell(args.cell_id) - except KeyError: - parser.error(f"unknown --cell-id {args.cell_id!r}") - accepted = authenticate_current_delta( - service.store, - cell_id=cell.cell_id, - expected_attempt_id=args.expected_attempt_id, - before=load_cell_boundary(args.before_snapshot), - validate_result=lambda result: validate_measurement( - result, - expected_cell=cell, - ), - ) - print(json.dumps(accepted, allow_nan=False, sort_keys=True)) - return 0 - if args.command == "validate": - print(json.dumps(service.validate(), sort_keys=True)) - return 0 - if args.command == "audit": - print(json.dumps(service.audit(), sort_keys=True)) - return 0 - if args.command == "audit-z-table-study": - try: - contract = load_z_table_f_study_contract( - args.study_contract, - repo_root, - Path(__file__).resolve().parents[2], - prior_store=service.store, - ) - result = audit_z_table_f_policy_projection( - contract, - service, - maximum_n=args.maximum_n, - ) - except (OSError, TypeError, ValueError) as error: - parser.error(str(error)) - print(json.dumps(result, allow_nan=False, sort_keys=True)) - return 0 - if args.command == "refresh-profile-environment": - if args.report_profile is None: - parser.error("refresh-profile-environment requires --report-profile") - environment = refresh_profile_environment( - repo_root, - args.report_profile, - expected_source_revision=args.expected_source_revision, - ) - print(json.dumps(environment, allow_nan=False, sort_keys=True)) - return 0 - if args.command == "prepare-class-c-bridge": - if args.report_profile is None: - parser.error("prepare-class-c-bridge requires --report-profile") - ancestor_runtime = ( - None - if args.class_c_ancestor_runtime_root is None - else _class_c_ancestor_runtime_identity( - repo_root, - args.class_c_ancestor_runtime_root, - ancestor_revision=args.ancestor_revision, - descendant_revision=args.descendant_revision, - ) - ) - prepared = prepare_class_c_bridge( - repo_root, - service.paths.docs_dir, - service.store, - ancestor_revision=args.ancestor_revision, - descendant_revision=args.descendant_revision, - impact=args.impact, - ) - pending = class_c_pending_path( - service.store, - ancestor_revision=str(prepared["ancestor_revision"]), - descendant_revision=str(prepared["descendant_revision"]), - ) - print( - json.dumps( - { - "pending_locator": pending.relative_to( - service.paths.artifact_root - ).as_posix(), - "current_snapshot_sha256": prepared["current_snapshot_sha256"], - **( - {} - if ancestor_runtime is None - else {"ancestor_runtime": ancestor_runtime} - ), - }, - sort_keys=True, - ) - ) - return 0 - if args.command == "finalize-class-c-bridge": - if args.report_profile is None: - parser.error("finalize-class-c-bridge requires --report-profile") - pending = class_c_pending_path( - service.store, - ancestor_revision=args.ancestor_revision, - descendant_revision=args.descendant_revision, - ) - finalized = finalize_class_c_bridge( - repo_root, - service.paths.docs_dir, - service.store, - pending_path=pending, - expected_active_source_revision=args.descendant_revision, - ) - print( - json.dumps( - { - "lineage": (service.paths.docs_dir / "measurement_lineage.json") - .relative_to(repo_root) - .as_posix(), - "descendant_revision": finalized["descendant_revision"], - }, - sort_keys=True, - ) - ) - return 0 - if args.command == "audit-source-bridge": - if args.report_profile is None: - parser.error("audit-source-bridge requires --report-profile") - result = audit_measurement_lineage( - repo_root, - service.paths.docs_dir, - service.store, - expected_active_source_revision=args.expected_active_source_revision, - ) - print(json.dumps(result, allow_nan=False, sort_keys=True)) - return 0 - if args.command == "seal-existing-worker-result": - if args.report_profile is None: - parser.error("seal-existing-worker-result requires --report-profile") - source = require_eligible_report_source(repo_root) - if source.revision != args.expected_source_revision: - parser.error("active source does not match --expected-source-revision") - require_active_profile_environment( - repo_root, - args.report_profile, - expected_source_revision=source.revision, - ) - try: - cell = REPORT_CATALOG.cell(args.cell_id) - except KeyError: - parser.error(f"unknown --cell-id {args.cell_id!r}") - policy = load_profile_campaign_policy( - repo_root, - args.report_profile, - expected_source_revision=source.revision, - ) - - def validate_orphan_result( - result: Mapping[str, object], - attempt_root: Path, - ) -> None: - validate_measurement(result, expected_cell=cell) - provenance = result.get("provenance") - artifact = result.get("artifact") - if ( - result.get("status") != ResultStatus.OK.value - or not isinstance(provenance, Mapping) - or provenance.get("report_source_revision") != source.revision - or provenance.get("report_source_tree") != source.tree - or provenance.get("report_measured_source_revision") != source.revision - or provenance.get("report_measured_source_tree") != source.tree - or not isinstance(artifact, Mapping) - or artifact.get("path") != os.fspath(attempt_root / "artifact") - or provenance.get("worker_log") - != os.fspath(attempt_root / "worker.log") - or not (attempt_root / "artifact").is_dir() - or (attempt_root / "artifact").is_symlink() - or not (attempt_root / "worker.log").is_file() - or (attempt_root / "worker.log").is_symlink() - ): - raise ValueError( - "orphan worker result lacks exact source/artifact/log evidence" - ) - allow_unavailable_resources = _is_pinned_epyc_orphan_without_rss( - profile=args.report_profile, - cell_id=args.cell_id, - attempt_id=args.attempt_id, - worker_result_sha256=args.worker_result_sha256, - result=result, - ) - state = validate_policy_measurement( - policy, - args.report_profile, - cell, - result, - expected_source_revision=source.revision, - expected_source_tree=source.tree, - allow_pinned_orphan_unavailable_resources=(allow_unavailable_resources), - ) - if state is not PolicyMeasurementState.SUCCESS: - raise ValueError( - "orphan worker result is not a successful policy measurement" - ) - - try: - record = service.store.seal_existing_worker_result( - args.cell_id, - args.attempt_id, - worker_result_sha256=args.worker_result_sha256, - artifact_policy=ArtifactPolicy(args.artifact_policy), - validate_result=validate_orphan_result, - ) - except (ValueError, OSError, ArtifactStoreError) as error: - parser.error(str(error)) - print( - json.dumps( - { - "cell_id": record.cell_id, - "attempt_id": record.attempt_id, - "manifest_sha256": record.manifest_sha256, - "result_sha256": hashlib.sha256( - record.result_path.read_bytes() - ).hexdigest(), - "resource_monitoring": ( - "unavailable-pinned-worker-result" - if _is_pinned_epyc_orphan_without_rss( - profile=args.report_profile, - cell_id=args.cell_id, - attempt_id=args.attempt_id, - worker_result_sha256=args.worker_result_sha256, - result=record.result, - ) - else "available" - ), - }, - sort_keys=True, - ) - ) - return 0 - if args.command == "final-audit": - from .final_audit import audit_final_report - - if args.report_profile is None: - parser.error("final-audit requires --report-profile") - require_active_profile_environment( - repo_root, - args.report_profile, - expected_source_revision=args.expected_source_revision, - ) - result = audit_final_report( - repo_root, - expected_source_revision=args.expected_source_revision, - expected_publication_revision=args.publication_revision, - max_n_final=args.max_n_final, - expected_cell_count=args.expected_cell_count, - replay=not args.structural_only, - service=service, - ) - print(json.dumps(result, allow_nan=False, sort_keys=True)) - return 0 if result["final_gate_complete"] is True else 2 - if args.command == "populate": - active_study_contract: Mapping[str, object] | None = None - try: - requested = select_cells(_selection(args)) - if not requested: - parser.error("cell filters select no report cells") - catalog_ids = {cell.cell_id for cell in REPORT_CATALOG.measurement_cells()} - unknown_exclusions = sorted( - set(args.exclude_cell_id).difference(catalog_ids) - ) - if unknown_exclusions: - parser.error( - "unknown --exclude-cell-id values: " + ", ".join(unknown_exclusions) - ) - if args.max_ram_gib is not None and args.max_ram_gb is not None: - parser.error("--max-ram-gib and --max-ram-gb are mutually exclusive") - if args.campaign_max_ram_gb is not None and ( - args.campaign_max_ram_gib is not None or args.limit_gib is not None - ): - parser.error( - "--campaign-max-ram-gb is mutually exclusive with " - "--campaign-max-ram-gib and --limit-gib" - ) - campaign_limit_gib = ( - args.campaign_max_ram_gib - if args.campaign_max_ram_gib is not None - else args.limit_gib - ) - source_identity = require_eligible_report_source(repo_root) - expected_revision = source_identity.revision - if args.fast_lineage and args.report_profile is None: - parser.error("--fast-lineage requires --report-profile") - original_amplicol_seed = ( - None - if args.report_profile is None - else service._original_amplicol_seed() - ) - if args.report_profile is None: - measurement_lineage = None - elif args.fast_lineage: - measurement_lineage = load_measurement_lineage( - repo_root, - service.paths.docs_dir, - expected_active_revision=expected_revision, - expected_active_tree=source_identity.tree, - ) - if measurement_lineage is None and original_amplicol_seed is None: - raise MeasurementLineageError( - "--fast-lineage requires a finalized measurement lineage " - "or authenticated original-AmpliCol campaign seed" - ) - else: - measurement_lineage = load_and_audit_measurement_lineage( - repo_root, - service.paths.docs_dir, - service.store, - expected_active_source_revision=expected_revision, - ) - policy_profile = args.report_profile - if args.study_policy is not None: - if args.report_profile is not None: - raise ValueError( - "--study-policy cannot be combined with --report-profile" - ) - if args.study_contract is None: - raise ValueError("--study-policy requires --study-contract") - if ( - len(args.cell_id) != 1 - or args.dataset - or args.mode - or args.model - or args.accuracy - or args.process_key - or args.process - or args.n_final - or args.variant - or args.workload is not None - ): - raise ValueError( - "--study-policy requires exactly one explicit " - "--cell-id and no broad cell selectors" - ) - active_study_contract = load_z_table_f_study_contract( - args.study_contract, - repo_root, - Path(__file__).resolve().parents[2], - prior_store=service.store, - ) - require_z_table_f_explicit_cell( - active_study_contract, - args.cell_id[0], - ) - campaign_policy = resolve_campaign_policy(args.study_policy) - policy_profile = MACBOOK_M3_PROFILE - elif args.study_contract is not None: - raise ValueError("--study-contract requires --study-policy") - elif args.report_profile is None: - campaign_policy = STRICT_POLICY - else: - campaign_policy = load_profile_campaign_policy( - repo_root, - args.report_profile, - expected_source_revision=expected_revision, - ) - settings = CampaignSettings( - workers=args.workers, - cell_cores=args.cell_cores, - amplicol_build_jobs=args.amplicol_build_jobs, - target_runtime_seconds=args.target_runtime, - batch_size=args.batch_size, - timeout_seconds=args.timeout_seconds, - generation_time_limit_seconds=args.generation_time_limit_seconds, - max_rss_bytes=( - _gb_bytes(args.max_ram_gb) - if args.max_ram_gb is not None - else _gib_bytes(args.max_ram_gib) - ), - campaign_max_rss_bytes=( - _gb_bytes(args.campaign_max_ram_gb) - if args.campaign_max_ram_gb is not None - else _gib_bytes(campaign_limit_gib) - ), - artifact_policy=ArtifactPolicy(args.artifact_policy), - missing_only=args.missing_only, - rerun=args.rerun, - allow_symbolica_parallel=args.allow_symbolica_parallel, - campaign_policy=campaign_policy, - report_profile=policy_profile, - study_contract_sha256=( - None - if active_study_contract is None - else str(active_study_contract["sha256"]) - ), - reuse_cross_source_comparison_dependencies=args.reuse_cross_source_comparison_dependencies, - ) - except (ValueError, ReportWorkspaceError, MeasurementLineageError) as error: - parser.error(str(error)) - planned = plan_campaign( - requested, - store=service.store, - settings=settings, - expected_revision=expected_revision, - expected_tree=source_identity.tree, - measurement_lineage=measurement_lineage, - original_amplicol_seed=original_amplicol_seed, - excluded_cell_ids=frozenset(args.exclude_cell_id), - expected_worker_harness=( - None - if active_study_contract is None - else z_table_f_worker_harness_identity(active_study_contract) - ), - ) - try: - validate_campaign_plan(planned, settings) - except StudyContractError as error: - parser.error(str(error)) - if args.dry_run: - print( - json.dumps( - { - "requested": len(requested), - "scheduled": len(planned), - "source_revision": expected_revision, - "source_tree": source_identity.tree, - "campaign_policy": (settings.campaign_policy.as_manifest()), - "policy_profile": settings.report_profile, - "study_contract_sha256": ( - None - if active_study_contract is None - else active_study_contract["sha256"] - ), - "excluded_cell_ids": sorted(set(args.exclude_cell_id)), - "cells": [ - { - "cell_id": item.cell.cell_id, - "dependency": item.dependency, - "baseline_cell_id": item.baseline_cell_id, - "comparison_peer_ids": list(item.comparison_peer_ids), - "rank": item.rank, - } - for item in planned - ], - }, - sort_keys=True, - ) - ) - return 0 - if args.report_profile is not None: - require_active_profile_environment( - repo_root, - args.report_profile, - expected_source_revision=expected_revision, - ) - service.bind_measurement_lineage(measurement_lineage) - if active_study_contract is None: - scheduler = CampaignScheduler(service, settings=settings) - else: - scheduler = CampaignScheduler( - service, - settings=settings, - study_contract=active_study_contract, - study_contract_wrapper_root=(Path(__file__).resolve().parents[2]), - ) - result = scheduler.run(planned) - if args.refresh_pdf == "end": - _launch_async_publication( - service, - entrypoint=scheduler.worker_entrypoint, - ) - print( - json.dumps( - { - "planned": len(result.planned), - "completed": len(result.outcomes), - "failed": len(result.failed), - "source_revision": expected_revision, - "source_tree": source_identity.tree, - "campaign_policy": (settings.campaign_policy.as_manifest()), - "policy_profile": settings.report_profile, - "study_contract_sha256": ( - None - if active_study_contract is None - else active_study_contract["sha256"] - ), - "outcomes": [ - { - "cell_id": outcome.cell_id, - "status": outcome.status, - "detail": outcome.detail, - } - for outcome in result.outcomes - ], - }, - sort_keys=True, - ) - ) - return 1 if result.failed else 0 - if args.command in {"reset", "render", "recover"}: - written = service.publish( - reset=args.command == "reset", - merge_artifacts=args.command != "reset", - ) - if args.compile: - written = (*written, _compile_pdf(service)) - for path in written: - print(path.relative_to(repo_root)) - return 0 - if args.command == "_worker": - if args.cell_id not in { - cell.cell_id for cell in REPORT_CATALOG.measurement_cells() - }: - parser.error(f"unknown --cell-id {args.cell_id!r}") - write_cell_result( - args.cell_id, - args.result_json, - repo_root=repo_root, - attempt_root=args.attempt_root, - target_runtime_seconds=args.target_runtime, - batch_size=args.batch_size, - worker_cores=args.cell_cores, - amplicol_build_jobs=args.amplicol_build_jobs, - memory_limit_bytes=args.memory_limit_bytes, - warmup_runs=args.warmup_runs, - minimum_samples=args.minimum_samples, - progress_jsonl=args.progress_jsonl, - worker_wall_limit_seconds=args.worker_wall_limit, - profiling_time_limit_seconds=args.profiling_time_limit, - validation_time_limit_seconds=args.validation_time_limit, - generation_lock_path=args.generation_lock_path, - manual_source_revision=args.manual_source_revision, - manual_source_tree=args.manual_source_tree, - baseline_json=args.baseline_json, - expected_authority_cell_ids=tuple(args.expected_authority_cell_id), - selected_authority_cell_id=args.selected_authority_cell_id, - peer_json=tuple((cell_id, Path(path)) for cell_id, path in args.peer_json), - prepared_model_path=args.prepared_model, - reused_measurement_json=args.reused_measurement_json, - phase_state_path=args.phase_state_path, - phase_state_run_id=args.phase_state_run_id, - phase_state_authentication_key=args.phase_state_authentication_key, - legacy_repository=args.legacy_repository, - legacy_source_repository=args.legacy_source_repository, - legacy_workspace=args.legacy_workspace, - legacy_copy_source=args.legacy_copy_source, - legacy_source_revision=args.legacy_source_revision, - madgraph_installation=args.madgraph, - log_path=args.log_path, - worker_harness=worker_harness, - ) - return 0 - if args.command == "_prepare": - try: - path, reused = ensure_report_prepared_model( - store=service.store, - repo_root=repo_root, - worker_cores=args.cell_cores, - model=ModelKey(args.model), - producer_revision=args.producer_revision, - progress=( - None - if args.progress_jsonl is None - else _JsonlProgressSink(args.progress_jsonl) - ), - ) - payload = { - "path": os.fspath(path), - "reused": reused, - **( - {} if worker_harness is None else {"worker_harness": worker_harness} - ), - } - returncode = 0 - except Exception as error: - payload = { - "error": { - "kind": type(error).__name__, - "message": str(error), - } - } - returncode = 1 - args.result_json.parent.mkdir(parents=True, exist_ok=True) - args.result_json.write_text( - json.dumps(payload, sort_keys=True) + "\n", - encoding="ascii", - ) - return returncode - parser.error(f"unsupported command {args.command!r}") - return 2 - - -__all__ = ["main"] diff --git a/pyamplicol/tools/performance_report/display_contract.py b/pyamplicol/tools/performance_report/display_contract.py deleted file mode 100644 index 5d9cf00867..0000000000 --- a/pyamplicol/tools/performance_report/display_contract.py +++ /dev/null @@ -1,89 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Logical display accounting for publication-facing report tables.""" - -from __future__ import annotations - -from dataclasses import dataclass - -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import ExecutionMode, ModelKey, Workload - - -@dataclass(frozen=True, slots=True) -class DisplayAccounting: - """Counts that distinguish measured cells from intentional table markers.""" - - maximum_n_final: int - declared_measurement_cell_count: int - required_measurement_count: int - catalog_static_na_cell_count: int - structurally_not_applicable_display_slot_count: int - not_exposed_display_slot_count: int - - -def report_display_accounting( - *, - catalog: ReportCatalog = REPORT_CATALOG, - max_n_final: int = 9, -) -> DisplayAccounting: - """Return canonical logical-slot counts through ``max_n_final``. - - A declared measurement is one catalog ``CellSpec``. Required measurements - exclude only catalog-authenticated static N/A cells that no supported - producer can evaluate. A structurally inapplicable slot is one matrix - process/multiplicity position for which no process exists. A not-exposed - slot is one original-AmpliCol execution submetric in a dedicated Z-ladder - row; those rows expose generation and wall timing, but not a separately - defined native-execution boundary. - """ - - if max_n_final < 1: - raise ValueError("max_n_final must be positive") - declared_cells = tuple( - cell - for cell in catalog.measurement_cells() - if cell.n_final <= max_n_final - ) - static_na = sum( - catalog.static_na_reason(cell) is not None for cell in declared_cells - ) - required = len(declared_cells) - static_na - matrix_datasets = getattr(catalog, "matrix_datasets", ()) - process_families = getattr(catalog, "process_families", ()) - structural = 0 - for dataset in matrix_datasets: - for family in process_families: - for n_final in dataset.multiplicities: - if n_final > max_n_final: - continue - if family.process(n_final) is None or n_final > family.maximum_n( - dataset.candidate.accuracy - ): - structural += 1 - - variants = getattr(catalog, "z_variants", ()) - reference_variants = sum( - variant.execution_mode is ExecutionMode.AMPLICOL for variant in variants - ) - model_count = sum( - model in getattr(catalog, "models", {}) - for model in (ModelKey.BUILTIN_SM, ModelKey.UFO_SM) - ) - z_multiplicity_count = sum(n_final <= max_n_final for n_final in range(1, 10)) - not_exposed = ( - reference_variants - * model_count - * z_multiplicity_count - * len((Workload.SELECTED_FLOW, Workload.ALL_FLOW)) - ) - return DisplayAccounting( - maximum_n_final=max_n_final, - declared_measurement_cell_count=len(declared_cells), - required_measurement_count=required, - catalog_static_na_cell_count=static_na, - structurally_not_applicable_display_slot_count=structural, - not_exposed_display_slot_count=not_exposed, - ) - - -__all__ = ["DisplayAccounting", "report_display_accounting"] diff --git a/pyamplicol/tools/performance_report/final_audit.py b/pyamplicol/tools/performance_report/final_audit.py deleted file mode 100644 index 38c80d1eaa..0000000000 --- a/pyamplicol/tools/performance_report/final_audit.py +++ /dev/null @@ -1,7201 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Final-SHA structural and numerical audit for checked-in report measurements.""" - -from __future__ import annotations - -import argparse -import gc -import hashlib -import importlib -import io -import json -import math -import os -import re -import shutil -import stat -import subprocess -import sys -import tempfile -import tomllib -from collections import Counter, defaultdict -from collections.abc import Callable, Collection, Mapping, Sequence -from dataclasses import dataclass -from functools import cache -from importlib.machinery import EXTENSION_SUFFIXES -from pathlib import Path, PurePosixPath -from typing import Any - -from .agreements import ( - BUILTIN_UFO_RECURRENCE, - DIRECT_AGREEMENT_FIELD, - DIRECT_AGREEMENT_V1_ABI, - DIRECT_AGREEMENT_V2_ABI, - INDEPENDENT_AUTHORITY_ABI, - INDEPENDENT_AUTHORITY_FIELD, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, - LC_CROSS_LAYOUT_COMPONENT, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_COMPARISON_FIELD, - MADGRAPH_FULL_COLOUR, - STRICT_ABSOLUTE_TOLERANCE, - STRICT_RELATIVE_TOLERANCE, - Z_RECURRENCE_CROSS_MODE, - AgreementEdge, - agreement_edges, - direct_agreement_record, - evaluate_lc_common_component, - incoming_agreement_edges, - independent_numerical_authorities, - madgraph_candidate_precision, - requires_independent_numerical_authority, - validate_madgraph_comparison_record, - validation_baseline_is_required, -) -from .cache import _validate_standalone_internal_validation, digest_json, reset_entry -from .campaign_policy import ( - MACBOOK_M3_POLICY, - MACBOOK_M3_PROFILE, - MACBOOK_M3_Z_TABLE_F_POLICY, - STRICT_POLICY, - X86_EPYC_POLICY, - X86_EPYC_PROFILE, - CampaignPolicy, - CampaignPolicyError, - PolicyMeasurementState, - dependency_reference, - resource_frontier_reference, - resource_lane_identity, - validate_policy_measurement, -) -from .catalog import ( - REPORT_CATALOG, - STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6, - STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT, - ReportCatalog, -) -from .measurement import ( - baseline_uses_lc_common_component_authority, - conditioned_measurement_comparison, - shared_validation_points, -) -from .measurement_lineage import ( - MeasurementLineage, - MeasurementLineageError, - _is_authorized_native_inputs_transition, - load_and_audit_measurement_lineage, -) -from .models import ( - Accuracy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .publication import publication_measurement_matches_current -from .publisher import _report_source_copy_ignore -from .render import render_all_tables, summarize_visible_completeness -from .report_policy import publication_measurement_policy_issues -from .runner import ( - ABSOLUTE_TOLERANCE, - CONDITIONED_COMPARISON_ABI, - INDEPENDENT_RELATIVE_TOLERANCE, - RELATIVE_TOLERANCE, - REPORT_BENCHMARK_BATCH_SIZE, - REPORT_BENCHMARK_WARMUP_RUNS, - RESOLVED_SUM_VALIDATION_ABI, - SelectorContract, - _valid_symjit_plane_target, - point_digest, - resolved_sum_validation, - runtime_validation_points, - validate_conditioned_comparison_record, - validate_profile_warmup_evidence, - validate_resolved_sum_validation_record, - validate_runtime_contract, - validate_selector_contract, -) -from .runtime_evidence import ( - RuntimeEvidenceError, - established_preimport_runtime_identity, - loaded_pyamplicol_origin_policy, - native_extension_in_package, - preimport_python_runtime_identity, - python_package_tree_identity, - source_only_bytecode_policy, -) -from .service import ReportPaths, ReportService, validate_profile_name -from .source_identity import ( - ReportSourceIdentityError, - require_report_only_publication, -) -from .standalone_build import StandaloneBuildError, validate_latex_log -from .timing import ( - ARENA_UNAVAILABLE_EXECUTION_TIMING_FIELDS, - EVALUATOR_TOTAL_TIMING_KEY, - evaluator_total_timing_record, - unavailable_execution_timing_record, -) -from .workspace import load_profile_campaign_policy - -_GIT_SHA_RE = re.compile(r"^[0-9a-f]{40}$") -_SHA256_RE = re.compile(r"^[0-9a-f]{64}$") -_FULL_CATALOG_MAX_N_FINAL = 9 -_EXPECTED_FULL_CATALOG_CELL_COUNT = 2198 -_EXPECTED_FULL_STATIC_NA_REASONS = { - **{ - cell_id: STATIC_NA_ORIGINAL_AMPLICOL_OPEN_QUARK_LINE_LIMIT - for cell_id in { - "reference-amplicol-lc-n6-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n6-dd-4q-lines-all-flow", - "reference-amplicol-lc-n7-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n7-dd-4q-lines-all-flow", - "reference-amplicol-lc-n8-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n8-dd-4q-lines-all-flow", - "reference-amplicol-lc-n9-dd-4q-lines-selected-flow", - "reference-amplicol-lc-n9-dd-4q-lines-all-flow", - "reference-amplicol-nlc-n6-dd-4q-lines-contracted", - "reference-amplicol-full-n6-dd-4q-lines-contracted", - } - }, - **{ - ( - f"z-{model}-n{n_final}-dd-z-jets-{variant}-{workload}" - ): STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6 - for model in ("builtin-sm", "external-sm") - for n_final in (7, 8, 9) - for variant in ("asm-o3", "cpp-o3") - for workload in ("selected-flow", "all-flow") - }, -} -_EXPECTED_FULL_STATIC_NA_CELL_IDS = frozenset(_EXPECTED_FULL_STATIC_NA_REASONS) -_EXPECTED_FULL_DIRECT_AGREEMENT_COUNT = 1973 -_EXPECTED_N4_CELL_COUNT = 1042 -_EXPECTED_N4_DIRECT_AGREEMENT_COUNTS = { - BUILTIN_UFO_RECURRENCE: 140, - Z_RECURRENCE_CROSS_MODE: 80, - LC_CROSS_LAYOUT_COMPONENT: 254, - LC_LEGACY_PYAMPLICOL_COMPONENT: 221, - MADGRAPH_FULL_COLOUR: 132, -} -_EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS = { - BUILTIN_UFO_RECURRENCE: 332, - Z_RECURRENCE_CROSS_MODE: 156, - LC_CROSS_LAYOUT_COMPONENT: 678, - LC_LEGACY_PYAMPLICOL_COMPONENT: 559, - MADGRAPH_FULL_COLOUR: 200, -} -_FULLY_REPLAYED_PYAMPLICOL = "fully-replayed-pyamplicol" -_REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY = ( - "replayed-pyamplicol-vs-authenticated-legacy" -) -_AUTHENTICATED_STORED_LEGACY_LAYOUT = "authenticated-stored-legacy-layout" -_AUTHENTICATED_STORED_MADGRAPH = "authenticated-stored-madgraph" -_DIRECT_REPLAY_CATEGORIES = ( - _FULLY_REPLAYED_PYAMPLICOL, - _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY, - _AUTHENTICATED_STORED_LEGACY_LAYOUT, - _AUTHENTICATED_STORED_MADGRAPH, -) -_EXPECTED_N4_DIRECT_REPLAY_COUNTS = { - _FULLY_REPLAYED_PYAMPLICOL: 441, - _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY: 221, - _AUTHENTICATED_STORED_LEGACY_LAYOUT: 33, - _AUTHENTICATED_STORED_MADGRAPH: 132, -} -_EXPECTED_FULL_DIRECT_REPLAY_COUNTS = { - _FULLY_REPLAYED_PYAMPLICOL: 1063, - _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY: 559, - _AUTHENTICATED_STORED_LEGACY_LAYOUT: 103, - _AUTHENTICATED_STORED_MADGRAPH: 200, -} - - -def _count_contract_matches_with_optional_categories( - observed: Mapping[str, int], - expected_maxima: Mapping[str, int], - *, - optional_categories: Collection[str], -) -> bool: - """Keep required counts exact while bounding optional edge categories.""" - - optional = frozenset(optional_categories) - if set(observed) != set(expected_maxima) or not optional <= set(expected_maxima): - return False - return all( - ( - 0 <= observed[category] <= expected - if category in optional - else observed[category] == expected - ) - for category, expected in expected_maxima.items() - ) - - -def _replay_count_contract_matches_direct_edges( - observed: Mapping[str, int], - direct_edge_counts: Mapping[str, int], - expected_replay_counts: Mapping[str, int], -) -> bool: - """Require replay of every direct edge that was actually available. - - Z recurrence and legacy-AmpliCol comparison edges may be absent. The - remaining built-in/UFO and LC cross-layout edges are still exact at the - direct-edge gate. Projecting the replay categories from those already - checked direct counts prevents either a required replay or an available - optional replay from disappearing behind an aggregate category count. - """ - - if set(observed) != set(expected_replay_counts): - return False - try: - stored_legacy_layout = expected_replay_counts[ - _AUTHENTICATED_STORED_LEGACY_LAYOUT - ] - fully_replayed = ( - direct_edge_counts[BUILTIN_UFO_RECURRENCE] - + direct_edge_counts[Z_RECURRENCE_CROSS_MODE] - + direct_edge_counts[LC_CROSS_LAYOUT_COMPONENT] - - stored_legacy_layout - ) - replayed_legacy = direct_edge_counts[LC_LEGACY_PYAMPLICOL_COMPONENT] - stored_madgraph = direct_edge_counts[MADGRAPH_FULL_COLOUR] - except KeyError: - return False - if fully_replayed < 0: - return False - return dict(observed) == { - _FULLY_REPLAYED_PYAMPLICOL: fully_replayed, - _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY: replayed_legacy, - _AUTHENTICATED_STORED_LEGACY_LAYOUT: stored_legacy_layout, - _AUTHENTICATED_STORED_MADGRAPH: stored_madgraph, - } - - -_LOADED_ORIGIN_OBSERVATION_FIELDS = frozenset( - { - "observed_module_count", - "observations", - "observations_sha256", - } -) -_ARENA_CAPABILITY = { - ExecutionMode.COMPILED: "compiled-plane-arena-v1", - ExecutionMode.EAGER: "eager-direct-arena-v1", - ExecutionMode.RECURRENCE: ("rusticol.recurrence-direct-arena.complex-f64.v1"), - ExecutionMode.ON_THE_FLY: "rusticol.on-the-fly.complex-f64.v1", -} -_ON_THE_FLY_LC_COLOR_CAPABILITY = "rusticol.on-the-fly.lc-color.v1" -_ON_THE_FLY_CONTRACTED_COLOR_CAPABILITY = "rusticol.on-the-fly.contracted-color.v1" -_ON_THE_FLY_COLOR_CONTRACTION_ABI = "pyamplicol-recurrence-color-contraction-v3" -_ON_THE_FLY_EXECUTION_KIND = "pyamplicol-runtime-on-the-fly-execution" -_ON_THE_FLY_RUNTIME_CONTAINER_KIND = "pyamplicol-on-the-fly-runtime-container" -_ON_THE_FLY_RUNTIME_STORAGE_ABI = "pacbin-v1" -_ON_THE_FLY_SEED_MEMBER_PATH = "on-the-fly/process-seed-v1.bin" -_ON_THE_FLY_PROCESS_SEED_IDENTITY_ABI = "pyamplicol-on-the-fly-process-seed-identity-v1" -_ON_THE_FLY_PROCESS_SEED_IDENTITY_FIELDS = frozenset( - { - "abi", - "process_digest", - "compiled_model_digest", - "recurrence_template_catalog_digest", - "prepared_kernel_pack_digest", - "recurrence_direct_template_catalog_digest", - "semantic_digest", - "external_permutation", - "external_sources", - } -) -_EAGER_PREPARED_PACK_IDENTITY_KIND = "pyamplicol-prepared-kernel-pack-identity" -_EAGER_PREPARED_PACK_IDENTITY_SCHEMA_VERSION = 1 -_COMPILED_DIRECT_ABI = "pyamplicol-compiled-plane-kernel-v2" -_NATIVE_COMPILED_DIRECT_ABI = "pyamplicol-native-compiled-direct-application-v1" -_SYMJIT_APPLICATION_ABI = "symjit-application-storage-v3" -_SYMJIT_PLANE_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -_EAGER_NATIVE_APPLICATION_ABI = "pyamplicol-eager-native-direct-table-v1" -_EAGER_DIRECT_CAPABILITY = "eager-direct-arena-v1" -_EAGER_DIRECT_DESCRIPTOR_ABI = "pyamplicol-eager-plane-table-descriptor-v1" -_EAGER_DIRECT_BINDING_ABI = "pyamplicol-eager-plane-table-binding-v2" -_RECURRENCE_DIRECT_TEMPLATE_ABI = "pyamplicol-recurrence-direct-template-v1" -_RECURRENCE_DIRECT_BACKEND_ABI = "rusticol.recurrence-direct-backend.v1" -_RECURRENCE_DIRECT_CANONICALIZATION_ABI = "pyamplicol-canonical-json-v1" -_RECURRENCE_DIRECT_PAYLOAD_BINDING_ABI = "pyamplicol-recurrence-plane-binding-v2" -_RECURRENCE_JIT_DIRECT_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -_SOURCE_RUNTIME_CAPABILITY = { - "jit": "symjit.application.complex-f64.v1", - "cpp": "symbolica.compiled-cpp.complex-f64.v1", - "asm": "symbolica.compiled-asm.complex-f64.v1", -} -_MODEL_SOURCE_PATH = { - ModelKey.UFO_SM: "src/pyamplicol/assets/models/json/sm/sm.json", - ModelKey.SCALAR_CONTACT: ("src/pyamplicol/assets/models/json/scalars/scalars.json"), - ModelKey.SCALAR_GRAVITY: ( - "src/pyamplicol/assets/models/json/scalar_gravity/scalar_gravity.json" - ), -} -_TEX_INPUT_RE = re.compile(r"\\(?:input|include)\s*\{([^{}]+)\}") -_REPORT_PROFILE_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,63}") -_PUBLICATION_MEMBER_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]*") -_PORTABLE_ARTIFACT_ROOT = "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}" -_PUBLICATION_LINEAGE_KIND = "pyamplicol-report-publication-lineage-v1" - - -class FinalAuditError(RuntimeError): - """The final report evidence does not satisfy its publication contract.""" - - -@cache -def _cached_packaged_eager_prepared_pack_identity( - model: ModelKey | None, - backend: str, - jit_optimization_level: int | None, -) -> dict[str, object]: - """Return the exact wheel-owned prepared identity for one report lane.""" - - if ( - model is not ModelKey.BUILTIN_SM - or backend != "jit" - or jit_optimization_level != 2 - ): - raise FinalAuditError( - "on-the-fly report cells require the packaged built-in-SM JIT O2 pack" - ) - try: - from pyamplicol.assets.prepared_models import ( - BUILTIN_SM_JIT_O2, - open_packaged_prepared_model, - ) - from pyamplicol.models.prepared import ( - EAGER_KERNEL_ABI, - PREPARED_KERNEL_PACK_IDENTITY_ABI, - prepared_kernel_pack_manifest_identity_sha256, - ) - - with open_packaged_prepared_model(BUILTIN_SM_JIT_O2) as bundle: - if bundle.kernel_pack.backend != backend: - raise FinalAuditError( - "packaged prepared-kernel backend differs from the report cell" - ) - return { - "kind": _EAGER_PREPARED_PACK_IDENTITY_KIND, - "schema_version": _EAGER_PREPARED_PACK_IDENTITY_SCHEMA_VERSION, - "abi": PREPARED_KERNEL_PACK_IDENTITY_ABI, - "eager_kernel_abi": EAGER_KERNEL_ABI, - "identity_sha256": ( - prepared_kernel_pack_manifest_identity_sha256(bundle.manifest) - ), - "backend": bundle.kernel_pack.backend, - "kernel_count": len(bundle.kernel_pack.kernels), - } - except (ImportError, OSError, RuntimeError, TypeError, ValueError) as error: - raise FinalAuditError( - "packaged prepared-kernel identity is unavailable" - ) from error - - -def _expected_eager_prepared_pack_identity(cell: CellSpec) -> dict[str, object]: - measurement = cell.measurement - return _cached_packaged_eager_prepared_pack_identity( - measurement.model, - measurement.backend, - measurement.jit_optimization_level, - ) - - -@dataclass(frozen=True, slots=True) -class ArtifactEvidence: - """Identity proven directly from one validated process artifact.""" - - artifact_id: str - process_id: str - producer_version: str - producer_git_revision: str | None - producer_native_build_inputs_sha256: str | None - runtime_version: str - runtime_capabilities: tuple[str, ...] - execution_manifest_path: str - execution_manifest_sha256: str - execution_mode: str - arena_record_count: int - direct_leaf_count: int - effective_config: Mapping[str, object] - source_jit_identity: Mapping[str, object] | None - - -@dataclass(frozen=True, slots=True) -class _ArtifactReference: - cell: CellSpec - measurement: Mapping[str, object] - path: Path - process_id: str - - -@dataclass(frozen=True, slots=True) -class _ReplayObservation: - matrix_element: float - resolved_maximum_absolute: float - resolved_maximum_relative: float - lc_common_component: float | None - - -ArtifactAuditor = Callable[[CellSpec, Path, str], ArtifactEvidence] -RuntimeLoader = Callable[[Path, str], object] -SourceAuditor = Callable[[Path, str], Mapping[str, object] | None] -PdfAuditor = Callable[[ReportService], Mapping[str, object]] -RuntimeAuditor = Callable[[str, Path], Mapping[str, object]] - - -def _mapping(value: object, context: str) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise FinalAuditError(f"{context} must be an object") - return value - - -def _sequence(value: object, context: str) -> Sequence[object]: - if isinstance(value, (str, bytes, bytearray)) or not isinstance(value, Sequence): - raise FinalAuditError(f"{context} must be an array") - return value - - -def _finite_number(value: object, context: str, *, nonnegative: bool = False) -> float: - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise FinalAuditError(f"{context} must be a finite number") - result = float(value) - if not math.isfinite(result): - raise FinalAuditError(f"{context} must be finite") - if nonnegative and result < 0.0: - raise FinalAuditError(f"{context} must be non-negative") - return result - - -def _sha256_file(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _canonical_relative_path(relative: object, context: str) -> PurePosixPath: - if not isinstance(relative, str) or not relative: - raise FinalAuditError(f"{context} path is missing") - logical = PurePosixPath(relative) - if ( - logical.is_absolute() - or not logical.parts - or any(part in {"", ".", ".."} for part in logical.parts) - or logical.as_posix() != relative - ): - raise FinalAuditError(f"{context} path is not canonical") - return logical - - -def _authenticated_payload_bytes( - artifact: Path, - manifest: object, - relative: object, - *, - role: str, - media_type: str, - process_id: str | None, - context: str, -) -> tuple[bytes, str, str]: - """Read one manifest-declared payload through one checked descriptor.""" - - logical = _canonical_relative_path(relative, context) - canonical = logical.as_posix() - payloads = getattr(manifest, "payloads", None) - if not isinstance(payloads, Sequence): - raise FinalAuditError(f"{context} has no artifact payload inventory") - matches = [ - payload for payload in payloads if getattr(payload, "path", None) == canonical - ] - if len(matches) != 1: - raise FinalAuditError(f"{context} payload is missing or ambiguous") - payload = matches[0] - expected_size = getattr(payload, "size_bytes", None) - expected_sha256 = getattr(payload, "sha256", None) - if ( - getattr(payload, "role", None) != role - or getattr(payload, "media_type", None) != media_type - or getattr(payload, "process_id", None) != process_id - or getattr(payload, "executable", None) is not False - or isinstance(expected_size, bool) - or not isinstance(expected_size, int) - or expected_size < 0 - or not isinstance(expected_sha256, str) - or _SHA256_RE.fullmatch(expected_sha256) is None - ): - raise FinalAuditError(f"{context} has an invalid artifact declaration") - path = artifact.joinpath(*logical.parts) - flags = os.O_RDONLY | getattr(os, "O_CLOEXEC", 0) | getattr(os, "O_NOFOLLOW", 0) - descriptor: int | None = None - try: - descriptor = os.open(path, flags) - metadata = os.fstat(descriptor) - if not stat.S_ISREG(metadata.st_mode) or metadata.st_size != expected_size: - raise FinalAuditError(f"{context} does not match its artifact declaration") - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - data = stream.read(expected_size + 1) - except OSError as error: - raise FinalAuditError(f"cannot read authenticated {context}") from error - finally: - if descriptor is not None: - os.close(descriptor) - actual_sha256 = hashlib.sha256(data).hexdigest() - if len(data) != expected_size or actual_sha256 != expected_sha256: - raise FinalAuditError(f"{context} does not match the artifact manifest") - return data, canonical, actual_sha256 - - -def _authenticated_json_payload( - artifact: Path, - manifest: object, - relative: object, - *, - process_id: str | None, - context: str, -) -> tuple[dict[str, Any], str, str]: - data, canonical, sha256 = _authenticated_payload_bytes( - artifact, - manifest, - relative, - role="evaluator-manifest", - media_type="application/json", - process_id=process_id, - context=context, - ) - try: - value = json.loads(data) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise FinalAuditError(f"authenticated {context} is invalid JSON") from error - if not isinstance(value, dict): - raise FinalAuditError(f"authenticated {context} must be an object") - return value, canonical, sha256 - - -def _authenticated_effective_config( - artifact: Path, - manifest: object, -) -> Mapping[str, object]: - configuration = _mapping( - getattr(manifest, "configuration", None), - "artifact.configuration", - ) - data, _canonical, _sha256 = _authenticated_payload_bytes( - artifact, - manifest, - configuration.get("effective_path"), - role="configuration-effective", - media_type="application/toml", - process_id=None, - context="effective configuration", - ) - try: - value = tomllib.loads(data.decode("utf-8")) - except (UnicodeDecodeError, tomllib.TOMLDecodeError) as error: - raise FinalAuditError( - "authenticated effective configuration is invalid TOML" - ) from error - return _mapping(value, "authenticated effective configuration") - - -def _python_package_tree_identity( - package_roots: Path | Sequence[Path], -) -> dict[str, object]: - """Translate exact-runtime evidence failures into final-audit failures.""" - - try: - return python_package_tree_identity(package_roots) - except RuntimeEvidenceError as error: - raise FinalAuditError( - "installed pyamplicol namespace cannot be authenticated" - ) from error - - -def _validate_python_package_tree_identity( - value: object, - *, - context: str, -) -> Mapping[str, object]: - identity = _mapping(value, context) - root = identity.get("root") - roots = identity.get("roots") - file_count = identity.get("file_count") - total_bytes = identity.get("total_bytes") - digest = identity.get("sha256") - bytecode_policy = identity.get("bytecode_policy") - if ( - identity.get("kind") != "pyamplicol-python-package-tree-v2" - or not isinstance(root, str) - or not root - or not Path(root).is_absolute() - or isinstance(roots, (str, bytes)) - or not isinstance(roots, Sequence) - or not roots - or any( - not isinstance(item, str) or not Path(item).is_absolute() for item in roots - ) - or len(set(roots)) != len(roots) - or roots[0] != root - or isinstance(file_count, bool) - or not isinstance(file_count, int) - or file_count < 1 - or isinstance(total_bytes, bool) - or not isinstance(total_bytes, int) - or total_bytes < 0 - or not isinstance(digest, str) - or _SHA256_RE.fullmatch(digest) is None - or identity.get("member_set_stable") is not True - or identity.get("namespace_bound_to_root_fd") is not True - or not isinstance(bytecode_policy, Mapping) - or bytecode_policy.get("kind") != "pyamplicol-source-only-bytecode-policy-v1" - or bytecode_policy.get("dont_write_bytecode") is not True - or bytecode_policy.get("external_pycache_prefix_absent") is not True - or bytecode_policy.get("package_local_bytecode_eligible") is not False - or bytecode_policy.get("isolated_startup") is not True - or bytecode_policy.get("site_initialization") is not False - or bytecode_policy.get("python_environment_ignored_at_startup") is not True - ): - raise FinalAuditError(f"{context} is not a valid package-tree identity") - return identity - - -def _validate_loaded_origin_policy( - value: object, - *, - context: str, -) -> Mapping[str, object]: - policy = _mapping(value, context) - count = policy.get("observed_module_count") - observations = policy.get("observations") - if ( - policy.get("kind") != "pyamplicol-loaded-module-origin-policy-v1" - or policy.get("all_loaded_origins_authenticated") is not True - or policy.get("native_image_origin_bound") is not True - or policy.get("loaded_bytecode_eligible") is not False - or isinstance(count, bool) - or not isinstance(count, int) - or count < 1 - or isinstance(observations, (str, bytes)) - or not isinstance(observations, Sequence) - or len(observations) != count - or _SHA256_RE.fullmatch(str(policy.get("observations_sha256"))) is None - or digest_json(list(observations)) != policy.get("observations_sha256") - ): - raise FinalAuditError(f"{context} is not a valid loaded-origin policy") - return policy - - -def _stable_runtime_identity(identity: Mapping[str, object]) -> dict[str, object]: - stable = dict(identity) - raw_policy = stable.get("loaded_module_origin_policy") - if isinstance(raw_policy, Mapping): - stable["loaded_module_origin_policy"] = { - field: value - for field, value in raw_policy.items() - if field not in _LOADED_ORIGIN_OBSERVATION_FIELDS - } - return stable - - -def _audit_runtime_identity_postflight( - provenance: Mapping[str, object], - identity: Mapping[str, object], - *, - context: str, -) -> None: - stable_digest = digest_json(_stable_runtime_identity(identity)) - if provenance.get("runtime_identity_stable_sha256") != stable_digest: - raise FinalAuditError( - f"{context}.runtime_identity_stable_sha256 does not match" - ) - if provenance.get("runtime_identity_postflight_stable_sha256") != stable_digest: - raise FinalAuditError( - f"{context}.runtime_identity postflight stable SHA-256 differs" - ) - if provenance.get("runtime_identity_postflight_match") is not True: - raise FinalAuditError( - f"{context}.runtime_identity_postflight_match is not true" - ) - - initial_policy = _validate_loaded_origin_policy( - identity.get("loaded_module_origin_policy"), - context=f"{context}.runtime_identity.loaded_module_origin_policy", - ) - postflight_policy = _validate_loaded_origin_policy( - provenance.get("runtime_identity_postflight_loaded_module_origin_policy"), - context=(f"{context}.runtime_identity_postflight_loaded_module_origin_policy"), - ) - stable_initial_policy = { - field: value - for field, value in initial_policy.items() - if field not in _LOADED_ORIGIN_OBSERVATION_FIELDS - } - stable_postflight_policy = { - field: value - for field, value in postflight_policy.items() - if field not in _LOADED_ORIGIN_OBSERVATION_FIELDS - } - if stable_postflight_policy != stable_initial_policy: - raise FinalAuditError(f"{context} runtime postflight origin policy changed") - initial_observations = _sequence( - initial_policy.get("observations"), - f"{context}.runtime_identity.loaded_module_origin_policy.observations", - ) - postflight_observations = _sequence( - postflight_policy.get("observations"), - ( - f"{context}." - "runtime_identity_postflight_loaded_module_origin_policy." - "observations" - ), - ) - postflight_keys = { - json.dumps( - observation, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - for observation in postflight_observations - } - if any( - json.dumps( - observation, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - not in postflight_keys - for observation in initial_observations - ): - raise FinalAuditError( - f"{context} runtime postflight lost a loaded-module origin" - ) - - -def _canonical_status( - absolute: float, - relative: float, - *, - absolute_tolerance: float, - relative_tolerance: float, -) -> str: - return ( - ResultStatus.OK.value - if absolute <= absolute_tolerance or relative <= relative_tolerance - else ResultStatus.VALIDATION_FAILED.value - ) - - -def _expected_pointwise_tolerance(cell: CellSpec) -> float: - if cell.dataset_id.startswith("matrix_recurrence_") or cell.dataset_id.startswith( - "z_" - ): - return INDEPENDENT_RELATIVE_TOLERANCE - return RELATIVE_TOLERANCE - - -def _same_float(observed: float, expected: float) -> bool: - return math.isclose(observed, expected, rel_tol=0.0, abs_tol=0.0) - - -def _audit_pointwise( - raw: object, - *, - context: str, - expected_candidate: float, - expected_baseline: float, - expected_relative_tolerance: float, - expected_point_digest: str | None = None, - expected_candidate_source_sha256: str | None = None, - expected_baseline_source_sha256: str | None = None, - expected_selector_identity: Mapping[str, object] | None = None, - require_success: bool = True, -) -> None: - record = _mapping(raw, context) - direct_abi = record.get("abi") - if direct_abi in {DIRECT_AGREEMENT_V2_ABI, DIRECT_AGREEMENT_V1_ABI}: - record = { - key: value - for key, value in record.items() - if key - not in { - "abi", - "edge_kind", - "value_kind", - "baseline_cell_id", - "candidate_cell_id", - } - } - if direct_abi == DIRECT_AGREEMENT_V2_ABI: - record["abi"] = CONDITIONED_COMPARISON_ABI - try: - validate_conditioned_comparison_record( - record, - require_binding=record.get("abi") == CONDITIONED_COMPARISON_ABI, - ) - except ValueError as error: - raise FinalAuditError(f"{context}: {error}") from error - candidate = _finite_number(record.get("candidate"), f"{context}.candidate") - baseline = _finite_number(record.get("baseline"), f"{context}.baseline") - relative_tolerance = _finite_number( - record.get("relative_tolerance"), - f"{context}.relative_tolerance", - nonnegative=True, - ) - checks = [ - ( - _same_float(candidate, expected_candidate), - "candidate does not equal measurement.matrix_element", - ), - ( - _same_float(baseline, expected_baseline), - "baseline does not equal the canonical baseline measurement", - ), - ( - _same_float(relative_tolerance, expected_relative_tolerance), - "relative tolerance is not the catalog contract", - ), - ] - if require_success: - checks.append( - ( - record.get("status") == ResultStatus.OK.value, - "stored or recomputed status is not ok", - ) - ) - failures = [message for passed, message in checks if not passed] - if record.get("abi") == CONDITIONED_COMPARISON_ABI: - binding = _mapping(record.get("comparison_binding"), f"{context}.binding") - if ( - expected_point_digest is not None - and binding.get("point_digest") != expected_point_digest - ): - failures.append("comparison scale is bound to a different point") - if ( - expected_candidate_source_sha256 is not None - and binding.get("candidate_source_sha256") - != expected_candidate_source_sha256 - ): - failures.append("candidate scale source differs from resolved evidence") - if ( - expected_baseline_source_sha256 is not None - and binding.get("baseline_source_sha256") != expected_baseline_source_sha256 - ): - failures.append("baseline scale source differs from authority evidence") - if ( - expected_selector_identity is not None - and binding.get("selector_component_identity") != expected_selector_identity - ): - failures.append("selector/component scale identity differs") - else: - absolute_tolerance = _finite_number( - record.get("absolute_tolerance"), - f"{context}.absolute_tolerance", - nonnegative=True, - ) - if not _same_float(absolute_tolerance, ABSOLUTE_TOLERANCE): - failures.append("legacy absolute tolerance is not the report contract") - if failures: - raise FinalAuditError(f"{context}: " + "; ".join(failures)) - - -def _audit_resolved_sum(raw: object, *, context: str) -> None: - record = _mapping(raw, context) - try: - validate_resolved_sum_validation_record(record) - except ValueError as error: - raise FinalAuditError(f"{context}: {error}") from error - if ( - _finite_number( - record.get("relative_tolerance"), - f"{context}.relative_tolerance", - nonnegative=True, - ) - != RELATIVE_TOLERANCE - or record.get("status") != ResultStatus.OK.value - ): - raise FinalAuditError(f"{context} is not a successful resolved-sum record") - - -def _audit_lc_common_component( - cell: CellSpec, - measurement: Mapping[str, object], - *, - context: str, -) -> float: - validation = _mapping(measurement.get("validation"), f"{context}.validation") - raw = _mapping( - validation.get(LC_COMMON_COMPONENT_FIELD), - f"{context}.validation.{LC_COMMON_COMPONENT_FIELD}", - ) - expected_fields = { - "abi", - "cell_id", - "value", - "point_digest", - "helicity_ids", - "color_flow_ids", - } - if set(raw) != expected_fields: - raise FinalAuditError( - f"{context} LC common-component fields differ from the contract" - ) - selector = SelectorContract.from_mapping( - _mapping(measurement.get("selector_contract"), f"{context}.selector_contract") - ) - if ( - raw.get("abi") != LC_COMMON_COMPONENT_ABI - or raw.get("cell_id") != cell.cell_id - or raw.get("point_digest") != selector.point_digest - or raw.get("helicity_ids") != list(selector.all_flow_helicity_ids) - or raw.get("color_flow_ids") != list(selector.selected_color_flow_ids) - ): - raise FinalAuditError( - f"{context} LC common component is not bound to its selector contract" - ) - return _finite_number(raw.get("value"), f"{context}.lc_common_component") - - -def _agreement_value( - edge: AgreementEdge, - cell: CellSpec, - measurement: Mapping[str, object], - *, - context: str, -) -> float: - if edge.kind == MADGRAPH_FULL_COLOUR and cell.cell_id == edge.candidate.cell_id: - validation = _mapping( - measurement.get("validation"), - f"{context}.validation", - ) - comparison = _mapping( - validation.get(MADGRAPH_COMPARISON_FIELD), - f"{context}.validation.{MADGRAPH_COMPARISON_FIELD}", - ) - try: - validate_madgraph_comparison_record( - comparison, - expected_candidate_id=edge.candidate.cell_id, - expected_candidate_precision=madgraph_candidate_precision( - edge.candidate - ), - ) - except ValueError as error: - raise FinalAuditError(f"{context}: {error}") from error - binding = _mapping( - comparison.get("comparison_binding"), - f"{context}.validation.{MADGRAPH_COMPARISON_FIELD}.binding", - ) - expected_point_digest = _measurement_validation_point_digest( - measurement, - context=context, - ) - if ( - comparison.get("baseline_cell_id") != edge.baseline.cell_id - or binding.get("point_digest") != expected_point_digest - ): - raise FinalAuditError( - f"{context} MadGraph comparison identity differs from the edge" - ) - return _finite_number( - comparison.get("candidate"), - f"{context}.validation.{MADGRAPH_COMPARISON_FIELD}.candidate", - ) - if edge.value_kind == "matrix_element": - return _finite_number( - measurement.get("matrix_element"), - f"{context}.matrix_element", - ) - return _audit_lc_common_component( - cell, - measurement, - context=context, - ) - - -def _measurement_validation_point_digest( - measurement: Mapping[str, object], - *, - context: str, -) -> str: - selector = measurement.get("selector_contract") - if isinstance(selector, Mapping): - raw = selector.get("point_digest") - if isinstance(raw, str): - return raw - validation = measurement.get("validation") - if isinstance(validation, Mapping): - raw = validation.get("point_digest") - if isinstance(raw, str): - return raw - provenance = measurement.get("provenance") - if isinstance(provenance, Mapping) and "report_momenta" in provenance: - return point_digest(provenance["report_momenta"]) - raise FinalAuditError(f"{context} has no validation point identity") - - -def _stored_direct_agreement( - measurement: Mapping[str, object], - *, - edge_kind: str, - baseline_cell_id: str | None = None, -) -> Mapping[str, object] | None: - validation = measurement.get("validation") - records = ( - validation.get(DIRECT_AGREEMENT_FIELD) - if isinstance(validation, Mapping) - else None - ) - if not isinstance(records, list): - return None - matches = tuple( - record - for record in records - if isinstance(record, Mapping) - and record.get("edge_kind") == edge_kind - and ( - baseline_cell_id is None - or record.get("baseline_cell_id") == baseline_cell_id - ) - ) - return matches[0] if len(matches) == 1 else None - - -def _stored_pointwise_matches_baseline( - cell: CellSpec, - measurement: Mapping[str, object], - baseline: Mapping[str, object], -) -> bool: - validation = measurement.get("validation") - pointwise = validation.get("pointwise") if isinstance(validation, Mapping) else None - if not isinstance(pointwise, Mapping): - return False - if cell.measurement.accuracy is Accuracy.LC and measurement.get( - "selector_contract" - ) != baseline.get("selector_contract"): - return False - candidate_value = measurement.get("matrix_element") - baseline_value = baseline.get("matrix_element") - if ( - isinstance(candidate_value, bool) - or not isinstance(candidate_value, (int, float)) - or isinstance(baseline_value, bool) - or not isinstance(baseline_value, (int, float)) - ): - return False - try: - _audit_pointwise( - pointwise, - context=f"{cell.cell_id}.validation.pointwise", - expected_candidate=float(candidate_value), - expected_baseline=float(baseline_value), - expected_relative_tolerance=_expected_pointwise_tolerance(cell), - expected_point_digest=( - _measurement_validation_point_digest( - measurement, - context=cell.cell_id, - ) - if pointwise.get("abi") == CONDITIONED_COMPARISON_ABI - else None - ), - ) - except FinalAuditError: - return False - return True - - -def _stored_independent_pointwise_matches_baseline( - cell: CellSpec, - measurement: Mapping[str, object], - baseline_cell: CellSpec, - baseline: Mapping[str, object], -) -> bool: - """Authenticate the stored comparison against its selected authority. - - Authorities compare matrix elements and use the ordinary pointwise audit. - The retained Original-AmpliCol LC all-flow diagnostic authenticates only - the common selector component; its aggregate is never a candidate - baseline. - """ - - validation = measurement.get("validation") - pointwise = validation.get("pointwise") if isinstance(validation, Mapping) else None - if not isinstance(pointwise, Mapping): - return False - if pointwise.get("abi") == CONDITIONED_COMPARISON_ABI: - try: - canonical = conditioned_measurement_comparison( - cell, - measurement, - baseline, - ) - except (RuntimeError, TypeError, ValueError): - return False - return dict(pointwise) == canonical - - try: - component_only = baseline_uses_lc_common_component_authority( - cell, - baseline, - ) - except (RuntimeError, ValueError): - return False - if not component_only: - return _stored_pointwise_matches_baseline(cell, measurement, baseline) - if measurement.get("selector_contract") != baseline.get("selector_contract"): - return False - baseline_validation = baseline.get("validation") - if not isinstance(validation, Mapping) or not isinstance( - baseline_validation, - Mapping, - ): - return False - candidate_component = validation.get(LC_COMMON_COMPONENT_FIELD) - baseline_component = baseline_validation.get(LC_COMMON_COMPONENT_FIELD) - if not isinstance(candidate_component, Mapping) or not isinstance( - baseline_component, - Mapping, - ): - return False - try: - candidate_value = _audit_lc_common_component( - cell, - measurement, - context=cell.cell_id, - ) - baseline_value = _audit_lc_common_component( - baseline_cell, - baseline, - context=baseline_cell.cell_id, - ) - component_identity = { - "candidate_cell_id": candidate_component.get("cell_id"), - "baseline_cell_id": baseline_component.get("cell_id"), - "point_digest": candidate_component.get("point_digest"), - "helicity_ids": candidate_component.get("helicity_ids"), - "color_flow_ids": candidate_component.get("color_flow_ids"), - } - if any( - candidate_component.get(field) != baseline_component.get(field) - for field in ("point_digest", "helicity_ids", "color_flow_ids") - ): - return False - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": measurement.get("selector_contract"), - "value_kind": LC_COMMON_COMPONENT_FIELD, - "component_identity": component_identity, - } - _audit_pointwise( - validation.get("pointwise"), - context=f"{cell.cell_id}.validation.pointwise", - expected_candidate=candidate_value, - expected_baseline=baseline_value, - expected_relative_tolerance=_expected_pointwise_tolerance(cell), - expected_point_digest=_measurement_validation_point_digest( - measurement, - context=cell.cell_id, - ), - expected_candidate_source_sha256=digest_json(candidate_component), - expected_baseline_source_sha256=digest_json(baseline_component), - expected_selector_identity=selector_identity, - ) - except (FinalAuditError, RuntimeError, TypeError, ValueError): - return False - return True - - -def _stored_legacy_component_matches_baseline( - cell: CellSpec, - measurement: Mapping[str, object], - baseline_cell: CellSpec, - baseline: Mapping[str, object], -) -> bool: - record = _stored_direct_agreement( - measurement, - edge_kind=LC_LEGACY_PYAMPLICOL_COMPONENT, - baseline_cell_id=baseline_cell.cell_id, - ) - if ( - record is None - or baseline.get("status") != ResultStatus.OK.value - or measurement.get("selector_contract") != baseline.get("selector_contract") - ): - return False - edge = AgreementEdge(LC_LEGACY_PYAMPLICOL_COMPONENT, baseline_cell, cell) - try: - _audit_pointwise( - record, - context=f"{cell.cell_id}.validation.{DIRECT_AGREEMENT_FIELD}", - expected_candidate=_agreement_value( - edge, - cell, - measurement, - context=cell.cell_id, - ), - expected_baseline=_agreement_value( - edge, - baseline_cell, - baseline, - context=baseline_cell.cell_id, - ), - expected_relative_tolerance=edge.relative_tolerance, - expected_point_digest=( - _measurement_validation_point_digest( - measurement, - context=cell.cell_id, - ) - if record.get("abi") == DIRECT_AGREEMENT_V2_ABI - else None - ), - ) - except FinalAuditError: - return False - return True - - -def _audit_direct_agreements( - cells: Sequence[CellSpec], - measurements: Mapping[str, Mapping[str, object]], - *, - catalog: ReportCatalog, -) -> tuple[tuple[AgreementEdge, ...], dict[str, int]]: - """Authenticate every stored direct edge and reject missing or extra ones.""" - - selected_ids = {cell.cell_id for cell in cells} - allowed_edges = tuple( - edge - for edge in agreement_edges(catalog=catalog) - if edge.candidate.cell_id in selected_ids - and (not edge.required or edge.baseline.cell_id in measurements) - ) - incoming: dict[str, list[AgreementEdge]] = defaultdict(list) - for edge in allowed_edges: - incoming[edge.candidate.cell_id].append(edge) - - errors: list[str] = [] - audited_edges: list[AgreementEdge] = [] - for cell in cells: - measurement = measurements[cell.cell_id] - validation = _mapping( - measurement.get("validation"), - f"{cell.cell_id}.validation", - ) - raw_records = validation.get(DIRECT_AGREEMENT_FIELD) - if not isinstance(raw_records, list): - errors.append( - f"{cell.cell_id}: validation.{DIRECT_AGREEMENT_FIELD} is not an array" - ) - continue - allowed = tuple( - sorted( - incoming.get(cell.cell_id, ()), - key=lambda edge: (edge.kind, edge.baseline.cell_id), - ) - ) - required = tuple(edge for edge in allowed if edge.required) - records_by_key: dict[tuple[str, str], Mapping[str, object]] = {} - for index, raw_record in enumerate(raw_records): - if not isinstance(raw_record, Mapping): - errors.append( - f"{cell.cell_id}: direct agreement {index} is not an object" - ) - continue - key = ( - str(raw_record.get("edge_kind")), - str(raw_record.get("baseline_cell_id")), - ) - if key in records_by_key: - errors.append(f"{cell.cell_id}: duplicate direct agreement {key!r}") - records_by_key[key] = raw_record - required_keys = {(edge.kind, edge.baseline.cell_id) for edge in required} - allowed_keys = {(edge.kind, edge.baseline.cell_id) for edge in allowed} - observed_keys = set(records_by_key) - if not required_keys.issubset(observed_keys) or not ( - observed_keys <= allowed_keys - ): - errors.append( - f"{cell.cell_id}: direct agreement edge set differs; " - f"required={sorted(required_keys)}, " - f"allowed={sorted(allowed_keys)}, " - f"observed={sorted(observed_keys)}" - ) - continue - for edge in allowed: - key = (edge.kind, edge.baseline.cell_id) - if key not in records_by_key: - assert not edge.required - continue - context = f"{cell.cell_id}.validation.{DIRECT_AGREEMENT_FIELD}[{edge.kind}]" - record = records_by_key[key] - baseline_measurement = measurements.get(edge.baseline.cell_id) - if ( - record.get("abi") - not in {DIRECT_AGREEMENT_V2_ABI, DIRECT_AGREEMENT_V1_ABI} - or record.get("edge_kind") != edge.kind - or record.get("value_kind") != edge.value_kind - or record.get("baseline_cell_id") != edge.baseline.cell_id - or record.get("candidate_cell_id") != edge.candidate.cell_id - ): - errors.append(f"{context}: edge identity differs from the catalog") - continue - try: - candidate_value = _agreement_value( - edge, - edge.candidate, - measurement, - context=edge.candidate.cell_id, - ) - stored_baseline = _finite_number( - record.get("baseline"), - f"{context}.baseline", - ) - current_baseline: float | None = None - if ( - baseline_measurement is not None - and baseline_measurement.get("status") == ResultStatus.OK.value - and measurement.get("selector_contract") - == baseline_measurement.get("selector_contract") - ): - current_baseline = _agreement_value( - edge, - edge.baseline, - baseline_measurement, - context=edge.baseline.cell_id, - ) - if edge.required and current_baseline is None: - raise FinalAuditError( - f"{context}: required baseline is not a successful " - "selector-compatible current" - ) - if ( - record.get("abi") == DIRECT_AGREEMENT_V2_ABI - and current_baseline is not None - and baseline_measurement is not None - ): - expected_record = direct_agreement_record( - edge, - candidate_measurement=measurement, - baseline_measurement=baseline_measurement, - ) - if dict(record) != expected_record: - raise FinalAuditError( - f"{context}: conditioned scale/source binding differs " - "from the current candidate and authority" - ) - _audit_pointwise( - record, - context=context, - expected_candidate=candidate_value, - expected_baseline=( - current_baseline - if edge.required - or ( - current_baseline is not None - and _same_float(current_baseline, stored_baseline) - ) - else stored_baseline - ), - expected_relative_tolerance=edge.relative_tolerance, - expected_point_digest=( - _measurement_validation_point_digest( - measurement, - context=edge.candidate.cell_id, - ) - if record.get("abi") == DIRECT_AGREEMENT_V2_ABI - else None - ), - require_success=(edge.kind != LC_LEGACY_PYAMPLICOL_COMPONENT), - ) - audited_edges.append(edge) - except Exception as error: - errors.append(f"{context}: {error}") - - for cell in cells: - measurement = measurements[cell.cell_id] - validation = _mapping( - measurement.get("validation"), - f"{cell.cell_id}.validation", - ) - if cell.measurement.accuracy is Accuracy.LC: - try: - _audit_lc_common_component( - cell, - measurement, - context=cell.cell_id, - ) - except Exception as error: - errors.append(f"{cell.cell_id}: {error}") - elif validation.get(LC_COMMON_COMPONENT_FIELD) is not None: - errors.append( - f"{cell.cell_id}: contracted-color cell stores an LC component" - ) - if errors: - rendered = "\n".join(f"- {message}" for message in errors[:50]) - suffix = ( - "" - if len(errors) <= 50 - else f"\n- ... and {len(errors) - 50} additional failures" - ) - raise FinalAuditError( - f"final report direct-agreement audit failed ({len(errors)}):\n" - f"{rendered}{suffix}" - ) - counts = Counter(edge.kind for edge in audited_edges) - return tuple(audited_edges), { - kind: counts.get(kind, 0) - for kind in ( - BUILTIN_UFO_RECURRENCE, - Z_RECURRENCE_CROSS_MODE, - LC_CROSS_LAYOUT_COMPONENT, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_FULL_COLOUR, - ) - } - - -def _runtime_namespace_paths( - expected_checkout: Path, - *, - search_path: Sequence[str] | None = None, -) -> tuple[tuple[Path, ...], Path]: - """Resolve source-first roots and only the first native-bearing candidate.""" - - try: - checkout = expected_checkout.expanduser().resolve(strict=True) - source_package = (checkout / "src" / "pyamplicol").resolve(strict=True) - except OSError as error: - raise FinalAuditError( - "cannot resolve the expected source pyamplicol package" - ) from error - if not source_package.is_dir(): - raise FinalAuditError( - "expected checkout has no source pyamplicol package directory" - ) - entries = tuple(sys.path if search_path is None else search_path) - native_package: Path | None = None - native_extension: Path | None = None - for raw_entry in entries: - try: - entry = Path(raw_entry or os.getcwd()).expanduser().resolve(strict=True) - candidate = (entry / "pyamplicol").resolve(strict=True) - except OSError: - continue - if not candidate.is_dir(): - continue - matches = tuple( - path - for path in candidate.iterdir() - if path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(tuple(EXTENSION_SUFFIXES)) - ) - if not matches: - continue - try: - native = native_extension_in_package(candidate) - except RuntimeEvidenceError as error: - raise FinalAuditError( - "native-bearing pyamplicol candidate is ambiguous" - ) from error - native_package = candidate - native_extension = native - break - if native_package is None or native_extension is None: - raise FinalAuditError( - "no native-bearing pyamplicol candidate exists on the original " - "Python search path" - ) - roots = ( - (source_package,) - if native_package == source_package - else (source_package, native_package) - ) - return roots, native_extension - - -def _prepare_exact_pyamplicol_namespace( - expected_checkout: Path, -) -> tuple[object, tuple[Path, ...], Path, Mapping[str, object]]: - """Authenticate and establish the exact source/native namespace.""" - - package_roots, expected_native = _runtime_namespace_paths(expected_checkout) - already_loaded = any( - name == "pyamplicol" or name.startswith("pyamplicol.") for name in sys.modules - ) - try: - if already_loaded: - preimport_identity = established_preimport_runtime_identity() - else: - preimport_identity = preimport_python_runtime_identity( - package_roots, - native_extension=expected_native, - ) - except RuntimeEvidenceError as error: - raise FinalAuditError( - "pyamplicol runtime was not authenticated before import" - ) from error - - source_parent = str(package_roots[0].parent) - sys.path[:] = [ - source_parent, - *(entry for entry in sys.path if entry != source_parent), - ] - pyamplicol = importlib.import_module("pyamplicol") - try: - package_origin = Path(str(pyamplicol.__file__)).resolve(strict=True) - except OSError as error: - raise FinalAuditError( - "loaded pyamplicol package origin cannot be resolved" - ) from error - if package_origin.parent != package_roots[0]: - raise FinalAuditError( - "loaded pyamplicol package does not originate in the expected checkout" - ) - pyamplicol.__path__ = [str(root) for root in package_roots] - return pyamplicol, package_roots, expected_native, preimport_identity - - -def _active_runtime_snapshot( - expected_source_revision: str, - *, - expected_checkout: Path, -) -> dict[str, object]: - """Resolve the active candidate wheel/native identity once for the audit.""" - - ( - pyamplicol, - package_roots, - expected_native, - preimport_identity, - ) = _prepare_exact_pyamplicol_namespace(expected_checkout) - from pyamplicol._internal.versions import ( - _active_build_info, - verify_native_module, - ) - - native = importlib.import_module("pyamplicol._rusticol") - verify_native_module(native) - build_info = _mapping( - _active_build_info(), "active pyamplicol candidate build identity" - ) - fields = ( - "schema_version", - "version", - "candidate_fingerprint", - "source_revision", - "source_checkout", - "native_build_inputs_sha256", - "publishable", - ) - candidate = {field: build_info.get(field) for field in fields} - native_digest = native.native_build_inputs_sha256() - native_version = str(native.package_version()) - source_checkout = candidate["source_checkout"] - try: - checkout_matches = isinstance(source_checkout, str) and Path( - source_checkout - ).expanduser().resolve(strict=True) == expected_checkout.resolve(strict=True) - except OSError: - checkout_matches = False - if ( - candidate["source_revision"] != expected_source_revision - or candidate["publishable"] is not False - or candidate["native_build_inputs_sha256"] != native_digest - or candidate["version"] != pyamplicol.__version__ - or native_version.replace("-dev.", ".dev") != pyamplicol.__version__ - or not checkout_matches - or not isinstance(native_digest, str) - or _SHA256_RE.fullmatch(native_digest) is None - or any(candidate[field] is None for field in fields) - ): - raise FinalAuditError( - "active candidate/native runtime is not bound to the expected final SHA" - ) - native_path = Path(str(native.__file__)).resolve(strict=True) - if native_path != expected_native: - raise FinalAuditError( - "imported native extension is not the first eligible candidate" - ) - package_tree = _python_package_tree_identity(package_roots) - expected_package_tree = _mapping( - preimport_identity.get("python_package_tree"), - "preimport runtime identity.python_package_tree", - ) - expected_native_identity = _mapping( - preimport_identity.get("native_extension"), - "preimport runtime identity.native_extension", - ) - if preimport_identity.get( - "kind" - ) != "pyamplicol-preimport-runtime-identity-v1" or dict(package_tree) != dict( - expected_package_tree - ): - raise FinalAuditError( - "active pyamplicol package differs from its preimport identity" - ) - try: - loaded_origin_policy = loaded_pyamplicol_origin_policy( - package_roots, - native_extension=native_path, - expected_package_identity=dict(expected_package_tree), - expected_native_identity=dict(expected_native_identity), - ) - except RuntimeEvidenceError as error: - raise FinalAuditError( - "loaded pyamplicol module origins cannot be authenticated" - ) from error - target = native.target_info() - return { - "package_version": pyamplicol.__version__, - "python_package_tree": package_tree, - "loaded_module_origin_policy": loaded_origin_policy, - "candidate_build_identity": candidate, - "candidate_build_identity_sha256": digest_json(candidate), - "native_build_inputs_sha256": native_digest, - "native_extension": { - "path": str(native_path), - "sha256": _sha256_file(native_path), - "package_version": native_version, - }, - "native_target": { - "triple": str(target.triple), - "cpu_features": [str(value) for value in target.cpu_features], - }, - } - - -def _audit_active_runtime( - expected_source_revision: str, - expected_checkout: Path, -) -> Mapping[str, object]: - return _active_runtime_snapshot( - expected_source_revision, - expected_checkout=expected_checkout, - ) - - -def _git_checked( - repo_root: Path, - arguments: Sequence[str], - *, - timeout: float = 30.0, -) -> bytes: - try: - completed = subprocess.run( - ("git", *arguments), - cwd=repo_root, - check=False, - capture_output=True, - timeout=timeout, - ) - except (OSError, subprocess.SubprocessError) as error: - raise FinalAuditError( - "cannot authenticate report publication Git history" - ) from error - if completed.returncode != 0: - detail = completed.stderr.decode("utf-8", errors="replace").strip() - raise FinalAuditError( - "cannot authenticate report publication Git history: " - f"git {' '.join(arguments)} failed" + (f": {detail}" if detail else "") - ) - return completed.stdout - - -def _publication_relative_member(path: str) -> PurePosixPath | None: - """Return an allowed report member, rejecting executable/source paths.""" - - logical = PurePosixPath(path) - if ( - not logical.parts - or logical.is_absolute() - or logical.as_posix() != path - or any(part in {"", ".", ".."} for part in logical.parts) - ): - return None - parts = logical.parts - if parts[:3] == ("src", "pyamplicol", "_profiling_campaign"): - root_length = 3 - elif parts[:2] == ("docs", "performance_reports"): - if ( - len(parts) < 4 - or _REPORT_PROFILE_RE.fullmatch(parts[2]) is None - or ".." in parts[2] - ): - return None - root_length = 3 - else: - return None - relative = PurePosixPath(*parts[root_length:]) - relative_parts = relative.parts - if not relative_parts: - return None - if relative_parts[0] == "results": - return ( - relative - if ( - len(relative_parts) == 2 - and _PUBLICATION_MEMBER_RE.fullmatch(relative_parts[1]) is not None - and relative_parts[1].endswith(".json") - ) - else None - ) - if len(relative_parts) != 1: - return None - name = relative_parts[0] - if _PUBLICATION_MEMBER_RE.fullmatch(name) is None: - return None - if name in { - "README.md", - "architecture-profile.json", - "architecture_profile.json", - "final-audit.json", - "pyAmpliCol.pdf", - "pyAmpliCol.tex", - "report-manifest.json", - "report-workspace.json", - "report_environment.json", - "report_environment.tex", - }: - return relative - if name.endswith(".manifest.json"): - return relative - if name.endswith(".md"): - return relative - if name.startswith("section_") and name.endswith(".tex"): - return relative - if name.startswith("result_") and name.endswith("_table.tex"): - return relative - return None - - -def _git_tree_entry( - repo_root: Path, - revision: str, - path: str, -) -> tuple[str, str] | None: - payload = _git_checked( - repo_root, - ("ls-tree", "-z", revision, "--", path), - ) - if not payload: - return None - records = tuple(record for record in payload.split(b"\0") if record) - if len(records) != 1: - raise FinalAuditError( - f"publication path {path!r} is ambiguous in Git tree {revision}" - ) - try: - metadata, observed_path = records[0].split(b"\t", 1) - mode, kind, _object_id = metadata.decode("ascii").split(" ", 2) - decoded_path = os.fsdecode(observed_path) - except (UnicodeDecodeError, ValueError) as error: - raise FinalAuditError( - f"publication path {path!r} has malformed Git tree metadata" - ) from error - if decoded_path != path: - raise FinalAuditError( - f"publication path {path!r} does not match its Git tree entry" - ) - return mode, kind - - -def _require_nonexecutable_publication_blob( - repo_root: Path, - revision: str, - path: str, -) -> None: - entry = _git_tree_entry(repo_root, revision, path) - if entry is None: - return - mode, kind = entry - if mode != "100644" or kind != "blob": - raise FinalAuditError( - f"publication path {path!r} is executable, a symlink, or not a file" - ) - - -def _publication_diff( - repo_root: Path, - measurement_source_revision: str, - publication_revision: str, -) -> tuple[dict[str, str], ...]: - payload = _git_checked( - repo_root, - ( - "diff", - "--name-status", - "--no-renames", - "-z", - measurement_source_revision, - publication_revision, - "--", - ), - timeout=120.0, - ) - fields = tuple(field for field in payload.split(b"\0") if field) - if len(fields) % 2: - raise FinalAuditError("publication Git diff has malformed name-status data") - changes: list[dict[str, str]] = [] - for offset in range(0, len(fields), 2): - try: - status = fields[offset].decode("ascii") - path = os.fsdecode(fields[offset + 1]) - except UnicodeDecodeError as error: - raise FinalAuditError( - "publication Git diff contains invalid metadata" - ) from error - if status not in {"A", "D", "M"}: - raise FinalAuditError( - f"publication Git diff has unsupported status {status!r} for {path!r}" - ) - if _publication_relative_member(path) is None: - raise FinalAuditError( - "publication descendant changes a path outside the explicit " - f"non-executable report allowlist: {path!r}" - ) - if status != "A": - _require_nonexecutable_publication_blob( - repo_root, - measurement_source_revision, - path, - ) - if status != "D": - _require_nonexecutable_publication_blob( - repo_root, - publication_revision, - path, - ) - changes.append({"status": status, "path": path}) - return tuple(changes) - - -def _report_publication_lineage( - repo_root: Path, - measurement_source_revision: str, -) -> dict[str, object]: - """Authenticate a clean report-only descendant of one measured SHA.""" - - root = repo_root.expanduser().resolve(strict=False) - if _GIT_SHA_RE.fullmatch(measurement_source_revision) is None: - raise FinalAuditError("measurement source revision must be a full Git SHA") - publication_revision = ( - _git_checked( - root, - ("rev-parse", "--verify", "HEAD^{commit}"), - ) - .decode("ascii") - .strip() - ) - if _GIT_SHA_RE.fullmatch(publication_revision) is None: - raise FinalAuditError("publication revision is not a full Git SHA") - _git_checked( - root, - ("cat-file", "-e", f"{measurement_source_revision}^{{commit}}"), - ) - status = _git_checked( - root, - ("status", "--porcelain=v1", "-z", "--untracked-files=all"), - ) - if status: - raise FinalAuditError( - "publication checkout must be completely clean, including report outputs" - ) - ancestor = subprocess.run( - ( - "git", - "merge-base", - "--is-ancestor", - measurement_source_revision, - publication_revision, - ), - cwd=root, - check=False, - capture_output=True, - timeout=30, - ) - if ancestor.returncode not in {0, 1}: - raise FinalAuditError("cannot authenticate measurement/publication ancestry") - if ancestor.returncode != 0: - raise FinalAuditError( - "publication revision is not a descendant of the measurement " - "source revision" - ) - changes = _publication_diff( - root, - measurement_source_revision, - publication_revision, - ) - same_revision = publication_revision == measurement_source_revision - if not same_revision and not changes: - raise FinalAuditError( - "later publication revision has no report-only publication diff" - ) - return { - "kind": _PUBLICATION_LINEAGE_KIND, - "schema_version": 1, - "measurement_source_revision": measurement_source_revision, - "publication_revision": publication_revision, - "relationship": ("same-commit" if same_revision else "report-only-descendant"), - "worktree_clean": True, - "changed_path_count": len(changes), - "changed_paths": list(changes), - "changed_paths_sha256": digest_json(list(changes)), - "allowed_path_contract": ( - "src/pyamplicol/_profiling_campaign or " - "docs/performance_reports/PROFILE roots: " - "results/*.json, generated table TeX, report TeX/Markdown/PDF, " - "architecture metadata, and report manifests; regular " - "non-executable blobs only" - ), - "executable_source_unchanged": True, - } - - -def _require_report_source_checkout( - repo_root: Path, - expected_source_revision: str, -) -> Mapping[str, object]: - return _report_publication_lineage(repo_root, expected_source_revision) - - -def _active_report_profile(repo_root: Path, service: ReportService) -> str: - root = repo_root.expanduser().resolve(strict=False) - if service.paths.repo_root.resolve(strict=False) != root: - raise FinalAuditError( - "final-audit report service belongs to a different repository" - ) - profile_root = root / "docs" / "performance_reports" - try: - relative = service.paths.docs_dir.resolve(strict=False).relative_to( - profile_root - ) - except ValueError as error: - raise FinalAuditError( - "final-audit requires an architecture-specific report profile" - ) from error - if len(relative.parts) != 1: - raise FinalAuditError( - "final-audit report workspace is not one architecture profile" - ) - if service.paths.results_dir.resolve(strict=False) != ( - service.paths.docs_dir.resolve(strict=False) / "results" - ): - raise FinalAuditError( - "final-audit report results are not inside the active profile" - ) - try: - return validate_profile_name(relative.parts[0]) - except ValueError as error: - raise FinalAuditError("final-audit report profile is invalid") from error - - -def _profile_publication_lineage( - repo_root: Path, - measurement_source_revision: str, - *, - profile: str, -) -> dict[str, object]: - """Authenticate a clean descendant limited to one active report profile.""" - - root = repo_root.expanduser().resolve(strict=False) - status = _git_checked( - root, - ("status", "--porcelain=v1", "-z", "--untracked-files=all"), - ) - if status: - raise FinalAuditError( - "publication checkout must be completely clean, including report outputs" - ) - try: - identity = require_report_only_publication( - root, - measured_revision=measurement_source_revision, - profile=profile, - publication_revision="HEAD", - ) - except ReportSourceIdentityError as error: - raise FinalAuditError(str(error)) from error - same_revision = identity.publication_revision == identity.measured_revision - changes = list(identity.changed_paths) - if not same_revision and not changes: - raise FinalAuditError( - "later publication revision has no report-only publication diff" - ) - return { - "kind": _PUBLICATION_LINEAGE_KIND, - "schema_version": 1, - "measurement_source_revision": identity.measured_revision, - "measurement_source_tree": identity.measured_tree, - "publication_revision": identity.publication_revision, - "publication_tree": identity.publication_tree, - "report_profile": profile, - "relationship": ("same-commit" if same_revision else "report-only-descendant"), - "worktree_clean": True, - "changed_path_count": len(changes), - "changed_paths": changes, - "changed_paths_sha256": digest_json(changes), - "allowed_path_contract": ( - f"docs/performance_reports/{profile}/results/*.json, generated " - "environment JSON/TeX, table/summary TeX, and pyAmpliCol.pdf; " - "regular non-executable blobs only" - ), - "executable_source_unchanged": True, - } - - -def _validated_publication_lineage( - value: Mapping[str, object] | None, - *, - measurement_source_revision: str, - expected_publication_revision: str | None, - expected_profile: str | None = None, -) -> dict[str, object]: - if value is None: - # Injectable source auditors used by focused unit tests predate the - # lineage return value. Production always uses the fail-closed auditor. - result: dict[str, object] = { - "kind": _PUBLICATION_LINEAGE_KIND, - "schema_version": 1, - "measurement_source_revision": measurement_source_revision, - "measurement_source_tree": None, - "publication_revision": measurement_source_revision, - "publication_tree": None, - "report_profile": expected_profile, - "relationship": "same-commit", - "worktree_clean": True, - "changed_path_count": 0, - "changed_paths": [], - "changed_paths_sha256": digest_json([]), - "allowed_path_contract": "injected source auditor", - "executable_source_unchanged": True, - } - else: - result = dict(value) - publication_revision = result.get("publication_revision") - changes = result.get("changed_paths") - changed_count = result.get("changed_path_count") - if ( - result.get("kind") != _PUBLICATION_LINEAGE_KIND - or result.get("schema_version") != 1 - or result.get("measurement_source_revision") != measurement_source_revision - or not isinstance(publication_revision, str) - or _GIT_SHA_RE.fullmatch(publication_revision) is None - or result.get("relationship") not in {"same-commit", "report-only-descendant"} - or result.get("worktree_clean") is not True - or result.get("executable_source_unchanged") is not True - or isinstance(changes, (str, bytes)) - or not isinstance(changes, Sequence) - or isinstance(changed_count, bool) - or not isinstance(changed_count, int) - or changed_count != len(changes) - or result.get("changed_paths_sha256") != digest_json(list(changes)) - ): - raise FinalAuditError("source auditor returned invalid publication lineage") - if expected_profile is not None and ( - result.get("report_profile") != expected_profile - or not isinstance(result.get("measurement_source_tree"), str) - or _GIT_SHA_RE.fullmatch(str(result["measurement_source_tree"])) is None - or not isinstance(result.get("publication_tree"), str) - or _GIT_SHA_RE.fullmatch(str(result["publication_tree"])) is None - ): - raise FinalAuditError( - "source auditor returned a lineage for the wrong report profile or tree" - ) - if ( - expected_publication_revision is not None - and publication_revision != expected_publication_revision - ): - raise FinalAuditError( - "publication checkout HEAD does not equal the explicitly expected " - "publication revision" - ) - return result - - -def _pdf_text_identity(path: Path) -> dict[str, object]: - try: - from pypdf import PdfReader - - reader = PdfReader(path) - if reader.is_encrypted: - raise FinalAuditError("report PDF is unexpectedly encrypted") - pages = [page.extract_text() or "" for page in reader.pages] - except ModuleNotFoundError as error: - if error.name == "pypdf": - raise FinalAuditError( - "final PDF audit requires the documentation extra; install " - "`pyamplicol[docs]`" - ) from error - raise - except FinalAuditError: - raise - except Exception as error: - raise FinalAuditError(f"cannot extract report PDF text: {path}") from error - if not pages or not any(page.strip() for page in pages): - raise FinalAuditError("report PDF has no extractable page text") - return { - "page_count": len(pages), - "text_sha256": digest_json(pages), - "text_character_count": sum(len(page) for page in pages), - } - - -def _pdf_visual_identity(path: Path, output_root: Path) -> dict[str, object]: - """Render every page with one Poppler binary and hash the resulting pixels.""" - - pdftoppm = shutil.which("pdftoppm") - if pdftoppm is None: - raise FinalAuditError("pdftoppm is required for the final PDF visual audit") - output_root.mkdir(parents=True, exist_ok=False) - prefix = output_root / "page" - try: - completed = subprocess.run( - ( - pdftoppm, - "-png", - "-r", - "96", - str(path), - str(prefix), - ), - check=False, - capture_output=True, - text=True, - timeout=900, - ) - except subprocess.TimeoutExpired as error: - raise FinalAuditError(f"PDF rendering timed out: {path}") from error - if completed.returncode != 0: - tail = "\n".join( - (*completed.stdout.splitlines(), *completed.stderr.splitlines())[-40:] - ) - raise FinalAuditError( - f"PDF rendering failed with exit {completed.returncode}: {path}\n{tail}" - ) - pages = sorted(output_root.glob("page-*.png")) - if not pages: - raise FinalAuditError(f"PDF rendering produced no pages: {path}") - page_hashes = [_sha256_file(page) for page in pages] - return { - "page_count": len(page_hashes), - "page_pixel_sha256": digest_json(page_hashes), - } - - -def _tex_without_comments(source: str) -> str: - return re.sub(r"(? dict[str, object]: - """Require every rendered table to be reachable from the PDF master.""" - - try: - master = master_tex.expanduser().resolve(strict=True) - except OSError as error: - raise FinalAuditError( - f"report master TeX is unavailable: {master_tex}" - ) from error - docs_root = master.parent - tables: list[Path] = [] - for raw_table in canonical_tables: - try: - table = raw_table.expanduser().resolve(strict=True) - table.relative_to(docs_root) - except (OSError, ValueError) as error: - raise FinalAuditError( - f"canonical report table is unavailable or outside docs: {raw_table}" - ) from error - tables.append(table) - if not tables: - raise FinalAuditError("report PDF audit has no canonical rendered tables") - - reachable: set[Path] = set() - pending = [master] - while pending: - source = pending.pop() - if source in reachable: - continue - reachable.add(source) - try: - text = source.read_text(encoding="utf-8") - except OSError as error: - raise FinalAuditError( - f"cannot read reachable report TeX source: {source}" - ) from error - for match in _TEX_INPUT_RE.finditer(_tex_without_comments(text)): - raw_dependency = match.group(1).strip() - if not raw_dependency: - raise FinalAuditError(f"{source} contains an empty TeX dependency") - dependency = source.parent / raw_dependency - if dependency.suffix == "": - dependency = dependency.with_suffix(".tex") - try: - dependency = dependency.resolve(strict=True) - dependency.relative_to(docs_root) - except (OSError, ValueError) as error: - raise FinalAuditError( - f"{source} has an unavailable or out-of-tree TeX dependency " - f"{raw_dependency!r}" - ) from error - pending.append(dependency) - - missing = sorted( - table.relative_to(docs_root).as_posix() - for table in set(tables).difference(reachable) - ) - if missing: - raise FinalAuditError( - "canonical rendered tables are not reachable from pyAmpliCol.tex: " - + ", ".join(missing) - ) - relative_sources = sorted( - source.relative_to(docs_root).as_posix() for source in reachable - ) - return { - "master_path": str(master), - "reachable_tex_source_count": len(reachable), - "reachable_tex_sources_sha256": digest_json(relative_sources), - "reachable_table_source_count": len(set(tables)), - } - - -def _audit_pdf(service: ReportService) -> dict[str, object]: - """Rebuild the PDF and compare both extracted text and rendered pixels.""" - - latexmk = shutil.which("latexmk") - if latexmk is None: - raise FinalAuditError("latexmk is required for the final PDF audit") - published = service.paths.docs_dir / "pyAmpliCol.pdf" - if not published.is_file() or published.stat().st_size == 0: - raise FinalAuditError("published report pyAmpliCol.pdf is missing or empty") - rendered_tables = render_all_tables( - service.load_caches(), - catalog=service.catalog, - ) - table_paths = [service.paths.docs_dir / name for name in sorted(rendered_tables)] - tex_dependency_identity = _audit_tex_table_reachability( - service.paths.docs_dir / "pyAmpliCol.tex", - table_paths, - ) - service.paths.artifact_root.mkdir(parents=True, exist_ok=True) - staging = Path( - tempfile.mkdtemp( - prefix="final-report-pdf-audit-", - dir=service.paths.artifact_root, - ) - ) - try: - build_docs = staging / "docs" - shutil.copytree( - service.paths.docs_dir, - build_docs, - ignore=_report_source_copy_ignore( - service.paths.docs_dir, - "*.aux", - "*.fdb_latexmk", - "*.fls", - "*.log", - "*.out", - "*.toc", - "pyAmpliCol.pdf", - ".coordination", - ), - ) - environment = os.environ.copy() - environment.update({"LANG": "C", "LC_ALL": "C", "LC_CTYPE": "C"}) - completed = subprocess.run( - ( - latexmk, - "-pdf", - "-interaction=nonstopmode", - "-halt-on-error", - "-file-line-error", - "pyAmpliCol.tex", - ), - cwd=build_docs, - check=False, - capture_output=True, - text=True, - env=environment, - timeout=900, - ) - if completed.returncode != 0: - tail = "\n".join( - (*completed.stdout.splitlines(), *completed.stderr.splitlines())[-80:] - ) - raise FinalAuditError( - f"isolated report PDF rebuild failed with exit " - f"{completed.returncode}:\n{tail}" - ) - latex_log = build_docs / "pyAmpliCol.log" - try: - log = latex_log.read_text(encoding="utf-8", errors="replace") - validate_latex_log(log) - except OSError as error: - raise FinalAuditError( - f"cannot read isolated report LaTeX log: {error}" - ) from error - except StandaloneBuildError as error: - raise FinalAuditError(str(error)) from error - rebuilt = build_docs / "pyAmpliCol.pdf" - if not rebuilt.is_file() or rebuilt.stat().st_size == 0: - raise FinalAuditError("isolated report PDF rebuild produced no PDF") - published_text = _pdf_text_identity(published) - rebuilt_text = _pdf_text_identity(rebuilt) - if published_text != rebuilt_text: - raise FinalAuditError( - "published report PDF page text differs from a rebuild of the " - "audited caches and tables" - ) - published_visual = _pdf_visual_identity( - published, - staging / "published-pages", - ) - rebuilt_visual = _pdf_visual_identity( - rebuilt, - staging / "rebuilt-pages", - ) - if published_visual != rebuilt_visual: - raise FinalAuditError( - "published report PDF rendered pixels differ from a rebuild of " - "the audited caches and tables" - ) - table_identity = {path.name: _sha256_file(path) for path in table_paths} - return { - "status": ResultStatus.OK.value, - "published_path": str(published.resolve(strict=True)), - "published_sha256": _sha256_file(published), - "rebuilt_sha256": _sha256_file(rebuilt), - "normalized_page_text": published_text, - "rendered_pages": published_visual, - "table_source_count": len(table_identity), - "table_sources_sha256": digest_json(table_identity), - "master_tex_dependencies": tex_dependency_identity, - } - except subprocess.TimeoutExpired as error: - raise FinalAuditError("isolated report PDF rebuild timed out") from error - finally: - shutil.rmtree(staging, ignore_errors=True) - - -def _expected_evaluator_abis(cell: CellSpec) -> tuple[str, str]: - if cell.measurement.execution_mode is ExecutionMode.COMPILED: - if cell.measurement.backend == "jit": - return _COMPILED_DIRECT_ABI, _SYMJIT_PLANE_APPLICATION_ABI - return _NATIVE_COMPILED_DIRECT_ABI, _NATIVE_COMPILED_DIRECT_ABI - if cell.measurement.execution_mode is ExecutionMode.EAGER: - source = ( - _SYMJIT_PLANE_APPLICATION_ABI - if cell.measurement.backend == "jit" - else _EAGER_NATIVE_APPLICATION_ABI - ) - return _EAGER_DIRECT_BINDING_ABI, source - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY: - if cell.measurement.backend != "jit": - raise FinalAuditError( - "on-the-fly report cells require prepared JIT source evaluators" - ) - return _ON_THE_FLY_EXECUTION_KIND, _SYMJIT_PLANE_APPLICATION_ABI - source = ( - _SYMJIT_PLANE_APPLICATION_ABI - if cell.measurement.backend == "jit" - else _SOURCE_RUNTIME_CAPABILITY[cell.measurement.backend] - ) - return "pyamplicol-recurrence-runtime-layout-v2", source - - -def _audit_runtime_identity( - cell: CellSpec, - provenance: Mapping[str, object], - *, - expected_source_revision: str | None, - active_runtime: Mapping[str, object], - artifact: ArtifactEvidence | None, -) -> None: - context = f"{cell.cell_id}.provenance.runtime_identity" - identity = _mapping(provenance.get("runtime_identity"), context) - identity_digest = provenance.get("runtime_identity_sha256") - if identity_digest != digest_json(identity): - raise FinalAuditError(f"{context} canonical SHA-256 does not match") - active_package_tree = _validate_python_package_tree_identity( - active_runtime.get("python_package_tree"), - context="active_runtime.python_package_tree", - ) - _validate_loaded_origin_policy( - active_runtime.get("loaded_module_origin_policy"), - context="active_runtime.loaded_module_origin_policy", - ) - _validate_loaded_origin_policy( - identity.get("loaded_module_origin_policy"), - context=f"{context}.loaded_module_origin_policy", - ) - _audit_runtime_identity_postflight( - provenance, - identity, - context=f"{cell.cell_id}.provenance", - ) - expected_capability = _ARENA_CAPABILITY[cell.measurement.execution_mode] - expected_abi, expected_source_abi = _expected_evaluator_abis(cell) - expected_source_runtime_capability = _SOURCE_RUNTIME_CAPABILITY.get( - cell.measurement.backend - ) - if expected_source_runtime_capability is None: - raise FinalAuditError( - f"{context} has unsupported backend {cell.measurement.backend!r}" - ) - checks = { - "kind": "pyamplicol-report-runtime-identity-v1", - "execution_mode": cell.measurement.execution_mode.value, - "loaded_execution_mode": cell.measurement.execution_mode.value, - "backend": cell.measurement.backend, - "required_arena_capability": expected_capability, - "expected_evaluator_abi": expected_abi, - "expected_source_evaluator_abi": expected_source_abi, - "expected_source_evaluator_runtime_capability": ( - expected_source_runtime_capability - ), - "source_revision": expected_source_revision, - "package_version": active_runtime.get("package_version"), - "python_package_tree": active_package_tree, - "candidate_build_identity": active_runtime.get("candidate_build_identity"), - "candidate_build_identity_sha256": active_runtime.get( - "candidate_build_identity_sha256" - ), - "native_build_inputs_sha256": active_runtime.get("native_build_inputs_sha256"), - "native_extension": active_runtime.get("native_extension"), - "native_target": active_runtime.get("native_target"), - } - mismatches = [ - field for field, expected in checks.items() if identity.get(field) != expected - ] - source_level_field = "source_jit_optimization_level" - direct_level_field = "direct_codegen_optimization_level" - if cell.measurement.backend == "jit": - source_level = identity.get(source_level_field) - if ( - type(source_level) is not int - or source_level != cell.measurement.jit_optimization_level - ): - mismatches.append(source_level_field) - elif source_level_field in identity: - mismatches.append(source_level_field) - if ( - cell.measurement.execution_mode is ExecutionMode.COMPILED - and cell.measurement.backend == "jit" - ): - direct_level = identity.get(direct_level_field) - if ( - type(direct_level) is not int - or direct_level != cell.measurement.jit_optimization_level - ): - mismatches.append(direct_level_field) - direct_identity = _mapping( - identity.get("direct_codegen_identity"), - f"{context}.direct_codegen_identity", - ) - if ( - direct_identity.get("kind") - != "authenticated-compiled-plane-arena-direct-codegen-v1" - or direct_identity.get("optimization_level") - != cell.measurement.jit_optimization_level - or direct_identity.get("source_optimization_level") - != cell.measurement.jit_optimization_level - or type(direct_identity.get("leaf_count")) is not int - or int(direct_identity["leaf_count"]) <= 0 - or not isinstance(direct_identity.get("execution_manifest_path"), str) - or not isinstance(direct_identity.get("execution_manifest_sha256"), str) - or _SHA256_RE.fullmatch( - str(direct_identity.get("execution_manifest_sha256")) - ) - is None - ): - mismatches.append("direct_codegen_identity") - else: - if direct_level_field in identity: - mismatches.append(direct_level_field) - if "direct_codegen_identity" in identity: - mismatches.append("direct_codegen_identity") - if ( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.backend == "jit" - ): - source_jit_identity = _mapping( - identity.get("source_jit_identity"), - f"{context}.source_jit_identity", - ) - if ( - source_jit_identity.get("kind") - != "authenticated-recurrence-direct-template-source-v1" - or source_jit_identity.get("optimization_level") - != cell.measurement.jit_optimization_level - or type(source_jit_identity.get("direct_template_count")) is not int - or int(source_jit_identity["direct_template_count"]) <= 0 - or type(source_jit_identity.get("prepared_direct_template_count")) - is not int - or int(source_jit_identity["prepared_direct_template_count"]) <= 0 - or type(source_jit_identity.get("source_evaluator_leaf_count")) is not int - or int(source_jit_identity["source_evaluator_leaf_count"]) <= 0 - or source_jit_identity.get("source_application_abi") - != _SYMJIT_PLANE_APPLICATION_ABI - or source_jit_identity.get("direct_application_abi") - != _RECURRENCE_JIT_DIRECT_APPLICATION_ABI - or _SHA256_RE.fullmatch( - str(source_jit_identity.get("prepared_kernel_pack_digest")) - ) - is None - or _SHA256_RE.fullmatch( - str(source_jit_identity.get("direct_template_catalog_digest")) - ) - is None - or not isinstance(source_jit_identity.get("execution_manifest_path"), str) - or not isinstance(source_jit_identity.get("kernel_pack_path"), str) - or not isinstance(source_jit_identity.get("execution_manifest_sha256"), str) - or _SHA256_RE.fullmatch( - str(source_jit_identity.get("execution_manifest_sha256")) - ) - is None - or not isinstance(source_jit_identity.get("kernel_pack_sha256"), str) - or _SHA256_RE.fullmatch(str(source_jit_identity.get("kernel_pack_sha256"))) - is None - ): - mismatches.append("source_jit_identity") - elif "source_jit_identity" in identity: - mismatches.append("source_jit_identity") - if identity.get("artifact_identity_match") is not True: - mismatches.append("artifact_identity_match") - if mismatches: - raise FinalAuditError( - f"{context} differs from the active final runtime: " - + ", ".join(sorted(set(mismatches))) - ) - if artifact is None: - return - _audit_artifact_producer_identity( - artifact, - expected_source_revision=expected_source_revision, - active_runtime=active_runtime, - ) - artifact_checks = { - "artifact_id": artifact.artifact_id, - "loaded_artifact_id": artifact.artifact_id, - "process_id": artifact.process_id, - "artifact_runtime_version": artifact.runtime_version, - "process_required_runtime_capabilities": list(artifact.runtime_capabilities), - } - mismatches = [] - measured_effective = _mapping( - provenance.get("effective_config"), - f"{cell.cell_id}.provenance.effective_config", - ) - if dict(measured_effective) != dict(artifact.effective_config): - mismatches.append("effective_config") - if ( - cell.measurement.execution_mode is ExecutionMode.COMPILED - and cell.measurement.backend == "jit" - ): - direct_identity = _mapping( - identity.get("direct_codegen_identity"), - f"{context}.direct_codegen_identity", - ) - direct_checks = { - "execution_manifest_path": artifact.execution_manifest_path, - "execution_manifest_sha256": artifact.execution_manifest_sha256, - "leaf_count": artifact.direct_leaf_count, - } - mismatches.extend( - f"direct_codegen_identity.{field}" - for field, expected in direct_checks.items() - if direct_identity.get(field) != expected - ) - if ( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.backend == "jit" - ): - source_jit_identity = _mapping( - identity.get("source_jit_identity"), - f"{context}.source_jit_identity", - ) - if artifact.source_jit_identity is None or dict(source_jit_identity) != dict( - artifact.source_jit_identity - ): - mismatches.append("source_jit_identity") - elif artifact.source_jit_identity is not None: - mismatches.append("artifact.source_jit_identity") - mismatches.extend( - field - for field, expected in artifact_checks.items() - if identity.get(field) != expected - ) - if mismatches: - raise FinalAuditError( - f"{context} differs from the authenticated artifact: " - + ", ".join(mismatches) - ) - - -def _audit_artifact_producer_identity( - artifact: ArtifactEvidence, - *, - expected_source_revision: str | None, - active_runtime: Mapping[str, object], -) -> None: - """Bind artifact production to the measured native runtime identity.""" - - candidate = _mapping( - active_runtime.get("candidate_build_identity"), - "active_runtime.candidate_build_identity", - ) - if candidate.get("source_revision") != expected_source_revision: - raise FinalAuditError( - "active runtime source revision differs from the measurement source" - ) - checks = { - "version": ( - artifact.producer_version, - active_runtime.get("package_version"), - ), - "git_revision": ( - artifact.producer_git_revision, - expected_source_revision, - ), - "native_build_inputs_sha256": ( - artifact.producer_native_build_inputs_sha256, - active_runtime.get("native_build_inputs_sha256"), - ), - } - mismatches = [ - field for field, (observed, expected) in checks.items() if observed != expected - ] - if mismatches: - raise FinalAuditError( - "artifact producer differs from the measured runtime: " - + ", ".join(mismatches) - ) - - -def _runtime_for_measurement_source( - active_runtime: Mapping[str, object], - provenance: Mapping[str, object], - *, - source_revision: str, - measurement_lineage: MeasurementLineage | None, -) -> Mapping[str, object]: - """Project invariant descendant runtime fields onto a retained A identity.""" - - if ( - measurement_lineage is None - or source_revision == measurement_lineage.descendant_revision - ): - return active_runtime - if source_revision != measurement_lineage.ancestor_revision: - raise FinalAuditError( - f"measurement source {source_revision} is outside the source bridge" - ) - identity = _mapping( - provenance.get("runtime_identity"), - "retained ancestor provenance.runtime_identity", - ) - package_tree = identity.get("python_package_tree") - if not isinstance(package_tree, Mapping): - raise FinalAuditError( - "retained ancestor runtime identity lacks its Python package tree" - ) - candidate = identity.get("candidate_build_identity") - candidate_digest = identity.get("candidate_build_identity_sha256") - native_extension = identity.get("native_extension") - native_target = identity.get("native_target") - native_features = ( - native_target.get("cpu_features") - if isinstance(native_target, Mapping) - else None - ) - environment = measurement_lineage.environment_for_source(source_revision) - if ( - not isinstance(candidate, Mapping) - or candidate.get("source_revision") != source_revision - or candidate_digest != digest_json(candidate) - or not isinstance(native_extension, Mapping) - or not isinstance(native_target, Mapping) - or not isinstance(native_features, list) - or not all(isinstance(feature, str) for feature in native_features) - or environment is None - or package_tree.get("sha256") != environment.get("python_package_tree_sha256") - or identity.get("package_version") != environment.get("pyamplicol") - or candidate.get("candidate_fingerprint") - != environment.get("candidate_fingerprint") - or candidate.get("native_build_inputs_sha256") - != environment.get("native_build_inputs_sha256") - or identity.get("native_build_inputs_sha256") - != environment.get("native_build_inputs_sha256") - or native_extension.get("sha256") != environment.get("native_extension_sha256") - or native_target.get("triple") != environment.get("native_target") - or (", ".join(native_features) or "baseline") - != environment.get("native_cpu_features") - ): - raise FinalAuditError( - "retained ancestor runtime identity differs from its authenticated " - "Class-C environment" - ) - ancestor_native_inputs = identity.get("native_build_inputs_sha256") - descendant_native_inputs = active_runtime.get("native_build_inputs_sha256") - native_inputs_match = ancestor_native_inputs == descendant_native_inputs - if not native_inputs_match: - native_inputs_match = _is_authorized_native_inputs_transition( - impact=measurement_lineage.impact, - ancestor_revision=measurement_lineage.ancestor_revision, - descendant_revision=measurement_lineage.descendant_revision, - ancestor_digest=ancestor_native_inputs, - descendant_digest=descendant_native_inputs, - ) - if not native_inputs_match or native_target != active_runtime.get("native_target"): - raise FinalAuditError( - "retained ancestor runtime changes a Class-C invariant native identity" - ) - projected = dict(active_runtime) - projected["package_version"] = identity.get("package_version") - projected["python_package_tree"] = package_tree - projected["candidate_build_identity"] = candidate - projected["candidate_build_identity_sha256"] = candidate_digest - projected["native_build_inputs_sha256"] = ancestor_native_inputs - # The ancestor and descendant extensions are independently authenticated by - # their endpoint environments. A fresh relink need not be byte-identical, - # so retained ancestor measurements must be checked against their own - # extension identity rather than the active descendant's output file. - projected["native_extension"] = native_extension - origin_policy = identity.get("loaded_module_origin_policy") - if isinstance(origin_policy, Mapping): - projected["loaded_module_origin_policy"] = origin_policy - return projected - - -def _audit_effective_config( - cell: CellSpec, - provenance: Mapping[str, object], -) -> Mapping[str, object]: - context = f"{cell.cell_id}.provenance.effective_config" - effective = _mapping(provenance.get("effective_config"), context) - _audit_effective_config_mapping(cell, effective, context=context) - return effective - - -def _audit_effective_config_mapping( - cell: CellSpec, - effective: Mapping[str, object], - *, - context: str, -) -> None: - evaluator = _mapping(effective.get("evaluator"), f"{context}.evaluator") - color = _mapping(effective.get("color"), f"{context}.color") - generation = _mapping(effective.get("generation"), f"{context}.generation") - on_the_fly = cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - expected_layout = ( - "topology-replay" - if on_the_fly - else ( - "all-flow-union" - if cell.workload is Workload.ALL_FLOW - else "topology-replay" - ) - ) - mismatches: list[str] = [] - expected = { - "execution_mode": cell.measurement.execution_mode.value, - "backend": cell.measurement.backend, - } - mismatches.extend( - f"evaluator.{field}" - for field, value in expected.items() - if evaluator.get(field) != value - ) - if color.get("accuracy") != cell.measurement.accuracy.value: - mismatches.append("color.accuracy") - if color.get("lc_flow_layout") != expected_layout: - mismatches.append("color.lc_flow_layout") - if cell.measurement.jit_optimization_level is not None: - jit = _mapping(evaluator.get("jit"), f"{context}.evaluator.jit") - if jit.get("optimization_level") != cell.measurement.jit_optimization_level: - mismatches.append("evaluator.jit.optimization_level") - if on_the_fly and generation.get("relation_discovery") != {"mode": "off"}: - mismatches.append("generation.relation_discovery") - if mismatches: - raise FinalAuditError( - f"{context} differs from the report contract: " + ", ".join(mismatches) - ) - - -def _audit_model_source( - cell: CellSpec, - effective: Mapping[str, object], -) -> None: - context = "authenticated effective configuration.model.source" - model = _mapping( - effective.get("model"), "authenticated effective configuration.model" - ) - source = model.get("source") - if not isinstance(source, str) or not source: - raise FinalAuditError(f"{context} is invalid") - if cell.measurement.model is ModelKey.BUILTIN_SM: - if source != "built-in-sm": - raise FinalAuditError(f"{context} differs from the built-in-SM cell") - return - relative = _MODEL_SOURCE_PATH.get(cell.measurement.model) - if relative is None: - raise FinalAuditError( - f"{cell.cell_id} has no authenticated model-source contract" - ) - repo_root = Path(__file__).resolve().parents[2] - expected = (repo_root / relative).resolve(strict=True) - try: - observed = Path(source).expanduser().resolve(strict=True) - except OSError as error: - raise FinalAuditError(f"{context} is unavailable: {source}") from error - if observed != expected: - raise FinalAuditError( - f"{context} differs from the exact source for " - f"{cell.measurement.model.value}" - ) - - -def _artifact_reference( - cell: CellSpec, - measurement: Mapping[str, object], - *, - report_paths: ReportPaths | None = None, -) -> _ArtifactReference: - artifact = _mapping(measurement.get("artifact"), f"{cell.cell_id}.artifact") - raw_path = artifact.get("path") - process_id = artifact.get("process_id") - if not isinstance(raw_path, str) or not raw_path: - raise FinalAuditError(f"{cell.cell_id}.artifact.path is invalid") - if not isinstance(process_id, str) or not process_id: - raise FinalAuditError(f"{cell.cell_id}.artifact.process_id is invalid") - try: - if raw_path.startswith(_PORTABLE_ARTIFACT_ROOT): - if report_paths is None: - raise FinalAuditError( - f"{cell.cell_id}.artifact.path requires report path context" - ) - suffix = raw_path.removeprefix(_PORTABLE_ARTIFACT_ROOT) - if not suffix.startswith("/") or suffix == "/": - raise FinalAuditError( - f"{cell.cell_id}.artifact.path has an invalid portable locator" - ) - logical = _canonical_relative_path( - suffix.removeprefix("/"), - f"{cell.cell_id}.artifact", - ) - path = report_paths.artifact_root.joinpath(*logical.parts).resolve( - strict=True - ) - path.relative_to(report_paths.artifact_root.resolve(strict=True)) - else: - if "${" in raw_path: - raise FinalAuditError( - f"{cell.cell_id}.artifact.path has an unsupported locator" - ) - path = Path(raw_path).expanduser().resolve(strict=True) - except OSError as error: - raise FinalAuditError( - f"{cell.cell_id}.artifact.path is unavailable: {raw_path}" - ) from error - except ValueError as error: - raise FinalAuditError( - f"{cell.cell_id}.artifact.path escapes its report artifact root" - ) from error - if not path.is_dir(): - raise FinalAuditError(f"{cell.cell_id}.artifact.path is not a directory") - return _ArtifactReference(cell, measurement, path, process_id) - - -def _shared_artifact_contract(cell: CellSpec) -> tuple[object, ...]: - """Fields that must agree when report cells reuse one process artifact.""" - - workload = ( - None - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - and cell.workload in {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - else cell.workload - ) - return ( - cell.process, - cell.n_final, - cell.process_key, - cell.measurement, - workload, - ) - - -def _expected_legacy_revision(repo_root: Path) -> str: - lock_path = repo_root / "dependencies" / "contributor-lock.toml" - try: - lock = tomllib.loads(lock_path.read_text(encoding="utf-8")) - section = _mapping(lock.get("legacy_amplicol"), "legacy_amplicol lock") - revision = section.get("revision") - except (OSError, tomllib.TOMLDecodeError) as error: - raise FinalAuditError( - "cannot authenticate the pinned original-AmpliCol revision" - ) from error - if not isinstance(revision, str) or _GIT_SHA_RE.fullmatch(revision) is None: - raise FinalAuditError("pinned original-AmpliCol revision is invalid") - return revision - - -def _audit_unavailable_execution_timing( - cell: CellSpec, - provenance: Mapping[str, object], - *, - measurement_sample_count: int, - context: str, -) -> None: - """Authenticate an unavailable execution attribution from the Arena profiler.""" - - timing = _mapping( - provenance.get("execution_timing"), - f"{context}.provenance.execution_timing", - ) - if set(timing) != ARENA_UNAVAILABLE_EXECUTION_TIMING_FIELDS: - raise FinalAuditError( - f"{context}.provenance.execution_timing fields do not match " - "the authenticated contract" - ) - timing_sample_count = timing.get("sample_count") - measurement = { - "execution_seconds_per_point": None, - "provenance": { - "execution_timing": timing, - "arena_profile_evidence": provenance.get("arena_profile_evidence"), - }, - } - if ( - unavailable_execution_timing_record( - measurement, - "execution_seconds_per_point", - ) - is None - or isinstance(timing_sample_count, bool) - or not isinstance(timing_sample_count, int) - or timing_sample_count < 5 - or timing_sample_count != measurement_sample_count - or timing.get("execution_mode") != cell.measurement.execution_mode.value - ): - raise FinalAuditError( - f"{context}.provenance.execution_timing is not an authenticated " - "Arena unavailable-attribution record" - ) - - -def _publication_policy_errors( - context: str, - measurement: Mapping[str, object], - *, - expected_source_revision: str, - expected_source_tree: str | None, -) -> tuple[str, ...]: - errors = [ - f"{context}.{issue.field}: {issue.detail}" - for issue in publication_measurement_policy_issues(measurement) - ] - if measurement.get("status") != ResultStatus.OK.value: - return tuple(errors) - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return tuple(errors) - for field in ("report_source_revision", "report_measured_source_revision"): - if provenance.get(field) != expected_source_revision: - errors.append( - f"{context}.provenance.{field}: does not match the measured commit" - ) - if expected_source_tree is not None: - for field in ("report_source_tree", "report_measured_source_tree"): - if provenance.get(field) != expected_source_tree: - errors.append( - f"{context}.provenance.{field}: " - "does not match the measured Git tree" - ) - return tuple(errors) - - -def _audit_runtime_profile_warmup_evidence( - cell: CellSpec, - provenance: Mapping[str, object], - *, - context: str, -) -> None: - """Reject incomplete or semantically widened OTF warm-up timings.""" - - if cell.measurement.execution_mode is not ExecutionMode.ON_THE_FLY: - return - if provenance.get("runtime_load_included_in_cold_warmup") is not False: - raise FinalAuditError( - f"{context}.provenance.runtime_load_included_in_cold_warmup must be false" - ) - if provenance.get("generation_timer_excludes_model_preparation") is not True: - raise FinalAuditError( - f"{context}.provenance.generation_timer_excludes_model_preparation " - "must be true" - ) - effective = _mapping( - provenance.get("effective_config"), - f"{context}.provenance.effective_config", - ) - benchmark = _mapping( - effective.get("benchmark"), - f"{context}.provenance.effective_config.benchmark", - ) - expected_batch_size = benchmark.get("batch_size") - expected_warmup_runs = benchmark.get("warmup_runs") - if ( - isinstance(expected_batch_size, bool) - or not isinstance(expected_batch_size, int) - or expected_batch_size < 1 - ): - raise FinalAuditError( - f"{context}.provenance.effective_config.benchmark.batch_size must " - "be positive" - ) - if ( - isinstance(expected_warmup_runs, bool) - or not isinstance(expected_warmup_runs, int) - or expected_warmup_runs < 0 - ): - raise FinalAuditError( - f"{context}.provenance.effective_config.benchmark.warmup_runs must " - "be non-negative" - ) - if expected_batch_size != REPORT_BENCHMARK_BATCH_SIZE: - raise FinalAuditError( - f"{context}.provenance.effective_config.benchmark.batch_size must " - f"equal the final report contract {REPORT_BENCHMARK_BATCH_SIZE}" - ) - if expected_warmup_runs != REPORT_BENCHMARK_WARMUP_RUNS: - raise FinalAuditError( - f"{context}.provenance.effective_config.benchmark.warmup_runs must " - f"equal the final report contract {REPORT_BENCHMARK_WARMUP_RUNS}" - ) - try: - validate_profile_warmup_evidence( - provenance.get("runtime_profile"), - execution_mode=cell.measurement.execution_mode, - expected_batch_size=expected_batch_size, - expected_warmup_run_count=expected_warmup_runs, - ) - except ValueError as error: - raise FinalAuditError( - f"{context}.provenance.runtime_profile: {error}" - ) from error - - -def _audit_measurement( - cell: CellSpec, - measurement: Mapping[str, object], - *, - baseline: Mapping[str, object] | None, - baseline_cell: CellSpec | None = None, - expected_source_revision: str, - expected_legacy_revision: str, - active_runtime: Mapping[str, object] | None, - expected_source_tree: str | None = None, - report_paths: ReportPaths | None = None, -) -> _ArtifactReference | None: - context = cell.cell_id - if measurement.get("status") != ResultStatus.OK.value: - raise FinalAuditError( - f"{context}.measurement.status is not {ResultStatus.OK.value!r}" - ) - if measurement.get("failure") is not None: - raise FinalAuditError(f"{context}.measurement has failure metadata") - matrix_element = _finite_number( - measurement.get("matrix_element"), - f"{context}.measurement.matrix_element", - nonnegative=True, - ) - for field in ("generation_seconds", "wall_seconds_per_point"): - _finite_number( - measurement.get(field), - f"{context}.measurement.{field}", - nonnegative=True, - ) - sample_count = measurement.get("sample_count") - if ( - isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < 5 - ): - raise FinalAuditError( - f"{context}.measurement.sample_count must be at least five" - ) - provenance = _mapping( - measurement.get("provenance"), f"{context}.measurement.provenance" - ) - _audit_runtime_profile_warmup_evidence( - cell, - provenance, - context=f"{context}.measurement", - ) - if provenance.get("report_source_revision") != expected_source_revision: - raise FinalAuditError( - f"{context} was not measured at source SHA {expected_source_revision}" - ) - if expected_source_tree is not None and ( - provenance.get("report_source_tree") != expected_source_tree - or provenance.get("report_measured_source_tree") != expected_source_tree - ): - raise FinalAuditError( - f"{context} source tree does not match the measured Git tree" - ) - validation = _mapping( - measurement.get("validation"), f"{context}.measurement.validation" - ) - if validation.get("status") != ResultStatus.OK.value: - raise FinalAuditError(f"{context}.measurement.validation.status is not ok") - validation_point_digest = _measurement_validation_point_digest( - measurement, - context=context, - ) - - raw_selector = measurement.get("selector_contract") - selector: SelectorContract | None = None - if cell.measurement.accuracy is Accuracy.LC: - selector = SelectorContract.from_mapping( - _mapping(raw_selector, f"{context}.measurement.selector_contract") - ) - elif raw_selector is not None: - raise FinalAuditError( - f"{context} contracted-color measurement has a selector contract" - ) - - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - if validation.get("method") != "independent-original-amplicol-oracle": - raise FinalAuditError( - f"{context} does not identify the legacy AmpliCol diagnostic" - ) - stored_point_digest = validation.get("point_digest") - expected_point_digest = point_digest(shared_validation_points(cell.process)) - if ( - not isinstance(stored_point_digest, str) - or _SHA256_RE.fullmatch(stored_point_digest) is None - or stored_point_digest != expected_point_digest - ): - raise FinalAuditError( - f"{context} oracle point digest does not match its physical process" - ) - if selector is not None and stored_point_digest != selector.point_digest: - raise FinalAuditError( - f"{context} oracle and selector use different validation points" - ) - revision = provenance.get("revision") - if revision != expected_legacy_revision: - raise FinalAuditError( - f"{context} does not use the pinned original-AmpliCol revision" - ) - return None - - if cell.measurement.execution_mode is ExecutionMode.MADGRAPH: - if baseline is not None or baseline_cell is not None: - raise FinalAuditError(f"{context} MadGraph oracle has a catalog baseline") - if validation.get("method") != "independent-madgraph-tree-level-oracle": - raise FinalAuditError( - f"{context} does not identify the independent MadGraph oracle" - ) - expected_point_digest = point_digest(shared_validation_points(cell.process)) - if validation.get("point_digest") != expected_point_digest: - raise FinalAuditError( - f"{context} MadGraph point digest differs from its physical process" - ) - execution_seconds = _finite_number( - measurement.get("execution_seconds_per_point"), - f"{context}.measurement.execution_seconds_per_point", - ) - if execution_seconds <= 0.0: - raise FinalAuditError( - f"{context}.measurement.execution_seconds_per_point must be positive" - ) - if provenance.get("method") != "madgraph-standalone-custom-fortran-driver": - raise FinalAuditError(f"{context} MadGraph driver method is invalid") - from .madgraph import madgraph_command_card - - expected_command_card = madgraph_command_card(cell.process) - if ( - provenance.get("command_card") != expected_command_card - or provenance.get("command_card_sha256") - != hashlib.sha256(expected_command_card.encode("utf-8")).hexdigest() - or provenance.get("generation_timing_scope") - != "generate-output-standalone-launch-force" - or provenance.get("generation_includes_madgraph_compilation") is not True - or provenance.get("driver_compilation_in_generation_seconds") is not False - ): - raise FinalAuditError( - f"{context} MadGraph generation command/timing scope is invalid" - ) - warmup_calls = provenance.get("driver_warmup_calls") - profile_chunks = provenance.get("profile_chunk_count") - if ( - isinstance(warmup_calls, bool) - or not isinstance(warmup_calls, int) - or warmup_calls < 20 - or isinstance(profile_chunks, bool) - or not isinstance(profile_chunks, int) - or profile_chunks < 5 - ): - raise FinalAuditError( - f"{context} MadGraph driver warmup/profile census is invalid" - ) - model = _mapping(provenance.get("model"), f"{context}.provenance.model") - if ( - model.get("name") != "sm" - or not isinstance(model.get("source_directory"), str) - or not Path(str(model["source_directory"])).is_absolute() - or _SHA256_RE.fullmatch(str(model.get("source_sha256"))) is None - ): - raise FinalAuditError(f"{context} MadGraph UFO-SM identity is invalid") - for field in ("default_restriction", "exact_param_card"): - parameter_record = _mapping( - provenance.get(field), - f"{context}.provenance.{field}", - ) - count = parameter_record.get("external_parameter_count") - if ( - isinstance(count, bool) - or not isinstance(count, int) - or count < 1 - or _SHA256_RE.fullmatch( - str(parameter_record.get("external_parameters_sha256")) - ) - is None - or parameter_record.get("binary64_exact_match") is not True - or parameter_record.get("format") != "%.14e" - ): - raise FinalAuditError(f"{context} MadGraph {field} identity is invalid") - commands = _sequence( - provenance.get("commands"), - f"{context}.provenance.commands", - ) - if len(commands) < profile_chunks + 2: - raise FinalAuditError(f"{context} MadGraph command census is incomplete") - for index, raw_command in enumerate(commands): - command = _mapping( - raw_command, - f"{context}.provenance.commands[{index}]", - ) - args = command.get("args") - cwd = command.get("cwd") - elapsed = _finite_number( - command.get("elapsed_seconds"), - f"{context}.provenance.commands[{index}].elapsed_seconds", - nonnegative=True, - ) - if ( - command.get("returncode") != 0 - or isinstance(args, (str, bytes)) - or not isinstance(args, Sequence) - or not args - or not isinstance(cwd, str) - or not Path(cwd).is_absolute() - or elapsed < 0.0 - ): - raise FinalAuditError(f"{context} MadGraph command {index} is invalid") - return None - - raw_execution_seconds = measurement.get("execution_seconds_per_point") - if raw_execution_seconds is None: - _audit_unavailable_execution_timing( - cell, - provenance, - measurement_sample_count=sample_count, - context=f"{context}.measurement", - ) - else: - execution_seconds = _finite_number( - raw_execution_seconds, - f"{context}.measurement.execution_seconds_per_point", - ) - if execution_seconds <= 0.0: - raise FinalAuditError( - f"{context}.measurement.execution_seconds_per_point must be positive" - ) - if EVALUATOR_TOTAL_TIMING_KEY in provenance: - evaluator_total = evaluator_total_timing_record(measurement) - if ( - evaluator_total is None - or evaluator_total.get("execution_mode") - != cell.measurement.execution_mode.value - ): - raise FinalAuditError( - f"{context}.measurement.provenance.evaluator_total_timing " - "is not an authenticated accumulated evaluator-total record" - ) - if provenance.get("source_revision") != expected_source_revision: - raise FinalAuditError( - f"{context} pyAmpliCol source revision is not the measurement SHA" - ) - if active_runtime is None: - raise FinalAuditError("pyAmpliCol measurements require an active runtime") - _audit_effective_config(cell, provenance) - raw_resolved_sum = _mapping( - validation.get("resolved_sum"), - f"{context}.measurement.validation.resolved_sum", - ) - _audit_resolved_sum( - raw_resolved_sum, - context=f"{context}.measurement.validation.resolved_sum", - ) - resolved_source_sha256 = ( - str(raw_resolved_sum["resolved_source_sha256"]) - if raw_resolved_sum.get("abi") == RESOLVED_SUM_VALIDATION_ABI - else None - ) - ordinary_selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": raw_selector, - "value_kind": "matrix-element", - } - high_selector_identity = { - **ordinary_selector_identity, - "value_kind": "matrix-element-p16-versus-p32", - } - raw_high_precision = validation.get("high_precision") - raw_high_resolved: Mapping[str, object] | None = None - if ( - isinstance(raw_high_precision, Mapping) - and raw_high_precision.get("abi") == CONDITIONED_COMPARISON_ABI - ): - raw_high_resolved = _mapping( - validation.get("high_precision_resolved_sum"), - f"{context}.measurement.validation.high_precision_resolved_sum", - ) - _audit_resolved_sum( - raw_high_resolved, - context=f"{context}.measurement.validation.high_precision_resolved_sum", - ) - if ( - raw_high_resolved.get("point_digest") != validation_point_digest - or raw_high_resolved.get("precision_digits") != 32 - ): - raise FinalAuditError( - f"{context} p32 resolved scale is bound to a different point/precision" - ) - - scalar = cell.measurement.model in { - ModelKey.SCALAR_CONTACT, - ModelKey.SCALAR_GRAVITY, - } - if scalar: - try: - _validate_standalone_internal_validation(measurement, validation) - except ValueError as error: - raise FinalAuditError( - f"{context}.measurement.validation standalone evidence: {error}" - ) from error - _audit_pointwise( - validation.get("high_precision"), - context=f"{context}.measurement.validation.high_precision", - expected_candidate=matrix_element, - expected_baseline=_finite_number( - _mapping( - validation.get("high_precision"), - f"{context}.measurement.validation.high_precision", - ).get("baseline"), - f"{context}.measurement.validation.high_precision.baseline", - ), - expected_relative_tolerance=RELATIVE_TOLERANCE, - expected_point_digest=validation_point_digest, - expected_candidate_source_sha256=resolved_source_sha256, - expected_baseline_source_sha256=( - str(raw_high_resolved["resolved_source_sha256"]) - if isinstance(raw_high_precision, Mapping) - and raw_high_precision.get("abi") == CONDITIONED_COMPARISON_ABI - else None - ), - expected_selector_identity=high_selector_identity, - ) - if baseline is not None: - raise FinalAuditError(f"{context} scalar cell has a catalog baseline") - else: - if baseline is None: - raw_pointwise = validation.get("pointwise") - if isinstance(raw_high_precision, Mapping): - if cell.measurement.execution_mode not in { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - }: - raise FinalAuditError( - f"{context} stores inapplicable high-precision authority" - ) - _audit_pointwise( - raw_high_precision, - context=f"{context}.measurement.validation.high_precision", - expected_candidate=matrix_element, - expected_baseline=_finite_number( - raw_high_precision.get("baseline"), - f"{context}.measurement.validation.high_precision.baseline", - nonnegative=True, - ), - expected_relative_tolerance=RELATIVE_TOLERANCE, - expected_point_digest=validation_point_digest, - expected_candidate_source_sha256=resolved_source_sha256, - expected_baseline_source_sha256=( - str(raw_high_resolved["resolved_source_sha256"]) - if raw_high_resolved is not None - else None - ), - expected_selector_identity=high_selector_identity, - ) - elif cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - raise FinalAuditError( - f"{context}.measurement.validation has no high_precision " - "self-consistency authority" - ) - elif isinstance(raw_pointwise, Mapping): - raise FinalAuditError(f"{context} has an unbound pointwise baseline") - elif ( - _stored_direct_agreement( - measurement, - edge_kind=Z_RECURRENCE_CROSS_MODE, - ) - is None - ): - raise FinalAuditError( - f"{context} has no canonical or stored recurrence authority" - ) - elif baseline_uses_lc_common_component_authority(cell, baseline): - if INDEPENDENT_AUTHORITY_FIELD in validation: - if baseline_cell is None: - raise FinalAuditError( - f"{context} has no selected LC component authority" - ) - if not _stored_independent_pointwise_matches_baseline( - cell, - measurement, - baseline_cell, - baseline, - ): - raise FinalAuditError( - f"{context} LC component authority comparison is invalid" - ) - elif "pointwise" in validation: - raise FinalAuditError( - f"{context} compares an LC all-flow aggregate outside the " - "legacy provider replay authority" - ) - baseline_selector = baseline.get("selector_contract") - if raw_selector != baseline_selector: - raise FinalAuditError( - f"{context} selector contract differs from canonical baseline" - ) - else: - baseline_value = _finite_number( - baseline.get("matrix_element"), - f"{context}.canonical_baseline.matrix_element", - nonnegative=True, - ) - _audit_pointwise( - validation.get("pointwise"), - context=f"{context}.measurement.validation.pointwise", - expected_candidate=matrix_element, - expected_baseline=baseline_value, - expected_relative_tolerance=_expected_pointwise_tolerance(cell), - expected_point_digest=validation_point_digest, - expected_candidate_source_sha256=resolved_source_sha256, - expected_selector_identity=ordinary_selector_identity, - ) - if INDEPENDENT_AUTHORITY_FIELD in validation and ( - baseline_cell is None - or not _stored_independent_pointwise_matches_baseline( - cell, - measurement, - baseline_cell, - baseline, - ) - ): - raise FinalAuditError( - f"{context} conditioned authority binding is not canonical" - ) - baseline_selector = baseline.get("selector_contract") - if cell.measurement.accuracy is Accuracy.LC: - if raw_selector != baseline_selector: - raise FinalAuditError( - f"{context} selector contract differs from canonical baseline" - ) - elif baseline_selector is not None: - raise FinalAuditError( - f"{context} contracted canonical baseline has selectors" - ) - - return _artifact_reference( - cell, - measurement, - report_paths=report_paths, - ) - - -def _validation_baseline_endpoint_for_audit( - cell: CellSpec, - measurements: Mapping[str, Mapping[str, object]], - measurement_states: Mapping[str, PolicyMeasurementState], - *, - catalog: ReportCatalog, -) -> tuple[CellSpec, Mapping[str, object]] | None: - """Resolve an authoritative baseline without promoting diagnostics. - - Original AmpliCol is never returned as an authority, irrespective of - whether its optional comparison happens to agree. Recurrence is audited - through its high-precision self-consistency evidence; compiled/eager - results authenticate the recurrence endpoint selected by their durable - independent-authority record. - """ - - measurement = measurements.get(cell.cell_id) - if measurement is None: - raise FinalAuditError(f"candidate measurement {cell.cell_id!r} is missing") - validation = _mapping( - measurement.get("validation"), - f"{cell.cell_id}.validation", - ) - raw_authority = validation.get(INDEPENDENT_AUTHORITY_FIELD) - if raw_authority is not None: - if not requires_independent_numerical_authority(cell, catalog=catalog): - raise FinalAuditError( - f"{cell.cell_id} stores inapplicable independent authority" - ) - record = _mapping( - raw_authority, - f"{cell.cell_id}.validation.{INDEPENDENT_AUTHORITY_FIELD}", - ) - expected_fields = { - "abi", - "expected_cell_ids", - "selected_cell_id", - "status", - "reason", - "same_artifact_diagnostics_are_authority", - } - authorities = independent_numerical_authorities(cell, catalog=catalog) - authority_ids = [authority.cell_id for authority in authorities] - selected_id = record.get("selected_cell_id") - if ( - set(record) != expected_fields - or record.get("abi") != INDEPENDENT_AUTHORITY_ABI - or record.get("expected_cell_ids") != authority_ids - or record.get("status") != "verified" - or record.get("reason") != "independent-authority-agreement" - or record.get("same_artifact_diagnostics_are_authority") is not False - or not isinstance(selected_id, str) - or selected_id not in authority_ids - ): - raise FinalAuditError( - f"{cell.cell_id} independent-authority record is invalid" - ) - selected_index = authority_ids.index(selected_id) - for higher_priority in authorities[:selected_index]: - if ( - measurement_states.get(higher_priority.cell_id) - is PolicyMeasurementState.SUCCESS - ): - raise FinalAuditError( - f"{cell.cell_id} has an unreconciled higher-priority authority " - f"{higher_priority.cell_id!r}" - ) - selected_cell = authorities[selected_index] - selected = measurements.get(selected_id) - if ( - selected is None - or measurement_states.get(selected_id) is not PolicyMeasurementState.SUCCESS - ): - raise FinalAuditError( - f"selected independent authority {selected_id!r} is unavailable" - ) - if not _stored_independent_pointwise_matches_baseline( - cell, - measurement, - selected_cell, - selected, - ): - raise FinalAuditError( - f"{cell.cell_id} stored comparison does not authenticate selected " - f"authority {selected_id!r}" - ) - return selected_cell, selected - baseline_cell = catalog.validation_baseline_cell(cell) - if baseline_cell is None: - return None - baseline = measurements.get(baseline_cell.cell_id) - baseline_state = measurement_states.get(baseline_cell.cell_id) - if validation_baseline_is_required(cell, baseline_cell): - if baseline is None: - raise FinalAuditError( - f"canonical baseline {baseline_cell.cell_id!r} is missing" - ) - if baseline_state is not PolicyMeasurementState.SUCCESS: - raise FinalAuditError( - f"required canonical baseline {baseline_cell.cell_id!r} " - "is not successful" - ) - return baseline_cell, baseline - if ( - baseline_cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - and baseline_state is PolicyMeasurementState.SUCCESS - ): - if baseline is None: - raise FinalAuditError( - f"successful optional baseline {baseline_cell.cell_id!r} is missing" - ) - if _stored_pointwise_matches_baseline(cell, measurement, baseline): - return baseline_cell, baseline - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - return None - if cell.measurement.execution_mode in { - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - }: - # Compatibility for already-valid currents produced before the durable - # authority record was introduced. They must still carry an - # authenticated comparison to a successful canonical endpoint. - for authority_cell in independent_numerical_authorities( - cell, - catalog=catalog, - ): - authority = measurements.get(authority_cell.cell_id) - if ( - authority is None - or measurement_states.get(authority_cell.cell_id) - is not PolicyMeasurementState.SUCCESS - ): - continue - if _stored_independent_pointwise_matches_baseline( - cell, - measurement, - authority_cell, - authority, - ): - return authority_cell, authority - if ( - authority_cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and _stored_direct_agreement( - measurement, - edge_kind=Z_RECURRENCE_CROSS_MODE, - baseline_cell_id=authority_cell.cell_id, - ) - is not None - ): - return None - raise FinalAuditError( - f"{cell.cell_id} has no successful authenticated numerical authority" - ) - raise FinalAuditError(f"{cell.cell_id} has no successful canonical baseline") - - -def _validation_baseline_for_audit( - cell: CellSpec, - measurements: Mapping[str, Mapping[str, object]], - measurement_states: Mapping[str, PolicyMeasurementState], - *, - catalog: ReportCatalog, -) -> Mapping[str, object] | None: - endpoint = _validation_baseline_endpoint_for_audit( - cell, - measurements, - measurement_states, - catalog=catalog, - ) - return None if endpoint is None else endpoint[1] - - -def _legacy_consumer_coverage( - successful_cells: Sequence[CellSpec], - measurements: Mapping[str, Mapping[str, object]], - measurement_states: Mapping[str, PolicyMeasurementState], - *, - catalog: ReportCatalog, -) -> tuple[tuple[str, str], ...]: - """Report authenticated legacy diagnostics without treating them as authority.""" - - legacy_ids = { - cell.cell_id - for cell in successful_cells - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - } - linked: list[tuple[str, str]] = [] - for candidate in successful_cells: - direct_legacy = next( - ( - edge - for edge in incoming_agreement_edges(candidate, catalog=catalog) - if edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT - and edge.baseline.cell_id in legacy_ids - and _stored_direct_agreement( - measurements[candidate.cell_id], - edge_kind=edge.kind, - baseline_cell_id=edge.baseline.cell_id, - ) - is not None - ), - None, - ) - if direct_legacy is not None: - linked.append((direct_legacy.baseline.cell_id, candidate.cell_id)) - continue - baseline_cell = catalog.validation_baseline_cell(candidate) - if ( - baseline_cell is None - or baseline_cell.cell_id not in legacy_ids - or measurement_states.get(baseline_cell.cell_id) - is not PolicyMeasurementState.SUCCESS - ): - continue - baseline = measurements.get(baseline_cell.cell_id) - if baseline is not None and ( - _stored_pointwise_matches_baseline( - candidate, - measurements[candidate.cell_id], - baseline, - ) - or _stored_legacy_component_matches_baseline( - candidate, - measurements[candidate.cell_id], - baseline_cell, - baseline, - ) - ): - linked.append((baseline_cell.cell_id, candidate.cell_id)) - return tuple(linked) - - -def _find_process_execution( - artifact: Path, - manifest: object, - process_id: str, -) -> tuple[dict[str, Any], str, str, tuple[str, ...]]: - runtime = _mapping(manifest.runtime, "artifact.runtime") - raw_index = runtime.get("evaluator_manifest_path") - index, index_relative, _index_sha256 = _authenticated_json_payload( - artifact, - manifest, - raw_index, - process_id=None, - context="evaluator manifest index", - ) - if ( - index.get("kind") != "pyamplicol-runtime-execution-set" - or type(index.get("schema_version")) is not int - or index.get("schema_version") != 3 - ): - raise FinalAuditError("artifact evaluator index has an invalid contract") - matches = [ - item - for item in _sequence(index.get("processes"), "evaluator index.processes") - if isinstance(item, Mapping) and item.get("process_id") == process_id - ] - if len(matches) != 1: - raise FinalAuditError( - f"artifact evaluator index does not uniquely identify {process_id!r}" - ) - record = matches[0] - raw_execution = record.get("manifest_path") - execution_logical = _canonical_relative_path( - raw_execution, - "process execution manifest", - ) - execution_relative = ( - PurePosixPath(index_relative).parent / execution_logical - ).as_posix() - execution, execution_relative, execution_sha256 = _authenticated_json_payload( - artifact, - manifest, - execution_relative, - process_id=process_id, - context="process execution manifest", - ) - capabilities = tuple( - str(value) - for value in _sequence( - record.get("required_runtime_capabilities"), - "evaluator process capabilities", - ) - ) - return execution, execution_relative, execution_sha256, capabilities - - -def _walk_compiled_lanes( - value: object, - *, - path: str = "execution", -) -> list[tuple[str, Mapping[str, object]]]: - result: list[tuple[str, Mapping[str, object]]] = [] - if isinstance(value, Mapping): - compiled = value.get("compiled") - if isinstance(compiled, Mapping) and isinstance( - compiled.get("stage_evaluators"), Mapping - ): - result.append((f"{path}.compiled", compiled)) - for key, child in value.items(): - result.extend(_walk_compiled_lanes(child, path=f"{path}.{key}")) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - result.extend(_walk_compiled_lanes(child, path=f"{path}[{index}]")) - return result - - -def _audit_symjit_plane_evaluator_leaves( - value: object, - *, - optimization_level: int, - context: str, -) -> list[tuple[str, str]]: - evaluator = _mapping(value, context) - if evaluator.get("kind") == "chunked-symbolica-evaluator": - chunks = _sequence(evaluator.get("chunks"), f"{context}.chunks") - if not chunks: - raise FinalAuditError(f"{context} has no source-evaluator leaves") - leaves: list[tuple[str, str]] = [] - for index, chunk in enumerate(chunks): - leaves.extend( - _audit_symjit_plane_evaluator_leaves( - chunk, - optimization_level=optimization_level, - context=f"{context}.chunks[{index}]", - ) - ) - return leaves - mismatches: list[str] = [] - if evaluator.get("kind") != "symjit-application-evaluator": - mismatches.append("kind") - legacy_backend = evaluator.get("backend") - if "backend" in evaluator and legacy_backend != "jit": - mismatches.append("backend") - if evaluator.get("runtime_capability") != _SOURCE_RUNTIME_CAPABILITY["jit"]: - mismatches.append("runtime_capability") - if evaluator.get("application_abi") != _SYMJIT_APPLICATION_ABI: - mismatches.append("application_abi") - if evaluator.get("element_layout") != "complex-f64": - mismatches.append("element_layout") - if evaluator.get("batch_layout") != "row-major": - mismatches.append("batch_layout") - if evaluator.get("compiler_type") != "native": - mismatches.append("compiler_type") - if evaluator.get("translation_mode") not in {"direct", "indirect"}: - mismatches.append("translation_mode") - if evaluator.get("optimization_level") != optimization_level: - mismatches.append("optimization_level") - if evaluator.get("word_bits") != 64: - mismatches.append("word_bits") - if evaluator.get("endianness") != "little": - mismatches.append("endianness") - if evaluator.get("required_defuns") != []: - mismatches.append("required_defuns") - fallback_path = evaluator.get("evaluator_state_path") - fallback_capability = evaluator.get("evaluator_state_runtime_capability") - if fallback_path is None and fallback_capability is None: - pass - elif ( - not isinstance(fallback_path, str) - or fallback_capability != "symbolica.legacy-jit-container.complex-f64.v1" - ): - mismatches.append("evaluator_state_fallback") - else: - _canonical_relative_path( - fallback_path, - f"{context}.fallback_evaluator_state", - ) - input_len = evaluator.get("input_len") - output_len = evaluator.get("output_len") - if isinstance(input_len, bool) or not isinstance(input_len, int) or input_len < 0: - mismatches.append("input_len") - if ( - isinstance(output_len, bool) - or not isinstance(output_len, int) - or output_len < 0 - ): - mismatches.append("output_len") - _canonical_relative_path( - evaluator.get("application_path"), - f"{context}.ordinary_application", - ) - plane = _mapping( - evaluator.get("plane_application"), - f"{context}.plane_application", - ) - if plane.get("application_abi") != _SYMJIT_PLANE_APPLICATION_ABI: - mismatches.append("plane_application.application_abi") - if plane.get("storage_abi") != _SYMJIT_APPLICATION_ABI: - mismatches.append("plane_application.storage_abi") - if plane.get("element_layout") != "split-complex-plane-major": - mismatches.append("plane_application.element_layout") - if plane.get("descriptor_order") != "inputs-re-im-then-outputs-re-im": - mismatches.append("plane_application.descriptor_order") - if isinstance(input_len, int) and not isinstance(input_len, bool): - if plane.get("input_complex_count") != input_len: - mismatches.append("plane_application.input_complex_count") - if plane.get("input_plane_count") != 2 * input_len: - mismatches.append("plane_application.input_plane_count") - if isinstance(output_len, int) and not isinstance(output_len, bool): - if plane.get("output_complex_count") != output_len: - mismatches.append("plane_application.output_complex_count") - if plane.get("output_plane_count") != 2 * output_len: - mismatches.append("plane_application.output_plane_count") - if plane.get("compiler_type") != "native": - mismatches.append("plane_application.compiler_type") - if plane.get("translation_mode") != "symbolica-structured-instructions": - mismatches.append("plane_application.translation_mode") - if plane.get("direct_arena") is not True: - mismatches.append("plane_application.direct_arena") - if plane.get("simd") is not True: - mismatches.append("plane_application.simd") - if plane.get("complex") is not True: - mismatches.append("plane_application.complex") - if plane.get("fast_math") is not True: - mismatches.append("plane_application.fast_math") - if plane.get("fast_complex") is not False: - mismatches.append("plane_application.fast_complex") - if not isinstance(plane.get("compression"), bool): - mismatches.append("plane_application.compression") - if plane.get("threading") is not False: - mismatches.append("plane_application.threading") - if plane.get("optimization_level") != optimization_level: - mismatches.append("plane_application.optimization_level") - target = plane.get("target") - if not _valid_symjit_plane_target(target): - mismatches.append("plane_application.target") - plane_path = _canonical_relative_path( - plane.get("application_path"), - f"{context}.plane_application.application", - ).as_posix() - source_digest = _require_sha256( - plane.get("source_digest"), - f"{context}.plane_application.source_digest", - ) - if mismatches: - raise FinalAuditError( - f"{context} differs from the JIT plane source evaluator contract: " - + ", ".join(mismatches) - ) - return [(plane_path, source_digest)] - - -def _audit_source_evaluator( - value: object, - cell: CellSpec, - *, - context: str, -) -> int: - if cell.measurement.backend == "jit": - level = cell.measurement.jit_optimization_level - if isinstance(level, bool) or not isinstance(level, int): - raise FinalAuditError( - f"{context} has no authenticated JIT optimization level" - ) - return len( - _audit_symjit_plane_evaluator_leaves( - value, - optimization_level=level, - context=context, - ) - ) - evaluator = _mapping(value, context) - kind = evaluator.get("kind") - if kind == "chunked-symbolica-evaluator": - chunks = _sequence(evaluator.get("chunks"), f"{context}.chunks") - if not chunks: - raise FinalAuditError(f"{context} has no source-evaluator leaves") - return sum( - _audit_source_evaluator( - chunk, - cell, - context=f"{context}.chunks[{index}]", - ) - for index, chunk in enumerate(chunks) - ) - expected_kind = "compiled-complex-evaluator" - expected_capability = _SOURCE_RUNTIME_CAPABILITY.get(cell.measurement.backend) - if expected_capability is None: - raise FinalAuditError( - f"{cell.cell_id} has unsupported evaluator backend " - f"{cell.measurement.backend!r}" - ) - mismatches: list[str] = [] - if kind != expected_kind: - mismatches.append("kind") - if evaluator.get("runtime_capability") != expected_capability: - mismatches.append("runtime_capability") - if mismatches: - raise FinalAuditError( - f"{context} differs from the {cell.measurement.backend} source " - "evaluator contract: " + ", ".join(mismatches) - ) - return 1 - - -def _audit_compiled_execution( - execution: Mapping[str, object], - cell: CellSpec, -) -> tuple[int, int]: - if execution.get("kind") != "pyamplicol-runtime-execution": - raise FinalAuditError("compiled execution manifest kind is invalid") - expected_application, expected_source = _expected_evaluator_abis(cell) - lanes = _walk_compiled_lanes(execution) - if not lanes: - raise FinalAuditError("compiled execution contains no executable lanes") - plane_count = 0 - direct_leaf_count = 0 - for lane_path, compiled in lanes: - stages = _mapping( - compiled.get("stage_evaluators"), - f"{lane_path}.stage_evaluators", - ) - stage_records = list(_sequence(stages.get("stages"), f"{lane_path}.stages")) - stage_records.append( - _mapping( - stages.get("amplitude_stage"), - f"{lane_path}.amplitude_stage", - ) - ) - if not stage_records: - raise FinalAuditError(f"{lane_path} has no fused stages") - for index, raw_stage in enumerate(stage_records): - stage = _mapping(raw_stage, f"{lane_path}.stage[{index}]") - arena = _mapping( - stage.get("compiled_plane_arena"), - f"{lane_path}.stage[{index}].compiled_plane_arena", - ) - expected = { - "schema_version": 1, - "kind": "compiled-plane-arena-stage", - "application_abi": expected_application, - "source_application_abi": expected_source, - "element_layout": "split-complex-component-major", - "output_operation": "overwrite", - "output_factor": "identity", - "input_output_aliasing": "forbidden", - "output_output_aliasing": "forbidden", - } - mismatches = [ - field for field, value in expected.items() if arena.get(field) != value - ] - inputs = _sequence( - arena.get("input_bindings"), f"{lane_path}.arena.input_bindings" - ) - outputs = _sequence( - arena.get("output_bindings"), - f"{lane_path}.arena.output_bindings", - ) - leaves = _sequence(arena.get("leaves"), f"{lane_path}.arena.leaves") - if len(inputs) != stage.get("parameter_count"): - mismatches.append("input_bindings") - if len(outputs) != stage.get("output_length"): - mismatches.append("output_bindings") - if not leaves: - mismatches.append("leaves") - source_planes: list[tuple[str, str]] = [] - if cell.measurement.backend == "jit": - source_level = cell.measurement.jit_optimization_level - if isinstance(source_level, bool) or not isinstance( - source_level, - int, - ): - raise FinalAuditError( - f"{lane_path}.stage[{index}] has no JIT optimization level" - ) - source_planes = _audit_symjit_plane_evaluator_leaves( - stage.get("evaluator"), - optimization_level=source_level, - context=f"{lane_path}.stage[{index}].evaluator", - ) - source_leaf_count = len(source_planes) - else: - source_leaf_count = _audit_source_evaluator( - stage.get("evaluator"), - cell, - context=f"{lane_path}.stage[{index}].evaluator", - ) - if source_leaf_count != len(leaves): - mismatches.append("source_evaluator_leaf_count") - for leaf_index, leaf in enumerate(leaves): - leaf_record = _mapping(leaf, f"{lane_path}.arena.leaf") - if leaf_record.get("source_application_abi") != expected_source: - mismatches.append("leaf.source_application_abi") - if ( - cell.measurement.backend == "jit" - and leaf_record.get("optimization_level") - != cell.measurement.jit_optimization_level - ): - mismatches.append("leaf.optimization_level") - if ( - cell.measurement.backend == "jit" - and leaf_index < len(source_planes) - and leaf_record.get("application_path") - != source_planes[leaf_index][0] - ): - mismatches.append("leaf.application_path") - expected_direct_level = ( - cell.measurement.jit_optimization_level - if cell.measurement.backend == "jit" - else 3 - ) - if ( - leaf_record.get("direct_codegen_optimization_level") - != expected_direct_level - ): - mismatches.append("leaf.direct_codegen_optimization_level") - if mismatches: - raise FinalAuditError( - f"{lane_path} has incompatible plane-Arena metadata: " - + ", ".join(sorted(set(mismatches))) - ) - plane_count += 1 - direct_leaf_count += len(leaves) - model_parameters = compiled.get("model_parameter_evaluator") - if model_parameters is not None: - _assert_model_parameter_not_direct( - model_parameters, - context=f"{lane_path}.model_parameter_evaluator", - ) - return plane_count, direct_leaf_count - - -def _assert_model_parameter_not_direct( - value: object, - *, - context: str, -) -> None: - """Reject every compiled DirectApplication representation recursively.""" - - if isinstance(value, Mapping): - if value.get("kind") == "compiled-plane-arena-stage": - raise FinalAuditError( - f"{context} model-parameter evaluator entered plane Arena" - ) - if "compiled_plane_arena" in value or "native_direct_application" in value: - raise FinalAuditError( - f"{context} model-parameter evaluator carries " - "DirectApplication metadata" - ) - if value.get("application_abi") in { - _COMPILED_DIRECT_ABI, - _NATIVE_COMPILED_DIRECT_ABI, - }: - raise FinalAuditError( - f"{context} model-parameter evaluator uses a direct application ABI" - ) - for name, child in value.items(): - _assert_model_parameter_not_direct( - child, - context=f"{context}.{name}", - ) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - _assert_model_parameter_not_direct( - child, - context=f"{context}[{index}]", - ) - - -def _assert_eager_model_parameter_not_direct( - value: object, - *, - context: str, -) -> None: - """Reject every eager DirectTable representation recursively.""" - - if isinstance(value, Mapping): - if "direct_table" in value: - raise FinalAuditError( - f"{context} model-parameter evaluator carries DirectTable metadata" - ) - direct_markers = { - _EAGER_DIRECT_CAPABILITY, - _EAGER_DIRECT_DESCRIPTOR_ABI, - _EAGER_DIRECT_BINDING_ABI, - _EAGER_NATIVE_APPLICATION_ABI, - } - for name, child in value.items(): - if isinstance(child, str) and child in direct_markers: - raise FinalAuditError( - f"{context}.{name} model-parameter evaluator uses eager " - "Direct-Arena metadata" - ) - _assert_eager_model_parameter_not_direct( - child, - context=f"{context}.{name}", - ) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for index, child in enumerate(value): - _assert_eager_model_parameter_not_direct( - child, - context=f"{context}[{index}]", - ) - - -def _audit_eager_execution( - artifact: Path, - manifest: object, - execution: Mapping[str, object], - cell: CellSpec, -) -> int: - if execution.get("kind") != "pyamplicol-runtime-eager-execution": - raise FinalAuditError("eager execution manifest kind is invalid") - plan = _mapping(execution.get("plan"), "eager execution.plan") - expected = { - "eager_plan_abi": "pyamplicol-eager-plan-v3", - "lowering_input_abi": "pyamplicol-eager-lowering-input-v1", - "runtime_layout_abi": "pyamplicol-eager-runtime-layout-v1", - } - for field, value in expected.items(): - if plan.get(field) != value: - raise FinalAuditError(f"eager execution.plan.{field} is incompatible") - if execution.get("eager_plan_abi") != expected["eager_plan_abi"]: - raise FinalAuditError("eager execution eager_plan_abi is incompatible") - extensions = _mapping(manifest.extensions, "artifact.extensions") - prepared = _mapping( - extensions.get("eager_prepared_pack"), - "artifact.extensions.eager_prepared_pack", - ) - if ( - prepared.get("kind") != "pyamplicol-prepared-kernel-pack-identity" - or prepared.get("schema_version") != 1 - or prepared.get("backend") != cell.measurement.backend - or prepared.get("eager_kernel_abi") != "pyamplicol-eager-kernel-v1" - or not isinstance(prepared.get("identity_sha256"), str) - or _SHA256_RE.fullmatch(str(prepared.get("identity_sha256"))) is None - ): - raise FinalAuditError("eager prepared-pack identity is incompatible") - kernel_pack = _mapping(execution.get("kernel_pack"), "eager kernel_pack") - raw_pack = kernel_pack.get("manifest_path") - pack, _pack_path, _pack_sha256 = _authenticated_json_payload( - artifact, - manifest, - raw_pack, - process_id=None, - context="eager kernel pack", - ) - kernels = _sequence(pack.get("kernels"), "eager kernel pack.kernels") - prepared_kernel_count = prepared.get("kernel_count") - if ( - isinstance(prepared_kernel_count, bool) - or not isinstance(prepared_kernel_count, int) - or prepared_kernel_count < len(kernels) - or not kernels - ): - raise FinalAuditError("eager prepared-pack kernel inventory is invalid") - direct_count = 0 - expected_source = _expected_evaluator_abis(cell)[1] - for index, raw_kernel in enumerate(kernels): - kernel = _mapping(raw_kernel, f"eager kernel[{index}]") - evaluator = _mapping( - kernel.get("f64_evaluator_manifest"), - f"eager kernel[{index}].f64_evaluator_manifest", - ) - direct = evaluator.get("direct_table") - if kernel.get("contract_kind") == "model-parameter": - _assert_eager_model_parameter_not_direct( - kernel, - context=f"eager kernel[{index}]", - ) - continue - source_leaf_count = _audit_source_evaluator( - evaluator, - cell, - context=f"eager kernel[{index}].f64_evaluator_manifest", - ) - if source_leaf_count != 1: - raise FinalAuditError( - f"eager kernel[{index}] has a non-canonical source leaf count" - ) - table = _mapping(direct, f"eager kernel[{index}].direct_table") - expected = { - "capability": _EAGER_DIRECT_CAPABILITY, - "descriptor_abi": _EAGER_DIRECT_DESCRIPTOR_ABI, - "binding_abi": _EAGER_DIRECT_BINDING_ABI, - "source_application_abi": expected_source, - } - mismatches = [ - field for field, value in expected.items() if table.get(field) != value - ] - if ( - cell.measurement.backend == "jit" - and evaluator.get("optimization_level") - != cell.measurement.jit_optimization_level - ): - mismatches.append("optimization_level") - if mismatches: - raise FinalAuditError( - f"eager kernel[{index}] DirectTable identity differs: " - + ", ".join(mismatches) - ) - direct_count += 1 - if direct_count == 0: - raise FinalAuditError("eager artifact contains no direct-Arena kernels") - return direct_count - - -def _audit_recurrence_source_pack( - artifact: Path, - manifest: object, - execution: Mapping[str, object], - cell: CellSpec, - *, - execution_manifest_path: str, - execution_manifest_sha256: str, -) -> Mapping[str, object]: - if ( - cell.measurement.backend != "jit" - or cell.measurement.jit_optimization_level != 2 - ): - raise FinalAuditError( - "recurrence report cells require an authenticated JIT O2 source pack" - ) - kernel_pack = _mapping(execution.get("kernel_pack"), "recurrence kernel_pack") - pack, pack_path, pack_sha256 = _authenticated_json_payload( - artifact, - manifest, - kernel_pack.get("manifest_path"), - process_id=None, - context="recurrence prepared kernel pack", - ) - optimization = _mapping( - pack.get("optimization_settings"), - "recurrence prepared kernel pack.optimization_settings", - ) - plan = _mapping(execution.get("plan"), "recurrence execution.plan") - expected_execution_abis = { - "direct_template_abi": _RECURRENCE_DIRECT_TEMPLATE_ABI, - "direct_backend_abi": _RECURRENCE_DIRECT_BACKEND_ABI, - } - for field, expected in expected_execution_abis.items(): - if execution.get(field) != expected or plan.get(field) != expected: - raise FinalAuditError(f"recurrence execution/plan {field} is incompatible") - prepared_kernel_pack_digest = _require_sha256( - execution.get("prepared_kernel_pack_digest"), - "recurrence execution.prepared_kernel_pack_digest", - ) - direct_template_catalog_digest = _require_sha256( - execution.get("direct_template_catalog_digest"), - "recurrence execution.direct_template_catalog_digest", - ) - if ( - plan.get("prepared_kernel_pack_digest") != prepared_kernel_pack_digest - or plan.get("direct_template_catalog_digest") != direct_template_catalog_digest - ): - raise FinalAuditError("recurrence execution/plan source digests differ") - kernel_payload_root = _canonical_relative_path( - kernel_pack.get("payload_root"), - "recurrence kernel payload root", - ).as_posix() - mismatches = [] - if pack.get("backend") != "jit": - mismatches.append("backend") - if optimization.get("backend") != "jit": - mismatches.append("optimization_settings.backend") - if optimization.get("jit_optimization_level") != 2: - mismatches.append("optimization_settings.jit_optimization_level") - direct_catalog = _mapping( - pack.get("recurrence_direct_template"), - "recurrence prepared kernel pack.recurrence_direct_template", - ) - templates = _sequence( - direct_catalog.get("templates"), - "recurrence prepared kernel pack.recurrence_direct_template.templates", - ) - expected_direct = { - "abi": _RECURRENCE_DIRECT_TEMPLATE_ABI, - "backend": "jit", - "backend_abi": _RECURRENCE_DIRECT_BACKEND_ABI, - "canonicalization_abi": _RECURRENCE_DIRECT_CANONICALIZATION_ABI, - "optimization_level": 2, - "portable": True, - } - mismatches.extend( - f"recurrence_direct_template.{field}" - for field, expected in expected_direct.items() - if direct_catalog.get(field) != expected - ) - if not templates: - mismatches.append("recurrence_direct_template.templates") - if ( - direct_catalog.get("prepared_kernel_pack_digest") != prepared_kernel_pack_digest - or direct_catalog.get("catalog_digest") != direct_template_catalog_digest - ): - mismatches.append("recurrence_direct_template.execution_digest_links") - if _digest_mapping_without(direct_catalog, "catalog_digest") != ( - direct_template_catalog_digest - ): - mismatches.append("recurrence_direct_template.catalog_digest") - if mismatches: - raise FinalAuditError( - "recurrence prepared kernel pack does not prove JIT O2: " - + ", ".join(mismatches) - ) - - evaluator_members = _authenticated_evaluator_container_members( - artifact, - manifest, - ) - authenticated_source_payloads: dict[str, str] = {} - - def authenticate_source_payload(relative: str, *, context: str) -> str: - cached = authenticated_source_payloads.get(relative) - if cached is not None: - return cached - result = _authenticated_recurrence_source_payload( - artifact, - manifest, - evaluator_members, - relative, - context=context, - ) - authenticated_source_payloads[relative] = result - return result - - kernels = _sequence( - pack.get("kernels"), - "recurrence prepared kernel pack.kernels", - ) - variants = _sequence( - pack.get("kernel_variants"), - "recurrence prepared kernel pack.kernel_variants", - ) - if not kernels: - raise FinalAuditError("recurrence prepared kernel pack has no source kernels") - source_leaves_by_kernel: dict[int, set[tuple[str, str]]] = {} - source_evaluator_leaf_count = 0 - for index, raw_kernel in enumerate(kernels): - kernel = _mapping( - raw_kernel, - f"recurrence prepared kernel pack.kernels[{index}]", - ) - kernel_id = kernel.get("kernel_id") - if ( - isinstance(kernel_id, bool) - or not isinstance(kernel_id, int) - or kernel_id < 0 - or kernel_id in source_leaves_by_kernel - ): - raise FinalAuditError( - f"recurrence prepared kernel pack.kernels[{index}] " - "has an invalid kernel ID" - ) - leaves = _audit_recurrence_source_evaluator_leaves( - kernel.get("f64_evaluator_manifest"), - payload_root=kernel_payload_root, - authenticate_payload=authenticate_source_payload, - context=( - f"recurrence prepared kernel pack.kernels[{index}]" - ".f64_evaluator_manifest" - ), - ) - source_evaluator_leaf_count += len(leaves) - source_leaves_by_kernel[kernel_id] = set(leaves) - for index, raw_variant in enumerate(variants): - variant = _mapping( - raw_variant, - f"recurrence prepared kernel pack.kernel_variants[{index}]", - ) - source_evaluator_leaf_count += len( - _audit_recurrence_source_evaluator_leaves( - variant.get("f64_evaluator_manifest"), - payload_root=kernel_payload_root, - authenticate_payload=authenticate_source_payload, - context=( - "recurrence prepared kernel pack." - f"kernel_variants[{index}].f64_evaluator_manifest" - ), - ) - ) - - prepared_direct_template_count = 0 - for index, raw_template in enumerate(templates): - template = _mapping( - raw_template, - f"recurrence prepared kernel pack.direct_template[{index}]", - ) - if ( - template.get("abi") != _RECURRENCE_DIRECT_TEMPLATE_ABI - or template.get("backend") != "jit" - or template.get("portable") is not True - or template.get("optimization_level") != 2 - ): - raise FinalAuditError( - f"recurrence direct template[{index}] contract is incompatible" - ) - if _digest_mapping_without(template, "semantic_digest") != ( - template.get("semantic_digest") - ): - raise FinalAuditError( - f"recurrence direct template[{index}] semantic digest is invalid" - ) - binding = _mapping( - template.get("payload_binding"), - f"recurrence direct template[{index}].payload_binding", - ) - if ( - binding.get("abi") != _RECURRENCE_DIRECT_PAYLOAD_BINDING_ABI - or _recurrence_payload_binding_digest(binding) - != binding.get("payload_digest") - ): - raise FinalAuditError( - f"recurrence direct template[{index}] payload-binding " - "contract is invalid" - ) - binding_kind = binding.get("kind") - if binding_kind == "rusticol-intrinsic": - if ( - binding.get("source_application_abi") is not None - or binding.get("direct_application_abi") is not None - or binding.get("source_application_path") is not None - or binding.get("source_application_sha256") is not None - or binding.get("payload_paths") != [] - or not isinstance(binding.get("runtime_template"), str) - or not binding.get("runtime_template") - ): - raise FinalAuditError( - f"recurrence direct template[{index}] intrinsic source " - "contract is invalid" - ) - continue - if binding_kind != "prepared-direct-call": - raise FinalAuditError( - f"recurrence direct template[{index}] is not executable" - ) - prepared_direct_template_count += 1 - source_path = _canonical_relative_path( - binding.get("source_application_path"), - f"recurrence direct template[{index}] source application", - ).as_posix() - source_sha256 = _require_sha256( - binding.get("source_application_sha256"), - f"recurrence direct template[{index}] source application digest", - ) - prepared_kernel_id = binding.get("prepared_kernel_id") - if ( - binding.get("source_application_abi") != _SYMJIT_PLANE_APPLICATION_ABI - or binding.get("direct_application_abi") - != _RECURRENCE_JIT_DIRECT_APPLICATION_ABI - or binding.get("payload_paths") != [source_path] - or isinstance(prepared_kernel_id, bool) - or not isinstance(prepared_kernel_id, int) - or prepared_kernel_id < 0 - or (source_path, source_sha256) - not in source_leaves_by_kernel.get(prepared_kernel_id, set()) - ): - raise FinalAuditError( - f"recurrence direct template[{index}] source application " - "is not bound to its prepared kernel" - ) - if prepared_direct_template_count == 0 or source_evaluator_leaf_count == 0: - raise FinalAuditError( - "recurrence direct-template pack has no source application evidence" - ) - return { - "kind": "authenticated-recurrence-direct-template-source-v1", - "optimization_level": 2, - "direct_template_count": len(templates), - "prepared_direct_template_count": prepared_direct_template_count, - "source_evaluator_leaf_count": source_evaluator_leaf_count, - "source_application_abi": _SYMJIT_PLANE_APPLICATION_ABI, - "direct_application_abi": _RECURRENCE_JIT_DIRECT_APPLICATION_ABI, - "prepared_kernel_pack_digest": prepared_kernel_pack_digest, - "direct_template_catalog_digest": direct_template_catalog_digest, - "execution_manifest_path": execution_manifest_path, - "execution_manifest_sha256": execution_manifest_sha256, - "kernel_pack_path": pack_path, - "kernel_pack_sha256": pack_sha256, - } - - -def _require_sha256(value: object, context: str) -> str: - if not isinstance(value, str) or _SHA256_RE.fullmatch(value) is None: - raise FinalAuditError(f"{context} must be a lowercase SHA-256") - return value - - -def _digest_mapping_without(value: Mapping[str, object], field: str) -> str: - payload = dict(value) - payload.pop(field, None) - return digest_json(payload) - - -def _recurrence_payload_binding_digest(binding: Mapping[str, object]) -> str: - if binding.get("kind") != "rusticol-intrinsic": - return _digest_mapping_without(binding, "payload_digest") - if binding.get("role") == "contribution": - fields = ( - "abi", - "destination_operation", - "contribution_parent_permutation", - "intrinsic_contract_digest", - "kind", - "role", - "runtime_template", - "scalar_input_count", - "scalar_projections", - ) - return digest_json({field: binding.get(field) for field in fields}) - # Source/finalization intrinsic digests include semantic-catalog fields - # which are not duplicated in the payload binding. The opaque digest is - # nevertheless bound by the recomputed template and catalog identities. - return _require_sha256( - binding.get("payload_digest"), - "recurrence intrinsic payload digest", - ) - - -def _authenticated_evaluator_container_members( - artifact: Path, - manifest: object, -) -> Mapping[str, tuple[int, str]]: - extensions = _mapping( - getattr(manifest, "extensions", None), - "artifact.extensions", - ) - raw_container = extensions.get("evaluator_payload_container") - if raw_container is None: - return {} - container = _mapping( - raw_container, - "artifact.extensions.evaluator_payload_container", - ) - required = { - "kind", - "schema_version", - "storage_abi", - "path", - "member_count", - "unpacked_size_bytes", - "index_sha256", - } - if ( - set(container) != required - or container.get("kind") != "pyamplicol-evaluator-payload-container" - or container.get("schema_version") != 1 - or container.get("storage_abi") != "pacbin-v1" - ): - raise FinalAuditError("artifact evaluator payload container contract drifted") - member_count = container.get("member_count") - unpacked_size = container.get("unpacked_size_bytes") - index_sha256 = _require_sha256( - container.get("index_sha256"), - "artifact evaluator payload container index digest", - ) - if ( - isinstance(member_count, bool) - or not isinstance(member_count, int) - or member_count < 0 - or isinstance(unpacked_size, bool) - or not isinstance(unpacked_size, int) - or unpacked_size < 0 - ): - raise FinalAuditError( - "artifact evaluator payload container inventory is invalid" - ) - data, _canonical, _sha256 = _authenticated_payload_bytes( - artifact, - manifest, - container.get("path"), - role="evaluator-state", - media_type="application/octet-stream", - process_id=None, - context="evaluator payload container", - ) - try: - from pyamplicol.generation.evaluator_container import PacbinReader - - with PacbinReader.open(io.BytesIO(data), verify_payloads=True) as reader: - index = reader.index - members = tuple(reader.members) - except (OSError, TypeError, ValueError) as error: - raise FinalAuditError( - "authenticated evaluator payload container is invalid" - ) from error - if ( - len(members) != member_count - or sum(member.length for member in members) != unpacked_size - or index.index_sha256 != index_sha256 - ): - raise FinalAuditError( - "authenticated evaluator payload container index metadata drifted" - ) - return { - member.logical_path: (int(member.kind), member.sha256) for member in members - } - - -def _authenticated_recurrence_source_payload( - artifact: Path, - manifest: object, - evaluator_members: Mapping[str, tuple[int, str]], - relative: str, - *, - context: str, -) -> str: - canonical = _canonical_relative_path(relative, context).as_posix() - payloads = getattr(manifest, "payloads", None) - if not isinstance(payloads, Sequence): - raise FinalAuditError(f"{context} has no artifact payload inventory") - loose = [ - payload for payload in payloads if getattr(payload, "path", None) == canonical - ] - packed = evaluator_members.get(canonical) - if len(loose) + (packed is not None) != 1: - raise FinalAuditError(f"{context} payload is missing or ambiguous") - if loose: - _data, _canonical, sha256 = _authenticated_payload_bytes( - artifact, - manifest, - canonical, - role="evaluator-state", - media_type="application/octet-stream", - process_id=None, - context=context, - ) - return sha256 - assert packed is not None - kind, sha256 = packed - if kind != 1: - raise FinalAuditError(f"{context} is not a packed SymJIT application") - return _require_sha256(sha256, f"{context} packed member digest") - - -def _audit_recurrence_source_evaluator_leaves( - value: object, - *, - payload_root: str, - authenticate_payload: Callable[..., str], - context: str, -) -> list[tuple[str, str]]: - plane_leaves = _audit_symjit_plane_evaluator_leaves( - value, - optimization_level=2, - context=context, - ) - result: list[tuple[str, str]] = [] - for application_path, _source_digest in plane_leaves: - payload_path = ( - PurePosixPath(payload_root) / PurePosixPath(application_path) - ).as_posix() - sha256 = authenticate_payload( - payload_path, - context=f"{context}.plane_application", - ) - result.append((application_path, sha256)) - return result - - -def _audit_recurrence_execution( - execution: Mapping[str, object], - cell: CellSpec, -) -> int: - if execution.get("kind") != "pyamplicol-runtime-recurrence-execution": - raise FinalAuditError("recurrence execution manifest kind is invalid") - expected = { - "builder_input_abi": "pyamplicol-recurrence-builder-input-v2", - "recurrence_plan_abi": "pyamplicol-recurrence-plan-v2", - "runtime_layout_abi": "pyamplicol-recurrence-runtime-layout-v2", - "direct_template_abi": "pyamplicol-recurrence-direct-template-v1", - "direct_backend_abi": "rusticol.recurrence-direct-backend.v1", - } - mismatches = [ - field for field, value in expected.items() if execution.get(field) != value - ] - plan = _mapping(execution.get("plan"), "recurrence execution.plan") - mismatches.extend( - f"plan.{field}" for field, value in expected.items() if plan.get(field) != value - ) - summary = _mapping( - plan.get("inspection_summary"), - "recurrence execution.plan.inspection_summary", - ) - arena = _mapping( - summary.get("direct_arena"), - "recurrence execution.plan.inspection_summary.direct_arena", - ) - for field in ("packed_input_bytes", "packed_output_bytes", "scatter_bytes"): - if arena.get(field) != 0: - mismatches.append(f"direct_arena.{field}") - capabilities = set( - str(value) - for value in _sequence( - execution.get("required_runtime_capabilities"), - "recurrence capabilities", - ) - ) - expected_color = ( - "rusticol.recurrence-color.lc.v1" - if cell.measurement.accuracy is Accuracy.LC - else "rusticol.recurrence-color.contracted.v1" - ) - if capabilities != { - _ARENA_CAPABILITY[ExecutionMode.RECURRENCE], - expected_color, - }: - mismatches.append("required_runtime_capabilities") - if mismatches: - raise FinalAuditError( - "recurrence direct-Arena identity differs: " - + ", ".join(sorted(set(mismatches))) - ) - row_groups = arena.get("row_group_count") - if ( - isinstance(row_groups, bool) - or not isinstance(row_groups, int) - or row_groups < 1 - ): - raise FinalAuditError("recurrence direct Arena has no row groups") - return row_groups - - -def _native_on_the_fly_process_seed_identity(payload: bytes) -> Mapping[str, object]: - """Decode one process seed with the production Rust authority.""" - - try: - module = importlib.import_module("pyamplicol._rusticol") - binding = getattr(module, "_inspect_on_the_fly_process_seed_v1", None) - if not callable(binding): - raise TypeError("native seed inspector is unavailable") - encoded = binding(payload) - if not isinstance(encoded, str): - raise TypeError("native seed inspector did not return JSON text") - decoded = json.loads(encoded) - except Exception as error: - raise FinalAuditError( - "on-the-fly compact seed cannot be decoded by the native authority" - ) from error - return _mapping(decoded, "native on-the-fly process-seed identity") - - -def _audit_on_the_fly_process_seed_identity( - identity: Mapping[str, object], - runtime_metadata: Mapping[str, object], - pack: Mapping[str, object], -) -> None: - """Bind decoded source identity to compact execution and prepared catalogs.""" - - if ( - set(identity) != _ON_THE_FLY_PROCESS_SEED_IDENTITY_FIELDS - or identity.get("abi") != _ON_THE_FLY_PROCESS_SEED_IDENTITY_ABI - ): - raise FinalAuditError("on-the-fly process-seed identity contract differs") - for field in ( - "process_digest", - "compiled_model_digest", - "recurrence_template_catalog_digest", - "prepared_kernel_pack_digest", - "recurrence_direct_template_catalog_digest", - "semantic_digest", - ): - if _SHA256_RE.fullmatch(str(identity.get(field))) is None: - raise FinalAuditError( - f"on-the-fly process-seed identity {field} is invalid" - ) - - template = _mapping( - pack.get("recurrence_template"), - "on-the-fly prepared recurrence template", - ) - header = _mapping( - template.get("header"), - "on-the-fly prepared recurrence template header", - ) - direct = _mapping( - pack.get("recurrence_direct_template"), - "on-the-fly prepared direct-template catalog", - ) - expected_catalog_identities = { - "compiled_model_digest": header.get("compiled_model_digest"), - "recurrence_template_catalog_digest": header.get("catalog_digest"), - "prepared_kernel_pack_digest": header.get("prepared_kernel_pack_digest"), - "recurrence_direct_template_catalog_digest": direct.get("catalog_digest"), - } - if any( - identity.get(field) != expected - for field, expected in expected_catalog_identities.items() - ) or ( - direct.get("compiled_model_digest") != header.get("compiled_model_digest") - or direct.get("recurrence_template_catalog_digest") - != header.get("catalog_digest") - or direct.get("prepared_kernel_pack_digest") - != header.get("prepared_kernel_pack_digest") - ): - raise FinalAuditError( - "on-the-fly process seed disagrees with its prepared catalogs" - ) - - external_legs = _sequence( - runtime_metadata.get("external_legs"), - "on-the-fly runtime metadata external_legs", - ) - parameter_projection = _sequence( - runtime_metadata.get("parameter_projection"), - "on-the-fly runtime metadata parameter_projection", - ) - permutation = _sequence( - identity.get("external_permutation"), - "on-the-fly process-seed external_permutation", - ) - sources = _sequence( - identity.get("external_sources"), - "on-the-fly process-seed external_sources", - ) - if ( - len(permutation) != len(external_legs) - or len(sources) != len(external_legs) - or any( - isinstance(slot, bool) or not isinstance(slot, int) for slot in permutation - ) - or sorted(permutation) != list(range(len(permutation))) - ): - raise FinalAuditError( - "on-the-fly process-seed external domain is not canonical" - ) - mass_slots: dict[str, int | None] = {} - for index, raw_projection in enumerate(parameter_projection): - projection = _mapping( - raw_projection, - f"on-the-fly parameter_projection[{index}]", - ) - runtime_name = projection.get("runtime_name") - component = projection.get("component") - prepared_id = projection.get("prepared_parameter_id") - if ( - isinstance(runtime_name, str) - and runtime_name.startswith("particle.") - and runtime_name.endswith(".mass") - and component == 0 - and ( - prepared_id is None - or (not isinstance(prepared_id, bool) and isinstance(prepared_id, int)) - ) - ): - mass_slots[runtime_name] = prepared_id - for source_slot, (raw_source, raw_leg) in enumerate( - zip(sources, external_legs, strict=True) - ): - source = _mapping( - raw_source, - f"on-the-fly process-seed external_sources[{source_slot}]", - ) - leg = _mapping( - raw_leg, - f"on-the-fly runtime metadata external_legs[{source_slot}]", - ) - if set(source) != {"source_slot", "public_label", "is_initial", "states"}: - raise FinalAuditError("on-the-fly process-seed source contract differs") - outgoing_pdg = leg.get("outgoing_pdg") - if isinstance(outgoing_pdg, bool) or not isinstance(outgoing_pdg, int): - raise FinalAuditError("on-the-fly external source PDG is invalid") - expected_mass_slot = mass_slots.get(f"particle.{abs(outgoing_pdg)}.mass") - states = _sequence( - source.get("states"), - f"on-the-fly process-seed external_sources[{source_slot}].states", - ) - if ( - source.get("source_slot") != source_slot - or source.get("public_label") != leg.get("public_label") - or source.get("is_initial") != leg.get("is_initial") - or not states - ): - raise FinalAuditError( - "on-the-fly process-seed source identity disagrees with " - "runtime metadata" - ) - previous_state_index = -1 - for raw_state in states: - state = _mapping(raw_state, "on-the-fly process-seed source state") - state_index = state.get("state_index") - if ( - set(state) - != { - "state_index", - "public_helicity", - "prepared_mass_parameter_slot", - } - or isinstance(state_index, bool) - or not isinstance(state_index, int) - or state_index <= previous_state_index - or isinstance(state.get("public_helicity"), bool) - or not isinstance(state.get("public_helicity"), int) - or state.get("prepared_mass_parameter_slot") != expected_mass_slot - ): - raise FinalAuditError( - "on-the-fly process-seed source state or mass slot differs" - ) - previous_state_index = state_index - - -def _audit_on_the_fly_color_contraction( - artifact: Path, - manifest: object, - runtime_metadata: Mapping[str, object], - cell: CellSpec, - *, - process_id: str, - execution_manifest_path: str, -) -> None: - """Authenticate the loose contracted-colour payload without dense axes.""" - - raw = runtime_metadata.get("color_contraction") - if cell.measurement.accuracy is Accuracy.LC: - if raw is not None or "color_contraction" in runtime_metadata: - raise FinalAuditError( - "LC on-the-fly execution unexpectedly carries color contraction" - ) - return - reference = _mapping(raw, "on-the-fly color contraction") - expected_fields = { - "abi", - "color_accuracy", - "storage", - "includes_color_factor", - "group_count", - "sector_count", - "active_sector_count", - "component_count", - "destination_count", - "entry_count", - "logical_entry_count", - "semantic_digest", - "factorization", - "path", - "size_bytes", - "sha256", - } - counters: dict[str, int] = {} - for field in ( - "group_count", - "sector_count", - "active_sector_count", - "component_count", - "destination_count", - "entry_count", - "logical_entry_count", - "size_bytes", - ): - value = reference.get(field) - if isinstance(value, bool) or not isinstance(value, int) or value < 1: - raise FinalAuditError( - f"on-the-fly color contraction {field} must be positive" - ) - counters[field] = value - payload_sha256 = reference.get("sha256") - if ( - set(reference) != expected_fields - or reference.get("abi") != _ON_THE_FLY_COLOR_CONTRACTION_ABI - or reference.get("color_accuracy") != cell.measurement.accuracy.value - or reference.get("storage") != "expanded" - or reference.get("includes_color_factor") is not True - or reference.get("factorization") is not None - or counters["component_count"] != 1 - or counters["active_sector_count"] != counters["group_count"] - or counters["destination_count"] != counters["group_count"] - or counters["group_count"] > counters["sector_count"] - or counters["logical_entry_count"] != counters["entry_count"] - or reference.get("path") != "on-the-fly-color.bin" - or not isinstance(payload_sha256, str) - or _SHA256_RE.fullmatch(payload_sha256) is None - or reference.get("semantic_digest") != payload_sha256 - ): - raise FinalAuditError( - "on-the-fly contracted color payload reference is noncanonical" - ) - execution_parent = PurePosixPath(execution_manifest_path).parent - relative = ( - execution_parent - / _canonical_relative_path( - reference["path"], - "on-the-fly color contraction", - ) - ).as_posix() - data, _payload_path, authenticated_sha256 = _authenticated_payload_bytes( - artifact, - manifest, - relative, - role="evaluator-state", - media_type="application/octet-stream", - process_id=process_id, - context="on-the-fly color contraction", - ) - if authenticated_sha256 != payload_sha256 or len(data) != counters["size_bytes"]: - raise FinalAuditError( - "on-the-fly contracted color payload differs from its reference" - ) - - -def _audit_on_the_fly_execution( - artifact: Path, - manifest: object, - execution: Mapping[str, object], - cell: CellSpec, - *, - process_id: str, - execution_manifest_path: str, - effective_config: Mapping[str, object] | None = None, -) -> int: - """Authenticate the compact OTF seed and its prepared JIT source pack.""" - - expected_fields = { - "schema_version", - "kind", - "required_runtime_capabilities", - "process", - "key", - "color_accuracy", - "external_pdg_order", - "kernel_pack", - "runtime_options", - "selector_policy", - "runtime_metadata", - "runtime_container", - } - capabilities = tuple( - str(value) - for value in _sequence( - execution.get("required_runtime_capabilities"), - "on-the-fly execution capabilities", - ) - ) - expected_color_capability = ( - _ON_THE_FLY_LC_COLOR_CAPABILITY - if cell.measurement.accuracy is Accuracy.LC - else _ON_THE_FLY_CONTRACTED_COLOR_CAPABILITY - ) - if ( - set(execution) != expected_fields - or execution.get("schema_version") != 3 - or execution.get("kind") != _ON_THE_FLY_EXECUTION_KIND - or execution.get("process") != cell.process - or execution.get("key") != process_id - or execution.get("color_accuracy") != cell.measurement.accuracy.value - or len(capabilities) != 2 - or set(capabilities) - != { - _ARENA_CAPABILITY[ExecutionMode.ON_THE_FLY], - expected_color_capability, - } - or ( - cell.measurement.accuracy is Accuracy.LC - and cell.workload not in {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - ) - or ( - cell.measurement.accuracy in {Accuracy.NLC, Accuracy.FULL} - and cell.workload is not Workload.CONTRACTED - ) - or cell.measurement.backend != "jit" - or cell.measurement.jit_optimization_level != 2 - ): - raise FinalAuditError("on-the-fly execution compact contract differs") - external_pdgs = _sequence( - execution.get("external_pdg_order"), - "on-the-fly execution external_pdg_order", - ) - if len(external_pdgs) != cell.n_final + 2 or any( - isinstance(value, bool) or not isinstance(value, int) for value in external_pdgs - ): - raise FinalAuditError("on-the-fly execution external PDG order is invalid") - runtime_options = _mapping( - execution.get("runtime_options"), - "on-the-fly execution runtime_options", - ) - point_tile_size = runtime_options.get("point_tile_size") - query_construction_threads = runtime_options.get("query_construction_threads") - contracted_color = cell.measurement.accuracy in {Accuracy.NLC, Accuracy.FULL} - expected_color_coverage = "contracted" if contracted_color else "complete" - if ( - set(runtime_options) != {"point_tile_size", "query_construction_threads"} - or isinstance(point_tile_size, bool) - or not isinstance(point_tile_size, int) - or point_tile_size < 1 - or isinstance(query_construction_threads, bool) - or not isinstance(query_construction_threads, int) - or query_construction_threads < 1 - ): - raise FinalAuditError("on-the-fly execution runtime options are invalid") - if effective_config is not None: - evaluator = _mapping( - effective_config.get("evaluator"), - "on-the-fly authenticated effective evaluator configuration", - ) - optimization = _mapping( - evaluator.get("optimization"), - "on-the-fly authenticated effective evaluator optimization", - ) - effective_cores = optimization.get("cores") - if ( - isinstance(effective_cores, bool) - or not isinstance(effective_cores, int) - or effective_cores < 1 - or query_construction_threads != effective_cores - ): - raise FinalAuditError( - "on-the-fly query construction threads differ from the " - "authenticated effective evaluator cores" - ) - selector_policy = _mapping( - execution.get("selector_policy"), - "on-the-fly selector_policy", - ) - if ( - set(selector_policy) - != { - "color_coverage", - "reference_color_word", - "trace_reflections_folded", - "selector_census", - } - or selector_policy.get("color_coverage") != expected_color_coverage - or not isinstance(selector_policy.get("trace_reflections_folded"), bool) - or ( - contracted_color - and selector_policy.get("trace_reflections_folded") is not False - ) - ): - raise FinalAuditError("on-the-fly selector policy differs") - reference_color_word = selector_policy.get("reference_color_word") - if contracted_color and reference_color_word is not None: - raise FinalAuditError( - "contracted on-the-fly selector policy has a flow selector" - ) - if reference_color_word is not None: - reference = _sequence( - reference_color_word, - "on-the-fly selector policy reference_color_word", - ) - if ( - not reference - or any( - isinstance(label, bool) or not isinstance(label, int) or label < 1 - for label in reference - ) - or len(set(reference)) != len(reference) - ): - raise FinalAuditError("on-the-fly selector reference word is invalid") - selector_census = _mapping( - selector_policy.get("selector_census"), - "on-the-fly selector census", - ) - if set(selector_census) != { - "physical_helicity_count", - "physical_color_flow_count", - }: - raise FinalAuditError("on-the-fly selector census fields differ") - for field in ("physical_helicity_count", "physical_color_flow_count"): - count = selector_census.get(field) - if ( - isinstance(count, bool) - or not isinstance(count, int) - or count < 1 - or count > (1 << 64) - 1 - ): - raise FinalAuditError( - f"on-the-fly selector census {field} is outside positive u64" - ) - if contracted_color and selector_census["physical_color_flow_count"] != 1: - raise FinalAuditError( - "contracted on-the-fly selector census must expose one color result" - ) - runtime_metadata = _mapping( - execution.get("runtime_metadata"), - "on-the-fly runtime_metadata", - ) - _audit_on_the_fly_color_contraction( - artifact, - manifest, - runtime_metadata, - cell, - process_id=process_id, - execution_manifest_path=execution_manifest_path, - ) - - kernel_pack = _mapping( - execution.get("kernel_pack"), - "on-the-fly execution kernel_pack", - ) - if kernel_pack != { - "manifest_path": "model/eager-kernel-pack.json", - "payload_root": "model/eager-kernels", - }: - raise FinalAuditError("on-the-fly prepared-kernel paths are not canonical") - pack, _pack_path, _pack_sha256 = _authenticated_json_payload( - artifact, - manifest, - kernel_pack["manifest_path"], - process_id=None, - context="on-the-fly prepared kernel pack", - ) - dependencies = _mapping( - pack.get("dependency_abis"), - "on-the-fly prepared kernel pack dependency_abis", - ) - optimization = _mapping( - pack.get("optimization_settings"), - "on-the-fly prepared kernel pack optimization_settings", - ) - if ( - pack.get("backend") != "jit" - or pack.get("eager_kernel_abi") != "pyamplicol-eager-kernel-v1" - or dependencies.get("symjit_application") != _SYMJIT_APPLICATION_ABI - or dependencies.get("symjit_plane_application") != _SYMJIT_PLANE_APPLICATION_ABI - or optimization.get("backend") != "jit" - or optimization.get("jit_optimization_level") != 2 - ): - raise FinalAuditError("on-the-fly prepared kernel pack does not prove JIT O2") - kernels = _sequence(pack.get("kernels"), "on-the-fly prepared kernels") - variants = _sequence( - pack.get("kernel_variants"), - "on-the-fly prepared kernel variants", - ) - source_leaf_count = 0 - for label, records in (("kernels", kernels), ("kernel_variants", variants)): - for index, raw_record in enumerate(records): - record = _mapping(raw_record, f"on-the-fly {label}[{index}]") - if record.get("contract_kind") == "model-parameter": - continue - source_leaf_count += _audit_source_evaluator( - record.get("f64_evaluator_manifest"), - cell, - context=f"on-the-fly {label}[{index}].f64_evaluator_manifest", - ) - extensions = _mapping(getattr(manifest, "extensions", None), "artifact.extensions") - prepared = _mapping( - extensions.get("eager_prepared_pack"), - "artifact.extensions.eager_prepared_pack", - ) - expected_prepared = _expected_eager_prepared_pack_identity(cell) - if ( - not kernels - or source_leaf_count < 1 - or set(prepared) != set(expected_prepared) - or any( - prepared.get(field) != value for field, value in expected_prepared.items() - ) - or prepared.get("kernel_count") != len(kernels) - ): - raise FinalAuditError("on-the-fly prepared-pack identity is incompatible") - - container = _mapping( - execution.get("runtime_container"), - "on-the-fly runtime container", - ) - if container != { - "kind": _ON_THE_FLY_RUNTIME_CONTAINER_KIND, - "schema_version": 1, - "storage_abi": _ON_THE_FLY_RUNTIME_STORAGE_ABI, - "path": "on-the-fly-runtime.pacbin", - "seed_member_path": _ON_THE_FLY_SEED_MEMBER_PATH, - }: - raise FinalAuditError("on-the-fly runtime container contract differs") - execution_parent = PurePosixPath(execution_manifest_path).parent - runtime_relative = ( - execution_parent - / _canonical_relative_path( - container["path"], - "on-the-fly runtime container", - ) - ).as_posix() - data, _runtime_path, _runtime_sha256 = _authenticated_payload_bytes( - artifact, - manifest, - runtime_relative, - role="evaluator-state", - media_type="application/octet-stream", - process_id=process_id, - context="on-the-fly runtime container", - ) - try: - from pyamplicol.generation.evaluator_container import ( - PacbinMemberKind, - PacbinReader, - ) - - with PacbinReader.open(io.BytesIO(data), verify_payloads=True) as reader: - members = tuple(reader.members) - if ( - len(members) != 1 - or members[0].logical_path != _ON_THE_FLY_SEED_MEMBER_PATH - or members[0].kind is not PacbinMemberKind.ON_THE_FLY_PROCESS_SEED - or members[0].length < 1 - ): - raise FinalAuditError( - "on-the-fly runtime container does not contain exactly its " - "compact seed" - ) - seed_payload = reader.read_member( - _ON_THE_FLY_SEED_MEMBER_PATH, - length=members[0].length, - ) - except FinalAuditError: - raise - except (OSError, TypeError, ValueError) as error: - raise FinalAuditError("on-the-fly runtime container is invalid") from error - native_identity = _native_on_the_fly_process_seed_identity(seed_payload) - recorded_identity = _mapping( - runtime_metadata.get("process_seed_identity"), - "on-the-fly runtime metadata process_seed_identity", - ) - if native_identity != recorded_identity: - raise FinalAuditError( - "on-the-fly runtime metadata does not identify its native compact seed" - ) - _audit_on_the_fly_process_seed_identity( - native_identity, - runtime_metadata, - pack, - ) - seed_helicity_count = math.prod( - len( - _sequence( - _mapping(source, "on-the-fly native source identity").get("states"), - "on-the-fly native source identity states", - ) - ) - for source in _sequence( - native_identity.get("external_sources"), - "on-the-fly native source identities", - ) - ) - if seed_helicity_count != selector_census["physical_helicity_count"]: - raise FinalAuditError( - "on-the-fly selector helicity census disagrees with the decoded seed" - ) - return source_leaf_count - - -def audit_artifact( - cell: CellSpec, - artifact: Path, - process_id: str, -) -> ArtifactEvidence: - """Authenticate one artifact and prove the mode-specific Arena ABI.""" - - from pyamplicol.artifacts import inspect_artifact, load_manifest - - inspection = inspect_artifact(artifact) - if inspection.integrity != "verified": - raise FinalAuditError(f"artifact integrity is not verified: {artifact}") - # ``inspect_artifact`` has just verified every payload. Re-load the typed - # manifest without hashing the potentially large evaluator container twice; - # every identity-bearing JSON/TOML payload below is then re-read through a - # checked descriptor against its own manifest size and SHA-256. - manifest = load_manifest(artifact, verify_payloads=False) - effective_config = _authenticated_effective_config(artifact, manifest) - _audit_effective_config_mapping( - cell, - effective_config, - context="authenticated effective configuration", - ) - _audit_model_source(cell, effective_config) - process_matches = [ - process for process in manifest.processes if process.get("id") == process_id - ] - inspected_matches = [ - process for process in inspection.processes if process.id == process_id - ] - if len(process_matches) != 1 or len(inspected_matches) != 1: - raise FinalAuditError( - f"artifact process {process_id!r} is missing or ambiguous" - ) - process = process_matches[0] - inspected = inspected_matches[0] - expected_layout = ( - "compact/query-local" - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - else ( - "all-flow-union" - if cell.workload is Workload.ALL_FLOW - else "topology-replay" - ) - ) - if ( - process.get("expression") != cell.process - or process.get("color_accuracy") != cell.measurement.accuracy.value - or inspected.execution_mode != cell.measurement.execution_mode.value - or inspected.generation_specialized_axes - or inspected.selected_source_helicities - or inspected.selected_color_sector_ids - or ( - cell.measurement.accuracy is Accuracy.LC - and inspected.lc_flow_layout != expected_layout - ) - ): - raise FinalAuditError( - f"artifact physics/execution contract differs for {cell.cell_id}" - ) - ( - execution, - execution_path, - execution_sha256, - indexed_capabilities, - ) = _find_process_execution(artifact, manifest, process_id) - capabilities = tuple( - str(value) for value in process["required_runtime_capabilities"] - ) - if capabilities != indexed_capabilities: - raise FinalAuditError("artifact and evaluator-index capabilities differ") - expected_capability = _ARENA_CAPABILITY[cell.measurement.execution_mode] - if expected_capability not in capabilities: - raise FinalAuditError( - f"artifact does not require final Arena capability {expected_capability}" - ) - if cell.measurement.execution_mode is ExecutionMode.COMPILED: - arena_count, direct_leaf_count = _audit_compiled_execution(execution, cell) - source_jit_identity = None - elif cell.measurement.execution_mode is ExecutionMode.EAGER: - arena_count = _audit_eager_execution(artifact, manifest, execution, cell) - direct_leaf_count = arena_count - source_jit_identity = None - elif cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - source_jit_identity = _audit_recurrence_source_pack( - artifact, - manifest, - execution, - cell, - execution_manifest_path=execution_path, - execution_manifest_sha256=execution_sha256, - ) - arena_count = _audit_recurrence_execution(execution, cell) - direct_leaf_count = 0 - elif cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY: - arena_count = _audit_on_the_fly_execution( - artifact, - manifest, - execution, - cell, - process_id=process_id, - execution_manifest_path=execution_path, - effective_config=effective_config, - ) - direct_leaf_count = 0 - source_jit_identity = None - else: - raise FinalAuditError( - "unsupported artifact execution mode " - f"{cell.measurement.execution_mode.value}" - ) - return ArtifactEvidence( - artifact_id=manifest.artifact_id, - process_id=process_id, - producer_version=str(manifest.producer["version"]), - producer_git_revision=( - None - if manifest.producer.get("git_revision") is None - else str(manifest.producer["git_revision"]) - ), - producer_native_build_inputs_sha256=( - None - if manifest.producer.get("native_build_inputs_sha256") is None - else str(manifest.producer["native_build_inputs_sha256"]) - ), - runtime_version=str(manifest.runtime["engine_version"]), - runtime_capabilities=capabilities, - execution_manifest_path=execution_path, - execution_manifest_sha256=execution_sha256, - execution_mode=cell.measurement.execution_mode.value, - arena_record_count=arena_count, - direct_leaf_count=direct_leaf_count, - effective_config=effective_config, - source_jit_identity=source_jit_identity, - ) - - -def _selector_kwargs( - cell: CellSpec, - measurement: Mapping[str, object], -) -> dict[str, tuple[str, ...] | None]: - if cell.measurement.accuracy is not Accuracy.LC: - return {"helicities": None, "color_flows": None} - contract = SelectorContract.from_mapping( - _mapping( - measurement.get("selector_contract"), - f"{cell.cell_id}.selector_contract", - ) - ) - if cell.workload is Workload.SELECTED_FLOW: - return { - "helicities": None, - "color_flows": contract.selected_color_flow_ids, - } - return { - "helicities": contract.runtime_all_flow_helicity_ids, - "color_flows": None, - } - - -def _real_nonnegative(value: object, context: str) -> float: - number = complex(value) - if not math.isfinite(number.real) or not math.isfinite(number.imag): - raise FinalAuditError(f"{context} is not finite") - if abs(number.imag) > 1.0e-9 * max(abs(number.real), 1.0): - raise FinalAuditError(f"{context} has a non-negligible imaginary part") - result = float(number.real) - if result < -ABSOLUTE_TOLERANCE: - raise FinalAuditError(f"{context} is materially negative") - return max(result, 0.0) - - -def _resolved_differences( - optimized: Sequence[object], - resolved_totals: Sequence[object], - *, - context: str, -) -> tuple[float, float]: - if len(optimized) != len(resolved_totals): - raise FinalAuditError(f"{context} optimized/resolved lengths differ") - maximum_absolute = 0.0 - maximum_relative = 0.0 - for candidate, baseline in zip(optimized, resolved_totals, strict=True): - absolute = abs(complex(candidate) - complex(baseline)) - relative = absolute / max(abs(complex(candidate)), 1.0e-300) - maximum_absolute = max(maximum_absolute, absolute) - maximum_relative = max(maximum_relative, relative) - return maximum_absolute, maximum_relative - - -def _replay_cell( - runtime: object, - reference: _ArtifactReference, - evidence: ArtifactEvidence, -) -> _ReplayObservation: - cell = reference.cell - measurement = reference.measurement - context = f"{cell.cell_id}.replay" - if getattr(runtime, "artifact_id", None) != evidence.artifact_id: - raise FinalAuditError(f"{context} loaded artifact ID differs") - expected_mode = cell.measurement.execution_mode.value - loaded_mode = getattr(runtime, "execution_mode", None) - if loaded_mode != expected_mode or evidence.execution_mode != expected_mode: - raise FinalAuditError( - f"{context} loaded execution mode differs from requested {expected_mode!r}" - ) - provenance = _mapping( - measurement.get("provenance"), - f"{context}.provenance", - ) - runtime_identity = _mapping( - provenance.get("runtime_identity"), - f"{context}.provenance.runtime_identity", - ) - if runtime_identity.get("loaded_execution_mode") != loaded_mode: - raise FinalAuditError( - f"{context} stored loaded_execution_mode differs from the runtime" - ) - validate_runtime_contract(cell, runtime) # type: ignore[arg-type] - points = ( - runtime_validation_points(runtime) - if cell.measurement.model in {ModelKey.SCALAR_CONTACT, ModelKey.SCALAR_GRAVITY} - else shared_validation_points(cell.process) - ) - raw_selector = measurement.get("selector_contract") - if raw_selector is not None: - validate_selector_contract( - runtime, # type: ignore[arg-type] - SelectorContract.from_mapping(_mapping(raw_selector, context)), - points, - cell=cell, - ) - selectors = _selector_kwargs(cell, measurement) - optimized = tuple( - runtime.evaluate( # type: ignore[attr-defined] - points, - precision=16, - **selectors, - ) - ) - if not optimized: - raise FinalAuditError(f"{context} returned no matrix elements") - observed_matrix = _real_nonnegative(optimized[0], f"{context}.matrix_element") - stored_matrix = _finite_number( - measurement.get("matrix_element"), f"{context}.stored_matrix_element" - ) - validation = _mapping( - measurement.get("validation"), - f"{context}.validation", - ) - stored_resolved = _mapping( - validation.get("resolved_sum"), - f"{context}.validation.resolved_sum", - ) - matrix_absolute = abs(observed_matrix - stored_matrix) - matrix_scale = max(abs(observed_matrix), abs(stored_matrix)) - if stored_resolved.get("abi") == RESOLVED_SUM_VALIDATION_ABI: - records = stored_resolved.get("points") - if ( - not isinstance(records, list) - or len(records) != 1 - or not isinstance(records[0], Mapping) - ): - raise FinalAuditError(f"{context} has invalid resolved scale evidence") - matrix_scale = max( - matrix_scale, - _finite_number( - records[0].get("candidate_scale"), - f"{context}.candidate_scale", - nonnegative=True, - ), - ) - if matrix_absolute > RELATIVE_TOLERANCE * matrix_scale: - raise FinalAuditError( - f"{context} no longer reproduces the stored matrix element" - ) - resolved = runtime.evaluate_resolved( # type: ignore[attr-defined] - points, - precision=16, - **selectors, - ) - if stored_resolved.get("abi") == RESOLVED_SUM_VALIDATION_ABI: - replayed_resolved = resolved_sum_validation( - runtime, # type: ignore[arg-type] - points, - cell=cell, - selector_contract=( - None - if raw_selector is None - else SelectorContract.from_mapping(_mapping(raw_selector, context)) - ), - precision=16, - ) - if replayed_resolved != dict(stored_resolved): - raise FinalAuditError( - f"{context} recomputed conditioned resolved evidence differs" - ) - maximum_absolute = _finite_number( - replayed_resolved.get("maximum_absolute_difference"), - f"{context}.maximum_absolute_difference", - nonnegative=True, - ) - maximum_relative = _finite_number( - replayed_resolved.get("maximum_relative_difference"), - f"{context}.maximum_relative_difference", - nonnegative=True, - ) - else: - resolved_totals = tuple(resolved.total()) - maximum_absolute, maximum_relative = _resolved_differences( - optimized, - resolved_totals, - context=context, - ) - for field, observed in ( - ("maximum_absolute_difference", maximum_absolute), - ("maximum_relative_difference", maximum_relative), - ): - stored = _finite_number(stored_resolved.get(field), f"{context}.{field}") - if not math.isclose( - observed, - stored, - rel_tol=RELATIVE_TOLERANCE, - abs_tol=ABSOLUTE_TOLERANCE, - ): - raise FinalAuditError( - f"{context} recomputed {field} differs from stored evidence" - ) - if validation.get("high_precision") is not None: - high_record = _mapping( - validation.get("high_precision"), - f"{context}.validation.high_precision", - ) - if high_record.get("abi") == CONDITIONED_COMPARISON_ABI: - replayed_high_resolved = resolved_sum_validation( - runtime, # type: ignore[arg-type] - points, - cell=cell, - selector_contract=( - None - if raw_selector is None - else SelectorContract.from_mapping(_mapping(raw_selector, context)) - ), - precision=32, - ) - if replayed_high_resolved != validation.get("high_precision_resolved_sum"): - raise FinalAuditError( - f"{context} recomputed p32 resolved evidence differs" - ) - high_value = _finite_number( - _mapping( - replayed_high_resolved["points"][0], - f"{context}.precision32.point", - ).get("candidate"), - f"{context}.precision32", - nonnegative=True, - ) - else: - high_precision = tuple( - runtime.evaluate( # type: ignore[attr-defined] - points, - precision=32, - **selectors, - ) - ) - if not high_precision: - raise FinalAuditError(f"{context} precision-32 evaluation is empty") - high_value = _real_nonnegative(high_precision[0], f"{context}.precision32") - _audit_pointwise( - high_record, - context=f"{context}.validation.high_precision", - expected_candidate=observed_matrix, - expected_baseline=high_value, - expected_relative_tolerance=RELATIVE_TOLERANCE, - expected_point_digest=point_digest(points), - ) - common_component: float | None = None - if cell.measurement.accuracy is Accuracy.LC: - assert raw_selector is not None - common_record = evaluate_lc_common_component( - runtime, - points, - cell=cell, - contract=SelectorContract.from_mapping( - _mapping(raw_selector, f"{context}.selector_contract") - ), - ) - common_component = _finite_number( - common_record.get("value"), - f"{context}.lc_common_component", - ) - stored_component = _audit_lc_common_component( - cell, - measurement, - context=context, - ) - absolute = abs(common_component - stored_component) - relative = absolute / max(abs(stored_component), 1.0e-300) - if ( - absolute > STRICT_ABSOLUTE_TOLERANCE - and relative > STRICT_RELATIVE_TOLERANCE - ): - raise FinalAuditError( - f"{context} no longer reproduces the stored LC common component" - ) - return _ReplayObservation( - matrix_element=observed_matrix, - resolved_maximum_absolute=maximum_absolute, - resolved_maximum_relative=maximum_relative, - lc_common_component=common_component, - ) - - -def _default_runtime_loader(path: Path, process_id: str) -> object: - from pyamplicol.api import Runtime - - return Runtime.load(path, process=process_id) - - -def _entry_map( - caches: Mapping[str, Mapping[str, object]], -) -> dict[str, Mapping[str, object]]: - result: dict[str, Mapping[str, object]] = {} - for cache_name, payload in caches.items(): - entries = _sequence(payload.get("entries"), f"{cache_name}.entries") - for raw_entry in entries: - entry = _mapping(raw_entry, f"{cache_name}.entry") - cell_id = entry.get("cell_id") - if not isinstance(cell_id, str) or not cell_id: - raise FinalAuditError(f"{cache_name} contains an invalid cell ID") - if cell_id in result: - raise FinalAuditError(f"duplicate cache cell {cell_id!r}") - result[cell_id] = entry - return result - - -def _catalog_static_na_projection_errors( - cells: Sequence[CellSpec], - entries: Mapping[str, Mapping[str, object]], - *, - load_current: Callable[[str], object | None], -) -> tuple[str, ...]: - """Audit the immutable no-measurement contract for static-N/A cells.""" - - errors: list[str] = [] - for cell in cells: - entry = entries.get(cell.cell_id) - if entry is None: - errors.append(f"{cell.cell_id}: cache entry is missing") - continue - if entry != reset_entry(cell): - errors.append( - f"{cell.cell_id}: catalog static N/A cache entry differs " - "from the canonical reset entry" - ) - if load_current(cell.cell_id) is not None: - errors.append( - f"{cell.cell_id}: catalog static N/A cell has a published current" - ) - return tuple(errors) - - -def _replayed_agreement_value( - edge: AgreementEdge, - cell: CellSpec, - measurement: Mapping[str, object], - replayed: Mapping[str, _ReplayObservation], - replay_required: bool, -) -> float: - observation = replayed.get(cell.cell_id) - if replay_required and observation is None: - raise FinalAuditError( - f"{cell.cell_id} is missing its required pyAmpliCol replay" - ) - if not replay_required and observation is not None: - raise FinalAuditError( - f"{cell.cell_id} unexpectedly has replay evidence in a stored-only lane" - ) - if edge.value_kind == "matrix_element": - if not replay_required: - return _finite_number( - measurement.get("matrix_element"), - f"{cell.cell_id}.matrix_element", - ) - assert observation is not None - return observation.matrix_element - if replay_required: - assert observation is not None - if observation.lc_common_component is None: - raise FinalAuditError(f"{cell.cell_id} replay has no LC common component") - return observation.lc_common_component - return _audit_lc_common_component( - cell, - measurement, - context=f"{cell.cell_id}.authenticated", - ) - - -def _direct_replay_category(edge: AgreementEdge) -> str: - if edge.kind == MADGRAPH_FULL_COLOUR: - if ( - edge.baseline.measurement.execution_mode is not ExecutionMode.MADGRAPH - or edge.candidate.measurement.execution_mode - in {ExecutionMode.AMPLICOL, ExecutionMode.MADGRAPH} - ): - raise FinalAuditError( - f"{edge.candidate.cell_id}: invalid MadGraph direct-edge endpoints" - ) - return _AUTHENTICATED_STORED_MADGRAPH - candidate_is_pyamplicol = edge.candidate.measurement.execution_mode not in { - ExecutionMode.AMPLICOL, - ExecutionMode.MADGRAPH, - } - baseline_is_pyamplicol = edge.baseline.measurement.execution_mode not in { - ExecutionMode.AMPLICOL, - ExecutionMode.MADGRAPH, - } - if candidate_is_pyamplicol and baseline_is_pyamplicol: - return _FULLY_REPLAYED_PYAMPLICOL - if ( - candidate_is_pyamplicol - and not baseline_is_pyamplicol - and edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT - ): - return _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY - if ( - not candidate_is_pyamplicol - and not baseline_is_pyamplicol - and edge.kind == LC_CROSS_LAYOUT_COMPONENT - ): - return _AUTHENTICATED_STORED_LEGACY_LAYOUT - raise FinalAuditError( - f"{edge.candidate.cell_id}: unexpected direct-edge replay endpoint classes " - f"for {edge.kind}" - ) - - -def _audit_replayed_direct_agreements( - edges: Sequence[AgreementEdge], - measurements: Mapping[str, Mapping[str, object]], - replayed: Mapping[str, _ReplayObservation], -) -> dict[str, int]: - errors: list[str] = [] - counts: Counter[str] = Counter() - for edge in edges: - try: - category = _direct_replay_category(edge) - counts[category] += 1 - stored_record = _stored_direct_agreement( - measurements[edge.candidate.cell_id], - edge_kind=edge.kind, - baseline_cell_id=edge.baseline.cell_id, - ) - if stored_record is None: - raise FinalAuditError( - f"{edge.candidate.cell_id} has no authenticated stored " - f"{edge.kind} agreement" - ) - candidate = _replayed_agreement_value( - edge, - edge.candidate, - measurements[edge.candidate.cell_id], - replayed, - replay_required=category - in { - _FULLY_REPLAYED_PYAMPLICOL, - _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY, - _AUTHENTICATED_STORED_MADGRAPH, - }, - ) - if category == _REPLAYED_PYAMPLICOL_AUTHENTICATED_LEGACY: - stored_candidate = _finite_number( - stored_record.get("candidate"), - f"{edge.candidate.cell_id}.stored_legacy_candidate", - ) - absolute = abs(candidate - stored_candidate) - scale = max(abs(candidate), abs(stored_candidate)) - if ( - absolute > STRICT_ABSOLUTE_TOLERANCE - and absolute > STRICT_RELATIVE_TOLERANCE * scale - ): - raise FinalAuditError( - "replayed legacy diagnostic candidate differs from its " - "authenticated stored candidate" - ) - # AmpliCol is diagnostic-only: a faithfully replayed candidate - # remains valid even when the stored legacy comparison failed. - continue - if category == _AUTHENTICATED_STORED_MADGRAPH: - candidate_precision = madgraph_candidate_precision(edge.candidate) - stored_authority_candidate = _finite_number( - stored_record.get("candidate"), - f"{edge.candidate.cell_id}.stored_madgraph_" - f"p{candidate_precision}_candidate", - ) - absolute = abs(candidate - stored_authority_candidate) - scale = max(abs(candidate), abs(stored_authority_candidate)) - if stored_record.get("abi") == DIRECT_AGREEMENT_V2_ABI: - scale = max( - scale, - _finite_number( - stored_record.get("candidate_scale"), - f"{edge.candidate.cell_id}.candidate_scale", - nonnegative=True, - ), - ) - if ( - absolute > STRICT_ABSOLUTE_TOLERANCE - and absolute > edge.relative_tolerance * scale - ): - raise FinalAuditError( - "replayed p16 candidate differs from its authenticated " - f"stored p{candidate_precision} MadGraph comparison" - ) - # The MadGraph executable is deliberately not replayed here. - # Its binary64 result and candidate comparison were already - # authenticated by the structural direct-edge audit. - continue - if category == _AUTHENTICATED_STORED_LEGACY_LAYOUT: - baseline = _replayed_agreement_value( - edge, - edge.baseline, - measurements[edge.baseline.cell_id], - replayed, - replay_required=False, - ) - else: - baseline = _replayed_agreement_value( - edge, - edge.baseline, - measurements[edge.baseline.cell_id], - replayed, - replay_required=category == _FULLY_REPLAYED_PYAMPLICOL, - ) - absolute = abs(candidate - baseline) - scale = max(abs(candidate), abs(baseline)) - if ( - isinstance(stored_record, Mapping) - and stored_record.get("abi") == DIRECT_AGREEMENT_V2_ABI - ): - scale = max( - scale, - _finite_number( - stored_record.get("candidate_scale"), - f"{edge.candidate.cell_id}.candidate_scale", - nonnegative=True, - ), - _finite_number( - stored_record.get("baseline_scale"), - f"{edge.candidate.cell_id}.baseline_scale", - nonnegative=True, - ), - ) - if absolute > edge.relative_tolerance * scale: - raise FinalAuditError( - f"replayed {edge.kind} direct edge differs from " - f"{edge.baseline.cell_id}" - ) - except Exception as error: - errors.append(f"{edge.candidate.cell_id}: {error}") - if errors: - rendered = "\n".join(f"- {message}" for message in errors[:50]) - raise FinalAuditError( - f"final report direct-edge replay failed ({len(errors)}):\n{rendered}" - ) - return {category: counts.get(category, 0) for category in _DIRECT_REPLAY_CATEGORIES} - - -def audit_final_report( - repo_root: Path, - *, - expected_source_revision: str, - expected_publication_revision: str | None = None, - max_n_final: int = _FULL_CATALOG_MAX_N_FINAL, - expected_cell_count: int | None = _EXPECTED_FULL_CATALOG_CELL_COUNT, - replay: bool = True, - catalog: ReportCatalog = REPORT_CATALOG, - service: ReportService | None = None, - active_runtime: Mapping[str, object] | None = None, - artifact_auditor: ArtifactAuditor = audit_artifact, - runtime_loader: RuntimeLoader = _default_runtime_loader, - source_auditor: SourceAuditor = _require_report_source_checkout, - runtime_auditor: RuntimeAuditor = _audit_active_runtime, - verify_render: bool = True, - verify_pdf: bool = True, - pdf_auditor: PdfAuditor = _audit_pdf, - campaign_policy: CampaignPolicy | None = None, -) -> dict[str, object]: - """Audit one cooperative report snapshot under the publication lock.""" - - root = repo_root.expanduser().resolve(strict=False) - report = service or ReportService(ReportPaths.from_repo(root), catalog=catalog) - with report.store.named_lock("report-writer"): - return _audit_final_report_locked( - root, - expected_source_revision=expected_source_revision, - expected_publication_revision=expected_publication_revision, - max_n_final=max_n_final, - expected_cell_count=expected_cell_count, - replay=replay, - catalog=catalog, - service=report, - active_runtime=active_runtime, - artifact_auditor=artifact_auditor, - runtime_loader=runtime_loader, - source_auditor=source_auditor, - runtime_auditor=runtime_auditor, - verify_render=verify_render, - verify_pdf=verify_pdf, - pdf_auditor=pdf_auditor, - campaign_policy=campaign_policy, - ) - - -def _audit_final_report_locked( - repo_root: Path, - *, - expected_source_revision: str, - expected_publication_revision: str | None = None, - max_n_final: int = _FULL_CATALOG_MAX_N_FINAL, - expected_cell_count: int | None = _EXPECTED_FULL_CATALOG_CELL_COUNT, - replay: bool = True, - catalog: ReportCatalog = REPORT_CATALOG, - service: ReportService | None = None, - active_runtime: Mapping[str, object] | None = None, - artifact_auditor: ArtifactAuditor = audit_artifact, - runtime_loader: RuntimeLoader = _default_runtime_loader, - source_auditor: SourceAuditor = _require_report_source_checkout, - runtime_auditor: RuntimeAuditor = _audit_active_runtime, - verify_render: bool = True, - verify_pdf: bool = True, - pdf_auditor: PdfAuditor = _audit_pdf, - campaign_policy: CampaignPolicy | None = None, -) -> dict[str, object]: - """Audit every selected record while the report-writer lock is held.""" - - if _GIT_SHA_RE.fullmatch(expected_source_revision) is None: - raise FinalAuditError("expected source revision must be a full Git SHA") - if ( - expected_publication_revision is not None - and _GIT_SHA_RE.fullmatch(expected_publication_revision) is None - ): - raise FinalAuditError("expected publication revision must be a full Git SHA") - if max_n_final < 1: - raise FinalAuditError("max_n_final must be positive") - root = repo_root.expanduser().resolve(strict=False) - report = service or ReportService(ReportPaths.from_repo(root), catalog=catalog) - using_production_source_auditor = source_auditor is _require_report_source_checkout - if using_production_source_auditor: - report_profile = _active_report_profile(root, report) - try: - active_policy = load_profile_campaign_policy( - root, - report_profile, - expected_source_revision=expected_source_revision, - ) - except Exception as error: - raise FinalAuditError( - f"cannot authenticate report campaign policy: {error}" - ) from error - if campaign_policy is not None and campaign_policy is not active_policy: - raise FinalAuditError( - "caller-supplied campaign policy differs from the measured profile" - ) - raw_publication_lineage = _profile_publication_lineage( - root, - expected_source_revision, - profile=report_profile, - ) - expected_source_tree: str | None = str( - raw_publication_lineage["measurement_source_tree"] - ) - try: - measurement_lineage = load_and_audit_measurement_lineage( - root, - report.paths.docs_dir, - report.store, - expected_active_source_revision=expected_source_revision, - catalog=catalog, - ) - report.bind_measurement_lineage(measurement_lineage) - except MeasurementLineageError as error: - seed = report._original_amplicol_seed() - if ( - seed is None - or (report.paths.docs_dir / "measurement_lineage.json").exists() - ): - raise FinalAuditError( - f"cannot authenticate measurement source bridge: {error}" - ) from error - measurement_lineage = None - report.bind_measurement_lineage(None) - else: - report_profile = None - active_policy = campaign_policy or STRICT_POLICY - raw_publication_lineage = source_auditor( - root, - expected_source_revision, - ) - expected_source_tree = None - measurement_lineage = None - policy_profile = report_profile or ( - MACBOOK_M3_PROFILE - if active_policy - in { - MACBOOK_M3_POLICY, - MACBOOK_M3_Z_TABLE_F_POLICY, - } - else (X86_EPYC_PROFILE if active_policy is X86_EPYC_POLICY else "") - ) - publication_lineage = _validated_publication_lineage( - raw_publication_lineage, - measurement_source_revision=expected_source_revision, - expected_publication_revision=expected_publication_revision, - expected_profile=report_profile, - ) - render_result = ( - report.audit() - if verify_render - else {"cache_render_match": None, "skipped": True} - ) - caches = report.load_caches() - entries = _entry_map(caches) - declared_cells = tuple( - sorted( - ( - cell - for cell in catalog.measurement_cells() - if cell.n_final <= max_n_final - ), - key=lambda item: item.cell_id, - ) - ) - if expected_cell_count is not None and len(declared_cells) != expected_cell_count: - raise FinalAuditError( - "catalog selected " - f"{len(declared_cells)} declared cells, expected " - f"{expected_cell_count}" - ) - static_na_cells = tuple( - cell for cell in declared_cells if catalog.static_na_reason(cell) is not None - ) - if catalog is REPORT_CATALOG and max_n_final == _FULL_CATALOG_MAX_N_FINAL: - observed_static_na_ids = {cell.cell_id for cell in static_na_cells} - if observed_static_na_ids != _EXPECTED_FULL_STATIC_NA_CELL_IDS: - missing_static_na_ids = sorted( - _EXPECTED_FULL_STATIC_NA_CELL_IDS - observed_static_na_ids - ) - extra_static_na_ids = sorted( - observed_static_na_ids - _EXPECTED_FULL_STATIC_NA_CELL_IDS - ) - raise FinalAuditError( - "canonical catalog static-N/A census differs: " - f"missing={missing_static_na_ids}, " - f"extra={extra_static_na_ids}" - ) - observed_static_na_reasons = { - cell.cell_id: catalog.static_na_reason(cell) for cell in static_na_cells - } - if observed_static_na_reasons != _EXPECTED_FULL_STATIC_NA_REASONS: - raise FinalAuditError( - "canonical catalog static-N/A reasons differ: " - f"{dict(sorted(observed_static_na_reasons.items()))}" - ) - cells = tuple( - cell for cell in declared_cells if catalog.static_na_reason(cell) is None - ) - published_measurements: dict[str, Mapping[str, object]] = {} - measurements: dict[str, Mapping[str, object]] = {} - measurement_sources: dict[str, tuple[str, str | None]] = {} - measurement_states: dict[str, PolicyMeasurementState] = {} - errors = list( - _catalog_static_na_projection_errors( - static_na_cells, - entries, - load_current=lambda cell_id: report.store.load_current( - cell_id, - missing_ok=True, - ), - ) - ) - for cell in cells: - entry = entries.get(cell.cell_id) - if entry is None: - errors.append(f"{cell.cell_id}: cache entry is missing") - continue - expected_entry = reset_entry(cell) - descriptor_mismatches = [ - field - for field, value in expected_entry.items() - if field != "measurement" and entry.get(field) != value - ] - if descriptor_mismatches: - errors.append( - f"{cell.cell_id}: cache descriptor differs: " - + ", ".join(descriptor_mismatches) - ) - continue - published = _mapping( - entry.get("measurement"), - f"{cell.cell_id}.published_measurement", - ) - current = report.store.load_current( - cell.cell_id, - missing_ok=True, - ) - if current is None: - errors.append(f"{cell.cell_id}: authenticated current result is missing") - continue - current_measurement = _mapping( - current.result, - f"{cell.cell_id}.current.result", - ) - if measurement_lineage is None: - seed = report._original_amplicol_seed() - authorized_seed = ( - None - if seed is None - else seed.source_for_current( - current, - active_revision=expected_source_revision, - active_tree=expected_source_tree or "", - ) - ) - cell_source = ( - authorized_seed - if authorized_seed is not None - else (expected_source_revision, expected_source_tree) - ) - else: - authorized = measurement_lineage.source_for_current( - current, - active_revision=expected_source_revision, - active_tree=expected_source_tree or "", - ) - if authorized is None: - errors.append( - f"{cell.cell_id}: current is not authorized by the " - "measurement source bridge" - ) - continue - cell_source = authorized - if ( - cell.cell_id in measurement_lineage.required_descendant_cell_ids - and cell_source[0] != expected_source_revision - ): - errors.append( - f"{cell.cell_id}: Class-C impact/agreement target has not " - "been remeasured at the descendant source" - ) - continue - policy_errors = ( - *_publication_policy_errors( - f"{cell.cell_id}.published_measurement", - published, - expected_source_revision=cell_source[0], - expected_source_tree=cell_source[1], - ), - *_publication_policy_errors( - f"{cell.cell_id}.current.result", - current_measurement, - expected_source_revision=cell_source[0], - expected_source_tree=cell_source[1], - ), - ) - if policy_errors: - errors.extend(policy_errors) - continue - try: - published_state = validate_policy_measurement( - active_policy, - policy_profile, - cell, - published, - expected_source_revision=cell_source[0], - expected_source_tree=cell_source[1], - ) - current_state = validate_policy_measurement( - active_policy, - policy_profile, - cell, - current_measurement, - expected_source_revision=cell_source[0], - expected_source_tree=cell_source[1], - ) - if published_state is not current_state: - raise FinalAuditError("published and current policy states differ") - except (CampaignPolicyError, FinalAuditError) as error: - errors.append(f"{cell.cell_id}: {error}") - continue - if not publication_measurement_matches_current( - published, - current_measurement, - report.paths, - ): - errors.append( - f"{cell.cell_id}: checked-in cache is not the exact portable " - "projection of authenticated current.result" - ) - continue - published_measurements[cell.cell_id] = published - measurements[cell.cell_id] = current_measurement - measurement_sources[cell.cell_id] = cell_source - measurement_states[cell.cell_id] = current_state - if errors: - rendered = "\n".join(f"- {message}" for message in errors[:50]) - suffix = ( - "" - if len(errors) <= 50 - else f"\n- ... and {len(errors) - 50} additional failures" - ) - raise FinalAuditError( - "final report publication projection audit failed " - f"({len(errors)}):\n{rendered}{suffix}" - ) - - def resource_lane(cell: CellSpec) -> tuple[object, ...]: - return tuple(resource_lane_identity(cell).items()) - - resource_sources: dict[tuple[object, ...], list[CellSpec]] = defaultdict(list) - for source_cell in cells: - if measurement_states[source_cell.cell_id] in { - PolicyMeasurementState.GENERATION_LIMIT, - PolicyMeasurementState.MEMORY_LIMIT, - }: - resource_sources[resource_lane(source_cell)].append(source_cell) - for lane_sources in resource_sources.values(): - lane_sources.sort(key=lambda item: item.n_final) - - dependency_errors: list[str] = [] - for cell in cells: - lower_resource_sources = tuple( - source - for source in resource_sources.get(resource_lane(cell), ()) - if source.n_final < cell.n_final - ) - frontier_source = lower_resource_sources[0] if lower_resource_sources else None - state = measurement_states[cell.cell_id] - if frontier_source is not None: - expected_frontier = resource_frontier_reference( - cell, - frontier_source, - measurements[frontier_source.cell_id], - ) - if state is not PolicyMeasurementState.RESOURCE_FRONTIER: - dependency_errors.append( - f"{cell.cell_id}: higher multiplicity is not bound to " - f"resource frontier {frontier_source.cell_id}" - ) - continue - provenance = _mapping( - measurements[cell.cell_id].get("provenance"), - f"{cell.cell_id}.provenance", - ) - censor = _mapping( - provenance.get("policy_censor"), - f"{cell.cell_id}.policy_censor", - ) - if censor.get("frontier") != expected_frontier: - dependency_errors.append( - f"{cell.cell_id}: resource frontier does not exactly bind " - f"the first lower hard censor {frontier_source.cell_id}" - ) - continue - if state is PolicyMeasurementState.RESOURCE_FRONTIER: - dependency_errors.append( - f"{cell.cell_id}: resource frontier has no current lower hard " - "resource censor in the same lane" - ) - continue - candidate_baseline_cell = catalog.validation_baseline_cell(cell) - baseline_cell = ( - candidate_baseline_cell - if validation_baseline_is_required(cell, candidate_baseline_cell) - else None - ) - dependency_cells = { - dependency.cell_id: dependency - for dependency in ( - *((baseline_cell,) if baseline_cell is not None else ()), - *( - edge.baseline - for edge in incoming_agreement_edges(cell, catalog=catalog) - if edge.required - ), - ) - if dependency.cell_id in measurements - } - terminal_dependencies = tuple( - sorted( - ( - dependency_reference( - dependency.cell_id, - measurements[dependency.cell_id], - ) - for dependency in dependency_cells.values() - if measurement_states[dependency.cell_id] - is not PolicyMeasurementState.SUCCESS - ), - key=lambda item: str(item["cell_id"]), - ) - ) - if state is PolicyMeasurementState.SUCCESS and terminal_dependencies: - dependency_errors.append( - f"{cell.cell_id}: successful measurement depends on a " - "policy-censored comparison endpoint" - ) - continue - if state is not PolicyMeasurementState.DEPENDENCY: - continue - provenance = _mapping( - measurements[cell.cell_id].get("provenance"), - f"{cell.cell_id}.provenance", - ) - censor = _mapping( - provenance.get("policy_censor"), - f"{cell.cell_id}.policy_censor", - ) - observed = censor.get("dependencies") - if observed != list(terminal_dependencies): - dependency_errors.append( - f"{cell.cell_id}: dependency censor does not exactly bind its " - "current required terminal dependencies" - ) - if dependency_errors: - rendered = "\n".join(f"- {message}" for message in dependency_errors[:50]) - raise FinalAuditError( - "final report policy-dependency audit failed " - f"({len(dependency_errors)}):\n{rendered}" - ) - - visible_completeness = summarize_visible_completeness( - caches, - catalog=catalog, - max_n_final=max_n_final, - policy=active_policy, - ) - if ( - visible_completeness.declared_measurement_cell_count != len(declared_cells) - or visible_completeness.required_measurement_count != len(cells) - or visible_completeness.rendered_required_measurement_count != len(cells) - or visible_completeness.catalog_static_na_cell_count != len(static_na_cells) - or visible_completeness.rendered_catalog_static_na_cell_count - != len(static_na_cells) - or not visible_completeness.complete - ): - evidence = visible_completeness.as_dict() - raise FinalAuditError( - "final report visible-completeness audit failed: " - f"declared={evidence['declared_measurement_cell_count']}, " - f"required={evidence['required_measurement_count']}, " - f"rendered={evidence['rendered_required_measurement_count']}, " - f"static={evidence['catalog_static_na_cell_count']}, " - "rendered_static=" - f"{evidence['rendered_catalog_static_na_cell_count']}, " - f"applicable_NA={evidence['applicable_na_display_slot_count']}, " - f"missing={evidence['missing_rendered_cell_count']}, " - f"errors={evidence['contract_errors']}, " - f"slots={evidence['applicable_na_display_slots']}" - ) - - successful_cells = tuple( - cell - for cell in cells - if measurement_states[cell.cell_id] is PolicyMeasurementState.SUCCESS - ) - pyamplicol_cells = tuple( - cell - for cell in successful_cells - if cell.measurement.execution_mode - not in {ExecutionMode.AMPLICOL, ExecutionMode.MADGRAPH} - ) - madgraph_cells = tuple( - cell - for cell in successful_cells - if cell.measurement.execution_mode is ExecutionMode.MADGRAPH - ) - successful_legacy_cells = tuple( - cell - for cell in successful_cells - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - expected_legacy_revision = ( - _expected_legacy_revision(root) if successful_legacy_cells else "" - ) - if pyamplicol_cells and active_runtime is None: - active_runtime = runtime_auditor( - expected_source_revision, - root, - ) - - references: list[_ArtifactReference] = [] - errors = [] - for cell in successful_cells: - measurement = measurements[cell.cell_id] - try: - baseline_endpoint = _validation_baseline_endpoint_for_audit( - cell, - measurements, - measurement_states, - catalog=catalog, - ) - baseline_cell = None if baseline_endpoint is None else baseline_endpoint[0] - baseline = None if baseline_endpoint is None else baseline_endpoint[1] - reference = _audit_measurement( - cell, - measurement, - baseline=baseline, - baseline_cell=baseline_cell, - expected_source_revision=measurement_sources[cell.cell_id][0], - expected_source_tree=measurement_sources[cell.cell_id][1], - expected_legacy_revision=expected_legacy_revision, - active_runtime=active_runtime, - report_paths=report.paths, - ) - if reference is not None: - published_reference = _artifact_reference( - cell, - published_measurements[cell.cell_id], - report_paths=report.paths, - ) - if ( - published_reference.path != reference.path - or published_reference.process_id != reference.process_id - ): - raise FinalAuditError( - "portable artifact locator differs from raw current.result" - ) - references.append(reference) - except Exception as error: # collect every independently actionable cell - errors.append(f"{cell.cell_id}: {error}") - if errors: - rendered = "\n".join(f"- {message}" for message in errors[:50]) - suffix = ( - "" - if len(errors) <= 50 - else f"\n- ... and {len(errors) - 50} additional failures" - ) - raise FinalAuditError( - f"final report structural measurement audit failed ({len(errors)}):\n" - f"{rendered}{suffix}" - ) - - direct_edges, direct_agreement_counts = _audit_direct_agreements( - successful_cells, - measurements, - catalog=catalog, - ) - if ( - catalog is REPORT_CATALOG - and max_n_final == 4 - and len(declared_cells) == _EXPECTED_N4_CELL_COUNT - and active_policy is STRICT_POLICY - and not _count_contract_matches_with_optional_categories( - direct_agreement_counts, - _EXPECTED_N4_DIRECT_AGREEMENT_COUNTS, - optional_categories={ - Z_RECURRENCE_CROSS_MODE, - LC_LEGACY_PYAMPLICOL_COMPONENT, - }, - ) - ): - raise FinalAuditError( - "canonical n<=4 direct-agreement edge counts differ: " - f"expected={_EXPECTED_N4_DIRECT_AGREEMENT_COUNTS}, " - f"observed={direct_agreement_counts}" - ) - if ( - catalog is REPORT_CATALOG - and max_n_final == _FULL_CATALOG_MAX_N_FINAL - and len(declared_cells) == _EXPECTED_FULL_CATALOG_CELL_COUNT - and active_policy is STRICT_POLICY - and not _count_contract_matches_with_optional_categories( - direct_agreement_counts, - _EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS, - optional_categories={ - Z_RECURRENCE_CROSS_MODE, - LC_LEGACY_PYAMPLICOL_COMPONENT, - }, - ) - ): - raise FinalAuditError( - "canonical full-catalog direct-agreement edge counts differ: " - f"expected={_EXPECTED_FULL_DIRECT_AGREEMENT_COUNTS}, " - f"observed={direct_agreement_counts}" - ) - - legacy_cells = successful_legacy_cells - legacy_agreement_edges = _legacy_consumer_coverage( - successful_cells, - measurements, - measurement_states, - catalog=catalog, - ) - covered_legacy_ids = {baseline for baseline, _candidate in legacy_agreement_edges} - - grouped: dict[tuple[Path, str], list[_ArtifactReference]] = defaultdict(list) - for reference in references: - grouped[(reference.path, reference.process_id)].append(reference) - evidence_by_key: dict[tuple[Path, str], ArtifactEvidence] = {} - errors = [] - for key, group in grouped.items(): - representative = group[0] - try: - evidence = artifact_auditor( - representative.cell, representative.path, representative.process_id - ) - evidence_by_key[key] = evidence - for reference in group: - if _shared_artifact_contract( - reference.cell - ) != _shared_artifact_contract(representative.cell): - raise FinalAuditError( - "one artifact path is shared by incompatible report cells" - ) - provenance = _mapping( - reference.measurement.get("provenance"), - f"{reference.cell.cell_id}.provenance", - ) - assert active_runtime is not None - source_revision = measurement_sources[reference.cell.cell_id][0] - _audit_runtime_identity( - reference.cell, - provenance, - expected_source_revision=source_revision, - active_runtime=_runtime_for_measurement_source( - active_runtime, - provenance, - source_revision=source_revision, - measurement_lineage=measurement_lineage, - ), - artifact=evidence, - ) - except Exception as error: - errors.append(f"{representative.path}: {error}") - if errors: - rendered = "\n".join(f"- {message}" for message in errors[:50]) - raise FinalAuditError( - f"final report artifact/Arena audit failed ({len(errors)}):\n{rendered}" - ) - - replayed: dict[str, _ReplayObservation] = {} - replayed_direct_agreement_counts = { - category: 0 for category in _DIRECT_REPLAY_CATEGORIES - } - if replay: - errors = [] - for key, group in grouped.items(): - path, process_id = key - try: - runtime = runtime_loader(path, process_id) - evidence = evidence_by_key[key] - for reference in group: - replayed[reference.cell.cell_id] = _replay_cell( - runtime, reference, evidence - ) - except Exception as error: - errors.append(f"{path} ({process_id}): {error}") - finally: - if "runtime" in locals(): - del runtime - gc.collect() - for cell in pyamplicol_cells: - observation = replayed.get(cell.cell_id) - if observation is None: - continue - try: - baseline_endpoint = _validation_baseline_endpoint_for_audit( - cell, - measurements, - measurement_states, - catalog=catalog, - ) - except FinalAuditError as error: - errors.append(f"{cell.cell_id}: {error}") - continue - if baseline_endpoint is None: - continue - baseline_cell, baseline_measurement = baseline_endpoint - baseline_observation = replayed.get(baseline_cell.cell_id) - baseline_value = ( - baseline_observation.matrix_element - if baseline_observation is not None - else _finite_number( - baseline_measurement.get("matrix_element"), - f"{baseline_cell.cell_id}.matrix_element", - ) - ) - absolute = abs(observation.matrix_element - baseline_value) - relative = absolute / max(abs(baseline_value), 1.0e-300) - if ( - absolute > ABSOLUTE_TOLERANCE - and relative > _expected_pointwise_tolerance(cell) - ): - errors.append(f"{cell.cell_id}: replay differs from canonical baseline") - if errors: - rendered = "\n".join(f"- {message}" for message in errors[:50]) - raise FinalAuditError( - f"final report numerical replay failed ({len(errors)}):\n{rendered}" - ) - replayed_direct_agreement_counts = _audit_replayed_direct_agreements( - direct_edges, - measurements, - replayed, - ) - if ( - catalog is REPORT_CATALOG - and max_n_final == 4 - and len(declared_cells) == _EXPECTED_N4_CELL_COUNT - and active_policy is STRICT_POLICY - and not _replay_count_contract_matches_direct_edges( - replayed_direct_agreement_counts, - direct_agreement_counts, - _EXPECTED_N4_DIRECT_REPLAY_COUNTS, - ) - ): - raise FinalAuditError( - "canonical n<=4 direct-agreement replay categories differ: " - f"expected={_EXPECTED_N4_DIRECT_REPLAY_COUNTS}, " - f"observed={replayed_direct_agreement_counts}" - ) - if ( - catalog is REPORT_CATALOG - and max_n_final == _FULL_CATALOG_MAX_N_FINAL - and len(declared_cells) == _EXPECTED_FULL_CATALOG_CELL_COUNT - and active_policy is STRICT_POLICY - and not _replay_count_contract_matches_direct_edges( - replayed_direct_agreement_counts, - direct_agreement_counts, - _EXPECTED_FULL_DIRECT_REPLAY_COUNTS, - ) - ): - raise FinalAuditError( - "canonical full-catalog direct-agreement replay categories " - f"differ: expected={_EXPECTED_FULL_DIRECT_REPLAY_COUNTS}, " - f"observed={replayed_direct_agreement_counts}" - ) - if len(replayed) != len(pyamplicol_cells): - raise FinalAuditError( - "final report replay did not cover every pyAmpliCol measurement: " - f"{len(replayed)}/{len(pyamplicol_cells)}" - ) - - pdf_result: Mapping[str, object] - if verify_pdf: - pdf_result = pdf_auditor(report) - if pdf_result.get("status") != ResultStatus.OK.value: - raise FinalAuditError("final PDF auditor did not return status='ok'") - else: - pdf_result = {"status": "incomplete", "skipped": True} - - raw_publication_postflight = ( - _profile_publication_lineage( - root, - expected_source_revision, - profile=report_profile, - ) - if using_production_source_auditor and report_profile is not None - else source_auditor(root, expected_source_revision) - ) - publication_postflight = _validated_publication_lineage( - raw_publication_postflight, - measurement_source_revision=expected_source_revision, - expected_publication_revision=expected_publication_revision, - expected_profile=report_profile, - ) - if publication_postflight != publication_lineage: - raise FinalAuditError( - "report publication lineage changed during final report audit" - ) - if pyamplicol_cells: - runtime_postflight = runtime_auditor(expected_source_revision, root) - _validate_loaded_origin_policy( - runtime_postflight.get("loaded_module_origin_policy"), - context="postflight_runtime.loaded_module_origin_policy", - ) - stable_postflight = dict(runtime_postflight) - stable_initial = dict(active_runtime or {}) - stable_postflight.pop("loaded_module_origin_policy", None) - stable_initial.pop("loaded_module_origin_policy", None) - if stable_postflight != stable_initial: - raise FinalAuditError( - "active candidate runtime identity changed during final report audit" - ) - else: - runtime_postflight = None - - canonical_publication_scope = ( - catalog is REPORT_CATALOG - and max_n_final == _FULL_CATALOG_MAX_N_FINAL - and expected_cell_count == _EXPECTED_FULL_CATALOG_CELL_COUNT - and len(declared_cells) == _EXPECTED_FULL_CATALOG_CELL_COUNT - ) - final_gate_complete = ( - replay and verify_render and verify_pdf and canonical_publication_scope - ) - state_counts = Counter(state.value for state in measurement_states.values()) - selected_ids = {cell.cell_id for cell in declared_cells} - catalog_direct_edges = tuple( - edge - for edge in agreement_edges(catalog=catalog) - if edge.candidate.cell_id in selected_ids - and edge.baseline.cell_id in selected_ids - ) - if ( - canonical_publication_scope - and len(catalog_direct_edges) != _EXPECTED_FULL_DIRECT_AGREEMENT_COUNT - ): - raise FinalAuditError( - "canonical publication direct-agreement catalog count differs: " - f"expected={_EXPECTED_FULL_DIRECT_AGREEMENT_COUNT}, " - f"observed={len(catalog_direct_edges)}" - ) - declared_modes: dict[str, int] = defaultdict(int) - measurable_modes: dict[str, int] = defaultdict(int) - static_na_modes: dict[str, int] = defaultdict(int) - static_na_reasons: Counter[str] = Counter() - for cell in declared_cells: - mode = cell.measurement.execution_mode.value - declared_modes[mode] += 1 - reason = catalog.static_na_reason(cell) - if reason is None: - measurable_modes[mode] += 1 - else: - static_na_modes[mode] += 1 - static_na_reasons[reason] += 1 - return { - "kind": "pyamplicol-final-report-audit", - "schema_version": 5, - "status": (ResultStatus.OK.value if final_gate_complete else "incomplete"), - "expected_source_revision": expected_source_revision, - "measurement_source_revision": expected_source_revision, - "measurement_source_lineage": ( - None - if measurement_lineage is None - else { - "schema": measurement_lineage.payload["schema"], - "impact": measurement_lineage.payload["impact"], - "ancestor_revision": measurement_lineage.ancestor_revision, - "ancestor_tree": measurement_lineage.ancestor_tree, - "descendant_revision": measurement_lineage.descendant_revision, - "descendant_tree": measurement_lineage.descendant_tree, - "retained_ancestor_current_count": sum( - source[0] == measurement_lineage.ancestor_revision - for source in measurement_sources.values() - ), - "descendant_current_count": sum( - source[0] == measurement_lineage.descendant_revision - for source in measurement_sources.values() - ), - "invalidated_cell_count": len(measurement_lineage.invalidated_cell_ids), - "recompare_cell_count": len(measurement_lineage.recompare_cell_ids), - } - ), - "publication_revision": publication_lineage["publication_revision"], - "publication_lineage": publication_lineage, - "report_profile": report_profile, - "campaign_policy": active_policy.as_manifest(), - "maximum_n_final": max_n_final, - "selected_cell_count": len(declared_cells), - "declared_cell_count": len(declared_cells), - "measurable_cell_count": len(cells), - "catalog_static_na_cell_count": len(static_na_cells), - "catalog_static_na_reason_counts": dict(sorted(static_na_reasons.items())), - "mode_counts": dict(sorted(declared_modes.items())), - "declared_mode_counts": dict(sorted(declared_modes.items())), - "measurable_mode_counts": dict(sorted(measurable_modes.items())), - "catalog_static_na_mode_counts": dict(sorted(static_na_modes.items())), - "authenticated_current_count": len(cells), - "portable_publication_projection_count": len(published_measurements), - "publication_cache_role": "portable-projection-of-current-result", - "cryptographic_audit_source": "immutable-current-result", - "policy_state_counts": dict(sorted(state_counts.items())), - "policy_complete_cell_count": len(measurement_states), - "hard_resource_censor_count": ( - state_counts[PolicyMeasurementState.GENERATION_LIMIT.value] - + state_counts[PolicyMeasurementState.MEMORY_LIMIT.value] - ), - "resource_frontier_cell_count": state_counts[ - PolicyMeasurementState.RESOURCE_FRONTIER.value - ], - "numerically_evidenced_cell_count": len(successful_cells), - "pyamplicol_measurement_count": len(pyamplicol_cells), - "madgraph_reference_measurement_count": len(madgraph_cells), - "legacy_fresh_oracle_count": len(legacy_cells), - "legacy_oracles_with_inbound_agreement": len(covered_legacy_ids), - "legacy_pointwise_agreement_edge_count": len(legacy_agreement_edges), - "direct_agreement_edge_count": len(direct_edges), - "direct_agreement_catalog_edge_count": len(catalog_direct_edges), - "direct_agreement_policy_unavailable_edge_count": ( - len(catalog_direct_edges) - len(direct_edges) - ), - "direct_agreement_edge_counts": direct_agreement_counts, - "replayed_direct_agreement_edge_count": ( - sum(replayed_direct_agreement_counts.values()) if replay else 0 - ), - "direct_agreement_replay_category_counts": ( - replayed_direct_agreement_counts - if replay - else {category: 0 for category in _DIRECT_REPLAY_CATEGORIES} - ), - "unique_artifact_count": len(grouped), - "arena_record_count": sum( - evidence.arena_record_count for evidence in evidence_by_key.values() - ), - "replay_enabled": replay, - "canonical_publication_scope": canonical_publication_scope, - "final_gate_complete": final_gate_complete, - "audit_scope": ( - "final-numerical-pdf-gate" - if final_gate_complete - else "diagnostic-incomplete" - ), - "pyamplicol_replay_count": len(replayed), - "replayed_measurement_count": len(replayed), - "visible_completeness": visible_completeness.as_dict(), - "render_audit": render_result, - "pdf_audit": dict(pdf_result), - "report_snapshot_lock": "report-writer", - "source_identity_postflight_match": True, - "runtime_identity_postflight_match": ( - True if runtime_postflight is not None else None - ), - } - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description=( - "Audit every record in the complete declared report range at one " - "exact measured source/runtime SHA and an optional report-only " - "publication descendant. Numerical replay is mandatory by default." - ) - ) - parser.add_argument("--repo-root", type=Path, default=Path.cwd()) - parser.add_argument( - "--report-profile", - type=validate_profile_name, - required=True, - ) - parser.add_argument("--expected-source-revision", required=True) - parser.add_argument( - "--publication-revision", - help="require the clean publication checkout to equal this full Git SHA", - ) - parser.add_argument( - "--max-n-final", - type=int, - default=_FULL_CATALOG_MAX_N_FINAL, - ) - parser.add_argument( - "--expected-cell-count", - type=int, - default=_EXPECTED_FULL_CATALOG_CELL_COUNT, - ) - replay = parser.add_mutually_exclusive_group() - replay.add_argument( - "--replay", - dest="replay", - action="store_true", - default=True, - help=( - "load every unique artifact and recompute matrix elements, resolved " - "totals, selectors, and precision-32 comparisons (default)" - ), - ) - replay.add_argument( - "--structural-only", - dest="replay", - action="store_false", - help="authenticate records and artifacts without numerical replay", - ) - return parser - - -def _ensure_exact_cli_python( - repo_root: Path, - argv: Sequence[str], -) -> None: - """Fail closed if this already-imported module was not isolated.""" - - del repo_root, argv - try: - source_only_bytecode_policy() - except RuntimeEvidenceError as error: - raise FinalAuditError( - "direct tools.performance_report.final_audit was imported before " - "source-only Python isolation; invoke " - "'python src/pyamplicol/_profiling_campaign/result_tables.py " - "final-audit ...' or start " - "the module under an already isolated -I -S -B bootstrap" - ) from error - - -def main(argv: Sequence[str] | None = None) -> int: - raw_arguments = tuple(sys.argv[1:] if argv is None else argv) - arguments = _parser().parse_args(raw_arguments) - try: - _ensure_exact_cli_python(arguments.repo_root, raw_arguments) - if arguments.report_profile is None: - raise FinalAuditError("final-audit requires --report-profile") - service = ReportService( - ReportPaths.from_repo( - arguments.repo_root, - profile=arguments.report_profile, - ) - ) - result = audit_final_report( - arguments.repo_root, - expected_source_revision=arguments.expected_source_revision, - expected_publication_revision=arguments.publication_revision, - max_n_final=arguments.max_n_final, - expected_cell_count=arguments.expected_cell_count, - replay=arguments.replay, - service=service, - ) - except Exception as error: - print(f"final report audit failed: {error}", file=sys.stderr) - return 1 - print(json.dumps(result, allow_nan=False, sort_keys=True)) - return 0 if result["final_gate_complete"] is True else 2 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/performance_report/legacy.py b/pyamplicol/tools/performance_report/legacy.py deleted file mode 100644 index c3dfa71964..0000000000 --- a/pyamplicol/tools/performance_report/legacy.py +++ /dev/null @@ -1,2737 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Independent original-AmpliCol adapter for performance-report cells. - -This module deliberately depends on the maintained developer oracle rather -than the historical report driver. It owns only campaign orchestration: -process-row selection, the three legacy measurement paths, bounded adaptive -sampling, compact result shaping, and provenance capture. -""" - -from __future__ import annotations - -import hashlib -import json -import math -import os -import platform -import re -import shutil -import statistics -import subprocess -import sys -import tempfile -import time -from collections.abc import Mapping, Sequence -from contextlib import contextmanager, nullcontext -from dataclasses import asdict, dataclass, is_dataclass -from pathlib import Path -from typing import Any, Protocol - -from .agreements import ( - DIRECT_AGREEMENT_FIELD, - LC_COMMON_COMPONENT_FIELD, - legacy_lc_common_component, - validate_lc_common_component, -) -from .cache import empty_measurement -from .catalog import REPORT_CATALOG -from .models import ( - LEGACY_AMPLICOL_MAX_OPEN_QUARK_LINES, - Accuracy, - CellSpec, - ExecutionMode, - ResultStatus, - Workload, -) -from .phase_state import WorkerPhaseReporter -from .runner import ( - ABSOLUTE_TOLERANCE, - DEFAULT_TARGET_RUNTIME_SECONDS, - RELATIVE_TOLERANCE, - ProfilingTimeLimitError, - SelectorContract, - point_digest, - pointwise_validation, -) -from .selector_policy import ( - fixed_selector_helicity, - selector_color_flow_id, - selector_helicity_id, -) - -DEFAULT_WARMUP_POINTS = 100 -DEFAULT_MIN_POINTS = 100 -DEFAULT_MAX_POINTS = 10_000_000 -DEFAULT_MIN_PROFILE_CHUNKS = 5 -DEFAULT_MAX_PROFILE_CHUNKS = 512 -MAX_OPEN_QUARK_LINES = LEGACY_AMPLICOL_MAX_OPEN_QUARK_LINES -LEGACY_IMODE2_DIAGNOSTIC_FIELD = "legacy_imode2_diagnostic" -LEGACY_IMODE2_DIAGNOSTIC_ABI = "pyamplicol-report-legacy-imode2-diagnostic-v1" -LEGACY_NUMERICAL_AUTHORITY_FIELD = "legacy_numerical_authority" -LEGACY_NUMERICAL_AUTHORITY_ABI = "pyamplicol-report-legacy-numerical-authority-v1" -LEGACY_IMODE2_DIAGNOSTIC_MAX_COLOR_ORDERS = 5_000 -_ORIGINAL_AMPLICOL_BUILD_ENVIRONMENT = {"PDF_BACKEND": "internal"} -_LIBRARY_COLOR_VALUE_RE = re.compile( - r"^AMPICOL_COLOR_PROBE_VALUE\s+(\S+)\s+(\d+)\s+(\d+)\s+" - r"([+\-0-9.EeDd]+)$", - re.MULTILINE, -) -_LIBRARY_COLOR_COMPONENTS_RE = re.compile( - r"^AMPICOL_COLOR_PROBE_COMPONENTS\s+" - r"([+\-0-9.EeDd]+)\s+([+\-0-9.EeDd]+)\s+([+\-0-9.EeDd]+)$", - re.MULTILINE, -) - - -class LegacyAdapterError(RuntimeError): - """The original-AmpliCol measurement contract could not be satisfied.""" - - -@dataclass(frozen=True, slots=True) -class LegacySettings: - target_runtime_seconds: float = DEFAULT_TARGET_RUNTIME_SECONDS - warmup_points: int = DEFAULT_WARMUP_POINTS - minimum_points: int = DEFAULT_MIN_POINTS - maximum_points: int = DEFAULT_MAX_POINTS - minimum_profile_chunks: int = DEFAULT_MIN_PROFILE_CHUNKS - maximum_profile_chunks: int = DEFAULT_MAX_PROFILE_CHUNKS - jobs: int = 1 - repository: Path | None = None - validate_checkout: bool = True - source_revision: str | None = None - profiling_time_limit_seconds: float | None = None - worker_deadline_monotonic: float | None = None - - def __post_init__(self) -> None: - if self.target_runtime_seconds <= 0.0: - raise ValueError("target_runtime_seconds must be positive") - if self.warmup_points < 1: - raise ValueError("warmup_points must be positive") - if self.minimum_points < 1: - raise ValueError("minimum_points must be positive") - if self.maximum_points < self.minimum_points: - raise ValueError("maximum_points must not be below minimum_points") - if self.minimum_profile_chunks < 1: - raise ValueError("minimum_profile_chunks must be positive") - if self.maximum_profile_chunks < self.minimum_profile_chunks: - raise ValueError( - "maximum_profile_chunks must not be below minimum_profile_chunks" - ) - if self.jobs < 1: - raise ValueError("jobs must be positive") - if self.source_revision is not None and re.fullmatch( - r"[0-9a-f]{40}", self.source_revision - ) is None: - raise ValueError("source_revision must be lowercase 40-hex") - for name, value in ( - ("profiling_time_limit_seconds", self.profiling_time_limit_seconds), - ("worker_deadline_monotonic", self.worker_deadline_monotonic), - ): - if value is not None and (not math.isfinite(value) or value <= 0.0): - raise ValueError(f"{name} must be finite and positive when specified") - - -@dataclass(frozen=True, slots=True) -class CommandResult: - args: tuple[str, ...] - cwd: Path - elapsed_seconds: float - returncode: int - stdout: str - stderr: str - environment: Mapping[str, str] - - def as_record(self) -> dict[str, object]: - return { - "args": list(self.args), - "cwd": os.fspath(self.cwd.resolve(strict=False)), - "elapsed_seconds": self.elapsed_seconds, - "returncode": self.returncode, - "environment": dict(self.environment), - } - - -class CommandExecutor(Protocol): - def run( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - environment: Mapping[str, str] | None = None, - ) -> CommandResult: ... - - -class SubprocessExecutor: - """Small command seam used by unit tests and campaign supervision.""" - - def run( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - environment: Mapping[str, str] | None = None, - ) -> CommandResult: - rendered = tuple(os.fspath(item) for item in args) - started = time.perf_counter() - completed = subprocess.run( - rendered, - cwd=cwd, - env=(None if environment is None else {**os.environ, **dict(environment)}), - capture_output=True, - check=False, - text=True, - ) - result = CommandResult( - args=rendered, - cwd=cwd, - elapsed_seconds=time.perf_counter() - started, - returncode=completed.returncode, - stdout=completed.stdout, - stderr=completed.stderr, - environment={} if environment is None else dict(environment), - ) - if completed.returncode != 0: - raise LegacyAdapterError( - f"command exited with {completed.returncode}: " - f"{' '.join(rendered)}\nstdout:\n{completed.stdout}\n" - f"stderr:\n{completed.stderr}" - ) - return result - - -class LegacyApi(Protocol): - default_repository: Path - - def expected_revision(self) -> str: ... - - def validate_checkout(self, repository: Path) -> None: ... - - def compiler_provenance(self, repository: Path) -> object: ... - - def process_pdgs(self, process: str) -> tuple[int, ...]: ... - - def parse_process_file(self, path: Path) -> tuple[object, ...]: ... - - def select_generated_process_entry( - self, - entries: Sequence[object], - *, - generated_process: str, - wanted_pdgs: Sequence[int], - ) -> tuple[object, tuple[object, ...]]: ... - - def source_mapped_color_order( - self, - entry: object, - *, - source_pdgs: Sequence[int], - ) -> tuple[int, ...]: ... - - def ordered_momenta( - self, - source_pdgs: Sequence[int], - target_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], - ) -> tuple[tuple[float, ...], ...]: ... - - def source_to_row_permutation( - self, - source_pdgs: Sequence[int], - target_pdgs: Sequence[int], - ) -> tuple[int, ...]: ... - - def parse_probe_output(self, output: str) -> object: ... - - def run_selected_flow_probe( - self, - repository: Path, - *, - entry: object, - source_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], - helicities: Sequence[int], - points: int, - ) -> object: ... - - def run_color_probe( - self, - repository: Path, - *, - process_file: Path, - entry: object, - source_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], - color_accuracy: str, - helicities: Sequence[int] | None, - ) -> object: ... - - -class MaintainedLegacyApi: - """Thin adapter over ``tools.developer.legacy_amplicol``.""" - - def __init__(self) -> None: - try: - from tools.developer import legacy_amplicol - except ModuleNotFoundError as error: - if error.name not in {"tools", "tools.developer"}: - raise - from ._developer import legacy_amplicol - - self._api = legacy_amplicol - self.default_repository = legacy_amplicol.DEFAULT_REPOSITORY - - def expected_revision(self) -> str: - return str(self._api.expected_revision()) - - def validate_checkout(self, repository: Path) -> None: - self._api.validate_checkout(repository) - - def compiler_provenance(self, repository: Path) -> object: - return self._api._compiler_provenance(repository) - - def process_pdgs(self, process: str) -> tuple[int, ...]: - return tuple(self._api.process_pdgs(process)) - - def parse_process_file(self, path: Path) -> tuple[object, ...]: - return tuple(self._api.parse_process_file(path)) - - def select_generated_process_entry( - self, - entries: Sequence[object], - *, - generated_process: str, - wanted_pdgs: Sequence[int], - ) -> tuple[object, tuple[object, ...]]: - return self._api.select_generated_process_entry( - entries, - generated_process=generated_process, - wanted_pdgs=wanted_pdgs, - ) - - def source_mapped_color_order( - self, - entry: object, - *, - source_pdgs: Sequence[int], - ) -> tuple[int, ...]: - return tuple( - self._api.source_mapped_color_order( - entry, - source_pdgs=source_pdgs, - ) - ) - - def ordered_momenta( - self, - source_pdgs: Sequence[int], - target_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], - ) -> tuple[tuple[float, ...], ...]: - return tuple( - tuple(float(component) for component in vector) - for vector in self._api._ordered_binary64_momenta( - source_pdgs, - target_pdgs, - momenta, - ) - ) - - def source_to_row_permutation( - self, - source_pdgs: Sequence[int], - target_pdgs: Sequence[int], - ) -> tuple[int, ...]: - return tuple(self._api._permutation(source_pdgs, target_pdgs)) - - def parse_probe_output(self, output: str) -> object: - return self._api._parse_probe_output(output) - - def run_selected_flow_probe( - self, - repository: Path, - *, - entry: object, - source_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], - helicities: Sequence[int], - points: int, - ) -> object: - return self._api.run_selected_flow_library_probe( - repository, - entry=entry, - source_pdgs=source_pdgs, - momenta=momenta, - helicities=helicities, - points=points, - ) - - def run_color_probe( - self, - repository: Path, - *, - process_file: Path, - entry: object, - source_pdgs: Sequence[int], - momenta: Sequence[Sequence[float]], - color_accuracy: str, - helicities: Sequence[int] | None, - ) -> object: - return self._api.run_color_probe( - repository, - process_file=process_file, - entry=entry, - source_pdgs=source_pdgs, - momenta=momenta, - color_accuracy=color_accuracy, - helicities=helicities, - ) - - -class ArtifactSnapshotter(Protocol): - def snapshot( - self, - repository: Path, - destination: Path, - *, - executables: Sequence[str], - process_file: Path, - ) -> Path: ... - - -class GeneratedLibrarySnapshotter: - """Copy a generated legacy library into its immutable cell attempt.""" - - def snapshot( - self, - repository: Path, - destination: Path, - *, - executables: Sequence[str], - process_file: Path, - ) -> Path: - if destination.exists(): - shutil.rmtree(destination) - destination.mkdir(parents=True) - libraries = tuple(sorted(repository.glob("libamp*.so"))) - if not libraries: - raise LegacyAdapterError("legacy generation produced no libamp*.so") - for source in libraries: - shutil.copy2(source, destination / source.name) - source_library = repository / "Library" - if not source_library.is_dir(): - raise LegacyAdapterError("legacy generation produced no Library directory") - shutil.copytree(source_library, destination / "Library") - for executable in executables: - source = repository / executable - if not source.is_file(): - raise LegacyAdapterError( - f"legacy generated-library probe is missing: {source}" - ) - shutil.copy2(source, destination / executable) - shutil.copy2(process_file, destination / "processes.txt") - return destination - - -@dataclass(frozen=True, slots=True) -class TimingRow: - label: str - seconds: float - - -@dataclass(frozen=True, slots=True) -class ProfileResult: - points: int - seconds: float - rows: tuple[TimingRow, ...] - record: Mapping[str, object] - probe: object | None - warmup_record: Mapping[str, object] - standard_error_seconds_per_point: float - relative_standard_error: float - - -@dataclass(frozen=True, slots=True) -class _ProfileChunk: - points: int - seconds: float - rows: tuple[TimingRow, ...] - result: CommandResult - probe: object | None - - -def _profile_rate_uncertainty( - chunks: Sequence[_ProfileChunk], -) -> tuple[float, float]: - if len(chunks) < 2: - return 0.0, 0.0 - rates = tuple(chunk.seconds / chunk.points for chunk in chunks) - mean_rate = statistics.fmean(rates) - standard_error = statistics.stdev(rates) / math.sqrt(len(rates)) - relative_standard_error = standard_error / mean_rate if mean_rate > 0.0 else 0.0 - return standard_error, relative_standard_error - - -@dataclass(frozen=True, slots=True) -class _ProcessContext: - process_file: Path - entries: tuple[object, ...] - entry: object - matching_rows: int - source_pdgs: tuple[int, ...] - momenta: tuple[tuple[float, ...], ...] - points: tuple[tuple[tuple[float, ...], ...], ...] - mapped_color_order: tuple[int, ...] - selector_contract: SelectorContract - - -@dataclass(frozen=True, slots=True) -class _SelectedFlowMeasurement: - measurement: dict[str, object] - fixed_helicity_value: float - - -@dataclass(frozen=True, slots=True) -class _ContractedMeasurement: - measurement: dict[str, object] - imode2_diagnostic: dict[str, object] | None - - -def _imode2_diagnostic( - *, - authoritative_source: str, - authoritative_value: float, - imode2_value: float, -) -> dict[str, object]: - absolute = abs(authoritative_value - imode2_value) - return { - "abi": LEGACY_IMODE2_DIAGNOSTIC_ABI, - "certifying": False, - "authoritative_source": authoritative_source, - "authoritative_value": authoritative_value, - "imode2_value": imode2_value, - "absolute_difference": absolute, - "relative_difference": absolute / max(abs(authoritative_value), 1.0e-300), - } - - -def _imode2_component_diagnostic_supported(source_pdgs: Sequence[int]) -> bool: - """Return whether the optional direct fixed-flow diagnostic is bounded.""" - - if _quark_line_count(source_pdgs) != MAX_OPEN_QUARK_LINES: - return True - singlets = sum( - not (1 <= abs(int(pdg)) <= 6 or abs(int(pdg)) == 21) - for pdg in source_pdgs - ) - if singlets: - return False - gluons = sum(abs(int(pdg)) == 21 for pdg in source_pdgs) - color_orders = 3 * math.factorial(gluons) * (gluons + 1) * (gluons + 2) - return color_orders <= LEGACY_IMODE2_DIAGNOSTIC_MAX_COLOR_ORDERS - - -def _parse_generated_library_color_probe_output( - output: str, - *, - expected_accuracy: str, - expected_group: int, - expected_integral: int, -) -> float: - """Parse the compact generated-library probe wire format.""" - - values = _LIBRARY_COLOR_VALUE_RE.findall(output) - component_rows = _LIBRARY_COLOR_COMPONENTS_RE.findall(output) - if len(values) != 1 or len(component_rows) != 1: - raise LegacyAdapterError( - "generated-library color probe must emit exactly one VALUE and " - "one three-component record" - ) - accuracy, raw_group, raw_integral, raw_value = values[0] - - def finite_number(raw: str, *, field: str) -> float: - try: - value = float(raw.replace("D", "E").replace("d", "e")) - except ValueError as error: - raise LegacyAdapterError( - f"generated-library color probe {field} is malformed" - ) from error - if not math.isfinite(value): - raise LegacyAdapterError( - f"generated-library color probe {field} is not finite" - ) - return value - - value = finite_number(raw_value, field="VALUE") - components = tuple( - finite_number(raw, field=f"COMPONENTS[{index}]") - for index, raw in enumerate(component_rows[0]) - ) - if ( - accuracy != expected_accuracy - or int(raw_group) != expected_group - or int(raw_integral) != expected_integral - ): - raise LegacyAdapterError( - "generated-library color probe identity differs from the requested row" - ) - component_index = { - Accuracy.LC.value: 0, - Accuracy.NLC.value: 1, - Accuracy.FULL.value: 2, - }.get(expected_accuracy) - if component_index is None or value != components[component_index]: - raise LegacyAdapterError( - "generated-library color probe VALUE differs from its requested component" - ) - return value - - -def _initial_state_count(process: str) -> int: - initial, separator, final = process.partition(">") - initial_count = len(initial.split()) - final_count = len(final.split()) - if ( - separator != ">" - or process.count(">") != 1 - or initial_count < 1 - or final_count < 1 - ): - raise LegacyAdapterError( - f"cannot identify initial and final legs in process {process!r}" - ) - return initial_count - - -def _colored_roles( - source_pdgs: Sequence[int], - *, - initial_state_count: int, -) -> dict[int, str]: - roles: dict[int, str] = {} - for label, physical_pdg in enumerate(source_pdgs, start=1): - absolute = abs(int(physical_pdg)) - if absolute == 21: - roles[label] = "adjoint" - continue - if not 1 <= absolute <= 6: - continue - outgoing_pdg = ( - -int(physical_pdg) if label <= initial_state_count else int(physical_pdg) - ) - roles[label] = "fundamental" if outgoing_pdg > 0 else "antifundamental" - return roles - - -def _canonical_mapped_color_word( - source_pdgs: Sequence[int], - mapped_color_order: Sequence[int], - *, - initial_state_count: int, -) -> tuple[int, ...]: - """Project a generated-library row onto the canonical public LC axis.""" - - pdgs = tuple(int(pdg) for pdg in source_pdgs) - mapped = tuple(int(label) for label in mapped_color_order) - expected_labels = tuple(range(1, len(pdgs) + 1)) - if tuple(sorted(mapped)) != expected_labels: - raise LegacyAdapterError( - "legacy mapped color row must be a permutation of source labels " - f"1..{len(pdgs)}, got {mapped}" - ) - if not 0 < initial_state_count < len(pdgs): - raise LegacyAdapterError( - "legacy selector canonicalization requires nonempty initial and " - "final states" - ) - roles = _colored_roles(pdgs, initial_state_count=initial_state_count) - return _canonical_colored_word( - pdgs, - tuple(label for label in mapped if label in roles), - initial_state_count=initial_state_count, - ) - - -def _canonical_colored_word( - source_pdgs: Sequence[int], - colored_word: Sequence[int], - *, - initial_state_count: int, -) -> tuple[int, ...]: - """Canonicalize one exact colored-label permutation without padding it.""" - - pdgs = tuple(int(pdg) for pdg in source_pdgs) - word = tuple(colored_word) - if not 0 < initial_state_count < len(pdgs): - raise LegacyAdapterError( - "legacy selector canonicalization requires nonempty initial and " - "final states" - ) - - roles = _colored_roles(pdgs, initial_state_count=initial_state_count) - - if not roles: - raise LegacyAdapterError("selected legacy LC row has no colored word") - if ( - any(isinstance(label, bool) or not isinstance(label, int) for label in word) - or len(word) != len(roles) - or len(set(word)) != len(word) - or set(word) != set(roles) - ): - raise LegacyAdapterError( - "legacy mapped color word must contain every colored source label " - "exactly once" - ) - - fundamental_count = sum(role == "fundamental" for role in roles.values()) - antifundamental_count = sum(role == "antifundamental" for role in roles.values()) - if fundamental_count == antifundamental_count == 0: - return word - if fundamental_count != antifundamental_count: - raise LegacyAdapterError( - "legacy mapped color word has unbalanced fundamental endpoints" - ) - - blocks: list[tuple[int, ...]] = [] - cursor = 0 - while cursor < len(word): - first = word[cursor] - if roles[first] != "fundamental": - raise LegacyAdapterError( - "legacy mapped color word is not a concatenation of " - "[fundamental, adjoints..., antifundamental] blocks" - ) - block = [first] - cursor += 1 - while cursor < len(word) and roles[word[cursor]] == "adjoint": - block.append(word[cursor]) - cursor += 1 - if cursor >= len(word) or roles[word[cursor]] != "antifundamental": - raise LegacyAdapterError( - "legacy mapped color word is not a concatenation of " - "[fundamental, adjoints..., antifundamental] blocks" - ) - block.append(word[cursor]) - cursor += 1 - blocks.append(tuple(block)) - - blocks.sort(key=lambda block: block[0]) - return tuple(label for block in blocks for label in block) - - -def _canonical_process_entry( - api: LegacyApi, - matches: Sequence[object], - *, - preferred_entry: object, - source_pdgs: Sequence[int], - initial_state_count: int, -) -> tuple[object, tuple[int, ...], tuple[int, ...]]: - """Bind the exact-source row selected by the generated process file.""" - - if sum(entry is preferred_entry for entry in matches) != 1: - raise LegacyAdapterError( - "preferred generated-library selector row is missing or ambiguous" - ) - mapped = api.source_mapped_color_order( - preferred_entry, - source_pdgs=source_pdgs, - ) - word = _canonical_mapped_color_word( - source_pdgs, - mapped, - initial_state_count=initial_state_count, - ) - return preferred_entry, mapped, word - - -def adaptive_profile_points( - warmup_seconds: float, - *, - target_runtime_seconds: float, - warmup_points: int = DEFAULT_WARMUP_POINTS, - minimum_points: int = DEFAULT_MIN_POINTS, - maximum_points: int = DEFAULT_MAX_POINTS, -) -> int: - """Choose a bounded integer sample count from one warmup.""" - - if warmup_points < 1 or minimum_points < 1: - raise ValueError("profile point bounds must be positive") - if maximum_points < minimum_points: - raise ValueError("maximum_points must not be below minimum_points") - if not math.isfinite(warmup_seconds) or warmup_seconds <= 0.0: - return minimum_points - estimate = math.ceil(float(target_runtime_seconds) * warmup_points / warmup_seconds) - return max(minimum_points, min(maximum_points, int(estimate))) - - -def _timing_rows(output: str) -> tuple[TimingRow, ...]: - rows: list[TimingRow] = [] - in_summary = False - for line in output.splitlines(): - if "Timing summary" in line: - in_summary = True - continue - if not in_summary: - continue - tokens = line.strip().split() - if len(tokens) < 2: - continue - seconds_index: int | None = None - seconds: float | None = None - for index in range(1, len(tokens)): - try: - candidate = float(tokens[index]) - except ValueError: - continue - seconds_index = index - seconds = candidate - break - if seconds_index is None or seconds is None: - continue - rows.append(TimingRow(" ".join(tokens[:seconds_index]).lower(), seconds)) - return tuple(rows) - - -def _timing_seconds(rows: Sequence[TimingRow], *labels: str) -> float | None: - for label in labels: - wanted = label.strip().lower() - for row in rows: - if row.label == wanted: - return row.seconds - for row in rows: - if wanted in row.label: - return row.seconds - return None - - -def _quark_line_count(pdgs: Sequence[int]) -> int: - return sum(1 for pdg in pdgs if 1 <= abs(int(pdg)) <= 6) // 2 - - -_fixed_helicity = fixed_selector_helicity -_helicity_id = selector_helicity_id - - -def _compiler_payload(value: object) -> object: - if is_dataclass(value): - return asdict(value) - if isinstance(value, Mapping): - return dict(value) - return str(value) - - -def _shared_point( - process: str, -) -> tuple[ - tuple[int, ...], - tuple[tuple[float, ...], ...], - tuple[tuple[tuple[float, ...], ...], ...], -]: - from pyamplicol.models.builtin.validation import generic_validation_point - - particles = tuple(generic_validation_point(process)) - pdgs = tuple(int(particle.pdg) for particle in particles) - momenta = tuple( - tuple(float(component) for component in particle.momentum) - for particle in particles - ) - return pdgs, momenta, (momenta,) - - -def _library_environment(path: Path) -> dict[str, str]: - existing = os.environ.get("LD_LIBRARY_PATH") - root = os.fspath(path.resolve(strict=False)) - return {"LD_LIBRARY_PATH": root if not existing else f"{root}:{existing}"} - - -@contextmanager -def _staged_process_file(repository: Path, process_file: Path): - repository.mkdir(parents=True, exist_ok=True) - target = repository / "processes.txt" - backup = repository / ".processes.txt.pyamplicol-report-backup" - existed = target.exists() - if existed: - shutil.copy2(target, backup) - shutil.copy2(process_file, target) - try: - yield target.name - finally: - if existed: - shutil.move(backup, target) - else: - target.unlink(missing_ok=True) - backup.unlink(missing_ok=True) - - -@contextmanager -def _generation_lepton_pt_cut(repository: Path): - """Keep massless-lepton discovery away from the singular zero-energy map.""" - - common = repository / "common.f03" - original = common.read_text(encoding="utf-8") - modified, count = re.subn( - r"(?im)^(\s*real\(kind=8\),parameter\s*::\s*pTl_min\s*=\s*)[^!\n]+", - r"\g<1>30d0", - original, - ) - if count != 1: - raise LegacyAdapterError("could not configure library-generation lepton pT cut") - common.write_text(modified, encoding="utf-8") - # Rebuild this module and its Make dependants even on coarse timestamps. - common_object = repository / "common.o" - common_object.unlink(missing_ok=True) - try: - yield - finally: - common.write_text(original, encoding="utf-8") - common_object.unlink(missing_ok=True) - - -class LegacyMeasurementAdapter: - """Measure one original-AmpliCol report workload.""" - - def __init__( - self, - *, - api: LegacyApi | None = None, - executor: CommandExecutor | None = None, - snapshotter: ArtifactSnapshotter | None = None, - structural_proof: bool | None = None, - ) -> None: - use_default_api = api is None - self.api = MaintainedLegacyApi() if api is None else api - self.executor = SubprocessExecutor() if executor is None else executor - self.snapshotter = ( - GeneratedLibrarySnapshotter() if snapshotter is None else snapshotter - ) - # Injected APIs are unit-test/developer seams and preserve the historical - # adapter surface unless the caller explicitly supplies real probe - # sources. The production worker constructs the default maintained API, - # for which structural evidence is mandatory and fail-closed. - self.structural_proof = ( - use_default_api if structural_proof is None else structural_proof - ) - - def measure( - self, - cell: CellSpec, - *, - artifact_path: Path, - settings: LegacySettings, - phase_reporter: WorkerPhaseReporter | None = None, - selector_provider: Mapping[str, object] | None = None, - ) -> dict[str, object]: - if cell.measurement.execution_mode is not ExecutionMode.AMPLICOL: - raise LegacyAdapterError("legacy adapter requires an AmpliCol cell") - if selector_provider is not None and not ( - cell.measurement.accuracy is Accuracy.LC - and cell.workload is Workload.ALL_FLOW - ): - raise LegacyAdapterError( - "selector_provider is only valid for LC all-flow AmpliCol cells" - ) - source_pdgs = self.api.process_pdgs(cell.process) - if _quark_line_count(source_pdgs) > MAX_OPEN_QUARK_LINES: - if phase_reporter is not None: - # Unsupported catalog declarations perform no generation, but - # a supervised worker must still close its authenticated phase - # channel rather than remain indefinitely in pre-generation. - with phase_reporter.generation(): - pass - result = self._unsupported_measurement( - f"original AmpliCol supports at most {MAX_OPEN_QUARK_LINES} " - "open quark lines in this report" - ) - if self.structural_proof: - from .legacy_structure import ( - emit_legacy_scope_unavailable_proof, - ) - - artifact_path.mkdir(parents=True, exist_ok=True) - revision = settings.source_revision or self.api.expected_revision() - proof = emit_legacy_scope_unavailable_proof( - cell, - artifact_path=artifact_path, - source_revision=revision, - maximum_open_quark_lines=MAX_OPEN_QUARK_LINES, - observed_open_quark_lines=_quark_line_count(source_pdgs), - ) - result["artifact"] = { - "path": os.fspath(artifact_path), - "legacy_structural_proof": os.fspath(proof), - } - result["provenance"] = { - "method": "original-amplicol-scope-boundary", - "revision": revision, - } - if phase_reporter is not None: - phase_reporter.profiling_started() - phase_reporter.validation_started() - return result - - repository = settings.repository or self.api.default_repository - repository_context: Any = nullcontext() - if self.structural_proof: - from .legacy_structure import legacy_structural_probe_lock - - repository_context = legacy_structural_probe_lock(repository) - with repository_context: - if settings.validate_checkout: - self.api.validate_checkout(repository) - artifact_path.mkdir(parents=True, exist_ok=True) - instrumentation_context: Any = nullcontext(None) - if self.structural_proof: - from .legacy_structure import instrument_legacy_structural_probes - - instrumentation_context = instrument_legacy_structural_probes( - repository, - artifact_path, - ) - with instrumentation_context as instrumentation: - return self._measure_supported( - cell, - repository=repository, - artifact_path=artifact_path, - settings=settings, - instrumentation=instrumentation, - phase_reporter=phase_reporter, - selector_provider=selector_provider, - ) - - def _measure_supported( - self, - cell: CellSpec, - *, - repository: Path, - artifact_path: Path, - settings: LegacySettings, - instrumentation: object | None, - phase_reporter: WorkerPhaseReporter | None, - selector_provider: Mapping[str, object] | None, - ) -> dict[str, object]: - log_path = artifact_path / "legacy.log" - commands: list[dict[str, object]] = [] - context = self._prepare_process( - cell, - repository=repository, - artifact_path=artifact_path, - commands=commands, - log_path=log_path, - ) - provided_common_component = ( - None - if selector_provider is None - else self._selector_provider_common_component( - cell, - context=context, - selector_provider=selector_provider, - commands=commands, - log_path=log_path, - ) - ) - contracted: _ContractedMeasurement | None = None - if cell.measurement.accuracy is Accuracy.LC: - if cell.workload is Workload.SELECTED_FLOW: - selected = self._measure_selected_flow( - cell, - context=context, - repository=repository, - artifact_path=artifact_path, - settings=settings, - commands=commands, - log_path=log_path, - phase_reporter=phase_reporter, - ) - result = selected.measurement - elif cell.workload is Workload.ALL_FLOW: - result = self._measure_all_flow( - cell, - context=context, - repository=repository, - artifact_path=artifact_path, - settings=settings, - commands=commands, - log_path=log_path, - phase_reporter=phase_reporter, - ) - else: - raise LegacyAdapterError("LC AmpliCol cell requires an LC workload") - elif cell.workload is Workload.CONTRACTED: - contracted = self._measure_contracted( - cell, - context=context, - repository=repository, - artifact_path=artifact_path, - settings=settings, - commands=commands, - log_path=log_path, - phase_reporter=phase_reporter, - ) - result = contracted.measurement - else: - raise LegacyAdapterError("NLC/full AmpliCol cells must be contracted") - - process_row = ( - f"group:{int(context.entry.group)}:integral:{int(context.entry.integral)}" - ) - result["artifact"] = { - "path": os.fspath(artifact_path), - "process_row": process_row, - "log_path": os.fspath(log_path), - } - result["selector_contract"] = ( - context.selector_contract.as_dict() - if cell.measurement.accuracy is Accuracy.LC - else None - ) - result["validation"] = { - "status": ResultStatus.OK.value, - "method": "independent-original-amplicol-oracle", - "point_digest": context.selector_contract.point_digest, - DIRECT_AGREEMENT_FIELD: [], - } - authority_source: str | None = None - if cell.workload is Workload.SELECTED_FLOW: - authority_source = "selected-flow-generated-library" - elif ( - cell.workload is Workload.ALL_FLOW - and provided_common_component is not None - ): - authority_source = "all-flow-selected-provider-replay" - elif contracted is not None: - authority_source = ( - "contracted-generated-library" - if contracted.imode2_diagnostic is not None - else "direct-imode2-three-quark-line" - ) - if authority_source is not None: - result["validation"][LEGACY_NUMERICAL_AUTHORITY_FIELD] = { - "abi": LEGACY_NUMERICAL_AUTHORITY_ABI, - "source": authority_source, - } - if contracted is not None and contracted.imode2_diagnostic is not None: - result["validation"][LEGACY_IMODE2_DIAGNOSTIC_FIELD] = ( - contracted.imode2_diagnostic - ) - if cell.measurement.accuracy is Accuracy.LC: - if cell.workload is Workload.SELECTED_FLOW: - common_component = legacy_lc_common_component( - cell, - context.selector_contract, - selected.fixed_helicity_value, - ) - elif provided_common_component is None: - common_component = self._measure_lc_common_component( - cell, - context=context, - repository=repository, - commands=commands, - log_path=log_path, - ) - else: - common_component = provided_common_component - if _imode2_component_diagnostic_supported(context.source_pdgs): - direct_common_component = self._measure_lc_common_component( - cell, - context=context, - repository=repository, - commands=commands, - log_path=log_path, - ) - result["validation"][LEGACY_IMODE2_DIAGNOSTIC_FIELD] = ( - _imode2_diagnostic( - authoritative_source=( - "selected-flow-generated-library-component" - ), - authoritative_value=float(common_component["value"]), - imode2_value=float(direct_common_component["value"]), - ) - ) - result["validation"][LC_COMMON_COMPONENT_FIELD] = common_component - if cell.workload is Workload.ALL_FLOW and ( - float(result["matrix_element"]) <= 0.0 - or float(common_component["value"]) <= 0.0 - ): - raise LegacyAdapterError( - "LC all-flow selector resolved to a structural-zero " - "helicity; choose and remeasure a nonzero fixed-helicity " - "selector before publishing dependent cells" - ) - result["resources"] = { - "monitor": "external-cell-supervisor", - "peak_rss_gib": None, - } - try: - compiler = _compiler_payload(self.api.compiler_provenance(repository)) - except Exception as error: - compiler = { - "status": "unavailable", - "error": str(error), - } - revision = settings.source_revision or self.api.expected_revision() - result["provenance"] = { - **dict(result.get("provenance") or {}), - "method": "original-amplicol-generated-library", - "revision": revision, - "compiler": compiler, - "platform": platform.platform(), - "python": platform.python_version(), - "repository": os.fspath(repository.resolve(strict=False)), - "row_selection_policy": ( - "exact-external-pdg-order-then-process-file-order-v1" - ), - "matching_row_count": context.matching_rows, - "raw_mapped_color_order": list(context.mapped_color_order), - "selector_color_word_policy": ( - "outgoing-open-string-blocks-by-fundamental-source-label-v1" - ), - "commands": commands, - "target_runtime_seconds": settings.target_runtime_seconds, - "warmup_points": settings.warmup_points, - "minimum_points": settings.minimum_points, - "maximum_points": settings.maximum_points, - "minimum_profile_chunks": settings.minimum_profile_chunks, - "maximum_profile_chunks": settings.maximum_profile_chunks, - "generation_timing_is_workload_specific": True, - } - if instrumentation is not None: - from .legacy_structure import emit_legacy_structural_proof - - proof = emit_legacy_structural_proof( - cell, - artifact_path=artifact_path, - process_row=process_row, - source_revision=revision, - repository=repository, - instrumentation=instrumentation, - ) - result["artifact"]["legacy_structural_proof"] = os.fspath(proof) - if result["status"] == ResultStatus.OK.value: - result["failure"] = None - return result - - def _selector_provider_common_component( - self, - cell: CellSpec, - *, - context: _ProcessContext, - selector_provider: Mapping[str, object], - commands: list[dict[str, object]], - log_path: Path, - ) -> dict[str, object]: - if selector_provider.get("status") != ResultStatus.OK.value: - raise LegacyAdapterError( - "LC all-flow selector provider is not a successful measurement" - ) - raw_contract = selector_provider.get("selector_contract") - if not isinstance(raw_contract, Mapping): - raise LegacyAdapterError( - "LC all-flow selector provider has no selector contract" - ) - try: - provider_contract = SelectorContract.from_mapping(raw_contract) - except (TypeError, ValueError) as error: - raise LegacyAdapterError( - "LC all-flow selector provider has an invalid selector contract" - ) from error - if provider_contract != context.selector_contract: - raise LegacyAdapterError( - "LC all-flow selector provider contract does not match the cell" - ) - raw_validation = selector_provider.get("validation") - if ( - not isinstance(raw_validation, Mapping) - or raw_validation.get("status") != ResultStatus.OK.value - ): - raise LegacyAdapterError( - "LC all-flow selector provider has no successful validation" - ) - raw_component = raw_validation.get(LC_COMMON_COMPONENT_FIELD) - try: - validate_lc_common_component( - raw_component, - selector_contract=raw_contract, - ) - except ValueError as error: - raise LegacyAdapterError( - "LC all-flow selector provider has an invalid common component" - ) from error - assert isinstance(raw_component, Mapping) - raw_value = raw_component.get("value") - if ( - isinstance(raw_value, bool) - or not isinstance(raw_value, (int, float)) - or not math.isfinite(float(raw_value)) - ): - raise LegacyAdapterError( - "LC all-flow selector provider common component is not finite" - ) - raw_artifact = selector_provider.get("artifact") - raw_artifact_path = ( - raw_artifact.get("path") if isinstance(raw_artifact, Mapping) else None - ) - if not isinstance(raw_artifact_path, str) or not raw_artifact_path: - raise LegacyAdapterError( - "LC all-flow selector provider has no artifact path" - ) - generated = Path(raw_artifact_path) / "selected-flow-generated-library" - required_paths = ( - generated / "amplicol_library_benchmark", - generated / "processes.txt", - generated / "Library", - ) - if ( - not required_paths[0].is_file() - or not os.access(required_paths[0], os.X_OK) - or not required_paths[1].is_file() - or not required_paths[2].is_dir() - ): - raise LegacyAdapterError( - "LC all-flow selector provider generated-library artifact is incomplete" - ) - provider_entries = self.api.parse_process_file(required_paths[1]) - _provider_entry, provider_matches = self.api.select_generated_process_entry( - provider_entries, - generated_process=cell.process, - wanted_pdgs=context.source_pdgs, - ) - provider_entry, _provider_mapped, provider_word = _canonical_process_entry( - self.api, - provider_matches, - preferred_entry=_provider_entry, - source_pdgs=context.source_pdgs, - initial_state_count=_initial_state_count(cell.process), - ) - if provider_word != context.selector_contract.selected_color_words[0]: - raise LegacyAdapterError( - "LC all-flow selector provider artifact row does not match its " - "selector contract" - ) - fixed_helicities = tuple( - value - for _label, value in context.selector_contract.all_flow_source_helicities - ) - probe_args = ( - "legacy_amplicol.run_selected_flow_library_probe", - os.fspath(generated), - "points=1", - "helicities=" + ",".join(f"{value:+d}" for value in fixed_helicities), - ) - record_index, probe_started = self._record_api_launch( - probe_args, - cwd=generated, - commands=commands, - log_path=log_path, - intended_points=1, - ) - with _temporary_environment(_library_environment(generated)): - probe = self.api.run_selected_flow_probe( - generated, - entry=provider_entry, - source_pdgs=context.source_pdgs, - momenta=context.momenta, - helicities=fixed_helicities, - points=1, - ) - self._finish_api_launch( - record_index, - probe_args, - cwd=generated, - commands=commands, - started=probe_started, - ) - fresh_value = getattr(probe, "fixed_helicity_value", None) - if ( - isinstance(fresh_value, bool) - or not isinstance(fresh_value, (int, float)) - or not math.isfinite(float(fresh_value)) - ): - raise LegacyAdapterError( - "LC all-flow selector provider replay emitted no finite fixed-" - "helicity component" - ) - replay = pointwise_validation( - float(fresh_value), - float(raw_value), - relative_tolerance=RELATIVE_TOLERANCE, - absolute_tolerance=ABSOLUTE_TOLERANCE, - ) - if replay["status"] != ResultStatus.OK.value: - raise LegacyAdapterError( - "LC all-flow selector provider replay disagrees with its recorded " - "common component" - ) - return legacy_lc_common_component( - cell, - context.selector_contract, - float(fresh_value), - ) - - def _measure_lc_common_component( - self, - cell: CellSpec, - *, - context: _ProcessContext, - repository: Path, - commands: list[dict[str, object]], - log_path: Path, - ) -> dict[str, object]: - """Probe the fixed-helicity/fixed-flow component common to both lanes.""" - - if cell.workload is Workload.SELECTED_FLOW: - raise LegacyAdapterError( - "selected-flow LC common components must come from the generated " - "library probe" - ) - helicities = tuple( - value - for _label, value in (context.selector_contract.all_flow_source_helicities) - ) - probe_args = ( - "legacy_amplicol.run_color_probe", - Accuracy.LC.value, - "fixed-helicity", - "points=1", - ) - record_index, started = self._record_api_launch( - probe_args, - cwd=repository, - commands=commands, - log_path=log_path, - intended_points=1, - ) - probe = self.api.run_color_probe( - repository, - process_file=context.process_file, - entry=context.entry, - source_pdgs=context.source_pdgs, - momenta=context.momenta, - color_accuracy=Accuracy.LC.value, - helicities=helicities, - ) - self._finish_api_launch( - record_index, - probe_args, - cwd=repository, - commands=commands, - started=started, - ) - partitions = tuple(getattr(probe, "lc_row_partitions", ())) - if not partitions: - raise LegacyAdapterError( - "direct LC probe emitted no resolved row partitions" - ) - source_to_row = self.api.source_to_row_permutation( - context.source_pdgs, - context.entry.process_pdgs, - ) - if ( - len(source_to_row) != len(context.source_pdgs) - or any( - isinstance(position, bool) or not isinstance(position, int) - for position in source_to_row - ) - or set(source_to_row) != set(range(len(context.source_pdgs))) - ): - raise LegacyAdapterError( - "direct LC probe source-to-row mapping is not a permutation" - ) - wanted_word = context.selector_contract.selected_color_words[0] - matching: list[object] = [] - seen_rows: set[int] = set() - seen_words: set[tuple[int, ...]] = set() - resolved_values: list[float] = [] - for partition in partitions: - raw_permutation = tuple(getattr(partition, "permutation", ())) - row = getattr(partition, "row", None) - if ( - isinstance(row, bool) - or not isinstance(row, int) - or row < 1 - or row in seen_rows - ): - raise LegacyAdapterError( - "direct LC probe emitted an invalid or duplicate row index" - ) - seen_rows.add(row) - if ( - any( - isinstance(position, bool) or not isinstance(position, int) - for position in raw_permutation - ) - or len(set(raw_permutation)) != len(raw_permutation) - or any( - position < 1 or position > len(source_to_row) - for position in raw_permutation - ) - ): - raise LegacyAdapterError( - "direct LC probe emitted an invalid row permutation" - ) - source_word = tuple( - source_to_row[position - 1] + 1 for position in raw_permutation - ) - if source_word in seen_words: - raise LegacyAdapterError( - "direct LC probe emitted a duplicate physical row" - ) - seen_words.add(source_word) - canonical_word = _canonical_colored_word( - context.source_pdgs, - source_word, - initial_state_count=_initial_state_count(cell.process), - ) - raw_value = getattr(partition, "value", None) - if ( - isinstance(raw_value, bool) - or not isinstance(raw_value, (int, float)) - or not math.isfinite(float(raw_value)) - ): - raise LegacyAdapterError( - "direct LC probe emitted a non-finite partition value" - ) - resolved_values.append(float(raw_value)) - if canonical_word == wanted_word: - matching.append(partition) - if sorted(seen_rows) != list(range(1, len(partitions) + 1)): - raise LegacyAdapterError( - "direct LC probe row indices are not a complete contiguous axis" - ) - raw_partition_sum = getattr(probe, "lc_partition_sum", None) - raw_aggregate = getattr(probe, "value", None) - if ( - isinstance(raw_partition_sum, bool) - or not isinstance(raw_partition_sum, (int, float)) - or not math.isfinite(float(raw_partition_sum)) - or isinstance(raw_aggregate, bool) - or not isinstance(raw_aggregate, (int, float)) - or not math.isfinite(float(raw_aggregate)) - ): - raise LegacyAdapterError("direct LC probe aggregate evidence is not finite") - resolved_sum = math.fsum(resolved_values) - if not math.isclose( - resolved_sum, - float(raw_partition_sum), - rel_tol=1.0e-10, - abs_tol=1.0e-12, - ): - raise LegacyAdapterError( - "direct LC probe resolved partitions do not match their sum" - ) - if not math.isclose( - float(raw_partition_sum), - float(raw_aggregate), - rel_tol=1.0e-10, - abs_tol=1.0e-12, - ): - raise LegacyAdapterError( - "direct LC probe partition sum does not match its aggregate" - ) - if len(matching) != 1: - raise LegacyAdapterError( - "direct LC probe did not identify exactly one selected physical row" - ) - raw_value = getattr(matching[0], "value", None) - if ( - isinstance(raw_value, bool) - or not isinstance(raw_value, (int, float)) - or not math.isfinite(float(raw_value)) - ): - raise LegacyAdapterError("direct LC probe selected row has no finite value") - return legacy_lc_common_component( - cell, - context.selector_contract, - float(raw_value), - ) - - def _prepare_process( - self, - cell: CellSpec, - *, - repository: Path, - artifact_path: Path, - commands: list[dict[str, object]], - log_path: Path, - ) -> _ProcessContext: - source_pdgs, momenta, points = _shared_point(cell.process) - declared_pdgs = self.api.process_pdgs(cell.process) - if source_pdgs != declared_pdgs: - raise LegacyAdapterError( - "shared validation point external order differs from the " - "legacy process expression" - ) - family = next( - ( - item - for item in REPORT_CATALOG.process_families - if item.key == cell.process_key - ), - None, - ) - flags: list[str] = [] - if family is not None: - if family.include_3qqbar: - flags.append("-3") - if family.include_cc: - flags.append("-cc") - if family.include_resonance: - flags.append("-res") - process_result = self._run( - [ - sys.executable, - repository / "process_list.py", - "--serial", - *flags, - cell.process, - ], - cwd=artifact_path, - commands=commands, - log_path=log_path, - ) - process_file = artifact_path / "processes.txt" - if not process_file.is_file(): - raise LegacyAdapterError( - "legacy process_list.py did not produce processes.txt; " - f"output={process_result.stdout[-1000:]!r}" - ) - entries = self.api.parse_process_file(process_file) - entry, matches = self.api.select_generated_process_entry( - entries, - generated_process=cell.process, - wanted_pdgs=source_pdgs, - ) - if cell.measurement.accuracy is Accuracy.LC: - entry, mapped, color_word = _canonical_process_entry( - self.api, - matches, - preferred_entry=entry, - source_pdgs=source_pdgs, - initial_state_count=_initial_state_count(cell.process), - ) - else: - mapped = self.api.source_mapped_color_order( - entry, - source_pdgs=source_pdgs, - ) - color_word = _canonical_mapped_color_word( - source_pdgs, - mapped, - initial_state_count=_initial_state_count(cell.process), - ) - helicities = _fixed_helicity(source_pdgs) - contract = SelectorContract( - selected_color_flow_ids=(selector_color_flow_id(color_word),), - selected_color_words=(color_word,), - all_flow_helicity_ids=(_helicity_id(helicities),), - all_flow_source_helicities=tuple( - (index, value) for index, value in enumerate(helicities, start=1) - ), - point_digest=point_digest(points), - ) - return _ProcessContext( - process_file=process_file, - entries=entries, - entry=entry, - matching_rows=len(matches), - source_pdgs=source_pdgs, - momenta=momenta, - points=points, - mapped_color_order=mapped, - selector_contract=contract, - ) - - def _generate_library( - self, - *, - context: _ProcessContext, - repository: Path, - raw_color: bool, - n_final: int, - process_key: str | None, - settings: LegacySettings, - commands: list[dict[str, object]], - log_path: Path, - phase_reporter: WorkerPhaseReporter | None = None, - ) -> float: - # Building the reusable generator and its object graph is campaign - # bootstrap, not per-process generation. Resolve that one-time cost - # before opening the generation timing boundary. ``cleanlib`` updates - # dummy.o, so the ordinary per-process relink below remains measured. - self._run( - ("make", f"-j{settings.jobs}", "amplicol_generate"), - cwd=repository, - commands=commands, - log_path=log_path, - ) - started_index = len(commands) - generation_context = ( - nullcontext() if phase_reporter is None else phase_reporter.generation() - ) - with generation_context: - # Optimized LC library creation discovers numerical-zero and alias - # helicities over ten accepted events. The supplied-momenta probe - # rereads one point and repeats it ten times, which can permanently - # prune a live helicity that is accidentally tiny at that point. - # Use standard, reproducibly seeded integration so those ten events - # carry genuinely distinct kinematics. For a 2-to-1 process, - # legacy gen23 leaves the sole final-state momentum at zero; that - # makes its H_T/2 scale invalid, so use the supplied canonical - # physical point instead. The same generator has a degenerate - # massless 2-to-2 lepton branch: its t range remains identically - # zero and it appends the diagnostic forever. Massless fermion - # helicity zeros are chirality identities rather than accidental - # pointwise zeros, so the non-degenerate canonical point is the - # safe library-construction boundary for these two-body leptonic - # references as well. - # Raw-color creation does not apply this filter and likewise keeps - # its existing single-point path. - final_pdgs = context.source_pdgs[2:] - massless_two_body_leptons = ( - n_final == 2 - and len(final_pdgs) == 2 - and all(11 <= abs(pdg) <= 16 for pdg in final_pdgs) - ) - generation_point_arguments = ( - ("--amplicol_momenta_probe=10", "--amplicol_probe_quiet") - if raw_color or n_final == 1 or massless_two_body_leptons - else ("--seed=101",) - ) - if ( - not raw_color - and n_final >= 4 - and process_key in {"dd_epemzh_jets", "ud_epve_jets"} - ): - # The default gen23 inverse map aborts with smin >= smax - # for these multi-body leptonic families. The existing - # t-channel map avoids that branch while retaining distinct - # seeded discovery points. - generation_point_arguments += ("--phasespace=4",) - momenta_directory = repository / "Utilities" / "ME_checks" - momenta_directory.mkdir(parents=True, exist_ok=True) - for entry in context.entries: - ordered = self.api.ordered_momenta( - context.source_pdgs, - entry.process_pdgs, - context.momenta, - ) - momenta_path = ( - momenta_directory / f"momenta_{entry.group}_{entry.integral}.txt" - ) - momenta_path.write_text( - "\n".join( - " ".join(f"{component:.17e}" for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - with _staged_process_file( - repository, - context.process_file, - ) as process_arg: - for args in ( - ("make", "cleanlib"), - ("make", f"-j{settings.jobs}", "amplicol_generate"), - ( - "./amplicol_generate", - f"--library={'create-raw' if raw_color else 'create'}", - f"--process={process_arg}", - *generation_point_arguments, - "--timing=none", - ), - ("make", f"-j{settings.jobs}", "amplicol_generate_library"), - ): - self._run( - args, - cwd=repository, - commands=commands, - log_path=log_path, - ) - return math.fsum( - float(record["elapsed_seconds"]) for record in commands[started_index:] - ) - - def _measure_selected_flow( - self, - cell: CellSpec, - *, - context: _ProcessContext, - repository: Path, - artifact_path: Path, - settings: LegacySettings, - commands: list[dict[str, object]], - log_path: Path, - phase_reporter: WorkerPhaseReporter | None, - ) -> _SelectedFlowMeasurement: - # Disabled lepton cuts leave singular zero-energy/transfer endpoints - # in gen23, also when the four-lepton family includes jets. - # These cuts only choose ten distinct library-discovery points; restore - # the original module before building the fixed-momenta benchmark. - discovery_cuts = ( - _generation_lepton_pt_cut(repository) - if cell.process_key == "dd_4l_jets" and cell.n_final >= 4 - else nullcontext() - ) - with discovery_cuts: - generation_seconds = self._generate_library( - context=context, - repository=repository, - raw_color=False, - n_final=cell.n_final, - process_key=cell.process_key, - settings=settings, - commands=commands, - log_path=log_path, - phase_reporter=phase_reporter, - ) - self._run( - ("make", f"-j{settings.jobs}", "amplicol_library_benchmark"), - cwd=repository, - commands=commands, - log_path=log_path, - ) - generated = self.snapshotter.snapshot( - repository, - artifact_path / "selected-flow-generated-library", - executables=("amplicol_library_benchmark",), - process_file=context.process_file, - ) - ordered = self.api.ordered_momenta( - context.source_pdgs, - context.entry.process_pdgs, - context.momenta, - ) - # Time the campaign's authenticated point explicitly. The legacy - # no-argument path instead replays an internal random generation point - # and applies a brittle componentwise check to cancellation residues; - # that self-check is not the selected-flow observable validated below. - momenta_path = generated / "profile-momenta.dat" - momenta_path.write_text( - "\n".join( - " ".join(format(component, ".17g") for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - environment = _library_environment(generated) - profile = self._profile( - lambda count: self._invoke_command( - ( - "./amplicol_library_benchmark", - str(count), - str(context.entry.group), - str(context.entry.integral), - momenta_path.name, - ), - cwd=generated, - environment=environment, - commands=commands, - log_path=log_path, - ), - settings=settings, - # Match pyAmpliCol's selected-flow observable: the physical - # helicity sum of squared amplitudes, not amplitude production alone. - timing_labels=("total",), - phase_reporter=phase_reporter, - ) - if phase_reporter is not None: - phase_reporter.validation_started() - with _temporary_environment(environment): - fixed_helicities = tuple( - value - for _label, value in ( - context.selector_contract.all_flow_source_helicities - ) - ) - probe_args = ( - "legacy_amplicol.run_selected_flow_library_probe", - os.fspath(generated), - "points=1", - "helicities=" + ",".join(f"{value:+d}" for value in fixed_helicities), - ) - record_index, probe_started = self._record_api_launch( - probe_args, - cwd=generated, - commands=commands, - log_path=log_path, - intended_points=1, - ) - probe = self.api.run_selected_flow_probe( - generated, - entry=context.entry, - source_pdgs=context.source_pdgs, - momenta=context.momenta, - helicities=fixed_helicities, - points=1, - ) - self._finish_api_launch( - record_index, - probe_args, - cwd=generated, - commands=commands, - started=probe_started, - ) - fixed_helicity_value = getattr(probe, "fixed_helicity_value", None) - if ( - isinstance(fixed_helicity_value, bool) - or not isinstance(fixed_helicity_value, (int, float)) - or not math.isfinite(float(fixed_helicity_value)) - ): - raise LegacyAdapterError( - "selected-flow generated-library probe emitted no finite " - "fixed-helicity component" - ) - return _SelectedFlowMeasurement( - measurement=self._success_measurement( - generation_seconds=generation_seconds, - profile=profile, - matrix_element=float(probe.value), - generation_source="generated-library-create-mode-1", - ), - fixed_helicity_value=float(fixed_helicity_value), - ) - - def _measure_all_flow( - self, - cell: CellSpec, - *, - context: _ProcessContext, - repository: Path, - artifact_path: Path, - settings: LegacySettings, - commands: list[dict[str, object]], - log_path: Path, - phase_reporter: WorkerPhaseReporter | None, - ) -> dict[str, object]: - self._run( - ("make", f"-j{settings.jobs}", "amplicol_color_probe"), - cwd=repository, - commands=commands, - log_path=log_path, - ) - helicities = tuple( - value - for _label, value in (context.selector_contract.all_flow_source_helicities) - ) - with tempfile.TemporaryDirectory(prefix="pac-", dir="/tmp") as raw: - work = Path(raw) - process_copy = work / "processes.txt" - momenta_path = work / "momenta.dat" - shutil.copy2(context.process_file, process_copy) - ordered = self.api.ordered_momenta( - context.source_pdgs, - context.entry.process_pdgs, - context.momenta, - ) - momenta_path.write_text( - "\n".join( - " ".join(format(component, ".17g") for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - permutation = self.api.source_to_row_permutation( - context.source_pdgs, - context.entry.process_pdgs, - ) - ordered_helicities = tuple(helicities[index] for index in permutation) - probe_args = ( - repository / "amplicol_color_probe", - str(1), - str(context.entry.group), - str(context.entry.integral), - "lc", - process_copy, - momenta_path, - *(str(value) for value in ordered_helicities), - ) - if phase_reporter is not None: - _generation_result, generation_rows, generation_probe = ( - self._invoke_generation_probe( - probe_args, - phase_reporter=phase_reporter, - cwd=work, - commands=commands, - log_path=log_path, - ) - ) - profile = self._profile( - lambda count: self._invoke_probe_command( - ( - repository / "amplicol_color_probe", - str(count), - str(context.entry.group), - str(context.entry.integral), - "lc", - process_copy, - momenta_path, - *(str(value) for value in ordered_helicities), - ), - cwd=work, - commands=commands, - log_path=log_path, - ), - settings=settings, - timing_labels=("amplitude evaluation", "total"), - phase_reporter=phase_reporter, - ) - if phase_reporter is not None: - phase_reporter.validation_started() - if phase_reporter is None: - # Preserve the unsupervised adapter's historical single-profile - # behavior. Campaign workers always supply a reporter and use - # the dedicated authenticated generation probe above. - generation_rows = profile.rows - generation_probe = profile.probe - if self.structural_proof: - from .legacy_structure import ( - STRUCTURAL_PROBE_ENVIRONMENT, - write_legacy_structural_probe_output, - ) - - structural, _rows, _probe = self._invoke_probe_command( - probe_args, - cwd=work, - commands=commands, - log_path=log_path, - environment={STRUCTURAL_PROBE_ENVIRONMENT: "1"}, - ) - write_legacy_structural_probe_output( - artifact_path - / "legacy-structural-evidence" - / "direct-structural-probe.stdout", - stdout=structural.stdout, - stderr=structural.stderr, - ) - generation_seconds = _timing_seconds( - generation_rows, - "generation setup", - ) - if generation_seconds is None: - raise LegacyAdapterError( - "direct all-flow probe did not report generation setup" - ) - if generation_probe is None: - raise LegacyAdapterError("direct all-flow probe emitted no value") - return self._success_measurement( - generation_seconds=generation_seconds, - profile=profile, - matrix_element=float(generation_probe.value), - generation_source="direct-imode2-generation-setup", - ) - - def _measure_contracted( - self, - cell: CellSpec, - *, - context: _ProcessContext, - repository: Path, - artifact_path: Path, - settings: LegacySettings, - commands: list[dict[str, object]], - log_path: Path, - phase_reporter: WorkerPhaseReporter | None, - ) -> _ContractedMeasurement: - if _quark_line_count(context.source_pdgs) == MAX_OPEN_QUARK_LINES: - return _ContractedMeasurement( - measurement=self._measure_direct_contracted( - cell, - context=context, - repository=repository, - artifact_path=artifact_path, - settings=settings, - commands=commands, - log_path=log_path, - phase_reporter=phase_reporter, - ), - imode2_diagnostic=None, - ) - generation_seconds = self._generate_library( - context=context, - repository=repository, - raw_color=True, - n_final=cell.n_final, - process_key=cell.process_key, - settings=settings, - commands=commands, - log_path=log_path, - phase_reporter=phase_reporter, - ) - self._run( - ( - "make", - f"-j{settings.jobs}", - "amplicol_color_library_probe", - "amplicol_color_probe", - ), - cwd=repository, - commands=commands, - log_path=log_path, - ) - generated = self.snapshotter.snapshot( - repository, - artifact_path / "contracted-generated-library", - executables=("amplicol_color_library_probe",), - process_file=context.process_file, - ) - ordered = self.api.ordered_momenta( - context.source_pdgs, - context.entry.process_pdgs, - context.momenta, - ) - momenta_path = generated / "momenta.dat" - momenta_path.write_text( - "\n".join( - " ".join(format(component, ".17g") for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - environment = _library_environment(generated) - profile = self._profile( - lambda count: self._invoke_command( - ( - "./amplicol_color_library_probe", - str(count), - str(context.entry.group), - str(context.entry.integral), - cell.measurement.accuracy.value, - momenta_path.name, - ), - cwd=generated, - environment=environment, - commands=commands, - log_path=log_path, - ), - settings=settings, - timing_labels=("total",), - phase_reporter=phase_reporter, - ) - if phase_reporter is not None: - phase_reporter.validation_started() - library_result, _, _ = self._invoke_command( - ( - "./amplicol_color_library_probe", - "1", - str(context.entry.group), - str(context.entry.integral), - cell.measurement.accuracy.value, - momenta_path.name, - ), - cwd=generated, - environment=environment, - commands=commands, - log_path=log_path, - ) - library_value = _parse_generated_library_color_probe_output( - library_result.stdout + "\n" + library_result.stderr, - expected_accuracy=cell.measurement.accuracy.value, - expected_group=int(context.entry.group), - expected_integral=int(context.entry.integral), - ) - if self.structural_proof: - from .legacy_structure import ( - STRUCTURAL_PROBE_ENVIRONMENT, - write_legacy_structural_probe_output, - ) - - structural, _rows, _probe = self._invoke_command( - ( - "./amplicol_color_library_probe", - "1", - str(context.entry.group), - str(context.entry.integral), - cell.measurement.accuracy.value, - momenta_path.name, - ), - cwd=generated, - environment={ - **environment, - STRUCTURAL_PROBE_ENVIRONMENT: "1", - }, - commands=commands, - log_path=log_path, - ) - write_legacy_structural_probe_output( - artifact_path - / "legacy-structural-evidence" - / "contracted-structural-probe.stdout", - stdout=structural.stdout, - stderr=structural.stderr, - ) - probe_args = ( - "legacy_amplicol.run_color_probe", - cell.measurement.accuracy.value, - "points=1", - ) - record_index, probe_started = self._record_api_launch( - probe_args, - cwd=repository, - commands=commands, - log_path=log_path, - intended_points=1, - ) - probe = self.api.run_color_probe( - repository, - process_file=context.process_file, - entry=context.entry, - source_pdgs=context.source_pdgs, - momenta=context.momenta, - color_accuracy=cell.measurement.accuracy.value, - helicities=None, - ) - self._finish_api_launch( - record_index, - probe_args, - cwd=repository, - commands=commands, - started=probe_started, - ) - raw_direct_value = getattr(probe, "value", None) - if ( - isinstance(raw_direct_value, bool) - or not isinstance(raw_direct_value, (int, float)) - or not math.isfinite(float(raw_direct_value)) - ): - raise LegacyAdapterError( - "contracted direct recursive probe emitted no finite value" - ) - direct_value = float(raw_direct_value) - return _ContractedMeasurement( - measurement=self._success_measurement( - generation_seconds=generation_seconds, - profile=profile, - matrix_element=library_value, - generation_source="generated-library-create-raw", - ), - imode2_diagnostic=_imode2_diagnostic( - authoritative_source="dedicated-generated-library-probe", - authoritative_value=library_value, - imode2_value=direct_value, - ), - ) - - def _measure_direct_contracted( - self, - cell: CellSpec, - *, - context: _ProcessContext, - repository: Path, - artifact_path: Path, - settings: LegacySettings, - commands: list[dict[str, object]], - log_path: Path, - phase_reporter: WorkerPhaseReporter | None, - ) -> dict[str, object]: - """Measure the exact direct path for three independent quark lines.""" - - self._run( - ("make", f"-j{settings.jobs}", "amplicol_color_probe"), - cwd=repository, - commands=commands, - log_path=log_path, - ) - with tempfile.TemporaryDirectory(prefix="pac-", dir="/tmp") as raw: - work = Path(raw) - process_copy = work / "processes.txt" - momenta_path = work / "momenta.dat" - shutil.copy2(context.process_file, process_copy) - ordered = self.api.ordered_momenta( - context.source_pdgs, - context.entry.process_pdgs, - context.momenta, - ) - momenta_path.write_text( - "\n".join( - " ".join(format(component, ".17g") for component in vector) - for vector in ordered - ) - + "\n", - encoding="utf-8", - ) - generation_args = ( - repository / "amplicol_color_probe", - "1", - str(context.entry.group), - str(context.entry.integral), - cell.measurement.accuracy.value, - process_copy, - momenta_path, - ) - if phase_reporter is not None: - _generation_result, generation_rows, generation_probe = ( - self._invoke_generation_probe( - generation_args, - phase_reporter=phase_reporter, - cwd=work, - commands=commands, - log_path=log_path, - ) - ) - profile = self._profile( - lambda count: self._invoke_probe_command( - ( - repository / "amplicol_color_probe", - str(count), - str(context.entry.group), - str(context.entry.integral), - cell.measurement.accuracy.value, - process_copy, - momenta_path, - ), - cwd=work, - commands=commands, - log_path=log_path, - ), - settings=settings, - timing_labels=("total",), - phase_reporter=phase_reporter, - ) - if phase_reporter is not None: - phase_reporter.validation_started() - if phase_reporter is None: - generation_rows = profile.rows - generation_probe = profile.probe - if self.structural_proof: - from .legacy_structure import ( - STRUCTURAL_PROBE_ENVIRONMENT, - write_legacy_structural_probe_output, - ) - - structural, _rows, _probe = self._invoke_probe_command( - ( - repository / "amplicol_color_probe", - "1", - str(context.entry.group), - str(context.entry.integral), - cell.measurement.accuracy.value, - process_copy, - momenta_path, - ), - cwd=work, - commands=commands, - log_path=log_path, - environment={STRUCTURAL_PROBE_ENVIRONMENT: "1"}, - ) - write_legacy_structural_probe_output( - artifact_path - / "legacy-structural-evidence" - / "direct-structural-probe.stdout", - stdout=structural.stdout, - stderr=structural.stderr, - ) - generation_seconds = _timing_seconds( - generation_rows, - "generation setup", - ) - if generation_seconds is None: - raise LegacyAdapterError( - "direct three-quark-line probe did not report generation setup" - ) - if generation_probe is None: - raise LegacyAdapterError("direct three-quark-line probe emitted no value") - return self._success_measurement( - generation_seconds=generation_seconds, - profile=profile, - matrix_element=float(generation_probe.value), - generation_source="direct-imode2-three-quark-line-setup", - ) - - def _profile( - self, - invoke: Any, - *, - settings: LegacySettings, - timing_labels: Sequence[str], - phase_reporter: WorkerPhaseReporter | None = None, - ) -> ProfileResult: - if phase_reporter is not None: - phase_reporter.profiling_started() - deadlines = tuple( - deadline - for deadline in ( - settings.worker_deadline_monotonic, - ( - None - if settings.profiling_time_limit_seconds is None - else time.monotonic() + settings.profiling_time_limit_seconds - ), - ) - if deadline is not None - ) - profiling_deadline = min(deadlines) if deadlines else None - - def require_chunk_budget(estimated_seconds: float | None, points: int) -> None: - if profiling_deadline is None: - return - remaining = profiling_deadline - time.monotonic() - if remaining <= 0.0 or ( - estimated_seconds is not None and estimated_seconds > remaining - ): - estimate = ( - "unknown" - if estimated_seconds is None - else f"{estimated_seconds:.6g}s" - ) - raise ProfilingTimeLimitError( - "profiling stage has insufficient remaining budget for " - f"legacy {points}-point chunk: " - f"remaining={max(remaining, 0.0):.6g}s, estimated={estimate}" - ) - # Calibrate with the smallest valid request. A fixed 100-point first - # call can itself run far beyond the intended stage budget for a large - # original-AmpliCol process. - calibration_points = 1 - require_chunk_budget(None, calibration_points) - warmup_result, warmup_rows, _warmup_probe = invoke(calibration_points) - warmup_seconds = _timing_seconds(warmup_rows, *timing_labels) - if warmup_seconds is None or warmup_seconds <= 0.0: - warmup_seconds = warmup_result.elapsed_seconds - chunks: list[_ProfileChunk] = [] - phase = "measurement_chunks" - points = adaptive_profile_points( - warmup_seconds, - target_runtime_seconds=( - settings.target_runtime_seconds / settings.minimum_profile_chunks - ), - warmup_points=calibration_points, - minimum_points=settings.minimum_points, - maximum_points=settings.maximum_points, - ) - measured_seconds = 0.0 - estimated_seconds = warmup_seconds * points / calibration_points - for _index in range(settings.maximum_profile_chunks): - require_chunk_budget(estimated_seconds, points) - result, rows, probe = invoke(points) - seconds = _timing_seconds(rows, *timing_labels) - if seconds is None or seconds <= 0.0: - seconds = result.elapsed_seconds - if not math.isfinite(seconds) or seconds <= 0.0: - raise LegacyAdapterError( - "legacy timing chunk did not report a positive duration" - ) - chunks.append( - _ProfileChunk( - points, - seconds, - tuple(rows), - result, - probe, - ) - ) - measured_seconds = math.fsum(chunk.seconds for chunk in chunks) - minimum_complete = len(chunks) >= settings.minimum_profile_chunks - target_complete = measured_seconds >= settings.target_runtime_seconds - standard_error, relative_standard_error = _profile_rate_uncertainty(chunks) - uncertainty_complete = ( - settings.minimum_profile_chunks == 1 - or ( - math.isfinite(standard_error) - and standard_error > 0.0 - and math.isfinite(relative_standard_error) - and relative_standard_error > 0.0 - ) - ) - if minimum_complete and target_complete and uncertainty_complete: - break - remaining = max( - settings.target_runtime_seconds - measured_seconds, - 0.0, - ) - remaining_minimum_chunks = max( - settings.minimum_profile_chunks - len(chunks), - 1, - ) - next_chunk_target = remaining / remaining_minimum_chunks - estimated = math.ceil(next_chunk_target * points / seconds) - points = max( - settings.minimum_points, - min(settings.maximum_points, int(estimated)), - ) - estimated_seconds = seconds * points / chunks[-1].points - else: - raise LegacyAdapterError( - "legacy timing did not reach its target, minimum sample " - "count, and positive measured uncertainty within " - f"{settings.maximum_profile_chunks} bounded chunks" - ) - - points = sum(chunk.points for chunk in chunks) - seconds = math.fsum(chunk.seconds for chunk in chunks) - if seconds < settings.target_runtime_seconds: - raise LegacyAdapterError( - "legacy timing completed without reaching its target runtime" - ) - standard_error, relative_standard_error = _profile_rate_uncertainty(chunks) - representative = chunks[0] - final = chunks[-1] - return ProfileResult( - points=points, - seconds=seconds, - rows=representative.rows, - record={ - **final.result.as_record(), - "profile_phase": phase, - "target_runtime_seconds": settings.target_runtime_seconds, - "achieved_runtime_seconds": seconds, - "target_runtime_achieved": True, - "chunk_count": len(chunks), - "total_points": points, - "chunks": [ - { - **chunk.result.as_record(), - "points": chunk.points, - "profile_seconds": chunk.seconds, - } - for chunk in chunks - ], - }, - probe=final.probe, - warmup_record=warmup_result.as_record(), - standard_error_seconds_per_point=standard_error, - relative_standard_error=relative_standard_error, - ) - - def _invoke_command( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - commands: list[dict[str, object]], - log_path: Path, - environment: Mapping[str, str] | None = None, - ) -> tuple[CommandResult, tuple[TimingRow, ...], None]: - result = self._run( - args, - cwd=cwd, - environment=environment, - commands=commands, - log_path=log_path, - ) - return result, _timing_rows(result.stdout + "\n" + result.stderr), None - - def _invoke_probe_command( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - commands: list[dict[str, object]], - log_path: Path, - environment: Mapping[str, str] | None = None, - ) -> tuple[CommandResult, tuple[TimingRow, ...], object]: - result = self._run( - args, - cwd=cwd, - environment=environment, - commands=commands, - log_path=log_path, - ) - output = result.stdout + "\n" + result.stderr - return result, _timing_rows(output), self.api.parse_probe_output(output) - - def _invoke_generation_probe( - self, - args: Sequence[str | os.PathLike[str]], - *, - phase_reporter: WorkerPhaseReporter | None, - cwd: Path, - commands: list[dict[str, object]], - log_path: Path, - ) -> tuple[CommandResult, tuple[TimingRow, ...], object]: - """Run one direct generation setup inside the authenticated phase. - - Direct original-AmpliCol probes combine their setup and a single - evaluation in one process. A dedicated one-point invocation gives the - supervisor one bounded generation interval, while the subsequent - adaptive runtime profile remains strictly post-generation. - """ - - generation_context = ( - nullcontext() if phase_reporter is None else phase_reporter.generation() - ) - with generation_context: - return self._invoke_probe_command( - args, - cwd=cwd, - commands=commands, - log_path=log_path, - ) - - def _run( - self, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - commands: list[dict[str, object]], - log_path: Path, - environment: Mapping[str, str] | None = None, - ) -> CommandResult: - rendered = tuple(os.fspath(item) for item in args) - if rendered and rendered[0] == "make": - environment = { - **({} if environment is None else dict(environment)), - **_ORIGINAL_AMPLICOL_BUILD_ENVIRONMENT, - } - launch_record: dict[str, object] = { - "args": list(rendered), - "cwd": os.fspath(cwd.resolve(strict=False)), - "environment": {} if environment is None else dict(environment), - "status": "launching", - } - try: - intended_points = int(rendered[1]) - except (IndexError, ValueError): - intended_points = None - if intended_points is not None and intended_points > 0: - launch_record["intended_points"] = intended_points - record_index = len(commands) - commands.append(launch_record) - with log_path.open("a", encoding="utf-8") as stream: - stream.write(f"$ {' '.join(rendered)}\n") - if intended_points is not None and intended_points > 0: - stream.write(f"[launch] intended_points={intended_points}\n") - stream.flush() - result = self.executor.run(rendered, cwd=cwd, environment=environment) - commands[record_index] = result.as_record() - with log_path.open("a", encoding="utf-8") as stream: - stream.write(result.stdout) - if result.stdout and not result.stdout.endswith("\n"): - stream.write("\n") - stream.write(result.stderr) - if result.stderr and not result.stderr.endswith("\n"): - stream.write("\n") - return result - - @staticmethod - def _record_api_launch( - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - commands: list[dict[str, object]], - log_path: Path, - intended_points: int, - ) -> tuple[int, float]: - rendered = tuple(os.fspath(item) for item in args) - record_index = len(commands) - commands.append( - { - "args": list(rendered), - "cwd": os.fspath(cwd.resolve(strict=False)), - "intended_points": intended_points, - "status": "launching", - } - ) - with log_path.open("a", encoding="utf-8") as stream: - stream.write(f"$ {' '.join(rendered)}\n") - stream.write(f"[launch] intended_points={intended_points}\n") - stream.flush() - return record_index, time.perf_counter() - - @staticmethod - def _finish_api_launch( - record_index: int, - args: Sequence[str | os.PathLike[str]], - *, - cwd: Path, - commands: list[dict[str, object]], - started: float, - ) -> None: - commands[record_index] = { - "args": [os.fspath(item) for item in args], - "cwd": os.fspath(cwd.resolve(strict=False)), - "elapsed_seconds": time.perf_counter() - started, - "returncode": 0, - } - - @staticmethod - def _success_measurement( - *, - generation_seconds: float, - profile: ProfileResult, - matrix_element: float, - generation_source: str, - ) -> dict[str, object]: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": float(generation_seconds), - "wall_seconds_per_point": profile.seconds / profile.points, - "execution_seconds_per_point": profile.seconds / profile.points, - "matrix_element": abs(float(matrix_element)), - "sample_count": profile.points, - "standard_error_seconds_per_point": ( - profile.standard_error_seconds_per_point - ), - "relative_standard_error": profile.relative_standard_error, - "provenance": { - "generation_source": generation_source, - "runtime_profile": { - "measurement": dict(profile.record), - "warmup": dict(profile.warmup_record), - "timing_rows": [ - {"label": row.label, "seconds": row.seconds} - for row in profile.rows - ], - }, - }, - } - ) - return measurement - - @staticmethod - def _unsupported_measurement(message: str) -> dict[str, object]: - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.UNSUPPORTED.value, - "failure": { - "kind": "LegacyOracleScopeError", - "message": message, - }, - } - ) - return measurement - - -@contextmanager -def _temporary_environment(values: Mapping[str, str]): - saved = {key: os.environ.get(key) for key in values} - os.environ.update(values) - try: - yield - finally: - for key, value in saved.items(): - if value is None: - os.environ.pop(key, None) - else: - os.environ[key] = value - - -def measurement_digest(measurement: Mapping[str, object]) -> str: - """Stable helper used when linking a legacy reference from another cache.""" - - payload = json.dumps( - measurement, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return hashlib.sha256(payload).hexdigest() - - -__all__ = [ - "CommandExecutor", - "CommandResult", - "LegacyAdapterError", - "LegacyMeasurementAdapter", - "LegacySettings", - "MaintainedLegacyApi", - "SubprocessExecutor", - "adaptive_profile_points", - "measurement_digest", -] diff --git a/pyamplicol/tools/performance_report/legacy_structure.py b/pyamplicol/tools/performance_report/legacy_structure.py deleted file mode 100644 index c044e141d5..0000000000 --- a/pyamplicol/tools/performance_report/legacy_structure.py +++ /dev/null @@ -1,1106 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Authenticated structural evidence for original-AmpliCol measurements. - -The performance campaign times an unmodified physics path. Structural -evidence is collected separately: - -* generated libraries are parsed from their persisted ``amp*_lib.f03`` files; -* direct imode-2 and contracted-library probes execute one additional point - with diagnostic-only Fortran output enabled. - -The pinned legacy checkout may be shared by manually steered cells. This -module serializes its temporary instrumentation per checkout, adds diagnostics -to the two probe sources, snapshots the exact instrumented sources, and -restores the checkout byte-for-byte after the attempt. The diagnostics do not -alter generation, evaluation, filtering, or contraction. No structural count -is inferred from timing or filled with a fallback value. -""" - -from __future__ import annotations - -import hashlib -import json -import os -import re -import tempfile -from collections import Counter -from collections.abc import Iterator, Mapping -from contextlib import contextmanager -from dataclasses import dataclass -from pathlib import Path - -from .artifacts import _filesystem_lock -from .models import CellSpec, Workload - -LEGACY_PROOF_SCHEMA = "pyamplicol-legacy-final-structural-proof-v1" -LEGACY_SCOPE_REASON = "original-amplicol-open-quark-line-limit" -STRUCTURAL_PROBE_ENVIRONMENT = "AMPICOL_STRUCTURAL_PROBE" -_EVIDENCE_DIRECTORY = "legacy-structural-evidence" -_INDEX_SCHEMA = "pyamplicol-legacy-structural-index-v1" -_SOURCE_CONTRACT_SCHEMA = "pyamplicol-legacy-structural-source-contract-v1" -_INSTRUMENTATION_ABI = "pyamplicol-legacy-probe-structural-diagnostics-v1" -_MAPPING_ABI = "pyamplicol-legacy-structural-object-mapping-v1" -_LOCK_DIRECTORY = "pyamplicol-performance-report-locks" - -_MODULE_NAME = re.compile(r"amp(\d+)_(\d+)_lib\.f03$") -_MODULE_CURRENT = re.compile( - r"dimension\s*\(\s*1\s*:\s*\d+\s*,\s*(\d+)\s*\)\s*::\s*val_c\b", - re.IGNORECASE, -) -_MODULE_INTERACTION = re.compile( - r"dimension\s*\(\s*1\s*:\s*\d+\s*,\s*(\d+)\s*\)\s*::\s*int_c\b", - re.IGNORECASE, -) -_MODULE_AMPLITUDE = re.compile( - r"complex\s*\(\s*kind\s*=\s*8\s*\)\s*,\s*dimension\s*\(\s*(\d+)\s*\)" - r"\s*,\s*intent\s*\(\s*out\s*\)\s*::\s*amps\b", - re.IGNORECASE, -) -_SUBROUTINE = re.compile( - r"^\s*subroutine\s+(\w+)\b(.*?)^\s*end\s+subroutine\s+\1\b", - re.IGNORECASE | re.MULTILINE | re.DOTALL, -) -_EXTERNAL_CURRENT = re.compile( - r"call\s+ext_\w+\s*\(.*?val_c\s*\(\s*1\s*,\s*(\d+)\s*\).*?\)", - re.IGNORECASE | re.DOTALL, -) -_INT1_ARRAY = re.compile( - r"integer\s*,\s*parameter\s*,\s*dimension\s*\(([^)]*)\)\s*::\s*" - r"int1\s*=\s*(?:reshape\s*\(\s*)?\[\s*&?(.*?)\]" - r"(?:\s*,\s*shape\s*=\s*\[[^]]*\]\s*\))?", - re.IGNORECASE | re.DOTALL, -) -_COMBINE_SHAPE = re.compile(r"0:(\d+),(\d+)") -_AMPLITUDE_ASSIGNMENT = re.compile( - r"amps\s*\(\s*(\d+)\s*\)\s*=\s*sum\s*\(\s*" - r"val_c\s*\([^,]+,\s*(\d+)\s*\)\s*\*\s*" - r"val_c\s*\([^,]+,\s*(\d+)\s*\)\s*\)", - re.IGNORECASE, -) -_PROCESS_ROW = re.compile(r"group:(\d+):integral:(\d+)") - -_DIRECT_CURRENT = re.compile( - r"^AMPICOL_STRUCTURAL_CURRENT\s+" - r"(\d+)\s+([01])\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s*$", - re.MULTILINE, -) -_DIRECT_KERNEL = re.compile( - r"^AMPICOL_STRUCTURAL_KERNEL\s+" - r"(\d+)\s+(-?\d+)\s+(-?\d+)\s+(\d+)\s+(\d+)\s+" - r"(\S+)\s+(\S+)\s*$", - re.MULTILINE, -) -_DIRECT_SINGLET = re.compile( - r"^AMPICOL_STRUCTURAL_KERNEL_SINGLET\s+(\d+)\s+(.*?)\s*$", - re.MULTILINE, -) -_DIRECT_ATTACHMENT = re.compile( - r"^AMPICOL_STRUCTURAL_ATTACHMENT\s+" - r"(\d+)\s+(\d+)\s+(\d+)\s+(-?1)\s*$", - re.MULTILINE, -) -_DIRECT_DESTINATION = re.compile( - r"^AMPICOL_STRUCTURAL_DESTINATION\s+" - r"(\d+)\s+(\d+)\s+(\d+)\s*$", - re.MULTILINE, -) -_DIRECT_SUMMARY = { - "current": re.compile(r"^AMPICOL_COLOR_PROBE_CURRENTS\s+(\d+)\s*$", re.M), - "kernel": re.compile(r"^AMPICOL_COLOR_PROBE_VERTICES\s+(\d+)\s*$", re.M), - "destination": re.compile( - r"^AMPICOL_COLOR_PROBE_AMPLITUDES\s+(\d+)\s*$", re.M - ), - "accuracy": re.compile(r"^color_accuracy\s+(\S+)\s*$", re.M), -} -_LIBRARY_CALL = re.compile( - r"^AMPICOL_COLOR_PROBE_LIBRARY_CALLS\s+(\d+)\s+(\d+)\s+(\d+)\s*$", - re.MULTILINE, -) -_LIBRARY_ROW = re.compile( - r"^AMPICOL_COLOR_PROBE_LIBRARY_ROW\s+" - r"(\d+)\s+(\d+)\s+(\d+)\s+(-?1)\s*$", - re.MULTILINE, -) - - -class LegacyStructuralProofError(RuntimeError): - """The real legacy generation/probe evidence is absent or inconsistent.""" - - -@dataclass(frozen=True, slots=True) -class InstrumentationRecord: - """Exact source identities for one temporary diagnostic installation.""" - - abi: str - sources: tuple[Mapping[str, str], ...] - evidence_paths: tuple[Path, ...] - - -@dataclass(frozen=True, slots=True) -class _ModuleStructure: - path: Path - group: int - integral: int - declared_current_count: int - declared_kernel_count: int - source_current_ids: tuple[int, ...] - produced_current_ids: tuple[int, ...] - kernel_term_ids: tuple[int, ...] - combine_routes: tuple[tuple[int, tuple[int, ...]], ...] - amplitude_destinations: tuple[tuple[int, int, int], ...] - - @property - def counts(self) -> dict[str, int]: - return { - "source_current_count": len(self.source_current_ids), - "produced_current_count": len(self.produced_current_ids), - "kernel_evaluation_count": len(self.kernel_term_ids), - "attachment_count": sum( - len(kernel_ids) for _current, kernel_ids in self.combine_routes - ), - "amplitude_destination_count": len(self.amplitude_destinations), - } - - -@dataclass(frozen=True, slots=True) -class _DirectStructure: - accuracy: str - current_map: tuple[tuple[int, int, int, int, int], ...] - kernel_map: tuple[tuple[int, int, int, int, int, str, str], ...] - singlet_map: tuple[tuple[int, tuple[int, ...]], ...] - attachment_map: tuple[tuple[int, int, int, int], ...] - destination_map: tuple[tuple[int, int, int], ...] - - @property - def counts(self) -> dict[str, int]: - return { - "source_current_count": sum(row[1] for row in self.current_map), - "produced_current_count": sum(1 - row[1] for row in self.current_map), - "kernel_evaluation_count": len(self.kernel_map), - "attachment_count": len(self.attachment_map), - "amplitude_destination_count": len(self.destination_map), - } - - -def _sha256_bytes(payload: bytes) -> str: - return hashlib.sha256(payload).hexdigest() - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - while chunk := stream.read(1024 * 1024): - digest.update(chunk) - return digest.hexdigest() - - -def _canonical_bytes(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def _canonical_sha256(value: object) -> str: - return _sha256_bytes(_canonical_bytes(value)) - - -def _atomic_write(path: Path, payload: bytes) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - descriptor, raw = tempfile.mkstemp(prefix=f".{path.name}.", dir=path.parent) - temporary = Path(raw) - try: - with os.fdopen(descriptor, "wb") as stream: - stream.write(payload) - stream.flush() - os.fsync(stream.fileno()) - temporary.replace(path) - except BaseException: - temporary.unlink(missing_ok=True) - raise - - -def _atomic_json(path: Path, value: object) -> None: - _atomic_write( - path, - json.dumps(value, indent=2, sort_keys=True).encode("utf-8") + b"\n", - ) - - -def _replace_once(text: str, old: str, new: str, *, label: str) -> str: - if text.count(old) != 1: - raise LegacyStructuralProofError( - f"legacy probe instrumentation anchor {label!r} occurs " - f"{text.count(old)} times, expected exactly once" - ) - return text.replace(old, new, 1) - - -_DIRECT_SUBROUTINE = r""" - subroutine print_structural_proof() - implicit none - integer :: current_id, kernel_id, route_index, destination_id - integer :: source_flag, route_sign - do current_id=1,amp%n_cur - source_flag = 0 - if (popcnt(amp%current_list(current_id)%bin).eq.1) source_flag = 1 - write (*,'(a,5(1x,i0))') 'AMPICOL_STRUCTURAL_CURRENT',& - current_id,source_flag,amp%current_list(current_id)%type,& - amp%current_list(current_id)%chirality,& - amp%current_list(current_id)%bin - do route_index=1,amp%current_list(current_id)%n_vert - route_sign = 1 - if (amp%current_list(current_id)%vertex_sign(route_index)) route_sign = -1 - write (*,'(a,4(1x,i0))') 'AMPICOL_STRUCTURAL_ATTACHMENT',& - current_id,route_index,& - amp%current_list(current_id)%vertices(route_index),route_sign - enddo - enddo - do kernel_id=1,amp%n_vert - write (*,'(a,5(1x,i0),2(1x,es24.16))') 'AMPICOL_STRUCTURAL_KERNEL',& - kernel_id,amp%interaction_list(kernel_id)%type,& - amp%interaction_list(kernel_id)%chirality,& - amp%interaction_list(kernel_id)%currents(1),& - amp%interaction_list(kernel_id)%currents(2),& - amp%interaction_list(kernel_id)%coupl(1),& - amp%interaction_list(kernel_id)%coupl(2) - if (allocated(amp%interaction_list(kernel_id)%singlet_mv)) then - write (*,'(a,1x,i0,1x,*(i0,1x))')& - 'AMPICOL_STRUCTURAL_KERNEL_SINGLET',kernel_id,& - amp%interaction_list(kernel_id)%singlet_mv(& - 0:amp%interaction_list(kernel_id)%singlet_mv(0)) - else - write (*,'(a,2(1x,i0))')& - 'AMPICOL_STRUCTURAL_KERNEL_SINGLET',kernel_id,0 - endif - enddo - do destination_id=1,amp%n_amps - write (*,'(a,3(1x,i0))') 'AMPICOL_STRUCTURAL_DESTINATION',& - destination_id,amp%curr2amp(1,destination_id),& - amp%curr2amp(2,destination_id) - enddo - end subroutine print_structural_proof - -""" - - -_LIBRARY_SUBROUTINE = r""" - subroutine print_library_call_histogram() - implicit none - integer :: row, previous, call_count - logical :: first_occurrence - do row=1,colour_amp%nColOrd - first_occurrence = .true. - do previous=1,row-1 - if (row_to_group(previous).eq.row_to_group(row) .and.& - row_to_integral(previous).eq.row_to_integral(row)) then - first_occurrence = .false. - exit - endif - enddo - if (.not.first_occurrence) cycle - call_count = count(row_to_group.eq.row_to_group(row) .and.& - row_to_integral.eq.row_to_integral(row)) - write (*,'(a,3(1x,i0))') 'AMPICOL_COLOR_PROBE_LIBRARY_CALLS',& - row_to_group(row),row_to_integral(row),call_count - write (99,'(a,3(1x,i0))') 'AMPICOL_COLOR_PROBE_LIBRARY_CALLS',& - row_to_group(row),row_to_integral(row),call_count - enddo - do row=1,colour_amp%nColOrd - write (*,'(a,4(1x,i0))') 'AMPICOL_COLOR_PROBE_LIBRARY_ROW',& - row,row_to_group(row),row_to_integral(row),row_sign(row) - write (99,'(a,4(1x,i0))') 'AMPICOL_COLOR_PROBE_LIBRARY_ROW',& - row,row_to_group(row),row_to_integral(row),row_sign(row) - enddo - end subroutine print_library_call_histogram - -""" - - -def _instrument_direct_source(text: str) -> str: - if "subroutine print_structural_proof()" in text: - raise LegacyStructuralProofError("direct probe is already instrumented") - text = _replace_once( - text, - " logical :: print_matrix, fixed_helicity\n", - " logical :: print_matrix, fixed_helicity, print_structure\n", - label="direct logical declaration", - ) - text = _replace_once( - text, - " print_matrix = .false.\n fixed_helicity = .false.\n", - " print_matrix = .false.\n" - " fixed_helicity = .false.\n" - " print_structure = .false.\n", - label="direct logical initialization", - ) - text = _replace_once( - text, - " if (trim(adjustl(env_value)).eq.'1') print_matrix = .true.\n" - " env_value = ''\n", - " if (trim(adjustl(env_value)).eq.'1') print_matrix = .true.\n" - " env_value = ''\n" - " call get_environment_variable('AMPICOL_STRUCTURAL_PROBE',env_value)\n" - " if (trim(adjustl(env_value)).eq.'1') print_structure = .true.\n" - " env_value = ''\n", - label="direct structural environment", - ) - text = _replace_once( - text, - " call print_recursion_counts()\n", - " call print_recursion_counts()\n" - " if (print_structure) call print_structural_proof()\n", - label="direct structural call", - ) - return _replace_once( - text, - " subroutine parse_color_accuracy()\n", - _DIRECT_SUBROUTINE + " subroutine parse_color_accuracy()\n", - label="direct structural subroutine", - ) - - -def _instrument_library_source(text: str) -> str: - if "subroutine print_library_call_histogram()" in text: - raise LegacyStructuralProofError("library probe is already instrumented") - text = _replace_once( - text, - " logical :: print_matrix\n", - " logical :: print_matrix, print_structure\n", - label="library logical declaration", - ) - text = _replace_once( - text, - " print_matrix = .false.\n" - " call get_environment_variable('AMPICOL_COLOR_PROBE_MATRIX',env_value)\n", - " print_matrix = .false.\n" - " print_structure = .false.\n" - " call get_environment_variable('AMPICOL_COLOR_PROBE_MATRIX',env_value)\n", - label="library logical initialization", - ) - text = _replace_once( - text, - " if (trim(adjustl(env_value)).eq.'1') print_matrix = .true.\n\n" - " argc = command_argument_count()\n", - " if (trim(adjustl(env_value)).eq.'1') print_matrix = .true.\n" - " env_value = ''\n" - " call get_environment_variable('AMPICOL_STRUCTURAL_PROBE',env_value)\n" - " if (trim(adjustl(env_value)).eq.'1') print_structure = .true.\n\n" - " argc = command_argument_count()\n", - label="library structural environment", - ) - text = _replace_once( - text, - " call build_row_to_integral()\n", - " call build_row_to_integral()\n" - " if (print_structure) call print_library_call_histogram()\n", - label="library structural call", - ) - return _replace_once( - text, - " integer function colour_order_match_sign(jgroup,jint,row,pass,leg_map)\n", - _LIBRARY_SUBROUTINE - + " integer function colour_order_match_sign(jgroup,jint,row,pass,leg_map)\n", - label="library structural subroutine", - ) - - -def _legacy_structural_probe_lock_path(repository: Path) -> Path: - resolved = repository.expanduser().resolve(strict=False) - repository_id = hashlib.sha256(os.fsencode(resolved)).hexdigest() - return ( - Path(tempfile.gettempdir()) - / f"{_LOCK_DIRECTORY}-{os.getuid()}" - / f"{repository_id}.lock" - ) - - -@contextmanager -def legacy_structural_probe_lock(repository: Path) -> Iterator[None]: - """Serialize temporary probe-source edits for one shared legacy checkout.""" - - with _filesystem_lock( - _legacy_structural_probe_lock_path(repository), - timeout=None, - poll_interval=0.05, - ): - yield - - -@contextmanager -def instrument_legacy_structural_probes( - repository: Path, - artifact_path: Path, -) -> Iterator[InstrumentationRecord]: - """Install diagnostic-only probe output and restore exact source bytes.""" - - with ( - legacy_structural_probe_lock(repository), - _instrument_legacy_structural_probes( - repository, - artifact_path, - ) as instrumentation, - ): - yield instrumentation - - -@contextmanager -def _instrument_legacy_structural_probes( - repository: Path, - artifact_path: Path, -) -> Iterator[InstrumentationRecord]: - evidence_root = artifact_path / _EVIDENCE_DIRECTORY - transformers = { - "amplicol_color_probe.f03": _instrument_direct_source, - "amplicol_color_library_probe.f03": _instrument_library_source, - } - originals: dict[Path, tuple[bytes, os.stat_result]] = {} - records: list[Mapping[str, str]] = [] - evidence_paths: list[Path] = [] - try: - for name, transform in transformers.items(): - source = repository / name - if not source.is_file(): - raise LegacyStructuralProofError( - f"pinned legacy probe source is absent: {source}" - ) - original = source.read_bytes() - stat = source.stat() - originals[source] = (original, stat) - try: - patched = transform(original.decode("utf-8")).encode("utf-8") - except UnicodeDecodeError as error: - raise LegacyStructuralProofError( - f"legacy probe source is not UTF-8: {source}" - ) from error - snapshot = evidence_root / f"instrumented-{name}" - _atomic_write(snapshot, patched) - _atomic_write(source, patched) - os.chmod(source, stat.st_mode) - records.append( - { - "path": name, - "original_sha256": _sha256_bytes(original), - "instrumented_sha256": _sha256_bytes(patched), - "instrumented_evidence_path": snapshot.relative_to( - artifact_path - ).as_posix(), - } - ) - evidence_paths.append(snapshot) - yield InstrumentationRecord( - abi=_INSTRUMENTATION_ABI, - sources=tuple(records), - evidence_paths=tuple(evidence_paths), - ) - finally: - for source, (payload, stat) in originals.items(): - _atomic_write(source, payload) - os.chmod(source, stat.st_mode) - os.utime(source, ns=(stat.st_atime_ns, stat.st_mtime_ns)) - - -def _required_match(pattern: re.Pattern[str], text: str, label: str) -> re.Match[str]: - match = pattern.search(text) - if match is None: - raise LegacyStructuralProofError(f"legacy structural evidence lacks {label}") - return match - - -def _parse_module(path: Path) -> _ModuleStructure: - name = _MODULE_NAME.fullmatch(path.name) - if name is None: - raise LegacyStructuralProofError(f"invalid generated module name: {path}") - text = path.read_text(encoding="utf-8") - declared_current_count = int( - _required_match(_MODULE_CURRENT, text, "module current dimension").group(1) - ) - declared_kernel_count = int( - _required_match(_MODULE_INTERACTION, text, "module kernel dimension").group(1) - ) - source_ids = {int(value) for value in _EXTERNAL_CURRENT.findall(text)} - produced_ids: set[int] = set() - kernel_ids: set[int] = set() - referenced_kernel_ids: set[int] = set() - routes: list[tuple[int, tuple[int, ...]]] = [] - for match in _SUBROUTINE.finditer(text): - routine = match.group(1).lower() - array = _INT1_ARRAY.search(match.group(2)) - if array is None: - continue - values = [int(value) for value in re.findall(r"\d+", array.group(2))] - if routine.startswith("vertex_"): - kernel_ids.update(values) - continue - if not routine.startswith("combine_currents"): - continue - shape = _COMBINE_SHAPE.fullmatch(array.group(1).replace(" ", "")) - if shape is None: - raise LegacyStructuralProofError( - f"unsupported combine-route shape in {path}" - ) - stride = int(shape.group(1)) + 1 - column_count = int(shape.group(2)) - if len(values) != stride * column_count: - raise LegacyStructuralProofError( - f"combine-route payload has the wrong size in {path}" - ) - for start in range(0, len(values), stride): - current = values[start] - contributions = tuple(values[start + 1 : start + stride]) - produced_ids.add(current) - referenced_kernel_ids.update(contributions) - routes.append((current, contributions)) - destinations = tuple( - (int(index), int(left), int(right)) - for index, left, right in _AMPLITUDE_ASSIGNMENT.findall(text) - ) - amplitude_count = int( - _required_match(_MODULE_AMPLITUDE, text, "module amplitude dimension").group( - 1 - ) - ) - expected_currents = set(range(1, declared_current_count + 1)) - expected_kernels = set(range(1, declared_kernel_count + 1)) - if ( - source_ids & produced_ids - or source_ids | produced_ids != expected_currents - or kernel_ids != expected_kernels - or referenced_kernel_ids != expected_kernels - or [item[0] for item in destinations] != list(range(1, amplitude_count + 1)) - or any( - left not in expected_currents or right not in expected_currents - for _index, left, right in destinations - ) - ): - raise LegacyStructuralProofError( - f"generated module has sparse/dangling structural objects: {path}" - ) - return _ModuleStructure( - path=path, - group=int(name.group(1)), - integral=int(name.group(2)), - declared_current_count=declared_current_count, - declared_kernel_count=declared_kernel_count, - source_current_ids=tuple(sorted(source_ids)), - produced_current_ids=tuple(sorted(produced_ids)), - kernel_term_ids=tuple(sorted(kernel_ids)), - combine_routes=tuple(routes), - amplitude_destinations=destinations, - ) - - -def _parse_direct(path: Path, expected_accuracy: str) -> _DirectStructure: - text = path.read_text(encoding="utf-8") - current_map = tuple( - tuple(int(value) for value in match) - for match in _DIRECT_CURRENT.findall(text) - ) - kernel_map = tuple( - ( - int(identifier), - int(kind), - int(chirality), - int(left), - int(right), - coupling_left, - coupling_right, - ) - for ( - identifier, - kind, - chirality, - left, - right, - coupling_left, - coupling_right, - ) in _DIRECT_KERNEL.findall(text) - ) - singlet_map = tuple( - ( - int(identifier), - tuple(int(value) for value in values.split()), - ) - for identifier, values in _DIRECT_SINGLET.findall(text) - ) - attachment_map = tuple( - tuple(int(value) for value in match) - for match in _DIRECT_ATTACHMENT.findall(text) - ) - destination_map = tuple( - tuple(int(value) for value in match) - for match in _DIRECT_DESTINATION.findall(text) - ) - counts = { - label: int(_required_match(pattern, text, label).group(1)) - for label, pattern in _DIRECT_SUMMARY.items() - if label != "accuracy" - } - accuracy = _required_match( - _DIRECT_SUMMARY["accuracy"], text, "color accuracy" - ).group(1) - if accuracy != expected_accuracy: - raise LegacyStructuralProofError( - f"direct structural probe accuracy is {accuracy}, " - f"expected {expected_accuracy}" - ) - current_ids = [row[0] for row in current_map] - kernel_ids = [row[0] for row in kernel_map] - singlet_ids = [row[0] for row in singlet_map] - destination_ids = [row[0] for row in destination_map] - current_id_set = set(current_ids) - kernel_id_set = set(kernel_ids) - if ( - current_ids != list(range(1, counts["current"] + 1)) - or kernel_ids != list(range(1, counts["kernel"] + 1)) - or singlet_ids != kernel_ids - or destination_ids != list(range(1, counts["destination"] + 1)) - or any( - left not in current_id_set or right not in current_id_set - for _identifier, _kind, _chirality, left, right, _coupling_a, _coupling_b - in kernel_map - ) - or any( - current not in current_id_set - or kernel not in kernel_id_set - or position < 1 - for current, position, kernel, _sign in attachment_map - ) - or any( - left not in current_id_set or right not in current_id_set - for _destination, left, right in destination_map - ) - or set(range(1, counts["kernel"] + 1)) - != {row[2] for row in attachment_map} - ): - raise LegacyStructuralProofError( - f"direct structural probe has sparse/dangling objects: {path}" - ) - positions: Counter[int] = Counter() - for current, position, _kernel, _sign in attachment_map: - positions[current] += 1 - if positions[current] != position: - raise LegacyStructuralProofError( - f"direct structural attachment positions are not contiguous: {path}" - ) - return _DirectStructure( - accuracy=accuracy, - current_map=current_map, - kernel_map=kernel_map, - singlet_map=singlet_map, - attachment_map=attachment_map, - destination_map=destination_map, - ) - - -def _parse_library_histogram( - path: Path, - modules: Mapping[tuple[int, int], _ModuleStructure], -) -> tuple[tuple[tuple[int, int, int], ...], tuple[tuple[int, int, int, int], ...]]: - text = path.read_text(encoding="utf-8") - histogram = tuple( - tuple(int(value) for value in match) - for match in _LIBRARY_CALL.findall(text) - ) - rows = tuple( - tuple(int(value) for value in match) - for match in _LIBRARY_ROW.findall(text) - ) - if not histogram or not rows: - raise LegacyStructuralProofError( - f"contracted probe lacks exact row-to-module calls: {path}" - ) - row_ids = [row[0] for row in rows] - if row_ids != list(range(1, len(rows) + 1)): - raise LegacyStructuralProofError( - f"contracted probe row axis is not contiguous: {path}" - ) - observed = Counter((group, integral) for _row, group, integral, _sign in rows) - declared = Counter( - {(group, integral): count for group, integral, count in histogram} - ) - if ( - observed != declared - or len(declared) != len(histogram) - or any(key not in modules for key in declared) - ): - raise LegacyStructuralProofError( - f"contracted probe row histogram is incomplete or stale: {path}" - ) - return histogram, rows - - -def _sum_counts( - modules: Mapping[tuple[int, int], _ModuleStructure], - multiplicities: Mapping[tuple[int, int], int], -) -> dict[str, int]: - fields = ( - "source_current_count", - "produced_current_count", - "kernel_evaluation_count", - "attachment_count", - "amplitude_destination_count", - ) - return { - field: sum( - module.counts[field] * multiplicities.get(key, 0) - for key, module in modules.items() - ) - for field in fields - } - - -def _mapping_payload( - modules: Mapping[tuple[int, int], _ModuleStructure], -) -> dict[str, object]: - ordered = [modules[key] for key in sorted(modules)] - return { - "current_map": [ - { - "module": [module.group, module.integral], - "source_ids": list(module.source_current_ids), - "produced_ids": list(module.produced_current_ids), - } - for module in ordered - ], - "kernel_map": [ - { - "module": [module.group, module.integral], - "kernel_term_ids": list(module.kernel_term_ids), - } - for module in ordered - ], - "combine_route_map": [ - { - "module": [module.group, module.integral], - "routes": [ - [current, list(kernel_ids)] - for current, kernel_ids in module.combine_routes - ], - } - for module in ordered - ], - "destination_map": [ - { - "module": [module.group, module.integral], - "destinations": [list(item) for item in module.amplitude_destinations], - } - for module in ordered - ], - } - - -def _direct_mapping_payload(structure: _DirectStructure) -> dict[str, object]: - return { - "current_map": [list(item) for item in structure.current_map], - "kernel_map": [list(item) for item in structure.kernel_map], - "kernel_singlet_map": [ - [identifier, list(values)] for identifier, values in structure.singlet_map - ], - "combine_route_map": [list(item) for item in structure.attachment_map], - "destination_map": [list(item) for item in structure.destination_map], - } - - -def _copy_evidence(source: Path, destination: Path) -> Path: - if not source.is_file(): - raise LegacyStructuralProofError(f"legacy evidence file is absent: {source}") - _atomic_write(destination, source.read_bytes()) - return destination - - -def write_legacy_structural_probe_output( - path: Path, - *, - stdout: str, - stderr: str, -) -> None: - """Atomically preserve one dedicated diagnostic probe transcript.""" - - payload = stdout - if payload and not payload.endswith("\n"): - payload += "\n" - payload += stderr - if payload and not payload.endswith("\n"): - payload += "\n" - _atomic_write(path, payload.encode("utf-8")) - - -def _evidence_inventory( - artifact_path: Path, - paths: set[Path], -) -> list[dict[str, str]]: - root = artifact_path.resolve() - inventory: list[dict[str, str]] = [] - for path in sorted(paths): - resolved = path.resolve() - try: - relative = resolved.relative_to(root) - except ValueError as error: - raise LegacyStructuralProofError( - f"legacy evidence escapes artifact: {path}" - ) from error - if not resolved.is_file(): - raise LegacyStructuralProofError( - f"legacy evidence disappeared before publication: {path}" - ) - inventory.append( - {"path": relative.as_posix(), "sha256": _sha256(resolved)} - ) - if not inventory: - raise LegacyStructuralProofError("legacy evidence inventory is empty") - return inventory - - -def emit_legacy_structural_proof( - cell: CellSpec, - *, - artifact_path: Path, - process_row: str, - source_revision: str, - repository: Path, - instrumentation: InstrumentationRecord, -) -> Path: - """Validate real structural evidence and atomically publish its sidecar.""" - - evidence_root = artifact_path / _EVIDENCE_DIRECTORY - evidence_paths = set(instrumentation.evidence_paths) - process_path = artifact_path / "processes.txt" - log_path = artifact_path / "legacy.log" - evidence_paths.update((process_path, log_path)) - modules_by_key: dict[tuple[int, int], _ModuleStructure] = {} - for path in sorted(artifact_path.rglob("amp*_lib.f03")): - module = _parse_module(path) - key = (module.group, module.integral) - if key in modules_by_key: - raise LegacyStructuralProofError( - f"duplicate generated module identity {key} in {artifact_path}" - ) - modules_by_key[key] = module - evidence_paths.add(path) - - direct_path = evidence_root / "direct-structural-probe.stdout" - contracted_path = evidence_root / "contracted-structural-probe.stdout" - mapping: dict[str, object] - histogram: tuple[tuple[int, int, int], ...] - row_map: tuple[tuple[int, int, int, int], ...] - if direct_path.is_file(): - if modules_by_key: - raise LegacyStructuralProofError( - "direct structural evidence unexpectedly contains generated modules" - ) - direct = _parse_direct(direct_path, cell.measurement.accuracy.value) - mapping = _direct_mapping_payload(direct) - active = direct.counts - static = direct.counts - row = _PROCESS_ROW.fullmatch(process_row) - if row is None: - raise LegacyStructuralProofError( - f"invalid direct-probe process row: {process_row!r}" - ) - histogram = ((int(row.group(1)), int(row.group(2)), 1),) - row_map = ( - (1, int(row.group(1)), int(row.group(2)), 1), - ) - evidence_paths.add(direct_path) - executable = _copy_evidence( - repository / "amplicol_color_probe", - evidence_root / "amplicol_color_probe", - ) - evidence_paths.add(executable) - evidence_kind = "direct-imode2-exact-object-map" - else: - if not modules_by_key: - raise LegacyStructuralProofError( - "generated-library structural proof has no modules" - ) - mapping = _mapping_payload(modules_by_key) - static = _sum_counts( - modules_by_key, - {key: 1 for key in modules_by_key}, - ) - if cell.workload is Workload.SELECTED_FLOW: - row = _PROCESS_ROW.fullmatch(process_row) - if row is None: - raise LegacyStructuralProofError( - f"invalid selected-flow process row: {process_row!r}" - ) - key = (int(row.group(1)), int(row.group(2))) - if key not in modules_by_key: - raise LegacyStructuralProofError( - f"selected-flow generated module is absent: {key}" - ) - histogram = ((key[0], key[1], 1),) - row_map = ((1, key[0], key[1], 1),) - active = _sum_counts(modules_by_key, {key: 1}) - executable = _copy_evidence( - artifact_path - / "selected-flow-generated-library" - / "amplicol_library_benchmark", - evidence_root / "amplicol_library_benchmark", - ) - evidence_paths.add(executable) - evidence_kind = "generated-library-selected-row-exact-object-map" - elif cell.workload is Workload.CONTRACTED: - histogram, row_map = _parse_library_histogram( - contracted_path, - modules_by_key, - ) - active = _sum_counts( - modules_by_key, - {(group, integral): count for group, integral, count in histogram}, - ) - evidence_paths.add(contracted_path) - output = ( - artifact_path - / "contracted-generated-library" - / "amplicol_color_library_probe.output" - ) - evidence_paths.add(output) - executable = ( - artifact_path - / "contracted-generated-library" - / "amplicol_color_library_probe" - ) - evidence_paths.add(executable) - evidence_kind = "generated-library-contracted-exact-call-map" - else: - raise LegacyStructuralProofError( - "generated-library evidence cannot certify this workload" - ) - - mapping_sections = { - "current_object_map_sha256": _canonical_sha256(mapping["current_map"]), - "kernel_term_map_sha256": _canonical_sha256(mapping["kernel_map"]), - "combine_route_map_sha256": _canonical_sha256( - mapping["combine_route_map"] - ), - "amplitude_destination_map_sha256": _canonical_sha256( - mapping["destination_map"] - ), - } - source_contract = { - "schema": _SOURCE_CONTRACT_SCHEMA, - "cell_id": cell.cell_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "process_row": process_row, - "source_revision": source_revision, - "instrumentation": { - "abi": instrumentation.abi, - "sources": list(instrumentation.sources), - }, - "scope": "available", - } - source_contract_path = evidence_root / "source-contract.json" - _atomic_json(source_contract_path, source_contract) - evidence_paths.add(source_contract_path) - source_contract_sha256 = _canonical_sha256(source_contract) - histogram_payload = { - "histogram": [list(item) for item in histogram], - "row_map": [list(item) for item in row_map], - } - index = { - "schema": _INDEX_SCHEMA, - "evidence_kind": evidence_kind, - "active": active, - "static": static, - "object_mapping": { - **mapping_sections, - "source_contract_sha256": source_contract_sha256, - }, - "row_multiplicity": histogram_payload, - "module_count": len(modules_by_key), - } - index_path = evidence_root / "legacy-structural-index.json" - _atomic_json(index_path, index) - evidence_paths.add(index_path) - proof = { - "schema": LEGACY_PROOF_SCHEMA, - "cell_id": cell.cell_id, - "source_revision": source_revision, - "scope": "available", - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "active": active, - "static": static, - "object_mapping": { - "status": "exact", - "abi": _MAPPING_ABI, - "accuracy": cell.measurement.accuracy.value, - **mapping_sections, - "source_contract_sha256": source_contract_sha256, - }, - "row_multiplicity": { - "status": "exact", - "scope": cell.workload.value, - "call_count": sum(count for _group, _integral, count in histogram), - "histogram_sha256": _canonical_sha256(histogram_payload), - }, - "evidence_files": _evidence_inventory(artifact_path, evidence_paths), - } - proof_path = artifact_path / "legacy-structural-proof.json" - _atomic_json(proof_path, proof) - return proof_path - - -def emit_legacy_scope_unavailable_proof( - cell: CellSpec, - *, - artifact_path: Path, - source_revision: str, - maximum_open_quark_lines: int, - observed_open_quark_lines: int, -) -> Path: - """Publish the exact original-AmpliCol scope boundary, with no fake counts.""" - - contract = { - "schema": _SOURCE_CONTRACT_SCHEMA, - "cell_id": cell.cell_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "source_revision": source_revision, - "scope": "unavailable", - "reason": LEGACY_SCOPE_REASON, - "maximum_open_quark_lines": maximum_open_quark_lines, - "observed_open_quark_lines": observed_open_quark_lines, - } - contract_path = artifact_path / _EVIDENCE_DIRECTORY / "source-contract.json" - _atomic_json(contract_path, contract) - proof = { - "schema": LEGACY_PROOF_SCHEMA, - "cell_id": cell.cell_id, - "source_revision": source_revision, - "scope": "unavailable", - "reason": LEGACY_SCOPE_REASON, - "maximum_open_quark_lines": maximum_open_quark_lines, - "observed_open_quark_lines": observed_open_quark_lines, - "source_contract_sha256": _canonical_sha256(contract), - "evidence_files": _evidence_inventory(artifact_path, {contract_path}), - } - proof_path = artifact_path / "legacy-structural-proof.json" - _atomic_json(proof_path, proof) - return proof_path - - -__all__ = [ - "LEGACY_PROOF_SCHEMA", - "LEGACY_SCOPE_REASON", - "STRUCTURAL_PROBE_ENVIRONMENT", - "InstrumentationRecord", - "LegacyStructuralProofError", - "emit_legacy_scope_unavailable_proof", - "emit_legacy_structural_proof", - "instrument_legacy_structural_probes", - "legacy_structural_probe_lock", - "write_legacy_structural_probe_output", -] diff --git a/pyamplicol/tools/performance_report/madgraph.py b/pyamplicol/tools/performance_report/madgraph.py deleted file mode 100644 index b85ba32b86..0000000000 --- a/pyamplicol/tools/performance_report/madgraph.py +++ /dev/null @@ -1,773 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""MadGraph tree-level authority adapter for full-colour report cells. - -The authority is MadGraph's installation-owned, default-restricted UFO ``sm`` -model. The adapter authenticates that model's external parameter identities -and values against the campaign UFO-SM inputs before evaluating either side. -""" - -from __future__ import annotations - -import ast -import hashlib -import importlib.resources -import json -import math -import os -import shutil -import statistics -import time -from collections.abc import Mapping -from contextlib import nullcontext -from dataclasses import dataclass -from pathlib import Path - -from tools.developer.madgraph_correctness import ( - MADGRAPH_DRIVER_SOURCE_SHA256, - CommandExecutor, - CommandResult, - DriverResult, - MadGraphAdapterError, - StandaloneMadGraphRunner, - SubprocessExecutor, -) -from tools.developer.madgraph_correctness import ( - discover_subprocess as _discover_subprocess, -) -from tools.developer.madgraph_correctness import ( - madgraph_command_card as _correctness_command_card, -) -from tools.developer.madgraph_correctness import ( - momenta_rows as _momenta_rows, -) -from tools.developer.madgraph_correctness import ( - reject_failed_generation as _reject_generic_generation, -) -from tools.developer.madgraph_correctness import ( - validate_installation as _validate_base_installation, -) - -from .agreements import DIRECT_AGREEMENT_FIELD -from .cache import empty_measurement -from .measurement import shared_validation_points -from .models import Accuracy, CellSpec, ExecutionMode, ModelKey, ResultStatus, Workload -from .phase_state import WorkerPhaseReporter -from .runner import ( - DEFAULT_TARGET_RUNTIME_SECONDS, - MADGRAPH_RELATIVE_TOLERANCE, - point_digest, -) - -DEFAULT_WARMUP_CALLS = 20 -DEFAULT_MINIMUM_CALLS = 10 -DEFAULT_MAXIMUM_CALLS = 10_000_000 -DEFAULT_MINIMUM_PROFILE_CHUNKS = 5 - - -@dataclass(frozen=True, slots=True) -class MadGraphSettings: - installation: Path - target_runtime_seconds: float = DEFAULT_TARGET_RUNTIME_SECONDS - warmup_calls: int = DEFAULT_WARMUP_CALLS - minimum_calls: int = DEFAULT_MINIMUM_CALLS - maximum_calls: int = DEFAULT_MAXIMUM_CALLS - minimum_profile_chunks: int = DEFAULT_MINIMUM_PROFILE_CHUNKS - json_model_path: Path | None = None - restriction_json_path: Path | None = None - worker_deadline_monotonic: float | None = None - - def __post_init__(self) -> None: - if ( - not math.isfinite(self.target_runtime_seconds) - or self.target_runtime_seconds <= 0.0 - ): - raise ValueError("target_runtime_seconds must be finite and positive") - if self.warmup_calls < DEFAULT_WARMUP_CALLS: - raise ValueError(f"warmup_calls must be at least {DEFAULT_WARMUP_CALLS}") - if self.minimum_calls < 1: - raise ValueError("minimum_calls must be positive") - if self.maximum_calls < self.minimum_calls: - raise ValueError("maximum_calls must not be below minimum_calls") - if self.minimum_profile_chunks < DEFAULT_MINIMUM_PROFILE_CHUNKS: - raise ValueError( - "minimum_profile_chunks must be at least " - f"{DEFAULT_MINIMUM_PROFILE_CHUNKS}" - ) - if self.worker_deadline_monotonic is not None and ( - not math.isfinite(self.worker_deadline_monotonic) - or self.worker_deadline_monotonic <= 0.0 - ): - raise ValueError("worker_deadline_monotonic must be finite and positive") - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _directory_digest(path: Path) -> str: - digest = hashlib.sha256() - files = tuple( - sorted( - candidate - for candidate in path.rglob("*") - if candidate.is_file() - and not candidate.is_symlink() - and "__pycache__" not in candidate.parts - and candidate.suffix != ".pyc" - ) - ) - if not files: - raise MadGraphAdapterError(f"UFO model directory is empty: {path}") - for candidate in files: - relative = candidate.relative_to(path).as_posix().encode("utf-8") - payload = candidate.read_bytes() - digest.update(len(relative).to_bytes(8, "big")) - digest.update(relative) - digest.update(len(payload).to_bytes(8, "big")) - digest.update(payload) - return digest.hexdigest() - - -def _default_json_model_path() -> Path: - resource = importlib.resources.files("pyamplicol").joinpath( - "assets", "models", "json", "sm", "sm.json" - ) - if not isinstance(resource, os.PathLike): - raise MadGraphAdapterError("installed UFO-SM JSON is not filesystem-backed") - try: - result = Path(os.fspath(resource)).resolve(strict=True) - except OSError as error: - raise MadGraphAdapterError("packaged UFO-SM JSON is unavailable") from error - if not result.is_file(): - raise MadGraphAdapterError("packaged UFO-SM JSON is not a regular file") - return result - - -def _default_restriction_json_path() -> Path: - resource = importlib.resources.files("pyamplicol").joinpath( - "assets", "models", "json", "sm", "restrict_default.json" - ) - if not isinstance(resource, os.PathLike): - raise MadGraphAdapterError( - "installed UFO-SM default restriction is not filesystem-backed" - ) - try: - result = Path(os.fspath(resource)).resolve(strict=True) - except OSError as error: - raise MadGraphAdapterError( - "packaged UFO-SM default restriction is unavailable" - ) from error - if not result.is_file(): - raise MadGraphAdapterError( - "packaged UFO-SM default restriction is not a regular file" - ) - return result - - -def _expected_external_parameters( - model_path: Path, - restriction_path: Path, -) -> dict[tuple[str, tuple[int, ...]], tuple[str, float]]: - try: - payload = json.loads(model_path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise MadGraphAdapterError("cannot read packaged UFO-SM JSON") from error - raw_parameters = payload.get("parameters") - if not isinstance(raw_parameters, list): - raise MadGraphAdapterError("packaged UFO-SM JSON has no parameter list") - try: - restriction = json.loads(restriction_path.read_text(encoding="utf-8")) - except (OSError, json.JSONDecodeError) as error: - raise MadGraphAdapterError( - "cannot read packaged UFO-SM default restriction" - ) from error - if not isinstance(restriction, Mapping): - raise MadGraphAdapterError("packaged UFO-SM restriction is not an object") - result: dict[tuple[str, tuple[int, ...]], tuple[str, float]] = {} - observed_names: set[str] = set() - for raw in raw_parameters: - if not isinstance(raw, Mapping) or raw.get("nature") != "external": - continue - block = raw.get("lhablock") - codes = raw.get("lhacode") - name = raw.get("name") - value = raw.get("value") - if ( - not isinstance(block, str) - or not isinstance(codes, list) - or not codes - or any( - isinstance(code, bool) or not isinstance(code, int) for code in codes - ) - or not isinstance(name, str) - or not isinstance(value, list) - or len(value) != 2 - or isinstance(value[0], bool) - or not isinstance(value[0], (int, float)) - or float(value[1]) != 0.0 - ): - raise MadGraphAdapterError( - "packaged UFO-SM external parameter is malformed" - ) - key = (block.upper(), tuple(codes)) - if key in result: - raise MadGraphAdapterError("packaged UFO-SM repeats an external LHA key") - restricted = restriction.get(name) - if ( - not isinstance(restricted, list) - or len(restricted) != 2 - or isinstance(restricted[0], bool) - or not isinstance(restricted[0], (int, float)) - or float(restricted[1]) != 0.0 - ): - raise MadGraphAdapterError( - f"default restriction has no real value for external {name}" - ) - observed_names.add(name) - result[key] = (name, float(restricted[0])) - if not result: - raise MadGraphAdapterError("packaged UFO-SM has no external parameters") - extra = set(restriction).difference(observed_names) - if extra: - raise MadGraphAdapterError( - f"default restriction contains unknown externals: {sorted(extra)!r}" - ) - return result - - -def _ufo_external_parameters( - parameters_path: Path, -) -> dict[tuple[str, tuple[int, ...]], tuple[str, float]]: - """Read literal UFO external declarations without importing model code.""" - - try: - tree = ast.parse(parameters_path.read_text(encoding="utf-8")) - except (OSError, SyntaxError) as error: - raise MadGraphAdapterError("cannot parse MadGraph UFO parameters.py") from error - result: dict[tuple[str, tuple[int, ...]], tuple[str, float]] = {} - for node in tree.body: - if ( - not isinstance(node, ast.Assign) - or len(node.targets) != 1 - or not isinstance(node.targets[0], ast.Name) - or not isinstance(node.value, ast.Call) - or not isinstance(node.value.func, ast.Name) - or node.value.func.id != "Parameter" - ): - continue - keywords = { - keyword.arg: keyword.value - for keyword in node.value.keywords - if keyword.arg is not None - } - try: - nature = ast.literal_eval(keywords["nature"]) - except (KeyError, ValueError, TypeError): - continue - if nature != "external": - continue - try: - name = ast.literal_eval(keywords["name"]) - value = ast.literal_eval(keywords["value"]) - block = ast.literal_eval(keywords["lhablock"]) - codes = ast.literal_eval(keywords["lhacode"]) - except (KeyError, ValueError, TypeError) as error: - raise MadGraphAdapterError( - "MadGraph UFO external parameter is not literal" - ) from error - if ( - not isinstance(name, str) - or not isinstance(block, str) - or isinstance(value, bool) - or not isinstance(value, (int, float)) - or not isinstance(codes, list) - or not codes - or any( - isinstance(code, bool) or not isinstance(code, int) for code in codes - ) - ): - raise MadGraphAdapterError("MadGraph UFO external parameter is malformed") - key = (block.upper(), tuple(codes)) - if key in result: - raise MadGraphAdapterError("MadGraph UFO repeats an external LHA key") - result[key] = (name, float(value)) - if not result: - raise MadGraphAdapterError("MadGraph UFO has no literal external parameters") - return result - - -def _write_exact_param_card( - card_path: Path, - *, - parameters_path: Path, - model_path: Path, - restriction_path: Path, -) -> dict[str, object]: - """Write the exact external LHA inputs within MG's 20-character limit.""" - - expected = _expected_external_parameters(model_path, restriction_path) - madgraph_parameters = _ufo_external_parameters(parameters_path) - expected_identity = {key: value[0] for key, value in expected.items()} - madgraph_identity = {key: value[0] for key, value in madgraph_parameters.items()} - if madgraph_identity != expected_identity: - missing = sorted(set(expected).difference(madgraph_parameters)) - extra = sorted(set(madgraph_parameters).difference(expected)) - changed = tuple( - (key, expected[key][0], madgraph_parameters[key][0]) - for key in sorted(set(expected).intersection(madgraph_parameters)) - if expected[key][0] != madgraph_parameters[key][0] - ) - raise MadGraphAdapterError( - "MadGraph UFO external identities differ from the packaged JSON model: " - f"missing={missing!r}, extra={extra!r}, changed={changed!r}" - ) - blocks = sorted( - {key[0] for key in expected if key[0] != "DECAY"}, - key=lambda name: ( - {"SMINPUTS": 0, "MASS": 1}.get(name, 2), - name, - ), - ) - lines = [ - "######################################################################", - "## Exact packaged UFO-SM external parameters for MadGraph validation", - "######################################################################", - "", - ] - for block in blocks: - lines.append(f"Block {block}") - for key in sorted(candidate for candidate in expected if candidate[0] == block): - name, value = expected[key] - rendered = f"{value:.14e}" - if len(rendered) > 20: - raise MadGraphAdapterError( - f"external parameter {name} exceeds MadGraph's LHA value field" - ) - codes = " ".join(str(code) for code in key[1]) - lines.append(f" {codes} {rendered} # {name}") - lines.append("") - for key in sorted(candidate for candidate in expected if candidate[0] == "DECAY"): - name, value = expected[key] - rendered = f"{value:.14e}" - if len(rendered) > 20: - raise MadGraphAdapterError( - f"external parameter {name} exceeds MadGraph's LHA value field" - ) - codes = " ".join(str(code) for code in key[1]) - lines.append(f"DECAY {codes} {rendered} # {name}") - card_path.write_text("\n".join(lines) + "\n", encoding="ascii") - return _validate_exact_param_card( - card_path, - model_path, - restriction_path, - ) - - -def _validate_exact_param_card( - card_path: Path, - model_path: Path, - restriction_path: Path, -) -> dict[str, object]: - expected = _expected_external_parameters(model_path, restriction_path) - observed: dict[tuple[str, tuple[int, ...]], float] = {} - block: str | None = None - for raw_line in card_path.read_text(encoding="utf-8", errors="strict").splitlines(): - content = raw_line.partition("#")[0].strip() - if not content: - continue - tokens = content.split() - keyword = tokens[0].upper() - if keyword == "BLOCK" and len(tokens) >= 2: - block = tokens[1].upper() - continue - if keyword == "DECAY" and len(tokens) >= 3: - key = ("DECAY", (int(tokens[1]),)) - value_token = tokens[2] - elif block is not None and len(tokens) >= 2: - try: - codes = tuple(int(token) for token in tokens[:-1]) - except ValueError: - continue - key = (block, codes) - value_token = tokens[-1] - else: - continue - if key not in expected: - continue - if key in observed: - raise MadGraphAdapterError( - "exact parameter card repeats an external LHA key" - ) - try: - observed[key] = float(value_token.replace("D", "E").replace("d", "e")) - except ValueError as error: - raise MadGraphAdapterError( - "exact parameter card contains a malformed external value" - ) from error - if set(observed) != set(expected): - missing = sorted(set(expected).difference(observed)) - raise MadGraphAdapterError( - "exact parameter card does not cover packaged UFO-SM externals: " - f"missing={missing!r}" - ) - mismatches = tuple( - (key, expected[key][1], observed[key]) - for key in sorted(expected) - if expected[key][1] != observed[key] - ) - if mismatches: - raise MadGraphAdapterError( - "exact parameter card differs from packaged UFO-SM defaults: " - f"{mismatches!r}" - ) - canonical = json.dumps( - {expected[key][0]: [observed[key], 0.0] for key in sorted(expected)}, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return { - "external_parameter_count": len(expected), - "external_parameters_sha256": hashlib.sha256(canonical).hexdigest(), - "binary64_exact_match": True, - "format": "%.14e", - } - - -def _validate_installation(path: Path) -> tuple[Path, Path, Path]: - installation, launcher = _validate_base_installation(path) - model = installation / "models" / "sm" - required_model_files = (model / "parameters.py", model / "restrict_default.dat") - if ( - model.is_symlink() - or not model.is_dir() - or any(path.is_symlink() or not path.is_file() for path in required_model_files) - ): - raise MadGraphAdapterError( - "MadGraph installation must contain its regular UFO models/sm model" - ) - return installation, launcher, model - - -def madgraph_command_card(process: str) -> str: - return _correctness_command_card(process) - - -def _reject_failed_generation( - result: CommandResult, - standalone: Path, -) -> None: - try: - _reject_generic_generation( - result, - standalone, - expected_model_import="sm", - ) - except MadGraphAdapterError as error: - if "bound exclusively" not in str(error): - raise - raise MadGraphAdapterError( - "standalone process card is not bound exclusively to MadGraph UFO sm" - ) from error - - -class MadGraphMeasurementAdapter(StandaloneMadGraphRunner): - """Generate, drive, and profile one standalone MadGraph matrix element.""" - - @staticmethod - def _assert_deadline(settings: MadGraphSettings) -> None: - deadline = settings.worker_deadline_monotonic - if deadline is not None and time.monotonic() >= deadline: - raise MadGraphAdapterError("MadGraph worker deadline was exhausted") - - def measure( - self, - cell: CellSpec, - *, - artifact_path: Path, - settings: MadGraphSettings, - phase_reporter: WorkerPhaseReporter | None = None, - ) -> dict[str, object]: - if ( - cell.measurement.execution_mode is not ExecutionMode.MADGRAPH - or cell.measurement.model is not ModelKey.UFO_SM - or cell.measurement.accuracy is not Accuracy.FULL - or cell.workload is not Workload.CONTRACTED - ): - raise MadGraphAdapterError( - "MadGraph adapter requires a contracted full-colour UFO-SM " - "reference cell" - ) - installation, launcher, madgraph_model = _validate_installation( - settings.installation - ) - json_model_path = settings.json_model_path or _default_json_model_path() - restriction_json_path = ( - settings.restriction_json_path or _default_restriction_json_path() - ) - artifact_path.mkdir(parents=True, exist_ok=True) - log_path = artifact_path / "madgraph.log" - standalone = artifact_path / "standalone" - model_record = { - "name": "sm", - "source_directory": os.fspath(madgraph_model), - "source_sha256": _directory_digest(madgraph_model), - } - command_card = madgraph_command_card(cell.process) - command_card_path = artifact_path / "madgraph_command_card.dat" - command_card_path.write_text(command_card, encoding="utf-8") - commands: list[dict[str, object]] = [] - - generation_context = ( - nullcontext() if phase_reporter is None else phase_reporter.generation() - ) - with generation_context: - self._assert_deadline(settings) - generation = self._run_logged( - self.executor, - (launcher, command_card_path), - cwd=artifact_path, - log_path=log_path, - ) - commands.append(generation.record()) - _reject_failed_generation(generation, standalone) - restriction_card_record = _validate_exact_param_card( - madgraph_model / "restrict_default.dat", - json_model_path, - restriction_json_path, - ) - param_card = standalone / "Cards" / "param_card.dat" - rounded_param_card = ( - standalone / "Cards" / "param_card.madgraph-rounded.dat" - ) - shutil.copy2(param_card, rounded_param_card) - exact_param_card_record = _write_exact_param_card( - param_card, - parameters_path=madgraph_model / "parameters.py", - model_path=json_model_path, - restriction_path=restriction_json_path, - ) - subprocess_dir = _discover_subprocess(standalone) - executable, compilation, driver_digest = self._compile_driver( - standalone, - subprocess_dir, - log_path=log_path, - ) - commands.append(compilation.record()) - - validation_points = shared_validation_points(cell.process) - momenta = _momenta_rows(validation_points) - momenta_path = subprocess_dir / "pyamplicol_momenta.dat" - momenta_path.write_text( - "".join( - " ".join(format(component, ".17e") for component in row) + "\n" - for row in momenta - ), - encoding="ascii", - ) - if phase_reporter is not None: - phase_reporter.profiling_started() - - self._assert_deadline(settings) - calibration = self._run_driver( - executable, - subprocess_dir=subprocess_dir, - momenta_path=momenta_path, - points=settings.minimum_calls, - warmup_calls=settings.warmup_calls, - log_path=log_path, - ) - commands.append(calibration.command.record()) - calibration_seconds = calibration.seconds - calibration_calls = calibration.points - target_chunk_seconds = ( - settings.target_runtime_seconds / settings.minimum_profile_chunks - ) - calibration_target_seconds = min(0.1, 0.25 * target_chunk_seconds) - while ( - calibration_seconds < calibration_target_seconds - and calibration_calls < settings.maximum_calls - ): - if calibration_seconds <= 0.0: - next_calls = calibration_calls * 10 - else: - next_calls = math.ceil( - 1.25 - * calibration_calls - * calibration_target_seconds - / calibration_seconds - ) - calibration_calls = min( - settings.maximum_calls, - max(calibration_calls + 1, next_calls), - ) - calibration = self._run_driver( - executable, - subprocess_dir=subprocess_dir, - momenta_path=momenta_path, - points=calibration_calls, - warmup_calls=settings.warmup_calls, - log_path=log_path, - ) - commands.append(calibration.command.record()) - calibration_seconds = calibration.seconds - if calibration_seconds <= 0.0: - raise MadGraphAdapterError("MadGraph driver timer did not advance") - seconds_per_call = calibration_seconds / calibration.points - profile_calls = max( - settings.minimum_calls, - min( - settings.maximum_calls, - math.ceil(target_chunk_seconds / seconds_per_call), - ), - ) - chunks: list[DriverResult] = [] - attempted_profile_chunks = 0 - zero_duration_profile_chunks = 0 - while not chunks: - attempt: list[DriverResult] = [] - for _ in range(settings.minimum_profile_chunks): - self._assert_deadline(settings) - chunk = self._run_driver( - executable, - subprocess_dir=subprocess_dir, - momenta_path=momenta_path, - points=profile_calls, - warmup_calls=settings.warmup_calls, - log_path=log_path, - ) - attempted_profile_chunks += 1 - commands.append(chunk.command.record()) - if not math.isclose( - chunk.value, - calibration.value, - rel_tol=5.0e-13, - abs_tol=1.0e-300, - ): - raise MadGraphAdapterError( - "MadGraph driver value changed between independent " - "profile chunks" - ) - if chunk.seconds <= 0.0: - zero_duration_profile_chunks += 1 - break - attempt.append(chunk) - if len(attempt) == settings.minimum_profile_chunks: - chunks = attempt - break - if profile_calls >= settings.maximum_calls: - raise MadGraphAdapterError( - "MadGraph profile timer did not advance at maximum_calls" - ) - profile_calls = min( - settings.maximum_calls, - max(profile_calls + 1, profile_calls * 10), - ) - if phase_reporter is not None: - phase_reporter.validation_started() - - total_points = sum(chunk.points for chunk in chunks) - total_seconds = math.fsum(chunk.seconds for chunk in chunks) - if total_seconds <= 0.0: - raise MadGraphAdapterError("MadGraph profile accumulated no positive time") - rates = tuple(chunk.seconds / chunk.points for chunk in chunks) - mean_rate = total_seconds / total_points - standard_error = statistics.stdev(rates) / math.sqrt(len(rates)) - relative_standard_error = standard_error / mean_rate - version_path = installation / "VERSION" - - measurement = empty_measurement() - measurement.update( - { - "status": ResultStatus.OK.value, - "generation_seconds": generation.elapsed_seconds, - "wall_seconds_per_point": mean_rate, - "execution_seconds_per_point": mean_rate, - "matrix_element": calibration.value, - "sample_count": total_points, - "standard_error_seconds_per_point": standard_error, - "relative_standard_error": relative_standard_error, - "artifact": { - "path": os.fspath(artifact_path), - "standalone": os.fspath(standalone), - "subprocess": os.fspath(subprocess_dir.relative_to(artifact_path)), - "log_path": os.fspath(log_path), - }, - "selector_contract": None, - "validation": { - "status": ResultStatus.OK.value, - "method": "independent-madgraph-tree-level-oracle", - "point_digest": point_digest(validation_points), - DIRECT_AGREEMENT_FIELD: [], - }, - "resources": { - "monitor": "external-cell-supervisor", - "peak_rss_gib": None, - }, - "provenance": { - "method": "madgraph-standalone-custom-fortran-driver", - "installation": os.fspath(installation), - "version": ( - None - if not version_path.is_file() - else version_path.read_text( - encoding="utf-8", errors="replace" - ).strip() - ), - "version_sha256": ( - None if not version_path.is_file() else _sha256(version_path) - ), - "model": model_record, - "default_restriction": restriction_card_record, - "command_card": command_card, - "command_card_sha256": _sha256(command_card_path), - "process_card_sha256": _sha256( - standalone / "Cards" / "proc_card_mg5.dat" - ), - "param_card_sha256": _sha256(param_card), - "madgraph_rounded_param_card_sha256": _sha256(rounded_param_card), - "exact_param_card": exact_param_card_record, - "driver_sha256": driver_digest, - "driver_compile_seconds": compilation.elapsed_seconds, - "driver_timer": "fortran-system-clock-int64", - "driver_warmup_calls": settings.warmup_calls, - "report_momenta": validation_points, - "profile_chunk_count": len(chunks), - "profile_calls_per_chunk": profile_calls, - "profile_attempted_chunk_count": attempted_profile_chunks, - "profile_discarded_chunk_count": ( - attempted_profile_chunks - len(chunks) - ), - "profile_zero_duration_chunk_count": (zero_duration_profile_chunks), - "commands": commands, - "generation_timing_scope": ( - "generate-output-standalone-launch-force" - ), - "generation_includes_madgraph_compilation": True, - "driver_compilation_in_generation_seconds": False, - }, - "failure": None, - } - ) - return measurement - - -__all__ = [ - "DEFAULT_MAXIMUM_CALLS", - "DEFAULT_MINIMUM_CALLS", - "DEFAULT_MINIMUM_PROFILE_CHUNKS", - "DEFAULT_WARMUP_CALLS", - "MADGRAPH_DRIVER_SOURCE_SHA256", - "MADGRAPH_RELATIVE_TOLERANCE", - "CommandExecutor", - "CommandResult", - "MadGraphAdapterError", - "MadGraphMeasurementAdapter", - "MadGraphSettings", - "SubprocessExecutor", - "madgraph_command_card", -] diff --git a/pyamplicol/tools/performance_report/manual_campaign.py b/pyamplicol/tools/performance_report/manual_campaign.py deleted file mode 100644 index eefc71e819..0000000000 --- a/pyamplicol/tools/performance_report/manual_campaign.py +++ /dev/null @@ -1,10126 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Human-steerable pyAmpliCol profiling campaign. - -This module is intentionally a thin controller. Cell definition, dependency -planning, generation, profiling, atomic attempt publication, rendering, and PDF -compilation remain owned by the existing performance-report and public -``pyamplicol`` command APIs. -""" - -from __future__ import annotations - -import argparse -import base64 -import copy -import difflib -import errno -import hashlib -import importlib -import json -import math -import os -import re -import shlex -import shutil -import stat -import statistics -import struct -import subprocess -import sys -import tempfile -import textwrap -import threading -import time -import uuid -import zlib -from collections import Counter -from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence -from contextlib import contextmanager, suppress -from dataclasses import asdict, dataclass, field -from datetime import UTC, datetime -from enum import StrEnum -from pathlib import Path -from typing import Any, Protocol, TextIO - -from colorama import Fore, Style, just_fix_windows_console -from prettytable import PrettyTable - -from .artifacts import ( - ATTEMPT_SCHEMA, - ArtifactStore, - CurrentRecord, - LockTimeoutError, - ManifestValidationError, - _raise_disk_full, -) -from .cache import reset_entry, validate_measurement -from .campaign_policy import ( - PolicyMeasurementState, - policy_measurement_state_hint, - policy_status_label, -) -from .catalog import PROCESS_FAMILIES, REPORT_CATALOG, ReportCatalog -from .measurement import failure_measurement -from .models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .publication import PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI -from .publisher import ( - DEFAULT_PDF_TIMEOUT_SECONDS, - _compile_pdf, - _report_source_copy_ignore, -) -from .resources import ( - DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES, - DEFAULT_MINIMUM_FREE_DISK_BYTES, -) -from .scheduler import ( - CampaignResult, - CampaignScheduler, - CampaignSettings, - CellSelection, - PlannedCell, - plan_campaign, - reconcile_attempt_history, - select_cells, -) -from .service import ReportPaths, ReportService, validate_profile_name -from .source_identity import ReportSourceIdentity, _generated_report_path -from .timing import ( - evaluator_total_timing_record, - recurrence_core_seconds_per_point, -) -from .workspace import ( - ENVIRONMENT_JSON, - ENVIRONMENT_TEX, - record_authenticated_profile_environment, -) - -PROFILE = "macbook_M3_manual" -_ACTIVE_PROFILE = PROFILE -_PRESENTATION_PROFILE = "campaign-local-v1" -DEFAULT_GENERATION_LIMIT_SECONDS = 60.0 * 60.0 -DEFAULT_WORKER_WALL_LIMIT_SECONDS = 60.0 * 60.0 -DEFAULT_RAM_BYTES = 30_000_000_000 -DEFAULT_CORES_PER_WORKER = 1 -DEFAULT_TARGET_RUNTIME_SECONDS = 5.0 -_NUMERICAL_RELATION_CORRECTNESS_ABI = ( - "pyamplicol-numerical-current-relation-correctness-v1" -) -DEFAULT_BATCH_SIZE = 128 -DEFAULT_WARMUP_RUNS = 2 -DEFAULT_MINIMUM_SAMPLES = 5 -DEFAULT_WORKER_STALE_SECONDS = 15.0 -DEFAULT_MANUAL_EXPECTED_PAGE_COUNT = 73 -_REPORT_SECTION_MARKER = re.compile( - r"^% pyamplicol-report-section-(begin|end): ([a-z][a-z0-9-]*)$" -) -_ORIGINAL_AMPLICOL_REQUIRED_FILES = ( - "makefile", - "process_list.py", - "amplicol_color_probe.f03", - "amplicol_color_library_probe.f03", - "amplicol_library_benchmark.f03", -) -_ORIGINAL_AMPLICOL_REQUIRED_MAKE_TARGETS = ( - "amplicol_generate_library", - "amplicol_library_benchmark", - "amplicol_color_probe", - "amplicol_color_library_probe", -) -_LOCAL_AMPLICOL_CONFIG = ".pyamplicol-original-amplicol" -_LOCAL_MADGRAPH_CONFIG = ".pyamplicol-madgraph" -MAX_TAIL_READ_BYTES = 64 * 1024 -MAX_LOG_TAIL_LINES = 8 -MANUAL_STATE_SCHEMA = "pyamplicol-manual-campaign-state-v1" -SOURCE_MARKER_SCHEMA = "pyamplicol-manual-source-v1" -PRESENTATION_OUTCOME_SCHEMA = "pyamplicol-manual-presentation-outcome-v1" -_FULL_SOURCE_REVISION = re.compile(r"[0-9a-f]{40}") -_SAFE_OUTCOME_SLUG = re.compile(r"[a-z][a-z0-9_-]{0,63}") -_SAFE_OUTCOME_CELL_ID = re.compile(r"[a-z0-9][a-z0-9-]{0,127}") -_PRESENTATION_FAILURE_KIND_PREFIX = "ManualCampaignOutcome:" -_UNRECORDED_MEASUREMENT_NUMPY = "unavailable (not recorded by measurement)" -_MAX_PRESENTATION_COMPLETED_AT_NS = (1 << 63) - 1 -_PRESENTATION_OUTCOME_KEYS = frozenset( - { - "schema", - "profile", - "cell_id", - "source_revision", - "campaign_invocation_id", - "attempt_id", - "status", - "label", - "completed_at_ns", - } -) -_DASHBOARD_COUNTER_KEYS = ( - "selected", - "recycled", - "active", - "selected_active", - "dependency_active", - "completed", - "remaining", - "static_na", - "capped", - "failed", - "unverified", - "dependency_only", - "dependency_completed", - "dependency_issues", -) -_ANSI_ESCAPE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]") -_ACTIVE_WORKER_STATUSES = frozenset({"queued", "preparing", "running"}) -_RECYCLED_SUCCESS_STATUSES = frozenset({"recycled", "reused", "skipped-current"}) -_COMPLETED_WORKER_STATUSES = frozenset( - {"ok", "success", *_RECYCLED_SUCCESS_STATUSES} -) -_TERMINAL_CAP_STATUSES = frozenset( - { - PolicyMeasurementState.GENERATION_LIMIT.value, - PolicyMeasurementState.MEMORY_LIMIT.value, - PolicyMeasurementState.WORKER_TIMEOUT.value, - PolicyMeasurementState.PROFILING_TIMEOUT.value, - PolicyMeasurementState.VALIDATION_TIMEOUT.value, - } -) -_TERMINAL_CAP_STATES = frozenset( - { - PolicyMeasurementState.GENERATION_LIMIT, - PolicyMeasurementState.MEMORY_LIMIT, - PolicyMeasurementState.WORKER_TIMEOUT, - PolicyMeasurementState.PROFILING_TIMEOUT, - PolicyMeasurementState.VALIDATION_TIMEOUT, - } -) -_PHASE_TIMELINE_SCHEMA = "pyamplicol-manual-campaign-phase-timeline-v1" -_REPRODUCTION_STAGES = ("prepare", "generate", "profile") -_SUMMARY_SUCCESS_STATUSES = frozenset( - {"ok", "success", "recycled", "reused", "skipped-current"} -) -_FAIL_FAST_SUCCESS_STATUSES = frozenset( - {"ok", "success", "reused", "skipped-current"} -) -FAIL_FAST_FAILURE_LOG = "fail_fast_failure.log" - - -class _DashboardTerminalOutcome(StrEnum): - """One normalized terminal category for a dashboard-owned cell. - - The map keyed by cell ID is the sole terminal-state authority. Counter - sets are derived views, so retries cannot leave a cell in two categories. - """ - - SUCCESS = "success" - CAPPED = "capped" - FAILED = "failed" - UNVERIFIED = "unverified" - - -class ManualCampaignError(RuntimeError): - """One concise, user-facing steering error.""" - - -def _require_literal_directory( - path: Path, - *, - label: str, - required: bool, -) -> None: - """Reject symlink and special-file campaign roots before resolution.""" - - try: - metadata = path.lstat() - except FileNotFoundError: - if required: - raise ManualCampaignError(f"{label} does not exist: {path}") from None - return - except OSError as error: - raise ManualCampaignError(f"cannot inspect {label} {path}: {error}") from error - if stat.S_ISLNK(metadata.st_mode): - raise ManualCampaignError(f"{label} must not be a symbolic link: {path}") - if not stat.S_ISDIR(metadata.st_mode): - raise ManualCampaignError(f"{label} must be a directory: {path}") - - -def _campaign_report_paths(repo_root: Path, docs_dir: Path) -> ReportPaths: - """Derive every private campaign path from one literal campaign directory.""" - - expanded = docs_dir.expanduser() - literal_docs = expanded if expanded.is_absolute() else Path.cwd() / expanded - _require_literal_directory( - literal_docs, - label="campaign directory", - required=True, - ) - literal_artifacts = literal_docs / "campaign_artifacts" - literal_coordination = literal_artifacts / "coordination" - _require_literal_directory( - literal_artifacts, - label="campaign artifact root", - required=False, - ) - _require_literal_directory( - literal_coordination, - label="campaign coordination root", - required=False, - ) - resolved_docs = literal_docs.resolve(strict=True) - if resolved_docs != Path(os.path.abspath(literal_docs)): - raise ManualCampaignError( - f"campaign directory must not traverse a symbolic link: {literal_docs}" - ) - artifact_root = resolved_docs / "campaign_artifacts" - return ReportPaths.from_repo( - repo_root, - docs_dir=resolved_docs, - artifact_root=artifact_root, - coordination_root=artifact_root / "coordination", - ) - - -def _require_launcher_working_directory_identity( - *, launcher_path_checked: bool -) -> None: - """Reject a launcher left inside a renamed campaign directory.""" - - if launcher_path_checked: - return - invocation = Path(sys.argv[0]) - if invocation.name != "steer_performance_campaign.py": - return - logical_text = os.environ.get("PWD") - logical_cwd = Path(logical_text) if logical_text else None - try: - physical_cwd = Path.cwd() - same_directory = ( - logical_cwd is not None - and logical_cwd.is_absolute() - and logical_cwd.samefile(physical_cwd) - ) - except OSError: - same_directory = False - if not same_directory: - raise ManualCampaignError( - "campaign launcher cannot identify its working directory: " - "the shell PWD is missing or no longer names the physical directory. " - "Run `cd ..` and re-enter the intended campaign directory, then retry " - "(or invoke its absolute path from another working directory)." - ) - - -def _acquire_campaign_directory_lock(docs_dir: Path) -> int: - """Hold a shared lifetime claim so ``copy --force`` cannot reset state.""" - - import fcntl - - flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) - try: - descriptor = os.open(docs_dir, flags) - except OSError as error: - raise ManualCampaignError( - f"cannot open campaign directory for coordination: {docs_dir}" - ) from error - try: - fcntl.flock(descriptor, fcntl.LOCK_SH) - except OSError as error: - os.close(descriptor) - if error.errno in {errno.EACCES, errno.EAGAIN}: - raise ManualCampaignError( - f"campaign directory is being reset: {docs_dir}" - ) from None - raise ManualCampaignError( - f"cannot coordinate campaign directory: {docs_dir}" - ) from error - return descriptor - - -def _release_campaign_directory_lock(descriptor: int) -> None: - import fcntl - - try: - fcntl.flock(descriptor, fcntl.LOCK_UN) - finally: - os.close(descriptor) - - -def _missing_ratatui_bindings() -> tuple[str, ...]: - missing: list[str] = [] - for module_name in ("ratatui", "ratatui_py"): - try: - importlib.import_module(module_name) - except Exception: - missing.append(module_name) - return tuple(missing) - - -def _configure_dashboard_capability( - arguments: argparse.Namespace, - *, - installed: bool, -) -> bool: - """Apply the release-wheel fallback and report whether it changed a run.""" - - if not installed or arguments.command not in {"dashboard-snapshot", "run"}: - return False - missing = _missing_ratatui_bindings() - if not missing: - return False - if arguments.command == "dashboard-snapshot": - missing_text = ", ".join(f"{name!r}" for name in missing) - raise ManualCampaignError( - "dashboard rendering is a contributor feature unless the optional " - f"ratatui bindings are installed (missing: {missing_text}); use " - "`run --no-dashboard` with a release wheel, or run from a contributor " - "checkout built with `just dev-install`" - ) - changed = not arguments.no_dashboard - arguments.no_dashboard = True - return changed - - -def _manual_static_na_reason(cell: CellSpec) -> str | None: - """Return only stable catalog policy exclusions. - - Runtime implementation limits belong under the ordinary worker resource - caps rather than becoming controller-specific static N/A rows. - """ - - return REPORT_CATALOG.static_na_reason(cell) - - -class HelpFormatter(argparse.RawDescriptionHelpFormatter): - """Keep examples readable while displaying option defaults.""" - - def _get_help_string(self, action: argparse.Action) -> str: - text = action.help or "" - if ( - action.default is not None - and action.default is not argparse.SUPPRESS - and "%(default)" not in text - and action.option_strings - ): - text += " (default: %(default)s)" - return text - - -@dataclass(frozen=True, slots=True) -class ReportSection: - """One stable top-level section that can be omitted from a PDF build.""" - - identifier: str - title: str - - -REPORT_SECTIONS = ( - ReportSection("scope", "Scope"), - ReportSection("recursion", "Current Recursion and Model Lowering"), - ReportSection("colour-runtime", "Colour and Runtime Semantics"), - ReportSection("methodology", "Benchmark Methodology"), - ReportSection("process-matrices", "Standard-Model Process Matrices"), - ReportSection("z-ladders", "Z-plus-Jets Evaluator Ladders"), - ReportSection("scalar-ladders", "Colour-Singlet Model Ladders"), - ReportSection("interpretation", "Interpretation"), - ReportSection("worked-zgg", "Worked d dbar -> Z g g Example"), - ReportSection( - "shared-current-dag", - "Shared-Current DAG and Numerical Execution", - ), - ReportSection("lc-layouts", "Reusable Leading-Colour Execution Layouts"), - ReportSection( - "execution-modes", - "Compiled, Eager, and Recurrence Execution", - ), - ReportSection("ufo-support", "Supported UFO and Serialized-JSON Models"), -) - - -class Palette: - def __init__(self, enabled: bool) -> None: - self.enabled = enabled - just_fix_windows_console() - - def paint(self, color: str, value: object, *, bright: bool = False) -> str: - text = str(value) - if not self.enabled: - return text - prefix = Style.BRIGHT if bright else "" - return f"{prefix}{color}{text}{Style.RESET_ALL}" - - def key(self, value: object) -> str: - return self.paint(Fore.CYAN, value, bright=True) - - def success(self, value: object) -> str: - return self.paint(Fore.GREEN, value) - - def warning(self, value: object) -> str: - return self.paint(Fore.YELLOW, value) - - def failure(self, value: object) -> str: - return self.paint(Fore.RED, value) - - def neutral(self, value: object) -> str: - return str(value) - - -class _SnapshotProgress(Protocol): - def begin(self, *, total: int, attempt: int, maximum_attempts: int) -> None: ... - - def update(self, completed: int, total: int, message: str) -> None: ... - - def end(self, *, success: bool, message: str, elapsed_seconds: float) -> None: ... - - def close(self) -> None: ... - - -@dataclass(slots=True) -class _RefreshScanProgress: - """One compact coloured progress line owned by ``refresh-pdf``.""" - - stream: TextIO - palette: Palette - _active: bool = False - _completed: int = 0 - _total: int = 0 - _last_width: int = 0 - - def begin(self, *, total: int, attempt: int, maximum_attempts: int) -> None: - self._active = True - self._completed = 0 - self._total = total - self.update( - 0, - total, - f"starting snapshot attempt {attempt}/{maximum_attempts}", - ) - - def update(self, completed: int, total: int, message: str) -> None: - self._completed = completed - self._total = total - fraction = 1.0 if total == 0 else min(1.0, completed / total) - width = 28 - filled = min(width, int(fraction * width)) - bar = self.palette.key("█" * filled) + "·" * (width - filled) - line = ( - f"{self.palette.key('Scanning campaign artifacts')} " - f"[{bar}] {completed:>{len(str(max(total, 1)))}}/{total} {message}" - ) - visible_padding = max(0, self._last_width - len(line)) - self.stream.write("\r" + line + " " * visible_padding) - self.stream.flush() - self._last_width = len(line) - - def end(self, *, success: bool, message: str, elapsed_seconds: float) -> None: - if not self._active: - return - color = self.palette.success if success else self.palette.failure - suffix = color(f"{message} in {elapsed_seconds:.2f}s") - self.update(self._completed, self._total, suffix) - self.stream.write("\n") - self.stream.flush() - self._active = False - self._last_width = 0 - - def close(self) -> None: - if self._active: - self.stream.write("\n") - self.stream.flush() - self._active = False - self._last_width = 0 - - -def _color_enabled(arguments: argparse.Namespace, *, json_output: bool = False) -> bool: - return ( - not json_output - and not bool(getattr(arguments, "no_color", False)) - and "NO_COLOR" not in os.environ - ) - - -def _utc_now() -> str: - return datetime.now(UTC).isoformat(timespec="seconds").replace("+00:00", "Z") - - -def _atomic_json(path: Path, payload: object, *, sync: bool = True) -> None: - temporary: Path | None = None - try: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.{uuid.uuid4().hex}.tmp") - with temporary.open("x", encoding="ascii") as stream: - json.dump( - payload, - stream, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - stream.write("\n") - stream.flush() - if sync: - os.fsync(stream.fileno()) - os.replace(temporary, path) - except OSError as error: - _raise_disk_full(error, path) - finally: - if temporary is not None: - temporary.unlink(missing_ok=True) - - -def _fsync_directory(path: Path) -> None: - descriptor = os.open(path, os.O_RDONLY) - try: - os.fsync(descriptor) - finally: - os.close(descriptor) - - -def _summary_status(value: str) -> str: - normalized = re.sub(r"[^a-z0-9]+", "_", value.strip().lower()).strip("_") - if normalized == "cancelled": - return "interrupted" - if not normalized: - raise ManualCampaignError("campaign outcome has an empty status") - return normalized - - -def _campaign_summary_categories( - *, - static_na_ids: Iterable[str] = (), - result: CampaignResult | None = None, - state: DashboardState | None = None, - interrupted: bool = False, -) -> dict[str, set[str]]: - categories: dict[str, set[str]] = {} - - def add(status: str, cell_id: str) -> None: - normalized = _summary_status(status) - if normalized in _SUMMARY_SUCCESS_STATUSES: - return - categories.setdefault(normalized, set()).add(cell_id) - - for cell_id in static_na_ids: - add("static_na", cell_id) - observed_workers = ( - {} - if state is None - else { - cell_id: worker - for cell_id, worker in state.workers.items() - if worker.peer_instance is None - and cell_id in state.invocation_evidence_ids - } - ) - outcome_ids: set[str] = set() - if result is not None: - for outcome in result.outcomes: - if ( - outcome.status == "cancelled" - and outcome.cell_id not in observed_workers - ): - continue - outcome_ids.add(outcome.cell_id) - add(outcome.status, outcome.cell_id) - if state is not None: - workers = tuple(observed_workers.values()) - for worker in workers: - if worker.recycled or worker.cell_id in state.recycled_ids: - continue - if worker.cell_id in outcome_ids: - continue - if interrupted and worker.status in _ACTIVE_WORKER_STATUSES: - add("interrupted", worker.cell_id) - elif worker.status not in _ACTIVE_WORKER_STATUSES: - add(worker.status, worker.cell_id) - return categories - - -def _has_invocation_summary_evidence( - result: CampaignResult | None, - state: DashboardState, -) -> bool: - if state.invocation_evidence_ids: - return True - return result is not None and any( - outcome.status != "cancelled" for outcome in result.outcomes - ) - - -def _validate_existing_summary_directory(path: Path) -> None: - if path.is_symlink() or not path.is_dir(): - raise ManualCampaignError( - f"campaign summary target is not a regular directory: {path}" - ) - - -def _publish_campaign_summary_ids( - service: ReportService, - categories: Mapping[str, Iterable[str]], - *, - fail_fast_failure_log: str | None = None, -) -> tuple[Path, dict[str, int]]: - target = service.paths.docs_dir / "campaign_summary_ids" - publication_root = service.paths.coordination_root / "campaign-summary-publication" - stage: Path | None = None - backup: Path | None = None - counts: dict[str, int] = {} - try: - target.parent.mkdir(parents=True, exist_ok=True) - publication_root.mkdir(parents=True, exist_ok=True) - if publication_root.is_symlink() or not publication_root.is_dir(): - raise ManualCampaignError( - "campaign summary staging root is not a regular directory: " - f"{publication_root}" - ) - if publication_root.stat().st_dev != target.parent.stat().st_dev: - raise ManualCampaignError( - "campaign summary cannot be replaced atomically because its " - "documentation and coordination roots are on different " - f"filesystems: {target.parent} and {publication_root}" - ) - token = uuid.uuid4().hex - stage = publication_root / f"{target.name}-{token}.stage" - backup = publication_root / f"{target.name}-{token}.backup" - stage.mkdir() - for raw_status, raw_ids in sorted(categories.items()): - status = _summary_status(raw_status) - if status in _SUMMARY_SUCCESS_STATUSES: - continue - cell_ids = tuple(sorted(set(raw_ids))) - if not cell_ids: - continue - path = stage / f"{status}.txt" - with path.open("x", encoding="utf-8", newline="\n") as stream: - stream.write("".join(f"{cell_id}\n" for cell_id in cell_ids)) - stream.flush() - os.fsync(stream.fileno()) - counts[status] = len(cell_ids) - if fail_fast_failure_log is not None: - if not fail_fast_failure_log.strip(): - raise ManualCampaignError("fail-fast failure log is empty") - failure_path = stage / FAIL_FAST_FAILURE_LOG - with failure_path.open("x", encoding="utf-8", newline="\n") as stream: - stream.write(fail_fast_failure_log.rstrip("\n")) - stream.write("\n") - stream.flush() - os.fsync(stream.fileno()) - _fsync_directory(stage) - with service.store.named_lock("campaign-summary-ids"): - moved_old = False - if target.exists() or target.is_symlink(): - _validate_existing_summary_directory(target) - os.replace(target, backup) - moved_old = True - try: - os.replace(stage, target) - _fsync_directory(target.parent) - except BaseException: - if moved_old and not target.exists(): - os.replace(backup, target) - _fsync_directory(target.parent) - raise - if moved_old: - shutil.rmtree(backup) - _fsync_directory(target.parent) - except OSError as error: - _raise_disk_full(error, target) - finally: - if stage is not None and stage.exists(): - shutil.rmtree(stage) - if backup is not None and backup.exists() and target.exists(): - shutil.rmtree(backup) - return target.resolve(strict=True), counts - - -def _print_campaign_summary_ids( - path: Path, - counts: Mapping[str, int], - palette: Palette, -) -> None: - print() - print( - _table( - ("campaign summary", "entries"), - ( - (palette.key(status), palette.warning(count)) - for status, count in sorted(counts.items()) - ) - if counts - else ((palette.success("non-OK entries"), palette.success(0)),), - align={"entries": "r"}, - ) - ) - print(f"Campaign summary IDs: {path}") - - -def _normal(value: str) -> str: - return value.strip().lower().replace("-", "_").replace(" ", "_") - - -def _positive_finite_float(value: str) -> float: - try: - result = float(value) - except ValueError as error: - raise argparse.ArgumentTypeError("expected a finite number") from error - if not math.isfinite(result) or result <= 0.0: - raise argparse.ArgumentTypeError("expected a positive finite number") - return result - - -def _positive_int(value: str) -> int: - try: - result = int(value) - except ValueError as error: - raise argparse.ArgumentTypeError("expected a positive integer") from error - if result <= 0: - raise argparse.ArgumentTypeError("expected a positive integer") - return result - - -def _nonnegative_finite_float(value: str) -> float: - try: - result = float(value) - except ValueError as error: - raise argparse.ArgumentTypeError("expected a finite number") from error - if not math.isfinite(result) or result < 0.0: - raise argparse.ArgumentTypeError("expected a non-negative finite number") - return result - - -def _flatten(values: Sequence[Sequence[str]] | None) -> tuple[str, ...]: - if not values: - return () - flattened = tuple(item for group in values for item in group) - if any(_normal(item) in {"*", "all"} for item in flattened): - return () - return flattened - - -def _shell_join(arguments: Iterable[object]) -> str: - return shlex.join(tuple(str(argument) for argument in arguments)) - - -def _table( - headers: Sequence[str], - rows: Iterable[Sequence[object]], - *, - align: Mapping[str, str] | None = None, - max_width: Mapping[str, int] | None = None, -) -> str: - value = PrettyTable() - value.field_names = list(headers) - value.hrules = 1 - value.vrules = 1 - value.padding_width = 1 - for header in headers: - value.align[header] = "l" - if align is not None: - for header, direction in align.items(): - value.align[header] = direction - if max_width is not None: - for header, width in max_width.items(): - value.max_width[header] = width - for row in rows: - value.add_row(list(row)) - return value.get_string() - - -_MODEL_ALIASES = { - "builtin": ModelKey.BUILTIN_SM, - "built_in": ModelKey.BUILTIN_SM, - "built_in_sm": ModelKey.BUILTIN_SM, - "builtin_sm": ModelKey.BUILTIN_SM, - "sm": ModelKey.BUILTIN_SM, - "ufo": ModelKey.UFO_SM, - "sm_ufo": ModelKey.UFO_SM, - "ufo_sm": ModelKey.UFO_SM, - "external_sm": ModelKey.UFO_SM, - "scalar_contact": ModelKey.SCALAR_CONTACT, - "scalar_gravity": ModelKey.SCALAR_GRAVITY, -} -_ACCURACY_ALIASES = { - "lc": Accuracy.LC, - "leading_color": Accuracy.LC, - "leading_colour": Accuracy.LC, - "nlc": Accuracy.NLC, - "next_to_leading_color": Accuracy.NLC, - "next_to_leading_colour": Accuracy.NLC, - "full": Accuracy.FULL, - "full_color": Accuracy.FULL, - "full_colour": Accuracy.FULL, -} -_MODE_ALIASES = { - "amplicol": ExecutionMode.AMPLICOL, - "legacy": ExecutionMode.AMPLICOL, - "recurrence": ExecutionMode.RECURRENCE, - "ampli_col": ExecutionMode.RECURRENCE, - "compiled": ExecutionMode.COMPILED, - "eager": ExecutionMode.EAGER, - "on_the_fly": ExecutionMode.ON_THE_FLY, - "onthefly": ExecutionMode.ON_THE_FLY, - "otf": ExecutionMode.ON_THE_FLY, -} -_WORKLOAD_ALIASES = { - "non_union_flow": Workload.SELECTED_FLOW, - "selected_flow": Workload.SELECTED_FLOW, - "single_flow": Workload.SELECTED_FLOW, - "single_flow_hel_sum": Workload.SELECTED_FLOW, - "topology_replay": Workload.SELECTED_FLOW, - "union_flow": Workload.ALL_FLOW, - "all_flow": Workload.ALL_FLOW, - "all_flows": Workload.ALL_FLOW, - "all_flows_single_hel": Workload.ALL_FLOW, - "all_flow_union": Workload.ALL_FLOW, - "contracted": Workload.CONTRACTED, -} - - -def _dataset_aliases(catalog: ReportCatalog) -> dict[str, frozenset[str]]: - dataset_ids = frozenset(cell.dataset_id for cell in catalog.measurement_cells()) - aliases: dict[str, frozenset[str]] = { - _normal(dataset): frozenset({dataset}) for dataset in dataset_ids - } - aliases.update( - { - "z": frozenset( - dataset for dataset in dataset_ids if dataset.startswith("z_") - ), - "z_table": frozenset( - dataset for dataset in dataset_ids if dataset.startswith("z_") - ), - "matrix": frozenset( - dataset for dataset in dataset_ids if dataset.startswith("matrix_") - ), - "matrix_table": frozenset( - dataset for dataset in dataset_ids if dataset.startswith("matrix_") - ), - "matrix_best": frozenset( - dataset - for dataset in dataset_ids - if dataset.startswith("matrix_") and "_builtin_sm_" in dataset - ), - "reference": frozenset( - dataset - for dataset in dataset_ids - if dataset.startswith("reference_amplicol_") - ), - "scalar": frozenset( - dataset for dataset in dataset_ids if dataset.startswith("scalar_") - ), - } - ) - return aliases - - -def _invalid_value( - option: str, - value: str, - allowed: Iterable[str], -) -> ManualCampaignError: - choices = tuple(sorted(set(allowed))) - suggestions = difflib.get_close_matches(_normal(value), choices, n=3, cutoff=0.45) - suffix = "" if not suggestions else f"; did you mean {', '.join(suggestions)}?" - if len(choices) > 24: - displayed = ( - *choices[:24], - f"… {len(choices) - 24} more (use --help or a dry run to browse)", - ) - else: - displayed = choices - return ManualCampaignError( - f"{option}: unsupported value {value!r}{suffix}\n" - + _table(("option", "allowed values"), ((option, ", ".join(displayed)),)) - ) - - -def _empty_selection_error( - arguments: argparse.Namespace, - catalog: ReportCatalog, -) -> ManualCampaignError: - provided = tuple( - option - for attribute, option in ( - ("table", "--table"), - ("process_id", "--process-id"), - ("multiplicity", "--multiplicity"), - ("color_approximation", "--color-approximation"), - ("generation_mode", "--generation-mode"), - ("generation_engine", "--generation-engine"), - ("model", "--model"), - ("variant", "--variant"), - ("cell_id", "--cell-id"), - ("cell_id_file", "--cell-id-file"), - ) - if getattr(arguments, attribute, None) - ) - variants = sorted( - { - str(cell.variant) - for cell in catalog.measurement_cells() - if cell.variant is not None - } - ) - multiplicities = sorted({cell.n_final for cell in catalog.measurement_cells()}) - processes = tuple( - f"{family.identifier}:{family.key}" for family in PROCESS_FAMILIES - ) - rows = ( - ( - "--table", - "z_table, matrix_table, matrix_best, scalar_contact, " - "scalar_gravity, reference", - ), - ("--process-id", ", ".join(processes)), - ("--multiplicity", ", ".join(str(value) for value in multiplicities)), - ("--color-approximation", "lc, nlc, full"), - ("--generation-mode", "non-union-flow, union-flow, contracted"), - ( - "--generation-engine", - "amplicol, recurrence, compiled, eager, on-the-fly (otf)", - ), - ("--model", "built_in, sm_ufo, scalar_contact, scalar_gravity"), - ("--variant", ", ".join(variants)), - ( - "--cell-id", - "one exact canonical cell ID (see --help or a broader dry run)", - ), - ( - "--cell-id-file", - "UTF-8 files containing one exact canonical cell ID per line", - ), - ) - suggestion = ( - "Remove one selector at a time to find the conflicting dimension" - if not provided - else "Try removing one of " + ", ".join(provided) - ) - return ManualCampaignError( - "the selector intersection contains no catalog entries. " - f"{suggestion}; wildcard `*`/`all` is also accepted.\n" - + _table( - ("selector", "canonical values / useful aliases"), - rows, - max_width={"canonical values / useful aliases": 96}, - ) - ) - - -def _resolve_map( - option: str, - raw_values: Sequence[str], - aliases: Mapping[str, Any], -) -> frozenset[Any]: - resolved: set[Any] = set() - for raw in raw_values: - key = _normal(raw) - try: - resolved.add(aliases[key]) - except KeyError: - raise _invalid_value(option, raw, aliases) from None - return frozenset(resolved) - - -def _resolve_datasets( - raw_values: Sequence[str], - catalog: ReportCatalog, -) -> frozenset[str]: - aliases = _dataset_aliases(catalog) - resolved: set[str] = set() - for raw in raw_values: - key = _normal(raw) - try: - resolved.update(aliases[key]) - except KeyError: - raise _invalid_value("--table", raw, aliases) from None - return frozenset(resolved) - - -def _resolve_processes( - raw_values: Sequence[str], -) -> tuple[frozenset[str], frozenset[str]]: - by_id = {str(family.identifier): family.key for family in PROCESS_FAMILIES} - by_key = {_normal(family.key): family.key for family in PROCESS_FAMILIES} - process_keys: set[str] = set() - concrete: set[str] = set() - allowed = {**by_id, **by_key} - for raw in raw_values: - key = _normal(raw) - if key in allowed: - process_keys.add(allowed[key]) - elif ">" in raw: - concrete.add(" ".join(raw.split())) - else: - raise _invalid_value("--process-id", raw, allowed) from None - return frozenset(process_keys), frozenset(concrete) - - -def _cell_ids_from_files( - raw_groups: Sequence[Sequence[Path]] | None, - *, - known_cells: frozenset[str], -) -> frozenset[str]: - selected: set[str] = set() - for group in raw_groups or (): - for raw_path in group: - path = Path(raw_path).expanduser() - try: - lines = path.read_text(encoding="utf-8").splitlines() - except (OSError, UnicodeError) as error: - raise ManualCampaignError( - f"--cell-id-file could not read {path}: {error}" - ) from error - for line_number, line in enumerate(lines, start=1): - value = line.strip() - if not value or value.startswith("#"): - continue - location = f"{path}:{line_number}" - if _normal(value) in {"*", "all"}: - raise ManualCampaignError( - f"{location}: wildcards are not allowed in a cell-ID file" - ) - if value not in known_cells: - suggestions = difflib.get_close_matches( - value, - sorted(known_cells), - n=3, - cutoff=0.45, - ) - suffix = ( - "" - if not suggestions - else f"; did you mean {', '.join(suggestions)}?" - ) - raise ManualCampaignError( - f"{location}: unknown canonical cell ID {value!r}{suffix}" - ) - selected.add(value) - return frozenset(selected) - - -def selection_from_arguments( - arguments: argparse.Namespace, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSelection, tuple[CellSpec, ...]]: - raw_tables = _flatten(getattr(arguments, "table", None)) - raw_processes = _flatten(getattr(arguments, "process_id", None)) - raw_multiplicities = _flatten(getattr(arguments, "multiplicity", None)) - raw_accuracies = _flatten(getattr(arguments, "color_approximation", None)) - raw_workloads = _flatten(getattr(arguments, "generation_mode", None)) - raw_modes = _flatten(getattr(arguments, "generation_engine", None)) - raw_models = _flatten(getattr(arguments, "model", None)) - raw_variants = _flatten(getattr(arguments, "variant", None)) - raw_cell_id_groups = getattr(arguments, "cell_id", None) - raw_cell_ids = _flatten(raw_cell_id_groups) - direct_cell_wildcard = any( - _normal(value) in {"*", "all"} - for group in raw_cell_id_groups or () - for value in group - ) - - multiplicities: set[int] = set() - for raw in raw_multiplicities: - try: - value = int(raw) - except ValueError: - raise ManualCampaignError( - f"--multiplicity expects positive integers, not {raw!r}" - ) from None - if value < 1: - raise ManualCampaignError("--multiplicity values must be positive") - multiplicities.add(value) - - process_keys, processes = _resolve_processes(raw_processes) - known_variants = frozenset( - cell.variant for cell in catalog.measurement_cells() if cell.variant is not None - ) - variants: set[str] = set() - for raw in raw_variants: - matches = { - variant for variant in known_variants if _normal(variant) == _normal(raw) - } - if not matches: - raise _invalid_value("--variant", raw, map(_normal, known_variants)) - variants.update(matches) - - known_cells = frozenset(cell.cell_id for cell in catalog.measurement_cells()) - cell_ids: set[str] = set() - for raw in raw_cell_ids: - normalized = raw.strip() - if _normal(normalized) in {"*", "all"}: - continue - if normalized not in known_cells: - raise _invalid_value("--cell-id", normalized, known_cells) - cell_ids.add(normalized) - file_cell_ids = _cell_ids_from_files( - getattr(arguments, "cell_id_file", None), - known_cells=known_cells, - ) - if ( - getattr(arguments, "cell_id_file", None) - and not file_cell_ids - and not raw_cell_ids - and not direct_cell_wildcard - ): - raise ManualCampaignError( - "--cell-id-file inputs contain no canonical cell IDs" - ) - if not direct_cell_wildcard: - cell_ids.update(file_cell_ids) - - resolved_modes = _resolve_map( - "--generation-engine", - raw_modes, - _MODE_ALIASES, - ) - resolved_models = _resolve_map("--model", raw_models, _MODEL_ALIASES) - selection = CellSelection( - datasets=_resolve_datasets(raw_tables, catalog), - modes=resolved_modes, - # Legacy AmpliCol represents the built-in SM but stores model=None. - # Apply the friendly model filter below so built_in + amplicol works. - models=frozenset(), - accuracies=_resolve_map( - "--color-approximation", - raw_accuracies, - _ACCURACY_ALIASES, - ), - process_keys=process_keys, - processes=processes, - multiplicities=frozenset(multiplicities), - variants=frozenset(variants), - workloads=_resolve_map( - "--generation-mode", - raw_workloads, - _WORKLOAD_ALIASES, - ), - cell_ids=frozenset(cell_ids), - ) - selected = list(select_cells(selection, catalog=catalog)) - - normalized_tables = {_normal(value) for value in raw_tables} - if ExecutionMode.AMPLICOL in resolved_modes: - supplemental_datasets: frozenset[str] = frozenset() - supplemental_process_keys = selection.process_keys - supplemental_workloads = selection.workloads - supplemental_accuracies = selection.accuracies - if "z" in normalized_tables or "z_table" in normalized_tables: - supplemental_datasets = frozenset({"reference_amplicol_lc"}) - supplemental_process_keys = frozenset({"dd_z_jets"}) - supplemental_workloads = frozenset({Workload.SELECTED_FLOW}) - supplemental_accuracies = frozenset({Accuracy.LC}) - elif normalized_tables.intersection({"matrix", "matrix_table", "matrix_best"}): - supplemental_datasets = frozenset( - { - "reference_amplicol_lc", - "reference_amplicol_nlc", - "reference_amplicol_full", - } - ) - if supplemental_datasets: - supplement = CellSelection( - datasets=supplemental_datasets, - modes=frozenset({ExecutionMode.AMPLICOL}), - accuracies=supplemental_accuracies, - process_keys=supplemental_process_keys, - processes=selection.processes, - multiplicities=selection.multiplicities, - variants=selection.variants, - workloads=supplemental_workloads, - cell_ids=selection.cell_ids, - ) - selected.extend(select_cells(supplement, catalog=catalog)) - - if resolved_models: - selected = [ - cell - for cell in selected - if cell.measurement.model in resolved_models - or ( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and ModelKey.BUILTIN_SM in resolved_models - ) - ] - cells = tuple( - sorted( - {cell.cell_id: cell for cell in selected}.values(), - key=lambda item: item.cell_id, - ) - ) - if not cells: - raise _empty_selection_error(arguments, catalog) - return selection, cells - - -def _model_cli_source(cell: CellSpec, repo_root: Path) -> str: - from .runner import _model_source_path - - model = cell.measurement.model - if model is None: - return "" - source = _model_source_path(repo_root, model) - return "built-in-sm" if source is None else os.fspath(source) - - -def _reproduction_root(artifact_root: Path, cell: CellSpec) -> Path: - return artifact_root / "manual-reproductions" / cell.cell_id - - -def _pyamplicol_cli(repo_root: Path) -> tuple[str, ...]: - """Return a cwd-independent source CLI prefix for contributor installs.""" - - source_package = repo_root / "src/pyamplicol" - executable = repo_root / ".venv/bin/pyamplicol" - if not source_package.is_dir() or not executable.is_file(): - return (sys.executable, "-m", "pyamplicol") - return ( - "env", - f"PYTHONPATH={os.fspath((repo_root / 'src').resolve(strict=False))}", - os.fspath(executable.expanduser().resolve(strict=False)), - ) - - -def _materialize_reproduction_momenta( - cell: CellSpec, - *, - artifact_root: Path, - momenta: object, -) -> Path: - """Publish the exact recorded report points for public recurrence.""" - - path = _reproduction_root(artifact_root, cell) / "momenta.json" - _atomic_json(path, momenta) - return path - - -@dataclass(frozen=True, slots=True) -class ReproductionRecipe: - kind: str - prepare: tuple[str, ...] | None - generate: tuple[str, ...] | None - profile: tuple[str, ...] | None - note: str - exact: bool - - def as_dict(self) -> dict[str, object]: - return { - "abi": PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI, - "kind": self.kind, - "prepare": None if self.prepare is None else list(self.prepare), - "generate": None if self.generate is None else list(self.generate), - "profile": None if self.profile is None else list(self.profile), - "note": self.note, - "exact": self.exact, - } - - -@dataclass(frozen=True, slots=True) -class ReproductionSettings: - """Effective invocation settings used for active public CLI recipes.""" - - cores: int = DEFAULT_CORES_PER_WORKER - target_runtime: float = DEFAULT_TARGET_RUNTIME_SECONDS - batch_size: int = DEFAULT_BATCH_SIZE - warmups: int = DEFAULT_WARMUP_RUNS - minimum_samples: int = DEFAULT_MINIMUM_SAMPLES - - -def _validated_recipe_numerical_relation_fallback( - provenance: object, -) -> Mapping[str, object] | None: - if not isinstance(provenance, Mapping): - return None - raw = provenance.get("numerical_relation_fallback") - if raw is None: - return None - from pyamplicol.generation.recurrence_numerical_current_warmup import ( - EVIDENCE_ENVELOPE_FALLBACK_REASON, - NUMERICAL_RELATION_FALLBACK_ABI, - RecurrenceNumericalEvidenceGeometry, - ) - - expected_fields = { - "abi", - "requested_mode", - "effective_mode", - "effective_reuse_state", - "reason", - "geometry", - "certified_relation_count", - "applied_relation_count", - } - geometry_fields = { - "current_count", - "component_count", - "candidate_probe_count", - "verification_probe_count", - "runtime_parameter_count", - "scalar_count", - "row_count", - } - geometry = raw.get("geometry") if isinstance(raw, Mapping) else None - if ( - not isinstance(raw, Mapping) - or set(raw) != expected_fields - or raw.get("abi") != NUMERICAL_RELATION_FALLBACK_ABI - or raw.get("requested_mode") != "certified-reuse" - or raw.get("effective_mode") != "off" - or raw.get("effective_reuse_state") != "disabled" - or raw.get("reason") != EVIDENCE_ENVELOPE_FALLBACK_REASON - or raw.get("certified_relation_count") != 0 - or isinstance(raw.get("certified_relation_count"), bool) - or raw.get("applied_relation_count") != 0 - or isinstance(raw.get("applied_relation_count"), bool) - or not isinstance(geometry, Mapping) - or set(geometry) != geometry_fields - or any(type(geometry.get(field)) is not int for field in geometry_fields) - ): - raise ManualCampaignError( - "measurement numerical-relation fallback provenance is malformed" - ) - try: - expected_geometry = RecurrenceNumericalEvidenceGeometry.from_counts( - current_count=int(geometry["current_count"]), - component_count=int(geometry["component_count"]), - candidate_probe_count=int(geometry["candidate_probe_count"]), - verification_probe_count=int(geometry["verification_probe_count"]), - runtime_parameter_count=int(geometry["runtime_parameter_count"]), - ).to_json_dict() - except (OverflowError, TypeError, ValueError) as error: - raise ManualCampaignError( - "measurement numerical-relation fallback provenance is malformed" - ) from error - if dict(geometry) != expected_geometry: - raise ManualCampaignError( - "measurement numerical-relation fallback geometry is inconsistent" - ) - return raw - - -def reproduction_recipe( - cell: CellSpec, - *, - repo_root: Path, - artifact_root: Path, - artifact_path: str = "", - cores: int = DEFAULT_CORES_PER_WORKER, - target_runtime: float = DEFAULT_TARGET_RUNTIME_SECONDS, - batch_size: int = DEFAULT_BATCH_SIZE, - warmups: int = DEFAULT_WARMUP_RUNS, - minimum_samples: int = DEFAULT_MINIMUM_SAMPLES, - measurement: Mapping[str, object] | None = None, -) -> ReproductionRecipe: - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - return ReproductionRecipe( - kind="legacy-report-adapter", - prepare=None, - generate=None, - profile=None, - note="Original AmpliCol has no public pyamplicol CLI subcommand.", - exact=False, - ) - cli = _pyamplicol_cli(repo_root) - if artifact_path == "": - artifact_path = os.fspath(_reproduction_root(artifact_root, cell) / "artifact") - model_cache = _reproduction_root(artifact_root, cell) / "model-cache" - provenance = ( - measurement.get("provenance") if isinstance(measurement, Mapping) else None - ) - numerical_relation_fallback = _validated_recipe_numerical_relation_fallback( - provenance - ) - requested = ( - provenance.get("requested_config") if isinstance(provenance, Mapping) else None - ) - requested_model = requested.get("model") if isinstance(requested, Mapping) else None - recorded_model_source = ( - requested_model.get("source") if isinstance(requested_model, Mapping) else None - ) - raw_model_source = ( - recorded_model_source - if isinstance(recorded_model_source, str) and recorded_model_source - else _model_cli_source(cell, repo_root) - ) - artifact_record = ( - measurement.get("artifact") if isinstance(measurement, Mapping) else None - ) - process_selector = cell.process - completed = ( - isinstance(measurement, Mapping) - and measurement.get("status") == ResultStatus.OK.value - and isinstance(artifact_record, Mapping) - and isinstance(artifact_record.get("path"), str) - and isinstance(artifact_record.get("process_id"), str) - ) - prepare: tuple[str, ...] | None = None - model_source = raw_model_source - prepared_execution = cell.measurement.execution_mode in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - } - if prepared_execution and cell.measurement.model in { - ModelKey.BUILTIN_SM, - ModelKey.UFO_SM, - }: - prepared_source = _model_cli_source(cell, repo_root) - prepared_stem = ( - "built-in-sm" if cell.measurement.model is ModelKey.BUILTIN_SM else "ufo-sm" - ) - prepared_path = ( - _reproduction_root(artifact_root, cell) - / "prepared-models" - / f"{prepared_stem}-jit-o2.pyamplicol-model" - ) - prepare = ( - *cli, - "model", - "compile", - prepared_source, - os.fspath(prepared_path), - "--model-cache-dir", - os.fspath(model_cache), - "--model-cache", - "--backend", - "jit", - "--cores", - str(cores), - "--jit-optimization-level", - "2", - "--set", - "evaluator.execution_mode=recurrence", - "--json", - "--color", - "always", - "--progress", - "tty", - ) - model_source = os.fspath(prepared_path) - on_the_fly = cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - layout = ( - "topology-replay" - if on_the_fly - else ( - "all-flow-union" - if cell.workload is Workload.ALL_FLOW - else "topology-replay" - ) - ) - numerical_reuse_flag = ( - "--no-numerical-current-reuse" - if on_the_fly or numerical_relation_fallback is not None - else "--numerical-current-reuse" - ) - generate = ( - *cli, - "generate", - cell.process, - artifact_path, - "--model", - model_source, - "--model-cache", - "--model-cache-dir", - os.fspath(model_cache), - "--color-accuracy", - cell.measurement.accuracy.value, - "--lc-flow-layout", - layout, - "--execution-mode", - cell.measurement.execution_mode.value, - "--backend", - cell.measurement.backend, - "--workers", - str(cores), - "--cores", - str(cores), - "--batch-size", - str(batch_size), - "--output-chunk-size", - "512", - "--horner-iterations", - "10", - "--cpe-iterations", - "none", - "--max-horner-variables", - "1000", - "--max-common-pair-cache-entries", - "5000000", - "--max-common-pair-distance", - "1000", - "--jit-optimization-level", - str(cell.measurement.jit_optimization_level or 2), - "--cpp-optimization", - "O3", - "--no-emit-api-bundle" if on_the_fly else "--emit-api-bundle", - "--no-validation" if on_the_fly else "--validation", - "--validation-samples", - "1", - "--validation-seed", - "12345", - "--relative-tolerance", - "1e-12", - "--absolute-tolerance", - "1e-300", - "--no-post-build-validation", - numerical_reuse_flag, - "--force", - "--color", - "always", - "--progress", - "tty", - ) - selector_contract = ( - measurement.get("selector_contract") - if isinstance(measurement, Mapping) - else None - ) - selector: tuple[str, ...] = () - if isinstance(selector_contract, Mapping): - if cell.workload is Workload.SELECTED_FLOW: - raw_flows = selector_contract.get("selected_color_flow_ids") - if isinstance(raw_flows, Sequence) and not isinstance( - raw_flows, (str, bytes) - ): - selector = tuple( - argument - for value in raw_flows - for argument in ("--color-flow", str(value)) - ) - elif cell.workload is Workload.ALL_FLOW: - try: - from .runner import SelectorContract - - raw_helicities: object = SelectorContract.from_mapping( - selector_contract - ).runtime_all_flow_helicity_ids - except (TypeError, ValueError): - raw_helicities = () - if isinstance(raw_helicities, Sequence): - selector = tuple( - argument - for value in raw_helicities - for argument in ("--helicity", str(value)) - ) - selector_ready = cell.workload is Workload.CONTRACTED or bool(selector) - recorded_momenta = ( - provenance.get("report_momenta") if isinstance(provenance, Mapping) else None - ) - momenta_ready = isinstance(recorded_momenta, Sequence) and not isinstance( - recorded_momenta, - (str, bytes), - ) - exact = ( - completed - and cell.measurement.execution_mode - in {ExecutionMode.RECURRENCE, ExecutionMode.ON_THE_FLY} - and selector_ready - and momenta_ready - ) - momenta: tuple[str, ...] = () - if exact: - momenta = ( - "--momenta", - os.fspath( - _materialize_reproduction_momenta( - cell, - artifact_root=artifact_root, - momenta=recorded_momenta, - ) - ), - ) - profile = ( - *cli, - "profile", - artifact_path, - "--process", - process_selector, - "--target-runtime", - f"{target_runtime:g}", - "--batch-size", - str(batch_size), - "--warmup-runs", - str(warmups), - "--minimum-samples", - str(minimum_samples), - "--precision", - "16", - *momenta, - *selector, - "--json", - "--color", - "always", - "--progress", - "tty", - ) - if cell.measurement.execution_mode is ExecutionMode.COMPILED: - kind = "public-cli+precompiled-generation+paired-arena-exceptions" - note = ( - "Diagnostic only: the report injects a precompiled model outside " - "generation_seconds and publishes a paired private Arena profile; " - "the public commands do not reproduce either timing boundary." - ) - elif cell.measurement.execution_mode is ExecutionMode.EAGER: - kind = "public-cli+paired-arena-profile-exception" - note = ( - "Generation uses the public CLI path. Profile is diagnostic only: " - "the report publishes a paired private Arena timing boundary." - ) - elif exact: - kind = "public-cli-exact" - note = ( - "Exact completed-cell public commands with the published stable " - "selector and materialized report momenta." - ) - else: - kind = "public-cli-template" - note = ( - "Prepare (when shown) and generate are runnable. Profile is a " - "template only: its stable flow/helicity selector and exact " - "momenta are published after successful generation/measurement." - ) - if numerical_relation_fallback is not None: - kind += "+effective-reuse-off-fallback" - note += ( - " The measured generation took the authenticated " - "evidence-envelope fallback: numerical-current reuse was effectively " - "disabled, so the reproduction command uses " - "--no-numerical-current-reuse." - ) - if prepare is not None: - kind += "+model-compile-prerequisite" - return ReproductionRecipe( - kind=kind, - prepare=prepare, - generate=generate, - profile=profile, - note=note, - exact=exact, - ) - - -def _git_directory(repo_root: Path) -> Path: - git_marker = repo_root / ".git" - if git_marker.is_file(): - text = git_marker.read_text(encoding="ascii").strip() - prefix = "gitdir:" - if not text.startswith(prefix): - raise ManualCampaignError(".git worktree marker is malformed") - git_dir = Path(text[len(prefix) :].strip()) - if not git_dir.is_absolute(): - git_dir = (repo_root / git_dir).resolve(strict=False) - else: - git_dir = git_marker - if not git_dir.is_dir(): - raise ManualCampaignError("checkout Git metadata directory is unavailable") - return git_dir - - -def _git_common_directory(git_dir: Path) -> Path: - commondir = git_dir / "commondir" - if not commondir.is_file(): - return git_dir - return (git_dir / commondir.read_text(encoding="ascii").strip()).resolve( - strict=False - ) - - -def _repo_head(repo_root: Path) -> str: - """Read the checkout revision without invoking Git.""" - - git_dir = _git_directory(repo_root) - head = (git_dir / "HEAD").read_text(encoding="ascii").strip() - if head.startswith("ref: "): - reference = head[5:] - loose = git_dir / reference - if loose.is_file(): - head = loose.read_text(encoding="ascii").strip() - else: - common_dir = _git_common_directory(git_dir) - common_loose = common_dir / reference - if common_loose.is_file(): - head = common_loose.read_text(encoding="ascii").strip() - else: - packed = common_dir / "packed-refs" - value = None - if packed.is_file(): - for line in packed.read_text(encoding="ascii").splitlines(): - if line.startswith(("#", "^")): - continue - candidate, separator, name = line.partition(" ") - if separator and name == reference: - value = candidate - break - if value is None: - raise ManualCampaignError( - f"cannot resolve Git reference {reference!r}" - ) - head = value - if len(head) != 40 or any( - character not in "0123456789abcdef" for character in head - ): - raise ManualCampaignError("checkout HEAD is not a lowercase 40-hex revision") - return head - - -def _commit_tree_marker(repo_root: Path, revision: str) -> str: - """Read HEAD's tree, using one Git query only when the commit is packed.""" - - common_dir = _git_common_directory(_git_directory(repo_root)) - object_path = common_dir / "objects" / revision[:2] / revision[2:] - try: - raw = zlib.decompress(object_path.read_bytes()) - except (OSError, zlib.error): - # Ordinary clones and repositories after ``git gc`` store commits in - # pack files. Parsing Git's pack format here would duplicate Git and - # be substantially more fragile than this single read-only fallback. - try: - completed = subprocess.run( - ("git", "rev-parse", "--verify", f"{revision}^{{tree}}"), - cwd=repo_root, - check=False, - capture_output=True, - text=True, - timeout=15, - ) - except (OSError, subprocess.SubprocessError): - return f"manual-revision:{revision}" - tree = completed.stdout.strip() - if completed.returncode == 0 and _FULL_SOURCE_REVISION.fullmatch(tree): - return tree - return f"manual-revision:{revision}" - _header, separator, body = raw.partition(b"\0") - if not separator: - return f"manual-revision:{revision}" - for line in body.splitlines(): - if not line.startswith(b"tree "): - continue - value = line[5:].decode("ascii", errors="ignore") - if len(value) == 40 and all( - character in "0123456789abcdef" for character in value - ): - return value - return f"manual-revision:{revision}" - - -def _index_tree_marker( - entries: Sequence[tuple[bytes, int, bytes]], -) -> str: - """Build Git's tree identity from index object IDs, never file contents.""" - - root: dict[bytes, Any] = {} - for raw_path, indexed_mode, object_id in entries: - parts = raw_path.split(b"/") - if not parts or any(part in {b"", b".", b".."} for part in parts): - raise ManualCampaignError("checkout index contains an unsafe path") - node = root - for part in parts[:-1]: - existing = node.get(part) - if existing is None: - child: dict[bytes, Any] = {} - node[part] = child - node = child - elif isinstance(existing, dict): - node = existing - else: - raise ManualCampaignError( - "checkout index contains a file/directory path collision" - ) - leaf = parts[-1] - if leaf in node: - raise ManualCampaignError("checkout index contains duplicate paths") - kind = indexed_mode & 0o170000 - if kind == 0o100000: - tree_mode = 0o100755 if indexed_mode & 0o111 else 0o100644 - elif kind in {0o120000, 0o160000}: - tree_mode = kind - else: - raise ManualCampaignError( - f"checkout index contains unsupported mode {indexed_mode:o}" - ) - node[leaf] = (tree_mode, object_id) - - def encode_tree(node: Mapping[bytes, Any]) -> bytes: - records: list[bytes] = [] - ordered = sorted( - node.items(), - key=lambda item: item[0] + (b"/" if isinstance(item[1], dict) else b""), - ) - for name, value in ordered: - if isinstance(value, dict): - mode = b"40000" - object_id = encode_tree(value) - else: - indexed_mode, object_id = value - mode = f"{indexed_mode:o}".encode("ascii") - records.append(mode + b" " + name + b"\0" + object_id) - payload = b"".join(records) - # SHA-1 here is Git's tree-object address over index metadata. No - # worktree or performance artifact bytes are read or hashed. - return hashlib.sha1( - b"tree " + str(len(payload)).encode("ascii") + b"\0" + payload, - usedforsecurity=False, - ).digest() - - return encode_tree(root).hex() - - -def _index_metadata_dirty_paths( - repo_root: Path, - *, - committed_tree: str | None = None, -) -> tuple[str, ...]: - """Check index/worktree metadata and index-vs-HEAD with a packed-HEAD fallback.""" - - index_path = _git_directory(repo_root) / "index" - try: - data = index_path.read_bytes() - except OSError as error: - raise ManualCampaignError(f"checkout index is unreadable: {error}") from error - if len(data) < 12: - raise ManualCampaignError("checkout index is truncated") - signature, version, count = struct.unpack("!4sII", data[:12]) - if signature != b"DIRC" or version not in {2, 3}: - raise ManualCampaignError( - f"unsupported checkout index format: signature={signature!r}, " - f"version={version}" - ) - offset = 12 - tracked: set[str] = set() - dirty: list[str] = [] - tree_entries: list[tuple[bytes, int, bytes]] = [] - unmerged = False - for _entry in range(count): - start = offset - if offset + 62 > len(data): - raise ManualCampaignError("checkout index entry is truncated") - fields = struct.unpack("!10I20sH", data[offset : offset + 62]) - offset += 62 - mtime_seconds, mtime_nanoseconds = fields[2], fields[3] - indexed_mode, indexed_size, flags = fields[6], fields[9], fields[11] - object_id = fields[10] - if version >= 3 and flags & 0x4000: - offset += 2 - encoded_length = flags & 0x0FFF - if encoded_length < 0x0FFF: - end = offset + encoded_length - else: - try: - end = data.index(b"\0", offset) - except ValueError as error: - raise ManualCampaignError( - "checkout index path is unterminated" - ) from error - if end >= len(data): - raise ManualCampaignError("checkout index path is truncated") - raw_relative = data[offset:end] - relative = raw_relative.decode("utf-8", errors="surrogateescape") - tracked.add(relative) - offset = end + 1 - while (offset - start) % 8: - offset += 1 - if flags & 0x3000: - unmerged = True - else: - tree_entries.append((raw_relative, indexed_mode, object_id)) - if _generated_report_path(relative): - continue - path = repo_root / relative - try: - observed = path.lstat() - except OSError: - dirty.append(relative) - continue - metadata = ( - observed.st_mtime_ns // 1_000_000_000, - observed.st_mtime_ns % 1_000_000_000, - observed.st_size, - observed.st_mode & 0o170000, - observed.st_mode & 0o111, - ) - expected = ( - mtime_seconds, - mtime_nanoseconds, - indexed_size, - indexed_mode & 0o170000, - indexed_mode & 0o111, - ) - if metadata != expected: - dirty.append(relative) - if committed_tree is None: - try: - revision = _repo_head(repo_root) - except (ManualCampaignError, OSError): - # Keep the metadata helper usable for deliberately minimal test - # indexes. lightweight_source_identity() resolves HEAD first and - # therefore never takes this compatibility path. - revision = None - if revision is not None: - committed_tree = _commit_tree_marker(repo_root, revision) - if committed_tree is not None: - if unmerged: - dirty.append("") - elif committed_tree.startswith("manual-revision:"): - dirty.append("") - elif _index_tree_marker(tree_entries) != committed_tree: - dirty.append("") - critical = ( - "tools/performance_report/manual_campaign.py", - "src/pyamplicol/_profiling_campaign/steer_performance_campaign.py", - ) - dirty.extend( - relative - for relative in critical - if (repo_root / relative).exists() and relative not in tracked - ) - return tuple(sorted(set(dirty))) - - -def lightweight_source_identity(repo_root: Path) -> ReportSourceIdentity: - revision = _repo_head(repo_root) - tree = _commit_tree_marker(repo_root, revision) - return ReportSourceIdentity( - revision, - tree, - _index_metadata_dirty_paths(repo_root, committed_tree=tree), - ) - - -def installed_source_identity( - *, - allow_candidate_checkout: bool = False, -) -> ReportSourceIdentity: - """Bind a copied campaign to its wheel or a dry-run candidate checkout.""" - - from pyamplicol._internal.versions import ( - active_source_checkout, - active_source_revision, - ) - - revision = active_source_revision() - if revision is None: - checkout = active_source_checkout() if allow_candidate_checkout else None - if checkout is not None: - return lightweight_source_identity(checkout) - raise ManualCampaignError( - "installed pyAmpliCol has no source revision in its build info; " - "reinstall a release wheel that retains build provenance" - ) - tree = hashlib.sha1( - f"pyamplicol-installed-report-tree-v1:{revision}".encode("ascii"), - usedforsecurity=False, - ).hexdigest() - return ReportSourceIdentity(revision, tree, ()) - - -@dataclass(frozen=True, slots=True) -class LightweightCurrent: - cell_id: str - attempt_id: str - result_path: Path - result: Mapping[str, object] - complete: bool - reusable: bool - reason: str - record: CurrentRecord | None = None - - -@dataclass(frozen=True, slots=True) -class _ProfileEnvironmentWitness: - active_runtime: Mapping[str, object] - host_environment: Mapping[str, object] - - -@dataclass(frozen=True, slots=True) -class RecordedSourcePolicy: - """The active measurement revision and persisted read-only reuse policy.""" - - source_revision: str - continue_across_revisions: bool = False - - -@dataclass(frozen=True, slots=True) -class LightweightPresentationOutcome: - """One tiny presentation-only terminal outcome for an otherwise empty cell.""" - - profile: str - cell_id: str - source_revision: str - campaign_invocation_id: str - attempt_id: str | None - status: str - label: str - completed_at_ns: int - - @property - def ordering_key(self) -> tuple[int, str, str, str]: - return ( - self.completed_at_ns, - self.campaign_invocation_id, - self.attempt_id or "", - self.status, - ) - - @property - def successful(self) -> bool: - return self.status in _SUMMARY_SUCCESS_STATUSES - - def as_dict(self) -> dict[str, object]: - return { - "schema": PRESENTATION_OUTCOME_SCHEMA, - "profile": self.profile, - "cell_id": self.cell_id, - "source_revision": self.source_revision, - "campaign_invocation_id": self.campaign_invocation_id, - "attempt_id": self.attempt_id, - "status": self.status, - "label": self.label, - "completed_at_ns": self.completed_at_ns, - } - - -def _read_object(path: Path) -> dict[str, object] | None: - try: - value = json.loads(path.read_text(encoding="utf-8")) - except (OSError, UnicodeError, json.JSONDecodeError): - return None - return value if isinstance(value, dict) else None - - -def _presentation_outcome_path( - service: ReportService, - cell_id: str, - *, - catalog_validated: bool = False, -) -> Path: - if not catalog_validated: - service.catalog.cell(cell_id) - if _SAFE_OUTCOME_CELL_ID.fullmatch(cell_id) is None: - raise ManualCampaignError( - f"presentation outcome cell ID is unsafe: {cell_id!r}" - ) - return ( - service.paths.coordination_root - / "manual-presentation-outcomes" - / f"{cell_id}.json" - ) - - -def _canonical_attempt_uuid(value: object) -> str | None: - if not isinstance(value, str): - return None - try: - parsed = uuid.UUID(value) - except ValueError: - return None - return value if str(parsed) == value else None - - -def _humanized_outcome_label(status: str) -> str: - if status == "cancelled": - return "interrupted" - return " ".join(status.replace("_", " ").replace("-", " ").split()) - - -def _parse_presentation_outcome( - raw: Mapping[str, object] | None, - *, - expected_profile: str, - expected_cell_id: str, - source_revision: str, - accept_historical_source: bool, -) -> LightweightPresentationOutcome | None: - if raw is None or set(raw) != _PRESENTATION_OUTCOME_KEYS: - return None - profile = raw.get("profile") - cell_id = raw.get("cell_id") - revision = raw.get("source_revision") - invocation_id = raw.get("campaign_invocation_id") - status = raw.get("status") - label = raw.get("label") - completed_at_ns = raw.get("completed_at_ns") - if ( - raw.get("schema") != PRESENTATION_OUTCOME_SCHEMA - or not isinstance(profile, str) - or profile != expected_profile - or not isinstance(cell_id, str) - or cell_id != expected_cell_id - or not isinstance(revision, str) - or _FULL_SOURCE_REVISION.fullmatch(revision) is None - or (revision != source_revision and not accept_historical_source) - or not isinstance(invocation_id, str) - or not (1 <= len(invocation_id) <= 128) - or not invocation_id.isascii() - or not invocation_id.isprintable() - or not isinstance(status, str) - or _SAFE_OUTCOME_SLUG.fullmatch(status) is None - or not isinstance(label, str) - or not (1 <= len(label) <= 64) - or label != label.strip() - or not label.isascii() - or not label.isprintable() - or isinstance(completed_at_ns, bool) - or not isinstance(completed_at_ns, int) - or completed_at_ns <= 0 - or completed_at_ns > _MAX_PRESENTATION_COMPLETED_AT_NS - ): - return None - raw_attempt_id = raw.get("attempt_id") - attempt_id = _canonical_attempt_uuid(raw_attempt_id) - if raw_attempt_id is not None and attempt_id is None: - return None - return LightweightPresentationOutcome( - profile=profile, - cell_id=cell_id, - source_revision=revision, - campaign_invocation_id=invocation_id, - attempt_id=attempt_id, - status=status, - label=label, - completed_at_ns=completed_at_ns, - ) - - -def lightweight_presentation_outcome( - service: ReportService, - cell: CellSpec, - *, - source_revision: str, - accept_historical_source: bool = False, -) -> LightweightPresentationOutcome | None: - """Read one direct compact outcome, ignoring unsafe or malformed metadata.""" - - path = _presentation_outcome_path( - service, - cell.cell_id, - catalog_validated=True, - ) - if path.is_symlink() or not path.is_file(): - return None - return _parse_presentation_outcome( - _read_object(path), - expected_profile=_PRESENTATION_PROFILE, - expected_cell_id=cell.cell_id, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - ) - - -def lightweight_presentation_outcomes( - service: ReportService, - cells: Sequence[CellSpec], - *, - source_revision: str, - accept_historical_source: bool = False, - progress: Callable[[int, int], None] | None = None, -) -> dict[str, LightweightPresentationOutcome]: - result: dict[str, LightweightPresentationOutcome] = {} - total = len(cells) - for completed, cell in enumerate(cells, start=1): - outcome = lightweight_presentation_outcome( - service, - cell, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - ) - if outcome is not None: - result[cell.cell_id] = outcome - if progress is not None: - progress(completed, total) - return result - - -def _replace_presentation_outcome_locked( - service: ReportService, - outcome: LightweightPresentationOutcome, - *, - accept_historical_source: bool, - only_if_replacing_failure: bool = False, - catalog_validated: bool = False, -) -> bool: - """Replace one outcome while the shared presentation lock is held.""" - - validated = _parse_presentation_outcome( - outcome.as_dict(), - expected_profile=_PRESENTATION_PROFILE, - expected_cell_id=outcome.cell_id, - source_revision=outcome.source_revision, - accept_historical_source=False, - ) - if validated is None: - raise ManualCampaignError("presentation outcome metadata is invalid") - outcome = validated - path = _presentation_outcome_path( - service, - outcome.cell_id, - catalog_validated=catalog_validated, - ) - raw_existing = ( - None if path.is_symlink() or not path.is_file() else _read_object(path) - ) - existing = ( - None - if raw_existing is None - else _parse_presentation_outcome( - raw_existing, - expected_profile=_PRESENTATION_PROFILE, - expected_cell_id=outcome.cell_id, - source_revision=outcome.source_revision, - accept_historical_source=accept_historical_source, - ) - ) - if only_if_replacing_failure: - replacement_target = existing - if replacement_target is None and not accept_historical_source: - historical = ( - None - if raw_existing is None - else _parse_presentation_outcome( - raw_existing, - expected_profile=_PRESENTATION_PROFILE, - expected_cell_id=outcome.cell_id, - source_revision=outcome.source_revision, - accept_historical_source=True, - ) - ) - if historical is not None and not historical.successful: - replacement_target = historical - if replacement_target is None or replacement_target.successful: - return False - if existing is not None and existing.ordering_key > outcome.ordering_key: - return False - _atomic_json(path, outcome.as_dict(), sync=False) - return True - - -def _publish_presentation_outcome( - service: ReportService, - outcome: LightweightPresentationOutcome, - *, - only_if_replacing_failure: bool = False, - catalog_validated: bool = False, -) -> bool: - """Atomically retain only the deterministically latest presentation outcome.""" - - with service.store.named_lock("manual-source-marker"): - source_policy = _recorded_measurement_source_policy_locked( - service, - checkout_revision=outcome.source_revision, - allow_missing=False, - ) - if ( - not source_policy.continue_across_revisions - and source_policy.source_revision != outcome.source_revision - ): - return False - with service.store.named_lock( - f"manual-presentation-outcome-{outcome.cell_id}" - ): - return _replace_presentation_outcome_locked( - service, - outcome, - accept_historical_source=( - source_policy.continue_across_revisions - ), - only_if_replacing_failure=only_if_replacing_failure, - catalog_validated=catalog_validated, - ) - - -def _publish_recycled_presentation_outcomes( - service: ReportService, - currents: Mapping[str, LightweightCurrent], - recycled_ids: Iterable[str], - *, - source_revision: str, - campaign_invocation_id: str, - accept_historical_source: bool = False, -) -> tuple[str, ...]: - """Publish front-end recycle outcomes that bypass scheduler observers.""" - - cells_by_id = { - cell.cell_id: cell for cell in service.catalog.measurement_cells() - } - warnings: list[str] = [] - for cell_id in sorted(set(recycled_ids)): - current = currents.get(cell_id) - if ( - current is None - or not current.reusable - or current.result.get("status") != ResultStatus.OK.value - ): - continue - cell = cells_by_id[cell_id] - observed = lightweight_presentation_outcome( - service, - cell, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - ) - if observed is not None and observed.successful: - continue - try: - with service.store.named_lock( - f"campaign-cell-{cell_id}", - timeout=0.0, - ): - _publish_presentation_outcome( - service, - LightweightPresentationOutcome( - profile=_PRESENTATION_PROFILE, - cell_id=cell_id, - source_revision=source_revision, - campaign_invocation_id=campaign_invocation_id, - attempt_id=current.attempt_id, - status="reused", - label="reused", - completed_at_ns=time.time_ns(), - ), - only_if_replacing_failure=True, - catalog_validated=True, - ) - except LockTimeoutError: - continue - except Exception as error: - warnings.append(f"{cell_id}: {type(error).__name__}: {error}") - return tuple(warnings) - - -def _presentation_failure_measurement( - outcome: LightweightPresentationOutcome, -) -> dict[str, object]: - try: - status = ResultStatus(outcome.status) - except ValueError: - status = ResultStatus.FAILED - # A durable ``unverified`` measurement is valid only when it is loaded - # from the exact authenticated sealed attempt below. Never synthesize an - # otherwise schema-invalid measured result from the tiny presentation - # ledger when that attempt is absent, malformed, or mismatched. - if status in { - ResultStatus.NOT_AVAILABLE, - ResultStatus.OK, - ResultStatus.UNVERIFIED, - }: - status = ResultStatus.FAILED - measurement = failure_measurement(status, outcome.label) - failure = measurement["failure"] - assert isinstance(failure, dict) - failure["kind"] = _PRESENTATION_FAILURE_KIND_PREFIX + outcome.status - return measurement - - -def _presentation_measurement( - service: ReportService, - cell: CellSpec, - outcome: LightweightPresentationOutcome, -) -> dict[str, object]: - """Return a presentation-only terminal measurement, failing closed. - - Unverified compiled/eager attempts are the sole terminal class whose - measured timings are useful. The tiny ledger supplies its exact attempt - UUID; the artifact store authenticates that sealed worker result without - scanning history. Every malformed or mismatched record falls back to the - ordinary compact terminal label. - """ - - if outcome.status != ResultStatus.UNVERIFIED.value or outcome.attempt_id is None: - return _presentation_failure_measurement(outcome) - try: - loaded = dict( - service.store.load_sealed_unsuccessful_worker_result( - cell.cell_id, - outcome.attempt_id, - ) - ) - if ( - loaded.get("status") != ResultStatus.UNVERIFIED.value - or not _result_matches_cell(loaded, cell) - or _measurement_source_revision(loaded) != outcome.source_revision - ): - raise ValueError("unverified result identity differs from presentation") - validate_measurement(loaded, expected_cell=cell) - except (OSError, TypeError, ValueError, ManifestValidationError): - return _presentation_failure_measurement(outcome) - return loaded - - -def _result_matches_cell( - result: Mapping[str, object], - cell: CellSpec, -) -> bool: - provenance = result.get("provenance") - manual = ( - provenance.get("manual_campaign") if isinstance(provenance, Mapping) else None - ) - identity = manual.get("cell_identity") if isinstance(manual, Mapping) else None - if not isinstance(identity, Mapping): - return False - expected = { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "workload": cell.workload.value, - "execution_mode": cell.measurement.execution_mode.value, - "model": ( - None if cell.measurement.model is None else cell.measurement.model.value - ), - "accuracy": cell.measurement.accuracy.value, - "backend": cell.measurement.backend, - "variant": cell.variant, - } - return all(identity.get(key) == value for key, value in expected.items()) - - -def _required_result_artifact_exists(result: Mapping[str, object]) -> bool: - if result.get("status") != ResultStatus.OK.value: - return True - artifact = result.get("artifact") - if not isinstance(artifact, Mapping): - return False - raw_path = artifact.get("path") - return isinstance(raw_path, str) and Path(raw_path).exists() - - -def _measurement_source_revision(result: Mapping[str, object]) -> str | None: - provenance = result.get("provenance") - revision = ( - provenance.get("report_source_revision") - if isinstance(provenance, Mapping) - else None - ) - return ( - revision - if isinstance(revision, str) - and _FULL_SOURCE_REVISION.fullmatch(revision) is not None - else None - ) - - -def _historical_numerical_relation_compatible( - cell: CellSpec, - result: Mapping[str, object], -) -> bool: - """Accept only historical results whose compact metadata proves safety.""" - - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - return True - provenance = result.get("provenance") - if not isinstance(provenance, Mapping): - return False - correctness = provenance.get("numerical_relation_correctness") - if isinstance(correctness, Mapping): - applied = correctness.get("applied_relation_count") - state = correctness.get("state") - if ( - correctness.get("abi") != _NUMERICAL_RELATION_CORRECTNESS_ABI - or isinstance(applied, bool) - or not isinstance(applied, int) - or applied < 0 - ): - return False - if state == "no-applied-relations": - return applied == 0 - if state == "member-scoped-v1": - return applied > 0 - return False - effective = provenance.get("effective_config") - generation = effective.get("generation") if isinstance(effective, Mapping) else None - relation = ( - generation.get("relation_discovery") - if isinstance(generation, Mapping) - else None - ) - return isinstance(relation, Mapping) and relation.get("mode") == "off" - - -def _legacy_numerical_authority_compatible( - cell: CellSpec, - result: Mapping[str, object], -) -> bool: - """Require the corrected legacy numerical path for affected currents. - - Older selected-flow measurements already used the generated library as - their numerical authority, and the special three-quark-line contracted - path remains a direct ``imode2`` measurement. Retain those inexpensive - metadata-identifiable currents while refreshing only the paths whose - authority changed. - """ - - if ( - cell.measurement.execution_mode is not ExecutionMode.AMPLICOL - or result.get("status") != ResultStatus.OK.value - ): - return True - from .legacy import ( - LEGACY_NUMERICAL_AUTHORITY_ABI, - LEGACY_NUMERICAL_AUTHORITY_FIELD, - ) - - validation = result.get("validation") - authority = ( - validation.get(LEGACY_NUMERICAL_AUTHORITY_FIELD) - if isinstance(validation, Mapping) - else None - ) - expected_sources = { - Workload.SELECTED_FLOW: {"selected-flow-generated-library"}, - Workload.ALL_FLOW: {"all-flow-selected-provider-replay"}, - Workload.CONTRACTED: { - "contracted-generated-library", - "direct-imode2-three-quark-line", - }, - } - if authority is not None: - return ( - isinstance(authority, Mapping) - and authority.get("abi") == LEGACY_NUMERICAL_AUTHORITY_ABI - and authority.get("source") - in expected_sources.get(cell.workload, set()) - ) - - provenance = result.get("provenance") - generation_source = ( - provenance.get("generation_source") - if isinstance(provenance, Mapping) - else None - ) - return ( - cell.workload is Workload.SELECTED_FLOW - and generation_source == "generated-library-create-mode-1" - ) or ( - cell.workload is Workload.CONTRACTED - and generation_source == "direct-imode2-three-quark-line-setup" - ) - - -def lightweight_current( - store: ArtifactStore, - cell: CellSpec, - *, - source_revision: str, - accept_historical_source: bool = False, -) -> LightweightCurrent | None: - """Read only the pointer, manifest metadata, and result required for reuse.""" - - root = store._cell_root(cell.cell_id) - pointer = _read_object(root / "current.json") - raw_attempt_id = None if pointer is None else pointer.get("attempt_id") - if ( - pointer is None - or pointer.get("schema") != store.current_schema - or pointer.get("cell_id") != cell.cell_id - or not isinstance(raw_attempt_id, str) - ): - return None - attempt_id = raw_attempt_id - try: - parsed_attempt_id = uuid.UUID(attempt_id) - except ValueError: - parsed_attempt_id = None - canonical_manifest = f"attempts/{attempt_id}/manifest.json" - manifest_sha256 = pointer.get("manifest_sha256") - if ( - parsed_attempt_id is None - or str(parsed_attempt_id) != attempt_id - or pointer.get("manifest_path") != canonical_manifest - or not isinstance(manifest_sha256, str) - or len(manifest_sha256) != 64 - or any(character not in "0123456789abcdef" for character in manifest_sha256) - ): - return LightweightCurrent( - cell.cell_id, - attempt_id, - root, - {}, - False, - False, - "incomplete pointer metadata", - ) - manifest_path = root / canonical_manifest - manifest = _read_object(manifest_path) - if ( - manifest is None - or manifest.get("schema") != ATTEMPT_SCHEMA - or manifest.get("cell_id") != cell.cell_id - or manifest.get("attempt_id") != attempt_id - or manifest.get("status") != "ok" - or manifest.get("error") is not None - or not isinstance(manifest.get("result_path"), str) - ): - return LightweightCurrent( - cell.cell_id, - attempt_id, - root, - {}, - False, - False, - "incomplete metadata", - ) - try: - artifact_policy = ArtifactPolicy(str(manifest.get("artifact_policy"))) - except ValueError: - return LightweightCurrent( - cell.cell_id, - attempt_id, - manifest_path, - {}, - False, - False, - "unsupported artifact policy", - ) - relative = Path(str(manifest["result_path"])) - if ( - relative.is_absolute() - or not relative.parts - or any(part in {"", ".", ".."} for part in relative.parts) - ): - return LightweightCurrent( - cell.cell_id, - attempt_id, - root, - {}, - False, - False, - "unsafe result path", - ) - artifact_records = manifest.get("artifacts") - if not isinstance(artifact_records, list) or not any( - isinstance(record, Mapping) and record.get("path") == relative.as_posix() - for record in artifact_records - ): - return LightweightCurrent( - cell.cell_id, - attempt_id, - manifest_path, - {}, - False, - False, - "result missing from manifest", - ) - result_path = root / "attempts" / attempt_id / relative - result = _read_object(result_path) - if result is None: - return LightweightCurrent( - cell.cell_id, - attempt_id, - result_path, - {}, - False, - False, - "result unreadable", - ) - try: - result = dict(store.materialize_current_result(result)) - except ManifestValidationError: - return LightweightCurrent( - cell.cell_id, - attempt_id, - result_path, - {}, - False, - False, - "unsafe result locator", - ) - revision = _measurement_source_revision(result) - revision_valid = revision is not None - status = str(result.get("status", "")) - complete = status in { - ResultStatus.OK.value, - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - } - measurement_valid = False - if complete: - try: - validate_measurement(result, expected_cell=cell) - except ValueError: - pass - else: - measurement_valid = True - complete = complete and measurement_valid - cell_match = _result_matches_cell(result, cell) - artifact_exists = _required_result_artifact_exists(result) - historical_relation_compatible = ( - revision == source_revision - or not revision_valid - or _historical_numerical_relation_compatible(cell, result) - ) - legacy_authority_compatible = _legacy_numerical_authority_compatible( - cell, - result, - ) - source_accepted = revision == source_revision or ( - accept_historical_source and revision_valid and historical_relation_compatible - ) - reusable = ( - complete - and source_accepted - and cell_match - and artifact_exists - and legacy_authority_compatible - ) - if status not in { - ResultStatus.OK.value, - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - }: - reason = "incomplete status" - elif not measurement_valid: - reason = "invalid measurement schema" - elif not revision_valid: - reason = "invalid source revision" - elif revision != source_revision and not accept_historical_source: - reason = "source mismatch" - elif revision != source_revision and not historical_relation_compatible: - reason = "historical numerical-relation policy is not reusable" - elif not legacy_authority_compatible: - reason = "legacy numerical authority requires refresh" - elif not cell_match: - reason = "cell metadata mismatch" - elif not artifact_exists: - reason = "required artifact missing" - elif status in {ResultStatus.TIMEOUT.value, ResultStatus.MEMORY_LIMIT.value}: - reason = ( - "historical resource-capped terminal" - if revision != source_revision - else "resource-capped terminal" - ) - elif revision != source_revision: - reason = "historical source current" - else: - reason = "reusable" - record = ( - CurrentRecord( - cell_id=cell.cell_id, - attempt_id=attempt_id, - manifest_path=manifest_path, - manifest_sha256=manifest_sha256, - result_path=result_path, - result=result, - artifacts=(), - artifact_policy=artifact_policy, - ) - if complete - else None - ) - return LightweightCurrent( - cell.cell_id, - attempt_id, - result_path, - result, - complete, - reusable, - reason, - record, - ) - - -def lightweight_currents( - service: ReportService, - cells: Sequence[CellSpec], - *, - source_revision: str, - accept_historical_source: bool = False, - progress: Callable[[int, int], None] | None = None, -) -> dict[str, LightweightCurrent]: - result: dict[str, LightweightCurrent] = {} - total = len(cells) - for completed, cell in enumerate(cells, start=1): - current = lightweight_current( - service.store, - cell, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - ) - if current is not None: - result[cell.cell_id] = current - if progress is not None: - progress(completed, total) - return result - - -def _selective_retry_requested(arguments: argparse.Namespace) -> bool: - return bool( - getattr(arguments, "rerun_failed", False) - or getattr(arguments, "rerun_capped", False) - ) - - -def _fresh_attempt_requested(arguments: argparse.Namespace) -> bool: - return bool( - getattr(arguments, "force_refresh", False) - or _selective_retry_requested(arguments) - ) - - -def _artifact_cleanup_enabled(arguments: argparse.Namespace) -> bool: - """Compact disposable payloads unless full debug workspaces were requested.""" - - return not bool(getattr(arguments, "retain_workspaces", False)) - - -def _selective_retry_category( - current: LightweightCurrent | None, - outcome: LightweightPresentationOutcome | None, -) -> str | None: - """Classify the latest reusable terminal for selective retry. - - Tiny presentation outcomes are authoritative for ordering, but a cap is - trusted only when it names the exact attempt of a validated reusable cap - current. This keeps future/unauthenticated timeout-like slugs in the - ordinary failure class rather than silently granting them policy meaning. - """ - - cap_state: PolicyMeasurementState | None = None - current_state: PolicyMeasurementState | None = None - if current is not None and current.reusable: - current_state = policy_measurement_state_hint(current.result) - if ( - current_state in _TERMINAL_CAP_STATES - and policy_status_label(current.result) is not None - ): - cap_state = current_state - - if outcome is not None: - if outcome.successful: - return None - if ( - cap_state is not None - and current is not None - and outcome.attempt_id == current.attempt_id - and outcome.status == cap_state.value - ): - return "capped" - return "failed" - - if current is None or not current.reusable: - return None - if current_state is PolicyMeasurementState.SUCCESS: - return None - return "capped" if cap_state is not None else "failed" - - -def _selective_retry_cells( - cells: Sequence[CellSpec], - currents: Mapping[str, LightweightCurrent], - outcomes: Mapping[str, LightweightPresentationOutcome], - *, - rerun_failed: bool, - rerun_capped: bool, -) -> tuple[CellSpec, ...]: - selected_categories = { - category - for category, enabled in ( - ("failed", rerun_failed), - ("capped", rerun_capped), - ) - if enabled - } - return tuple( - cell - for cell in cells - if _selective_retry_category( - currents.get(cell.cell_id), - outcomes.get(cell.cell_id), - ) - in selected_categories - ) - - -def _source_cohort_counts( - currents: Mapping[str, LightweightCurrent], - *, - cell_ids: set[str] | None = None, -) -> dict[str, int]: - counts: Counter[str] = Counter() - for cell_id, current in currents.items(): - if cell_ids is not None and cell_id not in cell_ids: - continue - if not current.reusable: - continue - revision = _measurement_source_revision(current.result) - if revision is not None: - counts[revision] += 1 - return dict(sorted(counts.items())) - - -def _format_source_cohorts(cohorts: Mapping[str, int]) -> str: - return ( - ", ".join(f"{revision}={count}" for revision, count in cohorts.items()) - or "none" - ) - - -def _lightweight_current_resolver( - service: ReportService, - *, - source_revision: str, - initial: Mapping[str, LightweightCurrent] | None = None, -) -> Callable[ - [CellSpec], - tuple[CurrentRecord, PolicyMeasurementState] | None, -]: - """Resolve planner currents from cheap metadata without artifact hashing.""" - - cache: dict[str, LightweightCurrent | None] = dict(initial or {}) - - def resolve( - cell: CellSpec, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if cell.cell_id not in cache: - cache[cell.cell_id] = lightweight_current( - service.store, - cell, - source_revision=source_revision, - ) - current = cache[cell.cell_id] - if current is None or not current.reusable or current.record is None: - return None - state = policy_measurement_state_hint(current.result) - return None if state is None else (current.record, state) - - return resolve - - -def _installed_source_revision() -> str | None: - try: - from pyamplicol._internal.versions import ( - active_source_revision, - package_version, - ) - except (ImportError, RuntimeError, ValueError) as error: - raise ManualCampaignError( - f"measurement runtime provenance cannot be loaded: {error}; rerun " - "`just dev-install`" - ) from error - try: - package_version() - return active_source_revision() - except (RuntimeError, ValueError) as error: - raise ManualCampaignError( - f"measurement runtime provenance check failed: {error}" - ) from error - - -def require_measurement_ready(source: ReportSourceIdentity) -> None: - if not source.eligible: - examples = ", ".join(source.dirty_paths[:5]) - remainder = max(0, len(source.dirty_paths) - 5) - suffix = "" if remainder == 0 else f", … {remainder} more" - raise ManualCampaignError( - "measurement source is not a clean committed checkout " - f"({examples}{suffix}); commit the campaign implementation and " - "rebuild before running measurements" - ) - installed = _installed_source_revision() - if installed is None: - raise ManualCampaignError( - "measurement runtime contains no clean source revision for this " - f"checkout ({source.revision}); rebuild it with `just dev-install` " - "after committing evaluator-source changes. Copied profiling " - "campaigns and generated report outputs do not invalidate the build." - ) - if installed != source.revision: - raise ManualCampaignError( - "measurement runtime is not a clean build of this checkout: " - f"checkout={source.revision}, installed={installed}. Commit the " - "implementation, ensure the worktree is clean, then run " - "`just dev-install`; dirty-build evidence is never reusable." - ) - - -def _source_marker_path(service: ReportService) -> Path: - return service.paths.coordination_root / "manual-source.json" - - -def update_source_marker( - service: ReportService, - source: ReportSourceIdentity, - *, - continue_across_revisions: bool = False, -) -> bool: - """Record the active source and lightweight publication policy once.""" - - path = _source_marker_path(service) - with service.store.named_lock("manual-source-marker"): - previous = _read_object(path) - changed = previous is not None and ( - previous.get("source_revision") != source.revision - or previous.get("continue_across_revisions", False) - != continue_across_revisions - ) - _atomic_json( - path, - { - "schema": SOURCE_MARKER_SCHEMA, - "source_revision": source.revision, - "continue_across_revisions": continue_across_revisions, - "recorded_at_utc": _utc_now(), - }, - ) - return changed - - -def recorded_measurement_source_policy( - service: ReportService, - *, - checkout_revision: str, -) -> RecordedSourcePolicy: - """Read the recorded measurement epoch and its lightweight reuse policy. - - Renderer-only commits must not make already published measurements vanish. - Real campaign runs update this marker only after the checkout and installed - runtime have passed the strict measurement-readiness checks. The optional - continuation policy lets read-only views merge per-cell currents from more - than one valid recorded source revision without weakening active-revision - dependency planning. - """ - - with service.store.named_lock("manual-source-marker"): - return _recorded_measurement_source_policy_locked( - service, - checkout_revision=checkout_revision, - allow_missing=True, - ) - - -def _recorded_measurement_source_policy_locked( - service: ReportService, - *, - checkout_revision: str, - allow_missing: bool, -) -> RecordedSourcePolicy: - """Decode the source marker while its named lock is already held.""" - - path = _source_marker_path(service) - exists = path.exists() - marker = _read_object(path) - if marker is None: - if exists or not allow_missing: - raise ManualCampaignError( - f"campaign source marker is unreadable: {path}; refusing to " - "guess which measurement cohort to publish" - ) - return RecordedSourcePolicy(checkout_revision) - revision = marker.get("source_revision") - continue_across_revisions = marker.get("continue_across_revisions", False) - if ( - marker.get("schema") != SOURCE_MARKER_SCHEMA - or not isinstance(revision, str) - or _FULL_SOURCE_REVISION.fullmatch(revision) is None - or not isinstance(continue_across_revisions, bool) - ): - raise ManualCampaignError( - f"campaign source marker is malformed: {path}; refusing to guess " - "which measurement cohort to publish" - ) - return RecordedSourcePolicy(revision, continue_across_revisions) - - -def recorded_measurement_source_revision( - service: ReportService, - *, - checkout_revision: str, -) -> str: - """Return the active recorded measurement revision for compatibility.""" - - return recorded_measurement_source_policy( - service, - checkout_revision=checkout_revision, - ).source_revision - - -@dataclass(slots=True) -class _IncrementalTailState: - identity: tuple[int, int] | None = None - offset: int = 0 - pending: bytes = b"" - last_read_bytes: int = 0 - - -@dataclass(frozen=True, slots=True) -class PhaseTimelineRow: - """One normalized, presentation-only phase record from persisted evidence.""" - - phase: str - wall_seconds: float | None = None - cpu_seconds: float | None = None - peak_memory_bytes: int | None = None - status: str | None = None - detail: str | None = None - - -@dataclass(slots=True) -class WorkerView: - cell_id: str - dependency: bool = False - peer_instance: str | None = None - generation_engine: str | None = None - status: str = "queued" - step: str = "waiting" - phase: str = "preparation" - attempt_id: str | None = None - pid: int | None = None - member_pids: tuple[int, ...] = () - wall_seconds: float = 0.0 - cpu_seconds: float | None = None - current_rss_bytes: int = 0 - peak_rss_bytes: int = 0 - current_physical_footprint_bytes: int | None = None - peak_physical_footprint_bytes: int | None = None - current_guard_bytes: int = 0 - peak_guard_bytes: int = 0 - child_count: int = 0 - progress_completed: int | None = None - progress_total: int | None = None - progress_message: str = "" - progress_task_id: str | None = None - progress_details: dict[str, object] = field(default_factory=dict) - log_path: str | None = None - progress_path: str | None = None - reproduce_prepare: str | None = None - reproduce_generate: str | None = None - reproduce_profile: str | None = None - published_wall_seconds_per_point: float | None = None - published_evaluator_total_seconds_per_point: float | None = None - published_recurrence_core_seconds_per_point: float | None = None - phase_timeline: tuple[PhaseTimelineRow, ...] = () - provenance_summary: str | None = None - reuse_explanation: str | None = None - blocked_prerequisite_ids: tuple[str, ...] = () - recycled: bool = False - events: list[str] = field(default_factory=list) - log_tail: list[str] = field(default_factory=list) - updated_at: float = field(default_factory=time.time) - _progress_tail_state: _IncrementalTailState = field( - default_factory=_IncrementalTailState, - repr=False, - ) - _log_tail_state: _IncrementalTailState = field( - default_factory=_IncrementalTailState, - repr=False, - ) - - def as_dict(self) -> dict[str, object]: - payload = asdict(self) - payload.pop("_progress_tail_state", None) - payload.pop("_log_tail_state", None) - return payload - - -@dataclass(slots=True) -class DashboardState: - instance_id: str - selected_ids: tuple[str, ...] - recycled_ids: set[str] - static_na_ids: set[str] - source_revision: str = "" - generation_time_limit_seconds: float = DEFAULT_GENERATION_LIMIT_SECONDS - memory_limit_bytes: int = DEFAULT_RAM_BYTES - worker_wall_limit_seconds: float | None = DEFAULT_WORKER_WALL_LIMIT_SECONDS - reproduction_settings: ReproductionSettings = field( - default_factory=ReproductionSettings - ) - dependency_ids: set[str] = field(default_factory=set) - workers: dict[str, WorkerView] = field(default_factory=dict) - terminal_outcomes: dict[str, _DashboardTerminalOutcome] = field( - default_factory=dict - ) - selected_index: int = 0 - detail_scroll: int = 0 - show_completed: bool = False - show_errors: bool = True - show_help: bool = False - command_stage: str | None = None - command_scroll: int = 0 - command_notice: str | None = None - pending_clipboard: tuple[str, str] | None = None - pending_print: tuple[str, str] | None = None - started_at: float = field(default_factory=time.time) - interrupted: bool = False - counter_snapshot: dict[str, int] | None = None - lease_updated_at: float | None = None - live_snapshot: bool = False - ready_count: int = 0 - waiting_dependency_count: int = 0 - waiting_coordination_lock_count: int = 0 - cleanup_warnings: list[tuple[str, str]] = field(default_factory=list) - invocation_evidence_ids: set[str] = field(default_factory=set) - - def _clear_cell_disposition(self, cell_id: str) -> None: - self.terminal_outcomes.pop(cell_id, None) - self.recycled_ids.discard(cell_id) - - def _reduce_started(self, cell_id: str, *, dependency: bool) -> WorkerView: - """Apply one started event and return a wholly fresh worker view.""" - - self._clear_cell_disposition(cell_id) - worker = WorkerView( - cell_id, - dependency=dependency, - status="preparing", - step="dependency preparation", - phase="preparation", - ) - self.workers[cell_id] = worker - return worker - - def _reduce_finished( - self, - cell_id: str, - status: str, - *, - recycled: bool = False, - ) -> None: - """Reduce a finished event into one normalized terminal category.""" - - self._clear_cell_disposition(cell_id) - if recycled or status in _RECYCLED_SUCCESS_STATUSES: - self.recycled_ids.add(cell_id) - if status in _SUMMARY_SUCCESS_STATUSES: - outcome = _DashboardTerminalOutcome.SUCCESS - elif status in _TERMINAL_CAP_STATUSES: - outcome = _DashboardTerminalOutcome.CAPPED - elif status == ResultStatus.UNVERIFIED.value: - outcome = _DashboardTerminalOutcome.UNVERIFIED - elif status != "cancelled": - outcome = _DashboardTerminalOutcome.FAILED - else: - return - self.terminal_outcomes[cell_id] = outcome - - @property - def completed_ids(self) -> set[str]: - return { - cell_id - for cell_id, outcome in self.terminal_outcomes.items() - if cell_id not in self.recycled_ids - and outcome is _DashboardTerminalOutcome.SUCCESS - } - - @property - def capped_ids(self) -> set[str]: - return { - cell_id - for cell_id, outcome in self.terminal_outcomes.items() - if outcome is _DashboardTerminalOutcome.CAPPED - } - - @property - def failed_ids(self) -> set[str]: - return { - cell_id - for cell_id, outcome in self.terminal_outcomes.items() - if outcome is _DashboardTerminalOutcome.FAILED - } - - @property - def unverified_ids(self) -> set[str]: - return { - cell_id - for cell_id, outcome in self.terminal_outcomes.items() - if outcome is _DashboardTerminalOutcome.UNVERIFIED - } - - @property - def active(self) -> tuple[WorkerView, ...]: - """Return active work owned by this invocation only. - - Peer leases are rendered to make cross-process activity observable, but - they must not inflate the primary ``Active`` counter for this runner. - """ - - return tuple( - worker - for worker in self.workers.values() - if worker.peer_instance is None and worker.status in _ACTIVE_WORKER_STATUSES - ) - - @property - def peer_active(self) -> tuple[WorkerView, ...]: - """Return visible active work owned by concurrent peer invocations.""" - - return tuple( - worker - for worker in self.workers.values() - if worker.peer_instance is not None - and worker.status in _ACTIVE_WORKER_STATUSES - ) - - def visible_workers(self) -> tuple[WorkerView, ...]: - """Return the single ordered worker view used by table and details.""" - - def rank(worker: WorkerView) -> tuple[int, str, str]: - status_rank = { - "running": 0, - "preparing": 1, - "queued": 2, - }.get( - worker.status, - 4 if worker.status in _COMPLETED_WORKER_STATUSES else 3, - ) - return status_rank, worker.cell_id, worker.peer_instance or "" - - return tuple( - sorted( - ( - worker - for worker in self.workers.values() - if ( - self.show_completed - or worker.status not in _COMPLETED_WORKER_STATUSES - ) - and ( - self.show_errors - or worker.status in _ACTIVE_WORKER_STATUSES - or worker.status in _COMPLETED_WORKER_STATUSES - ) - ), - key=rank, - ) - ) - - def counters(self) -> dict[str, int]: - """Return one snapshot with non-overlapping selection dispositions. - - ``Selected`` progress is one exclusive partition. Active work is not - a terminal disposition, so it remains in ``remaining`` until it - finishes. Slot utilisation deliberately spans direct and dependency - work, and is exposed separately as ``active`` with an explicit split. - """ - - if self.counter_snapshot is not None: - return dict(self.counter_snapshot) - selected = set(self.selected_ids) - recycled_ids = self.recycled_ids & selected - selected_outcomes = { - cell_id: outcome - for cell_id, outcome in self.terminal_outcomes.items() - if cell_id in selected and cell_id not in recycled_ids - } - selected_terminal_ids = set(selected_outcomes) - static_na_ids = ( - (self.static_na_ids & selected) - - recycled_ids - - selected_terminal_ids - ) - remaining_ids = selected - recycled_ids - selected_terminal_ids - static_na_ids - dependency_only_ids = self.dependency_ids - selected - active_ids = {worker.cell_id for worker in self.active} - selected_active_ids = active_ids & selected - dependency_active_ids = active_ids & dependency_only_ids - dependency_outcomes = { - cell_id: outcome - for cell_id, outcome in self.terminal_outcomes.items() - if cell_id in dependency_only_ids - } - dependency_completed = sum( - outcome is _DashboardTerminalOutcome.SUCCESS - for outcome in dependency_outcomes.values() - ) - dependency_issues = sum( - outcome is not _DashboardTerminalOutcome.SUCCESS - for outcome in dependency_outcomes.values() - ) - return { - "selected": len(self.selected_ids), - "recycled": len(recycled_ids), - "active": len(active_ids), - "selected_active": len(selected_active_ids), - "dependency_active": len(dependency_active_ids), - "completed": sum( - outcome is _DashboardTerminalOutcome.SUCCESS - for outcome in selected_outcomes.values() - ), - "remaining": len(remaining_ids), - "static_na": len(static_na_ids), - "capped": sum( - outcome is _DashboardTerminalOutcome.CAPPED - for outcome in selected_outcomes.values() - ), - "failed": sum( - outcome is _DashboardTerminalOutcome.FAILED - for outcome in selected_outcomes.values() - ), - "unverified": sum( - outcome is _DashboardTerminalOutcome.UNVERIFIED - for outcome in selected_outcomes.values() - ), - "dependency_only": len(dependency_only_ids), - "dependency_completed": dependency_completed, - "dependency_issues": dependency_issues, - } - - def selected_worker(self) -> WorkerView | None: - rows = self.visible_workers() - if not rows: - self.selected_index = 0 - return None - self.selected_index %= len(rows) - return rows[self.selected_index] - - -class LeaseManager: - """Publish compact atomic informational state for concurrent dashboards.""" - - def __init__( - self, - service: ReportService, - state: DashboardState, - ) -> None: - self.service = service - self.state = state - self._guard = threading.Lock() - self._closed = False - self.path = ( - service.paths.coordination_root - / "manual-leases" - / f"{state.instance_id}.json" - ) - - def _write(self) -> None: - if self._closed: - return - _atomic_json( - self.path, - { - "schema": MANUAL_STATE_SCHEMA, - "instance_id": self.state.instance_id, - "controller_pid": os.getpid(), - "source_revision": self.state.source_revision, - "started_at": self.state.started_at, - "updated_at": time.time(), - "counters": self.state.counters(), - "limits": { - "generation_time_limit_seconds": ( - self.state.generation_time_limit_seconds - ), - "memory_limit_bytes": self.state.memory_limit_bytes, - "worker_wall_limit_seconds": (self.state.worker_wall_limit_seconds), - }, - "scheduler": { - "ready": self.state.ready_count, - "waiting_dependency": self.state.waiting_dependency_count, - "waiting_coordination_lock": ( - self.state.waiting_coordination_lock_count - ), - }, - "workers": { - key: worker.as_dict() - for key, worker in sorted(self.state.workers.items()) - if worker.peer_instance is None - }, - }, - ) - - def publish(self) -> None: - with self._guard: - self._write() - - def dashboard_snapshot(self) -> DashboardState: - with self._guard: - _merge_peer_workers(self.service, self.state) - return copy.deepcopy(self.state) - - def observe(self, payload: Mapping[str, object]) -> None: - event = str(payload.get("event", "update")) - with self._guard: - if self._closed: - return - if event == "scheduler-state": - self.state.ready_count = max( - 0, - _optional_int(payload.get("ready")) or 0, - ) - self.state.waiting_dependency_count = max( - 0, - _optional_int(payload.get("waiting_dependency")) or 0, - ) - self.state.waiting_coordination_lock_count = max( - 0, - _optional_int(payload.get("waiting_coordination_lock")) or 0, - ) - self._write() - return - cell_id = str(payload.get("cell_id", "")) - if not cell_id: - return - if event == "preflight-finished": - attempt_id = str(payload.get("attempt_id") or "") - worker = self.state.workers.get(cell_id) - if worker is not None and worker.attempt_id == attempt_id: - del self.state.workers[cell_id] - self._write() - return - worker = self.state.workers.setdefault(cell_id, WorkerView(cell_id)) - worker.updated_at = time.time() - cleanup_detail: str | None = None - if event == "started": - self.state.invocation_evidence_ids.add(cell_id) - worker = self.state._reduce_started( - cell_id, - dependency=bool(payload.get("dependency", False)), - ) - try: - cell = self.service.catalog.cell(cell_id) - except KeyError: - cell = None - if cell is not None: - worker.generation_engine = cell.measurement.execution_mode.value - settings = self.state.reproduction_settings - recipe = reproduction_recipe( - cell, - repo_root=self.service.paths.repo_root, - artifact_root=self.service.paths.artifact_root, - cores=settings.cores, - target_runtime=settings.target_runtime, - batch_size=settings.batch_size, - warmups=settings.warmups, - minimum_samples=settings.minimum_samples, - ) - worker.reproduce_prepare = ( - None if recipe.prepare is None else _shell_join(recipe.prepare) - ) - worker.reproduce_generate = ( - None - if recipe.generate is None - else _shell_join(recipe.generate) - ) - worker.reproduce_profile = ( - None if recipe.profile is None else _shell_join(recipe.profile) - ) - elif event == "worker": - if worker.status not in _ACTIVE_WORKER_STATUSES: - self._write() - return - self.state.invocation_evidence_ids.add(cell_id) - worker.status = "running" - worker.step = "worker launched" - worker.attempt_id = str(payload.get("attempt_id") or "") or None - worker.log_path = str(payload.get("log_path") or "") or None - worker.progress_path = str(payload.get("progress_path") or "") or None - elif event == "resource": - resource_attempt_id = str(payload.get("attempt_id") or "") or None - if worker.status not in _ACTIVE_WORKER_STATUSES or ( - resource_attempt_id is not None - and resource_attempt_id != worker.attempt_id - ): - self._write() - return - self.state.invocation_evidence_ids.add(cell_id) - worker.status = "running" - worker.pid = _optional_int(payload.get("pid")) - worker.member_pids = tuple( - int(value) for value in payload.get("member_pids", ()) - ) - worker.phase = str(payload.get("phase") or "unknown") - worker.step = worker.phase.replace("_", " ") - worker.wall_seconds = _finite_float(payload.get("wall_seconds")) - worker.cpu_seconds = _optional_finite_float(payload.get("cpu_seconds")) - worker.current_rss_bytes = ( - _optional_int(payload.get("current_rss_bytes")) or 0 - ) - worker.peak_rss_bytes = ( - _optional_int(payload.get("peak_rss_bytes")) or 0 - ) - worker.current_physical_footprint_bytes = _optional_int( - payload.get("current_physical_footprint_bytes") - ) - worker.peak_physical_footprint_bytes = _optional_int( - payload.get("peak_physical_footprint_bytes") - ) - worker.current_guard_bytes = ( - _optional_int(payload.get("current_guard_bytes")) or 0 - ) - worker.peak_guard_bytes = ( - _optional_int(payload.get("peak_guard_bytes")) or 0 - ) - worker.child_count = _optional_int(payload.get("child_count")) or 0 - _tail_progress(worker) - _tail_log(worker) - elif event == "finished": - reported_status = str(payload.get("status") or "unknown") - reported_detail = str(payload.get("detail") or "") - raw_terminal_detail = payload.get("terminal_detail") - reported_terminal_detail = ( - raw_terminal_detail - if isinstance(raw_terminal_detail, str) - else None - ) - outcome_attempt_id = worker.attempt_id - reported_attempt_id = _canonical_attempt_uuid(outcome_attempt_id) - if reported_attempt_id is None: - reported_attempt_id = _canonical_attempt_uuid(reported_detail) - reported_success = reported_status in _SUMMARY_SUCCESS_STATUSES - if not ( - reported_status == "cancelled" - and reported_detail in {"not started", "lock wait cancelled"} - ): - self.state.invocation_evidence_ids.add(cell_id) - worker.status = ( - "recycled" - if reported_status in _RECYCLED_SUCCESS_STATUSES - else reported_status - ) - worker.recycled = reported_status in _RECYCLED_SUCCESS_STATUSES - worker.step = reported_detail or worker.status - raw_prerequisites = payload.get("prerequisite_cell_ids") - if isinstance(raw_prerequisites, Sequence) and not isinstance( - raw_prerequisites, - (str, bytes), - ): - worker.blocked_prerequisite_ids = tuple( - sorted( - { - str(value) - for value in raw_prerequisites - if isinstance(value, str) and value - } - ) - ) - try: - cell = self.service.catalog.cell(cell_id) - except KeyError: - cell = None - current: LightweightCurrent | None = None - terminal_result: Mapping[str, object] | None = None - if cell is not None: - worker.generation_engine = cell.measurement.execution_mode.value - current = lightweight_current( - self.service.store, - cell, - source_revision=self.state.source_revision, - ) - current_is_observed_attempt = ( - current is not None - and current.complete - and ( - reported_success - or reported_attempt_id == current.attempt_id - ) - ) - if current_is_observed_attempt: - assert current is not None - terminal_result = current.result - worker.attempt_id = current.attempt_id - _apply_persisted_worker_result( - worker, - current.result, - recycled=worker.recycled, - reuse_explanation=( - current.reason if worker.recycled else None - ), - ) - worker.published_wall_seconds_per_point = _number( - current.result, - "wall_seconds_per_point", - ) - worker.published_evaluator_total_seconds_per_point = ( - _evaluator_total_number(current.result) - ) - worker.published_recurrence_core_seconds_per_point = ( - _recurrence_core_number(current.result) - ) - provenance = current.result.get("provenance") - manual = ( - provenance.get("manual_campaign") - if isinstance(provenance, Mapping) - else None - ) - recipe = ( - manual.get("public_cli_reproduction") - if isinstance(manual, Mapping) - else None - ) - if isinstance(recipe, Mapping): - worker.reproduce_prepare = _stored_reproduction_command( - recipe, - "prepare", - ) - worker.reproduce_generate = _stored_reproduction_command( - recipe, - "generate", - ) - worker.reproduce_profile = _stored_reproduction_command( - recipe, - "profile", - ) - terminal_step = _concise_terminal_step(reported_terminal_detail) - if terminal_step is None and terminal_result is not None: - terminal_step = _terminal_result_step(terminal_result) - if terminal_step is not None: - worker.step = terminal_step - if worker.recycled and worker.reuse_explanation is None: - worker.reuse_explanation = worker.step - _tail_progress(worker) - _tail_log(worker) - self.state._reduce_finished( - cell_id, - worker.status, - recycled=worker.recycled, - ) - successful_current = ( - current - if reported_success - and current is not None - and current.reusable - and current.result.get("status") == ResultStatus.OK.value - else None - ) - if ( - cell is not None - and reported_status != ResultStatus.NOT_AVAILABLE.value - and (not reported_success or successful_current is not None) - and not ( - reported_status == "cancelled" - and reported_detail in {"not started", "lock wait cancelled"} - ) - ): - normalized_status = ( - reported_status - if _SAFE_OUTCOME_SLUG.fullmatch(reported_status) is not None - else _summary_status(reported_status) - ) - attempt_id = _canonical_attempt_uuid( - None - if successful_current is None - else successful_current.attempt_id - ) - if attempt_id is None: - attempt_id = _canonical_attempt_uuid(outcome_attempt_id) - if attempt_id is None: - attempt_id = _canonical_attempt_uuid(reported_detail) - label = _humanized_outcome_label(normalized_status) - if ( - current is not None - and attempt_id is not None - and current.attempt_id == attempt_id - ): - label = policy_status_label(current.result) or label - completed_at_ns = ( - _optional_int(payload.get("completed_at_ns")) or time.time_ns() - ) - try: - _publish_presentation_outcome( - self.service, - LightweightPresentationOutcome( - profile=_PRESENTATION_PROFILE, - cell_id=cell_id, - source_revision=self.state.source_revision, - campaign_invocation_id=self.state.instance_id, - attempt_id=attempt_id, - status=normalized_status, - label=label, - completed_at_ns=completed_at_ns, - ), - only_if_replacing_failure=reported_success, - catalog_validated=True, - ) - except Exception as error: - worker.events.append( - "presentation outcome warning: " - f"{type(error).__name__}: {error}" - ) - elif event == "cleanup-warning": - cleanup_detail = str(payload.get("detail") or "unknown cleanup error") - warning = (cell_id, cleanup_detail) - if warning not in self.state.cleanup_warnings: - self.state.cleanup_warnings.append(warning) - observed_event = ( - f"cleanup warning: {cleanup_detail}" - if cleanup_detail is not None - else ( - f"resource: {worker.phase}" - if event == "resource" - else f"{event}: {worker.step}" - ) - ) - if not ( - event == "resource" - and worker.events - and worker.events[-1] == observed_event - ): - worker.events.append(observed_event) - del worker.events[:-8] - self._write() - - def close(self) -> None: - with self._guard: - self._closed = True - self.path.unlink(missing_ok=True) - - -@dataclass(frozen=True, slots=True) -class _FailFastTerminalFailure: - observed_at_utc: str - cell_id: str - status: str - detail: str - terminal_detail: str | None - completed_at_ns: int | None - - -@dataclass(frozen=True, slots=True) -class _FailFastReport: - text: str - cell_id: str - attempt_root: str | None - artifact_path: str | None - worker_log_path: str | None - worker_progress_path: str | None - - -class _FailFastObserver: - """Turn the first terminal failure event into the campaign stop signal.""" - - def __init__( - self, - delegate: Callable[[Mapping[str, object]], None], - cancellation: threading.Event, - ) -> None: - self._delegate = delegate - self._cancellation = cancellation - self._guard = threading.Lock() - self._failure: _FailFastTerminalFailure | None = None - - @property - def failure(self) -> _FailFastTerminalFailure | None: - with self._guard: - return self._failure - - def observe(self, payload: Mapping[str, object]) -> None: - if payload.get("event") == "finished": - status = str(payload.get("status") or "unknown") - if status not in _FAIL_FAST_SUCCESS_STATUSES and status != "cancelled": - with self._guard: - if self._failure is None and not self._cancellation.is_set(): - raw_terminal_detail = payload.get("terminal_detail") - raw_completed_at_ns = payload.get("completed_at_ns") - self._failure = _FailFastTerminalFailure( - observed_at_utc=_utc_now(), - cell_id=str(payload.get("cell_id") or ""), - status=status, - detail=str(payload.get("detail") or ""), - terminal_detail=( - raw_terminal_detail - if isinstance(raw_terminal_detail, str) - else None - ), - completed_at_ns=( - raw_completed_at_ns - if isinstance(raw_completed_at_ns, int) - and not isinstance(raw_completed_at_ns, bool) - else None - ), - ) - # The scheduler consults this same event before filling - # another slot, and live supervisors consult it while - # sampling their process trees. - self._cancellation.set() - self._delegate(payload) - - -def _attempt_failure_evidence( - service: ReportService, - *, - cell_id: str, - attempt_id: str | None, -) -> tuple[Path | None, Mapping[str, object] | None]: - if attempt_id is None: - return None, None - current: CurrentRecord | None = None - with suppress(Exception): - current = service.store.load_current(cell_id, missing_ok=True) - if current is not None and current.attempt_id == attempt_id: - return current.manifest_path.parent, current.result - - live_root: Path | None = None - archived_root: Path | None = None - with suppress(Exception): - live_root = service.store._existing_live_attempt_root(cell_id, attempt_id) - with suppress(Exception): - archived_root = service.store._existing_archived_attempt_root( - cell_id, - attempt_id, - ) - roots = tuple(root for root in (live_root, archived_root) if root is not None) - root = roots[0] if len(roots) == 1 else None - result: Mapping[str, object] | None = None - with suppress(Exception): - result = service.store.load_sealed_unsuccessful_worker_result( - cell_id, - attempt_id, - ) - return root, result - - -def _fail_fast_report_value(value: object) -> str: - if value is None: - return "" - text = str(value) - return text if text else "" - - -def _fail_fast_report_line(label: str, value: object) -> str: - rendered = ( - _fail_fast_report_value(value) - .replace("\r\n", "\n") - .replace( - "\r", - "\n", - ) - ) - return f"{label}: " + rendered.replace("\n", "\n ") - - -def _build_fail_fast_report( - service: ReportService, - state: DashboardState, - failure: _FailFastTerminalFailure, - *, - invocation_command: str, -) -> _FailFastReport: - try: - cell = service.catalog.cell(failure.cell_id) - except KeyError as error: - raise ManualCampaignError( - f"fail-fast terminal references unknown cell {failure.cell_id!r}" - ) from error - worker = state.workers.get(failure.cell_id) - attempt_id = _canonical_attempt_uuid( - None if worker is None else worker.attempt_id - ) - if attempt_id is None: - attempt_id = _canonical_attempt_uuid(failure.detail) - attempt_root, result = _attempt_failure_evidence( - service, - cell_id=cell.cell_id, - attempt_id=attempt_id, - ) - failure_record = result.get("failure") if isinstance(result, Mapping) else None - failure_class = ( - failure_record.get("kind") if isinstance(failure_record, Mapping) else None - ) - failure_message = ( - failure_record.get("message") - if isinstance(failure_record, Mapping) - else None - ) - if not isinstance(failure_class, str) or not failure_class: - failure_class = None - if not isinstance(failure_message, str) or not failure_message: - failure_message = failure.terminal_detail or failure.detail or None - artifact = result.get("artifact") if isinstance(result, Mapping) else None - raw_artifact_path = artifact.get("path") if isinstance(artifact, Mapping) else None - artifact_path = ( - raw_artifact_path - if isinstance(raw_artifact_path, str) and raw_artifact_path - else None - ) - if ( - artifact_path is None - and attempt_root is not None - and (attempt_root / "artifact").is_dir() - ): - artifact_path = str(attempt_root / "artifact") - worker_log_path = None if worker is None else worker.log_path - worker_progress_path = None if worker is None else worker.progress_path - if attempt_root is not None: - if worker_log_path is None and (attempt_root / "worker.log").is_file(): - worker_log_path = str(attempt_root / "worker.log") - if ( - worker_progress_path is None - and (attempt_root / "worker-progress.jsonl").is_file() - ): - worker_progress_path = str(attempt_root / "worker-progress.jsonl") - process_family_id = next( - ( - family.identifier - for family in PROCESS_FAMILIES - if family.key == cell.process_key - ), - None, - ) - rows = ( - ("timestamp_utc", failure.observed_at_utc), - ("campaign_invocation_id", state.instance_id), - ("campaign_invocation", invocation_command), - ("cell_id", cell.cell_id), - ("process_family_id", process_family_id), - ("process_key", cell.process_key), - ("process", cell.process), - ("n_final", cell.n_final), - ("mode", cell.measurement.execution_mode.value), - ("workload", cell.workload.value), - ("accuracy", cell.measurement.accuracy.value), - ("terminal_status", failure.status), - ("outcome_detail", failure.detail), - ("terminal_detail", failure.terminal_detail), - ("failure_class", failure_class), - ("failure_message", failure_message), - ("attempt_uuid", attempt_id), - ("attempt_root", attempt_root), - ("artifact_path", artifact_path), - ("worker_log_path", worker_log_path), - ("worker_progress_path", worker_progress_path), - ( - "reproduce_prepare", - None if worker is None else worker.reproduce_prepare, - ), - ( - "reproduce_generate", - None if worker is None else worker.reproduce_generate, - ), - ( - "reproduce_profile", - None if worker is None else worker.reproduce_profile, - ), - ) - text = "\n".join( - ( - "pyAmpliCol campaign fail-fast failure", - *(_fail_fast_report_line(label, value) for label, value in rows), - ) - ) - return _FailFastReport( - text=text, - cell_id=cell.cell_id, - attempt_root=None if attempt_root is None else str(attempt_root), - artifact_path=artifact_path, - worker_log_path=worker_log_path, - worker_progress_path=worker_progress_path, - ) - - -def _publish_completion_summary( - service: ReportService, - categories: Mapping[str, Iterable[str]], - *, - state: DashboardState, - fail_fast_failure: _FailFastTerminalFailure | None, - invocation_command: str, - palette: Palette, -) -> Path: - report = ( - None - if fail_fast_failure is None - else _build_fail_fast_report( - service, - state, - fail_fast_failure, - invocation_command=invocation_command, - ) - ) - summary_path, summary_counts = _publish_campaign_summary_ids( - service, - categories, - fail_fast_failure_log=None if report is None else report.text, - ) - _print_campaign_summary_ids(summary_path, summary_counts, palette) - if report is not None: - report_path = summary_path / FAIL_FAST_FAILURE_LOG - print(file=sys.stderr) - print( - palette.failure( - "Fail-fast stopped dispatch after the first terminal failure." - ), - file=sys.stderr, - ) - print(report.text, file=sys.stderr) - print(f"fail_fast_report: {report_path}", file=sys.stderr) - return summary_path - - -def _print_cleanup_warnings(state: DashboardState, palette: Palette) -> None: - for cell_id, detail in state.cleanup_warnings: - print( - palette.warning(f"artifact cleanup skipped for {cell_id}: {detail}"), - file=sys.stderr, - ) - - -def _optional_int(value: object) -> int | None: - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - return int(value) - - -def _finite_float(value: object) -> float: - if isinstance(value, bool) or not isinstance(value, (int, float)): - return 0.0 - result = float(value) - return result if math.isfinite(result) else 0.0 - - -def _optional_finite_float(value: object) -> float | None: - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - result = float(value) - return result if math.isfinite(result) else None - - -def _first_mapping_text( - values: Sequence[Mapping[str, object]], - keys: Sequence[str], -) -> str | None: - for value in values: - for key in keys: - observed = value.get(key) - if isinstance(observed, str) and observed.strip(): - return observed.strip() - return None - - -def _manual_phase_timeline( - result: Mapping[str, object], -) -> Mapping[str, object] | None: - """Return only the versioned manual-campaign phase-timeline contract.""" - - provenance = result.get("provenance") - if not isinstance(provenance, Mapping): - return None - manual = provenance.get("manual_campaign") - if not isinstance(manual, Mapping): - return None - timeline = manual.get("phase_timeline") - if ( - not isinstance(timeline, Mapping) - or timeline.get("schema") != _PHASE_TIMELINE_SCHEMA - ): - return None - return timeline - - -def _persisted_phase_timeline_row(value: object) -> PhaseTimelineRow | None: - """Decode exactly one entry from the versioned persisted contract.""" - - if not isinstance(value, Mapping): - return None - phase = _first_mapping_text((value,), ("label", "key")) - if phase is None: - return None - seconds = _optional_finite_float(value.get("seconds")) - cpu_seconds = _optional_finite_float(value.get("cpu_seconds")) - peak_memory = _optional_int(value.get("peak_memory_bytes")) - return PhaseTimelineRow( - phase=phase, - wall_seconds=seconds if seconds is not None and seconds >= 0.0 else None, - cpu_seconds=( - cpu_seconds if cpu_seconds is not None and cpu_seconds >= 0.0 else None - ), - peak_memory_bytes=( - peak_memory if peak_memory is not None and peak_memory >= 0 else None - ), - status=_first_mapping_text((value,), ("status",)), - detail=_first_mapping_text((value,), ("detail",)), - ) - - -def _persisted_phase_timeline_rows( - timeline: Mapping[str, object], -) -> tuple[PhaseTimelineRow, ...]: - entries = timeline.get("entries") - if not isinstance(entries, Sequence) or isinstance(entries, (str, bytes)): - return () - return tuple( - row - for entry in entries[:16] - if (row := _persisted_phase_timeline_row(entry)) is not None - ) - - -def _lease_phase_timeline_rows(value: object) -> tuple[PhaseTimelineRow, ...]: - """Decode only the controller's own compact WorkerView lease shape.""" - - if not isinstance(value, Sequence) or isinstance(value, (str, bytes)): - return () - rows: list[PhaseTimelineRow] = [] - for item in value[:16]: - if isinstance(item, PhaseTimelineRow): - rows.append(item) - continue - if not isinstance(item, Mapping): - continue - phase = item.get("phase") - if not isinstance(phase, str) or not phase: - continue - wall = _optional_finite_float(item.get("wall_seconds")) - cpu = _optional_finite_float(item.get("cpu_seconds")) - peak = _optional_int(item.get("peak_memory_bytes")) - status = item.get("status") - detail = item.get("detail") - rows.append( - PhaseTimelineRow( - phase=phase, - wall_seconds=wall if wall is not None and wall >= 0.0 else None, - cpu_seconds=cpu if cpu is not None and cpu >= 0.0 else None, - peak_memory_bytes=peak if peak is not None and peak >= 0 else None, - status=status if isinstance(status, str) and status else None, - detail=detail if isinstance(detail, str) and detail else None, - ) - ) - return tuple(rows) - - -def _extract_phase_timeline( - result: Mapping[str, object], -) -> tuple[PhaseTimelineRow, ...]: - """Normalize a persisted timeline without requiring it for result reuse.""" - - timeline = _manual_phase_timeline(result) - if timeline is not None: - return _persisted_phase_timeline_rows(timeline) - - # Older results expose a few exact durations without a timeline wrapper. - # Use only those recorded numbers; never derive one phase from another. - rows: list[PhaseTimelineRow] = [] - provenance = result.get("provenance") - provenance_values = provenance if isinstance(provenance, Mapping) else {} - preparation = _optional_finite_float( - provenance_values.get("model_preparation_seconds") - ) - if preparation is not None and preparation >= 0.0: - rows.append( - PhaseTimelineRow( - "Model preparation", - wall_seconds=preparation, - status=( - "reused" - if provenance_values.get("model_preparation_reused") is True - else "measured" - ), - ) - ) - generation = _optional_finite_float(result.get("generation_seconds")) - if generation is not None and generation >= 0.0: - rows.append(PhaseTimelineRow("Generation", wall_seconds=generation)) - benchmark = provenance_values.get("runtime_profile") - benchmark_values = benchmark if isinstance(benchmark, Mapping) else {} - legacy_warmup = benchmark_values.get("warmup") - legacy_measurement = benchmark_values.get("measurement") - if isinstance(legacy_warmup, Mapping): - seconds = _optional_finite_float(legacy_warmup.get("elapsed_seconds")) - if seconds is not None and seconds >= 0.0: - rows.append(PhaseTimelineRow("Runtime warm-up", wall_seconds=seconds)) - if isinstance(legacy_measurement, Mapping): - chunks = legacy_measurement.get("chunks") - durations: list[float] = [] - if isinstance(chunks, Sequence) and not isinstance(chunks, (str, bytes)): - for chunk in chunks: - if not isinstance(chunk, Mapping): - durations = [] - break - seconds = _optional_finite_float(chunk.get("elapsed_seconds")) - if seconds is None or seconds < 0.0: - durations = [] - break - durations.append(seconds) - if durations: - rows.append( - PhaseTimelineRow( - "Timed profiling", - wall_seconds=math.fsum(durations), - ) - ) - for key, label in ( - ("warmup_elapsed_seconds", "Runtime warm-up"), - ("calibration_outer_elapsed_seconds", "Runtime calibration"), - ("profile_attribution_elapsed_seconds", "Profiling attribution"), - ("evaluator_elapsed_seconds", "Profiling attribution"), - ("profile_total_elapsed_seconds", "Complete runtime profile"), - ): - seconds = _optional_finite_float(benchmark_values.get(key)) - if seconds is not None and seconds >= 0.0: - rows.append(PhaseTimelineRow(label, wall_seconds=seconds)) - if not any( - row.phase in {"Timed profiling", "Timed headline measurement"} for row in rows - ): - seconds = _optional_finite_float( - benchmark_values.get("achieved_runtime_seconds") - ) - if seconds is None: - seconds = _optional_finite_float( - benchmark_values.get("measurement_phase_elapsed_seconds") - ) - if seconds is not None and seconds >= 0.0: - rows.append( - PhaseTimelineRow( - "Timed headline measurement", - wall_seconds=seconds, - ) - ) - return tuple(rows) - - -def _extract_provenance_summary(result: Mapping[str, object]) -> str | None: - provenance = result.get("provenance") - provenance_values = provenance if isinstance(provenance, Mapping) else {} - manual = provenance_values.get("manual_campaign") - manual_values = manual if isinstance(manual, Mapping) else {} - identity = manual_values.get("cell_identity") - identity_values = identity if isinstance(identity, Mapping) else {} - revision = _first_mapping_text( - (manual_values, provenance_values, result), - ( - "report_measured_source_revision", - "report_source_revision", - "source_revision", - ), - ) - engine = _first_mapping_text( - (identity_values, manual_values), - ("execution_mode", "generation_engine", "engine"), - ) - model = _first_mapping_text( - (identity_values, manual_values), - ("model", "model_source"), - ) - fragments: list[str] = [] - if revision is not None: - fragments.append(f"source {revision[:12]}") - if engine is not None: - fragments.append(f"engine {engine}") - if model is not None: - fragments.append(f"model {model}") - recorded_at = _first_mapping_text((manual_values,), ("recorded_at_utc",)) - if recorded_at is not None: - fragments.append(f"recorded {recorded_at}") - return " · ".join(fragments) or None - - -def _stored_reproduction_command( - recipe: object, - key: str, -) -> str | None: - value = recipe.get(key) if isinstance(recipe, Mapping) else None - if ( - not isinstance(value, Sequence) - or isinstance(value, (str, bytes, bytearray)) - or not value - or any(not isinstance(argument, str) or not argument for argument in value) - ): - return None - return _shell_join(value) - - -def _apply_persisted_worker_result( - worker: WorkerView, - result: Mapping[str, object], - *, - recycled: bool, - reuse_explanation: str | None = None, -) -> None: - """Populate optional dashboard evidence without making reuse depend on it.""" - - worker.phase_timeline = _extract_phase_timeline(result) - worker.provenance_summary = _extract_provenance_summary(result) - worker.recycled = recycled - worker.reuse_explanation = reuse_explanation if recycled else None - timeline = _manual_phase_timeline(result) - if isinstance(timeline, Mapping): - total_wall = _optional_finite_float(timeline.get("total_worker_wall_seconds")) - peak_rss = _optional_int(timeline.get("peak_rss_bytes")) - peak_guard = _optional_int(timeline.get("peak_guard_bytes")) - if worker.wall_seconds <= 0.0 and total_wall is not None and total_wall >= 0.0: - worker.wall_seconds = total_wall - if worker.peak_rss_bytes <= 0 and peak_rss is not None and peak_rss >= 0: - worker.peak_rss_bytes = peak_rss - if worker.peak_guard_bytes <= 0 and peak_guard is not None and peak_guard >= 0: - worker.peak_guard_bytes = peak_guard - - -def _concise_terminal_step(value: str | None) -> str | None: - """Normalize one event-carried terminal reason for bounded display.""" - - if value is None: - return None - concise = " ".join(_dashboard_log_line(value).split()) - if not concise: - return None - return concise if len(concise) <= 240 else f"{concise[:237]}..." - - -def _terminal_result_step(result: Mapping[str, object]) -> str | None: - """Return one concise terminal reason from an already loaded current.""" - - resources = result.get("resources") - supervisor = resources.get("supervisor") if isinstance(resources, Mapping) else None - if ( - isinstance(supervisor, Mapping) - and supervisor.get("reason") == "phase_state_error" - ): - phase_error = supervisor.get("phase_state_error") - if isinstance(phase_error, str) and phase_error.strip(): - value = phase_error - else: - value = "worker phase-state validation failed" - else: - policy_label = policy_status_label(result) - failure = result.get("failure") - failure_message = ( - failure.get("message") if isinstance(failure, Mapping) else None - ) - if isinstance(policy_label, str) and policy_label.strip(): - value = policy_label - elif isinstance(failure_message, str) and failure_message.strip(): - value = failure_message - else: - return None - return _concise_terminal_step(value) - - -def _coalesced_worker_events(events: Sequence[str]) -> tuple[str, ...]: - """Collapse repeated resource samples while retaining phase transitions.""" - - rows: list[str] = [] - previous_resource: str | None = None - for event in events: - resource = event if event.startswith("resource:") else None - if resource is not None and resource == previous_resource: - continue - rows.append(event) - previous_resource = resource - return tuple(rows) - - -def _incremental_tail_lines( - path: Path, - state: _IncrementalTailState, - *, - max_read_bytes: int = MAX_TAIL_READ_BYTES, -) -> tuple[str, ...]: - """Read only newly appended complete lines, bounded after large jumps.""" - - if max_read_bytes <= 0: - raise ValueError("max_read_bytes must be positive") - try: - metadata = path.stat() - except OSError: - state.last_read_bytes = 0 - return () - identity = (metadata.st_dev, metadata.st_ino) - if state.identity != identity or metadata.st_size < state.offset: - state.identity = identity - state.offset = 0 - state.pending = b"" - start = state.offset - discard_partial_prefix = False - if metadata.st_size - start > max_read_bytes: - start = metadata.st_size - max_read_bytes - state.pending = b"" - discard_partial_prefix = start > 0 - try: - with path.open("rb") as stream: - stream.seek(start) - payload = stream.read(max_read_bytes) - except OSError: - state.last_read_bytes = 0 - return () - state.offset = start + len(payload) - state.last_read_bytes = len(payload) - if discard_partial_prefix: - separator = payload.find(b"\n") - payload = b"" if separator < 0 else payload[separator + 1 :] - combined = state.pending + payload - chunks = combined.split(b"\n") - if combined.endswith(b"\n"): - state.pending = b"" - chunks.pop() - else: - state.pending = chunks.pop()[-max_read_bytes:] - return tuple( - chunk.rstrip(b"\r").decode("utf-8", errors="replace") for chunk in chunks - ) - - -def _tail_progress(worker: WorkerView) -> None: - if worker.progress_path is None: - return - lines = _incremental_tail_lines( - Path(worker.progress_path), - worker._progress_tail_state, - ) - for line in reversed(lines): - try: - event = json.loads(line) - except json.JSONDecodeError: - continue - if not isinstance(event, Mapping): - continue - task_id = event.get("task_id") - worker.progress_task_id = ( - str(task_id) if isinstance(task_id, str) and task_id else None - ) - completed = _optional_int(event.get("completed")) - total = _optional_int(event.get("total")) - event_kind = event.get("event") - if completed is not None: - worker.progress_completed = completed - elif event_kind == "start": - worker.progress_completed = 0 - if total is not None: - worker.progress_total = total - details = event.get("details") - if isinstance(details, Mapping): - worker.progress_details = { - str(key): value - for key, value in details.items() - if value is None or isinstance(value, (bool, int, float, str)) - } - else: - worker.progress_details = {} - detail_step = worker.progress_details.get("step") - message = ( - event.get("message") - or event.get("description") - or (detail_step if isinstance(detail_step, str) else None) - ) - worker.progress_message = "" if message is None else str(message) - if worker.progress_message: - worker.step = worker.progress_message - return - - -def _dashboard_log_line(value: str) -> str: - value = _ANSI_ESCAPE.sub("", value) - cleaned = "".join( - character - for character in value.replace("\t", " ") - if ord(character) >= 32 and ord(character) != 127 - ) - return cleaned[-500:] - - -def _tail_log(worker: WorkerView) -> None: - if worker.log_path is None: - return - lines = _incremental_tail_lines(Path(worker.log_path), worker._log_tail_state) - worker.log_tail.extend( - cleaned for line in lines if (cleaned := _dashboard_log_line(line)) - ) - del worker.log_tail[:-MAX_LOG_TAIL_LINES] - - -def _human_duration(seconds: float) -> str: - seconds = max(0.0, seconds) - hours, remainder = divmod(int(seconds), 3600) - minutes, whole = divmod(remainder, 60) - return f"{hours:02d}:{minutes:02d}:{whole:02d}" - - -def _human_phase_duration(seconds: float) -> str: - """Keep short phase timings visible without widening the worker runtime.""" - - seconds = max(0.0, seconds) - if seconds < 1.0: - return f"{seconds * 1000.0:.1f} ms" - if seconds < 60.0: - return f"{seconds:.2f} s" - if seconds < 3600.0: - minutes, remainder = divmod(seconds, 60.0) - return f"{int(minutes):02d}:{remainder:04.1f}" - return _human_duration(seconds) - - -def _human_bytes(value: int) -> str: - if value < 1000: - return f"{value} B" - units = ("kB", "MB", "GB", "TB") - amount = float(value) - for unit in units: - amount /= 1000.0 - if amount < 1000.0 or unit == units[-1]: - return f"{amount:.2f} {unit}" - return f"{value} B" - - -def _progress_detail_summary(details: Mapping[str, object]) -> str: - """Render typed progress details without discarding native stage counters.""" - - ignored = {"process", "step"} - ordered_keys = ( - "stage_index", - "stage_total", - "subset_size", - "candidate_parent_pair_count", - "candidate_parent_pair_total", - "current_count", - "contribution_count", - "dynamic_color_state_count", - "color_target_prune_count", - "inspected_current_count", - "certified_relation_count", - "applied_relation_count", - "generation_evidence_encoding", - "generation_raw_evidence_bytes", - "generation_evidence_transport_bytes", - ) - ordered = [key for key in ordered_keys if key in details] - ordered.extend( - sorted(key for key in details if key not in ignored and key not in ordered) - ) - fragments: list[str] = [] - consumed: set[str] = set() - if "stage_index" in details and "stage_total" in details: - fragments.append(f"stage {details['stage_index']}/{details['stage_total']}") - consumed.update({"stage_index", "stage_total"}) - if ( - "candidate_parent_pair_count" in details - and "candidate_parent_pair_total" in details - ): - count = details["candidate_parent_pair_count"] - total = details["candidate_parent_pair_total"] - if isinstance(count, int) and isinstance(total, int): - fragments.append(f"candidate pairs {count:,}/{total:,}") - consumed.update( - {"candidate_parent_pair_count", "candidate_parent_pair_total"} - ) - labels = { - "subset_size": "subset", - "current_count": "currents", - "contribution_count": "contributions", - "dynamic_color_state_count": "colour states", - "color_target_prune_count": "colour pruned", - "inspected_current_count": "currents inspected", - "certified_relation_count": "relations certified", - "applied_relation_count": "relations applied", - "generation_evidence_encoding": "evidence", - "generation_raw_evidence_bytes": "evidence raw", - "generation_evidence_transport_bytes": "evidence transport", - } - byte_fields = { - "generation_raw_evidence_bytes", - "generation_evidence_transport_bytes", - } - for key in ordered: - if key in consumed: - continue - value = details[key] - label = labels.get(key, key.replace("_", " ")) - if key in byte_fields and isinstance(value, int): - rendered = _human_bytes(value) - elif isinstance(value, int) and not isinstance(value, bool): - rendered = f"{value:,}" - else: - rendered = str(value) - fragments.append(f"{label} {rendered}") - return " · ".join(fragments) - - -def _worker_progress_ratio(worker: WorkerView) -> float: - if ( - worker.progress_completed is not None - and worker.progress_total is not None - and worker.progress_total > 0 - ): - return min(1.0, worker.progress_completed / worker.progress_total) - phase_ratio = { - "preparation": 0.05, - "generation": 0.35, - "profiling": 0.75, - "completed": 1.0, - } - return phase_ratio.get(worker.phase, 0.1) - - -def _worker_progress_indicator(worker: WorkerView, *, compact: bool) -> str: - ratio = _worker_progress_ratio(worker) - slots = 4 if compact else 6 - filled = min(slots, max(0, round(ratio * slots))) - return f"{'▰' * filled}{'▱' * (slots - filled)} {ratio * 100:3.0f}%" - - -def _worker_enforcement_memory(worker: WorkerView, *, peak: bool = False) -> int: - guard = worker.peak_guard_bytes if peak else worker.current_guard_bytes - rss = worker.peak_rss_bytes if peak else worker.current_rss_bytes - return guard if guard > 0 else rss - - -def _reproduction_command(worker: WorkerView | None, stage: str | None) -> str | None: - """Return one exact persisted command without regenerating or normalizing it.""" - - if worker is None or stage not in _REPRODUCTION_STAGES: - return None - value = getattr(worker, f"reproduce_{stage}") - return value if isinstance(value, str) and value else None - - -def _available_reproduction_stages(worker: WorkerView | None) -> tuple[str, ...]: - return tuple( - stage - for stage in _REPRODUCTION_STAGES - if _reproduction_command(worker, stage) is not None - ) - - -def _cycle_reproduction_stage(state: DashboardState, step: int = 1) -> None: - available = _available_reproduction_stages(state.selected_worker()) - if not available: - state.command_stage = None - state.command_notice = "No public CLI reproduction is available" - state.command_scroll = 0 - return - try: - index = available.index(state.command_stage or "") - except ValueError: - index = -1 if step >= 0 else 0 - state.command_stage = available[(index + step) % len(available)] - state.command_scroll = 0 - state.command_notice = None - - -def _osc52_clipboard_sequence(value: str) -> str: - """Encode an explicitly requested clipboard copy without a subprocess.""" - - encoded = base64.b64encode(value.encode("utf-8")).decode("ascii") - return f"\x1b]52;c;{encoded}\x07" - - -def _phase_timeline_lines( - rows: Sequence[PhaseTimelineRow], - *, - compact: bool, - limit: int, -) -> tuple[str, ...]: - """Render a small aligned phase table that remains legible at 80 columns.""" - - rendered: list[str] = [] - for row in rows[: max(0, limit)]: - wall = ( - "unavailable" - if row.wall_seconds is None - else _human_phase_duration(row.wall_seconds) - ) - outcome = ( - " · ".join(value for value in (row.status, row.detail) if value) - or "recorded" - ) - if compact: - rendered.append(f"{row.phase[:20]} · {wall} · {outcome}") - continue - cpu = ( - "unavailable" - if row.cpu_seconds is None - else _human_phase_duration(row.cpu_seconds) - ) - peak = ( - "unavailable" - if row.peak_memory_bytes is None - else _human_bytes(row.peak_memory_bytes) - ) - rendered.append( - f"{row.phase[:20]:<20} {wall:>11} {cpu:>11} {peak:>11} {outcome}" - ) - if len(rows) > len(rendered): - rendered.append(f"… {len(rows) - len(rendered)} more persisted phases") - return tuple(rendered) - - -def _worker_from_lease( - cell_id: str, - raw: Mapping[str, object], - *, - peer_instance: str | None, -) -> WorkerView: - """Decode one informational worker row without following referenced paths.""" - - def optional_text(key: str) -> str | None: - value = raw.get(key) - return value if isinstance(value, str) and value else None - - def text(key: str, default: str) -> str: - value = optional_text(key) - return default if value is None else value - - raw_status = text("status", "unknown") - recycled = raw.get("recycled") is True or raw_status in _RECYCLED_SUCCESS_STATUSES - worker = WorkerView( - cell_id=cell_id, - dependency=raw.get("dependency") is True, - peer_instance=peer_instance, - generation_engine=optional_text("generation_engine"), - status="recycled" if raw_status in _RECYCLED_SUCCESS_STATUSES else raw_status, - step=text("step", "waiting"), - phase=text("phase", "unknown"), - attempt_id=optional_text("attempt_id"), - pid=_optional_int(raw.get("pid")), - wall_seconds=max(0.0, _finite_float(raw.get("wall_seconds"))), - cpu_seconds=( - None - if (cpu_seconds := _optional_finite_float(raw.get("cpu_seconds"))) is None - else max(0.0, cpu_seconds) - ), - current_rss_bytes=max( - 0, - _optional_int(raw.get("current_rss_bytes")) or 0, - ), - peak_rss_bytes=max( - 0, - _optional_int(raw.get("peak_rss_bytes")) or 0, - ), - current_physical_footprint_bytes=_optional_int( - raw.get("current_physical_footprint_bytes") - ), - peak_physical_footprint_bytes=_optional_int( - raw.get("peak_physical_footprint_bytes") - ), - current_guard_bytes=max( - 0, - _optional_int(raw.get("current_guard_bytes")) or 0, - ), - peak_guard_bytes=max( - 0, - _optional_int(raw.get("peak_guard_bytes")) or 0, - ), - child_count=max(0, _optional_int(raw.get("child_count")) or 0), - progress_completed=_optional_int(raw.get("progress_completed")), - progress_total=_optional_int(raw.get("progress_total")), - progress_message=text("progress_message", ""), - progress_task_id=optional_text("progress_task_id"), - log_path=optional_text("log_path"), - progress_path=optional_text("progress_path"), - reproduce_prepare=optional_text("reproduce_prepare"), - reproduce_generate=optional_text("reproduce_generate"), - reproduce_profile=optional_text("reproduce_profile"), - published_wall_seconds_per_point=_optional_finite_float( - raw.get("published_wall_seconds_per_point") - ), - published_evaluator_total_seconds_per_point=_optional_finite_float( - raw.get("published_evaluator_total_seconds_per_point") - ), - published_recurrence_core_seconds_per_point=_optional_finite_float( - raw.get("published_recurrence_core_seconds_per_point") - ), - phase_timeline=_lease_phase_timeline_rows(raw.get("phase_timeline")), - provenance_summary=optional_text("provenance_summary"), - reuse_explanation=optional_text("reuse_explanation"), - blocked_prerequisite_ids=tuple( - sorted( - { - str(value) - for value in raw.get("blocked_prerequisite_ids", ()) - if isinstance(value, str) and value - } - ) - ) - if isinstance(raw.get("blocked_prerequisite_ids"), Sequence) - and not isinstance(raw.get("blocked_prerequisite_ids"), (str, bytes)) - else (), - recycled=recycled, - updated_at=max(0.0, _finite_float(raw.get("updated_at"))), - ) - raw_member_pids = raw.get("member_pids") - if isinstance(raw_member_pids, Sequence) and not isinstance( - raw_member_pids, - (str, bytes), - ): - worker.member_pids = tuple( - value - for item in raw_member_pids - if (value := _optional_int(item)) is not None and value >= 0 - ) - raw_progress_details = raw.get("progress_details") - if isinstance(raw_progress_details, Mapping): - worker.progress_details = { - str(key): value - for key, value in raw_progress_details.items() - if value is None or isinstance(value, (bool, int, float, str)) - } - raw_events = raw.get("events") - if isinstance(raw_events, Sequence) and not isinstance( - raw_events, - (str, bytes), - ): - worker.events = [str(value) for value in raw_events[-8:]] - raw_log_tail = raw.get("log_tail") - if isinstance(raw_log_tail, Sequence) and not isinstance( - raw_log_tail, - (str, bytes), - ): - worker.log_tail = [ - _dashboard_log_line(str(value)) - for value in raw_log_tail[-MAX_LOG_TAIL_LINES:] - ] - return worker - - -def _live_lease_workers( - service: ReportService, - selected_ids: frozenset[str], - *, - exclude_instance: str, - source_revision: str, -) -> tuple[WorkerView, ...]: - root = service.paths.coordination_root / "manual-leases" - now = time.time() - workers: list[WorkerView] = [] - if not root.is_dir(): - return () - for path in root.glob("*.json"): - payload = _read_object(path) - if payload is None: - continue - updated = _finite_float(payload.get("updated_at")) - if now - updated > DEFAULT_WORKER_STALE_SECONDS: - continue - instance_id = str(payload.get("instance_id") or "") - if not instance_id or instance_id == exclude_instance: - continue - if payload.get("source_revision") != source_revision: - continue - raw_workers = payload.get("workers") - if not isinstance(raw_workers, Mapping): - continue - for cell_id, raw in raw_workers.items(): - if cell_id not in selected_ids or not isinstance(raw, Mapping): - continue - worker = _worker_from_lease( - str(cell_id), - raw, - peer_instance=instance_id, - ) - if worker.status in {"queued", "preparing", "running"}: - workers.append(worker) - return tuple(workers) - - -def _merge_peer_workers( - service: ReportService, - state: DashboardState, -) -> None: - for key in tuple(state.workers): - if state.workers[key].peer_instance is not None: - del state.workers[key] - peers = _live_lease_workers( - service, - frozenset(state.selected_ids), - exclude_instance=state.instance_id, - source_revision=state.source_revision, - ) - for worker in peers: - state.workers[f"peer:{worker.peer_instance}:{worker.cell_id}"] = worker - - -def _lease_counter_snapshot(value: object) -> dict[str, int] | None: - if not isinstance(value, Mapping): - return None - counters: dict[str, int] = {} - for key in _DASHBOARD_COUNTER_KEYS: - observed = _optional_int( - value.get(key, 0 if key == "unverified" else None) - ) - if observed is None or observed < 0: - return None - counters[key] = observed - return counters - - -def _lease_limits( - value: object, -) -> tuple[float, int, float | None] | None: - """Decode effective invocation caps, retaining defaults for old leases.""" - - if value is None: - return ( - DEFAULT_GENERATION_LIMIT_SECONDS, - DEFAULT_RAM_BYTES, - DEFAULT_WORKER_WALL_LIMIT_SECONDS, - ) - if not isinstance(value, Mapping): - return None - generation = _optional_finite_float(value.get("generation_time_limit_seconds")) - memory = _optional_int(value.get("memory_limit_bytes")) - raw_wall = value.get("worker_wall_limit_seconds") - wall = None if raw_wall is None else _optional_finite_float(raw_wall) - if ( - generation is None - or generation <= 0.0 - or memory is None - or memory <= 0 - or (raw_wall is not None and (wall is None or wall <= 0.0)) - ): - return None - return generation, memory, wall - - -def _lease_scheduler_state(value: object) -> tuple[int, int, int]: - if not isinstance(value, Mapping): - return (0, 0, 0) - observed = tuple( - _optional_int(value.get(key)) - for key in ("ready", "waiting_dependency", "waiting_coordination_lock") - ) - if any(item is None or item < 0 for item in observed): - return (0, 0, 0) - return tuple(int(item) for item in observed) # type: ignore[arg-type,return-value] - - -def _live_dashboard_snapshot( - coordination_root: Path, - *, - instance: str | None, - stale_after_seconds: float, - now: float | None = None, -) -> DashboardState: - """Build one read-only frame from compact, non-stale lease JSON only.""" - - if not math.isfinite(stale_after_seconds) or stale_after_seconds <= 0.0: - raise ManualCampaignError("--stale-after must be a positive finite value") - lease_root = coordination_root / "manual-leases" - current_time = time.time() if now is None else now - records: list[dict[str, object]] = [] - if lease_root.is_dir(): - for path in sorted(lease_root.glob("*.json")): - payload = _read_object(path) - if payload is None or payload.get("schema") != MANUAL_STATE_SCHEMA: - continue - instance_id = payload.get("instance_id") - source_revision = payload.get("source_revision") - updated_at = _optional_finite_float(payload.get("updated_at")) - counters = _lease_counter_snapshot(payload.get("counters")) - limits = _lease_limits(payload.get("limits")) - workers = payload.get("workers") - if ( - not isinstance(instance_id, str) - or not instance_id - or len(instance_id) > 128 - or not isinstance(source_revision, str) - or not source_revision - or updated_at is None - or updated_at <= 0.0 - or current_time - updated_at > stale_after_seconds - or counters is None - or limits is None - or not isinstance(workers, Mapping) - ): - continue - records.append(payload) - if not records: - raise ManualCampaignError( - "no active manual-campaign lease is available; start `run` in " - "another terminal or increase --stale-after" - ) - - chosen: dict[str, object] | None = None - if instance is not None: - exact = [ - payload for payload in records if payload.get("instance_id") == instance - ] - matches = ( - exact - if exact - else [ - payload - for payload in records - if str(payload.get("instance_id")).startswith(instance) - ] - ) - identifiers = sorted({str(payload.get("instance_id")) for payload in matches}) - if not matches: - available = ", ".join( - sorted(str(payload.get("instance_id")) for payload in records) - ) - raise ManualCampaignError( - f"no active lease matches instance {instance!r}; available: {available}" - ) - if len(identifiers) > 1: - raise ManualCampaignError( - f"instance prefix {instance!r} is ambiguous: " + ", ".join(identifiers) - ) - chosen = max( - matches, - key=lambda payload: _finite_float(payload.get("updated_at")), - ) - else: - chosen = max( - records, - key=lambda payload: _finite_float(payload.get("updated_at")), - ) - - instance_id = str(chosen["instance_id"]) - source_revision = str(chosen["source_revision"]) - updated_at = _finite_float(chosen["updated_at"]) - started_at = _optional_finite_float(chosen.get("started_at")) or updated_at - counters = _lease_counter_snapshot(chosen["counters"]) - assert counters is not None - limits = _lease_limits(chosen.get("limits")) - assert limits is not None - generation_limit, memory_limit, wall_limit = limits - ready_count, waiting_dependency_count, waiting_coordination_lock_count = ( - _lease_scheduler_state(chosen.get("scheduler")) - ) - state = DashboardState( - instance_id=instance_id, - selected_ids=(), - recycled_ids=set(), - static_na_ids=set(), - source_revision=source_revision, - generation_time_limit_seconds=generation_limit, - memory_limit_bytes=memory_limit, - worker_wall_limit_seconds=wall_limit, - started_at=min(started_at, current_time), - counter_snapshot=counters, - lease_updated_at=updated_at, - live_snapshot=True, - ready_count=ready_count, - waiting_dependency_count=waiting_dependency_count, - waiting_coordination_lock_count=waiting_coordination_lock_count, - ) - raw_workers = chosen["workers"] - assert isinstance(raw_workers, Mapping) - for cell_id, raw in raw_workers.items(): - if not isinstance(cell_id, str) or not cell_id or not isinstance(raw, Mapping): - continue - state.workers[cell_id] = _worker_from_lease( - cell_id, - raw, - peer_instance=None, - ) - - # Show active workers from concurrent same-source instances as peer rows. - # The overview counters remain the chosen invocation's own atomic snapshot, - # avoiding guesses or double-counting when selections overlap. - for payload in records: - peer_instance = str(payload["instance_id"]) - if ( - peer_instance == instance_id - or payload.get("source_revision") != source_revision - ): - continue - raw_peer_workers = payload["workers"] - assert isinstance(raw_peer_workers, Mapping) - for cell_id, raw in raw_peer_workers.items(): - if ( - not isinstance(cell_id, str) - or not cell_id - or not isinstance(raw, Mapping) - ): - continue - worker = _worker_from_lease( - cell_id, - raw, - peer_instance=peer_instance, - ) - if worker.status not in {"queued", "preparing", "running"}: - continue - state.workers[f"peer:{peer_instance}:{cell_id}"] = worker - - ordered_workers = state.visible_workers() - state.selected_index = next( - ( - index - for index, worker in enumerate(ordered_workers) - if worker.status in _ACTIVE_WORKER_STATUSES - ), - 0, - ) - return state - - -def _snapshot_fixture( - *, - selected: int = 1796, - recycled: int = 318, - completed: int = 41, -) -> DashboardState: - state = DashboardState( - instance_id="snapshot-demo", - selected_ids=tuple(f"cell-{index:04d}" for index in range(selected)), - recycled_ids={f"cell-{index:04d}" for index in range(recycled)}, - static_na_ids={f"cell-{index:04d}" for index in range(12)}, - source_revision="5b58aeb7600548e84e7214ee0ef62e5f159ec3fb", - ) - for index in range(recycled, recycled + completed): - state._reduce_finished(f"cell-{index:04d}", "ok") - state._reduce_finished("cell-0412", "memory_limit") - state._reduce_finished("cell-0413", "error") - state.dependency_ids = {"reference-amplicol-lc-n6-dd-zzz-jets-selected-flow"} - state.workers = { - "matrix-compiled-builtin-sm-lc-n9-dd-zzz-jets-selected-flow": WorkerView( - "matrix-compiled-builtin-sm-lc-n9-dd-zzz-jets-selected-flow", - generation_engine=ExecutionMode.COMPILED.value, - status="running", - step="native Arena sample 4/8", - phase="profiling", - attempt_id="b92b46a0-demo", - pid=42173, - member_pids=(42173, 42174, 42175), - wall_seconds=412.8, - cpu_seconds=971.2, - current_rss_bytes=8_724_300_000, - peak_rss_bytes=11_941_200_000, - child_count=2, - progress_completed=4, - progress_total=8, - progress_message="native Arena sample 4/8", - published_wall_seconds_per_point=0.000_669_99, - published_evaluator_total_seconds_per_point=0.000_654_31, - events=[ - "generation: compiled Direct-Arena complete", - "profiling: warmups complete", - "profiling: native Arena sample 4/8", - ], - ), - "matrix-recurrence-ufo-sm-lc-n7-gg-gluons-all-flow": WorkerView( - "matrix-recurrence-ufo-sm-lc-n7-gg-gluons-all-flow", - generation_engine=ExecutionMode.RECURRENCE.value, - status="ok", - step="measurement published", - phase="complete", - attempt_id="dd84040e-demo", - pid=42191, - member_pids=(42191,), - wall_seconds=224.7, - cpu_seconds=216.3, - current_rss_bytes=3_252_000_000, - peak_rss_bytes=4_018_000_000, - progress_completed=72, - progress_total=72, - progress_message="measurement published", - published_wall_seconds_per_point=218.105e-6, - published_evaluator_total_seconds_per_point=217.812e-6, - published_recurrence_core_seconds_per_point=205.431e-6, - events=[ - "generation: model loaded", - "generation: recurrence plan projected", - "profiling: independent clocks published", - ], - ), - "reference-amplicol-full-n6-dd-3q-lines-contracted": WorkerView( - "reference-amplicol-full-n6-dd-3q-lines-contracted", - dependency=True, - generation_engine=ExecutionMode.AMPLICOL.value, - status="preparing", - step="prewarming original AmpliCol generator", - phase="preparation", - wall_seconds=8.3, - current_rss_bytes=181_000_000, - peak_rss_bytes=205_000_000, - events=["preparation: legacy generator prewarm"], - ), - } - worker_ids = tuple(state.workers) - state._reduce_finished( - "matrix-recurrence-ufo-sm-lc-n7-gg-gluons-all-flow", - "ok", - ) - state.selected_ids = ( - *worker_ids, - *(f"cell-{index:04d}" for index in range(max(0, selected - len(worker_ids)))), - ) - return state - - -def _append_dashboard_line( - paragraph: Any, - spans: Sequence[tuple[str, object]], -) -> None: - """Append a styled line through Ratatui's stable single-span API.""" - - for text, style in spans: - paragraph.append_span(text, style) - paragraph.line_break() - - -def _fit_dashboard_field(value: object, width: int) -> str: - text = str(value) - if width <= 0: - return "" - if len(text) > width: - text = text[: max(0, width - 1)] + "…" - return text.ljust(width) - - -def _append_detail_fields( - paragraph: Any, - fields: Sequence[tuple[str, object, object]], - *, - width: int, - compact: bool, - key_style: object, -) -> None: - """Render fixed detail columns so keys and values retain vertical anchors.""" - - content_width = max(20, width - 4) - gutter = 1 if compact else 3 - group_width = max(20, (content_width - gutter) // 2) - key_width = min(16 if compact else 18, max(12, group_width // 2)) - value_width = max(1, group_width - key_width) - for offset in range(0, len(fields), 2): - spans: list[tuple[str, object]] = [] - for local_index, (key, value, value_style) in enumerate( - fields[offset : offset + 2] - ): - if local_index: - spans.append((" " * gutter, key_style)) - spans.extend( - ( - (f"{key:<{key_width}}", key_style), - (_fit_dashboard_field(value, value_width), value_style), - ) - ) - _append_dashboard_line(paragraph, spans) - - -def _ratatui_commands( - state: DashboardState, - *, - width: int, - height: int, - color: bool = True, -) -> list[object]: - try: - from ratatui import Color, DrawCmd, Gauge, Paragraph - from ratatui import Style as RStyle - except ImportError as error: - raise ManualCampaignError( - "Ratatui is unavailable; run `just dev-install`" - ) from error - - counters = state.counters() - peer_active_count = len(state.peer_active) - compact = width < 105 or height < 30 - overview_height = 7 if compact else 8 - table_height = max(7, min(13, height // 3) - (1 if compact else 0)) - footer_height = 1 - detail_y = overview_height + table_height - detail_height = max(4, height - detail_y - footer_height) - - if color: - title_style = RStyle(fg=Color.Cyan).bold() - key_style = RStyle(fg=Color.Cyan).bold() - success_style = RStyle(fg=Color.Green) - warning_style = RStyle(fg=Color.Yellow) - failure_style = RStyle(fg=Color.Red) - neutral_style = RStyle(fg=Color.White) - muted_style = RStyle(fg=Color.DarkGray).dim() - metric_style = RStyle(fg=Color.LightCyan) - memory_style = RStyle(fg=Color.LightMagenta) - table_header_style = RStyle(fg=Color.LightCyan).bold().underlined() - summary_style = RStyle(fg=Color.LightCyan, bg=Color.DarkGray).bold() - highlight_style = RStyle(fg=Color.Black, bg=Color.Cyan).bold() - gauge_label_style = RStyle(fg=Color.White).bold() - gauge_value_style = RStyle(fg=Color.Green, bg=Color.Black).bold() - else: - title_style = RStyle() - key_style = RStyle() - success_style = RStyle() - warning_style = RStyle() - failure_style = RStyle() - neutral_style = RStyle() - muted_style = RStyle() - metric_style = RStyle() - memory_style = RStyle() - table_header_style = RStyle() - summary_style = RStyle() - highlight_style = RStyle() - gauge_label_style = RStyle() - gauge_value_style = RStyle() - - def status_style(status: str) -> object: - if status in {"error", "failed", "blocked_dependency"}: - return failure_style - if status in { - *_TERMINAL_CAP_STATUSES, - "timeout", - "cancelled", - ResultStatus.UNVERIFIED.value, - }: - return warning_style - if status in _COMPLETED_WORKER_STATUSES: - return success_style - if status in _ACTIVE_WORKER_STATUSES: - return warning_style - return muted_style - - def phase_style(phase: str) -> object: - normalized = phase.casefold().replace("_", "-") - if "profil" in normalized: - return metric_style - if "generat" in normalized or "post-generation" in normalized: - return memory_style - if normalized in {"complete", "completed"}: - return success_style - if "prepar" in normalized: - return warning_style - return neutral_style - - def outcome_style(status: str | None) -> object: - normalized = (status or "").casefold() - if any(value in normalized for value in ("error", "failed")): - return failure_style - if any(value in normalized for value in ("limit", "capped", "timeout")): - return warning_style - if any( - value in normalized - for value in ("measured", "completed", "reused", "observed") - ): - return success_style - if any(value in normalized for value in ("unavailable", "not_applicable")): - return muted_style - return neutral_style - - overview = Paragraph.new_empty() - overview.set_block_title( - f" LIVE pyAmpliCol profiling campaign · {state.instance_id[:12]} " - if state.live_snapshot - else " pyAmpliCol profiling campaign " - ) - selection_progress = [ - ("Selected ", key_style), - (str(counters["selected"]), neutral_style), - (" Recycled ", key_style), - (str(counters["recycled"]), success_style), - (" Completed ", key_style), - (str(counters["completed"]), success_style), - (" Remaining ", key_style), - (str(counters["remaining"]), neutral_style), - ] - selection_issues = [ - (" Capped ", key_style), - (str(counters["capped"]), warning_style), - (" Errors ", key_style), - (str(counters["failed"]), failure_style), - (" Unverified ", key_style), - (str(counters["unverified"]), warning_style), - ] - if compact: - _append_dashboard_line(overview, selection_progress) - _append_dashboard_line( - overview, - [ - *selection_issues, - (" Static N/A ", key_style), - (str(counters["static_na"]), warning_style), - ], - ) - else: - _append_dashboard_line(overview, [*selection_progress, *selection_issues]) - worker_scope = [ - ("Workers active ", key_style), - (str(counters["active"]), warning_style), - (" selected ", key_style), - (str(counters["selected_active"]), warning_style), - (" dependency ", key_style), - (str(counters["dependency_active"]), warning_style), - *( - ( - (" Peer active ", key_style), - (str(peer_active_count), metric_style), - ) - if peer_active_count - else () - ), - *( - () - if compact - else ( - (" Static N/A ", key_style), - (str(counters["static_na"]), warning_style), - ) - ), - (" Dependency-only ", key_style), - (str(counters["dependency_only"]), neutral_style), - *( - ( - (" Dependency done ", key_style), - (str(counters["dependency_completed"]), success_style), - (" issues ", key_style), - (str(counters["dependency_issues"]), failure_style), - ) - if not compact - else () - ), - ] - _append_dashboard_line(overview, worker_scope) - _append_dashboard_line( - overview, - [ - ("Ready ", key_style), - (str(state.ready_count), success_style), - (" Waiting dependency ", key_style), - (str(state.waiting_dependency_count), muted_style), - (" Waiting coordination lock ", key_style), - (str(state.waiting_coordination_lock_count), warning_style), - ], - ) - _append_dashboard_line( - overview, - [ - ("Caps ", key_style), - ("Generation ", key_style), - ( - _human_duration(state.generation_time_limit_seconds), - warning_style, - ), - (" RAM ", key_style), - (_human_bytes(state.memory_limit_bytes), warning_style), - (" Total wall ", key_style), - ( - ( - "disabled" - if state.worker_wall_limit_seconds is None - else _human_duration(state.worker_wall_limit_seconds) - ), - warning_style, - ), - ], - ) - if not compact: - _append_dashboard_line( - overview, - [ - ("Elapsed ", key_style), - (_human_duration(time.time() - state.started_at), neutral_style), - (" Source ", key_style), - (state.source_revision[:12] or "unavailable", neutral_style), - *( - ( - (" Lease age ", key_style), - ( - _human_duration( - max(0.0, time.time() - state.lease_updated_at) - ), - success_style, - ), - ) - if state.lease_updated_at is not None - else () - ), - ], - ) - _append_dashboard_line( - overview, - [ - ("Clocks ", key_style), - ( - "outer wall, evaluator-total, and recurrence core stay independent", - neutral_style, - ), - ], - ) - - workers = state.visible_workers() - selected_index = 0 - viewport_start = 0 - viewport_capacity = max(1, table_height - 3) - if workers: - selected_index = state.selected_index % len(workers) - state.selected_index = selected_index - viewport_start = min( - max(0, selected_index - viewport_capacity + 1), - max(0, len(workers) - viewport_capacity), - ) - viewport = workers[viewport_start : viewport_start + viewport_capacity] - viewport_end = viewport_start + len(viewport) - worker_table = Paragraph.new_empty() - worker_table.set_block_title( - " Workers ↑/↓" - f" · {viewport_start + 1 if viewport else 0}-{viewport_end}/{len(workers)}" - f" · d done:{'on' if state.show_completed else 'off'}" - f" · e errors:{'on' if state.show_errors else 'off'} " - ) - if compact: - headers = [ - " ", - "cell", - "status", - "phase / step", - "progress", - "runtime", - "cap guard", - ] - percentages = [3, 25, 10, 24, 16, 10, 12] - else: - headers = [ - " ", - "cell", - "status", - "phase / step", - "progress", - "runtime", - "cap guard", - "PID tree", - ] - percentages = [3, 23, 9, 22, 13, 8, 12, 10] - table_content_width = max(len(headers), width - 2) - spacing_width = len(headers) - 1 - distributable_width = max(len(headers), table_content_width - spacing_width) - column_widths = [ - max(1, distributable_width * percentage // 100) for percentage in percentages - ] - column_widths[-1] += max( - 0, - distributable_width - sum(column_widths), - ) - header_spans: list[tuple[str, object]] = [] - for header_index, (header, column_width) in enumerate( - zip(headers, column_widths, strict=True) - ): - if header_index: - header_spans.append((" ", table_header_style)) - header_spans.append( - (_fit_dashboard_field(header, column_width), table_header_style) - ) - _append_dashboard_line(worker_table, header_spans) - for local_index, worker in enumerate(viewport): - index = viewport_start + local_index - marker = "▶" if index == selected_index else " " - enforcement = _worker_enforcement_memory(worker) - guard_style = ( - failure_style - if enforcement > state.memory_limit_bytes - else ( - warning_style - if enforcement >= int(0.8 * state.memory_limit_bytes) - else muted_style - ) - ) - row_values = [ - marker, - worker.cell_id, - ( - "blocked by dependency" - if worker.status == "blocked_dependency" - else worker.status - ), - worker.step, - _worker_progress_indicator(worker, compact=compact), - _human_duration(worker.wall_seconds), - _human_bytes(enforcement), - ] - row_styles = [ - title_style, - title_style if index == selected_index else neutral_style, - status_style(worker.status), - phase_style(worker.phase), - status_style(worker.status), - metric_style, - guard_style, - ] - if not compact: - row_values.append( - "—" - if worker.pid is None - else f"{worker.pid}+{max(0, len(worker.member_pids) - 1)}" - ) - row_styles.append(muted_style) - row_spans: list[tuple[str, object]] = [] - for column_index, (value, value_style, column_width) in enumerate( - zip(row_values, row_styles, column_widths, strict=True) - ): - rendered_style = highlight_style if index == selected_index else value_style - if column_index: - row_spans.append((" ", rendered_style)) - row_spans.append( - (_fit_dashboard_field(value, column_width), rendered_style) - ) - _append_dashboard_line(worker_table, row_spans) - worker_table.set_wrap(False) - - selected = state.selected_worker() - details = Paragraph.new_empty() - details.set_block_title( - " Dashboard help " if state.show_help else " Selected worker " - ) - if state.show_help: - _append_dashboard_line( - details, [("↑/↓ or j/k ", key_style), ("select worker", neutral_style)] - ) - _append_dashboard_line( - details, - [("PgUp/PgDn ", key_style), ("scroll worker details", neutral_style)], - ) - _append_dashboard_line( - details, - [ - ("d ", key_style), - ("show/hide completed and successful reused workers", neutral_style), - ], - ) - _append_dashboard_line( - details, - [ - ("e ", key_style), - ("show/hide errors, caps, and recycled attention rows", neutral_style), - ], - ) - _append_dashboard_line( - details, - [ - ("1/2/3 ", key_style), - ("open full prepare/generate/profile command", neutral_style), - ], - ) - _append_dashboard_line( - details, - [ - ("y / p ", key_style), - ("copy exact command / print it for terminal selection", neutral_style), - ], - ) - _append_dashboard_line( - details, [("? ", key_style), ("close this help", neutral_style)] - ) - _append_dashboard_line( - details, - [ - ("Ctrl-C/Esc ", key_style), - ("stop dispatch and workers safely", warning_style), - ], - ) - ratio = 0.0 if selected is None else _worker_progress_ratio(selected) - gauge_label = "keyboard help" - elif selected is None: - _append_dashboard_line( - details, - [ - ("No workers match the current d/e filters", warning_style), - ], - ) - ratio = 0.0 - gauge_label = "filtered" - else: - _append_dashboard_line( - details, - [ - ("Cell ", key_style), - (selected.cell_id, title_style), - *( - ( - (" Peer ", key_style), - (selected.peer_instance[:12], neutral_style), - ) - if selected.peer_instance is not None - else () - ), - ], - ) - persisted_summary = ( - selected.status in _COMPLETED_WORKER_STATUSES or selected.recycled - ) - _append_detail_fields( - details, - ( - ("Phase", selected.phase, phase_style(selected.phase)), - ("Step", selected.step, neutral_style), - ), - width=width, - compact=compact, - key_style=key_style, - ) - if selected.blocked_prerequisite_ids: - _append_dashboard_line( - details, - [ - ("Blocked by ", key_style), - (", ".join(selected.blocked_prerequisite_ids), failure_style), - ], - ) - if compact and selected.log_tail and not persisted_summary: - _append_dashboard_line( - details, - [ - ("Recent log ", key_style), - (selected.log_tail[-1], neutral_style), - ], - ) - enforcement_current = _worker_enforcement_memory(selected) - enforcement_peak = _worker_enforcement_memory(selected, peak=True) - enforcement_style = ( - failure_style - if enforcement_current > state.memory_limit_bytes - else warning_style - ) - if compact and not persisted_summary: - _append_detail_fields( - details, - ( - ( - "Guard current", - _human_bytes(enforcement_current), - enforcement_style, - ), - ("Guard peak", _human_bytes(enforcement_peak), enforcement_style), - ("RAM cap", _human_bytes(state.memory_limit_bytes), warning_style), - ( - "Physical current", - ( - "unavailable" - if selected.current_physical_footprint_bytes is None - else _human_bytes(selected.current_physical_footprint_bytes) - ), - ( - muted_style - if selected.current_physical_footprint_bytes is None - else memory_style - ), - ), - ), - width=width, - compact=compact, - key_style=key_style, - ) - if persisted_summary: - if selected.recycled: - _append_dashboard_line( - details, - [ - ( - "No work executed by this invocation", - success_style, - ), - ], - ) - _append_dashboard_line( - details, - [ - ("Reuse ", key_style), - ( - selected.reuse_explanation or "existing current reused", - neutral_style, - ), - ], - ) - _append_dashboard_line( - details, - [ - ("Provenance ", key_style), - (selected.provenance_summary or "unavailable", neutral_style), - ], - ) - if selected.phase_timeline: - timeline_phase_width = 38 if width >= 150 else 28 - _append_dashboard_line( - details, - [("Phase timeline", key_style)], - ) - if compact: - _append_dashboard_line( - details, - [ - (" phase", table_header_style), - (" · wall · outcome", table_header_style), - ], - ) - else: - _append_dashboard_line( - details, - [ - ( - f" {'phase':<{timeline_phase_width}}", - table_header_style, - ), - (f"{'wall':>12} ", table_header_style), - (f"{'CPU':>12} ", table_header_style), - (f"{'peak RAM':>12} ", table_header_style), - ("outcome", table_header_style), - ], - ) - for timeline_row in selected.phase_timeline: - wall = ( - "unavailable" - if timeline_row.wall_seconds is None - else _human_phase_duration(timeline_row.wall_seconds) - ) - outcome = ( - " · ".join( - value - for value in (timeline_row.status, timeline_row.detail) - if value - ) - or "recorded" - ) - is_summary = timeline_row.phase.casefold() == "worker supervision" - if compact: - row_style = summary_style if is_summary else neutral_style - _append_dashboard_line( - details, - [ - ("Σ " if is_summary else " ", row_style), - (timeline_row.phase, row_style), - (" · ", row_style), - ( - wall, - summary_style - if is_summary - else ( - muted_style - if timeline_row.wall_seconds is None - else metric_style - ), - ), - (" · ", row_style), - ( - outcome, - summary_style - if is_summary - else outcome_style(timeline_row.status), - ), - ], - ) - continue - cpu = ( - "unavailable" - if timeline_row.cpu_seconds is None - else _human_phase_duration(timeline_row.cpu_seconds) - ) - peak = ( - "unavailable" - if timeline_row.peak_memory_bytes is None - else _human_bytes(timeline_row.peak_memory_bytes) - ) - row_style = summary_style if is_summary else neutral_style - metric_row_style = summary_style if is_summary else metric_style - unavailable_row_style = summary_style if is_summary else muted_style - _append_dashboard_line( - details, - [ - ("Σ " if is_summary else " ", row_style), - ( - _fit_dashboard_field( - timeline_row.phase, - timeline_phase_width, - ), - row_style, - ), - ( - f"{wall:>12} ", - unavailable_row_style - if timeline_row.wall_seconds is None - else metric_row_style, - ), - ( - f"{cpu:>12} ", - unavailable_row_style - if timeline_row.cpu_seconds is None - else (summary_style if is_summary else title_style), - ), - ( - f"{peak:>12} ", - unavailable_row_style - if timeline_row.peak_memory_bytes is None - else (summary_style if is_summary else memory_style), - ), - ( - outcome, - summary_style - if is_summary - else outcome_style(timeline_row.status), - ), - ], - ) - else: - _append_dashboard_line( - details, - [ - ("Phase timeline ", key_style), - ("unavailable (older result)", warning_style), - ], - ) - _append_detail_fields( - details, - ( - ( - "Wall", - _human_phase_duration(selected.wall_seconds), - metric_style, - ), - ( - "CPU", - ( - "unavailable" - if selected.cpu_seconds is None - else _human_phase_duration(selected.cpu_seconds) - ), - muted_style if selected.cpu_seconds is None else metric_style, - ), - ), - width=width, - compact=compact, - key_style=key_style, - ) - _append_detail_fields( - details, - ( - ("RSS current", _human_bytes(selected.current_rss_bytes), memory_style), - ("RSS peak", _human_bytes(selected.peak_rss_bytes), memory_style), - ), - width=width, - compact=compact, - key_style=key_style, - ) - if selected.current_physical_footprint_bytes is not None and not compact: - physical_peak = ( - selected.peak_physical_footprint_bytes - if selected.peak_physical_footprint_bytes is not None - else selected.current_physical_footprint_bytes - ) - _append_detail_fields( - details, - ( - ( - "Physical current", - _human_bytes(selected.current_physical_footprint_bytes), - memory_style, - ), - ("Physical peak", _human_bytes(physical_peak), memory_style), - ), - width=width, - compact=compact, - key_style=key_style, - ) - if not (compact and not persisted_summary): - _append_detail_fields( - details, - ( - ( - "Guard current", - _human_bytes(enforcement_current), - enforcement_style, - ), - ("Guard peak", _human_bytes(enforcement_peak), enforcement_style), - ("RAM cap", _human_bytes(state.memory_limit_bytes), warning_style), - ( - "Physical current" if compact else "Worker wall cap", - ( - ( - "unavailable" - if selected.current_physical_footprint_bytes is None - else _human_bytes( - selected.current_physical_footprint_bytes - ) - ) - if compact - else ( - "disabled" - if state.worker_wall_limit_seconds is None - else _human_duration(state.worker_wall_limit_seconds) - ) - ), - ( - muted_style - if ( - ( - compact - and selected.current_physical_footprint_bytes - is None - ) - or ( - not compact - and state.worker_wall_limit_seconds is None - ) - ) - else (memory_style if compact else warning_style) - ), - ), - ), - width=width, - compact=compact, - key_style=key_style, - ) - evaluator_total = selected.published_evaluator_total_seconds_per_point - recurrence_core = selected.published_recurrence_core_seconds_per_point - missing_published = ( - "pending" - if selected.status in {"queued", "preparing", "running"} - else ( - "not exposed" - if selected.status in _COMPLETED_WORKER_STATUSES - else "unavailable" - ) - ) - missing_recurrence_core = ( - "not applicable" - if selected.generation_engine is not None - and selected.generation_engine != ExecutionMode.RECURRENCE.value - else missing_published - ) - outer_wall_value = ( - missing_published - if selected.published_wall_seconds_per_point is None - else f"{selected.published_wall_seconds_per_point * 1.0e6:.6g} μs/pt" - ) - evaluator_total_value = ( - missing_published - if evaluator_total is None - else f"{evaluator_total * 1.0e6:.6g} μs/pt" - ) - _append_detail_fields( - details, - ( - ( - "Outer wall", - outer_wall_value, - ( - muted_style - if selected.published_wall_seconds_per_point is None - else metric_style - ), - ), - ( - "Evaluator total", - evaluator_total_value, - muted_style if evaluator_total is None else metric_style, - ), - ), - width=width, - compact=compact, - key_style=key_style, - ) - recurrence_value = ( - missing_recurrence_core - if recurrence_core is None - else f"{recurrence_core * 1.0e6:.6g} μs/pt" - ) - _append_detail_fields( - details, - ( - ( - "Recurrence core", - recurrence_value, - muted_style if recurrence_core is None else metric_style, - ), - ("Attribution", "independent narrow clock", muted_style), - ), - width=width, - compact=compact, - key_style=key_style, - ) - if not compact: - progress_details = _progress_detail_summary(selected.progress_details) - if progress_details: - _append_dashboard_line( - details, - [ - ("Progress data ", key_style), - (progress_details, neutral_style), - ], - ) - _append_detail_fields( - details, - ( - ( - "PID tree", - ", ".join(str(value) for value in selected.member_pids) or "—", - metric_style, - ), - ("Attempt", selected.attempt_id or "—", neutral_style), - ), - width=width, - compact=compact, - key_style=key_style, - ) - if selected.log_tail and not compact and not persisted_summary: - for index, line in enumerate(selected.log_tail[-3:]): - _append_dashboard_line( - details, - [ - ("Recent log " if index == 0 else " ", key_style), - (line, neutral_style), - ], - ) - if not compact: - visible_events = _coalesced_worker_events(selected.events) - if not persisted_summary: - for event in visible_events[-max(1, detail_height - 6) :]: - _append_dashboard_line( - details, - [("• ", key_style), (event, neutral_style)], - ) - available_commands = _available_reproduction_stages(selected) - if available_commands: - _append_dashboard_line( - details, - [ - ("Commands ", key_style), - *( - span - for stage in available_commands - for span in ( - ( - f"{_REPRODUCTION_STAGES.index(stage) + 1} ", - key_style, - ), - (stage, success_style), - (" ", neutral_style), - ) - ), - ("open full command · y copies there", muted_style), - ], - ) - elif selected.generation_engine == ExecutionMode.AMPLICOL.value: - _append_dashboard_line( - details, - [ - ("Commands ", key_style), - ( - "original AmpliCol uses the report adapter; " - "no public CLI reproduction is available", - muted_style, - ), - ], - ) - ratio = _worker_progress_ratio(selected) - gauge_label = ( - selected.progress_message or f"{selected.phase} {round(100.0 * ratio):d}%" - ) - if selected is not None and state.command_stage is not None: - stage = state.command_stage - command = _reproduction_command(selected, stage) - command_details = Paragraph.new_empty() - command_details.set_block_title( - f" Reproduction command · {stage} · {selected.cell_id} " - ) - _append_dashboard_line( - command_details, - [ - ("Stage ", key_style), - (stage, success_style if command is not None else warning_style), - (" 1 prepare 2 generate 3 profile Tab/←/→ cycle", muted_style), - ], - ) - _append_dashboard_line( - command_details, - [ - ("Copy ", key_style), - ("y exact clipboard", success_style), - (" Print ", key_style), - ("p normal terminal", metric_style), - *( - () - if compact - else ((" Scroll PgUp/PgDn Close Esc", muted_style),) - ), - ], - ) - if compact: - _append_dashboard_line( - command_details, - [("Scroll PgUp/PgDn Close Esc", muted_style)], - ) - if state.command_notice: - _append_dashboard_line( - command_details, - [ - ("Status ", key_style), - ( - state.command_notice, - warning_style - if "unavailable" in state.command_notice.casefold() - else success_style, - ), - ], - ) - if command is None: - _append_dashboard_line( - command_details, - [ - ("Unavailable ", warning_style), - ( - "this worker does not expose that public CLI stage", - muted_style, - ), - ], - ) - else: - wrapped = textwrap.wrap( - command, - width=max(24, width - 6), - break_long_words=True, - break_on_hyphens=False, - replace_whitespace=False, - drop_whitespace=True, - ) or [command] - header_lines = (4 if compact else 3) + bool(state.command_notice) - command_capacity = max(1, detail_height - 4 - header_lines) - command_start = min( - max(0, state.command_scroll), - max(0, len(wrapped) - command_capacity), - ) - command_end = min(len(wrapped), command_start + command_capacity) - _append_dashboard_line( - command_details, - [ - ("Exact command ", key_style), - ( - f"{len(command):,} characters · wrapped lines " - f"{command_start + 1}-{command_end}/{len(wrapped)}", - muted_style, - ), - ], - ) - for line in wrapped[command_start:command_end]: - _append_dashboard_line( - command_details, - [(" ", key_style), (line, neutral_style)], - ) - command_details.set_wrap(False) - details = command_details - else: - details.set_scroll(state.detail_scroll) - - gauge = Gauge().ratio(ratio).label(gauge_label) - gauge.set_styles( - neutral_style, - gauge_label_style, - gauge_value_style, - ) - if state.command_stage is not None: - footer_text = ( - ( - " 1/2/3 stage Tab cycle Pg scroll y copy" - " p print Esc close Ctrl-C stop " - ) - if compact - else ( - " 1/2/3 stage Tab/←/→ cycle PgUp/PgDn scroll" - " y copy p print Esc close Ctrl-C stop " - ) - ) - elif compact: - footer_text = ( - " ↑/↓ select d done e errors 1/2/3 command ? help Ctrl-C stop safely " - ) - else: - footer_text = ( - " ↑/↓ select d completed e errors 1/2/3 command" - " PgUp/PgDn details ? help Ctrl-C stop safely " - ) - footer = Paragraph.from_text(footer_text) - - return [ - DrawCmd.paragraph(overview, (0, 0, width, overview_height)), - DrawCmd.paragraph(worker_table, (0, overview_height, width, table_height)), - DrawCmd.paragraph(details, (0, detail_y, width, detail_height - 2)), - DrawCmd.gauge(gauge, (0, height - 3, width, 2)), - DrawCmd.paragraph(footer, (0, height - 1, width, footer_height)), - ] - - -def render_dashboard_frame( - state: DashboardState, - *, - width: int, - height: int, - cells: bool = False, - color: bool = True, -) -> object: - if width < 60 or height < 18: - raise ManualCampaignError("dashboard dimensions must be at least 60x18") - try: - from ratatui_py import headless_render_frame, headless_render_frame_cells - except ImportError as error: - raise ManualCampaignError( - "Ratatui is unavailable; run `just dev-install`" - ) from error - commands = _ratatui_commands(state, width=width, height=height, color=color) - if cells: - return headless_render_frame_cells(width, height, commands) - return headless_render_frame(width, height, commands) - - -def _toggle_worker_filter(state: DashboardState, attribute: str) -> None: - selected = state.selected_worker() - selected_identity = ( - None if selected is None else (selected.cell_id, selected.peer_instance) - ) - setattr(state, attribute, not bool(getattr(state, attribute))) - rows = state.visible_workers() - if not rows: - state.selected_index = 0 - elif selected_identity is not None: - state.selected_index = next( - ( - index - for index, worker in enumerate(rows) - if (worker.cell_id, worker.peer_instance) == selected_identity - ), - min(state.selected_index, len(rows) - 1), - ) - else: - state.selected_index %= len(rows) - state.detail_scroll = 0 - - -def _handle_dashboard_key( - state: DashboardState, - event: Mapping[str, object], - cancellation: threading.Event, -) -> bool: - """Apply one Ratatui key event; return true when rendering should stop.""" - - from ratatui import KeyCode, KeyMods - - if event.get("kind") != "key": - return False - code = event.get("code") - ch = event.get("ch") - mods = _optional_int(event.get("mods")) or 0 - if code == KeyCode.Char and ch in {ord("c"), ord("C")} and mods & int(KeyMods.CTRL): - state.interrupted = True - cancellation.set() - return True - if code == KeyCode.Esc and state.command_stage is not None: - state.command_stage = None - state.command_scroll = 0 - state.command_notice = None - state.pending_clipboard = None - state.pending_print = None - elif code == KeyCode.Up or (code == KeyCode.Char and ch == ord("k")): - state.selected_index -= 1 - state.detail_scroll = 0 - state.command_scroll = 0 - state.command_notice = None - elif code == KeyCode.Down or (code == KeyCode.Char and ch == ord("j")): - state.selected_index += 1 - state.detail_scroll = 0 - state.command_scroll = 0 - state.command_notice = None - elif code == KeyCode.PageUp: - if state.command_stage is None: - state.detail_scroll = max(0, state.detail_scroll - 3) - else: - state.command_scroll = max(0, state.command_scroll - 3) - elif code == KeyCode.PageDown: - if state.command_stage is None: - state.detail_scroll += 3 - else: - state.command_scroll += 3 - elif code == KeyCode.Char and ch in {ord("1"), ord("2"), ord("3")}: - assert isinstance(ch, int) - state.command_stage = _REPRODUCTION_STAGES[ch - ord("1")] - state.command_scroll = 0 - state.command_notice = None - state.show_help = False - elif code == KeyCode.Tab or code == KeyCode.Right: - _cycle_reproduction_stage(state, 1) - state.show_help = False - elif code == KeyCode.Left: - _cycle_reproduction_stage(state, -1) - state.show_help = False - elif code == KeyCode.Char and ch in {ord("y"), ord("Y")}: - command = _reproduction_command(state.selected_worker(), state.command_stage) - if command is None or state.command_stage is None: - state.command_notice = "Selected command is unavailable" - else: - state.pending_clipboard = (state.command_stage, command) - elif code == KeyCode.Char and ch in {ord("p"), ord("P")}: - command = _reproduction_command(state.selected_worker(), state.command_stage) - if command is None or state.command_stage is None: - state.command_notice = "Selected command is unavailable" - else: - state.pending_print = (state.command_stage, command) - elif code == KeyCode.Char and ch in {ord("d"), ord("D")}: - _toggle_worker_filter(state, "show_completed") - elif code == KeyCode.Char and ch in {ord("e"), ord("E")}: - _toggle_worker_filter(state, "show_errors") - elif code == KeyCode.Char and ch == ord("?"): - state.show_help = not state.show_help - state.command_stage = None - state.detail_scroll = 0 - elif code == KeyCode.Esc: - state.interrupted = True - cancellation.set() - return True - return False - - -@contextmanager -def _ratatui_terminal_session() -> Iterator[Any]: - """Open Ratatui without calling the package's unsafe mode wrappers. - - ``ratatui_py.terminal_session`` currently calls several native functions - without the terminal handle required by the bundled FFI. The native - terminal constructor and destructor already own raw-mode and alternate- - screen setup/cleanup, selected through environment variables, so use that - supported lifecycle directly. - """ - - try: - from ratatui_py import Terminal - except ImportError as error: - raise ManualCampaignError( - "Ratatui is unavailable; run `just dev-install`" - ) from error - - alt_was_set = "RATATUI_FFI_ALTSCR" in os.environ - previous_alt = os.environ.get("RATATUI_FFI_ALTSCR") - no_raw_was_set = "RATATUI_FFI_NO_RAW" in os.environ - previous_no_raw = os.environ.get("RATATUI_FFI_NO_RAW") - os.environ["RATATUI_FFI_ALTSCR"] = "1" - os.environ.pop("RATATUI_FFI_NO_RAW", None) - try: - terminal = Terminal() - finally: - if alt_was_set: - os.environ["RATATUI_FFI_ALTSCR"] = previous_alt or "" - else: - os.environ.pop("RATATUI_FFI_ALTSCR", None) - if no_raw_was_set: - os.environ["RATATUI_FFI_NO_RAW"] = previous_no_raw or "" - else: - os.environ.pop("RATATUI_FFI_NO_RAW", None) - - try: - yield terminal - finally: - terminal.close() - - -def _run_live_dashboard( - lease: LeaseManager, - state: DashboardState, - finished: threading.Event, - cancellation: threading.Event, - *, - color: bool = True, -) -> None: - while not finished.is_set(): - print_request: tuple[str, str] | None = None - with _ratatui_terminal_session() as terminal: - while not finished.is_set(): - display_state = lease.dashboard_snapshot() - width, height = terminal.size() - terminal.draw_frame( - _ratatui_commands( - display_state, - width=width, - height=height, - color=color, - ) - ) - event = terminal.next_event(timeout_ms=150) - if event is None: - continue - if _handle_dashboard_key(state, event, cancellation): - return - if state.pending_clipboard is not None: - stage, command = state.pending_clipboard - state.pending_clipboard = None - try: - sys.stdout.write(_osc52_clipboard_sequence(command)) - sys.stdout.flush() - except OSError: - state.command_notice = ( - "Clipboard unavailable; press p to print the command" - ) - else: - state.command_notice = ( - f"Copied full {stage} command ({len(command):,} characters)" - ) - if state.pending_print is not None: - print_request = state.pending_print - state.pending_print = None - break - if print_request is None: - continue - stage, command = print_request - print(f"\nFull {stage} command ({len(command):,} characters):\n") - print(command) - print() - with suppress(EOFError): - input("Press Enter to return to the dashboard… ") - state.command_notice = f"Returned from printed {stage} command" - - -def _manual_baseline( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> CellSpec | None: - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - return None - dataset_id = f"reference_amplicol_{cell.measurement.accuracy.value}" - return next( - ( - candidate - for candidate in catalog.measurement_cells() - if candidate.dataset_id == dataset_id - and candidate.process_key == cell.process_key - and candidate.n_final == cell.n_final - and candidate.workload is cell.workload - ), - None, - ) - - -@dataclass(frozen=True, slots=True) -class Comparison: - cell: CellSpec - baseline: CellSpec - candidate: float - reference: float - - @property - def multiplier(self) -> float: - return self.candidate / self.reference - - -def _number(measurement: Mapping[str, object], field: str) -> float | None: - value = measurement.get(field) - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or float(value) <= 0.0 - ): - return None - return float(value) - - -def _evaluator_total_number(measurement: Mapping[str, object]) -> float | None: - record = evaluator_total_timing_record(measurement) - return None if record is None else _number(record, "raw_seconds_per_point") - - -def _recurrence_core_number(measurement: Mapping[str, object]) -> float | None: - return recurrence_core_seconds_per_point(measurement) - - -@dataclass(frozen=True, slots=True) -class AbsoluteMetric: - cell: CellSpec - value: float - - -def _absolute_metric_identity(item: AbsoluteMetric) -> dict[str, object]: - cell = item.cell - return { - "table": cell.dataset_id, - "cell_id": cell.cell_id, - "process_id": cell.process_key, - "process": cell.process, - "multiplicity": cell.n_final, - "color_approximation": cell.measurement.accuracy.value, - "generation_mode": cell.workload.value, - "generation_engine": cell.measurement.execution_mode.value, - "backend": cell.measurement.backend, - "model": ( - None if cell.measurement.model is None else cell.measurement.model.value - ), - "variant": cell.variant, - "seconds_per_point": item.value, - "microseconds_per_point": item.value * 1.0e6, - } - - -def _inspect_recurrence_core( - cells: Sequence[CellSpec], - currents: Mapping[str, LightweightCurrent], -) -> tuple[dict[str, object], Counter[str]]: - observations: list[AbsoluteMetric] = [] - exclusions: Counter[str] = Counter() - for cell in cells: - if cell.measurement.execution_mode is not ExecutionMode.RECURRENCE: - exclusions["not_recurrence"] += 1 - continue - current = currents.get(cell.cell_id) - if current is None: - exclusions["candidate_missing"] += 1 - continue - if not current.reusable: - exclusions[f"candidate_{current.reason.replace(' ', '_')}"] += 1 - continue - if current.result.get("status") in { - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - }: - exclusions["candidate_resource_capped"] += 1 - continue - value = _recurrence_core_number(current.result) - if value is None: - exclusions["value_unavailable"] += 1 - continue - observations.append(AbsoluteMetric(cell=cell, value=value)) - ordered = sorted(observations, key=lambda item: item.value) - values = [item.value for item in ordered] - payload: dict[str, object] = { - "count": len(ordered), - "fastest": (None if not ordered else _absolute_metric_identity(ordered[0])), - "slowest": (None if not ordered else _absolute_metric_identity(ordered[-1])), - "median_seconds_per_point": (None if not values else statistics.median(values)), - "mean_seconds_per_point": (None if not values else statistics.fmean(values)), - } - return payload, exclusions - - -def comparison_statistics(comparisons: Sequence[Comparison]) -> dict[str, object]: - if not comparisons: - return { - "count": 0, - "best": None, - "worst": None, - "median": None, - "mean": None, - "weighted_mean": None, - } - ordered = sorted(comparisons, key=lambda item: item.multiplier) - ratios = [item.multiplier for item in ordered] - return { - "count": len(ordered), - "best": ordered[0], - "worst": ordered[-1], - "median": statistics.median(ratios), - "mean": statistics.fmean(ratios), - "weighted_mean": ( - math.fsum(item.candidate for item in ordered) - / math.fsum(item.reference for item in ordered) - ), - } - - -def _comparison_identity(item: Comparison) -> dict[str, object]: - cell = item.cell - return { - "table": cell.dataset_id, - "cell_id": cell.cell_id, - "process_id": cell.process_key, - "process": cell.process, - "multiplicity": cell.n_final, - "color_approximation": cell.measurement.accuracy.value, - "generation_mode": cell.workload.value, - "generation_engine": cell.measurement.execution_mode.value, - "backend": cell.measurement.backend, - "model": ( - None if cell.measurement.model is None else cell.measurement.model.value - ), - "variant": cell.variant, - "candidate": item.candidate, - "amplicol": item.reference, - "multiplier": item.multiplier, - "amplicol_cell_id": item.baseline.cell_id, - } - - -def _inspect_metric( - cells: Sequence[CellSpec], - currents: Mapping[str, LightweightCurrent], - *, - field: str | None, - generation: bool, - evaluator_total: bool = False, -) -> tuple[dict[str, object], Counter[str]]: - comparisons: list[Comparison] = [] - exclusions: Counter[str] = Counter() - for cell in cells: - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - exclusions["amplicol_candidate"] += 1 - continue - baseline = _manual_baseline(cell) - if baseline is None: - exclusions["no_amplicol_baseline"] += 1 - continue - if generation and cell.workload is Workload.ALL_FLOW: - exclusions["incompatible_generation_layout"] += 1 - continue - candidate_current = currents.get(cell.cell_id) - baseline_current = currents.get(baseline.cell_id) - if candidate_current is None: - exclusions["candidate_missing"] += 1 - continue - if not candidate_current.reusable: - exclusions[f"candidate_{candidate_current.reason.replace(' ', '_')}"] += 1 - continue - if baseline_current is None: - exclusions["baseline_missing"] += 1 - continue - if not baseline_current.reusable: - exclusions[f"baseline_{baseline_current.reason.replace(' ', '_')}"] += 1 - continue - if candidate_current.result.get("status") in { - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - }: - exclusions["candidate_resource_capped"] += 1 - continue - if baseline_current.result.get("status") in { - ResultStatus.TIMEOUT.value, - ResultStatus.MEMORY_LIMIT.value, - }: - exclusions["baseline_resource_capped"] += 1 - continue - if evaluator_total: - candidate = _evaluator_total_number(candidate_current.result) - reference = _evaluator_total_number(baseline_current.result) - else: - assert field is not None - candidate = _number(candidate_current.result, field) - reference = _number(baseline_current.result, field) - if candidate is None or reference is None: - exclusions["value_unavailable"] += 1 - continue - comparisons.append(Comparison(cell, baseline, candidate, reference)) - raw = comparison_statistics(comparisons) - payload = { - key: (_comparison_identity(value) if isinstance(value, Comparison) else value) - for key, value in raw.items() - } - return payload, exclusions - - -def _inspect_payload( - service: ReportService, - cells: Sequence[CellSpec], - *, - source_revision: str, - renderer_revision: str, - accept_historical_source: bool = False, -) -> dict[str, object]: - required = {cell.cell_id: cell for cell in cells} - for cell in cells: - baseline = _manual_baseline(cell) - if baseline is not None: - required[baseline.cell_id] = baseline - currents = lightweight_currents( - service, - tuple(required.values()), - source_revision=source_revision, - accept_historical_source=accept_historical_source, - ) - outcomes = lightweight_presentation_outcomes( - service, - tuple(required.values()), - source_revision=source_revision, - accept_historical_source=accept_historical_source, - ) - statuses: Counter[str] = Counter() - unverified_diagnostics: list[dict[str, object]] = [] - for cell in cells: - if _manual_static_na_reason(cell) is not None: - statuses["static_not_available"] += 1 - continue - current = currents.get(cell.cell_id) - outcome = outcomes.get(cell.cell_id) - if current is None: - if outcome is None or outcome.successful: - statuses[ResultStatus.NOT_AVAILABLE.value] += 1 - else: - statuses[outcome.status] += 1 - if outcome.status == ResultStatus.UNVERIFIED.value: - diagnostic = _presentation_measurement( - service, - cell, - outcome, - ) - if diagnostic.get("status") == ResultStatus.UNVERIFIED.value: - provenance = diagnostic.get("provenance") - evaluator = ( - provenance.get("evaluator_total_timing") - if isinstance(provenance, Mapping) - else None - ) - unverified_diagnostics.append( - { - "cell_id": cell.cell_id, - "attempt_id": outcome.attempt_id, - "generation_seconds": diagnostic.get( - "generation_seconds" - ), - "wall_seconds_per_point": diagnostic.get( - "wall_seconds_per_point" - ), - "evaluator_total_seconds_per_point": ( - evaluator.get("raw_seconds_per_point") - if isinstance(evaluator, Mapping) - else None - ), - "reason": ( - diagnostic.get("failure", {}).get("message") - if isinstance(diagnostic.get("failure"), Mapping) - else outcome.label - ), - } - ) - elif not current.reusable: - statuses[current.reason.replace(" ", "_")] += 1 - else: - statuses[str(current.result.get("status"))] += 1 - generation, generation_exclusions = _inspect_metric( - cells, - currents, - field="generation_seconds", - generation=True, - ) - runtime, runtime_exclusions = _inspect_metric( - cells, - currents, - field="wall_seconds_per_point", - generation=False, - ) - evaluator_total, evaluator_total_exclusions = _inspect_metric( - cells, - currents, - field=None, - generation=False, - evaluator_total=True, - ) - recurrence_core, recurrence_core_exclusions = _inspect_recurrence_core( - cells, - currents, - ) - selected_currents = tuple( - currents[cell.cell_id] - for cell in cells - if cell.cell_id in currents and currents[cell.cell_id].reusable - ) - clock_coverage = { - "outer_wall_available": sum( - _number(current.result, "wall_seconds_per_point") is not None - for current in selected_currents - ), - "evaluator_total_available": sum( - _evaluator_total_number(current.result) is not None - for current in selected_currents - ), - "recurrence_core_available": sum( - _recurrence_core_number(current.result) is not None - for current in selected_currents - ), - } - return { - "profile": _ACTIVE_PROFILE, - "source_revision": source_revision, - "renderer_source_revision": renderer_revision, - "source_policy": ( - "continue_across_revisions" - if accept_historical_source - else "strict_same_source" - ), - "source_cohorts": _source_cohort_counts(currents), - "selection_count": len(cells), - "reusable_count": sum( - bool(current.reusable) - for cell_id, current in currents.items() - if cell_id in {cell.cell_id for cell in cells} - ), - "statuses": dict(sorted(statuses.items())), - "unverified_diagnostics": sorted( - unverified_diagnostics, - key=lambda item: str(item["cell_id"]), - ), - "generation_multiplier_vs_amplicol": generation, - "runtime_wall_multiplier_vs_amplicol": runtime, - "runtime_evaluator_total_multiplier_vs_amplicol": evaluator_total, - "recurrence_core_absolute": recurrence_core, - "clock_coverage": clock_coverage, - "exclusions": { - "generation": dict(sorted(generation_exclusions.items())), - "runtime_wall": dict(sorted(runtime_exclusions.items())), - "runtime_evaluator_total": dict(sorted(evaluator_total_exclusions.items())), - "recurrence_core": dict(sorted(recurrence_core_exclusions.items())), - }, - "clock_note": ( - "Outer wall, evaluator-total, and recurrence core are independent " - "raw clocks; unavailable values are never copied or derived." - ), - } - - -def _format_multiplier(value: object) -> str: - return "—" if value is None else f"{float(value):.4g}x" - - -def _paint_multiplier(palette: Palette, value: object) -> str: - rendered = _format_multiplier(value) - if value is None: - return palette.neutral(rendered) - multiplier = float(value) - if math.isclose(multiplier, 1.0, rel_tol=1.0e-12, abs_tol=1.0e-12): - return palette.neutral(rendered) - return palette.success(rendered) if multiplier < 1.0 else palette.failure(rendered) - - -def _format_seconds_per_point(value: object) -> str: - return "—" if value is None else f"{float(value) * 1.0e6:.6g} μs/pt" - - -def _print_inspect(payload: Mapping[str, object], palette: Palette) -> None: - source_revision = str(payload["source_revision"]) - renderer_revision = str(payload["renderer_source_revision"]) - source_cohorts = payload["source_cohorts"] - if not isinstance(source_cohorts, Mapping): - raise ManualCampaignError("inspect source cohort summary is malformed") - rendered_source_cohorts = _format_source_cohorts( - {str(revision): int(count) for revision, count in source_cohorts.items()} - ) - identity_rows: list[tuple[object, object]] = [ - (palette.key("profile"), payload["profile"]), - (palette.key("source policy"), payload["source_policy"]), - (palette.key("active measurement build"), source_revision), - ( - palette.key("measurement source cohorts"), - rendered_source_cohorts, - ), - ] - if renderer_revision != source_revision: - identity_rows.append((palette.key("renderer checkout"), renderer_revision[:12])) - identity_rows.extend( - ( - (palette.key("selected"), payload["selection_count"]), - (palette.key("reusable"), palette.success(payload["reusable_count"])), - ( - palette.key("clock coverage"), - ", ".join( - f"{key}={value}" for key, value in payload["clock_coverage"].items() - ), - ), - (palette.key("clock semantics"), payload["clock_note"]), - ) - ) - print( - _table( - ("key", "value"), - identity_rows, - ) - ) - statuses = payload["statuses"] - assert isinstance(statuses, Mapping) - print() - print( - _table( - ("status", "entries"), - ( - ( - palette.key(status), - ( - palette.success(count) - if status == ResultStatus.OK.value - else ( - palette.failure(count) - if any( - token in status - for token in ("error", "failed", "mismatch") - ) - else palette.warning(count) - ) - ), - ) - for status, count in statuses.items() - ), - align={"entries": "r"}, - ) - ) - unverified = payload.get("unverified_diagnostics") - if isinstance(unverified, list) and unverified: - print() - print( - _table( - ( - "unverified cell", - "generation", - "wall", - "evaluator total", - "reason", - ), - ( - ( - item.get("cell_id"), - ( - "—" - if item.get("generation_seconds") is None - else f"{float(item['generation_seconds']):.6g} s" - ), - _format_seconds_per_point( - item.get("wall_seconds_per_point") - ), - _format_seconds_per_point( - item.get("evaluator_total_seconds_per_point") - ), - item.get("reason"), - ) - for item in unverified - if isinstance(item, Mapping) - ), - ) - ) - rows: list[tuple[object, ...]] = [] - for title, key in ( - ("Generation", "generation_multiplier_vs_amplicol"), - ("Runtime wall", "runtime_wall_multiplier_vs_amplicol"), - ( - "Runtime evaluator total", - "runtime_evaluator_total_multiplier_vs_amplicol", - ), - ): - summary = payload[key] - assert isinstance(summary, Mapping) - best = summary.get("best") - worst = summary.get("worst") - rows.append( - ( - palette.key(title), - summary.get("count"), - _paint_multiplier( - palette, - (None if not isinstance(best, Mapping) else best.get("multiplier")), - ), - _paint_multiplier(palette, summary.get("median")), - _paint_multiplier(palette, summary.get("mean")), - _paint_multiplier(palette, summary.get("weighted_mean")), - _paint_multiplier( - palette, - ( - None - if not isinstance(worst, Mapping) - else worst.get("multiplier") - ), - ), - ) - ) - print() - print( - _table( - ( - "metric", - "pairs", - "best", - "median", - "average", - "weighted avg", - "worst", - ), - rows, - align={"pairs": "r"}, - ) - ) - core_summary = payload["recurrence_core_absolute"] - assert isinstance(core_summary, Mapping) - fastest = core_summary.get("fastest") - slowest = core_summary.get("slowest") - print() - print( - _table( - ("metric", "samples", "fastest", "median", "average", "slowest"), - ( - ( - palette.key("Recurrence core (absolute)"), - core_summary.get("count"), - _format_seconds_per_point( - fastest.get("seconds_per_point") - if isinstance(fastest, Mapping) - else None - ), - _format_seconds_per_point( - core_summary.get("median_seconds_per_point") - ), - _format_seconds_per_point( - core_summary.get("mean_seconds_per_point") - ), - _format_seconds_per_point( - slowest.get("seconds_per_point") - if isinstance(slowest, Mapping) - else None - ), - ), - ), - align={"samples": "r"}, - ) - ) - identities: list[tuple[object, ...]] = [] - for title, key in ( - ("generation best", "generation_multiplier_vs_amplicol"), - ("generation worst", "generation_multiplier_vs_amplicol"), - ("runtime best", "runtime_wall_multiplier_vs_amplicol"), - ("runtime worst", "runtime_wall_multiplier_vs_amplicol"), - ( - "evaluator-total best", - "runtime_evaluator_total_multiplier_vs_amplicol", - ), - ( - "evaluator-total worst", - "runtime_evaluator_total_multiplier_vs_amplicol", - ), - ): - summary = payload[key] - assert isinstance(summary, Mapping) - identity = summary.get("best" if title.endswith("best") else "worst") - if not isinstance(identity, Mapping): - continue - for label, identity_field in ( - ("table", "table"), - ("cell", "cell_id"), - ("process ID", "process_id"), - ("concrete process", "process"), - ("multiplicity", "multiplicity"), - ("colour", "color_approximation"), - ("layout/workload", "generation_mode"), - ("engine", "generation_engine"), - ("backend", "backend"), - ("model", "model"), - ("variant", "variant"), - ("candidate value", "candidate"), - ("AmpliCol baseline", "amplicol"), - ("multiplier", "multiplier"), - ): - value = identity.get(identity_field) - if identity_field == "multiplier": - value = _paint_multiplier(palette, value) - identities.append((palette.key(title), palette.key(label), value)) - for title, identity in ( - ("recurrence-core fastest", fastest), - ("recurrence-core slowest", slowest), - ): - if not isinstance(identity, Mapping): - continue - for label, identity_field in ( - ("table", "table"), - ("cell", "cell_id"), - ("process ID", "process_id"), - ("concrete process", "process"), - ("multiplicity", "multiplicity"), - ("colour", "color_approximation"), - ("layout/workload", "generation_mode"), - ("engine", "generation_engine"), - ("backend", "backend"), - ("model", "model"), - ("variant", "variant"), - ("absolute value", "seconds_per_point"), - ): - value = identity.get(identity_field) - if identity_field == "seconds_per_point": - value = _format_seconds_per_point(value) - identities.append((palette.key(title), palette.key(label), value)) - if identities: - print() - print( - _table( - ("extreme", "key", "value"), - identities, - ) - ) - exclusions = payload["exclusions"] - assert isinstance(exclusions, Mapping) - print() - print( - _table( - ("metric", "excluded reason", "count"), - ( - (palette.key(metric), reason, count) - for metric, raw in exclusions.items() - if isinstance(raw, Mapping) - for reason, count in raw.items() - ), - align={"count": "r"}, - ) - ) - - -def _campaign_settings( - arguments: argparse.Namespace, - source: ReportSourceIdentity, - *, - original_amplicol_available: bool = False, - observer: Any = None, - cancelled: Any = None, - campaign_invocation_id: str | None = None, -) -> CampaignSettings: - workers = int(arguments.workers) - cores = int(arguments.cores_per_worker) - amplicol_build_jobs = int(getattr(arguments, "amplicol_build_jobs", 1)) - available = os.cpu_count() or 1 - effective_worker_cores = max(cores, amplicol_build_jobs) - if workers * effective_worker_cores > available and not bool( - arguments.allow_oversubscription - ): - raise ManualCampaignError( - f"{workers} workers x {effective_worker_cores} maximum per-worker " - f"cores exceeds {available} logical CPUs; lower --workers, " - "--cores-per-worker, or --amplicol-build-jobs, or pass " - "--allow-oversubscription" - ) - fresh_attempt = _fresh_attempt_requested(arguments) - original_amplicol_revision = getattr( - arguments, - "original_amplicol_revision", - None, - ) - return CampaignSettings( - workers=workers, - cell_cores=cores, - amplicol_build_jobs=amplicol_build_jobs, - target_runtime_seconds=float(arguments.target_measurement_duration), - batch_size=int(arguments.batch_size), - warmup_runs=int(arguments.warmups), - minimum_samples=int(arguments.minimum_samples), - timeout_seconds=arguments.worker_wall_limit, - generation_time_limit_seconds=float(arguments.generation_time_limit), - profiling_time_limit_seconds=( - None - if arguments.worker_wall_limit is None - else float(arguments.worker_wall_limit) - ), - validation_time_limit_seconds=( - None - if arguments.worker_wall_limit is None - else float(arguments.worker_wall_limit) - ), - max_rss_bytes=int(arguments.ram_limit), - campaign_max_rss_bytes=( - None - if getattr(arguments, "campaign_ram_limit", None) is None - else int(arguments.campaign_ram_limit) - ), - attempt_output_limit_bytes=int( - getattr( - arguments, - "attempt_output_limit", - DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES, - ) - ), - minimum_free_disk_bytes=int( - getattr( - arguments, - "minimum_free_disk", - DEFAULT_MINIMUM_FREE_DISK_BYTES, - ) - ), - artifact_policy=( - ArtifactPolicy.REGENERATE - if fresh_attempt - else ArtifactPolicy.REUSE - ), - missing_only=not fresh_attempt, - rerun=fresh_attempt, - add_optional_dependencies=not bool( - getattr(arguments, "no_dependencies_added", False) - ), - original_amplicol_available=original_amplicol_available, - allow_symbolica_parallel=bool(arguments.allow_engine_parallelism), - resource_sample_interval_seconds=float(arguments.resource_sample_interval), - termination_grace_seconds=float(arguments.termination_grace), - source_identity_override=source, - campaign_invocation_id=campaign_invocation_id, - progress_observer=observer, - cancellation_requested=cancelled, - manual_terminal_censors=True, - discard_cancelled_attempts=False, - remove_heavy_attempt_artifacts=_artifact_cleanup_enabled(arguments), - retain_workspaces=bool(getattr(arguments, "retain_workspaces", False)), - report_profile=None, - original_amplicol_repository=( - arguments.original_amplicol - if original_amplicol_revision is not None - else None - ), - original_amplicol_revision=original_amplicol_revision, - madgraph_installation=getattr(arguments, "madgraph", None), - multiplicity_wave_barrier=bool(getattr(arguments, "fail_fast", False)), - ) - - -def _validated_original_amplicol_checkout(path: Path) -> tuple[Path, str]: - """Return one clean checkout exposing the maintained profiling interface.""" - - repository = path.expanduser().resolve(strict=True) - missing = tuple( - name - for name in _ORIGINAL_AMPLICOL_REQUIRED_FILES - if not (repository / name).is_file() or (repository / name).is_symlink() - ) - if missing: - raise ManualCampaignError( - "--original-amplicol is not a complete patched checkout; missing " - + ", ".join(missing) - ) - makefile = (repository / "makefile").read_text( - encoding="utf-8", - errors="replace", - ) - missing_targets = tuple( - target - for target in _ORIGINAL_AMPLICOL_REQUIRED_MAKE_TARGETS - if re.search(rf"(?m)^{re.escape(target)}\s*:", makefile) is None - ) - if missing_targets: - raise ManualCampaignError( - "--original-amplicol lacks required Make targets: " - + ", ".join(missing_targets) - ) - head = subprocess.run( - ("git", "rev-parse", "HEAD"), - cwd=repository, - check=False, - capture_output=True, - text=True, - ) - revision = head.stdout.strip() - if head.returncode != 0 or re.fullmatch(r"[0-9a-f]{40}", revision) is None: - raise ManualCampaignError( - "--original-amplicol must be a Git checkout with a concrete HEAD" - ) - status = subprocess.run( - ("git", "status", "--porcelain=v1", "--untracked-files=all"), - cwd=repository, - check=False, - capture_output=True, - text=True, - ) - if status.returncode != 0 or status.stdout: - raise ManualCampaignError( - "--original-amplicol must be a clean checkout; commit, remove, " - "or relocate local changes and build products first" - ) - return repository, revision - - -def _configured_original_amplicol(docs_dir: Path) -> Path | None: - config = docs_dir / _LOCAL_AMPLICOL_CONFIG - if not config.exists(): - return None - if config.is_symlink() or not config.is_file(): - raise ManualCampaignError( - f"campaign local-AmpliCol configuration is not a regular file: {config}" - ) - try: - lines = config.read_text(encoding="utf-8").splitlines() - except OSError as error: - raise ManualCampaignError( - f"cannot read campaign local-AmpliCol configuration: {config}" - ) from error - if len(lines) != 1 or not lines[0] or not Path(lines[0]).is_absolute(): - raise ManualCampaignError( - f"campaign local-AmpliCol configuration is invalid: {config}" - ) - return Path(lines[0]) - - -def _configured_madgraph(docs_dir: Path) -> Path | None: - config = docs_dir / _LOCAL_MADGRAPH_CONFIG - if not config.exists(): - return None - if config.is_symlink() or not config.is_file(): - raise ManualCampaignError( - f"campaign MadGraph configuration is not a regular file: {config}" - ) - try: - lines = config.read_text(encoding="utf-8").splitlines() - except OSError as error: - raise ManualCampaignError( - f"cannot read campaign MadGraph configuration: {config}" - ) from error - if len(lines) != 1 or not lines[0] or not Path(lines[0]).is_absolute(): - raise ManualCampaignError( - f"campaign MadGraph configuration is invalid: {config}" - ) - return Path(lines[0]) - - -def _validated_madgraph_installation(path: Path) -> Path: - try: - installation = path.expanduser().resolve(strict=True) - except (OSError, RuntimeError) as error: - raise ManualCampaignError( - f"--madgraph installation does not exist: {path}" - ) from error - if not installation.is_dir(): - raise ManualCampaignError( - f"--madgraph must name an installation directory: {installation}" - ) - executable = installation / "bin/mg5_aMC" - try: - executable_mode = executable.stat(follow_symlinks=False).st_mode - except OSError as error: - raise ManualCampaignError( - "--madgraph must contain a regular executable bin/mg5_aMC" - ) from error - if not stat.S_ISREG(executable_mode) or not os.access(executable, os.X_OK): - raise ManualCampaignError( - "--madgraph must contain a regular executable bin/mg5_aMC" - ) - return installation - - -def _resolve_madgraph( - arguments: argparse.Namespace, - *, - installed: bool, - docs_dir: Path, -) -> Path | None: - installation = arguments.madgraph - if installation is None and installed: - installation = _configured_madgraph(docs_dir) - if installation is None: - return None - return _validated_madgraph_installation(installation) - - -def _original_amplicol_available_for_planning( - arguments: argparse.Namespace, - *, - installed: bool, - root: Path, - docs_dir: Path, -) -> bool: - """Whether optional validation dependencies may include original AmpliCol.""" - - if bool(getattr(arguments, "no_dependencies_added", False)): - return False - if arguments.original_amplicol is not None: - return True - if not installed: - return (root / "dependencies/checkouts/legacy-amplicol").is_dir() - try: - configured = _configured_original_amplicol(docs_dir) - except ManualCampaignError: - return False - return configured is not None and configured.is_dir() - - -def _resolve_original_amplicol( - arguments: argparse.Namespace, - *, - installed: bool, - root: Path, - docs_dir: Path, -) -> tuple[Path | None, str | None]: - original = arguments.original_amplicol - if original is None: - if installed: - original = _configured_original_amplicol(docs_dir) - else: - default_original = root / "dependencies/checkouts/legacy-amplicol" - if default_original.is_dir(): - original = default_original - if original is None: - return None, None - return _validated_original_amplicol_checkout(original) - - -def _bind_original_amplicol_if_required( - arguments: argparse.Namespace, - planned: Sequence[PlannedCell], - *, - installed: bool, - root: Path, - docs_dir: Path, -) -> None: - """Validate the optional legacy checkout only for work that will use it.""" - - if not any( - item.cell.measurement.execution_mode is ExecutionMode.AMPLICOL - for item in planned - ): - arguments.original_amplicol = None - arguments.original_amplicol_revision = None - return - repository, revision = _resolve_original_amplicol( - arguments, - installed=installed, - root=root, - docs_dir=docs_dir, - ) - if repository is None: - raise ManualCampaignError( - "this campaign selection requires original AmpliCol; pass " - "--original-amplicol PATH_TO_COMPLETE_CHECKOUT containing the " - "profiling interface from AmpliCol PR #12" - ) - arguments.original_amplicol = repository - arguments.original_amplicol_revision = revision - - -def _dry_run_rows( - direct: Sequence[CellSpec], - planned: Sequence[PlannedCell], - *, - repo_root: Path, - artifact_root: Path, - arguments: argparse.Namespace, -) -> Iterable[tuple[object, ...]]: - direct_ids = {cell.cell_id for cell in direct} - for item in planned: - recipe = reproduction_recipe( - item.cell, - repo_root=repo_root, - artifact_root=artifact_root, - cores=arguments.cores_per_worker, - target_runtime=arguments.target_measurement_duration, - batch_size=arguments.batch_size, - warmups=arguments.warmups, - minimum_samples=arguments.minimum_samples, - ) - role = "direct" if item.cell.cell_id in direct_ids else "dependency" - yield ( - f"{role} · rank {item.rank}", - "\n".join( - ( - item.cell.cell_id, - f"engine: {item.cell.measurement.execution_mode.value}", - f"kind: {recipe.kind}", - f"exact: {'yes' if recipe.exact else 'no'}", - f"note: {recipe.note}", - ) - ), - ) - - -def _wrapped_shell( - arguments: Sequence[str], - *, - width: int, - indent: str = " ", -) -> str: - """Wrap shell words without splitting quoted arguments.""" - - words = [shlex.quote(str(argument)) for argument in arguments] - lines: list[str] = [] - current = indent - for word in words: - separator = "" if current == indent else " " - if current != indent and len(current) + len(separator) + len(word) > width: - lines.append(current) - current = indent + word - else: - current += separator + word - if current != indent: - lines.append(current) - return " \\\n".join(lines) - - -def _dry_run_recipe_blocks( - direct: Sequence[CellSpec], - *, - repo_root: Path, - artifact_root: Path, - arguments: argparse.Namespace, - width: int, -) -> Iterable[str]: - for index, cell in enumerate(direct, start=1): - if _manual_static_na_reason(cell) is not None: - continue - recipe = reproduction_recipe( - cell, - repo_root=repo_root, - artifact_root=artifact_root, - cores=arguments.cores_per_worker, - target_runtime=arguments.target_measurement_duration, - batch_size=arguments.batch_size, - warmups=arguments.warmups, - minimum_samples=arguments.minimum_samples, - ) - metadata = _table( - ("key", "value"), - ( - ("recipe", index), - ("cell", cell.cell_id), - ("kind", recipe.kind), - ("exact", "yes" if recipe.exact else "no"), - ("note", recipe.note), - ), - max_width={"value": max(36, width - 16)}, - ) - commands: list[str] = [metadata] - for label, command in ( - ("Prepare prerequisite", recipe.prepare), - ("Generate", recipe.generate), - ( - "Profile" if recipe.exact else "Profile template/diagnostic", - recipe.profile, - ), - ): - if command is None: - continue - commands.extend((f"{label}:", _wrapped_shell(command, width=width))) - yield "\n".join(commands) - - -def _cancel_and_join_campaign_worker( - worker: threading.Thread, - cancellation: threading.Event, - *, - timeout_seconds: float, -) -> tuple[bool, bool]: - """Poll cancellation until the non-daemon controller has fully exited.""" - - cancellation.set() - interrupted = False - poll_seconds = min(max(timeout_seconds, 0.05), 0.25) - notice_polls = max(1, math.ceil(max(timeout_seconds, 1.0) / poll_seconds)) - polls = 0 - while worker.is_alive(): - try: - worker.join(timeout=poll_seconds) - except KeyboardInterrupt: - interrupted = True - cancellation.set() - print( - "Interrupt repeated; still waiting for supervised worker-tree " - "cleanup...", - file=sys.stderr, - flush=True, - ) - polls += 1 - if worker.is_alive() and polls % notice_polls == 0: - cancellation.set() - print( - "Waiting for campaign cancellation cleanup; no leases or claims " - "will be released early...", - file=sys.stderr, - flush=True, - ) - return interrupted, False - - -def _recycled_attention_workers( - cells: Sequence[CellSpec], - currents: Mapping[str, LightweightCurrent], - recycled_ids: set[str], - *, - repo_root: Path, - artifact_root: Path, - settings: ReproductionSettings, -) -> dict[str, WorkerView]: - """Expose same-source recycled currents without scanning attempt history.""" - - workers: dict[str, WorkerView] = {} - for cell in cells: - if cell.cell_id not in recycled_ids: - continue - current = currents.get(cell.cell_id) - if current is None: - continue - result_status = str(current.result.get("status") or "") - state = policy_measurement_state_hint(current.result) - status = ( - "recycled" - if result_status in {ResultStatus.OK.value, "reused", "skipped-current"} - else (None if state is None else state.value) - ) - if status is None: - continue - resources = current.result.get("resources") - resource_values = resources if isinstance(resources, Mapping) else {} - provenance = current.result.get("provenance") - manual = ( - provenance.get("manual_campaign") - if isinstance(provenance, Mapping) - else None - ) - stored_recipe = ( - manual.get("public_cli_reproduction") - if isinstance(manual, Mapping) - else None - ) - recipe = None - if not isinstance(stored_recipe, Mapping): - recipe = reproduction_recipe( - cell, - repo_root=repo_root, - artifact_root=artifact_root, - cores=settings.cores, - target_runtime=settings.target_runtime, - batch_size=settings.batch_size, - warmups=settings.warmups, - minimum_samples=settings.minimum_samples, - measurement=current.result, - ) - - worker = WorkerView( - cell.cell_id, - generation_engine=cell.measurement.execution_mode.value, - status=status, - step=( - "recycled generation-time cap" - if status == "generation_limit" - else ( - "recycled process-tree RAM cap" - if status == "memory_limit" - else ( - f"recycled {status.replace('_', ' ')}" - if status in _TERMINAL_CAP_STATUSES - else "reused existing current" - ) - ) - ), - phase="recycled current", - attempt_id=current.attempt_id, - wall_seconds=_finite_float(resource_values.get("wall_seconds")), - cpu_seconds=_optional_finite_float(resource_values.get("cpu_seconds")), - current_rss_bytes=_optional_int(resource_values.get("current_rss_bytes")) - or 0, - peak_rss_bytes=_optional_int(resource_values.get("peak_rss_bytes")) or 0, - current_physical_footprint_bytes=_optional_int( - resource_values.get("current_physical_footprint_bytes") - ), - peak_physical_footprint_bytes=_optional_int( - resource_values.get("peak_physical_footprint_bytes") - ), - current_guard_bytes=_optional_int( - resource_values.get("current_guard_bytes") - ) - or 0, - peak_guard_bytes=_optional_int(resource_values.get("peak_guard_bytes")) - or 0, - progress_completed=1, - progress_total=1, - progress_message=( - "recycled capped result" - if status in _TERMINAL_CAP_STATUSES - else "recycled current" - ), - reproduce_prepare=( - _stored_reproduction_command(stored_recipe, "prepare") - if recipe is None - else (None if recipe.prepare is None else _shell_join(recipe.prepare)) - ), - reproduce_generate=( - _stored_reproduction_command(stored_recipe, "generate") - if recipe is None - else (None if recipe.generate is None else _shell_join(recipe.generate)) - ), - reproduce_profile=( - _stored_reproduction_command(stored_recipe, "profile") - if recipe is None - else (None if recipe.profile is None else _shell_join(recipe.profile)) - ), - published_wall_seconds_per_point=_number( - current.result, - "wall_seconds_per_point", - ), - published_evaluator_total_seconds_per_point=( - _evaluator_total_number(current.result) - ), - published_recurrence_core_seconds_per_point=( - _recurrence_core_number(current.result) - ), - recycled=True, - reuse_explanation=current.reason, - events=[f"recycled: {current.reason}"], - ) - _apply_persisted_worker_result( - worker, - current.result, - recycled=True, - reuse_explanation=current.reason, - ) - workers[cell.cell_id] = worker - return workers - - -def _run_campaign( - arguments: argparse.Namespace, - *, - repo_root: Path, - service: ReportService, - source: ReportSourceIdentity, - cells: Sequence[CellSpec], - palette: Palette, - installed: bool = False, -) -> int: - invocation_command = getattr(arguments, "_campaign_invocation_command", None) - if not isinstance(invocation_command, str) or not invocation_command: - invocation_command = ( - "steer_performance_campaign.py run " - "" - ) - selective_retry = _selective_retry_requested(arguments) - if bool(getattr(arguments, "force_refresh", False)) and selective_retry: - raise ManualCampaignError( - "--force-refresh cannot be combined with --rerun-failed or " - "--rerun-capped; use force refresh for every selected cell or the " - "selective retry flags" - ) - fresh_attempt = _fresh_attempt_requested(arguments) - measurable = tuple(cell for cell in cells if _manual_static_na_reason(cell) is None) - static_na = { - cell.cell_id for cell in cells if _manual_static_na_reason(cell) is not None - } - if not measurable and selective_retry: - print( - palette.success( - "No measurable selected entries match the requested selective " - "retry; no workers or attempts were created." - ) - ) - return 0 - if not measurable: - print( - palette.warning( - f"All {len(cells)} selected entries are policy/static unavailable; " - "no attempts were created." - ) - ) - print( - _table( - ("cell", "reason"), - ((cell.cell_id, _manual_static_na_reason(cell)) for cell in cells), - ) - ) - if not arguments.dry_run: - summary_path, summary_counts = _publish_campaign_summary_ids( - service, - {"static_na": static_na}, - ) - _print_campaign_summary_ids(summary_path, summary_counts, palette) - return 0 - active_lightweight = lightweight_currents( - service, - measurable, - source_revision=source.revision, - ) - continue_across_revisions = bool( - getattr(arguments, "continue_across_revisions", False) - ) - lightweight = ( - lightweight_currents( - service, - measurable, - source_revision=source.revision, - accept_historical_source=True, - ) - if continue_across_revisions - else active_lightweight - ) - if selective_retry: - outcomes = lightweight_presentation_outcomes( - service, - measurable, - source_revision=source.revision, - accept_historical_source=continue_across_revisions, - ) - base_measurable_count = len(measurable) - measurable = _selective_retry_cells( - measurable, - lightweight, - outcomes, - rerun_failed=bool(getattr(arguments, "rerun_failed", False)), - rerun_capped=bool(getattr(arguments, "rerun_capped", False)), - ) - if not measurable: - requested = " and ".join( - option - for option, enabled in ( - ("--rerun-failed", getattr(arguments, "rerun_failed", False)), - ("--rerun-capped", getattr(arguments, "rerun_capped", False)), - ) - if enabled - ) - print( - palette.success( - f"No entries among {base_measurable_count} measurable " - f"selected cells match {requested}; no workers or attempts " - "were created." - ) - ) - return 0 - matched_ids = {cell.cell_id for cell in measurable} - cells = measurable - static_na = set() - active_lightweight = { - cell_id: current - for cell_id, current in active_lightweight.items() - if cell_id in matched_ids - } - lightweight = { - cell_id: current - for cell_id, current in lightweight.items() - if cell_id in matched_ids - } - print( - palette.warning( - f"Selective retry matched {len(measurable)} of " - f"{base_measurable_count} measurable selected entries." - ) - ) - recycled = { - cell_id - for cell_id, current in lightweight.items() - if current.reusable and not fresh_attempt - } - historical_recycled = { - cell_id - for cell_id in recycled - if _measurement_source_revision(lightweight[cell_id].result) != source.revision - } - requested_for_plan = tuple( - cell - for cell in measurable - if fresh_attempt or cell.cell_id not in historical_recycled - ) - original_amplicol_available = _original_amplicol_available_for_planning( - arguments, - installed=installed, - root=repo_root, - docs_dir=service.paths.docs_dir, - ) - arguments.madgraph = _resolve_madgraph( - arguments, - installed=installed, - docs_dir=service.paths.docs_dir, - ) - preliminary_settings = _campaign_settings( - arguments, - source, - original_amplicol_available=original_amplicol_available, - ) - planned = plan_campaign( - requested_for_plan, - store=service.store, - settings=preliminary_settings, - expected_revision=source.revision, - expected_tree=None, - current_resolver=_lightweight_current_resolver( - service, - source_revision=source.revision, - initial=active_lightweight, - ), - ) - # A historical cell can still be required as an active-source dependency - # of a newly measured cell. In that case it is work, not recycled work. - recycled.difference_update(item.cell.cell_id for item in planned) - selected_cohorts = _source_cohort_counts( - lightweight, - cell_ids=recycled, - ) - if continue_across_revisions: - print( - palette.warning( - "Cross-revision continuation is enabled: completed selected " - "currents are kept per cell; dependencies needed by new work " - "still require the active source revision. Recycled cohorts: " - f"{_format_source_cohorts(selected_cohorts)}" - ) - ) - if arguments.dry_run: - terminal_width = max( - 80, - min(160, shutil.get_terminal_size(fallback=(120, 24)).columns), - ) - print( - _table( - ("key", "value"), - ( - (palette.key("direct entries"), len(cells)), - (palette.key("static N/A"), len(static_na)), - (palette.key("recycled"), len(recycled)), - ( - palette.key("historical recycled"), - len(recycled & historical_recycled), - ), - (palette.key("planned with dependencies"), len(planned)), - (palette.key("source"), source.revision), - ( - palette.key("source policy"), - ( - "continue across revisions" - if continue_across_revisions - else "strict same-source" - ), - ), - ( - palette.key("artifact cleanup"), - ( - "compact retention (default)" - if _artifact_cleanup_enabled(arguments) - else "full debug workspaces (--retain-workspaces)" - ), - ), - ), - ) - ) - print() - if static_na: - print( - _table( - ("static/policy unavailable cell", "reason"), - ( - (cell.cell_id, _manual_static_na_reason(cell)) - for cell in cells - if cell.cell_id in static_na - ), - ) - ) - print() - print( - _table( - ("entry", "details"), - _dry_run_rows( - cells, - planned, - repo_root=repo_root, - artifact_root=service.paths.artifact_root, - arguments=arguments, - ), - max_width={"entry": 18, "details": max(48, terminal_width - 27)}, - ) - ) - direct_recipes = tuple( - cell for cell in cells if _manual_static_na_reason(cell) is None - ) - for block in _dry_run_recipe_blocks( - direct_recipes, - repo_root=repo_root, - artifact_root=service.paths.artifact_root, - arguments=arguments, - width=terminal_width, - ): - print() - print(block) - return 0 - - _bind_original_amplicol_if_required( - arguments, - planned, - installed=installed, - root=repo_root, - docs_dir=service.paths.docs_dir, - ) - - require_measurement_ready(source) - if continue_across_revisions: - update_source_marker( - service, - source, - continue_across_revisions=True, - ) - else: - update_source_marker(service, source) - campaign_invocation_id = uuid.uuid4().hex - for warning in _publish_recycled_presentation_outcomes( - service, - lightweight, - recycled, - source_revision=source.revision, - campaign_invocation_id=campaign_invocation_id, - accept_historical_source=continue_across_revisions, - ): - print( - palette.warning(f"presentation outcome warning: {warning}"), - file=sys.stderr, - ) - if _artifact_cleanup_enabled(arguments): - cleanup_cells = tuple( - { - cell.cell_id: cell - for cell in ( - *measurable, - *(item.cell for item in planned), - ) - }.values() - ) - cleanup_warnings = reconcile_attempt_history(service, cleanup_cells) - for cell_id, detail in cleanup_warnings: - print( - palette.warning( - f"artifact cleanup skipped for {cell_id}: {detail}" - ), - file=sys.stderr, - ) - measurable_ids = {cell.cell_id for cell in measurable} - if not planned and measurable_ids <= recycled: - print( - _table( - ("key", "value"), - ( - (palette.key("selected entries"), len(cells)), - (palette.key("measurable entries"), len(measurable)), - ( - palette.key("recycled measurable entries"), - palette.success(len(recycled)), - ), - ( - palette.key("static N/A entries"), - ( - palette.warning(len(static_na)) - if static_na - else palette.neutral(0) - ), - ), - (palette.key("workers created"), palette.success(0)), - (palette.key("attempts created"), palette.success(0)), - ), - align={"value": "r"}, - ) - ) - print() - print( - palette.success( - "All selected measurable entries were recycled " - f"({len(recycled)} of {len(measurable)}); no workers or " - "attempts were created." - ) - ) - if static_na: - print( - palette.warning( - f"{len(static_na)} selected static N/A " - f"{'entry remains' if len(static_na) == 1 else 'entries remain'} " - "policy unavailable and accounted for separately." - ) - ) - summary_path, summary_counts = _publish_campaign_summary_ids( - service, - _campaign_summary_categories( - static_na_ids=static_na, - ), - ) - _print_campaign_summary_ids(summary_path, summary_counts, palette) - return 0 - cancellation = threading.Event() - finished = threading.Event() - state = DashboardState( - instance_id=campaign_invocation_id, - selected_ids=tuple(cell.cell_id for cell in cells), - recycled_ids=recycled, - static_na_ids=static_na, - source_revision=source.revision, - generation_time_limit_seconds=float(arguments.generation_time_limit), - memory_limit_bytes=( - preliminary_settings.effective_cell_rss_limit() - or int(arguments.ram_limit) - ), - worker_wall_limit_seconds=arguments.worker_wall_limit, - reproduction_settings=ReproductionSettings( - cores=int(arguments.cores_per_worker), - target_runtime=float(arguments.target_measurement_duration), - batch_size=int(arguments.batch_size), - warmups=int(arguments.warmups), - minimum_samples=int(arguments.minimum_samples), - ), - dependency_ids={item.cell.cell_id for item in planned if item.dependency}, - ) - state.workers.update( - _recycled_attention_workers( - measurable, - lightweight, - recycled, - repo_root=repo_root, - artifact_root=service.paths.artifact_root, - settings=state.reproduction_settings, - ) - ) - for cell_id, worker in state.workers.items(): - state._reduce_finished( - cell_id, - worker.status, - recycled=worker.recycled, - ) - lease = LeaseManager(service, state) - lease.publish() - fail_fast_observer = ( - _FailFastObserver(lease.observe, cancellation) - if bool(getattr(arguments, "fail_fast", False)) - else None - ) - settings = _campaign_settings( - arguments, - source, - original_amplicol_available=original_amplicol_available, - observer=( - lease.observe - if fail_fast_observer is None - else fail_fast_observer.observe - ), - cancelled=cancellation.is_set, - campaign_invocation_id=state.instance_id, - ) - scheduler = CampaignScheduler(service, settings=settings) - result_holder: list[CampaignResult] = [] - error_holder: list[BaseException] = [] - - def execute() -> None: - try: - result_holder.append(scheduler.run(planned)) - except BaseException as error: - error_holder.append(error) - finally: - finished.set() - - worker = threading.Thread( - target=execute, - name="manual-performance-campaign", - daemon=False, - ) - worker.start() - interrupted = False - join_interrupted = False - worker_alive = False - try: - interactive = ( - not arguments.no_dashboard - and bool(getattr(sys.stdin, "isatty", lambda: False)()) - and bool(getattr(sys.stdout, "isatty", lambda: False)()) - ) - if interactive: - _run_live_dashboard( - lease, - state, - finished, - cancellation, - color=palette.enabled, - ) - else: - while not finished.wait(timeout=0.25): - pass - except KeyboardInterrupt: - interrupted = True - state.interrupted = True - cancellation.set() - finally: - if state.interrupted: - interrupted = True - try: - join_interrupted, worker_alive = _cancel_and_join_campaign_worker( - worker, - cancellation, - timeout_seconds=max(5.0, arguments.termination_grace + 2.0), - ) - finally: - lease.close() - if join_interrupted or worker_alive: - interrupted = True - state.interrupted = True - fail_fast_failure = ( - None if fail_fast_observer is None else fail_fast_observer.failure - ) - _print_cleanup_warnings(state, palette) - if interrupted: - result = result_holder[0] if result_holder else None - _publish_completion_summary( - service, - _campaign_summary_categories( - static_na_ids=static_na, - result=result, - state=state, - interrupted=True, - ), - state=state, - fail_fast_failure=fail_fast_failure, - invocation_command=invocation_command, - palette=palette, - ) - artifact_outcome = ( - "disposable workspaces were compacted (default)" - if _artifact_cleanup_enabled(arguments) - else "full debug workspaces were retained (--retain-workspaces)" - ) - print( - palette.warning( - "Interrupted: dispatch stopped, process trees received cancellation, " - "compact interrupted-attempt diagnostics and completed currents " - f"were preserved, {artifact_outcome}, and leases were removed." - ), - file=sys.stderr, - ) - return 130 - if error_holder: - partial_result = result_holder[0] if result_holder else None - if fail_fast_failure is not None or _has_invocation_summary_evidence( - partial_result, state - ): - _publish_completion_summary( - service, - _campaign_summary_categories( - static_na_ids=static_na, - result=partial_result, - state=state, - ), - state=state, - fail_fast_failure=fail_fast_failure, - invocation_command=invocation_command, - palette=palette, - ) - raise error_holder[0] - result = result_holder[0] - statuses = Counter(outcome.status for outcome in result.outcomes) - print( - _table( - ("status", "entries"), - ( - ( - palette.key(status), - ( - palette.success(count) - if status in _FAIL_FAST_SUCCESS_STATUSES - else palette.warning(count) - ), - ) - for status, count in sorted(statuses.items()) - ), - align={"entries": "r"}, - ) - ) - _publish_completion_summary( - service, - _campaign_summary_categories( - static_na_ids=static_na, - result=result, - state=state, - ), - state=state, - fail_fast_failure=fail_fast_failure, - invocation_command=invocation_command, - palette=palette, - ) - if bool(getattr(arguments, "fail_fast", False)): - has_terminal_failure = any( - outcome.status not in _FAIL_FAST_SUCCESS_STATUSES - and outcome.status != "cancelled" - for outcome in result.outcomes - ) - return 1 if fail_fast_failure is not None or has_terminal_failure else 0 - return 1 if result.failed else 0 - - -def _capture_lightweight_snapshot( - service: ReportService, - *, - source_revision: str, - accept_historical_source: bool = False, - progress: _SnapshotProgress | None = None, -) -> tuple[ - dict[str, LightweightCurrent], - dict[str, LightweightPresentationOutcome], - tuple[tuple[str, str], ...], -]: - cells = tuple(service.catalog.measurement_cells()) - total = 4 * len(cells) - for attempt in range(3): - started_at = time.monotonic() - completed_offset = 0 - last_update = 0.0 - - if progress is not None: - progress.begin( - total=total, - attempt=attempt + 1, - maximum_attempts=3, - ) - - def callback( - stage: str, - stage_offset: int, - ) -> Callable[[int, int], None] | None: - nonlocal last_update - if progress is None: - return None - progress.update(stage_offset, total, stage) - - def update(completed: int, _stage_total: int) -> None: - nonlocal last_update - now = time.monotonic() - overall = stage_offset + completed - if completed == 1 or overall == total or now - last_update >= 0.08: - progress.update(overall, total, stage) - last_update = now - - return update - - try: - currents = lightweight_currents( - service, - cells, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - progress=callback( - "Reading current records", - completed_offset, - ), - ) - completed_offset += len(cells) - outcomes = lightweight_presentation_outcomes( - service, - cells, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - progress=callback( - "Reading terminal outcomes", - completed_offset, - ), - ) - completed_offset += len(cells) - identity = tuple( - sorted( - (cell_id, current.attempt_id) - for cell_id, current in currents.items() - if current.reusable - ) - ) - outcome_identity = tuple( - sorted( - (cell_id, outcome.ordering_key) - for cell_id, outcome in outcomes.items() - ) - ) - confirmed = lightweight_currents( - service, - cells, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - progress=callback( - "Confirming current records", - completed_offset, - ), - ) - completed_offset += len(cells) - confirmed_outcomes = lightweight_presentation_outcomes( - service, - cells, - source_revision=source_revision, - accept_historical_source=accept_historical_source, - progress=callback( - "Confirming terminal outcomes", - completed_offset, - ), - ) - confirmed_identity = tuple( - sorted( - (cell_id, current.attempt_id) - for cell_id, current in confirmed.items() - if current.reusable - ) - ) - confirmed_outcome_identity = tuple( - sorted( - (cell_id, outcome.ordering_key) - for cell_id, outcome in confirmed_outcomes.items() - ) - ) - stable = ( - identity == confirmed_identity - and outcome_identity == confirmed_outcome_identity - ) - except BaseException: - if progress is not None: - progress.end( - success=False, - message="artifact scan failed", - elapsed_seconds=time.monotonic() - started_at, - ) - raise - final_attempt = attempt + 1 == 3 - if progress is not None: - progress.end( - success=stable or not final_attempt, - message=( - "stable snapshot captured" - if stable - else ( - "campaign state remained unstable after three scans" - if final_attempt - else "campaign state changed; rescanning" - ) - ), - elapsed_seconds=time.monotonic() - started_at, - ) - if stable: - return currents, outcomes, identity - raise ManualCampaignError( - "current pointers or presentation outcomes changed during three " - "snapshot reads; retry refresh-pdf" - ) - - -def _merge_lightweight_snapshot( - service: ReportService, - currents: Mapping[str, LightweightCurrent], - outcomes: Mapping[str, LightweightPresentationOutcome] | None = None, -) -> tuple[dict[str, dict[str, object]], int]: - caches = service.reset_payloads() - visible_outcomes = {} if outcomes is None else outcomes - by_cell = {cell.cell_id: cell for cell in service.catalog.measurement_cells()} - merged = 0 - for payload in caches.values(): - entries = payload["entries"] - assert isinstance(entries, list) - for entry in entries: - assert isinstance(entry, dict) - cell_id = str(entry["cell_id"]) - cell = by_cell[cell_id] - if service.catalog.static_na_reason(cell) is not None: - entry["measurement"] = reset_entry(cell)["measurement"] - continue - current = currents.get(cell_id) - outcome = visible_outcomes.get(cell_id) - if ( - current is not None - and current.reusable - and current.result.get("status") == ResultStatus.OK.value - ): - measurement = dict(current.result) - elif outcome is not None and not outcome.successful: - if ( - current is not None - and current.reusable - and outcome.attempt_id is not None - and outcome.attempt_id == current.attempt_id - ): - measurement = dict(current.result) - else: - measurement = _presentation_measurement(service, cell, outcome) - elif outcome is not None and outcome.successful: - if current is None or not current.reusable: - continue - measurement = dict(current.result) - elif current is not None and current.reusable: - measurement = dict(current.result) - else: - continue - validate_measurement(measurement, expected_cell=cell) - entry["measurement"] = measurement - merged += 1 - service.validate_payloads(caches) - return caches, merged - - -def _copy_report_sources(source: Path, destination: Path) -> None: - shutil.copytree( - source, - destination, - ignore=_report_source_copy_ignore( - source, - "pyAmpliCol.pdf", - "*.aux", - "*.bbl", - "*.bcf", - "*.blg", - "*.fdb_latexmk", - "*.fls", - "*.log", - "*.out", - "*.run.xml", - "*.synctex.gz", - "*.toc", - ), - ) - - -def _selected_report_sections(raw: Sequence[str] | None) -> tuple[ReportSection, ...]: - requested = set(raw or ()) - known = {section.identifier for section in REPORT_SECTIONS} - unknown = tuple(sorted(requested - known)) - if unknown: - raise ManualCampaignError( - "unknown report section ID(s): " - + ", ".join(unknown) - + "; run `refresh-pdf --list-sections` to list valid IDs" - ) - return tuple( - section for section in REPORT_SECTIONS if section.identifier in requested - ) - - -def _filter_report_sections( - master: Path, - removed: Sequence[ReportSection], -) -> None: - """Remove selected marked sections from one private staged TeX source.""" - - removed_ids = {section.identifier for section in removed} - if not removed_ids: - return - try: - lines = master.read_text(encoding="utf-8").splitlines(keepends=True) - except OSError as error: - raise ManualCampaignError( - f"cannot read staged report source {master}" - ) from error - events = tuple( - (match.group(1), match.group(2)) - for line in lines - if (match := _REPORT_SECTION_MARKER.fullmatch(line.rstrip("\r\n"))) - is not None - ) - expected = tuple( - event - for section in REPORT_SECTIONS - for event in (("begin", section.identifier), ("end", section.identifier)) - ) - if events != expected: - raise ManualCampaignError( - "report section markers differ from the installed section registry; " - "refresh the copied campaign template before using --remove-sections" - ) - output: list[str] = [] - active: str | None = None - for line in lines: - match = _REPORT_SECTION_MARKER.fullmatch(line.rstrip("\r\n")) - if match is not None: - event, identifier = match.groups() - if event == "begin": - active = identifier - if identifier not in removed_ids: - output.append(line) - else: - if identifier not in removed_ids: - output.append(line) - active = None - continue - if active not in removed_ids: - output.append(line) - master.write_text("".join(output), encoding="utf-8") - - -def _print_report_sections(palette: Palette) -> None: - print( - _table( - ("section ID", "PDF section"), - ( - (palette.key(section.identifier), section.title) - for section in REPORT_SECTIONS - ), - ) - ) - - -def _stage_copied_profile_identity(staging_docs: Path, profile: str) -> None: - """Rebind copied workspace labels inside the private PDF build only.""" - - environment_path = staging_docs / "report_environment.json" - environment = _read_object(environment_path) - if environment is not None: - environment["profile"] = profile - _atomic_json(environment_path, environment) - - workspace_path = staging_docs / "report-workspace.json" - workspace = _read_object(workspace_path) - if workspace is not None: - workspace["profile"] = profile - workspace["artifact_root"] = "campaign_artifacts" - workspace["coordination_root"] = "campaign_artifacts/coordination" - initialized = workspace.get("initialized_environment") - if isinstance(initialized, Mapping): - workspace["initialized_environment"] = { - **initialized, - "profile": profile, - } - _atomic_json(workspace_path, workspace) - - tex_path = staging_docs / "report_environment.tex" - try: - tex = tex_path.read_text(encoding="utf-8") - except OSError: - return - escaped_profile = profile.replace("_", r"\_") - updated, replacements = re.subn( - r"(\\renewcommand\{\\ReportProfileName\}\{)[^}\r\n]*(\})", - lambda match: f"{match.group(1)}{escaped_profile}{match.group(2)}", - tex, - count=1, - ) - if replacements != 1: - raise ManualCampaignError( - "staged report environment does not define ReportProfileName" - ) - tex_path.write_text(updated, encoding="utf-8") - - -def _require_reusable_staged_environment( - staging_docs: Path, - profile: str, - *, - expected_source_revision: str, -) -> None: - """Reject authenticated metadata from an older measurement-source epoch.""" - - environment_path = staging_docs / ENVIRONMENT_JSON - if not environment_path.exists(): - # The atomic installer reports a missing report member below. This - # helper is concerned only with preventing stale authentication reuse. - return - environment = _read_object(environment_path) - if environment is None: - raise ManualCampaignError( - "staged report environment metadata is malformed" - ) - if environment.get("profile") != profile: - raise ManualCampaignError( - "staged report environment profile was not rebound" - ) - status = environment.get("status") - source_revision = environment.get("source_revision") - if status == "pending_exact_runtime" and source_revision == "pending": - return - if status == "authenticated" and source_revision == expected_source_revision: - return - raise ManualCampaignError( - "no active-source runtime witness is available, and the staged report " - "environment is not authenticated for the active measurement source" - ) - - -def _install_report_snapshot( - service: ReportService, - staging_docs: Path, - table_names: Sequence[str], -) -> None: - sources: list[tuple[Path, Path]] = [ - *( - ( - path, - service.paths.results_dir / path.name, - ) - for path in sorted((staging_docs / "results").glob("*.json")) - ), - *( - ( - staging_docs / name, - service.paths.docs_dir / name, - ) - for name in sorted(table_names) - ), - *( - ( - staging_docs / name, - service.paths.docs_dir / name, - ) - for name in (ENVIRONMENT_JSON, ENVIRONMENT_TEX) - ), - ( - staging_docs / "pyAmpliCol.pdf", - service.paths.docs_dir / "pyAmpliCol.pdf", - ), - ] - for source_path, _destination in sources: - if not source_path.is_file(): - raise ManualCampaignError(f"staged report member is missing: {source_path}") - backup_root = staging_docs.parent / "previous" - backup_root.mkdir() - replaced: list[tuple[Path, Path | None]] = [] - with service.store.named_lock("report-writer"): - try: - for source_path, destination in sources: - destination.parent.mkdir(parents=True, exist_ok=True) - backup = None - if destination.exists(): - backup = backup_root / destination.relative_to( - service.paths.docs_dir - ) - backup.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(destination, backup) - temporary = destination.with_name( - f".{destination.name}.manual-{uuid.uuid4().hex}" - ) - try: - shutil.copy2(source_path, temporary) - os.replace(temporary, destination) - finally: - temporary.unlink(missing_ok=True) - replaced.append((destination, backup)) - except BaseException: - for destination, backup in reversed(replaced): - if backup is None: - destination.unlink(missing_ok=True) - else: - os.replace(backup, destination) - raise - - -def _active_environment_runtime_witness( - currents: Mapping[str, LightweightCurrent], - *, - source_revision: str, -) -> _ProfileEnvironmentWitness | None: - """Select one consistent runtime witness from validated active currents.""" - - selected: _ProfileEnvironmentWitness | None = None - selected_identity: str | None = None - for cell_id in sorted(currents): - current = currents[cell_id] - if ( - not current.reusable - or current.result.get("status") != ResultStatus.OK.value - or _measurement_source_revision(current.result) != source_revision - ): - continue - provenance = current.result.get("provenance") - runtime = ( - provenance.get("runtime_identity") - if isinstance(provenance, Mapping) - else None - ) - if runtime is None: - # Original AmpliCol results carry no pyAmpliCol runtime witness. - continue - if ( - not isinstance(runtime, Mapping) - or runtime.get("source_revision") != source_revision - ): - raise ManualCampaignError( - f"{cell_id}: active-source runtime witness is malformed" - ) - candidate = runtime.get("candidate_build_identity") - package_tree = runtime.get("python_package_tree") - native_extension = runtime.get("native_extension") - native_target = runtime.get("native_target") - if not all( - isinstance(value, Mapping) - for value in (candidate, package_tree, native_extension, native_target) - ): - raise ManualCampaignError( - f"{cell_id}: active-source runtime witness is incomplete" - ) - assert isinstance(candidate, Mapping) - if candidate.get("source_revision") != source_revision: - raise ManualCampaignError( - f"{cell_id}: active-source runtime build identity is malformed" - ) - numpy_version = provenance.get("numpy") - if numpy_version is None: - numpy_version = _UNRECORDED_MEASUREMENT_NUMPY - host_environment = { - "platform": provenance.get("platform"), - "machine": provenance.get("machine"), - "processor": provenance.get("processor"), - "python": provenance.get("python"), - "python_implementation": provenance.get( - "python_implementation", - "CPython", - ), - "numpy": numpy_version, - } - if not all( - isinstance(host_environment[field], str) and bool(host_environment[field]) - for field in ( - "platform", - "machine", - "python", - "python_implementation", - "numpy", - ) - ) or not isinstance(host_environment["processor"], str): - raise ManualCampaignError( - f"{cell_id}: active-source measurement-host witness is incomplete" - ) - assert isinstance(package_tree, Mapping) - assert isinstance(native_extension, Mapping) - assert isinstance(native_target, Mapping) - fingerprint = candidate.get("candidate_fingerprint") - if fingerprint is None and candidate.get("publishable") is True: - fingerprint = runtime.get("candidate_build_identity_sha256") - projection = { - "source_revision": runtime.get("source_revision"), - "package_version": runtime.get("package_version"), - "python_package_tree_sha256": package_tree.get("sha256"), - "build_fingerprint": fingerprint, - "native_build_inputs_sha256": runtime.get("native_build_inputs_sha256"), - "native_extension_sha256": native_extension.get("sha256"), - "native_target": native_target.get("triple"), - "native_cpu_features": native_target.get("cpu_features"), - "measurement_host": host_environment, - } - identity = json.dumps( - projection, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - if selected_identity is not None and identity != selected_identity: - raise ManualCampaignError( - "active measurement-source currents disagree on their " - "authenticated runtime environment" - ) - selected = _ProfileEnvironmentWitness(runtime, host_environment) - selected_identity = identity - return selected - - -def _refresh_pdf( - arguments: argparse.Namespace, - *, - service: ReportService, - source: ReportSourceIdentity, - palette: Palette, -) -> int: - removed_sections = _selected_report_sections(arguments.remove_sections) - source_policy = recorded_measurement_source_policy( - service, - checkout_revision=source.revision, - ) - scan_progress: _SnapshotProgress | None = None - if not bool(arguments.quiet) and bool( - getattr(sys.stderr, "isatty", lambda: False)() - ): - scan_progress = _RefreshScanProgress(sys.stderr, palette) - try: - snapshot_arguments = { - "source_revision": source_policy.source_revision, - "accept_historical_source": ( - source_policy.continue_across_revisions - ), - } - if scan_progress is None: - currents, outcomes, snapshot = _capture_lightweight_snapshot( - service, - **snapshot_arguments, - ) - else: - currents, outcomes, snapshot = _capture_lightweight_snapshot( - service, - progress=scan_progress, - **snapshot_arguments, - ) - finally: - if scan_progress is not None: - scan_progress.close() - source_cohorts = _source_cohort_counts(currents) - environment_runtime = _active_environment_runtime_witness( - currents, - source_revision=source_policy.source_revision, - ) - publication_caches, merged = _merge_lightweight_snapshot( - service, - currents, - ) - render_caches, _presentation_merged = _merge_lightweight_snapshot( - service, - currents, - outcomes, - ) - build_root = service.paths.artifact_root / "manual-publication-builds" - build_root.mkdir(parents=True, exist_ok=True) - staging = Path(tempfile.mkdtemp(prefix="refresh-", dir=build_root)) - try: - staging_docs = staging / "docs" - _copy_report_sources(service.paths.docs_dir, staging_docs) - _stage_copied_profile_identity( - staging_docs, - service.paths.docs_dir.name, - ) - if environment_runtime is not None: - record_authenticated_profile_environment( - staging_docs, - service.paths.docs_dir.name, - expected_source_revision=source_policy.source_revision, - active_runtime=environment_runtime.active_runtime, - host_environment=environment_runtime.host_environment, - ) - else: - _require_reusable_staged_environment( - staging_docs, - service.paths.docs_dir.name, - expected_source_revision=source_policy.source_revision, - ) - _filter_report_sections( - staging_docs / "pyAmpliCol.tex", - removed_sections, - ) - staging_service = ReportService( - ReportPaths.from_repo( - service.paths.repo_root, - docs_dir=staging_docs, - artifact_root=service.paths.artifact_root, - coordination_root=service.paths.coordination_root, - ), - catalog=service.catalog, - ) - staging_service.bind_measurement_lineage(None) - staging_service.bind_original_amplicol_seed(None) - tables = staging_service._render_tables(render_caches) - staging_service._snapshot_files(publication_caches, tables) - page_count = _compile_pdf( - staging_docs, - expected_page_count=( - None - if arguments.expected_page_count is None - else int(arguments.expected_page_count) - ), - timeout_seconds=float(arguments.pdf_timeout), - allow_overfull_boxes=True, - stream_output=not bool(arguments.quiet), - ) - _install_report_snapshot(service, staging_docs, tuple(tables)) - finally: - shutil.rmtree(staging, ignore_errors=True) - print( - _table( - ("key", "value"), - ( - ( - palette.key("source policy"), - ( - "continue across revisions" - if source_policy.continue_across_revisions - else "strict same-source" - ), - ), - ( - palette.key("measurement source cohorts"), - _format_source_cohorts(source_cohorts), - ), - (palette.key("renderer checkout"), source.revision), - (palette.key("current snapshot"), len(snapshot)), - (palette.key("measurements merged"), merged), - (palette.key("tables rebuilt"), len(tables)), - ( - palette.key("sections omitted"), - ( - ", ".join( - section.identifier for section in removed_sections - ) - or "none" - ), - ), - (palette.key("PDF pages"), page_count), - ( - palette.key("installed"), - palette.success(service.paths.docs_dir / "pyAmpliCol.pdf"), - ), - ), - ) - ) - print(f"PDF: {(service.paths.docs_dir / 'pyAmpliCol.pdf').resolve(strict=False)}") - return 0 - - -_PROCESS_SELECTOR_GUIDE = "\n".join( - f" {family.identifier:>2}: {family.key}" for family in PROCESS_FAMILIES -) -_DATASET_SELECTOR_GUIDE = textwrap.fill( - ", ".join(sorted({cell.dataset_id for cell in REPORT_CATALOG.measurement_cells()})), - width=78, - initial_indent=" ", - subsequent_indent=" ", -) -_ALIAS_SELECTOR_GUIDE = """ - table groups: z/z_table; matrix/matrix_table; matrix_best; reference; scalar - colour: lc/leading_color/leading_colour; - nlc/next_to_leading_color/next_to_leading_colour; - full/full_color/full_colour - layouts: non_union_flow/selected_flow/single_flow/single_flow_hel_sum/ - topology_replay; union_flow/all_flow/all_flows/ - all_flows_single_hel/all_flow_union; contracted - engines: amplicol/legacy; recurrence/ampli_col; compiled; eager; - on-the-fly/otf - models: builtin/built_in/built_in_sm/builtin_sm/sm; - ufo/sm_ufo/ufo_sm/external_sm; scalar_contact; scalar_gravity -""".strip("\n") - - -STEERING_GUIDE = f""" -Steering model --------------- -Selectors are repeatable and accept several values after one option. Values -within one dimension are ORed; dimensions are ANDed. Omitted dimensions and a -quoted '*' (or 'all') mean all values. Hyphens, underscores, and case are -normalized. `non-union-flow` means one selected colour flow with the helicity -sum; `union-flow` means all colour flows at one helicity; NLC/full rows use the -contracted workload. - -`--cell-id-file` reads exact IDs, one per UTF-8 line, ignoring blank lines and -full-line `#` comments. IDs from files and `--cell-id` are ORed before the -remaining selectors are applied. Each completed run atomically refreshes -`campaign_summary_ids/`; use one or more of its status files to target a retry. -`unverified.txt` needs no `--force-refresh`: those retained diagnostics are not -successful currents, and a later recurrence authority or AmpliCol diagnostic -dependency causes the selected cells to run and validate again automatically. -By default the controller retains results, provenance, commands, progress, and -bounded log tails while removing disposable legacy/MadGraph/build workspaces -and obsolete heavy payloads. Use `--retain-workspaces` only when a debugging -session needs the full workspaces; output and free-disk safety limits still -apply. `--cleanup-artifacts` remains an accepted compatibility spelling for -the default. `--attempt-output-limit` defaults to 64 MiB per watched file and -`--minimum-free-disk` reserves 5 GiB on the campaign artifact volume. Keyboard -interruption and fail-fast leave attempts sealed with compact diagnostics -rather than leaving unbounded partial workspaces behind. - -Where the report protocol permits, the controller parses, resolves, and -dispatches the real public `pyamplicol generate` and `pyamplicol profile` -subcommands in-process. Dry runs print directly runnable generation commands -and clearly labelled pre-generation profile templates; completed recurrence -provenance replaces templates with stable selectors and a materialized exact -momenta input. Compiled generation's precompiled-model injection and -compiled/eager paired Arena publication remain explicit report-protocol -exceptions. Original AmpliCol uses its maintained legacy adapter because no -public pyamplicol subcommand exists. - -Campaign copies ---------------- -Create a complete reset campaign with -`pyamplicol profiling-campaign copy DESTINATION`. The destination directory -name is the profile identity, so separate copies receive distinct artifact, -coordination, source-marker, result, and PDF paths. - -Resource and availability policy --------------------------------- -Multiplicity-eight all-flow recurrence is runnable. Current releases use -bounded numerical-current evidence; a shape that cannot fit the 1-GiB envelope -visibly falls back to reuse-off while ordinary generation continues under the -generation-time and 30-GB process-tree caps. Z-table C++/ASM variants above -multiplicity six remain catalog-defined static N/A and create no attempts. - -By default the planner adds each selected cell's available validation -dependencies at the active source revision. The exact per-process order is the -original-AmpliCol diagnostic, recurrence authority, then compiled/eager -candidate; added cells are shown as dependency-only work. Independent processes -remain parallel. A missing or terminal authority releases its candidate to run -unverified rather than creating a blocked dependency. Use -`--no-dependencies-added` for an explicitly baseline-free selection; hard -construction and selector/provider dependencies are always retained. Selecting -`amplicol` explicitly still requires a clean complete checkout. An omitted -engine selector and quoted `*` both mean every engine. - -Canonical selector values and aliases -------------------------------------- - tables: z_table (z), matrix, matrix_best, reference, scalar, or exact dataset - colour: lc, nlc, full - layouts: non-union-flow (selected-flow/topology-replay), - union-flow (all-flow), contracted - engines: amplicol, recurrence, compiled, eager, on-the-fly (otf) - models: built_in (builtin_sm), sm_ufo (ufo_sm), scalar_contact, scalar_gravity - variants: recurrence_jit_o2, jit_o1, jit_o3, eager_jit_o2, cpp_o3, asm_o3 - (filters named Z implementations only; unvaried rows remain) - wildcard: quoted '*' or all; omitted selectors also mean all - -Accepted aliases ----------------- -{_ALIAS_SELECTOR_GUIDE} - -Exact dataset IDs ------------------ -{_DATASET_SELECTOR_GUIDE} - -Process IDs ------------ -{_PROCESS_SELECTOR_GUIDE} - -Common recipes --------------- - One exact cell: - steer_performance_campaign.py run --cell-id CELL_ID - - Multiplicities 3 and 4 for both SM models: - steer_performance_campaign.py run --multiplicity 3 4 --model built_in sm_ufo - - Complete Z table: - steer_performance_campaign.py run --table z_table - - Every catalog entry, planned only: - steer_performance_campaign.py run --dry-run - - Four workers, two cores each: - steer_performance_campaign.py run --workers 4 --cores-per-worker 2 - - Stop dispatch on the first terminal failure and retain its full evidence: - steer_performance_campaign.py run --fail-fast --workers 4 --table matrix - - All pyAmpliCol engines without adding optional validation dependencies: - steer_performance_campaign.py run \\ - --generation-engine recurrence compiled eager on-the-fly \\ - --no-dependencies-added - - Recompute instead of reusing same-source currents: - steer_performance_campaign.py run --force-refresh --table z_table - - Retry only failed or policy-capped cells inside the ordinary selection: - steer_performance_campaign.py run --rerun-failed --rerun-capped \ - --continue-across-revisions --table matrix - - Retry exact error and validation-failure IDs: - steer_performance_campaign.py run \ - --cell-id-file campaign_summary_ids/error.txt \ - campaign_summary_ids/validation_failed.txt \ - --force-refresh - - Keep completed cells while complementing them with a new clean build: - steer_performance_campaign.py run --continue-across-revisions \\ - --table z_table - - Inspect recurrence and compiled LC rows: - steer_performance_campaign.py inspect --color-approximation lc \\ - --generation-engine recurrence compiled - - Rebuild every JSON/TeX table and the PDF: - steer_performance_campaign.py refresh-pdf - - List stable PDF section IDs or omit selected sections from one build: - steer_performance_campaign.py refresh-pdf --list-sections - steer_performance_campaign.py refresh-pdf \\ - --remove-sections worked-zgg shared-current-dag - - Deterministic dashboard fixture for layout review: - steer_performance_campaign.py dashboard-snapshot --width 120 --height 36 - - Read-only snapshot of the newest active campaign lease: - steer_performance_campaign.py dashboard-snapshot --live - - Snapshot one concurrent invocation by exact ID or unique prefix: - steer_performance_campaign.py dashboard-snapshot --live --instance ID_PREFIX - -Keyboard controls ------------------ - ↑/↓ or j/k select a worker PgUp/PgDn scroll worker details - d show/hide completed successful workers (hidden by default) - e show/hide errors, caps, and recycled non-success rows - 1/2/3 open the complete prepare/generate/profile command drawer - Tab or ←/→ cycle available commands y copy the exact command - p print the exact command outside the dashboard for selection - Esc close the command drawer ? show dashboard help - Ctrl-C stop safely, preserve compact diagnostics, and summarize IDs - -The selected-worker panel preserves typed engine details when available, -including recurrence stages, current/contribution counts, relation counts, -and evidence sizes. RAM is the sampled process-tree current/peak usage. -""" - - -def _selector_parent() -> argparse.ArgumentParser: - parent = argparse.ArgumentParser(add_help=False) - parent.add_argument( - "--table", - nargs="+", - action="append", - metavar="TABLE", - help=( - "Rendered table/dataset selector. Canonical groups: z_table, " - "matrix, matrix_best, reference, scalar; exact dataset IDs are " - "also accepted. Repeat or supply multiple values." - ), - ) - parent.add_argument( - "--process-id", - nargs="+", - action="append", - metavar="ID", - help=( - "Process family number 1..15, process key, or quoted concrete " - "process. Numeric IDs follow the report's canonical process list." - ), - ) - parent.add_argument( - "--multiplicity", - "--multiplcity", - nargs="+", - action="append", - metavar="N", - help="Final-state multiplicity; positive integers such as 3 4.", - ) - parent.add_argument( - "--color-approximation", - "--color_approximation", - "--colour-approximation", - "--colour_approximation", - nargs="+", - action="append", - metavar="LEVEL", - help="Colour accuracy: lc, nlc, or full (friendly long aliases accepted).", - ) - parent.add_argument( - "--generation-mode", - nargs="+", - action="append", - metavar="LAYOUT", - help=( - "Workload/layout: union-flow, non-union-flow, or contracted. " - "Aliases all-flow, selected-flow, and topology-replay are accepted." - ), - ) - parent.add_argument( - "--generation-engine", - nargs="+", - action="append", - metavar="ENGINE", - help=( - "Engine: amplicol, recurrence, compiled, eager, or on-the-fly (alias otf)." - ), - ) - parent.add_argument( - "--model", - nargs="+", - action="append", - metavar="MODEL", - help=( - "Model: built_in/builtin_sm, sm_ufo/ufo_sm, scalar_contact, or " - "scalar_gravity." - ), - ) - parent.add_argument( - "--variant", - nargs="+", - action="append", - metavar="VARIANT", - help=( - "Z-table implementation variant; repeat or supply multiple values. " - "This narrows only variant-bearing rows; ordinary matrix/reference " - "rows have no variant dimension and remain eligible." - ), - ) - parent.add_argument( - "--cell-id", - nargs="+", - action="append", - metavar="CELL", - help="Exact canonical cell identity; repeat or supply multiple values.", - ) - parent.add_argument( - "--cell-id-file", - nargs="+", - action="append", - type=Path, - metavar="PATH", - help=( - "UTF-8 file containing one exact canonical cell ID per line; blank " - "lines and full-line # comments are ignored. Repeat or supply " - "multiple paths. IDs are unioned with --cell-id and intersected " - "with every other selector. Wildcards are not accepted in files. " - "Running blocked_dependency.txt plans its prerequisite closure; " - "unverified.txt retries without --force-refresh when independent " - "authority becomes available; " - "use --force-refresh when a selected ID already has a reusable " - "terminal current." - ), - ) - return parent - - -def _output_parent() -> argparse.ArgumentParser: - parent = argparse.ArgumentParser(add_help=False) - parent.add_argument( - "--no-color", - action="store_true", - help=( - "Disable ANSI colours and Ratatui styles. Output is coloured by " - "default; NO_COLOR also disables colour. Inspect JSON never contains " - "ANSI escapes; dashboard cell JSON retains numeric style metadata " - "unless colour is disabled." - ), - ) - return parent - - -def build_parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - prog="steer_performance_campaign.py", - description=( - "Safely steer, observe, inspect, and publish a pyAmpliCol " - "profiling campaign." - ), - epilog=STEERING_GUIDE, - formatter_class=HelpFormatter, - ) - commands = parser.add_subparsers(dest="command", required=True) - selectors = _selector_parent() - output = _output_parent() - - run = commands.add_parser( - "run", - parents=[selectors, output], - help="Select cells, preview dependencies, or run supervised workers.", - description=( - "Select report cells, reuse matching same-source currents by " - "default, plan dependencies, and execute resource-supervised " - "workers. Cross-revision continuation is explicit and keeps " - "active-build dependency planning strict." - ), - epilog=STEERING_GUIDE, - formatter_class=HelpFormatter, - ) - resources = run.add_argument_group("workers and resource limits") - resources.add_argument( - "--workers", - type=int, - default=1, - help="Concurrent cell workers.", - ) - resources.add_argument( - "--cores-per-worker", - type=int, - default=DEFAULT_CORES_PER_WORKER, - help="Generation/engine cores assigned to each worker.", - ) - resources.add_argument( - "--amplicol-build-jobs", - type=int, - default=1, - metavar="JOBS", - help=( - "Make jobs used only for original AmpliCol builds (default: 1). " - "Keep this at 1 for the maintained legacy checkout, whose " - "generator target is not parallel-safe." - ), - ) - resources.add_argument( - "--generation-time-limit", - type=_positive_finite_float, - default=DEFAULT_GENERATION_LIMIT_SECONDS, - metavar="SECONDS", - help=( - "Generation-only cap per process tree; preparation and legacy " - "generation count, adaptive profiling does not." - ), - ) - resources.add_argument( - "--ram-limit", - type=_positive_int, - default=DEFAULT_RAM_BYTES, - metavar="BYTES", - help="Decimal process-tree RAM ceiling per worker (30 GB = 30000000000).", - ) - resources.add_argument( - "--campaign-ram-limit", - type=_positive_int, - metavar="BYTES", - help=( - "Optional decimal RAM ceiling across all concurrent worker trees. " - "The controller enforces it conservatively by also limiting each " - "worker to this value divided by --workers; the effective worker " - "cap is the smaller of that share and --ram-limit." - ), - ) - resources.add_argument( - "--attempt-output-limit", - type=_positive_int, - default=DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES, - metavar="BYTES", - help=( - "Maximum size of each supervised attempt log/output stream " - f"(default: {DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES} bytes). A breach " - "terminates that worker tree and records an error." - ), - ) - resources.add_argument( - "--minimum-free-disk", - type=_positive_int, - default=DEFAULT_MINIMUM_FREE_DISK_BYTES, - metavar="BYTES", - help=( - "Minimum free bytes reserved on the campaign artifact volume " - f"(default: {DEFAULT_MINIMUM_FREE_DISK_BYTES}). Crossing the " - "reserve terminates the active worker tree and records an error." - ), - ) - resources.add_argument( - "--worker-wall-limit", - type=_positive_finite_float, - default=DEFAULT_WORKER_WALL_LIMIT_SECONDS, - metavar="SECONDS", - help=( - "Hard total process-tree wall-time cap per worker; defaults to " - "3600 seconds and bounds generation, profiling, validation, and " - "every descendant command." - ), - ) - resources.add_argument( - "--resource-sample-interval", - type=_positive_finite_float, - default=1.0, - metavar="SECONDS", - help="Process-tree CPU/RAM/dashboard sampling interval.", - ) - resources.add_argument( - "--termination-grace", - type=_nonnegative_finite_float, - default=5.0, - metavar="SECONDS", - help=( - "Grace after SIGTERM before a remaining process tree is killed; " - "cancelled attempts are then sealed with compact diagnostics. " - "Output/free-disk breaches escalate immediately for host safety." - ), - ) - resources.add_argument( - "--allow-oversubscription", - action="store_true", - help="Permit workers x cores to exceed logical CPU count.", - ) - resources.add_argument( - "--allow-engine-parallelism", - action="store_true", - help=( - "Allow concurrent engine preparation where the scheduler normally " - "serializes it." - ), - ) - resources.add_argument( - "--original-amplicol", - type=Path, - metavar="PATH_TO_COMPLETE_CHECKOUT", - help=( - "Clean, complete original-AmpliCol checkout containing the profiling " - "interface from PR #12 (currently amplicol_with_patches; compatible " - "upstream revisions are accepted after merge). Required when the " - "direct selection or automatically added diagnostic dependency " - "includes the amplicol engine. When no checkout is configured, " - "recurrence remains available as the authority for compiled/eager " - "work. Pass " - "--no-dependencies-added for an explicitly baseline-free selection. " - "Omitted or '*' engine selection means all engines." - ), - ) - resources.add_argument( - "--madgraph", - type=Path, - metavar="PATH_TO_MADGRAPH_INSTALLATION", - help=( - "MadGraph installation containing an executable bin/mg5_aMC. " - "Installed campaign copies default to the path saved in " - ".pyamplicol-madgraph." - ), - ) - profiling = run.add_argument_group("profiling hyperparameters") - profiling.add_argument( - "--target-measurement-duration", - type=_positive_finite_float, - default=DEFAULT_TARGET_RUNTIME_SECONDS, - metavar="SECONDS", - help="Target accumulated profiling duration for each runtime.", - ) - profiling.add_argument( - "--minimum-samples", - type=int, - default=DEFAULT_MINIMUM_SAMPLES, - help="Minimum independent timed profiling blocks (at least 5).", - ) - profiling.add_argument( - "--warmups", - type=int, - default=DEFAULT_WARMUP_RUNS, - help="Untimed runtime warmup calls before calibration.", - ) - profiling.add_argument( - "--batch-size", - type=int, - default=DEFAULT_BATCH_SIZE, - help="Phase-space points in each runtime batch.", - ) - behavior = run.add_argument_group("reuse and display") - behavior.add_argument( - "--no-dependencies-added", - action="store_true", - help=( - "Do not automatically add availability-optional numerical " - "authorities outside the direct selection. Hard construction and " - "selector/provider dependencies are always retained; explicitly " - "selected authorities still run first." - ), - ) - behavior.add_argument( - "--force-refresh", - action="store_true", - help=( - "Create a fresh generation+measurement attempt even when a " - "complete current exists (including one accepted through " - "--continue-across-revisions). Disposable workspaces are compacted " - "after preserving bounded diagnostics by default." - ), - ) - behavior.add_argument( - "--rerun-failed", - action="store_true", - help=( - "Create fresh attempts only for selected cells whose latest " - "terminal outcome is a non-cap failure. Valid, unseen, static-N/A, " - "and authenticated capped cells are excluded. Missing or historical " - "numerical authorities are added as dependency-only work unless " - "--no-dependencies-added is given. May be combined with " - "--rerun-capped, but not --force-refresh." - ), - ) - behavior.add_argument( - "--rerun-capped", - action="store_true", - help=( - "Create fresh attempts only for selected cells with an " - "authenticated generation, RAM, worker, profiling, or validation " - "cap. May be combined with --rerun-failed, but not " - "--force-refresh." - ), - ) - behavior.add_argument( - "--cleanup-artifacts", - action="store_true", - help=( - "Compatibility spelling for the default compact-retention policy: " - "preserve results, provenance, progress, and bounded diagnostics " - "while removing disposable build/reference workspaces." - ), - ) - behavior.add_argument( - "--retain-workspaces", - action="store_true", - help=( - "Opt in to retaining full legacy, MadGraph, build, failed, and " - "obsolete attempt workspaces for debugging. Output and free-disk " - "safety limits remain enforced." - ), - ) - behavior.add_argument( - "--fail-fast", - action="store_true", - help=( - "Stop new dispatch after the first terminal non-success, cancel " - "other live workers, complete multiplicities in n=1, n=2, ... " - "waves, retain bounded failed/cancelled diagnostics, exit " - "nonzero, and atomically write " - "campaign_summary_ids/fail_fast_failure.log with exact diagnostic " - "and reproduction paths. Cancelled outcomes caused by the stop are " - "not treated as a second failure. With --dry-run no report is " - "created." - ), - ) - behavior.add_argument( - "--continue-across-revisions", - action="store_true", - help=( - "Explicitly keep structurally valid completed selected cells from " - "older pyAmpliCol source revisions while filling missing cells " - "with this clean active build. Historical currents never satisfy " - "dependencies required by newly run cells: those dependencies are " - "planned again at the active revision. The policy is persisted so " - "later inspect and refresh-pdf commands automatically merge the " - "per-cell currents and report every exact source cohort/count." - ), - ) - behavior.add_argument( - "--dry-run", - action="store_true", - help=( - "Print direct cells, dependency closure, reuse counts, and " - "copy-paste public CLI recipes without launching workers." - ), - ) - behavior.add_argument( - "--no-dashboard", - action="store_true", - help="Run without the interactive Ratatui terminal dashboard.", - ) - - inspect = commands.add_parser( - "inspect", - parents=[selectors, output], - help="Inspect coverage and AmpliCol-relative summary statistics.", - description=( - "Summarize lightweight current metadata and compute candidate / " - "AmpliCol generation and outer-wall runtime multipliers. Dedicated " - "evaluator-total multipliers are emitted only when both sides " - "expose that clock; original AmpliCol normally does not. " - "Recurrence core is reported separately as an absolute statistic. " - "If the latest real run enabled cross-revision continuation, the " - "persisted mixed current set and its exact source cohorts are used." - ), - epilog=( - "Lower multipliers are better. The weighted average is exactly " - "sum(candidate) / sum(AmpliCol). Missing, capped, incompatible, " - "baseline-less, and unexposed clocks are excluded and counted. " - "Outer wall, evaluator-total, and recurrence core are never copied " - "or derived from one another.\n\n" + STEERING_GUIDE - ), - formatter_class=HelpFormatter, - ) - inspect.add_argument( - "--format", - choices=("human", "json"), - default="human", - help="Human coloured tables or stable uncoloured JSON.", - ) - - refresh = commands.add_parser( - "refresh-pdf", - parents=[output], - help="Rebuild every table and atomically replace the report PDF.", - description=( - "Capture one stable current snapshot, rebuild every " - "result JSON and TeX table, compile in a fresh directory, and " - "atomically install pyAmpliCol.pdf. Overfull-box diagnostics are " - "reported by LaTeX but are non-fatal here; compilation errors and " - "unresolved references remain fatal. Compilation output streams " - "live by default; --quiet suppresses it. The final absolute PDF " - "path is printed on success. A prior real run with " - "--continue-across-revisions automatically publishes the mixed " - "per-cell current set and reports every exact source cohort/count." - ), - epilog=STEERING_GUIDE, - formatter_class=HelpFormatter, - ) - refresh.add_argument( - "--expected-page-count", - type=int, - default=None, - help=( - "Optional stable page-count assertion. Omit it to accept legitimate " - "layout changes or a copied campaign profile with a different name." - ), - ) - refresh.add_argument( - "--pdf-timeout", - type=_positive_finite_float, - default=DEFAULT_PDF_TIMEOUT_SECONDS, - metavar="SECONDS", - help="Direct latexmk process timeout.", - ) - refresh.add_argument( - "--quiet", - action="store_true", - help=( - "Suppress the live artifact-scan progress display and latexmk " - "stdout/stderr. The final publication summary and absolute PDF " - "path are still printed." - ), - ) - sections = refresh.add_mutually_exclusive_group() - sections.add_argument( - "--list-sections", - action="store_true", - help=( - "List stable section IDs and exit without reading campaign " - "artifacts or rebuilding the PDF." - ), - ) - sections.add_argument( - "--remove-sections", - nargs="+", - metavar="SECTION_ID", - help=( - "Omit one or more listed top-level sections from this PDF build. " - "Measurements, caches, tables, and the source template are unchanged." - ), - ) - - snapshot = commands.add_parser( - "dashboard-snapshot", - parents=[output], - help="Capture a deterministic fixture or read-only live lease frame.", - description=( - "Render a Ratatui headless frame for visual review and automated " - "style/value assertions. The default is a deterministic synthetic " - "fixture. --live instead reads only compact non-stale JSON leases " - "from the manual profile's ignored coordination directory: it " - "does not inspect results, artifacts, source identity, or Git." - ), - epilog=( - "Selection rules:\n" - " Without --live, output is deterministic and independent of " - "campaign state.\n" - " With --live, the newest active lease is selected unless " - "--instance names\n" - " an exact ID or unique prefix. Active same-source peer workers " - "are shown\n" - " as peer rows; overview totals remain the selected invocation's " - "own atomic\n" - " counters so overlapping selections are never guessed or " - "double-counted.\n\n" - "Examples:\n" - " steer_performance_campaign.py dashboard-snapshot " - "--width 80 --height 24\n" - " steer_performance_campaign.py dashboard-snapshot " - "--width 160 --height 48 --cells-json\n" - " steer_performance_campaign.py dashboard-snapshot --live " - "--width 160 --height 48\n" - " steer_performance_campaign.py dashboard-snapshot --live " - "--instance 7f91c2 --stale-after 30" - ), - formatter_class=HelpFormatter, - ) - snapshot.add_argument("--width", type=int, default=120, help="Frame columns.") - snapshot.add_argument("--height", type=int, default=36, help="Frame rows.") - snapshot.add_argument( - "--cells-json", - action="store_true", - help=( - "Emit ANSI-free styled-cell JSON instead of the terminal frame. " - "Use --no-color or NO_COLOR to zero the Ratatui style metadata." - ), - ) - snapshot.add_argument( - "--live", - action="store_true", - help=( - "Capture actual running state from lightweight lease JSON only. " - "No measurement/current/artifact/source/Git data is read, and " - "nothing is written. Without this flag the synthetic fixture is " - "rendered." - ), - ) - snapshot.add_argument( - "--instance", - "--instance-id", - metavar="ID_OR_PREFIX", - help=( - "With --live, select one invocation by its exact instance ID or a " - "unique prefix. Omit to select the most recently updated active " - "lease." - ), - ) - snapshot.add_argument( - "--stale-after", - type=_positive_finite_float, - default=DEFAULT_WORKER_STALE_SECONDS, - metavar="SECONDS", - help=( - "With --live, ignore leases older than this positive interval. " - "Increase only when resource sampling is intentionally slower." - ), - ) - return parser - - -def main( - argv: Sequence[str] | None = None, - *, - repo_root: Path | None = None, - profile: str = PROFILE, - docs_dir: Path | None = None, - installed: bool = False, - launcher_path_checked: bool = False, -) -> int: - global _ACTIVE_PROFILE - - selected_profile = validate_profile_name(profile) - _ACTIVE_PROFILE = selected_profile - parser = build_parser() - invocation_arguments = tuple(sys.argv[1:] if argv is None else argv) - invocation_program = sys.argv[0] if argv is None else parser.prog - arguments = parser.parse_args(invocation_arguments) - arguments._campaign_invocation_command = _shell_join( - (invocation_program, *invocation_arguments) - ) - root = ( - Path.cwd().resolve(strict=False) - if repo_root is None - else repo_root.expanduser().resolve(strict=False) - ) - if installed and docs_dir is None: - raise ValueError("installed campaign mode requires its destination directory") - campaign_docs = ( - root / "docs/performance_reports" / selected_profile - if docs_dir is None - else docs_dir - ) - json_output = arguments.command == "inspect" and arguments.format == "json" - palette = Palette(_color_enabled(arguments, json_output=json_output)) - campaign_lock: int | None = None - try: - _require_launcher_working_directory_identity( - launcher_path_checked=launcher_path_checked, - ) - if arguments.command == "refresh-pdf" and arguments.list_sections: - _print_report_sections(palette) - return 0 - paths = _campaign_report_paths(root, campaign_docs) - campaign_lock = _acquire_campaign_directory_lock(paths.docs_dir) - dashboard_disabled = _configure_dashboard_capability( - arguments, - installed=installed, - ) - if ( - dashboard_disabled - and bool(getattr(sys.stdin, "isatty", lambda: False)()) - and bool(getattr(sys.stdout, "isatty", lambda: False)()) - ): - print( - palette.warning( - "Optional Ratatui bindings are unavailable; continuing with " - "--no-dashboard." - ), - file=sys.stderr, - ) - if arguments.command == "dashboard-snapshot": - if arguments.instance is not None and not arguments.live: - raise ManualCampaignError("--instance requires --live") - state = ( - _live_dashboard_snapshot( - paths.coordination_root, - instance=arguments.instance, - stale_after_seconds=arguments.stale_after, - ) - if arguments.live - else _snapshot_fixture() - ) - result = render_dashboard_frame( - state, - width=arguments.width, - height=arguments.height, - cells=arguments.cells_json, - color=palette.enabled, - ) - if arguments.cells_json: - json.dump(result, sys.stdout, indent=2, sort_keys=True) - sys.stdout.write("\n") - else: - print(result) - return 0 - - service = ReportService(paths, portable_current_results=True) - service.bind_measurement_lineage(None) - service.bind_original_amplicol_seed(None) - source = ( - installed_source_identity( - allow_candidate_checkout=( - arguments.command == "run" - and bool(getattr(arguments, "dry_run", False)) - ) - ) - if installed - else lightweight_source_identity(root) - ) - - if arguments.command == "refresh-pdf": - return _refresh_pdf( - arguments, - service=service, - source=source, - palette=palette, - ) - - _selection, cells = selection_from_arguments(arguments) - if arguments.command == "inspect": - source_policy = recorded_measurement_source_policy( - service, - checkout_revision=source.revision, - ) - payload = _inspect_payload( - service, - cells, - source_revision=source_policy.source_revision, - renderer_revision=source.revision, - accept_historical_source=(source_policy.continue_across_revisions), - ) - if arguments.format == "json": - json.dump(payload, sys.stdout, indent=2, sort_keys=True) - sys.stdout.write("\n") - else: - _print_inspect(payload, palette) - return 0 - if arguments.command == "run": - return _run_campaign( - arguments, - repo_root=root, - service=service, - source=source, - cells=cells, - palette=palette, - installed=installed, - ) - parser.error(f"unsupported command {arguments.command!r}") - except KeyboardInterrupt: - print( - palette.warning("Interrupted cleanly; completed currents were preserved."), - file=sys.stderr, - ) - return 130 - except (ManualCampaignError, OSError, RuntimeError, TypeError, ValueError) as error: - print(palette.failure(f"error: {error}"), file=sys.stderr) - return 2 - finally: - if campaign_lock is not None: - _release_campaign_directory_lock(campaign_lock) - return 2 - - -__all__ = [ - "Comparison", - "DashboardState", - "LightweightCurrent", - "ManualCampaignError", - "ReproductionRecipe", - "ReproductionSettings", - "WorkerView", - "build_parser", - "comparison_statistics", - "lightweight_current", - "main", - "render_dashboard_frame", - "reproduction_recipe", - "selection_from_arguments", -] diff --git a/pyamplicol/tools/performance_report/measurement.py b/pyamplicol/tools/performance_report/measurement.py deleted file mode 100644 index c917b39b9f..0000000000 --- a/pyamplicol/tools/performance_report/measurement.py +++ /dev/null @@ -1,1911 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""One-cell measurement orchestration over the public pyAmpliCol Python API.""" - -from __future__ import annotations - -import hashlib -import json -import math -import os -import time -import uuid -from collections.abc import Mapping, Sequence -from pathlib import Path -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from .service import ReportPaths - -from .agreements import ( - DIRECT_AGREEMENT_FIELD, - INDEPENDENT_AUTHORITY_ABI, - INDEPENDENT_AUTHORITY_FIELD, - LC_COMMON_COMPONENT_FIELD, - MADGRAPH_COMPARISON_FIELD, - MADGRAPH_FULL_COLOUR, - evaluate_lc_common_component, - incoming_agreement_edges, - independent_numerical_authorities, - madgraph_candidate_precision, - madgraph_comparison_record, - requires_independent_numerical_authority, - validate_lc_common_component, -) -from .cache import empty_measurement -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import ( - Accuracy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .phase_state import WorkerPhaseReporter -from .runner import ( - INDEPENDENT_RELATIVE_TOLERANCE, - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD, - RELATIVE_TOLERANCE, - GeneratedArtifact, - RunnerError, - RunnerSettings, - SelectorContract, - _real_nonnegative, - _selector_kwargs, - generate_artifact, - on_the_fly_recurrence_authority_validation, - point_digest, - pointwise_validation, - profile_runtime, - provenance_payload, - resolved_sum_validation, - runtime_identity_payload, - runtime_validation_points, - validate_artifact_contract, - validate_resolved_sum_validation_record, -) -from .source_identity import ( - ReportSourceIdentityError, - inspect_report_source, - require_eligible_report_source, -) - - -def shared_validation_points(process: str) -> object: - from pyamplicol.models.builtin.validation import generic_validation_point - - return ( - tuple( - tuple(float(component) for component in particle.momentum) - for particle in generic_validation_point(process) - ), - ) - - -def _reproduction_momenta(points: object) -> object: - """Return the exact measured points in portable public-CLI JSON form.""" - - to_list = getattr(points, "tolist", None) - payload = to_list() if callable(to_list) else points - try: - encoded = json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - ) - except (TypeError, ValueError) as error: - raise RunnerError( - "report profiling points cannot be materialized for reproduction" - ) from error - return json.loads(encoded) - - -def source_revision(repo_root: Path, *, require_clean: bool = False) -> str: - try: - identity = ( - require_eligible_report_source(repo_root) - if require_clean - else inspect_report_source(repo_root) - ) - except ReportSourceIdentityError as error: - if require_clean: - raise RunnerError( - "report source worktree contains changes outside generated " - f"report outputs: {error}" - ) from error - return "unknown" - return identity.revision - - -def file_digest(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _baseline_selector_contract( - baseline: Mapping[str, object] | None, -) -> SelectorContract | None: - if baseline is None: - return None - raw = baseline.get("selector_contract") - if raw is None: - return None - if not isinstance(raw, Mapping): - raise RunnerError("baseline selector_contract must be an object") - return SelectorContract.from_mapping(raw) - - -def _measurement_selector_contract( - cell: CellSpec, - baseline: Mapping[str, object] | None, - selector_provider: Mapping[str, object] | None, -) -> SelectorContract | None: - """Choose one canonical LC selector before candidate work starts.""" - - if cell.measurement.accuracy is not Accuracy.LC: - return None - baseline_contract = _baseline_selector_contract(baseline) - provider_contract: SelectorContract | None = None - if selector_provider is not None: - if selector_provider.get("status") != ResultStatus.OK.value: - raise RunnerError("LC selector provider is not a successful measurement") - try: - provider_contract = _baseline_selector_contract(selector_provider) - except (TypeError, ValueError) as error: - raise RunnerError("LC selector provider has an invalid contract") from error - if provider_contract is None: - raise RunnerError("LC selector provider has no selector_contract") - if ( - baseline_contract is not None - and provider_contract is not None - and baseline_contract != provider_contract - ): - raise RunnerError( - "LC validation baseline and selected-flow selector provider disagree" - ) - if baseline_contract is not None: - return baseline_contract - return provider_contract - - -def _baseline_matrix_element( - baseline: Mapping[str, object] | None, -) -> float | None: - if baseline is None: - return None - if baseline.get("status") != ResultStatus.OK.value: - raise RunnerError("candidate baseline is not a valid completed measurement") - value = baseline.get("matrix_element") - if isinstance(value, bool) or not isinstance(value, (int, float)): - raise RunnerError("candidate baseline has no matrix element") - return float(value) - - -_LEGACY_NUMERICAL_AUTHORITY_ABI = "pyamplicol-report-legacy-numerical-authority-v1" -_LEGACY_NUMERICAL_AUTHORITY_FIELD = "legacy_numerical_authority" -_LEGACY_ALL_FLOW_COMPONENT_AUTHORITY_SOURCE = "all-flow-selected-provider-replay" - - -def _independent_authority_record( - expected_cell_ids: Sequence[str], - *, - selected_cell_id: str | None, - status: str, - reason: str, -) -> dict[str, object]: - return { - "abi": INDEPENDENT_AUTHORITY_ABI, - "expected_cell_ids": list(expected_cell_ids), - "selected_cell_id": selected_cell_id, - "status": status, - "reason": reason, - "same_artifact_diagnostics_are_authority": False, - } - - -def baseline_uses_lc_common_component_authority( - cell: CellSpec, - baseline: Mapping[str, object] | None, -) -> bool: - """Whether an LC all-flow baseline authenticates only its shared component.""" - - if ( - baseline is None - or cell.measurement.accuracy is not Accuracy.LC - or cell.workload is not Workload.ALL_FLOW - ): - return False - validation = baseline.get("validation") - authority = ( - validation.get(_LEGACY_NUMERICAL_AUTHORITY_FIELD) - if isinstance(validation, Mapping) - else None - ) - if not ( - isinstance(authority, Mapping) - and authority.get("abi") == _LEGACY_NUMERICAL_AUTHORITY_ABI - and authority.get("source") == _LEGACY_ALL_FLOW_COMPONENT_AUTHORITY_SOURCE - ): - return False - if baseline.get("status") != ResultStatus.OK.value: - raise RunnerError("LC all-flow component authority is not successful") - try: - validate_lc_common_component( - validation.get(LC_COMMON_COMPONENT_FIELD), - selector_contract=baseline.get("selector_contract"), - ) - except ValueError as error: - raise RunnerError( - "LC all-flow component authority is not bound to its selector" - ) from error - return True - - -def _attach_baseline_validation( - cell: CellSpec, - validation: dict[str, object], - *, - candidate_matrix_element: float, - baseline: Mapping[str, object] | None, - points: object = None, - contract: SelectorContract | None = None, -) -> None: - if baseline_uses_lc_common_component_authority(cell, baseline): - # The worker's direct-agreement edge compares the authenticated shared - # component. Direct imode2's aggregate is diagnostic, not authority. - return - baseline_value = _baseline_matrix_element(baseline) - if baseline_value is not None: - resolved_sum = validation.get("resolved_sum") - if not isinstance(resolved_sum, Mapping): - raise RunnerError("candidate resolved-sum scale evidence is unavailable") - point_records = resolved_sum.get("points") - if not isinstance(point_records, list) or len(point_records) != 1: - raise RunnerError("candidate comparison requires one resolved point") - point_record = point_records[0] - if not isinstance(point_record, Mapping): - raise RunnerError("candidate resolved scale record is unavailable") - candidate_scale = point_record.get("candidate_scale") - candidate_source = resolved_sum.get("resolved_source_sha256") - if ( - isinstance(candidate_scale, bool) - or not isinstance(candidate_scale, (int, float)) - or not isinstance(candidate_source, str) - ): - raise RunnerError("candidate resolved scale evidence is invalid") - baseline_source = _comparison_source_digest( - { - "matrix_element": baseline_value, - "selector_contract": baseline.get("selector_contract"), - "validation": baseline.get("validation"), - "provenance": baseline.get("provenance"), - } - ) - validation["pointwise"] = pointwise_validation( - candidate_matrix_element, - baseline_value, - relative_tolerance=_pointwise_tolerance(cell), - candidate_scale=float(candidate_scale), - baseline_scale=abs(baseline_value), - candidate_scale_source="resolved-component-l1", - baseline_scale_source="authority-value-magnitude", - comparison_binding=_conditioned_binding( - cell, - points, - contract, - candidate_source_sha256=candidate_source, - baseline_source_sha256=baseline_source, - value_kind="matrix-element", - ), - ) - - -def _stored_validation_point_digest(measurement: Mapping[str, object]) -> str: - selector = measurement.get("selector_contract") - if isinstance(selector, Mapping): - raw = selector.get("point_digest") - if isinstance(raw, str): - return raw - validation = measurement.get("validation") - if isinstance(validation, Mapping): - raw = validation.get("point_digest") - if isinstance(raw, str): - return raw - resolved = validation.get("resolved_sum") - if isinstance(resolved, Mapping): - try: - validate_resolved_sum_validation_record(resolved) - except ValueError as error: - raise RunnerError( - "measurement resolved-sum point identity is invalid" - ) from error - raw = resolved.get("point_digest") - if isinstance(raw, str): - return raw - provenance = measurement.get("provenance") - if isinstance(provenance, Mapping) and "report_momenta" in provenance: - return point_digest(provenance["report_momenta"]) - raise RunnerError("measurement has no validation point identity") - - -def _stored_conditioned_scale( - measurement: Mapping[str, object], - value: float, -) -> tuple[float, str, str]: - validation = measurement.get("validation") - if isinstance(validation, Mapping): - resolved = validation.get("resolved_sum") - if isinstance(resolved, Mapping): - try: - validate_resolved_sum_validation_record(resolved) - except ValueError as error: - raise RunnerError( - "measurement resolved-sum scale evidence is invalid" - ) from error - records = resolved.get("points") - source = resolved.get("resolved_source_sha256") - if ( - isinstance(records, list) - and len(records) == 1 - and isinstance(records[0], Mapping) - and isinstance(source, str) - ): - raw_scale = records[0].get("candidate_scale") - raw_candidate = records[0].get("candidate") - if ( - not isinstance(raw_scale, bool) - and isinstance(raw_scale, (int, float)) - and math.isfinite(float(raw_scale)) - and float(raw_scale) >= abs(value) - and not isinstance(raw_candidate, bool) - and isinstance(raw_candidate, (int, float)) - and float(raw_candidate) == value - ): - return float(raw_scale), "resolved-component-l1", source - raise RunnerError( - "measurement matrix element differs from resolved-sum evidence" - ) - source = _comparison_source_digest( - { - "matrix_element": value, - "selector_contract": measurement.get("selector_contract"), - "validation": validation, - "provenance": measurement.get("provenance"), - } - ) - return abs(value), "authority-value-magnitude", source - - -def _stored_lc_common_component( - measurement: Mapping[str, object], - *, - selector_contract: Mapping[str, object], - expected_cell_id: str | None, -) -> tuple[float, Mapping[str, object], str]: - validation = measurement.get("validation") - observation = ( - validation.get(LC_COMMON_COMPONENT_FIELD) - if isinstance(validation, Mapping) - else None - ) - try: - validate_lc_common_component( - observation, - expected_cell_id=expected_cell_id, - selector_contract=selector_contract, - ) - except ValueError as error: - raise RunnerError( - "LC all-flow authority has no selector-bound common component" - ) from error - assert isinstance(observation, Mapping) - raw_value = observation.get("value") - if isinstance(raw_value, bool) or not isinstance(raw_value, (int, float)): - raise RunnerError("LC all-flow common component is not numeric") - value = float(raw_value) - if not math.isfinite(value): - raise RunnerError("LC all-flow common component is not finite") - return value, observation, _comparison_source_digest(observation) - - -def conditioned_measurement_comparison( - cell: CellSpec, - candidate: Mapping[str, object], - baseline: Mapping[str, object], -) -> dict[str, object]: - """Compare a completed candidate to late independent authority evidence.""" - - raw_contract = candidate.get("selector_contract") - baseline_contract = baseline.get("selector_contract") - if raw_contract != baseline_contract: - raise RunnerError("candidate and authority selector contracts differ") - contract = ( - None if raw_contract is None else SelectorContract.from_mapping(raw_contract) # type: ignore[arg-type] - ) - candidate_point = _stored_validation_point_digest(candidate) - baseline_point = _stored_validation_point_digest(baseline) - if candidate_point != baseline_point: - raise RunnerError("candidate and authority validation points differ") - - if baseline_uses_lc_common_component_authority(cell, baseline): - if not isinstance(raw_contract, Mapping) or contract is None: - raise RunnerError("LC all-flow authority has no selector contract") - candidate_value, candidate_component, candidate_source = ( - _stored_lc_common_component( - candidate, - selector_contract=raw_contract, - expected_cell_id=cell.cell_id, - ) - ) - baseline_value, baseline_component, baseline_source = ( - _stored_lc_common_component( - baseline, - selector_contract=raw_contract, - expected_cell_id=None, - ) - ) - component_identity = { - "candidate_cell_id": candidate_component["cell_id"], - "baseline_cell_id": baseline_component["cell_id"], - "point_digest": candidate_component["point_digest"], - "helicity_ids": candidate_component["helicity_ids"], - "color_flow_ids": candidate_component["color_flow_ids"], - } - if any( - candidate_component[field] != baseline_component[field] - for field in ("point_digest", "helicity_ids", "color_flow_ids") - ): - raise RunnerError("LC all-flow common-component identities differ") - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": contract.as_dict(), - "value_kind": LC_COMMON_COMPONENT_FIELD, - "component_identity": component_identity, - } - return pointwise_validation( - candidate_value, - baseline_value, - relative_tolerance=_pointwise_tolerance(cell), - candidate_scale=abs(candidate_value), - baseline_scale=abs(baseline_value), - candidate_scale_source="authority-component-magnitude", - baseline_scale_source="authority-component-magnitude", - comparison_binding={ - "point_digest": candidate_point, - "selector_component_identity": selector_identity, - "selector_component_sha256": _comparison_source_digest( - selector_identity - ), - "candidate_source_sha256": candidate_source, - "baseline_source_sha256": baseline_source, - }, - ) - - raw_candidate_value = candidate.get("matrix_element") - if isinstance(raw_candidate_value, bool) or not isinstance( - raw_candidate_value, (int, float) - ): - raise RunnerError("candidate has no matrix element") - candidate_value = float(raw_candidate_value) - if not math.isfinite(candidate_value): - raise RunnerError("candidate matrix element is not finite") - baseline_value = _baseline_matrix_element(baseline) - assert baseline_value is not None - candidate_scale, candidate_scale_source, candidate_source = ( - _stored_conditioned_scale(candidate, candidate_value) - ) - baseline_scale, baseline_scale_source, baseline_source = _stored_conditioned_scale( - baseline, baseline_value - ) - return pointwise_validation( - candidate_value, - baseline_value, - relative_tolerance=_pointwise_tolerance(cell), - candidate_scale=candidate_scale, - baseline_scale=baseline_scale, - candidate_scale_source=candidate_scale_source, - baseline_scale_source=baseline_scale_source, - comparison_binding={ - "point_digest": candidate_point, - "selector_component_identity": { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": None if contract is None else contract.as_dict(), - "value_kind": "matrix-element", - }, - "selector_component_sha256": _comparison_source_digest( - { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": ( - None if contract is None else contract.as_dict() - ), - "value_kind": "matrix-element", - } - ), - "candidate_source_sha256": candidate_source, - "baseline_source_sha256": baseline_source, - }, - ) - - -def reconcile_independent_authority( - cell: CellSpec, - measurement: Mapping[str, object], - authority: Mapping[str, object], - *, - authority_cell_id: str, -) -> dict[str, object]: - """Resolve one durable unverified result against late authority evidence.""" - - initial_status = measurement.get("status") - if initial_status not in { - ResultStatus.UNVERIFIED.value, - ResultStatus.OK.value, - }: - raise RunnerError( - "late authority reconciliation requires measured candidate input" - ) - validation = measurement.get("validation") - if not isinstance(validation, Mapping): - raise RunnerError("unverified result has no validation evidence") - record = validation.get(INDEPENDENT_AUTHORITY_FIELD) - if not isinstance(record, Mapping): - raise RunnerError("unverified result has no independent-authority record") - expected_ids = tuple(record.get("expected_cell_ids", ())) - canonical_ids = tuple( - candidate.cell_id for candidate in independent_numerical_authorities(cell) - ) - previous_selected = record.get("selected_cell_id") - record_status = record.get("status") - if ( - record.get("abi") != INDEPENDENT_AUTHORITY_ABI - or expected_ids != canonical_ids - or authority_cell_id not in canonical_ids - or authority.get("status") != ResultStatus.OK.value - ): - raise RunnerError("late independent-authority contract is invalid") - if initial_status == ResultStatus.UNVERIFIED.value: - if previous_selected is not None or record_status != "unavailable": - raise RunnerError("unverified independent-authority state is invalid") - elif ( - not isinstance(previous_selected, str) - or previous_selected not in canonical_ids - or record_status != "verified" - or canonical_ids.index(authority_cell_id) - >= canonical_ids.index(previous_selected) - ): - raise RunnerError("late authority does not supersede the selected authority") - - updated = dict(measurement) - mutable_validation = dict(validation) - try: - comparison = conditioned_measurement_comparison(cell, updated, authority) - except Exception as error: - mutable_validation[INDEPENDENT_AUTHORITY_FIELD] = _independent_authority_record( - canonical_ids, - selected_cell_id=authority_cell_id, - status="incompatible", - reason="successful-independent-authority-contract-incompatible", - ) - mutable_validation["status"] = ResultStatus.VALIDATION_FAILED.value - updated["status"] = ResultStatus.VALIDATION_FAILED.value - updated["validation"] = mutable_validation - updated["failure"] = { - "kind": "IndependentAuthorityContractError", - "message": str(error), - } - return updated - - mutable_validation["pointwise"] = comparison - passed = comparison.get("status") == ResultStatus.OK.value - mutable_validation[INDEPENDENT_AUTHORITY_FIELD] = _independent_authority_record( - canonical_ids, - selected_cell_id=authority_cell_id, - status="verified" if passed else "mismatch", - reason=( - "independent-authority-agreement" - if passed - else "independent-authority-mismatch" - ), - ) - resolved_status = ( - ResultStatus.OK.value if passed else ResultStatus.VALIDATION_FAILED.value - ) - mutable_validation["status"] = resolved_status - updated["status"] = resolved_status - updated["validation"] = mutable_validation - updated["failure"] = ( - None - if passed - else { - "kind": "IndependentAuthorityMismatch", - "message": "candidate disagrees with independent numerical authority", - } - ) - return updated - - -_PRECISION_DIAGNOSTIC_ABI = ( - "pyamplicol-report-validation-failure-precision-diagnostic-v2" -) -_PRECISION_DIAGNOSTIC_CELL_IDS = frozenset( - { - "matrix-compiled-builtin-sm-full-n4-dd-tt-jets-contracted", - "matrix-compiled-builtin-sm-nlc-n4-dd-tt-jets-contracted", - "matrix-recurrence-builtin-sm-lc-n4-dd-tt-jets-all-flow", - } -) - - -def _precision_diagnostic_enabled(cell: CellSpec) -> bool: - return cell.cell_id in _PRECISION_DIAGNOSTIC_CELL_IDS - - -def _diagnostic_number(value: object) -> dict[str, object]: - real = getattr(value, "real", value) - if callable(real): - real = real() - return {"value": str(real), "binary64": _real_nonnegative(value)} - - -def _unavailable_precision_diagnostic(error: BaseException) -> dict[str, object]: - return { - "abi": _PRECISION_DIAGNOSTIC_ABI, - "status": "unavailable", - "promotes_measurement": False, - "error": {"kind": type(error).__name__, "message": str(error)}, - } - - -def _diagnostic_timing_context( - cell: CellSpec, - measurement: Mapping[str, object] | None, -) -> dict[str, object]: - """Copy independent measured clocks without recomputing or deriving them.""" - - measurement = measurement or {} - provenance = measurement.get("provenance") - provenance = provenance if isinstance(provenance, Mapping) else {} - evaluator_total = provenance.get("evaluator_total_timing") - execution = provenance.get("execution_timing") - return { - "source": "copied-from-measurement", - "recomputed": False, - "outer_wall_seconds_per_point": measurement.get("wall_seconds_per_point"), - "evaluator_total_timing": ( - dict(evaluator_total) if isinstance(evaluator_total, Mapping) else None - ), - "recurrence_core_timing": ( - dict(execution) - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and isinstance(execution, Mapping) - else None - ), - } - - -def _diagnostic_authorities( - cell: CellSpec, - measurements: Mapping[str, Mapping[str, object]], -) -> list[dict[str, object]]: - """Extract the few already-stored values relevant to the retained canaries.""" - - result: list[dict[str, object]] = [] - for label, measurement in measurements.items(): - validation = measurement.get("validation") - validation = validation if isinstance(validation, Mapping) else {} - component_only = baseline_uses_lc_common_component_authority(cell, measurement) - legacy = validation.get(_LEGACY_NUMERICAL_AUTHORITY_FIELD) - source = ( - str(legacy.get("source")) - if isinstance(legacy, Mapping) - else "stored-successful-measurement" - ) - - common = validation.get(LC_COMMON_COMPONENT_FIELD) - imode2 = validation.get("legacy_imode2_diagnostic") - kind = LC_COMMON_COMPONENT_FIELD if component_only else "total" - candidates = ( - ("matrix-element", "total", measurement.get("matrix_element"), source), - ( - LC_COMMON_COMPONENT_FIELD, - LC_COMMON_COMPONENT_FIELD, - common.get("value") if isinstance(common, Mapping) else None, - source, - ), - ( - "generated-library", - kind, - imode2.get("authoritative_value") - if isinstance(imode2, Mapping) - else None, - str(imode2.get("authoritative_source", source)) - if isinstance(imode2, Mapping) - else source, - ), - ( - "direct-imode2", - kind, - imode2.get("imode2_value") if isinstance(imode2, Mapping) else None, - "legacy-direct-imode2-non-certifying", - ), - ) - for name, value_kind, value, value_source in candidates: - if ( - (name == "matrix-element" and component_only) - or isinstance(value, bool) - or not isinstance(value, (int, float)) - ): - continue - result.append( - { - "authority": f"{label}:{name}", - "value_kind": value_kind, - "value": float(value), - "source": value_source, - } - ) - return result - - -def _diagnostic_evaluation( - runtime: object, - points: object, - *, - cell: CellSpec, - contract: SelectorContract | None, - precision: int, - point_context: str, -) -> dict[str, object]: - selectors = _selector_kwargs(cell, contract) - values = runtime.evaluate( # type: ignore[attr-defined] - points, precision=precision, **selectors - ) - resolved = runtime.evaluate_resolved( # type: ignore[attr-defined] - points, precision=precision, **selectors - ) - totals = tuple(resolved.total()) - if len(values) != 1 or len(totals) != 1: - raise RunnerError("precision diagnostic requires exactly one point") - result = { - "point_context": point_context, - "total": _diagnostic_number(values[0]), - "resolved_sum": _diagnostic_number(totals[0]), - "internal_agreement": pointwise_validation( - _real_nonnegative(values[0]), - _real_nonnegative(totals[0]), - ), - } - if ( - contract is not None - and cell.measurement.accuracy is Accuracy.LC - and cell.workload is Workload.ALL_FLOW - ): - component = runtime.evaluate_resolved( # type: ignore[attr-defined] - points, - precision=precision, - helicities=contract.runtime_all_flow_helicity_ids, - color_flows=contract.selected_color_flow_ids, - ) - if ( - tuple(component.helicity_ids) != contract.runtime_all_flow_helicity_ids - or tuple(component.color_ids) != contract.selected_color_flow_ids - ): - raise RunnerError("diagnostic LC common-component axes changed") - try: - result[LC_COMMON_COMPONENT_FIELD] = _diagnostic_number( - component.values[0][0][0] - ) - except (AttributeError, IndexError, TypeError) as error: - raise RunnerError("diagnostic LC common component is not scalar") from error - return result - - -def _validation_failure_precision_diagnostic( - runtime: object, - points: object, - *, - cell: CellSpec, - contract: SelectorContract | None, - baseline: Mapping[str, object] | None, - peers: Mapping[str, Mapping[str, object]] | None = None, - measurement_context: Mapping[str, object] | None = None, - complete_ladder: bool = False, -) -> dict[str, object]: - """Attach a bounded, non-promoting p32/p200 explanation to three canaries.""" - - try: - measurements = dict(peers or {}) - if baseline is not None: - measurements = {"baseline": baseline, **measurements} - authorities = _diagnostic_authorities(cell, measurements) - retained_digest = point_digest(points) - projector = getattr(runtime, "_diagnostic_project_onshell", None) - if not callable(projector): - raise RunnerError("runtime does not expose diagnostic on-shell projection") - diagnostic_points, raw_projection = projector(points, precision=200) - if not isinstance(raw_projection, Mapping): - raise RunnerError("runtime returned invalid diagnostic projection metadata") - projection = dict(raw_projection) - unchanged = projection.get("unchanged") - if not isinstance(unchanged, bool): - raise RunnerError( - "diagnostic projection does not report whether it changed" - ) - projected_digest = projection.get("projected_digest") - if not isinstance(projected_digest, str) or not projected_digest: - raise RunnerError("diagnostic projection has no projected point digest") - projection["original_digest"] = retained_digest - if unchanged: - candidate_point_context = "retained-point-unchanged-by-projection" - authority_point_context = candidate_point_context - else: - candidate_point_context = "projected-onshell-point" - authority_point_context = "original-retained-point" - result: dict[str, object] = { - "abi": _PRECISION_DIAGNOSTIC_ABI, - "status": "diagnostic-only", - "promotes_measurement": False, - "timings_unchanged": True, - "retained_point": { - "digest": retained_digest, - "momenta": _reproduction_momenta(points), - }, - "kinematic_projection": projection, - "stored_peer_point_context": authority_point_context, - "selector_contract": None if contract is None else contract.as_dict(), - "execution_identity": { - "cell_id": cell.cell_id, - "process": cell.process, - "multiplicity": cell.n_final, - "workload": cell.workload.value, - "layout": cell.workload.value, - "execution_mode": cell.measurement.execution_mode.value, - "backend": cell.measurement.backend, - "model": ( - None - if cell.measurement.model is None - else cell.measurement.model.value - ), - "accuracy": cell.measurement.accuracy.value, - "variant": cell.variant, - }, - "measurement_timing_context": _diagnostic_timing_context( - cell, measurement_context - ), - "attempts": [], - } - attempts = result["attempts"] - assert isinstance(attempts, list) - for precision in (32, 200): - attempt: dict[str, object] = {"precision_digits": precision} - try: - candidate = _diagnostic_evaluation( - runtime, - diagnostic_points, - cell=cell, - contract=contract, - precision=precision, - point_context=candidate_point_context, - ) - comparisons = [] - for authority in authorities: - value_kind = str(authority["value_kind"]) - candidate_fields = ( - ("total", "resolved_sum") - if value_kind == "total" - else (value_kind,) - ) - for candidate_field in candidate_fields: - candidate_value = candidate.get(candidate_field) - if not isinstance(candidate_value, Mapping): - continue - comparison = pointwise_validation( - float(candidate_value["binary64"]), - float(authority["value"]), - relative_tolerance=_pointwise_tolerance(cell), - ) - comparison_payload = { - "candidate_value_kind": candidate_field, - "authority": authority["authority"], - "source": authority["source"], - "candidate_point_context": candidate_point_context, - "authority_point_context": authority_point_context, - "same_kinematic_point": unchanged, - "certifying": unchanged, - **comparison, - } - if not unchanged: - comparison_payload.pop("status", None) - comparison_payload["context_only"] = True - comparisons.append(comparison_payload) - attempt.update( - { - "status": "evaluated", - "candidate": candidate, - "comparisons": comparisons, - } - ) - except Exception as error: - attempt.update( - { - "status": "unavailable", - "error": { - "kind": type(error).__name__, - "message": str(error), - }, - } - ) - attempts.append(attempt) - continue - attempts.append(attempt) - internal = candidate["internal_agreement"] - if ( - not complete_ladder - and precision == 32 - and isinstance(internal, Mapping) - and internal.get("status") == ResultStatus.OK.value - and comparisons - and all( - comparison.get("status") == ResultStatus.OK.value - for comparison in comparisons - ) - ): - break - return result - except Exception as error: - return _unavailable_precision_diagnostic(error) - - -def attach_validation_failure_precision_diagnostic( - cell: CellSpec, - measurement: dict[str, object], - *, - baseline: Mapping[str, object] | None, - peers: Mapping[str, Mapping[str, object]] | None = None, -) -> None: - """Add the same bounded diagnostic after late direct-agreement failures.""" - - validation = measurement.get("validation") - if ( - measurement.get("status") != ResultStatus.VALIDATION_FAILED.value - or not _precision_diagnostic_enabled(cell) - or not isinstance(validation, Mapping) - or "precision_diagnostic" in validation - ): - return - mutable_validation = dict(validation) - try: - artifact = measurement.get("artifact") - if not isinstance(artifact, Mapping): - raise RunnerError("failed measurement has no generated artifact") - path = artifact.get("path") - process_id = artifact.get("process_id") - if not isinstance(path, str) or not isinstance(process_id, str): - raise RunnerError("failed measurement artifact is not loadable") - runtime = _load_runtime( - Path(path).expanduser().resolve(strict=False), process_id - ) - points = shared_validation_points(cell.process) - raw_contract = measurement.get("selector_contract") - contract = ( - None - if raw_contract is None - else SelectorContract.from_mapping(raw_contract) - ) - diagnostic = _validation_failure_precision_diagnostic( - runtime, - points, - cell=cell, - contract=contract, - baseline=baseline, - peers=peers, - measurement_context=measurement, - ) - except Exception as error: - diagnostic = _unavailable_precision_diagnostic(error) - mutable_validation["precision_diagnostic"] = diagnostic - measurement["validation"] = mutable_validation - - -def _require_nonzero_lc_all_flow_baseline( - cell: CellSpec, - baseline: Mapping[str, object] | None, -) -> None: - """Reject inherited selector contracts that authenticate only a zero lane.""" - - if ( - baseline is None - or cell.measurement.accuracy is not Accuracy.LC - or cell.workload is not Workload.ALL_FLOW - ): - return - validation = baseline.get("validation") - common = ( - validation.get(LC_COMMON_COMPONENT_FIELD) - if isinstance(validation, Mapping) - else None - ) - value = common.get("value") if isinstance(common, Mapping) else None - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or float(value) <= 0.0 - ): - raise RunnerError( - "LC all-flow baseline selector is structural zero; remeasure the " - "baseline with a nonzero fixed-helicity selector before generating " - "a dependent candidate" - ) - - -def generated_artifact_from_measurement( - measurement: Mapping[str, object], -) -> GeneratedArtifact: - if measurement.get("status") != ResultStatus.OK.value: - raise RunnerError("only a successful measurement can provide an artifact") - artifact = measurement.get("artifact") - provenance = measurement.get("provenance") - generation_seconds = measurement.get("generation_seconds") - if ( - not isinstance(artifact, Mapping) - or not isinstance(provenance, Mapping) - or isinstance(generation_seconds, bool) - or not isinstance(generation_seconds, (int, float)) - ): - raise RunnerError("measurement does not contain reusable artifact metadata") - path = artifact.get("path") - process_id = artifact.get("process_id") - requested = provenance.get("requested_config") - effective = provenance.get("effective_config") - preparation_seconds = provenance.get("model_preparation_seconds", 0.0) - preparation_reused = provenance.get("model_preparation_reused", True) - generation_command_path = provenance.get("generation_command_path") - numerical_relation_correctness = provenance.get("numerical_relation_correctness") - numerical_relation_fallback = provenance.get("numerical_relation_fallback") - if ( - not isinstance(path, str) - or not isinstance(process_id, str) - or not isinstance(requested, Mapping) - or not isinstance(effective, Mapping) - or isinstance(preparation_seconds, bool) - or not isinstance(preparation_seconds, (int, float)) - or not isinstance(preparation_reused, bool) - or ( - generation_command_path is not None - and not isinstance(generation_command_path, str) - ) - or ( - numerical_relation_correctness is not None - and not isinstance(numerical_relation_correctness, Mapping) - ) - or ( - numerical_relation_fallback is not None - and not isinstance(numerical_relation_fallback, Mapping) - ) - ): - raise RunnerError("measurement reusable artifact metadata is malformed") - artifact_path = Path(path).expanduser().resolve(strict=False) - if not artifact_path.is_dir(): - raise RunnerError(f"reusable artifact directory is missing: {artifact_path}") - return GeneratedArtifact( - path=artifact_path, - process_id=process_id, - generation_seconds=float(generation_seconds), - model_preparation_seconds=float(preparation_seconds), - model_preparation_reused=preparation_reused, - requested_config=dict(requested), - effective_config=dict(effective), - generation_command_path=generation_command_path, - numerical_relation_correctness=( - None - if numerical_relation_correctness is None - else dict(numerical_relation_correctness) - ), - numerical_relation_fallback=( - None - if numerical_relation_fallback is None - else dict(numerical_relation_fallback) - ), - ) - - -def _reuse_artifact_for_measurement( - artifact: GeneratedArtifact, - *, - phase_reporter: WorkerPhaseReporter | None, -) -> GeneratedArtifact: - """Close the local generation phase when no generation work is needed.""" - - if phase_reporter is not None: - # The inherited generation_seconds remains the cost of producing the - # reusable artifact. This empty local interval only gives the current - # supervised worker an authenticated terminal phase state. - with phase_reporter.generation(): - pass - return artifact - - -def _pointwise_tolerance(cell: CellSpec) -> float: - if cell.dataset_id.startswith("matrix_recurrence_") or cell.dataset_id.startswith( - "z_" - ): - return INDEPENDENT_RELATIVE_TOLERANCE - return RELATIVE_TOLERANCE - - -def _stable_runtime_identity( - identity: Mapping[str, object], -) -> dict[str, object]: - """Remove only the growing loaded-module observation inventory.""" - - stable = dict(identity) - raw_policy = stable.get("loaded_module_origin_policy") - if isinstance(raw_policy, Mapping): - policy = dict(raw_policy) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - policy.pop(field, None) - stable["loaded_module_origin_policy"] = policy - return stable - - -def _runtime_identity_digest(identity: Mapping[str, object]) -> str: - return hashlib.sha256( - json.dumps( - identity, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _comparison_source_digest(value: object) -> str: - return hashlib.sha256( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _conditioned_binding( - cell: CellSpec, - points: object, - contract: SelectorContract | None, - *, - candidate_source_sha256: str, - baseline_source_sha256: str, - value_kind: str, -) -> dict[str, object]: - selector_identity = { - "cell_id": cell.cell_id, - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": None if contract is None else contract.as_dict(), - "value_kind": value_kind, - } - return { - "point_digest": point_digest(points), - "selector_component_identity": selector_identity, - "selector_component_sha256": _comparison_source_digest(selector_identity), - "candidate_source_sha256": candidate_source_sha256, - "baseline_source_sha256": baseline_source_sha256, - } - - -def _validate_runtime_identity_postflight( - initial: Mapping[str, object], - postflight: Mapping[str, object], -) -> None: - if _stable_runtime_identity(initial) != _stable_runtime_identity(postflight): - raise RunnerError( - "candidate runtime identity changed during report measurement" - ) - initial_policy = initial.get("loaded_module_origin_policy") - postflight_policy = postflight.get("loaded_module_origin_policy") - if not isinstance(initial_policy, Mapping) or not isinstance( - postflight_policy, - Mapping, - ): - raise RunnerError("report runtime has no loaded-module origin evidence") - initial_observations = initial_policy.get("observations") - postflight_observations = postflight_policy.get("observations") - if not isinstance(initial_observations, list) or not isinstance( - postflight_observations, - list, - ): - raise RunnerError("report runtime loaded-module evidence is incomplete") - postflight_keys = { - json.dumps( - observation, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - for observation in postflight_observations - } - if any( - json.dumps( - observation, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - not in postflight_keys - for observation in initial_observations - ): - raise RunnerError("report runtime lost an authenticated loaded-module origin") - - -def _load_runtime(artifact_path: Path, process_id: str) -> object: - from pyamplicol.api import Runtime - - return Runtime.load(artifact_path, process=process_id) - - -def _requires_high_precision_validation( - cell: CellSpec, - *, - baseline: Mapping[str, object] | None, - selected_authority_cell_id: str | None, - catalog: ReportCatalog, -) -> tuple[bool, bool]: - """Return the p32 requirement and whether ``baseline`` is legacy-only. - - A successful original-AmpliCol diagnostic must not suppress pyAmpliCol's - own p16-versus-p32 certification now that the legacy evaluator is no - longer a numerical authority. - """ - - baseline_cell = catalog.validation_baseline_cell(cell) - baseline_is_legacy_amplicol = ( - baseline is not None - and selected_authority_cell_id is None - and baseline_cell is not None - and baseline_cell.measurement.execution_mode is ExecutionMode.AMPLICOL - ) - scalar = cell.measurement.model in { - ModelKey.SCALAR_CONTACT, - ModelKey.SCALAR_GRAVITY, - } - required = scalar or ( - (baseline is None or baseline_is_legacy_amplicol) - and cell.measurement.execution_mode - in { - ExecutionMode.RECURRENCE, - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - } - ) - return required, baseline_is_legacy_amplicol - - -def _load_on_the_fly_recurrence_authority( - cell: CellSpec, - *, - baseline: Mapping[str, object] | None, - catalog: ReportCatalog, -) -> tuple[CellSpec, object]: - """Load the already measured recurrence authority without generating work.""" - - if ( - cell.measurement.execution_mode is not ExecutionMode.ON_THE_FLY - or cell.measurement.accuracy is not Accuracy.LC - ): - raise RunnerError("recurrence authority requires an on-the-fly LC cell") - recurrence_cell = catalog.validation_baseline_cell(cell) - if ( - recurrence_cell is None - or recurrence_cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or baseline is None - ): - raise RunnerError("on-the-fly measurement requires its recurrence baseline") - artifact = generated_artifact_from_measurement(baseline) - validate_artifact_contract(recurrence_cell, artifact.path) - return ( - recurrence_cell, - _load_runtime(artifact.path, artifact.process_id), - ) - - -def _resolution_benchmark_config(effective_config: Mapping[str, object]) -> object: - from pyamplicol.config import Action - from pyamplicol.config.resolver import resolve_config - - return resolve_config( - effective_config, - action=Action.GENERATE, - base_dir=Path.cwd(), - ).effective.benchmark - - -def measure_pyamplicol_cell( - cell: CellSpec, - *, - artifact_path: Path, - settings: RunnerSettings, - repo_root: Path, - baseline: Mapping[str, object] | None, - expected_authority_cell_ids: Sequence[str] = (), - selected_authority_cell_id: str | None = None, - validation_peers: Mapping[str, Mapping[str, object]] | None = None, - selector_provider: Mapping[str, object] | None = None, - prepared_model_path: Path | None = None, - reused_artifact: GeneratedArtifact | None = None, - phase_reporter: WorkerPhaseReporter | None = None, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, object]: - """Generate or retime one complete-coverage pyAmpliCol artifact.""" - - canonical_authority_ids = tuple( - authority.cell_id - for authority in independent_numerical_authorities(cell, catalog=catalog) - ) - authority_ids = tuple(expected_authority_cell_ids) - if authority_ids != canonical_authority_ids: - raise RunnerError( - "expected numerical authorities differ from the canonical catalog chain" - ) - if selected_authority_cell_id is not None and ( - selected_authority_cell_id not in authority_ids or baseline is None - ): - raise RunnerError("selected numerical authority is invalid") - if authority_ids and (baseline is not None) != ( - selected_authority_cell_id is not None - ): - raise RunnerError( - "compiled/eager baseline and selected numerical authority differ" - ) - - _require_nonzero_lc_all_flow_baseline(cell, baseline) - contract = _measurement_selector_contract(cell, baseline, selector_provider) - if ( - cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - and contract is None - ): - raise RunnerError( - "on-the-fly measurement requires an inherited recurrence selector contract" - ) - generated = ( - generate_artifact( - cell, - artifact_path, - settings=settings, - repo_root=repo_root, - prepared_model_path=prepared_model_path, - phase_reporter=phase_reporter, - ) - if reused_artifact is None - else _reuse_artifact_for_measurement( - reused_artifact, - phase_reporter=phase_reporter, - ) - ) - validate_artifact_contract(cell, generated.path) - runtime_load_started = time.perf_counter() - runtime = _load_runtime(generated.path, generated.process_id) - runtime_load_seconds = time.perf_counter() - runtime_load_started - revision = settings.source_revision_override or source_revision( - repo_root, - require_clean=True, - ) - runtime_identity = runtime_identity_payload( - cell, - runtime, - generated.path, - generated.process_id, - expected_source_revision=revision, - ) - runtime_identity_sha256 = _runtime_identity_digest(runtime_identity) - points = ( - runtime_validation_points(runtime) - if cell.measurement.model in {ModelKey.SCALAR_CONTACT, ModelKey.SCALAR_GRAVITY} - else shared_validation_points(cell.process) - ) - if cell.measurement.accuracy is Accuracy.LC and contract is None: - from .runner import derive_selector_contract - - contract = derive_selector_contract(runtime, points) - otf_recurrence_authority: dict[str, object] | None = None - if ( - cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - ): - assert contract is not None - recurrence_authority = _load_on_the_fly_recurrence_authority( - cell, - baseline=baseline, - catalog=catalog, - ) - try: - otf_recurrence_authority = on_the_fly_recurrence_authority_validation( - runtime, - points, - cell=cell, - selector_contract=contract, - authority=recurrence_authority, - ) - finally: - # Keep public candidate timing free of the loaded recurrence peer. - del recurrence_authority - if phase_reporter is not None: - phase_reporter.profiling_started() - profiling_deadlines = tuple( - deadline - for deadline in ( - settings.worker_deadline_monotonic, - ( - None - if settings.profiling_time_limit_seconds is None - else time.monotonic() + settings.profiling_time_limit_seconds - ), - ) - if deadline is not None - ) - profile = profile_runtime( - runtime, - points, - cell=cell, - benchmark_config=_resolution_benchmark_config(generated.effective_config), - selector_contract=contract, - progress=settings.progress, - profiling_deadline_monotonic=( - min(profiling_deadlines) if profiling_deadlines else None - ), - ) - execution_timing = profile.pop("execution_timing") - evaluator_total_timing = profile.pop("evaluator_total_timing", None) - arena_profile_evidence = profile.pop("arena_profile_evidence") - benchmark_evidence = profile.pop("benchmark_evidence") - if phase_reporter is not None: - phase_reporter.validation_started() - resolved_sum = profile.pop("resolved_sum_validation") - validation: dict[str, object] = { - "resolved_sum": resolved_sum, - DIRECT_AGREEMENT_FIELD: [], - **( - {OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD: otf_recurrence_authority} - if otf_recurrence_authority is not None - else {} - ), - } - if cell.measurement.accuracy is Accuracy.LC: - assert contract is not None - validation[LC_COMMON_COMPONENT_FIELD] = evaluate_lc_common_component( - runtime, - points, - cell=cell, - contract=contract, - ) - authority_expected = requires_independent_numerical_authority( - cell, - catalog=catalog, - ) - diagnostic_without_authority = ( - authority_expected and selected_authority_cell_id is None - ) - requires_high_precision, baseline_is_legacy_amplicol = ( - _requires_high_precision_validation( - cell, - baseline=baseline, - selected_authority_cell_id=selected_authority_cell_id, - catalog=catalog, - ) - ) - if requires_high_precision: - high_precision_resolved = resolved_sum_validation( - runtime, - points, - cell=cell, - selector_contract=contract, - precision=32, - ) - high_precision_records = high_precision_resolved.get("points") - candidate_records = resolved_sum.get("points") - if ( - not isinstance(high_precision_records, list) - or len(high_precision_records) != 1 - or not isinstance(candidate_records, list) - or len(candidate_records) != 1 - or not isinstance(high_precision_records[0], Mapping) - or not isinstance(candidate_records[0], Mapping) - ): - raise RunnerError("high-precision validation requires one resolved point") - high_record = high_precision_records[0] - candidate_record = candidate_records[0] - high_precision_value = float(high_record["candidate"]) - candidate_source = resolved_sum.get("resolved_source_sha256") - baseline_source = high_precision_resolved.get("resolved_source_sha256") - if not isinstance(candidate_source, str) or not isinstance( - baseline_source, str - ): - raise RunnerError("high-precision resolved source binding is unavailable") - validation["high_precision_resolved_sum"] = high_precision_resolved - validation["high_precision"] = pointwise_validation( - float(profile["matrix_element"]), - high_precision_value, - candidate_scale=float(candidate_record["candidate_scale"]), - baseline_scale=float(high_record["candidate_scale"]), - candidate_scale_source="resolved-component-l1-binary64", - baseline_scale_source="resolved-component-l1-p32", - comparison_binding=_conditioned_binding( - cell, - points, - contract, - candidate_source_sha256=candidate_source, - baseline_source_sha256=baseline_source, - value_kind="matrix-element-p16-versus-p32", - ), - ) - madgraph_edges = tuple( - edge - for edge in incoming_agreement_edges(cell, catalog=catalog) - if edge.kind == MADGRAPH_FULL_COLOUR - ) - if madgraph_edges: - if len(madgraph_edges) != 1: - raise RunnerError("candidate has ambiguous MadGraph authority edges") - edge = madgraph_edges[0] - peers = {} if validation_peers is None else validation_peers - madgraph_peer = peers.get(edge.baseline.cell_id) - if madgraph_peer is None: - raise RunnerError("required MadGraph authority measurement is unavailable") - comparison_precision = madgraph_candidate_precision(cell) - values = runtime.evaluate( # type: ignore[attr-defined] - points, - precision=comparison_precision, - **_selector_kwargs(cell, contract), - ) - if len(values) != 1: - raise RunnerError( - "MadGraph comparison requires exactly one " - f"p{comparison_precision} value" - ) - validation[MADGRAPH_COMPARISON_FIELD] = madgraph_comparison_record( - edge, - candidate=_real_nonnegative(values[0]), - baseline_measurement=madgraph_peer, - point_identity=point_digest(points), - ) - _attach_baseline_validation( - cell, - validation, - candidate_matrix_element=float(profile["matrix_element"]), - baseline=baseline, - points=points, - contract=contract, - ) - authority_failure: dict[str, str] | None = None - if authority_expected: - if selected_authority_cell_id is None: - validation[INDEPENDENT_AUTHORITY_FIELD] = _independent_authority_record( - authority_ids, - selected_cell_id=None, - status="unavailable", - reason="no-successful-independent-authority", - ) - else: - assert baseline is not None - candidate_view = { - "matrix_element": float(profile["matrix_element"]), - "selector_contract": None if contract is None else contract.as_dict(), - "validation": validation, - } - try: - comparison = conditioned_measurement_comparison( - cell, - candidate_view, - baseline, - ) - except Exception as error: - validation[INDEPENDENT_AUTHORITY_FIELD] = _independent_authority_record( - authority_ids, - selected_cell_id=selected_authority_cell_id, - status="incompatible", - reason=("successful-independent-authority-contract-incompatible"), - ) - validation["authority_contract_error"] = { - "kind": type(error).__name__, - "message": str(error), - } - authority_failure = { - "kind": "IndependentAuthorityContractError", - "message": str(error), - } - else: - validation["pointwise"] = comparison - passed = comparison.get("status") == ResultStatus.OK.value - validation[INDEPENDENT_AUTHORITY_FIELD] = _independent_authority_record( - authority_ids, - selected_cell_id=selected_authority_cell_id, - status="verified" if passed else "mismatch", - reason=( - "independent-authority-agreement" - if passed - else "independent-authority-mismatch" - ), - ) - if not passed: - authority_failure = { - "kind": "IndependentAuthorityMismatch", - "message": ( - "candidate disagrees with independent numerical authority" - ), - } - legacy_baseline = ( - baseline_is_legacy_amplicol - and baseline is not None - and baseline.get("status") == ResultStatus.OK.value - ) - statuses = { - str(record.get("status")) - for field, record in validation.items() - if isinstance(record, Mapping) - and not (legacy_baseline and field == "pointwise") - } - internal_failure = ResultStatus.VALIDATION_FAILED.value in statuses - validation["status"] = ( - ResultStatus.VALIDATION_FAILED.value - if internal_failure or authority_failure is not None - else ( - ResultStatus.UNVERIFIED.value - if diagnostic_without_authority - else ResultStatus.OK.value - ) - ) - if ( - validation["status"] == ResultStatus.VALIDATION_FAILED.value - and _precision_diagnostic_enabled(cell) - ) or validation["status"] == ResultStatus.UNVERIFIED.value: - validation["precision_diagnostic"] = _validation_failure_precision_diagnostic( - runtime, - points, - cell=cell, - contract=contract, - baseline=baseline, - peers=validation_peers, - measurement_context={ - "wall_seconds_per_point": profile.get("wall_seconds_per_point"), - "provenance": { - "execution_timing": execution_timing, - "evaluator_total_timing": evaluator_total_timing, - }, - }, - complete_ladder=(validation["status"] == ResultStatus.UNVERIFIED.value), - ) - status = str(profile["status"]) - if validation["status"] == ResultStatus.VALIDATION_FAILED.value: - status = ResultStatus.VALIDATION_FAILED.value - elif validation["status"] == ResultStatus.UNVERIFIED.value: - status = ResultStatus.UNVERIFIED.value - runtime_identity_postflight = runtime_identity_payload( - cell, - runtime, - generated.path, - generated.process_id, - expected_source_revision=revision, - ) - _validate_runtime_identity_postflight( - runtime_identity, - runtime_identity_postflight, - ) - runtime_identity_stable_sha256 = _runtime_identity_digest( - _stable_runtime_identity(runtime_identity) - ) - runtime_identity_postflight_stable_sha256 = _runtime_identity_digest( - _stable_runtime_identity(runtime_identity_postflight) - ) - postflight_origin_policy = runtime_identity_postflight.get( - "loaded_module_origin_policy" - ) - if not isinstance(postflight_origin_policy, Mapping): - raise RunnerError( - "report runtime postflight has no loaded-module origin evidence" - ) - - measurement = empty_measurement() - measurement.update(profile) - measurement.update( - { - "status": status, - "generation_seconds": generated.generation_seconds, - "artifact": { - "path": str(generated.path), - "process_id": generated.process_id, - "policy": "reused" if reused_artifact is not None else "generated", - }, - "selector_contract": None if contract is None else contract.as_dict(), - "validation": validation, - "resources": None, - "provenance": { - **provenance_payload(), - "source_revision": revision, - "requested_config": dict(generated.requested_config), - "effective_config": dict(generated.effective_config), - "model_preparation_seconds": generated.model_preparation_seconds, - "model_preparation_reused": generated.model_preparation_reused, - "generation_timer_excludes_model_preparation": True, - "generation_command_path": generated.generation_command_path, - "runtime_load_seconds": runtime_load_seconds, - "runtime_load_included_in_cold_warmup": False, - **( - { - "numerical_relation_correctness": dict( - generated.numerical_relation_correctness - ) - } - if generated.numerical_relation_correctness is not None - else {} - ), - **( - { - "numerical_relation_fallback": dict( - generated.numerical_relation_fallback - ) - } - if generated.numerical_relation_fallback is not None - else {} - ), - "report_momenta": _reproduction_momenta(points), - "runtime_profile": benchmark_evidence, - "execution_timing": execution_timing, - **( - {"evaluator_total_timing": evaluator_total_timing} - if evaluator_total_timing is not None - else {} - ), - "arena_profile_evidence": arena_profile_evidence, - "runtime_identity": runtime_identity, - "runtime_identity_sha256": runtime_identity_sha256, - "runtime_identity_stable_sha256": (runtime_identity_stable_sha256), - "runtime_identity_postflight_stable_sha256": ( - runtime_identity_postflight_stable_sha256 - ), - "runtime_identity_postflight_loaded_module_origin_policy": dict( - postflight_origin_policy - ), - "runtime_identity_postflight_match": True, - }, - "failure": None, - } - ) - if status == ResultStatus.UNVERIFIED.value: - measurement["failure"] = { - "kind": "IndependentAuthorityUnavailable", - "message": "no successful independent numerical authority is available", - } - elif status != ResultStatus.OK.value: - measurement["failure"] = authority_failure or { - "kind": "MeasurementValidationError", - "message": "candidate or same-artifact numerical validation failed", - } - return measurement - - -def failure_measurement( - status: ResultStatus, - error: BaseException | str, - *, - resources: Mapping[str, object] | None = None, -) -> dict[str, object]: - if status in {ResultStatus.NOT_AVAILABLE, ResultStatus.OK}: - raise ValueError("failure measurement requires a terminal failure status") - message = str(error) - failure = empty_measurement() - failure.update( - { - "status": status.value, - "resources": None if resources is None else dict(resources), - "failure": { - "kind": ( - type(error).__name__ if isinstance(error, BaseException) else None - ), - "message": message, - }, - } - ) - return failure - - -def _validate_portable_current_result_path( - path: Path, - paths: ReportPaths, -) -> Path: - root_input = paths.artifact_root.expanduser() - root_lexical = Path(os.path.abspath(root_input)) - try: - root = root_input.resolve(strict=True) - except OSError as error: - raise ValueError("portable current artifact root is unavailable") from error - if root_input.is_symlink() or root != root_lexical or not root.is_dir(): - raise ValueError("portable current artifact root is not canonical") - - source_input = path.expanduser() - source_lexical = Path(os.path.abspath(source_input)) - try: - source = source_input.resolve(strict=True) - except OSError as error: - raise ValueError("portable current result file is unavailable") from error - if source_input.is_symlink() or source != source_lexical or not source.is_file(): - raise ValueError("portable current result path is not canonical") - try: - relative = source.relative_to(root) - except ValueError as error: - raise ValueError( - "portable current result is outside the artifact root" - ) from error - parts = relative.parts - if ( - len(parts) != 5 - or parts[0] != "cells" - or not parts[1] - or parts[2] != "attempts" - or parts[4] != "result.json" - ): - raise ValueError("portable current result path has an unsupported shape") - try: - attempt_id = str(uuid.UUID(parts[3])) - except (AttributeError, ValueError) as error: - raise ValueError("portable current result attempt ID is invalid") from error - if attempt_id != parts[3]: - raise ValueError("portable current result attempt ID is not canonical") - return source - - -def load_measurement( - path: Path, - *, - publication_paths: ReportPaths | None = None, -) -> dict[str, object]: - source = ( - path - if publication_paths is None - else _validate_portable_current_result_path(path, publication_paths) - ) - payload = json.loads(source.read_text(encoding="utf-8")) - if not isinstance(payload, Mapping): - raise ValueError("measurement file must contain an object") - if publication_paths is not None: - from .publication import materialize_current_value - - payload = materialize_current_value(payload, publication_paths) - if not isinstance(payload, Mapping): # pragma: no cover - parsed object above. - raise ValueError("portable measurement did not materialize as an object") - return dict(payload) - - -__all__ = [ - "attach_validation_failure_precision_diagnostic", - "baseline_uses_lc_common_component_authority", - "conditioned_measurement_comparison", - "failure_measurement", - "file_digest", - "generated_artifact_from_measurement", - "load_measurement", - "measure_pyamplicol_cell", - "reconcile_independent_authority", - "shared_validation_points", - "source_revision", -] diff --git a/pyamplicol/tools/performance_report/measurement_lineage.py b/pyamplicol/tools/performance_report/measurement_lineage.py deleted file mode 100644 index df9537151c..0000000000 --- a/pyamplicol/tools/performance_report/measurement_lineage.py +++ /dev/null @@ -1,4914 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Fail-closed executable-source lineage for architecture report profiles. - -The ordinary report contract deliberately accepts measurements from one exact -source revision only. A Class-C bridge is the narrow exception used when a -bounded physics correction must replace only the directly affected cells in a -frozen architecture campaign. It never rewrites measurement provenance: -every retained ancestor current is authorized by its immutable attempt and -manifest digest. -""" - -from __future__ import annotations - -import hashlib -import json -import math -import os -import re -import subprocess -import uuid -from collections.abc import Callable, Mapping, Sequence -from dataclasses import dataclass -from pathlib import Path, PurePosixPath -from typing import Any - -from .agreements import incoming_agreement_edges -from .artifacts import ATTEMPT_SCHEMA, ArtifactStore, CurrentRecord -from .cache import _validate_runtime_identity_postflight, validate_measurement -from .catalog import REPORT_CATALOG, ReportCatalog -from .models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .runner import ( - validate_conditioned_comparison_record, - validate_resolved_sum_validation_record, -) -from .source_identity import require_eligible_report_source - -MEASUREMENT_LINEAGE_SCHEMA = "pyamplicol-performance-measurement-lineage-v2" -MEASUREMENT_LINEAGE_WRAPPER_SCHEMA = ( - "pyamplicol-performance-measurement-lineage-envelope-v1" -) -MEASUREMENT_LINEAGE_FILENAME = "measurement_lineage.json" -CLASS_C_HZZ_IMPACT = "hzz-orientation-v1" -CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT = "recurrence-summary-cap-v1" -_CLASS_C_IMPACTS = frozenset( - { - CLASS_C_HZZ_IMPACT, - CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - } -) - -_SHA256_RE = re.compile(r"[0-9a-f]{64}") -_GIT_SHA_RE = re.compile(r"[0-9a-f]{40,64}") -_ATTEMPT_KEYS = { - "schema", - "cell_id", - "attempt_id", - "status", - "artifact_policy", - "based_on", - "result_path", - "artifacts", - "error", -} -_PROFILE_ROOT = PurePosixPath("docs/performance_reports") -_HZZ_CONTRACT_IDS = frozenset( - { - "pyamplicol.models.builtin.model.BuiltinSMModel:18", - "pyamplicol.models.builtin.model.BuiltinSMModel:19", - } -) - -# The executable descendant is deliberately specific. Any additional path -# requires a reviewed source change to this allowlist and therefore cannot be -# smuggled into a bridge manifest at run time. -_HZZ_ALLOWED_PATHS = frozenset( - { - "src/pyamplicol/models/builtin/lowering.py", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.pyamplicol-model", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.metadata.json", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.pyamplicol-model", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.metadata.json", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.pyamplicol-model", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.metadata.json", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.pyamplicol-model", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.metadata.json", - "tools/performance_report/measurement_lineage.py", - "tools/performance_report/source_identity.py", - "tools/performance_report/workspace.py", - "tools/performance_report/cli.py", - "tools/performance_report/scheduler.py", - "tools/performance_report/service.py", - "tools/performance_report/render.py", - "tools/performance_report/validation_summary.py", - "tools/performance_report/campaign_policy.py", - "tools/performance_report/final_audit.py", - "docs/arxiv/result_tables.py", - "docs/performance_reports/macbook_M3/result_tables.py", - "docs/performance_reports/x86_EPYC/result_tables.py", - "docs/performance_reports/macbook_M3/TABLE_FILLING.md", - "docs/performance_reports/x86_EPYC/TABLE_FILLING.md", - "tests/unit/test_performance_report_measurement_lineage.py", - "tests/unit/test_performance_report_measurement_lineage_adversarial.py", - "tests/unit/test_performance_report_source_identity.py", - "tests/unit/test_performance_report_workspace.py", - "tests/unit/test_performance_report_cli.py", - "tests/unit/test_three_mode_report_scheduler.py", - "tests/unit/test_three_mode_report_service.py", - "tests/unit/test_three_mode_report_render.py", - "tests/unit/test_performance_report_campaign_policy.py", - "tests/unit/test_performance_report_final_audit.py", - "tests/unit/test_model_builtin.py", - "tests/unit/test_packaged_prepared_model.py", - "tests/unit/test_recurrence_catalog_builder.py", - } -) - -_HZZ_REQUIRED_FEATURE_PATHS = frozenset( - { - "src/pyamplicol/models/builtin/lowering.py", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.pyamplicol-model", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.metadata.json", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.pyamplicol-model", - "src/pyamplicol/assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.metadata.json", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.pyamplicol-model", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-aarch64.metadata.json", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.pyamplicol-model", - "release_assets/prepared_models/" - "built-in-sm-jit-o2-x86_64.metadata.json", - "tests/unit/test_model_builtin.py", - "tests/unit/test_packaged_prepared_model.py", - "tests/unit/test_recurrence_catalog_builder.py", - } -) - -_RECURRENCE_SUMMARY_CAP_REPORT_FILES = ( - "pyAmpliCol.tex", - "result_matrix_best_builtin_sm_full_table.tex", - "result_matrix_best_builtin_sm_lc_table.tex", - "result_matrix_best_builtin_sm_nlc_table.tex", - "result_matrix_compiled_builtin_sm_full_table.tex", - "result_matrix_compiled_builtin_sm_lc_table.tex", - "result_matrix_compiled_builtin_sm_nlc_table.tex", - "result_matrix_eager_builtin_sm_full_table.tex", - "result_matrix_eager_builtin_sm_lc_table.tex", - "result_matrix_eager_builtin_sm_nlc_table.tex", - "result_matrix_recurrence_builtin_sm_full_table.tex", - "result_matrix_recurrence_builtin_sm_lc_table.tex", - "result_matrix_recurrence_builtin_sm_nlc_table.tex", - "result_matrix_recurrence_ufo_sm_full_table.tex", - "result_matrix_recurrence_ufo_sm_lc_table.tex", - "result_matrix_recurrence_ufo_sm_nlc_table.tex", - "result_scalar_contact_table.tex", - "result_scalar_gravity_table.tex", - "result_tables.py", - "result_z_builtin_sm_table.tex", - "result_z_external_sm_table.tex", - "section_three_mode_performance_tables.tex", -) -_RECURRENCE_SUMMARY_CAP_ALLOWED_PATHS = ( - frozenset( - { - "docs/performance_reports/macbook_M3/TABLE_FILLING.md", - "docs/performance_reports/x86_EPYC/TABLE_FILLING.md", - "rust/crates/rusticol-core/src/engine/recurrence_manifest.rs", - "src/pyamplicol/generation/artifact_writer.py", - "tests/unit/test_performance_report_artifacts.py", - "tests/unit/test_performance_report_cli.py", - "tests/unit/test_performance_report_measurement_lineage.py", - "tests/unit/test_performance_report_measurement_lineage_adversarial.py", - "tests/unit/test_performance_report_publisher.py", - "tests/unit/test_recurrence_direct_artifact_metadata.py", - "tests/unit/test_three_mode_report_legacy.py", - "tests/unit/test_three_mode_report_render.py", - "tests/unit/test_three_mode_report_scheduler.py", - "tools/performance_report/artifacts.py", - "tools/performance_report/campaign_policy.py", - "tools/performance_report/cli.py", - "tools/performance_report/legacy.py", - "tools/performance_report/measurement_lineage.py", - "tools/performance_report/publisher.py", - "tools/performance_report/render.py", - "tools/performance_report/scheduler.py", - "tools/performance_report/workspace.py", - } - ) - | frozenset( - f"{root}/{filename}" - for root in ( - "docs/arxiv", - "docs/performance_reports/macbook_M3", - "docs/performance_reports/x86_EPYC", - ) - for filename in _RECURRENCE_SUMMARY_CAP_REPORT_FILES - ) -) -_RECURRENCE_SUMMARY_CAP_REQUIRED_PATHS = _RECURRENCE_SUMMARY_CAP_ALLOWED_PATHS - -_RECURRENCE_SUMMARY_CAP_PREDECESSOR_REVISION = ( - "6536ef131e18e7ff873eb1f4db1f08631155f3a9" -) -_RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION = ( - "be11d8304fdc04893dc0e23e9619be848126e3bc" -) -_RECURRENCE_SUMMARY_CAP_DESCENDANT_REVISION = ( - "2594d8b520b802f71d60bd646f73ebaa5547927a" -) -_RECURRENCE_SUMMARY_CAP_ANCESTOR_NATIVE_INPUTS_SHA256 = ( - "23b9637d5d3fba0947d78cf688df18799b0c9ee5b3bcbfa6a2963a1f1a21f870" -) -_RECURRENCE_SUMMARY_CAP_DESCENDANT_NATIVE_INPUTS_SHA256 = ( - "96e1ff79a007aaf67a0900dd6d67327ee00f6bd2cca002589b879aa3a734de08" -) -_PRE_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256 = ( - "7b7e641dd22964ca9feb486519859e0f9dc956b44c7fc9da35bd765531ab7154" -) -_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256 = ( - "49ed0246dedc3efa42dbbf6a7197d82306251118e19e6fea7d0dce1b02c8388c" -) -_RECURRENCE_SUMMARY_CAP_PROFILE = "x86_EPYC" -_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES = { - "matrix-recurrence-builtin-sm-lc-n7-gg-gluons-selected-flow": 4_270_140, - "matrix-recurrence-builtin-sm-lc-n8-dd-tt-jets-selected-flow": 1_083_926, - "matrix-recurrence-builtin-sm-lc-n9-dd-z-jets-selected-flow": 4_449_888, - "matrix-recurrence-builtin-sm-lc-n9-ud-w-jets-selected-flow": 4_449_912, -} -_RECURRENCE_SUMMARY_CAP_AGREEMENT_IDS = frozenset( - { - "matrix-recurrence-builtin-sm-lc-n7-gg-gluons-all-flow", - "matrix-recurrence-builtin-sm-lc-n8-dd-tt-jets-all-flow", - "matrix-recurrence-builtin-sm-lc-n9-dd-z-jets-all-flow", - "matrix-recurrence-builtin-sm-lc-n9-ud-w-jets-all-flow", - "matrix-recurrence-ufo-sm-lc-n7-gg-gluons-all-flow", - "matrix-recurrence-ufo-sm-lc-n7-gg-gluons-selected-flow", - "matrix-recurrence-ufo-sm-lc-n8-dd-tt-jets-all-flow", - "matrix-recurrence-ufo-sm-lc-n8-dd-tt-jets-selected-flow", - "matrix-recurrence-ufo-sm-lc-n9-dd-z-jets-all-flow", - "matrix-recurrence-ufo-sm-lc-n9-dd-z-jets-selected-flow", - "matrix-recurrence-ufo-sm-lc-n9-ud-w-jets-all-flow", - "matrix-recurrence-ufo-sm-lc-n9-ud-w-jets-selected-flow", - } -) -_SIGNED_ZERO_HELICITY_REFERENCE_IDS = frozenset( - { - f"reference-amplicol-lc-n{n_final}-{process}-{workload}" - for n_final in range(4, 8) - for process in ("dd-epemzh-jets", "dd-ttzh-jets") - for workload in ("selected-flow", "all-flow") - } -) -_SIGNED_ZERO_HELICITY_SELECTED_RECURRENCE_IDS = frozenset( - { - f"matrix-recurrence-builtin-sm-lc-n{n_final}-{process}-selected-flow" - for n_final in range(4, 8) - for process in ("dd-epemzh-jets", "dd-ttzh-jets") - } -) -_SIGNED_ZERO_HELICITY_IMPACTED_IDS = ( - _SIGNED_ZERO_HELICITY_REFERENCE_IDS - | _SIGNED_ZERO_HELICITY_SELECTED_RECURRENCE_IDS -) -_SIGNED_ZERO_HELICITY_AGREEMENT_IDS = frozenset( - { - f"matrix-recurrence-{model}-lc-n{n_final}-{process}-{workload}" - for model in ("builtin-sm", "ufo-sm") - for n_final in range(4, 8) - for process in ("dd-epemzh-jets", "dd-ttzh-jets") - for workload in ( - ("all-flow",) - if model == "builtin-sm" - else ("selected-flow", "all-flow") - ) - } -) | frozenset( - { - f"matrix-{mode}-builtin-sm-lc-n{n_final}-{process}-all-flow" - for mode in ("compiled", "eager") - for n_final in range(4, 8) - for process in ("dd-epemzh-jets", "dd-ttzh-jets") - } -) | frozenset( - { - f"matrix-on-the-fly-builtin-sm-lc-n4-{process}-all-flow" - for process in ("dd-epemzh-jets", "dd-ttzh-jets") - } -) - -_ENVIRONMENT_KEYS = { - "schema", - "profile", - "status", - "source_revision", - "platform", - "machine", - "processor", - "python", - "python_implementation", - "pyamplicol", - "numpy", - "native_target", - "native_cpu_features", - "native_build_inputs_sha256", - "native_extension_sha256", - "python_package_tree_sha256", - "candidate_fingerprint", -} - -# A fresh native relink is authenticated by its exact build-input digest, -# candidate fingerprint, target, and CPU feature set. The raw extension digest -# is intentionally recorded in each endpoint environment but is not invariant: -# Mach-O UUIDs, temporary build paths, and signatures make that output -# byte-nondeterministic even when every native input is unchanged. -_ENVIRONMENT_INVARIANT_FIELDS = ( - "schema", - "profile", - "platform", - "machine", - "processor", - "python", - "python_implementation", - "status", - "pyamplicol", - "numpy", - "native_target", - "native_cpu_features", - "native_build_inputs_sha256", - "candidate_fingerprint", -) - -_CURRENT_PIN_KEYS = { - "cell_id", - "attempt_id", - "manifest_sha256", - "current_locator", - "current_pointer_sha256", - "source_revision", - "source_tree", - "result_sha256", -} - -_REACHABILITY_RECORD_KEYS = { - "cell_id", - "attempt_id", - "manifest_sha256", - "artifact_locator", - "artifact_owner", - "process_id", - "execution_manifest_path", - "execution_manifest_sha256", - "schedule_path", - "schedule_sha256", - "schedule_index_sha256", - "schedule_member_sha256", - "process_binding_path", - "process_binding_sha256", - "kernel_pack_path", - "kernel_pack_sha256", - "semantic_catalog_sha256", - "direct_catalog_sha256", - "active_executor_ids", - "matched_template_ids", - "matched_contract_ids", -} - -_SUMMARY_CAP_FAILURE_RECORD_KEYS = { - "cell_id", - "attempt_id", - "manifest_sha256", - "result_locator", - "result_sha256", - "summary_bytes", - "failure_kind", - "failure_message", -} -_SUMMARY_CAP_EXCLUDED_RECORD_KEYS = { - "cell_id", - "attempt_id", - "manifest_sha256", - "result_locator", - "result_sha256", - "current_locator", - "current_pointer_sha256", - "status", - "failure_sha256", -} -_SUMMARY_CAP_PREDECESSOR_KEYS = { - "payload_sha256", - "profile", - "impact", - "ancestor_revision", - "ancestor_tree", - "descendant_revision", - "descendant_tree", - "ancestor_environment", - "ancestor_environment_sha256", - "descendant_environment_sha256", - "retained_currents", - "retained_currents_sha256", -} - -_ARTIFACT_OWNER_KEYS = { - "relation", - "artifact_locator", - "consumer_cell_id", - "consumer_attempt_id", - "consumer_manifest_locator", - "consumer_manifest_sha256", - "consumer_result_locator", - "consumer_result_sha256", - "consumer_source_revision", - "consumer_source_tree", - "consumer_runtime_identity_sha256", - "consumer_runtime_identity_stable_sha256", - "owner_cell_id", - "owner_attempt_id", - "owner_current_locator", - "owner_current_sha256", - "owner_manifest_locator", - "owner_manifest_sha256", - "owner_result_locator", - "owner_result_sha256", - "owner_artifacts_sha256", - "owner_source_revision", - "owner_source_tree", - "owner_runtime_identity_sha256", - "owner_runtime_identity_stable_sha256", -} - -_ATTEMPT_INVENTORY_KEYS = { - "cell_id", - "attempt_id", - "manifest_locator", - "manifest_sha256", - "status", - "error_sha256", - "result_path", - "result_sha256", - "artifact_count", - "artifacts_sha256", -} - -_PAYLOAD_KEYS = { - "schema", - "state", - "class", - "impact", - "profile", - "ancestor_revision", - "ancestor_tree", - "descendant_revision", - "descendant_tree", - "git_diff", - "git_diff_sha256", - "ancestor_environment", - "ancestor_environment_sha256", - "descendant_environment", - "descendant_environment_sha256", - "runtime_invariant_fields", - "impacted_cells", - "agreement_closure_cells", - "impact_certificate_sha256", - "catalog_sha256", - "agreement_graph_sha256", - "workspace_manifest", - "workspace_manifest_sha256", - "campaign_policy_sha256", - "reachability_certificate", - "reachability_certificate_sha256", - "retained_currents", - "invalidated_currents", - "recompare_currents", - "attempt_inventory", - "no_attempt_cells", - "current_snapshot_sha256", -} - -_CANONICAL_CATALOG_SHA256: str | None = None -_CANONICAL_AGREEMENT_SHA256: str | None = None - - -class MeasurementLineageError(RuntimeError): - """A Class-C measurement-lineage record is absent or inconsistent.""" - - -def _canonical_bytes(value: object) -> bytes: - try: - encoded = json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - except (TypeError, ValueError) as error: - raise MeasurementLineageError( - f"measurement lineage is not canonical JSON: {error}" - ) from error - return f"{encoded}\n".encode("ascii") - - -def _digest(value: object) -> str: - return hashlib.sha256(_canonical_bytes(value)).hexdigest() - - -def _file_digest(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for chunk in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def _reject_duplicate_pairs( - pairs: list[tuple[str, object]], -) -> dict[str, object]: - value: dict[str, object] = {} - for key, item in pairs: - if key in value: - raise MeasurementLineageError( - f"measurement-lineage JSON contains duplicate key {key!r}" - ) - value[key] = item - return value - - -def _read_canonical_json(path: Path, *, context: str) -> dict[str, object]: - if path.is_symlink() or not path.is_file(): - raise MeasurementLineageError(f"{context} is not a regular file: {path}") - try: - data = path.read_bytes() - raw = json.loads( - data.decode("ascii"), - object_pairs_hook=_reject_duplicate_pairs, - ) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise MeasurementLineageError( - f"cannot read {context} {path}: {error}" - ) from error - if not isinstance(raw, dict) or data != _canonical_bytes(raw): - raise MeasurementLineageError( - f"{context} has no valid canonical digest/JSON encoding: {path}" - ) - return raw - - -def _write_envelope(path: Path, payload: Mapping[str, object]) -> None: - envelope = { - "schema": MEASUREMENT_LINEAGE_WRAPPER_SCHEMA, - "payload": dict(payload), - "payload_sha256": _digest(payload), - } - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{uuid.uuid4().hex}") - try: - with temporary.open("xb") as stream: - stream.write(_canonical_bytes(envelope)) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - finally: - temporary.unlink(missing_ok=True) - - -def _atomic_write_bytes(path: Path, data: bytes) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{uuid.uuid4().hex}") - try: - with temporary.open("xb") as stream: - stream.write(data) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - finally: - temporary.unlink(missing_ok=True) - - -def _restore_file(path: Path, previous: bytes | None) -> None: - if previous is None: - path.unlink(missing_ok=True) - else: - _atomic_write_bytes(path, previous) - - -def _safe_locator(value: object) -> bool: - return ( - isinstance(value, str) - and bool(value) - and not Path(value).is_absolute() - and all( - part not in {"", ".", ".."} - for part in Path(value).parts - ) - ) - - -def _validate_artifact_owner( - record: Mapping[str, object], -) -> None: - raw = record.get("artifact_owner") - if not isinstance(raw, Mapping) or set(raw) != _ARTIFACT_OWNER_KEYS: - raise MeasurementLineageError( - "measurement-lineage recurrence artifact-owner record is malformed" - ) - relation = raw.get("relation") - try: - consumer_attempt = ( - str(uuid.UUID(str(raw["consumer_attempt_id"]))) - if isinstance(raw.get("consumer_attempt_id"), str) - else None - ) - owner_attempt = ( - str(uuid.UUID(str(raw["owner_attempt_id"]))) - if isinstance(raw.get("owner_attempt_id"), str) - else None - ) - except ValueError: - consumer_attempt = None - owner_attempt = None - consumer_cell = raw.get("consumer_cell_id") - owner_cell = raw.get("owner_cell_id") - locators = ( - raw.get("artifact_locator"), - raw.get("consumer_manifest_locator"), - raw.get("consumer_result_locator"), - raw.get("owner_manifest_locator"), - raw.get("owner_result_locator"), - ) - digests = ( - "consumer_manifest_sha256", - "consumer_result_sha256", - "consumer_runtime_identity_sha256", - "consumer_runtime_identity_stable_sha256", - "owner_manifest_sha256", - "owner_result_sha256", - "owner_artifacts_sha256", - "owner_runtime_identity_sha256", - "owner_runtime_identity_stable_sha256", - ) - revisions = ( - "consumer_source_revision", - "consumer_source_tree", - "owner_source_revision", - "owner_source_tree", - ) - if ( - relation not in {"consumer-attempt", "equivalent-matrix-peer"} - or not isinstance(consumer_cell, str) - or not consumer_cell - or not isinstance(owner_cell, str) - or not owner_cell - or consumer_attempt != raw.get("consumer_attempt_id") - or owner_attempt != raw.get("owner_attempt_id") - or consumer_cell != record.get("cell_id") - or consumer_attempt != record.get("attempt_id") - or raw.get("consumer_manifest_sha256") - != record.get("manifest_sha256") - or raw.get("artifact_locator") != record.get("artifact_locator") - or not all(_safe_locator(value) for value in locators) - or any( - not isinstance(raw.get(field), str) - or _SHA256_RE.fullmatch(str(raw[field])) is None - for field in digests - ) - or any( - not isinstance(raw.get(field), str) - or _GIT_SHA_RE.fullmatch(str(raw[field])) is None - for field in revisions - ) - or raw.get("consumer_source_revision") - != raw.get("owner_source_revision") - or raw.get("consumer_source_tree") != raw.get("owner_source_tree") - or raw.get("consumer_runtime_identity_stable_sha256") - != raw.get("owner_runtime_identity_stable_sha256") - ): - raise MeasurementLineageError( - "measurement-lineage recurrence artifact-owner identity is invalid" - ) - - consumer_manifest = PurePosixPath(str(raw["consumer_manifest_locator"])) - consumer_result = PurePosixPath(str(raw["consumer_result_locator"])) - owner_manifest = PurePosixPath(str(raw["owner_manifest_locator"])) - owner_result = PurePosixPath(str(raw["owner_result_locator"])) - artifact = PurePosixPath(str(raw["artifact_locator"])) - owner_current = raw.get("owner_current_locator") - owner_current_sha256 = raw.get("owner_current_sha256") - if ( - not consumer_manifest.as_posix().endswith( - f"/attempts/{consumer_attempt}/manifest.json" - ) - or consumer_result.parent != consumer_manifest.parent - or not owner_manifest.as_posix().endswith( - f"/attempts/{owner_attempt}/manifest.json" - ) - or owner_result.parent != owner_manifest.parent - or artifact != owner_manifest.parent / "artifact" - ): - raise MeasurementLineageError( - "measurement-lineage recurrence artifact-owner locators are inconsistent" - ) - if relation == "consumer-attempt": - if ( - owner_cell != consumer_cell - or owner_attempt != consumer_attempt - or owner_current is not None - or owner_current_sha256 is not None - or owner_manifest != consumer_manifest - or owner_result != consumer_result - or raw.get("owner_manifest_sha256") - != raw.get("consumer_manifest_sha256") - or raw.get("owner_result_sha256") - != raw.get("consumer_result_sha256") - ): - raise MeasurementLineageError( - "measurement-lineage direct artifact owner is inconsistent" - ) - elif ( - owner_cell == consumer_cell - or not _safe_locator(owner_current) - or not str(owner_current).endswith("/current.json") - or not isinstance(owner_current_sha256, str) - or _SHA256_RE.fullmatch(owner_current_sha256) is None - or PurePosixPath(str(owner_current)) - != owner_manifest.parents[2] / "current.json" - ): - raise MeasurementLineageError( - "measurement-lineage matrix-peer artifact owner is inconsistent" - ) - - -def _summary_cap_failure_message(summary_bytes: int) -> str: - return ( - "Rust recurrence execution summary must be smaller than 1 MiB; " - f"received {summary_bytes} bytes" - ) - - -def _validate_summary_cap_predecessor( - predecessor: object, -) -> None: - if ( - not isinstance(predecessor, Mapping) - or set(predecessor) != _SUMMARY_CAP_PREDECESSOR_KEYS - or predecessor.get("impact") != CLASS_C_HZZ_IMPACT - or predecessor.get("profile") != _RECURRENCE_SUMMARY_CAP_PROFILE - or predecessor.get("ancestor_revision") - != _RECURRENCE_SUMMARY_CAP_PREDECESSOR_REVISION - or predecessor.get("descendant_revision") - != _RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION - or not isinstance(predecessor.get("payload_sha256"), str) - or _SHA256_RE.fullmatch(str(predecessor["payload_sha256"])) is None - or any( - not isinstance(predecessor.get(field), str) - or _GIT_SHA_RE.fullmatch(str(predecessor[field])) is None - for field in ( - "ancestor_revision", - "ancestor_tree", - "descendant_revision", - "descendant_tree", - ) - ) - or not isinstance(predecessor.get("ancestor_environment"), Mapping) - or set(predecessor["ancestor_environment"]) != _ENVIRONMENT_KEYS - or predecessor.get("ancestor_environment_sha256") - != _digest(predecessor["ancestor_environment"]) - or not isinstance( - predecessor.get("descendant_environment_sha256"), - str, - ) - or _SHA256_RE.fullmatch( - str(predecessor["descendant_environment_sha256"]) - ) - is None - or not isinstance(predecessor.get("retained_currents"), list) - or predecessor.get("retained_currents_sha256") - != _digest(predecessor["retained_currents"]) - ): - raise MeasurementLineageError( - "measurement-lineage summary-cap predecessor is malformed" - ) - retained = _validated_pins(predecessor, "retained_currents") - if any( - pin["source_revision"] != predecessor["ancestor_revision"] - or pin["source_tree"] != predecessor["ancestor_tree"] - for pin in retained - ): - raise MeasurementLineageError( - "measurement-lineage summary-cap predecessor pins another source" - ) - - -def _validate_summary_cap_certificate( - certificate: Mapping[str, object], -) -> None: - expected_ids = sorted(_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES) - records = certificate.get("records") - excluded = certificate.get("excluded_non_success_currents") - predecessor = certificate.get("predecessor") - invalidated = certificate.get("invalidated_generation_error_current_ids") - inspected = certificate.get("inspected_current_count") - successful = certificate.get("successful_current_count") - excluded_count = certificate.get("excluded_non_success_current_count") - if ( - set(certificate) - != { - "algorithm", - "predecessor", - "target_summary_bytes", - "inspected_current_count", - "successful_current_count", - "excluded_non_success_current_count", - "records", - "excluded_non_success_currents", - "invalidated_generation_error_current_ids", - "sha256", - } - or certificate.get("algorithm") - != "authenticated-recurrence-summary-cap-failure-census-v1" - or certificate.get("target_summary_bytes") - != _RECURRENCE_SUMMARY_CAP_FAILURE_BYTES - or not isinstance(inspected, int) - or isinstance(inspected, bool) - or not isinstance(successful, int) - or isinstance(successful, bool) - or not isinstance(excluded_count, int) - or isinstance(excluded_count, bool) - or inspected != successful + excluded_count + len(expected_ids) - or successful < 0 - or excluded_count < 0 - or not isinstance(records, list) - or not isinstance(excluded, list) - or len(excluded) != excluded_count - or not isinstance(invalidated, list) - or invalidated != expected_ids - or len(records) != len(expected_ids) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence summary-cap census is malformed" - ) - _validate_summary_cap_predecessor(predecessor) - record_ids: list[str] = [] - for record in records: - if ( - not isinstance(record, dict) - or set(record) != _SUMMARY_CAP_FAILURE_RECORD_KEYS - ): - raise MeasurementLineageError( - "measurement-lineage recurrence summary-cap record is malformed" - ) - cell_id = record.get("cell_id") - attempt_id = record.get("attempt_id") - try: - canonical_attempt = ( - str(uuid.UUID(attempt_id)) - if isinstance(attempt_id, str) - else None - ) - except ValueError: - canonical_attempt = None - result_locator = record.get("result_locator") - summary_bytes = ( - _RECURRENCE_SUMMARY_CAP_FAILURE_BYTES.get(cell_id) - if isinstance(cell_id, str) - else None - ) - if ( - summary_bytes is None - or canonical_attempt != attempt_id - or not _safe_locator(result_locator) - or not str(result_locator).endswith( - f"/attempts/{attempt_id}/result.json" - ) - or not isinstance(record.get("manifest_sha256"), str) - or _SHA256_RE.fullmatch(str(record["manifest_sha256"])) is None - or not isinstance(record.get("result_sha256"), str) - or _SHA256_RE.fullmatch(str(record["result_sha256"])) is None - or record.get("summary_bytes") != summary_bytes - or record.get("failure_kind") != "GenerationError" - or record.get("failure_message") - != _summary_cap_failure_message(summary_bytes) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence summary-cap record is invalid" - ) - record_ids.append(cell_id) - if record_ids != expected_ids: - raise MeasurementLineageError( - "measurement-lineage recurrence summary-cap records do not match " - "the exact failure census" - ) - excluded_ids: list[str] = [] - for record in excluded: - if ( - not isinstance(record, dict) - or set(record) != _SUMMARY_CAP_EXCLUDED_RECORD_KEYS - ): - raise MeasurementLineageError( - "measurement-lineage excluded terminal current is malformed" - ) - cell_id = record.get("cell_id") - attempt_id = record.get("attempt_id") - try: - canonical_attempt = ( - str(uuid.UUID(attempt_id)) - if isinstance(attempt_id, str) - else None - ) - except ValueError: - canonical_attempt = None - if ( - not isinstance(cell_id, str) - or not cell_id - or cell_id in _RECURRENCE_SUMMARY_CAP_FAILURE_BYTES - or canonical_attempt != attempt_id - or not _safe_locator(record.get("result_locator")) - or not str(record["result_locator"]).endswith( - f"/attempts/{attempt_id}/result.json" - ) - or not _safe_locator(record.get("current_locator")) - or not str(record["current_locator"]).endswith("/current.json") - or record.get("status") == ResultStatus.OK.value - or record.get("status") - not in {status.value for status in ResultStatus} - or any( - not isinstance(record.get(field), str) - or _SHA256_RE.fullmatch(str(record[field])) is None - for field in ( - "manifest_sha256", - "result_sha256", - "current_pointer_sha256", - "failure_sha256", - ) - ) - ): - raise MeasurementLineageError( - "measurement-lineage excluded terminal current is invalid" - ) - excluded_ids.append(cell_id) - if excluded_ids != sorted(set(excluded_ids)): - raise MeasurementLineageError( - "measurement-lineage excluded terminal currents are not a unique census" - ) - - -def _validate_payload_shape(payload: Mapping[str, object]) -> None: - if set(payload) != _PAYLOAD_KEYS: - raise MeasurementLineageError( - "measurement-lineage payload has an unsupported schema shape" - ) - if ( - payload.get("schema") != MEASUREMENT_LINEAGE_SCHEMA - or payload.get("state") not in {"pending", "finalized"} - or payload.get("class") != "C" - or payload.get("impact") not in _CLASS_C_IMPACTS - or not isinstance(payload.get("profile"), str) - or not payload["profile"] - or ( - payload.get("impact") - == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - and ( - payload.get("profile") != _RECURRENCE_SUMMARY_CAP_PROFILE - or payload.get("ancestor_revision") - != _RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION - or payload.get("descendant_revision") - != _RECURRENCE_SUMMARY_CAP_DESCENDANT_REVISION - ) - ) - or payload.get("runtime_invariant_fields") - != list(_ENVIRONMENT_INVARIANT_FIELDS) - ): - raise MeasurementLineageError( - "measurement-lineage class, impact, profile, or invariants are invalid" - ) - for field in ( - "ancestor_revision", - "ancestor_tree", - "descendant_revision", - "descendant_tree", - ): - if ( - not isinstance(payload.get(field), str) - or _GIT_SHA_RE.fullmatch(str(payload[field])) is None - ): - raise MeasurementLineageError( - f"measurement-lineage {field} is not a full Git identity" - ) - for field in ( - "git_diff_sha256", - "ancestor_environment_sha256", - "impact_certificate_sha256", - "catalog_sha256", - "agreement_graph_sha256", - "workspace_manifest_sha256", - "campaign_policy_sha256", - "reachability_certificate_sha256", - "current_snapshot_sha256", - ): - if ( - not isinstance(payload.get(field), str) - or _SHA256_RE.fullmatch(str(payload[field])) is None - ): - raise MeasurementLineageError( - f"measurement-lineage {field} is not a SHA-256 digest" - ) - ancestor_environment = payload.get("ancestor_environment") - if ( - not isinstance(ancestor_environment, Mapping) - or set(ancestor_environment) != _ENVIRONMENT_KEYS - or payload.get("ancestor_environment_sha256") - != _digest(ancestor_environment) - ): - raise MeasurementLineageError( - "measurement-lineage ancestor environment is invalid" - ) - descendant_environment = payload.get("descendant_environment") - descendant_digest = payload.get("descendant_environment_sha256") - if payload["state"] == "pending": - if descendant_environment is not None or descendant_digest is not None: - raise MeasurementLineageError( - "pending measurement lineage carries a descendant environment" - ) - elif ( - not isinstance(descendant_environment, Mapping) - or set(descendant_environment) != _ENVIRONMENT_KEYS - or not isinstance(descendant_digest, str) - or descendant_digest != _digest(descendant_environment) - ): - raise MeasurementLineageError( - "finalized measurement-lineage descendant environment is invalid" - ) - workspace = payload.get("workspace_manifest") - if ( - not isinstance(workspace, Mapping) - or set(workspace) - != { - "path", - "mode", - "object", - "sha256", - "campaign_policy_sha256", - } - or workspace.get("mode") != "100644" - or workspace.get("campaign_policy_sha256") - != payload.get("campaign_policy_sha256") - or payload.get("workspace_manifest_sha256") != _digest(workspace) - ): - raise MeasurementLineageError( - "measurement-lineage workspace manifest identity is invalid" - ) - for field in ( - "git_diff", - "impacted_cells", - "agreement_closure_cells", - "attempt_inventory", - "no_attempt_cells", - "retained_currents", - "invalidated_currents", - "recompare_currents", - ): - if not isinstance(payload.get(field), list): - raise MeasurementLineageError( - f"measurement-lineage {field} must be an array" - ) - no_attempts = payload["no_attempt_cells"] - if no_attempts != sorted(set(no_attempts)) or not all( - isinstance(value, str) and value for value in no_attempts - ): - raise MeasurementLineageError( - "measurement-lineage no-attempt inventory is not sorted and unique" - ) - inventory = payload["attempt_inventory"] - inventory_keys: list[tuple[str, str]] = [] - for raw in inventory: - if not isinstance(raw, dict) or set(raw) != _ATTEMPT_INVENTORY_KEYS: - raise MeasurementLineageError( - "measurement-lineage attempt inventory row is malformed" - ) - cell_id = raw.get("cell_id") - attempt_id = raw.get("attempt_id") - try: - canonical_attempt_id = ( - str(uuid.UUID(attempt_id)) - if isinstance(attempt_id, str) - else None - ) - except ValueError: - canonical_attempt_id = None - locator = raw.get("manifest_locator") - result_path = raw.get("result_path") - status = raw.get("status") - if ( - not isinstance(cell_id, str) - or not cell_id - or canonical_attempt_id != attempt_id - or not isinstance(locator, str) - or Path(locator).is_absolute() - or any(part in {"", ".", ".."} for part in Path(locator).parts) - or not locator.endswith(f"/attempts/{attempt_id}/manifest.json") - or status not in {"ok", "failed", "interrupted"} - or ( - status == "ok" - and ( - not isinstance(result_path, str) - or not result_path - or Path(result_path).is_absolute() - or any( - part in {"", ".", ".."} - for part in Path(result_path).parts - ) - ) - ) - or (status != "ok" and result_path is not None) - or not isinstance(raw.get("manifest_sha256"), str) - or _SHA256_RE.fullmatch(str(raw["manifest_sha256"])) is None - or not isinstance(raw.get("error_sha256"), str) - or _SHA256_RE.fullmatch(str(raw["error_sha256"])) is None - or ( - raw.get("result_sha256") is not None - and ( - not isinstance(raw.get("result_sha256"), str) - or _SHA256_RE.fullmatch(str(raw["result_sha256"])) is None - ) - ) - or isinstance(raw.get("artifact_count"), bool) - or not isinstance(raw.get("artifact_count"), int) - or int(raw["artifact_count"]) < 0 - or not isinstance(raw.get("artifacts_sha256"), str) - or _SHA256_RE.fullmatch(str(raw["artifacts_sha256"])) is None - ): - raise MeasurementLineageError( - "measurement-lineage attempt inventory identity is invalid" - ) - inventory_keys.append((cell_id, attempt_id)) - if inventory_keys != sorted(set(inventory_keys)): - raise MeasurementLineageError( - "measurement-lineage attempt inventory is not sorted and unique" - ) - reachability = payload.get("reachability_certificate") - if ( - not isinstance(reachability, Mapping) - or not isinstance(reachability.get("sha256"), str) - or reachability.get("sha256") - != _digest( - { - key: value - for key, value in reachability.items() - if key != "sha256" - } - ) - or payload.get("reachability_certificate_sha256") - != _digest(reachability) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence reachability certificate is invalid" - ) - assert isinstance(reachability, Mapping) - if payload.get("impact") == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - _validate_summary_cap_certificate(reachability) - return - if ( - reachability.get("algorithm") - != "authenticated-recurrence-active-executor-reachability-v1" - or reachability.get("target_contract_ids") != sorted(_HZZ_CONTRACT_IDS) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence reachability certificate is invalid" - ) - records = reachability.get("records") - reached_ids = reachability.get("reached_cell_ids") - existing_target_ids = reachability.get("existing_catalog_target_ids") - invalidated_failure_ids = reachability.get( - "invalidated_validation_failed_current_ids" - ) - if ( - not isinstance(records, list) - or not isinstance(reached_ids, list) - or not isinstance(existing_target_ids, list) - or not isinstance(invalidated_failure_ids, list) - or reachability.get("inspected_current_count") != len(records) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence reachability inventory is malformed" - ) - record_ids: list[str] = [] - derived_reached: list[str] = [] - for record in records: - if not isinstance(record, dict) or set(record) != _REACHABILITY_RECORD_KEYS: - raise MeasurementLineageError( - "measurement-lineage recurrence reachability record is malformed" - ) - _validate_artifact_owner(record) - cell_id = record.get("cell_id") - attempt_id = record.get("attempt_id") - try: - canonical_attempt = ( - str(uuid.UUID(attempt_id)) - if isinstance(attempt_id, str) - else None - ) - except ValueError: - canonical_attempt = None - safe_paths = ( - record.get("artifact_locator"), - record.get("execution_manifest_path"), - record.get("schedule_path"), - record.get("process_binding_path"), - record.get("kernel_pack_path"), - ) - digest_fields = ( - "manifest_sha256", - "execution_manifest_sha256", - "schedule_sha256", - "schedule_index_sha256", - "schedule_member_sha256", - "process_binding_sha256", - "kernel_pack_sha256", - "semantic_catalog_sha256", - "direct_catalog_sha256", - ) - executor_ids = record.get("active_executor_ids") - templates = record.get("matched_template_ids") - contracts = record.get("matched_contract_ids") - if ( - not isinstance(cell_id, str) - or not cell_id - or canonical_attempt != attempt_id - or not isinstance(record.get("process_id"), str) - or not record["process_id"] - or any( - not isinstance(value, str) - or not value - or Path(value).is_absolute() - or any( - part in {"", ".", ".."} for part in Path(value).parts - ) - for value in safe_paths - ) - or any( - not isinstance(record.get(field), str) - or _SHA256_RE.fullmatch(str(record[field])) is None - for field in digest_fields - ) - or not isinstance(executor_ids, list) - or executor_ids != sorted(set(executor_ids)) - or any( - isinstance(value, bool) or not isinstance(value, int) or value < 0 - for value in executor_ids - ) - or not isinstance(templates, list) - or templates != sorted(set(templates)) - or any(not isinstance(value, str) or not value for value in templates) - or not isinstance(contracts, list) - or contracts != sorted(set(contracts)) - or any(value not in _HZZ_CONTRACT_IDS for value in contracts) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence reachability record is invalid" - ) - record_ids.append(cell_id) - if contracts: - derived_reached.append(cell_id) - if ( - record_ids != sorted(set(record_ids)) - or reached_ids != sorted(derived_reached) - or existing_target_ids != sorted(set(existing_target_ids)) - or invalidated_failure_ids - != sorted(set(invalidated_failure_ids)) - or any( - not isinstance(value, str) or value not in set(record_ids) - for value in existing_target_ids - ) - or any( - not isinstance(value, str) or not value - for value in invalidated_failure_ids - ) - or set(invalidated_failure_ids) & set(record_ids) - ): - raise MeasurementLineageError( - "measurement-lineage recurrence reachability sets are inconsistent" - ) - - -def _load_envelope(path: Path, *, expected_state: str | None = None) -> dict[str, Any]: - raw = _read_canonical_json(path, context="measurement-lineage envelope") - if ( - not isinstance(raw, dict) - or set(raw) != {"schema", "payload", "payload_sha256"} - or raw.get("schema") != MEASUREMENT_LINEAGE_WRAPPER_SCHEMA - or not isinstance(raw.get("payload"), dict) - or not isinstance(raw.get("payload_sha256"), str) - or raw["payload_sha256"] != _digest(raw["payload"]) - ): - raise MeasurementLineageError( - "measurement-lineage envelope or canonical digest is invalid" - ) - payload = dict(raw["payload"]) - if payload.get("schema") != MEASUREMENT_LINEAGE_SCHEMA: - raise MeasurementLineageError("measurement-lineage schema is incompatible") - _validate_payload_shape(payload) - if expected_state is not None and payload.get("state") != expected_state: - raise MeasurementLineageError( - f"measurement lineage is not in state {expected_state!r}" - ) - return payload - - -def _git( - repo_root: Path, - *arguments: str, - check: bool = True, -) -> subprocess.CompletedProcess[bytes]: - try: - completed = subprocess.run( - ("git", *arguments), - cwd=repo_root, - check=False, - capture_output=True, - timeout=30, - ) - except (OSError, subprocess.SubprocessError) as error: - raise MeasurementLineageError(f"cannot inspect Git lineage: {error}") from error - if check and completed.returncode != 0: - detail = completed.stderr.decode("utf-8", errors="replace").strip() - raise MeasurementLineageError( - f"git {' '.join(arguments)} failed: " - f"{detail or f'exit {completed.returncode}'}" - ) - return completed - - -def _git_commit(repo_root: Path, revision: str) -> str: - value = ( - _git(repo_root, "rev-parse", "--verify", f"{revision}^{{commit}}") - .stdout.decode("ascii") - .strip() - ) - if _GIT_SHA_RE.fullmatch(value) is None: - raise MeasurementLineageError("Git returned an invalid commit identity") - return value - - -def _git_tree(repo_root: Path, revision: str) -> str: - value = ( - _git(repo_root, "rev-parse", "--verify", f"{revision}^{{tree}}") - .stdout.decode("ascii") - .strip() - ) - if _GIT_SHA_RE.fullmatch(value) is None: - raise MeasurementLineageError("Git returned an invalid tree identity") - return value - - -def _tree_member( - repo_root: Path, - revision: str, - path: str, -) -> dict[str, str] | None: - raw = _git(repo_root, "ls-tree", "-z", revision, "--", path).stdout - if not raw: - return None - record = raw.split(b"\0", 1)[0] - header, separator, recorded_path = record.partition(b"\t") - fields = header.split() - if ( - not separator - or os.fsdecode(recorded_path) != path - or len(fields) != 3 - or fields[1] != b"blob" - ): - raise MeasurementLineageError(f"Git tree metadata is malformed for {path!r}") - return { - "mode": fields[0].decode("ascii"), - "object": fields[2].decode("ascii"), - } - - -def _blob_sha256(repo_root: Path, revision: str, path: str) -> str | None: - member = _tree_member(repo_root, revision, path) - if member is None: - return None - return hashlib.sha256( - _git(repo_root, "show", f"{revision}:{path}").stdout - ).hexdigest() - - -def _diff_records( - repo_root: Path, - *, - ancestor: str, - descendant: str, - impact: str, -) -> tuple[dict[str, object], ...]: - if impact == CLASS_C_HZZ_IMPACT: - allowed_paths = _HZZ_ALLOWED_PATHS - required_paths = _HZZ_REQUIRED_FEATURE_PATHS - impact_label = "HZZ" - elif impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - allowed_paths = _RECURRENCE_SUMMARY_CAP_ALLOWED_PATHS - required_paths = _RECURRENCE_SUMMARY_CAP_REQUIRED_PATHS - impact_label = "recurrence-summary-cap" - else: - raise MeasurementLineageError(f"unsupported Class-C impact {impact!r}") - ancestry = _git( - repo_root, - "merge-base", - "--is-ancestor", - ancestor, - descendant, - check=False, - ) - if ancestry.returncode != 0: - raise MeasurementLineageError( - "Class-C descendant is not a direct Git descendant of its ancestor" - ) - tokens = [ - os.fsdecode(value) - for value in _git( - repo_root, - "diff", - "--name-status", - "-z", - "--no-renames", - f"{ancestor}..{descendant}", - "--", - ).stdout.split(b"\0") - if value - ] - if len(tokens) % 2: - raise MeasurementLineageError("Git returned a malformed Class-C diff") - records: list[dict[str, object]] = [] - for offset in range(0, len(tokens), 2): - status, path = tokens[offset : offset + 2] - if status not in {"A", "M"}: - raise MeasurementLineageError( - f"Class-C diff contains unsupported status {status!r} for {path!r}" - ) - if path not in allowed_paths: - raise MeasurementLineageError( - f"Class-C {impact_label} descendant changes disallowed path {path!r}" - ) - old = _tree_member(repo_root, ancestor, path) - new = _tree_member(repo_root, descendant, path) - if new is None or new["mode"] != "100644": - raise MeasurementLineageError( - f"Class-C descendant member is not a regular 0644 file: {path!r}" - ) - if old is not None and old["mode"] != "100644": - raise MeasurementLineageError( - f"Class-C ancestor member is not a regular 0644 file: {path!r}" - ) - records.append( - { - "status": status, - "path": path, - "ancestor_blob": None if old is None else old["object"], - "ancestor_sha256": _blob_sha256(repo_root, ancestor, path), - "descendant_blob": new["object"], - "descendant_sha256": _blob_sha256(repo_root, descendant, path), - "mode": new["mode"], - } - ) - if not records: - raise MeasurementLineageError("Class-C descendant has an empty Git diff") - changed = {str(record["path"]) for record in records} - if not required_paths.issubset(changed): - missing = sorted(required_paths - changed) - raise MeasurementLineageError( - f"{impact_label} Class-C descendant lacks reviewed members: " - + ", ".join(missing) - ) - return tuple(records) - - -def _cell_record( - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, object]: - return { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process": cell.process, - "process_key": cell.process_key, - "n_final": cell.n_final, - "mode": cell.measurement.execution_mode.value, - "model": ( - None if cell.measurement.model is None else cell.measurement.model.value - ), - "accuracy": cell.measurement.accuracy.value, - "backend": cell.measurement.backend, - "jit_optimization_level": cell.measurement.jit_optimization_level, - "workload": cell.workload.value, - "variant": cell.variant, - "static_na_reason": catalog.static_na_reason(cell), - } - - -def hzz_impacted_cells( - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the exact built-in recurrence cells affected by the HZZ fix.""" - - cells = tuple( - sorted( - ( - cell - for cell in catalog.measurement_cells() - if ( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.BUILTIN_SM - and cell.process_key == "dd_zzz_jets" - and cell.n_final >= 3 - ) - ), - key=lambda item: item.cell_id, - ) - ) - if catalog is REPORT_CATALOG and len(cells) != 20: - raise MeasurementLineageError( - f"canonical HZZ impact census changed from 20 to {len(cells)} cells" - ) - return cells - - -def hzz_agreement_closure( - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return every direct-agreement consumer of an affected HZZ cell.""" - - impacted = hzz_impacted_cells(catalog=catalog) - impacted_ids = {cell.cell_id for cell in impacted} - impacted_keys = { - ( - cell.process, - cell.process_key, - cell.n_final, - cell.measurement.accuracy, - cell.workload, - ) - for cell in impacted - } - peers = tuple( - sorted( - ( - cell - for cell in catalog.measurement_cells() - if ( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and cell.measurement.model is ModelKey.UFO_SM - and ( - cell.process, - cell.process_key, - cell.n_final, - cell.measurement.accuracy, - cell.workload, - ) - in impacted_keys - and any( - edge.baseline.cell_id in impacted_ids - for edge in incoming_agreement_edges( - cell, - catalog=catalog, - ) - ) - ) - ), - key=lambda item: item.cell_id, - ) - ) - if catalog is REPORT_CATALOG and ( - len(peers) != 20 - or any( - cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or cell.measurement.model is not ModelKey.UFO_SM - or cell.process_key != "dd_zzz_jets" - for cell in peers - ) - ): - raise MeasurementLineageError( - "canonical HZZ direct-agreement closure is no longer the 20 UFO " - "recurrence peers" - ) - return peers - - -def recurrence_summary_cap_impacted_cells( - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the four currents blocked by the old recurrence summary cap.""" - - by_id = {cell.cell_id: cell for cell in catalog.measurement_cells()} - missing = sorted(set(_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES) - set(by_id)) - if missing: - raise MeasurementLineageError( - "recurrence summary-cap targets are absent from the catalog: " - + ", ".join(missing) - ) - cells = tuple( - by_id[cell_id] - for cell_id in sorted(_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES) - ) - if any( - cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or cell.measurement.model is not ModelKey.BUILTIN_SM - or cell.measurement.accuracy is not Accuracy.LC - or cell.workload is not Workload.SELECTED_FLOW - for cell in cells - ): - raise MeasurementLineageError( - "recurrence summary-cap target semantics changed in the catalog" - ) - return cells - - -def recurrence_summary_cap_agreement_closure( - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the exact-equivalent and dependent peers of the four targets.""" - - closure = _agreement_consumer_closure( - { - cell.cell_id - for cell in recurrence_summary_cap_impacted_cells(catalog=catalog) - }, - catalog=catalog, - ) - if catalog is REPORT_CATALOG and { - cell.cell_id for cell in closure - } != _RECURRENCE_SUMMARY_CAP_AGREEMENT_IDS: - raise MeasurementLineageError( - "canonical recurrence summary-cap agreement closure changed from " - "its reviewed 12-cell census" - ) - return closure - - -def signed_zero_helicity_impacted_cells( - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the 24 cells directly blocked by legacy unsigned zero.""" - - by_id = {cell.cell_id: cell for cell in catalog.measurement_cells()} - missing = sorted(_SIGNED_ZERO_HELICITY_IMPACTED_IDS - set(by_id)) - if missing: - raise MeasurementLineageError( - "signed-zero helicity targets are absent from the catalog: " - + ", ".join(missing) - ) - cells = tuple( - by_id[cell_id] - for cell_id in sorted(_SIGNED_ZERO_HELICITY_IMPACTED_IDS) - ) - if any( - cell.measurement.accuracy is not Accuracy.LC - or cell.workload not in {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - or cell.process_key not in {"dd_epemzh_jets", "dd_ttzh_jets"} - or cell.n_final not in range(4, 8) - or ( - cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and cell.measurement.model is not None - ) - or ( - cell.measurement.execution_mode is ExecutionMode.RECURRENCE - and ( - cell.measurement.model is not ModelKey.BUILTIN_SM - or cell.workload is not Workload.SELECTED_FLOW - ) - ) - or cell.measurement.execution_mode - not in {ExecutionMode.AMPLICOL, ExecutionMode.RECURRENCE} - for cell in cells - ): - raise MeasurementLineageError( - "signed-zero helicity target semantics changed in the catalog" - ) - return cells - - -def signed_zero_helicity_agreement_closure( - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - """Return the exact 42-cell dependent closure of the signed-zero targets.""" - - closure = _agreement_consumer_closure( - { - cell.cell_id - for cell in signed_zero_helicity_impacted_cells(catalog=catalog) - }, - catalog=catalog, - ) - if catalog is REPORT_CATALOG and { - cell.cell_id for cell in closure - } != _SIGNED_ZERO_HELICITY_AGREEMENT_IDS: - raise MeasurementLineageError( - "canonical signed-zero agreement closure changed from its reviewed " - "42-cell census" - ) - return closure - - -def _agreement_consumer_closure( - affected_cell_ids: set[str], - *, - catalog: ReportCatalog, -) -> tuple[CellSpec, ...]: - """Return the transitive incoming-agreement closure of ``affected_cell_ids``.""" - - affected = set(affected_cell_ids) - consumers: dict[str, CellSpec] = {} - changed = True - while changed: - changed = False - for cell in catalog.measurement_cells(): - if cell.cell_id in affected: - continue - if any( - edge.baseline.cell_id in affected - for edge in incoming_agreement_edges(cell, catalog=catalog) - ): - affected.add(cell.cell_id) - consumers[cell.cell_id] = cell - changed = True - return tuple( - sorted(consumers.values(), key=lambda item: item.cell_id) - ) - - -def _impact_and_agreement_cells( - impact: str, - reachability: Mapping[str, object], - *, - catalog: ReportCatalog, -) -> tuple[tuple[CellSpec, ...], tuple[CellSpec, ...]]: - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - impacted = { - cell.cell_id: cell - for cell in ( - *recurrence_summary_cap_impacted_cells(catalog=catalog), - *signed_zero_helicity_impacted_cells(catalog=catalog), - ) - } - return ( - tuple(sorted(impacted.values(), key=lambda item: item.cell_id)), - _agreement_consumer_closure(set(impacted), catalog=catalog), - ) - if impact != CLASS_C_HZZ_IMPACT: - raise MeasurementLineageError(f"unsupported Class-C impact {impact!r}") - by_id = {cell.cell_id: cell for cell in catalog.measurement_cells()} - raw_reached = reachability.get("reached_cell_ids") - if not isinstance(raw_reached, list) or any( - not isinstance(value, str) or value not in by_id for value in raw_reached - ): - raise MeasurementLineageError( - "reachability certificate has unknown reached cells" - ) - affected_by_id = { - cell.cell_id: cell for cell in hzz_impacted_cells(catalog=catalog) - } - affected_by_id.update({cell_id: by_id[cell_id] for cell_id in raw_reached}) - affected = tuple( - sorted(affected_by_id.values(), key=lambda item: item.cell_id) - ) - closure = _agreement_consumer_closure( - set(affected_by_id), - catalog=catalog, - ) - return affected, closure - - -def _catalog_digest(catalog: ReportCatalog) -> str: - global _CANONICAL_CATALOG_SHA256 - if catalog is REPORT_CATALOG and _CANONICAL_CATALOG_SHA256 is not None: - return _CANONICAL_CATALOG_SHA256 - result = _digest( - [ - _cell_record(cell, catalog=catalog) - for cell in catalog.measurement_cells() - ] - ) - if catalog is REPORT_CATALOG: - _CANONICAL_CATALOG_SHA256 = result - return result - - -def _agreement_digest(catalog: ReportCatalog) -> str: - global _CANONICAL_AGREEMENT_SHA256 - if catalog is REPORT_CATALOG and _CANONICAL_AGREEMENT_SHA256 is not None: - return _CANONICAL_AGREEMENT_SHA256 - edges: list[dict[str, str]] = [] - for cell in catalog.measurement_cells(): - for edge in incoming_agreement_edges(cell, catalog=catalog): - edges.append( - { - "candidate": cell.cell_id, - "baseline": edge.baseline.cell_id, - "kind": edge.kind, - } - ) - result = _digest(sorted(edges, key=lambda item: tuple(item.values()))) - if catalog is REPORT_CATALOG: - _CANONICAL_AGREEMENT_SHA256 = result - return result - - -def _agreement_graph_digest_matches( - payload: Mapping[str, object], - active_digest: str, -) -> bool: - """Authenticate the one controller-era agreement-graph transition. - - Arbitrary-quark-line report support removed obsolete original-AmpliCol - dependency edges for process #14 without changing either frozen bridge's - measurement cells or physics closure. Pending/finalized certificates from - before that controller-only correction retain their original graph digest. - Both digests and both exact EPYC lineages are pinned; every other graph - change remains fatal. - """ - - stored_digest = payload.get("agreement_graph_sha256") - if stored_digest == active_digest: - return True - if ( - payload.get("profile") != _RECURRENCE_SUMMARY_CAP_PROFILE - or stored_digest - != _PRE_ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256 - or active_digest != _ARBITRARY_QUARK_LINES_AGREEMENT_GRAPH_SHA256 - ): - return False - identity = ( - payload.get("impact"), - payload.get("ancestor_revision"), - payload.get("descendant_revision"), - ) - return identity in { - ( - CLASS_C_HZZ_IMPACT, - _RECURRENCE_SUMMARY_CAP_PREDECESSOR_REVISION, - _RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION, - ), - ( - CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT, - _RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION, - _RECURRENCE_SUMMARY_CAP_DESCENDANT_REVISION, - ), - } - - -def _environment(path: Path, *, expected_profile: str) -> dict[str, str]: - try: - raw = json.loads(path.read_text(encoding="ascii")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise MeasurementLineageError( - f"cannot read profile environment {path}: {error}" - ) from error - if ( - not isinstance(raw, dict) - or set(raw) != _ENVIRONMENT_KEYS - or raw.get("profile") != expected_profile - or raw.get("status") != "authenticated" - or not all(isinstance(value, str) for value in raw.values()) - ): - raise MeasurementLineageError( - "profile environment is not an authenticated string mapping" - ) - return dict(raw) - - -def _profile_name(repo_root: Path, docs_dir: Path) -> str: - try: - relative = docs_dir.resolve(strict=False).relative_to( - (repo_root / _PROFILE_ROOT).resolve(strict=False) - ) - except ValueError as error: - raise MeasurementLineageError( - "Class-C bridges require an architecture-specific report profile" - ) from error - if len(relative.parts) != 1 or relative.parts[0] in {".", ".."}: - raise MeasurementLineageError( - "Class-C report profile path is not one safe component" - ) - return relative.parts[0] - - -def measurement_lineage_path(repo_root: Path, docs_dir: Path) -> Path: - _profile_name(repo_root, docs_dir) - return docs_dir / MEASUREMENT_LINEAGE_FILENAME - - -def class_c_pending_path( - store: ArtifactStore, - *, - ancestor_revision: str, - descendant_revision: str, -) -> Path: - """Return the only permitted pending-bridge locator for an A→D pair.""" - - if ( - _GIT_SHA_RE.fullmatch(ancestor_revision) is None - or _GIT_SHA_RE.fullmatch(descendant_revision) is None - ): - raise MeasurementLineageError( - "pending Class-C bridge identities must be full Git object IDs" - ) - return ( - store.artifact_root - / "source-bridges" - / f"{ancestor_revision}-{descendant_revision}.pending.json" - ) - - -def _validated_pending_path(store: ArtifactStore, path: Path) -> Path: - candidate = path.expanduser().absolute() - root = (store.artifact_root / "source-bridges").absolute() - if ( - candidate.parent != root - or root.is_symlink() - or not root.is_dir() - or candidate.is_symlink() - or not candidate.is_file() - ): - raise MeasurementLineageError( - "pending Class-C bridge is not a regular canonical artifact-root member" - ) - try: - candidate.resolve(strict=True).relative_to( - store.artifact_root.resolve(strict=True) - ) - except (OSError, ValueError) as error: - raise MeasurementLineageError( - "pending Class-C bridge escapes the profile artifact root" - ) from error - return candidate - - -def _current_pin( - record: CurrentRecord, - *, - source_epoch_fallback: tuple[str, str] | None = None, -) -> dict[str, object]: - provenance = record.result.get("provenance") - if not isinstance(provenance, Mapping) and source_epoch_fallback is None: - raise MeasurementLineageError( - f"current {record.cell_id!r} has no source provenance" - ) - if isinstance(provenance, Mapping): - revision = provenance.get("report_source_revision") - tree = provenance.get("report_source_tree") - valid = ( - isinstance(revision, str) - and _GIT_SHA_RE.fullmatch(revision) is not None - and isinstance(tree, str) - and _GIT_SHA_RE.fullmatch(tree) is not None - and provenance.get("report_measured_source_revision") == revision - and provenance.get("report_measured_source_tree") == tree - ) - else: - revision, tree = source_epoch_fallback # type: ignore[misc] - valid = ( - _GIT_SHA_RE.fullmatch(revision) is not None - and _GIT_SHA_RE.fullmatch(tree) is not None - ) - if not valid: - raise MeasurementLineageError( - f"current {record.cell_id!r} has invalid source provenance" - ) - pointer = _current_pointer_identity(record) - return { - "cell_id": record.cell_id, - "attempt_id": record.attempt_id, - "manifest_sha256": record.manifest_sha256, - **pointer, - "source_revision": revision, - "source_tree": tree, - "result_sha256": _file_digest(record.result_path), - } - - -def _current_pointer_identity(record: CurrentRecord) -> dict[str, str]: - current_path = record.manifest_path.parent.parent.parent / "current.json" - return { - "current_locator": current_path.relative_to( - record.manifest_path.parents[4] - ).as_posix(), - "current_pointer_sha256": _file_digest(current_path), - } - - -def _artifact_canonical_bytes(value: object) -> bytes: - try: - encoded = json.dumps( - value, - allow_nan=False, - ensure_ascii=False, - separators=(",", ":"), - sort_keys=True, - ) - except (TypeError, ValueError) as error: - raise MeasurementLineageError( - f"attempt manifest is not canonical JSON: {error}" - ) from error - return f"{encoded}\n".encode() - - -def _read_attempt_manifest(path: Path) -> dict[str, object]: - if path.is_symlink() or not path.is_file(): - raise MeasurementLineageError(f"attempt has no regular manifest: {path.parent}") - try: - data = path.read_bytes() - raw = json.loads( - data.decode("utf-8"), - object_pairs_hook=_reject_duplicate_pairs, - ) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise MeasurementLineageError( - f"cannot read attempt manifest {path}: {error}" - ) from error - if not isinstance(raw, dict) or data != _artifact_canonical_bytes(raw): - raise MeasurementLineageError( - f"attempt manifest is not canonical JSON: {path}" - ) - return raw - - -def _attempt_member( - attempt_root: Path, - relative: object, - *, - context: str, -) -> tuple[str, Path]: - if ( - not isinstance(relative, str) - or not relative - or Path(relative).is_absolute() - or any(part in {"", ".", ".."} for part in Path(relative).parts) - ): - raise MeasurementLineageError(f"{context} is not a safe relative path") - candidate = attempt_root.joinpath(*Path(relative).parts) - try: - resolved = candidate.resolve(strict=True) - resolved.relative_to(attempt_root.resolve(strict=True)) - except (OSError, ValueError) as error: - raise MeasurementLineageError( - f"{context} is unavailable or escapes its attempt" - ) from error - if candidate.is_symlink() or not resolved.is_file(): - raise MeasurementLineageError(f"{context} is not a regular file") - return Path(relative).as_posix(), resolved - - -def _validated_attempt_inventory_row( - store: ArtifactStore, - path: Path, - *, - expected_cell_id: str, -) -> dict[str, object]: - raw = _read_attempt_manifest(path) - attempt_id = path.parent.name - try: - parsed = uuid.UUID(attempt_id) - except ValueError as error: - raise MeasurementLineageError( - f"attempt directory is not a UUID: {path.parent}" - ) from error - if ( - str(parsed) != attempt_id - or set(raw) != _ATTEMPT_KEYS - or raw.get("schema") != ATTEMPT_SCHEMA - or raw.get("cell_id") != expected_cell_id - or raw.get("attempt_id") != attempt_id - ): - raise MeasurementLineageError( - f"attempt manifest identity or schema is invalid: {path}" - ) - try: - ArtifactPolicy(raw.get("artifact_policy")) - except (TypeError, ValueError) as error: - raise MeasurementLineageError( - f"attempt manifest has an invalid artifact policy: {path}" - ) from error - based_on = raw.get("based_on") - if based_on is not None: - if ( - not isinstance(based_on, dict) - or set(based_on) != {"attempt_id", "manifest_sha256"} - or not isinstance(based_on.get("attempt_id"), str) - or not isinstance(based_on.get("manifest_sha256"), str) - or _SHA256_RE.fullmatch(str(based_on["manifest_sha256"])) is None - ): - raise MeasurementLineageError( - f"attempt manifest has an invalid based_on identity: {path}" - ) - try: - if str(uuid.UUID(str(based_on["attempt_id"]))) != based_on["attempt_id"]: - raise ValueError - except ValueError as error: - raise MeasurementLineageError( - f"attempt manifest has an invalid based_on UUID: {path}" - ) from error - - status = raw.get("status") - error = raw.get("error") - result_path = raw.get("result_path") - if status == "ok": - if error is not None or result_path is None: - raise MeasurementLineageError( - f"successful attempt has inconsistent result/error fields: {path}" - ) - elif status in {"failed", "interrupted"}: - if not isinstance(error, str) or not error or result_path is not None: - raise MeasurementLineageError( - f"unsuccessful attempt has inconsistent result/error fields: {path}" - ) - else: - raise MeasurementLineageError( - f"attempt manifest has an unsupported status: {path}" - ) - - raw_artifacts = raw.get("artifacts") - if not isinstance(raw_artifacts, list): - raise MeasurementLineageError( - f"attempt manifest artifacts are not an array: {path}" - ) - records: list[dict[str, object]] = [] - seen: set[str] = set() - for index, item in enumerate(raw_artifacts): - if not isinstance(item, dict) or set(item) != {"path", "size", "sha256"}: - raise MeasurementLineageError( - f"attempt artifact {index} has an invalid schema: {path}" - ) - relative, member = _attempt_member( - path.parent, - item.get("path"), - context=f"attempt artifact {index}", - ) - size = item.get("size") - sha256 = item.get("sha256") - if ( - relative in seen - or isinstance(size, bool) - or not isinstance(size, int) - or size < 0 - or member.stat().st_size != size - or not isinstance(sha256, str) - or _SHA256_RE.fullmatch(sha256) is None - or _file_digest(member) != sha256 - ): - raise MeasurementLineageError( - f"attempt artifact {index} differs from its manifest: {path}" - ) - seen.add(relative) - records.append({"path": relative, "size": size, "sha256": sha256}) - if records != sorted(records, key=lambda item: str(item["path"])): - raise MeasurementLineageError( - f"attempt artifact records are not canonically sorted: {path}" - ) - if status == "ok" and (not records or result_path not in seen): - raise MeasurementLineageError( - f"successful attempt result is not an authenticated artifact: {path}" - ) - observed_files: set[str] = set() - for member in path.parent.rglob("*"): - if member.is_symlink(): - raise MeasurementLineageError( - f"attempt contains a symbolic link: {member}" - ) - if member.is_file(): - observed_files.add(member.relative_to(path.parent).as_posix()) - if observed_files != seen | {"manifest.json"}: - raise MeasurementLineageError( - f"attempt contains untracked or missing artifact members: {path}" - ) - result_sha256: str | None = None - if result_path is not None: - _relative, result_file = _attempt_member( - path.parent, - result_path, - context="attempt result", - ) - result_sha256 = _file_digest(result_file) - return { - "cell_id": expected_cell_id, - "attempt_id": attempt_id, - "manifest_locator": path.relative_to(store.artifact_root).as_posix(), - "manifest_sha256": _file_digest(path), - "status": status, - "error_sha256": _digest(error), - "result_path": result_path, - "result_sha256": result_sha256, - "artifact_count": len(records), - "artifacts_sha256": _digest(records), - } - - -def _attempt_inventory( - store: ArtifactStore, - *, - catalog: ReportCatalog, -) -> tuple[tuple[dict[str, object], ...], tuple[str, ...]]: - """Snapshot every catalog attempt, including failed and orphan attempts.""" - - catalog_cells = tuple(catalog.measurement_cells()) - catalog_ids = {cell.cell_id for cell in catalog_cells} - roots = {store._cell_root(cell_id): cell_id for cell_id in catalog_ids} - if store.cells_root.is_symlink() or not store.cells_root.is_dir(): - raise MeasurementLineageError( - f"artifact cells root is not a regular directory: {store.cells_root}" - ) - for path in store.cells_root.iterdir(): - if path not in roots: - raise MeasurementLineageError( - f"artifact store contains an unknown catalog cell directory: {path}" - ) - if path.is_symlink() or not path.is_dir(): - raise MeasurementLineageError( - f"artifact cell root is not a regular directory: {path}" - ) - - inventory: list[dict[str, object]] = [] - no_attempts: list[str] = [] - for cell_id in sorted(catalog_ids): - cell_root = store._cell_root(cell_id) # same-package authenticated layout - attempts_root = cell_root / "attempts" - if attempts_root.exists() and ( - attempts_root.is_symlink() or not attempts_root.is_dir() - ): - raise MeasurementLineageError( - f"attempt root is not a regular directory: {attempts_root}" - ) - attempt_roots = ( - () - if not attempts_root.exists() - else tuple(sorted(attempts_root.iterdir())) - ) - manifests: list[Path] = [] - for attempt_root in attempt_roots: - if attempt_root.is_symlink() or not attempt_root.is_dir(): - raise MeasurementLineageError( - f"attempt entry is not a regular directory: {attempt_root}" - ) - manifest = attempt_root / "manifest.json" - if manifest.is_symlink() or not manifest.is_file(): - raise MeasurementLineageError( - f"attempt has no regular manifest: {attempt_root}" - ) - manifests.append(manifest) - if not manifests: - if store.load_current(cell_id, missing_ok=True) is not None: - raise MeasurementLineageError( - f"cell {cell_id!r} has a current pointer but no attempt manifest" - ) - no_attempts.append(cell_id) - continue - for path in manifests: - inventory.append( - _validated_attempt_inventory_row( - store, - path, - expected_cell_id=cell_id, - ) - ) - return ( - tuple( - sorted( - inventory, - key=lambda item: (item["cell_id"], item["attempt_id"]), - ) - ), - tuple(no_attempts), - ) - - -RecurrenceReachabilityInspector = Callable[ - [CurrentRecord, CellSpec], - Mapping[str, object], -] - - -def _runtime_identity_digest(value: Mapping[str, object]) -> str: - try: - encoded = json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - except (TypeError, ValueError) as error: - raise MeasurementLineageError( - f"runtime identity is not canonical JSON: {error}" - ) from error - return hashlib.sha256(encoded).hexdigest() - - -def _runtime_identity_evidence( - record: CurrentRecord, -) -> tuple[str, str]: - provenance = record.result.get("provenance") - identity = ( - provenance.get("runtime_identity") - if isinstance(provenance, Mapping) - else None - ) - if not isinstance(identity, Mapping): - raise MeasurementLineageError( - f"{record.cell_id}: current has no digest-covered runtime identity" - ) - identity_digest = _runtime_identity_digest(identity) - stable = dict(identity) - policy = stable.get("loaded_module_origin_policy") - if isinstance(policy, Mapping): - stable_policy = dict(policy) - for field in ( - "observed_module_count", - "observations", - "observations_sha256", - ): - stable_policy.pop(field, None) - stable["loaded_module_origin_policy"] = stable_policy - stable_digest = _runtime_identity_digest(stable) - if ( - provenance.get("runtime_identity_sha256") != identity_digest - or provenance.get("runtime_identity_stable_sha256") != stable_digest - or provenance.get("runtime_identity_postflight_stable_sha256") - != stable_digest - or provenance.get("runtime_identity_postflight_match") is not True - ): - raise MeasurementLineageError( - f"{record.cell_id}: runtime identity digest or postflight binding changed" - ) - return identity_digest, stable_digest - - -def _source_epoch(record: CurrentRecord) -> tuple[str, str]: - provenance = record.result.get("provenance") - revision = ( - provenance.get("report_source_revision") - if isinstance(provenance, Mapping) - else None - ) - tree = ( - provenance.get("report_source_tree") - if isinstance(provenance, Mapping) - else None - ) - if ( - not isinstance(revision, str) - or _GIT_SHA_RE.fullmatch(revision) is None - or not isinstance(tree, str) - or _GIT_SHA_RE.fullmatch(tree) is None - or provenance.get("report_measured_source_revision") != revision - or provenance.get("report_measured_source_tree") != tree - ): - raise MeasurementLineageError( - f"{record.cell_id}: current has no exact measured source epoch" - ) - return revision, tree - - -def _attempt_owner_evidence( - store: ArtifactStore, - record: CurrentRecord, -) -> tuple[dict[str, object], str]: - try: - record.manifest_path.resolve(strict=True).relative_to( - store.artifact_root.resolve(strict=True) - ) - except (OSError, ValueError) as error: - raise MeasurementLineageError( - f"{record.cell_id}: attempt is outside this profile artifact store" - ) from error - inventory = _validated_attempt_inventory_row( - store, - record.manifest_path, - expected_cell_id=record.cell_id, - ) - if ( - inventory.get("status") != "ok" - or inventory.get("attempt_id") != record.attempt_id - or inventory.get("manifest_sha256") != record.manifest_sha256 - or inventory.get("result_sha256") != _file_digest(record.result_path) - ): - raise MeasurementLineageError( - f"{record.cell_id}: attempt/result identity differs from its manifest" - ) - result_locator = record.result_path.relative_to( - store.artifact_root - ).as_posix() - return inventory, result_locator - - -def _resolve_recurrence_artifact_owner( - store: ArtifactStore, - catalog: ReportCatalog, - record: CurrentRecord, - cell: CellSpec, - artifact_root: Path, - process_id: str, -) -> dict[str, object]: - """Authenticate a direct artifact or one bounded matrix-peer reuse.""" - - consumer_inventory, consumer_result_locator = _attempt_owner_evidence( - store, - record, - ) - consumer_revision, consumer_tree = _source_epoch(record) - consumer_runtime, consumer_runtime_stable = _runtime_identity_evidence(record) - store_root = store.artifact_root.resolve(strict=True) - try: - artifact_locator = artifact_root.relative_to(store_root).as_posix() - except ValueError as error: - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact is outside this profile store" - ) from error - - consumer_attempt = record.manifest_path.parent.resolve(strict=True) - try: - artifact_root.relative_to(consumer_attempt) - except ValueError: - relation = "equivalent-matrix-peer" - else: - try: - expected_consumer_artifact = ( - consumer_attempt / "artifact" - ).resolve(strict=True) - except OSError as error: - raise MeasurementLineageError( - f"{cell.cell_id}: direct recurrence artifact is unavailable" - ) from error - if artifact_root != expected_consumer_artifact: - raise MeasurementLineageError( - f"{cell.cell_id}: direct recurrence artifact is not the canonical " - "attempt/artifact directory" - ) - relation = "consumer-attempt" - - owner = record - owner_current_locator: str | None = None - owner_current_sha256: str | None = None - if relation == "equivalent-matrix-peer": - peers = tuple( - peer - for peer in catalog.equivalent_cells(cell) - if peer.dataset_id.startswith("matrix_") - ) - if len(peers) != 1: - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact owner matrix peer is " - f"missing or ambiguous" - ) - try: - loaded = store.load_current(peers[0].cell_id, missing_ok=True) - except Exception as error: - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact owner current is invalid" - ) from error - if loaded is None: - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact owner current is missing" - ) - owner = loaded - owner_artifact = owner.result.get("artifact") - owner_raw_path = ( - owner_artifact.get("path") - if isinstance(owner_artifact, Mapping) - else None - ) - owner_process_id = ( - owner_artifact.get("process_id") - if isinstance(owner_artifact, Mapping) - else None - ) - if ( - not isinstance(owner_raw_path, str) - or not owner_raw_path - or "${" in owner_raw_path - or owner_process_id != process_id - ): - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact owner result is malformed" - ) - try: - owner_artifact_root = Path(owner_raw_path).expanduser().resolve( - strict=True - ) - expected_owner_artifact = ( - owner.manifest_path.parent.resolve(strict=True) / "artifact" - ).resolve(strict=True) - except (OSError, ValueError) as error: - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact owner chains to another attempt" - ) from error - if ( - Path(owner_raw_path).expanduser().is_symlink() - or not owner_artifact_root.is_dir() - or owner_artifact_root != expected_owner_artifact - or owner_artifact_root != artifact_root - ): - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact is not owned by its matrix peer" - ) - owner_pin = _current_pin(owner) - owner_current_locator = str(owner_pin["current_locator"]) - owner_current_sha256 = str(owner_pin["current_pointer_sha256"]) - - owner_inventory, owner_result_locator = _attempt_owner_evidence(store, owner) - owner_revision, owner_tree = _source_epoch(owner) - owner_runtime, owner_runtime_stable = _runtime_identity_evidence(owner) - if ( - (owner_revision, owner_tree) != (consumer_revision, consumer_tree) - or owner_runtime_stable != consumer_runtime_stable - ): - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact owner belongs to another " - "source/runtime epoch" - ) - - return { - "relation": relation, - "artifact_locator": artifact_locator, - "consumer_cell_id": record.cell_id, - "consumer_attempt_id": record.attempt_id, - "consumer_manifest_locator": consumer_inventory["manifest_locator"], - "consumer_manifest_sha256": record.manifest_sha256, - "consumer_result_locator": consumer_result_locator, - "consumer_result_sha256": consumer_inventory["result_sha256"], - "consumer_source_revision": consumer_revision, - "consumer_source_tree": consumer_tree, - "consumer_runtime_identity_sha256": consumer_runtime, - "consumer_runtime_identity_stable_sha256": consumer_runtime_stable, - "owner_cell_id": owner.cell_id, - "owner_attempt_id": owner.attempt_id, - "owner_current_locator": owner_current_locator, - "owner_current_sha256": owner_current_sha256, - "owner_manifest_locator": owner_inventory["manifest_locator"], - "owner_manifest_sha256": owner.manifest_sha256, - "owner_result_locator": owner_result_locator, - "owner_result_sha256": owner_inventory["result_sha256"], - "owner_artifacts_sha256": owner_inventory["artifacts_sha256"], - "owner_source_revision": owner_revision, - "owner_source_tree": owner_tree, - "owner_runtime_identity_sha256": owner_runtime, - "owner_runtime_identity_stable_sha256": owner_runtime_stable, - } - - -def _artifact_member(root: Path, relative: object, *, context: str) -> Path: - if ( - not isinstance(relative, str) - or not relative - or Path(relative).is_absolute() - or any(part in {"", ".", ".."} for part in Path(relative).parts) - ): - raise MeasurementLineageError(f"{context} is not a safe artifact member") - candidate = root.joinpath(*Path(relative).parts) - try: - resolved = candidate.resolve(strict=True) - resolved.relative_to(root.resolve(strict=True)) - except (OSError, ValueError) as error: - raise MeasurementLineageError( - f"{context} is unavailable or escapes its artifact" - ) from error - if candidate.is_symlink() or not resolved.is_file(): - raise MeasurementLineageError(f"{context} is not a regular file") - return resolved - - -def _validate_numerical_validation_failure( - record: CurrentRecord, - cell: CellSpec, -) -> None: - """Validate one completed pointwise failure selected for replacement.""" - - validation = record.result.get("validation") - failure = record.result.get("failure") - artifact = record.result.get("artifact") - provenance = record.result.get("provenance") - try: - validate_measurement(record.result, expected_cell=cell) - except ValueError as error: - raise MeasurementLineageError( - f"{record.cell_id}: closure failure measurement schema is invalid" - ) from error - if ( - record.result.get("status") != ResultStatus.VALIDATION_FAILED.value - or not isinstance(validation, Mapping) - or validation.get("status") - != ResultStatus.VALIDATION_FAILED.value - or not isinstance(failure, Mapping) - or set(failure) != {"kind", "message"} - or failure.get("kind") != "MeasurementValidationError" - or failure.get("message") - != "candidate or same-artifact numerical validation failed" - or not isinstance(artifact, Mapping) - or set(artifact) != {"path", "process_id", "policy"} - or not isinstance(artifact.get("path"), str) - or not artifact["path"] - or not isinstance(artifact.get("process_id"), str) - or not artifact["process_id"] - or artifact.get("policy") != "generated" - or not isinstance(provenance, Mapping) - ): - raise MeasurementLineageError( - f"{record.cell_id}: closure current is not an authenticated " - "numerical-validation failure" - ) - - pointwise = validation.get("pointwise") - resolved_sum = validation.get("resolved_sum") - if not isinstance(pointwise, Mapping) or not isinstance(resolved_sum, Mapping): - raise MeasurementLineageError( - f"{record.cell_id}: closure failure lacks complete pointwise/resolved " - "validation evidence" - ) - try: - validate_conditioned_comparison_record( - pointwise, - require_binding="abi" in pointwise, - ) - validate_resolved_sum_validation_record(resolved_sum) - except ValueError as error: - raise MeasurementLineageError( - f"{record.cell_id}: closure validation evidence is inconsistent" - ) from error - matrix_element = record.result.get("matrix_element") - candidate = pointwise.get("candidate") - if ( - isinstance(candidate, bool) - or not isinstance(candidate, (int, float)) - or not math.isfinite(float(candidate)) - or float(candidate) < 0.0 - or ( - isinstance(matrix_element, bool) - or not isinstance(matrix_element, (int, float)) - or not math.isfinite(float(matrix_element)) - or float(matrix_element) < 0.0 - ) - ): - raise MeasurementLineageError( - f"{record.cell_id}: closure validation evidence is not finite and " - "nonnegative" - ) - if ( - float(matrix_element) != float(candidate) - or pointwise.get("status") != ResultStatus.VALIDATION_FAILED.value - or resolved_sum.get("status") != ResultStatus.OK.value - ): - raise MeasurementLineageError( - f"{record.cell_id}: closure validation evidence is numerically " - "inconsistent" - ) - - try: - artifact_root = Path(str(artifact["path"])).expanduser().resolve(strict=True) - expected_artifact_root = ( - record.manifest_path.parent / "artifact" - ).resolve(strict=True) - except OSError as error: - raise MeasurementLineageError( - f"{record.cell_id}: closure failure artifact is unavailable" - ) from error - if ( - Path(str(artifact["path"])).expanduser().is_symlink() - or not artifact_root.is_dir() - or artifact_root != expected_artifact_root - ): - raise MeasurementLineageError( - f"{record.cell_id}: closure failure artifact is not its canonical " - "attempt artifact" - ) - try: - _validate_runtime_identity_postflight(provenance, validation) - except ValueError as error: - raise MeasurementLineageError( - f"{record.cell_id}: closure failure runtime identity is invalid" - ) from error - _source_epoch(record) - _runtime_identity_evidence(record) - - -def _authenticate_replaceable_validation_failure( - store: ArtifactStore, - record: CurrentRecord, - cell: CellSpec, -) -> None: - """Authenticate one immutable current selected for replacement.""" - - _validate_numerical_validation_failure(record, cell) - _current_pin(record) - _attempt_owner_evidence(store, record) - - -def _default_recurrence_reachability( - record: CurrentRecord, - cell: CellSpec, - *, - store: ArtifactStore, - catalog: ReportCatalog, -) -> Mapping[str, object]: - """Authenticate one recurrence schedule and expose active model contracts.""" - - if ( - cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or cell.measurement.model is not ModelKey.BUILTIN_SM - ): - raise MeasurementLineageError( - "recurrence reachability received a non-built-in recurrence cell" - ) - artifact = record.result.get("artifact") - if not isinstance(artifact, Mapping): - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence result has no artifact record" - ) - raw_path = artifact.get("path") - process_id = artifact.get("process_id") - if ( - not isinstance(raw_path, str) - or not raw_path - or "${" in raw_path - or not isinstance(process_id, str) - or not process_id - ): - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact locator is invalid" - ) - try: - raw_artifact_root = Path(raw_path).expanduser() - artifact_root = raw_artifact_root.resolve(strict=True) - except OSError as error: - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact is unavailable" - ) from error - if raw_artifact_root.is_symlink() or not artifact_root.is_dir(): - raise MeasurementLineageError( - f"{cell.cell_id}: recurrence artifact is not a regular directory" - ) - artifact_owner = _resolve_recurrence_artifact_owner( - store, - catalog, - record, - cell, - artifact_root, - process_id, - ) - - try: - from pyamplicol.models.prepared import ( - EAGER_KERNEL_ABI, - PreparedKernelPack, - ) - from pyamplicol.runtime.recurrence_exact._plan_v2 import ( - DIRECT_NONE_U32, - _load_recurrence_exact_sections_v1, - ) - - from .final_audit import audit_artifact - - evidence = audit_artifact(cell, artifact_root, process_id) - execution_path = _artifact_member( - artifact_root, - evidence.execution_manifest_path, - context=f"{cell.cell_id} execution manifest", - ) - execution = json.loads(execution_path.read_text(encoding="utf-8")) - if not isinstance(execution, dict): - raise MeasurementLineageError( - "recurrence execution manifest is not an object" - ) - plan = execution.get("plan") - kernel_pack = execution.get("kernel_pack") - if not isinstance(plan, Mapping) or not isinstance(kernel_pack, Mapping): - raise MeasurementLineageError( - "recurrence execution lacks plan or kernel-pack identity" - ) - runtime_schedule = plan.get("runtime_schedule") - process_binding = plan.get("process_binding") - if not isinstance(runtime_schedule, Mapping) or not isinstance( - process_binding, Mapping - ): - raise MeasurementLineageError( - "recurrence execution lacks schedule or process binding" - ) - schedule_path = _artifact_member( - artifact_root, - runtime_schedule.get("path"), - context=f"{cell.cell_id} recurrence schedule", - ) - binding_path = _artifact_member( - artifact_root - / "processes" - / process_id, - process_binding.get("path"), - context=f"{cell.cell_id} recurrence process binding", - ) - if ( - _file_digest(schedule_path) != runtime_schedule.get("sha256") - or schedule_path.stat().st_size != runtime_schedule.get("size_bytes") - or _file_digest(binding_path) != process_binding.get("sha256") - or binding_path.stat().st_size != process_binding.get("size_bytes") - ): - raise MeasurementLineageError( - "recurrence schedule or process-binding bytes differ from execution" - ) - pack_path = _artifact_member( - artifact_root, - kernel_pack.get("manifest_path"), - context=f"{cell.cell_id} recurrence kernel pack", - ) - raw_pack = json.loads(pack_path.read_text(encoding="utf-8")) - if ( - not isinstance(raw_pack, dict) - or raw_pack.pop("eager_kernel_abi", None) != EAGER_KERNEL_ABI - ): - raise MeasurementLineageError( - "recurrence prepared pack has an incompatible eager-kernel ABI" - ) - prepared_pack = PreparedKernelPack.from_dict(raw_pack) - direct_catalog = prepared_pack.recurrence_direct_template_catalog - semantic_catalog = prepared_pack.recurrence_template_catalog - if direct_catalog is None or semantic_catalog is None: - raise MeasurementLineageError( - "recurrence prepared pack lacks authenticated direct semantics" - ) - sections = _load_recurrence_exact_sections_v1( - artifact_root, - process_id, - ) - active_executor_ids = { - row.executor_id - for row in sections.row_groups - if row.executor_id != DIRECT_NONE_U32 - } - selected_dispatch_ids = { - row.dispatch_variant_id - for row in sections.resolved_source_selections - } - for dispatch_id in selected_dispatch_ids: - try: - active_executor_ids.add( - sections.source_dispatch_variants[dispatch_id].executor_id - ) - except IndexError as error: - raise MeasurementLineageError( - "recurrence source dispatch selects an absent variant" - ) from error - if not active_executor_ids: - raise MeasurementLineageError( - "recurrence schedule has no active direct executors" - ) - if max(active_executor_ids) >= len(direct_catalog.templates): - raise MeasurementLineageError( - "recurrence schedule selects an unknown direct executor" - ) - transition_by_id = { - transition.template_id: transition - for transition in semantic_catalog.transitions - } - matched_contracts: set[str] = set() - matched_templates: set[str] = set() - executor_by_id = { - executor.executor_id: executor for executor in sections.executors - } - for executor_id in active_executor_ids: - template = direct_catalog.templates[executor_id] - if template.direct_executor_id != executor_id: - raise MeasurementLineageError( - "recurrence direct executor catalog is not dense" - ) - executor = executor_by_id.get(executor_id) - binding = template.payload_binding - if ( - executor is None - or executor.role != template.role - or executor.destination_operation != template.destination_operation - or executor.parent_component_counts - != template.parent_component_counts - or executor.destination_component_count - != template.destination_component_count - or executor.momentum_operand_count - != template.momentum_operand_count - or executor.prepared_kernel_id != binding.prepared_kernel_id - or executor.runtime_template != binding.runtime_template - ): - raise MeasurementLineageError( - "active recurrence executor differs from its authenticated " - f"direct template: {executor_id}" - ) - for template_id in template.semantic_template_ids: - transition = transition_by_id.get(template_id) - if ( - transition is not None - and transition.equivalence_class in _HZZ_CONTRACT_IDS - ): - matched_contracts.add(transition.equivalence_class) - matched_templates.add(template_id) - except MeasurementLineageError: - raise - except Exception as error: - raise MeasurementLineageError( - f"{cell.cell_id}: cannot authenticate recurrence reachability: {error}" - ) from error - - return { - "cell_id": cell.cell_id, - "attempt_id": record.attempt_id, - "manifest_sha256": record.manifest_sha256, - "artifact_locator": artifact_root.relative_to( - record.manifest_path.parents[4] - ).as_posix(), - "artifact_owner": artifact_owner, - "process_id": process_id, - "execution_manifest_path": evidence.execution_manifest_path, - "execution_manifest_sha256": evidence.execution_manifest_sha256, - "schedule_path": schedule_path.relative_to(artifact_root).as_posix(), - "schedule_sha256": _file_digest(schedule_path), - "schedule_index_sha256": runtime_schedule.get("index_sha256"), - "schedule_member_sha256": runtime_schedule.get("sha256"), - "process_binding_path": binding_path.relative_to(artifact_root).as_posix(), - "process_binding_sha256": _file_digest(binding_path), - "kernel_pack_path": pack_path.relative_to(artifact_root).as_posix(), - "kernel_pack_sha256": _file_digest(pack_path), - "semantic_catalog_sha256": semantic_catalog.catalog_digest, - "direct_catalog_sha256": direct_catalog.catalog_digest, - "active_executor_ids": sorted(active_executor_ids), - "matched_template_ids": sorted(matched_templates), - "matched_contract_ids": sorted(matched_contracts), - } - - -def _hzz_reachability_certificate( - store: ArtifactStore, - *, - catalog: ReportCatalog, - inspector: RecurrenceReachabilityInspector | None, -) -> dict[str, object]: - by_id = {cell.cell_id: cell for cell in catalog.measurement_cells()} - target_ids = {cell.cell_id for cell in hzz_impacted_cells(catalog=catalog)} - replacement_ids = target_ids | { - cell.cell_id for cell in hzz_agreement_closure(catalog=catalog) - } - inspect = ( - inspector - if inspector is not None - else lambda record, cell: _default_recurrence_reachability( - record, - cell, - store=store, - catalog=catalog, - ) - ) - records: list[dict[str, object]] = [] - reached_ids: set[str] = set() - existing_target_ids: set[str] = set() - invalidated_failure_ids: set[str] = set() - for current in store.recover_current_records(): - cell = by_id.get(current.cell_id) - if cell is None: - raise MeasurementLineageError( - f"artifact store current is absent from the report catalog: " - f"{current.cell_id}" - ) - status = current.result.get("status") - if status != ResultStatus.OK.value: - if current.cell_id not in replacement_ids: - raise MeasurementLineageError( - "current outside the exact HZZ replacement closure is not " - f"successful: {current.cell_id}" - ) - _authenticate_replaceable_validation_failure(store, current, cell) - invalidated_failure_ids.add(current.cell_id) - continue - if ( - cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or cell.measurement.model is not ModelKey.BUILTIN_SM - ): - continue - raw = dict(inspect(current, cell)) - matched = raw.get("matched_contract_ids") - if ( - not isinstance(matched, list) - or matched != sorted(set(matched)) - or any(value not in _HZZ_CONTRACT_IDS for value in matched) - ): - raise MeasurementLineageError( - f"recurrence reachability record is malformed: {current.cell_id}" - ) - if matched: - reached_ids.add(current.cell_id) - if current.cell_id in target_ids: - existing_target_ids.add(current.cell_id) - if not matched: - raise MeasurementLineageError( - "catalog HZZ target is not structurally reachable through its " - f"stored schedule: {current.cell_id}" - ) - records.append(raw) - certificate = { - "algorithm": "authenticated-recurrence-active-executor-reachability-v1", - "target_contract_ids": sorted(_HZZ_CONTRACT_IDS), - "inspected_current_count": len(records), - "records": sorted(records, key=lambda item: str(item.get("cell_id"))), - "reached_cell_ids": sorted(reached_ids), - "existing_catalog_target_ids": sorted(existing_target_ids), - "invalidated_validation_failed_current_ids": sorted( - invalidated_failure_ids - ), - } - certificate["sha256"] = _digest(certificate) - return certificate - - -def _validate_recurrence_summary_cap_failure( - store: ArtifactStore, - record: CurrentRecord, - cell: CellSpec, - *, - expected_bytes: int, -) -> dict[str, object]: - """Authenticate one exact source-less summary-cap failure attempt.""" - - try: - validate_measurement(record.result, expected_cell=cell) - except ValueError as error: - raise MeasurementLineageError( - f"{record.cell_id}: recurrence summary-cap failure schema is invalid" - ) from error - failure = record.result.get("failure") - expected_message = _summary_cap_failure_message(expected_bytes) - if ( - _RECURRENCE_SUMMARY_CAP_FAILURE_BYTES.get(record.cell_id) - != expected_bytes - or cell.cell_id != record.cell_id - or record.result.get("status") != ResultStatus.ERROR.value - or not isinstance(failure, Mapping) - or set(failure) != {"kind", "message"} - or failure.get("kind") != "GenerationError" - or failure.get("message") != expected_message - ): - raise MeasurementLineageError( - f"{record.cell_id}: current is not the authenticated " - "recurrence summary-cap GenerationError" - ) - inventory, result_locator = _attempt_owner_evidence(store, record) - return { - "cell_id": record.cell_id, - "attempt_id": record.attempt_id, - "manifest_sha256": record.manifest_sha256, - "result_locator": result_locator, - "result_sha256": inventory["result_sha256"], - "summary_bytes": expected_bytes, - "failure_kind": "GenerationError", - "failure_message": expected_message, - } - - -def _summary_cap_excluded_current_record( - store: ArtifactStore, - record: CurrentRecord, - cell: CellSpec, -) -> dict[str, object]: - try: - validate_measurement(record.result, expected_cell=cell) - except ValueError as error: - raise MeasurementLineageError( - f"{record.cell_id}: excluded terminal current schema is invalid" - ) from error - status = record.result.get("status") - if ( - status == ResultStatus.OK.value - or status not in {value.value for value in ResultStatus} - or record.result.get("failure") is None - ): - raise MeasurementLineageError( - f"{record.cell_id}: excluded current is not a terminal failure" - ) - inventory, result_locator = _attempt_owner_evidence(store, record) - return { - "cell_id": record.cell_id, - "attempt_id": record.attempt_id, - "manifest_sha256": record.manifest_sha256, - "result_locator": result_locator, - "result_sha256": inventory["result_sha256"], - **_current_pointer_identity(record), - "status": status, - "failure_sha256": _digest(record.result["failure"]), - } - - -def _summary_cap_predecessor_record( - lineage: MeasurementLineage, -) -> dict[str, object]: - payload = lineage.payload - ancestor_environment = payload.get("ancestor_environment") - descendant_environment = payload.get("descendant_environment") - retained = payload.get("retained_currents") - if ( - payload.get("state") != "finalized" - or payload.get("impact") != CLASS_C_HZZ_IMPACT - or not isinstance(ancestor_environment, Mapping) - or not isinstance(descendant_environment, Mapping) - or not isinstance(retained, list) - ): - raise MeasurementLineageError( - "recurrence summary-cap continuity requires one finalized HZZ " - "predecessor" - ) - record = { - "payload_sha256": _digest(payload), - "profile": payload["profile"], - "impact": payload["impact"], - "ancestor_revision": lineage.ancestor_revision, - "ancestor_tree": lineage.ancestor_tree, - "descendant_revision": lineage.descendant_revision, - "descendant_tree": lineage.descendant_tree, - "ancestor_environment": dict(ancestor_environment), - "ancestor_environment_sha256": _digest(ancestor_environment), - "descendant_environment_sha256": _digest(descendant_environment), - "retained_currents": list(retained), - "retained_currents_sha256": _digest(retained), - } - _validate_summary_cap_predecessor(record) - return record - - -def _recurrence_summary_cap_failure_certificate( - store: ArtifactStore, - *, - catalog: ReportCatalog, - predecessor_lineage: MeasurementLineage, -) -> dict[str, object]: - by_id = {cell.cell_id: cell for cell in catalog.measurement_cells()} - target_ids = set(_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES) - records: list[dict[str, object]] = [] - excluded: list[dict[str, object]] = [] - inspected_count = 0 - successful_count = 0 - for current in store.recover_current_records(): - inspected_count += 1 - cell = by_id.get(current.cell_id) - if cell is None: - raise MeasurementLineageError( - "artifact store current is absent from the report catalog: " - f"{current.cell_id}" - ) - if current.cell_id in target_ids: - records.append( - _validate_recurrence_summary_cap_failure( - store, - current, - cell, - expected_bytes=_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES[ - current.cell_id - ], - ) - ) - elif current.result.get("status") != ResultStatus.OK.value: - excluded.append( - _summary_cap_excluded_current_record( - store, - current, - cell, - ) - ) - else: - successful_count += 1 - observed_ids = {str(record["cell_id"]) for record in records} - if observed_ids != target_ids or len(records) != len(target_ids): - missing = sorted(target_ids - observed_ids) - raise MeasurementLineageError( - "artifact store does not contain the exact recurrence summary-cap " - "failure census" - + (": " + ", ".join(missing) if missing else "") - ) - certificate = { - "algorithm": "authenticated-recurrence-summary-cap-failure-census-v1", - "predecessor": _summary_cap_predecessor_record(predecessor_lineage), - "target_summary_bytes": dict(_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES), - "inspected_current_count": inspected_count, - "successful_current_count": successful_count, - "excluded_non_success_current_count": len(excluded), - "records": sorted(records, key=lambda item: str(item["cell_id"])), - "excluded_non_success_currents": sorted( - excluded, - key=lambda item: str(item["cell_id"]), - ), - "invalidated_generation_error_current_ids": sorted(target_ids), - } - certificate["sha256"] = _digest(certificate) - return certificate - - -def _reachability_certificate( - impact: str, - store: ArtifactStore, - *, - catalog: ReportCatalog, - inspector: RecurrenceReachabilityInspector | None, - predecessor_lineage: MeasurementLineage | None = None, -) -> dict[str, object]: - if impact == CLASS_C_HZZ_IMPACT: - return _hzz_reachability_certificate( - store, - catalog=catalog, - inspector=inspector, - ) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - if predecessor_lineage is None: - raise MeasurementLineageError( - "recurrence summary-cap continuity has no audited predecessor" - ) - return _recurrence_summary_cap_failure_certificate( - store, - catalog=catalog, - predecessor_lineage=predecessor_lineage, - ) - raise MeasurementLineageError(f"unsupported Class-C impact {impact!r}") - - -def _certificate_failure_ids( - impact: str, - certificate: Mapping[str, object], -) -> frozenset[str]: - if impact == CLASS_C_HZZ_IMPACT: - field = "invalidated_validation_failed_current_ids" - elif impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - field = "invalidated_generation_error_current_ids" - else: - raise MeasurementLineageError(f"unsupported Class-C impact {impact!r}") - raw = certificate.get(field) - if not isinstance(raw, list) or any( - not isinstance(value, str) for value in raw - ): - raise MeasurementLineageError( - "measurement-lineage invalidated failure census is malformed" - ) - return frozenset(raw) - - -def _summary_cap_inherited_pins( - certificate: Mapping[str, object], -) -> tuple[dict[str, object], ...]: - predecessor = certificate.get("predecessor") - if not isinstance(predecessor, Mapping): - raise MeasurementLineageError( - "recurrence summary-cap predecessor is absent" - ) - return _validated_pins(predecessor, "retained_currents") - - -def _summary_cap_excluded_ids( - certificate: Mapping[str, object], -) -> frozenset[str]: - raw = certificate.get("excluded_non_success_currents") - if not isinstance(raw, list): - raise MeasurementLineageError( - "recurrence summary-cap excluded census is absent" - ) - return frozenset( - str(record["cell_id"]) - for record in raw - if isinstance(record, Mapping) - ) - - -def _snapshot_currents( - store: ArtifactStore, - *, - ancestor_revision: str, - ancestor_tree: str, - catalog: ReportCatalog, - invalidated_cell_ids: Sequence[str], - recompare_cell_ids: Sequence[str], - source_less_failure_ids: Sequence[str] = (), - inherited_current_pins: Sequence[Mapping[str, object]] = (), - excluded_current_ids: Sequence[str] = (), -) -> dict[str, object]: - impacted_ids = set(invalidated_cell_ids) - recompare_ids = set(recompare_cell_ids) - impacted_ids - source_less_ids = set(source_less_failure_ids) - inherited_by_cell = { - str(pin["cell_id"]): pin for pin in inherited_current_pins - } - excluded_ids = set(excluded_current_ids) - if not source_less_ids <= impacted_ids: - raise MeasurementLineageError( - "source-less failure pins escape the exact invalidated census" - ) - retained: list[dict[str, object]] = [] - invalidated: list[dict[str, object]] = [] - recompare: list[dict[str, object]] = [] - observed_excluded: set[str] = set() - for record in store.recover_current_records(): - if record.cell_id in excluded_ids: - observed_excluded.add(record.cell_id) - continue - pin = _current_pin( - record, - source_epoch_fallback=( - (ancestor_revision, ancestor_tree) - if record.cell_id in source_less_ids - else None - ), - ) - if ( - pin["source_revision"] != ancestor_revision - or pin["source_tree"] != ancestor_tree - ) and dict(inherited_by_cell.get(record.cell_id, {})) != pin: - raise MeasurementLineageError( - f"frozen current {record.cell_id!r} is not authorized by the " - "exact ancestor or its audited predecessor" - ) - if record.cell_id in impacted_ids: - invalidated.append(pin) - elif record.cell_id in recompare_ids: - recompare.append(pin) - else: - retained.append(pin) - if observed_excluded != excluded_ids: - raise MeasurementLineageError( - "excluded terminal current census changed during snapshot" - ) - attempt_inventory, no_attempts = _attempt_inventory(store, catalog=catalog) - return { - "retained_currents": sorted(retained, key=lambda item: item["cell_id"]), - "invalidated_currents": sorted( - invalidated, key=lambda item: item["cell_id"] - ), - "recompare_currents": sorted(recompare, key=lambda item: item["cell_id"]), - "attempt_inventory": list(attempt_inventory), - "no_attempt_cells": list(no_attempts), - } - - -def _workspace_manifest_identity( - repo_root: Path, - docs_dir: Path, - *, - ancestor_revision: str, - descendant_revision: str, -) -> dict[str, object]: - path = docs_dir / "report-workspace.json" - try: - relative = path.resolve(strict=True).relative_to(repo_root.resolve(strict=True)) - except (OSError, ValueError) as error: - raise MeasurementLineageError( - "report workspace manifest is unavailable or outside the repository" - ) from error - if path.is_symlink() or not path.is_file(): - raise MeasurementLineageError( - "report workspace manifest is not a regular file" - ) - logical = relative.as_posix() - ancestor_member = _tree_member(repo_root, ancestor_revision, logical) - descendant_member = _tree_member(repo_root, descendant_revision, logical) - if ( - ancestor_member is None - or descendant_member is None - or ancestor_member != descendant_member - or ancestor_member["mode"] != "100644" - ): - raise MeasurementLineageError( - "Class-C bridge requires one unchanged regular report-workspace blob" - ) - blob = _git(repo_root, "show", f"{ancestor_revision}:{logical}").stdout - if hashlib.sha256(path.read_bytes()).digest() != hashlib.sha256(blob).digest(): - raise MeasurementLineageError( - "working report workspace manifest differs from its committed blob" - ) - try: - raw = json.loads(blob.decode("ascii")) - except (UnicodeError, json.JSONDecodeError) as error: - raise MeasurementLineageError( - f"cannot read report workspace policy: {error}" - ) from error - if not isinstance(raw, dict) or not isinstance(raw.get("campaign_policy"), dict): - raise MeasurementLineageError("report workspace campaign policy is malformed") - return { - "path": logical, - "mode": ancestor_member["mode"], - "object": ancestor_member["object"], - "sha256": hashlib.sha256(blob).hexdigest(), - "campaign_policy_sha256": _digest(raw["campaign_policy"]), - } - - -def _prepare_class_c_bridge_locked( - repo_root: Path, - docs_dir: Path, - store: ArtifactStore, - *, - ancestor_revision: str, - descendant_revision: str, - impact: str, - catalog: ReportCatalog = REPORT_CATALOG, - reachability_inspector: RecurrenceReachabilityInspector | None = None, -) -> dict[str, object]: - """Snapshot a frozen ancestor campaign before runtime authentication changes.""" - - root = repo_root.expanduser().resolve(strict=False) - profile = _profile_name(root, docs_dir) - ancestor = _git_commit(root, ancestor_revision) - descendant = _git_commit(root, descendant_revision) - source = require_eligible_report_source(root) - if source.revision != descendant: - raise MeasurementLineageError( - "Class-C bridge preparation requires checkout HEAD at the descendant" - ) - ancestor_tree = _git_tree(root, ancestor) - descendant_tree = _git_tree(root, descendant) - environment = _environment( - docs_dir / "report_environment.json", - expected_profile=profile, - ) - if environment.get("source_revision") != ancestor: - raise MeasurementLineageError( - "profile environment is not authenticated for the Class-C ancestor" - ) - diff = _diff_records( - root, - ancestor=ancestor, - descendant=descendant, - impact=impact, - ) - workspace_manifest = _workspace_manifest_identity( - root, - docs_dir, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - predecessor_lineage = ( - load_and_audit_measurement_lineage( - root, - docs_dir, - store, - expected_active_source_revision=ancestor, - catalog=catalog, - reachability_inspector=reachability_inspector, - ) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else None - ) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT and ( - predecessor_lineage is None - or predecessor_lineage.descendant_revision != ancestor - or predecessor_lineage.descendant_tree != ancestor_tree - or predecessor_lineage.payload.get("profile") != profile - or predecessor_lineage.payload.get("descendant_environment") - != environment - ): - raise MeasurementLineageError( - "recurrence summary-cap continuity requires the audited HZZ bridge " - "ending at its exact measured ancestor" - ) - reachability = _reachability_certificate( - impact, - store, - catalog=catalog, - inspector=reachability_inspector, - predecessor_lineage=predecessor_lineage, - ) - impacted_cells, agreement_cells = _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - ) - impacted_ids = tuple(cell.cell_id for cell in impacted_cells) - agreement_ids = tuple(cell.cell_id for cell in agreement_cells) - snapshot = _snapshot_currents( - store, - ancestor_revision=ancestor, - ancestor_tree=ancestor_tree, - catalog=catalog, - invalidated_cell_ids=impacted_ids, - recompare_cell_ids=agreement_ids, - source_less_failure_ids=( - _certificate_failure_ids(impact, reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - inherited_current_pins=( - _summary_cap_inherited_pins(reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - excluded_current_ids=( - _summary_cap_excluded_ids(reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - ) - impacted = [ - _cell_record(cell, catalog=catalog) for cell in impacted_cells - ] - closure = [ - _cell_record(cell, catalog=catalog) for cell in agreement_cells - ] - payload: dict[str, object] = { - "schema": MEASUREMENT_LINEAGE_SCHEMA, - "state": "pending", - "class": "C", - "impact": impact, - "profile": profile, - "ancestor_revision": ancestor, - "ancestor_tree": ancestor_tree, - "descendant_revision": descendant, - "descendant_tree": descendant_tree, - "git_diff": list(diff), - "git_diff_sha256": _digest(diff), - "ancestor_environment": environment, - "ancestor_environment_sha256": _digest(environment), - "descendant_environment": None, - "descendant_environment_sha256": None, - "runtime_invariant_fields": list(_ENVIRONMENT_INVARIANT_FIELDS), - "impacted_cells": impacted, - "agreement_closure_cells": closure, - "impact_certificate_sha256": _digest( - {"impacted": impacted, "agreement_closure": closure} - ), - "catalog_sha256": _catalog_digest(catalog), - "agreement_graph_sha256": _agreement_digest(catalog), - "workspace_manifest": workspace_manifest, - "workspace_manifest_sha256": _digest(workspace_manifest), - "campaign_policy_sha256": workspace_manifest[ - "campaign_policy_sha256" - ], - "reachability_certificate": reachability, - "reachability_certificate_sha256": _digest(reachability), - **snapshot, - } - payload["current_snapshot_sha256"] = _digest(snapshot) - output = class_c_pending_path( - store, - ancestor_revision=ancestor, - descendant_revision=descendant, - ) - expected_root = store.artifact_root / "source-bridges" - expected_root.mkdir(parents=True, exist_ok=True) - if expected_root.is_symlink() or not expected_root.is_dir(): - raise MeasurementLineageError( - "pending Class-C bridge root is not a regular directory" - ) - try: - output.parent.resolve(strict=True).relative_to( - store.artifact_root.resolve(strict=True) - ) - except ValueError as error: - raise MeasurementLineageError( - "pending Class-C bridge must stay under the profile artifact root" - ) from error - if output.exists() or output.is_symlink(): - raise MeasurementLineageError( - f"pending Class-C bridge already exists: {output}" - ) - _write_envelope(output, payload) - return payload - - -def prepare_class_c_bridge( - repo_root: Path, - docs_dir: Path, - store: ArtifactStore, - *, - ancestor_revision: str, - descendant_revision: str, - impact: str, - catalog: ReportCatalog = REPORT_CATALOG, - reachability_inspector: RecurrenceReachabilityInspector | None = None, -) -> dict[str, object]: - """Snapshot a frozen ancestor campaign under the profile writer locks.""" - - with ( - store.named_lock("report-writer"), - store.named_lock("measurement-lineage"), - ): - return _prepare_class_c_bridge_locked( - repo_root, - docs_dir, - store, - ancestor_revision=ancestor_revision, - descendant_revision=descendant_revision, - impact=impact, - catalog=catalog, - reachability_inspector=reachability_inspector, - ) - - -def _environment_invariants(environment: Mapping[str, object]) -> dict[str, object]: - try: - return {field: environment[field] for field in _ENVIRONMENT_INVARIANT_FIELDS} - except KeyError as error: - raise MeasurementLineageError( - f"profile environment lacks invariant field {error.args[0]!r}" - ) from error - - -def _is_authorized_native_inputs_transition( - *, - impact: str, - ancestor_revision: str, - descendant_revision: str, - ancestor_digest: object, - descendant_digest: object, -) -> bool: - """Recognize the one reviewed Class-C native-input transition. - - Ordinary Class-C bridges remain native-input invariant. The recurrence - summary-cap bridge is different: its reviewed source closure intentionally - changes the native recurrence executor, so both endpoint revisions and - both independently computed input digests are pinned here. - """ - - return ( - impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - and ancestor_revision == _RECURRENCE_SUMMARY_CAP_ANCESTOR_REVISION - and descendant_revision == _RECURRENCE_SUMMARY_CAP_DESCENDANT_REVISION - and ancestor_digest - == _RECURRENCE_SUMMARY_CAP_ANCESTOR_NATIVE_INPUTS_SHA256 - and descendant_digest - == _RECURRENCE_SUMMARY_CAP_DESCENDANT_NATIVE_INPUTS_SHA256 - ) - - -def _require_environment_transition( - *, - impact: str, - ancestor_revision: str, - descendant_revision: str, - ancestor_environment: Mapping[str, object], - descendant_environment: Mapping[str, object], -) -> None: - """Require exact invariants, with one digest-pinned native exception.""" - - ancestor = _environment_invariants(ancestor_environment) - descendant = _environment_invariants(descendant_environment) - if impact != CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - if ancestor != descendant: - raise MeasurementLineageError( - "Class-C descendant changes dependency/native/host runtime identity" - ) - return - - ancestor_native = ancestor.pop("native_build_inputs_sha256") - descendant_native = descendant.pop("native_build_inputs_sha256") - if ( - ancestor != descendant - or not _is_authorized_native_inputs_transition( - impact=impact, - ancestor_revision=ancestor_revision, - descendant_revision=descendant_revision, - ancestor_digest=ancestor_native, - descendant_digest=descendant_native, - ) - ): - raise MeasurementLineageError( - "Class-C descendant changes dependency/native/host runtime identity " - "outside the exact recurrence-summary-cap transition" - ) - - -def _finalize_class_c_bridge_locked( - repo_root: Path, - docs_dir: Path, - store: ArtifactStore, - *, - pending_path: Path, - expected_active_source_revision: str, - runtime_auditor: Callable[[str, Path], Mapping[str, object]] | None = None, - catalog: ReportCatalog = REPORT_CATALOG, - reachability_inspector: RecurrenceReachabilityInspector | None = None, -) -> dict[str, object]: - """Authenticate the descendant runtime and publish the tracked lineage.""" - - root = repo_root.expanduser().resolve(strict=False) - profile = _profile_name(root, docs_dir) - pending_input = _validated_pending_path(store, pending_path) - payload = _load_envelope(pending_input, expected_state="pending") - active = _git_commit(root, expected_active_source_revision) - source = require_eligible_report_source(root) - if ( - payload.get("profile") != profile - or payload.get("descendant_revision") != active - or payload.get("descendant_tree") != source.tree - or source.revision != active - ): - raise MeasurementLineageError( - "pending Class-C bridge does not identify the active descendant" - ) - canonical_pending = class_c_pending_path( - store, - ancestor_revision=str(payload["ancestor_revision"]), - descendant_revision=active, - ) - if ( - pending_input != canonical_pending.absolute() - ): - raise MeasurementLineageError( - "pending Class-C bridge does not use its canonical A-D locator" - ) - expected_diff = _diff_records( - root, - ancestor=str(payload["ancestor_revision"]), - descendant=active, - impact=str(payload["impact"]), - ) - workspace_manifest = _workspace_manifest_identity( - root, - docs_dir, - ancestor_revision=str(payload["ancestor_revision"]), - descendant_revision=active, - ) - impact = str(payload["impact"]) - predecessor_lineage = ( - load_and_audit_measurement_lineage( - root, - docs_dir, - store, - expected_active_source_revision=str(payload["ancestor_revision"]), - catalog=catalog, - reachability_inspector=reachability_inspector, - ) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else None - ) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT and ( - predecessor_lineage is None - or predecessor_lineage.descendant_revision - != payload["ancestor_revision"] - or predecessor_lineage.descendant_tree != payload["ancestor_tree"] - or predecessor_lineage.payload.get("profile") != profile - or predecessor_lineage.payload.get("descendant_environment") - != payload.get("ancestor_environment") - ): - raise MeasurementLineageError( - "recurrence summary-cap predecessor changed after preparation" - ) - reachability = _reachability_certificate( - impact, - store, - catalog=catalog, - inspector=reachability_inspector, - predecessor_lineage=predecessor_lineage, - ) - active_agreement_graph = _agreement_digest(catalog) - if ( - payload.get("git_diff") != list(expected_diff) - or payload.get("git_diff_sha256") != _digest(expected_diff) - or payload.get("catalog_sha256") != _catalog_digest(catalog) - or not _agreement_graph_digest_matches( - payload, - active_agreement_graph, - ) - or payload.get("workspace_manifest") != workspace_manifest - or payload.get("workspace_manifest_sha256") - != _digest(workspace_manifest) - or payload.get("campaign_policy_sha256") - != workspace_manifest["campaign_policy_sha256"] - or payload.get("reachability_certificate") != reachability - or payload.get("reachability_certificate_sha256") - != _digest(reachability) - ): - raise MeasurementLineageError( - "pending Class-C source, catalog, agreement, or policy certificate changed" - ) - snapshot = _snapshot_currents( - store, - ancestor_revision=str(payload["ancestor_revision"]), - ancestor_tree=str(payload["ancestor_tree"]), - catalog=catalog, - invalidated_cell_ids=tuple( - cell.cell_id - for cell in _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - )[0] - ), - recompare_cell_ids=tuple( - cell.cell_id - for cell in _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - )[1] - ), - source_less_failure_ids=( - _certificate_failure_ids(impact, reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - inherited_current_pins=( - _summary_cap_inherited_pins(reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - excluded_current_ids=( - _summary_cap_excluded_ids(reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - ) - if payload.get("current_snapshot_sha256") != _digest(snapshot): - raise MeasurementLineageError( - "current or attempt state changed after Class-C preparation" - ) - if runtime_auditor is None: - from .final_audit import _audit_active_runtime - - runtime_auditor = _audit_active_runtime - try: - raw_runtime = runtime_auditor(active, root) - except Exception as error: - raise MeasurementLineageError( - f"cannot authenticate descendant runtime: {error}" - ) from error - from .workspace import _authenticated_environment_payload - - descendant_environment = _authenticated_environment_payload( - profile, - expected_source_revision=active, - active_runtime=raw_runtime, - ) - ancestor_environment = payload.get("ancestor_environment") - if not isinstance(ancestor_environment, Mapping): - raise MeasurementLineageError("pending ancestor environment is malformed") - _require_environment_transition( - impact=impact, - ancestor_revision=str(payload["ancestor_revision"]), - descendant_revision=active, - ancestor_environment=ancestor_environment, - descendant_environment=descendant_environment, - ) - if ( - ancestor_environment.get("python_package_tree_sha256") - == descendant_environment.get("python_package_tree_sha256") - ): - raise MeasurementLineageError( - "Class-C executable descendant did not change the Python package tree" - ) - finalized = dict(payload) - finalized.update( - { - "state": "finalized", - "descendant_environment": descendant_environment, - "descendant_environment_sha256": _digest(descendant_environment), - } - ) - target = measurement_lineage_path(root, docs_dir) - json_path = docs_dir / "report_environment.json" - tex_path = docs_dir / "report_environment.tex" - previous_json = json_path.read_bytes() if json_path.exists() else None - previous_tex = tex_path.read_bytes() if tex_path.exists() else None - previous_lineage = target.read_bytes() if target.exists() else None - from .workspace import refresh_profile_environment - - try: - refreshed = refresh_profile_environment( - root, - profile, - expected_source_revision=active, - runtime_auditor=lambda _revision, _root: raw_runtime, - _skip_workspace_validation=True, - ) - if refreshed != descendant_environment: - raise MeasurementLineageError( - "written descendant environment differs from its " - "authenticated snapshot" - ) - _write_envelope(target, finalized) - audit_measurement_lineage( - root, - docs_dir, - store, - expected_active_source_revision=active, - catalog=catalog, - reachability_inspector=reachability_inspector, - ) - final_snapshot = _snapshot_currents( - store, - ancestor_revision=str(payload["ancestor_revision"]), - ancestor_tree=str(payload["ancestor_tree"]), - catalog=catalog, - invalidated_cell_ids=tuple( - cell.cell_id - for cell in _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - )[0] - ), - recompare_cell_ids=tuple( - cell.cell_id - for cell in _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - )[1] - ), - source_less_failure_ids=( - _certificate_failure_ids(impact, reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - inherited_current_pins=( - _summary_cap_inherited_pins(reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - excluded_current_ids=( - _summary_cap_excluded_ids(reachability) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else () - ), - ) - if payload.get("current_snapshot_sha256") != _digest(final_snapshot): - raise MeasurementLineageError( - "current or attempt state raced Class-C finalization" - ) - except BaseException: - _restore_file(json_path, previous_json) - _restore_file(tex_path, previous_tex) - _restore_file(target, previous_lineage) - raise - return finalized - - -def finalize_class_c_bridge( - repo_root: Path, - docs_dir: Path, - store: ArtifactStore, - *, - pending_path: Path, - expected_active_source_revision: str, - runtime_auditor: Callable[[str, Path], Mapping[str, object]] | None = None, - catalog: ReportCatalog = REPORT_CATALOG, - reachability_inspector: RecurrenceReachabilityInspector | None = None, -) -> dict[str, object]: - """Authenticate and publish a Class-C bridge under the profile writer locks.""" - - with ( - store.named_lock("report-writer"), - store.named_lock("measurement-lineage"), - ): - return _finalize_class_c_bridge_locked( - repo_root, - docs_dir, - store, - pending_path=pending_path, - expected_active_source_revision=expected_active_source_revision, - runtime_auditor=runtime_auditor, - catalog=catalog, - reachability_inspector=reachability_inspector, - ) - - -@dataclass(frozen=True, slots=True) -class MeasurementLineage: - """Validated authorization map for one finalized Class-C bridge.""" - - payload: Mapping[str, object] - retained_by_cell: Mapping[str, Mapping[str, object]] - invalidated_cell_ids: frozenset[str] - recompare_cell_ids: frozenset[str] - required_descendant_cell_ids: frozenset[str] - inherited_environments_by_revision: Mapping[str, Mapping[str, object]] - - @property - def ancestor_revision(self) -> str: - return str(self.payload["ancestor_revision"]) - - @property - def ancestor_tree(self) -> str: - return str(self.payload["ancestor_tree"]) - - @property - def descendant_revision(self) -> str: - return str(self.payload["descendant_revision"]) - - @property - def descendant_tree(self) -> str: - return str(self.payload["descendant_tree"]) - - @property - def impact(self) -> str: - return str(self.payload["impact"]) - - def source_for_current( - self, - record: CurrentRecord, - *, - active_revision: str, - active_tree: str, - ) -> tuple[str, str] | None: - """Return the exact source authorized for ``record``, or reject it.""" - - provenance = record.result.get("provenance") - if not isinstance(provenance, Mapping): - return None - revision = provenance.get("report_source_revision") - tree = provenance.get("report_source_tree") - if ( - revision == active_revision - and tree == active_tree - and provenance.get("report_measured_source_revision") == active_revision - and provenance.get("report_measured_source_tree") == active_tree - ): - return active_revision, active_tree - if record.cell_id in self.required_descendant_cell_ids: - return None - pin = self.retained_by_cell.get(record.cell_id) - if pin is None: - return None - if ( - record.attempt_id != pin.get("attempt_id") - or record.manifest_sha256 != pin.get("manifest_sha256") - or _file_digest( - record.manifest_path.parent.parent.parent / "current.json" - ) - != pin.get("current_pointer_sha256") - or _file_digest(record.result_path) != pin.get("result_sha256") - or revision != pin.get("source_revision") - or tree != pin.get("source_tree") - or provenance.get("report_measured_source_revision") != revision - or provenance.get("report_measured_source_tree") != tree - ): - return None - return str(revision), str(tree) - - def environment_for_source(self, revision: str) -> Mapping[str, object] | None: - if revision == self.ancestor_revision: - value = self.payload.get("ancestor_environment") - elif revision == self.descendant_revision: - value = self.payload.get("descendant_environment") - else: - return self.inherited_environments_by_revision.get(revision) - return value if isinstance(value, Mapping) else None - - -def _validated_pins( - payload: Mapping[str, object], - field: str, -) -> tuple[dict[str, object], ...]: - raw = payload.get(field) - if not isinstance(raw, list): - raise MeasurementLineageError(f"measurement lineage {field} must be an array") - pins: list[dict[str, object]] = [] - seen: set[str] = set() - for value in raw: - if not isinstance(value, dict) or set(value) != { - "cell_id", - "attempt_id", - "manifest_sha256", - "current_locator", - "current_pointer_sha256", - "source_revision", - "source_tree", - "result_sha256", - }: - raise MeasurementLineageError( - f"measurement lineage {field} contains an invalid current pin" - ) - cell_id = value.get("cell_id") - try: - canonical_attempt_id = ( - str(uuid.UUID(str(value["attempt_id"]))) - if isinstance(value.get("attempt_id"), str) - else None - ) - except ValueError: - canonical_attempt_id = None - if ( - not isinstance(cell_id, str) - or not cell_id - or cell_id in seen - or canonical_attempt_id != value.get("attempt_id") - or not isinstance(value.get("manifest_sha256"), str) - or _SHA256_RE.fullmatch(str(value["manifest_sha256"])) is None - or not isinstance(value.get("current_locator"), str) - or not str(value["current_locator"]).endswith("/current.json") - or Path(str(value["current_locator"])).is_absolute() - or any( - part in {"", ".", ".."} - for part in Path(str(value["current_locator"])).parts - ) - or not isinstance(value.get("current_pointer_sha256"), str) - or _SHA256_RE.fullmatch(str(value["current_pointer_sha256"])) is None - or not isinstance(value.get("result_sha256"), str) - or _SHA256_RE.fullmatch(str(value["result_sha256"])) is None - or not isinstance(value.get("source_revision"), str) - or _GIT_SHA_RE.fullmatch(str(value["source_revision"])) is None - or not isinstance(value.get("source_tree"), str) - or _GIT_SHA_RE.fullmatch(str(value["source_tree"])) is None - ): - raise MeasurementLineageError( - f"measurement lineage {field} current pin is malformed" - ) - seen.add(cell_id) - pins.append(dict(value)) - if [str(pin["cell_id"]) for pin in pins] != sorted(seen): - raise MeasurementLineageError( - f"measurement lineage {field} is not sorted by cell identity" - ) - return tuple(pins) - - -def load_measurement_lineage( - repo_root: Path, - docs_dir: Path, - *, - expected_active_revision: str, - expected_active_tree: str, - catalog: ReportCatalog = REPORT_CATALOG, -) -> MeasurementLineage | None: - path = measurement_lineage_path(repo_root, docs_dir) - if not path.exists(): - return None - payload = _load_envelope(path, expected_state="finalized") - profile = _profile_name(repo_root, docs_dir) - if ( - payload.get("profile") != profile - or payload.get("class") != "C" - or payload.get("impact") not in _CLASS_C_IMPACTS - or payload.get("descendant_revision") != expected_active_revision - or payload.get("descendant_tree") != expected_active_tree - ): - raise MeasurementLineageError( - "finalized measurement lineage does not identify the active profile/source" - ) - retained = _validated_pins(payload, "retained_currents") - invalidated = _validated_pins(payload, "invalidated_currents") - recompare = _validated_pins(payload, "recompare_currents") - impact = str(payload["impact"]) - groups = [ - {str(pin["cell_id"]) for pin in values} - for values in (retained, invalidated, recompare) - ] - if any(groups[left] & groups[right] for left in range(3) for right in range(left)): - raise MeasurementLineageError( - "measurement-lineage current authorization groups overlap" - ) - all_pins = (*retained, *invalidated, *recompare) - raw_certificate = payload.get("reachability_certificate") - inherited_by_cell = ( - { - str(pin["cell_id"]): pin - for pin in _summary_cap_inherited_pins(raw_certificate) - } - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - and isinstance(raw_certificate, Mapping) - else {} - ) - if any( - ( - pin["source_revision"] != payload["ancestor_revision"] - or pin["source_tree"] != payload["ancestor_tree"] - ) - and dict(inherited_by_cell.get(str(pin["cell_id"]), {})) != pin - for pin in all_pins - ): - raise MeasurementLineageError( - "measurement-lineage ancestor pin identifies another source" - ) - inventory_by_key = { - (str(row["cell_id"]), str(row["attempt_id"])): row - for row in payload["attempt_inventory"] # type: ignore[union-attr] - if isinstance(row, Mapping) - } - for pin in all_pins: - key = (str(pin["cell_id"]), str(pin["attempt_id"])) - row = inventory_by_key.get(key) - manifest_locator = ( - PurePosixPath(str(row["manifest_locator"])) - if row is not None - else None - ) - canonical_current = ( - (manifest_locator.parents[2] / "current.json").as_posix() - if manifest_locator is not None - and len(manifest_locator.parents) >= 3 - else None - ) - if ( - row is None - or row.get("status") != "ok" - or row.get("manifest_sha256") != pin["manifest_sha256"] - or row.get("result_sha256") != pin["result_sha256"] - or pin.get("current_locator") != canonical_current - ): - raise MeasurementLineageError( - "measurement-lineage current pin is not bound to exactly one " - "successful attempt-inventory row" - ) - reachability = payload["reachability_certificate"] - assert isinstance(reachability, Mapping) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - predecessor = reachability.get("predecessor") - if ( - not isinstance(predecessor, Mapping) - or predecessor.get("profile") != payload.get("profile") - or predecessor.get("descendant_revision") - != payload.get("ancestor_revision") - or predecessor.get("descendant_tree") != payload.get("ancestor_tree") - or predecessor.get("descendant_environment_sha256") - != payload.get("ancestor_environment_sha256") - or _environment_invariants( - predecessor["ancestor_environment"] - ) - != _environment_invariants(payload["ancestor_environment"]) - ): - raise MeasurementLineageError( - "measurement-lineage summary-cap predecessor does not end at " - "the exact active ancestor" - ) - reachability_record_ids = { - str(record["cell_id"]) - for record in reachability["records"] # type: ignore[index] - if isinstance(record, Mapping) - } - catalog_by_id = { - cell.cell_id: cell - for cell in catalog.measurement_cells() - } - if impact == CLASS_C_HZZ_IMPACT: - for record in reachability["records"]: # type: ignore[index] - if not isinstance(record, Mapping): - continue - owner = record.get("artifact_owner") - if not isinstance(owner, Mapping): - raise MeasurementLineageError( - "measurement-lineage artifact owner is absent" - ) - consumer = catalog_by_id.get(str(owner.get("consumer_cell_id"))) - owner_cell = catalog_by_id.get(str(owner.get("owner_cell_id"))) - if consumer is None or owner_cell is None: - raise MeasurementLineageError( - "measurement-lineage artifact owner is absent from the catalog" - ) - relation = owner.get("relation") - if relation == "equivalent-matrix-peer" and ( - not owner_cell.dataset_id.startswith("matrix_") - or owner_cell not in catalog.equivalent_cells(consumer) - ): - raise MeasurementLineageError( - "measurement-lineage artifact owner is not the catalog matrix peer" - ) - if relation == "consumer-attempt" and owner_cell != consumer: - raise MeasurementLineageError( - "measurement-lineage direct artifact owner changed catalog cell" - ) - static_target_ids = { - cell.cell_id for cell in hzz_impacted_cells(catalog=catalog) - } - if reachability.get("existing_catalog_target_ids") != sorted( - static_target_ids & reachability_record_ids - ): - raise MeasurementLineageError( - "measurement-lineage existing HZZ target census is inconsistent" - ) - impacted_cells, agreement_cells = _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - ) - impacted = [ - _cell_record(cell, catalog=catalog) for cell in impacted_cells - ] - closure = [ - _cell_record(cell, catalog=catalog) for cell in agreement_cells - ] - if ( - payload.get("impacted_cells") != impacted - or payload.get("agreement_closure_cells") != closure - or payload.get("impact_certificate_sha256") - != _digest({"impacted": impacted, "agreement_closure": closure}) - ): - raise MeasurementLineageError( - "measurement-lineage impact/agreement closure is invalid" - ) - target_ids = {cell.cell_id for cell in impacted_cells} - closure_ids = {cell.cell_id for cell in agreement_cells} - failure_ids = set(_certificate_failure_ids(impact, reachability)) - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - failure_record_by_cell = { - str(record["cell_id"]): record - for record in reachability["records"] # type: ignore[index] - if isinstance(record, Mapping) - } - invalidated_pin_by_cell = { - str(pin["cell_id"]): pin for pin in invalidated - } - if any( - (record := failure_record_by_cell.get(cell_id)) is None - or (pin := invalidated_pin_by_cell.get(cell_id)) is None - or record.get("attempt_id") != pin.get("attempt_id") - or record.get("manifest_sha256") != pin.get("manifest_sha256") - or record.get("result_sha256") != pin.get("result_sha256") - for cell_id in failure_ids - ): - raise MeasurementLineageError( - "measurement-lineage summary-cap failure records do not match " - "their invalidated current pins" - ) - current_ids = set().union(*groups) - expected_invalidated = current_ids & target_ids - expected_recompare = (current_ids & closure_ids) - expected_invalidated - if ( - not failure_ids <= expected_invalidated | expected_recompare - or failure_ids & groups[0] - or ( - impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - and ( - len(current_ids) - != int(reachability["successful_current_count"]) - + len(failure_ids) - or int(reachability["inspected_current_count"]) - != len(current_ids) - + len(_summary_cap_excluded_ids(reachability)) - ) - ) - or groups[1] != expected_invalidated - or groups[2] != expected_recompare - or groups[0] != current_ids - expected_invalidated - expected_recompare - ): - raise MeasurementLineageError( - "measurement-lineage current groups do not match impact reachability" - ) - snapshot = { - field: payload[field] - for field in ( - "retained_currents", - "invalidated_currents", - "recompare_currents", - "attempt_inventory", - "no_attempt_cells", - ) - } - if payload.get("current_snapshot_sha256") != _digest(snapshot): - raise MeasurementLineageError( - "measurement-lineage current snapshot digest is invalid" - ) - catalog_ids = {cell.cell_id for cell in catalog.measurement_cells()} - attempted_ids = { - str(row["cell_id"]) - for row in payload["attempt_inventory"] # type: ignore[union-attr] - if isinstance(row, Mapping) - } - no_attempt_ids = set(payload["no_attempt_cells"]) # type: ignore[arg-type] - if ( - attempted_ids & no_attempt_ids - or attempted_ids | no_attempt_ids != catalog_ids - ): - raise MeasurementLineageError( - "measurement-lineage attempt/no-attempt inventory does not partition " - "the report catalog" - ) - return MeasurementLineage( - payload=payload, - retained_by_cell={str(pin["cell_id"]): pin for pin in retained}, - invalidated_cell_ids=frozenset(groups[1]), - recompare_cell_ids=frozenset(groups[2]), - required_descendant_cell_ids=frozenset(target_ids | closure_ids), - inherited_environments_by_revision=( - { - str(reachability["predecessor"]["ancestor_revision"]): dict( - reachability["predecessor"]["ancestor_environment"] - ) - } - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - else {} - ), - ) - - -def audit_measurement_lineage( - repo_root: Path, - docs_dir: Path, - store: ArtifactStore, - *, - expected_active_source_revision: str, - catalog: ReportCatalog = REPORT_CATALOG, - reachability_inspector: RecurrenceReachabilityInspector | None = None, - _loaded_lineage: MeasurementLineage | None = None, -) -> dict[str, object]: - """Audit source, environment, pins, and impact closure without mutation.""" - - root = repo_root.expanduser().resolve(strict=False) - active = _git_commit(root, expected_active_source_revision) - active_tree = _git_tree(root, active) - lineage = _loaded_lineage or load_measurement_lineage( - root, - docs_dir, - expected_active_revision=active, - expected_active_tree=active_tree, - catalog=catalog, - ) - if lineage is None: - raise MeasurementLineageError("profile has no finalized measurement lineage") - payload = lineage.payload - expected_diff = _diff_records( - root, - ancestor=lineage.ancestor_revision, - descendant=lineage.descendant_revision, - impact=str(payload["impact"]), - ) - reachability = payload["reachability_certificate"] - assert isinstance(reachability, Mapping) - impact = str(payload["impact"]) - impacted_cells, agreement_cells = _impact_and_agreement_cells( - impact, - reachability, - catalog=catalog, - ) - impacted = [ - _cell_record(cell, catalog=catalog) for cell in impacted_cells - ] - closure = [ - _cell_record(cell, catalog=catalog) for cell in agreement_cells - ] - workspace_manifest = _workspace_manifest_identity( - root, - docs_dir, - ancestor_revision=lineage.ancestor_revision, - descendant_revision=lineage.descendant_revision, - ) - active_agreement_graph = _agreement_digest(catalog) - if ( - payload.get("git_diff") != list(expected_diff) - or payload.get("git_diff_sha256") != _digest(expected_diff) - or payload.get("catalog_sha256") != _catalog_digest(catalog) - or not _agreement_graph_digest_matches( - payload, - active_agreement_graph, - ) - or payload.get("workspace_manifest") != workspace_manifest - or payload.get("workspace_manifest_sha256") - != _digest(workspace_manifest) - or payload.get("campaign_policy_sha256") - != workspace_manifest["campaign_policy_sha256"] - or payload.get("impacted_cells") != impacted - or payload.get("agreement_closure_cells") != closure - or payload.get("impact_certificate_sha256") - != _digest({"impacted": impacted, "agreement_closure": closure}) - ): - raise MeasurementLineageError( - "measurement-lineage source, policy, catalog, or impact certificate changed" - ) - profile = _profile_name(root, docs_dir) - descendant_environment = _environment( - docs_dir / "report_environment.json", - expected_profile=profile, - ) - if ( - payload.get("descendant_environment") != descendant_environment - or payload.get("descendant_environment_sha256") - != _digest(descendant_environment) - ): - raise MeasurementLineageError( - "active profile environment differs from the finalized lineage" - ) - ancestor_environment = payload.get("ancestor_environment") - if not isinstance(ancestor_environment, Mapping): - raise MeasurementLineageError( - "Class-C runtime invariant proof no longer holds" - ) - try: - _require_environment_transition( - impact=impact, - ancestor_revision=lineage.ancestor_revision, - descendant_revision=lineage.descendant_revision, - ancestor_environment=ancestor_environment, - descendant_environment=descendant_environment, - ) - except MeasurementLineageError as error: - raise MeasurementLineageError( - "Class-C runtime invariant proof no longer holds" - ) from error - missing_retained: list[str] = [] - for cell_id, pin in lineage.retained_by_cell.items(): - current = store.load_current(cell_id, missing_ok=True) - if ( - current is None - or lineage.source_for_current( - current, - active_revision=active, - active_tree=active_tree, - ) - != (pin.get("source_revision"), pin.get("source_tree")) - ): - missing_retained.append(cell_id) - if missing_retained: - raise MeasurementLineageError( - "retained ancestor currents changed or disappeared: " - + ", ".join(missing_retained[:8]) - ) - missing_history: list[str] = [] - inventory_by_key: dict[tuple[str, str], Mapping[str, object]] = {} - for raw in payload["attempt_inventory"]: # type: ignore[union-attr] - assert isinstance(raw, Mapping) - locator = raw.get("manifest_locator") - if not isinstance(locator, str): - missing_history.append("") - continue - try: - manifest_path = _artifact_member( - store.artifact_root, - locator, - context="historical attempt manifest", - ) - except MeasurementLineageError: - missing_history.append(locator) - continue - try: - observed = _validated_attempt_inventory_row( - store, - manifest_path, - expected_cell_id=str(raw["cell_id"]), - ) - except MeasurementLineageError: - missing_history.append(locator) - continue - if observed != dict(raw): - missing_history.append(locator) - continue - inventory_by_key[(str(raw["cell_id"]), str(raw["attempt_id"]))] = raw - if missing_history: - raise MeasurementLineageError( - "immutable historical attempt evidence changed or disappeared: " - + ", ".join(missing_history[:8]) - ) - certificate = payload["reachability_certificate"] - assert isinstance(certificate, Mapping) - by_cell = {cell.cell_id: cell for cell in catalog.measurement_cells()} - failure_ids = set(_certificate_failure_ids(impact, certificate)) - historical_status_errors: list[str] = [] - for field in ( - "retained_currents", - "invalidated_currents", - "recompare_currents", - ): - for pin in payload[field]: # type: ignore[index] - assert isinstance(pin, Mapping) - cell_id = str(pin["cell_id"]) - key = (cell_id, str(pin["attempt_id"])) - inventory = inventory_by_key.get(key) - if inventory is None: - historical_status_errors.append(cell_id) - continue - try: - manifest_path = _artifact_member( - store.artifact_root, - inventory["manifest_locator"], - context="historical pinned attempt manifest", - ) - historical = store._validate_attempt_manifest( - manifest_path, - expected_cell_id=cell_id, - expected_attempt_id=key[1], - expected_digest=str(inventory["manifest_sha256"]), - ) - if cell_id in failure_ids: - cell = by_cell.get(cell_id) - if cell is None: - raise MeasurementLineageError( - f"{cell_id}: historical failure is absent from the catalog" - ) - if impact == CLASS_C_HZZ_IMPACT: - _validate_numerical_validation_failure(historical, cell) - else: - _validate_recurrence_summary_cap_failure( - store, - historical, - cell, - expected_bytes=( - _RECURRENCE_SUMMARY_CAP_FAILURE_BYTES[cell_id] - ), - ) - elif historical.result.get("status") != ResultStatus.OK.value: - raise MeasurementLineageError( - f"{cell_id}: non-successful current was selected for " - "retention or replacement without failure evidence" - ) - except Exception: - historical_status_errors.append(cell_id) - if historical_status_errors: - raise MeasurementLineageError( - "historical current status or failure evidence changed: " - + ", ".join(historical_status_errors[:8]) - ) - inspect = ( - reachability_inspector - if reachability_inspector is not None - else lambda record, cell: _default_recurrence_reachability( - record, - cell, - store=store, - catalog=catalog, - ) - ) - changed_reachability: list[str] = [] - for raw_record in certificate["records"]: # type: ignore[index] - assert isinstance(raw_record, Mapping) - key = ( - str(raw_record["cell_id"]), - str(raw_record["attempt_id"]), - ) - inventory = inventory_by_key.get(key) - cell = by_cell.get(key[0]) - if inventory is None or cell is None: - changed_reachability.append(key[0]) - continue - manifest_path = _artifact_member( - store.artifact_root, - inventory["manifest_locator"], - context="reachability attempt manifest", - ) - try: - historical = store._validate_attempt_manifest( - manifest_path, - expected_cell_id=key[0], - expected_attempt_id=key[1], - expected_digest=str(inventory["manifest_sha256"]), - ) - if impact == CLASS_C_HZZ_IMPACT: - observed_record = dict(inspect(historical, cell)) - else: - observed_record = _validate_recurrence_summary_cap_failure( - store, - historical, - cell, - expected_bytes=_RECURRENCE_SUMMARY_CAP_FAILURE_BYTES[key[0]], - ) - except Exception: - changed_reachability.append(key[0]) - continue - if observed_record != dict(raw_record): - changed_reachability.append(key[0]) - if changed_reachability: - raise MeasurementLineageError( - "authenticated recurrence reachability changed or cannot be replayed: " - + ", ".join(changed_reachability[:8]) - ) - excluded_by_cell: dict[str, Mapping[str, object]] = {} - if impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT: - excluded_errors: list[str] = [] - for raw_record in certificate[ - "excluded_non_success_currents" - ]: # type: ignore[index] - assert isinstance(raw_record, Mapping) - cell_id = str(raw_record["cell_id"]) - excluded_by_cell[cell_id] = raw_record - key = (cell_id, str(raw_record["attempt_id"])) - inventory = inventory_by_key.get(key) - cell = by_cell.get(cell_id) - if inventory is None or cell is None: - excluded_errors.append(cell_id) - continue - try: - manifest_path = _artifact_member( - store.artifact_root, - inventory["manifest_locator"], - context="excluded terminal attempt manifest", - ) - historical = store._validate_attempt_manifest( - manifest_path, - expected_cell_id=cell_id, - expected_attempt_id=key[1], - expected_digest=str(inventory["manifest_sha256"]), - ) - observed = _summary_cap_excluded_current_record( - store, - historical, - cell, - ) - except Exception: - excluded_errors.append(cell_id) - continue - historical_fields = ( - set(_SUMMARY_CAP_EXCLUDED_RECORD_KEYS) - - {"current_locator", "current_pointer_sha256"} - ) - if any( - observed[field] != raw_record[field] - for field in historical_fields - ) or ( - cell_id not in lineage.required_descendant_cell_ids - and observed != dict(raw_record) - ): - excluded_errors.append(cell_id) - if excluded_errors: - raise MeasurementLineageError( - "excluded terminal current evidence changed: " - + ", ".join(excluded_errors[:8]) - ) - stale_targets: list[str] = [] - invalidated_pin_by_cell = { - str(pin["cell_id"]): pin - for pin in payload["invalidated_currents"] # type: ignore[index] - if isinstance(pin, Mapping) - } - historical_target_pin_by_cell = { - str(pin["cell_id"]): pin - for field in ("invalidated_currents", "recompare_currents") - for pin in payload[field] # type: ignore[index] - if isinstance(pin, Mapping) - } - for cell_id in sorted( - lineage.required_descendant_cell_ids - ): - current = store.load_current(cell_id, missing_ok=True) - if current is None: - continue - provenance = current.result.get("provenance") - if not isinstance(provenance, Mapping): - pin = invalidated_pin_by_cell.get(cell_id) - excluded = excluded_by_cell.get(cell_id) - if ( - impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - and cell_id in failure_ids - and pin is not None - and current.attempt_id == pin.get("attempt_id") - and current.manifest_sha256 == pin.get("manifest_sha256") - and _file_digest(current.result_path) == pin.get("result_sha256") - and _file_digest( - current.manifest_path.parent.parent.parent / "current.json" - ) - == pin.get("current_pointer_sha256") - ): - continue - if ( - excluded is not None - and current.attempt_id == excluded.get("attempt_id") - and current.manifest_sha256 == excluded.get("manifest_sha256") - and _file_digest(current.result_path) - == excluded.get("result_sha256") - and _file_digest( - current.manifest_path.parent.parent.parent / "current.json" - ) - == excluded.get("current_pointer_sha256") - ): - continue - stale_targets.append(cell_id) - continue - historical_pin = historical_target_pin_by_cell.get(cell_id) - if ( - impact == CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT - and historical_pin is not None - and provenance.get("report_source_revision") - == historical_pin.get("source_revision") - and provenance.get("report_source_tree") - == historical_pin.get("source_tree") - and provenance.get("report_measured_source_revision") - == historical_pin.get("source_revision") - and provenance.get("report_measured_source_tree") - == historical_pin.get("source_tree") - and current.attempt_id == historical_pin.get("attempt_id") - and current.manifest_sha256 - == historical_pin.get("manifest_sha256") - and _file_digest(current.result_path) - == historical_pin.get("result_sha256") - and _file_digest( - current.manifest_path.parent.parent.parent / "current.json" - ) - == historical_pin.get("current_pointer_sha256") - ): - continue - if ( - provenance.get("report_source_revision") == lineage.ancestor_revision - and provenance.get("report_source_tree") == lineage.ancestor_tree - and provenance.get("report_measured_source_revision") - == lineage.ancestor_revision - and provenance.get("report_measured_source_tree") - == lineage.ancestor_tree - ): - # This historical pointer remains immutable evidence, but the - # scheduler and service must not authorize it as fresh. - continue - if ( - provenance.get("report_source_revision") != active - or provenance.get("report_source_tree") != active_tree - or provenance.get("report_measured_source_revision") != active - or provenance.get("report_measured_source_tree") != active_tree - ): - stale_targets.append(cell_id) - if stale_targets: - raise MeasurementLineageError( - "Class-C target current has an unauthorized source: " - + ", ".join(stale_targets[:8]) - ) - return { - "schema": MEASUREMENT_LINEAGE_SCHEMA, - "profile": profile, - "impact": payload["impact"], - "ancestor_revision": lineage.ancestor_revision, - "descendant_revision": lineage.descendant_revision, - "retained_current_count": len(lineage.retained_by_cell), - "invalidated_current_count": len(lineage.invalidated_cell_ids), - "recompare_current_count": len(lineage.recompare_cell_ids), - "impacted_cell_count": len(impacted), - "agreement_closure_cell_count": len(closure), - "runtime_invariants_match": True, - } - - -def load_and_audit_measurement_lineage( - repo_root: Path, - docs_dir: Path, - store: ArtifactStore, - *, - expected_active_source_revision: str, - catalog: ReportCatalog = REPORT_CATALOG, - reachability_inspector: RecurrenceReachabilityInspector | None = None, -) -> MeasurementLineage | None: - """Load one lineage object once and fully authenticate it under its lock.""" - - root = repo_root.expanduser().resolve(strict=False) - active = _git_commit(root, expected_active_source_revision) - active_tree = _git_tree(root, active) - with store.named_lock("measurement-lineage"): - lineage = load_measurement_lineage( - root, - docs_dir, - expected_active_revision=active, - expected_active_tree=active_tree, - catalog=catalog, - ) - if lineage is None: - stale: list[str] = [] - for current in store.recover_current_records(): - provenance = current.result.get("provenance") - if not isinstance(provenance, Mapping): - continue - measured_revision = provenance.get("report_measured_source_revision") - measured_tree = provenance.get("report_measured_source_tree") - if measured_revision is not None and ( - provenance.get("report_source_revision") != active - or measured_revision != active - or provenance.get("report_source_tree") != active_tree - or measured_tree != active_tree - ): - stale.append(current.cell_id) - if stale: - raise MeasurementLineageError( - "profile has mixed/ancestor measurements but no authenticated " - "measurement lineage: " - + ", ".join(sorted(stale)[:8]) - ) - return None - audit_measurement_lineage( - root, - docs_dir, - store, - expected_active_source_revision=active, - catalog=catalog, - reachability_inspector=reachability_inspector, - _loaded_lineage=lineage, - ) - if ( - _load_envelope( - measurement_lineage_path(root, docs_dir), - expected_state="finalized", - ) - != dict(lineage.payload) - ): - raise MeasurementLineageError( - "measurement lineage changed during authentication" - ) - return lineage - - -__all__ = [ - "CLASS_C_HZZ_IMPACT", - "CLASS_C_RECURRENCE_SUMMARY_CAP_IMPACT", - "MEASUREMENT_LINEAGE_FILENAME", - "MEASUREMENT_LINEAGE_SCHEMA", - "MeasurementLineage", - "MeasurementLineageError", - "audit_measurement_lineage", - "finalize_class_c_bridge", - "hzz_agreement_closure", - "hzz_impacted_cells", - "load_and_audit_measurement_lineage", - "load_measurement_lineage", - "measurement_lineage_path", - "prepare_class_c_bridge", - "recurrence_summary_cap_agreement_closure", - "recurrence_summary_cap_impacted_cells", - "signed_zero_helicity_agreement_closure", - "signed_zero_helicity_impacted_cells", -] diff --git a/pyamplicol/tools/performance_report/models.py b/pyamplicol/tools/performance_report/models.py deleted file mode 100644 index ff8fd4023d..0000000000 --- a/pyamplicol/tools/performance_report/models.py +++ /dev/null @@ -1,227 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Typed contracts shared by the report catalog, runner, cache, and renderer.""" - -from __future__ import annotations - -from dataclasses import dataclass -from enum import StrEnum -from typing import Literal - -LEGACY_AMPLICOL_MAX_OPEN_QUARK_LINES = 3 -_QUARK_TOKENS = frozenset({"d", "u", "s", "c", "b", "t"}) -_ANTIQUARK_TOKENS = frozenset(f"{token}~" for token in _QUARK_TOKENS) - - -def open_quark_line_count(process: str) -> int: - """Return the number of open quark/antiquark lines in a concrete process.""" - - initial, separator, final = process.partition(">") - if not separator: - raise ValueError(f"process has no initial/final separator: {process!r}") - tokens = (*initial.split(), *final.split()) - quarks = sum(token in _QUARK_TOKENS for token in tokens) - antiquarks = sum(token in _ANTIQUARK_TOKENS for token in tokens) - if quarks != antiquarks: - raise ValueError( - "concrete report process has unpaired quark content: " - f"{process!r} ({quarks} quarks, {antiquarks} antiquarks)" - ) - return quarks - - -class Accuracy(StrEnum): - LC = "lc" - NLC = "nlc" - FULL = "full" - - -class ExecutionMode(StrEnum): - AMPLICOL = "amplicol" - MADGRAPH = "madgraph" - RECURRENCE = "recurrence" - COMPILED = "compiled" - EAGER = "eager" - ON_THE_FLY = "on-the-fly" - - -class ModelKey(StrEnum): - BUILTIN_SM = "builtin_sm" - UFO_SM = "ufo_sm" - SCALAR_CONTACT = "scalar_contact" - SCALAR_GRAVITY = "scalar_gravity" - - -class Workload(StrEnum): - SELECTED_FLOW = "selected-flow" - ALL_FLOW = "all-flow" - CONTRACTED = "contracted" - - -class ArtifactPolicy(StrEnum): - REUSE = "reuse" - RETIME = "retime" - REGENERATE = "regenerate" - - -class ResultStatus(StrEnum): - NOT_AVAILABLE = "not_available" - OK = "ok" - FAILED = "failed" - TIMEOUT = "timeout" - MEMORY_LIMIT = "memory_limit" - SKIP = "skip" - VALIDATION_FAILED = "validation_failed" - UNVERIFIED = "unverified" - ERROR = "error" - UNSUPPORTED = "unsupported" - - -@dataclass(frozen=True, slots=True) -class ModelSpec: - key: ModelKey - profile: str - label: str - source_kind: Literal["built-in-sm", "json"] - - -@dataclass(frozen=True, slots=True) -class ProcessFamily: - identifier: int - key: str - label_tex: str - initial_state: tuple[str, ...] - base_final_state: tuple[str, ...] - maximum_lc_n: int - maximum_contracted_n: int = 5 - include_3qqbar: bool = False - include_cc: bool = False - include_resonance: bool = False - - @property - def minimum_n(self) -> int: - return len(self.base_final_state) - - def maximum_n(self, accuracy: Accuracy) -> int: - return ( - self.maximum_lc_n - if accuracy is Accuracy.LC - else self.maximum_contracted_n - ) - - def process(self, n_final: int) -> str | None: - extra_gluons = n_final - self.minimum_n - if extra_gluons < 0: - return None - final_state = (*self.base_final_state, *("g" for _ in range(extra_gluons))) - return f"{' '.join(self.initial_state)} > {' '.join(final_state)}" - - -@dataclass(frozen=True, slots=True) -class MeasurementSpec: - execution_mode: ExecutionMode - model: ModelKey | None - accuracy: Accuracy - backend: str - jit_optimization_level: int | None - - -@dataclass(frozen=True, slots=True) -class MatrixDataset: - dataset_id: str - title: str - table_name: str - cache_name: str - candidate: MeasurementSpec - baseline: MeasurementSpec - multiplicities: tuple[int, ...] - static_na_reason_code: str | None = None - - -@dataclass(frozen=True, slots=True) -class MatrixComparisonView: - """One rendered matrix comparison backed by shared measurement datasets. - - A view deliberately identifies its candidate and reference datasets by ID - instead of duplicating either measurement surface. In particular, the - MadGraph recurrence view can reuse the existing UFO-SM/full recurrence - profile while presenting it against the independent MadGraph reference. - """ - - comparison_id: str - candidate_dataset_id: str - baseline_dataset_id: str - title: str - table_name: str - - -@dataclass(frozen=True, slots=True) -class ScalarDataset: - dataset_id: str - title: str - table_name: str - cache_name: str - model: ModelKey - process_template: str - final_particle: str - multiplicities: tuple[int, ...] - measurement: MeasurementSpec - - def process(self, n_final: int) -> str: - final_state = " ".join(self.final_particle for _ in range(n_final)) - return f"scalar_0 scalar_0 > {final_state}" - - -@dataclass(frozen=True, slots=True) -class ZVariant: - key: str - label: str - execution_mode: ExecutionMode - backend: str - jit_optimization_level: int | None = None - cpp_optimization: str | None = None - maximum_generation_n_final: int | None = None - static_na_reason_code: str | None = None - - def __post_init__(self) -> None: - maximum = self.maximum_generation_n_final - reason = self.static_na_reason_code - if maximum is not None and ( - isinstance(maximum, bool) - or not isinstance(maximum, int) - or maximum <= 0 - ): - raise ValueError("maximum_generation_n_final must be a positive integer") - if maximum is None and reason is not None: - raise ValueError( - "static_na_reason_code requires maximum_generation_n_final" - ) - if maximum is not None and ( - not isinstance(reason, str) or not reason.strip() - ): - raise ValueError( - "maximum_generation_n_final requires a static_na_reason_code" - ) - - -@dataclass(frozen=True, slots=True) -class CellSpec: - dataset_id: str - process: str - n_final: int - process_key: str | None - measurement: MeasurementSpec - workload: Workload - variant: str | None = None - - @property - def cell_id(self) -> str: - parts = [ - self.dataset_id, - f"n{self.n_final}", - self.process_key, - self.variant, - self.workload.value, - ] - return "-".join( - part.replace("_", "-") for part in parts if part is not None - ) diff --git a/pyamplicol/tools/performance_report/phase_state.py b/pyamplicol/tools/performance_report/phase_state.py deleted file mode 100644 index f785b63782..0000000000 --- a/pyamplicol/tools/performance_report/phase_state.py +++ /dev/null @@ -1,630 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Authenticated atomic phase state for one performance-report worker.""" - -from __future__ import annotations - -import hashlib -import hmac -import json -import os -import secrets -import tempfile -import time -from collections.abc import Callable, Iterator, Mapping -from contextlib import AbstractContextManager, contextmanager, nullcontext -from dataclasses import dataclass -from pathlib import Path -from typing import Literal, cast - -WORKER_PHASE_STATE_ABI = "pyamplicol-report-worker-phase-state-v1" -WORKER_PHASE_AUTHENTICATION = "hmac-sha256" - -WorkerPhase = Literal[ - "pre-generation", - "generation", - "post-generation", - "profiling", - "validation", - "complete", -] - -_PHASE_FIELDS = frozenset( - { - "abi", - "run_id", - "worker_pid", - "sequence", - "phase", - "transition_monotonic_ns", - "generation_started_monotonic_ns", - "generation_finished_monotonic_ns", - "profiling_started_monotonic_ns", - "profiling_finished_monotonic_ns", - "validation_started_monotonic_ns", - "validation_finished_monotonic_ns", - } -) -_STATE_FIELDS = _PHASE_FIELDS | {"authentication"} - - -class WorkerPhaseStateError(RuntimeError): - """Raised when worker phase evidence is absent, malformed, or unauthenticated.""" - - -@dataclass(frozen=True, slots=True) -class WorkerPhaseChannel: - """Parent-issued credentials for one worker phase-state file.""" - - path: Path - run_id: str - authentication_key: str - - def __post_init__(self) -> None: - if not self.path.is_absolute(): - raise ValueError("worker phase-state path must be absolute") - if len(self.run_id) != 32 or any( - character not in "0123456789abcdef" for character in self.run_id - ): - raise ValueError("worker phase-state run_id must be 128-bit lowercase hex") - if len(self.authentication_key) != 64 or any( - character not in "0123456789abcdef" for character in self.authentication_key - ): - raise ValueError( - "worker phase-state authentication key must be 256-bit lowercase hex" - ) - - @classmethod - def create(cls, path: Path) -> WorkerPhaseChannel: - """Create fresh credentials bound to ``path``.""" - - return cls( - path=path.expanduser().resolve(strict=False), - run_id=secrets.token_hex(16), - authentication_key=secrets.token_hex(32), - ) - - -@dataclass(frozen=True, slots=True) -class WorkerPhaseState: - """One authenticated phase transition written by the worker.""" - - run_id: str - worker_pid: int - sequence: int - phase: WorkerPhase - transition_monotonic_ns: int - generation_started_monotonic_ns: int | None - generation_finished_monotonic_ns: int | None - profiling_started_monotonic_ns: int | None - profiling_finished_monotonic_ns: int | None - validation_started_monotonic_ns: int | None - validation_finished_monotonic_ns: int | None - sha256: str - - def generation_elapsed_seconds(self, *, now_seconds: float) -> float | None: - """Return generation duration through the authenticated boundary.""" - - if self.generation_started_monotonic_ns is None: - return None - stop_ns = self.generation_finished_monotonic_ns - if stop_ns is None: - stop_ns = max( - int(now_seconds * 1_000_000_000), - self.generation_started_monotonic_ns, - ) - return (stop_ns - self.generation_started_monotonic_ns) / 1_000_000_000 - - def stage_elapsed_seconds( - self, - stage: Literal["profiling", "validation"], - *, - now_seconds: float, - ) -> float | None: - """Return an active or closed stage duration from authenticated bounds.""" - - if stage == "profiling": - started_ns = self.profiling_started_monotonic_ns - finished_ns = self.profiling_finished_monotonic_ns - else: - started_ns = self.validation_started_monotonic_ns - finished_ns = self.validation_finished_monotonic_ns - if started_ns is None: - return None - stop_ns = ( - max(int(now_seconds * 1_000_000_000), started_ns) - if finished_ns is None - else finished_ns - ) - return (stop_ns - started_ns) / 1_000_000_000 - - -def _canonical_json(payload: Mapping[str, object]) -> bytes: - return json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def _authentication_digest( - payload: Mapping[str, object], - authentication_key: str, -) -> str: - return hmac.new( - bytes.fromhex(authentication_key), - _canonical_json(payload), - hashlib.sha256, - ).hexdigest() - - -def _atomic_json(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - descriptor, temporary_name = tempfile.mkstemp( - prefix=f".{path.name}.", - suffix=".tmp", - dir=path.parent, - ) - temporary = Path(temporary_name) - try: - with os.fdopen(descriptor, "wb") as stream: - stream.write(_canonical_json(payload) + b"\n") - stream.flush() - os.fsync(stream.fileno()) - temporary.replace(path) - finally: - temporary.unlink(missing_ok=True) - - -def _unsigned_state( - *, - channel: WorkerPhaseChannel, - worker_pid: int, - sequence: int, - phase: WorkerPhase, - transition_monotonic_ns: int, - generation_started_monotonic_ns: int | None, - generation_finished_monotonic_ns: int | None, - profiling_started_monotonic_ns: int | None, - profiling_finished_monotonic_ns: int | None, - validation_started_monotonic_ns: int | None, - validation_finished_monotonic_ns: int | None, -) -> dict[str, object]: - return { - "abi": WORKER_PHASE_STATE_ABI, - "run_id": channel.run_id, - "worker_pid": worker_pid, - "sequence": sequence, - "phase": phase, - "transition_monotonic_ns": transition_monotonic_ns, - "generation_started_monotonic_ns": generation_started_monotonic_ns, - "generation_finished_monotonic_ns": generation_finished_monotonic_ns, - "profiling_started_monotonic_ns": profiling_started_monotonic_ns, - "profiling_finished_monotonic_ns": profiling_finished_monotonic_ns, - "validation_started_monotonic_ns": validation_started_monotonic_ns, - "validation_finished_monotonic_ns": validation_finished_monotonic_ns, - } - - -class WorkerPhaseReporter: - """Publish the worker's one allowed generation interval.""" - - def __init__( - self, - channel: WorkerPhaseChannel, - *, - worker_pid: int | None = None, - clock_ns: Callable[[], int] = time.monotonic_ns, - track_post_generation_stages: bool = False, - generation_gate: Callable[[], AbstractContextManager[None]] | None = None, - ) -> None: - self.channel = channel - self.worker_pid = os.getpid() if worker_pid is None else worker_pid - if self.worker_pid <= 0: - raise ValueError("worker phase-state PID must be positive") - self._clock_ns = clock_ns - self._track_post_generation_stages = track_post_generation_stages - self._generation_gate = generation_gate - self._phase: WorkerPhase = "pre-generation" - self._sequence = 0 - self._generation_started_ns: int | None = None - self._generation_finished_ns: int | None = None - self._profiling_started_ns: int | None = None - self._profiling_finished_ns: int | None = None - self._validation_started_ns: int | None = None - self._validation_finished_ns: int | None = None - self._last_transition_ns = self._clock() - self._write(self._last_transition_ns) - - @property - def phase(self) -> WorkerPhase: - return self._phase - - def _clock(self) -> int: - value = self._clock_ns() - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise WorkerPhaseStateError( - "worker phase-state monotonic clock must return non-negative int" - ) - return value - - def _write(self, transition_ns: int) -> None: - unsigned = _unsigned_state( - channel=self.channel, - worker_pid=self.worker_pid, - sequence=self._sequence, - phase=self._phase, - transition_monotonic_ns=transition_ns, - generation_started_monotonic_ns=self._generation_started_ns, - generation_finished_monotonic_ns=self._generation_finished_ns, - profiling_started_monotonic_ns=self._profiling_started_ns, - profiling_finished_monotonic_ns=self._profiling_finished_ns, - validation_started_monotonic_ns=self._validation_started_ns, - validation_finished_monotonic_ns=self._validation_finished_ns, - ) - _atomic_json( - self.channel.path, - { - **unsigned, - "authentication": { - "kind": WORKER_PHASE_AUTHENTICATION, - "digest": _authentication_digest( - unsigned, - self.channel.authentication_key, - ), - }, - }, - ) - - @contextmanager - def generation(self) -> Iterator[None]: - """Mark one local generation-work interval. - - The interval may be empty when the worker authenticates reuse of an - artifact generated by an earlier measurement. - """ - - gate = ( - nullcontext() if self._generation_gate is None else self._generation_gate() - ) - with gate: - if self._phase != "pre-generation": - raise WorkerPhaseStateError( - "worker phase reporter permits exactly one generation interval" - ) - started_ns = max(self._clock(), self._last_transition_ns) - self._phase = "generation" - self._sequence = 1 - self._generation_started_ns = started_ns - self._last_transition_ns = started_ns - self._write(started_ns) - try: - yield - finally: - finished_ns = max(self._clock(), started_ns) - self._generation_finished_ns = finished_ns - self._phase = "post-generation" - self._sequence = 2 - self._last_transition_ns = finished_ns - self._write(finished_ns) - - def profiling_started(self) -> None: - """Close the generation guard and start the profiling-stage clock.""" - - if not self._track_post_generation_stages: - return - self._transition( - expected="post-generation", - phase="profiling", - sequence=3, - ) - - def validation_started(self) -> None: - """Close profiling and start the post-profile validation-stage clock.""" - - if not self._track_post_generation_stages: - return - self._transition( - expected="profiling", - phase="validation", - sequence=4, - ) - - def complete(self) -> None: - """Mark successful completion of all supervised worker stages.""" - - if not self._track_post_generation_stages: - return - self._transition( - expected="validation", - phase="complete", - sequence=5, - ) - - def _transition( - self, - *, - expected: WorkerPhase, - phase: WorkerPhase, - sequence: int, - ) -> None: - if self._phase != expected: - raise WorkerPhaseStateError( - f"worker phase transition expected {expected!r}, observed " - f"{self._phase!r}" - ) - transition_ns = max(self._clock(), self._last_transition_ns) - if self._generation_finished_ns is not None: - transition_ns = max(transition_ns, self._generation_finished_ns) - if phase == "profiling": - self._profiling_started_ns = transition_ns - elif phase == "validation": - self._profiling_finished_ns = transition_ns - self._validation_started_ns = transition_ns - elif phase == "complete": - self._validation_finished_ns = transition_ns - self._phase = phase - self._sequence = sequence - self._last_transition_ns = transition_ns - self._write(transition_ns) - - -def _required_int(value: object, name: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise WorkerPhaseStateError(f"{name} must be a non-negative integer") - return value - - -def _optional_timestamp(payload: Mapping[str, object], name: str) -> int | None: - value = payload.get(name) - return None if value is None else _required_int(value, name) - - -def _validated_timing( - payload: Mapping[str, object], -) -> tuple[ - WorkerPhase, - int, - int | None, - int | None, - int | None, - int | None, - int | None, - int | None, -]: - raw_phase = payload.get("phase") - if raw_phase not in { - "pre-generation", - "generation", - "post-generation", - "profiling", - "validation", - "complete", - }: - raise WorkerPhaseStateError("worker phase-state phase is unsupported") - phase = cast(WorkerPhase, raw_phase) - sequence = _required_int(payload.get("sequence"), "sequence") - transition_ns = _required_int( - payload.get("transition_monotonic_ns"), - "transition_monotonic_ns", - ) - started_raw = payload.get("generation_started_monotonic_ns") - finished_raw = payload.get("generation_finished_monotonic_ns") - started_ns = ( - None - if started_raw is None - else _required_int(started_raw, "generation_started_monotonic_ns") - ) - finished_ns = ( - None - if finished_raw is None - else _required_int(finished_raw, "generation_finished_monotonic_ns") - ) - profiling_started_ns = _optional_timestamp( - payload, - "profiling_started_monotonic_ns", - ) - profiling_finished_ns = _optional_timestamp( - payload, - "profiling_finished_monotonic_ns", - ) - validation_started_ns = _optional_timestamp( - payload, - "validation_started_monotonic_ns", - ) - validation_finished_ns = _optional_timestamp( - payload, - "validation_finished_monotonic_ns", - ) - expected_sequence = { - "pre-generation": 0, - "generation": 1, - "post-generation": 2, - "profiling": 3, - "validation": 4, - "complete": 5, - }[phase] - if sequence != expected_sequence: - raise WorkerPhaseStateError( - "worker phase-state phase and sequence are inconsistent" - ) - if phase == "pre-generation": - if any( - timestamp is not None - for timestamp in ( - started_ns, - finished_ns, - profiling_started_ns, - profiling_finished_ns, - validation_started_ns, - validation_finished_ns, - ) - ): - raise WorkerPhaseStateError( - "pre-generation state cannot contain generation timestamps" - ) - elif phase == "generation": - if ( - started_ns != transition_ns - or finished_ns is not None - or any( - timestamp is not None - for timestamp in ( - profiling_started_ns, - profiling_finished_ns, - validation_started_ns, - validation_finished_ns, - ) - ) - ): - raise WorkerPhaseStateError( - "generation state has inconsistent generation timestamps" - ) - elif ( - started_ns is None - or finished_ns is None - or finished_ns < started_ns - or finished_ns > transition_ns - or (phase == "post-generation" and finished_ns != transition_ns) - ): - raise WorkerPhaseStateError( - "post-generation state has inconsistent generation timestamps" - ) - if phase == "post-generation": - stage_timestamps = ( - profiling_started_ns, - profiling_finished_ns, - validation_started_ns, - validation_finished_ns, - ) - valid_stages = all(timestamp is None for timestamp in stage_timestamps) - elif phase == "profiling": - valid_stages = ( - profiling_started_ns == transition_ns - and profiling_finished_ns is None - and validation_started_ns is None - and validation_finished_ns is None - ) - elif phase == "validation": - valid_stages = ( - profiling_started_ns is not None - and profiling_finished_ns is not None - and profiling_started_ns <= profiling_finished_ns - and profiling_finished_ns == transition_ns - and validation_started_ns == transition_ns - and validation_finished_ns is None - ) - elif phase == "complete": - valid_stages = ( - profiling_started_ns is not None - and profiling_finished_ns is not None - and profiling_started_ns <= profiling_finished_ns - and validation_started_ns == profiling_finished_ns - and validation_finished_ns == transition_ns - and validation_started_ns <= validation_finished_ns - ) - else: - valid_stages = True - if not valid_stages: - raise WorkerPhaseStateError( - "worker phase-state has inconsistent profiling/validation timestamps" - ) - return ( - phase, - transition_ns, - started_ns, - finished_ns, - profiling_started_ns, - profiling_finished_ns, - validation_started_ns, - validation_finished_ns, - ) - - -def read_worker_phase_state( - channel: WorkerPhaseChannel, - *, - expected_pid: int, -) -> WorkerPhaseState: - """Read and authenticate the current atomic worker phase state.""" - - if expected_pid <= 0: - raise ValueError("expected worker PID must be positive") - try: - raw = channel.path.read_bytes() - except FileNotFoundError: - raise - except OSError as error: - raise WorkerPhaseStateError( - f"cannot read worker phase-state file: {error}" - ) from error - if len(raw) > 64 * 1024: - raise WorkerPhaseStateError("worker phase-state file is unreasonably large") - try: - decoded = json.loads(raw) - except (UnicodeDecodeError, json.JSONDecodeError) as error: - raise WorkerPhaseStateError( - "worker phase-state file is not valid JSON" - ) from error - if not isinstance(decoded, Mapping) or set(decoded) != _STATE_FIELDS: - raise WorkerPhaseStateError( - "worker phase-state fields do not match the authenticated ABI" - ) - unsigned = {field: decoded[field] for field in _PHASE_FIELDS} - authentication = decoded.get("authentication") - if ( - not isinstance(authentication, Mapping) - or set(authentication) != {"kind", "digest"} - or authentication.get("kind") != WORKER_PHASE_AUTHENTICATION - or not isinstance(authentication.get("digest"), str) - or not hmac.compare_digest( - str(authentication["digest"]), - _authentication_digest(unsigned, channel.authentication_key), - ) - ): - raise WorkerPhaseStateError("worker phase-state authentication is invalid") - if decoded.get("abi") != WORKER_PHASE_STATE_ABI: - raise WorkerPhaseStateError("worker phase-state ABI is unsupported") - if decoded.get("run_id") != channel.run_id: - raise WorkerPhaseStateError("worker phase-state run_id does not match") - worker_pid = _required_int(decoded.get("worker_pid"), "worker_pid") - if worker_pid != expected_pid: - raise WorkerPhaseStateError( - "worker phase-state PID does not match supervised worker" - ) - ( - phase, - transition_ns, - started_ns, - finished_ns, - profiling_started_ns, - profiling_finished_ns, - validation_started_ns, - validation_finished_ns, - ) = _validated_timing(decoded) - return WorkerPhaseState( - run_id=channel.run_id, - worker_pid=worker_pid, - sequence=int(decoded["sequence"]), - phase=phase, - transition_monotonic_ns=transition_ns, - generation_started_monotonic_ns=started_ns, - generation_finished_monotonic_ns=finished_ns, - profiling_started_monotonic_ns=profiling_started_ns, - profiling_finished_monotonic_ns=profiling_finished_ns, - validation_started_monotonic_ns=validation_started_ns, - validation_finished_monotonic_ns=validation_finished_ns, - sha256=hashlib.sha256(raw).hexdigest(), - ) - - -__all__ = [ - "WORKER_PHASE_AUTHENTICATION", - "WORKER_PHASE_STATE_ABI", - "WorkerPhaseChannel", - "WorkerPhaseReporter", - "WorkerPhaseState", - "WorkerPhaseStateError", - "read_worker_phase_state", -] diff --git a/pyamplicol/tools/performance_report/phase_timeline.py b/pyamplicol/tools/performance_report/phase_timeline.py deleted file mode 100644 index fb6189590d..0000000000 --- a/pyamplicol/tools/performance_report/phase_timeline.py +++ /dev/null @@ -1,359 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Directly measured phase evidence for the manual campaign dashboard.""" - -from __future__ import annotations - -import json -import math -from collections.abc import Mapping -from pathlib import Path - -from .models import ExecutionMode - -PHASE_TIMELINE_SCHEMA = "pyamplicol-manual-campaign-phase-timeline-v1" - - -def _seconds(value: object) -> float | None: - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - result = float(value) - if not math.isfinite(result) or result < 0.0: - return None - return result - - -def _count(value: object) -> int | None: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - return None - return value - - -def _mapping(value: object) -> Mapping[str, object]: - return value if isinstance(value, Mapping) else {} - - -def _legacy_profile_outer_seconds(measurement: Mapping[str, object]) -> float | None: - chunks = measurement.get("chunks") - if not isinstance(chunks, list) or not chunks: - return None - durations: list[float] = [] - for chunk in chunks: - values = _mapping(chunk) - elapsed = _seconds(values.get("elapsed_seconds")) - if elapsed is None: - return None - durations.append(elapsed) - return math.fsum(durations) - - -def _entry( - key: str, - label: str, - seconds: float | None, - *, - status: str, - source: str, - detail: str | None = None, - included_in: str | None = None, - cpu_seconds: float | None = None, - peak_memory_bytes: int | None = None, -) -> dict[str, object]: - return { - "key": key, - "label": label, - "seconds": seconds, - "status": status, - "source": source, - "detail": detail, - "included_in": included_in, - "cpu_seconds": cpu_seconds, - "peak_memory_bytes": peak_memory_bytes, - } - - -def _progress_generation_children(path: Path | None) -> tuple[dict[str, object], ...]: - """Read direct progress clocks for generation children once, if available.""" - - if path is None or not path.is_file(): - return () - starts: dict[str, tuple[str, str | None]] = {} - ended: dict[str, float] = {} - order: list[str] = [] - try: - with path.open("r", encoding="utf-8") as stream: - for line in stream: - try: - event = json.loads(line) - except (UnicodeError, json.JSONDecodeError): - continue - if not isinstance(event, Mapping): - continue - task_id = event.get("task_id") - if not isinstance(task_id, str): - continue - if event.get("event") == "start": - description = event.get("description") - parent = event.get("parent_task_id") - starts[task_id] = ( - description if isinstance(description, str) else task_id, - parent if isinstance(parent, str) else None, - ) - order.append(task_id) - elif event.get("event") == "end" and event.get("success") is not False: - elapsed = _seconds(event.get("elapsed_seconds")) - if elapsed is not None: - ended[task_id] = elapsed - except OSError: - return () - - rows: list[dict[str, object]] = [] - for task_id in order: - description, parent = starts[task_id] - if parent != "generation" or task_id not in ended: - continue - rows.append( - _entry( - f"generation-step:{task_id.removeprefix('generation:')}", - description, - ended[task_id], - status="measured", - source="worker progress direct elapsed clock", - detail="included in Generation", - included_in="generation", - ) - ) - return tuple(rows) - - -def build_phase_timeline( - result: Mapping[str, object], - *, - progress_path: Path | None = None, -) -> dict[str, object]: - """Build a compact timeline without deriving one clock from another.""" - - provenance = _mapping(result.get("provenance")) - manual = _mapping(provenance.get("manual_campaign")) - identity = _mapping(manual.get("cell_identity")) - runtime = _mapping(provenance.get("runtime_profile")) - resources = _mapping(result.get("resources")) - execution_mode = str(identity.get("execution_mode") or "") - entries: list[dict[str, object]] = [] - - preparation = _seconds(provenance.get("model_preparation_seconds")) - preparation_reused = provenance.get("model_preparation_reused") is True - if execution_mode == ExecutionMode.AMPLICOL.value: - entries.append( - _entry( - "model-preparation", - "Model preparation", - None, - status="not_applicable", - source="legacy adapter", - detail="not applicable to original AmpliCol", - ) - ) - else: - entries.append( - _entry( - "model-preparation", - "Model preparation", - preparation, - status=( - "reused" - if preparation_reused - else ("measured" if preparation is not None else "unavailable") - ), - source="result provenance model_preparation_seconds", - detail=( - "prepared model reused" - if preparation_reused - else ( - None - if preparation is not None - else "not recorded by this result" - ) - ), - ) - ) - - generation = _seconds(result.get("generation_seconds")) - entries.append( - _entry( - "generation", - "Generation", - generation, - status="measured" if generation is not None else "unavailable", - source="result generation_seconds", - ) - ) - entries.extend(_progress_generation_children(progress_path)) - - if execution_mode == ExecutionMode.AMPLICOL.value: - warmup = _mapping(runtime.get("warmup")) - warmup_seconds = _seconds(warmup.get("elapsed_seconds")) - measurement = _mapping(runtime.get("measurement")) - measurement_seconds = _legacy_profile_outer_seconds(measurement) - entries.extend( - ( - _entry( - "runtime-warmup", - "Runtime warm-up", - warmup_seconds, - status=( - "measured" if warmup_seconds is not None else "unavailable" - ), - source="legacy warmup subprocess wall clock", - ), - _entry( - "runtime-calibration", - "Runtime calibration", - None, - status="not_applicable", - source="legacy adaptive point calculation", - detail="no timed calibration phase", - ), - _entry( - "runtime-measurement", - "Timed profiling", - measurement_seconds, - status=( - "measured" if measurement_seconds is not None else "unavailable" - ), - source="sum of legacy profiling subprocess wall clocks", - detail=( - None - if _count(measurement.get("chunk_count")) is None - else f"{_count(measurement.get('chunk_count'))} chunks" - ), - ), - ) - ) - else: - warmup_seconds = _seconds(runtime.get("warmup_elapsed_seconds")) - calibration_seconds = _seconds(runtime.get("calibration_outer_elapsed_seconds")) - if calibration_seconds is None and execution_mode in { - ExecutionMode.COMPILED.value, - ExecutionMode.EAGER.value, - }: - calibration_seconds = _seconds(runtime.get("calibration_elapsed_seconds")) - measurement_seconds = _seconds(runtime.get("achieved_runtime_seconds")) - if measurement_seconds is None: - measurement_seconds = _seconds( - runtime.get("measurement_phase_elapsed_seconds") - ) - profile_total = _seconds(runtime.get("profile_total_elapsed_seconds")) - attribution = _seconds(runtime.get("profile_attribution_elapsed_seconds")) - if attribution is None: - attribution = _seconds(runtime.get("evaluator_elapsed_seconds")) - sample_count = _count(runtime.get("completed_sample_count")) - entries.extend( - ( - _entry( - "runtime-warmup", - "Runtime warm-up", - warmup_seconds, - status=( - "measured" if warmup_seconds is not None else "unavailable" - ), - source="benchmark warm-up wall clock", - ), - _entry( - "runtime-calibration", - "Runtime calibration", - calibration_seconds, - status=( - "measured" if calibration_seconds is not None else "unavailable" - ), - source="benchmark calibration wall clock", - detail=( - None - if _count(runtime.get("calibration_block_count")) is None - else ( - f"{_count(runtime.get('calibration_block_count'))} blocks" - ) - ), - ), - _entry( - "runtime-measurement", - "Timed headline measurement", - measurement_seconds, - status=( - "measured" if measurement_seconds is not None else "unavailable" - ), - source="accumulated benchmark headline outer wall clock", - detail=( - None if sample_count is None else f"{sample_count} samples" - ), - ), - _entry( - "runtime-attribution", - "Profiling attribution", - attribution, - status="measured" if attribution is not None else "unavailable", - source="native profile-call outer wall clock", - detail="separate from wall/evaluator-total/core metrics", - ), - _entry( - "runtime-profile-total", - "Complete runtime profile", - profile_total, - status=("measured" if profile_total is not None else "unavailable"), - source="profile operation outer wall clock", - detail="contains warm-up, calibration, measurement and attribution", - ), - ) - ) - - validation_completed = result.get("validation") is not None - entries.extend( - ( - _entry( - "post-profile-validation", - "Post-profile validation", - None, - status="completed" if validation_completed else "unavailable", - source="result validation status", - detail=( - "completed; duration not separately timed" - if validation_completed - else "status and duration not separately recorded" - ), - ), - _entry( - "attempt-publication", - "Result publication", - None, - status="completed", - source="atomic attempt publication", - detail="completed; duration not separately timed", - ), - ) - ) - - worker_wall = _seconds(resources.get("wall_seconds")) - peak_rss = _count(resources.get("peak_rss_bytes")) - peak_guard = _count(resources.get("peak_guard_bytes")) - cpu_seconds = _seconds(resources.get("cpu_seconds")) - entries.append( - _entry( - "worker-supervision", - "Worker supervision", - worker_wall, - status="observed" if worker_wall is not None else "unavailable", - source="resource supervisor sample", - detail="overall observed worker wall; phase rows may overlap", - cpu_seconds=cpu_seconds, - peak_memory_bytes=peak_guard or peak_rss, - ) - ) - return { - "schema": PHASE_TIMELINE_SCHEMA, - "entries": entries, - "total_worker_wall_seconds": worker_wall, - "peak_rss_bytes": peak_rss, - "peak_guard_bytes": peak_guard, - } - - -__all__ = ["PHASE_TIMELINE_SCHEMA", "build_phase_timeline"] diff --git a/pyamplicol/tools/performance_report/prepared.py b/pyamplicol/tools/performance_report/prepared.py deleted file mode 100644 index 97e5ba4ae4..0000000000 --- a/pyamplicol/tools/performance_report/prepared.py +++ /dev/null @@ -1,410 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Deterministic, lock-protected prepared-model assets for report workers.""" - -from __future__ import annotations - -import hashlib -import json -import os -import platform -import tempfile -import uuid -from collections.abc import Iterator, Mapping -from contextlib import contextmanager -from pathlib import Path -from typing import TYPE_CHECKING, Protocol - -if TYPE_CHECKING: - from pyamplicol.reporting import ProgressSink - -from .artifacts import ArtifactStore -from .models import ModelKey -from .runner import _model_source_path - -PREPARED_RECORD_SCHEMA = "pyamplicol-report-prepared-model-v1" -PUBLIC_MODEL_COMPILE_COMMAND_PATH = "pyamplicol-model-compile-parse-resolve-dispatch-v1" - - -class PreparedModelError(RuntimeError): - """Raised when a report prepared-model bundle is absent or invalid.""" - - -class CompilableModelSource(Protocol): - def compile( - self, - *, - cache_dir: os.PathLike[str] | str | None = None, - use_cache: bool = True, - require_supported: bool = True, - prepared_output: os.PathLike[str] | str | None = None, - evaluator: object | None = None, - ) -> object: ... - - -class _PublicCliModelCompiler: - """Compile a report bundle through the real public model CLI path.""" - - command_path = PUBLIC_MODEL_COMPILE_COMMAND_PATH - - def __init__(self, source: str, *, progress: ProgressSink | None = None) -> None: - self.source = source - self.progress = progress - - def compile( - self, - *, - cache_dir: os.PathLike[str] | str | None = None, - use_cache: bool = True, - require_supported: bool = True, - prepared_output: os.PathLike[str] | str | None = None, - evaluator: object | None = None, - ) -> object: - if not require_supported: - raise PreparedModelError( - "report prepared-model compilation must require supported models" - ) - if prepared_output is None or evaluator is None: - raise PreparedModelError( - "public model compilation requires an output and evaluator" - ) - - from pyamplicol.cli import CliInvocation, parse_cli - from pyamplicol.cli.handlers import DefaultCliServices, dispatch - from pyamplicol.reporting import NullProgressSink - - output = Path(prepared_output).expanduser().resolve(strict=False) - backend = getattr(getattr(evaluator, "backend", None), "value", None) - execution_mode = getattr( - getattr(evaluator, "execution_mode", None), - "value", - None, - ) - optimization = getattr(evaluator, "optimization", None) - cores = getattr(optimization, "cores", None) - jit = getattr(evaluator, "jit", None) - optimization_level = getattr(jit, "optimization_level", None) - compression = getattr(jit, "compress", None) - if ( - backend != "jit" - or execution_mode not in {"compiled", "eager", "recurrence"} - or isinstance(cores, bool) - or not isinstance(cores, int) - or cores < 1 - or isinstance(optimization_level, bool) - or not isinstance(optimization_level, int) - or (compression != "auto" and not isinstance(compression, bool)) - ): - raise PreparedModelError( - "report prepared-model CLI requires a concrete JIT evaluator" - ) - arguments = [ - "model", - "compile", - self.source, - os.fspath(output), - "--backend", - backend, - "--cores", - str(cores), - "--jit-optimization-level", - str(optimization_level), - "--set", - f"evaluator.execution_mode={execution_mode}", - "--set", - f"evaluator.jit.compress={str(compression).lower()}", - "--model-cache" if use_cache else "--no-model-cache", - ] - if cache_dir is not None: - arguments.extend(("--model-cache-dir", os.fspath(cache_dir))) - invocation = parse_cli(tuple(arguments)) - if not isinstance(invocation, CliInvocation): - raise PreparedModelError( - "public model compile parser returned a non-command invocation" - ) - resolution = invocation.resolve() - if resolution.requested.evaluator != evaluator: - raise PreparedModelError( - "public model compile arguments changed the report evaluator settings" - ) - result = dispatch( - resolution.effective, - DefaultCliServices(resolution=resolution), - self.progress or NullProgressSink(), - dry_run=invocation.dry_run, - ) - if not isinstance(result, Mapping): - raise PreparedModelError( - "public model compile returned a non-object result" - ) - raw_output = result.get("output") - if ( - not isinstance(raw_output, str) - or Path(raw_output).expanduser().resolve(strict=False) != output - ): - raise PreparedModelError( - "public model compile did not publish the requested bundle" - ) - return result - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def _canonical_bytes(payload: object) -> bytes: - return ( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ).encode("ascii") - - -def _atomic_write(path: Path, payload: object) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - descriptor, temporary_name = tempfile.mkstemp( - dir=path.parent, - prefix=f".{path.name}.", - suffix=".tmp", - ) - temporary = Path(temporary_name) - try: - with os.fdopen(descriptor, "wb") as stream: - stream.write(_canonical_bytes(payload)) - stream.flush() - os.fsync(stream.fileno()) - temporary.replace(path) - finally: - temporary.unlink(missing_ok=True) - - -def prepared_identity( - *, - model: ModelKey, - backend: str, - jit_optimization_level: int, - source_digest: str, - producer_revision: str, - target_platform: str | None = None, -) -> dict[str, object]: - if len(source_digest) != 64: - raise ValueError("source_digest must be SHA-256") - if not producer_revision: - raise ValueError("producer_revision must not be empty") - return { - "model": model.value, - "backend": backend, - "jit_optimization_level": jit_optimization_level, - "source_digest": source_digest, - "producer_revision": producer_revision, - "target_platform": ( - target_platform - if target_platform is not None - else f"{platform.system().lower()}-{platform.machine().lower()}" - ), - } - - -def _record_path(bundle_path: Path) -> Path: - return bundle_path.with_suffix(bundle_path.suffix + ".report.json") - - -def validate_prepared_record( - bundle_path: Path, - *, - expected_identity: Mapping[str, object], -) -> dict[str, object]: - record_path = _record_path(bundle_path) - try: - record = json.loads(record_path.read_text(encoding="ascii")) - except (OSError, json.JSONDecodeError) as error: - raise PreparedModelError( - f"cannot read prepared-model record: {error}" - ) from error - if not isinstance(record, Mapping): - raise PreparedModelError("prepared-model record must be an object") - if record.get("schema") != PREPARED_RECORD_SCHEMA: - raise PreparedModelError("prepared-model record schema is unsupported") - if record.get("identity") != dict(expected_identity): - raise PreparedModelError("prepared-model identity does not match") - if not bundle_path.is_file() or bundle_path.is_symlink(): - raise PreparedModelError("prepared-model bundle is not a regular file") - if record.get("bundle_size") != bundle_path.stat().st_size: - raise PreparedModelError("prepared-model bundle size does not match") - if record.get("bundle_sha256") != _sha256(bundle_path): - raise PreparedModelError("prepared-model bundle digest does not match") - return dict(record) - - -@contextmanager -def ensure_prepared_model( - *, - store: ArtifactStore, - bundle_path: Path, - source: CompilableModelSource, - evaluator: object, - identity: Mapping[str, object], - model_cache_dir: Path, -) -> Iterator[tuple[Path, bool]]: - """Create one prepared bundle atomically or reuse its validated record.""" - - lock_name = ( - "prepared-" + hashlib.sha256(_canonical_bytes(dict(identity))).hexdigest() - ) - with store.named_lock(lock_name): - try: - validate_prepared_record(bundle_path, expected_identity=identity) - except PreparedModelError: - reused = False - bundle_path.parent.mkdir(parents=True, exist_ok=True) - staging = bundle_path.with_name( - f".{bundle_path.stem}.{uuid.uuid4().hex}.staging.pyamplicol-model" - ) - try: - source.compile( - cache_dir=model_cache_dir, - use_cache=True, - require_supported=True, - prepared_output=staging, - evaluator=evaluator, - ) - if not staging.is_file() or staging.is_symlink(): - raise PreparedModelError( - "prepared-model compiler did not publish a regular bundle" - ) - digest = _sha256(staging) - size = staging.stat().st_size - staging.replace(bundle_path) - _atomic_write( - _record_path(bundle_path), - { - "schema": PREPARED_RECORD_SCHEMA, - "identity": dict(identity), - "bundle_sha256": digest, - "bundle_size": size, - **( - {"command_path": command_path} - if isinstance( - command_path := getattr(source, "command_path", None), - str, - ) - else {} - ), - }, - ) - validate_prepared_record( - bundle_path, - expected_identity=identity, - ) - finally: - staging.unlink(missing_ok=True) - else: - reused = True - yield bundle_path, reused - - -def ensure_report_prepared_model( - *, - store: ArtifactStore, - repo_root: Path, - worker_cores: int, - model: ModelKey, - producer_revision: str | None, - progress: ProgressSink | None = None, -) -> tuple[Path, bool]: - """Create or reuse one portable report JIT O2 prepared bundle.""" - - if producer_revision is None: - raise PreparedModelError( - "report prepared-model creation requires an explicit producer revision" - ) - from pyamplicol.config import ( - EvaluatorBackend, - EvaluatorConfig, - EvaluatorExecutionMode, - EvaluatorOptimizationConfig, - JITConfig, - ) - - revision = producer_revision - if not revision: - raise ValueError("producer_revision must not be empty") - if model is ModelKey.BUILTIN_SM: - source_path = None - source = _PublicCliModelCompiler("built-in-sm", progress=progress) - digest = hashlib.sha256(f"built-in-sm:{revision}".encode("ascii")).hexdigest() - stem = "built-in-sm" - elif model is ModelKey.UFO_SM: - source_path = _model_source_path(repo_root, model) - if source_path is None: - raise PreparedModelError("UFO-SM model resource is unavailable") - source = _PublicCliModelCompiler(os.fspath(source_path), progress=progress) - digest = _sha256(source_path) - stem = "ufo-sm" - else: - raise ValueError("report prepared packs support built-in SM and UFO-SM") - identity = prepared_identity( - model=model, - backend="jit", - jit_optimization_level=2, - source_digest=digest, - producer_revision=revision, - ) - identity_digest = hashlib.sha256(_canonical_bytes(identity)).hexdigest()[:20] - bundle_path = ( - store.artifact_root - / "prepared-models" - / f"{stem}-jit-o2-{identity_digest}.pyamplicol-model" - ) - evaluator = EvaluatorConfig( - backend=EvaluatorBackend.JIT, - execution_mode=EvaluatorExecutionMode.RECURRENCE, - optimization=EvaluatorOptimizationConfig(cores=worker_cores), - jit=JITConfig(optimization_level=2), - ) - with ensure_prepared_model( - store=store, - bundle_path=bundle_path, - source=source, - evaluator=evaluator, - identity=identity, - model_cache_dir=store.artifact_root / "model-cache", - ) as result: - return result - - -def ensure_report_ufo_sm_prepared_model( - *, - store: ArtifactStore, - repo_root: Path, - worker_cores: int, -) -> tuple[Path, bool]: - from pyamplicol._internal.versions import active_source_revision - - return ensure_report_prepared_model( - store=store, - repo_root=repo_root, - worker_cores=worker_cores, - model=ModelKey.UFO_SM, - producer_revision=active_source_revision(), - ) - - -__all__ = [ - "PREPARED_RECORD_SCHEMA", - "PUBLIC_MODEL_COMPILE_COMMAND_PATH", - "PreparedModelError", - "ensure_prepared_model", - "ensure_report_prepared_model", - "ensure_report_ufo_sm_prepared_model", - "prepared_identity", - "validate_prepared_record", -] diff --git a/pyamplicol/tools/performance_report/publication.py b/pyamplicol/tools/performance_report/publication.py deleted file mode 100644 index 1dc5400b1c..0000000000 --- a/pyamplicol/tools/performance_report/publication.py +++ /dev/null @@ -1,853 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Fail-closed publication projection and local-path resolution.""" - -from __future__ import annotations - -import hashlib -import json -import re -from collections.abc import Mapping, Sequence -from pathlib import Path, PurePosixPath -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from .service import ReportPaths - -_ARTIFACT_ROOT = "${PYAMPLICOL_REPORT_ARTIFACT_ROOT}" -_COORDINATION_ROOT = "${PYAMPLICOL_REPORT_COORDINATION_ROOT}" -_SOURCE_ROOT = "${PYAMPLICOL_SOURCE_ROOT}" -_REDACTED_ROOT = "${LOCAL_PATH_REDACTED}" -_PORTABLE_ROOTS = ( - _ARTIFACT_ROOT, - _COORDINATION_ROOT, - _SOURCE_ROOT, - _REDACTED_ROOT, -) -PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI = ( - "pyamplicol-portable-current-reproduction-recipe-v1" -) -_REPRODUCTION_RECIPE_POINTER = ( - "provenance", - "manual_campaign", - "public_cli_reproduction", -) -_REPRODUCTION_STAGES = ("prepare", "generate", "profile") - -# These are the only measurement fields whose machine-local value is not part -# of an authenticated identity or numerical result. The patterns are relative -# to ``measurement``; ``*`` matches one sequence element. Adding a locator to -# the report schema must therefore make an explicit, reviewable change here. -_LOCATOR_POINTERS = ( - ("artifact", "path"), - ("artifact", "log_path"), - # MadGraph retains its generated standalone tree as an ordinary artifact - # locator. It is diagnostic/reusable campaign state, not numerical - # identity, and must be projected just like the enclosing artifact path. - ("artifact", "standalone"), - # Both supported and scope-unavailable original-AmpliCol measurements - # attach their authenticated structural proof at this artifact locator. - ("artifact", "legacy_structural_proof"), - ("provenance", "worker_log"), - ("provenance", "repository"), - # MadGraph records the selected installation and model directory for - # diagnostics. Neither path contributes to the sealed numerical result; - # installations outside the report/source roots are therefore redacted. - ("provenance", "installation"), - ("provenance", "model", "source_directory"), - ("provenance", "requested_config", "model", "source"), - ("provenance", "requested_config", "model", "cache_dir"), - ("provenance", "effective_config", "model", "source"), - ("provenance", "effective_config", "model", "cache_dir"), - ("provenance", "worker_environment", "LD_LIBRARY_PATH"), - ("provenance", "worker_environment", "DYLD_LIBRARY_PATH"), - ("provenance", "commands", "*", "cwd"), - # Legacy command records are diagnostic, not authenticated evidence. Their - # executable, first operand, and the all-flow probe's process/momenta file - # operands are the only schema positions that carry absolute launch paths. - ("provenance", "commands", "*", "args", 0), - ("provenance", "commands", "*", "args", 1), - ("provenance", "commands", "*", "args", 5), - ("provenance", "commands", "*", "args", 6), - ("provenance", "commands", "*", "environment", "LD_LIBRARY_PATH"), - ("provenance", "commands", "*", "environment", "DYLD_LIBRARY_PATH"), - ("provenance", "runtime_profile", "measurement", "args", 0), - ("provenance", "runtime_profile", "measurement", "args", 5), - ("provenance", "runtime_profile", "measurement", "args", 6), - ("provenance", "runtime_profile", "measurement", "cwd"), - ( - "provenance", - "runtime_profile", - "measurement", - "environment", - "LD_LIBRARY_PATH", - ), - ( - "provenance", - "runtime_profile", - "measurement", - "environment", - "DYLD_LIBRARY_PATH", - ), - ( - "provenance", - "runtime_profile", - "measurement", - "chunks", - "*", - "args", - 0, - ), - ( - "provenance", - "runtime_profile", - "measurement", - "chunks", - "*", - "args", - 5, - ), - ( - "provenance", - "runtime_profile", - "measurement", - "chunks", - "*", - "args", - 6, - ), - ("provenance", "runtime_profile", "measurement", "chunks", "*", "cwd"), - ( - "provenance", - "runtime_profile", - "measurement", - "chunks", - "*", - "environment", - "LD_LIBRARY_PATH", - ), - ( - "provenance", - "runtime_profile", - "measurement", - "chunks", - "*", - "environment", - "DYLD_LIBRARY_PATH", - ), - ("provenance", "runtime_profile", "warmup", "args", 0), - ("provenance", "runtime_profile", "warmup", "args", 5), - ("provenance", "runtime_profile", "warmup", "args", 6), - ("provenance", "runtime_profile", "warmup", "cwd"), - ( - "provenance", - "runtime_profile", - "warmup", - "environment", - "LD_LIBRARY_PATH", - ), - ( - "provenance", - "runtime_profile", - "warmup", - "environment", - "DYLD_LIBRARY_PATH", - ), - ( - "provenance", - "manual_campaign", - "public_cli_reproduction", - "prepare", - "*", - ), - ( - "provenance", - "manual_campaign", - "public_cli_reproduction", - "generate", - "*", - ), - ( - "provenance", - "manual_campaign", - "public_cli_reproduction", - "profile", - "*", - ), -) - -# Generation retains its output directory in the requested/effective CLI -# configuration. Unlike diagnostic locator fields, these values are expected -# to identify the published result's artifact and must never be silently -# redacted: an absolute path is accepted only when it is rooted in this -# profile's artifact store. -_STRICT_ARTIFACT_LOCATOR_POINTERS = ( - ("provenance", "requested_config", "generation", "output"), - ("provenance", "effective_config", "generation", "output"), -) - -# These exact-path fields are consumed when a current is reused. Portable -# current records therefore require an explicit rooted locator here; a raw -# absolute path or a merely relative path must never be interpreted relative -# to the process working directory after a campaign has moved. -_CURRENT_ROOTED_PATH_POINTERS = ( - ("artifact", "path"), - ("artifact", "log_path"), - ("artifact", "legacy_structural_proof"), - ("provenance", "worker_log"), - *_STRICT_ARTIFACT_LOCATOR_POINTERS, -) - -_SCHEME_URI_RE = re.compile(r"[A-Za-z][A-Za-z0-9+.-]*://[^\s]+") -_FILE_URI_RE = re.compile(r"file:(?://)?/[^\r\n]*", flags=re.IGNORECASE) -_PATH_PREFIX = r"(?P^|[\s:;,\"'=()\[\]{}@]|-[A-Za-z])" -_WINDOWS_PATH_RE = re.compile( - _PATH_PREFIX + r"(?P[A-Z]:[\\/][^\s:;,\"'=\]\[(){}]*)", - flags=re.IGNORECASE | re.MULTILINE, -) -_UNC_PATH_RE = re.compile( - _PATH_PREFIX + r"(?P(?:\\\\|//)[^\s:;,\"'=\]\[(){}]+)", - flags=re.MULTILINE, -) -_POSIX_PATH_RE = re.compile( - _PATH_PREFIX + r"(?P/(?!/)[^\s:;,\"'=\]\[(){}]*)", - flags=re.MULTILINE, -) -_KNOWN_ROOT_SUFFIX = r"(?=$|[/\\:;,\s\"'=)\]}\[])" - - -class PublicationPortabilityError(ValueError): - """A publication value contains a non-whitelisted machine-local path.""" - - -def _known_roots(paths: ReportPaths) -> tuple[tuple[str, str], ...]: - return tuple( - sorted( - ( - (paths.artifact_root.as_posix(), _ARTIFACT_ROOT), - (paths.coordination_root.as_posix(), _COORDINATION_ROOT), - (paths.repo_root.as_posix(), _SOURCE_ROOT), - ), - key=lambda item: len(item[0]), - reverse=True, - ) - ) - - -def _measurement_pointer( - pointer: tuple[str | int, ...], -) -> tuple[str | int, ...]: - if ( - len(pointer) >= 3 - and pointer[0] == "entries" - and isinstance(pointer[1], int) - and pointer[2] == "measurement" - ): - return pointer[3:] - if pointer and pointer[0] == "measurement": - return pointer[1:] - return pointer - - -def _pointer_matches( - pointer: tuple[str | int, ...], - pattern: tuple[str | int, ...], -) -> bool: - return len(pointer) == len(pattern) and all( - expected == "*" or observed == expected - for observed, expected in zip(pointer, pattern, strict=True) - ) - - -def _locator_pointer(pointer: tuple[str | int, ...]) -> bool: - relative = _measurement_pointer(pointer) - return any(_pointer_matches(relative, pattern) for pattern in _LOCATOR_POINTERS) - - -def _strict_artifact_locator_pointer(pointer: tuple[str | int, ...]) -> bool: - relative = _measurement_pointer(pointer) - return any( - _pointer_matches(relative, pattern) - for pattern in _STRICT_ARTIFACT_LOCATOR_POINTERS - ) - - -def _current_rooted_path_pointer(pointer: tuple[str | int, ...]) -> bool: - relative = _measurement_pointer(pointer) - return any( - _pointer_matches(relative, pattern) - for pattern in _CURRENT_ROOTED_PATH_POINTERS - ) - - -def _current_reproduction_recipe_pointer(pointer: tuple[str | int, ...]) -> bool: - return _measurement_pointer(pointer) == _REPRODUCTION_RECIPE_POINTER - - -def _validated_reproduction_argv( - value: Mapping[object, object], -) -> dict[str, tuple[str, ...] | None]: - if value.get("abi") != PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI: - raise PublicationPortabilityError( - "portable current reproduction recipe has no supported structured ABI" - ) - result: dict[str, tuple[str, ...] | None] = {} - for stage in _REPRODUCTION_STAGES: - raw_argv = value.get(stage) - if raw_argv is None: - result[stage] = None - continue - if ( - not isinstance(raw_argv, Sequence) - or isinstance(raw_argv, (str, bytes, bytearray)) - or not raw_argv - or any( - not isinstance(argument, str) or not argument - for argument in raw_argv - ) - ): - raise PublicationPortabilityError( - f"portable current reproduction {stage} argv is malformed" - ) - argv = tuple(raw_argv) - result[stage] = argv - return result - - -def _canonical_bytes(value: object) -> bytes: - try: - rendered = json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - except (TypeError, ValueError): - return b"" - return rendered.encode("ascii") - - -def _digest_matches(value: object, digest: object) -> bool: - if not isinstance(digest, str) or re.fullmatch(r"[0-9a-f]{64}", digest) is None: - return False - payload = _canonical_bytes(value) - return bool(payload) and hashlib.sha256(payload).hexdigest() == digest - - -def _digest_covered_keys( - value: Mapping[object, object], - pointer: tuple[str | int, ...], -) -> frozenset[str]: - """Return authenticated sibling objects that publication must not rewrite.""" - - rendered = {str(key): item for key, item in value.items()} - protected = { - key - for key, item in rendered.items() - if _digest_matches(item, rendered.get(f"{key}_sha256")) - } - relative = _measurement_pointer(pointer) - postflight_key = "runtime_identity_postflight_loaded_module_origin_policy" - if relative == ("provenance",): - postflight = rendered.get(postflight_key) - if isinstance(postflight, Mapping) and _digest_matches( - postflight.get("observations"), - postflight.get("observations_sha256"), - ): - protected.add(postflight_key) - return frozenset(protected) - - -def _json_pointer(pointer: tuple[str | int, ...]) -> str: - return "/" + "/".join( - str(part).replace("~", "~0").replace("/", "~1") for part in pointer - ) - - -def _replace_known_root(value: str, local: str, portable: str) -> str: - # The prefix prevents a root such as /repo from matching the suffix of - # /other/repo. The suffix prevents /repo from corrupting /repo-sibling. - prefix = r"(?P^|[\s:;,\"'=()\[\]{}@]|-[A-Za-z])" - pattern = re.compile( - prefix + rf"(?P{re.escape(local)}){_KNOWN_ROOT_SUFFIX}", - flags=re.MULTILINE, - ) - return pattern.sub( - lambda match: f"{match.group('prefix')}{portable}", - value, - ) - - -def _portable_locator_string(value: str, paths: ReportPaths) -> str: - result = value - for local, portable in _known_roots(paths): - result = _replace_known_root(result, local, portable) - windows_local = local.replace("/", "\\") - if windows_local != local: - result = _replace_known_root(result, windows_local, portable) - if _absolute_path_fragments(result): - # Unknown local roots are deliberately irreversible. Redact the whole - # locator field instead of attempting a lossy partial path parser. - return _REDACTED_ROOT - return result - - -def _portable_artifact_locator_string( - value: str, - paths: ReportPaths, - *, - pointer: tuple[str | int, ...], -) -> str: - """Project one exact artifact path, rejecting every external absolute root.""" - - has_absolute_path = bool(_absolute_path_fragments(value)) - has_portable_root = any(marker in value for marker in _PORTABLE_ROOTS) - if not has_absolute_path and not has_portable_root: - return value - portable = _portable_locator_string(value, paths) - if not (portable == _ARTIFACT_ROOT or portable.startswith(f"{_ARTIFACT_ROOT}/")): - raise PublicationPortabilityError( - "artifact path outside publication artifact root at " - f"{_json_pointer(pointer)}: {value!r}" - ) - try: - resolve_publication_path(portable, paths) - except ValueError as error: - raise PublicationPortabilityError( - f"invalid publication artifact path at {_json_pointer(pointer)}: {value!r}" - ) from error - return portable - - -def _portable_publication_value( - value: object, - paths: ReportPaths, - *, - pointer: tuple[str | int, ...], -) -> object: - if isinstance(value, str): - if _strict_artifact_locator_pointer(pointer): - return _portable_artifact_locator_string( - value, - paths, - pointer=pointer, - ) - if _locator_pointer(pointer): - return _portable_locator_string(value, paths) - fragments = _absolute_path_fragments(value) - if fragments: - raise PublicationPortabilityError( - "absolute path outside publication locator allowlist at " - f"{_json_pointer(pointer)}: {fragments[0]!r}" - ) - return value - if isinstance(value, Mapping): - protected = _digest_covered_keys(value, pointer) - result: dict[str, object] = {} - for key, item in value.items(): - rendered_key = str(key) - key_fragments = _absolute_path_fragments(rendered_key) - if key_fragments: - raise PublicationPortabilityError( - "absolute path in publication mapping key at " - f"{_json_pointer((*pointer, rendered_key))}: " - f"{key_fragments[0]!r}" - ) - result[rendered_key] = ( - item - if rendered_key in protected - else _portable_publication_value( - item, - paths, - pointer=(*pointer, rendered_key), - ) - ) - return result - if isinstance(value, Sequence) and not isinstance(value, (bytes, bytearray)): - return [ - _portable_publication_value( - item, - paths, - pointer=(*pointer, index), - ) - for index, item in enumerate(value) - ] - return value - - -def portable_publication_value(value: object, paths: ReportPaths) -> object: - """Project approved local locators and reject every unknown absolute path. - - Digest-verified sibling objects and the authenticated postflight - loaded-origin policy are copied byte-identically. Every absolute path - outside those opaque evidence objects must occur at an explicit locator - pointer above or publication fails closed. - """ - - return _portable_publication_value(value, paths, pointer=()) - - -def _current_state_roots(paths: ReportPaths) -> tuple[tuple[str, str], ...]: - return tuple( - sorted( - ( - (paths.artifact_root.as_posix(), _ARTIFACT_ROOT), - (paths.coordination_root.as_posix(), _COORDINATION_ROOT), - ), - key=lambda item: len(item[0]), - reverse=True, - ) - ) - - -def _portable_current_locator_string(value: str, paths: ReportPaths) -> str: - result = value - for local, portable in _current_state_roots(paths): - result = _replace_known_root(result, local, portable) - windows_local = local.replace("/", "\\") - if windows_local != local: - result = _replace_known_root(result, windows_local, portable) - return result - - -def _validate_current_state_tokens(value: str) -> None: - forbidden = (_SOURCE_ROOT, _REDACTED_ROOT) - if any(marker in value for marker in forbidden): - raise PublicationPortabilityError( - "portable current contains a non-state publication locator" - ) - delimiters = frozenset(" \t\r\n:;,\"'=()[]{}@") - for marker in (_ARTIFACT_ROOT, _COORDINATION_ROOT): - offset = 0 - while True: - start = value.find(marker, offset) - if start < 0: - break - suffix_start = start + len(marker) - if suffix_start >= len(value) or value[suffix_start] != "/": - raise PublicationPortabilityError( - "portable current state locator has an empty or invalid suffix" - ) - end = suffix_start + 1 - while end < len(value) and value[end] not in delimiters: - end += 1 - suffix = value[suffix_start + 1 : end] - logical = PurePosixPath(suffix) - if ( - not suffix - or "\\" in suffix - or logical.is_absolute() - or any(part in {"", ".", ".."} for part in logical.parts) - or logical.as_posix() != suffix - ): - raise PublicationPortabilityError( - "portable current state locator suffix is not canonical" - ) - offset = suffix_start - - -def _current_root_for_locator(value: str, paths: ReportPaths) -> tuple[str, Path]: - for marker, root in ( - (_ARTIFACT_ROOT, paths.artifact_root), - (_COORDINATION_ROOT, paths.coordination_root), - ): - if value.startswith(marker + "/"): - return marker, root - raise PublicationPortabilityError( - "portable current rooted path has no state-root locator" - ) - - -def _resolve_current_rooted_path(value: str, paths: ReportPaths) -> str: - _validate_current_state_tokens(value) - marker, raw_root = _current_root_for_locator(value, paths) - if value.count(_ARTIFACT_ROOT) + value.count(_COORDINATION_ROOT) != 1: - raise PublicationPortabilityError( - "portable current rooted path must contain exactly one locator" - ) - try: - resolved = resolve_publication_path(value, paths) - except ValueError as error: - raise PublicationPortabilityError( - f"portable current contains an invalid rooted path: {value!r}" - ) from error - relative = PurePosixPath(value[len(marker) + 1 :]) - lexical_root = Path(raw_root).expanduser() - lexical_root = Path(lexical_root.absolute()) - lexical = lexical_root.joinpath(*relative.parts) - # ``resolve(strict=False)`` follows every existing symlink component. A - # difference from the lexical canonical path therefore rejects even an - # in-root symlink, not merely an escape outside the state root. - if lexical != resolved: - raise PublicationPortabilityError( - f"portable current rooted path traverses a symbolic link: {value!r}" - ) - return resolved.as_posix() - - -def _portable_current_value( - value: object, - paths: ReportPaths, - *, - pointer: tuple[str | int, ...], -) -> object: - if isinstance(value, str): - if _current_rooted_path_pointer(pointer): - portable = _portable_current_locator_string(value, paths) - _resolve_current_rooted_path(portable, paths) - return portable - if _locator_pointer(pointer): - portable = _portable_current_locator_string(value, paths) - _validate_current_state_tokens(portable) - return portable - projected = _portable_current_locator_string(value, paths) - _validate_current_state_tokens(projected) - return projected - if isinstance(value, Mapping): - if _current_reproduction_recipe_pointer(pointer): - _validated_reproduction_argv(value) - protected = _digest_covered_keys(value, pointer) - return { - str(key): ( - item - if str(key) in protected - else _portable_current_value( - item, - paths, - pointer=(*pointer, str(key)), - ) - ) - for key, item in value.items() - } - if isinstance(value, Sequence) and not isinstance(value, (bytes, bytearray)): - return [ - _portable_current_value( - item, - paths, - pointer=(*pointer, index), - ) - for index, item in enumerate(value) - ] - return value - - -def _materialize_current_value( - value: object, - paths: ReportPaths, - *, - pointer: tuple[str | int, ...], -) -> object: - if isinstance(value, str): - if _current_rooted_path_pointer(pointer): - if _absolute_path_fragments(value): - raise PublicationPortabilityError( - "portable current contains a raw rooted path at " - f"{_json_pointer(pointer)}: {value!r}" - ) - return _resolve_current_rooted_path(value, paths) - if _locator_pointer(pointer): - _validate_current_state_tokens(value) - return resolve_publication_string(value, paths) - _validate_current_state_tokens(value) - if any(marker in value for marker in (_ARTIFACT_ROOT, _COORDINATION_ROOT)): - return resolve_publication_string(value, paths) - return value - if isinstance(value, Mapping): - if _current_reproduction_recipe_pointer(pointer): - _validated_reproduction_argv(value) - protected = _digest_covered_keys(value, pointer) - return { - str(key): ( - item - if str(key) in protected - else _materialize_current_value( - item, - paths, - pointer=(*pointer, str(key)), - ) - ) - for key, item in value.items() - } - if isinstance(value, Sequence) and not isinstance(value, (bytes, bytearray)): - return [ - _materialize_current_value( - item, - paths, - pointer=(*pointer, index), - ) - for index, item in enumerate(value) - ] - return value - - -def portable_current_value(value: object, paths: ReportPaths) -> object: - """Project one newly sealed current into the portable locator ABI. - - The ordinary publication projection remains unchanged. This additional - boundary proves that every state path needed by current reuse is an exact, - canonical artifact/coordination-root locator before immutable result bytes - are written. - """ - - portable = _portable_current_value(value, paths, pointer=()) - _materialize_current_value(portable, paths, pointer=()) - return portable - - -def materialize_current_value(value: object, paths: ReportPaths) -> object: - """Resolve one authenticated portable current against its present roots. - - This deliberately does not migrate historical absolute-path records. A - campaign current either uses the portable locator ABI in its stored bytes - or fails closed. - """ - - return _materialize_current_value(value, paths, pointer=()) - - -def resolve_publication_string(value: str, paths: ReportPaths) -> str: - """Resolve reversible publication placeholders on the current machine.""" - - replacements = ( - (_ARTIFACT_ROOT, paths.artifact_root.as_posix()), - (_COORDINATION_ROOT, paths.coordination_root.as_posix()), - (_SOURCE_ROOT, paths.repo_root.as_posix()), - ) - result = value - for portable, local in replacements: - result = result.replace(portable, local) - return result - - -def resolve_publication_path(value: str, paths: ReportPaths) -> Path: - """Resolve one rooted portable path and enforce root containment.""" - - if _REDACTED_ROOT in value: - raise ValueError("redacted publication path cannot be resolved") - roots = ( - (_ARTIFACT_ROOT, paths.artifact_root), - (_COORDINATION_ROOT, paths.coordination_root), - (_SOURCE_ROOT, paths.repo_root), - ) - for marker, raw_root in roots: - if value == marker: - relative = "" - elif value.startswith(f"{marker}/"): - relative = value[len(marker) + 1 :] - else: - continue - logical = PurePosixPath(relative) - if relative and ( - logical.is_absolute() - or "\\" in relative - or any(part in {"", ".", ".."} for part in logical.parts) - or logical.as_posix() != relative - ): - raise ValueError(f"publication path is not canonical: {value!r}") - root = raw_root.expanduser().resolve(strict=False) - resolved = root.joinpath(*logical.parts).resolve(strict=False) - try: - resolved.relative_to(root) - except ValueError as error: - raise ValueError( - f"publication path escapes its declared root: {value!r}" - ) from error - return resolved - raise ValueError( - f"publication path must begin with one recognized root placeholder: {value!r}" - ) - - -def publication_measurement_matches_current( - measurement: Mapping[str, object], - current: Mapping[str, object], - paths: ReportPaths, -) -> bool: - """Compare a portable cache with an already-authenticated raw result. - - The caller is responsible for authenticating ``current`` before invoking - this projection. Neither input is mutated. - """ - - portable = portable_publication_value(current, paths) - return isinstance(portable, Mapping) and dict(measurement) == dict(portable) - - -def _absolute_path_fragments(value: str) -> tuple[str, ...]: - sanitized = value - for marker in _PORTABLE_ROOTS: - sanitized = sanitized.replace(marker, "PORTABLE_ROOT") - file_uris = tuple(_FILE_URI_RE.findall(sanitized)) - without_file_uris = _FILE_URI_RE.sub("", sanitized) - without_urls = _SCHEME_URI_RE.sub("", without_file_uris) - stripped = without_urls.strip() - direct: tuple[str, ...] = () - if ( - stripped.startswith(("/", "\\\\")) - or re.match(r"^[A-Za-z]:[\\/]", stripped) is not None - ): - direct = (stripped,) - without_urls = "" - fragments = ( - *file_uris, - *direct, - *(match.group("path") for match in _WINDOWS_PATH_RE.finditer(without_urls)), - *(match.group("path") for match in _UNC_PATH_RE.finditer(without_urls)), - *(match.group("path") for match in _POSIX_PATH_RE.finditer(without_urls)), - ) - return tuple(dict.fromkeys(fragment for fragment in fragments if fragment)) - - -def _publication_absolute_paths( - value: object, - *, - pointer: tuple[str | int, ...], -) -> tuple[str, ...]: - if isinstance(value, str): - return _absolute_path_fragments(value) - if isinstance(value, Mapping): - protected = _digest_covered_keys(value, pointer) - return tuple( - fragment - for key, item in value.items() - if str(key) not in protected - for fragment in ( - *_publication_absolute_paths( - str(key), - pointer=(*pointer, str(key), ""), - ), - *_publication_absolute_paths( - item, - pointer=(*pointer, str(key)), - ), - ) - ) - if isinstance(value, Sequence) and not isinstance(value, (bytes, bytearray)): - return tuple( - fragment - for index, item in enumerate(value) - for fragment in _publication_absolute_paths( - item, - pointer=(*pointer, index), - ) - ) - return () - - -def publication_absolute_paths(value: object) -> tuple[str, ...]: - """Return host paths outside authenticated digest-covered objects.""" - - return _publication_absolute_paths(value, pointer=()) - - -__all__ = [ - "PORTABLE_CURRENT_REPRODUCTION_RECIPE_ABI", - "PublicationPortabilityError", - "materialize_current_value", - "portable_current_value", - "portable_publication_value", - "publication_absolute_paths", - "publication_measurement_matches_current", - "resolve_publication_path", - "resolve_publication_string", -] diff --git a/pyamplicol/tools/performance_report/publisher.py b/pyamplicol/tools/performance_report/publisher.py deleted file mode 100644 index 44ed70478b..0000000000 --- a/pyamplicol/tools/performance_report/publisher.py +++ /dev/null @@ -1,662 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Nonblocking snapshot, render, and PDF publication for live campaigns.""" - -from __future__ import annotations - -import errno -import fcntl -import hashlib -import json -import math -import os -import re -import shutil -import subprocess -import tempfile -import time -import uuid -from collections.abc import Callable, Iterator, Mapping -from contextlib import ExitStack, contextmanager -from dataclasses import dataclass -from datetime import UTC, datetime -from pathlib import Path - -from .artifacts import CurrentRecord, LockTimeoutError -from .measurement_lineage import load_measurement_lineage -from .service import ReportPaths, ReportService -from .source_identity import require_eligible_report_source -from .standalone_build import StandaloneBuildError, validate_latex_log - -PUBLICATION_SNAPSHOT_SCHEMA = "pyamplicol-report-publication-snapshot-v1" -DEFAULT_PUBLICATION_INTERVAL_SECONDS = 600.0 -DEFAULT_PDF_TIMEOUT_SECONDS = 900.0 -DEFAULT_EXPECTED_PAGE_COUNT = 73 -_INSTALL_LOCK_INITIAL_BACKOFF_SECONDS = 0.05 -_INSTALL_LOCK_MAXIMUM_BACKOFF_SECONDS = 1.0 - -_PAGE_COUNT_RE = re.compile( - r"Output written on .+? \((?P[1-9][0-9]*) pages?," -) - - -class ReportPublisherError(RuntimeError): - """Raised when a report snapshot cannot be built or published.""" - - -@dataclass(frozen=True, slots=True) -class PublicationResult: - """One internally consistent cache/table/PDF publication.""" - - current_count: int - page_count: int - snapshot_sha256: str - captured_at_utc: str - published_at_utc: str - - def as_dict(self) -> dict[str, object]: - return { - "schema": PUBLICATION_SNAPSHOT_SCHEMA, - "current_count": self.current_count, - "page_count": self.page_count, - "snapshot_sha256": self.snapshot_sha256, - "captured_at_utc": self.captured_at_utc, - "published_at_utc": self.published_at_utc, - } - - -def _utc_now() -> str: - return datetime.now(UTC).isoformat(timespec="seconds").replace("+00:00", "Z") - - -def _canonical_bytes(value: object) -> bytes: - return ( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ).encode("ascii") - - -def _digest_bytes(value: object) -> str: - return hashlib.sha256(_canonical_bytes(value).rstrip(b"\n")).hexdigest() - - -def _sha256(path: Path) -> str: - digest = hashlib.sha256() - with path.open("rb") as stream: - for chunk in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(chunk) - return digest.hexdigest() - - -def _fsync_directory(path: Path) -> None: - descriptor = os.open(path, os.O_RDONLY) - try: - os.fsync(descriptor) - finally: - os.close(descriptor) - - -def _atomic_json(path: Path, payload: Mapping[str, object]) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - temporary = path.with_name(f".{path.name}.tmp-{uuid.uuid4().hex}") - try: - with temporary.open("xb") as stream: - stream.write(_canonical_bytes(payload)) - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - _fsync_directory(path.parent) - finally: - temporary.unlink(missing_ok=True) - - -def _snapshot_manifest_path(service: ReportService) -> Path: - return service.paths.coordination_root / "publication" / "current.json" - - -def _publisher_state_path(service: ReportService) -> Path: - return service.paths.coordination_root / "publication" / "daemon.json" - - -@contextmanager -def _publisher_state_lease( - service: ReportService, - *, - interval_seconds: float, -) -> Iterator[None]: - """Claim the publisher state without a long-lived campaign named lock.""" - - state_path = _publisher_state_path(service) - state_path.parent.mkdir(parents=True, exist_ok=True) - guard_path = state_path.parent / "daemon.guard" - guard = guard_path.open("a+b") - lease_id = uuid.uuid4().hex - payload = { - "schema": PUBLICATION_SNAPSHOT_SCHEMA, - "pid": os.getpid(), - "lease_id": lease_id, - "started_at_utc": _utc_now(), - "interval_seconds": interval_seconds, - } - try: - try: - fcntl.flock(guard.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) - except OSError as error: - if error.errno not in (errno.EACCES, errno.EAGAIN): - raise - raise ReportPublisherError( - "another report publisher is already active" - ) from None - _atomic_json(state_path, payload) - try: - yield - finally: - try: - current = json.loads(state_path.read_text(encoding="ascii")) - except (json.JSONDecodeError, OSError): - current = None - if ( - isinstance(current, Mapping) - and current.get("lease_id") == lease_id - ): - state_path.unlink(missing_ok=True) - _fsync_directory(state_path.parent) - finally: - try: - fcntl.flock(guard.fileno(), fcntl.LOCK_UN) - finally: - guard.close() - - -@contextmanager -def _publisher_writer_lock(service: ReportService) -> Iterator[None]: - """Yield only after the publisher can take the install lock without waiting.""" - - backoff = _INSTALL_LOCK_INITIAL_BACKOFF_SECONDS - while True: - stack = ExitStack() - try: - stack.enter_context( - service.store.named_lock("report-writer", timeout=0.0) - ) - except LockTimeoutError: - stack.close() - time.sleep(backoff) - backoff = min( - _INSTALL_LOCK_MAXIMUM_BACKOFF_SECONDS, - backoff * 2.0, - ) - continue - with stack: - yield - return - - -def _current_snapshot( - records: tuple[CurrentRecord, ...], -) -> tuple[dict[str, str], ...]: - return tuple( - { - "cell_id": record.cell_id, - "attempt_id": record.attempt_id, - "manifest_sha256": record.manifest_sha256, - } - for record in sorted(records, key=lambda item: item.cell_id) - ) - - -def _capture_current_records( - service: ReportService, -) -> tuple[tuple[CurrentRecord, ...], tuple[dict[str, str], ...]]: - """Read a stable pointer set without taking any campaign writer lock.""" - - for _attempt in range(3): - records = service.store.recover_current_records() - snapshot = _current_snapshot(records) - confirmed = service.store.recover_current_records() - if _current_snapshot(confirmed) == snapshot: - return records, snapshot - raise ReportPublisherError( - "current pointers changed during three consecutive snapshot reads" - ) - - -def _report_source_copy_ignore( - source: Path, - *patterns: str, -) -> Callable[[str, list[str]], set[str]]: - """Ignore build debris and only the report root's private campaign state.""" - - pattern_ignore = shutil.ignore_patterns(*patterns) - source_path = os.path.abspath(source) - - def ignore(directory: str, names: list[str]) -> set[str]: - ignored = set(pattern_ignore(directory, names)) - if os.path.abspath(directory) == source_path and "campaign_artifacts" in names: - ignored.add("campaign_artifacts") - return ignored - - return ignore - - -def _copy_report_source(source: Path, destination: Path) -> None: - shutil.copytree( - source, - destination, - ignore=_report_source_copy_ignore( - source, - "*.aux", - "*.fdb_latexmk", - "*.fls", - "*.log", - "*.out", - "*.toc", - "pyAmpliCol.pdf", - ".coordination", - ), - ) - - -def _compile_pdf( - docs_dir: Path, - *, - expected_page_count: int | None, - timeout_seconds: float, - allow_overfull_boxes: bool = False, - stream_output: bool = False, -) -> int: - latexmk = shutil.which("latexmk") - if latexmk is None: - raise ReportPublisherError("latexmk is required for report publication") - if expected_page_count is not None and expected_page_count < 1: - raise ReportPublisherError("expected PDF page count must be positive") - if not math.isfinite(timeout_seconds) or timeout_seconds <= 0.0: - raise ReportPublisherError("PDF timeout must be finite and positive") - environment = os.environ.copy() - environment.update({"LANG": "C", "LC_ALL": "C", "LC_CTYPE": "C"}) - try: - completed = subprocess.run( - ( - latexmk, - "-pdf", - "-interaction=nonstopmode", - "-halt-on-error", - "-file-line-error", - "pyAmpliCol.tex", - ), - cwd=docs_dir, - check=False, - capture_output=not stream_output, - text=True, - env=environment, - timeout=timeout_seconds, - ) - except subprocess.TimeoutExpired as error: - raise ReportPublisherError( - f"latexmk exceeded the {timeout_seconds:g}s publication timeout" - ) from error - if completed.returncode != 0: - if stream_output: - raise ReportPublisherError( - f"latexmk failed with exit {completed.returncode}; " - "see the compilation output above" - ) - stdout = completed.stdout or "" - stderr = completed.stderr or "" - tail = "\n".join((*stdout.splitlines(), *stderr.splitlines())[-80:]) - raise ReportPublisherError( - f"latexmk failed with exit {completed.returncode}:\n{tail}" - ) - log_path = docs_dir / "pyAmpliCol.log" - try: - log = log_path.read_text(encoding="utf-8", errors="replace") - validate_latex_log( - log, - allow_overfull_boxes=allow_overfull_boxes, - ) - except OSError as error: - raise ReportPublisherError(f"cannot read LaTeX log: {error}") from error - except StandaloneBuildError as error: - raise ReportPublisherError(str(error)) from error - matches = tuple(_PAGE_COUNT_RE.finditer(log)) - if not matches: - raise ReportPublisherError("LaTeX log does not report a PDF page count") - page_count = int(matches[-1].group("pages")) - if ( - expected_page_count is not None - and page_count != expected_page_count - ): - raise ReportPublisherError( - "compiled PDF page count differs from the expected stable layout: " - f"{page_count} != {expected_page_count}" - ) - pdf = docs_dir / "pyAmpliCol.pdf" - if not pdf.is_file() or pdf.stat().st_size == 0: - raise ReportPublisherError("latexmk did not produce a non-empty PDF") - return page_count - - -def _staged_publications( - staging_docs: Path, - service: ReportService, - table_names: tuple[str, ...], -) -> tuple[tuple[Path, Path, str], ...]: - cache_names = tuple( - sorted(path.name for path in (staging_docs / "results").glob("*.json")) - ) - return ( - *( - ( - staging_docs / "results" / name, - service.paths.results_dir / name, - f"results/{name}", - ) - for name in cache_names - ), - *( - ( - staging_docs / name, - service.paths.docs_dir / name, - name, - ) - for name in table_names - ), - ( - staging_docs / "pyAmpliCol.pdf", - service.paths.docs_dir / "pyAmpliCol.pdf", - "pyAmpliCol.pdf", - ), - ) - - -def _install_snapshot( - service: ReportService, - publications: tuple[tuple[Path, Path, str], ...], - manifest: Mapping[str, object], -) -> None: - staging_root = publications[0][0].parents[2] - backup_root = staging_root / "previous" - backup_root.mkdir() - replaced: list[tuple[Path, Path | None]] = [] - with _publisher_writer_lock(service): - try: - for source, destination, relative in publications: - if not source.is_file(): - raise ReportPublisherError( - f"publication snapshot member is missing: {source}" - ) - destination.parent.mkdir(parents=True, exist_ok=True) - backup: Path | None = None - if destination.exists(): - backup = backup_root / relative - backup.parent.mkdir(parents=True, exist_ok=True) - shutil.copy2(destination, backup) - temporary = destination.with_name( - f".{destination.name}.publisher-{uuid.uuid4().hex}" - ) - try: - shutil.copy2(source, temporary) - with temporary.open("rb") as stream: - os.fsync(stream.fileno()) - os.replace(temporary, destination) - _fsync_directory(destination.parent) - finally: - temporary.unlink(missing_ok=True) - replaced.append((destination, backup)) - _atomic_json(_snapshot_manifest_path(service), manifest) - except BaseException: - for destination, backup in reversed(replaced): - if backup is None: - destination.unlink(missing_ok=True) - else: - temporary = destination.with_name( - f".{destination.name}.rollback-{uuid.uuid4().hex}" - ) - try: - shutil.copy2(backup, temporary) - os.replace(temporary, destination) - finally: - temporary.unlink(missing_ok=True) - raise - - -def validate_published_snapshot(service: ReportService) -> dict[str, object]: - """Validate only the committed schema and snapshot file identities.""" - - service.validate_payloads(service.load_caches()) - path = _snapshot_manifest_path(service) - try: - payload = json.loads(path.read_text(encoding="ascii")) - except (OSError, json.JSONDecodeError) as error: - raise ReportPublisherError( - f"cannot read publication snapshot manifest {path}: {error}" - ) from error - if not isinstance(payload, dict) or payload.get("schema") != ( - PUBLICATION_SNAPSHOT_SCHEMA - ): - raise ReportPublisherError("publication snapshot manifest is malformed") - files = payload.get("files") - if not isinstance(files, list) or not files: - raise ReportPublisherError("publication snapshot file inventory is missing") - observed: list[dict[str, object]] = [] - for index, item in enumerate(files): - if ( - not isinstance(item, dict) - or set(item) != {"path", "sha256", "size"} - or not isinstance(item["path"], str) - or Path(item["path"]).is_absolute() - or ".." in Path(item["path"]).parts - ): - raise ReportPublisherError( - f"publication snapshot file record {index} is malformed" - ) - source = service.paths.docs_dir / item["path"] - if ( - not source.is_file() - or source.stat().st_size != item["size"] - or _sha256(source) != item["sha256"] - ): - raise ReportPublisherError( - f"published report differs from snapshot member {item['path']!r}" - ) - observed.append(dict(item)) - expected_digest = payload.get("snapshot_sha256") - unsigned = dict(payload) - unsigned.pop("snapshot_sha256", None) - if expected_digest != _digest_bytes(unsigned): - raise ReportPublisherError("publication snapshot digest does not recompute") - return { - "schema": PUBLICATION_SNAPSHOT_SCHEMA, - "snapshot_sha256": expected_digest, - "current_count": payload.get("current_count"), - "page_count": payload.get("page_count"), - "file_count": len(observed), - "status": "ok", - } - - -def publish_once( - service: ReportService, - *, - expected_page_count: int = DEFAULT_EXPECTED_PAGE_COUNT, - pdf_timeout_seconds: float = DEFAULT_PDF_TIMEOUT_SECONDS, -) -> PublicationResult: - """Render and compile an immutable current-pointer snapshot off-thread.""" - - source = require_eligible_report_source(service.paths.repo_root) - try: - profile_relative = service.paths.docs_dir.relative_to( - service.paths.repo_root / "docs/performance_reports" - ) - except ValueError: - profile_relative = None - lineage = ( - load_measurement_lineage( - service.paths.repo_root, - service.paths.docs_dir, - expected_active_revision=source.revision, - expected_active_tree=source.tree, - ) - if profile_relative is not None and len(profile_relative.parts) == 1 - else None - ) - service.bind_measurement_lineage(lineage) - captured_at = _utc_now() - records, current_snapshot = _capture_current_records(service) - build_root = service.paths.artifact_root / "publication-builds" - build_root.mkdir(parents=True, exist_ok=True) - staging = Path( - tempfile.mkdtemp(prefix="report-publication-", dir=build_root) - ) - try: - staging_docs = staging / "docs" - _copy_report_source(service.paths.docs_dir, staging_docs) - staging_service = ReportService( - ReportPaths.from_repo( - service.paths.repo_root, - docs_dir=staging_docs, - artifact_root=service.paths.artifact_root, - coordination_root=service.paths.coordination_root, - ), - catalog=service.catalog, - ) - staging_service.bind_measurement_lineage(lineage) - caches = staging_service.load_caches() - staging_service.merge_current(caches, records) - tables = staging_service._render_tables(caches) - staging_service._snapshot_files(caches, tables) - - checked_caches = staging_service.load_caches() - staging_service.validate_payloads(checked_caches) - rerendered = staging_service._render_tables(checked_caches) - if rerendered != tables: - raise ReportPublisherError( - "staged cache snapshot does not reproduce its staged tables" - ) - page_count = _compile_pdf( - staging_docs, - expected_page_count=expected_page_count, - timeout_seconds=pdf_timeout_seconds, - ) - publications = _staged_publications( - staging_docs, - service, - tuple(sorted(tables)), - ) - file_inventory = [ - { - "path": relative, - "size": source_path.stat().st_size, - "sha256": _sha256(source_path), - } - for source_path, _destination, relative in publications - ] - published_at = _utc_now() - manifest: dict[str, object] = { - "schema": PUBLICATION_SNAPSHOT_SCHEMA, - "source_revision": source.revision, - "source_tree": source.tree, - "captured_at_utc": captured_at, - "published_at_utc": published_at, - "current_count": len(current_snapshot), - "current_snapshot": list(current_snapshot), - "current_snapshot_sha256": _digest_bytes(current_snapshot), - "page_count": page_count, - "files": file_inventory, - } - manifest["snapshot_sha256"] = _digest_bytes(manifest) - _install_snapshot(service, publications, manifest) - validated = validate_published_snapshot(service) - if validated["snapshot_sha256"] != manifest["snapshot_sha256"]: - raise ReportPublisherError( - "installed publication snapshot identity changed" - ) - return PublicationResult( - current_count=len(current_snapshot), - page_count=page_count, - snapshot_sha256=str(manifest["snapshot_sha256"]), - captured_at_utc=captured_at, - published_at_utc=published_at, - ) - finally: - shutil.rmtree(staging, ignore_errors=True) - - -def run_publisher( - service: ReportService, - *, - watch: bool, - interval_seconds: float = DEFAULT_PUBLICATION_INTERVAL_SECONDS, - expected_page_count: int = DEFAULT_EXPECTED_PAGE_COUNT, - pdf_timeout_seconds: float = DEFAULT_PDF_TIMEOUT_SECONDS, -) -> PublicationResult: - """Publish immediately and optionally repeat at a start-to-start cadence.""" - - if not math.isfinite(interval_seconds) or interval_seconds <= 0.0: - raise ReportPublisherError( - "publication interval must be finite and positive" - ) - with _publisher_state_lease( - service, - interval_seconds=interval_seconds, - ): - latest: PublicationResult | None = None - while True: - cycle_started = time.monotonic() - try: - latest = publish_once( - service, - expected_page_count=expected_page_count, - pdf_timeout_seconds=pdf_timeout_seconds, - ) - print( - json.dumps( - latest.as_dict(), - allow_nan=False, - sort_keys=True, - ), - flush=True, - ) - except Exception as error: - print( - json.dumps( - { - "schema": PUBLICATION_SNAPSHOT_SCHEMA, - "status": "error", - "kind": type(error).__name__, - "message": str(error), - "recorded_at_utc": _utc_now(), - }, - allow_nan=False, - sort_keys=True, - ), - flush=True, - ) - if not watch: - raise - if not watch: - assert latest is not None - return latest - remaining = interval_seconds - ( - time.monotonic() - cycle_started - ) - if remaining > 0.0: - time.sleep(remaining) - - -__all__ = [ - "DEFAULT_EXPECTED_PAGE_COUNT", - "DEFAULT_PDF_TIMEOUT_SECONDS", - "DEFAULT_PUBLICATION_INTERVAL_SECONDS", - "PUBLICATION_SNAPSHOT_SCHEMA", - "PublicationResult", - "ReportPublisherError", - "publish_once", - "run_publisher", - "validate_published_snapshot", -] diff --git a/pyamplicol/tools/performance_report/render.py b/pyamplicol/tools/performance_report/render.py deleted file mode 100644 index 636b4c244d..0000000000 --- a/pyamplicol/tools/performance_report/render.py +++ /dev/null @@ -1,5004 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Dynamic baseline joins and fixed-block TeX rendering for the report tables.""" - -from __future__ import annotations - -import hashlib -import math -import re -from collections.abc import Iterable, Mapping, Sequence -from dataclasses import dataclass, replace - -from .agreements import ( - DIRECT_AGREEMENT_ABI, - DIRECT_AGREEMENT_FIELD, - DIRECT_AGREEMENT_V2_ABI, - LC_COMMON_COMPONENT_ABI, - LC_COMMON_COMPONENT_FIELD, - LC_LEGACY_PYAMPLICOL_COMPONENT, - incoming_agreement_edges, -) -from .cache import empty_measurement -from .campaign_policy import ( - STRICT_POLICY, - CampaignPolicy, - PolicyMeasurementState, - policy_measurement_state_hint, - policy_status_label, -) -from .catalog import ( - REPORT_CATALOG, - STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6, - STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION, - ReportCatalog, - matrix_multiplicities, - z_dataset_id, -) -from .display_contract import report_display_accounting -from .models import ( - Accuracy, - CellSpec, - ExecutionMode, - MatrixComparisonView, - MatrixDataset, - ModelKey, - ProcessFamily, - ResultStatus, - ScalarDataset, - Workload, - ZVariant, -) -from .runner import ( - OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD, - SelectorContract, - validate_on_the_fly_recurrence_authority_validation_record, -) -from .timing import ( - evaluator_total_seconds_per_point, - evaluator_total_timing_record, - recurrence_core_seconds_per_point, - unavailable_execution_timing_record, -) -from .validation_summary import ( - SUMMARY_TABLE_NAME, - render_validation_summary, -) - -Measurement = Mapping[str, object] -CachePayload = Mapping[str, object] - -_NA = empty_measurement() -_MATRIX_BLOCK_SIZE = 3 -_Z_BLOCK_SIZE = 3 -_BEST_MODE_CODES = { - ExecutionMode.RECURRENCE: "r", - ExecutionMode.COMPILED: "c", - ExecutionMode.EAGER: "e", - ExecutionMode.ON_THE_FLY: "o", -} -_BEST_MODE_ORDER = tuple(_BEST_MODE_CODES) -_BEST_MODE_TABLE_NAMES = { - Accuracy.LC: "result_matrix_best_builtin_sm_lc_table.tex", - Accuracy.NLC: "result_matrix_best_builtin_sm_nlc_table.tex", - Accuracy.FULL: "result_matrix_best_builtin_sm_full_table.tex", -} -_PRESENTATION_FAILURE_KIND_PREFIX = "ManualCampaignOutcome:" -_SAFE_OUTCOME_SLUG = re.compile(r"[a-z][a-z0-9_-]{0,63}") -_TIME_CAP_LABEL = re.compile(r">(?P[0-9]+(?:\.[0-9]+)?)(?Ph|s)") -_RAM_CAP_LABEL = re.compile(r">(?P[0-9]+)GB") -_POLICY_PRESENTATION_OUTCOME_SLUGS = frozenset( - state.value - for state in PolicyMeasurementState - if state is not PolicyMeasurementState.SUCCESS -) -_MAX_BEST_MODE_TERMINAL_LABEL_CHARS = 48 -_TERMINAL_LABEL_DIGEST_CHARS = 6 -_KNOWN_PRESENTATION_TERMINAL_LABELS = { - "blocked_dependency": "blocked dependency", - "cancelled": "interrupted", - "error": "error", - "failed": "failed", - "generation_limit": "generation limit", - "interrupted": "interrupted", - "memory_limit": "memory limit", - "preparation_error": "preparation error", - "preparation_failed": "preparation failed", - "profiling_timeout": "profiling timeout", - "resource_frontier": "resource frontier", - "skip": "skip", - "static_na": "static na", - "unsupported": "unsupported", - "unverified": "unverified", - "validation_failed": "validation failed", - "validation_timeout": "validation timeout", - "worker_timeout": "worker timeout", -} -_KNOWN_PRESENTATION_TERMINAL_DISPLAY_LABELS = { - "blocked_dependency": "blocked dep.", -} -_KNOWN_RESULT_TERMINAL_LABELS = frozenset( - { - "N/A", - "t/o", - "RAM", - "skip", - "validation failed", - "unverified", - "unsupported", - "failed", - "error", - } -) -_POLICY_TERMINAL_DISPLAY_LABEL = re.compile( - r"(?:(?:worker|profile|validation) >[0-9]{1,4}(?:\.[0-9]{1,4})?(?:h|s)" - r"|>[0-9]{1,4}(?:\.[0-9]{1,4})?(?:h|s)|>[0-9]{1,4}GB" - r"|dependency(?: (?:>[0-9]{1,4}(?:\.[0-9]{1,4})?(?:h|s)" - r"|>[0-9]{1,4}GB|blocked))?)" -) -_COMPACT_OUTCOME_COUNT_LABEL = re.compile( - r"[1-9][0-9]* outcomes \[(?P[0-9a-f]{6})\]" -) - - -def _chunks(values: Sequence[int], size: int) -> tuple[tuple[int, ...], ...]: - return tuple( - tuple(values[start : start + size]) for start in range(0, len(values), size) - ) - - -def _cache_dataset_id(payload: CachePayload) -> str: - dataset_id = payload.get("dataset_id") - if not isinstance(dataset_id, str) or not dataset_id: - raise ValueError("cache payload has no dataset_id") - return dataset_id - - -def _entry_key( - dataset_id: str, - entry: Mapping[str, object], -) -> tuple[str, str | None, int, str, str | None]: - process_key = entry.get("process_key") - if process_key is not None and not isinstance(process_key, str): - raise ValueError("cache process_key must be a string or null") - n_final = entry.get("n_final") - if isinstance(n_final, bool) or not isinstance(n_final, int): - raise ValueError("cache n_final must be an integer") - workload = entry.get("workload") - if not isinstance(workload, str): - raise ValueError("cache workload must be a string") - variant = entry.get("variant") - if variant is not None and not isinstance(variant, str): - raise ValueError("cache variant must be a string or null") - return dataset_id, process_key, n_final, workload, variant - - -class MeasurementIndex: - """Read-only index over mode-owned caches. - - The index never copies measurements between datasets. Report views locate the - candidate and baseline independently and compute ratios while rendering. - """ - - def __init__(self, caches: Mapping[str, CachePayload] | Iterable[CachePayload]): - payloads = caches.values() if isinstance(caches, Mapping) else caches - entries: dict[ - tuple[str, str | None, int, str, str | None], - Measurement, - ] = {} - for payload in payloads: - dataset_id = _cache_dataset_id(payload) - raw_entries = payload.get("entries") - if not isinstance(raw_entries, list): - raise ValueError(f"cache {dataset_id!r} has no entries list") - for raw_entry in raw_entries: - if not isinstance(raw_entry, Mapping): - raise ValueError( - f"cache {dataset_id!r} contains a non-object entry" - ) - key = _entry_key(dataset_id, raw_entry) - if key in entries: - raise ValueError(f"duplicate report measurement key {key!r}") - measurement = raw_entry.get("measurement") - if not isinstance(measurement, Mapping): - raise ValueError(f"cache entry {key!r} has no measurement object") - entries[key] = measurement - self._entries = entries - - def get( - self, - dataset_id: str, - process_key: str | None, - n_final: int, - workload: Workload, - *, - variant: str | None = None, - ) -> Measurement: - return self._entries.get( - (dataset_id, process_key, n_final, workload.value, variant), - _NA, - ) - - def for_cell(self, cell: CellSpec) -> Measurement: - """Return the current measurement owned by one canonical catalog cell.""" - - return self.get( - cell.dataset_id, - cell.process_key, - cell.n_final, - cell.workload, - variant=cell.variant, - ) - - -@dataclass(frozen=True, slots=True) -class JoinedWorkload: - workload: Workload - baseline: Measurement - candidate: Measurement - comparison_linked: bool = False - generation_comparison_linked: bool | None = None - legacy_diagnostic: Measurement | None = None - - -@dataclass(frozen=True, slots=True) -class JoinedMatrixCell: - dataset: MatrixDataset - process_family: ProcessFamily - n_final: int - applicable: bool - workloads: tuple[JoinedWorkload, ...] - - -@dataclass(frozen=True, slots=True) -class _TerminalOutcome: - """One terminal result with identity and color kept separate from its label.""" - - identity: str - label: str - color: str - - -@dataclass(frozen=True, slots=True) -class _TerminalSummary: - """A bounded display label retaining every represented terminal outcome.""" - - outcomes: tuple[_TerminalOutcome, ...] - label: str - color: str - - -@dataclass(frozen=True, slots=True) -class BestModeWorkload: - workload: Workload - baseline: Measurement - candidate: Measurement - mode: ExecutionMode | None - terminal_label: _TerminalSummary | None - comparison_linked: bool = False - generation_comparison_linked: bool | None = None - legacy_diagnostic: Measurement | None = None - - -@dataclass(frozen=True, slots=True) -class BestModeMatrixCell: - process_family: ProcessFamily - n_final: int - accuracy: Accuracy - applicable: bool - workloads: tuple[BestModeWorkload, ...] - - -@dataclass(frozen=True, slots=True) -class _BestModeComparisonLayout: - """One comparison token in both inline and column-aligned forms.""" - - inline: str - prefix: str - primary: str - - -@dataclass(frozen=True, slots=True) -class _BestModeCellRows: - """Physical generation/runtime rows for one multiplicity cell.""" - - generation: tuple[str, ...] - runtime: tuple[str, ...] - - -@dataclass(frozen=True, slots=True) -class _MatrixCellRows: - """Physical generation/runtime rows for one detailed matrix cell.""" - - generation: tuple[str, ...] - runtime: tuple[str, ...] - - -@dataclass(frozen=True, slots=True) -class VisibleCompleteness: - """Render-level evidence for the publication's measured-cell contract.""" - - maximum_n_final: int - required_measurement_count: int - rendered_required_measurement_count: int - structurally_not_applicable_display_slot_count: int - not_exposed_display_slot_count: int - applicable_na_display_slots: tuple[str, ...] - missing_rendered_cell_ids: tuple[str, ...] - contract_errors: tuple[str, ...] - declared_measurement_cell_count: int = 0 - catalog_static_na_cell_count: int = 0 - rendered_catalog_static_na_cell_count: int = 0 - - @property - def complete(self) -> bool: - return not ( - self.applicable_na_display_slots - or self.missing_rendered_cell_ids - or self.contract_errors - or self.declared_measurement_cell_count - != (self.required_measurement_count + self.catalog_static_na_cell_count) - or self.rendered_required_measurement_count - != self.required_measurement_count - or self.rendered_catalog_static_na_cell_count - != self.catalog_static_na_cell_count - ) - - def as_dict(self) -> dict[str, object]: - """Return compact, JSON-safe final-audit evidence.""" - - preview_limit = 50 - return { - "kind": "pyamplicol-report-visible-completeness", - "schema_version": 2, - "status": "ok" if self.complete else "incomplete", - "maximum_n_final": self.maximum_n_final, - "declared_measurement_cell_count": (self.declared_measurement_cell_count), - "required_measurement_count": self.required_measurement_count, - "rendered_required_measurement_count": ( - self.rendered_required_measurement_count - ), - "structurally_not_applicable_display_slot_count": ( - self.structurally_not_applicable_display_slot_count - ), - "not_exposed_display_slot_count": self.not_exposed_display_slot_count, - "catalog_static_na_cell_count": self.catalog_static_na_cell_count, - "rendered_catalog_static_na_cell_count": ( - self.rendered_catalog_static_na_cell_count - ), - "applicable_na_display_slot_count": len(self.applicable_na_display_slots), - "applicable_na_display_slots": list( - self.applicable_na_display_slots[:preview_limit] - ), - "missing_rendered_cell_count": len(self.missing_rendered_cell_ids), - "missing_rendered_cell_ids": list( - self.missing_rendered_cell_ids[:preview_limit] - ), - "contract_errors": list(self.contract_errors[:preview_limit]), - } - - -class BaselineCandidateAdapter: - """Join candidate measurements to their canonical baseline at render time.""" - - def __init__( - self, - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, - ): - self.catalog = catalog - self.index = MeasurementIndex(caches) - self._cells = { - ( - cell.dataset_id, - cell.process_key, - cell.n_final, - cell.workload, - cell.variant, - ): cell - for cell in catalog.measurement_cells() - } - - def _cell( - self, - dataset_id: str, - process_key: str, - n_final: int, - workload: Workload, - *, - variant: str | None = None, - ) -> CellSpec: - return self._cells[(dataset_id, process_key, n_final, workload, variant)] - - @staticmethod - def _finite_number(value: object) -> bool: - return ( - not isinstance(value, bool) - and isinstance(value, (int, float)) - and math.isfinite(float(value)) - ) - - @classmethod - def _exact_number(cls, value: object, expected: object) -> bool: - if not cls._finite_number(value) or not cls._finite_number(expected): - return False - return float(value) == float(expected) - - @staticmethod - def _selectors_match( - candidate_cell: CellSpec, - candidate: Measurement, - baseline: Measurement, - ) -> bool: - candidate_selector = candidate.get("selector_contract") - baseline_selector = baseline.get("selector_contract") - if candidate_cell.measurement.accuracy is Accuracy.LC: - return ( - isinstance(candidate_selector, Mapping) - and isinstance(baseline_selector, Mapping) - and candidate_selector == baseline_selector - ) - return candidate_selector is None and baseline_selector is None - - @staticmethod - def _component( - cell: CellSpec, - measurement: Measurement, - ) -> Mapping[str, object] | None: - validation = measurement.get("validation") - component = ( - validation.get(LC_COMMON_COMPONENT_FIELD) - if isinstance(validation, Mapping) - else None - ) - if not isinstance(component, Mapping): - return None - if ( - component.get("abi") != LC_COMMON_COMPONENT_ABI - or component.get("cell_id") != cell.cell_id - or not BaselineCandidateAdapter._finite_number(component.get("value")) - ): - return None - return component - - def _direct_agreement_link( - self, - candidate_cell: CellSpec, - candidate: Measurement, - baseline_cell: CellSpec, - baseline: Measurement, - ) -> bool: - matching_edges = tuple( - edge - for edge in incoming_agreement_edges( - candidate_cell, - catalog=self.catalog, - ) - if edge.baseline.cell_id == baseline_cell.cell_id - ) - if not matching_edges: - return False - validation = candidate.get("validation") - records = ( - validation.get(DIRECT_AGREEMENT_FIELD) - if isinstance(validation, Mapping) - else None - ) - if not isinstance(records, list): - return False - for edge in matching_edges: - record = next( - ( - item - for item in records - if isinstance(item, Mapping) - and item.get("abi") - in {DIRECT_AGREEMENT_ABI, DIRECT_AGREEMENT_V2_ABI} - and item.get("edge_kind") == edge.kind - and item.get("value_kind") == edge.value_kind - and item.get("candidate_cell_id") == candidate_cell.cell_id - and item.get("baseline_cell_id") == baseline_cell.cell_id - and ( - item.get("status") == ResultStatus.OK.value - or ( - edge.kind == LC_LEGACY_PYAMPLICOL_COMPONENT - and item.get("status") - == ResultStatus.VALIDATION_FAILED.value - ) - ) - ), - None, - ) - if record is None: - continue - if edge.value_kind == "matrix_element": - candidate_value = candidate.get("matrix_element") - baseline_value = baseline.get("matrix_element") - else: - candidate_component = self._component(candidate_cell, candidate) - baseline_component = self._component(baseline_cell, baseline) - if candidate_component is None or baseline_component is None: - continue - identity_fields = ( - "point_digest", - "helicity_ids", - "color_flow_ids", - ) - if any( - candidate_component.get(field) != baseline_component.get(field) - for field in identity_fields - ): - continue - candidate_value = candidate_component.get("value") - baseline_value = baseline_component.get("value") - if self._exact_number( - record.get("candidate"), - candidate_value, - ) and self._exact_number( - record.get("baseline"), - baseline_value, - ): - return True - return False - - def _direct_link( - self, - candidate_cell: CellSpec, - candidate: Measurement, - baseline_cell: CellSpec, - baseline: Measurement, - ) -> bool: - if not (_ok(candidate) and _ok(baseline)) or not self._selectors_match( - candidate_cell, - candidate, - baseline, - ): - return False - matching_edges = tuple( - edge - for edge in incoming_agreement_edges( - candidate_cell, - catalog=self.catalog, - ) - if edge.baseline.cell_id == baseline_cell.cell_id - ) - if matching_edges: - return self._direct_agreement_link( - candidate_cell, - candidate, - baseline_cell, - baseline, - ) - canonical_baseline = self.catalog.validation_baseline_cell(candidate_cell) - if ( - canonical_baseline is None - or canonical_baseline.cell_id != baseline_cell.cell_id - ): - return False - validation = candidate.get("validation") - pointwise = ( - validation.get("pointwise") if isinstance(validation, Mapping) else None - ) - comparison_status = ( - pointwise.get("status") if isinstance(pointwise, Mapping) else None - ) - legacy_diagnostic = ( - baseline_cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and candidate_cell.measurement.execution_mode - is ExecutionMode.RECURRENCE - ) - return ( - isinstance(pointwise, Mapping) - and ( - comparison_status == ResultStatus.OK.value - or ( - legacy_diagnostic - and comparison_status == ResultStatus.VALIDATION_FAILED.value - ) - ) - and self._exact_number( - pointwise.get("candidate"), - candidate.get("matrix_element"), - ) - and self._exact_number( - pointwise.get("baseline"), - baseline.get("matrix_element"), - ) - ) - - def _recurrence_bridge(self, candidate_cell: CellSpec) -> CellSpec | None: - baseline = self.catalog.validation_baseline_cell(candidate_cell) - if ( - baseline is not None - and baseline.measurement.execution_mode is ExecutionMode.RECURRENCE - ): - return baseline - peers = tuple( - edge.baseline - for edge in incoming_agreement_edges( - candidate_cell, - catalog=self.catalog, - ) - if edge.baseline.measurement.execution_mode is ExecutionMode.RECURRENCE - ) - return peers[0] if len(peers) == 1 else None - - def _legacy_diagnostic_measurement( - self, - candidate_cell: CellSpec, - candidate: Measurement, - baseline_cell: CellSpec, - ) -> Measurement | None: - """Locate the recurrence record that compared with legacy AmpliCol.""" - - if ( - baseline_cell.measurement.execution_mode - is not ExecutionMode.AMPLICOL - ): - return None - if ( - candidate_cell.measurement.execution_mode - is ExecutionMode.RECURRENCE - ): - return candidate - recurrence_cell = self._recurrence_bridge(candidate_cell) - return ( - None - if recurrence_cell is None - else self.index.for_cell(recurrence_cell) - ) - - @staticmethod - def _runtime_artifact_id(measurement: Measurement) -> str | None: - provenance = measurement.get("provenance") - runtime_identity = ( - provenance.get("runtime_identity") - if isinstance(provenance, Mapping) - else None - ) - artifact_id = ( - runtime_identity.get("artifact_id") - if isinstance(runtime_identity, Mapping) - else None - ) - return artifact_id if isinstance(artifact_id, str) else None - - def _otf_recurrence_authority_link( - self, - candidate_cell: CellSpec, - candidate: Measurement, - recurrence_cell: CellSpec, - recurrence: Measurement, - ) -> bool: - """Authenticate the dedicated OTF-to-recurrence numerical edge.""" - - if not (_ok(candidate) and _ok(recurrence)) or not self._selectors_match( - candidate_cell, - candidate, - recurrence, - ): - return False - validation = candidate.get("validation") - authority_record = ( - validation.get(OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD) - if isinstance(validation, Mapping) - else None - ) - authority = ( - authority_record.get("authority") - if isinstance(authority_record, Mapping) - else None - ) - candidate_artifact_id = self._runtime_artifact_id(candidate) - recurrence_artifact_id = self._runtime_artifact_id(recurrence) - if ( - candidate_artifact_id is None - or recurrence_artifact_id is None - or not isinstance(authority, Mapping) - or authority.get("artifact_id") != recurrence_artifact_id - ): - return False - try: - validate_on_the_fly_recurrence_authority_validation_record( - authority_record, - expected_cell=candidate_cell, - selector_contract=candidate.get("selector_contract"), - candidate_artifact_id=candidate_artifact_id, - expected_authority_cell_id=recurrence_cell.cell_id, - ) - except (TypeError, ValueError): - return False - return True - - @staticmethod - def _same_performance_scope( - candidate_cell: CellSpec, - baseline_cell: CellSpec, - ) -> bool: - """Match process-wide timing identities without using a numerical edge.""" - - return ( - candidate_cell.process == baseline_cell.process - and candidate_cell.process_key == baseline_cell.process_key - and candidate_cell.n_final == baseline_cell.n_final - and candidate_cell.workload is baseline_cell.workload - and candidate_cell.measurement.model is ModelKey.BUILTIN_SM - and baseline_cell.measurement.model is None - and candidate_cell.measurement.accuracy - is baseline_cell.measurement.accuracy - ) - - @staticmethod - def _otf_amplicol_runtime_selectors_match( - workload: Workload, - candidate: Measurement, - baseline: Measurement, - ) -> bool: - candidate_selector = candidate.get("selector_contract") - baseline_selector = baseline.get("selector_contract") - if not isinstance(candidate_selector, Mapping) or not isinstance( - baseline_selector, - Mapping, - ): - return False - try: - candidate_contract = SelectorContract.from_mapping(candidate_selector) - baseline_contract = SelectorContract.from_mapping(baseline_selector) - except (TypeError, ValueError): - return False - if workload is Workload.SELECTED_FLOW: - return candidate_contract == baseline_contract - if workload is Workload.ALL_FLOW: - return ( - candidate_contract.point_digest == baseline_contract.point_digest - and candidate_contract.all_flow_helicity_ids - == baseline_contract.all_flow_helicity_ids - and candidate_contract.all_flow_source_helicities - == baseline_contract.all_flow_source_helicities - ) - return False - - def _otf_amplicol_performance_link( - self, - candidate_cell: CellSpec, - candidate: Measurement, - baseline_cell: CellSpec, - baseline: Measurement, - *, - require_runtime_selectors: bool, - ) -> bool: - if ( - candidate_cell.measurement.accuracy is not Accuracy.LC - or candidate_cell.workload - not in {Workload.SELECTED_FLOW, Workload.ALL_FLOW} - or not (_ok(candidate) and _ok(baseline)) - or not self._same_performance_scope(candidate_cell, baseline_cell) - ): - return False - recurrence_cell = self._recurrence_bridge(candidate_cell) - if recurrence_cell is None: - return False - recurrence = self.index.for_cell(recurrence_cell) - if not self._otf_recurrence_authority_link( - candidate_cell, - candidate, - recurrence_cell, - recurrence, - ): - return False - return not require_runtime_selectors or ( - self._otf_amplicol_runtime_selectors_match( - candidate_cell.workload, - candidate, - baseline, - ) - ) - - def _comparison_linked( - self, - candidate_cell: CellSpec, - candidate: Measurement, - baseline_cell: CellSpec, - baseline: Measurement, - ) -> bool: - if ( - baseline_cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and candidate_cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and candidate_cell.measurement.accuracy is Accuracy.LC - ): - return self._otf_amplicol_performance_link( - candidate_cell, - candidate, - baseline_cell, - baseline, - require_runtime_selectors=True, - ) - if ( - baseline_cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and candidate_cell.measurement.execution_mode - in { - ExecutionMode.COMPILED, - ExecutionMode.EAGER, - ExecutionMode.ON_THE_FLY, - } - ): - recurrence_cell = self._recurrence_bridge(candidate_cell) - if recurrence_cell is None: - return False - recurrence = self.index.for_cell(recurrence_cell) - return self._direct_link( - candidate_cell, - candidate, - recurrence_cell, - recurrence, - ) and self._direct_link( - recurrence_cell, - recurrence, - baseline_cell, - baseline, - ) - return self._direct_link( - candidate_cell, - candidate, - baseline_cell, - baseline, - ) - - def _generation_comparison_linked( - self, - candidate_cell: CellSpec, - candidate: Measurement, - baseline_cell: CellSpec, - baseline: Measurement, - ) -> bool: - if ( - baseline_cell.measurement.execution_mode is ExecutionMode.AMPLICOL - and candidate_cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and candidate_cell.measurement.accuracy is Accuracy.LC - ): - return self._otf_amplicol_performance_link( - candidate_cell, - candidate, - baseline_cell, - baseline, - require_runtime_selectors=False, - ) - return self._comparison_linked( - candidate_cell, - candidate, - baseline_cell, - baseline, - ) - - def _best_mode_candidate( - self, - cell: CellSpec, - ) -> tuple[CellSpec, Measurement]: - """Resolve one mode across its owned and exact-equivalent attempts. - - Campaign planning follows the same precedence: an existing current owned - by the requested cell wins before a reusable equivalent current. The - report must nevertheless see an equivalent Z-ladder success when the - matrix-owned cell contains only a terminal outcome. If neither surface - succeeded, retain the owned terminal before an equivalent terminal so - the recurrence fallback can report the attempt that actually ran. - """ - - measurement = self.index.for_cell(cell) - if _runtime_value(measurement) is not None: - return cell, measurement - equivalents = self.catalog.equivalent_cells(cell) - for equivalent in equivalents: - equivalent_measurement = self.index.for_cell(equivalent) - if _runtime_value(equivalent_measurement) is not None: - return equivalent, equivalent_measurement - if _terminal_measurement_label(measurement) is not None: - return cell, measurement - for equivalent in equivalents: - equivalent_measurement = self.index.for_cell(equivalent) - if _terminal_measurement_label(equivalent_measurement) is not None: - return equivalent, equivalent_measurement - return cell, measurement - - def matrix_cell( - self, - dataset: MatrixDataset, - family: ProcessFamily, - n_final: int, - *, - baseline_dataset_id: str | None = None, - ) -> JoinedMatrixCell: - process = family.process(n_final) - applicable = ( - process is not None - and n_final in dataset.multiplicities - and n_final <= family.maximum_n(dataset.candidate.accuracy) - ) - workloads = ( - (Workload.SELECTED_FLOW, Workload.ALL_FLOW) - if dataset.candidate.accuracy is Accuracy.LC - else (Workload.CONTRACTED,) - ) - if not applicable: - joined = tuple(JoinedWorkload(workload, _NA, _NA) for workload in workloads) - else: - joined_items: list[JoinedWorkload] = [] - for workload in workloads: - candidate_cell = self._cell( - dataset.dataset_id, - family.key, - n_final, - workload, - ) - baseline_cell = ( - self.catalog.baseline_cell(candidate_cell) - if baseline_dataset_id is None - else self._cell( - baseline_dataset_id, - family.key, - n_final, - workload, - ) - ) - assert baseline_cell is not None - candidate = self.index.for_cell(candidate_cell) - baseline = self.index.for_cell(baseline_cell) - comparison_linked = self._comparison_linked( - candidate_cell, - candidate, - baseline_cell, - baseline, - ) - joined_items.append( - JoinedWorkload( - workload, - baseline, - candidate, - comparison_linked, - self._generation_comparison_linked( - candidate_cell, - candidate, - baseline_cell, - baseline, - ), - self._legacy_diagnostic_measurement( - candidate_cell, - candidate, - baseline_cell, - ), - ) - ) - joined = tuple(joined_items) - return JoinedMatrixCell(dataset, family, n_final, applicable, joined) - - def z_workload( - self, - *, - model: ModelKey, - n_final: int, - variant: ZVariant, - workload: Workload, - ) -> JoinedWorkload: - baseline = self.index.get( - "reference_amplicol_lc", - "dd_z_jets", - n_final, - workload, - ) - if variant.execution_mode is ExecutionMode.AMPLICOL: - return JoinedWorkload(workload, baseline, baseline) - candidate_cell = self._cell( - z_dataset_id(model), - "dd_z_jets", - n_final, - workload, - variant=variant.key, - ) - baseline_cell = self.catalog.baseline_cell(candidate_cell) - assert baseline_cell is not None - candidate = self.index.for_cell(candidate_cell) - comparison_linked = self._comparison_linked( - candidate_cell, - candidate, - baseline_cell, - baseline, - ) - return JoinedWorkload( - workload, - baseline, - candidate, - comparison_linked, - self._generation_comparison_linked( - candidate_cell, - candidate, - baseline_cell, - baseline, - ), - self._legacy_diagnostic_measurement( - candidate_cell, - candidate, - baseline_cell, - ), - ) - - def best_mode_cell( - self, - accuracy: Accuracy, - family: ProcessFamily, - n_final: int, - ) -> BestModeMatrixCell: - """Join AmpliCol to the fastest valid built-in-SM mode per workload.""" - - process = family.process(n_final) - multiplicities = matrix_multiplicities(accuracy) - applicable = ( - process is not None - and n_final in multiplicities - and n_final <= family.maximum_n(accuracy) - ) - workloads = ( - (Workload.SELECTED_FLOW, Workload.ALL_FLOW) - if accuracy is Accuracy.LC - else (Workload.CONTRACTED,) - ) - if not applicable: - joined = tuple( - BestModeWorkload(workload, _NA, _NA, None, None) - for workload in workloads - ) - return BestModeMatrixCell( - family, - n_final, - accuracy, - applicable, - joined, - ) - - baseline_dataset = f"reference_amplicol_{accuracy.value}" - joined_workloads: list[BestModeWorkload] = [] - for workload in workloads: - baseline_cell = self._cell( - baseline_dataset, - family.key, - n_final, - workload, - ) - baseline = self.index.for_cell(baseline_cell) - candidate_datasets = tuple( - ( - mode, - "matrix_" - f"{mode.value.replace('-', '_')}_builtin_sm_" - f"{accuracy.value}", - ) - for mode in _BEST_MODE_ORDER - ) - candidates = tuple( - ( - mode, - self._cell( - dataset_id, - family.key, - n_final, - workload, - ), - ) - for mode, dataset_id in candidate_datasets - if n_final in self.catalog.dataset(dataset_id).multiplicities - ) - measured_candidates = tuple( - (mode, *self._best_mode_candidate(cell)) for mode, cell in candidates - ) - eligible = tuple( - (mode, cell, measurement) - for mode, cell, measurement in measured_candidates - if _runtime_value(measurement) is not None - ) - if eligible: - winner_mode, winner_cell, winner = min( - eligible, - key=lambda item: ( - _runtime_value(item[2]), - _BEST_MODE_ORDER.index(item[0]), - ), - ) - terminal_label = None - comparison_linked = self._comparison_linked( - winner_cell, - winner, - baseline_cell, - baseline, - ) - generation_comparison_linked = self._generation_comparison_linked( - winner_cell, - winner, - baseline_cell, - baseline, - ) - legacy_diagnostic = self._legacy_diagnostic_measurement( - winner_cell, - winner, - baseline_cell, - ) - else: - _recurrence_mode, recurrence_cell, recurrence = next( - candidate - for candidate in measured_candidates - if candidate[0] is ExecutionMode.RECURRENCE - ) - if _terminal_measurement_label(recurrence) is None: - winner_mode, winner = None, _NA - else: - winner_mode, winner = ExecutionMode.RECURRENCE, recurrence - terminal_label = None - comparison_linked = False - generation_comparison_linked = False - legacy_diagnostic = self._legacy_diagnostic_measurement( - recurrence_cell, - recurrence, - baseline_cell, - ) - joined_workloads.append( - BestModeWorkload( - workload, - baseline, - winner, - winner_mode, - terminal_label, - comparison_linked, - generation_comparison_linked, - legacy_diagnostic, - ) - ) - return BestModeMatrixCell( - family, - n_final, - accuracy, - applicable, - tuple(joined_workloads), - ) - - -def _tex_escape(value: str) -> str: - replacements = { - "\\": r"\textbackslash{}", - "&": r"\&", - "%": r"\%", - "$": r"\$", - "#": r"\#", - "_": r"\_", - "{": r"\{", - "}": r"\}", - "~": r"\textasciitilde{}", - "^": r"\textasciicircum{}", - } - return "".join(replacements.get(character, character) for character in value) - - -def _compact(value: float) -> str: - return f"{value:.3g}" - - -def _timing_value(value: float) -> str: - return f"{value:.6g}" - - -def _best_mode_value(value: float) -> str: - """Render exactly three significant digits in compact overview tables.""" - - rendered = f"{value:#.3g}" - if "e" not in rendered and "E" not in rendered and rendered.endswith("."): - return rendered[:-1] - return rendered - - -def _best_mode_time(value: object, *, microseconds: bool = False) -> str: - if value is None: - return r"\matrixna{ReportMuted}" - number = float(value) - if not math.isfinite(number): - return r"\matrixna{ReportMuted}" - if microseconds: - number *= 1.0e6 - return rf"\texttt{{{_best_mode_value(number)}}}" - - -def _best_mode_ratio_color(value: float) -> str: - if value < 1.0: - return "ReportGreen" - if value < 2.0: - return "ReportOrange" - return "ReportRed" - - -def _metric_group_span(accuracy: Accuracy) -> int: - return 8 if accuracy is Accuracy.LC else 3 - - -def _metric_group_column_spec(accuracy: Accuracy) -> str: - """Physical value columns shared by detailed and best-mode tables. - - Ordinary inter-column padding is intentional: ``colortbl`` paints it as - part of a coloured row. Non-zero ``@{...}`` inserts leave unpainted seams - through alternating row bands, so ``@{}`` is used only where two fragments - form one visually continuous value. - """ - - font = r"\matrixentryfontlc" if accuracy is Accuracy.LC else r"\matrixentryfont" - if accuracy is Accuracy.LC: - return ( - rf">{{{font}}}l" - rf">{{{font}}}c" - rf">{{{font}}}l" - rf">{{{font}}}r" - r"@{}" - rf">{{{font}}}l" - rf">{{{font}}}c" - rf">{{{font}}}r" - r"@{}" - rf">{{{font}}}l" - ) - return ( - rf">{{{font}}}l" - rf">{{{font}}}r" - r"@{}" - rf">{{{font}}}l" - ) - - -def _metric_table_column_spec( - accuracy: Accuracy, - multiplicity_count: int, -) -> str: - multiplicity_groups = "".join( - _metric_group_column_spec(accuracy) for _ in range(multiplicity_count) - ) - return r"@{}rL{1.45in}l" + multiplicity_groups + r"@{}" - - -def _metric_group_cell( - content: str, - accuracy: Accuracy, - *, - alignment: str = "c", -) -> str: - if alignment not in {"c", "l", "r"}: - raise ValueError(f"unsupported metric-group alignment: {alignment}") - return ( - rf"\multicolumn{{{_metric_group_span(accuracy)}}}" - rf"{{{alignment}}}{{{content}}}" - ) - - -def _metric_summary_group_cell( - content: str, - accuracy: Accuracy, - *, - group_index: int, -) -> str: - """Render one centred summary group with block-local band shading.""" - - if group_index % 2 == 0: - content = rf"\cellcolor{{refblue}}{content}" - return _metric_group_cell(content, accuracy, alignment="c") - - -def _metric_summary_header_row( - multiplicities: Sequence[int], - accuracy: Accuracy, - *, - annotations: Sequence[str] | None = None, -) -> str: - """Repeat the multiplicity headings immediately above summary rows.""" - - if annotations is None: - annotations = ("",) * len(multiplicities) - if len(annotations) != len(multiplicities): - raise ValueError("summary header annotations must match multiplicities") - - return ( - r"\multicolumn{3}{@{}l}{} & " - + " & ".join( - _metric_summary_group_cell( - ( - rf"\textbf{{n={n_final}}}" - + (rf"\hspace{{0.08in}}{annotation}" if annotation else "") - ), - accuracy, - group_index=group_index, - ) - for group_index, (n_final, annotation) in enumerate( - zip(multiplicities, annotations, strict=True) - ) - ) - + r" \\" - ) - - -def _matrix_wall_summary_label(accuracy: Accuracy) -> str: - if accuracy is Accuracy.LC: - return ( - r"\matrixsummaryworkloads" - r"{\textbf{summary: run single-flow, hel. sum}}" - r"{\textbf{summary: run all-flows, single hel.}}" - ) - return r"\textbf{summary: wall}" - - -def _metric_row_label(*, runtime: bool) -> str: - label = r"run [\(\mu\mathrm{s}/\mathrm{pt}\)]" if runtime else r"gen. [s]" - return rf"\textcolor{{ReportMuted}}{{\scriptsize {label}}}" - - -def _time(value: object, *, microseconds: bool = False) -> str: - if value is None: - return r"\matrixna{ReportMuted}" - number = float(value) - if not math.isfinite(number): - return r"\matrixna{ReportMuted}" - if microseconds: - number *= 1.0e6 - return rf"\texttt{{{_timing_value(number)}}}" - - -def _unavailable_time( - measurement: Measurement, - field: str, - *, - microseconds: bool = False, -) -> str | None: - record = unavailable_execution_timing_record(measurement, field) - if record is None: - return None - total_record = evaluator_total_timing_record(measurement) - if total_record is not None: - return ( - r"\matrixtotalevaluator{" - + _time( - total_record["raw_seconds_per_point"], - microseconds=microseconds, - ) - + "}" - ) - return _not_exposed() - - -def _presentation_outcome( - measurement: Measurement, -) -> tuple[str, str] | None: - failure = measurement.get("failure") - if not isinstance(failure, Mapping): - return None - kind = failure.get("kind") - message = failure.get("message") - if ( - not isinstance(kind, str) - or not kind.startswith(_PRESENTATION_FAILURE_KIND_PREFIX) - or not isinstance(message, str) - or not message - ): - return None - slug = kind.removeprefix(_PRESENTATION_FAILURE_KIND_PREFIX) - if _SAFE_OUTCOME_SLUG.fullmatch(slug) is None: - return None - return slug, message - - -def _visible_status(measurement: Measurement) -> _TerminalOutcome: - """Return a visible label whose classification does not depend on its text.""" - - status = str(measurement.get("status", ResultStatus.NOT_AVAILABLE.value)) - policy_label = policy_status_label(measurement) - if policy_label is not None: - policy_state = policy_measurement_state_hint(measurement) - display_label = ( - "dependency" - if policy_state - in { - PolicyMeasurementState.DEPENDENCY, - PolicyMeasurementState.RESOURCE_FRONTIER, - } - else policy_label - ) - return _TerminalOutcome( - identity=( - f"policy:{policy_state.value}" - if policy_state is not None - else f"policy-label:{policy_label}" - ), - label=display_label, - color="ReportOrange", - ) - presentation = _presentation_outcome(measurement) - if presentation is not None: - slug, label = presentation - return _TerminalOutcome( - identity=f"presentation:{slug}", - label=label, - color=( - "ReportOrange" - if slug in _POLICY_PRESENTATION_OUTCOME_SLUGS - or slug == ResultStatus.UNVERIFIED.value - else "ReportRed" - ), - ) - labels = { - ResultStatus.NOT_AVAILABLE.value: "N/A", - ResultStatus.TIMEOUT.value: "t/o", - ResultStatus.MEMORY_LIMIT.value: "RAM", - ResultStatus.SKIP.value: "skip", - ResultStatus.VALIDATION_FAILED.value: "validation failed", - ResultStatus.UNVERIFIED.value: "unverified", - ResultStatus.UNSUPPORTED.value: "unsupported", - ResultStatus.FAILED.value: "failed", - ResultStatus.ERROR.value: "error", - } - label = labels.get(status, status) - color = ( - "ReportMuted" - if status == ResultStatus.NOT_AVAILABLE.value - else "ReportOrange" - if status == ResultStatus.UNVERIFIED.value - else "ReportRed" - ) - return _TerminalOutcome( - identity=f"result:{status}", - label=label, - color=color, - ) - - -def _visible_status_label(measurement: Measurement) -> tuple[str, str]: - visible = _visible_status(measurement) - return _compact_terminal_display(visible), visible.color - - -def _compact_terminal_display(outcome: _TerminalOutcome) -> str: - """Bound hostile/future labels while retaining one stable identity token.""" - - identity_kind, _, identity_value = outcome.identity.partition(":") - known_presentation = ( - identity_kind == "presentation" - and _KNOWN_PRESENTATION_TERMINAL_LABELS.get(identity_value) == outcome.label - ) - known_result = ( - identity_kind == "result" and outcome.label in _KNOWN_RESULT_TERMINAL_LABELS - ) - known_policy = ( - ( - identity_kind in {"policy", "policy-label"} - or ( - identity_kind == "presentation" - and identity_value in _POLICY_PRESENTATION_OUTCOME_SLUGS - ) - ) - and _POLICY_TERMINAL_DISPLAY_LABEL.fullmatch(outcome.label) is not None - and len(outcome.label) <= 18 - ) - compact_count = ( - _COMPACT_OUTCOME_COUNT_LABEL.fullmatch(outcome.label) - if identity_kind == "summary" - else None - ) - if known_presentation or known_result or known_policy: - return ( - _KNOWN_PRESENTATION_TERMINAL_DISPLAY_LABELS.get( - identity_value, - outcome.label, - ) - if known_presentation - else outcome.label - ) - if compact_count is not None: - return f"N out.[{compact_count.group('digest')}]" - if identity_kind in {"policy", "presentation"} and _SAFE_OUTCOME_SLUG.fullmatch( - identity_value - ): - slug_words = tuple(word for word in re.split(r"[_-]+", identity_value) if word) - if len(slug_words) == 1 and len(slug_words[0]) <= 12: - return slug_words[0] - if 2 <= len(slug_words) <= 3: - return " ".join(word[:4] for word in slug_words) - digest = hashlib.sha256( - f"{outcome.identity}\0{outcome.label}\0{outcome.color}".encode() - ).hexdigest()[:_TERMINAL_LABEL_DIGEST_CHARS] - if " | " in outcome.label: - return f"N out.[{digest}]" - prefix = "".join( - character - for character in outcome.label - if character.isascii() and character.isalnum() - )[:4] - return f"{prefix or 'term'}..{digest}" - - -def _status(measurement: Measurement) -> str: - label, color = _visible_status_label(measurement) - return rf"\matrixstatus{{{color}}}{{{_tex_escape(label)}}}" - - -def _ok(measurement: Measurement) -> bool: - return measurement.get("status") == ResultStatus.OK.value - - -def _runtime_value(measurement: Measurement) -> float | None: - """Return a comparable wall time for best-mode selection.""" - - if not _ok(measurement): - return None - value = measurement.get("wall_seconds_per_point") - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - number = float(value) - if not math.isfinite(number) or number < 0.0: - return None - return number - - -def _metric(measurement: Measurement, field: str, *, microseconds: bool = False) -> str: - if not _ok(measurement): - return _status(measurement) - unavailable = _unavailable_time( - measurement, - field, - microseconds=microseconds, - ) - if unavailable is not None: - return unavailable - return _time(measurement.get(field), microseconds=microseconds) - - -def _best_mode_metric( - measurement: Measurement, - field: str, - *, - microseconds: bool = False, -) -> str: - if not _ok(measurement): - return _status(measurement) - unavailable = _unavailable_time( - measurement, - field, - microseconds=microseconds, - ) - if unavailable is not None: - return unavailable - return _best_mode_time(measurement.get(field), microseconds=microseconds) - - -def _failed_comparison_status(value: object) -> bool: - return value in { - ResultStatus.FAILED.value, - ResultStatus.VALIDATION_FAILED.value, - "mismatch", - } - - -def _contains_failed_comparison(value: object) -> bool: - if isinstance(value, Mapping): - return _failed_comparison_status(value.get("status")) or any( - _contains_failed_comparison(item) for item in value.values() - ) - if isinstance(value, list): - return any(_contains_failed_comparison(item) for item in value) - return False - - -def _original_amplicol_comparison_failed( - candidate: Measurement, - *, - candidate_mode: ExecutionMode | None, -) -> bool: - """Identify only failed comparisons against original AmpliCol.""" - - validation = candidate.get("validation") - if not isinstance(validation, Mapping): - return False - if _contains_failed_comparison( - validation.get("legacy_amplicol_comparison") - ): - return True - direct = validation.get(DIRECT_AGREEMENT_FIELD) - if isinstance(direct, list) and any( - isinstance(record, Mapping) - and str(record.get("baseline_cell_id", "")).startswith( - "reference-amplicol-" - ) - and _failed_comparison_status(record.get("status")) - for record in direct - ): - return True - authority = validation.get("independent_authority") - if ( - isinstance(authority, Mapping) - and str(authority.get("selected_cell_id", "")).startswith( - "reference-amplicol-" - ) - and _failed_comparison_status(authority.get("status")) - ): - return True - for field in ("legacy_comparison", "amplicol_comparison"): - comparison = validation.get(field) - if isinstance(comparison, Mapping) and _failed_comparison_status( - comparison.get("status") - ): - return True - pointwise = validation.get("pointwise") - return ( - candidate_mode is ExecutionMode.RECURRENCE - and isinstance(pointwise, Mapping) - and _failed_comparison_status(pointwise.get("status")) - ) - - -def _original_amplicol_generation_metric( - joined: JoinedWorkload | BestModeWorkload, - *, - candidate_mode: ExecutionMode | None, -) -> str: - """Render a retained AmpliCol generation time red on legacy mismatch only.""" - - rendered = _best_mode_metric(joined.baseline, "generation_seconds") - value = joined.baseline.get("generation_seconds") - retained = ( - _ok(joined.baseline) - and not isinstance(value, bool) - and isinstance(value, (int, float)) - and math.isfinite(float(value)) - and float(value) >= 0.0 - ) - diagnostic = joined.legacy_diagnostic or joined.candidate - diagnostic_mode = ( - ExecutionMode.RECURRENCE - if joined.legacy_diagnostic is not None - else candidate_mode - ) - if retained and _original_amplicol_comparison_failed( - diagnostic, - candidate_mode=diagnostic_mode, - ): - return rf"\textcolor{{ReportRed}}{{{rendered}}}" - return rendered - - -def _diagnostic_best_mode_time( - measurement: Measurement, - field: str, - *, - microseconds: bool = False, -) -> str: - """Render one retained diagnostic timing without treating it as success.""" - - value = measurement.get(field) - if isinstance(value, bool) or not isinstance(value, (int, float)): - return r"\matrixna{ReportMuted}" - number = float(value) - if not math.isfinite(number) or number < 0.0: - return r"\matrixna{ReportMuted}" - return _best_mode_time(number, microseconds=microseconds) - - -def _unverified_runtime_clocks(measurement: Measurement) -> tuple[str, str]: - """Return retained evaluator-total and outer-wall clocks for diagnostics.""" - - wall = _diagnostic_best_mode_time( - measurement, - "wall_seconds_per_point", - microseconds=True, - ) - evaluator_total = evaluator_total_seconds_per_point(measurement) - evaluator = ( - r"\matrixna{ReportMuted}" - if evaluator_total is None - else _best_mode_time(evaluator_total, microseconds=True) - ) - return evaluator, wall - - -def _unverified_absolute_time( - measurement: Measurement, - field: str, - *, - microseconds: bool = False, -) -> str: - """Render one retained diagnostic clock with its non-success marker.""" - - absolute = _diagnostic_best_mode_time( - measurement, - field, - microseconds=microseconds, - ) - return rf"\matrixruntimepair{{{absolute}}}{{{_status(measurement)}}}" - - -def _unverified_evaluator_total(measurement: Measurement) -> str: - """Render retained evaluator-total timing without making it comparable.""" - - total = evaluator_total_seconds_per_point(measurement) - absolute = ( - r"\matrixna{ReportMuted}" - if total is None - else _best_mode_time(total, microseconds=True) - ) - return rf"\matrixruntimepair{{{absolute}}}{{{_status(measurement)}}}" - - -def _ratio_value( - candidate: Measurement, - baseline: Measurement, - field: str, -) -> float | None: - if not (_ok(candidate) and _ok(baseline)): - return None - if field == "execution_seconds_per_point": - for measurement in (candidate, baseline): - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - continue - timing = provenance.get("execution_timing") - if isinstance(timing, Mapping) and timing.get("ratio_eligible") is not True: - return None - if ( - unavailable_execution_timing_record(candidate, field) is not None - or unavailable_execution_timing_record(baseline, field) is not None - ): - return None - numerator = candidate.get(field) - denominator = baseline.get(field) - if numerator is None or denominator is None: - return None - numerator_number = float(numerator) - denominator_number = float(denominator) - if ( - not math.isfinite(numerator_number) - or not math.isfinite(denominator_number) - or denominator_number <= 0.0 - ): - return None - return numerator_number / denominator_number - - -def _positive_timing_value( - measurement: Measurement, - field: str, -) -> float | None: - """Return one finite positive timing without changing its clock identity.""" - - if not _ok(measurement): - return None - value = measurement.get(field) - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - number = float(value) - if not math.isfinite(number) or number <= 0.0: - return None - return number - - -def _otf_cold_warmup_seconds(measurement: Measurement) -> float | None: - """Return the separately timed first OTF evaluation from provenance.""" - - provenance = measurement.get("provenance") - runtime_profile = ( - provenance.get("runtime_profile") - if isinstance(provenance, Mapping) - else None - ) - value = ( - runtime_profile.get("cold_warmup_elapsed_seconds") - if isinstance(runtime_profile, Mapping) - else None - ) - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - seconds = float(value) - if not math.isfinite(seconds) or seconds <= 0.0: - return None - return seconds - - -def _otf_generation_pair_layout( - candidate: Measurement, - baseline: Measurement | None, -) -> _BestModeComparisonLayout: - """Render OTF generation alone beside generation plus its first evaluation.""" - - generation = _positive_timing_value(candidate, "generation_seconds") - cold_warmup = _otf_cold_warmup_seconds(candidate) - if generation is None or cold_warmup is None: - unavailable = r"\matrixna{ReportMuted}" - return _BestModeComparisonLayout(unavailable, "", unavailable) - total = generation + cold_warmup - if not math.isfinite(total): - unavailable = r"\matrixna{ReportMuted}" - return _BestModeComparisonLayout(unavailable, "", unavailable) - - if baseline is None: - generation_text = _best_mode_value(generation) - total_text = _best_mode_value(total) - return _BestModeComparisonLayout( - rf"\bestmodecompactabsolute{{{generation_text}}}{{{total_text}}}", - rf"\bestmodecompactabsoluteprefix{{{generation_text}}}", - rf"\bestmodeabsoluteprimary{{{total_text}}}", - ) - - denominator = _positive_timing_value(baseline, "generation_seconds") - if denominator is None: - unavailable = r"\matrixna{ReportMuted}" - return _BestModeComparisonLayout(unavailable, "", unavailable) - generation_ratio = generation / denominator - total_ratio = total / denominator - color = _best_mode_ratio_color(total_ratio) - generation_text = _best_mode_value(generation_ratio) - total_text = _best_mode_value(total_ratio) - return _BestModeComparisonLayout( - rf"\bestmodecompactratio{{{generation_text}}}{{{color}}}{{{total_text}}}", - rf"\bestmodecompactprefix{{{generation_text}}}", - rf"\bestmodeprimaryratio{{{color}}}{{{total_text}}}", - ) - - -def _secondary_runtime_ratio( - candidate: Measurement, - baseline: Measurement, - *, - baseline_mode: ExecutionMode, -) -> float | None: - """Return the documented supplementary runtime ratio, if available. - - The clock hierarchy is deliberately strict: compare exposed execution - attribution first, then authenticated evaluator totals. Only the legacy - AmpliCol reference may supply its direct execution (or wall) clock when it - has no evaluator-total record; a recurrence core is never used as the - denominator for another backend's evaluator total. - """ - - execution_ratio = _ratio_value( - candidate, - baseline, - "execution_seconds_per_point", - ) - if execution_ratio is not None: - return execution_ratio - - candidate_total = evaluator_total_seconds_per_point(candidate) - if candidate_total is None: - return None - baseline_total = evaluator_total_seconds_per_point(baseline) - if baseline_total is not None: - return candidate_total / baseline_total - if baseline_mode is not ExecutionMode.AMPLICOL: - return None - - legacy_direct = _positive_timing_value( - baseline, - "execution_seconds_per_point", - ) - if legacy_direct is None: - legacy_direct = _positive_timing_value( - baseline, - "wall_seconds_per_point", - ) - if legacy_direct is None: - return None - return candidate_total / legacy_direct - - -def _ratio(candidate: Measurement, baseline: Measurement, field: str) -> str: - value = _ratio_value(candidate, baseline, field) - if value is None: - if not _ok(candidate): - return _status(candidate) - if ( - unavailable_execution_timing_record(candidate, field) is not None - or unavailable_execution_timing_record(baseline, field) is not None - ): - return _not_exposed() - return r"\matrixnaratio{ReportMuted}" - color = ( - "ReportGreen" if value < 1.0 else "ReportOrange" if value < 2.0 else "ReportRed" - ) - return rf"\matrixratio{{{color}}}{{{_compact(value)}}}" - - -def _ratio_or_absolute( - candidate: Measurement, - baseline: Measurement, - field: str, - *, - absolute: bool, - microseconds: bool = False, -) -> str: - if absolute and _ok(candidate): - return ( - r"\matrixncabsolute{" - + _metric(candidate, field, microseconds=microseconds) - + "}" - ) - return _ratio(candidate, baseline, field) - - -def _evaluator_total_clock(measurement: Measurement) -> str: - total = evaluator_total_seconds_per_point(measurement) - value = _not_exposed() if total is None else _time(total, microseconds=True) - return r"\matrixtotalevaluator{" + value + "}" - - -def _recurrence_core_clock(measurement: Measurement) -> str: - core = recurrence_core_seconds_per_point(measurement) - value = _not_exposed() if core is None else _time(core, microseconds=True) - return r"\matrixrecurrencecore{" + value + "}" - - -def _ratio_pair( - candidate: Measurement, - baseline: Measurement, - *, - candidate_mode: ExecutionMode, -) -> str: - wall = _ratio_value(candidate, baseline, "wall_seconds_per_point") - if not _ok(candidate): - return _status(candidate) - if wall is None: - wall_clock = r"\matrixna{ReportMuted}" - else: - color = ( - "ReportGreen" - if wall < 1.0 - else "ReportOrange" - if wall < 2.0 - else "ReportRed" - ) - wall_clock = rf"\matrixwallclock{{{color}}}{{x{_compact(wall)}}}" - total_clock = _evaluator_total_clock(candidate) - if candidate_mode is not ExecutionMode.RECURRENCE: - return rf"\matrixruntimepair{{{wall_clock}}}{{{total_clock}}}" - return ( - rf"\matrixruntimetriple{{{wall_clock}}}{{{total_clock}}}" - rf"{{{_recurrence_core_clock(candidate)}}}" - ) - - -def _ratio_pair_or_absolute( - candidate: Measurement, - baseline: Measurement, - *, - candidate_mode: ExecutionMode, - absolute: bool, -) -> str: - if absolute and _ok(candidate): - wall = _metric(candidate, "wall_seconds_per_point", microseconds=True) - wall_clock = r"\matrixncabsolute{\matrixwallabsolute{" + wall + "}}" - total_clock = _evaluator_total_clock(candidate) - if candidate_mode is not ExecutionMode.RECURRENCE: - return rf"\matrixruntimepair{{{wall_clock}}}{{{total_clock}}}" - return ( - rf"\matrixruntimetriple{{{wall_clock}}}{{{total_clock}}}" - rf"{{{_recurrence_core_clock(candidate)}}}" - ) - return _ratio_pair( - candidate, - baseline, - candidate_mode=candidate_mode, - ) - - -def _matrix_macros() -> list[str]: - return [ - r"\providecommand{\matrixentryfont}{\fontsize{6.8pt}{7.8pt}\selectfont}", - r"\providecommand{\matrixentryfontlc}{\fontsize{6.5pt}{7.5pt}\selectfont}", - r"\providecommand{\matrixsummaryfont}{\fontsize{6.2pt}{7.4pt}\selectfont}", - ( - r"\providecommand{\matrixfitwidth}[1]{\begingroup" - r"\sbox0{#1}\ifdim\wd0>\linewidth" - r"\resizebox{\linewidth}{!}{\usebox0}" - r"\else\makebox[\linewidth][c]{\usebox0}\fi\endgroup}" - ), - r"\providecommand{\matrixpunct}[1]{\textcolor{black}{\texttt{#1}}}", - ( - r"\providecommand{\matrixratio}[2]{\matrixpunct{(}" - r"\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}}" - ), - r"\providecommand{\matrixna}[1]{\textcolor{#1}{\texttt{N/A}}}", - ( - r"\providecommand{\matrixnotapplicable}[1]{" - r"\textcolor{#1}{\textsc{not applicable}}}" - ), - ( - r"\providecommand{\matrixnotexposed}[1]{" - r"\textcolor{#1}{\textsc{not exposed}}}" - ), - ( - r"\providecommand{\matrixstaticna}[1]{" - r"\textcolor{#1}{\textsc{static N/A}}}" - ), - ( - r"\providecommand{\matrixtotalevaluator}[1]{" - r"\textcolor{ReportBlue}{\texttt{T }}#1}" - ), - ( - r"\providecommand{\matrixrecurrencecore}[1]{" - r"\textcolor{ReportOrange}{\texttt{C }}#1}" - ), - ( - r"\providecommand{\matrixzrecurrenceclocks}[2]{" - r"\shortstack[r]{#1\\#2}}" - ), - ( - r"\providecommand{\matrixwallclock}[2]{" - r"\textcolor{#1}{\texttt{W #2}}}" - ), - ( - r"\providecommand{\matrixwallabsolute}[1]{" - r"\textcolor{ReportBlue}{\texttt{W }}#1}" - ), - ( - r"\providecommand{\matrixruntimepair}[2]{" - r"\shortstack[l]{#1\\#2}}" - ), - ( - r"\providecommand{\matrixruntimetriple}[3]{" - r"\shortstack[l]{#1\\#2\matrixpunct{ | }#3}}" - ), - r"\providecommand{\matrixbelow}[1]{\textcolor{ReportMuted}{\texttt{<#1}}}", - ( - r"\providecommand{\matrixnaratio}[1]{\matrixpunct{(}" - r"\matrixna{#1}\matrixpunct{)}}" - ), - r"\providecommand{\matrixstatus}[2]{\textcolor{#1}{\textsc{#2}}}", - ( - r"\providecommand{\matrixncabsolute}[1]{" - r"#1}" - ), - ( - r"\providecommand{\matrixsummaryratio}[2]{" - r"\textcolor{#1}{\texttt{x#2}}}" - ), - ( - r"\providecommand{\matrixsummaryratiohighlight}[2]{" - r"\begingroup\setlength{\fboxsep}{0.9pt}" - r"\setlength{\fboxrule}{0.35pt}" - r"\fbox{\textcolor{#1}{{\usefont{T1}{lmtt}{b}{n}x#2}}}" - r"\endgroup}" - ), - # Keep the five statistic anchors identical on every summary line. - # Max accommodates scientific notation; weighted average carries the frame. - ( - r"\providecommand{\matrixsummarystats}[5]{" - r"\begingroup\matrixsummaryfont" - r"\begin{tabular}[t]{@{}l" - r"@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l" - r"@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l" - r"@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l" - r"@{\hspace{0.014in}\matrixpunct{|}\hspace{0.014in}}l@{}}" - r"\makebox[3.6em][l]{#1}&" - r"\makebox[4.6em][l]{#2}&" - r"\makebox[3.6em][l]{#3}&" - r"\makebox[3.6em][l]{#4}&" - r"\makebox[4.2em][l]{#5}" - r"\end{tabular}\endgroup}" - ), - ( - r"\providecommand{\matrixsummaryworkloads}[2]{" - r"\begin{tabular}[t]{@{}l@{}}#1\\[-0.10em]#2\end{tabular}}" - ), - ] - - -def _compact_comparison_macros() -> list[str]: - """Return the compact aligned comparison vocabulary shared by matrices.""" - - return [ - ( - r"\providecommand{\bestmoderatio}[2]{" - r"\textcolor{#1}{\texttt{x#2}}}" - ), - ( - r"\providecommand{\bestmodecompactratio}[3]{" - r"\matrixpunct{(}" - r"\textcolor{ReportMuted}{\texttt{[x#1]}}" - r"\hspace{0.04in}" - r"\textcolor{#2}{\texttt{x#3}}" - r"\matrixpunct{)}}" - ), - ( - r"\providecommand{\bestmodewallratio}[2]{" - r"\matrixpunct{(}\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}}" - ), - ( - r"\providecommand{\bestmodecompactprefix}[1]{" - r"\matrixpunct{(}\textcolor{ReportMuted}{\texttt{[x#1]}}" - r"\hspace{0.04in}}" - ), - ( - r"\providecommand{\bestmodeopenprefix}{" - r"\matrixpunct{(}\hspace{0.04in}}" - ), - ( - r"\providecommand{\bestmodeprimaryratio}[2]{" - r"\textcolor{#1}{\texttt{x#2}}\matrixpunct{)}}" - ), - ( - r"\providecommand{\bestmodeabsoluteprefix}[1]{" - r"#1\hspace{0.04in}}" - ), - ( - r"\providecommand{\bestmodecompactabsolute}[2]{" - r"\textcolor{ReportMuted}{\texttt{[#1]}}" - r"\hspace{0.04in}\textcolor{black}{\texttt{#2}}}" - ), - ( - r"\providecommand{\bestmodecompactabsoluteprefix}[1]{" - r"\textcolor{ReportMuted}{\texttt{[#1]}}\hspace{0.04in}}" - ), - ( - r"\providecommand{\bestmodeabsoluteprimary}[1]{" - r"\textcolor{black}{\texttt{#1}}}" - ), - ( - r"\providecommand{\bestmodeunverifiedclockprefix}[2]{" - r"\textcolor{ReportMuted}{\texttt{[}#1\texttt{]}}" - r"\hspace{0.04in}#2\hspace{0.04in}}" - ), - ] - - -def _not_applicable() -> str: - return r"\matrixnotapplicable{ReportMuted}" - - -def _not_run() -> str: - return r"\matrixstatus{ReportMuted}{not run}" - - -def _matrix_scope_marker( - family: ProcessFamily, - n_final: int, - accuracy: Accuracy, -) -> str: - """Distinguish nonexistent processes from intentionally unrun cells.""" - - if family.process(n_final) is None: - return _not_applicable() - if n_final > family.maximum_n(accuracy): - return _not_run() - raise ValueError("applicable matrix cell has no scope marker") - - -def _not_exposed() -> str: - return r"\matrixnotexposed{ReportMuted}" - - -def _static_na() -> str: - return r"\matrixstaticna{ReportMuted}" - - -def _legacy_baseline_static_na( - *, - catalog: ReportCatalog, - accuracy: Accuracy, - process_key: str, - n_final: int, - workload: Workload, -) -> bool: - baseline = next( - cell - for cell in catalog.measurement_cells() - if cell.dataset_id == f"reference_amplicol_{accuracy.value}" - and cell.process_key == process_key - and cell.n_final == n_final - and cell.workload is workload - ) - return catalog.static_na_reason(baseline) is not None - - -def _legacy_baseline_unavailable( - view: JoinedMatrixCell, - *, - catalog: ReportCatalog, -) -> bool: - return ( - view.dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - and _legacy_baseline_static_na( - catalog=catalog, - accuracy=view.dataset.baseline.accuracy, - process_key=view.process_family.key, - n_final=view.n_final, - workload=view.workloads[0].workload, - ) - ) - - -def _generation_comparison_linked( - joined: JoinedWorkload | BestModeWorkload, -) -> bool: - """Use a metric-specific link when generation is process-wide.""" - - if joined.generation_comparison_linked is None: - return joined.comparison_linked - return joined.generation_comparison_linked - - -def _fixed_mode_generation_comparison_layout( - joined: JoinedWorkload, - *, - candidate_mode: ExecutionMode, - baseline_mode: ExecutionMode, - baseline_static_na: bool = False, - comparable: bool = True, -) -> _BestModeComparisonLayout: - """Render one fixed-engine generation comparison without a mode letter.""" - - if joined.candidate.get("status") == ResultStatus.UNVERIFIED.value: - absolute = _diagnostic_best_mode_time( - joined.candidate, - "generation_seconds", - ) - status = _status(joined.candidate) - return _BestModeComparisonLayout( - rf"{absolute}\,{status}", - rf"\bestmodeabsoluteprefix{{{absolute}}}", - status, - ) - if not _ok(joined.candidate): - status = _status(joined.candidate) - return _BestModeComparisonLayout(status, "", status) - if ( - candidate_mode is ExecutionMode.ON_THE_FLY - and baseline_mode is ExecutionMode.AMPLICOL - ): - if ( - joined.workload is Workload.ALL_FLOW - or baseline_static_na - or not comparable - or not _generation_comparison_linked(joined) - or not _ok(joined.baseline) - ): - return _otf_generation_pair_layout(joined.candidate, None) - return _otf_generation_pair_layout(joined.candidate, joined.baseline) - if ( - baseline_static_na - or not comparable - or not _generation_comparison_linked(joined) - or (baseline_mode is ExecutionMode.AMPLICOL and not _ok(joined.baseline)) - ): - absolute = _best_mode_metric(joined.candidate, "generation_seconds") - return _BestModeComparisonLayout( - absolute, - rf"\bestmodeabsoluteprefix{{{absolute}}}", - "", - ) - if not _ok(joined.baseline): - status = _status(joined.baseline) - return _BestModeComparisonLayout(status, "", status) - generation_ratio = _ratio_value( - joined.candidate, - joined.baseline, - "generation_seconds", - ) - if generation_ratio is None: - unavailable = r"\matrixna{ReportMuted}" - return _BestModeComparisonLayout(unavailable, "", unavailable) - ratio = ( - rf"\bestmoderatio{{{_best_mode_ratio_color(generation_ratio)}}}" - rf"{{{_best_mode_value(generation_ratio)}}}" - ) - return _BestModeComparisonLayout(ratio, "", ratio) - - -def _fixed_mode_runtime_comparison_layout( - joined: JoinedWorkload, - *, - candidate_mode: ExecutionMode, - baseline_mode: ExecutionMode, - baseline_static_na: bool = False, -) -> _BestModeComparisonLayout: - """Use the best-table compact clock layout for one fixed engine.""" - - if joined.candidate.get("status") == ResultStatus.UNVERIFIED.value: - evaluator, wall = _unverified_runtime_clocks(joined.candidate) - status = _status(joined.candidate) - clocks = rf"\bestmodeunverifiedclockprefix{{{evaluator}}}{{{wall}}}" - return _BestModeComparisonLayout( - rf"{clocks}{status}", - clocks, - status, - ) - - return _best_mode_runtime_comparison_layout( - BestModeWorkload( - workload=joined.workload, - baseline=joined.baseline, - candidate=joined.candidate, - mode=candidate_mode, - terminal_label=None, - comparison_linked=joined.comparison_linked, - ), - baseline_mode=baseline_mode, - baseline_static_na=baseline_static_na, - ) - - -def _lc_cell( - view: JoinedMatrixCell, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> _MatrixCellRows: - selected, all_flow = view.workloads - legacy_baseline_unavailable = _legacy_baseline_unavailable( - view, - catalog=catalog, - ) - selected_baseline_generation = ( - _static_na() - if legacy_baseline_unavailable - else ( - _original_amplicol_generation_metric( - selected, - candidate_mode=view.dataset.candidate.execution_mode, - ) - if view.dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - else _best_mode_metric(selected.baseline, "generation_seconds") - ) - ) - all_flow_baseline_generation = ( - _static_na() - if legacy_baseline_unavailable - else ( - _original_amplicol_generation_metric( - all_flow, - candidate_mode=view.dataset.candidate.execution_mode, - ) - if view.dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - else _best_mode_metric(all_flow.baseline, "generation_seconds") - ) - ) - selected_generation = _fixed_mode_generation_comparison_layout( - selected, - candidate_mode=view.dataset.candidate.execution_mode, - baseline_mode=view.dataset.baseline.execution_mode, - baseline_static_na=legacy_baseline_unavailable, - ) - all_flow_generation = _fixed_mode_generation_comparison_layout( - all_flow, - candidate_mode=view.dataset.candidate.execution_mode, - baseline_mode=view.dataset.baseline.execution_mode, - baseline_static_na=legacy_baseline_unavailable, - comparable=not ( - view.dataset.candidate.execution_mode is ExecutionMode.RECURRENCE - and view.dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - ), - ) - selected_baseline_runtime = ( - _static_na() - if legacy_baseline_unavailable - else _best_mode_metric( - selected.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ) - all_flow_baseline_runtime = ( - _static_na() - if legacy_baseline_unavailable - else _best_mode_metric( - all_flow.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ) - selected_runtime = _fixed_mode_runtime_comparison_layout( - selected, - candidate_mode=view.dataset.candidate.execution_mode, - baseline_mode=view.dataset.baseline.execution_mode, - baseline_static_na=legacy_baseline_unavailable, - ) - all_flow_runtime = _fixed_mode_runtime_comparison_layout( - all_flow, - candidate_mode=view.dataset.candidate.execution_mode, - baseline_mode=view.dataset.baseline.execution_mode, - baseline_static_na=legacy_baseline_unavailable, - ) - return _MatrixCellRows( - generation=( - selected_baseline_generation, - r"\matrixpunct{|}", - all_flow_baseline_generation, - *_best_mode_comparison_columns(selected_generation), - r"\matrixpunct{|}", - *_best_mode_comparison_columns(all_flow_generation), - ), - runtime=( - selected_baseline_runtime, - r"\matrixpunct{|}", - all_flow_baseline_runtime, - *_best_mode_comparison_columns(selected_runtime), - r"\matrixpunct{|}", - *_best_mode_comparison_columns(all_flow_runtime), - ), - ) - - -def _contracted_cell( - view: JoinedMatrixCell, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> _MatrixCellRows: - joined = view.workloads[0] - candidate_cell = next( - cell - for cell in catalog.measurement_cells() - if cell.dataset_id == view.dataset.dataset_id - and cell.process_key == view.process_family.key - and cell.n_final == view.n_final - and cell.workload is joined.workload - and cell.variant is None - ) - candidate_static_na = catalog.static_na_reason(candidate_cell) is not None - legacy_baseline_unavailable = _legacy_baseline_unavailable( - view, - catalog=catalog, - ) - candidate_generation = ( - _BestModeComparisonLayout(_static_na(), "", _static_na()) - if candidate_static_na - else _fixed_mode_generation_comparison_layout( - joined, - candidate_mode=view.dataset.candidate.execution_mode, - baseline_mode=view.dataset.baseline.execution_mode, - baseline_static_na=legacy_baseline_unavailable, - ) - ) - candidate_runtime = ( - _BestModeComparisonLayout(_static_na(), "", _static_na()) - if candidate_static_na - else _fixed_mode_runtime_comparison_layout( - joined, - candidate_mode=view.dataset.candidate.execution_mode, - baseline_mode=view.dataset.baseline.execution_mode, - baseline_static_na=legacy_baseline_unavailable, - ) - ) - baseline_generation = ( - _static_na() - if legacy_baseline_unavailable - else ( - _original_amplicol_generation_metric( - joined, - candidate_mode=view.dataset.candidate.execution_mode, - ) - if view.dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - else _best_mode_metric(joined.baseline, "generation_seconds") - ) - ) - baseline_runtime = ( - _static_na() - if legacy_baseline_unavailable - else _best_mode_metric( - joined.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ) - return _MatrixCellRows( - generation=( - baseline_generation, - *_best_mode_comparison_columns(candidate_generation), - ), - runtime=( - baseline_runtime, - *_best_mode_comparison_columns(candidate_runtime), - ), - ) - - -def _summary_pair( - views: Sequence[JoinedMatrixCell], - workload: Workload, - field: str, -) -> str: - joined = [ - next(item for item in view.workloads if item.workload is workload) - for view in views - if view.applicable - ] - valid = [ - item - for item in joined - if ( - _generation_comparison_linked(item) - if field == "generation_seconds" - else item.comparison_linked - ) - and _ok(item.baseline) - and _ok(item.candidate) - and item.baseline.get(field) is not None - and item.candidate.get(field) is not None - and unavailable_execution_timing_record(item.baseline, field) is None - and unavailable_execution_timing_record(item.candidate, field) is None - and math.isfinite(float(item.baseline[field])) - and math.isfinite(float(item.candidate[field])) - and float(item.baseline[field]) > 0.0 - and float(item.candidate[field]) >= 0.0 - ] - if not valid: - if field == "execution_seconds_per_point" and any( - unavailable_execution_timing_record(measurement, field) is not None - for item in joined - for measurement in (item.baseline, item.candidate) - ): - return _not_exposed() - for item in joined: - if not _ok(item.candidate) and policy_status_label(item.candidate): - return _status(item.candidate) - if not _ok(item.baseline) and policy_status_label(item.baseline): - return _status(item.baseline) - return r"\matrixna{ReportMuted}" - return _ratio_statistics_tex( - tuple( - (float(item.baseline[field]), float(item.candidate[field])) - for item in valid - ) - ) - - -def _ratio_statistics_tex( - timings: Sequence[tuple[float, float]], -) -> str: - """Render min/max/median/mean/ratio-of-sums for timing pairs.""" - - ratios = tuple(candidate / baseline for baseline, candidate in timings) - ordered = tuple(sorted(ratios)) - middle = len(ordered) // 2 - median = ( - ordered[middle] - if len(ordered) % 2 - else (ordered[middle - 1] + ordered[middle]) / 2.0 - ) - average = math.fsum(ratios) / len(ratios) - baseline_sum = math.fsum(baseline for baseline, _candidate in timings) - candidate_sum = math.fsum(candidate for _baseline, candidate in timings) - weighted_average = candidate_sum / baseline_sum - statistics = ( - ordered[0], - ordered[-1], - median, - average, - weighted_average, - ) - rendered = tuple( - ( - rf"\matrixsummaryratiohighlight" - rf"{{{_best_mode_ratio_color(value)}}}" - rf"{{{_best_mode_value(value)}}}" - if index == 4 - else rf"\matrixsummaryratio{{{_best_mode_ratio_color(value)}}}" - rf"{{{_best_mode_value(value)}}}" - ) - for index, value in enumerate(statistics) - ) - return r"\matrixsummarystats{" + "}{".join(rendered) + "}" - - -def _matrix_block( - adapter: BaselineCandidateAdapter, - dataset: MatrixDataset, - multiplicities: tuple[int, ...], - *, - block_index: int, - block_count: int, - baseline_dataset_id: str | None = None, -) -> list[str]: - if len(multiplicities) not in (2, 3): - raise ValueError("matrix blocks must contain two or three multiplicities") - accuracy = dataset.candidate.accuracy - array_stretch = ( - "1.00" - if dataset.candidate.execution_mode is ExecutionMode.ON_THE_FLY - and accuracy is Accuracy.LC - else "1.04" - ) - column_spec = _metric_table_column_spec( - accuracy, - len(multiplicities), - ) - lines = [ - r"\clearpage", - r"\noindent\begin{minipage}{\linewidth}", - ( - rf"\subsubsection*{{{_tex_escape(dataset.title)}" - + ( - "" - if block_count == 1 - else rf" (block {block_index + 1} of {block_count})" - ) - + "}" - ), - r"\begingroup", - r"\centering", - r"\footnotesize", - r"\setlength{\tabcolsep}{2.1pt}", - rf"\renewcommand{{\arraystretch}}{{{array_stretch}}}", - r"\matrixfitwidth{%", - rf"\begin{{tabular}}{{{column_spec}}}", - r"\toprule", - ( - r"\textbf{ID} & \textbf{base process} & \textbf{metric} & " - + " & ".join( - _metric_group_cell( - rf"\textbf{{n={n_final}}}", - accuracy, - ) - for n_final in multiplicities - ) - + r" \\" - ), - r"\specialrule{0.85pt}{0pt}{0pt}", - ] - views_by_n: dict[int, list[JoinedMatrixCell]] = { - n_final: [] for n_final in multiplicities - } - for row_index, family in enumerate(adapter.catalog.process_families): - generation_row = [ - rf"\texttt{{{family.identifier}}}", - family.label_tex, - _metric_row_label(runtime=False), - ] - runtime_row = ["", "", _metric_row_label(runtime=True)] - for n_final in multiplicities: - view = adapter.matrix_cell( - dataset, - family, - n_final, - baseline_dataset_id=baseline_dataset_id, - ) - views_by_n[n_final].append(view) - if not view.applicable: - generation_row.append( - _metric_group_cell( - _matrix_scope_marker(family, n_final, accuracy), - accuracy, - ) - ) - runtime_row.append( - _metric_group_cell( - "", - accuracy, - ) - ) - elif accuracy is Accuracy.LC: - rendered = _lc_cell(view, catalog=adapter.catalog) - generation_row.extend(rendered.generation) - runtime_row.extend(rendered.runtime) - else: - rendered = _contracted_cell(view, catalog=adapter.catalog) - generation_row.extend(rendered.generation) - runtime_row.extend(rendered.runtime) - if row_index % 2 == 0: - lines.append(r"\rowcolor{refblue}") - lines.append(" & ".join(generation_row) + r" \\") - if row_index % 2 == 0: - lines.append(r"\rowcolor{refblue}") - lines.append(" & ".join(runtime_row) + r" \\") - lines.append(r"\addlinespace[0.05em]") - lines.extend( - [ - r"\specialrule{1.05pt}{0.22em}{0.18em}", - _metric_summary_header_row(multiplicities, accuracy), - ( - r"\multicolumn{3}{@{}l}{\textbf{summary: generation}} & " - + " & ".join( - _metric_summary_group_cell( - _matrix_generation_summary( - views_by_n[n_final], - dataset, - catalog=adapter.catalog, - ), - accuracy, - group_index=group_index, - ) - for group_index, n_final in enumerate(multiplicities) - ) - + r" \\[0.08em]" - ), - ( - rf"\multicolumn{{3}}{{@{{}}l}}{{" - rf"{_matrix_wall_summary_label(accuracy)}}} & " - + " & ".join( - _metric_summary_group_cell( - _matrix_wall_summary( - views_by_n[n_final], - accuracy, - dataset=dataset, - catalog=adapter.catalog, - ), - accuracy, - group_index=group_index, - ) - for group_index, n_final in enumerate(multiplicities) - ) - + r" \\" - ), - r"\bottomrule", - r"\end{tabular}", - r"}", - r"\endgroup", - _matrix_legend(dataset), - r"\end{minipage}", - ] - ) - return lines - - -def _matrix_generation_summary( - views: Sequence[JoinedMatrixCell], - dataset: MatrixDataset, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> str: - if _matrix_candidates_are_static_na(views, dataset, catalog=catalog): - return _static_na() - if dataset.candidate.accuracy is Accuracy.LC: - return _summary_pair( - views, - Workload.SELECTED_FLOW, - "generation_seconds", - ) - return _summary_pair(views, Workload.CONTRACTED, "generation_seconds") - - -def _matrix_wall_summary( - views: Sequence[JoinedMatrixCell], - accuracy: Accuracy, - *, - dataset: MatrixDataset | None = None, - catalog: ReportCatalog = REPORT_CATALOG, -) -> str: - if dataset is not None and _matrix_candidates_are_static_na( - views, - dataset, - catalog=catalog, - ): - return _static_na() - if accuracy is Accuracy.LC: - selected = _summary_pair( - views, - Workload.SELECTED_FLOW, - "wall_seconds_per_point", - ) - all_flow = _summary_pair( - views, - Workload.ALL_FLOW, - "wall_seconds_per_point", - ) - return rf"\matrixsummaryworkloads{{{selected}}}{{{all_flow}}}" - return _summary_pair( - views, - Workload.CONTRACTED, - "wall_seconds_per_point", - ) - - -def _matrix_candidates_are_static_na( - views: Sequence[JoinedMatrixCell], - dataset: MatrixDataset, - *, - catalog: ReportCatalog, -) -> bool: - candidate_cells = { - (cell.process_key, cell.n_final, cell.workload): cell - for cell in catalog.measurement_cells() - if cell.dataset_id == dataset.dataset_id and cell.variant is None - } - applicable = tuple(view for view in views if view.applicable) - return bool(applicable) and all( - catalog.static_na_reason( - candidate_cells[ - (view.process_family.key, view.n_final, joined.workload) - ] - ) - is not None - for view in applicable - for joined in view.workloads - ) - - -def _mode_label(mode: ExecutionMode) -> str: - return { - ExecutionMode.AMPLICOL: "original AmpliCol", - ExecutionMode.MADGRAPH: "MadGraph standalone", - ExecutionMode.RECURRENCE: "recurrence JIT O2", - ExecutionMode.COMPILED: "compiled JIT O3", - ExecutionMode.EAGER: "eager-DAG JIT O2", - ExecutionMode.ON_THE_FLY: "on-the-fly JIT O2", - }[mode] - - -def _matrix_legend(dataset: MatrixDataset) -> str: - baseline = _mode_label(dataset.baseline.execution_mode) - candidate = _mode_label(dataset.candidate.execution_mode) - if dataset.candidate.accuracy is Accuracy.LC: - if ( - dataset.candidate.execution_mode is ExecutionMode.ON_THE_FLY - and dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - ): - detail = ( - "Each cell shows non-union-flow and union-flow quantities. " - "For non-union flow, generation is ([xG] x(G+W)): the muted " - "inner multiplier is artifact generation G alone and the " - "normally coloured outer multiplier adds exactly the first " - "cold on-the-fly evaluation W, both relative to AmpliCol " - "selected-flow generation. For union flow, generation is the " - "absolute [G] G+W pair, with G muted and G+W in normal black. " - "W excludes artifact loading and conventional benchmark warm-ups." - ) - elif ( - dataset.candidate.execution_mode is ExecutionMode.RECURRENCE - and dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - ): - detail = ( - "Each cell shows the selected-flow library-generation and " - "all-flow direct-setup baseline quantities. The selected-flow " - "entry carries a generation ratio; the all-flow entry carries " - "the absolute pyAmpliCol process-generation time. Its setup " - "boundary differs from the reference, so no generation ratio " - "is formed." - ) - else: - detail = ( - "Each cell shows the topology-replay/all-flow-union baseline " - "generation times and wall times, followed by layout-matched " - "candidate/baseline generation and wall-time ratios." - ) - else: - detail = ( - "Each cell shows the baseline generation and wall time, followed by " - "candidate/baseline generation and wall-time ratios." - ) - clock_detail = ( - " Runtime comparisons use ([xS]xW). The muted supplementary xS first " - "compares compatible exposed execution attributions; otherwise it " - "compares authenticated evaluator totals. Only when original AmpliCol " - "has no evaluator-total clock may a candidate evaluator total use the " - "legacy direct execution clock (or its wall clock when direct execution " - "is absent) as denominator. An evaluator total is never divided by a " - "recurrence core. This evaluator-total fallback is diagnostic only; the " - "execution/execution ratio remains the compatible supplementary " - "attribution. The coloured xW is always the candidate/baseline wall " - "multiplier and remains the primary figure of merit. When no compatible " - "supplementary clock exists, only (xW) is shown. No clock is fabricated " - "from another. Every displayed number uses exactly three significant " - "digits." - ) - legacy_scope_detail = ( - " Original AmpliCol is static N/A beyond three open quark lines; " - "unavailable, terminal, or unlinked baselines keep their status while " - "successful candidate timings remain absolute and leave summaries." - if dataset.baseline.execution_mode is ExecutionMode.AMPLICOL - else "" - ) - madgraph_reference_detail = ( - " MadGraph standalone is the authoritative full-colour numerical " - "reference; its generation and repeated-evaluation measurements are " - "shared by all four UFO-SM comparison views. Recurrence, compiled, and " - "eager candidates use p200 at the comparison point; the on-the-fly " - "candidate uses its supported p16 lane." - if dataset.baseline.execution_mode is ExecutionMode.MADGRAPH - else "" - ) - unverified_detail = ( - " Unverified compiled or eager diagnostics show absolute generation " - "and runtime values with a yellow unverified marker, but never enter " - "ratios or summaries. In their runtime token the muted bracketed value " - "is evaluator-total and the following value is outer wall time." - if dataset.candidate.execution_mode - in {ExecutionMode.COMPILED, ExecutionMode.EAGER} - else "" - ) - summary_detail = ( - " Summary rows contain multipliers only in min, max, median, average, " - "and weighted-average order; the weighted average is the ratio of " - "timing sums and is the framed bold entry. LC generation uses selected " - "flow only, while LC " - "runtime shows separate selected-flow and all-flow wall-only lines." - if dataset.candidate.accuracy is Accuracy.LC - else " Summary rows contain multipliers only in min, max, median, average, " - "and weighted-average order; the weighted average is the ratio of " - "timing sums, is the framed bold entry, and runtime statistics use wall " - "time only." - ) - comparison_identity_detail = ( - " Ratios and summaries require exact stored linkage to the current denominator." - if dataset.baseline.execution_mode is not ExecutionMode.AMPLICOL - else "" - ) - return ( - r"\ReportTableNote{{\scriptsize Baseline: " - + _tex_escape(baseline) - + "; candidate: " - + _tex_escape(candidate) - + ". " - + _tex_escape(detail) - + _tex_escape(clock_detail) - + _tex_escape(legacy_scope_detail) - + _tex_escape(madgraph_reference_detail) - + _tex_escape(unverified_detail) - + _tex_escape(comparison_identity_detail) - + _tex_escape(summary_detail) - + " " - + _tex_escape( - "Not applicable marks a multiplicity for which the process family " - "does not exist. Not run marks an otherwise defined process that " - "was intentionally excluded from the declared measurement scope. " - "Fixed-engine tables intentionally omit mode letters because the " - "selected engine is named in the table heading." - ) - + "}}" - ) - - -def render_matrix_table( - dataset: MatrixDataset, - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, - baseline_dataset_id: str | None = None, -) -> str: - """Render one matrix dataset into nonbreaking page-sized TeX blocks.""" - - adapter = BaselineCandidateAdapter(caches, catalog=catalog) - # The scoped OTF LC surface has four multiplicities. Keep every rendered - # matrix block within the established two-or-three-column table grammar. - block_size = ( - 2 - if dataset.candidate.execution_mode is ExecutionMode.ON_THE_FLY - and len(dataset.multiplicities) == 4 - else _MATRIX_BLOCK_SIZE - ) - blocks = _chunks(dataset.multiplicities, block_size) - lines = [ - "% SPDX-License-Identifier: 0BSD", - "% Generated by tools/performance_report/render.py; do not edit.", - *_matrix_macros(), - ( - r"\providecommand{\matrixpair}[2]{" - r"\begin{tabular}[t]{@{}r@{\hspace{0.025in}" - r"\matrixpunct{|}\hspace{0.025in}}r@{}}" - r"#1\end{tabular}}" - ), - *_compact_comparison_macros(), - r"\clearpage", - rf"\subsection{{{_tex_escape(dataset.title)}}}", - ] - for block_index, multiplicities in enumerate(blocks): - block = _matrix_block( - adapter, - dataset, - multiplicities, - block_index=block_index, - block_count=len(blocks), - baseline_dataset_id=baseline_dataset_id, - ) - lines.extend(block[1:] if block_index == 0 else block) - return "\n".join(lines) + "\n" - - -def render_matrix_comparison_table( - view: MatrixComparisonView, - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> str: - """Render a cache-reusing matrix view against its explicit reference.""" - - candidate = catalog.dataset(view.candidate_dataset_id) - baseline_specs = { - cell.measurement - for cell in catalog.reference_cells() - if cell.dataset_id == view.baseline_dataset_id - } - if len(baseline_specs) != 1: - raise ValueError( - f"comparison view {view.comparison_id!r} has no unique baseline spec" - ) - dataset = replace( - candidate, - title=view.title, - table_name=view.table_name, - baseline=next(iter(baseline_specs)), - ) - return render_matrix_table( - dataset, - caches, - catalog=catalog, - baseline_dataset_id=view.baseline_dataset_id, - ) - - -def render_all_matrix_tables( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, str]: - """Render canonical matrices and cache-reusing comparison views.""" - - cache_source = caches if isinstance(caches, Mapping) else tuple(caches) - comparison_candidate_ids = { - view.candidate_dataset_id for view in catalog.matrix_comparison_views - } - rendered = { - dataset.table_name: render_matrix_table( - dataset, - cache_source, - catalog=catalog, - ) - for dataset in catalog.matrix_datasets - if not ( - dataset.dataset_id in comparison_candidate_ids - and dataset.baseline.execution_mode is ExecutionMode.MADGRAPH - ) - } - rendered.update( - { - view.table_name: render_matrix_comparison_table( - view, - cache_source, - catalog=catalog, - ) - for view in catalog.matrix_comparison_views - } - ) - return rendered - - -def _canonical_best_mode_terminal_label( - terminals: Sequence[_TerminalOutcome | _TerminalSummary | None], -) -> _TerminalSummary | None: - """Return one deterministic, bounded label for represented terminals.""" - - if not terminals: - return None - represented: list[_TerminalOutcome] = [] - for terminal in terminals: - if terminal is None: - continue - outcomes = ( - terminal.outcomes if isinstance(terminal, _TerminalSummary) else (terminal,) - ) - for outcome in outcomes: - key = (outcome.identity, outcome.label, outcome.color) - if all( - (item.identity, item.label, item.color) != key for item in represented - ): - represented.append(outcome) - - def order(outcome: _TerminalOutcome) -> tuple[int, float, str, str]: - time_cap = ( - _TIME_CAP_LABEL.fullmatch(outcome.label) - if outcome.color == "ReportOrange" - else None - ) - if time_cap is not None: - seconds = float(time_cap.group("value")) * ( - 3600.0 if time_cap.group("unit") == "h" else 1.0 - ) - return (0, seconds, outcome.label, outcome.identity) - ram_cap = ( - _RAM_CAP_LABEL.fullmatch(outcome.label) - if outcome.color == "ReportOrange" - else None - ) - if ram_cap is not None: - return (1, float(ram_cap.group("value")), outcome.label, outcome.identity) - if outcome.color == "ReportOrange" and outcome.label == "dependency": - return (2, 0.0, outcome.label, outcome.identity) - return (3, 0.0, outcome.label, outcome.identity) - - outcomes = tuple(sorted(represented, key=order)) - if not outcomes: - return None - labels = tuple(_compact_terminal_display(outcome) for outcome in outcomes) - label = " | ".join(labels) - if len(label) > _MAX_BEST_MODE_TERMINAL_LABEL_CHARS: - separators = 3 * (len(labels) - 1) - item_budget = max( - _TERMINAL_LABEL_DIGEST_CHARS + 3, - (_MAX_BEST_MODE_TERMINAL_LABEL_CHARS - separators) // len(labels), - ) - compacted: list[str] = [] - for outcome in outcomes: - if len(outcome.label) <= item_budget: - compacted.append(outcome.label) - continue - digest = hashlib.sha256( - f"{outcome.identity}\0{outcome.label}".encode() - ).hexdigest()[:_TERMINAL_LABEL_DIGEST_CHARS] - prefix_chars = item_budget - len(digest) - 2 - compacted.append(f"{outcome.label[:prefix_chars]}..{digest}") - label = " | ".join(compacted) - if len(label) > _MAX_BEST_MODE_TERMINAL_LABEL_CHARS: - identity_digest = hashlib.sha256( - "\0".join( - f"{outcome.identity}\0{outcome.label}\0{outcome.color}" - for outcome in outcomes - ).encode() - ).hexdigest()[:_TERMINAL_LABEL_DIGEST_CHARS] - label = f"{len(outcomes)} outcomes [{identity_digest}]" - color = ( - "ReportOrange" - if all(outcome.color == "ReportOrange" for outcome in outcomes) - else "ReportRed" - ) - return _TerminalSummary(outcomes=outcomes, label=label, color=color) - - -def _terminal_measurement_label(measurement: Measurement) -> _TerminalOutcome | None: - status = measurement.get("status") - if status in {ResultStatus.NOT_AVAILABLE.value, ResultStatus.OK.value}: - return None - return _visible_status(measurement) - - -def _best_mode_terminal_status(joined: BestModeWorkload) -> str: - if joined.terminal_label is None: - return _status(joined.candidate) - display_label = _compact_terminal_summary_display(joined.terminal_label) - return ( - rf"\matrixstatus{{{joined.terminal_label.color}}}" - rf"{{{_tex_escape(display_label)}}}" - ) - - -def _compact_terminal_summary_display(summary: _TerminalSummary) -> str: - if len(summary.outcomes) == 1: - return _compact_terminal_display(summary.outcomes[0]) - return _compact_terminal_display( - _TerminalOutcome( - identity="summary:" - + "|".join(outcome.identity for outcome in summary.outcomes), - label=summary.label, - color=summary.color, - ) - ) - - -def _best_mode_generation_comparison_layout( - joined: BestModeWorkload, - *, - baseline_static_na: bool = False, - comparable: bool = True, -) -> _BestModeComparisonLayout: - if joined.mode is None: - status = _best_mode_terminal_status(joined) - return _BestModeComparisonLayout(status, "", status) - if not _ok(joined.candidate): - status = _status(joined.candidate) - mode_code = _BEST_MODE_CODES[joined.mode] - return _BestModeComparisonLayout( - rf"\bestmodecodeprefix{{{mode_code}}}{status}", - rf"\bestmodecodeprefix{{{mode_code}}}", - status, - ) - assert joined.mode is not None - mode_code = _BEST_MODE_CODES[joined.mode] - if joined.mode is ExecutionMode.ON_THE_FLY: - absolute = ( - joined.workload is Workload.ALL_FLOW - or baseline_static_na - or not comparable - or not _generation_comparison_linked(joined) - or not _ok(joined.baseline) - ) - pair = _otf_generation_pair_layout( - joined.candidate, - None if absolute else joined.baseline, - ) - if absolute: - code = rf"\bestmodecode{{{mode_code}}}" - return _BestModeComparisonLayout( - rf"{pair.inline}\hspace{{0.025in}}{code}", - pair.prefix, - rf"{pair.primary}\hspace{{0.025in}}{code}", - ) - code_prefix = rf"\bestmodecodeprefix{{{mode_code}}}" - return _BestModeComparisonLayout( - f"{code_prefix}{pair.inline}", - f"{code_prefix}{pair.prefix}", - pair.primary, - ) - if ( - baseline_static_na - or not comparable - or not _generation_comparison_linked(joined) - or not _ok(joined.baseline) - ): - absolute = _best_mode_metric(joined.candidate, "generation_seconds") - return _BestModeComparisonLayout( - rf"\bestmodeabsolutechoice{{{absolute}}}{{{mode_code}}}", - rf"\bestmodeabsoluteprefix{{{absolute}}}", - rf"\bestmodecode{{{mode_code}}}", - ) - if not _ok(joined.baseline): - status = _status(joined.baseline) - return _BestModeComparisonLayout(status, "", status) - generation_ratio = _ratio_value( - joined.candidate, - joined.baseline, - "generation_seconds", - ) - if generation_ratio is None: - unavailable = r"\matrixna{ReportMuted}" - return _BestModeComparisonLayout(unavailable, "", unavailable) - generation_color = _best_mode_ratio_color(generation_ratio) - ratio = ( - rf"\bestmoderatio{{{generation_color}}}" - rf"{{{_best_mode_value(generation_ratio)}}}" - ) - return _BestModeComparisonLayout( - rf"\bestmodecodeprefix{{{mode_code}}}{ratio}", - rf"\bestmodecodeprefix{{{mode_code}}}", - ratio, - ) - - -def _best_mode_generation_comparison( - joined: BestModeWorkload, - *, - baseline_static_na: bool = False, - comparable: bool = True, -) -> str: - return _best_mode_generation_comparison_layout( - joined, - baseline_static_na=baseline_static_na, - comparable=comparable, - ).inline - - -def _best_mode_runtime_comparison_layout( - joined: BestModeWorkload, - *, - baseline_mode: ExecutionMode = ExecutionMode.AMPLICOL, - baseline_static_na: bool = False, -) -> _BestModeComparisonLayout: - if joined.mode is None: - status = _best_mode_terminal_status(joined) - return _BestModeComparisonLayout(status, "", status) - if not _ok(joined.candidate): - status = _status(joined.candidate) - return _BestModeComparisonLayout(status, "", status) - if ( - baseline_static_na - or not joined.comparison_linked - or (baseline_mode is ExecutionMode.AMPLICOL and not _ok(joined.baseline)) - ): - wall = _best_mode_metric( - joined.candidate, - "wall_seconds_per_point", - microseconds=True, - ) - return _BestModeComparisonLayout( - wall, - rf"\bestmodeabsoluteprefix{{{wall}}}", - "", - ) - if not _ok(joined.baseline): - status = _status(joined.baseline) - return _BestModeComparisonLayout(status, "", status) - wall_ratio = _ratio_value( - joined.candidate, - joined.baseline, - "wall_seconds_per_point", - ) - if wall_ratio is None: - unavailable = r"\matrixnaratio{ReportMuted}" - return _BestModeComparisonLayout(unavailable, "", unavailable) - wall_color = _best_mode_ratio_color(wall_ratio) - secondary_ratio = _secondary_runtime_ratio( - joined.candidate, - joined.baseline, - baseline_mode=baseline_mode, - ) - if secondary_ratio is None: - inline = ( - rf"\bestmodewallratio{{{wall_color}}}" - rf"{{{_best_mode_value(wall_ratio)}}}" - ) - return _BestModeComparisonLayout( - inline, - "", - inline, - ) - inline = ( - rf"\bestmodecompactratio{{{_best_mode_value(secondary_ratio)}}}" - rf"{{{wall_color}}}{{{_best_mode_value(wall_ratio)}}}" - ) - return _BestModeComparisonLayout( - inline, - rf"\bestmodecompactprefix{{{_best_mode_value(secondary_ratio)}}}", - ( - rf"\bestmodeprimaryratio{{{wall_color}}}" - rf"{{{_best_mode_value(wall_ratio)}}}" - ), - ) - - -def _best_mode_runtime_comparison( - joined: BestModeWorkload, - *, - baseline_static_na: bool = False, -) -> str: - return _best_mode_runtime_comparison_layout( - joined, - baseline_static_na=baseline_static_na, - ).inline - - -def _best_mode_comparison_columns( - layout: _BestModeComparisonLayout, -) -> tuple[str, str]: - """Expose a comparison's prefix and primary anchor as table columns.""" - - return layout.prefix, layout.primary - - -def _best_mode_summary_terminal_label( - joined: BestModeWorkload, -) -> _TerminalOutcome | _TerminalSummary | None: - if joined.mode is None: - return joined.terminal_label - if not _ok(joined.candidate): - return _terminal_measurement_label(joined.candidate) - return None - - -def _best_mode_lc_cell( - view: BestModeMatrixCell, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> _BestModeCellRows: - selected, all_flow = view.workloads - baseline_static_na = _legacy_baseline_static_na( - catalog=catalog, - accuracy=view.accuracy, - process_key=view.process_family.key, - n_final=view.n_final, - workload=selected.workload, - ) - selected_baseline_generation = ( - _static_na() - if baseline_static_na - else _original_amplicol_generation_metric( - selected, - candidate_mode=selected.mode, - ) - ) - all_flow_baseline_generation = ( - _static_na() - if baseline_static_na - else _original_amplicol_generation_metric( - all_flow, - candidate_mode=all_flow.mode, - ) - ) - selected_baseline_runtime = ( - _static_na() - if baseline_static_na - else _best_mode_metric( - selected.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ) - all_flow_baseline_runtime = ( - _static_na() - if baseline_static_na - else _best_mode_metric( - all_flow.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ) - selected_generation = _best_mode_generation_comparison_layout( - selected, - baseline_static_na=baseline_static_na, - ) - all_flow_generation = _best_mode_generation_comparison_layout( - all_flow, - baseline_static_na=baseline_static_na, - comparable=False, - ) - selected_runtime = _best_mode_runtime_comparison_layout( - selected, - baseline_static_na=baseline_static_na, - ) - all_flow_runtime = _best_mode_runtime_comparison_layout( - all_flow, - baseline_static_na=baseline_static_na, - ) - return _BestModeCellRows( - generation=( - selected_baseline_generation, - r"\matrixpunct{|}", - all_flow_baseline_generation, - *_best_mode_comparison_columns(selected_generation), - r"\matrixpunct{|}", - *_best_mode_comparison_columns(all_flow_generation), - ), - runtime=( - selected_baseline_runtime, - r"\matrixpunct{|}", - all_flow_baseline_runtime, - *_best_mode_comparison_columns(selected_runtime), - r"\matrixpunct{|}", - *_best_mode_comparison_columns(all_flow_runtime), - ), - ) - - -def _best_mode_contracted_cell( - view: BestModeMatrixCell, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> _BestModeCellRows: - joined = view.workloads[0] - baseline_static_na = _legacy_baseline_static_na( - catalog=catalog, - accuracy=view.accuracy, - process_key=view.process_family.key, - n_final=view.n_final, - workload=joined.workload, - ) - baseline_generation = ( - _static_na() - if baseline_static_na - else _original_amplicol_generation_metric( - joined, - candidate_mode=joined.mode, - ) - ) - baseline_runtime = ( - _static_na() - if baseline_static_na - else _best_mode_metric( - joined.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ) - generation_comparison = _best_mode_generation_comparison_layout( - joined, - baseline_static_na=baseline_static_na, - ) - runtime_comparison = _best_mode_runtime_comparison_layout( - joined, - baseline_static_na=baseline_static_na, - ) - return _BestModeCellRows( - generation=( - baseline_generation, - *_best_mode_comparison_columns(generation_comparison), - ), - runtime=( - baseline_runtime, - *_best_mode_comparison_columns(runtime_comparison), - ), - ) - - -def _best_mode_summary_pair( - views: Sequence[BestModeMatrixCell], - workload: Workload, - field: str, -) -> str: - joined, valid = _best_mode_summary_items(views, workload, field) - if not valid: - if field == "execution_seconds_per_point" and any( - unavailable_execution_timing_record(measurement, field) is not None - for item in joined - for measurement in (item.baseline, item.candidate) - ): - return _not_exposed() - terminal_label = _canonical_best_mode_terminal_label( - tuple(_best_mode_summary_terminal_label(item) for item in joined) - ) - if terminal_label is not None: - display_label = _compact_terminal_summary_display(terminal_label) - return ( - rf"\matrixstatus{{{terminal_label.color}}}" - rf"{{{_tex_escape(display_label)}}}" - ) - return r"\matrixna{ReportMuted}" - timings: list[tuple[float, float]] = [] - for item in valid: - candidate_value = _best_mode_summary_candidate_value(item, field) - assert candidate_value is not None - timings.append((float(item.baseline[field]), candidate_value)) - return _ratio_statistics_tex(tuple(timings)) - - -def _best_mode_summary_candidate_value( - item: BestModeWorkload, - field: str, -) -> float | None: - """Return the candidate value represented by a best-table primary token.""" - - if field == "generation_seconds" and item.mode is ExecutionMode.ON_THE_FLY: - generation = _positive_timing_value(item.candidate, field) - cold_warmup = _otf_cold_warmup_seconds(item.candidate) - if generation is None or cold_warmup is None: - return None - total = generation + cold_warmup - return total if math.isfinite(total) else None - value = item.candidate.get(field) - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - number = float(value) - return number if math.isfinite(number) and number >= 0.0 else None - - -def _best_mode_summary_items( - views: Sequence[BestModeMatrixCell], - workload: Workload, - field: str, -) -> tuple[tuple[BestModeWorkload, ...], tuple[BestModeWorkload, ...]]: - """Return joined and ratio-eligible workloads for one summary metric.""" - - joined = tuple( - next(item for item in view.workloads if item.workload is workload) - for view in views - if view.applicable - ) - valid = tuple( - item - for item in joined - if ( - _generation_comparison_linked(item) - if field == "generation_seconds" - else item.comparison_linked - ) - and item.mode is not None - and _ok(item.baseline) - and _ok(item.candidate) - and item.baseline.get(field) is not None - and _best_mode_summary_candidate_value(item, field) is not None - and unavailable_execution_timing_record(item.baseline, field) is None - and unavailable_execution_timing_record(item.candidate, field) is None - and math.isfinite(float(item.baseline[field])) - and float(item.baseline[field]) > 0.0 - ) - return joined, valid - - -def _best_mode_generation_mode_mix( - views: Sequence[BestModeMatrixCell], - accuracy: Accuracy, -) -> str: - workload = ( - Workload.SELECTED_FLOW if accuracy is Accuracy.LC else Workload.CONTRACTED - ) - _joined, valid = _best_mode_summary_items( - views, - workload, - "generation_seconds", - ) - if not valid: - return "" - displayed_modes = _BEST_MODE_ORDER - counts = { - mode: sum(item.mode is mode for item in valid) for mode in displayed_modes - } - return ( - r"\bestmodemix{" - + "|".join( - f"{_BEST_MODE_CODES[mode]}:{counts[mode]}" for mode in displayed_modes - ) - + "}" - ) - - -def _best_mode_generation_summary( - views: Sequence[BestModeMatrixCell], - accuracy: Accuracy, -) -> str: - if accuracy is Accuracy.LC: - return _best_mode_summary_pair( - views, - Workload.SELECTED_FLOW, - "generation_seconds", - ) - return _best_mode_summary_pair( - views, - Workload.CONTRACTED, - "generation_seconds", - ) - - -def _best_mode_wall_summary( - views: Sequence[BestModeMatrixCell], - accuracy: Accuracy, -) -> str: - if accuracy is Accuracy.LC: - selected = _best_mode_summary_pair( - views, - Workload.SELECTED_FLOW, - "wall_seconds_per_point", - ) - all_flow = _best_mode_summary_pair( - views, - Workload.ALL_FLOW, - "wall_seconds_per_point", - ) - return rf"\matrixsummaryworkloads{{{selected}}}{{{all_flow}}}" - return _best_mode_summary_pair( - views, - Workload.CONTRACTED, - "wall_seconds_per_point", - ) - - -def _best_mode_block( - adapter: BaselineCandidateAdapter, - accuracy: Accuracy, - multiplicities: tuple[int, ...], - *, - block_index: int, - block_count: int, -) -> list[str]: - accuracy_label = { - Accuracy.LC: "LC", - Accuracy.NLC: "NLC", - Accuracy.FULL: "full-colour", - }[accuracy] - if len(multiplicities) not in (2, 3): - raise ValueError("matrix blocks must contain two or three multiplicities") - column_spec = _metric_table_column_spec( - accuracy, - len(multiplicities), - ) - lines = [ - r"\clearpage", - r"\noindent\begin{minipage}{\linewidth}", - ( - rf"\subsubsection*{{Built-in SM best measured mode versus AmpliCol " - rf"{accuracy_label}" - + ( - "" - if block_count == 1 - else rf" (block {block_index + 1} of {block_count})" - ) - + "}" - ), - r"\begingroup", - r"\centering", - r"\footnotesize", - r"\setlength{\tabcolsep}{2.1pt}", - r"\renewcommand{\arraystretch}{1.00}", - r"\matrixfitwidth{%", - rf"\begin{{tabular}}{{{column_spec}}}", - r"\toprule", - ( - r"\textbf{ID} & \textbf{base process} & \textbf{metric} & " - + " & ".join( - _metric_group_cell( - rf"\textbf{{n={n_final}}}", - accuracy, - ) - for n_final in multiplicities - ) - + r" \\" - ), - r"\specialrule{0.85pt}{0pt}{0pt}", - ] - views_by_n: dict[int, list[BestModeMatrixCell]] = { - n_final: [] for n_final in multiplicities - } - for row_index, family in enumerate(adapter.catalog.process_families): - generation_row = [ - rf"\texttt{{{family.identifier}}}", - family.label_tex, - _metric_row_label(runtime=False), - ] - runtime_row = ["", "", _metric_row_label(runtime=True)] - for n_final in multiplicities: - view = adapter.best_mode_cell(accuracy, family, n_final) - views_by_n[n_final].append(view) - if not view.applicable: - generation_row.append( - _metric_group_cell( - _matrix_scope_marker(family, n_final, accuracy), - accuracy, - ) - ) - runtime_row.append( - _metric_group_cell( - "", - accuracy, - ) - ) - elif accuracy is Accuracy.LC: - rendered = _best_mode_lc_cell( - view, - catalog=adapter.catalog, - ) - generation_row.extend(rendered.generation) - runtime_row.extend(rendered.runtime) - else: - rendered = _best_mode_contracted_cell( - view, - catalog=adapter.catalog, - ) - generation_row.extend(rendered.generation) - runtime_row.extend(rendered.runtime) - if row_index % 2 == 0: - lines.append(r"\rowcolor{refblue}") - lines.append(" & ".join(generation_row) + r" \\") - if row_index % 2 == 0: - lines.append(r"\rowcolor{refblue}") - lines.append(" & ".join(runtime_row) + r" \\") - lines.append(r"\addlinespace[0.05em]") - boundary_note = ( - r" For the LC all-flow workload, AmpliCol direct-evaluation setup and " - r"pyAmpliCol process generation have different boundaries, so the " - r"candidate generation value is shown absolutely; no " - r"misleading multiplier is formed." - if accuracy is Accuracy.LC - else "" - ) - otf_generation_note = ( - r" OTF \texttt{([xG]x(G+W)) | [G]G+W} follows the enclosing " - r"cold-start contract." - if accuracy is Accuracy.LC - else ( - r" OTF \texttt{([xG]x(G+W))} follows the enclosing " - r"contracted cold-start contract." - ) - ) - mode_legend_note = ( - r" Muted generation-row codes (r)|(c)|(e)|(o) identify " - r"recurrence JIT O2, compiled JIT O3, eager-DAG JIT O2, and " - r"on-the-fly JIT O2 wall-time winners; runtime rows omit them. " - r"Summary mode counts use r|c|e|o in the same order." - ) - lines.extend( - [ - r"\specialrule{1.05pt}{0.22em}{0.18em}", - _metric_summary_header_row( - multiplicities, - accuracy, - annotations=tuple( - _best_mode_generation_mode_mix( - views_by_n[n_final], - accuracy, - ) - for n_final in multiplicities - ), - ), - ( - r"\multicolumn{3}{@{}l}{\textbf{summary: generation}} & " - + " & ".join( - _metric_summary_group_cell( - _best_mode_generation_summary( - views_by_n[n_final], - accuracy, - ), - accuracy, - group_index=group_index, - ) - for group_index, n_final in enumerate(multiplicities) - ) - + r" \\[0.08em]" - ), - ( - rf"\multicolumn{{3}}{{@{{}}l}}{{" - rf"{_matrix_wall_summary_label(accuracy)}}} & " - + " & ".join( - _metric_summary_group_cell( - _best_mode_wall_summary( - views_by_n[n_final], - accuracy, - ), - accuracy, - group_index=group_index, - ) - for group_index, n_final in enumerate(multiplicities) - ) - + r" \\" - ), - r"\bottomrule", - r"\end{tabular}", - r"}", - r"\endgroup", - ( - r"\ReportTableNote{{\scriptsize The candidate is selected " - r"independently in " - r"each cell and workload by the smallest validated wall time. " - r"The upper row is generation in seconds and the lower row is " - r"runtime in \(\mu\mathrm{s}/\mathrm{pt}\). In LC cells, each " - r"pair is non-union-flow \texttt{|} union-flow. Generation " - r"multipliers are coloured directly. Each runtime workload " - r"uses \texttt{([xS]xW)}. The muted supplementary xS first " - r"compares compatible exposed execution attributions; otherwise " - r"it uses authenticated evaluator totals. Because original " - r"AmpliCol exposes no evaluator-total clock, a candidate total " - r"then uses the AmpliCol direct execution clock, or its wall " - r"clock when direct execution is absent, as denominator. An " - r"evaluator total is " - r"never divided by a recurrence core. This evaluator-total " - r"fallback is diagnostic only; execution/execution remains the " - r"compatible supplementary attribution. The coloured xW is always " - r"the candidate/AmpliCol wall-time multiplier used for selection " - r"and as the primary figure of merit. If no compatible " - r"supplementary clock exists, only \texttt{(xW)} is shown. No " - r"clock is fabricated from another. Every " - r"displayed number uses exactly three significant digits. " - r"Original-AmpliCol " - r"rows beyond its three-open-quark-line scope are catalog " - r"static N/A entries; their candidates are shown absolutely and " - r"excluded from ratio summaries. Unavailable baselines keep " - r"their status; candidates remain absolute. Unverified " - r"compiled, eager, or on-the-fly diagnostics are never eligible " - r"for best-mode selection or summaries and remain visibly marked " - r"unverified." - + boundary_note - + otf_generation_note - + r" Only exact stored same-point links enter ratios." - + r" Summary rows contain multipliers only in min, max, " - r"median, average, and weighted-average order; the weighted " - r"average is the ratio of timing sums and is the framed bold " - r"entry. " - r"LC generation is non-union only; LC runtime retains separate " - r"non-union and union wall-only lines." - + mode_legend_note - + r"}}" - ), - r"\end{minipage}", - ] - ) - return lines - - -def render_best_mode_table( - accuracy: Accuracy, - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> str: - """Render the fastest valid built-in mode against AmpliCol.""" - - adapter = BaselineCandidateAdapter(caches, catalog=catalog) - multiplicities = matrix_multiplicities(accuracy) - blocks = _chunks(multiplicities, _MATRIX_BLOCK_SIZE) - accuracy_label = { - Accuracy.LC: "LC", - Accuracy.NLC: "NLC", - Accuracy.FULL: "full-colour", - }[accuracy] - lines = [ - "% SPDX-License-Identifier: 0BSD", - "% Generated by tools/performance_report/render.py; do not edit.", - *_matrix_macros(), - ( - r"\providecommand{\matrixpair}[2]{" - r"\begin{tabular}[t]{@{}r@{\hspace{0.025in}" - r"\matrixpunct{|}\hspace{0.025in}}r@{}}" - r"#1\end{tabular}}" - ), - *_compact_comparison_macros(), - ( - r"\providecommand{\bestmodecode}[1]{" - r"\textcolor{ReportMuted}{\texttt{(#1)}}}" - ), - ( - r"\providecommand{\bestmodecodeprefix}[1]{" - r"\bestmodecode{#1}\hspace{0.025in}}" - ), - ( - r"\providecommand{\bestmodeabsolutechoice}[2]{" - r"#1\hspace{0.025in}\bestmodecode{#2}}" - ), - ( - r"\providecommand{\bestmodemix}[1]{" - r"\textcolor{ReportBlue}{\texttt{[#1]}}}" - ), - r"\clearpage", - ( - r"\subsection{Built-in SM best measured mode versus AmpliCol: " - f"{accuracy_label}}}" - ), - ] - for block_index, block in enumerate(blocks): - rendered = _best_mode_block( - adapter, - accuracy, - block, - block_index=block_index, - block_count=len(blocks), - ) - lines.extend(rendered[1:] if block_index == 0 else rendered) - return "\n".join(lines) + "\n" - - -def render_all_best_mode_tables( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, str]: - cache_source = caches if isinstance(caches, Mapping) else tuple(caches) - return { - _BEST_MODE_TABLE_NAMES[accuracy]: render_best_mode_table( - accuracy, - cache_source, - catalog=catalog, - ) - for accuracy in Accuracy - } - - -def _z_setup(variant: ZVariant) -> str: - labels = { - "reference": r"\AC{} reference", - "jit_o1": r"compiled JIT O1", - "asm_o3": r"compiled ASM O3", - "cpp_o3": r"compiled C++ O3", - "jit_o3": r"compiled JIT O3", - "eager_jit_o2": r"eager-DAG JIT O2", - "recurrence_jit_o2": r"recurrence JIT O2", - "on_the_fly_jit_o2": r"on-the-fly JIT O2", - } - return labels.get(variant.key, _tex_escape(variant.label)) - - -def _z_value( - joined: JoinedWorkload, - field: str, - *, - reference: bool, - microseconds: bool = False, - comparable: bool = True, - static_na: bool = False, -) -> str: - if static_na: - return _static_na() - measurement = joined.baseline if reference else joined.candidate - if ( - not reference - and measurement.get("status") == ResultStatus.UNVERIFIED.value - ): - return _unverified_absolute_time( - measurement, - field, - microseconds=microseconds, - ) - absolute = _metric(measurement, field, microseconds=microseconds) - if reference or not _ok(measurement): - return absolute - if ( - unavailable_execution_timing_record(measurement, field) is not None - or unavailable_execution_timing_record(joined.baseline, field) is not None - ): - if evaluator_total_timing_record(measurement) is not None: - return absolute - return _not_exposed() - if not comparable or not joined.comparison_linked or not _ok(joined.baseline): - return rf"\matrixncabsolute{{{absolute}}}" - return absolute + r"\," + _ratio(measurement, joined.baseline, field) - - -def _z_generation_value( - joined: JoinedWorkload, - variant: ZVariant, - *, - reference: bool, - comparable: bool = True, - static_na: bool = False, -) -> str: - """Render one Z-ladder generation cell without hiding OTF cold start.""" - - if ( - not reference - and variant.execution_mode is ExecutionMode.ON_THE_FLY - and not static_na - and _ok(joined.candidate) - ): - return _otf_generation_pair_layout(joined.candidate, None).inline - return _z_value( - joined, - "generation_seconds", - reference=reference, - comparable=comparable, - static_na=static_na, - ) - - -def _z_evaluator_total( - joined: JoinedWorkload, - *, - reference: bool, - static_na: bool = False, -) -> str: - if static_na: - return _static_na() - measurement = joined.baseline if reference else joined.candidate - if reference: - return _not_exposed() - if measurement.get("status") == ResultStatus.UNVERIFIED.value: - return _unverified_evaluator_total(measurement) - if not _ok(measurement): - return _status(measurement) - total = evaluator_total_seconds_per_point(measurement) - if total is None: - return _not_exposed() - absolute = _time(total, microseconds=True) - if not joined.comparison_linked or not _ok(joined.baseline): - return rf"\matrixncabsolute{{{absolute}}}" - baseline_wall = joined.baseline.get("wall_seconds_per_point") - if ( - isinstance(baseline_wall, bool) - or not isinstance(baseline_wall, (int, float)) - or not math.isfinite(float(baseline_wall)) - or float(baseline_wall) <= 0.0 - ): - return absolute + r"\," + r"\matrixnaratio{ReportMuted}" - ratio = total / float(baseline_wall) - return ( - absolute - + r"\," - + rf"\matrixratio{{{_best_mode_ratio_color(ratio)}}}" - + rf"{{{_compact(ratio)}}}" - ) - - -def _z_block( - adapter: BaselineCandidateAdapter, - *, - model: ModelKey, - multiplicities: tuple[int, ...], - block_index: int, - block_count: int, -) -> list[str]: - model_label = "Built-in SM" if model is ModelKey.BUILTIN_SM else "UFO-SM" - candidate_cells = { - (cell.n_final, cell.variant, cell.workload): cell - for cell in adapter.catalog.z_cells() - if cell.dataset_id == z_dataset_id(model) - } - lines = [ - r"\clearpage", - r"\noindent\begin{minipage}{\linewidth}", - ( - rf"\subsubsection*{{{model_label} \(d\bar d\to Z+\) gluon ladder" - + ( - "" - if block_count == 1 - else rf" (block {block_index + 1} of {block_count})" - ) - + "}" - ), - r"\begingroup", - r"\centering", - r"\scriptsize", - r"\setlength{\tabcolsep}{1.4pt}", - r"\renewcommand{\arraystretch}{1.05}", - ( - r"\begin{tabular}{@{}r L{1.50in} " - r"R{1.26in} R{1.26in} R{1.26in} " - r"@{\hspace{0.08in}}" - r"R{1.26in} R{1.26in} R{1.26in}@{}}" - ), - r"\toprule", - ( - r"\textbf{n} & \textbf{setup} & " - r"\multicolumn{3}{c}{\textbf{selected flow, helicity sum}} & " - r"\multicolumn{3}{c}{\textbf{all flows, single helicity}} \\" - ), - ( - r"& & \textbf{gen [s]} & " - r"\textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & " - r"\textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} & " - r"\textbf{gen [s]} & " - r"\textbf{wall [\(\mu\mathrm{s}/\mathrm{pt}\)]} & " - r"\textbf{eval [\(\mu\mathrm{s}/\mathrm{pt}\)]} \\" - ), - r"\midrule", - ] - for n_final in multiplicities: - for variant in adapter.catalog.z_variants: - selected = adapter.z_workload( - model=model, - n_final=n_final, - variant=variant, - workload=Workload.SELECTED_FLOW, - ) - all_flow = adapter.z_workload( - model=model, - n_final=n_final, - variant=variant, - workload=Workload.ALL_FLOW, - ) - reference = variant.execution_mode is ExecutionMode.AMPLICOL - selected_static_na = False - all_flow_static_na = False - if not reference: - selected_cell = candidate_cells[ - (n_final, variant.key, Workload.SELECTED_FLOW) - ] - all_flow_cell = candidate_cells[ - (n_final, variant.key, Workload.ALL_FLOW) - ] - selected_static_na = ( - adapter.catalog.static_na_reason(selected_cell) is not None - ) - all_flow_static_na = ( - adapter.catalog.static_na_reason(all_flow_cell) is not None - ) - if reference: - lines.append(r"\rowcolor{refblue}") - elif variant.key in { - "jit_o3", - "eager_jit_o2", - "recurrence_jit_o2", - "on_the_fly_jit_o2", - }: - lines.append(r"\rowcolor{ReportGreen!12}") - row = ( - str(n_final), - _z_setup(variant), - _z_generation_value( - selected, - variant, - reference=reference, - static_na=selected_static_na, - ), - _z_value( - selected, - "wall_seconds_per_point", - reference=reference, - microseconds=True, - static_na=selected_static_na, - ), - _z_evaluator_total( - selected, - reference=reference, - static_na=selected_static_na, - ), - _z_generation_value( - all_flow, - variant, - reference=reference, - comparable=False, - static_na=all_flow_static_na, - ), - _z_value( - all_flow, - "wall_seconds_per_point", - reference=reference, - microseconds=True, - static_na=all_flow_static_na, - ), - _z_evaluator_total( - all_flow, - reference=reference, - static_na=all_flow_static_na, - ), - ) - lines.append(" & ".join(row) + r" \\") - if n_final != multiplicities[-1]: - lines.append(r"\midrule[0.45pt]") - lines.extend( - [ - r"\bottomrule", - r"\end{tabular}", - r"\endgroup", - ( - r"\ReportTableNote{Original AmpliCol is the denominator only " - r"when successful and exactly linked by stored same-point " - r"evidence, directly or through current recurrence. Otherwise " - r"its status remains visible and successful pyAmpliCol values " - r"are absolute. Unverified diagnostics retain absolute clocks " - r"with a yellow marker, but never enter ratios or summaries. " - r"Compiled, eager, and recurrence rows report separate " - r"topology-replay and all-flow-union generation and runtime " - r"measurements. On-the-fly uses one compact query-local " - r"process seed for both physical workloads. Its generation " - r"entry is the absolute \texttt{[G] G+W} pair: muted G is " - r"process-seed generation and G+W adds the first cold " - r"on-the-fly evaluation. " - r"Parenthesized values are candidate/reference ratios. " - r"All-flow generation shows the absolute pyAmpliCol value " - r"without a ratio because its setup boundary differs from the " - r"reference. The wall time is the common runtime observable. " - r"Not exposed means that a successful wall measurement has no " - r"dedicated authenticated evaluator-total timing. Authenticated " - r"accumulated warmed evaluator totals appear in the eval column " - r"with enough precision to remain distinct from wall time. Its " - r"parenthesized multiplier uses the original-AmpliCol wall " - r"measurement as denominator because the legacy reference has " - r"no separate evaluator-total clock. Recurrence rows retain the " - r"independently measured narrower recurrence core in detailed " - r"evidence; it is not relabeled as evaluator total. Neither " - r"evaluator total nor recurrence core is derived from wall " - r"time or from the other. Older entries " - r"without authenticated total evidence remain marked not " - r"exposed; it is not a missing measurement. " - + _tex_escape(STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6_DESCRIPTION) - + " (" - + _tex_escape(STATIC_NA_NATIVE_BACKEND_GENERATION_CAP_N6) - + r").}" - ), - r"\end{minipage}", - ] - ) - return lines - - -def render_z_ladder( - model: ModelKey, - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> str: - if model not in {ModelKey.BUILTIN_SM, ModelKey.UFO_SM}: - raise ValueError("Z ladder model must be built-in SM or UFO-SM") - adapter = BaselineCandidateAdapter(caches, catalog=catalog) - model_label = "Built-in SM" if model is ModelKey.BUILTIN_SM else "UFO-SM" - blocks = _chunks(tuple(range(1, 10)), _Z_BLOCK_SIZE) - lines = [ - "% SPDX-License-Identifier: 0BSD", - "% Generated by tools/performance_report/render.py; do not edit.", - *_matrix_macros(), - r"\clearpage", - rf"\subsection{{{model_label} dedicated \(d\bar d\to Z+\) gluon performance}}", - ] - for block_index, multiplicities in enumerate(blocks): - block = _z_block( - adapter, - model=model, - multiplicities=multiplicities, - block_index=block_index, - block_count=len(blocks), - ) - lines.extend(block[1:] if block_index == 0 else block) - return "\n".join(lines) + "\n" - - -def render_all_z_ladders( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, str]: - cache_source = caches if isinstance(caches, Mapping) else tuple(caches) - return { - "result_z_builtin_sm_table.tex": render_z_ladder( - ModelKey.BUILTIN_SM, - cache_source, - catalog=catalog, - ), - "result_z_external_sm_table.tex": render_z_ladder( - ModelKey.UFO_SM, - cache_source, - catalog=catalog, - ), - } - - -def _scalar_value(measurement: Measurement, field: str) -> str: - if field == "evaluator_total_seconds_per_point": - if measurement.get("status") == ResultStatus.UNVERIFIED.value: - return _unverified_evaluator_total(measurement) - if not _ok(measurement): - return _status(measurement) - total = evaluator_total_seconds_per_point(measurement) - if total is None: - return _not_exposed() - return _time(total, microseconds=True) - if field == "matrix_element": - if not _ok(measurement): - return _status(measurement) - value = measurement.get(field) - if value is None: - return r"\matrixna{ReportMuted}" - try: - return rf"\texttt{{{_compact(float(value))}}}" - except (TypeError, ValueError): - return rf"\texttt{{{_tex_escape(str(value))}}}" - if measurement.get("status") == ResultStatus.UNVERIFIED.value: - return _unverified_absolute_time( - measurement, - field, - microseconds=field - in {"wall_seconds_per_point", "execution_seconds_per_point"}, - ) - return _metric( - measurement, - field, - microseconds=field in {"wall_seconds_per_point", "execution_seconds_per_point"}, - ) - - -def _scalar_relative_difference(measurement: Measurement) -> str: - if not _ok(measurement): - return _status(measurement) - validation = measurement.get("validation") - if not isinstance(validation, Mapping): - return r"\matrixna{ReportMuted}" - high_precision = validation.get("high_precision") - if not isinstance(high_precision, Mapping): - return r"\matrixna{ReportMuted}" - value = high_precision.get("relative_difference") - if value is None: - return r"\matrixna{ReportMuted}" - return rf"\texttt{{{_compact(float(value))}}}" - - -def render_scalar_ladder( - dataset: ScalarDataset, - caches: Mapping[str, CachePayload] | Iterable[CachePayload], -) -> str: - index = MeasurementIndex(caches) - dense = len(dataset.multiplicities) > 4 - label_width = "1.00in" if dense else "1.08in" - value_width = "0.72in" if dense else "0.82in" - tab_column_separation = "2.2pt" if dense else "3.2pt" - column_spec = ( - rf"@{{}}L{{{label_width}}}" - + "".join(rf"L{{{value_width}}}" for _ in dataset.multiplicities) - + r"@{}" - ) - rows = ( - ("generation [s]", "generation_seconds"), - (r"wall [\(\mu\mathrm{s}/\mathrm{pt}\)]", "wall_seconds_per_point"), - ( - r"{\fontsize{6.4pt}{7.4pt}\selectfont" - r"\mbox{evaluator total [\(\mu\mathrm{s}/\mathrm{pt}\)]}}", - "evaluator_total_seconds_per_point", - ), - ("matrix element", "matrix_element"), - ) - lines = [ - "% SPDX-License-Identifier: 0BSD", - "% Generated by tools/performance_report/render.py; do not edit.", - *_matrix_macros(), - rf"\subsection{{{_tex_escape(dataset.title)}}}", - r"\begingroup", - r"\scriptsize", - rf"\setlength{{\tabcolsep}}{{{tab_column_separation}}}", - r"\renewcommand{\arraystretch}{1.10}", - r"\begin{center}", - rf"\begin{{tabular}}{{{column_spec}}}", - r"\toprule", - ( - rf"\multicolumn{{{len(dataset.multiplicities) + 1}}}{{c}}" - rf"{{\texttt{{{_tex_escape(dataset.process_template)}}}}} \\" - ), - ( - r"\textbf{metric} & " - + " & ".join( - rf"\textbf{{\texttt{{n={n_final}}}}}" - for n_final in dataset.multiplicities - ) - + r" \\" - ), - r"\midrule", - ] - for row_index, (label, field) in enumerate(rows): - if row_index % 2 == 0: - lines.append(r"\rowcolor{refblue}") - values = [ - _scalar_value( - index.get( - dataset.dataset_id, - dataset.dataset_id, - n_final, - Workload.CONTRACTED, - ), - field, - ) - for n_final in dataset.multiplicities - ] - lines.append(label + " & " + " & ".join(values) + r" \\") - relative_values = [ - _scalar_relative_difference( - index.get( - dataset.dataset_id, - dataset.dataset_id, - n_final, - Workload.CONTRACTED, - ) - ) - for n_final in dataset.multiplicities - ] - lines.extend( - [ - r"\rowcolor{ReportOrange!8}", - "relative diff. vs hp & " + " & ".join(relative_values) + r" \\", - r"\bottomrule", - r"\end{tabular}", - r"\end{center}", - r"\endgroup", - ( - r"\ReportTableNote{Wall time is the common runtime observable. " - r"Evaluator total is the independently measured accumulated " - r"warmed evaluator clock from its dedicated authenticated " - r"record; it is never copied from or derived from wall time. " - r"Unverified diagnostics retain absolute generation, wall, and " - r"evaluator clocks with a yellow marker; they are not successes. " - r"\textsc{not exposed} denotes a successful wall measurement, " - r"and older entries without dedicated evaluator-total evidence " - r"remain valid; it does not denote a missing result.}" - ), - ] - ) - return "\n".join(lines) + "\n" - - -def render_all_scalar_ladders( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, str]: - cache_source = caches if isinstance(caches, Mapping) else tuple(caches) - return { - dataset.table_name: render_scalar_ladder(dataset, cache_source) - for dataset in catalog.scalar_datasets - } - - -def _renders_na(value: str) -> bool: - return r"\matrixna{" in value or r"\matrixnaratio{" in value or "{N/A}" in value - - -def _measurements_by_cell_id( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], -) -> dict[str, Measurement]: - payloads = caches.values() if isinstance(caches, Mapping) else caches - measurements: dict[str, Measurement] = {} - for payload in payloads: - entries = payload.get("entries") - if not isinstance(entries, list): - raise ValueError("report cache has no entries list") - for entry in entries: - if not isinstance(entry, Mapping): - raise ValueError("report cache contains a non-object entry") - cell_id = entry.get("cell_id") - measurement = entry.get("measurement") - if not isinstance(cell_id, str) or not isinstance(measurement, Mapping): - raise ValueError("report cache entry is missing its measurement") - if cell_id in measurements: - raise ValueError(f"duplicate report cell {cell_id!r}") - measurements[cell_id] = measurement - return measurements - - -def summarize_visible_completeness( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, - max_n_final: int = 9, - policy: CampaignPolicy = STRICT_POLICY, -) -> VisibleCompleteness: - """Audit every logical table slot that represents a required measurement. - - The check invokes the same field-level rendering helpers as the tables. It - therefore catches an ``ok`` cache record whose missing submetric would still - appear as ``N/A`` in TeX, as well as an applicable reset record. Structural - matrix positions and reference-only execution fields are counted separately - and are required to use their dedicated visible markers. - """ - - if max_n_final < 1: - raise ValueError("max_n_final must be positive") - cache_source = caches if isinstance(caches, Mapping) else tuple(caches) - measurements = _measurements_by_cell_id(cache_source) - declared_cells = tuple( - cell for cell in catalog.measurement_cells() if cell.n_final <= max_n_final - ) - static_na_cells = tuple( - cell for cell in declared_cells if catalog.static_na_reason(cell) is not None - ) - required_cells = tuple( - cell for cell in declared_cells if catalog.static_na_reason(cell) is None - ) - required_by_id = {cell.cell_id: cell for cell in required_cells} - if len(required_by_id) != len(required_cells): - raise ValueError("report catalog contains duplicate required cell IDs") - cell_index = { - ( - cell.dataset_id, - cell.process_key, - cell.n_final, - cell.workload, - cell.variant, - ): cell - for cell in catalog.measurement_cells() - } - rendered_cell_ids: set[str] = set() - rendered_static_na_cell_ids: set[str] = set() - na_slots: list[str] = [] - contract_errors: list[str] = [] - for cell in required_cells: - measurement = measurements.get(cell.cell_id, _NA) - status = measurement.get("status", ResultStatus.NOT_AVAILABLE.value) - policy_terminal = ( - policy.allow_terminal_censors - and policy_status_label(measurement) is not None - ) - if status != ResultStatus.OK.value and not policy_terminal: - contract_errors.append( - f"{cell.cell_id}: required measurement status is " - f"{status!r}, expected {ResultStatus.OK.value!r}" - ) - for cell in static_na_cells: - measurement = measurements.get(cell.cell_id) - if measurement != _NA: - contract_errors.append( - f"{cell.cell_id}: catalog static N/A measurement differs " - "from the canonical reset record" - ) - - def inspect( - location: str, - fragments: Sequence[str], - ) -> None: - for index, fragment in enumerate(fragments): - if _renders_na(fragment): - na_slots.append(f"{location}[{index}]") - - def record( - cell: CellSpec, - location: str, - fragments: Sequence[str], - ) -> None: - if cell.n_final > max_n_final: - return - rendered_cell_ids.add(cell.cell_id) - if catalog.static_na_reason(cell) is not None: - rendered_static_na_cell_ids.add(cell.cell_id) - if any(fragment != _static_na() for fragment in fragments): - contract_errors.append( - f"{location} ({cell.cell_id}): catalog static N/A slot " - "does not use the dedicated marker" - ) - return - inspect( - f"{location} ({cell.cell_id})", - fragments, - ) - - def locate( - dataset_id: str, - process_key: str | None, - n_final: int, - workload: Workload, - variant: str | None = None, - ) -> CellSpec | None: - cell = cell_index.get((dataset_id, process_key, n_final, workload, variant)) - if cell is None: - contract_errors.append( - f"renderer has no catalog cell for {dataset_id}/n{n_final}/" - f"{process_key}/{variant}/{workload.value}" - ) - return cell - - adapter = BaselineCandidateAdapter(cache_source, catalog=catalog) - structural_seen = 0 - matrix_datasets = getattr(catalog, "matrix_datasets", ()) - process_families = getattr(catalog, "process_families", ()) - for dataset in matrix_datasets: - views_by_n: dict[int, list[JoinedMatrixCell]] = {} - for family in process_families: - for n_final in dataset.multiplicities: - if n_final > max_n_final: - continue - view = adapter.matrix_cell(dataset, family, n_final) - views_by_n.setdefault(n_final, []).append(view) - if not view.applicable: - structural_seen += 1 - marker = _matrix_scope_marker( - family, - n_final, - dataset.candidate.accuracy, - ) - if _renders_na(marker): - contract_errors.append( - f"{dataset.table_name}/n{n_final}/{family.key}: " - "out-of-scope slot uses the missing-measurement marker" - ) - continue - for joined in view.workloads: - candidate = locate( - dataset.dataset_id, - family.key, - n_final, - joined.workload, - ) - if candidate is None: - continue - baseline = catalog.baseline_cell(candidate) - if baseline is None: - contract_errors.append( - f"{candidate.cell_id}: matrix baseline is missing" - ) - continue - baseline_static_na = catalog.static_na_reason(baseline) is not None - candidate_static_na = ( - catalog.static_na_reason(candidate) is not None - ) - record( - baseline, - ( - f"{dataset.table_name}/n{n_final}/{family.key}/" - f"{joined.workload.value}/baseline" - ), - ( - ( - _static_na() - if baseline_static_na - else _best_mode_metric( - joined.baseline, - "generation_seconds", - ) - ), - ( - _static_na() - if baseline_static_na - else _best_mode_metric( - joined.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ), - ), - ) - candidate_generation = _fixed_mode_generation_comparison_layout( - joined, - candidate_mode=dataset.candidate.execution_mode, - baseline_mode=dataset.baseline.execution_mode, - baseline_static_na=baseline_static_na, - comparable=not ( - joined.workload is Workload.ALL_FLOW - and dataset.candidate.execution_mode - is ExecutionMode.RECURRENCE - and dataset.baseline.execution_mode - is ExecutionMode.AMPLICOL - ), - ) - record( - candidate, - ( - f"{dataset.table_name}/n{n_final}/{family.key}/" - f"{joined.workload.value}/candidate" - ), - ( - ( - _static_na() - if candidate_static_na - else candidate_generation.inline - ), - ( - _static_na() - if candidate_static_na - else _fixed_mode_runtime_comparison_layout( - joined, - candidate_mode=( - dataset.candidate.execution_mode - ), - baseline_mode=( - dataset.baseline.execution_mode - ), - baseline_static_na=baseline_static_na, - ).inline - ), - ), - ) - for n_final, views in views_by_n.items(): - if not any(view.applicable for view in views): - continue - for label, fragment in ( - ( - "generation-summary", - _matrix_generation_summary(views, dataset, catalog=catalog), - ), - ( - "wall-summary", - _matrix_wall_summary( - views, - dataset.candidate.accuracy, - dataset=dataset, - catalog=catalog, - ), - ), - ): - if _renders_na(fragment): - na_slots.append(f"{dataset.table_name}/n{n_final}/{label}") - - for accuracy in Accuracy: - table_name = _BEST_MODE_TABLE_NAMES[accuracy] - multiplicities = matrix_multiplicities(accuracy) - views_by_n: dict[int, list[BestModeMatrixCell]] = {} - for family in process_families: - for n_final in multiplicities: - if n_final > max_n_final: - continue - view = adapter.best_mode_cell(accuracy, family, n_final) - views_by_n.setdefault(n_final, []).append(view) - if not view.applicable: - continue - for joined in view.workloads: - baseline_static_na = _legacy_baseline_static_na( - catalog=catalog, - accuracy=accuracy, - process_key=family.key, - n_final=n_final, - workload=joined.workload, - ) - inspect( - ( - f"{table_name}/n{n_final}/{family.key}/" - f"{joined.workload.value}" - ), - ( - ( - _static_na() - if baseline_static_na - else _best_mode_metric( - joined.baseline, - "generation_seconds", - ) - ), - _best_mode_generation_comparison( - joined, - baseline_static_na=baseline_static_na, - comparable=not ( - accuracy is Accuracy.LC - and joined.workload is Workload.ALL_FLOW - ), - ), - ( - _static_na() - if baseline_static_na - else _best_mode_metric( - joined.baseline, - "wall_seconds_per_point", - microseconds=True, - ) - ), - _best_mode_runtime_comparison( - joined, - baseline_static_na=baseline_static_na, - ), - ), - ) - for n_final, views in views_by_n.items(): - if not any(view.applicable for view in views): - continue - inspect( - f"{table_name}/n{n_final}/best-mode-summaries", - ( - _best_mode_generation_summary(views, accuracy), - _best_mode_wall_summary(views, accuracy), - ), - ) - - not_exposed_seen = 0 - if getattr(catalog, "z_variants", ()): - for model in (ModelKey.BUILTIN_SM, ModelKey.UFO_SM): - if model not in getattr(catalog, "models", {}): - continue - for n_final in range(1, min(max_n_final, 9) + 1): - for variant in catalog.z_variants: - for workload in ( - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - ): - joined = adapter.z_workload( - model=model, - n_final=n_final, - variant=variant, - workload=workload, - ) - reference = variant.execution_mode is ExecutionMode.AMPLICOL - if reference: - cell = locate( - "reference_amplicol_lc", - "dd_z_jets", - n_final, - workload, - ) - if cell is None: - continue - fragments = ( - _z_value( - joined, - "generation_seconds", - reference=True, - comparable=workload is not Workload.ALL_FLOW, - ), - _z_value( - joined, - "wall_seconds_per_point", - reference=True, - microseconds=True, - ), - ) - not_exposed_seen += 1 - if _renders_na(_not_exposed()): - contract_errors.append( - "reference execution slot uses the " - "missing-measurement marker" - ) - else: - cell = locate( - z_dataset_id(model), - "dd_z_jets", - n_final, - workload, - variant.key, - ) - if cell is None: - continue - static_na = catalog.static_na_reason(cell) is not None - fragments = ( - _z_value( - joined, - "generation_seconds", - reference=False, - comparable=workload is not Workload.ALL_FLOW, - static_na=static_na, - ), - _z_value( - joined, - "wall_seconds_per_point", - reference=False, - microseconds=True, - static_na=static_na, - ), - _z_evaluator_total( - joined, - reference=False, - static_na=static_na, - ), - ) - record( - cell, - ( - f"result_z_{model.value}/n{n_final}/" - f"{variant.key}/{workload.value}" - ), - fragments, - ) - - for dataset in getattr(catalog, "scalar_datasets", ()): - for n_final in dataset.multiplicities: - if n_final > max_n_final: - continue - cell = locate( - dataset.dataset_id, - dataset.dataset_id, - n_final, - Workload.CONTRACTED, - ) - if cell is None: - continue - measurement = measurements.get(cell.cell_id, _NA) - record( - cell, - f"{dataset.table_name}/n{n_final}", - ( - _scalar_value(measurement, "generation_seconds"), - _scalar_value(measurement, "wall_seconds_per_point"), - _scalar_value( - measurement, - "evaluator_total_seconds_per_point", - ), - _scalar_value(measurement, "matrix_element"), - _scalar_relative_difference(measurement), - ), - ) - - if not (matrix_datasets or getattr(catalog, "scalar_datasets", ())): - # Small injected catalogs used by the final-audit unit boundary do not - # carry renderer metadata. Their cells still receive the core field-level - # visibility check, while the canonical catalog exercises every table. - for cell in required_cells: - measurement = measurements.get(cell.cell_id, _NA) - fragments = [ - _metric(measurement, "generation_seconds"), - _metric( - measurement, - "wall_seconds_per_point", - microseconds=True, - ), - ] - if cell.measurement.execution_mode is not ExecutionMode.AMPLICOL: - fragments.append( - _metric( - measurement, - "execution_seconds_per_point", - microseconds=True, - ) - ) - record(cell, f"injected-catalog/{cell.cell_id}", fragments) - for cell in static_na_cells: - record( - cell, - f"injected-catalog/{cell.cell_id}", - (_static_na(), _static_na()), - ) - - accounting = report_display_accounting( - catalog=catalog, - max_n_final=max_n_final, - ) - if structural_seen != (accounting.structurally_not_applicable_display_slot_count): - contract_errors.append( - "structural display-slot enumeration differs from the catalog: " - f"{structural_seen}/" - f"{accounting.structurally_not_applicable_display_slot_count}" - ) - if not_exposed_seen != accounting.not_exposed_display_slot_count: - contract_errors.append( - "not-exposed display-slot enumeration differs from the catalog: " - f"{not_exposed_seen}/{accounting.not_exposed_display_slot_count}" - ) - required_ids = set(required_by_id) - missing = tuple(sorted(required_ids - rendered_cell_ids)) - static_na_ids = {cell.cell_id for cell in static_na_cells} - missing_static_na = tuple(sorted(static_na_ids - rendered_static_na_cell_ids)) - if missing_static_na: - contract_errors.append( - "catalog static N/A cells are not rendered: " + ", ".join(missing_static_na) - ) - return VisibleCompleteness( - maximum_n_final=max_n_final, - declared_measurement_cell_count=(accounting.declared_measurement_cell_count), - required_measurement_count=accounting.required_measurement_count, - rendered_required_measurement_count=len(rendered_cell_ids & required_ids), - structurally_not_applicable_display_slot_count=structural_seen, - not_exposed_display_slot_count=not_exposed_seen, - applicable_na_display_slots=tuple(sorted(set(na_slots))), - missing_rendered_cell_ids=missing, - contract_errors=tuple(sorted(set(contract_errors))), - catalog_static_na_cell_count=accounting.catalog_static_na_cell_count, - rendered_catalog_static_na_cell_count=len(rendered_static_na_cell_ids), - ) - - -def render_all_tables( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, - authenticated_source_lineage: tuple[str, str] | None = None, -) -> dict[str, str]: - cache_source = caches if isinstance(caches, Mapping) else tuple(caches) - return { - SUMMARY_TABLE_NAME: render_validation_summary( - cache_source, - catalog=catalog, - authenticated_source_lineage=authenticated_source_lineage, - ), - **render_all_best_mode_tables(cache_source, catalog=catalog), - **render_all_matrix_tables(cache_source, catalog=catalog), - **render_all_z_ladders(cache_source, catalog=catalog), - **render_all_scalar_ladders(cache_source, catalog=catalog), - } - - -__all__ = [ - "BaselineCandidateAdapter", - "JoinedMatrixCell", - "JoinedWorkload", - "MeasurementIndex", - "VisibleCompleteness", - "render_all_best_mode_tables", - "render_all_matrix_tables", - "render_all_scalar_ladders", - "render_all_tables", - "render_all_z_ladders", - "render_best_mode_table", - "render_matrix_comparison_table", - "render_matrix_table", - "render_scalar_ladder", - "render_validation_summary", - "render_z_ladder", - "summarize_visible_completeness", -] diff --git a/pyamplicol/tools/performance_report/report_policy.py b/pyamplicol/tools/performance_report/report_policy.py deleted file mode 100644 index 6bd03296b4..0000000000 --- a/pyamplicol/tools/performance_report/report_policy.py +++ /dev/null @@ -1,289 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Strict publication policies not duplicated by the exhaustive final auditor.""" - -from __future__ import annotations - -import math -import re -from collections.abc import Mapping -from dataclasses import dataclass - -from .models import ResultStatus -from .runner import DEFAULT_TARGET_RUNTIME_SECONDS -from .source_identity import SOURCE_IDENTITY_SCHEMA -from .timing import unavailable_execution_timing_record - -Measurement = Mapping[str, object] -_FULL_SHA_RE = re.compile(r"[0-9a-f]{40}") -_MINIMUM_TARGET_FRACTION = 0.95 -_MINIMUM_TIMED_SAMPLES = 5 - - -@dataclass(frozen=True, slots=True) -class ReportPolicyIssue: - field: str - detail: str - - -def _finite_number(value: object) -> float | None: - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - result = float(value) - return result if math.isfinite(result) else None - - -def _runtime_evidence(measurement: Measurement) -> Mapping[str, object] | None: - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return None - runtime = provenance.get("runtime_profile") - if not isinstance(runtime, Mapping): - return None - legacy = runtime.get("measurement") - return legacy if isinstance(legacy, Mapping) else runtime - - -def timing_policy_issues( - measurement: Measurement, - *, - target_runtime_seconds: float = DEFAULT_TARGET_RUNTIME_SECONDS, -) -> tuple[ReportPolicyIssue, ...]: - """Return timing defects for one otherwise successful report measurement.""" - - if measurement.get("status") != ResultStatus.OK.value: - return () - issues: list[ReportPolicyIssue] = [] - for field in ("generation_seconds", "wall_seconds_per_point"): - value = _finite_number(measurement.get(field)) - if value is None or value <= 0.0: - issues.append( - ReportPolicyIssue(field, "must be finite and strictly positive") - ) - - execution = _finite_number(measurement.get("execution_seconds_per_point")) - if execution is None: - if unavailable_execution_timing_record( - measurement, - "execution_seconds_per_point", - ) is None: - issues.append( - ReportPolicyIssue( - "execution_seconds_per_point", - ( - "must be measured or carry authenticated Arena evidence " - "that the execution attribution is not exposed" - ), - ) - ) - elif execution < 0.0: - issues.append( - ReportPolicyIssue( - "execution_seconds_per_point", - "must not be negative", - ) - ) - elif execution == 0.0: - issues.append( - ReportPolicyIssue( - "execution_seconds_per_point", - "zero is not a timing measurement; an unexposed attribution " - "must be null with authenticated Arena evidence", - ) - ) - - sample_count = measurement.get("sample_count") - if ( - isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < _MINIMUM_TIMED_SAMPLES - ): - issues.append( - ReportPolicyIssue( - "sample_count", - f"at least {_MINIMUM_TIMED_SAMPLES} timed samples are required", - ) - ) - for field in ( - "standard_error_seconds_per_point", - "relative_standard_error", - ): - value = _finite_number(measurement.get(field)) - if value is None or value <= 0.0: - issues.append( - ReportPolicyIssue( - field, - "must be finite, measured, and strictly positive", - ) - ) - - evidence = _runtime_evidence(measurement) - if evidence is None: - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile", - "measured-duration evidence is required", - ) - ) - return tuple(issues) - requested = _finite_number(evidence.get("target_runtime_seconds")) - achieved = _finite_number(evidence.get("achieved_runtime_seconds")) - if requested is None or not math.isclose( - requested, - target_runtime_seconds, - rel_tol=0.0, - abs_tol=1.0e-12, - ): - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.target_runtime_seconds", - f"must equal {target_runtime_seconds:g} seconds", - ) - ) - if ( - achieved is None - or achieved < _MINIMUM_TARGET_FRACTION * target_runtime_seconds - ): - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.achieved_runtime_seconds", - ( - "must record at least " - f"{_MINIMUM_TARGET_FRACTION * target_runtime_seconds:g} " - "seconds of timed evaluation" - ), - ) - ) - if evidence.get("target_runtime_achieved") is not True: - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.target_runtime_achieved", - "must be true", - ) - ) - if evidence.get("interrupted") is True: - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.interrupted", - "partial timing runs are not publishable", - ) - ) - completed = evidence.get("completed_sample_count") - planned = evidence.get("planned_sample_count") - if (completed is not None or planned is not None) and ( - isinstance(completed, bool) - or not isinstance(completed, int) - or isinstance(planned, bool) - or not isinstance(planned, int) - or completed < _MINIMUM_TIMED_SAMPLES - or completed != planned - ): - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.completed_sample_count", - "all planned timing blocks must complete", - ) - ) - chunk_count = evidence.get("chunk_count") - if chunk_count is not None and ( - isinstance(chunk_count, bool) - or not isinstance(chunk_count, int) - or chunk_count < _MINIMUM_TIMED_SAMPLES - ): - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.chunk_count", - f"at least {_MINIMUM_TIMED_SAMPLES} timed chunks are required", - ) - ) - if completed is None and chunk_count is None: - issues.append( - ReportPolicyIssue( - "provenance.runtime_profile.sample_count", - "timed sample or chunk completion evidence is required", - ) - ) - return tuple(issues) - - -def source_policy_issues( - measurement: Measurement, -) -> tuple[ReportPolicyIssue, ...]: - """Require the exact clean measurement commit and tree in provenance.""" - - if measurement.get("status") != ResultStatus.OK.value: - return () - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return ( - ReportPolicyIssue("provenance", "source identity is required"), - ) - issues: list[ReportPolicyIssue] = [] - if provenance.get("report_source_identity_schema") != SOURCE_IDENTITY_SCHEMA: - issues.append( - ReportPolicyIssue( - "provenance.report_source_identity_schema", - f"must equal {SOURCE_IDENTITY_SCHEMA}", - ) - ) - for field in ( - "report_source_revision", - "report_source_tree", - "report_measured_source_revision", - "report_measured_source_tree", - ): - value = provenance.get(field) - if not isinstance(value, str) or _FULL_SHA_RE.fullmatch(value) is None: - issues.append( - ReportPolicyIssue( - f"provenance.{field}", - "must be a full lowercase Git object ID", - ) - ) - if provenance.get("report_source_revision") != provenance.get( - "report_measured_source_revision" - ): - issues.append( - ReportPolicyIssue( - "provenance.report_measured_source_revision", - "must match the measured source revision", - ) - ) - if provenance.get("report_source_tree") != provenance.get( - "report_measured_source_tree" - ): - issues.append( - ReportPolicyIssue( - "provenance.report_measured_source_tree", - "must match the measured source tree", - ) - ) - if provenance.get("report_source_clean") is not True: - issues.append( - ReportPolicyIssue( - "provenance.report_source_clean", - "measurement source must be clean", - ) - ) - return tuple(issues) - - -def publication_measurement_policy_issues( - measurement: Measurement, - *, - target_runtime_seconds: float = DEFAULT_TARGET_RUNTIME_SECONDS, -) -> tuple[ReportPolicyIssue, ...]: - return ( - *timing_policy_issues( - measurement, - target_runtime_seconds=target_runtime_seconds, - ), - *source_policy_issues(measurement), - ) - - -__all__ = [ - "ReportPolicyIssue", - "publication_measurement_policy_issues", - "source_policy_issues", - "timing_policy_issues", -] diff --git a/pyamplicol/tools/performance_report/resources.py b/pyamplicol/tools/performance_report/resources.py deleted file mode 100644 index dec488b448..0000000000 --- a/pyamplicol/tools/performance_report/resources.py +++ /dev/null @@ -1,2068 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Portable process-tree resource monitoring for report workers.""" - -from __future__ import annotations - -import ctypes -import math -import os -import platform -import shutil -import signal -import subprocess -import threading -import time -from collections import defaultdict -from collections.abc import Callable, Collection, Mapping, Sequence -from contextlib import suppress -from dataclasses import dataclass -from datetime import UTC, datetime -from functools import cache -from pathlib import Path -from typing import Literal, Protocol - -try: - from tools.ci.memory_watchdog import ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON, - DARWIN_PHYSICAL_FOOTPRINT_PROBE_REASON, - MEMORY_PROBE_REASON, - RSS_LIMIT_REASON, - DarwinPhysicalFootprintProbe, - ) - from tools.ci.memory_watchdog import ( - ProbeError as WatchdogProbeError, - ) - from tools.ci.memory_watchdog import ( - ProcessInfo as WatchdogProcessInfo, - ) - from tools.ci.memory_watchdog import ( - _darwin_libproc_snapshot as _watchdog_darwin_libproc_snapshot, - ) -except ModuleNotFoundError as error: - if error.name not in {"tools", "tools.ci", "tools.ci.memory_watchdog"}: - raise - from ._memory_watchdog import ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON, - DARWIN_PHYSICAL_FOOTPRINT_PROBE_REASON, - MEMORY_PROBE_REASON, - RSS_LIMIT_REASON, - DarwinPhysicalFootprintProbe, - ) - from ._memory_watchdog import ( - ProbeError as WatchdogProbeError, - ) - from ._memory_watchdog import ( - ProcessInfo as WatchdogProcessInfo, - ) - from ._memory_watchdog import ( - _darwin_libproc_snapshot as _watchdog_darwin_libproc_snapshot, - ) - -from .phase_state import ( - WORKER_PHASE_STATE_ABI, - WorkerPhaseChannel, - WorkerPhaseState, - WorkerPhaseStateError, - read_worker_phase_state, -) - -DEFAULT_SAMPLE_INTERVAL_SECONDS = 1.0 -DEFAULT_TERMINATION_GRACE_SECONDS = 5.0 -DEFAULT_PHASE_STATE_STARTUP_GRACE_SECONDS = 30.0 -GENERATION_PHASE_EVIDENCE_ABI = "pyamplicol-report-generation-phase-evidence-v1" -PROCESS_TREE_MEMORY_METRIC_ABI = "pyamplicol-process-tree-memory-metric-v1" -MAX_CONSECUTIVE_MEMORY_PROBE_FAILURES = 3 -DEFAULT_SUPERVISOR_STDERR_LIMIT_BYTES = 64 * 1024 -DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES = 64 * 1024 * 1024 -DEFAULT_MINIMUM_FREE_DISK_BYTES = 5 * 1024 * 1024 * 1024 -DEFAULT_STORAGE_SAFETY_INTERVAL_SECONDS = 0.05 -_WORKER_IMPORT_ENVIRONMENT = frozenset( - { - "VIRTUAL_ENV", - "_OLD_VIRTUAL_PATH", - "__PYVENV_LAUNCHER__", - } -) -_EXPLICIT_PYAMPLICOL_WORKER_CONTROLS = frozenset( - { - "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR", - "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT", - } -) - - -class ResourceProbeError(RuntimeError): - """Raised when a host process snapshot cannot be collected.""" - - -@dataclass(frozen=True, slots=True) -class ProcessRecord: - """Resource data for one process.""" - - pid: int - ppid: int - rss_bytes: int - cpu_seconds: float | None = None - - -@dataclass(frozen=True, slots=True) -class ProcessTreeSample: - """Aggregate resource data for a root process and its descendants.""" - - rss_bytes: int - child_count: int - cpu_seconds: float | None - member_pids: tuple[int, ...] - physical_footprint_bytes: int | None = None - guard_bytes: int | None = None - - -@dataclass(frozen=True, slots=True) -class ResourceUsage: - """Latest and peak resource data exposed to report scheduling.""" - - available: bool - current_rss_bytes: int | None - peak_rss_bytes: int | None - child_count: int | None - cpu_seconds: float | None - wall_seconds: float - error: str | None = None - current_physical_footprint_bytes: int | None = None - peak_physical_footprint_bytes: int | None = None - current_guard_bytes: int | None = None - peak_guard_bytes: int | None = None - memory_metric_abi: str | None = None - memory_probe_reason: str | None = None - - -TerminationReason = Literal[ - "completed", - "worker_exit", - "cancelled", - "worker_timeout", - "generation_timeout", - "profiling_timeout", - "validation_timeout", - "memory_limit", - "memory_probe_error", - "output_limit", - "output_probe_error", - "disk_space_limit", - "disk_probe_error", - "phase_state_error", -] - - -@dataclass(frozen=True, slots=True) -class WorkerObservation: - """One non-authoritative live sample for dashboards and logs.""" - - pid: int - usage: ResourceUsage - phase: str | None - phase_sequence: int | None - member_pids: tuple[int, ...] - - -@dataclass(frozen=True, slots=True) -class GenerationPhaseEvidence: - """Supervisor-authenticated evidence for the worker generation interval.""" - - configured_timeout_seconds: float - supervisor_reason: TerminationReason - authenticated: bool - run_id: str - worker_pid: int - final_sequence: int | None - final_phase: str | None - generation_started_monotonic_ns: int | None - generation_finished_monotonic_ns: int | None - generation_elapsed_seconds: float | None - final_state_sha256: str | None - error: str | None = None - - def as_dict(self) -> dict[str, object]: - return { - "abi": GENERATION_PHASE_EVIDENCE_ABI, - "phase_state_abi": WORKER_PHASE_STATE_ABI, - "configured_timeout_seconds": self.configured_timeout_seconds, - "supervisor_reason": self.supervisor_reason, - "authenticated": self.authenticated, - "run_id": self.run_id, - "worker_pid": self.worker_pid, - "final_sequence": self.final_sequence, - "final_phase": self.final_phase, - "generation_started_monotonic_ns": (self.generation_started_monotonic_ns), - "generation_finished_monotonic_ns": (self.generation_finished_monotonic_ns), - "generation_elapsed_seconds": self.generation_elapsed_seconds, - "final_state_sha256": self.final_state_sha256, - "error": self.error, - } - - -@dataclass(frozen=True, slots=True) -class SupervisedResult: - """Result of one worker process supervised under optional limits.""" - - returncode: int - reason: TerminationReason - usage: ResourceUsage - generation_phase: GenerationPhaseEvidence | None = None - memory_limit_bytes: int | None = None - memory_limit_reason: str | None = None - output_limit_path: str | None = None - output_limit_bytes: int | None = None - observed_output_bytes: int | None = None - minimum_free_disk_bytes: int | None = None - observed_free_disk_bytes: int | None = None - pid: int | None = None - member_pids: tuple[int, ...] = () - signal_number: int | None = None - signal_name: str | None = None - supervisor_stderr: str | None = None - supervisor_stderr_truncated: bool = False - supervisor_stderr_limit_bytes: int | None = None - phase_state_error: str | None = None - started_at_utc: str | None = None - finished_at_utc: str | None = None - teardown_escalated: bool = False - teardown_seconds: float = 0.0 - - -class _BoundedByteTail: - """Drain a pipe without allowing diagnostic capture to grow unbounded.""" - - def __init__(self, limit_bytes: int) -> None: - if limit_bytes <= 0: - raise ValueError("stderr capture limit must be positive") - self._limit_bytes = limit_bytes - self._tail = bytearray() - self._total_bytes = 0 - self._lock = threading.Lock() - - def drain(self, stream: object) -> None: - read = getattr(stream, "read", None) - if not callable(read): - return - while True: - try: - chunk = read(64 * 1024) - except (OSError, ValueError): - return - if not chunk: - return - if isinstance(chunk, str): - chunk = chunk.encode("utf-8", errors="replace") - with self._lock: - self._total_bytes += len(chunk) - self._tail.extend(chunk) - if len(self._tail) > self._limit_bytes: - del self._tail[: len(self._tail) - self._limit_bytes] - - def decoded(self) -> tuple[str | None, bool]: - with self._lock: - if not self._tail and self._total_bytes == 0: - return None, False - return ( - bytes(self._tail).decode("utf-8", errors="replace"), - self._total_bytes > self._limit_bytes, - ) - - -class CompletedProcessLike(Protocol): - returncode: int - stdout: str - stderr: str - - -class WorkerProcess(Protocol): - pid: int - returncode: int | None - - def poll(self) -> int | None: ... - - def wait(self, timeout: float | None = None) -> int: ... - - -Snapshotter = Callable[[], Mapping[int, ProcessRecord]] -DarwinSnapshotter = Callable[[], Mapping[int, WatchdogProcessInfo]] -PhysicalFootprintProbe = Callable[[Collection[int]], Mapping[int, int]] -PsRunner = Callable[[Sequence[str]], CompletedProcessLike] -PopenFactory = Callable[..., WorkerProcess] -Clock = Callable[[], float] -Sleeper = Callable[[float], None] -TreeSignaler = Callable[[int | None, Collection[int], int], None] -ObservationCallback = Callable[[WorkerObservation], None] -CancellationCheck = Callable[[], bool] -DiskFreeProbe = Callable[[Path], int] - - -def _disk_free_bytes(path: Path) -> int: - return int(shutil.disk_usage(path).free) - - -@dataclass(frozen=True, slots=True) -class _ProcessIdentity: - """Authenticated process birth identity plus its current signal group.""" - - birth_token: int | tuple[int, int] - process_group: int - - -ProcessIdentityProbe = Callable[[int], _ProcessIdentity | None] - - -def _parse_proc_stat(text: str, *, clock_ticks_per_second: int) -> tuple[int, float]: - """Return ``(ppid, cpu_seconds)`` from one Linux ``/proc/PID/stat`` row.""" - - if clock_ticks_per_second <= 0: - raise ValueError("clock_ticks_per_second must be positive") - closing_parenthesis = text.rfind(")") - if closing_parenthesis < 0: - raise ValueError("missing process-name terminator") - fields = text[closing_parenthesis + 1 :].split() - # fields starts at the kernel's field 3 (state). - if len(fields) < 13: - raise ValueError("incomplete /proc stat record") - ppid = int(fields[1]) - cpu_ticks = int(fields[11]) + int(fields[12]) - if min(ppid, cpu_ticks) < 0: - raise ValueError("negative /proc process value") - return ppid, cpu_ticks / clock_ticks_per_second - - -def _parse_proc_status_rss(text: str) -> int: - """Return RSS bytes from one Linux ``/proc/PID/status`` payload.""" - - for line in text.splitlines(): - if not line.startswith("VmRSS:"): - continue - fields = line.split() - if len(fields) != 3 or fields[2].lower() != "kb": - raise ValueError(f"invalid VmRSS record: {line!r}") - rss_kib = int(fields[1]) - if rss_kib < 0: - raise ValueError("negative VmRSS value") - return rss_kib * 1024 - return 0 - - -def _parse_ps_output(text: str) -> dict[int, ProcessRecord]: - """Parse ``ps -axo pid=,ppid=,rss=`` output.""" - - records: dict[int, ProcessRecord] = {} - for line_number, line in enumerate(text.splitlines(), start=1): - if not line.strip(): - continue - fields = line.split() - if len(fields) != 3: - raise ValueError(f"invalid ps row {line_number}: {line!r}") - pid, ppid, rss_kib = map(int, fields) - if min(pid, ppid, rss_kib) < 0: - raise ValueError(f"negative ps value on row {line_number}") - records[pid] = ProcessRecord( - pid=pid, - ppid=ppid, - rss_bytes=rss_kib * 1024, - ) - return records - - -def _parse_ps_cpu_time(value: str) -> float: - """Parse BSD ``ps time=`` as cumulative CPU seconds.""" - - raw = value.strip() - if not raw: - raise ValueError("empty ps CPU time") - days = 0 - if "-" in raw: - raw_days, raw = raw.split("-", 1) - days = int(raw_days) - fields = raw.split(":") - if len(fields) == 2: - hours = 0 - minutes = int(fields[0]) - seconds = float(fields[1]) - elif len(fields) == 3: - hours = int(fields[0]) - minutes = int(fields[1]) - seconds = float(fields[2]) - else: - raise ValueError(f"invalid ps CPU time: {value!r}") - if ( - min(days, hours, minutes) < 0 - or not math.isfinite(seconds) - or seconds < 0.0 - or seconds >= 60.0 - or (len(fields) == 3 and minutes >= 60) - ): - raise ValueError(f"invalid ps CPU time: {value!r}") - return days * 86_400.0 + hours * 3_600.0 + minutes * 60.0 + seconds - - -def _parse_darwin_ps_output(text: str) -> dict[int, ProcessRecord]: - """Parse Darwin process rows including truthful cumulative CPU time.""" - - records: dict[int, ProcessRecord] = {} - for line_number, line in enumerate(text.splitlines(), start=1): - if not line.strip(): - continue - fields = line.split() - if len(fields) != 4: - raise ValueError(f"invalid Darwin ps row {line_number}: {line!r}") - pid, ppid, rss_kib = map(int, fields[:3]) - if min(pid, ppid, rss_kib) < 0: - raise ValueError(f"negative Darwin ps value on row {line_number}") - records[pid] = ProcessRecord( - pid=pid, - ppid=ppid, - rss_bytes=rss_kib * 1024, - cpu_seconds=_parse_ps_cpu_time(fields[3]), - ) - return records - - -def _linux_proc_snapshot( - proc_root: Path = Path("/proc"), - *, - clock_ticks_per_second: int | None = None, -) -> dict[int, ProcessRecord]: - """Collect a Linux process snapshot directly from procfs.""" - - if clock_ticks_per_second is None: - clock_ticks_per_second = int(os.sysconf("SC_CLK_TCK")) - try: - entries = tuple(proc_root.iterdir()) - except OSError as error: - raise ResourceProbeError(f"cannot enumerate {proc_root}: {error}") from error - - records: dict[int, ProcessRecord] = {} - for entry in entries: - if not entry.name.isdecimal(): - continue - try: - stat = (entry / "stat").read_text(encoding="utf-8", errors="replace") - status = (entry / "status").read_text( - encoding="utf-8", - errors="replace", - ) - ppid, cpu_seconds = _parse_proc_stat( - stat, - clock_ticks_per_second=clock_ticks_per_second, - ) - pid = int(entry.name) - records[pid] = ProcessRecord( - pid=pid, - ppid=ppid, - rss_bytes=_parse_proc_status_rss(status), - cpu_seconds=cpu_seconds, - ) - except (OSError, ValueError): - # A process can disappear or become inaccessible during the scan. - continue - if not records: - raise ResourceProbeError(f"{proc_root} yielded no readable processes") - return records - - -def _default_ps_runner(command: Sequence[str]) -> CompletedProcessLike: - environment = os.environ.copy() - environment["LC_ALL"] = "C" - try: - return subprocess.run( - tuple(command), - check=False, - capture_output=True, - text=True, - env=environment, - timeout=10, - ) - except (OSError, subprocess.SubprocessError) as error: - raise ResourceProbeError(f"cannot execute ps: {error}") from error - - -def _ps_snapshot(*, runner: PsRunner = _default_ps_runner) -> dict[int, ProcessRecord]: - """Collect a portable process snapshot through ``ps``.""" - - completed = runner(("ps", "-axo", "pid=,ppid=,rss=")) - if completed.returncode != 0: - detail = completed.stderr.strip() or f"exit code {completed.returncode}" - raise ResourceProbeError(f"ps process probe failed: {detail}") - try: - records = _parse_ps_output(completed.stdout) - except ValueError as error: - raise ResourceProbeError(str(error)) from error - if not records: - raise ResourceProbeError("ps process probe yielded no records") - return records - - -def _darwin_ps_snapshot( - *, - runner: PsRunner = _default_ps_runner, -) -> dict[int, ProcessRecord]: - completed = runner(("ps", "-axo", "pid=,ppid=,rss=,time=")) - if completed.returncode != 0: - detail = completed.stderr.strip() or f"exit code {completed.returncode}" - raise ResourceProbeError(f"Darwin ps process probe failed: {detail}") - try: - records = _parse_darwin_ps_output(completed.stdout) - except ValueError as error: - raise ResourceProbeError(str(error)) from error - if not records: - raise ResourceProbeError("Darwin ps process probe yielded no records") - return records - - -def _darwin_native_snapshot( - *, - snapshotter: DarwinSnapshotter = _watchdog_darwin_libproc_snapshot, -) -> dict[int, ProcessRecord]: - """Collect a Darwin process snapshot through ``libproc`` only.""" - - try: - native_records = snapshotter() - except WatchdogProbeError as error: - raise ResourceProbeError(str(error)) from error - records = { - pid: ProcessRecord( - pid=record.pid, - ppid=record.ppid, - rss_bytes=record.rss_bytes, - cpu_seconds=record.cpu_seconds, - ) - for pid, record in native_records.items() - } - if not records: - raise ResourceProbeError("Darwin libproc process probe yielded no records") - return records - - -def process_snapshot( - system: str | None = None, - *, - proc_root: Path = Path("/proc"), - ps_runner: PsRunner = _default_ps_runner, - darwin_snapshotter: DarwinSnapshotter = _watchdog_darwin_libproc_snapshot, -) -> dict[int, ProcessRecord]: - """Collect one process snapshot on Linux or macOS.""" - - host = system or platform.system() - if host == "Linux": - try: - return _linux_proc_snapshot(proc_root) - except ResourceProbeError: - return _ps_snapshot(runner=ps_runner) - if host == "Darwin": - return _darwin_native_snapshot(snapshotter=darwin_snapshotter) - raise ResourceProbeError(f"unsupported host for resource monitoring: {host!r}") - - -class ProcessTreeSampler: - """Aggregate a root and recursively discovered descendants.""" - - def __init__(self, root_pid: int) -> None: - if root_pid <= 0: - raise ValueError("root_pid must be positive") - self.root_pid = root_pid - self._known_pids = {root_pid} - - def sample( - self, - records: Mapping[int, ProcessRecord], - physical_footprint_probe: PhysicalFootprintProbe | None = None, - ) -> ProcessTreeSample: - children: dict[int, list[int]] = defaultdict(list) - for record in records.values(): - children[record.ppid].append(record.pid) - - selected = {pid for pid in self._known_pids if pid in records} - if self.root_pid in records: - selected.add(self.root_pid) - pending = list(selected) - while pending: - parent = pending.pop() - for child in children.get(parent, ()): - if child not in selected: - selected.add(child) - pending.append(child) - - self._known_pids = selected - members = tuple(sorted(selected)) - cpu_values = [ - records[pid].cpu_seconds - for pid in members - if records[pid].cpu_seconds is not None - ] - rss_bytes = sum(records[pid].rss_bytes for pid in members) - physical_footprint_bytes: int | None = None - if physical_footprint_probe is not None: - try: - footprints = physical_footprint_probe(members) - except WatchdogProbeError as error: - raise ResourceProbeError(str(error)) from error - physical_footprint_bytes = sum( - footprints.get(pid, records[pid].rss_bytes) for pid in members - ) - return ProcessTreeSample( - rss_bytes=rss_bytes, - child_count=max(len(members) - (self.root_pid in selected), 0), - cpu_seconds=( - sum(cpu_values) if members and len(cpu_values) == len(members) else None - ), - member_pids=members, - physical_footprint_bytes=physical_footprint_bytes, - guard_bytes=max( - rss_bytes, - physical_footprint_bytes - if physical_footprint_bytes is not None - else rss_bytes, - ), - ) - - -class ResourceMonitor: - """Sample current and peak resource usage, optionally in a daemon thread.""" - - def __init__( - self, - root_pid: int, - *, - interval_seconds: float = DEFAULT_SAMPLE_INTERVAL_SECONDS, - snapshotter: Snapshotter = process_snapshot, - physical_footprint_probe: PhysicalFootprintProbe | None = None, - clock: Clock = time.monotonic, - ) -> None: - if interval_seconds <= 0: - raise ValueError("interval_seconds must be positive") - self._sampler = ProcessTreeSampler(root_pid) - self._interval_seconds = float(interval_seconds) - self._snapshotter = snapshotter - self._physical_footprint_probe = physical_footprint_probe - self._clock = clock - self._started_at = clock() - self._usage = ResourceUsage( - available=False, - current_rss_bytes=None, - peak_rss_bytes=None, - child_count=None, - cpu_seconds=None, - wall_seconds=0.0, - current_guard_bytes=None, - peak_guard_bytes=None, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - ) - self._last_members: tuple[int, ...] = () - self._lock = threading.Lock() - self._stop = threading.Event() - self._thread: threading.Thread | None = None - - @property - def usage(self) -> ResourceUsage: - with self._lock: - return self._usage - - @property - def member_pids(self) -> tuple[int, ...]: - with self._lock: - return self._last_members - - def sample_once(self) -> ResourceUsage: - """Take one sample and record unavailable host metrics.""" - - wall_seconds = max(self._clock() - self._started_at, 0.0) - try: - records = self._snapshotter() - except ( - OSError, - ResourceProbeError, - subprocess.SubprocessError, - ValueError, - ) as error: - return self._record_probe_failure( - wall_seconds, - error, - MEMORY_PROBE_REASON, - ) - try: - sample = self._sampler.sample( - records, - physical_footprint_probe=self._physical_footprint_probe, - ) - except ( - OSError, - ResourceProbeError, - subprocess.SubprocessError, - ValueError, - ) as error: - return self._record_probe_failure( - wall_seconds, - error, - ( - DARWIN_PHYSICAL_FOOTPRINT_PROBE_REASON - if self._physical_footprint_probe is not None - else MEMORY_PROBE_REASON - ), - ) - - with self._lock: - peak_rss = max(self._usage.peak_rss_bytes or 0, sample.rss_bytes) - peak_physical_footprint = self._usage.peak_physical_footprint_bytes - if sample.physical_footprint_bytes is not None: - peak_physical_footprint = max( - peak_physical_footprint or 0, - sample.physical_footprint_bytes, - ) - assert sample.guard_bytes is not None - peak_guard = max( - self._usage.peak_guard_bytes or 0, - sample.guard_bytes, - ) - self._last_members = sample.member_pids - self._usage = ResourceUsage( - available=True, - current_rss_bytes=sample.rss_bytes, - peak_rss_bytes=peak_rss, - child_count=sample.child_count, - cpu_seconds=sample.cpu_seconds, - wall_seconds=wall_seconds, - current_physical_footprint_bytes=(sample.physical_footprint_bytes), - peak_physical_footprint_bytes=peak_physical_footprint, - current_guard_bytes=sample.guard_bytes, - peak_guard_bytes=peak_guard, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - ) - return self._usage - - def _record_probe_failure( - self, - wall_seconds: float, - error: BaseException, - reason: str, - ) -> ResourceUsage: - with self._lock: - self._usage = ResourceUsage( - available=False, - current_rss_bytes=None, - peak_rss_bytes=self._usage.peak_rss_bytes, - child_count=None, - cpu_seconds=self._usage.cpu_seconds, - wall_seconds=wall_seconds, - error=str(error), - current_physical_footprint_bytes=None, - peak_physical_footprint_bytes=( - self._usage.peak_physical_footprint_bytes - ), - current_guard_bytes=None, - peak_guard_bytes=self._usage.peak_guard_bytes, - memory_metric_abi=PROCESS_TREE_MEMORY_METRIC_ABI, - memory_probe_reason=reason, - ) - return self._usage - - def start(self) -> None: - if self._thread is not None: - return - self.sample_once() - self._thread = threading.Thread( - target=self._run, - name="pyamplicol-report-resource-monitor", - daemon=True, - ) - self._thread.start() - - def close(self) -> None: - self._stop.set() - if self._thread is not None: - self._thread.join(timeout=max(2.0 * self._interval_seconds, 1.0)) - self._thread = None - - def _run(self) -> None: - while not self._stop.wait(self._interval_seconds): - self.sample_once() - - def __enter__(self) -> ResourceMonitor: - self.start() - return self - - def __exit__(self, *_exc: object) -> None: - self.close() - - -def _default_popen(command: Sequence[str], **kwargs: object) -> WorkerProcess: - return subprocess.Popen(tuple(command), **kwargs) - - -def _worker_environment( - overrides: Mapping[str, str] | None = None, - *, - scrub_import_environment: bool = False, -) -> dict[str, str]: - """Copy the controller environment explicitly for supervised workers.""" - - environment = os.environ.copy() - if scrub_import_environment: - for name in tuple(environment): - if ( - name in _WORKER_IMPORT_ENVIRONMENT - or name.startswith("PYTHON") - or name.startswith("PYAMPLICOL") - ): - environment.pop(name, None) - symbolica_license = os.environ.get("SYMBOLICA_LICENSE") - if symbolica_license is not None: - environment["SYMBOLICA_LICENSE"] = symbolica_license - for name, value in (overrides or {}).items(): - if ( - not isinstance(name, str) - or not name - or "=" in name - or "\x00" in name - or not isinstance(value, str) - or "\x00" in value - or ( - scrub_import_environment - and ( - name in _WORKER_IMPORT_ENVIRONMENT - or name.startswith("PYTHON") - or ( - name.startswith("PYAMPLICOL") - and name not in _EXPLICIT_PYAMPLICOL_WORKER_CONTROLS - ) - ) - ) - ): - raise ValueError("worker environment override is invalid") - environment[name] = value - return environment - - -def _signal_process_tree( - root_process_group: int | None, - out_of_group_pids: Collection[int], - selected_signal: int, -) -> None: - if root_process_group is not None: - with suppress(ProcessLookupError, PermissionError): - os.killpg(root_process_group, selected_signal) - for pid in out_of_group_pids: - with suppress(ProcessLookupError, PermissionError): - os.kill(pid, selected_signal) - - -def _parse_linux_process_identity(stat: str) -> _ProcessIdentity: - """Authenticate a Linux process from one coherent ``/proc/PID/stat`` row.""" - - closing_parenthesis = stat.rfind(")") - if closing_parenthesis < 0: - raise ValueError("missing process-name terminator") - fields = stat[closing_parenthesis + 1 :].split() - # ``fields`` starts at kernel field 3 (state). Read pgrp (field 5) and - # starttime (field 22) from the same snapshot so group migration cannot be - # mistaken for PID reuse. - process_group = int(fields[2]) - start_ticks = int(fields[19]) - if process_group <= 0 or start_ticks < 0: - raise ValueError("invalid process identity") - return _ProcessIdentity( - birth_token=start_ticks, - process_group=process_group, - ) - - -class _DarwinProcBsdInfo(ctypes.Structure): - """Darwin ``proc_bsdinfo`` fields needed for authenticated teardown.""" - - _fields_ = [ - ("pbi_flags", ctypes.c_uint32), - ("pbi_status", ctypes.c_uint32), - ("pbi_xstatus", ctypes.c_uint32), - ("pbi_pid", ctypes.c_uint32), - ("pbi_ppid", ctypes.c_uint32), - ("pbi_uid", ctypes.c_uint32), - ("pbi_gid", ctypes.c_uint32), - ("pbi_ruid", ctypes.c_uint32), - ("pbi_rgid", ctypes.c_uint32), - ("pbi_svuid", ctypes.c_uint32), - ("pbi_svgid", ctypes.c_uint32), - ("rfu_1", ctypes.c_uint32), - ("pbi_comm", ctypes.c_char * 16), - ("pbi_name", ctypes.c_char * 32), - ("pbi_nfiles", ctypes.c_uint32), - ("pbi_pgid", ctypes.c_uint32), - ("pbi_pjobc", ctypes.c_uint32), - ("e_tdev", ctypes.c_uint32), - ("e_tpgid", ctypes.c_uint32), - ("pbi_nice", ctypes.c_int32), - ("pbi_start_tvsec", ctypes.c_uint64), - ("pbi_start_tvusec", ctypes.c_uint64), - ] - - -@cache -def _darwin_libproc() -> ctypes.CDLL: - return ctypes.CDLL("/usr/lib/libproc.dylib", use_errno=True) - - -def _darwin_process_identity(pid: int) -> _ProcessIdentity | None: - info = _DarwinProcBsdInfo() - try: - proc_pidinfo = _darwin_libproc().proc_pidinfo - proc_pidinfo.argtypes = ( - ctypes.c_int, - ctypes.c_int, - ctypes.c_uint64, - ctypes.c_void_p, - ctypes.c_int, - ) - proc_pidinfo.restype = ctypes.c_int - written = proc_pidinfo( - pid, - 3, # PROC_PIDTBSDINFO - 0, - ctypes.byref(info), - ctypes.sizeof(info), - ) - except (AttributeError, OSError): - return None - if written != ctypes.sizeof(info): - return None - process_group = int(info.pbi_pgid) - start_seconds = int(info.pbi_start_tvsec) - start_microseconds = int(info.pbi_start_tvusec) - if ( - int(info.pbi_pid) != pid - or process_group <= 0 - or start_seconds < 0 - or not 0 <= start_microseconds < 1_000_000 - or (start_seconds == 0 and start_microseconds == 0) - ): - return None - return _ProcessIdentity( - birth_token=(start_seconds, start_microseconds), - process_group=process_group, - ) - - -def _process_identity(pid: int) -> _ProcessIdentity | None: - """Return immutable birth evidence and the process's current signal group.""" - - system = platform.system() - if system == "Linux": - try: - stat = Path(f"/proc/{pid}/stat").read_text(encoding="ascii") - return _parse_linux_process_identity(stat) - except (OSError, UnicodeError, ValueError, IndexError): - return None - if system == "Darwin": - return _darwin_process_identity(pid) - return None - - -@dataclass(frozen=True, slots=True) -class _TeardownResult: - returncode: int - escalated: bool - elapsed_seconds: float - - -@dataclass(frozen=True, slots=True) -class _TeardownDiagnostics: - escalated: bool - elapsed_seconds: float - - -def _emit_teardown_observation( - process: WorkerProcess, - monitor: ResourceMonitor, - observation_callback: ObservationCallback | None, - *, - phase: str, -) -> None: - usage = monitor.sample_once() - if observation_callback is None: - return - with suppress(Exception): - observation_callback( - WorkerObservation( - pid=process.pid, - usage=usage, - phase=phase, - phase_sequence=None, - member_pids=monitor.member_pids, - ) - ) - - -def _identity_process_group(identity: _ProcessIdentity) -> int: - return identity.process_group - - -def _capture_process_identities( - identities: dict[int, _ProcessIdentity], - member_pids: Collection[int], - identity_probe: ProcessIdentityProbe, -) -> None: - """Retain the first authenticated identity observed for each worker PID.""" - - for pid in member_pids: - if pid in identities: - continue - identity = identity_probe(pid) - if identity is not None: - identities[pid] = identity - - -def _live_descendant_identities( - process: WorkerProcess, - identities: Mapping[int, _ProcessIdentity], - identity_probe: ProcessIdentityProbe, -) -> dict[int, _ProcessIdentity]: - surviving: dict[int, _ProcessIdentity] = {} - for pid, captured in identities.items(): - if pid == process.pid: - continue - current = identity_probe(pid) - if current is None or current.birth_token != captured.birth_token: - continue - # Birth identity is immutable; route signals using the freshly probed - # process group in case the descendant called setpgid()/setsid(). - surviving[pid] = current - return surviving - - -def _signal_authenticated_tree( - process: WorkerProcess, - *, - returncode: int | None, - descendants: Mapping[int, _ProcessIdentity], - selected_signal: int, - signaler: TreeSignaler, -) -> None: - """Signal each authenticated worker identity no more than once.""" - - group_is_live = returncode is None or any( - _identity_process_group(identity) == process.pid - for identity in descendants.values() - ) - out_of_group = tuple( - sorted( - pid - for pid, identity in descendants.items() - if _identity_process_group(identity) != process.pid - ) - ) - if not group_is_live and not out_of_group: - return - signaler(process.pid if group_is_live else None, out_of_group, selected_signal) - - -def _terminate_worker( - process: WorkerProcess, - *, - monitor: ResourceMonitor, - process_identities: dict[int, _ProcessIdentity], - grace_seconds: float, - signaler: TreeSignaler, - clock: Clock, - sleeper: Sleeper, - observation_callback: ObservationCallback | None, - identity_probe: ProcessIdentityProbe, -) -> _TeardownResult: - started = clock() - identities = process_identities - - def refresh(*, phase: str) -> tuple[int | None, dict[int, _ProcessIdentity]]: - returncode = process.poll() - surviving = _live_descendant_identities( - process, - identities, - identity_probe, - ) - if returncode is not None and not surviving: - return returncode, {} - _emit_teardown_observation( - process, - monitor, - observation_callback, - phase=phase, - ) - _capture_process_identities( - identities, - monitor.member_pids, - identity_probe, - ) - returncode = process.poll() - surviving = _live_descendant_identities( - process, - identities, - identity_probe, - ) - return returncode, surviving - - returncode = process.poll() - surviving = _live_descendant_identities( - process, - identities, - identity_probe, - ) - if returncode is not None and not surviving: - return _TeardownResult( - returncode=returncode, - escalated=False, - elapsed_seconds=max(clock() - started, 0.0), - ) - _signal_authenticated_tree( - process, - returncode=returncode, - descendants=surviving, - selected_signal=signal.SIGTERM, - signaler=signaler, - ) - deadline = clock() + grace_seconds - while True: - returncode, surviving = refresh(phase="terminating") - if returncode is not None and not surviving: - return _TeardownResult( - returncode=returncode, - escalated=False, - elapsed_seconds=max(clock() - started, 0.0), - ) - if clock() >= deadline: - break - sleeper(min(0.25, max(deadline - clock(), 0.0))) - - _signal_authenticated_tree( - process, - returncode=returncode, - descendants=surviving, - selected_signal=signal.SIGKILL, - signaler=signaler, - ) - while True: - returncode, surviving = refresh(phase="waiting-for-reap") - if returncode is not None and not surviving: - return _TeardownResult( - returncode=returncode, - escalated=True, - elapsed_seconds=max(clock() - started, 0.0), - ) - # SIGKILL can remain uninterruptible while a task is in kernel I/O. - # Keep this lane occupied, but let the dashboard and other lanes run. - sleeper(0.25) - - -def _terminate_surviving_descendants( - process: WorkerProcess, - *, - monitor: ResourceMonitor, - grace_seconds: float, - signaler: TreeSignaler, - clock: Clock, - sleeper: Sleeper, - observation_callback: ObservationCallback | None, - identity_probe: ProcessIdentityProbe, - process_identities: dict[int, _ProcessIdentity], -) -> _TeardownDiagnostics: - """Terminate a process group left behind after its root has exited.""" - - started = clock() - identities = process_identities - surviving = _live_descendant_identities( - process, - identities, - identity_probe, - ) - if not surviving: - return _TeardownDiagnostics( - escalated=False, - elapsed_seconds=0.0, - ) - _signal_authenticated_tree( - process, - returncode=process.poll(), - descendants=surviving, - selected_signal=signal.SIGTERM, - signaler=signaler, - ) - deadline = clock() + grace_seconds - while surviving and clock() < deadline: - sleeper(min(0.05, max(deadline - clock(), 0.0))) - _emit_teardown_observation( - process, - monitor, - observation_callback, - phase="terminating", - ) - _capture_process_identities( - identities, - monitor.member_pids, - identity_probe, - ) - surviving = _live_descendant_identities( - process, - identities, - identity_probe, - ) - if not surviving: - return _TeardownDiagnostics( - escalated=False, - elapsed_seconds=max(clock() - started, 0.0), - ) - _signal_authenticated_tree( - process, - returncode=process.poll(), - descendants=surviving, - selected_signal=signal.SIGKILL, - signaler=signaler, - ) - while surviving: - sleeper(0.25) - _emit_teardown_observation( - process, - monitor, - observation_callback, - phase="waiting-for-reap", - ) - _capture_process_identities( - identities, - monitor.member_pids, - identity_probe, - ) - surviving = _live_descendant_identities( - process, - identities, - identity_probe, - ) - return _TeardownDiagnostics( - escalated=True, - elapsed_seconds=max(clock() - started, 0.0), - ) - - -def supervise_worker( - command: Sequence[str], - *, - timeout_seconds: float | None = None, - generation_timeout_seconds: float | None = None, - profiling_timeout_seconds: float | None = None, - validation_timeout_seconds: float | None = None, - generation_guard_includes_preparation: bool = False, - phase_channel: WorkerPhaseChannel | None = None, - max_rss_bytes: int | None = None, - output_file_limits: Mapping[Path, int] | None = None, - minimum_free_disk_bytes: int | None = None, - disk_probe_path: Path | None = None, - interval_seconds: float = DEFAULT_SAMPLE_INTERVAL_SECONDS, - termination_grace_seconds: float = DEFAULT_TERMINATION_GRACE_SECONDS, - phase_state_startup_grace_seconds: float = ( - DEFAULT_PHASE_STATE_STARTUP_GRACE_SECONDS - ), - environment_overrides: Mapping[str, str] | None = None, - scrub_import_environment: bool = False, - working_directory: Path | None = None, - snapshotter: Snapshotter = process_snapshot, - physical_footprint_probe: PhysicalFootprintProbe | None = None, - popen_factory: PopenFactory = _default_popen, - clock: Clock = time.monotonic, - sleeper: Sleeper = time.sleep, - signaler: TreeSignaler = _signal_process_tree, - observation_callback: ObservationCallback | None = None, - cancellation_requested: CancellationCheck | None = None, - capture_stderr: bool = False, - stderr_limit_bytes: int = DEFAULT_SUPERVISOR_STDERR_LIMIT_BYTES, - process_identity_probe: ProcessIdentityProbe = _process_identity, - disk_free_probe: DiskFreeProbe = _disk_free_bytes, -) -> SupervisedResult: - """Run a worker and enforce wall, stage, memory, and disk-safety limits. - - ``generation_timeout_seconds`` requires an authenticated phase channel. - Missing, malformed, replayed, or incomplete phase evidence terminates the - worker rather than silently turning the generation limit into a wall limit. - """ - - if not command: - raise ValueError("command must not be empty") - if timeout_seconds is not None and ( - timeout_seconds <= 0 or not math.isfinite(timeout_seconds) - ): - raise ValueError("timeout_seconds must be positive when specified") - if generation_timeout_seconds is not None and ( - generation_timeout_seconds <= 0 or not math.isfinite(generation_timeout_seconds) - ): - raise ValueError("generation_timeout_seconds must be positive when specified") - for stage_name, stage_timeout in ( - ("profiling_timeout_seconds", profiling_timeout_seconds), - ("validation_timeout_seconds", validation_timeout_seconds), - ): - if stage_timeout is not None and ( - stage_timeout <= 0 or not math.isfinite(stage_timeout) - ): - raise ValueError(f"{stage_name} must be positive when specified") - if generation_timeout_seconds is not None and phase_channel is None: - raise ValueError( - "generation_timeout_seconds requires an authenticated phase_channel" - ) - if ( - profiling_timeout_seconds is not None - or validation_timeout_seconds is not None - or generation_guard_includes_preparation - ) and phase_channel is None: - raise ValueError("stage limits require an authenticated phase_channel") - if max_rss_bytes is not None and max_rss_bytes <= 0: - raise ValueError("max_rss_bytes must be positive when specified") - normalized_output_limits: tuple[tuple[Path, int], ...] = () - if output_file_limits: - observed_limits: list[tuple[Path, int]] = [] - for raw_path, raw_limit in output_file_limits.items(): - if ( - isinstance(raw_limit, bool) - or not isinstance(raw_limit, int) - or raw_limit <= 0 - ): - raise ValueError("output file limits must be positive") - observed_limits.append( - ( - Path(os.path.abspath(Path(raw_path).expanduser())), - int(raw_limit), - ) - ) - normalized_output_limits = tuple( - sorted(observed_limits, key=lambda item: os.fspath(item[0])) - ) - if minimum_free_disk_bytes is not None and ( - isinstance(minimum_free_disk_bytes, bool) - or not isinstance(minimum_free_disk_bytes, int) - or minimum_free_disk_bytes <= 0 - ): - raise ValueError( - "minimum_free_disk_bytes must be a positive integer when specified" - ) - if minimum_free_disk_bytes is not None and disk_probe_path is None: - disk_probe_path = working_directory or Path.cwd() - if disk_probe_path is not None: - disk_probe_path = disk_probe_path.expanduser().resolve(strict=True) - if not disk_probe_path.is_dir(): - raise ValueError("disk_probe_path must be a directory") - if interval_seconds <= 0: - raise ValueError("interval_seconds must be positive") - if termination_grace_seconds < 0: - raise ValueError("termination_grace_seconds must be non-negative") - if phase_state_startup_grace_seconds < 0: - raise ValueError("phase_state_startup_grace_seconds must be non-negative") - if stderr_limit_bytes <= 0: - raise ValueError("stderr_limit_bytes must be positive") - if working_directory is not None: - working_directory = working_directory.expanduser().resolve(strict=True) - if not working_directory.is_dir(): - raise ValueError("working_directory must be a directory") - - if ( - max_rss_bytes is not None - and physical_footprint_probe is None - and platform.system() == "Darwin" - and snapshotter is process_snapshot - ): - try: - darwin_probe = DarwinPhysicalFootprintProbe() - except WatchdogProbeError as error: - raise ResourceProbeError( - f"Darwin physical-footprint probe is unavailable: {error}" - ) from error - - def physical_footprint_probe( - pids: Collection[int], - ) -> Mapping[int, int]: - return darwin_probe(pids) - - started_at_utc = datetime.now(UTC).isoformat() - phase_monitor_started = clock() - popen_arguments: dict[str, object] = { - "start_new_session": True, - "env": _worker_environment( - environment_overrides, - scrub_import_environment=scrub_import_environment, - ), - } - if working_directory is not None: - popen_arguments["cwd"] = os.fspath(working_directory) - if capture_stderr: - popen_arguments["stderr"] = subprocess.PIPE - process = popen_factory(tuple(command), **popen_arguments) - if process_identity_probe is _process_identity and not isinstance( - process, subprocess.Popen - ): - # Injected protocol fakes have no relationship to host PIDs. Focused - # teardown tests opt in to an injected identity probe explicitly. - def unavailable_process_identity(_pid: int) -> _ProcessIdentity | None: - return None - - process_identity_probe = unavailable_process_identity - stderr_tail = _BoundedByteTail(stderr_limit_bytes) - stderr_stream = getattr(process, "stderr", None) if capture_stderr else None - stderr_thread: threading.Thread | None = None - if stderr_stream is not None: - stderr_thread = threading.Thread( - target=stderr_tail.drain, - args=(stderr_stream,), - name=f"worker-{process.pid}-stderr", - daemon=True, - ) - stderr_thread.start() - monitor = ResourceMonitor( - process.pid, - interval_seconds=interval_seconds, - snapshotter=snapshotter, - physical_footprint_probe=physical_footprint_probe, - clock=clock, - ) - reason: TerminationReason = "completed" - returncode: int | None = None - phase_state: WorkerPhaseState | None = None - phase_error: str | None = None - memory_limit_reason: str | None = None - output_limit_path: str | None = None - output_limit_bytes: int | None = None - observed_output_bytes: int | None = None - observed_free_disk_bytes: int | None = None - storage_stop = threading.Event() - storage_wakeup = threading.Event() - storage_lock = threading.Lock() - storage_violation: tuple[ - TerminationReason, - str | None, - int | None, - int | None, - int | None, - ] | None = None - consecutive_memory_probe_failures = 0 - pending_memory_probe_reason: str | None = None - tree_termination_requested = False - teardown_escalated = False - teardown_seconds = 0.0 - observed_member_pids = {process.pid} - observed_process_identities: dict[int, _ProcessIdentity] = {} - _capture_process_identities( - observed_process_identities, - (process.pid,), - process_identity_probe, - ) - - def terminate(selected_reason: TerminationReason) -> None: - nonlocal reason, returncode, tree_termination_requested - nonlocal teardown_escalated, teardown_seconds - if tree_termination_requested: - return - reason = selected_reason - tree_termination_requested = True - # Once output or free-disk containment has fired, an uncooperative - # writer must not receive another multi-second window in which to fill - # the host volume. The process still receives SIGTERM first, followed - # immediately by SIGKILL when it does not exit. - grace_seconds = ( - 0.0 - if selected_reason - in { - "output_limit", - "output_probe_error", - "disk_space_limit", - "disk_probe_error", - } - else termination_grace_seconds - ) - teardown = _terminate_worker( - process, - monitor=monitor, - process_identities=observed_process_identities, - grace_seconds=grace_seconds, - signaler=signaler, - clock=clock, - sleeper=sleeper, - observation_callback=observation_callback, - identity_probe=process_identity_probe, - ) - returncode = teardown.returncode - teardown_escalated = teardown.escalated - teardown_seconds = teardown.elapsed_seconds - - def probe_storage_safety() -> tuple[ - TerminationReason, - str | None, - int | None, - int | None, - int | None, - ] | None: - nonlocal observed_free_disk_bytes - for output_path, configured_limit in normalized_output_limits: - try: - output_size = output_path.stat().st_size - except FileNotFoundError: - continue - except OSError: - return ( - "output_probe_error", - os.fspath(output_path), - configured_limit, - None, - None, - ) - if output_size > configured_limit: - return ( - "output_limit", - os.fspath(output_path), - configured_limit, - output_size, - None, - ) - if minimum_free_disk_bytes is None: - return None - assert disk_probe_path is not None - try: - observed_free_disk_bytes = disk_free_probe(disk_probe_path) - if ( - isinstance(observed_free_disk_bytes, bool) - or not isinstance(observed_free_disk_bytes, int) - or observed_free_disk_bytes < 0 - ): - raise ValueError("free-disk probe returned an invalid value") - except (OSError, ValueError, OverflowError): - return ("disk_probe_error", None, None, None, None) - if observed_free_disk_bytes < minimum_free_disk_bytes: - return ( - "disk_space_limit", - None, - None, - None, - observed_free_disk_bytes, - ) - return None - - def record_storage_violation( - violation: tuple[ - TerminationReason, - str | None, - int | None, - int | None, - int | None, - ], - ) -> None: - nonlocal storage_violation - with storage_lock: - if storage_violation is None: - storage_violation = violation - storage_wakeup.set() - - def pending_storage_violation() -> tuple[ - TerminationReason, - str | None, - int | None, - int | None, - int | None, - ] | None: - with storage_lock: - return storage_violation - - def capture_storage_violation( - violation: tuple[ - TerminationReason, - str | None, - int | None, - int | None, - int | None, - ], - ) -> TerminationReason: - nonlocal output_limit_path, output_limit_bytes - nonlocal observed_output_bytes, observed_free_disk_bytes - ( - selected_reason, - output_limit_path, - output_limit_bytes, - observed_output_bytes, - violation_free_disk_bytes, - ) = violation - if violation_free_disk_bytes is not None: - observed_free_disk_bytes = violation_free_disk_bytes - return selected_reason - - def apply_storage_violation( - violation: tuple[ - TerminationReason, - str | None, - int | None, - int | None, - int | None, - ], - ) -> None: - selected_reason = capture_storage_violation(violation) - exit_code = process.poll() - if exit_code is not None and exit_code != 0: - classify_process_exit(exit_code, now_seconds=clock()) - return - terminate(selected_reason) - - def watch_storage_safety() -> None: - while not storage_stop.wait(DEFAULT_STORAGE_SAFETY_INTERVAL_SECONDS): - violation = probe_storage_safety() - if violation is not None: - record_storage_violation(violation) - return - - storage_thread: threading.Thread | None = None - if normalized_output_limits or minimum_free_disk_bytes is not None: - storage_thread = threading.Thread( - target=watch_storage_safety, - name=f"worker-{process.pid}-storage-guard", - daemon=True, - ) - storage_thread.start() - - def effective_generation_elapsed( - state: WorkerPhaseState, - *, - now_seconds: float, - wall_seconds: float, - ) -> float | None: - if not generation_guard_includes_preparation: - return state.generation_elapsed_seconds(now_seconds=now_seconds) - finished_ns = state.generation_finished_monotonic_ns - if finished_ns is None: - return wall_seconds - return max(finished_ns / 1_000_000_000 - phase_monitor_started, 0.0) - - def observe_phase(now_seconds: float) -> float: - nonlocal phase_state, phase_error - assert phase_channel is not None - try: - observed = read_worker_phase_state( - phase_channel, - expected_pid=process.pid, - ) - except FileNotFoundError: - observed_at_seconds = max(now_seconds, clock()) - if ( - phase_state is not None - or observed_at_seconds - phase_monitor_started - >= phase_state_startup_grace_seconds - ): - phase_error = "worker phase-state file is missing" - return observed_at_seconds - except WorkerPhaseStateError as error: - phase_error = str(error) - return max(now_seconds, clock()) - - # The dashboard callback and the authenticated file read both happen - # after the loop's initial sample. Validate worker timestamps against - # a clock captured after that read so a legitimate transition during - # a slow observation cannot appear spuriously in the future. - observed_at_seconds = max(now_seconds, clock()) - earliest_seconds = phase_monitor_started - interval_seconds - latest_seconds = observed_at_seconds + interval_seconds - observed_timestamps = ( - observed.transition_monotonic_ns, - observed.generation_started_monotonic_ns, - observed.generation_finished_monotonic_ns, - observed.profiling_started_monotonic_ns, - observed.profiling_finished_monotonic_ns, - observed.validation_started_monotonic_ns, - observed.validation_finished_monotonic_ns, - ) - if any( - timestamp is not None - and not (earliest_seconds <= timestamp / 1_000_000_000 <= latest_seconds) - for timestamp in observed_timestamps - ): - phase_error = ( - "worker phase-state transition timestamp is outside the " - "supervised process lifetime" - ) - return observed_at_seconds - if phase_state is not None: - if observed.sequence < phase_state.sequence: - phase_error = "worker phase-state sequence moved backwards" - return observed_at_seconds - if ( - observed.sequence == phase_state.sequence - and observed.sha256 != phase_state.sha256 - ): - phase_error = ( - "worker phase-state changed without advancing its sequence" - ) - return observed_at_seconds - for field in ( - "generation_started_monotonic_ns", - "generation_finished_monotonic_ns", - "profiling_started_monotonic_ns", - "profiling_finished_monotonic_ns", - "validation_started_monotonic_ns", - "validation_finished_monotonic_ns", - ): - prior_timestamp = getattr(phase_state, field) - if ( - prior_timestamp is not None - and getattr(observed, field) != prior_timestamp - ): - phase_error = f"worker {field} changed" - return observed_at_seconds - phase_state = observed - return observed_at_seconds - - def classify_process_exit( - exit_code: int, - *, - now_seconds: float, - zero_reason: TerminationReason = "completed", - ) -> None: - nonlocal returncode, reason, phase_error - returncode = exit_code - if phase_channel is not None: - observe_phase(now_seconds) - if phase_error is None and phase_state is None: - phase_error = "worker exited without authenticated phase-state evidence" - elif ( - phase_error is None - and phase_state is not None - and phase_state.phase == "generation" - ): - phase_error = "worker exited before closing its generation interval" - if exit_code != 0: - reason = "worker_exit" - elif phase_error is not None: - reason = "phase_state_error" - else: - reason = zero_reason - - def classify_process_exit_at_boundary( - exit_code: int, - *, - now_seconds: float, - zero_reason: TerminationReason = "completed", - ) -> None: - # A fast writer can cross its cap and exit between background storage - # samples. A synchronous final probe keeps a clean exit from hiding - # that violation. A genuine nonzero worker exit remains the primary - # outcome, while the storage evidence is still retained for diagnosis. - violation = pending_storage_violation() or probe_storage_safety() - if violation is not None: - selected_reason = capture_storage_violation(violation) - if exit_code == 0: - terminate(selected_reason) - return - classify_process_exit( - exit_code, - now_seconds=now_seconds, - zero_reason=zero_reason, - ) - - def wait_for_next_sample() -> None: - if storage_thread is None: - sleeper(interval_seconds) - else: - storage_wakeup.wait(timeout=interval_seconds) - - try: - while True: - if ( - violation := pending_storage_violation() or probe_storage_safety() - ) is not None: - apply_storage_violation(violation) - break - if cancellation_requested is not None and cancellation_requested(): - returncode = process.poll() - if returncode is None: - terminate("cancelled") - else: - classify_process_exit_at_boundary( - returncode, - now_seconds=clock(), - zero_reason="cancelled", - ) - break - if pending_memory_probe_reason is not None: - returncode = process.poll() - if returncode is not None: - classify_process_exit_at_boundary( - returncode, - now_seconds=clock(), - zero_reason="memory_probe_error", - ) - break - - usage = monitor.sample_once() - observed_member_pids.update(monitor.member_pids) - _capture_process_identities( - observed_process_identities, - monitor.member_pids, - process_identity_probe, - ) - now_seconds = clock() - if observation_callback is not None: - # Monitoring is deliberately informational. A broken - # dashboard must never invalidate a measurement. - with suppress(Exception): - observation_callback( - WorkerObservation( - pid=process.pid, - usage=usage, - phase=(None if phase_state is None else phase_state.phase), - phase_sequence=( - None if phase_state is None else phase_state.sequence - ), - member_pids=monitor.member_pids, - ) - ) - returncode = process.poll() - if returncode is not None: - classify_process_exit_at_boundary( - returncode, - now_seconds=now_seconds, - ) - break - if max_rss_bytes is not None and usage.memory_probe_reason is not None: - consecutive_memory_probe_failures += 1 - pending_memory_probe_reason = usage.memory_probe_reason - returncode = process.poll() - if returncode is not None: - classify_process_exit_at_boundary( - returncode, - now_seconds=now_seconds, - zero_reason="memory_probe_error", - ) - break - if ( - consecutive_memory_probe_failures - >= MAX_CONSECUTIVE_MEMORY_PROBE_FAILURES - ): - terminate("memory_probe_error") - break - wait_for_next_sample() - continue - if pending_memory_probe_reason is not None: - returncode = process.poll() - if returncode is not None: - classify_process_exit_at_boundary( - returncode, - now_seconds=now_seconds, - zero_reason="memory_probe_error", - ) - break - pending_memory_probe_reason = None - consecutive_memory_probe_failures = 0 - if ( - max_rss_bytes is not None - and usage.current_guard_bytes is not None - and usage.current_guard_bytes > max_rss_bytes - ): - physical = usage.current_physical_footprint_bytes - rss = usage.current_rss_bytes - memory_limit_reason = ( - DARWIN_PHYSICAL_FOOTPRINT_LIMIT_REASON - if physical is not None and rss is not None and physical >= rss - else RSS_LIMIT_REASON - ) - terminate("memory_limit") - break - if phase_channel is not None: - now_seconds = observe_phase(now_seconds) - if phase_error is not None: - returncode = process.poll() - if returncode is not None: - classify_process_exit_at_boundary( - returncode, - now_seconds=now_seconds, - zero_reason="phase_state_error", - ) - if returncode == 0 and not tree_termination_requested: - terminate("phase_state_error") - else: - terminate("phase_state_error") - break - if phase_state is not None: - if generation_timeout_seconds is not None: - generation_elapsed = effective_generation_elapsed( - phase_state, - now_seconds=now_seconds, - wall_seconds=usage.wall_seconds, - ) - if ( - generation_elapsed is not None - and generation_elapsed >= generation_timeout_seconds - ): - terminate("generation_timeout") - break - if ( - profiling_timeout_seconds is not None - and ( - profiling_elapsed := phase_state.stage_elapsed_seconds( - "profiling", - now_seconds=now_seconds, - ) - ) - is not None - and profiling_elapsed >= profiling_timeout_seconds - ): - terminate("profiling_timeout") - break - if ( - validation_timeout_seconds is not None - and ( - validation_elapsed := phase_state.stage_elapsed_seconds( - "validation", - now_seconds=now_seconds, - ) - ) - is not None - and validation_elapsed >= validation_timeout_seconds - ): - terminate("validation_timeout") - break - if timeout_seconds is not None and usage.wall_seconds >= timeout_seconds: - terminate("worker_timeout") - break - - returncode = process.poll() - if returncode is not None: - classify_process_exit_at_boundary( - returncode, - now_seconds=now_seconds, - ) - break - wait_for_next_sample() - finally: - storage_stop.set() - storage_wakeup.set() - if storage_thread is not None: - storage_thread.join(timeout=1.0) - if process.poll() is None and not tree_termination_requested: - teardown = _terminate_worker( - process, - monitor=monitor, - process_identities=observed_process_identities, - grace_seconds=termination_grace_seconds, - signaler=signaler, - clock=clock, - sleeper=sleeper, - observation_callback=observation_callback, - identity_probe=process_identity_probe, - ) - returncode = teardown.returncode - teardown_escalated = teardown.escalated - teardown_seconds = teardown.elapsed_seconds - elif not tree_termination_requested: - # ``poll`` reaps the root, but a daemonized/reparented descendant - # may still survive in the worker's process group. Do not return - # control to the scheduler until that known tree is gone. - returncode = process.wait() - descendant_teardown = _terminate_surviving_descendants( - process, - monitor=monitor, - grace_seconds=termination_grace_seconds, - signaler=signaler, - clock=clock, - sleeper=sleeper, - observation_callback=observation_callback, - identity_probe=process_identity_probe, - process_identities=observed_process_identities, - ) - teardown_escalated = teardown_escalated or descendant_teardown.escalated - teardown_seconds += descendant_teardown.elapsed_seconds - - if returncode is None: - returncode = process.wait() - observed_member_pids.update(monitor.member_pids) - if stderr_thread is not None: - stderr_thread.join(timeout=max(termination_grace_seconds, 1.0)) - if stderr_thread.is_alive() and stderr_stream is not None: - with suppress(OSError, ValueError): - stderr_stream.close() - stderr_thread.join(timeout=1.0) - supervisor_stderr, supervisor_stderr_truncated = stderr_tail.decoded() - signal_number = -returncode if returncode < 0 else None - signal_name: str | None = None - if signal_number is not None: - try: - signal_name = signal.Signals(signal_number).name - except ValueError: - signal_name = f"SIG{signal_number}" - generation_phase = None - if phase_channel is not None and generation_timeout_seconds is not None: - generation_phase = GenerationPhaseEvidence( - configured_timeout_seconds=generation_timeout_seconds, - supervisor_reason=reason, - authenticated=phase_state is not None and phase_error is None, - run_id=phase_channel.run_id, - worker_pid=process.pid, - final_sequence=None if phase_state is None else phase_state.sequence, - final_phase=None if phase_state is None else phase_state.phase, - generation_started_monotonic_ns=( - None - if phase_state is None - else phase_state.generation_started_monotonic_ns - ), - generation_finished_monotonic_ns=( - None - if phase_state is None - else phase_state.generation_finished_monotonic_ns - ), - generation_elapsed_seconds=( - None - if phase_state is None - else effective_generation_elapsed( - phase_state, - now_seconds=clock(), - wall_seconds=monitor.usage.wall_seconds, - ) - ), - final_state_sha256=(None if phase_state is None else phase_state.sha256), - error=phase_error, - ) - return SupervisedResult( - returncode=returncode, - reason=reason, - usage=monitor.usage, - generation_phase=generation_phase, - memory_limit_bytes=max_rss_bytes, - memory_limit_reason=memory_limit_reason, - output_limit_path=output_limit_path, - output_limit_bytes=output_limit_bytes, - observed_output_bytes=observed_output_bytes, - minimum_free_disk_bytes=minimum_free_disk_bytes, - observed_free_disk_bytes=observed_free_disk_bytes, - pid=process.pid, - member_pids=tuple(sorted(observed_member_pids)), - signal_number=signal_number, - signal_name=signal_name, - supervisor_stderr=supervisor_stderr, - supervisor_stderr_truncated=supervisor_stderr_truncated, - supervisor_stderr_limit_bytes=(stderr_limit_bytes if capture_stderr else None), - phase_state_error=phase_error, - started_at_utc=started_at_utc, - finished_at_utc=datetime.now(UTC).isoformat(), - teardown_escalated=teardown_escalated, - teardown_seconds=teardown_seconds, - ) - - -__all__ = [ - "DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES", - "DEFAULT_MINIMUM_FREE_DISK_BYTES", - "DEFAULT_PHASE_STATE_STARTUP_GRACE_SECONDS", - "DEFAULT_SAMPLE_INTERVAL_SECONDS", - "DEFAULT_STORAGE_SAFETY_INTERVAL_SECONDS", - "DEFAULT_SUPERVISOR_STDERR_LIMIT_BYTES", - "DEFAULT_TERMINATION_GRACE_SECONDS", - "GENERATION_PHASE_EVIDENCE_ABI", - "MAX_CONSECUTIVE_MEMORY_PROBE_FAILURES", - "PROCESS_TREE_MEMORY_METRIC_ABI", - "GenerationPhaseEvidence", - "ProcessRecord", - "ProcessTreeSample", - "ProcessTreeSampler", - "ResourceMonitor", - "ResourceProbeError", - "ResourceUsage", - "SupervisedResult", - "WorkerObservation", - "process_snapshot", - "supervise_worker", -] diff --git a/pyamplicol/tools/performance_report/runner.py b/pyamplicol/tools/performance_report/runner.py deleted file mode 100644 index 41de47f486..0000000000 --- a/pyamplicol/tools/performance_report/runner.py +++ /dev/null @@ -1,5499 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Direct Python-API generation, profiling, and validation for report cells.""" - -from __future__ import annotations - -import hashlib -import importlib -import importlib.resources -import io -import json -import math -import os -import platform -import re -import stat -import statistics -import time -import tomllib -from collections.abc import Callable, Mapping, Sequence -from contextlib import nullcontext -from dataclasses import dataclass, replace -from decimal import Decimal, InvalidOperation -from pathlib import Path, PurePosixPath -from typing import TYPE_CHECKING, Protocol - -if TYPE_CHECKING: - from pyamplicol.config import BenchmarkConfig - from pyamplicol.reporting import ProgressSink - -from .arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - ARENA_PROFILE_PROTOCOL, - ARENA_PROFILE_SAMPLE_PASS, - PAIRED_TIMING_SAMPLE_CONTRACT, - ArenaProfileEvidenceError, - build_arena_profile_evidence, - digest_arena_profile_value, - validate_arena_profile_evidence, -) -from .models import ( - Accuracy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .phase_state import WorkerPhaseReporter -from .runtime_evidence import ( - RuntimeEvidenceError, - established_preimport_runtime_identity, - loaded_pyamplicol_origin_policy, - python_package_tree_identity, -) -from .selector_policy import ( - SelectorPolicyError, - canonical_lc_flow_word, - canonical_lc_selector_word, - fixed_selector_helicity, - selector_color_flow_id, - selector_helicity_id, -) -from .timing import ( - ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI, - EVALUATOR_TOTAL_SAMPLE_CONTRACT, - EVALUATOR_TOTAL_TIMING_ABI, - EVALUATOR_TOTAL_TIMING_KEY, - EVALUATOR_TOTAL_TIMING_SOURCE, - MEASURED_EXECUTION_TIMING_ABI, - UNAVAILABLE_STATUS, - evaluator_total_timing_record, -) - -RELATIVE_TOLERANCE = 1.0e-12 -INDEPENDENT_RELATIVE_TOLERANCE = 1.0e-8 -MADGRAPH_RELATIVE_TOLERANCE = 1.0e-10 -ABSOLUTE_TOLERANCE = 1.0e-15 -CONDITIONED_COMPARISON_ABI = "pyamplicol-report-conditioned-comparison-v2" -RESOLVED_SUM_VALIDATION_ABI = "pyamplicol-report-resolved-sum-validation-v2" -RESOLVED_COMPONENT_SCALE_ABI = "pyamplicol-report-resolved-component-scale-v1" -OTF_RECURRENCE_AUTHORITY_VALIDATION_ABI = ( - "pyamplicol-report-on-the-fly-recurrence-authority-validation-v1" -) -OTF_RECURRENCE_AUTHORITY_VALIDATION_FIELD = "on_the_fly_recurrence_authority" -OTF_COLD_WARMUP_FIELDS = frozenset( - { - "cold_warmup_elapsed_seconds", - "cold_warmup_run_count", - "cold_warmup_batch_size", - "cold_warmup_point_count", - "cold_warmup_timer_source", - "cold_warmup_timing_scope", - "cold_warmup_runtime_freshness", - "cold_warmup_runtime_state_evidence", - "cold_warmup_runtime_state_before", - "cold_warmup_runtime_state_after", - "cold_warmup_runtime_cold_before_first_evaluation", - "cold_warmup_runtime_retained_before_first_evaluation", - "cold_warmup_runtime_retained_after_first_evaluation", - "cold_warmup_ratio_eligible", - "cold_warmup_acceptance_eligible", - } -) -CONVENTIONAL_WARMUP_FIELDS = frozenset( - { - "warmup_elapsed_seconds", - "warmup_configured_run_count", - "warmup_batch_size", - "warmup_point_count", - "warmup_run_outer_wall_seconds", - "first_warmup_run_outer_wall_seconds", - "warmup_timer_source", - "warmup_timing_scope", - } -) -WARMUP_TIMER_SOURCE = "python_outer_time.perf_counter" -OTF_COLD_WARMUP_TIMING_SCOPE = ( - "one initial requested-selector Runtime evaluation on the full benchmark " - "batch; artifact generation and Runtime/artifact load are excluded" -) -OTF_COLD_WARMUP_RUNTIME_FRESHNESS = "authenticated-cold" -OTF_COLD_WARMUP_RUNTIME_RETAINED_FRESHNESS = "authenticated-already-retained" -OTF_COLD_WARMUP_RUNTIME_FRESHNESSES = frozenset( - { - OTF_COLD_WARMUP_RUNTIME_FRESHNESS, - OTF_COLD_WARMUP_RUNTIME_RETAINED_FRESHNESS, - } -) -OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE = "authenticated-native-otf-census-v1" -OTF_RUNTIME_STATE_CENSUS_KIND = "rusticol-on-the-fly-runtime-state-census-v1" -OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY = "last-family-only" -OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT = 1 -OTF_RUNTIME_STATE_COUNT_FIELDS = ( - "process_preparation_count", - "retained_family_count", - "pending_family_count", - "retained_selection_count", - "retained_request_count", - "retained_amplitude_destination_count", - "retained_executor_handle_count", - "retained_query_local_trace_count", - "retained_embedded_lookup_key_count", - "semantic_executor_binding_count", -) -OTF_RUNTIME_STATE_RETAINED_BASE_POSITIVE_FIELDS = ( - "process_preparation_count", - "retained_family_count", - "retained_selection_count", - "retained_request_count", -) -OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS = ( - "retained_amplitude_destination_count", - "retained_executor_handle_count", - "semantic_executor_binding_count", -) -OTF_ACTIVE_FAMILY_COUNT_FIELDS = ( - "query_count", - "union_unique_current_count", - "union_unique_current_component_count", - "union_source_rows", - "union_contribution_rows", - "union_finalization_rows", - "union_closure_rows", - "union_amplitude_destination_count", - "union_source_executor_call_groups", - "union_contribution_executor_call_groups", - "union_finalization_executor_call_groups", - "union_closure_executor_call_groups", -) -OTF_OPERATION_ROLES = ("source", "contribution", "finalization", "closure") -CONVENTIONAL_WARMUP_TIMING_SCOPE = ( - "configured benchmark warm-up iteration outer wall; includes the headline " - "evaluation and optional native-profile warm-up; artifact generation and " - "Runtime/artifact load are excluded" -) -_SHA256_PATTERN = re.compile(r"[0-9a-f]{64}") -GENERATION_VALIDATION_SEED = 12345 -DEFAULT_TARGET_RUNTIME_SECONDS = 5.0 -REPORT_BENCHMARK_BATCH_SIZE = 128 -REPORT_BENCHMARK_WARMUP_RUNS = 2 -_ARENA_MINIMUM_SAMPLES = 5 -_ARENA_MAX_SAMPLES = 64 -_ARENA_MAX_CALIBRATION_BLOCKS = 4 -_ARENA_MAX_REPETITIONS = 1_000_000_000 -_ARENA_MINIMUM_TARGET_FRACTION = 0.95 -_MIB = 1024 * 1024 -_RECURRENCE_DIRECT_TEMPLATE_ABI = "pyamplicol-recurrence-direct-template-v1" -_RECURRENCE_DIRECT_BACKEND_ABI = "rusticol.recurrence-direct-backend.v1" -_RECURRENCE_DIRECT_CANONICALIZATION_ABI = "pyamplicol-canonical-json-v1" -_RECURRENCE_DIRECT_PAYLOAD_BINDING_ABI = "pyamplicol-recurrence-plane-binding-v2" -_SYMJIT_APPLICATION_ABI = "symjit-application-storage-v3" -_SYMJIT_PLANE_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -_RECURRENCE_JIT_SOURCE_APPLICATION_ABI = _SYMJIT_PLANE_APPLICATION_ABI -_RECURRENCE_JIT_DIRECT_APPLICATION_ABI = "pyamplicol-symjit-plane-application-v2" -_RECURRENCE_JIT_SOURCE_RUNTIME_CAPABILITY = "symjit.application.complex-f64.v1" - -# These labels make the public-command boundary, and its two report-only -# exceptions, explicit in returned generation/profile evidence. -PUBLIC_CLI_COMMAND_PATH = "pyamplicol-cli-parse-resolve-dispatch-v1" -LOADED_RUNTIME_PROFILE_COMMAND_PATH = ( - "pyamplicol-profile-loaded-runtime-and-points-injection-v1" -) -PAIRED_ARENA_PROFILE_COMMAND_PATH = "pyamplicol-report-private-paired-arena-profile-v1" -PRECOMPILED_GENERATION_COMMAND_PATH = ( - "pyamplicol-generate-precompiled-model-injection-v1" -) - - -class RunnerError(RuntimeError): - """Raised when a cell cannot satisfy the report measurement contract.""" - - -class ProfilingTimeLimitError(RunnerError): - """Raised before a profiling chunk cannot fit its remaining stage budget.""" - - -ProfilingChunkGuard = Callable[[float | None, str], None] - - -def profiling_chunk_guard( - deadline_monotonic: float | None, - *, - clock: Callable[[], float] | None = None, -) -> ProfilingChunkGuard | None: - """Return a cheap pre-launch guard for one absolute profiling deadline.""" - - if deadline_monotonic is None: - return None - if not math.isfinite(deadline_monotonic) or deadline_monotonic <= 0.0: - raise ValueError("profiling deadline must be finite and positive") - selected_clock = time.monotonic if clock is None else clock - - def guard(estimated_seconds: float | None, description: str) -> None: - if not isinstance(description, str) or not description: - raise ValueError("profiling chunk description must be non-empty") - if estimated_seconds is not None and ( - not math.isfinite(estimated_seconds) or estimated_seconds < 0.0 - ): - raise ValueError("profiling chunk estimate must be finite and non-negative") - remaining = deadline_monotonic - selected_clock() - if remaining <= 0.0 or ( - estimated_seconds is not None and estimated_seconds > remaining - ): - estimate = ( - "unknown" if estimated_seconds is None else f"{estimated_seconds:.6g}s" - ) - raise ProfilingTimeLimitError( - "profiling stage has insufficient remaining budget for " - f"{description}: remaining={max(remaining, 0.0):.6g}s, " - f"estimated={estimate}" - ) - - return guard - - -@dataclass(frozen=True, slots=True) -class RunnerSettings: - target_runtime_seconds: float = DEFAULT_TARGET_RUNTIME_SECONDS - batch_size: int = REPORT_BENCHMARK_BATCH_SIZE - worker_cores: int = 1 - memory_limit_bytes: int | None = None - warmup_runs: int = REPORT_BENCHMARK_WARMUP_RUNS - minimum_samples: int = 5 - model_cache_dir: Path | None = None - progress: ProgressSink | None = None - source_revision_override: str | None = None - profiling_time_limit_seconds: float | None = None - worker_deadline_monotonic: float | None = None - - def __post_init__(self) -> None: - if self.target_runtime_seconds <= 0.0: - raise ValueError("target_runtime_seconds must be positive") - if self.batch_size < 1: - raise ValueError("batch_size must be positive") - if self.worker_cores < 1: - raise ValueError("worker_cores must be positive") - if self.memory_limit_bytes is not None and ( - isinstance(self.memory_limit_bytes, bool) - or not isinstance(self.memory_limit_bytes, int) - or self.memory_limit_bytes < _MIB - ): - raise ValueError("memory_limit_bytes must be at least one MiB") - if self.warmup_runs < 0: - raise ValueError("warmup_runs must be non-negative") - if self.minimum_samples < _ARENA_MINIMUM_SAMPLES: - raise ValueError( - f"minimum_samples must be at least {_ARENA_MINIMUM_SAMPLES}" - ) - if self.progress is not None and not callable( - getattr(self.progress, "emit", None) - ): - raise TypeError("progress must implement ProgressSink.emit(event)") - if ( - self.source_revision_override is not None - and not self.source_revision_override - ): - raise ValueError("source_revision_override must be non-empty") - for name, value in ( - ("profiling_time_limit_seconds", self.profiling_time_limit_seconds), - ("worker_deadline_monotonic", self.worker_deadline_monotonic), - ): - if value is not None and (not math.isfinite(value) or value <= 0.0): - raise ValueError(f"{name} must be finite and positive when specified") - - -@dataclass(frozen=True, slots=True) -class SelectorContract: - selected_color_flow_ids: tuple[str, ...] - selected_color_words: tuple[tuple[int, ...], ...] - all_flow_helicity_ids: tuple[str, ...] - all_flow_source_helicities: tuple[tuple[int, int], ...] - point_digest: str - - def __post_init__(self) -> None: - if not self.selected_color_flow_ids: - raise ValueError("selector contract requires a selected color flow") - if len(self.selected_color_flow_ids) != len(self.selected_color_words): - raise ValueError("color-flow IDs and words must have equal length") - if len(set(self.selected_color_flow_ids)) != len(self.selected_color_flow_ids): - raise ValueError("selector contract color-flow IDs must be unique") - if len(self.all_flow_helicity_ids) != 1: - raise ValueError("selector contract requires one fixed helicity") - if not self.all_flow_source_helicities: - raise ValueError("selector contract requires source helicities") - if len(self.point_digest) != 64: - raise ValueError("selector contract point digest must be SHA-256") - - def as_dict(self) -> dict[str, object]: - return { - "selected_color_flow_ids": list(self.selected_color_flow_ids), - "selected_color_words": [list(word) for word in self.selected_color_words], - "all_flow_helicity_ids": list(self.all_flow_helicity_ids), - "all_flow_source_helicities": { - str(label): value for label, value in self.all_flow_source_helicities - }, - "point_digest": self.point_digest, - } - - @property - def runtime_all_flow_helicity_ids(self) -> tuple[str, ...]: - """Return exact public runtime IDs for the stored physical states. - - Historical original-AmpliCol contracts encoded a zero-helicity state as - ``0`` while generated runtime axes use the canonical signed spelling - ``+0``. Treat only that textual alias as equivalent: the parsed ID must - reproduce every stored source state before it is canonicalized. - """ - - states = tuple( - state for _label, state in sorted(self.all_flow_source_helicities) - ) - resolved: list[str] = [] - for identifier in self.all_flow_helicity_ids: - if not identifier.startswith("h:"): - resolved.append(identifier) - continue - try: - encoded = tuple( - int(token) for token in identifier.removeprefix("h:").split(",") - ) - except ValueError: - resolved.append(identifier) - continue - if encoded != states: - resolved.append(identifier) - continue - resolved.append("h:" + ",".join(f"{state:+d}" for state in states)) - return tuple(resolved) - - @classmethod - def from_mapping(cls, value: Mapping[str, object]) -> SelectorContract: - raw_ids = value.get("selected_color_flow_ids") - raw_words = value.get("selected_color_words") - raw_helicities = value.get("all_flow_helicity_ids") - raw_sources = value.get("all_flow_source_helicities") - point_digest = value.get("point_digest") - if ( - not isinstance(raw_ids, Sequence) - or isinstance(raw_ids, (str, bytes)) - or not isinstance(raw_words, Sequence) - or isinstance(raw_words, (str, bytes)) - or not isinstance(raw_helicities, Sequence) - or isinstance(raw_helicities, (str, bytes)) - or not isinstance(raw_sources, Mapping) - or not isinstance(point_digest, str) - ): - raise ValueError("selector contract has an invalid shape") - return cls( - selected_color_flow_ids=tuple(str(item) for item in raw_ids), - selected_color_words=tuple( - tuple(int(label) for label in word) # type: ignore[arg-type] - for word in raw_words - ), - all_flow_helicity_ids=tuple(str(item) for item in raw_helicities), - all_flow_source_helicities=tuple( - sorted((int(label), int(state)) for label, state in raw_sources.items()) - ), - point_digest=point_digest, - ) - - -@dataclass(frozen=True, slots=True) -class GeneratedArtifact: - path: Path - process_id: str - generation_seconds: float - model_preparation_seconds: float - model_preparation_reused: bool - requested_config: Mapping[str, object] - effective_config: Mapping[str, object] - generation_command_path: str | None = None - numerical_relation_correctness: Mapping[str, object] | None = None - numerical_relation_fallback: Mapping[str, object] | None = None - - -class RuntimeLike(Protocol): - @property - def physics(self) -> object: ... - - def evaluate( - self, - momenta: object, - *, - helicities: Sequence[str] | None = None, - color_flows: Sequence[str] | None = None, - precision: int = 16, - ) -> Sequence[object]: ... - - def evaluate_resolved( - self, - momenta: object, - *, - helicities: Sequence[str] | None = None, - color_flows: Sequence[str] | None = None, - precision: int = 16, - ) -> object: ... - - def clear(self) -> None: ... - - -def _canonical_json(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - default=lambda item: item.tolist(), - ).encode("ascii") - - -def _regular_file_identity(path: Path) -> tuple[int, str]: - """Hash one unchanged regular file through a single no-follow descriptor.""" - - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_NOFOLLOW", 0) - | getattr(os, "O_BINARY", 0) - ) - digest = hashlib.sha256() - descriptor: int | None = None - try: - descriptor = os.open(path, flags) - before = os.fstat(descriptor) - if not stat.S_ISREG(before.st_mode): - raise RunnerError(f"identity target is not a regular file: {path}") - byte_count = 0 - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - byte_count += len(block) - after = os.fstat(stream.fileno()) - except OSError as error: - raise RunnerError( - f"cannot hash regular file through a checked fd: {path}" - ) from error - finally: - if descriptor is not None: - os.close(descriptor) - stable_fields = ( - "st_dev", - "st_ino", - "st_mode", - "st_size", - "st_mtime_ns", - "st_ctime_ns", - ) - if byte_count != before.st_size or any( - getattr(before, name) != getattr(after, name) for name in stable_fields - ): - raise RunnerError(f"identity target changed while it was hashed: {path}") - return byte_count, digest.hexdigest() - - -def _sha256_file(path: Path) -> str: - return _regular_file_identity(path)[1] - - -def point_digest(points: object) -> str: - return hashlib.sha256(_canonical_json(points)).hexdigest() - - -def _scale_decimal(value: object) -> Decimal: - """Return one finite non-negative magnitude without binary64 accumulation.""" - - try: - magnitude = abs(value) # type: ignore[arg-type] - decimal = Decimal(str(magnitude)) - except (InvalidOperation, TypeError, ValueError) as error: - raise RunnerError("resolved component magnitude is not numeric") from error - if not decimal.is_finite() or decimal < 0: - raise RunnerError("resolved component magnitude is not finite") - return decimal - - -def _resolved_l1(value: object) -> Decimal: - to_list = getattr(value, "tolist", None) - if callable(to_list): - value = to_list() - if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)): - return sum((_resolved_l1(item) for item in value), Decimal(0)) - return _scale_decimal(value) - - -def _exact_number_text(value: object) -> str: - """Serialize a real component deterministically for a source binding.""" - - if isinstance(value, bool): - raise RunnerError("resolved component is boolean") - if isinstance(value, float): - if not math.isfinite(value): - raise RunnerError("resolved component is not finite") - return value.hex() - number = float(value) # validates arbitrary-precision real values cheaply - if not math.isfinite(number): - raise RunnerError("resolved component is not finite") - return str(value) - - -def _resolved_component_payload(value: object) -> object: - to_list = getattr(value, "tolist", None) - if callable(to_list): - value = to_list() - if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)): - return [_resolved_component_payload(item) for item in value] - real = getattr(value, "real", value) - imag = getattr(value, "imag", 0) - if callable(real): - real = real() - if callable(imag): - imag = imag() - return {"real": _exact_number_text(real), "imag": _exact_number_text(imag)} - - -def resolved_component_scale_evidence( - resolved: object, - points: object, -) -> dict[str, object]: - """Bind per-point L1 scales to exact axes, ordering, values and momenta.""" - - values = getattr(resolved, "values", None) - to_list = getattr(values, "tolist", None) - if callable(to_list): - values = to_list() - if not isinstance(values, Sequence) or not values: - raise RunnerError("resolved evaluation does not expose point components") - helicity_ids = tuple(str(item) for item in getattr(resolved, "helicity_ids", ())) - color_flow_ids = tuple(str(item) for item in getattr(resolved, "color_ids", ())) - ordered = { - "helicity_ids": list(helicity_ids), - "color_flow_ids": list(color_flow_ids), - "values": _resolved_component_payload(values), - } - source_digest = hashlib.sha256(_canonical_json(ordered)).hexdigest() - ordering_digest = hashlib.sha256( - _canonical_json( - { - "helicity_ids": list(helicity_ids), - "color_flow_ids": list(color_flow_ids), - } - ) - ).hexdigest() - scales: list[float] = [] - for point_values in values: - scale = float(_resolved_l1(point_values)) - if not math.isfinite(scale) or scale < 0.0: - raise RunnerError("resolved component L1 scale is not finite") - scales.append(scale) - return { - "abi": RESOLVED_COMPONENT_SCALE_ABI, - "point_digest": point_digest(points), - "helicity_ids": list(helicity_ids), - "color_flow_ids": list(color_flow_ids), - "resolved_ordering_sha256": ordering_digest, - "resolved_source_sha256": source_digest, - "scales": scales, - } - - -def validate_conditioned_comparison_record( - value: object, - *, - require_binding: bool, -) -> None: - """Authenticate a v2 conditioned comparison or a safely reusable v1 row.""" - - if not isinstance(value, Mapping): - raise ValueError("conditioned comparison must be an object") - if value.get("abi") != CONDITIONED_COMPARISON_ABI: - # Schema-free v1 rows can be reused only when the stored numbers - # recompute and satisfy the symmetric, floor-free criterion. - expected_v1 = { - "status", - "candidate", - "baseline", - "absolute_difference", - "relative_difference", - "relative_tolerance", - "absolute_tolerance", - } - if set(value) != expected_v1: - raise ValueError("conditioned comparison ABI is unsupported") - numeric: dict[str, float] = {} - for field in expected_v1 - {"status"}: - raw = value.get(field) - if ( - isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - ): - raise ValueError(f"legacy comparison {field} is not finite") - numeric[field] = float(raw) - delta = abs(numeric["candidate"] - numeric["baseline"]) - relative = delta / max(abs(numeric["baseline"]), 1.0e-300) - old_passed = ( - delta <= numeric["absolute_tolerance"] - or relative <= numeric["relative_tolerance"] - ) - safe = delta <= numeric["relative_tolerance"] * max( - abs(numeric["candidate"]), abs(numeric["baseline"]) - ) - expected_status = ( - ResultStatus.OK.value - if old_passed - else ResultStatus.VALIDATION_FAILED.value - ) - if numeric["absolute_difference"] != delta: - raise ValueError("legacy absolute difference was not recomputed") - if numeric["relative_difference"] != relative: - raise ValueError("legacy relative difference was not recomputed") - if value.get("status") != expected_status: - raise ValueError("legacy comparison status is inconsistent") - if expected_status == ResultStatus.OK.value and not safe: - raise ValueError("legacy comparison is not safely reusable") - return - - expected_v2 = { - "abi", - "status", - "candidate", - "baseline", - "candidate_scale", - "baseline_scale", - "candidate_scale_source", - "baseline_scale_source", - "comparison_scale", - "absolute_difference", - "relative_difference", - "conditioned_residual", - "error_bound", - "relative_tolerance", - "comparison_binding", - } - if set(value) != expected_v2: - raise ValueError("conditioned comparison fields differ from the v2 ABI") - numeric = {} - for field in ( - "candidate", - "baseline", - "candidate_scale", - "baseline_scale", - "comparison_scale", - "absolute_difference", - "relative_difference", - "conditioned_residual", - "error_bound", - "relative_tolerance", - ): - raw = value.get(field) - if ( - isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - ): - raise ValueError(f"conditioned comparison {field} is not finite") - numeric[field] = float(raw) - if any( - numeric[field] < 0.0 - for field in ( - "candidate_scale", - "baseline_scale", - "comparison_scale", - "absolute_difference", - "relative_difference", - "conditioned_residual", - "error_bound", - "relative_tolerance", - ) - ): - raise ValueError("conditioned comparison contains a negative magnitude") - for field in ("candidate_scale_source", "baseline_scale_source"): - raw = value.get(field) - if not isinstance(raw, str) or not raw: - raise ValueError(f"conditioned comparison {field} is invalid") - binding = value.get("comparison_binding") - if require_binding and (not isinstance(binding, Mapping) or not binding): - raise ValueError("conditioned comparison is not bound to its source") - if binding is not None and not isinstance(binding, Mapping): - raise ValueError("conditioned comparison binding is invalid") - if require_binding: - assert isinstance(binding, Mapping) - point_identity = binding.get("point_digest") - if not isinstance(point_identity, str) or not _SHA256_PATTERN.fullmatch( - point_identity - ): - raise ValueError("conditioned comparison point binding is invalid") - if binding.get("abi") == RESOLVED_COMPONENT_SCALE_ABI: - for field in ("resolved_ordering_sha256", "resolved_source_sha256"): - raw_digest = binding.get(field) - if not isinstance(raw_digest, str) or not _SHA256_PATTERN.fullmatch( - raw_digest - ): - raise ValueError( - f"conditioned comparison {field} binding is invalid" - ) - else: - expected_binding_fields = { - "point_digest", - "selector_component_identity", - "selector_component_sha256", - "candidate_source_sha256", - "baseline_source_sha256", - } - if set(binding) != expected_binding_fields: - raise ValueError("conditioned comparison source binding fields differ") - selector_identity = binding.get("selector_component_identity") - if not isinstance(selector_identity, Mapping) or not selector_identity: - raise ValueError( - "conditioned comparison selector/component binding is invalid" - ) - expected_selector_digest = hashlib.sha256( - _canonical_json(selector_identity) - ).hexdigest() - if binding.get("selector_component_sha256") != expected_selector_digest: - raise ValueError( - "conditioned comparison selector/component digest differs" - ) - for field in ("candidate_source_sha256", "baseline_source_sha256"): - raw_digest = binding.get(field) - if not isinstance(raw_digest, str) or not _SHA256_PATTERN.fullmatch( - raw_digest - ): - raise ValueError( - f"conditioned comparison {field} binding is invalid" - ) - candidate = numeric["candidate"] - baseline = numeric["baseline"] - candidate_scale = numeric["candidate_scale"] - baseline_scale = numeric["baseline_scale"] - if candidate_scale < abs(candidate) or baseline_scale < abs(baseline): - raise ValueError("conditioned comparison scale is below its value") - delta = abs(candidate - baseline) - raw_relative = delta / max(abs(baseline), 1.0e-300) - scale = max(abs(candidate), abs(baseline), candidate_scale, baseline_scale) - if scale == 0.0: - if candidate != 0.0 or baseline != 0.0 or delta != 0.0: - raise ValueError("zero scale comparison contains a nonzero value") - residual = 0.0 - else: - residual = delta / scale - bound = numeric["relative_tolerance"] * scale - status = ( - ResultStatus.OK.value - if delta <= bound - else ResultStatus.VALIDATION_FAILED.value - ) - if ( - numeric["comparison_scale"] != scale - or numeric["absolute_difference"] != delta - or numeric["relative_difference"] != raw_relative - or numeric["conditioned_residual"] != residual - or numeric["error_bound"] != bound - or value.get("status") != status - ): - raise ValueError("conditioned comparison numerical evidence is inconsistent") - - -def _real_nonnegative(value: object) -> float: - number = complex(value) - if not math.isfinite(number.real) or not math.isfinite(number.imag): - raise RunnerError("matrix element is not finite") - if abs(number.imag) > 1.0e-9 * max(abs(number.real), 1.0): - raise RunnerError( - f"matrix element has a non-negligible imaginary part: {value}" - ) - result = float(number.real) - if result < -ABSOLUTE_TOLERANCE: - raise RunnerError(f"matrix element is materially negative: {value}") - return max(result, 0.0) - - -def _model_source_path(repo_root: Path, model: ModelKey) -> Path | None: - if model is ModelKey.BUILTIN_SM: - return None - relative = { - ModelKey.UFO_SM: Path("sm/sm.json"), - ModelKey.SCALAR_CONTACT: Path("scalars/scalars.json"), - ModelKey.SCALAR_GRAVITY: Path("scalar_gravity/scalar_gravity.json"), - }.get(model) - if relative is None: - raise RunnerError(f"model {model.value!r} is not supported by process matrices") - source_path = repo_root / "src/pyamplicol/assets/models/json" / relative - if source_path.is_file(): - return source_path - resource = importlib.resources.files("pyamplicol").joinpath( - "assets", - "models", - "json", - *relative.parts, - ) - if not isinstance(resource, os.PathLike): - raise RunnerError("installed model resources are not filesystem-backed") - try: - return Path(os.fspath(resource)).resolve(strict=True) - except OSError as error: - raise RunnerError( - f"installed model resource is unavailable: {relative.as_posix()}" - ) from error - - -def config_values( - cell: CellSpec, - settings: RunnerSettings, - *, - repo_root: Path, -) -> dict[str, object]: - """Return complete generation/benchmark settings for one pyAmpliCol cell.""" - - measurement = cell.measurement - if measurement.execution_mode is ExecutionMode.AMPLICOL: - raise RunnerError("original AmpliCol does not use the pyAmpliCol runner") - if measurement.model is None: - raise RunnerError("pyAmpliCol measurement requires an explicit model") - on_the_fly = measurement.execution_mode is ExecutionMode.ON_THE_FLY - if on_the_fly and ( - measurement.backend != "jit" or measurement.jit_optimization_level != 2 - ): - raise RunnerError("on-the-fly campaign measurements require prepared JIT O2") - model_path = _model_source_path(repo_root, measurement.model) - layout = ( - "topology-replay" - if on_the_fly - else ( - "all-flow-union" - if cell.workload is Workload.ALL_FLOW - else "topology-replay" - ) - ) - values: dict[str, object] = { - "model": { - "source": "built-in-sm" if model_path is None else os.fspath(model_path), - "cache": True, - "cache_dir": ( - None - if settings.model_cache_dir is None - else os.fspath(settings.model_cache_dir) - ), - }, - "color": { - "accuracy": measurement.accuracy.value, - "lc_flow_layout": layout, - }, - "generation": { - "workers": settings.worker_cores, - "emit_api_bundle": not on_the_fly, - "validation": { - "enabled": not on_the_fly, - "samples": 1, - "seed": GENERATION_VALIDATION_SEED, - "relative_tolerance": RELATIVE_TOLERANCE, - "absolute_tolerance": 1.0e-300, - # The campaign immediately loads the artifact and performs its - # own resolved, high-precision, and authority validation. - "post_build_validation": False, - }, - # The published campaign protocol searches for certified numerical - # current reuse; it is explicit here because the package default - # is off. - "relation_discovery": {"mode": "off" if on_the_fly else "certified-reuse"}, - }, - "evaluator": { - "backend": measurement.backend, - "execution_mode": measurement.execution_mode.value, - "batch_size": settings.batch_size, - "output_chunk_size": 512, - "optimization": { - "horner_iterations": 10, - "cpe_iterations": None, - "cores": settings.worker_cores, - "max_horner_variables": 1000, - "max_common_pair_cache_entries": 5_000_000, - "max_common_pair_distance": 1000, - }, - "jit": { - "optimization_level": measurement.jit_optimization_level or 2, - }, - "cpp": {"optimization": "O3"}, - }, - "benchmark": { - "target_runtime": settings.target_runtime_seconds, - "batch_size": settings.batch_size, - "warmup_runs": settings.warmup_runs, - "minimum_samples": settings.minimum_samples, - }, - "output": {"format": "json", "progress": "off"}, - } - if settings.memory_limit_bytes is not None and measurement.execution_mode in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - }: - workspace_mib = settings.memory_limit_bytes // _MIB - evaluator = values["evaluator"] - assert isinstance(evaluator, dict) - evaluator[measurement.execution_mode.value] = {"workspace_mib": workspace_mib} - return values - - -def _cli_override_value(value: object) -> str: - """Encode one config leaf using the public ``--set`` value grammar.""" - - if value is None: - return "null" - if isinstance(value, Path): - value = os.fspath(value) - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - ) - - -def _cli_overrides( - values: Mapping[str, object], - *, - prefix: str = "", -) -> tuple[str, ...]: - """Flatten config values into deterministic public ``--set`` arguments.""" - - arguments: list[str] = [] - for key in sorted(values): - path = f"{prefix}.{key}" if prefix else key - value = values[key] - if isinstance(value, Mapping): - arguments.extend(_cli_overrides(value, prefix=path)) - continue - arguments.extend(("--set", f"{path}={_cli_override_value(value)}")) - return tuple(arguments) - - -def _generation_cli_argv( - cell: CellSpec, - destination: Path, - values: Mapping[str, object], -) -> tuple[str, ...]: - """Return the exact public ``pyamplicol generate`` argument vector.""" - - command_values = {key: value for key, value in values.items() if key != "process"} - output = command_values.get("output") - if isinstance(output, Mapping): - command_values["output"] = { - key: value for key, value in output.items() if key != "format" - } - return ( - "generate", - cell.process, - os.fspath(destination), - "--json", - *_cli_overrides(command_values), - ) - - -def _physics_ids(physics: object, name: str) -> tuple[str, ...]: - return tuple(str(item.id) for item in getattr(physics, name, ())) - - -def _on_the_fly_compact_context( - cell: CellSpec, - runtime: RuntimeLike, -) -> tuple[int, int]: - """Validate OTF process identity and return compact selector counts.""" - - backend = getattr(runtime, "_backend", runtime) - operation = getattr(backend, "_on_the_fly_benchmark_context", None) - if not callable(operation): - raise RunnerError("on-the-fly report runtime has no compact selector context") - try: - raw = operation(()) - except Exception as error: - raise RunnerError( - "on-the-fly report runtime compact selector context is unavailable" - ) from error - if not isinstance(raw, Mapping): - raise RunnerError( - "on-the-fly report runtime compact selector context is invalid" - ) - process_id = raw.get("process_id") - process_expression = raw.get("process_expression") - selected_color_ids = raw.get("selected_color_ids") - if ( - not isinstance(process_id, str) - or not process_id - or not isinstance(process_expression, str) - or process_expression.casefold() != cell.process.casefold() - or raw.get("color_accuracy") != cell.measurement.accuracy.value - or not isinstance(selected_color_ids, Sequence) - or isinstance(selected_color_ids, (str, bytes)) - or selected_color_ids - ): - raise RunnerError("on-the-fly report runtime compact selector identity differs") - counts: list[int] = [] - for field in ("helicity_count", "color_count"): - value = raw.get(field) - if isinstance(value, bool) or not isinstance(value, int) or value < 1: - raise RunnerError(f"on-the-fly report runtime compact {field} is invalid") - counts.append(value) - return counts[0], counts[1] - - -def _on_the_fly_selector_ordinals( - runtime: RuntimeLike, - values: Sequence[str], - *, - name: str, - count: int, -) -> tuple[int, ...]: - backend = getattr(runtime, "_backend", runtime) - operation = getattr(backend, "_point_selector_indices", None) - if not callable(operation): - raise RunnerError("on-the-fly report runtime has no compact selector resolver") - try: - raw = operation(values, name) - except Exception as error: - raise RunnerError(f"on-the-fly report runtime cannot resolve {name}") from error - if ( - not isinstance(raw, Sequence) - or isinstance(raw, (str, bytes)) - or len(raw) != len(values) - or any( - isinstance(value, bool) - or not isinstance(value, int) - or value < 0 - or value >= count - for value in raw - ) - or len(set(raw)) != len(raw) - ): - raise RunnerError(f"on-the-fly report runtime returned invalid {name} ordinals") - return tuple(raw) - - -def validate_runtime_contract(cell: CellSpec, runtime: RuntimeLike) -> None: - runtime_is_on_the_fly = ( - _runtime_execution_mode(runtime) == ExecutionMode.ON_THE_FLY.value - ) - cell_is_on_the_fly = cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - if runtime_is_on_the_fly: - if not cell_is_on_the_fly: - raise RunnerError("on-the-fly report runtime has the wrong execution mode") - _helicity_count, color_count = _on_the_fly_compact_context(cell, runtime) - if cell.measurement.accuracy is Accuracy.LC: - if cell.workload not in {Workload.SELECTED_FLOW, Workload.ALL_FLOW}: - raise RunnerError("LC on-the-fly measurement has an invalid workload") - elif ( - cell.measurement.accuracy not in {Accuracy.NLC, Accuracy.FULL} - or cell.workload is not Workload.CONTRACTED - or color_count != 1 - ): - raise RunnerError( - "contracted on-the-fly measurement has an invalid public color axis" - ) - return - if cell_is_on_the_fly: - raise RunnerError("on-the-fly report runtime has the wrong execution mode") - physics = runtime.physics - accuracy = str(getattr(physics, "color_accuracy", "")) - if accuracy != cell.measurement.accuracy.value: - raise RunnerError( - f"artifact color accuracy {accuracy!r} does not match " - f"{cell.measurement.accuracy.value!r}" - ) - capabilities = set(getattr(physics, "selector_capabilities", ())) - helicity_ids = _physics_ids(physics, "helicities") - if not helicity_ids: - raise RunnerError("artifact exposes no physical helicities") - if cell.measurement.accuracy is Accuracy.LC: - color_ids = _physics_ids(physics, "color_flows") - if not color_ids: - raise RunnerError("LC artifact exposes no physical color flows") - missing = {"helicity", "color_flow"} - capabilities - if missing: - raise RunnerError( - "LC artifact does not retain complete runtime selectors: " - + ", ".join(sorted(missing)) - ) - elif cell.workload is not Workload.CONTRACTED: - raise RunnerError("NLC/full measurements must use the contracted workload") - - -def validate_artifact_contract(cell: CellSpec, artifact_path: Path) -> None: - from pyamplicol._internal.versions import ( - COMPILED_PLANE_ARENA_RUNTIME_CAPABILITY, - EAGER_DIRECT_ARENA_RUNTIME_CAPABILITY, - ON_THE_FLY_CONTRACTED_COLOR_RUNTIME_CAPABILITY, - ON_THE_FLY_LC_COLOR_RUNTIME_CAPABILITY, - ON_THE_FLY_RUNTIME_CAPABILITY, - RECURRENCE_DIRECT_ARENA_RUNTIME_CAPABILITY, - ) - from pyamplicol.artifacts import inspect_artifact - - inspection = inspect_artifact(artifact_path) - if len(inspection.processes) != 1: - raise RunnerError("report artifacts must contain exactly one process") - process = inspection.processes[0] - if process.execution_mode != cell.measurement.execution_mode.value: - raise RunnerError( - f"artifact execution mode {process.execution_mode!r} does not match " - f"{cell.measurement.execution_mode.value!r}" - ) - if process.generation_specialized_axes: - raise RunnerError( - "report artifacts must retain complete runtime coverage; specialized " - f"axes: {process.generation_specialized_axes}" - ) - if process.selected_source_helicities or process.selected_color_sector_ids: - raise RunnerError("report artifact contains forbidden generation selectors") - expected_runtime_capability = { - ExecutionMode.COMPILED: COMPILED_PLANE_ARENA_RUNTIME_CAPABILITY, - ExecutionMode.EAGER: EAGER_DIRECT_ARENA_RUNTIME_CAPABILITY, - ExecutionMode.RECURRENCE: RECURRENCE_DIRECT_ARENA_RUNTIME_CAPABILITY, - ExecutionMode.ON_THE_FLY: ON_THE_FLY_RUNTIME_CAPABILITY, - }[cell.measurement.execution_mode] - runtime_capabilities = set(inspection.runtime_capabilities) - if expected_runtime_capability not in runtime_capabilities: - raise RunnerError( - "report artifact does not require its authenticated execution lane " - f"{expected_runtime_capability!r}" - ) - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY: - expected_color_capability = ( - ON_THE_FLY_LC_COLOR_RUNTIME_CAPABILITY - if cell.measurement.accuracy is Accuracy.LC - else ON_THE_FLY_CONTRACTED_COLOR_RUNTIME_CAPABILITY - ) - if len(inspection.runtime_capabilities) != 2 or runtime_capabilities != { - ON_THE_FLY_RUNTIME_CAPABILITY, - expected_color_capability, - }: - raise RunnerError( - "on-the-fly report artifact does not expose exactly its two " - "accuracy-specific runtime capabilities" - ) - if cell.measurement.accuracy is not Accuracy.LC and ( - cell.workload is not Workload.CONTRACTED - or process.recurrence_color_accuracy != cell.measurement.accuracy.value - or process.recurrence_color_storage != "expanded" - or process.recurrence_color_component_count != 1 - or process.recurrence_color_group_count is None - or process.recurrence_color_group_count < 1 - or process.recurrence_color_destination_count - != process.recurrence_color_group_count - ): - raise RunnerError( - "contracted on-the-fly report artifact has no authenticated " - "expanded color payload" - ) - if cell.measurement.accuracy is Accuracy.LC: - expected_layout = ( - "compact/query-local" - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - else ( - "all-flow-union" - if cell.workload is Workload.ALL_FLOW - else "topology-replay" - ) - ) - if process.lc_flow_layout != expected_layout: - raise RunnerError( - f"artifact LC layout {process.lc_flow_layout!r} does not match " - f"{expected_layout!r}" - ) - - -def runtime_identity_payload( - cell: CellSpec, - runtime: object, - artifact_path: Path, - process_id: str, - *, - expected_source_revision: str, -) -> dict[str, object]: - """Return the exact artifact/native-Arena identity used by one report cell.""" - - import pyamplicol - from pyamplicol._internal.versions import ( - COMPILED_PLANE_ARENA_RUNTIME_CAPABILITY, - COMPILED_PLANE_DIRECT_APPLICATION_ABI, - EAGER_DIRECT_ARENA_RUNTIME_CAPABILITY, - EAGER_DIRECT_TABLE_BINDING_ABI, - NATIVE_COMPILED_DIRECT_APPLICATION_ABI, - ON_THE_FLY_CONTRACTED_COLOR_RUNTIME_CAPABILITY, - ON_THE_FLY_LC_COLOR_RUNTIME_CAPABILITY, - ON_THE_FLY_RUNTIME_CAPABILITY, - RECURRENCE_DIRECT_ARENA_RUNTIME_CAPABILITY, - RECURRENCE_RUNTIME_LAYOUT_ABI, - SYMBOLICA_ASM_RUNTIME_CAPABILITY, - SYMBOLICA_CPP_RUNTIME_CAPABILITY, - SYMJIT_F64_RUNTIME_CAPABILITY, - SYMJIT_PLANE_APPLICATION_ABI, - _active_build_info, - verify_native_module, - ) - from pyamplicol.artifacts import load_manifest - - manifest = load_manifest(artifact_path, verify_payloads=False) - matches = [ - process for process in manifest.processes if process.get("id") == process_id - ] - if len(matches) != 1: - raise RunnerError( - f"report runtime process {process_id!r} is missing or ambiguous" - ) - process = matches[0] - loaded_artifact_id = getattr(runtime, "artifact_id", None) - if loaded_artifact_id != manifest.artifact_id: - raise RunnerError( - "native runtime loaded artifact identity does not match the report " - "artifact manifest" - ) - try: - loaded_execution_mode = runtime.execution_mode # type: ignore[attr-defined] - except Exception as exc: - raise RunnerError( - "native runtime does not expose an authenticated execution mode" - ) from exc - expected_execution_mode = cell.measurement.execution_mode.value - if loaded_execution_mode != expected_execution_mode: - raise RunnerError( - f"native runtime loaded execution mode {loaded_execution_mode!r} " - f"does not match the requested report mode {expected_execution_mode!r}" - ) - required_capabilities = tuple( - str(value) for value in process["required_runtime_capabilities"] - ) - on_the_fly_color_capability = ( - ON_THE_FLY_LC_COLOR_RUNTIME_CAPABILITY - if cell.measurement.accuracy is Accuracy.LC - else ON_THE_FLY_CONTRACTED_COLOR_RUNTIME_CAPABILITY - ) - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY and ( - len(required_capabilities) != 2 - or set(required_capabilities) - != { - ON_THE_FLY_RUNTIME_CAPABILITY, - on_the_fly_color_capability, - } - ): - raise RunnerError( - "on-the-fly report runtime identity requires exactly its two " - "accuracy-specific capabilities" - ) - arena_capability, evaluator_abi, source_evaluator_abi = { - ExecutionMode.EAGER: ( - EAGER_DIRECT_ARENA_RUNTIME_CAPABILITY, - EAGER_DIRECT_TABLE_BINDING_ABI, - SYMJIT_PLANE_APPLICATION_ABI, - ), - ExecutionMode.RECURRENCE: ( - RECURRENCE_DIRECT_ARENA_RUNTIME_CAPABILITY, - RECURRENCE_RUNTIME_LAYOUT_ABI, - ( - SYMJIT_PLANE_APPLICATION_ABI - if cell.measurement.backend == "jit" - else { - "cpp": SYMBOLICA_CPP_RUNTIME_CAPABILITY, - "asm": SYMBOLICA_ASM_RUNTIME_CAPABILITY, - }.get(cell.measurement.backend) - ), - ), - ExecutionMode.ON_THE_FLY: ( - ON_THE_FLY_RUNTIME_CAPABILITY, - "pyamplicol-runtime-on-the-fly-execution", - SYMJIT_PLANE_APPLICATION_ABI, - ), - }.get( - cell.measurement.execution_mode, - ( - COMPILED_PLANE_ARENA_RUNTIME_CAPABILITY, - ( - COMPILED_PLANE_DIRECT_APPLICATION_ABI - if cell.measurement.backend == "jit" - else NATIVE_COMPILED_DIRECT_APPLICATION_ABI - ), - ( - SYMJIT_PLANE_APPLICATION_ABI - if cell.measurement.backend == "jit" - else NATIVE_COMPILED_DIRECT_APPLICATION_ABI - ), - ), - ) - if arena_capability not in required_capabilities: - raise RunnerError( - f"report artifact process does not require {arena_capability!r}" - ) - source_evaluator_runtime_capability = { - "jit": SYMJIT_F64_RUNTIME_CAPABILITY, - "cpp": SYMBOLICA_CPP_RUNTIME_CAPABILITY, - "asm": SYMBOLICA_ASM_RUNTIME_CAPABILITY, - }.get(cell.measurement.backend) - if source_evaluator_runtime_capability is None: - raise RunnerError( - f"report runtime has unsupported backend {cell.measurement.backend!r}" - ) - native = importlib.import_module("pyamplicol._rusticol") - verify_native_module(native) - native_digest = native.native_build_inputs_sha256() - target = native.target_info() - build_info = _active_build_info() - if not isinstance(build_info, Mapping): - raise RunnerError("report runtime has no exact wheel build identity") - publishable = build_info.get("publishable") - if publishable is False: - build_identity_fields = ( - "schema_version", - "version", - "candidate_fingerprint", - "source_revision", - "source_checkout", - "native_build_inputs_sha256", - "publishable", - ) - candidate_build_identity = { - field: build_info.get(field) for field in build_identity_fields - } - if candidate_build_identity[ - "native_build_inputs_sha256" - ] != native_digest or not all( - candidate_build_identity[field] is not None - for field in build_identity_fields - ): - raise RunnerError( - "report runtime is not a complete compatible non-publishable " - "candidate build" - ) - elif publishable is True: - build_identity_fields = ( - "schema_version", - "version", - "source_revision", - "publishable", - "selftest_fixture_bootstrap", - ) - candidate_build_identity = { - field: build_info.get(field) for field in build_identity_fields - } - if ( - candidate_build_identity["source_revision"] != expected_source_revision - or candidate_build_identity["selftest_fixture_bootstrap"] is not False - or not all( - candidate_build_identity[field] is not None - for field in build_identity_fields - if field != "selftest_fixture_bootstrap" - ) - ): - raise RunnerError( - "report runtime is not a complete compatible release-wheel build" - ) - else: - raise RunnerError("report runtime build kind is unavailable") - if ( - not isinstance(native_digest, str) - or re.fullmatch(r"[0-9a-f]{64}", native_digest) is None - ): - raise RunnerError("native runtime build-input identity is invalid") - native_path = Path(str(native.__file__)).resolve(strict=True) - native_extension_sha256 = _sha256_file(native_path) - package_roots = tuple(Path(str(path)) for path in pyamplicol.__path__) - try: - if __package__.startswith("pyamplicol."): - package_tree = python_package_tree_identity(package_roots) - loaded_origin_policy = loaded_pyamplicol_origin_policy( - package_roots, - native_extension=native_path, - ) - else: - preimport_identity = established_preimport_runtime_identity() - expected_package_tree = preimport_identity.get("python_package_tree") - expected_native_identity = preimport_identity.get("native_extension") - if ( - preimport_identity.get("kind") - != "pyamplicol-preimport-runtime-identity-v1" - or not isinstance(expected_package_tree, Mapping) - or not isinstance(expected_native_identity, Mapping) - ): - raise RuntimeEvidenceError( - "preimport runtime identity has an invalid contract" - ) - package_tree = python_package_tree_identity(package_roots) - if dict(package_tree) != dict(expected_package_tree): - raise RuntimeEvidenceError( - "report runtime package tree differs from its preimport identity" - ) - loaded_origin_policy = loaded_pyamplicol_origin_policy( - package_roots, - native_extension=native_path, - expected_package_identity=dict(expected_package_tree), - expected_native_identity=dict(expected_native_identity), - ) - except RuntimeEvidenceError as error: - raise RunnerError( - "report runtime Python namespace cannot be authenticated" - ) from error - candidate_build_identity_sha256 = hashlib.sha256( - _canonical_json(candidate_build_identity) - ).hexdigest() - optimization_identity: dict[str, int] = {} - direct_codegen_identity: dict[str, object] = {} - source_jit_identity: dict[str, object] = {} - if cell.measurement.backend == "jit": - source_level = cell.measurement.jit_optimization_level - if ( - isinstance(source_level, bool) - or not isinstance(source_level, int) - or source_level not in {0, 1, 2, 3} - ): - raise RunnerError( - "JIT Arena report runtime has no valid source optimization level" - ) - if ( - cell.measurement.execution_mode - in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - } - and source_level != 2 - ): - raise RunnerError( - f"{cell.measurement.execution_mode.value} JIT Arena report " - "runtime must use its authenticated portable O2 source" - ) - optimization_identity["source_jit_optimization_level"] = source_level - if cell.measurement.execution_mode is ExecutionMode.COMPILED: - direct_codegen_identity = _authenticated_direct_codegen_identity( - manifest, - process_id=process_id, - source_optimization_level=source_level, - ) - optimization_identity["direct_codegen_optimization_level"] = int( - direct_codegen_identity["optimization_level"] - ) - elif cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - source_jit_identity = _authenticated_recurrence_source_identity( - manifest, - process_id=process_id, - source_optimization_level=source_level, - ) - elif cell.measurement.jit_optimization_level is not None: - raise RunnerError( - "non-JIT Arena report runtime unexpectedly declares a JIT " - "optimization level" - ) - return { - "kind": "pyamplicol-report-runtime-identity-v1", - "artifact_id": manifest.artifact_id, - "loaded_artifact_id": loaded_artifact_id, - "artifact_identity_match": True, - "process_id": process_id, - "execution_mode": expected_execution_mode, - "loaded_execution_mode": loaded_execution_mode, - "backend": cell.measurement.backend, - "required_arena_capability": arena_capability, - "expected_evaluator_abi": evaluator_abi, - "expected_source_evaluator_abi": source_evaluator_abi, - "expected_source_evaluator_runtime_capability": ( - source_evaluator_runtime_capability - ), - "process_required_runtime_capabilities": list(required_capabilities), - "package_version": pyamplicol.__version__, - "python_package_tree": package_tree, - "loaded_module_origin_policy": loaded_origin_policy, - "artifact_runtime_version": manifest.runtime["engine_version"], - "source_revision": expected_source_revision, - "candidate_build_identity": candidate_build_identity, - "candidate_build_identity_sha256": candidate_build_identity_sha256, - "native_build_inputs_sha256": native_digest, - "native_extension": { - "path": str(native_path), - "sha256": native_extension_sha256, - "package_version": str(native.package_version()), - }, - "native_target": { - "triple": str(target.triple), - "cpu_features": [str(value) for value in target.cpu_features], - }, - **optimization_identity, - **( - {"direct_codegen_identity": direct_codegen_identity} - if direct_codegen_identity - else {} - ), - **({"source_jit_identity": source_jit_identity} if source_jit_identity else {}), - } - - -def _authenticated_process_execution( - manifest: object, - *, - process_id: str, -) -> tuple[Mapping[str, object], str, str, Path, Sequence[object]]: - runtime = getattr(manifest, "runtime", None) - root = getattr(manifest, "root", None) - payloads = getattr(manifest, "payloads", None) - if ( - not isinstance(runtime, Mapping) - or not isinstance(root, Path) - or not isinstance(payloads, Sequence) - ): - raise RunnerError("artifact exposes no authenticated execution payload") - relative = runtime.get("evaluator_manifest_path") - if not isinstance(relative, str) or not relative: - raise RunnerError("artifact runtime has no evaluator manifest path") - evaluator_index, _ = _authenticated_json_payload( - root, - payloads, - relative, - expected_process_id=None, - label="evaluator index", - ) - if ( - evaluator_index.get("kind") != "pyamplicol-runtime-execution-set" - or type(evaluator_index.get("schema_version")) is not int - or evaluator_index.get("schema_version") != 3 - ): - raise RunnerError("authenticated evaluator index has an invalid contract") - entries = evaluator_index.get("processes") - if isinstance(entries, (str, bytes)) or not isinstance(entries, Sequence): - raise RunnerError("authenticated evaluator index has no process entries") - matches = [ - entry - for entry in entries - if isinstance(entry, Mapping) and entry.get("process_id") == process_id - ] - if len(matches) != 1: - raise RunnerError( - f"authenticated evaluator index has no unique entry for {process_id!r}" - ) - entry_relative = matches[0].get("manifest_path") - if not isinstance(entry_relative, str) or not entry_relative: - raise RunnerError("authenticated evaluator index entry has no manifest path") - entry_logical = PurePosixPath(entry_relative) - if ( - entry_logical.is_absolute() - or not entry_logical.parts - or any(part in {"", ".", ".."} for part in entry_logical.parts) - or entry_logical.as_posix() != entry_relative - ): - raise RunnerError( - "authenticated evaluator index entry has a noncanonical manifest path" - ) - execution_relative = (PurePosixPath(relative).parent / entry_logical).as_posix() - execution, actual_sha256 = _authenticated_json_payload( - root, - payloads, - execution_relative, - expected_process_id=process_id, - label="process execution manifest", - ) - return execution, execution_relative, actual_sha256, root, payloads - - -def _authenticated_symjit_plane_leaves( - value: object, - *, - source_optimization_level: int, - context: str, -) -> list[tuple[str, str]]: - if not isinstance(value, Mapping): - raise RunnerError(f"{context} source evaluator is not an object") - if value.get("kind") == "chunked-symbolica-evaluator": - chunks = value.get("chunks") - if ( - isinstance(chunks, (str, bytes)) - or not isinstance(chunks, Sequence) - or not chunks - ): - raise RunnerError(f"{context} chunked source evaluator has no leaves") - leaves: list[tuple[str, str]] = [] - for index, chunk in enumerate(chunks): - leaves.extend( - _authenticated_symjit_plane_leaves( - chunk, - source_optimization_level=source_optimization_level, - context=f"{context}.chunks[{index}]", - ) - ) - return leaves - legacy_backend = value.get("backend") - input_len = value.get("input_len") - output_len = value.get("output_len") - if ( - value.get("kind") != "symjit-application-evaluator" - or ("backend" in value and legacy_backend != "jit") - or value.get("runtime_capability") != _RECURRENCE_JIT_SOURCE_RUNTIME_CAPABILITY - or value.get("application_abi") != _SYMJIT_APPLICATION_ABI - or value.get("element_layout") != "complex-f64" - or value.get("batch_layout") != "row-major" - or value.get("compiler_type") != "native" - or value.get("translation_mode") not in {"direct", "indirect"} - or value.get("optimization_level") != source_optimization_level - or value.get("word_bits") != 64 - or value.get("endianness") != "little" - or value.get("required_defuns") != [] - or isinstance(input_len, bool) - or not isinstance(input_len, int) - or input_len < 0 - or isinstance(output_len, bool) - or not isinstance(output_len, int) - or output_len < 0 - ): - raise RunnerError(f"{context} source evaluator leaf contract drifted") - _canonical_recurrence_path( - value.get("application_path"), - f"{context} ordinary source evaluator application", - ) - fallback_path = value.get("evaluator_state_path") - fallback_capability = value.get("evaluator_state_runtime_capability") - if fallback_path is None and fallback_capability is None: - pass - elif ( - not isinstance(fallback_path, str) - or fallback_capability != "symbolica.legacy-jit-container.complex-f64.v1" - ): - raise RunnerError(f"{context} source evaluator fallback contract drifted") - else: - _canonical_recurrence_path( - fallback_path, - f"{context} fallback source evaluator state", - ) - plane = value.get("plane_application") - if not isinstance(plane, Mapping): - raise RunnerError(f"{context} source evaluator has no plane application") - target = plane.get("target") - if ( - plane.get("application_abi") != _SYMJIT_PLANE_APPLICATION_ABI - or plane.get("storage_abi") != _SYMJIT_APPLICATION_ABI - or plane.get("element_layout") != "split-complex-plane-major" - or plane.get("descriptor_order") != "inputs-re-im-then-outputs-re-im" - or plane.get("input_complex_count") != input_len - or plane.get("output_complex_count") != output_len - or plane.get("input_plane_count") != 2 * input_len - or plane.get("output_plane_count") != 2 * output_len - or plane.get("compiler_type") != "native" - or plane.get("translation_mode") != "symbolica-structured-instructions" - or plane.get("simd") is not True - or plane.get("complex") is not True - or plane.get("fast_math") is not True - or plane.get("fast_complex") is not False - or not isinstance(plane.get("compression"), bool) - or plane.get("threading") is not False - or plane.get("direct_arena") is not True - or plane.get("optimization_level") != source_optimization_level - or not _valid_symjit_plane_target(target) - ): - raise RunnerError(f"{context} plane application contract drifted") - plane_path = _canonical_recurrence_path( - plane.get("application_path"), - f"{context} plane application", - ) - source_digest = _lowercase_sha256( - plane.get("source_digest"), - f"{context} plane source digest", - ) - return [(plane_path, source_digest)] - - -def _valid_symjit_plane_target(value: object) -> bool: - """Match Rusticol's canonical SymJIT plane-target object contract.""" - - if not isinstance(value, Mapping): - return False - allowed_fields = {"word_bits", "endianness", "triple", "cpu_features"} - if set(value) - allowed_fields: - return False - word_bits = value.get("word_bits") - if isinstance(word_bits, bool) or not isinstance(word_bits, int) or word_bits != 64: - return False - if value.get("endianness") != "little": - return False - if "triple" in value: - triple = value.get("triple") - if not isinstance(triple, str) or not triple or "\0" in triple: - return False - if "cpu_features" in value: - features = value.get("cpu_features") - if not isinstance(features, list): - return False - previous: str | None = None - for feature in features: - if ( - not isinstance(feature, str) - or not feature - or "\0" in feature - or (previous is not None and previous >= feature) - ): - return False - previous = feature - return True - - -def _authenticated_direct_codegen_identity( - manifest: object, - *, - process_id: str, - source_optimization_level: int, -) -> dict[str, object]: - """Authenticate P-kernel lowering in one artifact-ID-bound process payload.""" - - execution, execution_relative, actual_sha256, _, _ = ( - _authenticated_process_execution(manifest, process_id=process_id) - ) - - leaf_count = 0 - - def walk(value: object) -> None: - nonlocal leaf_count - if isinstance(value, Mapping): - arena = value.get("compiled_plane_arena") - if isinstance(arena, Mapping): - source_leaves = _authenticated_symjit_plane_leaves( - value.get("evaluator"), - source_optimization_level=source_optimization_level, - context="compiled plane-Arena evaluator", - ) - leaves = arena.get("leaves") - if ( - isinstance(leaves, (str, bytes)) - or not isinstance(leaves, Sequence) - or not leaves - ): - raise RunnerError( - "compiled plane-Arena descriptor has no authenticated leaves" - ) - if len(leaves) != len(source_leaves): - raise RunnerError( - "compiled plane-Arena descriptor does not cover its " - "authenticated plane applications" - ) - for raw_leaf, (plane_path, _source_digest) in zip( - leaves, - source_leaves, - strict=True, - ): - if not isinstance(raw_leaf, Mapping): - raise RunnerError( - "compiled plane-Arena descriptor has an invalid leaf" - ) - if ( - raw_leaf.get("application_path") != plane_path - or raw_leaf.get("source_application_abi") - != _SYMJIT_PLANE_APPLICATION_ABI - or raw_leaf.get("optimization_level") - != source_optimization_level - or raw_leaf.get("direct_codegen_optimization_level") - != source_optimization_level - ): - raise RunnerError( - "compiled plane-Arena leaf optimization identity drifted" - ) - leaf_count += 1 - for child in value.values(): - walk(child) - elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)): - for child in value: - walk(child) - - walk(execution) - if leaf_count == 0: - raise RunnerError("execution payload contains no compiled plane-Arena leaves") - return { - "kind": "authenticated-compiled-plane-arena-direct-codegen-v1", - "optimization_level": source_optimization_level, - "source_optimization_level": source_optimization_level, - "leaf_count": leaf_count, - "execution_manifest_path": execution_relative, - "execution_manifest_sha256": actual_sha256, - } - - -def _authenticated_recurrence_source_identity( - manifest: object, - *, - process_id: str, - source_optimization_level: int, -) -> dict[str, object]: - """Bind recurrence JIT O2 to its exact source and direct-template payloads.""" - - execution, execution_relative, execution_sha256, root, payloads = ( - _authenticated_process_execution(manifest, process_id=process_id) - ) - if execution.get("kind") != "pyamplicol-runtime-recurrence-execution": - raise RunnerError("authenticated recurrence execution kind is invalid") - plan = execution.get("plan") - if not isinstance(plan, Mapping): - raise RunnerError("authenticated recurrence execution has no plan") - expected_execution_abis = { - "direct_template_abi": _RECURRENCE_DIRECT_TEMPLATE_ABI, - "direct_backend_abi": _RECURRENCE_DIRECT_BACKEND_ABI, - } - for field, expected in expected_execution_abis.items(): - if execution.get(field) != expected or plan.get(field) != expected: - raise RunnerError( - f"authenticated recurrence execution/plan {field} drifted" - ) - prepared_kernel_pack_digest = _lowercase_sha256( - execution.get("prepared_kernel_pack_digest"), - "authenticated recurrence execution prepared-kernel pack digest", - ) - direct_template_catalog_digest = _lowercase_sha256( - execution.get("direct_template_catalog_digest"), - "authenticated recurrence execution direct-template catalog digest", - ) - if ( - plan.get("prepared_kernel_pack_digest") != prepared_kernel_pack_digest - or plan.get("direct_template_catalog_digest") != direct_template_catalog_digest - ): - raise RunnerError( - "authenticated recurrence execution/plan source digests drifted" - ) - kernel_pack = execution.get("kernel_pack") - if not isinstance(kernel_pack, Mapping): - raise RunnerError("authenticated recurrence execution has no kernel pack") - pack_relative = kernel_pack.get("manifest_path") - if not isinstance(pack_relative, str) or not pack_relative: - raise RunnerError("authenticated recurrence execution has no kernel-pack path") - payload_root = _canonical_recurrence_path( - kernel_pack.get("payload_root"), - "authenticated recurrence kernel payload root", - ) - pack, pack_sha256 = _authenticated_json_payload( - root, - payloads, - pack_relative, - expected_process_id=None, - label="recurrence kernel pack", - ) - settings = pack.get("optimization_settings") - direct_catalog = pack.get("recurrence_direct_template") - if not isinstance(settings, Mapping) or not isinstance(direct_catalog, Mapping): - raise RunnerError("authenticated recurrence kernel pack is incomplete") - templates = direct_catalog.get("templates") - if ( - pack.get("backend") != "jit" - or settings.get("backend") != "jit" - or settings.get("jit_optimization_level") != source_optimization_level - or direct_catalog.get("abi") != _RECURRENCE_DIRECT_TEMPLATE_ABI - or direct_catalog.get("backend") != "jit" - or direct_catalog.get("backend_abi") != _RECURRENCE_DIRECT_BACKEND_ABI - or direct_catalog.get("canonicalization_abi") - != _RECURRENCE_DIRECT_CANONICALIZATION_ABI - or direct_catalog.get("optimization_level") != source_optimization_level - or direct_catalog.get("portable") is not True - or isinstance(templates, (str, bytes)) - or not isinstance(templates, Sequence) - or not templates - ): - raise RunnerError( - "authenticated recurrence direct-template optimization identity drifted" - ) - if ( - direct_catalog.get("prepared_kernel_pack_digest") != prepared_kernel_pack_digest - or direct_catalog.get("catalog_digest") != direct_template_catalog_digest - ): - raise RunnerError( - "authenticated recurrence execution and kernel-pack digests differ" - ) - if _mapping_digest_without(direct_catalog, "catalog_digest") != ( - direct_template_catalog_digest - ): - raise RunnerError( - "authenticated recurrence direct-template catalog digest is invalid" - ) - - evaluator_members = _authenticated_evaluator_container_members( - manifest, - root=root, - payloads=payloads, - ) - authenticated_source_payloads: dict[str, str] = {} - - def authenticate_source_payload(relative: str, *, label: str) -> str: - cached = authenticated_source_payloads.get(relative) - if cached is not None: - return cached - result = _authenticated_recurrence_source_payload( - root, - payloads, - evaluator_members, - relative, - label=label, - ) - authenticated_source_payloads[relative] = result - return result - - kernels = pack.get("kernels") - variants = pack.get("kernel_variants") - if ( - isinstance(kernels, (str, bytes)) - or not isinstance(kernels, Sequence) - or not kernels - or isinstance(variants, (str, bytes)) - or not isinstance(variants, Sequence) - ): - raise RunnerError( - "authenticated recurrence kernel pack has an invalid source inventory" - ) - source_leaves_by_kernel: dict[int, set[tuple[str, str]]] = {} - source_evaluator_leaf_count = 0 - for index, raw_kernel in enumerate(kernels): - if not isinstance(raw_kernel, Mapping): - raise RunnerError( - f"authenticated recurrence kernel {index} is not an object" - ) - kernel_id = raw_kernel.get("kernel_id") - if ( - isinstance(kernel_id, bool) - or not isinstance(kernel_id, int) - or kernel_id < 0 - or kernel_id in source_leaves_by_kernel - ): - raise RunnerError( - f"authenticated recurrence kernel {index} has an invalid kernel ID" - ) - leaves = _authenticated_recurrence_source_leaves( - raw_kernel.get("f64_evaluator_manifest"), - source_optimization_level=source_optimization_level, - payload_root=payload_root, - authenticate_payload=authenticate_source_payload, - context=f"authenticated recurrence kernel {index}", - ) - source_evaluator_leaf_count += len(leaves) - source_leaves_by_kernel[kernel_id] = set(leaves) - for index, raw_variant in enumerate(variants): - if not isinstance(raw_variant, Mapping): - raise RunnerError( - f"authenticated recurrence kernel variant {index} is not an object" - ) - source_evaluator_leaf_count += len( - _authenticated_recurrence_source_leaves( - raw_variant.get("f64_evaluator_manifest"), - source_optimization_level=source_optimization_level, - payload_root=payload_root, - authenticate_payload=authenticate_source_payload, - context=f"authenticated recurrence kernel variant {index}", - ) - ) - - prepared_direct_template_count = 0 - for index, raw_template in enumerate(templates): - if ( - not isinstance(raw_template, Mapping) - or raw_template.get("abi") != _RECURRENCE_DIRECT_TEMPLATE_ABI - or raw_template.get("backend") != "jit" - or raw_template.get("portable") is not True - or raw_template.get("optimization_level") != source_optimization_level - ): - raise RunnerError( - f"authenticated recurrence direct-template {index} contract drifted" - ) - if _mapping_digest_without(raw_template, "semantic_digest") != ( - raw_template.get("semantic_digest") - ): - raise RunnerError( - f"authenticated recurrence direct-template {index} digest is invalid" - ) - binding = raw_template.get("payload_binding") - if not isinstance(binding, Mapping): - raise RunnerError( - f"authenticated recurrence direct-template {index} has no " - "payload binding" - ) - if ( - binding.get("abi") != _RECURRENCE_DIRECT_PAYLOAD_BINDING_ABI - or _recurrence_payload_binding_digest(binding) - != binding.get("payload_digest") - ): - raise RunnerError( - f"authenticated recurrence direct-template {index} " - "payload-binding contract is invalid" - ) - binding_kind = binding.get("kind") - if binding_kind == "rusticol-intrinsic": - if ( - binding.get("source_application_abi") is not None - or binding.get("direct_application_abi") is not None - or binding.get("source_application_path") is not None - or binding.get("source_application_sha256") is not None - or binding.get("payload_paths") != [] - or not isinstance(binding.get("runtime_template"), str) - or not binding.get("runtime_template") - ): - raise RunnerError( - f"authenticated recurrence direct-template {index} " - "intrinsic source contract is invalid" - ) - continue - if binding_kind != "prepared-direct-call": - raise RunnerError( - f"authenticated recurrence direct-template {index} is not executable" - ) - prepared_direct_template_count += 1 - source_path = _canonical_recurrence_path( - binding.get("source_application_path"), - (f"authenticated recurrence direct-template {index} source application"), - ) - source_sha256 = _lowercase_sha256( - binding.get("source_application_sha256"), - ( - f"authenticated recurrence direct-template {index} " - "source application digest" - ), - ) - prepared_kernel_id = binding.get("prepared_kernel_id") - if ( - binding.get("source_application_abi") - != _RECURRENCE_JIT_SOURCE_APPLICATION_ABI - or binding.get("direct_application_abi") - != _RECURRENCE_JIT_DIRECT_APPLICATION_ABI - or binding.get("payload_paths") != [source_path] - or isinstance(prepared_kernel_id, bool) - or not isinstance(prepared_kernel_id, int) - or prepared_kernel_id < 0 - or (source_path, source_sha256) - not in source_leaves_by_kernel.get(prepared_kernel_id, set()) - ): - raise RunnerError( - f"authenticated recurrence direct-template {index} source " - "application is not bound to its prepared kernel" - ) - if prepared_direct_template_count == 0 or source_evaluator_leaf_count == 0: - raise RunnerError( - "authenticated recurrence direct-template pack has no source " - "application evidence" - ) - return { - "kind": "authenticated-recurrence-direct-template-source-v1", - "optimization_level": source_optimization_level, - "direct_template_count": len(templates), - "prepared_direct_template_count": prepared_direct_template_count, - "source_evaluator_leaf_count": source_evaluator_leaf_count, - "source_application_abi": _RECURRENCE_JIT_SOURCE_APPLICATION_ABI, - "direct_application_abi": _RECURRENCE_JIT_DIRECT_APPLICATION_ABI, - "prepared_kernel_pack_digest": prepared_kernel_pack_digest, - "direct_template_catalog_digest": direct_template_catalog_digest, - "execution_manifest_path": execution_relative, - "execution_manifest_sha256": execution_sha256, - "kernel_pack_path": pack_relative, - "kernel_pack_sha256": pack_sha256, - } - - -def _lowercase_sha256(value: object, label: str) -> str: - if ( - not isinstance(value, str) - or len(value) != 64 - or any(character not in "0123456789abcdef" for character in value) - ): - raise RunnerError(f"{label} is not a lowercase SHA-256") - return value - - -def _mapping_digest_without(value: Mapping[str, object], field: str) -> str: - payload = dict(value) - payload.pop(field, None) - return hashlib.sha256(_canonical_json(payload)).hexdigest() - - -def _recurrence_payload_binding_digest(binding: Mapping[str, object]) -> str: - if binding.get("kind") != "rusticol-intrinsic": - return _mapping_digest_without(binding, "payload_digest") - if binding.get("role") == "contribution": - fields = ( - "abi", - "destination_operation", - "contribution_parent_permutation", - "intrinsic_contract_digest", - "kind", - "role", - "runtime_template", - "scalar_input_count", - "scalar_projections", - ) - return hashlib.sha256( - _canonical_json({field: binding.get(field) for field in fields}) - ).hexdigest() - # Source/finalization intrinsics have an opaque Rusticol implementation - # digest whose derivation includes semantic-catalog fields not duplicated - # in the payload binding. Its exact value remains transitively bound by - # the recomputed template and catalog digests. - return _lowercase_sha256( - binding.get("payload_digest"), - "authenticated recurrence intrinsic payload digest", - ) - - -def _canonical_recurrence_path(value: object, label: str) -> str: - if not isinstance(value, str) or not value: - raise RunnerError(f"{label} path is missing") - logical = PurePosixPath(value) - if ( - logical.is_absolute() - or not logical.parts - or any(part in {"", ".", ".."} for part in logical.parts) - or logical.as_posix() != value - ): - raise RunnerError(f"{label} path is not canonical") - return value - - -def _authenticated_evaluator_container_members( - manifest: object, - *, - root: Path, - payloads: Sequence[object], -) -> Mapping[str, tuple[int, str]]: - extensions = getattr(manifest, "extensions", None) - if extensions is None: - return {} - if not isinstance(extensions, Mapping): - raise RunnerError("artifact evaluator payload extensions are invalid") - raw_container = extensions.get("evaluator_payload_container") - if raw_container is None: - return {} - if not isinstance(raw_container, Mapping): - raise RunnerError("artifact evaluator payload container is invalid") - required = { - "kind", - "schema_version", - "storage_abi", - "path", - "member_count", - "unpacked_size_bytes", - "index_sha256", - } - if ( - set(raw_container) != required - or raw_container.get("kind") != "pyamplicol-evaluator-payload-container" - or raw_container.get("schema_version") != 1 - or raw_container.get("storage_abi") != "pacbin-v1" - ): - raise RunnerError("artifact evaluator payload container contract drifted") - member_count = raw_container.get("member_count") - unpacked_size = raw_container.get("unpacked_size_bytes") - index_sha256 = _lowercase_sha256( - raw_container.get("index_sha256"), - "artifact evaluator payload container index digest", - ) - if ( - isinstance(member_count, bool) - or not isinstance(member_count, int) - or member_count < 0 - or isinstance(unpacked_size, bool) - or not isinstance(unpacked_size, int) - or unpacked_size < 0 - ): - raise RunnerError("artifact evaluator payload container inventory is invalid") - container_path = _canonical_recurrence_path( - raw_container.get("path"), - "artifact evaluator payload container", - ) - data, _ = _authenticated_payload_bytes( - root, - payloads, - container_path, - expected_process_id=None, - expected_role="evaluator-state", - expected_media_type="application/octet-stream", - label="evaluator payload container", - ) - try: - from pyamplicol.generation.evaluator_container import PacbinReader - - with PacbinReader.open(io.BytesIO(data), verify_payloads=True) as reader: - index = reader.index - members = tuple(reader.members) - except (OSError, TypeError, ValueError) as error: - raise RunnerError( - "authenticated evaluator payload container is invalid" - ) from error - if ( - len(members) != member_count - or sum(member.length for member in members) != unpacked_size - or index.index_sha256 != index_sha256 - ): - raise RunnerError( - "authenticated evaluator payload container index metadata drifted" - ) - return { - member.logical_path: (int(member.kind), member.sha256) for member in members - } - - -def _authenticated_recurrence_source_payload( - root: Path, - payloads: Sequence[object], - evaluator_members: Mapping[str, tuple[int, str]], - relative: str, - *, - label: str, -) -> str: - canonical = _canonical_recurrence_path(relative, label) - loose = [ - payload for payload in payloads if getattr(payload, "path", None) == canonical - ] - packed = evaluator_members.get(canonical) - if len(loose) + (packed is not None) != 1: - raise RunnerError(f"{label} payload is missing or ambiguous") - if loose: - _, sha256 = _authenticated_payload_bytes( - root, - payloads, - canonical, - expected_process_id=None, - expected_role="evaluator-state", - expected_media_type="application/octet-stream", - label=label, - ) - return sha256 - assert packed is not None - kind, sha256 = packed - if kind != 1: - raise RunnerError(f"{label} is not a packed SymJIT application") - return _lowercase_sha256(sha256, f"{label} packed member digest") - - -def _authenticated_recurrence_source_leaves( - value: object, - *, - source_optimization_level: int, - payload_root: str, - authenticate_payload: object, - context: str, -) -> list[tuple[str, str]]: - plane_leaves = _authenticated_symjit_plane_leaves( - value, - source_optimization_level=source_optimization_level, - context=context, - ) - if not callable(authenticate_payload): - raise RunnerError("recurrence source payload authenticator is invalid") - result: list[tuple[str, str]] = [] - for application_path, _source_digest in plane_leaves: - payload_path = ( - PurePosixPath(payload_root) / PurePosixPath(application_path) - ).as_posix() - sha256 = authenticate_payload( # type: ignore[operator] - payload_path, - label=f"{context} plane application", - ) - if not isinstance(sha256, str): - raise RunnerError(f"{context} plane application digest is invalid") - result.append((application_path, sha256)) - return result - - -def _authenticated_json_payload( - root: Path, - payloads: Sequence[object], - relative: str, - *, - expected_process_id: str | None, - label: str, -) -> tuple[Mapping[str, object], str]: - """Read one declared JSON payload through one checked file descriptor.""" - - data, actual_sha256 = _authenticated_payload_bytes( - root, - payloads, - relative, - expected_process_id=expected_process_id, - expected_role="evaluator-manifest", - expected_media_type="application/json", - label=label, - ) - try: - value = json.loads(data) - except json.JSONDecodeError as error: - raise RunnerError(f"authenticated {label} is invalid JSON") from error - if not isinstance(value, Mapping): - raise RunnerError(f"authenticated {label} is not a JSON object") - return value, actual_sha256 - - -def _authenticated_payload_bytes( - root: Path, - payloads: Sequence[object], - relative: str, - *, - expected_process_id: str | None, - expected_role: str, - expected_media_type: str, - label: str, -) -> tuple[bytes, str]: - """Read exact manifest-declared bytes through one no-follow descriptor.""" - - logical = PurePosixPath(relative) - if ( - logical.is_absolute() - or not logical.parts - or any(part in {"", ".", ".."} for part in logical.parts) - or logical.as_posix() != relative - ): - raise RunnerError(f"{label} path is not canonical") - matches = [ - payload for payload in payloads if getattr(payload, "path", None) == relative - ] - if len(matches) != 1: - raise RunnerError(f"{label} payload is missing or ambiguous") - payload = matches[0] - expected_size = getattr(payload, "size_bytes", None) - expected_sha256 = getattr(payload, "sha256", None) - if ( - getattr(payload, "role", None) != expected_role - or getattr(payload, "media_type", None) != expected_media_type - or getattr(payload, "executable", None) is not False - or getattr(payload, "process_id", None) != expected_process_id - or isinstance(expected_size, bool) - or not isinstance(expected_size, int) - or expected_size < 0 - or not isinstance(expected_sha256, str) - or len(expected_sha256) != 64 - ): - raise RunnerError(f"{label} has an invalid artifact declaration") - path = root.joinpath(*logical.parts) - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_NOFOLLOW", 0) - | getattr(os, "O_BINARY", 0) - ) - descriptor: int | None = None - try: - descriptor = os.open(path, flags) - before = os.fstat(descriptor) - if not stat.S_ISREG(before.st_mode) or before.st_size != expected_size: - raise RunnerError(f"{label} does not match its artifact declaration") - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - data = stream.read(expected_size + 1) - after = os.fstat(stream.fileno()) - except OSError as error: - raise RunnerError(f"cannot read authenticated {label}") from error - finally: - if descriptor is not None: - os.close(descriptor) - stable_fields = ( - "st_dev", - "st_ino", - "st_mode", - "st_size", - "st_mtime_ns", - "st_ctime_ns", - ) - if any(getattr(before, name) != getattr(after, name) for name in stable_fields): - raise RunnerError(f"authenticated {label} changed while it was read") - actual_sha256 = hashlib.sha256(data).hexdigest() - if len(data) != expected_size or actual_sha256 != expected_sha256: - raise RunnerError(f"{label} does not match the artifact manifest") - return data, actual_sha256 - - -def _authenticated_effective_config(artifact_path: Path) -> Mapping[str, object]: - """Return the exact effective TOML declared by a generated artifact.""" - - from pyamplicol.artifacts import load_manifest - - manifest = load_manifest(artifact_path, verify_payloads=False) - root = getattr(manifest, "root", None) - payloads = getattr(manifest, "payloads", None) - configuration = getattr(manifest, "configuration", None) - if ( - not isinstance(root, Path) - or not isinstance(payloads, Sequence) - or not isinstance(configuration, Mapping) - ): - raise RunnerError("generated artifact exposes no effective configuration") - relative = configuration.get("effective_path") - if not isinstance(relative, str) or not relative: - raise RunnerError("generated artifact has no effective configuration path") - data, _ = _authenticated_payload_bytes( - root, - payloads, - relative, - expected_process_id=None, - expected_role="configuration-effective", - expected_media_type="application/toml", - label="effective configuration", - ) - try: - value = tomllib.loads(data.decode("utf-8")) - except (UnicodeDecodeError, tomllib.TOMLDecodeError) as error: - raise RunnerError( - "authenticated effective configuration is invalid TOML" - ) from error - if not isinstance(value, Mapping): - raise RunnerError("authenticated effective configuration is not a TOML table") - return value - - -def _artifact_numerical_relation_metadata( - artifact_path: Path, - process_id: str, -) -> tuple[Mapping[str, object], Mapping[str, object] | None]: - """Read compact correctness and fallback state from one manifest load.""" - - from pyamplicol.artifacts import load_manifest - from pyamplicol.generation.recurrence_numerical_current_warmup import ( - recurrence_numerical_relation_correctness_summary, - recurrence_numerical_relation_fallback_summary, - ) - - manifest = load_manifest(artifact_path, verify_payloads=False) - generation = manifest.extensions.get("generation") - concrete = ( - generation.get("concrete_processes") - if isinstance(generation, Mapping) - else None - ) - if not isinstance(concrete, Sequence) or isinstance(concrete, (str, bytes)): - raise RunnerError("generated artifact has no concrete-process metadata") - matches = tuple( - entry - for entry in concrete - if isinstance(entry, Mapping) and entry.get("id") == process_id - ) - if len(matches) != 1: - raise RunnerError( - "generated artifact numerical relation process is missing or ambiguous" - ) - filters = matches[0].get("filters") - relation_report = ( - filters.get("relation_discovery") if isinstance(filters, Mapping) else None - ) - if not isinstance(relation_report, Mapping): - raise RunnerError("generated artifact has no numerical relation report") - try: - return ( - recurrence_numerical_relation_correctness_summary(relation_report), - recurrence_numerical_relation_fallback_summary(relation_report), - ) - except ValueError as error: - raise RunnerError(str(error)) from error - - -def _selector_kwargs( - cell: CellSpec, - contract: SelectorContract | None, -) -> dict[str, tuple[str, ...] | None]: - if cell.measurement.accuracy is not Accuracy.LC: - return {"helicities": None, "color_flows": None} - if contract is None: - raise RunnerError("LC measurement requires a selector contract") - if cell.workload is Workload.SELECTED_FLOW: - return { - "helicities": None, - "color_flows": contract.selected_color_flow_ids, - } - if cell.workload is Workload.ALL_FLOW: - return { - "helicities": contract.runtime_all_flow_helicity_ids, - "color_flows": None, - } - raise RunnerError("LC measurement has an invalid workload") - - -def derive_selector_contract( - runtime: RuntimeLike, - points: object, -) -> SelectorContract: - """Select one backend-independent labelled LC flow and helicity.""" - - if _runtime_execution_mode(runtime) == ExecutionMode.ON_THE_FLY.value: - raise RunnerError( - "on-the-fly selector contracts must be inherited from a dense authority" - ) - physics = runtime.physics - color_flows = tuple(getattr(physics, "color_flows", ())) - helicities = tuple(getattr(physics, "helicities", ())) - particles = tuple(getattr(physics, "external_particles", ())) - if not color_flows or not helicities or not particles: - raise RunnerError("LC selector derivation requires complete physical axes") - - try: - words = tuple(canonical_lc_flow_word(flow.word) for flow in color_flows) - selected_word = canonical_lc_selector_word(words) - except (AttributeError, SelectorPolicyError) as error: - raise RunnerError(str(error)) from error - selected_matches = tuple( - flow - for flow, word in zip(color_flows, words, strict=True) - if word == selected_word - ) - if len(selected_matches) != 1: - raise RunnerError("LC selector did not identify exactly one physical flow") - selected_flow = selected_matches[0] - expected_flow_id = selector_color_flow_id(selected_word) - if str(selected_flow.id) != expected_flow_id: - raise RunnerError("LC selector flow ID does not encode its physical word") - - try: - pdgs = tuple(int(particle.pdg_id) for particle in particles) - states = fixed_selector_helicity(pdgs) - except (AttributeError, SelectorPolicyError, TypeError, ValueError) as error: - raise RunnerError( - "LC selector derivation requires external particle PDGs" - ) from error - helicity_matches = tuple( - helicity - for helicity in helicities - if tuple(int(value) for value in helicity.values) == states - ) - if len(helicity_matches) != 1: - raise RunnerError( - "artifact does not expose exactly one deterministic selector helicity" - ) - helicity = helicity_matches[0] - expected_helicity_id = selector_helicity_id(states) - if str(helicity.id) != expected_helicity_id: - raise RunnerError("LC selector helicity ID does not encode its physical states") - - resolved = runtime.evaluate_resolved( - points, - color_flows=(expected_flow_id,), - helicities=(expected_helicity_id,), - ) - components = tuple( - complex(component) - for point in getattr(resolved, "values", ()) - for helicity_row in point - for component in helicity_row - ) - if not components: - raise RunnerError("fixed-helicity selector evaluation is empty") - if any( - not math.isfinite(component.real) or not math.isfinite(component.imag) - for component in components - ): - raise RunnerError("fixed-helicity selector contains a non-finite component") - if not any(abs(component) > 0.0 for component in components): - raise RunnerError("canonical fixed-helicity selector is zero at report point") - - labels = tuple(int(particle.label) for particle in particles) - if len(labels) != len(states): - raise RunnerError( - "helicity source-state axis does not match external particles" - ) - return SelectorContract( - selected_color_flow_ids=(expected_flow_id,), - selected_color_words=(selected_word,), - all_flow_helicity_ids=(expected_helicity_id,), - all_flow_source_helicities=tuple(zip(labels, states, strict=True)), - point_digest=point_digest(points), - ) - - -def validate_selector_contract( - runtime: RuntimeLike, - contract: SelectorContract, - points: object, - *, - cell: CellSpec | None = None, -) -> None: - if point_digest(points) != contract.point_digest: - raise RunnerError("selector contract and measurement point differ") - runtime_is_on_the_fly = ( - _runtime_execution_mode(runtime) == ExecutionMode.ON_THE_FLY.value - ) - cell_is_on_the_fly = ( - cell is not None and cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - ) - if runtime_is_on_the_fly: - if cell is None: - raise RunnerError("on-the-fly selector validation requires its report cell") - if not cell_is_on_the_fly: - raise RunnerError("on-the-fly report runtime has the wrong execution mode") - helicity_count, color_count = _on_the_fly_compact_context( - cell, - runtime, - ) - for identifier, word in zip( - contract.selected_color_flow_ids, - contract.selected_color_words, - strict=True, - ): - try: - canonical_word = canonical_lc_flow_word(word) - except SelectorPolicyError as error: - raise RunnerError(str(error)) from error - if canonical_word != word or selector_color_flow_id(word) != identifier: - raise RunnerError( - f"artifact does not expose selected physical flow {identifier!r}" - ) - expected_states = tuple( - state for _label, state in sorted(contract.all_flow_source_helicities) - ) - runtime_helicity_ids = contract.runtime_all_flow_helicity_ids - if runtime_helicity_ids != (selector_helicity_id(expected_states),): - raise RunnerError( - "artifact does not expose selected physical helicity " - f"{contract.all_flow_helicity_ids[0]!r}" - ) - _on_the_fly_selector_ordinals( - runtime, - contract.selected_color_flow_ids, - name="color_flow_by_point", - count=color_count, - ) - _on_the_fly_selector_ordinals( - runtime, - runtime_helicity_ids, - name="helicity_by_point", - count=helicity_count, - ) - return - if cell_is_on_the_fly: - raise RunnerError("on-the-fly report runtime has the wrong execution mode") - physics = runtime.physics - colors = { - str(flow.id): tuple(int(label) for label in flow.word) - for flow in getattr(physics, "color_flows", ()) - } - for identifier, word in zip( - contract.selected_color_flow_ids, - contract.selected_color_words, - strict=True, - ): - if colors.get(identifier) != word: - raise RunnerError( - f"artifact does not expose selected physical flow {identifier!r}" - ) - helicities = { - str(item.id): tuple(int(value) for value in item.values) - for item in getattr(physics, "helicities", ()) - } - labels = tuple( - int(particle.label) for particle in getattr(physics, "external_particles", ()) - ) - expected_states = dict(contract.all_flow_source_helicities) - expected = tuple(expected_states[label] for label in labels) - for identifier, runtime_identifier in zip( - contract.all_flow_helicity_ids, - contract.runtime_all_flow_helicity_ids, - strict=True, - ): - if helicities.get(runtime_identifier) != expected: - raise RunnerError( - f"artifact does not expose selected physical helicity {identifier!r}" - ) - - -@dataclass(frozen=True, slots=True) -class _OtfAuthorityCapture: - totals: tuple[float, ...] - helicity_ids: tuple[str, ...] - color_flow_ids: tuple[str, ...] - components: tuple[tuple[tuple[float, ...], ...], ...] - total_source_sha256: str - resolved_total_source_sha256: str - resolved_ordering_sha256: str - resolved_source_sha256: str - resolved_sum: dict[str, object] - - -def _finite_real(value: object, label: str) -> float: - try: - number = complex(value) # type: ignore[arg-type] - except (OverflowError, TypeError, ValueError) as error: - raise RunnerError(f"{label} is not numeric") from error - if not math.isfinite(number.real) or not math.isfinite(number.imag): - raise RunnerError(f"{label} is not finite") - if number.imag != 0.0: - raise RunnerError(f"{label} is not real") - return float(number.real) - - -def _otf_selector_digest(cell: CellSpec, contract: SelectorContract) -> str: - selectors = _selector_kwargs(cell, contract) - return hashlib.sha256( - _canonical_json( - { - "accuracy": cell.measurement.accuracy.value, - "workload": cell.workload.value, - "selector_contract": contract.as_dict(), - "helicities": ( - None - if selectors["helicities"] is None - else list(selectors["helicities"]) - ), - "color_flows": ( - None - if selectors["color_flows"] is None - else list(selectors["color_flows"]) - ), - } - ) - ).hexdigest() - - -def _otf_runtime_artifact_id(runtime: object, label: str) -> str: - artifact_id = getattr(runtime, "artifact_id", None) - if not isinstance(artifact_id, str) or not _SHA256_PATTERN.fullmatch(artifact_id): - raise RunnerError(f"{label} runtime has no authenticated artifact ID") - return artifact_id - - -def _runtime_execution_mode(runtime: object) -> str: - value = getattr(runtime, "execution_mode", None) - return value.value if isinstance(value, ExecutionMode) else str(value) - - -def _capture_otf_authority_values( - runtime: RuntimeLike, - points: object, - *, - cell: CellSpec, - contract: SelectorContract, - label: str, -) -> _OtfAuthorityCapture: - selectors = _selector_kwargs(cell, contract) - raw_totals = tuple(runtime.evaluate(points, precision=16, **selectors)) - try: - expected_point_count = len(points) # type: ignore[arg-type] - except TypeError as error: - raise RunnerError("on-the-fly authority points have no finite axis") from error - if expected_point_count < 1 or len(raw_totals) != expected_point_count: - raise RunnerError(f"{label} total point axis is empty or differs") - totals = tuple(_real_nonnegative(value) for value in raw_totals) - - resolved = runtime.evaluate_resolved(points, precision=16, **selectors) - helicity_ids = tuple(str(item) for item in getattr(resolved, "helicity_ids", ())) - color_flow_ids = tuple(str(item) for item in getattr(resolved, "color_ids", ())) - if ( - not helicity_ids - or not color_flow_ids - or any(not item for item in helicity_ids + color_flow_ids) - or len(set(helicity_ids)) != len(helicity_ids) - or len(set(color_flow_ids)) != len(color_flow_ids) - ): - raise RunnerError(f"{label} resolved axes are empty or ambiguous") - if cell.workload is Workload.SELECTED_FLOW and ( - len(color_flow_ids) != len(contract.selected_color_flow_ids) - or set(color_flow_ids) != set(contract.selected_color_flow_ids) - ): - raise RunnerError(f"{label} resolved output ignored the selected flow") - if cell.workload is Workload.ALL_FLOW and ( - len(helicity_ids) != len(contract.runtime_all_flow_helicity_ids) - or set(helicity_ids) != set(contract.runtime_all_flow_helicity_ids) - ): - raise RunnerError(f"{label} resolved output ignored the selected helicity") - - raw_components = getattr(resolved, "values", None) - to_list = getattr(raw_components, "tolist", None) - if callable(to_list): - raw_components = to_list() - if ( - not isinstance(raw_components, Sequence) - or isinstance(raw_components, (str, bytes, bytearray)) - or len(raw_components) != expected_point_count - ): - raise RunnerError(f"{label} resolved point axis is invalid") - components: list[tuple[tuple[float, ...], ...]] = [] - for point_index, raw_point in enumerate(raw_components): - if ( - not isinstance(raw_point, Sequence) - or isinstance(raw_point, (str, bytes, bytearray)) - or len(raw_point) != len(helicity_ids) - ): - raise RunnerError(f"{label} resolved helicity axis is invalid") - point_rows: list[tuple[float, ...]] = [] - for helicity_index, raw_row in enumerate(raw_point): - if ( - not isinstance(raw_row, Sequence) - or isinstance(raw_row, (str, bytes, bytearray)) - or len(raw_row) != len(color_flow_ids) - ): - raise RunnerError(f"{label} resolved color-flow axis is invalid") - point_rows.append( - tuple( - _finite_real( - value, - ( - f"{label} resolved component " - f"{point_index}/{helicity_index}/{color_index}" - ), - ) - for color_index, value in enumerate(raw_row) - ) - ) - components.append(tuple(point_rows)) - frozen_components = tuple(components) - resolved_total = getattr(resolved, "total", None) - if not callable(resolved_total): - raise RunnerError(f"{label} resolved result does not expose total()") - raw_resolved_totals = tuple(resolved_total()) - if len(raw_resolved_totals) != expected_point_count: - raise RunnerError(f"{label} resolved total point axis differs") - resolved_totals = tuple(_real_nonnegative(value) for value in raw_resolved_totals) - resolved_sum = _otf_compact_series_summary( - totals, - resolved_totals, - label=f"{label} optimized/resolved sum", - ) - ordering = { - "helicity_ids": list(helicity_ids), - "color_flow_ids": list(color_flow_ids), - } - return _OtfAuthorityCapture( - totals=totals, - helicity_ids=helicity_ids, - color_flow_ids=color_flow_ids, - components=frozen_components, - total_source_sha256=hashlib.sha256( - _canonical_json(_resolved_component_payload(totals)) - ).hexdigest(), - resolved_total_source_sha256=hashlib.sha256( - _canonical_json(_resolved_component_payload(resolved_totals)) - ).hexdigest(), - resolved_ordering_sha256=hashlib.sha256(_canonical_json(ordering)).hexdigest(), - resolved_source_sha256=hashlib.sha256( - _canonical_json( - { - **ordering, - "values": _resolved_component_payload(frozen_components), - } - ) - ).hexdigest(), - resolved_sum=resolved_sum, - ) - - -def _otf_compact_series_summary( - candidate: Sequence[float], - authority: Sequence[float], - *, - label: str, - candidate_scales: Sequence[float] | None = None, - authority_scales: Sequence[float] | None = None, -) -> dict[str, object]: - if not candidate or len(candidate) != len(authority): - raise RunnerError(f"{label} comparison axes are empty or differ") - if (candidate_scales is None) != (authority_scales is None): - raise RunnerError(f"{label} comparison scales must be paired") - if candidate_scales is not None and ( - len(candidate_scales) != len(candidate) - or authority_scales is None - or len(authority_scales) != len(authority) - ): - raise RunnerError(f"{label} comparison scale axes differ") - - if candidate_scales is None: - scale_pairs: Sequence[tuple[float | None, float | None]] = ( - (None, None), - ) * len(candidate) - else: - assert authority_scales is not None - scale_pairs = tuple(zip(candidate_scales, authority_scales, strict=True)) - records = tuple( - pointwise_validation( - candidate_value, - authority_value, - relative_tolerance=RELATIVE_TOLERANCE, - candidate_scale=candidate_scale, - baseline_scale=authority_scale, - candidate_scale_source=( - "value-magnitude" - if candidate_scale is None - else "resolved-component-l1" - ), - baseline_scale_source=( - "value-magnitude" - if authority_scale is None - else "resolved-component-l1" - ), - ) - for (candidate_value, authority_value), ( - candidate_scale, - authority_scale, - ) in zip( - zip(candidate, authority, strict=True), - scale_pairs, - strict=True, - ) - ) - failed = next( - ( - index - for index, record in enumerate(records) - if record["status"] != ResultStatus.OK.value - ), - None, - ) - if failed is not None: - raise RunnerError( - f"{label} disagrees at check {failed}: conditioned residual " - f"{records[failed]['conditioned_residual']!r}" - ) - return { - "check_count": len(records), - "maximum_conditioned_residual": max( - float(record["conditioned_residual"]) for record in records - ), - "maximum_absolute_delta": max( - float(record["absolute_difference"]) for record in records - ), - } - - -def _otf_capture_comparison( - candidate: _OtfAuthorityCapture, - authority: _OtfAuthorityCapture, - *, - authority_cell_id: str, - label: str, -) -> dict[str, object]: - total = _otf_compact_series_summary( - candidate.totals, - authority.totals, - label=f"{label} totals", - ) - if ( - len(candidate.helicity_ids) != len(authority.helicity_ids) - or set(candidate.helicity_ids) != set(authority.helicity_ids) - or len(candidate.color_flow_ids) != len(authority.color_flow_ids) - or set(candidate.color_flow_ids) != set(authority.color_flow_ids) - ): - raise RunnerError(f"{label} resolved semantic axes differ") - authority_helicities = { - identifier: index for index, identifier in enumerate(authority.helicity_ids) - } - authority_colors = { - identifier: index for index, identifier in enumerate(authority.color_flow_ids) - } - candidate_values: list[float] = [] - authority_values: list[float] = [] - candidate_scales: list[float] = [] - authority_scales: list[float] = [] - component_count = len(candidate.helicity_ids) * len(candidate.color_flow_ids) - for point_index in range(len(candidate.components)): - candidate_point = candidate.components[point_index] - authority_point = tuple( - tuple( - authority.components[point_index][authority_helicities[helicity_id]][ - authority_colors[color_id] - ] - for color_id in candidate.color_flow_ids - ) - for helicity_id in candidate.helicity_ids - ) - candidate_scales.extend( - [float(_resolved_l1(candidate_point))] * component_count - ) - authority_scales.extend( - [float(_resolved_l1(authority_point))] * component_count - ) - for candidate_row, authority_row in zip( - candidate_point, - authority_point, - strict=True, - ): - for candidate_value, authority_value in zip( - candidate_row, - authority_row, - strict=True, - ): - candidate_values.append(candidate_value) - authority_values.append(authority_value) - resolved = _otf_compact_series_summary( - candidate_values, - authority_values, - label=f"{label} resolved components", - candidate_scales=candidate_scales, - authority_scales=authority_scales, - ) - resolved["component_count"] = component_count - return { - "authority_cell_id": authority_cell_id, - "total": total, - "resolved_components": resolved, - } - - -def _otf_stage_record( - candidate: _OtfAuthorityCapture, - authority_cell: CellSpec, - authority: _OtfAuthorityCapture, - *, - stage: str, -) -> dict[str, object]: - return { - "candidate_total_source_sha256": candidate.total_source_sha256, - "candidate_resolved_total_source_sha256": ( - candidate.resolved_total_source_sha256 - ), - "candidate_resolved_ordering_sha256": (candidate.resolved_ordering_sha256), - "candidate_resolved_source_sha256": candidate.resolved_source_sha256, - "candidate_resolved_sum": candidate.resolved_sum, - "comparison": _otf_capture_comparison( - candidate, - authority, - authority_cell_id=authority_cell.cell_id, - label=f"on-the-fly {stage}/recurrence", - ), - } - - -def on_the_fly_recurrence_authority_validation( - candidate: RuntimeLike, - points: object, - *, - cell: CellSpec, - selector_contract: SelectorContract, - authority: tuple[CellSpec, RuntimeLike], -) -> dict[str, object]: - """Validate cold OTF against recurrence, then reset it for profiling.""" - - if ( - cell.measurement.execution_mode is not ExecutionMode.ON_THE_FLY - or cell.measurement.accuracy is not Accuracy.LC - ): - raise RunnerError( - "recurrence-authority preflight requires an on-the-fly LC cell" - ) - validate_runtime_contract(cell, candidate) - if _runtime_execution_mode(candidate) != ExecutionMode.ON_THE_FLY.value: - raise RunnerError("on-the-fly candidate runtime has the wrong execution mode") - validate_selector_contract( - candidate, - selector_contract, - points, - cell=cell, - ) - candidate_artifact_id = _otf_runtime_artifact_id(candidate, "on-the-fly candidate") - - authority_cell, authority_runtime = authority - if ( - authority_cell.measurement.execution_mode is not ExecutionMode.RECURRENCE - or authority_cell.measurement.accuracy is not Accuracy.LC - or authority_cell.process_key != cell.process_key - or authority_cell.n_final != cell.n_final - or authority_cell.workload is not cell.workload - ): - raise RunnerError("on-the-fly recurrence authority cell is incompatible") - validate_runtime_contract(authority_cell, authority_runtime) - if _runtime_execution_mode(authority_runtime) != ExecutionMode.RECURRENCE.value: - raise RunnerError("on-the-fly recurrence authority has the wrong mode") - validate_selector_contract(authority_runtime, selector_contract, points) - authority_capture = _capture_otf_authority_values( - authority_runtime, - points, - cell=authority_cell, - contract=selector_contract, - label="on-the-fly recurrence authority", - ) - authority_record = { - "cell_id": authority_cell.cell_id, - "artifact_id": _otf_runtime_artifact_id( - authority_runtime, "on-the-fly recurrence authority" - ), - "total_source_sha256": authority_capture.total_source_sha256, - "resolved_total_source_sha256": ( - authority_capture.resolved_total_source_sha256 - ), - "resolved_ordering_sha256": authority_capture.resolved_ordering_sha256, - "resolved_source_sha256": authority_capture.resolved_source_sha256, - "resolved_sum": authority_capture.resolved_sum, - } - - before = _capture_otf_authority_values( - candidate, - points, - cell=cell, - contract=selector_contract, - label="on-the-fly candidate before clear", - ) - before_record = _otf_stage_record( - before, - authority_cell, - authority_capture, - stage="before-clear", - ) - clear = getattr(candidate, "clear", None) - if not callable(clear): - raise RunnerError("on-the-fly candidate does not expose Runtime.clear()") - clear() - try: - after = _capture_otf_authority_values( - candidate, - points, - cell=cell, - contract=selector_contract, - label="on-the-fly candidate after clear", - ) - after_record = _otf_stage_record( - after, - authority_cell, - authority_capture, - stage="after-clear", - ) - finally: - # The public profiler must own the next evaluation and its cold clock. - clear() - - point_count = len(before.totals) - component_count = len(before.helicity_ids) * len(before.color_flow_ids) - record = { - "abi": OTF_RECURRENCE_AUTHORITY_VALIDATION_ABI, - "status": ResultStatus.OK.value, - "candidate_cell_id": cell.cell_id, - "candidate_artifact_id": candidate_artifact_id, - "workload": cell.workload.value, - "precision_digits": 16, - "relative_tolerance": RELATIVE_TOLERANCE, - "point_digest": point_digest(points), - "selector_sha256": _otf_selector_digest(cell, selector_contract), - "point_count": point_count, - "resolved_component_count": component_count, - "resolved_check_count": point_count * component_count, - "authority": authority_record, - "before_clear": before_record, - "after_clear": after_record, - "lifecycle": { - "authority_artifact_loaded_only": True, - "candidate_loaded_before_validation": True, - "validated_before_clear": True, - "validated_after_clear": True, - "clear_call_count": 2, - "final_clear_before_profile": True, - }, - } - validate_on_the_fly_recurrence_authority_validation_record( - record, - expected_cell=cell, - selector_contract=selector_contract.as_dict(), - candidate_artifact_id=candidate_artifact_id, - expected_authority_cell_id=authority_cell.cell_id, - ) - return record - - -def _require_otf_sha256(value: object, field: str) -> str: - if not isinstance(value, str) or not _SHA256_PATTERN.fullmatch(value): - raise ValueError(f"on-the-fly recurrence-authority {field} is not SHA-256") - return value - - -def _validate_otf_compact_summary( - value: object, - *, - field: str, - expected_checks: int, - expected_components: int | None = None, - relative_tolerance: float, -) -> None: - if not isinstance(value, Mapping): - raise ValueError(f"on-the-fly recurrence-authority {field} is not an object") - expected = { - "check_count", - "maximum_conditioned_residual", - "maximum_absolute_delta", - } - if expected_components is not None: - expected.add("component_count") - check_count = value.get("check_count") - if ( - set(value) != expected - or isinstance(check_count, bool) - or not isinstance(check_count, int) - or check_count != expected_checks - ): - raise ValueError(f"on-the-fly recurrence-authority {field} counts differ") - if expected_components is not None: - component_count = value.get("component_count") - if ( - isinstance(component_count, bool) - or not isinstance(component_count, int) - or component_count != expected_components - ): - raise ValueError( - f"on-the-fly recurrence-authority {field} component count differs" - ) - for name in ("maximum_conditioned_residual", "maximum_absolute_delta"): - raw = value.get(name) - if ( - isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - or float(raw) < 0.0 - ): - raise ValueError( - f"on-the-fly recurrence-authority {field}.{name} is invalid" - ) - if float(value["maximum_conditioned_residual"]) > relative_tolerance: - raise ValueError(f"on-the-fly recurrence-authority {field} is not successful") - - -def validate_on_the_fly_recurrence_authority_validation_record( - value: object, - *, - expected_cell: CellSpec | None = None, - selector_contract: object = None, - candidate_artifact_id: str | None = None, - expected_authority_cell_id: str | None = None, -) -> None: - """Validate the compact, success-only OTF numerical preflight record.""" - - if not isinstance(value, Mapping): - raise ValueError("on-the-fly recurrence-authority validation must be an object") - expected_fields = { - "abi", - "status", - "candidate_cell_id", - "candidate_artifact_id", - "workload", - "precision_digits", - "relative_tolerance", - "point_digest", - "selector_sha256", - "point_count", - "resolved_component_count", - "resolved_check_count", - "authority", - "before_clear", - "after_clear", - "lifecycle", - } - if set(value) != expected_fields: - raise ValueError("on-the-fly recurrence-authority validation fields differ") - if ( - value.get("abi") != OTF_RECURRENCE_AUTHORITY_VALIDATION_ABI - or value.get("status") != ResultStatus.OK.value - or value.get("precision_digits") != 16 - or value.get("relative_tolerance") != RELATIVE_TOLERANCE - ): - raise ValueError("on-the-fly recurrence-authority validation header is invalid") - _require_otf_sha256(value.get("candidate_artifact_id"), "candidate_artifact_id") - _require_otf_sha256(value.get("point_digest"), "point_digest") - _require_otf_sha256(value.get("selector_sha256"), "selector_sha256") - point_count = value.get("point_count") - component_count = value.get("resolved_component_count") - check_count = value.get("resolved_check_count") - if ( - isinstance(point_count, bool) - or not isinstance(point_count, int) - or point_count < 1 - or isinstance(component_count, bool) - or not isinstance(component_count, int) - or component_count < 1 - or check_count != point_count * component_count - ): - raise ValueError( - "on-the-fly recurrence-authority validation counts are invalid" - ) - if ( - candidate_artifact_id is not None - and value.get("candidate_artifact_id") != candidate_artifact_id - ): - raise ValueError("on-the-fly candidate artifact ID differs") - - if expected_cell is not None: - if ( - expected_cell.measurement.execution_mode is not ExecutionMode.ON_THE_FLY - or expected_cell.measurement.accuracy is not Accuracy.LC - or value.get("candidate_cell_id") != expected_cell.cell_id - or value.get("workload") != expected_cell.workload.value - ): - raise ValueError("on-the-fly recurrence-authority candidate cell differs") - if not isinstance(selector_contract, Mapping): - raise ValueError( - "on-the-fly recurrence-authority selector contract is absent" - ) - try: - contract = SelectorContract.from_mapping(selector_contract) - except (TypeError, ValueError) as error: - raise ValueError( - "on-the-fly recurrence-authority selector contract is invalid" - ) from error - if value.get("point_digest") != contract.point_digest or value.get( - "selector_sha256" - ) != _otf_selector_digest(expected_cell, contract): - raise ValueError("on-the-fly recurrence-authority selector binding differs") - elif ( - not isinstance(value.get("candidate_cell_id"), str) - or not value.get("candidate_cell_id") - or value.get("workload") - not in { - Workload.SELECTED_FLOW.value, - Workload.ALL_FLOW.value, - } - ): - raise ValueError( - "on-the-fly recurrence-authority candidate identity is invalid" - ) - - authority = value.get("authority") - authority_fields = { - "cell_id", - "artifact_id", - "total_source_sha256", - "resolved_total_source_sha256", - "resolved_ordering_sha256", - "resolved_source_sha256", - "resolved_sum", - } - if not isinstance(authority, Mapping) or set(authority) != authority_fields: - raise ValueError("on-the-fly recurrence-authority fields differ") - authority_cell_id = authority.get("cell_id") - if not isinstance(authority_cell_id, str) or not authority_cell_id: - raise ValueError("on-the-fly recurrence-authority identity is invalid") - if ( - expected_authority_cell_id is not None - and authority_cell_id != expected_authority_cell_id - ): - raise ValueError("on-the-fly recurrence-authority catalog identity differs") - for field in ( - "artifact_id", - "total_source_sha256", - "resolved_total_source_sha256", - "resolved_ordering_sha256", - "resolved_source_sha256", - ): - _require_otf_sha256(authority.get(field), f"authority.{field}") - _validate_otf_compact_summary( - authority.get("resolved_sum"), - field="authority.resolved_sum", - expected_checks=point_count, - relative_tolerance=RELATIVE_TOLERANCE, - ) - - for stage_name in ("before_clear", "after_clear"): - stage = value.get(stage_name) - expected_stage_fields = { - "candidate_total_source_sha256", - "candidate_resolved_total_source_sha256", - "candidate_resolved_ordering_sha256", - "candidate_resolved_source_sha256", - "candidate_resolved_sum", - "comparison", - } - if not isinstance(stage, Mapping) or set(stage) != expected_stage_fields: - raise ValueError( - f"on-the-fly recurrence-authority {stage_name} fields differ" - ) - for field in ( - "candidate_total_source_sha256", - "candidate_resolved_total_source_sha256", - "candidate_resolved_ordering_sha256", - "candidate_resolved_source_sha256", - ): - _require_otf_sha256(stage.get(field), f"{stage_name}.{field}") - _validate_otf_compact_summary( - stage.get("candidate_resolved_sum"), - field=f"{stage_name}.candidate_resolved_sum", - expected_checks=point_count, - relative_tolerance=RELATIVE_TOLERANCE, - ) - comparison = stage.get("comparison") - if not isinstance(comparison, Mapping) or set(comparison) != { - "authority_cell_id", - "total", - "resolved_components", - }: - raise ValueError( - f"on-the-fly recurrence-authority {stage_name} comparison fields differ" - ) - if comparison.get("authority_cell_id") != authority_cell_id: - raise ValueError( - f"on-the-fly recurrence-authority {stage_name} identity differs" - ) - _validate_otf_compact_summary( - comparison.get("total"), - field=f"{stage_name}.comparison.total", - expected_checks=point_count, - relative_tolerance=RELATIVE_TOLERANCE, - ) - _validate_otf_compact_summary( - comparison.get("resolved_components"), - field=f"{stage_name}.comparison.resolved_components", - expected_checks=check_count, - expected_components=component_count, - relative_tolerance=RELATIVE_TOLERANCE, - ) - - expected_lifecycle = { - "authority_artifact_loaded_only": True, - "candidate_loaded_before_validation": True, - "validated_before_clear": True, - "validated_after_clear": True, - "clear_call_count": 2, - "final_clear_before_profile": True, - } - if value.get("lifecycle") != expected_lifecycle: - raise ValueError("on-the-fly recurrence-authority lifecycle is invalid") - - -def resolved_sum_validation( - runtime: RuntimeLike, - points: object, - *, - cell: CellSpec, - selector_contract: SelectorContract | None, - precision: int = 16, -) -> dict[str, object]: - selectors = _selector_kwargs(cell, selector_contract) - optimized = runtime.evaluate(points, precision=precision, **selectors) - resolved = runtime.evaluate_resolved(points, precision=precision, **selectors) - totals = tuple(resolved.total()) - if len(optimized) != len(totals): - raise RunnerError("optimized and resolved evaluations have different lengths") - scale_evidence = resolved_component_scale_evidence(resolved, points) - scales = scale_evidence["scales"] - if not isinstance(scales, list) or len(scales) != len(totals): - raise RunnerError("resolved scale evidence differs from evaluated points") - - records: list[dict[str, object]] = [] - for point_index, (optimized_value, resolved_value, raw_scale) in enumerate( - zip(optimized, totals, scales, strict=True) - ): - candidate = _real_nonnegative(optimized_value) - baseline = _real_nonnegative(resolved_value) - scale = float(raw_scale) - binding = { - field: scale_evidence[field] - for field in ( - "abi", - "point_digest", - "helicity_ids", - "color_flow_ids", - "resolved_ordering_sha256", - "resolved_source_sha256", - ) - } - binding["point_index"] = point_index - records.append( - pointwise_validation( - candidate, - baseline, - candidate_scale=max(scale, abs(candidate)), - baseline_scale=max(scale, abs(baseline)), - candidate_scale_source="resolved-component-l1", - baseline_scale_source="resolved-component-l1", - comparison_binding=binding, - ) - ) - maximum_absolute = max( - (float(record["absolute_difference"]) for record in records), default=0.0 - ) - maximum_relative = max( - (float(record["relative_difference"]) for record in records), default=0.0 - ) - maximum_conditioned = max( - (float(record["conditioned_residual"]) for record in records), default=0.0 - ) - passed = all(record["status"] == ResultStatus.OK.value for record in records) - return { - "abi": RESOLVED_SUM_VALIDATION_ABI, - "status": ( - ResultStatus.OK.value if passed else ResultStatus.VALIDATION_FAILED.value - ), - "maximum_absolute_difference": maximum_absolute, - "maximum_relative_difference": maximum_relative, - "maximum_conditioned_residual": maximum_conditioned, - "relative_tolerance": RELATIVE_TOLERANCE, - "point_digest": point_digest(points), - "helicity_ids": list(getattr(resolved, "helicity_ids", ())), - "color_flow_ids": list(getattr(resolved, "color_ids", ())), - "resolved_ordering_sha256": scale_evidence["resolved_ordering_sha256"], - "resolved_source_sha256": scale_evidence["resolved_source_sha256"], - "scale_source": "resolved-component-l1", - "precision_digits": precision, - "points": records, - } - - -def pointwise_validation( - candidate: float, - baseline: float, - *, - relative_tolerance: float = RELATIVE_TOLERANCE, - absolute_tolerance: float | None = None, - candidate_scale: float | None = None, - baseline_scale: float | None = None, - candidate_scale_source: str = "value-magnitude", - baseline_scale_source: str = "value-magnitude", - comparison_binding: Mapping[str, object] | None = None, -) -> dict[str, object]: - """Return a scale-conditioned comparison without an absolute escape hatch. - - ``absolute_tolerance`` remains an accepted keyword solely so callers from - the v1 API fail over without a signature break. It is deliberately not - used for acceptance and must be either absent or finite/non-negative. - """ - - numbers = (candidate, baseline, relative_tolerance) - if any(not math.isfinite(float(value)) for value in numbers): - raise ValueError("pointwise values and tolerance must be finite") - if relative_tolerance < 0.0: - raise ValueError("pointwise tolerance must be non-negative") - if absolute_tolerance is not None and ( - not math.isfinite(absolute_tolerance) or absolute_tolerance < 0.0 - ): - raise ValueError("legacy absolute tolerance must be finite and non-negative") - candidate_scale = abs(candidate) if candidate_scale is None else candidate_scale - baseline_scale = abs(baseline) if baseline_scale is None else baseline_scale - if any( - not math.isfinite(float(value)) or value < 0.0 - for value in (candidate_scale, baseline_scale) - ): - raise ValueError("comparison scales must be finite and non-negative") - if candidate_scale < abs(candidate) or baseline_scale < abs(baseline): - raise ValueError("comparison scale is smaller than its value magnitude") - absolute = abs(candidate - baseline) - relative = absolute / max(abs(baseline), 1.0e-300) - comparison_scale = max( - abs(candidate), abs(baseline), candidate_scale, baseline_scale - ) - if comparison_scale == 0.0: - if candidate != 0.0 or baseline != 0.0 or absolute != 0.0: - raise ValueError("zero comparison scale requires exact zero values") - conditioned_residual = 0.0 - else: - conditioned_residual = absolute / comparison_scale - error_bound = relative_tolerance * comparison_scale - passed = absolute <= error_bound - return { - "abi": CONDITIONED_COMPARISON_ABI, - "status": ( - ResultStatus.OK.value if passed else ResultStatus.VALIDATION_FAILED.value - ), - "candidate": candidate, - "baseline": baseline, - "candidate_scale": candidate_scale, - "baseline_scale": baseline_scale, - "candidate_scale_source": candidate_scale_source, - "baseline_scale_source": baseline_scale_source, - "comparison_scale": comparison_scale, - "absolute_difference": absolute, - "relative_difference": relative, - "conditioned_residual": conditioned_residual, - "error_bound": error_bound, - "relative_tolerance": relative_tolerance, - "comparison_binding": ( - None if comparison_binding is None else dict(comparison_binding) - ), - } - - -def validate_resolved_sum_validation_record(value: object) -> None: - """Validate v2 resolved-scale evidence or an exact-zero legacy record.""" - - if not isinstance(value, Mapping): - raise ValueError("resolved-sum validation must be an object") - if value.get("abi") != RESOLVED_SUM_VALIDATION_ABI: - expected_v1 = { - "status", - "maximum_absolute_difference", - "maximum_relative_difference", - "relative_tolerance", - "absolute_tolerance", - } - if set(value) != expected_v1: - raise ValueError("resolved-sum validation ABI is unsupported") - numbers: dict[str, float] = {} - for field in expected_v1 - {"status"}: - raw = value.get(field) - if ( - isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - or float(raw) < 0.0 - ): - raise ValueError(f"legacy resolved-sum {field} is invalid") - numbers[field] = float(raw) - old_passed = ( - numbers["maximum_absolute_difference"] <= numbers["absolute_tolerance"] - or numbers["maximum_relative_difference"] <= numbers["relative_tolerance"] - ) - if value.get("status") != ( - ResultStatus.OK.value - if old_passed - else ResultStatus.VALIDATION_FAILED.value - ): - raise ValueError("legacy resolved-sum status is inconsistent") - # v1 did not retain either side of each comparison, so a nonzero - # difference cannot be authenticated against the new symmetric scale. - if old_passed and numbers["maximum_absolute_difference"] != 0.0: - raise ValueError("legacy resolved-sum evidence is floor-only or unbound") - return - - expected = { - "abi", - "status", - "maximum_absolute_difference", - "maximum_relative_difference", - "maximum_conditioned_residual", - "relative_tolerance", - "point_digest", - "helicity_ids", - "color_flow_ids", - "resolved_ordering_sha256", - "resolved_source_sha256", - "scale_source", - "precision_digits", - "points", - } - if set(value) != expected: - raise ValueError("resolved-sum validation fields differ from the v2 ABI") - for field in ("point_digest", "resolved_ordering_sha256", "resolved_source_sha256"): - raw = value.get(field) - if ( - not isinstance(raw, str) - or len(raw) != 64 - or any(character not in "0123456789abcdef" for character in raw) - ): - raise ValueError(f"resolved-sum {field} is not SHA-256") - for field in ("helicity_ids", "color_flow_ids"): - raw = value.get(field) - if not isinstance(raw, list) or any( - not isinstance(item, str) or not item for item in raw - ): - raise ValueError(f"resolved-sum {field} is invalid") - if value.get("scale_source") != "resolved-component-l1": - raise ValueError("resolved-sum scale source is unsupported") - precision = value.get("precision_digits") - if isinstance(precision, bool) or not isinstance(precision, int) or precision < 1: - raise ValueError("resolved-sum precision is invalid") - relative_tolerance = value.get("relative_tolerance") - if ( - isinstance(relative_tolerance, bool) - or not isinstance(relative_tolerance, (int, float)) - or not math.isfinite(float(relative_tolerance)) - or float(relative_tolerance) < 0.0 - ): - raise ValueError("resolved-sum relative tolerance is invalid") - records = value.get("points") - if not isinstance(records, list) or not records: - raise ValueError("resolved-sum points are unavailable") - for point_index, record in enumerate(records): - validate_conditioned_comparison_record(record, require_binding=True) - assert isinstance(record, Mapping) - if float(record["relative_tolerance"]) != float(relative_tolerance): - raise ValueError("resolved-sum point tolerance differs") - binding = record.get("comparison_binding") - if not isinstance(binding, Mapping): - raise ValueError("resolved-sum point binding is unavailable") - expected_binding = { - "abi": RESOLVED_COMPONENT_SCALE_ABI, - "point_digest": value["point_digest"], - "helicity_ids": value["helicity_ids"], - "color_flow_ids": value["color_flow_ids"], - "resolved_ordering_sha256": value["resolved_ordering_sha256"], - "resolved_source_sha256": value["resolved_source_sha256"], - "point_index": point_index, - } - if dict(binding) != expected_binding: - raise ValueError("resolved-sum point binding differs from its source") - maximum_absolute = max(float(record["absolute_difference"]) for record in records) - maximum_relative = max(float(record["relative_difference"]) for record in records) - maximum_conditioned = max( - float(record["conditioned_residual"]) for record in records - ) - for field, expected_value in ( - ("maximum_absolute_difference", maximum_absolute), - ("maximum_relative_difference", maximum_relative), - ("maximum_conditioned_residual", maximum_conditioned), - ): - raw = value.get(field) - if ( - isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - or float(raw) != expected_value - ): - raise ValueError(f"resolved-sum {field} is inconsistent") - status = ( - ResultStatus.OK.value - if all(record["status"] == ResultStatus.OK.value for record in records) - else ResultStatus.VALIDATION_FAILED.value - ) - if value.get("status") != status: - raise ValueError("resolved-sum status is inconsistent") - - -@dataclass(frozen=True, slots=True) -class _ArenaStatistics: - standard_deviation: float - standard_error: float - relative_standard_error: float - - -@dataclass(frozen=True, slots=True) -class _ArenaBenchmarkResult: - effective_config: object - sample_count: int - wall_time_per_point: float - evaluator_time_per_point: None - evaluator_total_time_per_point: float - uncertainty: _ArenaStatistics - environment: Mapping[str, object] - timing_breakdown: Mapping[str, object] - arena_profile_evidence: Mapping[str, object] - evaluator_uncertainty: None = None - - -def _positive_duration(value: object, name: str) -> float: - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or float(value) <= 0.0 - ): - raise RunnerError(f"{name} must be finite and positive") - return float(value) - - -def _arena_benchmark_batch(points: object, batch_size: int) -> tuple[object, ...]: - if ( - not isinstance(points, Sequence) - or isinstance(points, (str, bytes, bytearray)) - or not points - ): - raise RunnerError("Arena report benchmark requires validation points") - if ( - isinstance(batch_size, bool) - or not isinstance(batch_size, int) - or batch_size < 1 - ): - raise RunnerError("Arena report benchmark batch size must be positive") - source = tuple(points) - return tuple(source[index % len(source)] for index in range(batch_size)) - - -def _arena_statistics(samples: Sequence[float]) -> _ArenaStatistics: - if len(samples) < _ARENA_MINIMUM_SAMPLES: - raise RunnerError( - f"Arena report benchmark requires at least {_ARENA_MINIMUM_SAMPLES} " - "timed blocks" - ) - mean = statistics.fmean(samples) - deviation = statistics.stdev(samples) - error = deviation / math.sqrt(len(samples)) - relative = error / mean - return _ArenaStatistics( - standard_deviation=deviation, - standard_error=error, - relative_standard_error=relative, - ) - - -def _calibrate_arena_repetitions( - timer: object, - batch: tuple[object, ...], - *, - target_runtime: float, - sample_count: int, - selector_arguments: Mapping[str, object], - progress: ProgressSink | None = None, - task_id: str = "report-profile:calibration", -) -> tuple[int, list[dict[str, object]]]: - if not callable(timer): - raise RunnerError("native unprofiled wall timer is unavailable") - if progress is not None: - from pyamplicol.reporting import ProgressUpdate - - target_per_block = target_runtime / sample_count - repetitions = 1 - observed = _positive_duration( - timer(batch, repetitions, **selector_arguments), - "Arena wall calibration duration", - ) - blocks = [{"repetitions": repetitions, "duration_seconds": observed}] - minimum_repetition_confirmed = False - if progress is not None: - progress.emit( - ProgressUpdate( - task_id, - 1, - _ARENA_MAX_CALIBRATION_BLOCKS + 1, - "initial timing block", - { - "duration_seconds": observed, - "repetitions": repetitions, - }, - ) - ) - for _ in range(_ARENA_MAX_CALIBRATION_BLOCKS): - estimate = math.ceil(repetitions * target_per_block / observed) - candidate = min(max(estimate, 1), _ARENA_MAX_REPETITIONS) - if candidate == repetitions: - # A busy worker can make the first one-repetition probe arbitrarily - # slow. At the repetition floor that outlier otherwise terminates - # calibration immediately, even when the warmed steady-state call - # is orders of magnitude faster. Confirm the floor once and use - # the faster observation: scheduling contention can delay a probe, - # but it cannot make the native work complete spuriously early. - if ( - repetitions == 1 - and observed >= target_per_block - and not minimum_repetition_confirmed - ): - confirmation = _positive_duration( - timer(batch, repetitions, **selector_arguments), - "Arena wall calibration confirmation duration", - ) - blocks.append( - { - "repetitions": repetitions, - "duration_seconds": confirmation, - } - ) - observed = min(observed, confirmation) - minimum_repetition_confirmed = True - if progress is not None: - progress.emit( - ProgressUpdate( - task_id, - len(blocks), - _ARENA_MAX_CALIBRATION_BLOCKS + 1, - "confirming minimum-repetition timing", - { - "duration_seconds": confirmation, - "selected_duration_seconds": observed, - "repetitions": repetitions, - }, - ) - ) - continue - break - repetitions = candidate - observed = _positive_duration( - timer(batch, repetitions, **selector_arguments), - "Arena wall calibration duration", - ) - blocks.append({"repetitions": repetitions, "duration_seconds": observed}) - if progress is not None: - progress.emit( - ProgressUpdate( - task_id, - len(blocks), - _ARENA_MAX_CALIBRATION_BLOCKS + 1, - "refining repetitions", - { - "duration_seconds": observed, - "repetitions": repetitions, - }, - ) - ) - ratio = observed / target_per_block - if 0.75 <= ratio <= 1.5: - break - return repetitions, blocks - - -def _run_arena_benchmark( - runtime: object, - points: object, - *, - execution_mode: str, - benchmark_config: object, - selectors: Mapping[str, tuple[str, ...] | None], - progress: ProgressSink | None = None, - chunk_guard: ProfilingChunkGuard | None = None, -) -> _ArenaBenchmarkResult: - """Measure native wall time and authenticate a paired private Arena profile.""" - - if execution_mode not in {"compiled", "eager"}: - raise RunnerError( - "private warmed Arena profiling is supported only for eager and " - "compiled report cells" - ) - timer = getattr(runtime, "_benchmark_f64_wall_time", None) - profiler = getattr(runtime, "_profile_arena_repeated", None) - if not callable(timer): - raise RunnerError( - "current report timing requires runtime._benchmark_f64_wall_time" - ) - if not callable(profiler): - raise RunnerError( - "current report timing requires runtime._profile_arena_repeated" - ) - target_runtime = float(getattr(benchmark_config, "target_runtime", 0.0)) - batch_size = getattr(benchmark_config, "batch_size", None) - warmup_runs = getattr(benchmark_config, "warmup_runs", None) - minimum_samples = getattr(benchmark_config, "minimum_samples", None) - precision = getattr(benchmark_config, "precision", None) - if not math.isfinite(target_runtime) or target_runtime <= 0.0: - raise RunnerError("Arena report target runtime must be finite and positive") - if ( - isinstance(warmup_runs, bool) - or not isinstance(warmup_runs, int) - or warmup_runs < 0 - ): - raise RunnerError("Arena report warmup count is invalid") - if ( - isinstance(minimum_samples, bool) - or not isinstance(minimum_samples, int) - or minimum_samples < _ARENA_MINIMUM_SAMPLES - ): - raise RunnerError( - f"Arena report timing requires at least {_ARENA_MINIMUM_SAMPLES} samples" - ) - if precision != 16: - raise RunnerError("Arena report timing requires native f64 precision") - if progress is not None: - from pyamplicol.reporting import ProgressEnd, ProgressStart, ProgressUpdate - - batch = _arena_benchmark_batch(points, batch_size) - selector_arguments: dict[str, object] = { - "helicities": selectors.get("helicities"), - "color_flows": selectors.get("color_flows"), - "precision": 16, - } - profile_arguments = {**selector_arguments, "include_values": False} - timer_seconds_per_repetition: float | None = None - profiler_seconds_per_repetition: float | None = None - - def guarded_timer(repetitions: int) -> float: - nonlocal timer_seconds_per_repetition - estimate = ( - None - if timer_seconds_per_repetition is None - else timer_seconds_per_repetition * repetitions - ) - if chunk_guard is not None: - chunk_guard(estimate, f"{execution_mode} evaluator timing chunk") - observed = _positive_duration( - timer(batch, repetitions, **selector_arguments), - "Arena evaluator duration", - ) - timer_seconds_per_repetition = observed / repetitions - return observed - - def guarded_profiler( - repetitions: int, - *, - measure_elapsed: bool = True, - ) -> tuple[Mapping[str, object], float]: - nonlocal profiler_seconds_per_repetition - estimated_per_repetition = ( - profiler_seconds_per_repetition - if profiler_seconds_per_repetition is not None - else timer_seconds_per_repetition - ) - estimate = ( - None - if estimated_per_repetition is None - else estimated_per_repetition * repetitions - ) - if chunk_guard is not None: - chunk_guard(estimate, f"{execution_mode} attribution chunk") - started = time.perf_counter() if measure_elapsed else None - raw = profiler(batch, repetitions, **profile_arguments) - observed = ( - (time.perf_counter() - started) - if started is not None - else (estimate or 0.0) - ) - if not isinstance(raw, Mapping): - raise RunnerError("native warmed Arena profile is not an object") - if observed > 0.0: - profiler_seconds_per_repetition = observed / repetitions - return raw, observed - - parent_task_id = "report-profile" - warmup_task_id = f"{parent_task_id}:warmup" - calibration_task_id = f"{parent_task_id}:calibration" - samples_task_id = f"{parent_task_id}:samples" - started = time.perf_counter() - active_task_id: str | None = None - if progress is not None: - progress.emit( - ProgressStart( - parent_task_id, - f"Profiling {execution_mode} runtime", - None, - unit="stages", - details={ - "target_runtime_seconds": target_runtime, - "minimum_samples": minimum_samples, - }, - ) - ) - try: - active_task_id = warmup_task_id - if progress is not None: - progress.emit( - ProgressStart( - warmup_task_id, - "Warming the native runtime", - warmup_runs, - parent_task_id=parent_task_id, - unit="runs", - ) - ) - warmup_started = time.perf_counter() - for index in range(warmup_runs): - guarded_timer(1) - warmup_profile, _warmup_profile_elapsed = guarded_profiler( - 1, - measure_elapsed=False, - ) - try: - build_arena_profile_evidence( - (warmup_profile,), - execution_mode=execution_mode, - repetitions_per_profile=1, - batch_size=len(batch), - ) - except ArenaProfileEvidenceError as error: - raise RunnerError(f"invalid warmed Arena profile: {error}") from error - if progress is not None: - progress.emit( - ProgressUpdate( - warmup_task_id, - index + 1, - warmup_runs, - "runtime warmed", - ) - ) - warmup_elapsed = time.perf_counter() - warmup_started - if progress is not None: - progress.emit( - ProgressEnd( - warmup_task_id, - elapsed_seconds=warmup_elapsed, - ) - ) - active_task_id = calibration_task_id - if progress is not None: - progress.emit( - ProgressStart( - calibration_task_id, - "Calibrating repetitions", - _ARENA_MAX_CALIBRATION_BLOCKS + 1, - parent_task_id=parent_task_id, - unit="blocks", - ) - ) - calibration_started = time.perf_counter() - repetitions, calibration_blocks = _calibrate_arena_repetitions( - lambda _batch, repetitions, **_arguments: guarded_timer(repetitions), - batch, - target_runtime=target_runtime, - sample_count=minimum_samples, - selector_arguments=selector_arguments, - progress=progress, - task_id=calibration_task_id, - ) - calibration_elapsed = time.perf_counter() - calibration_started - if progress is not None: - progress.emit( - ProgressEnd( - calibration_task_id, - elapsed_seconds=calibration_elapsed, - details={ - "blocks": len(calibration_blocks), - "repetitions": repetitions, - }, - ) - ) - active_task_id = samples_task_id - if progress is not None: - progress.emit( - ProgressStart( - samples_task_id, - "Measuring paired runtime samples", - _ARENA_MAX_SAMPLES, - parent_task_id=parent_task_id, - unit="samples", - details={ - "minimum_samples": minimum_samples, - "target_runtime_seconds": target_runtime, - }, - ) - ) - samples_started = time.perf_counter() - evaluated_points = repetitions * len(batch) - headline_samples: list[float] = [] - headline_durations: list[float] = [] - evaluator_total_durations: list[float] = [] - raw_profiles: list[Mapping[str, object]] = [] - profile_elapsed = 0.0 - while ( - len(headline_samples) < minimum_samples - or math.fsum(headline_durations) < target_runtime - ): - if len(headline_samples) >= _ARENA_MAX_SAMPLES: - raise RunnerError( - "Arena report benchmark could not reach its target duration " - f"within {_ARENA_MAX_SAMPLES} samples" - ) - headline_started = time.perf_counter() - evaluator_total_duration = guarded_timer(repetitions) - wall_duration = _positive_duration( - time.perf_counter() - headline_started, - "Arena headline wall duration", - ) - headline_durations.append(wall_duration) - evaluator_total_durations.append(evaluator_total_duration) - headline_samples.append(wall_duration / evaluated_points) - raw_profile, raw_profile_elapsed = guarded_profiler(repetitions) - profile_elapsed += raw_profile_elapsed - raw_profiles.append(raw_profile) - if progress is not None: - progress.emit( - ProgressUpdate( - samples_task_id, - len(headline_samples), - _ARENA_MAX_SAMPLES, - "sample complete", - { - "elapsed_seconds": math.fsum(headline_durations), - "minimum_samples": minimum_samples, - "target_runtime_seconds": target_runtime, - }, - ) - ) - samples_elapsed = time.perf_counter() - samples_started - if progress is not None: - progress.emit( - ProgressEnd( - samples_task_id, - elapsed_seconds=samples_elapsed, - details={ - "samples": len(headline_samples), - "measured_seconds": math.fsum(headline_durations), - }, - ) - ) - active_task_id = None - try: - arena_evidence = build_arena_profile_evidence( - raw_profiles, - execution_mode=execution_mode, - repetitions_per_profile=repetitions, - batch_size=len(batch), - ) - except ArenaProfileEvidenceError as error: - raise RunnerError(f"invalid warmed Arena profile: {error}") from error - sample_count = len(headline_samples) - uncertainty = _arena_statistics(headline_samples) - except BaseException as error: - if progress is not None: - if active_task_id is not None: - progress.emit( - ProgressEnd(active_task_id, success=False, message=str(error)) - ) - progress.emit( - ProgressEnd( - parent_task_id, - success=False, - message=str(error), - elapsed_seconds=time.perf_counter() - started, - ) - ) - raise - mean_wall = statistics.fmean(headline_samples) - achieved_runtime = math.fsum(headline_durations) - evaluator_total_accumulated = math.fsum(evaluator_total_durations) - measured_evaluations = sample_count * repetitions - measured_points = measured_evaluations * len(batch) - evaluator_total_time_per_point = evaluator_total_accumulated / measured_points - profile_total_elapsed = time.perf_counter() - started - if progress is not None: - progress.emit( - ProgressEnd( - parent_task_id, - elapsed_seconds=profile_total_elapsed, - ) - ) - return _ArenaBenchmarkResult( - effective_config=benchmark_config, - sample_count=sample_count, - wall_time_per_point=mean_wall, - evaluator_time_per_point=None, - evaluator_total_time_per_point=evaluator_total_time_per_point, - uncertainty=uncertainty, - environment={ - "wall_time_source": "runtime_core_repeated_wall_time", - "wall_time_sample_pass": "runtime._benchmark_f64_wall_time", - "evaluator_time_raw_seconds_per_point": None, - "evaluator_time_status": UNAVAILABLE_STATUS, - "evaluator_time_ratio_eligible": False, - "evaluator_time_sample_pass": ARENA_PROFILE_SAMPLE_PASS, - "evaluator_total_time_raw_seconds_per_point": ( - evaluator_total_time_per_point - ), - "evaluator_total_time_status": "measured", - "evaluator_total_time_ratio_eligible": False, - "evaluator_total_time_source": EVALUATOR_TOTAL_TIMING_SOURCE, - "evaluator_total_time_sample_contract": (EVALUATOR_TOTAL_SAMPLE_CONTRACT), - "evaluator_total_accumulated_seconds": (evaluator_total_accumulated), - "timing_breakdown_sample_pass": ARENA_PROFILE_SAMPLE_PASS, - "profile_protocol": ARENA_PROFILE_PROTOCOL, - "report_command_path": PAIRED_ARENA_PROFILE_COMMAND_PATH, - "report_public_cli_path": None, - "profile_attribution_boundary": ARENA_PROFILE_BOUNDARY, - "profile_attribution_borrowed_flat_input": True, - "profile_attribution_preallocated_output": True, - "profile_attribution_phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "profile_attribution_evaluator_timing_available": False, - "profile_attribution_paired_with_headline": True, - "profile_attribution_identical_batch": True, - "profile_attribution_identical_repetitions": True, - "execution_mode": execution_mode, - "evaluator_sample_count": sample_count, - "native_profile_sample_count": sample_count, - "native_profile_points_per_sample": evaluated_points, - "native_profile_repetitions_per_sample": repetitions, - "native_profile_batch_size": len(batch), - "timing_sample_contract": PAIRED_TIMING_SAMPLE_CONTRACT, - "elapsed_seconds": achieved_runtime, - "warmup_elapsed_seconds": warmup_elapsed, - "calibration_elapsed_seconds": calibration_elapsed, - "calibration_outer_elapsed_seconds": calibration_elapsed, - "measurement_phase_elapsed_seconds": samples_elapsed, - "profile_total_elapsed_seconds": profile_total_elapsed, - "completed_sample_count": sample_count, - "planned_sample_count": sample_count, - "repetitions_per_sample": repetitions, - "measured_point_count": measured_points, - "profile_attribution_evaluation_count": measured_evaluations, - "profile_attribution_point_count": measured_points, - "profile_attribution_elapsed_seconds": profile_elapsed, - "headline_block_durations_seconds": headline_durations, - "calibration": { - "target_seconds_per_block": (target_runtime / minimum_samples), - "blocks": calibration_blocks, - }, - "interrupted": False, - }, - timing_breakdown={ - "sample_count": sample_count, - "execution_mode": execution_mode, - "wall_time": { - "mean_seconds_per_point": arena_evidence[ - "warmed_boundary_wall_seconds_per_point" - ], - }, - "evaluator_call_time": None, - "raw_profile_samples": arena_evidence["raw_profiles"], - }, - arena_profile_evidence=arena_evidence, - ) - - -def _profile_cli_argv( - benchmark_config: BenchmarkConfig, -) -> tuple[str, ...]: - """Return public ``pyamplicol profile`` arguments for one loaded runtime.""" - - arguments = [ - "profile", - ".pyamplicol-loaded-runtime", - "--target-runtime", - str(benchmark_config.target_runtime), - "--batch-size", - str(benchmark_config.batch_size), - "--precision", - str(benchmark_config.precision), - "--warmup-runs", - str(benchmark_config.warmup_runs), - "--minimum-samples", - str(benchmark_config.minimum_samples), - "--json", - "--progress", - "off", - ] - for identifier in benchmark_config.helicity_ids: - arguments.extend(("--helicity", str(identifier))) - for identifier in benchmark_config.color_flow_ids: - arguments.extend(("--color-flow", str(identifier))) - return tuple(arguments) - - -def _run_report_benchmark( - runtime: object, - points: object, - *, - execution_mode: ExecutionMode, - benchmark_config: BenchmarkConfig, - selectors: Mapping[str, tuple[str, ...] | None], - progress: ProgressSink | None = None, - chunk_guard: ProfilingChunkGuard | None = None, -) -> object: - """Select the authenticated timing command path without fallback. - - Recurrence and on-the-fly use the public ``profile`` parser/config/dispatch - path. Their narrowly scoped service override supplies the already - authenticated runtime and exact in-memory point set, avoiding an artifact - reload inside the measured campaign. Compiled/eager retain the report-only - paired private Arena protocol because the public profiler does not expose - that paired headline/attribution boundary. - """ - - if execution_mode in {ExecutionMode.EAGER, ExecutionMode.COMPILED}: - backend = getattr(runtime, "_backend", None) - if backend is None: - raise RunnerError( - "eager/compiled report timing requires the runtime's private " - "native backend" - ) - return _run_arena_benchmark( - backend, - points, - execution_mode=execution_mode.value, - benchmark_config=benchmark_config, - selectors=selectors, - progress=progress, - chunk_guard=chunk_guard, - ) - if execution_mode in {ExecutionMode.RECURRENCE, ExecutionMode.ON_THE_FLY}: - from pyamplicol.api import BenchmarkRunner - from pyamplicol.cli import CliInvocation, parse_cli - from pyamplicol.cli.handlers import DefaultCliServices, dispatch - from pyamplicol.config import RunConfig - from pyamplicol.reporting import NullProgressSink - - selected_progress = progress or NullProgressSink() - invocation = parse_cli(_profile_cli_argv(benchmark_config)) - if not isinstance(invocation, CliInvocation): - raise RunnerError("public profile parser returned a non-command invocation") - resolution = invocation.resolve() - if resolution.effective.benchmark != benchmark_config: - raise RunnerError( - "public profile arguments do not preserve report benchmark settings" - ) - expected_helicities = tuple(selectors["helicities"] or ()) - expected_color_flows = tuple(selectors["color_flows"] or ()) - if ( - resolution.effective.benchmark.helicity_ids != expected_helicities - or resolution.effective.benchmark.color_flow_ids != expected_color_flows - ): - raise RunnerError( - "public profile arguments do not preserve report selectors" - ) - - class _LoadedRuntimeProfileServices(DefaultCliServices): - """Inject only the authenticated loaded runtime and exact points. - - Parsing, typed resolution, progress propagation, benchmark settings, - and dispatch remain the public ``pyamplicol profile`` path. - """ - - def benchmark( - self, - config: RunConfig, - command_progress: ProgressSink, - ) -> object: - profile_started = time.perf_counter() - runner_arguments: dict[str, object] = { - "progress": command_progress, - } - if chunk_guard is not None: - runner_arguments["_chunk_guard"] = chunk_guard - result = BenchmarkRunner(config, **runner_arguments).run( - runtime, - points=points, - ) - profile_total_elapsed = time.perf_counter() - profile_started - environment = getattr(result, "environment", None) - if not isinstance(environment, Mapping): - raise RunnerError( - "public profile result does not retain environment evidence" - ) - return replace( - result, - environment={ - **environment, - "report_command_path": (LOADED_RUNTIME_PROFILE_COMMAND_PATH), - "report_public_cli_path": PUBLIC_CLI_COMMAND_PATH, - "profile_total_elapsed_seconds": profile_total_elapsed, - }, - ) - - return dispatch( - resolution.effective, - _LoadedRuntimeProfileServices(), - selected_progress, - dry_run=invocation.dry_run, - ) - raise RunnerError( - f"unsupported pyAmpliCol report execution mode: {execution_mode.value}" - ) - - -def _warmup_finite_number( - value: object, - field: str, - *, - positive: bool = False, -) -> float: - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or (float(value) <= 0.0 if positive else float(value) < 0.0) - ): - qualifier = "positive" if positive else "non-negative" - raise ValueError(f"runtime profile {field} must be a finite {qualifier} number") - return float(value) - - -def _warmup_nonnegative_integer(value: object, field: str) -> int: - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise ValueError(f"runtime profile {field} must be a non-negative integer") - return value - - -def _warmup_boolean(value: object, field: str) -> bool: - if not isinstance(value, bool): - raise ValueError(f"runtime profile {field} must be a boolean") - return value - - -def _warmup_plain_value(value: object) -> object: - if isinstance(value, Mapping): - return {str(key): _warmup_plain_value(item) for key, item in value.items()} - if isinstance(value, tuple): - return tuple(_warmup_plain_value(item) for item in value) - if isinstance(value, list): - return [_warmup_plain_value(item) for item in value] - return value - - -def _validate_otf_runtime_state_census( - value: object, - field: str, -) -> Mapping[str, object]: - if not isinstance(value, Mapping): - raise ValueError(f"runtime profile {field} must be a mapping") - expected_fields = { - "kind", - "process_id", - "family_cache_policy", - "family_cache_limit", - "active_family_union_census", - *OTF_RUNTIME_STATE_COUNT_FIELDS, - } - if set(value) != expected_fields: - raise ValueError(f"runtime profile {field} has invalid runtime census fields") - if value.get("kind") != OTF_RUNTIME_STATE_CENSUS_KIND: - raise ValueError(f"runtime profile {field} has an invalid runtime census kind") - if value.get("family_cache_policy") != OTF_RUNTIME_STATE_FAMILY_CACHE_POLICY: - raise ValueError( - f"runtime profile {field} has an unsupported family cache policy" - ) - family_cache_limit = value.get("family_cache_limit") - if ( - isinstance(family_cache_limit, bool) - or not isinstance(family_cache_limit, int) - or family_cache_limit != OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT - ): - raise ValueError( - f"runtime profile {field} must use family cache limit " - f"{OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT}" - ) - process_id = value.get("process_id") - if not isinstance(process_id, str) or not process_id: - raise ValueError( - f"runtime profile {field} runtime census has an invalid process ID" - ) - for count_field in OTF_RUNTIME_STATE_COUNT_FIELDS: - _warmup_nonnegative_integer(value[count_field], f"{field}.{count_field}") - if value["retained_family_count"] > OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT: - raise ValueError( - f"runtime profile {field} retained family count exceeds its cache limit" - ) - - active = value.get("active_family_union_census") - if active is None: - return value - if not isinstance(active, Mapping): - raise ValueError( - f"runtime profile {field} active-family census must be a mapping or null" - ) - expected_active_fields = { - "basis", - "scope", - *OTF_ACTIVE_FAMILY_COUNT_FIELDS, - } - if set(active) != expected_active_fields: - raise ValueError( - f"runtime profile {field} has invalid active-family census fields" - ) - if ( - active.get("basis") != "shared-query-family-union-v1" - or active.get("scope") != "active-family-union" - ): - raise ValueError( - f"runtime profile {field} has an invalid active-family census identity" - ) - for count_field in OTF_ACTIVE_FAMILY_COUNT_FIELDS: - _warmup_nonnegative_integer( - active[count_field], - f"{field}.active_family_union_census.{count_field}", - ) - if ( - active["query_count"] < 1 - or active["union_unique_current_count"] - > active["union_unique_current_component_count"] - or active["union_amplitude_destination_count"] < 1 - or active["union_amplitude_destination_count"] > active["query_count"] - or active["query_count"] > value["retained_request_count"] - or active["union_amplitude_destination_count"] - > value["retained_amplitude_destination_count"] - ): - raise ValueError( - f"runtime profile {field} active-family census is inconsistent" - ) - for role in OTF_OPERATION_ROLES: - if active[f"union_{role}_executor_call_groups"] > active[f"union_{role}_rows"]: - raise ValueError( - f"runtime profile {field} active-family {role} call-group " - "count exceeds its row count" - ) - return value - - -def _otf_runtime_state_is_cold(value: Mapping[str, object]) -> bool: - return all(value[field] == 0 for field in OTF_RUNTIME_STATE_COUNT_FIELDS) and ( - value["active_family_union_census"] is None - ) - - -def _otf_runtime_state_is_retained(value: Mapping[str, object]) -> bool: - if ( - value["pending_family_count"] != 0 - or value["process_preparation_count"] != 1 - or value["retained_family_count"] != OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT - or value["retained_selection_count"] != OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT - or _warmup_nonnegative_integer( - value["retained_request_count"], - "retained_request_count", - ) - < 1 - ): - return False - executable_counts = tuple( - _warmup_nonnegative_integer(value[field], field) - for field in OTF_RUNTIME_STATE_RETAINED_EXECUTABLE_FIELDS - ) - active = value["active_family_union_census"] - if isinstance(active, Mapping): - return ( - executable_counts[0] > 0 - and executable_counts[1] == OTF_RUNTIME_STATE_FAMILY_CACHE_LIMIT - and executable_counts[2] > 0 - ) - return active is None and all(count == 0 for count in executable_counts) - - -def validate_profile_warmup_evidence( - value: object, - *, - execution_mode: ExecutionMode | str, - expected_batch_size: int | None = None, - expected_warmup_run_count: int | None = None, -) -> None: - """Validate bounded OTF cold preparation and conventional warm-ups. - - The fields are the flat environment evidence emitted by - :class:`BenchmarkBackend`; this validator deliberately does not introduce a - second timing record or reinterpret the backend's clocks. - """ - - if not isinstance(value, Mapping): - raise ValueError("runtime profile warm-up evidence must be a mapping") - mode = ( - execution_mode.value - if isinstance(execution_mode, ExecutionMode) - else execution_mode - ) - is_otf = mode == ExecutionMode.ON_THE_FLY.value - conventional_present = CONVENTIONAL_WARMUP_FIELDS & value.keys() - cold_present = OTF_COLD_WARMUP_FIELDS & value.keys() - if is_otf and conventional_present != CONVENTIONAL_WARMUP_FIELDS: - missing = sorted(CONVENTIONAL_WARMUP_FIELDS - value.keys()) - raise ValueError( - "on-the-fly runtime profile has incomplete conventional warm-up " - f"evidence; missing={missing}" - ) - if is_otf and cold_present != OTF_COLD_WARMUP_FIELDS: - missing = sorted(OTF_COLD_WARMUP_FIELDS - value.keys()) - raise ValueError( - "on-the-fly runtime profile has incomplete cold warm-up evidence; " - f"missing={missing}" - ) - if not is_otf and cold_present: - raise ValueError( - "non-on-the-fly runtime profile cannot contain cold warm-up evidence" - ) - if ( - not is_otf - and conventional_present - and conventional_present != CONVENTIONAL_WARMUP_FIELDS - ): - if conventional_present != {"warmup_elapsed_seconds"}: - missing = sorted(CONVENTIONAL_WARMUP_FIELDS - value.keys()) - raise ValueError( - "runtime profile has unsupported partial conventional warm-up " - f"evidence; missing={missing}" - ) - _warmup_finite_number( - value["warmup_elapsed_seconds"], - "warmup_elapsed_seconds", - ) - return - if not conventional_present: - return - - warmup_elapsed = _warmup_finite_number( - value["warmup_elapsed_seconds"], - "warmup_elapsed_seconds", - ) - warmup_count = _warmup_nonnegative_integer( - value["warmup_configured_run_count"], - "warmup_configured_run_count", - ) - if expected_warmup_run_count is not None and ( - isinstance(expected_warmup_run_count, bool) - or not isinstance(expected_warmup_run_count, int) - or expected_warmup_run_count < 0 - or warmup_count != expected_warmup_run_count - ): - raise ValueError( - "runtime profile warmup_configured_run_count does not match the " - "effective benchmark configuration" - ) - warmup_batch_size = _warmup_nonnegative_integer( - value["warmup_batch_size"], - "warmup_batch_size", - ) - if warmup_batch_size < 1: - raise ValueError("runtime profile warmup_batch_size must be positive") - warmup_point_count = _warmup_nonnegative_integer( - value["warmup_point_count"], - "warmup_point_count", - ) - if warmup_point_count != warmup_count * warmup_batch_size: - raise ValueError( - "runtime profile warmup_point_count does not equal configured runs " - "times batch size" - ) - raw_runs = value["warmup_run_outer_wall_seconds"] - if isinstance(raw_runs, (str, bytes)) or not isinstance(raw_runs, Sequence): - raise ValueError( - "runtime profile warmup_run_outer_wall_seconds must be a sequence" - ) - runs = tuple( - _warmup_finite_number(item, "warmup_run_outer_wall_seconds[]") - for item in raw_runs - ) - if len(runs) != warmup_count: - raise ValueError( - "runtime profile warmup_run_outer_wall_seconds length does not match " - "the configured run count" - ) - warmup_sum = sum(runs) - consistency_tolerance = max( - 1.0e-12, - max(abs(warmup_elapsed), abs(warmup_sum)) * 1.0e-12, - ) - if abs(warmup_sum - warmup_elapsed) > consistency_tolerance: - raise ValueError( - "runtime profile warmup_elapsed_seconds does not equal its per-run " - "outer-wall timing sum" - ) - first_run = value["first_warmup_run_outer_wall_seconds"] - if warmup_count == 0: - if first_run is not None: - raise ValueError( - "runtime profile first_warmup_run_outer_wall_seconds must be null " - "when no warm-up runs are configured" - ) - elif ( - _warmup_finite_number( - first_run, - "first_warmup_run_outer_wall_seconds", - ) - != runs[0] - ): - raise ValueError( - "runtime profile first warm-up timing does not match the first per-run " - "timing" - ) - if value["warmup_timer_source"] != WARMUP_TIMER_SOURCE: - raise ValueError("runtime profile warmup_timer_source is unsupported") - if value["warmup_timing_scope"] != CONVENTIONAL_WARMUP_TIMING_SCOPE: - raise ValueError("runtime profile warmup_timing_scope is unsupported") - - if not is_otf: - return - cold_elapsed = _warmup_finite_number( - value["cold_warmup_elapsed_seconds"], - "cold_warmup_elapsed_seconds", - positive=True, - ) - if cold_elapsed <= 0.0: # Defensive clarity for static type narrowing. - raise ValueError("on-the-fly cold warm-up timing must be positive") - cold_runs = _warmup_nonnegative_integer( - value["cold_warmup_run_count"], - "cold_warmup_run_count", - ) - cold_batch_size = _warmup_nonnegative_integer( - value["cold_warmup_batch_size"], - "cold_warmup_batch_size", - ) - cold_point_count = _warmup_nonnegative_integer( - value["cold_warmup_point_count"], - "cold_warmup_point_count", - ) - if cold_runs != 1: - raise ValueError("on-the-fly cold warm-up must contain exactly one run") - if ( - cold_batch_size < 1 - or cold_point_count != cold_batch_size - or cold_batch_size != warmup_batch_size - ): - raise ValueError( - "on-the-fly cold warm-up must cover exactly the full benchmark batch" - ) - if expected_batch_size is not None and ( - isinstance(expected_batch_size, bool) - or not isinstance(expected_batch_size, int) - or expected_batch_size < 1 - or cold_batch_size != expected_batch_size - ): - raise ValueError( - "on-the-fly cold warm-up batch does not match the effective " - "benchmark configuration" - ) - if value["cold_warmup_timer_source"] != WARMUP_TIMER_SOURCE: - raise ValueError("on-the-fly cold warm-up timer source is unsupported") - if value["cold_warmup_timing_scope"] != OTF_COLD_WARMUP_TIMING_SCOPE: - raise ValueError( - "on-the-fly cold warm-up scope must exclude artifact generation and " - "Runtime/artifact load" - ) - if ( - value["cold_warmup_runtime_state_evidence"] - != OTF_COLD_WARMUP_RUNTIME_STATE_EVIDENCE - ): - raise ValueError( - "on-the-fly cold warm-up runtime state evidence is unsupported" - ) - state_before = _validate_otf_runtime_state_census( - value["cold_warmup_runtime_state_before"], - "cold_warmup_runtime_state_before", - ) - state_after = _validate_otf_runtime_state_census( - value["cold_warmup_runtime_state_after"], - "cold_warmup_runtime_state_after", - ) - if state_before["process_id"] != state_after["process_id"]: - raise ValueError( - "on-the-fly cold warm-up runtime state snapshots identify different " - "processes" - ) - runtime_was_cold = _otf_runtime_state_is_cold(state_before) - runtime_was_retained = _otf_runtime_state_is_retained(state_before) - runtime_is_retained = _otf_runtime_state_is_retained(state_after) - if runtime_was_cold == runtime_was_retained: - raise ValueError( - "on-the-fly runtime state before the first evaluation must be exactly " - "cold or strictly retained" - ) - if not runtime_is_retained: - raise ValueError( - "on-the-fly runtime state after the first evaluation must be strictly " - "retained" - ) - if ( - _warmup_boolean( - value["cold_warmup_runtime_cold_before_first_evaluation"], - "cold_warmup_runtime_cold_before_first_evaluation", - ) - is not runtime_was_cold - or _warmup_boolean( - value["cold_warmup_runtime_retained_before_first_evaluation"], - "cold_warmup_runtime_retained_before_first_evaluation", - ) - is not runtime_was_retained - or _warmup_boolean( - value["cold_warmup_runtime_retained_after_first_evaluation"], - "cold_warmup_runtime_retained_after_first_evaluation", - ) - is not runtime_is_retained - ): - raise ValueError( - "on-the-fly cold warm-up runtime state booleans do not match the " - "authenticated census snapshots" - ) - expected_freshness = ( - OTF_COLD_WARMUP_RUNTIME_FRESHNESS - if runtime_was_cold - else OTF_COLD_WARMUP_RUNTIME_RETAINED_FRESHNESS - ) - if value["cold_warmup_runtime_freshness"] != expected_freshness: - raise ValueError( - "on-the-fly cold warm-up freshness does not match the authenticated " - "runtime state" - ) - if ( - value["cold_warmup_ratio_eligible"] is not False - or value["cold_warmup_acceptance_eligible"] is not False - ): - raise ValueError( - "on-the-fly cold warm-up must be ineligible for ratios and acceptance" - ) - - -def _benchmark_measurement( - benchmark: object, - *, - matrix_element: float, -) -> dict[str, object]: - uncertainty = benchmark.uncertainty - environment = getattr(benchmark, "environment", None) - if not isinstance(environment, Mapping): - raise RunnerError("benchmark did not retain timing provenance") - evaluator_time = benchmark.evaluator_time_per_point - raw_evaluator_time = environment.get("evaluator_time_raw_seconds_per_point") - timing_status = environment.get("evaluator_time_status") - ratio_eligible = environment.get("evaluator_time_ratio_eligible") - evaluator_sample_count = environment.get( - "evaluator_sample_count", - environment.get("native_profile_sample_count", benchmark.sample_count), - ) - if ( - isinstance(evaluator_sample_count, bool) - or not isinstance(evaluator_sample_count, int) - or evaluator_sample_count < 1 - ): - raise RunnerError("benchmark has invalid evaluator timing sample count") - raw_points_per_sample = environment.get("native_profile_points_per_sample") - if ( - isinstance(raw_points_per_sample, bool) - or not isinstance(raw_points_per_sample, int) - or raw_points_per_sample < 1 - ): - raise RunnerError("benchmark has invalid native-profile point count") - timing_sample_contract = environment.get("timing_sample_contract") - arena_profile_evidence: Mapping[str, object] | None = None - if timing_status == UNAVAILABLE_STATUS: - breakdown = getattr(benchmark, "timing_breakdown", None) - wall_component = ( - breakdown.get("wall_time") - if isinstance(breakdown, Mapping) - else getattr(breakdown, "wall_time", None) - ) - warmed_wall = ( - wall_component.get("mean_seconds_per_point") - if isinstance(wall_component, Mapping) - else getattr(wall_component, "mean_seconds_per_point", None) - ) - evaluator_component = ( - breakdown.get("evaluator_call_time") - if isinstance(breakdown, Mapping) - else getattr(breakdown, "evaluator_call_time", None) - ) - raw_arena_evidence = getattr(benchmark, "arena_profile_evidence", None) - profile_repetitions = environment.get("native_profile_repetitions_per_sample") - profile_batch_size = environment.get("native_profile_batch_size") - try: - arena_profile_evidence = validate_arena_profile_evidence( - raw_arena_evidence, - execution_mode=str(environment.get("execution_mode")), - sample_count=evaluator_sample_count, - native_profile_points_per_sample=raw_points_per_sample, - ) - except ArenaProfileEvidenceError as error: - raise RunnerError( - f"benchmark has invalid warmed Arena profile evidence: {error}" - ) from error - if ( - evaluator_time is not None - or getattr(benchmark, "evaluator_uncertainty", None) is not None - or raw_evaluator_time is not None - or ratio_eligible is not False - or environment.get("profile_protocol") != ARENA_PROFILE_PROTOCOL - or environment.get("evaluator_time_sample_pass") - != ARENA_PROFILE_SAMPLE_PASS - or environment.get("timing_breakdown_sample_pass") - != ARENA_PROFILE_SAMPLE_PASS - or environment.get("profile_attribution_boundary") != ARENA_PROFILE_BOUNDARY - or environment.get("profile_attribution_borrowed_flat_input") is not True - or environment.get("profile_attribution_preallocated_output") is not True - or environment.get("profile_attribution_phase_timing_scope") - != ARENA_PHASE_TIMING_SCOPE - or environment.get("profile_attribution_evaluator_timing_available") - is not False - or environment.get("profile_attribution_paired_with_headline") is not True - or environment.get("profile_attribution_identical_batch") is not True - or environment.get("profile_attribution_identical_repetitions") is not True - or timing_sample_contract != PAIRED_TIMING_SAMPLE_CONTRACT - or environment.get("execution_mode") not in {"compiled", "eager"} - or evaluator_sample_count != benchmark.sample_count - or isinstance(profile_repetitions, bool) - or not isinstance(profile_repetitions, int) - or profile_repetitions < 1 - or isinstance(profile_batch_size, bool) - or not isinstance(profile_batch_size, int) - or profile_batch_size < 1 - or profile_repetitions * profile_batch_size != raw_points_per_sample - or arena_profile_evidence.get("repetitions_per_profile") - != profile_repetitions - or arena_profile_evidence.get("batch_size") != profile_batch_size - or evaluator_component is not None - or isinstance(warmed_wall, bool) - or not isinstance(warmed_wall, (int, float)) - or not math.isfinite(float(warmed_wall)) - or float(warmed_wall) <= 0.0 - ): - raise RunnerError( - "benchmark unavailable execution timing is not authenticated " - "by the warmed Arena profile boundary" - ) - execution_timing = { - "abi": ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI, - "status": UNAVAILABLE_STATUS, - "ratio_eligible": False, - "raw_seconds_per_point": None, - "sample_count": evaluator_sample_count, - "native_profile_points_per_sample": raw_points_per_sample, - "repetitions_per_sample": profile_repetitions, - "batch_size": profile_batch_size, - "sample_contract": PAIRED_TIMING_SAMPLE_CONTRACT, - "profile_protocol": ARENA_PROFILE_PROTOCOL, - "profile_sample_pass": ARENA_PROFILE_SAMPLE_PASS, - "profile_boundary": ARENA_PROFILE_BOUNDARY, - "borrowed_flat_input": True, - "preallocated_output": True, - "phase_timing_scope": ARENA_PHASE_TIMING_SCOPE, - "evaluator_timing_available": False, - "paired_with_headline": True, - "identical_batch": True, - "identical_repetitions": True, - "execution_mode": environment["execution_mode"], - "warmed_boundary_wall_seconds_per_point": float(warmed_wall), - "arena_profile_evidence_sha256": digest_arena_profile_value( - arena_profile_evidence - ), - } - elif timing_status == "measured": - time_source = environment.get("evaluator_time_source") - compiled_direct_arena_active = environment.get( - "compiled_direct_arena_active", - False, - ) - if ( - isinstance(raw_evaluator_time, bool) - or not isinstance(raw_evaluator_time, (int, float)) - or not math.isfinite(float(raw_evaluator_time)) - or float(raw_evaluator_time) <= 0.0 - or isinstance(evaluator_time, bool) - or not isinstance(evaluator_time, (int, float)) - or not math.isfinite(float(evaluator_time)) - or float(evaluator_time) != float(raw_evaluator_time) - or ratio_eligible is not True - or not isinstance(time_source, str) - or not time_source - or not isinstance(compiled_direct_arena_active, bool) - or not isinstance(timing_sample_contract, str) - or not timing_sample_contract - ): - raise RunnerError("benchmark measured execution timing is inconsistent") - execution_timing = { - "abi": MEASURED_EXECUTION_TIMING_ABI, - "status": "measured", - "ratio_eligible": True, - "raw_seconds_per_point": float(raw_evaluator_time), - "source": time_source, - "compiled_direct_arena_active": compiled_direct_arena_active, - "sample_count": evaluator_sample_count, - "native_profile_points_per_sample": raw_points_per_sample, - "sample_contract": timing_sample_contract, - } - else: - raise RunnerError("benchmark has unsupported evaluator timing status") - total_environment_fields = ( - "evaluator_total_time_raw_seconds_per_point", - "evaluator_total_time_status", - "evaluator_total_time_ratio_eligible", - "evaluator_total_time_source", - "evaluator_total_time_sample_contract", - "evaluator_total_accumulated_seconds", - ) - total_fields_present = tuple( - field in environment for field in total_environment_fields - ) - evaluator_total_timing: Mapping[str, object] | None = None - if any(total_fields_present): - if not all(total_fields_present): - raise RunnerError( - "benchmark has incomplete accumulated evaluator-total timing" - ) - repetitions = environment.get("native_profile_repetitions_per_sample") - batch_size = environment.get("native_profile_batch_size") - measured_point_count = environment.get("measured_point_count") - raw_total = environment["evaluator_total_time_raw_seconds_per_point"] - evaluator_total_timing = { - "abi": EVALUATOR_TOTAL_TIMING_ABI, - "status": environment["evaluator_total_time_status"], - "ratio_eligible": environment["evaluator_total_time_ratio_eligible"], - "raw_seconds_per_point": raw_total, - "source": environment["evaluator_total_time_source"], - "execution_mode": environment.get("execution_mode"), - "sample_contract": environment["evaluator_total_time_sample_contract"], - "sample_count": benchmark.sample_count, - "repetitions_per_sample": repetitions, - "batch_size": batch_size, - "points_per_sample": raw_points_per_sample, - "measured_point_count": measured_point_count, - "accumulated_seconds": environment["evaluator_total_accumulated_seconds"], - } - total_measurement = { - "status": ResultStatus.OK.value, - "wall_seconds_per_point": benchmark.wall_time_per_point, - "sample_count": benchmark.sample_count, - "provenance": { - EVALUATOR_TOTAL_TIMING_KEY: evaluator_total_timing, - }, - } - result_total = getattr( - benchmark, - "evaluator_total_time_per_point", - None, - ) - if ( - evaluator_total_timing_record(total_measurement) is None - or isinstance(result_total, bool) - or not isinstance(result_total, (int, float)) - or not math.isfinite(float(result_total)) - or float(result_total) != float(raw_total) - ): - raise RunnerError( - "benchmark accumulated evaluator-total timing is inconsistent" - ) - target_runtime = float(benchmark.effective_config.target_runtime) - if not math.isfinite(target_runtime) or target_runtime <= 0.0: - raise RunnerError("benchmark has an invalid target timing duration") - achieved_runtime = environment.get("elapsed_seconds") - if ( - isinstance(achieved_runtime, bool) - or not isinstance(achieved_runtime, (int, float)) - or not math.isfinite(float(achieved_runtime)) - or float(achieved_runtime) < 0.0 - ): - raise RunnerError("benchmark did not report its achieved timing duration") - command_evidence: dict[str, object] = {} - if "report_command_path" in environment: - command_path = environment.get("report_command_path") - if not isinstance(command_path, str) or not command_path: - raise RunnerError("benchmark has an invalid report command path") - command_evidence["report_command_path"] = command_path - if "report_public_cli_path" in environment: - public_path = environment.get("report_public_cli_path") - if public_path is not None and ( - not isinstance(public_path, str) or not public_path - ): - raise RunnerError("benchmark has an invalid public CLI command path") - command_evidence["report_public_cli_path"] = public_path - phase_evidence: dict[str, object] = {} - raw_execution_mode = environment.get("execution_mode") - benchmark_batch_size: int | None = None - benchmark_warmup_runs: int | None = None - if raw_execution_mode == ExecutionMode.ON_THE_FLY.value: - raw_batch_size = environment.get("batch_size") - effective_batch_size = getattr( - benchmark.effective_config, - "batch_size", - None, - ) - effective_warmup_runs = getattr( - benchmark.effective_config, - "warmup_runs", - None, - ) - if ( - isinstance(raw_batch_size, bool) - or not isinstance(raw_batch_size, int) - or raw_batch_size < 1 - or isinstance(effective_batch_size, bool) - or not isinstance(effective_batch_size, int) - or effective_batch_size < 1 - or raw_batch_size != effective_batch_size - ): - raise RunnerError( - "on-the-fly benchmark batch size does not match its effective " - "configuration" - ) - if ( - isinstance(effective_warmup_runs, bool) - or not isinstance(effective_warmup_runs, int) - or effective_warmup_runs < 0 - ): - raise RunnerError( - "on-the-fly benchmark has an invalid effective warm-up run count" - ) - benchmark_batch_size = effective_batch_size - benchmark_warmup_runs = effective_warmup_runs - try: - validate_profile_warmup_evidence( - environment, - execution_mode=( - raw_execution_mode - if isinstance(raw_execution_mode, str) - else "" - ), - expected_batch_size=benchmark_batch_size, - expected_warmup_run_count=benchmark_warmup_runs, - ) - except ValueError as error: - raise RunnerError(str(error)) from error - for field in (*sorted(OTF_COLD_WARMUP_FIELDS), *sorted(CONVENTIONAL_WARMUP_FIELDS)): - if field in environment: - phase_evidence[field] = _warmup_plain_value(environment[field]) - for field in ( - "calibration_elapsed_seconds", - "calibration_outer_elapsed_seconds", - "measurement_phase_elapsed_seconds", - "profile_total_elapsed_seconds", - "profile_attribution_elapsed_seconds", - "evaluator_elapsed_seconds", - "calibration_probe_seconds", - ): - if field not in environment: - continue - value = environment[field] - if ( - isinstance(value, bool) - or not isinstance(value, (int, float)) - or not math.isfinite(float(value)) - or float(value) < 0.0 - ): - raise RunnerError(f"benchmark has invalid {field.replace('_', ' ')}") - phase_evidence[field] = float(value) - for field in ( - "calibration_block_count", - "calibration_evaluation_count", - ): - if field not in environment: - continue - value = environment[field] - if isinstance(value, bool) or not isinstance(value, int) or value < 0: - raise RunnerError(f"benchmark has invalid {field.replace('_', ' ')}") - phase_evidence[field] = value - if "measurement_phase_elapsed_seconds" not in phase_evidence: - phase_evidence["measurement_phase_elapsed_seconds"] = float(achieved_runtime) - return { - "status": ResultStatus.OK.value, - "wall_seconds_per_point": float(benchmark.wall_time_per_point), - "execution_seconds_per_point": ( - None if evaluator_time is None else float(evaluator_time) - ), - "execution_timing": execution_timing, - "evaluator_total_timing": evaluator_total_timing, - "arena_profile_evidence": arena_profile_evidence, - "matrix_element": matrix_element, - "sample_count": int(benchmark.sample_count), - "standard_error_seconds_per_point": float(uncertainty.standard_error), - "relative_standard_error": float(uncertainty.relative_standard_error), - "benchmark_evidence": { - **command_evidence, - **phase_evidence, - "target_runtime_seconds": target_runtime, - "achieved_runtime_seconds": float(achieved_runtime), - "target_runtime_achieved": ( - float(achieved_runtime) >= 0.95 * target_runtime - ), - "completed_sample_count": environment.get("completed_sample_count"), - "planned_sample_count": environment.get("planned_sample_count"), - "repetitions_per_sample": environment.get("repetitions_per_sample"), - "measured_point_count": environment.get("measured_point_count"), - "interrupted": bool(environment.get("interrupted", False)), - }, - } - - -def profile_runtime( - runtime: RuntimeLike, - points: object, - *, - cell: CellSpec, - benchmark_config: BenchmarkConfig, - selector_contract: SelectorContract | None, - progress: ProgressSink | None = None, - profiling_deadline_monotonic: float | None = None, -) -> dict[str, object]: - validate_runtime_contract(cell, runtime) - if selector_contract is not None: - validate_selector_contract( - runtime, - selector_contract, - points, - cell=cell, - ) - selectors = _selector_kwargs(cell, selector_contract) - values = ( - None - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - else runtime.evaluate(points, **selectors) - ) - if values is not None and not values: - raise RunnerError("runtime returned no matrix elements") - selected_config = replace( - benchmark_config, - helicity_ids=tuple(selectors["helicities"] or ()), - color_flow_ids=tuple(selectors["color_flows"] or ()), - ) - benchmark = _run_report_benchmark( - runtime, - points, - execution_mode=cell.measurement.execution_mode, - benchmark_config=selected_config, - selectors=selectors, - progress=progress, - chunk_guard=profiling_chunk_guard(profiling_deadline_monotonic), - ) - # The public OTF profiler owns the first evaluation so that its separately - # reported cold warm-up is not destroyed by campaign-side validation. - if values is None: - values = runtime.evaluate(points, **selectors) - if not values: - raise RunnerError("runtime returned no matrix elements") - result = _benchmark_measurement( - benchmark, - matrix_element=_real_nonnegative(values[0]), - ) - result["resolved_sum_validation"] = resolved_sum_validation( - runtime, - points, - cell=cell, - selector_contract=selector_contract, - ) - if result["resolved_sum_validation"]["status"] != ResultStatus.OK.value: - result["status"] = ResultStatus.VALIDATION_FAILED.value - return result - - -def runtime_validation_points(runtime: object) -> object: - backend = getattr(runtime, "_backend", None) - operation = getattr(backend, "validation_momenta", None) - if not callable(operation): - raise RunnerError("artifact does not retain deterministic validation momenta") - points = operation() - if points is None: - raise RunnerError("artifact validation momenta are unavailable") - return points - - -def _single_process_id(artifact_path: Path, fallback: str) -> str: - manifest_path = artifact_path / "artifact.json" - try: - manifest = json.loads(manifest_path.read_text(encoding="utf-8")) - processes = manifest["processes"] - if isinstance(processes, list) and len(processes) == 1: - identifier = processes[0]["id"] - if isinstance(identifier, str) and identifier: - return identifier - except (KeyError, OSError, TypeError, json.JSONDecodeError): - pass - return fallback - - -def generate_artifact( - cell: CellSpec, - destination: Path, - *, - settings: RunnerSettings, - repo_root: Path, - prepared_model_path: Path | None = None, - phase_reporter: WorkerPhaseReporter | None = None, -) -> GeneratedArtifact: - """Generate one complete-coverage artifact and time process generation only.""" - - from pyamplicol.api import Generator, ModelSource - from pyamplicol.cli import CliInvocation, parse_cli - from pyamplicol.cli.handlers import DefaultCliServices, dispatch - from pyamplicol.config import Action, RunConfig - from pyamplicol.config.resolver import config_to_dict, resolve_config - from pyamplicol.reporting import NullProgressSink - - values = config_values(cell, settings, repo_root=repo_root) - generation_values = values["generation"] - assert isinstance(generation_values, dict) - generation_values.update( - { - "output": os.fspath(destination), - "mode": "replace", - } - ) - values["process"] = {"entries": [{"expression": cell.process}]} - if prepared_model_path is not None: - if not prepared_model_path.is_file(): - raise RunnerError(f"prepared model does not exist: {prepared_model_path}") - model_values = values["model"] - assert isinstance(model_values, dict) - model_values["source"] = os.fspath(prepared_model_path) - expected_resolution = resolve_config( - values, - action=Action.GENERATE, - base_dir=repo_root, - ) - invocation = parse_cli(_generation_cli_argv(cell, destination, values)) - if not isinstance(invocation, CliInvocation): - raise RunnerError("public generate parser returned a non-command invocation") - resolution = invocation.resolve() - if ( - resolution.requested != expected_resolution.requested - or resolution.effective != expected_resolution.effective - ): - raise RunnerError( - "public generate arguments do not preserve report generation settings" - ) - generation_phase = ( - nullcontext() if phase_reporter is None else phase_reporter.generation() - ) - with generation_phase: - # The process-tree watchdog owns the complete preparation+generation - # interval, while the published generation timer below intentionally - # continues to measure dispatch/generation only. - assert cell.measurement.model is not None - source_path = _model_source_path(repo_root, cell.measurement.model) - source = ( - ModelSource.built_in_sm() - if source_path is None - else ModelSource.from_path(source_path) - ) - model_started = time.perf_counter() - prepared_execution = cell.measurement.execution_mode in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - } - if prepared_model_path is not None: - model = ModelSource.from_path(prepared_model_path) - preparation_reused = True - elif prepared_execution and cell.measurement.model is ModelKey.BUILTIN_SM: - # Omitting the explicit model lets the generation service select the - # validated wheel-owned built-in-SM JIT O2 prepared pack. - model = None - preparation_reused = True - elif prepared_execution: - raise RunnerError( - f"{cell.measurement.model.value} " - f"{cell.measurement.execution_mode.value} generation requires " - "a prepared model path" - ) - else: - model = source.compile( - cache_dir=settings.model_cache_dir, - use_cache=True, - require_supported=True, - ) - preparation_reused = False - model_seconds = time.perf_counter() - model_started - generation_started = time.perf_counter() - selected_progress = settings.progress or NullProgressSink() - if prepared_execution: - command_services = DefaultCliServices(resolution=resolution) - generation_command_path = PUBLIC_CLI_COMMAND_PATH - else: - - class _PreparedGenerationServices(DefaultCliServices): - """Inject only the already compiled model into public dispatch. - - The public parser, typed resolution, progress path, and dispatch - are retained. This report-only handler exception is necessary - to exclude model preparation from the process-generation timer. - """ - - def generate( - self, - config: RunConfig, - command_progress: ProgressSink, - ) -> object: - return Generator( - resolution, - progress=command_progress, - ).generate( - cell.process, - destination, - model=model, - mode="replace", - ) - - command_services = _PreparedGenerationServices(resolution=resolution) - generation_command_path = PRECOMPILED_GENERATION_COMMAND_PATH - - dispatch( - resolution.effective, - command_services, - selected_progress, - dry_run=invocation.dry_run, - ) - generation_seconds = time.perf_counter() - generation_started - effective_config = _authenticated_effective_config(destination) - process_id = _single_process_id(destination, cell.process) - if cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY: - numerical_relation_correctness = None - numerical_relation_fallback = None - else: - ( - numerical_relation_correctness, - numerical_relation_fallback, - ) = _artifact_numerical_relation_metadata(destination, process_id) - return GeneratedArtifact( - path=destination, - process_id=process_id, - generation_seconds=generation_seconds, - model_preparation_seconds=model_seconds, - model_preparation_reused=preparation_reused, - requested_config=config_to_dict(resolution.requested), - effective_config=effective_config, - generation_command_path=generation_command_path, - numerical_relation_correctness=numerical_relation_correctness, - numerical_relation_fallback=numerical_relation_fallback, - ) - - -def provenance_payload() -> dict[str, object]: - numpy_version = getattr(importlib.import_module("numpy"), "__version__", None) - if not isinstance(numpy_version, str) or not numpy_version: - raise RunnerError("measurement NumPy version is unavailable") - return { - "platform": platform.platform(), - "python": platform.python_version(), - "python_implementation": platform.python_implementation(), - "numpy": numpy_version, - "machine": platform.machine(), - "processor": platform.processor(), - } - - -__all__ = [ - "ABSOLUTE_TOLERANCE", - "CONDITIONED_COMPARISON_ABI", - "INDEPENDENT_RELATIVE_TOLERANCE", - "MADGRAPH_RELATIVE_TOLERANCE", - "RELATIVE_TOLERANCE", - "RESOLVED_COMPONENT_SCALE_ABI", - "RESOLVED_SUM_VALIDATION_ABI", - "GeneratedArtifact", - "ProfilingTimeLimitError", - "RunnerError", - "RunnerSettings", - "SelectorContract", - "config_values", - "derive_selector_contract", - "generate_artifact", - "point_digest", - "pointwise_validation", - "profile_runtime", - "profiling_chunk_guard", - "provenance_payload", - "resolved_component_scale_evidence", - "resolved_sum_validation", - "runtime_identity_payload", - "runtime_validation_points", - "validate_artifact_contract", - "validate_conditioned_comparison_record", - "validate_resolved_sum_validation_record", - "validate_runtime_contract", - "validate_selector_contract", -] diff --git a/pyamplicol/tools/performance_report/runtime_evidence.py b/pyamplicol/tools/performance_report/runtime_evidence.py deleted file mode 100644 index 24bd274fc0..0000000000 --- a/pyamplicol/tools/performance_report/runtime_evidence.py +++ /dev/null @@ -1,645 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Checked identities for the Python bytes eligible during final measurements.""" - -from __future__ import annotations - -import hashlib -import importlib.machinery -import json -import os -import stat -import sys -from collections.abc import Sequence -from pathlib import Path, PurePosixPath - -_HASH_CHUNK_BYTES = 1024 * 1024 -_STABLE_STAT_FIELDS = ( - "st_dev", - "st_ino", - "st_mode", - "st_size", - "st_mtime_ns", - "st_ctime_ns", -) -_PREIMPORT_RUNTIME_IDENTITY: dict[str, object] | None = None - - -class RuntimeEvidenceError(RuntimeError): - """A runtime tree cannot be authenticated without a namespace race.""" - - -def _isolated_startup_flags() -> tuple[bool, bool, bool]: - return ( - bool(sys.flags.isolated), - bool(sys.flags.no_site), - bool(sys.flags.ignore_environment), - ) - - -def _canonical_json(value: object) -> bytes: - return json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - - -def source_only_bytecode_policy() -> dict[str, object]: - """Prove that this process cannot read or write package-local bytecode. - - ``-B`` prevents writes, while an absolute, absent ``PYTHONPYCACHEPREFIX`` - makes the interpreter's cache lookup namespace empty. The exact random - prefix is intentionally omitted so identities remain comparable across - isolated workers. - """ - - prefix_value = sys.pycache_prefix - isolated, no_site, ignore_environment = _isolated_startup_flags() - if not (isolated and ignore_environment): - raise RuntimeEvidenceError( - "exact runtime evidence requires isolated Python startup (-I)" - ) - if not sys.dont_write_bytecode: - raise RuntimeEvidenceError( - "exact runtime evidence requires Python -B " - "(sys.dont_write_bytecode must be true)" - ) - if not no_site: - if prefix_value is not None: - raise RuntimeEvidenceError( - "installed runtime evidence requires no external bytecode prefix" - ) - return { - "kind": "pyamplicol-installed-bytecode-policy-v1", - "dont_write_bytecode": True, - "external_pycache_prefix": False, - "package_local_bytecode_eligible": False, - "isolated_startup": True, - "site_initialization": True, - "python_environment_ignored_at_startup": True, - } - if not isinstance(prefix_value, str) or not prefix_value: - raise RuntimeEvidenceError( - "exact runtime evidence requires an absent external " - "PYTHONPYCACHEPREFIX" - ) - prefix = Path(prefix_value).expanduser() - if not prefix.is_absolute(): - raise RuntimeEvidenceError( - "exact runtime evidence requires an absolute PYTHONPYCACHEPREFIX" - ) - if prefix.exists(): - raise RuntimeEvidenceError( - "exact runtime evidence requires PYTHONPYCACHEPREFIX to remain absent" - ) - return { - "kind": "pyamplicol-source-only-bytecode-policy-v1", - "dont_write_bytecode": True, - "external_pycache_prefix": True, - "external_pycache_prefix_absent": True, - "package_local_bytecode_eligible": False, - "isolated_startup": True, - "site_initialization": False, - "python_environment_ignored_at_startup": True, - } - - -def _same_stat(left: os.stat_result, right: os.stat_result) -> bool: - return all( - getattr(left, field) == getattr(right, field) - for field in _STABLE_STAT_FIELDS - ) - - -def _relative_directory(path: str) -> PurePosixPath: - if path in {"", "."}: - return PurePosixPath() - normalized = path[2:] if path.startswith("./") else path - logical = PurePosixPath(normalized) - if ( - logical.is_absolute() - or any(part in {"", ".", ".."} for part in logical.parts) - or logical.as_posix() != normalized - ): - raise RuntimeEvidenceError( - f"package traversal produced a noncanonical directory: {path!r}" - ) - return logical - - -def _regular_file_record( - directory_fd: int, - name: str, - logical_path: str, -) -> dict[str, object]: - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_NOFOLLOW", 0) - | getattr(os, "O_BINARY", 0) - ) - descriptor: int | None = None - try: - namespace_before = os.stat(name, dir_fd=directory_fd, follow_symlinks=False) - if not stat.S_ISREG(namespace_before.st_mode): - raise RuntimeEvidenceError( - f"package member is not a regular file: {logical_path}" - ) - descriptor = os.open(name, flags, dir_fd=directory_fd) - opened_before = os.fstat(descriptor) - if not _same_stat(namespace_before, opened_before): - raise RuntimeEvidenceError( - f"package member changed while it was opened: {logical_path}" - ) - digest = hashlib.sha256() - byte_count = 0 - with os.fdopen(descriptor, "rb", closefd=True) as stream: - descriptor = None - for block in iter(lambda: stream.read(_HASH_CHUNK_BYTES), b""): - digest.update(block) - byte_count += len(block) - opened_after = os.fstat(stream.fileno()) - namespace_after = os.stat(name, dir_fd=directory_fd, follow_symlinks=False) - except OSError as error: - raise RuntimeEvidenceError( - f"cannot authenticate installed package member: {logical_path}" - ) from error - finally: - if descriptor is not None: - os.close(descriptor) - if ( - byte_count != opened_before.st_size - or not _same_stat(opened_before, opened_after) - or not _same_stat(opened_after, namespace_after) - ): - raise RuntimeEvidenceError( - f"package member changed while it was hashed: {logical_path}" - ) - return { - "path": logical_path, - "size": byte_count, - "sha256": digest.hexdigest(), - } - - -def _path_file_identity(path: Path) -> dict[str, object]: - try: - parent = path.parent.resolve(strict=True) - name = path.name - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_DIRECTORY", 0) - | getattr(os, "O_NOFOLLOW", 0) - ) - directory_fd = os.open(parent, flags) - try: - parent_before = os.fstat(directory_fd) - record = _regular_file_record(directory_fd, name, name) - parent_after = os.fstat(directory_fd) - parent_namespace = os.stat(parent, follow_symlinks=False) - finally: - os.close(directory_fd) - except OSError as error: - raise RuntimeEvidenceError( - f"cannot authenticate runtime file: {path}" - ) from error - if ( - not _same_stat(parent_before, parent_after) - or not _same_stat(parent_after, parent_namespace) - ): - raise RuntimeEvidenceError( - f"runtime file parent changed while it was authenticated: {path}" - ) - return { - "path": str(parent / name), - "size": record["size"], - "sha256": record["sha256"], - } - - -def _scan_package_tree( - root_fd: int, -) -> tuple[list[dict[str, object]], tuple[object, ...]]: - records: list[dict[str, object]] = [] - namespace: list[object] = [] - try: - walker = os.fwalk( - ".", - topdown=True, - follow_symlinks=False, - dir_fd=root_fd, - ) - for directory, directory_names, file_names, directory_fd in walker: - logical_directory = _relative_directory(directory) - directory_names.sort() - file_names.sort() - if "__pycache__" in directory_names: - directory_names.remove("__pycache__") - directory_metadata = os.fstat(directory_fd) - if not stat.S_ISDIR(directory_metadata.st_mode): - raise RuntimeEvidenceError( - f"package member is not a directory: {logical_directory}" - ) - namespace.append( - ( - "directory", - logical_directory.as_posix(), - *( - getattr(directory_metadata, field) - for field in _STABLE_STAT_FIELDS - ), - ) - ) - for name in directory_names: - metadata = os.stat( - name, - dir_fd=directory_fd, - follow_symlinks=False, - ) - logical = (logical_directory / name).as_posix() - if not stat.S_ISDIR(metadata.st_mode): - raise RuntimeEvidenceError( - "installed pyamplicol package tree contains an " - f"unsupported directory entry: {logical}" - ) - namespace.append( - ( - "directory-entry", - logical, - *(getattr(metadata, field) for field in _STABLE_STAT_FIELDS), - ) - ) - for name in file_names: - logical = (logical_directory / name).as_posix() - if Path(name).suffix in {".pyc", ".pyo"}: - raise RuntimeEvidenceError( - "installed pyamplicol package tree contains executable " - f"sourceless bytecode: {logical}" - ) - record = _regular_file_record(directory_fd, name, logical) - records.append(record) - metadata = os.stat( - name, - dir_fd=directory_fd, - follow_symlinks=False, - ) - namespace.append( - ( - "file", - logical, - *(getattr(metadata, field) for field in _STABLE_STAT_FIELDS), - ) - ) - except OSError as error: - raise RuntimeEvidenceError( - "cannot traverse installed pyamplicol package through checked descriptors" - ) from error - records.sort(key=lambda record: str(record["path"])) - namespace.sort(key=repr) - return records, tuple(namespace) - - -def _resolved_package_roots(package_roots: Path | Sequence[Path]) -> tuple[Path, ...]: - raw_roots = ( - (package_roots,) - if isinstance(package_roots, Path) - else tuple(package_roots) - ) - if not raw_roots: - raise RuntimeEvidenceError("installed pyamplicol package has no search roots") - roots: list[Path] = [] - for raw_root in raw_roots: - try: - root = raw_root.expanduser().resolve(strict=True) - except OSError as error: - raise RuntimeEvidenceError( - f"cannot resolve installed pyamplicol package tree: {raw_root}" - ) from error - if root not in roots: - roots.append(root) - return tuple(roots) - - -def _package_tree_records(root: Path) -> list[dict[str, object]]: - try: - flags = ( - os.O_RDONLY - | getattr(os, "O_CLOEXEC", 0) - | getattr(os, "O_DIRECTORY", 0) - | getattr(os, "O_NOFOLLOW", 0) - ) - root_fd = os.open(root, flags) - root_before = os.fstat(root_fd) - if not stat.S_ISDIR(root_before.st_mode): - raise RuntimeEvidenceError( - f"installed pyamplicol package tree is not a directory: {root}" - ) - first_records, first_namespace = _scan_package_tree(root_fd) - second_records, second_namespace = _scan_package_tree(root_fd) - root_after = os.fstat(root_fd) - namespace_root = os.stat(root, follow_symlinks=False) - except OSError as error: - raise RuntimeEvidenceError( - f"cannot authenticate installed pyamplicol package tree: {root}" - ) from error - finally: - if "root_fd" in locals(): - os.close(root_fd) - if ( - not _same_stat(root_before, root_after) - or not _same_stat(root_after, namespace_root) - or first_records != second_records - or first_namespace != second_namespace - ): - raise RuntimeEvidenceError( - "installed pyamplicol package tree changed while it was authenticated" - ) - if not first_records: - raise RuntimeEvidenceError( - "installed pyamplicol package tree contains no source/runtime files" - ) - return first_records - - -def python_package_tree_identity( - package_roots: Path | Sequence[Path], -) -> dict[str, object]: - """Hash every ordered package search root through anchored directory fds.""" - - bytecode_policy = source_only_bytecode_policy() - roots = _resolved_package_roots(package_roots) - records: list[dict[str, object]] = [] - for root_index, root in enumerate(roots): - for record in _package_tree_records(root): - records.append({"root_index": root_index, **record}) - total_bytes = sum(int(record["size"]) for record in records) - return { - "kind": "pyamplicol-python-package-tree-v2", - "root": str(roots[0]), - "roots": [str(root) for root in roots], - "file_count": len(records), - "total_bytes": total_bytes, - "sha256": hashlib.sha256(_canonical_json(records)).hexdigest(), - "member_set_stable": True, - "namespace_bound_to_root_fd": True, - "bytecode_policy": bytecode_policy, - } - - -def native_extension_in_package(package_root: Path) -> Path: - """Return the one importable native extension in an ordered package root.""" - - try: - root = package_root.expanduser().resolve(strict=True) - except OSError as error: - raise RuntimeEvidenceError( - f"cannot resolve native package root: {package_root}" - ) from error - suffixes = tuple(importlib.machinery.EXTENSION_SUFFIXES) - matches = sorted( - ( - path - for path in root.iterdir() - if path.is_file() - and path.name.startswith("_rusticol") - and path.name.endswith(suffixes) - ), - key=lambda path: path.name, - ) - if len(matches) != 1: - raise RuntimeEvidenceError( - "exact runtime evidence requires one native _rusticol extension in " - f"{root}; found {len(matches)}" - ) - return matches[0] - - -def preimport_python_runtime_identity( - package_roots: Path | Sequence[Path], - *, - native_extension: Path, -) -> dict[str, object]: - """Authenticate candidate Python/native files before importing pyamplicol.""" - - global _PREIMPORT_RUNTIME_IDENTITY - if any( - name == "pyamplicol" or name.startswith("pyamplicol.") - for name in sys.modules - ): - raise RuntimeEvidenceError( - "pyamplicol was imported before exact runtime preauthentication" - ) - identity = { - "kind": "pyamplicol-preimport-runtime-identity-v1", - "python_package_tree": python_package_tree_identity(package_roots), - "native_extension": _path_file_identity(native_extension), - } - _PREIMPORT_RUNTIME_IDENTITY = identity - return identity - - -def established_preimport_runtime_identity() -> dict[str, object]: - """Return the identity established before the first pyamplicol import.""" - - if _PREIMPORT_RUNTIME_IDENTITY is None: - raise RuntimeEvidenceError( - "exact runtime evidence has no preimport Python/native identity" - ) - return _PREIMPORT_RUNTIME_IDENTITY - - -def loaded_pyamplicol_origin_policy( - package_roots: Path | Sequence[Path], - *, - native_extension: Path, - expected_package_identity: dict[str, object] | None = None, - expected_native_identity: dict[str, object] | None = None, -) -> dict[str, object]: - """Require every loaded pyamplicol module to originate in authenticated bytes.""" - - source_only_bytecode_policy() - try: - roots = _resolved_package_roots(package_roots) - native = native_extension.expanduser().resolve(strict=True) - except OSError as error: - raise RuntimeEvidenceError( - "cannot resolve loaded pyamplicol module origins" - ) from error - current_package_identity = python_package_tree_identity(roots) - if ( - expected_package_identity is not None - and current_package_identity != expected_package_identity - ): - raise RuntimeEvidenceError( - "pyamplicol package roots differ from their preimport identity" - ) - current_native_identity = _path_file_identity(native) - if ( - expected_native_identity is not None - and current_native_identity != expected_native_identity - ): - raise RuntimeEvidenceError( - "native extension differs from its preimport identity" - ) - member_records: list[dict[str, object]] = [] - for root_index, root in enumerate(roots): - member_records.extend( - {"root_index": root_index, **record} - for record in _package_tree_records(root) - ) - members = { - (int(record["root_index"]), str(record["path"])): record - for record in member_records - } - observed = 0 - observations: list[dict[str, object]] = [] - for name, module in tuple(sys.modules.items()): - if name != "pyamplicol" and not name.startswith("pyamplicol."): - continue - specification = getattr(module, "__spec__", None) - origin_value = getattr(specification, "origin", None) - if not isinstance(origin_value, str) or origin_value in { - "built-in", - "frozen", - }: - origin_value = getattr(module, "__file__", None) - if not isinstance(origin_value, str) or not origin_value: - locations = getattr(specification, "submodule_search_locations", None) - if locations is None: - raise RuntimeEvidenceError( - f"loaded pyamplicol module has no filesystem origin: {name}" - ) - for raw_location in locations: - try: - location = Path(str(raw_location)).expanduser().resolve(strict=True) - except OSError as error: - raise RuntimeEvidenceError( - "loaded pyamplicol namespace is outside the authenticated " - f"package tree: {name}" - ) from error - if not any( - location == root or location.is_relative_to(root) - for root in roots - ): - raise RuntimeEvidenceError( - "loaded pyamplicol namespace is outside the authenticated " - f"package tree: {name}" - ) - root_index = next( - index - for index, root in enumerate(roots) - if location == root or location.is_relative_to(root) - ) - relative = location.relative_to(roots[root_index]).as_posix() - if "__pycache__" in PurePosixPath(relative).parts: - raise RuntimeEvidenceError( - f"loaded pyamplicol namespace uses excluded cache bytes: {name}" - ) - observations.append( - { - "module": name, - "kind": "namespace", - "root_index": root_index, - "path": relative, - } - ) - observed += 1 - continue - try: - origin = Path(origin_value).expanduser().resolve(strict=True) - except OSError as error: - raise RuntimeEvidenceError( - f"loaded pyamplicol module origin is unavailable: {name}" - ) from error - in_package = any( - origin == root or origin.is_relative_to(root) for root in roots - ) - if not in_package and origin != native: - raise RuntimeEvidenceError( - "loaded pyamplicol module is outside the authenticated package " - f"tree/native image: {name} -> {origin}" - ) - if origin.suffix in {".pyc", ".pyo"}: - raise RuntimeEvidenceError( - f"loaded pyamplicol module used sourceless bytecode: {name}" - ) - if origin == native: - observations.append( - { - "module": name, - "kind": "native-extension", - "path": current_native_identity["path"], - "size": current_native_identity["size"], - "sha256": current_native_identity["sha256"], - } - ) - else: - root_index = next( - index - for index, root in enumerate(roots) - if origin == root or origin.is_relative_to(root) - ) - relative = origin.relative_to(roots[root_index]).as_posix() - if "__pycache__" in PurePosixPath(relative).parts: - raise RuntimeEvidenceError( - f"loaded pyamplicol module uses excluded cache bytes: {name}" - ) - member = members.get((root_index, relative)) - if member is None: - raise RuntimeEvidenceError( - "loaded pyamplicol module is absent from the authenticated " - f"member set: {name}" - ) - actual = _path_file_identity(origin) - if ( - actual["size"] != member["size"] - or actual["sha256"] != member["sha256"] - ): - raise RuntimeEvidenceError( - f"loaded pyamplicol module bytes changed: {name}" - ) - observations.append( - { - "module": name, - "kind": "package-member", - "root_index": root_index, - "path": relative, - "size": member["size"], - "sha256": member["sha256"], - } - ) - observed += 1 - if observed == 0: - raise RuntimeEvidenceError("no loaded pyamplicol modules were observed") - observations.sort( - key=lambda observation: ( - str(observation["module"]), - str(observation["kind"]), - str(observation["path"]), - ) - ) - return { - "kind": "pyamplicol-loaded-module-origin-policy-v1", - "all_loaded_origins_authenticated": True, - "native_image_origin_bound": True, - "loaded_bytecode_eligible": False, - "observed_module_count": observed, - "observations": observations, - "observations_sha256": hashlib.sha256( - _canonical_json(observations) - ).hexdigest(), - } - - -__all__ = [ - "RuntimeEvidenceError", - "established_preimport_runtime_identity", - "loaded_pyamplicol_origin_policy", - "native_extension_in_package", - "preimport_python_runtime_identity", - "python_package_tree_identity", - "source_only_bytecode_policy", -] diff --git a/pyamplicol/tools/performance_report/scheduler.py b/pyamplicol/tools/performance_report/scheduler.py deleted file mode 100644 index dc8becf524..0000000000 --- a/pyamplicol/tools/performance_report/scheduler.py +++ /dev/null @@ -1,3870 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Dependency-aware, resource-supervised performance-report campaigns.""" - -from __future__ import annotations - -import hashlib -import heapq -import json -import math -import os -import re -import shutil -import sys -import time -import uuid -from collections.abc import Callable, Mapping, Sequence -from concurrent.futures import FIRST_COMPLETED, Future, ThreadPoolExecutor, wait -from contextlib import ExitStack, suppress -from dataclasses import dataclass -from datetime import UTC, datetime -from pathlib import Path - -from .agreements import ( - INDEPENDENT_AUTHORITY_FIELD, - attach_direct_agreements, - incoming_agreement_edges, - independent_numerical_authorities, - validation_baseline_is_required, -) -from .artifacts import ( - ArtifactAction, - ArtifactStore, - CurrentRecord, - LockCancelledError, - LockTimeoutError, -) -from .cache import validate_measurement -from .campaign_policy import ( - MACBOOK_M3_Z_TABLE_F_POLICY, - STRICT_POLICY, - X86_EPYC_NATIVE_COMPILER_SLOTS, - X86_EPYC_PROFILE, - CampaignPolicy, - CampaignPolicyError, - PolicyCensorKind, - PolicyMeasurementState, - dependency_reference, - generation_limit_for_cell, - policy_censor_measurement, - policy_measurement_state_hint, - policy_status_label, - resource_frontier_reference, - resource_lane_identity, - validate_campaign_settings, - validate_policy_measurement, - validate_policy_profile, -) -from .campaign_reset import OriginalAmplicolSeed, load_seed_if_present -from .catalog import REPORT_CATALOG, ReportCatalog -from .measurement import failure_measurement, reconcile_independent_authority -from .measurement_lineage import MeasurementLineage -from .models import ( - Accuracy, - ArtifactPolicy, - CellSpec, - ExecutionMode, - ModelKey, - ResultStatus, - Workload, -) -from .phase_state import WorkerPhaseChannel -from .resources import ( - DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES, - DEFAULT_MINIMUM_FREE_DISK_BYTES, - DEFAULT_SAMPLE_INTERVAL_SECONDS, - DEFAULT_TERMINATION_GRACE_SECONDS, - GenerationPhaseEvidence, - ResourceUsage, - SupervisedResult, - WorkerObservation, - supervise_worker, -) -from .runner import DEFAULT_TARGET_RUNTIME_SECONDS -from .service import CANONICAL_REPORT_ENTRYPOINT, ReportService -from .source_identity import ReportSourceIdentity, require_eligible_report_source -from .study_contract import ( - StudyContractError, - authenticate_z_table_f_study_contract, - bind_z_table_f_attempt, - require_z_table_f_attempt_binding, - z_table_f_attempt_binding, - z_table_f_cell_ids, - z_table_f_worker_harness_identity, -) -from .worker_harness import ( - POLICY_ENTRYPOINT, - WorkerHarnessError, - attach_worker_harness_identity, - require_worker_harness_identity, - validate_worker_harness_identity, -) - -_NATIVE_COMPILER_GATE_DIR_ENV = "PYAMPLICOL_NATIVE_COMPILER_GATE_DIR" -_NATIVE_COMPILER_GATE_SLOT_COUNT_ENV = "PYAMPLICOL_NATIVE_COMPILER_SLOT_COUNT" -_DIAGNOSTIC_TAIL_BYTES = 64 * 1024 - - -@dataclass(frozen=True, slots=True) -class CellSelection: - datasets: frozenset[str] = frozenset() - modes: frozenset[ExecutionMode] = frozenset() - models: frozenset[ModelKey] = frozenset() - accuracies: frozenset[Accuracy] = frozenset() - process_keys: frozenset[str] = frozenset() - processes: frozenset[str] = frozenset() - multiplicities: frozenset[int] = frozenset() - variants: frozenset[str] = frozenset() - workloads: frozenset[Workload] = frozenset() - cell_ids: frozenset[str] = frozenset() - - def matches(self, cell: CellSpec) -> bool: - model = cell.measurement.model - checks = ( - not self.datasets or cell.dataset_id in self.datasets, - not self.modes or cell.measurement.execution_mode in self.modes, - not self.models or model in self.models, - not self.accuracies or cell.measurement.accuracy in self.accuracies, - not self.process_keys or cell.process_key in self.process_keys, - not self.processes or cell.process in self.processes, - not self.multiplicities or cell.n_final in self.multiplicities, - # Variants are an optional dimension exposed by Z-ladder rows. - # Ordinary matrix/reference/scalar rows have no variant to filter. - not self.variants or cell.variant is None or cell.variant in self.variants, - not self.workloads or cell.workload in self.workloads, - not self.cell_ids or cell.cell_id in self.cell_ids, - ) - return all(checks) - - -@dataclass(frozen=True, slots=True) -class CampaignSettings: - workers: int = 1 - cell_cores: int = 1 - amplicol_build_jobs: int = 1 - target_runtime_seconds: float = DEFAULT_TARGET_RUNTIME_SECONDS - batch_size: int = 128 - warmup_runs: int = 2 - minimum_samples: int = 5 - timeout_seconds: float | None = None - generation_time_limit_seconds: float | None = None - profiling_time_limit_seconds: float | None = None - validation_time_limit_seconds: float | None = None - max_rss_bytes: int | None = None - campaign_max_rss_bytes: int | None = None - attempt_output_limit_bytes: int = DEFAULT_ATTEMPT_OUTPUT_LIMIT_BYTES - minimum_free_disk_bytes: int = DEFAULT_MINIMUM_FREE_DISK_BYTES - artifact_policy: ArtifactPolicy = ArtifactPolicy.REGENERATE - missing_only: bool = False - rerun: bool = False - add_optional_dependencies: bool = False - original_amplicol_available: bool = False - allow_symbolica_parallel: bool = False - resource_sample_interval_seconds: float = DEFAULT_SAMPLE_INTERVAL_SECONDS - termination_grace_seconds: float = DEFAULT_TERMINATION_GRACE_SECONDS - source_identity_override: ReportSourceIdentity | None = None - campaign_invocation_id: str | None = None - progress_observer: Callable[[Mapping[str, object]], None] | None = None - cancellation_requested: Callable[[], bool] | None = None - manual_terminal_censors: bool = False - discard_cancelled_attempts: bool = False - remove_heavy_attempt_artifacts: bool = True - retain_workspaces: bool = False - campaign_policy: CampaignPolicy = STRICT_POLICY - report_profile: str | None = None - study_contract_sha256: str | None = None - reuse_cross_source_comparison_dependencies: bool = False - original_amplicol_repository: Path | None = None - original_amplicol_revision: str | None = None - madgraph_installation: Path | None = None - multiplicity_wave_barrier: bool = False - - def __post_init__(self) -> None: - if self.workers < 1 or self.cell_cores < 1 or self.amplicol_build_jobs < 1: - raise ValueError( - "workers, cell_cores, and amplicol_build_jobs must be positive" - ) - if ( - not math.isfinite(self.target_runtime_seconds) - or self.target_runtime_seconds <= 0.0 - or self.batch_size < 1 - ): - raise ValueError("target runtime and batch size must be positive") - if self.warmup_runs < 0 or self.minimum_samples < 5: - raise ValueError("warmups must be non-negative and samples at least five") - if ( - not math.isfinite(self.resource_sample_interval_seconds) - or self.resource_sample_interval_seconds <= 0.0 - ): - raise ValueError("resource sample interval must be positive") - if ( - not math.isfinite(self.termination_grace_seconds) - or self.termination_grace_seconds < 0.0 - ): - raise ValueError("termination grace must be non-negative") - if self.manual_terminal_censors and self.campaign_policy is not STRICT_POLICY: - raise ValueError("manual terminal censors require the strict base policy") - if self.timeout_seconds is not None and ( - not math.isfinite(self.timeout_seconds) or self.timeout_seconds <= 0.0 - ): - raise ValueError("timeout_seconds must be positive") - if self.generation_time_limit_seconds is not None and ( - self.generation_time_limit_seconds <= 0.0 - or not math.isfinite(self.generation_time_limit_seconds) - ): - raise ValueError("generation_time_limit_seconds must be positive") - for field_name, value in ( - ("profiling_time_limit_seconds", self.profiling_time_limit_seconds), - ("validation_time_limit_seconds", self.validation_time_limit_seconds), - ): - if value is not None and (value <= 0.0 or not math.isfinite(value)): - raise ValueError(f"{field_name} must be positive") - if self.max_rss_bytes is not None and self.max_rss_bytes <= 0: - raise ValueError("max_rss_bytes must be positive") - if self.campaign_max_rss_bytes is not None and self.campaign_max_rss_bytes <= 0: - raise ValueError("campaign_max_rss_bytes must be positive") - if self.attempt_output_limit_bytes <= 0: - raise ValueError("attempt_output_limit_bytes must be positive") - if self.minimum_free_disk_bytes <= 0: - raise ValueError("minimum_free_disk_bytes must be positive") - if ( - self.campaign_max_rss_bytes is not None - and self.campaign_max_rss_bytes < self.workers - ): - raise ValueError( - "campaign_max_rss_bytes must provide at least one byte per worker" - ) - if self.campaign_invocation_id is not None and ( - not self.campaign_invocation_id - or len(self.campaign_invocation_id) > 128 - or not self.campaign_invocation_id.isprintable() - ): - raise ValueError( - "campaign_invocation_id must be 1..128 printable characters" - ) - if self.missing_only and self.rerun: - raise ValueError("--missing-only and --rerun are mutually exclusive") - if (self.original_amplicol_repository is None) != ( - self.original_amplicol_revision is None - ): - raise ValueError( - "original AmpliCol repository and revision must be specified together" - ) - if ( - self.original_amplicol_revision is not None - and re.fullmatch(r"[0-9a-f]{40}", self.original_amplicol_revision) is None - ): - raise ValueError("original AmpliCol revision must be lowercase 40-hex") - profile = self.report_profile or "" - if self.campaign_policy is not STRICT_POLICY or self.report_profile is not None: - validate_policy_profile(self.campaign_policy, profile) - if self.campaign_policy is MACBOOK_M3_Z_TABLE_F_POLICY: - if self.study_contract_sha256 is None: - raise ValueError( - "the Z-table F policy requires a study contract SHA-256" - ) - try: - z_table_f_attempt_binding(self.study_contract_sha256) - except StudyContractError as error: - raise ValueError(str(error)) from error - elif self.study_contract_sha256 is not None: - raise ValueError("a study contract SHA-256 requires the Z-table F policy") - validate_campaign_settings(self.campaign_policy, self) - - def effective_cell_rss_limit(self) -> int | None: - """Return the conservative process-tree cap for each cell worker.""" - - limits = [ - limit - for limit in ( - self.max_rss_bytes, - ( - None - if self.campaign_max_rss_bytes is None - else self.campaign_max_rss_bytes // self.workers - ), - ) - if limit is not None - ] - return min(limits) if limits else None - - -@dataclass(frozen=True, slots=True) -class PlannedCell: - cell: CellSpec - dependency: bool - baseline_cell_id: str | None - rank: int - comparison_peer_ids: tuple[str, ...] = () - optional_baseline_cell_id: str | None = None - optional_comparison_peer_ids: tuple[str, ...] = () - numerical_authority_cell_ids: tuple[str, ...] = () - force_recompare: bool = False - prerequisite_cell_ids: tuple[str, ...] = () - resource_predecessor_ids: tuple[str, ...] = () - - -@dataclass(frozen=True, slots=True) -class CellOutcome: - cell_id: str - status: str - detail: str - prerequisite_cell_ids: tuple[str, ...] = () - terminal_detail: str | None = None - - -class _CoordinationDeferred(RuntimeError): - """Signal that a ready cell lost a non-blocking coordination-lock race.""" - - def __init__(self, lock_name: str) -> None: - super().__init__(f"coordination lock is busy: {lock_name}") - self.lock_name = lock_name - - -class _PreparationFailed(RuntimeError): - """Memoized failure of one shared prepared-model prerequisite.""" - - def __init__( - self, - model: ModelKey, - reason: str, - detail: str, - supervised: SupervisedResult | None = None, - ) -> None: - super().__init__(detail) - self.model = model - self.reason = reason - self.detail = detail - self.supervised = supervised - - -def _directional_otf_artifact_owner( - cell: CellSpec, - *, - catalog: ReportCatalog, -) -> CellSpec | None: - """Return the sole selected-flow owner for one OTF all-flow artifact.""" - - if not ( - cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - and cell.workload is Workload.ALL_FLOW - ): - return None - owners = catalog.equivalent_cells(cell) - if len(owners) != 1 or owners[0].workload is not Workload.SELECTED_FLOW: - raise ValueError( - f"OTF all-flow cell {cell.cell_id!r} must have one selected-flow " - "artifact owner" - ) - return owners[0] - - -def _artifact_consumer_cell_ids( - cell: CellSpec, - *, - catalog: ReportCatalog, -) -> tuple[str, ...]: - consumers = { - cell.cell_id, - *(candidate.cell_id for candidate in catalog.equivalent_cells(cell)), - } - if ( - cell.measurement.execution_mode is ExecutionMode.ON_THE_FLY - and cell.measurement.accuracy is Accuracy.LC - and cell.workload is Workload.SELECTED_FLOW - ): - consumers.update( - candidate.cell_id - for candidate in catalog.measurement_cells() - if _directional_otf_artifact_owner(candidate, catalog=catalog) == cell - ) - return tuple(sorted(consumers)) - - -def archive_cell_attempt_history( - service: ReportService, - cell: CellSpec, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[str, ...]: - """Archive one cell's obsolete attempts while preserving live owners.""" - - return service.store.archive_obsolete_attempts( - cell.cell_id, - consumer_cell_ids=_artifact_consumer_cell_ids(cell, catalog=catalog), - ) - - -def reconcile_attempt_history( - service: ReportService, - cells: Sequence[CellSpec], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[tuple[str, str], ...]: - """Best-effort bounded startup cleanup for an explicit campaign closure.""" - - warnings: list[tuple[str, str]] = [] - for cell in sorted(cells, key=lambda candidate: candidate.cell_id): - try: - with service.store.named_lock( - f"campaign-cell-{cell.cell_id}", timeout=0.0 - ): - archive_cell_attempt_history(service, cell, catalog=catalog) - except LockTimeoutError: - continue - except Exception as error: - warnings.append((cell.cell_id, f"{type(error).__name__}: {error}")) - return tuple(warnings) - - -def _worker_environment_overrides( - settings: CampaignSettings, - coordination_root: Path, -) -> dict[str, str]: - """Return identity-neutral cross-controller worker controls.""" - - if settings.report_profile != X86_EPYC_PROFILE: - return {} - return { - _NATIVE_COMPILER_GATE_DIR_ENV: os.fspath( - coordination_root.resolve() / "native-compiler-slots" - ), - _NATIVE_COMPILER_GATE_SLOT_COUNT_ENV: str(X86_EPYC_NATIVE_COMPILER_SLOTS), - } - - -def _symbolica_generation_lock_path( - settings: CampaignSettings, - coordination_root: Path, - cell: CellSpec, -) -> Path | None: - if ( - settings.allow_symbolica_parallel - or cell.measurement.model is not ModelKey.UFO_SM - or cell.measurement.execution_mode is not ExecutionMode.COMPILED - ): - return None - return coordination_root.resolve() / "symbolica-ufo-compiled-generation.lock" - - -@dataclass(frozen=True, slots=True) -class CampaignResult: - planned: tuple[PlannedCell, ...] - outcomes: tuple[CellOutcome, ...] - - @property - def failed(self) -> tuple[CellOutcome, ...]: - return tuple( - outcome - for outcome in self.outcomes - if outcome.status - not in { - "ok", - "reused", - "skipped-current", - PolicyMeasurementState.GENERATION_LIMIT.value, - PolicyMeasurementState.MEMORY_LIMIT.value, - PolicyMeasurementState.WORKER_TIMEOUT.value, - PolicyMeasurementState.PROFILING_TIMEOUT.value, - PolicyMeasurementState.VALIDATION_TIMEOUT.value, - PolicyMeasurementState.DEPENDENCY.value, - PolicyMeasurementState.RESOURCE_FRONTIER.value, - } - ) - - -def select_cells( - selection: CellSelection, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CellSpec, ...]: - return tuple( - sorted( - (cell for cell in catalog.measurement_cells() if selection.matches(cell)), - key=lambda cell: cell.cell_id, - ) - ) - - -def _rank(cell: CellSpec) -> int: - if cell.measurement.execution_mode in { - ExecutionMode.AMPLICOL, - ExecutionMode.MADGRAPH, - }: - return 0 - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - return 1 - if cell.dataset_id in {"scalar_contact", "scalar_gravity"}: - return 0 - return 2 - - -_READY_MODE_ORDER = { - ExecutionMode.MADGRAPH: 0, - ExecutionMode.AMPLICOL: 1, - ExecutionMode.RECURRENCE: 2, - ExecutionMode.COMPILED: 3, - ExecutionMode.ON_THE_FLY: 4, - ExecutionMode.EAGER: 5, -} - - -def _ready_priority(cell: CellSpec) -> tuple[object, ...]: - """Prefer the authority ladder within one comparable physics cohort. - - Plan-level ordering prerequisites serialize optional authorities when both - endpoints are selected. This priority only orders otherwise-ready cells; - independent physics cohorts remain work-conserving. - """ - - return ( - cell.process_key or cell.process, - cell.n_final, - cell.measurement.accuracy.value, - cell.workload.value, - _READY_MODE_ORDER[cell.measurement.execution_mode], - "" if cell.measurement.model is None else cell.measurement.model.value, - cell.variant or "", - cell.cell_id, - ) - - -def _successful_current( - store: ArtifactStore, - cell_id: str, - *, - expected_revision: str | None = None, - expected_tree: str | None = None, - expected_cell: CellSpec | None = None, - measurement_lineage: MeasurementLineage | None = None, - expected_study_contract_sha256: str | None = None, - expected_worker_harness: Mapping[str, object] | None = None, - catalog: ReportCatalog = REPORT_CATALOG, -) -> CurrentRecord | None: - current = store.load_current(cell_id, missing_ok=True) - if current is None or current.result.get("status") != ResultStatus.OK.value: - return None - try: - validate_measurement( - current.result, - expected_cell=expected_cell, - catalog=catalog, - ) - if expected_study_contract_sha256 is not None: - require_z_table_f_attempt_binding( - current.result, - expected_study_contract_sha256, - ) - if expected_worker_harness is None: - raise WorkerHarnessError("the expected worker harness is unavailable") - require_worker_harness_identity( - current.result, - expected=expected_worker_harness, - ) - except (StudyContractError, ValueError): - return None - if expected_revision is not None: - provenance = current.result.get("provenance") - if measurement_lineage is not None and expected_tree is not None: - source = measurement_lineage.source_for_current( - current, - active_revision=expected_revision, - active_tree=expected_tree, - ) - else: - source = ( - (expected_revision, expected_tree or "") - if isinstance(provenance, Mapping) - and provenance.get("report_source_revision") == expected_revision - and ( - expected_tree is None - or provenance.get("report_source_tree") == expected_tree - ) - else None - ) - if source is None: - return None - return current - - -def _policy_current( - store: ArtifactStore, - cell: CellSpec, - *, - settings: CampaignSettings, - expected_revision: str | None, - expected_tree: str | None = None, - measurement_lineage: MeasurementLineage | None = None, - original_amplicol_seed: OriginalAmplicolSeed | None = None, - expected_worker_harness: Mapping[str, object] | None = None, - comparison_dependency: bool = False, - catalog: ReportCatalog = REPORT_CATALOG, -) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if settings.campaign_policy is STRICT_POLICY: - current = _successful_current( - store, - cell.cell_id, - expected_revision=expected_revision, - expected_tree=expected_tree, - expected_cell=cell, - measurement_lineage=measurement_lineage, - expected_study_contract_sha256=(settings.study_contract_sha256), - expected_worker_harness=expected_worker_harness, - catalog=catalog, - ) - if current is not None: - return current, PolicyMeasurementState.SUCCESS - if not settings.manual_terminal_censors: - return None - terminal = store.load_current(cell.cell_id, missing_ok=True) - if terminal is None: - return None - state = policy_measurement_state_hint(terminal.result) - if state is None or policy_status_label(terminal.result) is None: - return None - provenance = terminal.result.get("provenance") - if expected_revision is not None and ( - not isinstance(provenance, Mapping) - or provenance.get("report_source_revision") != expected_revision - ): - return None - try: - validate_measurement( - terminal.result, - expected_cell=cell, - catalog=catalog, - ) - except ValueError: - return None - return terminal, state - current = store.load_current(cell.cell_id, missing_ok=True) - if current is None or expected_revision is None: - return None - provenance = current.result.get("provenance") - expected_source = ( - measurement_lineage.source_for_current( - current, - active_revision=expected_revision, - active_tree=expected_tree or "", - ) - if measurement_lineage is not None and expected_tree is not None - else ( - (expected_revision, expected_tree) - if isinstance(provenance, Mapping) - and provenance.get("report_source_revision") == expected_revision - and ( - expected_tree is None - or provenance.get("report_source_tree") == expected_tree - ) - else None - ) - ) - if expected_source is None and original_amplicol_seed is not None: - expected_source = original_amplicol_seed.source_for_current( - current, - active_revision=expected_revision, - active_tree=expected_tree or "", - ) - cross_source = ( - expected_source is None - and comparison_dependency - and settings.reuse_cross_source_comparison_dependencies - and isinstance(provenance, Mapping) - and isinstance(provenance.get("report_source_revision"), str) - and isinstance(provenance.get("report_source_tree"), str) - ) - if cross_source: - expected_source = ( - str(provenance["report_source_revision"]), - str(provenance["report_source_tree"]), - ) - if expected_source is None: - return None - try: - validate_measurement( - current.result, - expected_cell=cell, - catalog=catalog, - ) - if settings.study_contract_sha256 is not None and not cross_source: - require_z_table_f_attempt_binding( - current.result, - settings.study_contract_sha256, - ) - if expected_worker_harness is None: - raise WorkerHarnessError("the expected worker harness is unavailable") - require_worker_harness_identity( - current.result, - expected=expected_worker_harness, - ) - state = validate_policy_measurement( - settings.campaign_policy, - settings.report_profile or "", - cell, - current.result, - expected_source_revision=expected_source[0], - expected_source_tree=expected_source[1], - ) - except (CampaignPolicyError, StudyContractError, ValueError): - return None - return current, state - - -def _resource_lane_key(cell: CellSpec) -> tuple[object, ...]: - """Identify one monotone multiplicity lane across the report catalog.""" - - return tuple(resource_lane_identity(cell).items()) - - -def _resource_lane_lock_name(cell: CellSpec) -> str: - encoded = json.dumps( - resource_lane_identity(cell), - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - return f"campaign-resource-lane-{hashlib.sha256(encoded).hexdigest()}" - - -def _resource_frontier_source( - store: ArtifactStore, - cell: CellSpec, - *, - settings: CampaignSettings, - catalog: ReportCatalog, - expected_revision: str | None, - expected_tree: str | None, - measurement_lineage: MeasurementLineage | None = None, - original_amplicol_seed: OriginalAmplicolSeed | None = None, - expected_worker_harness: Mapping[str, object] | None = None, - lane_cells: Sequence[CellSpec] | None = None, - current_resolver: ( - Callable[ - [CellSpec], - tuple[CurrentRecord, PolicyMeasurementState] | None, - ] - | None - ) = None, -) -> tuple[CellSpec, CurrentRecord, PolicyMeasurementState] | None: - """Return the first authenticated lower-multiplicity hard resource censor.""" - - if not settings.campaign_policy.allow_terminal_censors: - return None - lane = _resource_lane_key(cell) - sources: list[tuple[CellSpec, CurrentRecord, PolicyMeasurementState]] = [] - candidates = catalog.measurement_cells() if lane_cells is None else lane_cells - for candidate in candidates: - if candidate.n_final >= cell.n_final or _resource_lane_key(candidate) != lane: - continue - current = ( - current_resolver(candidate) - if current_resolver is not None - else _policy_current( - store, - candidate, - settings=settings, - expected_revision=expected_revision, - expected_tree=expected_tree, - measurement_lineage=measurement_lineage, - original_amplicol_seed=original_amplicol_seed, - expected_worker_harness=expected_worker_harness, - catalog=catalog, - ) - ) - if current is None: - continue - record, state = current - if state in { - PolicyMeasurementState.GENERATION_LIMIT, - PolicyMeasurementState.MEMORY_LIMIT, - }: - sources.append((candidate, record, state)) - return min(sources, key=lambda item: item[0].n_final) if sources else None - - -def _frontier_reference( - source: tuple[CellSpec, CurrentRecord, PolicyMeasurementState], - cell: CellSpec, -) -> dict[str, object]: - source_cell, record, _state = source - return resource_frontier_reference(cell, source_cell, record.result) - - -def _measurement_frontier( - measurement: Mapping[str, object], -) -> object: - provenance = measurement.get("provenance") - censor = ( - provenance.get("policy_censor") if isinstance(provenance, Mapping) else None - ) - return censor.get("frontier") if isinstance(censor, Mapping) else None - - -def _partition_dependency_records( - *, - baseline_cell_id: str | None, - comparison_peer_ids: Sequence[str], - optional_baseline_cell_id: str | None = None, - optional_comparison_peer_ids: Sequence[str] = (), - currents: Mapping[ - str, - tuple[CurrentRecord, PolicyMeasurementState], - ], -) -> tuple[ - CurrentRecord | None, - dict[str, CurrentRecord], - tuple[dict[str, object], ...], -]: - """Partition successful dependencies and retain every terminal blocker.""" - - baseline_record: CurrentRecord | None = None - terminal_required: list[dict[str, object]] = [] - terminal_ids: set[str] = set() - if baseline_cell_id is not None: - record, state = currents[baseline_cell_id] - if state is PolicyMeasurementState.SUCCESS: - baseline_record = record - else: - terminal_required.append( - dependency_reference(baseline_cell_id, record.result) - ) - terminal_ids.add(baseline_cell_id) - elif optional_baseline_cell_id is not None: - optional = currents.get(optional_baseline_cell_id) - if optional is not None and optional[1] is PolicyMeasurementState.SUCCESS: - baseline_record = optional[0] - peer_records: dict[str, CurrentRecord] = {} - for peer_cell_id in comparison_peer_ids: - record, state = currents[peer_cell_id] - if state is PolicyMeasurementState.SUCCESS: - peer_records[peer_cell_id] = record - elif peer_cell_id not in terminal_ids: - terminal_required.append( - dependency_reference(peer_cell_id, record.result) - ) - terminal_ids.add(peer_cell_id) - for peer_cell_id in optional_comparison_peer_ids: - optional = currents.get(peer_cell_id) - if optional is not None and optional[1] is PolicyMeasurementState.SUCCESS: - peer_records[peer_cell_id] = optional[0] - return baseline_record, peer_records, tuple(terminal_required) - - -def _fresh_equivalent_current( - store: ArtifactStore, - cell: CellSpec, - *, - catalog: ReportCatalog, - expected_revision: str, - expected_tree: str | None = None, - measurement_lineage: MeasurementLineage | None = None, - expected_study_contract_sha256: str | None = None, - expected_worker_harness: Mapping[str, object] | None = None, -) -> CurrentRecord | None: - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - return None - for equivalent in catalog.equivalent_cells(cell): - current = _successful_current( - store, - equivalent.cell_id, - expected_revision=expected_revision, - expected_tree=expected_tree, - expected_cell=equivalent, - measurement_lineage=measurement_lineage, - expected_study_contract_sha256=(expected_study_contract_sha256), - expected_worker_harness=expected_worker_harness, - catalog=catalog, - ) - if current is not None: - return current - return None - - -def plan_campaign( - requested: Sequence[CellSpec], - *, - store: ArtifactStore, - settings: CampaignSettings, - catalog: ReportCatalog = REPORT_CATALOG, - expected_revision: str | None = None, - expected_tree: str | None = None, - measurement_lineage: MeasurementLineage | None = None, - original_amplicol_seed: OriginalAmplicolSeed | None = None, - excluded_cell_ids: frozenset[str] = frozenset(), - expected_worker_harness: Mapping[str, object] | None = None, - current_resolver: ( - Callable[ - [CellSpec], - tuple[CurrentRecord, PolicyMeasurementState] | None, - ] - | None - ) = None, -) -> tuple[PlannedCell, ...]: - requested_ids = {cell.cell_id for cell in requested} - needed: dict[str, CellSpec] = {} - force_recompare_ids: set[str] = set() - visiting: set[str] = set() - resource_lanes: dict[tuple[object, ...], list[CellSpec]] = {} - if original_amplicol_seed is None and settings.report_profile is not None: - original_amplicol_seed = load_seed_if_present( - profile=settings.report_profile, - store=store, - ) - if settings.campaign_policy.allow_terminal_censors: - for catalog_cell in catalog.measurement_cells(): - if catalog.static_na_reason(catalog_cell) is not None: - continue - resource_lanes.setdefault( - _resource_lane_key(catalog_cell), - [], - ).append(catalog_cell) - - def resolve_current( - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - if current_resolver is not None: - return current_resolver(cell) - return _policy_current( - store, - cell, - settings=settings, - expected_revision=expected_revision, - expected_tree=expected_tree, - measurement_lineage=measurement_lineage, - original_amplicol_seed=original_amplicol_seed, - expected_worker_harness=expected_worker_harness, - comparison_dependency=comparison_dependency, - catalog=catalog, - ) - - def dependency_roles( - cell: CellSpec, - ) -> tuple[ - CellSpec | None, - CellSpec | None, - tuple[CellSpec, ...], - tuple[CellSpec, ...], - ]: - candidate_baseline = catalog.validation_baseline_cell(cell) - baseline_required = validation_baseline_is_required(cell, candidate_baseline) - edges = incoming_agreement_edges(cell, catalog=catalog) - return ( - candidate_baseline if baseline_required else None, - candidate_baseline if not baseline_required else None, - tuple(edge.baseline for edge in edges if edge.required), - tuple(edge.baseline for edge in edges if not edge.required), - ) - - def numerical_authorities(cell: CellSpec) -> tuple[CellSpec, ...]: - """Return ordered, availability-only numerical authorities. - - Construction, selector/provider, cross-layout, and built-in/UFO - dependencies remain represented by the ordinary hard dependency - roles. This list is only the independent numerical baseline chain - for compiled/eager measurements: recurrence first, then matching - original AmpliCol when the catalog exposes it. - """ - - return independent_numerical_authorities(cell, catalog=catalog) - - def higher_priority_authority_is_now_successful( - cell: CellSpec, - current: CurrentRecord, - ) -> bool: - """Whether a verified current must be reconciled with a newer peer.""" - - authorities = numerical_authorities(cell) - if not authorities: - return False - validation = current.result.get("validation") - record = ( - validation.get(INDEPENDENT_AUTHORITY_FIELD) - if isinstance(validation, Mapping) - else None - ) - if not isinstance(record, Mapping): - # Existing verified currents predate the durable authority record; - # preserve their byte-for-byte reuse contract. - return False - authority_ids = tuple(authority.cell_id for authority in authorities) - if tuple(record.get("expected_cell_ids", ())) != authority_ids: - return True - selected_id = record.get("selected_cell_id") - if not isinstance(selected_id, str) or selected_id not in authority_ids: - return True - selected_index = authority_ids.index(selected_id) - return any( - ( - resolved := resolve_current( - authority, - comparison_dependency=True, - ) - ) - is not None - and resolved[1] is PolicyMeasurementState.SUCCESS - for authority in authorities[:selected_index] - ) - - def dependencies(cell: CellSpec) -> tuple[CellSpec, ...]: - baseline, _optional_baseline, peers, _optional_peers = dependency_roles(cell) - return tuple( - { - dependency.cell_id: dependency - for dependency in ( - *((baseline,) if baseline is not None else ()), - *peers, - ) - }.values() - ) - - def optional_dependencies(cell: CellSpec) -> tuple[CellSpec, ...]: - _baseline, optional_baseline, _peers, optional_peers = dependency_roles(cell) - return tuple( - { - dependency.cell_id: dependency - for dependency in ( - *((optional_baseline,) if optional_baseline is not None else ()), - *optional_peers, - ) - }.values() - ) - - def automatically_added_authorities(cell: CellSpec) -> tuple[CellSpec, ...]: - """Return the runnable optional numerical-authority closure.""" - - if not settings.add_optional_dependencies: - return () - candidates = list(numerical_authorities(cell)) - if cell.measurement.execution_mode is ExecutionMode.RECURRENCE: - baseline = catalog.validation_baseline_cell(cell) - if ( - baseline is not None - and not validation_baseline_is_required(cell, baseline) - and baseline.measurement.execution_mode is ExecutionMode.AMPLICOL - ): - candidates.append(baseline) - return tuple( - { - authority.cell_id: authority - for authority in candidates - if ( - authority.measurement.execution_mode is not ExecutionMode.AMPLICOL - or settings.original_amplicol_available - ) - }.values() - ) - - exclusion_memo: dict[str, bool] = {} - exclusion_visiting: set[str] = set() - - def blocked_by_exclusion(cell: CellSpec) -> bool: - cached = exclusion_memo.get(cell.cell_id) - if cached is not None: - return cached - if cell.cell_id in excluded_cell_ids: - exclusion_memo[cell.cell_id] = True - return True - if cell.cell_id in exclusion_visiting: - raise ValueError( - f"report comparison dependency cycle reaches {cell.cell_id!r}" - ) - exclusion_visiting.add(cell.cell_id) - try: - blocked = any( - blocked_by_exclusion(dependency) - for dependency in dependencies(cell) - if resolve_current( - dependency, - comparison_dependency=True, - ) - is None - ) - finally: - exclusion_visiting.remove(cell.cell_id) - exclusion_memo[cell.cell_id] = blocked - return blocked - - def include(cell: CellSpec, *, explicitly_requested: bool) -> None: - if catalog.static_na_reason(cell) is not None: - return - if blocked_by_exclusion(cell): - return - cell_dependencies = dependencies(cell) - dependency_currents = { - dependency.cell_id: resolve_current( - dependency, - comparison_dependency=True, - ) - for dependency in cell_dependencies - } - missing_dependencies = tuple( - dependency - for dependency in cell_dependencies - if dependency_currents[dependency.cell_id] is None - ) - terminal_dependency_cells = tuple( - dependency - for dependency in cell_dependencies - if ( - dependency_currents[dependency.cell_id] is not None - and dependency_currents[dependency.cell_id][1] # type: ignore[index] - is not PolicyMeasurementState.SUCCESS - ) - ) - terminal_dependencies = tuple( - dependency_reference( - dependency.cell_id, - dependency_currents[dependency.cell_id][0].result, # type: ignore[index] - ) - for dependency in terminal_dependency_cells - if not settings.manual_terminal_censors - ) - current = resolve_current(cell) - frontier_source = _resource_frontier_source( - store, - cell, - settings=settings, - catalog=catalog, - expected_revision=expected_revision, - expected_tree=expected_tree, - measurement_lineage=measurement_lineage, - original_amplicol_seed=original_amplicol_seed, - expected_worker_harness=expected_worker_harness, - lane_cells=resource_lanes.get(_resource_lane_key(cell), ()), - current_resolver=resolve_current, - ) - expected_frontier = ( - None - if frontier_source is None - else _frontier_reference(frontier_source, cell) - ) - fresh_requested = False - if settings.missing_only and explicitly_requested and current is not None: - _record, state = current - if frontier_source is not None: - fresh_requested = ( - state is PolicyMeasurementState.RESOURCE_FRONTIER - and _measurement_frontier(_record.result) == expected_frontier - ) - elif state is PolicyMeasurementState.SUCCESS: - fresh_requested = ( - not missing_dependencies and not terminal_dependency_cells - and not higher_priority_authority_is_now_successful( - cell, - _record, - ) - ) - elif state is PolicyMeasurementState.DEPENDENCY: - provenance = _record.result.get("provenance") - censor = ( - provenance.get("policy_censor") - if isinstance(provenance, Mapping) - else None - ) - observed = ( - censor.get("dependencies") if isinstance(censor, Mapping) else None - ) - fresh_requested = ( - not missing_dependencies - and bool(terminal_dependencies) - and observed - == list( - sorted( - terminal_dependencies, - key=lambda item: str(item["cell_id"]), - ) - ) - ) - elif state is PolicyMeasurementState.RESOURCE_FRONTIER: - fresh_requested = False - else: - fresh_requested = True - if fresh_requested: - return - if settings.missing_only and explicitly_requested and current is not None: - force_recompare_ids.add(cell.cell_id) - if cell.cell_id in needed: - return - if cell.cell_id in visiting: - raise ValueError( - f"report comparison dependency cycle reaches {cell.cell_id!r}" - ) - visiting.add(cell.cell_id) - if frontier_source is None: - owner = _directional_otf_artifact_owner(cell, catalog=catalog) - refresh_owner = owner is not None and ( - settings.artifact_policy is ArtifactPolicy.REGENERATE - or settings.rerun - ) - required_generation_dependencies = { - dependency.cell_id: dependency for dependency in missing_dependencies - } - if refresh_owner: - required_generation_dependencies[owner.cell_id] = owner - for dependency in required_generation_dependencies.values(): - include(dependency, explicitly_requested=False) - for authority in automatically_added_authorities(cell): - if ( - resolve_current( - authority, - comparison_dependency=True, - ) - is None - ): - include(authority, explicitly_requested=False) - visiting.remove(cell.cell_id) - needed[cell.cell_id] = cell - - for cell in requested: - include(cell, explicitly_requested=True) - - if settings.campaign_policy.allow_terminal_censors: - scheduled = tuple(needed.values()) - for cell in requested: - if cell.cell_id in needed: - continue - if catalog.static_na_reason(cell) is not None: - continue - if blocked_by_exclusion(cell): - continue - if any( - predecessor.n_final < cell.n_final - and _resource_lane_key(predecessor) == _resource_lane_key(cell) - for predecessor in scheduled - ): - # The lower cell will run in this campaign. Retain the higher - # fresh current for a post-wave frontier rescan; _run_cell - # returns without launching it when the lower cell succeeds. - needed[cell.cell_id] = cell - - def scheduled_dependencies(cell: CellSpec) -> tuple[CellSpec, ...]: - return tuple( - { - dependency.cell_id: dependency - for dependency in ( - *dependencies(cell), - *optional_dependencies(cell), - ) - if dependency.cell_id in needed - }.values() - ) - - ranks: dict[str, int] = {} - - def planned_rank(cell: CellSpec) -> int: - if cell.cell_id in ranks: - return ranks[cell.cell_id] - rank = _rank(cell) - for dependency in scheduled_dependencies(cell): - scheduled = needed.get(dependency.cell_id) - if scheduled is not None: - rank = max(rank, planned_rank(scheduled) + 1) - if settings.campaign_policy.allow_terminal_censors: - predecessors = tuple( - candidate - for candidate in needed.values() - if candidate.n_final < cell.n_final - and _resource_lane_key(candidate) == _resource_lane_key(cell) - ) - if predecessors: - predecessor = max( - predecessors, - key=lambda item: item.n_final, - ) - rank = max(rank, planned_rank(predecessor) + 1) - ranks[cell.cell_id] = rank - return rank - - def validation_baseline_id(cell: CellSpec) -> str | None: - baseline, _optional, _peers, _optional_peers = dependency_roles(cell) - return None if baseline is None else baseline.cell_id - - def optional_baseline_id(cell: CellSpec) -> str | None: - _baseline, optional, _peers, _optional_peers = dependency_roles(cell) - return None if optional is None else optional.cell_id - - def comparison_peer_ids(cell: CellSpec) -> tuple[str, ...]: - _baseline, _optional, peers, _optional_peers = dependency_roles(cell) - return tuple(peer.cell_id for peer in peers) - - def optional_comparison_peer_ids(cell: CellSpec) -> tuple[str, ...]: - _baseline, _optional, _peers, optional_peers = dependency_roles(cell) - return tuple(peer.cell_id for peer in optional_peers) - - def scheduled_prerequisite_ids(cell: CellSpec) -> tuple[str, ...]: - return tuple( - sorted( - dependency.cell_id for dependency in scheduled_dependencies(cell) - ) - ) - - def resource_predecessor_ids(cell: CellSpec) -> tuple[str, ...]: - if not settings.campaign_policy.allow_terminal_censors: - return () - predecessors = tuple( - candidate - for candidate in needed.values() - if candidate.n_final < cell.n_final - and _resource_lane_key(candidate) == _resource_lane_key(cell) - ) - if not predecessors: - return () - predecessor = max( - predecessors, - key=lambda item: (item.n_final, item.cell_id), - ) - return (predecessor.cell_id,) - - return tuple( - PlannedCell( - cell=cell, - dependency=cell.cell_id not in requested_ids, - baseline_cell_id=validation_baseline_id(cell), - rank=planned_rank(cell), - comparison_peer_ids=comparison_peer_ids(cell), - optional_baseline_cell_id=optional_baseline_id(cell), - optional_comparison_peer_ids=optional_comparison_peer_ids(cell), - numerical_authority_cell_ids=tuple( - authority.cell_id for authority in numerical_authorities(cell) - ), - force_recompare=cell.cell_id in force_recompare_ids, - prerequisite_cell_ids=scheduled_prerequisite_ids(cell), - resource_predecessor_ids=resource_predecessor_ids(cell), - ) - for cell in sorted( - needed.values(), - key=lambda item: (planned_rank(item), item.cell_id), - ) - ) - - -def validate_campaign_plan( - planned: Sequence[PlannedCell], - settings: CampaignSettings, - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> None: - """Enforce study-wide plan constraints before any attempt is created.""" - - if settings.campaign_policy is not MACBOOK_M3_Z_TABLE_F_POLICY: - return - if len(planned) != 1 or planned[0].dependency: - raise StudyContractError( - "the Z-table F policy requires exactly one runnable requested " - "cell; all comparison dependencies must already have " - "authenticated currents" - ) - cell_id = planned[0].cell.cell_id - if cell_id not in frozenset(z_table_f_cell_ids()): - raise StudyContractError( - f"cell {cell_id!r} is outside the contracted 32-cell Z-table F scope" - ) - baseline = catalog.validation_baseline_cell(planned[0].cell) - baseline_required = validation_baseline_is_required(planned[0].cell, baseline) - expected_baseline_id = ( - baseline.cell_id if baseline is not None and baseline_required else None - ) - expected_optional_baseline_id = ( - baseline.cell_id if baseline is not None and not baseline_required else None - ) - edges = incoming_agreement_edges(planned[0].cell, catalog=catalog) - expected_peer_ids = tuple( - edge.baseline.cell_id for edge in edges if edge.required - ) - expected_optional_peer_ids = tuple( - edge.baseline.cell_id for edge in edges if not edge.required - ) - if ( - planned[0].baseline_cell_id != expected_baseline_id - or planned[0].comparison_peer_ids != expected_peer_ids - or planned[0].optional_baseline_cell_id - != expected_optional_baseline_id - or planned[0].optional_comparison_peer_ids - != expected_optional_peer_ids - ): - raise StudyContractError( - "the Z-table F runnable cell does not carry its canonical " - "comparison dependency plan" - ) - - -def _resource_payload( - usage: ResourceUsage, - generation_phase: GenerationPhaseEvidence | None = None, - *, - memory_limit_bytes: int | None = None, - memory_limit_reason: str | None = None, - supervised: SupervisedResult | None = None, - source_revision: str | None = None, - campaign_invocation_id: str | None = None, - supervisor_phase: str | None = None, -) -> dict[str, object]: - payload: dict[str, object] = { - "available": usage.available, - "current_rss_bytes": usage.current_rss_bytes, - "peak_rss_bytes": usage.peak_rss_bytes, - "child_count": usage.child_count, - "cpu_seconds": usage.cpu_seconds, - "wall_seconds": usage.wall_seconds, - "probe_error": usage.error, - } - if usage.memory_metric_abi is not None: - payload.update( - { - "memory_metric_abi": usage.memory_metric_abi, - "current_physical_footprint_bytes": ( - usage.current_physical_footprint_bytes - ), - "peak_physical_footprint_bytes": (usage.peak_physical_footprint_bytes), - "current_guard_bytes": usage.current_guard_bytes, - "peak_guard_bytes": usage.peak_guard_bytes, - "memory_limit_bytes": memory_limit_bytes, - "memory_limit_reason": memory_limit_reason, - "memory_probe_reason": usage.memory_probe_reason, - } - ) - if generation_phase is not None: - payload["generation_phase"] = generation_phase.as_dict() - if supervised is not None: - supervisor_payload: dict[str, object] = { - "abi": "pyamplicol-report-worker-supervisor-v1", - "reason": supervised.reason, - "returncode": supervised.returncode, - "signal_number": supervised.signal_number, - "signal_name": supervised.signal_name, - "pid": supervised.pid, - "member_pids": list(supervised.member_pids), - "phase": ( - supervisor_phase - if supervisor_phase is not None - else ( - None - if generation_phase is None - else generation_phase.final_phase - ) - ), - "phase_state_error": supervised.phase_state_error, - "stderr": supervised.supervisor_stderr, - "stderr_truncated": supervised.supervisor_stderr_truncated, - "stderr_limit_bytes": supervised.supervisor_stderr_limit_bytes, - "source_revision": source_revision, - "campaign_invocation_id": campaign_invocation_id, - "started_at_utc": supervised.started_at_utc, - "finished_at_utc": supervised.finished_at_utc, - "teardown_escalated": supervised.teardown_escalated, - "teardown_seconds": supervised.teardown_seconds, - } - if ( - supervised.output_limit_path is not None - or supervised.output_limit_bytes is not None - or supervised.observed_output_bytes is not None - ): - supervisor_payload.update( - { - "output_limit_path": supervised.output_limit_path, - "output_limit_bytes": supervised.output_limit_bytes, - "observed_output_bytes": supervised.observed_output_bytes, - } - ) - if supervised.minimum_free_disk_bytes is not None: - supervisor_payload.update( - { - "minimum_free_disk_bytes": (supervised.minimum_free_disk_bytes), - "observed_free_disk_bytes": (supervised.observed_free_disk_bytes), - } - ) - payload["supervisor"] = supervisor_payload - return payload - - -class WorkerProcessExitError(RuntimeError): - """A worker process exited independently of a supervisor resource cap.""" - - -def _worker_process_exit_error(supervised: SupervisedResult) -> WorkerProcessExitError: - if supervised.signal_name is not None and supervised.signal_number is not None: - detail = ( - f"worker terminated by {supervised.signal_name} " - f"(signal {supervised.signal_number}, return code {supervised.returncode})" - ) - else: - detail = f"worker exited with code {supervised.returncode}" - return WorkerProcessExitError(detail) - - -def _measurement_terminal_detail(result: Mapping[str, object]) -> str | None: - """Return the compact persisted reason carried by a terminal event.""" - - policy_label = policy_status_label(result) - if isinstance(policy_label, str) and policy_label.strip(): - return policy_label - failure = result.get("failure") - message = failure.get("message") if isinstance(failure, Mapping) else None - return message if isinstance(message, str) and message.strip() else None - - -def _attempt_files( - root: Path, - *, - include_heavy_artifact: bool = True, -) -> tuple[str, ...]: - members: list[str] = [] - for path in root.rglob("*"): - if ( - not path.is_file() - or path.name in {"manifest.json", "result.json"} - or path.is_symlink() - ): - continue - relative = path.relative_to(root) - if not include_heavy_artifact and relative.parts[0] == "artifact": - continue - members.append(relative.as_posix()) - return tuple(sorted(members)) - - -class CampaignScheduler: - def __init__( - self, - service: ReportService, - *, - settings: CampaignSettings, - catalog: ReportCatalog | None = None, - measurement_lineage: MeasurementLineage | None = None, - measurement_lineage_authenticated: bool = False, - study_contract: Mapping[str, object] | None = None, - study_contract_wrapper_root: Path | None = None, - ) -> None: - self.service = service - self.settings = settings - self.catalog = service.catalog if catalog is None else catalog - self.source_identity = ( - settings.source_identity_override - if settings.source_identity_override is not None - else require_eligible_report_source(service.paths.repo_root) - ) - self.source_revision = self.source_identity.revision - self.source_tree = self.source_identity.tree - if settings.campaign_policy is MACBOOK_M3_Z_TABLE_F_POLICY: - if study_contract is None or study_contract_wrapper_root is None: - raise StudyContractError( - "the Z-table F scheduler requires the authenticated " - "study contract, not only a SHA-256" - ) - authenticated_contract = authenticate_z_table_f_study_contract( - study_contract, - service.paths.repo_root, - study_contract_wrapper_root, - prior_store=service.store, - ) - if authenticated_contract.get("sha256") != settings.study_contract_sha256: - raise StudyContractError( - "the Z-table F scheduler contract SHA-256 differs from " - "campaign settings" - ) - self.study_contract = authenticated_contract - wrapper_record = authenticated_contract.get("policy_wrapper") - source_record = authenticated_contract.get("measured_source") - if not isinstance(wrapper_record, Mapping) or not isinstance( - source_record, - Mapping, - ): - raise StudyContractError("the Z-table F worker identities are missing") - self.worker_wrapper_root = study_contract_wrapper_root.expanduser().resolve( - strict=True - ) - self.worker_entrypoint = self.worker_wrapper_root / POLICY_ENTRYPOINT - self.worker_module: str | None = None - if ( - self.worker_entrypoint.is_symlink() - or not self.worker_entrypoint.is_file() - ): - raise StudyContractError( - "the authenticated policy-wrapper entrypoint is unavailable" - ) - self.worker_harness_identity = z_table_f_worker_harness_identity( - authenticated_contract - ) - else: - if study_contract is not None or study_contract_wrapper_root is not None: - raise StudyContractError( - "a study contract authorization requires the Z-table F policy" - ) - self.study_contract = None - self.worker_wrapper_root = service.paths.repo_root - source_entrypoint = service.paths.repo_root / CANONICAL_REPORT_ENTRYPOINT - if __package__.startswith("pyamplicol."): - self.worker_entrypoint: Path | None = None - self.worker_module = "pyamplicol._performance_report" - else: - self.worker_entrypoint = source_entrypoint - self.worker_module = None - self.worker_harness_identity = None - self.measurement_lineage = ( - measurement_lineage - if measurement_lineage_authenticated - else ( - None - if settings.report_profile is None - else service._measurement_lineage() - ) - ) - self.measurement_source_tree = ( - self.source_tree if settings.report_profile is not None else None - ) - self.service.bind_measurement_lineage(self.measurement_lineage) - self.original_amplicol_seed = ( - None - if settings.report_profile is None - else self.service._original_amplicol_seed() - ) - self.service.bind_original_amplicol_seed(self.original_amplicol_seed) - self._prepared_model_paths: dict[ModelKey, Path] = {} - self._prepared_model_failures: dict[ModelKey, _PreparationFailed] = {} - self._resource_lanes: dict[tuple[object, ...], tuple[CellSpec, ...]] = {} - if settings.campaign_policy.allow_terminal_censors: - grouped: dict[tuple[object, ...], list[CellSpec]] = {} - for cell in self.catalog.measurement_cells(): - if self.catalog.static_na_reason(cell) is not None: - continue - grouped.setdefault(_resource_lane_key(cell), []).append(cell) - self._resource_lanes = { - lane: tuple(sorted(cells, key=lambda item: item.n_final)) - for lane, cells in grouped.items() - } - - def _observe(self, event: str, cell: CellSpec, **values: object) -> None: - callback = self.settings.progress_observer - if callback is None: - return - # Dashboard/lease updates are informational and must not change a - # campaign result. - with suppress(Exception): - callback({"event": event, "cell_id": cell.cell_id, **values}) - - def _observe_schedule( - self, - *, - ready: int, - waiting_dependency: int, - waiting_coordination_lock: int, - ) -> None: - callback = self.settings.progress_observer - if callback is None: - return - with suppress(Exception): - callback( - { - "event": "scheduler-state", - "ready": ready, - "waiting_dependency": waiting_dependency, - "waiting_coordination_lock": waiting_coordination_lock, - } - ) - - def _cancelled(self) -> bool: - callback = self.settings.cancellation_requested - return callback is not None and callback() - - def _attach_manual_provenance( - self, - result: dict[str, object], - *, - cell: CellSpec, - censor: Mapping[str, object] | None = None, - progress_path: Path | None = None, - ) -> None: - if self.settings.source_identity_override is None: - return - # Imported lazily to keep the ordinary report scheduler independent of - # the optional manual UI during module initialization. - from .manual_campaign import reproduction_recipe - - recipe = reproduction_recipe( - cell, - repo_root=self.service.paths.repo_root, - artifact_root=self.service.paths.artifact_root, - cores=self.settings.cell_cores, - target_runtime=self.settings.target_runtime_seconds, - batch_size=self.settings.batch_size, - warmups=self.settings.warmup_runs, - minimum_samples=self.settings.minimum_samples, - measurement=result, - ) - existing = result.get("provenance") - result["provenance"] = { - **({} if not isinstance(existing, Mapping) else dict(existing)), - **self.source_identity.provenance(), - "manual_campaign": { - "cell_identity": { - "cell_id": cell.cell_id, - "dataset_id": cell.dataset_id, - "process_key": cell.process_key, - "process": cell.process, - "n_final": cell.n_final, - "workload": cell.workload.value, - "execution_mode": cell.measurement.execution_mode.value, - "model": ( - None - if cell.measurement.model is None - else cell.measurement.model.value - ), - "accuracy": cell.measurement.accuracy.value, - "backend": cell.measurement.backend, - "variant": cell.variant, - }, - "generation_limit_seconds": ( - self.settings.generation_time_limit_seconds - ), - "worker_wall_limit_seconds": self.settings.timeout_seconds, - "profiling_time_limit_seconds": ( - self.settings.profiling_time_limit_seconds - ), - "validation_time_limit_seconds": ( - self.settings.validation_time_limit_seconds - ), - "memory_limit_bytes": self._effective_cell_rss_limit(), - "campaign_memory_limit_bytes": (self.settings.campaign_max_rss_bytes), - "attempt_output_limit_bytes": ( - self.settings.attempt_output_limit_bytes - ), - "minimum_free_disk_bytes": (self.settings.minimum_free_disk_bytes), - "retained_full_workspaces": self.settings.retain_workspaces, - "workers": self.settings.workers, - "cores_per_worker": self.settings.cell_cores, - "amplicol_build_jobs": self.settings.amplicol_build_jobs, - "target_runtime_seconds": self.settings.target_runtime_seconds, - "warmup_runs": self.settings.warmup_runs, - "minimum_samples": self.settings.minimum_samples, - "batch_size": self.settings.batch_size, - "recorded_at_utc": datetime.now(UTC).isoformat(), - "public_cli_reproduction": recipe.as_dict(), - }, - **({} if censor is None else {"policy_censor": dict(censor)}), - } - from .phase_timeline import build_phase_timeline - - persisted_provenance = result["provenance"] - if not isinstance(persisted_provenance, dict): - raise TypeError("manual result provenance must be mutable") - manual = persisted_provenance["manual_campaign"] - if not isinstance(manual, dict): - raise TypeError("manual campaign provenance must be mutable") - manual["phase_timeline"] = build_phase_timeline( - result, - progress_path=progress_path, - ) - - def _manual_terminal_result( - self, - *, - cell: CellSpec, - reason: str, - resources: Mapping[str, object], - progress_path: Path | None = None, - ) -> tuple[dict[str, object], PolicyMeasurementState]: - state, censor = self._manual_terminal_contract(reason) - status = ( - ResultStatus.MEMORY_LIMIT - if reason == "memory_limit" - else ResultStatus.TIMEOUT - ) - result = failure_measurement( - status, - f"worker terminated by {reason}", - resources=resources, - ) - self._attach_manual_provenance( - result, - cell=cell, - censor=censor, - progress_path=progress_path, - ) - return result, state - - def _manual_terminal_contract( - self, - reason: str, - ) -> tuple[PolicyMeasurementState, dict[str, object]]: - if reason == "generation_timeout": - state = PolicyMeasurementState.GENERATION_LIMIT - censor = { - "kind": PolicyCensorKind.GENERATION_LIMIT.value, - "terminal_reason": reason, - "generation_limit_seconds": ( - self.settings.generation_time_limit_seconds - ), - } - elif reason == "memory_limit": - state = PolicyMeasurementState.MEMORY_LIMIT - censor = { - "kind": PolicyCensorKind.MEMORY_LIMIT.value, - "terminal_reason": reason, - "memory_limit_bytes": self._effective_cell_rss_limit(), - } - elif reason == "worker_timeout": - state = PolicyMeasurementState.WORKER_TIMEOUT - censor = { - "kind": PolicyCensorKind.WORKER_TIMEOUT.value, - "terminal_reason": reason, - "worker_wall_limit_seconds": self.settings.timeout_seconds, - } - elif reason == "profiling_timeout": - state = PolicyMeasurementState.PROFILING_TIMEOUT - censor = { - "kind": PolicyCensorKind.PROFILING_TIMEOUT.value, - "terminal_reason": reason, - "profiling_time_limit_seconds": ( - self.settings.profiling_time_limit_seconds - ), - } - elif reason == "validation_timeout": - state = PolicyMeasurementState.VALIDATION_TIMEOUT - censor = { - "kind": PolicyCensorKind.VALIDATION_TIMEOUT.value, - "terminal_reason": reason, - "validation_time_limit_seconds": ( - self.settings.validation_time_limit_seconds - ), - } - else: - raise ValueError(f"unsupported manual terminal reason {reason!r}") - return state, censor - - def _current( - self, - cell: CellSpec, - *, - comparison_dependency: bool = False, - ) -> tuple[CurrentRecord, PolicyMeasurementState] | None: - return _policy_current( - self.service.store, - cell, - settings=self.settings, - expected_revision=self.source_revision, - expected_tree=self.measurement_source_tree, - measurement_lineage=self.measurement_lineage, - original_amplicol_seed=self.original_amplicol_seed, - expected_worker_harness=self.worker_harness_identity, - comparison_dependency=comparison_dependency, - catalog=self.catalog, - ) - - def _validate_z_table_f_plan( - self, - planned: Sequence[PlannedCell], - ) -> None: - validate_campaign_plan( - planned, - self.settings, - catalog=self.catalog, - ) - if self.settings.campaign_policy is not MACBOOK_M3_Z_TABLE_F_POLICY: - return - item = planned[0] - baseline = self.catalog.validation_baseline_cell(item.cell) - edges = incoming_agreement_edges( - item.cell, - catalog=self.catalog, - ) - dependencies = ( - *( - (baseline,) - if validation_baseline_is_required(item.cell, baseline) - else () - ), - *(edge.baseline for edge in edges if edge.required), - ) - missing = tuple( - dependency.cell_id - for dependency in dependencies - if self._current(dependency, comparison_dependency=True) is None - ) - if missing: - raise StudyContractError( - "the Z-table F runnable cell has unauthenticated comparison " - f"dependencies: {', '.join(sorted(missing))}" - ) - - def _legacy_workspace_paths(self, attempt_id: str) -> tuple[Path, Path]: - """Resolve legacy copy paths without doing controller-side work.""" - - from .legacy import MaintainedLegacyApi - - api = MaintainedLegacyApi() - source = ( - ( - api.default_repository - if self.settings.original_amplicol_repository is None - else self.settings.original_amplicol_repository - ) - .expanduser() - .resolve(strict=True) - ) - destination = ( - self.service.paths.artifact_root / "legacy-workspaces" / attempt_id - ) - return source, destination - - @staticmethod - def _remove_legacy_workspace(destination: Path) -> None: - if not destination.exists(): - return - if destination.is_symlink() or not destination.is_dir(): - raise RuntimeError( - "legacy worker workspace is not its canonical regular directory: " - f"{destination}" - ) - shutil.rmtree(destination) - - @staticmethod - def _retain_bounded_log(source: Path, destination: Path) -> None: - """Retain only a small tail from a potentially runaway diagnostic.""" - - if not source.exists(): - return - if source.is_symlink() or not source.is_file(): - raise RuntimeError(f"diagnostic log is not a regular file: {source}") - size = source.stat().st_size - if source == destination and size <= _DIAGNOSTIC_TAIL_BYTES: - return - header = ( - f"[pyamplicol retained final log tail; original_bytes={size}]\n" - ).encode("ascii") - tail_bytes = max(_DIAGNOSTIC_TAIL_BYTES - len(header), 0) - with source.open("rb") as stream: - if size > tail_bytes: - stream.seek(size - tail_bytes) - tail = stream.read(tail_bytes) - destination.parent.mkdir(parents=True, exist_ok=True) - with destination.open("wb") as stream: - stream.write(header) - stream.write(tail) - - def _finalize_legacy_workspace( - self, - workspace: Path, - *, - diagnostic_path: Path, - ) -> None: - if self.settings.retain_workspaces: - return - if workspace.exists(): - self._retain_bounded_log( - workspace / "Outputs" / "log_file.txt", - diagnostic_path, - ) - self._remove_legacy_workspace(workspace) - - def _finalize_worker_log(self, worker_log: Path) -> None: - if not self.settings.retain_workspaces: - self._retain_bounded_log(worker_log, worker_log) - - def _compact_reference_artifact( - self, - cell: CellSpec, - artifact: Path, - result: dict[str, object], - ) -> None: - """Drop disposable reference builds while retaining reusable evidence.""" - - if self.settings.retain_workspaces or not artifact.exists(): - return - if artifact.is_symlink() or not artifact.is_dir(): - raise RuntimeError( - f"reference artifact is not a regular directory: {artifact}" - ) - raw_artifact_record = result.get("artifact") - if not isinstance(raw_artifact_record, Mapping): - raise RuntimeError("successful reference result has no artifact record") - artifact_record = dict(raw_artifact_record) - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - self._retain_bounded_log(artifact / "legacy.log", artifact / "legacy.log") - disposable = (artifact / "contracted-generated-library",) - elif cell.measurement.execution_mode is ExecutionMode.MADGRAPH: - self._retain_bounded_log( - artifact / "madgraph.log", - artifact / "madgraph.log", - ) - disposable = (artifact / "standalone",) - # The complete standalone tree is intentionally disposable after - # its measurement and hashes are sealed. Remove its path fields - # together with the tree so retained metadata never advertises a - # workspace that no longer exists. - artifact_record.pop("standalone", None) - artifact_record.pop("subprocess", None) - else: - return - removed: list[str] = [] - for path in disposable: - if not path.exists(): - continue - if path.is_symlink() or not path.is_dir(): - raise RuntimeError(f"disposable workspace is not a directory: {path}") - shutil.rmtree(path) - removed.append(path.name) - artifact_record["workspace_retention"] = { - "schema": "pyamplicol-reference-workspace-retention-v1", - "full_workspaces_retained": False, - "removed": removed, - } - result["artifact"] = artifact_record - - def _discard_terminal_artifact(self, artifact: Path, attempt_root: Path) -> None: - """Keep bounded reference diagnostics and remove an unusable payload.""" - - if self.settings.retain_workspaces or not artifact.exists(): - return - if artifact.is_symlink() or not artifact.is_dir(): - raise RuntimeError( - f"terminal artifact is not a regular directory: {artifact}" - ) - for name in ("legacy.log", "madgraph.log"): - self._retain_bounded_log( - artifact / name, - attempt_root / f"{Path(name).stem}-artifact-tail.log", - ) - shutil.rmtree(artifact) - - def _service_path_arguments(self) -> tuple[str, ...]: - paths = self.service.paths - return ( - "--docs-dir", - os.fspath(paths.docs_dir), - "--artifact-root", - os.fspath(paths.artifact_root), - "--coordination-root", - os.fspath(paths.coordination_root), - ) - - def _worker_invocation(self) -> tuple[str, ...]: - if self.worker_module is not None: - return ( - sys.executable, - "-I", - "-B", - "-m", - self.worker_module, - ) - if self.worker_entrypoint is None: - raise RuntimeError("performance-report worker entrypoint is unavailable") - return ( - sys.executable, - "-I", - "-S", - "-B", - os.fspath(self.worker_entrypoint), - ) - - def _worker_harness_arguments(self) -> tuple[str, ...]: - identity = self.worker_harness_identity - if identity is None: - return () - return ( - "--measurement-source-root", - os.fspath(self.service.paths.repo_root), - "--expected-measurement-source-revision", - str(identity["measured_source_revision"]), - "--expected-measurement-source-tree", - str(identity["measured_source_tree"]), - "--expected-policy-wrapper-revision", - str(identity["policy_wrapper_revision"]), - "--expected-policy-wrapper-tree", - str(identity["policy_wrapper_tree"]), - "--expected-policy-entrypoint-sha256", - str(identity["policy_entrypoint_sha256"]), - "--expected-legacy-adapter-sha256", - str(identity["legacy_adapter_sha256"]), - "--study-contract-sha256", - str(identity["study_contract_sha256"]), - ) - - def _bind_study_result( - self, - result: dict[str, object], - *, - require_existing_harness: bool = False, - ) -> None: - if self.settings.study_contract_sha256 is None: - return - identity = self.worker_harness_identity - if identity is None: - raise StudyContractError( - "the Z-table F worker harness identity is unavailable" - ) - if require_existing_harness: - require_worker_harness_identity(result, expected=identity) - else: - attach_worker_harness_identity(result, identity) - bind_z_table_f_attempt( - result, - self.settings.study_contract_sha256, - ) - - def _ensure_prepared_model(self, planned: Sequence[PlannedCell]) -> None: - models = { - item.cell.measurement.model - for item in planned - if item.cell.measurement.execution_mode - in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - } - and item.cell.measurement.model in {ModelKey.BUILTIN_SM, ModelKey.UFO_SM} - } - for model in sorted(models, key=lambda item: item.value): # type: ignore[union-attr] - assert model is not None - preflight_attempt_id = f"prepared-model-{model.value}" - representative = next( - item - for item in planned - if item.cell.measurement.model is model - and item.cell.measurement.execution_mode - in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - } - ) - result_path = ( - self.service.paths.artifact_root - / "prepared-models" - / f".preflight-{model.value}-{uuid.uuid4().hex}.json" - ) - progress_path = result_path.with_suffix(".progress.jsonl") - command = ( - *self._worker_invocation(), - "--repo-root", - os.fspath(self.service.paths.repo_root), - *self._service_path_arguments(), - *self._worker_harness_arguments(), - "_prepare", - "--model", - model.value, - "--result-json", - os.fspath(result_path), - "--progress-jsonl", - os.fspath(progress_path), - "--cell-cores", - str(self.settings.cell_cores), - "--producer-revision", - self.source_revision, - ) - preflight_timeout = self.settings.generation_time_limit_seconds - if self.settings.timeout_seconds is not None: - preflight_timeout = ( - self.settings.timeout_seconds - if preflight_timeout is None - else min(preflight_timeout, self.settings.timeout_seconds) - ) - - self._observe( - "started", - representative.cell, - dependency=representative.dependency, - ) - self._observe( - "worker", - representative.cell, - attempt_id=preflight_attempt_id, - progress_path=os.fspath(progress_path), - ) - - def observe_preflight_resources( - observation: WorkerObservation, - *, - cell: CellSpec = representative.cell, - attempt_id: str = preflight_attempt_id, - ) -> None: - self._observe( - "resource", - cell, - attempt_id=attempt_id, - pid=observation.pid, - member_pids=list(observation.member_pids), - phase=observation.phase or "preparation", - phase_sequence=None, - wall_seconds=observation.usage.wall_seconds, - cpu_seconds=observation.usage.cpu_seconds, - current_rss_bytes=observation.usage.current_rss_bytes, - peak_rss_bytes=observation.usage.peak_rss_bytes, - current_physical_footprint_bytes=( - observation.usage.current_physical_footprint_bytes - ), - peak_physical_footprint_bytes=( - observation.usage.peak_physical_footprint_bytes - ), - current_guard_bytes=observation.usage.current_guard_bytes, - peak_guard_bytes=observation.usage.peak_guard_bytes, - child_count=observation.usage.child_count, - ) - - try: - supervised = supervise_worker( - command, - timeout_seconds=preflight_timeout, - max_rss_bytes=self._effective_cell_rss_limit(), - output_file_limits={ - progress_path: self.settings.attempt_output_limit_bytes, - }, - minimum_free_disk_bytes=(self.settings.minimum_free_disk_bytes), - disk_probe_path=self.service.paths.artifact_root, - interval_seconds=(self.settings.resource_sample_interval_seconds), - termination_grace_seconds=self.settings.termination_grace_seconds, - cancellation_requested=self.settings.cancellation_requested, - observation_callback=observe_preflight_resources, - environment_overrides=_worker_environment_overrides( - self.settings, - self.service.paths.coordination_root, - ), - scrub_import_environment=(self.worker_harness_identity is not None), - working_directory=( - self.service.paths.repo_root - if self.worker_harness_identity is not None - else None - ), - capture_stderr=True, - ) - if ( - supervised.reason != "completed" - or supervised.returncode != 0 - or not result_path.is_file() - ): - effective_reason = supervised.reason - if supervised.reason == "worker_timeout": - generation_limit = self.settings.generation_time_limit_seconds - worker_limit = self.settings.timeout_seconds - effective_reason = ( - "generation_timeout" - if generation_limit is not None - and ( - worker_limit is None or generation_limit <= worker_limit - ) - else "worker_timeout" - ) - detail = None - if result_path.is_file(): - try: - detail = json.loads( - result_path.read_text(encoding="ascii") - ).get("error") - except (AttributeError, json.JSONDecodeError, OSError): - detail = None - process_detail = ( - str(_worker_process_exit_error(supervised)) - if supervised.reason == "worker_exit" - else ( - f"reason={supervised.reason}, exit={supervised.returncode}" - ) - ) - message = ( - f"{model.value} prepared-model preflight failed: " - f"{process_detail}, detail={detail}" - ) - raise _PreparationFailed( - model, - effective_reason, - message, - supervised, - ) - payload = json.loads(result_path.read_text(encoding="ascii")) - if not isinstance(payload, Mapping): - raise RuntimeError( - f"{model.value} prepared-model preflight returned " - "a non-object payload" - ) - if self.worker_harness_identity is not None: - validate_worker_harness_identity( - payload.get("worker_harness"), - expected=self.worker_harness_identity, - ) - path = Path(str(payload["path"])).resolve(strict=True) - self._prepared_model_paths[model] = path - finally: - self._observe( - "preflight-finished", - representative.cell, - attempt_id=preflight_attempt_id, - ) - result_path.unlink(missing_ok=True) - progress_path.unlink(missing_ok=True) - - def _prepare_model_for(self, planned: PlannedCell) -> None: - cell = planned.cell - model = cell.measurement.model - if cell.measurement.execution_mode not in { - ExecutionMode.EAGER, - ExecutionMode.RECURRENCE, - ExecutionMode.ON_THE_FLY, - } or model not in {ModelKey.BUILTIN_SM, ModelKey.UFO_SM}: - return - assert model is not None - if model in self._prepared_model_paths: - return - failure = self._prepared_model_failures.get(model) - if failure is not None: - raise failure - lock_name = f"campaign-prepared-model-{model.value}" - try: - with self.service.store.named_lock( - lock_name, - timeout=0.0, - cancellation_requested=self.settings.cancellation_requested, - ): - if model in self._prepared_model_paths: - return - failure = self._prepared_model_failures.get(model) - if failure is not None: - raise failure - try: - self._ensure_prepared_model((planned,)) - except _PreparationFailed as error: - self._prepared_model_failures[model] = error - raise - except Exception as error: - failure = _PreparationFailed( - model, - "error", - f"{type(error).__name__}: {error}", - ) - self._prepared_model_failures[model] = failure - raise failure from error - except LockTimeoutError as error: - raise _CoordinationDeferred(lock_name) from error - - def _preparation_failure_outcome( - self, - cell: CellSpec, - failure: _PreparationFailed, - ) -> CellOutcome: - if failure.reason == "cancelled": - return CellOutcome(cell.cell_id, "cancelled", failure.detail) - supervised = failure.supervised - manual_reason = { - "generation_timeout": "generation_timeout", - "worker_timeout": "worker_timeout", - "memory_limit": "memory_limit", - }.get(failure.reason) - if ( - self.settings.manual_terminal_censors - and supervised is not None - and manual_reason is not None - ): - resources = _resource_payload( - supervised.usage, - None, - memory_limit_bytes=supervised.memory_limit_bytes, - memory_limit_reason=supervised.memory_limit_reason, - supervised=supervised, - source_revision=self.source_revision, - campaign_invocation_id=self.settings.campaign_invocation_id, - ) - resources["terminal_reason"] = manual_reason - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=self.service.store.load_current( - cell.cell_id, - missing_ok=True, - ), - ) as attempt: - result, state = self._manual_terminal_result( - cell=cell, - reason=manual_reason, - resources=resources, - ) - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - record = attempt.publish(result) - return CellOutcome( - cell.cell_id, - state.value, - record.attempt_id, - terminal_detail=_measurement_terminal_detail(result), - ) - if supervised is not None and failure.reason in { - "worker_exit", - "memory_probe_error", - "output_limit", - "output_probe_error", - "disk_space_limit", - "disk_probe_error", - "phase_state_error", - }: - resources = _resource_payload( - supervised.usage, - supervised.generation_phase, - memory_limit_bytes=supervised.memory_limit_bytes, - memory_limit_reason=supervised.memory_limit_reason, - supervised=supervised, - source_revision=self.source_revision, - campaign_invocation_id=self.settings.campaign_invocation_id, - supervisor_phase="preparation", - ) - result = failure_measurement( - ResultStatus.ERROR, - ( - _worker_process_exit_error(supervised) - if failure.reason == "worker_exit" - else failure.detail - ), - resources=resources, - ) - self._attach_manual_provenance(result, cell=cell) - self._bind_study_result(result) - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=self.service.store.load_current( - cell.cell_id, - missing_ok=True, - ), - ) as attempt: - attempt.write_json("worker-result.json", result) - attempt.mark_failed( - str(result.get("failure")), - artifact_paths=("worker-result.json",), - ) - return CellOutcome( - cell.cell_id, - ResultStatus.ERROR.value, - attempt.attempt_id, - terminal_detail=_measurement_terminal_detail(result), - ) - return CellOutcome( - cell.cell_id, - "preparation_error", - failure.detail, - ) - - def run(self, planned: Sequence[PlannedCell]) -> CampaignResult: - ordered = tuple(planned) - self._validate_z_table_f_plan(ordered) - if self.settings.madgraph_installation is None and any( - item.cell.measurement.execution_mode is ExecutionMode.MADGRAPH - for item in ordered - ): - raise ValueError( - "campaign plan contains MadGraph reference cells but no " - "MadGraph installation is configured" - ) - static_na = tuple( - ( - item.cell.cell_id, - self.catalog.static_na_reason(item.cell), - ) - for item in ordered - if self.catalog.static_na_reason(item.cell) is not None - ) - if static_na: - cell_id, reason = static_na[0] - raise ValueError( - f"campaign plan contains catalog static N/A cell {cell_id!r}: {reason}" - ) - if self._cancelled(): - return CampaignResult(planned=ordered, outcomes=()) - if not ordered: - return CampaignResult(planned=ordered, outcomes=()) - - by_id = {item.cell.cell_id: item for item in ordered} - if len(by_id) != len(ordered): - raise ValueError("campaign plan contains duplicate cell IDs") - planned_ids = frozenset(by_id) - prerequisites: dict[str, set[str]] = {} - dependents: dict[str, set[str]] = {cell_id: set() for cell_id in planned_ids} - for item in ordered: - declared = set(item.prerequisite_cell_ids) | set( - item.resource_predecessor_ids - ) - # Hand-written/older plans did not carry explicit DAG edges. Preserve - # their dependency semantics while plan_campaign now records them. - declared.update( - cell_id - for cell_id in ( - item.baseline_cell_id, - *item.comparison_peer_ids, - ) - if cell_id is not None and cell_id in planned_ids - ) - missing = declared - planned_ids - if missing: - raise ValueError( - f"campaign plan for {item.cell.cell_id!r} references " - f"unscheduled prerequisites: {', '.join(sorted(missing))}" - ) - if item.cell.cell_id in declared: - raise ValueError( - "campaign plan contains a self dependency for " - f"{item.cell.cell_id!r}" - ) - prerequisites[item.cell.cell_id] = declared - for predecessor_id in declared: - dependents[predecessor_id].add(item.cell.cell_id) - ready: list[tuple[tuple[object, ...], str]] = [ - (_ready_priority(item.cell), item.cell.cell_id) - for item in ordered - if not prerequisites[item.cell.cell_id] - ] - heapq.heapify(ready) - queued_ids = {cell_id for _priority, cell_id in ready} - if not ready and ordered: - raise ValueError("campaign plan contains a dependency cycle") - - outcomes: list[CellOutcome] = [] - futures: dict[Future[CellOutcome], PlannedCell] = {} - waiting_locks: dict[str, float] = {} - retry_delay_seconds = min( - 0.05, - self.settings.resource_sample_interval_seconds, - ) - - def observe_schedule() -> None: - self._observe_schedule( - ready=len(queued_ids - waiting_locks.keys()), - waiting_dependency=sum(bool(value) for value in prerequisites.values()), - waiting_coordination_lock=len(waiting_locks), - ) - - def pop_lockable_candidate(now: float) -> PlannedCell | None: - deferred: list[tuple[tuple[object, ...], str]] = [] - selected: PlannedCell | None = None - active_multiplicity = ( - min(by_id[cell_id].cell.n_final for cell_id in prerequisites) - if self.settings.multiplicity_wave_barrier and prerequisites - else None - ) - while ready: - key = heapq.heappop(ready) - if ( - active_multiplicity is not None - and by_id[key[1]].cell.n_final != active_multiplicity - ): - deferred.append(key) - continue - retry_at = waiting_locks.get(key[1]) - if retry_at is not None and retry_at > now: - deferred.append(key) - continue - selected = by_id[key[1]] - queued_ids.remove(key[1]) - waiting_locks.pop(key[1], None) - break - for key in deferred: - heapq.heappush(ready, key) - return selected - - observe_schedule() - with ThreadPoolExecutor(max_workers=self.settings.workers) as executor: - while futures or queued_ids: - cancelled = self._cancelled() - now = time.monotonic() - while len(futures) < self.settings.workers: - # A fast worker can publish its terminal observer event while - # this loop is still filling slots. Re-read cancellation - # before every submission instead of relying on the outer - # loop's snapshot. - cancelled = self._cancelled() - if cancelled: - break - item = pop_lockable_candidate(now) - if item is None: - break - if self._cancelled(): - cancelled = True - queued_ids.add(item.cell.cell_id) - heapq.heappush( - ready, - (_ready_priority(item.cell), item.cell.cell_id), - ) - break - futures[executor.submit(self._run_cell, item)] = item - observe_schedule() - - if not futures: - if cancelled: - break - if not queued_ids: - break - next_retry = min(waiting_locks.values(), default=now) - time.sleep(max(0.001, min(retry_delay_seconds, next_retry - now))) - continue - - completed, _pending = wait( - tuple(futures), - timeout=retry_delay_seconds, - return_when=FIRST_COMPLETED, - ) - for future in sorted( - completed, - key=lambda candidate: futures[candidate].cell.cell_id, - ): - item = futures.pop(future) - cell_id = item.cell.cell_id - try: - outcome = future.result() - except _CoordinationDeferred: - waiting_locks[cell_id] = time.monotonic() + retry_delay_seconds - queued_ids.add(cell_id) - heapq.heappush( - ready, - (_ready_priority(item.cell), cell_id), - ) - continue - outcomes.append(outcome) - prerequisites.pop(cell_id, None) - waiting_locks.pop(cell_id, None) - for dependent_id in sorted(dependents[cell_id]): - if dependent_id not in prerequisites: - continue - remaining = prerequisites[dependent_id] - remaining.discard(cell_id) - if ( - not remaining - and dependent_id not in queued_ids - and all( - scheduled.cell.cell_id != dependent_id - for scheduled in futures.values() - ) - ): - dependent = by_id[dependent_id] - queued_ids.add(dependent_id) - heapq.heappush( - ready, - (_ready_priority(dependent.cell), dependent_id), - ) - if not futures and not queued_ids and prerequisites: - blocked = ", ".join(sorted(prerequisites)) - raise ValueError( - "campaign plan contains an unresolved dependency cycle: " - f"{blocked}" - ) - observe_schedule() - return CampaignResult( - planned=ordered, - outcomes=tuple(sorted(outcomes, key=lambda item: item.cell_id)), - ) - - def _coordination_lock_names(self, cell: CellSpec) -> tuple[str, ...]: - names = {f"campaign-cell-{cell.cell_id}"} - if self.settings.campaign_policy.allow_terminal_censors: - names.add(_resource_lane_lock_name(cell)) - return tuple(sorted(names)) - - def _run_cell(self, planned: PlannedCell) -> CellOutcome: - cell = planned.cell - if self._cancelled(): - outcome = CellOutcome(cell.cell_id, "cancelled", "not started") - self._observe( - "finished", - cell, - status=outcome.status, - detail=outcome.detail, - terminal_detail=outcome.terminal_detail, - ) - return outcome - completed_at_ns: int | None = None - completion_observed = False - try: - with ExitStack() as locks: - for lock_name in self._coordination_lock_names(cell): - try: - locks.enter_context( - self.service.store.named_lock( - lock_name, - timeout=0.0, - cancellation_requested=( - self.settings.cancellation_requested - ), - ) - ) - except LockTimeoutError as error: - raise _CoordinationDeferred(lock_name) from error - try: - try: - outcome = self._run_cell_in_lane(planned) - except _PreparationFailed as error: - # Publishing the shared-preparation terminal must remain - # inside the same cell/lane exclusion as ordinary results. - outcome = self._preparation_failure_outcome(cell, error) - completed_at_ns = time.time_ns() - completion_observed = True - self._observe( - "finished", - cell, - status=outcome.status, - detail=outcome.detail, - terminal_detail=outcome.terminal_detail, - prerequisite_cell_ids=outcome.prerequisite_cell_ids, - completed_at_ns=completed_at_ns, - ) - except (_CoordinationDeferred, LockCancelledError): - raise - except BaseException as error: - if not completion_observed: - completed_at_ns = time.time_ns() - completion_observed = True - self._observe( - "finished", - cell, - status="error", - detail=f"{type(error).__name__}: {error}", - completed_at_ns=completed_at_ns, - ) - raise - finally: - if self.settings.remove_heavy_attempt_artifacts: - try: - archive_cell_attempt_history( - self.service, - cell, - catalog=self.catalog, - ) - except Exception as error: - self._observe( - "cleanup-warning", - cell, - detail=f"{type(error).__name__}: {error}", - ) - except _CoordinationDeferred: - # A lock race is scheduling state, not a worker failure. The ready - # queue will defer and retry this cell without emitting completion. - raise - except LockCancelledError: - outcome = CellOutcome(cell.cell_id, "cancelled", "lock wait cancelled") - completed_at_ns = time.time_ns() - except BaseException as error: - if not completion_observed: - self._observe( - "finished", - cell, - status="error", - detail=f"{type(error).__name__}: {error}", - completed_at_ns=(completed_at_ns or time.time_ns()), - ) - raise - assert completed_at_ns is not None - if not completion_observed: - self._observe( - "finished", - cell, - status=outcome.status, - detail=outcome.detail, - terminal_detail=outcome.terminal_detail, - prerequisite_cell_ids=outcome.prerequisite_cell_ids, - completed_at_ns=completed_at_ns, - ) - return outcome - - def _run_cell_in_lane(self, planned: PlannedCell) -> CellOutcome: - if self.settings.campaign_policy is MACBOOK_M3_Z_TABLE_F_POLICY: - self._validate_z_table_f_plan((planned,)) - cell = planned.cell - # Coordination locks are acquired non-blockingly by _run_cell before a - # worker slot performs any artifact or dependency work. - with ExitStack() as lane_locks: - fresh = self._current(cell) - frontier_source = ( - _resource_frontier_source( - self.service.store, - cell, - settings=self.settings, - catalog=self.catalog, - expected_revision=self.source_revision, - expected_tree=self.measurement_source_tree, - measurement_lineage=self.measurement_lineage, - original_amplicol_seed=self.original_amplicol_seed, - expected_worker_harness=self.worker_harness_identity, - lane_cells=self._resource_lanes.get( - _resource_lane_key(cell), - (), - ), - ) - if planned.dependency - else None - ) - if ( - self.settings.missing_only - and not planned.force_recompare - and fresh is not None - and frontier_source is None - ): - return CellOutcome(cell.cell_id, "skipped-current", "already complete") - if frontier_source is not None: - expected_frontier = _frontier_reference(frontier_source, cell) - if ( - fresh is not None - and fresh[1] is PolicyMeasurementState.RESOURCE_FRONTIER - and _measurement_frontier(fresh[0].result) == expected_frontier - ): - return CellOutcome( - cell.cell_id, - "skipped-current", - "resource frontier already authenticated", - ) - decision = self.service.store.decide( - cell.cell_id, - self.settings.artifact_policy, - ) - if frontier_source is not None: - return self._publish_resource_frontier( - cell, - _frontier_reference(frontier_source, cell), - current=decision.current, - ) - current_is_fresh = fresh is not None - if ( - decision.action is ArtifactAction.REUSE_CURRENT - and decision.current is not None - and current_is_fresh - and not self.settings.rerun - and not planned.force_recompare - ): - return CellOutcome(cell.cell_id, "reused", decision.current.attempt_id) - - artifact_owner = _directional_otf_artifact_owner( - cell, - catalog=self.catalog, - ) - equivalent_record = ( - _fresh_equivalent_current( - self.service.store, - cell, - catalog=self.catalog, - expected_revision=self.source_revision, - expected_tree=self.measurement_source_tree, - measurement_lineage=self.measurement_lineage, - expected_study_contract_sha256=( - self.settings.study_contract_sha256 - ), - expected_worker_harness=self.worker_harness_identity, - ) - if ( - artifact_owner is not None - or ( - not self.settings.rerun - and self.settings.artifact_policy - in {ArtifactPolicy.REUSE, ArtifactPolicy.RETIME} - ) - ) - else None - ) - baseline = ( - None - if planned.baseline_cell_id is None - else self.catalog.cell(planned.baseline_cell_id) - ) - optional_baseline = ( - None - if planned.optional_baseline_cell_id is None - else self.catalog.cell(planned.optional_baseline_cell_id) - ) - required_dependency_ids = { - dependency_id - for dependency_id in ( - planned.baseline_cell_id, - *planned.comparison_peer_ids, - ) - if dependency_id is not None - } - dependency_cells = { - dependency.cell_id: dependency - for dependency in ( - *((baseline,) if baseline is not None else ()), - *((optional_baseline,) if optional_baseline is not None else ()), - *( - self.catalog.cell(peer_cell_id) - for peer_cell_id in ( - *planned.comparison_peer_ids, - *planned.optional_comparison_peer_ids, - *planned.numerical_authority_cell_ids, - ) - ), - ) - } - dependency_currents: dict[ - str, - tuple[CurrentRecord, PolicyMeasurementState], - ] = {} - missing_dependency_ids: list[str] = [] - for dependency in dependency_cells.values(): - current_dependency = self._current( - dependency, - comparison_dependency=True, - ) - if ( - current_dependency is None - and dependency.cell_id in required_dependency_ids - ): - missing_dependency_ids.append(dependency.cell_id) - elif current_dependency is not None: - dependency_currents[dependency.cell_id] = current_dependency - if missing_dependency_ids: - return self._publish_blocked_dependency( - cell, - missing_dependency_ids, - current=decision.current, - ) - if self.settings.manual_terminal_censors: - terminal_dependency_ids = tuple( - dependency_id - for dependency_id, (_record, state) in dependency_currents.items() - if dependency_id in required_dependency_ids - if state is not PolicyMeasurementState.SUCCESS - ) - if terminal_dependency_ids: - return self._publish_blocked_dependency( - cell, - terminal_dependency_ids, - current=decision.current, - ) - baseline_record, peer_records, terminal_dependencies = ( - _partition_dependency_records( - baseline_cell_id=(None if baseline is None else baseline.cell_id), - comparison_peer_ids=planned.comparison_peer_ids, - optional_baseline_cell_id=( - None - if optional_baseline is None - else optional_baseline.cell_id - ), - optional_comparison_peer_ids=( - planned.optional_comparison_peer_ids - ), - currents=dependency_currents, - ) - ) - # Numerical authorities are availability-only and ordered: - # recurrence first, then original AmpliCol. They never enter the - # terminal-dependency censor path, but a successful one is passed - # to the worker as the independent numerical baseline. - selected_authority_cell_id: str | None = None - for authority_cell_id in planned.numerical_authority_cell_ids: - authority = dependency_currents.get(authority_cell_id) - if ( - authority is not None - and authority[1] is PolicyMeasurementState.SUCCESS - ): - baseline_record = authority[0] - selected_authority_cell_id = authority_cell_id - break - if terminal_dependencies: - return self._publish_dependency_censor( - cell, - terminal_dependencies, - current=decision.current, - ) - - reusable_record = ( - equivalent_record - if artifact_owner is not None - else ( - decision.current - if ( - decision.action is ArtifactAction.RETIME_CURRENT - and decision.current is not None - and current_is_fresh - and not self.settings.rerun - ) - else equivalent_record - ) - ) - if reusable_record is not None: - artifact_use_lock = ( - f"campaign-artifact-use-{reusable_record.attempt_id}" - ) - try: - lane_locks.enter_context( - self.service.store.named_lock( - artifact_use_lock, - timeout=0.0, - cancellation_requested=( - self.settings.cancellation_requested - ), - ) - ) - except LockTimeoutError as error: - raise _CoordinationDeferred(artifact_use_lock) from error - artifact = reusable_record.result.get("artifact") - artifact_path = ( - artifact.get("path") - if isinstance(artifact, Mapping) - else None - ) - if isinstance(artifact_path, str) and not Path(artifact_path).is_dir(): - reusable_record = None - if artifact_owner is not None and reusable_record is None: - raise RuntimeError( - f"OTF all-flow cell {cell.cell_id!r} has no fresh artifact " - f"from selected-flow owner {artifact_owner.cell_id!r}" - ) - if reusable_record is None: - self._prepare_model_for(planned) - self._observe("started", cell, dependency=planned.dependency) - - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=decision.current, - ) as attempt: - worker_result = attempt.path("worker-result.json") - worker_log = attempt.path("worker.log") - worker_progress = attempt.path("worker-progress.jsonl") - generation_timeout = ( - self.settings.generation_time_limit_seconds - if self.settings.campaign_policy is STRICT_POLICY - else generation_limit_for_cell( - self.settings.campaign_policy, - cell, - ) - ) - generation_lock_path = ( - None - if reusable_record is not None - else _symbolica_generation_lock_path( - self.settings, - self.service.paths.coordination_root, - cell, - ) - ) - phase_channel = ( - None - if generation_timeout is None - and self.settings.profiling_time_limit_seconds is None - and self.settings.validation_time_limit_seconds is None - and generation_lock_path is None - else WorkerPhaseChannel.create( - attempt.path("worker-phase-state.json") - ) - ) - command = [ - *self._worker_invocation(), - "--repo-root", - os.fspath(self.service.paths.repo_root), - *self._service_path_arguments(), - *self._worker_harness_arguments(), - "_worker", - "--cell-id", - cell.cell_id, - "--attempt-root", - os.fspath(attempt.root), - "--result-json", - os.fspath(worker_result), - "--log-path", - os.fspath(worker_log), - "--target-runtime", - str(self.settings.target_runtime_seconds), - "--batch-size", - str(self.settings.batch_size), - "--cell-cores", - str(self.settings.cell_cores), - "--amplicol-build-jobs", - str(self.settings.amplicol_build_jobs), - "--warmup-runs", - str(self.settings.warmup_runs), - "--minimum-samples", - str(self.settings.minimum_samples), - "--progress-jsonl", - os.fspath(worker_progress), - ] - memory_limit_bytes = self._effective_cell_rss_limit() - if memory_limit_bytes is not None: - command.extend(("--memory-limit-bytes", str(memory_limit_bytes))) - for option, limit in ( - ("--worker-wall-limit", self.settings.timeout_seconds), - ( - "--profiling-time-limit", - self.settings.profiling_time_limit_seconds, - ), - ( - "--validation-time-limit", - self.settings.validation_time_limit_seconds, - ), - ): - if limit is not None: - command.extend((option, str(limit))) - if self.settings.source_identity_override is not None: - command.extend( - ( - "--manual-source-revision", - self.source_revision, - "--manual-source-tree", - self.source_tree, - ) - ) - if self.settings.madgraph_installation is not None: - command.extend( - ( - "--madgraph", - os.fspath(self.settings.madgraph_installation), - ) - ) - if phase_channel is not None: - command.extend( - ( - "--phase-state-path", - os.fspath(phase_channel.path), - "--phase-state-run-id", - phase_channel.run_id, - "--phase-state-authentication-key", - phase_channel.authentication_key, - ) - ) - if generation_lock_path is not None: - command.extend( - ("--generation-lock-path", os.fspath(generation_lock_path)) - ) - if baseline_record is not None: - command.extend( - ("--baseline-json", os.fspath(baseline_record.result_path)) - ) - if selected_authority_cell_id is not None: - command.extend( - ( - "--selected-authority-cell-id", - selected_authority_cell_id, - ) - ) - for authority_cell_id in planned.numerical_authority_cell_ids: - command.extend( - ("--expected-authority-cell-id", authority_cell_id) - ) - for peer_cell_id, peer_record in sorted(peer_records.items()): - command.extend( - ( - "--peer-json", - peer_cell_id, - os.fspath(peer_record.result_path), - ) - ) - prepared_model = self._prepared_model_paths.get( - cell.measurement.model # type: ignore[arg-type] - ) - if prepared_model is not None: - command.extend(("--prepared-model", os.fspath(prepared_model))) - legacy_workspace: Path | None = None - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL and ( - self.settings.campaign_policy.allow_terminal_censors - or self.settings.source_identity_override is not None - ): - legacy_source, legacy_workspace = self._legacy_workspace_paths( - attempt.attempt_id - ) - command.extend( - ( - "--legacy-source-repository", - os.fspath(legacy_source), - "--legacy-workspace", - os.fspath(legacy_workspace), - ) - ) - if self.settings.source_identity_override is not None: - command.append("--legacy-copy-source") - if self.settings.original_amplicol_revision is not None: - command.extend( - ( - "--legacy-source-revision", - self.settings.original_amplicol_revision, - ) - ) - if reusable_record is not None: - command.extend( - ( - "--reused-measurement-json", - os.fspath(reusable_record.result_path), - ) - ) - self._observe( - "worker", - cell, - attempt_id=attempt.attempt_id, - log_path=os.fspath(worker_log), - progress_path=os.fspath(worker_progress), - phase_path=( - None if phase_channel is None else os.fspath(phase_channel.path) - ), - ) - - def observe_resources(observation: WorkerObservation) -> None: - self._observe( - "resource", - cell, - attempt_id=attempt.attempt_id, - pid=observation.pid, - member_pids=list(observation.member_pids), - phase=observation.phase, - phase_sequence=observation.phase_sequence, - wall_seconds=observation.usage.wall_seconds, - cpu_seconds=observation.usage.cpu_seconds, - current_rss_bytes=observation.usage.current_rss_bytes, - peak_rss_bytes=observation.usage.peak_rss_bytes, - current_physical_footprint_bytes=( - observation.usage.current_physical_footprint_bytes - ), - peak_physical_footprint_bytes=( - observation.usage.peak_physical_footprint_bytes - ), - current_guard_bytes=observation.usage.current_guard_bytes, - peak_guard_bytes=observation.usage.peak_guard_bytes, - child_count=observation.usage.child_count, - ) - - artifact_path = attempt.root / "artifact" - output_file_limits = { - worker_log: self.settings.attempt_output_limit_bytes, - worker_progress: self.settings.attempt_output_limit_bytes, - artifact_path / "legacy.log": ( - self.settings.attempt_output_limit_bytes - ), - artifact_path / "madgraph.log": ( - self.settings.attempt_output_limit_bytes - ), - } - if legacy_workspace is not None: - output_file_limits[ - legacy_workspace / "Outputs" / "log_file.txt" - ] = self.settings.attempt_output_limit_bytes - try: - supervised = supervise_worker( - command, - timeout_seconds=self.settings.timeout_seconds, - generation_timeout_seconds=generation_timeout, - profiling_timeout_seconds=( - self.settings.profiling_time_limit_seconds - ), - validation_timeout_seconds=( - self.settings.validation_time_limit_seconds - ), - generation_guard_includes_preparation=True, - phase_channel=phase_channel, - max_rss_bytes=memory_limit_bytes, - output_file_limits=output_file_limits, - minimum_free_disk_bytes=( - self.settings.minimum_free_disk_bytes - ), - disk_probe_path=self.service.paths.artifact_root, - environment_overrides=_worker_environment_overrides( - self.settings, - self.service.paths.coordination_root, - ), - scrub_import_environment=( - self.worker_harness_identity is not None - ), - working_directory=( - self.service.paths.repo_root - if self.worker_harness_identity is not None - else None - ), - interval_seconds=( - self.settings.resource_sample_interval_seconds - ), - termination_grace_seconds=( - self.settings.termination_grace_seconds - ), - observation_callback=observe_resources, - cancellation_requested=( - self.settings.cancellation_requested - ), - capture_stderr=True, - ) - finally: - if legacy_workspace is not None: - self._finalize_legacy_workspace( - legacy_workspace, - diagnostic_path=attempt.path("legacy-generator-tail.log"), - ) - self._finalize_worker_log(worker_log) - generation_phase = supervised.generation_phase - resources = _resource_payload( - supervised.usage, - generation_phase, - memory_limit_bytes=supervised.memory_limit_bytes, - memory_limit_reason=supervised.memory_limit_reason, - supervised=supervised, - source_revision=self.source_revision, - campaign_invocation_id=self.settings.campaign_invocation_id, - ) - if supervised.reason == "cancelled": - if self.settings.discard_cancelled_attempts: - attempt.discard() - detail = ( - "incomplete attempt discarded" - if decision.current is None - else ( - "previous valid current preserved; incomplete " - "attempt discarded" - ) - ) - else: - attempt.mark_interrupted( - "worker terminated by cancellation", - artifact_paths=_attempt_files( - attempt.root, - include_heavy_artifact=( - not self.settings.remove_heavy_attempt_artifacts - ), - ), - ) - detail = ( - attempt.attempt_id - if decision.current is None - else "previous valid current preserved" - ) - return CellOutcome( - cell.cell_id, - "cancelled", - detail, - terminal_detail="worker terminated by cancellation", - ) - policy_state: PolicyMeasurementState | None = None - if self.settings.manual_terminal_censors and supervised.reason in { - "generation_timeout", - "memory_limit", - "worker_timeout", - "profiling_timeout", - "validation_timeout", - }: - resources["terminal_reason"] = supervised.reason - result, policy_state = self._manual_terminal_result( - cell=cell, - reason=supervised.reason, - resources=resources, - progress_path=worker_progress, - ) - elif ( - supervised.reason == "generation_timeout" - and generation_timeout is not None - and self.settings.campaign_policy.allow_terminal_censors - ): - phase_evidence = ( - None if generation_phase is None else generation_phase.as_dict() - ) - observed_generation = ( - phase_evidence.get("generation_elapsed_seconds") - if isinstance(phase_evidence, Mapping) - else None - ) - if ( - isinstance(phase_evidence, Mapping) - and isinstance(observed_generation, (int, float)) - and not isinstance(observed_generation, bool) - ): - result = policy_censor_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - kind=PolicyCensorKind.GENERATION_LIMIT, - source_identity=self.source_identity, - resources=resources, - observed_generation_seconds=float(observed_generation), - phase_evidence=phase_evidence, - ) - policy_state = PolicyMeasurementState.GENERATION_LIMIT - else: - result = failure_measurement( - ResultStatus.ERROR, - "generation timeout lacked authenticated phase evidence", - resources=resources, - ) - elif ( - supervised.reason == "memory_limit" - and self.settings.campaign_policy.allow_terminal_censors - ): - peak_rss = resources.get("peak_rss_bytes") - peak_guard = resources.get("peak_guard_bytes") - metric_abi = resources.get("memory_metric_abi") - limit_reason = resources.get("memory_limit_reason") - if ( - isinstance(peak_rss, int) - and not isinstance(peak_rss, bool) - and isinstance(peak_guard, int) - and not isinstance(peak_guard, bool) - and isinstance(metric_abi, str) - and isinstance(limit_reason, str) - ): - result = policy_censor_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=self.source_identity, - resources=resources, - observed_rss_bytes=peak_rss, - observed_guard_bytes=peak_guard, - memory_metric_abi=metric_abi, - memory_limit_reason=limit_reason, - ) - policy_state = PolicyMeasurementState.MEMORY_LIMIT - elif ( - isinstance(peak_rss, int) - and not isinstance(peak_rss, bool) - and metric_abi is None - and self.settings.campaign_policy - is not MACBOOK_M3_Z_TABLE_F_POLICY - ): - result = policy_censor_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - kind=PolicyCensorKind.MEMORY_LIMIT, - source_identity=self.source_identity, - resources=resources, - observed_rss_bytes=peak_rss, - ) - policy_state = PolicyMeasurementState.MEMORY_LIMIT - else: - result = failure_measurement( - ResultStatus.ERROR, - "memory limit lacked authenticated RSS evidence", - resources=resources, - ) - elif supervised.reason != "completed": - status = { - "worker_timeout": ResultStatus.TIMEOUT, - "generation_timeout": ResultStatus.TIMEOUT, - "profiling_timeout": ResultStatus.TIMEOUT, - "validation_timeout": ResultStatus.TIMEOUT, - "memory_limit": ResultStatus.MEMORY_LIMIT, - "memory_probe_error": ResultStatus.ERROR, - "output_limit": ResultStatus.ERROR, - "output_probe_error": ResultStatus.ERROR, - "disk_space_limit": ResultStatus.ERROR, - "disk_probe_error": ResultStatus.ERROR, - "phase_state_error": ResultStatus.ERROR, - "worker_exit": ResultStatus.ERROR, - }[supervised.reason] - if supervised.reason == "worker_exit": - error: BaseException | str = _worker_process_exit_error( - supervised - ) - elif supervised.reason == "phase_state_error": - error = ( - supervised.phase_state_error - or "worker phase-state validation failed" - ) - else: - error = f"worker terminated by {supervised.reason}" - result = failure_measurement( - status, - error, - resources=resources, - ) - elif supervised.returncode != 0 or not worker_result.is_file(): - result = failure_measurement( - ResultStatus.ERROR, - _worker_process_exit_error(supervised), - resources=resources, - ) - else: - raw = json.loads(worker_result.read_text(encoding="ascii")) - if not isinstance(raw, Mapping): - raise TypeError("worker result must be a JSON object") - result = dict(raw) - child_resources = result.get("resources") - child_failure = result.get("failure") - child_terminal_reason = ( - child_resources.get("terminal_reason") - if isinstance(child_resources, Mapping) - else None - ) - authenticated_child_profile_timeout = ( - result.get("status") == ResultStatus.TIMEOUT.value - and child_terminal_reason == "profiling_timeout" - and isinstance(child_failure, Mapping) - and child_failure.get("kind") == "ProfilingTimeLimitError" - ) - if authenticated_child_profile_timeout: - resources["terminal_reason"] = "profiling_timeout" - result["resources"] = resources - if ( - self.settings.manual_terminal_censors - and authenticated_child_profile_timeout - ): - policy_state, censor = self._manual_terminal_contract( - "profiling_timeout" - ) - self._attach_manual_provenance( - result, - cell=cell, - censor=censor, - progress_path=worker_progress, - ) - else: - self._attach_manual_provenance( - result, - cell=cell, - progress_path=worker_progress, - ) - self._bind_study_result( - result, - require_existing_harness=True, - ) - if supervised.reason != "completed" or ( - supervised.returncode != 0 or not worker_result.is_file() - ): - provenance = result.get("provenance") - manual_provenance = ( - provenance.get("manual_campaign") - if isinstance(provenance, Mapping) - else None - ) - if not isinstance(manual_provenance, Mapping): - self._attach_manual_provenance( - result, - cell=cell, - progress_path=worker_progress, - ) - self._bind_study_result(result) - candidate_status = result.get("status") - result_validation = result.get("validation") - authority_state = ( - result_validation.get(INDEPENDENT_AUTHORITY_FIELD) - if isinstance(result_validation, Mapping) - else None - ) - if candidate_status == ResultStatus.UNVERIFIED.value or ( - candidate_status == ResultStatus.OK.value - and isinstance(authority_state, Mapping) - ): - # Authenticate the complete retained diagnostic before any - # late authority is allowed to transform its status. - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - late_authority: tuple[str, CurrentRecord] | None = None - for authority_cell_id in planned.numerical_authority_cell_ids: - current_authority = self._current( - self.catalog.cell(authority_cell_id), - comparison_dependency=True, - ) - if ( - current_authority is not None - and current_authority[1] - is PolicyMeasurementState.SUCCESS - ): - late_authority = ( - authority_cell_id, - current_authority[0], - ) - break - previous_selected = ( - authority_state.get("selected_cell_id") - if isinstance(authority_state, Mapping) - else None - ) - should_reconcile = late_authority is not None and ( - candidate_status == ResultStatus.UNVERIFIED.value - or ( - isinstance(previous_selected, str) - and planned.numerical_authority_cell_ids.index( - late_authority[0] - ) - < planned.numerical_authority_cell_ids.index( - previous_selected - ) - ) - ) - if should_reconcile: - assert late_authority is not None - authority_cell_id, authority_record = late_authority - result = reconcile_independent_authority( - cell, - result, - authority_record.result, - authority_cell_id=authority_cell_id, - ) - if result.get("status") == ResultStatus.OK.value: - direct_peer_ids = { - edge.baseline.cell_id - for edge in incoming_agreement_edges( - cell, - catalog=self.catalog, - ) - } - late_peers = { - peer_cell_id: peer_record.result - for peer_cell_id, peer_record in peer_records.items() - } - if authority_cell_id in direct_peer_ids: - late_peers[authority_cell_id] = authority_record.result - attach_direct_agreements( - cell, - result, - late_peers, - catalog=self.catalog, - ) - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - if result["status"] == ResultStatus.OK.value: - policy_state = ( - PolicyMeasurementState.SUCCESS - if self.settings.campaign_policy is STRICT_POLICY - else validate_policy_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - result, - expected_source_revision=self.source_revision, - expected_source_tree=self.source_tree, - ) - ) - elif ( - policy_state is not None - and not self.settings.manual_terminal_censors - ): - validated_state = validate_policy_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - result, - expected_source_revision=self.source_revision, - expected_source_tree=self.source_tree, - ) - if validated_state is not policy_state: - raise RuntimeError( - "policy censor state changed during validation" - ) - if policy_state is PolicyMeasurementState.SUCCESS: - self._compact_reference_artifact(cell, artifact_path, result) - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - else: - self._discard_terminal_artifact(artifact_path, attempt.root) - attempt.write_json("worker-result.json", result) - paths = _attempt_files( - attempt.root, - include_heavy_artifact=( - policy_state is PolicyMeasurementState.SUCCESS - or not self.settings.remove_heavy_attempt_artifacts - ), - ) - if policy_state is not None: - record = attempt.publish(result, artifact_paths=paths) - return CellOutcome( - cell.cell_id, - ( - "ok" - if policy_state is PolicyMeasurementState.SUCCESS - else policy_state.value - ), - record.attempt_id, - terminal_detail=( - None - if policy_state is PolicyMeasurementState.SUCCESS - else _measurement_terminal_detail(result) - ), - ) - attempt.mark_failed( - str(result.get("failure")), - artifact_paths=paths, - ) - return CellOutcome( - cell.cell_id, - str(result["status"]), - ( - attempt.attempt_id - if decision.current is None - else "previous valid current preserved" - ), - terminal_detail=_measurement_terminal_detail(result), - ) - - def _publish_dependency_censor( - self, - cell: CellSpec, - dependencies: Sequence[Mapping[str, object]], - *, - current: CurrentRecord | None, - ) -> CellOutcome: - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=current, - ) as attempt: - result = policy_censor_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - kind=PolicyCensorKind.DEPENDENCY, - source_identity=self.source_identity, - resources=None, - dependencies=tuple( - sorted( - (dict(item) for item in dependencies), - key=lambda item: str(item["cell_id"]), - ) - ), - ) - self._bind_study_result(result) - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - record = attempt.publish(result) - return CellOutcome( - cell.cell_id, - PolicyMeasurementState.DEPENDENCY.value, - record.attempt_id, - terminal_detail=_measurement_terminal_detail(result), - ) - - def _publish_resource_frontier( - self, - cell: CellSpec, - frontier: Mapping[str, object], - *, - current: CurrentRecord | None, - ) -> CellOutcome: - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=current, - ) as attempt: - result = policy_censor_measurement( - self.settings.campaign_policy, - self.settings.report_profile or "", - cell, - kind=PolicyCensorKind.RESOURCE_FRONTIER, - source_identity=self.source_identity, - resources=None, - frontier=frontier, - ) - self._bind_study_result(result) - validate_measurement( - result, - expected_cell=cell, - catalog=self.catalog, - ) - record = attempt.publish(result) - return CellOutcome( - cell.cell_id, - PolicyMeasurementState.RESOURCE_FRONTIER.value, - record.attempt_id, - terminal_detail=_measurement_terminal_detail(result), - ) - - def _effective_cell_rss_limit(self) -> int | None: - return self.settings.effective_cell_rss_limit() - - def _publish_blocked_dependency( - self, - cell: CellSpec, - prerequisite_cell_ids: str | Sequence[str], - *, - current: CurrentRecord | None, - ) -> CellOutcome: - normalized = tuple( - sorted( - { - value - for value in ( - (prerequisite_cell_ids,) - if isinstance(prerequisite_cell_ids, str) - else prerequisite_cell_ids - ) - if isinstance(value, str) and value - } - ) - ) - if not normalized: - raise ValueError("blocked dependency requires a prerequisite cell ID") - if len(normalized) == 1: - message = ( - "blocked by dependency: required prerequisite " - f"{normalized[0]!r} is unavailable" - ) - else: - rendered = ", ".join(repr(value) for value in normalized) - message = ( - "blocked by dependency: required prerequisites " - f"{rendered} are unavailable" - ) - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=current, - ) as attempt: - result = failure_measurement(ResultStatus.SKIP, message) - result["blocked_dependency"] = { - "prerequisite_cell_ids": list(normalized), - } - self._bind_study_result(result) - attempt.write_json("worker-result.json", result) - attempt.mark_failed( - message, - artifact_paths=("worker-result.json",), - ) - return CellOutcome( - cell.cell_id, - "blocked_dependency", - message, - normalized, - terminal_detail=message, - ) - - def _publish_skip( - self, - cell: CellSpec, - message: str, - *, - current: CurrentRecord | None, - ) -> CellOutcome: - """Retain the generic failed-attempt helper for non-dependency callers.""" - - with self.service.store.new_attempt( - cell.cell_id, - self.settings.artifact_policy, - based_on=current, - ) as attempt: - result = failure_measurement(ResultStatus.SKIP, message) - self._bind_study_result(result) - attempt.write_json("worker-result.json", result) - attempt.mark_failed( - message, - artifact_paths=("worker-result.json",), - ) - return CellOutcome( - cell.cell_id, - ResultStatus.SKIP.value, - ( - attempt.attempt_id - if current is None - else "previous valid current preserved" - ), - terminal_detail=message, - ) - - -__all__ = [ - "CampaignResult", - "CampaignScheduler", - "CampaignSettings", - "CellOutcome", - "CellSelection", - "PlannedCell", - "archive_cell_attempt_history", - "plan_campaign", - "reconcile_attempt_history", - "select_cells", - "validate_campaign_plan", -] diff --git a/pyamplicol/tools/performance_report/selector_policy.py b/pyamplicol/tools/performance_report/selector_policy.py deleted file mode 100644 index b5be5236b3..0000000000 --- a/pyamplicol/tools/performance_report/selector_policy.py +++ /dev/null @@ -1,116 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Backend-independent selector policy for LC report comparisons.""" - -from __future__ import annotations - -from collections.abc import Iterable, Sequence - - -class SelectorPolicyError(ValueError): - """Raised when a physical selector axis cannot be chosen unambiguously.""" - - -def canonical_lc_flow_word(word: Sequence[int]) -> tuple[int, ...]: - """Validate and return one labelled physical LC flow word.""" - - normalized = tuple(word) - if ( - not normalized - or any( - isinstance(label, bool) or not isinstance(label, int) - for label in normalized - ) - or any(label < 1 for label in normalized) - or len(set(normalized)) != len(normalized) - ): - raise SelectorPolicyError( - "LC selector flow words must contain distinct positive source labels" - ) - return normalized - - -def canonical_lc_selector_word( - words: Iterable[Sequence[int]], -) -> tuple[int, ...]: - """Choose the backend-independent representative of a physical LC axis. - - The choice is deliberately structural. Selecting by evaluated magnitude - makes two correct backends choose different labelled components whenever - their physical axes have different enumeration orders or roundoff. - """ - - normalized = tuple(canonical_lc_flow_word(word) for word in words) - if not normalized: - raise SelectorPolicyError("LC selector derivation requires a color-flow axis") - if len(set(normalized)) != len(normalized): - raise SelectorPolicyError("LC selector color-flow words must be unique") - return min(normalized) - - -def selector_color_flow_id(word: Sequence[int]) -> str: - normalized = canonical_lc_flow_word(word) - return "flow:" + ",".join(str(label) for label in normalized) - - -def _preferred_helicities(pdg: int) -> tuple[int, ...]: - absolute = abs(int(pdg)) - if absolute in { - 1, - 2, - 3, - 4, - 5, - 6, - 11, - 12, - 13, - 14, - 15, - 16, - 21, - 22, - }: - return (-1, 1) - if absolute in {23, 24}: - return (-1, 0, 1) - return (0,) - - -def fixed_selector_helicity(pdgs: Sequence[int]) -> tuple[int, ...]: - """Return the deterministic physical helicity shared by report backends.""" - - if not pdgs: - raise SelectorPolicyError("selector helicity derivation requires external PDGs") - result: list[int] = [] - charged_current_fermions = any(abs(int(pdg)) in {12, 14, 16} for pdg in pdgs) - for index, pdg in enumerate(pdgs, start=1): - domain = _preferred_helicities(pdg) - if -1 in domain and 1 in domain: - # Prefer the left-chiral particle/right-chiral antiparticle state - # for charged-current fermion chains. Preserve the established - # alternating vector/neutral-current report convention otherwise. - if charged_current_fermions and ( - 1 <= abs(int(pdg)) <= 6 or 11 <= abs(int(pdg)) <= 16 - ): - result.append(-1 if int(pdg) > 0 else 1) - else: - result.append(-1 if index % 2 else 1) - elif 0 in domain: - result.append(0) - else: - result.append(domain[0]) - return tuple(result) - - -def selector_helicity_id(values: Sequence[int]) -> str: - return "h:" + ",".join(f"{int(value):+d}" for value in values) - - -__all__ = [ - "SelectorPolicyError", - "canonical_lc_flow_word", - "canonical_lc_selector_word", - "fixed_selector_helicity", - "selector_color_flow_id", - "selector_helicity_id", -] diff --git a/pyamplicol/tools/performance_report/service.py b/pyamplicol/tools/performance_report/service.py deleted file mode 100644 index 119ff490e6..0000000000 --- a/pyamplicol/tools/performance_report/service.py +++ /dev/null @@ -1,560 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Transactional cache merge, validation, and report-table publication.""" - -from __future__ import annotations - -import json -import re -import shutil -import tempfile -from collections import Counter -from collections.abc import Mapping -from dataclasses import dataclass -from pathlib import Path - -from .artifacts import ArtifactStore, CurrentRecord -from .cache import ( - build_reset_caches, - reset_entry, - schema_document, - validate_cache, - validate_measurement, -) -from .campaign_reset import OriginalAmplicolSeed, load_seed_if_present -from .catalog import REPORT_CATALOG, ReportCatalog -from .measurement_lineage import ( - MeasurementLineage, - load_and_audit_measurement_lineage, -) -from .models import CellSpec -from .publication import portable_publication_value -from .render import render_all_tables, summarize_visible_completeness -from .report_policy import publication_measurement_policy_issues -from .source_identity import require_eligible_report_source - - -class ReportServiceError(RuntimeError): - """Raised when cache or table publication cannot be completed.""" - - -_PROFILE_RE = re.compile(r"[A-Za-z0-9][A-Za-z0-9_.-]{0,63}") -CANONICAL_REPORT_ROOT = Path("src/pyamplicol/_profiling_campaign") -PROFILE_REPORT_ROOT = Path("docs/performance_reports") -CANONICAL_REPORT_ENTRYPOINT = CANONICAL_REPORT_ROOT / "result_tables.py" - - -def validate_profile_name(value: str) -> str: - """Return a filesystem-safe, human-readable report profile identifier.""" - - if _PROFILE_RE.fullmatch(value) is None or ".." in value: - raise ValueError( - "report profile must contain 1-64 letters, digits, dots, " - "underscores, or hyphens; it cannot contain '..'" - ) - return value - - -@dataclass(frozen=True, slots=True) -class ReportPaths: - repo_root: Path - docs_dir: Path - results_dir: Path - artifact_root: Path - coordination_root: Path - - @classmethod - def from_repo( - cls, - repo_root: Path, - *, - profile: str | None = None, - docs_dir: Path | None = None, - artifact_root: Path | None = None, - coordination_root: Path | None = None, - ) -> ReportPaths: - root = repo_root.expanduser().resolve(strict=False) - if profile is not None: - profile = validate_profile_name(profile) - if profile is not None and docs_dir is not None: - raise ValueError("profile and docs_dir are mutually exclusive") - docs = root / ( - CANONICAL_REPORT_ROOT - if profile is None - else PROFILE_REPORT_ROOT / profile - ) - if docs_dir is not None: - docs = docs_dir.expanduser().resolve(strict=False) - identity = "canonical" if profile is None else profile - default_artifacts = root / ".artifacts/performance-report" / identity - artifacts = ( - default_artifacts - if artifact_root is None - else artifact_root.expanduser().resolve(strict=False) - ) - coordination = ( - ( - root - / ".artifacts/performance-report-coordination" - / identity - ) - if coordination_root is None - else coordination_root.expanduser().resolve(strict=False) - ) - return cls(root, docs, docs / "results", artifacts, coordination) - - -def _canonical_bytes(payload: object) -> bytes: - return ( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ).encode("ascii") - - -class ReportService: - def __init__( - self, - paths: ReportPaths, - *, - catalog: ReportCatalog = REPORT_CATALOG, - portable_current_results: bool = False, - ) -> None: - self.paths = paths - self.catalog = catalog - self.store = ArtifactStore( - artifact_root=paths.artifact_root, - lock_root=paths.coordination_root, - current_publication_paths=(paths if portable_current_results else None), - ) - self._authenticated_measurement_lineage: MeasurementLineage | None = None - self._measurement_lineage_bound = False - self._authenticated_original_amplicol_seed: OriginalAmplicolSeed | None = None - self._original_amplicol_seed_bound = False - - def bind_measurement_lineage( - self, - lineage: MeasurementLineage | None, - ) -> None: - """Reuse one already fully audited bridge through a campaign transaction.""" - - self._authenticated_measurement_lineage = lineage - self._measurement_lineage_bound = True - - def _profile_name(self) -> str | None: - try: - relative = self.paths.docs_dir.relative_to( - self.paths.repo_root / PROFILE_REPORT_ROOT - ) - except ValueError: - return None - if ( - len(relative.parts) != 1 - or _PROFILE_RE.fullmatch(relative.parts[0]) is None - or ".." in relative.parts[0] - ): - return None - return relative.parts[0] - - def bind_original_amplicol_seed( - self, - seed: OriginalAmplicolSeed | None, - ) -> None: - """Reuse one already authenticated campaign-seed manifest.""" - - self._authenticated_original_amplicol_seed = seed - self._original_amplicol_seed_bound = True - - def _original_amplicol_seed(self) -> OriginalAmplicolSeed | None: - if self._original_amplicol_seed_bound: - return self._authenticated_original_amplicol_seed - profile = self._profile_name() - seed = ( - None - if profile is None - else load_seed_if_present( - profile=profile, - store=self.store, - catalog=self.catalog, - ) - ) - self.bind_original_amplicol_seed(seed) - return seed - - def _measurement_lineage(self) -> MeasurementLineage | None: - if self._measurement_lineage_bound: - return self._authenticated_measurement_lineage - if self._profile_name() is None: - return None - if not ( - self.paths.docs_dir / "measurement_lineage.json" - ).exists() and ( - not self.store.recover_current_records() - or self._original_amplicol_seed() is not None - ): - self.bind_measurement_lineage(None) - return None - source = require_eligible_report_source(self.paths.repo_root) - lineage = load_and_audit_measurement_lineage( - self.paths.repo_root, - self.paths.docs_dir, - self.store, - expected_active_source_revision=source.revision, - catalog=self.catalog, - ) - self.bind_measurement_lineage(lineage) - return lineage - - def _render_tables( - self, - caches: Mapping[str, Mapping[str, object]], - ) -> dict[str, str]: - lineage = self._measurement_lineage() - source_lineage = ( - None - if lineage is None - else (lineage.ancestor_revision, lineage.descendant_revision) - ) - if source_lineage is None: - return render_all_tables(caches, catalog=self.catalog) - return render_all_tables( - caches, - catalog=self.catalog, - authenticated_source_lineage=source_lineage, - ) - - def reset_payloads(self) -> dict[str, dict[str, object]]: - return build_reset_caches(self.catalog) - - def load_caches(self) -> dict[str, dict[str, object]]: - expected = self.reset_payloads() - caches: dict[str, dict[str, object]] = {} - for name in expected: - path = self.paths.results_dir / name - try: - payload = json.loads(path.read_text(encoding="ascii")) - except FileNotFoundError: - payload = expected[name] - except (OSError, json.JSONDecodeError) as error: - raise ReportServiceError( - f"cannot load report cache {path}: {error}" - ) from error - if not isinstance(payload, dict): - raise ReportServiceError(f"report cache {path} must be an object") - caches[name] = payload - self.validate_payloads(caches) - return caches - - def validate_payloads( - self, - caches: Mapping[str, Mapping[str, object]], - ) -> None: - cells_by_dataset: dict[str, list[object]] = {} - cells_by_id: dict[str, CellSpec] = {} - for cell in self.catalog.measurement_cells(): - cells_by_dataset.setdefault(cell.dataset_id, []).append(cell) - cells_by_id[cell.cell_id] = cell - expected_names = {f"{dataset_id}.json" for dataset_id in cells_by_dataset} - if set(caches) != expected_names: - raise ReportServiceError( - "report cache set differs from catalog; " - f"missing={sorted(expected_names - set(caches))}, " - f"extra={sorted(set(caches) - expected_names)}" - ) - for name, payload in caches.items(): - dataset_id = name.removesuffix(".json") - validate_cache( - payload, - expected_cells=cells_by_dataset[dataset_id], # type: ignore[arg-type] - catalog=self.catalog, - ) - entries = payload["entries"] - assert isinstance(entries, list) - for entry in entries: - assert isinstance(entry, Mapping) - cell = cells_by_id[str(entry["cell_id"])] - if ( - self.catalog.static_na_reason(cell) is not None - and entry.get("measurement") - != reset_entry(cell)["measurement"] - ): - raise ReportServiceError( - f"{cell.cell_id}: catalog static N/A cache entry " - "differs from the canonical reset measurement" - ) - - def merge_current( - self, - caches: dict[str, dict[str, object]], - records: tuple[CurrentRecord, ...] | None = None, - ) -> int: - records = self.store.recover_current_records() if records is None else records - source = require_eligible_report_source(self.paths.repo_root) - expected_revision = source.revision - lineage = self._measurement_lineage() - seed = self._original_amplicol_seed() - by_cell = { - record.cell_id: record - for record in records - if ( - ( - lineage.source_for_current( - record, - active_revision=source.revision, - active_tree=source.tree, - ) - is not None - if lineage is not None - else ( - isinstance(record.result.get("provenance"), Mapping) - and record.result["provenance"].get( - "report_source_revision" - ) - == expected_revision - and record.result["provenance"].get("report_source_tree") - == source.tree - ) - ) - or ( - seed is not None - and seed.source_for_current( - record, - active_revision=source.revision, - active_tree=source.tree, - ) - is not None - ) - ) - } - cells_by_id = { - cell.cell_id: cell for cell in self.catalog.measurement_cells() - } - merged = 0 - for payload in caches.values(): - entries = payload["entries"] - assert isinstance(entries, list) - for entry in entries: - assert isinstance(entry, dict) - cell_id = str(entry["cell_id"]) - cell = cells_by_id[cell_id] - if self.catalog.static_na_reason(cell) is not None: - entry["measurement"] = reset_entry(cell)["measurement"] - continue - if ( - lineage is not None - and cell_id in lineage.required_descendant_cell_ids - ): - entry["measurement"] = reset_entry(cell)["measurement"] - record = by_cell.get(cell_id) - if record is None: - continue - measurement = record.result - validate_measurement( - measurement, - expected_cell=cell, - catalog=self.catalog, - ) - entry["measurement"] = dict(measurement) - merged += 1 - self.validate_payloads(caches) - return merged - - def _snapshot_files( - self, - caches: Mapping[str, Mapping[str, object]], - tables: Mapping[str, str], - ) -> tuple[Path, ...]: - portable_caches = { - name: portable_publication_value(payload, self.paths) - for name, payload in caches.items() - } - self.validate_payloads(portable_caches) # type: ignore[arg-type] - self.paths.results_dir.mkdir(parents=True, exist_ok=True) - staging_root = self.paths.artifact_root / "report-snapshot-builds" - staging_root.mkdir(parents=True, exist_ok=True) - staging = Path( - tempfile.mkdtemp( - prefix=".report-snapshot-", - dir=staging_root, - ) - ) - written: list[Path] = [] - replaced: list[tuple[Path, Path | None]] = [] - temporary_files: list[Path] = [] - - def adjacent_temporary(destination: Path, *, kind: str) -> Path: - with tempfile.NamedTemporaryFile( - prefix=f".{destination.name}.report-{kind}-", - dir=destination.parent, - delete=False, - ) as handle: - temporary = Path(handle.name) - temporary_files.append(temporary) - return temporary - - try: - staged_results = staging / "results" - staged_results.mkdir() - schema_path = staged_results / "report-cache.schema.json" - schema_path.write_bytes(_canonical_bytes(schema_document())) - for name, payload in portable_caches.items(): - (staged_results / name).write_bytes(_canonical_bytes(payload)) - for name, content in tables.items(): - (staging / name).write_text(content, encoding="ascii") - - publications = [ - ( - schema_path, - self.paths.results_dir / "report-cache.schema.json", - Path("results/report-cache.schema.json"), - ), - *( - ( - staged_results / name, - self.paths.results_dir / name, - Path("results") / name, - ) - for name in sorted(caches) - ), - *( - ( - staging / name, - self.paths.docs_dir / name, - Path(name), - ) - for name in sorted(tables) - ), - ] - try: - for source, destination, _relative in publications: - backup: Path | None = None - if destination.exists(): - backup = adjacent_temporary(destination, kind="backup") - shutil.copy2(destination, backup) - install = adjacent_temporary(destination, kind="install") - shutil.copy2(source, install) - install.replace(destination) - replaced.append((destination, backup)) - written.append(destination) - except BaseException: - for destination, backup in reversed(replaced): - if backup is None: - destination.unlink(missing_ok=True) - else: - backup.replace(destination) - raise - finally: - for temporary in temporary_files: - temporary.unlink(missing_ok=True) - shutil.rmtree(staging, ignore_errors=True) - return tuple(written) - - def publish( - self, - *, - reset: bool = False, - merge_artifacts: bool = True, - ) -> tuple[Path, ...]: - with self.store.named_lock("report-writer"): - caches = self.reset_payloads() if reset else self.load_caches() - if merge_artifacts and not reset: - self.merge_current(caches) - tables = self._render_tables(caches) - return self._snapshot_files(caches, tables) - - def validate(self) -> dict[str, object]: - caches = self.load_caches() - tables = self._render_tables(caches) - statuses: Counter[str] = Counter() - for payload in caches.values(): - for entry in payload["entries"]: # type: ignore[index] - statuses[str(entry["measurement"]["status"])] += 1 - return { - "cache_count": len(caches), - "table_count": len(tables), - "statuses": dict(sorted(statuses.items())), - } - - def validate_publication_policy( - self, - caches: Mapping[str, Mapping[str, object]], - ) -> None: - """Reject successful measurements that are not publication-grade.""" - - issues: list[str] = [] - for payload in caches.values(): - entries = payload.get("entries") - if not isinstance(entries, list): - continue - for entry in entries: - if not isinstance(entry, Mapping): - continue - measurement = entry.get("measurement") - if not isinstance(measurement, Mapping): - continue - for issue in publication_measurement_policy_issues(measurement): - issues.append( - f"{entry.get('cell_id', '')}: " - f"{issue.field}: {issue.detail}" - ) - if issues: - displayed = "; ".join(issues[:12]) - if len(issues) > 12: - displayed += f"; ... ({len(issues)} issues total)" - raise ReportServiceError( - "checked-in measurements violate publication policy: " - + displayed - ) - - def audit(self) -> dict[str, object]: - """Validate cache coverage and exact checked-in render correspondence.""" - - result = self.validate() - caches = self.load_caches() - self.validate_publication_policy(caches) - rendered = self._render_tables(caches) - visible_completeness = summarize_visible_completeness( - caches, - catalog=self.catalog, - ) - expected_cache_files = { - *caches, - "report-cache.schema.json", - } - actual_cache_files = { - path.name for path in self.paths.results_dir.glob("*.json") - } - if actual_cache_files != expected_cache_files: - raise ReportServiceError( - "checked-in report cache files differ from the catalog; " - f"missing={sorted(expected_cache_files - actual_cache_files)}, " - f"extra={sorted(actual_cache_files - expected_cache_files)}" - ) - mismatched_tables = [ - name - for name, content in rendered.items() - if not (self.paths.docs_dir / name).is_file() - or (self.paths.docs_dir / name).read_text(encoding="ascii") != content - ] - if mismatched_tables: - raise ReportServiceError( - "checked-in report tables differ from canonical rendering: " - + ", ".join(sorted(mismatched_tables)) - ) - return { - **result, - "cache_render_match": True, - "visible_completeness": visible_completeness.as_dict(), - } - - -__all__ = [ - "ReportPaths", - "ReportService", - "ReportServiceError", - "validate_profile_name", -] diff --git a/pyamplicol/tools/performance_report/source_identity.py b/pyamplicol/tools/performance_report/source_identity.py deleted file mode 100644 index 4f089376de..0000000000 --- a/pyamplicol/tools/performance_report/source_identity.py +++ /dev/null @@ -1,527 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Fail-closed source identity for reproducible report measurements.""" - -from __future__ import annotations - -import os -import subprocess -from dataclasses import dataclass -from pathlib import Path, PurePosixPath - -SOURCE_IDENTITY_SCHEMA = "pyamplicol-report-source-v1" -PUBLICATION_SOURCE_IDENTITY_SCHEMA = "pyamplicol-report-publication-source-v1" - - -class ReportSourceIdentityError(RuntimeError): - """The report source cannot be identified as an immutable checkout.""" - - -def _git_output(repo_root: Path, *arguments: str) -> bytes: - try: - completed = subprocess.run( - ("git", *arguments), - cwd=repo_root, - check=False, - capture_output=True, - timeout=15, - ) - except (OSError, subprocess.SubprocessError) as error: - raise ReportSourceIdentityError( - f"cannot inspect report source at {repo_root}: {error}" - ) from error - if completed.returncode != 0: - detail = completed.stderr.decode("utf-8", errors="replace").strip() - raise ReportSourceIdentityError( - f"git {' '.join(arguments)} failed at {repo_root}: " - f"{detail or f'exit {completed.returncode}'}" - ) - return completed.stdout - - -def _require_repository_root(repo_root: Path) -> Path: - """Reject a nested path that Git would silently bind to a parent checkout.""" - - try: - root = repo_root.expanduser().resolve(strict=True) - except OSError as error: - raise ReportSourceIdentityError( - f"report source root is unavailable: {repo_root}" - ) from error - raw = _git_output(root, "rev-parse", "--show-toplevel") - rendered = os.fsdecode(raw).strip() - if not rendered: - raise ReportSourceIdentityError( - f"git returned an empty repository root for {root}" - ) - try: - discovered = Path(rendered).resolve(strict=True) - except (OSError, ValueError) as error: - raise ReportSourceIdentityError( - f"git returned an invalid repository root for {root}" - ) from error - if discovered != root: - raise ReportSourceIdentityError( - f"report source is not the repository root: {root} (Git root {discovered})" - ) - return root - - -def _git_commit(repo_root: Path, revision: str) -> str: - commit = ( - _git_output(repo_root, "rev-parse", "--verify", f"{revision}^{{commit}}") - .decode("ascii") - .strip() - ) - if not commit: - raise ReportSourceIdentityError( - f"git returned an empty commit identity for {revision!r}" - ) - return commit - - -def _git_tree(repo_root: Path, revision: str) -> str: - tree = ( - _git_output(repo_root, "rev-parse", "--verify", f"{revision}^{{tree}}") - .decode("ascii") - .strip() - ) - if not tree: - raise ReportSourceIdentityError( - f"git returned an empty tree identity for {revision!r}" - ) - return tree - - -def _generated_report_path(value: str) -> bool: - """Return whether a dirty path is a generated report output. - - Benchmark caches, rendered tables, authenticated environment metadata, - PDFs, campaign-local evaluator attempts, and the corresponding generated - files inside one architecture-profile workspace are outputs of a report - campaign. - They do not alter the evaluator source being measured and therefore do not - make the source checkout ineligible. Profile prose, manifests, entry points, - nested files, and all other tracked or untracked changes do. - """ - - path = PurePosixPath(value) - parts = path.parts - if not parts: - return False - if parts[0] in {".artifacts", "tmp"}: - return True - if ( - len(parts) >= 5 - and parts[:3] == ("src", "pyamplicol", "_profiling_campaign") - and parts[3] == "campaign_artifacts" - ): - return True - if ( - len(parts) == 5 - and parts[:4] - == ("src", "pyamplicol", "_profiling_campaign", "results") - and parts[4].endswith(".json") - ): - return True - if ( - len(parts) == 4 - and parts[:3] == ("src", "pyamplicol", "_profiling_campaign") - ): - return _generated_publication_member( - parts[3], - allow_auxiliary=True, - allow_environment=True, - ) - if ( - len(parts) >= 5 - and parts[:2] == ("docs", "performance_reports") - and parts[2] not in {"", ".", ".."} - and parts[3] == "campaign_artifacts" - ): - return True - if parts[:4] == ("docs", "arxiv", "results", ".coordination"): - return True - if ( - len(parts) == 4 - and parts[:3] == ("docs", "arxiv", "results") - and parts[3].endswith((".json", ".lock")) - ): - return True - if len(parts) == 3 and parts[:2] == ("docs", "arxiv"): - return _generated_publication_member( - parts[2], - allow_auxiliary=True, - allow_environment=False, - ) - if ( - len(parts) == 5 - and parts[:2] == ("docs", "performance_reports") - and parts[3] == "results" - and parts[4].endswith(".json") - ): - return True - if ( - len(parts) == 5 - and parts[:2] == ("docs", "performance_reports") - and parts[3] == "campaign_summary_ids" - and parts[4].endswith(".txt") - ): - return True - if len(parts) == 4 and parts[:2] == ("docs", "performance_reports"): - return _generated_publication_member( - parts[3], - allow_auxiliary=True, - allow_environment=True, - ) - return False - - -def _generated_publication_member( - name: str, - *, - allow_auxiliary: bool, - allow_environment: bool, -) -> bool: - if name == "pyAmpliCol.pdf": - return True - if allow_environment and name in { - "measurement_lineage.json", - "report_environment.json", - "report_environment.tex", - }: - return True - if name == "result_validation_summary.tex": - return True - if name.startswith("result_") and name.endswith("_table.tex"): - return True - return allow_auxiliary and name.endswith( - ( - ".aux", - ".bbl", - ".bcf", - ".blg", - ".fdb_latexmk", - ".fls", - ".log", - ".out", - ".run.xml", - ".synctex.gz", - ".toc", - ) - ) - - -def _architecture_report_path(value: str, profile: str) -> bool: - """Return whether ``value`` is a tracked publication member for ``profile``. - - This is deliberately narrower than a directory-prefix check. In - particular, executables, arbitrary nested files, evaluator tools, profile - prose, and manifests are not report-only changes. A measurement commit can - therefore be published from a descendant commit only when every intervening - path is raw result JSON, authenticated generated environment metadata, a - generated table or validation summary, or the reviewed PDF. - """ - - path = PurePosixPath(value) - root = ("docs", "performance_reports", profile) - parts = path.parts - if parts[:3] != root: - return False - relative = parts[3:] - if len(relative) == 1: - return _generated_publication_member( - relative[0], - allow_auxiliary=False, - allow_environment=True, - ) - if len(relative) == 2 and relative[0] == "results": - return relative[1].endswith(".json") - return False - - -def _diff_changes( - repo_root: Path, - measured: str, - publication: str, -) -> tuple[tuple[str, tuple[str, ...]], ...]: - tokens = iter( - _nul_paths( - _git_output( - repo_root, - "diff", - "--name-status", - "-z", - "--find-renames", - f"{measured}..{publication}", - "--", - ) - ) - ) - changes: list[tuple[str, tuple[str, ...]]] = [] - while True: - try: - status = next(tokens) - except StopIteration: - break - try: - if status.startswith(("R", "C")): - paths = (next(tokens), next(tokens)) - else: - paths = (next(tokens),) - except StopIteration as error: - raise ReportSourceIdentityError( - "git returned a malformed publication diff" - ) from error - changes.append((status, paths)) - return tuple(changes) - - -def _git_path_mode(repo_root: Path, revision: str, path: str) -> str | None: - raw = _git_output(repo_root, "ls-tree", "-z", revision, "--", path) - if not raw: - return None - record = raw.split(b"\0", 1)[0] - header, separator, recorded_path = record.partition(b"\t") - if not separator or os.fsdecode(recorded_path) != path: - raise ReportSourceIdentityError( - f"git returned malformed tree metadata for {path!r}" - ) - fields = header.split() - if len(fields) != 3: - raise ReportSourceIdentityError( - f"git returned malformed tree mode for {path!r}" - ) - return fields[0].decode("ascii") - - -def _nul_paths(payload: bytes) -> tuple[str, ...]: - return tuple( - os.fsdecode(raw) - for raw in payload.split(b"\0") - if raw - ) - - -@dataclass(frozen=True, slots=True) -class ReportSourceIdentity: - """Committed source identity plus any disqualifying working-tree changes.""" - - revision: str - tree: str - dirty_paths: tuple[str, ...] - - @property - def eligible(self) -> bool: - return not self.dirty_paths - - def provenance(self) -> dict[str, object]: - return { - "report_source_identity_schema": SOURCE_IDENTITY_SCHEMA, - "report_source_revision": self.revision, - "report_source_tree": self.tree, - "report_measured_source_revision": self.revision, - "report_measured_source_tree": self.tree, - "report_source_clean": self.eligible, - } - - -@dataclass(frozen=True, slots=True) -class ReportPublicationIdentity: - """Authenticated relation between measured and published source commits.""" - - profile: str - measured_revision: str - measured_tree: str - publication_revision: str - publication_tree: str - changed_paths: tuple[str, ...] - disallowed_paths: tuple[str, ...] - - @property - def eligible(self) -> bool: - return not self.disallowed_paths - - def provenance(self) -> dict[str, object]: - """Return a non-self-referential audit record for external retention. - - The publication revision cannot be embedded in a file contained by - that same commit without changing the commit hash. Final-audit output - or release metadata should retain this mapping instead. - """ - - return { - "report_publication_source_identity_schema": ( - PUBLICATION_SOURCE_IDENTITY_SCHEMA - ), - "report_profile": self.profile, - "report_measured_source_revision": self.measured_revision, - "report_measured_source_tree": self.measured_tree, - "report_publication_revision": self.publication_revision, - "report_publication_tree": self.publication_tree, - "report_publication_report_only": self.eligible, - "report_publication_changed_paths": list(self.changed_paths), - } - - -def inspect_report_source(repo_root: Path) -> ReportSourceIdentity: - """Inspect the current Git commit and fail-relevant working-tree changes.""" - - root = _require_repository_root(repo_root) - revision = _git_commit(root, "HEAD") - tree = _git_tree(root, revision) - changed = { - *_nul_paths( - _git_output( - root, - "diff", - "--name-only", - "--no-renames", - "-z", - "HEAD", - "--", - ) - ), - *_nul_paths( - _git_output( - root, - "ls-files", - "--others", - "--exclude-standard", - "-z", - "--", - ) - ), - } - dirty = tuple( - sorted(path for path in changed if not _generated_report_path(path)) - ) - return ReportSourceIdentity(revision, tree, dirty) - - -def inspect_report_publication( - repo_root: Path, - *, - measured_revision: str, - profile: str, - publication_revision: str = "HEAD", -) -> ReportPublicationIdentity: - """Inspect a publication commit descended from an exact measurement SHA.""" - - if ( - not profile - or "/" in profile - or "\\" in profile - or profile in {".", ".."} - or ".." in profile - ): - raise ValueError("report profile must be one safe path component") - root = _require_repository_root(repo_root) - measured = _git_commit(root, measured_revision) - publication = _git_commit(root, publication_revision) - try: - ancestry = subprocess.run( - ("git", "merge-base", "--is-ancestor", measured, publication), - cwd=root, - check=False, - capture_output=True, - timeout=15, - ) - except (OSError, subprocess.SubprocessError) as error: - raise ReportSourceIdentityError( - f"cannot authenticate report publication ancestry: {error}" - ) from error - if ancestry.returncode == 1: - raise ReportSourceIdentityError( - "publication commit is not a descendant of measured source " - f"{measured}" - ) - if ancestry.returncode != 0: - detail = ancestry.stderr.decode("utf-8", errors="replace").strip() - raise ReportSourceIdentityError( - "cannot authenticate report publication ancestry: " - f"{detail or f'exit {ancestry.returncode}'}" - ) - changes = _diff_changes(root, measured, publication) - changed = tuple( - sorted({path for _status, paths in changes for path in paths}) - ) - disallowed: set[str] = set() - for status, paths in changes: - if status not in {"A", "M"}: - disallowed.update(paths) - continue - path = paths[0] - if not _architecture_report_path(path, profile): - disallowed.add(path) - continue - old_mode = _git_path_mode(root, measured, path) - new_mode = _git_path_mode(root, publication, path) - if new_mode != "100644" or ( - status == "M" and old_mode != "100644" - ): - disallowed.add(path) - return ReportPublicationIdentity( - profile=profile, - measured_revision=measured, - measured_tree=_git_tree(root, measured), - publication_revision=publication, - publication_tree=_git_tree(root, publication), - changed_paths=changed, - disallowed_paths=tuple(sorted(disallowed)), - ) - - -def require_eligible_report_source(repo_root: Path) -> ReportSourceIdentity: - """Return an exact source identity or reject a dirty measurement source.""" - - identity = inspect_report_source(repo_root) - if not identity.eligible: - displayed = ", ".join(identity.dirty_paths[:8]) - if len(identity.dirty_paths) > 8: - displayed += f", ... ({len(identity.dirty_paths)} paths total)" - raise ReportSourceIdentityError( - "report measurements require a clean evaluator source checkout; " - f"dirty source paths: {displayed}" - ) - return identity - - -def require_report_only_publication( - repo_root: Path, - *, - measured_revision: str, - profile: str, - publication_revision: str = "HEAD", -) -> ReportPublicationIdentity: - """Authenticate a descendant with only profile-publication changes.""" - - identity = inspect_report_publication( - repo_root, - measured_revision=measured_revision, - profile=profile, - publication_revision=publication_revision, - ) - if not identity.eligible: - displayed = ", ".join(identity.disallowed_paths[:8]) - if len(identity.disallowed_paths) > 8: - displayed += ( - f", ... ({len(identity.disallowed_paths)} paths total)" - ) - raise ReportSourceIdentityError( - "publication changed evaluator or non-profile source after " - f"measurement; disallowed paths: {displayed}" - ) - return identity - - -__all__ = [ - "PUBLICATION_SOURCE_IDENTITY_SCHEMA", - "SOURCE_IDENTITY_SCHEMA", - "ReportPublicationIdentity", - "ReportSourceIdentity", - "ReportSourceIdentityError", - "inspect_report_publication", - "inspect_report_source", - "require_eligible_report_source", - "require_report_only_publication", -] diff --git a/pyamplicol/tools/performance_report/standalone_build.py b/pyamplicol/tools/performance_report/standalone_build.py deleted file mode 100644 index 55f52d6f6a..0000000000 --- a/pyamplicol/tools/performance_report/standalone_build.py +++ /dev/null @@ -1,123 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Compile and verify an exported pyAmpliCol report using only its TeX folder.""" - -from __future__ import annotations - -import argparse -import re -import subprocess -from collections.abc import Sequence -from pathlib import Path -from shutil import which - - -class StandaloneBuildError(RuntimeError): - """The standalone publication could not be compiled or verified.""" - - -_UNRESOLVED_PATTERNS = ( - re.compile(r"LaTeX Warning: Citation .* undefined"), - re.compile(r"LaTeX Warning: Reference .* undefined"), - re.compile(r"LaTeX Warning: There were undefined references"), - re.compile(r"Package rerunfilecheck Warning:"), -) - - -def validate_latex_log( - log: str, - *, - allow_overfull_boxes: bool = False, -) -> None: - """Reject unresolved diagnostics and, by default, layout overflow. - - Interactive report refreshes may explicitly tolerate overfull boxes while - a campaign is still being filled. The stricter default remains useful for - release and final-layout audits. - """ - - if not allow_overfull_boxes and ( - "Overfull \\hbox" in log or "Overfull \\vbox" in log - ): - raise StandaloneBuildError("LaTeX output contains an overfull box") - for pattern in _UNRESOLVED_PATTERNS: - if pattern.search(log): - raise StandaloneBuildError( - f"LaTeX output is unresolved: {pattern.pattern}" - ) - - -def compile_report( - report_dir: Path, - *, - engine: str = "pdflatex", - passes: int = 3, -) -> Path: - """Compile ``pyAmpliCol.tex`` and reject unresolved or overflowing output.""" - - root = report_dir.expanduser().resolve(strict=True) - source = root / "pyAmpliCol.tex" - if not source.is_file(): - raise StandaloneBuildError(f"missing report source: {source}") - if passes < 2: - raise StandaloneBuildError("at least two LaTeX passes are required") - executable = which(engine) - if executable is None: - raise StandaloneBuildError(f"LaTeX engine is not available: {engine}") - - command = ( - executable, - "-interaction=nonstopmode", - "-halt-on-error", - "-file-line-error", - source.name, - ) - for _ in range(passes): - completed = subprocess.run( - command, - cwd=root, - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - detail = (completed.stdout + completed.stderr)[-4000:] - raise StandaloneBuildError( - f"LaTeX compilation failed with exit {completed.returncode}:\n" - f"{detail}" - ) - - log_path = root / "pyAmpliCol.log" - try: - log = log_path.read_text(encoding="utf-8", errors="replace") - except OSError as error: - raise StandaloneBuildError(f"cannot read LaTeX log: {error}") from error - validate_latex_log(log) - - output = root / "pyAmpliCol.pdf" - if not output.is_file() or output.stat().st_size == 0: - raise StandaloneBuildError(f"LaTeX did not produce {output}") - return output - - -def _parser() -> argparse.ArgumentParser: - parser = argparse.ArgumentParser( - description="Compile and verify this standalone pyAmpliCol report", - ) - parser.add_argument("--engine", default="pdflatex") - parser.add_argument("--passes", type=int, default=3) - return parser - - -def main(argv: Sequence[str] | None = None) -> int: - arguments = _parser().parse_args(argv) - output = compile_report( - Path(__file__).resolve().parent, - engine=arguments.engine, - passes=arguments.passes, - ) - print(output) - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/pyamplicol/tools/performance_report/study_contract.py b/pyamplicol/tools/performance_report/study_contract.py deleted file mode 100644 index 4dd3e16851..0000000000 --- a/pyamplicol/tools/performance_report/study_contract.py +++ /dev/null @@ -1,780 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Authenticated contracts for narrowly scoped performance studies.""" - -from __future__ import annotations - -import hashlib -import json -import os -import subprocess -from collections.abc import Mapping -from pathlib import Path -from typing import TYPE_CHECKING - -from .cache import validate_measurement -from .campaign_policy import ( - GENERATION_PHASE_EVIDENCE_ABI, - MACBOOK_M3_MEMORY_LIMIT_BYTES, - MACBOOK_M3_PROFILE, - MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS, - MACBOOK_M3_Z_TABLE_F_POLICY, - PolicyMeasurementState, - policy_status_label, - validate_policy_measurement, -) -from .catalog import REPORT_CATALOG -from .models import Accuracy, ResultStatus, Workload -from .publication import publication_measurement_matches_current -from .resources import PROCESS_TREE_MEMORY_METRIC_ABI -from .source_identity import require_eligible_report_source -from .worker_harness import ( - LEGACY_ADAPTER, - POLICY_ENTRYPOINT, - WorkerHarnessError, - require_worker_harness_identity, - worker_harness_identity, -) - -if TYPE_CHECKING: - from .artifacts import ArtifactStore - from .service import ReportService - -Z_TABLE_F_STUDY_CONTRACT_SCHEMA = "pyamplicol-z-table-f-study-contract-v1" -Z_TABLE_F_STUDY_ID = "macbook-m3-z-table-f" -Z_TABLE_F_CONTRACT_MINIMUM_N = 8 -Z_TABLE_F_CELL_COUNT = 32 -Z_TABLE_F_PRIOR_EVIDENCE_ABI = ( - "pyamplicol-z-table-f-prior-evidence-snapshot-v1" -) -Z_TABLE_F_PRIOR_CELL_COUNT = 112 -Z_TABLE_F_PRIOR_STATIC_NA_CELL_COUNT = 4 -Z_TABLE_F_SELECTION_ABI = "pyamplicol-explicit-single-cell-selection-v1" -Z_TABLE_F_ATTEMPT_BINDING_ABI = ( - "pyamplicol-z-table-f-attempt-binding-v1" -) -Z_TABLE_F_MEMORY_GUARD = ( - "max(aggregate-process-tree-rss,darwin-physical-footprint)" -) -_SHA40 = frozenset("0123456789abcdef") -_CONTRACT_FIELDS = frozenset( - { - "schema", - "study_id", - "campaign_policy", - "policy_profile", - "measured_source", - "policy_wrapper", - "allowed_cell_ids", - "selection_abi", - "memory_guard", - "generation_guard", - "retained_prior_evidence", - "sha256", - } -) - - -class StudyContractError(ValueError): - """A study contract is missing, stale, or internally inconsistent.""" - - -def _canonical_sha256(value: object) -> str: - return hashlib.sha256( - json.dumps( - value, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ).encode("ascii") - ).hexdigest() - - -def _git_value(root: Path, expression: str) -> str: - completed = subprocess.run( - ("git", "-C", os.fspath(root), "rev-parse", expression), - check=False, - capture_output=True, - text=True, - ) - value = completed.stdout.strip() - if ( - completed.returncode != 0 - or len(value) != 40 - or any(character not in _SHA40 for character in value) - ): - detail = completed.stderr.strip() or f"exit {completed.returncode}" - raise StudyContractError( - f"cannot authenticate Git identity {expression!r}: {detail}" - ) - return value - - -def _clean_git_identity(root: Path) -> dict[str, str]: - resolved = root.expanduser().resolve(strict=True) - completed = subprocess.run( - ( - "git", - "-C", - os.fspath(resolved), - "status", - "--porcelain=v1", - "--untracked-files=all", - ), - check=False, - capture_output=True, - text=True, - ) - if completed.returncode != 0: - raise StudyContractError( - "cannot inspect policy-wrapper worktree cleanliness" - ) - if completed.stdout: - raise StudyContractError( - "policy-wrapper worktree must be clean before contract creation" - ) - return { - "revision": _git_value(resolved, "HEAD^{commit}"), - "tree": _git_value(resolved, "HEAD^{tree}"), - "policy_entrypoint": POLICY_ENTRYPOINT, - "policy_entrypoint_sha256": _tracked_file_sha256( - resolved, - POLICY_ENTRYPOINT, - ), - "legacy_adapter": LEGACY_ADAPTER, - "legacy_adapter_sha256": _tracked_file_sha256( - resolved, - LEGACY_ADAPTER, - ), - } - - -def _tracked_file_sha256(root: Path, relative_path: str) -> str: - """Hash one regular, tracked wrapper file without retaining its root.""" - - candidate = root / relative_path - try: - resolved = candidate.resolve(strict=True) - resolved.relative_to(root) - except (OSError, ValueError) as error: - raise StudyContractError( - f"policy-wrapper file is unavailable: {relative_path}" - ) from error - tracked = subprocess.run( - ( - "git", - "-C", - os.fspath(root), - "ls-files", - "--error-unmatch", - "--", - relative_path, - ), - check=False, - capture_output=True, - text=True, - ) - if ( - tracked.returncode != 0 - or candidate.is_symlink() - or not resolved.is_file() - ): - raise StudyContractError( - f"policy-wrapper file is not a tracked regular file: {relative_path}" - ) - digest = hashlib.sha256() - with resolved.open("rb") as stream: - for block in iter(lambda: stream.read(1024 * 1024), b""): - digest.update(block) - return digest.hexdigest() - - -def z_table_f_cell_ids() -> tuple[str, ...]: - """Return the exact newly supervised Z-table declaration scope.""" - - cell_ids = tuple( - sorted( - cell.cell_id - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id - in { - "z_builtin_sm", - "reference_amplicol_lc", - } - and cell.process_key == "dd_z_jets" - and Z_TABLE_F_CONTRACT_MINIMUM_N <= cell.n_final <= 9 - and cell.measurement.accuracy is Accuracy.LC - and cell.workload - in { - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - } - ) - ) - if len(cell_ids) != Z_TABLE_F_CELL_COUNT: - raise StudyContractError( - "contracted Z-table n8-n9 catalog census is not exactly 32 cells" - ) - return cell_ids - - -def z_table_f_prior_cell_ids() -> tuple[str, ...]: - """Return the exact retained n1--n7 declaration scope for the Z table.""" - - cell_ids = tuple( - sorted( - cell.cell_id - for cell in REPORT_CATALOG.measurement_cells() - if cell.dataset_id - in { - "z_builtin_sm", - "reference_amplicol_lc", - } - and cell.process_key == "dd_z_jets" - and 1 <= cell.n_final < Z_TABLE_F_CONTRACT_MINIMUM_N - and cell.measurement.accuracy is Accuracy.LC - and cell.workload - in { - Workload.SELECTED_FLOW, - Workload.ALL_FLOW, - } - ) - ) - static_na_count = sum( - REPORT_CATALOG.static_na_reason(REPORT_CATALOG.cell(cell_id)) - is not None - for cell_id in cell_ids - ) - if ( - len(cell_ids) != Z_TABLE_F_PRIOR_CELL_COUNT - or static_na_count != Z_TABLE_F_PRIOR_STATIC_NA_CELL_COUNT - ): - raise StudyContractError( - "retained Z-table n1-n7 catalog census differs from the " - "authenticated contract" - ) - return cell_ids - - -def _prior_evidence_snapshot( - store: ArtifactStore | None, -) -> dict[str, object]: - """Digest retained Z-table currents without embedding path-dependent data.""" - - entries: list[dict[str, object]] = [] - current_count = 0 - cell_ids = z_table_f_prior_cell_ids() - static_na_cell_ids = tuple( - cell_id - for cell_id in cell_ids - if REPORT_CATALOG.static_na_reason(REPORT_CATALOG.cell(cell_id)) - is not None - ) - for cell_id in cell_ids: - cell = REPORT_CATALOG.cell(cell_id) - current = ( - None - if store is None - else store.load_current(cell.cell_id, missing_ok=True) - ) - if current is None: - entries.append( - { - "cell_id": cell.cell_id, - "attempt_id": None, - "manifest_sha256": None, - "result_sha256": None, - "provenance_sha256": None, - } - ) - continue - provenance = current.result.get("provenance") - if ( - isinstance(provenance, Mapping) - and "study_contract" in provenance - ): - raise StudyContractError( - f"pre-study cell {cell.cell_id!r} already has an F binding" - ) - current_count += 1 - entries.append( - { - "cell_id": cell.cell_id, - "attempt_id": current.attempt_id, - "manifest_sha256": current.manifest_sha256, - "result_sha256": _canonical_sha256(current.result), - "provenance_sha256": _canonical_sha256(provenance), - } - ) - return { - "abi": Z_TABLE_F_PRIOR_EVIDENCE_ABI, - "maximum_n_final": Z_TABLE_F_CONTRACT_MINIMUM_N - 1, - "cell_ids": list(cell_ids), - "static_na_cell_ids": list(static_na_cell_ids), - "declared_cell_count": len(entries), - "static_na_cell_count": len(static_na_cell_ids), - "current_cell_count": current_count, - "snapshot_sha256": _canonical_sha256(entries), - } - - -def create_z_table_f_study_contract( - measured_root: Path, - policy_wrapper_root: Path, - *, - prior_store: ArtifactStore | None = None, -) -> dict[str, object]: - """Create a digest-bound contract from two clean, separate Git identities.""" - - source = require_eligible_report_source( - measured_root.expanduser().resolve(strict=True) - ) - wrapper = _clean_git_identity(policy_wrapper_root) - body: dict[str, object] = { - "schema": Z_TABLE_F_STUDY_CONTRACT_SCHEMA, - "study_id": Z_TABLE_F_STUDY_ID, - "campaign_policy": MACBOOK_M3_Z_TABLE_F_POLICY.as_manifest(), - "policy_profile": MACBOOK_M3_PROFILE, - "measured_source": { - "revision": source.revision, - "tree": source.tree, - }, - "policy_wrapper": wrapper, - "allowed_cell_ids": list(z_table_f_cell_ids()), - "selection_abi": Z_TABLE_F_SELECTION_ABI, - "memory_guard": { - "metric_abi": PROCESS_TREE_MEMORY_METRIC_ABI, - "metric": Z_TABLE_F_MEMORY_GUARD, - "limit_bytes": MACBOOK_M3_MEMORY_LIMIT_BYTES, - }, - "generation_guard": { - "evidence_abi": GENERATION_PHASE_EVIDENCE_ABI, - "limit_seconds": ( - MACBOOK_M3_Z_TABLE_F_GENERATION_LIMIT_SECONDS - ), - "scope": "every legacy, selected-flow, and all-flow generation", - }, - "retained_prior_evidence": { - "n_final": list(range(1, Z_TABLE_F_CONTRACT_MINIMUM_N)), - "snapshot": _prior_evidence_snapshot(prior_store), - "treatment": ( - "outside this contract; retain each original attempt, " - "provenance record, and resource ABI unchanged" - ), - "memory_guard_interpretation": ( - "legacy RSS-only evidence remains legacy and is not " - "relabeled as Darwin physical-footprint or exact-decimal-" - "30GB evidence" - ), - }, - } - return {**body, "sha256": _canonical_sha256(body)} - - -def z_table_f_worker_harness_identity( - contract: Mapping[str, object], -) -> dict[str, object]: - """Derive the exact relocation-safe worker identity from one contract.""" - - wrapper = contract.get("policy_wrapper") - source = contract.get("measured_source") - if not isinstance(wrapper, Mapping) or not isinstance(source, Mapping): - raise StudyContractError( - "study contract worker identities are missing" - ) - try: - return worker_harness_identity( - study_contract_sha256=str(contract["sha256"]), - policy_wrapper_revision=str(wrapper["revision"]), - policy_wrapper_tree=str(wrapper["tree"]), - policy_entrypoint_sha256=str( - wrapper["policy_entrypoint_sha256"] - ), - legacy_adapter_sha256=str( - wrapper["legacy_adapter_sha256"] - ), - measured_source_revision=str(source["revision"]), - measured_source_tree=str(source["tree"]), - ) - except (KeyError, WorkerHarnessError) as error: - raise StudyContractError( - "study contract worker identities are invalid" - ) from error - - -def write_z_table_f_study_contract( - path: Path, - measured_root: Path, - policy_wrapper_root: Path, - *, - prior_store: ArtifactStore | None = None, -) -> dict[str, object]: - """Write a new contract without overwriting prior study evidence.""" - - destination = path.expanduser().resolve(strict=False) - if destination.exists() or destination.is_symlink(): - raise StudyContractError( - f"study contract already exists: {destination}" - ) - payload = create_z_table_f_study_contract( - measured_root, - policy_wrapper_root, - prior_store=prior_store, - ) - destination.parent.mkdir(parents=True, exist_ok=True) - temporary = destination.with_name(f".{destination.name}.new") - temporary.write_text( - json.dumps(payload, indent=2, sort_keys=True, allow_nan=False) + "\n", - encoding="ascii", - ) - os.replace(temporary, destination) - return payload - - -def load_z_table_f_study_contract( - path: Path, - measured_root: Path, - policy_wrapper_root: Path, - *, - prior_store: ArtifactStore | None = None, -) -> dict[str, object]: - """Load a contract and reauthenticate both source and wrapper identities.""" - - try: - raw = json.loads( - path.expanduser().resolve(strict=True).read_text( - encoding="ascii" - ) - ) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise StudyContractError( - f"cannot read Z-table study contract: {error}" - ) from error - if not isinstance(raw, dict): - raise StudyContractError("Z-table study contract fields are invalid") - return authenticate_z_table_f_study_contract( - raw, - measured_root, - policy_wrapper_root, - prior_store=prior_store, - ) - - -def authenticate_z_table_f_study_contract( - contract: Mapping[str, object], - measured_root: Path, - policy_wrapper_root: Path, - *, - prior_store: ArtifactStore | None = None, -) -> dict[str, object]: - """Reauthenticate a loaded contract against both roots and prior currents.""" - - if ( - not isinstance(contract, Mapping) - or set(contract) != _CONTRACT_FIELDS - ): - raise StudyContractError("Z-table study contract fields are invalid") - body = { - key: value - for key, value in contract.items() - if key != "sha256" - } - if contract.get("sha256") != _canonical_sha256(body): - raise StudyContractError("Z-table study contract digest differs") - expected = create_z_table_f_study_contract( - measured_root, - policy_wrapper_root, - prior_store=prior_store, - ) - if dict(contract) != expected: - if contract.get("retained_prior_evidence") != expected.get( - "retained_prior_evidence" - ): - raise StudyContractError( - "Z-table study contract retained prior evidence differs" - ) - raise StudyContractError( - "Z-table study contract differs from active source or policy" - ) - return expected - - -def require_z_table_f_explicit_cell( - contract: Mapping[str, object], - cell_id: str, -) -> None: - """Reject broad selectors and any cell outside the dedicated Z table.""" - - allowed = contract.get("allowed_cell_ids") - if ( - not isinstance(cell_id, str) - or not cell_id - or not isinstance(allowed, list) - or cell_id not in allowed - ): - raise StudyContractError( - f"cell {cell_id!r} is outside the authenticated Z-table scope" - ) - - -def z_table_f_attempt_binding( - study_contract_sha256: str, -) -> dict[str, str]: - """Return the exact provenance record for one contracted attempt.""" - - if ( - len(study_contract_sha256) != 64 - or any(character not in _SHA40 for character in study_contract_sha256) - ): - raise StudyContractError("study contract SHA-256 is invalid") - return { - "abi": Z_TABLE_F_ATTEMPT_BINDING_ABI, - "study_id": Z_TABLE_F_STUDY_ID, - "study_contract_sha256": study_contract_sha256, - } - - -def bind_z_table_f_attempt( - measurement: dict[str, object], - study_contract_sha256: str, -) -> None: - """Bind a scheduler-produced attempt result to its study contract.""" - - expected = z_table_f_attempt_binding(study_contract_sha256) - provenance = measurement.get("provenance") - if provenance is not None and not isinstance(provenance, Mapping): - raise StudyContractError("measurement provenance is invalid") - active = ( - provenance.get("study_contract") - if isinstance(provenance, Mapping) - else None - ) - if active is not None and active != expected: - raise StudyContractError( - "measurement is already bound to a different study contract" - ) - measurement["provenance"] = { - **({} if provenance is None else dict(provenance)), - "study_contract": expected, - } - - -def require_z_table_f_attempt_binding( - measurement: Mapping[str, object], - study_contract_sha256: str, -) -> None: - """Reject a current or publication transplanted from another study.""" - - provenance = measurement.get("provenance") - active = ( - provenance.get("study_contract") - if isinstance(provenance, Mapping) - else None - ) - if active != z_table_f_attempt_binding(study_contract_sha256): - raise StudyContractError( - "measurement is not bound to the active study contract" - ) - - -def audit_z_table_f_policy_projection( - contract: Mapping[str, object], - service: ReportService, - *, - maximum_n: int, -) -> dict[str, object]: - """Audit current-to-publication policy identity for a completed Z tier.""" - - if set(contract) != _CONTRACT_FIELDS: - raise StudyContractError("study contract fields are invalid") - contract_body = { - key: value - for key, value in contract.items() - if key != "sha256" - } - if contract.get("sha256") != _canonical_sha256(contract_body): - raise StudyContractError("study contract digest differs") - if maximum_n < Z_TABLE_F_CONTRACT_MINIMUM_N or maximum_n > 9: - raise StudyContractError( - "maximum_n must be between 8 and 9 for contracted evidence" - ) - source = contract.get("measured_source") - if not isinstance(source, Mapping): - raise StudyContractError("study contract source identity is missing") - revision = source.get("revision") - tree = source.get("tree") - if not isinstance(revision, str) or not isinstance(tree, str): - raise StudyContractError("study contract source identity is invalid") - contract_sha256 = contract.get("sha256") - if not isinstance(contract_sha256, str): - raise StudyContractError("study contract digest is invalid") - z_table_f_attempt_binding(contract_sha256) - expected_worker_harness = z_table_f_worker_harness_identity(contract) - retained = contract.get("retained_prior_evidence") - if not isinstance(retained, Mapping) or retained.get( - "snapshot" - ) != _prior_evidence_snapshot(service.store): - raise StudyContractError( - "pre-study n1-n7 current/provenance snapshot differs" - ) - - allowed = contract.get("allowed_cell_ids") - if allowed != list(z_table_f_cell_ids()): - raise StudyContractError("study contract cell scope is invalid") - assert isinstance(allowed, list) - allowed_ids = frozenset(str(value) for value in allowed) - cells = tuple( - cell - for cell in REPORT_CATALOG.measurement_cells() - if cell.cell_id in allowed_ids and cell.n_final <= maximum_n - ) - if not cells: - raise StudyContractError("study contract selects no audit cells") - - published_by_cell: dict[str, Mapping[str, object]] = {} - for payload in service.load_caches().values(): - entries = payload.get("entries") - if not isinstance(entries, list): - continue - for entry in entries: - if not isinstance(entry, Mapping): - continue - cell_id = entry.get("cell_id") - measurement = entry.get("measurement") - if isinstance(cell_id, str) and isinstance( - measurement, - Mapping, - ): - published_by_cell[cell_id] = measurement - - errors: list[str] = [] - states: dict[str, int] = {} - static_na = 0 - for cell in cells: - published = published_by_cell.get(cell.cell_id) - if published is None: - errors.append(f"{cell.cell_id}: publication entry is missing") - continue - static_reason = REPORT_CATALOG.static_na_reason(cell) - if static_reason is not None: - static_na += 1 - if published.get("status") != ResultStatus.NOT_AVAILABLE.value: - errors.append( - f"{cell.cell_id}: static N/A publication was overwritten" - ) - continue - - current = service.store.load_current( - cell.cell_id, - missing_ok=True, - ) - if current is None: - errors.append(f"{cell.cell_id}: authenticated current is missing") - continue - try: - validate_measurement(current.result, expected_cell=cell) - validate_measurement(published, expected_cell=cell) - require_z_table_f_attempt_binding( - current.result, - contract_sha256, - ) - require_z_table_f_attempt_binding( - published, - contract_sha256, - ) - require_worker_harness_identity( - current.result, - expected=expected_worker_harness, - ) - require_worker_harness_identity( - published, - expected=expected_worker_harness, - ) - current_state = validate_policy_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - MACBOOK_M3_PROFILE, - cell, - current.result, - expected_source_revision=revision, - expected_source_tree=tree, - ) - published_state = validate_policy_measurement( - MACBOOK_M3_Z_TABLE_F_POLICY, - MACBOOK_M3_PROFILE, - cell, - published, - expected_source_revision=revision, - expected_source_tree=tree, - ) - if current_state is not published_state: - raise StudyContractError( - "current and publication policy states differ" - ) - if not publication_measurement_matches_current( - published, - current.result, - service.paths, - ): - raise StudyContractError( - "publication is not the portable current projection" - ) - expected_label = { - PolicyMeasurementState.GENERATION_LIMIT: ">1h", - PolicyMeasurementState.MEMORY_LIMIT: ">30GB", - }.get(current_state) - if ( - expected_label is not None - and policy_status_label(published) != expected_label - ): - raise StudyContractError( - f"terminal label is not {expected_label}" - ) - except (OSError, TypeError, ValueError) as error: - errors.append(f"{cell.cell_id}: {error}") - continue - states[current_state.value] = states.get(current_state.value, 0) + 1 - - if errors: - preview = "; ".join(errors[:20]) - raise StudyContractError( - f"Z-table policy projection audit failed: {preview}" - ) - return { - "schema": "pyamplicol-z-table-f-policy-audit-v1", - "status": "ok", - "study_contract_sha256": contract_sha256, - "campaign_policy": MACBOOK_M3_Z_TABLE_F_POLICY.as_manifest(), - "policy_profile": MACBOOK_M3_PROFILE, - "measured_source": dict(source), - "maximum_n": maximum_n, - "declared_cell_count": len(cells), - "static_na_cell_count": static_na, - "policy_state_counts": dict(sorted(states.items())), - } - - -__all__ = [ - "Z_TABLE_F_ATTEMPT_BINDING_ABI", - "Z_TABLE_F_CELL_COUNT", - "Z_TABLE_F_CONTRACT_MINIMUM_N", - "Z_TABLE_F_MEMORY_GUARD", - "Z_TABLE_F_PRIOR_CELL_COUNT", - "Z_TABLE_F_PRIOR_EVIDENCE_ABI", - "Z_TABLE_F_PRIOR_STATIC_NA_CELL_COUNT", - "Z_TABLE_F_SELECTION_ABI", - "Z_TABLE_F_STUDY_CONTRACT_SCHEMA", - "Z_TABLE_F_STUDY_ID", - "StudyContractError", - "audit_z_table_f_policy_projection", - "authenticate_z_table_f_study_contract", - "bind_z_table_f_attempt", - "create_z_table_f_study_contract", - "load_z_table_f_study_contract", - "require_z_table_f_attempt_binding", - "require_z_table_f_explicit_cell", - "write_z_table_f_study_contract", - "z_table_f_attempt_binding", - "z_table_f_cell_ids", - "z_table_f_prior_cell_ids", - "z_table_f_worker_harness_identity", -] diff --git a/pyamplicol/tools/performance_report/timing.py b/pyamplicol/tools/performance_report/timing.py deleted file mode 100644 index 2386d807b2..0000000000 --- a/pyamplicol/tools/performance_report/timing.py +++ /dev/null @@ -1,346 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Authenticated native execution-timing metadata shared by report views.""" - -from __future__ import annotations - -import math -from collections.abc import Mapping - -from .arena_profile import ( - ARENA_PHASE_TIMING_SCOPE, - ARENA_PROFILE_BOUNDARY, - ARENA_PROFILE_PROTOCOL, - ARENA_PROFILE_SAMPLE_PASS, - PAIRED_TIMING_SAMPLE_CONTRACT, - ArenaProfileEvidenceError, - digest_arena_profile_value, - validate_arena_profile_evidence, -) - -MEASURED_EXECUTION_TIMING_ABI = "pyamplicol-report-execution-timing-v1" -ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI = ( - "pyamplicol-report-arena-execution-timing-v2" -) -EXECUTION_TIMING_KEY = "execution_timing" -EVALUATOR_TOTAL_TIMING_ABI = "pyamplicol-report-evaluator-total-timing-v1" -EVALUATOR_TOTAL_TIMING_KEY = "evaluator_total_timing" -EVALUATOR_TOTAL_TIMING_SOURCE = ( - "runtime._benchmark_f64_wall_time.accumulated" -) -EVALUATOR_TOTAL_TIMING_SOURCES = frozenset( - { - EVALUATOR_TOTAL_TIMING_SOURCE, - "runtime.evaluate.accumulated", - } -) -EVALUATOR_TOTAL_SAMPLE_CONTRACT = ( - "accumulated-repeated-warmed-evaluator-total-v1" -) -RECURRENCE_EXECUTION_TIMING_SOURCE = ( - "runtime_profile_core_recurrence_schedule_time" -) -UNAVAILABLE_STATUS = "unavailable" -ARENA_UNAVAILABLE_EXECUTION_TIMING_FIELDS = frozenset( - { - "abi", - "status", - "ratio_eligible", - "raw_seconds_per_point", - "sample_count", - "native_profile_points_per_sample", - "repetitions_per_sample", - "batch_size", - "sample_contract", - "profile_protocol", - "profile_sample_pass", - "profile_boundary", - "borrowed_flat_input", - "preallocated_output", - "phase_timing_scope", - "evaluator_timing_available", - "paired_with_headline", - "identical_batch", - "identical_repetitions", - "execution_mode", - "warmed_boundary_wall_seconds_per_point", - "arena_profile_evidence_sha256", - } -) -EVALUATOR_TOTAL_TIMING_FIELDS = frozenset( - { - "abi", - "status", - "ratio_eligible", - "raw_seconds_per_point", - "source", - "execution_mode", - "sample_contract", - "sample_count", - "repetitions_per_sample", - "batch_size", - "points_per_sample", - "measured_point_count", - "accumulated_seconds", - } -) -RECURRENCE_CORE_TIMING_FIELDS = frozenset( - { - "abi", - "status", - "ratio_eligible", - "raw_seconds_per_point", - "source", - "compiled_direct_arena_active", - "sample_count", - "native_profile_points_per_sample", - "sample_contract", - } -) - - -def recurrence_core_timing_record( - measurement: Mapping[str, object], -) -> Mapping[str, object] | None: - """Return an authenticated narrow recurrence-core timing record.""" - - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return None - record = provenance.get(EXECUTION_TIMING_KEY) - if not isinstance(record, Mapping): - return None - raw = record.get("raw_seconds_per_point") - sample_count = record.get("sample_count") - native_points = record.get("native_profile_points_per_sample") - if ( - measurement.get("status") not in {"ok", "unverified"} - or set(record) != RECURRENCE_CORE_TIMING_FIELDS - or record.get("abi") != MEASURED_EXECUTION_TIMING_ABI - or record.get("status") != "measured" - or record.get("ratio_eligible") is not True - or record.get("source") != RECURRENCE_EXECUTION_TIMING_SOURCE - or record.get("compiled_direct_arena_active") is not False - or record.get("sample_contract") != PAIRED_TIMING_SAMPLE_CONTRACT - or isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - or float(raw) <= 0.0 - or measurement.get("execution_seconds_per_point") != raw - or isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < 1 - or measurement.get("sample_count") != sample_count - or isinstance(native_points, bool) - or not isinstance(native_points, int) - or native_points < 1 - ): - return None - return record - - -def evaluator_total_timing_record( - measurement: Mapping[str, object], -) -> Mapping[str, object] | None: - """Return an authenticated accumulated warmed evaluator-total record.""" - - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return None - record = provenance.get(EVALUATOR_TOTAL_TIMING_KEY) - if not isinstance(record, Mapping): - return None - raw = record.get("raw_seconds_per_point") - accumulated = record.get("accumulated_seconds") - sample_count = record.get("sample_count") - repetitions = record.get("repetitions_per_sample") - batch_size = record.get("batch_size") - points_per_sample = record.get("points_per_sample") - measured_points = record.get("measured_point_count") - if ( - measurement.get("status") not in {"ok", "unverified"} - or set(record) != EVALUATOR_TOTAL_TIMING_FIELDS - or record.get("abi") != EVALUATOR_TOTAL_TIMING_ABI - or record.get("status") != "measured" - or record.get("ratio_eligible") is not False - or record.get("source") not in EVALUATOR_TOTAL_TIMING_SOURCES - or record.get("execution_mode") not in { - "compiled", - "eager", - "recurrence", - "on-the-fly", - } - or record.get("sample_contract") != EVALUATOR_TOTAL_SAMPLE_CONTRACT - or isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < 1 - or measurement.get("sample_count") != sample_count - or isinstance(repetitions, bool) - or not isinstance(repetitions, int) - or repetitions < 1 - or isinstance(batch_size, bool) - or not isinstance(batch_size, int) - or batch_size < 1 - or isinstance(points_per_sample, bool) - or not isinstance(points_per_sample, int) - or points_per_sample != repetitions * batch_size - or isinstance(measured_points, bool) - or not isinstance(measured_points, int) - or measured_points != sample_count * points_per_sample - or isinstance(accumulated, bool) - or not isinstance(accumulated, (int, float)) - or not math.isfinite(float(accumulated)) - or float(accumulated) <= 0.0 - or isinstance(raw, bool) - or not isinstance(raw, (int, float)) - or not math.isfinite(float(raw)) - or float(raw) <= 0.0 - or not math.isclose( - float(raw), - float(accumulated) / measured_points, - rel_tol=1.0e-15, - abs_tol=0.0, - ) - ): - return None - return record - - -def evaluator_total_seconds_per_point( - measurement: Mapping[str, object], -) -> float | None: - """Return only a dedicated authenticated accumulated evaluator total.""" - - record = evaluator_total_timing_record(measurement) - if record is None: - return None - return float(record["raw_seconds_per_point"]) - - -def recurrence_core_seconds_per_point( - measurement: Mapping[str, object], -) -> float | None: - """Return the independent narrow recurrence-core attribution.""" - - record = recurrence_core_timing_record(measurement) - if record is None: - return None - return float(record["raw_seconds_per_point"]) - - -def unavailable_execution_timing_record( - measurement: Mapping[str, object], - field: str, -) -> Mapping[str, object] | None: - """Return an authenticated Arena record for an unexposed timing field.""" - - if field != "execution_seconds_per_point": - return None - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return None - record = provenance.get(EXECUTION_TIMING_KEY) - if not isinstance(record, Mapping): - return None - raw = record.get("raw_seconds_per_point") - sample_count = record.get("sample_count") - native_points = record.get("native_profile_points_per_sample") - repetitions = record.get("repetitions_per_sample") - batch_size = record.get("batch_size") - warmed_wall = record.get("warmed_boundary_wall_seconds_per_point") - execution_mode = record.get("execution_mode") - evidence = provenance.get("arena_profile_evidence") - evidence_digest = record.get("arena_profile_evidence_sha256") - evidence_valid = False - if ( - isinstance(execution_mode, str) - and isinstance(sample_count, int) - and not isinstance(sample_count, bool) - and isinstance(native_points, int) - and not isinstance(native_points, bool) - and isinstance(evidence_digest, str) - ): - try: - validate_arena_profile_evidence( - evidence, - execution_mode=execution_mode, - sample_count=sample_count, - native_profile_points_per_sample=native_points, - ) - except ArenaProfileEvidenceError: - pass - else: - evidence_valid = ( - digest_arena_profile_value(evidence) == evidence_digest - and isinstance(evidence, Mapping) - and evidence.get("repetitions_per_profile") == repetitions - and evidence.get("batch_size") == batch_size - and evidence.get("warmed_boundary_wall_seconds_per_point") - == warmed_wall - ) - if ( - set(record) != ARENA_UNAVAILABLE_EXECUTION_TIMING_FIELDS - or record.get("abi") != ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI - or record.get("status") != UNAVAILABLE_STATUS - or record.get("ratio_eligible") is not False - or raw is not None - or isinstance(sample_count, bool) - or not isinstance(sample_count, int) - or sample_count < 1 - or isinstance(native_points, bool) - or not isinstance(native_points, int) - or native_points < 1 - or isinstance(repetitions, bool) - or not isinstance(repetitions, int) - or repetitions < 1 - or isinstance(batch_size, bool) - or not isinstance(batch_size, int) - or batch_size < 1 - or repetitions * batch_size != native_points - or record.get("sample_contract") != PAIRED_TIMING_SAMPLE_CONTRACT - or record.get("profile_protocol") != ARENA_PROFILE_PROTOCOL - or record.get("profile_sample_pass") != ARENA_PROFILE_SAMPLE_PASS - or record.get("profile_boundary") != ARENA_PROFILE_BOUNDARY - or record.get("borrowed_flat_input") is not True - or record.get("preallocated_output") is not True - or record.get("phase_timing_scope") != ARENA_PHASE_TIMING_SCOPE - or record.get("evaluator_timing_available") is not False - or record.get("paired_with_headline") is not True - or record.get("identical_batch") is not True - or record.get("identical_repetitions") is not True - or execution_mode not in {"compiled", "eager"} - or isinstance(warmed_wall, bool) - or not isinstance(warmed_wall, (int, float)) - or not math.isfinite(float(warmed_wall)) - or float(warmed_wall) <= 0.0 - or not evidence_valid - or measurement.get(field) is not None - ): - return None - return record - - -__all__ = [ - "ARENA_PHASE_TIMING_SCOPE", - "ARENA_PROFILE_BOUNDARY", - "ARENA_PROFILE_PROTOCOL", - "ARENA_PROFILE_SAMPLE_PASS", - "ARENA_UNAVAILABLE_EXECUTION_TIMING_ABI", - "ARENA_UNAVAILABLE_EXECUTION_TIMING_FIELDS", - "EVALUATOR_TOTAL_SAMPLE_CONTRACT", - "EVALUATOR_TOTAL_TIMING_ABI", - "EVALUATOR_TOTAL_TIMING_FIELDS", - "EVALUATOR_TOTAL_TIMING_KEY", - "EVALUATOR_TOTAL_TIMING_SOURCE", - "EVALUATOR_TOTAL_TIMING_SOURCES", - "EXECUTION_TIMING_KEY", - "MEASURED_EXECUTION_TIMING_ABI", - "PAIRED_TIMING_SAMPLE_CONTRACT", - "RECURRENCE_CORE_TIMING_FIELDS", - "RECURRENCE_EXECUTION_TIMING_SOURCE", - "UNAVAILABLE_STATUS", - "evaluator_total_seconds_per_point", - "evaluator_total_timing_record", - "recurrence_core_seconds_per_point", - "recurrence_core_timing_record", - "unavailable_execution_timing_record", -] diff --git a/pyamplicol/tools/performance_report/validation_summary.py b/pyamplicol/tools/performance_report/validation_summary.py deleted file mode 100644 index 551fdd9e0d..0000000000 --- a/pyamplicol/tools/performance_report/validation_summary.py +++ /dev/null @@ -1,550 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Publication-facing numerical-validation coverage for the report.""" - -from __future__ import annotations - -import math -from collections import Counter -from collections.abc import Iterable, Mapping -from dataclasses import dataclass - -from .agreements import ( - DIRECT_AGREEMENT_FIELD, - INDEPENDENT_AUTHORITY_FIELD, - LC_LEGACY_PYAMPLICOL_COMPONENT, - MADGRAPH_COMPARISON_FIELD, -) -from .campaign_policy import policy_status_label -from .catalog import REPORT_CATALOG, ReportCatalog -from .display_contract import report_display_accounting -from .models import CellSpec, ExecutionMode, ResultStatus - -Measurement = Mapping[str, object] -CachePayload = Mapping[str, object] - -SUMMARY_TABLE_NAME = "result_validation_summary.tex" -MAX_PUBLICATION_MULTIPLICITY = 9 - - -def _number(record: Mapping[str, object], field: str) -> float | None: - value = record.get(field) - if isinstance(value, bool) or not isinstance(value, (int, float)): - return None - result = float(value) - return result if math.isfinite(result) and result >= 0.0 else None - - -def _maximum(records: Iterable[Mapping[str, object]], field: str) -> float | None: - values = tuple( - value for record in records if (value := _number(record, field)) is not None - ) - return max(values) if values else None - - -def _validation_record( - measurement: Measurement, - name: str, -) -> Mapping[str, object] | None: - validation = measurement.get("validation") - if not isinstance(validation, Mapping): - return None - record = validation.get(name) - return record if isinstance(record, Mapping) else None - - -def _successful(measurement: Measurement) -> bool: - validation = measurement.get("validation") - return ( - measurement.get("status") == ResultStatus.OK.value - and isinstance(validation, Mapping) - and validation.get("status") == ResultStatus.OK.value - ) - - -def _source_revision(measurement: Measurement) -> str | None: - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - return None - for field in ( - "report_measured_source_revision", - "report_source_revision", - "source_revision", - ): - value = provenance.get(field) - if isinstance(value, str) and value and value != "unknown": - return value - return None - - -def _cell_measurements( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], -) -> dict[str, Measurement]: - payloads = caches.values() if isinstance(caches, Mapping) else caches - result: dict[str, Measurement] = {} - for payload in payloads: - entries = payload.get("entries") - if not isinstance(entries, list): - raise ValueError("report cache has no entries list") - for entry in entries: - if not isinstance(entry, Mapping): - raise ValueError("report cache contains a non-object entry") - cell_id = entry.get("cell_id") - measurement = entry.get("measurement") - if not isinstance(cell_id, str) or not isinstance(measurement, Mapping): - raise ValueError("report cache entry is missing its measurement") - if cell_id in result: - raise ValueError(f"duplicate report cell {cell_id!r}") - result[cell_id] = measurement - return result - - -@dataclass(frozen=True, slots=True) -class ValidationSummary: - """Numerical evidence across the complete declared publication range.""" - - declared_by_n: tuple[tuple[int, int], ...] - expected_by_n: tuple[tuple[int, int], ...] - static_na_by_n: tuple[tuple[int, int], ...] - passed_by_n: tuple[tuple[int, int], ...] - policy_terminal_by_n: tuple[tuple[int, int], ...] - status_counts: tuple[tuple[str, int], ...] - madgraph_reference_count: int - madgraph_comparison_count: int - madgraph_comparison_maximum_relative_difference: float | None - legacy_reference_count: int - legacy_comparison_pass_count: int - legacy_comparison_failure_count: int - legacy_comparison_maximum_relative_difference: float | None - cross_mode_count: int - cross_mode_maximum_relative_difference: float | None - resolved_count: int - resolved_maximum_relative_difference: float | None - high_precision_count: int - high_precision_maximum_relative_difference: float | None - source_revisions: tuple[str, ...] - successful_source_identity_count: int - - @property - def legacy_comparison_count(self) -> int: - return self.legacy_comparison_pass_count + self.legacy_comparison_failure_count - - @property - def declared_total(self) -> int: - return sum(count for _, count in self.declared_by_n) - - @property - def expected_total(self) -> int: - return sum(count for _, count in self.expected_by_n) - - @property - def static_na_total(self) -> int: - return sum(count for _, count in self.static_na_by_n) - - @property - def passed_total(self) -> int: - return sum(count for _, count in self.passed_by_n) - - @property - def complete(self) -> bool: - return self.passed_total == self.expected_total - - @property - def policy_terminal_total(self) -> int: - return sum(count for _, count in self.policy_terminal_by_n) - - @property - def policy_complete(self) -> bool: - return self.passed_total + self.policy_terminal_total == self.expected_total - - @property - def uniform_source_revision(self) -> str | None: - if ( - len(self.source_revisions) == 1 - and self.successful_source_identity_count == self.passed_total - ): - return self.source_revisions[0] - return None - - -def summarize_validation( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, -) -> ValidationSummary: - """Summarize validation evidence without treating missing cells as passing.""" - - measurements = _cell_measurements(caches) - cells = tuple( - cell - for cell in catalog.measurement_cells() - if cell.n_final <= MAX_PUBLICATION_MULTIPLICITY - ) - declared = Counter(cell.n_final for cell in cells) - static_na = Counter( - cell.n_final for cell in cells if catalog.static_na_reason(cell) is not None - ) - expected = declared - static_na - passed: Counter[int] = Counter() - policy_terminal: Counter[int] = Counter() - statuses: Counter[str] = Counter() - madgraph_reference_count = 0 - madgraph_comparisons: list[Mapping[str, object]] = [] - legacy_reference_count = 0 - legacy_comparisons: list[Mapping[str, object]] = [] - cross_mode: list[Mapping[str, object]] = [] - resolved: list[Mapping[str, object]] = [] - high_precision: list[Mapping[str, object]] = [] - revisions: list[str] = [] - - for cell in cells: - if catalog.static_na_reason(cell) is not None: - statuses["static-na"] += 1 - continue - measurement = measurements.get(cell.cell_id, {}) - status = str(measurement.get("status", ResultStatus.NOT_AVAILABLE.value)) - statuses[status] += 1 - if not _successful(measurement): - if policy_status_label(measurement) is not None: - policy_terminal[cell.n_final] += 1 - continue - passed[cell.n_final] += 1 - revision = _source_revision(measurement) - if revision is not None: - revisions.append(revision) - validation = measurement["validation"] - assert isinstance(validation, Mapping) - method = validation.get("method") - if method == "independent-madgraph-tree-level-oracle": - madgraph_reference_count += 1 - elif method == "independent-original-amplicol-oracle": - legacy_reference_count += 1 - if ( - comparison := _validation_record( - measurement, - MADGRAPH_COMPARISON_FIELD, - ) - ) is not None: - madgraph_comparisons.append(comparison) - if (pointwise := _validation_record(measurement, "pointwise")) is not None: - reference_mode = _pointwise_reference_mode( - cell, - validation, - catalog=catalog, - ) - if reference_mode is ExecutionMode.AMPLICOL: - legacy_comparisons.append(pointwise) - elif reference_mode is ExecutionMode.RECURRENCE: - cross_mode.append(pointwise) - legacy_comparisons.extend(_additional_legacy_comparisons(validation)) - if (record := _validation_record(measurement, "resolved_sum")) is not None: - resolved.append(record) - if (record := _validation_record(measurement, "high_precision")) is not None: - high_precision.append(record) - - multiplicities = tuple(sorted(declared)) - return ValidationSummary( - declared_by_n=tuple((n_final, declared[n_final]) for n_final in multiplicities), - expected_by_n=tuple((n_final, expected[n_final]) for n_final in multiplicities), - static_na_by_n=tuple( - (n_final, static_na[n_final]) for n_final in multiplicities - ), - passed_by_n=tuple((n_final, passed[n_final]) for n_final in multiplicities), - policy_terminal_by_n=tuple( - (n_final, policy_terminal[n_final]) for n_final in multiplicities - ), - status_counts=tuple(sorted(statuses.items())), - madgraph_reference_count=madgraph_reference_count, - madgraph_comparison_count=len(madgraph_comparisons), - madgraph_comparison_maximum_relative_difference=_maximum( - madgraph_comparisons, - "relative_difference", - ), - legacy_reference_count=legacy_reference_count, - legacy_comparison_pass_count=sum( - record.get("status") == ResultStatus.OK.value - for record in legacy_comparisons - ), - legacy_comparison_failure_count=sum( - record.get("status") != ResultStatus.OK.value - for record in legacy_comparisons - ), - legacy_comparison_maximum_relative_difference=_maximum( - legacy_comparisons, - "relative_difference", - ), - cross_mode_count=len(cross_mode), - cross_mode_maximum_relative_difference=_maximum( - cross_mode, - "relative_difference", - ), - resolved_count=len(resolved), - resolved_maximum_relative_difference=_maximum( - resolved, - "maximum_relative_difference", - ), - high_precision_count=len(high_precision), - high_precision_maximum_relative_difference=_maximum( - high_precision, - "relative_difference", - ), - source_revisions=tuple(sorted(set(revisions))), - successful_source_identity_count=len(revisions), - ) - - -def _pointwise_reference_mode( - cell: CellSpec, - validation: Mapping[str, object], - *, - catalog: ReportCatalog, -) -> ExecutionMode | None: - """Identify the actual endpoint of a stored pointwise comparison.""" - - authority = validation.get(INDEPENDENT_AUTHORITY_FIELD) - if isinstance(authority, Mapping): - selected = authority.get("selected_cell_id") - if isinstance(selected, str): - try: - return catalog.cell(selected).measurement.execution_mode - except KeyError: - return None - baseline = catalog.validation_baseline_cell(cell) - return None if baseline is None else baseline.measurement.execution_mode - - -def _additional_legacy_comparisons( - validation: Mapping[str, object], -) -> tuple[Mapping[str, object], ...]: - """Return retained legacy records not represented by ``pointwise``.""" - - records: list[Mapping[str, object]] = [] - direct = validation.get(DIRECT_AGREEMENT_FIELD) - if isinstance(direct, list): - records.extend( - record - for record in direct - if isinstance(record, Mapping) - and record.get("edge_kind") == LC_LEGACY_PYAMPLICOL_COMPONENT - ) - for field in ( - "legacy_amplicol_comparison", - "legacy_comparison", - "amplicol_comparison", - ): - raw = validation.get(field) - if not isinstance(raw, Mapping): - continue - nested = raw.get("pointwise") - if isinstance(nested, Mapping): - records.append(nested) - elif "status" in raw: - records.append(raw) - return tuple(records) - - -def _scientific(value: float | None) -> str: - if value is None: - return r"\textcolor{ReportMuted}{---}" - if value == 0.0: - return r"\texttt{0}" - coefficient, exponent = f"{value:.3e}".split("e") - return rf"\(\texttt{{{coefficient}}}\times10^{{{int(exponent)}}}\)" - - -def _coverage_status(passed: int, expected: int, policy_terminal: int = 0) -> str: - if passed == expected: - return r"\textcolor{ReportGreen}{verified}" - if passed + policy_terminal == expected: - return ( - r"\textcolor{ReportOrange}{policy-complete (" - f"{policy_terminal} censored" - r")}" - ) - open_count = expected - passed - policy_terminal - return ( - r"\textcolor{ReportOrange}{incomplete (" - f"{policy_terminal} censored, {open_count} open" - r")}" - ) - - -def render_validation_summary( - caches: Mapping[str, CachePayload] | Iterable[CachePayload], - *, - catalog: ReportCatalog = REPORT_CATALOG, - authenticated_source_lineage: tuple[str, str] | None = None, -) -> str: - """Render a compact summary immediately before the performance tables.""" - - summary = summarize_validation(caches, catalog=catalog) - display = report_display_accounting( - catalog=catalog, - max_n_final=MAX_PUBLICATION_MULTIPLICITY, - ) - declared_by_n = dict(summary.declared_by_n) - static_na_by_n = dict(summary.static_na_by_n) - passed_by_n = dict(summary.passed_by_n) - terminal_by_n = dict(summary.policy_terminal_by_n) - total_coverage = _coverage_status( - summary.passed_total, - summary.expected_total, - summary.policy_terminal_total, - ) - lines = [ - "% SPDX-License-Identifier: 0BSD", - "% Generated by tools/performance_report/validation_summary.py; do not edit.", - r"\begin{samepage}", - r"\subsection*{Numerical validation summary}", - ( - r"Only measurements whose numerical checks pass are counted below. " - r"The scope comprises every applicable report cell across the " - r"complete declared multiplicity range." - ), - r"\begin{center}", - r"\small", - r"\begin{tabular}{@{}l r r r l@{}}", - r"\toprule", - ( - r"\textbf{final-state multiplicity} & \textbf{declared} & " - r"\textbf{static N/A} & \textbf{verified} & " - r"\textbf{measurable coverage} \\" - ), - r"\midrule", - ] - for n_final, expected in summary.expected_by_n: - passed = passed_by_n[n_final] - lines.append( - f"{n_final} & {declared_by_n[n_final]} & " - f"{static_na_by_n[n_final]} & {passed} & " - f"{_coverage_status(passed, expected, terminal_by_n[n_final])}" - r" \\" - ) - lines.extend( - [ - r"\midrule", - ( - r"\textbf{total} & " - f"{summary.declared_total} & {summary.static_na_total} & " - f"{summary.passed_total} & " - f"{total_coverage}" - r" \\" - ), - r"\bottomrule", - r"\end{tabular}", - r"\end{center}", - r"\end{samepage}", - ( - r"\ReportTableNote{Full-catalog display accounting through \(n=9\): " - f"{display.declared_measurement_cell_count} declared cells, comprising " - f"{display.required_measurement_count} measurable cells and " - f"{display.catalog_static_na_cell_count} catalog-authenticated " - r"static N/A rows; " - f"{display.structurally_not_applicable_display_slot_count} " - r"matrix process/multiplicity positions marked either " - r"\textsc{not applicable} or \textsc{not run}; and " - f"{display.not_exposed_display_slot_count} " - r"reference execution fields marked \textsc{not exposed}. " - r"The latter two categories are intentional table structure, " - r"not unfilled measurements.}" - ), - r"\begin{center}", - r"\small", - r"\begin{tabular}{@{}l r r@{}}", - r"\toprule", - ( - r"\textbf{validation evidence} & \textbf{records} & " - r"\textbf{max. relative difference} \\" - ), - r"\midrule", - ( - r"MadGraph standalone tree-level reference records" - f" & {summary.madgraph_reference_count} & " - r"\textcolor{ReportMuted}{reference} \\" - ), - ( - r"\PAC{} versus MadGraph binary64 (p200; OTF p16)" - f" & {summary.madgraph_comparison_count} & " - f"{_scientific(summary.madgraph_comparison_maximum_relative_difference)}" - r" \\" - ), - ( - r"original-\AC{} legacy diagnostic records" - f" & {summary.legacy_reference_count} & " - r"\textcolor{ReportMuted}{diagnostic} \\" - ), - ( - r"\PAC{} versus original-\AC{} legacy diagnostic" - f" & {summary.legacy_comparison_pass_count} pass, " - f"{summary.legacy_comparison_failure_count} mismatch & " - f"{_scientific(summary.legacy_comparison_maximum_relative_difference)}" - r" \\" - ), - ( - r"compiled/eager/OTF versus recurrence" - f" & {summary.cross_mode_count} & " - f"{_scientific(summary.cross_mode_maximum_relative_difference)}" - r" \\" - ), - ( - r"optimized result versus resolved sum" - f" & {summary.resolved_count} & " - f"{_scientific(summary.resolved_maximum_relative_difference)}" - r" \\" - ), - ( - r"binary64 result versus p32" - f" & {summary.high_precision_count} & " - f"{_scientific(summary.high_precision_maximum_relative_difference)}" - r" \\" - ), - r"\bottomrule", - r"\end{tabular}", - r"\end{center}", - ] - ) - revision = summary.uniform_source_revision - if ( - authenticated_source_lineage is not None - and summary.successful_source_identity_count == summary.passed_total - and set(summary.source_revisions).issubset(set(authenticated_source_lineage)) - ): - ancestor, descendant = authenticated_source_lineage - source_text = ( - rf"\nolinkurl{{{ancestor}}} \(\rightarrow\) " - rf"\nolinkurl{{{descendant}}} " - r"\textcolor{ReportGreen}{(authenticated Class-C lineage)}" - ) - elif revision is None: - source_text = ( - r"\textcolor{ReportOrange}{source identity is incomplete or mixed}" - ) - else: - source_text = rf"\nolinkurl{{{revision}}}" - lines.extend( - [ - ( - r"\ReportTableNote{Profile: \texttt{\ReportProfileName}. " - r"Measured source: " - + source_text - + r". The authoritative \PAC{} versus MadGraph binary64 " - r"full-colour comparison uses p200 for recurrence, compiled, " - r"and eager candidates and the supported p16 lane for OTF; " - r"all use a relative tolerance " - r"of \(10^{-10}\). Original-\AC{} comparisons are retained " - r"non-authoritative legacy diagnostics at \(10^{-8}\); a " - r"legacy mismatch does not invalidate a candidate; cross-mode " - r"(including OTF/recurrence), resolved-sum, and p32 " - r"comparisons use \(10^{-12}\).}" - ), - ] - ) - return "\n".join(lines) + "\n" - - -__all__ = [ - "MAX_PUBLICATION_MULTIPLICITY", - "SUMMARY_TABLE_NAME", - "ValidationSummary", - "render_validation_summary", - "summarize_validation", -] diff --git a/pyamplicol/tools/performance_report/worker.py b/pyamplicol/tools/performance_report/worker.py deleted file mode 100644 index 43137ae55f..0000000000 --- a/pyamplicol/tools/performance_report/worker.py +++ /dev/null @@ -1,689 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Isolated one-cell worker entry point used by the campaign scheduler.""" - -from __future__ import annotations - -import json -import math -import os -import re -import shutil -import subprocess -import tempfile -import threading -import time -import traceback -import uuid -from collections.abc import Iterator, Mapping, Sequence -from contextlib import contextmanager, redirect_stderr, redirect_stdout -from pathlib import Path -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from pyamplicol.reporting import ProgressEvent, ProgressSink - -from .agreements import ( - LC_CROSS_LAYOUT_COMPONENT, - attach_direct_agreements, - incoming_agreement_edges, - independent_numerical_authorities, -) -from .artifacts import _filesystem_lock, _raise_disk_full -from .catalog import REPORT_CATALOG, ReportCatalog -from .measurement import ( - attach_validation_failure_precision_diagnostic, - failure_measurement, - generated_artifact_from_measurement, - load_measurement, - measure_pyamplicol_cell, -) -from .models import ExecutionMode, ResultStatus -from .phase_state import WorkerPhaseChannel, WorkerPhaseReporter -from .runner import ProfilingTimeLimitError, RunnerSettings -from .service import ReportPaths -from .source_identity import ReportSourceIdentity, require_eligible_report_source -from .worker_harness import attach_worker_harness_identity - -_GIT_OBJECT_ID = re.compile(r"^[0-9a-fA-F]{40}$") - - -class _JsonlProgressSink: - """Thread-safe, append-only typed progress capture for dashboard readers.""" - - def __init__(self, path: Path) -> None: - self.path = path.expanduser().resolve(strict=False) - self.path.parent.mkdir(parents=True, exist_ok=True) - self._lock = threading.Lock() - - def emit(self, event: ProgressEvent) -> None: - from pyamplicol.reporting import ProgressEnd, ProgressStart, ProgressUpdate - - payload: dict[str, object] = { - "timestamp_unix": time.time(), - "pid": os.getpid(), - "task_id": event.task_id, - } - if isinstance(event, ProgressStart): - payload.update( - { - "event": "start", - "description": event.description, - "total": event.total, - "parent_task_id": event.parent_task_id, - "unit": event.unit, - "details": dict(event.details), - } - ) - elif isinstance(event, ProgressUpdate): - payload.update( - { - "event": "update", - "completed": event.completed, - "total": event.total, - "message": event.message, - "details": dict(event.details), - } - ) - elif isinstance(event, ProgressEnd): - payload.update( - { - "event": "end", - "success": event.success, - "message": event.message, - "elapsed_seconds": event.elapsed_seconds, - "details": dict(event.details), - } - ) - else: # pragma: no cover - ProgressEvent is a closed typed union. - raise TypeError(f"unsupported progress event: {type(event).__name__}") - encoded = ( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ).encode("ascii") - flags = os.O_APPEND | os.O_CREAT | os.O_WRONLY | getattr(os, "O_CLOEXEC", 0) - with self._lock: - descriptor = os.open(self.path, flags, 0o600) - try: - os.write(descriptor, encoded) - finally: - os.close(descriptor) - - -def _source_identity( - repo_root: Path, - revision: str | None, - tree: str | None, -) -> ReportSourceIdentity: - if (revision is None) != (tree is None): - raise ValueError("manual source revision and tree must be specified together") - if revision is None: - return require_eligible_report_source(repo_root) - assert tree is not None - if _GIT_OBJECT_ID.fullmatch(revision) is None: - raise ValueError("manual source revision must be a 40-digit hexadecimal ID") - if _GIT_OBJECT_ID.fullmatch(tree) is None: - raise ValueError("manual source tree must be a 40-digit hexadecimal ID") - return ReportSourceIdentity(revision.lower(), tree.lower(), ()) - - -def _portable_current_paths( - *, - repo_root: Path, - attempt_root: Path, -) -> ReportPaths | None: - """Recognize the canonical copied-campaign attempt shape. - - Ordinary developer/report stores retain their historical raw-current ABI. - A copied manual campaign has one literal visible state root, so its worker - can materialize authenticated peer/current files without another CLI flag. - """ - - lexical_attempt = Path(os.path.abspath(attempt_root.expanduser())) - if len(lexical_attempt.parents) < 4: - return None - artifact_root = lexical_attempt.parents[3] - if artifact_root.name != "campaign_artifacts": - return None - relative = lexical_attempt.relative_to(artifact_root) - if ( - len(relative.parts) != 4 - or relative.parts[0] != "cells" - or not relative.parts[1] - or relative.parts[2] != "attempts" - ): - raise ValueError("manual campaign worker attempt path is not canonical") - try: - attempt_id = str(uuid.UUID(relative.parts[3])) - except ValueError as error: - raise ValueError("manual campaign worker attempt ID is invalid") from error - if attempt_id != relative.parts[3]: - raise ValueError("manual campaign worker attempt ID is not canonical") - try: - resolved_attempt = attempt_root.expanduser().resolve(strict=True) - resolved_root = artifact_root.resolve(strict=True) - except OSError as error: - raise ValueError("manual campaign worker state root is unavailable") from error - if ( - resolved_attempt != lexical_attempt - or resolved_root != artifact_root - or artifact_root.is_symlink() - or not artifact_root.is_dir() - ): - raise ValueError("manual campaign worker state root is not canonical") - coordination_root = artifact_root / "coordination" - if ( - coordination_root.is_symlink() - or not coordination_root.is_dir() - or coordination_root.resolve(strict=True) != coordination_root - ): - raise ValueError("manual campaign coordination root is not canonical") - docs_dir = artifact_root.parent - return ReportPaths( - repo_root=repo_root.expanduser().resolve(strict=False), - docs_dir=docs_dir, - results_dir=docs_dir / "results", - artifact_root=artifact_root, - coordination_root=coordination_root, - ) - - -def _atomic_json(path: Path, payload: Mapping[str, object]) -> None: - descriptor: int | None = None - temporary: Path | None = None - try: - path.parent.mkdir(parents=True, exist_ok=True) - descriptor, temporary_name = tempfile.mkstemp( - prefix=f".{path.name}.", - suffix=".tmp", - dir=path.parent, - ) - temporary = Path(temporary_name) - stream = os.fdopen(descriptor, "w", encoding="ascii") - descriptor = None - with stream: - json.dump( - payload, - stream, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - stream.write("\n") - stream.flush() - os.fsync(stream.fileno()) - os.replace(temporary, path) - except OSError as error: - _raise_disk_full(error, path) - finally: - if descriptor is not None: - os.close(descriptor) - if temporary is not None: - temporary.unlink(missing_ok=True) - - -def _selector_provider_measurement( - cell_id: str, - peers: Mapping[str, Mapping[str, object]], - *, - catalog: ReportCatalog, -) -> Mapping[str, object] | None: - """Return the scheduled selected-flow peer used to seed LC all-flow.""" - - cell = catalog.cell(cell_id) - providers = tuple( - edge.baseline.cell_id - for edge in incoming_agreement_edges(cell, catalog=catalog) - if edge.kind == LC_CROSS_LAYOUT_COMPONENT - ) - if not providers: - return None - if len(providers) != 1: - raise ValueError(f"{cell_id}: selector provider is not unique") - provider_id = providers[0] - provider = peers.get(provider_id) - if provider is None: - raise ValueError( - f"{cell_id}: required selector provider {provider_id!r} is unavailable" - ) - return provider - - -@contextmanager -def _worker_legacy_workspace( - *, - repository: Path | None, - source_repository: Path | None, - workspace: Path | None, - copy_source: bool, -) -> Iterator[Path | None]: - """Prepare an isolated legacy checkout inside the supervised worker.""" - - if source_repository is None: - if workspace is not None or copy_source: - raise ValueError( - "legacy workspace/copy options require a source repository" - ) - yield repository - return - if repository is not None: - raise ValueError( - "legacy repository and legacy source repository are mutually exclusive" - ) - if workspace is None: - raise ValueError("legacy source repository requires a workspace destination") - source = source_repository.expanduser().resolve(strict=True) - destination = workspace.expanduser().resolve(strict=False) - destination.parent.mkdir(parents=True, exist_ok=True) - if destination.exists(): - raise RuntimeError(f"legacy worker workspace already exists: {destination}") - - from .legacy import MaintainedLegacyApi - from .legacy_structure import legacy_structural_probe_lock - - api = MaintainedLegacyApi() - print( - f"Preparing isolated original-AmpliCol workspace {destination}", - flush=True, - ) - if copy_source: - with legacy_structural_probe_lock(source): - shutil.copytree( - source, - destination, - ignore=shutil.ignore_patterns(".git", ".DS_Store"), - ) - else: - api.validate_checkout(source) - commands = ( - ( - "git", - "clone", - "--shared", - "--no-checkout", - "--", - os.fspath(source), - os.fspath(destination), - ), - ( - "git", - "-C", - os.fspath(destination), - "checkout", - "--detach", - api.expected_revision(), - ), - ) - for command in commands: - print(f"Legacy workspace command: {' '.join(command)}", flush=True) - completed = subprocess.run( - command, - check=False, - capture_output=True, - text=True, - timeout=300, - ) - if completed.returncode != 0: - detail = completed.stderr.strip() or completed.stdout.strip() - raise RuntimeError( - "cannot prepare isolated legacy worker checkout: " - f"{detail or f'exit {completed.returncode}'}" - ) - api.validate_checkout(destination) - try: - yield destination - finally: - if destination.exists(): - if destination.is_symlink() or not destination.is_dir(): - raise RuntimeError( - "legacy worker workspace is not its canonical regular " - f"directory: {destination}" - ) - shutil.rmtree(destination) - - -def measure_cell( - cell_id: str, - *, - repo_root: Path, - attempt_root: Path, - target_runtime_seconds: float, - batch_size: int, - worker_cores: int, - amplicol_build_jobs: int = 1, - memory_limit_bytes: int | None = None, - warmup_runs: int = 2, - minimum_samples: int = 5, - progress_jsonl: Path | None = None, - worker_wall_limit_seconds: float | None = None, - profiling_time_limit_seconds: float | None = None, - validation_time_limit_seconds: float | None = None, - manual_source_revision: str | None = None, - manual_source_tree: str | None = None, - baseline_json: Path | None = None, - expected_authority_cell_ids: Sequence[str] = (), - selected_authority_cell_id: str | None = None, - peer_json: Sequence[tuple[str, Path]] = (), - prepared_model_path: Path | None = None, - reused_measurement_json: Path | None = None, - phase_reporter: WorkerPhaseReporter | None = None, - legacy_repository: Path | None = None, - legacy_source_repository: Path | None = None, - legacy_workspace: Path | None = None, - legacy_copy_source: bool = False, - legacy_source_revision: str | None = None, - madgraph_installation: Path | None = None, - catalog: ReportCatalog = REPORT_CATALOG, -) -> dict[str, object]: - worker_started_monotonic = time.monotonic() - if amplicol_build_jobs < 1: - raise ValueError("amplicol_build_jobs must be positive") - for name, value in ( - ("worker_wall_limit_seconds", worker_wall_limit_seconds), - ("profiling_time_limit_seconds", profiling_time_limit_seconds), - ("validation_time_limit_seconds", validation_time_limit_seconds), - ): - if value is not None and (not math.isfinite(value) or value <= 0.0): - raise ValueError(f"{name} must be finite and positive") - cell = catalog.cell(cell_id) - static_na_reason = catalog.static_na_reason(cell) - if static_na_reason is not None: - description = catalog.static_na_description(cell) - raise ValueError( - f"{cell_id}: catalog static N/A cell cannot be measured " - f"({static_na_reason}: {description})" - ) - authority_ids = tuple(expected_authority_cell_ids) - canonical_authority_ids = tuple( - authority.cell_id - for authority in independent_numerical_authorities(cell, catalog=catalog) - ) - if authority_ids != canonical_authority_ids: - raise ValueError( - "expected numerical authority cell IDs differ from the canonical " - f"catalog chain: expected={canonical_authority_ids!r}, " - f"observed={authority_ids!r}" - ) - if selected_authority_cell_id is not None and ( - selected_authority_cell_id not in authority_ids - or baseline_json is None - ): - raise ValueError("selected numerical authority is not in the expected chain") - if authority_ids and (baseline_json is not None) != ( - selected_authority_cell_id is not None - ): - raise ValueError( - "compiled/eager baseline and selected numerical authority must be " - "specified together" - ) - source_identity = _source_identity( - repo_root, - manual_source_revision, - manual_source_tree, - ) - progress: ProgressSink | None = ( - None if progress_jsonl is None else _JsonlProgressSink(progress_jsonl) - ) - publication_paths = _portable_current_paths( - repo_root=repo_root, - attempt_root=attempt_root, - ) - baseline = ( - None - if baseline_json is None - else load_measurement( - baseline_json, - publication_paths=publication_paths, - ) - ) - peers = { - peer_cell_id: load_measurement( - path, - publication_paths=publication_paths, - ) - for peer_cell_id, path in peer_json - } - if len(peers) != len(peer_json): - raise ValueError("direct-agreement peer cell IDs must be unique") - reused_artifact = ( - None - if reused_measurement_json is None - else generated_artifact_from_measurement( - load_measurement( - reused_measurement_json, - publication_paths=publication_paths, - ) - ) - ) - selector_provider = _selector_provider_measurement( - cell.cell_id, - peers, - catalog=catalog, - ) - if cell.measurement.execution_mode is ExecutionMode.AMPLICOL: - from .legacy import LegacyMeasurementAdapter, LegacySettings - - with _worker_legacy_workspace( - repository=legacy_repository, - source_repository=legacy_source_repository, - workspace=legacy_workspace, - copy_source=legacy_copy_source, - ) as prepared_legacy_repository: - result = LegacyMeasurementAdapter().measure( - cell, - artifact_path=attempt_root / "artifact", - settings=LegacySettings( - target_runtime_seconds=target_runtime_seconds, - jobs=amplicol_build_jobs, - repository=prepared_legacy_repository, - validate_checkout=manual_source_revision is None, - source_revision=legacy_source_revision, - profiling_time_limit_seconds=profiling_time_limit_seconds, - worker_deadline_monotonic=( - None - if worker_wall_limit_seconds is None - else worker_started_monotonic + worker_wall_limit_seconds - ), - ), - phase_reporter=phase_reporter, - selector_provider=selector_provider, - ) - elif cell.measurement.execution_mode is ExecutionMode.MADGRAPH: - if madgraph_installation is None: - raise ValueError( - "MadGraph reference cell requires a configured installation" - ) - from .madgraph import MadGraphMeasurementAdapter, MadGraphSettings - - result = MadGraphMeasurementAdapter().measure( - cell, - artifact_path=attempt_root / "artifact", - settings=MadGraphSettings( - installation=madgraph_installation, - target_runtime_seconds=target_runtime_seconds, - worker_deadline_monotonic=( - None - if worker_wall_limit_seconds is None - else worker_started_monotonic + worker_wall_limit_seconds - ), - ), - phase_reporter=phase_reporter, - ) - else: - result = measure_pyamplicol_cell( - cell, - artifact_path=attempt_root / "artifact", - settings=RunnerSettings( - target_runtime_seconds=target_runtime_seconds, - batch_size=batch_size, - worker_cores=worker_cores, - memory_limit_bytes=memory_limit_bytes, - warmup_runs=warmup_runs, - minimum_samples=minimum_samples, - model_cache_dir=attempt_root.parent.parent.parent / "model-cache", - progress=progress, - source_revision_override=( - None if manual_source_revision is None else source_identity.revision - ), - profiling_time_limit_seconds=profiling_time_limit_seconds, - worker_deadline_monotonic=( - None - if worker_wall_limit_seconds is None - else worker_started_monotonic + worker_wall_limit_seconds - ), - ), - repo_root=repo_root, - baseline=baseline, - expected_authority_cell_ids=authority_ids, - selected_authority_cell_id=selected_authority_cell_id, - validation_peers=peers, - selector_provider=selector_provider, - prepared_model_path=prepared_model_path, - reused_artifact=reused_artifact, - phase_reporter=phase_reporter, - catalog=catalog, - ) - attach_direct_agreements( - cell, - result, - peers, - catalog=catalog, - ) - attach_validation_failure_precision_diagnostic( - cell, - result, - baseline=baseline, - peers=peers, - ) - source_identity_postflight = _source_identity( - repo_root, - manual_source_revision, - manual_source_tree, - ) - if source_identity_postflight != source_identity: - raise RuntimeError("report source identity changed during cell measurement") - provenance = result.get("provenance") - result["provenance"] = { - **({} if not isinstance(provenance, Mapping) else dict(provenance)), - **source_identity.provenance(), - } - if phase_reporter is not None: - phase_reporter.complete() - return result - - -def write_cell_result( - cell_id: str, - result_path: Path, - *, - log_path: Path | None = None, - phase_state_path: Path | None = None, - phase_state_run_id: str | None = None, - phase_state_authentication_key: str | None = None, - worker_harness: Mapping[str, object] | None = None, - worker_wall_limit_seconds: float | None = None, - profiling_time_limit_seconds: float | None = None, - validation_time_limit_seconds: float | None = None, - generation_lock_path: Path | None = None, - madgraph_installation: Path | None = None, - **kwargs: object, -) -> dict[str, object]: - try: - phase_arguments = ( - phase_state_path, - phase_state_run_id, - phase_state_authentication_key, - ) - if any(argument is not None for argument in phase_arguments): - if not all(argument is not None for argument in phase_arguments): - raise ValueError( - "worker phase-state arguments must be specified together" - ) - assert phase_state_path is not None - assert phase_state_run_id is not None - assert phase_state_authentication_key is not None - phase_reporter = WorkerPhaseReporter( - WorkerPhaseChannel( - path=phase_state_path.expanduser().resolve(strict=False), - run_id=phase_state_run_id, - authentication_key=phase_state_authentication_key, - ), - track_post_generation_stages=( - profiling_time_limit_seconds is not None - or validation_time_limit_seconds is not None - ), - generation_gate=( - None - if generation_lock_path is None - else lambda: _filesystem_lock( - generation_lock_path, - timeout=None, - poll_interval=0.05, - ) - ), - ) - else: - phase_reporter = None - if log_path is None: - result = measure_cell( - cell_id, - phase_reporter=phase_reporter, - worker_wall_limit_seconds=worker_wall_limit_seconds, - profiling_time_limit_seconds=profiling_time_limit_seconds, - validation_time_limit_seconds=validation_time_limit_seconds, - madgraph_installation=madgraph_installation, - **kwargs, # type: ignore[arg-type] - ) - else: - log_path.parent.mkdir(parents=True, exist_ok=True) - with ( - log_path.open("a", encoding="utf-8") as stream, - redirect_stdout(stream), - redirect_stderr(stream), - ): - result = measure_cell( - cell_id, - phase_reporter=phase_reporter, - worker_wall_limit_seconds=worker_wall_limit_seconds, - profiling_time_limit_seconds=profiling_time_limit_seconds, - validation_time_limit_seconds=validation_time_limit_seconds, - madgraph_installation=madgraph_installation, - **kwargs, # type: ignore[arg-type] - ) - except ProfilingTimeLimitError as error: - if log_path is not None: - with log_path.open("a", encoding="utf-8") as stream: - traceback.print_exc(file=stream) - result = failure_measurement( - ResultStatus.TIMEOUT, - error, - resources={"terminal_reason": "profiling_timeout"}, - ) - except Exception as error: - if log_path is not None: - with log_path.open("a", encoding="utf-8") as stream: - traceback.print_exc(file=stream) - result = failure_measurement(ResultStatus.ERROR, error) - if worker_harness is not None: - attach_worker_harness_identity(result, worker_harness) - provenance = result.get("provenance") - if isinstance(provenance, Mapping): - result["provenance"] = { - **provenance, - "worker_environment": { - "LD_LIBRARY_PATH": os.environ.get("LD_LIBRARY_PATH"), - "DYLD_LIBRARY_PATH": os.environ.get("DYLD_LIBRARY_PATH"), - }, - "worker_log": None if log_path is None else os.fspath(log_path), - } - _atomic_json(result_path, result) - return result - - -__all__ = ["measure_cell", "write_cell_result"] diff --git a/pyamplicol/tools/performance_report/worker_harness.py b/pyamplicol/tools/performance_report/worker_harness.py deleted file mode 100644 index 4ad480c6a1..0000000000 --- a/pyamplicol/tools/performance_report/worker_harness.py +++ /dev/null @@ -1,177 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Relocation-safe identities for split wrapper/measurement workers.""" - -from __future__ import annotations - -import re -from collections.abc import Mapping, MutableMapping - -WORKER_HARNESS_ABI = "pyamplicol-report-worker-harness-v1" -WORKER_HARNESS_PROVENANCE_FIELD = "worker_harness" -POLICY_ENTRYPOINT = "src/pyamplicol/_profiling_campaign/result_tables.py" -LEGACY_ADAPTER = "tools/performance_report/legacy.py" - -_SHA40_RE = re.compile(r"[0-9a-f]{40}") -_SHA256_RE = re.compile(r"[0-9a-f]{64}") -_FIELDS = frozenset( - { - "abi", - "study_contract_sha256", - "policy_wrapper_revision", - "policy_wrapper_tree", - "policy_entrypoint", - "policy_entrypoint_sha256", - "legacy_adapter", - "legacy_adapter_sha256", - "measured_source_revision", - "measured_source_tree", - } -) - - -class WorkerHarnessError(ValueError): - """A worker did not use the authenticated wrapper/measurement split.""" - - -def worker_harness_identity( - *, - study_contract_sha256: str, - policy_wrapper_revision: str, - policy_wrapper_tree: str, - policy_entrypoint_sha256: str, - legacy_adapter_sha256: str, - measured_source_revision: str, - measured_source_tree: str, -) -> dict[str, object]: - """Build a canonical identity without embedding checkout paths.""" - - payload: dict[str, object] = { - "abi": WORKER_HARNESS_ABI, - "study_contract_sha256": study_contract_sha256, - "policy_wrapper_revision": policy_wrapper_revision, - "policy_wrapper_tree": policy_wrapper_tree, - "policy_entrypoint": POLICY_ENTRYPOINT, - "policy_entrypoint_sha256": policy_entrypoint_sha256, - "legacy_adapter": LEGACY_ADAPTER, - "legacy_adapter_sha256": legacy_adapter_sha256, - "measured_source_revision": measured_source_revision, - "measured_source_tree": measured_source_tree, - } - validate_worker_harness_identity(payload) - return payload - - -def validate_worker_harness_identity( - value: object, - *, - expected: Mapping[str, object] | None = None, - expected_measured_revision: str | None = None, - expected_measured_tree: str | None = None, -) -> Mapping[str, object]: - """Validate one canonical wrapper/measurement identity.""" - - if not isinstance(value, Mapping) or set(value) != _FIELDS: - raise WorkerHarnessError("worker harness fields are not canonical") - if ( - value.get("abi") != WORKER_HARNESS_ABI - or value.get("policy_entrypoint") != POLICY_ENTRYPOINT - or value.get("legacy_adapter") != LEGACY_ADAPTER - ): - raise WorkerHarnessError("worker harness ABI or relative paths differ") - for field in ( - "policy_wrapper_revision", - "policy_wrapper_tree", - "measured_source_revision", - "measured_source_tree", - ): - item = value.get(field) - if not isinstance(item, str) or _SHA40_RE.fullmatch(item) is None: - raise WorkerHarnessError( - f"worker harness {field} is not a Git identity" - ) - for field in ( - "study_contract_sha256", - "policy_entrypoint_sha256", - "legacy_adapter_sha256", - ): - item = value.get(field) - if not isinstance(item, str) or _SHA256_RE.fullmatch(item) is None: - raise WorkerHarnessError( - f"worker harness {field} is not SHA-256" - ) - if expected is not None and dict(value) != dict(expected): - raise WorkerHarnessError( - "worker harness differs from the authenticated study contract" - ) - if ( - expected_measured_revision is not None - and value.get("measured_source_revision") - != expected_measured_revision - ): - raise WorkerHarnessError( - "worker harness measured source revision differs" - ) - if ( - expected_measured_tree is not None - and value.get("measured_source_tree") != expected_measured_tree - ): - raise WorkerHarnessError("worker harness measured source tree differs") - return value - - -def attach_worker_harness_identity( - measurement: MutableMapping[str, object], - identity: Mapping[str, object], -) -> None: - """Attach an authenticated identity without overwriting another harness.""" - - validated = dict(validate_worker_harness_identity(identity)) - provenance = measurement.get("provenance") - if provenance is not None and not isinstance(provenance, Mapping): - raise WorkerHarnessError("measurement provenance is invalid") - existing = ( - provenance.get(WORKER_HARNESS_PROVENANCE_FIELD) - if isinstance(provenance, Mapping) - else None - ) - if existing is not None and existing != validated: - raise WorkerHarnessError( - "measurement is already bound to another worker harness" - ) - measurement["provenance"] = { - **({} if provenance is None else dict(provenance)), - WORKER_HARNESS_PROVENANCE_FIELD: validated, - } - - -def require_worker_harness_identity( - measurement: Mapping[str, object], - *, - expected: Mapping[str, object] | None = None, - expected_measured_revision: str | None = None, - expected_measured_tree: str | None = None, -) -> Mapping[str, object]: - """Return the authenticated harness carried by a measurement.""" - - provenance = measurement.get("provenance") - if not isinstance(provenance, Mapping): - raise WorkerHarnessError("measurement has no worker harness provenance") - return validate_worker_harness_identity( - provenance.get(WORKER_HARNESS_PROVENANCE_FIELD), - expected=expected, - expected_measured_revision=expected_measured_revision, - expected_measured_tree=expected_measured_tree, - ) - - -__all__ = [ - "LEGACY_ADAPTER", - "POLICY_ENTRYPOINT", - "WORKER_HARNESS_ABI", - "WORKER_HARNESS_PROVENANCE_FIELD", - "WorkerHarnessError", - "attach_worker_harness_identity", - "require_worker_harness_identity", - "validate_worker_harness_identity", - "worker_harness_identity", -] diff --git a/pyamplicol/tools/performance_report/workspace.py b/pyamplicol/tools/performance_report/workspace.py deleted file mode 100644 index 436a7d5a5f..0000000000 --- a/pyamplicol/tools/performance_report/workspace.py +++ /dev/null @@ -1,1316 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Architecture-scoped, tracked performance-report workspaces.""" - -from __future__ import annotations - -import importlib -import json -import platform -import re -import shutil -import subprocess -import uuid -from collections.abc import Callable, Mapping -from pathlib import Path - -from .campaign_policy import ( - MACBOOK_M3_POLICY, - X86_EPYC_POLICY, - X86_EPYC_WORKERS, - CampaignPolicy, - CampaignPolicyError, - campaign_policy, - default_campaign_policy, - policy_from_manifest, - validate_policy_profile, -) -from .publication import publication_absolute_paths -from .service import ( - CANONICAL_REPORT_ENTRYPOINT, - CANONICAL_REPORT_ROOT, - PROFILE_REPORT_ROOT, - ReportPaths, - ReportService, - validate_profile_name, -) -from .source_identity import ( - SOURCE_IDENTITY_SCHEMA, - ReportSourceIdentityError, - inspect_report_source, -) -from .standalone_build import compile_report - -WORKSPACE_SCHEMA = "pyamplicol-performance-report-workspace-v4" -WORKSPACE_MANIFEST = "report-workspace.json" -ENVIRONMENT_SCHEMA = "pyamplicol-performance-report-environment-v1" -ENVIRONMENT_JSON = "report_environment.json" -ENVIRONMENT_TEX = "report_environment.tex" -MEASUREMENT_LINEAGE_JSON = "measurement_lineage.json" -STANDALONE_BUILDER = "build_pdf.py" -TABLE_FILLING_RUNBOOK = "TABLE_FILLING.md" -PROFILE_PARENT = PROFILE_REPORT_ROOT -_GIT_SHA_RE = re.compile(r"^[0-9a-f]{40}$") -_PENDING_RUNTIME = "pending exact-source runtime authentication" - - -class ReportWorkspaceError(RuntimeError): - """A report workspace could not be initialized or exported safely.""" - - -def _canonical_json(payload: Mapping[str, object]) -> str: - return ( - json.dumps( - payload, - allow_nan=False, - ensure_ascii=True, - separators=(",", ":"), - sort_keys=True, - ) - + "\n" - ) - - -def profile_docs_dir(repo_root: Path, profile: str) -> Path: - root = repo_root.expanduser().resolve(strict=False) - return root / PROFILE_PARENT / validate_profile_name(profile) - - -def _source_docs_dir( - repo_root: Path, - *, - source_profile: str | None, -) -> Path: - if source_profile is None: - return repo_root / CANONICAL_REPORT_ROOT - return profile_docs_dir(repo_root, source_profile) - - -def _copy_publication_members( - source: Path, - destination: Path, -) -> None: - required = (source / "pyAmpliCol.tex", source / "result_tables.py") - missing = [path.name for path in required if not path.is_file()] - if missing: - raise ReportWorkspaceError( - f"report source {source} is missing required files: {missing}" - ) - results = source / "results" - if not results.is_dir(): - raise ReportWorkspaceError(f"report source has no results directory: {source}") - - destination.mkdir(parents=True, exist_ok=False) - for path in sorted(source.glob("*.tex")): - if not path.is_file() or path.is_symlink(): - raise ReportWorkspaceError(f"unsafe TeX source member: {path}") - shutil.copy2(path, destination / path.name) - environment_json = source / ENVIRONMENT_JSON - if environment_json.exists(): - if not environment_json.is_file() or environment_json.is_symlink(): - raise ReportWorkspaceError( - f"unsafe environment metadata member: {environment_json}" - ) - shutil.copy2(environment_json, destination / ENVIRONMENT_JSON) - shutil.copy2(source / "result_tables.py", destination / "result_tables.py") - - output_results = destination / "results" - output_results.mkdir() - json_files = tuple(sorted(results.glob("*.json"))) - if not json_files: - raise ReportWorkspaceError(f"report source has no JSON caches: {results}") - for path in json_files: - if not path.is_file() or path.is_symlink(): - raise ReportWorkspaceError(f"unsafe result-cache member: {path}") - shutil.copy2(path, output_results / path.name) - - -def _copy_measurement_lineage(source: Path, destination: Path) -> None: - measurement_lineage = source / MEASUREMENT_LINEAGE_JSON - if not measurement_lineage.exists(): - return - if not measurement_lineage.is_file() or measurement_lineage.is_symlink(): - raise ReportWorkspaceError( - f"unsafe measurement-lineage member: {measurement_lineage}" - ) - shutil.copy2( - measurement_lineage, - destination / MEASUREMENT_LINEAGE_JSON, - ) - - -def _install_standalone_builder(destination: Path) -> None: - source = Path(__file__).with_name("standalone_build.py") - if not source.is_file() or source.is_symlink(): - raise ReportWorkspaceError( - f"standalone report builder is unavailable: {source}" - ) - shutil.copy2(source, destination / STANDALONE_BUILDER) - - -def _assert_portable_results(docs_dir: Path) -> None: - for path in sorted((docs_dir / "results").glob("*.json")): - try: - payload = json.loads(path.read_text(encoding="ascii")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise ReportWorkspaceError( - f"cannot inspect publication result {path}: {error}" - ) from error - absolute = publication_absolute_paths(payload) - if absolute: - raise ReportWorkspaceError( - f"publication result retains absolute host paths: " - f"{path.name}: {absolute[:3]}" - ) - - -def _campaign_commands(profile: str, policy: CampaignPolicy) -> str: - if policy is X86_EPYC_POLICY: - populate_options = ( - f" --workers {X86_EPYC_WORKERS} --cell-cores 1 " - "--target-runtime 5 \\\n" - " --max-ram-gb 80 --allow-symbolica-parallel --refresh-pdf end" - ) - elif policy is MACBOOK_M3_POLICY: - populate_options = ( - " --workers 1 --cell-cores 1 --target-runtime 5 \\\n" - " --max-ram-gb 30 --refresh-pdf end" - ) - else: - populate_options = ( - " --workers 1 --cell-cores 1 --target-runtime 5 --refresh-pdf end" - ) - return "\n".join( - line - for multiplicity in range(1, 10) - for line in ( - f"python3 docs/performance_reports/{profile}/result_tables.py populate \\", - f" --n-final {multiplicity} --missing-only --artifact-policy reuse \\", - populate_options, - f"python3 docs/performance_reports/{profile}/result_tables.py audit", - "", - ) - ).rstrip() - - -def _workspace_readme(profile: str, policy: CampaignPolicy) -> str: - return f""" -# pyAmpliCol performance report: `{profile}` - -This directory is the self-contained publication workspace for the -`{profile}` measurement environment. It contains the report's LaTeX sources, -canonical raw JSON measurements, generated table TeX, and the PDF when it has -been compiled. Large evaluator artifacts, worker logs, locks, and coordination -state are deliberately stored outside this tracked directory. - -`{TABLE_FILLING_RUNBOOK}` is the sole authoritative campaign procedure. Follow -its phase ordering, resource limits, user-approval pauses, numerical gates, -visual-review cadence, branch coordination, and publication allowlist. This -README intentionally contains no shortened measurement recipe. - -Compile this publication folder on any machine with Python and pdfLaTeX: - -```bash -cd docs/performance_reports/{profile} -python3 {STANDALONE_BUILDER} -``` - -From a pyAmpliCol source checkout, regenerate tables and run the cache audit -with: - -```bash -python3 docs/performance_reports/{profile}/result_tables.py render --compile -python3 docs/performance_reports/{profile}/result_tables.py audit -``` - -Create a portable copy, including raw data, TeX, and the reviewed PDF, from a -source checkout with: - -```bash -python3 {CANONICAL_REPORT_ENTRYPOINT.as_posix()} \ - export-profile {profile} /absolute/output/path -``` - -The copied entry point selects this profile automatically. Measurements still -require the exact pyAmpliCol source checkout and authenticated native runtime. -Never commit evaluator artifacts, candidate wheels, prepared models, attempts, -logs, locks, coordination state, page images, or LaTeX auxiliary files. -""" - - -def _table_filling_runbook(profile: str, policy: CampaignPolicy) -> str: - if policy is X86_EPYC_POLICY: - resources = ( - f"Run up to {X86_EPYC_WORKERS} independent workers, with one core " - "and a decimal 80 GB authenticated process-tree memory guard per " - "worker (RSS on Linux; max(process-tree RSS, Darwin physical " - "footprint) if enforced on macOS). The authenticated generation " - "phase is capped at two hours except for original AmpliCol and " - "compiled/recurrence LC selected-flow cells, which must finish. " - "Legacy v2 RSS-only censor evidence remains readable, but every " - "new run records the guard metric ABI and exact reason." - ) - elif policy is MACBOOK_M3_POLICY: - resources = ( - "Run exactly one worker on one core with a decimal 30 GB " - "authenticated memory guard defined as max(process-tree RSS, " - "Darwin physical footprint). Legacy v2 RSS-only censor evidence " - "remains readable, but every new run records the guard metric ABI " - "and exact reason. No generation timeout is authorized for this " - "profile." - ) - else: - resources = "Run one worker on one core without policy censors." - return f""" -# Complete table-filling campaign for `{profile}` - -Start from a clean checkout of the exact committed measurement SHA and a clean -native build authenticated by `refresh-profile-environment`. Populate the full -catalog in increasing final-state multiplicity from `n=1` through `n=9`. -{resources} - -Every successful pyAmpliCol result must pass the configured numerical -comparison. A direct hard-resource boundary is recorded canonically; higher -multiplicities in the same execution lane receive authenticated frontier -markers and are not launched. Do not replace failures with hand-written table -text. - -Run each multiplicity separately: - -```bash -{_campaign_commands(profile, policy)} -``` - -After every populate step, rebuild the PDF, inspect every refreshed page and -table visually, and confirm that values, ratios, status markers, and summary -rows are plausible. Investigate and fix any numerical mismatch before -continuing. Publish only canonical JSON results, generated table TeX, -environment metadata, and the reviewed PDF; never publish evaluator artifacts, -logs, locks, or worker checkouts. -""" - - -def _processor_description() -> str: - commands = ( - ("sysctl", "-n", "machdep.cpu.brand_string"), - ("sysctl", "-n", "hw.model"), - ) - if platform.system() == "Darwin": - for command in commands: - try: - completed = subprocess.run( - command, - check=False, - capture_output=True, - text=True, - timeout=5, - ) - except (OSError, subprocess.SubprocessError): - continue - value = completed.stdout.strip() - if completed.returncode == 0 and value: - return value - if platform.system() == "Linux": - try: - for line in ( - Path("/proc/cpuinfo") - .read_text( - encoding="utf-8", - errors="replace", - ) - .splitlines() - ): - key, separator, value = line.partition(":") - if separator and key.strip() in {"model name", "Hardware"}: - rendered = value.strip() - if rendered: - return rendered - except OSError: - pass - return platform.processor().strip() - - -def _host_environment_payload(profile: str) -> dict[str, str]: - processor = _processor_description() - machine = platform.machine().strip() or "unknown architecture" - platform_parts = [ - f"{platform.system()} {platform.release()}".strip(), - machine, - ] - if processor and processor.lower() != machine.lower(): - platform_parts.append(processor) - return { - "schema": ENVIRONMENT_SCHEMA, - "profile": profile, - "platform": "; ".join(platform_parts), - "machine": machine, - "processor": processor, - "python": platform.python_version(), - "python_implementation": platform.python_implementation(), - } - - -def _recorded_host_environment_payload( - profile: str, - host_environment: Mapping[str, object], -) -> dict[str, str]: - required = { - "platform", - "machine", - "processor", - "python", - "python_implementation", - "numpy", - } - if set(host_environment) != required: - raise ReportWorkspaceError( - "recorded measurement-host environment has an invalid shape" - ) - processor = host_environment.get("processor") - if not isinstance(processor, str): - raise ReportWorkspaceError( - "recorded measurement-host processor label must be a string" - ) - return { - "schema": ENVIRONMENT_SCHEMA, - "profile": profile, - "platform": _required_text( - host_environment.get("platform"), - "recorded measurement-host platform", - ), - "machine": _required_text( - host_environment.get("machine"), - "recorded measurement-host machine", - ), - "processor": processor, - "python": _required_text( - host_environment.get("python"), - "recorded measurement-host Python version", - ), - "python_implementation": _required_text( - host_environment.get("python_implementation"), - "recorded measurement-host Python implementation", - ), - "numpy": _required_text( - host_environment.get("numpy"), - "recorded measurement-host NumPy version", - ), - } - - -def _pending_environment_payload(profile: str) -> dict[str, str]: - pending_host = "pending measurement-host authentication" - return { - "schema": ENVIRONMENT_SCHEMA, - "profile": profile, - "platform": pending_host, - "machine": pending_host, - "processor": pending_host, - "python": pending_host, - "python_implementation": pending_host, - "status": "pending_exact_runtime", - "source_revision": "pending", - "pyamplicol": _PENDING_RUNTIME, - "numpy": _PENDING_RUNTIME, - "native_target": _PENDING_RUNTIME, - "native_cpu_features": _PENDING_RUNTIME, - "native_build_inputs_sha256": "pending", - "native_extension_sha256": "pending", - "python_package_tree_sha256": "pending", - "candidate_fingerprint": "pending", - } - - -def _required_text( - value: object, - context: str, -) -> str: - if not isinstance(value, str) or not value.strip(): - raise ReportWorkspaceError(f"{context} must be a non-empty string") - return value - - -def _authenticated_environment_payload( - profile: str, - *, - expected_source_revision: str, - active_runtime: Mapping[str, object], - host_environment: Mapping[str, object] | None = None, -) -> dict[str, str]: - package_version = _required_text( - active_runtime.get("package_version"), - "active runtime package_version", - ) - native_target = active_runtime.get("native_target") - if not isinstance(native_target, Mapping): - raise ReportWorkspaceError("active runtime native_target must be an object") - target_triple = _required_text( - native_target.get("triple"), - "active runtime native target triple", - ) - raw_features = native_target.get("cpu_features") - if not isinstance(raw_features, list) or not all( - isinstance(feature, str) and feature for feature in raw_features - ): - raise ReportWorkspaceError( - "active runtime native CPU features must be a string list" - ) - native_digest = _required_text( - active_runtime.get("native_build_inputs_sha256"), - "active runtime native build-input digest", - ) - if re.fullmatch(r"[0-9a-f]{64}", native_digest) is None: - raise ReportWorkspaceError( - "active runtime native build-input digest is not SHA-256" - ) - native_extension = active_runtime.get("native_extension") - python_package_tree = active_runtime.get("python_package_tree") - candidate_identity = active_runtime.get("candidate_build_identity") - if ( - not isinstance(native_extension, Mapping) - or not isinstance(python_package_tree, Mapping) - or not isinstance(candidate_identity, Mapping) - ): - raise ReportWorkspaceError( - "active runtime file and candidate identities must be objects" - ) - candidate_source_revision = candidate_identity.get("source_revision") - if candidate_source_revision != expected_source_revision: - raise ReportWorkspaceError( - "active runtime build identity differs from the expected source revision" - ) - native_extension_digest = _required_text( - native_extension.get("sha256"), - "active runtime native extension digest", - ) - package_tree_digest = _required_text( - python_package_tree.get("sha256"), - "active runtime Python package-tree digest", - ) - if any( - re.fullmatch(r"[0-9a-f]{64}", digest) is None - for digest in (native_extension_digest, package_tree_digest) - ): - raise ReportWorkspaceError("active runtime file identity digest is not SHA-256") - raw_candidate_fingerprint = candidate_identity.get("candidate_fingerprint") - if ( - raw_candidate_fingerprint is None - and candidate_identity.get("publishable") is True - ): - release_identity = _required_text( - active_runtime.get("candidate_build_identity_sha256"), - "active release runtime build-identity digest", - ) - if re.fullmatch(r"[0-9a-f]{64}", release_identity) is None: - raise ReportWorkspaceError( - "active release runtime build-identity digest is not SHA-256" - ) - raw_candidate_fingerprint = f"release:{release_identity}" - candidate_fingerprint = _required_text( - raw_candidate_fingerprint, - "active runtime candidate fingerprint", - ) - if host_environment is None: - host_payload = _host_environment_payload(profile) - numpy = importlib.import_module("numpy") - numpy_version = _required_text( - getattr(numpy, "__version__", None), - "active NumPy version", - ) - else: - host_payload = _recorded_host_environment_payload(profile, host_environment) - numpy_version = host_payload.pop("numpy") - return { - **host_payload, - "status": "authenticated", - "source_revision": expected_source_revision, - "pyamplicol": package_version, - "numpy": numpy_version, - "native_target": target_triple, - "native_cpu_features": ", ".join(raw_features) or "baseline", - "native_build_inputs_sha256": native_digest, - "native_extension_sha256": native_extension_digest, - "python_package_tree_sha256": package_tree_digest, - "candidate_fingerprint": candidate_fingerprint, - } - - -def _tex_escape(value: str) -> str: - replacements = { - "\\": r"\textbackslash{}", - "&": r"\&", - "%": r"\%", - "$": r"\$", - "#": r"\#", - "_": r"\_", - "{": r"\{", - "}": r"\}", - "~": r"\textasciitilde{}", - "^": r"\textasciicircum{}", - } - return "".join(replacements.get(character, character) for character in value) - - -def _environment_tex(environment: Mapping[str, str]) -> str: - toolchain = ( - "pending an authenticated post-checkpoint build" - if environment["status"] == "pending_exact_runtime" - else ( - f"{environment['python_implementation']} " - f"{environment['python']}; pyAmpliCol {environment['pyamplicol']}; " - f"NumPy {environment['numpy']}; native {environment['native_target']}" - ) - ) - return ( - "% SPDX-License-Identifier: 0BSD\n" - "% Generated architecture-profile metadata; do not edit by hand.\n" - rf"\renewcommand{{\ReportProfileName}}{{" - f"{_tex_escape(environment['profile'])}}}\n" - rf"\renewcommand{{\ReportPlatformSummary}}{{" - f"{_tex_escape(environment['platform'])}}}\n" - rf"\renewcommand{{\ReportToolchainSummary}}{{" - f"{_tex_escape(toolchain)}}}\n" - "\\renewcommand{\\ReportEditionStatement}{" - "This document is an architecture-specific edition.}\n" - ) - - -def _stable_environment_identity( - environment: Mapping[str, str], -) -> dict[str, str]: - """Project an environment onto measurement-relevant identity fields. - - ``processor`` is a display-only label. On macOS it normally comes from - ``sysctl`` but falls back to :func:`platform.processor` when sandbox policy - denies that query. Validate and remove only that canonical Darwin display - suffix; non-Darwin processor labels and every system/release, machine, - Python, source, candidate, native, and package identity remain exact. - """ - - platform_summary = _required_text( - environment.get("platform"), - "profile environment platform summary", - ) - machine = _required_text( - environment.get("machine"), - "profile environment machine", - ) - processor = environment.get("processor") - if not isinstance(processor, str): - raise ReportWorkspaceError( - "profile environment processor label must be a string" - ) - - canonical_platform = platform_summary - if processor and processor.casefold() != machine.casefold(): - processor_suffix = f"; {processor}" - if not canonical_platform.endswith(processor_suffix): - raise ReportWorkspaceError( - "profile environment platform summary does not match its " - "processor label" - ) - canonical_platform = canonical_platform[: -len(processor_suffix)] - - machine_suffix = f"; {machine}" - if ( - not canonical_platform.endswith(machine_suffix) - or not canonical_platform[: -len(machine_suffix)].strip() - ): - raise ReportWorkspaceError( - "profile environment platform summary does not identify its " - "system, release, and machine" - ) - - identity = dict(environment) - system_release = canonical_platform[: -len(machine_suffix)].strip() - system, separator, release = system_release.partition(" ") - if not separator or not system or not release.strip(): - raise ReportWorkspaceError( - "profile environment platform summary does not identify separate " - "system and release values" - ) - if system == "Darwin": - identity["platform"] = canonical_platform - identity.pop("processor", None) - return identity - - -def _workspace_manifest( - repo_root: Path, - *, - profile: str, - source_profile: str | None, - reset_measurements: bool, - environment: Mapping[str, str], - policy: CampaignPolicy, -) -> dict[str, object]: - paths = ReportPaths.from_repo(repo_root, profile=profile) - try: - source = inspect_report_source(repo_root) - source_record: dict[str, object] = { - "schema": SOURCE_IDENTITY_SCHEMA, - "revision": source.revision, - "tree": source.tree, - "clean": source.eligible, - "dirty_paths": list(source.dirty_paths), - } - except ReportSourceIdentityError: - source_record = { - "schema": SOURCE_IDENTITY_SCHEMA, - "revision": "unknown", - "tree": "unknown", - "clean": False, - "dirty_paths": [], - } - return { - "schema": WORKSPACE_SCHEMA, - "profile": profile, - "report_source_revision": source_record["revision"], - "report_source_tree": source_record["tree"], - "initialized_source_identity": source_record, - "initialized_from": ( - CANONICAL_REPORT_ROOT.as_posix() - if source_profile is None - else f"docs/performance_reports/{source_profile}" - ), - "measurement_state": "reset" if reset_measurements else "copied", - "campaign_policy": policy.as_manifest(), - "document": "pyAmpliCol.tex", - "environment_json": ENVIRONMENT_JSON, - "environment_tex": ENVIRONMENT_TEX, - "initialized_environment": dict(environment), - "measurement_environment_contract": ( - "refresh generated environment JSON/TeX after the exact-source " - "clean build and before population" - ), - "raw_results": "results", - "artifact_root": paths.artifact_root.relative_to(repo_root).as_posix(), - "coordination_root": paths.coordination_root.relative_to(repo_root).as_posix(), - "tracked_content": [ - "*.tex", - ENVIRONMENT_JSON, - MEASUREMENT_LINEAGE_JSON, - "results/*.json", - "README.md", - TABLE_FILLING_RUNBOOK, - WORKSPACE_MANIFEST, - STANDALONE_BUILDER, - "result_tables.py", - "pyAmpliCol.pdf (when compiled and reviewed)", - ], - "excluded_content": [ - ".artifacts evaluator attempts", - "worker logs", - "locks and coordination state", - "LaTeX auxiliary files", - ], - } - - -def initialize_profile( - repo_root: Path, - profile: str, - *, - source_profile: str | None = None, - reset_measurements: bool = False, - measurement_policy: str | None = None, - require_source_audit: bool = True, -) -> Path: - """Create a new tracked report profile atomically. - - The destination must not already exist. ``reset_measurements`` rebuilds the - caches and generated table inputs from the catalog and never carries a PDF - from the source profile. - """ - - root = repo_root.expanduser().resolve(strict=False) - validated = validate_profile_name(profile) - policy = ( - default_campaign_policy(validated) - if measurement_policy is None - else campaign_policy(measurement_policy) - ) - validate_policy_profile(policy, validated) - if source_profile is not None: - source_profile = validate_profile_name(source_profile) - if source_profile == validated: - raise ValueError("source and destination report profiles must differ") - source = _source_docs_dir(root, source_profile=source_profile) - target = profile_docs_dir(root, validated) - if target.exists(): - raise ReportWorkspaceError(f"report profile already exists: {target}") - - parent = target.parent - parent.mkdir(parents=True, exist_ok=True) - staging = parent / f".{validated}.init-{uuid.uuid4().hex}" - state_root = ( - root / ".artifacts" / "performance-report-workspace-init" / uuid.uuid4().hex - ) - try: - source_paths = ReportPaths.from_repo(root, profile=source_profile) - source_service = ReportService(source_paths) - with source_service.store.named_lock("report-writer"): - source_lineage = source / MEASUREMENT_LINEAGE_JSON - if source_lineage.exists() and not reset_measurements: - raise ReportWorkspaceError( - "a profile with mixed Class-C source lineage can only seed a " - "new profile with reset_measurements=True" - ) - if require_source_audit: - source_service.audit() - _copy_publication_members(source, staging) - _install_standalone_builder(staging) - target_paths = ReportPaths.from_repo(root, profile=validated) - if reset_measurements and ( - target_paths.artifact_root.exists() - and any(target_paths.artifact_root.iterdir()) - ): - raise ReportWorkspaceError( - "reset profile artifact root already contains local state: " - f"{target_paths.artifact_root}" - ) - paths = ReportPaths.from_repo( - root, - docs_dir=staging, - artifact_root=( - target_paths.artifact_root - if reset_measurements - else source_paths.artifact_root - ), - coordination_root=state_root / "coordination", - ) - service = ReportService(paths) - if reset_measurements: - service.publish(reset=True, merge_artifacts=False) - else: - service.publish(reset=False, merge_artifacts=False) - service.audit() - _assert_portable_results(staging) - - environment = _pending_environment_payload(validated) - (staging / ENVIRONMENT_JSON).write_text( - _canonical_json(environment), - encoding="ascii", - ) - (staging / ENVIRONMENT_TEX).write_text( - _environment_tex(environment), - encoding="utf-8", - ) - (staging / "README.md").write_text( - _workspace_readme(validated, policy), - encoding="utf-8", - ) - (staging / TABLE_FILLING_RUNBOOK).write_text( - _table_filling_runbook(validated, policy), - encoding="utf-8", - ) - manifest = _workspace_manifest( - root, - profile=validated, - source_profile=source_profile, - reset_measurements=reset_measurements, - environment=environment, - policy=policy, - ) - (staging / WORKSPACE_MANIFEST).write_text( - _canonical_json(manifest), - encoding="ascii", - ) - staging.replace(target) - except BaseException: - shutil.rmtree(staging, ignore_errors=True) - raise - finally: - shutil.rmtree(state_root, ignore_errors=True) - return target - - -def _read_environment_payload(path: Path) -> dict[str, str]: - try: - raw = json.loads(path.read_text(encoding="ascii")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise ReportWorkspaceError( - f"invalid or missing report environment metadata: {path}" - ) from error - required = { - "schema", - "profile", - "status", - "source_revision", - "platform", - "machine", - "processor", - "python", - "python_implementation", - "pyamplicol", - "numpy", - "native_target", - "native_cpu_features", - "native_build_inputs_sha256", - "native_extension_sha256", - "python_package_tree_sha256", - "candidate_fingerprint", - } - if ( - not isinstance(raw, dict) - or set(raw) != required - or not all(isinstance(value, str) for value in raw.values()) - ): - raise ReportWorkspaceError( - f"report environment metadata has an invalid shape: {path}" - ) - return raw - - -def record_authenticated_profile_environment( - docs_dir: Path, - profile: str, - *, - expected_source_revision: str, - active_runtime: Mapping[str, object], - host_environment: Mapping[str, object] | None = None, -) -> dict[str, str]: - """Record one already-authenticated runtime in an explicit report directory. - - This is the destination-explicit write boundary shared by source-checkout - profiles and portable campaign publication. It deliberately does not - authenticate ``active_runtime`` itself: callers must either use - :func:`refresh_profile_environment` or supply runtime evidence already - validated as part of a successful campaign measurement. - """ - - validated = validate_profile_name(profile) - if _GIT_SHA_RE.fullmatch(expected_source_revision) is None: - raise ReportWorkspaceError( - "profile environment source revision must be a full Git SHA" - ) - destination = docs_dir.expanduser().resolve(strict=True) - if not destination.is_dir(): - raise ReportWorkspaceError( - f"profile environment destination is not a directory: {destination}" - ) - environment = _authenticated_environment_payload( - validated, - expected_source_revision=expected_source_revision, - active_runtime=active_runtime, - host_environment=host_environment, - ) - json_path = destination / ENVIRONMENT_JSON - tex_path = destination / ENVIRONMENT_TEX - temporary_json = json_path.with_name(f".{json_path.name}.{uuid.uuid4().hex}") - temporary_tex = tex_path.with_name(f".{tex_path.name}.{uuid.uuid4().hex}") - expected_tex = _environment_tex(environment) - try: - temporary_json.write_text(_canonical_json(environment), encoding="ascii") - temporary_tex.write_text(expected_tex, encoding="utf-8") - temporary_json.replace(json_path) - temporary_tex.replace(tex_path) - finally: - temporary_json.unlink(missing_ok=True) - temporary_tex.unlink(missing_ok=True) - recorded = _read_environment_payload(json_path) - try: - recorded_tex = tex_path.read_text(encoding="utf-8") - except OSError as error: - raise ReportWorkspaceError( - f"profile environment TeX is unavailable: {tex_path}" - ) from error - if recorded != environment or recorded_tex != expected_tex: - raise ReportWorkspaceError( - "recorded profile environment differs from its authenticated payload" - ) - return recorded - - -def require_authenticated_profile_environment( - repo_root: Path, - profile: str, - *, - expected_source_revision: str, -) -> dict[str, str]: - """Require exact-source runtime metadata before profile measurement.""" - - validated = validate_profile_name(profile) - if _GIT_SHA_RE.fullmatch(expected_source_revision) is None: - raise ReportWorkspaceError( - "profile environment source revision must be a full Git SHA" - ) - path = profile_docs_dir(repo_root, validated) - environment = _read_environment_payload(path / ENVIRONMENT_JSON) - if ( - environment["schema"] != ENVIRONMENT_SCHEMA - or environment["profile"] != validated - or environment["status"] != "authenticated" - or environment["source_revision"] != expected_source_revision - ): - raise ReportWorkspaceError( - "profile environment is not authenticated for measurement source " - f"{expected_source_revision}; run refresh-profile-environment after " - "the exact-source clean build" - ) - expected_tex = _environment_tex(environment) - try: - observed_tex = (path / ENVIRONMENT_TEX).read_text(encoding="utf-8") - except OSError as error: - raise ReportWorkspaceError( - f"profile environment TeX is unavailable: {path / ENVIRONMENT_TEX}" - ) from error - if observed_tex != expected_tex: - raise ReportWorkspaceError( - "profile environment JSON and generated TeX do not match" - ) - return environment - - -def refresh_profile_environment( - repo_root: Path, - profile: str, - *, - expected_source_revision: str, - runtime_auditor: Callable[[str, Path], Mapping[str, object]] | None = None, - _skip_workspace_validation: bool = False, -) -> dict[str, str]: - """Authenticate and record the exact installed measurement runtime.""" - - root = repo_root.expanduser().resolve(strict=False) - validated = validate_profile_name(profile) - if _GIT_SHA_RE.fullmatch(expected_source_revision) is None: - raise ReportWorkspaceError( - "profile environment source revision must be a full Git SHA" - ) - if not _skip_workspace_validation: - _validate_workspace(root, validated) - source = inspect_report_source(root) - if not source.eligible or source.revision != expected_source_revision: - raise ReportWorkspaceError( - "profile environment refresh requires a clean evaluator source " - "checkout at the requested full Git SHA" - ) - if runtime_auditor is None: - from .final_audit import _audit_active_runtime - - runtime_auditor = _audit_active_runtime - try: - active_runtime = runtime_auditor(expected_source_revision, root) - except Exception as error: - raise ReportWorkspaceError( - "installed pyAmpliCol runtime is not authenticated for the " - "requested measurement source" - ) from error - profile_dir = profile_docs_dir(root, validated) - record_authenticated_profile_environment( - profile_dir, - validated, - expected_source_revision=expected_source_revision, - active_runtime=active_runtime, - ) - return require_authenticated_profile_environment( - root, - validated, - expected_source_revision=expected_source_revision, - ) - - -def require_active_profile_environment( - repo_root: Path, - profile: str, - *, - expected_source_revision: str, - runtime_auditor: Callable[[str, Path], Mapping[str, object]] | None = None, -) -> dict[str, str]: - """Require recorded metadata to equal the currently active exact runtime.""" - - root = repo_root.expanduser().resolve(strict=False) - validated = validate_profile_name(profile) - recorded = require_authenticated_profile_environment( - root, - validated, - expected_source_revision=expected_source_revision, - ) - if runtime_auditor is None: - from .final_audit import _audit_active_runtime - - runtime_auditor = _audit_active_runtime - try: - active_runtime = runtime_auditor(expected_source_revision, root) - except Exception as error: - raise ReportWorkspaceError( - "active pyAmpliCol runtime is not authenticated for the requested " - "measurement source" - ) from error - active = _authenticated_environment_payload( - validated, - expected_source_revision=expected_source_revision, - active_runtime=active_runtime, - ) - if _stable_environment_identity(active) != _stable_environment_identity(recorded): - raise ReportWorkspaceError( - "active measurement runtime differs from the authenticated profile " - "environment; rerun refresh-profile-environment" - ) - return recorded - - -def _read_workspace_manifest(path: Path) -> dict[str, object]: - try: - raw = json.loads(path.read_text(encoding="ascii")) - except (OSError, UnicodeError, json.JSONDecodeError) as error: - raise ReportWorkspaceError( - f"invalid or missing report workspace manifest: {path}" - ) from error - if not isinstance(raw, dict): - raise ReportWorkspaceError( - f"report workspace manifest is not an object: {path}" - ) - return raw - - -def _committed_workspace_manifest( - repo_root: Path, - profile: str, - revision: str, -) -> dict[str, object]: - if _GIT_SHA_RE.fullmatch(revision) is None: - raise ReportWorkspaceError( - "workspace policy authentication requires a full Git SHA" - ) - relative = (PROFILE_PARENT / profile / WORKSPACE_MANIFEST).as_posix() - try: - completed = subprocess.run( - ("git", "show", f"{revision}:{relative}"), - cwd=repo_root, - check=False, - capture_output=True, - timeout=15, - ) - except (OSError, subprocess.SubprocessError) as error: - raise ReportWorkspaceError( - "cannot read measured-source workspace policy" - ) from error - if completed.returncode != 0: - detail = completed.stderr.decode("utf-8", errors="replace").strip() - raise ReportWorkspaceError( - "measured source does not contain the selected report workspace: " - f"{detail or f'exit {completed.returncode}'}" - ) - try: - raw = json.loads(completed.stdout.decode("ascii")) - except (UnicodeError, json.JSONDecodeError) as error: - raise ReportWorkspaceError( - "measured-source workspace manifest is malformed" - ) from error - if not isinstance(raw, dict): - raise ReportWorkspaceError( - "measured-source workspace manifest is not an object" - ) - return raw - - -def load_profile_campaign_policy( - repo_root: Path, - profile: str, - *, - expected_source_revision: str | None = None, -) -> CampaignPolicy: - """Load the canonical policy, optionally authenticating its measured SHA.""" - - root = repo_root.expanduser().resolve(strict=False) - validated = validate_profile_name(profile) - manifest = _read_workspace_manifest( - profile_docs_dir(root, validated) / WORKSPACE_MANIFEST - ) - if ( - manifest.get("schema") != WORKSPACE_SCHEMA - or manifest.get("profile") != validated - ): - raise ReportWorkspaceError( - f"workspace manifest does not identify profile {validated!r}" - ) - try: - policy = policy_from_manifest( - manifest.get("campaign_policy"), - profile=validated, - ) - except CampaignPolicyError as error: - raise ReportWorkspaceError(str(error)) from error - if expected_source_revision is not None: - committed = _committed_workspace_manifest( - root, - validated, - expected_source_revision, - ) - if ( - committed.get("schema") != WORKSPACE_SCHEMA - or committed.get("profile") != validated - or committed.get("campaign_policy") != manifest.get("campaign_policy") - ): - raise ReportWorkspaceError( - "active workspace campaign policy differs from the exact " - "measured-source commit" - ) - try: - committed_policy = policy_from_manifest( - committed.get("campaign_policy"), - profile=validated, - ) - except CampaignPolicyError as error: - raise ReportWorkspaceError(str(error)) from error - if committed_policy is not policy: - raise ReportWorkspaceError( - "workspace policy identity is not stable at measured source" - ) - return policy - - -def _validate_workspace( - repo_root: Path, - profile: str, - *, - service: ReportService | None = None, -) -> Path: - root = repo_root.expanduser().resolve(strict=False) - path = profile_docs_dir(root, profile) - manifest_path = path / WORKSPACE_MANIFEST - manifest = _read_workspace_manifest(manifest_path) - if ( - not isinstance(manifest, dict) - or manifest.get("schema") != WORKSPACE_SCHEMA - or manifest.get("profile") != profile - or manifest.get("environment_json") != ENVIRONMENT_JSON - or manifest.get("environment_tex") != ENVIRONMENT_TEX - ): - raise ReportWorkspaceError( - f"workspace manifest does not identify profile {profile!r}" - ) - if not (path / TABLE_FILLING_RUNBOOK).is_file(): - raise ReportWorkspaceError( - f"workspace table-filling runbook is missing: " - f"{path / TABLE_FILLING_RUNBOOK}" - ) - try: - policy_from_manifest(manifest.get("campaign_policy"), profile=profile) - except CampaignPolicyError as error: - raise ReportWorkspaceError(str(error)) from error - environment = _read_environment_payload(path / ENVIRONMENT_JSON) - if ( - environment["schema"] != ENVIRONMENT_SCHEMA - or environment["profile"] != profile - or environment["status"] not in {"pending_exact_runtime", "authenticated"} - or ( - environment["status"] == "pending_exact_runtime" - and environment["source_revision"] != "pending" - ) - or ( - environment["status"] == "authenticated" - and _GIT_SHA_RE.fullmatch(environment["source_revision"]) is None - ) - ): - raise ReportWorkspaceError( - f"workspace environment does not identify profile {profile!r}" - ) - try: - environment_tex = (path / ENVIRONMENT_TEX).read_text(encoding="utf-8") - except OSError as error: - raise ReportWorkspaceError( - f"invalid or missing workspace environment TeX: {path / ENVIRONMENT_TEX}" - ) from error - if environment_tex != _environment_tex(environment): - raise ReportWorkspaceError( - "workspace environment JSON and generated TeX do not match" - ) - active = service or ReportService(ReportPaths.from_repo(root, profile=profile)) - active.audit() - return path - - -def export_profile( - repo_root: Path, - profile: str, - destination: Path, - *, - include_pdf: bool = True, -) -> Path: - """Export publication inputs without evaluator artifacts or local state.""" - - root = repo_root.expanduser().resolve(strict=False) - validated = validate_profile_name(profile) - profile_paths = ReportPaths.from_repo(root, profile=validated) - source_service = ReportService(profile_paths) - target = destination.expanduser().resolve(strict=False) - if target.exists(): - raise ReportWorkspaceError(f"export destination already exists: {target}") - target.parent.mkdir(parents=True, exist_ok=True) - staging = target.parent / f".{target.name}.export-{uuid.uuid4().hex}" - state_root = ( - root / ".artifacts" / "performance-report-workspace-export" / uuid.uuid4().hex - ) - try: - with source_service.store.named_lock("report-writer"): - source = _validate_workspace( - root, - validated, - service=source_service, - ) - _copy_publication_members(source, staging) - _copy_measurement_lineage(source, staging) - for name in ( - "README.md", - TABLE_FILLING_RUNBOOK, - WORKSPACE_MANIFEST, - ): - shutil.copy2(source / name, staging / name) - _install_standalone_builder(staging) - service = ReportService( - ReportPaths.from_repo( - root, - docs_dir=staging, - artifact_root=profile_paths.artifact_root, - coordination_root=state_root, - ) - ) - service.publish(reset=False, merge_artifacts=False) - service.audit() - _assert_portable_results(staging) - if include_pdf: - compile_report(staging) - for suffix in ( - ".aux", - ".bbl", - ".bcf", - ".blg", - ".fdb_latexmk", - ".fls", - ".log", - ".out", - ".run.xml", - ".synctex.gz", - ".toc", - ): - (staging / f"pyAmpliCol{suffix}").unlink(missing_ok=True) - staging.replace(target) - except BaseException: - shutil.rmtree(staging, ignore_errors=True) - raise - finally: - shutil.rmtree(state_root, ignore_errors=True) - return target - - -__all__ = [ - "ENVIRONMENT_JSON", - "ENVIRONMENT_SCHEMA", - "ENVIRONMENT_TEX", - "PROFILE_PARENT", - "STANDALONE_BUILDER", - "TABLE_FILLING_RUNBOOK", - "WORKSPACE_MANIFEST", - "WORKSPACE_SCHEMA", - "ReportWorkspaceError", - "export_profile", - "initialize_profile", - "load_profile_campaign_policy", - "profile_docs_dir", - "record_authenticated_profile_environment", - "refresh_profile_environment", - "require_active_profile_environment", - "require_authenticated_profile_environment", -] diff --git a/pyamplicol/tools/release/test_deployment.py b/pyamplicol/tools/release/test_deployment.py index 3479f585b7..8e0347cb2b 100644 --- a/pyamplicol/tools/release/test_deployment.py +++ b/pyamplicol/tools/release/test_deployment.py @@ -108,9 +108,7 @@ from pathlib import Path import re import shutil -import subprocess import sys -import tempfile import urllib.parse expected = json.loads(os.environ["PYAMPLICOL_EXPECTED_DEPENDENCIES"]) @@ -151,63 +149,6 @@ or archive_info.get("hashes", {}).get("sha256") == expected_hash ), name -# Finish CLI children before this process imports Symbolica through pyamplicol. -# A live parent Symbolica session would consume the restricted thread allowance -# also needed by those children. -with tempfile.TemporaryDirectory(prefix="pyamplicol-profiling-campaign-") as raw: - campaign = Path(raw).resolve() / "campaign" - subprocess.run( - ( - sys.executable, - "-I", - "-m", - "pyamplicol", - "profiling-campaign", - "copy", - str(campaign), - "--force", - ), - check=True, - capture_output=True, - text=True, - ) - launcher = campaign / "steer_performance_campaign.py" - assert launcher.is_file() - assert not (campaign / "pyAmpliCol.pdf").exists() - dry_run_command = ( - sys.executable, - "-I", - str(launcher), - "run", - "--dry-run", - "--table", - "scalar_contact", - "--multiplicity", - "2", - "--generation-engine", - "compiled", - "--no-color", - ) - dry_run = subprocess.run( - dry_run_command, - check=False, - capture_output=True, - text=True, - ) - assert dry_run.returncode == 0, (dry_run.stdout, dry_run.stderr) - assert "compact retention (default)" in dry_run.stdout - retained_dry_run = subprocess.run( - (*dry_run_command, "--retain-workspaces"), - check=False, - capture_output=True, - text=True, - ) - assert retained_dry_run.returncode == 0, ( - retained_dry_run.stdout, - retained_dry_run.stderr, - ) - assert "full debug workspaces (--retain-workspaces)" in retained_dry_run.stdout - import pyamplicol import pyamplicol._rusticol from pyamplicol._sdk.config import load_sdk_info diff --git a/pyamplicol/umami_example/README.md b/pyamplicol/umami_example/README.md deleted file mode 100644 index b7764f4bc0..0000000000 --- a/pyamplicol/umami_example/README.md +++ /dev/null @@ -1,227 +0,0 @@ -# MadSpace integration through the generated UMAMI API - -This example generates `g g > g g g` in leading colour (LC) and full colour, -builds each generated UMAMI shared library, runs its linked C driver, compares -batched MadSpace evaluations with native pyAmpliCol, and performs a real partonic -integration with MadSpace and VEGAS. LC and full-colour integrals need not agree: -they are different colour approximations. - -`test_umami.py` and `test_integrate.py` are adapted from the examples by -R. Frederix and T. Vitos in the -[AmpliCol `madspace_interface` branch](https://github.com/rikkert-frederix/AmpliCol/tree/madspace_interface): -[loading example](https://github.com/rikkert-frederix/AmpliCol/blob/madspace_interface/test_umami.py) -and [integration example](https://github.com/rikkert-frederix/AmpliCol/blob/madspace_interface/test_integrate.py). -The loading example retains MadSpace's batched matrix-element calls; the -integration example retains the original seven-section layout, phase-space -mappings, differential cross section, per-channel VEGAS and optional MadNIS/PDF -workflow. - -The upstream `madspace_interface` branch contains no explicit license file or -license notice in these two scripts. Their attribution is retained, and this -repository does not assign them a new 0BSD license. The generated UMAMI header -has its own separate `UMAMI_LICENSE` notice. - -## Run the complete example - -Use an environment containing this version of pyAmpliCol, a C compiler and Make. -The following are optional example dependencies, not pyAmpliCol requirements: - -```sh -python -m pip install -r umami_example/requirements.txt -python umami_example/run.py -``` - -Generation uses recurrence JIT O2, one worker and one optimization core, with -numerical current-relation discovery explicitly disabled. Full colour uses the -configured default exact colour contraction (adjoint FFT). Both accuracies use -automatic symmetry grouping. - -The output is `.artifacts/umami-example/`. Artifact payloads are in `lc/` and -`full/`; compiled libraries and drivers are outside them in `build_lc/` and -`build_full/`. Each integration writes `integration_lc.json` or -`integration_full.json`, with a cross section in pb and statistical uncertainty. -Defaults are intentionally small: two VEGAS training iterations with 256 and 512 -points, then 2048 integration points **per independent channel**. These are -smoke demonstrations, not precision cross-section predictions. - -Existing artifacts are never overwritten. Continue using the saved artifacts -with `--reuse`, or choose another `--output`. For example: - -```sh -python umami_example/run.py --reuse --accuracy full --n 8192 --training 1024 2048 -``` - -If `rusticol-config` is not on `PATH`, pass -`--rusticol-config /absolute/path/to/rusticol-config`. It must belong to the same -pyAmpliCol installation as the generation/runtime environment. Its `--cflags` -and `--libs` supply the headers and native library to the generated Makefile. -The C driver links to the resulting UMAMI `.so`, not to a second copy of -Rusticol. The Makefile sets a relative runtime-library search path so the driver -and `.so` can be moved together. - -### Updating a checkout or stale environment - -`git pull` updates these example scripts, but does not update a non-editable -pyAmpliCol installation. `run.py` prints the active Python and UMAMI exporter -paths and rejects an obsolete exporter before loading the optional integration -dependencies. To inspect those paths without running the example: - -```sh -python -c "import sys; import pyamplicol.artifacts.umami as umami; print(sys.executable); print(umami.__file__)" -``` - -From a clean checkout of the current `umami` branch, use the repository's normal -contributor installation workflow to rebuild and reinstall it into `.venv`: - -```sh -just dev-install -.venv/bin/python -m pip install -r umami_example/requirements.txt -.venv/bin/python umami_example/run.py \ - --rusticol-config "$PWD/.venv/bin/rusticol-config" \ - --output .artifacts/umami-example-current -``` - -For Python-only development with an already matching native runtime staged by -`just dev-install`, run directly from the checkout without rebuilding Rusticol: - -```sh -env PYTHONPATH="$PWD/src" .venv/bin/python umami_example/run.py \ - --rusticol-config "$PWD/.venv/bin/rusticol-config" \ - --output .artifacts/umami-example-source -``` - -Run these commands from the repository root and choose a previously unused -`--output`, **without `--reuse`**, when replacing stale artifacts. An old exporter -with a `grouping` argument, or metadata retaining `grouping.mode` (such as -`"exact"`), predates the automatic-grouping contract. The examples reject that -metadata. Updating Python does not update existing artifacts: regenerate the -artifact and rebuild its matching `.so`. Editing JSON counts or multiplicities -cannot repair the provider tables compiled into an old library. The run reports -the actual channel, representative and physical-member counts from metadata. - -## Run the individual steps - -For an already generated artifact, use absolute paths (substitute your paths): - -```sh -make -C /path/to/artifact/API/umami BUILD_DIR=/path/to/build -/path/to/build/umami_driver /path/to/artifact -python umami_example/test_umami.py /path/to/artifact \ - --library /path/to/build/libumami.so -python umami_example/test_integrate.py /path/to/artifact/API/umami/metadata.json \ - --library /path/to/build/libumami.so --artifact /path/to/artifact \ - --no-pdf --vegas-only --n 8192 --training 1024 2048 -``` - -UMAMI's `param_card_path` argument is the **absolute artifact directory**, not a -parameter card. The artifact supplies the saved model parameters. The loading -test varies the declared αs parameter event by event when available and checks -the resulting matrix elements against native pyAmpliCol, including refreshed -dependent parameters. A sampled helicity label is informational: the returned -matrix element remains summed over the artifact's available helicities. -For complete LC coverage, the pointwise check expands the physical members and -their momentum mappings and checks that their sum reconstructs the native LC -total. Integration multiplicities are not pointwise factors. - -Mixed process sets can produce multiple fixed-metadata providers. Select one -explicitly using `--provider p0` (or another ID from the metadata index) and its -matching `libumami_p0.so`. Its standalone driver is `umami_driver_p0`. The -orchestrator generates a single-process artifact and therefore needs no provider -selection. - -## Integration options and assumptions - -The default integration is at fixed partonic centre-of-mass energy 1 TeV, with -no PDFs and no downloads. All outgoing legs have `pT > 30 GeV`, `|eta| < 6` and -pairwise `delta R > 0.4`. Masses come from provider metadata; there are no -built-in particle-category or mass tables. This scattering example requires two -massless incoming particles, matching MadSpace's `1/(2 s_hat)` flux; the UMAMI -provider itself has no such restriction. The integration script's `--sqrts`, -`--pt-min`, `--eta-max` and `--dr-min` options change these settings. All compact -UMAMI integrations assume permutation-invariant, flavour-blind cuts and -observables. The script therefore has no species-selective cut option, and its -programmatic cut builder rejects species selections. - -UMAMI automatically groups proven equivalent contributions with different -physical final-state flavours, and always groups integration orbits of identical -final-state PDGs, using oriented physical colour topology and permutations that -preserve the available helicity coverage. There is no additional reflection -quotient, equal PDF assumption or beam exchange. For complete LC coverage of `g g > g g g`, -24 physical colour contributions reduce to four representatives with -integration multiplicity six each. Full colour remains one contracted -contribution without an extra factorial multiplier. Equivalence comes from the -model expressions and generated computation, not equal parameter defaults or -Standard Model-specific particle rules. Unproved relations remain separate; -there is no grouping option. - -The integration script applies metadata multiplicities once, assuming cuts -invariant under the recorded permutations and blind to final-state flavour, -and does not sum alternative mappings of the same contribution. Arbitrary -labelled-leg or species-sensitive cuts, or pointwise sums, require expanding the -retained physical members and their momentum mappings; multiplying one -representative by its integration multiplicity is not a substitute. The compact -integration script does not implement such cuts. Physical incoming PDGs keep -their own PDF weights. - -For the optional neural-flow training, pass `--madnis --epochs 200` to -`test_integrate.py`. `--learn-discrete` also lets MadNIS learn the phase-space -mapping's discrete choices. The default is VEGAS only and one CPU thread. - -For hadronic integration, use `--pdf --sqrts 13000 --pdf-dir /path/to/PDF/set` -and `--pdfset NAME`. The directory must already contain `NAME.info` and -`NAME_0000.dat`; this example does not download PDF data. If `--pdf-dir` is -omitted, the optional `lhapdf` Python binding locates the installed set. A -provider must expose a model-declared αs parameter for this running-coupling -workflow. A fixed scale can be given with `--scale`; otherwise the original -example's dynamical scale is used. - -## Necessary adaptations from the AmpliCol examples - -- Load the generated library and artifact path, including explicit provider - selection, rather than a process-specific AmpliCol library and parameter card. -- Use current MadSpace call signatures, and derive masses, physical flavours, - colour orderings and contribution maps from the generated metadata. -- Bind `FunctionRuntime` explicitly to the one-thread context holding the - loaded provider; MadSpace 0.2.1's convenience calls use its global context. -- Construct MadSpace's matrix-element function with its explicit particle - count, avoiding the convenience overload's unconditional diagram-count query. - No diagrams are invented for the recursion-based provider. -- Integrate one representative per identical-final-particle LC orbit, with its - metadata multiplicity. Full colour is an already contracted result and is not - evaluated repeatedly as if it were separate colour flows. -- Retain Rusticol's incoming averages and identical-final-state factors exactly - once. MadSpace's differential cross section adds flux, phase-space weights, - optional PDFs and the conversion to pb. -- In the no-PDF workflow, use the artifact's default αs rather than requesting - running αs without a running-coupling object. -- Sum only independent metadata contributions, not alternative phase-space - maps without a partition of unity. -- Use bounded deterministic defaults, finite-result assertions, native numerical - comparisons, and machine-readable integration results. - Both Torch and VEGAS's independent NumPy generator are explicitly seeded. - -The standalone SDK and complete UMAMI conventions are documented in the -project's UMAMI API page and in the generated `API/umami/README.md`. - -## Optional grouping acceptance check - -```sh -python umami_example/test_grouping.py -``` - -This generates one automatically compacted provider for the much smaller LC -process `g g > g g` and reuses the same real MadSpace/VEGAS integration code. Its -cuts are symmetric in the outgoing legs (`pT > 100 GeV`, `|eta| < 6`, -`delta R > 0.4` at 1 TeV). The fixture must compact six physical colour -contributions into three representatives with integration multiplicity two. -The reference expands each retained member into a separate integration channel, -composes its momentum mapping with the representative's map, and uses only its -physical weight, not the integration multiplicity. The provider's representative -computations remain certified and unchanged. It compares the compact and -explicit-member integrals using independent, fixed-seed -estimates within six combined statistical standard errors, with each estimate's -relative error below 5%. This is -stochastic validation, not the authority establishing amplitude equivalences. -The default is 4096 points per channel after 256/512-point training. Estimates, -errors, counts and comparisons are retained in -`.artifacts/umami-grouping/grouping_comparison.json`; `--reuse` skips regeneration. diff --git a/pyamplicol/umami_example/_metadata.py b/pyamplicol/umami_example/_metadata.py deleted file mode 100644 index 677a77451f..0000000000 --- a/pyamplicol/umami_example/_metadata.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Small shared reader for the generated UMAMI example metadata.""" - -from __future__ import annotations - -import inspect -import json -import sys -from pathlib import Path - - -def require_current_exporter() -> Path: - """Reject the old selectable exporter before starting expensive generation.""" - from pyamplicol.artifacts import umami - - path = Path(umami.__file__).resolve() - if "grouping" in inspect.signature(umami.build_umami_metadata).parameters: - raise RuntimeError( - f"Outdated pyAmpliCol UMAMI exporter loaded by {sys.executable}: {path}. " - "Reinstall pyAmpliCol from the current umami branch in this Python " - "environment; git pull alone only updates the example scripts. " - "Then regenerate into a fresh --output without --reuse. " - "See umami_example/README.md for the source-checkout workflow." - ) - return path - - -def grouping_summary(data: dict) -> str: - """Describe the loaded tables, without claiming that a policy was applied.""" - entries = [entry for channel in data["channels"] for entry in channel["processes"]] - physical_count = sum(len(entry["members"]) for entry in entries) - return ( - f"{len(data['channels'])} integration channels, " - f"{len(entries)} representative contributions, " - f"{physical_count} physical contributions" - ) - - -def load_metadata(path: str | Path, provider: str | None = None) -> dict: - path = Path(path).resolve() - data = json.loads(path.read_text()) - if data.get("kind") == "pyamplicol-umami-provider-index": - choices = data["providers"] - selected = [item for item in choices if item["id"] == provider] - if len(selected) != 1: - names = ", ".join(item["id"] for item in choices) - raise ValueError(f"select one provider with --provider: {names}") - return load_metadata(path.parent / selected[0]["metadata"], provider) - if provider is not None and data["provider"]["id"] != provider: - raise ValueError(f"metadata does not describe provider {provider!r}") - if data["provider"]["incoming_count"] != 2: - raise ValueError("this scattering example requires two incoming particles") - grouping = data.get("grouping") - if ( - not isinstance(grouping, dict) - or "mode" in grouping - or not {"physical_contributions", "exported_contributions"} <= grouping.keys() - ): - raise ValueError( - f"Outdated or missing automatic-grouping metadata in {path}. " - "Reinstall pyAmpliCol from the current umami branch, then regenerate " - "into a fresh --output without --reuse. Rebuilding the .so alone " - "does not update metadata; do not edit channel counts by hand." - ) - return data diff --git a/pyamplicol/umami_example/requirements.txt b/pyamplicol/umami_example/requirements.txt deleted file mode 100644 index 0896f6a951..0000000000 --- a/pyamplicol/umami_example/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -# Optional demonstration dependencies; not pyAmpliCol runtime requirements. -madspace==0.2.1 -madnis==1.0.0 -vegas>=6.0 -torch>=2.4 -numpy>=1.26 diff --git a/pyamplicol/umami_example/run.py b/pyamplicol/umami_example/run.py deleted file mode 100644 index dd49e09184..0000000000 --- a/pyamplicol/umami_example/run.py +++ /dev/null @@ -1,150 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Generate gg -> ggg artifacts and run the standalone and MadSpace examples.""" - -from __future__ import annotations - -import argparse -import shutil -import subprocess -import sys -from pathlib import Path - -from _metadata import load_metadata, require_current_exporter - - -def generate(artifact: Path, accuracy: str, expression: str = "g g > g g g") -> None: - from pyamplicol import Generator, ModelSource - from pyamplicol.config import resolve_config - - config = resolve_config( - { - "schema_version": 1, - "action": "generate", - "color": {"accuracy": accuracy}, - "generation": { - "workers": 1, - "emit_api_bundle": True, - "relation_discovery": {"mode": "off"}, - }, - "evaluator": { - "backend": "jit", - "execution_mode": "recurrence", - "optimization": {"cores": 1}, - "jit": {"optimization_level": 2}, - }, - } - ) - Generator(config).generate(expression, artifact, model=ModelSource.built_in_sm()) - - -def execute(*command: object) -> None: - print("+ " + " ".join(str(part) for part in command), flush=True) - subprocess.run([str(part) for part in command], check=True) - - -def main() -> None: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--output", type=Path, default=Path(".artifacts/umami-example")) - parser.add_argument( - "--accuracy", choices=("lc", "full"), nargs="+", default=["lc", "full"] - ) - parser.add_argument( - "--reuse", action="store_true", help="reuse previously generated artifacts" - ) - parser.add_argument("--rusticol-config", default="rusticol-config") - parser.add_argument( - "--n", type=int, default=2048, help="integration points per channel" - ) - parser.add_argument("--training", type=int, nargs="+", default=[256, 512]) - parser.add_argument("--check-points", type=int, default=20) - parser.add_argument("--seed", type=int, default=12345) - args = parser.parse_args() - if min(args.n, *args.training) < 2 or args.check_points < 1: - parser.error( - "integration/training counts must be at least two; " - "check-points must be positive" - ) - exporter = require_current_exporter() - print(f"Python: {sys.executable}\nUMAMI exporter: {exporter}", flush=True) - directory = args.output.resolve() - accuracies = tuple(dict.fromkeys(args.accuracy)) - existing = {} - for accuracy in accuracies: - artifact = directory / accuracy - if artifact.exists(): - if not args.reuse: - parser.error( - f"{artifact} exists; choose another output or pass --reuse" - ) - # Reject stale reused metadata before dependencies, builds or profiling. - existing[accuracy] = load_metadata(artifact / "API/umami/metadata.json") - rusticol_config = shutil.which(args.rusticol_config) - if rusticol_config is None: - parser.error( - "activate pyAmpliCol's environment or provide " - "--rusticol-config /absolute/path" - ) - # Check optional integration dependencies before starting generation. - for module in ("madspace", "madnis", "vegas", "torch"): - __import__(module) - directory.mkdir(parents=True, exist_ok=True) - scripts = Path(__file__).resolve().parent - for accuracy in accuracies: - artifact = directory / accuracy - metadata = artifact / "API/umami/metadata.json" - if accuracy in existing: - data = existing[accuracy] - else: - generate(artifact, accuracy) - data = load_metadata(metadata) - if data["provider"]["color_accuracy"] != accuracy: - raise ValueError( - "existing artifact's colour accuracy differs from the request" - ) - build_dir = directory / f"build_{accuracy}" - execute( - "make", - "-C", - artifact / "API/umami", - f"BUILD_DIR={build_dir}", - f"RUSTICOL_CONFIG={rusticol_config}", - ) - library = build_dir / data["provider"]["library"] - execute(build_dir / "umami_driver", artifact) - execute( - sys.executable, - scripts / "test_umami.py", - artifact, - "--library", - library, - "--n", - args.check_points, - "--seed", - args.seed, - ) - execute( - sys.executable, - scripts / "test_integrate.py", - metadata, - "--library", - library, - "--artifact", - artifact, - "--no-pdf", - "--vegas-only", - "--n", - args.n, - "--training", - *args.training, - "--seed", - args.seed, - "--result", - directory / f"integration_{accuracy}.json", - ) - print( - f"Completed standalone, batched-parity and integration examples in {directory}" - ) - - -if __name__ == "__main__": - main() diff --git a/pyamplicol/umami_example/test_grouping.py b/pyamplicol/umami_example/test_grouping.py deleted file mode 100644 index e6976f34c4..0000000000 --- a/pyamplicol/umami_example/test_grouping.py +++ /dev/null @@ -1,244 +0,0 @@ -# SPDX-License-Identifier: 0BSD -"""Compare automatically grouped and explicit-member MadSpace integrals. - -This is stochastic validation of structurally established equivalences, not a -numerical proof of those equivalences. Run explicitly; no optional integration -packages are added to pyAmpliCol's ordinary test dependencies. -""" - -from __future__ import annotations - -import argparse -import json -import math -import shutil -import sys -from pathlib import Path - -import madspace as ms -import torch -from _metadata import require_current_exporter -from run import execute, generate -from test_integrate import Channel, Config, Cuts, integrate_per_channel, load_channels - -FIXTURES = { - # Process: (integration channels, physical colour contributions, orbit size). - "g g > g g": (3, 6, 2), - "g g > g g g": (4, 24, 6), -} - - -def check_identical_grouping(data, process): - """Require the automatic identical-particle quotient for a known fixture.""" - channel_count, physical_count, orbit_size = FIXTURES[process] - entries = [entry for ch in data["channels"] for entry in ch["processes"]] - if ( - len(data["channels"]) != channel_count - or len(entries) != channel_count - or data["grouping"]["exported_contributions"] != channel_count - or data["grouping"]["physical_contributions"] != physical_count - ): - raise AssertionError( - f"{process} must group {physical_count} physical contributions into " - f"{channel_count} automatic integration channels" - ) - factors = [] - for entry in entries: - terms = entry["matrix_elements"] - if ( - len(terms) != 1 - or float(terms[0]["factor"]) != orbit_size - or len(entry["members"]) != orbit_size - ): - raise AssertionError( - f"each {process} representative must have {orbit_size} physical " - f"members and explicit integration factor {orbit_size}" - ) - factors.append(float(terms[0]["factor"])) - return factors - - -def physical_member_channels(data): - """Expand physical weights and momentum maps, never integration factors. - - This is a reference integrand for the acceptance check, not an export option. - The provider still uses its certified representative computations. - """ - channels = [] - for ci, channel in enumerate(data["channels"]): - for fi, entry in enumerate(channel["processes"]): - for member in entry["members"]: - # p_rep[representative map] = p_physical[member map]. - permutation = [0] * data["provider"]["particle_count"] - for rep_slot, physical_slot in zip( - entry["runtime"]["permutation"], - member["runtime"]["permutation"], - strict=True, - ): - permutation[rep_slot] = physical_slot - pdgs = member["pdgs"] - channels.append( - Channel( - index=len(channels), - color_order=[ - permutation[slot] for slot in channel["phasespace_order"] - ], - init_states=[tuple(pdgs[:2])], - pdg_final=list(pdgs[2:]), - masses=list(data["provider"]["masses"]), - processes=[ - [ - ( - float(member["factor"]), - pdgs[0], - pdgs[1], - tuple(pdgs[2:]), - ) - ] - ], - selector=(ci, fi), - momentum_permutation=permutation, - ) - ) - return channels - - -def check_agreement(results, *, sigma=6.0, maximum_relative_error=0.05): - """Compare independent estimates, retaining their complete uncertainties.""" - for result in results.values(): - value, error = result["integral"], result["uncertainty"] - if not ( - math.isfinite(value) and value > 0 and math.isfinite(error) and error > 0 - ): - raise AssertionError("expected a positive finite integral and uncertainty") - if error > maximum_relative_error * value: - raise AssertionError( - "grouping comparison is inconclusive: increase --n to reduce " - "the integration uncertainty" - ) - reference = results["physical_members"] - result = results["grouped"] - difference = abs(result["integral"] - reference["integral"]) - uncertainty = math.hypot(result["uncertainty"], reference["uncertainty"]) - rounding = 1e-10 * max(result["integral"], reference["integral"]) - if difference > sigma * uncertainty + rounding: - raise AssertionError( - "grouped and physical-member integrals differ by " - f"{difference / uncertainty:.2f} combined standard errors (limit {sigma:g})" - ) - return { - "difference": difference, - "combined_error": uncertainty, - "standard_errors": difference / uncertainty, - } - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--output", type=Path, default=Path(".artifacts/umami-grouping") - ) - parser.add_argument( - "--process", - choices=tuple(FIXTURES), - default="g g > g g", - help="identical-gluon acceptance fixture (default: %(default)s)", - ) - parser.add_argument("--reuse", action="store_true") - parser.add_argument("--rusticol-config", default="rusticol-config") - parser.add_argument("--n", type=int, default=4096) - parser.add_argument("--training", type=int, nargs="+", default=[256, 512]) - parser.add_argument("--seed", type=int, default=24680) - args = parser.parse_args() - if min(args.n, *args.training) < 2: - parser.error("integration and training counts must be at least two") - exporter = require_current_exporter() - print(f"Python: {sys.executable}\nUMAMI exporter: {exporter}", flush=True) - config_binary = shutil.which(args.rusticol_config) - if config_binary is None: - parser.error("activate the pyAmpliCol environment or pass --rusticol-config") - output = args.output.resolve() - output.mkdir(parents=True, exist_ok=True) - torch.set_num_threads(1) - cfg = Config(sqrts=1000.0, cuts=Cuts(pt_min=100.0, eta_max=6.0, dr_min=0.4)) - artifact = output / "lc" - if artifact.exists(): - if not args.reuse: - parser.error(f"{artifact} already exists; use --reuse or another output") - else: - generate(artifact, "lc", args.process) - metadata = artifact / "API/umami/metadata.json" - grouped_channels, n_out, data = load_channels(metadata) - if data["provider"]["color_accuracy"] != "lc": - raise AssertionError("existing artifact is not a leading-colour provider") - integration_factors = check_identical_grouping(data, args.process) - member_channels = physical_member_channels(data) - if len(member_channels) != data["grouping"]["physical_contributions"]: - raise AssertionError("reference must contain every physical contribution once") - build = output / "build_lc" - execute( - "make", - "-C", - artifact / "API/umami", - f"BUILD_DIR={build}", - f"RUSTICOL_CONFIG={config_binary}", - ) - library = build / data["provider"]["library"] - execute( - sys.executable, - Path(__file__).with_name("test_umami.py"), - artifact, - "--library", - library, - "--n", - 4, - "--seed", - args.seed, - ) - results = {} - for index, (label, channels) in enumerate( - (("grouped", grouped_channels), ("physical_members", member_channels)) - ): - # Distinct fixed seeds make the quadrature combination of errors valid. - seed = args.seed + index * 100_003 - value, error, per_channel = integrate_per_channel( - channels, - n_out, - cfg, - ms.Context(1), - library, - artifact, - n_points=args.n, - seed=seed, - training_points=args.training, - ) - results[label] = { - "integral": value, - "uncertainty": error, - "unit": "pb", - "seed": seed, - "points_per_channel": args.n, - "per_channel": per_channel, - "integration_channels": len(channels), - } - print(f"{label}: {value:.8g} +/- {error:.3g} pb", flush=True) - summary = { - "process": args.process, - "cuts": vars(cfg.cuts), - "grouping": data["grouping"], - "integration_factors": integration_factors, - "results": results, - } - report = output / "grouping_comparison.json" - # Retain estimates even if the statistical acceptance fails. - report.write_text(json.dumps(summary, indent=2, allow_nan=False) + "\n") - summary["comparison"] = check_agreement(results) - summary["accepted"] = True - report.write_text(json.dumps(summary, indent=2, allow_nan=False) + "\n") - print( - f"Grouped/member integrals agree within six combined standard errors: {report}" - ) - - -if __name__ == "__main__": - main() diff --git a/pyamplicol/umami_example/test_integrate.py b/pyamplicol/umami_example/test_integrate.py deleted file mode 100644 index 31b8705f4b..0000000000 --- a/pyamplicol/umami_example/test_integrate.py +++ /dev/null @@ -1,501 +0,0 @@ -"""Integrate a generated UMAMI provider with MadSpace and VEGAS/MadNIS. - -Adapted from R. Frederix and T. Vitos's AmpliCol madspace_interface example: -https://github.com/rikkert-frederix/AmpliCol/blob/madspace_interface/test_integrate.py -Its seven-section structure, channel integration and optional MadNIS/PDF workflow -are retained. README.md describes the pyAmpliCol and current-MadSpace adaptations. -""" - -from __future__ import annotations - -import argparse -import json -import math -import time -from dataclasses import dataclass, field -from pathlib import Path - -import madspace as ms -import numpy as np -import torch -import torch.nn as nn -from _metadata import grouping_summary, load_metadata - - -# ============================================================================= -# 1. Config / cuts -# ============================================================================= -@dataclass -class Cuts: - pt_min: float = 30.0 - eta_max: float = 6.0 - dr_min: float = 0.4 - # None means all outgoing species; no built-in particle classification. - pdgs: list[int] | None = None - - -@dataclass -class Config: - sqrts: float = 1000.0 - pdfset: str = "NNPDF23_nlo_as_0119_qed" - pdf_dir: Path | None = None - scale_ref: float | None = None - t_invariant_power: float = 0.3 - cuts: Cuts = field(default_factory=Cuts) - - -# ============================================================================= -# 2. Channel loader (generated converted metadata) -# ============================================================================= -@dataclass -class Channel: - index: int - color_order: list[int] - init_states: list[tuple[int, int]] - pdg_final: list[int] - masses: list[float] - processes: list[list[tuple[float, int, int, tuple]]] = field(default_factory=list) - # Explicit-member validation can evaluate a mapped exported representative. - selector: tuple[int, int] | None = None - momentum_permutation: list[int] | None = None - - -def load_channels(path, provider=None): - data = load_metadata(path, provider) - if any(mass != 0.0 for mass in data["provider"]["masses"][:2]): - raise ValueError( - "this MadSpace scattering example uses massless-beam flux; " - "massive incoming particles require a different flux prescription" - ) - channels = [] - for ci, ch in enumerate(data["channels"]): - inits, finals, procs = set(), [], [] - for proc in ch["processes"]: - partners = proc.get("multichannels", [ci]) - if partners != [ci]: - raise ValueError( - "this example requires one nonduplicated map per contribution" - ) - cfgs = [] - for me in proc["matrix_elements"]: - pdg = list(data["pdg_ids"][me["pdg_ids"]]) - factor = float(me["factor"]) - cfgs.append((factor, pdg[0], pdg[1], tuple(pdg[2:]))) - inits.add((pdg[0], pdg[1])) - if not finals: - finals = pdg[2:] - procs.append(cfgs) - channels.append( - Channel( - ci, - list(ch["phasespace_order"]), - sorted(inits), - finals, - list(data["provider"]["masses"]), - procs, - ) - ) - return channels, data["provider"]["particle_count"] - 2, data - - -# ============================================================================= -# 3. Cuts -> ms.Cuts (applied INSIDE PhaseSpaceMapping) -# ============================================================================= -def build_ms_cuts(cfg: Config, ch: Channel): - c = cfg.cuts - if c.pdgs is not None: - raise ValueError("automatic UMAMI grouping requires flavour-blind cuts") - a, b = ch.init_states[0] - pids = [a, b, *ch.pdg_final] - selected = sorted(set(ch.pdg_final)) - obs_type = ms.Observable - items = [] - - def add(obs, **kwargs): - items.append(ms.CutItem(obs_type(pids, obs, [selected]), **kwargs)) - - if c.pt_min > 0: - add(obs_type.obs_pt, min=c.pt_min) - if c.eta_max > 0: - add(obs_type.obs_eta_abs, max=c.eta_max) - if c.dr_min > 0: - add(obs_type.obs_delta_r, min=c.dr_min) - return ms.Cuts(items) if items else None - - -# ============================================================================= -# 4. PDFs & alpha_s + matrix element (MadSpace primitives, train.py style) -# ============================================================================= -def load_pdf_and_coupling(cfg: Config, ctx): - if cfg.pdf_dir is None: - import lhapdf - - lhapdf.setVerbosity(0) - candidates = [Path(directory) / cfg.pdfset for directory in lhapdf.paths()] - base = next((path for path in candidates if path.is_dir()), None) - if base is None: - raise FileNotFoundError(f"PDF set {cfg.pdfset!r} is not installed") - else: - base = cfg.pdf_dir - pdf_grid = ms.PdfGrid(str(base / f"{cfg.pdfset}_0000.dat")) - pdf_grid.initialize_globals(ctx) - ag = ms.AlphaSGrid(str(base / f"{cfg.pdfset}.info")) - run_coupl = ms.RunningCoupling(ag) - ag.initialize_globals(ctx) - return pdf_grid, run_coupl - - -def load_matrix_element(ctx, library, artifact, use_running_alpha_s=False): - api = ctx.load_matrix_element( - str(Path(library).resolve()), str(Path(artifact).resolve()) - ) - inputs = [ms.MatrixElement.momenta_in] - # No-PDF default deliberately omits alpha_s: UMAMI uses artifact defaults. - if use_running_alpha_s: - inputs.append(ms.MatrixElement.alpha_s_in) - inputs += [ - ms.MatrixElement.flavor_in, - ms.MatrixElement.channel_in, - ms.MatrixElement.random_helicity_in, - ] - # Avoid the convenience overload's unconditional diagram-count query. - # No diagram output is requested or represented by this provider. - return ms.MatrixElement( - api.index(), - api.particle_count(), - inputs, - [ms.MatrixElement.matrix_element_out, ms.MatrixElement.helicity_index_out], - diagram_count=0, - ) - - -# ============================================================================= -# 5. One color-ordered channel: randoms -> weight -# ============================================================================= -class ColorOrderedChannel: - """One independent additive contribution, with an optional PDF convolution.""" - - def __init__( - self, - ch: Channel, - n_out, - cfg: Config, - ctx, - me_func=None, - run_coupl=None, - pdf_grid=None, - ): - self.ch, self.cfg, self.ctx = ch, cfg, ctx - self.psmap = ms.PhaseSpaceMapping( - ch.masses, - cfg.sqrts, - leptonic=pdf_grid is None, - invariant_power=cfg.t_invariant_power, - mode=ms.PhaseSpaceMapping.color_ordered, - color_order=ch.color_order, - cuts=build_ms_cuts(cfg, ch), - ) - self.random_dim = self.psmap.random_dim() - self.discrete_dim = self.psmap.discrete_dim() - self.dim = self.random_dim - self.ps_runtime = ms.FunctionRuntime(self.psmap.forward_function(), ctx) - self.cfg_proc, self.cfg_factor, pid_options = [], [], [] - for iproc, cfgs in enumerate(ch.processes): - for fac, a, b, final in cfgs: - self.cfg_proc.append(iproc if ch.selector is None else ch.selector[1]) - self.cfg_factor.append(fac) - pid_options.append([a, b, *final]) - self.n_config = len(pid_options) - self.dcs = None - if me_func is not None: - escale = None - if run_coupl is not None: - escale = ms.EnergyScale( - 2 + n_out, - ms.EnergyScale.half_transverse_mass - if cfg.scale_ref is None - else float(cfg.scale_ref), - ) - # UMAMI already supplies spin/colour averaging and identical-particle - # normalization; DCS adds only flux, optional PDFs and the pb conversion. - self.dcs = ms.DifferentialCrossSection( - me_func, - cfg.sqrts, - run_coupl, - escale, - pid_options, - pdf_grid, - pdf_grid, - True, - False, - ) - self.dcs_runtime = ms.FunctionRuntime(self.dcs.function(), ctx) - - def weight(self, r, disc=None): - """Keep upstream's ownership of discrete phase-space branch weights.""" - dev, dt = r.device, r.dtype - mult = 1.0 - if self.discrete_dim: - if disc is None: - disc = torch.randint( - 0, 2, (r.shape[0], self.discrete_dim), device=dev, dtype=torch.int32 - ) - mult = float(2**self.discrete_dim) - else: - disc = disc.to(torch.int32) - inputs = [r, disc] - else: - inputs = [r] - p, x1, x2, det = self.ps_runtime(*inputs) - good = torch.isfinite(det) & (det > 0) - out = torch.zeros(r.shape[0], dtype=det.dtype, device=dev) - if self.dcs is None: - return torch.where(good, det * mult, out) - if not bool(good.any()): - return out - # Fixed partonic energy returns singleton x1/x2; broadcast before masking. - x1, x2 = x1.expand(r.shape[0]), x2.expand(r.shape[0]) - pg, x1g, x2g, detg = p[good], x1[good], x2[good], det[good] - ng = len(detg) - if self.ch.momentum_permutation is not None: - pg = pg[:, self.ch.momentum_permutation, :] - selector_channel = ( - self.ch.index if self.ch.selector is None else self.ch.selector[0] - ) - chan_id = torch.full((ng,), selector_channel, device=dev, dtype=torch.int32) - total = torch.zeros(ng, dtype=detg.dtype, device=dev) - for c in range(self.n_config): - flavor = torch.full((ng,), self.cfg_proc[c], device=dev, dtype=torch.int32) - pdf_id = torch.full((ng,), c, device=dev, dtype=torch.int32) - rnd_hel = torch.rand(ng, device=dev, dtype=dt) - res = self.dcs_runtime( - pg.contiguous(), - flavor, - chan_id, - rnd_hel, - x1g, - x2g, - pdf_id, - ) - dxs = res[0] if isinstance(res, (tuple, list)) else res - if not bool(torch.isfinite(dxs).all()): - raise FloatingPointError("nonfinite UMAMI differential cross section") - total = total + dxs * self.cfg_factor[c] - out[good] = total * detg * mult - return out - - -# ============================================================================= -# 6. Per-ordering integration: one independent integrator per colour ordering -# ============================================================================= -def integrate_per_channel( - channels, - n_out, - cfg, - ctx, - me_library=None, - param_card="", - use_pdf=False, - batch_size=256, - epochs=200, - n_points=2048, - seed=0, - vegas_only=True, - learn_discrete=False, - training_points=(256, 512), -): - from madnis.integrator import ( - Integrand, - Integrator, - VegasPreTraining, - stratified_variance_softclip, - ) - - torch.set_default_dtype(torch.float64) - torch.manual_seed(seed) - me_func = ( - None - if me_library is None - else load_matrix_element( - ctx, me_library, param_card, use_running_alpha_s=use_pdf - ) - ) - pdf_grid = run_coupl = None - if use_pdf and me_func is not None: - pdf_grid, run_coupl = load_pdf_and_coupling(cfg, ctx) - - results = [] - total, var = 0.0, 0.0 - for c in channels: - ch = ColorOrderedChannel(c, n_out, cfg, ctx, me_func, run_coupl, pdf_grid) - dd = ch.discrete_dim - if learn_discrete and dd: - - def fn(x, ch=ch, nd=dd): - return ch.weight( - x[:, nd:].contiguous().double(), disc=x[:, :nd] - ).double() - - integrand = Integrand( - fn, input_dim=ch.random_dim + dd, discrete_dims=[2] * dd - ) - else: - - def fn(x, ch=ch): - return ch.weight(x.double()).double() - - integrand = Integrand(fn, input_dim=ch.dim) - - def vegas_callback(status, channel_index=c.index): - print( - f"[VEGAS channel {channel_index}] Iteration {status.step + 1}: " - f"loss={status.variance:.6f}", - flush=True, - ) - - def callback(status): - if (status.step + 1) % max(1, epochs // 10) == 0: - print( - f"[MadNIS] Iteration {status.step + 1:4d}: loss={status.loss:.6f}" - ) - - flow_dict = dict(layers=3, units=64, bins=10, activation=nn.LeakyReLU) - integrator = Integrator( - integrand, - flow_kwargs=flow_dict, - batch_size=batch_size, - dtype=torch.float64, - optimizer=lambda p: torch.optim.Adam(p, lr=1e-3), - scheduler=lambda o: torch.optim.lr_scheduler.CosineAnnealingLR( - o, T_max=epochs - ), - loss=stratified_variance_softclip, - ) - vegas = VegasPreTraining(integrator, bins=16, damping=0.7) - # MadNIS gives VEGAS its own NumPy generator, independent of Torch's RNG. - vegas.rng = np.random.default_rng(np.random.SeedSequence([seed, c.index])) - vegas.train(list(training_points), callback=vegas_callback) - if vegas_only: - Ii, ei = vegas.integrate(n_points) - else: - vegas.initialize_integrator() - integrator.train(epochs, callback=callback) - Ii, ei = integrator.integrate(n_points) - if not (math.isfinite(Ii) and math.isfinite(ei) and ei >= 0): - raise FloatingPointError( - "integration returned invalid estimate/uncertainty" - ) - rsd = (ei / Ii) * math.sqrt(n_points) if Ii else None - results.append((c.index, c.color_order, Ii, ei, rsd)) - total += Ii - var += ei * ei - rsd_text = f"{rsd:.3f}" if rsd is not None else "undefined (zero integral)" - print( - f"[channel {c.index}] color_order={c.color_order}: " - f"{Ii:.6e} +/- {ei:.2e} RSD={rsd_text}", - flush=True, - ) - return total, math.sqrt(var), results - - -# ============================================================================= -# 7. CLI -# ============================================================================= -def main(): - ap = argparse.ArgumentParser(description=__doc__) - ap.add_argument("json", type=Path) - ap.add_argument("--library", type=Path, required=True) - ap.add_argument( - "--param-card", "--artifact", dest="artifact", type=Path, required=True - ) - ap.add_argument("--provider") - ap.add_argument( - "--pdf", action="store_true", help="optional hadronic run; needs PDF data" - ) - ap.add_argument("--no-pdf", dest="pdf", action="store_false") - ap.add_argument("--pdfset", default=Config.pdfset) - ap.add_argument("--pdf-dir", type=Path) - ap.add_argument("--sqrts", type=float, default=1000.0) - ap.add_argument("--scale", type=float) - ap.add_argument("--seed", type=int, default=12345) - ap.add_argument( - "--n", type=int, default=2048, help="integration points per contribution" - ) - ap.add_argument("--training", type=int, nargs="+", default=[256, 512]) - ap.add_argument("--batch-size", type=int, default=256) - ap.add_argument("--epochs", type=int, default=200) - ap.add_argument( - "--madnis", action="store_true", help="train a neural flow after VEGAS" - ) - ap.add_argument("--vegas-only", dest="madnis", action="store_false") - ap.add_argument("--learn-discrete", action="store_true") - ap.add_argument("--pt-min", type=float, default=30.0) - ap.add_argument("--eta-max", type=float, default=6.0) - ap.add_argument("--dr-min", type=float, default=0.4) - ap.add_argument( - "--selftest", action="store_true", help="phase-space volume, without ME or PDFs" - ) - ap.add_argument("--result", type=Path, help="optional machine-readable result") - args = ap.parse_args() - if min(args.n, args.batch_size, args.epochs, *args.training) < 2: - ap.error("sample counts, batch size and epochs must be at least two") - channels, n_out, data = load_channels(args.json, args.provider) - if args.pdf and data["provider"]["alpha_s_parameter"] is None: - ap.error("this provider has no unambiguous running-alpha_s input") - cfg = Config( - sqrts=args.sqrts, - pdfset=args.pdfset, - pdf_dir=args.pdf_dir, - scale_ref=args.scale, - cuts=Cuts(args.pt_min, args.eta_max, args.dr_min), - ) - print( - f"Metadata: {args.json.resolve()} (provider {data['provider']['id']})\n" - f"Loaded {grouping_summary(data)}, n_out={n_out}; " - f"{data['provider']['color_accuracy']} colour", - flush=True, - ) - ctx = ms.Context(1) - torch.set_num_threads(1) - t0 = time.time() - sigma, err, per_channel = integrate_per_channel( - channels, - n_out, - cfg, - ctx, - None if args.selftest else args.library, - args.artifact, - args.pdf and not args.selftest, - args.batch_size, - args.epochs, - args.n, - args.seed, - not args.madnis, - args.learn_discrete, - args.training, - ) - if not args.selftest and sigma <= 0: - raise AssertionError("the demonstration must produce a positive cross section") - result = dict( - integral=sigma, - uncertainty=err, - unit="" if args.selftest else "pb", - points_per_channel=args.n, - channels=len(channels), - elapsed_seconds=time.time() - t0, - per_channel=per_channel, - provider=data["provider"]["id"], - seed=args.seed, - ) - print( - f"\n{'MadNIS' if args.madnis else 'VEGAS'} integral: " - f"{sigma:.6e} +/- {err:.2e} {result['unit']} " - f"({result['elapsed_seconds']:.1f}s)" - ) - if args.result: - args.result.parent.mkdir(parents=True, exist_ok=True) - args.result.write_text(json.dumps(result, indent=2, allow_nan=False) + "\n") - - -if __name__ == "__main__": - main() diff --git a/pyamplicol/umami_example/test_umami.py b/pyamplicol/umami_example/test_umami.py deleted file mode 100644 index ae9393ac63..0000000000 --- a/pyamplicol/umami_example/test_umami.py +++ /dev/null @@ -1,212 +0,0 @@ -"""Batched MadSpace loading example, with native pyAmpliCol parity checks. - -Adapted from R. Frederix and T. Vitos's AmpliCol madspace_interface example: -https://github.com/rikkert-frederix/AmpliCol/blob/madspace_interface/test_umami.py -See README.md for the small, necessary changes to that workflow. -""" - -from __future__ import annotations - -import argparse -from pathlib import Path - -import madspace as ms -import numpy as np -from _metadata import load_metadata - - -def main() -> None: - ap = argparse.ArgumentParser(description=__doc__) - ap.add_argument("artifact", type=Path) - ap.add_argument("--library", type=Path, required=True) - ap.add_argument("--metadata", type=Path) - ap.add_argument("--provider") - ap.add_argument("--n", type=int, default=100) - ap.add_argument("--sqrts", type=float, default=1000.0) - ap.add_argument("--seed", type=int, default=12345) - args = ap.parse_args() - if args.n < 1: - ap.error("--n must be positive") - artifact = args.artifact.resolve() - data = load_metadata( - args.metadata or artifact / "API/umami/metadata.json", args.provider - ) - - # Same load -> phase space -> batched MatrixElement sequence as upstream. - np.random.seed(args.seed) - ctx = ms.Context(1) - me = ctx.load_matrix_element(str(args.library.resolve()), str(artifact)) - n = args.n - psmap = ms.PhaseSpaceMapping(data["provider"]["masses"], args.sqrts, leptonic=True) - # Bind the explicit context: v0.2.1 convenience calls use the global context. - ps_runtime = ms.FunctionRuntime(psmap.forward_function(), ctx) - p_ext, _x1, _x2, det = ps_runtime(np.random.rand(n, psmap.random_dim())) - if not np.all(np.isfinite(det) & (det > 0)): - raise AssertionError("phase-space mapping returned a degenerate point") - inputs = [ms.MatrixElement.momenta_in] - alpha_name = data["provider"]["alpha_s_parameter"] - if alpha_name is not None: - inputs.append(ms.MatrixElement.alpha_s_in) - inputs += [ - ms.MatrixElement.flavor_in, - ms.MatrixElement.channel_in, - ms.MatrixElement.random_helicity_in, - ] - # The convenience overload queries diagram_count even without diagram - # outputs. This recursion provider intentionally has no diagram metadata. - func = ms.MatrixElement( - me.index(), - me.particle_count(), - inputs, - [ms.MatrixElement.matrix_element_out, ms.MatrixElement.helicity_index_out], - diagram_count=0, - ) - evaluator = ms.FunctionRuntime(func.function(), ctx) - - from pyamplicol import Runtime - - runtimes = {} - physical_sums = {} - generated = {process["id"] for process in data["runtime_processes"]} - checked = 0 - maximum_error = 0.0 - for channel_index, channel in enumerate(data["channels"]): - for flavor_index, process in enumerate(channel["processes"]): - spec = process["runtime"] - process_id = spec["process_id"] - if process_id not in runtimes: - runtimes[process_id] = Runtime.load(artifact, process=process_id) - runtime = runtimes[process_id] - buffers = [p_ext] - alpha_s = None - if alpha_name is not None: - default = next( - p.default_real - for p in runtime.physics.model_parameters - if p.name == alpha_name - ) - # Exercise actual dependent-coupling updates, not just a fixed alpha_s. - alpha_s = default * np.linspace(0.9, 1.1, n) - buffers.append(alpha_s) - flavors = np.full(n, flavor_index, dtype=np.int32) - channels = np.full(n, channel_index, dtype=np.int32) - rnd_hel = np.random.rand(n) - amp2, hel = evaluator(*buffers, flavors, channels, rnd_hel) - - native = [] - color_id = spec["color_id"] - for i, point in enumerate(p_ext): - if alpha_s is not None: - runtime.set_model_parameter(alpha_name, float(alpha_s[i])) - mapped = point[spec["permutation"]] - value = runtime.evaluate( - (mapped,), color_flows=None if color_id is None else (color_id,) - )[0] - native.append(float(complex(value).real) * float(spec["factor"])) - native = np.asarray(native) - np.testing.assert_allclose(amp2, native, rtol=2e-10, atol=1e-25) - if not np.all(np.isfinite(amp2)) or not np.all(amp2 >= 0): - raise AssertionError("invalid squared matrix element") - runtime_meta = data["runtime_processes"][spec["process_index"]] - helicity_count = len(runtime_meta["helicity_ids"]) - if not np.all((hel >= 0) & (hel < helicity_count)): - raise AssertionError("sampled helicity does not index process metadata") - scale = np.maximum(np.abs(native), np.finfo(float).tiny) - maximum_error = max( - maximum_error, float(np.max(np.abs(amp2 - native) / scale)) - ) - checked += n - for member in process["members"]: - if member["process_id"] not in generated: - # A --flavor-blind member has no native runtime of its own: - # its equality with the representative is assumed. - continue - # Automatic grouping includes identical-particle integration orbits. - # Compose the maps to evaluate each member at the original - # labelled point, not at the representative's labelled point. - mapped_points = np.empty_like(p_ext) - mapped_points[:, spec["permutation"], :] = p_ext[ - :, member["runtime"]["permutation"], : - ] - member_buffers = [mapped_points] - if alpha_s is not None: - member_buffers.append(alpha_s) - member_amp2, _member_hel = evaluator( - *member_buffers, flavors, channels, rnd_hel - ) - original_id = member["process_id"] - if original_id not in runtimes: - runtimes[original_id] = Runtime.load(artifact, process=original_id) - physical_runtime = runtimes[original_id] - physical_color = member["color_id"] - selected = None if physical_color is None else (physical_color,) - physical_native = [] - for i, point in enumerate(p_ext): - if alpha_s is not None: - physical_runtime.set_model_parameter( - alpha_name, float(alpha_s[i]) - ) - value = physical_runtime.evaluate((point,), color_flows=selected)[0] - physical_native.append(float(complex(value).real)) - physical_native = np.asarray(physical_native) - np.testing.assert_allclose( - member_amp2, physical_native, rtol=2e-10, atol=1e-25 - ) - if not np.all(np.isfinite(member_amp2)) or not np.all(member_amp2 >= 0): - raise AssertionError("invalid physical-member matrix element") - scale = np.maximum(np.abs(physical_native), np.finfo(float).tiny) - maximum_error = max( - maximum_error, - float(np.max(np.abs(member_amp2 - physical_native) / scale)), - ) - checked += n - if data["provider"]["color_accuracy"] == "lc": - total, colors = physical_sums.setdefault( - original_id, (np.zeros(n), []) - ) - # Only the physical member weight belongs in a pointwise - # sum; matrix_elements factors are integration weights. - total += member_amp2 * float(member["factor"]) - colors.append(physical_color) - reconstructed = 0 - for process_id, (total, colors) in physical_sums.items(): - if process_id not in runtimes: - runtimes[process_id] = Runtime.load(artifact, process=process_id) - runtime = runtimes[process_id] - if runtime.physics.color_coverage != "complete": - continue - if len(colors) != len(set(colors)) or set(colors) != set( - runtime.physics.color_flow_ids - ): - raise AssertionError( - "UMAMI contributions do not cover physical LC flows once" - ) - default = ( - None - if alpha_name is None - else next( - p.default_real - for p in runtime.physics.model_parameters - if p.name == alpha_name - ) - ) - native_total = [] - alpha_factors = np.linspace(0.9, 1.1, n) - for i, point in enumerate(p_ext): - if default is not None: - runtime.set_model_parameter( - alpha_name, default * float(alpha_factors[i]) - ) - native_total.append(float(complex(runtime.evaluate((point,))[0]).real)) - np.testing.assert_allclose(total, native_total, rtol=2e-10, atol=1e-25) - reconstructed += n - print( - f"MadSpace/UMAMI: {checked} values match native pyAmpliCol; " - f"max relative difference {maximum_error:.3g}" - ) - if reconstructed: - print(f"LC channel sums reconstruct {reconstructed} native total values") - - -if __name__ == "__main__": - main()