Interface change for set_study_directions

This commit is contained in:
gen740
2022-11-28 17:46:58 +09:00
parent 7f279b3a5a
commit c30fe8234f
2 changed files with 13 additions and 14 deletions
+7 -9
View File
@@ -249,19 +249,17 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle:
return {"reason": "You need to set study_name and direction"}
try:
study_id = storage.create_new_study(study_name)
study_id = storage.create_new_study(
study_name,
directions=[
StudyDirection.MAXIMIZE if d.lower() == "maximize" else StudyDirection.MINIMIZE
for d in directions
],
)
except DuplicatedStudyError:
response.status = 400 # Bad request
return {"reason": f"'{study_name}' is already exists"}
storage.set_study_directions(
study_id,
[
StudyDirection.MAXIMIZE if d.lower() == "maximize" else StudyDirection.MINIMIZE
for d in directions
],
)
summary = get_study_summary(storage, study_id)
if summary is None:
response.status = 500 # Internal server error
+6 -5
View File
@@ -2,6 +2,7 @@ import json
from unittest import TestCase
import optuna
from optuna.study import StudyDirection
from optuna import get_all_study_summaries
from optuna_dashboard._app import create_app
@@ -16,8 +17,8 @@ def objective(trial: optuna.trial.Trial) -> float:
class APITestCase(TestCase):
def test_get_study_summaries(self) -> None:
storage = optuna.storages.InMemoryStorage()
storage.create_new_study("foo1")
storage.create_new_study("foo2")
storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE])
storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE])
app = create_app(storage)
status, _, body = send_request(
@@ -126,7 +127,7 @@ class APITestCase(TestCase):
def test_create_study_duplicated(self) -> None:
storage = optuna.storages.InMemoryStorage()
storage.create_new_study("foo")
storage.create_new_study(study_name="foo", directions=[StudyDirection.MINIMIZE])
self.assertEqual(len(get_all_study_summaries(storage)), 1)
app = create_app(storage)
@@ -146,8 +147,8 @@ class APITestCase(TestCase):
def test_delete_study(self) -> None:
storage = optuna.storages.InMemoryStorage()
storage.create_new_study("foo1")
storage.create_new_study("foo2")
storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE])
storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE])
self.assertEqual(len(get_all_study_summaries(storage)), 2)
app = create_app(storage)