Update visual regression test

This commit is contained in:
c-bata
2022-05-25 21:16:38 +09:00
parent 68f7b75e1c
commit f46a1d724d
2 changed files with 17 additions and 8 deletions
+4 -3
View File
@@ -5,20 +5,20 @@ from typing import List
from typing import Tuple
from typing import Union
import numpy as np
from optuna.distributions import BaseDistribution
from optuna.study import StudySummary
from optuna.trial import FrozenTrial
import numpy as np
from . import _note as note
try:
from typing import TypedDict
from typing import Literal
from typing import TypedDict
except ImportError:
from typing_extensions import TypedDict
from typing_extensions import Literal
from typing_extensions import TypedDict
MAX_ATTR_LENGTH = 1024
@@ -125,6 +125,7 @@ def serialize_frozen_trial(study_id: int, trial: FrozenTrial) -> Dict[str, Any]:
elif np.isneginf(value):
serialized_value = "-inf"
else:
assert np.isfinite(value)
serialized_value = value
serialized_intermediate_values.append({"step": step, "value": serialized_value})
serialized["intermediate_values"] = serialized_intermediate_values
+13 -5
View File
@@ -87,13 +87,15 @@ def create_dummy_storage() -> optuna.storages.InMemoryStorage:
study.optimize(objective_single_dynamic, n_trials=50)
# Single objective study with 'inf' value
# Single objective study with 'inf', '-inf', or 'nan' value
study = optuna.create_study(study_name="single-inf", storage=storage)
def objective_single_inf(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", -10, 10)
if x > 0:
return math.inf
if trial.number % 3 == 0:
return float("inf")
elif trial.number % 3 == 1:
return float("-inf")
else:
return x**2
@@ -152,13 +154,19 @@ def create_dummy_storage() -> optuna.storages.InMemoryStorage:
study.optimize(objective_prune_without_report, n_trials=100)
# Single objective pruned after reported 'inf' value
# Single objective pruned after reported 'inf', '-inf', or 'nan'
study = optuna.create_study(study_name="single-inf-report", storage=storage)
def objective_single_inf_report(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", -10, 10)
if trial.number % 3 == 0:
trial.report(float("inf"), 1)
elif trial.number % 3 == 1:
trial.report(float("-inf"), 1)
else:
trial.report(float("nan"), 1)
if x > 0:
trial.report(math.inf, 1)
raise optuna.TrialPruned()
else:
return x**2