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
#[test]
//  #[ignore = "production-style AOT acceptance suite with real build/bootstrap"]
fn aot_rust_default_exact_examples_sequential_cover_tens_and_hundreds_of_steps() {
    println!("[AOT acceptance] default Rust AOT smoke: exact examples, sequential execution");
    let configs = [
        (
            "two-point-64",
            NonlinEquation::TwoPointBVP,
            64usize,
            1.5e-2f64,
        ),
        (
            "two-point-240",
            NonlinEquation::TwoPointBVP,
            240usize,
            6.0e-3f64,
        ),
        ("clairaut-72", NonlinEquation::Clairaut, 72usize, 1.5e-2f64),
        (
            "clairaut-220",
            NonlinEquation::Clairaut,
            220usize,
            1.25e-2f64,
        ),
    ];

    for (label, equation, n_steps, max_tol) in configs {
        let generated_backend_config =
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly);
        let mut solver = make_example_solver(
            &equation,
            n_steps,
            Some(SolverParams::default()),
            generated_backend_config,
        );
        let _guard = solve_with_aot_and_report(&mut solver, label)
            .expect("sequential AOT exact-example acceptance case should solve");

        let error = match equation {
            NonlinEquation::TwoPointBVP => {
                max_abs_error_against_exact(&solver, |x| (-x * x / 4.0).exp())
            }
            NonlinEquation::Clairaut => l2_error_against_exact(&solver, |x| {
                1.0 + (x - 1.0).powi(2) - (x - 1.0).powi(3) / 6.0 + (x - 1.0).powi(4) / 12.0
            }),
            _ => unreachable!("only exact sequential examples are expected here"),
        };

        println!("[AOT exact sequential] {label}: n_steps={n_steps}, error={error:.6e}");
        assert!(
            error < max_tol,
            "{label}: exact-solution error {error} exceeded tolerance {max_tol}"
        );
    }
}

#[test]
//   #[ignore = "production-style AOT acceptance suite with real build/bootstrap"]
fn aot_rust_default_parallel_exact_examples_cover_parallel_modes_and_chunking() {
    println!("[AOT acceptance] default Rust AOT smoke: exact examples, parallel/chunked execution");
    let lane_parallel = SolverParams {
        max_jac: Some(5),
        max_damp_iter: Some(5),
        damp_factor: None,
        adaptive: None,
    };
    let parachute_parallel = SolverParams {
        max_jac: Some(5),
        max_damp_iter: Some(5),
        damp_factor: None,
        adaptive: None,
    };

    let cases = [
        (
            "parachute-parallel-48",
            NonlinEquation::ParachuteEquation,
            48usize,
            parachute_parallel.clone(),
            5.0e-3f64,
        ),
        (
            "lane-emden-parallel-180",
            NonlinEquation::LaneEmden5,
            180usize,
            lane_parallel.clone(),
            3.5e-4f64,
        ),
    ];

    for (label, equation, n_steps, strategy_params, l2_tol) in cases {
        let generated_backend_config =
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_aot_execution_policy(sparse_parallel_policy())
                    .with_aot_chunking_policy(AotChunkingPolicy::with_parts(
                        Some(ResidualChunkingStrategy::ByTargetChunkCount { target_chunks: 8 }),
                        Some(SparseChunkingStrategy::ByTargetChunkCount { target_chunks: 8 }),
                    ));
        let mut solver = make_example_solver(
            &equation,
            n_steps,
            Some(strategy_params),
            generated_backend_config,
        );
        let _guard = solve_with_aot_and_report(&mut solver, label)
            .expect("parallel AOT exact-example acceptance case should solve");

        let l2_error = match equation {
            NonlinEquation::ParachuteEquation => {
                l2_error_against_exact(&solver, |x| (((2.0 * x).exp() + 1.0) / 2.0).ln() - x)
            }
            NonlinEquation::LaneEmden5 => {
                l2_error_against_exact(&solver, |x| (1.0 + x * x / 3.0).powf(-0.5))
            }
            _ => unreachable!("only parallel analytical examples are expected here"),
        };

        println!("[AOT exact parallel] {label}: n_steps={n_steps}, l2_error={l2_error:.6e}");
        assert!(
            l2_error < l2_tol,
            "{label}: L2 exact-solution error {l2_error} exceeded tolerance {l2_tol}"
        );
    }
}

#[test]
// #[ignore = "production-style AOT acceptance suite with real build/bootstrap"]
fn aot_rust_default_combustion_acceptance_covers_sequential_parallel_and_varied_grids() {
    println!("[AOT acceptance] default Rust AOT smoke: combustion sequential/parallel grids");
    let sequential_config =
            crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly);
    let parallel_config =
            crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                .with_aot_execution_policy(sparse_parallel_policy())
                .with_aot_chunking_policy(AotChunkingPolicy::with_parts(
                    Some(ResidualChunkingStrategy::ByTargetChunkCount { target_chunks: 8 }),
                    Some(SparseChunkingStrategy::ByTargetChunkCount { target_chunks: 8 }),
                ));

    let mut sequential = make_combustion_solver(36, sequential_config.clone());
    let _sequential_guard = solve_with_aot_and_report(&mut sequential, "combustion-sequential-36")
        .expect("sequential AOT combustion case should solve");
    let sequential_solution = sequential
        .get_result()
        .expect("sequential AOT combustion case should produce a solution");
    assert!(
        sequential_solution.iter().all(|value| value.is_finite()),
        "sequential AOT combustion solution should remain finite"
    );

    let mut parallel = make_combustion_solver(36, parallel_config.clone());
    let _parallel_guard = solve_with_aot_and_report(&mut parallel, "combustion-parallel-36")
        .expect("parallel AOT combustion case should solve");
    let parallel_solution = parallel
        .get_result()
        .expect("parallel AOT combustion case should produce a solution");
    assert!(
        parallel_solution.iter().all(|value| value.is_finite()),
        "parallel AOT combustion solution should remain finite"
    );

    let max_difference = sequential_solution
        .iter()
        .zip(parallel_solution.iter())
        .map(|(&lhs, &rhs)| (lhs - rhs).abs())
        .fold(0.0, f64::max);
    println!("[AOT combustion compare] n_steps=36, max_difference_seq_vs_par={max_difference:.6e}");
    assert!(
        max_difference < 1.0e-4,
        "AOT combustion sequential/parallel disagreement {max_difference} is too large"
    );

    let mut large_sequential = make_combustion_solver(256, sequential_config);
    let _large_sequential_guard =
        solve_with_aot_and_report(&mut large_sequential, "combustion-sequential-256")
            .expect("large-grid sequential AOT combustion case should solve");
    let large_sequential_solution = large_sequential
        .get_result()
        .expect("large-grid sequential AOT combustion case should produce a solution");
    assert!(
        large_sequential_solution
            .iter()
            .all(|value| value.is_finite()),
        "large-grid sequential AOT combustion solution should remain finite"
    );

    let mut large_parallel = make_combustion_solver(256, parallel_config);
    let _large_parallel_guard =
        solve_with_aot_and_report(&mut large_parallel, "combustion-parallel-256")
            .expect("large-grid parallel AOT combustion case should solve");
    let large_solution = large_parallel
        .get_result()
        .expect("large-grid AOT combustion case should produce a solution");
    assert!(
        large_solution.iter().all(|value| value.is_finite()),
        "large-grid parallel AOT combustion solution should remain finite"
    );

    let large_max_difference = large_sequential_solution
        .iter()
        .zip(large_solution.iter())
        .map(|(&lhs, &rhs)| (lhs - rhs).abs())
        .fold(0.0, f64::max);
    println!(
        "[AOT combustion compare] n_steps=256, max_difference_seq_vs_par={large_max_difference:.6e}"
    );
    assert!(
        large_max_difference < 1.0e-4,
        "AOT combustion sequential/parallel disagreement {large_max_difference} is too large"
    );
}

#[test]
fn aot_tcc_smoke_exact_two_point_small_grid_solves() {
    println!(
        "[AOT acceptance] compact TCC smoke: two-point exact BVP, sparse AtomView, sequential execution"
    );
    let generated_backend_config =
            crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_atomview_build_if_missing_release_tcc()
                .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly);
    let mut solver = make_example_solver(
        &NonlinEquation::TwoPointBVP,
        40,
        Some(SolverParams::default()),
        generated_backend_config,
    );

    match solve_with_aot_and_report(&mut solver, "tcc-smoke-two-point-40") {
        Ok(_guard) => {
            let error = max_abs_error_against_exact(&solver, |x| (-x * x / 4.0).exp());
            println!("[AOT TCC smoke] two-point-40: error={error:.6e}");
            assert!(
                error < 2.0e-2,
                "TCC smoke exact-solution error {error} exceeded tolerance"
            );
        }
        Err(err) if is_aot_environment_issue(&err) => {
            eprintln!(
                "[AOT TCC smoke] skipped because TCC toolchain/artifact environment is unavailable: {err:?}"
            );
        }
        Err(err) => panic!("TCC smoke should solve or report an environment issue: {err:?}"),
    }
}
// Historical local timing notes kept only as archaeological context. The live
// source of truth is the multi-run, multi-toolchain table printed by
// `aot_combustion_parallel_tuning_reports_runtime_table` and summarized in
// BVP_DAMP_STORY_TESTS.md.
/*
        слишком мало чанков: не хватает загрузки
    слишком много чанков: overhead на orchestration начинает съедать выигрыш
    средний режим вроде 8x8 + jobs8 попадает в sweet spot
    И очень важно:

    max_diff_vs_seq = 0 у всех конфигураций
    это именно то, что и нужно было доказать: parallel AOT меняет скорость, но не математику.
    CPU 4 Cores
    [AOT combustion tuning map] scenario=medium-grid, n_steps=128
    config                   | n_steps | bootstrap_ms |     solve_ms | speedup_vs_seq | max_diff_vs_seq
    ------------------------------------------------------------------------------------------------
    sequential-baseline      |     128 |     7113.999 |      440.910 |          1.000 |     0.000000e0
    par-4x4-jobs4            |     128 |    15332.448 |      335.703 |          1.313 |     0.000000e0
    par-8x8-jobs8            |     128 |    10177.598 |     1116.167 |          0.395 |     0.000000e0
    par-16x16-jobs16         |     128 |     8069.948 |      261.911 |          1.683 |     0.000000e0
    par-res16-row32-jobs8    |     128 |     6763.878 |      280.503 |          1.572 |     0.000000e0
    [AOT tuning winner] scenario=medium-grid, config=par-16x16-jobs16, n_steps=128, solve_ms=261.911, speedup_vs_seq=1.683, bootstrap_ms=8069.948

    [AOT combustion tuning map] scenario=large-grid, n_steps=256
    config                   | n_steps | bootstrap_ms |     solve_ms | speedup_vs_seq | max_diff_vs_seq
    ------------------------------------------------------------------------------------------------
    sequential-baseline      |     256 |    15992.826 |      803.811 |          1.000 |     0.000000e0
    par-4x4-jobs4            |     256 |    36969.672 |     1046.569 |          0.768 |     0.000000e0
    par-8x8-jobs8            |     256 |    22350.296 |      510.894 |          1.573 |     0.000000e0
    par-16x16-jobs16         |     256 |    18268.103 |      956.696 |          0.840 |     0.000000e0
    par-res16-row32-jobs8    |     256 |    13534.274 |      593.440 |          1.354 |     0.000000e0
    [AOT tuning winner] scenario=large-grid, config=par-8x8-jobs8, n_steps=256, solve_ms=510.894, speedup_vs_seq=1.573, bootstrap_ms=22350.296
        CPU 8 Core:
        run 1
    [AOT combustion tuning map] scenario=medium-grid, n_steps=128
config                   | n_steps | bootstrap_ms |     solve_ms | speedup_vs_seq | max_diff_vs_seq
------------------------------------------------------------------------------------------------
sequential-baseline      |     128 |     2130.826 |      137.532 |          1.000 |     0.000000e0
par-4x4-jobs4            |     128 |     3685.552 |      116.561 |          1.180 |     0.000000e0
par-8x8-jobs8            |     128 |     2446.450 |      104.325 |          1.318 |     0.000000e0
par-16x16-jobs16         |     128 |     1870.474 |      116.204 |          1.184 |     0.000000e0
par-res16-row32-jobs8    |     128 |     1807.076 |      109.260 |          1.259 |     0.000000e0
[AOT tuning winner] scenario=medium-grid, config=par-8x8-jobs8, n_steps=128, solve_ms=104.325, speedup_vs_seq=1.318, bootstrap_ms=2446.450

[AOT combustion tuning map] scenario=large-grid, n_steps=256
config                   | n_steps | bootstrap_ms |     solve_ms | speedup_vs_seq | max_diff_vs_seq
------------------------------------------------------------------------------------------------
sequential-baseline      |     256 |     3382.138 |      203.362 |          1.000 |     0.000000e0
par-4x4-jobs4            |     256 |    12063.711 |      172.593 |          1.178 |     0.000000e0
par-8x8-jobs8            |     256 |     7365.829 |      168.625 |          1.206 |     0.000000e0
par-16x16-jobs16         |     256 |     4900.391 |      170.448 |          1.193 |     0.000000e0
par-res16-row32-jobs8    |     256 |     3832.109 |      168.844 |          1.204 |     0.000000e0
[AOT tuning winner] scenario=large-grid, config=par-8x8-jobs8, n_steps=256, solve_ms=168.625, speedup_vs_seq=1.206, bootstrap_ms=7365.829
run 2
[AOT combustion tuning map] scenario=medium-grid, n_steps=128
config                   | n_steps | bootstrap_ms |     solve_ms | speedup_vs_seq | max_diff_vs_seq
------------------------------------------------------------------------------------------------
sequential-baseline      |     128 |     2044.555 |      127.818 |          1.000 |     0.000000e0
par-4x4-jobs4            |     128 |     3723.176 |      115.799 |          1.104 |     0.000000e0
par-8x8-jobs8            |     128 |     2492.751 |      108.581 |          1.177 |     0.000000e0
par-16x16-jobs16         |     128 |     1891.942 |      107.237 |          1.192 |     0.000000e0
par-res16-row32-jobs8    |     128 |     1794.337 |      107.782 |          1.186 |     0.000000e0
[AOT tuning winner] scenario=medium-grid, config=par-16x16-jobs16, n_steps=128, solve_ms=107.237, speedup_vs_seq=1.192, bootstrap_ms=1891.942

config                   | n_steps | bootstrap_ms |     solve_ms | speedup_vs_seq | max_diff_vs_seq
------------------------------------------------------------------------------------------------
sequential-baseline      |     256 |     3503.787 |      188.826 |          1.000 |     0.000000e0
par-4x4-jobs4            |     256 |    12043.939 |      167.994 |          1.124 |     0.000000e0
par-8x8-jobs8            |     256 |     7444.171 |      167.913 |          1.125 |     0.000000e0
par-16x16-jobs16         |     256 |     5047.130 |      164.290 |          1.149 |     0.000000e0
par-res16-row32-jobs8    |     256 |     3913.400 |      176.590 |          1.069 |     0.000000e0
[AOT tuning winner] scenario=large-grid, config=par-16x16-jobs16, n_steps=256, solve_ms=164.290, speedup_vs_seq=1.149, bootstrap_ms=5047.130

        */
#[test]
fn isolated_tuning_solution_payload_round_trips() {
    let solution = DMatrix::from_column_slice(2, 3, &[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]);
    let encoded = format!(
        "{ISOLATED_TUNING_SOLUTION_MARKER}\t{}",
        encode_isolated_tuning_solution(&solution)
    );
    assert_eq!(
        decode_isolated_tuning_solution(&encoded),
        solution.iter().copied().collect::<Vec<_>>()
    );
    let metrics = IsolatedColdMetrics {
        total_timer_ms: 1.0,
        symbolic_ms: 2.0,
        linear_ms: 3.0,
        jac_ms: 4.0,
        fun_ms: 5.0,
        cb_residual_values_ms: 6.0,
        cb_jacobian_values_ms: 7.0,
        cb_jacobian_assembly_ms: 8.0,
        residual_actual_jobs: 4.0,
        sparse_jacobian_actual_jobs: 4.0,
        initial_symbolic_jacobian_ms: 9.0,
        post_build_rebind_ms: 10.0,
        aot_artifact_ms: 11.0,
        aot_materialize_ms: 12.0,
        aot_compile_link_ms: 13.0,
        aot_register_link_ms: 14.0,
        iterations: 15,
        linear_solves: 16,
        jacobian_rebuilds: 17,
        refinements: 18,
        residual_calls: 19,
        jacobian_calls: 20,
    };
    let encoded = format!(
        "{ISOLATED_TUNING_METRICS_MARKER}\t{}",
        encode_isolated_cold_metrics(&metrics)
    );
    let decoded = decode_isolated_cold_metrics(&encoded);
    assert_eq!(decoded.initial_symbolic_jacobian_ms, 9.0);
    assert_eq!(decoded.aot_compile_link_ms, 13.0);
    assert_eq!(decoded.residual_actual_jobs, 4.0);
}

#[test]
#[ignore = "heavy combustion sparse AOT runtime tuning map across Rust/gcc/tcc/zig and chunking policies; cold wall-clock rows run in isolated child processes"]
fn aot_combustion_parallel_tuning_reports_runtime_table() {
    if let Ok(index) = std::env::var(ISOLATED_TUNING_CHILD_INDEX_ENV) {
        let index = index
            .parse::<usize>()
            .expect("isolated tuning child index should be an integer");
        let n_steps = std::env::var(ISOLATED_TUNING_CHILD_STEPS_ENV)
            .expect("isolated tuning child should receive n_steps")
            .parse::<usize>()
            .expect("isolated tuning n_steps should be an integer");
        run_isolated_tuning_child(index, n_steps);
        return;
    }
    run_combustion_tuning_scenario(1000, 4, "medium-grid-multi-toolchain")
        .expect("medium-grid multi-run AOT combustion tuning scenario should solve");
}

#[test]
#[ignore = "practical isolated cold combustion tuning table for Lambdify versus tcc chunking strategies"]
fn combustion_tcc_chunking_honest_wall_clock_table() {
    let n_steps = 1_000usize;
    let repetitions = 3usize;
    let variants = runtime_tuning_cold_variants();
    let selected = variants
        .iter()
        .enumerate()
        .filter(|(_, (label, _))| label == "lambdify-baseline" || label.starts_with("tcc/"))
        .map(|(index, (label, _))| (index, label.clone()))
        .collect::<Vec<_>>();
    assert_eq!(
        selected.len(),
        1 + 1 + runtime_tuning_parallel_cases().len(),
        "narrow cold table should contain Lambdify and every tcc chunking policy"
    );
    println!(
        "[AOT tcc practical cold map] n_steps={n_steps}, repetitions={repetitions}, cooldown_ms={}, cleanup_child_artifacts={}",
        cold_cooldown_ms(),
        clean_cold_artifacts_enabled()
    );

    let mut samples: Vec<(String, IsolatedColdObservation, f64)> = Vec::new();
    for repetition in 0..repetitions {
        let (baseline_index, baseline_label) = &selected[0];
        let baseline = solve_isolated_cold_tuning_variant(*baseline_index, n_steps);
        print_isolated_cold_raw_observation(repetition, baseline_label, &baseline);
        let baseline_solution = baseline.solution.clone();
        samples.push((baseline_label.clone(), baseline, 0.0));
        for (index, label) in selected.iter().skip(1) {
            let observation = solve_isolated_cold_tuning_variant(*index, n_steps);
            print_isolated_cold_raw_observation(repetition, label, &observation);
            let max_diff = baseline_solution
                .iter()
                .zip(observation.solution.iter())
                .map(|(&lhs, &rhs)| (lhs - rhs).abs())
                .fold(0.0, f64::max);
            assert!(
                max_diff < 1.0e-4,
                "{label}: isolated cold result differs from Lambdify by {max_diff}"
            );
            samples.push((label.clone(), observation, max_diff));
        }
    }

    println!();
    println!("[AOT tcc practical cold map] correctness and wall-clock table");
    println!(
        "{:<26} | {:<22} | {:<18} | {:<18} | {:<18}",
        "config", "honest_e2e_ms [min,max]", "max_diff", "symbolic_ms", "initial_sym_jac"
    );
    println!("{}", "-".repeat(114));
    for (_, label) in &selected {
        let rows = samples
            .iter()
            .filter(|(sample_label, _, _)| sample_label == label)
            .collect::<Vec<_>>();
        let total = runtime_tuning_aggregate(rows.iter().map(|(_, row, _)| row.elapsed_ms));
        let diff = runtime_tuning_aggregate(rows.iter().map(|(_, _, diff)| *diff));
        let symbolic =
            runtime_tuning_aggregate(rows.iter().map(|(_, row, _)| row.metrics.symbolic_ms));
        let sym_jac = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.initial_symbolic_jacobian_ms),
        );
        println!(
            "{:<26} | {:<22} | {:<18} | {:<18} | {:<18}",
            label,
            fmt_tuning_agg(total),
            fmt_tuning_exp(diff),
            fmt_tuning_short(symbolic),
            fmt_tuning_short(sym_jac)
        );
    }

    println!();
    println!("[AOT tcc practical cold map] build and callback stages from the same child solves");
    println!(
        "{:<26} | {:<18} | {:<18} | {:<18} | {:<18} | {:<12} | {:<12}",
        "config",
        "materialize_ms",
        "compile_link_ms",
        "residual_values",
        "jacobian_values",
        "res_jobs",
        "jac_jobs"
    );
    println!("{}", "-".repeat(132));
    for (_, label) in &selected {
        let rows = samples
            .iter()
            .filter(|(sample_label, _, _)| sample_label == label)
            .collect::<Vec<_>>();
        let materialize = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.aot_materialize_ms),
        );
        let compile_link = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.aot_compile_link_ms),
        );
        let residual = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.cb_residual_values_ms),
        );
        let jacobian = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.cb_jacobian_values_ms),
        );
        let res_jobs = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.residual_actual_jobs),
        );
        let jac_jobs = runtime_tuning_aggregate(
            rows.iter()
                .map(|(_, row, _)| row.metrics.sparse_jacobian_actual_jobs),
        );
        println!(
            "{:<26} | {:<18} | {:<18} | {:<18} | {:<18} | {:<12} | {:<12}",
            label,
            fmt_tuning_short(materialize),
            fmt_tuning_short(compile_link),
            fmt_tuning_short(residual),
            fmt_tuning_short(jacobian),
            fmt_tuning_short(res_jobs),
            fmt_tuning_short(jac_jobs)
        );
    }
}

/// Measures what fraction of total solve time is spent in residual+Jacobian eval
/// vs the linear solve and other Newton overhead.
///
/// If eval_fraction is small (< 0.3), parallelising the eval cannot give
/// more than 1/(1 - eval_fraction) speedup by Amdahl's law regardless of
/// how many cores are used.  That is the root cause of the 1.2x ceiling.
///
/// Run with: cargo test diagnose_eval_fraction -- --nocapture
#[test]
fn diagnose_eval_fraction_of_solve_time() {
    /*
     use std::hint::black_box;
    use crate::numerical::BVP_Damp::BVP_traits::Jac;
     let n_steps_list = [128usize, 256, 512, 1000];
     let iters = 50usize;

     println!(
         "\n=== Eval fraction of solve time (combustion, iters={iters}) ==="
     );
     println!(
         "{:<8} {:<10} {:<10} {:<12} {:<12} {:<14} {:<14}",
         "n_steps", "vars", "nnz",
         "full_ms", "eval_ms", "eval_frac", "amdahl_ceil"
     );

     for n_steps in n_steps_list {
         let sequential_config =
             crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                 .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly);
         let mut solver = make_combustion_solver(n_steps, sequential_config);
         let _guard = bootstrap_callable_aot_backend(
             &mut solver,
             &format!("eval-fraction-{n_steps}"),
         )
         .expect("bootstrap should succeed");

         // Full solve timing.
         let t_full = Instant::now();
         solver.try_solve().expect("solve should succeed");
         let full_ms = t_full.elapsed().as_secs_f64() * 1_000.0;

         // Isolate eval cost: call fun+jac directly iters times on the
         // converged solution so we measure hot-path eval, not convergence.
         let solution = solver
             .get_result()
             .expect("solution should be present after solve");
         let flat: Vec<f64> = solution.as_slice().to_vec();
         let col = faer::col::ColRef::from_slice(&flat).to_owned();

         let fun = &solver.fun;
         let jac: & Box<dyn Jac> = solver.jac.as_ref().expect("jac should be present");

         let t_eval = Instant::now();
         for _ in 0..iters {
             let r = fun.call(0.0, &col);
             black_box(r.len());
             let j = jac.call(0.0, &col);
             black_box(j.shape());
         }
         let eval_ms = t_eval.elapsed().as_secs_f64() * 1_000.0 / iters as f64;

         // Estimate Newton iterations from solve time and per-eval cost.
         let vars = 6 * n_steps;
         // nnz estimate: banded structure ~12 nonzeros per row for this problem
         let nnz_est = vars * 12;
         let eval_frac = eval_ms / (full_ms / iters as f64).max(eval_ms);
         // Amdahl ceiling: max speedup if eval is perfectly parallelised
         let amdahl_ceil = if eval_frac >= 1.0 {
             f64::INFINITY
         } else {
             1.0 / (1.0 - eval_frac)
         };

         println!(
             "{:<8} {:<10} {:<10} {:<12.3} {:<12.3} {:<14.3} {:<14.2}",
             n_steps, vars, nnz_est,
             full_ms, eval_ms, eval_frac, amdahl_ceil
         );

     }
     */
}
/// THE MOST IMPOTANT TEST FOR LINEAR SOLVERS COMPARISON: runs a full combustion-1000 eval+linear-solve and compares
#[test]
#[ignore = "heavy combustion-1000 linear-system story for sparse baseline vs consistent superblock solver"]
fn combustion_1000_linear_system_story_sparse_vs_banded_consistent() {
    #[derive(Debug)]
    struct Row {
        source: &'static str,
        matrix_backend: &'static str,
        variant: String,
        linear_solver: String,
        bootstrap_ms: f64,
        residual_diff: f64,
        jacobian_diff: f64,
        sparse_ms: f64,
        banded_ms: f64,
        layout: String,
        refinement: String,
        direct_rr: f64,
        final_rr: f64,
        solve_rr: f64,
        solve_diff: f64,
        relative_x_diff: f64,
        status: String,
    }

    let n_steps = 1000usize;
    let mut rows = Vec::new();
    println!(
        "[BVP Damp story] starting combustion-1000 linear-system comparison across sparse/banded backends"
    );

    let lambdify_sparse_config =
        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::SparseCol);

    println!("[BVP Damp story] bootstrapping lambdify sparse baseline");
    let mut baseline_solver = make_combustion_solver(n_steps, lambdify_sparse_config);
    let baseline_bootstrap_begin = Instant::now();
    baseline_solver
        .try_eq_generate(None, None)
        .expect("lambdify sparse combustion-1000 bootstrap should succeed");
    let baseline_bootstrap_ms = baseline_bootstrap_begin.elapsed().as_secs_f64() * 1_000.0;

    let baseline_args = flattened_initial_guess_state(
        &baseline_solver,
        baseline_solver.values.len() * n_steps,
        "combustion-1000-lambdify-sparse",
    );
    let (baseline_residual, baseline_dense_matrix, baseline_sparse_matrix, _) =
        eval_solver_callback_state(
            &mut baseline_solver,
            &baseline_args,
            MatrixBackend::SparseCol,
            "combustion-1000-lambdify-sparse",
        );
    let baseline_sparse_matrix =
        baseline_sparse_matrix.expect("sparse baseline should produce SparseColMat");
    let baseline_rhs: Vec<f64> = baseline_residual.iter().map(|value| -*value).collect();

    let baseline_sparse_begin = Instant::now();
    let baseline_sparse_solution =
        solve_sparse_lu_for_rhs(&baseline_sparse_matrix, baseline_rhs.as_slice());
    let baseline_sparse_ms = baseline_sparse_begin.elapsed().as_secs_f64() * 1_000.0;
    rows.push(Row {
        source: "Lambdify",
        matrix_backend: "Sparse",
        variant: "ExprLegacy".to_string(),
        linear_solver: "faer_sparse_lu".to_string(),
        bootstrap_ms: baseline_bootstrap_ms,
        residual_diff: 0.0,
        jacobian_diff: 0.0,
        sparse_ms: baseline_sparse_ms,
        banded_ms: 0.0,
        layout: "-".to_string(),
        refinement: "-".to_string(),
        direct_rr: 0.0,
        final_rr: 0.0,
        solve_rr: relative_dense_residual(
            &baseline_dense_matrix,
            &baseline_sparse_solution,
            baseline_rhs.as_slice(),
        ),
        solve_diff: 0.0,
        relative_x_diff: 0.0,
        status: "ok".to_string(),
    });

    let baseline_dense_banded_assembly = banded_assembly_from_dense_matrix(&baseline_dense_matrix);
    for solver_choice in BandedStorySolver::variants() {
        let banded_begin = Instant::now();
        let metrics = solve_banded_story_for_rhs(
            &baseline_dense_banded_assembly,
            n_steps,
            baseline_rhs.as_slice(),
            solver_choice,
        );
        let banded_ms = banded_begin.elapsed().as_secs_f64() * 1_000.0;
        let solve_diff = metrics
            .solution
            .as_ref()
            .map(|solution| {
                solution
                    .iter()
                    .zip(baseline_sparse_solution.iter())
                    .map(|(lhs, rhs)| (lhs - rhs).abs())
                    .fold(0.0_f64, f64::max)
            })
            .unwrap_or(f64::NAN);
        let rel_x = metrics
            .solution
            .as_ref()
            .map(|solution| relative_x_diff(solution, &baseline_sparse_solution))
            .unwrap_or(f64::NAN);
        let solve_rr = metrics
            .solution
            .as_ref()
            .map(|solution| {
                relative_dense_residual(&baseline_dense_matrix, solution, baseline_rhs.as_slice())
            })
            .unwrap_or(f64::NAN);
        rows.push(Row {
            source: "Derived",
            matrix_backend: "Sparse->Banded",
            variant: "DenseBaseline".to_string(),
            linear_solver: metrics.linear_solver,
            bootstrap_ms: 0.0,
            residual_diff: 0.0,
            jacobian_diff: 0.0,
            sparse_ms: 0.0,
            banded_ms,
            layout: metrics.layout,
            refinement: metrics
                .report
                .as_ref()
                .map(|report| {
                    format!(
                        "{}/{}{}",
                        report.accepted_steps,
                        report.requested_steps,
                        if report.refinement_attempted {
                            ""
                        } else {
                            " skipped"
                        }
                    )
                })
                .unwrap_or_else(|| "-".to_string()),
            direct_rr: metrics
                .report
                .as_ref()
                .map(|report| report.direct_relative_residual)
                .unwrap_or(f64::NAN),
            final_rr: metrics
                .report
                .as_ref()
                .map(|report| report.final_relative_residual)
                .unwrap_or(f64::NAN),
            solve_rr,
            solve_diff,
            relative_x_diff: rel_x,
            status: if metrics.status == "ok" {
                "diag".to_string()
            } else {
                metrics.status
            },
        });
    }

    let lambdify_banded_config =
        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);
    println!("[BVP Damp story] bootstrapping lambdify banded path");
    let mut lambdify_banded_solver = make_combustion_solver(n_steps, lambdify_banded_config);
    let lambdify_banded_bootstrap_begin = Instant::now();
    lambdify_banded_solver
        .try_eq_generate(None, None)
        .expect("lambdify banded combustion-1000 bootstrap should succeed");
    let lambdify_banded_bootstrap_ms =
        lambdify_banded_bootstrap_begin.elapsed().as_secs_f64() * 1_000.0;
    let lambdify_banded_args = flattened_initial_guess_state(
        &lambdify_banded_solver,
        lambdify_banded_solver.values.len() * n_steps,
        "combustion-1000-lambdify-banded",
    );
    let (lambdify_banded_residual, lambdify_banded_dense, _, lambdify_banded_matrix) =
        eval_solver_callback_state(
            &mut lambdify_banded_solver,
            &lambdify_banded_args,
            MatrixBackend::Banded,
            "combustion-1000-lambdify-banded",
        );
    let lambdify_banded_matrix =
        lambdify_banded_matrix.expect("banded lambdify path should produce BandedMatrixType");
    let lambdify_banded_rhs: Vec<f64> = lambdify_banded_residual
        .iter()
        .map(|value| -*value)
        .collect();
    for solver_choice in BandedStorySolver::variants() {
        let banded_begin = Instant::now();
        let metrics = solve_banded_story_for_rhs(
            &lambdify_banded_matrix.assembly,
            n_steps,
            lambdify_banded_rhs.as_slice(),
            solver_choice,
        );
        let banded_ms = banded_begin.elapsed().as_secs_f64() * 1_000.0;
        let solve_diff = metrics
            .solution
            .as_ref()
            .map(|solution| {
                solution
                    .iter()
                    .zip(baseline_sparse_solution.iter())
                    .map(|(lhs, rhs)| (lhs - rhs).abs())
                    .fold(0.0_f64, f64::max)
            })
            .unwrap_or(f64::NAN);
        let rel_x = metrics
            .solution
            .as_ref()
            .map(|solution| relative_x_diff(solution, &baseline_sparse_solution))
            .unwrap_or(f64::NAN);
        let solve_rr = metrics
            .solution
            .as_ref()
            .map(|solution| {
                relative_dense_residual(
                    &lambdify_banded_dense,
                    solution,
                    lambdify_banded_rhs.as_slice(),
                )
            })
            .unwrap_or(f64::NAN);
        rows.push(Row {
            source: "Lambdify",
            matrix_backend: "Banded",
            variant: "ExprLegacy".to_string(),
            linear_solver: metrics.linear_solver,
            bootstrap_ms: lambdify_banded_bootstrap_ms,
            residual_diff: max_abs_vector_diff(&lambdify_banded_residual, &baseline_residual),
            jacobian_diff: max_abs_matrix_diff(&lambdify_banded_dense, &baseline_dense_matrix),
            sparse_ms: 0.0,
            banded_ms,
            layout: metrics.layout,
            refinement: metrics
                .report
                .as_ref()
                .map(|report| {
                    format!(
                        "{}/{}{}",
                        report.accepted_steps,
                        report.requested_steps,
                        if report.refinement_attempted {
                            ""
                        } else {
                            " skipped"
                        }
                    )
                })
                .unwrap_or_else(|| "-".to_string()),
            direct_rr: metrics
                .report
                .as_ref()
                .map(|report| report.direct_relative_residual)
                .unwrap_or(f64::NAN),
            final_rr: metrics
                .report
                .as_ref()
                .map(|report| report.final_relative_residual)
                .unwrap_or(f64::NAN),
            solve_rr,
            solve_diff,
            relative_x_diff: rel_x,
            status: metrics.status,
        });
    }

    let compiled_sparse_variants = [
            (
                "C-gcc",
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                    .with_aot_codegen_backend(AotCodegenBackend::C)
                    .with_aot_c_compiler("gcc")
                    .with_aot_compile_dev_fastest()
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly)
                    .with_matrix_backend_override(MatrixBackend::SparseCol),
            ),
            (
                "C-tcc",
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                    .with_aot_codegen_backend(AotCodegenBackend::C)
                    .with_aot_c_compiler("tcc")
                    .with_aot_compile_dev_fastest()
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly)
                    .with_matrix_backend_override(MatrixBackend::SparseCol),
            ),
            (
                "Zig",
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                    .with_aot_codegen_backend(AotCodegenBackend::Zig)
                    .with_aot_compile_dev_fastest()
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly)
                    .with_matrix_backend_override(MatrixBackend::SparseCol),
            ),
        ];

    for (variant, config) in compiled_sparse_variants {
        println!("[BVP Damp story] bootstrapping compiled sparse variant `{variant}`");
        let mut solver = make_combustion_solver(n_steps, config);
        let bootstrap_begin = Instant::now();
        solver
            .try_eq_generate(None, None)
            .expect("compiled sparse combustion-1000 bootstrap should succeed");
        let bootstrap_ms = bootstrap_begin.elapsed().as_secs_f64() * 1_000.0;

        let args = flattened_initial_guess_state(
            &solver,
            solver.values.len() * n_steps,
            &format!("combustion-1000-sparse-{variant}"),
        );
        let (residual, dense_matrix, sparse_matrix, _) = eval_solver_callback_state(
            &mut solver,
            &args,
            MatrixBackend::SparseCol,
            &format!("combustion-1000-sparse-{variant}"),
        );
        let sparse_matrix =
            sparse_matrix.expect("compiled sparse path should produce SparseColMat");
        let rhs: Vec<f64> = residual.iter().map(|value| -*value).collect();

        let sparse_begin = Instant::now();
        let sparse_solution = solve_sparse_lu_for_rhs(&sparse_matrix, rhs.as_slice());
        let sparse_ms = sparse_begin.elapsed().as_secs_f64() * 1_000.0;

        rows.push(Row {
            source: "Compiled",
            matrix_backend: "Sparse",
            variant: variant.to_string(),
            linear_solver: "faer_sparse_lu".to_string(),
            bootstrap_ms,
            residual_diff: max_abs_vector_diff(&residual, &baseline_residual),
            jacobian_diff: max_abs_matrix_diff(&dense_matrix, &baseline_dense_matrix),
            sparse_ms,
            banded_ms: 0.0,
            layout: "-".to_string(),
            refinement: "-".to_string(),
            direct_rr: 0.0,
            final_rr: 0.0,
            solve_rr: relative_dense_residual(&dense_matrix, &sparse_solution, rhs.as_slice()),
            solve_diff: sparse_solution
                .iter()
                .zip(baseline_sparse_solution.iter())
                .map(|(lhs, rhs)| (lhs - rhs).abs())
                .fold(0.0_f64, f64::max),
            relative_x_diff: relative_x_diff(&sparse_solution, &baseline_sparse_solution),
            status: "ok".to_string(),
        });
    }

    let compiled_banded_variants = [
            (
                "C-gcc",
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                    .with_aot_codegen_backend(AotCodegenBackend::C)
                    .with_aot_c_compiler("gcc")
                    .with_aot_compile_dev_fastest()
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly)
                    .with_matrix_backend_override(MatrixBackend::Banded),
            ),
            (
                "C-tcc",
                crate::numerical::BVP_Damp::generated_solver_handoff::GeneratedBackendConfig::sparse_build_if_missing_release()
                    .with_symbolic_assembly_backend(BvpSymbolicAssemblyBackend::AtomView)
                    .with_aot_codegen_backend(AotCodegenBackend::C)
                    .with_aot_c_compiler("tcc")
                    .with_aot_compile_dev_fastest()
                    .with_aot_execution_policy(AotExecutionPolicy::SequentialOnly)
                    .with_matrix_backend_override(MatrixBackend::Banded),
            ),
        ];

    for (variant, config) in compiled_banded_variants {
        println!("[BVP Damp story] bootstrapping compiled banded variant `{variant}`");
        let mut solver = make_combustion_solver(n_steps, config);
        let bootstrap_begin = Instant::now();
        solver
            .try_eq_generate(None, None)
            .expect("compiled banded combustion-1000 bootstrap should succeed");
        let bootstrap_ms = bootstrap_begin.elapsed().as_secs_f64() * 1_000.0;

        let args = flattened_initial_guess_state(
            &solver,
            solver.values.len() * n_steps,
            &format!("combustion-1000-banded-{variant}"),
        );
        let (residual, dense_matrix, _, banded_matrix) = eval_solver_callback_state(
            &mut solver,
            &args,
            MatrixBackend::Banded,
            &format!("combustion-1000-banded-{variant}"),
        );
        let banded_matrix =
            banded_matrix.expect("compiled banded path should produce BandedMatrixType");
        let rhs: Vec<f64> = residual.iter().map(|value| -*value).collect();

        for solver_choice in BandedStorySolver::variants() {
            let banded_begin = Instant::now();
            let metrics = solve_banded_story_for_rhs(
                &banded_matrix.assembly,
                n_steps,
                rhs.as_slice(),
                solver_choice,
            );
            let banded_ms = banded_begin.elapsed().as_secs_f64() * 1_000.0;
            let solve_diff = metrics
                .solution
                .as_ref()
                .map(|solution| {
                    solution
                        .iter()
                        .zip(baseline_sparse_solution.iter())
                        .map(|(lhs, rhs)| (lhs - rhs).abs())
                        .fold(0.0_f64, f64::max)
                })
                .unwrap_or(f64::NAN);
            let rel_x = metrics
                .solution
                .as_ref()
                .map(|solution| relative_x_diff(solution, &baseline_sparse_solution))
                .unwrap_or(f64::NAN);
            let solve_rr = metrics
                .solution
                .as_ref()
                .map(|solution| relative_dense_residual(&dense_matrix, solution, rhs.as_slice()))
                .unwrap_or(f64::NAN);

            rows.push(Row {
                source: "Compiled",
                matrix_backend: "Banded",
                variant: variant.to_string(),
                linear_solver: metrics.linear_solver,
                bootstrap_ms,
                residual_diff: max_abs_vector_diff(&residual, &baseline_residual),
                jacobian_diff: max_abs_matrix_diff(&dense_matrix, &baseline_dense_matrix),
                sparse_ms: 0.0,
                banded_ms,
                layout: metrics.layout,
                refinement: metrics
                    .report
                    .as_ref()
                    .map(|report| {
                        format!(
                            "{}/{}{}",
                            report.accepted_steps,
                            report.requested_steps,
                            if report.refinement_attempted {
                                ""
                            } else {
                                " skipped"
                            }
                        )
                    })
                    .unwrap_or_else(|| "-".to_string()),
                direct_rr: metrics
                    .report
                    .as_ref()
                    .map(|report| report.direct_relative_residual)
                    .unwrap_or(f64::NAN),
                final_rr: metrics
                    .report
                    .as_ref()
                    .map(|report| report.final_relative_residual)
                    .unwrap_or(f64::NAN),
                solve_rr,
                solve_diff,
                relative_x_diff: rel_x,
                status: metrics.status,
            });
        }
    }

    println!("[BVP Damp linear story] combustion-1000 sparse baseline vs banded solver variants");
    println!(
        "{:<10} | {:<13} | {:<10} | {:<34} | {:>12} | {:>12} | {:>12} | {:>10} | {:>10} | {:<8} | {:<13} | {:>10} | {:>10} | {:>10} | {:>12} | {:>12} | {:<24}",
        "source",
        "matrix",
        "variant",
        "linear_solver",
        "bootstrap_ms",
        "res_diff",
        "jac_diff",
        "sparse_ms",
        "banded_ms",
        "layout",
        "refinement",
        "direct_rr",
        "final_rr",
        "solve_rr",
        "solve_diff",
        "rel_x_diff",
        "status"
    );
    println!("{}", "-".repeat(262));
    for row in &rows {
        println!(
            "{:<10} | {:<13} | {:<10} | {:<34} | {:>12.3} | {:>12.3e} | {:>12.3e} | {:>10.3} | {:>10.3} | {:<8} | {:<13} | {:>10} | {:>10} | {:>10} | {:>12.3e} | {:>12.3e} | {:<24}",
            row.source,
            row.matrix_backend,
            row.variant,
            row.linear_solver,
            row.bootstrap_ms,
            row.residual_diff,
            row.jacobian_diff,
            row.sparse_ms,
            row.banded_ms,
            row.layout,
            row.refinement,
            fmt_metric(row.direct_rr),
            fmt_metric(row.final_rr),
            fmt_metric(row.solve_rr),
            row.solve_diff,
            row.relative_x_diff,
            row.status
        );
    }

    for row in &rows {
        assert!(
            row.residual_diff < 1e-6,
            "{} {} {} residual diff too large: {}",
            row.source,
            row.matrix_backend,
            row.variant,
            row.residual_diff
        );
        assert!(
            row.jacobian_diff < 1e-6,
            "{} {} {} jacobian diff too large: {}",
            row.source,
            row.matrix_backend,
            row.variant,
            row.jacobian_diff
        );
        if row.matrix_backend == "Sparse" {
            assert!(
                row.solve_diff < 1e-6,
                "{} {} {} sparse solve drift too large: {}",
                row.source,
                row.matrix_backend,
                row.variant,
                row.solve_diff
            );
        } else if row.matrix_backend.contains("Banded") && row.status == "ok" {
            assert!(
                row.solve_diff.is_finite(),
                "{} {} {} {} should report finite banded solve_diff",
                row.source,
                row.matrix_backend,
                row.variant,
                row.linear_solver
            );
        }
    }
}