Add Result.extra for arbitrary attributes + flexible objective classes (MinimizeAttribute/MaximizeAttribute) - #171
Merged
Conversation
…dd MinimizeAttribute/MaximizeAttribute (works with built-ins or extra keys); docs+example; bump DB version to 0.1; tests
jansel
approved these changes
Aug 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Result.extradict for attaching custom per-result attributes without schema changes.MinimizeAttributeandMaximizeAttributeobjectives that can optimize on any built-inResultfield or a key inResult.extra.Motivation
Today, adding a new metric requires modifying the
Resultmodel or using a sidecar table. This PR makes it simple and first-class to attach arbitrary attributes to results and use them directly as optimization metrics.What’s changed
Result.extra:MutableDict-backedPickleTypeto store arbitrary attributes.set_attribute(),get_attribute(),update_attributes().MinimizeAttribute(attribute_name, missing_value=None)MaximizeAttribute(attribute_name, missing_value=None)attribute_nameis a concrete column (e.g.,time,accuracy), ordering is done in SQL; otherwise, comparison uses values fromResult.extra.examples/py_api/custom_metric_example.py: Demonstrates optimizing a customqpsmetric viaMaximizeAttribute.tests/test_custom_metric.py: Verifiesextrahelpers and attribute objectives.DB_VERSIONbumped to0.1.Usage
Attach metrics:
Optimize built-ins or custom metrics:
Example
See
examples/py_api/custom_metric_example.pyfor a runnable script optimizing a syntheticqpsmetric inResult.extra.Backward compatibility
Database migration
Testing
tests/test_custom_metric.py.declarative_base).Quick start in a venv:
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt -r optional-requirements.txt pytest -qFiles changed
opentuner/resultsdb/models.py: addResult.extra, helper methodsopentuner/search/objective.py: addMinimizeAttribute,MaximizeAttributeopentuner/resultsdb/connect.py: bumpDB_VERSIONto0.1examples/py_api/custom_metric_example.py: new exampletests/test_custom_metric.py: new testsREADME.md: docs section and examplesCHANGES.txt: changelog entryNotes and robustness considerations
MutableDictensures in-place updates onResult.extraare tracked by SQLAlchemy without reassigning the dict.result_relative()to integrate with existing relative comparisons.declarative_baseis pre-existing and unrelated to this change.Checklist