1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-17 09:24:34 +08:00

Update api

This commit is contained in:
Jactus
2021-04-30 13:27:19 +08:00
parent eab19de080
commit 694ae34027
3 changed files with 23 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ class QlibRecorder:
@contextmanager @contextmanager
def start( def start(
self, self,
*,
experiment_id: Optional[Text] = None, experiment_id: Optional[Text] = None,
experiment_name: Optional[Text] = None, experiment_name: Optional[Text] = None,
recorder_id: Optional[Text] = None, recorder_id: Optional[Text] = None,
@@ -63,7 +64,14 @@ class QlibRecorder:
resume : bool resume : bool
whether to resume the specific recorder with given name under the given experiment. whether to resume the specific recorder with given name under the given experiment.
""" """
run = self.start_exp(experiment_id, experiment_name, recorder_id, recorder_name, uri, resume) run = self.start_exp(
experiment_id=experiment_id,
experiment_name=experiment_name,
recorder_id=recorder_id,
recorder_name=recorder_name,
uri=uri,
resume=resume,
)
try: try:
yield run yield run
except Exception as e: except Exception as e:
@@ -72,7 +80,7 @@ class QlibRecorder:
self.end_exp(Recorder.STATUS_FI) self.end_exp(Recorder.STATUS_FI)
def start_exp( def start_exp(
self, experiment_id=None, experiment_name=None, recorder_id=None, recorder_name=None, uri=None, resume=False self, *, experiment_id=None, experiment_name=None, recorder_id=None, recorder_name=None, uri=None, resume=False
): ):
""" """
Lower level method for starting an experiment. When use this method, one should end the experiment manually Lower level method for starting an experiment. When use this method, one should end the experiment manually
@@ -105,7 +113,14 @@ class QlibRecorder:
------- -------
An experiment instance being started. An experiment instance being started.
""" """
return self.exp_manager.start_exp(experiment_id, experiment_name, recorder_id, recorder_name, uri, resume) return self.exp_manager.start_exp(
experiment_id=experiment_id,
experiment_name=experiment_name,
recorder_id=recorder_id,
recorder_name=recorder_name,
uri=uri,
resume=resume,
)
def end_exp(self, recorder_status=Recorder.STATUS_FI): def end_exp(self, recorder_status=Recorder.STATUS_FI):
""" """

View File

@@ -39,7 +39,7 @@ class Experiment:
output["recorders"] = list(recorders.keys()) output["recorders"] = list(recorders.keys())
return output return output
def start(self, recorder_id=None, recorder_name=None, resume=False): def start(self, *, recorder_id=None, recorder_name=None, resume=False):
""" """
Start the experiment and set it to be active. This method will also start a new recorder. Start the experiment and set it to be active. This method will also start a new recorder.
@@ -240,7 +240,7 @@ class MLflowExperiment(Experiment):
def __repr__(self): def __repr__(self):
return "{name}(id={id}, info={info})".format(name=self.__class__.__name__, id=self.id, info=self.info) return "{name}(id={id}, info={info})".format(name=self.__class__.__name__, id=self.id, info=self.info)
def start(self, recorder_id=None, recorder_name=None, resume=False): def start(self, *, recorder_id=None, recorder_name=None, resume=False):
logger.info(f"Experiment {self.id} starts running ...") logger.info(f"Experiment {self.id} starts running ...")
# Get or create recorder # Get or create recorder
if recorder_name is None: if recorder_name is None:

View File

@@ -33,6 +33,7 @@ class ExpManager:
def start_exp( def start_exp(
self, self,
*,
experiment_id: Optional[Text] = None, experiment_id: Optional[Text] = None,
experiment_name: Optional[Text] = None, experiment_name: Optional[Text] = None,
recorder_id: Optional[Text] = None, recorder_id: Optional[Text] = None,
@@ -304,6 +305,7 @@ class MLflowExpManager(ExpManager):
def start_exp( def start_exp(
self, self,
*,
experiment_id: Optional[Text] = None, experiment_id: Optional[Text] = None,
experiment_name: Optional[Text] = None, experiment_name: Optional[Text] = None,
recorder_id: Optional[Text] = None, recorder_id: Optional[Text] = None,
@@ -320,7 +322,7 @@ class MLflowExpManager(ExpManager):
# Set up active experiment # Set up active experiment
self.active_experiment = experiment self.active_experiment = experiment
# Start the experiment # Start the experiment
self.active_experiment.start(recorder_id, recorder_name, resume) self.active_experiment.start(recorder_id=recorder_id, recorder_name=recorder_name, resume=resume)
return self.active_experiment return self.active_experiment