<commit_before>"""Encapsulation of functionality provided by various batch schedulers.

Exports:
    SLURMScheduler: Interface to SLURM batch scheduler.
    Scheduler: Generic instantiator for all implemented schedulers.
"""
import logging
import os
from subprocess import CalledProcessError, check_output, STDOUT

class _BatchScheduler(object):
    """Superclass for batch scheduler classes.

    Subclasses must override the non-magic methods defined here.
    """
    @classmethod
    def is_scheduler_for(cls, type):
        """Return boolean indicating whether the class provides an interface to
        the batch scheduler type given.

        Args:
            type (str): Batch scheduler type.
        """
        pass

    def get_batch_script(self, run_name, numtasks=4, email=None):
        """Return the batch script that runs a job as per args formatted for the
        given batch scheduler.

        Args:
            run_name (str): Human-readable label for job run.
            num_tasks (int): Number of tasks to schedule.
            email (str): Email to send results to upon completion. If None, no
                email sent.
        """
        pass

    def schedule(self, proj_loc):
        """Schedule a job using the given batch scheduler.

        Args:
            proj_loc (str): Folder containing the batch script 'script.sh' for
                the job to schedule.
        """
        pass

    def check_status(self, scheduler_job_num):
        """Return job status from scheduler.

        Args:
            scheduler_job_num (int): Job number of the job to check state on as
                given by the scheduler, not as given by OnRamp.
        """
        pass

    def cancel_job(self, scheduler_job_num):
        """Cancel the given job.
    
        Args:
            scheduler_job_num (int): Job number, as given by the scheduler, of the
                job to cancel.
        """
        pass
        
    def __init__(self, type):
        """Set batch scheduler type and return the instance.

        Args:
            type (str): Batch scheduler type.
        """
        pass

class SLURMScheduler(_BatchScheduler):
    @classmethod
    def is_scheduler_for(cls, type):
        """Return boolean indicating whether the class provides an interface to
        the batch scheduler type given.

        Args:
            type (str): Batch scheduler type.
        """
        return type == 'SLURM'

    def get_batch_script(self, run_name, numtasks=4, email=None):
        """Return the batch script that runs a job as per args formatted for the
        SLURM batch scheduler.

        Args:
            run_name (str): Human-readable label for job run.
            num_tasks (int): Number of tasks to schedule.
            email (str): Email to send results to upon completion. If None, no
                email sent.
        """
        contents = '#!/bin/bash\n'
        contents += '\n'
        contents += '###################################\n'
        contents += '# Slurm Submission options\n'
        contents += '#\n'
        contents += '#SBATCH --job-name=' + run_name + '\n'
        contents += '#SBATCH -o output.txt\n'
        contents += '#SBATCH -n ' + str(numtasks) + '\n'
        if email:
            self.logger.debug('%s configured for email reporting to %s'
                              % (run_name, email))
            contents += '#SBATCH --mail-user=' + email + '\n'
        contents += '###################################\n'
        contents += '\n'
        contents += 'python bin/onramp_run.py\n'
        return contents
        
    def schedule(self, proj_loc):
        """Schedule a job using the SLURM batch scheduler.

        Args:<commit_msg>Corrected python interpreter used to launch bin/onramp_run.py.<commit_after>"""Encapsulation of functionality provided by various batch schedulers.

Exports:
    SLURMScheduler: Interface to SLURM batch scheduler.
    Scheduler: Generic instantiator for all implemented schedulers.
"""
import logging
import os
from subprocess import CalledProcessError, check_output, STDOUT

from PCE import pce_root

class _BatchScheduler(object):
    """Superclass for batch scheduler classes.

    Subclasses must override the non-magic methods defined here.
    """
    local_python = os.path.join(pce_root, 'src', 'env', 'bin', 'python')

    @classmethod
    def is_scheduler_for(cls, type):
        """Return boolean indicating whether the class provides an interface to
        the batch scheduler type given.

        Args:
            type (str): Batch scheduler type.
        """
        pass

    def get_batch_script(self, run_name, numtasks=4, email=None):
        """Return the batch script that runs a job as per args formatted for the
        given batch scheduler.

        Args:
            run_name (str): Human-readable label for job run.
            num_tasks (int): Number of tasks to schedule.
            email (str): Email to send results to upon completion. If None, no
                email sent.
        """
        pass

    def schedule(self, proj_loc):
        """Schedule a job using the given batch scheduler.

        Args:
            proj_loc (str): Folder containing the batch script 'script.sh' for
                the job to schedule.
        """
        pass

    def check_status(self, scheduler_job_num):
        """Return job status from scheduler.

        Args:
            scheduler_job_num (int): Job number of the job to check state on as
                given by the scheduler, not as given by OnRamp.
        """
        pass

    def cancel_job(self, scheduler_job_num):
        """Cancel the given job.
    
        Args:
            scheduler_job_num (int): Job number, as given by the scheduler, of the
                job to cancel.
        """
        pass
        
    def __init__(self, type):
        """Set batch scheduler type and return the instance.

        Args:
            type (str): Batch scheduler type.
        """
        pass

class SLURMScheduler(_BatchScheduler):
    @classmethod
    def is_scheduler_for(cls, type):
        """Return boolean indicating whether the class provides an interface to
        the batch scheduler type given.

        Args:
            type (str): Batch scheduler type.
        """
        return type == 'SLURM'

    def get_batch_script(self, run_name, numtasks=4, email=None):
        """Return the batch script that runs a job as per args formatted for the
        SLURM batch scheduler.

        Args:
            run_name (str): Human-readable label for job run.
            num_tasks (int): Number of tasks to schedule.
            email (str): Email to send results to upon completion. If None, no
                email sent.
        """
        contents = '#!/bin/bash\n'
        contents += '\n'
        contents += '###################################\n'
        contents += '# Slurm Submission options\n'
        contents += '#\n'
        contents += '#SBATCH --job-name=' + run_name + '\n'
        contents += '#SBATCH -o output.txt\n'
        contents += '#SBATCH -n ' + str(numtasks) + '\n'
        if email:
            self.logger.debug('%s configured for email reporting to %s'
                              % (run_name, email))
            contents += '#SBATCH --mail-user=' + email + '\n'
        contents += '###################################\n'
        contents += '\n'
        contents += '%s bin/onramp_run.py\n' % self.local_python
        return contents
        
    def schedule(self, proj_loc):
        """Schedule a job using the SLURM batch scheduler.

        Args:
{'fraction_non_alphanumeric': 0.10550518985678622, 'fraction_numerical': 0.0005255551175929575, 'mean_word_length': 2.0326693227091632, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3605138', 'n_tokens_mistral': 2048, 'n_tokens_neox': 1990, 'n_words': 750}