From 82eaa39da3b469722cbf0800b00836d561fc1bab Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 05:33:19 +0000 Subject: [PATCH 1/6] =?UTF-8?q?uorc:=20the=20performance=20vocabulary=20(s?= =?UTF-8?q?tep=20measure,=20codec=20point,=20corpus=20=CE=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A step is one model input evaluated for one coded bit, read from a frame header alone. A codec point names basis, profile word, state and lanes. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_013Asa3LszhHCxmceQ2V8xxx --- crates/uorc/src/lib.rs | 1 + crates/uorc/src/performance.rs | 163 +++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 crates/uorc/src/performance.rs diff --git a/crates/uorc/src/lib.rs b/crates/uorc/src/lib.rs index 481e7896..5cc9b14a 100644 --- a/crates/uorc/src/lib.rs +++ b/crates/uorc/src/lib.rs @@ -61,6 +61,7 @@ pub mod archive; pub mod chunk; mod frame; pub mod ncm; +pub mod performance; pub mod portfolio; mod store; pub mod tree; diff --git a/crates/uorc/src/performance.rs b/crates/uorc/src/performance.rs new file mode 100644 index 00000000..5a105b46 --- /dev/null +++ b/crates/uorc/src/performance.rs @@ -0,0 +1,163 @@ +//! The performance vocabulary of the Prism model (`Uorc.Performance`), as the +//! native client computes it: the step measure and the codec point. +//! +//! A **step** is one model input evaluated for one coded bit. It is exact and +//! deterministic, and it is read from a frame's header alone: a raw frame +//! costs one step per output byte (the copy), a reference frame costs none +//! (its bytes were produced once already), and an ncm frame costs eight bits +//! times the inputs its profile word keeps, per output byte, plus one step per +//! byte when the x86 filter runs. The constants are the model's; the test +//! in `tests/performance.rs` reads them from the module text. + +use crate::frame::{Info, Representation}; +use crate::ncm; +use sha2::{Digest, Sha256}; + +/// Coded bits per output byte. +pub const BITS_PER_BYTE: u64 = 8; +/// Inputs every ncm profile evaluates beside its contexts: the match model's +/// two and the bias. +pub const FIXED_INPUTS: u32 = 3; +/// Inputs each optional model (short match, repeat distance) adds. +pub const FEATURE_INPUTS: u32 = 2; +/// Context bits of a profile word. +pub const CONTEXT_BITS: u32 = 17; +/// The most inputs any profile evaluates: 17 contexts, the fixed 3, two features. +pub const MAX_INPUTS: u32 = CONTEXT_BITS + FIXED_INPUTS + 2 * FEATURE_INPUTS; +/// The bound of `Uorc.Performance.decodeStepsBound`: no frame costs more +/// steps per output byte than this (the full model over the x86 filter). +pub const MAX_STEPS_PER_BYTE: u64 = BITS_PER_BYTE * MAX_INPUTS as u64 + 1; +/// Domain tag of a codec point's identity. +pub const CODEC_POINT_TAG: &[u8] = b"uorc/codec-point/1"; + +/// Model inputs an ncm frame coded under `profile` evaluates per bit. +pub fn inputs(profile: u32) -> u32 { + (profile & ((1 << CONTEXT_BITS) - 1)).count_ones() + + FIXED_INPUTS + + FEATURE_INPUTS * u32::from(profile & ncm::F_SHORT != 0) + + FEATURE_INPUTS * u32::from(profile & ncm::F_REP != 0) +} + +/// Steps to decode `n` output bytes of a frame of this representation and +/// profile word; `None` for a representation the model states no measure for +/// (the ulz decoders kept for earlier archives, and searched programs). +pub fn steps(representation: Representation, profile: Option, n: u64) -> Option { + match representation { + Representation::Raw => Some(n), + Representation::Reference => Some(0), + Representation::Ncm => { + Some(BITS_PER_BYTE * u64::from(inputs(profile.unwrap_or(ncm::V03))) * n) + } + Representation::NcmX86 => { + Some((BITS_PER_BYTE * u64::from(inputs(profile.unwrap_or(ncm::V03))) + 1) * n) + } + Representation::Ulz | Representation::UlzKernel | Representation::Program => None, + } +} + +/// [`steps`] of the frame a header describes. +pub fn frame_steps(info: &Info) -> Option { + steps(info.representation, info.ncm_profile, info.output_len) +} + +/// A point of the codec space: which decoder basis, profile word, consolidated +/// model state and lane count code a frame. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct CodecPoint { + /// The basis identity the frame names (the export's library), zeros when + /// the frame is self-contained. + pub basis: [u8; 32], + /// The ncm profile word, 0 when the frame applies no ncm decoder. + pub profile: u32, + /// κ of the consolidated model state the frame starts from, zeros for none. + pub state: [u8; 32], + /// Lanes the frame is coded in (1 for a single stream). + pub lanes: u32, +} + +impl CodecPoint { + /// The point of the frame a header describes (no state, one lane). + pub fn of(info: &Info) -> CodecPoint { + CodecPoint { + basis: info.basis.unwrap_or([0; 32]), + profile: info.ncm_profile.unwrap_or(0), + state: [0; 32], + lanes: 1, + } + } + + /// κ of the point: SHA-256 over the tag, the basis, the profile word + /// (little-endian), the state and the lane count (little-endian). + pub fn kappa(&self) -> [u8; 32] { + let mut h = Sha256::new(); + h.update(CODEC_POINT_TAG); + h.update(self.basis); + h.update(self.profile.to_le_bytes()); + h.update(self.state); + h.update(self.lanes.to_le_bytes()); + h.finalize().into() + } +} + +/// κ of a corpus: SHA-256 over `uorc/corpus/1` and, for each object in order, +/// its name length (u32 LE), name, SHA-256 and length (u64 LE). +pub fn corpus_kappa<'a>(objects: impl IntoIterator) -> [u8; 32] { + let mut h = Sha256::new(); + h.update(b"uorc/corpus/1"); + for (name, digest, len) in objects { + h.update((name.len() as u32).to_le_bytes()); + h.update(name.as_bytes()); + h.update(digest); + h.update(len.to_le_bytes()); + } + h.finalize().into() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn steps_follow_the_profile_word() { + assert_eq!(inputs(ncm::V03), 20); + assert_eq!(inputs(ncm::FULL), MAX_INPUTS); + assert_eq!(steps(Representation::Raw, None, 10), Some(10)); + assert_eq!(steps(Representation::Reference, None, 10), Some(0)); + assert_eq!(steps(Representation::Ncm, Some(ncm::FULL), 10), Some(1920)); + assert_eq!( + steps(Representation::NcmX86, Some(ncm::FULL), 10), + Some(10 * MAX_STEPS_PER_BYTE) + ); + for profile in [ncm::V03, ncm::FULL, 1, 0x7ffff] { + assert!(inputs(profile) <= MAX_INPUTS); + } + } + + #[test] + fn a_codec_point_is_named_by_all_its_coordinates() { + let p = CodecPoint { + basis: [1; 32], + profile: ncm::FULL, + state: [0; 32], + lanes: 1, + }; + assert_ne!(p.kappa(), CodecPoint { lanes: 2, ..p }.kappa()); + assert_ne!( + p.kappa(), + CodecPoint { + state: [2; 32], + ..p + } + .kappa() + ); + assert_ne!( + p.kappa(), + CodecPoint { + profile: ncm::V03, + ..p + } + .kappa() + ); + assert_eq!(p.kappa(), p.kappa()); + } +} From 1cc7ed334e10b8b2213619fc7e35f2a510949be2 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 05:38:29 +0000 Subject: [PATCH 2/6] uorc: an x86-filtered frame costs the same steps as its profile Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_013Asa3LszhHCxmceQ2V8xxx --- crates/uorc/src/performance.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/uorc/src/performance.rs b/crates/uorc/src/performance.rs index 5a105b46..9a5e7051 100644 --- a/crates/uorc/src/performance.rs +++ b/crates/uorc/src/performance.rs @@ -5,9 +5,9 @@ //! deterministic, and it is read from a frame's header alone: a raw frame //! costs one step per output byte (the copy), a reference frame costs none //! (its bytes were produced once already), and an ncm frame costs eight bits -//! times the inputs its profile word keeps, per output byte, plus one step per -//! byte when the x86 filter runs. The constants are the model's; the test -//! in `tests/performance.rs` reads them from the module text. +//! times the inputs its profile word keeps, per output byte, with or without +//! the x86 filter. The constants are the model's; `tests/performance.rs` +//! reads them from the module text. use crate::frame::{Info, Representation}; use crate::ncm; @@ -25,8 +25,8 @@ pub const CONTEXT_BITS: u32 = 17; /// The most inputs any profile evaluates: 17 contexts, the fixed 3, two features. pub const MAX_INPUTS: u32 = CONTEXT_BITS + FIXED_INPUTS + 2 * FEATURE_INPUTS; /// The bound of `Uorc.Performance.decodeStepsBound`: no frame costs more -/// steps per output byte than this (the full model over the x86 filter). -pub const MAX_STEPS_PER_BYTE: u64 = BITS_PER_BYTE * MAX_INPUTS as u64 + 1; +/// steps per output byte than this (the full model). +pub const MAX_STEPS_PER_BYTE: u64 = BITS_PER_BYTE * MAX_INPUTS as u64; /// Domain tag of a codec point's identity. pub const CODEC_POINT_TAG: &[u8] = b"uorc/codec-point/1"; @@ -45,12 +45,9 @@ pub fn steps(representation: Representation, profile: Option, n: u64) -> Op match representation { Representation::Raw => Some(n), Representation::Reference => Some(0), - Representation::Ncm => { + Representation::Ncm | Representation::NcmX86 => { Some(BITS_PER_BYTE * u64::from(inputs(profile.unwrap_or(ncm::V03))) * n) } - Representation::NcmX86 => { - Some((BITS_PER_BYTE * u64::from(inputs(profile.unwrap_or(ncm::V03))) + 1) * n) - } Representation::Ulz | Representation::UlzKernel | Representation::Program => None, } } From 7f4e64ab81f4a6ebb1e5b6d8900d4dcf621bd65a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 05:51:25 +0000 Subject: [PATCH 3/6] Prism model Uorc.Engine; the portfolio as a data table the engine consolidates Uorc.Engine (src/Uorc/Engine.lex.tex) states the engine that moves the codec through its space, with kernel-checked laws: exact rule 30 on a 64-cell ring (stepFromBelowPow2, closed vectors), bounded Hebbian weights 1..16 (+2/-1), the winner of a proved dominance is scheduled before the incumbent it beat, dominance in bytes and steps is a strict partial order that never costs bytes, a result known by its kappa is never rerun, and the generated workflow's schedule and budgets are valid. The portfolio becomes data in the byte form the model's compress reads (5 bytes per strategy: u32 LE profile word with bit 31 = x86, state byte; one weight per family and strategy). crates/uorc/src/weights.rs is the shipped table, generated by the engine from model/engine.toml and seeded with the v0.4 table. compress_stream_with codes under any table. The hand-run learning (examples/portfolio_outcomes.rs, portfolio-outcomes.tsv) is superseded by the engine. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3LeJgXkUvvAfeAGt9A --- crates/uorc/examples/portfolio_outcomes.rs | 60 ---- crates/uorc/src/lib.rs | 63 +++- crates/uorc/src/portfolio-outcomes.tsv | 334 --------------------- crates/uorc/src/portfolio.rs | 227 +++++++------- crates/uorc/src/weights.rs | 14 + src/Uorc/Engine.lex.tex | 334 +++++++++++++++++++++ 6 files changed, 529 insertions(+), 503 deletions(-) delete mode 100644 crates/uorc/examples/portfolio_outcomes.rs delete mode 100644 crates/uorc/src/portfolio-outcomes.tsv create mode 100644 crates/uorc/src/weights.rs create mode 100644 src/Uorc/Engine.lex.tex diff --git a/crates/uorc/examples/portfolio_outcomes.rs b/crates/uorc/examples/portfolio_outcomes.rs deleted file mode 100644 index 2bb1d31e..00000000 --- a/crates/uorc/examples/portfolio_outcomes.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! Regenerates `src/portfolio-outcomes.tsv`, the measured outcomes the -//! portfolio's weight table is learned from (`portfolio::WEIGHTS`, checked by -//! the test `weights_are_learned_from_the_outcomes`): -//! -//! ```text -//! cargo run --release -p uorc --example portfolio_outcomes -- FILE... > crates/uorc/src/portfolio-outcomes.tsv -//! ``` -//! -//! Each file is one training frame (at most `uorc::FRAME` bytes are read). -//! Lines are sorted by file name, so the order the table learns in is fixed; -//! after regenerating, update `WEIGHTS` to what the test reports. -use uorc::{ncm, portfolio, x86}; - -fn main() { - let mut files: Vec = std::env::args().skip(1).collect(); - files.sort_by_key(|f| { - std::path::Path::new(f) - .file_name() - .map(|n| n.to_string_lossy().into_owned()) - }); - println!("# uorc strategy portfolio training outcomes: one frame per line."); - println!("# Columns: frame length, family, then the ncm payload length of each strategy in portfolio order"); - println!("# (FULL, FULL over x86, MID, MID over x86, V03, V03 over x86); the frame length + 50 when the coder declined."); - println!("# Generated by crates/uorc/examples/portfolio_outcomes.rs."); - println!("# Training set: describe it here; files sorted by name."); - let next = std::sync::atomic::AtomicUsize::new(0); - let mut rows = vec![String::new(); files.len()]; - let slots: Vec> = - rows.iter_mut().map(std::sync::Mutex::new).collect(); - std::thread::scope(|s| { - for _ in 0..uorc::default_threads() { - s.spawn(|| loop { - let i = next.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - let Some(f) = files.get(i) else { break }; - **slots[i].lock().expect("slot") = outcome(f); - }); - } - }); - for r in rows { - println!("{r}"); - } -} - -/// One training line for the frame `f`. -fn outcome(f: &str) -> String { - let mut d = std::fs::read(f).expect("readable file"); - d.truncate(uorc::FRAME); - let n = d.len(); - let filtered = x86::filter(&d, false, 0).0; - let sizes: Vec = portfolio::STRATEGIES - .iter() - .map(|st| { - let src = if st.x86 { &filtered } else { &d }; - ncm::encode_profile(&[], src, st.profile) - .map_or(n + 50, |p| p.len().min(n + 50)) - .to_string() - }) - .collect(); - format!("{n}\t{}\t{}", portfolio::family(&d), sizes.join("\t")) -} diff --git a/crates/uorc/src/lib.rs b/crates/uorc/src/lib.rs index 5cc9b14a..86e72e23 100644 --- a/crates/uorc/src/lib.rs +++ b/crates/uorc/src/lib.rs @@ -66,6 +66,7 @@ pub mod portfolio; mod store; pub mod tree; pub mod ulz; +pub mod weights; pub mod x86; pub use frame::{frame_length, frames, inspect, object_lengths, Info, Representation, HEADER_HINT}; @@ -164,7 +165,14 @@ pub fn default_threads() -> usize { /// archive when that is not smaller; with `steps > 0` the exported model also searches and keeps the /// smallest. pub fn compress_frame(frame: &[u8], steps: u64) -> Result, Error> { - compress_pieces(frame, &[frame.len() as u64], &[], steps, true) + compress_pieces( + frame, + &[frame.len() as u64], + &[], + steps, + true, + &portfolio::SHIPPED, + ) } /// [`compress_frame`] for a frame that follows the frames `window` (at most @@ -172,7 +180,14 @@ pub fn compress_frame(frame: &[u8], steps: u64) -> Result, Error> { /// `compress input window steps`: the ncm candidate is the window archive /// whose payload reads those frames as history. pub fn compress_frame_with(frame: &[u8], window: &[&[u8]], steps: u64) -> Result, Error> { - compress_pieces(frame, &[frame.len() as u64], window, steps, true) + compress_pieces( + frame, + &[frame.len() as u64], + window, + steps, + true, + &portfolio::SHIPPED, + ) } /// [`compress_frame`] with the output split into objects of `lengths`, which @@ -184,6 +199,7 @@ fn compress_pieces( window: &[&[u8]], steps: u64, side_by_side: bool, + table: &portfolio::Table, ) -> Result, Error> { if steps > 0 { let archive = on_reference_stack(|| reference_compress(frame, window, steps))?; @@ -265,7 +281,14 @@ fn compress_pieces( // With a core to spare they code side by side, each bounded by the raw // archive; otherwise one after the other, the second bounded by the // first's archive as well (it is kept only when strictly smaller). - let [first, second] = portfolio::plan(frame); + let plan = table.plan(frame); + let (first, second) = ( + plan.first().copied().flatten(), + plan.get(1).copied().flatten(), + ); + let code = |strategy: Option, learn: bool, bound: u64| { + strategy.and_then(|s| code(s, learn, bound)) + }; let (a, b) = if side_by_side && cfg!(not(target_family = "wasm")) { std::thread::scope(|s| { let other = s.spawn(|| code(second, false, raw)); @@ -647,6 +670,7 @@ fn compress_frames( writer: &mut dyn Write, steps: u64, threads: usize, + table: &portfolio::Table, ) -> io::Result { let threads = threads.max(1); let mut totals = Totals::default(); @@ -671,6 +695,7 @@ fn compress_frames( &all[k - frame.window..k], steps, spare, + table, ) }) .into_iter(); @@ -723,6 +748,28 @@ pub fn compress_stream( &mut writer, steps, threads, + &portfolio::SHIPPED, + ) +} + +/// [`compress_stream`] under the portfolio `table` instead of the shipped +/// one (no search): how the engine and the claim decider code a corpus at a +/// point of the codec space. Every table writes a stream that decodes to the +/// input; the table changes its size, never its meaning. +pub fn compress_stream_with( + reader: impl Read, + mut writer: impl Write, + threads: usize, + table: &portfolio::Table, +) -> io::Result { + compress_frames( + chunk::Framer::plain(), + reader, + None, + &mut writer, + 0, + threads, + table, ) } @@ -748,6 +795,7 @@ pub fn compress_objects_stream( &mut writer, steps, threads, + &portfolio::SHIPPED, ) } @@ -1192,7 +1240,14 @@ impl FrameEncoder { .iter() .map(Vec::as_slice) .collect(); - compress_pieces(&frame.bytes, &frame.pieces, &window, steps, true)? + compress_pieces( + &frame.bytes, + &frame.pieces, + &window, + steps, + true, + &portfolio::SHIPPED, + )? } }; out.extend_from_slice(&archive); diff --git a/crates/uorc/src/portfolio-outcomes.tsv b/crates/uorc/src/portfolio-outcomes.tsv deleted file mode 100644 index a47bb4ad..00000000 --- a/crates/uorc/src/portfolio-outcomes.tsv +++ /dev/null @@ -1,334 +0,0 @@ -# uorc strategy portfolio training outcomes: one frame per line. -# Columns: frame length, family, then the ncm payload length of each strategy in portfolio order -# (FULL, FULL over x86, MID, MID over x86, V03, V03 over x86); the frame length + 50 when the coder declined. -# Generated by crates/uorc/examples/portfolio_outcomes.rs. -# Training set: 328 files of a Linux system and a Rust build (source, docs, configs, libraries, -# executables, Rust .rlib/.rmeta, LLVM bitcode, already-compressed files), sorted by name. -3473 0 837 837 827 827 835 835 -7651 1 1835 1835 1810 1810 1812 1812 -16428 1 1736 1736 1716 1716 1748 1748 -20458 1 1530 1530 1504 1504 1532 1532 -23119 1 4717 4717 4667 4667 4685 4685 -1791 0 591 591 586 586 585 585 -3873 0 749 749 744 744 750 750 -1140 0 507 507 504 504 504 504 -4401 1 1414 1414 1396 1396 1397 1397 -2383 0 785 785 772 772 774 774 -1097 0 285 285 284 284 283 283 -7180 1 1332 1332 1314 1314 1318 1318 -22406 1 8497 8497 8427 8429 8538 8540 -13877 1 2968 3109 2939 3079 3119 3258 -2679 0 1102 1105 1092 1094 1104 1107 -2419 0 1383 1385 1370 1370 1379 1380 -1464 0 684 684 676 676 676 676 -1757 0 752 752 741 741 739 739 -2904 0 787 787 776 776 772 772 -969 0 394 394 391 391 391 391 -5555 1 1510 1510 1487 1487 1500 1500 -3990 0 808 808 791 791 793 793 -2034 0 662 662 656 656 657 657 -1311 0 466 466 462 462 464 464 -14658 1 3660 3660 3628 3628 3639 3639 -24126 1 3454 3454 3412 3412 3485 3485 -20603 1 3906 3906 3869 3869 3886 3886 -2082 0 476 476 471 471 469 469 -29161 1 1160 1160 1156 1156 1163 1163 -1334 0 526 526 519 519 518 518 -13710 1 840 840 833 833 841 841 -8540 1 1930 1930 1904 1904 1897 1897 -849 0 366 366 362 362 363 363 -12433 1 2283 2283 2259 2259 2272 2272 -35289 1 11388 11388 11312 11312 11307 11307 -3154 0 639 639 634 634 633 633 -14776 1 3397 3352 3370 3326 3394 3350 -14784 1 1984 1969 1975 1962 1976 1961 -18640 1 4526 4486 4499 4459 4530 4484 -18640 1 4574 4533 4545 4505 4582 4534 -3889 0 1538 1538 1519 1519 1518 1518 -1372 0 491 491 486 486 488 488 -30166 1 5392 5392 5344 5344 5395 5395 -15942 1 3328 3328 3295 3295 3312 3312 -4509 1 4559 4559 4559 4559 4559 4559 -1171 0 1221 1221 1221 1221 1221 1221 -592 0 642 642 642 642 642 642 -1803 0 1853 1853 1853 1853 1853 1853 -2620 0 674 674 667 667 663 663 -9434 1 2804 2804 2777 2777 2784 2784 -13848 1 3340 3340 3308 3308 3315 3315 -879 0 443 443 440 440 439 439 -15555 1 4251 4251 4212 4212 4231 4231 -536 0 300 300 297 297 299 299 -703 0 358 358 352 352 358 358 -641 0 336 336 333 333 337 337 -40947 1 9264 9264 9205 9205 9324 9324 -5148 1 1704 1704 1687 1687 1689 1689 -1091 0 522 522 517 517 516 516 -6331 1 2273 2273 2244 2244 2242 2242 -43367 1 2296 2296 2263 2263 2315 2315 -2950 0 632 632 625 625 625 625 -2596 0 586 586 581 581 578 578 -65423 1 2626 2626 2598 2598 2745 2745 -2174 0 884 884 877 877 875 875 -18145 1 5105 5105 5058 5058 5075 5075 -10174 1 2837 2837 2809 2809 2804 2804 -1281 0 501 501 495 495 494 494 -33028 1 21167 21172 21132 21137 21430 21431 -14524 1 10272 10273 10244 10245 10286 10287 -9424 1 5903 5905 5881 5883 5921 5922 -1612 0 1456 1456 1454 1454 1450 1450 -18824 1 4423 4331 4391 4304 4430 4337 -18896 1 4516 4421 4493 4398 4550 4447 -146000 2 44362 41704 44114 41462 44917 42096 -81240 2 23897 23105 23709 22923 24143 23264 -11000 1 3044 3044 3009 3009 3018 3018 -4783 1 1891 1891 1870 1870 1868 1868 -3259 0 770 770 759 759 764 764 -106071 3 38553 38553 38518 38518 38468 38468 -6642 1 1618 1618 1599 1599 1606 1606 -6204 1 1434 1434 1415 1415 1427 1427 -3524 0 397 397 395 395 410 410 -1822 0 607 607 600 600 598 598 -662 0 200 200 199 199 200 200 -1762 0 390 390 387 387 388 388 -6465 1 1621 1621 1599 1599 1593 1593 -766 0 341 341 338 338 336 336 -67712 2 17265 16493 17108 16367 17406 16580 -845 0 397 397 393 393 393 393 -13909 1 3446 3446 3413 3413 3416 3416 -2559 0 1009 1009 999 999 997 997 -1025 0 417 417 414 414 413 413 -1494 0 626 626 620 620 620 620 -1207 0 441 441 437 437 435 435 -4699 1 2354 2354 2335 2335 2327 2327 -3634 0 996 996 982 982 977 977 -1831 0 337 337 330 330 323 323 -8188 1 1996 1996 1968 1968 1967 1967 -3502 0 966 966 952 952 961 961 -8746 1 1032 1032 1016 1016 1031 1031 -15140 1 4090 4090 4051 4051 4047 4047 -20624 1 5960 5960 5912 5912 5910 5910 -6973 1 976 976 967 967 973 973 -2642 0 965 965 948 948 948 948 -6860 1 2255 2255 2221 2221 2247 2247 -5659 1 1663 1663 1645 1645 1653 1653 -3063 0 1157 1157 1141 1141 1141 1141 -580 0 272 272 270 270 270 270 -92192 2 28204 27233 28020 27045 28398 27344 -162392 2 34788 33479 34521 33238 35372 33952 -326912 2 86268 81412 85868 81060 88091 82817 -4152 1 3333 3333 3323 3322 3328 3328 -597777 4 541657 541715 541642 541700 542522 542598 -75479 4 69271 69271 69214 69214 69364 69363 -476853 4 405472 405504 405469 405501 406496 406527 -628 0 655 655 654 654 654 654 -621 0 632 632 631 631 631 631 -1233 0 1262 1262 1258 1258 1258 1258 -18358 1 14156 14156 14109 14109 14090 14090 -523 0 138 138 138 138 137 137 -11743 1 1292 1292 1283 1283 1299 1299 -1091 0 204 204 204 204 204 204 -732 0 174 174 175 175 175 175 -1132 0 312 312 310 310 309 309 -5162 1 1027 1027 1015 1015 1023 1023 -3866 0 808 808 795 795 793 793 -2480 0 795 795 786 786 790 790 -6977 1 808 808 802 802 794 794 -805 0 229 229 229 229 230 230 -1641 0 272 272 272 272 273 273 -516 0 245 245 244 244 244 244 -961 0 445 445 442 442 441 441 -5452 1 1960 1960 1941 1941 1963 1963 -989 0 466 466 462 462 462 462 -1112 0 499 499 497 497 497 497 -16400 1 12488 12488 12453 12453 12463 12464 -15896 1 11946 11947 11911 11912 11926 11926 -15920 1 11949 11951 11915 11917 11930 11933 -20976 1 16827 16830 16792 16796 16807 16811 -10601 1 3090 3090 3054 3054 3060 3060 -18065 1 4439 4439 4401 4401 4416 4416 -770 0 536 536 534 534 535 535 -13416 1 3634 3634 3600 3600 3615 3615 -3351 0 1104 1104 1091 1091 1088 1088 -30765 1 3919 3919 3874 3874 3914 3914 -3667 0 1159 1159 1143 1143 1140 1140 -2922 0 1129 1129 1112 1112 1109 1109 -8192 1 548 548 539 539 550 550 -8192 1 35 35 34 34 34 34 -16384 1 131 131 129 129 129 129 -8192 1 32 32 33 33 33 33 -16384 1 223 223 223 223 234 234 -8192 1 28 28 28 28 29 29 -16384 1 1750 1825 1740 1815 1825 1903 -8192 1 34 34 34 34 33 33 -8192 1 34 34 35 35 34 34 -24576 1 61 61 61 61 63 63 -24576 1 1014 1014 995 995 1087 1087 -24576 1 52 52 52 52 53 53 -3133 0 917 917 904 904 908 908 -2760 0 988 988 974 974 975 975 -5897 1 2142 2142 2121 2121 2117 2117 -646 0 282 282 278 278 277 277 -1509 0 277 277 275 275 275 275 -3849 0 1359 1359 1341 1341 1338 1338 -1641 0 426 426 422 422 422 422 -1199 0 407 407 404 404 403 403 -3467 0 1126 1126 1110 1110 1129 1129 -1987 0 721 721 708 708 708 708 -3517 0 693 693 701 701 695 695 -2566 0 688 688 679 679 674 674 -1416 0 610 613 608 611 617 620 -614 0 295 295 293 293 293 293 -2410 0 1036 1037 1027 1028 1042 1043 -3494 0 1498 1505 1494 1501 1556 1563 -1171 0 402 402 397 397 399 399 -1315 0 566 566 560 560 565 565 -526 0 172 172 172 172 173 173 -1695 0 764 764 753 753 761 761 -31461 1 9295 9295 9238 9238 9248 9248 -13511 1 1407 1407 1378 1378 1397 1397 -1844 0 379 379 377 377 379 379 -4957 1 2069 2069 2045 2045 2042 2042 -18481 1 3655 3655 3611 3611 3640 3640 -14678 1 3465 3465 3430 3430 3443 3443 -8385 1 1433 1433 1410 1410 1408 1408 -10644 1 2825 2825 2795 2795 2799 2799 -3933 0 1492 1493 1462 1463 1497 1498 -2800 0 1135 1135 1114 1114 1124 1124 -1644 0 580 580 571 571 576 576 -853 0 104 104 104 104 103 103 -2194 0 499 499 493 493 492 492 -5264 1 276 276 271 271 269 269 -1246 0 415 415 410 410 411 411 -850 0 420 420 416 416 415 415 -1229 0 904 904 900 900 897 897 -2025 0 1572 1572 1565 1565 1562 1562 -1017 0 702 702 699 699 697 697 -1883 0 1446 1446 1439 1439 1436 1436 -6530 1 1294 1294 1283 1283 1306 1306 -2238 0 426 426 419 419 416 416 -6317 1 1202 1202 1178 1178 1201 1201 -19260 1 2641 2641 2622 2622 2645 2645 -555 0 235 235 232 232 234 234 -691 0 246 246 244 244 245 245 -1160 0 436 436 432 432 433 433 -992 0 119 119 118 118 118 118 -956 0 467 467 462 462 461 461 -962 0 470 470 466 466 465 465 -956 0 466 466 462 462 461 461 -968 0 470 470 466 466 464 464 -1909 0 757 764 753 760 803 808 -2298 0 949 957 939 947 997 1005 -2641 0 1168 1177 1157 1166 1225 1232 -2301 0 921 931 916 926 971 979 -809294 4 125305 125306 125184 125184 127826 127825 -726901 4 137929 137929 137938 137938 140976 140976 -1581411 4 137718 137718 137911 137911 140535 140535 -762510 4 133687 133711 133539 133564 136537 136563 -1509 0 591 591 585 585 585 585 -1614 0 619 619 613 613 617 617 -1214 0 328 328 325 325 327 327 -1218 0 548 548 542 542 547 547 -1752 0 776 778 766 767 770 772 -1615 0 725 725 715 715 720 720 -1752 0 776 778 766 768 770 772 -1605 0 732 732 723 723 730 730 -1046 0 496 496 492 492 492 492 -1187 0 601 601 596 596 594 594 -813 0 454 454 450 450 450 450 -634 0 367 367 364 364 364 364 -983 0 423 426 420 422 432 436 -577 0 257 260 255 259 259 263 -1151 0 490 490 488 488 507 507 -969 0 403 405 399 401 404 406 -8369 1 2187 2187 2158 2158 2164 2164 -2516 0 880 880 868 868 868 868 -21478 1 3452 3452 3415 3415 3445 3445 -2717 0 1030 1030 1017 1017 1017 1017 -2220 0 671 671 658 658 677 677 -1476 0 579 579 568 568 584 584 -1232 0 172 172 171 171 175 175 -1606 0 606 606 593 593 612 612 -145263 4 74658 74658 74390 74390 74525 74525 -145263 4 74657 74657 74389 74389 74525 74525 -317251 4 139219 139233 138837 138851 139110 139125 -120218 4 58340 58345 58070 58076 58175 58182 -80676 3 7289 7289 7228 7228 7300 7300 -26352 1 5957 5957 5894 5894 5929 5929 -83454 3 7018 7018 6985 6985 7055 7055 -26203 1 6447 6447 6386 6386 6415 6415 -2247 0 694 694 683 683 681 681 -1213 0 550 550 544 544 546 546 -2059 0 574 574 564 564 568 568 -743 0 270 270 268 268 269 269 -273924 4 98729 98794 98597 98667 100745 100823 -269428 4 93176 93240 93064 93126 95244 95306 -273580 4 99097 99184 98970 99060 101122 101219 -65932 4 30980 31006 30804 30832 32245 32271 -1026404 2 178050 187051 178376 187556 181522 191167 -760322 2 118068 128569 118116 128852 120091 131680 -1918 0 531 536 531 535 531 535 -321422 2 57026 59336 56975 59348 57858 60434 -1648 0 549 549 545 545 548 548 -2429 0 872 872 863 863 858 858 -1568 0 506 506 498 498 497 497 -680 0 185 185 184 184 184 184 -16896 1 13974 13974 13937 13938 13931 13931 -53248 1 50644 50644 50569 50569 50574 50574 -463872 4 462876 462877 462716 462717 462705 462707 -463872 4 462876 462877 462716 462717 462705 462707 -441864 4 68051 68518 68022 68527 69334 69836 -1432 0 334 334 331 331 332 332 -500208 4 83524 84258 83520 84308 85144 85927 -1192 0 276 276 273 273 274 274 -2153 0 676 676 670 670 667 667 -2202 0 613 613 608 608 605 605 -2042 0 639 639 635 635 639 639 -2416 0 732 732 723 723 723 723 -714 0 376 376 373 373 373 373 -3589 0 1249 1249 1232 1232 1228 1228 -32056 1 8048 8048 7974 7974 8017 8017 -681 0 345 345 341 341 341 341 -868 0 190 190 188 188 189 189 -54590 1 5971 5971 5918 5918 6003 6003 -868 0 190 190 188 188 189 189 -2335 0 689 689 682 682 682 682 -1282 0 511 511 505 505 508 508 -1550 0 663 664 653 654 658 660 -1588 0 690 691 680 681 684 685 -1313 0 527 527 521 521 524 524 -2669 0 948 948 936 936 934 934 -3885 0 454 454 449 449 453 453 -2705 0 778 778 770 770 768 768 -642 0 361 361 358 358 357 357 -4603 1 1193 1193 1178 1178 1179 1179 -4749 1 1401 1401 1383 1383 1385 1385 -11834 1 2332 2332 2304 2304 2312 2312 -8701 1 1330 1330 1312 1312 1320 1320 -793 0 329 329 327 327 325 325 -573 0 242 242 241 241 239 239 -599 0 236 236 235 235 232 232 -793 0 329 329 327 327 325 325 -7701 1 1360 1360 1334 1334 1335 1335 -1846 0 386 386 382 382 381 381 -2457 0 614 614 606 606 610 610 -76672 3 8237 8237 8187 8187 8301 8301 -344096 2 107417 103288 107114 102998 108865 104538 -14336 1 1150 1160 1146 1154 1150 1158 -1126 0 388 388 386 386 387 387 -92152 2 30952 29925 30802 29789 31299 30197 -741 0 335 335 332 332 336 336 -1281 0 512 515 505 509 510 513 -1014 0 357 357 354 354 356 356 -1204 0 349 349 348 348 351 351 -1434 0 388 388 384 384 382 382 -3297 0 1251 1251 1236 1236 1242 1242 -1394 0 487 487 482 482 483 483 -1438 0 437 437 432 432 431 431 -2000000 4 611489 612581 613523 614609 662279 663296 -1934893 3 101899 101899 102180 102180 107822 107822 -2500000 4 457583 464319 460185 466925 465155 472320 -874782 3 44140 44140 44588 44588 45510 45510 -2500000 2 296559 339521 298375 342207 303779 350163 -3000000 4 676235 681606 681148 686513 744349 750164 -1263512 4 235710 237400 236915 238622 258561 260320 -2000000 3 89159 89159 89415 89415 91389 91389 diff --git a/crates/uorc/src/portfolio.rs b/crates/uorc/src/portfolio.rs index 5ca3b8c9..8c1fcabe 100644 --- a/crates/uorc/src/portfolio.rs +++ b/crates/uorc/src/portfolio.rs @@ -1,6 +1,5 @@ //! The strategy portfolio (`Uorc.Client.portfolio`): how the encoder picks -//! the coding of a frame, after the schedule engine of afflom/rule30 -//! (`Engine.lex.tex`) and the PrismPM factory. +//! the coding of a frame. //! //! A strategy is a transform (none, or the x86 branch filter) and an ncm //! model profile. A frame's family comes from cheap statistics of its bytes @@ -11,14 +10,17 @@ //! the smallest archive (raw when that is smaller): the weights order the //! work, and the measured sizes decide. //! -//! [`WEIGHTS`] is learned by the rule30 rule ([`learn`]: +2 for the strategy -//! that coded a frame smallest, -1 for every other, bounded to 1..=16) over -//! the measured outcomes in `portfolio-outcomes.tsv`, starting from 8; the -//! test `weights_are_learned_from_the_outcomes` repeats that learning. The -//! table is part of the client's model, so the output is a function of the -//! input alone, whatever `--threads` is. +//! The portfolio is data, a [`Table`] of strategy entries and weights in the +//! byte form the model's `compress` reads. The shipped table ([`SHIPPED`], +//! `weights.rs`) is generated by the engine (`Uorc.Engine`, `crates/engine`) +//! from `model/engine.toml`: each tick decides "candidate dominates incumbent +//! on family f" over a κ-named corpus and consolidates the winners into these +//! weights. Any table is safe: an entry the coder cannot apply is skipped, +//! and every candidate decodes to the frame. The output is a function of the +//! input and the table alone, whatever `--threads` is. use crate::ncm; +use crate::weights; /// A way to code a frame: over the x86 filter or not, and the ncm profile. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -33,49 +35,95 @@ pub struct Strategy { /// short inputs favour. pub const MID: u32 = ncm::FULL & !ncm::F_SEL; -/// The portfolio, in order. -pub const STRATEGIES: [Strategy; 6] = [ - Strategy { - x86: false, - profile: ncm::FULL, - }, - Strategy { - x86: true, - profile: ncm::FULL, - }, - Strategy { - x86: false, - profile: MID, - }, - Strategy { - x86: true, - profile: MID, - }, - Strategy { - x86: false, - profile: ncm::V03, - }, - Strategy { - x86: true, - profile: ncm::V03, - }, -]; +/// Bytes of one strategy entry: the u32 little-endian word, then the state. +pub const ENTRY: usize = 5; + +/// The word's x86 filter bit. +pub const X86_BIT: u32 = 1 << 31; /// Families: tiny (< 4 KiB), small (< 64 KiB), x86 code, text, other. pub const FAMILIES: usize = 5; +/// The families' names, in order. +pub const FAMILY_NAMES: [&str; FAMILIES] = ["tiny", "small", "x86", "text", "other"]; + /// Strategies the encoder codes per frame. pub const BUDGET: usize = 2; -/// The learned weight of each strategy (columns, portfolio order) for each -/// family (rows). -pub const WEIGHTS: [[u8; 6]; FAMILIES] = [ - [1, 1, 15, 1, 12, 1], - [1, 1, 16, 1, 1, 1], - [5, 1, 1, 15, 1, 1], - [10, 1, 10, 1, 4, 1], - [9, 1, 12, 1, 1, 1], -]; +/// A portfolio: strategy entries and one weight per (family, strategy). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Table<'a> { + /// [`ENTRY`] bytes per strategy. + pub strategies: &'a [u8], + /// `FAMILIES * count` weights, row by family. + pub weights: &'a [u8], +} + +/// The portfolio the client ships. +pub const SHIPPED: Table<'static> = Table { + strategies: &weights::STRATEGIES, + weights: &weights::WEIGHTS, +}; + +impl Strategy { + /// The entry's word: the profile, and bit 31 for the x86 filter. + pub fn word(self) -> u32 { + self.profile | if self.x86 { X86_BIT } else { 0 } + } + + /// The [`ENTRY`] bytes of this strategy (no state). + pub fn entry(self) -> [u8; ENTRY] { + let w = self.word().to_le_bytes(); + [w[0], w[1], w[2], w[3], 0] + } +} + +impl<'a> Table<'a> { + /// Strategy entries in the table. + pub fn count(&self) -> usize { + self.strategies.len() / ENTRY + } + + /// Entry `i`, when the coder can apply it: a valid profile word, no other + /// word bits, and no state (none is in the basis yet). + pub fn strategy(&self, i: usize) -> Option { + let e = self.strategies.get(i * ENTRY..(i + 1) * ENTRY)?; + let word = u32::from_le_bytes([e[0], e[1], e[2], e[3]]); + let profile = word & !X86_BIT; + (ncm::valid_profile(profile) && e[4] == 0).then_some(Strategy { + x86: word & X86_BIT != 0, + profile, + }) + } + + /// The weight of strategy `i` for `family` (0 when the table has none). + pub fn weight(&self, family: usize, i: usize) -> u8 { + self.weights + .get(family * self.count() + i) + .copied() + .unwrap_or(0) + } + + /// Every strategy index, ordered by its weight for `family` (highest + /// first, ties in portfolio order): a permutation of the entries. + pub fn schedule(&self, family: usize) -> Vec { + let mut s: Vec = (0..self.count()).collect(); + // stable, so equal weights keep portfolio order + s.sort_by_key(|&i| std::cmp::Reverse(self.weight(family, i))); + s + } + + /// The strategies the encoder codes for `frame`, in schedule order: the + /// first [`BUDGET`] scheduled entries (an entry the coder cannot apply + /// keeps its place and yields no candidate). + pub fn plan(&self, frame: &[u8]) -> Vec> { + self.schedule(family(frame)) + .into_iter() + .take(BUDGET) + .map(|i| self.strategy(i)) + .collect() + } +} /// The rule30 learning rule: a success adds 2 up to 16, a failure takes 1 /// down to 1. @@ -118,84 +166,53 @@ fn printable(frame: &[u8]) -> usize { .count() } -/// Every strategy index, ordered by its weight for `family` (highest first, -/// ties in portfolio order): a permutation of the portfolio. -pub fn schedule_with(weights: &[[u8; 6]; FAMILIES], family: usize) -> [usize; 6] { - let mut s = [0, 1, 2, 3, 4, 5]; - // stable, so equal weights keep portfolio order - s.sort_by_key(|&i| std::cmp::Reverse(weights[family][i])); - s -} - -/// The schedule of `family` under the learned [`WEIGHTS`]. -pub fn schedule(family: usize) -> [usize; 6] { - schedule_with(&WEIGHTS, family) -} - -/// The strategies the encoder codes for `frame`, in schedule order. -pub fn plan(frame: &[u8]) -> [Strategy; BUDGET] { - let s = schedule(family(frame)); - std::array::from_fn(|k| STRATEGIES[s[k]]) -} - #[cfg(test)] mod tests { use super::*; - /// One outcome per training frame: its family and each strategy's size. - fn outcomes() -> Vec<(usize, [u64; 6])> { - include_str!("portfolio-outcomes.tsv") - .lines() - .filter(|l| !l.starts_with('#')) - .map(|l| { - let v: Vec = l.split('\t').map(|x| x.parse().expect("number")).collect(); - (v[1] as usize, v[2..8].try_into().expect("six sizes")) - }) - .collect() - } - - #[test] - fn weights_are_learned_from_the_outcomes() { - let mut w = [[8u8; 6]; FAMILIES]; - for (f, sizes) in outcomes() { - let best = (0..6).min_by_key(|&i| (sizes[i], i)).expect("six"); - for (i, w) in w[f].iter_mut().enumerate() { - *w = learn(*w, i == best); - } - } - assert_eq!(w, WEIGHTS); - } - #[test] fn learning_stays_bounded_and_schedules_are_permutations() { for w in 1..=16 { assert!((1..=16).contains(&learn(w, true))); assert!((1..=16).contains(&learn(w, false))); } - for (f, w) in WEIGHTS.iter().enumerate() { - let mut s = schedule(f); - for k in 1..6 { - assert!(w[s[k - 1]] >= w[s[k]]); + assert_eq!(SHIPPED.weights.len(), FAMILIES * SHIPPED.count()); + for f in 0..FAMILIES { + let mut s = SHIPPED.schedule(f); + for k in 1..s.len() { + assert!(SHIPPED.weight(f, s[k - 1]) >= SHIPPED.weight(f, s[k])); } s.sort_unstable(); - assert_eq!(s, [0, 1, 2, 3, 4, 5]); + assert_eq!(s, (0..SHIPPED.count()).collect::>()); + assert!( + SHIPPED.weights[f * SHIPPED.count()..(f + 1) * SHIPPED.count()] + .iter() + .all(|w| (1..=16).contains(w)) + ); } } - /// On the training frames, the budget-2 schedule is within 0.01% of - /// coding every strategy and keeping the smallest. #[test] - fn the_schedule_nearly_reaches_the_best_strategy() { - let (mut got, mut best) = (0, 0); - for (f, sizes) in outcomes() { - got += schedule(f)[..BUDGET] - .iter() - .map(|&i| sizes[i]) - .min() - .expect("budget"); - best += sizes.iter().min().expect("six"); + fn the_shipped_entries_are_the_v04_portfolio() { + let v04 = [ncm::FULL, MID, ncm::V03] + .into_iter() + .flat_map(|profile| [false, true].map(|x86| Strategy { x86, profile })); + for (i, s) in v04.enumerate() { + assert_eq!(SHIPPED.strategy(i), Some(s)); + assert_eq!(SHIPPED.strategies[i * ENTRY..(i + 1) * ENTRY], s.entry()); } - assert!(got * 10_000 <= best * 10_001, "{got} vs {best}"); + } + + #[test] + fn an_entry_the_coder_cannot_apply_is_skipped() { + let bad = Table { + strategies: &[0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x01], + weights: &[1; 10], + }; + assert_eq!(bad.strategy(0), None); + assert_eq!(bad.strategy(1), None); + assert_eq!(bad.strategy(2), None); + assert_eq!(bad.plan(&[0; 10]), vec![None, None]); } #[test] diff --git a/crates/uorc/src/weights.rs b/crates/uorc/src/weights.rs new file mode 100644 index 00000000..0fed907a --- /dev/null +++ b/crates/uorc/src/weights.rs @@ -0,0 +1,14 @@ +// @generated by `uorc-engine consolidate` from model/engine.toml (Uorc.Engine); do not edit. +//! The shipped strategy portfolio, as the engine consolidated it. + +/// Five bytes per strategy: the u32 little-endian word (bits 0-19 the ncm +/// profile word, bit 31 the x86 filter), then the state index (0 for none). +pub const STRATEGIES: [u8; 30] = [ + 0xff, 0xff, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x80, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0xff, + 0xff, 0x07, 0x80, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x01, 0x80, 0x00, +]; + +/// One weight in 1..=16 per (family, strategy): byte `family * S + strategy`. +pub const WEIGHTS: [u8; 30] = [ + 1, 1, 15, 1, 12, 1, 1, 1, 16, 1, 1, 1, 5, 1, 1, 15, 1, 1, 10, 1, 10, 1, 4, 1, 9, 1, 12, 1, 1, 1, +]; diff --git a/src/Uorc/Engine.lex.tex b/src/Uorc/Engine.lex.tex new file mode 100644 index 00000000..a6f85f18 --- /dev/null +++ b/src/Uorc/Engine.lex.tex @@ -0,0 +1,334 @@ +\begin{lexlean}{Uorc.Engine} +\title{Parameters} +\begin{semanticmodule} +inductive{ + name: MintVerdict, + type_parameters: [], + parameters: [], + constructors: [ + {name: minted, fields: [Nat]}, + {name: refusedKnown, fields: []}, + {name: refusedBudget, fields: []} + ] +} + +definition{name: weightMin, parameters: [], result: Nat, body: 1} + +definition{name: weightMax, parameters: [], result: Nat, body: 16} + +definition{name: weightInitial, parameters: [], result: Nat, body: 8} + +definition{name: potentiation, parameters: [], result: Nat, body: 2} + +definition{name: depression, parameters: [], result: Nat, body: 1} + +definition{name: consolidation, parameters: [], result: Nat, body: 12} + +definition{name: hypothesisBudget, parameters: [], result: Nat, body: 6} + +definition{name: tickHistory, parameters: [], result: Nat, body: 32} + +definition{name: cells, parameters: [], result: Nat, body: 64} + +definition{name: ring, parameters: [], result: Nat, body: 18446744073709551616} + +definition{name: seed, parameters: [], result: Nat, body: 11400714819323198485} + +definition{name: cronFirst, parameters: [], result: Nat, body: 23} + +definition{name: cronSecond, parameters: [], result: Nat, body: 53} + +definition{name: setupMinutes, parameters: [], result: Nat, body: 10} + +definition{name: tickMinutes, parameters: [], result: Nat, body: 45} + +definition{name: timeoutMinutes, parameters: [], result: Nat, body: 60} + +definition{ + name: pow2, + parameters: [n : Nat], + result: Nat, + body: (match n | Nat.zero => 1 | Nat.succ k => ((pow2 k) + (pow2 k))), + axioms: [], + recursive_argument: n +} + +definition{ + name: cell, + parameters: [s : Nat, i : Nat], + result: Nat, + body: (prim remainder (prim quotient s (pow2 i) 0 : Nat) 2 0 : Nat) +} + +definition{ + name: rule, + parameters: [l : Nat, c : Nat, r : Nat], + result: Nat, + body: (if ((c =? 1) || (r =? 1)) then (if (l =? 0) then 1 else 0) else (if (l =? 1) then 1 else 0)) +} + +definition{ + name: nextCell, + parameters: [s : Nat, i : Nat], + result: Nat, + body: (rule (cell s (prim remainder (i + 1) (cells) 0 : Nat)) (cell s i) (cell s (prim remainder (i + 63) (cells) 0 : Nat))) +} + +definition{ + name: stepFrom, + parameters: [s : Nat, fuel : Nat], + result: Nat, + body: (match fuel + | Nat.zero => 0 + | Nat.succ m => ((stepFrom s m) + (if ((nextCell s m) =? 1) then (pow2 m) else 0))), + axioms: [], + recursive_argument: fuel +} + +definition{ + name: rule30Step, + parameters: [s : Nat], + result: Nat, + body: (stepFrom (if (s =? 0) then (seed) else s) (cells)) +} + +theorem{ + name: stepFromBelowPow2, + parameters: [s : Nat, fuel : Nat], + statement: ((stepFrom s fuel) < (pow2 fuel)), + proof: induction{ + branches: [ + {proof: linear_arithmetic{definitions: [pow2, stepFrom]}, binders: [], constructor: zero}, + {proof: linear_arithmetic{definitions: [pow2, stepFrom]}, binders: [m, ih], constructor: succ} + ], + scrutinee: fuel + }, + axioms: [Quot.sound, propext] +} + +theorem{ + name: ringIsPow2Cells, + parameters: [], + statement: ((pow2 (cells)) = (ring)), + proof: decide{}, + axioms: [] +} + +theorem{ + name: rule30FromZeroIsSeedStep, + parameters: [], + statement: ((rule30Step 0) = 8170733857868071477), + proof: decide{}, + axioms: [] +} + +theorem{ + name: rule30OfSeed, + parameters: [], + statement: ((rule30Step (seed)) = 8170733857868071477), + proof: decide{}, + axioms: [] +} + +theorem{ + name: rule30OfOne, + parameters: [], + statement: ((rule30Step 1) = 9223372036854775811), + proof: decide{}, + axioms: [] +} + +definition{ + name: select, + parameters: [s : Nat, n : Nat], + result: Nat, + body: (prim remainder s n 0 : Nat) +} + +definition{ + name: potentiate, + parameters: [w : Nat], + result: Nat, + body: (if ((weightMax) (((weightMin) <= (potentiate w)) /\ ((potentiate w) <= (weightMax)))), + proof: linear_arithmetic{definitions: [potentiate, potentiation, weightMax, weightMin]}, + axioms: [Classical.choice, Quot.sound, propext] +} + +theorem{ + name: depressionStaysBounded, + parameters: [w : Nat], + statement: ((((weightMin) <= w) /\ (w <= (weightMax))) -> (((weightMin) <= (depress w)) /\ ((depress w) <= (weightMax)))), + proof: linear_arithmetic{definitions: [depress, depression, weightMax, weightMin]}, + axioms: [Classical.choice, Quot.sound, propext] +} + +theorem{ + name: potentiationNeverLowers, + parameters: [w : Nat], + statement: ((w <= (weightMax)) -> (w <= (potentiate w))), + proof: linear_arithmetic{definitions: [depress, learn, potentiate, potentiation, weightMax]}, + axioms: [Quot.sound, propext] +} + +theorem{ + name: depressionNeverRaises, + parameters: [w : Nat], + statement: (((weightMin) <= w) -> ((depress w) <= w)), + proof: linear_arithmetic{definitions: [depress, depression, learn, potentiate, weightMin]}, + axioms: [Quot.sound, propext] +} + +definition{ + name: larger, + parameters: [a : Nat, b : Nat], + result: Nat, + body: (if (a ((loserWeight incumbent) < (winnerWeight candidate incumbent))), + proof: linear_arithmetic{ + definitions: [ + depress, + depression, + larger, + learn, + loserWeight, + potentiate, + potentiation, + weightMax, + weightMin, + winnerWeight + ] + }, + axioms: [Quot.sound, propext] +} + +definition{name: consolidated, parameters: [w : Nat], result: Bool, body: ((consolidation) <=? w)} + +theorem{ + name: winnerAtCeilingIsConsolidated, + parameters: [incumbent : Nat], + statement: ((((consolidation) <= incumbent) /\ (incumbent <= (weightMax))) -> ((consolidated (winnerWeight 0 incumbent)) = true)), + proof: linear_arithmetic{ + definitions: [ + consolidated, + consolidation, + depress, + larger, + learn, + potentiate, + potentiation, + weightMax, + winnerWeight + ] + }, + axioms: [Quot.sound, propext] +} + +definition{ + name: dominates, + parameters: [ + candidateBytes : Nat, + candidateSteps : Nat, + incumbentBytes : Nat, + incumbentSteps : Nat + ], + result: Bool, + body: (((candidateBytes <=? incumbentBytes) && (candidateSteps <=? incumbentSteps)) && ((candidateBytes ((dominates bb bs ab as) = false)), + proof: linear_arithmetic{definitions: [dominates]}, + axioms: [Quot.sound, propext] +} + +theorem{ + name: dominanceIsTransitive, + parameters: [ab : Nat, as : Nat, bb : Nat, bs : Nat, cb : Nat, cs : Nat], + statement: (((dominates ab as bb bs) = true) -> (((dominates bb bs cb cs) = true) -> ((dominates ab as cb cs) = true))), + proof: linear_arithmetic{definitions: [dominates]}, + axioms: [Classical.choice, Quot.sound, propext] +} + +theorem{ + name: dominanceNeverCostsBytes, + parameters: [ab : Nat, as : Nat, bb : Nat, bs : Nat], + statement: (((dominates ab as bb bs) = true) -> ((ab <= bb) /\ (as <= bs))), + proof: linear_arithmetic{definitions: [dominates]}, + axioms: [Classical.choice, Quot.sound, propext] +} + +definition{ + name: admitMint, + parameters: [known : Bool, remaining : Nat], + result: MintVerdict, + body: (if known then (ctor MintVerdict.refusedKnown) else (if (remaining =? 0) then (ctor MintVerdict.refusedBudget) else (ctor MintVerdict.minted (prim subtract remaining 1 : Nat)))) +} + +theorem{ + name: knownResultIsNeverRerun, + parameters: [remaining : Nat], + statement: ((admitMint true remaining) = (ctor MintVerdict.refusedKnown)), + proof: reflexivity{}, + axioms: [] +} + +definition{ + name: validWorkflow, + parameters: [early : Nat, late : Nat, setup : Nat, tick : Nat, timeout : Nat], + result: Bool, + body: ((((0 Date: Wed, 11 Nov 2026 06:03:00 +0000 Subject: [PATCH 4/6] =?UTF-8?q?frontier:=20the=20claim=20register=20and=20?= =?UTF-8?q?its=20decider=20(closed=20claims=20by=20=CE=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit crates/frontier holds frontier.toml (corpora, pinned comparators, encoder points, claims by the κ of their question) and decides closed claims by running the shipped codec over a κ-named corpus: exact archive bytes and decode steps (uorc::performance), round-tripped. Bound, dominance and exclusion claims are decided from closed ones without coding. A claim the factory decided is never rerun. inspect --json reports each frame's steps. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3QshCSRwiddS64zU3j --- Cargo.lock | 10 + Cargo.toml | 1 + crates/frontier/Cargo.toml | 27 + crates/frontier/src/lib.rs | 1150 +++++++++++++++++++++++++++++++++++ crates/frontier/src/main.rs | 464 ++++++++++++++ crates/uorc/src/frame.rs | 3 +- frontier.toml | 168 +++++ 7 files changed, 1822 insertions(+), 1 deletion(-) create mode 100644 crates/frontier/Cargo.toml create mode 100644 crates/frontier/src/lib.rs create mode 100644 crates/frontier/src/main.rs create mode 100644 frontier.toml diff --git a/Cargo.lock b/Cargo.lock index 72b8e842..45dfdb50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,6 +220,16 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" +[[package]] +name = "frontier" +version = "0.4.0" +dependencies = [ + "serde", + "sha2 0.11.1", + "toml 0.8.23", + "uorc", +] + [[package]] name = "fs4" version = "0.13.1" diff --git a/Cargo.toml b/Cargo.toml index 66245f2a..2ebf042c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ repo-model = { version = "0.4.0", path = "crates/model" } # `cargo deny` refuses those (`wildcards = "deny"`). Every internal dependency # carries both. repo-conformance = { version = "0.4.0", path = "crates/conformance" } +uorc = { version = "0.4.0", path = "crates/uorc" } [workspace.lints.rust] missing_docs = "deny" diff --git a/crates/frontier/Cargo.toml b/crates/frontier/Cargo.toml new file mode 100644 index 00000000..ea0cb70c --- /dev/null +++ b/crates/frontier/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "frontier" +description = "uorc's claim register (frontier.toml) and decider: closed performance claims over κ-named corpora, decided by running the shipped codec." +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +authors.workspace = true +publish = false + +[lib] +path = "src/lib.rs" + +[[bin]] +name = "frontier" +path = "src/main.rs" + +[dependencies] +serde = { version = "1.0.229", features = ["derive"] } +sha2 = "0.11.1" +toml = "0.8.23" +uorc = { workspace = true } + +[lints] +workspace = true diff --git a/crates/frontier/src/lib.rs b/crates/frontier/src/lib.rs new file mode 100644 index 00000000..24ed7d46 --- /dev/null +++ b/crates/frontier/src/lib.rs @@ -0,0 +1,1150 @@ +//! uorc's claim register and its decider. +//! +//! A closed claim says "codec point X codes corpus κ in exactly N bytes and S +//! steps". Archive sizes and model step counts are deterministic, so such a +//! claim is not a timing: it is decided by running the shipped codec over the +//! corpus, and it is true or false. The register (`frontier.toml` at the +//! repository root) holds every corpus, codec point and claim by κ: +//! +//! - a **corpus** is an ordered list of members (name, SHA-256, length); its +//! κ is [`corpus_kappa`] over that list, so the corpus is the same object +//! wherever its bytes come from (a download, a directory, git objects); +//! - a **codec point** is where the codec sits in its modelled space: the +//! export identity of the model the native code is byte-identical to, the +//! strategy plan (the portfolio under a weight table, or one fixed +//! strategy), the consolidated model state κ and the lane count; its κ is +//! [`CodecPoint::kappa`]; +//! - a **claim** is one of the forms of `Uorc.Performance`: closed (point, +//! corpus, bytes, steps), bound (point, corpus, at most B bytes, B from a +//! pinned comparator), dominance (candidate, incumbent, family: bytes and +//! steps no larger, one strictly smaller) and exclusion (a refuted point, +//! never rerun). Its κ is the κ of the question ([`claim_kappa`]), not of +//! the answer, so a question known by κ is never asked twice. +//! +//! Steps are decode steps, read from each frame's header by +//! [`uorc::performance::frame_steps`]: one model input evaluated for one coded bit. +//! +//! Who decided a claim is part of the record. A result a workstation wrote is +//! `local`; the factory obligation `frontier` re-decides every claim that is +//! not yet decided by the factory and then never again. + +use std::collections::BTreeMap; +use std::fmt; +use std::io; +use std::path::Path; + +use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; +use uorc::portfolio::{self, Strategy, Table}; + +/// The register's schema name. +pub const SCHEMA: &str = "uorc/frontier/1"; + +/// Names of the portfolio's frame families, in [`portfolio::family`] order. +pub const FAMILIES: [&str; portfolio::FAMILIES] = portfolio::FAMILY_NAMES; + +/// The strategy coordinate of a codec point: a portfolio table in the byte +/// form the model's `compress` reads, or one fixed strategy (coded as the +/// one-entry table, exactly as the shipped encoder codes that strategy, +/// learned context mask included). +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum Plan { + /// A portfolio: [`portfolio::ENTRY`] bytes per strategy, and + /// `FAMILIES * count` weights. + Portfolio { + /// The strategy entries. + strategies: Vec, + /// The weights, row by family. + weights: Vec, + }, + /// One strategy for every frame. + Fixed(Strategy), +} + +impl Plan { + /// The shipped portfolio ([`portfolio::SHIPPED`]). + pub fn shipped() -> Plan { + Plan::Portfolio { + strategies: portfolio::SHIPPED.strategies.to_vec(), + weights: portfolio::SHIPPED.weights.to_vec(), + } + } + + /// The plan's table, borrowing `fixed` for a fixed strategy's entry. + fn table<'a>( + &'a self, + fixed: &'a mut ([u8; portfolio::ENTRY], [u8; portfolio::FAMILIES]), + ) -> Table<'a> { + match self { + Plan::Portfolio { + strategies, + weights, + } => Table { + strategies, + weights, + }, + Plan::Fixed(s) => { + *fixed = (s.entry(), [1; portfolio::FAMILIES]); + Table { + strategies: &fixed.0, + weights: &fixed.1, + } + } + } + } +} + +/// A failure of the register or the decider. +#[derive(Debug)] +pub enum Error { + /// Reading or writing a file failed. + Io(String, io::Error), + /// The register is not valid TOML of this schema. + Parse(String), + /// The register contradicts itself (a stored κ that does not recompute). + Inconsistent(String), + /// A corpus member's bytes are not the ones its κ names. + Member(String), + /// The codec failed on a member: it did not compress, did not round-trip, + /// or wrote a frame with no step value. + Codec(String), + /// A name the register does not hold. + Unknown(String), +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Error::Io(path, e) => write!(f, "{path}: {e}"), + Error::Parse(m) => write!(f, "frontier.toml: {m}"), + Error::Inconsistent(m) => write!(f, "frontier.toml is inconsistent: {m}"), + Error::Member(m) => write!(f, "corpus member: {m}"), + Error::Codec(m) => write!(f, "codec: {m}"), + Error::Unknown(m) => write!(f, "unknown: {m}"), + } + } +} + +impl std::error::Error for Error {} + +/// SHA-256 as lowercase hex. +pub fn sha256_hex(bytes: &[u8]) -> String { + hex(&Sha256::digest(bytes)) +} + +/// One member of a corpus. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Member { + /// The member's name (a file name, or a path in a git tree). + pub name: String, + /// SHA-256 of its bytes, lowercase hex. + pub sha256: String, + /// Its length in bytes. + pub bytes: u64, +} + +impl Member { + /// The member record of `bytes` under `name`. + pub fn of(name: &str, bytes: &[u8]) -> Member { + Member { + name: name.to_owned(), + sha256: sha256_hex(bytes), + bytes: bytes.len() as u64, + } + } +} + +fn hex(bytes: &[u8]) -> String { + bytes.iter().map(|b| format!("{b:02x}")).collect() +} + +fn unhex(s: &str) -> Option> { + s.len() + .is_multiple_of(2) + .then(|| { + (0..s.len() / 2) + .map(|k| u8::from_str_radix(s.get(2 * k..2 * k + 2)?, 16).ok()) + .collect() + }) + .flatten() +} + +fn unhex32(s: &str) -> Option<[u8; 32]> { + if s.len() != 64 { + return None; + } + let mut out = [0; 32]; + for (k, o) in out.iter_mut().enumerate() { + *o = u8::from_str_radix(s.get(2 * k..2 * k + 2)?, 16).ok()?; + } + Some(out) +} + +/// The κ of a corpus, as `Uorc.Performance` defines it +/// ([`uorc::performance::corpus_kappa`]: SHA-256 over `uorc/corpus/1` and +/// each member's name length, name, SHA-256 and length), as hex. A member +/// whose SHA-256 is not 64 hex digits names no corpus. +pub fn corpus_kappa(members: &[Member]) -> String { + let digests: Vec<[u8; 32]> = members + .iter() + .map(|m| unhex32(&m.sha256).unwrap_or([0xff; 32])) + .collect(); + hex(&uorc::performance::corpus_kappa( + members + .iter() + .zip(&digests) + .map(|(m, d)| (m.name.as_str(), *d, m.bytes)), + )) +} + +/// A κ-named corpus. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Corpus { + /// A short name, used on the command line and in reports. + pub name: String, + /// [`corpus_kappa`] of `members`. + pub kappa: String, + /// Where the bytes come from: a URL, or `git:` (each member is the + /// blob at that path in that revision, so the corpus needs no network). + pub source: String, + /// A public corpus: its bound claims are UC-PERF-01's target. + #[serde(default)] + pub public: bool, + /// The members, in order. + pub members: Vec, +} + +impl Corpus { + /// A corpus of `members` from `source`, its κ computed. + pub fn new(name: &str, source: &str, public: bool, members: Vec) -> Corpus { + Corpus { + name: name.to_owned(), + kappa: corpus_kappa(&members), + source: source.to_owned(), + public, + members, + } + } + + /// Total input bytes. + pub fn bytes(&self) -> u64 { + self.members.iter().map(|m| m.bytes).sum() + } + + /// The members' bytes, read from `dir` (one file per member name) or, + /// for a `git:` source with no `dir`, from the git objects of + /// `repo`. Every member is checked against its length and SHA-256. + pub fn materialize(&self, dir: Option<&Path>, repo: &Path) -> Result>, Error> { + self.members + .iter() + .map(|m| { + let bytes = match (dir, self.source.strip_prefix("git:")) { + (Some(dir), _) => { + let path = dir.join(&m.name); + std::fs::read(&path) + .map_err(|e| Error::Io(path.display().to_string(), e))? + } + (None, Some(rev)) => git_blob(repo, rev, &m.name)?, + (None, None) => { + return Err(Error::Member(format!( + "{}: corpus {} needs a directory (source {})", + m.name, self.name, self.source + ))) + } + }; + if bytes.len() as u64 != m.bytes || sha256_hex(&bytes) != m.sha256 { + return Err(Error::Member(format!( + "{} in corpus {} is not the member its κ names", + m.name, self.name + ))); + } + Ok(bytes) + }) + .collect() + } +} + +fn git_blob(repo: &Path, rev: &str, path: &str) -> Result, Error> { + let out = std::process::Command::new("git") + .arg("-C") + .arg(repo) + .args(["cat-file", "blob", &format!("{rev}:{path}")]) + .output() + .map_err(|e| Error::Io("git".to_owned(), e))?; + if !out.status.success() { + return Err(Error::Member(format!( + "git {rev}:{path}: {}", + String::from_utf8_lossy(&out.stderr).trim() + ))); + } + Ok(out.stdout) +} + +/// A point in the codec's modelled space. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct CodecPoint { + /// The export identity of the model the native codec is byte-identical + /// to (`generated/rust/factory.identity`). + pub export: String, + /// The strategy coordinate: the portfolio under a weight table, or one + /// fixed strategy. + pub plan: Plan, + /// The κ of the consolidated model state the coder starts from; `None` + /// for a fresh model. + pub state: Option, + /// Independent lanes per frame (1: one coder per frame). + pub lanes: u32, +} + +impl CodecPoint { + /// The shipped client's point for export identity `export`: the + /// portfolio under the learned weights, a fresh model, one lane. + pub fn shipped(export: &str) -> CodecPoint { + CodecPoint { + export: export.to_owned(), + plan: Plan::shipped(), + state: None, + lanes: 1, + } + } + + /// The plan in a few words. + pub fn plan_text(&self) -> String { + match &self.plan { + Plan::Portfolio { strategies, .. } => { + format!("portfolio of {}", strategies.len() / portfolio::ENTRY) + } + Plan::Fixed(s) => format!("fixed x86={} profile=0x{:05x}", u8::from(s.x86), s.profile), + } + } + + /// The point's κ: SHA-256 over `uorc/encoder-point/1`, the export + /// identity (32 bytes), the plan (`0`, then the SHA-256 of the strategy + /// entries and of the weights; or `1` and the strategy's entry), the + /// state κ (32 bytes, zeros for none) and the lane count (u32 LE). It names the encoder's + /// coordinates; each frame the encoder writes has its own frame point, + /// [`uorc::performance::CodecPoint`]. + pub fn kappa(&self) -> String { + let mut h = Sha256::new(); + h.update(b"uorc/encoder-point/1"); + h.update( + unhex32(&self.export).unwrap_or_else(|| Sha256::digest(self.export.as_bytes()).into()), + ); + match &self.plan { + Plan::Portfolio { + strategies, + weights, + } => { + h.update([0u8]); + h.update(Sha256::digest(strategies)); + h.update(Sha256::digest(weights)); + } + Plan::Fixed(s) => { + h.update([1u8]); + h.update(s.entry()); + } + } + h.update(self.state.as_deref().and_then(unhex32).unwrap_or([0; 32])); + h.update(self.lanes.to_le_bytes()); + hex(&h.finalize()) + } + + /// The register record of this point. + pub fn record(&self, label: Option<&str>) -> Point { + let (strategies, weights, x86, profile) = match &self.plan { + Plan::Portfolio { + strategies, + weights, + } => (Some(hex(strategies)), Some(hex(weights)), None, None), + Plan::Fixed(s) => ( + None, + None, + Some(s.x86), + Some(format!("0x{:05x}", s.profile)), + ), + }; + Point { + kappa: self.kappa(), + label: label.map(str::to_owned), + export: self.export.clone(), + plan: match self.plan { + Plan::Portfolio { .. } => "portfolio", + Plan::Fixed(_) => "fixed", + } + .to_owned(), + strategies, + weights, + x86, + profile, + state: self.state.clone(), + lanes: self.lanes, + } + } +} + +/// A codec point as the register stores it. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Point { + /// [`CodecPoint::kappa`]. + pub kappa: String, + /// A reader's name for the point (`v0.5.0`, `fixed FULL`). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub label: Option, + /// The export identity. + pub export: String, + /// `portfolio` or `fixed`. + pub plan: String, + /// A portfolio's strategy entries, hex. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub strategies: Option, + /// A portfolio's weights, hex, row by family. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub weights: Option, + /// A fixed strategy's transform. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub x86: Option, + /// A fixed strategy's ncm profile word. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub profile: Option, + /// The consolidated model state κ. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub state: Option, + /// Lanes per frame. + pub lanes: u32, +} + +impl Point { + /// The codec point this record names. + pub fn point(&self) -> Result { + let bad = || Error::Inconsistent(format!("point {} has no valid plan", self.kappa)); + let plan = match self.plan.as_str() { + "portfolio" => Plan::Portfolio { + strategies: self.strategies.as_deref().and_then(unhex).ok_or_else(bad)?, + weights: self.weights.as_deref().and_then(unhex).ok_or_else(bad)?, + }, + "fixed" => { + let profile = self + .profile + .as_deref() + .and_then(|p| p.strip_prefix("0x")) + .and_then(|p| u32::from_str_radix(p, 16).ok()) + .filter(|&p| uorc::ncm::valid_profile(p)) + .ok_or_else(bad)?; + Plan::Fixed(Strategy { + x86: self.x86.ok_or_else(bad)?, + profile, + }) + } + _ => return Err(bad()), + }; + Ok(CodecPoint { + export: self.export.clone(), + plan, + state: self.state.clone(), + lanes: self.lanes, + }) + } +} + +/// A claim's form (`Uorc.Performance`). +#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] +#[serde(rename_all = "lowercase")] +pub enum Form { + /// Codec point X codes corpus κ in exactly N bytes and S steps. + Closed, + /// Codec point X codes corpus κ in at most B bytes (B pinned from a + /// comparator). + Bound, + /// Candidate dominates incumbent on a family of corpus κ: bytes and + /// steps no larger, one strictly smaller. + Dominance, + /// A refuted point, recorded so that it is never rerun. + Exclusion, +} + +/// A claim's status. +#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] +#[serde(rename_all = "lowercase")] +pub enum Status { + /// Minted, not decided yet. + Minted, + /// Decided true. + Proved, + /// Decided false. + Refuted, +} + +impl Status { + /// Lowercase name. + pub fn name(self) -> &'static str { + match self { + Status::Minted => "minted", + Status::Proved => "proved", + Status::Refuted => "refuted", + } + } +} + +/// One member's exact result under a codec point. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct MemberResult { + /// The member's name. + pub name: String, + /// The portfolio family of its first frame ([`FAMILIES`]). + pub family: String, + /// Archive bytes. + pub bytes: u64, + /// Decode steps. + pub steps: u64, +} + +/// The answer to a closed claim. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Closed { + /// Total archive bytes over the corpus. + pub bytes: u64, + /// Total decode steps over the corpus. + pub steps: u64, + /// Per member, in corpus order. + pub members: Vec, +} + +impl Closed { + /// Sums over the members of `family` (`None`: every member). + pub fn family(&self, family: Option<&str>) -> (u64, u64) { + self.members + .iter() + .filter(|m| family.is_none_or(|f| m.family == f)) + .fold((0, 0), |(b, s), m| (b + m.bytes, s + m.steps)) + } +} + +/// Whether `candidate` dominates `incumbent` on `family` (`None`: the whole +/// corpus): no more bytes and no more steps, and strictly fewer of one. +pub fn dominates(candidate: &Closed, incumbent: &Closed, family: Option<&str>) -> bool { + let (cb, cs) = candidate.family(family); + let (ib, is) = incumbent.family(family); + cb <= ib && cs <= is && (cb < ib || cs < is) +} + +/// One claim of the register. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Claim { + /// The claim's κ: [`claim_kappa`] of its question. + pub id: String, + /// The form. + pub form: Form, + /// The status. + pub status: Status, + /// Who decided it: `local` (a workstation run), or + /// `factory:` (the factory obligation `frontier`). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub receipt: Option, + /// The corpus κ. + pub corpus: String, + /// The codec point κ (closed, bound, exclusion). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub codec: Option, + /// The candidate point κ (dominance). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub candidate: Option, + /// The incumbent point κ (dominance). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub incumbent: Option, + /// The family (dominance); absent for the whole corpus. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub family: Option, + /// The comparator a bound comes from (`xz -9e`). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub against: Option, + /// The bound in bytes (bound). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub bound: Option, + /// Exact archive bytes (closed): stated, then decided. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub bytes: Option, + /// Exact decode steps (closed): stated, then decided. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub steps: Option, + /// What the deciding run observed when it refuted a stated closed claim. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub observed_bytes: Option, + /// What the deciding run observed when it refuted a stated closed claim. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub observed_steps: Option, + /// Per member results (closed). + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub members: Vec, +} + +impl Claim { + fn question(form: Form, corpus: &str) -> Claim { + Claim { + id: String::new(), + form, + status: Status::Minted, + receipt: None, + corpus: corpus.to_owned(), + codec: None, + candidate: None, + incumbent: None, + family: None, + against: None, + bound: None, + bytes: None, + steps: None, + observed_bytes: None, + observed_steps: None, + members: Vec::new(), + } + } + + /// The closed claim's answer, when it has one. + pub fn closed(&self) -> Option { + Some(Closed { + bytes: self.bytes?, + steps: self.steps?, + members: self.members.clone(), + }) + } + + /// Whether the factory decided it (and so it is never decided again). + pub fn final_(&self) -> bool { + self.status != Status::Minted + && self + .receipt + .as_deref() + .is_some_and(|b| b.starts_with("factory:")) + } +} + +/// The κ of a claim's question: SHA-256 of `uorc/claim/1`, the form, and the +/// question's fields (codec or candidate and incumbent, corpus, family, the +/// comparator and bound), one `key value` line each. +pub fn claim_kappa(claim: &Claim) -> String { + let mut text = format!("uorc/claim/1\nform {:?}\n", claim.form).to_lowercase(); + let mut line = |k: &str, v: Option| { + if let Some(v) = v { + text.push_str(&format!("{k} {v}\n")); + } + }; + line("codec", claim.codec.clone()); + line("candidate", claim.candidate.clone()); + line("incumbent", claim.incumbent.clone()); + line("corpus", Some(claim.corpus.clone())); + line("family", claim.family.clone()); + line("against", claim.against.clone()); + line("bound", claim.bound.map(|b| b.to_string())); + sha256_hex(text.as_bytes()) +} + +/// A comparator's pinned archive size on a corpus: a fact measured once by +/// running that tool version, kept as a validation authority (it never +/// enters uorc's coding). +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Comparator { + /// The corpus κ. + pub corpus: String, + /// Tool and settings (`xz -9e`). + pub tool: String, + /// The tool's version line. + pub version: String, + /// Total archive bytes over the corpus. + pub bytes: u64, + /// Where the measurement was published. + pub source: String, +} + +/// The register, `frontier.toml`. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +pub struct Register { + /// [`SCHEMA`]. + pub schema: String, + /// κ-named corpora. + #[serde(default)] + pub corpus: Vec, + /// Pinned comparator sizes. + #[serde(default)] + pub comparator: Vec, + /// Codec points. + #[serde(default)] + pub point: Vec, + /// Claims, in the order they were minted. + #[serde(default)] + pub claim: Vec, +} + +impl Default for Register { + fn default() -> Register { + Register { + schema: SCHEMA.to_owned(), + corpus: Vec::new(), + comparator: Vec::new(), + point: Vec::new(), + claim: Vec::new(), + } + } +} + +const HEADER: &str = + "# uorc claim register (uorc/frontier/1). Written by `frontier`; see crates/frontier.\n\ +# Every κ here recomputes from the fields beside it (`frontier check`).\n\n"; + +impl Register { + /// Parse a register from TOML text and check it ([`Register::check`]). + pub fn parse(text: &str) -> Result { + let register: Register = toml::from_str(text).map_err(|e| Error::Parse(e.to_string()))?; + register.check()?; + Ok(register) + } + + /// Read the register at `path`. + pub fn load(path: &Path) -> Result { + let text = + std::fs::read_to_string(path).map_err(|e| Error::Io(path.display().to_string(), e))?; + Register::parse(&text) + } + + /// The register as TOML text, exactly as [`Register::save`] writes it. + pub fn to_text(&self) -> Result { + let body = toml::to_string(self).map_err(|e| Error::Parse(e.to_string()))?; + Ok(format!("{HEADER}{body}")) + } + + /// Write the register to `path`. + pub fn save(&self, path: &Path) -> Result<(), Error> { + self.check()?; + std::fs::write(path, self.to_text()?).map_err(|e| Error::Io(path.display().to_string(), e)) + } + + /// Every stored κ recomputes, every claim names known corpora and + /// points, and no question appears twice. + pub fn check(&self) -> Result<(), Error> { + let bad = |m: String| Err(Error::Inconsistent(m)); + if self.schema != SCHEMA { + return bad(format!("schema {} is not {SCHEMA}", self.schema)); + } + for c in &self.corpus { + if corpus_kappa(&c.members) != c.kappa { + return bad(format!("corpus {} κ does not recompute", c.name)); + } + } + for p in &self.point { + if p.point()?.kappa() != p.kappa { + return bad(format!("point {} κ does not recompute", p.kappa)); + } + } + let mut seen = BTreeMap::new(); + for c in &self.claim { + if claim_kappa(c) != c.id { + return bad(format!("claim {} κ does not recompute", c.id)); + } + if seen.insert(c.id.clone(), ()).is_some() { + return bad(format!("claim {} appears twice", c.id)); + } + if self.corpus_by_kappa(&c.corpus).is_none() { + return bad(format!("claim {} names an unknown corpus", c.id)); + } + for p in [&c.codec, &c.candidate, &c.incumbent].into_iter().flatten() { + if !self.point.iter().any(|q| &q.kappa == p) { + return bad(format!("claim {} names an unknown point {p}", c.id)); + } + } + } + Ok(()) + } + + /// The corpus called `name`. + pub fn corpus_named(&self, name: &str) -> Result<&Corpus, Error> { + self.corpus + .iter() + .find(|c| c.name == name) + .ok_or_else(|| Error::Unknown(format!("corpus {name}"))) + } + + /// The corpus of κ `kappa`. + pub fn corpus_by_kappa(&self, kappa: &str) -> Option<&Corpus> { + self.corpus.iter().find(|c| c.kappa == kappa) + } + + /// The claim of κ `kappa`, when known. + pub fn known(&self, kappa: &str) -> Option<&Claim> { + self.claim.iter().find(|c| c.id == kappa) + } + + /// Record a point (once). + pub fn add_point(&mut self, point: &CodecPoint, label: Option<&str>) { + let kappa = point.kappa(); + match self.point.iter_mut().find(|p| p.kappa == kappa) { + Some(p) => { + if p.label.is_none() { + p.label = label.map(str::to_owned); + } + } + None => self.point.push(point.record(label)), + } + } + + /// Record a corpus (once; a second corpus of the same name must be the + /// same corpus). + pub fn add_corpus(&mut self, corpus: Corpus) -> Result<(), Error> { + match self.corpus.iter().find(|c| c.name == corpus.name) { + Some(c) if c.kappa == corpus.kappa => Ok(()), + Some(_) => Err(Error::Inconsistent(format!( + "a different corpus is already called {}", + corpus.name + ))), + None => { + self.corpus.push(corpus); + Ok(()) + } + } + } + + /// Put `claim` in the register under its κ, replacing an earlier record + /// of the same question. + pub fn put(&mut self, mut claim: Claim) -> &Claim { + claim.id = claim_kappa(&claim); + let at = match self.claim.iter().position(|c| c.id == claim.id) { + Some(k) => { + self.claim[k] = claim; + k + } + None => { + self.claim.push(claim); + self.claim.len() - 1 + } + }; + &self.claim[at] + } + + /// The closed question for `point` on `corpus`. + pub fn closed_question(point: &CodecPoint, corpus: &Corpus) -> Claim { + let mut q = Claim::question(Form::Closed, &corpus.kappa); + q.codec = Some(point.kappa()); + q.id = claim_kappa(&q); + q + } + + /// Decide "point codes corpus in exactly N bytes and S steps". + /// + /// A claim the factory decided is returned as recorded and never rerun. + /// So is one decided locally when `by` is local too. Otherwise the shipped + /// codec runs over `files` (the corpus members' bytes, in order): a + /// claim with stated bytes and steps is proved when the run reproduces + /// them exactly and refuted (keeping what was observed) when it does not; + /// a claim with none records the run's values, proved by that run. + pub fn decide( + &mut self, + point: &CodecPoint, + corpus: &Corpus, + files: &[Vec], + by: &str, + ) -> Result { + let q = Register::closed_question(point, corpus); + let factory = by.starts_with("factory:"); + if let Some(known) = self.known(&q.id) { + if known.final_() || (!factory && known.status != Status::Minted) { + if let Some(mut closed) = known.closed() { + // a refuted statement answers with what was observed + closed.bytes = known.observed_bytes.unwrap_or(closed.bytes); + closed.steps = known.observed_steps.unwrap_or(closed.steps); + return Ok(closed); + } + } + } + self.add_corpus(corpus.clone())?; + self.add_point(point, None); + let run = measure(point, corpus, files)?; + let mut claim = self.known(&q.id).cloned().unwrap_or(q); + match (claim.bytes, claim.steps) { + (Some(b), Some(s)) if (b, s) != (run.bytes, run.steps) => { + claim.status = Status::Refuted; + claim.observed_bytes = Some(run.bytes); + claim.observed_steps = Some(run.steps); + } + _ => { + claim.status = Status::Proved; + claim.bytes = Some(run.bytes); + claim.steps = Some(run.steps); + claim.observed_bytes = None; + claim.observed_steps = None; + } + } + claim.members = run.members.clone(); + claim.receipt = Some(by.to_owned()); + self.put(claim); + Ok(run) + } + + /// Decide every bound claim of `point` on `corpus` against the pinned + /// comparators, from the closed claim (no run): proved when the archive + /// is no larger than the comparator's. + pub fn decide_bounds(&mut self, point: &CodecPoint, corpus: &Corpus, by: &str) -> Vec { + let Some(closed) = self + .known(&Register::closed_question(point, corpus).id) + .filter(|c| c.status == Status::Proved) + .and_then(Claim::closed) + else { + return Vec::new(); + }; + let comparators: Vec = self + .comparator + .iter() + .filter(|c| c.corpus == corpus.kappa) + .cloned() + .collect(); + comparators + .iter() + .map(|c| { + let mut q = Claim::question(Form::Bound, &corpus.kappa); + q.codec = Some(point.kappa()); + q.against = Some(c.tool.clone()); + q.bound = Some(c.bytes); + q.status = if closed.bytes <= c.bytes { + Status::Proved + } else { + Status::Refuted + }; + q.receipt = Some(by.to_owned()); + self.put(q).clone() + }) + .collect() + } + + /// Decide "candidate dominates incumbent on `family` of `corpus`" from + /// their closed claims, both of which must be proved; `None` when either + /// is missing. The result is recorded under its κ. + pub fn decide_dominance( + &mut self, + candidate: &CodecPoint, + incumbent: &CodecPoint, + family: Option<&str>, + corpus: &Corpus, + by: &str, + ) -> Option { + let answer = |p: &CodecPoint| { + self.known(&Register::closed_question(p, corpus).id) + .filter(|c| c.status == Status::Proved) + .and_then(Claim::closed) + }; + let (c, i) = (answer(candidate)?, answer(incumbent)?); + let mut q = Claim::question(Form::Dominance, &corpus.kappa); + q.candidate = Some(candidate.kappa()); + q.incumbent = Some(incumbent.kappa()); + q.family = family.map(str::to_owned); + q.status = if dominates(&c, &i, family) { + Status::Proved + } else { + Status::Refuted + }; + q.receipt = Some(by.to_owned()); + Some(self.put(q).clone()) + } + + /// Record `point` as excluded on `corpus` (a refuted point, never rerun). + pub fn exclude(&mut self, point: &CodecPoint, corpus: &Corpus, by: &str) -> Claim { + self.add_point(point, None); + let mut q = Claim::question(Form::Exclusion, &corpus.kappa); + q.codec = Some(point.kappa()); + q.status = Status::Proved; + q.receipt = Some(by.to_owned()); + self.put(q).clone() + } +} + +/// Run the codec at `point` over the corpus members `files`: compress each +/// member as its own stream, read the decode steps from the frame headers, +/// and decompress it back. Exact and deterministic: the result depends on +/// the point and the bytes alone (not on the thread count or the machine). +pub fn measure(point: &CodecPoint, corpus: &Corpus, files: &[Vec]) -> Result { + if point.state.is_some() || point.lanes != 1 { + return Err(Error::Codec( + "this client codes fresh models in one lane only".to_owned(), + )); + } + if files.len() != corpus.members.len() { + return Err(Error::Member(format!( + "{} files for {} members", + files.len(), + corpus.members.len() + ))); + } + let threads = uorc::default_threads(); + let mut members = Vec::with_capacity(files.len()); + for (m, input) in corpus.members.iter().zip(files) { + let fail = |what: &str| Error::Codec(format!("{}: {what}", m.name)); + let mut stream = Vec::new(); + let mut fixed = ([0; portfolio::ENTRY], [0; portfolio::FAMILIES]); + let table = point.plan.table(&mut fixed); + uorc::compress_stream_with(&input[..], &mut stream, threads, &table) + .map_err(|e| fail(&format!("compress: {e}")))?; + let mut steps = 0u64; + for frame in uorc::frames(&stream).map_err(|e| fail(&format!("frames: {e}")))? { + let info = uorc::inspect(frame).map_err(|e| fail(&format!("inspect: {e}")))?; + let s = uorc::performance::frame_steps(&info).ok_or_else(|| { + fail(&format!( + "a {} frame has no step value", + info.representation.name() + )) + })?; + steps = steps.checked_add(s).ok_or_else(|| fail("step overflow"))?; + } + let back = uorc::decompress(&stream, uorc::DEFAULT_DECODE_WORK) + .map_err(|e| fail(&format!("decompress: {e}")))?; + if back != *input { + return Err(fail("the archive does not round-trip")); + } + let head = &input[..input.len().min(uorc::FRAME)]; + members.push(MemberResult { + name: m.name.clone(), + family: FAMILIES[portfolio::family(head)].to_owned(), + bytes: stream.len() as u64, + steps, + }); + } + Ok(Closed { + bytes: members.iter().map(|m| m.bytes).sum(), + steps: members.iter().map(|m| m.steps).sum(), + members, + }) +} + +/// The export identity recorded in `generated/rust/factory.identity` under +/// `repo` (its `export ` line). +pub fn export_identity(repo: &Path) -> Result { + let path = repo.join("generated/rust/factory.identity"); + let text = + std::fs::read_to_string(&path).map_err(|e| Error::Io(path.display().to_string(), e))?; + text.lines() + .find_map(|l| l.strip_prefix("export ")) + .map(|s| s.trim().to_owned()) + .ok_or_else(|| Error::Parse(format!("{} has no export line", path.display()))) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn tiny_corpus() -> (Corpus, Vec>) { + let files: Vec> = vec![ + b"hello hello hello hello".to_vec(), + (0..20_000u32).map(|i| (i * 7 % 251) as u8).collect(), + Vec::new(), + ]; + let members = ["a.txt", "b.bin", "empty"] + .iter() + .zip(&files) + .map(|(n, f)| Member::of(n, f)) + .collect(); + (Corpus::new("tiny", "test", false, members), files) + } + + #[test] + fn closed_claims_are_decided_once_and_reproduce() { + let (corpus, files) = tiny_corpus(); + let point = CodecPoint::shipped("test-export"); + let mut reg = Register::default(); + let first = reg + .decide(&point, &corpus, &files, "local") + .expect("decide"); + assert_eq!(first.members.len(), 3); + assert_eq!(first.members[2].steps, 0); + // known by κ: a local decision is not rerun locally + let again = reg.decide(&point, &corpus, &[], "local").expect("known"); + assert_eq!(first, again); + // the factory re-decides a local result and proves it + reg.decide(&point, &corpus, &files, "factory:x") + .expect("factory"); + let claim = reg + .known(&Register::closed_question(&point, &corpus).id) + .expect("claim"); + assert_eq!(claim.status, Status::Proved); + assert!(claim.final_()); + // a wrong stated answer is refuted with the observation kept + let mut wrong = claim.clone(); + wrong.bytes = Some(first.bytes + 1); + wrong.status = Status::Minted; + wrong.receipt = None; + reg.put(wrong); + reg.decide(&point, &corpus, &files, "factory:y") + .expect("refute"); + let claim = reg + .known(&Register::closed_question(&point, &corpus).id) + .expect("claim"); + assert_eq!(claim.status, Status::Refuted); + assert_eq!(claim.observed_bytes, Some(first.bytes)); + // the text form round-trips + let text = reg.to_text().expect("text"); + assert_eq!(Register::parse(&text).expect("parse"), reg); + } + + #[test] + fn the_shipped_plan_is_the_shipped_client() { + let (corpus, files) = tiny_corpus(); + let run = measure(&CodecPoint::shipped("e"), &corpus, &files).expect("measure"); + for (m, f) in run.members.iter().zip(&files) { + assert_eq!( + m.bytes, + uorc::compress(f, 0).expect("compress").len() as u64 + ); + } + } + + #[test] + fn dominance_and_bounds_are_decided_from_closed_claims() { + let (corpus, files) = tiny_corpus(); + let shipped = CodecPoint::shipped("e"); + let v03 = CodecPoint { + plan: Plan::Fixed(Strategy { + x86: false, + profile: uorc::ncm::V03, + }), + ..shipped.clone() + }; + let mut reg = Register::default(); + let a = reg.decide(&shipped, &corpus, &files, "local").expect("a"); + let b = reg.decide(&v03, &corpus, &files, "local").expect("b"); + let d = reg + .decide_dominance(&v03, &shipped, None, &corpus, "local") + .expect("both known"); + assert_eq!(d.status == Status::Proved, dominates(&b, &a, None)); + reg.comparator.push(Comparator { + corpus: corpus.kappa.clone(), + tool: "none".to_owned(), + version: "-".to_owned(), + bytes: a.bytes, + source: "test".to_owned(), + }); + let bounds = reg.decide_bounds(&shipped, &corpus, "local"); + assert_eq!(bounds.len(), 1); + assert_eq!(bounds[0].status, Status::Proved); + reg.check().expect("consistent"); + } + + #[test] + fn steps_follow_the_measure() { + let (corpus, files) = tiny_corpus(); + let run = measure(&CodecPoint::shipped("e"), &corpus, &files).expect("measure"); + let stream = uorc::compress(&files[1], 0).expect("compress"); + let info = uorc::inspect(uorc::frames(&stream).expect("frames")[0]).expect("inspect"); + let per_byte = run.members[1].steps / files[1].len() as u64; + assert!(matches!( + info.representation, + uorc::Representation::Ncm | uorc::Representation::Raw + )); + assert!(per_byte == 1 || per_byte.is_multiple_of(8)); + } + + #[test] + fn the_repository_register_is_consistent() { + let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../frontier.toml"); + let reg = Register::load(&path).expect("frontier.toml loads and checks"); + let text = std::fs::read_to_string(&path).expect("read"); + assert_eq!( + reg.to_text().expect("text"), + text, + "frontier.toml is in canonical form" + ); + } +} diff --git a/crates/frontier/src/main.rs b/crates/frontier/src/main.rs new file mode 100644 index 00000000..6d6635b6 --- /dev/null +++ b/crates/frontier/src/main.rs @@ -0,0 +1,464 @@ +//! `frontier`: the claim register's command line. +//! +//! ```text +//! frontier check [--register frontier.toml] +//! frontier pin NAME --source SRC [--public] (--dir DIR | --git REV PATH...) +//! frontier compare NAME [--dir DIR] [--source TEXT] +//! frontier decide [--corpus NAME[=DIR]]... [--point KAPPA] [--label TEXT] [--by WHO] +//! frontier report [--point KAPPA] --out DIR +//! ``` +//! +//! Every command reads and writes `--register` (default `frontier.toml`) and +//! takes `--repo` (default `.`) for git sources and the export identity. +//! `decide` with no `--corpus` decides every corpus whose bytes it can reach +//! offline (git sources); with no `--point` it decides the shipped client's +//! point. `--by` is `local` unless the factory names itself +//! (`factory:`). + +use std::collections::BTreeMap; +use std::path::{Path, PathBuf}; +use std::process::ExitCode; + +use frontier::{ + export_identity, CodecPoint, Comparator, Corpus, Error, Form, Member, Register, Status, + FAMILIES, +}; + +struct Args { + command: String, + positional: Vec, + options: BTreeMap>, + flags: Vec, +} + +fn parse() -> Result { + let mut it = std::env::args().skip(1); + let command = it.next().ok_or_else(|| "missing command".to_owned())?; + let mut args = Args { + command, + positional: Vec::new(), + options: BTreeMap::new(), + flags: Vec::new(), + }; + while let Some(a) = it.next() { + match a.strip_prefix("--") { + Some(flag @ "public") => args.flags.push(flag.to_owned()), + Some(key) => { + let v = it.next().ok_or_else(|| format!("--{key} needs a value"))?; + args.options.entry(key.to_owned()).or_default().push(v); + } + None => args.positional.push(a), + } + } + Ok(args) +} + +impl Args { + fn one(&self, key: &str) -> Option<&str> { + self.options + .get(key) + .and_then(|v| v.last()) + .map(String::as_str) + } + fn all(&self, key: &str) -> &[String] { + self.options.get(key).map_or(&[], Vec::as_slice) + } +} + +fn main() -> ExitCode { + match run() { + Ok(()) => ExitCode::SUCCESS, + Err(e) => { + eprintln!("frontier: {e}"); + ExitCode::from(2) + } + } +} + +fn run() -> Result<(), String> { + let args = parse()?; + let register_path = PathBuf::from(args.one("register").unwrap_or("frontier.toml")); + let repo = PathBuf::from(args.one("repo").unwrap_or(".")); + let load = || -> Result { + if register_path.exists() { + Register::load(®ister_path).map_err(|e| e.to_string()) + } else { + Ok(Register::default()) + } + }; + let save = |r: &Register| r.save(®ister_path).map_err(|e| e.to_string()); + match args.command.as_str() { + "check" => { + let r = load()?; + let text = std::fs::read_to_string(®ister_path).map_err(|e| e.to_string())?; + if r.to_text().map_err(|e| e.to_string())? != text { + return Err( + "frontier.toml is not in canonical form (run any writing command)".into(), + ); + } + println!( + "ok: {} corpora, {} points, {} claims", + r.corpus.len(), + r.point.len(), + r.claim.len() + ); + Ok(()) + } + "pin" => { + let mut r = load()?; + let name = args.positional.first().ok_or("pin NAME")?; + let source = args.one("source").ok_or("pin needs --source")?; + let members = match (args.one("dir"), args.one("git")) { + (Some(dir), None) => dir_members(Path::new(dir))?, + (None, Some(rev)) => args.positional[1..] + .iter() + .map(|p| git_member(&repo, rev, p)) + .collect::>()?, + _ => return Err("pin needs --dir DIR or --git REV PATH...".into()), + }; + let corpus = Corpus::new( + name, + source, + args.flags.iter().any(|f| f == "public"), + members, + ); + println!( + "{} {} ({} members, {} bytes)", + corpus.name, + corpus.kappa, + corpus.members.len(), + corpus.bytes() + ); + r.add_corpus(corpus).map_err(|e| e.to_string())?; + save(&r) + } + "compare" => { + let mut r = load()?; + let name = args.positional.first().ok_or("compare NAME")?; + let corpus = r.corpus_named(name).map_err(|e| e.to_string())?.clone(); + let files = corpus + .materialize(args.one("dir").map(Path::new), &repo) + .map_err(|e| e.to_string())?; + let source = args.one("source").unwrap_or("measured by frontier compare"); + for (tool, cmd, argv, version) in [ + ("gzip -9", "gzip", &["-9", "-c"][..], &["--version"][..]), + ("bzip2 -9", "bzip2", &["-9", "-c"][..], &["--help"][..]), + ("xz -9e", "xz", &["-9e", "-c"][..], &["--version"][..]), + ] { + let Some(version) = first_line(cmd, version) else { + continue; + }; + let mut total = 0u64; + for f in &files { + total += stdin_size(cmd, argv, f)?; + } + r.comparator + .retain(|c| !(c.corpus == corpus.kappa && c.tool == tool)); + r.comparator.push(Comparator { + corpus: corpus.kappa.clone(), + tool: tool.to_owned(), + version, + bytes: total, + source: source.to_owned(), + }); + println!("{tool}: {total}"); + } + save(&r) + } + "decide" => { + let mut r = load()?; + let by = args.one("by").unwrap_or("local").to_owned(); + let point = point_of(&r, &args, &repo)?; + r.add_point(&point, args.one("label")); + let targets: Vec<(Corpus, Option)> = if args.all("corpus").is_empty() { + r.corpus + .iter() + .filter(|c| c.source.starts_with("git:")) + .map(|c| (c.clone(), None)) + .collect() + } else { + args.all("corpus") + .iter() + .map(|spec| { + let (name, dir) = match spec.split_once('=') { + Some((n, d)) => (n, Some(PathBuf::from(d))), + None => (spec.as_str(), None), + }; + Ok(( + r.corpus_named(name).map_err(|e| e.to_string())?.clone(), + dir, + )) + }) + .collect::>()? + }; + let mut refuted = 0; + for (corpus, dir) in targets { + let q = Register::closed_question(&point, &corpus); + let needs_run = r.known(&q.id).is_none_or(|k| { + !(k.final_() || (!by.starts_with("factory:") && k.status != Status::Minted)) + }); + let files = if needs_run { + corpus + .materialize(dir.as_deref(), &repo) + .map_err(|e| e.to_string())? + } else { + Vec::new() + }; + let closed = r + .decide(&point, &corpus, &files, &by) + .map_err(|e| e.to_string())?; + let claim = r.known(&q.id).cloned().ok_or("decided claim")?; + println!( + "closed {} on {}: {} bytes, {} steps: {}{}", + &point.kappa()[..12], + corpus.name, + closed.bytes, + closed.steps, + claim.status.name(), + if needs_run { "" } else { " (known by κ)" } + ); + refuted += usize::from(claim.status == Status::Refuted); + for b in r.decide_bounds(&point, &corpus, &by) { + println!( + " bound {} <= {} ({}): {}", + corpus.name, + b.bound.unwrap_or(0), + b.against.as_deref().unwrap_or(""), + b.status.name() + ); + } + save(&r)?; + } + if refuted > 0 { + return Err(format!( + "{refuted} closed claim(s) refuted: the codec did not reproduce them" + )); + } + Ok(()) + } + "report" => { + let r = load()?; + let point = point_of(&r, &args, &repo)?; + let out = PathBuf::from(args.one("out").ok_or("report needs --out DIR")?); + std::fs::create_dir_all(&out).map_err(|e| e.to_string())?; + std::fs::write(out.join("frontier.md"), report_md(&r, &point)) + .map_err(|e| e.to_string())?; + std::fs::write( + out.join("frontier.toml"), + r.to_text().map_err(|e| e.to_string())?, + ) + .map_err(|e| e.to_string())?; + println!("wrote {}/frontier.{{md,toml}}", out.display()); + Ok(()) + } + other => Err(format!("unknown command {other}")), + } +} + +fn point_of(r: &Register, args: &Args, repo: &Path) -> Result { + match args.one("point") { + Some(k) => r + .point + .iter() + .find(|p| p.kappa.starts_with(k)) + .ok_or_else(|| format!("no point {k}"))? + .point() + .map_err(|e| e.to_string()), + None => Ok(CodecPoint::shipped( + &export_identity(repo).map_err(|e: Error| e.to_string())?, + )), + } +} + +fn dir_members(dir: &Path) -> Result, String> { + let mut names: Vec = std::fs::read_dir(dir) + .map_err(|e| format!("{}: {e}", dir.display()))? + .filter_map(Result::ok) + .filter(|e| e.file_type().is_ok_and(|t| t.is_file())) + .map(|e| e.file_name().to_string_lossy().into_owned()) + .collect(); + names.sort(); + names + .iter() + .map(|n| { + let bytes = std::fs::read(dir.join(n)).map_err(|e| format!("{n}: {e}"))?; + Ok(Member::of(n, &bytes)) + }) + .collect() +} + +fn git_member(repo: &Path, rev: &str, path: &str) -> Result { + let out = std::process::Command::new("git") + .arg("-C") + .arg(repo) + .args(["cat-file", "blob", &format!("{rev}:{path}")]) + .output() + .map_err(|e| e.to_string())?; + if !out.status.success() { + return Err(format!("git {rev}:{path} not found")); + } + Ok(Member::of(path, &out.stdout)) +} + +fn first_line(cmd: &str, argv: &[&str]) -> Option { + let out = std::process::Command::new(cmd).args(argv).output().ok()?; + let text = format!( + "{}{}", + String::from_utf8_lossy(&out.stdout), + String::from_utf8_lossy(&out.stderr) + ); + text.lines() + .find(|l| !l.trim().is_empty()) + .map(|l| l.trim().to_owned()) +} + +fn stdin_size(cmd: &str, argv: &[&str], input: &[u8]) -> Result { + use std::io::Write; + let mut child = std::process::Command::new(cmd) + .args(argv) + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() + .map_err(|e| format!("{cmd}: {e}"))?; + let mut stdin = child.stdin.take().ok_or("stdin")?; + let data = input.to_vec(); + let writer = std::thread::spawn(move || stdin.write_all(&data)); + let out = child + .wait_with_output() + .map_err(|e| format!("{cmd}: {e}"))?; + writer + .join() + .map_err(|_| "writer".to_owned())? + .map_err(|e| format!("{cmd}: {e}"))?; + if !out.status.success() { + return Err(format!("{cmd} failed")); + } + Ok(out.stdout.len() as u64) +} + +/// The release notes section: every claim about `point`, then the register's +/// other decided claims by form. +fn report_md(r: &Register, point: &CodecPoint) -> String { + let k = point.kappa(); + let name = |kappa: &str| { + r.corpus_by_kappa(kappa) + .map_or("?".to_owned(), |c| c.name.clone()) + }; + let mut md = vec![ + "## Closed claims".to_owned(), + String::new(), + format!( + "Codec point `{}` (export `{}`, plan {}, {} lane). Sizes and decode steps are exact: each was decided by running this codec over the κ-named corpus and is recorded with its decision in the release's `frontier.toml`. A step is one model input evaluated for one coded bit.", + &k[..16], + &point.export[..16.min(point.export.len())], + point.plan_text().split(' ').next().unwrap_or(""), + point.lanes + ), + String::new(), + "| corpus | corpus κ | input bytes | archive bytes | decode steps | steps per byte | status | decided by |".to_owned(), + "| --- | --- | ---: | ---: | ---: | ---: | --- | --- |".to_owned(), + ]; + for c in r + .claim + .iter() + .filter(|c| c.form == Form::Closed && c.codec.as_deref() == Some(&k)) + { + let input = r.corpus_by_kappa(&c.corpus).map_or(0, Corpus::bytes); + let steps = c.observed_steps.or(c.steps).unwrap_or(0); + md.push(format!( + "| {} | `{}` | {} | {} | {} | {:.2} | {} | {} |", + name(&c.corpus), + &c.corpus[..12], + input, + c.observed_bytes + .or(c.bytes) + .map_or("-".into(), |b| b.to_string()), + steps, + if input > 0 { + steps as f64 / input as f64 + } else { + 0.0 + }, + c.status.name(), + c.receipt + .as_deref() + .map_or("-", |b| b.split_once(':').map_or(b, |(w, _)| w)), + )); + } + md.push(String::new()); + let bounds: Vec<_> = r + .claim + .iter() + .filter(|c| c.form == Form::Bound && c.codec.as_deref() == Some(&k)) + .collect(); + if !bounds.is_empty() { + md.push("## UC-PERF-01 target".to_owned()); + md.push(String::new()); + md.push("On every public corpus, the archive is no larger than each pinned comparator's. A refuted row is a comparator this codec does not yet reach.".to_owned()); + md.push(String::new()); + md.push("| corpus | comparator | comparator bytes | uorc bytes | status |".to_owned()); + md.push("| --- | --- | ---: | ---: | --- |".to_owned()); + for b in bounds { + let own = r + .known( + &Register::closed_question( + point, + r.corpus_by_kappa(&b.corpus).expect("known corpus"), + ) + .id, + ) + .and_then(|c| c.bytes) + .unwrap_or(0); + md.push(format!( + "| {} | {} | {} | {} | {} |", + name(&b.corpus), + b.against.as_deref().unwrap_or(""), + b.bound.unwrap_or(0), + own, + b.status.name() + )); + } + md.push(String::new()); + } + let closed: Vec<_> = r + .claim + .iter() + .filter(|c| { + c.form == Form::Closed && c.codec.as_deref() == Some(&k) && c.status == Status::Proved + }) + .collect(); + if let Some(c) = closed.first() { + md.push("
Per family (first claim's corpus)".to_owned()); + md.push(String::new()); + md.push("| family | members | archive bytes | decode steps |".to_owned()); + md.push("| --- | ---: | ---: | ---: |".to_owned()); + for f in FAMILIES { + let ms: Vec<_> = c.members.iter().filter(|m| m.family == f).collect(); + if !ms.is_empty() { + md.push(format!( + "| {f} | {} | {} | {} |", + ms.len(), + ms.iter().map(|m| m.bytes).sum::(), + ms.iter().map(|m| m.steps).sum::() + )); + } + } + md.push(String::new()); + md.push("
".to_owned()); + md.push(String::new()); + } + let others = r + .claim + .iter() + .filter(|c| c.status != Status::Minted && c.codec.as_deref() != Some(&k)) + .count(); + md.push(format!( + "The register holds {} claims over {} corpora and {} codec points; {} concern other points (earlier releases, engine candidates) and are kept by κ, never rerun.", + r.claim.len(), + r.corpus.len(), + r.point.len(), + others + )); + md.push(String::new()); + md.join("\n") +} diff --git a/crates/uorc/src/frame.rs b/crates/uorc/src/frame.rs index 6c04647a..c3fa2689 100644 --- a/crates/uorc/src/frame.rs +++ b/crates/uorc/src/frame.rs @@ -105,7 +105,7 @@ impl Info { format!( "{{\"format\":{},\"profile\":{},\"scope\":\"{}\",\"basis\":{},\"representation\":\"{}\",\"ncm_profile\":{},\"window\":{},\ \"objects\":{},\"object_lengths\":[{}],\"output_bytes\":{},\"body_bytes\":{},\ - \"archive_bytes\":{},\"integrity\":\"{}\",\"digest\":\"{}\",\"integrity_ok\":{}}}", + \"archive_bytes\":{},\"integrity\":\"{}\",\"digest\":\"{}\",\"integrity_ok\":{},\"steps\":{}}}", self.format, self.profile, if self.basis.is_some() { "conditional" } else { "self-contained" }, @@ -122,6 +122,7 @@ impl Info { self.integrity_profile(), self.digest_hex(), self.integrity_ok, + crate::performance::frame_steps(self).map_or_else(|| "null".to_owned(), |n| n.to_string()), ) } } diff --git a/frontier.toml b/frontier.toml new file mode 100644 index 00000000..deb82fcb --- /dev/null +++ b/frontier.toml @@ -0,0 +1,168 @@ +# uorc claim register (uorc/frontier/1). Written by `frontier`; see crates/frontier. +# Every κ here recomputes from the fields beside it (`frontier check`). + +schema = "uorc/frontier/1" + +[[corpus]] +name = "uorc-v0.3.0" +kappa = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +source = "git:v0.3.0" +public = false + +[[corpus.members]] +name = "crates/uorc/Cargo.toml" +sha256 = "035c885fd2c2f445cf9ed49b4ddb2acc4bb948bcf9d44481174d328ca75e9852" +bytes = 634 + +[[corpus.members]] +name = "crates/uorc/tests/kernel-empty-padded.uorc" +sha256 = "a601e92a945f0d8230dd93b2d142dbe11341421844caab3ad606f78239a29551" +bytes = 2654 + +[[corpus.members]] +name = "Justfile" +sha256 = "f5dd19c1baff04c579b515dd1871649bd020f1dfde63a3dc0b34a741903f0885" +bytes = 4630 + +[[corpus.members]] +name = "src/Uorc/Core/RuntimeOpcode.lex.tex" +sha256 = "cb7c7765be1ee31a20e163ffc922b78fb15084949a7f0dc474d6fec2ef64d427" +bytes = 28918 + +[[corpus.members]] +name = "prismpm.lock" +sha256 = "97f3ca37a1077a7819a6ac6206c9132672a05820d547cc834ade18503e5643bf" +bytes = 257584 + +[[corpus.members]] +name = "src/Uorc/Search/FixedTemplates.lex.tex" +sha256 = "a52fbb9c953ed9079cf244466cff544ef334a862af6e2524a79ee72087d8d7f4" +bytes = 395809 + +[[corpus.members]] +name = "standards/nist-sha256/SHA256LongMsg.rsp" +sha256 = "6fac36f37360bcf74ffcf4465c18e30d6d5a04cc90885b901fc3130c16060974" +bytes = 426209 + +[[corpus.members]] +name = "validation/product/read-image-core-compatibility/d5a19f2b6d554a5f18506b1111c7ca92b0ce1b61bfee8a9fc243e6c7203f44d3/diagnostic.tar.gz" +sha256 = "b87eaa03a33bf55279852efd1e0f3960670f90d5525461d7b5a0786fbacabc81" +bytes = 325877 + +[[comparator]] +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +tool = "gzip -9" +version = "gzip 1.12" +bytes = 650271 +source = "frontier compare, cloud container (Ubuntu 24.04 tools)" + +[[comparator]] +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +tool = "bzip2 -9" +version = "bzip2, a block-sorting file compressor. Version 1.0.8, 13-Jul-2019." +bytes = 606478 +source = "frontier compare, cloud container (Ubuntu 24.04 tools)" + +[[comparator]] +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +tool = "xz -9e" +version = "xz (XZ Utils) 5.4.5" +bytes = 595432 +source = "frontier compare, cloud container (Ubuntu 24.04 tools)" + +[[point]] +kappa = "331ad2aa810f712d27d7124b41ab7717e0ca1c1f5ee084c456684aa2f5abdd20" +label = "v0.5 shipped client" +export = "b84a73b11361031ae64a594848ee9161b35f051d15e70ec9031a72c84b755618" +plan = "portfolio" +strategies = "ffff0f0000ffff0f8000ffff070000ffff078000ffff010000ffff018000" +weights = "01010f010c010101100101010501010f01010a010a01040109010c010101" +lanes = 1 + +[[claim]] +id = "8f34ed433450f4e354e92260193b7270c07caaefdfd325ad55c79c870493c5b4" +form = "closed" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "331ad2aa810f712d27d7124b41ab7717e0ca1c1f5ee084c456684aa2f5abdd20" +bytes = 577331 +steps = 211930176 + +[[claim.members]] +name = "crates/uorc/Cargo.toml" +family = "tiny" +bytes = 347 +steps = 76080 + +[[claim.members]] +name = "crates/uorc/tests/kernel-empty-padded.uorc" +family = "tiny" +bytes = 1235 +steps = 509568 + +[[claim.members]] +name = "Justfile" +family = "small" +bytes = 1674 +steps = 518560 + +[[claim.members]] +name = "src/Uorc/Core/RuntimeOpcode.lex.tex" +family = "small" +bytes = 1609 +steps = 5552256 + +[[claim.members]] +name = "prismpm.lock" +family = "text" +bytes = 41682 +steps = 49456128 + +[[claim.members]] +name = "src/Uorc/Search/FixedTemplates.lex.tex" +family = "text" +bytes = 6225 +steps = 75995328 + +[[claim.members]] +name = "standards/nist-sha256/SHA256LongMsg.rsp" +family = "text" +bytes = 212699 +steps = 51145080 + +[[claim.members]] +name = "validation/product/read-image-core-compatibility/d5a19f2b6d554a5f18506b1111c7ca92b0ce1b61bfee8a9fc243e6c7203f44d3/diagnostic.tar.gz" +family = "other" +bytes = 311860 +steps = 28677176 + +[[claim]] +id = "920ce28da479533995d2b3594e890d7718dd860cab95cf5421c06649712da59e" +form = "bound" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "331ad2aa810f712d27d7124b41ab7717e0ca1c1f5ee084c456684aa2f5abdd20" +against = "gzip -9" +bound = 650271 + +[[claim]] +id = "99e86369f21e9eec744d7ec7cf951794663e4874cf903d67165fc1500f47628c" +form = "bound" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "331ad2aa810f712d27d7124b41ab7717e0ca1c1f5ee084c456684aa2f5abdd20" +against = "bzip2 -9" +bound = 606478 + +[[claim]] +id = "b888d209172616914d6356c49eafb26e113cfbe201f9693466af6ab5147be920" +form = "bound" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "331ad2aa810f712d27d7124b41ab7717e0ca1c1f5ee084c456684aa2f5abdd20" +against = "xz -9e" +bound = 595432 From fb23393b82cf727869731cdecbbd13dee51ec82b Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 06:07:07 +0000 Subject: [PATCH 5/6] frontier: factory obligation, release notes and the UC-PERF-01 target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The register pins three κ-named corpora (uorc-v0.3.0 from git objects, and Canterbury and Silesia by their published member hashes) and the comparator sizes of the v0.3.0 release run. The release's new hermetic obligation `frontier` (needs native-x86_64) decides the closed claims of the release's codec point over all three and the bound claims against every comparator, publishes frontier.md in the release notes and frontier.toml as an asset. UC-PERF-01 gets a target: on every public corpus the archive is no larger than each pinned comparator's. It stays open, measured_target_unmet, while a bound is refuted (Silesia against zpaq -m5 at v0.3.0). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3QshCSRwiddS64zU3j --- .github/workflows/release.yml | 86 ++++++++- CONFORMANCE.md | 4 +- README.md | 2 +- UORC-VERIFICATION.md | 2 +- factory/README.md | 3 +- factory/graph.json | 7 +- features/suites/source-authority.feature | 4 +- frontier.toml | 225 +++++++++++++++++++++++ model/claim-policy.toml | 4 +- model/ids.toml | 2 +- model/ledger.toml | 6 +- src/Uorc/Claims.lex.tex | 6 +- src/Uorc/Registry.lex.tex | 2 +- 13 files changed, 328 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fb946f78..5978621b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,8 @@ # Builds the uorc client from the committed LexLean-exported Rust (generated/rust) # and publishes it: native binaries, the library source bundle, the WebAssembly -# module, a Canterbury and Silesia benchmark run, and the GitHub Pages site that runs the client. +# module, a Canterbury and Silesia benchmark run, the release's closed claims +# (frontier.toml, decided by running the client over κ-named corpora), and the +# GitHub Pages site that runs the client. # # Every stage is a factory obligation (factory/graph.json, scripts/factory.mjs) # keyed on its own inputs. A stage proved by a receipt is not run again: its @@ -60,6 +62,9 @@ jobs: bench: ${{ steps.route.outputs.bench_route }} bench_identity: ${{ steps.route.outputs.bench_identity }} bench_run: ${{ steps.route.outputs.bench_run }} + frontier: ${{ steps.route.outputs.frontier_route }} + frontier_identity: ${{ steps.route.outputs.frontier_identity }} + frontier_run: ${{ steps.route.outputs.frontier_run }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 with: @@ -81,7 +86,7 @@ jobs: run: | set -euo pipefail node --test scripts/factory.test.mjs >/dev/null - node scripts/factory.mjs route gate native-x86_64-unknown-linux-gnu native-aarch64-unknown-linux-gnu wasm bench publish \ + node scripts/factory.mjs route gate native-x86_64-unknown-linux-gnu native-aarch64-unknown-linux-gnu wasm bench frontier publish \ --context "mode=$MODE" --context "run=$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" | tee -a "$GITHUB_OUTPUT" - name: List the native targets to build id: matrix @@ -246,12 +251,76 @@ jobs: if-no-files-found: error retention-days: 3 + # Layer 2 of the performance model: closed claims. The decider + # (crates/frontier) runs the client over every corpus the register names + # (the offline git corpus, Canterbury and Silesia, each checked against its + # κ), records "this codec point codes corpus κ in exactly N bytes and S + # decode steps" for this release's point, and decides the UC-PERF-01 target + # (no larger than each pinned comparator) from it. A claim the factory + # already decided is never rerun; a stated claim the client does not + # reproduce is refuted and fails the obligation. Hermetic: only the decide + # step's outcome is recorded, so a failed download records nothing. + frontier: + name: closed claims + needs: [factory, native] + if: always() && needs.factory.outputs.frontier == 'observe' && (needs.native.result == 'success' || needs.native.result == 'skipped') + runs-on: ubuntu-24.04 + timeout-minutes: 120 + env: + TAG: ${{ needs.factory.outputs.tag }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + ref: ${{ env.REF }} + fetch-depth: 0 + persist-credentials: false + - name: Fetch the corpora + run: | + set -euo pipefail + mkdir -p corpus/canterbury corpus/silesia + curl -fsSL --retry 5 --retry-all-errors https://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz | tar -xz -C corpus/canterbury + curl -fsSL --retry 5 --retry-all-errors -o silesia.zip https://sun.aei.polsl.pl/~sdeor/corpus/silesia.zip + unzip -q -d corpus/silesia silesia.zip + find corpus/silesia -mindepth 2 -type f -exec mv -t corpus/silesia {} + + - name: Decide the closed claims + id: run + env: + IDENTITY: ${{ needs.factory.outputs.frontier_identity }} + run: | + set -euo pipefail + cargo build --locked --release -p frontier + target/release/frontier decide --label "$TAG" --by "factory:$IDENTITY" \ + --corpus uorc-v0.3.0 --corpus canterbury=corpus/canterbury --corpus silesia=corpus/silesia + target/release/frontier report --out frontier + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + if: always() && (steps.run.outcome == 'success' || steps.run.outcome == 'failure') + with: + name: factory-frontier + path: | + frontier.toml + frontier/ + if-no-files-found: error + retention-days: 90 + - name: Record the outcome + if: always() && (steps.run.outcome == 'success' || steps.run.outcome == 'failure') + env: + IDENTITY: ${{ needs.factory.outputs.frontier_identity }} + OUTCOME: ${{ steps.run.outcome }} + run: node scripts/factory.mjs outcome frontier "$IDENTITY" "$OUTCOME" .tmp/factory + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + if: always() && (steps.run.outcome == 'success' || steps.run.outcome == 'failure') + with: + name: factory-outcome-frontier + path: .tmp/factory/ + if-no-files-found: error + retention-days: 3 + # Packages what the stages proved (from this run or the runs that proved # them) under the tag, and publishes it; a rehearsal keeps the package as an # artifact instead. publish: name: ${{ github.event.inputs.mode == 'rehearsal' && 'package (rehearsal)' || 'publish release' }} - needs: [factory, native, wasm, bench] + needs: [factory, native, wasm, bench, frontier] if: always() && needs.factory.result == 'success' && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') runs-on: ubuntu-24.04 timeout-minutes: 15 @@ -290,6 +359,12 @@ jobs: path: bench run-id: ${{ needs.factory.outputs.bench_run }} github-token: ${{ needs.factory.outputs.bench_run != github.run_id && github.token || '' }} + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 + with: + name: factory-frontier + path: claims + run-id: ${{ needs.factory.outputs.frontier_run }} + github-token: ${{ needs.factory.outputs.frontier_run != github.run_id && github.token || '' }} - name: Package the binaries, the source bundle, the wasm bundle and the site run: | set -euo pipefail @@ -314,7 +389,8 @@ jobs: git archive --format=tar.gz --prefix="uorc-${TAG}-src/" -o "dist/uorc-${TAG}-src.tar.gz" HEAD \ Cargo.toml Cargo.lock rust-toolchain.toml crates/uorc crates/uorc-wasm generated/rust LICENSE-APACHE LICENSE-MIT cp bench/bench.json "dist/uorc-${TAG}-bench.json" - (cd dist && sha256sum uorc-*-wasm.tar.gz uorc-*-src.tar.gz *.json > SHA256SUMS-wasm-src) + cp claims/frontier.toml "dist/uorc-${TAG}-frontier.toml" + (cd dist && sha256sum uorc-*-wasm.tar.gz uorc-*-src.tar.gz *.json *.toml > SHA256SUMS-wasm-src) ls -la dist - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 if: env.MODE == 'rehearsal' @@ -329,7 +405,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail - { printf 'uorc %s\n\n' "$TAG"; printf 'Client: https://%s.github.io/%s/\n\n' "${GITHUB_REPOSITORY_OWNER,,}" "${GITHUB_REPOSITORY#*/}"; cat bench/bench.md; } > notes.md + { printf 'uorc %s\n\n' "$TAG"; printf 'Client: https://%s.github.io/%s/\n\n' "${GITHUB_REPOSITORY_OWNER,,}" "${GITHUB_REPOSITORY#*/}"; cat claims/frontier/frontier.md; echo; cat bench/bench.md; } > notes.md if gh release view "$TAG" >/dev/null 2>&1; then gh release upload "$TAG" dist/* --clobber else diff --git a/CONFORMANCE.md b/CONFORMANCE.md index d1c3a099..4ee5d482 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -107,7 +107,7 @@ The three honesty levels (R2): | --- | --- | --- | | `UC-CHR-01` | `build` | UORC charter, claim-boundary, evidence-boundary, and research-position records are accepted by the locked LexLean project and generate the committed project documentation projections. | | `UC-CHR-02` | `build` | Handwritten project prose cannot define a second UORC specification or BCP-14 semantic rule, while non-authoritative evidence and planning prose remain permitted. | -| `UC-PERF-01` | `open` | measured public-corpus compression: every release runs scripts/bench.mjs on the Canterbury and Silesia corpora against gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd, reports each throughput against the host's measured core count and memory copy rate, and publishes archive sizes and times in the release notes, the release's bench.json and the Pages site; open because the measurement sets no target | +| `UC-PERF-01` | `open` | closed public-corpus claims with a target: every release runs crates/frontier over the Canterbury and Silesia corpora, each pinned by its κ in frontier.toml, records the exact archive bytes and decode steps of its codec point as closed claims the factory decides, and publishes them in the release notes and the release's frontier.toml; the target is that on every public corpus the archive is no larger than each pinned comparator's (gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd from the v0.3.0 release run), decided per comparator as a bound claim; open with the target unmet while any bound is refuted (Silesia against zpaq -m5, 41726363 against 39112562 bytes at v0.3.0); scripts/bench.mjs still reports times against the host's core count and memory copy rate | | `UC-REC-01` | `open` | externally accepted compression record; open unless the external authority actually accepts it | ## varint @@ -135,7 +135,7 @@ The three honesty levels (R2): | --- | --- | --- | --- | --- | | `UC-CHR-01` | `build` | `build_evidence` | `not_measured` | UORC charter, claim-boundary, evidence-boundary, and research-position records are accepted by the locked LexLean project and generate the committed project documentation projections. | | `UC-CHR-02` | `build` | `build_evidence` | `not_measured` | Handwritten project prose cannot define a second UORC specification or BCP-14 semantic rule, while non-authoritative evidence and planning prose remain permitted. | -| `UC-PERF-01` | `open` | `benchmark_measurement` | `measured_no_target` | measured public-corpus compression: every release runs scripts/bench.mjs on the Canterbury and Silesia corpora against gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd, reports each throughput against the host's measured core count and memory copy rate, and publishes archive sizes and times in the release notes, the release's bench.json and the Pages site; open because the measurement sets no target | +| `UC-PERF-01` | `open` | `benchmark_target_unmet` | `measured_target_unmet` | closed public-corpus claims with a target: every release runs crates/frontier over the Canterbury and Silesia corpora, each pinned by its κ in frontier.toml, records the exact archive bytes and decode steps of its codec point as closed claims the factory decides, and publishes them in the release notes and the release's frontier.toml; the target is that on every public corpus the archive is no larger than each pinned comparator's (gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd from the v0.3.0 release run), decided per comparator as a bound claim; open with the target unmet while any bound is refuted (Silesia against zpaq -m5, 41726363 against 39112562 bytes at v0.3.0); scripts/bench.mjs still reports times against the host's core count and memory copy rate | | `UC-REC-01` | `open` | `none` | `not_measured` | externally accepted compression record; open unless the external authority actually accepts it | | `UC-REP-01` | `build` | `build_evidence` | `not_measured` | Source-derived charter projections and complete LexLean build and verification artifacts are byte-identical across clean absolute roots under the locked SDK. | | `UC-REP-02` | `build` | `build_evidence` | `not_measured` | Dependency and execution-boundary failures are explicit and planted SDK-lock, source-lock, adjacent-checkout, and host-PATH fallbacks are rejected. | diff --git a/README.md b/README.md index 652abd19..76f9c00e 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ This table classifies evidence within its verified scope. It does not validate a ## Current research dispositions -- `UC-PERF-01`: `measured_no_target`; evidence `benchmark_measurement`; honesty level `open`. +- `UC-PERF-01`: `measured_target_unmet`; evidence `benchmark_target_unmet`; honesty level `open`. - `UC-REC-01`: `not_measured`; evidence `none`; honesty level `open`. The source-owned bounded ULEB128 codec, errors, and proof inventory are projected in [UORC-VARINT.md](UORC-VARINT.md). diff --git a/UORC-VERIFICATION.md b/UORC-VERIFICATION.md index 755413df..4adc7987 100644 --- a/UORC-VERIFICATION.md +++ b/UORC-VERIFICATION.md @@ -40,7 +40,7 @@ This table classifies evidence within its verified scope. It does not validate a ## Current research dispositions -- `UC-PERF-01`: `measured_no_target`; evidence `benchmark_measurement`; honesty level `open`. +- `UC-PERF-01`: `measured_target_unmet`; evidence `benchmark_target_unmet`; honesty level `open`. - `UC-REC-01`: `not_measured`; evidence `none`; honesty level `open`. The source-owned bounded ULEB128 codec, errors, and proof inventory are projected in [UORC-VARINT.md](UORC-VARINT.md). diff --git a/factory/README.md b/factory/README.md index acb987a3..61baccd2 100644 --- a/factory/README.md +++ b/factory/README.md @@ -8,7 +8,7 @@ identity text (`prism-factory/obligation/1`), receipts on a `factory-receipts` branch, refutation of hermetic failures, retried fetches, and a 16-level weight that orders remaining work. Here the decisions are a small Node host (`scripts/factory.mjs`, tests in `scripts/factory.test.mjs`) over the graph in -`graph.json`, not a kernel-checked model: uorc's graph is fifteen rows. +`graph.json`, not a kernel-checked model: uorc's graph is sixteen rows. ## The graph @@ -24,6 +24,7 @@ that orders remaining work. Here the decisions are a small Node host | `gate` | gate | the identities of the seven bootstrap legs | proved when all seven are | | `native-` (2), `wasm` | fetch | the client set (+ `crates/uorc-wasm/`) | release `native`, `wasm` | | `bench` | fetch | `scripts/bench.mjs`, release.yml, `native-x86_64` | release `bench` | +| `frontier` | hermetic | the client set, `crates/frontier/`, `frontier.toml`, release.yml; needs `native-x86_64` | release `frontier`: decides the closed claims of the release's codec point over every κ-named corpus in `frontier.toml` | | `publish` | fetch | everything, `@mode`, `@run` | release `publish`, `pages` | The formal set is the tree without the product client and the release plumbing. diff --git a/factory/graph.json b/factory/graph.json index 6eaff621..4f145815 100644 --- a/factory/graph.json +++ b/factory/graph.json @@ -1,9 +1,9 @@ { "schema": "uorc/factory-graph/1", "sets": { - "formal": ["", "!client/", "!crates/uorc/", "!crates/uorc-wasm/", "!generated/", "!web/", "!vendor/hologram-brand/", "!scripts/site.", "!scripts/bench.mjs", "!scripts/client-export.mjs", "!factory/", "!scripts/factory.", "!.github/workflows/release.yml", "!.github/workflows/pages.yml", "!.github/workflows/factory.yml", "manifest:crates/conformance/Cargo.toml", "manifest:crates/uorc/Cargo.toml", "manifest:crates/uorc-wasm/Cargo.toml", "manifest:generated/rust/uorc_compress/Cargo.toml", "manifest:generated/rust/uorc_decompress/Cargo.toml"], + "formal": ["", "!client/", "!crates/uorc/", "!crates/uorc-wasm/", "!crates/frontier/", "!frontier.toml", "!generated/", "!web/", "!vendor/hologram-brand/", "!scripts/site.", "!scripts/bench.mjs", "!scripts/client-export.mjs", "!factory/", "!scripts/factory.", "!.github/workflows/release.yml", "!.github/workflows/pages.yml", "!.github/workflows/factory.yml", "manifest:crates/conformance/Cargo.toml", "manifest:crates/uorc/Cargo.toml", "manifest:crates/uorc-wasm/Cargo.toml", "manifest:generated/rust/uorc_compress/Cargo.toml", "manifest:generated/rust/uorc_decompress/Cargo.toml", "manifest:crates/frontier/Cargo.toml"], "lexlean": ["lexlean.toml", "lexlean.lock", "lakefile.toml", "lake-manifest.json", "lean-toolchain", "prismpm.lock", "Justfile", ".github/workflows/bootstrap.yml", "validation/lexlean-verify-hints.json"], - "xtask": ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", ".cargo/", "xtask/", "crates/model/", "manifest:crates/conformance/Cargo.toml", "manifest:crates/uorc/Cargo.toml", "manifest:crates/uorc-wasm/Cargo.toml", "manifest:generated/rust/uorc_compress/Cargo.toml", "manifest:generated/rust/uorc_decompress/Cargo.toml"], + "xtask": ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", ".cargo/", "xtask/", "crates/model/", "manifest:crates/conformance/Cargo.toml", "manifest:crates/uorc/Cargo.toml", "manifest:crates/uorc-wasm/Cargo.toml", "manifest:generated/rust/uorc_compress/Cargo.toml", "manifest:generated/rust/uorc_decompress/Cargo.toml", "manifest:crates/frontier/Cargo.toml"], "scripts": ["scripts/", "!scripts/factory.", "!scripts/site.", "!scripts/bench.mjs", "!scripts/client-export.mjs"], "client": ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", ".cargo/", "crates/uorc/", "generated/rust/", ".github/workflows/release.yml"] }, @@ -22,6 +22,7 @@ {"name": "native-aarch64-unknown-linux-gnu", "kind": "fetch", "environment": "ubuntu-24.04-arm", "run": "cargo test --locked --release -p uorc && cargo build --locked --release -p uorc --target aarch64-unknown-linux-gnu", "inputs": ["&client"], "needs": [], "workflow": "release.yml", "job": "native", "evidence": "factory-native-aarch64-unknown-linux-gnu"}, {"name": "wasm", "kind": "fetch", "environment": "ubuntu-24.04", "run": "cargo build --locked --release -p uorc-wasm --target wasm32-unknown-unknown", "inputs": ["&client", "crates/uorc-wasm/"], "needs": [], "workflow": "release.yml", "job": "wasm", "evidence": "factory-wasm"}, {"name": "bench", "kind": "fetch", "environment": "ubuntu-24.04", "run": "node scripts/bench.mjs --corpus corpus/canterbury,corpus/silesia --steps 0", "inputs": ["scripts/bench.mjs", ".github/workflows/release.yml"], "needs": ["native-x86_64-unknown-linux-gnu"], "workflow": "release.yml", "job": "bench", "evidence": "factory-bench"}, - {"name": "publish", "kind": "fetch", "environment": "ubuntu-24.04", "run": "package, gh release, pages", "inputs": ["", "@mode", "@run"], "needs": ["gate", "native-x86_64-unknown-linux-gnu", "native-aarch64-unknown-linux-gnu", "wasm", "bench"], "workflow": "release.yml", "job": "publish"} + {"name": "frontier", "kind": "hermetic", "environment": "ubuntu-24.04", "run": "frontier decide --corpus uorc-v0.3.0 --corpus canterbury=corpus/canterbury --corpus silesia=corpus/silesia --by factory:", "inputs": ["&client", "crates/frontier/", "frontier.toml", ".github/workflows/release.yml"], "needs": ["native-x86_64-unknown-linux-gnu"], "workflow": "release.yml", "job": "frontier", "evidence": "factory-frontier"}, + {"name": "publish", "kind": "fetch", "environment": "ubuntu-24.04", "run": "package, gh release, pages", "inputs": ["", "@mode", "@run"], "needs": ["gate", "native-x86_64-unknown-linux-gnu", "native-aarch64-unknown-linux-gnu", "wasm", "bench", "frontier"], "workflow": "release.yml", "job": "publish"} ] } diff --git a/features/suites/source-authority.feature b/features/suites/source-authority.feature index dd24f70e..5f469d32 100644 --- a/features/suites/source-authority.feature +++ b/features/suites/source-authority.feature @@ -14,10 +14,10 @@ Feature: source-authority Then the marked evidence remains non-authoritative and the conflicting handwritten rule is rejected by the R1 source-authority gate @UC-PERF-01 @open - Scenario: measured public-corpus compression: every release runs scripts/bench.mjs on the Canterbury and Silesia corpora against gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd, reports each throughput against the host's measured core count and memory copy rate, and publishes archive sizes and times in the release notes, the release's bench.json and the Pages site; open because the measurement sets no target + Scenario: closed public-corpus claims with a target: every release runs crates/frontier over the Canterbury and Silesia corpora, each pinned by its κ in frontier.toml, records the exact archive bytes and decode steps of its codec point as closed claims the factory decides, and publishes them in the release notes and the release's frontier.toml; the target is that on every public corpus the archive is no larger than each pinned comparator's (gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd from the v0.3.0 release run), decided per comparator as a bound claim; open with the target unmet while any bound is refuted (Silesia against zpaq -m5, 41726363 against 39112562 bytes at v0.3.0); scripts/bench.mjs still reports times against the host's core count and memory copy rate Given the registered public-corpus performance claim When the honesty gate reads its disposition - Then the claim remains open with its measurements reported, rather than becoming implementation evidence + Then the claim remains open with its target unmet and its closed claims reported, rather than becoming implementation evidence @UC-REC-01 @open Scenario: externally accepted compression record; open unless the external authority actually accepts it diff --git a/frontier.toml b/frontier.toml index deb82fcb..0ae337c2 100644 --- a/frontier.toml +++ b/frontier.toml @@ -49,6 +49,133 @@ name = "validation/product/read-image-core-compatibility/d5a19f2b6d554a5f18506b1 sha256 = "b87eaa03a33bf55279852efd1e0f3960670f90d5525461d7b5a0786fbacabc81" bytes = 325877 +[[corpus]] +name = "canterbury" +kappa = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +source = "https://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz" +public = true + +[[corpus.members]] +name = "alice29.txt" +sha256 = "7467306ee0feed4971260f3c87421154a05be571d944e9cb021a5713700c38f0" +bytes = 152089 + +[[corpus.members]] +name = "asyoulik.txt" +sha256 = "eaa3526fe53859f34ecdf255712f9ecf0b2c903451d4755b2edaa2e2599cb0fc" +bytes = 125179 + +[[corpus.members]] +name = "cp.html" +sha256 = "e0cd21cef5b6c4069461e949be100080c3ce887de6f1dd8626c480528efaaf61" +bytes = 24603 + +[[corpus.members]] +name = "fields.c" +sha256 = "85d73e354cc50cec76cb5a50537cf8dc035f8cbb8480f9e1cbe2f7d6c23393c7" +bytes = 11150 + +[[corpus.members]] +name = "grammar.lsp" +sha256 = "1b0805dfc0ae706b35aac2bb4e15f02485efd24dda5dbd29de7b2f84d1a88c15" +bytes = 3721 + +[[corpus.members]] +name = "kennedy.xls" +sha256 = "9af47239ca29dfe20e633f80bbbb9a4cc9783d0803d7b2b5626f42e4c3790420" +bytes = 1029744 + +[[corpus.members]] +name = "lcet10.txt" +sha256 = "5314ba1dbb03f471df88bec6cd120a938ef60d0fd3511c5c1dce61bf7463245f" +bytes = 426754 + +[[corpus.members]] +name = "plrabn12.txt" +sha256 = "07e2e0b461af78c7c647cb53dab39de560198e16f799b4516eccf0fbd69f764c" +bytes = 481861 + +[[corpus.members]] +name = "ptt5" +sha256 = "0ec3a75089bb52342813496b17e51377bc9eba3cb519a444d67025354841d650" +bytes = 513216 + +[[corpus.members]] +name = "sum" +sha256 = "ee5733cd76ecc2f9d8ff156adc3c02a7a851051dcf43a2d56ff4ee4ff606bdb3" +bytes = 38240 + +[[corpus.members]] +name = "xargs.1" +sha256 = "c58aeb5d2d1e12751d47e7412b45784405fc30a5671b03d480fa05776e183619" +bytes = 4227 + +[[corpus]] +name = "silesia" +kappa = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +source = "https://sun.aei.polsl.pl/~sdeor/corpus/silesia.zip" +public = true + +[[corpus.members]] +name = "dickens" +sha256 = "b24c37886142e11d0ee687db6ab06f936207aa7f2ea1fd1d9a36763c7a507e6a" +bytes = 10192446 + +[[corpus.members]] +name = "mozilla" +sha256 = "657fc3764b0c75ac9de9623125705831ebbfbe08fed248df73bc2dc66e2a963b" +bytes = 51220480 + +[[corpus.members]] +name = "mr" +sha256 = "68637ed52e3e4860174ed2dc0840ac77d5f1a60abbcb13770d5754e3774d53e6" +bytes = 9970564 + +[[corpus.members]] +name = "nci" +sha256 = "fc63a31770947b8c2062d3b19ca94c00485a232bb91b502021948fee983e1635" +bytes = 33553445 + +[[corpus.members]] +name = "ooffice" +sha256 = "e7ee013880d34dd5208283d0d3d91b07f442e067454276095ded14f322a656eb" +bytes = 6152192 + +[[corpus.members]] +name = "osdb" +sha256 = "60f027179302ca3ad87c58ac90b6be72ec23588aaa7a3b7fe8ecc0f11def3fa3" +bytes = 10085684 + +[[corpus.members]] +name = "reymont" +sha256 = "0eac0114a3dfe6e2ee1f345a0f79d653cb26c3bc9f0ed79238af4933422b7578" +bytes = 6627202 + +[[corpus.members]] +name = "samba" +sha256 = "93ba07bc44d8267789c1d911992f40b089ffa2140b4a160fac11ccae9a40e7b2" +bytes = 21606400 + +[[corpus.members]] +name = "sao" +sha256 = "c2d0ea2cc59d4c21b7fe43a71499342a00cbe530a1d5548770e91ecd6214adcc" +bytes = 7251944 + +[[corpus.members]] +name = "webster" +sha256 = "6a68f69b26daf09f9dd84f7470368553194a0b294fcfa80f1604efb11143a383" +bytes = 41458703 + +[[corpus.members]] +name = "x-ray" +sha256 = "7de9fce1405dc44ae5e6813ed21cd5751e761bd4265655a005d39b9685d1c9ad" +bytes = 8474240 + +[[corpus.members]] +name = "xml" +sha256 = "0e82e54e695c1938e4193448022543845b33020c8be6bf3bf3ead2224903e08c" +bytes = 5345280 + [[comparator]] corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" tool = "gzip -9" @@ -70,6 +197,104 @@ version = "xz (XZ Utils) 5.4.5" bytes = 595432 source = "frontier compare, cloud container (Ubuntu 24.04 tools)" +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "gzip -9" +version = "gzip 1.12" +bytes = 730625 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "bzip2 -9" +version = "bzip2, a block-sorting file compressor. Version 1.0.8, 13-Jul-2019." +bytes = 542710 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "xz -9e" +version = "xz (XZ Utils) 5.4.5" +bytes = 493080 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "zstd -19 --long" +version = "*** Zstandard CLI (64-bit) v1.5.7, by Yann Collet ***" +bytes = 516216 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "brotli -q 11" +version = "brotli 1.1.0" +bytes = 490662 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "zpaq -m5" +version = "zpaq v7.15 journaling archiver, compiled Jan 5 2021" +bytes = 361718 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "c97b3c539721f91651d4826af878ca2422bed982fc3a6be5081f591db052b69c" +tool = "7z PPMd -mx9" +version = "7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20" +bytes = 575170 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "gzip -9" +version = "gzip 1.12" +bytes = 67631918 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "bzip2 -9" +version = "bzip2, a block-sorting file compressor. Version 1.0.8, 13-Jul-2019." +bytes = 54506769 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "xz -9e" +version = "xz (XZ Utils) 5.4.5" +bytes = 48456004 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "zstd -19 --long" +version = "*** Zstandard CLI (64-bit) v1.5.7, by Yann Collet ***" +bytes = 52646619 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "brotli -q 11" +version = "brotli 1.1.0" +bytes = 49564563 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "zpaq -m5" +version = "zpaq v7.15 journaling archiver, compiled Jan 5 2021" +bytes = 39112562 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + +[[comparator]] +corpus = "45094a50011621091810bb027fbd1b5803e603abeabf85ded0f334d08cddd7e9" +tool = "7z PPMd -mx9" +version = "7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20" +bytes = 47684624 +source = "uorc v0.3.0 release bench.json (GitHub ubuntu-24.04 runner)" + [[point]] kappa = "331ad2aa810f712d27d7124b41ab7717e0ca1c1f5ee084c456684aa2f5abdd20" label = "v0.5 shipped client" diff --git a/model/claim-policy.toml b/model/claim-policy.toml index 2142c8bd..eb966c86 100644 --- a/model/claim-policy.toml +++ b/model/claim-policy.toml @@ -167,8 +167,8 @@ implementation_evidence = false [[open_claim]] id = "UC-PERF-01" level = "open" -evidence = "benchmark_measurement" -disposition = "measured_no_target" +evidence = "benchmark_target_unmet" +disposition = "measured_target_unmet" [[open_claim]] id = "UC-REC-01" diff --git a/model/ids.toml b/model/ids.toml index b6a17d04..7a2e1858 100644 --- a/model/ids.toml +++ b/model/ids.toml @@ -19,7 +19,7 @@ statement = "Handwritten project prose cannot define a second UORC specification id = "UC-PERF-01" level = "open" suite = "source-authority" -statement = "measured public-corpus compression: every release runs scripts/bench.mjs on the Canterbury and Silesia corpora against gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd, reports each throughput against the host's measured core count and memory copy rate, and publishes archive sizes and times in the release notes, the release's bench.json and the Pages site; open because the measurement sets no target" +statement = "closed public-corpus claims with a target: every release runs crates/frontier over the Canterbury and Silesia corpora, each pinned by its κ in frontier.toml, records the exact archive bytes and decode steps of its codec point as closed claims the factory decides, and publishes them in the release notes and the release's frontier.toml; the target is that on every public corpus the archive is no larger than each pinned comparator's (gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd from the v0.3.0 release run), decided per comparator as a bound claim; open with the target unmet while any bound is refuted (Silesia against zpaq -m5, 41726363 against 39112562 bytes at v0.3.0); scripts/bench.mjs still reports times against the host's core count and memory copy rate" [[id]] id = "UC-REC-01" diff --git a/model/ledger.toml b/model/ledger.toml index cf47135b..2762b1de 100644 --- a/model/ledger.toml +++ b/model/ledger.toml @@ -22,9 +22,9 @@ feature = "features/suites/source-authority.feature" [[claim]] id = "UC-PERF-01" level = "open" -statement = "measured public-corpus compression: every release runs scripts/bench.mjs on the Canterbury and Silesia corpora against gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd, reports each throughput against the host's measured core count and memory copy rate, and publishes archive sizes and times in the release notes, the release's bench.json and the Pages site; open because the measurement sets no target" -evidence_kind = "benchmark_measurement" -research_disposition = "measured_no_target" +statement = "closed public-corpus claims with a target: every release runs crates/frontier over the Canterbury and Silesia corpora, each pinned by its κ in frontier.toml, records the exact archive bytes and decode steps of its codec point as closed claims the factory decides, and publishes them in the release notes and the release's frontier.toml; the target is that on every public corpus the archive is no larger than each pinned comparator's (gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd from the v0.3.0 release run), decided per comparator as a bound claim; open with the target unmet while any bound is refuted (Silesia against zpaq -m5, 41726363 against 39112562 bytes at v0.3.0); scripts/bench.mjs still reports times against the host's core count and memory copy rate" +evidence_kind = "benchmark_target_unmet" +research_disposition = "measured_target_unmet" feature = "features/suites/source-authority.feature" [[claim]] diff --git a/src/Uorc/Claims.lex.tex b/src/Uorc/Claims.lex.tex index 9847fe2f..5cc30b65 100644 --- a/src/Uorc/Claims.lex.tex +++ b/src/Uorc/Claims.lex.tex @@ -516,7 +516,7 @@ name: performance, parameters: [], result: OpenClaim, - body: (record OpenClaim {id := "UC-PERF-01", level := "open", evidence := "benchmark_measurement", disposition := "measured_no_target"}) + body: (record OpenClaim {id := "UC-PERF-01", level := "open", evidence := "benchmark_target_unmet", disposition := "measured_target_unmet"}) } definition{ @@ -643,7 +643,7 @@ theorem{ name: performance_evidence_unpromoted, parameters: [], - statement: ((project (performance) evidence) = "benchmark_measurement"), + statement: ((project (performance) evidence) = "benchmark_target_unmet"), proof: reflexivity{}, axioms: [] } @@ -651,7 +651,7 @@ theorem{ name: performance_disposition_unpromoted, parameters: [], - statement: ((project (performance) disposition) = "measured_no_target"), + statement: ((project (performance) disposition) = "measured_target_unmet"), proof: reflexivity{}, axioms: [] } diff --git a/src/Uorc/Registry.lex.tex b/src/Uorc/Registry.lex.tex index b5d1b6d4..4753557c 100644 --- a/src/Uorc/Registry.lex.tex +++ b/src/Uorc/Registry.lex.tex @@ -38,7 +38,7 @@ name: ucPerf01, parameters: [], result: ConformanceRow, - body: (record ConformanceRow {id := "UC-PERF-01", level := "open", suite := "source-authority", statement := "measured public-corpus compression: every release runs scripts/bench.mjs on the Canterbury and Silesia corpora against gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd, reports each throughput against the host's measured core count and memory copy rate, and publishes archive sizes and times in the release notes, the release's bench.json and the Pages site; open because the measurement sets no target", given := "the registered public-corpus performance claim", when := "the honesty gate reads its disposition", expected := "the claim remains open with its measurements reported, rather than becoming implementation evidence", evidenceKind := "benchmark_measurement", researchDisposition := "measured_no_target"}) + body: (record ConformanceRow {id := "UC-PERF-01", level := "open", suite := "source-authority", statement := "closed public-corpus claims with a target: every release runs crates/frontier over the Canterbury and Silesia corpora, each pinned by its κ in frontier.toml, records the exact archive bytes and decode steps of its codec point as closed claims the factory decides, and publishes them in the release notes and the release's frontier.toml; the target is that on every public corpus the archive is no larger than each pinned comparator's (gzip, bzip2, xz, zstd, brotli, zpaq and 7-Zip PPMd from the v0.3.0 release run), decided per comparator as a bound claim; open with the target unmet while any bound is refuted (Silesia against zpaq -m5, 41726363 against 39112562 bytes at v0.3.0); scripts/bench.mjs still reports times against the host's core count and memory copy rate", given := "the registered public-corpus performance claim", when := "the honesty gate reads its disposition", expected := "the claim remains open with its target unmet and its closed claims reported, rather than becoming implementation evidence", evidenceKind := "benchmark_target_unmet", researchDisposition := "measured_target_unmet"}) } definition{ From 5d829dc8c32f91d6178149b9f79d1bf41468780c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 07:47:32 +0000 Subject: [PATCH 6/6] frontier: universal exclusion claims (a kernel theorem blocks a point on every corpus) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Form::Universal records a point excluded by a named theorem template and parameter with no corpus, so its κ blocks the point everywhere without a run; Register::excluded answers for exclusions and universal claims alike. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Asa3QshCSRwiddS64zU3j --- crates/frontier/src/lib.rs | 73 +++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/crates/frontier/src/lib.rs b/crates/frontier/src/lib.rs index 24ed7d46..66bc06dd 100644 --- a/crates/frontier/src/lib.rs +++ b/crates/frontier/src/lib.rs @@ -460,6 +460,10 @@ pub enum Form { Dominance, /// A refuted point, recorded so that it is never rerun. Exclusion, + /// A point excluded on every corpus by a named kernel theorem (a + /// template and its parameter): recorded with no corpus, so its κ + /// blocks the point everywhere without a run. + Universal, } /// A claim's status. @@ -540,7 +544,8 @@ pub struct Claim { /// `factory:` (the factory obligation `frontier`). #[serde(default, skip_serializing_if = "Option::is_none")] pub receipt: Option, - /// The corpus κ. + /// The corpus κ; empty for a universal claim (every corpus). + #[serde(default, skip_serializing_if = "String::is_empty")] pub corpus: String, /// The codec point κ (closed, bound, exclusion). #[serde(default, skip_serializing_if = "Option::is_none")] @@ -554,6 +559,12 @@ pub struct Claim { /// The family (dominance); absent for the whole corpus. #[serde(default, skip_serializing_if = "Option::is_none")] pub family: Option, + /// The kernel theorem that decides a universal claim (its template). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub theorem: Option, + /// The theorem template's parameter. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub parameter: Option, /// The comparator a bound comes from (`xz -9e`). #[serde(default, skip_serializing_if = "Option::is_none")] pub against: Option, @@ -589,6 +600,8 @@ impl Claim { candidate: None, incumbent: None, family: None, + theorem: None, + parameter: None, against: None, bound: None, bytes: None, @@ -620,7 +633,8 @@ impl Claim { /// The κ of a claim's question: SHA-256 of `uorc/claim/1`, the form, and the /// question's fields (codec or candidate and incumbent, corpus, family, the -/// comparator and bound), one `key value` line each. +/// theorem and its parameter, the comparator and bound), one `key value` line +/// each; an absent field (a universal claim's corpus) has no line. pub fn claim_kappa(claim: &Claim) -> String { let mut text = format!("uorc/claim/1\nform {:?}\n", claim.form).to_lowercase(); let mut line = |k: &str, v: Option| { @@ -631,8 +645,13 @@ pub fn claim_kappa(claim: &Claim) -> String { line("codec", claim.codec.clone()); line("candidate", claim.candidate.clone()); line("incumbent", claim.incumbent.clone()); - line("corpus", Some(claim.corpus.clone())); + line( + "corpus", + (!claim.corpus.is_empty()).then(|| claim.corpus.clone()), + ); line("family", claim.family.clone()); + line("theorem", claim.theorem.clone()); + line("parameter", claim.parameter.clone()); line("against", claim.against.clone()); line("bound", claim.bound.map(|b| b.to_string())); sha256_hex(text.as_bytes()) @@ -742,7 +761,16 @@ impl Register { if seen.insert(c.id.clone(), ()).is_some() { return bad(format!("claim {} appears twice", c.id)); } - if self.corpus_by_kappa(&c.corpus).is_none() { + if (c.form == Form::Universal) != c.corpus.is_empty() { + return bad(format!( + "claim {}: exactly the universal claims name no corpus", + c.id + )); + } + if c.form == Form::Universal && c.theorem.is_none() { + return bad(format!("universal claim {} names no theorem", c.id)); + } + if !c.corpus.is_empty() && self.corpus_by_kappa(&c.corpus).is_none() { return bad(format!("claim {} names an unknown corpus", c.id)); } for p in [&c.codec, &c.candidate, &c.incumbent].into_iter().flatten() { @@ -951,6 +979,37 @@ impl Register { q.receipt = Some(by.to_owned()); self.put(q).clone() } + + /// Record `point` as excluded on every corpus by the kernel theorem + /// `theorem` at `parameter` (a universal claim: no corpus, no run). + pub fn exclude_universal( + &mut self, + point: &CodecPoint, + theorem: &str, + parameter: &str, + by: &str, + ) -> Claim { + self.add_point(point, None); + let mut q = Claim::question(Form::Universal, ""); + q.codec = Some(point.kappa()); + q.theorem = Some(theorem.to_owned()); + q.parameter = Some(parameter.to_owned()); + q.status = Status::Proved; + q.receipt = Some(by.to_owned()); + self.put(q).clone() + } + + /// Whether `point` is excluded on `corpus`: by an exclusion on that + /// corpus, or by a universal claim on any. + pub fn excluded(&self, point: &CodecPoint, corpus: &Corpus) -> bool { + let k = point.kappa(); + self.claim.iter().any(|c| { + c.status == Status::Proved + && c.codec.as_deref() == Some(k.as_str()) + && (c.form == Form::Universal + || (c.form == Form::Exclusion && c.corpus == corpus.kappa)) + }) + } } /// Run the codec at `point` over the corpus members `files`: compress each @@ -1120,6 +1179,12 @@ mod tests { assert_eq!(bounds.len(), 1); assert_eq!(bounds[0].status, Status::Proved); reg.check().expect("consistent"); + assert!(!reg.excluded(&v03, &corpus)); + let u = reg.exclude_universal(&v03, "Uorc.Performance.dominated", "0x1ffff", "local"); + assert!(u.corpus.is_empty()); + assert!(reg.excluded(&v03, &corpus)); + let text = reg.to_text().expect("text"); + assert_eq!(Register::parse(&text).expect("parse"), reg); } #[test]