Skip to content

Use measured results to generate candidates

A fixed comparison can tell you which of the candidates you supplied scored highest. A search also has to decide what to try next. In OptPilot, the Task defines the measurement and the Generator makes that decision. You can change the search strategy while keeping the same cases, baseline and grader.

Start with a baseline and a budget

From the Core checkout, run the staffing search. It needs only Core.

uv run optpilot experiment run --project tests/fixtures/catalog/optpilot_tutorial --study toy_factory-search

The baseline uses five workers, a buffer of twelve and balanced operation. The grader measures throughput and operating cost at a demand of 72. The first Trial produces a throughput of 67.1 and a cost of 44.2. Its score is throughput - 0.55 × operating_cost, or 42.79 to two decimal places.

The generation budget of five counts new candidates. With one instance and one repetition, the baseline plus five proposals gives six trials. In generations, the first call contains the baseline's metrics in input.feedback. Later calls contain measurements from the earlier proposals too. Each call lists the candidate versions it produced. The bundled random search uses the parameter ranges and a seed to choose values, even though the scores are available to it.

Try a feedback-driven proposal

Work in a copy of tests/fixtures/catalog/optpilot_tutorial. In that copy, replace the contents of generate.py with the following function. It first tries one additional worker. It then takes the higher-scoring configuration and tests whether switching it to efficient operation helps.

def propose(context):
    measured = context['feedback']
    if not measured or context['generatedCount'] >= 2:
        return []

    best = max(measured, key=lambda row: row['metrics']['score'])
    proposal = dict(best['value'])
    if context['generatedCount'] == 0:
        proposal['workers'] += 1
    else:
        proposal['mode'] = 'efficient'
    return proposal

Run the same command with --project pointing to your copy. The Task makes score, throughput and operating_cost available to this generator through feedbackMetrics. Inspect the second call's feedback and compare its chosen parent configuration with its output. With the supplied model, adding a worker raises the score from 42.79 to 43.29. The generator therefore tries efficient operation with six workers and measures 44.418. It returns an empty list after those two proposals, ending the Run after three scored trials. A new review captures the changed generator code. Generator contract · Read a Run