Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
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)
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())
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(
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())
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())
# 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__)