How to use the optuna.logging 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 / trial.py View on Github external
def _adjust_discrete_uniform_high(name, low, high, q):
    # type: (str, float, float, float) -> float

    r = high - low

    if math.fmod(r, q) != 0:
        high = (r // q) * q + low
        logger = logging.get_logger(__name__)
        logger.warning('The range of parameter `{}` is not divisible by `q`, and is '
                       'replaced by [{}, {}].'.format(name, low, high))

    return high
github optuna / optuna / tests / test_logging.py View on Github external
def test_get_logger(caplog):
    # type: (_pytest.logging.LogCaptureFixture) -> None

    # Log propagation is necessary for caplog to capture log outputs.
    optuna.logging.enable_propagation()

    logger = optuna.logging.get_logger('optuna.foo')
    with caplog.at_level(logging.INFO, logger='optuna.foo'):
        logger.info('hello')
    assert 'hello' in caplog.text
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 / storages / rdb / storage.py View on Github external
engine_kwargs = engine_kwargs or {}

        url = self._fill_storage_url_template(url)

        try:
            self.engine = create_engine(url, **engine_kwargs)
        except ImportError as e:
            raise ImportError('Failed to import DB access module for the specified storage URL. '
                              'Please install appropriate one. (The actual import error is: ' +
                              str(e) + '.)')

        self.scoped_session = orm.scoped_session(orm.sessionmaker(bind=self.engine))
        models.BaseModel.metadata.create_all(self.engine)

        self.logger = optuna.logging.get_logger(__name__)

        self._version_manager = _VersionManager(url, self.engine, self.scoped_session)
        if not skip_compatibility_check:
            self._version_manager.check_table_schema_compatibility()

        self._finished_trials_cache = _FinishedTrialsCache(enable_cache)
github optuna / optuna / optuna / cli.py View on Github external
def configure_logging(self):
        # type: () -> None

        super(OptunaApp, self).configure_logging()

        # Find the StreamHandler that is configured by super's configure_logging,
        # and replace its formatter with our fancy one.
        root_logger = logging.getLogger()
        stream_handlers = [
            handler for handler in root_logger.handlers
            if isinstance(handler, logging.StreamHandler)
        ]
        assert len(stream_handlers) == 1
        stream_handler = stream_handlers[0]
        stream_handler.setFormatter(optuna.logging.create_default_formatter())
github optuna / optuna / optuna / integration / sklearn.py View on Github external
if type_checking.TYPE_CHECKING:
    import pandas as pd  # NOQA
    from scipy.sparse import spmatrix  # NOQA
    from typing import Any  # NOQA
    from typing import Callable  # NOQA
    from typing import Dict  # NOQA
    from typing import List  # NOQA
    from typing import Mapping  # NOQA
    from typing import Optional  # NOQA
    from typing import Union  # NOQA

    OneDimArrayLikeType = Union[List[float], np.ndarray, pd.Series]
    TwoDimArrayLikeType = \
        Union[List[List[float]], np.ndarray, pd.DataFrame, spmatrix]

logger = logging.get_logger(__name__)


def _check_sklearn_availability():
    # type: () -> None

    if not _available:
        raise ImportError(
            'scikit-learn is not available. Please install scikit-learn to '
            'use this feature. scikit-learn can be installed by executing '
            '`$ pip install scikit-learn>=0.19.0`. For further information, '
            'please refer to the installation guide of scikit-learn. (The '
            'actual import error is as follows: ' + str(_import_error) + ')'
        )


def safe_indexing(
github optuna / optuna / optuna / cli.py View on Github external
def configure_logging(self):
        # type: () -> None

        super(_OptunaApp, self).configure_logging()

        # Find the StreamHandler that is configured by super's configure_logging,
        # and replace its formatter with our fancy one.
        root_logger = logging.getLogger()
        stream_handlers = [
            handler for handler in root_logger.handlers
            if isinstance(handler, logging.StreamHandler)
        ]
        assert len(stream_handlers) == 1
        stream_handler = stream_handlers[0]
        stream_handler.setFormatter(optuna.logging.create_default_formatter())
github optuna / optuna / optuna / cli.py View on Github external
def configure_logging(self):
        # type: () -> None

        super(OptunaApp, self).configure_logging()

        # Find the StreamHandler that is configured by super's configure_logging,
        # and replace its formatter with our fancy one.
        root_logger = logging.getLogger()
        stream_handlers = [
            handler for handler in root_logger.handlers
            if isinstance(handler, logging.StreamHandler)
        ]
        assert len(stream_handlers) == 1
        stream_handler = stream_handlers[0]
        stream_handler.setFormatter(optuna.logging.create_default_formatter())
github optuna / optuna / optuna / integration / cma.py View on Github external
# type: (...) -> None

        _check_cma_availability()

        self._x0 = x0
        self._sigma0 = sigma0
        self._cma_stds = cma_stds
        if seed is None:
            seed = random.randint(1, 2**32)
        self._cma_opts = cma_opts or {}
        self._cma_opts['seed'] = seed
        self._cma_opts.setdefault('verbose', -2)
        self._n_startup_trials = n_startup_trials
        self._independent_sampler = independent_sampler or optuna.samplers.RandomSampler(seed=seed)
        self._warn_independent_sampling = warn_independent_sampling
        self._logger = optuna.logging.get_logger(__name__)