Skip to content

Commit

Permalink
exp_tp_df calculate relative metrics after calculating feasibility (f…
Browse files Browse the repository at this point in the history
…acebook#3103)

Summary:
Pull Request resolved: facebook#3103

As titled, move the logic of calculating relative metrics to after calculating feasibility, as feasibility calculation relies on derelativized optimization config + metrics.

Reviewed By: Balandat

Differential Revision: D66319304

fbshipit-source-id: 0a224e3918bc4987942957c6c4bdcc0d175dbde3
  • Loading branch information
Sunny Shen authored and facebook-github-bot committed Nov 22, 2024
1 parent 1c01236 commit 4127865
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions ax/service/utils/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,23 +874,6 @@ def exp_to_df(
metric_names = [m.name for m in metrics]
results = results[results["metric_name"].isin(metric_names)]

# Calculate relative metrics if `show_relative_metrics` is True.
if show_relative_metrics:
if exp.status_quo is None:
logger.warning(
"No status quo arm found. Showing raw metric values instead of "
"relative metric values."
)
else:
status_quo_arm_name = exp.status_quo.name
try:
results = _get_relative_results(results, status_quo_arm_name)
except Exception:
logger.warning(
"Failed to calculate relative metrics. Showing raw metric values "
"instead of relative metric values."
)

# Add `FEASIBLE_COL_NAME` column according to constraints if any.
if (
exp.optimization_config is not None
Expand All @@ -910,6 +893,23 @@ def exp_to_df(
except (KeyError, ValueError, DataRequiredError) as e:
logger.warning(f"Feasibility calculation failed with error: {e}")

# Calculate relative metrics if `show_relative_metrics` is True.
if show_relative_metrics:
if exp.status_quo is None:
logger.warning(
"No status quo arm found. Showing raw metric values instead of "
"relative metric values."
)
else:
status_quo_arm_name = exp.status_quo.name
try:
results = _get_relative_results(results, status_quo_arm_name)
except Exception:
logger.warning(
"Failed to calculate relative metrics. Showing raw metric values "
"instead of relative metric values."
)

# If arms_df is empty, return empty results (legacy behavior)
if len(arms_df.index) == 0:
if len(results.index) != 0:
Expand Down

0 comments on commit 4127865

Please sign in to comment.