Something went wrong. Try again.
Exploring the idea of generated web rendering engine.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122//! [`bin/absolute_generation_loop.rs`](../absolute_generation_loop.rs)'s counterpart for//! the transform function: compiles the hand-written candidates in//! `crates/generation/fixtures/transform-candidates` into one batch crate, runs every//! candidate over the cached corpus, and gates each against the permanent regression set//! (`generation::transform_runner::evaluate`). Requires `transform_ground_truth_cache` to//! have already populated `corpus/transform-ground-truth/`.//!//! Like the absolute-positioning loop, this one never admits anything://! `specs/transforms2d.md` is explicit that a correct implementation is not written by//! hand before every model batch has failed, so there is no `correct` fixture here, 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::groundtruth::load_all;use generation::model::{CandidateSource, DirectoryCandidateSource};use generation::orchestrate::{repo_root, run_candidates, write_regression_set};use generation::transform_runner::passing_case_ids;use layout::transform::{resolve_baseline, TransformResolver};
fn main() -> Result<()> { let repo_root = repo_root(); let cache_dir = repo_root.join("corpus/transform-ground-truth"); let cases = load_all(&cache_dir)?; if cases.is_empty() { bail!( "no cached cases under {}; run the transform_ground_truth_cache binary first", cache_dir.display() ); }
let fixtures_dir = repo_root.join("crates/generation/fixtures/transform-candidates"); let candidates = DirectoryCandidateSource { dir: fixtures_dir }.candidates()?; println!( "candidates: {}", candidates.iter().map(|c| c.name.as_str()).collect::<Vec<_>>().join(", ") );
let crate_dir = repo_root.join("corpus/candidates/transform-generated"); candidate_crate::write_for(candidate_crate::Seam::Transform, &crate_dir, &repo_root, &candidates)?; let binary = candidate_crate::compile(&crate_dir, &crate_dir.join("target"))?;
let regression_set_path = repo_root.join("corpus/transform-regression-set.json"); let report_out = repo_root.join("corpus/candidates/transform-report.json");
// Seeded from every case any hand-written fixture passes -- the shipped (deliberately // wrong) baseline's own and both seeded-wrong candidates' -- not the baseline's // alone, the way `bin/absolute_generation_loop.rs` seeds, and for the same reason // `bin/float_generation_loop.rs` already seeds this way. 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. // // The baseline alone is not enough here and the first run proved it: the baseline // returns the identity, so the only cases it passes are the `rotate(180deg)` ones, // whose bounding box is the untransformed one. `composes_right_to_left` passes all // three of those and 84 more, so a no-loss gate seeded from the baseline had nothing // to catch it on and admitted it at 87/110 (`docs/model-first-cost.md` -> // "Transforms"). The union puts the order categories in the regression set, which is // exactly what a right-to-left candidate loses. if !regression_set_path.exists() { let ungated = run_candidates(&binary, &cache_dir, None, &report_out)?; let mut seed: Vec<String> = passing_case_ids(resolve_baseline as TransformResolver, &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:<32} {}/{}", 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_transform_origin", "composes_right_to_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(())}