1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-13 15:56:57 +08:00

OnlineServing V9

This commit is contained in:
lzh222333
2021-04-29 04:30:09 +00:00
parent 6f669348a8
commit 67c5740c83
19 changed files with 677 additions and 1010 deletions

View File

@@ -1,9 +1,11 @@
from abc import abstractmethod
from typing import Callable, Union
from qlib import init
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Collector can collect object from everywhere and process them such as merging, grouping, averaging and so on.
"""
from qlib.workflow import R
from qlib.workflow.task.utils import list_recorders
from qlib.utils.serial import Serializable
import dill as pickle
@@ -19,7 +21,7 @@ class Collector:
process_list = [process_list]
self.process_list = process_list
def collect(self):
def collect(self) -> dict:
"""Collect the results and return a dict like {key: things}
Returns:
@@ -36,7 +38,7 @@ class Collector:
raise NotImplementedError(f"Please implement the `collect` method.")
@staticmethod
def process_collect(collected_dict, process_list=[], *args, **kwargs):
def process_collect(collected_dict, process_list=[], *args, **kwargs) -> dict:
"""do a series of processing to the dict returned by collect and return a dict like {key: things}
For example: you can group and ensemble.
@@ -61,7 +63,7 @@ class Collector:
result[artifact] = value
return result
def __call__(self, *args, **kwargs):
def __call__(self, *args, **kwargs) -> dict:
"""
do the workflow including collect and process_collect
@@ -124,7 +126,7 @@ class HyperCollector(Collector):
super().__init__(process_list=process_list)
self.collector_dict = collector_dict
def collect(self):
def collect(self) -> dict:
collect_dict = {}
for key, collector in self.collector_dict.items():
collect_dict[key] = collector()
@@ -153,10 +155,10 @@ class RecorderCollector(Collector):
artifacts_path (dict, optional): The artifacts name and its path in Recorder. Defaults to {"pred": "pred.pkl", "IC": "sig_analysis/ic.pkl"}.
artifacts_key (str or List, optional): the artifacts key you want to get. If None, get all artifacts.
"""
super().__init__(process_list=process_list)
if isinstance(experiment, str):
experiment = R.get_exp(experiment_name=experiment)
self.experiment = experiment
self.process_list = process_list
self.artifacts_path = artifacts_path
if rec_key_func is None:
rec_key_func = lambda rec: rec.info["id"]
@@ -166,7 +168,7 @@ class RecorderCollector(Collector):
self.artifacts_key = artifacts_key
self._rec_filter_func = rec_filter_func
def collect(self, artifacts_key=None, rec_filter_func=None):
def collect(self, artifacts_key=None, rec_filter_func=None) -> dict:
"""Collect different artifacts based on recorder after filtering.
Args:
@@ -203,5 +205,11 @@ class RecorderCollector(Collector):
return collect_dict
def get_exp_name(self):
def get_exp_name(self) -> str:
"""
Get experiment name
Returns:
str: experiment name
"""
return self.experiment.name