Skip to content

Commit

Permalink
Update np.Inf -> np.inf per numpy 2.0 release (#2527)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2527

Numpy 2.0 was released yesterday ([post](https://numpy.org/news/#numpy-20-release-date-june-16)) and accordingly a couple of tests started breaking due to usage of a now-outdated API. This updates references to the now-deprecated `np.Inf` to `np.inf`, which is available in both old and new versions of numpy and so shouldn't create any issues.

Our early-stopping tutorial is still breaking due to a similar issue in TensorBoard (tensorflow/tensorboard#6869), so not all tests are expected to pass as of now.

Reviewed By: mpolson64

Differential Revision: D58672474

fbshipit-source-id: 717b751ac9608867976923bc60ecb5656cc36e08
  • Loading branch information
Bernie Beckerman authored and facebook-github-bot committed Jun 17, 2024
1 parent ffd5b77 commit ae28cb1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ax/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def best_feasible_objective(
objective = optimization_config.objective
f = values[objective.metric.name]
# Set infeasible points to have infinitely bad values
infeas_val = np.Inf if objective.minimize else -np.Inf
infeas_val = np.inf if objective.minimize else -np.inf
for oc in optimization_config.outcome_constraints:
if oc.relative:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions ax/models/discrete/thompson.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ def _produce_samples(
objective_values = np.dot(
samples_per_metric, objective_weights
) # (k x num_samples)
objective_values[any_violation] = -np.Inf
objective_values[any_violation] = -np.inf
best_arm = objective_values.max(axis=0) # (num_samples,)
all_arms_infeasible = best_arm == -np.Inf # (num_samples,)
all_arms_infeasible = best_arm == -np.inf # (num_samples,)
fraction_all_infeasible = all_arms_infeasible.mean()
filtered_objective = objective_values[:, ~all_arms_infeasible] # (k x ?)
return filtered_objective, fraction_all_infeasible
Expand Down
4 changes: 2 additions & 2 deletions ax/models/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,15 @@ def best_in_sample_point(
# Identify best point
if method == "feasible_threshold":
utility = obj
utility[pfeas < threshold] = -np.Inf
utility[pfeas < threshold] = -np.inf
elif method == "max_utility":
if B is None:
B = obj.min()
utility = (obj - B) * pfeas
else: # pragma: no cover
raise UnsupportedError(f"Unknown best point method {method}.")
i = np.argmax(utility)
if utility[i] == -np.Inf:
if utility[i] == -np.inf:
return None
else:
return X_obs[i, :], utility[i]
Expand Down

0 comments on commit ae28cb1

Please sign in to comment.