Repository: microsoft/qlib
File: qlib/workflow/expm.py (Python)

Code before:
from .exp import MLflowExperiment, Experiment
from .recorder import Recorder
from ..log import get_module_logger

logger = get_module_logger("workflow", "INFO")


class ExpManager:
    """
    This is the `ExpManager` class for managing experiments. The API is designed similar to mlflow.
    (The link: https://mlflow.org/docs/latest/python_api/mlflow.html)
    """

    def __init__(self, uri: Text, default_exp_name: Optional[Text]):
        self._default_uri = uri
        self._current_uri = None
        self.default_exp_name = default_exp_name
        self.active_experiment = None  # only one experiment can active each time

    def __repr__(self):
        return "{name}(default_uri={duri}, current_uri={curi})".format(
            name=self.__class__.__name__, duri=self._default_uri, curi=self._current_uri
        )

    def reset_default_uri(self, uri: Text):
        self._default_uri = uri
        self.set_uri(None)

    def start_exp(
        self,
        experiment_name: Optional[Text] = None,
        recorder_name: Optional[Text] = None,
        uri: Optional[Text] = None,
        **kwargs,
    ):
        """
        Start an experiment. This method includes first get_or_create an experiment, and then
        set it to be active.

        Parameters
        ----------
        experiment_name : str
            name of the active experiment.
        recorder_name : str
            name of the recorder to be started.
        uri : str
            the current tracking URI.

        Returns
        -------
        An active experiment.

Review comment (suggestion):
Is any reason that you want to add this method? From my perspective, `default_uri` should be initialized and fixed when users call `qlib.init`. It seems there is no need to have such method here.

Code after:
from .exp import MLflowExperiment, Experiment
from ..config import C
from .recorder import Recorder
from ..log import get_module_logger

logger = get_module_logger("workflow", "INFO")


class ExpManager:
    """
    This is the `ExpManager` class for managing experiments. The API is designed similar to mlflow.
    (The link: https://mlflow.org/docs/latest/python_api/mlflow.html)
    """

    def __init__(self, uri: Text, default_exp_name: Optional[Text]):
        self._current_uri = uri
        self.default_exp_name = default_exp_name
        self.active_experiment = None  # only one experiment can active each time

    def __repr__(self):
        return "{name}(current_uri={curi})".format(name=self.__class__.__name__, curi=self._current_uri)

    def start_exp(
        self,
        experiment_name: Optional[Text] = None,
        recorder_name: Optional[Text] = None,
        uri: Optional[Text] = None,
        **kwargs,
    ):
        """
        Start an experiment. This method includes first get_or_create an experiment, and then
        set it to be active.

        Parameters
        ----------
        experiment_name : str
            name of the active experiment.
        recorder_name : str
            name of the recorder to be started.
        uri : str
            the current tracking URI.

        Returns
        -------
        An active experiment.
        """
        raise NotImplementedError(f"Please implement the `start_exp` method.")

    def end_exp(self, recorder_status: Text = Recorder.STATUS_S, **kwargs):
        """
        End an active experiment.