"""Module for submitting jobs""" import subprocess def submit_slurm( cmd: str, time: str, partition: str, nodes: int, ntasks_per_node: int, job_name: str, account: str, **kwargs, ): """Submit a job to the slurm scheduler.""" scmd = [ *f"""sbatch --time={time} --account={account} --qos={partition} --job-name={job_name} --output=%x-%j.out --error=%x-%j.err --nodes={nodes} --ntasks-per-node={ntasks_per_node}""".replace("'", "").split(), ] if kwargs.get("constraint", False): scmd += [f"--constraint={kwargs['constraint']}"] if kwargs.get("exclude", False): scmd += ["--exclude"] scmd += ["--wrap", cmd] return subprocess.run(scmd, check=True)