-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from xadrianzetx/catch-trial-exc
Add `catch` functionality to distributed study
- Loading branch information
Showing
4 changed files
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
|
||
import optuna | ||
import pytest | ||
|
||
from optuna_distributed.eventloop import EventLoop | ||
from optuna_distributed.managers import LocalOptimizationManager | ||
from optuna_distributed.messages import FailedMessage | ||
from optuna_distributed.trial import DistributedTrial | ||
|
||
|
||
def test_raises_on_trial_exception() -> None: | ||
def _objective(trial: DistributedTrial) -> None: | ||
exception = ValueError() | ||
trial.connection.put(FailedMessage(trial.trial_id, exception, exc_info=sys.exc_info())) | ||
|
||
n_trials = 5 | ||
study = optuna.create_study() | ||
manager = LocalOptimizationManager(n_trials, n_jobs=1) | ||
event_loop = EventLoop(study, manager, objective=_objective) | ||
with pytest.raises(ValueError): | ||
event_loop.run(n_trials, timeout=None) | ||
|
||
|
||
def test_catches_on_trial_exception() -> None: | ||
def _objective(trial: DistributedTrial) -> None: | ||
exception = ValueError() | ||
trial.connection.put(FailedMessage(trial.trial_id, exception, exc_info=sys.exc_info())) | ||
|
||
n_trials = 5 | ||
study = optuna.create_study() | ||
manager = LocalOptimizationManager(n_trials, n_jobs=1) | ||
event_loop = EventLoop(study, manager, objective=_objective) | ||
event_loop.run(n_trials, timeout=None, catch=(ValueError,)) |