Skip to content

Commit 7520224

Browse files
committed
Fix AssertionError crash in MSD binary search when all alphas are feasible
When the network has excess capacity and every probed alpha up to alpha_max is feasible, the bracketing phase sets upper = min(alpha_max, lower + 1.0). Since lower already equals alpha_max at that point, upper == lower, causing the assertion `lower < upper` to fail with an AssertionError. Fix: return lower directly when no infeasible upper bound is found, since the last proven feasible alpha is the best answer available. https://claude.ai/code/session_013XZpjpJ1MM2jJFXHRdEZVi
1 parent 04e88bb commit 7520224

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

ngraph/workflow/maximum_supported_demand_step.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ def _binary_search(self, probe: "Any") -> float:
229229
break
230230
lower = alpha
231231
if upper is None:
232-
upper = min(self.alpha_max, lower + max(self.resolution, 1.0))
232+
# All probed alphas up to alpha_max are feasible;
233+
# no infeasible upper bound exists to bisect toward.
234+
return lower
233235
else:
234236
upper = start_alpha
235237
alpha = start_alpha

tests/workflow/test_maximum_supported_demand.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,42 @@ def test_msd_auto_vs_one_equivalence_single_link() -> None:
228228
alpha_one = float(exported["steps"]["msd_one"]["data"]["alpha_star"])
229229
# Both should find approximately the same alpha* for this simple case
230230
assert abs(alpha_auto - alpha_one) <= 0.02
231+
232+
233+
@patch.object(MaximumSupportedDemand, "_evaluate_alpha")
234+
@patch.object(MaximumSupportedDemand, "_build_cache")
235+
def test_msd_all_feasible_up_to_alpha_max(
236+
mock_build_cache: MagicMock, mock_eval: MagicMock
237+
) -> None:
238+
"""Test that MSD returns alpha_max when all alphas are feasible.
239+
240+
Regression test: when the network has excess capacity and every probed
241+
alpha up to alpha_max is feasible, the binary search must return
242+
alpha_max instead of crashing with an AssertionError.
243+
"""
244+
mock_build_cache.return_value = MagicMock()
245+
246+
# Always feasible — network has more capacity than any demand multiplier
247+
def _eval(cache, alpha, seeds):
248+
return True, {"seeds": 1, "feasible_seeds": 1, "min_placement_ratio": 1.0}
249+
250+
mock_eval.side_effect = _eval
251+
252+
scenario = _mock_scenario_with_matrix()
253+
alpha_max = 100.0
254+
step = MaximumSupportedDemand(
255+
name="msd_all_feasible",
256+
demand_set="default",
257+
alpha_start=1.0,
258+
growth_factor=2.0,
259+
resolution=0.01,
260+
alpha_max=alpha_max,
261+
max_bracket_iters=16,
262+
seeds_per_alpha=1,
263+
)
264+
scenario.results = Results()
265+
step.execute(scenario)
266+
267+
exported = scenario.results.to_dict()
268+
alpha_star = exported["steps"]["msd_all_feasible"]["data"]["alpha_star"]
269+
assert alpha_star == alpha_max

0 commit comments

Comments
 (0)