Exemple #1
0
 def close(self) -> None:
     """Close progress bars."""
     if self._is_valid:
         self._progress_bar.close()
         assert _tqdm_handler is not None
         optuna_logging._get_library_root_logger().removeHandler(_tqdm_handler)
         optuna_logging.enable_default_handler()
Exemple #2
0
    def _init_valid(self) -> None:
        self._progress_bar = tqdm(range(self._n_trials) if self._n_trials is not None else None)
        global _tqdm_handler

        _tqdm_handler = _TqdmLoggingHandler()
        _tqdm_handler.setLevel(logging.INFO)
        _tqdm_handler.setFormatter(optuna_logging.create_default_formatter())
        optuna_logging.disable_default_handler()
        optuna_logging._get_library_root_logger().addHandler(_tqdm_handler)
Exemple #3
0
    def _init_valid(self) -> None:

        if self._n_trials is not None:
            self._progress_bar = tqdm(total=self._n_trials)

        else:
            fmt = "{percentage:3.0f}%|{bar}| {elapsed}/{desc}"
            self._progress_bar = tqdm(total=self._timeout, bar_format=fmt)

            # Using description string instead postfix string
            # to display formatted timeout, since postfix carries
            # extra comma space auto-format.
            # https://github.com/tqdm/tqdm/issues/712
            total = tqdm.format_interval(self._timeout)
            self._progress_bar.set_description_str(total)

        global _tqdm_handler

        _tqdm_handler = _TqdmLoggingHandler()
        _tqdm_handler.setLevel(logging.INFO)
        _tqdm_handler.setFormatter(optuna_logging.create_default_formatter())
        optuna_logging.disable_default_handler()
        optuna_logging._get_library_root_logger().addHandler(_tqdm_handler)
Exemple #4
0
    def __init__(self, choices):
        # type: (Sequence[CategoricalChoiceType]) -> None

        if len(choices) == 0:
            raise ValueError("The `choices` must contains one or more elements.")
        for choice in choices:
            if choice is not None and not isinstance(choice, (bool, int, float, str)):
                message = (
                    "Choices for a categorical distribution should be a tuple of None, bool, "
                    "int, float and str for persistent storage but contains {} which is of type "
                    "{}.".format(choice, type(choice).__name__)
                )
                warnings.warn(message)

                logger = logging._get_library_root_logger()
                logger.warning(message)

        self.choices = choices
Exemple #5
0
    def study_id(self):
        # type: () -> int
        """Return the study ID.

        .. deprecated:: 0.20.0
            The direct use of this attribute is deprecated and it is recommended that you use
            :attr:`~optuna.structs.StudySummary.study_name` instead.

        Returns:
            The study ID.
        """

        message = 'The use of `StudySummary.study_id` is deprecated. ' \
                  'Please use `StudySummary.study_name` instead.'
        warnings.warn(message, DeprecationWarning)

        logger = logging._get_library_root_logger()
        logger.warning(message)

        return self._study_id
Exemple #6
0
    def trial_id(self):
        # type: () -> int
        """Return the trial ID.

        .. deprecated:: 0.19.0
            The direct use of this attribute is deprecated and it is recommended that you use
            :attr:`~optuna.trial.FrozenTrial.number` instead.

        Returns:
            The trial ID.
        """

        warnings.warn(
            'The use of `FrozenTrial.trial_id` is deprecated. '
            'Please use `FrozenTrial.number` instead.', DeprecationWarning)

        logger = logging._get_library_root_logger()
        logger.warning('The use of `FrozenTrial.trial_id` is deprecated. '
                       'Please use `FrozenTrial.number` instead.')

        return self._trial_id