Skip to content

Accuracy: measured per-value tables for HLL and UnivMon, loaded by --measured-accuracy - #1562

Draft
zzylol wants to merge 7 commits into
feat/hll-ingest-execfrom
feat/hll-measured-accuracy
Draft

zzylol wants to merge 7 commits into
feat/hll-ingest-execfrom
feat/hll-measured-accuracy

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

HLL's distinct count, and UnivMon's distinct count and entropy, have no guarantee with a known failure probability, so Pass 2 prunes them under any accuracy target. The certified HLL route was replaced (user decision, 2026-12-03) by measured per-value accuracy: tables measured on the executor's own states (ProjectASAP/ASAPBench#295), loaded with a validating loader and passed to production planning with asap_planner --measured-accuracy / PlanningModels::with_evidence. Example: W1 (count(DISTINCT value) per host over 1 h, rel 0.05 at δ 0.05 per value, 10,000 hosts). Before: all HLL θ pruned and the plan scans raw data. After: Pass 2 keeps HLL p13 (measured worst 0.0426; p12 misses at 0.0507) and its 10 s → 900 s pane chain.

Review guide

  • Base feat/hll-ingest-exec (track 1: the sparse HLL state, sketchlib pin d28d5a6). Track 3's feat(cost,accuracy): price HLL states by their distinct items; a ranking (Limit) keeps its input's error #1556 (cost + ranking) is stacked on the same base. This PR is track 2 of 3.
  • Read first: crates/accuracy/src/measured.rs (from_json), crates/accuracy/src/readout/mod.rs (measured_only_metric), crates/planner/src/models.rs, the --measured-accuracy arm in crates/planner-cli/src/bin/asap_planner.rs.
  • Data: crates/accuracy/measured/hll_distinct.json, univmon.json (generated by ASAPBench#295; not hand-edited).
  • Mechanical: parameter_lists (HLL 12..=18); integration fixtures switched to accuracy_scope: per_value.

Behavior: before → after

asap_planner --workload w1.json --sql-catalog-table '<flows>' --run-until stage1_pass2 \
  --measured-accuracy crates/accuracy/measured/hll_distinct.json

with "requirements": {"accuracy": {"max_error": 0.05, "failure_probability": 0.05, "accuracy_scope": "per_value"}}.

before (no table) after (with table)
SummaryAgg HLL (Pass 2) 7 candidates: 7 pruned, 0 kept (NoGuarantee) 7 candidates: 6 pruned, 1 kept: Hll(precision=13) (p12 below the required accuracy, p14..18 above the reader threshold)
HLL pane chain absent 10 s tumbling + 60/300/900 s levels at p13, ✓ into SummaryEstimate "Cardinality"
UnivMon entropy_over_time, abs 0.1 bits δ 0.05 per value 0 kept kept (e.g. 13,500 × 5 × 56,817 × 19 measured at 0.020 bits)

Interfaces

crates/accuracy/src/measured.rs

 impl MeasuredSketchAccuracy {
+    /// The table in `json` (this type's serde form, e.g. a calibration's output file), validated:
+    /// the loader to call before handing a table to the planner. Err names the parse or check failure.
+    pub fn from_json(json: &str) -> Result<Self, String>;
     pub fn validate(&self) -> Result<(), MeasuredSketchAccuracyError>;
 }

crates/planner/src/models.rs, crates/planner/src/lib.rs

 impl<'a> PlanningModels<'a> {
+    /// These models with the deployment's measured accuracy (e.g. a loaded MeasuredSketchAccuracy).
+    pub fn with_evidence(self, evidence: &'a dyn AccuracyEvidence) -> Self;
 }
+/// Re-exported so callers (CLI, SIL intent callers) can load a table without depending on asap-accuracy.
+pub use asap_accuracy::MeasuredSketchAccuracy;

crates/accuracy/src/readout/mod.rs (crate-private; the behaviour change)

-/// … None for … no guarantee for the statistic (UnivMon's distinct count).
+/// … a listed readout with no theoretical guarantee reads in its statistic's own metric.
 pub(crate) fn readout_error_metric(summary_type: &FieldDataType, statistic: &SketchStatistic) -> Option<AccuracyMetric>;
+/// Cardinality → Relative, FrequencyEntropy → Absolute (bits); any other statistic → None.
+fn measured_only_metric(statistic: &SketchStatistic) -> Option<AccuracyMetric>;

crates/types/src/summary_type/parameter_lists/mod.rs

-const HLL_PARAMETERS: [SketchParams; 4] = [Hll{13}, Hll{15}, Hll{17}, Hll{18}];
+const HLL_PARAMETERS: [SketchParams; 7] = [Hll{12}, Hll{13}, Hll{14}, Hll{15}, Hll{16}, Hll{17}, Hll{18}];

CLI (asap_planner.rs) and file format:

+--measured-accuracy <file>   (repeatable; entries joined, validated; default none = PlanningModels::builtin)
+crates/accuracy/measured/hll_distinct.json   7 entries: Hll{12..18} × Cardinality × relative, trials 1000 (band points; grid points 2000), δ 0.005…0.1
+crates/accuracy/measured/univmon.json        32 entries: 16 UnivMon shapes × {Cardinality relative, FrequencyEntropy absolute}, trials 200, δ 0.02…0.1

Usage (end to end, checked by measured_accuracy_flag_lets_pass2_keep_hll and hll_distinct_ingest::pass2_keeps_least_measured_hll):

// The deployment's measured table, e.g. read by the CLI from --measured-accuracy.
let table = MeasuredSketchAccuracy::from_json(&std::fs::read_to_string(path)?)?;
// Planning models with that evidence; Pass 2 asks it before theoretical_guarantee for each readout edge.
let models = PlanningModels::builtin().with_evidence(&table);
// W1 (per_value rel 0.05, δ 0.05): Pass 2 asks the table for Hll{p} at δ 0.05 and gets
// 0.0507 (p12, misses) … 0.0297 (p18); the least meeting 0.05 (p13) is kept with its pane chain.
let installable = plan_installable(UserInput::new(&workload, FrontendInput::Sql { catalog }, models)).await?;

The SIL intent path is the same: plan_intents(…, models.with_evidence(&table), …).

Algorithm changes

Where a readout's guarantee comes from (Pass 2). Problem: UnivMon entropy / distinct had no readout metric, so a measured entry could never match (measured_guarantee needs the metric). Before: metric = first listed θ's theoretical guarantee's metric, else None, so the readout gets NoGuarantee. After: the same, falling back to the statistic's metric (measured_only_metric). Correctness: without a measured entry, evaluable is still false, so the readout is still pruned (univmon_entropy_pruned_without_a_meeting_entry, hll_has_no_guarantee_without_a_table). A target in another metric is pruned by the metric rule instead of NoGuarantee. Complexity: unchanged. Measurement method and limits: ASAPBench#295.

Review fix (2026-12-04)

The first table (c504f14 / f60c217) came from a 10-per-decade count grid that stepped over HLL's linear-counting → harmonic-mean switch band near 2.4·2^p. It understated the worst error up to 2× (p16 0.0150 → 0.0319) and passed p12. The table now includes the band (ASAPBench#295 87f3ce2): p12 0.0507 misses, so p = 13*.

p 12 13 14 15 16 17 18
worst rel @ δ 0.05 0.0507 0.0426 0.0375 0.0342 0.0319 0.0308 0.0297

Decisions and open questions

  • Decided (2026-12-03, user): measured route; accuracy_scope: per_value, δ 0.05 per value; the paper calls it a measured per-value bound. UnivMon added to scope.
  • Needs reviewer decision — tiny δ and the m/8 exact range. The ranked drill q1 (ORDER BY c DESC LIMIT 10, whole-result target, part D splits δ over 10,000 hosts → 5e-6 per host) cannot be served by measurement: the table records δ ≥ 3/trials = 0.0015. However, HyperLogLogSparse is exact (δ = 0) while a group's union holds ≤ m/8 items (p16: 8,192; p17: 16,384; p18: 32,768), and merged panes stay exact while the union stays ≤ m/8. E6 drill x1: flows 20,000 rows/s over 10,000 hosts gives 7,200 rows per host per hour on average, so ≤ 7,200 distinct per host-hour < 8,192 (p16). q2 / lightcone: auth 10,000 rows/s over 100,000 (host, user) series is about 60 rows per series per 10 min, so a user over 10 hosts has ≤ 600 < 1,024 (p13). So the drill is exact at p16 (q1) and p13 (q2) if the facts bound the per-group distinct count. The planner cannot express that today: max_distinct_per_evaluation is per source (100,000 in E6), and rows/s ÷ groups is an average, not a bound. Needed: a per-group bound fact, e.g. max_distinct_per_group_per_evaluation (or max rows per group per window), which guarantee/hll turns into "exact" when ≤ m/8. Recommendation: add that fact (small PR), or run the drill q1 with per_value scope. Not implemented here.

Verification

scope result newly failing vs base notes
asap-accuracy (all) pass — new: hll_measured_accuracy (6), readout UnivMon metric (1); measured_sketch_accuracy UnivMon test rewritten (decision changed)
asap-types (all) 216 + 95 + 8 pass — hll_list_is_every_precision_12_to_18 now passes
asap-stage1-pass1-… 41 pass —
asap-planner-cli --test planner_cli (incl. sketch snapshots) 77 pass, 2 ignored — new: measured_accuracy_flag_lets_pass2_keep_hll
integration univmon_measured_accuracy 3 pass — new
integration hll_distinct_ingest (this branch alone) 11 pass, 1 fail — (failing on base too) ranked_distinct_keeps_estimates: needs δ 5e-6 (see above); MILP tests pass
integration hll_distinct_ingest, stacked with #1556 (local merge, c42b43a) 11 pass, 1 fail the same ranked_distinct_keeps_estimates only
hll_measured_accuracy 7 pass new: the_switch_band_makes_p13_the_least_precision_for_five_percent
fmt; clippy -D warnings (accuracy, planner, planner-cli, integration-tests, types; all targets) clean

Follow-ups (deferred)

  • A per-group distinct-bound fact plus the m/8 exactness rule (above), for tiny δ.
  • MILP fixtures changed with the measured p* (13): 10 s margin 10× → 1.5× (holds with dense pricing alone and with feat(cost,accuracy): price HLL states by their distinct items; a ranking (Limit) keeps its input's error #1556), and the hourly test now checks the oracle (argmin of a, b, c) instead of "drops the chain".
  • UnivMon: 24 listed shapes above 64 MB, counts above 1e5, and panes above 6 are not measured. HydraUnivMon (and the other Hydra algorithms) have an empty parameter list, so there is nothing to measure.
  • The SIL REQUIRE clause cannot state accuracy_scope yet, so the drill intent uses whole-result targets.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi

zzylol and others added 5 commits December 3, 2026 20:23
Pass 2 keeps the least listed precision that meets the reader's target, so a
full 12..=18 list avoids paying up to 2x state for the gaps of {13,15,17,18}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- MeasuredSketchAccuracy::from_json: the loader (parse + validate).
- HLL's guarantee comes from a measured per-value table instead of the
  removed level-linear-counting certificate: the certificate tests are
  dropped (the classic small-range contract stays) and the properties test
  keeps its HLL filter.
- A readout with no theoretical guarantee (UnivMon's distinct count and
  entropy) reads in its statistic's metric (relative, absolute bits), so a
  measured entry supplies its guarantee; without one it is still pruned.
- crates/accuracy/measured/hll_distinct.json: HLL's measured relative error
  per value at precisions 12..=18 (ASAPBench study_saturation.py --phase
  hll-tail), with tests: the table loads, p14 meets rel 0.05 at delta 0.05
  per value, HLL has no guarantee without a table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Production planning (the asap_planner CLI and any PlanningModels caller,
the SIL intent path included) can read a measured accuracy table; without
one, nothing changes (PlanningModels::builtin has no evidence).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hll_distinct_ingest: W1, W2 and the MILP fixture state per-value targets and
plan with the committed HLL table (W1's p* follows the table); KMV's
unchanged check and the ranked query keep whole-result targets; new: HLL
pruned without a table. univmon_measured_accuracy: UnivMon's entropy kept
with an entry within 0.1 bits at delta 0.05, pruned without one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…table --measured-accuracy

- hll_distinct.json now measures the executor's HyperLogLogSparse
  (asap_sketchlib d28d5a6): 2,000 trials per point, counts 1..1e6, 1-360
  merged panes; worst rel error at delta 0.05: p12 0.0477 ... p18 0.0126.
- univmon.json: UnivMon's distinct count (relative) and entropy (absolute
  bits) for the 16 listed shapes up to 64 MB a state, counts 1..1e5.
- --measured-accuracy is repeatable; the files' entries are joined.
- Tests: the UnivMon table loads and gives entropy a guarantee; Pass 2
  keeps UnivMon's entropy with the committed table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol zzylol added enhancement New feature or request accuracy Accuracy requirements, guarantees, and propagation labels Dec 3, 2026
zzylol and others added 2 commits December 3, 2026 23:08
With HLL's measured table the fixture's p* is 12, not the certificate's 17,
so the chain is cheaper than planned: on the stack with the sparse HLL
pricing (#1556) it wins by 3.8x every 10 s (a 7,093, b 462, c 123) and still
wins hourly (2.36 vs 26.9 / 8.5). The margin becomes 2x, and the hourly test
checks the oracle itself: the MILP picks the cheapest of (a), (b), (c) and
keeps the chain exactly when (c) is cheapest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASAPBench#295 now measures the counts near 2.4 * 2^p where HLL's estimator
switches from linear counting to the harmonic mean; the 10-per-decade grid
had stepped over that spike. New worst rel error at delta 0.05 per value:
p12 0.0507 (misses 0.05), p13 0.0426, ... p18 0.0297 (1,000 trials at the
band points). W1's p* becomes 13; a test pins that p12 misses and p13..18
meet rel 0.05. The 10 s MILP test's margin is 1.5x, so it holds with dense
pricing (this branch alone) and with the sparse pricing of #1556.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accuracy Accuracy requirements, guarantees, and propagation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant