Add black settings

This commit is contained in:
c-bata
2022-06-08 16:00:21 +09:00
parent 552fa31cf6
commit 48c30d5955
11 changed files with 48 additions and 75 deletions
+4 -12
View File
@@ -146,9 +146,7 @@ def get_study_summary(storage: BaseStorage, study_id: int) -> Optional[StudySumm
return None
def get_trials(
storage: BaseStorage, study_id: int, ttl_seconds: int = 10
) -> List[FrozenTrial]:
def get_trials(storage: BaseStorage, study_id: int, ttl_seconds: int = 10) -> List[FrozenTrial]:
with trials_cache_lock:
trials = trials_cache.get(study_id, None)
last_fetched_at = trials_last_fetched_at.get(study_id, None)
@@ -247,9 +245,7 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle:
storage.set_study_directions(
study_id,
[
StudyDirection.MAXIMIZE
if d.lower() == "maximize"
else StudyDirection.MINIMIZE
StudyDirection.MAXIMIZE if d.lower() == "maximize" else StudyDirection.MINIMIZE
for d in directions
],
)
@@ -311,15 +307,11 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle:
return {"reason": f"study_id={study_id} is not found"}
if objective_id >= n_directions:
response.status = 400 # Bad request
return {
"reason": f"study_id={study_id} has only {n_directions} direction(s)."
}
return {"reason": f"study_id={study_id} has only {n_directions} direction(s)."}
trials = get_trials(storage, study_id)
try:
return get_param_importance_from_trials_cache(
storage, study_id, objective_id, trials
)
return get_param_importance_from_trials_cache(storage, study_id, objective_id, trials)
except ValueError as e:
response.status = 400 # Bad request
return {"reason": str(e)}
@@ -25,9 +25,7 @@ def get_cached_extra_study_property(
study_id: int, trials: List[FrozenTrial]
) -> Tuple[SearchSpaceListT, SearchSpaceListT, bool]:
with cached_extra_study_property_cache_lock:
cached_extra_study_property = cached_extra_study_property_cache.get(
study_id, None
)
cached_extra_study_property = cached_extra_study_property_cache.get(study_id, None)
if cached_extra_study_property is None:
cached_extra_study_property = _CachedExtraStudyProperty()
cached_extra_study_property.update(trials)
+1 -3
View File
@@ -81,9 +81,7 @@ def main() -> None:
parser.add_argument(
"--port", help="port number (default: %(default)s)", type=int, default=8080
)
parser.add_argument(
"--host", help="hostname (default: %(default)s)", default="127.0.0.1"
)
parser.add_argument("--host", help="hostname (default: %(default)s)", default="127.0.0.1")
parser.add_argument(
"--server",
help="server (default: %(default)s)",
+2 -6
View File
@@ -31,9 +31,7 @@ def get_note_from_system_attrs(system_attrs: Dict[str, Any]) -> NoteType:
}
note_ver = int(system_attrs[NOTE_VER_KEY])
note_attrs: Dict[str, str] = {
key: value
for key, value in system_attrs.items()
if key.startswith(NOTE_STR_KEY_PREFIX)
key: value for key, value in system_attrs.items() if key.startswith(NOTE_STR_KEY_PREFIX)
}
return {"version": note_ver, "body": concat_body(note_attrs)}
@@ -72,6 +70,4 @@ def split_body(note_str: str) -> Dict[str, str]:
def concat_body(note_attrs: Dict[str, str]) -> str:
return "".join(
note_attrs[f"{NOTE_STR_KEY_PREFIX}{i}"] for i in range(len(note_attrs))
)
return "".join(note_attrs[f"{NOTE_STR_KEY_PREFIX}{i}"] for i in range(len(note_attrs)))
+2 -6
View File
@@ -80,9 +80,7 @@ def serialize_study_detail(
if summary.datetime_start is not None:
serialized["datetime_start"] = summary.datetime_start.isoformat()
serialized["trials"] = [
serialize_frozen_trial(summary._study_id, trial) for trial in trials
]
serialized["trials"] = [serialize_frozen_trial(summary._study_id, trial) for trial in trials]
serialized["intersection_search_space"] = serialize_search_space(intersection)
serialized["union_search_space"] = serialize_search_space(union)
serialized["has_intermediate_values"] = has_intermediate_values
@@ -96,9 +94,7 @@ def serialize_frozen_trial(study_id: int, trial: FrozenTrial) -> Dict[str, Any]:
"study_id": study_id,
"number": trial.number,
"state": trial.state.name.capitalize(),
"params": [
{"name": name, "value": str(value)} for name, value in trial.params.items()
],
"params": [{"name": name, "value": str(value)} for name, value in trial.params.items()],
"user_attrs": serialize_attrs(trial.user_attrs),
"system_attrs": serialize_attrs(trial.system_attrs),
}
+1 -2
View File
@@ -8,9 +8,8 @@ from typing import TYPE_CHECKING
from bottle import Bottle
from bottle import SimpleTemplate
from optuna.storages import RDBStorage
from sqlalchemy import event
from optuna_dashboard._app import BottleView
from sqlalchemy import event
if TYPE_CHECKING:
+26
View File
@@ -0,0 +1,26 @@
[tool.black]
line-length = 99
target-version = ['py38']
exclude = '''
/(
\.eggs
| \.git
| \.mypy_cache
| \.tox
| \.venv
| _build
| build
| dist
| venv
)/
'''
[tool.isort]
profile = 'black'
src_paths = ['optuna', 'tests', 'docs', 'benchmarks']
skip_glob = ['docs/source/conf.py', '**/alembic/versions/*.py', 'tutorial/**/*.py']
line_length = 99
lines_after_imports = 2
force_single_line = 'True'
force_sort_within_sections = 'True'
order_by_type = 'False'
+1 -2
View File
@@ -6,9 +6,8 @@ import optuna
from optuna.storages import BaseStorage
from optuna.study import StudySummary
from optuna.version import __version__ as optuna_ver
from packaging import version
from optuna_dashboard._app import create_app
from packaging import version
from .wsgi_client import send_request
@@ -9,7 +9,6 @@ from optuna.distributions import BaseDistribution
from optuna.distributions import UniformDistribution
from optuna.exceptions import ExperimentalWarning
from optuna.trial import TrialState
from optuna_dashboard._cached_extra_study_property import _CachedExtraStudyProperty
-11
View File
@@ -56,14 +56,3 @@ exclude = venv,build,.tox
[mypy]
ignore_missing_imports = True
disallow_untyped_defs = True
[isort]
profile = black
src_paths =
optuna_dashboard
python_tests
line_length = 99
lines_after_imports = 2
force_single_line = True
force_sort_within_sections = True
order_by_type = False
+10 -29
View File
@@ -10,41 +10,28 @@ from wsgiref.simple_server import make_server
import optuna
from optuna.version import __version__ as optuna_ver
from optuna_dashboard import wsgi
from packaging import version
from pyppeteer import launch
from pyppeteer.page import Page
from optuna_dashboard import wsgi
parser = argparse.ArgumentParser()
parser.add_argument(
"--port", help="port number (default: %(default)s)", type=int, default=8081
)
parser.add_argument(
"--host", help="hostname (default: %(default)s)", default="127.0.0.1"
)
parser.add_argument("--port", help="port number (default: %(default)s)", type=int, default=8081)
parser.add_argument("--host", help="hostname (default: %(default)s)", default="127.0.0.1")
parser.add_argument(
"--sleep",
help="sleep seconds on each page open (default: %(default)s)",
type=int,
default=5,
)
parser.add_argument(
"--output-dir", help="output directory (default: %(default)s)", default="tmp"
)
parser.add_argument(
"--width", help="window width (default: %(default)s)", type=int, default=1000
)
parser.add_argument("--output-dir", help="output directory (default: %(default)s)", default="tmp")
parser.add_argument("--width", help="window width (default: %(default)s)", type=int, default=1000)
parser.add_argument(
"--height", help="window height (default: %(default)s)", type=int, default=3000
)
parser.add_argument(
"--storage", help="storage url (default: %(default)s)", default=None
)
parser.add_argument(
"--skip-screenshot", help="skip to take screenshot", action="store_true"
)
parser.add_argument("--storage", help="storage url (default: %(default)s)", default=None)
parser.add_argument("--skip-screenshot", help="skip to take screenshot", action="store_true")
args = parser.parse_args()
@@ -62,9 +49,7 @@ def create_dummy_storage() -> optuna.storages.InMemoryStorage:
study.optimize(objective_single, n_trials=50)
# Single-objective study with 1 parameter
study = optuna.create_study(
study_name="single-1-param", storage=storage, direction="maximize"
)
study = optuna.create_study(study_name="single-1-param", storage=storage, direction="maximize")
def objective_single_with_1param(trial: optuna.Trial) -> float:
x1 = trial.suggest_float("x1", 0, 10)
@@ -73,9 +58,7 @@ def create_dummy_storage() -> optuna.storages.InMemoryStorage:
study.optimize(objective_single_with_1param, n_trials=50)
# Single-objective study with dynamic search space
study = optuna.create_study(
study_name="single-dynamic", storage=storage, direction="maximize"
)
study = optuna.create_study(study_name="single-dynamic", storage=storage, direction="maximize")
def objective_single_dynamic(trial: optuna.Trial) -> float:
category = trial.suggest_categorical("category", ["foo", "bar"])
@@ -139,9 +122,7 @@ def create_dummy_storage() -> optuna.storages.InMemoryStorage:
study.optimize(objective_multi_dynamic, n_trials=50)
# Pruning with no intermediate values
study = optuna.create_study(
study_name="single-pruned-without-report", storage=storage
)
study = optuna.create_study(study_name="single-pruned-without-report", storage=storage)
def objective_prune_without_report(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", -15, 30)