'''
This file contains helper functions for the multiguide package.
NOTE: best to keep this package as independent of third-party packages as possible. 
The goal is to make it callable by scripts from any conda environment.
'''

import os
from pathlib import Path
import torch
import pandas as pd
import os
from typing import List, Dict, Optional
import random
import numpy as np

PROJECT_ROOT = Path(os.path.realpath(__file__)).parents[1]
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

def set_seed(seed):
    """Set seed for reproducibility across all random number generators"""
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed(seed)
        torch.cuda.manual_seed_all(seed)  # for multi-GPU
        # For deterministic behavior (may impact performance)
        torch.backends.cudnn.deterministic = True
        torch.backends.cudnn.benchmark = False

class DotDict(dict):
    def __getattr__(self, key):
        return self[key]
    def __setattr__(self, key, value):
        self[key] = value
    def __delattr__(self, key):
        del self[key]
