diff --git a/qlib/workflow/__init__.py b/qlib/workflow/__init__.py index 678ae99a8a..a036656262 100644 --- a/qlib/workflow/__init__.py +++ b/qlib/workflow/__init__.py @@ -202,13 +202,13 @@ def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True) - no id or name specified, return the active experiment. - - if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given id or name, and the experiment is set to be active. + - if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given id or name. - If `active experiment` not exists: - no id or name specified, create a default experiment, and the experiment is set to be active. - - if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given name or the default experiment, and the experiment is set to be active. + - if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given name or the default experiment. - Else If '`create`' is False: @@ -260,7 +260,7 @@ def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True) ------- An experiment instance with given id or name. """ - return self.exp_manager.get_exp(experiment_id, experiment_name, create) + return self.exp_manager.get_exp(experiment_id, experiment_name, create, start=False) def delete_exp(self, experiment_id=None, experiment_name=None): """ @@ -358,7 +358,7 @@ def get_recorder(self, recorder_id=None, recorder_name=None, experiment_name=Non A recorder instance. """ return self.get_exp(experiment_name=experiment_name, create=False).get_recorder( - recorder_id, recorder_name, create=False + recorder_id, recorder_name, create=False, start=False ) def delete_recorder(self, recorder_id=None, recorder_name=None): diff --git a/qlib/workflow/exp.py b/qlib/workflow/exp.py index 0f420cec49..dd73f7f520 100644 --- a/qlib/workflow/exp.py +++ b/qlib/workflow/exp.py @@ -107,24 +107,24 @@ def delete_recorder(self, recorder_id): """ raise NotImplementedError(f"Please implement the `delete_recorder` method.") - def get_recorder(self, recorder_id=None, recorder_name=None, create: bool = True): + def get_recorder(self, recorder_id=None, recorder_name=None, create: bool = True, start: bool = False): """ Retrieve a Recorder for user. When user specify recorder id and name, the method will try to return the specific recorder. When user does not provide recorder id or name, the method will try to return the current active recorder. The `create` argument determines whether the method will automatically create a new recorder - according to user's specification if the recorder hasn't been created before + according to user's specification if the recorder hasn't been created before. * If `create` is True: * If `active recorder` exists: * no id or name specified, return the active recorder. - * if id or name is specified, return the specified recorder. If no such exp found, create a new recorder with given id or name, and the recorder shoud be active. + * if id or name is specified, return the specified recorder. If no such exp found, create a new recorder with given id or name. If `start` is set to be True, the recorder is set to be active. * If `active recorder` not exists: * no id or name specified, create a new recorder. - * if id or name is specified, return the specified experiment. If no such exp found, create a new recorder with given id or name, and the recorder shoud be active. + * if id or name is specified, return the specified experiment. If no such exp found, create a new recorder with given id or name. If `start` is set to be True, the recorder is set to be active. * Else If `create` is False: @@ -146,6 +146,8 @@ def get_recorder(self, recorder_id=None, recorder_name=None, create: bool = True the name of the recorder to be deleted. create : boolean create the recorder if it hasn't been created before. + start : boolean + start the new recorder if one is created. Returns ------- @@ -163,7 +165,7 @@ def get_recorder(self, recorder_id=None, recorder_name=None, create: bool = True self._get_recorder(recorder_id=recorder_id, recorder_name=recorder_name), False, ) - if is_new: + if is_new and start: self.active_recorder = recorder # start the recorder self.active_recorder.start_run() diff --git a/qlib/workflow/expm.py b/qlib/workflow/expm.py index 28d6d92c77..5275e57d7b 100644 --- a/qlib/workflow/expm.py +++ b/qlib/workflow/expm.py @@ -102,10 +102,9 @@ def search_records(self, experiment_ids=None, **kwargs): """ raise NotImplementedError(f"Please implement the `search_records` method.") - def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True): + def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True, start: bool = False): """ Retrieve an experiment. This method includes getting an active experiment, and get_or_create a specific experiment. - The returned experiment will be active. When user specify experiment id and name, the method will try to return the specific experiment. When user does not provide recorder id or name, the method will try to return the current active experiment. @@ -117,12 +116,12 @@ def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True) * If `active experiment` exists: * no id or name specified, return the active experiment. - * if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given id or name, and the experiment is set to be active. + * if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given id or name. If `start` is set to be True, the experiment is set to be active. * If `active experiment` not exists: * no id or name specified, create a default experiment. - * if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given id or name, and the experiment is set to be active. + * if id or name is specified, return the specified experiment. If no such exp found, create a new experiment with given id or name. If `start` is set to be True, the experiment is set to be active. * Else If `create` is False: @@ -144,6 +143,8 @@ def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True) name of the experiment to return. create : boolean create the experiment it if hasn't been created before. + start : boolean + start the new experiment if one is created. Returns ------- @@ -163,7 +164,7 @@ def get_exp(self, experiment_id=None, experiment_name=None, create: bool = True) self._get_exp(experiment_id=experiment_id, experiment_name=experiment_name), False, ) - if is_new: + if is_new and start: self.active_experiment = exp # start the recorder self.active_experiment.start()