<commit_before>import logging
import time
from parsl.providers.kubernetes.template import template_string

logger = logging.getLogger(__name__)

from parsl.providers.error import *
from parsl.providers.provider_base import ExecutionProvider
from parsl.utils import RepresentationMixin

try:
    from kubernetes import client, config
    config.load_kube_config()
    _kubernetes_enabled = True
except (ImportError, NameError, FileNotFoundError):
    _kubernetes_enabled = False


class KubernetesProvider(ExecutionProvider, RepresentationMixin):
    """ Kubernetes execution provider
    Parameters
    ----------
    namespace : str
        Kubernetes namespace to create deployments.
    image : str
        Docker image to use in the deployment.
    channel : Channel
        Channel for accessing this provider. Possible channels include
        :class:`~parsl.channels.LocalChannel` (the default),
        :class:`~parsl.channels.SSHChannel`, or
        :class:`~parsl.channels.SSHInteractiveLoginChannel`.
    tasks_per_node : int
        Tasks to run per node.
    nodes_per_block : int
        Nodes to provision per block.
    init_blocks : int
        Number of blocks to provision at the start of the run. Default is 1.
    min_blocks : int
        Minimum number of blocks to maintain.
    max_blocks : int
        Maximum number of blocks to maintain.
    parallelism : float
        Ratio of provisioned task slots to active tasks. A parallelism value of 1 represents aggressive
        scaling where as many resources as possible are used; parallelism close to 0 represents
        the opposite situation in which as few resources as possible (i.e., min_blocks) are used.
    secret : str
        Docker secret to use to pull images
    user_id : str
        Unix user id to run the container as.
    group_id : str
        Unix group id to run the container as.
    run_as_non_root : bool
        Run as non-root (True) or run as root (False).
    """

    def __init__(self,
                 image,
                 namespace='default',
                 channel=None,
                 tasks_per_node=1,
                 nodes_per_block=1,
                 init_blocks=4,
                 min_blocks=0,
                 max_blocks=10,
                 parallelism=1,
                 overrides="",
                 user_id=None,
                 group_id=None,
                 run_as_non_root=False,
                 secret=None):
        if not _kubernetes_enabled:
            raise OptionalModuleMissing(['kubernetes'],
                                        "Kubernetes provider requires kubernetes module and config.")

        self.namespace = namespace
        self.image = image
        self.channel = channel
        self.tasks_per_node = tasks_per_node
        self.nodes_per_block = nodes_per_block
        self.init_blocks = init_blocks
        self.min_blocks = min_blocks
        self.max_blocks = max_blocks
        self.parallelism = parallelism
        self.overrides = overrides
        self.secret = secret
        self.user_id = user_id
        self.group_id = group_id
        self.run_as_non_root = run_as_non_root

        self.kube_client = client.ExtensionsV1beta1Api()

        # Dictionary that keeps track of jobs, keyed on job_id
        self.resources = {}

    def submit(self, cmd_string, blocksize, job_name="parsl.auto"):
        """ Submit a job<commit_msg>move config.load_kube_config to init in KubernetesProvider<commit_after>import logging
import time
from parsl.providers.kubernetes.template import template_string

logger = logging.getLogger(__name__)

from parsl.providers.error import *
from parsl.providers.provider_base import ExecutionProvider
from parsl.utils import RepresentationMixin

try:
    from kubernetes import client, config
    _kubernetes_enabled = True
except (ImportError, NameError, FileNotFoundError):
    _kubernetes_enabled = False


class KubernetesProvider(ExecutionProvider, RepresentationMixin):
    """ Kubernetes execution provider
    Parameters
    ----------
    namespace : str
        Kubernetes namespace to create deployments.
    image : str
        Docker image to use in the deployment.
    channel : Channel
        Channel for accessing this provider. Possible channels include
        :class:`~parsl.channels.LocalChannel` (the default),
        :class:`~parsl.channels.SSHChannel`, or
        :class:`~parsl.channels.SSHInteractiveLoginChannel`.
    tasks_per_node : int
        Tasks to run per node.
    nodes_per_block : int
        Nodes to provision per block.
    init_blocks : int
        Number of blocks to provision at the start of the run. Default is 1.
    min_blocks : int
        Minimum number of blocks to maintain.
    max_blocks : int
        Maximum number of blocks to maintain.
    parallelism : float
        Ratio of provisioned task slots to active tasks. A parallelism value of 1 represents aggressive
        scaling where as many resources as possible are used; parallelism close to 0 represents
        the opposite situation in which as few resources as possible (i.e., min_blocks) are used.
    secret : str
        Docker secret to use to pull images
    user_id : str
        Unix user id to run the container as.
    group_id : str
        Unix group id to run the container as.
    run_as_non_root : bool
        Run as non-root (True) or run as root (False).
    """

    def __init__(self,
                 image,
                 namespace='default',
                 channel=None,
                 tasks_per_node=1,
                 nodes_per_block=1,
                 init_blocks=4,
                 min_blocks=0,
                 max_blocks=10,
                 parallelism=1,
                 overrides="",
                 user_id=None,
                 group_id=None,
                 run_as_non_root=False,
                 secret=None):
        if not _kubernetes_enabled:
            raise OptionalModuleMissing(['kubernetes'],
                                        "Kubernetes provider requires kubernetes module and config.")
        config.load_kube_config()

        self.namespace = namespace
        self.image = image
        self.channel = channel
        self.tasks_per_node = tasks_per_node
        self.nodes_per_block = nodes_per_block
        self.init_blocks = init_blocks
        self.min_blocks = min_blocks
        self.max_blocks = max_blocks
        self.parallelism = parallelism
        self.overrides = overrides
        self.secret = secret
        self.user_id = user_id
        self.group_id = group_id
        self.run_as_non_root = run_as_non_root

        self.kube_client = client.ExtensionsV1beta1Api()

        # Dictionary that keeps track of jobs, keyed on job_id
        self.resources = {}

    def submit(self, cmd_string, blocksize, job_name="parsl.auto"):
        """ Submit a job
{'fraction_non_alphanumeric': 0.06099868976561363, 'fraction_numerical': 0.003493958363662833, 'mean_word_length': 2.190896423594984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6419276', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1747, 'n_words': 568}