You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit af65096
Browse filesBrowse the repository at this point in the historyBrowse files
Update the developer docs and the `CostModel` trait doc: strategies take no
cost model, sketch sizing is analytical, extension intents stay
pass-through, and the cost model is consulted only at selection.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/develop_docs/asap-aware-mapping-architecture.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,9 @@ A strategy should answer:
42
42
43
43
A cost model should answer:
44
44
45
-
> Given valid choices, which choices are preferable, and how should they be parameterized?
45
+
> Given valid choices, which choices are preferable?
46
+
47
+
It is consulted only at selection time; sketch parameters come from the analytical estimators.
46
48
47
49
Do not put cost-based pruning into a `ReplacementStrategy`. A strategy must enumerate every valid alternative, even when the default cost model clearly prefers one. See [Rule 2](extend-asap-aware-mapping.md#rule-2-enumerate-do-not-rank).
48
50
@@ -98,8 +100,6 @@ flowchart TB
98
100
STRATEGY["ReplacementStrategy<br/>when a target matches, enumerate every legal replacement;<br/>implementations generate but do not choose"]:::generate
99
101
CAND["ReplacementSubDAG candidates<br/>each contains a Subtree (summary or logical rewrite) or ExactComposition<br/>plus typed provenance and rationale;<br/>no alternative is removed solely on cost"]:::store
100
102
TARGET -->|"try every registered strategy"| STRATEGY --> CAND
101
-
CM(["CostModel<br/>orders candidates and supplies<br/>deployment-specific parameters"]):::choose
102
-
CM -. "rank and parameterize; accuracy checks remain required" .-> STRATEGY
103
103
end
104
104
105
105
subgraph SEARCHSPACE[3. Store the workload-wide search space]
@@ -108,7 +108,9 @@ flowchart TB
108
108
end
109
109
110
110
subgraph RANKING[Optional ranked view]
111
+
CM(["CostModel<br/>selection-time preferences and costs"]):::choose
111
112
SORT["CandidateLogicalASAPDAGs::cost_sorted<br/>use the CostModel to order each candidate set<br/>and cost every candidate"]:::choose
113
+
CM -.-> SORT
112
114
RANKED["RankedTargetSubDAGCandidates<br/>the same candidates in preferred order,<br/>with costs aligned by index"]:::choose
113
115
SPACE --> SORT -->|"reorder only; preserve every candidate"| RANKED
114
116
end
@@ -193,9 +195,8 @@ capability and accuracy checks; supported algorithm applicability alone is not
193
195
a result certificate.
194
196
195
197
The complete `replacements()` result is the candidate set produced by one
196
-
strategy for one target. A strategy may order or parameterize candidates with
197
-
help from a `CostModel`, but it must not remove a valid candidate because of
198
-
cost.
198
+
strategy for one target. Strategies take no `CostModel` and must not remove a
199
+
valid candidate because of cost; ranking happens at selection time.
199
200
200
201
### 3.3 Current concrete strategies
201
202
@@ -204,9 +205,9 @@ The default context-free registry contains five `ReplacementStrategy` implementa
204
205
-`ASAPStrategies` matches supported aggregate and binary shapes. Its
205
206
`replacements(target)` method constructs every legal post-ASAP summary sub-DAG,
206
207
including applicable sketch, exact-accumulator, and pass-through
207
-
realizations. Candidates are sized and ordered for the target's accuracy
208
-
requirement; candidates without a sufficient guarantee are rejected before
209
-
costing.
208
+
realizations. Candidates are sized analytically for the target's accuracy
209
+
requirement and listed in `summary_candidates` order; candidates without a
210
+
sufficient guarantee are rejected before costing.
210
211
-`SharedSubDAGStrategy` uses `consumer_count` to identify shared targets. It
211
212
emits both build-once-and-share and recompute-independently rewrites when a
212
213
target has multiple consumers.
@@ -215,8 +216,8 @@ The default context-free registry contains five `ReplacementStrategy` implementa
215
216
-`ExactCompositionStrategy` preserves child-target references for compatible
216
217
composition selection.
217
218
218
-
`default_strategies_with` uses `SemanticEquivalentRewriteStrategy`in its rewrite
219
-
slot. The evidence-aware registry supplies the accuracy evidence provider to
219
+
`default_strategies` uses `SemanticEquivalentRewriteStrategy`(via its
220
+
`AvgToSumOverCountStrategy` alias) in its rewrite slot. The evidence-aware registry supplies the accuracy evidence provider to
220
221
summary and Hydra construction. Search derives `RollupStrategy` after CSE from
Copy file name to clipboardExpand all lines: docs/develop_docs/asap-aware-mapping-contracts.md
+11-46Lines changed: 11 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,9 +147,9 @@ Search calls `propose`, so rejected candidates remain available for explanation.
147
147
148
148
> What are all semantically valid alternatives for this target?
149
149
150
-
`replacements` must be **exhaustive and not cost-filtered**. When its output has
151
-
a preferred order, that ordering must come from the supplied `CostModel`; the
152
-
strategy must still return every supported legal candidate. Required accuracy,
150
+
`replacements` must be **exhaustive and not cost-filtered**. Strategies take no
151
+
`CostModel`; output order carries no cost preference, and ranking happens at
152
+
selection time. The strategy must return every supported legal candidate. Required accuracy,
153
153
schema and capability checks can reject an otherwise applicable algorithm;
154
154
exhaustiveness is not a promise of all theoretically possible plans.
155
155
@@ -164,7 +164,9 @@ accumulator, or a pass-through that keeps the original operation instead of
164
164
building a summary. `realizations_for_intent` enumerates these concrete
165
165
realizations; `ASAPStrategies::replacements()` constructs each one as
166
166
a `ReplacementSubDAG`. It returns all
167
-
candidates in preferred order without selecting a winner. At workload scale,
167
+
candidates in `summary_candidates` order, sized by the analytical estimators,
168
+
without selecting a winner; `AggIntent::Extension` intents stay
169
+
`Realization::PassThrough`. At workload scale,
168
170
`search_workload`/`search_workload_with` preserve all supported legal alternatives
169
171
across every `TargetSubDAG`. Optional planner APIs coordinate compatible semantic selections; physical
170
172
commitment and placement remain downstream deployment decisions.
@@ -201,17 +203,14 @@ see [code architecture §3](asap-aware-mapping-architecture.md#3-how-the-current
201
203
202
204
### `CostModel`
203
205
204
-
`CostModel` covers every deployment-specific numeric or configuration decision—not only which candidate is cheapest. For example, sketch sizing trades memory and update cost for accuracy, so it belongs here too.
206
+
`CostModel` covers deployment-specific preference and cost decisions. It is consulted only at selection time (`cost_sorted`, `global_selection` and their `_with_recurrence` variants), never during candidate generation: sketch parameters come from the analytical estimators (`accuracy::estimators::size_params`), and extension intents stay pass-through.
205
207
206
208
The crate cannot hardcode real deployment costs: `asap-aware-mapping` uses `asap-types` and pinned `asap_sketchlib` mapping
207
209
bounds, but does not execute workloads or own deployment measurements. Most hooks therefore provide the crate's built-in static behavior as a default. Override only the decisions your deployment needs to change.
208
210
209
211
| Hook | Use it to | Default? |
210
212
|---|---|---|
211
213
|`rank_candidates`| Order valid sketch algorithms | No |
212
-
|`size_params`| Convert an accuracy target into sketch parameters | Yes |
213
-
|`realize_extension`| Map a custom intent to a realization | Yes |
214
-
|`evaluation_extension`| Query a custom extension summary | Panics until paired with a custom realization |
-**`size_params`** — choose parameters, such as sketch capacity, for an already-selected `SketchAlgorithm` and accuracy target `(eps, delta)`, where `eps` is the tolerated error and `delta` is the tolerated probability of exceeding that error. It is separate from ranking so a deployment can customize sizing without changing algorithm preference. The trait provides a default implementation.
-**`realize_extension`** — map a deployment-defined `AggIntent::Extension` to a post-ASAP `Realization`. The default is `Realization::PassThrough`.
233
-
234
-
Use `AggIntent::Extension { ext_kind, payload }` for intent shapes that only your deployment needs. Core treats both fields as opaque. For example, a deployment can tag an approximate-frequency intent with `ext_kind: "frequency"` and recognize it in `realize_extension`:
-**`evaluation_extension`** — define how queries read an extension summary that `realize_extension` mapped to a `Sketch`. The two hooks are a pair: realization defines what is maintained; evaluation defines how it is queried. Override both for the same `ext_kind`. The default evaluation panics to prevent a silent wrong answer.
-**`cse_recompute_cost`** — estimate the one-time cost of recomputing a CSE candidate's sub-DAG independently at a single consumer. Default: `default_cse_recompute_cost`, a structural-size proxy.
262
226
263
227
```rust
@@ -297,7 +261,8 @@ A custom cost model does not necessarily need to override every hook. The curren
297
261
`ReplacementStrategy` answers "what are the candidates for this one target?" `CandidateLogicalASAPDAGs` answers the same question for every target in a whole workload at once, without enumerating `2^N` fully-copied plans for `N` independently-choosable sites.
// One TargetSubDAGCandidates per distinct TargetSubDAG in the whole workload —
303
268
// never a flat list of fully assembled plans.
@@ -345,7 +310,7 @@ to the selected algorithm and classifies the pair into its category. The public
345
310
`.category()`, `.algorithm()`, and `.params()` accessors expose the committed
346
311
values without permitting an invalid combination.
347
312
348
-
Where this matters in practice: `CostModel::rank_candidates`, `CostModel::size_params`, and `ASAPStrategies::replacements` operate at the **algorithm** level. `summary_candidates(intent)` returns a list of `SketchAlgorithm`s (`[Kll, DDSketch]` for a `Quantile` intent), never a bare `SketchKind` with nothing chosen underneath it. `SketchKind` appears after an algorithm has been selected and sized—on `Realization::Sketch(SketchKind)` and `FieldDataType::Sketch(SketchKind, GroupingStrategy)`.
313
+
Where this matters in practice: `CostModel::rank_candidates` and `ASAPStrategies::replacements` operate at the **algorithm** level. `summary_candidates(intent)` returns a list of `SketchAlgorithm`s (`[Kll, DDSketch]` for a `Quantile` intent), never a bare `SketchKind` with nothing chosen underneath it. `SketchKind` appears after an algorithm has been selected and sized—on `Realization::Sketch(SketchKind)` and `FieldDataType::Sketch(SketchKind, GroupingStrategy)`.
349
314
350
315
`Sample`, `Wavelet`, and `StatModel` each use a flat `(Kind, Params)` pair. `Sketch` needs the additional algorithm level because multiple algorithms can serve the same purpose—for example, KLL and DDSketch both answer quantile queries.
351
316
@@ -395,7 +360,7 @@ Each `ReplacementExplanation::reason` is copied verbatim from the matching candi
395
360
396
361
### Why there is no `ExplanationRule` trait
397
362
398
-
Explanations are derived from candidates already present in `CandidateLogicalASAPDAGs`. A new candidate kind therefore requires an `impl ReplacementStrategy` wired into `default_strategies`/`default_strategies_with`; a second explanation-specific trait would duplicate registration and could drift from the actual search space. Custom callers supply strategies through `explain_replacements_with`, using the same extension point exposed by `search_workload_with`.
363
+
Explanations are derived from candidates already present in `CandidateLogicalASAPDAGs`. A new candidate kind therefore requires an `impl ReplacementStrategy` wired into `default_strategies`; a second explanation-specific trait would duplicate registration and could drift from the actual search space. Custom callers supply strategies through `explain_replacements_with`, using the same extension point exposed by `search_workload_with`.
0 commit comments