RustedSciThe 0.4.19

Rust framework for symbolic and numerical computing:BVP ( Newton-Raphson frozen/damped/with collocations ), IVP( BDF, Radau, Backward Euler, LSODE, LSODA, RK45, DoPri), nonlinear equations ( Levenberg, Gavin) and more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
#[test]
#[ignore = "diagnostic combustion Rust-AOT-only compile-preset table; compares rustc presets, not C/Zig toolchains"]
fn symbolic_assembly_rust_compile_presets_report_build_vs_runtime_1000() {
    aot_test_report!(symbolic_assembly_rust_compile_presets_report_build_vs_runtime_1000);
    #[derive(Debug)]
    struct Row {
        backend: &'static str,
        preset: &'static str,
        bootstrap_ms: f64,
        solve_ms: f64,
        max_abs_solution: f64,
    }

    let n_steps = 200usize;
    let mut rows = Vec::new();

    for (backend_label, symbolic_backend) in [
        ("ExprLegacy", BvpSymbolicAssemblyBackend::ExprLegacy),
        ("AtomView", BvpSymbolicAssemblyBackend::AtomView),
    ] {
        for (preset_label, config) in [
                (
                    "Production",
                    crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                        .with_aot_compile_production(),
                ),
                (
                    "FastBuild",
                    crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                        .with_aot_compile_fast_build(),
                ),
                (
                    "DevFastest",
                    crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                        .with_aot_compile_dev_fastest(),
                ),
            ] {
                let generated_backend_config = config
                    .with_symbolic_assembly_backend(symbolic_backend)
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly)
                    .with_aot_build_policy(AotBuildPolicy::RebuildAlways {
                        profile:
                            crate::numerical::BVP_Damp::generated_solver_handoff::AotBuildProfile::Release,
                    });

                let mut solver = make_combustion_solver(n_steps, generated_backend_config);
                let label = format!(
                    "combustion-compile-preset-{}-{}-{}",
                    backend_label, preset_label, n_steps
                );
                let (_guard, bootstrap_ms, solve_ms) = solve_with_aot_and_measure(&mut solver, &label)
                    .expect("compile-preset combustion run should solve");
                let solution = solver
                    .get_result()
                    .expect("compile-preset combustion run should produce a solution");
                let max_abs_solution = solution.iter().copied().map(f64::abs).fold(0.0, f64::max);
                assert!(
                    solution.iter().all(|value| value.is_finite()),
                    "{backend_label} {preset_label} solution should remain finite"
                );

                rows.push(Row {
                    backend: backend_label,
                    preset: preset_label,
                    bootstrap_ms,
                    solve_ms,
                    max_abs_solution,
                });
            }
    }

    println!(
        "[BVP symbolic assembly Rust compile presets] combustion build-vs-runtime, n_steps={n_steps}"
    );
    println!(
        "note: this is intentionally Rust-AOT only; C/Zig toolchain comparisons live in the end-to-end and callback-throughput matrices."
    );
    println!(
        "{:<12} | {:<11} | {:>12} | {:>10} | {:>16}",
        "backend", "preset", "bootstrap_ms", "solve_ms", "max_abs_solution"
    );
    println!("{}", "-".repeat(74));
    for row in rows {
        println!(
            "{:<12} | {:<11} | {:>12.3} | {:>10.3} | {:>16.6e}",
            row.backend, row.preset, row.bootstrap_ms, row.solve_ms, row.max_abs_solution
        );
    }
}

#[test]
#[ignore = "diagnostic combustion Lambdify vs AtomView DevFastest end-to-end matrix across Rust/gcc/tcc/zig"]
fn combustion_lambdify_vs_atomview_devfastest_toolchain_end_to_end_1000() {
    aot_test_report!(combustion_lambdify_vs_atomview_devfastest_toolchain_end_to_end_1000);
    #[derive(Debug)]
    struct Row {
        backend: String,
        setup_ms: f64,
        solve_ms: f64,
        total_ms: f64,
        solution_diff: f64,
        max_abs_solution: f64,
    }

    // Keep this compact: it is an end-to-end toolchain comparison, while large-grid
    // stress belongs to the test_aot_race_stress release matrices. Rust AOT can become a
    // compiler-stress test before the solver path is reached on larger generated crates.
    let n_steps = 200usize;

    let lambdify_config =
        crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::default()
            .with_backend_policy_override(Some(BackendSelectionPolicy::LambdifyOnly))
            .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::ExprLegacy);

    let mut lambdify_solver = make_combustion_solver(n_steps, lambdify_config);
    let lambdify_generate_begin = Instant::now();
    lambdify_solver
        .try_eq_generate(None, None)
        .expect("lambdify combustion generate should succeed");
    let lambdify_setup_ms = lambdify_generate_begin.elapsed().as_secs_f64() * 1_000.0;
    let lambdify_solve_begin = Instant::now();
    lambdify_solver
        .try_solve()
        .expect("lambdify combustion solve should succeed");
    let lambdify_solve_ms = lambdify_solve_begin.elapsed().as_secs_f64() * 1_000.0;
    let lambdify_solution = lambdify_solver
        .get_result()
        .expect("lambdify combustion solve should produce a solution");

    let mut rows = vec![Row {
        backend: "Lambdify".to_string(),
        setup_ms: lambdify_setup_ms,
        solve_ms: lambdify_solve_ms,
        total_ms: lambdify_setup_ms + lambdify_solve_ms,
        solution_diff: 0.0,
        max_abs_solution: lambdify_solution
            .iter()
            .copied()
            .map(f64::abs)
            .fold(0.0, f64::max),
    }];

    for toolchain in RuntimeTuningToolchain::variants() {
        let config = sparse_atomview_rebuild_release_devfastest_config(toolchain);
        let label = format!("AtomView+{}", toolchain.label());
        let mut atom_solver = make_combustion_solver(n_steps, config);
        let (_atom_guard, atom_setup_ms, atom_solve_ms) = solve_with_aot_and_measure(
            &mut atom_solver,
            &format!(
                "combustion-atomview-{}-devfastest-vs-lambdify-{n_steps}",
                toolchain.label()
            ),
        )
        .unwrap_or_else(|err| {
            panic!("{label} DevFastest combustion solve should succeed: {err:?}")
        });
        let atom_solution = atom_solver.get_result().unwrap_or_else(|| {
            panic!("{label} DevFastest combustion solve should produce a solution")
        });

        let solution_diff = lambdify_solution
            .iter()
            .zip(atom_solution.iter())
            .map(|(&lhs, &rhs)| (lhs - rhs).abs())
            .fold(0.0, f64::max);
        assert!(
            solution_diff < 1e-6,
            "{label}: Lambdify vs AtomView DevFastest disagreement {solution_diff} is too large"
        );

        rows.push(Row {
            backend: label,
            setup_ms: atom_setup_ms,
            solve_ms: atom_solve_ms,
            total_ms: atom_setup_ms + atom_solve_ms,
            solution_diff,
            max_abs_solution: atom_solution
                .iter()
                .copied()
                .map(f64::abs)
                .fold(0.0, f64::max),
        });
    }

    println!(
        "[BVP end-to-end compare] combustion Lambdify vs AtomView DevFastest toolchain matrix, n_steps={n_steps}"
    );
    println!(
        "{:<16} | {:>12} | {:>10} | {:>10} | {:>14} | {:>16}",
        "backend", "setup_ms", "solve_ms", "total_ms", "diff_vs_base", "max_abs_solution"
    );
    println!("{}", "-".repeat(95));
    for row in rows {
        println!(
            "{:<16} | {:>12.3} | {:>10.3} | {:>10.3} | {:>14.6e} | {:>16.6e}",
            row.backend,
            row.setup_ms,
            row.solve_ms,
            row.total_ms,
            row.solution_diff,
            row.max_abs_solution
        );
    }
}

#[test]
#[ignore = "diagnostic combustion callback-throughput matrix: Lambdify baseline vs linked AtomView Rust/gcc/tcc/zig"]
fn combustion_callback_throughput_lambdify_vs_atomview_linked_runtime_1000() {
    aot_test_report!(combustion_callback_throughput_lambdify_vs_atomview_linked_runtime_1000);
    #[derive(Debug)]
    struct Row {
        backend: String,
        residual_ms: f64,
        jacobian_ms: f64,
        total_ms: f64,
        speedup_vs_lambdify: f64,
        residual_diff: f64,
        jacobian_diff: f64,
    }

    // This diagnostic is a runtime callback-binding guard, not a Rust compiler stress test.
    // Large Rust AOT artifacts can overflow rustc's stack before the test reaches the linked
    // chunk callbacks we want to validate here.
    let n_steps = 200usize;
    let iters = 20usize;
    // Cross-backend callback equivalence compares Lambdify against generated
    // cdylib code. Tiny libm/codegen ordering differences show up around
    // 1e-6 on this combustion fixture, while actual callback wiring bugs
    // were orders of magnitude larger.
    let cross_backend_callback_tol = 5.0e-6;

    let lambdify_config =
        crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::default()
            .with_backend_policy_override(Some(BackendSelectionPolicy::LambdifyOnly))
            .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::ExprLegacy);

    let mut lambdify_solver = make_combustion_solver(n_steps, lambdify_config);
    let mut lambdify_bundle = sparse_bundle_from_solver_request(&mut lambdify_solver)
        .expect("lambdify sparse bundle should build for callback throughput compare");
    assert_eq!(
        lambdify_bundle.effective_backend(),
        SelectedBackendKind::Lambdify,
        "lambdify callback throughput compare should stay on lambdify backend"
    );
    assert!(
        lambdify_bundle.is_runtime_callable(),
        "lambdify sparse bundle should be runtime-callable"
    );

    let args = DVector::from_element(lambdify_bundle.jacobian_shape().1, 0.99);
    let typed = Vectors_type_casting(
        &args,
        crate::symbolic::symbolic_functions_BVP::BvpMatrixBackend::FaerSparseCol
            .legacy_method()
            .to_string(),
    );

    let (lambdify_residual_ms, lambdify_jacobian_ms) =
        measure_sparse_runtime_callback_throughput(&mut lambdify_bundle, &*typed, iters);
    let lambdify_total_ms = lambdify_residual_ms + lambdify_jacobian_ms;

    let mut rows = vec![Row {
        backend: "Lambdify".to_string(),
        residual_ms: lambdify_residual_ms,
        jacobian_ms: lambdify_jacobian_ms,
        total_ms: lambdify_total_ms,
        speedup_vs_lambdify: 1.0,
        residual_diff: 0.0,
        jacobian_diff: 0.0,
    }];

    for toolchain in RuntimeTuningToolchain::variants() {
        let label = format!("AtomView+{}", toolchain.label());
        let config = sparse_atomview_rebuild_release_devfastest_config(toolchain);
        let mut atom_solver = make_combustion_solver(n_steps, config);
        let _atom_guard = bootstrap_callable_aot_backend(
            &mut atom_solver,
            &format!(
                "combustion-linked-runtime-callback-throughput-{}-{n_steps}",
                toolchain.label()
            ),
        )
        .unwrap_or_else(|err| {
            panic!("{label} bootstrap should succeed for callback throughput compare: {err:?}")
        });
        let mut atom_bundle =
            sparse_bundle_from_solver_request(&mut atom_solver).unwrap_or_else(|err| {
                panic!("{label} sparse bundle should rebuild after linked bootstrap: {err:?}")
            });
        assert_eq!(
            atom_bundle.effective_backend(),
            SelectedBackendKind::AotCompiled,
            "{label}: callback throughput compare should resolve to compiled AOT selection"
        );
        assert!(
            atom_bundle.is_runtime_callable(),
            "{label}: linked sparse bundle should be runtime-callable after bootstrap"
        );

        let (residual_diff, jacobian_diff) = compare_sparse_bundles_numerically(
            &mut lambdify_bundle,
            &mut atom_bundle,
            &args,
            &format!(
                "combustion-callback-throughput-{}-{n_steps}",
                toolchain.label()
            ),
        );
        assert!(
            residual_diff <= cross_backend_callback_tol
                && jacobian_diff <= cross_backend_callback_tol,
            "{label}: runtime callback compare requires numerically close callbacks within {cross_backend_callback_tol:e}, got residual_diff={residual_diff}, jacobian_diff={jacobian_diff}"
        );

        let (atom_residual_ms, atom_jacobian_ms) =
            measure_sparse_runtime_callback_throughput(&mut atom_bundle, &*typed, iters);
        let atom_total_ms = atom_residual_ms + atom_jacobian_ms;

        rows.push(Row {
            backend: label,
            residual_ms: atom_residual_ms,
            jacobian_ms: atom_jacobian_ms,
            total_ms: atom_total_ms,
            speedup_vs_lambdify: lambdify_total_ms / atom_total_ms.max(f64::EPSILON),
            residual_diff,
            jacobian_diff,
        });
    }

    println!(
        "[BVP callback throughput] combustion Lambdify vs AtomView linked-runtime toolchain matrix, n_steps={n_steps}, iters={iters}"
    );
    println!(
        "[BVP callback throughput] note: AtomView+Linked now measures the generated cdylib runtime path loaded into the current process"
    );
    println!(
        "{:<16} | {:>12} | {:>12} | {:>12} | {:>18} | {:>13} | {:>13}",
        "backend",
        "residual_ms",
        "jacobian_ms",
        "total_ms",
        "speedup_vs_lambdify",
        "res_diff",
        "jac_diff"
    );
    println!("{}", "-".repeat(112));
    for row in rows {
        println!(
            "{:<16} | {:>12.3} | {:>12.3} | {:>12.3} | {:>18.3}x | {:>13.6e} | {:>13.6e}",
            row.backend,
            row.residual_ms,
            row.jacobian_ms,
            row.total_ms,
            row.speedup_vs_lambdify,
            row.residual_diff,
            row.jacobian_diff
        );
    }
}

#[test]
#[ignore = "diagnostic sparse AOT whole-vs-chunked callback throughput across Rust/gcc/tcc/zig; isolates runtime parallelism from Newton/bootstrap cost"]
fn combustion_sparse_aot_callback_chunking_parallelism_diagnostic() {
    aot_test_report!(combustion_sparse_aot_callback_chunking_parallelism_diagnostic);
    #[derive(Debug)]
    struct CallbackChunkRow {
        config: String,
        bootstrap_ms: f64,
        rayon_workers: usize,
        residual_chunks: usize,
        sparse_chunks: usize,
        residual_jobs: usize,
        sparse_jobs: usize,
        residual_ms: RuntimeTuningAggregate,
        jacobian_ms: RuntimeTuningAggregate,
        total_ms: RuntimeTuningAggregate,
        speedup_vs_whole: RuntimeTuningAggregate,
        residual_diff_vs_whole: f64,
        jacobian_diff_vs_whole: f64,
    }

    fn sparse_aot_callback_config(
        toolchain: RuntimeTuningToolchain,
        execution_policy: AotExecutionPolicy,
        chunking_policy: AotChunkingPolicy,
    ) -> crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig {
        let config = crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                .with_aot_build_policy(AotBuildPolicy::RebuildAlways {
                    profile: crate::numerical::BVP_Damp::generated_solver_handoff::AotBuildProfile::Debug,
                })
                .with_aot_compile_dev_fastest()
                .with_aot_execution_policy(execution_policy)
                .with_aot_chunking_policy(chunking_policy);
        toolchain.apply_to(config)
    }

    fn linked_job_range_count(chunk_count: usize, max_jobs: usize) -> usize {
        if chunk_count == 0 {
            return 0;
        }
        let target_jobs = chunk_count.min(max_jobs.max(1));
        let items_per_job = chunk_count.div_ceil(target_jobs);
        chunk_count.div_ceil(items_per_job)
    }

    fn policy_max_jobs(policy: &AotExecutionPolicy) -> (usize, usize) {
        match policy {
            AotExecutionPolicy::Parallel(config) => {
                let workers = rayon::current_num_threads().max(1);
                let worker_jobs = workers.saturating_mul(config.jobs_per_worker.max(1));
                (
                    config.max_residual_jobs.unwrap_or(worker_jobs).max(1),
                    config.max_sparse_jobs.unwrap_or(worker_jobs).max(1),
                )
            }
            _ => (1, 1),
        }
    }

    fn linked_sparse_chunk_counts(
        bundle: &BvpSparseSolverBundle,
        residual_max_jobs: usize,
        sparse_max_jobs: usize,
    ) -> (usize, usize, usize, usize) {
        let Some(problem_key) = bundle
            .resolved_aot_artifact()
            .map(|artifact| artifact.registered.problem_key.as_str())
        else {
            return (0, 0, 0, 0);
        };
        let Some(linked) = resolve_linked_sparse_backend(problem_key) else {
            return (0, 0, 0, 0);
        };
        let residual_chunks = linked.residual_chunks.len();
        let sparse_chunks = linked.jacobian_value_chunks.len();
        (
            residual_chunks,
            sparse_chunks,
            linked_job_range_count(residual_chunks, residual_max_jobs),
            linked_job_range_count(sparse_chunks, sparse_max_jobs),
        )
    }

    // This diagnostic is a runtime callback-binding guard, not a Rust compiler stress test.
    // Large Rust AOT artifacts can overflow rustc's stack before the test reaches the linked
    // chunk callbacks we want to validate here.
    let n_steps = 200usize;
    let callback_iters = 30usize;
    let measurement_repeats = 5usize;
    let variants = [
        (
            "whole-sequential",
            AotExecutionPolicy::SequentialOnly,
            AotChunkingPolicy::default(),
        ),
        (
            "par-4x4-jobs4",
            AotExecutionPolicy::Parallel(ParallelExecutorConfig {
                jobs_per_worker: 1,
                max_residual_jobs: Some(4),
                max_sparse_jobs: Some(4),
                fallback_policy: ParallelFallbackPolicy::Never,
            }),
            AotChunkingPolicy::with_parts(
                Some(ResidualChunkingStrategy::ByTargetChunkCount { target_chunks: 4 }),
                Some(SparseChunkingStrategy::ByTargetChunkCount { target_chunks: 4 }),
            ),
        ),
        (
            "par-8x8-jobs8",
            AotExecutionPolicy::Parallel(ParallelExecutorConfig {
                jobs_per_worker: 1,
                max_residual_jobs: Some(8),
                max_sparse_jobs: Some(8),
                fallback_policy: ParallelFallbackPolicy::Never,
            }),
            AotChunkingPolicy::with_parts(
                Some(ResidualChunkingStrategy::ByTargetChunkCount { target_chunks: 8 }),
                Some(SparseChunkingStrategy::ByTargetChunkCount { target_chunks: 8 }),
            ),
        ),
        (
            "par-16x16-jobs16",
            AotExecutionPolicy::Parallel(ParallelExecutorConfig {
                jobs_per_worker: 1,
                max_residual_jobs: Some(16),
                max_sparse_jobs: Some(16),
                fallback_policy: ParallelFallbackPolicy::Never,
            }),
            AotChunkingPolicy::with_parts(
                Some(ResidualChunkingStrategy::ByTargetChunkCount { target_chunks: 16 }),
                Some(SparseChunkingStrategy::ByTargetChunkCount { target_chunks: 16 }),
            ),
        ),
    ];

    let mut rows = Vec::new();

    for toolchain in RuntimeTuningToolchain::variants() {
        let toolchain_label = toolchain.label();
        let mut whole_solver = make_combustion_solver(
            n_steps,
            sparse_aot_callback_config(
                toolchain,
                AotExecutionPolicy::SequentialOnly,
                AotChunkingPolicy::default(),
            ),
        );
        let whole_bootstrap_begin = Instant::now();
        let _whole_guard = bootstrap_callable_aot_backend(
            &mut whole_solver,
            &format!("combustion-sparse-aot-callback-{toolchain_label}-whole-{n_steps}"),
        )
        .unwrap_or_else(|err| {
            panic!(
                "{toolchain_label}/whole: sparse AOT callback diagnostic bootstrap failed: {err:?}"
            )
        });
        let whole_bootstrap_ms = whole_bootstrap_begin.elapsed().as_secs_f64() * 1_000.0;
        let mut whole_bundle =
            sparse_bundle_from_solver_request(&mut whole_solver).unwrap_or_else(|err| {
                panic!(
                    "{toolchain_label}/whole: sparse AOT callback diagnostic bundle failed: {err:?}"
                )
            });
        assert_eq!(
            whole_bundle.effective_backend(),
            SelectedBackendKind::AotCompiled,
            "{toolchain_label}/whole: sparse AOT callback diagnostic should use compiled backend"
        );

        let args = DVector::from_element(whole_bundle.jacobian_shape().1, 0.99);
        let typed = Vectors_type_casting(
            &args,
            crate::symbolic::symbolic_functions_BVP::BvpMatrixBackend::FaerSparseCol
                .legacy_method()
                .to_string(),
        );

        let mut whole_residual_samples = Vec::with_capacity(measurement_repeats);
        let mut whole_jacobian_samples = Vec::with_capacity(measurement_repeats);
        for _ in 0..measurement_repeats {
            let (residual_ms, jacobian_ms) = measure_sparse_runtime_callback_throughput(
                &mut whole_bundle,
                &*typed,
                callback_iters,
            );
            whole_residual_samples.push(residual_ms);
            whole_jacobian_samples.push(jacobian_ms);
        }
        let whole_total_samples = whole_residual_samples
            .iter()
            .zip(whole_jacobian_samples.iter())
            .map(|(&residual_ms, &jacobian_ms)| residual_ms + jacobian_ms)
            .collect::<Vec<_>>();
        let whole_total_mean = runtime_tuning_aggregate(whole_total_samples.iter().copied()).mean;
        let (whole_residual_chunks, whole_sparse_chunks, whole_residual_jobs, whole_sparse_jobs) =
            linked_sparse_chunk_counts(&whole_bundle, 1, 1);

        rows.push(CallbackChunkRow {
            config: format!("{toolchain_label}/whole-sequential"),
            bootstrap_ms: whole_bootstrap_ms,
            rayon_workers: rayon::current_num_threads(),
            residual_chunks: whole_residual_chunks,
            sparse_chunks: whole_sparse_chunks,
            residual_jobs: whole_residual_jobs,
            sparse_jobs: whole_sparse_jobs,
            residual_ms: runtime_tuning_aggregate(whole_residual_samples.iter().copied()),
            jacobian_ms: runtime_tuning_aggregate(whole_jacobian_samples.iter().copied()),
            total_ms: runtime_tuning_aggregate(whole_total_samples.iter().copied()),
            speedup_vs_whole: runtime_tuning_aggregate([1.0]),
            residual_diff_vs_whole: 0.0,
            jacobian_diff_vs_whole: 0.0,
        });

        for (label, execution_policy, chunking_policy) in variants.iter().skip(1) {
            let (residual_max_jobs, sparse_max_jobs) = policy_max_jobs(execution_policy);
            let full_label = format!("{toolchain_label}/{label}");
            let mut solver = make_combustion_solver(
                n_steps,
                sparse_aot_callback_config(
                    toolchain,
                    execution_policy.clone(),
                    chunking_policy.clone(),
                ),
            );
            let bootstrap_begin = Instant::now();
            let _guard = bootstrap_callable_aot_backend(
                &mut solver,
                &format!("combustion-sparse-aot-callback-{toolchain_label}-{label}-{n_steps}"),
            )
            .unwrap_or_else(|err| {
                panic!("{full_label}: sparse AOT callback diagnostic bootstrap failed: {err:?}")
            });
            let bootstrap_ms = bootstrap_begin.elapsed().as_secs_f64() * 1_000.0;
            let mut bundle = sparse_bundle_from_solver_request(&mut solver).unwrap_or_else(|err| {
                panic!("{full_label}: sparse AOT callback diagnostic bundle failed: {err:?}")
            });
            assert_eq!(
                bundle.effective_backend(),
                SelectedBackendKind::AotCompiled,
                "{full_label}: sparse AOT callback diagnostic should use compiled backend"
            );

            let (residual_diff, jacobian_diff) = compare_sparse_bundles_numerically(
                &mut whole_bundle,
                &mut bundle,
                &args,
                &format!("combustion-sparse-aot-callback-{toolchain_label}-{label}-{n_steps}"),
            );
            assert!(
                residual_diff < 1e-6 && jacobian_diff < 1e-6,
                "{full_label}: chunked callback differs from whole callback, residual_diff={residual_diff}, jacobian_diff={jacobian_diff}"
            );

            let mut residual_samples = Vec::with_capacity(measurement_repeats);
            let mut jacobian_samples = Vec::with_capacity(measurement_repeats);
            for _ in 0..measurement_repeats {
                let (residual_ms, jacobian_ms) = measure_sparse_runtime_callback_throughput(
                    &mut bundle,
                    &*typed,
                    callback_iters,
                );
                residual_samples.push(residual_ms);
                jacobian_samples.push(jacobian_ms);
            }
            let total_samples = residual_samples
                .iter()
                .zip(jacobian_samples.iter())
                .map(|(&residual_ms, &jacobian_ms)| residual_ms + jacobian_ms)
                .collect::<Vec<_>>();
            let speedup_samples = total_samples
                .iter()
                .map(|&total_ms| whole_total_mean / total_ms.max(f64::EPSILON))
                .collect::<Vec<_>>();
            let (residual_chunks, sparse_chunks, residual_jobs, sparse_jobs) =
                linked_sparse_chunk_counts(&bundle, residual_max_jobs, sparse_max_jobs);
            assert!(
                residual_chunks > 1,
                "{full_label}: requested chunked sparse AOT residual execution, but linked backend registered only {residual_chunks} residual chunks"
            );
            assert!(
                sparse_chunks > 1,
                "{full_label}: requested chunked sparse AOT Jacobian execution, but linked backend registered only {sparse_chunks} Jacobian chunks"
            );
            assert!(
                residual_jobs > 1,
                "{full_label}: requested parallel residual execution, but runtime job planner produced only {residual_jobs} job"
            );
            assert!(
                sparse_jobs > 1,
                "{full_label}: requested parallel Jacobian execution, but runtime job planner produced only {sparse_jobs} job"
            );

            rows.push(CallbackChunkRow {
                config: full_label,
                bootstrap_ms,
                rayon_workers: rayon::current_num_threads(),
                residual_chunks,
                sparse_chunks,
                residual_jobs,
                sparse_jobs,
                residual_ms: runtime_tuning_aggregate(residual_samples.iter().copied()),
                jacobian_ms: runtime_tuning_aggregate(jacobian_samples.iter().copied()),
                total_ms: runtime_tuning_aggregate(total_samples.iter().copied()),
                speedup_vs_whole: runtime_tuning_aggregate(speedup_samples.iter().copied()),
                residual_diff_vs_whole: residual_diff,
                jacobian_diff_vs_whole: jacobian_diff,
            });
        }
    }

    println!(
        "[BVP callback parallelism diagnostic] sparse AtomView AOT callbacks, n_steps={n_steps}, callback_iters={callback_iters}, measurement_repeats={measurement_repeats}"
    );
    println!(
        "note: this isolates residual/Jacobian callback evaluation; bootstrap_ms is reported only to expose artifact overhead and is not part of callback throughput."
    );
    println!(
        "{:<28} | {:>12} | {:>7} | {:>7} | {:>7} | {:>7} | {:>7} | {:<18} | {:<18} | {:<18} | {:<18} | {:>15} | {:>15}",
        "config",
        "bootstrap_ms",
        "workers",
        "res_ch",
        "jac_ch",
        "res_jobs",
        "jac_jobs",
        "residual_ms",
        "jacobian_ms",
        "callback_total_ms",
        "speedup_vs_whole",
        "residual_diff",
        "jacobian_diff",
    );
    println!("{}", "-".repeat(214));
    for row in rows {
        println!(
            "{:<28} | {:>12.3} | {:>7} | {:>7} | {:>7} | {:>7} | {:>7} | {:<18} | {:<18} | {:<18} | {:<18} | {:>15.6e} | {:>15.6e}",
            row.config,
            row.bootstrap_ms,
            row.rayon_workers,
            row.residual_chunks,
            row.sparse_chunks,
            row.residual_jobs,
            row.sparse_jobs,
            fmt_tuning_short(row.residual_ms),
            fmt_tuning_short(row.jacobian_ms),
            fmt_tuning_short(row.total_ms),
            fmt_tuning_short(row.speedup_vs_whole),
            row.residual_diff_vs_whole,
            row.jacobian_diff_vs_whole,
        );
    }
}

#[test]
#[ignore = "diagnostic stage breakdown inside generate_ms for combustion symbolic backends"]
fn symbolic_assembly_backends_report_combustion_generate_breakdown_table() {
    aot_test_report!(symbolic_assembly_backends_report_combustion_generate_breakdown_table);
    #[derive(Debug)]
    struct GenerateBreakdownRow {
        backend: BvpSymbolicAssemblyBackend,
        n_steps: usize,
        discretization_ms: f64,
        symbolic_jacobian_ms: f64,
        sparse_aot_prep_ms: f64,
        total_ms: f64,
    }

    let n_steps_list = [200usize, 300usize];
    let base_config =
        crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::default();
    let mut rows = Vec::new();

    for &n_steps in &n_steps_list {
        let mut legacy_solver = make_combustion_solver(
            n_steps,
            base_config
                .clone()
                .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::ExprLegacy),
        );
        let legacy_request = legacy_solver.build_solver_request(None, None);
        let legacy_snapshot = measure_symbolic_generation_breakdown_with_symbolic_backend(
            legacy_request,
            BvpSymbolicAssemblyBackend::ExprLegacy,
        )
        .expect("ExprLegacy combustion breakdown should build");

        let mut atom_solver = make_combustion_solver(
            n_steps,
            base_config
                .clone()
                .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView),
        );
        let atom_request = atom_solver.build_solver_request(None, None);
        let atom_snapshot = measure_symbolic_generation_breakdown_with_symbolic_backend(
            atom_request,
            BvpSymbolicAssemblyBackend::AtomView,
        )
        .expect("AtomView combustion breakdown should build");

        for (backend, snapshot) in [
            (BvpSymbolicAssemblyBackend::ExprLegacy, legacy_snapshot),
            (BvpSymbolicAssemblyBackend::AtomView, atom_snapshot),
        ] {
            rows.push(GenerateBreakdownRow {
                backend,
                n_steps,
                discretization_ms: snapshot
                    .get("discretization time")
                    .copied()
                    .unwrap_or_default()
                    * 1_000.0,
                symbolic_jacobian_ms: snapshot
                    .get("symbolic jacobian time")
                    .copied()
                    .unwrap_or_default()
                    * 1_000.0,
                sparse_aot_prep_ms: snapshot
                    .get("sparse AOT preparation time")
                    .copied()
                    .unwrap_or_default()
                    * 1_000.0,
                total_ms: snapshot.get("total time, sec").copied().unwrap_or_default() * 1_000.0,
            });
        }
    }

    println!("[BVP symbolic assembly generate breakdown] combustion ExprLegacy vs AtomView");
    println!(
        "{:<12} | {:>7} | {:>17} | {:>20} | {:>19} | {:>10}",
        "backend",
        "n_steps",
        "discretization_ms",
        "symbolic_jacobian_ms",
        "sparse_aot_prep_ms",
        "total_ms"
    );
    println!("{}", "-".repeat(104));
    for row in &rows {
        let backend = match row.backend {
            BvpSymbolicAssemblyBackend::ExprLegacy => "ExprLegacy",
            BvpSymbolicAssemblyBackend::AtomView => "AtomView",
        };
        println!(
            "{:<12} | {:>7} | {:>17.3} | {:>20.3} | {:>19.3} | {:>10.3}",
            backend,
            row.n_steps,
            row.discretization_ms,
            row.symbolic_jacobian_ms,
            row.sparse_aot_prep_ms,
            row.total_ms
        );
    }
}

#[test]
#[ignore = "heavy oscillator end-to-end compare for banded lambdify baseline vs AtomView AOT with bootstrap/runtime split"]
fn oscillator_lambdify_vs_atomview_aot_banded_end_to_end_heavy() {
    aot_test_report!(oscillator_lambdify_vs_atomview_aot_banded_end_to_end_heavy);
    #[derive(Debug)]
    struct Row {
        backend: &'static str,
        setup_ms: f64,
        solve_ms: f64,
        total_ms: f64,
        max_abs_solution: f64,
    }

    let n_steps = 1000usize;

    let lambdify_cfg =
        crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::default()
            .with_backend_policy_override(Some(BackendSelectionPolicy::LambdifyOnly))
            .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::ExprLegacy)
            .with_matrix_backend_override(MatrixBackend::Banded);

    let atom_aot_cfg =
            crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::banded_atomview_build_if_missing_release_tcc()
                .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                .with_matrix_backend_override(MatrixBackend::Banded);

    let mut lambdify_solver = make_oscillator_solver(n_steps, lambdify_cfg);
    let lambdify_generate_begin = Instant::now();
    lambdify_solver
        .try_eq_generate(None, None)
        .expect("banded lambdify oscillator generate should succeed");
    let lambdify_setup_ms = lambdify_generate_begin.elapsed().as_secs_f64() * 1_000.0;
    let lambdify_solve_begin = Instant::now();
    lambdify_solver
        .try_solve()
        .expect("banded lambdify oscillator solve should succeed");
    let lambdify_solve_ms = lambdify_solve_begin.elapsed().as_secs_f64() * 1_000.0;
    let lambdify_solution = lambdify_solver
        .get_result()
        .expect("banded lambdify oscillator solve should produce a solution");

    let mut atom_solver = make_oscillator_solver(n_steps, atom_aot_cfg);
    let (atom_setup_ms, atom_solve_ms, atom_solution) = match solve_with_aot_and_measure(
        &mut atom_solver,
        &format!("oscillator-atomview-aot-banded-vs-lambdify-{n_steps}"),
    ) {
        Ok((_guard, setup_ms, solve_ms)) => {
            let solution = atom_solver
                .get_result()
                .expect("banded AtomView AOT oscillator solve should produce a solution")
                .clone();
            (setup_ms, solve_ms, solution)
        }
        Err(err) if is_aot_environment_issue(&err) => {
            eprintln!(
                "Skipping heavy oscillator AOT compare due to environment/toolchain issue: {err:?}"
            );
            return;
        }
        Err(err) => {
            panic!("banded AtomView AOT oscillator compare failed unexpectedly: {err:?}")
        }
    };

    let solution_diff = lambdify_solution
        .iter()
        .zip(atom_solution.iter())
        .map(|(&lhs, &rhs)| (lhs - rhs).abs())
        .fold(0.0, f64::max);
    assert!(
        solution_diff < 1e-5,
        "banded oscillator Lambdify vs AtomView AOT disagreement {solution_diff} is too large"
    );

    let rows = [
        Row {
            backend: "Lambdify",
            setup_ms: lambdify_setup_ms,
            solve_ms: lambdify_solve_ms,
            total_ms: lambdify_setup_ms + lambdify_solve_ms,
            max_abs_solution: lambdify_solution
                .iter()
                .copied()
                .map(f64::abs)
                .fold(0.0, f64::max),
        },
        Row {
            backend: "AtomView+AOT",
            setup_ms: atom_setup_ms,
            solve_ms: atom_solve_ms,
            total_ms: atom_setup_ms + atom_solve_ms,
            max_abs_solution: atom_solution
                .iter()
                .copied()
                .map(f64::abs)
                .fold(0.0, f64::max),
        },
    ];

    println!(
        "[BVP end-to-end compare] oscillator banded Lambdify vs AtomView AOT, n_steps={n_steps}"
    );
    println!(
        "{:<14} | {:>12} | {:>10} | {:>10} | {:>16}",
        "backend", "setup_ms", "solve_ms", "total_ms", "max_abs_solution"
    );
    println!("{}", "-".repeat(76));
    for row in rows {
        println!(
            "{:<14} | {:>12.3} | {:>10.3} | {:>10.3} | {:>16.6e}",
            row.backend, row.setup_ms, row.solve_ms, row.total_ms, row.max_abs_solution
        );
    }
    println!(
        "[BVP end-to-end compare] max_diff_lambdify_vs_atomview_aot = {:.6e}",
        solution_diff
    );
}

#[test]
#[ignore = "diagnostic AOT crate emission/materialize/build comparison for combustion symbolic backends"]
fn symbolic_assembly_backends_report_combustion_aot_crate_build_table() {
    aot_test_report!(symbolic_assembly_backends_report_combustion_aot_crate_build_table);
    let n_steps_list = [200usize, 300usize];
    let base_config =
        crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::default();
    let mut rows = Vec::new();

    for &n_steps in &n_steps_list {
        let mut legacy_solver = make_combustion_solver(
            n_steps,
            base_config
                .clone()
                .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::ExprLegacy),
        );
        let legacy_request = legacy_solver.build_solver_request(None, None);
        rows.push(
            measure_generated_crate_build_with_symbolic_backend(
                legacy_request,
                BvpSymbolicAssemblyBackend::ExprLegacy,
                n_steps,
                &format!("combustion-aot-expr-{n_steps}"),
            )
            .expect("ExprLegacy combustion AOT crate generation should succeed"),
        );

        let mut atom_solver = make_combustion_solver(
            n_steps,
            base_config
                .clone()
                .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView),
        );
        let atom_request = atom_solver.build_solver_request(None, None);
        rows.push(
            measure_generated_crate_build_with_symbolic_backend(
                atom_request,
                BvpSymbolicAssemblyBackend::AtomView,
                n_steps,
                &format!("combustion-aot-atom-{n_steps}"),
            )
            .expect("AtomView combustion AOT crate generation should succeed"),
        );
    }

    println!("[BVP symbolic assembly AOT crate build] combustion ExprLegacy vs AtomView");
    println!(
        "{:<12} | {:>7} | {:>11} | {:>11} | {:>11} | {:>8} | {:>11} | {:>10} | {:>14} | {:>10} | {:>10} | {:>6} | {:>8} | {:>8} | {:>8} | {:>8} | {:>8} | {:<18}",
        "backend",
        "n_steps",
        "jac_prep_ms",
        "lookup_ms",
        "jac_ms",
        "nnz",
        "finalize_ms",
        "module_ms",
        "source_ms",
        "materialize_ms",
        "build_ms",
        "source_kb",
        "blocks",
        "instr",
        "temps",
        "max_blk",
        "outputs",
        "status"
    );
    println!("{}", "-".repeat(234));
    for row in &rows {
        let backend = match row.backend {
            BvpSymbolicAssemblyBackend::ExprLegacy => "ExprLegacy",
            BvpSymbolicAssemblyBackend::AtomView => "AtomView",
        };
        println!(
            "{:<12} | {:>7} | {:>11} | {:>11} | {:>11} | {:>8} | {:>11} | {:>10} | {:>14} | {:>10} | {:>10} | {:>6} | {:>8} | {:>8} | {:>8} | {:>8} | {:>8} | {:<18}",
            backend,
            row.n_steps,
            row.jacobian_prepare_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_lookup_prepare_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_jacobian_build_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_nnz
                .map(|value| value.to_string())
                .unwrap_or_else(|| "-".to_string()),
            row.atom_finalize_codegen_plan_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.module_build_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.source_emit_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.materialize_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.build_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.source_kb
                .map(|value| format!("{value:.1}"))
                .unwrap_or_else(|| "-".to_string()),
            row.module_blocks
                .map(|value| value.to_string())
                .unwrap_or_else(|| "-".to_string()),
            row.total_block_instructions
                .map(|value| value.to_string())
                .unwrap_or_else(|| "-".to_string()),
            row.total_block_temps
                .map(|value| value.to_string())
                .unwrap_or_else(|| "-".to_string()),
            row.max_block_instructions
                .map(|value| value.to_string())
                .unwrap_or_else(|| "-".to_string()),
            row.total_block_outputs
                .map(|value| value.to_string())
                .unwrap_or_else(|| "-".to_string()),
            &row.status
        );
    }

    println!();
    println!("[BVP symbolic assembly AOT crate build] atom module pass breakdown");
    println!(
        "{:<12} | {:>7} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12}",
        "backend",
        "n_steps",
        "res_view_ms",
        "res_lower_ms",
        "res_ph_ms",
        "res_reuse_ms",
        "sp_view_ms",
        "sp_lower_ms",
        "sp_ph_ms",
        "sp_reuse_ms"
    );
    println!("{}", "-".repeat(143));
    for row in rows
        .iter()
        .filter(|row| matches!(row.backend, BvpSymbolicAssemblyBackend::AtomView))
    {
        println!(
            "{:<12} | {:>7} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12} | {:>12}",
            "AtomView",
            row.n_steps,
            row.atom_residual_view_collect_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_residual_lower_many_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_residual_peephole_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_residual_reuse_temps_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_view_collect_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_lower_many_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_peephole_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
            row.atom_sparse_reuse_temps_ms
                .map(|value| format!("{value:.3}"))
                .unwrap_or_else(|| "-".to_string()),
        );
    }

    println!();
    println!(
        "[BVP typed AOT lifecycle] AtomView rows expose the same canonical buckets as the historical AOT story"
    );
    println!(
        "frontend | n_steps | symbolic_prepare_ms | fixture_generation_ms | compile_ms | link_ms | residual_calls | jacobian_calls | errors"
    );
    println!("{}", "-".repeat(132));
    for row in &rows {
        let Some(snapshot) = row.typed_aot_snapshot else {
            continue;
        };
        println!(
            "{:>8} | {:>7} | {:>19.3} | {:>22.3} | {:>10.3} | {:>7.3} | {:>14} | {:>14} | {:>6}",
            match row.backend {
                BvpSymbolicAssemblyBackend::ExprLegacy => "ExprLegacy",
                BvpSymbolicAssemblyBackend::AtomView => "AtomView",
            },
            row.n_steps,
            snapshot.symbolic_preparation().as_secs_f64() * 1_000.0,
            snapshot.fixture_generation().as_secs_f64() * 1_000.0,
            snapshot.compilation().as_secs_f64() * 1_000.0,
            snapshot.linking().as_secs_f64() * 1_000.0,
            snapshot.residual_calls,
            snapshot.jacobian_calls,
            snapshot.errors,
        );
    }
}

#[test]
#[ignore = "diagnostic chunk-level IR compare for ExprLegacy vs AtomView combustion lowering"]
fn symbolic_assembly_backends_report_combustion_chunk_ir_table() {
    aot_test_report!(symbolic_assembly_backends_report_combustion_chunk_ir_table);
    let n_steps = 300usize;
    let base_config =
        crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::default();

    let mut legacy_solver = make_combustion_solver(
        n_steps,
        base_config
            .clone()
            .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::ExprLegacy),
    );
    let legacy_request = legacy_solver.build_solver_request(None, None);
    let (legacy_module, legacy_breakdown) = measure_codegen_module_with_symbolic_backend(
        legacy_request,
        BvpSymbolicAssemblyBackend::ExprLegacy,
    )
    .expect("legacy combustion codegen module should build");

    let mut atom_solver = make_combustion_solver(
        n_steps,
        base_config
            .clone()
            .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView),
    );
    let atom_request = atom_solver.build_solver_request(None, None);
    let (atom_module, atom_breakdown) = measure_codegen_module_with_symbolic_backend(
        atom_request,
        BvpSymbolicAssemblyBackend::AtomView,
    )
    .expect("atom combustion codegen module should build");

    assert_eq!(
        legacy_module.blocks().len(),
        atom_module.blocks().len(),
        "legacy and atom module should produce the same number of blocks"
    );

    let rows = legacy_module
        .blocks()
        .iter()
        .zip(atom_module.blocks().iter())
        .map(|(legacy, atom)| ChunkIrCompareRow {
            fn_name: legacy.fn_name.clone(),
            outputs: legacy.output_count(),
            legacy_instr: legacy.instruction_count(),
            atom_instr: atom.instruction_count(),
            legacy_temps: legacy.temp_count(),
            atom_temps: atom.temp_count(),
        })
        .collect::<Vec<_>>();

    println!(
        "[BVP symbolic assembly chunk IR compare] combustion, n_steps={n_steps}, legacy_instr_total={}, atom_instr_total={}, legacy_temps_total={}, atom_temps_total={}",
        legacy_breakdown.total_block_instructions,
        atom_breakdown.total_block_instructions,
        legacy_breakdown.total_block_temps,
        atom_breakdown.total_block_temps
    );
    println!(
        "{:<36} | {:>7} | {:>12} | {:>10} | {:>12} | {:>10}",
        "fn_name", "outputs", "legacy_instr", "atom_instr", "legacy_temps", "atom_temps"
    );
    println!("{}", "-".repeat(103));
    for row in rows.iter().take(12) {
        println!(
            "{:<36} | {:>7} | {:>12} | {:>10} | {:>12} | {:>10}",
            row.fn_name,
            row.outputs,
            row.legacy_instr,
            row.atom_instr,
            row.legacy_temps,
            row.atom_temps
        );
    }
}