# AUTOGENERATED! DO NOT EDIT! File to edit: 00_basics.ipynb (unless otherwise specified).

__all__ = ['get_device', 'read_settings', 'DEVICE', 'settings', 'DATA_STORE', 'LOG_STORE', 'MODEL_STORE',
           'EXPERIMENT_STORE', 'PATH_1K', 'PATH_10K', 'PATH_20K', 'PATH_100K', 'FILENAMES', 'SYNTHEA_DATAGEN_DATES',
           'CONDITIONS', 'LABELS', 'LOG_NUMERICALIZE_EXCEP']

# Cell
from fastai.imports import *
from addict import Dict

# Cell
def get_device():
    '''Checks to see if GPU is available and sets device to GPU or CPU'''
    use_cuda = torch.cuda.is_available()
    if use_cuda:
        assert torch.backends.cudnn.enabled == True
        torch.backends.cudnn.benchmark = True #Enable cuDNN auto-tuner - perf benefit for convs
        device = torch.device("cuda")
    else:
        device = torch.device("cpu")
    return device

# Cell
def read_settings():
    '''Read settings file at "~/.lemonpie/settings.yaml", if doesnt exist, create it from template'''
    settings_dir = f'{Path.home()}/.lemonpie'
    settings_file = Path(f'{settings_dir}/settings.yaml')

    if not settings_file.exists():
        print('No settings file found, so creating from template ..')
        with open('./templates/settings_template.yaml', 'r') as t:
            template = Dict(yaml.full_load(t))
        template.STORES.DATA_STORE       = f'{Path.home()}/.lemonpie/datasets'
        template.STORES.LOG_STORE        = f'{Path.home()}/.lemonpie/logs'
        template.STORES.MODEL_STORE      = f'{Path.home()}/.lemonpie/models'
        template.STORES.EXPERIMENT_STORE = f'{Path.home()}/.lemonpie/experiments'

        settings = template
        Path.mkdir(Path(settings_dir), exist_ok=True)
        with open(settings_file, 'w') as s:
            yaml.dump(settings.to_dict(), s)
    else:
        with open(settings_file, 'r') as s:
            settings = Dict(yaml.full_load(s))

    return settings

# Cell
DEVICE = get_device()
settings = read_settings()

DATA_STORE         = settings.STORES.DATA_STORE
LOG_STORE          = settings.STORES.LOG_STORE
MODEL_STORE        = settings.STORES.MODEL_STORE
EXPERIMENT_STORE   = settings.STORES.EXPERIMENT_STORE

PATH_1K   = f'{DATA_STORE}/synthea/1K'
PATH_10K  = f'{DATA_STORE}/synthea/10K'
PATH_20K  = f'{DATA_STORE}/synthea/20K'
PATH_100K = f'{DATA_STORE}/synthea/100K'

FILENAMES = settings.FILENAMES

SYNTHEA_DATAGEN_DATES = settings.SYNTHEA_DATAGEN_DATES

CONDITIONS = settings.CONDITIONS

LABELS = settings.LABELS

LOG_NUMERICALIZE_EXCEP = settings.LOG_NUMERICALIZE_EXCEP