You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move metric_name_to_signature from Adapter to Objective/OutcomeConstraint (facebook#5122)
Summary:
Pull Request resolved: facebook#5122
The `metric_name_to_signature` mapping (user-facing metric name -> canonical signature used in data/modeling) previously lived on `Adapter`, built from `experiment.metrics` at init time. This was architecturally awkward because the mapping is consumed alongside `OptimizationConfig` objects (objectives, constraints) throughout adapter_utils, transforms, and cross-validation, but lived on a separate object.
This diff co-locates the mapping with the objects that reference metrics by name:
**Core changes (ax/core):**
- `Objective` and `OutcomeConstraint` now accept an optional `metric_name_to_signature` kwarg, stored as an instance field
- Both classes expose `metric_signatures` and `metric_name_to_signature` properties (with getter and setter)
- `metric_weights` on both classes now returns `(signature, weight)` tuples instead of `(name, weight)`, aligning with how downstream consumers use them
- `OptimizationConfig` aggregates these into `metric_signatures` and `metric_name_to_signature` properties, with a setter that propagates to children
- `clone()` methods preserve the mapping
**Adapter changes (ax/adapter):**
- Removed `Adapter._metric_name_to_signature` field and property
- Removed `metric_name_to_signature` parameter from `adapter_utils.py` functions: `extract_objective_thresholds`, `extract_objective_weights`, `extract_objective_weight_matrix`, `extract_outcome_constraints`, `feasible_hypervolume`
- Removed `metric_name_to_signature` parameter from `has_good_opt_config_model_fit` in `cross_validation.py`
- Removed `metric_name_to_signature` parameter from `validate_transformed_optimization_config` in `torch.py`
- Updated all transforms to use `constraint.metric_signatures` and `objective.metric_signatures` directly instead of looking up through `adapter.metric_name_to_signature`
**Orchestration test fix (ax/orchestration):**
- Updated `test_get_best_trial` in `test_orchestrator.py` to expect `ValueError` instead of `KeyError` when passing a mismatched `OptimizationConfig`. Previously the dict lookup on `metric_name_to_signature` raised `KeyError`; now `outcomes.index()` raises `ValueError`.
**Storage:** No changes needed -- the mapping is not persisted on its own and instead is reconstructed by Experiment initialization.
Reviewed By: saitcakmak
Differential Revision: D98837790
fbshipit-source-id: b4dbef567a1601f7f23909fac8f8f6383cd11b09
0 commit comments