in slurm-to-batch/slurm_script_parser.py [0:0]
def parse_slurm_script(file_path: str) -> SlurmJobConfig:
with open(file_path, 'r') as file:
content = file.read()
job_name = re.search(r'#SBATCH\s+--job-name=(\S+)', content)
cpus_per_task = re.search(r'#SBATCH\s+--cpus-per-task=(\d+)', content)
gpus_per_task = re.search(r'#SBATCH\s+--gpus-per-task=(\d+)', content)
gres_match = re.search(r'#SBATCH\s+--gres=gpu:(\S+)?:(\d+)', content)
node_count = re.search(r'#SBATCH\s+--nodes=(\d+)', content)
tasks_per_node = re.search(r'#SBATCH\s+--ntasks-per-node=(\d+)', content)
job_name = job_name.group(1) if job_name else "Unknown"
cpus_per_task = int(cpus_per_task.group(1)) if cpus_per_task else 1
gpus_per_task = int(gpus_per_task.group(1)) if gpus_per_task else 0
gpu_type = gres_match.group(1) if gres_match and gres_match.group(1) else "None"
node_count = int(node_count.group(1))
tasks_per_node = int(tasks_per_node.group(1)) if tasks_per_node else 1
total_tasks = node_count * tasks_per_node
total_cpus = total_tasks * cpus_per_task
if gres_match:
total_gpus = int(gres_match.group(2)) * node_count # Total GPUs based on gres directive
else:
total_gpus = gpus_per_task * total_tasks # Total GPUs based on gpus-per-task directive if gres is not specified
slurm_config = SlurmJobConfig(job_name, node_count, total_cpus, total_gpus, gpu_type, total_tasks)
return slurm_config