_recommend can KeyError when peak-clamped node count isn't in node_grid #18

Closed
opened 2026-07-08 16:27:06 +03:00 by issuer-agent · 1 comment

In nix_estimator/estimate.py, _recommend does chosen_nodes = min(chosen_nodes, max(1, peak)) and then indexes at[chosen_nodes] (and returns est_makespan_min = round(at[chosen_nodes], 1)). But at is keyed only by the values present in node_grid. When the graph's peak concurrency is smaller than every element of node_grid (or otherwise not one of the swept node counts), min(chosen_nodes, peak) produces a value that is not a key in at, raising KeyError. Example: node_grid=(2,4,8) with peak=1chosen_nodes=1, at[1] → KeyError.

Implementation: after clamping, snap chosen_nodes to the largest node_grid value ≤ the clamp target (or the smallest available if none qualifies), so it is always a valid key in at. Alternatively compute makespan for the clamped node count on demand. Add a regression test with node_grid whose minimum exceeds peak.

Discovered during work on issue #11.

In `nix_estimator/estimate.py`, `_recommend` does `chosen_nodes = min(chosen_nodes, max(1, peak))` and then indexes `at[chosen_nodes]` (and returns `est_makespan_min = round(at[chosen_nodes], 1)`). But `at` is keyed only by the values present in `node_grid`. When the graph's `peak` concurrency is smaller than every element of `node_grid` (or otherwise not one of the swept node counts), `min(chosen_nodes, peak)` produces a value that is not a key in `at`, raising `KeyError`. Example: `node_grid=(2,4,8)` with `peak=1` → `chosen_nodes=1`, `at[1]` → KeyError. Implementation: after clamping, snap `chosen_nodes` to the largest `node_grid` value ≤ the clamp target (or the smallest available if none qualifies), so it is always a valid key in `at`. Alternatively compute makespan for the clamped node count on demand. Add a regression test with `node_grid` whose minimum exceeds `peak`. Discovered during work on issue #11.
Owner

Fixed and merged to main (commit 837b885).

Fixed and merged to main (commit 837b885).
oleks closed this issue 2026-07-08 17:52:11 +03:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: oleks/nix-estimator#18