Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions crates/asap-aware-mapping/src/accuracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ pub struct PropagationStats {
/// of groups a `sum` folds), for `ExactSum`/`ExactExtremum`'s union
/// bound over per-input failures.
pub input_row_count: Option<u64>,
/// Fresh key-frequency distribution evidence from the data workload.
/// Built-in rules preserve it for deployment-specific accuracy models;
/// they do not assume a favorable distribution when it is absent.
pub data_distribution: Option<asap_types::workload::DataDistribution>,
/// Lower confidence bound of the kth selected TopK item, after widening
/// the interval by the sketch's own estimation error.
pub topk_selected_lower_bound: Option<f64>,
Expand Down Expand Up @@ -120,6 +124,29 @@ pub struct NoAccuracyEvidence;

impl AccuracyEvidenceProvider for NoAccuracyEvidence {}

/// Accuracy evidence backed by the normalized data workload. Freshness is
/// checked at the planning time before values reach any accuracy rule.
#[derive(Debug, Clone, Copy)]
pub struct WorkloadAccuracyEvidence<'a> {
pub data: &'a asap_types::workload::DataWorkload,
pub now_ms: u64,
}

impl AccuracyEvidenceProvider for WorkloadAccuracyEvidence<'_> {
fn propagation_stats(
&self,
_op: &CompositionOperator,
_family: &SummaryFamilyType,
_query: Option<&SketchQuery>,
) -> PropagationStats {
PropagationStats {
input_row_count: self.data.input_cardinality.value_at(self.now_ms).copied(),
data_distribution: self.data.distribution.value_at(self.now_ms).cloned(),
..PropagationStats::default()
}
}
}

/// The deployment-extensible accuracy algebra. `asap-aware-mapping` ships
/// [`DefaultAccuracyModel`]; a deployment with a proof for a composition the
/// default rejects (a registered cross-metric conversion, say) implements
Expand Down Expand Up @@ -839,6 +866,7 @@ impl AccuracyBudgetAllocator for EqualSplitAllocator {
mod tests {
use super::*;
use asap_types::post_asap::{GroupingStrategy, SketchKind};
use asap_types::workload::{DataDistribution, DataWorkload, Evidence, EvidenceSource};

fn abs(bound: f64, delta: f64) -> ResultGuarantee {
ResultGuarantee {
Expand All @@ -865,6 +893,54 @@ mod tests {
}
}

#[test]
fn workload_accuracy_evidence_uses_only_fresh_data_characteristics() {
let data = DataWorkload {
input_cardinality: Evidence {
value: Some(42),
source: EvidenceSource::Observed,
observed_at_ms: Some(1_000),
valid_for_ms: Some(500),
},
distribution: Evidence {
value: Some(DataDistribution::Bursty),
source: EvidenceSource::Observed,
observed_at_ms: Some(1_000),
valid_for_ms: Some(500),
},
..Default::default()
};
let provider = WorkloadAccuracyEvidence {
data: &data,
now_ms: 1_500,
};
let fresh = provider.propagation_stats(
&CompositionOperator::ExactSum,
&SummaryFamilyType::ExactAggregate(
asap_types::post_asap::ExactKind::Sum,
asap_types::post_asap::ExactParams::Sum,
),
None,
);
assert_eq!(fresh.input_row_count, Some(42));
assert_eq!(fresh.data_distribution, Some(DataDistribution::Bursty));

let stale = WorkloadAccuracyEvidence {
data: &data,
now_ms: 1_501,
}
.propagation_stats(
&CompositionOperator::ExactSum,
&SummaryFamilyType::ExactAggregate(
asap_types::post_asap::ExactKind::Sum,
asap_types::post_asap::ExactParams::Sum,
),
None,
);
assert_eq!(stale.input_row_count, None);
assert_eq!(stale.data_distribution, None);
}

#[test]
fn exact_child_contributes_zero_error() {
let local = abs(0.05, 0.01);
Expand Down
18 changes: 16 additions & 2 deletions crates/asap-aware-mapping/src/recurrence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
//!
//! ## Provenance of each new cost input
//!
//! - [`EvaluationRate`]: derived from [`asap_types::workload::RepeatingEntry::interval`]
//! - [`EvaluationRate`]: derived from [`asap_types::workload::RepeatingEntry::demand`]
//! values of every repeating consumer reaching a target (via
//! [`evaluation_rate_of`], or [`crate::replacement::PlanSpace::recurrence_profiles`]
//! for a whole workload). A one-shot ([`asap_types::workload::BatchEntry`])
Expand Down Expand Up @@ -200,6 +200,12 @@ pub enum RecurrenceError {
well-defined maintained_cost_rate"
)]
InvalidUpdateRate(UpdateRate),
#[error("invalid EvaluationRate({0:?}Hz): an evaluation rate must be finite and >= 0")]
InvalidEvaluationRate(EvaluationRate),
#[error(transparent)]
InvalidWorkload(#[from] asap_types::workload::WorkloadError),
#[error("workload entry index {index} is out of bounds for {entry_count} entries")]
InvalidWorkloadEntry { index: usize, entry_count: usize },
/// A [`Horizon`] that isn't finite and strictly positive (NaN,
/// infinite, zero, or negative) was supplied — a non-positive or
/// infinite horizon would silently drop or invert the recurring
Expand Down Expand Up @@ -374,16 +380,24 @@ impl RecurrenceProfile {
/// already-opaque `Id` granularity `search_workload`'s callers already use
/// — this crate needs no more of a caller's own query identity than "which
/// of these two recurrence kinds is this root".
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RootRecurrence {
/// A one-shot (batch) root — contributes to a reached target's
/// [`RecurrenceProfile::one_shot_consumers`], never to its
/// `evaluation_rate`.
OneShot,
/// A declared number of one-time invocations for this root.
OneShotCount(usize),
/// A repeating root firing every `RepetitionInterval` — contributes to
/// a reached target's `evaluation_rate` (`1 / interval`, aggregated via
/// [`evaluation_rate_of`]).
Repeating(RepetitionInterval),
/// A repeated root whose schedule or estimate has already been
/// normalized to evaluations per second.
RepeatingRate(EvaluationRate),
/// No reliable recurrence evidence was supplied. It contributes no read
/// count or evaluation rate, but remains distinct from zero demand.
Unknown,
}

// ── Explanation ──────────────────────────────────────────────────────────
Expand Down
Loading