diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6fd6972..8d4aa830 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 7e19ea8b..2221f2f6 100644 --- a/CONFORMANCE.md +++ b/CONFORMANCE.md @@ -126,7 +126,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 @@ -154,7 +154,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/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/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/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..2e0d4e4a --- /dev/null +++ b/crates/frontier/src/lib.rs @@ -0,0 +1,1275 @@ +//! 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}; + +/// 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] = ["tiny", "small", "x86", "text", "other"]; + +/// Bytes of one strategy entry: the u32 little-endian word (bits 0-19 the +/// ncm profile, bit 31 the x86 filter), then a state byte (0: none). +pub const ENTRY: usize = 5; + +/// The x86 bit of an entry's word. +pub const X86_BIT: u32 = 1 << 31; + +/// The [`ENTRY`] bytes of a strategy. +pub fn entry(s: Strategy) -> [u8; ENTRY] { + let w = (s.profile | if s.x86 { X86_BIT } else { 0 }).to_le_bytes(); + [w[0], w[1], w[2], w[3], 0] +} + +/// The strategy an entry names, when the coder can apply it: a valid +/// profile word, no other word bits, and no state. +pub fn strategy_of(e: &[u8]) -> Option { + let e: &[u8; ENTRY] = e.try_into().ok()?; + let word = u32::from_le_bytes([e[0], e[1], e[2], e[3]]); + let profile = word & !X86_BIT; + (uorc::ncm::valid_profile(profile) && e[4] == 0).then_some(Strategy { + x86: word & X86_BIT != 0, + profile, + }) +} + +/// The strategy coordinate of a codec point: a portfolio table (strategy +/// entries and one weight per family and entry, the byte form the engine +/// consolidates), or one fixed strategy (coded exactly as the shipped +/// encoder codes that strategy, learned context mask included). +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum Plan { + /// A portfolio: [`ENTRY`] bytes per strategy, and `FAMILIES * count` + /// weights, row by family. + 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::STRATEGIES`] under + /// [`portfolio::WEIGHTS`]). + pub fn shipped() -> Plan { + Plan::Portfolio { + strategies: portfolio::STRATEGIES + .iter() + .flat_map(|&s| entry(s)) + .collect(), + weights: portfolio::WEIGHTS.iter().flatten().copied().collect(), + } + } + + /// The strategies this plan codes for `frame`, in order: a portfolio's + /// first [`portfolio::BUDGET`] entries by the frame family's weights + /// (highest first, ties in table order), or the fixed strategy. + pub fn strategies(&self, frame: &[u8]) -> Vec> { + match self { + Plan::Fixed(s) => vec![Some(*s)], + Plan::Portfolio { + strategies, + weights, + } => { + let count = strategies.len() / ENTRY; + let family = portfolio::family(frame); + let weight = |i: usize| weights.get(family * count + i).copied().unwrap_or(0); + let mut order: Vec = (0..count).collect(); + order.sort_by_key(|&i| std::cmp::Reverse(weight(i))); + order + .into_iter() + .take(portfolio::BUDGET) + .map(|i| strategy_of(&strategies[i * ENTRY..(i + 1) * ENTRY])) + .collect() + } + } + } + + /// The stream of `input` under this plan: framed exactly as the shipped + /// encoder frames it (repeats, windows), each coded frame coded by + /// [`uorc::compress_with_strategies`], frames on up to `threads` cores. + pub fn compress(&self, input: &[u8], threads: usize) -> Vec { + let mut encoder = uorc::FrameEncoder::new(); + let mut planned = encoder.plan(input); + planned.extend(encoder.plan_end()); + let code = |p: &uorc::Planned| match p { + uorc::Planned::Done { archive, .. } => archive.clone(), + uorc::Planned::Code { + bytes, + pieces, + window, + } => { + let window: Vec<&[u8]> = window.iter().map(Vec::as_slice).collect(); + uorc::compress_with_strategies(bytes, pieces, &window, &self.strategies(bytes)) + } + }; + let mut out = Vec::new(); + for chunk in planned.chunks(threads.max(1)) { + let archives: Vec> = std::thread::scope(|s| { + let handles: Vec<_> = chunk.iter().map(|p| s.spawn(move || code(p))).collect(); + handles + .into_iter() + .map(|h| h.join().expect("frame thread")) + .collect() + }); + for a in archives { + out.extend_from_slice(&a); + } + } + out + } +} + +/// 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() / 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(entry(*s)); + } + } + 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 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. +#[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 κ; 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")] + 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 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, + /// 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, + theorem: None, + parameter: 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 +/// 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| { + 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", + (!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()) +} + +/// 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 (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() { + 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() + } + + /// 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 +/// 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 stream = point.plan.compress(input, threads); + 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"); + 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] + 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/crates/uorc/src/lib.rs b/crates/uorc/src/lib.rs index 21dae631..41834b98 100644 --- a/crates/uorc/src/lib.rs +++ b/crates/uorc/src/lib.rs @@ -242,6 +242,31 @@ pub fn compress_strategy( ) } +/// The archive a frame gets when the encoder codes `strategies` (in +/// order, at most [`portfolio::BUDGET`]) instead of the ones +/// [`portfolio::plan`] schedules: the first learns its context mask, each is +/// bounded by the raw archive, and [`choose`] keeps the result. With +/// `portfolio::plan(frame)` it is the archive [`compress_frame_with`] writes +/// (with `steps == 0`); with other strategies it is the frame at another +/// point of the codec space (the claim decider, `crates/frontier`). `None` +/// entries (a strategy the coder cannot apply) yield no candidate. +pub fn compress_with_strategies( + frame: &[u8], + lengths: &[u64], + window: &[&[u8]], + strategies: &[Option], +) -> Vec { + let raw = archive::raw_length(lengths); + let mut coded = strategies + .iter() + .take(portfolio::BUDGET) + .enumerate() + .map(|(k, s)| s.and_then(|s| code_strategy(frame, lengths, window, s, k == 0, raw))); + let first = coded.next().flatten(); + let second = coded.next().flatten(); + choose(frame, lengths, first, second) +} + /// The frame's archive from its two strategies' archives (see /// [`compress_strategy`]): the second only when strictly shorter than the /// first, then the raw archive unless the kept one is strictly shorter. diff --git a/factory/README.md b/factory/README.md index 51e587a9..b35f1434 100644 --- a/factory/README.md +++ b/factory/README.md @@ -25,6 +25,7 @@ that orders remaining work. Here the decisions are a small Node host | `gate` | gate | the identities of the seven bootstrap legs and `pages` | proved when all eight 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 898aa4d1..d66d43a4 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/", "web/index.html", "!vendor/hologram-brand/", "!scripts/site.", "!scripts/page-acceptance.mjs", "!.github/workflows/pages-client.yml", "!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/", "web/index.html", "!vendor/hologram-brand/", "!scripts/site.", "!scripts/page-acceptance.mjs", "!.github/workflows/pages-client.yml", "!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/page-acceptance.mjs", "!scripts/bench.mjs", "!scripts/client-export.mjs"], "client": ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", ".cargo/", "crates/uorc/", "generated/rust/", ".github/workflows/release.yml"] }, @@ -23,6 +23,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 new file mode 100644 index 00000000..a0dbe86d --- /dev/null +++ b/frontier.toml @@ -0,0 +1,393 @@ +# 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 + +[[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" +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)" + +[[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 = "a0d04f0b8e76041db0cdc6190d4886fc375a8eb8c81a0243d5b0d8a26ed81771" +label = "v0.5 shipped client" +export = "a99d6a37a045dfd7b6fa135549a2798a009e8a3b3577124a5ac14ea9788122b3" +plan = "portfolio" +strategies = "ffff0f0000ffff0f8000ffff070000ffff078000ffff010000ffff018000" +weights = "01010101100101010e0110010401010f01010a010a0104010c010c010101" +lanes = 1 + +[[claim]] +id = "675e5a8ac1c9dc722ac29ed58c5df1b56f9bc18f1af0e26f861f8e0b16d74ffa" +form = "closed" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "a0d04f0b8e76041db0cdc6190d4886fc375a8eb8c81a0243d5b0d8a26ed81771" +bytes = 577506 +steps = 214329464 + +[[claim.members]] +name = "crates/uorc/Cargo.toml" +family = "tiny" +bytes = 347 +steps = 101440 + +[[claim.members]] +name = "crates/uorc/tests/kernel-empty-padded.uorc" +family = "tiny" +bytes = 1247 +steps = 424640 + +[[claim.members]] +name = "Justfile" +family = "small" +bytes = 1676 +steps = 370400 + +[[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 = 312021 +steps = 31284192 + +[[claim]] +id = "e844bd77106b58d7984b323dc145b009a39e66be1b46c998be5b148dbead63b5" +form = "bound" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "a0d04f0b8e76041db0cdc6190d4886fc375a8eb8c81a0243d5b0d8a26ed81771" +against = "gzip -9" +bound = 650271 + +[[claim]] +id = "36a574c89ddb88570cdc5a6f42b79d5f28f1fdf03ec7e3ff1bcea47ccfe47b60" +form = "bound" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "a0d04f0b8e76041db0cdc6190d4886fc375a8eb8c81a0243d5b0d8a26ed81771" +against = "bzip2 -9" +bound = 606478 + +[[claim]] +id = "5f54c8652f087a4d4bbfe66844905273e1ecd5e4cdb222f925034766ea627bfe" +form = "bound" +status = "proved" +receipt = "local" +corpus = "9b781bfc9840425743140cf728a8fbdd2f9f35253eef45371ad328e43662bffd" +codec = "a0d04f0b8e76041db0cdc6190d4886fc375a8eb8c81a0243d5b0d8a26ed81771" +against = "xz -9e" +bound = 595432 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 0201e018..b53eb2ff 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 30df847c..1ee56df9 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 93e27a53..8173dc0d 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{