1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-16 01:06:56 +08:00

Fix the multi-processing bug

This commit is contained in:
Young
2021-04-12 06:33:31 +00:00
parent cca43cf102
commit b15e5e33fd
3 changed files with 8 additions and 8 deletions

View File

@@ -1,10 +1,9 @@
from qlib.model.ens.ensemble import Ensemble, RollingEnsemble from qlib.model.ens.ensemble import Ensemble, RollingEnsemble
from typing import Callable, Union from typing import Callable, Union
from qlib.utils.serial import Serializable
from joblib import Parallel, delayed from joblib import Parallel, delayed
class Group(Serializable): class Group:
"""Group the objects based on dict""" """Group the objects based on dict"""
def __init__(self, group_func=None, ens: Ensemble = None): def __init__(self, group_func=None, ens: Ensemble = None):
@@ -45,9 +44,8 @@ class Group(Serializable):
dict: grouped_dict like {G1: object, G2: object} dict: grouped_dict like {G1: object, G2: object}
""" """
# FIXME: The multiprocessing will raise the following error # NOTE: The multiprocessing will raise error if you use `Serializable`
# NotImplementedError: Please specify valid `_ens_func`. # Because the `Serializable` will affect the behaviours of pickle
# The problem maybe the state of the function is lost
grouped_dict = self.group(ungrouped_dict, *args, **kwargs) grouped_dict = self.group(ungrouped_dict, *args, **kwargs)
key_l = [] key_l = []

View File

@@ -7,8 +7,10 @@ import pickle
class Serializable: class Serializable:
""" """
Serializable behaves like pickle. Serializable will change the behaviours of pickle.
But it only saves the state whose name **does not** start with `_` - 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): def __init__(self):

View File

@@ -4,7 +4,7 @@ from qlib.workflow.task.utils import list_recorders
from qlib.utils.serial import Serializable from qlib.utils.serial import Serializable
class Collector(Serializable): class Collector:
"""The collector to collect different results""" """The collector to collect different results"""
def collect(self, *args, **kwargs): def collect(self, *args, **kwargs):