mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-09 11:28:14 +08:00
Merge branch 'main' into preferential-best-trials
This commit is contained in:
@@ -1,19 +1,43 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
import optuna
|
||||
from optuna_dashboard._serializer import serialize_attrs
|
||||
from optuna_dashboard._serializer import serialize_study_detail
|
||||
from optuna_dashboard._storage import get_study_summaries
|
||||
from optuna_dashboard.preferential import create_study
|
||||
|
||||
|
||||
class SerializeAttrsTestCase(TestCase):
|
||||
def test_serialize_bytes(self) -> None:
|
||||
serialized = serialize_attrs({"bytes": b"This is a bytes object."})
|
||||
self.assertEqual(serialized[0]["value"], "<binary object>")
|
||||
def test_serialize_bytes() -> None:
|
||||
serialized = serialize_attrs({"bytes": b"This is a bytes object."})
|
||||
assert serialized[0]["value"] == "<binary object>"
|
||||
|
||||
def test_serialize_dict(self) -> None:
|
||||
serialized = serialize_attrs(
|
||||
{
|
||||
"key": {"foo": "bar"},
|
||||
}
|
||||
)
|
||||
self.assertLessEqual(len(serialized), 1)
|
||||
|
||||
def test_serialize_dict() -> None:
|
||||
serialized = serialize_attrs(
|
||||
{
|
||||
"key": {"foo": "bar"},
|
||||
}
|
||||
)
|
||||
assert len(serialized) <= 1
|
||||
|
||||
|
||||
def test_get_study_detail_is_preferential() -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
study = create_study(storage=storage)
|
||||
study_summaries = get_study_summaries(storage)
|
||||
assert len(study_summaries) == 1
|
||||
|
||||
study_summary = study_summaries[0]
|
||||
study_detail = serialize_study_detail(study_summary, [], study.trials, [], [], [], False)
|
||||
assert study_detail["is_preferential"]
|
||||
|
||||
|
||||
def test_get_study_detail_is_not_preferential() -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
study = optuna.create_study(storage=storage)
|
||||
study_summaries = get_study_summaries(storage)
|
||||
assert len(study_summaries) == 1
|
||||
|
||||
study_summary = study_summaries[0]
|
||||
study_detail = serialize_study_detail(study_summary, [], study.trials, [], [], [], False)
|
||||
assert not study_detail["is_preferential"]
|
||||
|
||||
@@ -6,12 +6,21 @@ from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
from bottle import Bottle
|
||||
from optuna_dashboard._storage import trials_cache
|
||||
from optuna_dashboard._storage import trials_cache_lock
|
||||
from optuna_dashboard._storage import trials_last_fetched_at
|
||||
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from _typeshed.wsgi import WSGIEnvironment
|
||||
|
||||
|
||||
def clear_inmemory_cache() -> None:
|
||||
with trials_cache_lock:
|
||||
trials_cache.clear()
|
||||
trials_last_fetched_at.clear()
|
||||
|
||||
|
||||
def create_wsgi_env(
|
||||
path: str,
|
||||
method: str,
|
||||
@@ -66,6 +75,8 @@ def send_request(
|
||||
headers = headers or {}
|
||||
queries = queries or {}
|
||||
env = create_wsgi_env(path, method, content_type, bytes_body, queries, headers)
|
||||
|
||||
clear_inmemory_cache()
|
||||
response_body = b""
|
||||
iterable_body = app(env, start_response)
|
||||
for b in iterable_body:
|
||||
|
||||
Reference in New Issue
Block a user