Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions autosklearn/automl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
from autosklearn.evaluation.abstract_evaluator import _fit_and_suppress_warnings
from autosklearn.evaluation.train_evaluator import _fit_with_budget
from autosklearn.metrics import calculate_score
from autosklearn.util import StopWatch, get_logger, setup_logger, \
pipeline
from autosklearn.util.stopwatch import StopWatch
from autosklearn.util.logging_ import get_logger, setup_logger
from autosklearn.util import pipeline
from autosklearn.ensemble_builder import EnsembleBuilder
from autosklearn.smbo import AutoMLSMBO
from autosklearn.util.hash import hash_array_or_matrix
Expand Down
2 changes: 1 addition & 1 deletion autosklearn/data/abstract_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from autosklearn.pipeline.components.data_preprocessing.data_preprocessing \
import DataPreprocessor
from autosklearn.util import predict_RAM_usage
from autosklearn.util.data import predict_RAM_usage


def perform_one_hot_encoding(sparse, categorical, data):
Expand Down
2 changes: 1 addition & 1 deletion autosklearn/data/competition_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from autosklearn.constants import MULTILABEL_CLASSIFICATION, \
STRING_TO_TASK_TYPES, MULTICLASS_CLASSIFICATION
from autosklearn.data.abstract_data_manager import AbstractDataManager
from autosklearn.util import convert_to_num
from autosklearn.util.data import convert_to_num
try:
import autosklearn.data.competition_c_functions as competition_c_functions

Expand Down
2 changes: 1 addition & 1 deletion autosklearn/metalearning/mismbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import MetaLearningOptimizer

from autosklearn.constants import *
from autosklearn.util import get_logger
from autosklearn.util.logging_ import get_logger

__all__ = [
'calc_meta_features',
Expand Down
2 changes: 1 addition & 1 deletion autosklearn/smbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from autosklearn.data.abstract_data_manager import AbstractDataManager
from autosklearn.data.competition_data_manager import CompetitionDataManager
from autosklearn.evaluation import ExecuteTaFuncWithQueue, WORST_POSSIBLE_RESULT
from autosklearn.util import get_logger
from autosklearn.util.logging_ import get_logger
from autosklearn.metalearning.metalearning.meta_base import MetaBase
from autosklearn.metalearning.metafeatures.metafeatures import \
calculate_all_metafeatures_with_labels, calculate_all_metafeatures_encoded_labels
Expand Down
5 changes: 0 additions & 5 deletions autosklearn/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# -*- encoding: utf-8 -*-
from .common import *
from .logging_ import *
from .stopwatch import *
from .data import *
from .backend import *
50 changes: 20 additions & 30 deletions autosklearn/util/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def __init__(self,
shared_mode=False):

# Check that the names of tmp_dir and output_dir is not the same.
if temporary_directory == output_directory \
and temporary_directory is not None:
if temporary_directory == output_directory and temporary_directory is not None:
raise ValueError("The temporary and the output directory "
"must be different.")

Expand Down Expand Up @@ -122,18 +121,16 @@ def create_directories(self):
os.makedirs(self.output_directory)
self._output_dir_created = True


def __del__(self):
self.delete_directories(force=False)

def delete_directories(self, force=True):
if self.delete_output_folder_after_terminate or force:
if self._output_dir_created is False and self.shared_mode is False:
raise ValueError("Failed to delete output dir: %s "
"because auto-sklearn did not create it. "
"Please make sure that the specified output "
"dir does not exist when instantiating "
"auto-sklearn." % self.output_directory)
raise ValueError("Failed to delete output dir: %s because auto-sklearn did not "
"create it. Please make sure that the specified output dir does "
"not exist when instantiating auto-sklearn."
% self.output_directory)
try:
shutil.rmtree(self.output_directory)
except Exception:
Expand All @@ -146,21 +143,17 @@ def delete_directories(self, force=True):

if self.delete_tmp_folder_after_terminate or force:
if self._tmp_dir_created is False and self.shared_mode is False:
raise ValueError("Failed to delete tmp dir: % s "
"because auto-sklearn did not create it. "
"Please make sure that the specified tmp "
"dir does not exist when instantiating "
"auto-sklearn." % self.temporary_directory)
raise ValueError("Failed to delete tmp dir: % s because auto-sklearn did not "
"create it. Please make sure that the specified tmp dir does not "
"exist when instantiating auto-sklearn."
% self.temporary_directory)
try:
shutil.rmtree(self.temporary_directory)
except Exception:
if self._logger is not None:
self._logger.warning("Could not delete tmp dir: %s" %
self.temporary_directory)
pass
self._logger.warning("Could not delete tmp dir: %s" % self.temporary_directory)
else:
print("Could not delete tmp dir: %s" %
self.temporary_directory)
print("Could not delete tmp dir: %s" % self.temporary_directory)


class Backend(object):
Expand All @@ -183,11 +176,9 @@ def __init__(self, context):
# This does not have to exist or be specified
if self.output_directory is not None:
if not os.path.exists(self.output_directory):
raise ValueError("Output directory %s does not exist." %
self.output_directory)
raise ValueError("Output directory %s does not exist." % self.output_directory)

self.internals_directory = os.path.join(self.temporary_directory,
".auto-sklearn")
self.internals_directory = os.path.join(self.temporary_directory, ".auto-sklearn")
self._make_internals_directory()

@property
Expand Down Expand Up @@ -216,11 +207,9 @@ def save_start_time(self, seed):
filepath = self._get_start_time_filename(seed)

if not isinstance(start_time, float):
raise ValueError("Start time must be a float, but is %s." %
type(start_time))
raise ValueError("Start time must be a float, but is %s." % type(start_time))

with tempfile.NamedTemporaryFile('w', dir=os.path.dirname(filepath),
delete=False) as fh:
with tempfile.NamedTemporaryFile('w', dir=os.path.dirname(filepath), delete=False) as fh:
fh.write(str(start_time))
tempname = fh.name
os.rename(tempname, filepath)
Expand Down Expand Up @@ -268,7 +257,7 @@ def save_targets_ensemble(self, targets):
existing_targets = np.load(filepath, allow_pickle=True)
if existing_targets.shape[0] > targets.shape[0] or \
(existing_targets.shape == targets.shape and
np.allclose(existing_targets, targets)):
np.allclose(existing_targets, targets)):

return filepath
except Exception:
Expand Down Expand Up @@ -461,9 +450,10 @@ def save_predictions_as_npy(self, predictions, filepath):

def save_predictions_as_txt(self, predictions, subset, idx, precision, prefix=None):
# Write prediction scores in prescribed format
filepath = os.path.join(self.output_directory,
('%s_' % prefix if prefix else '') +
'%s_%s.predict' % (subset, str(idx)))
filepath = os.path.join(
self.output_directory,
('%s_' % prefix if prefix else '') + '%s_%s.predict' % (subset, str(idx)),
)

format_string = '{:.%dg} ' % precision
with tempfile.NamedTemporaryFile('w', dir=os.path.dirname(
Expand Down
7 changes: 2 additions & 5 deletions autosklearn/util/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
r'^(?P<name>[\w\-]+)%s?(,%s)?$' % (SUBPATTERN % (1, 1), SUBPATTERN % (2, 2)))



def verify_packages(packages):
if not packages:
return
Expand Down Expand Up @@ -45,7 +44,6 @@ def _verify_package(name, operation, version):

required_version = LooseVersion(version)


if operation == '==':
check = required_version == installed_version
elif operation == '>':
Expand All @@ -71,10 +69,9 @@ def __init__(self, package_name):


class IncorrectPackageVersionError(Exception):
error_message = '\'{name} {installed_version}\' version mismatch ({operation}{required_version})'
error_message = "'{name} {installed_version}' version mismatch ({operation}{required_version})"

def __init__(self, package_name, installed_version, operation,
required_version):
def __init__(self, package_name, installed_version, operation, required_version):
self.package_name = package_name
self.installed_version = installed_version
self.operation = operation
Expand Down
2 changes: 1 addition & 1 deletion autosklearn/util/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def hash_array_or_matrix(X):
m.update(str(X_tmp.shape).encode('utf8'))

hash = m.hexdigest()
return hash
return hash
3 changes: 1 addition & 2 deletions autosklearn/util/logging_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import logging.config
import os
import sys

import yaml

Expand Down Expand Up @@ -47,7 +46,7 @@ def __getstate__(self):
Dictionary, representing the object state to be pickled. Ignores
the self.logger field and only returns the logger name.
"""
return { 'name': self.name }
return {'name': self.name}

def __setstate__(self, state):
"""
Expand Down
3 changes: 2 additions & 1 deletion autosklearn/util/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*-
from autosklearn.constants import *
from autosklearn.constants import CLASSIFICATION_TASKS, REGRESSION_TASKS, BINARY_CLASSIFICATION, \
MULTILABEL_CLASSIFICATION, REGRESSION, MULTICLASS_CLASSIFICATION
from autosklearn.pipeline.classification import SimpleClassificationPipeline
from autosklearn.pipeline.regression import SimpleRegressionPipeline

Expand Down
2 changes: 1 addition & 1 deletion ci_scripts/flake8_diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ check_files() {
if [ -n "$files" ]; then
# Conservative approach: diff without context (--unified=0) so that code
# that was not changed does not create failures
git diff --no-ext-diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --max-line-length=90 --show-source $options
git diff --no-ext-diff --unified=0 $COMMIT_RANGE -- $files | flake8 --diff --max-line-length=100 --show-source $options
fi
}

Expand Down
4 changes: 4 additions & 0 deletions ci_scripts/flake8_full.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Running flake8 on whole sections of the package"
flake8 --max-line-length=100 --show-source autosklearn/util
1 change: 1 addition & 0 deletions ci_scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if [[ "$RUN_FLAKE8" ]]; then
echo 'Running flake8'
echo '***********************************************************'
source ci_scripts/flake8_diff.sh
source ci_scripts/flake8_full.sh
fi

if [[ "$SKIP_TESTS" != "true" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion test/test_automl/test_automl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import autosklearn.automl
from autosklearn.metrics import accuracy
import autosklearn.pipeline.util as putil
from autosklearn.util import setup_logger, get_logger, backend
from autosklearn.util.logging_ import setup_logger, get_logger
from autosklearn.constants import MULTICLASS_CLASSIFICATION, BINARY_CLASSIFICATION
from autosklearn.smbo import load_data
from smac.tae.execute_ta_run import StatusType
Expand Down
38 changes: 21 additions & 17 deletions test/test_evaluation/test_test_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
import numpy as np
from smac.tae.execute_ta_run import StatusType

this_directory = os.path.dirname(__file__)
sys.path.append(this_directory)
from evaluation_util import get_dataset_getters, BaseEvaluatorTest, \
get_multiclass_classification_datamanager
from autosklearn.constants import *
from autosklearn.constants import MULTILABEL_CLASSIFICATION, BINARY_CLASSIFICATION, \
MULTICLASS_CLASSIFICATION, REGRESSION
from autosklearn.evaluation.test_evaluator import TestEvaluator, eval_t
from autosklearn.evaluation.util import read_queue
from autosklearn.util.pipeline import get_configuration_space
from autosklearn.util import Backend
from autosklearn.util.backend import Backend
from autosklearn.metrics import accuracy, r2, f1_macro

this_directory = os.path.dirname(__file__)
sys.path.append(this_directory)
from evaluation_util import get_dataset_getters, BaseEvaluatorTest, \
get_multiclass_classification_datamanager # noqa


N_TEST_RUNS = 3


Expand Down Expand Up @@ -86,17 +89,18 @@ def tearDown(self):
pass

def test_eval_test(self):
eval_t(queue=self.queue,
backend=self.backend,
config=self.configuration,
metric=accuracy,
seed=1, num_run=1,
all_scoring_functions=False,
output_y_hat_optimization=False,
include=None,
exclude=None,
disable_file_output=False,
instance=self.dataset_name
eval_t(
queue=self.queue,
backend=self.backend,
config=self.configuration,
metric=accuracy,
seed=1, num_run=1,
all_scoring_functions=False,
output_y_hat_optimization=False,
include=None,
exclude=None,
disable_file_output=False,
instance=self.dataset_name
)
rval = read_queue(self.queue)
self.assertEqual(len(rval), 1)
Expand Down
2 changes: 1 addition & 1 deletion test/test_util/test_StopWatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import unittest
import unittest.mock

from autosklearn.util import StopWatch
from autosklearn.util.stopwatch import StopWatch


class Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_util/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import unittest

from autosklearn.util import check_pid
from autosklearn.util.common import check_pid


class TestUtilsCommon(unittest.TestCase):
Expand Down