Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update QlibRecorder wrapper
  • Loading branch information
Derek-Wds committed Jun 15, 2021
commit 9e0e2ff7362989b2267702d20dfc013bc753f78b
23 changes: 21 additions & 2 deletions qlib/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,33 @@ def set_tags(self, **kwargs):
self.get_exp().get_recorder().set_tags(**kwargs)


# error type for reinitialization when starting an experiment
class RecorderInitializationError(Exception):
def __init__(self, message):
super(RecorderInitializationError, self).__init__(message)


class RecorderWrapper(Wrapper):
"""
Wrapper class for QlibRecorder, which detects whether users reinitialize qlib when already starting an experiment.
"""

def register(self, provider):
if self._provider is not None:
raise RecorderInitializationError(
"Please don't reinitialize Qlib if QlibRecorder is already acivated. Otherwise, the experiment stored location will be modified."
)
self._provider = provider


import sys

if sys.version_info >= (3, 9):
from typing import Annotated

QlibRecorderWrapper = Annotated[QlibRecorder, Wrapper]
QlibRecorderWrapper = Annotated[QlibRecorder, RecorderWrapper]
else:
QlibRecorderWrapper = QlibRecorder

# global record
R: QlibRecorderWrapper = Wrapper()
R: QlibRecorderWrapper = RecorderWrapper()