Repository navigation
feat(bench): scaffold ourios-bench crate (PR-H1 of RFC 0006) #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
15fe1ef
feat(bench): scaffold ourios-bench crate (PR-H1 of RFC 0006)
jensholdgaard 4b3dfde
fixup! feat(bench): scaffold ourios-bench crate (PR-H1 of RFC 0006)
jensholdgaard dc81044
fixup! feat(bench): scaffold ourios-bench crate (PR-H1 of RFC 0006)
jensholdgaard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| [package] | ||
| name = "ourios-bench" | ||
| version = "0.0.0" | ||
| description = "RFC 0006 thesis-gate bench harness (A1 / C1 / C2). Drives ourios-miner + ourios-parquet against a corpus and computes the writer-side thesis-gate numbers." | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| publish = false | ||
|
|
||
| [[bin]] | ||
| name = "ourios-bench" | ||
| path = "src/main.rs" | ||
|
|
||
| [lib] | ||
| name = "ourios_bench" | ||
| path = "src/lib.rs" | ||
|
|
||
| [dependencies] | ||
| # Workspace crates the harness drives end-to-end. The bench is | ||
| # the only consumer that pulls all three on the same dep line | ||
| # (miner + parquet writer + the core OtlpLogRecord shape they | ||
| # share). | ||
| ourios-core = { path = "../ourios-core" } | ||
| ourios-miner = { path = "../ourios-miner" } | ||
| ourios-parquet = { path = "../ourios-parquet" } | ||
| # Serde + serde_json for the §3.6 ResultsFile JSON contract. | ||
| # `derive` gives the struct→JSON path; `std` covers the rest. | ||
| serde = { version = "1", default-features = false, features = ["derive", "std"] } | ||
| serde_json = { version = "1", default-features = false, features = ["std"] } | ||
|
|
||
| [dev-dependencies] | ||
| # `tempfile` is the standard scratch-directory helper the other | ||
| # integration tests in this workspace use (see ourios-parquet's | ||
| # dev-dependencies). The bench's red-gate test stubs will need | ||
| # it once they run real flows. | ||
| tempfile = "3" | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| //! `ourios-bench` — RFC 0006 thesis-gate bench harness | ||
| //! (A1 compression, C1 reconstruction, C2 template-count | ||
| //! convergence). | ||
| //! | ||
| //! This file is the **Red-stage scaffold** for the RFC. The | ||
| //! public surface declared here is what the RFC0006.1–7 | ||
| //! acceptance-criterion tests will exercise once they land in | ||
| //! a follow-up PR; today every entry point returns | ||
| //! [`BenchError::NotImplemented`] so the crate compiles, the | ||
| //! test stubs link, and the maturity-model gate (`specified` | ||
| //! → `red`: stubs exist and fail) is satisfied without | ||
| //! pre-committing to an implementation shape the tests would | ||
| //! then have to fight. | ||
| //! | ||
| //! Per RFC 0006 §3.2 the eventual module layout is `corpus`, | ||
| //! `harness`, `a1`, `c1`, `c2`, `report`. Those modules land | ||
| //! incrementally; this scaffold keeps them collapsed into | ||
| //! `lib.rs` so the first scaffold PR stays under CLAUDE.md | ||
| //! §5.2's "≤ 5 files per phase" rule. The first per-module | ||
| //! split is what flips the maturity gate from `red` → `green`. | ||
|
|
||
| #![deny(unsafe_code)] | ||
|
|
||
| use std::fmt; | ||
| use std::path::PathBuf; | ||
|
|
||
| /// Configuration for one bench invocation. | ||
| /// | ||
| /// Built from the CLI in `main.rs`; passed to [`run`] either | ||
| /// directly (from `main`) or by integration tests under | ||
| /// `tests/`. Field order tracks the §3.7 flag list. | ||
| #[derive(Debug, Clone)] | ||
| pub struct BenchConfig { | ||
| /// Directory of `*.txt` corpus files (RFC 0006 §3.3). | ||
| pub corpus_dir: PathBuf, | ||
| /// Directory the §3.6 results JSON lands in. | ||
| pub results_dir: PathBuf, | ||
| /// Parquet writer's `bucket_root`. `None` means | ||
| /// "create a fresh temp dir and clean it up on exit". | ||
| pub bucket_dir: Option<PathBuf>, | ||
| /// If `true`, the temp bucket dir survives the run (debug | ||
| /// inspection); otherwise it's removed in [`run`]'s cleanup | ||
| /// path. | ||
| pub keep_parquet: bool, | ||
| /// §3.5 hardware-kind annotation. `None` means | ||
| /// `--allow-unknown-hardware` was passed. | ||
| pub hardware_kind: Option<String>, | ||
| /// Append / rewrite the §9 sub-heading in | ||
| /// `docs/benchmarks.md`. Off by default; CI runs without | ||
| /// it, maintainers opt in to commit numbers. | ||
| pub update_benchmarks_md: bool, | ||
| /// Which gates to compute. Empty set is rejected by CLI | ||
| /// parsing. | ||
| pub gates: GateSet, | ||
| } | ||
|
|
||
| /// Subset of {A1, C1, C2} selected via `--gates`. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct GateSet { | ||
| pub a1: bool, | ||
| pub c1: bool, | ||
| pub c2: bool, | ||
| } | ||
|
|
||
| impl GateSet { | ||
| /// All three gates enabled — the default when `--gates` is | ||
| /// omitted. | ||
| #[must_use] | ||
| pub const fn all() -> Self { | ||
| Self { | ||
| a1: true, | ||
| c1: true, | ||
| c2: true, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Top-level entry point. Loads the corpus, drives the miner | ||
| /// and writer pipeline, computes the §3.4 measurements for | ||
| /// every enabled gate, writes the §3.6 results JSON, and | ||
| /// optionally rewrites the `docs/benchmarks.md` §9 sub-heading | ||
| /// per `config.update_benchmarks_md`. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`BenchError`] for any failure along the path. The | ||
| /// scaffold stage returns [`BenchError::NotImplemented`] from | ||
| /// every entry point — the Red-gate tests in | ||
| /// `tests/{a1,c1,c2,reproducibility}.rs` are `#[ignore]`'d | ||
| /// against this exact error. | ||
| pub fn run(_config: &BenchConfig) -> Result<ResultsFile, BenchError> { | ||
| Err(BenchError::NotImplemented { | ||
| what: "BenchConfig::run is RFC 0006 Red-gate scaffold — no measurement code yet", | ||
|
jensholdgaard marked this conversation as resolved.
Resolved
|
||
| }) | ||
| } | ||
|
|
||
| /// §3.6 JSON results file. Field order mirrors the RFC. | ||
| /// | ||
| /// The struct is `serde::Serialize` + `serde::Deserialize` so | ||
| /// downstream analysis tooling can parse it without re-reading | ||
| /// the RFC; `rfc_version = "v1"` is the stability tag and | ||
| /// bumping it requires an amendment. | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct ResultsFile { | ||
| /// Always `"RFC 0006"`. | ||
| pub rfc: String, | ||
| /// Pinned by §3.6 to `"v1"` until the RFC is amended. | ||
| pub rfc_version: String, | ||
| /// RFC3339 with millisecond precision (§3.6 collision-avoidance rule). | ||
| pub timestamp: String, | ||
| /// Seven-character abbreviated git SHA at run time. | ||
| pub git_sha: String, | ||
| /// §3.5 hardware-kind annotation. `"unknown"` is allowed | ||
| /// only when `--allow-unknown-hardware` was passed. | ||
| pub hardware_kind: String, | ||
| pub corpus: CorpusStats, | ||
| pub ourios: OuriosStats, | ||
| pub zstd: ZstdStats, | ||
| /// `null` when A1 was skipped via `--gates` (§3.6 nullability rule). | ||
| pub a1: Option<A1Result>, | ||
| /// `null` when C1 was skipped via `--gates`. | ||
| pub c1: Option<C1Result>, | ||
| /// `null` when C2 was skipped via `--gates`, or when the | ||
| /// corpus is `< 1 M lines` (§3.4.3 abstention). | ||
| pub c2: Option<C2Result>, | ||
| } | ||
|
|
||
| /// §3.6 `corpus` block. | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct CorpusStats { | ||
| pub directory: String, | ||
| pub total_lines: u64, | ||
| pub total_files: u32, | ||
| pub raw_bytes: u64, | ||
| } | ||
|
|
||
| /// §3.6 `ourios` block. `total = data + audit`; A1 operates on | ||
| /// the total per §3.4.1. | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct OuriosStats { | ||
| pub data_parquet_bytes: u64, | ||
| pub audit_parquet_bytes: u64, | ||
| pub total_parquet_bytes: u64, | ||
| } | ||
|
|
||
| /// §3.6 `zstd` block. `level` is pinned to 19 by §3.4.1. | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct ZstdStats { | ||
| pub level: u8, | ||
| pub compressed_bytes: u64, | ||
| } | ||
|
|
||
| /// §3.6 `a1` block (populated only when A1 ran). | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct A1Result { | ||
| pub ourios_ratio: f64, | ||
| pub zstd_ratio: f64, | ||
| pub delta: f64, | ||
| pub target_delta: f64, | ||
| pub pass: bool, | ||
| } | ||
|
|
||
| /// §3.6 `c1` block (populated only when C1 ran). | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct C1Result { | ||
| pub non_lossy_total: u64, | ||
| pub non_lossy_reconstruct_ok: u64, | ||
| pub rate: f64, | ||
| pub lossy_flag_ratio: f64, | ||
| pub pass: bool, | ||
| } | ||
|
|
||
| /// §3.6 `c2` block (populated only when C2 ran). `pass` is | ||
| /// `None` when the corpus is `< 1 M lines` (§3.4.3 abstention). | ||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct C2Result { | ||
| pub sample_cadence: u64, | ||
| pub total_lines: u64, | ||
| pub template_count_at_1m_lines: Option<u64>, | ||
| pub template_count_at_end: u64, | ||
| pub convergence_ratio: Option<f64>, | ||
| pub convergence_curve: Vec<ConvergenceSample>, | ||
| pub pass: Option<bool>, | ||
| pub corpus_at_least_1m: bool, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub struct ConvergenceSample { | ||
| pub lines: u64, | ||
| pub template_count: u64, | ||
| } | ||
|
|
||
| /// Errors produced by [`run`] and the §3.4 measurement helpers. | ||
| /// | ||
| /// The Red-gate scaffold only ever returns | ||
| /// [`Self::NotImplemented`]; the other variants are the wire | ||
| /// shapes the eventual implementation will use, declared now so | ||
| /// downstream test code doesn't have to refactor when they start | ||
| /// firing. | ||
| #[derive(Debug)] | ||
| pub enum BenchError { | ||
| /// Red-gate placeholder. | ||
| NotImplemented { what: &'static str }, | ||
| /// A required CLI argument was missing or malformed. | ||
| Cli { detail: String }, | ||
| /// Corpus directory missing / empty / non-readable. | ||
|
jensholdgaard marked this conversation as resolved.
Resolved
|
||
| Corpus { detail: String }, | ||
| /// Miner / writer / reader returned an error during ingest. | ||
| Pipeline { detail: String }, | ||
| /// JSON serialisation, file write, or `benchmarks.md` | ||
| /// rewrite failed. | ||
| Report { detail: String }, | ||
| } | ||
|
|
||
| impl fmt::Display for BenchError { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| Self::NotImplemented { what } => write!(f, "RFC 0006 Red-gate scaffold: {what}"), | ||
| Self::Cli { detail } => write!(f, "CLI: {detail}"), | ||
| Self::Corpus { detail } => write!(f, "corpus: {detail}"), | ||
| Self::Pipeline { detail } => write!(f, "pipeline: {detail}"), | ||
| Self::Report { detail } => write!(f, "report: {detail}"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for BenchError {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //! `ourios-bench` binary entry point. | ||
| //! | ||
| //! Thin wrapper that parses CLI arguments into a | ||
| //! [`ourios_bench::BenchConfig`] and calls | ||
| //! [`ourios_bench::run`]. The CLI surface is pinned by | ||
| //! RFC 0006 §3.7; this file is the Red-gate scaffold and the | ||
| //! argument parser is still a stub. | ||
|
jensholdgaard marked this conversation as resolved.
Resolved
|
||
|
|
||
| use std::process::ExitCode; | ||
|
|
||
| fn main() -> ExitCode { | ||
| eprintln!( | ||
| "ourios-bench: RFC 0006 Red-gate scaffold — argument parser and harness are \ | ||
| not implemented yet. Track progress on the maturity-model bump in \ | ||
| `docs/rfcs/0006-bench-harness.md` §7.", | ||
| ); | ||
| // Exit non-zero so a `just thesis-bench` invocation in the | ||
| // scaffold window can't be mistaken for a successful | ||
| // benchmark run. | ||
| ExitCode::from(2) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.