mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-11 12:30:25 +08:00
Merge pull request #769 from c-bata/remove-deprecation-warning
Remove deprecation warning messages
This commit is contained in:
@@ -246,7 +246,7 @@ def serialize_frozen_trial(
|
||||
],
|
||||
"user_attrs": serialize_attrs(trial.user_attrs),
|
||||
"note": note.get_note_from_system_attrs(study_system_attrs, trial._trial_id),
|
||||
"artifacts": list_trial_artifacts(study_system_attrs, trial),
|
||||
"artifacts": list_trial_artifacts(study_system_attrs, trial_system_attrs, trial),
|
||||
"constraints": trial_system_attrs.get(CONSTRAINTS_KEY, []),
|
||||
}
|
||||
|
||||
|
||||
@@ -150,10 +150,12 @@ def register_artifact_route(
|
||||
storage.set_trial_system_attr(trial_id, attr_key, json.dumps(artifact))
|
||||
response.status = 201
|
||||
|
||||
trial = storage.get_trial(trial_id) # Fetch trial.system_attrs again.
|
||||
study_system_attrs = storage.get_study_system_attrs(study_id)
|
||||
trial_system_attrs = storage.get_trial_system_attrs(trial_id)
|
||||
artifacts = list_trial_artifacts(study_system_attrs, trial_system_attrs, trial)
|
||||
return {
|
||||
"artifact_id": artifact_id,
|
||||
"artifacts": list_trial_artifacts(storage.get_study_system_attrs(study_id), trial),
|
||||
"artifacts": artifacts,
|
||||
}
|
||||
|
||||
@app.post("/api/artifacts/<study_id:int>")
|
||||
@@ -333,7 +335,11 @@ def delete_all_artifacts(backend: ArtifactStore, storage: BaseStorage, study_id:
|
||||
study_system_attrs = storage.get_study_system_attrs(study_id)
|
||||
artifact_metas.extend(list_study_artifacts(study_system_attrs))
|
||||
for trial in storage.get_all_trials(study_id):
|
||||
trial_artifacts = list_trial_artifacts(study_system_attrs, trial)
|
||||
trial_system_attrs = getattr(trial, "_system_attrs")
|
||||
if trial_system_attrs is None:
|
||||
# This is unreachable line until Optuna v5.0.0 release.
|
||||
trial_system_attrs = storage.get_trial_system_attrs(trial._trial_id)
|
||||
trial_artifacts = list_trial_artifacts(study_system_attrs, trial_system_attrs, trial)
|
||||
artifact_metas.extend(trial_artifacts)
|
||||
|
||||
for meta in artifact_metas:
|
||||
@@ -350,7 +356,7 @@ def list_study_artifacts(study_system_attrs: dict[str, Any]) -> list[ArtifactMet
|
||||
|
||||
|
||||
def list_trial_artifacts(
|
||||
study_system_attrs: dict[str, Any], trial: FrozenTrial
|
||||
study_system_attrs: dict[str, Any], trial_system_attrs: dict[str, Any], trial: FrozenTrial
|
||||
) -> list[ArtifactMeta]:
|
||||
# Collect ArtifactMeta from study_system_attrs due to backward compatibility.
|
||||
dashboard_artifact_metas = [
|
||||
@@ -364,7 +370,7 @@ def list_trial_artifacts(
|
||||
# See https://github.com/optuna/optuna/blob/f827582a8/optuna/artifacts/_upload.py#L16
|
||||
optuna_artifact_metas = [
|
||||
json.loads(value)
|
||||
for key, value in trial.system_attrs.items()
|
||||
for key, value in trial_system_attrs.items()
|
||||
if key.startswith(ARTIFACTS_ATTR_PREFIX)
|
||||
]
|
||||
artifact_metas = dashboard_artifact_metas + optuna_artifact_metas
|
||||
|
||||
@@ -84,9 +84,12 @@ def test_delete_all_artifacts(init_storage_with_artifact_meta: MagicMock) -> Non
|
||||
|
||||
def test_list_trial_artifacts(init_storage_with_artifact_meta: MagicMock) -> None:
|
||||
storage = init_storage_with_artifact_meta
|
||||
trial = MagicMock(_trial_id=0, system_attrs=storage.get_trial_system_attrs(0))
|
||||
trial_system_attrs = storage.get_trial_system_attrs(0)
|
||||
trial = MagicMock(_trial_id=0, system_attrs={})
|
||||
|
||||
actual = _backend.list_trial_artifacts(storage.get_study_system_attrs(0), trial)
|
||||
actual = _backend.list_trial_artifacts(
|
||||
storage.get_study_system_attrs(0), trial_system_attrs, trial
|
||||
)
|
||||
assert actual == [
|
||||
{"artifact_id": "id0", "filename": "foo.txt"},
|
||||
{"artifact_id": "id1", "filename": "bar.txt"},
|
||||
|
||||
@@ -36,8 +36,11 @@ def test_list_optuna_trial_artifacts() -> None:
|
||||
study.tell(trial, 0.0)
|
||||
|
||||
study_system_attrs = storage.get_study_system_attrs(study._study_id)
|
||||
trial_system_attrs = storage.get_trial_system_attrs(trial._trial_id)
|
||||
frozen_trial = storage.get_trial(trial._trial_id)
|
||||
artifact_meta_list = list_trial_artifacts(study_system_attrs, frozen_trial)
|
||||
artifact_meta_list = list_trial_artifacts(
|
||||
study_system_attrs, trial_system_attrs, frozen_trial
|
||||
)
|
||||
assert len(artifact_meta_list) == 1
|
||||
|
||||
artifact_id = artifact_meta_list[0]["artifact_id"]
|
||||
|
||||
Reference in New Issue
Block a user