How to use the optuna.logging.get_logger function in optuna

To help you get started, we’ve selected a few optuna examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github optuna / optuna / optuna / storages / rdb / storage.py View on Github external
def _commit_with_integrity_check(session):
        # type: (orm.Session) -> bool

        try:
            session.commit()
        except IntegrityError as e:
            logger = optuna.logging.get_logger(__name__)
            logger.debug(
                'Ignoring {}. This happens due to a timing issue among threads/processes/nodes. '
                'Another one might have committed a record with the same key(s).'.format(repr(e)))
            session.rollback()
            return False

        return True
github optuna / optuna / optuna / integration / skopt.py View on Github external
def _log_independent_sampling(self, trial, param_name):
        # type: (FrozenTrial, str) -> None

        logger = optuna.logging.get_logger(__name__)
        logger.warning("The parameter '{}' in trial#{} is sampled independently "
                       "by using `{}` instead of `SkoptSampler` "
                       "(optimization performance may be degraded). "
                       "You can suppress this warning by setting `warn_independent_sampling` "
                       "to `False` in the constructor of `SkoptSampler`, "
                       "if this independent sampling is intended behavior.".format(
                           param_name, trial.number, self._independent_sampler.__class__.__name__))
github optuna / optuna / optuna / study.py View on Github external
self,
            study_name,  # type: str
            storage,  # type: Union[str, storages.BaseStorage]
            sampler=None,  # type: samplers.BaseSampler
            pruner=None,  # type: pruners.BasePruner
            direction='minimize',  # type: str
    ):
        # type: (...) -> None

        self.study_name = study_name
        self.storage = storages.get_storage(storage)
        self.sampler = sampler or samplers.TPESampler()
        self.pruner = pruner or pruners.MedianPruner()

        self.study_id = self.storage.get_study_id_from_name(study_name)
        self.logger = logging.get_logger(__name__)
        self.save_distribution = True

        if direction == 'minimize':
            _direction = structs.StudyDirection.MINIMIZE
        elif direction == 'maximize':
            _direction = structs.StudyDirection.MAXIMIZE
        else:
            raise ValueError('Please set either \'minimize\' or \'maximize\' to direction.')

        # TODO(Yanase): Implement maximization.
        if _direction == structs.StudyDirection.MAXIMIZE:
            raise ValueError(
                'Optimization direction of study {} is set to `MAXIMIZE`. '
                'Currently, Optuna supports `MINIMIZE` only.'.format(study_name))

        self.storage.set_study_direction(self.study_id, _direction)
github optuna / optuna / optuna / cli.py View on Github external
def __init__(self, *args, **kwargs):
        # type: (List[Any], Dict[str, Any]) -> None

        super(_BaseCommand, self).__init__(*args, **kwargs)
        self.logger = optuna.logging.get_logger(__name__)
github optuna / optuna / optuna / study.py View on Github external
set to :obj:`False`.
            Otherwise, the creation of the study is skipped, and the existing one is returned.

    Returns:
        A :class:`~optuna.study.Study` object.

    """

    storage = storages.get_storage(storage)
    try:
        study_id = storage.create_new_study_id(study_name)
    except structs.DuplicatedStudyError:
        if load_if_exists:
            assert study_name is not None

            logger = logging.get_logger(__name__)
            logger.info("Using an existing study with name '{}' instead of "
                        "creating a new one.".format(study_name))
            study_id = storage.get_study_id_from_name(study_name)
        else:
            raise

    study_name = storage.get_study_name_from_id(study_id)

    return Study(study_name=study_name, storage=storage, sampler=sampler, pruner=pruner,
                 direction=direction)
github optuna / optuna / optuna / study.py View on Github external
.. deprecated:: 0.15.0
            The direct use of storage is deprecated.
            Please access to storage via study's public methods
            (e.g., :meth:`~optuna.study.Study.set_user_attr`).

        Returns:
            A storage object.
        """

        warnings.warn("The direct use of storage is deprecated. "
                      "Please access to storage via study's public methods "
                      "(e.g., `Study.set_user_attr`)",
                      DeprecationWarning)

        logger = logging.get_logger(__name__)
        logger.warning("The direct use of storage is deprecated. "
                       "Please access to storage via study's public methods "
                       "(e.g., `Study.set_user_attr`)")

        return self._storage