You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems as though if there exists pruned trials within the independent sample... those trials don't have values obviously. This causes "zip(trial.values, study.directions)" to return the error "TypeError: 'NoneType' object is not iterable".
[W 2024-02-19 13:30:42,152] Trial 51 failed with value None.
Traceback (most recent call last):
File "/demos/optuna_bug.py", line 28, in<module>
study.optimize(objective, n_trials=100)
File "/demo/.venv/lib/python3.10/site-packages/optuna/study/study.py", line 451, in optimize
_optimize(
File "/demo/.venv/lib/python3.10/site-packages/optuna/study/_optimize.py", line 66, in _optimize
_optimize_sequential(
File "/demo/.venv/lib/python3.10/site-packages/optuna/study/_optimize.py", line 163, in _optimize_sequential
frozen_trial = _run_trial(study, func, catch)
File "/demo/.venv/lib/python3.10/site-packages/optuna/study/_optimize.py", line 251, in _run_trial
raise func_err
File "/demo/.venv/lib/python3.10/site-packages/optuna/study/_optimize.py", line 200, in _run_trial
value_or_values = func(trial)
File "/home/patrick/source/Research/strat_dev/demos/optuna_bug.py", line 6, in objective
x = trial.suggest_int("x", -10, 1000)
File "/demo/.venv/lib/python3.10/site-packages/optuna/_convert_positional_args.py", line 83, in converter_wrapper
return func(**kwargs)
File "/demo/.venv/lib/python3.10/site-packages/optuna/trial/_trial.py", line 326, in suggest_int
suggested_value = int(self._suggest(name, distribution))
File "/demo/.venv/lib/python3.10/site-packages/optuna/trial/_trial.py", line 635, in _suggest
param_value = self.study.sampler.sample_independent(
File "/demo/.venv/lib/python3.10/site-packages/optuna/samplers/_tpe/sampler.py", line 447, in sample_independent
return self._sample(study, trial, {param_name: param_distribution})[param_name]
File "/demo/.venv/lib/python3.10/site-packages/optuna/samplers/_tpe/sampler.py", line 490, in _sample
weights_below = _calculate_weights_below_for_multi_objective(
File "/demo/.venv/lib/python3.10/site-packages/optuna/samplers/_tpe/sampler.py", line 778, in _calculate_weights_below_for_multi_objective
forvalue, directionin zip(trial.values, study.directions):
TypeError: 'NoneType' object is not iterable
Steps to reproduce
Setup a muli-objective study
Specify a TPESampler for the study
Prune trials within startup trials
importoptunafromoptuna.samplersimportTPESamplerimportnumpyasnpdefobjective(trial):
x=trial.suggest_int("x", -10, 1000)
y=trial.suggest_int("y", -10, 1000)
# Simulated objective function# Here, we'll try to maximize two objectives, and we'll add some artificial pruningvalue1=np.sin(x) *np.cos(y)
value2=np.cos(x) *np.sin(y)
# Prune some trials to simulate a scenario with pruned trialsiftrial.number>4:
raiseoptuna.exceptions.TrialPruned()
returnvalue1, value2,
# Create an in-memory storagestorage=optuna.storages.InMemoryStorage()
# Create a study with the multi-objective samplerstudy=optuna.create_study(storage=storage, directions=['maximize', 'maximize'], sampler=TPESampler())
# Optimize the studystudy.optimize(objective, n_trials=100)
Additional context (optional)
No response
The text was updated successfully, but these errors were encountered:
patrickbritz
added
the
bug
Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.
label
Feb 19, 2024
Thank you for reporting this. I don't think this usage is expected because pruners do not support multi-objective study due to trial.report's restriction. So I'm not sure this is a bug, but at least this should be documented somewhere.
Expected behavior
It seems as though if there exists pruned trials within the independent sample... those trials don't have values obviously. This causes "zip(trial.values, study.directions)" to return the error "TypeError: 'NoneType' object is not iterable".
Environment
Error messages, stack traces, or logs
Steps to reproduce
Additional context (optional)
No response
The text was updated successfully, but these errors were encountered: