-
-
Notifications
You must be signed in to change notification settings - Fork 88
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 #540 from c-bata/optuna-artifact-support
Support optuna's artifact metadata
- Loading branch information
Showing
8 changed files
with
264 additions
and
37 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
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,39 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
|
||
if TYPE_CHECKING: | ||
from typing import BinaryIO | ||
from typing import TypeGuard | ||
|
||
from optuna.artifacts._protocol import ArtifactStore | ||
|
||
from .protocol import ArtifactBackend | ||
|
||
|
||
def is_artifact_backend(store: ArtifactBackend | ArtifactStore) -> TypeGuard[ArtifactBackend]: | ||
return getattr(store, "open_reader", None) is None | ||
|
||
|
||
def to_artifact_store(store: ArtifactBackend | ArtifactStore) -> ArtifactStore: | ||
if is_artifact_backend(store): | ||
return ArtifactBackendToStore(store) | ||
# mypy cannot infer the type of `store` here. | ||
return store # type: ignore | ||
|
||
|
||
class ArtifactBackendToStore: | ||
"""Converts a Dashboard's ArtifactBackend to Optuna's ArtifactStore.""" | ||
|
||
def __init__(self, artifact_backend: ArtifactBackend) -> None: | ||
self._backend = artifact_backend | ||
|
||
def open_reader(self, artifact_id: str) -> BinaryIO: | ||
return self._backend.open(artifact_id) | ||
|
||
def write(self, artifact_id: str, content_body: BinaryIO) -> None: | ||
self._backend.write(artifact_id, content_body) | ||
|
||
def remove(self, artifact_id: str) -> None: | ||
self._backend.remove(artifact_id) |
Oops, something went wrong.