harbor run -t openthoughts/tasktrove-exp-rpt-issue-issue-1477harbor download openthoughts/tasktrove-exp-rpt-issue-issue-1477Currently, RandomizedSearchCV raises an error when the number of iterations (n_iter) requested by the user is larger than the total number of parameter configurations available (grid_size). The desired behavior is to treat n_iter as an upper bound: if n_iter > grid_size, emit a warning and run at most grid_size iterations (i.e., exhaust the grid). This keeps the interface simple (no new constructor options) and avoids hard failures for user-supplied inputs that may exceed the current grid size.
What to implement
Files to modify
Before (pre-fix state)
# app/random_search.py (before)
from itertools import product
import random
class RandomizedSearchCVLike:
def __init__(self, param_distributions, n_iter=10, random_state=None):
self.param_distributions = param_distributions
self.n_iter = n_iter
self.random_state = random_state
def _build_param_grid(self):
keys = list(self.param_distributions.keys())
values = [self.param_distributions[k] for k in keys]
grids = [list(v) for v in values]
combos = [dict(zip(keys, prod)) for prod in product(*grids)]
return combos
def __iter__(self):
param_grid = self._build_param_grid()
grid_size = len(param_grid)
if grid_size < self.n_iter:
raise ValueError(
"The total space of parameters %d is smaller "
"than n_iter=%d. For exhaustive searches, use "
"GridSearchCV." % (grid_size, self.n_iter))
indices = list(range(grid_size))
rnd = self.random_state or random.Random()
chosen = rnd.sample(indices, self.n_iter)
for i in chosen:
yield param_grid[i]
How to run / test locally (example)
What to implement (behavior expected after fix)
Exactly which files to create/modify
Notes and constraints
What you will deliver
Rationale