feat(iterate2): support per-metric direction (minimize/maximize)#316
Merged
Conversation
- Add _default_direction() heuristic: metrics containing loss/error/err/mse/mae/rmse default to minimize, all others to maximize
- Extend load_metrics() to return (names, directions) tuple; accept both simple string form and extended {name, direction} dict form in the YAML metrics: section
- Remove hardcoded ['maximize'] * len(metrics) in main(); use directions from load_metrics() instead
- Log directions at startup
- Update docs/iterate2.md with new Metric directions subsection
Signed-off-by: Romeo Kienzler <romeo.kienzler1@ibm.com>
693c2ee to
344eeac
Compare
- Replace broken 'python ./run_tests.py' (LSF/bsub job submitter, not runnable in GitHub Actions) with 'pytest tests/unit/test_iterate2.py' - Install pytest, pyyaml, optuna and the package itself (--no-deps) so the test module can be imported without a ModuleNotFoundError for yaml Signed-off-by: Romeo Kienzler <romeo.kienzler1@ibm.com>
MatteoZanotto
approved these changes
Jun 29, 2026
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
Adds support for specifying whether each metric should be minimized or maximized in
iterate2. Previously all metrics were unconditionally maximized.Changes
terratorch_iterate/iterate2/_iterate2.py_default_direction(metric_name)— new heuristic helper: metrics whose name containsloss,error,err,mse,mae, orrmsedefault tominimize; all others default tomaximize.load_metrics()— now returns(names, directions)tuple. Themetrics:YAML key now accepts two forms:{name: ..., direction: minimize|maximize}— explicit per-metric controlValueError.main()— unpacks the tuple and passes the real directions tooptuna.create_study()instead of the hardcoded["maximize"] * len(metrics).docs/iterate2.mdYAML usage
Simple form (direction inferred from name):
Extended form (explicit per-metric):
Mixed form is also supported.