Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ax/analysis/plotly/tests/test_utility_progression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

# pyre-strict

import math
from unittest.mock import patch

from ax.analysis.plotly.plotly_analysis import PlotlyAnalysisCard
from ax.analysis.plotly.utility_progression import UtilityProgressionAnalysis
from ax.core.auxiliary import AuxiliaryExperiment, AuxiliaryExperimentPurpose
from ax.core.metric import Metric
from ax.core.objective import MultiObjective, Objective
from ax.core.optimization_config import PreferenceOptimizationConfig
from ax.exceptions.core import ExperimentNotReadyError
from ax.utils.common.testutils import TestCase
from ax.utils.testing.core_stubs import (
get_branin_experiment,
Expand Down Expand Up @@ -199,3 +203,18 @@ def test_scalarized_objective_support(self) -> None:

# Assert: Check that title/subtitle show the formula
self.assertIn("formula:", card.subtitle)

def test_all_infeasible_points_raises_error(self) -> None:
"""Test that an error is raised when all points are infeasible."""
experiment = get_branin_experiment(with_completed_trial=True)

with (
patch(
"ax.analysis.plotly.utility_progression.get_trace",
return_value=[math.inf, -math.inf, math.inf],
),
self.assertRaises(ExperimentNotReadyError) as cm,
):
self.analysis.compute(experiment=experiment)

self.assertIn("infeasible", str(cm.exception).lower())
8 changes: 8 additions & 0 deletions ax/analysis/plotly/utility_progression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from typing import final

import numpy as np
import pandas as pd
import plotly.express as px
from ax.adapter.base import Adapter
Expand Down Expand Up @@ -113,6 +114,13 @@ def compute(
"constraints."
)

# Check if all points are infeasible (inf or -inf values)
if all(np.isinf(value) for value in trace):
raise ExperimentNotReadyError(
"All trials in the utility trace are infeasible (violate outcome "
"constraints). No feasible points to plot."
)

# Create DataFrame with 1-based trace index for user-friendly display
# (1st completed trial, 2nd completed trial, etc. instead of 0-indexed)
df = pd.DataFrame(
Expand Down