mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-11 12:30:25 +08:00
Update visual regression test
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user