Language models for context rewrites, ideas, and benchmark tasks¶
The LLM search examples use
deterministic callbacks by default. The optional live mode sends the
same kinds of proposals to a model. In the scheduling examples the model
returns small JSON data structures. QDpy evaluates them with ordinary
Python scheduling functions.
python -m examples.llm_qd neighborhood --budget 12 --seed 11
python -m examples.llm_qd ideagent --budget 12 --seed 11
python -m examples.llm_qd tasks --budget 12 --seed 11
python -m examples.llm_qd qdevo --budget 12 --seed 11
Neighborhood Elites¶
qdpy.algorithms.NeighborhoodElites builds an archive for one
question and context. A cell identifies an edit type and a level of
answer support. The scheduler first generates rewrites from the source,
then targets empty cells, and finally tries to raise the quality of
occupied cells. Insertion and reordering can inherit the parent’s level
of answer support. The assessor assigns the realized cell and rejects
rewrites that fail answer preservation or the edit check.
from qdpy.algorithms import NeighborhoodElites
search = NeighborhoodElites(context, seed=11)
search.run(edit_context, validate_and_score, budget=25,
refinement_reserve=5)
result = search.probe(answer_question, group=answer_class, limit=8)
print(result.entropy, search.stats.answer_calls)
Close the editor and assessor over the fixed question and reference
answer. The assessor receives the parent text, its proposed rewrite,
and the target cell, and returns (realized_cell, quality) or
None. Bind the answerer to the question and query it on the
retained contexts. Group equivalent answers using a callback.
Empirical entropy is reported in nats. With an empty archive it is
undefined and returned as None.
The example uses a labeled question with two support levels, a restricted edit grammar, lexical quality, and normalized answer strings. It compares archive coverage with independent style rewrites at the same editor-call cap. The answerer queries all targeted elites. The report also gives entropy on equally sized subsets when the comparator has fewer valid rewrites. The paper uses a larger edit strategy library and semantic and locality scores. [1]
IDEAgent¶
qdpy.algorithms.IDEAgent keeps lineages of ideas that meet
non-obviousness, soundness, and clarity thresholds. An eligible near
miss can receive one repair. Accepted drafts can receive further
refinement as long as the auxiliary cap and overall proposal budget
allow it. A similar, stronger draft can replace an active draft in
the same lineage. Historical and rejected signatures accompany later
proposals, and ambiguous matches to multiple active lineages are
rejected.
The proposer receives an qdpy.algorithms.IdeaRequest with
the operation, the measured parent when applicable, and the current
memory. The assessor returns an qdpy.algorithms.IdeaAssessment
with scores in [0, 1] and a mechanism signature. Supply a symmetric
similarity function over signatures. An optional
refinement_preference(parent, revision) callback can provide an
independent comparison of otherwise eligible revisions. A judgment panel,
critic, or two-order comparison can be implemented inside the callbacks.
qdpy.algorithms.idea_yield() counts the largest pairwise diverse
subset satisfying all quality thresholds. It uses exact maximum clique
search, so use small panels. The example defines mechanisms by scheduling
mode and dominant priority term. It uses measured tardiness and a
synthetic non-obviousness score. The comparison spends the same number of
proposal attempts on independent drafts with the same admission rules.
The original paper evaluates research ideas with a panel of model
judgments. [2]
Generate benchmark tasks¶
qdpy.algorithms.TaskArchiveSearch adapts OMNI-EPIC’s reuse
of successful and unsuccessful tasks to bounded solver benchmarks.
It passes a parent, its nearest archived examples, and recent
unsolved tasks to the proposer. An optional reviewer sees the solved
task and nearby measured elites before admission. Only solved tasks
can compete in the QD grid.
The example proposes five-job scheduling instances, computes an exact tardiness optimum over 120 orders, and measures two fixed heuristics on the same job data. The grid axes are the better heuristic’s regret and the absolute gap between the two heuristics. Quality is the gap. The task must satisfy the declared normalized optimum threshold and show a positive gap. The independent arm receives no archive examples. One measured task costs three solver calls. This adaptation uses a fixed solver panel in place of the paper’s RL training loop. [3]
Reflect on QDEvo parent measurements¶
In the reflection arm, QDEvo supplies archived rules and measured training objectives to the model. The same response gives a short diagnosis and a revised rule. In the independent arm, the model uses the same grammar and objectives and receives no parent measurements. Both use QDEvo’s local Pareto competition and get the same number of proposal attempts. The example separates training, behaviour embedding, and held-out schedules. It uses one model call to propose each revision, a small workflow inspired by the paper’s hierarchical self-reflection. [4]
Run with a hosted model¶
The openrouter backend uses HTTP. The litellm backend uses the
separately installed client and the same OpenRouter model slug. Configure
OPENROUTER_API_KEY or supply --openrouter-key-file. See
Run QDAIF with OpenRouter or LiteLLM for client installation.
python -m examples.llm_qd qdevo --backend openrouter --model openai/gpt-4.1-mini --budget 2
python -m examples.llm_qd neighborhood --backend litellm --model openai/gpt-4.1-mini --budget 2
The budget is per arm. The QA example also queries the answerer at most once per retained rewrite in each arm. The output records model calls by role and token usage reported by the provider. The seed controls QDpy and the offline generators. Live outcomes depend on the model and routing.
Small offline comparison¶
The complete results use seeds
11, 23 and 47 with 12 proposals per arm.
Targeted Neighborhood Elites filled six cells on each seed. Independent style rewrites filled two. Both queried six contexts per seed. The deliberately position-sensitive answerer gave entropy 0.637 versus 0.
IDEAgent retained three, four and three distinct qualified lineages. Independent drafting retained three, five and five. The lineage workflow used one repair on each seed.
Both task generators retained two occupied cells per seed. The archive-conditioned arm evaluated 12, nine and ten distinct tasks. The independent arm evaluated 12 per seed.
The QDEvo example compares proposal policies at equal proposal caps. The offline reflection arm uses seeded mutations in place of a model. It made eight to ten rule evaluations, including three shared seed rules, against 14 or 15 for independent proposals. See the per-seed held-out scores for their trade-offs.
These comparisons check workflows and accounting. The QA fixture illustrates disagreement for a position-sensitive stand-in on a single labeled question.