Skip to content

Commit

Permalink
Merge pull request #380 from Derek-Wds/main
Browse files Browse the repository at this point in the history
Modify get_exp & get_recorder api
  • Loading branch information
you-n-g committed Mar 30, 2021
2 parents ae57110 + b6df11b commit da59b35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions qlib/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 7 additions & 5 deletions qlib/workflow/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
-------
Expand All @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions qlib/workflow/expm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
-------
Expand All @@ -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()
Expand Down

0 comments on commit da59b35

Please sign in to comment.