<commit_before>import logging
import typing as tp
from enum import Enum
import copy
import abc

from benchbuild.settings import CFG

LOG = logging.getLogger(__name__)

SlurmOptionSubType = tp.TypeVar("SlurmOptionSubType", bound='SlurmOption')


class SlurmOption:
    """
    Base class for Slurm options.
    """
    def to_slurm_opt(self) -> str:
        """
        Converst slurm option into a script usable option string, i.e., bash
        #SBATCH option line.
        """
        return f"#SBATCH {self.to_slurm_cli_opt()}"

    @abc.abstractmethod
    def to_slurm_cli_opt(self) -> str:
        """
        Converst slurm option to command line string.
        """

    @classmethod
    @abc.abstractmethod
    def merge_requirements(
            cls: tp.Type[SlurmOptionSubType], lhs_option: SlurmOptionSubType,
            rhs_option: SlurmOptionSubType) -> SlurmOptionSubType:
        """
        Merge the requirements of the same type together.
        """
        return type(lhs_option).merge_requirements(lhs_option, rhs_option)


class CoresPerSocket(SlurmOption):
    """
    Restrict node selection to nodes with at least the specified number of
    cores per socket. See additional information under -B option above when
    task/affinity plugin is enabled.
    """
    def __init__(self, cores: int) -> None:
        self.__cores = cores

    @property
    def cores(self) -> int:
        """ Number of cores required per socket. """
        return self.__cores

    def to_slurm_cli_opt(self) -> str:
        return f"--cores-per-socket={self.cores}"

    def __str__(self) -> str:
        return f"Cores {self.cores}"

    def __repr__(self) -> str:
        return f"CoresPerSocket (Cores: {self.cores})"

    @classmethod
    def merge_requirements(cls, lhs_option: 'CoresPerSocket',
                           rhs_option: 'CoresPerSocket') -> 'CoresPerSocket':
        """
        Merge the requirements of the same type together.
        """
        return CoresPerSocket(max(lhs_option.cores, rhs_option.cores))


class Exclusive(SlurmOption):
    """
    The job allocation can not share nodes with other running jobsThe job
    allocation can not share nodes with other running jobs
    """
    def to_slurm_cli_opt(self) -> str:
        return "--exclusive"

    def __str__(self) -> str:
        return "Run Exclusive"

    def __repr__(self) -> str:
        return "Exclusive"

    @classmethod
    def merge_requirements(cls, lhs_option: 'Exclusive',
                           rhs_option: 'Exclusive') -> 'Exclusive':
        """
        Merge the requirements of the same type together.
        """
        return Exclusive()


class Niceness(SlurmOption):
    """
    Run the job with an adjusted scheduling priority within Slurm. With no
    adjustment value the scheduling priority is decreased by 100. A negative
    nice value increases the priority, otherwise decreases it. The adjustment
    range is +/- 2147483645. Only privileged users can specify a negative
    adjustment.
    """
    def __init__(self, niceness: int) -> None:
        self.__niceness = niceness

    @property
    def niceness(self) -> int:
        return self.__niceness

    def to_slurm_cli_opt(self) -> str:
        return f"--nice={self.niceness}"

    def __str__(self) -> str:
        return f"Nice: {self.niceness}"

    def __repr__(self) -> str:
        return f"Niceness (Nice: {self.niceness})"

    @classmethod
    def merge_requirements(cls, lhs_option: 'Niceness',
                           rhs_option: 'Niceness') -> 'Niceness':
        """
        Merge the requirements of the same type together.
        """
        if lhs_option.niceness != rhs_option.niceness:
            LOG.info("Multiple different slurm niceness values specifcied, "
                     "choosing the smaller value.")

        return Niceness(min(lhs_option.niceness, rhs_option.niceness))


class Hint(SlurmOption):
    """
    Bind tasks according to application hints.
        * compute_bound
            Select settings for compute bound applications: use all cores in
            each socket, one thread per core.
        * memory_bound
            Select settings for memory bound applications: use only one core
            in each socket, one thread per core.
        * [no]multithread
            [don't] use extra threads with in-core multi-threading which can
            benefit communication intensive applications. Only supported with
            the task/affinity plugin.
    """
    class SlurmHints(Enum):
        compute_bound = "compute_bound"
        memory_bound = "memory_bound"
        multithread = "multithread"
        nomultithread = "nomultithread"

        def __str__(self) -> str:
            return tp.cast(str, self.value)

    def __init__(self, hints: tp.Set[SlurmHints]) -> None:
        self.__hints = hints

    @property
    def hints(self) -> tp.Set[SlurmHints]:
        return self.__hints

    def to_slurm_cli_opt(self) -> str:
        return f"--hint={','.join(map(str, self.hints))}"

    def __str__(self) -> str:
        return f"Hints: {','.join(map(str, self.hints))}"

    def __repr__(self) -> str:
        return f"Hint ({str(self)})"

    @classmethod
    def merge_requirements(cls, lhs_option: 'Hint',
                           rhs_option: 'Hint') -> 'Hint':
        """
        Merge the requirements of the same type together.
        """
        combined_hints = set()
        combined_hints |= lhs_option.hints | rhs_option.hints

        if not cls.__hints_not_mutually_exclusive(combined_hints):
            raise ValueError(
                "Two mutally exclusive hints for slurm have be specified.")<commit_msg>Fixes remarks<commit_after>import logging
import typing as tp
from enum import Enum
import copy
import abc
import attr

from benchbuild.settings import CFG

LOG = logging.getLogger(__name__)

SlurmOptionSubType = tp.TypeVar("SlurmOptionSubType", bound='SlurmOption')


@attr.s
class SlurmOption:
    """
    Base class for Slurm options.
    """
    def to_slurm_opt(self) -> str:
        """
        Converst slurm option into a script usable option string, i.e., bash
        #SBATCH option line.
        """
        return f"#SBATCH {self.to_slurm_cli_opt()}"

    @abc.abstractmethod
    def to_slurm_cli_opt(self) -> str:
        """
        Converst slurm option to command line string.
        """

    @classmethod
    @abc.abstractmethod
    def merge_requirements(
            cls: tp.Type[SlurmOptionSubType], lhs_option: SlurmOptionSubType,
            rhs_option: SlurmOptionSubType) -> SlurmOptionSubType:
        """
        Merge the requirements of the same type together.
        """
        return type(lhs_option).merge_requirements(lhs_option, rhs_option)


@attr.s
class CoresPerSocket(SlurmOption):
    """
    Restrict node selection to nodes with at least the specified number of
    cores per socket. See additional information under -B option above when
    task/affinity plugin is enabled.
    """
    """ Number of cores required per socket. """
    cores: int = attr.ib()

    def to_slurm_cli_opt(self) -> str:
        return f"--cores-per-socket={self.cores}"

    @classmethod
    def merge_requirements(cls, lhs_option: 'CoresPerSocket',
                           rhs_option: 'CoresPerSocket') -> 'CoresPerSocket':
        """
        Merge the requirements of the same type together.
        """
        return CoresPerSocket(max(lhs_option.cores, rhs_option.cores))


class Exclusive(SlurmOption):
    """
    The job allocation can not share nodes with other running jobsThe job
    allocation can not share nodes with other running jobs
    """
    def to_slurm_cli_opt(self) -> str:
        return "--exclusive"

    def __str__(self) -> str:
        return "Run Exclusive"

    def __repr__(self) -> str:
        return "Exclusive"

    @classmethod
    def merge_requirements(cls, lhs_option: 'Exclusive',
                           rhs_option: 'Exclusive') -> 'Exclusive':
        """
        Merge the requirements of the same type together.
        """
        return Exclusive()


@attr.s
class Niceness(SlurmOption):
    """
    Run the job with an adjusted scheduling priority within Slurm. With no
    adjustment value the scheduling priority is decreased by 100. A negative
    nice value increases the priority, otherwise decreases it. The adjustment
    range is +/- 2147483645. Only privileged users can specify a negative
    adjustment.
    """
    niceness: int = attr.ib()

    def to_slurm_cli_opt(self) -> str:
        return f"--nice={self.niceness}"

    @classmethod
    def merge_requirements(cls, lhs_option: 'Niceness',
                           rhs_option: 'Niceness') -> 'Niceness':
        """
        Merge the requirements of the same type together.
        """
        if lhs_option.niceness != rhs_option.niceness:
            LOG.info("Multiple different slurm niceness values specifcied, "
                     "choosing the smaller value.")

        return Niceness(min(lhs_option.niceness, rhs_option.niceness))


@attr.s
class Hint(SlurmOption):
    """
    Bind tasks according to application hints.
        * compute_bound
            Select settings for compute bound applications: use all cores in
            each socket, one thread per core.
        * memory_bound
            Select settings for memory bound applications: use only one core
            in each socket, one thread per core.
        * [no]multithread
            [don't] use extra threads with in-core multi-threading which can
            benefit communication intensive applications. Only supported with
            the task/affinity plugin.
    """
    class SlurmHints(Enum):
        compute_bound = "compute_bound"
        memory_bound = "memory_bound"
        multithread = "multithread"
        nomultithread = "nomultithread"

        def __str__(self) -> str:
            return str(self.value)

    hints: tp.Set[SlurmHints] = attr.ib()

    def to_slurm_cli_opt(self) -> str:
        return f"--hint={','.join(map(str, self.hints))}"

    def __str__(self) -> str:
        return f"Hints: {','.join(map(str, self.hints))}"

    def __repr__(self) -> str:
        return f"Hint ({str(self)})"

    @classmethod
    def merge_requirements(cls, lhs_option: 'Hint',
                           rhs_option: 'Hint') -> 'Hint':
        """
        Merge the requirements of the same type together.
        """
        combined_hints = set()
        combined_hints |= lhs_option.hints | rhs_option.hints

        if not cls.__hints_not_mutually_exclusive(combined_hints):
            raise ValueError(
                "Two mutally exclusive hints for slurm have be specified.")
{'fraction_non_alphanumeric': 0.09380250140003733, 'fraction_numerical': 0.0024267313795034535, 'mean_word_length': 2.402667513496348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6323665', 'n_tokens_mistral': 3149, 'n_tokens_neox': 3078, 'n_words': 909}