//! [`bin/absolute_generation_loop.rs`](../absolute_generation_loop.rs)'s counterpart for //! the floats/block-formatting-context seam: compiles the hand-written candidates in //! `crates/generation/fixtures/float-candidates` into one batch crate, runs every //! candidate over the cached corpus, and gates each against the permanent regression set //! (`generation::float_runner::evaluate`). Requires `float_ground_truth_cache` to have //! already populated `corpus/float-ground-truth/` -- this seam's own cache, separate from //! the one the width/margin-collapse/percentage-resolution seams share (none of which //! generate `float`). //! //! Unlike every other seam's own generation-loop binary, this one never admits anything: //! `specs/floats-bfc.md` is explicit that a correct float implementation is not written //! by hand before every model batch has failed, so there is no `correct` fixture here to //! admit, only `baseline` and two deliberately wrong candidates this binary proves the //! gate rejects. All three seed the regression set (the comment at the seeding site //! says why the baseline alone is not enough here). use anyhow::{bail, Result}; use generation::candidate_crate; use generation::float_runner::passing_case_ids; use generation::groundtruth::load_all; use generation::model::{CandidateSource, DirectoryCandidateSource}; use generation::orchestrate::{repo_root, run_candidates, write_regression_set}; use layout::float::{resolve_baseline, FloatResolver}; fn main() -> Result<()> { let repo_root = repo_root(); let cache_dir = repo_root.join("corpus/float-ground-truth"); let cases = load_all(&cache_dir)?; if cases.is_empty() { bail!("no cached cases under {}; run the float_ground_truth_cache binary first", cache_dir.display()); } let fixtures_dir = repo_root.join("crates/generation/fixtures/float-candidates"); let candidates = DirectoryCandidateSource { dir: fixtures_dir }.candidates()?; println!( "candidates: {}", candidates.iter().map(|c| c.name.as_str()).collect::>().join(", ") ); let crate_dir = repo_root.join("corpus/candidates/float-generated"); candidate_crate::write_for(candidate_crate::Seam::Floats, &crate_dir, &repo_root, &candidates)?; let binary = candidate_crate::compile(&crate_dir, &crate_dir.join("target"))?; let regression_set_path = repo_root.join("corpus/float-regression-set.json"); let report_out = repo_root.join("corpus/candidates/float-report.json"); // Seeded from every case any hand-written fixture passes -- the shipped (deliberately // wrong) baseline's own and the two seeded-wrong candidates' -- not the baseline's // alone, the way `bin/absolute_generation_loop.rs` seeds. Each seeded-wrong fixture // is wrong in one respect and right in the others, so the union is the set of cases // known to be achievable, and a candidate wrong in any one of those respects loses // some of it. Seeding from the baseline alone cannot reject a fixture that merely // ignores `clear`: the baseline ignores `clear` too, so that fixture strictly // improves on it and a no-loss gate has nothing to catch it on // (`docs/model-first-cost.md` -> "Batch scores and token totals", floats). if !regression_set_path.exists() { let ungated = run_candidates(&binary, &cache_dir, None, &report_out)?; let mut seed: Vec = passing_case_ids(resolve_baseline as FloatResolver, &cases); for candidate in &ungated.candidates { for id in &candidate.passed_case_ids { if !seed.contains(id) { seed.push(id.clone()); } } } write_regression_set(®ression_set_path, &seed)?; println!( "seeded the permanent regression set with {} case(s) at least one fixture already passes", seed.len() ); } let gated = run_candidates(&binary, &cache_dir, Some(®ression_set_path), &report_out)?; println!("\n== per-candidate results =="); for candidate in &gated.candidates { println!( "{:<28} {}/{} passed, admitted={}, regressed={}", candidate.name, candidate.cases_passed, candidate.cases_run, candidate.admitted, candidate.regressed_cases.len(), ); let mut categories: Vec<_> = candidate.per_category.iter().collect(); categories.sort_by_key(|(name, _)| (*name).clone()); for (category, tally) in categories { println!(" {category:<28} {}/{}", tally.passed, tally.total); } } // Prove the gate discriminates: every seeded-wrong candidate must not be admitted, // given this fixture set. No `correct` candidate exists yet to also check the // positive case with (this binary's own module doc). let get = |name: &str| gated.candidates.iter().find(|c| c.name == name); let wrong_names = ["ignores_clearance", "pins_every_float_left"]; let mut discrimination_ok = true; for name in wrong_names { match get(name) { Some(wrong) if wrong.admitted => { discrimination_ok = false; eprintln!("gate did not reject seeded-wrong candidate {name}"); } Some(_) => {} None => bail!("no candidate named {name:?} in the batch"), } } if !discrimination_ok { bail!("the generation loop did not reject every seeded-wrong candidate"); } println!("\ngate rejected every seeded-wrong candidate"); Ok(()) }