From b15e5e33fd0d20e24ac52c9397374af27a5bc987 Mon Sep 17 00:00:00 2001 From: Young Date: Mon, 12 Apr 2021 06:33:31 +0000 Subject: [PATCH] Fix the multi-processing bug --- qlib/model/ens/group.py | 8 +++----- qlib/utils/serial.py | 6 ++++-- qlib/workflow/task/collect.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/qlib/model/ens/group.py b/qlib/model/ens/group.py index f5ab5d8a7..c80959b0d 100644 --- a/qlib/model/ens/group.py +++ b/qlib/model/ens/group.py @@ -1,10 +1,9 @@ from qlib.model.ens.ensemble import Ensemble, RollingEnsemble from typing import Callable, Union -from qlib.utils.serial import Serializable from joblib import Parallel, delayed -class Group(Serializable): +class Group: """Group the objects based on dict""" def __init__(self, group_func=None, ens: Ensemble = None): @@ -45,9 +44,8 @@ class Group(Serializable): dict: grouped_dict like {G1: object, G2: object} """ - # FIXME: The multiprocessing will raise the following error - # NotImplementedError: Please specify valid `_ens_func`. - # The problem maybe the state of the function is lost + # NOTE: The multiprocessing will raise error if you use `Serializable` + # Because the `Serializable` will affect the behaviours of pickle grouped_dict = self.group(ungrouped_dict, *args, **kwargs) key_l = [] diff --git a/qlib/utils/serial.py b/qlib/utils/serial.py index b94be464b..1b775d99a 100644 --- a/qlib/utils/serial.py +++ b/qlib/utils/serial.py @@ -7,8 +7,10 @@ import pickle class Serializable: """ - Serializable behaves like pickle. - But it only saves the state whose name **does not** start with `_` + Serializable will change the behaviours of pickle. + - It only saves the state whose name **does not** start with `_` + It provides a syntactic sugar for distinguish the attributes which user doesn't want. + - For examples, a learnable Datahandler just wants to save the parameters without data when dumping to disk """ def __init__(self): diff --git a/qlib/workflow/task/collect.py b/qlib/workflow/task/collect.py index 9bd609670..f651ef8d8 100644 --- a/qlib/workflow/task/collect.py +++ b/qlib/workflow/task/collect.py @@ -4,7 +4,7 @@ from qlib.workflow.task.utils import list_recorders from qlib.utils.serial import Serializable -class Collector(Serializable): +class Collector: """The collector to collect different results""" def collect(self, *args, **kwargs):