Skip to content
Open
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.5
rev: v0.16.5
hooks:
- id: ruff
args: [ --fix ]
Expand All @@ -16,7 +16,7 @@ repos:
types_or: ["python"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.15.0'
rev: 'v2.3.1'
hooks:
- id: mypy
additional_dependencies: ["types-tabulate", "types-requests"]
Expand Down
16 changes: 8 additions & 8 deletions amlb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
amlb entrypoint package.
"""

from .logger import app_logger as log
from .__version__ import __version__
from .benchmark import Benchmark, SetupMode
from .errors import AutoMLError
from .logger import app_logger as log
from .resources import Resources
from .benchmark import Benchmark, SetupMode
from .runners import AWSBenchmark, DockerBenchmark, SingularityBenchmark
from .results import TaskResult
from .__version__ import __version__
from .runners import AWSBenchmark, DockerBenchmark, SingularityBenchmark

__all__ = [
"log",
"AWSBenchmark",
"AutoMLError",
"Resources",
"Benchmark",
"DockerBenchmark",
"SingularityBenchmark",
"AWSBenchmark",
"Resources",
"SetupMode",
"SingularityBenchmark",
"TaskResult",
"__version__",
"log",
]
41 changes: 22 additions & 19 deletions amlb/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@

from __future__ import annotations

from copy import copy
from enum import Enum
from functools import cached_property
from importlib import import_module, invalidate_caches
import logging
import math
import os
import re
import signal
import sys
from copy import copy
from enum import Enum
from functools import cached_property
from importlib import import_module, invalidate_caches

import pandas as pd

from .frameworks.definitions import load_framework_definition
from .job import Job, JobError, SimpleJobRunner, MultiThreadingJobRunner
from .datasets import DataLoader, DataSourceType
from .data import DatasetType
from .datasets import DataLoader, DataSourceType
from .datautils import read_csv
from .resources import get as rget, config as rconfig, output_dirs as routput_dirs
from .frameworks.definitions import load_framework_definition
from .job import Job, JobError, MultiThreadingJobRunner, SimpleJobRunner
from .resources import config as rconfig
from .resources import get as rget
from .resources import output_dirs as routput_dirs
from .results import ErrorResult, Scoreboard, TaskResult
from .utils import (
Namespace as ns,
)
from .utils import (
OSMonitoring,
as_list,
datetime_iso,
Expand All @@ -51,7 +55,6 @@
touch,
)


log = logging.getLogger(__name__)

_setup_dir_ = ".setup"
Expand Down Expand Up @@ -187,7 +190,7 @@ def setup(self, mode: SetupMode):
if mode == SetupMode.skip or mode == SetupMode.auto and self._is_setup_done():
return

log.info("Setting up framework {}.".format(self.framework_name))
log.info(f"Setting up framework {self.framework_name}.")

self._write_setup_env(
self.framework_module.__path__[0], **dict(self.framework_def.setup_env)
Expand Down Expand Up @@ -235,9 +238,7 @@ def resolve_venv(cmd):
)

invalidate_caches()
log.info(
"Setup of framework {} completed successfully.".format(self.framework_name)
)
log.info(f"Setup of framework {self.framework_name} completed successfully.")

self._mark_setup_done()

Expand Down Expand Up @@ -338,15 +339,17 @@ def on_interrupt(*_):
# threading.Thread(target=self.cleanup)

try:
with signal_handler(signal.SIGINT, on_interrupt):
with OSMonitoring(
with (
signal_handler(signal.SIGINT, on_interrupt),
OSMonitoring(
name=jobs[0].name if len(jobs) == 1 else None,
interval_seconds=rconfig().monitoring.interval_seconds,
check_on_exit=True,
statistics=rconfig().monitoring.statistics,
verbosity=rconfig().monitoring.verbosity,
):
self.job_runner.start()
),
):
self.job_runner.start()
except (KeyboardInterrupt, InterruptedError):
pass
finally:
Expand Down Expand Up @@ -381,7 +384,7 @@ def _get_task_def(self, task_name, include_disabled=False, fail_on_missing=True)
)
except StopIteration:
if fail_on_missing:
raise ValueError("Incorrect task name: {}.".format(task_name))
raise ValueError(f"Incorrect task name: {task_name}.")
return None
if not include_disabled and not Benchmark._is_task_enabled(task_def):
raise ValueError(
Expand Down Expand Up @@ -563,7 +566,7 @@ def __init__(
self.git_info = git_info
self.measure_inference_time = measure_inference_time
self.ext = ns() # used if frameworks require extra config points
self.quantile_levels = list(sorted(quantile_levels))
self.quantile_levels = sorted(quantile_levels)

def __setattr__(self, name, value):
if name == "metrics":
Expand Down
4 changes: 2 additions & 2 deletions amlb/benchmarks/file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import os
from typing import List, Tuple, Optional
from typing import List, Optional, Tuple

from amlb.utils import config_load, Namespace
from amlb.utils import Namespace, config_load

log = logging.getLogger(__name__)

Expand Down
7 changes: 3 additions & 4 deletions amlb/benchmarks/openml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

import openml
import pandas as pd
from openml import OpenMLTask, OpenMLDataset
from openml import OpenMLDataset, OpenMLTask

from amlb.utils import Namespace, str_sanitize


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -67,7 +66,7 @@ def load_openml_tasks_from_suite(domain: str, oml_id: int) -> list[Namespace]:
name=str_sanitize(datasets.loc[did]["name"]),
description=f"{domain}/d/{did}",
openml_task_id=tid,
id="{}.org/t/{}".format(domain, tid),
id=f"{domain}.org/t/{tid}",
)
)
return tasks
Expand All @@ -81,7 +80,7 @@ def load_openml_task_as_definition(domain: str, oml_id: int) -> list[Namespace]:
name=str_sanitize(data.name),
description=data.description,
openml_task_id=task.id,
id="{}.org/t/{}".format(domain, task.id),
id=f"{domain}.org/t/{task.id}",
)
]

Expand Down
5 changes: 3 additions & 2 deletions amlb/benchmarks/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from typing import List, Tuple

from .openml import is_openml_benchmark, load_oml_benchmark
from amlb.utils import Namespace, str_sanitize

from .file import load_file_benchmark
from amlb.utils import str_sanitize, Namespace
from .openml import is_openml_benchmark, load_oml_benchmark


def benchmark_load(
Expand Down
12 changes: 3 additions & 9 deletions amlb/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

from __future__ import annotations

import logging
from abc import ABC, abstractmethod
from collections.abc import Iterable
from enum import Enum
from functools import cached_property
import logging
from typing import List, Union, Iterable
from typing import List, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -126,15 +127,13 @@ def data_path(self, format: str) -> str:
:param format: the format requested for the data file. Currently supported formats are 'arff', 'csv'.
:return: the path to the data-split file in the requested format.
"""
pass

@cached_property
@abstractmethod
def data(self) -> DF:
"""
:return: all the columns (predictors + target) as a pandas DataFrame.
"""
pass

@cached_property
@profile(logger=log)
Expand Down Expand Up @@ -199,31 +198,27 @@ def type(self) -> DatasetType:
"""
:return: the problem type for the current dataset.
"""
pass

@property
@abstractmethod
def train(self) -> Datasplit:
"""
:return: the data subset used to train the model.
"""
pass

@property
@abstractmethod
def test(self) -> Datasplit:
"""
:return: the data subset used to score the model.
"""
pass

@property
@abstractmethod
def features(self) -> List[Feature]:
"""
:return: the list of all features available in the current dataset, target included.
"""
pass

@property
def predictors(self) -> List[Feature]:
Expand All @@ -238,7 +233,6 @@ def target(self) -> Feature:
"""
:return: the target feature for the current dataset.
"""
pass

@profile(logger=log)
def release(self) -> None:
Expand Down
7 changes: 4 additions & 3 deletions amlb/datasets/file.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

from abc import abstractmethod
import logging
import os
import re
import tempfile
from abc import abstractmethod
from functools import cache, cached_property
from typing import List

Expand All @@ -18,15 +18,16 @@
from ..resources import config as rconfig
from ..utils import (
Namespace as ns,
)
from ..utils import (
as_list,
list_all_files,
path_from_split,
profile,
repr_def,
split_path,
)

from .fileutils import is_archive, is_valid_url, unarchive_file, get_file_handler
from .fileutils import get_file_handler, is_archive, is_valid_url, unarchive_file

log = logging.getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions amlb/datasets/fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import os
import shutil
import tarfile
import boto3
from botocore.errorfactory import ClientError
import zipfile
from urllib.error import URLError
from urllib.parse import urlparse
from urllib.request import Request, urlopen
import zipfile

import boto3
from botocore.errorfactory import ClientError

from ..utils import touch

Expand Down
Loading
Loading