Something went wrong. Try again.
Exploring the idea of generated web rendering engine.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161//! [`bin/relpos_generation_loop.rs`](../relpos_generation_loop.rs)'s counterpart for the//! block-height seam: compiles the hand-written candidates in//! `crates/generation/fixtures/height-candidates` into one batch crate, runs every//! candidate over the cached corpus, and gates each against the permanent regression set//! (`generation::height_runner::evaluate`). Requires `height_ground_truth_cache` to have//! already populated `corpus/block-height-ground-truth/` -- this seam's own cache.//!//! The one structural difference from every other seam's own generation-loop binary: the//! `baseline` fixture here is *correct*, not deliberately wrong//! (`specs/block-height-equation.md` -> "Stage 1"). It is the rule `layout::fragment` ran//! inline before the extraction, so seeding the permanent regression set from its own//! passing cases seeds it from a correct rule rather than from a placeholder's accidental//! passes -- which makes this the one seam whose gate is tight from the first run, and the//! reason both seeded-wrong fixtures below can be checked on `admitted` directly instead of//! on a bare `cases_passed` count the way `bin/relpos_generation_loop.rs` has to.
use std::fs;
use anyhow::{bail, Result};use generation::groundtruth::load_all;use generation::height_runner::passing_case_ids;use generation::model::{CandidateSource, DirectoryCandidateSource};use generation::orchestrate::{repo_root, run_candidates, write_regression_set};use generation::{admit, candidate_crate, css21_block_height, prompt};use layout::height::{resolve_baseline, HeightResolver};
fn main() -> Result<()> { let repo_root = repo_root(); let cache_dir = repo_root.join("corpus/block-height-ground-truth"); let cases = load_all(&cache_dir)?; if cases.is_empty() { bail!( "no cached cases under {}; run the height_ground_truth_cache binary first", cache_dir.display() ); }
let fixtures_dir = repo_root.join("crates/generation/fixtures/height-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/height-generated"); candidate_crate::write_for(candidate_crate::Seam::Height, &crate_dir, &repo_root, &candidates)?; let binary = candidate_crate::compile(&crate_dir, &crate_dir.join("target"))?;
let regression_set_path = repo_root.join("corpus/block-height-regression-set.json"); let report_out = repo_root.join("corpus/candidates/block-height-report.json");
// Seeded from the baseline's own passing cases, as every other seam's loop does -- but // here that baseline is the correct extracted rule rather than a placeholder (this // binary's own module doc), so the seeded set is as wide as the corpus allows from the // first run. let baseline_passing: Vec<String> = passing_case_ids(resolve_baseline as HeightResolver, &cases); if !regression_set_path.exists() { write_regression_set(®ression_set_path, &baseline_passing)?; println!( "seeded the permanent regression set with {} case(s) the Stage-1 baseline already passes", baseline_passing.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); } }
let get = |name: &str| gated.candidates.iter().find(|c| c.name == name);
// The positive half of the discrimination proof, which only this seam can run: the // baseline is the correct rule, so it must come back admitted. Every other seam's // loop has no correct candidate to check this side with. match get("baseline") { Some(baseline) if !baseline.admitted => { bail!( "the Stage-1 baseline was not admitted against a regression set seeded from its own \ passing cases ({}/{} passed, {} regressed) -- the gate is inconsistent with itself", baseline.cases_passed, baseline.cases_run, baseline.regressed_cases.len() ); } Some(baseline) => { println!("\nthe Stage-1 baseline is admitted, as a correct candidate must be");
// Record the baseline's measured score as the committed candidate's own // provenance, if nothing is committed yet. This is what gives // `admit::beats_committed` a score to protect during // `bin/height_real_model_run.rs`: without it the committed // `crates/layout/src/generated/height.rs` reads as `CommittedScore::Missing` // and the first model candidate to be admitted at all would overwrite a // correct-by-construction extraction regardless of how it scored // (`specs/block-height-equation.md` -> "Admission is different here than on // the other seams"). `prompt::HAND_WRITTEN_SEED` and the `"hand-written"` // model label are the same markers every other seam's hand-written record // carries; the prompt hash is of the prompt this seam's model run will send, // since no prompt produced this candidate. let generated_dir = repo_root.join("crates/layout/src/generated"); let provenance_path = generated_dir.join("height.provenance.json"); match admit::read_committed_score(&provenance_path) { admit::CommittedScore::Existing { cases_passed, cases_run } => println!( "a candidate is already committed at {} ({cases_passed}/{cases_run}); leaving it alone", provenance_path.display() ), _ => { let seam_source = fs::read_to_string(repo_root.join("crates/layout/src/height.rs"))?; let built_prompt = prompt::build_block_height(css21_block_height::SPEC_TEXT, &seam_source, &[]); let record = admit::record_for_block_height( baseline, "hand-written", &built_prompt.hash, prompt::HAND_WRITTEN_SEED, ); admit::write(&generated_dir, "height", &record)?; println!( "recorded the Stage-1 baseline as the committed candidate at {} ({}/{})", provenance_path.display(), baseline.cases_passed, baseline.cases_run ); } } } None => bail!("no candidate named \"baseline\" in the batch"), }
// The negative half: every seeded-wrong candidate must be rejected. let wrong_names = ["ignores_float_extension", "pins_height_to_lowest_float"]; 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!("gate rejected every seeded-wrong candidate");
Ok(())}