协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
advanced-apis【开发与工程】Advanced Optuna support APIs for terminator stopping, search-space inspection, hypervolume helpers, constraints notes, logging, exceptions, experimental warnings, and extension/debugging patterns.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is about advanced, user-facing support APIs and cross-cutting debugging around Optuna studies: optuna.terminator, optuna.search_space, Optuna logging controls, Optuna-specific exceptions, ExperimentalWarning, constrained/multi-objective support notes, and internal hypervolume utilities that sometimes appear in advanced multi-objective workflows.
Terminator, TerminatorCallback, report_cross_validation_scores, IntersectionSearchSpace, intersection_search_space, Optuna logger configuration, optuna.exceptions, ExperimentalWarning, private _hypervolume adaptation notes, and constraint debugging concepts.Study.optimize, Study.ask, Study.tell, objective authoring, callbacks in general, and result extraction to ../optimization-workflows/SKILL.md.constraints_func constructor tuning, and algorithm-specific behavior to ../samplers-pruners/SKILL.md.../cli-and-storage/SKILL.md.../artifacts-integrations/SKILL.md.../analysis-visualization/SKILL.md.references/advanced-api-reference.md for exact APIs, version/stability notes, and copy-paste patterns.references/troubleshooting.md for import failures, optional dependency absence, terminator warnings, empty search spaces, logging duplication, constraints issues, and exception triage.optuna is importable:
python scripts/terminator_smoke.pyoptuna.terminator is deprecated as of Optuna 4.9.0 and planned for removal in 6.0.0. Use it only for legacy or explicitly requested workflows, and expect FutureWarning when constructing terminator objects.
import optuna
from optuna.terminator import BestValueStagnationEvaluator
from optuna.terminator import StaticErrorEvaluator
from optuna.terminator import Terminator
from optuna.terminator import TerminatorCallback
def objective(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", -1.0, 1.0)
return x * x
study = optuna.create_study(direction="minimize")
terminator = Terminator(
improvement_evaluator=BestValueStagnationEvaluator(max_stagnation_trials=5),
error_evaluator=StaticErrorEvaluator(constant=0.0),
min_n_trials=3,
)
study.optimize(objective, n_trials=100, callbacks=[TerminatorCallback(terminator)])
from optuna.search_space import IntersectionSearchSpace
search_space = IntersectionSearchSpace()
study.optimize(objective, n_trials=5)
print(search_space.calculate(study))
Intersection search spaces include only parameters whose distributions are present and equal across completed trials. Conditional or changing distributions can shrink the result to {}.
Terminator.should_terminate(study) stops only when the evaluated improvement is strictly smaller than the evaluated error and the number of complete trials is at least min_n_trials.report_cross_validation_scores(trial, scores) requires more than one score and stores scores for CrossValidationErrorEvaluator.IntersectionSearchSpace instances are intended for one study; with persistent storage, reusing one instance across different studies raises ValueError.optuna.logging controls Optuna's library root logger; enable propagation and disable the default handler when integrating with application logging to avoid duplicate stderr output.optuna._hypervolume as private: useful for advanced diagnostics or adaptation, but not a stable public API contract.optuna.exceptions.ExperimentalWarning or Python warning filters when an experimental API warning is expected and intentional.TerminatorCallback to a deterministic objective, explain why FutureWarning appears, and verify that the callback stops after a custom BaseTerminator.should_terminate condition.IntersectionSearchSpace.calculate(study) returns {} after trials use the same parameter name with different distributions, while also filtering expected ExperimentalWarning noise.