Skip to content

feat(plan): add a CostModel interface for deployment-specific sketch ranking - #138

Merged
zzylol merged 2 commits into
mainfrom
feat/plan-cost-model-interface
Jul 20, 2026
Merged

zzylol merged 2 commits into
mainfrom
feat/plan-cost-model-interface

Conversation

@zzylol

@zzylol zzylol commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • asap-plan deliberately has no cost model implementation of its own (it depends only on asap-ir, never on a runtime or deployment model) -- but until now it also had no interface for one: boundary::bind_summary_with (formerly bind_sketch) picked the static-order head unconditionally, and cost_model.rs was a 7-line stub with no callers (TODO(#6)/TODO(#33)).
  • Adds a CostModel trait (rank_candidates(intent, candidates) -> Vec<SummaryKind>, best first) plus DefaultCostModel, which preserves the existing static candidate order exactly.
  • boundary::realize_with and bind::bind_with/bind_in_with thread a &dyn CostModel through to summary selection. The existing realize/bind/bind_in entry points are unchanged -- thin wrappers over the _with variants using DefaultCostModel -- so this is purely additive, no behavioral change for any existing caller.
  • Gives each downstream deployment (ASAPCollector + ASAPQuery-backend, ASAPFusion, ...) one place to plug in real cost-based summary selection (bandwidth budget, memory footprint, site count, observed drift, ...) instead of forking bind_summary_with.
  • Renamed sketch_candidates/bind_sketch_with to summary_candidates/bind_summary_with (second commit): SummaryKind already spans exact accumulators alongside approximate sketches, and non-sketch summary realizations (sampling-based, wavelet-transform, OMP/compressive-sensing) are expected to land as SummaryKind variants over time -- naming the new interface around "sketch" would've introduced a second, narrower vocabulary for the same concept SummaryKind/SummaryParams/SummaryExpr already name "summary".

Test plan

  • cargo build --workspace -- clean
  • cargo test --workspace -- all green, no regressions
  • cargo clippy -p asap-plan --all-targets -- clean
  • cargo fmt -p asap-plan applied
  • New test bind_with_custom_cost_model_overrides_default_summary_choice proves a custom CostModel actually changes the bound summary (KLL -> DDSketch for the same query), not just that the parameter type-checks

🤖 Generated with Claude Code

zzylol and others added 2 commits July 19, 2026 13:56
…ranking

asap-plan intentionally has no cost model implementation of its own --
ranking candidate sketches by real cost (bandwidth budget, memory
footprint, site count, observed drift, ...) needs deployment knowledge
this crate deliberately doesn't have (it depends only on asap-ir, never
on a runtime or deployment model). Until now that meant no extension
point at all: boundary::bind_sketch took sketch_candidates(intent)
unconditionally by static-list order (.first()), and cost_model.rs was
a 7-line stub with no callers.

Add the CostModel trait (rank_candidates) plus DefaultCostModel, which
preserves the existing static order exactly. boundary::realize_with and
bind::bind_with/bind_in_with thread a &dyn CostModel through to
bind_sketch's candidate selection; the existing realize/bind/bind_in
entry points are unchanged (thin wrappers over the _with variants using
DefaultCostModel), so this is purely additive -- no behavioral change
for any existing caller.

This gives each downstream deployment (ASAPCollector + ASAPQuery-backend,
ASAPFusion, ...) one place to plug in its own cost-based sketch
selection instead of forking bind_sketch.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… naming

sketch_candidates/bind_sketch_with predate this PR's CostModel interface,
but the "sketch" in their names is narrower than what CostModel::
rank_candidates is meant to cover: SummaryKind already spans exact
accumulators alongside approximate sketches, and non-sketch summary
realizations (sampling-based, wavelet-transform, OMP/compressive-sensing)
are expected to land as SummaryKind variants over time. Renaming to
summary_candidates/bind_summary_with matches the established SummaryKind/
SummaryParams/SummaryExpr convention instead of introducing a competing
"sketch" vocabulary for the same concept. Doc comments and one test name
updated to match; no behavioral change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zzylol
zzylol merged commit e9ff765 into main Jul 20, 2026
2 of 3 checks passed
@zzylol
zzylol deleted the feat/plan-cost-model-interface branch July 20, 2026 01:53
zzylol added a commit to ProjectASAP/ASAPQuery-backend that referenced this pull request Jul 20, 2026
…nterface)

Picks up ProjectASAP/ASAPPlanner#138: asap-plan's new CostModel trait
(deployment-pluggable summary ranking) plus the sketch_candidates/
bind_sketch_with -> summary_candidates/bind_summary_with rename. No
source changes needed here -- asap-ir/asap-l2 (what control_plane
actually depends on) are unaffected by that PR; control_plane doesn't
depend on asap-plan. cargo build/test -p control_plane clean (768
passed, 1 known pre-existing unrelated failure).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
zzylol added a commit to ProjectASAP/ASAPQuery-backend that referenced this pull request Jul 20, 2026
…ary::implementation_for

Bumps the ASAPController pin to 12b3054 (ProjectASAP/ASAPPlanner#138-140:
CostModel interface, realize/Realization -> implementation_for/Implementation
Cascades-terminology rename, CountSketch/CountSketchWithHeap SummaryKind
variants, Implementation::is_satisfied_by) and adds asap-plan/asap-sketch as
new git dependencies (same repo/rev as asap-ir/asap-l2; asap-plan depends
only on asap-ir, so this pulls in no datafusion/front-end weight).

capability_for no longer maintains its own hand-written AggIntent -> ASAP-tier
capability match -- that was a second, parallel judgment kept in sync with
asap-plan's own implementation_for by hand (and had already drifted twice:
the Count/Min-Max divergences fixed in a prior commit). It now keeps only
the Extension/Frequency special case (deployment-specific -- asap-plan has
no opinion on an intent shape it can't see into, by design) and delegates
everything else to asap_plan::boundary::implementation_for, translating the
returned Implementation into this repo's coarser Capability vocabulary via
the new implementation_to_capability helper. One deliberate override
survives the delegation: Count{Exact} is forced to None (archive) rather
than trusting implementation_for's ExactAccumulator claim, because the data
plane has no working count accumulator (SumAccumulator conflates Sum and
Count).

All 772 existing tests pass unchanged -- confirms the delegation is
behaviorally identical to the hand-written match it replaces, including the
Min/Max and Count fixes from the prior commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
zzylol added a commit to ProjectASAP/ASAPQuery-backend that referenced this pull request Jul 21, 2026
…ary::implementation_for

Bumps the ASAPController pin to 12b3054 (ProjectASAP/ASAPPlanner#138-140:
CostModel interface, realize/Realization -> implementation_for/Implementation
Cascades-terminology rename, CountSketch/CountSketchWithHeap SummaryKind
variants, Implementation::is_satisfied_by) and adds asap-plan/asap-sketch as
new git dependencies (same repo/rev as asap-ir/asap-l2; asap-plan depends
only on asap-ir, so this pulls in no datafusion/front-end weight).

capability_for no longer maintains its own hand-written AggIntent -> ASAP-tier
capability match -- that was a second, parallel judgment kept in sync with
asap-plan's own implementation_for by hand (and had already drifted twice:
the Count/Min-Max divergences fixed in a prior commit). It now keeps only
the Extension/Frequency special case (deployment-specific -- asap-plan has
no opinion on an intent shape it can't see into, by design) and delegates
everything else to asap_plan::boundary::implementation_for, translating the
returned Implementation into this repo's coarser Capability vocabulary via
the new implementation_to_capability helper. One deliberate override
survives the delegation: Count{Exact} is forced to None (archive) rather
than trusting implementation_for's ExactAccumulator claim, because the data
plane has no working count accumulator (SumAccumulator conflates Sum and
Count).

All 772 existing tests pass unchanged -- confirms the delegation is
behaviorally identical to the hand-written match it replaces, including the
Min/Max and Count fixes from the prior commit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant