1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-18 18:04:31 +08:00

Fix log object bug (#977)

This commit is contained in:
you-n-g
2022-03-14 17:33:13 +08:00
committed by GitHub
parent 776b0c5bb4
commit 2681c61c60
3 changed files with 7 additions and 4 deletions

View File

@@ -96,11 +96,12 @@ class RecordTemp:
""" """
try: try:
return self.recorder.load_object(self.get_path(name)) return self.recorder.load_object(self.get_path(name))
except LoadObjectError: except LoadObjectError as e:
if parents: if parents:
if self.depend_cls is not None: if self.depend_cls is not None:
with class_casting(self, self.depend_cls): with class_casting(self, self.depend_cls):
return self.load(name, parents=True) return self.load(name, parents=True)
raise e
def list(self): def list(self):
""" """

View File

@@ -347,17 +347,17 @@ class MLflowRecorder(Recorder):
""" """
assert self.uri is not None, "Please start the experiment and recorder first before using recorder directly." assert self.uri is not None, "Please start the experiment and recorder first before using recorder directly."
path = None
try: try:
path = self.client.download_artifacts(self.id, name) path = self.client.download_artifacts(self.id, name)
with Path(path).open("rb") as f: with Path(path).open("rb") as f:
data = unpickler(f).load() data = unpickler(f).load()
return data return data
except Exception as e: except Exception as e:
logger.exception(f"Fail to load data '{name}'")
raise LoadObjectError(str(e)) from e raise LoadObjectError(str(e)) from e
finally: finally:
ar = self.client._tracking_client._get_artifact_repo(self.id) ar = self.client._tracking_client._get_artifact_repo(self.id)
if isinstance(ar, AzureBlobArtifactRepository): if isinstance(ar, AzureBlobArtifactRepository) and path is not None:
# for saving disk space # for saving disk space
# For safety, only remove redundant file for specific ArtifactRepository # For safety, only remove redundant file for specific ArtifactRepository
shutil.rmtree(Path(path).absolute().parent) shutil.rmtree(Path(path).absolute().parent)

View File

@@ -10,6 +10,7 @@ from qlib.log import TimeInspector
from typing import Callable, Dict, Iterable, List from typing import Callable, Dict, Iterable, List
from qlib.log import get_module_logger from qlib.log import get_module_logger
from qlib.utils.serial import Serializable from qlib.utils.serial import Serializable
from qlib.utils.exceptions import LoadObjectError
from qlib.workflow import R from qlib.workflow import R
from qlib.workflow.exp import Experiment from qlib.workflow.exp import Experiment
from qlib.workflow.recorder import Recorder from qlib.workflow.recorder import Recorder
@@ -228,9 +229,10 @@ class RecorderCollector(Collector):
else: else:
try: try:
artifact = rec.load_object(self.artifacts_path[key]) artifact = rec.load_object(self.artifacts_path[key])
except Exception as e: except LoadObjectError as e:
if only_exist: if only_exist:
# only collect existing artifact # only collect existing artifact
logger.warning(f"Fail to load {self.artifacts_path[key]} and it is ignored.")
continue continue
raise e raise e
# give user some warning if the values are overridden # give user some warning if the values are overridden