# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


import os
import subprocess, subprocess as sub
import getpass
import copy
import time
import resource
import numpy as np
    import argparse
from collections import OrderedDict as odict
from itertools import chain
from ugali.utils.logger import logger

        Parameters
        ----------
        None
        
        Returns
        -------
        mlimit : memory limit (bytes)
        """
        rsrc = resource.RLIMIT_AS
        soft, hard = resource.getrlimit(rsrc)
        if os.getenv('LSB_CG_MEMLIMIT') and os.getenv('LSB_HOSTS'):
            # Memory limit per core
            memlimit = int(os.getenv('LSB_CG_MEMLIMIT'), 16)
            # Number of cores
            ncores = len(os.getenv('LSB_HOSTS').split())
            #soft = ncores * memlimit - 100*1024**2
            soft = int( 0.95 * ncores * memlimit )
        return soft,hard

        
class Slurm(Batch):
    _defaults = odict([
        ('account','kicp'),
        ('partition','kicp-ht'),
        ('mem',10000)
    ])

    def __init__(self, **kwargs):
        super(Slurm,self).__init__(**kwargs)

# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


# Path: ugali/utils/batch.py
import os
import subprocess, subprocess as sub
import getpass
import copy
import time
import resource
import numpy as np
    import argparse
from collections import OrderedDict as odict
from itertools import chain
from ugali.utils.logger import logger


        Parameters
        ----------
        None
        
        Returns
        -------
        mlimit : memory limit (bytes)
        """
        rsrc = resource.RLIMIT_AS
        soft, hard = resource.getrlimit(rsrc)
        if os.getenv('LSB_CG_MEMLIMIT') and os.getenv('LSB_HOSTS'):
            # Memory limit per core
            memlimit = int(os.getenv('LSB_CG_MEMLIMIT'), 16)
            # Number of cores
            ncores = len(os.getenv('LSB_HOSTS').split())
            #soft = ncores * memlimit - 100*1024**2
            soft = int( 0.95 * ncores * memlimit )
        return soft,hard

        
class Slurm(Batch):
    _defaults = odict([
        ('account','kicp'),
        ('partition','kicp-ht'),
        ('mem',10000)
    ])

    def __init__(self, **kwargs):
        super(Slurm,self).__init__(**kwargs)

        logger.warning('Slurm cluster is untested')