Repository navigation
refactor(stage3): one cost-row builder and model setup for cost models 1 and 3 - #1519
Merged
Merged
Conversation
…fixed cost Add refresh_queue (which groups a refresh group waits behind, whole or shared over the precompute threads), request_fixed_cost and requests_per_second, used by plan_cost and, next, by Stage 3. Delete lookup, which only tests called; they call lookup_at_scale.
…s 1 and 3
selection_cost_terms builds the x/y/h terms and raw-data rows for both
objectives (the per-source r_s comes from a closure, keyed by Source);
selection_model, structure_constraints, column_of, solution_columns and
the read-back helpers replace the duplicated setup and HiGHS handling.
Use asap_cost's refresh_queue and request_fixed_cost. Reader::variable
and Reader::is_selected replace six matches. Delete Pairing,
LARGEST_SCALED_COEFFICIENT and Objective::{Memory, Disk}; fill
ClusterLimitShortfall::available in the cluster module.
Make step_rounds private (RequestFixedCost::step_rounds replaces it); compute request_fixed_cost once per query in plan_cost and query_latencies; assert cost model 1's costed-edge and retention-share invariants again; if/else on refresh_queue's kind; keep over_a_limit_alone's short-circuit.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
cluster/solve.rs) re-implemented cost model 1's cost rows, model setup, HiGHS status handling and read-back. It also re-implemented twoasap_costrules: refresh queueing and the fixed cost of each request. Every change had to be made twice and kept in sync by hand. feat: storage description in the cost inputs, disk cost in the presets, and exact raw-data disk cost in Stage 3 (#1469) #1474 had to do this for the raw-data rows.selection_cost_terms, with each source's&Sourceinstead of a debug string). Shared helpers for model setup and solving.asap_cost::{refresh_queue, request_fixed_cost, requests_per_second}used on both sides.Reader::{variable, is_selected}replace six copies of amatch. Dead or one-variant items are deleted.the_milp_latencies_are_the_plan_costs_on_every_snapshot_workload(MILP latency ==plan_costlatency) and the debug assert that the MILP objective equalsplan_coststill hold. Net change: −551 / +564 lines; the additions include doc comments on the new shared helpers.Review guide
main. Not stacked.crates/stage3-plan-selection/src/milp/model/mod.rs:selection_cost_terms,selection_model,structure_constraints,solution_columns,selected_executions_and_edges/answering_executions,objective_scale. Thencluster/solve.rs(quantity_expression,build_and_solve), which now calls them.retention.rsandselection_cost_per_second(Readermethods),dominance.rs(Pairingremoved,no_more/answers_per_execution/input_ofmoved to module level),exclusions.rs(D8),lib.rs(O4),measured.rs(X1), andlowest_mean_latency.rs(D14).Behavior: before → after
asap-planner --format jsonon any workload, under cost model 1 or cost model 3 (lowest_mean_latency): the same selected plan, cost per second, per-query latencies, and the same accepted/rejected lines, before and after. Evidence: the planner-cli snapshot suites and the exactness tests in Verification, which compare complete plan outputs over the snapshot corpus. The only visible difference is the label in thelog_solverstderr line for tie-break solves:Memory/DiskbecomeLimit(MemoryBytes)/Limit(DiskBytes). The PR serves maintainability: one place to change each cost row and each queueing rule.Interfaces
crates/cost/src/plan/cost.rs,crates/cost/src/lib.rs,crates/cost/src/measured.rs(cost.rs, measured.rs)lookupis removed because only tests called it. Production code callslookup_at_scale, which now carrieslookup's doc. The tests calllookup_at_scale(..., None).crates/stage3-plan-selection/src/selectable.rs(file), crate-privatepub(crate) enum Reader { Edge(usize), Output(QueryId), } +impl Reader { + /// This read's y (edge) or z (query output) variable; None when not selectable. + pub(crate) fn variable(self, execution: usize, y: &BTreeMap<usize, Variable>, z: &BTreeMap<(QueryId, usize), Variable>) -> Option<Variable>; + /// Whether this read is among the selected edges / outputs. + pub(crate) fn is_selected(self, execution: usize, edges: &HashSet<usize>, outputs: &HashSet<(QueryId, usize)>) -> bool; +}crates/stage3-plan-selection/src/milp/model/mod.rs(file), module-privatecrates/stage3-plan-selection/src/milp/model/cluster/{solve,mod}.rs,milp/dominance.rs,lib.rs, crate-privateavailable()moved fromlib.rstocluster/mod.rs.ClusterLimitShortfall.availableis now set when the shortfall is built, with no NaN placeholder.Usage (flow, unchanged in behavior):$r_s$ per source) → f_G and big-M from
asap-planner --format json→select_plan→ under cost model 1,solve_selection→selection_model→selection_cost_terms(…, |source| variables.raw_data_on_disk[source])→structure_constraints+ raw-data rows scaled byobjective_scale→ HiGHS →solution_columns→ read-back. Under cost model 3,solve_cluster_selection→build_and_solve→selection_model→quantity_expressiononce per memory, disk and CPU (each callsselection_cost_termswith a closure that adds oneasap_cost::refresh_queue→ per-query fixed latency and CPU fromasap_cost::request_fixed_cost→ the same read-back. The output is the selected plan, as before.Algorithm changes
None. The rules and formulas are the same; only where they are written changes. The order of variables (HiGHS columns) and rows is preserved for cost model 3. For cost model 1, only the raw-data rows move (see below).
Decisions and open questions
Needs reviewer decision: None.
Decided (2026-11-25, by the implementer, within the behavior-preserving rule):
kept_result_terms/resident_window_termsstay outside the shared builder. Cost model 1 calls them in the order resident, then kept; cost model 3 calls them kept, then resident. Each adds variables, so moving them into one builder would reorder HiGHS columns for one of the two models. Both are already shared functions.structure_constraints. This only reorders rows in a gap-0 solve, so the optimum is the same. Among plans that cost exactly the same, HiGHS may now return a different one, because its search follows row order, and solve time may shift; neither was measured. No snapshot changed.expectand indexing; it is now anassert!insolve_selection. The shared builder reads a missing value as 0, which only cost model 3's quantities have.over_a_limit_alonekeeps its own||test, so it skips the disk sum when memory alone is over the limit (review nit).solution_columnsacceptsReachedSolutionLimitwith a feasible solution for both models. Cost model 1 sets no node or solution limit, so it never gets that status.refresh_queuereturns which kind of wait applies (bool), not a coefficient. Each site applies its own form (/ threadsin f64,* (1/threads)on anExpression), so the floats are identical bit for bit. Not shared: grouping by refresh window and building group reads.plan_costgroups DAG nodes and updates their phase times at the same time, while Stage 3 groups executions. The parts that have to stay in sync withplan_costare the queueing rule and the request cost, and both are now shared.plan_cost's per-query fixed latency now usesrequest_fixed_cost(..).latency_ms=(a + b·r)·1e-6instead ofa·1e-6 + b·1e-6·r. These can differ in the last bit; no snapshot or golden changed.Objectiveis crate-private and never serialized, so no input or output file format changes.assert_closehas a 1e-9 floor, where the deleted local copy had 1e-7. Alllowest_mean_latencytests pass with it.Deleted
asap_cost::lookuplookup_at_scale(.., None)asap_cost::step_rounds(now private, not re-exported)request_fixed_cost; others readRequestFixedCost::step_roundsPairing { LifetimeTwin }and its parameter (dominance.rs)LARGEST_SCALED_COEFFICIENT(cluster/solve.rs)LARGEST_SCALED_OBJECTIVE_COEFFICIENT, viaobjective_scaleObjective::Memory,Objective::DiskObjective::Limit(MemoryBytes / DiskBytes)raw_data_disk_rows,raw_data_read_variable(model/mod.rs)selection_cost_termsandReader::variablegroup_ofclosure (exclusions.rs)memo_group_ofassert_close(lowest_mean_latency.rs)lowest_mean_latency_common.rsavailableinlib.rsdiagnoseincluster/mod.rsVerification
cargo fmt --all --checkcargo clippy -p asap-cost -p asap-stage3-plan-selection -p asap-integration-tests -p asap-devtools --all-targets -- -D warnings-p asap-cost -p asap-stage3-plan-selectionmeasured_operation_costs/ integrationlowest_mean_latency+stage3_objective/ planner-cligoldensasap-stage3-plan-selectionlib (debug: MILP objective ==plan_costassert)big_m_bounds_the_freshness_of_every_selection, which checksfreshness_big_magainst its own copy of the queueing ruleasap-costlib /measured_operation_costs/cost_inputs_jsonlookuptests moved tolookup_at_scale(.., None)asap-integration-tests(lowest_mean_latency,stage3_objective,storage_costs,calibration_terms, …)corpus_snapshots/goldenstests/main.rs(sketch plan snapshots,lowest_mean_latency_exactness)tests/main.rs,asap_lane_conformance, lib)asap-costdoctestsmeasured.rsNo new tests: this PR is a refactor, and the suites above already cover each changed path.
Follow-ups
LatencySelectionChecksout ofasap_cost::CostInputsinto Stage 3. Left out because it changes the cost-inputs format.ExecutionCostsfields instage3 cost.rs, and the D7/O6 cover code.refresh_wait_ms_per_run), D10, D11, D13, O5, O7, X2–X4.