def _write_slurm_script(args, cmd_str, cmd_folder_name):
    """Write a slurm job script for the given command string.

    The bash script will be dumped in the current folder.

    Args:
        args (argparse.Namespace): Command-line arguments.
        cmd_str (str): The actual command that should be executed by the job
            job scheduler (independent of slurm).
        cmd_folder_name (str): The folder name of the command ``cmd_str`` within
            the hpsearch output folder. This is used to determine a filename.

    Returns:
        (str):
            Bash script filename.
    """
    script_fn = '%s_script.sh' % cmd_folder_name
    with open(script_fn, 'w') as f:
        f.write('#!/bin/bash\n')
        f.write('#SBATCH --job-name %s\n' % cmd_folder_name)
        f.write('#SBATCH --output %s_' % cmd_folder_name + '%j.out\n')
        f.write('#SBATCH --error %s_' % cmd_folder_name + '%j.err\n')
        f.write('#SBATCH --time %d:00:00\n' % args.num_hours)
        if len(args.slurm_mem) > 0:
            f.write('#SBATCH --mem %s\n' % args.slurm_mem)
        if len(args.slurm_gres) > 0:
            f.write('#SBATCH --gres %s\n' % args.slurm_gres)
        if len(args.slurm_partition) > 0:
            f.write('#SBATCH --partition %s\n' % args.slurm_partition)
        if len(args.slurm_qos) > 0:
            f.write('#SBATCH --qos %s\n' % args.slurm_qos)
        if len(args.slurm_constraint) > 0:
            f.write('#SBATCH --constraint %s\n' % args.slurm_constraint)
        f.write(cmd_str)

    return script_fn